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 // #define DEBUG // error path messages, extra info
111 // #define VERBOSE // more; success messages
113 #include <linux/config.h>
114 #ifdef CONFIG_USB_DEBUG
117 #include <linux/module.h>
118 #include <linux/kmod.h>
119 #include <linux/sched.h>
120 #include <linux/init.h>
121 #include <linux/netdevice.h>
122 #include <linux/etherdevice.h>
123 #include <linux/random.h>
124 #include <linux/ethtool.h>
125 #include <linux/workqueue.h>
126 #include <linux/mii.h>
127 #include <asm/uaccess.h>
128 #include <asm/unaligned.h>
129 #include <linux/usb.h>
131 #include <asm/scatterlist.h>
132 #include <linux/mm.h>
133 #include <linux/dma-mapping.h>
135 #define DRIVER_VERSION "25-Aug-2003"
138 /*-------------------------------------------------------------------------*/
141 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
142 * Several dozen bytes of IPv4 data can fit in two such transactions.
143 * One maximum size Ethernet packet takes twenty four of them.
144 * For high speed, each frame comfortably fits almost 36 max size
145 * Ethernet packets (so queues should be bigger).
147 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
148 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
150 // packets are always ethernet inside
151 // ... except they can be bigger (limit of 64K with NetChip framing)
152 #define MIN_PACKET sizeof(struct ethhdr)
153 #define MAX_PACKET 32768
155 // reawaken network queue this soon after stopping; else watchdog barks
156 #define TX_TIMEOUT_JIFFIES (5*HZ)
158 // throttle rx/tx briefly after some faults, so khubd might disconnect()
159 // us (it polls at HZ/4 usually) before we report too many false errors.
160 #define THROTTLE_JIFFIES (HZ/8)
162 // for vendor-specific control operations
163 #define CONTROL_TIMEOUT_MS (500) /* msec */
164 #define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
167 #define UNLINK_TIMEOUT_JIFFIES ((3 /*ms*/ * HZ)/1000)
169 /*-------------------------------------------------------------------------*/
171 // randomly generated ethernet address
172 static u8 node_id [ETH_ALEN];
174 // state we keep for each device we handle
177 struct usb_device *udev;
178 struct driver_info *driver_info;
179 wait_queue_head_t *wait;
181 // i/o info: pipes etc
184 struct timer_list delay;
186 // protocol/interface state
187 struct net_device *net;
188 struct net_device_stats stats;
190 unsigned long data [5];
192 struct mii_if_info mii;
194 // various kinds of pending driver work
195 struct sk_buff_head rxq;
196 struct sk_buff_head txq;
197 struct sk_buff_head done;
198 struct tasklet_struct bh;
200 struct work_struct kevent;
202 # define EVENT_TX_HALT 0
203 # define EVENT_RX_HALT 1
204 # define EVENT_RX_MEMORY 2
207 // device-specific info used by the driver
212 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
213 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
214 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
215 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
216 #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
218 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
219 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
221 /* init device ... can sleep, or cause probe() failure */
222 int (*bind)(struct usbnet *, struct usb_interface *);
224 /* cleanup device ... can sleep, but can't fail */
225 void (*unbind)(struct usbnet *, struct usb_interface *);
227 /* reset device ... can sleep */
228 int (*reset)(struct usbnet *);
230 /* see if peer is connected ... can sleep */
231 int (*check_connect)(struct usbnet *);
233 /* fixup rx packet (strip framing) */
234 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
236 /* fixup tx packet (add framing) */
237 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
238 struct sk_buff *skb, int flags);
240 // FIXME -- also an interrupt mechanism
241 // useful for at least PL2301/2302 and GL620USB-A
242 // and CDC use them to report 'is it connected' changes
244 /* for new devices, use the descriptor-reading code instead */
245 int in; /* rx endpoint */
246 int out; /* tx endpoint */
248 unsigned long data; /* Misc driver specific data */
251 // we record the state for each of our queued skbs
255 rx_start, rx_done, rx_cleanup
258 struct skb_data { // skb->cb is one of these
261 enum skb_state state;
265 static const char driver_name [] = "usbnet";
267 /* use ethtool to change the level for any given device */
268 static int msg_level = 1;
269 MODULE_PARM (msg_level, "i");
270 MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
273 #define RUN_CONTEXT (in_irq () ? "in_irq" \
274 : (in_interrupt () ? "in_interrupt" : "can sleep"))
277 #define devdbg(usbnet, fmt, arg...) \
278 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
280 #define devdbg(usbnet, fmt, arg...) do {} while(0)
283 #define deverr(usbnet, fmt, arg...) \
284 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
285 #define devwarn(usbnet, fmt, arg...) \
286 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
288 #define devinfo(usbnet, fmt, arg...) \
289 do { if ((usbnet)->msg_level >= 1) \
290 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
293 /*-------------------------------------------------------------------------*/
295 static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
296 static u32 usbnet_get_link (struct net_device *);
297 static u32 usbnet_get_msglevel (struct net_device *);
298 static void usbnet_set_msglevel (struct net_device *, u32);
300 /* mostly for PDA style devices, which are always connected if present */
301 static int always_connected (struct usbnet *dev)
306 /* handles CDC Ethernet and many other network "bulk data" interfaces */
308 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
311 struct usb_host_interface *alt;
312 struct usb_host_endpoint *in, *out;
314 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
318 alt = intf->altsetting + tmp;
320 /* take the first altsetting with in-bulk + out-bulk;
321 * ignore other endpoints and altsetttings.
323 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
324 struct usb_host_endpoint *e;
326 e = alt->endpoint + ep;
327 if (e->desc.bmAttributes != USB_ENDPOINT_XFER_BULK)
329 if (e->desc.bEndpointAddress & USB_DIR_IN) {
343 if (alt->desc.bAlternateSetting != 0
344 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
345 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
346 alt->desc.bAlternateSetting);
351 dev->in = usb_rcvbulkpipe (dev->udev,
352 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
353 dev->out = usb_sndbulkpipe (dev->udev,
354 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
358 static void skb_return (struct usbnet *dev, struct sk_buff *skb)
363 skb->protocol = eth_type_trans (skb, dev->net);
364 dev->stats.rx_packets++;
365 dev->stats.rx_bytes += skb->len;
368 devdbg (dev, "< rx, len %d, type 0x%x",
369 skb->len + sizeof (struct ethhdr), skb->protocol);
371 memset (skb->cb, 0, sizeof (struct skb_data));
372 status = netif_rx (skb);
373 if (status != NET_RX_SUCCESS)
374 devdbg (dev, "netif_rx status %d", status);
378 #ifdef CONFIG_USB_ALI_M5632
379 #define HAVE_HARDWARE
381 /*-------------------------------------------------------------------------
383 * ALi M5632 driver ... does high speed
385 *-------------------------------------------------------------------------*/
387 static const struct driver_info ali_m5632_info = {
388 .description = "ALi M5632",
395 #ifdef CONFIG_USB_AN2720
396 #define HAVE_HARDWARE
398 /*-------------------------------------------------------------------------
400 * AnchorChips 2720 driver ... http://www.cypress.com
402 * This doesn't seem to have a way to detect whether the peer is
403 * connected, or need any reset handshaking. It's got pretty big
404 * internal buffers (handles most of a frame's worth of data).
405 * Chip data sheets don't describe any vendor control messages.
407 *-------------------------------------------------------------------------*/
409 static const struct driver_info an2720_info = {
410 .description = "AnchorChips/Cypress 2720",
411 // no reset available!
412 // no check_connect available!
414 .in = 2, .out = 2, // direction distinguishes these
417 #endif /* CONFIG_USB_AN2720 */
420 #ifdef CONFIG_USB_AX8817X
421 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
423 #define HAVE_HARDWARE
426 #include <linux/crc32.h>
428 #define AX_CMD_SET_SW_MII 0x06
429 #define AX_CMD_READ_MII_REG 0x07
430 #define AX_CMD_WRITE_MII_REG 0x08
431 #define AX_CMD_SET_HW_MII 0x0a
432 #define AX_CMD_READ_EEPROM 0x0b
433 #define AX_CMD_WRITE_EEPROM 0x0c
434 #define AX_CMD_WRITE_RX_CTL 0x10
435 #define AX_CMD_READ_IPG012 0x11
436 #define AX_CMD_WRITE_IPG0 0x12
437 #define AX_CMD_WRITE_IPG1 0x13
438 #define AX_CMD_WRITE_IPG2 0x14
439 #define AX_CMD_WRITE_MULTI_FILTER 0x16
440 #define AX_CMD_READ_NODE_ID 0x17
441 #define AX_CMD_READ_PHY_ID 0x19
442 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
443 #define AX_CMD_READ_MONITOR_MODE 0x1c
444 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
445 #define AX_CMD_WRITE_GPIOS 0x1f
447 #define AX_MONITOR_MODE 0x01
448 #define AX_MONITOR_LINK 0x02
449 #define AX_MONITOR_MAGIC 0x04
450 #define AX_MONITOR_HSFS 0x10
452 #define AX_MCAST_FILTER_SIZE 8
453 #define AX_MAX_MCAST 64
455 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
456 u16 size, void *data)
458 return usb_control_msg(
460 usb_rcvctrlpipe(dev->udev, 0),
462 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
467 CONTROL_TIMEOUT_JIFFIES);
470 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
471 u16 size, void *data)
473 return usb_control_msg(
475 usb_sndctrlpipe(dev->udev, 0),
477 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
482 CONTROL_TIMEOUT_JIFFIES);
485 static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
487 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
490 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
497 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
498 u16 size, void *data)
500 struct usb_ctrlrequest *req;
504 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
505 devdbg(dev, "Error allocating URB in write_cmd_async!");
509 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
510 deverr(dev, "Failed to allocate memory for control request");
515 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
517 req->wValue = cpu_to_le16(value);
518 req->wIndex = cpu_to_le16(index);
519 req->wLength = cpu_to_le16(size);
521 usb_fill_control_urb(urb, dev->udev,
522 usb_sndctrlpipe(dev->udev, 0),
523 (void *)req, data, size,
524 ax8817x_async_cmd_callback, req);
526 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
527 deverr(dev, "Error submitting the control message: status=%d", status);
533 static void ax8817x_set_multicast(struct net_device *net)
535 struct usbnet *dev = (struct usbnet *) net->priv;
538 if (net->flags & IFF_PROMISC) {
540 } else if (net->flags & IFF_ALLMULTI
541 || net->mc_count > AX_MAX_MCAST) {
543 } else if (net->mc_count == 0) {
544 /* just broadcast and directed */
546 /* We use the 20 byte dev->data
547 * for our 8 byte filter buffer
548 * to avoid allocating memory that
549 * is tricky to free later */
550 u8 *multi_filter = (u8 *)&dev->data;
551 struct dev_mc_list *mc_list = net->mc_list;
555 memset(multi_filter, 0, AX_MCAST_FILTER_SIZE);
557 /* Build the multicast hash filter. */
558 for (i = 0; i < net->mc_count; i++) {
561 mc_list->dmi_addr) >> 26;
562 multi_filter[crc_bits >> 3] |=
564 mc_list = mc_list->next;
567 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
568 AX_MCAST_FILTER_SIZE, multi_filter);
573 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
576 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
578 struct usbnet *dev = netdev->priv;
582 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
583 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
584 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
589 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
591 struct usbnet *dev = netdev->priv;
595 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
596 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
597 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
600 static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
602 struct usbnet *dev = (struct usbnet *)net->priv;
605 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
606 wolinfo->supported = 0;
607 wolinfo->wolopts = 0;
610 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
611 wolinfo->wolopts = 0;
612 if (opt & AX_MONITOR_MODE) {
613 if (opt & AX_MONITOR_LINK)
614 wolinfo->wolopts |= WAKE_PHY;
615 if (opt & AX_MONITOR_MAGIC)
616 wolinfo->wolopts |= WAKE_MAGIC;
620 static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
622 struct usbnet *dev = (struct usbnet *)net->priv;
626 if (wolinfo->wolopts & WAKE_PHY)
627 opt |= AX_MONITOR_LINK;
628 if (wolinfo->wolopts & WAKE_MAGIC)
629 opt |= AX_MONITOR_MAGIC;
631 opt |= AX_MONITOR_MODE;
633 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
634 opt, 0, 0, &buf) < 0)
640 static int ax8817x_get_eeprom(struct net_device *net,
641 struct ethtool_eeprom *eeprom, u8 *data)
643 struct usbnet *dev = (struct usbnet *)net->priv;
644 u16 *ebuf = (u16 *)data;
647 /* Crude hack to ensure that we don't overwrite memory
648 * if an odd length is supplied
653 /* ax8817x returns 2 bytes from eeprom on read */
654 for (i=0; i < eeprom->len / 2; i++) {
655 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
656 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
662 static void ax8817x_get_drvinfo (struct net_device *net,
663 struct ethtool_drvinfo *info)
665 /* Inherit standard device info */
666 usbnet_get_drvinfo(net, info);
667 info->eedump_len = 0x3e;
670 static u32 ax8817x_get_link (struct net_device *net)
672 struct usbnet *dev = (struct usbnet *)net->priv;
674 return (u32)mii_link_ok(&dev->mii);
677 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
679 struct usbnet *dev = (struct usbnet *)net->priv;
681 return mii_ethtool_gset(&dev->mii,cmd);
684 static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
686 struct usbnet *dev = (struct usbnet *)net->priv;
688 return mii_ethtool_sset(&dev->mii,cmd);
691 /* We need to override some ethtool_ops so we require our
692 own structure so we don't interfere with other usbnet
693 devices that may be connected at the same time. */
694 static struct ethtool_ops ax8817x_ethtool_ops = {
695 .get_drvinfo = ax8817x_get_drvinfo,
696 .get_link = ax8817x_get_link,
697 .get_msglevel = usbnet_get_msglevel,
698 .set_msglevel = usbnet_set_msglevel,
699 .get_wol = ax8817x_get_wol,
700 .set_wol = ax8817x_set_wol,
701 .get_eeprom = ax8817x_get_eeprom,
702 .get_settings = ax8817x_get_settings,
703 .set_settings = ax8817x_set_settings,
706 static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
710 u16 *buf16 = (u16 *) buf;
712 unsigned long gpio_bits = dev->driver_info->data;
714 dev->in = usb_rcvbulkpipe(dev->udev, 3);
715 dev->out = usb_sndbulkpipe(dev->udev, 2);
717 /* Toggle the GPIOs in a manufacturer/model specific way */
718 for (i = 2; i >= 0; i--) {
719 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
720 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
726 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
727 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
731 /* Get the MAC address */
732 memset(buf, 0, ETH_ALEN);
733 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
734 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
737 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
740 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
741 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
743 } else if (ret < 2) {
744 /* this should always return 2 bytes */
745 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
749 /* Initialize MII structure */
750 dev->mii.dev = dev->net;
751 dev->mii.mdio_read = ax8817x_mdio_read;
752 dev->mii.mdio_write = ax8817x_mdio_write;
753 dev->mii.phy_id_mask = 0x3f;
754 dev->mii.reg_num_mask = 0x1f;
755 dev->mii.phy_id = buf[1];
757 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf)) < 0) {
758 dbg("Failed to go to software MII mode: %02x", ret);
762 *buf16 = cpu_to_le16(BMCR_RESET);
763 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
764 dev->mii.phy_id, MII_BMCR, 2, buf16)) < 0) {
765 dbg("Failed to write MII reg - MII_BMCR: %02x", ret);
769 /* Advertise that we can do full-duplex pause */
770 *buf16 = cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400);
771 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
772 dev->mii.phy_id, MII_ADVERTISE,
774 dbg("Failed to write MII_REG advertisement: %02x", ret);
778 *buf16 = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART);
779 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
780 dev->mii.phy_id, MII_BMCR,
782 dbg("Failed to write MII reg autonegotiate: %02x", ret);
786 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
787 dbg("Failed to set hardware MII: %02x", ret);
791 dev->net->set_multicast_list = ax8817x_set_multicast;
792 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
797 static const struct driver_info ax8817x_info = {
798 .description = "ASIX AX8817x USB 2.0 Ethernet",
799 .bind = ax8817x_bind,
804 static const struct driver_info dlink_dub_e100_info = {
805 .description = "DLink DUB-E100 USB Ethernet",
806 .bind = ax8817x_bind,
811 static const struct driver_info netgear_fa120_info = {
812 .description = "Netgear FA-120 USB Ethernet",
813 .bind = ax8817x_bind,
818 static const struct driver_info hawking_uf200_info = {
819 .description = "Hawking UF200 USB Ethernet",
820 .bind = ax8817x_bind,
825 #endif /* CONFIG_USB_AX8817X */
829 #ifdef CONFIG_USB_BELKIN
830 #define HAVE_HARDWARE
832 /*-------------------------------------------------------------------------
834 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
836 * ... also two eTEK designs, including one sold as "Advance USBNET"
838 *-------------------------------------------------------------------------*/
840 static const struct driver_info belkin_info = {
841 .description = "Belkin, eTEK, or compatible",
844 #endif /* CONFIG_USB_BELKIN */
848 /*-------------------------------------------------------------------------
850 * Communications Device Class declarations.
851 * Used by CDC Ethernet, and some CDC variants
853 *-------------------------------------------------------------------------*/
855 #ifdef CONFIG_USB_CDCETHER
856 #define NEED_GENERIC_CDC
859 #ifdef CONFIG_USB_ZAURUS
860 /* Ethernet variant uses funky framing, broken ethernet addressing */
861 #define NEED_GENERIC_CDC
864 #ifdef CONFIG_USB_RNDIS
865 /* ACM variant uses even funkier framing, complex control RPC scheme */
866 #define NEED_GENERIC_CDC
870 #ifdef NEED_GENERIC_CDC
872 /* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
876 u8 bDescriptorSubType;
879 } __attribute__ ((packed));
881 /* "Union Functional Descriptor" from CDC spec 5.2.3.X */
885 u8 bDescriptorSubType;
887 u8 bMasterInterface0;
889 /* ... and there could be other slave interfaces */
890 } __attribute__ ((packed));
892 /* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
896 u8 bDescriptorSubType;
899 u32 bmEthernetStatistics;
901 u16 wNumberMCFilters;
902 u8 bNumberPowerFilters;
903 } __attribute__ ((packed));
906 struct header_desc *header;
907 struct union_desc *u;
908 struct ether_desc *ether;
909 struct usb_interface *control;
910 struct usb_interface *data;
913 static struct usb_driver usbnet_driver;
916 * probes control interface, claims data interface, collects the bulk
917 * endpoints, activates data interface (if needed), maybe sets MTU.
918 * all pure cdc, except for certain firmware workarounds.
920 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
922 u8 *buf = intf->cur_altsetting->extra;
923 int len = intf->cur_altsetting->extralen;
924 struct usb_interface_descriptor *d;
925 struct cdc_state *info = (void *) &dev->data;
929 if (sizeof dev->data < sizeof *info)
932 /* expect strict spec conformance for the descriptors, but
933 * cope with firmware which stores them in the wrong place
935 if (len == 0 && dev->udev->actconfig->extralen) {
936 /* Motorola SB4100 (and others: Brad Hards says it's
937 * from a Broadcom design) put CDC descriptors here
939 buf = dev->udev->actconfig->extra;
940 len = dev->udev->actconfig->extralen;
943 "CDC descriptors on config\n");
946 /* this assumes that if there's a non-RNDIS vendor variant
947 * of cdc-acm, it'll fail RNDIS requests cleanly.
949 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
951 memset (info, 0, sizeof *info);
952 info->control = intf;
954 if (buf [1] != USB_DT_CS_INTERFACE)
957 /* use bDescriptorSubType to identify the CDC descriptors.
958 * We expect devices with CDC header and union descriptors.
959 * For CDC Ethernet we need the ethernet descriptor.
960 * For RNDIS, ignore two (pointless) CDC modem descriptors
961 * in favor of a complicated OID-based RPC scheme doing what
962 * CDC Ethernet achieves with a simple descriptor.
965 case 0x00: /* Header, mostly useless */
967 dev_dbg (&intf->dev, "extra CDC header\n");
970 info->header = (void *) buf;
971 if (info->header->bLength != sizeof *info->header) {
972 dev_dbg (&intf->dev, "CDC header len %u\n",
973 info->header->bLength);
977 case 0x06: /* Union (groups interfaces) */
979 dev_dbg (&intf->dev, "extra CDC union\n");
982 info->u = (void *) buf;
983 if (info->u->bLength != sizeof *info->u) {
984 dev_dbg (&intf->dev, "CDC union len %u\n",
989 /* we need a master/control interface (what we're
990 * probed with) and a slave/data interface; union
991 * descriptors sort this all out.
993 info->control = usb_ifnum_to_if(dev->udev,
994 info->u->bMasterInterface0);
995 info->data = usb_ifnum_to_if(dev->udev,
996 info->u->bSlaveInterface0);
997 if (!info->control || !info->data) {
999 "master #%u/%p slave #%u/%p\n",
1000 info->u->bMasterInterface0,
1002 info->u->bSlaveInterface0,
1006 if (info->control != intf) {
1007 dev_dbg (&intf->dev, "bogus CDC Union\n");
1008 /* Ambit USB Cable Modem (and maybe others)
1009 * interchanges master and slave interface.
1011 if (info->data == intf) {
1012 info->data = info->control;
1013 info->control = intf;
1018 /* a data interface altsetting does the real i/o */
1019 d = &info->data->cur_altsetting->desc;
1020 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1021 dev_dbg (&intf->dev, "slave class %u\n",
1022 d->bInterfaceClass);
1026 case 0x0F: /* Ethernet Networking */
1028 dev_dbg (&intf->dev, "extra CDC ether\n");
1031 info->ether = (void *) buf;
1032 if (info->ether->bLength != sizeof *info->ether) {
1033 dev_dbg (&intf->dev, "CDC ether len %u\n",
1037 dev->net->mtu = cpu_to_le16p (
1038 &info->ether->wMaxSegmentSize)
1040 /* because of Zaurus, we may be ignoring the host
1041 * side link address we were given.
1046 len -= buf [0]; /* bLength */
1050 if (!info->header || !info->u || (!rndis && !info->ether)) {
1051 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1052 info->header ? "" : "header ",
1053 info->u ? "" : "union ",
1054 info->ether ? "" : "ether ");
1058 /* claim data interface and set it up ... with side effects.
1059 * network traffic can't flow until an altsetting is enabled.
1061 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1064 status = get_endpoints (dev, info->data);
1066 /* ensure immediate exit from usbnet_disconnect */
1067 usb_set_intfdata(info->data, NULL);
1068 usb_driver_release_interface (&usbnet_driver, info->data);
1074 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1078 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1080 struct cdc_state *info = (void *) &dev->data;
1082 /* disconnect master --> disconnect slave */
1083 if (intf == info->control && info->data) {
1084 /* ensure immediate exit from usbnet_disconnect */
1085 usb_set_intfdata(info->data, NULL);
1086 usb_driver_release_interface (&usbnet_driver, info->data);
1090 /* and vice versa (just in case) */
1091 else if (intf == info->data && info->control) {
1092 /* ensure immediate exit from usbnet_disconnect */
1093 usb_set_intfdata(info->control, NULL);
1094 usb_driver_release_interface (&usbnet_driver, info->control);
1099 #endif /* NEED_GENERIC_CDC */
1102 #ifdef CONFIG_USB_CDCETHER
1103 #define HAVE_HARDWARE
1105 /*-------------------------------------------------------------------------
1107 * Communications Device Class, Ethernet Control model
1109 * Takes two interfaces. The DATA interface is inactive till an altsetting
1110 * is selected. Configuration data includes class descriptors.
1112 * This should interop with whatever the 2.4 "CDCEther.c" driver
1113 * (by Brad Hards) talked with.
1115 *-------------------------------------------------------------------------*/
1117 #include <linux/ctype.h>
1119 static u8 nibble (unsigned char c)
1121 if (likely (isdigit (c)))
1124 if (likely (isxdigit (c)))
1125 return 10 + c - 'A';
1130 get_ethernet_addr (struct usbnet *dev, struct ether_desc *e)
1133 unsigned char buf [13];
1135 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1137 dev_dbg (&dev->udev->dev,
1138 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1143 for (i = tmp = 0; i < 6; i++, tmp += 2)
1144 dev->net->dev_addr [i] =
1145 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1149 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1152 struct cdc_state *info = (void *) &dev->data;
1154 status = generic_cdc_bind (dev, intf);
1158 status = get_ethernet_addr (dev, info->ether);
1160 usb_driver_release_interface (&usbnet_driver, info->data);
1164 /* FIXME cdc-ether has some multicast code too, though it complains
1165 * in routine cases. info->ether describes the multicast support.
1170 static const struct driver_info cdc_info = {
1171 .description = "CDC Ethernet Device",
1172 .flags = FLAG_ETHER,
1173 // .check_connect = cdc_check_connect,
1175 .unbind = cdc_unbind,
1178 #endif /* CONFIG_USB_CDCETHER */
1182 #ifdef CONFIG_USB_EPSON2888
1183 #define HAVE_HARDWARE
1185 /*-------------------------------------------------------------------------
1189 * This is the same idea as Linux PDAs (below) except the firmware in the
1190 * device might not be Tux-powered. Epson provides reference firmware that
1191 * implements this interface. Product developers can reuse or modify that
1192 * code, such as by using their own product and vendor codes.
1194 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1196 *-------------------------------------------------------------------------*/
1198 static const struct driver_info epson2888_info = {
1199 .description = "Epson USB Device",
1200 .check_connect = always_connected,
1205 #endif /* CONFIG_USB_EPSON2888 */
1208 #ifdef CONFIG_USB_GENESYS
1209 #define HAVE_HARDWARE
1211 /*-------------------------------------------------------------------------
1213 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1215 * ... should partially interop with the Win32 driver for this hardware
1216 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1218 * Some info from GeneSys:
1219 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1220 * (Some cables, like the BAFO-100c, use the half duplex version.)
1221 * - For the full duplex model, the low bit of the version code says
1222 * which side is which ("left/right").
1223 * - For the half duplex type, a control/interrupt handshake settles
1224 * the transfer direction. (That's disabled here, partially coded.)
1225 * A control URB would block until other side writes an interrupt.
1227 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1228 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1230 *-------------------------------------------------------------------------*/
1232 // control msg write command
1233 #define GENELINK_CONNECT_WRITE 0xF0
1234 // interrupt pipe index
1235 #define GENELINK_INTERRUPT_PIPE 0x03
1236 // interrupt read buffer size
1237 #define INTERRUPT_BUFSIZE 0x08
1238 // interrupt pipe interval value
1239 #define GENELINK_INTERRUPT_INTERVAL 0x10
1240 // max transmit packet number per transmit
1241 #define GL_MAX_TRANSMIT_PACKETS 32
1242 // max packet length
1243 #define GL_MAX_PACKET_LEN 1514
1244 // max receive buffer size
1245 #define GL_RCV_BUF_SIZE \
1246 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1250 char packet_data [1];
1255 struct gl_packet packets;
1260 // FIXME: this code is incomplete, not debugged; it doesn't
1261 // handle interrupts correctly. interrupts should be generic
1262 // code like all other device I/O, anyway.
1265 struct urb *irq_urb;
1266 char irq_buf [INTERRUPT_BUFSIZE];
1269 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1273 retval = usb_control_msg (dev->udev,
1274 usb_sndctrlpipe (dev->udev, 0),
1276 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1281 CONTROL_TIMEOUT_JIFFIES);
1285 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1287 int status = urb->status;
1296 /* this urb is terminated, clean up */
1297 dbg("%s - urb shutting down with status: %d",
1298 __FUNCTION__, status);
1301 dbg("%s - nonzero urb status received: %d",
1302 __FUNCTION__, urb->status);
1305 status = usb_submit_urb (urb, GFP_ATOMIC);
1307 err ("%s - usb_submit_urb failed with result %d",
1308 __FUNCTION__, status);
1311 static int gl_interrupt_read (struct usbnet *dev)
1313 struct gl_priv *priv = dev->priv_data;
1316 // issue usb interrupt read
1317 if (priv && priv->irq_urb) {
1319 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1320 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1322 dbg ("gl_interrupt_read: submit success...");
1328 // check whether another side is connected
1329 static int genelink_check_connect (struct usbnet *dev)
1333 dbg ("genelink_check_connect...");
1335 // detect whether another side is connected
1336 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1337 dbg ("%s: genelink_check_connect write fail - %X",
1338 dev->net->name, retval);
1342 // usb interrupt read to ack another side
1343 if ((retval = gl_interrupt_read (dev)) != 0) {
1344 dbg ("%s: genelink_check_connect read fail - %X",
1345 dev->net->name, retval);
1349 dbg ("%s: genelink_check_connect read success", dev->net->name);
1353 // allocate and initialize the private data for genelink
1354 static int genelink_init (struct usbnet *dev)
1356 struct gl_priv *priv;
1358 // allocate the private data structure
1359 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1360 dbg ("%s: cannot allocate private data per device",
1366 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1367 dbg ("%s: cannot allocate private irq urb per device",
1374 usb_fill_int_urb (priv->irq_urb, dev->udev,
1375 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1376 priv->irq_buf, INTERRUPT_BUFSIZE,
1377 gl_interrupt_complete, 0,
1378 GENELINK_INTERRUPT_INTERVAL);
1380 // set private data pointer
1381 dev->priv_data = priv;
1386 // release the private data
1387 static int genelink_free (struct usbnet *dev)
1389 struct gl_priv *priv = dev->priv_data;
1394 // FIXME: can't cancel here; it's synchronous, and
1395 // should have happened earlier in any case (interrupt
1396 // handling needs to be generic)
1398 // cancel irq urb first
1399 usb_unlink_urb (priv->irq_urb);
1402 usb_free_urb (priv->irq_urb);
1404 // free the private data structure
1412 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1414 struct gl_header *header;
1415 struct gl_packet *packet;
1416 struct sk_buff *gl_skb;
1419 header = (struct gl_header *) skb->data;
1421 // get the packet count of the received skb
1422 le32_to_cpus (&header->packet_count);
1423 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1424 || (header->packet_count < 0)) {
1425 dbg ("genelink: invalid received packet count %d",
1426 header->packet_count);
1430 // set the current packet pointer to the first packet
1431 packet = &header->packets;
1433 // decrement the length for the packet count size 4 bytes
1436 while (header->packet_count > 1) {
1437 // get the packet length
1438 size = packet->packet_length;
1440 // this may be a broken packet
1441 if (size > GL_MAX_PACKET_LEN) {
1442 dbg ("genelink: invalid rx length %d", size);
1446 // allocate the skb for the individual packet
1447 gl_skb = alloc_skb (size, GFP_ATOMIC);
1450 // copy the packet data to the new skb
1451 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1452 skb_return (dev, skb);
1455 // advance to the next packet
1456 packet = (struct gl_packet *)
1457 &packet->packet_data [size];
1458 header->packet_count--;
1460 // shift the data pointer to the next gl_packet
1461 skb_pull (skb, size + 4);
1464 // skip the packet length field 4 bytes
1467 if (skb->len > GL_MAX_PACKET_LEN) {
1468 dbg ("genelink: invalid rx length %d", skb->len);
1474 static struct sk_buff *
1475 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1478 int length = skb->len;
1479 int headroom = skb_headroom (skb);
1480 int tailroom = skb_tailroom (skb);
1484 // FIXME: magic numbers, bleech
1485 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1487 if ((!skb_cloned (skb))
1488 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1489 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1490 skb->data = memmove (skb->head + (4 + 4*1),
1491 skb->data, skb->len);
1492 skb->tail = skb->data + skb->len;
1495 struct sk_buff *skb2;
1496 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1497 dev_kfree_skb_any (skb);
1503 // attach the packet count to the header
1504 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1505 packet_len = packet_count + 1;
1507 // FIXME little endian?
1509 *packet_len = length;
1512 if ((skb->len % dev->maxpacket) == 0)
1518 static const struct driver_info genelink_info = {
1519 .description = "Genesys GeneLink",
1520 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1521 .rx_fixup = genelink_rx_fixup,
1522 .tx_fixup = genelink_tx_fixup,
1527 .check_connect =genelink_check_connect,
1531 #endif /* CONFIG_USB_GENESYS */
1535 #ifdef CONFIG_USB_NET1080
1536 #define HAVE_HARDWARE
1538 /*-------------------------------------------------------------------------
1540 * Netchip 1080 driver ... http://www.netchip.com
1541 * Used in LapLink cables
1543 *-------------------------------------------------------------------------*/
1545 #define dev_packet_id data[0]
1546 #define frame_errors data[1]
1549 * NetChip framing of ethernet packets, supporting additional error
1550 * checks for links that may drop bulk packets from inside messages.
1551 * Odd USB length == always short read for last usb packet.
1553 * - Ethernet header (14 bytes)
1555 * - (optional padding byte, if needed so length becomes odd)
1558 * This framing is to be avoided for non-NetChip devices.
1561 struct nc_header { // packed:
1562 u16 hdr_len; // sizeof nc_header (LE, all)
1563 u16 packet_len; // payload size (including ethhdr)
1564 u16 packet_id; // detects dropped packets
1565 #define MIN_HEADER 6
1567 // all else is optional, and must start with:
1568 // u16 vendorId; // from usb-if
1570 } __attribute__((__packed__));
1572 #define PAD_BYTE ((unsigned char)0xAC)
1576 } __attribute__((__packed__));
1578 // packets may use FLAG_FRAMING_NC and optional pad
1579 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1580 + sizeof (struct ethhdr) \
1583 + sizeof (struct nc_trailer))
1585 #define MIN_FRAMED FRAMED_SIZE(0)
1589 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1590 * before the hardware drops it. If that's done, the driver will need to
1591 * frame network packets to guard against the dropped USB packets. The win32
1592 * driver sets this for both sides of the link.
1594 #define NC_READ_TTL_MS ((u8)255) // ms
1597 * We ignore most registers and EEPROM contents.
1599 #define REG_USBCTL ((u8)0x04)
1600 #define REG_TTL ((u8)0x10)
1601 #define REG_STATUS ((u8)0x11)
1604 * Vendor specific requests to read/write data
1606 #define REQUEST_REGISTER ((u8)0x10)
1607 #define REQUEST_EEPROM ((u8)0x11)
1610 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1612 int status = usb_control_msg (dev->udev,
1613 usb_rcvctrlpipe (dev->udev, 0),
1615 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1617 retval_ptr, sizeof *retval_ptr,
1618 CONTROL_TIMEOUT_JIFFIES);
1622 le16_to_cpus (retval_ptr);
1627 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1629 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1632 // no retval ... can become async, usable in_interrupt()
1634 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1636 usb_control_msg (dev->udev,
1637 usb_sndctrlpipe (dev->udev, 0),
1639 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1641 0, 0, // data is in setup packet
1642 CONTROL_TIMEOUT_JIFFIES);
1646 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1648 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1653 static void nc_dump_registers (struct usbnet *dev)
1656 u16 *vp = kmalloc (sizeof (u16));
1663 dbg ("%s registers:", dev->net->name);
1664 for (reg = 0; reg < 0x20; reg++) {
1667 // reading some registers is trouble
1668 if (reg >= 0x08 && reg <= 0xf)
1670 if (reg >= 0x12 && reg <= 0x1e)
1673 retval = nc_register_read (dev, reg, vp);
1675 dbg ("%s reg [0x%x] ==> error %d",
1676 dev->net->name, reg, retval);
1678 dbg ("%s reg [0x%x] = 0x%x",
1679 dev->net->name, reg, *vp);
1686 /*-------------------------------------------------------------------------*/
1692 #define USBCTL_WRITABLE_MASK 0x1f0f
1693 // bits 15-13 reserved, r/o
1694 #define USBCTL_ENABLE_LANG (1 << 12)
1695 #define USBCTL_ENABLE_MFGR (1 << 11)
1696 #define USBCTL_ENABLE_PROD (1 << 10)
1697 #define USBCTL_ENABLE_SERIAL (1 << 9)
1698 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1699 // bits 7-4 reserved, r/o
1700 #define USBCTL_FLUSH_OTHER (1 << 3)
1701 #define USBCTL_FLUSH_THIS (1 << 2)
1702 #define USBCTL_DISCONN_OTHER (1 << 1)
1703 #define USBCTL_DISCONN_THIS (1 << 0)
1705 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1708 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1710 " other%s%s; r/o 0x%x",
1711 dev->udev->bus->bus_name, dev->udev->devpath,
1713 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1714 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1715 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1716 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1717 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1719 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1720 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1721 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1722 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1723 usbctl & ~USBCTL_WRITABLE_MASK
1728 /*-------------------------------------------------------------------------*/
1734 #define STATUS_PORT_A (1 << 15)
1736 #define STATUS_CONN_OTHER (1 << 14)
1737 #define STATUS_SUSPEND_OTHER (1 << 13)
1738 #define STATUS_MAILBOX_OTHER (1 << 12)
1739 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1741 #define STATUS_CONN_THIS (1 << 6)
1742 #define STATUS_SUSPEND_THIS (1 << 5)
1743 #define STATUS_MAILBOX_THIS (1 << 4)
1744 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1746 #define STATUS_UNSPEC_MASK 0x0c8c
1747 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1750 static inline void nc_dump_status (struct usbnet *dev, u16 status)
1753 devdbg (dev, "net1080 %s-%s status 0x%x:"
1754 " this (%c) PKT=%d%s%s%s;"
1755 " other PKT=%d%s%s%s; unspec 0x%x",
1756 dev->udev->bus->bus_name, dev->udev->devpath,
1759 // XXX the packet counts don't seem right
1760 // (1 at reset, not 0); maybe UNSPEC too
1762 (status & STATUS_PORT_A) ? 'A' : 'B',
1763 STATUS_PACKETS_THIS (status),
1764 (status & STATUS_CONN_THIS) ? " CON" : "",
1765 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1766 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1768 STATUS_PACKETS_OTHER (status),
1769 (status & STATUS_CONN_OTHER) ? " CON" : "",
1770 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1771 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1773 status & STATUS_UNSPEC_MASK
1778 /*-------------------------------------------------------------------------*/
1784 #define TTL_THIS(ttl) (0x00ff & ttl)
1785 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1786 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1788 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1791 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1792 dev->udev->bus->bus_name, dev->udev->devpath,
1801 /*-------------------------------------------------------------------------*/
1803 static int net1080_reset (struct usbnet *dev)
1805 u16 usbctl, status, ttl;
1806 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1812 // nc_dump_registers (dev);
1814 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1815 dbg ("can't read %s-%s status: %d",
1816 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1820 // nc_dump_status (dev, status);
1822 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1823 dbg ("can't read USBCTL, %d", retval);
1827 // nc_dump_usbctl (dev, usbctl);
1829 nc_register_write (dev, REG_USBCTL,
1830 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1832 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1833 dbg ("can't read TTL, %d", retval);
1837 // nc_dump_ttl (dev, ttl);
1839 nc_register_write (dev, REG_TTL,
1840 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1841 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
1843 if (dev->msg_level >= 2)
1844 devinfo (dev, "port %c, peer %sconnected",
1845 (status & STATUS_PORT_A) ? 'A' : 'B',
1846 (status & STATUS_CONN_OTHER) ? "" : "dis"
1855 static int net1080_check_connect (struct usbnet *dev)
1859 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1863 retval = nc_register_read (dev, REG_STATUS, vp);
1867 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
1870 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1875 static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
1877 kfree (urb->context);
1881 static void nc_ensure_sync (struct usbnet *dev)
1883 dev->frame_errors++;
1884 if (dev->frame_errors > 5) {
1886 struct usb_ctrlrequest *req;
1890 urb = usb_alloc_urb (0, SLAB_ATOMIC);
1894 req = kmalloc (sizeof *req, GFP_ATOMIC);
1900 req->bRequestType = USB_DIR_OUT
1903 req->bRequest = REQUEST_REGISTER;
1904 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
1905 | USBCTL_FLUSH_OTHER);
1906 req->wIndex = cpu_to_le16 (REG_USBCTL);
1907 req->wLength = cpu_to_le16 (0);
1909 /* queue an async control request, we don't need
1910 * to do anything when it finishes except clean up.
1912 usb_fill_control_urb (urb, dev->udev,
1913 usb_sndctrlpipe (dev->udev, 0),
1914 (unsigned char *) req,
1916 nc_flush_complete, req);
1917 status = usb_submit_urb (urb, GFP_ATOMIC);
1924 devdbg (dev, "flush net1080; too many framing errors");
1925 dev->frame_errors = 0;
1929 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1931 struct nc_header *header;
1932 struct nc_trailer *trailer;
1934 if (!(skb->len & 0x01)
1935 || MIN_FRAMED > skb->len
1936 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
1937 dev->stats.rx_frame_errors++;
1938 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1939 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
1941 nc_ensure_sync (dev);
1945 header = (struct nc_header *) skb->data;
1946 le16_to_cpus (&header->hdr_len);
1947 le16_to_cpus (&header->packet_len);
1948 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1949 dev->stats.rx_frame_errors++;
1950 dbg ("packet too big, %d", header->packet_len);
1951 nc_ensure_sync (dev);
1953 } else if (header->hdr_len < MIN_HEADER) {
1954 dev->stats.rx_frame_errors++;
1955 dbg ("header too short, %d", header->hdr_len);
1956 nc_ensure_sync (dev);
1958 } else if (header->hdr_len > MIN_HEADER) {
1959 // out of band data for us?
1960 dbg ("header OOB, %d bytes",
1961 header->hdr_len - MIN_HEADER);
1962 nc_ensure_sync (dev);
1963 // switch (vendor/product ids) { ... }
1965 skb_pull (skb, header->hdr_len);
1967 trailer = (struct nc_trailer *)
1968 (skb->data + skb->len - sizeof *trailer);
1969 skb_trim (skb, skb->len - sizeof *trailer);
1971 if ((header->packet_len & 0x01) == 0) {
1972 if (skb->data [header->packet_len] != PAD_BYTE) {
1973 dev->stats.rx_frame_errors++;
1977 skb_trim (skb, skb->len - 1);
1979 if (skb->len != header->packet_len) {
1980 dev->stats.rx_frame_errors++;
1981 dbg ("bad packet len %d (expected %d)",
1982 skb->len, header->packet_len);
1983 nc_ensure_sync (dev);
1986 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
1987 dev->stats.rx_fifo_errors++;
1988 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
1989 header->packet_id, trailer->packet_id);
1993 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
1994 header->packet_len, header->packet_id);
1996 dev->frame_errors = 0;
2000 static struct sk_buff *
2001 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2004 struct sk_buff *skb2;
2006 padlen = ((skb->len + sizeof (struct nc_header)
2007 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2008 if (!skb_cloned (skb)) {
2009 int headroom = skb_headroom (skb);
2010 int tailroom = skb_tailroom (skb);
2012 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2013 && sizeof (struct nc_header) <= headroom)
2014 /* There's enough head and tail room */
2017 if ((sizeof (struct nc_header) + padlen
2018 + sizeof (struct nc_trailer)) <
2019 (headroom + tailroom)) {
2020 /* There's enough total room, so just readjust */
2021 skb->data = memmove (skb->head
2022 + sizeof (struct nc_header),
2023 skb->data, skb->len);
2024 skb->tail = skb->data + skb->len;
2029 /* Create a new skb to use with the correct size */
2030 skb2 = skb_copy_expand (skb,
2031 sizeof (struct nc_header),
2032 sizeof (struct nc_trailer) + padlen,
2034 dev_kfree_skb_any (skb);
2038 static const struct driver_info net1080_info = {
2039 .description = "NetChip TurboCONNECT",
2040 .flags = FLAG_FRAMING_NC,
2041 .reset = net1080_reset,
2042 .check_connect =net1080_check_connect,
2043 .rx_fixup = net1080_rx_fixup,
2044 .tx_fixup = net1080_tx_fixup,
2047 #endif /* CONFIG_USB_NET1080 */
2051 #ifdef CONFIG_USB_PL2301
2052 #define HAVE_HARDWARE
2054 /*-------------------------------------------------------------------------
2056 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2058 * The protocol and handshaking used here should be bug-compatible
2059 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2061 *-------------------------------------------------------------------------*/
2064 * Bits 0-4 can be used for software handshaking; they're set from
2065 * one end, cleared from the other, "read" with the interrupt byte.
2067 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2068 /* reserved bit -- rx ready (6) ? */
2069 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2070 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2071 #define PL_RESET_IN (1<<3) /* reset input pipe */
2072 #define PL_TX_C (1<<2) /* transmission complete */
2073 #define PL_TX_REQ (1<<1) /* transmission received */
2074 #define PL_PEER_E (1<<0) /* peer exists */
2077 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2079 return usb_control_msg (dev->udev,
2080 usb_rcvctrlpipe (dev->udev, 0),
2082 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2085 CONTROL_TIMEOUT_JIFFIES);
2089 pl_clear_QuickLink_features (struct usbnet *dev, int val)
2091 return pl_vendor_req (dev, 1, (u8) val, 0);
2095 pl_set_QuickLink_features (struct usbnet *dev, int val)
2097 return pl_vendor_req (dev, 3, (u8) val, 0);
2100 /*-------------------------------------------------------------------------*/
2102 static int pl_reset (struct usbnet *dev)
2104 /* some units seem to need this reset, others reject it utterly.
2105 * FIXME be more like "naplink" or windows drivers.
2107 (void) pl_set_QuickLink_features (dev,
2108 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2112 static const struct driver_info prolific_info = {
2113 .description = "Prolific PL-2301/PL-2302",
2114 .flags = FLAG_NO_SETINT,
2115 /* some PL-2302 versions seem to fail usb_set_interface() */
2119 #endif /* CONFIG_USB_PL2301 */
2123 #ifdef CONFIG_USB_ARMLINUX
2124 #define HAVE_HARDWARE
2126 /*-------------------------------------------------------------------------
2128 * Intel's SA-1100 chip integrates basic USB support, and is used
2129 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2130 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2131 * network using minimal USB framing data.
2133 * This describes the driver currently in standard ARM Linux kernels.
2134 * The Zaurus uses a different driver (see later).
2136 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2137 * and different USB endpoint numbering than the SA1100 devices. The
2138 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2139 * so we rely on the endpoint descriptors.
2141 *-------------------------------------------------------------------------*/
2143 static const struct driver_info linuxdev_info = {
2144 .description = "Linux Device",
2145 .check_connect = always_connected,
2148 static const struct driver_info yopy_info = {
2149 .description = "Yopy",
2150 .check_connect = always_connected,
2153 static const struct driver_info blob_info = {
2154 .description = "Boot Loader OBject",
2155 .check_connect = always_connected,
2158 #endif /* CONFIG_USB_ARMLINUX */
2161 #ifdef CONFIG_USB_ZAURUS
2162 #define HAVE_HARDWARE
2164 #include <linux/crc32.h>
2166 /*-------------------------------------------------------------------------
2168 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2169 * (and framing) for its USB slave/gadget controller than the case above.
2171 * For the current version of that driver, the main way that framing is
2172 * nonstandard (also from perspective of the CDC ethernet model!) is a
2173 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2174 * haven't been fully worked around.
2176 * PXA based models use the same framing, and also can't implement
2177 * set_interface properly.
2179 *-------------------------------------------------------------------------*/
2181 static struct sk_buff *
2182 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2185 struct sk_buff *skb2;
2188 if (!skb_cloned (skb)) {
2189 int tailroom = skb_tailroom (skb);
2190 if ((padlen + 4) <= tailroom)
2193 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2194 dev_kfree_skb_any (skb);
2199 fcs = crc32_le (~0, skb->data, skb->len);
2202 *skb_put (skb, 1) = fcs & 0xff;
2203 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2204 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2205 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2210 static const struct driver_info zaurus_sl5x00_info = {
2211 .description = "Sharp Zaurus SL-5x00",
2212 .flags = FLAG_FRAMING_Z,
2213 .check_connect = always_connected,
2214 .bind = generic_cdc_bind,
2215 .unbind = cdc_unbind,
2216 .tx_fixup = zaurus_tx_fixup,
2218 static const struct driver_info zaurus_pxa_info = {
2219 .description = "Sharp Zaurus, PXA-2xx based",
2220 .flags = FLAG_FRAMING_Z,
2221 .check_connect = always_connected,
2222 .tx_fixup = zaurus_tx_fixup,
2230 /*-------------------------------------------------------------------------
2232 * Network Device Driver (peer link to "Host Device", from USB host)
2234 *-------------------------------------------------------------------------*/
2236 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2238 struct usbnet *dev = (struct usbnet *) net->priv;
2240 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2242 #ifdef CONFIG_USB_NET1080
2243 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2244 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2248 #ifdef CONFIG_USB_GENESYS
2249 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2250 && new_mtu > GL_MAX_PACKET_LEN)
2253 // no second zero-length packet read wanted after mtu-sized packets
2254 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2260 /*-------------------------------------------------------------------------*/
2262 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2264 return &((struct usbnet *) net->priv)->stats;
2267 /*-------------------------------------------------------------------------*/
2269 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2270 * completion callbacks. 2.5 should have fixed those bugs...
2273 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2275 struct sk_buff_head *list = skb->list;
2276 unsigned long flags;
2278 spin_lock_irqsave (&list->lock, flags);
2279 __skb_unlink (skb, list);
2280 spin_unlock (&list->lock);
2281 spin_lock (&dev->done.lock);
2282 __skb_queue_tail (&dev->done, skb);
2283 if (dev->done.qlen == 1)
2284 tasklet_schedule (&dev->bh);
2285 spin_unlock_irqrestore (&dev->done.lock, flags);
2288 /* some work can't be done in tasklets, so we use keventd
2290 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2291 * but tasklet_schedule() doesn't. hope the failure is rare.
2293 static void defer_kevent (struct usbnet *dev, int work)
2295 set_bit (work, &dev->flags);
2296 if (!schedule_work (&dev->kevent))
2297 deverr (dev, "kevent %d may have been dropped", work);
2299 devdbg (dev, "kevent %d scheduled", work);
2302 /*-------------------------------------------------------------------------*/
2304 static void rx_complete (struct urb *urb, struct pt_regs *regs);
2306 static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2308 struct sk_buff *skb;
2309 struct skb_data *entry;
2311 unsigned long lockflags;
2314 #ifdef CONFIG_USB_NET1080
2315 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2316 size = FRAMED_SIZE (dev->net->mtu);
2319 #ifdef CONFIG_USB_GENESYS
2320 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2321 size = GL_RCV_BUF_SIZE;
2324 #ifdef CONFIG_USB_ZAURUS
2325 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2326 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2329 #ifdef CONFIG_USB_RNDIS
2330 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2331 size = RNDIS_MAX_TRANSFER;
2334 size = (sizeof (struct ethhdr) + dev->net->mtu);
2336 if ((skb = alloc_skb (size, flags)) == 0) {
2337 devdbg (dev, "no rx skb");
2338 defer_kevent (dev, EVENT_RX_MEMORY);
2343 entry = (struct skb_data *) skb->cb;
2346 entry->state = rx_start;
2349 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2350 skb->data, size, rx_complete, skb);
2351 urb->transfer_flags |= URB_ASYNC_UNLINK;
2353 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2355 if (netif_running (dev->net)
2356 && netif_device_present (dev->net)
2357 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2358 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2360 defer_kevent (dev, EVENT_RX_HALT);
2363 defer_kevent (dev, EVENT_RX_MEMORY);
2366 devdbg (dev, "device gone");
2367 netif_device_detach (dev->net);
2370 devdbg (dev, "rx submit, %d", retval);
2371 tasklet_schedule (&dev->bh);
2374 __skb_queue_tail (&dev->rxq, skb);
2377 devdbg (dev, "rx: stopped");
2380 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2382 dev_kfree_skb_any (skb);
2388 /*-------------------------------------------------------------------------*/
2390 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2392 if (dev->driver_info->rx_fixup
2393 && !dev->driver_info->rx_fixup (dev, skb))
2395 // else network stack removes extra byte if we forced a short packet
2398 skb_return (dev, skb);
2400 devdbg (dev, "drop");
2402 dev->stats.rx_errors++;
2403 skb_queue_tail (&dev->done, skb);
2407 /*-------------------------------------------------------------------------*/
2409 static void rx_complete (struct urb *urb, struct pt_regs *regs)
2411 struct sk_buff *skb = (struct sk_buff *) urb->context;
2412 struct skb_data *entry = (struct skb_data *) skb->cb;
2413 struct usbnet *dev = entry->dev;
2414 int urb_status = urb->status;
2416 skb_put (skb, urb->actual_length);
2417 entry->state = rx_done;
2420 switch (urb_status) {
2423 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2424 entry->state = rx_cleanup;
2425 dev->stats.rx_errors++;
2426 dev->stats.rx_length_errors++;
2427 devdbg (dev, "rx length %d", skb->len);
2431 // stalls need manual reset. this is rare ... except that
2432 // when going through USB 2.0 TTs, unplug appears this way.
2433 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2434 // storm, recovering as needed.
2436 dev->stats.rx_errors++;
2437 defer_kevent (dev, EVENT_RX_HALT);
2440 // software-driven interface shutdown
2441 case -ECONNRESET: // async unlink
2442 case -ESHUTDOWN: // hardware gone
2444 devdbg (dev, "rx shutdown, code %d", urb_status);
2448 // we get controller i/o faults during khubd disconnect() delays.
2449 // throttle down resubmits, to avoid log floods; just temporarily,
2450 // so we still recover when the fault isn't a khubd delay.
2451 case -EPROTO: // ehci
2452 case -ETIMEDOUT: // ohci
2453 case -EILSEQ: // uhci
2454 dev->stats.rx_errors++;
2455 if (!timer_pending (&dev->delay)) {
2456 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2457 devdbg (dev, "rx throttle %d", urb_status);
2460 entry->state = rx_cleanup;
2465 // data overrun ... flush fifo?
2467 dev->stats.rx_over_errors++;
2471 entry->state = rx_cleanup;
2472 dev->stats.rx_errors++;
2473 devdbg (dev, "rx status %d", urb_status);
2477 defer_bh (dev, skb);
2480 if (netif_running (dev->net)
2481 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2482 rx_submit (dev, urb, GFP_ATOMIC);
2488 devdbg (dev, "no read resubmitted");
2489 #endif /* VERBOSE */
2492 /*-------------------------------------------------------------------------*/
2494 // unlink pending rx/tx; completion handlers do all other cleanup
2496 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2498 unsigned long flags;
2499 struct sk_buff *skb, *skbnext;
2502 spin_lock_irqsave (&q->lock, flags);
2503 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2504 struct skb_data *entry;
2508 entry = (struct skb_data *) skb->cb;
2510 skbnext = skb->next;
2512 // during some PM-driven resume scenarios,
2513 // these (async) unlinks complete immediately
2514 retval = usb_unlink_urb (urb);
2515 if (retval != -EINPROGRESS && retval != 0)
2516 devdbg (dev, "unlink urb err, %d", retval);
2520 spin_unlock_irqrestore (&q->lock, flags);
2525 /*-------------------------------------------------------------------------*/
2527 // precondition: never called in_interrupt
2529 static int usbnet_stop (struct net_device *net)
2531 struct usbnet *dev = (struct usbnet *) net->priv;
2533 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2534 DECLARE_WAITQUEUE (wait, current);
2536 netif_stop_queue (net);
2538 if (dev->msg_level >= 2)
2539 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2540 dev->stats.rx_packets, dev->stats.tx_packets,
2541 dev->stats.rx_errors, dev->stats.tx_errors
2544 // ensure there are no more active urbs
2545 add_wait_queue (&unlink_wakeup, &wait);
2546 dev->wait = &unlink_wakeup;
2547 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2549 // maybe wait for deletions to finish.
2550 while (skb_queue_len (&dev->rxq)
2551 && skb_queue_len (&dev->txq)
2552 && skb_queue_len (&dev->done)) {
2553 set_current_state (TASK_UNINTERRUPTIBLE);
2554 schedule_timeout (UNLINK_TIMEOUT_JIFFIES);
2555 devdbg (dev, "waited for %d urb completions", temp);
2558 remove_wait_queue (&unlink_wakeup, &wait);
2560 /* deferred work (task, timer, softirq) must also stop.
2561 * can't flush_scheduled_work() until we drop rtnl (later),
2562 * else workers could deadlock; so make workers a NOP.
2565 del_timer_sync (&dev->delay);
2566 tasklet_kill (&dev->bh);
2571 /*-------------------------------------------------------------------------*/
2573 // posts reads, and enables write queuing
2575 // precondition: never called in_interrupt
2577 static int usbnet_open (struct net_device *net)
2579 struct usbnet *dev = (struct usbnet *) net->priv;
2581 struct driver_info *info = dev->driver_info;
2583 // put into "known safe" state
2584 if (info->reset && (retval = info->reset (dev)) < 0) {
2585 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2587 dev->udev->bus->bus_name, dev->udev->devpath,
2592 // insist peer be connected
2593 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2594 devdbg (dev, "can't open; %d", retval);
2598 netif_start_queue (net);
2599 if (dev->msg_level >= 2) {
2602 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2603 framing = "NetChip";
2604 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
2605 framing = "GeneSys";
2606 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
2608 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
2613 devinfo (dev, "open: enable queueing "
2614 "(rx %d, tx %d) mtu %d %s framing",
2615 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
2619 // delay posting reads until we're fully open
2620 tasklet_schedule (&dev->bh);
2625 /*-------------------------------------------------------------------------*/
2627 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2629 struct usbnet *dev = net->priv;
2631 strncpy (info->driver, driver_name, sizeof info->driver);
2632 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2633 strncpy (info->fw_version, dev->driver_info->description,
2634 sizeof info->fw_version);
2635 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2638 static u32 usbnet_get_link (struct net_device *net)
2640 struct usbnet *dev = net->priv;
2642 /* If a check_connect is defined, return it's results */
2643 if (dev->driver_info->check_connect)
2644 return dev->driver_info->check_connect (dev) == 0;
2646 /* Otherwise, we're up to avoid breaking scripts */
2650 static u32 usbnet_get_msglevel (struct net_device *net)
2652 struct usbnet *dev = net->priv;
2654 return dev->msg_level;
2657 static void usbnet_set_msglevel (struct net_device *net, u32 level)
2659 struct usbnet *dev = net->priv;
2661 dev->msg_level = level;
2664 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2668 struct usbnet *dev = (struct usbnet *)net->priv;
2670 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2671 return generic_mii_ioctl(&dev->mii,
2672 (struct mii_ioctl_data *) &rq->ifr_data,
2679 /*-------------------------------------------------------------------------*/
2681 /* work that cannot be done in interrupt context uses keventd.
2683 * NOTE: with 2.5 we could do more of this using completion callbacks,
2684 * especially now that control transfers can be queued.
2689 struct usbnet *dev = data;
2692 /* usb_clear_halt() needs a thread context */
2693 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2694 unlink_urbs (dev, &dev->txq);
2695 status = usb_clear_halt (dev->udev, dev->out);
2697 deverr (dev, "can't clear tx halt, status %d",
2700 clear_bit (EVENT_TX_HALT, &dev->flags);
2701 netif_wake_queue (dev->net);
2704 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2705 unlink_urbs (dev, &dev->rxq);
2706 status = usb_clear_halt (dev->udev, dev->in);
2708 deverr (dev, "can't clear rx halt, status %d",
2711 clear_bit (EVENT_RX_HALT, &dev->flags);
2712 tasklet_schedule (&dev->bh);
2716 /* tasklet could resubmit itself forever if memory is tight */
2717 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2718 struct urb *urb = 0;
2720 if (netif_running (dev->net))
2721 urb = usb_alloc_urb (0, GFP_KERNEL);
2723 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2725 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2726 rx_submit (dev, urb, GFP_KERNEL);
2727 tasklet_schedule (&dev->bh);
2732 devdbg (dev, "kevent done, flags = 0x%lx",
2736 /*-------------------------------------------------------------------------*/
2738 static void tx_complete (struct urb *urb, struct pt_regs *regs)
2740 struct sk_buff *skb = (struct sk_buff *) urb->context;
2741 struct skb_data *entry = (struct skb_data *) skb->cb;
2742 struct usbnet *dev = entry->dev;
2744 if (urb->status == 0) {
2745 dev->stats.tx_packets++;
2746 dev->stats.tx_bytes += entry->length;
2748 dev->stats.tx_errors++;
2750 switch (urb->status) {
2752 defer_kevent (dev, EVENT_TX_HALT);
2755 // like rx, tx gets controller i/o faults during khubd delays
2756 // and so it uses the same throttling mechanism.
2757 case -EPROTO: // ehci
2758 case -ETIMEDOUT: // ohci
2759 case -EILSEQ: // uhci
2760 if (!timer_pending (&dev->delay)) {
2761 mod_timer (&dev->delay,
2762 jiffies + THROTTLE_JIFFIES);
2763 devdbg (dev, "tx throttle %d", urb->status);
2765 netif_stop_queue (dev->net);
2768 devdbg (dev, "tx err %d", entry->urb->status);
2774 entry->state = tx_done;
2775 defer_bh (dev, skb);
2778 /*-------------------------------------------------------------------------*/
2780 static void usbnet_tx_timeout (struct net_device *net)
2782 struct usbnet *dev = (struct usbnet *) net->priv;
2784 unlink_urbs (dev, &dev->txq);
2785 tasklet_schedule (&dev->bh);
2787 // FIXME: device recovery -- reset?
2790 /*-------------------------------------------------------------------------*/
2792 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2794 struct usbnet *dev = (struct usbnet *) net->priv;
2796 int retval = NET_XMIT_SUCCESS;
2797 struct urb *urb = 0;
2798 struct skb_data *entry;
2799 struct driver_info *info = dev->driver_info;
2800 unsigned long flags;
2801 #ifdef CONFIG_USB_NET1080
2802 struct nc_header *header = 0;
2803 struct nc_trailer *trailer = 0;
2804 #endif /* CONFIG_USB_NET1080 */
2806 // some devices want funky USB-level framing, for
2807 // win32 driver (usually) and/or hardware quirks
2808 if (info->tx_fixup) {
2809 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2811 devdbg (dev, "can't tx_fixup skb");
2817 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
2818 devdbg (dev, "no urb");
2822 entry = (struct skb_data *) skb->cb;
2825 entry->state = tx_start;
2826 entry->length = length;
2828 // FIXME: reorganize a bit, so that fixup() fills out NetChip
2829 // framing too. (Packet ID update needs the spinlock...)
2830 // [ BETTER: we already own net->xmit_lock, that's enough ]
2832 #ifdef CONFIG_USB_NET1080
2833 if (info->flags & FLAG_FRAMING_NC) {
2834 header = (struct nc_header *) skb_push (skb, sizeof *header);
2835 header->hdr_len = cpu_to_le16 (sizeof (*header));
2836 header->packet_len = cpu_to_le16 (length);
2837 if (!((skb->len + sizeof *trailer) & 0x01))
2838 *skb_put (skb, 1) = PAD_BYTE;
2839 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2841 #endif /* CONFIG_USB_NET1080 */
2843 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2844 skb->data, skb->len, tx_complete, skb);
2845 urb->transfer_flags |= URB_ASYNC_UNLINK;
2847 /* don't assume the hardware handles USB_ZERO_PACKET
2848 * NOTE: strictly conforming cdc-ether devices should expect
2849 * the ZLP here, but ignore the one-byte packet.
2851 * FIXME zero that byte, if it doesn't require a new skb.
2853 if ((length % dev->maxpacket) == 0)
2854 urb->transfer_buffer_length++;
2856 spin_lock_irqsave (&dev->txq.lock, flags);
2858 #ifdef CONFIG_USB_NET1080
2859 if (info->flags & FLAG_FRAMING_NC) {
2860 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
2861 put_unaligned (header->packet_id, &trailer->packet_id);
2863 devdbg (dev, "frame >tx h %d p %d id %d",
2864 header->hdr_len, header->packet_len,
2868 #endif /* CONFIG_USB_NET1080 */
2870 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2872 netif_stop_queue (net);
2873 defer_kevent (dev, EVENT_TX_HALT);
2876 devdbg (dev, "tx: submit urb err %d", retval);
2879 net->trans_start = jiffies;
2880 __skb_queue_tail (&dev->txq, skb);
2881 if (dev->txq.qlen >= TX_QLEN (dev))
2882 netif_stop_queue (net);
2884 spin_unlock_irqrestore (&dev->txq.lock, flags);
2887 devdbg (dev, "drop, code %d", retval);
2889 retval = NET_XMIT_SUCCESS;
2890 dev->stats.tx_dropped++;
2892 dev_kfree_skb_any (skb);
2896 devdbg (dev, "> tx, len %d, type 0x%x",
2897 length, skb->protocol);
2904 /*-------------------------------------------------------------------------*/
2906 // tasklet (work deferred from completions, in_irq) or timer
2908 static void usbnet_bh (unsigned long param)
2910 struct usbnet *dev = (struct usbnet *) param;
2911 struct sk_buff *skb;
2912 struct skb_data *entry;
2914 while ((skb = skb_dequeue (&dev->done))) {
2915 entry = (struct skb_data *) skb->cb;
2916 switch (entry->state) {
2918 entry->state = rx_cleanup;
2919 rx_process (dev, skb);
2923 usb_free_urb (entry->urb);
2924 dev_kfree_skb (skb);
2927 devdbg (dev, "bogus skb state %d", entry->state);
2931 // waiting for all pending urbs to complete?
2933 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
2934 wake_up (dev->wait);
2937 // or are we maybe short a few urbs?
2938 } else if (netif_running (dev->net)
2939 && netif_device_present (dev->net)
2940 && !timer_pending (&dev->delay)
2941 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2942 int temp = dev->rxq.qlen;
2943 int qlen = RX_QLEN (dev);
2949 // don't refill the queue all at once
2950 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
2951 if ((urb = usb_alloc_urb (0, GFP_ATOMIC)) != 0)
2952 rx_submit (dev, urb, GFP_ATOMIC);
2954 if (temp != dev->rxq.qlen)
2955 devdbg (dev, "rxqlen %d --> %d",
2956 temp, dev->rxq.qlen);
2957 if (dev->rxq.qlen < qlen)
2958 tasklet_schedule (&dev->bh);
2960 if (dev->txq.qlen < TX_QLEN (dev))
2961 netif_wake_queue (dev->net);
2967 /*-------------------------------------------------------------------------
2969 * USB Device Driver support
2971 *-------------------------------------------------------------------------*/
2973 // precondition: never called in_interrupt
2975 static void usbnet_disconnect (struct usb_interface *intf)
2978 struct usb_device *xdev;
2980 dev = usb_get_intfdata(intf);
2981 usb_set_intfdata(intf, NULL);
2985 xdev = interface_to_usbdev (intf);
2987 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
2988 xdev->bus->bus_name, xdev->devpath,
2989 dev->driver_info->description);
2991 unregister_netdev (dev->net);
2993 /* we don't hold rtnl here ... */
2994 flush_scheduled_work ();
2996 if (dev->driver_info->unbind)
2997 dev->driver_info->unbind (dev, intf);
2999 free_netdev(dev->net);
3005 /*-------------------------------------------------------------------------*/
3007 static struct ethtool_ops usbnet_ethtool_ops;
3009 // precondition: never called in_interrupt
3012 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3015 struct net_device *net;
3016 struct usb_host_interface *interface;
3017 struct driver_info *info;
3018 struct usb_device *xdev;
3021 info = (struct driver_info *) prod->driver_info;
3023 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3026 xdev = interface_to_usbdev (udev);
3027 interface = udev->cur_altsetting;
3033 // set up our own records
3034 if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) {
3035 dbg ("can't kmalloc dev");
3038 memset (dev, 0, sizeof *dev);
3041 dev->driver_info = info;
3042 dev->msg_level = msg_level;
3043 skb_queue_head_init (&dev->rxq);
3044 skb_queue_head_init (&dev->txq);
3045 skb_queue_head_init (&dev->done);
3046 dev->bh.func = usbnet_bh;
3047 dev->bh.data = (unsigned long) dev;
3048 INIT_WORK (&dev->kevent, kevent, dev);
3049 dev->delay.function = usbnet_bh;
3050 dev->delay.data = (unsigned long) dev;
3051 init_timer (&dev->delay);
3053 // set up network interface records
3054 net = alloc_etherdev(0);
3058 SET_MODULE_OWNER (net);
3061 strcpy (net->name, "usb%d");
3062 memcpy (net->dev_addr, node_id, sizeof node_id);
3065 // dma_supported() is deeply broken on almost all architectures
3066 // possible with some EHCI controllers
3067 if (dma_supported (&udev->dev, 0xffffffffffffffffULL))
3068 net->features |= NETIF_F_HIGHDMA;
3071 net->change_mtu = usbnet_change_mtu;
3072 net->get_stats = usbnet_get_stats;
3073 net->hard_start_xmit = usbnet_start_xmit;
3074 net->open = usbnet_open;
3075 net->stop = usbnet_stop;
3076 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3077 net->tx_timeout = usbnet_tx_timeout;
3078 net->do_ioctl = usbnet_ioctl;
3079 net->ethtool_ops = &usbnet_ethtool_ops;
3081 // allow device-specific bind/init procedures
3082 // NOTE net->name still not usable ...
3084 status = info->bind (dev, udev);
3085 // heuristic: "usb%d" for links we know are two-host,
3086 // else "eth%d" when there's reasonable doubt. userspace
3087 // can rename the link if it knows better.
3088 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3089 && (net->dev_addr [0] & 0x02) == 0)
3090 strcpy (net->name, "eth%d");
3091 } else if (!info->in || info->out)
3092 status = get_endpoints (dev, udev);
3094 dev->in = usb_rcvbulkpipe (xdev, info->in);
3095 dev->out = usb_sndbulkpipe (xdev, info->out);
3096 if (!(info->flags & FLAG_NO_SETINT))
3097 status = usb_set_interface (xdev,
3098 interface->desc.bInterfaceNumber,
3099 interface->desc.bAlternateSetting);
3107 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3109 SET_NETDEV_DEV(dev->net, &udev->dev);
3110 status = register_netdev (dev->net);
3113 devinfo (dev, "register usbnet at usb-%s-%s, %s",
3114 xdev->bus->bus_name, xdev->devpath,
3115 dev->driver_info->description);
3117 // ok, it's ready to go.
3118 usb_set_intfdata (udev, dev);
3120 // start as if the link is up
3121 netif_device_attach (dev->net);
3127 info->unbind (dev, udev);
3137 /*-------------------------------------------------------------------------*/
3139 #ifndef HAVE_HARDWARE
3140 #error You need to configure some hardware for this driver
3144 * chip vendor names won't normally be on the cables, and
3145 * may not be on the device.
3148 static const struct usb_device_id products [] = {
3150 #ifdef CONFIG_USB_ALI_M5632
3152 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3153 .driver_info = (unsigned long) &ali_m5632_info,
3157 #ifdef CONFIG_USB_AN2720
3159 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3160 .driver_info = (unsigned long) &an2720_info,
3162 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3163 .driver_info = (unsigned long) &an2720_info,
3167 #ifdef CONFIG_USB_BELKIN
3169 USB_DEVICE (0x050d, 0x0004), // Belkin
3170 .driver_info = (unsigned long) &belkin_info,
3172 USB_DEVICE (0x056c, 0x8100), // eTEK
3173 .driver_info = (unsigned long) &belkin_info,
3175 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3176 .driver_info = (unsigned long) &belkin_info,
3180 #ifdef CONFIG_USB_AX8817X
3183 USB_DEVICE (0x077b, 0x2226),
3184 .driver_info = (unsigned long) &ax8817x_info,
3187 USB_DEVICE (0x0846, 0x1040),
3188 .driver_info = (unsigned long) &netgear_fa120_info,
3191 USB_DEVICE (0x2001, 0x1a00),
3192 .driver_info = (unsigned long) &dlink_dub_e100_info,
3194 // Intellinet, ST Lab USB Ethernet
3195 USB_DEVICE (0x0b95, 0x1720),
3196 .driver_info = (unsigned long) &ax8817x_info,
3198 // Hawking UF200, TrendNet TU2-ET100
3199 USB_DEVICE (0x07b8, 0x420a),
3200 .driver_info = (unsigned long) &hawking_uf200_info,
3202 // Billionton Systems, USB2AR
3203 USB_DEVICE (0x08dd, 0x90ff),
3204 .driver_info = (unsigned long) &ax8817x_info,
3207 USB_DEVICE (0x0557, 0x2009),
3208 .driver_info = (unsigned long) &ax8817x_info,
3212 #ifdef CONFIG_USB_EPSON2888
3214 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3215 .driver_info = (unsigned long) &epson2888_info,
3219 #ifdef CONFIG_USB_GENESYS
3221 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3222 .driver_info = (unsigned long) &genelink_info,
3224 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3225 * that's half duplex, not currently supported
3229 #ifdef CONFIG_USB_NET1080
3231 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3232 .driver_info = (unsigned long) &net1080_info,
3234 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3235 .driver_info = (unsigned long) &net1080_info,
3239 #ifdef CONFIG_USB_PL2301
3241 USB_DEVICE (0x067b, 0x0000), // PL-2301
3242 .driver_info = (unsigned long) &prolific_info,
3244 USB_DEVICE (0x067b, 0x0001), // PL-2302
3245 .driver_info = (unsigned long) &prolific_info,
3249 #ifdef CONFIG_USB_RNDIS
3251 /* RNDIS is MSFT's un-official variant of CDC ACM */
3252 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3253 .driver_info = (unsigned long) &rndis_info,
3257 #ifdef CONFIG_USB_ARMLINUX
3259 * SA-1100 using standard ARM Linux kernels, or compatible.
3260 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3261 * The sa-1100 "usb-eth" driver handles the basic framing.
3263 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3264 * the sa1100 one, but hardware uses different endpoint numbers.
3267 // 1183 = 0x049F, both used as hex values?
3268 // Compaq "Itsy" vendor/product id
3269 USB_DEVICE (0x049F, 0x505A),
3270 .driver_info = (unsigned long) &linuxdev_info,
3272 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3273 .driver_info = (unsigned long) &yopy_info,
3275 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3276 .driver_info = (unsigned long) &blob_info,
3280 #ifdef CONFIG_USB_ZAURUS
3282 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3283 * Same idea as above, but different framing.
3285 * PXA-2xx based models are also lying-about-cdc.
3288 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3289 | USB_DEVICE_ID_MATCH_DEVICE,
3291 .idProduct = 0x8004,
3292 /* match the master interface */
3293 .bInterfaceClass = USB_CLASS_COMM,
3294 .bInterfaceSubClass = 6 /* Ethernet model */,
3295 .bInterfaceProtocol = 0,
3296 .driver_info = (unsigned long) &zaurus_sl5x00_info,
3298 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3299 | USB_DEVICE_ID_MATCH_DEVICE,
3301 .idProduct = 0x8005, /* A-300 */
3302 .bInterfaceClass = 0x02,
3303 .bInterfaceSubClass = 0x0a,
3304 .bInterfaceProtocol = 0x00,
3305 .driver_info = (unsigned long) &zaurus_pxa_info,
3307 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3308 | USB_DEVICE_ID_MATCH_DEVICE,
3310 .idProduct = 0x8006, /* B-500/SL-5600 */
3311 .bInterfaceClass = 0x02,
3312 .bInterfaceSubClass = 0x0a,
3313 .bInterfaceProtocol = 0x00,
3314 .driver_info = (unsigned long) &zaurus_pxa_info,
3316 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3317 | USB_DEVICE_ID_MATCH_DEVICE,
3319 .idProduct = 0x8007, /* C-700 */
3320 .bInterfaceClass = 0x02,
3321 .bInterfaceSubClass = 0x0a,
3322 .bInterfaceProtocol = 0x00,
3323 .driver_info = (unsigned long) &zaurus_pxa_info,
3325 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3326 | USB_DEVICE_ID_MATCH_DEVICE,
3328 .idProduct = 0x9031, /* C-750 C-760 */
3329 .bInterfaceClass = 0x02,
3330 .bInterfaceSubClass = 0x0a,
3331 .bInterfaceProtocol = 0x00,
3332 .driver_info = (unsigned long) &zaurus_pxa_info,
3334 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3335 | USB_DEVICE_ID_MATCH_DEVICE,
3337 .idProduct = 0x9032, /* SL-6000 */
3338 .bInterfaceClass = 0x02,
3339 .bInterfaceSubClass = 0x0a,
3340 .bInterfaceProtocol = 0x00,
3341 .driver_info = (unsigned long) &zaurus_pxa_info,
3343 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3344 | USB_DEVICE_ID_MATCH_DEVICE,
3346 .idProduct = 0x9050, /* C-860 */
3347 .bInterfaceClass = 0x02,
3348 .bInterfaceSubClass = 0x0a,
3349 .bInterfaceProtocol = 0x00,
3350 .driver_info = (unsigned long) &zaurus_pxa_info,
3354 #ifdef CONFIG_USB_CDCETHER
3356 #ifndef CONFIG_USB_ZAURUS
3357 /* if we couldn't whitelist Zaurus, we must blacklist it */
3359 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3360 | USB_DEVICE_ID_MATCH_DEVICE,
3362 .idProduct = 0x8004,
3363 /* match the master interface */
3364 .bInterfaceClass = USB_CLASS_COMM,
3365 .bInterfaceSubClass = 6 /* Ethernet model */,
3366 .bInterfaceProtocol = 0,
3367 .driver_info = 0, /* BLACKLIST */
3369 // FIXME blacklist the other Zaurus models too, sigh
3373 /* CDC Ether uses two interfaces, not necessarily consecutive.
3374 * We match the main interface, ignoring the optional device
3375 * class so we could handle devices that aren't exclusively
3378 * NOTE: this match must come AFTER entries working around
3379 * bugs/quirks in a given product (like Zaurus, above).
3381 USB_INTERFACE_INFO (USB_CLASS_COMM, 6 /* Ethernet model */, 0),
3382 .driver_info = (unsigned long) &cdc_info,
3388 MODULE_DEVICE_TABLE (usb, products);
3390 static struct usb_driver usbnet_driver = {
3391 .owner = THIS_MODULE,
3392 .name = driver_name,
3393 .id_table = products,
3394 .probe = usbnet_probe,
3395 .disconnect = usbnet_disconnect,
3398 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
3399 static struct ethtool_ops usbnet_ethtool_ops = {
3400 .get_drvinfo = usbnet_get_drvinfo,
3401 .get_link = usbnet_get_link,
3402 .get_msglevel = usbnet_get_msglevel,
3403 .set_msglevel = usbnet_set_msglevel,
3406 /*-------------------------------------------------------------------------*/
3408 static int __init usbnet_init (void)
3410 // compiler should optimize these out
3411 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3412 < sizeof (struct skb_data));
3413 #ifdef CONFIG_USB_CDCETHER
3414 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3415 < sizeof (struct cdc_state)));
3418 random_ether_addr(node_id);
3420 return usb_register(&usbnet_driver);
3422 module_init (usbnet_init);
3424 static void __exit usbnet_exit (void)
3426 usb_deregister (&usbnet_driver);
3428 module_exit (usbnet_exit);
3430 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
3431 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
3432 MODULE_LICENSE ("GPL");