3 * Copyright (C) 2000-2003 by David Brownell <dbrownell@users.sourceforge.net>
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003 David Hollis <dhollis@davehollis.com>
6 * Copyright (c) 2002-2003 TiVo Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This is a generic "USB networking" framework that works with several
25 * kinds of full and high speed networking devices:
27 * + USB host-to-host "network cables", used for IP-over-USB links.
28 * These are often used for Laplink style connectivity products.
30 * - Belkin, eTEK (interops with Win32 drivers)
31 * - GeneSys GL620USB-A
32 * - NetChip 1080 (interoperates with NetChip Win32 drivers)
33 * - Prolific PL-2301/2302 (replaces "plusb" driver)
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).
108 *-------------------------------------------------------------------------*/
110 #include <linux/config.h>
111 #include <linux/module.h>
112 #include <linux/kmod.h>
113 #include <linux/sched.h>
114 #include <linux/init.h>
115 #include <linux/netdevice.h>
116 #include <linux/etherdevice.h>
117 #include <linux/random.h>
118 #include <linux/ethtool.h>
119 #include <linux/workqueue.h>
120 #include <linux/mii.h>
121 #include <asm/uaccess.h>
122 #include <asm/unaligned.h>
125 // #define DEBUG // error path messages, extra info
126 // #define VERBOSE // more; success messages
129 #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
132 #include <linux/usb.h>
135 #include <asm/scatterlist.h>
136 #include <linux/mm.h>
137 #include <linux/dma-mapping.h>
140 #define DRIVER_VERSION "25-Aug-2003"
142 /*-------------------------------------------------------------------------*/
145 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
146 * Several dozen bytes of IPv4 data can fit in two such transactions.
147 * One maximum size Ethernet packet takes twenty four of them.
148 * For high speed, each frame comfortably fits almost 36 max size
149 * Ethernet packets (so queues should be bigger).
152 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
153 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
155 #define RX_QLEN(dev) 1
156 #define TX_QLEN(dev) 1
159 // packets are always ethernet inside
160 // ... except they can be bigger (limit of 64K with NetChip framing)
161 #define MIN_PACKET sizeof(struct ethhdr)
162 #define MAX_PACKET 32768
164 // reawaken network queue this soon after stopping; else watchdog barks
165 #define TX_TIMEOUT_JIFFIES (5*HZ)
167 // throttle rx/tx briefly after some faults, so khubd might disconnect()
168 // us (it polls at HZ/4 usually) before we report too many false errors.
169 #define THROTTLE_JIFFIES (HZ/8)
171 // for vendor-specific control operations
172 #define CONTROL_TIMEOUT_MS (500) /* msec */
173 #define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
176 #define UNLINK_TIMEOUT_JIFFIES ((3 /*ms*/ * HZ)/1000)
178 /*-------------------------------------------------------------------------*/
180 // randomly generated ethernet address
181 static u8 node_id [ETH_ALEN];
183 // state we keep for each device we handle
186 struct usb_device *udev;
187 struct driver_info *driver_info;
188 wait_queue_head_t *wait;
190 // i/o info: pipes etc
193 struct timer_list delay;
195 // protocol/interface state
196 struct net_device *net;
197 struct net_device_stats stats;
199 unsigned long data [5];
201 struct mii_if_info mii;
203 // various kinds of pending driver work
204 struct sk_buff_head rxq;
205 struct sk_buff_head txq;
206 struct sk_buff_head done;
207 struct tasklet_struct bh;
209 struct work_struct kevent;
211 # define EVENT_TX_HALT 0
212 # define EVENT_RX_HALT 1
213 # define EVENT_RX_MEMORY 2
216 // device-specific info used by the driver
221 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
222 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
223 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
224 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
225 #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
227 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
228 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
230 /* init device ... can sleep, or cause probe() failure */
231 int (*bind)(struct usbnet *, struct usb_interface *);
233 /* cleanup device ... can sleep, but can't fail */
234 void (*unbind)(struct usbnet *, struct usb_interface *);
236 /* reset device ... can sleep */
237 int (*reset)(struct usbnet *);
239 /* see if peer is connected ... can sleep */
240 int (*check_connect)(struct usbnet *);
242 /* fixup rx packet (strip framing) */
243 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
245 /* fixup tx packet (add framing) */
246 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
247 struct sk_buff *skb, int flags);
249 // FIXME -- also an interrupt mechanism
250 // useful for at least PL2301/2302 and GL620USB-A
251 // and CDC use them to report 'is it connected' changes
253 /* for new devices, use the descriptor-reading code instead */
254 int in; /* rx endpoint */
255 int out; /* tx endpoint */
257 unsigned long data; /* Misc driver specific data */
260 // we record the state for each of our queued skbs
264 rx_start, rx_done, rx_cleanup
267 struct skb_data { // skb->cb is one of these
270 enum skb_state state;
274 static const char driver_name [] = "usbnet";
276 /* use ethtool to change the level for any given device */
277 static int msg_level = 1;
278 MODULE_PARM (msg_level, "i");
279 MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
282 #define RUN_CONTEXT (in_irq () ? "in_irq" \
283 : (in_interrupt () ? "in_interrupt" : "can sleep"))
286 #define devdbg(usbnet, fmt, arg...) \
287 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
289 #define devdbg(usbnet, fmt, arg...) do {} while(0)
292 #define deverr(usbnet, fmt, arg...) \
293 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
294 #define devwarn(usbnet, fmt, arg...) \
295 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
297 #define devinfo(usbnet, fmt, arg...) \
298 do { if ((usbnet)->msg_level >= 1) \
299 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
302 /*-------------------------------------------------------------------------*/
304 static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
305 static u32 usbnet_get_link (struct net_device *);
306 static u32 usbnet_get_msglevel (struct net_device *);
307 static void usbnet_set_msglevel (struct net_device *, u32);
309 /* mostly for PDA style devices, which are always connected if present */
310 static int always_connected (struct usbnet *dev)
315 /* handles CDC Ethernet and many other network "bulk data" interfaces */
317 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
320 struct usb_host_interface *alt;
321 struct usb_host_endpoint *in, *out;
323 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
327 alt = intf->altsetting + tmp;
329 /* take the first altsetting with in-bulk + out-bulk;
330 * ignore other endpoints and altsetttings.
332 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
333 struct usb_host_endpoint *e;
335 e = alt->endpoint + ep;
336 if (e->desc.bmAttributes != USB_ENDPOINT_XFER_BULK)
338 if (e->desc.bEndpointAddress & USB_DIR_IN) {
352 if (alt->desc.bAlternateSetting != 0
353 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
354 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
355 alt->desc.bAlternateSetting);
360 dev->in = usb_rcvbulkpipe (dev->udev,
361 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
362 dev->out = usb_sndbulkpipe (dev->udev,
363 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
367 static void skb_return (struct usbnet *dev, struct sk_buff *skb)
372 skb->protocol = eth_type_trans (skb, dev->net);
373 dev->stats.rx_packets++;
374 dev->stats.rx_bytes += skb->len;
377 devdbg (dev, "< rx, len %d, type 0x%x",
378 skb->len + sizeof (struct ethhdr), skb->protocol);
380 memset (skb->cb, 0, sizeof (struct skb_data));
381 status = netif_rx (skb);
382 if (status != NET_RX_SUCCESS)
383 devdbg (dev, "netif_rx status %d", status);
387 #ifdef CONFIG_USB_ALI_M5632
388 #define HAVE_HARDWARE
390 /*-------------------------------------------------------------------------
392 * ALi M5632 driver ... does high speed
394 *-------------------------------------------------------------------------*/
396 static const struct driver_info ali_m5632_info = {
397 .description = "ALi M5632",
404 #ifdef CONFIG_USB_AN2720
405 #define HAVE_HARDWARE
407 /*-------------------------------------------------------------------------
409 * AnchorChips 2720 driver ... http://www.cypress.com
411 * This doesn't seem to have a way to detect whether the peer is
412 * connected, or need any reset handshaking. It's got pretty big
413 * internal buffers (handles most of a frame's worth of data).
414 * Chip data sheets don't describe any vendor control messages.
416 *-------------------------------------------------------------------------*/
418 static const struct driver_info an2720_info = {
419 .description = "AnchorChips/Cypress 2720",
420 // no reset available!
421 // no check_connect available!
423 .in = 2, .out = 2, // direction distinguishes these
426 #endif /* CONFIG_USB_AN2720 */
429 #ifdef CONFIG_USB_AX8817X
430 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
432 #define HAVE_HARDWARE
435 #include <linux/crc32.h>
437 #define AX_CMD_SET_SW_MII 0x06
438 #define AX_CMD_READ_MII_REG 0x07
439 #define AX_CMD_WRITE_MII_REG 0x08
440 #define AX_CMD_SET_HW_MII 0x0a
441 #define AX_CMD_READ_EEPROM 0x0b
442 #define AX_CMD_WRITE_EEPROM 0x0c
443 #define AX_CMD_WRITE_RX_CTL 0x10
444 #define AX_CMD_READ_IPG012 0x11
445 #define AX_CMD_WRITE_IPG0 0x12
446 #define AX_CMD_WRITE_IPG1 0x13
447 #define AX_CMD_WRITE_IPG2 0x14
448 #define AX_CMD_WRITE_MULTI_FILTER 0x16
449 #define AX_CMD_READ_NODE_ID 0x17
450 #define AX_CMD_READ_PHY_ID 0x19
451 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
452 #define AX_CMD_READ_MONITOR_MODE 0x1c
453 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
454 #define AX_CMD_WRITE_GPIOS 0x1f
456 #define AX_MONITOR_MODE 0x01
457 #define AX_MONITOR_LINK 0x02
458 #define AX_MONITOR_MAGIC 0x04
459 #define AX_MONITOR_HSFS 0x10
461 #define AX_MCAST_FILTER_SIZE 8
462 #define AX_MAX_MCAST 64
464 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
465 u16 size, void *data)
467 return usb_control_msg(
469 usb_rcvctrlpipe(dev->udev, 0),
471 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
476 CONTROL_TIMEOUT_JIFFIES);
479 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
480 u16 size, void *data)
482 return usb_control_msg(
484 usb_sndctrlpipe(dev->udev, 0),
486 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
491 CONTROL_TIMEOUT_JIFFIES);
494 static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
496 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
499 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
506 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
507 u16 size, void *data)
509 struct usb_ctrlrequest *req;
513 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
514 devdbg(dev, "Error allocating URB in write_cmd_async!");
518 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
519 deverr(dev, "Failed to allocate memory for control request");
524 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
526 req->wValue = cpu_to_le16(value);
527 req->wIndex = cpu_to_le16(index);
528 req->wLength = cpu_to_le16(size);
530 usb_fill_control_urb(urb, dev->udev,
531 usb_sndctrlpipe(dev->udev, 0),
532 (void *)req, data, size,
533 ax8817x_async_cmd_callback, req);
535 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
536 deverr(dev, "Error submitting the control message: status=%d", status);
542 static void ax8817x_set_multicast(struct net_device *net)
544 struct usbnet *dev = (struct usbnet *) net->priv;
547 if (net->flags & IFF_PROMISC) {
549 } else if (net->flags & IFF_ALLMULTI
550 || net->mc_count > AX_MAX_MCAST) {
552 } else if (net->mc_count == 0) {
553 /* just broadcast and directed */
555 /* We use the 20 byte dev->data
556 * for our 8 byte filter buffer
557 * to avoid allocating memory that
558 * is tricky to free later */
559 u8 *multi_filter = (u8 *)&dev->data;
560 struct dev_mc_list *mc_list = net->mc_list;
564 memset(multi_filter, 0, AX_MCAST_FILTER_SIZE);
566 /* Build the multicast hash filter. */
567 for (i = 0; i < net->mc_count; i++) {
570 mc_list->dmi_addr) >> 26;
571 multi_filter[crc_bits >> 3] |=
573 mc_list = mc_list->next;
576 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
577 AX_MCAST_FILTER_SIZE, multi_filter);
582 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
585 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
587 struct usbnet *dev = netdev->priv;
591 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
592 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
593 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
598 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
600 struct usbnet *dev = netdev->priv;
604 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
605 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
606 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
609 void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
611 struct usbnet *dev = (struct usbnet *)net->priv;
614 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
615 wolinfo->supported = 0;
616 wolinfo->wolopts = 0;
619 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
620 wolinfo->wolopts = 0;
621 if (opt & AX_MONITOR_MODE) {
622 if (opt & AX_MONITOR_LINK)
623 wolinfo->wolopts |= WAKE_PHY;
624 if (opt & AX_MONITOR_MAGIC)
625 wolinfo->wolopts |= WAKE_MAGIC;
629 int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
631 struct usbnet *dev = (struct usbnet *)net->priv;
635 if (wolinfo->wolopts & WAKE_PHY)
636 opt |= AX_MONITOR_LINK;
637 if (wolinfo->wolopts & WAKE_MAGIC)
638 opt |= AX_MONITOR_MAGIC;
640 opt |= AX_MONITOR_MODE;
642 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
643 opt, 0, 0, &buf) < 0)
649 int ax8817x_get_eeprom(struct net_device *net,
650 struct ethtool_eeprom *eeprom, u8 *data)
652 struct usbnet *dev = (struct usbnet *)net->priv;
653 u16 *ebuf = (u16 *)data;
656 /* Crude hack to ensure that we don't overwrite memory
657 * if an odd length is supplied
662 /* ax8817x returns 2 bytes from eeprom on read */
663 for (i=0; i < eeprom->len / 2; i++) {
664 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
665 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
671 static void ax8817x_get_drvinfo (struct net_device *net,
672 struct ethtool_drvinfo *info)
674 /* Inherit standard device info */
675 usbnet_get_drvinfo(net, info);
676 info->eedump_len = 0x3e;
679 static u32 ax8817x_get_link (struct net_device *net)
681 struct usbnet *dev = (struct usbnet *)net->priv;
683 return (u32)mii_link_ok(&dev->mii);
686 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
688 struct usbnet *dev = (struct usbnet *)net->priv;
690 return mii_ethtool_gset(&dev->mii,cmd);
693 static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
695 struct usbnet *dev = (struct usbnet *)net->priv;
697 return mii_ethtool_sset(&dev->mii,cmd);
700 /* We need to override some ethtool_ops so we require our
701 own structure so we don't interfere with other usbnet
702 devices that may be connected at the same time. */
703 static struct ethtool_ops ax8817x_ethtool_ops = {
704 .get_drvinfo = ax8817x_get_drvinfo,
705 .get_link = ax8817x_get_link,
706 .get_msglevel = usbnet_get_msglevel,
707 .set_msglevel = usbnet_set_msglevel,
708 .get_wol = ax8817x_get_wol,
709 .set_wol = ax8817x_set_wol,
710 .get_eeprom = ax8817x_get_eeprom,
711 .get_settings = ax8817x_get_settings,
712 .set_settings = ax8817x_set_settings,
715 static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
719 u16 *buf16 = (u16 *) buf;
721 unsigned long gpio_bits = dev->driver_info->data;
723 dev->in = usb_rcvbulkpipe(dev->udev, 3);
724 dev->out = usb_sndbulkpipe(dev->udev, 2);
726 /* Toggle the GPIOs in a manufacturer/model specific way */
727 for (i = 2; i >= 0; i--) {
728 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
729 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
735 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
736 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
740 /* Get the MAC address */
741 memset(buf, 0, ETH_ALEN);
742 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
743 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
746 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
749 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
750 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
752 } else if (ret < 2) {
753 /* this should always return 2 bytes */
754 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
758 /* Initialize MII structure */
759 dev->mii.dev = dev->net;
760 dev->mii.mdio_read = ax8817x_mdio_read;
761 dev->mii.mdio_write = ax8817x_mdio_write;
762 dev->mii.phy_id_mask = 0x3f;
763 dev->mii.reg_num_mask = 0x1f;
764 dev->mii.phy_id = buf[1];
766 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf)) < 0) {
767 dbg("Failed to go to software MII mode: %02x", ret);
771 *buf16 = cpu_to_le16(BMCR_RESET);
772 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
773 dev->mii.phy_id, MII_BMCR, 2, buf16)) < 0) {
774 dbg("Failed to write MII reg - MII_BMCR: %02x", ret);
778 /* Advertise that we can do full-duplex pause */
779 *buf16 = cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400);
780 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
781 dev->mii.phy_id, MII_ADVERTISE,
783 dbg("Failed to write MII_REG advertisement: %02x", ret);
787 *buf16 = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART);
788 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
789 dev->mii.phy_id, MII_BMCR,
791 dbg("Failed to write MII reg autonegotiate: %02x", ret);
795 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
796 dbg("Failed to set hardware MII: %02x", ret);
800 dev->net->set_multicast_list = ax8817x_set_multicast;
801 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
806 static const struct driver_info ax8817x_info = {
807 .description = "ASIX AX8817x USB 2.0 Ethernet",
808 .bind = ax8817x_bind,
813 static const struct driver_info dlink_dub_e100_info = {
814 .description = "DLink DUB-E100 USB Ethernet",
815 .bind = ax8817x_bind,
820 static const struct driver_info netgear_fa120_info = {
821 .description = "Netgear FA-120 USB Ethernet",
822 .bind = ax8817x_bind,
827 static const struct driver_info hawking_uf200_info = {
828 .description = "Hawking UF200 USB Ethernet",
829 .bind = ax8817x_bind,
834 #endif /* CONFIG_USB_AX8817X */
838 #ifdef CONFIG_USB_BELKIN
839 #define HAVE_HARDWARE
841 /*-------------------------------------------------------------------------
843 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
845 * ... also two eTEK designs, including one sold as "Advance USBNET"
847 *-------------------------------------------------------------------------*/
849 static const struct driver_info belkin_info = {
850 .description = "Belkin, eTEK, or compatible",
853 #endif /* CONFIG_USB_BELKIN */
857 /*-------------------------------------------------------------------------
859 * Communications Device Class declarations.
860 * Used by CDC Ethernet, and some CDC variants
862 *-------------------------------------------------------------------------*/
864 #ifdef CONFIG_USB_CDCETHER
865 #define NEED_GENERIC_CDC
868 #ifdef CONFIG_USB_ZAURUS
869 /* Ethernet variant uses funky framing, broken ethernet addressing */
870 #define NEED_GENERIC_CDC
873 #ifdef CONFIG_USB_RNDIS
874 /* ACM variant uses even funkier framing, complex control RPC scheme */
875 #define NEED_GENERIC_CDC
879 #ifdef NEED_GENERIC_CDC
881 /* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
885 u8 bDescriptorSubType;
888 } __attribute__ ((packed));
890 /* "Union Functional Descriptor" from CDC spec 5.2.3.X */
894 u8 bDescriptorSubType;
896 u8 bMasterInterface0;
898 /* ... and there could be other slave interfaces */
899 } __attribute__ ((packed));
901 /* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
905 u8 bDescriptorSubType;
908 u32 bmEthernetStatistics;
910 u16 wNumberMCFilters;
911 u8 bNumberPowerFilters;
912 } __attribute__ ((packed));
915 struct header_desc *header;
916 struct union_desc *u;
917 struct ether_desc *ether;
918 struct usb_interface *control;
919 struct usb_interface *data;
922 static struct usb_driver usbnet_driver;
925 * probes control interface, claims data interface, collects the bulk
926 * endpoints, activates data interface (if needed), maybe sets MTU.
927 * all pure cdc, except for certain firmware workarounds.
929 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
931 u8 *buf = intf->altsetting->extra;
932 int len = intf->altsetting->extralen;
933 struct usb_interface_descriptor *d;
934 struct cdc_state *info = (void *) &dev->data;
938 if (sizeof dev->data < sizeof *info)
941 /* expect strict spec conformance for the descriptors, but
942 * cope with firmware which stores them in the wrong place
944 if (len == 0 && dev->udev->actconfig->extralen) {
945 /* Motorola SB4100 (and others: Brad Hards says it's
946 * from a Broadcom design) put CDC descriptors here
948 buf = dev->udev->actconfig->extra;
949 len = dev->udev->actconfig->extralen;
952 "CDC descriptors on config\n");
955 /* this assumes that if there's a non-RNDIS vendor variant
956 * of cdc-acm, it'll fail RNDIS requests cleanly.
958 rndis = (intf->altsetting->desc.bInterfaceProtocol == 0xff);
960 memset (info, 0, sizeof *info);
961 info->control = intf;
963 if (buf [1] != USB_DT_CS_INTERFACE)
966 /* use bDescriptorSubType to identify the CDC descriptors.
967 * We expect devices with CDC header and union descriptors.
968 * For CDC Ethernet we need the ethernet descriptor.
969 * For RNDIS, ignore two (pointless) CDC modem descriptors
970 * in favor of a complicated OID-based RPC scheme doing what
971 * CDC Ethernet achieves with a simple descriptor.
974 case 0x00: /* Header, mostly useless */
976 dev_dbg (&intf->dev, "extra CDC header\n");
979 info->header = (void *) buf;
980 if (info->header->bLength != sizeof *info->header) {
981 dev_dbg (&intf->dev, "CDC header len %u\n",
982 info->header->bLength);
986 case 0x06: /* Union (groups interfaces) */
988 dev_dbg (&intf->dev, "extra CDC union\n");
991 info->u = (void *) buf;
992 if (info->u->bLength != sizeof *info->u) {
993 dev_dbg (&intf->dev, "CDC union len %u\n",
998 /* we need a master/control interface (what we're
999 * probed with) and a slave/data interface; union
1000 * descriptors sort this all out.
1002 info->control = usb_ifnum_to_if(dev->udev,
1003 info->u->bMasterInterface0);
1004 info->data = usb_ifnum_to_if(dev->udev,
1005 info->u->bSlaveInterface0);
1006 if (!info->control || !info->data) {
1007 dev_dbg (&intf->dev,
1008 "master #%u/%p slave #%u/%p\n",
1009 info->u->bMasterInterface0
1011 info->u->bSlaveInterface0,
1015 if (info->control != intf) {
1016 dev_dbg (&intf->dev, "bogus CDC Union\n");
1017 /* Ambit USB Cable Modem (and maybe others)
1018 * interchanges master and slave interface.
1020 if (info->data == intf) {
1021 info->data = info->control;
1022 info->control = intf;
1027 /* a data interface altsetting does the real i/o */
1028 d = &info->data->altsetting->desc;
1029 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1030 dev_dbg (&intf->dev, "slave class %u\n",
1031 d->bInterfaceClass);
1035 case 0x0F: /* Ethernet Networking */
1037 dev_dbg (&intf->dev, "extra CDC ether\n");
1040 info->ether = (void *) buf;
1041 if (info->ether->bLength != sizeof *info->ether) {
1042 dev_dbg (&intf->dev, "CDC ether len %u\n",
1046 dev->net->mtu = cpu_to_le16p (
1047 &info->ether->wMaxSegmentSize)
1049 /* because of Zaurus, we may be ignoring the host
1050 * side link address we were given.
1055 len -= buf [0]; /* bLength */
1059 if (!info->header || !info->u || (!rndis && !info->ether)) {
1060 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1061 info->header ? "" : "header ",
1062 info->u ? "" : "union ",
1063 info->ether ? "" : "ether ");
1067 /* claim data interface and set it up ... with side effects.
1068 * network traffic can't flow until an altsetting is enabled.
1070 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1073 status = get_endpoints (dev, info->data);
1075 /* ensure immediate exit from usbnet_disconnect */
1076 usb_set_intfdata(info->data, NULL);
1077 usb_driver_release_interface (&usbnet_driver, info->data);
1083 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1087 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1089 struct cdc_state *info = (void *) &dev->data;
1091 /* disconnect master --> disconnect slave */
1092 if (intf == info->control && info->data) {
1093 /* ensure immediate exit from usbnet_disconnect */
1094 usb_set_intfdata(info->data, NULL);
1095 usb_driver_release_interface (&usbnet_driver, info->data);
1099 /* and vice versa (just in case) */
1100 else if (intf == info->data && info->control) {
1101 /* ensure immediate exit from usbnet_disconnect */
1102 usb_set_intfdata(info->control, NULL);
1103 usb_driver_release_interface (&usbnet_driver, info->control);
1108 #endif /* NEED_GENERIC_CDC */
1111 #ifdef CONFIG_USB_CDCETHER
1112 #define HAVE_HARDWARE
1114 /*-------------------------------------------------------------------------
1116 * Communications Device Class, Ethernet Control model
1118 * Takes two interfaces. The DATA interface is inactive till an altsetting
1119 * is selected. Configuration data includes class descriptors.
1121 * This should interop with whatever the 2.4 "CDCEther.c" driver
1122 * (by Brad Hards) talked with.
1124 *-------------------------------------------------------------------------*/
1126 #include <linux/ctype.h>
1128 static u8 nibble (unsigned char c)
1130 if (likely (isdigit (c)))
1133 if (likely (isxdigit (c)))
1134 return 10 + c - 'A';
1139 get_ethernet_addr (struct usbnet *dev, struct ether_desc *e)
1142 unsigned char buf [13];
1144 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1149 for (i = tmp = 0; i < 6; i++, tmp += 2)
1150 dev->net->dev_addr [i] =
1151 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1155 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1158 struct cdc_state *info = (void *) &dev->data;
1160 status = generic_cdc_bind (dev, intf);
1164 status = get_ethernet_addr (dev, info->ether);
1166 usb_driver_release_interface (&usbnet_driver, info->data);
1170 /* FIXME cdc-ether has some multicast code too, though it complains
1171 * in routine cases. info->ether describes the multicast support.
1176 static const struct driver_info cdc_info = {
1177 .description = "CDC Ethernet Device",
1178 .flags = FLAG_ETHER,
1179 // .check_connect = cdc_check_connect,
1181 .unbind = cdc_unbind,
1184 #endif /* CONFIG_USB_CDCETHER */
1188 #ifdef CONFIG_USB_EPSON2888
1189 #define HAVE_HARDWARE
1191 /*-------------------------------------------------------------------------
1195 * This is the same idea as Linux PDAs (below) except the firmware in the
1196 * device might not be Tux-powered. Epson provides reference firmware that
1197 * implements this interface. Product developers can reuse or modify that
1198 * code, such as by using their own product and vendor codes.
1200 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1202 *-------------------------------------------------------------------------*/
1204 static const struct driver_info epson2888_info = {
1205 .description = "Epson USB Device",
1206 .check_connect = always_connected,
1211 #endif /* CONFIG_USB_EPSON2888 */
1214 #ifdef CONFIG_USB_GENESYS
1215 #define HAVE_HARDWARE
1217 /*-------------------------------------------------------------------------
1219 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1221 * ... should partially interop with the Win32 driver for this hardware
1222 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1224 * Some info from GeneSys:
1225 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1226 * (Some cables, like the BAFO-100c, use the half duplex version.)
1227 * - For the full duplex model, the low bit of the version code says
1228 * which side is which ("left/right").
1229 * - For the half duplex type, a control/interrupt handshake settles
1230 * the transfer direction. (That's disabled here, partially coded.)
1231 * A control URB would block until other side writes an interrupt.
1233 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1234 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1236 *-------------------------------------------------------------------------*/
1238 // control msg write command
1239 #define GENELINK_CONNECT_WRITE 0xF0
1240 // interrupt pipe index
1241 #define GENELINK_INTERRUPT_PIPE 0x03
1242 // interrupt read buffer size
1243 #define INTERRUPT_BUFSIZE 0x08
1244 // interrupt pipe interval value
1245 #define GENELINK_INTERRUPT_INTERVAL 0x10
1246 // max transmit packet number per transmit
1247 #define GL_MAX_TRANSMIT_PACKETS 32
1248 // max packet length
1249 #define GL_MAX_PACKET_LEN 1514
1250 // max receive buffer size
1251 #define GL_RCV_BUF_SIZE \
1252 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1256 char packet_data [1];
1261 struct gl_packet packets;
1266 // FIXME: this code is incomplete, not debugged; it doesn't
1267 // handle interrupts correctly. interrupts should be generic
1268 // code like all other device I/O, anyway.
1271 struct urb *irq_urb;
1272 char irq_buf [INTERRUPT_BUFSIZE];
1275 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1279 retval = usb_control_msg (dev->udev,
1280 usb_sndctrlpipe (dev->udev, 0),
1282 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1287 CONTROL_TIMEOUT_JIFFIES);
1291 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1293 int status = urb->status;
1302 /* this urb is terminated, clean up */
1303 dbg("%s - urb shutting down with status: %d",
1304 __FUNCTION__, status);
1307 dbg("%s - nonzero urb status received: %d",
1308 __FUNCTION__, urb->status);
1311 status = usb_submit_urb (urb, GFP_ATOMIC);
1313 err ("%s - usb_submit_urb failed with result %d",
1314 __FUNCTION__, status);
1317 static int gl_interrupt_read (struct usbnet *dev)
1319 struct gl_priv *priv = dev->priv_data;
1322 // issue usb interrupt read
1323 if (priv && priv->irq_urb) {
1325 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1326 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1328 dbg ("gl_interrupt_read: submit success...");
1334 // check whether another side is connected
1335 static int genelink_check_connect (struct usbnet *dev)
1339 dbg ("genelink_check_connect...");
1341 // detect whether another side is connected
1342 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1343 dbg ("%s: genelink_check_connect write fail - %X",
1344 dev->net->name, retval);
1348 // usb interrupt read to ack another side
1349 if ((retval = gl_interrupt_read (dev)) != 0) {
1350 dbg ("%s: genelink_check_connect read fail - %X",
1351 dev->net->name, retval);
1355 dbg ("%s: genelink_check_connect read success", dev->net->name);
1359 // allocate and initialize the private data for genelink
1360 static int genelink_init (struct usbnet *dev)
1362 struct gl_priv *priv;
1364 // allocate the private data structure
1365 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1366 dbg ("%s: cannot allocate private data per device",
1372 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1373 dbg ("%s: cannot allocate private irq urb per device",
1380 usb_fill_int_urb (priv->irq_urb, dev->udev,
1381 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1382 priv->irq_buf, INTERRUPT_BUFSIZE,
1383 gl_interrupt_complete, 0,
1384 GENELINK_INTERRUPT_INTERVAL);
1386 // set private data pointer
1387 dev->priv_data = priv;
1392 // release the private data
1393 static int genelink_free (struct usbnet *dev)
1395 struct gl_priv *priv = dev->priv_data;
1400 // FIXME: can't cancel here; it's synchronous, and
1401 // should have happened earlier in any case (interrupt
1402 // handling needs to be generic)
1404 // cancel irq urb first
1405 usb_unlink_urb (priv->irq_urb);
1408 usb_free_urb (priv->irq_urb);
1410 // free the private data structure
1418 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1420 struct gl_header *header;
1421 struct gl_packet *packet;
1422 struct sk_buff *gl_skb;
1425 header = (struct gl_header *) skb->data;
1427 // get the packet count of the received skb
1428 le32_to_cpus (&header->packet_count);
1429 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1430 || (header->packet_count < 0)) {
1431 dbg ("genelink: invalid received packet count %d",
1432 header->packet_count);
1436 // set the current packet pointer to the first packet
1437 packet = &header->packets;
1439 // decrement the length for the packet count size 4 bytes
1442 while (header->packet_count > 1) {
1443 // get the packet length
1444 size = packet->packet_length;
1446 // this may be a broken packet
1447 if (size > GL_MAX_PACKET_LEN) {
1448 dbg ("genelink: invalid rx length %d", size);
1452 // allocate the skb for the individual packet
1453 gl_skb = alloc_skb (size, GFP_ATOMIC);
1456 // copy the packet data to the new skb
1457 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1458 skb_return (dev, skb);
1461 // advance to the next packet
1462 packet = (struct gl_packet *)
1463 &packet->packet_data [size];
1464 header->packet_count--;
1466 // shift the data pointer to the next gl_packet
1467 skb_pull (skb, size + 4);
1470 // skip the packet length field 4 bytes
1473 if (skb->len > GL_MAX_PACKET_LEN) {
1474 dbg ("genelink: invalid rx length %d", skb->len);
1480 static struct sk_buff *
1481 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1484 int length = skb->len;
1485 int headroom = skb_headroom (skb);
1486 int tailroom = skb_tailroom (skb);
1490 // FIXME: magic numbers, bleech
1491 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1493 if ((!skb_cloned (skb))
1494 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1495 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1496 skb->data = memmove (skb->head + (4 + 4*1),
1497 skb->data, skb->len);
1498 skb->tail = skb->data + skb->len;
1501 struct sk_buff *skb2;
1502 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1503 dev_kfree_skb_any (skb);
1509 // attach the packet count to the header
1510 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1511 packet_len = packet_count + 1;
1513 // FIXME little endian?
1515 *packet_len = length;
1518 if ((skb->len % dev->maxpacket) == 0)
1524 static const struct driver_info genelink_info = {
1525 .description = "Genesys GeneLink",
1526 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1527 .rx_fixup = genelink_rx_fixup,
1528 .tx_fixup = genelink_tx_fixup,
1533 .check_connect =genelink_check_connect,
1537 #endif /* CONFIG_USB_GENESYS */
1541 #ifdef CONFIG_USB_NET1080
1542 #define HAVE_HARDWARE
1544 /*-------------------------------------------------------------------------
1546 * Netchip 1080 driver ... http://www.netchip.com
1547 * Used in LapLink cables
1549 *-------------------------------------------------------------------------*/
1551 #define dev_packet_id data[0]
1552 #define frame_errors data[1]
1555 * NetChip framing of ethernet packets, supporting additional error
1556 * checks for links that may drop bulk packets from inside messages.
1557 * Odd USB length == always short read for last usb packet.
1559 * - Ethernet header (14 bytes)
1561 * - (optional padding byte, if needed so length becomes odd)
1564 * This framing is to be avoided for non-NetChip devices.
1567 struct nc_header { // packed:
1568 u16 hdr_len; // sizeof nc_header (LE, all)
1569 u16 packet_len; // payload size (including ethhdr)
1570 u16 packet_id; // detects dropped packets
1571 #define MIN_HEADER 6
1573 // all else is optional, and must start with:
1574 // u16 vendorId; // from usb-if
1576 } __attribute__((__packed__));
1578 #define PAD_BYTE ((unsigned char)0xAC)
1582 } __attribute__((__packed__));
1584 // packets may use FLAG_FRAMING_NC and optional pad
1585 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1586 + sizeof (struct ethhdr) \
1589 + sizeof (struct nc_trailer))
1591 #define MIN_FRAMED FRAMED_SIZE(0)
1595 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1596 * before the hardware drops it. If that's done, the driver will need to
1597 * frame network packets to guard against the dropped USB packets. The win32
1598 * driver sets this for both sides of the link.
1600 #define NC_READ_TTL_MS ((u8)255) // ms
1603 * We ignore most registers and EEPROM contents.
1605 #define REG_USBCTL ((u8)0x04)
1606 #define REG_TTL ((u8)0x10)
1607 #define REG_STATUS ((u8)0x11)
1610 * Vendor specific requests to read/write data
1612 #define REQUEST_REGISTER ((u8)0x10)
1613 #define REQUEST_EEPROM ((u8)0x11)
1616 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1618 int status = usb_control_msg (dev->udev,
1619 usb_rcvctrlpipe (dev->udev, 0),
1621 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1623 retval_ptr, sizeof *retval_ptr,
1624 CONTROL_TIMEOUT_JIFFIES);
1628 le16_to_cpus (retval_ptr);
1633 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1635 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1638 // no retval ... can become async, usable in_interrupt()
1640 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1642 usb_control_msg (dev->udev,
1643 usb_sndctrlpipe (dev->udev, 0),
1645 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1647 0, 0, // data is in setup packet
1648 CONTROL_TIMEOUT_JIFFIES);
1652 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1654 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1659 static void nc_dump_registers (struct usbnet *dev)
1662 u16 *vp = kmalloc (sizeof (u16));
1669 dbg ("%s registers:", dev->net->name);
1670 for (reg = 0; reg < 0x20; reg++) {
1673 // reading some registers is trouble
1674 if (reg >= 0x08 && reg <= 0xf)
1676 if (reg >= 0x12 && reg <= 0x1e)
1679 retval = nc_register_read (dev, reg, vp);
1681 dbg ("%s reg [0x%x] ==> error %d",
1682 dev->net->name, reg, retval);
1684 dbg ("%s reg [0x%x] = 0x%x",
1685 dev->net->name, reg, *vp);
1692 /*-------------------------------------------------------------------------*/
1698 #define USBCTL_WRITABLE_MASK 0x1f0f
1699 // bits 15-13 reserved, r/o
1700 #define USBCTL_ENABLE_LANG (1 << 12)
1701 #define USBCTL_ENABLE_MFGR (1 << 11)
1702 #define USBCTL_ENABLE_PROD (1 << 10)
1703 #define USBCTL_ENABLE_SERIAL (1 << 9)
1704 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1705 // bits 7-4 reserved, r/o
1706 #define USBCTL_FLUSH_OTHER (1 << 3)
1707 #define USBCTL_FLUSH_THIS (1 << 2)
1708 #define USBCTL_DISCONN_OTHER (1 << 1)
1709 #define USBCTL_DISCONN_THIS (1 << 0)
1711 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1714 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1716 " other%s%s; r/o 0x%x",
1717 dev->udev->bus->bus_name, dev->udev->devpath,
1719 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1720 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1721 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1722 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1723 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1725 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1726 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1727 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1728 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1729 usbctl & ~USBCTL_WRITABLE_MASK
1734 /*-------------------------------------------------------------------------*/
1740 #define STATUS_PORT_A (1 << 15)
1742 #define STATUS_CONN_OTHER (1 << 14)
1743 #define STATUS_SUSPEND_OTHER (1 << 13)
1744 #define STATUS_MAILBOX_OTHER (1 << 12)
1745 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1747 #define STATUS_CONN_THIS (1 << 6)
1748 #define STATUS_SUSPEND_THIS (1 << 5)
1749 #define STATUS_MAILBOX_THIS (1 << 4)
1750 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1752 #define STATUS_UNSPEC_MASK 0x0c8c
1753 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1756 static inline void nc_dump_status (struct usbnet *dev, u16 status)
1759 devdbg (dev, "net1080 %s-%s status 0x%x:"
1760 " this (%c) PKT=%d%s%s%s;"
1761 " other PKT=%d%s%s%s; unspec 0x%x",
1762 dev->udev->bus->bus_name, dev->udev->devpath,
1765 // XXX the packet counts don't seem right
1766 // (1 at reset, not 0); maybe UNSPEC too
1768 (status & STATUS_PORT_A) ? 'A' : 'B',
1769 STATUS_PACKETS_THIS (status),
1770 (status & STATUS_CONN_THIS) ? " CON" : "",
1771 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1772 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1774 STATUS_PACKETS_OTHER (status),
1775 (status & STATUS_CONN_OTHER) ? " CON" : "",
1776 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1777 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1779 status & STATUS_UNSPEC_MASK
1784 /*-------------------------------------------------------------------------*/
1790 #define TTL_THIS(ttl) (0x00ff & ttl)
1791 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1792 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1794 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1797 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1798 dev->udev->bus->bus_name, dev->udev->devpath,
1807 /*-------------------------------------------------------------------------*/
1809 static int net1080_reset (struct usbnet *dev)
1811 u16 usbctl, status, ttl;
1812 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1818 // nc_dump_registers (dev);
1820 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1821 dbg ("can't read %s-%s status: %d",
1822 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1826 // nc_dump_status (dev, status);
1828 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1829 dbg ("can't read USBCTL, %d", retval);
1833 // nc_dump_usbctl (dev, usbctl);
1835 nc_register_write (dev, REG_USBCTL,
1836 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1838 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1839 dbg ("can't read TTL, %d", retval);
1843 // nc_dump_ttl (dev, ttl);
1845 nc_register_write (dev, REG_TTL,
1846 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1847 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
1849 if (dev->msg_level >= 2)
1850 devinfo (dev, "port %c, peer %sconnected",
1851 (status & STATUS_PORT_A) ? 'A' : 'B',
1852 (status & STATUS_CONN_OTHER) ? "" : "dis"
1861 static int net1080_check_connect (struct usbnet *dev)
1865 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1869 retval = nc_register_read (dev, REG_STATUS, vp);
1873 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
1876 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1881 static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
1883 kfree (urb->context);
1887 static void nc_ensure_sync (struct usbnet *dev)
1889 dev->frame_errors++;
1890 if (dev->frame_errors > 5) {
1892 struct usb_ctrlrequest *req;
1896 urb = usb_alloc_urb (0, SLAB_ATOMIC);
1900 req = kmalloc (sizeof *req, GFP_ATOMIC);
1906 req->bRequestType = USB_DIR_OUT
1909 req->bRequest = REQUEST_REGISTER;
1910 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
1911 | USBCTL_FLUSH_OTHER);
1912 req->wIndex = cpu_to_le16 (REG_USBCTL);
1913 req->wLength = cpu_to_le16 (0);
1915 /* queue an async control request, we don't need
1916 * to do anything when it finishes except clean up.
1918 usb_fill_control_urb (urb, dev->udev,
1919 usb_sndctrlpipe (dev->udev, 0),
1920 (unsigned char *) req,
1922 nc_flush_complete, req);
1923 status = usb_submit_urb (urb, GFP_ATOMIC);
1930 devdbg (dev, "flush net1080; too many framing errors");
1931 dev->frame_errors = 0;
1935 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1937 struct nc_header *header;
1938 struct nc_trailer *trailer;
1940 if (!(skb->len & 0x01)
1941 || MIN_FRAMED > skb->len
1942 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
1943 dev->stats.rx_frame_errors++;
1944 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1945 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
1947 nc_ensure_sync (dev);
1951 header = (struct nc_header *) skb->data;
1952 le16_to_cpus (&header->hdr_len);
1953 le16_to_cpus (&header->packet_len);
1954 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1955 dev->stats.rx_frame_errors++;
1956 dbg ("packet too big, %d", header->packet_len);
1957 nc_ensure_sync (dev);
1959 } else if (header->hdr_len < MIN_HEADER) {
1960 dev->stats.rx_frame_errors++;
1961 dbg ("header too short, %d", header->hdr_len);
1962 nc_ensure_sync (dev);
1964 } else if (header->hdr_len > MIN_HEADER) {
1965 // out of band data for us?
1966 dbg ("header OOB, %d bytes",
1967 header->hdr_len - MIN_HEADER);
1968 nc_ensure_sync (dev);
1969 // switch (vendor/product ids) { ... }
1971 skb_pull (skb, header->hdr_len);
1973 trailer = (struct nc_trailer *)
1974 (skb->data + skb->len - sizeof *trailer);
1975 skb_trim (skb, skb->len - sizeof *trailer);
1977 if ((header->packet_len & 0x01) == 0) {
1978 if (skb->data [header->packet_len] != PAD_BYTE) {
1979 dev->stats.rx_frame_errors++;
1983 skb_trim (skb, skb->len - 1);
1985 if (skb->len != header->packet_len) {
1986 dev->stats.rx_frame_errors++;
1987 dbg ("bad packet len %d (expected %d)",
1988 skb->len, header->packet_len);
1989 nc_ensure_sync (dev);
1992 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
1993 dev->stats.rx_fifo_errors++;
1994 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
1995 header->packet_id, trailer->packet_id);
1999 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2000 header->packet_len, header->packet_id);
2002 dev->frame_errors = 0;
2006 static struct sk_buff *
2007 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2010 struct sk_buff *skb2;
2012 padlen = ((skb->len + sizeof (struct nc_header)
2013 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2014 if (!skb_cloned (skb)) {
2015 int headroom = skb_headroom (skb);
2016 int tailroom = skb_tailroom (skb);
2018 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2019 && sizeof (struct nc_header) <= headroom)
2020 /* There's enough head and tail room */
2023 if ((sizeof (struct nc_header) + padlen
2024 + sizeof (struct nc_trailer)) <
2025 (headroom + tailroom)) {
2026 /* There's enough total room, so just readjust */
2027 skb->data = memmove (skb->head
2028 + sizeof (struct nc_header),
2029 skb->data, skb->len);
2030 skb->tail = skb->data + skb->len;
2035 /* Create a new skb to use with the correct size */
2036 skb2 = skb_copy_expand (skb,
2037 sizeof (struct nc_header),
2038 sizeof (struct nc_trailer) + padlen,
2040 dev_kfree_skb_any (skb);
2044 static const struct driver_info net1080_info = {
2045 .description = "NetChip TurboCONNECT",
2046 .flags = FLAG_FRAMING_NC,
2047 .reset = net1080_reset,
2048 .check_connect =net1080_check_connect,
2049 .rx_fixup = net1080_rx_fixup,
2050 .tx_fixup = net1080_tx_fixup,
2053 #endif /* CONFIG_USB_NET1080 */
2057 #ifdef CONFIG_USB_PL2301
2058 #define HAVE_HARDWARE
2060 /*-------------------------------------------------------------------------
2062 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2064 * The protocol and handshaking used here should be bug-compatible
2065 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2067 *-------------------------------------------------------------------------*/
2070 * Bits 0-4 can be used for software handshaking; they're set from
2071 * one end, cleared from the other, "read" with the interrupt byte.
2073 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2074 /* reserved bit -- rx ready (6) ? */
2075 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2076 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2077 #define PL_RESET_IN (1<<3) /* reset input pipe */
2078 #define PL_TX_C (1<<2) /* transmission complete */
2079 #define PL_TX_REQ (1<<1) /* transmission received */
2080 #define PL_PEER_E (1<<0) /* peer exists */
2083 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2085 return usb_control_msg (dev->udev,
2086 usb_rcvctrlpipe (dev->udev, 0),
2088 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2091 CONTROL_TIMEOUT_JIFFIES);
2095 pl_clear_QuickLink_features (struct usbnet *dev, int val)
2097 return pl_vendor_req (dev, 1, (u8) val, 0);
2101 pl_set_QuickLink_features (struct usbnet *dev, int val)
2103 return pl_vendor_req (dev, 3, (u8) val, 0);
2106 /*-------------------------------------------------------------------------*/
2108 static int pl_reset (struct usbnet *dev)
2110 /* some units seem to need this reset, others reject it utterly.
2111 * FIXME be more like "naplink" or windows drivers.
2113 (void) pl_set_QuickLink_features (dev,
2114 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2118 static const struct driver_info prolific_info = {
2119 .description = "Prolific PL-2301/PL-2302",
2120 .flags = FLAG_NO_SETINT,
2121 /* some PL-2302 versions seem to fail usb_set_interface() */
2125 #endif /* CONFIG_USB_PL2301 */
2129 #ifdef CONFIG_USB_ARMLINUX
2130 #define HAVE_HARDWARE
2132 /*-------------------------------------------------------------------------
2134 * Intel's SA-1100 chip integrates basic USB support, and is used
2135 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2136 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2137 * network using minimal USB framing data.
2139 * This describes the driver currently in standard ARM Linux kernels.
2140 * The Zaurus uses a different driver (see later).
2142 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2143 * and different USB endpoint numbering than the SA1100 devices. The
2144 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2145 * so we rely on the endpoint descriptors.
2147 *-------------------------------------------------------------------------*/
2149 static const struct driver_info linuxdev_info = {
2150 .description = "Linux Device",
2151 .check_connect = always_connected,
2154 static const struct driver_info yopy_info = {
2155 .description = "Yopy",
2156 .check_connect = always_connected,
2159 static const struct driver_info blob_info = {
2160 .description = "Boot Loader OBject",
2161 .check_connect = always_connected,
2164 #endif /* CONFIG_USB_ARMLINUX */
2167 #ifdef CONFIG_USB_ZAURUS
2168 #define HAVE_HARDWARE
2170 #include <linux/crc32.h>
2172 /*-------------------------------------------------------------------------
2174 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2175 * (and framing) for its USB slave/gadget controller than the case above.
2177 * For the current version of that driver, the main way that framing is
2178 * nonstandard (also from perspective of the CDC ethernet model!) is a
2179 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2180 * haven't been fully worked around.
2182 * PXA based models use the same framing, and also can't implement
2183 * set_interface properly.
2185 *-------------------------------------------------------------------------*/
2187 static struct sk_buff *
2188 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2191 struct sk_buff *skb2;
2194 if (!skb_cloned (skb)) {
2195 int tailroom = skb_tailroom (skb);
2196 if ((padlen + 4) <= tailroom)
2199 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2200 dev_kfree_skb_any (skb);
2205 fcs = crc32_le (~0, skb->data, skb->len);
2208 *skb_put (skb, 1) = fcs & 0xff;
2209 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2210 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2211 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2216 static const struct driver_info zaurus_sl5x00_info = {
2217 .description = "Sharp Zaurus SL-5x00",
2218 .flags = FLAG_FRAMING_Z,
2219 .check_connect = always_connected,
2220 .bind = generic_cdc_bind,
2221 .unbind = cdc_unbind,
2222 .tx_fixup = zaurus_tx_fixup,
2224 static const struct driver_info zaurus_pxa_info = {
2225 .description = "Sharp Zaurus, PXA-2xx based",
2226 .flags = FLAG_FRAMING_Z,
2227 .check_connect = always_connected,
2228 .tx_fixup = zaurus_tx_fixup,
2236 /*-------------------------------------------------------------------------
2238 * Network Device Driver (peer link to "Host Device", from USB host)
2240 *-------------------------------------------------------------------------*/
2242 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2244 struct usbnet *dev = (struct usbnet *) net->priv;
2246 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2248 #ifdef CONFIG_USB_NET1080
2249 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2250 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2254 #ifdef CONFIG_USB_GENESYS
2255 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2256 && new_mtu > GL_MAX_PACKET_LEN)
2259 // no second zero-length packet read wanted after mtu-sized packets
2260 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2266 /*-------------------------------------------------------------------------*/
2268 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2270 return &((struct usbnet *) net->priv)->stats;
2273 /*-------------------------------------------------------------------------*/
2275 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2276 * completion callbacks. 2.5 should have fixed those bugs...
2279 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2281 struct sk_buff_head *list = skb->list;
2282 unsigned long flags;
2284 spin_lock_irqsave (&list->lock, flags);
2285 __skb_unlink (skb, list);
2286 spin_unlock (&list->lock);
2287 spin_lock (&dev->done.lock);
2288 __skb_queue_tail (&dev->done, skb);
2289 if (dev->done.qlen == 1)
2290 tasklet_schedule (&dev->bh);
2291 spin_unlock_irqrestore (&dev->done.lock, flags);
2294 /* some work can't be done in tasklets, so we use keventd
2296 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2297 * but tasklet_schedule() doesn't. hope the failure is rare.
2299 static void defer_kevent (struct usbnet *dev, int work)
2301 set_bit (work, &dev->flags);
2302 if (!schedule_work (&dev->kevent))
2303 deverr (dev, "kevent %d may have been dropped", work);
2305 devdbg (dev, "kevent %d scheduled", work);
2308 /*-------------------------------------------------------------------------*/
2310 static void rx_complete (struct urb *urb, struct pt_regs *regs);
2312 static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2314 struct sk_buff *skb;
2315 struct skb_data *entry;
2317 unsigned long lockflags;
2320 #ifdef CONFIG_USB_NET1080
2321 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2322 size = FRAMED_SIZE (dev->net->mtu);
2325 #ifdef CONFIG_USB_GENESYS
2326 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2327 size = GL_RCV_BUF_SIZE;
2330 #ifdef CONFIG_USB_ZAURUS
2331 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2332 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2335 #ifdef CONFIG_USB_RNDIS
2336 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2337 size = RNDIS_MAX_TRANSFER;
2340 size = (sizeof (struct ethhdr) + dev->net->mtu);
2342 if ((skb = alloc_skb (size, flags)) == 0) {
2343 devdbg (dev, "no rx skb");
2344 defer_kevent (dev, EVENT_RX_MEMORY);
2349 entry = (struct skb_data *) skb->cb;
2352 entry->state = rx_start;
2355 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2356 skb->data, size, rx_complete, skb);
2357 urb->transfer_flags |= URB_ASYNC_UNLINK;
2359 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2361 if (netif_running (dev->net)
2362 && netif_device_present (dev->net)
2363 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2364 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2366 defer_kevent (dev, EVENT_RX_HALT);
2369 defer_kevent (dev, EVENT_RX_MEMORY);
2372 devdbg (dev, "device gone");
2373 netif_device_detach (dev->net);
2376 devdbg (dev, "rx submit, %d", retval);
2377 tasklet_schedule (&dev->bh);
2380 __skb_queue_tail (&dev->rxq, skb);
2383 devdbg (dev, "rx: stopped");
2386 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2388 dev_kfree_skb_any (skb);
2394 /*-------------------------------------------------------------------------*/
2396 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2398 if (dev->driver_info->rx_fixup
2399 && !dev->driver_info->rx_fixup (dev, skb))
2401 // else network stack removes extra byte if we forced a short packet
2404 skb_return (dev, skb);
2406 devdbg (dev, "drop");
2408 dev->stats.rx_errors++;
2409 skb_queue_tail (&dev->done, skb);
2413 /*-------------------------------------------------------------------------*/
2415 static void rx_complete (struct urb *urb, struct pt_regs *regs)
2417 struct sk_buff *skb = (struct sk_buff *) urb->context;
2418 struct skb_data *entry = (struct skb_data *) skb->cb;
2419 struct usbnet *dev = entry->dev;
2420 int urb_status = urb->status;
2422 skb_put (skb, urb->actual_length);
2423 entry->state = rx_done;
2426 switch (urb_status) {
2429 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2430 entry->state = rx_cleanup;
2431 dev->stats.rx_errors++;
2432 dev->stats.rx_length_errors++;
2433 devdbg (dev, "rx length %d", skb->len);
2437 // stalls need manual reset. this is rare ... except that
2438 // when going through USB 2.0 TTs, unplug appears this way.
2439 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2440 // storm, recovering as needed.
2442 dev->stats.rx_errors++;
2443 defer_kevent (dev, EVENT_RX_HALT);
2446 // software-driven interface shutdown
2447 case -ECONNRESET: // async unlink
2448 case -ESHUTDOWN: // hardware gone
2450 devdbg (dev, "rx shutdown, code %d", urb_status);
2454 // we get controller i/o faults during khubd disconnect() delays.
2455 // throttle down resubmits, to avoid log floods; just temporarily,
2456 // so we still recover when the fault isn't a khubd delay.
2457 case -EPROTO: // ehci
2458 case -ETIMEDOUT: // ohci
2459 case -EILSEQ: // uhci
2460 dev->stats.rx_errors++;
2461 if (!timer_pending (&dev->delay)) {
2462 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2463 devdbg (dev, "rx throttle %d", urb_status);
2466 entry->state = rx_cleanup;
2471 // data overrun ... flush fifo?
2473 dev->stats.rx_over_errors++;
2477 entry->state = rx_cleanup;
2478 dev->stats.rx_errors++;
2479 devdbg (dev, "rx status %d", urb_status);
2483 defer_bh (dev, skb);
2486 if (netif_running (dev->net)
2487 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2488 rx_submit (dev, urb, GFP_ATOMIC);
2494 devdbg (dev, "no read resubmitted");
2495 #endif /* VERBOSE */
2498 /*-------------------------------------------------------------------------*/
2500 // unlink pending rx/tx; completion handlers do all other cleanup
2502 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2504 unsigned long flags;
2505 struct sk_buff *skb, *skbnext;
2508 spin_lock_irqsave (&q->lock, flags);
2509 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2510 struct skb_data *entry;
2514 entry = (struct skb_data *) skb->cb;
2516 skbnext = skb->next;
2518 // during some PM-driven resume scenarios,
2519 // these (async) unlinks complete immediately
2520 retval = usb_unlink_urb (urb);
2521 if (retval != -EINPROGRESS && retval != 0)
2522 devdbg (dev, "unlink urb err, %d", retval);
2526 spin_unlock_irqrestore (&q->lock, flags);
2531 /*-------------------------------------------------------------------------*/
2533 // precondition: never called in_interrupt
2535 static int usbnet_stop (struct net_device *net)
2537 struct usbnet *dev = (struct usbnet *) net->priv;
2539 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2540 DECLARE_WAITQUEUE (wait, current);
2542 netif_stop_queue (net);
2544 if (dev->msg_level >= 2)
2545 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2546 dev->stats.rx_packets, dev->stats.tx_packets,
2547 dev->stats.rx_errors, dev->stats.tx_errors
2550 // ensure there are no more active urbs
2551 add_wait_queue (&unlink_wakeup, &wait);
2552 dev->wait = &unlink_wakeup;
2553 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2555 // maybe wait for deletions to finish.
2556 while (skb_queue_len (&dev->rxq)
2557 && skb_queue_len (&dev->txq)
2558 && skb_queue_len (&dev->done)) {
2559 set_current_state (TASK_UNINTERRUPTIBLE);
2560 schedule_timeout (UNLINK_TIMEOUT_JIFFIES);
2561 devdbg (dev, "waited for %d urb completions", temp);
2564 remove_wait_queue (&unlink_wakeup, &wait);
2566 /* deferred work (task, timer, softirq) must also stop.
2567 * can't flush_scheduled_work() until we drop rtnl (later),
2568 * else workers could deadlock; so make workers a NOP.
2571 del_timer_sync (&dev->delay);
2572 tasklet_kill (&dev->bh);
2577 /*-------------------------------------------------------------------------*/
2579 // posts reads, and enables write queuing
2581 // precondition: never called in_interrupt
2583 static int usbnet_open (struct net_device *net)
2585 struct usbnet *dev = (struct usbnet *) net->priv;
2587 struct driver_info *info = dev->driver_info;
2589 // put into "known safe" state
2590 if (info->reset && (retval = info->reset (dev)) < 0) {
2591 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2593 dev->udev->bus->bus_name, dev->udev->devpath,
2598 // insist peer be connected
2599 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2600 devdbg (dev, "can't open; %d", retval);
2604 netif_start_queue (net);
2605 if (dev->msg_level >= 2) {
2608 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2609 framing = "NetChip";
2610 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
2611 framing = "GeneSys";
2612 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
2614 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
2619 devinfo (dev, "open: enable queueing "
2620 "(rx %d, tx %d) mtu %d %s framing",
2621 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
2625 // delay posting reads until we're fully open
2626 tasklet_schedule (&dev->bh);
2631 /*-------------------------------------------------------------------------*/
2633 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2635 struct usbnet *dev = net->priv;
2637 strncpy (info->driver, driver_name, sizeof info->driver);
2638 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2639 strncpy (info->fw_version, dev->driver_info->description,
2640 sizeof info->fw_version);
2641 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2644 static u32 usbnet_get_link (struct net_device *net)
2646 struct usbnet *dev = net->priv;
2648 /* If a check_connect is defined, return it's results */
2649 if (dev->driver_info->check_connect)
2650 return dev->driver_info->check_connect (dev) == 0;
2652 /* Otherwise, we're up to avoid breaking scripts */
2656 static u32 usbnet_get_msglevel (struct net_device *net)
2658 struct usbnet *dev = net->priv;
2660 return dev->msg_level;
2663 static void usbnet_set_msglevel (struct net_device *net, u32 level)
2665 struct usbnet *dev = net->priv;
2667 dev->msg_level = level;
2670 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2674 struct usbnet *dev = (struct usbnet *)net->priv;
2676 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2677 return generic_mii_ioctl(&dev->mii,
2678 (struct mii_ioctl_data *) &rq->ifr_data,
2685 /*-------------------------------------------------------------------------*/
2687 /* work that cannot be done in interrupt context uses keventd.
2689 * NOTE: with 2.5 we could do more of this using completion callbacks,
2690 * especially now that control transfers can be queued.
2695 struct usbnet *dev = data;
2698 /* usb_clear_halt() needs a thread context */
2699 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2700 unlink_urbs (dev, &dev->txq);
2701 status = usb_clear_halt (dev->udev, dev->out);
2703 deverr (dev, "can't clear tx halt, status %d",
2706 clear_bit (EVENT_TX_HALT, &dev->flags);
2707 netif_wake_queue (dev->net);
2710 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2711 unlink_urbs (dev, &dev->rxq);
2712 status = usb_clear_halt (dev->udev, dev->in);
2714 deverr (dev, "can't clear rx halt, status %d",
2717 clear_bit (EVENT_RX_HALT, &dev->flags);
2718 tasklet_schedule (&dev->bh);
2722 /* tasklet could resubmit itself forever if memory is tight */
2723 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2724 struct urb *urb = 0;
2726 if (netif_running (dev->net))
2727 urb = usb_alloc_urb (0, GFP_KERNEL);
2729 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2731 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2732 rx_submit (dev, urb, GFP_KERNEL);
2733 tasklet_schedule (&dev->bh);
2738 devdbg (dev, "kevent done, flags = 0x%lx",
2742 /*-------------------------------------------------------------------------*/
2744 static void tx_complete (struct urb *urb, struct pt_regs *regs)
2746 struct sk_buff *skb = (struct sk_buff *) urb->context;
2747 struct skb_data *entry = (struct skb_data *) skb->cb;
2748 struct usbnet *dev = entry->dev;
2750 if (urb->status == 0) {
2751 dev->stats.tx_packets++;
2752 dev->stats.tx_bytes += entry->length;
2754 dev->stats.tx_errors++;
2756 switch (urb->status) {
2758 defer_kevent (dev, EVENT_TX_HALT);
2761 // like rx, tx gets controller i/o faults during khubd delays
2762 // and so it uses the same throttling mechanism.
2763 case -EPROTO: // ehci
2764 case -ETIMEDOUT: // ohci
2765 case -EILSEQ: // uhci
2766 if (!timer_pending (&dev->delay)) {
2767 mod_timer (&dev->delay,
2768 jiffies + THROTTLE_JIFFIES);
2769 devdbg (dev, "tx throttle %d", urb->status);
2771 netif_stop_queue (dev->net);
2774 devdbg (dev, "tx err %d", entry->urb->status);
2780 entry->state = tx_done;
2781 defer_bh (dev, skb);
2784 /*-------------------------------------------------------------------------*/
2786 static void usbnet_tx_timeout (struct net_device *net)
2788 struct usbnet *dev = (struct usbnet *) net->priv;
2790 unlink_urbs (dev, &dev->txq);
2791 tasklet_schedule (&dev->bh);
2793 // FIXME: device recovery -- reset?
2796 /*-------------------------------------------------------------------------*/
2798 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2800 struct usbnet *dev = (struct usbnet *) net->priv;
2802 int retval = NET_XMIT_SUCCESS;
2803 struct urb *urb = 0;
2804 struct skb_data *entry;
2805 struct driver_info *info = dev->driver_info;
2806 unsigned long flags;
2807 #ifdef CONFIG_USB_NET1080
2808 struct nc_header *header = 0;
2809 struct nc_trailer *trailer = 0;
2810 #endif /* CONFIG_USB_NET1080 */
2812 // some devices want funky USB-level framing, for
2813 // win32 driver (usually) and/or hardware quirks
2814 if (info->tx_fixup) {
2815 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2817 devdbg (dev, "can't tx_fixup skb");
2823 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
2824 devdbg (dev, "no urb");
2828 entry = (struct skb_data *) skb->cb;
2831 entry->state = tx_start;
2832 entry->length = length;
2834 // FIXME: reorganize a bit, so that fixup() fills out NetChip
2835 // framing too. (Packet ID update needs the spinlock...)
2836 // [ BETTER: we already own net->xmit_lock, that's enough ]
2838 #ifdef CONFIG_USB_NET1080
2839 if (info->flags & FLAG_FRAMING_NC) {
2840 header = (struct nc_header *) skb_push (skb, sizeof *header);
2841 header->hdr_len = cpu_to_le16 (sizeof (*header));
2842 header->packet_len = cpu_to_le16 (length);
2843 if (!((skb->len + sizeof *trailer) & 0x01))
2844 *skb_put (skb, 1) = PAD_BYTE;
2845 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2847 #endif /* CONFIG_USB_NET1080 */
2849 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2850 skb->data, skb->len, tx_complete, skb);
2851 urb->transfer_flags |= URB_ASYNC_UNLINK;
2853 /* don't assume the hardware handles USB_ZERO_PACKET
2854 * NOTE: strictly conforming cdc-ether devices should expect
2855 * the ZLP here, but ignore the one-byte packet.
2857 * FIXME zero that byte, if it doesn't require a new skb.
2859 if ((length % dev->maxpacket) == 0)
2860 urb->transfer_buffer_length++;
2862 spin_lock_irqsave (&dev->txq.lock, flags);
2864 #ifdef CONFIG_USB_NET1080
2865 if (info->flags & FLAG_FRAMING_NC) {
2866 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
2867 put_unaligned (header->packet_id, &trailer->packet_id);
2869 devdbg (dev, "frame >tx h %d p %d id %d",
2870 header->hdr_len, header->packet_len,
2874 #endif /* CONFIG_USB_NET1080 */
2876 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2878 netif_stop_queue (net);
2879 defer_kevent (dev, EVENT_TX_HALT);
2882 devdbg (dev, "tx: submit urb err %d", retval);
2885 net->trans_start = jiffies;
2886 __skb_queue_tail (&dev->txq, skb);
2887 if (dev->txq.qlen >= TX_QLEN (dev))
2888 netif_stop_queue (net);
2890 spin_unlock_irqrestore (&dev->txq.lock, flags);
2893 devdbg (dev, "drop, code %d", retval);
2895 retval = NET_XMIT_SUCCESS;
2896 dev->stats.tx_dropped++;
2898 dev_kfree_skb_any (skb);
2902 devdbg (dev, "> tx, len %d, type 0x%x",
2903 length, skb->protocol);
2910 /*-------------------------------------------------------------------------*/
2912 // tasklet (work deferred from completions, in_irq) or timer
2914 static void usbnet_bh (unsigned long param)
2916 struct usbnet *dev = (struct usbnet *) param;
2917 struct sk_buff *skb;
2918 struct skb_data *entry;
2920 while ((skb = skb_dequeue (&dev->done))) {
2921 entry = (struct skb_data *) skb->cb;
2922 switch (entry->state) {
2924 entry->state = rx_cleanup;
2925 rx_process (dev, skb);
2929 usb_free_urb (entry->urb);
2930 dev_kfree_skb (skb);
2933 devdbg (dev, "bogus skb state %d", entry->state);
2937 // waiting for all pending urbs to complete?
2939 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
2940 wake_up (dev->wait);
2943 // or are we maybe short a few urbs?
2944 } else if (netif_running (dev->net)
2945 && netif_device_present (dev->net)
2946 && !timer_pending (&dev->delay)
2947 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2948 int temp = dev->rxq.qlen;
2949 int qlen = RX_QLEN (dev);
2955 // don't refill the queue all at once
2956 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
2957 if ((urb = usb_alloc_urb (0, GFP_ATOMIC)) != 0)
2958 rx_submit (dev, urb, GFP_ATOMIC);
2960 if (temp != dev->rxq.qlen)
2961 devdbg (dev, "rxqlen %d --> %d",
2962 temp, dev->rxq.qlen);
2963 if (dev->rxq.qlen < qlen)
2964 tasklet_schedule (&dev->bh);
2966 if (dev->txq.qlen < TX_QLEN (dev))
2967 netif_wake_queue (dev->net);
2973 /*-------------------------------------------------------------------------
2975 * USB Device Driver support
2977 *-------------------------------------------------------------------------*/
2979 // precondition: never called in_interrupt
2981 static void usbnet_disconnect (struct usb_interface *intf)
2984 struct usb_device *xdev;
2986 dev = usb_get_intfdata(intf);
2987 usb_set_intfdata(intf, NULL);
2991 xdev = interface_to_usbdev (intf);
2993 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
2994 xdev->bus->bus_name, xdev->devpath,
2995 dev->driver_info->description);
2997 unregister_netdev (dev->net);
2999 /* we don't hold rtnl here ... */
3000 flush_scheduled_work ();
3002 if (dev->driver_info->unbind)
3003 dev->driver_info->unbind (dev, intf);
3005 free_netdev(dev->net);
3011 /*-------------------------------------------------------------------------*/
3013 static struct ethtool_ops usbnet_ethtool_ops;
3015 // precondition: never called in_interrupt
3018 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3021 struct net_device *net;
3022 struct usb_host_interface *interface;
3023 struct driver_info *info;
3024 struct usb_device *xdev;
3027 info = (struct driver_info *) prod->driver_info;
3029 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3032 xdev = interface_to_usbdev (udev);
3033 interface = udev->cur_altsetting;
3039 // set up our own records
3040 if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) {
3041 dbg ("can't kmalloc dev");
3044 memset (dev, 0, sizeof *dev);
3047 dev->driver_info = info;
3048 dev->msg_level = msg_level;
3049 skb_queue_head_init (&dev->rxq);
3050 skb_queue_head_init (&dev->txq);
3051 skb_queue_head_init (&dev->done);
3052 dev->bh.func = usbnet_bh;
3053 dev->bh.data = (unsigned long) dev;
3054 INIT_WORK (&dev->kevent, kevent, dev);
3055 dev->delay.function = usbnet_bh;
3056 dev->delay.data = (unsigned long) dev;
3057 init_timer (&dev->delay);
3059 // set up network interface records
3060 net = alloc_etherdev(0);
3064 SET_MODULE_OWNER (net);
3067 strcpy (net->name, "usb%d");
3068 memcpy (net->dev_addr, node_id, sizeof node_id);
3071 // dma_supported() is deeply broken on almost all architectures
3072 // possible with some EHCI controllers
3073 if (dma_supported (&udev->dev, 0xffffffffffffffffULL))
3074 net->features |= NETIF_F_HIGHDMA;
3077 net->change_mtu = usbnet_change_mtu;
3078 net->get_stats = usbnet_get_stats;
3079 net->hard_start_xmit = usbnet_start_xmit;
3080 net->open = usbnet_open;
3081 net->stop = usbnet_stop;
3082 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3083 net->tx_timeout = usbnet_tx_timeout;
3084 net->do_ioctl = usbnet_ioctl;
3085 net->ethtool_ops = &usbnet_ethtool_ops;
3087 // allow device-specific bind/init procedures
3088 // NOTE net->name still not usable ...
3090 status = info->bind (dev, udev);
3091 // heuristic: "usb%d" for links we know are two-host,
3092 // else "eth%d" when there's reasonable doubt. userspace
3093 // can rename the link if it knows better.
3094 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3095 && (net->dev_addr [0] & 0x02) == 0)
3096 strcpy (net->name, "eth%d");
3097 } else if (!info->in || info->out)
3098 status = get_endpoints (dev, udev);
3100 dev->in = usb_rcvbulkpipe (xdev, info->in);
3101 dev->out = usb_sndbulkpipe (xdev, info->out);
3102 if (!(info->flags & FLAG_NO_SETINT))
3103 status = usb_set_interface (xdev,
3104 interface->desc.bInterfaceNumber,
3105 interface->desc.bAlternateSetting);
3113 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3115 SET_NETDEV_DEV(dev->net, &udev->dev);
3116 status = register_netdev (dev->net);
3119 devinfo (dev, "register usbnet at usb-%s-%s, %s",
3120 xdev->bus->bus_name, xdev->devpath,
3121 dev->driver_info->description);
3123 // ok, it's ready to go.
3124 usb_set_intfdata (udev, dev);
3126 // start as if the link is up
3127 netif_device_attach (dev->net);
3133 info->unbind (dev, udev);
3143 /*-------------------------------------------------------------------------*/
3145 #ifndef HAVE_HARDWARE
3146 #error You need to configure some hardware for this driver
3150 * chip vendor names won't normally be on the cables, and
3151 * may not be on the device.
3154 static const struct usb_device_id products [] = {
3156 #ifdef CONFIG_USB_ALI_M5632
3158 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3159 .driver_info = (unsigned long) &ali_m5632_info,
3163 #ifdef CONFIG_USB_AN2720
3165 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3166 .driver_info = (unsigned long) &an2720_info,
3168 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3169 .driver_info = (unsigned long) &an2720_info,
3173 #ifdef CONFIG_USB_BELKIN
3175 USB_DEVICE (0x050d, 0x0004), // Belkin
3176 .driver_info = (unsigned long) &belkin_info,
3178 USB_DEVICE (0x056c, 0x8100), // eTEK
3179 .driver_info = (unsigned long) &belkin_info,
3181 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3182 .driver_info = (unsigned long) &belkin_info,
3186 #ifdef CONFIG_USB_AX8817X
3189 USB_DEVICE (0x077b, 0x2226),
3190 .driver_info = (unsigned long) &ax8817x_info,
3193 USB_DEVICE (0x0846, 0x1040),
3194 .driver_info = (unsigned long) &netgear_fa120_info,
3197 USB_DEVICE (0x2001, 0x1a00),
3198 .driver_info = (unsigned long) &dlink_dub_e100_info,
3200 // Intellinet, ST Lab USB Ethernet
3201 USB_DEVICE (0x0b95, 0x1720),
3202 .driver_info = (unsigned long) &ax8817x_info,
3204 // Hawking UF200, TrendNet TU2-ET100
3205 USB_DEVICE (0x07b8, 0x420a),
3206 .driver_info = (unsigned long) &hawking_uf200_info,
3209 USB_DEVICE (0x0557, 0x2009),
3210 .driver_info = (unsigned long) &ax8817x_info,
3214 #ifdef CONFIG_USB_EPSON2888
3216 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3217 .driver_info = (unsigned long) &epson2888_info,
3221 #ifdef CONFIG_USB_GENESYS
3223 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3224 .driver_info = (unsigned long) &genelink_info,
3226 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3227 * that's half duplex, not currently supported
3231 #ifdef CONFIG_USB_NET1080
3233 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3234 .driver_info = (unsigned long) &net1080_info,
3236 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3237 .driver_info = (unsigned long) &net1080_info,
3241 #ifdef CONFIG_USB_PL2301
3243 USB_DEVICE (0x067b, 0x0000), // PL-2301
3244 .driver_info = (unsigned long) &prolific_info,
3246 USB_DEVICE (0x067b, 0x0001), // PL-2302
3247 .driver_info = (unsigned long) &prolific_info,
3251 #ifdef CONFIG_USB_RNDIS
3253 /* RNDIS is MSFT's un-official variant of CDC ACM */
3254 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3255 .driver_info = (unsigned long) &rndis_info,
3259 #ifdef CONFIG_USB_ARMLINUX
3261 * SA-1100 using standard ARM Linux kernels, or compatible.
3262 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3263 * The sa-1100 "usb-eth" driver handles the basic framing.
3265 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3266 * the sa1100 one, but hardware uses different endpoint numbers.
3269 // 1183 = 0x049F, both used as hex values?
3270 // Compaq "Itsy" vendor/product id
3271 USB_DEVICE (0x049F, 0x505A),
3272 .driver_info = (unsigned long) &linuxdev_info,
3274 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3275 .driver_info = (unsigned long) &yopy_info,
3277 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3278 .driver_info = (unsigned long) &blob_info,
3282 #ifdef CONFIG_USB_ZAURUS
3284 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3285 * Same idea as above, but different framing.
3287 * PXA-2xx based models are also lying-about-cdc.
3290 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3291 | USB_DEVICE_ID_MATCH_DEVICE,
3293 .idProduct = 0x8004,
3294 /* match the master interface */
3295 .bInterfaceClass = USB_CLASS_COMM,
3296 .bInterfaceSubClass = 6 /* Ethernet model */,
3297 .bInterfaceProtocol = 0,
3298 .driver_info = (unsigned long) &zaurus_sl5x00_info,
3300 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3301 | USB_DEVICE_ID_MATCH_DEVICE,
3303 .idProduct = 0x8005, /* A-300 */
3304 .bInterfaceClass = 0x02,
3305 .bInterfaceSubClass = 0x0a,
3306 .bInterfaceProtocol = 0x00,
3307 .driver_info = (unsigned long) &zaurus_pxa_info,
3309 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3310 | USB_DEVICE_ID_MATCH_DEVICE,
3312 .idProduct = 0x8006, /* B-500/SL-5600 */
3313 .bInterfaceClass = 0x02,
3314 .bInterfaceSubClass = 0x0a,
3315 .bInterfaceProtocol = 0x00,
3316 .driver_info = (unsigned long) &zaurus_pxa_info,
3318 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3319 | USB_DEVICE_ID_MATCH_DEVICE,
3321 .idProduct = 0x8007, /* C-700 */
3322 .bInterfaceClass = 0x02,
3323 .bInterfaceSubClass = 0x0a,
3324 .bInterfaceProtocol = 0x00,
3325 .driver_info = (unsigned long) &zaurus_pxa_info,
3327 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3328 | USB_DEVICE_ID_MATCH_DEVICE,
3330 .idProduct = 0x9031, /* C-750 C-760 */
3331 .bInterfaceClass = 0x02,
3332 .bInterfaceSubClass = 0x0a,
3333 .bInterfaceProtocol = 0x00,
3334 .driver_info = (unsigned long) &zaurus_pxa_info,
3336 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3337 | USB_DEVICE_ID_MATCH_DEVICE,
3339 .idProduct = 0x9032, /* SL-6000 */
3340 .bInterfaceClass = 0x02,
3341 .bInterfaceSubClass = 0x0a,
3342 .bInterfaceProtocol = 0x00,
3343 .driver_info = (unsigned long) &zaurus_pxa_info,
3345 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3346 | USB_DEVICE_ID_MATCH_DEVICE,
3348 .idProduct = 0x9050, /* C-860 */
3349 .bInterfaceClass = 0x02,
3350 .bInterfaceSubClass = 0x0a,
3351 .bInterfaceProtocol = 0x00,
3352 .driver_info = (unsigned long) &zaurus_pxa_info,
3356 #ifdef CONFIG_USB_CDCETHER
3358 #ifndef CONFIG_USB_ZAURUS
3359 /* if we couldn't whitelist Zaurus, we must blacklist it */
3361 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3362 | USB_DEVICE_ID_MATCH_DEVICE,
3364 .idProduct = 0x8004,
3365 /* match the master interface */
3366 .bInterfaceClass = USB_CLASS_COMM,
3367 .bInterfaceSubClass = 6 /* Ethernet model */,
3368 .bInterfaceProtocol = 0,
3369 .driver_info = 0, /* BLACKLIST */
3371 // FIXME blacklist the other Zaurus models too, sigh
3375 /* CDC Ether uses two interfaces, not necessarily consecutive.
3376 * We match the main interface, ignoring the optional device
3377 * class so we could handle devices that aren't exclusively
3380 * NOTE: this match must come AFTER entries working around
3381 * bugs/quirks in a given product (like Zaurus, above).
3383 USB_INTERFACE_INFO (USB_CLASS_COMM, 6 /* Ethernet model */, 0),
3384 .driver_info = (unsigned long) &cdc_info,
3390 MODULE_DEVICE_TABLE (usb, products);
3392 static struct usb_driver usbnet_driver = {
3393 .owner = THIS_MODULE,
3394 .name = driver_name,
3395 .id_table = products,
3396 .probe = usbnet_probe,
3397 .disconnect = usbnet_disconnect,
3400 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
3401 static struct ethtool_ops usbnet_ethtool_ops = {
3402 .get_drvinfo = usbnet_get_drvinfo,
3403 .get_link = usbnet_get_link,
3404 .get_msglevel = usbnet_get_msglevel,
3405 .set_msglevel = usbnet_set_msglevel,
3408 /*-------------------------------------------------------------------------*/
3410 static int __init usbnet_init (void)
3412 // compiler should optimize these out
3413 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3414 < sizeof (struct skb_data));
3415 #ifdef CONFIG_USB_CDCETHER
3416 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3417 < sizeof (struct cdc_state)));
3420 random_ether_addr(node_id);
3422 return usb_register(&usbnet_driver);
3424 module_init (usbnet_init);
3426 static void __exit usbnet_exit (void)
3428 usb_deregister (&usbnet_driver);
3430 module_exit (usbnet_exit);
3432 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
3433 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
3434 MODULE_LICENSE ("GPL");