3 * Copyright (C) 2000-2003 by David Brownell <dbrownell@users.sourceforge.net>
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-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/random.h>
130 #include <linux/ethtool.h>
131 #include <linux/workqueue.h>
132 #include <linux/mii.h>
133 #include <asm/uaccess.h>
134 #include <asm/unaligned.h>
135 #include <linux/usb.h>
137 #include <asm/scatterlist.h>
138 #include <linux/mm.h>
139 #include <linux/dma-mapping.h>
141 #define DRIVER_VERSION "03-Nov-2004"
144 /*-------------------------------------------------------------------------*/
147 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
148 * Several dozen bytes of IPv4 data can fit in two such transactions.
149 * One maximum size Ethernet packet takes twenty four of them.
150 * For high speed, each frame comfortably fits almost 36 max size
151 * Ethernet packets (so queues should be bigger).
153 #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
154 #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
156 // packets are always ethernet inside
157 // ... except they can be bigger (limit of 64K with NetChip framing)
158 #define MIN_PACKET sizeof(struct ethhdr)
159 #define MAX_PACKET 32768
161 // reawaken network queue this soon after stopping; else watchdog barks
162 #define TX_TIMEOUT_JIFFIES (5*HZ)
164 // throttle rx/tx briefly after some faults, so khubd might disconnect()
165 // us (it polls at HZ/4 usually) before we report too many false errors.
166 #define THROTTLE_JIFFIES (HZ/8)
168 // for vendor-specific control operations
169 #define CONTROL_TIMEOUT_MS 500
172 #define UNLINK_TIMEOUT_MS 3
174 /*-------------------------------------------------------------------------*/
176 // randomly generated ethernet address
177 static u8 node_id
[ETH_ALEN
];
179 // state we keep for each device we handle
182 struct usb_device
*udev
;
183 struct driver_info
*driver_info
;
184 wait_queue_head_t
*wait
;
186 // i/o info: pipes etc
188 struct usb_host_endpoint
*status
;
190 struct timer_list delay
;
192 // protocol/interface state
193 struct net_device
*net
;
194 struct net_device_stats stats
;
196 unsigned long data
[5];
198 struct mii_if_info mii
;
200 // various kinds of pending driver work
201 struct sk_buff_head rxq
;
202 struct sk_buff_head txq
;
203 struct sk_buff_head done
;
204 struct urb
*interrupt
;
205 struct tasklet_struct bh
;
207 struct work_struct kevent
;
209 # define EVENT_TX_HALT 0
210 # define EVENT_RX_HALT 1
211 # define EVENT_RX_MEMORY 2
212 # define EVENT_STS_SPLIT 3
215 // device-specific info used by the driver
220 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
221 #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
222 #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
223 #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
224 #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
226 #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
227 #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
229 #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
231 /* init device ... can sleep, or cause probe() failure */
232 int (*bind
)(struct usbnet
*, struct usb_interface
*);
234 /* cleanup device ... can sleep, but can't fail */
235 void (*unbind
)(struct usbnet
*, struct usb_interface
*);
237 /* reset device ... can sleep */
238 int (*reset
)(struct usbnet
*);
240 /* see if peer is connected ... can sleep */
241 int (*check_connect
)(struct usbnet
*);
243 /* for status polling */
244 void (*status
)(struct usbnet
*, struct urb
*);
246 /* fixup rx packet (strip framing) */
247 int (*rx_fixup
)(struct usbnet
*dev
, struct sk_buff
*skb
);
249 /* fixup tx packet (add framing) */
250 struct sk_buff
*(*tx_fixup
)(struct usbnet
*dev
,
251 struct sk_buff
*skb
, int flags
);
253 // FIXME -- also an interrupt mechanism
254 // useful for at least PL2301/2302 and GL620USB-A
255 // and CDC use them to report 'is it connected' changes
257 /* for new devices, use the descriptor-reading code instead */
258 int in
; /* rx endpoint */
259 int out
; /* tx endpoint */
261 unsigned long data
; /* Misc driver specific data */
264 // we record the state for each of our queued skbs
268 rx_start
, rx_done
, rx_cleanup
271 struct skb_data
{ // skb->cb is one of these
274 enum skb_state state
;
278 static const char driver_name
[] = "usbnet";
280 /* use ethtool to change the level for any given device */
281 static int msg_level
= -1;
282 module_param (msg_level
, int, 0);
283 MODULE_PARM_DESC (msg_level
, "Override default message level");
287 #define devdbg(usbnet, fmt, arg...) \
288 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
290 #define devdbg(usbnet, fmt, arg...) do {} while(0)
293 #define deverr(usbnet, fmt, arg...) \
294 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
295 #define devwarn(usbnet, fmt, arg...) \
296 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
298 #define devinfo(usbnet, fmt, arg...) \
299 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
301 /*-------------------------------------------------------------------------*/
303 static void usbnet_get_drvinfo (struct net_device
*, struct ethtool_drvinfo
*);
304 static u32
usbnet_get_link (struct net_device
*);
305 static u32
usbnet_get_msglevel (struct net_device
*);
306 static void usbnet_set_msglevel (struct net_device
*, u32
);
308 /* mostly for PDA style devices, which are always connected if present */
309 static int always_connected (struct usbnet
*dev
)
314 /* handles CDC Ethernet and many other network "bulk data" interfaces */
316 get_endpoints (struct usbnet
*dev
, struct usb_interface
*intf
)
319 struct usb_host_interface
*alt
= NULL
;
320 struct usb_host_endpoint
*in
= NULL
, *out
= NULL
;
321 struct usb_host_endpoint
*status
= NULL
;
323 for (tmp
= 0; tmp
< intf
->num_altsetting
; tmp
++) {
326 in
= out
= status
= NULL
;
327 alt
= intf
->altsetting
+ tmp
;
329 /* take the first altsetting with in-bulk + out-bulk;
330 * remember any status endpoint, just in case;
331 * ignore other endpoints and altsetttings.
333 for (ep
= 0; ep
< alt
->desc
.bNumEndpoints
; ep
++) {
334 struct usb_host_endpoint
*e
;
337 e
= alt
->endpoint
+ ep
;
338 switch (e
->desc
.bmAttributes
) {
339 case USB_ENDPOINT_XFER_INT
:
340 if (!(e
->desc
.bEndpointAddress
& USB_DIR_IN
))
344 case USB_ENDPOINT_XFER_BULK
:
349 if (e
->desc
.bEndpointAddress
& USB_DIR_IN
) {
352 else if (intr
&& !status
)
362 if (!alt
|| !in
|| !out
)
365 if (alt
->desc
.bAlternateSetting
!= 0
366 || !(dev
->driver_info
->flags
& FLAG_NO_SETINT
)) {
367 tmp
= usb_set_interface (dev
->udev
, alt
->desc
.bInterfaceNumber
,
368 alt
->desc
.bAlternateSetting
);
373 dev
->in
= usb_rcvbulkpipe (dev
->udev
,
374 in
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
375 dev
->out
= usb_sndbulkpipe (dev
->udev
,
376 out
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
377 dev
->status
= status
;
381 static void intr_complete (struct urb
*urb
, struct pt_regs
*regs
);
383 static int init_status (struct usbnet
*dev
, struct usb_interface
*intf
)
390 if (!dev
->driver_info
->status
)
393 pipe
= usb_rcvintpipe (dev
->udev
,
394 dev
->status
->desc
.bEndpointAddress
395 & USB_ENDPOINT_NUMBER_MASK
);
396 maxp
= usb_maxpacket (dev
->udev
, pipe
, 0);
398 /* avoid 1 msec chatter: min 8 msec poll rate */
399 period
= max ((int) dev
->status
->desc
.bInterval
,
400 (dev
->udev
->speed
== USB_SPEED_HIGH
) ? 7 : 3);
402 buf
= kmalloc (maxp
, SLAB_KERNEL
);
404 dev
->interrupt
= usb_alloc_urb (0, SLAB_KERNEL
);
405 if (!dev
->interrupt
) {
409 usb_fill_int_urb(dev
->interrupt
, dev
->udev
, pipe
,
410 buf
, maxp
, intr_complete
, dev
, period
);
412 "status ep%din, %d bytes period %d\n",
413 usb_pipeendpoint(pipe
), maxp
, period
);
419 static void skb_return (struct usbnet
*dev
, struct sk_buff
*skb
)
424 skb
->protocol
= eth_type_trans (skb
, dev
->net
);
425 dev
->stats
.rx_packets
++;
426 dev
->stats
.rx_bytes
+= skb
->len
;
428 if (netif_msg_rx_status (dev
))
429 devdbg (dev
, "< rx, len %d, type 0x%x",
430 skb
->len
+ sizeof (struct ethhdr
), skb
->protocol
);
431 memset (skb
->cb
, 0, sizeof (struct skb_data
));
432 status
= netif_rx (skb
);
433 if (status
!= NET_RX_SUCCESS
&& netif_msg_rx_err (dev
))
434 devdbg (dev
, "netif_rx status %d", status
);
438 #ifdef CONFIG_USB_ALI_M5632
439 #define HAVE_HARDWARE
441 /*-------------------------------------------------------------------------
443 * ALi M5632 driver ... does high speed
445 *-------------------------------------------------------------------------*/
447 static const struct driver_info ali_m5632_info
= {
448 .description
= "ALi M5632",
455 #ifdef CONFIG_USB_AN2720
456 #define HAVE_HARDWARE
458 /*-------------------------------------------------------------------------
460 * AnchorChips 2720 driver ... http://www.cypress.com
462 * This doesn't seem to have a way to detect whether the peer is
463 * connected, or need any reset handshaking. It's got pretty big
464 * internal buffers (handles most of a frame's worth of data).
465 * Chip data sheets don't describe any vendor control messages.
467 *-------------------------------------------------------------------------*/
469 static const struct driver_info an2720_info
= {
470 .description
= "AnchorChips/Cypress 2720",
471 // no reset available!
472 // no check_connect available!
474 .in
= 2, .out
= 2, // direction distinguishes these
477 #endif /* CONFIG_USB_AN2720 */
480 #ifdef CONFIG_USB_AX8817X
481 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
483 #define HAVE_HARDWARE
486 #include <linux/crc32.h>
488 #define AX_CMD_SET_SW_MII 0x06
489 #define AX_CMD_READ_MII_REG 0x07
490 #define AX_CMD_WRITE_MII_REG 0x08
491 #define AX_CMD_SET_HW_MII 0x0a
492 #define AX_CMD_READ_EEPROM 0x0b
493 #define AX_CMD_WRITE_EEPROM 0x0c
494 #define AX_CMD_WRITE_ENABLE 0x0d
495 #define AX_CMD_WRITE_DISABLE 0x0e
496 #define AX_CMD_WRITE_RX_CTL 0x10
497 #define AX_CMD_READ_IPG012 0x11
498 #define AX_CMD_WRITE_IPG0 0x12
499 #define AX_CMD_WRITE_IPG1 0x13
500 #define AX_CMD_WRITE_IPG2 0x14
501 #define AX_CMD_WRITE_MULTI_FILTER 0x16
502 #define AX_CMD_READ_NODE_ID 0x17
503 #define AX_CMD_READ_PHY_ID 0x19
504 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
505 #define AX_CMD_READ_MONITOR_MODE 0x1c
506 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
507 #define AX_CMD_WRITE_GPIOS 0x1f
508 #define AX_CMD_SW_RESET 0x20
509 #define AX_CMD_SW_PHY_STATUS 0x21
510 #define AX_CMD_SW_PHY_SELECT 0x22
511 #define AX88772_CMD_READ_NODE_ID 0x13
513 #define AX_MONITOR_MODE 0x01
514 #define AX_MONITOR_LINK 0x02
515 #define AX_MONITOR_MAGIC 0x04
516 #define AX_MONITOR_HSFS 0x10
518 #define AX_MCAST_FILTER_SIZE 8
519 #define AX_MAX_MCAST 64
521 #define AX_INTERRUPT_BUFSIZE 8
523 #define AX_EEPROM_LEN 0x40
525 #define AX_SWRESET_CLEAR 0x00
526 #define AX_SWRESET_RR 0x01
527 #define AX_SWRESET_RT 0x02
528 #define AX_SWRESET_PRTE 0x04
529 #define AX_SWRESET_PRL 0x08
530 #define AX_SWRESET_BZ 0x10
531 #define AX_SWRESET_IPRL 0x20
532 #define AX_SWRESET_IPPD 0x40
534 #define AX88772_IPG0_DEFAULT 0x15
535 #define AX88772_IPG1_DEFAULT 0x0c
536 #define AX88772_IPG2_DEFAULT 0x12
538 #define AX_EEPROM_MAGIC 0xdeadbeef
540 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
541 struct ax8817x_data
{
542 u8 multi_filter
[AX_MCAST_FILTER_SIZE
];
547 static int ax8817x_read_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
548 u16 size
, void *data
)
550 return usb_control_msg(
552 usb_rcvctrlpipe(dev
->udev
, 0),
554 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
562 static int ax8817x_write_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
563 u16 size
, void *data
)
565 return usb_control_msg(
567 usb_sndctrlpipe(dev
->udev
, 0),
569 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
577 static void ax8817x_async_cmd_callback(struct urb
*urb
, struct pt_regs
*regs
)
579 struct usb_ctrlrequest
*req
= (struct usb_ctrlrequest
*)urb
->context
;
582 printk(KERN_DEBUG
"ax8817x_async_cmd_callback() failed with %d",
589 static void ax8817x_interrupt_complete(struct urb
*urb
, struct pt_regs
*regs
)
591 struct usbnet
*dev
= (struct usbnet
*)urb
->context
;
592 struct ax8817x_data
*data
= (struct ax8817x_data
*)&dev
->data
;
595 if (urb
->status
< 0) {
596 devdbg(dev
,"ax8817x_interrupt_complete() failed with %d",
599 link
= data
->int_buf
[2] & 0x01;
600 if (netif_carrier_ok(dev
->net
) != link
) {
602 netif_carrier_on(dev
->net
);
604 netif_carrier_off(dev
->net
);
605 devdbg(dev
, "ax8817x - Link Status is: %d", link
);
607 usb_submit_urb(data
->int_urb
, GFP_ATOMIC
);
611 static void ax8817x_write_cmd_async(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
612 u16 size
, void *data
)
614 struct usb_ctrlrequest
*req
;
618 if ((urb
= usb_alloc_urb(0, GFP_ATOMIC
)) == NULL
) {
619 devdbg(dev
, "Error allocating URB in write_cmd_async!");
623 if ((req
= kmalloc(sizeof(struct usb_ctrlrequest
), GFP_ATOMIC
)) == NULL
) {
624 deverr(dev
, "Failed to allocate memory for control request");
629 req
->bRequestType
= USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
;
631 req
->wValue
= cpu_to_le16(value
);
632 req
->wIndex
= cpu_to_le16(index
);
633 req
->wLength
= cpu_to_le16(size
);
635 usb_fill_control_urb(urb
, dev
->udev
,
636 usb_sndctrlpipe(dev
->udev
, 0),
637 (void *)req
, data
, size
,
638 ax8817x_async_cmd_callback
, req
);
640 if((status
= usb_submit_urb(urb
, GFP_ATOMIC
)) < 0) {
641 deverr(dev
, "Error submitting the control message: status=%d", status
);
647 static void ax8817x_set_multicast(struct net_device
*net
)
649 struct usbnet
*dev
= netdev_priv(net
);
650 struct ax8817x_data
*data
= (struct ax8817x_data
*)&dev
->data
;
653 if (net
->flags
& IFF_PROMISC
) {
655 } else if (net
->flags
& IFF_ALLMULTI
656 || net
->mc_count
> AX_MAX_MCAST
) {
658 } else if (net
->mc_count
== 0) {
659 /* just broadcast and directed */
661 /* We use the 20 byte dev->data
662 * for our 8 byte filter buffer
663 * to avoid allocating memory that
664 * is tricky to free later */
665 struct dev_mc_list
*mc_list
= net
->mc_list
;
669 memset(data
->multi_filter
, 0, AX_MCAST_FILTER_SIZE
);
671 /* Build the multicast hash filter. */
672 for (i
= 0; i
< net
->mc_count
; i
++) {
675 mc_list
->dmi_addr
) >> 26;
676 data
->multi_filter
[crc_bits
>> 3] |=
678 mc_list
= mc_list
->next
;
681 ax8817x_write_cmd_async(dev
, AX_CMD_WRITE_MULTI_FILTER
, 0, 0,
682 AX_MCAST_FILTER_SIZE
, data
->multi_filter
);
687 ax8817x_write_cmd_async(dev
, AX_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
690 static int ax8817x_mdio_read(struct net_device
*netdev
, int phy_id
, int loc
)
692 struct usbnet
*dev
= netdev_priv(netdev
);
696 ax8817x_write_cmd(dev
, AX_CMD_SET_SW_MII
, 0, 0, 0, &buf
);
697 ax8817x_read_cmd(dev
, AX_CMD_READ_MII_REG
, phy_id
, (__u16
)loc
, 2, (u16
*)&res
);
698 ax8817x_write_cmd(dev
, AX_CMD_SET_HW_MII
, 0, 0, 0, &buf
);
703 static void ax8817x_mdio_write(struct net_device
*netdev
, int phy_id
, int loc
, int val
)
705 struct usbnet
*dev
= netdev_priv(netdev
);
709 ax8817x_write_cmd(dev
, AX_CMD_SET_SW_MII
, 0, 0, 0, &buf
);
710 ax8817x_write_cmd(dev
, AX_CMD_WRITE_MII_REG
, phy_id
, (__u16
)loc
, 2, (u16
*)&res
);
711 ax8817x_write_cmd(dev
, AX_CMD_SET_HW_MII
, 0, 0, 0, &buf
);
714 static void ax8817x_get_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
716 struct usbnet
*dev
= netdev_priv(net
);
719 if (ax8817x_read_cmd(dev
, AX_CMD_READ_MONITOR_MODE
, 0, 0, 1, &opt
) < 0) {
720 wolinfo
->supported
= 0;
721 wolinfo
->wolopts
= 0;
724 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
;
725 wolinfo
->wolopts
= 0;
726 if (opt
& AX_MONITOR_MODE
) {
727 if (opt
& AX_MONITOR_LINK
)
728 wolinfo
->wolopts
|= WAKE_PHY
;
729 if (opt
& AX_MONITOR_MAGIC
)
730 wolinfo
->wolopts
|= WAKE_MAGIC
;
734 static int ax8817x_set_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
736 struct usbnet
*dev
= netdev_priv(net
);
740 if (wolinfo
->wolopts
& WAKE_PHY
)
741 opt
|= AX_MONITOR_LINK
;
742 if (wolinfo
->wolopts
& WAKE_MAGIC
)
743 opt
|= AX_MONITOR_MAGIC
;
745 opt
|= AX_MONITOR_MODE
;
747 if (ax8817x_write_cmd(dev
, AX_CMD_WRITE_MONITOR_MODE
,
748 opt
, 0, 0, &buf
) < 0)
754 static int ax8817x_get_eeprom_len(struct net_device
*net
)
756 return AX_EEPROM_LEN
;
759 static int ax8817x_get_eeprom(struct net_device
*net
,
760 struct ethtool_eeprom
*eeprom
, u8
*data
)
762 struct usbnet
*dev
= netdev_priv(net
);
763 u16
*ebuf
= (u16
*)data
;
766 /* Crude hack to ensure that we don't overwrite memory
767 * if an odd length is supplied
772 eeprom
->magic
= AX_EEPROM_MAGIC
;
774 /* ax8817x returns 2 bytes from eeprom on read */
775 for (i
=0; i
< eeprom
->len
/ 2; i
++) {
776 if (ax8817x_read_cmd(dev
, AX_CMD_READ_EEPROM
,
777 eeprom
->offset
+ i
, 0, 2, &ebuf
[i
]) < 0)
783 static void ax8817x_get_drvinfo (struct net_device
*net
,
784 struct ethtool_drvinfo
*info
)
786 /* Inherit standard device info */
787 usbnet_get_drvinfo(net
, info
);
788 info
->eedump_len
= 0x3e;
791 static int ax8817x_get_settings(struct net_device
*net
, struct ethtool_cmd
*cmd
)
793 struct usbnet
*dev
= netdev_priv(net
);
795 return mii_ethtool_gset(&dev
->mii
,cmd
);
798 static int ax8817x_set_settings(struct net_device
*net
, struct ethtool_cmd
*cmd
)
800 struct usbnet
*dev
= netdev_priv(net
);
802 return mii_ethtool_sset(&dev
->mii
,cmd
);
805 /* We need to override some ethtool_ops so we require our
806 own structure so we don't interfere with other usbnet
807 devices that may be connected at the same time. */
808 static struct ethtool_ops ax8817x_ethtool_ops
= {
809 .get_drvinfo
= ax8817x_get_drvinfo
,
810 .get_link
= ethtool_op_get_link
,
811 .get_msglevel
= usbnet_get_msglevel
,
812 .set_msglevel
= usbnet_set_msglevel
,
813 .get_wol
= ax8817x_get_wol
,
814 .set_wol
= ax8817x_set_wol
,
815 .get_eeprom_len
= ax8817x_get_eeprom_len
,
816 .get_eeprom
= ax8817x_get_eeprom
,
817 .get_settings
= ax8817x_get_settings
,
818 .set_settings
= ax8817x_set_settings
,
821 static int ax8817x_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
826 unsigned long gpio_bits
= dev
->driver_info
->data
;
827 struct ax8817x_data
*data
= (struct ax8817x_data
*)dev
->data
;
829 get_endpoints(dev
,intf
);
831 if ((data
->int_urb
= usb_alloc_urb (0, GFP_KERNEL
)) == NULL
) {
832 dbg ("%s: cannot allocate interrupt URB",
838 if ((data
->int_buf
= kmalloc(AX_INTERRUPT_BUFSIZE
, GFP_KERNEL
)) == NULL
) {
839 dbg ("%s: cannot allocate memory for interrupt buffer",
844 memset(data
->int_buf
, 0, AX_INTERRUPT_BUFSIZE
);
846 usb_fill_int_urb (data
->int_urb
, dev
->udev
,
847 usb_rcvintpipe (dev
->udev
, 1),
848 data
->int_buf
, AX_INTERRUPT_BUFSIZE
,
849 ax8817x_interrupt_complete
, dev
,
850 dev
->udev
->speed
== USB_SPEED_HIGH
? 8 : 100);
852 buf
= kmalloc(ETH_ALEN
, GFP_KERNEL
);
858 /* Toggle the GPIOs in a manufacturer/model specific way */
859 for (i
= 2; i
>= 0; i
--) {
860 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_WRITE_GPIOS
,
861 (gpio_bits
>> (i
* 8)) & 0xff, 0, 0,
867 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_WRITE_RX_CTL
, 0x80, 0, 0, buf
)) < 0) {
868 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret
);
872 /* Get the MAC address */
873 memset(buf
, 0, ETH_ALEN
);
874 if ((ret
= ax8817x_read_cmd(dev
, AX_CMD_READ_NODE_ID
, 0, 0, 6, buf
)) < 0) {
875 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret
);
878 memcpy(dev
->net
->dev_addr
, buf
, ETH_ALEN
);
881 if ((ret
= ax8817x_read_cmd(dev
, AX_CMD_READ_PHY_ID
, 0, 0, 2, buf
)) < 0) {
882 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret
);
884 } else if (ret
< 2) {
885 /* this should always return 2 bytes */
886 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret
);
891 /* Initialize MII structure */
892 dev
->mii
.dev
= dev
->net
;
893 dev
->mii
.mdio_read
= ax8817x_mdio_read
;
894 dev
->mii
.mdio_write
= ax8817x_mdio_write
;
895 dev
->mii
.phy_id_mask
= 0x3f;
896 dev
->mii
.reg_num_mask
= 0x1f;
897 dev
->mii
.phy_id
= *((u8
*)buf
+ 1);
899 dev
->net
->set_multicast_list
= ax8817x_set_multicast
;
900 dev
->net
->ethtool_ops
= &ax8817x_ethtool_ops
;
902 ax8817x_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
,
903 cpu_to_le16(BMCR_RESET
));
904 ax8817x_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
905 cpu_to_le16(ADVERTISE_ALL
| ADVERTISE_CSMA
| 0x0400));
906 mii_nway_restart(&dev
->mii
);
908 if((ret
= usb_submit_urb(data
->int_urb
, GFP_KERNEL
)) < 0) {
909 dbg("Failed to submit interrupt URB: %02x", ret
);
917 kfree(data
->int_buf
);
919 usb_free_urb(data
->int_urb
);
923 static void ax8817x_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
925 struct ax8817x_data
*data
= (struct ax8817x_data
*)dev
->data
;
927 usb_kill_urb(data
->int_urb
);
928 usb_free_urb(data
->int_urb
);
929 kfree(data
->int_buf
);
932 static struct ethtool_ops ax88772_ethtool_ops
= {
933 .get_drvinfo
= ax8817x_get_drvinfo
,
934 .get_link
= ethtool_op_get_link
,
935 .get_msglevel
= usbnet_get_msglevel
,
936 .set_msglevel
= usbnet_set_msglevel
,
937 .get_wol
= ax8817x_get_wol
,
938 .set_wol
= ax8817x_set_wol
,
939 .get_eeprom_len
= ax8817x_get_eeprom_len
,
940 .get_eeprom
= ax8817x_get_eeprom
,
941 .get_settings
= ax8817x_get_settings
,
942 .set_settings
= ax8817x_set_settings
,
945 static int ax88772_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
949 struct ax8817x_data
*data
= (struct ax8817x_data
*)dev
->data
;
951 get_endpoints(dev
,intf
);
953 if ((data
->int_urb
= usb_alloc_urb (0, GFP_KERNEL
)) == 0) {
954 dbg ("Cannot allocate interrupt URB");
959 if ((data
->int_buf
= kmalloc(AX_INTERRUPT_BUFSIZE
, GFP_KERNEL
)) == NULL
) {
960 dbg ("Cannot allocate memory for interrupt buffer");
964 memset(data
->int_buf
, 0, AX_INTERRUPT_BUFSIZE
);
966 usb_fill_int_urb (data
->int_urb
, dev
->udev
,
967 usb_rcvintpipe (dev
->udev
, 1),
968 data
->int_buf
, AX_INTERRUPT_BUFSIZE
,
969 ax8817x_interrupt_complete
, dev
,
970 dev
->udev
->speed
== USB_SPEED_HIGH
? 8 : 100);
972 buf
= kmalloc(6, GFP_KERNEL
);
974 dbg ("Cannot allocate memory for buffer");
979 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_WRITE_GPIOS
,
980 0x00B0, 0, 0, buf
)) < 0)
984 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, 0x0001, 0, 0, buf
)) < 0) {
985 dbg("Select PHY #1 failed: %d", ret
);
990 ax8817x_write_cmd(dev
, AX_CMD_SW_RESET
, AX_SWRESET_IPPD
, 0, 0, buf
)) < 0) {
991 dbg("Failed to power down internal PHY: %d", ret
);
997 ax8817x_write_cmd(dev
, AX_CMD_SW_RESET
, AX_SWRESET_CLEAR
, 0, 0, buf
)) < 0) {
998 dbg("Failed to perform software reset: %d", ret
);
1004 ax8817x_write_cmd(dev
, AX_CMD_SW_RESET
, AX_SWRESET_IPRL
| AX_SWRESET_PRL
, 0, 0, buf
)) < 0) {
1005 dbg("Failed to set Internal/External PHY reset control: %d", ret
);
1011 ax8817x_write_cmd(dev
, AX_CMD_WRITE_RX_CTL
, 0x0000, 0, 0,
1013 dbg("Failed to reset RX_CTL: %d", ret
);
1017 /* Get the MAC address */
1018 memset(buf
, 0, ETH_ALEN
);
1019 if ((ret
= ax8817x_read_cmd(dev
, AX88772_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
)) < 0) {
1020 dbg("Failed to read MAC address: %d", ret
);
1023 memcpy(dev
->net
->dev_addr
, buf
, ETH_ALEN
);
1025 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_SET_SW_MII
, 0, 0, 0, buf
)) < 0) {
1026 dbg("Enabling software MII failed: %d", ret
);
1031 ax8817x_read_cmd(dev
, AX_CMD_READ_MII_REG
, 0x0010, 2, 2, buf
)) < 0)
1032 || (*((u16
*)buf
) != 0x003b)) {
1033 dbg("Read PHY register 2 must be 0x3b00: %d", ret
);
1037 /* Initialize MII structure */
1038 dev
->mii
.dev
= dev
->net
;
1039 dev
->mii
.mdio_read
= ax8817x_mdio_read
;
1040 dev
->mii
.mdio_write
= ax8817x_mdio_write
;
1041 dev
->mii
.phy_id_mask
= 0xff;
1042 dev
->mii
.reg_num_mask
= 0xff;
1044 /* Get the PHY id */
1045 if ((ret
= ax8817x_read_cmd(dev
, AX_CMD_READ_PHY_ID
, 0, 0, 2, buf
)) < 0) {
1046 dbg("Error reading PHY ID: %02x", ret
);
1048 } else if (ret
< 2) {
1049 /* this should always return 2 bytes */
1050 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
1055 dev
->mii
.phy_id
= *((u8
*)buf
+ 1);
1058 ax8817x_write_cmd(dev
, AX_CMD_SW_RESET
, AX_SWRESET_PRL
, 0, 0, buf
)) < 0) {
1059 dbg("Set external PHY reset pin level: %d", ret
);
1064 ax8817x_write_cmd(dev
, AX_CMD_SW_RESET
, AX_SWRESET_IPRL
| AX_SWRESET_PRL
, 0, 0, buf
)) < 0) {
1065 dbg("Set Internal/External PHY reset control: %d", ret
);
1071 dev
->net
->set_multicast_list
= ax8817x_set_multicast
;
1072 dev
->net
->ethtool_ops
= &ax88772_ethtool_ops
;
1074 ax8817x_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
,
1075 cpu_to_le16(BMCR_RESET
));
1076 ax8817x_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
1077 cpu_to_le16(ADVERTISE_ALL
| ADVERTISE_CSMA
));
1078 mii_nway_restart(&dev
->mii
);
1080 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_WRITE_MEDIUM_MODE
, 0x0336, 0, 0, buf
)) < 0) {
1081 dbg("Write medium mode register: %d", ret
);
1085 if ((ret
= ax8817x_write_cmd(dev
, AX_CMD_WRITE_IPG0
, AX88772_IPG0_DEFAULT
| AX88772_IPG1_DEFAULT
,AX88772_IPG2_DEFAULT
, 0, buf
)) < 0) {
1086 dbg("Write IPG,IPG1,IPG2 failed: %d", ret
);
1090 ax8817x_write_cmd(dev
, AX_CMD_SET_HW_MII
, 0, 0, 0, &buf
)) < 0) {
1091 dbg("Failed to set hardware MII: %02x", ret
);
1095 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1097 ax8817x_write_cmd(dev
, AX_CMD_WRITE_RX_CTL
, 0x0088, 0, 0,
1099 dbg("Reset RX_CTL failed: %d", ret
);
1103 if((ret
= usb_submit_urb(data
->int_urb
, GFP_KERNEL
)) < 0) {
1104 dbg("Failed to submit interrupt URB: %02x", ret
);
1115 kfree(data
->int_buf
);
1117 usb_free_urb(data
->int_urb
);
1122 static int ax88772_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
)
1126 struct sk_buff
*ax_skb
;
1129 header
= (u32
*) skb
->data
;
1130 le32_to_cpus(header
);
1131 packet
= (char *)(header
+ 1);
1135 while (skb
->len
> 0) {
1136 if ((short)(*header
& 0x0000ffff) !=
1137 ~((short)((*header
& 0xffff0000) >> 16))) {
1138 devdbg(dev
,"header length data is error");
1140 /* get the packet length */
1141 size
= (u16
) (*header
& 0x0000ffff);
1143 if ((skb
->len
) - ((size
+ 1) & 0xfffe) == 0)
1145 if (size
> ETH_FRAME_LEN
) {
1146 devdbg(dev
,"invalid rx length %d", size
);
1149 ax_skb
= skb_clone(skb
, GFP_ATOMIC
);
1152 ax_skb
->data
= packet
;
1153 ax_skb
->tail
= packet
+ size
;
1154 skb_return(dev
, ax_skb
);
1159 skb_pull(skb
, (size
+ 1) & 0xfffe);
1164 header
= (u32
*) skb
->data
;
1165 le32_to_cpus(header
);
1166 packet
= (char *)(header
+ 1);
1171 devdbg(dev
,"invalid rx length %d", skb
->len
);
1177 static struct sk_buff
*ax88772_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
,
1181 int headroom
= skb_headroom(skb
);
1182 int tailroom
= skb_tailroom(skb
);
1186 padlen
= ((skb
->len
+ 4) % 512) ? 0 : 4;
1188 if ((!skb_cloned(skb
))
1189 && ((headroom
+ tailroom
) >= (4 + padlen
))) {
1190 if ((headroom
< 4) || (tailroom
< padlen
)) {
1191 skb
->data
= memmove(skb
->head
+ 4, skb
->data
, skb
->len
);
1192 skb
->tail
= skb
->data
+ skb
->len
;
1195 struct sk_buff
*skb2
;
1196 skb2
= skb_copy_expand(skb
, 4, padlen
, flags
);
1197 dev_kfree_skb_any(skb
);
1203 packet_len
= (u32
*) skb_push(skb
, 4);
1205 packet_len
= (u32
*) skb
->data
;
1206 *packet_len
= (((skb
->len
- 4) ^ 0x0000ffff) << 16) + (skb
->len
- 4);
1208 if ((skb
->len
% 512) == 0) {
1209 padbytes_ptr
= (u32
*) skb
->tail
;
1210 *padbytes_ptr
= 0xffff0000;
1211 skb_put(skb
, padlen
);
1216 static const struct driver_info ax8817x_info
= {
1217 .description
= "ASIX AX8817x USB 2.0 Ethernet",
1218 .bind
= ax8817x_bind
,
1219 .unbind
= ax8817x_unbind
,
1220 .flags
= FLAG_ETHER
,
1224 static const struct driver_info dlink_dub_e100_info
= {
1225 .description
= "DLink DUB-E100 USB Ethernet",
1226 .bind
= ax8817x_bind
,
1227 .unbind
= ax8817x_unbind
,
1228 .flags
= FLAG_ETHER
,
1232 static const struct driver_info netgear_fa120_info
= {
1233 .description
= "Netgear FA-120 USB Ethernet",
1234 .bind
= ax8817x_bind
,
1235 .unbind
= ax8817x_unbind
,
1236 .flags
= FLAG_ETHER
,
1240 static const struct driver_info hawking_uf200_info
= {
1241 .description
= "Hawking UF200 USB Ethernet",
1242 .bind
= ax8817x_bind
,
1243 .unbind
= ax8817x_unbind
,
1244 .flags
= FLAG_ETHER
,
1248 static const struct driver_info ax88772_info
= {
1249 .description
= "ASIX AX88772 USB 2.0 Ethernet",
1250 .bind
= ax88772_bind
,
1251 .unbind
= ax8817x_unbind
,
1252 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1253 .rx_fixup
= ax88772_rx_fixup
,
1254 .tx_fixup
= ax88772_tx_fixup
,
1258 #endif /* CONFIG_USB_AX8817X */
1262 #ifdef CONFIG_USB_BELKIN
1263 #define HAVE_HARDWARE
1265 /*-------------------------------------------------------------------------
1267 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
1269 * ... also two eTEK designs, including one sold as "Advance USBNET"
1271 *-------------------------------------------------------------------------*/
1273 static const struct driver_info belkin_info
= {
1274 .description
= "Belkin, eTEK, or compatible",
1277 #endif /* CONFIG_USB_BELKIN */
1281 /*-------------------------------------------------------------------------
1283 * Communications Device Class declarations.
1284 * Used by CDC Ethernet, and some CDC variants
1286 *-------------------------------------------------------------------------*/
1288 #ifdef CONFIG_USB_CDCETHER
1289 #define NEED_GENERIC_CDC
1292 #ifdef CONFIG_USB_ZAURUS
1293 /* Ethernet variant uses funky framing, broken ethernet addressing */
1294 #define NEED_GENERIC_CDC
1297 #ifdef CONFIG_USB_RNDIS
1298 /* ACM variant uses even funkier framing, complex control RPC scheme */
1299 #define NEED_GENERIC_CDC
1303 #ifdef NEED_GENERIC_CDC
1305 #include <linux/usb_cdc.h>
1308 struct usb_cdc_header_desc
*header
;
1309 struct usb_cdc_union_desc
*u
;
1310 struct usb_cdc_ether_desc
*ether
;
1311 struct usb_interface
*control
;
1312 struct usb_interface
*data
;
1315 static struct usb_driver usbnet_driver
;
1318 * probes control interface, claims data interface, collects the bulk
1319 * endpoints, activates data interface (if needed), maybe sets MTU.
1320 * all pure cdc, except for certain firmware workarounds.
1322 static int generic_cdc_bind (struct usbnet
*dev
, struct usb_interface
*intf
)
1324 u8
*buf
= intf
->cur_altsetting
->extra
;
1325 int len
= intf
->cur_altsetting
->extralen
;
1326 struct usb_interface_descriptor
*d
;
1327 struct cdc_state
*info
= (void *) &dev
->data
;
1331 if (sizeof dev
->data
< sizeof *info
)
1334 /* expect strict spec conformance for the descriptors, but
1335 * cope with firmware which stores them in the wrong place
1337 if (len
== 0 && dev
->udev
->actconfig
->extralen
) {
1338 /* Motorola SB4100 (and others: Brad Hards says it's
1339 * from a Broadcom design) put CDC descriptors here
1341 buf
= dev
->udev
->actconfig
->extra
;
1342 len
= dev
->udev
->actconfig
->extralen
;
1344 dev_dbg (&intf
->dev
,
1345 "CDC descriptors on config\n");
1348 /* this assumes that if there's a non-RNDIS vendor variant
1349 * of cdc-acm, it'll fail RNDIS requests cleanly.
1351 rndis
= (intf
->cur_altsetting
->desc
.bInterfaceProtocol
== 0xff);
1353 memset (info
, 0, sizeof *info
);
1354 info
->control
= intf
;
1356 if (buf
[1] != USB_DT_CS_INTERFACE
)
1359 /* use bDescriptorSubType to identify the CDC descriptors.
1360 * We expect devices with CDC header and union descriptors.
1361 * For CDC Ethernet we need the ethernet descriptor.
1362 * For RNDIS, ignore two (pointless) CDC modem descriptors
1363 * in favor of a complicated OID-based RPC scheme doing what
1364 * CDC Ethernet achieves with a simple descriptor.
1367 case USB_CDC_HEADER_TYPE
:
1369 dev_dbg (&intf
->dev
, "extra CDC header\n");
1372 info
->header
= (void *) buf
;
1373 if (info
->header
->bLength
!= sizeof *info
->header
) {
1374 dev_dbg (&intf
->dev
, "CDC header len %u\n",
1375 info
->header
->bLength
);
1379 case USB_CDC_UNION_TYPE
:
1381 dev_dbg (&intf
->dev
, "extra CDC union\n");
1384 info
->u
= (void *) buf
;
1385 if (info
->u
->bLength
!= sizeof *info
->u
) {
1386 dev_dbg (&intf
->dev
, "CDC union len %u\n",
1391 /* we need a master/control interface (what we're
1392 * probed with) and a slave/data interface; union
1393 * descriptors sort this all out.
1395 info
->control
= usb_ifnum_to_if(dev
->udev
,
1396 info
->u
->bMasterInterface0
);
1397 info
->data
= usb_ifnum_to_if(dev
->udev
,
1398 info
->u
->bSlaveInterface0
);
1399 if (!info
->control
|| !info
->data
) {
1400 dev_dbg (&intf
->dev
,
1401 "master #%u/%p slave #%u/%p\n",
1402 info
->u
->bMasterInterface0
,
1404 info
->u
->bSlaveInterface0
,
1408 if (info
->control
!= intf
) {
1409 dev_dbg (&intf
->dev
, "bogus CDC Union\n");
1410 /* Ambit USB Cable Modem (and maybe others)
1411 * interchanges master and slave interface.
1413 if (info
->data
== intf
) {
1414 info
->data
= info
->control
;
1415 info
->control
= intf
;
1420 /* a data interface altsetting does the real i/o */
1421 d
= &info
->data
->cur_altsetting
->desc
;
1422 if (d
->bInterfaceClass
!= USB_CLASS_CDC_DATA
) {
1423 dev_dbg (&intf
->dev
, "slave class %u\n",
1424 d
->bInterfaceClass
);
1428 case USB_CDC_ETHERNET_TYPE
:
1430 dev_dbg (&intf
->dev
, "extra CDC ether\n");
1433 info
->ether
= (void *) buf
;
1434 if (info
->ether
->bLength
!= sizeof *info
->ether
) {
1435 dev_dbg (&intf
->dev
, "CDC ether len %u\n",
1439 dev
->net
->mtu
= le16_to_cpup (
1440 &info
->ether
->wMaxSegmentSize
)
1442 /* because of Zaurus, we may be ignoring the host
1443 * side link address we were given.
1448 len
-= buf
[0]; /* bLength */
1452 if (!info
->header
|| !info
->u
|| (!rndis
&& !info
->ether
)) {
1453 dev_dbg (&intf
->dev
, "missing cdc %s%s%sdescriptor\n",
1454 info
->header
? "" : "header ",
1455 info
->u
? "" : "union ",
1456 info
->ether
? "" : "ether ");
1460 /* claim data interface and set it up ... with side effects.
1461 * network traffic can't flow until an altsetting is enabled.
1463 status
= usb_driver_claim_interface (&usbnet_driver
, info
->data
, dev
);
1466 status
= get_endpoints (dev
, info
->data
);
1468 /* ensure immediate exit from usbnet_disconnect */
1469 usb_set_intfdata(info
->data
, NULL
);
1470 usb_driver_release_interface (&usbnet_driver
, info
->data
);
1474 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
1476 if (info
->control
->cur_altsetting
->desc
.bNumEndpoints
== 1) {
1477 struct usb_endpoint_descriptor
*desc
;
1479 dev
->status
= &info
->control
->cur_altsetting
->endpoint
[0];
1480 desc
= &dev
->status
->desc
;
1481 if (desc
->bmAttributes
!= USB_ENDPOINT_XFER_INT
1482 || !(desc
->bEndpointAddress
& USB_DIR_IN
)
1483 || (le16_to_cpu(desc
->wMaxPacketSize
)
1484 < sizeof (struct usb_cdc_notification
))
1485 || !desc
->bInterval
) {
1486 dev_dbg (&intf
->dev
, "bad notification endpoint\n");
1490 if (rndis
&& !dev
->status
) {
1491 dev_dbg (&intf
->dev
, "missing RNDIS status endpoint\n");
1492 usb_set_intfdata(info
->data
, NULL
);
1493 usb_driver_release_interface (&usbnet_driver
, info
->data
);
1499 dev_info (&dev
->udev
->dev
, "bad CDC descriptors\n");
1503 static void cdc_unbind (struct usbnet
*dev
, struct usb_interface
*intf
)
1505 struct cdc_state
*info
= (void *) &dev
->data
;
1507 /* disconnect master --> disconnect slave */
1508 if (intf
== info
->control
&& info
->data
) {
1509 /* ensure immediate exit from usbnet_disconnect */
1510 usb_set_intfdata(info
->data
, NULL
);
1511 usb_driver_release_interface (&usbnet_driver
, info
->data
);
1515 /* and vice versa (just in case) */
1516 else if (intf
== info
->data
&& info
->control
) {
1517 /* ensure immediate exit from usbnet_disconnect */
1518 usb_set_intfdata(info
->control
, NULL
);
1519 usb_driver_release_interface (&usbnet_driver
, info
->control
);
1520 info
->control
= NULL
;
1525 static void dumpspeed (struct usbnet
*dev
, __le32
*speeds
)
1527 if (netif_msg_timer (dev
))
1528 devinfo (dev
, "link speeds: %u kbps up, %u kbps down",
1529 __le32_to_cpu(speeds
[0]) / 1000,
1530 __le32_to_cpu(speeds
[1]) / 1000);
1533 static void cdc_status (struct usbnet
*dev
, struct urb
*urb
)
1535 struct usb_cdc_notification
*event
;
1537 if (urb
->actual_length
< sizeof *event
)
1540 /* SPEED_CHANGE can get split into two 8-byte packets */
1541 if (test_and_clear_bit (EVENT_STS_SPLIT
, &dev
->flags
)) {
1542 dumpspeed (dev
, (__le32
*) urb
->transfer_buffer
);
1546 event
= urb
->transfer_buffer
;
1547 switch (event
->bNotificationType
) {
1548 case USB_CDC_NOTIFY_NETWORK_CONNECTION
:
1549 if (netif_msg_timer (dev
))
1550 devdbg (dev
, "CDC: carrier %s",
1551 event
->wValue
? "on" : "off");
1553 netif_carrier_on(dev
->net
);
1555 netif_carrier_off(dev
->net
);
1557 case USB_CDC_NOTIFY_SPEED_CHANGE
: /* tx/rx rates */
1558 if (netif_msg_timer (dev
))
1559 devdbg (dev
, "CDC: speed change (len %d)",
1560 urb
->actual_length
);
1561 if (urb
->actual_length
!= (sizeof *event
+ 8))
1562 set_bit (EVENT_STS_SPLIT
, &dev
->flags
);
1564 dumpspeed (dev
, (__le32
*) &event
[1]);
1566 // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
1568 deverr (dev
, "CDC: unexpected notification %02x!",
1569 event
->bNotificationType
);
1574 #endif /* NEED_GENERIC_CDC */
1577 #ifdef CONFIG_USB_CDCETHER
1578 #define HAVE_HARDWARE
1580 /*-------------------------------------------------------------------------
1582 * Communications Device Class, Ethernet Control model
1584 * Takes two interfaces. The DATA interface is inactive till an altsetting
1585 * is selected. Configuration data includes class descriptors.
1587 * This should interop with whatever the 2.4 "CDCEther.c" driver
1588 * (by Brad Hards) talked with.
1590 *-------------------------------------------------------------------------*/
1592 #include <linux/ctype.h>
1594 static u8
nibble (unsigned char c
)
1596 if (likely (isdigit (c
)))
1599 if (likely (isxdigit (c
)))
1600 return 10 + c
- 'A';
1605 get_ethernet_addr (struct usbnet
*dev
, struct usb_cdc_ether_desc
*e
)
1608 unsigned char buf
[13];
1610 tmp
= usb_string (dev
->udev
, e
->iMACAddress
, buf
, sizeof buf
);
1612 dev_dbg (&dev
->udev
->dev
,
1613 "bad MAC string %d fetch, %d\n", e
->iMACAddress
, tmp
);
1618 for (i
= tmp
= 0; i
< 6; i
++, tmp
+= 2)
1619 dev
->net
->dev_addr
[i
] =
1620 (nibble (buf
[tmp
]) << 4) + nibble (buf
[tmp
+ 1]);
1624 static int cdc_bind (struct usbnet
*dev
, struct usb_interface
*intf
)
1627 struct cdc_state
*info
= (void *) &dev
->data
;
1629 status
= generic_cdc_bind (dev
, intf
);
1633 status
= get_ethernet_addr (dev
, info
->ether
);
1635 usb_set_intfdata(info
->data
, NULL
);
1636 usb_driver_release_interface (&usbnet_driver
, info
->data
);
1640 /* FIXME cdc-ether has some multicast code too, though it complains
1641 * in routine cases. info->ether describes the multicast support.
1646 static const struct driver_info cdc_info
= {
1647 .description
= "CDC Ethernet Device",
1648 .flags
= FLAG_ETHER
,
1649 // .check_connect = cdc_check_connect,
1651 .unbind
= cdc_unbind
,
1652 .status
= cdc_status
,
1655 #endif /* CONFIG_USB_CDCETHER */
1659 #ifdef CONFIG_USB_EPSON2888
1660 #define HAVE_HARDWARE
1662 /*-------------------------------------------------------------------------
1666 * This is the same idea as Linux PDAs (below) except the firmware in the
1667 * device might not be Tux-powered. Epson provides reference firmware that
1668 * implements this interface. Product developers can reuse or modify that
1669 * code, such as by using their own product and vendor codes.
1671 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1673 *-------------------------------------------------------------------------*/
1675 static const struct driver_info epson2888_info
= {
1676 .description
= "Epson USB Device",
1677 .check_connect
= always_connected
,
1682 #endif /* CONFIG_USB_EPSON2888 */
1685 #ifdef CONFIG_USB_GENESYS
1686 #define HAVE_HARDWARE
1688 /*-------------------------------------------------------------------------
1690 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1692 * ... should partially interop with the Win32 driver for this hardware
1693 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1695 * Some info from GeneSys:
1696 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1697 * (Some cables, like the BAFO-100c, use the half duplex version.)
1698 * - For the full duplex model, the low bit of the version code says
1699 * which side is which ("left/right").
1700 * - For the half duplex type, a control/interrupt handshake settles
1701 * the transfer direction. (That's disabled here, partially coded.)
1702 * A control URB would block until other side writes an interrupt.
1704 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1705 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1707 *-------------------------------------------------------------------------*/
1709 // control msg write command
1710 #define GENELINK_CONNECT_WRITE 0xF0
1711 // interrupt pipe index
1712 #define GENELINK_INTERRUPT_PIPE 0x03
1713 // interrupt read buffer size
1714 #define INTERRUPT_BUFSIZE 0x08
1715 // interrupt pipe interval value
1716 #define GENELINK_INTERRUPT_INTERVAL 0x10
1717 // max transmit packet number per transmit
1718 #define GL_MAX_TRANSMIT_PACKETS 32
1719 // max packet length
1720 #define GL_MAX_PACKET_LEN 1514
1721 // max receive buffer size
1722 #define GL_RCV_BUF_SIZE \
1723 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1727 char packet_data
[1];
1732 struct gl_packet packets
;
1737 // FIXME: this code is incomplete, not debugged; it doesn't
1738 // handle interrupts correctly. interrupts should be generic
1739 // code like all other device I/O, anyway.
1742 struct urb
*irq_urb
;
1743 char irq_buf
[INTERRUPT_BUFSIZE
];
1746 static inline int gl_control_write (struct usbnet
*dev
, u8 request
, u16 value
)
1750 retval
= usb_control_msg (dev
->udev
,
1751 usb_sndctrlpipe (dev
->udev
, 0),
1753 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
1758 CONTROL_TIMEOUT_MS
);
1762 static void gl_interrupt_complete (struct urb
*urb
, struct pt_regs
*regs
)
1764 int status
= urb
->status
;
1773 /* this urb is terminated, clean up */
1774 dbg("%s - urb shutting down with status: %d",
1775 __FUNCTION__
, status
);
1778 dbg("%s - nonzero urb status received: %d",
1779 __FUNCTION__
, urb
->status
);
1782 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
1784 err ("%s - usb_submit_urb failed with result %d",
1785 __FUNCTION__
, status
);
1788 static int gl_interrupt_read (struct usbnet
*dev
)
1790 struct gl_priv
*priv
= dev
->priv_data
;
1793 // issue usb interrupt read
1794 if (priv
&& priv
->irq_urb
) {
1796 if ((retval
= usb_submit_urb (priv
->irq_urb
, GFP_KERNEL
)) != 0)
1797 dbg ("gl_interrupt_read: submit fail - %X...", retval
);
1799 dbg ("gl_interrupt_read: submit success...");
1805 // check whether another side is connected
1806 static int genelink_check_connect (struct usbnet
*dev
)
1810 dbg ("genelink_check_connect...");
1812 // detect whether another side is connected
1813 if ((retval
= gl_control_write (dev
, GENELINK_CONNECT_WRITE
, 0)) != 0) {
1814 dbg ("%s: genelink_check_connect write fail - %X",
1815 dev
->net
->name
, retval
);
1819 // usb interrupt read to ack another side
1820 if ((retval
= gl_interrupt_read (dev
)) != 0) {
1821 dbg ("%s: genelink_check_connect read fail - %X",
1822 dev
->net
->name
, retval
);
1826 dbg ("%s: genelink_check_connect read success", dev
->net
->name
);
1830 // allocate and initialize the private data for genelink
1831 static int genelink_init (struct usbnet
*dev
)
1833 struct gl_priv
*priv
;
1835 // allocate the private data structure
1836 if ((priv
= kmalloc (sizeof *priv
, GFP_KERNEL
)) == 0) {
1837 dbg ("%s: cannot allocate private data per device",
1843 if ((priv
->irq_urb
= usb_alloc_urb (0, GFP_KERNEL
)) == 0) {
1844 dbg ("%s: cannot allocate private irq urb per device",
1851 usb_fill_int_urb (priv
->irq_urb
, dev
->udev
,
1852 usb_rcvintpipe (dev
->udev
, GENELINK_INTERRUPT_PIPE
),
1853 priv
->irq_buf
, INTERRUPT_BUFSIZE
,
1854 gl_interrupt_complete
, 0,
1855 GENELINK_INTERRUPT_INTERVAL
);
1857 // set private data pointer
1858 dev
->priv_data
= priv
;
1863 // release the private data
1864 static int genelink_free (struct usbnet
*dev
)
1866 struct gl_priv
*priv
= dev
->priv_data
;
1871 // FIXME: can't cancel here; it's synchronous, and
1872 // should have happened earlier in any case (interrupt
1873 // handling needs to be generic)
1875 // cancel irq urb first
1876 usb_kill_urb (priv
->irq_urb
);
1879 usb_free_urb (priv
->irq_urb
);
1881 // free the private data structure
1889 static int genelink_rx_fixup (struct usbnet
*dev
, struct sk_buff
*skb
)
1891 struct gl_header
*header
;
1892 struct gl_packet
*packet
;
1893 struct sk_buff
*gl_skb
;
1896 header
= (struct gl_header
*) skb
->data
;
1898 // get the packet count of the received skb
1899 le32_to_cpus (&header
->packet_count
);
1900 if ((header
->packet_count
> GL_MAX_TRANSMIT_PACKETS
)
1901 || (header
->packet_count
< 0)) {
1902 dbg ("genelink: invalid received packet count %d",
1903 header
->packet_count
);
1907 // set the current packet pointer to the first packet
1908 packet
= &header
->packets
;
1910 // decrement the length for the packet count size 4 bytes
1913 while (header
->packet_count
> 1) {
1914 // get the packet length
1915 size
= packet
->packet_length
;
1917 // this may be a broken packet
1918 if (size
> GL_MAX_PACKET_LEN
) {
1919 dbg ("genelink: invalid rx length %d", size
);
1923 // allocate the skb for the individual packet
1924 gl_skb
= alloc_skb (size
, GFP_ATOMIC
);
1927 // copy the packet data to the new skb
1928 memcpy(skb_put(gl_skb
, size
), packet
->packet_data
, size
);
1929 skb_return (dev
, skb
);
1932 // advance to the next packet
1933 packet
= (struct gl_packet
*)
1934 &packet
->packet_data
[size
];
1935 header
->packet_count
--;
1937 // shift the data pointer to the next gl_packet
1938 skb_pull (skb
, size
+ 4);
1941 // skip the packet length field 4 bytes
1944 if (skb
->len
> GL_MAX_PACKET_LEN
) {
1945 dbg ("genelink: invalid rx length %d", skb
->len
);
1951 static struct sk_buff
*
1952 genelink_tx_fixup (struct usbnet
*dev
, struct sk_buff
*skb
, int flags
)
1955 int length
= skb
->len
;
1956 int headroom
= skb_headroom (skb
);
1957 int tailroom
= skb_tailroom (skb
);
1961 // FIXME: magic numbers, bleech
1962 padlen
= ((skb
->len
+ (4 + 4*1)) % 64) ? 0 : 1;
1964 if ((!skb_cloned (skb
))
1965 && ((headroom
+ tailroom
) >= (padlen
+ (4 + 4*1)))) {
1966 if ((headroom
< (4 + 4*1)) || (tailroom
< padlen
)) {
1967 skb
->data
= memmove (skb
->head
+ (4 + 4*1),
1968 skb
->data
, skb
->len
);
1969 skb
->tail
= skb
->data
+ skb
->len
;
1972 struct sk_buff
*skb2
;
1973 skb2
= skb_copy_expand (skb
, (4 + 4*1) , padlen
, flags
);
1974 dev_kfree_skb_any (skb
);
1980 // attach the packet count to the header
1981 packet_count
= (u32
*) skb_push (skb
, (4 + 4*1));
1982 packet_len
= packet_count
+ 1;
1984 // FIXME little endian?
1986 *packet_len
= length
;
1989 if ((skb
->len
% dev
->maxpacket
) == 0)
1995 static const struct driver_info genelink_info
= {
1996 .description
= "Genesys GeneLink",
1997 .flags
= FLAG_FRAMING_GL
| FLAG_NO_SETINT
,
1998 .rx_fixup
= genelink_rx_fixup
,
1999 .tx_fixup
= genelink_tx_fixup
,
2004 .check_connect
=genelink_check_connect
,
2008 #endif /* CONFIG_USB_GENESYS */
2012 #ifdef CONFIG_USB_NET1080
2013 #define HAVE_HARDWARE
2015 /*-------------------------------------------------------------------------
2017 * Netchip 1080 driver ... http://www.netchip.com
2018 * Used in LapLink cables
2020 *-------------------------------------------------------------------------*/
2022 #define dev_packet_id data[0]
2023 #define frame_errors data[1]
2026 * NetChip framing of ethernet packets, supporting additional error
2027 * checks for links that may drop bulk packets from inside messages.
2028 * Odd USB length == always short read for last usb packet.
2030 * - Ethernet header (14 bytes)
2032 * - (optional padding byte, if needed so length becomes odd)
2035 * This framing is to be avoided for non-NetChip devices.
2038 struct nc_header
{ // packed:
2039 __le16 hdr_len
; // sizeof nc_header (LE, all)
2040 __le16 packet_len
; // payload size (including ethhdr)
2041 __le16 packet_id
; // detects dropped packets
2042 #define MIN_HEADER 6
2044 // all else is optional, and must start with:
2045 // u16 vendorId; // from usb-if
2047 } __attribute__((__packed__
));
2049 #define PAD_BYTE ((unsigned char)0xAC)
2053 } __attribute__((__packed__
));
2055 // packets may use FLAG_FRAMING_NC and optional pad
2056 #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
2057 + sizeof (struct ethhdr) \
2060 + sizeof (struct nc_trailer))
2062 #define MIN_FRAMED FRAMED_SIZE(0)
2066 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
2067 * before the hardware drops it. If that's done, the driver will need to
2068 * frame network packets to guard against the dropped USB packets. The win32
2069 * driver sets this for both sides of the link.
2071 #define NC_READ_TTL_MS ((u8)255) // ms
2074 * We ignore most registers and EEPROM contents.
2076 #define REG_USBCTL ((u8)0x04)
2077 #define REG_TTL ((u8)0x10)
2078 #define REG_STATUS ((u8)0x11)
2081 * Vendor specific requests to read/write data
2083 #define REQUEST_REGISTER ((u8)0x10)
2084 #define REQUEST_EEPROM ((u8)0x11)
2087 nc_vendor_read (struct usbnet
*dev
, u8 req
, u8 regnum
, u16
*retval_ptr
)
2089 int status
= usb_control_msg (dev
->udev
,
2090 usb_rcvctrlpipe (dev
->udev
, 0),
2092 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
2094 retval_ptr
, sizeof *retval_ptr
,
2095 CONTROL_TIMEOUT_MS
);
2099 le16_to_cpus (retval_ptr
);
2104 nc_register_read (struct usbnet
*dev
, u8 regnum
, u16
*retval_ptr
)
2106 return nc_vendor_read (dev
, REQUEST_REGISTER
, regnum
, retval_ptr
);
2109 // no retval ... can become async, usable in_interrupt()
2111 nc_vendor_write (struct usbnet
*dev
, u8 req
, u8 regnum
, u16 value
)
2113 usb_control_msg (dev
->udev
,
2114 usb_sndctrlpipe (dev
->udev
, 0),
2116 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
2118 NULL
, 0, // data is in setup packet
2119 CONTROL_TIMEOUT_MS
);
2123 nc_register_write (struct usbnet
*dev
, u8 regnum
, u16 value
)
2125 nc_vendor_write (dev
, REQUEST_REGISTER
, regnum
, value
);
2130 static void nc_dump_registers (struct usbnet
*dev
)
2133 u16
*vp
= kmalloc (sizeof (u16
));
2140 dbg ("%s registers:", dev
->net
->name
);
2141 for (reg
= 0; reg
< 0x20; reg
++) {
2144 // reading some registers is trouble
2145 if (reg
>= 0x08 && reg
<= 0xf)
2147 if (reg
>= 0x12 && reg
<= 0x1e)
2150 retval
= nc_register_read (dev
, reg
, vp
);
2152 dbg ("%s reg [0x%x] ==> error %d",
2153 dev
->net
->name
, reg
, retval
);
2155 dbg ("%s reg [0x%x] = 0x%x",
2156 dev
->net
->name
, reg
, *vp
);
2163 /*-------------------------------------------------------------------------*/
2169 #define USBCTL_WRITABLE_MASK 0x1f0f
2170 // bits 15-13 reserved, r/o
2171 #define USBCTL_ENABLE_LANG (1 << 12)
2172 #define USBCTL_ENABLE_MFGR (1 << 11)
2173 #define USBCTL_ENABLE_PROD (1 << 10)
2174 #define USBCTL_ENABLE_SERIAL (1 << 9)
2175 #define USBCTL_ENABLE_DEFAULTS (1 << 8)
2176 // bits 7-4 reserved, r/o
2177 #define USBCTL_FLUSH_OTHER (1 << 3)
2178 #define USBCTL_FLUSH_THIS (1 << 2)
2179 #define USBCTL_DISCONN_OTHER (1 << 1)
2180 #define USBCTL_DISCONN_THIS (1 << 0)
2182 static inline void nc_dump_usbctl (struct usbnet
*dev
, u16 usbctl
)
2184 if (!netif_msg_link (dev
))
2186 devdbg (dev
, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
2188 " other%s%s; r/o 0x%x",
2189 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
,
2191 (usbctl
& USBCTL_ENABLE_LANG
) ? " lang" : "",
2192 (usbctl
& USBCTL_ENABLE_MFGR
) ? " mfgr" : "",
2193 (usbctl
& USBCTL_ENABLE_PROD
) ? " prod" : "",
2194 (usbctl
& USBCTL_ENABLE_SERIAL
) ? " serial" : "",
2195 (usbctl
& USBCTL_ENABLE_DEFAULTS
) ? " defaults" : "",
2197 (usbctl
& USBCTL_FLUSH_OTHER
) ? " FLUSH" : "",
2198 (usbctl
& USBCTL_DISCONN_OTHER
) ? " DIS" : "",
2199 (usbctl
& USBCTL_FLUSH_THIS
) ? " FLUSH" : "",
2200 (usbctl
& USBCTL_DISCONN_THIS
) ? " DIS" : "",
2201 usbctl
& ~USBCTL_WRITABLE_MASK
2205 /*-------------------------------------------------------------------------*/
2211 #define STATUS_PORT_A (1 << 15)
2213 #define STATUS_CONN_OTHER (1 << 14)
2214 #define STATUS_SUSPEND_OTHER (1 << 13)
2215 #define STATUS_MAILBOX_OTHER (1 << 12)
2216 #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
2218 #define STATUS_CONN_THIS (1 << 6)
2219 #define STATUS_SUSPEND_THIS (1 << 5)
2220 #define STATUS_MAILBOX_THIS (1 << 4)
2221 #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
2223 #define STATUS_UNSPEC_MASK 0x0c8c
2224 #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
2227 static inline void nc_dump_status (struct usbnet
*dev
, u16 status
)
2229 if (!netif_msg_link (dev
))
2231 devdbg (dev
, "net1080 %s-%s status 0x%x:"
2232 " this (%c) PKT=%d%s%s%s;"
2233 " other PKT=%d%s%s%s; unspec 0x%x",
2234 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
,
2237 // XXX the packet counts don't seem right
2238 // (1 at reset, not 0); maybe UNSPEC too
2240 (status
& STATUS_PORT_A
) ? 'A' : 'B',
2241 STATUS_PACKETS_THIS (status
),
2242 (status
& STATUS_CONN_THIS
) ? " CON" : "",
2243 (status
& STATUS_SUSPEND_THIS
) ? " SUS" : "",
2244 (status
& STATUS_MAILBOX_THIS
) ? " MBOX" : "",
2246 STATUS_PACKETS_OTHER (status
),
2247 (status
& STATUS_CONN_OTHER
) ? " CON" : "",
2248 (status
& STATUS_SUSPEND_OTHER
) ? " SUS" : "",
2249 (status
& STATUS_MAILBOX_OTHER
) ? " MBOX" : "",
2251 status
& STATUS_UNSPEC_MASK
2255 /*-------------------------------------------------------------------------*/
2261 #define TTL_THIS(ttl) (0x00ff & ttl)
2262 #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
2263 #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
2265 static inline void nc_dump_ttl (struct usbnet
*dev
, u16 ttl
)
2267 if (netif_msg_link (dev
))
2268 devdbg (dev
, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
2269 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
,
2270 ttl
, TTL_THIS (ttl
), TTL_OTHER (ttl
));
2273 /*-------------------------------------------------------------------------*/
2275 static int net1080_reset (struct usbnet
*dev
)
2277 u16 usbctl
, status
, ttl
;
2278 u16
*vp
= kmalloc (sizeof (u16
), GFP_KERNEL
);
2284 // nc_dump_registers (dev);
2286 if ((retval
= nc_register_read (dev
, REG_STATUS
, vp
)) < 0) {
2287 dbg ("can't read %s-%s status: %d",
2288 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
, retval
);
2292 nc_dump_status (dev
, status
);
2294 if ((retval
= nc_register_read (dev
, REG_USBCTL
, vp
)) < 0) {
2295 dbg ("can't read USBCTL, %d", retval
);
2299 nc_dump_usbctl (dev
, usbctl
);
2301 nc_register_write (dev
, REG_USBCTL
,
2302 USBCTL_FLUSH_THIS
| USBCTL_FLUSH_OTHER
);
2304 if ((retval
= nc_register_read (dev
, REG_TTL
, vp
)) < 0) {
2305 dbg ("can't read TTL, %d", retval
);
2309 // nc_dump_ttl (dev, ttl);
2311 nc_register_write (dev
, REG_TTL
,
2312 MK_TTL (NC_READ_TTL_MS
, TTL_OTHER (ttl
)) );
2313 dbg ("%s: assigned TTL, %d ms", dev
->net
->name
, NC_READ_TTL_MS
);
2315 if (netif_msg_link (dev
))
2316 devinfo (dev
, "port %c, peer %sconnected",
2317 (status
& STATUS_PORT_A
) ? 'A' : 'B',
2318 (status
& STATUS_CONN_OTHER
) ? "" : "dis"
2327 static int net1080_check_connect (struct usbnet
*dev
)
2331 u16
*vp
= kmalloc (sizeof (u16
), GFP_KERNEL
);
2335 retval
= nc_register_read (dev
, REG_STATUS
, vp
);
2339 dbg ("%s net1080_check_conn read - %d", dev
->net
->name
, retval
);
2342 if ((status
& STATUS_CONN_OTHER
) != STATUS_CONN_OTHER
)
2347 static void nc_flush_complete (struct urb
*urb
, struct pt_regs
*regs
)
2349 kfree (urb
->context
);
2353 static void nc_ensure_sync (struct usbnet
*dev
)
2355 dev
->frame_errors
++;
2356 if (dev
->frame_errors
> 5) {
2358 struct usb_ctrlrequest
*req
;
2362 urb
= usb_alloc_urb (0, SLAB_ATOMIC
);
2366 req
= kmalloc (sizeof *req
, GFP_ATOMIC
);
2372 req
->bRequestType
= USB_DIR_OUT
2375 req
->bRequest
= REQUEST_REGISTER
;
2376 req
->wValue
= cpu_to_le16 (USBCTL_FLUSH_THIS
2377 | USBCTL_FLUSH_OTHER
);
2378 req
->wIndex
= cpu_to_le16 (REG_USBCTL
);
2379 req
->wLength
= cpu_to_le16 (0);
2381 /* queue an async control request, we don't need
2382 * to do anything when it finishes except clean up.
2384 usb_fill_control_urb (urb
, dev
->udev
,
2385 usb_sndctrlpipe (dev
->udev
, 0),
2386 (unsigned char *) req
,
2388 nc_flush_complete
, req
);
2389 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
2396 if (netif_msg_rx_err (dev
))
2397 devdbg (dev
, "flush net1080; too many framing errors");
2398 dev
->frame_errors
= 0;
2402 static int net1080_rx_fixup (struct usbnet
*dev
, struct sk_buff
*skb
)
2404 struct nc_header
*header
;
2405 struct nc_trailer
*trailer
;
2406 u16 hdr_len
, packet_len
;
2408 if (!(skb
->len
& 0x01)
2409 || MIN_FRAMED
> skb
->len
2410 || skb
->len
> FRAMED_SIZE (dev
->net
->mtu
)) {
2411 dev
->stats
.rx_frame_errors
++;
2412 dbg ("rx framesize %d range %d..%d mtu %d", skb
->len
,
2413 (int)MIN_FRAMED
, (int)FRAMED_SIZE (dev
->net
->mtu
),
2415 nc_ensure_sync (dev
);
2419 header
= (struct nc_header
*) skb
->data
;
2420 hdr_len
= le16_to_cpup (&header
->hdr_len
);
2421 packet_len
= le16_to_cpup (&header
->packet_len
);
2422 if (FRAMED_SIZE (packet_len
) > MAX_PACKET
) {
2423 dev
->stats
.rx_frame_errors
++;
2424 dbg ("packet too big, %d", packet_len
);
2425 nc_ensure_sync (dev
);
2427 } else if (hdr_len
< MIN_HEADER
) {
2428 dev
->stats
.rx_frame_errors
++;
2429 dbg ("header too short, %d", hdr_len
);
2430 nc_ensure_sync (dev
);
2432 } else if (hdr_len
> MIN_HEADER
) {
2433 // out of band data for us?
2434 dbg ("header OOB, %d bytes", hdr_len
- MIN_HEADER
);
2435 nc_ensure_sync (dev
);
2436 // switch (vendor/product ids) { ... }
2438 skb_pull (skb
, hdr_len
);
2440 trailer
= (struct nc_trailer
*)
2441 (skb
->data
+ skb
->len
- sizeof *trailer
);
2442 skb_trim (skb
, skb
->len
- sizeof *trailer
);
2444 if ((packet_len
& 0x01) == 0) {
2445 if (skb
->data
[packet_len
] != PAD_BYTE
) {
2446 dev
->stats
.rx_frame_errors
++;
2450 skb_trim (skb
, skb
->len
- 1);
2452 if (skb
->len
!= packet_len
) {
2453 dev
->stats
.rx_frame_errors
++;
2454 dbg ("bad packet len %d (expected %d)",
2455 skb
->len
, packet_len
);
2456 nc_ensure_sync (dev
);
2459 if (header
->packet_id
!= get_unaligned (&trailer
->packet_id
)) {
2460 dev
->stats
.rx_fifo_errors
++;
2461 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2462 le16_to_cpu (header
->packet_id
),
2463 le16_to_cpu (trailer
->packet_id
));
2467 devdbg (dev
, "frame <rx h %d p %d id %d", header
->hdr_len
,
2468 header
->packet_len
, header
->packet_id
);
2470 dev
->frame_errors
= 0;
2474 static struct sk_buff
*
2475 net1080_tx_fixup (struct usbnet
*dev
, struct sk_buff
*skb
, int flags
)
2478 struct sk_buff
*skb2
;
2480 padlen
= ((skb
->len
+ sizeof (struct nc_header
)
2481 + sizeof (struct nc_trailer
)) & 0x01) ? 0 : 1;
2482 if (!skb_cloned (skb
)) {
2483 int headroom
= skb_headroom (skb
);
2484 int tailroom
= skb_tailroom (skb
);
2486 if ((padlen
+ sizeof (struct nc_trailer
)) <= tailroom
2487 && sizeof (struct nc_header
) <= headroom
)
2488 /* There's enough head and tail room */
2491 if ((sizeof (struct nc_header
) + padlen
2492 + sizeof (struct nc_trailer
)) <
2493 (headroom
+ tailroom
)) {
2494 /* There's enough total room, so just readjust */
2495 skb
->data
= memmove (skb
->head
2496 + sizeof (struct nc_header
),
2497 skb
->data
, skb
->len
);
2498 skb
->tail
= skb
->data
+ skb
->len
;
2503 /* Create a new skb to use with the correct size */
2504 skb2
= skb_copy_expand (skb
,
2505 sizeof (struct nc_header
),
2506 sizeof (struct nc_trailer
) + padlen
,
2508 dev_kfree_skb_any (skb
);
2512 static const struct driver_info net1080_info
= {
2513 .description
= "NetChip TurboCONNECT",
2514 .flags
= FLAG_FRAMING_NC
,
2515 .reset
= net1080_reset
,
2516 .check_connect
=net1080_check_connect
,
2517 .rx_fixup
= net1080_rx_fixup
,
2518 .tx_fixup
= net1080_tx_fixup
,
2521 #endif /* CONFIG_USB_NET1080 */
2525 #ifdef CONFIG_USB_PL2301
2526 #define HAVE_HARDWARE
2528 /*-------------------------------------------------------------------------
2530 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2532 * The protocol and handshaking used here should be bug-compatible
2533 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2535 *-------------------------------------------------------------------------*/
2538 * Bits 0-4 can be used for software handshaking; they're set from
2539 * one end, cleared from the other, "read" with the interrupt byte.
2541 #define PL_S_EN (1<<7) /* (feature only) suspend enable */
2542 /* reserved bit -- rx ready (6) ? */
2543 #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2544 #define PL_RESET_OUT (1<<4) /* reset output pipe */
2545 #define PL_RESET_IN (1<<3) /* reset input pipe */
2546 #define PL_TX_C (1<<2) /* transmission complete */
2547 #define PL_TX_REQ (1<<1) /* transmission received */
2548 #define PL_PEER_E (1<<0) /* peer exists */
2551 pl_vendor_req (struct usbnet
*dev
, u8 req
, u8 val
, u8 index
)
2553 return usb_control_msg (dev
->udev
,
2554 usb_rcvctrlpipe (dev
->udev
, 0),
2556 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
2559 CONTROL_TIMEOUT_MS
);
2563 pl_clear_QuickLink_features (struct usbnet
*dev
, int val
)
2565 return pl_vendor_req (dev
, 1, (u8
) val
, 0);
2569 pl_set_QuickLink_features (struct usbnet
*dev
, int val
)
2571 return pl_vendor_req (dev
, 3, (u8
) val
, 0);
2574 /*-------------------------------------------------------------------------*/
2576 static int pl_reset (struct usbnet
*dev
)
2578 /* some units seem to need this reset, others reject it utterly.
2579 * FIXME be more like "naplink" or windows drivers.
2581 (void) pl_set_QuickLink_features (dev
,
2582 PL_S_EN
|PL_RESET_OUT
|PL_RESET_IN
|PL_PEER_E
);
2586 static const struct driver_info prolific_info
= {
2587 .description
= "Prolific PL-2301/PL-2302",
2588 .flags
= FLAG_NO_SETINT
,
2589 /* some PL-2302 versions seem to fail usb_set_interface() */
2593 #endif /* CONFIG_USB_PL2301 */
2596 #ifdef CONFIG_USB_KC2190
2597 #define HAVE_HARDWARE
2598 static const struct driver_info kc2190_info
= {
2599 .description
= "KC Technology KC-190",
2601 #endif /* CONFIG_USB_KC2190 */
2604 #ifdef CONFIG_USB_ARMLINUX
2605 #define HAVE_HARDWARE
2607 /*-------------------------------------------------------------------------
2609 * Intel's SA-1100 chip integrates basic USB support, and is used
2610 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2611 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2612 * network using minimal USB framing data.
2614 * This describes the driver currently in standard ARM Linux kernels.
2615 * The Zaurus uses a different driver (see later).
2617 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2618 * and different USB endpoint numbering than the SA1100 devices. The
2619 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2620 * so we rely on the endpoint descriptors.
2622 *-------------------------------------------------------------------------*/
2624 static const struct driver_info linuxdev_info
= {
2625 .description
= "Linux Device",
2626 .check_connect
= always_connected
,
2629 static const struct driver_info yopy_info
= {
2630 .description
= "Yopy",
2631 .check_connect
= always_connected
,
2634 static const struct driver_info blob_info
= {
2635 .description
= "Boot Loader OBject",
2636 .check_connect
= always_connected
,
2639 #endif /* CONFIG_USB_ARMLINUX */
2642 #ifdef CONFIG_USB_ZAURUS
2643 #define HAVE_HARDWARE
2645 #include <linux/crc32.h>
2647 /*-------------------------------------------------------------------------
2649 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2650 * (and framing) for its USB slave/gadget controller than the case above.
2652 * For the current version of that driver, the main way that framing is
2653 * nonstandard (also from perspective of the CDC ethernet model!) is a
2654 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2655 * haven't been fully worked around. Also, all Zaurii use the same
2656 * default Ethernet address.
2658 * PXA based models use the same framing, and also can't implement
2659 * set_interface properly.
2661 * All known Zaurii lie about their standards conformance. Most lie by
2662 * saying they support CDC Ethernet. Some lie and say they support CDC
2663 * MDLM (as if for access to cell phone modems). Someone, please beat
2664 * on Sharp for a while with a cluestick.
2666 *-------------------------------------------------------------------------*/
2668 static struct sk_buff
*
2669 zaurus_tx_fixup (struct usbnet
*dev
, struct sk_buff
*skb
, int flags
)
2672 struct sk_buff
*skb2
;
2675 if (!skb_cloned (skb
)) {
2676 int tailroom
= skb_tailroom (skb
);
2677 if ((padlen
+ 4) <= tailroom
)
2680 skb2
= skb_copy_expand (skb
, 0, 4 + padlen
, flags
);
2681 dev_kfree_skb_any (skb
);
2686 fcs
= crc32_le (~0, skb
->data
, skb
->len
);
2689 *skb_put (skb
, 1) = fcs
& 0xff;
2690 *skb_put (skb
, 1) = (fcs
>> 8) & 0xff;
2691 *skb_put (skb
, 1) = (fcs
>>16) & 0xff;
2692 *skb_put (skb
, 1) = (fcs
>>24) & 0xff;
2697 static const struct driver_info zaurus_sl5x00_info
= {
2698 .description
= "Sharp Zaurus SL-5x00",
2699 .flags
= FLAG_FRAMING_Z
,
2700 .check_connect
= always_connected
,
2701 .bind
= generic_cdc_bind
,
2702 .unbind
= cdc_unbind
,
2703 .tx_fixup
= zaurus_tx_fixup
,
2705 #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2707 static const struct driver_info zaurus_pxa_info
= {
2708 .description
= "Sharp Zaurus, PXA-2xx based",
2709 .flags
= FLAG_FRAMING_Z
,
2710 .check_connect
= always_connected
,
2711 .bind
= generic_cdc_bind
,
2712 .unbind
= cdc_unbind
,
2713 .tx_fixup
= zaurus_tx_fixup
,
2715 #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2717 static const struct driver_info zaurus_pxa_mdlm_info
= {
2718 .description
= "Sharp Zaurus, PXA-255 based",
2719 .flags
= FLAG_FRAMING_Z
,
2720 .check_connect
= always_connected
,
2721 .tx_fixup
= zaurus_tx_fixup
,
2724 static const struct driver_info olympus_mxl_info
= {
2725 .description
= "Olympus R1000",
2726 .flags
= FLAG_FRAMING_Z
,
2727 .check_connect
= always_connected
,
2728 .bind
= generic_cdc_bind
,
2729 .unbind
= cdc_unbind
,
2730 .tx_fixup
= zaurus_tx_fixup
,
2732 #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2736 /* blacklist all those devices */
2737 #define ZAURUS_STRONGARM_INFO 0
2738 #define ZAURUS_PXA_INFO 0
2739 #define OLYMPUS_MXL_INFO 0
2744 /*-------------------------------------------------------------------------
2746 * Network Device Driver (peer link to "Host Device", from USB host)
2748 *-------------------------------------------------------------------------*/
2750 static int usbnet_change_mtu (struct net_device
*net
, int new_mtu
)
2752 struct usbnet
*dev
= netdev_priv(net
);
2754 if (new_mtu
<= MIN_PACKET
|| new_mtu
> MAX_PACKET
)
2756 #ifdef CONFIG_USB_NET1080
2757 if (((dev
->driver_info
->flags
) & FLAG_FRAMING_NC
)) {
2758 if (FRAMED_SIZE (new_mtu
) > MAX_PACKET
)
2762 #ifdef CONFIG_USB_GENESYS
2763 if (((dev
->driver_info
->flags
) & FLAG_FRAMING_GL
)
2764 && new_mtu
> GL_MAX_PACKET_LEN
)
2767 // no second zero-length packet read wanted after mtu-sized packets
2768 if (((new_mtu
+ sizeof (struct ethhdr
)) % dev
->maxpacket
) == 0)
2774 /*-------------------------------------------------------------------------*/
2776 static struct net_device_stats
*usbnet_get_stats (struct net_device
*net
)
2778 struct usbnet
*dev
= netdev_priv(net
);
2782 /*-------------------------------------------------------------------------*/
2784 /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
2785 * completion callbacks. 2.5 should have fixed those bugs...
2788 static void defer_bh (struct usbnet
*dev
, struct sk_buff
*skb
)
2790 struct sk_buff_head
*list
= skb
->list
;
2791 unsigned long flags
;
2793 spin_lock_irqsave (&list
->lock
, flags
);
2794 __skb_unlink (skb
, list
);
2795 spin_unlock (&list
->lock
);
2796 spin_lock (&dev
->done
.lock
);
2797 __skb_queue_tail (&dev
->done
, skb
);
2798 if (dev
->done
.qlen
== 1)
2799 tasklet_schedule (&dev
->bh
);
2800 spin_unlock_irqrestore (&dev
->done
.lock
, flags
);
2803 /* some work can't be done in tasklets, so we use keventd
2805 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2806 * but tasklet_schedule() doesn't. hope the failure is rare.
2808 static void defer_kevent (struct usbnet
*dev
, int work
)
2810 set_bit (work
, &dev
->flags
);
2811 if (!schedule_work (&dev
->kevent
))
2812 deverr (dev
, "kevent %d may have been dropped", work
);
2814 devdbg (dev
, "kevent %d scheduled", work
);
2817 /*-------------------------------------------------------------------------*/
2819 static void rx_complete (struct urb
*urb
, struct pt_regs
*regs
);
2821 static void rx_submit (struct usbnet
*dev
, struct urb
*urb
, int flags
)
2823 struct sk_buff
*skb
;
2824 struct skb_data
*entry
;
2826 unsigned long lockflags
;
2829 #ifdef CONFIG_USB_NET1080
2830 if (dev
->driver_info
->flags
& FLAG_FRAMING_NC
)
2831 size
= FRAMED_SIZE (dev
->net
->mtu
);
2834 #ifdef CONFIG_USB_GENESYS
2835 if (dev
->driver_info
->flags
& FLAG_FRAMING_GL
)
2836 size
= GL_RCV_BUF_SIZE
;
2839 #ifdef CONFIG_USB_ZAURUS
2840 if (dev
->driver_info
->flags
& FLAG_FRAMING_Z
)
2841 size
= 6 + (sizeof (struct ethhdr
) + dev
->net
->mtu
);
2844 #ifdef CONFIG_USB_RNDIS
2845 if (dev
->driver_info
->flags
& FLAG_FRAMING_RN
)
2846 size
= RNDIS_MAX_TRANSFER
;
2849 #ifdef CONFIG_USB_AX8817X
2850 if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
)
2854 size
= (sizeof (struct ethhdr
) + dev
->net
->mtu
);
2856 if ((skb
= alloc_skb (size
+ NET_IP_ALIGN
, flags
)) == NULL
) {
2857 if (netif_msg_rx_err (dev
))
2858 devdbg (dev
, "no rx skb");
2859 defer_kevent (dev
, EVENT_RX_MEMORY
);
2863 skb_reserve (skb
, NET_IP_ALIGN
);
2865 entry
= (struct skb_data
*) skb
->cb
;
2868 entry
->state
= rx_start
;
2871 usb_fill_bulk_urb (urb
, dev
->udev
, dev
->in
,
2872 skb
->data
, size
, rx_complete
, skb
);
2873 urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
2875 spin_lock_irqsave (&dev
->rxq
.lock
, lockflags
);
2877 if (netif_running (dev
->net
)
2878 && netif_device_present (dev
->net
)
2879 && !test_bit (EVENT_RX_HALT
, &dev
->flags
)) {
2880 switch (retval
= usb_submit_urb (urb
, GFP_ATOMIC
)){
2882 defer_kevent (dev
, EVENT_RX_HALT
);
2885 defer_kevent (dev
, EVENT_RX_MEMORY
);
2888 if (netif_msg_ifdown (dev
))
2889 devdbg (dev
, "device gone");
2890 netif_device_detach (dev
->net
);
2893 if (netif_msg_rx_err (dev
))
2894 devdbg (dev
, "rx submit, %d", retval
);
2895 tasklet_schedule (&dev
->bh
);
2898 __skb_queue_tail (&dev
->rxq
, skb
);
2901 if (netif_msg_ifdown (dev
))
2902 devdbg (dev
, "rx: stopped");
2905 spin_unlock_irqrestore (&dev
->rxq
.lock
, lockflags
);
2907 dev_kfree_skb_any (skb
);
2913 /*-------------------------------------------------------------------------*/
2915 static inline void rx_process (struct usbnet
*dev
, struct sk_buff
*skb
)
2917 if (dev
->driver_info
->rx_fixup
2918 && !dev
->driver_info
->rx_fixup (dev
, skb
))
2920 // else network stack removes extra byte if we forced a short packet
2923 skb_return (dev
, skb
);
2925 if (netif_msg_rx_err (dev
))
2926 devdbg (dev
, "drop");
2928 dev
->stats
.rx_errors
++;
2929 skb_queue_tail (&dev
->done
, skb
);
2933 /*-------------------------------------------------------------------------*/
2935 static void rx_complete (struct urb
*urb
, struct pt_regs
*regs
)
2937 struct sk_buff
*skb
= (struct sk_buff
*) urb
->context
;
2938 struct skb_data
*entry
= (struct skb_data
*) skb
->cb
;
2939 struct usbnet
*dev
= entry
->dev
;
2940 int urb_status
= urb
->status
;
2942 skb_put (skb
, urb
->actual_length
);
2943 entry
->state
= rx_done
;
2946 switch (urb_status
) {
2949 if (MIN_PACKET
> skb
->len
|| skb
->len
> MAX_PACKET
) {
2950 entry
->state
= rx_cleanup
;
2951 dev
->stats
.rx_errors
++;
2952 dev
->stats
.rx_length_errors
++;
2953 if (netif_msg_rx_err (dev
))
2954 devdbg (dev
, "rx length %d", skb
->len
);
2958 // stalls need manual reset. this is rare ... except that
2959 // when going through USB 2.0 TTs, unplug appears this way.
2960 // we avoid the highspeed version of the ETIMEOUT/EILSEQ
2961 // storm, recovering as needed.
2963 dev
->stats
.rx_errors
++;
2964 defer_kevent (dev
, EVENT_RX_HALT
);
2967 // software-driven interface shutdown
2968 case -ECONNRESET
: // async unlink
2969 case -ESHUTDOWN
: // hardware gone
2970 if (netif_msg_ifdown (dev
))
2971 devdbg (dev
, "rx shutdown, code %d", urb_status
);
2974 // we get controller i/o faults during khubd disconnect() delays.
2975 // throttle down resubmits, to avoid log floods; just temporarily,
2976 // so we still recover when the fault isn't a khubd delay.
2977 case -EPROTO
: // ehci
2978 case -ETIMEDOUT
: // ohci
2979 case -EILSEQ
: // uhci
2980 dev
->stats
.rx_errors
++;
2981 if (!timer_pending (&dev
->delay
)) {
2982 mod_timer (&dev
->delay
, jiffies
+ THROTTLE_JIFFIES
);
2983 if (netif_msg_link (dev
))
2984 devdbg (dev
, "rx throttle %d", urb_status
);
2987 entry
->state
= rx_cleanup
;
2992 // data overrun ... flush fifo?
2994 dev
->stats
.rx_over_errors
++;
2998 entry
->state
= rx_cleanup
;
2999 dev
->stats
.rx_errors
++;
3000 if (netif_msg_rx_err (dev
))
3001 devdbg (dev
, "rx status %d", urb_status
);
3005 defer_bh (dev
, skb
);
3008 if (netif_running (dev
->net
)
3009 && !test_bit (EVENT_RX_HALT
, &dev
->flags
)) {
3010 rx_submit (dev
, urb
, GFP_ATOMIC
);
3015 if (netif_msg_rx_err (dev
))
3016 devdbg (dev
, "no read resubmitted");
3019 static void intr_complete (struct urb
*urb
, struct pt_regs
*regs
)
3021 struct usbnet
*dev
= urb
->context
;
3022 int status
= urb
->status
;
3027 dev
->driver_info
->status(dev
, urb
);
3030 /* software-driven interface shutdown */
3031 case -ENOENT
: // urb killed
3032 case -ESHUTDOWN
: // hardware gone
3033 if (netif_msg_ifdown (dev
))
3034 devdbg (dev
, "intr shutdown, code %d", status
);
3037 /* NOTE: not throttling like RX/TX, since this endpoint
3038 * already polls infrequently
3041 devdbg (dev
, "intr status %d", status
);
3045 if (!netif_running (dev
->net
))
3048 memset(urb
->transfer_buffer
, 0, urb
->transfer_buffer_length
);
3049 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
3050 if (status
!= 0 && netif_msg_timer (dev
))
3051 deverr(dev
, "intr resubmit --> %d", status
);
3054 /*-------------------------------------------------------------------------*/
3056 // unlink pending rx/tx; completion handlers do all other cleanup
3058 static int unlink_urbs (struct usbnet
*dev
, struct sk_buff_head
*q
)
3060 unsigned long flags
;
3061 struct sk_buff
*skb
, *skbnext
;
3064 spin_lock_irqsave (&q
->lock
, flags
);
3065 for (skb
= q
->next
; skb
!= (struct sk_buff
*) q
; skb
= skbnext
) {
3066 struct skb_data
*entry
;
3070 entry
= (struct skb_data
*) skb
->cb
;
3072 skbnext
= skb
->next
;
3074 // during some PM-driven resume scenarios,
3075 // these (async) unlinks complete immediately
3076 retval
= usb_unlink_urb (urb
);
3077 if (retval
!= -EINPROGRESS
&& retval
!= 0)
3078 devdbg (dev
, "unlink urb err, %d", retval
);
3082 spin_unlock_irqrestore (&q
->lock
, flags
);
3087 /*-------------------------------------------------------------------------*/
3089 // precondition: never called in_interrupt
3091 static int usbnet_stop (struct net_device
*net
)
3093 struct usbnet
*dev
= netdev_priv(net
);
3095 DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup
);
3096 DECLARE_WAITQUEUE (wait
, current
);
3098 netif_stop_queue (net
);
3100 if (netif_msg_ifdown (dev
))
3101 devinfo (dev
, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
3102 dev
->stats
.rx_packets
, dev
->stats
.tx_packets
,
3103 dev
->stats
.rx_errors
, dev
->stats
.tx_errors
3106 // ensure there are no more active urbs
3107 add_wait_queue (&unlink_wakeup
, &wait
);
3108 dev
->wait
= &unlink_wakeup
;
3109 temp
= unlink_urbs (dev
, &dev
->txq
) + unlink_urbs (dev
, &dev
->rxq
);
3111 // maybe wait for deletions to finish.
3112 while (skb_queue_len (&dev
->rxq
)
3113 && skb_queue_len (&dev
->txq
)
3114 && skb_queue_len (&dev
->done
)) {
3115 msleep(UNLINK_TIMEOUT_MS
);
3116 if (netif_msg_ifdown (dev
))
3117 devdbg (dev
, "waited for %d urb completions", temp
);
3120 remove_wait_queue (&unlink_wakeup
, &wait
);
3122 usb_kill_urb(dev
->interrupt
);
3124 /* deferred work (task, timer, softirq) must also stop.
3125 * can't flush_scheduled_work() until we drop rtnl (later),
3126 * else workers could deadlock; so make workers a NOP.
3129 del_timer_sync (&dev
->delay
);
3130 tasklet_kill (&dev
->bh
);
3135 /*-------------------------------------------------------------------------*/
3137 // posts reads, and enables write queuing
3139 // precondition: never called in_interrupt
3141 static int usbnet_open (struct net_device
*net
)
3143 struct usbnet
*dev
= netdev_priv(net
);
3145 struct driver_info
*info
= dev
->driver_info
;
3147 // put into "known safe" state
3148 if (info
->reset
&& (retval
= info
->reset (dev
)) < 0) {
3149 if (netif_msg_ifup (dev
))
3151 "open reset fail (%d) usbnet usb-%s-%s, %s",
3153 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
,
3158 // insist peer be connected
3159 if (info
->check_connect
&& (retval
= info
->check_connect (dev
)) < 0) {
3160 if (netif_msg_ifup (dev
))
3161 devdbg (dev
, "can't open; %d", retval
);
3165 /* start any status interrupt transfer */
3166 if (dev
->interrupt
) {
3167 retval
= usb_submit_urb (dev
->interrupt
, GFP_KERNEL
);
3169 if (netif_msg_ifup (dev
))
3170 deverr (dev
, "intr submit %d", retval
);
3175 netif_start_queue (net
);
3176 if (netif_msg_ifup (dev
)) {
3179 if (dev
->driver_info
->flags
& FLAG_FRAMING_NC
)
3180 framing
= "NetChip";
3181 else if (dev
->driver_info
->flags
& FLAG_FRAMING_GL
)
3182 framing
= "GeneSys";
3183 else if (dev
->driver_info
->flags
& FLAG_FRAMING_Z
)
3185 else if (dev
->driver_info
->flags
& FLAG_FRAMING_RN
)
3187 else if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
)
3192 devinfo (dev
, "open: enable queueing "
3193 "(rx %d, tx %d) mtu %d %s framing",
3194 RX_QLEN (dev
), TX_QLEN (dev
), dev
->net
->mtu
,
3198 // delay posting reads until we're fully open
3199 tasklet_schedule (&dev
->bh
);
3204 /*-------------------------------------------------------------------------*/
3206 static void usbnet_get_drvinfo (struct net_device
*net
, struct ethtool_drvinfo
*info
)
3208 struct usbnet
*dev
= netdev_priv(net
);
3210 strncpy (info
->driver
, driver_name
, sizeof info
->driver
);
3211 strncpy (info
->version
, DRIVER_VERSION
, sizeof info
->version
);
3212 strncpy (info
->fw_version
, dev
->driver_info
->description
,
3213 sizeof info
->fw_version
);
3214 usb_make_path (dev
->udev
, info
->bus_info
, sizeof info
->bus_info
);
3217 static u32
usbnet_get_link (struct net_device
*net
)
3219 struct usbnet
*dev
= netdev_priv(net
);
3221 /* If a check_connect is defined, return it's results */
3222 if (dev
->driver_info
->check_connect
)
3223 return dev
->driver_info
->check_connect (dev
) == 0;
3225 /* Otherwise, we're up to avoid breaking scripts */
3229 static u32
usbnet_get_msglevel (struct net_device
*net
)
3231 struct usbnet
*dev
= netdev_priv(net
);
3233 return dev
->msg_enable
;
3236 static void usbnet_set_msglevel (struct net_device
*net
, u32 level
)
3238 struct usbnet
*dev
= netdev_priv(net
);
3240 dev
->msg_enable
= level
;
3243 static int usbnet_ioctl (struct net_device
*net
, struct ifreq
*rq
, int cmd
)
3247 struct usbnet
*dev
= netdev_priv(net
);
3249 if (dev
->mii
.mdio_read
!= NULL
&& dev
->mii
.mdio_write
!= NULL
)
3250 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
3256 /*-------------------------------------------------------------------------*/
3258 /* work that cannot be done in interrupt context uses keventd.
3260 * NOTE: with 2.5 we could do more of this using completion callbacks,
3261 * especially now that control transfers can be queued.
3266 struct usbnet
*dev
= data
;
3269 /* usb_clear_halt() needs a thread context */
3270 if (test_bit (EVENT_TX_HALT
, &dev
->flags
)) {
3271 unlink_urbs (dev
, &dev
->txq
);
3272 status
= usb_clear_halt (dev
->udev
, dev
->out
);
3273 if (status
< 0 && status
!= -EPIPE
) {
3274 if (netif_msg_tx_err (dev
))
3275 deverr (dev
, "can't clear tx halt, status %d",
3278 clear_bit (EVENT_TX_HALT
, &dev
->flags
);
3279 netif_wake_queue (dev
->net
);
3282 if (test_bit (EVENT_RX_HALT
, &dev
->flags
)) {
3283 unlink_urbs (dev
, &dev
->rxq
);
3284 status
= usb_clear_halt (dev
->udev
, dev
->in
);
3285 if (status
< 0 && status
!= -EPIPE
) {
3286 if (netif_msg_rx_err (dev
))
3287 deverr (dev
, "can't clear rx halt, status %d",
3290 clear_bit (EVENT_RX_HALT
, &dev
->flags
);
3291 tasklet_schedule (&dev
->bh
);
3295 /* tasklet could resubmit itself forever if memory is tight */
3296 if (test_bit (EVENT_RX_MEMORY
, &dev
->flags
)) {
3297 struct urb
*urb
= NULL
;
3299 if (netif_running (dev
->net
))
3300 urb
= usb_alloc_urb (0, GFP_KERNEL
);
3302 clear_bit (EVENT_RX_MEMORY
, &dev
->flags
);
3304 clear_bit (EVENT_RX_MEMORY
, &dev
->flags
);
3305 rx_submit (dev
, urb
, GFP_KERNEL
);
3306 tasklet_schedule (&dev
->bh
);
3311 devdbg (dev
, "kevent done, flags = 0x%lx",
3315 /*-------------------------------------------------------------------------*/
3317 static void tx_complete (struct urb
*urb
, struct pt_regs
*regs
)
3319 struct sk_buff
*skb
= (struct sk_buff
*) urb
->context
;
3320 struct skb_data
*entry
= (struct skb_data
*) skb
->cb
;
3321 struct usbnet
*dev
= entry
->dev
;
3323 if (urb
->status
== 0) {
3324 dev
->stats
.tx_packets
++;
3325 dev
->stats
.tx_bytes
+= entry
->length
;
3327 dev
->stats
.tx_errors
++;
3329 switch (urb
->status
) {
3331 defer_kevent (dev
, EVENT_TX_HALT
);
3334 /* software-driven interface shutdown */
3335 case -ECONNRESET
: // async unlink
3336 case -ESHUTDOWN
: // hardware gone
3339 // like rx, tx gets controller i/o faults during khubd delays
3340 // and so it uses the same throttling mechanism.
3341 case -EPROTO
: // ehci
3342 case -ETIMEDOUT
: // ohci
3343 case -EILSEQ
: // uhci
3344 if (!timer_pending (&dev
->delay
)) {
3345 mod_timer (&dev
->delay
,
3346 jiffies
+ THROTTLE_JIFFIES
);
3347 if (netif_msg_link (dev
))
3348 devdbg (dev
, "tx throttle %d",
3351 netif_stop_queue (dev
->net
);
3354 if (netif_msg_tx_err (dev
))
3355 devdbg (dev
, "tx err %d", entry
->urb
->status
);
3361 entry
->state
= tx_done
;
3362 defer_bh (dev
, skb
);
3365 /*-------------------------------------------------------------------------*/
3367 static void usbnet_tx_timeout (struct net_device
*net
)
3369 struct usbnet
*dev
= netdev_priv(net
);
3371 unlink_urbs (dev
, &dev
->txq
);
3372 tasklet_schedule (&dev
->bh
);
3374 // FIXME: device recovery -- reset?
3377 /*-------------------------------------------------------------------------*/
3379 static int usbnet_start_xmit (struct sk_buff
*skb
, struct net_device
*net
)
3381 struct usbnet
*dev
= netdev_priv(net
);
3383 int retval
= NET_XMIT_SUCCESS
;
3384 struct urb
*urb
= NULL
;
3385 struct skb_data
*entry
;
3386 struct driver_info
*info
= dev
->driver_info
;
3387 unsigned long flags
;
3388 #ifdef CONFIG_USB_NET1080
3389 struct nc_header
*header
= NULL
;
3390 struct nc_trailer
*trailer
= NULL
;
3391 #endif /* CONFIG_USB_NET1080 */
3393 // some devices want funky USB-level framing, for
3394 // win32 driver (usually) and/or hardware quirks
3395 if (info
->tx_fixup
) {
3396 skb
= info
->tx_fixup (dev
, skb
, GFP_ATOMIC
);
3398 if (netif_msg_tx_err (dev
))
3399 devdbg (dev
, "can't tx_fixup skb");
3405 if (!(urb
= usb_alloc_urb (0, GFP_ATOMIC
))) {
3406 if (netif_msg_tx_err (dev
))
3407 devdbg (dev
, "no urb");
3411 entry
= (struct skb_data
*) skb
->cb
;
3414 entry
->state
= tx_start
;
3415 entry
->length
= length
;
3417 // FIXME: reorganize a bit, so that fixup() fills out NetChip
3418 // framing too. (Packet ID update needs the spinlock...)
3419 // [ BETTER: we already own net->xmit_lock, that's enough ]
3421 #ifdef CONFIG_USB_NET1080
3422 if (info
->flags
& FLAG_FRAMING_NC
) {
3423 header
= (struct nc_header
*) skb_push (skb
, sizeof *header
);
3424 header
->hdr_len
= cpu_to_le16 (sizeof (*header
));
3425 header
->packet_len
= cpu_to_le16 (length
);
3426 if (!((skb
->len
+ sizeof *trailer
) & 0x01))
3427 *skb_put (skb
, 1) = PAD_BYTE
;
3428 trailer
= (struct nc_trailer
*) skb_put (skb
, sizeof *trailer
);
3430 #endif /* CONFIG_USB_NET1080 */
3432 usb_fill_bulk_urb (urb
, dev
->udev
, dev
->out
,
3433 skb
->data
, skb
->len
, tx_complete
, skb
);
3434 urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
3436 /* don't assume the hardware handles USB_ZERO_PACKET
3437 * NOTE: strictly conforming cdc-ether devices should expect
3438 * the ZLP here, but ignore the one-byte packet.
3440 * FIXME zero that byte, if it doesn't require a new skb.
3442 if ((length
% dev
->maxpacket
) == 0)
3443 urb
->transfer_buffer_length
++;
3445 spin_lock_irqsave (&dev
->txq
.lock
, flags
);
3447 #ifdef CONFIG_USB_NET1080
3448 if (info
->flags
& FLAG_FRAMING_NC
) {
3449 header
->packet_id
= cpu_to_le16 ((u16
)dev
->dev_packet_id
++);
3450 put_unaligned (header
->packet_id
, &trailer
->packet_id
);
3452 devdbg (dev
, "frame >tx h %d p %d id %d",
3453 header
->hdr_len
, header
->packet_len
,
3457 #endif /* CONFIG_USB_NET1080 */
3459 switch ((retval
= usb_submit_urb (urb
, GFP_ATOMIC
))) {
3461 netif_stop_queue (net
);
3462 defer_kevent (dev
, EVENT_TX_HALT
);
3465 if (netif_msg_tx_err (dev
))
3466 devdbg (dev
, "tx: submit urb err %d", retval
);
3469 net
->trans_start
= jiffies
;
3470 __skb_queue_tail (&dev
->txq
, skb
);
3471 if (dev
->txq
.qlen
>= TX_QLEN (dev
))
3472 netif_stop_queue (net
);
3474 spin_unlock_irqrestore (&dev
->txq
.lock
, flags
);
3477 if (netif_msg_tx_err (dev
))
3478 devdbg (dev
, "drop, code %d", retval
);
3480 retval
= NET_XMIT_SUCCESS
;
3481 dev
->stats
.tx_dropped
++;
3483 dev_kfree_skb_any (skb
);
3485 } else if (netif_msg_tx_queued (dev
)) {
3486 devdbg (dev
, "> tx, len %d, type 0x%x",
3487 length
, skb
->protocol
);
3493 /*-------------------------------------------------------------------------*/
3495 // tasklet (work deferred from completions, in_irq) or timer
3497 static void usbnet_bh (unsigned long param
)
3499 struct usbnet
*dev
= (struct usbnet
*) param
;
3500 struct sk_buff
*skb
;
3501 struct skb_data
*entry
;
3503 while ((skb
= skb_dequeue (&dev
->done
))) {
3504 entry
= (struct skb_data
*) skb
->cb
;
3505 switch (entry
->state
) {
3507 entry
->state
= rx_cleanup
;
3508 rx_process (dev
, skb
);
3512 usb_free_urb (entry
->urb
);
3513 dev_kfree_skb (skb
);
3516 devdbg (dev
, "bogus skb state %d", entry
->state
);
3520 // waiting for all pending urbs to complete?
3522 if ((dev
->txq
.qlen
+ dev
->rxq
.qlen
+ dev
->done
.qlen
) == 0) {
3523 wake_up (dev
->wait
);
3526 // or are we maybe short a few urbs?
3527 } else if (netif_running (dev
->net
)
3528 && netif_device_present (dev
->net
)
3529 && !timer_pending (&dev
->delay
)
3530 && !test_bit (EVENT_RX_HALT
, &dev
->flags
)) {
3531 int temp
= dev
->rxq
.qlen
;
3532 int qlen
= RX_QLEN (dev
);
3538 // don't refill the queue all at once
3539 for (i
= 0; i
< 10 && dev
->rxq
.qlen
< qlen
; i
++) {
3540 urb
= usb_alloc_urb (0, GFP_ATOMIC
);
3542 rx_submit (dev
, urb
, GFP_ATOMIC
);
3544 if (temp
!= dev
->rxq
.qlen
&& netif_msg_link (dev
))
3545 devdbg (dev
, "rxqlen %d --> %d",
3546 temp
, dev
->rxq
.qlen
);
3547 if (dev
->rxq
.qlen
< qlen
)
3548 tasklet_schedule (&dev
->bh
);
3550 if (dev
->txq
.qlen
< TX_QLEN (dev
))
3551 netif_wake_queue (dev
->net
);
3557 /*-------------------------------------------------------------------------
3559 * USB Device Driver support
3561 *-------------------------------------------------------------------------*/
3563 // precondition: never called in_interrupt
3565 static void usbnet_disconnect (struct usb_interface
*intf
)
3568 struct usb_device
*xdev
;
3569 struct net_device
*net
;
3571 dev
= usb_get_intfdata(intf
);
3572 usb_set_intfdata(intf
, NULL
);
3576 xdev
= interface_to_usbdev (intf
);
3578 if (netif_msg_probe (dev
))
3579 devinfo (dev
, "unregister usbnet usb-%s-%s, %s",
3580 xdev
->bus
->bus_name
, xdev
->devpath
,
3581 dev
->driver_info
->description
);
3584 unregister_netdev (net
);
3586 /* we don't hold rtnl here ... */
3587 flush_scheduled_work ();
3589 if (dev
->driver_info
->unbind
)
3590 dev
->driver_info
->unbind (dev
, intf
);
3597 /*-------------------------------------------------------------------------*/
3599 static struct ethtool_ops usbnet_ethtool_ops
;
3601 // precondition: never called in_interrupt
3604 usbnet_probe (struct usb_interface
*udev
, const struct usb_device_id
*prod
)
3607 struct net_device
*net
;
3608 struct usb_host_interface
*interface
;
3609 struct driver_info
*info
;
3610 struct usb_device
*xdev
;
3613 info
= (struct driver_info
*) prod
->driver_info
;
3615 dev_dbg (&udev
->dev
, "blacklisted by %s\n", driver_name
);
3618 xdev
= interface_to_usbdev (udev
);
3619 interface
= udev
->cur_altsetting
;
3625 // set up our own records
3626 net
= alloc_etherdev(sizeof(*dev
));
3628 dbg ("can't kmalloc dev");
3632 dev
= netdev_priv(net
);
3634 dev
->driver_info
= info
;
3635 dev
->msg_enable
= netif_msg_init (msg_level
, NETIF_MSG_DRV
3636 | NETIF_MSG_PROBE
| NETIF_MSG_LINK
);
3637 skb_queue_head_init (&dev
->rxq
);
3638 skb_queue_head_init (&dev
->txq
);
3639 skb_queue_head_init (&dev
->done
);
3640 dev
->bh
.func
= usbnet_bh
;
3641 dev
->bh
.data
= (unsigned long) dev
;
3642 INIT_WORK (&dev
->kevent
, kevent
, dev
);
3643 dev
->delay
.function
= usbnet_bh
;
3644 dev
->delay
.data
= (unsigned long) dev
;
3645 init_timer (&dev
->delay
);
3647 SET_MODULE_OWNER (net
);
3649 strcpy (net
->name
, "usb%d");
3650 memcpy (net
->dev_addr
, node_id
, sizeof node_id
);
3653 // dma_supported() is deeply broken on almost all architectures
3654 // possible with some EHCI controllers
3655 if (dma_supported (&udev
->dev
, DMA_64BIT_MASK
))
3656 net
->features
|= NETIF_F_HIGHDMA
;
3659 net
->change_mtu
= usbnet_change_mtu
;
3660 net
->get_stats
= usbnet_get_stats
;
3661 net
->hard_start_xmit
= usbnet_start_xmit
;
3662 net
->open
= usbnet_open
;
3663 net
->stop
= usbnet_stop
;
3664 net
->watchdog_timeo
= TX_TIMEOUT_JIFFIES
;
3665 net
->tx_timeout
= usbnet_tx_timeout
;
3666 net
->do_ioctl
= usbnet_ioctl
;
3667 net
->ethtool_ops
= &usbnet_ethtool_ops
;
3669 // allow device-specific bind/init procedures
3670 // NOTE net->name still not usable ...
3672 status
= info
->bind (dev
, udev
);
3673 // heuristic: "usb%d" for links we know are two-host,
3674 // else "eth%d" when there's reasonable doubt. userspace
3675 // can rename the link if it knows better.
3676 if ((dev
->driver_info
->flags
& FLAG_ETHER
) != 0
3677 && (net
->dev_addr
[0] & 0x02) == 0)
3678 strcpy (net
->name
, "eth%d");
3679 } else if (!info
->in
|| info
->out
)
3680 status
= get_endpoints (dev
, udev
);
3682 dev
->in
= usb_rcvbulkpipe (xdev
, info
->in
);
3683 dev
->out
= usb_sndbulkpipe (xdev
, info
->out
);
3684 if (!(info
->flags
& FLAG_NO_SETINT
))
3685 status
= usb_set_interface (xdev
,
3686 interface
->desc
.bInterfaceNumber
,
3687 interface
->desc
.bAlternateSetting
);
3693 if (status
== 0 && dev
->status
)
3694 status
= init_status (dev
, udev
);
3698 dev
->maxpacket
= usb_maxpacket (dev
->udev
, dev
->out
, 1);
3700 SET_NETDEV_DEV(net
, &udev
->dev
);
3701 status
= register_netdev (net
);
3704 if (netif_msg_probe (dev
))
3705 devinfo (dev
, "register usbnet at usb-%s-%s, %s, "
3706 "%02x:%02x:%02x:%02x:%02x:%02x",
3707 xdev
->bus
->bus_name
, xdev
->devpath
,
3708 dev
->driver_info
->description
,
3709 net
->dev_addr
[0], net
->dev_addr
[1],
3710 net
->dev_addr
[2], net
->dev_addr
[3],
3711 net
->dev_addr
[4], net
->dev_addr
[5]);
3713 // ok, it's ready to go.
3714 usb_set_intfdata (udev
, dev
);
3716 // start as if the link is up
3717 netif_device_attach (net
);
3723 info
->unbind (dev
, udev
);
3731 /*-------------------------------------------------------------------------*/
3735 static int usbnet_suspend (struct usb_interface
*intf
, pm_message_t message
)
3737 struct usbnet
*dev
= usb_get_intfdata(intf
);
3739 /* accelerate emptying of the rx and queues, to avoid
3740 * having everything error out.
3742 netif_device_detach (dev
->net
);
3743 (void) unlink_urbs (dev
, &dev
->rxq
);
3744 (void) unlink_urbs (dev
, &dev
->txq
);
3745 intf
->dev
.power
.power_state
= PMSG_SUSPEND
;
3749 static int usbnet_resume (struct usb_interface
*intf
)
3751 struct usbnet
*dev
= usb_get_intfdata(intf
);
3753 intf
->dev
.power
.power_state
= PMSG_ON
;
3754 netif_device_attach (dev
->net
);
3755 tasklet_schedule (&dev
->bh
);
3759 #else /* !CONFIG_PM */
3761 #define usbnet_suspend NULL
3762 #define usbnet_resume NULL
3764 #endif /* CONFIG_PM */
3766 /*-------------------------------------------------------------------------*/
3768 #ifndef HAVE_HARDWARE
3769 #error You need to configure some hardware for this driver
3773 * chip vendor names won't normally be on the cables, and
3774 * may not be on the device.
3777 static const struct usb_device_id products
[] = {
3779 #ifdef CONFIG_USB_ALI_M5632
3781 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3782 .driver_info
= (unsigned long) &ali_m5632_info
,
3786 #ifdef CONFIG_USB_AN2720
3788 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3789 .driver_info
= (unsigned long) &an2720_info
,
3791 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3792 .driver_info
= (unsigned long) &an2720_info
,
3796 #ifdef CONFIG_USB_BELKIN
3798 USB_DEVICE (0x050d, 0x0004), // Belkin
3799 .driver_info
= (unsigned long) &belkin_info
,
3801 USB_DEVICE (0x056c, 0x8100), // eTEK
3802 .driver_info
= (unsigned long) &belkin_info
,
3804 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3805 .driver_info
= (unsigned long) &belkin_info
,
3809 #ifdef CONFIG_USB_AX8817X
3812 USB_DEVICE (0x077b, 0x2226),
3813 .driver_info
= (unsigned long) &ax8817x_info
,
3816 USB_DEVICE (0x0846, 0x1040),
3817 .driver_info
= (unsigned long) &netgear_fa120_info
,
3820 USB_DEVICE (0x2001, 0x1a00),
3821 .driver_info
= (unsigned long) &dlink_dub_e100_info
,
3823 // Intellinet, ST Lab USB Ethernet
3824 USB_DEVICE (0x0b95, 0x1720),
3825 .driver_info
= (unsigned long) &ax8817x_info
,
3827 // Hawking UF200, TrendNet TU2-ET100
3828 USB_DEVICE (0x07b8, 0x420a),
3829 .driver_info
= (unsigned long) &hawking_uf200_info
,
3831 // Billionton Systems, USB2AR
3832 USB_DEVICE (0x08dd, 0x90ff),
3833 .driver_info
= (unsigned long) &ax8817x_info
,
3836 USB_DEVICE (0x0557, 0x2009),
3837 .driver_info
= (unsigned long) &ax8817x_info
,
3839 // Buffalo LUA-U2-KTX
3840 USB_DEVICE (0x0411, 0x003d),
3841 .driver_info
= (unsigned long) &ax8817x_info
,
3843 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3844 USB_DEVICE (0x6189, 0x182d),
3845 .driver_info
= (unsigned long) &ax8817x_info
,
3847 // corega FEther USB2-TX
3848 USB_DEVICE (0x07aa, 0x0017),
3849 .driver_info
= (unsigned long) &ax8817x_info
,
3851 // Surecom EP-1427X-2
3852 USB_DEVICE (0x1189, 0x0893),
3853 .driver_info
= (unsigned long) &ax8817x_info
,
3855 // goodway corp usb gwusb2e
3856 USB_DEVICE (0x1631, 0x6200),
3857 .driver_info
= (unsigned long) &ax8817x_info
,
3859 // ASIX AX88772 10/100
3860 USB_DEVICE (0x0b95, 0x7720),
3861 .driver_info
= (unsigned long) &ax88772_info
,
3865 #ifdef CONFIG_USB_EPSON2888
3867 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3868 .driver_info
= (unsigned long) &epson2888_info
,
3872 #ifdef CONFIG_USB_GENESYS
3874 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
3875 .driver_info
= (unsigned long) &genelink_info
,
3877 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
3878 * that's half duplex, not currently supported
3882 #ifdef CONFIG_USB_NET1080
3884 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
3885 .driver_info
= (unsigned long) &net1080_info
,
3887 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
3888 .driver_info
= (unsigned long) &net1080_info
,
3892 #ifdef CONFIG_USB_PL2301
3894 USB_DEVICE (0x067b, 0x0000), // PL-2301
3895 .driver_info
= (unsigned long) &prolific_info
,
3897 USB_DEVICE (0x067b, 0x0001), // PL-2302
3898 .driver_info
= (unsigned long) &prolific_info
,
3902 #ifdef CONFIG_USB_KC2190
3904 USB_DEVICE (0x050f, 0x0190), // KC-190
3905 .driver_info
= (unsigned long) &kc2190_info
,
3909 #ifdef CONFIG_USB_RNDIS
3911 /* RNDIS is MSFT's un-official variant of CDC ACM */
3912 USB_INTERFACE_INFO (USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3913 .driver_info
= (unsigned long) &rndis_info
,
3917 #ifdef CONFIG_USB_ARMLINUX
3919 * SA-1100 using standard ARM Linux kernels, or compatible.
3920 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
3921 * The sa-1100 "usb-eth" driver handles the basic framing.
3923 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
3924 * the sa1100 one, but hardware uses different endpoint numbers.
3926 * Or the Linux "Ethernet" gadget on hardware that can't talk
3927 * CDC Ethernet (e.g., no altsettings), in either of two modes:
3928 * - acting just like the old "usb-eth" firmware, though
3929 * the implementation is different
3930 * - supporting RNDIS as the first/default configuration for
3931 * MS-Windows interop; Linux needs to use the other config
3934 // 1183 = 0x049F, both used as hex values?
3935 // Compaq "Itsy" vendor/product id
3936 USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
3937 .driver_info
= (unsigned long) &linuxdev_info
,
3939 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
3940 .driver_info
= (unsigned long) &yopy_info
,
3942 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
3943 .driver_info
= (unsigned long) &blob_info
,
3945 // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
3946 // e.g. Gumstix, current OpenZaurus, ...
3947 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
3948 .driver_info
= (unsigned long) &linuxdev_info
,
3952 #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
3954 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
3955 * Same idea as above, but different framing.
3957 * PXA-2xx based models are also lying-about-cdc.
3958 * Some models don't even tell the same lies ...
3960 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
3961 * unlike the older ones with 2.4 "embedix" kernels.
3963 * NOTE: These entries do double-duty, serving as blacklist entries
3964 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
3966 #define ZAURUS_MASTER_INTERFACE \
3967 .bInterfaceClass = USB_CLASS_COMM, \
3968 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
3969 .bInterfaceProtocol = USB_CDC_PROTO_NONE
3971 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3972 | USB_DEVICE_ID_MATCH_DEVICE
,
3974 .idProduct
= 0x8004,
3975 ZAURUS_MASTER_INTERFACE
,
3976 .driver_info
= ZAURUS_STRONGARM_INFO
,
3978 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3979 | USB_DEVICE_ID_MATCH_DEVICE
,
3981 .idProduct
= 0x8005, /* A-300 */
3982 ZAURUS_MASTER_INTERFACE
,
3983 .driver_info
= ZAURUS_PXA_INFO
,
3985 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3986 | USB_DEVICE_ID_MATCH_DEVICE
,
3988 .idProduct
= 0x8006, /* B-500/SL-5600 */
3989 ZAURUS_MASTER_INTERFACE
,
3990 .driver_info
= ZAURUS_PXA_INFO
,
3992 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3993 | USB_DEVICE_ID_MATCH_DEVICE
,
3995 .idProduct
= 0x8007, /* C-700 */
3996 ZAURUS_MASTER_INTERFACE
,
3997 .driver_info
= ZAURUS_PXA_INFO
,
3999 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
4000 | USB_DEVICE_ID_MATCH_DEVICE
,
4002 .idProduct
= 0x9031, /* C-750 C-760 */
4003 ZAURUS_MASTER_INTERFACE
,
4004 .driver_info
= ZAURUS_PXA_INFO
,
4006 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
4007 | USB_DEVICE_ID_MATCH_DEVICE
,
4009 .idProduct
= 0x9032, /* SL-6000 */
4010 ZAURUS_MASTER_INTERFACE
,
4011 .driver_info
= ZAURUS_PXA_INFO
,
4013 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
4014 | USB_DEVICE_ID_MATCH_DEVICE
,
4016 /* reported with some C860 units */
4017 .idProduct
= 0x9050, /* C-860 */
4018 ZAURUS_MASTER_INTERFACE
,
4019 .driver_info
= ZAURUS_PXA_INFO
,
4020 #ifdef CONFIG_USB_ZAURUS
4021 /* at least some (reports vary) C-860 units have very different
4022 * lies about their standards support.
4025 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
4026 | USB_DEVICE_ID_MATCH_DEVICE
,
4028 /* reported with some C860 units */
4029 .idProduct
= 0x9031, /* C-860 */
4030 .bInterfaceClass
= USB_CLASS_COMM
,
4031 .bInterfaceSubClass
= USB_CDC_SUBCLASS_MDLM
,
4032 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
4033 .driver_info
= (unsigned long) &zaurus_pxa_mdlm_info
,
4037 /* Olympus has some models with a Zaurus-compatible option.
4038 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
4041 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
4042 | USB_DEVICE_ID_MATCH_DEVICE
,
4044 .idProduct
= 0x0F02, /* R-1000 */
4045 ZAURUS_MASTER_INTERFACE
,
4046 .driver_info
= OLYMPUS_MXL_INFO
,
4050 #ifdef CONFIG_USB_CDCETHER
4052 /* CDC Ether uses two interfaces, not necessarily consecutive.
4053 * We match the main interface, ignoring the optional device
4054 * class so we could handle devices that aren't exclusively
4057 * NOTE: this match must come AFTER entries working around
4058 * bugs/quirks in a given product (like Zaurus, above).
4060 USB_INTERFACE_INFO (USB_CLASS_COMM
, USB_CDC_SUBCLASS_ETHERNET
,
4061 USB_CDC_PROTO_NONE
),
4062 .driver_info
= (unsigned long) &cdc_info
,
4068 MODULE_DEVICE_TABLE (usb
, products
);
4070 static struct usb_driver usbnet_driver
= {
4071 .owner
= THIS_MODULE
,
4072 .name
= driver_name
,
4073 .id_table
= products
,
4074 .probe
= usbnet_probe
,
4075 .disconnect
= usbnet_disconnect
,
4076 .suspend
= usbnet_suspend
,
4077 .resume
= usbnet_resume
,
4080 /* Default ethtool_ops assigned. Devices can override in their bind() routine */
4081 static struct ethtool_ops usbnet_ethtool_ops
= {
4082 .get_drvinfo
= usbnet_get_drvinfo
,
4083 .get_link
= usbnet_get_link
,
4084 .get_msglevel
= usbnet_get_msglevel
,
4085 .set_msglevel
= usbnet_set_msglevel
,
4088 /*-------------------------------------------------------------------------*/
4090 static int __init
usbnet_init (void)
4092 // compiler should optimize these out
4093 BUG_ON (sizeof (((struct sk_buff
*)0)->cb
)
4094 < sizeof (struct skb_data
));
4095 #ifdef CONFIG_USB_CDCETHER
4096 BUG_ON ((sizeof (((struct usbnet
*)0)->data
)
4097 < sizeof (struct cdc_state
)));
4100 random_ether_addr(node_id
);
4102 return usb_register(&usbnet_driver
);
4104 module_init (usbnet_init
);
4106 static void __exit
usbnet_exit (void)
4108 usb_deregister (&usbnet_driver
);
4110 module_exit (usbnet_exit
);
4112 MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>");
4113 MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)");
4114 MODULE_LICENSE ("GPL");