ChangeSet 1.1078.2.7, 2003/05/08 11:35:20-07:00, david-b@pacbell.net [PATCH] USB: gadget cleanup of #ifdefs > can you get rid of all of the #ifdef HAVE_DRIVER_MODEL stuff? Done. Now this code "knows" it's running in a 2.5 environment, and needs modifications to run on 2.4. I also changed the file modes in the module_parm() calls so the parameters will be writable when they eventually show up in sysfs; and fixed a typo. Compile-tested with and without DEBUG enabled. diff -Nru a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig --- a/drivers/usb/gadget/Kconfig Thu May 8 14:31:32 2003 +++ b/drivers/usb/gadget/Kconfig Thu May 8 14:31:32 2003 @@ -118,7 +118,7 @@ This driver implements the "Communication Device Class" (CDC) Ethernet Control Model. That protocol is often avoided with pure Ethernet adapters, in favor of simpler vendor-specific hardware, - but is widely suppored by firmware for smart network devices. + but is widely supported by firmware for smart network devices. Within the USB device, this gadget driver exposes a network device "usbX", where X depends on what other networking devices you have. diff -Nru a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c --- a/drivers/usb/gadget/ether.c Thu May 8 14:31:32 2003 +++ b/drivers/usb/gadget/ether.c Thu May 8 14:31:32 2003 @@ -37,6 +37,8 @@ #include #include #include +#include +#include #include #include @@ -118,17 +120,8 @@ #define TX_DELAY 8 -#ifdef HAVE_DRIVER_MODEL -#include - -module_param (qmult, uint, 0); - -#else +module_param (qmult, uint, S_IRUGO|S_IWUSR); -MODULE_PARM (qmult, "i"); -MODULE_PARM_DESC (qmult, "rx/tx buffering factor"); - -#endif /* HAVE_DRIVER_MODEL */ /*-------------------------------------------------------------------------*/ @@ -279,14 +272,8 @@ /*-------------------------------------------------------------------------*/ -#ifdef HAVE_DRIVER_MODEL -#define xprintk(dev,level,fmt,args...) \ - dev_printk(level , &dev->gadget->dev , fmt , ## args) -#else -#define xprintk(dev,level,fmt,args...) \ - printk(level "%s %s: " fmt , shortname, dev->gadget->dev.bus_id, \ - ## args) -#endif /* HAVE_DRIVER_MODEL */ +#define xprintk(d,level,fmt,args...) \ + dev_printk(level , &(d)->gadget->dev , fmt , ## args) #ifdef DEBUG #undef DEBUG @@ -954,12 +941,10 @@ static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req) { - if (req->status || req->actual != req->length) { - struct eth_dev *dev = ep->driver_data; - - DEBUG (dev, "setup complete --> %d, %d/%d\n", + if (req->status || req->actual != req->length) + DEBUG ((struct eth_dev *) ep->driver_data, + "setup complete --> %d, %d/%d\n", req->status, req->actual, req->length); - } } /* see section 3.8.2 table 10 of the CDC spec for more ethernet diff -Nru a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c --- a/drivers/usb/gadget/net2280.c Thu May 8 14:31:32 2003 +++ b/drivers/usb/gadget/net2280.c Thu May 8 14:31:32 2003 @@ -60,8 +60,8 @@ #include #include #include -#include - +#include +#include #include #include @@ -79,6 +79,7 @@ #define EP_DONTUSE 13 /* nonzero */ #define USE_RDK_LEDS /* GPIO pins control three LEDs */ +#define USE_SYSFS_DEBUG_FILES static const char driver_name [] = "net2280"; @@ -93,26 +94,12 @@ static int use_dma = 1; -#ifdef HAVE_DRIVER_MODEL -#include - /* "modprobe net2280 use_dma=n" etc */ module_param (use_dma, bool, S_IRUGO|S_IWUSR); -#else -/* use zero/nonzero for older versions */ -MODULE_PARM (use_dma, "i"); -MODULE_PARM_DESC (use_dma, "true to use dma controllers"); -#endif - -#include "net2280.h" - -#define valid_bit cpu_to_le32 (1 << VALID_BIT) -#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE) - -/*-------------------------------------------------------------------------*/ #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") +#if defined(USE_SYSFS_DEBUG_FILES) || defined (DEBUG) static char *type_string (u8 bmAttributes) { switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { @@ -122,6 +109,14 @@ }; return "control"; } +#endif + +#include "net2280.h" + +#define valid_bit cpu_to_le32 (1 << VALID_BIT) +#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE) + +/*-------------------------------------------------------------------------*/ static int net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) @@ -1280,7 +1275,7 @@ /*-------------------------------------------------------------------------*/ -#ifdef HAVE_DRIVER_MODEL +#ifdef USE_SYSFS_DEBUG_FILES /* "function" sysfs attribute */ static ssize_t @@ -1771,25 +1766,19 @@ /* hook up the driver ... */ dev->driver = driver; -#ifdef HAVE_DRIVER_MODEL dev->gadget.dev.driver = &driver->driver; -#endif retval = driver->bind (&dev->gadget); if (retval) { DEBUG (dev, "bind to driver %s --> %d\n", driver->driver.name, retval); dev->driver = 0; -#ifdef HAVE_DRIVER_MODEL dev->gadget.dev.driver = 0; -#endif return retval; } -#ifdef HAVE_DRIVER_MODEL // FIXME // driver_register (&driver->driver); // device_register (&dev->gadget.dev); -#endif device_create_file (&dev->pdev->dev, &dev_attr_function); device_create_file (&dev->pdev->dev, &dev_attr_queues); @@ -2501,14 +2490,10 @@ dev->pdev = pdev; dev->gadget.ops = &net2280_ops; -#ifdef HAVE_DRIVER_MODEL strcpy (dev->gadget.dev.bus_id, pdev->slot_name); strcpy (dev->gadget.dev.name, pdev->dev.name); dev->gadget.dev.parent = &pdev->dev; dev->gadget.dev.dma_mask = pdev->dev.dma_mask; -#else - dev->gadget.dev.bus_id = pdev->slot_name; -#endif dev->gadget.name = driver_name; /* now all the pci goodies ... */ @@ -2601,9 +2586,7 @@ , &dev->pci->pcimstctl); /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */ pci_set_master (pdev); -#ifdef HAVE_PCI_SET_MWI pci_set_mwi (pdev); -#endif /* ... also flushes any posted pci writes */ dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff; diff -Nru a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c --- a/drivers/usb/gadget/usbstring.c Thu May 8 14:31:32 2003 +++ b/drivers/usb/gadget/usbstring.c Thu May 8 14:31:32 2003 @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff -Nru a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c --- a/drivers/usb/gadget/zero.c Thu May 8 14:31:32 2003 +++ b/drivers/usb/gadget/zero.c Thu May 8 14:31:32 2003 @@ -77,6 +77,8 @@ #include #include #include +#include +#include #include #include @@ -259,14 +261,8 @@ struct usb_ep *in_ep, *out_ep; }; -#ifdef HAVE_DRIVER_MODEL -#define xprintk(dev,level,fmt,args...) \ - dev_printk(level , &dev->gadget->dev , fmt , ## args) -#else -#define xprintk(dev,level,fmt,args...) \ - printk(level "%s %s: " fmt , shortname, dev->gadget->dev.bus_id, \ - ## args) -#endif /* HAVE_DRIVER_MODEL */ +#define xprintk(d,level,fmt,args...) \ + dev_printk(level , &(d)->gadget->dev , fmt , ## args) #ifdef DEBUG #undef DEBUG @@ -296,6 +292,9 @@ static unsigned buflen = 4096; static unsigned qlen = 32; +module_param (buflen, uint, S_IRUGO|S_IWUSR); +module_param (qlen, uint, S_IRUGO|S_IWUSR); + /* * Normally the "loopback" configuration is second (index 1) so * it's not the default. Here's where to change that order, to @@ -304,25 +303,7 @@ */ static int loopdefault = 0; -#ifdef HAVE_DRIVER_MODEL -#include - -module_param (buflen, uint, 0); -module_param (qlen, uint, 0); -module_param (loopdefault, bool, 0); - -#else - -MODULE_PARM (buflen, "i"); -MODULE_PARM_DESC (buflen, "size of i/o buffers"); - -MODULE_PARM (qlen, "i"); -MODULE_PARM_DESC (qlen, "depth of loopback buffering"); - -MODULE_PARM (loopdefault, "b"); -MODULE_PARM_DESC (loopdefault, "true to have default config be loopback"); - -#endif /* HAVE_DRIVER_MODEL */ +module_param (loopdefault, bool, S_IRUGO|S_IWUSR); /*-------------------------------------------------------------------------*/ @@ -984,12 +965,10 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) { - if (req->status || req->actual != req->length) { - struct zero_dev *dev = ep->driver_data; - - DEBUG (dev, "setup complete --> %d, %d/%d\n", + if (req->status || req->actual != req->length) + DEBUG ((struct zero_dev *) ep->driver_data, + "setup complete --> %d, %d/%d\n", req->status, req->actual, req->length); - } } /* diff -Nru a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h --- a/include/linux/usb_gadget.h Thu May 8 14:31:32 2003 +++ b/include/linux/usb_gadget.h Thu May 8 14:31:32 2003 @@ -435,11 +435,6 @@ unsigned code, unsigned long param); }; -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,50) -#define HAVE_DRIVER_MODEL -#include -#endif - /** * struct usb_gadget - represents a usb slave device * @ep0: Endpoint zero, used when reading or writing responses to @@ -469,47 +464,21 @@ enum usb_device_speed speed; const char *name; -#ifdef HAVE_DRIVER_MODEL - /* with 2.5 "generic dma" api, use this to allocate dma-coherent - * buffers or set up dma mappings. or print diagnostics, etc. + /* use this to allocate dma-coherent buffers or set up + * dma mappings. or print diagnostics, etc. */ struct device dev; -#else - struct __gadget_device { - char *bus_id; - void *driver_data; - } dev; -#endif }; -#ifdef HAVE_DRIVER_MODEL static inline void set_gadget_data (struct usb_gadget *gadget, void *data) { dev_set_drvdata (&gadget->dev, data); } static inline void *get_gadget_data (struct usb_gadget *gadget) { return dev_get_drvdata (&gadget->dev); } -#else -static inline void set_gadget_data (struct usb_gadget *gadget, void *data) - { gadget->dev.driver_data = data; } -static inline void *get_gadget_data (struct usb_gadget *gadget) - { return gadget->dev.driver_data; } - -#endif - /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ #define gadget_for_each_ep(tmp,gadget) \ list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) -#ifndef list_for_each_entry -/* not available in 2.4.18 */ -#define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - prefetch(pos->member.next); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member), \ - prefetch(pos->member.next)) -#endif - /** * usb_gadget_frame_number - returns the current frame number @@ -649,14 +618,7 @@ void (*resume)(struct usb_gadget *); // FIXME support safe rmmod -#ifdef HAVE_DRIVER_MODEL struct device_driver driver; -#else - struct __gadget_driver { - char *name; - void *driver_data; - } driver; -#endif };