MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / usbnet.c
blobcca6e72cf2fab8e90998bc8108bda9bfd68bbf99
1 /*
2 * USB Networking Links
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.
29 * - AnchorChip 2720
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
55 * within devices.
58 * CHANGELOG:
60 * 13-sep-2000 experimental, new
61 * 10-oct-2000 usb_device_id table created.
62 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
63 * 01-nov-2000 usb_device_id table and probing api update by
64 * Adam J. Richter <adam@yggdrasil.com>.
65 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
66 * and prolific support, isolate net1080-specific bits, cleanup.
67 * fix unlink_urbs oops in D3 PM resume code path.
69 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
70 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
71 * AnchorChips 2720 support (from spec) for testing;
72 * fix bit-ordering problem with ethernet multicast addr
73 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
74 * updates. Oleg Drokin (green@iXcelerator.com)
75 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
76 * expecting cleared skb->cb and framing change to match latest
77 * handhelds.org version (Oleg). Enable device IDs from the
78 * Win32 Belkin driver; other cleanups (db).
79 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
80 * cleanups for problems not yet seen in the field. (db)
81 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
82 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
83 * rx unlinks somehow weren't async; minor cleanup.
84 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
85 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
86 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
87 * tie mostly to (sub)driver info. Workaround some PL-2302
88 * chips that seem to reject SET_INTERFACE requests.
90 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
91 * Level of diagnostics is more configurable; they use device
92 * location (usb_device->devpath) instead of address (2.5).
93 * For tx_fixup, memflags can't be NOIO.
94 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
95 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
96 * Use "locally assigned" IEEE802 address space. (Brad Hards)
97 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
98 * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
99 * cleanups and stubbed PXA-250 support (db), fix for framing
100 * issues on Z, net1080, and gl620a (Toby Milne)
102 * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
103 * vs pxa25x, and CDC Ethernet. Throttle down log floods on
104 * disconnect; other cleanups. (db) Flush net1080 fifos
105 * after several sequential framing errors. (Johannes Erdfelt)
106 * 22-aug-2003 AX8817X support (Dave Hollis).
107 * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
108 * (Neil Bortnak)
110 *-------------------------------------------------------------------------*/
112 // #define DEBUG // error path messages, extra info
113 // #define VERBOSE // more; success messages
115 #include <linux/config.h>
116 #ifdef CONFIG_USB_DEBUG
117 # define DEBUG
118 #endif
119 #include <linux/module.h>
120 #include <linux/kmod.h>
121 #include <linux/sched.h>
122 #include <linux/init.h>
123 #include <linux/netdevice.h>
124 #include <linux/etherdevice.h>
125 #include <linux/random.h>
126 #include <linux/ethtool.h>
127 #include <linux/workqueue.h>
128 #include <linux/mii.h>
129 #include <asm/uaccess.h>
130 #include <asm/unaligned.h>
131 #include <linux/usb.h>
132 #include <asm/io.h>
133 #include <asm/scatterlist.h>
134 #include <linux/mm.h>
135 #include <linux/dma-mapping.h>
137 #define DRIVER_VERSION "25-Aug-2003"
140 /*-------------------------------------------------------------------------*/
143 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
144 * Several dozen bytes of IPv4 data can fit in two such transactions.
145 * One maximum size Ethernet packet takes twenty four of them.
146 * For high speed, each frame comfortably fits almost 36 max size
147 * Ethernet packets (so queues should be bigger).
149 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
150 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
152 // packets are always ethernet inside
153 // ... except they can be bigger (limit of 64K with NetChip framing)
154 #define MIN_PACKET sizeof(struct ethhdr)
155 #define MAX_PACKET 32768
157 // reawaken network queue this soon after stopping; else watchdog barks
158 #define TX_TIMEOUT_JIFFIES (5*HZ)
160 // throttle rx/tx briefly after some faults, so khubd might disconnect()
161 // us (it polls at HZ/4 usually) before we report too many false errors.
162 #define THROTTLE_JIFFIES (HZ/8)
164 // for vendor-specific control operations
165 #define CONTROL_TIMEOUT_MS (500) /* msec */
166 #define CONTROL_TIMEOUT_JIFFIES ((CONTROL_TIMEOUT_MS * HZ)/1000)
168 // between wakeups
169 #define UNLINK_TIMEOUT_MS 3
171 /*-------------------------------------------------------------------------*/
173 // randomly generated ethernet address
174 static u8 node_id [ETH_ALEN];
176 // state we keep for each device we handle
177 struct usbnet {
178 // housekeeping
179 struct usb_device *udev;
180 struct driver_info *driver_info;
181 wait_queue_head_t *wait;
183 // i/o info: pipes etc
184 unsigned in, out;
185 unsigned maxpacket;
186 struct timer_list delay;
188 // protocol/interface state
189 struct net_device *net;
190 struct net_device_stats stats;
191 int msg_level;
192 unsigned long data [5];
194 struct mii_if_info mii;
196 // various kinds of pending driver work
197 struct sk_buff_head rxq;
198 struct sk_buff_head txq;
199 struct sk_buff_head done;
200 struct tasklet_struct bh;
202 struct work_struct kevent;
203 unsigned long flags;
204 # define EVENT_TX_HALT 0
205 # define EVENT_RX_HALT 1
206 # define EVENT_RX_MEMORY 2
209 // device-specific info used by the driver
210 struct driver_info {
211 char *description;
213 int flags;
214 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
215 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
216 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
217 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
218 #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
220 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
221 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
223 /* init device ... can sleep, or cause probe() failure */
224 int (*bind)(struct usbnet *, struct usb_interface *);
226 /* cleanup device ... can sleep, but can't fail */
227 void (*unbind)(struct usbnet *, struct usb_interface *);
229 /* reset device ... can sleep */
230 int (*reset)(struct usbnet *);
232 /* see if peer is connected ... can sleep */
233 int (*check_connect)(struct usbnet *);
235 /* fixup rx packet (strip framing) */
236 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
238 /* fixup tx packet (add framing) */
239 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
240 struct sk_buff *skb, int flags);
242 // FIXME -- also an interrupt mechanism
243 // useful for at least PL2301/2302 and GL620USB-A
244 // and CDC use them to report 'is it connected' changes
246 /* for new devices, use the descriptor-reading code instead */
247 int in; /* rx endpoint */
248 int out; /* tx endpoint */
250 unsigned long data; /* Misc driver specific data */
253 // we record the state for each of our queued skbs
254 enum skb_state {
255 illegal = 0,
256 tx_start, tx_done,
257 rx_start, rx_done, rx_cleanup
260 struct skb_data { // skb->cb is one of these
261 struct urb *urb;
262 struct usbnet *dev;
263 enum skb_state state;
264 size_t length;
267 static const char driver_name [] = "usbnet";
269 /* use ethtool to change the level for any given device */
270 static int msg_level = 1;
271 module_param (msg_level, int, 0);
272 MODULE_PARM_DESC (msg_level, "Initial message level (default = 1)");
275 #define RUN_CONTEXT (in_irq () ? "in_irq" \
276 : (in_interrupt () ? "in_interrupt" : "can sleep"))
278 #ifdef DEBUG
279 #define devdbg(usbnet, fmt, arg...) \
280 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
281 #else
282 #define devdbg(usbnet, fmt, arg...) do {} while(0)
283 #endif
285 #define deverr(usbnet, fmt, arg...) \
286 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
287 #define devwarn(usbnet, fmt, arg...) \
288 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
290 #define devinfo(usbnet, fmt, arg...) \
291 do { if ((usbnet)->msg_level >= 1) \
292 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
293 } while (0)
295 /*-------------------------------------------------------------------------*/
297 static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
298 static u32 usbnet_get_link (struct net_device *);
299 static u32 usbnet_get_msglevel (struct net_device *);
300 static void usbnet_set_msglevel (struct net_device *, u32);
302 /* mostly for PDA style devices, which are always connected if present */
303 static int always_connected (struct usbnet *dev)
305 return 0;
308 /* handles CDC Ethernet and many other network "bulk data" interfaces */
309 static int
310 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
312 int tmp;
313 struct usb_host_interface *alt;
314 struct usb_host_endpoint *in, *out;
316 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
317 unsigned ep;
319 in = out = NULL;
320 alt = intf->altsetting + tmp;
322 /* take the first altsetting with in-bulk + out-bulk;
323 * ignore other endpoints and altsetttings.
325 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
326 struct usb_host_endpoint *e;
328 e = alt->endpoint + ep;
329 if (e->desc.bmAttributes != USB_ENDPOINT_XFER_BULK)
330 continue;
331 if (e->desc.bEndpointAddress & USB_DIR_IN) {
332 if (!in)
333 in = e;
334 } else {
335 if (!out)
336 out = e;
338 if (in && out)
339 goto found;
342 return -EINVAL;
344 found:
345 if (alt->desc.bAlternateSetting != 0
346 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
347 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
348 alt->desc.bAlternateSetting);
349 if (tmp < 0)
350 return tmp;
353 dev->in = usb_rcvbulkpipe (dev->udev,
354 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
355 dev->out = usb_sndbulkpipe (dev->udev,
356 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
357 return 0;
360 static void skb_return (struct usbnet *dev, struct sk_buff *skb)
362 int status;
364 skb->dev = dev->net;
365 skb->protocol = eth_type_trans (skb, dev->net);
366 dev->stats.rx_packets++;
367 dev->stats.rx_bytes += skb->len;
369 #ifdef VERBOSE
370 devdbg (dev, "< rx, len %d, type 0x%x",
371 skb->len + sizeof (struct ethhdr), skb->protocol);
372 #endif
373 memset (skb->cb, 0, sizeof (struct skb_data));
374 status = netif_rx (skb);
375 if (status != NET_RX_SUCCESS)
376 devdbg (dev, "netif_rx status %d", status);
380 #ifdef CONFIG_USB_ALI_M5632
381 #define HAVE_HARDWARE
383 /*-------------------------------------------------------------------------
385 * ALi M5632 driver ... does high speed
387 *-------------------------------------------------------------------------*/
389 static const struct driver_info ali_m5632_info = {
390 .description = "ALi M5632",
394 #endif
397 #ifdef CONFIG_USB_AN2720
398 #define HAVE_HARDWARE
400 /*-------------------------------------------------------------------------
402 * AnchorChips 2720 driver ... http://www.cypress.com
404 * This doesn't seem to have a way to detect whether the peer is
405 * connected, or need any reset handshaking. It's got pretty big
406 * internal buffers (handles most of a frame's worth of data).
407 * Chip data sheets don't describe any vendor control messages.
409 *-------------------------------------------------------------------------*/
411 static const struct driver_info an2720_info = {
412 .description = "AnchorChips/Cypress 2720",
413 // no reset available!
414 // no check_connect available!
416 .in = 2, .out = 2, // direction distinguishes these
419 #endif /* CONFIG_USB_AN2720 */
422 #ifdef CONFIG_USB_AX8817X
423 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
425 #define HAVE_HARDWARE
426 #define NEED_MII
428 #include <linux/crc32.h>
430 #define AX_CMD_SET_SW_MII 0x06
431 #define AX_CMD_READ_MII_REG 0x07
432 #define AX_CMD_WRITE_MII_REG 0x08
433 #define AX_CMD_SET_HW_MII 0x0a
434 #define AX_CMD_READ_EEPROM 0x0b
435 #define AX_CMD_WRITE_EEPROM 0x0c
436 #define AX_CMD_WRITE_RX_CTL 0x10
437 #define AX_CMD_READ_IPG012 0x11
438 #define AX_CMD_WRITE_IPG0 0x12
439 #define AX_CMD_WRITE_IPG1 0x13
440 #define AX_CMD_WRITE_IPG2 0x14
441 #define AX_CMD_WRITE_MULTI_FILTER 0x16
442 #define AX_CMD_READ_NODE_ID 0x17
443 #define AX_CMD_READ_PHY_ID 0x19
444 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
445 #define AX_CMD_READ_MONITOR_MODE 0x1c
446 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
447 #define AX_CMD_WRITE_GPIOS 0x1f
449 #define AX_MONITOR_MODE 0x01
450 #define AX_MONITOR_LINK 0x02
451 #define AX_MONITOR_MAGIC 0x04
452 #define AX_MONITOR_HSFS 0x10
454 #define AX_MCAST_FILTER_SIZE 8
455 #define AX_MAX_MCAST 64
457 #define AX_INTERRUPT_BUFSIZE 8
459 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
460 struct ax8817x_data {
461 u8 multi_filter[AX_MCAST_FILTER_SIZE];
462 struct urb *int_urb;
463 u8 *int_buf;
466 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
467 u16 size, void *data)
469 return usb_control_msg(
470 dev->udev,
471 usb_rcvctrlpipe(dev->udev, 0),
472 cmd,
473 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
474 value,
475 index,
476 data,
477 size,
478 CONTROL_TIMEOUT_JIFFIES);
481 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
482 u16 size, void *data)
484 return usb_control_msg(
485 dev->udev,
486 usb_sndctrlpipe(dev->udev, 0),
487 cmd,
488 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
489 value,
490 index,
491 data,
492 size,
493 CONTROL_TIMEOUT_JIFFIES);
496 static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
498 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
500 if (urb->status < 0)
501 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
502 urb->status);
504 kfree(req);
505 usb_free_urb(urb);
508 static void ax8817x_interrupt_complete(struct urb *urb, struct pt_regs *regs)
510 struct usbnet *dev = (struct usbnet *)urb->context;
511 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
512 int link;
514 if (urb->status < 0) {
515 printk(KERN_DEBUG "ax8817x_interrupt_complete() failed with %d",
516 urb->status);
517 } else {
518 if (data->int_buf[5] == 0x90) {
519 link = data->int_buf[2] & 0x01;
520 if (netif_carrier_ok(dev->net) != link) {
521 if (link)
522 netif_carrier_on(dev->net);
523 else
524 netif_carrier_off(dev->net);
525 devdbg(dev, "ax8817x - Link Status is: %d", link);
528 usb_submit_urb(data->int_urb, GFP_KERNEL);
532 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
533 u16 size, void *data)
535 struct usb_ctrlrequest *req;
536 int status;
537 struct urb *urb;
539 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
540 devdbg(dev, "Error allocating URB in write_cmd_async!");
541 return;
544 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
545 deverr(dev, "Failed to allocate memory for control request");
546 usb_free_urb(urb);
547 return;
550 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
551 req->bRequest = cmd;
552 req->wValue = cpu_to_le16(value);
553 req->wIndex = cpu_to_le16(index);
554 req->wLength = cpu_to_le16(size);
556 usb_fill_control_urb(urb, dev->udev,
557 usb_sndctrlpipe(dev->udev, 0),
558 (void *)req, data, size,
559 ax8817x_async_cmd_callback, req);
561 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
562 deverr(dev, "Error submitting the control message: status=%d", status);
563 kfree(req);
564 usb_free_urb(urb);
568 static void ax8817x_set_multicast(struct net_device *net)
570 struct usbnet *dev = (struct usbnet *) net->priv;
571 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
572 u8 rx_ctl = 0x8c;
574 if (net->flags & IFF_PROMISC) {
575 rx_ctl |= 0x01;
576 } else if (net->flags & IFF_ALLMULTI
577 || net->mc_count > AX_MAX_MCAST) {
578 rx_ctl |= 0x02;
579 } else if (net->mc_count == 0) {
580 /* just broadcast and directed */
581 } else {
582 /* We use the 20 byte dev->data
583 * for our 8 byte filter buffer
584 * to avoid allocating memory that
585 * is tricky to free later */
586 struct dev_mc_list *mc_list = net->mc_list;
587 u32 crc_bits;
588 int i;
590 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
592 /* Build the multicast hash filter. */
593 for (i = 0; i < net->mc_count; i++) {
594 crc_bits =
595 ether_crc(ETH_ALEN,
596 mc_list->dmi_addr) >> 26;
597 data->multi_filter[crc_bits >> 3] |=
598 1 << (crc_bits & 7);
599 mc_list = mc_list->next;
602 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
603 AX_MCAST_FILTER_SIZE, data->multi_filter);
605 rx_ctl |= 0x10;
608 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
611 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
613 struct usbnet *dev = netdev->priv;
614 u16 res;
615 u8 buf[1];
617 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
618 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
619 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
621 return res & 0xffff;
624 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
626 struct usbnet *dev = netdev->priv;
627 u16 res = val;
628 u8 buf[1];
630 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
631 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
632 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
635 static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
637 struct usbnet *dev = (struct usbnet *)net->priv;
638 u8 opt;
640 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
641 wolinfo->supported = 0;
642 wolinfo->wolopts = 0;
643 return;
645 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
646 wolinfo->wolopts = 0;
647 if (opt & AX_MONITOR_MODE) {
648 if (opt & AX_MONITOR_LINK)
649 wolinfo->wolopts |= WAKE_PHY;
650 if (opt & AX_MONITOR_MAGIC)
651 wolinfo->wolopts |= WAKE_MAGIC;
655 static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
657 struct usbnet *dev = (struct usbnet *)net->priv;
658 u8 opt = 0;
659 u8 buf[1];
661 if (wolinfo->wolopts & WAKE_PHY)
662 opt |= AX_MONITOR_LINK;
663 if (wolinfo->wolopts & WAKE_MAGIC)
664 opt |= AX_MONITOR_MAGIC;
665 if (opt != 0)
666 opt |= AX_MONITOR_MODE;
668 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
669 opt, 0, 0, &buf) < 0)
670 return -EINVAL;
672 return 0;
675 static int ax8817x_get_eeprom(struct net_device *net,
676 struct ethtool_eeprom *eeprom, u8 *data)
678 struct usbnet *dev = (struct usbnet *)net->priv;
679 u16 *ebuf = (u16 *)data;
680 int i;
682 /* Crude hack to ensure that we don't overwrite memory
683 * if an odd length is supplied
685 if (eeprom->len % 2)
686 return -EINVAL;
688 /* ax8817x returns 2 bytes from eeprom on read */
689 for (i=0; i < eeprom->len / 2; i++) {
690 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
691 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
692 return -EINVAL;
694 return i * 2;
697 static void ax8817x_get_drvinfo (struct net_device *net,
698 struct ethtool_drvinfo *info)
700 /* Inherit standard device info */
701 usbnet_get_drvinfo(net, info);
702 info->eedump_len = 0x3e;
705 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
707 struct usbnet *dev = (struct usbnet *)net->priv;
709 return mii_ethtool_gset(&dev->mii,cmd);
712 static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
714 struct usbnet *dev = (struct usbnet *)net->priv;
716 return mii_ethtool_sset(&dev->mii,cmd);
719 /* We need to override some ethtool_ops so we require our
720 own structure so we don't interfere with other usbnet
721 devices that may be connected at the same time. */
722 static struct ethtool_ops ax8817x_ethtool_ops = {
723 .get_drvinfo = ax8817x_get_drvinfo,
724 .get_link = ethtool_op_get_link,
725 .get_msglevel = usbnet_get_msglevel,
726 .set_msglevel = usbnet_set_msglevel,
727 .get_wol = ax8817x_get_wol,
728 .set_wol = ax8817x_set_wol,
729 .get_eeprom = ax8817x_get_eeprom,
730 .get_settings = ax8817x_get_settings,
731 .set_settings = ax8817x_set_settings,
734 static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
736 int ret;
737 u8 buf[6];
738 int i;
739 unsigned long gpio_bits = dev->driver_info->data;
740 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
742 dev->in = usb_rcvbulkpipe(dev->udev, 3);
743 dev->out = usb_sndbulkpipe(dev->udev, 2);
745 // allocate irq urb
746 if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
747 dbg ("%s: cannot allocate interrupt URB",
748 dev->net->name);
749 return -ENOMEM;
752 if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
753 dbg ("%s: cannot allocate memory for interrupt buffer",
754 dev->net->name);
755 usb_free_urb(data->int_urb);
756 return -ENOMEM;
758 memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
760 usb_fill_int_urb (data->int_urb, dev->udev,
761 usb_rcvintpipe (dev->udev, 1),
762 data->int_buf, AX_INTERRUPT_BUFSIZE,
763 ax8817x_interrupt_complete, dev,
764 dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
766 /* Toggle the GPIOs in a manufacturer/model specific way */
767 for (i = 2; i >= 0; i--) {
768 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
769 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
770 buf)) < 0)
771 return ret;
772 msleep(5);
775 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
776 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
777 return ret;
780 /* Get the MAC address */
781 memset(buf, 0, ETH_ALEN);
782 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
783 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
784 return ret;
786 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
788 /* Get the PHY id */
789 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
790 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
791 return ret;
792 } else if (ret < 2) {
793 /* this should always return 2 bytes */
794 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
795 return -EIO;
798 /* Initialize MII structure */
799 dev->mii.dev = dev->net;
800 dev->mii.mdio_read = ax8817x_mdio_read;
801 dev->mii.mdio_write = ax8817x_mdio_write;
802 dev->mii.phy_id_mask = 0x3f;
803 dev->mii.reg_num_mask = 0x1f;
804 dev->mii.phy_id = buf[1];
806 dev->net->set_multicast_list = ax8817x_set_multicast;
807 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
809 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
810 cpu_to_le16(BMCR_RESET));
811 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
812 cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400));
813 mii_nway_restart(&dev->mii);
815 if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
816 dbg("Failed to submit interrupt URB: %02x", ret);
817 usb_free_urb(data->int_urb);
818 return ret;
821 return 0;
824 static void ax8817x_unbind(struct usbnet *dev, struct usb_interface *intf)
826 struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
828 usb_unlink_urb(data->int_urb);
829 usb_free_urb(data->int_urb);
830 kfree(data->int_buf);
833 static const struct driver_info ax8817x_info = {
834 .description = "ASIX AX8817x USB 2.0 Ethernet",
835 .bind = ax8817x_bind,
836 .unbind = ax8817x_unbind,
837 .flags = FLAG_ETHER,
838 .data = 0x00130103,
841 static const struct driver_info dlink_dub_e100_info = {
842 .description = "DLink DUB-E100 USB Ethernet",
843 .bind = ax8817x_bind,
844 .unbind = ax8817x_unbind,
845 .flags = FLAG_ETHER,
846 .data = 0x009f9d9f,
849 static const struct driver_info netgear_fa120_info = {
850 .description = "Netgear FA-120 USB Ethernet",
851 .bind = ax8817x_bind,
852 .unbind = ax8817x_unbind,
853 .flags = FLAG_ETHER,
854 .data = 0x00130103,
857 static const struct driver_info hawking_uf200_info = {
858 .description = "Hawking UF200 USB Ethernet",
859 .bind = ax8817x_bind,
860 .unbind = ax8817x_unbind,
861 .flags = FLAG_ETHER,
862 .data = 0x001f1d1f,
865 #endif /* CONFIG_USB_AX8817X */
869 #ifdef CONFIG_USB_BELKIN
870 #define HAVE_HARDWARE
872 /*-------------------------------------------------------------------------
874 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
876 * ... also two eTEK designs, including one sold as "Advance USBNET"
878 *-------------------------------------------------------------------------*/
880 static const struct driver_info belkin_info = {
881 .description = "Belkin, eTEK, or compatible",
884 #endif /* CONFIG_USB_BELKIN */
888 /*-------------------------------------------------------------------------
890 * Communications Device Class declarations.
891 * Used by CDC Ethernet, and some CDC variants
893 *-------------------------------------------------------------------------*/
895 #ifdef CONFIG_USB_CDCETHER
896 #define NEED_GENERIC_CDC
897 #endif
899 #ifdef CONFIG_USB_ZAURUS
900 /* Ethernet variant uses funky framing, broken ethernet addressing */
901 #define NEED_GENERIC_CDC
902 #endif
904 #ifdef CONFIG_USB_RNDIS
905 /* ACM variant uses even funkier framing, complex control RPC scheme */
906 #define NEED_GENERIC_CDC
907 #endif
910 #ifdef NEED_GENERIC_CDC
912 /* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
913 struct header_desc {
914 u8 bLength;
915 u8 bDescriptorType;
916 u8 bDescriptorSubType;
918 u16 bcdCDC;
919 } __attribute__ ((packed));
921 /* "Union Functional Descriptor" from CDC spec 5.2.3.X */
922 struct union_desc {
923 u8 bLength;
924 u8 bDescriptorType;
925 u8 bDescriptorSubType;
927 u8 bMasterInterface0;
928 u8 bSlaveInterface0;
929 /* ... and there could be other slave interfaces */
930 } __attribute__ ((packed));
932 /* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */
933 struct ether_desc {
934 u8 bLength;
935 u8 bDescriptorType;
936 u8 bDescriptorSubType;
938 u8 iMACAddress;
939 u32 bmEthernetStatistics;
940 __le16 wMaxSegmentSize;
941 __le16 wNumberMCFilters;
942 u8 bNumberPowerFilters;
943 } __attribute__ ((packed));
945 struct cdc_state {
946 struct header_desc *header;
947 struct union_desc *u;
948 struct ether_desc *ether;
949 struct usb_interface *control;
950 struct usb_interface *data;
953 static struct usb_driver usbnet_driver;
956 * probes control interface, claims data interface, collects the bulk
957 * endpoints, activates data interface (if needed), maybe sets MTU.
958 * all pure cdc, except for certain firmware workarounds.
960 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
962 u8 *buf = intf->cur_altsetting->extra;
963 int len = intf->cur_altsetting->extralen;
964 struct usb_interface_descriptor *d;
965 struct cdc_state *info = (void *) &dev->data;
966 int status;
967 int rndis;
969 if (sizeof dev->data < sizeof *info)
970 return -EDOM;
972 /* expect strict spec conformance for the descriptors, but
973 * cope with firmware which stores them in the wrong place
975 if (len == 0 && dev->udev->actconfig->extralen) {
976 /* Motorola SB4100 (and others: Brad Hards says it's
977 * from a Broadcom design) put CDC descriptors here
979 buf = dev->udev->actconfig->extra;
980 len = dev->udev->actconfig->extralen;
981 if (len)
982 dev_dbg (&intf->dev,
983 "CDC descriptors on config\n");
986 /* this assumes that if there's a non-RNDIS vendor variant
987 * of cdc-acm, it'll fail RNDIS requests cleanly.
989 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
991 memset (info, 0, sizeof *info);
992 info->control = intf;
993 while (len > 3) {
994 if (buf [1] != USB_DT_CS_INTERFACE)
995 goto next_desc;
997 /* use bDescriptorSubType to identify the CDC descriptors.
998 * We expect devices with CDC header and union descriptors.
999 * For CDC Ethernet we need the ethernet descriptor.
1000 * For RNDIS, ignore two (pointless) CDC modem descriptors
1001 * in favor of a complicated OID-based RPC scheme doing what
1002 * CDC Ethernet achieves with a simple descriptor.
1004 switch (buf [2]) {
1005 case 0x00: /* Header, mostly useless */
1006 if (info->header) {
1007 dev_dbg (&intf->dev, "extra CDC header\n");
1008 goto bad_desc;
1010 info->header = (void *) buf;
1011 if (info->header->bLength != sizeof *info->header) {
1012 dev_dbg (&intf->dev, "CDC header len %u\n",
1013 info->header->bLength);
1014 goto bad_desc;
1016 break;
1017 case 0x06: /* Union (groups interfaces) */
1018 if (info->u) {
1019 dev_dbg (&intf->dev, "extra CDC union\n");
1020 goto bad_desc;
1022 info->u = (void *) buf;
1023 if (info->u->bLength != sizeof *info->u) {
1024 dev_dbg (&intf->dev, "CDC union len %u\n",
1025 info->u->bLength);
1026 goto bad_desc;
1029 /* we need a master/control interface (what we're
1030 * probed with) and a slave/data interface; union
1031 * descriptors sort this all out.
1033 info->control = usb_ifnum_to_if(dev->udev,
1034 info->u->bMasterInterface0);
1035 info->data = usb_ifnum_to_if(dev->udev,
1036 info->u->bSlaveInterface0);
1037 if (!info->control || !info->data) {
1038 dev_dbg (&intf->dev,
1039 "master #%u/%p slave #%u/%p\n",
1040 info->u->bMasterInterface0,
1041 info->control,
1042 info->u->bSlaveInterface0,
1043 info->data);
1044 goto bad_desc;
1046 if (info->control != intf) {
1047 dev_dbg (&intf->dev, "bogus CDC Union\n");
1048 /* Ambit USB Cable Modem (and maybe others)
1049 * interchanges master and slave interface.
1051 if (info->data == intf) {
1052 info->data = info->control;
1053 info->control = intf;
1054 } else
1055 goto bad_desc;
1058 /* a data interface altsetting does the real i/o */
1059 d = &info->data->cur_altsetting->desc;
1060 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1061 dev_dbg (&intf->dev, "slave class %u\n",
1062 d->bInterfaceClass);
1063 goto bad_desc;
1065 break;
1066 case 0x0F: /* Ethernet Networking */
1067 if (info->ether) {
1068 dev_dbg (&intf->dev, "extra CDC ether\n");
1069 goto bad_desc;
1071 info->ether = (void *) buf;
1072 if (info->ether->bLength != sizeof *info->ether) {
1073 dev_dbg (&intf->dev, "CDC ether len %u\n",
1074 info->u->bLength);
1075 goto bad_desc;
1077 dev->net->mtu = le16_to_cpup (
1078 &info->ether->wMaxSegmentSize)
1079 - ETH_HLEN;
1080 /* because of Zaurus, we may be ignoring the host
1081 * side link address we were given.
1083 break;
1085 next_desc:
1086 len -= buf [0]; /* bLength */
1087 buf += buf [0];
1090 if (!info->header || !info->u || (!rndis && !info->ether)) {
1091 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1092 info->header ? "" : "header ",
1093 info->u ? "" : "union ",
1094 info->ether ? "" : "ether ");
1095 goto bad_desc;
1098 /* claim data interface and set it up ... with side effects.
1099 * network traffic can't flow until an altsetting is enabled.
1101 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1102 if (status < 0)
1103 return status;
1104 status = get_endpoints (dev, info->data);
1105 if (status < 0) {
1106 /* ensure immediate exit from usbnet_disconnect */
1107 usb_set_intfdata(info->data, NULL);
1108 usb_driver_release_interface (&usbnet_driver, info->data);
1109 return status;
1111 return 0;
1113 bad_desc:
1114 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1115 return -ENODEV;
1118 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1120 struct cdc_state *info = (void *) &dev->data;
1122 /* disconnect master --> disconnect slave */
1123 if (intf == info->control && info->data) {
1124 /* ensure immediate exit from usbnet_disconnect */
1125 usb_set_intfdata(info->data, NULL);
1126 usb_driver_release_interface (&usbnet_driver, info->data);
1127 info->data = NULL;
1130 /* and vice versa (just in case) */
1131 else if (intf == info->data && info->control) {
1132 /* ensure immediate exit from usbnet_disconnect */
1133 usb_set_intfdata(info->control, NULL);
1134 usb_driver_release_interface (&usbnet_driver, info->control);
1135 info->control = NULL;
1139 #endif /* NEED_GENERIC_CDC */
1142 #ifdef CONFIG_USB_CDCETHER
1143 #define HAVE_HARDWARE
1145 /*-------------------------------------------------------------------------
1147 * Communications Device Class, Ethernet Control model
1149 * Takes two interfaces. The DATA interface is inactive till an altsetting
1150 * is selected. Configuration data includes class descriptors.
1152 * This should interop with whatever the 2.4 "CDCEther.c" driver
1153 * (by Brad Hards) talked with.
1155 *-------------------------------------------------------------------------*/
1157 #include <linux/ctype.h>
1159 static u8 nibble (unsigned char c)
1161 if (likely (isdigit (c)))
1162 return c - '0';
1163 c = toupper (c);
1164 if (likely (isxdigit (c)))
1165 return 10 + c - 'A';
1166 return 0;
1169 static inline int
1170 get_ethernet_addr (struct usbnet *dev, struct ether_desc *e)
1172 int tmp, i;
1173 unsigned char buf [13];
1175 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1176 if (tmp != 12) {
1177 dev_dbg (&dev->udev->dev,
1178 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1179 if (tmp >= 0)
1180 tmp = -EINVAL;
1181 return tmp;
1183 for (i = tmp = 0; i < 6; i++, tmp += 2)
1184 dev->net->dev_addr [i] =
1185 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1186 return 0;
1189 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1191 int status;
1192 struct cdc_state *info = (void *) &dev->data;
1194 status = generic_cdc_bind (dev, intf);
1195 if (status < 0)
1196 return status;
1198 status = get_ethernet_addr (dev, info->ether);
1199 if (status < 0) {
1200 usb_set_intfdata(info->data, NULL);
1201 usb_driver_release_interface (&usbnet_driver, info->data);
1202 return status;
1205 /* FIXME cdc-ether has some multicast code too, though it complains
1206 * in routine cases. info->ether describes the multicast support.
1208 return 0;
1211 static const struct driver_info cdc_info = {
1212 .description = "CDC Ethernet Device",
1213 .flags = FLAG_ETHER,
1214 // .check_connect = cdc_check_connect,
1215 .bind = cdc_bind,
1216 .unbind = cdc_unbind,
1219 #endif /* CONFIG_USB_CDCETHER */
1223 #ifdef CONFIG_USB_EPSON2888
1224 #define HAVE_HARDWARE
1226 /*-------------------------------------------------------------------------
1228 * EPSON USB clients
1230 * This is the same idea as Linux PDAs (below) except the firmware in the
1231 * device might not be Tux-powered. Epson provides reference firmware that
1232 * implements this interface. Product developers can reuse or modify that
1233 * code, such as by using their own product and vendor codes.
1235 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1237 *-------------------------------------------------------------------------*/
1239 static const struct driver_info epson2888_info = {
1240 .description = "Epson USB Device",
1241 .check_connect = always_connected,
1243 .in = 4, .out = 3,
1246 #endif /* CONFIG_USB_EPSON2888 */
1249 #ifdef CONFIG_USB_GENESYS
1250 #define HAVE_HARDWARE
1252 /*-------------------------------------------------------------------------
1254 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1256 * ... should partially interop with the Win32 driver for this hardware
1257 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1259 * Some info from GeneSys:
1260 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1261 * (Some cables, like the BAFO-100c, use the half duplex version.)
1262 * - For the full duplex model, the low bit of the version code says
1263 * which side is which ("left/right").
1264 * - For the half duplex type, a control/interrupt handshake settles
1265 * the transfer direction. (That's disabled here, partially coded.)
1266 * A control URB would block until other side writes an interrupt.
1268 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1269 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1271 *-------------------------------------------------------------------------*/
1273 // control msg write command
1274 #define GENELINK_CONNECT_WRITE 0xF0
1275 // interrupt pipe index
1276 #define GENELINK_INTERRUPT_PIPE 0x03
1277 // interrupt read buffer size
1278 #define INTERRUPT_BUFSIZE 0x08
1279 // interrupt pipe interval value
1280 #define GENELINK_INTERRUPT_INTERVAL 0x10
1281 // max transmit packet number per transmit
1282 #define GL_MAX_TRANSMIT_PACKETS 32
1283 // max packet length
1284 #define GL_MAX_PACKET_LEN 1514
1285 // max receive buffer size
1286 #define GL_RCV_BUF_SIZE \
1287 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1289 struct gl_packet {
1290 u32 packet_length;
1291 char packet_data [1];
1294 struct gl_header {
1295 u32 packet_count;
1296 struct gl_packet packets;
1299 #ifdef GENLINK_ACK
1301 // FIXME: this code is incomplete, not debugged; it doesn't
1302 // handle interrupts correctly. interrupts should be generic
1303 // code like all other device I/O, anyway.
1305 struct gl_priv {
1306 struct urb *irq_urb;
1307 char irq_buf [INTERRUPT_BUFSIZE];
1310 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1312 int retval;
1314 retval = usb_control_msg (dev->udev,
1315 usb_sndctrlpipe (dev->udev, 0),
1316 request,
1317 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1318 value,
1319 0, // index
1320 0, // data buffer
1321 0, // size
1322 CONTROL_TIMEOUT_JIFFIES);
1323 return retval;
1326 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1328 int status = urb->status;
1330 switch (status) {
1331 case 0:
1332 /* success */
1333 break;
1334 case -ECONNRESET:
1335 case -ENOENT:
1336 case -ESHUTDOWN:
1337 /* this urb is terminated, clean up */
1338 dbg("%s - urb shutting down with status: %d",
1339 __FUNCTION__, status);
1340 return;
1341 default:
1342 dbg("%s - nonzero urb status received: %d",
1343 __FUNCTION__, urb->status);
1346 status = usb_submit_urb (urb, GFP_ATOMIC);
1347 if (status)
1348 err ("%s - usb_submit_urb failed with result %d",
1349 __FUNCTION__, status);
1352 static int gl_interrupt_read (struct usbnet *dev)
1354 struct gl_priv *priv = dev->priv_data;
1355 int retval;
1357 // issue usb interrupt read
1358 if (priv && priv->irq_urb) {
1359 // submit urb
1360 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1361 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1362 else
1363 dbg ("gl_interrupt_read: submit success...");
1366 return 0;
1369 // check whether another side is connected
1370 static int genelink_check_connect (struct usbnet *dev)
1372 int retval;
1374 dbg ("genelink_check_connect...");
1376 // detect whether another side is connected
1377 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1378 dbg ("%s: genelink_check_connect write fail - %X",
1379 dev->net->name, retval);
1380 return retval;
1383 // usb interrupt read to ack another side
1384 if ((retval = gl_interrupt_read (dev)) != 0) {
1385 dbg ("%s: genelink_check_connect read fail - %X",
1386 dev->net->name, retval);
1387 return retval;
1390 dbg ("%s: genelink_check_connect read success", dev->net->name);
1391 return 0;
1394 // allocate and initialize the private data for genelink
1395 static int genelink_init (struct usbnet *dev)
1397 struct gl_priv *priv;
1399 // allocate the private data structure
1400 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1401 dbg ("%s: cannot allocate private data per device",
1402 dev->net->name);
1403 return -ENOMEM;
1406 // allocate irq urb
1407 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1408 dbg ("%s: cannot allocate private irq urb per device",
1409 dev->net->name);
1410 kfree (priv);
1411 return -ENOMEM;
1414 // fill irq urb
1415 usb_fill_int_urb (priv->irq_urb, dev->udev,
1416 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1417 priv->irq_buf, INTERRUPT_BUFSIZE,
1418 gl_interrupt_complete, 0,
1419 GENELINK_INTERRUPT_INTERVAL);
1421 // set private data pointer
1422 dev->priv_data = priv;
1424 return 0;
1427 // release the private data
1428 static int genelink_free (struct usbnet *dev)
1430 struct gl_priv *priv = dev->priv_data;
1432 if (!priv)
1433 return 0;
1435 // FIXME: can't cancel here; it's synchronous, and
1436 // should have happened earlier in any case (interrupt
1437 // handling needs to be generic)
1439 // cancel irq urb first
1440 usb_unlink_urb (priv->irq_urb);
1442 // free irq urb
1443 usb_free_urb (priv->irq_urb);
1445 // free the private data structure
1446 kfree (priv);
1448 return 0;
1451 #endif
1453 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1455 struct gl_header *header;
1456 struct gl_packet *packet;
1457 struct sk_buff *gl_skb;
1458 u32 size;
1460 header = (struct gl_header *) skb->data;
1462 // get the packet count of the received skb
1463 le32_to_cpus (&header->packet_count);
1464 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1465 || (header->packet_count < 0)) {
1466 dbg ("genelink: invalid received packet count %d",
1467 header->packet_count);
1468 return 0;
1471 // set the current packet pointer to the first packet
1472 packet = &header->packets;
1474 // decrement the length for the packet count size 4 bytes
1475 skb_pull (skb, 4);
1477 while (header->packet_count > 1) {
1478 // get the packet length
1479 size = packet->packet_length;
1481 // this may be a broken packet
1482 if (size > GL_MAX_PACKET_LEN) {
1483 dbg ("genelink: invalid rx length %d", size);
1484 return 0;
1487 // allocate the skb for the individual packet
1488 gl_skb = alloc_skb (size, GFP_ATOMIC);
1489 if (gl_skb) {
1491 // copy the packet data to the new skb
1492 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1493 skb_return (dev, skb);
1496 // advance to the next packet
1497 packet = (struct gl_packet *)
1498 &packet->packet_data [size];
1499 header->packet_count--;
1501 // shift the data pointer to the next gl_packet
1502 skb_pull (skb, size + 4);
1505 // skip the packet length field 4 bytes
1506 skb_pull (skb, 4);
1508 if (skb->len > GL_MAX_PACKET_LEN) {
1509 dbg ("genelink: invalid rx length %d", skb->len);
1510 return 0;
1512 return 1;
1515 static struct sk_buff *
1516 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1518 int padlen;
1519 int length = skb->len;
1520 int headroom = skb_headroom (skb);
1521 int tailroom = skb_tailroom (skb);
1522 u32 *packet_count;
1523 u32 *packet_len;
1525 // FIXME: magic numbers, bleech
1526 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1528 if ((!skb_cloned (skb))
1529 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1530 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1531 skb->data = memmove (skb->head + (4 + 4*1),
1532 skb->data, skb->len);
1533 skb->tail = skb->data + skb->len;
1535 } else {
1536 struct sk_buff *skb2;
1537 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1538 dev_kfree_skb_any (skb);
1539 skb = skb2;
1540 if (!skb)
1541 return NULL;
1544 // attach the packet count to the header
1545 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1546 packet_len = packet_count + 1;
1548 // FIXME little endian?
1549 *packet_count = 1;
1550 *packet_len = length;
1552 // add padding byte
1553 if ((skb->len % dev->maxpacket) == 0)
1554 skb_put (skb, 1);
1556 return skb;
1559 static const struct driver_info genelink_info = {
1560 .description = "Genesys GeneLink",
1561 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1562 .rx_fixup = genelink_rx_fixup,
1563 .tx_fixup = genelink_tx_fixup,
1565 .in = 1, .out = 2,
1567 #ifdef GENELINK_ACK
1568 .check_connect =genelink_check_connect,
1569 #endif
1572 #endif /* CONFIG_USB_GENESYS */
1576 #ifdef CONFIG_USB_NET1080
1577 #define HAVE_HARDWARE
1579 /*-------------------------------------------------------------------------
1581 * Netchip 1080 driver ... http://www.netchip.com
1582 * Used in LapLink cables
1584 *-------------------------------------------------------------------------*/
1586 #define dev_packet_id data[0]
1587 #define frame_errors data[1]
1590 * NetChip framing of ethernet packets, supporting additional error
1591 * checks for links that may drop bulk packets from inside messages.
1592 * Odd USB length == always short read for last usb packet.
1593 * - nc_header
1594 * - Ethernet header (14 bytes)
1595 * - payload
1596 * - (optional padding byte, if needed so length becomes odd)
1597 * - nc_trailer
1599 * This framing is to be avoided for non-NetChip devices.
1602 struct nc_header { // packed:
1603 u16 hdr_len; // sizeof nc_header (LE, all)
1604 u16 packet_len; // payload size (including ethhdr)
1605 u16 packet_id; // detects dropped packets
1606 #define MIN_HEADER 6
1608 // all else is optional, and must start with:
1609 // u16 vendorId; // from usb-if
1610 // u16 productId;
1611 } __attribute__((__packed__));
1613 #define PAD_BYTE ((unsigned char)0xAC)
1615 struct nc_trailer {
1616 u16 packet_id;
1617 } __attribute__((__packed__));
1619 // packets may use FLAG_FRAMING_NC and optional pad
1620 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1621 + sizeof (struct ethhdr) \
1622 + (mtu) \
1623 + 1 \
1624 + sizeof (struct nc_trailer))
1626 #define MIN_FRAMED FRAMED_SIZE(0)
1630 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1631 * before the hardware drops it. If that's done, the driver will need to
1632 * frame network packets to guard against the dropped USB packets. The win32
1633 * driver sets this for both sides of the link.
1635 #define NC_READ_TTL_MS ((u8)255) // ms
1638 * We ignore most registers and EEPROM contents.
1640 #define REG_USBCTL ((u8)0x04)
1641 #define REG_TTL ((u8)0x10)
1642 #define REG_STATUS ((u8)0x11)
1645 * Vendor specific requests to read/write data
1647 #define REQUEST_REGISTER ((u8)0x10)
1648 #define REQUEST_EEPROM ((u8)0x11)
1650 static int
1651 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1653 int status = usb_control_msg (dev->udev,
1654 usb_rcvctrlpipe (dev->udev, 0),
1655 req,
1656 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1657 0, regnum,
1658 retval_ptr, sizeof *retval_ptr,
1659 CONTROL_TIMEOUT_JIFFIES);
1660 if (status > 0)
1661 status = 0;
1662 if (!status)
1663 le16_to_cpus (retval_ptr);
1664 return status;
1667 static inline int
1668 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1670 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1673 // no retval ... can become async, usable in_interrupt()
1674 static void
1675 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1677 usb_control_msg (dev->udev,
1678 usb_sndctrlpipe (dev->udev, 0),
1679 req,
1680 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1681 value, regnum,
1682 NULL, 0, // data is in setup packet
1683 CONTROL_TIMEOUT_JIFFIES);
1686 static inline void
1687 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1689 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1693 #if 0
1694 static void nc_dump_registers (struct usbnet *dev)
1696 u8 reg;
1697 u16 *vp = kmalloc (sizeof (u16));
1699 if (!vp) {
1700 dbg ("no memory?");
1701 return;
1704 dbg ("%s registers:", dev->net->name);
1705 for (reg = 0; reg < 0x20; reg++) {
1706 int retval;
1708 // reading some registers is trouble
1709 if (reg >= 0x08 && reg <= 0xf)
1710 continue;
1711 if (reg >= 0x12 && reg <= 0x1e)
1712 continue;
1714 retval = nc_register_read (dev, reg, vp);
1715 if (retval < 0)
1716 dbg ("%s reg [0x%x] ==> error %d",
1717 dev->net->name, reg, retval);
1718 else
1719 dbg ("%s reg [0x%x] = 0x%x",
1720 dev->net->name, reg, *vp);
1722 kfree (vp);
1724 #endif
1727 /*-------------------------------------------------------------------------*/
1730 * Control register
1733 #define USBCTL_WRITABLE_MASK 0x1f0f
1734 // bits 15-13 reserved, r/o
1735 #define USBCTL_ENABLE_LANG (1 << 12)
1736 #define USBCTL_ENABLE_MFGR (1 << 11)
1737 #define USBCTL_ENABLE_PROD (1 << 10)
1738 #define USBCTL_ENABLE_SERIAL (1 << 9)
1739 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1740 // bits 7-4 reserved, r/o
1741 #define USBCTL_FLUSH_OTHER (1 << 3)
1742 #define USBCTL_FLUSH_THIS (1 << 2)
1743 #define USBCTL_DISCONN_OTHER (1 << 1)
1744 #define USBCTL_DISCONN_THIS (1 << 0)
1746 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1748 #ifdef DEBUG
1749 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1750 " this%s%s;"
1751 " other%s%s; r/o 0x%x",
1752 dev->udev->bus->bus_name, dev->udev->devpath,
1753 usbctl,
1754 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1755 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1756 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1757 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
1758 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
1760 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
1761 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
1762 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
1763 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
1764 usbctl & ~USBCTL_WRITABLE_MASK
1766 #endif
1769 /*-------------------------------------------------------------------------*/
1772 * Status register
1775 #define STATUS_PORT_A (1 << 15)
1777 #define STATUS_CONN_OTHER (1 << 14)
1778 #define STATUS_SUSPEND_OTHER (1 << 13)
1779 #define STATUS_MAILBOX_OTHER (1 << 12)
1780 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
1782 #define STATUS_CONN_THIS (1 << 6)
1783 #define STATUS_SUSPEND_THIS (1 << 5)
1784 #define STATUS_MAILBOX_THIS (1 << 4)
1785 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
1787 #define STATUS_UNSPEC_MASK 0x0c8c
1788 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
1791 static inline void nc_dump_status (struct usbnet *dev, u16 status)
1793 #ifdef DEBUG
1794 devdbg (dev, "net1080 %s-%s status 0x%x:"
1795 " this (%c) PKT=%d%s%s%s;"
1796 " other PKT=%d%s%s%s; unspec 0x%x",
1797 dev->udev->bus->bus_name, dev->udev->devpath,
1798 status,
1800 // XXX the packet counts don't seem right
1801 // (1 at reset, not 0); maybe UNSPEC too
1803 (status & STATUS_PORT_A) ? 'A' : 'B',
1804 STATUS_PACKETS_THIS (status),
1805 (status & STATUS_CONN_THIS) ? " CON" : "",
1806 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
1807 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
1809 STATUS_PACKETS_OTHER (status),
1810 (status & STATUS_CONN_OTHER) ? " CON" : "",
1811 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
1812 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
1814 status & STATUS_UNSPEC_MASK
1816 #endif
1819 /*-------------------------------------------------------------------------*/
1822 * TTL register
1825 #define TTL_THIS(ttl) (0x00ff & ttl)
1826 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
1827 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
1829 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
1831 #ifdef DEBUG
1832 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
1833 dev->udev->bus->bus_name, dev->udev->devpath,
1834 ttl,
1836 TTL_THIS (ttl),
1837 TTL_OTHER (ttl)
1839 #endif
1842 /*-------------------------------------------------------------------------*/
1844 static int net1080_reset (struct usbnet *dev)
1846 u16 usbctl, status, ttl;
1847 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1848 int retval;
1850 if (!vp)
1851 return -ENOMEM;
1853 // nc_dump_registers (dev);
1855 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
1856 dbg ("can't read %s-%s status: %d",
1857 dev->udev->bus->bus_name, dev->udev->devpath, retval);
1858 goto done;
1860 status = *vp;
1861 // nc_dump_status (dev, status);
1863 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
1864 dbg ("can't read USBCTL, %d", retval);
1865 goto done;
1867 usbctl = *vp;
1868 // nc_dump_usbctl (dev, usbctl);
1870 nc_register_write (dev, REG_USBCTL,
1871 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
1873 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
1874 dbg ("can't read TTL, %d", retval);
1875 goto done;
1877 ttl = *vp;
1878 // nc_dump_ttl (dev, ttl);
1880 nc_register_write (dev, REG_TTL,
1881 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
1882 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
1884 if (dev->msg_level >= 2)
1885 devinfo (dev, "port %c, peer %sconnected",
1886 (status & STATUS_PORT_A) ? 'A' : 'B',
1887 (status & STATUS_CONN_OTHER) ? "" : "dis"
1889 retval = 0;
1891 done:
1892 kfree (vp);
1893 return retval;
1896 static int net1080_check_connect (struct usbnet *dev)
1898 int retval;
1899 u16 status;
1900 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
1902 if (!vp)
1903 return -ENOMEM;
1904 retval = nc_register_read (dev, REG_STATUS, vp);
1905 status = *vp;
1906 kfree (vp);
1907 if (retval != 0) {
1908 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
1909 return retval;
1911 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
1912 return -ENOLINK;
1913 return 0;
1916 static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
1918 kfree (urb->context);
1919 usb_free_urb(urb);
1922 static void nc_ensure_sync (struct usbnet *dev)
1924 dev->frame_errors++;
1925 if (dev->frame_errors > 5) {
1926 struct urb *urb;
1927 struct usb_ctrlrequest *req;
1928 int status;
1930 /* Send a flush */
1931 urb = usb_alloc_urb (0, SLAB_ATOMIC);
1932 if (!urb)
1933 return;
1935 req = kmalloc (sizeof *req, GFP_ATOMIC);
1936 if (!req) {
1937 usb_free_urb (urb);
1938 return;
1941 req->bRequestType = USB_DIR_OUT
1942 | USB_TYPE_VENDOR
1943 | USB_RECIP_DEVICE;
1944 req->bRequest = REQUEST_REGISTER;
1945 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
1946 | USBCTL_FLUSH_OTHER);
1947 req->wIndex = cpu_to_le16 (REG_USBCTL);
1948 req->wLength = cpu_to_le16 (0);
1950 /* queue an async control request, we don't need
1951 * to do anything when it finishes except clean up.
1953 usb_fill_control_urb (urb, dev->udev,
1954 usb_sndctrlpipe (dev->udev, 0),
1955 (unsigned char *) req,
1956 NULL, 0,
1957 nc_flush_complete, req);
1958 status = usb_submit_urb (urb, GFP_ATOMIC);
1959 if (status) {
1960 kfree (req);
1961 usb_free_urb (urb);
1962 return;
1965 devdbg (dev, "flush net1080; too many framing errors");
1966 dev->frame_errors = 0;
1970 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1972 struct nc_header *header;
1973 struct nc_trailer *trailer;
1975 if (!(skb->len & 0x01)
1976 || MIN_FRAMED > skb->len
1977 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
1978 dev->stats.rx_frame_errors++;
1979 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
1980 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
1981 dev->net->mtu);
1982 nc_ensure_sync (dev);
1983 return 0;
1986 header = (struct nc_header *) skb->data;
1987 le16_to_cpus (&header->hdr_len);
1988 le16_to_cpus (&header->packet_len);
1989 if (FRAMED_SIZE (header->packet_len) > MAX_PACKET) {
1990 dev->stats.rx_frame_errors++;
1991 dbg ("packet too big, %d", header->packet_len);
1992 nc_ensure_sync (dev);
1993 return 0;
1994 } else if (header->hdr_len < MIN_HEADER) {
1995 dev->stats.rx_frame_errors++;
1996 dbg ("header too short, %d", header->hdr_len);
1997 nc_ensure_sync (dev);
1998 return 0;
1999 } else if (header->hdr_len > MIN_HEADER) {
2000 // out of band data for us?
2001 dbg ("header OOB, %d bytes",
2002 header->hdr_len - MIN_HEADER);
2003 nc_ensure_sync (dev);
2004 // switch (vendor/product ids) { ... }
2006 skb_pull (skb, header->hdr_len);
2008 trailer = (struct nc_trailer *)
2009 (skb->data + skb->len - sizeof *trailer);
2010 skb_trim (skb, skb->len - sizeof *trailer);
2012 if ((header->packet_len & 0x01) == 0) {
2013 if (skb->data [header->packet_len] != PAD_BYTE) {
2014 dev->stats.rx_frame_errors++;
2015 dbg ("bad pad");
2016 return 0;
2018 skb_trim (skb, skb->len - 1);
2020 if (skb->len != header->packet_len) {
2021 dev->stats.rx_frame_errors++;
2022 dbg ("bad packet len %d (expected %d)",
2023 skb->len, header->packet_len);
2024 nc_ensure_sync (dev);
2025 return 0;
2027 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2028 dev->stats.rx_fifo_errors++;
2029 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2030 header->packet_id, trailer->packet_id);
2031 return 0;
2033 #if 0
2034 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2035 header->packet_len, header->packet_id);
2036 #endif
2037 dev->frame_errors = 0;
2038 return 1;
2041 static struct sk_buff *
2042 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2044 int padlen;
2045 struct sk_buff *skb2;
2047 padlen = ((skb->len + sizeof (struct nc_header)
2048 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2049 if (!skb_cloned (skb)) {
2050 int headroom = skb_headroom (skb);
2051 int tailroom = skb_tailroom (skb);
2053 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2054 && sizeof (struct nc_header) <= headroom)
2055 /* There's enough head and tail room */
2056 return skb;
2058 if ((sizeof (struct nc_header) + padlen
2059 + sizeof (struct nc_trailer)) <
2060 (headroom + tailroom)) {
2061 /* There's enough total room, so just readjust */
2062 skb->data = memmove (skb->head
2063 + sizeof (struct nc_header),
2064 skb->data, skb->len);
2065 skb->tail = skb->data + skb->len;
2066 return skb;
2070 /* Create a new skb to use with the correct size */
2071 skb2 = skb_copy_expand (skb,
2072 sizeof (struct nc_header),
2073 sizeof (struct nc_trailer) + padlen,
2074 flags);
2075 dev_kfree_skb_any (skb);
2076 return skb2;
2079 static const struct driver_info net1080_info = {
2080 .description = "NetChip TurboCONNECT",
2081 .flags = FLAG_FRAMING_NC,
2082 .reset = net1080_reset,
2083 .check_connect =net1080_check_connect,
2084 .rx_fixup = net1080_rx_fixup,
2085 .tx_fixup = net1080_tx_fixup,
2088 #endif /* CONFIG_USB_NET1080 */
2092 #ifdef CONFIG_USB_PL2301
2093 #define HAVE_HARDWARE
2095 /*-------------------------------------------------------------------------
2097 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2099 * The protocol and handshaking used here should be bug-compatible
2100 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2102 *-------------------------------------------------------------------------*/
2105 * Bits 0-4 can be used for software handshaking; they're set from
2106 * one end, cleared from the other, "read" with the interrupt byte.
2108 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2109 /* reserved bit -- rx ready (6) ? */
2110 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2111 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2112 #define PL_RESET_IN (1<<3) /* reset input pipe */
2113 #define PL_TX_C (1<<2) /* transmission complete */
2114 #define PL_TX_REQ (1<<1) /* transmission received */
2115 #define PL_PEER_E (1<<0) /* peer exists */
2117 static inline int
2118 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2120 return usb_control_msg (dev->udev,
2121 usb_rcvctrlpipe (dev->udev, 0),
2122 req,
2123 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2124 val, index,
2125 NULL, 0,
2126 CONTROL_TIMEOUT_JIFFIES);
2129 static inline int
2130 pl_clear_QuickLink_features (struct usbnet *dev, int val)
2132 return pl_vendor_req (dev, 1, (u8) val, 0);
2135 static inline int
2136 pl_set_QuickLink_features (struct usbnet *dev, int val)
2138 return pl_vendor_req (dev, 3, (u8) val, 0);
2141 /*-------------------------------------------------------------------------*/
2143 static int pl_reset (struct usbnet *dev)
2145 /* some units seem to need this reset, others reject it utterly.
2146 * FIXME be more like "naplink" or windows drivers.
2148 (void) pl_set_QuickLink_features (dev,
2149 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2150 return 0;
2153 static const struct driver_info prolific_info = {
2154 .description = "Prolific PL-2301/PL-2302",
2155 .flags = FLAG_NO_SETINT,
2156 /* some PL-2302 versions seem to fail usb_set_interface() */
2157 .reset = pl_reset,
2160 #endif /* CONFIG_USB_PL2301 */
2164 #ifdef CONFIG_USB_ARMLINUX
2165 #define HAVE_HARDWARE
2167 /*-------------------------------------------------------------------------
2169 * Intel's SA-1100 chip integrates basic USB support, and is used
2170 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2171 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2172 * network using minimal USB framing data.
2174 * This describes the driver currently in standard ARM Linux kernels.
2175 * The Zaurus uses a different driver (see later).
2177 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2178 * and different USB endpoint numbering than the SA1100 devices. The
2179 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2180 * so we rely on the endpoint descriptors.
2182 *-------------------------------------------------------------------------*/
2184 static const struct driver_info linuxdev_info = {
2185 .description = "Linux Device",
2186 .check_connect = always_connected,
2189 static const struct driver_info yopy_info = {
2190 .description = "Yopy",
2191 .check_connect = always_connected,
2194 static const struct driver_info blob_info = {
2195 .description = "Boot Loader OBject",
2196 .check_connect = always_connected,
2199 #endif /* CONFIG_USB_ARMLINUX */
2202 #ifdef CONFIG_USB_ZAURUS
2203 #define HAVE_HARDWARE
2205 #include <linux/crc32.h>
2207 /*-------------------------------------------------------------------------
2209 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2210 * (and framing) for its USB slave/gadget controller than the case above.
2212 * For the current version of that driver, the main way that framing is
2213 * nonstandard (also from perspective of the CDC ethernet model!) is a
2214 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2215 * haven't been fully worked around.
2217 * PXA based models use the same framing, and also can't implement
2218 * set_interface properly.
2220 *-------------------------------------------------------------------------*/
2222 static struct sk_buff *
2223 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2225 int padlen;
2226 struct sk_buff *skb2;
2228 padlen = 2;
2229 if (!skb_cloned (skb)) {
2230 int tailroom = skb_tailroom (skb);
2231 if ((padlen + 4) <= tailroom)
2232 goto done;
2234 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2235 dev_kfree_skb_any (skb);
2236 skb = skb2;
2237 if (skb) {
2238 u32 fcs;
2239 done:
2240 fcs = crc32_le (~0, skb->data, skb->len);
2241 fcs = ~fcs;
2243 *skb_put (skb, 1) = fcs & 0xff;
2244 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2245 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2246 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2248 return skb;
2251 static const struct driver_info zaurus_sl5x00_info = {
2252 .description = "Sharp Zaurus SL-5x00",
2253 .flags = FLAG_FRAMING_Z,
2254 .check_connect = always_connected,
2255 .bind = generic_cdc_bind,
2256 .unbind = cdc_unbind,
2257 .tx_fixup = zaurus_tx_fixup,
2259 static const struct driver_info zaurus_pxa_info = {
2260 .description = "Sharp Zaurus, PXA-2xx based",
2261 .flags = FLAG_FRAMING_Z,
2262 .check_connect = always_connected,
2263 .tx_fixup = zaurus_tx_fixup,
2265 .in = 1, .out = 2,
2268 #endif
2271 /*-------------------------------------------------------------------------
2273 * Network Device Driver (peer link to "Host Device", from USB host)
2275 *-------------------------------------------------------------------------*/
2277 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2279 struct usbnet *dev = (struct usbnet *) net->priv;
2281 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
2282 return -EINVAL;
2283 #ifdef CONFIG_USB_NET1080
2284 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2285 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2286 return -EINVAL;
2288 #endif
2289 #ifdef CONFIG_USB_GENESYS
2290 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2291 && new_mtu > GL_MAX_PACKET_LEN)
2292 return -EINVAL;
2293 #endif
2294 // no second zero-length packet read wanted after mtu-sized packets
2295 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0)
2296 return -EDOM;
2297 net->mtu = new_mtu;
2298 return 0;
2301 /*-------------------------------------------------------------------------*/
2303 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2305 return &((struct usbnet *) net->priv)->stats;
2308 /*-------------------------------------------------------------------------*/
2310 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2311 * completion callbacks. 2.5 should have fixed those bugs...
2314 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
2316 struct sk_buff_head *list = skb->list;
2317 unsigned long flags;
2319 spin_lock_irqsave (&list->lock, flags);
2320 __skb_unlink (skb, list);
2321 spin_unlock (&list->lock);
2322 spin_lock (&dev->done.lock);
2323 __skb_queue_tail (&dev->done, skb);
2324 if (dev->done.qlen == 1)
2325 tasklet_schedule (&dev->bh);
2326 spin_unlock_irqrestore (&dev->done.lock, flags);
2329 /* some work can't be done in tasklets, so we use keventd
2331 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2332 * but tasklet_schedule() doesn't. hope the failure is rare.
2334 static void defer_kevent (struct usbnet *dev, int work)
2336 set_bit (work, &dev->flags);
2337 if (!schedule_work (&dev->kevent))
2338 deverr (dev, "kevent %d may have been dropped", work);
2339 else
2340 devdbg (dev, "kevent %d scheduled", work);
2343 /*-------------------------------------------------------------------------*/
2345 static void rx_complete (struct urb *urb, struct pt_regs *regs);
2347 static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2349 struct sk_buff *skb;
2350 struct skb_data *entry;
2351 int retval = 0;
2352 unsigned long lockflags;
2353 size_t size;
2355 #ifdef CONFIG_USB_NET1080
2356 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2357 size = FRAMED_SIZE (dev->net->mtu);
2358 else
2359 #endif
2360 #ifdef CONFIG_USB_GENESYS
2361 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2362 size = GL_RCV_BUF_SIZE;
2363 else
2364 #endif
2365 #ifdef CONFIG_USB_ZAURUS
2366 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2367 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2368 else
2369 #endif
2370 #ifdef CONFIG_USB_RNDIS
2371 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2372 size = RNDIS_MAX_TRANSFER;
2373 else
2374 #endif
2375 size = (sizeof (struct ethhdr) + dev->net->mtu);
2377 if ((skb = alloc_skb (size, flags)) == 0) {
2378 devdbg (dev, "no rx skb");
2379 defer_kevent (dev, EVENT_RX_MEMORY);
2380 usb_free_urb (urb);
2381 return;
2384 entry = (struct skb_data *) skb->cb;
2385 entry->urb = urb;
2386 entry->dev = dev;
2387 entry->state = rx_start;
2388 entry->length = 0;
2390 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2391 skb->data, size, rx_complete, skb);
2392 urb->transfer_flags |= URB_ASYNC_UNLINK;
2394 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2396 if (netif_running (dev->net)
2397 && netif_device_present (dev->net)
2398 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2399 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2400 case -EPIPE:
2401 defer_kevent (dev, EVENT_RX_HALT);
2402 break;
2403 case -ENOMEM:
2404 defer_kevent (dev, EVENT_RX_MEMORY);
2405 break;
2406 case -ENODEV:
2407 devdbg (dev, "device gone");
2408 netif_device_detach (dev->net);
2409 break;
2410 default:
2411 devdbg (dev, "rx submit, %d", retval);
2412 tasklet_schedule (&dev->bh);
2413 break;
2414 case 0:
2415 __skb_queue_tail (&dev->rxq, skb);
2417 } else {
2418 devdbg (dev, "rx: stopped");
2419 retval = -ENOLINK;
2421 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2422 if (retval) {
2423 dev_kfree_skb_any (skb);
2424 usb_free_urb (urb);
2429 /*-------------------------------------------------------------------------*/
2431 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2433 if (dev->driver_info->rx_fixup
2434 && !dev->driver_info->rx_fixup (dev, skb))
2435 goto error;
2436 // else network stack removes extra byte if we forced a short packet
2438 if (skb->len)
2439 skb_return (dev, skb);
2440 else {
2441 devdbg (dev, "drop");
2442 error:
2443 dev->stats.rx_errors++;
2444 skb_queue_tail (&dev->done, skb);
2448 /*-------------------------------------------------------------------------*/
2450 static void rx_complete (struct urb *urb, struct pt_regs *regs)
2452 struct sk_buff *skb = (struct sk_buff *) urb->context;
2453 struct skb_data *entry = (struct skb_data *) skb->cb;
2454 struct usbnet *dev = entry->dev;
2455 int urb_status = urb->status;
2457 skb_put (skb, urb->actual_length);
2458 entry->state = rx_done;
2459 entry->urb = NULL;
2461 switch (urb_status) {
2462 // success
2463 case 0:
2464 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) {
2465 entry->state = rx_cleanup;
2466 dev->stats.rx_errors++;
2467 dev->stats.rx_length_errors++;
2468 devdbg (dev, "rx length %d", skb->len);
2470 break;
2472 // stalls need manual reset. this is rare ... except that
2473 // when going through USB 2.0 TTs, unplug appears this way.
2474 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2475 // storm, recovering as needed.
2476 case -EPIPE:
2477 dev->stats.rx_errors++;
2478 defer_kevent (dev, EVENT_RX_HALT);
2479 // FALLTHROUGH
2481 // software-driven interface shutdown
2482 case -ECONNRESET: // async unlink
2483 case -ESHUTDOWN: // hardware gone
2484 #ifdef VERBOSE
2485 devdbg (dev, "rx shutdown, code %d", urb_status);
2486 #endif
2487 goto block;
2489 // we get controller i/o faults during khubd disconnect() delays.
2490 // throttle down resubmits, to avoid log floods; just temporarily,
2491 // so we still recover when the fault isn't a khubd delay.
2492 case -EPROTO: // ehci
2493 case -ETIMEDOUT: // ohci
2494 case -EILSEQ: // uhci
2495 dev->stats.rx_errors++;
2496 if (!timer_pending (&dev->delay)) {
2497 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2498 devdbg (dev, "rx throttle %d", urb_status);
2500 block:
2501 entry->state = rx_cleanup;
2502 entry->urb = urb;
2503 urb = NULL;
2504 break;
2506 // data overrun ... flush fifo?
2507 case -EOVERFLOW:
2508 dev->stats.rx_over_errors++;
2509 // FALLTHROUGH
2511 default:
2512 entry->state = rx_cleanup;
2513 dev->stats.rx_errors++;
2514 devdbg (dev, "rx status %d", urb_status);
2515 break;
2518 defer_bh (dev, skb);
2520 if (urb) {
2521 if (netif_running (dev->net)
2522 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2523 rx_submit (dev, urb, GFP_ATOMIC);
2524 return;
2526 usb_free_urb (urb);
2528 #ifdef VERBOSE
2529 devdbg (dev, "no read resubmitted");
2530 #endif /* VERBOSE */
2533 /*-------------------------------------------------------------------------*/
2535 // unlink pending rx/tx; completion handlers do all other cleanup
2537 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2539 unsigned long flags;
2540 struct sk_buff *skb, *skbnext;
2541 int count = 0;
2543 spin_lock_irqsave (&q->lock, flags);
2544 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2545 struct skb_data *entry;
2546 struct urb *urb;
2547 int retval;
2549 entry = (struct skb_data *) skb->cb;
2550 urb = entry->urb;
2551 skbnext = skb->next;
2553 // during some PM-driven resume scenarios,
2554 // these (async) unlinks complete immediately
2555 retval = usb_unlink_urb (urb);
2556 if (retval != -EINPROGRESS && retval != 0)
2557 devdbg (dev, "unlink urb err, %d", retval);
2558 else
2559 count++;
2561 spin_unlock_irqrestore (&q->lock, flags);
2562 return count;
2566 /*-------------------------------------------------------------------------*/
2568 // precondition: never called in_interrupt
2570 static int usbnet_stop (struct net_device *net)
2572 struct usbnet *dev = (struct usbnet *) net->priv;
2573 int temp;
2574 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2575 DECLARE_WAITQUEUE (wait, current);
2577 netif_stop_queue (net);
2579 if (dev->msg_level >= 2)
2580 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2581 dev->stats.rx_packets, dev->stats.tx_packets,
2582 dev->stats.rx_errors, dev->stats.tx_errors
2585 // ensure there are no more active urbs
2586 add_wait_queue (&unlink_wakeup, &wait);
2587 dev->wait = &unlink_wakeup;
2588 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2590 // maybe wait for deletions to finish.
2591 while (skb_queue_len (&dev->rxq)
2592 && skb_queue_len (&dev->txq)
2593 && skb_queue_len (&dev->done)) {
2594 msleep(UNLINK_TIMEOUT_MS);
2595 devdbg (dev, "waited for %d urb completions", temp);
2597 dev->wait = NULL;
2598 remove_wait_queue (&unlink_wakeup, &wait);
2600 /* deferred work (task, timer, softirq) must also stop.
2601 * can't flush_scheduled_work() until we drop rtnl (later),
2602 * else workers could deadlock; so make workers a NOP.
2604 dev->flags = 0;
2605 del_timer_sync (&dev->delay);
2606 tasklet_kill (&dev->bh);
2608 return 0;
2611 /*-------------------------------------------------------------------------*/
2613 // posts reads, and enables write queuing
2615 // precondition: never called in_interrupt
2617 static int usbnet_open (struct net_device *net)
2619 struct usbnet *dev = (struct usbnet *) net->priv;
2620 int retval = 0;
2621 struct driver_info *info = dev->driver_info;
2623 // put into "known safe" state
2624 if (info->reset && (retval = info->reset (dev)) < 0) {
2625 devinfo (dev, "open reset fail (%d) usbnet usb-%s-%s, %s",
2626 retval,
2627 dev->udev->bus->bus_name, dev->udev->devpath,
2628 info->description);
2629 goto done;
2632 // insist peer be connected
2633 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
2634 devdbg (dev, "can't open; %d", retval);
2635 goto done;
2638 netif_start_queue (net);
2639 if (dev->msg_level >= 2) {
2640 char *framing;
2642 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2643 framing = "NetChip";
2644 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
2645 framing = "GeneSys";
2646 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
2647 framing = "Zaurus";
2648 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
2649 framing = "RNDIS";
2650 else
2651 framing = "simple";
2653 devinfo (dev, "open: enable queueing "
2654 "(rx %d, tx %d) mtu %d %s framing",
2655 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
2656 framing);
2659 // delay posting reads until we're fully open
2660 tasklet_schedule (&dev->bh);
2661 done:
2662 return retval;
2665 /*-------------------------------------------------------------------------*/
2667 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
2669 struct usbnet *dev = net->priv;
2671 strncpy (info->driver, driver_name, sizeof info->driver);
2672 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
2673 strncpy (info->fw_version, dev->driver_info->description,
2674 sizeof info->fw_version);
2675 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
2678 static u32 usbnet_get_link (struct net_device *net)
2680 struct usbnet *dev = net->priv;
2682 /* If a check_connect is defined, return it's results */
2683 if (dev->driver_info->check_connect)
2684 return dev->driver_info->check_connect (dev) == 0;
2686 /* Otherwise, we're up to avoid breaking scripts */
2687 return 1;
2690 static u32 usbnet_get_msglevel (struct net_device *net)
2692 struct usbnet *dev = net->priv;
2694 return dev->msg_level;
2697 static void usbnet_set_msglevel (struct net_device *net, u32 level)
2699 struct usbnet *dev = net->priv;
2701 dev->msg_level = level;
2704 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
2706 #ifdef NEED_MII
2708 struct usbnet *dev = (struct usbnet *)net->priv;
2710 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
2711 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
2713 #endif
2714 return -EOPNOTSUPP;
2717 /*-------------------------------------------------------------------------*/
2719 /* work that cannot be done in interrupt context uses keventd.
2721 * NOTE: with 2.5 we could do more of this using completion callbacks,
2722 * especially now that control transfers can be queued.
2724 static void
2725 kevent (void *data)
2727 struct usbnet *dev = data;
2728 int status;
2730 /* usb_clear_halt() needs a thread context */
2731 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
2732 unlink_urbs (dev, &dev->txq);
2733 status = usb_clear_halt (dev->udev, dev->out);
2734 if (status < 0)
2735 deverr (dev, "can't clear tx halt, status %d",
2736 status);
2737 else {
2738 clear_bit (EVENT_TX_HALT, &dev->flags);
2739 netif_wake_queue (dev->net);
2742 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
2743 unlink_urbs (dev, &dev->rxq);
2744 status = usb_clear_halt (dev->udev, dev->in);
2745 if (status < 0)
2746 deverr (dev, "can't clear rx halt, status %d",
2747 status);
2748 else {
2749 clear_bit (EVENT_RX_HALT, &dev->flags);
2750 tasklet_schedule (&dev->bh);
2754 /* tasklet could resubmit itself forever if memory is tight */
2755 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
2756 struct urb *urb = NULL;
2758 if (netif_running (dev->net))
2759 urb = usb_alloc_urb (0, GFP_KERNEL);
2760 else
2761 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2762 if (urb != 0) {
2763 clear_bit (EVENT_RX_MEMORY, &dev->flags);
2764 rx_submit (dev, urb, GFP_KERNEL);
2765 tasklet_schedule (&dev->bh);
2769 if (dev->flags)
2770 devdbg (dev, "kevent done, flags = 0x%lx",
2771 dev->flags);
2774 /*-------------------------------------------------------------------------*/
2776 static void tx_complete (struct urb *urb, struct pt_regs *regs)
2778 struct sk_buff *skb = (struct sk_buff *) urb->context;
2779 struct skb_data *entry = (struct skb_data *) skb->cb;
2780 struct usbnet *dev = entry->dev;
2782 if (urb->status == 0) {
2783 dev->stats.tx_packets++;
2784 dev->stats.tx_bytes += entry->length;
2785 } else {
2786 dev->stats.tx_errors++;
2788 switch (urb->status) {
2789 case -EPIPE:
2790 defer_kevent (dev, EVENT_TX_HALT);
2791 break;
2793 // like rx, tx gets controller i/o faults during khubd delays
2794 // and so it uses the same throttling mechanism.
2795 case -EPROTO: // ehci
2796 case -ETIMEDOUT: // ohci
2797 case -EILSEQ: // uhci
2798 if (!timer_pending (&dev->delay)) {
2799 mod_timer (&dev->delay,
2800 jiffies + THROTTLE_JIFFIES);
2801 devdbg (dev, "tx throttle %d", urb->status);
2803 netif_stop_queue (dev->net);
2804 break;
2805 default:
2806 devdbg (dev, "tx err %d", entry->urb->status);
2807 break;
2811 urb->dev = NULL;
2812 entry->state = tx_done;
2813 defer_bh (dev, skb);
2816 /*-------------------------------------------------------------------------*/
2818 static void usbnet_tx_timeout (struct net_device *net)
2820 struct usbnet *dev = (struct usbnet *) net->priv;
2822 unlink_urbs (dev, &dev->txq);
2823 tasklet_schedule (&dev->bh);
2825 // FIXME: device recovery -- reset?
2828 /*-------------------------------------------------------------------------*/
2830 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
2832 struct usbnet *dev = (struct usbnet *) net->priv;
2833 int length;
2834 int retval = NET_XMIT_SUCCESS;
2835 struct urb *urb = NULL;
2836 struct skb_data *entry;
2837 struct driver_info *info = dev->driver_info;
2838 unsigned long flags;
2839 #ifdef CONFIG_USB_NET1080
2840 struct nc_header *header = NULL;
2841 struct nc_trailer *trailer = NULL;
2842 #endif /* CONFIG_USB_NET1080 */
2844 // some devices want funky USB-level framing, for
2845 // win32 driver (usually) and/or hardware quirks
2846 if (info->tx_fixup) {
2847 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
2848 if (!skb) {
2849 devdbg (dev, "can't tx_fixup skb");
2850 goto drop;
2853 length = skb->len;
2855 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
2856 devdbg (dev, "no urb");
2857 goto drop;
2860 entry = (struct skb_data *) skb->cb;
2861 entry->urb = urb;
2862 entry->dev = dev;
2863 entry->state = tx_start;
2864 entry->length = length;
2866 // FIXME: reorganize a bit, so that fixup() fills out NetChip
2867 // framing too. (Packet ID update needs the spinlock...)
2868 // [ BETTER: we already own net->xmit_lock, that's enough ]
2870 #ifdef CONFIG_USB_NET1080
2871 if (info->flags & FLAG_FRAMING_NC) {
2872 header = (struct nc_header *) skb_push (skb, sizeof *header);
2873 header->hdr_len = cpu_to_le16 (sizeof (*header));
2874 header->packet_len = cpu_to_le16 (length);
2875 if (!((skb->len + sizeof *trailer) & 0x01))
2876 *skb_put (skb, 1) = PAD_BYTE;
2877 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
2879 #endif /* CONFIG_USB_NET1080 */
2881 usb_fill_bulk_urb (urb, dev->udev, dev->out,
2882 skb->data, skb->len, tx_complete, skb);
2883 urb->transfer_flags |= URB_ASYNC_UNLINK;
2885 /* don't assume the hardware handles USB_ZERO_PACKET
2886 * NOTE: strictly conforming cdc-ether devices should expect
2887 * the ZLP here, but ignore the one-byte packet.
2889 * FIXME zero that byte, if it doesn't require a new skb.
2891 if ((length % dev->maxpacket) == 0)
2892 urb->transfer_buffer_length++;
2894 spin_lock_irqsave (&dev->txq.lock, flags);
2896 #ifdef CONFIG_USB_NET1080
2897 if (info->flags & FLAG_FRAMING_NC) {
2898 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
2899 put_unaligned (header->packet_id, &trailer->packet_id);
2900 #if 0
2901 devdbg (dev, "frame >tx h %d p %d id %d",
2902 header->hdr_len, header->packet_len,
2903 header->packet_id);
2904 #endif
2906 #endif /* CONFIG_USB_NET1080 */
2908 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
2909 case -EPIPE:
2910 netif_stop_queue (net);
2911 defer_kevent (dev, EVENT_TX_HALT);
2912 break;
2913 default:
2914 devdbg (dev, "tx: submit urb err %d", retval);
2915 break;
2916 case 0:
2917 net->trans_start = jiffies;
2918 __skb_queue_tail (&dev->txq, skb);
2919 if (dev->txq.qlen >= TX_QLEN (dev))
2920 netif_stop_queue (net);
2922 spin_unlock_irqrestore (&dev->txq.lock, flags);
2924 if (retval) {
2925 devdbg (dev, "drop, code %d", retval);
2926 drop:
2927 retval = NET_XMIT_SUCCESS;
2928 dev->stats.tx_dropped++;
2929 if (skb)
2930 dev_kfree_skb_any (skb);
2931 usb_free_urb (urb);
2932 #ifdef VERBOSE
2933 } else {
2934 devdbg (dev, "> tx, len %d, type 0x%x",
2935 length, skb->protocol);
2936 #endif
2938 return retval;
2942 /*-------------------------------------------------------------------------*/
2944 // tasklet (work deferred from completions, in_irq) or timer
2946 static void usbnet_bh (unsigned long param)
2948 struct usbnet *dev = (struct usbnet *) param;
2949 struct sk_buff *skb;
2950 struct skb_data *entry;
2952 while ((skb = skb_dequeue (&dev->done))) {
2953 entry = (struct skb_data *) skb->cb;
2954 switch (entry->state) {
2955 case rx_done:
2956 entry->state = rx_cleanup;
2957 rx_process (dev, skb);
2958 continue;
2959 case tx_done:
2960 case rx_cleanup:
2961 usb_free_urb (entry->urb);
2962 dev_kfree_skb (skb);
2963 continue;
2964 default:
2965 devdbg (dev, "bogus skb state %d", entry->state);
2969 // waiting for all pending urbs to complete?
2970 if (dev->wait) {
2971 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
2972 wake_up (dev->wait);
2975 // or are we maybe short a few urbs?
2976 } else if (netif_running (dev->net)
2977 && netif_device_present (dev->net)
2978 && !timer_pending (&dev->delay)
2979 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2980 int temp = dev->rxq.qlen;
2981 int qlen = RX_QLEN (dev);
2983 if (temp < qlen) {
2984 struct urb *urb;
2985 int i;
2987 // don't refill the queue all at once
2988 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
2989 if ((urb = usb_alloc_urb (0, GFP_ATOMIC)) != 0)
2990 rx_submit (dev, urb, GFP_ATOMIC);
2992 if (temp != dev->rxq.qlen)
2993 devdbg (dev, "rxqlen %d --> %d",
2994 temp, dev->rxq.qlen);
2995 if (dev->rxq.qlen < qlen)
2996 tasklet_schedule (&dev->bh);
2998 if (dev->txq.qlen < TX_QLEN (dev))
2999 netif_wake_queue (dev->net);
3005 /*-------------------------------------------------------------------------
3007 * USB Device Driver support
3009 *-------------------------------------------------------------------------*/
3011 // precondition: never called in_interrupt
3013 static void usbnet_disconnect (struct usb_interface *intf)
3015 struct usbnet *dev;
3016 struct usb_device *xdev;
3018 dev = usb_get_intfdata(intf);
3019 usb_set_intfdata(intf, NULL);
3020 if (!dev)
3021 return;
3023 xdev = interface_to_usbdev (intf);
3025 devinfo (dev, "unregister usbnet usb-%s-%s, %s",
3026 xdev->bus->bus_name, xdev->devpath,
3027 dev->driver_info->description);
3029 unregister_netdev (dev->net);
3031 /* we don't hold rtnl here ... */
3032 flush_scheduled_work ();
3034 if (dev->driver_info->unbind)
3035 dev->driver_info->unbind (dev, intf);
3037 free_netdev(dev->net);
3038 kfree (dev);
3039 usb_put_dev (xdev);
3043 /*-------------------------------------------------------------------------*/
3045 static struct ethtool_ops usbnet_ethtool_ops;
3047 // precondition: never called in_interrupt
3049 static int
3050 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3052 struct usbnet *dev;
3053 struct net_device *net;
3054 struct usb_host_interface *interface;
3055 struct driver_info *info;
3056 struct usb_device *xdev;
3057 int status;
3059 info = (struct driver_info *) prod->driver_info;
3060 if (!info) {
3061 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3062 return -ENODEV;
3064 xdev = interface_to_usbdev (udev);
3065 interface = udev->cur_altsetting;
3067 usb_get_dev (xdev);
3069 status = -ENOMEM;
3071 // set up our own records
3072 if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) {
3073 dbg ("can't kmalloc dev");
3074 goto out;
3076 memset (dev, 0, sizeof *dev);
3078 dev->udev = xdev;
3079 dev->driver_info = info;
3080 dev->msg_level = msg_level;
3081 skb_queue_head_init (&dev->rxq);
3082 skb_queue_head_init (&dev->txq);
3083 skb_queue_head_init (&dev->done);
3084 dev->bh.func = usbnet_bh;
3085 dev->bh.data = (unsigned long) dev;
3086 INIT_WORK (&dev->kevent, kevent, dev);
3087 dev->delay.function = usbnet_bh;
3088 dev->delay.data = (unsigned long) dev;
3089 init_timer (&dev->delay);
3091 // set up network interface records
3092 net = alloc_etherdev(0);
3093 if (!net)
3094 goto out1;
3096 SET_MODULE_OWNER (net);
3097 dev->net = net;
3098 net->priv = dev;
3099 strcpy (net->name, "usb%d");
3100 memcpy (net->dev_addr, node_id, sizeof node_id);
3102 #if 0
3103 // dma_supported() is deeply broken on almost all architectures
3104 // possible with some EHCI controllers
3105 if (dma_supported (&udev->dev, 0xffffffffffffffffULL))
3106 net->features |= NETIF_F_HIGHDMA;
3107 #endif
3109 net->change_mtu = usbnet_change_mtu;
3110 net->get_stats = usbnet_get_stats;
3111 net->hard_start_xmit = usbnet_start_xmit;
3112 net->open = usbnet_open;
3113 net->stop = usbnet_stop;
3114 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3115 net->tx_timeout = usbnet_tx_timeout;
3116 net->do_ioctl = usbnet_ioctl;
3117 net->ethtool_ops = &usbnet_ethtool_ops;
3119 // allow device-specific bind/init procedures
3120 // NOTE net->name still not usable ...
3121 if (info->bind) {
3122 status = info->bind (dev, udev);
3123 // heuristic: "usb%d" for links we know are two-host,
3124 // else "eth%d" when there's reasonable doubt. userspace
3125 // can rename the link if it knows better.
3126 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3127 && (net->dev_addr [0] & 0x02) == 0)
3128 strcpy (net->name, "eth%d");
3129 } else if (!info->in || info->out)
3130 status = get_endpoints (dev, udev);
3131 else {
3132 dev->in = usb_rcvbulkpipe (xdev, info->in);
3133 dev->out = usb_sndbulkpipe (xdev, info->out);
3134 if (!(info->flags & FLAG_NO_SETINT))
3135 status = usb_set_interface (xdev,
3136 interface->desc.bInterfaceNumber,
3137 interface->desc.bAlternateSetting);
3138 else
3139 status = 0;
3142 if (status < 0)
3143 goto out1;
3145 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3147 SET_NETDEV_DEV(dev->net, &udev->dev);
3148 status = register_netdev (dev->net);
3149 if (status)
3150 goto out3;
3151 devinfo (dev, "register usbnet at usb-%s-%s, %s",
3152 xdev->bus->bus_name, xdev->devpath,
3153 dev->driver_info->description);
3155 // ok, it's ready to go.
3156 usb_set_intfdata (udev, dev);
3158 // start as if the link is up
3159 netif_device_attach (dev->net);
3161 return 0;
3163 out3:
3164 if (info->unbind)
3165 info->unbind (dev, udev);
3166 free_netdev(net);
3167 out1:
3168 kfree(dev);
3169 out:
3170 usb_put_dev(xdev);
3171 return status;
3175 /*-------------------------------------------------------------------------*/
3177 #ifndef HAVE_HARDWARE
3178 #error You need to configure some hardware for this driver
3179 #endif
3182 * chip vendor names won't normally be on the cables, and
3183 * may not be on the device.
3186 static const struct usb_device_id products [] = {
3188 #ifdef CONFIG_USB_ALI_M5632
3190 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3191 .driver_info = (unsigned long) &ali_m5632_info,
3193 #endif
3195 #ifdef CONFIG_USB_AN2720
3197 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3198 .driver_info = (unsigned long) &an2720_info,
3199 }, {
3200 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3201 .driver_info = (unsigned long) &an2720_info,
3203 #endif
3205 #ifdef CONFIG_USB_BELKIN
3207 USB_DEVICE (0x050d, 0x0004), // Belkin
3208 .driver_info = (unsigned long) &belkin_info,
3209 }, {
3210 USB_DEVICE (0x056c, 0x8100), // eTEK
3211 .driver_info = (unsigned long) &belkin_info,
3212 }, {
3213 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3214 .driver_info = (unsigned long) &belkin_info,
3216 #endif
3218 #ifdef CONFIG_USB_AX8817X
3220 // Linksys USB200M
3221 USB_DEVICE (0x077b, 0x2226),
3222 .driver_info = (unsigned long) &ax8817x_info,
3223 }, {
3224 // Netgear FA120
3225 USB_DEVICE (0x0846, 0x1040),
3226 .driver_info = (unsigned long) &netgear_fa120_info,
3227 }, {
3228 // DLink DUB-E100
3229 USB_DEVICE (0x2001, 0x1a00),
3230 .driver_info = (unsigned long) &dlink_dub_e100_info,
3231 }, {
3232 // Intellinet, ST Lab USB Ethernet
3233 USB_DEVICE (0x0b95, 0x1720),
3234 .driver_info = (unsigned long) &ax8817x_info,
3235 }, {
3236 // Hawking UF200, TrendNet TU2-ET100
3237 USB_DEVICE (0x07b8, 0x420a),
3238 .driver_info = (unsigned long) &hawking_uf200_info,
3239 }, {
3240 // Billionton Systems, USB2AR
3241 USB_DEVICE (0x08dd, 0x90ff),
3242 .driver_info = (unsigned long) &ax8817x_info,
3243 }, {
3244 // ATEN UC210T
3245 USB_DEVICE (0x0557, 0x2009),
3246 .driver_info = (unsigned long) &ax8817x_info,
3247 }, {
3248 // Buffalo LUA-U2-KTX
3249 USB_DEVICE (0x0411, 0x003d),
3250 .driver_info = (unsigned long) &ax8817x_info,
3251 }, {
3252 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3253 USB_DEVICE (0x6189, 0x182d),
3254 .driver_info = (unsigned long) &ax8817x_info,
3256 #endif
3258 #ifdef CONFIG_USB_EPSON2888
3260 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3261 .driver_info = (unsigned long) &epson2888_info,
3263 #endif
3265 #ifdef CONFIG_USB_GENESYS
3267 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3268 .driver_info = (unsigned long) &genelink_info,
3270 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3271 * that's half duplex, not currently supported
3273 #endif
3275 #ifdef CONFIG_USB_NET1080
3277 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3278 .driver_info = (unsigned long) &net1080_info,
3279 }, {
3280 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3281 .driver_info = (unsigned long) &net1080_info,
3283 #endif
3285 #ifdef CONFIG_USB_PL2301
3287 USB_DEVICE (0x067b, 0x0000), // PL-2301
3288 .driver_info = (unsigned long) &prolific_info,
3289 }, {
3290 USB_DEVICE (0x067b, 0x0001), // PL-2302
3291 .driver_info = (unsigned long) &prolific_info,
3293 #endif
3295 #ifdef CONFIG_USB_RNDIS
3297 /* RNDIS is MSFT's un-official variant of CDC ACM */
3298 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3299 .driver_info = (unsigned long) &rndis_info,
3301 #endif
3303 #ifdef CONFIG_USB_ARMLINUX
3305 * SA-1100 using standard ARM Linux kernels, or compatible.
3306 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3307 * The sa-1100 "usb-eth" driver handles the basic framing.
3309 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3310 * the sa1100 one, but hardware uses different endpoint numbers.
3313 // 1183 = 0x049F, both used as hex values?
3314 // Compaq "Itsy" vendor/product id
3315 USB_DEVICE (0x049F, 0x505A),
3316 .driver_info = (unsigned long) &linuxdev_info,
3317 }, {
3318 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3319 .driver_info = (unsigned long) &yopy_info,
3320 }, {
3321 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3322 .driver_info = (unsigned long) &blob_info,
3324 #endif
3326 #ifdef CONFIG_USB_ZAURUS
3328 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3329 * Same idea as above, but different framing.
3331 * PXA-2xx based models are also lying-about-cdc.
3334 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3335 | USB_DEVICE_ID_MATCH_DEVICE,
3336 .idVendor = 0x04DD,
3337 .idProduct = 0x8004,
3338 /* match the master interface */
3339 .bInterfaceClass = USB_CLASS_COMM,
3340 .bInterfaceSubClass = 6 /* Ethernet model */,
3341 .bInterfaceProtocol = 0,
3342 .driver_info = (unsigned long) &zaurus_sl5x00_info,
3343 }, {
3344 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3345 | USB_DEVICE_ID_MATCH_DEVICE,
3346 .idVendor = 0x04DD,
3347 .idProduct = 0x8005, /* A-300 */
3348 .bInterfaceClass = 0x02,
3349 .bInterfaceSubClass = 0x0a,
3350 .bInterfaceProtocol = 0x00,
3351 .driver_info = (unsigned long) &zaurus_pxa_info,
3352 }, {
3353 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3354 | USB_DEVICE_ID_MATCH_DEVICE,
3355 .idVendor = 0x04DD,
3356 .idProduct = 0x8006, /* B-500/SL-5600 */
3357 .bInterfaceClass = 0x02,
3358 .bInterfaceSubClass = 0x0a,
3359 .bInterfaceProtocol = 0x00,
3360 .driver_info = (unsigned long) &zaurus_pxa_info,
3361 }, {
3362 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3363 | USB_DEVICE_ID_MATCH_DEVICE,
3364 .idVendor = 0x04DD,
3365 .idProduct = 0x8007, /* C-700 */
3366 .bInterfaceClass = 0x02,
3367 .bInterfaceSubClass = 0x0a,
3368 .bInterfaceProtocol = 0x00,
3369 .driver_info = (unsigned long) &zaurus_pxa_info,
3370 }, {
3371 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3372 | USB_DEVICE_ID_MATCH_DEVICE,
3373 .idVendor = 0x04DD,
3374 .idProduct = 0x9031, /* C-750 C-760 */
3375 .bInterfaceClass = 0x02,
3376 .bInterfaceSubClass = 0x0a,
3377 .bInterfaceProtocol = 0x00,
3378 .driver_info = (unsigned long) &zaurus_pxa_info,
3379 }, {
3380 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3381 | USB_DEVICE_ID_MATCH_DEVICE,
3382 .idVendor = 0x04DD,
3383 .idProduct = 0x9032, /* SL-6000 */
3384 .bInterfaceClass = 0x02,
3385 .bInterfaceSubClass = 0x0a,
3386 .bInterfaceProtocol = 0x00,
3387 .driver_info = (unsigned long) &zaurus_pxa_info,
3388 }, {
3389 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3390 | USB_DEVICE_ID_MATCH_DEVICE,
3391 .idVendor = 0x04DD,
3392 .idProduct = 0x9050, /* C-860 */
3393 .bInterfaceClass = 0x02,
3394 .bInterfaceSubClass = 0x0a,
3395 .bInterfaceProtocol = 0x00,
3396 .driver_info = (unsigned long) &zaurus_pxa_info,
3398 #endif
3400 #ifdef CONFIG_USB_CDCETHER
3402 #ifndef CONFIG_USB_ZAURUS
3403 /* if we couldn't whitelist Zaurus, we must blacklist it */
3405 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3406 | USB_DEVICE_ID_MATCH_DEVICE,
3407 .idVendor = 0x04DD,
3408 .idProduct = 0x8004,
3409 /* match the master interface */
3410 .bInterfaceClass = USB_CLASS_COMM,
3411 .bInterfaceSubClass = 6 /* Ethernet model */,
3412 .bInterfaceProtocol = 0,
3413 .driver_info = 0, /* BLACKLIST */
3415 // FIXME blacklist the other Zaurus models too, sigh
3416 #endif
3419 /* CDC Ether uses two interfaces, not necessarily consecutive.
3420 * We match the main interface, ignoring the optional device
3421 * class so we could handle devices that aren't exclusively
3422 * CDC ether.
3424 * NOTE: this match must come AFTER entries working around
3425 * bugs/quirks in a given product (like Zaurus, above).
3427 USB_INTERFACE_INFO (USB_CLASS_COMM, 6 /* Ethernet model */, 0),
3428 .driver_info = (unsigned long) &cdc_info,
3430 #endif
3432 { }, // END
3434 MODULE_DEVICE_TABLE (usb, products);
3436 static struct usb_driver usbnet_driver = {
3437 .owner = THIS_MODULE,
3438 .name = driver_name,
3439 .id_table = products,
3440 .probe = usbnet_probe,
3441 .disconnect = usbnet_disconnect,
3444 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
3445 static struct ethtool_ops usbnet_ethtool_ops = {
3446 .get_drvinfo = usbnet_get_drvinfo,
3447 .get_link = usbnet_get_link,
3448 .get_msglevel = usbnet_get_msglevel,
3449 .set_msglevel = usbnet_set_msglevel,
3452 /*-------------------------------------------------------------------------*/
3454 static int __init usbnet_init (void)
3456 // compiler should optimize these out
3457 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3458 < sizeof (struct skb_data));
3459 #ifdef CONFIG_USB_CDCETHER
3460 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3461 < sizeof (struct cdc_state)));
3462 #endif
3464 random_ether_addr(node_id);
3466 return usb_register(&usbnet_driver);
3468 module_init (usbnet_init);
3470 static void __exit usbnet_exit (void)
3472 usb_deregister (&usbnet_driver);
3474 module_exit (usbnet_exit);
3476 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
3477 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
3478 MODULE_LICENSE ("GPL");