3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
7 * Copyright (c) 2002-2003 TiVo Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * This is a generic "USB networking" framework that works with several
26 * kinds of full and high speed networking devices:
28 * + USB host-to-host "network cables", used for IP-over-USB links.
29 * These are often used for Laplink style connectivity products.
31 * - Belkin, eTEK (interops with Win32 drivers)
32 * - GeneSys GL620USB-A
33 * - NetChip 1080 (interoperates with NetChip Win32 drivers)
34 * - Prolific PL-2301/2302 (replaces "plusb" driver)
35 * - KC Technology KC2190
37 * + Smart USB devices can support such links directly, using Internet
38 * standard protocols instead of proprietary host-to-device links.
39 * - Linux PDAs like iPaq, Yopy, and Zaurus
40 * - The BLOB boot loader (for diskless booting)
41 * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
42 * - Devices using EPSON's sample USB firmware
43 * - CDC-Ethernet class devices, such as many cable modems
45 * + Adapters to networks such as Ethernet.
46 * - AX8817X based USB 2.0 products
48 * Links to these devices can be bridged using Linux Ethernet bridging.
49 * With minor exceptions, these all use similar USB framing for network
50 * traffic, but need different protocols for control traffic.
52 * USB devices can implement their side of this protocol at the cost
53 * of two bulk endpoints; it's not restricted to "cable" applications.
54 * See the SA1110, Zaurus, or EPSON device/client support in this driver;
55 * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
56 * "g_ether" (in the Linux "gadget" framework) implement that behavior
62 * 13-sep-2000 experimental, new
63 * 10-oct-2000 usb_device_id table created.
64 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
65 * 01-nov-2000 usb_device_id table and probing api update by
66 * Adam J. Richter <adam@yggdrasil.com>.
67 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
68 * and prolific support, isolate net1080-specific bits, cleanup.
69 * fix unlink_urbs oops in D3 PM resume code path.
71 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
72 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
73 * AnchorChips 2720 support (from spec) for testing;
74 * fix bit-ordering problem with ethernet multicast addr
75 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
76 * updates. Oleg Drokin (green@iXcelerator.com)
77 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
78 * expecting cleared skb->cb and framing change to match latest
79 * handhelds.org version (Oleg). Enable device IDs from the
80 * Win32 Belkin driver; other cleanups (db).
81 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
82 * cleanups for problems not yet seen in the field. (db)
83 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
84 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
85 * rx unlinks somehow weren't async; minor cleanup.
86 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
87 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
88 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
89 * tie mostly to (sub)driver info. Workaround some PL-2302
90 * chips that seem to reject SET_INTERFACE requests.
92 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
93 * Level of diagnostics is more configurable; they use device
94 * location (usb_device->devpath) instead of address (2.5).
95 * For tx_fixup, memflags can't be NOIO.
96 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
97 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
98 * Use "locally assigned" IEEE802 address space. (Brad Hards)
99 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
100 * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
101 * cleanups and stubbed PXA-250 support (db), fix for framing
102 * issues on Z, net1080, and gl620a (Toby Milne)
104 * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
105 * vs pxa25x, and CDC Ethernet. Throttle down log floods on
106 * disconnect; other cleanups. (db) Flush net1080 fifos
107 * after several sequential framing errors. (Johannes Erdfelt)
108 * 22-aug-2003 AX8817X support (Dave Hollis).
109 * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
111 * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
113 * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis)
114 *-------------------------------------------------------------------------*/
116 // #define DEBUG // error path messages, extra info
117 // #define VERBOSE // more; success messages
119 #include <linux/config.h>
120 #ifdef CONFIG_USB_DEBUG
123 #include <linux/module.h>
124 #include <linux/kmod.h>
125 #include <linux/sched.h>
126 #include <linux/init.h>
127 #include <linux/netdevice.h>
128 #include <linux/etherdevice.h>
129 #include <linux/ethtool.h>
130 #include <linux/workqueue.h>
131 #include <linux/mii.h>
132 #include <linux/usb.h>
133 #include <linux/mm.h>
134 #include <linux/dma-mapping.h>
136 #include <asm/unaligned.h>
140 #define DRIVER_VERSION "22-Aug-2005"
143 /*-------------------------------------------------------------------------*/
146 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
147 * Several dozen bytes of IPv4 data can fit in two such transactions.
148 * One maximum size Ethernet packet takes twenty four of them.
149 * For high speed, each frame comfortably fits almost 36 max size
150 * Ethernet packets (so queues should be bigger).
152 * REVISIT qlens should be members of 'struct usbnet'; the goal is to
153 * let the USB host controller be busy for 5msec or more before an irq
154 * is required, under load. Jumbograms change the equation.
156 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
157 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
159 /* packets are always ethernet, sometimes wrapped in other framing */
160 #define MIN_PACKET sizeof(struct ethhdr)
162 // reawaken network queue this soon after stopping; else watchdog barks
163 #define TX_TIMEOUT_JIFFIES (5*HZ)
165 // throttle rx/tx briefly after some faults, so khubd might disconnect()
166 // us (it polls at HZ/4 usually) before we report too many false errors.
167 #define THROTTLE_JIFFIES (HZ/8)
169 // for vendor-specific control operations
170 #define CONTROL_TIMEOUT_MS USB_CTRL_GET_TIMEOUT
173 #define UNLINK_TIMEOUT_MS 3
175 /*-------------------------------------------------------------------------*/
177 // randomly generated ethernet address
178 static u8 node_id [ETH_ALEN];
180 static const char driver_name [] = "usbnet";
182 /* use ethtool to change the level for any given device */
183 static int msg_level = -1;
184 module_param (msg_level, int, 0);
185 MODULE_PARM_DESC (msg_level, "Override default message level");
187 /*-------------------------------------------------------------------------*/
189 static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
190 static u32 usbnet_get_link (struct net_device *);
191 static u32 usbnet_get_msglevel (struct net_device *);
192 static void usbnet_set_msglevel (struct net_device *, u32);
193 static void defer_kevent (struct usbnet *, int);
195 /* mostly for PDA style devices, which are always connected if present */
196 static int always_connected (struct usbnet *dev)
201 /* handles CDC Ethernet and many other network "bulk data" interfaces */
203 get_endpoints (struct usbnet *dev, struct usb_interface *intf)
206 struct usb_host_interface *alt = NULL;
207 struct usb_host_endpoint *in = NULL, *out = NULL;
208 struct usb_host_endpoint *status = NULL;
210 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
213 in = out = status = NULL;
214 alt = intf->altsetting + tmp;
216 /* take the first altsetting with in-bulk + out-bulk;
217 * remember any status endpoint, just in case;
218 * ignore other endpoints and altsetttings.
220 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
221 struct usb_host_endpoint *e;
224 e = alt->endpoint + ep;
225 switch (e->desc.bmAttributes) {
226 case USB_ENDPOINT_XFER_INT:
227 if (!(e->desc.bEndpointAddress & USB_DIR_IN))
231 case USB_ENDPOINT_XFER_BULK:
236 if (e->desc.bEndpointAddress & USB_DIR_IN) {
239 else if (intr && !status)
249 if (!alt || !in || !out)
252 if (alt->desc.bAlternateSetting != 0
253 || !(dev->driver_info->flags & FLAG_NO_SETINT)) {
254 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
255 alt->desc.bAlternateSetting);
260 dev->in = usb_rcvbulkpipe (dev->udev,
261 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
262 dev->out = usb_sndbulkpipe (dev->udev,
263 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
264 dev->status = status;
268 static void intr_complete (struct urb *urb, struct pt_regs *regs);
270 static int init_status (struct usbnet *dev, struct usb_interface *intf)
277 if (!dev->driver_info->status)
280 pipe = usb_rcvintpipe (dev->udev,
281 dev->status->desc.bEndpointAddress
282 & USB_ENDPOINT_NUMBER_MASK);
283 maxp = usb_maxpacket (dev->udev, pipe, 0);
285 /* avoid 1 msec chatter: min 8 msec poll rate */
286 period = max ((int) dev->status->desc.bInterval,
287 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
289 buf = kmalloc (maxp, SLAB_KERNEL);
291 dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL);
292 if (!dev->interrupt) {
296 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
297 buf, maxp, intr_complete, dev, period);
299 "status ep%din, %d bytes period %d\n",
300 usb_pipeendpoint(pipe), maxp, period);
306 static void skb_return (struct usbnet *dev, struct sk_buff *skb)
311 skb->protocol = eth_type_trans (skb, dev->net);
312 dev->stats.rx_packets++;
313 dev->stats.rx_bytes += skb->len;
315 if (netif_msg_rx_status (dev))
316 devdbg (dev, "< rx, len %zu, type 0x%x",
317 skb->len + sizeof (struct ethhdr), skb->protocol);
318 memset (skb->cb, 0, sizeof (struct skb_data));
319 status = netif_rx (skb);
320 if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
321 devdbg (dev, "netif_rx status %d", status);
325 #ifdef CONFIG_USB_AX8817X
326 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
328 #define HAVE_HARDWARE
331 #include <linux/crc32.h>
333 #define AX_CMD_SET_SW_MII 0x06
334 #define AX_CMD_READ_MII_REG 0x07
335 #define AX_CMD_WRITE_MII_REG 0x08
336 #define AX_CMD_SET_HW_MII 0x0a
337 #define AX_CMD_READ_EEPROM 0x0b
338 #define AX_CMD_WRITE_EEPROM 0x0c
339 #define AX_CMD_WRITE_ENABLE 0x0d
340 #define AX_CMD_WRITE_DISABLE 0x0e
341 #define AX_CMD_WRITE_RX_CTL 0x10
342 #define AX_CMD_READ_IPG012 0x11
343 #define AX_CMD_WRITE_IPG0 0x12
344 #define AX_CMD_WRITE_IPG1 0x13
345 #define AX_CMD_WRITE_IPG2 0x14
346 #define AX_CMD_WRITE_MULTI_FILTER 0x16
347 #define AX_CMD_READ_NODE_ID 0x17
348 #define AX_CMD_READ_PHY_ID 0x19
349 #define AX_CMD_READ_MEDIUM_STATUS 0x1a
350 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
351 #define AX_CMD_READ_MONITOR_MODE 0x1c
352 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
353 #define AX_CMD_WRITE_GPIOS 0x1f
354 #define AX_CMD_SW_RESET 0x20
355 #define AX_CMD_SW_PHY_STATUS 0x21
356 #define AX_CMD_SW_PHY_SELECT 0x22
357 #define AX88772_CMD_READ_NODE_ID 0x13
359 #define AX_MONITOR_MODE 0x01
360 #define AX_MONITOR_LINK 0x02
361 #define AX_MONITOR_MAGIC 0x04
362 #define AX_MONITOR_HSFS 0x10
364 /* AX88172 Medium Status Register values */
365 #define AX_MEDIUM_FULL_DUPLEX 0x02
366 #define AX_MEDIUM_TX_ABORT_ALLOW 0x04
367 #define AX_MEDIUM_FLOW_CONTROL_EN 0x10
369 #define AX_MCAST_FILTER_SIZE 8
370 #define AX_MAX_MCAST 64
372 #define AX_EEPROM_LEN 0x40
374 #define AX_SWRESET_CLEAR 0x00
375 #define AX_SWRESET_RR 0x01
376 #define AX_SWRESET_RT 0x02
377 #define AX_SWRESET_PRTE 0x04
378 #define AX_SWRESET_PRL 0x08
379 #define AX_SWRESET_BZ 0x10
380 #define AX_SWRESET_IPRL 0x20
381 #define AX_SWRESET_IPPD 0x40
383 #define AX88772_IPG0_DEFAULT 0x15
384 #define AX88772_IPG1_DEFAULT 0x0c
385 #define AX88772_IPG2_DEFAULT 0x12
387 #define AX88772_MEDIUM_FULL_DUPLEX 0x0002
388 #define AX88772_MEDIUM_RESERVED 0x0004
389 #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
390 #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
391 #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
392 #define AX88772_MEDIUM_RX_ENABLE 0x0100
393 #define AX88772_MEDIUM_100MB 0x0200
394 #define AX88772_MEDIUM_DEFAULT \
395 (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
396 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
397 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
399 #define AX_EEPROM_MAGIC 0xdeadbeef
401 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
402 struct ax8817x_data {
403 u8 multi_filter[AX_MCAST_FILTER_SIZE];
406 struct ax88172_int_data {
412 } __attribute__ ((packed));
414 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
415 u16 size, void *data)
417 return usb_control_msg(
419 usb_rcvctrlpipe(dev->udev, 0),
421 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
429 static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
430 u16 size, void *data)
432 return usb_control_msg(
434 usb_sndctrlpipe(dev->udev, 0),
436 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
444 static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
446 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
449 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
456 static void ax8817x_status(struct usbnet *dev, struct urb *urb)
458 struct ax88172_int_data *event;
461 if (urb->actual_length < 8)
464 event = urb->transfer_buffer;
465 link = event->link & 0x01;
466 if (netif_carrier_ok(dev->net) != link) {
468 netif_carrier_on(dev->net);
469 defer_kevent (dev, EVENT_LINK_RESET );
471 netif_carrier_off(dev->net);
472 devdbg(dev, "ax8817x - Link Status is: %d", link);
476 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
477 u16 size, void *data)
479 struct usb_ctrlrequest *req;
483 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
484 devdbg(dev, "Error allocating URB in write_cmd_async!");
488 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
489 deverr(dev, "Failed to allocate memory for control request");
494 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
496 req->wValue = cpu_to_le16(value);
497 req->wIndex = cpu_to_le16(index);
498 req->wLength = cpu_to_le16(size);
500 usb_fill_control_urb(urb, dev->udev,
501 usb_sndctrlpipe(dev->udev, 0),
502 (void *)req, data, size,
503 ax8817x_async_cmd_callback, req);
505 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
506 deverr(dev, "Error submitting the control message: status=%d", status);
512 static void ax8817x_set_multicast(struct net_device *net)
514 struct usbnet *dev = netdev_priv(net);
515 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
518 if (net->flags & IFF_PROMISC) {
520 } else if (net->flags & IFF_ALLMULTI
521 || net->mc_count > AX_MAX_MCAST) {
523 } else if (net->mc_count == 0) {
524 /* just broadcast and directed */
526 /* We use the 20 byte dev->data
527 * for our 8 byte filter buffer
528 * to avoid allocating memory that
529 * is tricky to free later */
530 struct dev_mc_list *mc_list = net->mc_list;
534 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
536 /* Build the multicast hash filter. */
537 for (i = 0; i < net->mc_count; i++) {
540 mc_list->dmi_addr) >> 26;
541 data->multi_filter[crc_bits >> 3] |=
543 mc_list = mc_list->next;
546 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
547 AX_MCAST_FILTER_SIZE, data->multi_filter);
552 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
555 static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
557 struct usbnet *dev = netdev_priv(netdev);
561 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
562 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
563 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
568 static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
570 struct usbnet *dev = netdev_priv(netdev);
574 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
575 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
576 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
579 static int ax88172_link_reset(struct usbnet *dev)
584 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
585 lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
586 if (lpa & LPA_DUPLEX)
587 mode |= AX_MEDIUM_FULL_DUPLEX;
588 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
593 static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
595 struct usbnet *dev = netdev_priv(net);
598 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
599 wolinfo->supported = 0;
600 wolinfo->wolopts = 0;
603 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
604 wolinfo->wolopts = 0;
605 if (opt & AX_MONITOR_MODE) {
606 if (opt & AX_MONITOR_LINK)
607 wolinfo->wolopts |= WAKE_PHY;
608 if (opt & AX_MONITOR_MAGIC)
609 wolinfo->wolopts |= WAKE_MAGIC;
613 static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
615 struct usbnet *dev = netdev_priv(net);
619 if (wolinfo->wolopts & WAKE_PHY)
620 opt |= AX_MONITOR_LINK;
621 if (wolinfo->wolopts & WAKE_MAGIC)
622 opt |= AX_MONITOR_MAGIC;
624 opt |= AX_MONITOR_MODE;
626 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
627 opt, 0, 0, &buf) < 0)
633 static int ax8817x_get_eeprom_len(struct net_device *net)
635 return AX_EEPROM_LEN;
638 static int ax8817x_get_eeprom(struct net_device *net,
639 struct ethtool_eeprom *eeprom, u8 *data)
641 struct usbnet *dev = netdev_priv(net);
642 u16 *ebuf = (u16 *)data;
645 /* Crude hack to ensure that we don't overwrite memory
646 * if an odd length is supplied
651 eeprom->magic = AX_EEPROM_MAGIC;
653 /* ax8817x returns 2 bytes from eeprom on read */
654 for (i=0; i < eeprom->len / 2; i++) {
655 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
656 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
662 static void ax8817x_get_drvinfo (struct net_device *net,
663 struct ethtool_drvinfo *info)
665 /* Inherit standard device info */
666 usbnet_get_drvinfo(net, info);
667 info->eedump_len = 0x3e;
670 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
672 struct usbnet *dev = netdev_priv(net);
674 return mii_ethtool_gset(&dev->mii,cmd);
677 static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
679 struct usbnet *dev = netdev_priv(net);
681 return mii_ethtool_sset(&dev->mii,cmd);
684 /* We need to override some ethtool_ops so we require our
685 own structure so we don't interfere with other usbnet
686 devices that may be connected at the same time. */
687 static struct ethtool_ops ax8817x_ethtool_ops = {
688 .get_drvinfo = ax8817x_get_drvinfo,
689 .get_link = ethtool_op_get_link,
690 .get_msglevel = usbnet_get_msglevel,
691 .set_msglevel = usbnet_set_msglevel,
692 .get_wol = ax8817x_get_wol,
693 .set_wol = ax8817x_set_wol,
694 .get_eeprom_len = ax8817x_get_eeprom_len,
695 .get_eeprom = ax8817x_get_eeprom,
696 .get_settings = ax8817x_get_settings,
697 .set_settings = ax8817x_set_settings,
700 static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
705 unsigned long gpio_bits = dev->driver_info->data;
707 get_endpoints(dev,intf);
709 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
715 /* Toggle the GPIOs in a manufacturer/model specific way */
716 for (i = 2; i >= 0; i--) {
717 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
718 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
724 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
725 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
729 /* Get the MAC address */
730 memset(buf, 0, ETH_ALEN);
731 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
732 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
735 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
738 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
739 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
741 } else if (ret < 2) {
742 /* this should always return 2 bytes */
743 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
748 /* Initialize MII structure */
749 dev->mii.dev = dev->net;
750 dev->mii.mdio_read = ax8817x_mdio_read;
751 dev->mii.mdio_write = ax8817x_mdio_write;
752 dev->mii.phy_id_mask = 0x3f;
753 dev->mii.reg_num_mask = 0x1f;
754 dev->mii.phy_id = *((u8 *)buf + 1);
756 dev->net->set_multicast_list = ax8817x_set_multicast;
757 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
759 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
760 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
761 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
762 mii_nway_restart(&dev->mii);
764 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
765 /* REVISIT: adjust hard_header_len too */
766 dev->hard_mtu = 2048;
776 static struct ethtool_ops ax88772_ethtool_ops = {
777 .get_drvinfo = ax8817x_get_drvinfo,
778 .get_link = ethtool_op_get_link,
779 .get_msglevel = usbnet_get_msglevel,
780 .set_msglevel = usbnet_set_msglevel,
781 .get_wol = ax8817x_get_wol,
782 .set_wol = ax8817x_set_wol,
783 .get_eeprom_len = ax8817x_get_eeprom_len,
784 .get_eeprom = ax8817x_get_eeprom,
785 .get_settings = ax8817x_get_settings,
786 .set_settings = ax8817x_set_settings,
789 static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
794 get_endpoints(dev,intf);
796 buf = kmalloc(6, GFP_KERNEL);
798 dbg ("Cannot allocate memory for buffer");
803 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
804 0x00B0, 0, 0, buf)) < 0)
808 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) {
809 dbg("Select PHY #1 failed: %d", ret);
814 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) {
815 dbg("Failed to power down internal PHY: %d", ret);
821 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) {
822 dbg("Failed to perform software reset: %d", ret);
828 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
829 dbg("Failed to set Internal/External PHY reset control: %d", ret);
835 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0,
837 dbg("Failed to reset RX_CTL: %d", ret);
841 /* Get the MAC address */
842 memset(buf, 0, ETH_ALEN);
843 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) {
844 dbg("Failed to read MAC address: %d", ret);
847 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
849 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) {
850 dbg("Enabling software MII failed: %d", ret);
855 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0)
856 || (*((u16 *)buf) != 0x003b)) {
857 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
861 /* Initialize MII structure */
862 dev->mii.dev = dev->net;
863 dev->mii.mdio_read = ax8817x_mdio_read;
864 dev->mii.mdio_write = ax8817x_mdio_write;
865 dev->mii.phy_id_mask = 0xff;
866 dev->mii.reg_num_mask = 0xff;
869 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
870 dbg("Error reading PHY ID: %02x", ret);
872 } else if (ret < 2) {
873 /* this should always return 2 bytes */
874 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
879 dev->mii.phy_id = *((u8 *)buf + 1);
882 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) {
883 dbg("Set external PHY reset pin level: %d", ret);
888 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
889 dbg("Set Internal/External PHY reset control: %d", ret);
895 dev->net->set_multicast_list = ax8817x_set_multicast;
896 dev->net->ethtool_ops = &ax88772_ethtool_ops;
898 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
899 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
900 ADVERTISE_ALL | ADVERTISE_CSMA);
901 mii_nway_restart(&dev->mii);
903 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
904 dbg("Write medium mode register: %d", ret);
908 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
909 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
913 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
914 dbg("Failed to set hardware MII: %02x", ret);
918 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
920 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
922 dbg("Reset RX_CTL failed: %d", ret);
936 static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
940 struct sk_buff *ax_skb;
943 header = (u32 *) skb->data;
944 le32_to_cpus(header);
945 packet = (char *)(header + 1);
949 while (skb->len > 0) {
950 if ((short)(*header & 0x0000ffff) !=
951 ~((short)((*header & 0xffff0000) >> 16))) {
952 devdbg(dev,"header length data is error");
954 /* get the packet length */
955 size = (u16) (*header & 0x0000ffff);
957 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
959 if (size > ETH_FRAME_LEN) {
960 devdbg(dev,"invalid rx length %d", size);
963 ax_skb = skb_clone(skb, GFP_ATOMIC);
966 ax_skb->data = packet;
967 ax_skb->tail = packet + size;
968 skb_return(dev, ax_skb);
973 skb_pull(skb, (size + 1) & 0xfffe);
978 header = (u32 *) skb->data;
979 le32_to_cpus(header);
980 packet = (char *)(header + 1);
985 devdbg(dev,"invalid rx length %d", skb->len);
991 static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
995 int headroom = skb_headroom(skb);
996 int tailroom = skb_tailroom(skb);
1000 padlen = ((skb->len + 4) % 512) ? 0 : 4;
1002 if ((!skb_cloned(skb))
1003 && ((headroom + tailroom) >= (4 + padlen))) {
1004 if ((headroom < 4) || (tailroom < padlen)) {
1005 skb->data = memmove(skb->head + 4, skb->data, skb->len);
1006 skb->tail = skb->data + skb->len;
1009 struct sk_buff *skb2;
1010 skb2 = skb_copy_expand(skb, 4, padlen, flags);
1011 dev_kfree_skb_any(skb);
1017 packet_len = (u32 *) skb_push(skb, 4);
1019 packet_len = (u32 *) skb->data;
1020 *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
1022 if ((skb->len % 512) == 0) {
1023 padbytes_ptr = (u32 *) skb->tail;
1024 *padbytes_ptr = 0xffff0000;
1025 skb_put(skb, padlen);
1030 static int ax88772_link_reset(struct usbnet *dev)
1035 mode = AX88772_MEDIUM_DEFAULT;
1036 lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
1038 if ((lpa & LPA_DUPLEX) == 0)
1039 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
1040 if ((lpa & LPA_100) == 0)
1041 mode &= ~AX88772_MEDIUM_100MB;
1042 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
1047 static const struct driver_info ax8817x_info = {
1048 .description = "ASIX AX8817x USB 2.0 Ethernet",
1049 .bind = ax8817x_bind,
1050 .status = ax8817x_status,
1051 .link_reset = ax88172_link_reset,
1052 .reset = ax88172_link_reset,
1053 .flags = FLAG_ETHER,
1057 static const struct driver_info dlink_dub_e100_info = {
1058 .description = "DLink DUB-E100 USB Ethernet",
1059 .bind = ax8817x_bind,
1060 .status = ax8817x_status,
1061 .link_reset = ax88172_link_reset,
1062 .reset = ax88172_link_reset,
1063 .flags = FLAG_ETHER,
1067 static const struct driver_info netgear_fa120_info = {
1068 .description = "Netgear FA-120 USB Ethernet",
1069 .bind = ax8817x_bind,
1070 .status = ax8817x_status,
1071 .link_reset = ax88172_link_reset,
1072 .reset = ax88172_link_reset,
1073 .flags = FLAG_ETHER,
1077 static const struct driver_info hawking_uf200_info = {
1078 .description = "Hawking UF200 USB Ethernet",
1079 .bind = ax8817x_bind,
1080 .status = ax8817x_status,
1081 .link_reset = ax88172_link_reset,
1082 .reset = ax88172_link_reset,
1083 .flags = FLAG_ETHER,
1087 static const struct driver_info ax88772_info = {
1088 .description = "ASIX AX88772 USB 2.0 Ethernet",
1089 .bind = ax88772_bind,
1090 .status = ax8817x_status,
1091 .link_reset = ax88772_link_reset,
1092 .reset = ax88772_link_reset,
1093 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1094 .rx_fixup = ax88772_rx_fixup,
1095 .tx_fixup = ax88772_tx_fixup,
1099 #endif /* CONFIG_USB_AX8817X */
1103 /*-------------------------------------------------------------------------
1105 * Communications Device Class declarations.
1106 * Used by CDC Ethernet, and some CDC variants
1108 *-------------------------------------------------------------------------*/
1110 #ifdef CONFIG_USB_CDCETHER
1111 #define NEED_GENERIC_CDC
1114 #ifdef CONFIG_USB_ZAURUS
1115 /* Ethernet variant uses funky framing, broken ethernet addressing */
1116 #define NEED_GENERIC_CDC
1119 #ifdef CONFIG_USB_RNDIS
1120 /* ACM variant uses even funkier framing, complex control RPC scheme */
1121 #define NEED_GENERIC_CDC
1125 #ifdef NEED_GENERIC_CDC
1127 #include <linux/usb_cdc.h>
1130 struct usb_cdc_header_desc *header;
1131 struct usb_cdc_union_desc *u;
1132 struct usb_cdc_ether_desc *ether;
1133 struct usb_interface *control;
1134 struct usb_interface *data;
1137 static struct usb_driver usbnet_driver;
1140 * probes control interface, claims data interface, collects the bulk
1141 * endpoints, activates data interface (if needed), maybe sets MTU.
1142 * all pure cdc, except for certain firmware workarounds.
1144 static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1146 u8 *buf = intf->cur_altsetting->extra;
1147 int len = intf->cur_altsetting->extralen;
1148 struct usb_interface_descriptor *d;
1149 struct cdc_state *info = (void *) &dev->data;
1153 if (sizeof dev->data < sizeof *info)
1156 /* expect strict spec conformance for the descriptors, but
1157 * cope with firmware which stores them in the wrong place
1159 if (len == 0 && dev->udev->actconfig->extralen) {
1160 /* Motorola SB4100 (and others: Brad Hards says it's
1161 * from a Broadcom design) put CDC descriptors here
1163 buf = dev->udev->actconfig->extra;
1164 len = dev->udev->actconfig->extralen;
1166 dev_dbg (&intf->dev,
1167 "CDC descriptors on config\n");
1170 /* this assumes that if there's a non-RNDIS vendor variant
1171 * of cdc-acm, it'll fail RNDIS requests cleanly.
1173 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
1175 memset (info, 0, sizeof *info);
1176 info->control = intf;
1178 if (buf [1] != USB_DT_CS_INTERFACE)
1181 /* use bDescriptorSubType to identify the CDC descriptors.
1182 * We expect devices with CDC header and union descriptors.
1183 * For CDC Ethernet we need the ethernet descriptor.
1184 * For RNDIS, ignore two (pointless) CDC modem descriptors
1185 * in favor of a complicated OID-based RPC scheme doing what
1186 * CDC Ethernet achieves with a simple descriptor.
1189 case USB_CDC_HEADER_TYPE:
1191 dev_dbg (&intf->dev, "extra CDC header\n");
1194 info->header = (void *) buf;
1195 if (info->header->bLength != sizeof *info->header) {
1196 dev_dbg (&intf->dev, "CDC header len %u\n",
1197 info->header->bLength);
1201 case USB_CDC_UNION_TYPE:
1203 dev_dbg (&intf->dev, "extra CDC union\n");
1206 info->u = (void *) buf;
1207 if (info->u->bLength != sizeof *info->u) {
1208 dev_dbg (&intf->dev, "CDC union len %u\n",
1213 /* we need a master/control interface (what we're
1214 * probed with) and a slave/data interface; union
1215 * descriptors sort this all out.
1217 info->control = usb_ifnum_to_if(dev->udev,
1218 info->u->bMasterInterface0);
1219 info->data = usb_ifnum_to_if(dev->udev,
1220 info->u->bSlaveInterface0);
1221 if (!info->control || !info->data) {
1222 dev_dbg (&intf->dev,
1223 "master #%u/%p slave #%u/%p\n",
1224 info->u->bMasterInterface0,
1226 info->u->bSlaveInterface0,
1230 if (info->control != intf) {
1231 dev_dbg (&intf->dev, "bogus CDC Union\n");
1232 /* Ambit USB Cable Modem (and maybe others)
1233 * interchanges master and slave interface.
1235 if (info->data == intf) {
1236 info->data = info->control;
1237 info->control = intf;
1242 /* a data interface altsetting does the real i/o */
1243 d = &info->data->cur_altsetting->desc;
1244 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1245 dev_dbg (&intf->dev, "slave class %u\n",
1246 d->bInterfaceClass);
1250 case USB_CDC_ETHERNET_TYPE:
1252 dev_dbg (&intf->dev, "extra CDC ether\n");
1255 info->ether = (void *) buf;
1256 if (info->ether->bLength != sizeof *info->ether) {
1257 dev_dbg (&intf->dev, "CDC ether len %u\n",
1258 info->ether->bLength);
1261 dev->hard_mtu = le16_to_cpu(
1262 info->ether->wMaxSegmentSize);
1263 /* because of Zaurus, we may be ignoring the host
1264 * side link address we were given.
1269 len -= buf [0]; /* bLength */
1273 if (!info->header || !info->u || (!rndis && !info->ether)) {
1274 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1275 info->header ? "" : "header ",
1276 info->u ? "" : "union ",
1277 info->ether ? "" : "ether ");
1281 /* claim data interface and set it up ... with side effects.
1282 * network traffic can't flow until an altsetting is enabled.
1284 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1287 status = get_endpoints (dev, info->data);
1289 /* ensure immediate exit from usbnet_disconnect */
1290 usb_set_intfdata(info->data, NULL);
1291 usb_driver_release_interface (&usbnet_driver, info->data);
1295 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
1297 if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
1298 struct usb_endpoint_descriptor *desc;
1300 dev->status = &info->control->cur_altsetting->endpoint [0];
1301 desc = &dev->status->desc;
1302 if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
1303 || !(desc->bEndpointAddress & USB_DIR_IN)
1304 || (le16_to_cpu(desc->wMaxPacketSize)
1305 < sizeof (struct usb_cdc_notification))
1306 || !desc->bInterval) {
1307 dev_dbg (&intf->dev, "bad notification endpoint\n");
1311 if (rndis && !dev->status) {
1312 dev_dbg (&intf->dev, "missing RNDIS status endpoint\n");
1313 usb_set_intfdata(info->data, NULL);
1314 usb_driver_release_interface (&usbnet_driver, info->data);
1320 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1324 static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1326 struct cdc_state *info = (void *) &dev->data;
1328 /* disconnect master --> disconnect slave */
1329 if (intf == info->control && info->data) {
1330 /* ensure immediate exit from usbnet_disconnect */
1331 usb_set_intfdata(info->data, NULL);
1332 usb_driver_release_interface (&usbnet_driver, info->data);
1336 /* and vice versa (just in case) */
1337 else if (intf == info->data && info->control) {
1338 /* ensure immediate exit from usbnet_disconnect */
1339 usb_set_intfdata(info->control, NULL);
1340 usb_driver_release_interface (&usbnet_driver, info->control);
1341 info->control = NULL;
1345 #endif /* NEED_GENERIC_CDC */
1348 #ifdef CONFIG_USB_CDCETHER
1349 #define HAVE_HARDWARE
1351 /*-------------------------------------------------------------------------
1353 * Communications Device Class, Ethernet Control model
1355 * Takes two interfaces. The DATA interface is inactive till an altsetting
1356 * is selected. Configuration data includes class descriptors.
1358 * This should interop with whatever the 2.4 "CDCEther.c" driver
1359 * (by Brad Hards) talked with.
1361 *-------------------------------------------------------------------------*/
1363 #include <linux/ctype.h>
1366 static void dumpspeed (struct usbnet *dev, __le32 *speeds)
1368 if (netif_msg_timer (dev))
1369 devinfo (dev, "link speeds: %u kbps up, %u kbps down",
1370 __le32_to_cpu(speeds[0]) / 1000,
1371 __le32_to_cpu(speeds[1]) / 1000);
1374 static void cdc_status (struct usbnet *dev, struct urb *urb)
1376 struct usb_cdc_notification *event;
1378 if (urb->actual_length < sizeof *event)
1381 /* SPEED_CHANGE can get split into two 8-byte packets */
1382 if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) {
1383 dumpspeed (dev, (__le32 *) urb->transfer_buffer);
1387 event = urb->transfer_buffer;
1388 switch (event->bNotificationType) {
1389 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
1390 if (netif_msg_timer (dev))
1391 devdbg (dev, "CDC: carrier %s",
1392 event->wValue ? "on" : "off");
1394 netif_carrier_on(dev->net);
1396 netif_carrier_off(dev->net);
1398 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
1399 if (netif_msg_timer (dev))
1400 devdbg (dev, "CDC: speed change (len %d)",
1401 urb->actual_length);
1402 if (urb->actual_length != (sizeof *event + 8))
1403 set_bit (EVENT_STS_SPLIT, &dev->flags);
1405 dumpspeed (dev, (__le32 *) &event[1]);
1407 // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
1409 deverr (dev, "CDC: unexpected notification %02x!",
1410 event->bNotificationType);
1415 static u8 nibble (unsigned char c)
1417 if (likely (isdigit (c)))
1420 if (likely (isxdigit (c)))
1421 return 10 + c - 'A';
1426 get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e)
1429 unsigned char buf [13];
1431 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1433 dev_dbg (&dev->udev->dev,
1434 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1439 for (i = tmp = 0; i < 6; i++, tmp += 2)
1440 dev->net->dev_addr [i] =
1441 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1445 static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1448 struct cdc_state *info = (void *) &dev->data;
1450 status = generic_cdc_bind (dev, intf);
1454 status = get_ethernet_addr (dev, info->ether);
1456 usb_set_intfdata(info->data, NULL);
1457 usb_driver_release_interface (&usbnet_driver, info->data);
1461 /* FIXME cdc-ether has some multicast code too, though it complains
1462 * in routine cases. info->ether describes the multicast support.
1467 static const struct driver_info cdc_info = {
1468 .description = "CDC Ethernet Device",
1469 .flags = FLAG_ETHER,
1470 // .check_connect = cdc_check_connect,
1472 .unbind = cdc_unbind,
1473 .status = cdc_status,
1476 #endif /* CONFIG_USB_CDCETHER */
1480 #ifdef CONFIG_USB_GENESYS
1481 #define HAVE_HARDWARE
1483 /*-------------------------------------------------------------------------
1485 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1487 * ... should partially interop with the Win32 driver for this hardware
1488 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1490 * Some info from GeneSys:
1491 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1492 * (Some cables, like the BAFO-100c, use the half duplex version.)
1493 * - For the full duplex model, the low bit of the version code says
1494 * which side is which ("left/right").
1495 * - For the half duplex type, a control/interrupt handshake settles
1496 * the transfer direction. (That's disabled here, partially coded.)
1497 * A control URB would block until other side writes an interrupt.
1499 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1500 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1502 *-------------------------------------------------------------------------*/
1504 // control msg write command
1505 #define GENELINK_CONNECT_WRITE 0xF0
1506 // interrupt pipe index
1507 #define GENELINK_INTERRUPT_PIPE 0x03
1508 // interrupt read buffer size
1509 #define INTERRUPT_BUFSIZE 0x08
1510 // interrupt pipe interval value
1511 #define GENELINK_INTERRUPT_INTERVAL 0x10
1512 // max transmit packet number per transmit
1513 #define GL_MAX_TRANSMIT_PACKETS 32
1514 // max packet length
1515 #define GL_MAX_PACKET_LEN 1514
1516 // max receive buffer size
1517 #define GL_RCV_BUF_SIZE \
1518 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1522 char packet_data [1];
1527 struct gl_packet packets;
1532 // FIXME: this code is incomplete, not debugged; it doesn't
1533 // handle interrupts correctly. interrupts should be generic
1534 // code like all other device I/O, anyway.
1537 struct urb *irq_urb;
1538 char irq_buf [INTERRUPT_BUFSIZE];
1541 static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1545 retval = usb_control_msg (dev->udev,
1546 usb_sndctrlpipe (dev->udev, 0),
1548 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1553 CONTROL_TIMEOUT_MS);
1557 static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1559 int status = urb->status;
1568 /* this urb is terminated, clean up */
1569 dbg("%s - urb shutting down with status: %d",
1570 __FUNCTION__, status);
1573 dbg("%s - nonzero urb status received: %d",
1574 __FUNCTION__, urb->status);
1577 status = usb_submit_urb (urb, GFP_ATOMIC);
1579 err ("%s - usb_submit_urb failed with result %d",
1580 __FUNCTION__, status);
1583 static int gl_interrupt_read (struct usbnet *dev)
1585 struct gl_priv *priv = dev->priv_data;
1588 // issue usb interrupt read
1589 if (priv && priv->irq_urb) {
1591 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1592 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1594 dbg ("gl_interrupt_read: submit success...");
1600 // check whether another side is connected
1601 static int genelink_check_connect (struct usbnet *dev)
1605 dbg ("genelink_check_connect...");
1607 // detect whether another side is connected
1608 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1609 dbg ("%s: genelink_check_connect write fail - %X",
1610 dev->net->name, retval);
1614 // usb interrupt read to ack another side
1615 if ((retval = gl_interrupt_read (dev)) != 0) {
1616 dbg ("%s: genelink_check_connect read fail - %X",
1617 dev->net->name, retval);
1621 dbg ("%s: genelink_check_connect read success", dev->net->name);
1625 // allocate and initialize the private data for genelink
1626 static int genelink_init (struct usbnet *dev)
1628 struct gl_priv *priv;
1630 // allocate the private data structure
1631 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1632 dbg ("%s: cannot allocate private data per device",
1638 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1639 dbg ("%s: cannot allocate private irq urb per device",
1646 usb_fill_int_urb (priv->irq_urb, dev->udev,
1647 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1648 priv->irq_buf, INTERRUPT_BUFSIZE,
1649 gl_interrupt_complete, 0,
1650 GENELINK_INTERRUPT_INTERVAL);
1652 // set private data pointer
1653 dev->priv_data = priv;
1658 // release the private data
1659 static int genelink_free (struct usbnet *dev)
1661 struct gl_priv *priv = dev->priv_data;
1666 // FIXME: can't cancel here; it's synchronous, and
1667 // should have happened earlier in any case (interrupt
1668 // handling needs to be generic)
1670 // cancel irq urb first
1671 usb_kill_urb (priv->irq_urb);
1674 usb_free_urb (priv->irq_urb);
1676 // free the private data structure
1684 static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1686 struct gl_header *header;
1687 struct gl_packet *packet;
1688 struct sk_buff *gl_skb;
1691 header = (struct gl_header *) skb->data;
1693 // get the packet count of the received skb
1694 le32_to_cpus (&header->packet_count);
1695 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1696 || (header->packet_count < 0)) {
1697 dbg ("genelink: invalid received packet count %d",
1698 header->packet_count);
1702 // set the current packet pointer to the first packet
1703 packet = &header->packets;
1705 // decrement the length for the packet count size 4 bytes
1708 while (header->packet_count > 1) {
1709 // get the packet length
1710 size = packet->packet_length;
1712 // this may be a broken packet
1713 if (size > GL_MAX_PACKET_LEN) {
1714 dbg ("genelink: invalid rx length %d", size);
1718 // allocate the skb for the individual packet
1719 gl_skb = alloc_skb (size, GFP_ATOMIC);
1722 // copy the packet data to the new skb
1723 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1724 skb_return (dev, gl_skb);
1727 // advance to the next packet
1728 packet = (struct gl_packet *)
1729 &packet->packet_data [size];
1730 header->packet_count--;
1732 // shift the data pointer to the next gl_packet
1733 skb_pull (skb, size + 4);
1736 // skip the packet length field 4 bytes
1739 if (skb->len > GL_MAX_PACKET_LEN) {
1740 dbg ("genelink: invalid rx length %d", skb->len);
1746 static struct sk_buff *
1747 genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
1750 int length = skb->len;
1751 int headroom = skb_headroom (skb);
1752 int tailroom = skb_tailroom (skb);
1756 // FIXME: magic numbers, bleech
1757 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1759 if ((!skb_cloned (skb))
1760 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1761 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1762 skb->data = memmove (skb->head + (4 + 4*1),
1763 skb->data, skb->len);
1764 skb->tail = skb->data + skb->len;
1767 struct sk_buff *skb2;
1768 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1769 dev_kfree_skb_any (skb);
1775 // attach the packet count to the header
1776 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1777 packet_len = packet_count + 1;
1779 // FIXME little endian?
1781 *packet_len = length;
1784 if ((skb->len % dev->maxpacket) == 0)
1790 static int genelink_bind (struct usbnet *dev, struct usb_interface *intf)
1792 dev->hard_mtu = GL_RCV_BUF_SIZE;
1793 dev->net->hard_header_len += 4;
1797 static const struct driver_info genelink_info = {
1798 .description = "Genesys GeneLink",
1799 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1800 .bind = genelink_bind,
1801 .rx_fixup = genelink_rx_fixup,
1802 .tx_fixup = genelink_tx_fixup,
1807 .check_connect =genelink_check_connect,
1811 #endif /* CONFIG_USB_GENESYS */
1815 #ifdef CONFIG_USB_NET1080
1816 #define HAVE_HARDWARE
1818 /*-------------------------------------------------------------------------
1820 * Netchip 1080 driver ... http://www.netchip.com
1821 * Used in LapLink cables
1823 *-------------------------------------------------------------------------*/
1825 #define frame_errors data[1]
1828 * NetChip framing of ethernet packets, supporting additional error
1829 * checks for links that may drop bulk packets from inside messages.
1830 * Odd USB length == always short read for last usb packet.
1832 * - Ethernet header (14 bytes)
1834 * - (optional padding byte, if needed so length becomes odd)
1837 * This framing is to be avoided for non-NetChip devices.
1840 struct nc_header { // packed:
1841 __le16 hdr_len; // sizeof nc_header (LE, all)
1842 __le16 packet_len; // payload size (including ethhdr)
1843 __le16 packet_id; // detects dropped packets
1844 #define MIN_HEADER 6
1846 // all else is optional, and must start with:
1847 // u16 vendorId; // from usb-if
1849 } __attribute__((__packed__));
1851 #define PAD_BYTE ((unsigned char)0xAC)
1855 } __attribute__((__packed__));
1857 // packets may use FLAG_FRAMING_NC and optional pad
1858 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
1859 + sizeof (struct ethhdr) \
1862 + sizeof (struct nc_trailer))
1864 #define MIN_FRAMED FRAMED_SIZE(0)
1866 /* packets _could_ be up to 64KB... */
1867 #define NC_MAX_PACKET 32767
1871 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
1872 * before the hardware drops it. If that's done, the driver will need to
1873 * frame network packets to guard against the dropped USB packets. The win32
1874 * driver sets this for both sides of the link.
1876 #define NC_READ_TTL_MS ((u8)255) // ms
1879 * We ignore most registers and EEPROM contents.
1881 #define REG_USBCTL ((u8)0x04)
1882 #define REG_TTL ((u8)0x10)
1883 #define REG_STATUS ((u8)0x11)
1886 * Vendor specific requests to read/write data
1888 #define REQUEST_REGISTER ((u8)0x10)
1889 #define REQUEST_EEPROM ((u8)0x11)
1892 nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
1894 int status = usb_control_msg (dev->udev,
1895 usb_rcvctrlpipe (dev->udev, 0),
1897 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1899 retval_ptr, sizeof *retval_ptr,
1900 CONTROL_TIMEOUT_MS);
1904 le16_to_cpus (retval_ptr);
1909 nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
1911 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
1914 // no retval ... can become async, usable in_interrupt()
1916 nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
1918 usb_control_msg (dev->udev,
1919 usb_sndctrlpipe (dev->udev, 0),
1921 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1923 NULL, 0, // data is in setup packet
1924 CONTROL_TIMEOUT_MS);
1928 nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
1930 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
1935 static void nc_dump_registers (struct usbnet *dev)
1938 u16 *vp = kmalloc (sizeof (u16));
1945 dbg ("%s registers:", dev->net->name);
1946 for (reg = 0; reg < 0x20; reg++) {
1949 // reading some registers is trouble
1950 if (reg >= 0x08 && reg <= 0xf)
1952 if (reg >= 0x12 && reg <= 0x1e)
1955 retval = nc_register_read (dev, reg, vp);
1957 dbg ("%s reg [0x%x] ==> error %d",
1958 dev->net->name, reg, retval);
1960 dbg ("%s reg [0x%x] = 0x%x",
1961 dev->net->name, reg, *vp);
1968 /*-------------------------------------------------------------------------*/
1974 #define USBCTL_WRITABLE_MASK 0x1f0f
1975 // bits 15-13 reserved, r/o
1976 #define USBCTL_ENABLE_LANG (1 << 12)
1977 #define USBCTL_ENABLE_MFGR (1 << 11)
1978 #define USBCTL_ENABLE_PROD (1 << 10)
1979 #define USBCTL_ENABLE_SERIAL (1 << 9)
1980 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
1981 // bits 7-4 reserved, r/o
1982 #define USBCTL_FLUSH_OTHER (1 << 3)
1983 #define USBCTL_FLUSH_THIS (1 << 2)
1984 #define USBCTL_DISCONN_OTHER (1 << 1)
1985 #define USBCTL_DISCONN_THIS (1 << 0)
1987 static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
1989 if (!netif_msg_link (dev))
1991 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
1993 " other%s%s; r/o 0x%x",
1994 dev->udev->bus->bus_name, dev->udev->devpath,
1996 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
1997 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
1998 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
1999 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
2000 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
2002 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
2003 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
2004 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
2005 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
2006 usbctl & ~USBCTL_WRITABLE_MASK
2010 /*-------------------------------------------------------------------------*/
2016 #define STATUS_PORT_A (1 << 15)
2018 #define STATUS_CONN_OTHER (1 << 14)
2019 #define STATUS_SUSPEND_OTHER (1 << 13)
2020 #define STATUS_MAILBOX_OTHER (1 << 12)
2021 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
2023 #define STATUS_CONN_THIS (1 << 6)
2024 #define STATUS_SUSPEND_THIS (1 << 5)
2025 #define STATUS_MAILBOX_THIS (1 << 4)
2026 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
2028 #define STATUS_UNSPEC_MASK 0x0c8c
2029 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
2032 static inline void nc_dump_status (struct usbnet *dev, u16 status)
2034 if (!netif_msg_link (dev))
2036 devdbg (dev, "net1080 %s-%s status 0x%x:"
2037 " this (%c) PKT=%d%s%s%s;"
2038 " other PKT=%d%s%s%s; unspec 0x%x",
2039 dev->udev->bus->bus_name, dev->udev->devpath,
2042 // XXX the packet counts don't seem right
2043 // (1 at reset, not 0); maybe UNSPEC too
2045 (status & STATUS_PORT_A) ? 'A' : 'B',
2046 STATUS_PACKETS_THIS (status),
2047 (status & STATUS_CONN_THIS) ? " CON" : "",
2048 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
2049 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
2051 STATUS_PACKETS_OTHER (status),
2052 (status & STATUS_CONN_OTHER) ? " CON" : "",
2053 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
2054 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
2056 status & STATUS_UNSPEC_MASK
2060 /*-------------------------------------------------------------------------*/
2066 #define TTL_THIS(ttl) (0x00ff & ttl)
2067 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
2068 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
2070 static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
2072 if (netif_msg_link (dev))
2073 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
2074 dev->udev->bus->bus_name, dev->udev->devpath,
2075 ttl, TTL_THIS (ttl), TTL_OTHER (ttl));
2078 /*-------------------------------------------------------------------------*/
2080 static int net1080_reset (struct usbnet *dev)
2082 u16 usbctl, status, ttl;
2083 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2089 // nc_dump_registers (dev);
2091 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
2092 dbg ("can't read %s-%s status: %d",
2093 dev->udev->bus->bus_name, dev->udev->devpath, retval);
2097 nc_dump_status (dev, status);
2099 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
2100 dbg ("can't read USBCTL, %d", retval);
2104 nc_dump_usbctl (dev, usbctl);
2106 nc_register_write (dev, REG_USBCTL,
2107 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
2109 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
2110 dbg ("can't read TTL, %d", retval);
2114 // nc_dump_ttl (dev, ttl);
2116 nc_register_write (dev, REG_TTL,
2117 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
2118 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
2120 if (netif_msg_link (dev))
2121 devinfo (dev, "port %c, peer %sconnected",
2122 (status & STATUS_PORT_A) ? 'A' : 'B',
2123 (status & STATUS_CONN_OTHER) ? "" : "dis"
2132 static int net1080_check_connect (struct usbnet *dev)
2136 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2140 retval = nc_register_read (dev, REG_STATUS, vp);
2144 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
2147 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
2152 static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
2154 kfree (urb->context);
2158 static void nc_ensure_sync (struct usbnet *dev)
2160 dev->frame_errors++;
2161 if (dev->frame_errors > 5) {
2163 struct usb_ctrlrequest *req;
2167 urb = usb_alloc_urb (0, SLAB_ATOMIC);
2171 req = kmalloc (sizeof *req, GFP_ATOMIC);
2177 req->bRequestType = USB_DIR_OUT
2180 req->bRequest = REQUEST_REGISTER;
2181 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
2182 | USBCTL_FLUSH_OTHER);
2183 req->wIndex = cpu_to_le16 (REG_USBCTL);
2184 req->wLength = cpu_to_le16 (0);
2186 /* queue an async control request, we don't need
2187 * to do anything when it finishes except clean up.
2189 usb_fill_control_urb (urb, dev->udev,
2190 usb_sndctrlpipe (dev->udev, 0),
2191 (unsigned char *) req,
2193 nc_flush_complete, req);
2194 status = usb_submit_urb (urb, GFP_ATOMIC);
2201 if (netif_msg_rx_err (dev))
2202 devdbg (dev, "flush net1080; too many framing errors");
2203 dev->frame_errors = 0;
2207 static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
2209 struct nc_header *header;
2210 struct net_device *net = dev->net;
2211 struct nc_trailer *trailer;
2212 u16 hdr_len, packet_len;
2214 if (!(skb->len & 0x01)) {
2215 dev->stats.rx_frame_errors++;
2216 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
2217 net->hard_header_len, dev->hard_mtu, net->mtu);
2218 nc_ensure_sync (dev);
2222 header = (struct nc_header *) skb->data;
2223 hdr_len = le16_to_cpup (&header->hdr_len);
2224 packet_len = le16_to_cpup (&header->packet_len);
2225 if (FRAMED_SIZE (packet_len) > NC_MAX_PACKET) {
2226 dev->stats.rx_frame_errors++;
2227 dbg ("packet too big, %d", packet_len);
2228 nc_ensure_sync (dev);
2230 } else if (hdr_len < MIN_HEADER) {
2231 dev->stats.rx_frame_errors++;
2232 dbg ("header too short, %d", hdr_len);
2233 nc_ensure_sync (dev);
2235 } else if (hdr_len > MIN_HEADER) {
2236 // out of band data for us?
2237 dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER);
2238 nc_ensure_sync (dev);
2239 // switch (vendor/product ids) { ... }
2241 skb_pull (skb, hdr_len);
2243 trailer = (struct nc_trailer *)
2244 (skb->data + skb->len - sizeof *trailer);
2245 skb_trim (skb, skb->len - sizeof *trailer);
2247 if ((packet_len & 0x01) == 0) {
2248 if (skb->data [packet_len] != PAD_BYTE) {
2249 dev->stats.rx_frame_errors++;
2253 skb_trim (skb, skb->len - 1);
2255 if (skb->len != packet_len) {
2256 dev->stats.rx_frame_errors++;
2257 dbg ("bad packet len %d (expected %d)",
2258 skb->len, packet_len);
2259 nc_ensure_sync (dev);
2262 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2263 dev->stats.rx_fifo_errors++;
2264 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2265 le16_to_cpu (header->packet_id),
2266 le16_to_cpu (trailer->packet_id));
2270 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2271 header->packet_len, header->packet_id);
2273 dev->frame_errors = 0;
2277 static struct sk_buff *
2278 net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
2281 struct sk_buff *skb2;
2283 padlen = ((skb->len + sizeof (struct nc_header)
2284 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2285 if (!skb_cloned (skb)) {
2286 int headroom = skb_headroom (skb);
2287 int tailroom = skb_tailroom (skb);
2289 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2290 && sizeof (struct nc_header) <= headroom)
2291 /* There's enough head and tail room */
2294 if ((sizeof (struct nc_header) + padlen
2295 + sizeof (struct nc_trailer)) <
2296 (headroom + tailroom)) {
2297 /* There's enough total room, so just readjust */
2298 skb->data = memmove (skb->head
2299 + sizeof (struct nc_header),
2300 skb->data, skb->len);
2301 skb->tail = skb->data + skb->len;
2306 /* Create a new skb to use with the correct size */
2307 skb2 = skb_copy_expand (skb,
2308 sizeof (struct nc_header),
2309 sizeof (struct nc_trailer) + padlen,
2311 dev_kfree_skb_any (skb);
2315 static int net1080_bind (struct usbnet *dev, struct usb_interface *intf)
2317 unsigned extra = sizeof (struct nc_header)
2319 + sizeof (struct nc_trailer);
2321 dev->net->hard_header_len += extra;
2322 dev->hard_mtu = NC_MAX_PACKET;
2326 static const struct driver_info net1080_info = {
2327 .description = "NetChip TurboCONNECT",
2328 .flags = FLAG_FRAMING_NC,
2329 .bind = net1080_bind,
2330 .reset = net1080_reset,
2331 .check_connect = net1080_check_connect,
2332 .rx_fixup = net1080_rx_fixup,
2333 .tx_fixup = net1080_tx_fixup,
2336 #endif /* CONFIG_USB_NET1080 */
2340 #ifdef CONFIG_USB_PL2301
2341 #define HAVE_HARDWARE
2343 /*-------------------------------------------------------------------------
2345 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2347 * The protocol and handshaking used here should be bug-compatible
2348 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2350 *-------------------------------------------------------------------------*/
2353 * Bits 0-4 can be used for software handshaking; they're set from
2354 * one end, cleared from the other, "read" with the interrupt byte.
2356 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2357 /* reserved bit -- rx ready (6) ? */
2358 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2359 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2360 #define PL_RESET_IN (1<<3) /* reset input pipe */
2361 #define PL_TX_C (1<<2) /* transmission complete */
2362 #define PL_TX_REQ (1<<1) /* transmission received */
2363 #define PL_PEER_E (1<<0) /* peer exists */
2366 pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2368 return usb_control_msg (dev->udev,
2369 usb_rcvctrlpipe (dev->udev, 0),
2371 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2374 CONTROL_TIMEOUT_MS);
2378 pl_clear_QuickLink_features (struct usbnet *dev, int val)
2380 return pl_vendor_req (dev, 1, (u8) val, 0);
2384 pl_set_QuickLink_features (struct usbnet *dev, int val)
2386 return pl_vendor_req (dev, 3, (u8) val, 0);
2389 /*-------------------------------------------------------------------------*/
2391 static int pl_reset (struct usbnet *dev)
2393 /* some units seem to need this reset, others reject it utterly.
2394 * FIXME be more like "naplink" or windows drivers.
2396 (void) pl_set_QuickLink_features (dev,
2397 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2401 static const struct driver_info prolific_info = {
2402 .description = "Prolific PL-2301/PL-2302",
2403 .flags = FLAG_NO_SETINT,
2404 /* some PL-2302 versions seem to fail usb_set_interface() */
2408 #endif /* CONFIG_USB_PL2301 */
2411 #ifdef CONFIG_USB_ZAURUS
2412 #define HAVE_HARDWARE
2414 #include <linux/crc32.h>
2416 /*-------------------------------------------------------------------------
2418 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2419 * (and framing) for its USB slave/gadget controller than the case above.
2421 * For the current version of that driver, the main way that framing is
2422 * nonstandard (also from perspective of the CDC ethernet model!) is a
2423 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2424 * haven't been fully worked around. Also, all Zaurii use the same
2425 * default Ethernet address.
2427 * PXA based models use the same framing, and also can't implement
2428 * set_interface properly.
2430 * All known Zaurii lie about their standards conformance. Most lie by
2431 * saying they support CDC Ethernet. Some lie and say they support CDC
2432 * MDLM (as if for access to cell phone modems). Someone, please beat
2433 * on Sharp (and other such vendors) for a while with a cluestick.
2435 *-------------------------------------------------------------------------*/
2437 static struct sk_buff *
2438 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
2441 struct sk_buff *skb2;
2444 if (!skb_cloned (skb)) {
2445 int tailroom = skb_tailroom (skb);
2446 if ((padlen + 4) <= tailroom)
2449 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2450 dev_kfree_skb_any (skb);
2455 fcs = crc32_le (~0, skb->data, skb->len);
2458 *skb_put (skb, 1) = fcs & 0xff;
2459 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2460 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2461 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2466 static int zaurus_bind (struct usbnet *dev, struct usb_interface *intf)
2468 /* Belcarra's funky framing has other options; mostly
2469 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
2471 dev->net->hard_header_len += 6;
2472 return generic_cdc_bind(dev, intf);
2475 static const struct driver_info zaurus_sl5x00_info = {
2476 .description = "Sharp Zaurus SL-5x00",
2477 .flags = FLAG_FRAMING_Z,
2478 .check_connect = always_connected,
2479 .bind = zaurus_bind,
2480 .unbind = cdc_unbind,
2481 .tx_fixup = zaurus_tx_fixup,
2483 #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2485 static const struct driver_info zaurus_pxa_info = {
2486 .description = "Sharp Zaurus, PXA-2xx based",
2487 .flags = FLAG_FRAMING_Z,
2488 .check_connect = always_connected,
2489 .bind = zaurus_bind,
2490 .unbind = cdc_unbind,
2491 .tx_fixup = zaurus_tx_fixup,
2493 #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2495 static const struct driver_info olympus_mxl_info = {
2496 .description = "Olympus R1000",
2497 .flags = FLAG_FRAMING_Z,
2498 .check_connect = always_connected,
2499 .bind = zaurus_bind,
2500 .unbind = cdc_unbind,
2501 .tx_fixup = zaurus_tx_fixup,
2503 #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2506 /* Some more recent products using Lineo/Belcarra code will wrongly claim
2507 * CDC MDLM conformance. They aren't conformant: data endpoints live
2508 * in the control interface, there's no data interface, and it's not used
2509 * to talk to a cell phone radio. But at least we can detect these two
2510 * pseudo-classes, rather than growing this product list with entries for
2511 * each new nonconformant product (sigh).
2513 static const u8 safe_guid[16] = {
2514 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
2515 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
2517 static const u8 blan_guid[16] = {
2518 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
2519 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
2522 static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
2524 u8 *buf = intf->cur_altsetting->extra;
2525 int len = intf->cur_altsetting->extralen;
2526 struct usb_cdc_mdlm_desc *desc = NULL;
2527 struct usb_cdc_mdlm_detail_desc *detail = NULL;
2530 if (buf [1] != USB_DT_CS_INTERFACE)
2533 /* use bDescriptorSubType, and just verify that we get a
2534 * "BLAN" (or "SAFE") descriptor.
2537 case USB_CDC_MDLM_TYPE:
2539 dev_dbg (&intf->dev, "extra MDLM\n");
2542 desc = (void *) buf;
2543 if (desc->bLength != sizeof *desc) {
2544 dev_dbg (&intf->dev, "MDLM len %u\n",
2548 /* expect bcdVersion 1.0, ignore */
2549 if (memcmp(&desc->bGUID, blan_guid, 16)
2550 && memcmp(&desc->bGUID, safe_guid, 16) ) {
2551 /* hey, this one might _really_ be MDLM! */
2552 dev_dbg (&intf->dev, "MDLM guid\n");
2556 case USB_CDC_MDLM_DETAIL_TYPE:
2558 dev_dbg (&intf->dev, "extra MDLM detail\n");
2561 detail = (void *) buf;
2562 switch (detail->bGuidDescriptorType) {
2563 case 0: /* "SAFE" */
2564 if (detail->bLength != (sizeof *detail + 2))
2567 case 1: /* "BLAN" */
2568 if (detail->bLength != (sizeof *detail + 3))
2575 /* assuming we either noticed BLAN already, or will
2576 * find it soon, there are some data bytes here:
2577 * - bmNetworkCapabilities (unused)
2578 * - bmDataCapabilities (bits, see below)
2579 * - bPad (ignored, for PADAFTER -- BLAN-only)
2581 * - 0x01 -- Zaurus framing (add CRC)
2582 * - 0x02 -- PADBEFORE (CRC includes some padding)
2583 * - 0x04 -- PADAFTER (some padding after CRC)
2584 * - 0x08 -- "fermat" packet mangling (for hw bugs)
2585 * the PADBEFORE appears not to matter; we interop
2586 * with devices that use it and those that don't.
2588 if ((detail->bDetailData[1] & ~02) != 0x01) {
2589 /* bmDataCapabilites == 0 would be fine too,
2590 * but framing is minidriver-coupled for now.
2593 dev_dbg (&intf->dev,
2594 "bad MDLM detail, %d %d %d\n",
2596 detail->bDetailData[0],
2597 detail->bDetailData[2]);
2603 len -= buf [0]; /* bLength */
2607 if (!desc || !detail) {
2608 dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
2609 desc ? "" : "func ",
2610 detail ? "" : "detail ");
2614 /* There's probably a CDC Ethernet descriptor there, but we can't
2615 * rely on the Ethernet address it provides since not all vendors
2616 * bother to make it unique. Likewise there's no point in tracking
2617 * of the CDC event notifications.
2619 return get_endpoints (dev, intf);
2622 dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
2626 static const struct driver_info bogus_mdlm_info = {
2627 .description = "pseudo-MDLM (BLAN) device",
2628 .flags = FLAG_FRAMING_Z,
2629 .check_connect = always_connected,
2630 .tx_fixup = zaurus_tx_fixup,
2631 .bind = blan_mdlm_bind,
2636 /* blacklist all those devices */
2637 #define ZAURUS_STRONGARM_INFO 0
2638 #define ZAURUS_PXA_INFO 0
2639 #define OLYMPUS_MXL_INFO 0
2644 /*-------------------------------------------------------------------------
2646 * Network Device Driver (peer link to "Host Device", from USB host)
2648 *-------------------------------------------------------------------------*/
2650 static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2652 struct usbnet *dev = netdev_priv(net);
2653 int ll_mtu = new_mtu + net->hard_header_len;
2655 if (new_mtu <= 0 || ll_mtu > dev->hard_mtu)
2657 // no second zero-length packet read wanted after mtu-sized packets
2658 if ((ll_mtu % dev->maxpacket) == 0)
2664 /*-------------------------------------------------------------------------*/
2666 static struct net_device_stats *usbnet_get_stats (struct net_device *net)
2668 struct usbnet *dev = netdev_priv(net);
2672 /*-------------------------------------------------------------------------*/
2674 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2675 * completion callbacks. 2.5 should have fixed those bugs...
2678 static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)
2680 unsigned long flags;
2682 spin_lock_irqsave(&list->lock, flags);
2683 __skb_unlink(skb, list);
2684 spin_unlock(&list->lock);
2685 spin_lock(&dev->done.lock);
2686 __skb_queue_tail(&dev->done, skb);
2687 if (dev->done.qlen == 1)
2688 tasklet_schedule(&dev->bh);
2689 spin_unlock_irqrestore(&dev->done.lock, flags);
2692 /* some work can't be done in tasklets, so we use keventd
2694 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2695 * but tasklet_schedule() doesn't. hope the failure is rare.
2697 static void defer_kevent (struct usbnet *dev, int work)
2699 set_bit (work, &dev->flags);
2700 if (!schedule_work (&dev->kevent))
2701 deverr (dev, "kevent %d may have been dropped", work);
2703 devdbg (dev, "kevent %d scheduled", work);
2706 /*-------------------------------------------------------------------------*/
2708 static void rx_complete (struct urb *urb, struct pt_regs *regs);
2710 static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags)
2712 struct sk_buff *skb;
2713 struct skb_data *entry;
2715 unsigned long lockflags;
2718 size = max(dev->net->hard_header_len + dev->net->mtu,
2719 (unsigned)ETH_FRAME_LEN);
2720 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
2721 if (netif_msg_rx_err (dev))
2722 devdbg (dev, "no rx skb");
2723 defer_kevent (dev, EVENT_RX_MEMORY);
2727 skb_reserve (skb, NET_IP_ALIGN);
2729 entry = (struct skb_data *) skb->cb;
2732 entry->state = rx_start;
2735 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2736 skb->data, size, rx_complete, skb);
2738 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2740 if (netif_running (dev->net)
2741 && netif_device_present (dev->net)
2742 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2743 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2745 defer_kevent (dev, EVENT_RX_HALT);
2748 defer_kevent (dev, EVENT_RX_MEMORY);
2751 if (netif_msg_ifdown (dev))
2752 devdbg (dev, "device gone");
2753 netif_device_detach (dev->net);
2756 if (netif_msg_rx_err (dev))
2757 devdbg (dev, "rx submit, %d", retval);
2758 tasklet_schedule (&dev->bh);
2761 __skb_queue_tail (&dev->rxq, skb);
2764 if (netif_msg_ifdown (dev))
2765 devdbg (dev, "rx: stopped");
2768 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
2770 dev_kfree_skb_any (skb);
2776 /*-------------------------------------------------------------------------*/
2778 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
2780 if (dev->driver_info->rx_fixup
2781 && !dev->driver_info->rx_fixup (dev, skb))
2783 // else network stack removes extra byte if we forced a short packet
2786 skb_return (dev, skb);
2788 if (netif_msg_rx_err (dev))
2789 devdbg (dev, "drop");
2791 dev->stats.rx_errors++;
2792 skb_queue_tail (&dev->done, skb);
2796 /*-------------------------------------------------------------------------*/
2798 static void rx_complete (struct urb *urb, struct pt_regs *regs)
2800 struct sk_buff *skb = (struct sk_buff *) urb->context;
2801 struct skb_data *entry = (struct skb_data *) skb->cb;
2802 struct usbnet *dev = entry->dev;
2803 int urb_status = urb->status;
2805 skb_put (skb, urb->actual_length);
2806 entry->state = rx_done;
2809 switch (urb_status) {
2812 if (skb->len < dev->net->hard_header_len) {
2813 entry->state = rx_cleanup;
2814 dev->stats.rx_errors++;
2815 dev->stats.rx_length_errors++;
2816 if (netif_msg_rx_err (dev))
2817 devdbg (dev, "rx length %d", skb->len);
2821 // stalls need manual reset. this is rare ... except that
2822 // when going through USB 2.0 TTs, unplug appears this way.
2823 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2824 // storm, recovering as needed.
2826 dev->stats.rx_errors++;
2827 defer_kevent (dev, EVENT_RX_HALT);
2830 // software-driven interface shutdown
2831 case -ECONNRESET: // async unlink
2832 case -ESHUTDOWN: // hardware gone
2833 if (netif_msg_ifdown (dev))
2834 devdbg (dev, "rx shutdown, code %d", urb_status);
2837 // we get controller i/o faults during khubd disconnect() delays.
2838 // throttle down resubmits, to avoid log floods; just temporarily,
2839 // so we still recover when the fault isn't a khubd delay.
2840 case -EPROTO: // ehci
2841 case -ETIMEDOUT: // ohci
2842 case -EILSEQ: // uhci
2843 dev->stats.rx_errors++;
2844 if (!timer_pending (&dev->delay)) {
2845 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
2846 if (netif_msg_link (dev))
2847 devdbg (dev, "rx throttle %d", urb_status);
2850 entry->state = rx_cleanup;
2855 // data overrun ... flush fifo?
2857 dev->stats.rx_over_errors++;
2861 entry->state = rx_cleanup;
2862 dev->stats.rx_errors++;
2863 if (netif_msg_rx_err (dev))
2864 devdbg (dev, "rx status %d", urb_status);
2868 defer_bh(dev, skb, &dev->rxq);
2871 if (netif_running (dev->net)
2872 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2873 rx_submit (dev, urb, GFP_ATOMIC);
2878 if (netif_msg_rx_err (dev))
2879 devdbg (dev, "no read resubmitted");
2882 static void intr_complete (struct urb *urb, struct pt_regs *regs)
2884 struct usbnet *dev = urb->context;
2885 int status = urb->status;
2890 dev->driver_info->status(dev, urb);
2893 /* software-driven interface shutdown */
2894 case -ENOENT: // urb killed
2895 case -ESHUTDOWN: // hardware gone
2896 if (netif_msg_ifdown (dev))
2897 devdbg (dev, "intr shutdown, code %d", status);
2900 /* NOTE: not throttling like RX/TX, since this endpoint
2901 * already polls infrequently
2904 devdbg (dev, "intr status %d", status);
2908 if (!netif_running (dev->net))
2911 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
2912 status = usb_submit_urb (urb, GFP_ATOMIC);
2913 if (status != 0 && netif_msg_timer (dev))
2914 deverr(dev, "intr resubmit --> %d", status);
2917 /*-------------------------------------------------------------------------*/
2919 // unlink pending rx/tx; completion handlers do all other cleanup
2921 static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
2923 unsigned long flags;
2924 struct sk_buff *skb, *skbnext;
2927 spin_lock_irqsave (&q->lock, flags);
2928 for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) {
2929 struct skb_data *entry;
2933 entry = (struct skb_data *) skb->cb;
2935 skbnext = skb->next;
2937 // during some PM-driven resume scenarios,
2938 // these (async) unlinks complete immediately
2939 retval = usb_unlink_urb (urb);
2940 if (retval != -EINPROGRESS && retval != 0)
2941 devdbg (dev, "unlink urb err, %d", retval);
2945 spin_unlock_irqrestore (&q->lock, flags);
2950 /*-------------------------------------------------------------------------*/
2952 // precondition: never called in_interrupt
2954 static int usbnet_stop (struct net_device *net)
2956 struct usbnet *dev = netdev_priv(net);
2958 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
2959 DECLARE_WAITQUEUE (wait, current);
2961 netif_stop_queue (net);
2963 if (netif_msg_ifdown (dev))
2964 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
2965 dev->stats.rx_packets, dev->stats.tx_packets,
2966 dev->stats.rx_errors, dev->stats.tx_errors
2969 // ensure there are no more active urbs
2970 add_wait_queue (&unlink_wakeup, &wait);
2971 dev->wait = &unlink_wakeup;
2972 temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq);
2974 // maybe wait for deletions to finish.
2975 while (!skb_queue_empty(&dev->rxq) &&
2976 !skb_queue_empty(&dev->txq) &&
2977 !skb_queue_empty(&dev->done)) {
2978 msleep(UNLINK_TIMEOUT_MS);
2979 if (netif_msg_ifdown (dev))
2980 devdbg (dev, "waited for %d urb completions", temp);
2983 remove_wait_queue (&unlink_wakeup, &wait);
2985 usb_kill_urb(dev->interrupt);
2987 /* deferred work (task, timer, softirq) must also stop.
2988 * can't flush_scheduled_work() until we drop rtnl (later),
2989 * else workers could deadlock; so make workers a NOP.
2992 del_timer_sync (&dev->delay);
2993 tasklet_kill (&dev->bh);
2998 /*-------------------------------------------------------------------------*/
3000 // posts reads, and enables write queuing
3002 // precondition: never called in_interrupt
3004 static int usbnet_open (struct net_device *net)
3006 struct usbnet *dev = netdev_priv(net);
3008 struct driver_info *info = dev->driver_info;
3010 // put into "known safe" state
3011 if (info->reset && (retval = info->reset (dev)) < 0) {
3012 if (netif_msg_ifup (dev))
3014 "open reset fail (%d) usbnet usb-%s-%s, %s",
3016 dev->udev->bus->bus_name, dev->udev->devpath,
3021 // insist peer be connected
3022 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
3023 if (netif_msg_ifup (dev))
3024 devdbg (dev, "can't open; %d", retval);
3028 /* start any status interrupt transfer */
3029 if (dev->interrupt) {
3030 retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
3032 if (netif_msg_ifup (dev))
3033 deverr (dev, "intr submit %d", retval);
3038 netif_start_queue (net);
3039 if (netif_msg_ifup (dev)) {
3042 if (dev->driver_info->flags & FLAG_FRAMING_NC)
3043 framing = "NetChip";
3044 else if (dev->driver_info->flags & FLAG_FRAMING_GL)
3045 framing = "GeneSys";
3046 else if (dev->driver_info->flags & FLAG_FRAMING_Z)
3048 else if (dev->driver_info->flags & FLAG_FRAMING_RN)
3050 else if (dev->driver_info->flags & FLAG_FRAMING_AX)
3055 devinfo (dev, "open: enable queueing "
3056 "(rx %d, tx %d) mtu %d %s framing",
3057 RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu,
3061 // delay posting reads until we're fully open
3062 tasklet_schedule (&dev->bh);
3067 /*-------------------------------------------------------------------------*/
3069 static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
3071 struct usbnet *dev = netdev_priv(net);
3073 strncpy (info->driver, driver_name, sizeof info->driver);
3074 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
3075 strncpy (info->fw_version, dev->driver_info->description,
3076 sizeof info->fw_version);
3077 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
3080 static u32 usbnet_get_link (struct net_device *net)
3082 struct usbnet *dev = netdev_priv(net);
3084 /* If a check_connect is defined, return its result */
3085 if (dev->driver_info->check_connect)
3086 return dev->driver_info->check_connect (dev) == 0;
3088 /* Otherwise, say we're up (to avoid breaking scripts) */
3092 static u32 usbnet_get_msglevel (struct net_device *net)
3094 struct usbnet *dev = netdev_priv(net);
3096 return dev->msg_enable;
3099 static void usbnet_set_msglevel (struct net_device *net, u32 level)
3101 struct usbnet *dev = netdev_priv(net);
3103 dev->msg_enable = level;
3106 static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
3110 struct usbnet *dev = netdev_priv(net);
3112 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
3113 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
3119 /*-------------------------------------------------------------------------*/
3121 /* work that cannot be done in interrupt context uses keventd.
3123 * NOTE: with 2.5 we could do more of this using completion callbacks,
3124 * especially now that control transfers can be queued.
3129 struct usbnet *dev = data;
3132 /* usb_clear_halt() needs a thread context */
3133 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
3134 unlink_urbs (dev, &dev->txq);
3135 status = usb_clear_halt (dev->udev, dev->out);
3138 && status != -ESHUTDOWN) {
3139 if (netif_msg_tx_err (dev))
3140 deverr (dev, "can't clear tx halt, status %d",
3143 clear_bit (EVENT_TX_HALT, &dev->flags);
3144 if (status != -ESHUTDOWN)
3145 netif_wake_queue (dev->net);
3148 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
3149 unlink_urbs (dev, &dev->rxq);
3150 status = usb_clear_halt (dev->udev, dev->in);
3153 && status != -ESHUTDOWN) {
3154 if (netif_msg_rx_err (dev))
3155 deverr (dev, "can't clear rx halt, status %d",
3158 clear_bit (EVENT_RX_HALT, &dev->flags);
3159 tasklet_schedule (&dev->bh);
3163 /* tasklet could resubmit itself forever if memory is tight */
3164 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
3165 struct urb *urb = NULL;
3167 if (netif_running (dev->net))
3168 urb = usb_alloc_urb (0, GFP_KERNEL);
3170 clear_bit (EVENT_RX_MEMORY, &dev->flags);
3172 clear_bit (EVENT_RX_MEMORY, &dev->flags);
3173 rx_submit (dev, urb, GFP_KERNEL);
3174 tasklet_schedule (&dev->bh);
3178 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
3179 struct driver_info *info = dev->driver_info;
3182 clear_bit (EVENT_LINK_RESET, &dev->flags);
3183 if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
3184 devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s",
3186 dev->udev->bus->bus_name, dev->udev->devpath,
3192 devdbg (dev, "kevent done, flags = 0x%lx",
3196 /*-------------------------------------------------------------------------*/
3198 static void tx_complete (struct urb *urb, struct pt_regs *regs)
3200 struct sk_buff *skb = (struct sk_buff *) urb->context;
3201 struct skb_data *entry = (struct skb_data *) skb->cb;
3202 struct usbnet *dev = entry->dev;
3204 if (urb->status == 0) {
3205 dev->stats.tx_packets++;
3206 dev->stats.tx_bytes += entry->length;
3208 dev->stats.tx_errors++;
3210 switch (urb->status) {
3212 defer_kevent (dev, EVENT_TX_HALT);
3215 /* software-driven interface shutdown */
3216 case -ECONNRESET: // async unlink
3217 case -ESHUTDOWN: // hardware gone
3220 // like rx, tx gets controller i/o faults during khubd delays
3221 // and so it uses the same throttling mechanism.
3222 case -EPROTO: // ehci
3223 case -ETIMEDOUT: // ohci
3224 case -EILSEQ: // uhci
3225 if (!timer_pending (&dev->delay)) {
3226 mod_timer (&dev->delay,
3227 jiffies + THROTTLE_JIFFIES);
3228 if (netif_msg_link (dev))
3229 devdbg (dev, "tx throttle %d",
3232 netif_stop_queue (dev->net);
3235 if (netif_msg_tx_err (dev))
3236 devdbg (dev, "tx err %d", entry->urb->status);
3242 entry->state = tx_done;
3243 defer_bh(dev, skb, &dev->txq);
3246 /*-------------------------------------------------------------------------*/
3248 static void usbnet_tx_timeout (struct net_device *net)
3250 struct usbnet *dev = netdev_priv(net);
3252 unlink_urbs (dev, &dev->txq);
3253 tasklet_schedule (&dev->bh);
3255 // FIXME: device recovery -- reset?
3258 /*-------------------------------------------------------------------------*/
3260 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3262 struct usbnet *dev = netdev_priv(net);
3264 int retval = NET_XMIT_SUCCESS;
3265 struct urb *urb = NULL;
3266 struct skb_data *entry;
3267 struct driver_info *info = dev->driver_info;
3268 unsigned long flags;
3269 #ifdef CONFIG_USB_NET1080
3270 struct nc_header *header = NULL;
3271 struct nc_trailer *trailer = NULL;
3272 #endif /* CONFIG_USB_NET1080 */
3274 // some devices want funky USB-level framing, for
3275 // win32 driver (usually) and/or hardware quirks
3276 if (info->tx_fixup) {
3277 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
3279 if (netif_msg_tx_err (dev))
3280 devdbg (dev, "can't tx_fixup skb");
3286 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
3287 if (netif_msg_tx_err (dev))
3288 devdbg (dev, "no urb");
3292 entry = (struct skb_data *) skb->cb;
3295 entry->state = tx_start;
3296 entry->length = length;
3298 // FIXME: reorganize a bit, so that fixup() fills out NetChip
3299 // framing too. (Packet ID update needs the spinlock...)
3300 // [ BETTER: we already own net->xmit_lock, that's enough ]
3302 #ifdef CONFIG_USB_NET1080
3303 if (info->flags & FLAG_FRAMING_NC) {
3304 header = (struct nc_header *) skb_push (skb, sizeof *header);
3305 header->hdr_len = cpu_to_le16 (sizeof (*header));
3306 header->packet_len = cpu_to_le16 (length);
3307 if (!((skb->len + sizeof *trailer) & 0x01))
3308 *skb_put (skb, 1) = PAD_BYTE;
3309 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
3311 #endif /* CONFIG_USB_NET1080 */
3313 usb_fill_bulk_urb (urb, dev->udev, dev->out,
3314 skb->data, skb->len, tx_complete, skb);
3316 /* don't assume the hardware handles USB_ZERO_PACKET
3317 * NOTE: strictly conforming cdc-ether devices should expect
3318 * the ZLP here, but ignore the one-byte packet.
3320 * FIXME zero that byte, if it doesn't require a new skb.
3322 if ((length % dev->maxpacket) == 0)
3323 urb->transfer_buffer_length++;
3325 spin_lock_irqsave (&dev->txq.lock, flags);
3327 #ifdef CONFIG_USB_NET1080
3328 if (info->flags & FLAG_FRAMING_NC) {
3329 header->packet_id = cpu_to_le16 ((u16)dev->xid++);
3330 put_unaligned (header->packet_id, &trailer->packet_id);
3332 devdbg (dev, "frame >tx h %d p %d id %d",
3333 header->hdr_len, header->packet_len,
3337 #endif /* CONFIG_USB_NET1080 */
3339 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
3341 netif_stop_queue (net);
3342 defer_kevent (dev, EVENT_TX_HALT);
3345 if (netif_msg_tx_err (dev))
3346 devdbg (dev, "tx: submit urb err %d", retval);
3349 net->trans_start = jiffies;
3350 __skb_queue_tail (&dev->txq, skb);
3351 if (dev->txq.qlen >= TX_QLEN (dev))
3352 netif_stop_queue (net);
3354 spin_unlock_irqrestore (&dev->txq.lock, flags);
3357 if (netif_msg_tx_err (dev))
3358 devdbg (dev, "drop, code %d", retval);
3360 retval = NET_XMIT_SUCCESS;
3361 dev->stats.tx_dropped++;
3363 dev_kfree_skb_any (skb);
3365 } else if (netif_msg_tx_queued (dev)) {
3366 devdbg (dev, "> tx, len %d, type 0x%x",
3367 length, skb->protocol);
3373 /*-------------------------------------------------------------------------*/
3375 // tasklet (work deferred from completions, in_irq) or timer
3377 static void usbnet_bh (unsigned long param)
3379 struct usbnet *dev = (struct usbnet *) param;
3380 struct sk_buff *skb;
3381 struct skb_data *entry;
3383 while ((skb = skb_dequeue (&dev->done))) {
3384 entry = (struct skb_data *) skb->cb;
3385 switch (entry->state) {
3387 entry->state = rx_cleanup;
3388 rx_process (dev, skb);
3392 usb_free_urb (entry->urb);
3393 dev_kfree_skb (skb);
3396 devdbg (dev, "bogus skb state %d", entry->state);
3400 // waiting for all pending urbs to complete?
3402 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
3403 wake_up (dev->wait);
3406 // or are we maybe short a few urbs?
3407 } else if (netif_running (dev->net)
3408 && netif_device_present (dev->net)
3409 && !timer_pending (&dev->delay)
3410 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
3411 int temp = dev->rxq.qlen;
3412 int qlen = RX_QLEN (dev);
3418 // don't refill the queue all at once
3419 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
3420 urb = usb_alloc_urb (0, GFP_ATOMIC);
3422 rx_submit (dev, urb, GFP_ATOMIC);
3424 if (temp != dev->rxq.qlen && netif_msg_link (dev))
3425 devdbg (dev, "rxqlen %d --> %d",
3426 temp, dev->rxq.qlen);
3427 if (dev->rxq.qlen < qlen)
3428 tasklet_schedule (&dev->bh);
3430 if (dev->txq.qlen < TX_QLEN (dev))
3431 netif_wake_queue (dev->net);
3437 /*-------------------------------------------------------------------------
3439 * USB Device Driver support
3441 *-------------------------------------------------------------------------*/
3443 // precondition: never called in_interrupt
3445 void usbnet_disconnect (struct usb_interface *intf)
3448 struct usb_device *xdev;
3449 struct net_device *net;
3451 dev = usb_get_intfdata(intf);
3452 usb_set_intfdata(intf, NULL);
3456 xdev = interface_to_usbdev (intf);
3458 if (netif_msg_probe (dev))
3459 devinfo (dev, "unregister '%s' usb-%s-%s, %s",
3460 intf->dev.driver->name,
3461 xdev->bus->bus_name, xdev->devpath,
3462 dev->driver_info->description);
3465 unregister_netdev (net);
3467 /* we don't hold rtnl here ... */
3468 flush_scheduled_work ();
3470 if (dev->driver_info->unbind)
3471 dev->driver_info->unbind (dev, intf);
3476 EXPORT_SYMBOL_GPL(usbnet_disconnect);
3479 /*-------------------------------------------------------------------------*/
3481 static struct ethtool_ops usbnet_ethtool_ops;
3483 // precondition: never called in_interrupt
3486 usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3489 struct net_device *net;
3490 struct usb_host_interface *interface;
3491 struct driver_info *info;
3492 struct usb_device *xdev;
3495 info = (struct driver_info *) prod->driver_info;
3497 dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name);
3500 xdev = interface_to_usbdev (udev);
3501 interface = udev->cur_altsetting;
3507 // set up our own records
3508 net = alloc_etherdev(sizeof(*dev));
3510 dbg ("can't kmalloc dev");
3514 dev = netdev_priv(net);
3516 dev->driver_info = info;
3517 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
3518 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
3519 skb_queue_head_init (&dev->rxq);
3520 skb_queue_head_init (&dev->txq);
3521 skb_queue_head_init (&dev->done);
3522 dev->bh.func = usbnet_bh;
3523 dev->bh.data = (unsigned long) dev;
3524 INIT_WORK (&dev->kevent, kevent, dev);
3525 dev->delay.function = usbnet_bh;
3526 dev->delay.data = (unsigned long) dev;
3527 init_timer (&dev->delay);
3529 SET_MODULE_OWNER (net);
3531 strcpy (net->name, "usb%d");
3532 memcpy (net->dev_addr, node_id, sizeof node_id);
3533 dev->hard_mtu = net->mtu + net->hard_header_len;
3536 // dma_supported() is deeply broken on almost all architectures
3537 // possible with some EHCI controllers
3538 if (dma_supported (&udev->dev, DMA_64BIT_MASK))
3539 net->features |= NETIF_F_HIGHDMA;
3542 net->change_mtu = usbnet_change_mtu;
3543 net->get_stats = usbnet_get_stats;
3544 net->hard_start_xmit = usbnet_start_xmit;
3545 net->open = usbnet_open;
3546 net->stop = usbnet_stop;
3547 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3548 net->tx_timeout = usbnet_tx_timeout;
3549 net->do_ioctl = usbnet_ioctl;
3550 net->ethtool_ops = &usbnet_ethtool_ops;
3552 // allow device-specific bind/init procedures
3553 // NOTE net->name still not usable ...
3555 status = info->bind (dev, udev);
3556 // heuristic: "usb%d" for links we know are two-host,
3557 // else "eth%d" when there's reasonable doubt. userspace
3558 // can rename the link if it knows better.
3559 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3560 && (net->dev_addr [0] & 0x02) == 0)
3561 strcpy (net->name, "eth%d");
3563 /* maybe the remote can't receive an Ethernet MTU */
3564 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
3565 net->mtu = dev->hard_mtu - net->hard_header_len;
3566 } else if (!info->in || info->out)
3567 status = get_endpoints (dev, udev);
3569 dev->in = usb_rcvbulkpipe (xdev, info->in);
3570 dev->out = usb_sndbulkpipe (xdev, info->out);
3571 if (!(info->flags & FLAG_NO_SETINT))
3572 status = usb_set_interface (xdev,
3573 interface->desc.bInterfaceNumber,
3574 interface->desc.bAlternateSetting);
3579 if (status == 0 && dev->status)
3580 status = init_status (dev, udev);
3584 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3586 SET_NETDEV_DEV(net, &udev->dev);
3587 status = register_netdev (net);
3590 if (netif_msg_probe (dev))
3591 devinfo (dev, "register '%s' at usb-%s-%s, %s, "
3592 "%02x:%02x:%02x:%02x:%02x:%02x",
3593 udev->dev.driver->name,
3594 xdev->bus->bus_name, xdev->devpath,
3595 dev->driver_info->description,
3596 net->dev_addr [0], net->dev_addr [1],
3597 net->dev_addr [2], net->dev_addr [3],
3598 net->dev_addr [4], net->dev_addr [5]);
3600 // ok, it's ready to go.
3601 usb_set_intfdata (udev, dev);
3603 // start as if the link is up
3604 netif_device_attach (net);
3610 info->unbind (dev, udev);
3617 EXPORT_SYMBOL_GPL(usbnet_probe);
3619 /*-------------------------------------------------------------------------*/
3621 /* FIXME these suspend/resume methods assume non-CDC style
3622 * devices, with only one interface.
3625 int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
3627 struct usbnet *dev = usb_get_intfdata(intf);
3629 /* accelerate emptying of the rx and queues, to avoid
3630 * having everything error out.
3632 netif_device_detach (dev->net);
3633 (void) unlink_urbs (dev, &dev->rxq);
3634 (void) unlink_urbs (dev, &dev->txq);
3635 intf->dev.power.power_state = PMSG_SUSPEND;
3638 EXPORT_SYMBOL_GPL(usbnet_suspend);
3640 int usbnet_resume (struct usb_interface *intf)
3642 struct usbnet *dev = usb_get_intfdata(intf);
3644 intf->dev.power.power_state = PMSG_ON;
3645 netif_device_attach (dev->net);
3646 tasklet_schedule (&dev->bh);
3649 EXPORT_SYMBOL_GPL(usbnet_resume);
3652 /*-------------------------------------------------------------------------*/
3654 #ifndef HAVE_HARDWARE
3655 #error You need to configure some hardware for this driver
3659 * chip vendor names won't normally be on the cables, and
3660 * may not be on the device.
3663 static const struct usb_device_id products [] = {
3665 #ifdef CONFIG_USB_AX8817X
3668 USB_DEVICE (0x077b, 0x2226),
3669 .driver_info = (unsigned long) &ax8817x_info,
3672 USB_DEVICE (0x0846, 0x1040),
3673 .driver_info = (unsigned long) &netgear_fa120_info,
3676 USB_DEVICE (0x2001, 0x1a00),
3677 .driver_info = (unsigned long) &dlink_dub_e100_info,
3679 // Intellinet, ST Lab USB Ethernet
3680 USB_DEVICE (0x0b95, 0x1720),
3681 .driver_info = (unsigned long) &ax8817x_info,
3683 // Hawking UF200, TrendNet TU2-ET100
3684 USB_DEVICE (0x07b8, 0x420a),
3685 .driver_info = (unsigned long) &hawking_uf200_info,
3687 // Billionton Systems, USB2AR
3688 USB_DEVICE (0x08dd, 0x90ff),
3689 .driver_info = (unsigned long) &ax8817x_info,
3692 USB_DEVICE (0x0557, 0x2009),
3693 .driver_info = (unsigned long) &ax8817x_info,
3695 // Buffalo LUA-U2-KTX
3696 USB_DEVICE (0x0411, 0x003d),
3697 .driver_info = (unsigned long) &ax8817x_info,
3699 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3700 USB_DEVICE (0x6189, 0x182d),
3701 .driver_info = (unsigned long) &ax8817x_info,
3703 // corega FEther USB2-TX
3704 USB_DEVICE (0x07aa, 0x0017),
3705 .driver_info = (unsigned long) &ax8817x_info,
3707 // Surecom EP-1427X-2
3708 USB_DEVICE (0x1189, 0x0893),
3709 .driver_info = (unsigned long) &ax8817x_info,
3711 // goodway corp usb gwusb2e
3712 USB_DEVICE (0x1631, 0x6200),
3713 .driver_info = (unsigned long) &ax8817x_info,
3715 // ASIX AX88772 10/100
3716 USB_DEVICE (0x0b95, 0x7720),
3717 .driver_info = (unsigned long) &ax88772_info,
3721 #ifdef CONFIG_USB_GENESYS
3723 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3724 .driver_info = (unsigned long) &genelink_info,
3726 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3727 * that's half duplex, not currently supported
3731 #ifdef CONFIG_USB_NET1080
3733 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3734 .driver_info = (unsigned long) &net1080_info,
3736 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3737 .driver_info = (unsigned long) &net1080_info,
3741 #ifdef CONFIG_USB_PL2301
3743 USB_DEVICE (0x067b, 0x0000), // PL-2301
3744 .driver_info = (unsigned long) &prolific_info,
3746 USB_DEVICE (0x067b, 0x0001), // PL-2302
3747 .driver_info = (unsigned long) &prolific_info,
3751 #ifdef CONFIG_USB_RNDIS
3753 /* RNDIS is MSFT's un-official variant of CDC ACM */
3754 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3755 .driver_info = (unsigned long) &rndis_info,
3759 #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
3761 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3762 * Same idea as above, but different framing.
3764 * PXA-2xx based models are also lying-about-cdc.
3765 * Some models don't even tell the same lies ...
3767 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
3768 * unlike the older ones with 2.4 "embedix" kernels.
3770 * NOTE: These entries do double-duty, serving as blacklist entries
3771 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
3773 #define ZAURUS_MASTER_INTERFACE \
3774 .bInterfaceClass = USB_CLASS_COMM, \
3775 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
3776 .bInterfaceProtocol = USB_CDC_PROTO_NONE
3778 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3779 | USB_DEVICE_ID_MATCH_DEVICE,
3781 .idProduct = 0x8004,
3782 ZAURUS_MASTER_INTERFACE,
3783 .driver_info = ZAURUS_STRONGARM_INFO,
3785 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3786 | USB_DEVICE_ID_MATCH_DEVICE,
3788 .idProduct = 0x8005, /* A-300 */
3789 ZAURUS_MASTER_INTERFACE,
3790 .driver_info = ZAURUS_PXA_INFO,
3792 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3793 | USB_DEVICE_ID_MATCH_DEVICE,
3795 .idProduct = 0x8006, /* B-500/SL-5600 */
3796 ZAURUS_MASTER_INTERFACE,
3797 .driver_info = ZAURUS_PXA_INFO,
3799 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3800 | USB_DEVICE_ID_MATCH_DEVICE,
3802 .idProduct = 0x8007, /* C-700 */
3803 ZAURUS_MASTER_INTERFACE,
3804 .driver_info = ZAURUS_PXA_INFO,
3806 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3807 | USB_DEVICE_ID_MATCH_DEVICE,
3809 .idProduct = 0x9031, /* C-750 C-760 */
3810 ZAURUS_MASTER_INTERFACE,
3811 .driver_info = ZAURUS_PXA_INFO,
3813 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3814 | USB_DEVICE_ID_MATCH_DEVICE,
3816 .idProduct = 0x9032, /* SL-6000 */
3817 ZAURUS_MASTER_INTERFACE,
3818 .driver_info = ZAURUS_PXA_INFO,
3820 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3821 | USB_DEVICE_ID_MATCH_DEVICE,
3823 /* reported with some C860 units */
3824 .idProduct = 0x9050, /* C-860 */
3825 ZAURUS_MASTER_INTERFACE,
3826 .driver_info = ZAURUS_PXA_INFO,
3829 #ifdef CONFIG_USB_ZAURUS
3830 /* At least some (reports vary) PXA units have very different lies
3831 * about their standards support: they claim to be cell phones with
3832 * direct access to their radios. (They don't conform to CDC MDLM.)
3835 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
3836 USB_CDC_PROTO_NONE),
3837 .driver_info = (unsigned long) &bogus_mdlm_info,
3841 /* Olympus has some models with a Zaurus-compatible option.
3842 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
3845 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3846 | USB_DEVICE_ID_MATCH_DEVICE,
3848 .idProduct = 0x0F02, /* R-1000 */
3849 ZAURUS_MASTER_INTERFACE,
3850 .driver_info = OLYMPUS_MXL_INFO,
3854 #ifdef CONFIG_USB_CDCETHER
3856 /* CDC Ether uses two interfaces, not necessarily consecutive.
3857 * We match the main interface, ignoring the optional device
3858 * class so we could handle devices that aren't exclusively
3861 * NOTE: this match must come AFTER entries working around
3862 * bugs/quirks in a given product (like Zaurus, above).
3864 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
3865 USB_CDC_PROTO_NONE),
3866 .driver_info = (unsigned long) &cdc_info,
3872 MODULE_DEVICE_TABLE (usb, products);
3874 static struct usb_driver usbnet_driver = {
3875 .owner = THIS_MODULE,
3876 .name = driver_name,
3877 .id_table = products,
3878 .probe = usbnet_probe,
3879 .disconnect = usbnet_disconnect,
3880 .suspend = usbnet_suspend,
3881 .resume = usbnet_resume,
3884 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
3885 static struct ethtool_ops usbnet_ethtool_ops = {
3886 .get_drvinfo = usbnet_get_drvinfo,
3887 .get_link = usbnet_get_link,
3888 .get_msglevel = usbnet_get_msglevel,
3889 .set_msglevel = usbnet_set_msglevel,
3892 /*-------------------------------------------------------------------------*/
3894 static int __init usbnet_init(void)
3896 // compiler should optimize these out
3897 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
3898 < sizeof (struct skb_data));
3899 #ifdef CONFIG_USB_CDCETHER
3900 BUG_ON ((sizeof (((struct usbnet *)0)->data)
3901 < sizeof (struct cdc_state)));
3904 random_ether_addr(node_id);
3906 return usb_register(&usbnet_driver);
3908 module_init(usbnet_init);
3910 static void __exit usbnet_exit(void)
3912 usb_deregister(&usbnet_driver);
3914 module_exit(usbnet_exit);
3916 MODULE_AUTHOR("David Brownell");
3917 MODULE_DESCRIPTION("USB Host-to-Host Link Drivers (numerous vendors)");
3918 MODULE_LICENSE("GPL");