patch-2.4.25 linux-2.4.25/drivers/usb/gadget/ether.c

Next file: linux-2.4.25/drivers/usb/gadget/file_storage.c
Previous file: linux-2.4.25/drivers/usb/gadget/Makefile
Back to the patch index
Back to the overall index

diff -urN linux-2.4.24/drivers/usb/gadget/ether.c linux-2.4.25/drivers/usb/gadget/ether.c
@@ -134,12 +134,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
  *
@@ -155,6 +152,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.
  *
@@ -164,11 +164,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	0x0111
-#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";
@@ -176,8 +175,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);
@@ -193,22 +190,19 @@
 
 /*
  * PXA-2xx UDC:  widely used in second gen Linux-capable ARM PDAs
- * and other products.
+ * and other products.  The IXP-42x UDC is register-compatible.
  *
  * 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	0x0113
-#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 */
@@ -221,17 +215,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	0x0115
-#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 */
@@ -243,25 +234,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	0x0116
-#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	0x0117
+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
 
@@ -292,19 +301,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 */
@@ -388,7 +393,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,
@@ -398,7 +403,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),
@@ -408,7 +412,7 @@
 	.bNumConfigurations =	1,
 };
 
-static const struct usb_config_descriptor
+static struct usb_config_descriptor
 eth_config = {
 	.bLength =		sizeof eth_config,
 	.bDescriptorType =	USB_DT_CONFIG,
@@ -421,7 +425,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,
 };
 
@@ -657,7 +661,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,
@@ -665,12 +669,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))
 
@@ -971,7 +973,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");
@@ -1018,6 +1020,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 {
@@ -1135,6 +1138,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 */
 
 /*
@@ -1200,7 +1205,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.
 	 */
@@ -1650,7 +1655,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++;
@@ -1782,6 +1787,17 @@
 		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);
  	if (!net)
 		return status;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)