ChangeSet 1.1474.148.7, 2004/01/23 15:39:36-08:00, david-b@pacbell.net [PATCH] USB gadget: ethernet config updates Autoconfigure ep0 maxpacket size, and simplify configuration for device power consumption. Use new boolean CONFIG_* symbols. SuperH UDC support. drivers/usb/gadget/ether.c | 98 ++++++++++++++++++++++++++------------------- 1 files changed, 57 insertions(+), 41 deletions(-) diff -Nru a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c --- a/drivers/usb/gadget/ether.c Tue Jan 27 15:14:07 2004 +++ b/drivers/usb/gadget/ether.c Tue Jan 27 15:14:07 2004 @@ -122,12 +122,9 @@ * * CHIP ... hardware identifier * DRIVER_VERSION_NUM ... alerts the host side driver to differences - * EP0_MAXPACKET ... controls packetization of control requests * EP_*_NAME ... which endpoints do we use for which purpose? * EP_*_NUM ... numbers for them (often limited by hardware) * HIGHSPEED ... define if ep0 and descriptors need high speed support - * MAX_USB_POWER ... define if we use other than 100 mA bus current - * SELFPOWER ... unless we can run on bus power, USB_CONFIG_ATT_SELFPOWER * WAKEUP ... if hardware supports remote wakeup AND we will issue the * usb_gadget_wakeup() call to initiate it, USB_CONFIG_ATT_WAKEUP * @@ -143,6 +140,9 @@ /* #undef on hardware that can't implement CDC */ #define DEV_CONFIG_CDC +/* undef on bus-powered hardware, and #define MAX_USB_POWER */ +#define SELFPOWER + /* * NetChip 2280, PCI based. * @@ -152,11 +152,10 @@ * performance note: only PIO needs per-usb-packet IRQs (ep0, ep-e, ep-f) * otherwise IRQs are per-Ethernet-packet unless TX_DELAY and chaining help. */ -#ifdef CONFIG_USB_ETH_NET2280 +#ifdef CONFIG_USB_GADGET_NET2280 #define CHIP "net2280" #define DEFAULT_QLEN 4 /* has dma chaining */ #define DRIVER_VERSION_NUM 0x0101 -#define EP0_MAXPACKET 64 static const char EP_OUT_NAME [] = "ep-a"; #define EP_OUT_NUM 1 static const char EP_IN_NAME [] = "ep-b"; @@ -164,8 +163,6 @@ static const char EP_STATUS_NAME [] = "ep-f"; #define EP_STATUS_NUM 3 #define HIGHSPEED -/* specific hardware configs could be bus-powered */ -#define SELFPOWER USB_CONFIG_ATT_SELFPOWER /* supports remote wakeup, but this driver doesn't */ extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); @@ -186,17 +183,14 @@ * multiple interfaces (or altsettings) aren't usable. so this hardware * can't implement CDC, which needs both capabilities. */ -#ifdef CONFIG_USB_ETH_PXA2XX +#ifdef CONFIG_USB_GADGET_PXA2XX #undef DEV_CONFIG_CDC #define CHIP "pxa2xx" #define DRIVER_VERSION_NUM 0x0103 -#define EP0_MAXPACKET 16 static const char EP_OUT_NAME [] = "ep2out-bulk"; #define EP_OUT_NUM 2 static const char EP_IN_NAME [] = "ep1in-bulk"; #define EP_IN_NUM 1 -/* doesn't support bus-powered operation */ -#define SELFPOWER USB_CONFIG_ATT_SELFPOWER /* supports remote wakeup, but this driver doesn't */ /* no hw optimizations to apply */ @@ -209,17 +203,14 @@ * can't have a notification endpoint, since there are only the two * bulk-capable ones. the CDC spec allows that. */ -#ifdef CONFIG_USB_ETH_SA1100 +#ifdef CONFIG_USB_GADGET_SA1100 #define CHIP "sa1100" #define DRIVER_VERSION_NUM 0x0105 -#define EP0_MAXPACKET 8 static const char EP_OUT_NAME [] = "ep1out-bulk"; #define EP_OUT_NUM 1 static const char EP_IN_NAME [] = "ep2in-bulk"; #define EP_IN_NUM 2 // EP_STATUS_NUM is undefined -/* doesn't support bus-powered operation */ -#define SELFPOWER USB_CONFIG_ATT_SELFPOWER /* doesn't support remote wakeup? */ /* no hw optimizations to apply */ @@ -231,25 +222,43 @@ * * This has three semi-configurable full speed bulk/interrupt endpoints. */ -#ifdef CONFIG_USB_ETH_GOKU +#ifdef CONFIG_USB_GADGET_GOKU #define CHIP "goku" #define DRIVER_VERSION_NUM 0x0106 -#define EP0_MAXPACKET 8 static const char EP_OUT_NAME [] = "ep1-bulk"; #define EP_OUT_NUM 1 static const char EP_IN_NAME [] = "ep2-bulk"; #define EP_IN_NUM 2 static const char EP_STATUS_NAME [] = "ep3-bulk"; #define EP_STATUS_NUM 3 -#define SELFPOWER USB_CONFIG_ATT_SELFPOWER /* doesn't support remote wakeup */ #define hw_optimize(g) do {} while (0) #endif +/* + * SuperH UDC: UDC built-in to some Renesas SH processors. + * + * This has three semi-configurable full speed bulk/interrupt endpoints. + * + * Only one configuration and interface is supported. So this hardware + * can't implement CDC. + */ +#ifdef CONFIG_USB_GADGET_SUPERH +#undef DEV_CONFIG_CDC +#define CHIP "superh" +#define DRIVER_VERSION_NUM 0x0107 +static const char EP_OUT_NAME[] = "ep1out-bulk"; +#define EP_OUT_NUM 1 +static const char EP_IN_NAME[] = "ep2in-bulk"; +#define EP_IN_NUM 2 + +#define hw_optimize(g) do {} while (0) +#endif + /*-------------------------------------------------------------------------*/ -#ifndef EP0_MAXPACKET +#ifndef CHIP # error Configure some USB peripheral controller driver! #endif @@ -280,19 +289,15 @@ * hardware that supports remote wakeup defaults to disabling it. */ -#ifndef SELFPOWER -/* default: say we rely on bus power */ -#define SELFPOWER 0 -/* else: - * - SELFPOWER value must be USB_CONFIG_ATT_SELFPOWER - * - MAX_USB_POWER may be nonzero. - */ -#endif - #ifndef MAX_USB_POWER -/* any hub supports this steady state bus power consumption */ -#define MAX_USB_POWER 100 /* mA */ +#ifdef SELFPOWER +/* some hosts are confused by 0mA */ +#define MAX_USB_POWER 2 /* mA */ +#else +/* bus powered */ +#error Define your bus power consumption! #endif +#endif /* MAX_USB_POWER */ #ifndef WAKEUP /* default: this driver won't do remote wakeup */ @@ -376,7 +381,7 @@ /* * This device advertises one configuration. */ -static const struct usb_device_descriptor +static struct usb_device_descriptor device_desc = { .bLength = sizeof device_desc, .bDescriptorType = USB_DT_DEVICE, @@ -386,7 +391,6 @@ .bDeviceClass = DEV_CONFIG_CLASS, .bDeviceSubClass = 0, .bDeviceProtocol = 0, - .bMaxPacketSize0 = EP0_MAXPACKET, .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM), .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM), @@ -396,7 +400,7 @@ .bNumConfigurations = 1, }; -static const struct usb_config_descriptor +static struct usb_config_descriptor eth_config = { .bLength = sizeof eth_config, .bDescriptorType = USB_DT_CONFIG, @@ -409,7 +413,7 @@ #endif .bConfigurationValue = DEV_CONFIG_VALUE, .iConfiguration = STRING_PRODUCT, - .bmAttributes = USB_CONFIG_ATT_ONE | SELFPOWER | WAKEUP, + .bmAttributes = USB_CONFIG_ATT_ONE | WAKEUP, .bMaxPower = (MAX_USB_POWER + 1) / 2, }; @@ -645,7 +649,7 @@ .bInterval = 1, }; -static const struct usb_qualifier_descriptor +static struct usb_qualifier_descriptor dev_qualifier = { .bLength = sizeof dev_qualifier, .bDescriptorType = USB_DT_DEVICE_QUALIFIER, @@ -653,12 +657,10 @@ .bcdUSB = __constant_cpu_to_le16 (0x0200), .bDeviceClass = DEV_CONFIG_CLASS, - /* assumes ep0 uses the same value for both speeds ... */ - .bMaxPacketSize0 = EP0_MAXPACKET, - .bNumConfigurations = 1, }; + /* maxpacket and other transfer characteristics vary by speed. */ #define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs)) @@ -959,7 +961,7 @@ if (number == dev->config) return 0; -#ifdef CONFIG_USB_ETH_SA1100 +#ifdef CONFIG_USB_GADGET_SA1100 if (dev->config && atomic_read (&dev->tx_qlen) != 0) { /* tx fifo is full, but we can't clear it...*/ INFO (dev, "can't change configurations\n"); @@ -1006,6 +1008,7 @@ /* section 3.8.2 table 11 of the CDC spec lists Ethernet notifications */ #define CDC_NOTIFY_NETWORK_CONNECTION 0x00 /* required; 6.3.1 */ +#define CDC_NOTIFY_RESPONSE_AVAILABLE 0x01 /* optional; 6.3.2 */ #define CDC_NOTIFY_SPEED_CHANGE 0x2a /* required; 6.3.8 */ struct cdc_notification { @@ -1123,6 +1126,8 @@ /* see section 3.8.2 table 10 of the CDC spec for more ethernet * requests, mostly for filters (multicast, pm) and statistics */ +#define CDC_SEND_ENCAPSULATED_REQUEST 0x00 /* optional */ +#define CDC_GET_ENCAPSULATED_RESPONSE 0x01 /* optional */ #define CDC_SET_ETHERNET_PACKET_FILTER 0x43 /* required */ /* @@ -1188,7 +1193,7 @@ value = eth_set_config (dev, ctrl->wValue, GFP_ATOMIC); spin_unlock (&dev->lock); break; -#ifdef CONFIG_USB_ETH_PXA2XX +#ifdef CONFIG_USB_GADGET_PXA2XX /* PXA UDC prevents us from using SET_INTERFACE in normal ways. * And it hides GET_CONFIGURATION and GET_INTERFACE too. */ @@ -1638,7 +1643,7 @@ req->context = skb; req->complete = tx_complete; -#ifdef CONFIG_USB_ETH_SA1100 +#ifdef CONFIG_USB_GADGET_SA1100 /* don't demand zlp (req->zero) support from all hardware */ if ((length % dev->in_ep->maxpacket) == 0) length++; @@ -1768,6 +1773,17 @@ /* just one upstream link at a time */ if (ethaddr [0] != 0) return -ENODEV; +#endif + + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; +#ifdef HIGHSPEED + /* assumes ep0 uses the same value for both speeds ... */ + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0; +#endif + +#ifdef SELFPOWERED + eth_config.bmAttributes |= USB_CONFIG_ATT_SELFPOWERED; + usb_gadget_set_selfpowered (gadget); #endif net = alloc_etherdev (sizeof *dev);