2 * USB Host-to-Host Links
3 * Copyright (C) 2000-2002 by David Brownell <dbrownell@users.sourceforge.net>
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This is used for "USB networking", connecting USB hosts as peers.
24 * It can be used with USB "network cables", for IP-over-USB communications;
25 * Ethernet speeds without the Ethernet. USB devices (including some PDAs)
26 * can support such links directly, replacing device-specific protocols
27 * with Internet standard ones.
29 * The links can be bridged using the Ethernet bridging (net/bridge)
30 * support as appropriate. Devices currently supported include:
33 * - Belkin, eTEK (interops with Win32 drivers)
35 * - GeneSys GL620USB-A
36 * - NetChip 1080 (interoperates with NetChip Win32 drivers)
37 * - Prolific PL-2301/2302 (replaces "plusb" driver)
38 * - PXA-250 or SA-1100 Linux PDAs like iPAQ, Yopy, and Zaurus
40 * USB devices can implement their side of this protocol at the cost
41 * of two bulk endpoints; it's not restricted to "cable" applications.
42 * See the SA1110, Zaurus, or EPSON device/client support in this driver;
43 * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) are
44 * used inside USB slave/target devices.
49 * - AN2720 ... not widely available, but reportedly works well
51 * - Belkin/eTEK ... no known issues
53 * - Both GeneSys and PL-230x use interrupt transfers for driver-to-driver
54 * handshaking; it'd be worth implementing those as "carrier detect".
55 * Prefer generic hooks, not minidriver-specific hacks.
57 * - For Netchip, should use keventd to poll via control requests to detect
58 * hardware level "carrier detect".
60 * - PL-230x ... the initialization protocol doesn't seem to match chip data
61 * sheets, sometimes it's not needed and sometimes it hangs. Prolific has
62 * not responded to repeated support/information requests.
64 * - SA-1100 PDAs ... the standard ARM Linux SA-1100 support works nicely,
65 * as found in www.handhelds.org and other kernels. The Sharp/Lineo
66 * kernels use different drivers, which also talk to this code.
68 * Interop with more Win32 drivers may be a good thing.
70 * Seems like reporting "peer connected" (carrier present) events may end
71 * up going through the netlink event system, not hotplug ... so new links
72 * would likely be handled with a link monitoring thread in some daemon.
74 * There are reports that bridging gives lower-than-usual throughput.
76 * Need smarter hotplug policy scripts ... ones that know how to arrange
77 * bridging with "brctl", and can handle static and dynamic ("pump") setups.
78 * Use those eventual "peer connected" events, and zeroconf.
83 * 13-sep-2000 experimental, new
84 * 10-oct-2000 usb_device_id table created.
85 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
86 * 01-nov-2000 usb_device_id table and probing api update by
87 * Adam J. Richter <adam@yggdrasil.com>.
88 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
89 * and prolific support, isolate net1080-specific bits, cleanup.
90 * fix unlink_urbs oops in D3 PM resume code path.
92 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
93 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
94 * AnchorChips 2720 support (from spec) for testing;
95 * fix bit-ordering problem with ethernet multicast addr
96 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
97 * updates. Oleg Drokin (green@iXcelerator.com)
98 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
99 * expecting cleared skb->cb and framing change to match latest
100 * handhelds.org version (Oleg). Enable device IDs from the
101 * Win32 Belkin driver; other cleanups (db).
102 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
103 * cleanups for problems not yet seen in the field. (db)
104 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
105 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
106 * rx unlinks somehow weren't async; minor cleanup.
107 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
108 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
109 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
110 * tie mostly to (sub)driver info. Workaround some PL-2302
111 * chips that seem to reject SET_INTERFACE requests.
113 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
114 * Level of diagnostics is more configurable; they use device
115 * location (usb_device->devpath) instead of address (2.5).
116 * For tx_fixup, memflags can't be NOIO.
117 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
118 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
119 * Use "locally assigned" IEEE802 address space. (Brad Hards)
120 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
121 * 15-dec-2002 Partial sync with 2.5 code: cleanups and stubbed PXA-250
122 * support (db), fix for framing issues on Z, net1080, and
123 * gl620a (Toby Milne)
125 *-------------------------------------------------------------------------*/
127 #include <linux/config.h>
128 #include <linux/module.h>
129 #include <linux/kmod.h>
130 #include <linux/sched.h>
131 #include <linux/init.h>
132 #include <linux/netdevice.h>
133 #include <linux/etherdevice.h>
134 #include <linux/random.h>
135 #include <linux/ethtool.h>
136 #include <linux/mii.h>
137 #include <linux/tqueue.h>
138 #include <asm/uaccess.h>
139 #include <asm/unaligned.h>
141 // #define DEBUG // error path messages, extra info
142 // #define VERBOSE // more; success messages
143 // #define REALLY_QUEUE
145 #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
148 #include <linux/usb.h>
150 /* in 2.5 these standard usb ops take mem_flags */
151 #define ALLOC_URB(n,flags) usb_alloc_urb(n)
152 #define SUBMIT_URB(u,flags) usb_submit_urb(u)
154 /* and these got renamed (may move to usb.h) */
155 #define usb_get_dev usb_inc_dev_use
156 #define usb_put_dev usb_dec_dev_use
159 /* minidrivers _could_ be individually configured */
160 #define CONFIG_USB_AN2720
161 #define CONFIG_USB_AX8817X
162 #define CONFIG_USB_BELKIN
163 #define CONFIG_USB_EPSON2888
164 #define CONFIG_USB_GENESYS
165 #define CONFIG_USB_NET1080
166 #define CONFIG_USB_PL2301
167 #define CONFIG_USB_ARMLINUX
168 #define CONFIG_USB_ZAURUS
171 #define DRIVER_VERSION "18-Oct-2002"
173 /*-------------------------------------------------------------------------*/
176 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
177 * Several dozen bytes of IPv4 data can fit in two such transactions.
178 * One maximum size Ethernet packet takes twenty four of them.
179 * For high speed, each frame comfortably fits almost 36 max size
180 * Ethernet packets (so queues should be bigger).
190 // packets are always ethernet inside
191 // ... except they can be bigger (limit of 64K with NetChip framing)
192 #define MIN_PACKET sizeof(struct ethhdr)
193 #define MAX_PACKET 32768
195 // reawaken network queue this soon after stopping; else watchdog barks
196 #define TX_TIMEOUT_JIFFIES (5*HZ)
198 // for vendor-specific control operations
199 #define CONTROL_TIMEOUT_MS (500) /* msec */
200 #define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
203 #define UNLINK_TIMEOUT_JIFFIES ((3 /*ms*/ * HZ)/1000)
205 /*-------------------------------------------------------------------------*/
207 // list of all devices we manage
208 static DECLARE_MUTEX (usbnet_mutex);
209 static LIST_HEAD (usbnet_list);
211 // randomly generated ethernet address
212 static u8 node_id [ETH_ALEN];
214 // state we keep for each device we handle
217 struct usb_device *udev;
218 struct driver_info *driver_info;
219 struct semaphore mutex;
220 struct list_head dev_list;
221 wait_queue_head_t *wait;
223 // i/o info: pipes etc
226 //struct timer_list delay;
228 // protocol/interface state
229 struct net_device net;
230 struct net_device_stats stats;
232 struct mii_if_info mii;
234 #ifdef CONFIG_USB_NET1080
238 // various kinds of pending driver work
239 struct sk_buff_head rxq;
240 struct sk_buff_head txq;
241 struct sk_buff_head done;
242 struct tasklet_struct bh;
244 struct tq_struct kevent;
246 # define EVENT_TX_HALT 0
247 # define EVENT_RX_HALT 1
248 # define EVENT_RX_MEMORY 2
251 // device-specific info used by the driver
256 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
257 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
258 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
259 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
260 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
262 /* init device ... can sleep, or cause probe() failure */
263 int (*bind)(struct usbnet *, struct usb_device *);
265 /* reset device ... can sleep */
266 int (*reset)(struct usbnet *);
268 /* see if peer is connected ... can sleep */
269 int (*check_connect)(struct usbnet *);
271 /* fixup rx packet (strip framing) */
272 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
274 /* fixup tx packet (add framing) */
275 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
276 struct sk_buff *skb, int flags);
278 // FIXME -- also an interrupt mechanism
279 // useful for at least PL2301/2302 and GL620USB-A
281 /* for new devices, use the descriptor-reading code instead */
282 int in; /* rx endpoint */
283 int out; /* tx endpoint */
286 unsigned long data; /* Misc driver specific data */
289 // we record the state for each of our queued skbs
293 rx_start, rx_done, rx_cleanup
296 struct skb_data { // skb->cb is one of these
299 enum skb_state state;
303 static const char driver_name [] = "usbnet";
305 /* use ethtool to change the level for any given device */
306 static int msg_level = 1;
307 MODULE_PARM (msg_level, "i");
308 MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
311 #define mutex_lock(x) down(x)
312 #define mutex_unlock(x) up(x)
314 #define RUN_CONTEXT (in_irq () ? "in_irq" \
315 : (in_interrupt () ? "in_interrupt" : "can sleep"))
317 static struct ethtool_ops usbnet_ethtool_ops;
319 /* mostly for PDA style devices, which are always present */
320 static int always_connected (struct usbnet *dev)
325 /*-------------------------------------------------------------------------*/
327 /* handles CDC Ethernet and many other network "bulk data" interfaces */
329 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
332 struct usb_interface_descriptor *alt;
333 struct usb_endpoint_descriptor *in, *out;
335 for (tmp = 0; tmp < intf->max_altsetting; tmp++) {
339 alt = intf->altsetting + tmp;
341 /* take the first altsetting with in-bulk + out-bulk;
342 * ignore other endpoints and altsetttings.
344 for (ep = 0; ep < alt->bNumEndpoints; ep++) {
345 struct usb_endpoint_descriptor *e;
347 e = alt->endpoint + ep;
348 if (e->bmAttributes != USB_ENDPOINT_XFER_BULK)
350 if (e->bEndpointAddress & USB_DIR_IN) {
364 if (alt->bAlternateSetting != 0
365 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
366 tmp = usb_set_interface (dev->udev, alt->bInterfaceNumber,
367 alt->bAlternateSetting);
372 dev->in = usb_rcvbulkpipe (dev->udev,
373 in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
374 dev->out = usb_sndbulkpipe (dev->udev,
375 out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
376 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
380 /*-------------------------------------------------------------------------*/
383 #define devdbg(usbnet, fmt, arg...) \
384 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net.name , ## arg)
386 #define devdbg(usbnet, fmt, arg...) do {} while(0)
389 #define devinfo(usbnet, fmt, arg...) \
390 do { if ((usbnet)->msg_level >= 1) \
391 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net.name , ## arg); \
395 #ifdef CONFIG_USB_AN2720
397 /*-------------------------------------------------------------------------
399 * AnchorChips 2720 driver ... http://www.cypress.com
401 * This doesn't seem to have a way to detect whether the peer is
402 * connected, or need any reset handshaking. It's got pretty big
403 * internal buffers (handles most of a frame's worth of data).
404 * Chip data sheets don't describe any vendor control messages.
406 *-------------------------------------------------------------------------*/
408 static const struct driver_info an2720_info = {
409 .description = "AnchorChips/Cypress 2720",
410 // no reset available!
411 // no check_connect available!
413 .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_WRITE_RX_CTL 0x10
433 #define AX_CMD_READ_IPG012 0x11
434 #define AX_CMD_WRITE_IPG0 0x12
435 #define AX_CMD_WRITE_IPG1 0x13
436 #define AX_CMD_WRITE_IPG2 0x14
437 #define AX_CMD_WRITE_MULTI_FILTER 0x16
438 #define AX_CMD_READ_NODE_ID 0x17
439 #define AX_CMD_READ_PHY_ID 0x19
440 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
441 #define AX_CMD_WRITE_GPIOS 0x1f
443 #define AX_MCAST_FILTER_SIZE 8
444 #define AX_MAX_MCAST 64
446 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
447 u16 size, void *data)
449 return usb_control_msg(
451 usb_rcvctrlpipe(dev->udev, 0),
453 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
458 CONTROL_TIMEOUT_JIFFIES);
461 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
462 u16 size, void *data)
464 return usb_control_msg(
466 usb_sndctrlpipe(dev->udev, 0),
468 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
473 CONTROL_TIMEOUT_JIFFIES);
476 static void ax8817x_async_cmd_callback(struct urb *urb)
478 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
481 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
488 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
489 u16 size, void *data)
491 struct usb_ctrlrequest *req;
495 if ((urb = ALLOC_URB(0, GFP_ATOMIC)) == NULL) {
496 devdbg(dev, "Error allocating URB in write_cmd_async!");
500 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
501 devdbg(dev, "Failed to allocate memory for control request");
506 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
508 req->wValue = cpu_to_le16(value);
509 req->wIndex = cpu_to_le16(index);
510 req->wLength = cpu_to_le16(size);
512 usb_fill_control_urb(urb, dev->udev,
513 usb_sndctrlpipe(dev->udev, 0),
514 (void *)req, data, size,
515 ax8817x_async_cmd_callback, req);
517 if((status = SUBMIT_URB(urb, GFP_ATOMIC)) < 0)
518 devdbg(dev, "Error submitting the control message: status=%d", status);
521 static void ax8817x_set_multicast(struct net_device *net)
523 struct usbnet *dev = (struct usbnet *) net->priv;
526 if (net->flags & IFF_PROMISC) {
528 } else if (net->flags & IFF_ALLMULTI
529 || net->mc_count > AX_MAX_MCAST) {
531 } else if (net->mc_count == 0) {
532 /* just broadcast and directed */
534 struct dev_mc_list *mc_list = net->mc_list;
539 multi_filter = kmalloc(AX_MCAST_FILTER_SIZE, GFP_ATOMIC);
540 if (multi_filter == NULL) {
541 /* Oops, couldn't allocate a buffer for setting the multicast
542 filter. Try all multi mode. */
545 memset(multi_filter, 0, AX_MCAST_FILTER_SIZE);
547 /* Build the multicast hash filter. */
548 for (i = 0; i < net->mc_count; i++) {
551 mc_list->dmi_addr) >> 26;
552 multi_filter[crc_bits >> 3] |=
554 mc_list = mc_list->next;
557 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
558 AX_MCAST_FILTER_SIZE, multi_filter);
564 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
567 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
569 struct usbnet *dev = netdev->priv;
573 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
574 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
575 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
580 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
582 struct usbnet *dev = netdev->priv;
586 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
587 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
588 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
591 static int ax8817x_bind(struct usbnet *dev, struct usb_device *intf)
595 u16 *buf16 = (u16 *) buf;
597 unsigned long gpio_bits = dev->driver_info->data;
599 dev->in = usb_rcvbulkpipe(dev->udev, 3);
600 dev->out = usb_sndbulkpipe(dev->udev, 2);
602 /* Toggle the GPIOs in a manufacturer/model specific way */
603 for (i = 2; i >= 0; i--) {
604 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
605 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
611 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
612 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
616 /* Get the MAC address */
617 memset(buf, 0, ETH_ALEN);
618 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
619 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
622 memcpy(dev->net.dev_addr, buf, ETH_ALEN);
625 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_IPG012, 0, 0, 3, buf)) < 0) {
626 dbg("Error reading IPG values: %d", ret);
630 for(i = 0;i < 3;i++) {
631 ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0 + i, 0, 0, 1, &buf[i]);
635 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
636 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
638 } else if (ret < 2) {
639 /* this should always return 2 bytes */
640 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
644 /* Initialize MII structure */
645 dev->mii.dev = &dev->net;
646 dev->mii.mdio_read = ax8817x_mdio_read;
647 dev->mii.mdio_write = ax8817x_mdio_write;
648 dev->mii.phy_id_mask = 0x3f;
649 dev->mii.reg_num_mask = 0x1f;
650 dev->mii.phy_id = buf[1];
652 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf)) < 0) {
653 dbg("Failed to go to software MII mode: %02x", ret);
657 *buf16 = cpu_to_le16(BMCR_RESET);
658 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
659 dev->mii.phy_id, MII_BMCR, 2, buf16)) < 0) {
660 dbg("Failed to write MII reg - MII_BMCR: %02x", ret);
664 /* Advertise that we can do full-duplex pause */
665 *buf16 = cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400);
666 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
667 dev->mii.phy_id, MII_ADVERTISE,
669 dbg("Failed to write MII_REG advertisement: %02x", ret);
673 *buf16 = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART);
674 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
675 dev->mii.phy_id, MII_BMCR,
677 dbg("Failed to write MII reg autonegotiate: %02x", ret);
681 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
682 dbg("Failed to set hardware MII: %02x", ret);
686 dev->net.set_multicast_list = ax8817x_set_multicast;
691 static const struct driver_info ax8817x_info = {
692 .description = "ASIX AX8817x USB 2.0 Ethernet",
693 .bind = ax8817x_bind,
698 static const struct driver_info dlink_dub_e100_info = {
699 .description = "DLink DUB-E100 USB Ethernet",
700 .bind = ax8817x_bind,
705 static const struct driver_info netgear_fa120_info = {
706 .description = "Netgear FA-120 USB Ethernet",
707 .bind = ax8817x_bind,
712 static const struct driver_info hawking_uf200_info = {
713 .description = "Hawking UF200 USB Ethernet",
714 .bind = ax8817x_bind,
718 #endif /* CONFIG_USB_AX8817X */
721 #ifdef CONFIG_USB_BELKIN
723 /*-------------------------------------------------------------------------
725 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
727 * ... also two eTEK designs, including one sold as "Advance USBNET"
729 *-------------------------------------------------------------------------*/
731 static const struct driver_info belkin_info = {
732 .description = "Belkin, eTEK, or compatible",
735 #endif /* CONFIG_USB_BELKIN */
739 #ifdef CONFIG_USB_EPSON2888
741 /*-------------------------------------------------------------------------
745 * This is the same idea as Linux PDAs (below) except the firmware in the
746 * device might not be Tux-powered. Epson provides reference firmware that
747 * implements this interface. Product developers can reuse or modify that
748 * code, such as by using their own product and vendor codes.
750 *-------------------------------------------------------------------------*/
752 static const struct driver_info epson2888_info = {
753 .description = "Epson USB Device",
754 .check_connect = always_connected,
760 #endif /* CONFIG_USB_EPSON2888 */
763 #ifdef CONFIG_USB_GENESYS
765 /*-------------------------------------------------------------------------
767 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
769 * ... should partially interop with the Win32 driver for this hardware
770 * The GeneSys docs imply there's some NDIS issue motivating this framing.
772 * Some info from GeneSys:
773 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
774 * (Some cables, like the BAFO-100c, use the half duplex version.)
775 * - For the full duplex model, the low bit of the version code says
776 * which side is which ("left/right").
777 * - For the half duplex type, a control/interrupt handshake settles
778 * the transfer direction. (That's disabled here, partially coded.)
779 * A control URB would block until other side writes an interrupt.
781 *-------------------------------------------------------------------------*/
783 // control msg write command
784 #define GENELINK_CONNECT_WRITE 0xF0
785 // interrupt pipe index
786 #define GENELINK_INTERRUPT_PIPE 0x03
787 // interrupt read buffer size
788 #define INTERRUPT_BUFSIZE 0x08
789 // interrupt pipe interval value
790 #define GENELINK_INTERRUPT_INTERVAL 0x10
791 // max transmit packet number per transmit
792 #define GL_MAX_TRANSMIT_PACKETS 32
794 #define GL_MAX_PACKET_LEN 1514
795 // max receive buffer size
796 #define GL_RCV_BUF_SIZE \
797 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
801 char packet_data [1];
806 struct gl_packet packets;
811 // FIXME: this code is incomplete, not debugged; it doesn't
812 // handle interrupts correctly. interrupts should be generic
813 // code like all other device I/O, anyway.
817 char irq_buf [INTERRUPT_BUFSIZE];
820 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
824 retval = usb_control_msg (dev->udev,
825 usb_sndctrlpipe (dev->udev, 0),
827 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
832 CONTROL_TIMEOUT_JIFFIES);
836 static void gl_interrupt_complete (struct urb *urb)
838 int status = urb->status;
847 /* this urb is terminated, clean up */
848 dbg("%s - urb shutting down with status: %d",
849 __FUNCTION__, status);
852 dbg("%s - nonzero urb status received: %d",
853 __FUNCTION__, urb->status);
856 // NOTE: 2.4 still has automagic resubmit, so this would be
857 // wrong ... but this code has never worked, is always disabled.
858 status = usb_submit_urb (urb, GFP_ATOMIC);
860 err ("%s - usb_submit_urb failed with result %d",
861 __FUNCTION__, status);
864 static int gl_interrupt_read (struct usbnet *dev)
866 struct gl_priv *priv = dev->priv_data;
869 // issue usb interrupt read
870 if (priv && priv->irq_urb) {
872 if ((retval = SUBMIT_URB (priv->irq_urb, GFP_KERNEL)) != 0)
873 dbg ("gl_interrupt_read: submit fail - %X...", retval);
875 dbg ("gl_interrupt_read: submit success...");
881 // check whether another side is connected
882 static int genelink_check_connect (struct usbnet *dev)
886 dbg ("genelink_check_connect...");
888 // detect whether another side is connected
889 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
890 dbg ("%s: genelink_check_connect write fail - %X",
891 dev->net.name, retval);
895 // usb interrupt read to ack another side
896 if ((retval = gl_interrupt_read (dev)) != 0) {
897 dbg ("%s: genelink_check_connect read fail - %X",
898 dev->net.name, retval);
902 dbg ("%s: genelink_check_connect read success", dev->net.name);
906 // allocate and initialize the private data for genelink
907 static int genelink_init (struct usbnet *dev)
909 struct gl_priv *priv;
911 // allocate the private data structure
912 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
913 dbg ("%s: cannot allocate private data per device",
919 if ((priv->irq_urb = ALLOC_URB (0, GFP_KERNEL)) == 0) {
920 dbg ("%s: cannot allocate private irq urb per device",
927 usb_fill_int_urb (priv->irq_urb, dev->udev,
928 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
929 priv->irq_buf, INTERRUPT_BUFSIZE,
930 gl_interrupt_complete, 0,
931 GENELINK_INTERRUPT_INTERVAL);
933 // set private data pointer
934 dev->priv_data = priv;
939 // release the private data
940 static int genelink_free (struct usbnet *dev)
942 struct gl_priv *priv = dev->priv_data;
947 // FIXME: can't cancel here; it's synchronous, and
948 // should have happened earlier in any case (interrupt
949 // handling needs to be generic)
951 // cancel irq urb first
952 usb_unlink_urb (priv->irq_urb);
955 usb_free_urb (priv->irq_urb);
957 // free the private data structure
965 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
967 struct gl_header *header;
968 struct gl_packet *packet;
969 struct sk_buff *gl_skb;
973 header = (struct gl_header *) skb->data;
975 // get the packet count of the received skb
976 le32_to_cpus (&header->packet_count);
977 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
978 || (header->packet_count < 0)) {
979 dbg ("genelink: illegal received packet count %d",
980 header->packet_count);
984 // set the current packet pointer to the first packet
985 packet = &header->packets;
987 // decrement the length for the packet count size 4 bytes
990 while (header->packet_count > 1) {
991 // get the packet length
992 size = packet->packet_length;
994 // this may be a broken packet
995 if (size > GL_MAX_PACKET_LEN) {
996 dbg ("genelink: illegal rx length %d", size);
1000 // allocate the skb for the individual packet
1001 gl_skb = alloc_skb (size, GFP_ATOMIC);
1004 // copy the packet data to the new skb
1005 memcpy (gl_skb->data, packet->packet_data, size);
1007 // set skb data size
1009 gl_skb->dev = &dev->net;
1011 // determine the packet's protocol ID
1012 gl_skb->protocol = eth_type_trans (gl_skb, &dev->net);
1014 // update the status
1015 dev->stats.rx_packets++;
1016 dev->stats.rx_bytes += size;
1018 // notify os of the received packet
1019 status = netif_rx (gl_skb);
1022 // advance to the next packet
1023 packet = (struct gl_packet *)
1024 &packet->packet_data [size];
1025 header->packet_count--;
1027 // shift the data pointer to the next gl_packet
1028 skb_pull (skb, size + 4);
1031 // skip the packet length field 4 bytes
1034 if (skb->len > GL_MAX_PACKET_LEN) {
1035 dbg ("genelink: illegal rx length %d", skb->len);
1041 static struct sk_buff *
1042 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1045 int length = skb->len;
1046 int headroom = skb_headroom (skb);
1047 int tailroom = skb_tailroom (skb);
1051 // FIXME: magic numbers, bleech
1052 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1054 if ((!skb_cloned (skb))
1055 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1056 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1057 skb->data = memmove (skb->head + (4 + 4*1),
1058 skb->data, skb->len);
1059 skb->tail = skb->data + skb->len;
1062 struct sk_buff *skb2;
1063 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1064 dev_kfree_skb_any (skb);
1068 // attach the packet count to the header
1069 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1070 packet_len = packet_count + 1;
1072 // FIXME little endian?
1074 *packet_len = length;
1077 if ((skb->len % dev->maxpacket) == 0)
1083 static const struct driver_info genelink_info = {
1084 .description = "Genesys GeneLink",
1085 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1086 .rx_fixup = genelink_rx_fixup,
1087 .tx_fixup = genelink_tx_fixup,
1093 .check_connect =genelink_check_connect,
1097 #endif /* CONFIG_USB_GENESYS */
1101 #ifdef CONFIG_USB_NET1080
1103 /*-------------------------------------------------------------------------
1105 * Netchip 1080 driver ... http://www.netchip.com
1106 * Used in LapLink cables
1108 *-------------------------------------------------------------------------*/
1111 * NetChip framing of ethernet packets, supporting additional error
1112 * checks for links that may drop bulk packets from inside messages.
1113 * Odd USB length == always short read for last usb packet.
1115 * - Ethernet header (14 bytes)
1117 * - (optional padding byte, if needed so length becomes odd)
1120 * This framing is to be avoided for non-NetChip devices.
1123 struct nc_header { // packed:
1124 u16 hdr_len; // sizeof nc_header (LE, all)
1125 u16 packet_len; // payload size (including ethhdr)
1126 u16 packet_id; // detects dropped packets
1127 #define MIN_HEADER 6
1129 // all else is optional, and must start with:
1130 // u16 vendorId; // from usb-if
1132 } __attribute__((__packed__));
1134 #define PAD_BYTE ((unsigned char)0xAC)
1138 } __attribute__((__packed__));
1140 // packets may use FLAG_FRAMING_NC and optional pad
1141 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1142 + sizeof (struct ethhdr) \
1145 + sizeof (struct nc_trailer))
1147 #define MIN_FRAMED FRAMED_SIZE(0)
1151 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1152 * before the hardware drops it. If that's done, the driver will need to
1153 * frame network packets to guard against the dropped USB packets. The win32
1154 * driver sets this for both sides of the link.
1156 #define NC_READ_TTL_MS ((u8)255) // ms
1159 * We ignore most registers and EEPROM contents.
1161 #define REG_USBCTL ((u8)0x04)
1162 #define REG_TTL ((u8)0x10)
1163 #define REG_STATUS ((u8)0x11)
1166 * Vendor specific requests to read/write data
1168 #define REQUEST_REGISTER ((u8)0x10)
1169 #define REQUEST_EEPROM ((u8)0x11)
1172 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1174 int status = usb_control_msg (dev->udev,
1175 usb_rcvctrlpipe (dev->udev, 0),
1177 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1179 retval_ptr, sizeof *retval_ptr,
1180 CONTROL_TIMEOUT_JIFFIES);
1184 le16_to_cpus (retval_ptr);
1189 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1191 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1194 // no retval ... can become async, usable in_interrupt()
1196 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1198 usb_control_msg (dev->udev,
1199 usb_sndctrlpipe (dev->udev, 0),
1201 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1203 0, 0, // data is in setup packet
1204 CONTROL_TIMEOUT_JIFFIES);
1208 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1210 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1215 static void nc_dump_registers (struct usbnet *dev)
1218 u16 *vp = kmalloc (sizeof (u16));
1225 dbg ("%s registers:", dev->net.name);
1226 for (reg = 0; reg < 0x20; reg++) {
1229 // reading some registers is trouble
1230 if (reg >= 0x08 && reg <= 0xf)
1232 if (reg >= 0x12 && reg <= 0x1e)
1235 retval = nc_register_read (dev, reg, vp);
1237 dbg ("%s reg [0x%x] ==> error %d",
1238 dev->net.name, reg, retval);
1240 dbg ("%s reg [0x%x] = 0x%x",
1241 dev->net.name, reg, *vp);
1248 /*-------------------------------------------------------------------------*/
1254 #define USBCTL_WRITABLE_MASK 0x1f0f
1255 // bits 15-13 reserved, r/o
1256 #define USBCTL_ENABLE_LANG (1 << 12)
1257 #define USBCTL_ENABLE_MFGR (1 << 11)
1258 #define USBCTL_ENABLE_PROD (1 << 10)
1259 #define USBCTL_ENABLE_SERIAL (1 << 9)
1260 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1261 // bits 7-4 reserved, r/o
1262 #define USBCTL_FLUSH_OTHER (1 << 3)
1263 #define USBCTL_FLUSH_THIS (1 << 2)
1264 #define USBCTL_DISCONN_OTHER (1 << 1)
1265 #define USBCTL_DISCONN_THIS (1 << 0)
1267 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1270 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1272 " other%s%s; r/o 0x%x",
1273 dev->udev->bus->bus_name, dev->udev->devpath,
1275 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1276 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1277 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1278 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1279 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1281 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1282 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1283 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1284 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1285 usbctl & ~USBCTL_WRITABLE_MASK
1290 /*-------------------------------------------------------------------------*/
1296 #define STATUS_PORT_A (1 << 15)
1298 #define STATUS_CONN_OTHER (1 << 14)
1299 #define STATUS_SUSPEND_OTHER (1 << 13)
1300 #define STATUS_MAILBOX_OTHER (1 << 12)
1301 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1303 #define STATUS_CONN_THIS (1 << 6)
1304 #define STATUS_SUSPEND_THIS (1 << 5)
1305 #define STATUS_MAILBOX_THIS (1 << 4)
1306 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1308 #define STATUS_UNSPEC_MASK 0x0c8c
1309 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1312 static inline void nc_dump_status (struct usbnet *dev, u16 status)
1315 devdbg (dev, "net1080 %s-%s status 0x%x:"
1316 " this (%c) PKT=%d%s%s%s;"
1317 " other PKT=%d%s%s%s; unspec 0x%x",
1318 dev->udev->bus->bus_name, dev->udev->devpath,
1321 // XXX the packet counts don't seem right
1322 // (1 at reset, not 0); maybe UNSPEC too
1324 (status & STATUS_PORT_A) ? 'A' : 'B',
1325 STATUS_PACKETS_THIS (status),
1326 (status & STATUS_CONN_THIS) ? " CON" : "",
1327 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1328 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1330 STATUS_PACKETS_OTHER (status),
1331 (status & STATUS_CONN_OTHER) ? " CON" : "",
1332 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1333 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1335 status & STATUS_UNSPEC_MASK
1340 /*-------------------------------------------------------------------------*/
1346 #define TTL_THIS(ttl) (0x00ff & ttl)
1347 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1348 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1350 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1353 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1354 dev->udev->bus->bus_name, dev->udev->devpath,
1363 /*-------------------------------------------------------------------------*/
1365 static int net1080_reset (struct usbnet *dev)
1367 u16 usbctl, status, ttl;
1368 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1374 // nc_dump_registers (dev);
1376 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1377 dbg ("can't read %s-%s status: %d",
1378 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1382 // nc_dump_status (dev, status);
1384 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1385 dbg ("can't read USBCTL, %d", retval);
1389 // nc_dump_usbctl (dev, usbctl);
1391 nc_register_write (dev, REG_USBCTL,
1392 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1394 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1395 dbg ("can't read TTL, %d", retval);
1399 // nc_dump_ttl (dev, ttl);
1401 nc_register_write (dev, REG_TTL,
1402 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1403 dbg ("%s: assigned TTL, %d ms", dev->net.name, NC_READ_TTL_MS);
1405 if (dev->msg_level >= 2)
1406 devinfo (dev, "port %c, peer %sconnected",
1407 (status & STATUS_PORT_A) ? 'A' : 'B',
1408 (status & STATUS_CONN_OTHER) ? "" : "dis"
1417 static int net1080_check_connect (struct usbnet *dev)
1421 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1425 retval = nc_register_read (dev, REG_STATUS, vp);
1429 dbg ("%s net1080_check_conn read - %d", dev->net.name, retval);
1432 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1437 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1439 struct nc_header *header;
1440 struct nc_trailer *trailer;
1442 if (!(skb->len & 0x01)
1443 || MIN_FRAMED > skb->len
1444 || skb->len > FRAMED_SIZE (dev->net.mtu)) {
1445 dev->stats.rx_frame_errors++;
1446 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1447 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net.mtu),
1452 header = (struct nc_header *) skb->data;
1453 le16_to_cpus (&header->hdr_len);
1454 le16_to_cpus (&header->packet_len);
1455 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1456 dev->stats.rx_frame_errors++;
1457 dbg ("packet too big, %d", header->packet_len);
1459 } else if (header->hdr_len < MIN_HEADER) {
1460 dev->stats.rx_frame_errors++;
1461 dbg ("header too short, %d", header->hdr_len);
1463 } else if (header->hdr_len > MIN_HEADER) {
1464 // out of band data for us?
1465 dbg ("header OOB, %d bytes",
1466 header->hdr_len - MIN_HEADER);
1467 // switch (vendor/product ids) { ... }
1469 skb_pull (skb, header->hdr_len);
1471 trailer = (struct nc_trailer *)
1472 (skb->data + skb->len - sizeof *trailer);
1473 skb_trim (skb, skb->len - sizeof *trailer);
1475 if ((header->packet_len & 0x01) == 0) {
1476 if (skb->data [header->packet_len] != PAD_BYTE) {
1477 dev->stats.rx_frame_errors++;
1481 skb_trim (skb, skb->len - 1);
1483 if (skb->len != header->packet_len) {
1484 dev->stats.rx_frame_errors++;
1485 dbg ("bad packet len %d (expected %d)",
1486 skb->len, header->packet_len);
1489 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
1490 dev->stats.rx_fifo_errors++;
1491 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
1492 header->packet_id, trailer->packet_id);
1496 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
1497 header->packet_len, header->packet_id);
1502 static struct sk_buff *
1503 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1506 struct sk_buff *skb2;
1508 padlen = ((skb->len + sizeof (struct nc_header)
1509 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
1510 if (!skb_cloned (skb)) {
1511 int headroom = skb_headroom (skb);
1512 int tailroom = skb_tailroom (skb);
1514 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
1515 && sizeof (struct nc_header) <= headroom)
1518 if ((sizeof (struct nc_header) + padlen
1519 + sizeof (struct nc_trailer)) <
1520 (headroom + tailroom)) {
1521 skb->data = memmove (skb->head
1522 + sizeof (struct nc_header),
1523 skb->data, skb->len);
1524 skb->tail = skb->data + skb->len;
1528 skb2 = skb_copy_expand (skb,
1529 sizeof (struct nc_header),
1530 sizeof (struct nc_trailer) + padlen,
1532 dev_kfree_skb_any (skb);
1536 static const struct driver_info net1080_info = {
1537 .description = "NetChip TurboCONNECT",
1538 .flags = FLAG_FRAMING_NC,
1539 .reset = net1080_reset,
1540 .check_connect =net1080_check_connect,
1541 .rx_fixup = net1080_rx_fixup,
1542 .tx_fixup = net1080_tx_fixup,
1545 #endif /* CONFIG_USB_NET1080 */
1549 #ifdef CONFIG_USB_PL2301
1551 /*-------------------------------------------------------------------------
1553 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
1555 *-------------------------------------------------------------------------*/
1558 * Bits 0-4 can be used for software handshaking; they're set from
1559 * one end, cleared from the other, "read" with the interrupt byte.
1561 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
1562 /* reserved bit -- rx ready (6) ? */
1563 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
1564 #define PL_RESET_OUT (1<<4) /* reset output pipe */
1565 #define PL_RESET_IN (1<<3) /* reset input pipe */
1566 #define PL_TX_C (1<<2) /* transmission complete */
1567 #define PL_TX_REQ (1<<1) /* transmission received */
1568 #define PL_PEER_E (1<<0) /* peer exists */
1571 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
1573 return usb_control_msg (dev->udev,
1574 usb_rcvctrlpipe (dev->udev, 0),
1576 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1579 CONTROL_TIMEOUT_JIFFIES);
1583 pl_clear_QuickLink_features (struct usbnet *dev, int val)
1585 return pl_vendor_req (dev, 1, (u8) val, 0);
1589 pl_set_QuickLink_features (struct usbnet *dev, int val)
1591 return pl_vendor_req (dev, 3, (u8) val, 0);
1594 /*-------------------------------------------------------------------------*/
1596 static int pl_reset (struct usbnet *dev)
1598 return pl_set_QuickLink_features (dev,
1599 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
1602 static const struct driver_info prolific_info = {
1603 .description = "Prolific PL-2301/PL-2302",
1604 .flags = FLAG_NO_SETINT,
1605 /* some PL-2302 versions seem to fail usb_set_interface() */
1609 #endif /* CONFIG_USB_PL2301 */
1613 #ifdef CONFIG_USB_ARMLINUX
1615 /*-------------------------------------------------------------------------
1617 * Standard ARM kernels include a "usb-eth" driver, or a newer
1618 * "ethernet gadget" driver for basic USB connectivity. The vendor
1619 * and product code may also be used for other non-CDC Linux devices,
1620 * if they all maintain protocol compatibility.
1622 * That means lots of hardware could match here, possibly using
1623 * different endpoint numbers (and bcdVersion ids). so we rely on
1624 * endpoint descriptors to sort that out for us.
1626 * (Current Zaurus models need a different driver; see later.)
1628 *-------------------------------------------------------------------------*/
1630 static const struct driver_info linuxdev_info = {
1631 .description = "Linux Device",
1632 .check_connect = always_connected,
1635 static const struct driver_info yopy_info = {
1636 .description = "Yopy",
1637 .check_connect = always_connected,
1640 static const struct driver_info blob_info = {
1641 .description = "Boot Loader OBject",
1642 .check_connect = always_connected,
1645 #endif /* CONFIG_USB_ARMLINUX */
1648 #ifdef CONFIG_USB_ZAURUS
1650 #include <linux/crc32.h>
1652 /*-------------------------------------------------------------------------
1654 * Zaurus PDAs are also ARM based, but currently use different drivers
1655 * (and framing) for USB slave/gadget controllers than the case above.
1657 * For the current version of that driver, the main way that framing is
1658 * nonstandard (also from perspective of the CDC ethernet model!) is a
1659 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
1660 * haven't been fully worked around.
1662 *-------------------------------------------------------------------------*/
1664 static struct sk_buff *
1665 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1668 struct sk_buff *skb2;
1671 if (!skb_cloned (skb)) {
1672 int tailroom = skb_tailroom (skb);
1673 if ((padlen + 4) <= tailroom)
1676 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
1677 dev_kfree_skb_any (skb);
1682 fcs = crc32_le (~0, skb->data, skb->len);
1685 *skb_put (skb, 1) = fcs & 0xff;
1686 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
1687 *skb_put (skb, 1) = (fcs>>16) & 0xff;
1688 *skb_put (skb, 1) = (fcs>>24) & 0xff;
1694 static const struct driver_info zaurus_sl5x00_info = {
1695 .description = "Sharp Zaurus SL-5x00",
1696 .flags = FLAG_FRAMING_Z,
1697 .check_connect = always_connected,
1698 .tx_fixup = zaurus_tx_fixup,
1705 static const struct driver_info zaurus_pxa_info = {
1706 .description = "Sharp Zaurus, PXA-2xx based",
1707 .flags = FLAG_FRAMING_Z,
1708 .check_connect = always_connected,
1709 .tx_fixup = zaurus_tx_fixup,
1718 /*-------------------------------------------------------------------------
1720 * Network Device Driver (peer link to "Host Device", from USB host)
1722 *-------------------------------------------------------------------------*/
1724 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
1726 struct usbnet *dev = (struct usbnet *) net->priv;
1728 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
1730 #ifdef CONFIG_USB_NET1080
1731 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
1732 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
1736 #ifdef CONFIG_USB_GENESYS
1737 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
1738 && new_mtu > GL_MAX_PACKET_LEN)
1741 // no second zero-length packet read wanted after mtu-sized packets
1742 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
1748 /*-------------------------------------------------------------------------*/
1750 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
1752 return &((struct usbnet *) net->priv)->stats;
1755 /*-------------------------------------------------------------------------*/
1757 /* urb completions may be in_irq; avoid doing real work then. */
1759 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
1761 struct sk_buff_head *list = skb->list;
1762 unsigned long flags;
1764 spin_lock_irqsave (&list->lock, flags);
1765 __skb_unlink (skb, list);
1766 spin_unlock (&list->lock);
1767 spin_lock (&dev->done.lock);
1768 __skb_queue_tail (&dev->done, skb);
1769 if (dev->done.qlen == 1)
1770 tasklet_schedule (&dev->bh);
1771 spin_unlock_irqrestore (&dev->done.lock, flags);
1774 /* some work can't be done in tasklets, so we use keventd
1776 * NOTE: annoying asymmetry: if it's active, schedule_task() fails,
1777 * but tasklet_schedule() doesn't. hope the failure is rare.
1779 static void defer_kevent (struct usbnet *dev, int work)
1781 set_bit (work, &dev->flags);
1782 if (!schedule_task (&dev->kevent))
1783 err ("%s: kevent %d may have been dropped",
1784 dev->net.name, work);
1786 dbg ("%s: kevent %d scheduled", dev->net.name, work);
1789 /*-------------------------------------------------------------------------*/
1791 static void rx_complete (struct urb *urb);
1793 static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
1795 struct sk_buff *skb;
1796 struct skb_data *entry;
1798 unsigned long lockflags;
1801 #ifdef CONFIG_USB_NET1080
1802 if (dev->driver_info->flags & FLAG_FRAMING_NC)
1803 size = FRAMED_SIZE (dev->net.mtu);
1806 #ifdef CONFIG_USB_GENESYS
1807 if (dev->driver_info->flags & FLAG_FRAMING_GL)
1808 size = GL_RCV_BUF_SIZE;
1811 #ifdef CONFIG_USB_ZAURUS
1812 if (dev->driver_info->flags & FLAG_FRAMING_Z)
1813 size = 6 + (sizeof (struct ethhdr) + dev->net.mtu);
1816 size = (sizeof (struct ethhdr) + dev->net.mtu);
1818 if ((skb = alloc_skb (size, flags)) == 0) {
1820 defer_kevent (dev, EVENT_RX_MEMORY);
1825 entry = (struct skb_data *) skb->cb;
1828 entry->state = rx_start;
1831 usb_fill_bulk_urb (urb, dev->udev, dev->in,
1832 skb->data, size, rx_complete, skb);
1833 urb->transfer_flags |= USB_ASYNC_UNLINK;
1835 spin_lock_irqsave (&dev->rxq.lock, lockflags);
1837 if (netif_running (&dev->net)
1838 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
1839 switch (retval = SUBMIT_URB (urb, GFP_ATOMIC)){
1841 defer_kevent (dev, EVENT_RX_HALT);
1844 defer_kevent (dev, EVENT_RX_MEMORY);
1847 dbg ("%s rx submit, %d", dev->net.name, retval);
1848 tasklet_schedule (&dev->bh);
1851 __skb_queue_tail (&dev->rxq, skb);
1854 dbg ("rx: stopped");
1857 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
1859 dev_kfree_skb_any (skb);
1865 /*-------------------------------------------------------------------------*/
1867 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
1869 if (dev->driver_info->rx_fixup
1870 && !dev->driver_info->rx_fixup (dev, skb))
1872 // else network stack removes extra byte if we forced a short packet
1877 skb->dev = &dev->net;
1878 skb->protocol = eth_type_trans (skb, &dev->net);
1879 dev->stats.rx_packets++;
1880 dev->stats.rx_bytes += skb->len;
1883 devdbg (dev, "< rx, len %d, type 0x%x",
1884 skb->len + sizeof (struct ethhdr), skb->protocol);
1886 memset (skb->cb, 0, sizeof (struct skb_data));
1887 status = netif_rx (skb);
1888 if (status != NET_RX_SUCCESS)
1889 devdbg (dev, "netif_rx status %d", status);
1893 dev->stats.rx_errors++;
1894 skb_queue_tail (&dev->done, skb);
1898 /*-------------------------------------------------------------------------*/
1900 static void rx_complete (struct urb *urb)
1902 struct sk_buff *skb = (struct sk_buff *) urb->context;
1903 struct skb_data *entry = (struct skb_data *) skb->cb;
1904 struct usbnet *dev = entry->dev;
1905 int urb_status = urb->status;
1907 skb_put (skb, urb->actual_length);
1908 entry->state = rx_done;
1911 switch (urb_status) {
1914 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
1915 entry->state = rx_cleanup;
1916 dev->stats.rx_errors++;
1917 dev->stats.rx_length_errors++;
1918 dbg ("rx length %d", skb->len);
1922 // stalls need manual reset. this is rare ... except that
1923 // when going through USB 2.0 TTs, unplug appears this way.
1924 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
1925 // storm, recovering as needed.
1927 defer_kevent (dev, EVENT_RX_HALT);
1930 // software-driven interface shutdown
1931 case -ECONNRESET: // according to API spec
1932 case -ECONNABORTED: // some (now fixed?) UHCI bugs
1933 dbg ("%s rx shutdown, code %d", dev->net.name, urb_status);
1934 entry->state = rx_cleanup;
1935 // do urb frees only in the tasklet (UHCI has oopsed ...)
1940 // data overrun ... flush fifo?
1942 dev->stats.rx_over_errors++;
1946 // on unplug we get ETIMEDOUT (ohci) or EILSEQ (uhci)
1947 // until khubd sees its interrupt and disconnects us.
1948 // that can easily be hundreds of passes through here.
1949 entry->state = rx_cleanup;
1950 dev->stats.rx_errors++;
1951 dbg ("%s rx: status %d", dev->net.name, urb_status);
1955 defer_bh (dev, skb);
1958 if (netif_running (&dev->net)
1959 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
1960 rx_submit (dev, urb, GFP_ATOMIC);
1966 dbg ("no read resubmitted");
1967 #endif /* VERBOSE */
1970 /*-------------------------------------------------------------------------*/
1972 // unlink pending rx/tx; completion handlers do all other cleanup
1974 static int unlink_urbs (struct sk_buff_head *q)
1976 unsigned long flags;
1977 struct sk_buff *skb, *skbnext;
1980 spin_lock_irqsave (&q->lock, flags);
1981 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
1982 struct skb_data *entry;
1986 entry = (struct skb_data *) skb->cb;
1988 skbnext = skb->next;
1990 // during some PM-driven resume scenarios,
1991 // these (async) unlinks complete immediately
1992 retval = usb_unlink_urb (urb);
1993 if (retval != -EINPROGRESS && retval != 0)
1994 dbg ("unlink urb err, %d", retval);
1998 spin_unlock_irqrestore (&q->lock, flags);
2003 /*-------------------------------------------------------------------------*/
2005 // precondition: never called in_interrupt
2007 static int usbnet_stop (struct net_device *net)
2009 struct usbnet *dev = (struct usbnet *) net->priv;
2011 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2012 DECLARE_WAITQUEUE (wait, current);
2014 mutex_lock (&dev->mutex);
2015 netif_stop_queue (net);
2017 if (dev->msg_level >= 2)
2018 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2019 dev->stats.rx_packets, dev->stats.tx_packets,
2020 dev->stats.rx_errors, dev->stats.tx_errors
2023 // ensure there are no more active urbs
2024 add_wait_queue (&unlink_wakeup, &wait);
2025 dev->wait = &unlink_wakeup;
2026 temp = unlink_urbs (&dev->txq) + unlink_urbs (&dev->rxq);
2028 // maybe wait for deletions to finish.
2029 while (skb_queue_len (&dev->rxq)
2030 && skb_queue_len (&dev->txq)
2031 && skb_queue_len (&dev->done)) {
2032 set_current_state (TASK_UNINTERRUPTIBLE);
2033 schedule_timeout (UNLINK_TIMEOUT_JIFFIES);
2034 dbg ("waited for %d urb completions", temp);
2037 remove_wait_queue (&unlink_wakeup, &wait);
2039 mutex_unlock (&dev->mutex);
2043 /*-------------------------------------------------------------------------*/
2045 // posts reads, and enables write queing
2047 // precondition: never called in_interrupt
2049 static int usbnet_open (struct net_device *net)
2051 struct usbnet *dev = (struct usbnet *) net->priv;
2053 struct driver_info *info = dev->driver_info;
2055 mutex_lock (&dev->mutex);
2057 // put into "known safe" state
2058 if (info->reset && (retval = info->reset (dev)) < 0) {
2059 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2061 dev->udev->bus->bus_name, dev->udev->devpath,
2066 // insist peer be connected
2067 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2068 devdbg (dev, "can't open; %d", retval);
2072 netif_start_queue (net);
2073 if (dev->msg_level >= 2)
2074 devinfo (dev, "open: enable queueing "
2075 "(rx %d, tx %d) mtu %d %s framing",
2076 RX_QLEN, TX_QLEN, dev->net.mtu,
2077 (info->flags & (FLAG_FRAMING_NC | FLAG_FRAMING_GL))
2078 ? ((info->flags & FLAG_FRAMING_NC)
2084 // delay posting reads until we're fully open
2085 tasklet_schedule (&dev->bh);
2087 mutex_unlock (&dev->mutex);
2091 /*-------------------------------------------------------------------------*/
2093 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2095 struct usbnet *dev = net->priv;
2097 strncpy (info->driver, driver_name, sizeof info->driver);
2098 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2099 strncpy (info->fw_version, dev->driver_info->description,
2100 sizeof info->fw_version);
2101 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2104 static u32 usbnet_get_link (struct net_device *net)
2106 struct usbnet *dev = net->priv;
2108 /* If a check_connect is defined, return it's results */
2109 if (dev->driver_info->check_connect)
2110 return dev->driver_info->check_connect (dev) == 0;
2112 /* Otherwise, we're up to avoid breaking scripts */
2116 static u32 usbnet_get_msglevel (struct net_device *net)
2118 struct usbnet *dev = net->priv;
2120 return dev->msg_level;
2123 static void usbnet_set_msglevel (struct net_device *net, u32 level)
2125 struct usbnet *dev = net->priv;
2127 dev->msg_level = level;
2130 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2134 struct usbnet *dev = (struct usbnet *)net->priv;
2136 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2137 return generic_mii_ioctl(&dev->mii,
2138 (struct mii_ioctl_data *) &rq->ifr_data,
2145 /*-------------------------------------------------------------------------*/
2147 /* work that cannot be done in interrupt context uses keventd.
2149 * NOTE: "uhci" and "usb-uhci" may have trouble with this since they don't
2150 * queue control transfers to individual devices, and other threads could
2151 * trigger control requests concurrently. hope that's rare.
2156 struct usbnet *dev = data;
2159 /* usb_clear_halt() needs a thread context */
2160 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2161 unlink_urbs (&dev->txq);
2162 status = usb_clear_halt (dev->udev, dev->out);
2164 err ("%s: can't clear tx halt, status %d",
2165 dev->net.name, status);
2167 clear_bit (EVENT_TX_HALT, &dev->flags);
2168 netif_wake_queue (&dev->net);
2171 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2172 unlink_urbs (&dev->rxq);
2173 status = usb_clear_halt (dev->udev, dev->in);
2175 err ("%s: can't clear rx halt, status %d",
2176 dev->net.name, status);
2178 clear_bit (EVENT_RX_HALT, &dev->flags);
2179 tasklet_schedule (&dev->bh);
2183 /* tasklet could resubmit itself forever if memory is tight */
2184 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2185 struct urb *urb = 0;
2187 if (netif_running (&dev->net))
2188 urb = ALLOC_URB (0, GFP_KERNEL);
2190 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2192 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2193 rx_submit (dev, urb, GFP_KERNEL);
2194 tasklet_schedule (&dev->bh);
2199 dbg ("%s: kevent done, flags = 0x%lx",
2200 dev->net.name, dev->flags);
2203 /*-------------------------------------------------------------------------*/
2205 static void tx_complete (struct urb *urb)
2207 struct sk_buff *skb = (struct sk_buff *) urb->context;
2208 struct skb_data *entry = (struct skb_data *) skb->cb;
2209 struct usbnet *dev = entry->dev;
2211 if (urb->status == -EPIPE)
2212 defer_kevent (dev, EVENT_TX_HALT);
2214 entry->state = tx_done;
2215 defer_bh (dev, skb);
2218 /*-------------------------------------------------------------------------*/
2220 static void usbnet_tx_timeout (struct net_device *net)
2222 struct usbnet *dev = (struct usbnet *) net->priv;
2224 unlink_urbs (&dev->txq);
2225 tasklet_schedule (&dev->bh);
2227 // FIXME: device recovery -- reset?
2230 /*-------------------------------------------------------------------------*/
2232 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2234 struct usbnet *dev = (struct usbnet *) net->priv;
2236 int retval = NET_XMIT_SUCCESS;
2237 struct urb *urb = 0;
2238 struct skb_data *entry;
2239 struct driver_info *info = dev->driver_info;
2240 unsigned long flags;
2241 #ifdef CONFIG_USB_NET1080
2242 struct nc_header *header = 0;
2243 struct nc_trailer *trailer = 0;
2244 #endif /* CONFIG_USB_NET1080 */
2246 // some devices want funky USB-level framing, for
2247 // win32 driver (usually) and/or hardware quirks
2248 if (info->tx_fixup) {
2249 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2251 dbg ("can't tx_fixup skb");
2257 if (!(urb = ALLOC_URB (0, GFP_ATOMIC))) {
2262 entry = (struct skb_data *) skb->cb;
2265 entry->state = tx_start;
2266 entry->length = length;
2268 // FIXME: reorganize a bit, so that fixup() fills out NetChip
2269 // framing too. (Packet ID update needs the spinlock...)
2270 // [ BETTER: we already own net->xmit_lock, that's enough ]
2272 #ifdef CONFIG_USB_NET1080
2273 if (info->flags & FLAG_FRAMING_NC) {
2274 header = (struct nc_header *) skb_push (skb, sizeof *header);
2275 header->hdr_len = cpu_to_le16 (sizeof (*header));
2276 header->packet_len = cpu_to_le16 (length);
2277 if (!((skb->len + sizeof *trailer) & 0x01))
2278 *skb_put (skb, 1) = PAD_BYTE;
2279 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2281 #endif /* CONFIG_USB_NET1080 */
2283 /* don't assume the hardware handles USB_ZERO_PACKET */
2284 if ((length % dev->maxpacket) == 0)
2287 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2288 skb->data, skb->len, tx_complete, skb);
2289 urb->transfer_flags |= USB_ASYNC_UNLINK;
2291 spin_lock_irqsave (&dev->txq.lock, flags);
2293 #ifdef CONFIG_USB_NET1080
2294 if (info->flags & FLAG_FRAMING_NC) {
2295 header->packet_id = cpu_to_le16 (dev->packet_id++);
2296 put_unaligned (header->packet_id, &trailer->packet_id);
2298 devdbg (dev, "frame >tx h %d p %d id %d",
2299 header->hdr_len, header->packet_len,
2303 #endif /* CONFIG_USB_NET1080 */
2305 switch ((retval = SUBMIT_URB (urb, GFP_ATOMIC))) {
2307 netif_stop_queue (net);
2308 defer_kevent (dev, EVENT_TX_HALT);
2311 dbg ("%s tx: submit urb err %d", net->name, retval);
2314 net->trans_start = jiffies;
2315 __skb_queue_tail (&dev->txq, skb);
2316 if (dev->txq.qlen >= TX_QLEN)
2317 netif_stop_queue (net);
2319 spin_unlock_irqrestore (&dev->txq.lock, flags);
2322 devdbg (dev, "drop, code %d", retval);
2324 retval = NET_XMIT_SUCCESS;
2325 dev->stats.tx_dropped++;
2327 dev_kfree_skb_any (skb);
2331 devdbg (dev, "> tx, len %d, type 0x%x",
2332 length, skb->protocol);
2339 /*-------------------------------------------------------------------------*/
2341 // tasklet ... work that avoided running in_irq()
2343 static void usbnet_bh (unsigned long param)
2345 struct usbnet *dev = (struct usbnet *) param;
2346 struct sk_buff *skb;
2347 struct skb_data *entry;
2349 while ((skb = skb_dequeue (&dev->done))) {
2350 entry = (struct skb_data *) skb->cb;
2351 switch (entry->state) {
2353 entry->state = rx_cleanup;
2354 rx_process (dev, skb);
2357 if (entry->urb->status) {
2358 // can this statistic become more specific?
2359 dev->stats.tx_errors++;
2360 dbg ("%s tx: err %d", dev->net.name,
2361 entry->urb->status);
2363 dev->stats.tx_packets++;
2364 dev->stats.tx_bytes += entry->length;
2368 usb_free_urb (entry->urb);
2369 dev_kfree_skb (skb);
2372 dbg ("%s: bogus skb state %d",
2373 dev->net.name, entry->state);
2377 // waiting for all pending urbs to complete?
2379 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
2380 wake_up (dev->wait);
2383 // or are we maybe short a few urbs?
2384 } else if (netif_running (&dev->net)
2385 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2386 int temp = dev->rxq.qlen;
2388 if (temp < RX_QLEN) {
2391 for (i = 0; i < 3 && dev->rxq.qlen < RX_QLEN; i++) {
2392 if ((urb = ALLOC_URB (0, GFP_ATOMIC)) != 0)
2393 rx_submit (dev, urb, GFP_ATOMIC);
2395 if (temp != dev->rxq.qlen)
2396 devdbg (dev, "rxqlen %d --> %d",
2397 temp, dev->rxq.qlen);
2398 if (dev->rxq.qlen < RX_QLEN)
2399 tasklet_schedule (&dev->bh);
2401 if (dev->txq.qlen < TX_QLEN)
2402 netif_wake_queue (&dev->net);
2408 /*-------------------------------------------------------------------------
2410 * USB Device Driver support
2412 *-------------------------------------------------------------------------*/
2414 // precondition: never called in_interrupt
2416 static void usbnet_disconnect (struct usb_device *udev, void *ptr)
2418 struct usbnet *dev = (struct usbnet *) ptr;
2420 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
2421 udev->bus->bus_name, udev->devpath,
2422 dev->driver_info->description);
2424 unregister_netdev (&dev->net);
2426 mutex_lock (&usbnet_mutex);
2427 mutex_lock (&dev->mutex);
2428 list_del (&dev->dev_list);
2429 mutex_unlock (&usbnet_mutex);
2431 // assuming we used keventd, it must quiesce too
2432 flush_scheduled_tasks ();
2439 /*-------------------------------------------------------------------------*/
2441 // precondition: never called in_interrupt
2444 usbnet_probe (struct usb_device *udev, unsigned ifnum,
2445 const struct usb_device_id *prod)
2448 struct net_device *net;
2449 struct driver_info *info;
2453 info = (struct driver_info *) prod->driver_info;
2455 #ifdef CONFIG_USB_ZAURUS
2456 if (info == &zaurus_sl5x00_info) {
2459 /* old ROMs have more than one config
2460 * so we have to make sure config="1" (?)
2462 status = usb_set_configuration (udev, 1);
2464 err ("set_config failed, %d", status);
2471 // more sanity (unless the device is broken)
2472 if (!(info->flags & FLAG_NO_SETINT)) {
2473 if (usb_set_interface (udev, ifnum, altnum) < 0) {
2474 err ("set_interface failed");
2479 // set up our own records
2480 if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) {
2481 dbg ("can't kmalloc dev");
2484 memset (dev, 0, sizeof *dev);
2486 init_MUTEX_LOCKED (&dev->mutex);
2489 dev->driver_info = info;
2490 dev->msg_level = msg_level;
2491 INIT_LIST_HEAD (&dev->dev_list);
2492 skb_queue_head_init (&dev->rxq);
2493 skb_queue_head_init (&dev->txq);
2494 skb_queue_head_init (&dev->done);
2495 dev->bh.func = usbnet_bh;
2496 dev->bh.data = (unsigned long) dev;
2497 INIT_TQUEUE (&dev->kevent, kevent, dev);
2499 // set up network interface records
2501 SET_MODULE_OWNER (net);
2503 strcpy (net->name, "usb%d");
2504 memcpy (net->dev_addr, node_id, sizeof node_id);
2506 // point-to-point link ... we always use Ethernet headers
2507 // supports win32 interop and the bridge driver.
2510 net->change_mtu = usbnet_change_mtu;
2511 net->get_stats = usbnet_get_stats;
2512 net->hard_start_xmit = usbnet_start_xmit;
2513 net->open = usbnet_open;
2514 net->stop = usbnet_stop;
2515 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
2516 net->tx_timeout = usbnet_tx_timeout;
2517 net->do_ioctl = usbnet_ioctl;
2518 net->ethtool_ops = &usbnet_ethtool_ops;
2520 // allow device-specific bind/init procedures
2521 // NOTE net->name still not usable ...
2523 status = info->bind (dev, udev);
2524 // heuristic: "usb%d" for links we know are two-host,
2525 // else "eth%d" when there's reasonable doubt. userspace
2526 // can rename the link if it knows better.
2527 if ((dev->driver_info->flags & FLAG_ETHER) != 0
2528 && (net->dev_addr [0] & 0x02) == 0)
2529 strcpy (net->name, "eth%d");
2530 } else if (!info->in || info->out)
2531 status = get_endpoints (dev, udev->actconfig->interface + ifnum);
2533 dev->in = usb_rcvbulkpipe (udev, info->in);
2534 dev->out = usb_sndbulkpipe (udev, info->out);
2537 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
2539 register_netdev (&dev->net);
2540 devinfo (dev, "register usbnet usb-%s-%s, %s",
2541 udev->bus->bus_name, udev->devpath,
2542 dev->driver_info->description);
2544 // ok, it's ready to go.
2545 mutex_lock (&usbnet_mutex);
2546 list_add (&dev->dev_list, &usbnet_list);
2547 mutex_unlock (&dev->mutex);
2549 // start as if the link is up
2550 netif_device_attach (&dev->net);
2552 mutex_unlock (&usbnet_mutex);
2557 /*-------------------------------------------------------------------------*/
2560 * chip vendor names won't normally be on the cables, and
2561 * may not be on the device.
2564 static const struct usb_device_id products [] = {
2566 #ifdef CONFIG_USB_AN2720
2568 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
2569 .driver_info = (unsigned long) &an2720_info,
2571 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
2572 .driver_info = (unsigned long) &an2720_info,
2576 #ifdef CONFIG_USB_AX8817X
2579 USB_DEVICE (0x077b, 0x2226),
2580 .driver_info = (unsigned long) &ax8817x_info,
2583 USB_DEVICE (0x0846, 0x1040),
2584 .driver_info = (unsigned long) &netgear_fa120_info,
2587 USB_DEVICE (0x2001, 0x1a00),
2588 .driver_info = (unsigned long) &dlink_dub_e100_info,
2590 // Intellinet, ST Lab USB Ethernet
2591 USB_DEVICE (0x0b95, 0x1720),
2592 .driver_info = (unsigned long) &ax8817x_info,
2594 // Hawking UF200, TrendNet TU2-ET100
2595 USB_DEVICE (0x07b8, 0x420a),
2596 .driver_info = (unsigned long) &hawking_uf200_info,
2599 USB_DEVICE (0x0557, 0x2009),
2600 .driver_info = (unsigned long) &ax8817x_info,
2604 #ifdef CONFIG_USB_BELKIN
2606 USB_DEVICE (0x050d, 0x0004), // Belkin
2607 .driver_info = (unsigned long) &belkin_info,
2609 USB_DEVICE (0x056c, 0x8100), // eTEK
2610 .driver_info = (unsigned long) &belkin_info,
2612 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
2613 .driver_info = (unsigned long) &belkin_info,
2617 #ifdef CONFIG_USB_EPSON2888
2619 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
2620 .driver_info = (unsigned long) &epson2888_info,
2624 #ifdef CONFIG_USB_GENESYS
2626 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
2627 .driver_info = (unsigned long) &genelink_info,
2629 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
2630 * that's half duplex, not currently supported
2634 #ifdef CONFIG_USB_NET1080
2636 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
2637 .driver_info = (unsigned long) &net1080_info,
2639 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
2640 .driver_info = (unsigned long) &net1080_info,
2644 #ifdef CONFIG_USB_PL2301
2646 USB_DEVICE (0x067b, 0x0000), // PL-2301
2647 .driver_info = (unsigned long) &prolific_info,
2649 USB_DEVICE (0x067b, 0x0001), // PL-2302
2650 .driver_info = (unsigned long) &prolific_info,
2654 #ifdef CONFIG_USB_ARMLINUX
2656 * SA-1100 using standard ARM Linux kernels, or compatible.
2657 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
2658 * The sa-1100 "usb-eth" driver handles the basic framing.
2661 * PXA2xx using usb "gadget" driver, or older "usb-eth" much like
2662 * the sa1100 one. (But PXA hardware uses different endpoints.)
2666 // 1183 = 0x049F, both used as hex values?
2667 // Compaq "Itsy" vendor/product id
2668 // version numbers vary, along with endpoint usage
2669 // but otherwise they're protocol-compatible
2670 USB_DEVICE (0x049F, 0x505A),
2671 .driver_info = (unsigned long) &linuxdev_info,
2673 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
2674 .driver_info = (unsigned long) &yopy_info,
2676 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
2677 .driver_info = (unsigned long) &blob_info,
2681 #ifdef CONFIG_USB_ZAURUS
2683 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
2684 * Same idea as above, but different framing.
2687 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2688 | USB_DEVICE_ID_MATCH_DEVICE,
2690 .idProduct = 0x8004,
2691 .bInterfaceClass = 0x0a,
2692 .bInterfaceSubClass = 0x00,
2693 .bInterfaceProtocol = 0x00,
2694 .driver_info = (unsigned long) &zaurus_sl5x00_info,
2696 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2697 | USB_DEVICE_ID_MATCH_DEVICE,
2699 .idProduct = 0x8005, /* A-300 */
2700 .bInterfaceClass = 0x02,
2701 .bInterfaceSubClass = 0x0a,
2702 .bInterfaceProtocol = 0x00,
2703 .driver_info = (unsigned long) &zaurus_pxa_info,
2705 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2706 | USB_DEVICE_ID_MATCH_DEVICE,
2708 .idProduct = 0x8006, /* B-500/SL-5600 */
2709 .bInterfaceClass = 0x02,
2710 .bInterfaceSubClass = 0x0a,
2711 .bInterfaceProtocol = 0x00,
2712 .driver_info = (unsigned long) &zaurus_pxa_info,
2714 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2715 | USB_DEVICE_ID_MATCH_DEVICE,
2717 .idProduct = 0x8007, /* C-700 */
2718 .bInterfaceClass = 0x02,
2719 .bInterfaceSubClass = 0x0a,
2720 .bInterfaceProtocol = 0x00,
2721 .driver_info = (unsigned long) &zaurus_pxa_info,
2723 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2724 | USB_DEVICE_ID_MATCH_DEVICE,
2726 .idProduct = 0x9031, /* C-750 C-760 */
2727 .bInterfaceClass = 0x02,
2728 .bInterfaceSubClass = 0x0a,
2729 .bInterfaceProtocol = 0x00,
2730 .driver_info = (unsigned long) &zaurus_pxa_info,
2732 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2733 | USB_DEVICE_ID_MATCH_DEVICE,
2735 .idProduct = 0x9032, /* SL-6000 */
2736 .bInterfaceClass = 0x02,
2737 .bInterfaceSubClass = 0x0a,
2738 .bInterfaceProtocol = 0x00,
2739 .driver_info = (unsigned long) &zaurus_pxa_info,
2745 MODULE_DEVICE_TABLE (usb, products);
2747 static struct usb_driver usbnet_driver = {
2748 .name = driver_name,
2749 .id_table = products,
2750 .probe = usbnet_probe,
2751 .disconnect = usbnet_disconnect,
2754 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
2755 static struct ethtool_ops usbnet_ethtool_ops = {
2756 .get_drvinfo = usbnet_get_drvinfo,
2757 .get_link = usbnet_get_link,
2758 .get_msglevel = usbnet_get_msglevel,
2759 .set_msglevel = usbnet_set_msglevel,
2761 /*-------------------------------------------------------------------------*/
2763 static int __init usbnet_init (void)
2765 // compiler should optimize this out
2766 if (sizeof (((struct sk_buff *)0)->cb) < sizeof (struct skb_data))
2769 get_random_bytes (node_id, sizeof node_id);
2770 node_id [0] &= 0xfe; // clear multicast bit
2771 node_id [0] |= 0x02; // set local assignment bit (IEEE802)
2773 if (usb_register (&usbnet_driver) < 0)
2778 module_init (usbnet_init);
2780 static void __exit usbnet_exit (void)
2782 usb_deregister (&usbnet_driver);
2784 module_exit (usbnet_exit);
2787 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
2788 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
2789 MODULE_LICENSE ("GPL");