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)
34 * - KC Technology KC2190
36 * + Smart USB devices can support such links directly, using Internet
37 * standard protocols instead of proprietary host-to-device links.
38 * - Linux PDAs like iPaq, Yopy, and Zaurus
39 * - The BLOB boot loader (for diskless booting)
40 * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
41 * - Devices using EPSON's sample USB firmware
42 * - CDC-Ethernet class devices, such as many cable modems
44 * + Adapters to networks such as Ethernet.
45 * - AX8817X based USB 2.0 products
47 * Links to these devices can be bridged using Linux Ethernet bridging.
48 * With minor exceptions, these all use similar USB framing for network
49 * traffic, but need different protocols for control traffic.
51 * USB devices can implement their side of this protocol at the cost
52 * of two bulk endpoints; it's not restricted to "cable" applications.
53 * See the SA1110, Zaurus, or EPSON device/client support in this driver;
54 * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
55 * "g_ether" (in the Linux "gadget" framework) implement that behavior
61 * 13-sep-2000 experimental, new
62 * 10-oct-2000 usb_device_id table created.
63 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
64 * 01-nov-2000 usb_device_id table and probing api update by
65 * Adam J. Richter <adam@yggdrasil.com>.
66 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
67 * and prolific support, isolate net1080-specific bits, cleanup.
68 * fix unlink_urbs oops in D3 PM resume code path.
70 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
71 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
72 * AnchorChips 2720 support (from spec) for testing;
73 * fix bit-ordering problem with ethernet multicast addr
74 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
75 * updates. Oleg Drokin (green@iXcelerator.com)
76 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
77 * expecting cleared skb->cb and framing change to match latest
78 * handhelds.org version (Oleg). Enable device IDs from the
79 * Win32 Belkin driver; other cleanups (db).
80 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
81 * cleanups for problems not yet seen in the field. (db)
82 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
83 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
84 * rx unlinks somehow weren't async; minor cleanup.
85 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
86 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
87 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
88 * tie mostly to (sub)driver info. Workaround some PL-2302
89 * chips that seem to reject SET_INTERFACE requests.
91 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
92 * Level of diagnostics is more configurable; they use device
93 * location (usb_device->devpath) instead of address (2.5).
94 * For tx_fixup, memflags can't be NOIO.
95 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
96 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
97 * Use "locally assigned" IEEE802 address space. (Brad Hards)
98 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
99 * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
100 * cleanups and stubbed PXA-250 support (db), fix for framing
101 * issues on Z, net1080, and gl620a (Toby Milne)
103 * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
104 * vs pxa25x, and CDC Ethernet. Throttle down log floods on
105 * disconnect; other cleanups. (db) Flush net1080 fifos
106 * after several sequential framing errors. (Johannes Erdfelt)
107 * 22-aug-2003 AX8817X support (Dave Hollis).
108 * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
110 * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
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/kmod.h>
123 #include <linux/sched.h>
124 #include <linux/init.h>
125 #include <linux/netdevice.h>
126 #include <linux/etherdevice.h>
127 #include <linux/random.h>
128 #include <linux/ethtool.h>
129 #include <linux/workqueue.h>
130 #include <linux/mii.h>
131 #include <asm/uaccess.h>
132 #include <asm/unaligned.h>
133 #include <linux/usb.h>
135 #include <asm/scatterlist.h>
136 #include <linux/mm.h>
137 #include <linux/dma-mapping.h>
139 #define DRIVER_VERSION "03-Nov-2004"
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).
151 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
152 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
154 // packets are always ethernet inside
155 // ... except they can be bigger (limit of 64K with NetChip framing)
156 #define MIN_PACKET sizeof(struct ethhdr)
157 #define MAX_PACKET 32768
159 // reawaken network queue this soon after stopping; else watchdog barks
160 #define TX_TIMEOUT_JIFFIES (5*HZ)
162 // throttle rx/tx briefly after some faults, so khubd might disconnect()
163 // us (it polls at HZ/4 usually) before we report too many false errors.
164 #define THROTTLE_JIFFIES (HZ/8)
166 // for vendor-specific control operations
167 #define CONTROL_TIMEOUT_MS (500) /* msec */
168 #define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
171 #define UNLINK_TIMEOUT_MS 3
173 /*-------------------------------------------------------------------------*/
175 // randomly generated ethernet address
176 static u8 node_id [ETH_ALEN];
178 // state we keep for each device we handle
181 struct usb_device *udev;
182 struct driver_info *driver_info;
183 wait_queue_head_t *wait;
185 // i/o info: pipes etc
188 struct timer_list delay;
190 // protocol/interface state
191 struct net_device *net;
192 struct net_device_stats stats;
194 unsigned long data [5];
196 struct mii_if_info mii;
198 // various kinds of pending driver work
199 struct sk_buff_head rxq;
200 struct sk_buff_head txq;
201 struct sk_buff_head done;
202 struct tasklet_struct bh;
204 struct work_struct kevent;
206 # define EVENT_TX_HALT 0
207 # define EVENT_RX_HALT 1
208 # define EVENT_RX_MEMORY 2
211 // device-specific info used by the driver
216 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
217 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
218 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
219 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
220 #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
222 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
223 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
225 /* init device ... can sleep, or cause probe() failure */
226 int (*bind)(struct usbnet *, struct usb_interface *);
228 /* cleanup device ... can sleep, but can't fail */
229 void (*unbind)(struct usbnet *, struct usb_interface *);
231 /* reset device ... can sleep */
232 int (*reset)(struct usbnet *);
234 /* see if peer is connected ... can sleep */
235 int (*check_connect)(struct usbnet *);
237 /* fixup rx packet (strip framing) */
238 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
240 /* fixup tx packet (add framing) */
241 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
242 struct sk_buff *skb, int flags);
244 // FIXME -- also an interrupt mechanism
245 // useful for at least PL2301/2302 and GL620USB-A
246 // and CDC use them to report 'is it connected' changes
248 /* for new devices, use the descriptor-reading code instead */
249 int in; /* rx endpoint */
250 int out; /* tx endpoint */
252 unsigned long data; /* Misc driver specific data */
255 // we record the state for each of our queued skbs
259 rx_start, rx_done, rx_cleanup
262 struct skb_data { // skb->cb is one of these
265 enum skb_state state;
269 static const char driver_name [] = "usbnet";
271 /* use ethtool to change the level for any given device */
272 static int msg_level = 1;
273 module_param (msg_level, int, 0);
274 MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
277 #define RUN_CONTEXT (in_irq () ? "in_irq" \
278 : (in_interrupt () ? "in_interrupt" : "can sleep"))
281 #define devdbg(usbnet, fmt, arg...) \
282 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
284 #define devdbg(usbnet, fmt, arg...) do {} while(0)
287 #define deverr(usbnet, fmt, arg...) \
288 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
289 #define devwarn(usbnet, fmt, arg...) \
290 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
292 #define devinfo(usbnet, fmt, arg...) \
293 do { if ((usbnet)->msg_level >= 1) \
294 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
297 /*-------------------------------------------------------------------------*/
299 static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
300 static u32 usbnet_get_link (struct net_device *);
301 static u32 usbnet_get_msglevel (struct net_device *);
302 static void usbnet_set_msglevel (struct net_device *, u32);
304 /* mostly for PDA style devices, which are always connected if present */
305 static int always_connected (struct usbnet *dev)
310 /* handles CDC Ethernet and many other network "bulk data" interfaces */
312 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
315 struct usb_host_interface *alt;
316 struct usb_host_endpoint *in, *out;
318 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
322 alt = intf->altsetting + tmp;
324 /* take the first altsetting with in-bulk + out-bulk;
325 * ignore other endpoints and altsetttings.
327 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
328 struct usb_host_endpoint *e;
330 e = alt->endpoint + ep;
331 if (e->desc.bmAttributes != USB_ENDPOINT_XFER_BULK)
333 if (e->desc.bEndpointAddress & USB_DIR_IN) {
347 if (alt->desc.bAlternateSetting != 0
348 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
349 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
350 alt->desc.bAlternateSetting);
355 dev->in = usb_rcvbulkpipe (dev->udev,
356 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
357 dev->out = usb_sndbulkpipe (dev->udev,
358 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
362 static void skb_return (struct usbnet *dev, struct sk_buff *skb)
367 skb->protocol = eth_type_trans (skb, dev->net);
368 dev->stats.rx_packets++;
369 dev->stats.rx_bytes += skb->len;
372 devdbg (dev, "< rx, len %d, type 0x%x",
373 skb->len + sizeof (struct ethhdr), skb->protocol);
375 memset (skb->cb, 0, sizeof (struct skb_data));
376 status = netif_rx (skb);
377 if (status != NET_RX_SUCCESS)
378 devdbg (dev, "netif_rx status %d", status);
382 #ifdef CONFIG_USB_ALI_M5632
383 #define HAVE_HARDWARE
385 /*-------------------------------------------------------------------------
387 * ALi M5632 driver ... does high speed
389 *-------------------------------------------------------------------------*/
391 static const struct driver_info ali_m5632_info = {
392 .description = "ALi M5632",
399 #ifdef CONFIG_USB_AN2720
400 #define HAVE_HARDWARE
402 /*-------------------------------------------------------------------------
404 * AnchorChips 2720 driver ... http://www.cypress.com
406 * This doesn't seem to have a way to detect whether the peer is
407 * connected, or need any reset handshaking. It's got pretty big
408 * internal buffers (handles most of a frame's worth of data).
409 * Chip data sheets don't describe any vendor control messages.
411 *-------------------------------------------------------------------------*/
413 static const struct driver_info an2720_info = {
414 .description = "AnchorChips/Cypress 2720",
415 // no reset available!
416 // no check_connect available!
418 .in = 2, .out = 2, // direction distinguishes these
421 #endif /* CONFIG_USB_AN2720 */
424 #ifdef CONFIG_USB_AX8817X
425 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
427 #define HAVE_HARDWARE
430 #include <linux/crc32.h>
432 #define AX_CMD_SET_SW_MII 0x06
433 #define AX_CMD_READ_MII_REG 0x07
434 #define AX_CMD_WRITE_MII_REG 0x08
435 #define AX_CMD_SET_HW_MII 0x0a
436 #define AX_CMD_READ_EEPROM 0x0b
437 #define AX_CMD_WRITE_EEPROM 0x0c
438 #define AX_CMD_WRITE_RX_CTL 0x10
439 #define AX_CMD_READ_IPG012 0x11
440 #define AX_CMD_WRITE_IPG0 0x12
441 #define AX_CMD_WRITE_IPG1 0x13
442 #define AX_CMD_WRITE_IPG2 0x14
443 #define AX_CMD_WRITE_MULTI_FILTER 0x16
444 #define AX_CMD_READ_NODE_ID 0x17
445 #define AX_CMD_READ_PHY_ID 0x19
446 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
447 #define AX_CMD_READ_MONITOR_MODE 0x1c
448 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
449 #define AX_CMD_WRITE_GPIOS 0x1f
451 #define AX_MONITOR_MODE 0x01
452 #define AX_MONITOR_LINK 0x02
453 #define AX_MONITOR_MAGIC 0x04
454 #define AX_MONITOR_HSFS 0x10
456 #define AX_MCAST_FILTER_SIZE 8
457 #define AX_MAX_MCAST 64
459 #define AX_INTERRUPT_BUFSIZE 8
461 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
462 struct ax8817x_data {
463 u8 multi_filter[AX_MCAST_FILTER_SIZE];
468 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
469 u16 size, void *data)
471 return usb_control_msg(
473 usb_rcvctrlpipe(dev->udev, 0),
475 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
480 CONTROL_TIMEOUT_JIFFIES);
483 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
484 u16 size, void *data)
486 return usb_control_msg(
488 usb_sndctrlpipe(dev->udev, 0),
490 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
495 CONTROL_TIMEOUT_JIFFIES);
498 static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
500 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
503 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
510 static void ax8817x_interrupt_complete(struct urb *urb, struct pt_regs *regs)
512 struct usbnet *dev = (struct usbnet *)urb->context;
513 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
516 if (urb->status < 0) {
517 printk(KERN_DEBUG "ax8817x_interrupt_complete() failed with %d",
520 if (data->int_buf[5] == 0x90) {
521 link = data->int_buf[2] & 0x01;
522 if (netif_carrier_ok(dev->net) != link) {
524 netif_carrier_on(dev->net);
526 netif_carrier_off(dev->net);
527 devdbg(dev, "ax8817x - Link Status is: %d", link);
530 usb_submit_urb(data->int_urb, GFP_ATOMIC);
534 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
535 u16 size, void *data)
537 struct usb_ctrlrequest *req;
541 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
542 devdbg(dev, "Error allocating URB in write_cmd_async!");
546 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
547 deverr(dev, "Failed to allocate memory for control request");
552 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
554 req->wValue = cpu_to_le16(value);
555 req->wIndex = cpu_to_le16(index);
556 req->wLength = cpu_to_le16(size);
558 usb_fill_control_urb(urb, dev->udev,
559 usb_sndctrlpipe(dev->udev, 0),
560 (void *)req, data, size,
561 ax8817x_async_cmd_callback, req);
563 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
564 deverr(dev, "Error submitting the control message: status=%d", status);
570 static void ax8817x_set_multicast(struct net_device *net)
572 struct usbnet *dev = netdev_priv(net);
573 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
576 if (net->flags & IFF_PROMISC) {
578 } else if (net->flags & IFF_ALLMULTI
579 || net->mc_count > AX_MAX_MCAST) {
581 } else if (net->mc_count == 0) {
582 /* just broadcast and directed */
584 /* We use the 20 byte dev->data
585 * for our 8 byte filter buffer
586 * to avoid allocating memory that
587 * is tricky to free later */
588 struct dev_mc_list *mc_list = net->mc_list;
592 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
594 /* Build the multicast hash filter. */
595 for (i = 0; i < net->mc_count; i++) {
598 mc_list->dmi_addr) >> 26;
599 data->multi_filter[crc_bits >> 3] |=
601 mc_list = mc_list->next;
604 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
605 AX_MCAST_FILTER_SIZE, data->multi_filter);
610 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
613 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
615 struct usbnet *dev = netdev_priv(netdev);
619 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
620 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
621 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
626 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
628 struct usbnet *dev = netdev_priv(netdev);
632 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
633 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
634 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
637 static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
639 struct usbnet *dev = netdev_priv(net);
642 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
643 wolinfo->supported = 0;
644 wolinfo->wolopts = 0;
647 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
648 wolinfo->wolopts = 0;
649 if (opt & AX_MONITOR_MODE) {
650 if (opt & AX_MONITOR_LINK)
651 wolinfo->wolopts |= WAKE_PHY;
652 if (opt & AX_MONITOR_MAGIC)
653 wolinfo->wolopts |= WAKE_MAGIC;
657 static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
659 struct usbnet *dev = netdev_priv(net);
663 if (wolinfo->wolopts & WAKE_PHY)
664 opt |= AX_MONITOR_LINK;
665 if (wolinfo->wolopts & WAKE_MAGIC)
666 opt |= AX_MONITOR_MAGIC;
668 opt |= AX_MONITOR_MODE;
670 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
671 opt, 0, 0, &buf) < 0)
677 static int ax8817x_get_eeprom(struct net_device *net,
678 struct ethtool_eeprom *eeprom, u8 *data)
680 struct usbnet *dev = netdev_priv(net);
681 u16 *ebuf = (u16 *)data;
684 /* Crude hack to ensure that we don't overwrite memory
685 * if an odd length is supplied
690 /* ax8817x returns 2 bytes from eeprom on read */
691 for (i=0; i < eeprom->len / 2; i++) {
692 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
693 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
699 static void ax8817x_get_drvinfo (struct net_device *net,
700 struct ethtool_drvinfo *info)
702 /* Inherit standard device info */
703 usbnet_get_drvinfo(net, info);
704 info->eedump_len = 0x3e;
707 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
709 struct usbnet *dev = netdev_priv(net);
711 return mii_ethtool_gset(&dev->mii,cmd);
714 static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
716 struct usbnet *dev = netdev_priv(net);
718 return mii_ethtool_sset(&dev->mii,cmd);
721 /* We need to override some ethtool_ops so we require our
722 own structure so we don't interfere with other usbnet
723 devices that may be connected at the same time. */
724 static struct ethtool_ops ax8817x_ethtool_ops = {
725 .get_drvinfo = ax8817x_get_drvinfo,
726 .get_link = ethtool_op_get_link,
727 .get_msglevel = usbnet_get_msglevel,
728 .set_msglevel = usbnet_set_msglevel,
729 .get_wol = ax8817x_get_wol,
730 .set_wol = ax8817x_set_wol,
731 .get_eeprom = ax8817x_get_eeprom,
732 .get_settings = ax8817x_get_settings,
733 .set_settings = ax8817x_set_settings,
736 static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
741 unsigned long gpio_bits = dev->driver_info->data;
742 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
744 dev->in = usb_rcvbulkpipe(dev->udev, 3);
745 dev->out = usb_sndbulkpipe(dev->udev, 2);
748 if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == NULL) {
749 dbg ("%s: cannot allocate interrupt URB",
754 if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
755 dbg ("%s: cannot allocate memory for interrupt buffer",
757 usb_free_urb(data->int_urb);
760 memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
762 usb_fill_int_urb (data->int_urb, dev->udev,
763 usb_rcvintpipe (dev->udev, 1),
764 data->int_buf, AX_INTERRUPT_BUFSIZE,
765 ax8817x_interrupt_complete, dev,
766 dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
768 /* Toggle the GPIOs in a manufacturer/model specific way */
769 for (i = 2; i >= 0; i--) {
770 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
771 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
777 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
778 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
782 /* Get the MAC address */
783 memset(buf, 0, ETH_ALEN);
784 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
785 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
788 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
791 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
792 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
794 } else if (ret < 2) {
795 /* this should always return 2 bytes */
796 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
800 /* Initialize MII structure */
801 dev->mii.dev = dev->net;
802 dev->mii.mdio_read = ax8817x_mdio_read;
803 dev->mii.mdio_write = ax8817x_mdio_write;
804 dev->mii.phy_id_mask = 0x3f;
805 dev->mii.reg_num_mask = 0x1f;
806 dev->mii.phy_id = buf[1];
808 dev->net->set_multicast_list = ax8817x_set_multicast;
809 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
811 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
812 cpu_to_le16(BMCR_RESET));
813 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
814 cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400));
815 mii_nway_restart(&dev->mii);
817 if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
818 dbg("Failed to submit interrupt URB: %02x", ret);
819 usb_free_urb(data->int_urb);
826 static void ax8817x_unbind(struct usbnet *dev, struct usb_interface *intf)
828 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
830 usb_kill_urb(data->int_urb);
831 usb_free_urb(data->int_urb);
832 kfree(data->int_buf);
835 static const struct driver_info ax8817x_info = {
836 .description = "ASIX AX8817x USB 2.0 Ethernet",
837 .bind = ax8817x_bind,
838 .unbind = ax8817x_unbind,
843 static const struct driver_info dlink_dub_e100_info = {
844 .description = "DLink DUB-E100 USB Ethernet",
845 .bind = ax8817x_bind,
846 .unbind = ax8817x_unbind,
851 static const struct driver_info netgear_fa120_info = {
852 .description = "Netgear FA-120 USB Ethernet",
853 .bind = ax8817x_bind,
854 .unbind = ax8817x_unbind,
859 static const struct driver_info hawking_uf200_info = {
860 .description = "Hawking UF200 USB Ethernet",
861 .bind = ax8817x_bind,
862 .unbind = ax8817x_unbind,
867 #endif /* CONFIG_USB_AX8817X */
871 #ifdef CONFIG_USB_BELKIN
872 #define HAVE_HARDWARE
874 /*-------------------------------------------------------------------------
876 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
878 * ... also two eTEK designs, including one sold as "Advance USBNET"
880 *-------------------------------------------------------------------------*/
882 static const struct driver_info belkin_info = {
883 .description = "Belkin, eTEK, or compatible",
886 #endif /* CONFIG_USB_BELKIN */
890 /*-------------------------------------------------------------------------
892 * Communications Device Class declarations.
893 * Used by CDC Ethernet, and some CDC variants
895 *-------------------------------------------------------------------------*/
897 #ifdef CONFIG_USB_CDCETHER
898 #define NEED_GENERIC_CDC
901 #ifdef CONFIG_USB_ZAURUS
902 /* Ethernet variant uses funky framing, broken ethernet addressing */
903 #define NEED_GENERIC_CDC
906 #ifdef CONFIG_USB_RNDIS
907 /* ACM variant uses even funkier framing, complex control RPC scheme */
908 #define NEED_GENERIC_CDC
912 #ifdef NEED_GENERIC_CDC
914 /* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
918 u8 bDescriptorSubType;
921 } __attribute__ ((packed));
923 /* "Union Functional Descriptor" from CDC spec 5.2.3.X */
927 u8 bDescriptorSubType;
929 u8 bMasterInterface0;
931 /* ... and there could be other slave interfaces */
932 } __attribute__ ((packed));
934 /* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
938 u8 bDescriptorSubType;
941 u32 bmEthernetStatistics;
942 __le16 wMaxSegmentSize;
943 __le16 wNumberMCFilters;
944 u8 bNumberPowerFilters;
945 } __attribute__ ((packed));
948 struct header_desc *header;
949 struct union_desc *u;
950 struct ether_desc *ether;
951 struct usb_interface *control;
952 struct usb_interface *data;
955 static struct usb_driver usbnet_driver;
958 * probes control interface, claims data interface, collects the bulk
959 * endpoints, activates data interface (if needed), maybe sets MTU.
960 * all pure cdc, except for certain firmware workarounds.
962 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
964 u8 *buf = intf->cur_altsetting->extra;
965 int len = intf->cur_altsetting->extralen;
966 struct usb_interface_descriptor *d;
967 struct cdc_state *info = (void *) &dev->data;
971 if (sizeof dev->data < sizeof *info)
974 /* expect strict spec conformance for the descriptors, but
975 * cope with firmware which stores them in the wrong place
977 if (len == 0 && dev->udev->actconfig->extralen) {
978 /* Motorola SB4100 (and others: Brad Hards says it's
979 * from a Broadcom design) put CDC descriptors here
981 buf = dev->udev->actconfig->extra;
982 len = dev->udev->actconfig->extralen;
985 "CDC descriptors on config\n");
988 /* this assumes that if there's a non-RNDIS vendor variant
989 * of cdc-acm, it'll fail RNDIS requests cleanly.
991 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
993 memset (info, 0, sizeof *info);
994 info->control = intf;
996 if (buf [1] != USB_DT_CS_INTERFACE)
999 /* use bDescriptorSubType to identify the CDC descriptors.
1000 * We expect devices with CDC header and union descriptors.
1001 * For CDC Ethernet we need the ethernet descriptor.
1002 * For RNDIS, ignore two (pointless) CDC modem descriptors
1003 * in favor of a complicated OID-based RPC scheme doing what
1004 * CDC Ethernet achieves with a simple descriptor.
1007 case 0x00: /* Header, mostly useless */
1009 dev_dbg (&intf->dev, "extra CDC header\n");
1012 info->header = (void *) buf;
1013 if (info->header->bLength != sizeof *info->header) {
1014 dev_dbg (&intf->dev, "CDC header len %u\n",
1015 info->header->bLength);
1019 case 0x06: /* Union (groups interfaces) */
1021 dev_dbg (&intf->dev, "extra CDC union\n");
1024 info->u = (void *) buf;
1025 if (info->u->bLength != sizeof *info->u) {
1026 dev_dbg (&intf->dev, "CDC union len %u\n",
1031 /* we need a master/control interface (what we're
1032 * probed with) and a slave/data interface; union
1033 * descriptors sort this all out.
1035 info->control = usb_ifnum_to_if(dev->udev,
1036 info->u->bMasterInterface0);
1037 info->data = usb_ifnum_to_if(dev->udev,
1038 info->u->bSlaveInterface0);
1039 if (!info->control || !info->data) {
1040 dev_dbg (&intf->dev,
1041 "master #%u/%p slave #%u/%p\n",
1042 info->u->bMasterInterface0,
1044 info->u->bSlaveInterface0,
1048 if (info->control != intf) {
1049 dev_dbg (&intf->dev, "bogus CDC Union\n");
1050 /* Ambit USB Cable Modem (and maybe others)
1051 * interchanges master and slave interface.
1053 if (info->data == intf) {
1054 info->data = info->control;
1055 info->control = intf;
1060 /* a data interface altsetting does the real i/o */
1061 d = &info->data->cur_altsetting->desc;
1062 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1063 dev_dbg (&intf->dev, "slave class %u\n",
1064 d->bInterfaceClass);
1068 case 0x0F: /* Ethernet Networking */
1070 dev_dbg (&intf->dev, "extra CDC ether\n");
1073 info->ether = (void *) buf;
1074 if (info->ether->bLength != sizeof *info->ether) {
1075 dev_dbg (&intf->dev, "CDC ether len %u\n",
1079 dev->net->mtu = le16_to_cpup (
1080 &info->ether->wMaxSegmentSize)
1082 /* because of Zaurus, we may be ignoring the host
1083 * side link address we were given.
1088 len -= buf [0]; /* bLength */
1092 if (!info->header || !info->u || (!rndis && !info->ether)) {
1093 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1094 info->header ? "" : "header ",
1095 info->u ? "" : "union ",
1096 info->ether ? "" : "ether ");
1100 /* claim data interface and set it up ... with side effects.
1101 * network traffic can't flow until an altsetting is enabled.
1103 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1106 status = get_endpoints (dev, info->data);
1108 /* ensure immediate exit from usbnet_disconnect */
1109 usb_set_intfdata(info->data, NULL);
1110 usb_driver_release_interface (&usbnet_driver, info->data);
1116 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1120 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1122 struct cdc_state *info = (void *) &dev->data;
1124 /* disconnect master --> disconnect slave */
1125 if (intf == info->control && info->data) {
1126 /* ensure immediate exit from usbnet_disconnect */
1127 usb_set_intfdata(info->data, NULL);
1128 usb_driver_release_interface (&usbnet_driver, info->data);
1132 /* and vice versa (just in case) */
1133 else if (intf == info->data && info->control) {
1134 /* ensure immediate exit from usbnet_disconnect */
1135 usb_set_intfdata(info->control, NULL);
1136 usb_driver_release_interface (&usbnet_driver, info->control);
1137 info->control = NULL;
1141 #endif /* NEED_GENERIC_CDC */
1144 #ifdef CONFIG_USB_CDCETHER
1145 #define HAVE_HARDWARE
1147 /*-------------------------------------------------------------------------
1149 * Communications Device Class, Ethernet Control model
1151 * Takes two interfaces. The DATA interface is inactive till an altsetting
1152 * is selected. Configuration data includes class descriptors.
1154 * This should interop with whatever the 2.4 "CDCEther.c" driver
1155 * (by Brad Hards) talked with.
1157 *-------------------------------------------------------------------------*/
1159 #include <linux/ctype.h>
1161 static u8 nibble (unsigned char c)
1163 if (likely (isdigit (c)))
1166 if (likely (isxdigit (c)))
1167 return 10 + c - 'A';
1172 get_ethernet_addr (struct usbnet *dev, struct ether_desc *e)
1175 unsigned char buf [13];
1177 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1179 dev_dbg (&dev->udev->dev,
1180 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1185 for (i = tmp = 0; i < 6; i++, tmp += 2)
1186 dev->net->dev_addr [i] =
1187 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1191 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1194 struct cdc_state *info = (void *) &dev->data;
1196 status = generic_cdc_bind (dev, intf);
1200 status = get_ethernet_addr (dev, info->ether);
1202 usb_set_intfdata(info->data, NULL);
1203 usb_driver_release_interface (&usbnet_driver, info->data);
1207 /* FIXME cdc-ether has some multicast code too, though it complains
1208 * in routine cases. info->ether describes the multicast support.
1213 static const struct driver_info cdc_info = {
1214 .description = "CDC Ethernet Device",
1215 .flags = FLAG_ETHER,
1216 // .check_connect = cdc_check_connect,
1218 .unbind = cdc_unbind,
1221 #endif /* CONFIG_USB_CDCETHER */
1225 #ifdef CONFIG_USB_EPSON2888
1226 #define HAVE_HARDWARE
1228 /*-------------------------------------------------------------------------
1232 * This is the same idea as Linux PDAs (below) except the firmware in the
1233 * device might not be Tux-powered. Epson provides reference firmware that
1234 * implements this interface. Product developers can reuse or modify that
1235 * code, such as by using their own product and vendor codes.
1237 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1239 *-------------------------------------------------------------------------*/
1241 static const struct driver_info epson2888_info = {
1242 .description = "Epson USB Device",
1243 .check_connect = always_connected,
1248 #endif /* CONFIG_USB_EPSON2888 */
1251 #ifdef CONFIG_USB_GENESYS
1252 #define HAVE_HARDWARE
1254 /*-------------------------------------------------------------------------
1256 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1258 * ... should partially interop with the Win32 driver for this hardware
1259 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1261 * Some info from GeneSys:
1262 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1263 * (Some cables, like the BAFO-100c, use the half duplex version.)
1264 * - For the full duplex model, the low bit of the version code says
1265 * which side is which ("left/right").
1266 * - For the half duplex type, a control/interrupt handshake settles
1267 * the transfer direction. (That's disabled here, partially coded.)
1268 * A control URB would block until other side writes an interrupt.
1270 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1271 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1273 *-------------------------------------------------------------------------*/
1275 // control msg write command
1276 #define GENELINK_CONNECT_WRITE 0xF0
1277 // interrupt pipe index
1278 #define GENELINK_INTERRUPT_PIPE 0x03
1279 // interrupt read buffer size
1280 #define INTERRUPT_BUFSIZE 0x08
1281 // interrupt pipe interval value
1282 #define GENELINK_INTERRUPT_INTERVAL 0x10
1283 // max transmit packet number per transmit
1284 #define GL_MAX_TRANSMIT_PACKETS 32
1285 // max packet length
1286 #define GL_MAX_PACKET_LEN 1514
1287 // max receive buffer size
1288 #define GL_RCV_BUF_SIZE \
1289 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1293 char packet_data [1];
1298 struct gl_packet packets;
1303 // FIXME: this code is incomplete, not debugged; it doesn't
1304 // handle interrupts correctly. interrupts should be generic
1305 // code like all other device I/O, anyway.
1308 struct urb *irq_urb;
1309 char irq_buf [INTERRUPT_BUFSIZE];
1312 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1316 retval = usb_control_msg (dev->udev,
1317 usb_sndctrlpipe (dev->udev, 0),
1319 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1324 CONTROL_TIMEOUT_JIFFIES);
1328 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1330 int status = urb->status;
1339 /* this urb is terminated, clean up */
1340 dbg("%s - urb shutting down with status: %d",
1341 __FUNCTION__, status);
1344 dbg("%s - nonzero urb status received: %d",
1345 __FUNCTION__, urb->status);
1348 status = usb_submit_urb (urb, GFP_ATOMIC);
1350 err ("%s - usb_submit_urb failed with result %d",
1351 __FUNCTION__, status);
1354 static int gl_interrupt_read (struct usbnet *dev)
1356 struct gl_priv *priv = dev->priv_data;
1359 // issue usb interrupt read
1360 if (priv && priv->irq_urb) {
1362 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1363 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1365 dbg ("gl_interrupt_read: submit success...");
1371 // check whether another side is connected
1372 static int genelink_check_connect (struct usbnet *dev)
1376 dbg ("genelink_check_connect...");
1378 // detect whether another side is connected
1379 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1380 dbg ("%s: genelink_check_connect write fail - %X",
1381 dev->net->name, retval);
1385 // usb interrupt read to ack another side
1386 if ((retval = gl_interrupt_read (dev)) != 0) {
1387 dbg ("%s: genelink_check_connect read fail - %X",
1388 dev->net->name, retval);
1392 dbg ("%s: genelink_check_connect read success", dev->net->name);
1396 // allocate and initialize the private data for genelink
1397 static int genelink_init (struct usbnet *dev)
1399 struct gl_priv *priv;
1401 // allocate the private data structure
1402 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1403 dbg ("%s: cannot allocate private data per device",
1409 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1410 dbg ("%s: cannot allocate private irq urb per device",
1417 usb_fill_int_urb (priv->irq_urb, dev->udev,
1418 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1419 priv->irq_buf, INTERRUPT_BUFSIZE,
1420 gl_interrupt_complete, 0,
1421 GENELINK_INTERRUPT_INTERVAL);
1423 // set private data pointer
1424 dev->priv_data = priv;
1429 // release the private data
1430 static int genelink_free (struct usbnet *dev)
1432 struct gl_priv *priv = dev->priv_data;
1437 // FIXME: can't cancel here; it's synchronous, and
1438 // should have happened earlier in any case (interrupt
1439 // handling needs to be generic)
1441 // cancel irq urb first
1442 usb_kill_urb (priv->irq_urb);
1445 usb_free_urb (priv->irq_urb);
1447 // free the private data structure
1455 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1457 struct gl_header *header;
1458 struct gl_packet *packet;
1459 struct sk_buff *gl_skb;
1462 header = (struct gl_header *) skb->data;
1464 // get the packet count of the received skb
1465 le32_to_cpus (&header->packet_count);
1466 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1467 || (header->packet_count < 0)) {
1468 dbg ("genelink: invalid received packet count %d",
1469 header->packet_count);
1473 // set the current packet pointer to the first packet
1474 packet = &header->packets;
1476 // decrement the length for the packet count size 4 bytes
1479 while (header->packet_count > 1) {
1480 // get the packet length
1481 size = packet->packet_length;
1483 // this may be a broken packet
1484 if (size > GL_MAX_PACKET_LEN) {
1485 dbg ("genelink: invalid rx length %d", size);
1489 // allocate the skb for the individual packet
1490 gl_skb = alloc_skb (size, GFP_ATOMIC);
1493 // copy the packet data to the new skb
1494 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1495 skb_return (dev, skb);
1498 // advance to the next packet
1499 packet = (struct gl_packet *)
1500 &packet->packet_data [size];
1501 header->packet_count--;
1503 // shift the data pointer to the next gl_packet
1504 skb_pull (skb, size + 4);
1507 // skip the packet length field 4 bytes
1510 if (skb->len > GL_MAX_PACKET_LEN) {
1511 dbg ("genelink: invalid rx length %d", skb->len);
1517 static struct sk_buff *
1518 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1521 int length = skb->len;
1522 int headroom = skb_headroom (skb);
1523 int tailroom = skb_tailroom (skb);
1527 // FIXME: magic numbers, bleech
1528 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1530 if ((!skb_cloned (skb))
1531 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1532 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1533 skb->data = memmove (skb->head + (4 + 4*1),
1534 skb->data, skb->len);
1535 skb->tail = skb->data + skb->len;
1538 struct sk_buff *skb2;
1539 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1540 dev_kfree_skb_any (skb);
1546 // attach the packet count to the header
1547 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1548 packet_len = packet_count + 1;
1550 // FIXME little endian?
1552 *packet_len = length;
1555 if ((skb->len % dev->maxpacket) == 0)
1561 static const struct driver_info genelink_info = {
1562 .description = "Genesys GeneLink",
1563 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1564 .rx_fixup = genelink_rx_fixup,
1565 .tx_fixup = genelink_tx_fixup,
1570 .check_connect =genelink_check_connect,
1574 #endif /* CONFIG_USB_GENESYS */
1578 #ifdef CONFIG_USB_NET1080
1579 #define HAVE_HARDWARE
1581 /*-------------------------------------------------------------------------
1583 * Netchip 1080 driver ... http://www.netchip.com
1584 * Used in LapLink cables
1586 *-------------------------------------------------------------------------*/
1588 #define dev_packet_id data[0]
1589 #define frame_errors data[1]
1592 * NetChip framing of ethernet packets, supporting additional error
1593 * checks for links that may drop bulk packets from inside messages.
1594 * Odd USB length == always short read for last usb packet.
1596 * - Ethernet header (14 bytes)
1598 * - (optional padding byte, if needed so length becomes odd)
1601 * This framing is to be avoided for non-NetChip devices.
1604 struct nc_header { // packed:
1605 u16 hdr_len; // sizeof nc_header (LE, all)
1606 u16 packet_len; // payload size (including ethhdr)
1607 u16 packet_id; // detects dropped packets
1608 #define MIN_HEADER 6
1610 // all else is optional, and must start with:
1611 // u16 vendorId; // from usb-if
1613 } __attribute__((__packed__));
1615 #define PAD_BYTE ((unsigned char)0xAC)
1619 } __attribute__((__packed__));
1621 // packets may use FLAG_FRAMING_NC and optional pad
1622 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1623 + sizeof (struct ethhdr) \
1626 + sizeof (struct nc_trailer))
1628 #define MIN_FRAMED FRAMED_SIZE(0)
1632 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1633 * before the hardware drops it. If that's done, the driver will need to
1634 * frame network packets to guard against the dropped USB packets. The win32
1635 * driver sets this for both sides of the link.
1637 #define NC_READ_TTL_MS ((u8)255) // ms
1640 * We ignore most registers and EEPROM contents.
1642 #define REG_USBCTL ((u8)0x04)
1643 #define REG_TTL ((u8)0x10)
1644 #define REG_STATUS ((u8)0x11)
1647 * Vendor specific requests to read/write data
1649 #define REQUEST_REGISTER ((u8)0x10)
1650 #define REQUEST_EEPROM ((u8)0x11)
1653 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1655 int status = usb_control_msg (dev->udev,
1656 usb_rcvctrlpipe (dev->udev, 0),
1658 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1660 retval_ptr, sizeof *retval_ptr,
1661 CONTROL_TIMEOUT_JIFFIES);
1665 le16_to_cpus (retval_ptr);
1670 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1672 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1675 // no retval ... can become async, usable in_interrupt()
1677 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1679 usb_control_msg (dev->udev,
1680 usb_sndctrlpipe (dev->udev, 0),
1682 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1684 NULL, 0, // data is in setup packet
1685 CONTROL_TIMEOUT_JIFFIES);
1689 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1691 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1696 static void nc_dump_registers (struct usbnet *dev)
1699 u16 *vp = kmalloc (sizeof (u16));
1706 dbg ("%s registers:", dev->net->name);
1707 for (reg = 0; reg < 0x20; reg++) {
1710 // reading some registers is trouble
1711 if (reg >= 0x08 && reg <= 0xf)
1713 if (reg >= 0x12 && reg <= 0x1e)
1716 retval = nc_register_read (dev, reg, vp);
1718 dbg ("%s reg [0x%x] ==> error %d",
1719 dev->net->name, reg, retval);
1721 dbg ("%s reg [0x%x] = 0x%x",
1722 dev->net->name, reg, *vp);
1729 /*-------------------------------------------------------------------------*/
1735 #define USBCTL_WRITABLE_MASK 0x1f0f
1736 // bits 15-13 reserved, r/o
1737 #define USBCTL_ENABLE_LANG (1 << 12)
1738 #define USBCTL_ENABLE_MFGR (1 << 11)
1739 #define USBCTL_ENABLE_PROD (1 << 10)
1740 #define USBCTL_ENABLE_SERIAL (1 << 9)
1741 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1742 // bits 7-4 reserved, r/o
1743 #define USBCTL_FLUSH_OTHER (1 << 3)
1744 #define USBCTL_FLUSH_THIS (1 << 2)
1745 #define USBCTL_DISCONN_OTHER (1 << 1)
1746 #define USBCTL_DISCONN_THIS (1 << 0)
1748 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1751 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1753 " other%s%s; r/o 0x%x",
1754 dev->udev->bus->bus_name, dev->udev->devpath,
1756 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1757 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1758 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1759 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1760 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1762 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1763 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1764 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1765 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1766 usbctl & ~USBCTL_WRITABLE_MASK
1771 /*-------------------------------------------------------------------------*/
1777 #define STATUS_PORT_A (1 << 15)
1779 #define STATUS_CONN_OTHER (1 << 14)
1780 #define STATUS_SUSPEND_OTHER (1 << 13)
1781 #define STATUS_MAILBOX_OTHER (1 << 12)
1782 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1784 #define STATUS_CONN_THIS (1 << 6)
1785 #define STATUS_SUSPEND_THIS (1 << 5)
1786 #define STATUS_MAILBOX_THIS (1 << 4)
1787 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1789 #define STATUS_UNSPEC_MASK 0x0c8c
1790 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1793 static inline void nc_dump_status (struct usbnet *dev, u16 status)
1796 devdbg (dev, "net1080 %s-%s status 0x%x:"
1797 " this (%c) PKT=%d%s%s%s;"
1798 " other PKT=%d%s%s%s; unspec 0x%x",
1799 dev->udev->bus->bus_name, dev->udev->devpath,
1802 // XXX the packet counts don't seem right
1803 // (1 at reset, not 0); maybe UNSPEC too
1805 (status & STATUS_PORT_A) ? 'A' : 'B',
1806 STATUS_PACKETS_THIS (status),
1807 (status & STATUS_CONN_THIS) ? " CON" : "",
1808 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1809 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1811 STATUS_PACKETS_OTHER (status),
1812 (status & STATUS_CONN_OTHER) ? " CON" : "",
1813 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1814 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1816 status & STATUS_UNSPEC_MASK
1821 /*-------------------------------------------------------------------------*/
1827 #define TTL_THIS(ttl) (0x00ff & ttl)
1828 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1829 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1831 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1834 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1835 dev->udev->bus->bus_name, dev->udev->devpath,
1844 /*-------------------------------------------------------------------------*/
1846 static int net1080_reset (struct usbnet *dev)
1848 u16 usbctl, status, ttl;
1849 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1855 // nc_dump_registers (dev);
1857 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1858 dbg ("can't read %s-%s status: %d",
1859 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1863 // nc_dump_status (dev, status);
1865 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1866 dbg ("can't read USBCTL, %d", retval);
1870 // nc_dump_usbctl (dev, usbctl);
1872 nc_register_write (dev, REG_USBCTL,
1873 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1875 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1876 dbg ("can't read TTL, %d", retval);
1880 // nc_dump_ttl (dev, ttl);
1882 nc_register_write (dev, REG_TTL,
1883 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1884 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
1886 if (dev->msg_level >= 2)
1887 devinfo (dev, "port %c, peer %sconnected",
1888 (status & STATUS_PORT_A) ? 'A' : 'B',
1889 (status & STATUS_CONN_OTHER) ? "" : "dis"
1898 static int net1080_check_connect (struct usbnet *dev)
1902 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1906 retval = nc_register_read (dev, REG_STATUS, vp);
1910 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
1913 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1918 static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
1920 kfree (urb->context);
1924 static void nc_ensure_sync (struct usbnet *dev)
1926 dev->frame_errors++;
1927 if (dev->frame_errors > 5) {
1929 struct usb_ctrlrequest *req;
1933 urb = usb_alloc_urb (0, SLAB_ATOMIC);
1937 req = kmalloc (sizeof *req, GFP_ATOMIC);
1943 req->bRequestType = USB_DIR_OUT
1946 req->bRequest = REQUEST_REGISTER;
1947 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
1948 | USBCTL_FLUSH_OTHER);
1949 req->wIndex = cpu_to_le16 (REG_USBCTL);
1950 req->wLength = cpu_to_le16 (0);
1952 /* queue an async control request, we don't need
1953 * to do anything when it finishes except clean up.
1955 usb_fill_control_urb (urb, dev->udev,
1956 usb_sndctrlpipe (dev->udev, 0),
1957 (unsigned char *) req,
1959 nc_flush_complete, req);
1960 status = usb_submit_urb (urb, GFP_ATOMIC);
1967 devdbg (dev, "flush net1080; too many framing errors");
1968 dev->frame_errors = 0;
1972 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1974 struct nc_header *header;
1975 struct nc_trailer *trailer;
1977 if (!(skb->len & 0x01)
1978 || MIN_FRAMED > skb->len
1979 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
1980 dev->stats.rx_frame_errors++;
1981 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1982 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
1984 nc_ensure_sync (dev);
1988 header = (struct nc_header *) skb->data;
1989 le16_to_cpus (&header->hdr_len);
1990 le16_to_cpus (&header->packet_len);
1991 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1992 dev->stats.rx_frame_errors++;
1993 dbg ("packet too big, %d", header->packet_len);
1994 nc_ensure_sync (dev);
1996 } else if (header->hdr_len < MIN_HEADER) {
1997 dev->stats.rx_frame_errors++;
1998 dbg ("header too short, %d", header->hdr_len);
1999 nc_ensure_sync (dev);
2001 } else if (header->hdr_len > MIN_HEADER) {
2002 // out of band data for us?
2003 dbg ("header OOB, %d bytes",
2004 header->hdr_len - MIN_HEADER);
2005 nc_ensure_sync (dev);
2006 // switch (vendor/product ids) { ... }
2008 skb_pull (skb, header->hdr_len);
2010 trailer = (struct nc_trailer *)
2011 (skb->data + skb->len - sizeof *trailer);
2012 skb_trim (skb, skb->len - sizeof *trailer);
2014 if ((header->packet_len & 0x01) == 0) {
2015 if (skb->data [header->packet_len] != PAD_BYTE) {
2016 dev->stats.rx_frame_errors++;
2020 skb_trim (skb, skb->len - 1);
2022 if (skb->len != header->packet_len) {
2023 dev->stats.rx_frame_errors++;
2024 dbg ("bad packet len %d (expected %d)",
2025 skb->len, header->packet_len);
2026 nc_ensure_sync (dev);
2029 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2030 dev->stats.rx_fifo_errors++;
2031 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2032 header->packet_id, trailer->packet_id);
2036 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2037 header->packet_len, header->packet_id);
2039 dev->frame_errors = 0;
2043 static struct sk_buff *
2044 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2047 struct sk_buff *skb2;
2049 padlen = ((skb->len + sizeof (struct nc_header)
2050 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2051 if (!skb_cloned (skb)) {
2052 int headroom = skb_headroom (skb);
2053 int tailroom = skb_tailroom (skb);
2055 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2056 && sizeof (struct nc_header) <= headroom)
2057 /* There's enough head and tail room */
2060 if ((sizeof (struct nc_header) + padlen
2061 + sizeof (struct nc_trailer)) <
2062 (headroom + tailroom)) {
2063 /* There's enough total room, so just readjust */
2064 skb->data = memmove (skb->head
2065 + sizeof (struct nc_header),
2066 skb->data, skb->len);
2067 skb->tail = skb->data + skb->len;
2072 /* Create a new skb to use with the correct size */
2073 skb2 = skb_copy_expand (skb,
2074 sizeof (struct nc_header),
2075 sizeof (struct nc_trailer) + padlen,
2077 dev_kfree_skb_any (skb);
2081 static const struct driver_info net1080_info = {
2082 .description = "NetChip TurboCONNECT",
2083 .flags = FLAG_FRAMING_NC,
2084 .reset = net1080_reset,
2085 .check_connect =net1080_check_connect,
2086 .rx_fixup = net1080_rx_fixup,
2087 .tx_fixup = net1080_tx_fixup,
2090 #endif /* CONFIG_USB_NET1080 */
2094 #ifdef CONFIG_USB_PL2301
2095 #define HAVE_HARDWARE
2097 /*-------------------------------------------------------------------------
2099 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2101 * The protocol and handshaking used here should be bug-compatible
2102 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2104 *-------------------------------------------------------------------------*/
2107 * Bits 0-4 can be used for software handshaking; they're set from
2108 * one end, cleared from the other, "read" with the interrupt byte.
2110 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2111 /* reserved bit -- rx ready (6) ? */
2112 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2113 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2114 #define PL_RESET_IN (1<<3) /* reset input pipe */
2115 #define PL_TX_C (1<<2) /* transmission complete */
2116 #define PL_TX_REQ (1<<1) /* transmission received */
2117 #define PL_PEER_E (1<<0) /* peer exists */
2120 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2122 return usb_control_msg (dev->udev,
2123 usb_rcvctrlpipe (dev->udev, 0),
2125 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2128 CONTROL_TIMEOUT_JIFFIES);
2132 pl_clear_QuickLink_features (struct usbnet *dev, int val)
2134 return pl_vendor_req (dev, 1, (u8) val, 0);
2138 pl_set_QuickLink_features (struct usbnet *dev, int val)
2140 return pl_vendor_req (dev, 3, (u8) val, 0);
2143 /*-------------------------------------------------------------------------*/
2145 static int pl_reset (struct usbnet *dev)
2147 /* some units seem to need this reset, others reject it utterly.
2148 * FIXME be more like "naplink" or windows drivers.
2150 (void) pl_set_QuickLink_features (dev,
2151 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2155 static const struct driver_info prolific_info = {
2156 .description = "Prolific PL-2301/PL-2302",
2157 .flags = FLAG_NO_SETINT,
2158 /* some PL-2302 versions seem to fail usb_set_interface() */
2162 #endif /* CONFIG_USB_PL2301 */
2165 #ifdef CONFIG_USB_KC2190
2166 #define HAVE_HARDWARE
2167 static const struct driver_info kc2190_info = {
2168 .description = "KC Technology KC-190",
2170 #endif /* CONFIG_USB_KC2190 */
2173 #ifdef CONFIG_USB_ARMLINUX
2174 #define HAVE_HARDWARE
2176 /*-------------------------------------------------------------------------
2178 * Intel's SA-1100 chip integrates basic USB support, and is used
2179 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2180 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2181 * network using minimal USB framing data.
2183 * This describes the driver currently in standard ARM Linux kernels.
2184 * The Zaurus uses a different driver (see later).
2186 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2187 * and different USB endpoint numbering than the SA1100 devices. The
2188 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2189 * so we rely on the endpoint descriptors.
2191 *-------------------------------------------------------------------------*/
2193 static const struct driver_info linuxdev_info = {
2194 .description = "Linux Device",
2195 .check_connect = always_connected,
2198 static const struct driver_info yopy_info = {
2199 .description = "Yopy",
2200 .check_connect = always_connected,
2203 static const struct driver_info blob_info = {
2204 .description = "Boot Loader OBject",
2205 .check_connect = always_connected,
2208 #endif /* CONFIG_USB_ARMLINUX */
2211 #ifdef CONFIG_USB_ZAURUS
2212 #define HAVE_HARDWARE
2214 #include <linux/crc32.h>
2216 /*-------------------------------------------------------------------------
2218 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2219 * (and framing) for its USB slave/gadget controller than the case above.
2221 * For the current version of that driver, the main way that framing is
2222 * nonstandard (also from perspective of the CDC ethernet model!) is a
2223 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2224 * haven't been fully worked around.
2226 * PXA based models use the same framing, and also can't implement
2227 * set_interface properly.
2229 *-------------------------------------------------------------------------*/
2231 static struct sk_buff *
2232 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2235 struct sk_buff *skb2;
2238 if (!skb_cloned (skb)) {
2239 int tailroom = skb_tailroom (skb);
2240 if ((padlen + 4) <= tailroom)
2243 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2244 dev_kfree_skb_any (skb);
2249 fcs = crc32_le (~0, skb->data, skb->len);
2252 *skb_put (skb, 1) = fcs & 0xff;
2253 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2254 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2255 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2260 static const struct driver_info zaurus_sl5x00_info = {
2261 .description = "Sharp Zaurus SL-5x00",
2262 .flags = FLAG_FRAMING_Z,
2263 .check_connect = always_connected,
2264 .bind = generic_cdc_bind,
2265 .unbind = cdc_unbind,
2266 .tx_fixup = zaurus_tx_fixup,
2268 #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2270 static const struct driver_info zaurus_pxa_info = {
2271 .description = "Sharp Zaurus, PXA-2xx based",
2272 .flags = FLAG_FRAMING_Z,
2273 .check_connect = always_connected,
2274 .bind = generic_cdc_bind,
2275 .unbind = cdc_unbind,
2276 .tx_fixup = zaurus_tx_fixup,
2278 #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2280 static const struct driver_info olympus_mxl_info = {
2281 .description = "Olympus R1000",
2282 .flags = FLAG_FRAMING_Z,
2283 .check_connect = always_connected,
2284 .bind = generic_cdc_bind,
2285 .unbind = cdc_unbind,
2286 .tx_fixup = zaurus_tx_fixup,
2288 #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2292 /* blacklist all those devices */
2293 #define ZAURUS_STRONGARM_INFO 0
2294 #define ZAURUS_PXA_INFO 0
2295 #define OLYMPUS_MXL_INFO 0
2300 /*-------------------------------------------------------------------------
2302 * Network Device Driver (peer link to "Host Device", from USB host)
2304 *-------------------------------------------------------------------------*/
2306 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2308 struct usbnet *dev = netdev_priv(net);
2310 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2312 #ifdef CONFIG_USB_NET1080
2313 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2314 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2318 #ifdef CONFIG_USB_GENESYS
2319 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2320 && new_mtu > GL_MAX_PACKET_LEN)
2323 // no second zero-length packet read wanted after mtu-sized packets
2324 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2330 /*-------------------------------------------------------------------------*/
2332 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2334 struct usbnet *dev = netdev_priv(net);
2338 /*-------------------------------------------------------------------------*/
2340 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2341 * completion callbacks. 2.5 should have fixed those bugs...
2344 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2346 struct sk_buff_head *list = skb->list;
2347 unsigned long flags;
2349 spin_lock_irqsave (&list->lock, flags);
2350 __skb_unlink (skb, list);
2351 spin_unlock (&list->lock);
2352 spin_lock (&dev->done.lock);
2353 __skb_queue_tail (&dev->done, skb);
2354 if (dev->done.qlen == 1)
2355 tasklet_schedule (&dev->bh);
2356 spin_unlock_irqrestore (&dev->done.lock, flags);
2359 /* some work can't be done in tasklets, so we use keventd
2361 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2362 * but tasklet_schedule() doesn't. hope the failure is rare.
2364 static void defer_kevent (struct usbnet *dev, int work)
2366 set_bit (work, &dev->flags);
2367 if (!schedule_work (&dev->kevent))
2368 deverr (dev, "kevent %d may have been dropped", work);
2370 devdbg (dev, "kevent %d scheduled", work);
2373 /*-------------------------------------------------------------------------*/
2375 static void rx_complete (struct urb *urb, struct pt_regs *regs);
2377 static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2379 struct sk_buff *skb;
2380 struct skb_data *entry;
2382 unsigned long lockflags;
2385 #ifdef CONFIG_USB_NET1080
2386 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2387 size = FRAMED_SIZE (dev->net->mtu);
2390 #ifdef CONFIG_USB_GENESYS
2391 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2392 size = GL_RCV_BUF_SIZE;
2395 #ifdef CONFIG_USB_ZAURUS
2396 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2397 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2400 #ifdef CONFIG_USB_RNDIS
2401 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2402 size = RNDIS_MAX_TRANSFER;
2405 size = (sizeof (struct ethhdr) + dev->net->mtu);
2407 if ((skb = alloc_skb (size, flags)) == NULL) {
2408 devdbg (dev, "no rx skb");
2409 defer_kevent (dev, EVENT_RX_MEMORY);
2414 entry = (struct skb_data *) skb->cb;
2417 entry->state = rx_start;
2420 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2421 skb->data, size, rx_complete, skb);
2422 urb->transfer_flags |= URB_ASYNC_UNLINK;
2424 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2426 if (netif_running (dev->net)
2427 && netif_device_present (dev->net)
2428 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2429 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2431 defer_kevent (dev, EVENT_RX_HALT);
2434 defer_kevent (dev, EVENT_RX_MEMORY);
2437 devdbg (dev, "device gone");
2438 netif_device_detach (dev->net);
2441 devdbg (dev, "rx submit, %d", retval);
2442 tasklet_schedule (&dev->bh);
2445 __skb_queue_tail (&dev->rxq, skb);
2448 devdbg (dev, "rx: stopped");
2451 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2453 dev_kfree_skb_any (skb);
2459 /*-------------------------------------------------------------------------*/
2461 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2463 if (dev->driver_info->rx_fixup
2464 && !dev->driver_info->rx_fixup (dev, skb))
2466 // else network stack removes extra byte if we forced a short packet
2469 skb_return (dev, skb);
2471 devdbg (dev, "drop");
2473 dev->stats.rx_errors++;
2474 skb_queue_tail (&dev->done, skb);
2478 /*-------------------------------------------------------------------------*/
2480 static void rx_complete (struct urb *urb, struct pt_regs *regs)
2482 struct sk_buff *skb = (struct sk_buff *) urb->context;
2483 struct skb_data *entry = (struct skb_data *) skb->cb;
2484 struct usbnet *dev = entry->dev;
2485 int urb_status = urb->status;
2487 skb_put (skb, urb->actual_length);
2488 entry->state = rx_done;
2491 switch (urb_status) {
2494 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2495 entry->state = rx_cleanup;
2496 dev->stats.rx_errors++;
2497 dev->stats.rx_length_errors++;
2498 devdbg (dev, "rx length %d", skb->len);
2502 // stalls need manual reset. this is rare ... except that
2503 // when going through USB 2.0 TTs, unplug appears this way.
2504 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2505 // storm, recovering as needed.
2507 dev->stats.rx_errors++;
2508 defer_kevent (dev, EVENT_RX_HALT);
2511 // software-driven interface shutdown
2512 case -ECONNRESET: // async unlink
2513 case -ESHUTDOWN: // hardware gone
2515 devdbg (dev, "rx shutdown, code %d", urb_status);
2519 // we get controller i/o faults during khubd disconnect() delays.
2520 // throttle down resubmits, to avoid log floods; just temporarily,
2521 // so we still recover when the fault isn't a khubd delay.
2522 case -EPROTO: // ehci
2523 case -ETIMEDOUT: // ohci
2524 case -EILSEQ: // uhci
2525 dev->stats.rx_errors++;
2526 if (!timer_pending (&dev->delay)) {
2527 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2528 devdbg (dev, "rx throttle %d", urb_status);
2531 entry->state = rx_cleanup;
2536 // data overrun ... flush fifo?
2538 dev->stats.rx_over_errors++;
2542 entry->state = rx_cleanup;
2543 dev->stats.rx_errors++;
2544 devdbg (dev, "rx status %d", urb_status);
2548 defer_bh (dev, skb);
2551 if (netif_running (dev->net)
2552 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2553 rx_submit (dev, urb, GFP_ATOMIC);
2559 devdbg (dev, "no read resubmitted");
2560 #endif /* VERBOSE */
2563 /*-------------------------------------------------------------------------*/
2565 // unlink pending rx/tx; completion handlers do all other cleanup
2567 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2569 unsigned long flags;
2570 struct sk_buff *skb, *skbnext;
2573 spin_lock_irqsave (&q->lock, flags);
2574 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2575 struct skb_data *entry;
2579 entry = (struct skb_data *) skb->cb;
2581 skbnext = skb->next;
2583 // during some PM-driven resume scenarios,
2584 // these (async) unlinks complete immediately
2585 retval = usb_unlink_urb (urb);
2586 if (retval != -EINPROGRESS && retval != 0)
2587 devdbg (dev, "unlink urb err, %d", retval);
2591 spin_unlock_irqrestore (&q->lock, flags);
2596 /*-------------------------------------------------------------------------*/
2598 // precondition: never called in_interrupt
2600 static int usbnet_stop (struct net_device *net)
2602 struct usbnet *dev = netdev_priv(net);
2604 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2605 DECLARE_WAITQUEUE (wait, current);
2607 netif_stop_queue (net);
2609 if (dev->msg_level >= 2)
2610 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2611 dev->stats.rx_packets, dev->stats.tx_packets,
2612 dev->stats.rx_errors, dev->stats.tx_errors
2615 // ensure there are no more active urbs
2616 add_wait_queue (&unlink_wakeup, &wait);
2617 dev->wait = &unlink_wakeup;
2618 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2620 // maybe wait for deletions to finish.
2621 while (skb_queue_len (&dev->rxq)
2622 && skb_queue_len (&dev->txq)
2623 && skb_queue_len (&dev->done)) {
2624 msleep(UNLINK_TIMEOUT_MS);
2625 devdbg (dev, "waited for %d urb completions", temp);
2628 remove_wait_queue (&unlink_wakeup, &wait);
2630 /* deferred work (task, timer, softirq) must also stop.
2631 * can't flush_scheduled_work() until we drop rtnl (later),
2632 * else workers could deadlock; so make workers a NOP.
2635 del_timer_sync (&dev->delay);
2636 tasklet_kill (&dev->bh);
2641 /*-------------------------------------------------------------------------*/
2643 // posts reads, and enables write queuing
2645 // precondition: never called in_interrupt
2647 static int usbnet_open (struct net_device *net)
2649 struct usbnet *dev = netdev_priv(net);
2651 struct driver_info *info = dev->driver_info;
2653 // put into "known safe" state
2654 if (info->reset && (retval = info->reset (dev)) < 0) {
2655 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2657 dev->udev->bus->bus_name, dev->udev->devpath,
2662 // insist peer be connected
2663 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2664 devdbg (dev, "can't open; %d", retval);
2668 netif_start_queue (net);
2669 if (dev->msg_level >= 2) {
2672 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2673 framing = "NetChip";
2674 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
2675 framing = "GeneSys";
2676 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
2678 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
2683 devinfo (dev, "open: enable queueing "
2684 "(rx %d, tx %d) mtu %d %s framing",
2685 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
2689 // delay posting reads until we're fully open
2690 tasklet_schedule (&dev->bh);
2695 /*-------------------------------------------------------------------------*/
2697 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2699 struct usbnet *dev = netdev_priv(net);
2701 strncpy (info->driver, driver_name, sizeof info->driver);
2702 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2703 strncpy (info->fw_version, dev->driver_info->description,
2704 sizeof info->fw_version);
2705 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2708 static u32 usbnet_get_link (struct net_device *net)
2710 struct usbnet *dev = netdev_priv(net);
2712 /* If a check_connect is defined, return it's results */
2713 if (dev->driver_info->check_connect)
2714 return dev->driver_info->check_connect (dev) == 0;
2716 /* Otherwise, we're up to avoid breaking scripts */
2720 static u32 usbnet_get_msglevel (struct net_device *net)
2722 struct usbnet *dev = netdev_priv(net);
2724 return dev->msg_level;
2727 static void usbnet_set_msglevel (struct net_device *net, u32 level)
2729 struct usbnet *dev = netdev_priv(net);
2731 dev->msg_level = level;
2734 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2738 struct usbnet *dev = netdev_priv(net);
2740 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2741 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
2747 /*-------------------------------------------------------------------------*/
2749 /* work that cannot be done in interrupt context uses keventd.
2751 * NOTE: with 2.5 we could do more of this using completion callbacks,
2752 * especially now that control transfers can be queued.
2757 struct usbnet *dev = data;
2760 /* usb_clear_halt() needs a thread context */
2761 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2762 unlink_urbs (dev, &dev->txq);
2763 status = usb_clear_halt (dev->udev, dev->out);
2764 if (status < 0 && status != -EPIPE)
2765 deverr (dev, "can't clear tx halt, status %d",
2768 clear_bit (EVENT_TX_HALT, &dev->flags);
2769 netif_wake_queue (dev->net);
2772 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2773 unlink_urbs (dev, &dev->rxq);
2774 status = usb_clear_halt (dev->udev, dev->in);
2775 if (status < 0 && status != -EPIPE)
2776 deverr (dev, "can't clear rx halt, status %d",
2779 clear_bit (EVENT_RX_HALT, &dev->flags);
2780 tasklet_schedule (&dev->bh);
2784 /* tasklet could resubmit itself forever if memory is tight */
2785 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2786 struct urb *urb = NULL;
2788 if (netif_running (dev->net))
2789 urb = usb_alloc_urb (0, GFP_KERNEL);
2791 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2793 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2794 rx_submit (dev, urb, GFP_KERNEL);
2795 tasklet_schedule (&dev->bh);
2800 devdbg (dev, "kevent done, flags = 0x%lx",
2804 /*-------------------------------------------------------------------------*/
2806 static void tx_complete (struct urb *urb, struct pt_regs *regs)
2808 struct sk_buff *skb = (struct sk_buff *) urb->context;
2809 struct skb_data *entry = (struct skb_data *) skb->cb;
2810 struct usbnet *dev = entry->dev;
2812 if (urb->status == 0) {
2813 dev->stats.tx_packets++;
2814 dev->stats.tx_bytes += entry->length;
2816 dev->stats.tx_errors++;
2818 switch (urb->status) {
2820 defer_kevent (dev, EVENT_TX_HALT);
2823 // like rx, tx gets controller i/o faults during khubd delays
2824 // and so it uses the same throttling mechanism.
2825 case -EPROTO: // ehci
2826 case -ETIMEDOUT: // ohci
2827 case -EILSEQ: // uhci
2828 if (!timer_pending (&dev->delay)) {
2829 mod_timer (&dev->delay,
2830 jiffies + THROTTLE_JIFFIES);
2831 devdbg (dev, "tx throttle %d", urb->status);
2833 netif_stop_queue (dev->net);
2836 devdbg (dev, "tx err %d", entry->urb->status);
2842 entry->state = tx_done;
2843 defer_bh (dev, skb);
2846 /*-------------------------------------------------------------------------*/
2848 static void usbnet_tx_timeout (struct net_device *net)
2850 struct usbnet *dev = netdev_priv(net);
2852 unlink_urbs (dev, &dev->txq);
2853 tasklet_schedule (&dev->bh);
2855 // FIXME: device recovery -- reset?
2858 /*-------------------------------------------------------------------------*/
2860 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2862 struct usbnet *dev = netdev_priv(net);
2864 int retval = NET_XMIT_SUCCESS;
2865 struct urb *urb = NULL;
2866 struct skb_data *entry;
2867 struct driver_info *info = dev->driver_info;
2868 unsigned long flags;
2869 #ifdef CONFIG_USB_NET1080
2870 struct nc_header *header = NULL;
2871 struct nc_trailer *trailer = NULL;
2872 #endif /* CONFIG_USB_NET1080 */
2874 // some devices want funky USB-level framing, for
2875 // win32 driver (usually) and/or hardware quirks
2876 if (info->tx_fixup) {
2877 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2879 devdbg (dev, "can't tx_fixup skb");
2885 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
2886 devdbg (dev, "no urb");
2890 entry = (struct skb_data *) skb->cb;
2893 entry->state = tx_start;
2894 entry->length = length;
2896 // FIXME: reorganize a bit, so that fixup() fills out NetChip
2897 // framing too. (Packet ID update needs the spinlock...)
2898 // [ BETTER: we already own net->xmit_lock, that's enough ]
2900 #ifdef CONFIG_USB_NET1080
2901 if (info->flags & FLAG_FRAMING_NC) {
2902 header = (struct nc_header *) skb_push (skb, sizeof *header);
2903 header->hdr_len = cpu_to_le16 (sizeof (*header));
2904 header->packet_len = cpu_to_le16 (length);
2905 if (!((skb->len + sizeof *trailer) & 0x01))
2906 *skb_put (skb, 1) = PAD_BYTE;
2907 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2909 #endif /* CONFIG_USB_NET1080 */
2911 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2912 skb->data, skb->len, tx_complete, skb);
2913 urb->transfer_flags |= URB_ASYNC_UNLINK;
2915 /* don't assume the hardware handles USB_ZERO_PACKET
2916 * NOTE: strictly conforming cdc-ether devices should expect
2917 * the ZLP here, but ignore the one-byte packet.
2919 * FIXME zero that byte, if it doesn't require a new skb.
2921 if ((length % dev->maxpacket) == 0)
2922 urb->transfer_buffer_length++;
2924 spin_lock_irqsave (&dev->txq.lock, flags);
2926 #ifdef CONFIG_USB_NET1080
2927 if (info->flags & FLAG_FRAMING_NC) {
2928 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
2929 put_unaligned (header->packet_id, &trailer->packet_id);
2931 devdbg (dev, "frame >tx h %d p %d id %d",
2932 header->hdr_len, header->packet_len,
2936 #endif /* CONFIG_USB_NET1080 */
2938 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2940 netif_stop_queue (net);
2941 defer_kevent (dev, EVENT_TX_HALT);
2944 devdbg (dev, "tx: submit urb err %d", retval);
2947 net->trans_start = jiffies;
2948 __skb_queue_tail (&dev->txq, skb);
2949 if (dev->txq.qlen >= TX_QLEN (dev))
2950 netif_stop_queue (net);
2952 spin_unlock_irqrestore (&dev->txq.lock, flags);
2955 devdbg (dev, "drop, code %d", retval);
2957 retval = NET_XMIT_SUCCESS;
2958 dev->stats.tx_dropped++;
2960 dev_kfree_skb_any (skb);
2964 devdbg (dev, "> tx, len %d, type 0x%x",
2965 length, skb->protocol);
2972 /*-------------------------------------------------------------------------*/
2974 // tasklet (work deferred from completions, in_irq) or timer
2976 static void usbnet_bh (unsigned long param)
2978 struct usbnet *dev = (struct usbnet *) param;
2979 struct sk_buff *skb;
2980 struct skb_data *entry;
2982 while ((skb = skb_dequeue (&dev->done))) {
2983 entry = (struct skb_data *) skb->cb;
2984 switch (entry->state) {
2986 entry->state = rx_cleanup;
2987 rx_process (dev, skb);
2991 usb_free_urb (entry->urb);
2992 dev_kfree_skb (skb);
2995 devdbg (dev, "bogus skb state %d", entry->state);
2999 // waiting for all pending urbs to complete?
3001 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
3002 wake_up (dev->wait);
3005 // or are we maybe short a few urbs?
3006 } else if (netif_running (dev->net)
3007 && netif_device_present (dev->net)
3008 && !timer_pending (&dev->delay)
3009 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
3010 int temp = dev->rxq.qlen;
3011 int qlen = RX_QLEN (dev);
3017 // don't refill the queue all at once
3018 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
3019 urb = usb_alloc_urb (0, GFP_ATOMIC);
3021 rx_submit (dev, urb, GFP_ATOMIC);
3023 if (temp != dev->rxq.qlen)
3024 devdbg (dev, "rxqlen %d --> %d",
3025 temp, dev->rxq.qlen);
3026 if (dev->rxq.qlen < qlen)
3027 tasklet_schedule (&dev->bh);
3029 if (dev->txq.qlen < TX_QLEN (dev))
3030 netif_wake_queue (dev->net);
3036 /*-------------------------------------------------------------------------
3038 * USB Device Driver support
3040 *-------------------------------------------------------------------------*/
3042 // precondition: never called in_interrupt
3044 static void usbnet_disconnect (struct usb_interface *intf)
3047 struct usb_device *xdev;
3048 struct net_device *net;
3050 dev = usb_get_intfdata(intf);
3051 usb_set_intfdata(intf, NULL);
3055 xdev = interface_to_usbdev (intf);
3057 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
3058 xdev->bus->bus_name, xdev->devpath,
3059 dev->driver_info->description);
3062 unregister_netdev (net);
3064 /* we don't hold rtnl here ... */
3065 flush_scheduled_work ();
3067 if (dev->driver_info->unbind)
3068 dev->driver_info->unbind (dev, intf);
3075 /*-------------------------------------------------------------------------*/
3077 static struct ethtool_ops usbnet_ethtool_ops;
3079 // precondition: never called in_interrupt
3082 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3085 struct net_device *net;
3086 struct usb_host_interface *interface;
3087 struct driver_info *info;
3088 struct usb_device *xdev;
3091 info = (struct driver_info *) prod->driver_info;
3093 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3096 xdev = interface_to_usbdev (udev);
3097 interface = udev->cur_altsetting;
3103 // set up our own records
3104 net = alloc_etherdev(sizeof(*dev));
3106 dbg ("can't kmalloc dev");
3110 dev = netdev_priv(net);
3112 dev->driver_info = info;
3113 dev->msg_level = msg_level;
3114 skb_queue_head_init (&dev->rxq);
3115 skb_queue_head_init (&dev->txq);
3116 skb_queue_head_init (&dev->done);
3117 dev->bh.func = usbnet_bh;
3118 dev->bh.data = (unsigned long) dev;
3119 INIT_WORK (&dev->kevent, kevent, dev);
3120 dev->delay.function = usbnet_bh;
3121 dev->delay.data = (unsigned long) dev;
3122 init_timer (&dev->delay);
3124 SET_MODULE_OWNER (net);
3126 strcpy (net->name, "usb%d");
3127 memcpy (net->dev_addr, node_id, sizeof node_id);
3130 // dma_supported() is deeply broken on almost all architectures
3131 // possible with some EHCI controllers
3132 if (dma_supported (&udev->dev, 0xffffffffffffffffULL))
3133 net->features |= NETIF_F_HIGHDMA;
3136 net->change_mtu = usbnet_change_mtu;
3137 net->get_stats = usbnet_get_stats;
3138 net->hard_start_xmit = usbnet_start_xmit;
3139 net->open = usbnet_open;
3140 net->stop = usbnet_stop;
3141 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3142 net->tx_timeout = usbnet_tx_timeout;
3143 net->do_ioctl = usbnet_ioctl;
3144 net->ethtool_ops = &usbnet_ethtool_ops;
3146 // allow device-specific bind/init procedures
3147 // NOTE net->name still not usable ...
3149 status = info->bind (dev, udev);
3150 // heuristic: "usb%d" for links we know are two-host,
3151 // else "eth%d" when there's reasonable doubt. userspace
3152 // can rename the link if it knows better.
3153 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3154 && (net->dev_addr [0] & 0x02) == 0)
3155 strcpy (net->name, "eth%d");
3156 } else if (!info->in || info->out)
3157 status = get_endpoints (dev, udev);
3159 dev->in = usb_rcvbulkpipe (xdev, info->in);
3160 dev->out = usb_sndbulkpipe (xdev, info->out);
3161 if (!(info->flags & FLAG_NO_SETINT))
3162 status = usb_set_interface (xdev,
3163 interface->desc.bInterfaceNumber,
3164 interface->desc.bAlternateSetting);
3172 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3174 SET_NETDEV_DEV(net, &udev->dev);
3175 status = register_netdev (net);
3178 devinfo (dev, "register usbnet at usb-%s-%s, %s",
3179 xdev->bus->bus_name, xdev->devpath,
3180 dev->driver_info->description);
3182 // ok, it's ready to go.
3183 usb_set_intfdata (udev, dev);
3185 // start as if the link is up
3186 netif_device_attach (net);
3192 info->unbind (dev, udev);
3201 /*-------------------------------------------------------------------------*/
3203 #ifndef HAVE_HARDWARE
3204 #error You need to configure some hardware for this driver
3208 * chip vendor names won't normally be on the cables, and
3209 * may not be on the device.
3212 static const struct usb_device_id products [] = {
3214 #ifdef CONFIG_USB_ALI_M5632
3216 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3217 .driver_info = (unsigned long) &ali_m5632_info,
3221 #ifdef CONFIG_USB_AN2720
3223 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3224 .driver_info = (unsigned long) &an2720_info,
3226 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3227 .driver_info = (unsigned long) &an2720_info,
3231 #ifdef CONFIG_USB_BELKIN
3233 USB_DEVICE (0x050d, 0x0004), // Belkin
3234 .driver_info = (unsigned long) &belkin_info,
3236 USB_DEVICE (0x056c, 0x8100), // eTEK
3237 .driver_info = (unsigned long) &belkin_info,
3239 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3240 .driver_info = (unsigned long) &belkin_info,
3244 #ifdef CONFIG_USB_AX8817X
3247 USB_DEVICE (0x077b, 0x2226),
3248 .driver_info = (unsigned long) &ax8817x_info,
3251 USB_DEVICE (0x0846, 0x1040),
3252 .driver_info = (unsigned long) &netgear_fa120_info,
3255 USB_DEVICE (0x2001, 0x1a00),
3256 .driver_info = (unsigned long) &dlink_dub_e100_info,
3258 // Intellinet, ST Lab USB Ethernet
3259 USB_DEVICE (0x0b95, 0x1720),
3260 .driver_info = (unsigned long) &ax8817x_info,
3262 // Hawking UF200, TrendNet TU2-ET100
3263 USB_DEVICE (0x07b8, 0x420a),
3264 .driver_info = (unsigned long) &hawking_uf200_info,
3266 // Billionton Systems, USB2AR
3267 USB_DEVICE (0x08dd, 0x90ff),
3268 .driver_info = (unsigned long) &ax8817x_info,
3271 USB_DEVICE (0x0557, 0x2009),
3272 .driver_info = (unsigned long) &ax8817x_info,
3274 // Buffalo LUA-U2-KTX
3275 USB_DEVICE (0x0411, 0x003d),
3276 .driver_info = (unsigned long) &ax8817x_info,
3278 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3279 USB_DEVICE (0x6189, 0x182d),
3280 .driver_info = (unsigned long) &ax8817x_info,
3282 // corega FEther USB2-TX
3283 USB_DEVICE (0x07aa, 0x0017),
3284 .driver_info = (unsigned long) &ax8817x_info,
3286 // Surecom EP-1427X-2
3287 USB_DEVICE (0x1189, 0x0893),
3288 .driver_info = (unsigned long) &ax8817x_info,
3290 // goodway corp usb gwusb2e
3291 USB_DEVICE (0x1631, 0x6200),
3292 .driver_info = (unsigned long) &ax8817x_info,
3296 #ifdef CONFIG_USB_EPSON2888
3298 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3299 .driver_info = (unsigned long) &epson2888_info,
3303 #ifdef CONFIG_USB_GENESYS
3305 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3306 .driver_info = (unsigned long) &genelink_info,
3308 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3309 * that's half duplex, not currently supported
3313 #ifdef CONFIG_USB_NET1080
3315 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3316 .driver_info = (unsigned long) &net1080_info,
3318 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3319 .driver_info = (unsigned long) &net1080_info,
3323 #ifdef CONFIG_USB_PL2301
3325 USB_DEVICE (0x067b, 0x0000), // PL-2301
3326 .driver_info = (unsigned long) &prolific_info,
3328 USB_DEVICE (0x067b, 0x0001), // PL-2302
3329 .driver_info = (unsigned long) &prolific_info,
3333 #ifdef CONFIG_USB_KC2190
3335 USB_DEVICE (0x050f, 0x0190), // KC-190
3336 .driver_info = (unsigned long) &kc2190_info,
3340 #ifdef CONFIG_USB_RNDIS
3342 /* RNDIS is MSFT's un-official variant of CDC ACM */
3343 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3344 .driver_info = (unsigned long) &rndis_info,
3348 #ifdef CONFIG_USB_ARMLINUX
3350 * SA-1100 using standard ARM Linux kernels, or compatible.
3351 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3352 * The sa-1100 "usb-eth" driver handles the basic framing.
3354 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3355 * the sa1100 one, but hardware uses different endpoint numbers.
3357 * Or the Linux "Ethernet" gadget on hardware that can't talk
3358 * CDC Ethernet (e.g., no altsettings), in either of two modes:
3359 * - acting just like the old "usb-eth" firmware, though
3360 * the implementation is different
3361 * - supporting RNDIS as the first/default configuration for
3362 * MS-Windows interop; Linux needs to use the other config
3365 // 1183 = 0x049F, both used as hex values?
3366 // Compaq "Itsy" vendor/product id
3367 USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
3368 .driver_info = (unsigned long) &linuxdev_info,
3370 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3371 .driver_info = (unsigned long) &yopy_info,
3373 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3374 .driver_info = (unsigned long) &blob_info,
3376 // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
3377 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
3378 .driver_info = (unsigned long) &linuxdev_info,
3382 #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
3384 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3385 * Same idea as above, but different framing.
3387 * PXA-2xx based models are also lying-about-cdc.
3389 * NOTE: These entries do double-duty, serving as blacklist entries
3390 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
3393 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3394 | USB_DEVICE_ID_MATCH_DEVICE,
3396 .idProduct = 0x8004,
3397 /* match the master interface */
3398 .bInterfaceClass = USB_CLASS_COMM,
3399 .bInterfaceSubClass = 6 /* Ethernet model */,
3400 .bInterfaceProtocol = 0,
3401 .driver_info = ZAURUS_STRONGARM_INFO,
3403 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3404 | USB_DEVICE_ID_MATCH_DEVICE,
3406 .idProduct = 0x8005, /* A-300 */
3407 .bInterfaceClass = USB_CLASS_COMM,
3408 .bInterfaceSubClass = 6 /* Ethernet model */,
3409 .bInterfaceProtocol = 0x00,
3410 .driver_info = ZAURUS_PXA_INFO,
3412 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3413 | USB_DEVICE_ID_MATCH_DEVICE,
3415 .idProduct = 0x8006, /* B-500/SL-5600 */
3416 .bInterfaceClass = USB_CLASS_COMM,
3417 .bInterfaceSubClass = 6 /* Ethernet model */,
3418 .bInterfaceProtocol = 0x00,
3419 .driver_info = ZAURUS_PXA_INFO,
3421 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3422 | USB_DEVICE_ID_MATCH_DEVICE,
3424 .idProduct = 0x8007, /* C-700 */
3425 .bInterfaceClass = USB_CLASS_COMM,
3426 .bInterfaceSubClass = 6 /* Ethernet model */,
3427 .bInterfaceProtocol = 0x00,
3428 .driver_info = ZAURUS_PXA_INFO,
3430 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3431 | USB_DEVICE_ID_MATCH_DEVICE,
3433 .idProduct = 0x9031, /* C-750 C-760 */
3434 .bInterfaceClass = USB_CLASS_COMM,
3435 .bInterfaceSubClass = 6 /* Ethernet model */,
3436 .bInterfaceProtocol = 0x00,
3437 .driver_info = ZAURUS_PXA_INFO,
3439 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3440 | USB_DEVICE_ID_MATCH_DEVICE,
3442 .idProduct = 0x9032, /* SL-6000 */
3443 .bInterfaceClass = USB_CLASS_COMM,
3444 .bInterfaceSubClass = 6 /* Ethernet model */,
3445 .bInterfaceProtocol = 0x00,
3446 .driver_info = ZAURUS_PXA_INFO,
3448 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3449 | USB_DEVICE_ID_MATCH_DEVICE,
3451 .idProduct = 0x9050, /* C-860 */
3452 .bInterfaceClass = USB_CLASS_COMM,
3453 .bInterfaceSubClass = 6 /* Ethernet model */,
3454 .bInterfaceProtocol = 0x00,
3455 .driver_info = ZAURUS_PXA_INFO,
3458 /* Olympus has some models with a Zaurus-compatible option.
3459 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
3462 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3463 | USB_DEVICE_ID_MATCH_DEVICE,
3465 .idProduct = 0x0F02, /* R-1000 */
3466 .bInterfaceClass = USB_CLASS_COMM,
3467 .bInterfaceSubClass = 6 /* Ethernet model */,
3468 .bInterfaceProtocol = 0x00,
3469 .driver_info = OLYMPUS_MXL_INFO,
3473 #ifdef CONFIG_USB_CDCETHER
3475 /* CDC Ether uses two interfaces, not necessarily consecutive.
3476 * We match the main interface, ignoring the optional device
3477 * class so we could handle devices that aren't exclusively
3480 * NOTE: this match must come AFTER entries working around
3481 * bugs/quirks in a given product (like Zaurus, above).
3483 USB_INTERFACE_INFO (USB_CLASS_COMM, 6 /* Ethernet model */, 0),
3484 .driver_info = (unsigned long) &cdc_info,
3490 MODULE_DEVICE_TABLE (usb, products);
3492 static struct usb_driver usbnet_driver = {
3493 .owner = THIS_MODULE,
3494 .name = driver_name,
3495 .id_table = products,
3496 .probe = usbnet_probe,
3497 .disconnect = usbnet_disconnect,
3500 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
3501 static struct ethtool_ops usbnet_ethtool_ops = {
3502 .get_drvinfo = usbnet_get_drvinfo,
3503 .get_link = usbnet_get_link,
3504 .get_msglevel = usbnet_get_msglevel,
3505 .set_msglevel = usbnet_set_msglevel,
3508 /*-------------------------------------------------------------------------*/
3510 static int __init usbnet_init (void)
3512 // compiler should optimize these out
3513 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3514 < sizeof (struct skb_data));
3515 #ifdef CONFIG_USB_CDCETHER
3516 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3517 < sizeof (struct cdc_state)));
3520 random_ether_addr(node_id);
3522 return usb_register(&usbnet_driver);
3524 module_init (usbnet_init);
3526 static void __exit usbnet_exit (void)
3528 usb_deregister (&usbnet_driver);
3530 module_exit (usbnet_exit);
3532 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
3533 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
3534 MODULE_LICENSE ("GPL");