ChangeSet 1.1172, 2003/04/29 15:30:55-07:00, david-b@pacbell.net

[PATCH] USB: usbnet, config changes for CDC Ether

This patch changes how usbnet and CDC Ether get configured,
switching to the newer implementation with that CDC model
(using a "minidriver" for "usbnet").

  - Removes "cdc-ether" from Kconfig and Makefile.
    Once everything flies, "cdc-ether.c" can be
    removed from the kernel.

  - Makes all the "minidriver" options in "usbnet"
    explicit in Kconfig, defaulting to "y" for most
    cases.  So folk expecting a CDC Ether option in
    Kconfig will still have one, and during config
    a list of hardware (cables, PDAs, etc) using the
    "usbnet" driver is now available.  (It's possible
    to save a few pages of code by configuring out
    drivers that use custom framing.)

  - Since now it's possible to create broken configs,
    this checks for them.  The two basic errors being
    configuring "usbnet" with no minidrivers, and
    needing to blacklist Zaurus in CDC-only configs.

  - Zaurus shouldn't do full CDC style init, since it
    doesn't uniquify the Ethernet address it reports;
    and it still shouldn't come up as an "eth%d" link.

The CDC support is still "experimental", since I want
to see a few interop reports for commercial products
before changing that.


diff -Nru a/drivers/usb/Makefile b/drivers/usb/Makefile
--- a/drivers/usb/Makefile	Wed Apr 30 13:34:13 2003
+++ b/drivers/usb/Makefile	Wed Apr 30 13:34:13 2003
@@ -36,7 +36,6 @@
 obj-$(CONFIG_USB_VICAM)		+= media/
 
 obj-$(CONFIG_USB_CATC)		+= net/
-obj-$(CONFIG_USB_CDCETHER)	+= net/
 obj-$(CONFIG_USB_KAWETH)	+= net/
 obj-$(CONFIG_USB_PEGASUS)	+= net/
 obj-$(CONFIG_USB_RTL8150)	+= net/
diff -Nru a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
--- a/drivers/usb/net/Kconfig	Wed Apr 30 13:34:13 2003
+++ b/drivers/usb/net/Kconfig	Wed Apr 30 13:34:13 2003
@@ -28,30 +28,6 @@
 	  The module will be called catc. If you want to compile it as a
 	  module, say M here and read <file:Documentation/modules.txt>.
 
-config USB_CDCETHER
-	tristate "USB CDC Ethernet support (EXPERIMENTAL)"
-	depends on USB && NET && EXPERIMENTAL
-	---help---
-	  This driver supports devices conforming to the Communication Device
-	  Class Ethernet Control Model.  This is used in some cable modems.
-	  For more details on the specification, get the Communication Device
-	  Class specification from <http://www.usb.org/>.
-
-	  This driver should work with the following devices:
-	  * Ericsson PipeRider (all variants)
-	  * Motorola (DM100 and SB4100)
-	  * Broadcom Cable Modem (reference design)
-	  * Toshiba PCX1100U and possibly other cable modems
-
-	  The device creates a network device (ethX, where X depends on what
-	  other networking devices you have in use), as for a normal PCI
-	  or ISA based ethernet network card.
-
-	  This code is also available as a module ( = code which can be
-	  inserted in and removed from the running kernel whenever you want).
-	  The module will be called cdc-ether.  If you want to compile it 
-	  as a module, say M here and read <file:Documentation/modules.txt>.
-
 config USB_KAWETH
 	tristate "USB KLSI KL5USB101-based ethernet device support"
 	depends on USB && NET
@@ -124,26 +100,147 @@
 	  module, say M here and read <file:Documentation/modules.txt>.
 
 config USB_USBNET
-	tristate "USB-to-USB Networking for cables, PDAs and other devices"
+	tristate "Host-to-Host Networking for Cables and Smart Devices"
 	depends on USB && NET
 	---help---
-	  This driver supports network links over USB with USB "Network"
-	  or "data transfer" cables, often used to network laptops to PCs.
-	  Such cables have chips from suppliers such as Belkin/eTEK, GeneSys
-	  (GeneLink), NetChip and Prolific.  Some motherboards with USB PC2PC
-	  support include such chips.
-	  
-	  Intelligent USB devices, such as PDAs running Linux (like Yopy
-	  and Zaurus, or iPaqs after upgrading to Linux) can use the same
-	  approach to provide Internet access.
-
-	  These links will have names like "usb0", "usb1", etc.  They act
-	  like two-node Ethernets, so you can use 802.1d Ethernet Bridging
-	  (CONFIG_BRIDGE) to simplify your network routing.  For more
-	  information see <http://www.linux-usb.org/usbnet/>.
+	  This driver supports several kinds of network links over USB,
+	  with "minidrivers" built around a common network driver core
+	  that supports deep queues for efficient transfers.
+
+	  Typically, these links involves only two network hosts.  The
+	  host runs "usbnet", and the other end of the link might be:
+
+	  - Another USB host, when using USB "network" or "data transfer"
+	    cables.  These are often used to network laptops to PCs, like
+	    "Laplink" parallel cables or some motherboards.  These rely
+	    on specialized chips from many suppliers.
+
+	  - An intelligent USB gadget, perhaps embedding a Linux system.
+	    These include PDAs running Linux (iPaq, Yopy, Zaurus, and
+	    others), and devices that interoperate using the standard
+	    CDC-Ethernet specification (including many cable modems).
+
+	  The link will appear with a name like "usb0", when the link is
+	  a two-node link, or "eth0" for most CDC-Ethernet devices.  Those
+	  two-node links are most easily managed with Ethernet Bridging
+	  (CONFIG_BRIDGE) instead of routing.
+
+	  For more information see <http://www.linux-usb.org/usbnet/>.
 
 	  This code is also available as a kernel module (code which can be
 	  inserted in and removed from the running kernel whenever you want).
 	  The module will be called usbnet. If you want to compile it as a
 	  module, say M here and read <file:Documentation/modules.txt>.
+
+comment "USB Host-to-Host Cables"
+	depends on USB_USBNET
+
+config USB_AN2720
+	boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)"
+	depends on USB_USBNET
+	default y
+	help
+	  Choose this option if you're using a host-to-host cable
+	  based on this design.  Note that AnchorChips is now a
+	  Cypress brand.
+
+config USB_BELKIN
+	boolean "eTEK based host-to-host cables (Advance, Belkin, ...)"
+	depends on USB_USBNET
+	default y
+	help
+	  Choose this option if you're using a host-to-host cable
+	  based on this design:  two NetChip 2890 chips and an Atmel
+	  microcontroller, with LEDs that indicate traffic.
+
+config USB_GENESYS
+	boolean "GeneSys GL620USB-A based cables"
+	default y
+	depends on USB_USBNET
+	help
+	  Choose this option if you're using a host-to-host cable,
+	  or PC2PC motherboard, with this chip.
+
+	  Note that the half-duplex "GL620USB" is not supported.
+
+config USB_NET1080
+	boolean "NetChip 1080 based cables (Laplink, ...)"
+	default y
+	depends on USB_USBNET
+	help
+	  Choose this option if you're using a host-to-host cable based
+	  on this design:  one NetChip 1080 chips and supporting logic,
+	  supporting LEDs that indicate traffic
+
+config USB_PL2301
+	boolean "Prolific PL-2301/2302 based cables"
+	default y
+	# handshake/init/reset problems, from original 'plusb' driver
+	depends on USB_USBNET && EXPERIMENTAL
+	help
+	  Choose this option if you're using a host-to-host cable
+	  with one of these chips.
+
+comment "Intelligent USB Devices/Gadgets"
+	depends on USB_USBNET
+
+config USB_ARMLINUX
+	boolean "Embedded ARM Linux links (iPaq, ...)"
+	depends on USB_USBNET
+	default y
+	help
+	  Choose this option to support the "usb-eth" networking driver
+	  used by most of the ARM Linux community with device controllers
+	  such as the SA-11x0 and PXA-25x UDCs.
+
+	  Although the ROMs shipped with Sharp Zaurus products use a
+	  different link level framing protocol, you can have them use
+	  this simpler protocol by installing a different kernel.
+
+config USB_EPSON2888
+	boolean "Epson 2888 based firmware (DEVELOPMENT)"
+	depends on USB_USBNET
+	default y
+	help
+	  Choose this option to support the usb networking links used
+	  by some sample firmware from Epson.
+
+config USB_ZAURUS
+	boolean "Sharp Zaurus (stock ROMs)"
+	depends on USB_USBNET
+	default y
+	help
+	  Choose this option to support the usb networking links used by
+	  Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
+
+	  If you install an alternate ROM image, you may no longer need
+	  to support this protocol.  Only the "eth-fd" driver really needs
+	  this non-conformant variant of CDC Ethernet protocol.
+
+config USB_CDCETHER
+	boolean "CDC Ethernet support (smart devices such as cable modems)"
+	# experimental primarily because cdc-ether was.
+	# make it non-experimental after more interop testing
+	depends on USB_USBNET && EXPERIMENTAL
+	default y
+	help
+	  This option supports devices conforming to the Communication Device
+	  Class (CDC) Ethernet Control Model, a specification that's easy to
+	  implement in device firmware.  The CDC specifications are available
+	  from <http://www.usb.org/>.
+	  
+	  CDC Ethernet is an implementation option for DOCSIS cable modems
+	  that support USB connectivity, used for non-Microsoft USB hosts.
+ 	  This driver should work with at least the following devices:
+
+ 	    * Ericsson PipeRider (all variants)
+ 	    * Motorola (DM100 and SB4100)
+ 	    * Broadcom Cable Modem (reference design)
+ 	    * Toshiba PCX1100U
+	    * ...
+
+	  This driver creates an interface named "ethX", where X depends on
+	  what other networking devices you have in use.  However, if the
+	  IEEE 802 "local assignment" bit is set in the address, a "usbX"
+	  name is used instead.
 
diff -Nru a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile
--- a/drivers/usb/net/Makefile	Wed Apr 30 13:34:12 2003
+++ b/drivers/usb/net/Makefile	Wed Apr 30 13:34:12 2003
@@ -3,7 +3,6 @@
 #
 
 obj-$(CONFIG_USB_CATC)		+= catc.o
-obj-$(CONFIG_USB_CDCETHER)	+= cdc-ether.o
 obj-$(CONFIG_USB_KAWETH)	+= kaweth.o
 obj-$(CONFIG_USB_PEGASUS)	+= pegasus.o
 obj-$(CONFIG_USB_RTL8150)	+= rtl8150.o
diff -Nru a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
--- a/drivers/usb/net/usbnet.c	Wed Apr 30 13:34:12 2003
+++ b/drivers/usb/net/usbnet.c	Wed Apr 30 13:34:13 2003
@@ -157,20 +157,7 @@
 #include <linux/dma-mapping.h>
 
 
-/* minidrivers _could_ be individually configured */
-#define	CONFIG_USB_AN2720
-#define	CONFIG_USB_BELKIN
-#undef	CONFIG_USB_CDCETHER
-//#define	CONFIG_USB_CDCETHER		/* NYET */
-#define	CONFIG_USB_EPSON2888
-#define	CONFIG_USB_GENESYS
-#define	CONFIG_USB_NET1080
-#define	CONFIG_USB_PL2301
-#define	CONFIG_USB_ARMLINUX
-#define	CONFIG_USB_ZAURUS
-
-
-#define DRIVER_VERSION		"31-Mar-2003"
+#define DRIVER_VERSION		"25-Apr-2003"
 
 /*-------------------------------------------------------------------------*/
 
@@ -256,6 +243,7 @@
 #define FLAG_FRAMING_Z	0x0004		/* zaurus adds a trailer */
 
 #define FLAG_NO_SETINT	0x0010		/* device can't set_interface() */
+#define FLAG_ETHER	0x0020		/* maybe use "eth%d" names */
 
 	/* init device ... can sleep, or cause probe() failure */
 	int	(*bind)(struct usbnet *, struct usb_interface *);
@@ -396,6 +384,7 @@
 
 
 #ifdef	CONFIG_USB_AN2720
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -421,6 +410,7 @@
 
 
 #ifdef	CONFIG_USB_BELKIN
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -447,7 +437,11 @@
  * Takes two interfaces.  The DATA interface is inactive till an altsetting
  * is selected.  Configuration data includes class descriptors.
  *
- * Zaurus uses nonstandard framing, but is otherwise CDC Ether.
+ * Zaurus uses nonstandard framing, and doesn't uniquify its Ethernet
+ * addresses, but is otherwise CDC Ether.
+ *
+ * This should interop with whatever the 2.4 "CDCEther.c" driver
+ * (by Brad Hards) talked with.
  *
  *-------------------------------------------------------------------------*/
 
@@ -589,9 +583,17 @@
 	if (!info->header || !info ->u || !info->ether)
 		goto bad_desc;
 
-	status = get_ethernet_addr (dev, info->ether);
-	if (status < 0)
-		return status;
+#ifdef CONFIG_USB_ZAURUS
+	/* Zaurus ethernet addresses aren't unique ... */
+	if ((dev->driver_info->flags & FLAG_FRAMING_Z) != 0)
+		/* ignore */ ;
+	else
+#endif
+	{
+		status = get_ethernet_addr (dev, info->ether);
+		if (status < 0)
+			return status;
+	}
 
 	/* claim data interface and set it up ... with side effects.
 	 * network traffic can't flow until an altsetting is enabled.
@@ -609,8 +611,6 @@
 
 	dev->net.mtu = cpu_to_le16p (&info->ether->wMaxSegmentSize)
 		- ETH_HLEN;
-	if ((dev->driver_info->flags & FLAG_FRAMING_Z) == 0)
-		strcpy (dev->net.name, "eth%d");
 	return 0;
 
 bad_desc:
@@ -640,9 +640,11 @@
 
 
 #ifdef	CONFIG_USB_CDCETHER
+#define	HAVE_HARDWARE
 
 static const struct driver_info	cdc_info = {
 	.description =	"CDC Ethernet Device",
+	.flags =	FLAG_ETHER,
 	// .check_connect = cdc_check_connect,
 	.bind =		cdc_bind,
 	.unbind =	cdc_unbind,
@@ -653,6 +655,7 @@
 
 
 #ifdef	CONFIG_USB_EPSON2888
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -663,6 +666,8 @@
  * implements this interface.  Product developers can reuse or modify that
  * code, such as by using their own product and vendor codes.
  *
+ * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
+ *
  *-------------------------------------------------------------------------*/
 
 static const struct driver_info	epson2888_info = {
@@ -676,6 +681,7 @@
 
 
 #ifdef CONFIG_USB_GENESYS
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -693,6 +699,9 @@
  *    the transfer direction.  (That's disabled here, partially coded.)
  *    A control URB would block until other side writes an interrupt.
  *
+ * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
+ * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
+ *
  *-------------------------------------------------------------------------*/
 
 // control msg write command
@@ -1011,6 +1020,7 @@
 
 
 #ifdef	CONFIG_USB_NET1080
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -1526,11 +1536,15 @@
 
 
 #ifdef CONFIG_USB_PL2301
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
  * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
  *
+ * The protocol and handshaking used here should be bug-compatible
+ * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
+ *
  *-------------------------------------------------------------------------*/
 
 /*
@@ -1590,6 +1604,7 @@
 
 
 #ifdef	CONFIG_USB_ARMLINUX
+#define	HAVE_HARDWARE
 
 /*-------------------------------------------------------------------------
  *
@@ -1622,6 +1637,7 @@
 
 
 #ifdef CONFIG_USB_ZAURUS
+#define	HAVE_HARDWARE
 
 #include <linux/crc32.h>
 
@@ -1736,7 +1752,9 @@
 
 /*-------------------------------------------------------------------------*/
 
-/* urb completions may be in_irq; avoid doing real work then. */
+/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
+ * completion callbacks.  2.5 should have fixed those bugs...
+ */
 
 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
 {
@@ -2502,6 +2520,10 @@
 	int				status;
 
 	info = (struct driver_info *) prod->driver_info;
+	if (!info) {
+		dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
+		return -ENODEV;
+	}
 	xdev = interface_to_usbdev (udev);
 	interface = &udev->altsetting [udev->act_altsetting];
 
@@ -2553,9 +2575,15 @@
 
 	// allow device-specific bind/init procedures
 	// NOTE net->name still not usable ...
-	if (info->bind)
+	if (info->bind) {
 		status = info->bind (dev, udev);
-	else if (!info->in || info->out)
+		// heuristic:  "usb%d" for links we know are two-host,
+		// else "eth%d" when there's reasonable doubt.  userspace
+		// can rename the link if it knows better.
+		if ((dev->driver_info->flags & FLAG_ETHER) != 0
+				&& (net->dev_addr [0] & 0x02) == 0)
+			strcpy (net->name, "eth%d");
+	} else if (!info->in || info->out)
 		status = get_endpoints (dev, udev);
 	else {
 		dev->in = usb_rcvbulkpipe (xdev, info->in);
@@ -2592,6 +2620,10 @@
 
 /*-------------------------------------------------------------------------*/
 
+#ifndef	HAVE_HARDWARE
+#error You need to configure some hardware for this driver
+#endif
+
 /*
  * chip vendor names won't normally be on the cables, and
  * may not be on the device.
@@ -2716,6 +2748,22 @@
 #endif
 
 #ifdef	CONFIG_USB_CDCETHER
+
+#ifndef	CONFIG_USB_ZAURUS
+	/* if we couldn't whitelist Zaurus, we must blacklist it */
+{
+	.match_flags	=   USB_DEVICE_ID_MATCH_INT_INFO
+			  | USB_DEVICE_ID_MATCH_DEVICE, 
+	.idVendor		= 0x04DD,
+	.idProduct		= 0x8004,
+	/* match the master interface */
+	.bInterfaceClass	= USB_CLASS_COMM,
+	.bInterfaceSubClass	= 6 /* Ethernet model */,
+	.bInterfaceProtocol	= 0,
+	.driver_info 		= 0, /* BLACKLIST */
+},
+#endif
+
 {
 	/* CDC Ether uses two interfaces, not necessarily consecutive.
 	 * We match the main interface, ignoring the optional device
@@ -2725,10 +2773,7 @@
 	 * NOTE:  this match must come AFTER entries working around
 	 * bugs/quirks in a given product (like Zaurus, above).
 	 */
-	.match_flags		= USB_DEVICE_ID_MATCH_INT_INFO,
-	.bInterfaceClass	= USB_CLASS_COMM,
-	.bInterfaceSubClass	= 6 /* Ethernet model */,
-	.bInterfaceProtocol	= 0,
+	USB_INTERFACE_INFO (USB_CLASS_COMM, 6 /* Ethernet model */, 0),
 	.driver_info = (unsigned long) &cdc_info,
 },
 #endif
