3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This is a generic "USB networking" framework that works with several
24 * kinds of full and high speed networking devices:
26 * + USB host-to-host "network cables", used for IP-over-USB links.
27 * These are often used for Laplink style connectivity products.
29 * - Belkin, eTEK (interops with Win32 drivers)
30 * - GeneSys GL620USB-A
31 * - NetChip 1080 (interoperates with NetChip Win32 drivers)
32 * - Prolific PL-2301/2302 (replaces "plusb" driver)
33 * - KC Technology KC2190
35 * + Smart USB devices can support such links directly, using Internet
36 * standard protocols instead of proprietary host-to-device links.
37 * - Linux PDAs like iPaq, Yopy, and Zaurus
38 * - The BLOB boot loader (for diskless booting)
39 * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
40 * - Devices using EPSON's sample USB firmware
41 * - CDC-Ethernet class devices, such as many cable modems
43 * + Adapters to networks such as Ethernet.
44 * - AX8817X based USB 2.0 products
46 * Links to these devices can be bridged using Linux Ethernet bridging.
47 * With minor exceptions, these all use similar USB framing for network
48 * traffic, but need different protocols for control traffic.
50 * USB devices can implement their side of this protocol at the cost
51 * of two bulk endpoints; it's not restricted to "cable" applications.
52 * See the SA1110, Zaurus, or EPSON device/client support in this driver;
53 * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
54 * "g_ether" (in the Linux "gadget" framework) implement that behavior
60 * 13-sep-2000 experimental, new
61 * 10-oct-2000 usb_device_id table created.
62 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
63 * 01-nov-2000 usb_device_id table and probing api update by
64 * Adam J. Richter <adam@yggdrasil.com>.
65 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
66 * and prolific support, isolate net1080-specific bits, cleanup.
67 * fix unlink_urbs oops in D3 PM resume code path.
69 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
70 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
71 * AnchorChips 2720 support (from spec) for testing;
72 * fix bit-ordering problem with ethernet multicast addr
73 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
74 * updates. Oleg Drokin (green@iXcelerator.com)
75 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
76 * expecting cleared skb->cb and framing change to match latest
77 * handhelds.org version (Oleg). Enable device IDs from the
78 * Win32 Belkin driver; other cleanups (db).
79 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
80 * cleanups for problems not yet seen in the field. (db)
81 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
82 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
83 * rx unlinks somehow weren't async; minor cleanup.
84 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
85 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
86 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
87 * tie mostly to (sub)driver info. Workaround some PL-2302
88 * chips that seem to reject SET_INTERFACE requests.
90 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
91 * Level of diagnostics is more configurable; they use device
92 * location (usb_device->devpath) instead of address (2.5).
93 * For tx_fixup, memflags can't be NOIO.
94 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
95 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
96 * Use "locally assigned" IEEE802 address space. (Brad Hards)
97 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
98 * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
99 * cleanups and stubbed PXA-250 support (db), fix for framing
100 * issues on Z, net1080, and gl620a (Toby Milne)
102 * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
103 * vs pxa25x, and CDC Ethernet. Throttle down log floods on
104 * disconnect; other cleanups. (db) Flush net1080 fifos
105 * after several sequential framing errors. (Johannes Erdfelt)
106 * 22-aug-2003 AX8817X support (Dave Hollis).
107 * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
109 * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
111 * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis)
112 *-------------------------------------------------------------------------*/
114 // #define DEBUG // error path messages, extra info
115 // #define VERBOSE // more; success messages
117 #include <linux/config.h>
118 #ifdef CONFIG_USB_DEBUG
121 #include <linux/module.h>
122 #include <linux/sched.h>
123 #include <linux/init.h>
124 #include <linux/netdevice.h>
125 #include <linux/etherdevice.h>
126 #include <linux/ethtool.h>
127 #include <linux/workqueue.h>
128 #include <linux/mii.h>
129 #include <linux/usb.h>
133 #define DRIVER_VERSION "22-Aug-2005"
136 /*-------------------------------------------------------------------------*/
139 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
140 * Several dozen bytes of IPv4 data can fit in two such transactions.
141 * One maximum size Ethernet packet takes twenty four of them.
142 * For high speed, each frame comfortably fits almost 36 max size
143 * Ethernet packets (so queues should be bigger).
145 * REVISIT qlens should be members of 'struct usbnet'; the goal is to
146 * let the USB host controller be busy for 5msec or more before an irq
147 * is required, under load. Jumbograms change the equation.
149 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
150 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
152 // reawaken network queue this soon after stopping; else watchdog barks
153 #define TX_TIMEOUT_JIFFIES (5*HZ)
155 // throttle rx/tx briefly after some faults, so khubd might disconnect()
156 // us (it polls at HZ/4 usually) before we report too many false errors.
157 #define THROTTLE_JIFFIES (HZ/8)
159 // for vendor-specific control operations
160 #define CONTROL_TIMEOUT_MS USB_CTRL_GET_TIMEOUT
163 #define UNLINK_TIMEOUT_MS 3
165 /*-------------------------------------------------------------------------*/
167 // randomly generated ethernet address
168 static u8 node_id [ETH_ALEN];
170 static const char driver_name [] = "usbnet";
172 /* use ethtool to change the level for any given device */
173 static int msg_level = -1;
174 module_param (msg_level, int, 0);
175 MODULE_PARM_DESC (msg_level, "Override default message level");
177 /*-------------------------------------------------------------------------*/
179 static u32 usbnet_get_link (struct net_device *);
181 /* mostly for PDA style devices, which are always connected if present */
182 static int always_connected (struct usbnet *dev)
187 /* handles CDC Ethernet and many other network "bulk data" interfaces */
188 int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
191 struct usb_host_interface *alt = NULL;
192 struct usb_host_endpoint *in = NULL, *out = NULL;
193 struct usb_host_endpoint *status = NULL;
195 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
198 in = out = status = NULL;
199 alt = intf->altsetting + tmp;
201 /* take the first altsetting with in-bulk + out-bulk;
202 * remember any status endpoint, just in case;
203 * ignore other endpoints and altsetttings.
205 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
206 struct usb_host_endpoint *e;
209 e = alt->endpoint + ep;
210 switch (e->desc.bmAttributes) {
211 case USB_ENDPOINT_XFER_INT:
212 if (!(e->desc.bEndpointAddress & USB_DIR_IN))
216 case USB_ENDPOINT_XFER_BULK:
221 if (e->desc.bEndpointAddress & USB_DIR_IN) {
224 else if (intr && !status)
234 if (!alt || !in || !out)
237 if (alt->desc.bAlternateSetting != 0
238 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
239 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
240 alt->desc.bAlternateSetting);
245 dev->in = usb_rcvbulkpipe (dev->udev,
246 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
247 dev->out = usb_sndbulkpipe (dev->udev,
248 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
249 dev->status = status;
252 EXPORT_SYMBOL_GPL(usbnet_get_endpoints);
254 static void intr_complete (struct urb *urb, struct pt_regs *regs);
256 static int init_status (struct usbnet *dev, struct usb_interface *intf)
263 if (!dev->driver_info->status)
266 pipe = usb_rcvintpipe (dev->udev,
267 dev->status->desc.bEndpointAddress
268 & USB_ENDPOINT_NUMBER_MASK);
269 maxp = usb_maxpacket (dev->udev, pipe, 0);
271 /* avoid 1 msec chatter: min 8 msec poll rate */
272 period = max ((int) dev->status->desc.bInterval,
273 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
275 buf = kmalloc (maxp, SLAB_KERNEL);
277 dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL);
278 if (!dev->interrupt) {
282 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
283 buf, maxp, intr_complete, dev, period);
285 "status ep%din, %d bytes period %d\n",
286 usb_pipeendpoint(pipe), maxp, period);
292 /* Passes this packet up the stack, updating its accounting.
293 * Some link protocols batch packets, so their rx_fixup paths
294 * can return clones as well as just modify the original skb.
296 void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
301 skb->protocol = eth_type_trans (skb, dev->net);
302 dev->stats.rx_packets++;
303 dev->stats.rx_bytes += skb->len;
305 if (netif_msg_rx_status (dev))
306 devdbg (dev, "< rx, len %zu, type 0x%x",
307 skb->len + sizeof (struct ethhdr), skb->protocol);
308 memset (skb->cb, 0, sizeof (struct skb_data));
309 status = netif_rx (skb);
310 if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
311 devdbg (dev, "netif_rx status %d", status);
313 EXPORT_SYMBOL_GPL(usbnet_skb_return);
316 /*-------------------------------------------------------------------------
318 * Communications Device Class declarations.
319 * Used by CDC Ethernet, and some CDC variants
321 *-------------------------------------------------------------------------*/
323 #ifdef CONFIG_USB_CDCETHER
324 #define NEED_GENERIC_CDC
327 #ifdef CONFIG_USB_ZAURUS
328 /* Ethernet variant uses funky framing, broken ethernet addressing */
329 #define NEED_GENERIC_CDC
332 #ifdef CONFIG_USB_RNDIS
333 /* ACM variant uses even funkier framing, complex control RPC scheme */
334 #define NEED_GENERIC_CDC
338 #ifdef NEED_GENERIC_CDC
340 #include <linux/usb_cdc.h>
343 struct usb_cdc_header_desc *header;
344 struct usb_cdc_union_desc *u;
345 struct usb_cdc_ether_desc *ether;
346 struct usb_interface *control;
347 struct usb_interface *data;
350 static struct usb_driver usbnet_driver;
353 * probes control interface, claims data interface, collects the bulk
354 * endpoints, activates data interface (if needed), maybe sets MTU.
355 * all pure cdc, except for certain firmware workarounds.
357 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
359 u8 *buf = intf->cur_altsetting->extra;
360 int len = intf->cur_altsetting->extralen;
361 struct usb_interface_descriptor *d;
362 struct cdc_state *info = (void *) &dev->data;
366 if (sizeof dev->data < sizeof *info)
369 /* expect strict spec conformance for the descriptors, but
370 * cope with firmware which stores them in the wrong place
372 if (len == 0 && dev->udev->actconfig->extralen) {
373 /* Motorola SB4100 (and others: Brad Hards says it's
374 * from a Broadcom design) put CDC descriptors here
376 buf = dev->udev->actconfig->extra;
377 len = dev->udev->actconfig->extralen;
380 "CDC descriptors on config\n");
383 /* this assumes that if there's a non-RNDIS vendor variant
384 * of cdc-acm, it'll fail RNDIS requests cleanly.
386 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
388 memset (info, 0, sizeof *info);
389 info->control = intf;
391 if (buf [1] != USB_DT_CS_INTERFACE)
394 /* use bDescriptorSubType to identify the CDC descriptors.
395 * We expect devices with CDC header and union descriptors.
396 * For CDC Ethernet we need the ethernet descriptor.
397 * For RNDIS, ignore two (pointless) CDC modem descriptors
398 * in favor of a complicated OID-based RPC scheme doing what
399 * CDC Ethernet achieves with a simple descriptor.
402 case USB_CDC_HEADER_TYPE:
404 dev_dbg (&intf->dev, "extra CDC header\n");
407 info->header = (void *) buf;
408 if (info->header->bLength != sizeof *info->header) {
409 dev_dbg (&intf->dev, "CDC header len %u\n",
410 info->header->bLength);
414 case USB_CDC_UNION_TYPE:
416 dev_dbg (&intf->dev, "extra CDC union\n");
419 info->u = (void *) buf;
420 if (info->u->bLength != sizeof *info->u) {
421 dev_dbg (&intf->dev, "CDC union len %u\n",
426 /* we need a master/control interface (what we're
427 * probed with) and a slave/data interface; union
428 * descriptors sort this all out.
430 info->control = usb_ifnum_to_if(dev->udev,
431 info->u->bMasterInterface0);
432 info->data = usb_ifnum_to_if(dev->udev,
433 info->u->bSlaveInterface0);
434 if (!info->control || !info->data) {
436 "master #%u/%p slave #%u/%p\n",
437 info->u->bMasterInterface0,
439 info->u->bSlaveInterface0,
443 if (info->control != intf) {
444 dev_dbg (&intf->dev, "bogus CDC Union\n");
445 /* Ambit USB Cable Modem (and maybe others)
446 * interchanges master and slave interface.
448 if (info->data == intf) {
449 info->data = info->control;
450 info->control = intf;
455 /* a data interface altsetting does the real i/o */
456 d = &info->data->cur_altsetting->desc;
457 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
458 dev_dbg (&intf->dev, "slave class %u\n",
463 case USB_CDC_ETHERNET_TYPE:
465 dev_dbg (&intf->dev, "extra CDC ether\n");
468 info->ether = (void *) buf;
469 if (info->ether->bLength != sizeof *info->ether) {
470 dev_dbg (&intf->dev, "CDC ether len %u\n",
471 info->ether->bLength);
474 dev->hard_mtu = le16_to_cpu(
475 info->ether->wMaxSegmentSize);
476 /* because of Zaurus, we may be ignoring the host
477 * side link address we were given.
482 len -= buf [0]; /* bLength */
486 if (!info->header || !info->u || (!rndis && !info->ether)) {
487 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
488 info->header ? "" : "header ",
489 info->u ? "" : "union ",
490 info->ether ? "" : "ether ");
494 /* claim data interface and set it up ... with side effects.
495 * network traffic can't flow until an altsetting is enabled.
497 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
500 status = usbnet_get_endpoints (dev, info->data);
502 /* ensure immediate exit from usbnet_disconnect */
503 usb_set_intfdata(info->data, NULL);
504 usb_driver_release_interface (&usbnet_driver, info->data);
508 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
510 if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
511 struct usb_endpoint_descriptor *desc;
513 dev->status = &info->control->cur_altsetting->endpoint [0];
514 desc = &dev->status->desc;
515 if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
516 || !(desc->bEndpointAddress & USB_DIR_IN)
517 || (le16_to_cpu(desc->wMaxPacketSize)
518 < sizeof (struct usb_cdc_notification))
519 || !desc->bInterval) {
520 dev_dbg (&intf->dev, "bad notification endpoint\n");
524 if (rndis && !dev->status) {
525 dev_dbg (&intf->dev, "missing RNDIS status endpoint\n");
526 usb_set_intfdata(info->data, NULL);
527 usb_driver_release_interface (&usbnet_driver, info->data);
533 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
537 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
539 struct cdc_state *info = (void *) &dev->data;
541 /* disconnect master --> disconnect slave */
542 if (intf == info->control && info->data) {
543 /* ensure immediate exit from usbnet_disconnect */
544 usb_set_intfdata(info->data, NULL);
545 usb_driver_release_interface (&usbnet_driver, info->data);
549 /* and vice versa (just in case) */
550 else if (intf == info->data && info->control) {
551 /* ensure immediate exit from usbnet_disconnect */
552 usb_set_intfdata(info->control, NULL);
553 usb_driver_release_interface (&usbnet_driver, info->control);
554 info->control = NULL;
558 #endif /* NEED_GENERIC_CDC */
561 #ifdef CONFIG_USB_CDCETHER
562 #define HAVE_HARDWARE
564 /*-------------------------------------------------------------------------
566 * Communications Device Class, Ethernet Control model
568 * Takes two interfaces. The DATA interface is inactive till an altsetting
569 * is selected. Configuration data includes class descriptors.
571 * This should interop with whatever the 2.4 "CDCEther.c" driver
572 * (by Brad Hards) talked with.
574 *-------------------------------------------------------------------------*/
576 #include <linux/ctype.h>
579 static void dumpspeed (struct usbnet *dev, __le32 *speeds)
581 if (netif_msg_timer (dev))
582 devinfo (dev, "link speeds: %u kbps up, %u kbps down",
583 __le32_to_cpu(speeds[0]) / 1000,
584 __le32_to_cpu(speeds[1]) / 1000);
587 static void cdc_status (struct usbnet *dev, struct urb *urb)
589 struct usb_cdc_notification *event;
591 if (urb->actual_length < sizeof *event)
594 /* SPEED_CHANGE can get split into two 8-byte packets */
595 if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) {
596 dumpspeed (dev, (__le32 *) urb->transfer_buffer);
600 event = urb->transfer_buffer;
601 switch (event->bNotificationType) {
602 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
603 if (netif_msg_timer (dev))
604 devdbg (dev, "CDC: carrier %s",
605 event->wValue ? "on" : "off");
607 netif_carrier_on(dev->net);
609 netif_carrier_off(dev->net);
611 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
612 if (netif_msg_timer (dev))
613 devdbg (dev, "CDC: speed change (len %d)",
615 if (urb->actual_length != (sizeof *event + 8))
616 set_bit (EVENT_STS_SPLIT, &dev->flags);
618 dumpspeed (dev, (__le32 *) &event[1]);
620 // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
622 deverr (dev, "CDC: unexpected notification %02x!",
623 event->bNotificationType);
628 static u8 nibble (unsigned char c)
630 if (likely (isdigit (c)))
633 if (likely (isxdigit (c)))
639 get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e)
642 unsigned char buf [13];
644 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
646 dev_dbg (&dev->udev->dev,
647 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
652 for (i = tmp = 0; i < 6; i++, tmp += 2)
653 dev->net->dev_addr [i] =
654 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
658 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
661 struct cdc_state *info = (void *) &dev->data;
663 status = generic_cdc_bind (dev, intf);
667 status = get_ethernet_addr (dev, info->ether);
669 usb_set_intfdata(info->data, NULL);
670 usb_driver_release_interface (&usbnet_driver, info->data);
674 /* FIXME cdc-ether has some multicast code too, though it complains
675 * in routine cases. info->ether describes the multicast support.
680 static const struct driver_info cdc_info = {
681 .description = "CDC Ethernet Device",
683 // .check_connect = cdc_check_connect,
685 .unbind = cdc_unbind,
686 .status = cdc_status,
689 #endif /* CONFIG_USB_CDCETHER */
693 #ifdef CONFIG_USB_GENESYS
694 #define HAVE_HARDWARE
696 /*-------------------------------------------------------------------------
698 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
700 * ... should partially interop with the Win32 driver for this hardware
701 * The GeneSys docs imply there's some NDIS issue motivating this framing.
703 * Some info from GeneSys:
704 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
705 * (Some cables, like the BAFO-100c, use the half duplex version.)
706 * - For the full duplex model, the low bit of the version code says
707 * which side is which ("left/right").
708 * - For the half duplex type, a control/interrupt handshake settles
709 * the transfer direction. (That's disabled here, partially coded.)
710 * A control URB would block until other side writes an interrupt.
712 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
713 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
715 *-------------------------------------------------------------------------*/
717 // control msg write command
718 #define GENELINK_CONNECT_WRITE 0xF0
719 // interrupt pipe index
720 #define GENELINK_INTERRUPT_PIPE 0x03
721 // interrupt read buffer size
722 #define INTERRUPT_BUFSIZE 0x08
723 // interrupt pipe interval value
724 #define GENELINK_INTERRUPT_INTERVAL 0x10
725 // max transmit packet number per transmit
726 #define GL_MAX_TRANSMIT_PACKETS 32
728 #define GL_MAX_PACKET_LEN 1514
729 // max receive buffer size
730 #define GL_RCV_BUF_SIZE \
731 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
735 char packet_data [1];
740 struct gl_packet packets;
745 // FIXME: this code is incomplete, not debugged; it doesn't
746 // handle interrupts correctly. interrupts should be generic
747 // code like all other device I/O, anyway.
751 char irq_buf [INTERRUPT_BUFSIZE];
754 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
758 retval = usb_control_msg (dev->udev,
759 usb_sndctrlpipe (dev->udev, 0),
761 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
770 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
772 int status = urb->status;
781 /* this urb is terminated, clean up */
782 dbg("%s - urb shutting down with status: %d",
783 __FUNCTION__, status);
786 dbg("%s - nonzero urb status received: %d",
787 __FUNCTION__, urb->status);
790 status = usb_submit_urb (urb, GFP_ATOMIC);
792 err ("%s - usb_submit_urb failed with result %d",
793 __FUNCTION__, status);
796 static int gl_interrupt_read (struct usbnet *dev)
798 struct gl_priv *priv = dev->priv_data;
801 // issue usb interrupt read
802 if (priv && priv->irq_urb) {
804 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
805 dbg ("gl_interrupt_read: submit fail - %X...", retval);
807 dbg ("gl_interrupt_read: submit success...");
813 // check whether another side is connected
814 static int genelink_check_connect (struct usbnet *dev)
818 dbg ("genelink_check_connect...");
820 // detect whether another side is connected
821 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
822 dbg ("%s: genelink_check_connect write fail - %X",
823 dev->net->name, retval);
827 // usb interrupt read to ack another side
828 if ((retval = gl_interrupt_read (dev)) != 0) {
829 dbg ("%s: genelink_check_connect read fail - %X",
830 dev->net->name, retval);
834 dbg ("%s: genelink_check_connect read success", dev->net->name);
838 // allocate and initialize the private data for genelink
839 static int genelink_init (struct usbnet *dev)
841 struct gl_priv *priv;
843 // allocate the private data structure
844 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
845 dbg ("%s: cannot allocate private data per device",
851 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
852 dbg ("%s: cannot allocate private irq urb per device",
859 usb_fill_int_urb (priv->irq_urb, dev->udev,
860 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
861 priv->irq_buf, INTERRUPT_BUFSIZE,
862 gl_interrupt_complete, 0,
863 GENELINK_INTERRUPT_INTERVAL);
865 // set private data pointer
866 dev->priv_data = priv;
871 // release the private data
872 static int genelink_free (struct usbnet *dev)
874 struct gl_priv *priv = dev->priv_data;
879 // FIXME: can't cancel here; it's synchronous, and
880 // should have happened earlier in any case (interrupt
881 // handling needs to be generic)
883 // cancel irq urb first
884 usb_kill_urb (priv->irq_urb);
887 usb_free_urb (priv->irq_urb);
889 // free the private data structure
897 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
899 struct gl_header *header;
900 struct gl_packet *packet;
901 struct sk_buff *gl_skb;
904 header = (struct gl_header *) skb->data;
906 // get the packet count of the received skb
907 le32_to_cpus (&header->packet_count);
908 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
909 || (header->packet_count < 0)) {
910 dbg ("genelink: invalid received packet count %d",
911 header->packet_count);
915 // set the current packet pointer to the first packet
916 packet = &header->packets;
918 // decrement the length for the packet count size 4 bytes
921 while (header->packet_count > 1) {
922 // get the packet length
923 size = packet->packet_length;
925 // this may be a broken packet
926 if (size > GL_MAX_PACKET_LEN) {
927 dbg ("genelink: invalid rx length %d", size);
931 // allocate the skb for the individual packet
932 gl_skb = alloc_skb (size, GFP_ATOMIC);
935 // copy the packet data to the new skb
936 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
937 usbnet_skb_return (dev, gl_skb);
940 // advance to the next packet
941 packet = (struct gl_packet *)
942 &packet->packet_data [size];
943 header->packet_count--;
945 // shift the data pointer to the next gl_packet
946 skb_pull (skb, size + 4);
949 // skip the packet length field 4 bytes
952 if (skb->len > GL_MAX_PACKET_LEN) {
953 dbg ("genelink: invalid rx length %d", skb->len);
959 static struct sk_buff *
960 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
963 int length = skb->len;
964 int headroom = skb_headroom (skb);
965 int tailroom = skb_tailroom (skb);
969 // FIXME: magic numbers, bleech
970 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
972 if ((!skb_cloned (skb))
973 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
974 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
975 skb->data = memmove (skb->head + (4 + 4*1),
976 skb->data, skb->len);
977 skb->tail = skb->data + skb->len;
980 struct sk_buff *skb2;
981 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
982 dev_kfree_skb_any (skb);
988 // attach the packet count to the header
989 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
990 packet_len = packet_count + 1;
992 // FIXME little endian?
994 *packet_len = length;
997 if ((skb->len % dev->maxpacket) == 0)
1003 static int genelink_bind (struct usbnet *dev, struct usb_interface *intf)
1005 dev->hard_mtu = GL_RCV_BUF_SIZE;
1006 dev->net->hard_header_len += 4;
1010 static const struct driver_info genelink_info = {
1011 .description = "Genesys GeneLink",
1012 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1013 .bind = genelink_bind,
1014 .rx_fixup = genelink_rx_fixup,
1015 .tx_fixup = genelink_tx_fixup,
1020 .check_connect =genelink_check_connect,
1024 #endif /* CONFIG_USB_GENESYS */
1028 #ifdef CONFIG_USB_PL2301
1029 #define HAVE_HARDWARE
1031 /*-------------------------------------------------------------------------
1033 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
1035 * The protocol and handshaking used here should be bug-compatible
1036 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
1038 *-------------------------------------------------------------------------*/
1041 * Bits 0-4 can be used for software handshaking; they're set from
1042 * one end, cleared from the other, "read" with the interrupt byte.
1044 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
1045 /* reserved bit -- rx ready (6) ? */
1046 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
1047 #define PL_RESET_OUT (1<<4) /* reset output pipe */
1048 #define PL_RESET_IN (1<<3) /* reset input pipe */
1049 #define PL_TX_C (1<<2) /* transmission complete */
1050 #define PL_TX_REQ (1<<1) /* transmission received */
1051 #define PL_PEER_E (1<<0) /* peer exists */
1054 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
1056 return usb_control_msg (dev->udev,
1057 usb_rcvctrlpipe (dev->udev, 0),
1059 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1062 CONTROL_TIMEOUT_MS);
1066 pl_clear_QuickLink_features (struct usbnet *dev, int val)
1068 return pl_vendor_req (dev, 1, (u8) val, 0);
1072 pl_set_QuickLink_features (struct usbnet *dev, int val)
1074 return pl_vendor_req (dev, 3, (u8) val, 0);
1077 /*-------------------------------------------------------------------------*/
1079 static int pl_reset (struct usbnet *dev)
1081 /* some units seem to need this reset, others reject it utterly.
1082 * FIXME be more like "naplink" or windows drivers.
1084 (void) pl_set_QuickLink_features (dev,
1085 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
1089 static const struct driver_info prolific_info = {
1090 .description = "Prolific PL-2301/PL-2302",
1091 .flags = FLAG_NO_SETINT,
1092 /* some PL-2302 versions seem to fail usb_set_interface() */
1096 #endif /* CONFIG_USB_PL2301 */
1099 #ifdef CONFIG_USB_ZAURUS
1100 #define HAVE_HARDWARE
1102 #include <linux/crc32.h>
1104 /*-------------------------------------------------------------------------
1106 * Zaurus is also a SA-1110 based PDA, but one using a different driver
1107 * (and framing) for its USB slave/gadget controller than the case above.
1109 * For the current version of that driver, the main way that framing is
1110 * nonstandard (also from perspective of the CDC ethernet model!) is a
1111 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
1112 * haven't been fully worked around. Also, all Zaurii use the same
1113 * default Ethernet address.
1115 * PXA based models use the same framing, and also can't implement
1116 * set_interface properly.
1118 * All known Zaurii lie about their standards conformance. Most lie by
1119 * saying they support CDC Ethernet. Some lie and say they support CDC
1120 * MDLM (as if for access to cell phone modems). Someone, please beat
1121 * on Sharp (and other such vendors) for a while with a cluestick.
1123 *-------------------------------------------------------------------------*/
1125 static struct sk_buff *
1126 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
1129 struct sk_buff *skb2;
1132 if (!skb_cloned (skb)) {
1133 int tailroom = skb_tailroom (skb);
1134 if ((padlen + 4) <= tailroom)
1137 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
1138 dev_kfree_skb_any (skb);
1143 fcs = crc32_le (~0, skb->data, skb->len);
1146 *skb_put (skb, 1) = fcs & 0xff;
1147 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
1148 *skb_put (skb, 1) = (fcs>>16) & 0xff;
1149 *skb_put (skb, 1) = (fcs>>24) & 0xff;
1154 static int zaurus_bind (struct usbnet *dev, struct usb_interface *intf)
1156 /* Belcarra's funky framing has other options; mostly
1157 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
1159 dev->net->hard_header_len += 6;
1160 return generic_cdc_bind(dev, intf);
1163 static const struct driver_info zaurus_sl5x00_info = {
1164 .description = "Sharp Zaurus SL-5x00",
1165 .flags = FLAG_FRAMING_Z,
1166 .check_connect = always_connected,
1167 .bind = zaurus_bind,
1168 .unbind = cdc_unbind,
1169 .tx_fixup = zaurus_tx_fixup,
1171 #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
1173 static const struct driver_info zaurus_pxa_info = {
1174 .description = "Sharp Zaurus, PXA-2xx based",
1175 .flags = FLAG_FRAMING_Z,
1176 .check_connect = always_connected,
1177 .bind = zaurus_bind,
1178 .unbind = cdc_unbind,
1179 .tx_fixup = zaurus_tx_fixup,
1181 #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
1183 static const struct driver_info olympus_mxl_info = {
1184 .description = "Olympus R1000",
1185 .flags = FLAG_FRAMING_Z,
1186 .check_connect = always_connected,
1187 .bind = zaurus_bind,
1188 .unbind = cdc_unbind,
1189 .tx_fixup = zaurus_tx_fixup,
1191 #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
1194 /* Some more recent products using Lineo/Belcarra code will wrongly claim
1195 * CDC MDLM conformance. They aren't conformant: data endpoints live
1196 * in the control interface, there's no data interface, and it's not used
1197 * to talk to a cell phone radio. But at least we can detect these two
1198 * pseudo-classes, rather than growing this product list with entries for
1199 * each new nonconformant product (sigh).
1201 static const u8 safe_guid[16] = {
1202 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
1203 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
1205 static const u8 blan_guid[16] = {
1206 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
1207 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
1210 static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
1212 u8 *buf = intf->cur_altsetting->extra;
1213 int len = intf->cur_altsetting->extralen;
1214 struct usb_cdc_mdlm_desc *desc = NULL;
1215 struct usb_cdc_mdlm_detail_desc *detail = NULL;
1218 if (buf [1] != USB_DT_CS_INTERFACE)
1221 /* use bDescriptorSubType, and just verify that we get a
1222 * "BLAN" (or "SAFE") descriptor.
1225 case USB_CDC_MDLM_TYPE:
1227 dev_dbg (&intf->dev, "extra MDLM\n");
1230 desc = (void *) buf;
1231 if (desc->bLength != sizeof *desc) {
1232 dev_dbg (&intf->dev, "MDLM len %u\n",
1236 /* expect bcdVersion 1.0, ignore */
1237 if (memcmp(&desc->bGUID, blan_guid, 16)
1238 && memcmp(&desc->bGUID, safe_guid, 16) ) {
1239 /* hey, this one might _really_ be MDLM! */
1240 dev_dbg (&intf->dev, "MDLM guid\n");
1244 case USB_CDC_MDLM_DETAIL_TYPE:
1246 dev_dbg (&intf->dev, "extra MDLM detail\n");
1249 detail = (void *) buf;
1250 switch (detail->bGuidDescriptorType) {
1251 case 0: /* "SAFE" */
1252 if (detail->bLength != (sizeof *detail + 2))
1255 case 1: /* "BLAN" */
1256 if (detail->bLength != (sizeof *detail + 3))
1263 /* assuming we either noticed BLAN already, or will
1264 * find it soon, there are some data bytes here:
1265 * - bmNetworkCapabilities (unused)
1266 * - bmDataCapabilities (bits, see below)
1267 * - bPad (ignored, for PADAFTER -- BLAN-only)
1269 * - 0x01 -- Zaurus framing (add CRC)
1270 * - 0x02 -- PADBEFORE (CRC includes some padding)
1271 * - 0x04 -- PADAFTER (some padding after CRC)
1272 * - 0x08 -- "fermat" packet mangling (for hw bugs)
1273 * the PADBEFORE appears not to matter; we interop
1274 * with devices that use it and those that don't.
1276 if ((detail->bDetailData[1] & ~02) != 0x01) {
1277 /* bmDataCapabilites == 0 would be fine too,
1278 * but framing is minidriver-coupled for now.
1281 dev_dbg (&intf->dev,
1282 "bad MDLM detail, %d %d %d\n",
1284 detail->bDetailData[0],
1285 detail->bDetailData[2]);
1291 len -= buf [0]; /* bLength */
1295 if (!desc || !detail) {
1296 dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
1297 desc ? "" : "func ",
1298 detail ? "" : "detail ");
1302 /* There's probably a CDC Ethernet descriptor there, but we can't
1303 * rely on the Ethernet address it provides since not all vendors
1304 * bother to make it unique. Likewise there's no point in tracking
1305 * of the CDC event notifications.
1307 return usbnet_get_endpoints (dev, intf);
1310 dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
1314 static const struct driver_info bogus_mdlm_info = {
1315 .description = "pseudo-MDLM (BLAN) device",
1316 .flags = FLAG_FRAMING_Z,
1317 .check_connect = always_connected,
1318 .tx_fixup = zaurus_tx_fixup,
1319 .bind = blan_mdlm_bind,
1324 /* blacklist all those devices */
1325 #define ZAURUS_STRONGARM_INFO 0
1326 #define ZAURUS_PXA_INFO 0
1327 #define OLYMPUS_MXL_INFO 0
1332 /*-------------------------------------------------------------------------
1334 * Network Device Driver (peer link to "Host Device", from USB host)
1336 *-------------------------------------------------------------------------*/
1338 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
1340 struct usbnet *dev = netdev_priv(net);
1341 int ll_mtu = new_mtu + net->hard_header_len;
1343 if (new_mtu <= 0 || ll_mtu > dev->hard_mtu)
1345 // no second zero-length packet read wanted after mtu-sized packets
1346 if ((ll_mtu % dev->maxpacket) == 0)
1352 /*-------------------------------------------------------------------------*/
1354 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
1356 struct usbnet *dev = netdev_priv(net);
1360 /*-------------------------------------------------------------------------*/
1362 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
1363 * completion callbacks. 2.5 should have fixed those bugs...
1366 static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)
1368 unsigned long flags;
1370 spin_lock_irqsave(&list->lock, flags);
1371 __skb_unlink(skb, list);
1372 spin_unlock(&list->lock);
1373 spin_lock(&dev->done.lock);
1374 __skb_queue_tail(&dev->done, skb);
1375 if (dev->done.qlen == 1)
1376 tasklet_schedule(&dev->bh);
1377 spin_unlock_irqrestore(&dev->done.lock, flags);
1380 /* some work can't be done in tasklets, so we use keventd
1382 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
1383 * but tasklet_schedule() doesn't. hope the failure is rare.
1385 void usbnet_defer_kevent (struct usbnet *dev, int work)
1387 set_bit (work, &dev->flags);
1388 if (!schedule_work (&dev->kevent))
1389 deverr (dev, "kevent %d may have been dropped", work);
1391 devdbg (dev, "kevent %d scheduled", work);
1393 EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
1395 /*-------------------------------------------------------------------------*/
1397 static void rx_complete (struct urb *urb, struct pt_regs *regs);
1399 static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags)
1401 struct sk_buff *skb;
1402 struct skb_data *entry;
1404 unsigned long lockflags;
1405 size_t size = dev->rx_urb_size;
1407 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
1408 if (netif_msg_rx_err (dev))
1409 devdbg (dev, "no rx skb");
1410 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
1414 skb_reserve (skb, NET_IP_ALIGN);
1416 entry = (struct skb_data *) skb->cb;
1419 entry->state = rx_start;
1422 usb_fill_bulk_urb (urb, dev->udev, dev->in,
1423 skb->data, size, rx_complete, skb);
1425 spin_lock_irqsave (&dev->rxq.lock, lockflags);
1427 if (netif_running (dev->net)
1428 && netif_device_present (dev->net)
1429 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
1430 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
1432 usbnet_defer_kevent (dev, EVENT_RX_HALT);
1435 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
1438 if (netif_msg_ifdown (dev))
1439 devdbg (dev, "device gone");
1440 netif_device_detach (dev->net);
1443 if (netif_msg_rx_err (dev))
1444 devdbg (dev, "rx submit, %d", retval);
1445 tasklet_schedule (&dev->bh);
1448 __skb_queue_tail (&dev->rxq, skb);
1451 if (netif_msg_ifdown (dev))
1452 devdbg (dev, "rx: stopped");
1455 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
1457 dev_kfree_skb_any (skb);
1463 /*-------------------------------------------------------------------------*/
1465 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
1467 if (dev->driver_info->rx_fixup
1468 && !dev->driver_info->rx_fixup (dev, skb))
1470 // else network stack removes extra byte if we forced a short packet
1473 usbnet_skb_return (dev, skb);
1475 if (netif_msg_rx_err (dev))
1476 devdbg (dev, "drop");
1478 dev->stats.rx_errors++;
1479 skb_queue_tail (&dev->done, skb);
1483 /*-------------------------------------------------------------------------*/
1485 static void rx_complete (struct urb *urb, struct pt_regs *regs)
1487 struct sk_buff *skb = (struct sk_buff *) urb->context;
1488 struct skb_data *entry = (struct skb_data *) skb->cb;
1489 struct usbnet *dev = entry->dev;
1490 int urb_status = urb->status;
1492 skb_put (skb, urb->actual_length);
1493 entry->state = rx_done;
1496 switch (urb_status) {
1499 if (skb->len < dev->net->hard_header_len) {
1500 entry->state = rx_cleanup;
1501 dev->stats.rx_errors++;
1502 dev->stats.rx_length_errors++;
1503 if (netif_msg_rx_err (dev))
1504 devdbg (dev, "rx length %d", skb->len);
1508 // stalls need manual reset. this is rare ... except that
1509 // when going through USB 2.0 TTs, unplug appears this way.
1510 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
1511 // storm, recovering as needed.
1513 dev->stats.rx_errors++;
1514 usbnet_defer_kevent (dev, EVENT_RX_HALT);
1517 // software-driven interface shutdown
1518 case -ECONNRESET: // async unlink
1519 case -ESHUTDOWN: // hardware gone
1520 if (netif_msg_ifdown (dev))
1521 devdbg (dev, "rx shutdown, code %d", urb_status);
1524 // we get controller i/o faults during khubd disconnect() delays.
1525 // throttle down resubmits, to avoid log floods; just temporarily,
1526 // so we still recover when the fault isn't a khubd delay.
1527 case -EPROTO: // ehci
1528 case -ETIMEDOUT: // ohci
1529 case -EILSEQ: // uhci
1530 dev->stats.rx_errors++;
1531 if (!timer_pending (&dev->delay)) {
1532 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
1533 if (netif_msg_link (dev))
1534 devdbg (dev, "rx throttle %d", urb_status);
1537 entry->state = rx_cleanup;
1542 // data overrun ... flush fifo?
1544 dev->stats.rx_over_errors++;
1548 entry->state = rx_cleanup;
1549 dev->stats.rx_errors++;
1550 if (netif_msg_rx_err (dev))
1551 devdbg (dev, "rx status %d", urb_status);
1555 defer_bh(dev, skb, &dev->rxq);
1558 if (netif_running (dev->net)
1559 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
1560 rx_submit (dev, urb, GFP_ATOMIC);
1565 if (netif_msg_rx_err (dev))
1566 devdbg (dev, "no read resubmitted");
1569 static void intr_complete (struct urb *urb, struct pt_regs *regs)
1571 struct usbnet *dev = urb->context;
1572 int status = urb->status;
1577 dev->driver_info->status(dev, urb);
1580 /* software-driven interface shutdown */
1581 case -ENOENT: // urb killed
1582 case -ESHUTDOWN: // hardware gone
1583 if (netif_msg_ifdown (dev))
1584 devdbg (dev, "intr shutdown, code %d", status);
1587 /* NOTE: not throttling like RX/TX, since this endpoint
1588 * already polls infrequently
1591 devdbg (dev, "intr status %d", status);
1595 if (!netif_running (dev->net))
1598 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
1599 status = usb_submit_urb (urb, GFP_ATOMIC);
1600 if (status != 0 && netif_msg_timer (dev))
1601 deverr(dev, "intr resubmit --> %d", status);
1604 /*-------------------------------------------------------------------------*/
1606 // unlink pending rx/tx; completion handlers do all other cleanup
1608 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
1610 unsigned long flags;
1611 struct sk_buff *skb, *skbnext;
1614 spin_lock_irqsave (&q->lock, flags);
1615 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
1616 struct skb_data *entry;
1620 entry = (struct skb_data *) skb->cb;
1622 skbnext = skb->next;
1624 // during some PM-driven resume scenarios,
1625 // these (async) unlinks complete immediately
1626 retval = usb_unlink_urb (urb);
1627 if (retval != -EINPROGRESS && retval != 0)
1628 devdbg (dev, "unlink urb err, %d", retval);
1632 spin_unlock_irqrestore (&q->lock, flags);
1637 /*-------------------------------------------------------------------------*/
1639 // precondition: never called in_interrupt
1641 static int usbnet_stop (struct net_device *net)
1643 struct usbnet *dev = netdev_priv(net);
1645 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
1646 DECLARE_WAITQUEUE (wait, current);
1648 netif_stop_queue (net);
1650 if (netif_msg_ifdown (dev))
1651 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
1652 dev->stats.rx_packets, dev->stats.tx_packets,
1653 dev->stats.rx_errors, dev->stats.tx_errors
1656 // ensure there are no more active urbs
1657 add_wait_queue (&unlink_wakeup, &wait);
1658 dev->wait = &unlink_wakeup;
1659 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
1661 // maybe wait for deletions to finish.
1662 while (!skb_queue_empty(&dev->rxq) &&
1663 !skb_queue_empty(&dev->txq) &&
1664 !skb_queue_empty(&dev->done)) {
1665 msleep(UNLINK_TIMEOUT_MS);
1666 if (netif_msg_ifdown (dev))
1667 devdbg (dev, "waited for %d urb completions", temp);
1670 remove_wait_queue (&unlink_wakeup, &wait);
1672 usb_kill_urb(dev->interrupt);
1674 /* deferred work (task, timer, softirq) must also stop.
1675 * can't flush_scheduled_work() until we drop rtnl (later),
1676 * else workers could deadlock; so make workers a NOP.
1679 del_timer_sync (&dev->delay);
1680 tasklet_kill (&dev->bh);
1685 /*-------------------------------------------------------------------------*/
1687 // posts reads, and enables write queuing
1689 // precondition: never called in_interrupt
1691 static int usbnet_open (struct net_device *net)
1693 struct usbnet *dev = netdev_priv(net);
1695 struct driver_info *info = dev->driver_info;
1697 // put into "known safe" state
1698 if (info->reset && (retval = info->reset (dev)) < 0) {
1699 if (netif_msg_ifup (dev))
1701 "open reset fail (%d) usbnet usb-%s-%s, %s",
1703 dev->udev->bus->bus_name, dev->udev->devpath,
1708 // insist peer be connected
1709 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
1710 if (netif_msg_ifup (dev))
1711 devdbg (dev, "can't open; %d", retval);
1715 /* start any status interrupt transfer */
1716 if (dev->interrupt) {
1717 retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
1719 if (netif_msg_ifup (dev))
1720 deverr (dev, "intr submit %d", retval);
1725 netif_start_queue (net);
1726 if (netif_msg_ifup (dev)) {
1729 if (dev->driver_info->flags & FLAG_FRAMING_NC)
1730 framing = "NetChip";
1731 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
1732 framing = "GeneSys";
1733 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
1735 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
1737 else if (dev->driver_info->flags & FLAG_FRAMING_AX)
1742 devinfo (dev, "open: enable queueing "
1743 "(rx %d, tx %d) mtu %d %s framing",
1744 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
1748 // delay posting reads until we're fully open
1749 tasklet_schedule (&dev->bh);
1754 /*-------------------------------------------------------------------------*/
1756 /* ethtool methods; minidrivers may need to add some more, but
1757 * they'll probably want to use this base set.
1760 void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
1762 struct usbnet *dev = netdev_priv(net);
1764 /* REVISIT don't always return "usbnet" */
1765 strncpy (info->driver, driver_name, sizeof info->driver);
1766 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
1767 strncpy (info->fw_version, dev->driver_info->description,
1768 sizeof info->fw_version);
1769 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
1771 EXPORT_SYMBOL_GPL(usbnet_get_drvinfo);
1773 static u32 usbnet_get_link (struct net_device *net)
1775 struct usbnet *dev = netdev_priv(net);
1777 /* If a check_connect is defined, return its result */
1778 if (dev->driver_info->check_connect)
1779 return dev->driver_info->check_connect (dev) == 0;
1781 /* Otherwise, say we're up (to avoid breaking scripts) */
1785 u32 usbnet_get_msglevel (struct net_device *net)
1787 struct usbnet *dev = netdev_priv(net);
1789 return dev->msg_enable;
1791 EXPORT_SYMBOL_GPL(usbnet_get_msglevel);
1793 void usbnet_set_msglevel (struct net_device *net, u32 level)
1795 struct usbnet *dev = netdev_priv(net);
1797 dev->msg_enable = level;
1799 EXPORT_SYMBOL_GPL(usbnet_set_msglevel);
1801 /* drivers may override default ethtool_ops in their bind() routine */
1802 static struct ethtool_ops usbnet_ethtool_ops = {
1803 .get_drvinfo = usbnet_get_drvinfo,
1804 .get_link = usbnet_get_link,
1805 .get_msglevel = usbnet_get_msglevel,
1806 .set_msglevel = usbnet_set_msglevel,
1809 /*-------------------------------------------------------------------------*/
1811 /* work that cannot be done in interrupt context uses keventd.
1813 * NOTE: with 2.5 we could do more of this using completion callbacks,
1814 * especially now that control transfers can be queued.
1819 struct usbnet *dev = data;
1822 /* usb_clear_halt() needs a thread context */
1823 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
1824 unlink_urbs (dev, &dev->txq);
1825 status = usb_clear_halt (dev->udev, dev->out);
1828 && status != -ESHUTDOWN) {
1829 if (netif_msg_tx_err (dev))
1830 deverr (dev, "can't clear tx halt, status %d",
1833 clear_bit (EVENT_TX_HALT, &dev->flags);
1834 if (status != -ESHUTDOWN)
1835 netif_wake_queue (dev->net);
1838 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
1839 unlink_urbs (dev, &dev->rxq);
1840 status = usb_clear_halt (dev->udev, dev->in);
1843 && status != -ESHUTDOWN) {
1844 if (netif_msg_rx_err (dev))
1845 deverr (dev, "can't clear rx halt, status %d",
1848 clear_bit (EVENT_RX_HALT, &dev->flags);
1849 tasklet_schedule (&dev->bh);
1853 /* tasklet could resubmit itself forever if memory is tight */
1854 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
1855 struct urb *urb = NULL;
1857 if (netif_running (dev->net))
1858 urb = usb_alloc_urb (0, GFP_KERNEL);
1860 clear_bit (EVENT_RX_MEMORY, &dev->flags);
1862 clear_bit (EVENT_RX_MEMORY, &dev->flags);
1863 rx_submit (dev, urb, GFP_KERNEL);
1864 tasklet_schedule (&dev->bh);
1868 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
1869 struct driver_info *info = dev->driver_info;
1872 clear_bit (EVENT_LINK_RESET, &dev->flags);
1873 if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
1874 devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s",
1876 dev->udev->bus->bus_name, dev->udev->devpath,
1882 devdbg (dev, "kevent done, flags = 0x%lx",
1886 /*-------------------------------------------------------------------------*/
1888 static void tx_complete (struct urb *urb, struct pt_regs *regs)
1890 struct sk_buff *skb = (struct sk_buff *) urb->context;
1891 struct skb_data *entry = (struct skb_data *) skb->cb;
1892 struct usbnet *dev = entry->dev;
1894 if (urb->status == 0) {
1895 dev->stats.tx_packets++;
1896 dev->stats.tx_bytes += entry->length;
1898 dev->stats.tx_errors++;
1900 switch (urb->status) {
1902 usbnet_defer_kevent (dev, EVENT_TX_HALT);
1905 /* software-driven interface shutdown */
1906 case -ECONNRESET: // async unlink
1907 case -ESHUTDOWN: // hardware gone
1910 // like rx, tx gets controller i/o faults during khubd delays
1911 // and so it uses the same throttling mechanism.
1912 case -EPROTO: // ehci
1913 case -ETIMEDOUT: // ohci
1914 case -EILSEQ: // uhci
1915 if (!timer_pending (&dev->delay)) {
1916 mod_timer (&dev->delay,
1917 jiffies + THROTTLE_JIFFIES);
1918 if (netif_msg_link (dev))
1919 devdbg (dev, "tx throttle %d",
1922 netif_stop_queue (dev->net);
1925 if (netif_msg_tx_err (dev))
1926 devdbg (dev, "tx err %d", entry->urb->status);
1932 entry->state = tx_done;
1933 defer_bh(dev, skb, &dev->txq);
1936 /*-------------------------------------------------------------------------*/
1938 static void usbnet_tx_timeout (struct net_device *net)
1940 struct usbnet *dev = netdev_priv(net);
1942 unlink_urbs (dev, &dev->txq);
1943 tasklet_schedule (&dev->bh);
1945 // FIXME: device recovery -- reset?
1948 /*-------------------------------------------------------------------------*/
1950 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
1952 struct usbnet *dev = netdev_priv(net);
1954 int retval = NET_XMIT_SUCCESS;
1955 struct urb *urb = NULL;
1956 struct skb_data *entry;
1957 struct driver_info *info = dev->driver_info;
1958 unsigned long flags;
1960 // some devices want funky USB-level framing, for
1961 // win32 driver (usually) and/or hardware quirks
1962 if (info->tx_fixup) {
1963 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
1965 if (netif_msg_tx_err (dev))
1966 devdbg (dev, "can't tx_fixup skb");
1972 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
1973 if (netif_msg_tx_err (dev))
1974 devdbg (dev, "no urb");
1978 entry = (struct skb_data *) skb->cb;
1981 entry->state = tx_start;
1982 entry->length = length;
1984 usb_fill_bulk_urb (urb, dev->udev, dev->out,
1985 skb->data, skb->len, tx_complete, skb);
1987 /* don't assume the hardware handles USB_ZERO_PACKET
1988 * NOTE: strictly conforming cdc-ether devices should expect
1989 * the ZLP here, but ignore the one-byte packet.
1991 * FIXME zero that byte, if it doesn't require a new skb.
1993 if ((length % dev->maxpacket) == 0)
1994 urb->transfer_buffer_length++;
1996 spin_lock_irqsave (&dev->txq.lock, flags);
1998 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2000 netif_stop_queue (net);
2001 usbnet_defer_kevent (dev, EVENT_TX_HALT);
2004 if (netif_msg_tx_err (dev))
2005 devdbg (dev, "tx: submit urb err %d", retval);
2008 net->trans_start = jiffies;
2009 __skb_queue_tail (&dev->txq, skb);
2010 if (dev->txq.qlen >= TX_QLEN (dev))
2011 netif_stop_queue (net);
2013 spin_unlock_irqrestore (&dev->txq.lock, flags);
2016 if (netif_msg_tx_err (dev))
2017 devdbg (dev, "drop, code %d", retval);
2019 retval = NET_XMIT_SUCCESS;
2020 dev->stats.tx_dropped++;
2022 dev_kfree_skb_any (skb);
2024 } else if (netif_msg_tx_queued (dev)) {
2025 devdbg (dev, "> tx, len %d, type 0x%x",
2026 length, skb->protocol);
2032 /*-------------------------------------------------------------------------*/
2034 // tasklet (work deferred from completions, in_irq) or timer
2036 static void usbnet_bh (unsigned long param)
2038 struct usbnet *dev = (struct usbnet *) param;
2039 struct sk_buff *skb;
2040 struct skb_data *entry;
2042 while ((skb = skb_dequeue (&dev->done))) {
2043 entry = (struct skb_data *) skb->cb;
2044 switch (entry->state) {
2046 entry->state = rx_cleanup;
2047 rx_process (dev, skb);
2051 usb_free_urb (entry->urb);
2052 dev_kfree_skb (skb);
2055 devdbg (dev, "bogus skb state %d", entry->state);
2059 // waiting for all pending urbs to complete?
2061 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
2062 wake_up (dev->wait);
2065 // or are we maybe short a few urbs?
2066 } else if (netif_running (dev->net)
2067 && netif_device_present (dev->net)
2068 && !timer_pending (&dev->delay)
2069 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2070 int temp = dev->rxq.qlen;
2071 int qlen = RX_QLEN (dev);
2077 // don't refill the queue all at once
2078 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
2079 urb = usb_alloc_urb (0, GFP_ATOMIC);
2081 rx_submit (dev, urb, GFP_ATOMIC);
2083 if (temp != dev->rxq.qlen && netif_msg_link (dev))
2084 devdbg (dev, "rxqlen %d --> %d",
2085 temp, dev->rxq.qlen);
2086 if (dev->rxq.qlen < qlen)
2087 tasklet_schedule (&dev->bh);
2089 if (dev->txq.qlen < TX_QLEN (dev))
2090 netif_wake_queue (dev->net);
2096 /*-------------------------------------------------------------------------
2098 * USB Device Driver support
2100 *-------------------------------------------------------------------------*/
2102 // precondition: never called in_interrupt
2104 void usbnet_disconnect (struct usb_interface *intf)
2107 struct usb_device *xdev;
2108 struct net_device *net;
2110 dev = usb_get_intfdata(intf);
2111 usb_set_intfdata(intf, NULL);
2115 xdev = interface_to_usbdev (intf);
2117 if (netif_msg_probe (dev))
2118 devinfo (dev, "unregister '%s' usb-%s-%s, %s",
2119 intf->dev.driver->name,
2120 xdev->bus->bus_name, xdev->devpath,
2121 dev->driver_info->description);
2124 unregister_netdev (net);
2126 /* we don't hold rtnl here ... */
2127 flush_scheduled_work ();
2129 if (dev->driver_info->unbind)
2130 dev->driver_info->unbind (dev, intf);
2135 EXPORT_SYMBOL_GPL(usbnet_disconnect);
2138 /*-------------------------------------------------------------------------*/
2140 // precondition: never called in_interrupt
2143 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
2146 struct net_device *net;
2147 struct usb_host_interface *interface;
2148 struct driver_info *info;
2149 struct usb_device *xdev;
2152 info = (struct driver_info *) prod->driver_info;
2154 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
2157 xdev = interface_to_usbdev (udev);
2158 interface = udev->cur_altsetting;
2164 // set up our own records
2165 net = alloc_etherdev(sizeof(*dev));
2167 dbg ("can't kmalloc dev");
2171 dev = netdev_priv(net);
2173 dev->driver_info = info;
2174 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
2175 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
2176 skb_queue_head_init (&dev->rxq);
2177 skb_queue_head_init (&dev->txq);
2178 skb_queue_head_init (&dev->done);
2179 dev->bh.func = usbnet_bh;
2180 dev->bh.data = (unsigned long) dev;
2181 INIT_WORK (&dev->kevent, kevent, dev);
2182 dev->delay.function = usbnet_bh;
2183 dev->delay.data = (unsigned long) dev;
2184 init_timer (&dev->delay);
2186 SET_MODULE_OWNER (net);
2188 strcpy (net->name, "usb%d");
2189 memcpy (net->dev_addr, node_id, sizeof node_id);
2191 /* rx and tx sides can use different message sizes;
2192 * bind() should set rx_urb_size in that case.
2194 dev->hard_mtu = net->mtu + net->hard_header_len;
2196 // dma_supported() is deeply broken on almost all architectures
2197 // possible with some EHCI controllers
2198 if (dma_supported (&udev->dev, DMA_64BIT_MASK))
2199 net->features |= NETIF_F_HIGHDMA;
2202 net->change_mtu = usbnet_change_mtu;
2203 net->get_stats = usbnet_get_stats;
2204 net->hard_start_xmit = usbnet_start_xmit;
2205 net->open = usbnet_open;
2206 net->stop = usbnet_stop;
2207 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
2208 net->tx_timeout = usbnet_tx_timeout;
2209 net->ethtool_ops = &usbnet_ethtool_ops;
2211 // allow device-specific bind/init procedures
2212 // NOTE net->name still not usable ...
2214 status = info->bind (dev, udev);
2215 // heuristic: "usb%d" for links we know are two-host,
2216 // else "eth%d" when there's reasonable doubt. userspace
2217 // can rename the link if it knows better.
2218 if ((dev->driver_info->flags & FLAG_ETHER) != 0
2219 && (net->dev_addr [0] & 0x02) == 0)
2220 strcpy (net->name, "eth%d");
2222 /* maybe the remote can't receive an Ethernet MTU */
2223 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
2224 net->mtu = dev->hard_mtu - net->hard_header_len;
2225 } else if (!info->in || !info->out)
2226 status = usbnet_get_endpoints (dev, udev);
2228 dev->in = usb_rcvbulkpipe (xdev, info->in);
2229 dev->out = usb_sndbulkpipe (xdev, info->out);
2230 if (!(info->flags & FLAG_NO_SETINT))
2231 status = usb_set_interface (xdev,
2232 interface->desc.bInterfaceNumber,
2233 interface->desc.bAlternateSetting);
2238 if (status == 0 && dev->status)
2239 status = init_status (dev, udev);
2243 if (!dev->rx_urb_size)
2244 dev->rx_urb_size = dev->hard_mtu;
2245 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
2247 SET_NETDEV_DEV(net, &udev->dev);
2248 status = register_netdev (net);
2251 if (netif_msg_probe (dev))
2252 devinfo (dev, "register '%s' at usb-%s-%s, %s, "
2253 "%02x:%02x:%02x:%02x:%02x:%02x",
2254 udev->dev.driver->name,
2255 xdev->bus->bus_name, xdev->devpath,
2256 dev->driver_info->description,
2257 net->dev_addr [0], net->dev_addr [1],
2258 net->dev_addr [2], net->dev_addr [3],
2259 net->dev_addr [4], net->dev_addr [5]);
2261 // ok, it's ready to go.
2262 usb_set_intfdata (udev, dev);
2264 // start as if the link is up
2265 netif_device_attach (net);
2271 info->unbind (dev, udev);
2278 EXPORT_SYMBOL_GPL(usbnet_probe);
2280 /*-------------------------------------------------------------------------*/
2282 /* FIXME these suspend/resume methods assume non-CDC style
2283 * devices, with only one interface.
2286 int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
2288 struct usbnet *dev = usb_get_intfdata(intf);
2290 /* accelerate emptying of the rx and queues, to avoid
2291 * having everything error out.
2293 netif_device_detach (dev->net);
2294 (void) unlink_urbs (dev, &dev->rxq);
2295 (void) unlink_urbs (dev, &dev->txq);
2296 intf->dev.power.power_state = PMSG_SUSPEND;
2299 EXPORT_SYMBOL_GPL(usbnet_suspend);
2301 int usbnet_resume (struct usb_interface *intf)
2303 struct usbnet *dev = usb_get_intfdata(intf);
2305 intf->dev.power.power_state = PMSG_ON;
2306 netif_device_attach (dev->net);
2307 tasklet_schedule (&dev->bh);
2310 EXPORT_SYMBOL_GPL(usbnet_resume);
2313 /*-------------------------------------------------------------------------*/
2315 #ifndef HAVE_HARDWARE
2316 #error You need to configure some hardware for this driver
2320 * chip vendor names won't normally be on the cables, and
2321 * may not be on the device.
2324 static const struct usb_device_id products [] = {
2326 #ifdef CONFIG_USB_GENESYS
2328 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
2329 .driver_info = (unsigned long) &genelink_info,
2331 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
2332 * that's half duplex, not currently supported
2336 #ifdef CONFIG_USB_PL2301
2338 USB_DEVICE (0x067b, 0x0000), // PL-2301
2339 .driver_info = (unsigned long) &prolific_info,
2341 USB_DEVICE (0x067b, 0x0001), // PL-2302
2342 .driver_info = (unsigned long) &prolific_info,
2346 #ifdef CONFIG_USB_RNDIS
2348 /* RNDIS is MSFT's un-official variant of CDC ACM */
2349 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
2350 .driver_info = (unsigned long) &rndis_info,
2354 #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
2356 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
2357 * Same idea as above, but different framing.
2359 * PXA-2xx based models are also lying-about-cdc.
2360 * Some models don't even tell the same lies ...
2362 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
2363 * unlike the older ones with 2.4 "embedix" kernels.
2365 * NOTE: These entries do double-duty, serving as blacklist entries
2366 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
2368 #define ZAURUS_MASTER_INTERFACE \
2369 .bInterfaceClass = USB_CLASS_COMM, \
2370 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
2371 .bInterfaceProtocol = USB_CDC_PROTO_NONE
2373 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2374 | USB_DEVICE_ID_MATCH_DEVICE,
2376 .idProduct = 0x8004,
2377 ZAURUS_MASTER_INTERFACE,
2378 .driver_info = ZAURUS_STRONGARM_INFO,
2380 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2381 | USB_DEVICE_ID_MATCH_DEVICE,
2383 .idProduct = 0x8005, /* A-300 */
2384 ZAURUS_MASTER_INTERFACE,
2385 .driver_info = ZAURUS_PXA_INFO,
2387 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2388 | USB_DEVICE_ID_MATCH_DEVICE,
2390 .idProduct = 0x8006, /* B-500/SL-5600 */
2391 ZAURUS_MASTER_INTERFACE,
2392 .driver_info = ZAURUS_PXA_INFO,
2394 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2395 | USB_DEVICE_ID_MATCH_DEVICE,
2397 .idProduct = 0x8007, /* C-700 */
2398 ZAURUS_MASTER_INTERFACE,
2399 .driver_info = ZAURUS_PXA_INFO,
2401 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2402 | USB_DEVICE_ID_MATCH_DEVICE,
2404 .idProduct = 0x9031, /* C-750 C-760 */
2405 ZAURUS_MASTER_INTERFACE,
2406 .driver_info = ZAURUS_PXA_INFO,
2408 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2409 | USB_DEVICE_ID_MATCH_DEVICE,
2411 .idProduct = 0x9032, /* SL-6000 */
2412 ZAURUS_MASTER_INTERFACE,
2413 .driver_info = ZAURUS_PXA_INFO,
2415 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2416 | USB_DEVICE_ID_MATCH_DEVICE,
2418 /* reported with some C860 units */
2419 .idProduct = 0x9050, /* C-860 */
2420 ZAURUS_MASTER_INTERFACE,
2421 .driver_info = ZAURUS_PXA_INFO,
2424 #ifdef CONFIG_USB_ZAURUS
2425 /* At least some (reports vary) PXA units have very different lies
2426 * about their standards support: they claim to be cell phones with
2427 * direct access to their radios. (They don't conform to CDC MDLM.)
2430 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
2431 USB_CDC_PROTO_NONE),
2432 .driver_info = (unsigned long) &bogus_mdlm_info,
2436 /* Olympus has some models with a Zaurus-compatible option.
2437 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
2440 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2441 | USB_DEVICE_ID_MATCH_DEVICE,
2443 .idProduct = 0x0F02, /* R-1000 */
2444 ZAURUS_MASTER_INTERFACE,
2445 .driver_info = OLYMPUS_MXL_INFO,
2449 #ifdef CONFIG_USB_CDCETHER
2451 /* CDC Ether uses two interfaces, not necessarily consecutive.
2452 * We match the main interface, ignoring the optional device
2453 * class so we could handle devices that aren't exclusively
2456 * NOTE: this match must come AFTER entries working around
2457 * bugs/quirks in a given product (like Zaurus, above).
2459 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
2460 USB_CDC_PROTO_NONE),
2461 .driver_info = (unsigned long) &cdc_info,
2467 MODULE_DEVICE_TABLE (usb, products);
2469 static struct usb_driver usbnet_driver = {
2470 .owner = THIS_MODULE,
2471 .name = driver_name,
2472 .id_table = products,
2473 .probe = usbnet_probe,
2474 .disconnect = usbnet_disconnect,
2475 .suspend = usbnet_suspend,
2476 .resume = usbnet_resume,
2479 /*-------------------------------------------------------------------------*/
2481 static int __init usbnet_init(void)
2483 // compiler should optimize these out
2484 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
2485 < sizeof (struct skb_data));
2486 #ifdef CONFIG_USB_CDCETHER
2487 BUG_ON ((sizeof (((struct usbnet *)0)->data)
2488 < sizeof (struct cdc_state)));
2491 random_ether_addr(node_id);
2493 return usb_register(&usbnet_driver);
2495 module_init(usbnet_init);
2497 static void __exit usbnet_exit(void)
2499 usb_deregister(&usbnet_driver);
2501 module_exit(usbnet_exit);
2503 MODULE_AUTHOR("David Brownell");
2504 MODULE_DESCRIPTION("USB Host-to-Host Link Drivers (numerous vendors)");
2505 MODULE_LICENSE("GPL");