speedtch testatm.c,1.2,1.3

Duncan Sands duncan at infradead.org
Mon Feb 7 12:34:37 EST 2005


Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv15740

Modified Files:
	testatm.c 
Log Message:
Add more test minidrivers.


Index: testatm.c
===================================================================
RCS file: /home/cvs/speedtch/testatm.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- testatm.c	1 Feb 2005 23:26:47 -0000	1.2
+++ testatm.c	7 Feb 2005 17:34:34 -0000	1.3
@@ -17,24 +17,178 @@
  *
  ******************************************************************************/
 
+#include <linux/delay.h>
 #include <linux/module.h>
 
 #include "usbatm.h"
 
+uint	driver;
+module_param(driver, uint, 0444);
+
 uint	idVendor;
 module_param(idVendor, uint, 0444);
 
 uint	idProduct;
 module_param(idProduct, uint, 0444);
 
-static struct usbatm_driver testatm_driver_0 = {
-        .owner          = THIS_MODULE,
-        .driver_name    = "testatm_0"
+static int accept_bind(struct usbatm_data *usbatm, struct usb_interface *intf, int *need_heavy_init)
+{
+	dbg("accept_bind");
+
+	return 0;
+}
+
+static int refuse_bind(struct usbatm_data *usbatm, struct usb_interface *intf, int *need_heavy_init)
+{
+	dbg("refuse_bind");
+
+	return -1;
+}
+
+void testatm_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+	dbg("testatm_unbind");
+}
+
+static int accept_atm(struct usbatm_data *usbatm, struct atm_dev *dev)
+{
+	dbg("accept_atm");
+
+	return 0;
+}
+
+static int refuse_atm(struct usbatm_data *usbatm, struct atm_dev *dev)
+{
+	dbg("refuse_atm");
+
+	return -1;
+}
+
+void testatm_atm_stop(struct usbatm_data *usbatm, struct atm_dev *dev)
+{
+	dbg("testatm_atm_stop");
+}
+
+static int trivial_accept_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+	dbg("trivial_accept_heavy_init");
+
+	return 0;
+}
+
+static int trivial_refuse_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+	dbg("trivial_refuse_heavy_init");
+
+	return -1;
+}
+
+static int slow_accept_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+	unsigned long ret;
+
+	dbg("slow_accept_heavy_init");
+
+	ret = msleep_interruptible (30 * 60 * 1000);
+
+	dbg("slow_accept_heavy_init done (%lu)", ret);
+
+	return 0;
+}
+
+static int slow_refuse_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
+{
+	unsigned long ret;
+
+	dbg("slow_refuse_heavy_init");
+
+	ret = msleep_interruptible (30 * 60 * 1000);
+
+	dbg("slow_refuse_heavy_init done (%lu)", ret);
+
+	return -1;
+}
+
+static struct usbatm_driver testatm_drivers[] = {
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_0"
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_1",
+
+		.bind		= refuse_bind
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_2",
+
+		.bind		= accept_bind,
+
+		.atm_start	= refuse_atm
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_3",
+
+		.bind		= accept_bind,
+		.unbind		= testatm_unbind,
+
+		.atm_start	= accept_atm,
+		.atm_stop	= testatm_atm_stop
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_4",
+
+		.bind		= accept_bind,
+		.unbind		= testatm_unbind,
+
+		.heavy_init	= trivial_refuse_heavy_init,
+
+		.atm_start	= refuse_atm
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_5",
+
+		.bind		= accept_bind,
+		.unbind		= testatm_unbind,
+
+		.heavy_init	= trivial_accept_heavy_init,
+
+		.atm_start	= refuse_atm
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_6",
+
+		.bind		= accept_bind,
+		.unbind		= testatm_unbind,
+
+		.heavy_init	= slow_refuse_heavy_init,
+
+		.atm_start	= refuse_atm
+	},
+	{
+		.owner          = THIS_MODULE,
+	        .driver_name    = "testatm_7",
+
+		.bind		= accept_bind,
+		.unbind		= testatm_unbind,
+
+		.heavy_init	= slow_accept_heavy_init,
+
+		.atm_start	= refuse_atm
+	}
 };
 
 static int testatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
 {
-        return usbatm_usb_probe(intf, id, &testatm_driver_0);
+	struct usbatm_driver *test_driver = &testatm_drivers[driver];
+
+        return usbatm_usb_probe(intf, id, test_driver);
 }
 
 static struct usb_device_id testatm_usb_ids[] = {
@@ -51,8 +205,13 @@
 
 static int __init testatm_init(void)
 {
+	struct usbatm_driver *test_driver = &testatm_drivers[driver];
+
 	dbg("testatm_init");
 
+	if (((char *)test_driver - (char *)testatm_drivers) >= sizeof(testatm_drivers))
+		return -EINVAL;
+
 	printk("idVendor: %04x\n", idVendor);
 	printk("idProduct: %04x\n", idProduct);
 




More information about the Usbatm-commits mailing list