Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Networking Links |
| 3 | * Copyright (C) 2000-2003 by David Brownell <dbrownell@users.sourceforge.net> |
| 4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> |
| 5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> |
| 6 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> |
| 7 | * Copyright (c) 2002-2003 TiVo Inc. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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 |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * This is a generic "USB networking" framework that works with several |
| 26 | * kinds of full and high speed networking devices: |
| 27 | * |
| 28 | * + USB host-to-host "network cables", used for IP-over-USB links. |
| 29 | * These are often used for Laplink style connectivity products. |
| 30 | * - AnchorChip 2720 |
| 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 |
| 36 | * |
| 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 |
| 44 | * |
| 45 | * + Adapters to networks such as Ethernet. |
| 46 | * - AX8817X based USB 2.0 products |
| 47 | * |
| 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. |
| 51 | * |
| 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 |
| 57 | * within devices. |
| 58 | * |
| 59 | * |
| 60 | * CHANGELOG: |
| 61 | * |
| 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. |
| 70 | * |
| 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. |
| 91 | * |
| 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) |
| 103 | * |
| 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 |
| 110 | * (Neil Bortnak) |
| 111 | * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell) |
| 112 | * |
| 113 | * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis) |
| 114 | *-------------------------------------------------------------------------*/ |
| 115 | |
| 116 | // #define DEBUG // error path messages, extra info |
| 117 | // #define VERBOSE // more; success messages |
| 118 | |
| 119 | #include <linux/config.h> |
| 120 | #ifdef CONFIG_USB_DEBUG |
| 121 | # define DEBUG |
| 122 | #endif |
| 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> |
| 136 | #include <asm/io.h> |
| 137 | #include <asm/scatterlist.h> |
| 138 | #include <linux/mm.h> |
| 139 | #include <linux/dma-mapping.h> |
| 140 | |
| 141 | #define DRIVER_VERSION "03-Nov-2004" |
| 142 | |
| 143 | |
| 144 | /*-------------------------------------------------------------------------*/ |
| 145 | |
| 146 | /* |
| 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). |
| 152 | */ |
| 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) |
| 155 | |
| 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 |
| 160 | |
| 161 | // reawaken network queue this soon after stopping; else watchdog barks |
| 162 | #define TX_TIMEOUT_JIFFIES (5*HZ) |
| 163 | |
| 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) |
| 167 | |
| 168 | // for vendor-specific control operations |
| 169 | #define CONTROL_TIMEOUT_MS 500 |
| 170 | |
| 171 | // between wakeups |
| 172 | #define UNLINK_TIMEOUT_MS 3 |
| 173 | |
| 174 | /*-------------------------------------------------------------------------*/ |
| 175 | |
| 176 | // randomly generated ethernet address |
| 177 | static u8 node_id [ETH_ALEN]; |
| 178 | |
| 179 | // state we keep for each device we handle |
| 180 | struct usbnet { |
| 181 | // housekeeping |
| 182 | struct usb_device *udev; |
| 183 | struct driver_info *driver_info; |
| 184 | wait_queue_head_t *wait; |
| 185 | |
| 186 | // i/o info: pipes etc |
| 187 | unsigned in, out; |
| 188 | struct usb_host_endpoint *status; |
| 189 | unsigned maxpacket; |
| 190 | struct timer_list delay; |
| 191 | |
| 192 | // protocol/interface state |
| 193 | struct net_device *net; |
| 194 | struct net_device_stats stats; |
| 195 | int msg_enable; |
| 196 | unsigned long data [5]; |
| 197 | |
| 198 | struct mii_if_info mii; |
| 199 | |
| 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; |
| 206 | |
| 207 | struct work_struct kevent; |
| 208 | unsigned long flags; |
| 209 | # define EVENT_TX_HALT 0 |
| 210 | # define EVENT_RX_HALT 1 |
| 211 | # define EVENT_RX_MEMORY 2 |
| 212 | # define EVENT_STS_SPLIT 3 |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 213 | # define EVENT_LINK_RESET 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | // device-specific info used by the driver |
| 217 | struct driver_info { |
| 218 | char *description; |
| 219 | |
| 220 | int flags; |
| 221 | /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ |
| 222 | #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ |
| 223 | #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ |
| 224 | #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ |
| 225 | #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */ |
| 226 | |
| 227 | #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ |
| 228 | #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ |
| 229 | |
| 230 | #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ |
| 231 | |
| 232 | /* init device ... can sleep, or cause probe() failure */ |
| 233 | int (*bind)(struct usbnet *, struct usb_interface *); |
| 234 | |
| 235 | /* cleanup device ... can sleep, but can't fail */ |
| 236 | void (*unbind)(struct usbnet *, struct usb_interface *); |
| 237 | |
| 238 | /* reset device ... can sleep */ |
| 239 | int (*reset)(struct usbnet *); |
| 240 | |
| 241 | /* see if peer is connected ... can sleep */ |
| 242 | int (*check_connect)(struct usbnet *); |
| 243 | |
| 244 | /* for status polling */ |
| 245 | void (*status)(struct usbnet *, struct urb *); |
| 246 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 247 | /* link reset handling, called from defer_kevent */ |
| 248 | int (*link_reset)(struct usbnet *); |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /* fixup rx packet (strip framing) */ |
| 251 | int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb); |
| 252 | |
| 253 | /* fixup tx packet (add framing) */ |
| 254 | struct sk_buff *(*tx_fixup)(struct usbnet *dev, |
| 255 | struct sk_buff *skb, int flags); |
| 256 | |
| 257 | // FIXME -- also an interrupt mechanism |
| 258 | // useful for at least PL2301/2302 and GL620USB-A |
| 259 | // and CDC use them to report 'is it connected' changes |
| 260 | |
| 261 | /* for new devices, use the descriptor-reading code instead */ |
| 262 | int in; /* rx endpoint */ |
| 263 | int out; /* tx endpoint */ |
| 264 | |
| 265 | unsigned long data; /* Misc driver specific data */ |
| 266 | }; |
| 267 | |
| 268 | // we record the state for each of our queued skbs |
| 269 | enum skb_state { |
| 270 | illegal = 0, |
| 271 | tx_start, tx_done, |
| 272 | rx_start, rx_done, rx_cleanup |
| 273 | }; |
| 274 | |
| 275 | struct skb_data { // skb->cb is one of these |
| 276 | struct urb *urb; |
| 277 | struct usbnet *dev; |
| 278 | enum skb_state state; |
| 279 | size_t length; |
| 280 | }; |
| 281 | |
| 282 | static const char driver_name [] = "usbnet"; |
| 283 | |
| 284 | /* use ethtool to change the level for any given device */ |
| 285 | static int msg_level = -1; |
| 286 | module_param (msg_level, int, 0); |
| 287 | MODULE_PARM_DESC (msg_level, "Override default message level"); |
| 288 | |
| 289 | |
| 290 | #ifdef DEBUG |
| 291 | #define devdbg(usbnet, fmt, arg...) \ |
| 292 | printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg) |
| 293 | #else |
| 294 | #define devdbg(usbnet, fmt, arg...) do {} while(0) |
| 295 | #endif |
| 296 | |
| 297 | #define deverr(usbnet, fmt, arg...) \ |
| 298 | printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg) |
| 299 | #define devwarn(usbnet, fmt, arg...) \ |
| 300 | printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg) |
| 301 | |
| 302 | #define devinfo(usbnet, fmt, arg...) \ |
| 303 | printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \ |
| 304 | |
| 305 | /*-------------------------------------------------------------------------*/ |
| 306 | |
| 307 | static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); |
| 308 | static u32 usbnet_get_link (struct net_device *); |
| 309 | static u32 usbnet_get_msglevel (struct net_device *); |
| 310 | static void usbnet_set_msglevel (struct net_device *, u32); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 311 | static void defer_kevent (struct usbnet *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | /* mostly for PDA style devices, which are always connected if present */ |
| 314 | static int always_connected (struct usbnet *dev) |
| 315 | { |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ |
| 320 | static int |
| 321 | get_endpoints (struct usbnet *dev, struct usb_interface *intf) |
| 322 | { |
| 323 | int tmp; |
| 324 | struct usb_host_interface *alt = NULL; |
| 325 | struct usb_host_endpoint *in = NULL, *out = NULL; |
| 326 | struct usb_host_endpoint *status = NULL; |
| 327 | |
| 328 | for (tmp = 0; tmp < intf->num_altsetting; tmp++) { |
| 329 | unsigned ep; |
| 330 | |
| 331 | in = out = status = NULL; |
| 332 | alt = intf->altsetting + tmp; |
| 333 | |
| 334 | /* take the first altsetting with in-bulk + out-bulk; |
| 335 | * remember any status endpoint, just in case; |
| 336 | * ignore other endpoints and altsetttings. |
| 337 | */ |
| 338 | for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { |
| 339 | struct usb_host_endpoint *e; |
| 340 | int intr = 0; |
| 341 | |
| 342 | e = alt->endpoint + ep; |
| 343 | switch (e->desc.bmAttributes) { |
| 344 | case USB_ENDPOINT_XFER_INT: |
| 345 | if (!(e->desc.bEndpointAddress & USB_DIR_IN)) |
| 346 | continue; |
| 347 | intr = 1; |
| 348 | /* FALLTHROUGH */ |
| 349 | case USB_ENDPOINT_XFER_BULK: |
| 350 | break; |
| 351 | default: |
| 352 | continue; |
| 353 | } |
| 354 | if (e->desc.bEndpointAddress & USB_DIR_IN) { |
| 355 | if (!intr && !in) |
| 356 | in = e; |
| 357 | else if (intr && !status) |
| 358 | status = e; |
| 359 | } else { |
| 360 | if (!out) |
| 361 | out = e; |
| 362 | } |
| 363 | } |
| 364 | if (in && out) |
| 365 | break; |
| 366 | } |
| 367 | if (!alt || !in || !out) |
| 368 | return -EINVAL; |
| 369 | |
| 370 | if (alt->desc.bAlternateSetting != 0 |
| 371 | || !(dev->driver_info->flags & FLAG_NO_SETINT)) { |
| 372 | tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber, |
| 373 | alt->desc.bAlternateSetting); |
| 374 | if (tmp < 0) |
| 375 | return tmp; |
| 376 | } |
| 377 | |
| 378 | dev->in = usb_rcvbulkpipe (dev->udev, |
| 379 | in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 380 | dev->out = usb_sndbulkpipe (dev->udev, |
| 381 | out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 382 | dev->status = status; |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static void intr_complete (struct urb *urb, struct pt_regs *regs); |
| 387 | |
| 388 | static int init_status (struct usbnet *dev, struct usb_interface *intf) |
| 389 | { |
| 390 | char *buf = NULL; |
| 391 | unsigned pipe = 0; |
| 392 | unsigned maxp; |
| 393 | unsigned period; |
| 394 | |
| 395 | if (!dev->driver_info->status) |
| 396 | return 0; |
| 397 | |
| 398 | pipe = usb_rcvintpipe (dev->udev, |
| 399 | dev->status->desc.bEndpointAddress |
| 400 | & USB_ENDPOINT_NUMBER_MASK); |
| 401 | maxp = usb_maxpacket (dev->udev, pipe, 0); |
| 402 | |
| 403 | /* avoid 1 msec chatter: min 8 msec poll rate */ |
| 404 | period = max ((int) dev->status->desc.bInterval, |
| 405 | (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3); |
| 406 | |
| 407 | buf = kmalloc (maxp, SLAB_KERNEL); |
| 408 | if (buf) { |
| 409 | dev->interrupt = usb_alloc_urb (0, SLAB_KERNEL); |
| 410 | if (!dev->interrupt) { |
| 411 | kfree (buf); |
| 412 | return -ENOMEM; |
| 413 | } else { |
| 414 | usb_fill_int_urb(dev->interrupt, dev->udev, pipe, |
| 415 | buf, maxp, intr_complete, dev, period); |
| 416 | dev_dbg(&intf->dev, |
| 417 | "status ep%din, %d bytes period %d\n", |
| 418 | usb_pipeendpoint(pipe), maxp, period); |
| 419 | } |
| 420 | } |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static void skb_return (struct usbnet *dev, struct sk_buff *skb) |
| 425 | { |
| 426 | int status; |
| 427 | |
| 428 | skb->dev = dev->net; |
| 429 | skb->protocol = eth_type_trans (skb, dev->net); |
| 430 | dev->stats.rx_packets++; |
| 431 | dev->stats.rx_bytes += skb->len; |
| 432 | |
| 433 | if (netif_msg_rx_status (dev)) |
akpm@osdl.org | 403a981 | 2005-04-18 17:39:27 -0700 | [diff] [blame] | 434 | devdbg (dev, "< rx, len %zd, type 0x%x", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | skb->len + sizeof (struct ethhdr), skb->protocol); |
| 436 | memset (skb->cb, 0, sizeof (struct skb_data)); |
| 437 | status = netif_rx (skb); |
| 438 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) |
| 439 | devdbg (dev, "netif_rx status %d", status); |
| 440 | } |
| 441 | |
| 442 | |
| 443 | #ifdef CONFIG_USB_ALI_M5632 |
| 444 | #define HAVE_HARDWARE |
| 445 | |
| 446 | /*------------------------------------------------------------------------- |
| 447 | * |
| 448 | * ALi M5632 driver ... does high speed |
| 449 | * |
| 450 | *-------------------------------------------------------------------------*/ |
| 451 | |
| 452 | static const struct driver_info ali_m5632_info = { |
| 453 | .description = "ALi M5632", |
| 454 | }; |
| 455 | |
| 456 | |
| 457 | #endif |
| 458 | |
| 459 | |
| 460 | #ifdef CONFIG_USB_AN2720 |
| 461 | #define HAVE_HARDWARE |
| 462 | |
| 463 | /*------------------------------------------------------------------------- |
| 464 | * |
| 465 | * AnchorChips 2720 driver ... http://www.cypress.com |
| 466 | * |
| 467 | * This doesn't seem to have a way to detect whether the peer is |
| 468 | * connected, or need any reset handshaking. It's got pretty big |
| 469 | * internal buffers (handles most of a frame's worth of data). |
| 470 | * Chip data sheets don't describe any vendor control messages. |
| 471 | * |
| 472 | *-------------------------------------------------------------------------*/ |
| 473 | |
| 474 | static const struct driver_info an2720_info = { |
| 475 | .description = "AnchorChips/Cypress 2720", |
| 476 | // no reset available! |
| 477 | // no check_connect available! |
| 478 | |
| 479 | .in = 2, .out = 2, // direction distinguishes these |
| 480 | }; |
| 481 | |
| 482 | #endif /* CONFIG_USB_AN2720 */ |
| 483 | |
| 484 | |
| 485 | #ifdef CONFIG_USB_AX8817X |
| 486 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ |
| 487 | |
| 488 | #define HAVE_HARDWARE |
| 489 | #define NEED_MII |
| 490 | |
| 491 | #include <linux/crc32.h> |
| 492 | |
| 493 | #define AX_CMD_SET_SW_MII 0x06 |
| 494 | #define AX_CMD_READ_MII_REG 0x07 |
| 495 | #define AX_CMD_WRITE_MII_REG 0x08 |
| 496 | #define AX_CMD_SET_HW_MII 0x0a |
| 497 | #define AX_CMD_READ_EEPROM 0x0b |
| 498 | #define AX_CMD_WRITE_EEPROM 0x0c |
| 499 | #define AX_CMD_WRITE_ENABLE 0x0d |
| 500 | #define AX_CMD_WRITE_DISABLE 0x0e |
| 501 | #define AX_CMD_WRITE_RX_CTL 0x10 |
| 502 | #define AX_CMD_READ_IPG012 0x11 |
| 503 | #define AX_CMD_WRITE_IPG0 0x12 |
| 504 | #define AX_CMD_WRITE_IPG1 0x13 |
| 505 | #define AX_CMD_WRITE_IPG2 0x14 |
| 506 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 |
| 507 | #define AX_CMD_READ_NODE_ID 0x17 |
| 508 | #define AX_CMD_READ_PHY_ID 0x19 |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 509 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b |
| 511 | #define AX_CMD_READ_MONITOR_MODE 0x1c |
| 512 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d |
| 513 | #define AX_CMD_WRITE_GPIOS 0x1f |
| 514 | #define AX_CMD_SW_RESET 0x20 |
| 515 | #define AX_CMD_SW_PHY_STATUS 0x21 |
| 516 | #define AX_CMD_SW_PHY_SELECT 0x22 |
| 517 | #define AX88772_CMD_READ_NODE_ID 0x13 |
| 518 | |
| 519 | #define AX_MONITOR_MODE 0x01 |
| 520 | #define AX_MONITOR_LINK 0x02 |
| 521 | #define AX_MONITOR_MAGIC 0x04 |
| 522 | #define AX_MONITOR_HSFS 0x10 |
| 523 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 524 | /* AX88172 Medium Status Register values */ |
| 525 | #define AX_MEDIUM_FULL_DUPLEX 0x02 |
| 526 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 |
| 527 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | #define AX_MCAST_FILTER_SIZE 8 |
| 530 | #define AX_MAX_MCAST 64 |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | #define AX_EEPROM_LEN 0x40 |
| 533 | |
| 534 | #define AX_SWRESET_CLEAR 0x00 |
| 535 | #define AX_SWRESET_RR 0x01 |
| 536 | #define AX_SWRESET_RT 0x02 |
| 537 | #define AX_SWRESET_PRTE 0x04 |
| 538 | #define AX_SWRESET_PRL 0x08 |
| 539 | #define AX_SWRESET_BZ 0x10 |
| 540 | #define AX_SWRESET_IPRL 0x20 |
| 541 | #define AX_SWRESET_IPPD 0x40 |
| 542 | |
| 543 | #define AX88772_IPG0_DEFAULT 0x15 |
| 544 | #define AX88772_IPG1_DEFAULT 0x0c |
| 545 | #define AX88772_IPG2_DEFAULT 0x12 |
| 546 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 547 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 |
| 548 | #define AX88772_MEDIUM_RESERVED 0x0004 |
| 549 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 |
| 550 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 |
| 551 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 |
| 552 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 |
| 553 | #define AX88772_MEDIUM_100MB 0x0200 |
| 554 | #define AX88772_MEDIUM_DEFAULT \ |
| 555 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ |
| 556 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ |
| 557 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | #define AX_EEPROM_MAGIC 0xdeadbeef |
| 560 | |
| 561 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ |
| 562 | struct ax8817x_data { |
| 563 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | }; |
| 565 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 566 | struct ax88172_int_data { |
| 567 | u16 res1; |
| 568 | u8 link; |
| 569 | u16 res2; |
| 570 | u8 status; |
| 571 | u16 res3; |
| 572 | } __attribute__ ((packed)); |
| 573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, |
| 575 | u16 size, void *data) |
| 576 | { |
| 577 | return usb_control_msg( |
| 578 | dev->udev, |
| 579 | usb_rcvctrlpipe(dev->udev, 0), |
| 580 | cmd, |
| 581 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 582 | value, |
| 583 | index, |
| 584 | data, |
| 585 | size, |
| 586 | CONTROL_TIMEOUT_MS); |
| 587 | } |
| 588 | |
| 589 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, |
| 590 | u16 size, void *data) |
| 591 | { |
| 592 | return usb_control_msg( |
| 593 | dev->udev, |
| 594 | usb_sndctrlpipe(dev->udev, 0), |
| 595 | cmd, |
| 596 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 597 | value, |
| 598 | index, |
| 599 | data, |
| 600 | size, |
| 601 | CONTROL_TIMEOUT_MS); |
| 602 | } |
| 603 | |
| 604 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) |
| 605 | { |
| 606 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; |
| 607 | |
| 608 | if (urb->status < 0) |
| 609 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", |
| 610 | urb->status); |
| 611 | |
| 612 | kfree(req); |
| 613 | usb_free_urb(urb); |
| 614 | } |
| 615 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 616 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 618 | struct ax88172_int_data *event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int link; |
| 620 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 621 | if (urb->actual_length < 8) |
| 622 | return; |
| 623 | |
| 624 | event = urb->transfer_buffer; |
| 625 | link = event->link & 0x01; |
| 626 | if (netif_carrier_ok(dev->net) != link) { |
| 627 | if (link) { |
| 628 | netif_carrier_on(dev->net); |
| 629 | defer_kevent (dev, EVENT_LINK_RESET ); |
| 630 | } else |
| 631 | netif_carrier_off(dev->net); |
| 632 | devdbg(dev, "ax8817x - Link Status is: %d", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, |
| 637 | u16 size, void *data) |
| 638 | { |
| 639 | struct usb_ctrlrequest *req; |
| 640 | int status; |
| 641 | struct urb *urb; |
| 642 | |
| 643 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { |
| 644 | devdbg(dev, "Error allocating URB in write_cmd_async!"); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { |
| 649 | deverr(dev, "Failed to allocate memory for control request"); |
| 650 | usb_free_urb(urb); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; |
| 655 | req->bRequest = cmd; |
| 656 | req->wValue = cpu_to_le16(value); |
| 657 | req->wIndex = cpu_to_le16(index); |
| 658 | req->wLength = cpu_to_le16(size); |
| 659 | |
| 660 | usb_fill_control_urb(urb, dev->udev, |
| 661 | usb_sndctrlpipe(dev->udev, 0), |
| 662 | (void *)req, data, size, |
| 663 | ax8817x_async_cmd_callback, req); |
| 664 | |
| 665 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { |
| 666 | deverr(dev, "Error submitting the control message: status=%d", status); |
| 667 | kfree(req); |
| 668 | usb_free_urb(urb); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | static void ax8817x_set_multicast(struct net_device *net) |
| 673 | { |
| 674 | struct usbnet *dev = netdev_priv(net); |
| 675 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; |
| 676 | u8 rx_ctl = 0x8c; |
| 677 | |
| 678 | if (net->flags & IFF_PROMISC) { |
| 679 | rx_ctl |= 0x01; |
| 680 | } else if (net->flags & IFF_ALLMULTI |
| 681 | || net->mc_count > AX_MAX_MCAST) { |
| 682 | rx_ctl |= 0x02; |
| 683 | } else if (net->mc_count == 0) { |
| 684 | /* just broadcast and directed */ |
| 685 | } else { |
| 686 | /* We use the 20 byte dev->data |
| 687 | * for our 8 byte filter buffer |
| 688 | * to avoid allocating memory that |
| 689 | * is tricky to free later */ |
| 690 | struct dev_mc_list *mc_list = net->mc_list; |
| 691 | u32 crc_bits; |
| 692 | int i; |
| 693 | |
| 694 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); |
| 695 | |
| 696 | /* Build the multicast hash filter. */ |
| 697 | for (i = 0; i < net->mc_count; i++) { |
| 698 | crc_bits = |
| 699 | ether_crc(ETH_ALEN, |
| 700 | mc_list->dmi_addr) >> 26; |
| 701 | data->multi_filter[crc_bits >> 3] |= |
| 702 | 1 << (crc_bits & 7); |
| 703 | mc_list = mc_list->next; |
| 704 | } |
| 705 | |
| 706 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, |
| 707 | AX_MCAST_FILTER_SIZE, data->multi_filter); |
| 708 | |
| 709 | rx_ctl |= 0x10; |
| 710 | } |
| 711 | |
| 712 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); |
| 713 | } |
| 714 | |
| 715 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) |
| 716 | { |
| 717 | struct usbnet *dev = netdev_priv(netdev); |
| 718 | u16 res; |
| 719 | u8 buf[1]; |
| 720 | |
| 721 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); |
| 722 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); |
| 723 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); |
| 724 | |
| 725 | return res & 0xffff; |
| 726 | } |
| 727 | |
| 728 | static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) |
| 729 | { |
| 730 | struct usbnet *dev = netdev_priv(netdev); |
| 731 | u16 res = val; |
| 732 | u8 buf[1]; |
| 733 | |
| 734 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); |
| 735 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); |
| 736 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); |
| 737 | } |
| 738 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 739 | static int ax88172_link_reset(struct usbnet *dev) |
| 740 | { |
| 741 | u16 lpa; |
| 742 | u8 mode; |
| 743 | |
| 744 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; |
| 745 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); |
| 746 | if (lpa & LPA_DUPLEX) |
| 747 | mode |= AX_MEDIUM_FULL_DUPLEX; |
| 748 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) |
| 754 | { |
| 755 | struct usbnet *dev = netdev_priv(net); |
| 756 | u8 opt; |
| 757 | |
| 758 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { |
| 759 | wolinfo->supported = 0; |
| 760 | wolinfo->wolopts = 0; |
| 761 | return; |
| 762 | } |
| 763 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; |
| 764 | wolinfo->wolopts = 0; |
| 765 | if (opt & AX_MONITOR_MODE) { |
| 766 | if (opt & AX_MONITOR_LINK) |
| 767 | wolinfo->wolopts |= WAKE_PHY; |
| 768 | if (opt & AX_MONITOR_MAGIC) |
| 769 | wolinfo->wolopts |= WAKE_MAGIC; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) |
| 774 | { |
| 775 | struct usbnet *dev = netdev_priv(net); |
| 776 | u8 opt = 0; |
| 777 | u8 buf[1]; |
| 778 | |
| 779 | if (wolinfo->wolopts & WAKE_PHY) |
| 780 | opt |= AX_MONITOR_LINK; |
| 781 | if (wolinfo->wolopts & WAKE_MAGIC) |
| 782 | opt |= AX_MONITOR_MAGIC; |
| 783 | if (opt != 0) |
| 784 | opt |= AX_MONITOR_MODE; |
| 785 | |
| 786 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, |
| 787 | opt, 0, 0, &buf) < 0) |
| 788 | return -EINVAL; |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | static int ax8817x_get_eeprom_len(struct net_device *net) |
| 794 | { |
| 795 | return AX_EEPROM_LEN; |
| 796 | } |
| 797 | |
| 798 | static int ax8817x_get_eeprom(struct net_device *net, |
| 799 | struct ethtool_eeprom *eeprom, u8 *data) |
| 800 | { |
| 801 | struct usbnet *dev = netdev_priv(net); |
| 802 | u16 *ebuf = (u16 *)data; |
| 803 | int i; |
| 804 | |
| 805 | /* Crude hack to ensure that we don't overwrite memory |
| 806 | * if an odd length is supplied |
| 807 | */ |
| 808 | if (eeprom->len % 2) |
| 809 | return -EINVAL; |
| 810 | |
| 811 | eeprom->magic = AX_EEPROM_MAGIC; |
| 812 | |
| 813 | /* ax8817x returns 2 bytes from eeprom on read */ |
| 814 | for (i=0; i < eeprom->len / 2; i++) { |
| 815 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, |
| 816 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) |
| 817 | return -EINVAL; |
| 818 | } |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | static void ax8817x_get_drvinfo (struct net_device *net, |
| 823 | struct ethtool_drvinfo *info) |
| 824 | { |
| 825 | /* Inherit standard device info */ |
| 826 | usbnet_get_drvinfo(net, info); |
| 827 | info->eedump_len = 0x3e; |
| 828 | } |
| 829 | |
| 830 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) |
| 831 | { |
| 832 | struct usbnet *dev = netdev_priv(net); |
| 833 | |
| 834 | return mii_ethtool_gset(&dev->mii,cmd); |
| 835 | } |
| 836 | |
| 837 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) |
| 838 | { |
| 839 | struct usbnet *dev = netdev_priv(net); |
| 840 | |
| 841 | return mii_ethtool_sset(&dev->mii,cmd); |
| 842 | } |
| 843 | |
| 844 | /* We need to override some ethtool_ops so we require our |
| 845 | own structure so we don't interfere with other usbnet |
| 846 | devices that may be connected at the same time. */ |
| 847 | static struct ethtool_ops ax8817x_ethtool_ops = { |
| 848 | .get_drvinfo = ax8817x_get_drvinfo, |
| 849 | .get_link = ethtool_op_get_link, |
| 850 | .get_msglevel = usbnet_get_msglevel, |
| 851 | .set_msglevel = usbnet_set_msglevel, |
| 852 | .get_wol = ax8817x_get_wol, |
| 853 | .set_wol = ax8817x_set_wol, |
| 854 | .get_eeprom_len = ax8817x_get_eeprom_len, |
| 855 | .get_eeprom = ax8817x_get_eeprom, |
| 856 | .get_settings = ax8817x_get_settings, |
| 857 | .set_settings = ax8817x_set_settings, |
| 858 | }; |
| 859 | |
| 860 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) |
| 861 | { |
| 862 | int ret = 0; |
| 863 | void *buf; |
| 864 | int i; |
| 865 | unsigned long gpio_bits = dev->driver_info->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
| 867 | get_endpoints(dev,intf); |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); |
| 870 | if(!buf) { |
| 871 | ret = -ENOMEM; |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 872 | goto out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | /* Toggle the GPIOs in a manufacturer/model specific way */ |
| 876 | for (i = 2; i >= 0; i--) { |
| 877 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, |
| 878 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, |
| 879 | buf)) < 0) |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 880 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | msleep(5); |
| 882 | } |
| 883 | |
| 884 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) { |
| 885 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 886 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /* Get the MAC address */ |
| 890 | memset(buf, 0, ETH_ALEN); |
| 891 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) { |
| 892 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 893 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
| 895 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); |
| 896 | |
| 897 | /* Get the PHY id */ |
| 898 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { |
| 899 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 900 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } else if (ret < 2) { |
| 902 | /* this should always return 2 bytes */ |
| 903 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret); |
| 904 | ret = -EIO; |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 905 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /* Initialize MII structure */ |
| 909 | dev->mii.dev = dev->net; |
| 910 | dev->mii.mdio_read = ax8817x_mdio_read; |
| 911 | dev->mii.mdio_write = ax8817x_mdio_write; |
| 912 | dev->mii.phy_id_mask = 0x3f; |
| 913 | dev->mii.reg_num_mask = 0x1f; |
| 914 | dev->mii.phy_id = *((u8 *)buf + 1); |
| 915 | |
| 916 | dev->net->set_multicast_list = ax8817x_set_multicast; |
| 917 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; |
| 918 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 919 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 921 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | mii_nway_restart(&dev->mii); |
| 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | out2: |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 926 | kfree(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | return ret; |
| 929 | } |
| 930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | static struct ethtool_ops ax88772_ethtool_ops = { |
| 932 | .get_drvinfo = ax8817x_get_drvinfo, |
| 933 | .get_link = ethtool_op_get_link, |
| 934 | .get_msglevel = usbnet_get_msglevel, |
| 935 | .set_msglevel = usbnet_set_msglevel, |
| 936 | .get_wol = ax8817x_get_wol, |
| 937 | .set_wol = ax8817x_set_wol, |
| 938 | .get_eeprom_len = ax8817x_get_eeprom_len, |
| 939 | .get_eeprom = ax8817x_get_eeprom, |
| 940 | .get_settings = ax8817x_get_settings, |
| 941 | .set_settings = ax8817x_set_settings, |
| 942 | }; |
| 943 | |
| 944 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) |
| 945 | { |
| 946 | int ret; |
| 947 | void *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | get_endpoints(dev,intf); |
| 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | buf = kmalloc(6, GFP_KERNEL); |
| 952 | if(!buf) { |
| 953 | dbg ("Cannot allocate memory for buffer"); |
| 954 | ret = -ENOMEM; |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 955 | goto out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, |
| 959 | 0x00B0, 0, 0, buf)) < 0) |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 960 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | msleep(5); |
| 963 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) { |
| 964 | dbg("Select PHY #1 failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 965 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | if ((ret = |
| 969 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) { |
| 970 | dbg("Failed to power down internal PHY: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 971 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | msleep(150); |
| 975 | if ((ret = |
| 976 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) { |
| 977 | dbg("Failed to perform software reset: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 978 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | msleep(150); |
| 982 | if ((ret = |
| 983 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { |
| 984 | dbg("Failed to set Internal/External PHY reset control: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 985 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | msleep(150); |
| 989 | if ((ret = |
| 990 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0, |
| 991 | buf)) < 0) { |
| 992 | dbg("Failed to reset RX_CTL: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 993 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /* Get the MAC address */ |
| 997 | memset(buf, 0, ETH_ALEN); |
| 998 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) { |
| 999 | dbg("Failed to read MAC address: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1000 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); |
| 1003 | |
| 1004 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) { |
| 1005 | dbg("Enabling software MII failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1006 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | if (((ret = |
| 1010 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0) |
| 1011 | || (*((u16 *)buf) != 0x003b)) { |
| 1012 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1013 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /* Initialize MII structure */ |
| 1017 | dev->mii.dev = dev->net; |
| 1018 | dev->mii.mdio_read = ax8817x_mdio_read; |
| 1019 | dev->mii.mdio_write = ax8817x_mdio_write; |
| 1020 | dev->mii.phy_id_mask = 0xff; |
| 1021 | dev->mii.reg_num_mask = 0xff; |
| 1022 | |
| 1023 | /* Get the PHY id */ |
| 1024 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { |
| 1025 | dbg("Error reading PHY ID: %02x", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1026 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } else if (ret < 2) { |
| 1028 | /* this should always return 2 bytes */ |
| 1029 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", |
| 1030 | ret); |
| 1031 | ret = -EIO; |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1032 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | dev->mii.phy_id = *((u8 *)buf + 1); |
| 1035 | |
| 1036 | if ((ret = |
| 1037 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) { |
| 1038 | dbg("Set external PHY reset pin level: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1039 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } |
| 1041 | msleep(150); |
| 1042 | if ((ret = |
| 1043 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { |
| 1044 | dbg("Set Internal/External PHY reset control: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1045 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | msleep(150); |
| 1048 | |
| 1049 | |
| 1050 | dev->net->set_multicast_list = ax8817x_set_multicast; |
| 1051 | dev->net->ethtool_ops = &ax88772_ethtool_ops; |
| 1052 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1053 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1055 | ADVERTISE_ALL | ADVERTISE_CSMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | mii_nway_restart(&dev->mii); |
| 1057 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1058 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | dbg("Write medium mode register: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1060 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) { |
| 1064 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1065 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | } |
| 1067 | if ((ret = |
| 1068 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { |
| 1069 | dbg("Failed to set hardware MII: %02x", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1070 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ |
| 1074 | if ((ret = |
| 1075 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, |
| 1076 | buf)) < 0) { |
| 1077 | dbg("Reset RX_CTL failed: %d", ret); |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1078 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | kfree(buf); |
| 1082 | |
| 1083 | return 0; |
| 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | out2: |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1086 | kfree(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return ret; |
| 1089 | } |
| 1090 | |
| 1091 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
| 1092 | { |
| 1093 | u32 *header; |
| 1094 | char *packet; |
| 1095 | struct sk_buff *ax_skb; |
| 1096 | u16 size; |
| 1097 | |
| 1098 | header = (u32 *) skb->data; |
| 1099 | le32_to_cpus(header); |
| 1100 | packet = (char *)(header + 1); |
| 1101 | |
| 1102 | skb_pull(skb, 4); |
| 1103 | |
| 1104 | while (skb->len > 0) { |
| 1105 | if ((short)(*header & 0x0000ffff) != |
| 1106 | ~((short)((*header & 0xffff0000) >> 16))) { |
| 1107 | devdbg(dev,"header length data is error"); |
| 1108 | } |
| 1109 | /* get the packet length */ |
| 1110 | size = (u16) (*header & 0x0000ffff); |
| 1111 | |
| 1112 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) |
| 1113 | return 2; |
| 1114 | if (size > ETH_FRAME_LEN) { |
| 1115 | devdbg(dev,"invalid rx length %d", size); |
| 1116 | return 0; |
| 1117 | } |
| 1118 | ax_skb = skb_clone(skb, GFP_ATOMIC); |
| 1119 | if (ax_skb) { |
| 1120 | ax_skb->len = size; |
| 1121 | ax_skb->data = packet; |
| 1122 | ax_skb->tail = packet + size; |
| 1123 | skb_return(dev, ax_skb); |
| 1124 | } else { |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | skb_pull(skb, (size + 1) & 0xfffe); |
| 1129 | |
| 1130 | if (skb->len == 0) |
| 1131 | break; |
| 1132 | |
| 1133 | header = (u32 *) skb->data; |
| 1134 | le32_to_cpus(header); |
| 1135 | packet = (char *)(header + 1); |
| 1136 | skb_pull(skb, 4); |
| 1137 | } |
| 1138 | |
| 1139 | if (skb->len < 0) { |
| 1140 | devdbg(dev,"invalid rx length %d", skb->len); |
| 1141 | return 0; |
| 1142 | } |
| 1143 | return 1; |
| 1144 | } |
| 1145 | |
| 1146 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, |
| 1147 | int flags) |
| 1148 | { |
| 1149 | int padlen; |
| 1150 | int headroom = skb_headroom(skb); |
| 1151 | int tailroom = skb_tailroom(skb); |
| 1152 | u32 *packet_len; |
| 1153 | u32 *padbytes_ptr; |
| 1154 | |
| 1155 | padlen = ((skb->len + 4) % 512) ? 0 : 4; |
| 1156 | |
| 1157 | if ((!skb_cloned(skb)) |
| 1158 | && ((headroom + tailroom) >= (4 + padlen))) { |
| 1159 | if ((headroom < 4) || (tailroom < padlen)) { |
| 1160 | skb->data = memmove(skb->head + 4, skb->data, skb->len); |
| 1161 | skb->tail = skb->data + skb->len; |
| 1162 | } |
| 1163 | } else { |
| 1164 | struct sk_buff *skb2; |
| 1165 | skb2 = skb_copy_expand(skb, 4, padlen, flags); |
| 1166 | dev_kfree_skb_any(skb); |
| 1167 | skb = skb2; |
| 1168 | if (!skb) |
| 1169 | return NULL; |
| 1170 | } |
| 1171 | |
| 1172 | packet_len = (u32 *) skb_push(skb, 4); |
| 1173 | |
| 1174 | packet_len = (u32 *) skb->data; |
| 1175 | *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); |
| 1176 | |
| 1177 | if ((skb->len % 512) == 0) { |
| 1178 | padbytes_ptr = (u32 *) skb->tail; |
| 1179 | *padbytes_ptr = 0xffff0000; |
| 1180 | skb_put(skb, padlen); |
| 1181 | } |
| 1182 | return skb; |
| 1183 | } |
| 1184 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1185 | static int ax88772_link_reset(struct usbnet *dev) |
| 1186 | { |
| 1187 | u16 lpa; |
| 1188 | u16 mode; |
| 1189 | |
| 1190 | mode = AX88772_MEDIUM_DEFAULT; |
| 1191 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); |
| 1192 | |
| 1193 | if ((lpa & LPA_DUPLEX) == 0) |
| 1194 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; |
| 1195 | if ((lpa & LPA_100) == 0) |
| 1196 | mode &= ~AX88772_MEDIUM_100MB; |
| 1197 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | static const struct driver_info ax8817x_info = { |
| 1203 | .description = "ASIX AX8817x USB 2.0 Ethernet", |
| 1204 | .bind = ax8817x_bind, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1205 | .status = ax8817x_status, |
| 1206 | .link_reset = ax88172_link_reset, |
| 1207 | .reset = ax88172_link_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | .flags = FLAG_ETHER, |
| 1209 | .data = 0x00130103, |
| 1210 | }; |
| 1211 | |
| 1212 | static const struct driver_info dlink_dub_e100_info = { |
| 1213 | .description = "DLink DUB-E100 USB Ethernet", |
| 1214 | .bind = ax8817x_bind, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1215 | .status = ax8817x_status, |
| 1216 | .link_reset = ax88172_link_reset, |
| 1217 | .reset = ax88172_link_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | .flags = FLAG_ETHER, |
| 1219 | .data = 0x009f9d9f, |
| 1220 | }; |
| 1221 | |
| 1222 | static const struct driver_info netgear_fa120_info = { |
| 1223 | .description = "Netgear FA-120 USB Ethernet", |
| 1224 | .bind = ax8817x_bind, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1225 | .status = ax8817x_status, |
| 1226 | .link_reset = ax88172_link_reset, |
| 1227 | .reset = ax88172_link_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | .flags = FLAG_ETHER, |
| 1229 | .data = 0x00130103, |
| 1230 | }; |
| 1231 | |
| 1232 | static const struct driver_info hawking_uf200_info = { |
| 1233 | .description = "Hawking UF200 USB Ethernet", |
| 1234 | .bind = ax8817x_bind, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1235 | .status = ax8817x_status, |
| 1236 | .link_reset = ax88172_link_reset, |
| 1237 | .reset = ax88172_link_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | .flags = FLAG_ETHER, |
| 1239 | .data = 0x001f1d1f, |
| 1240 | }; |
| 1241 | |
| 1242 | static const struct driver_info ax88772_info = { |
| 1243 | .description = "ASIX AX88772 USB 2.0 Ethernet", |
| 1244 | .bind = ax88772_bind, |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 1245 | .status = ax8817x_status, |
| 1246 | .link_reset = ax88772_link_reset, |
| 1247 | .reset = ax88772_link_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, |
| 1249 | .rx_fixup = ax88772_rx_fixup, |
| 1250 | .tx_fixup = ax88772_tx_fixup, |
| 1251 | .data = 0x00130103, |
| 1252 | }; |
| 1253 | |
| 1254 | #endif /* CONFIG_USB_AX8817X */ |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | #ifdef CONFIG_USB_BELKIN |
| 1259 | #define HAVE_HARDWARE |
| 1260 | |
| 1261 | /*------------------------------------------------------------------------- |
| 1262 | * |
| 1263 | * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller |
| 1264 | * |
| 1265 | * ... also two eTEK designs, including one sold as "Advance USBNET" |
| 1266 | * |
| 1267 | *-------------------------------------------------------------------------*/ |
| 1268 | |
| 1269 | static const struct driver_info belkin_info = { |
| 1270 | .description = "Belkin, eTEK, or compatible", |
| 1271 | }; |
| 1272 | |
| 1273 | #endif /* CONFIG_USB_BELKIN */ |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | /*------------------------------------------------------------------------- |
| 1278 | * |
| 1279 | * Communications Device Class declarations. |
| 1280 | * Used by CDC Ethernet, and some CDC variants |
| 1281 | * |
| 1282 | *-------------------------------------------------------------------------*/ |
| 1283 | |
| 1284 | #ifdef CONFIG_USB_CDCETHER |
| 1285 | #define NEED_GENERIC_CDC |
| 1286 | #endif |
| 1287 | |
| 1288 | #ifdef CONFIG_USB_ZAURUS |
| 1289 | /* Ethernet variant uses funky framing, broken ethernet addressing */ |
| 1290 | #define NEED_GENERIC_CDC |
| 1291 | #endif |
| 1292 | |
| 1293 | #ifdef CONFIG_USB_RNDIS |
| 1294 | /* ACM variant uses even funkier framing, complex control RPC scheme */ |
| 1295 | #define NEED_GENERIC_CDC |
| 1296 | #endif |
| 1297 | |
| 1298 | |
| 1299 | #ifdef NEED_GENERIC_CDC |
| 1300 | |
| 1301 | #include <linux/usb_cdc.h> |
| 1302 | |
| 1303 | struct cdc_state { |
| 1304 | struct usb_cdc_header_desc *header; |
| 1305 | struct usb_cdc_union_desc *u; |
| 1306 | struct usb_cdc_ether_desc *ether; |
| 1307 | struct usb_interface *control; |
| 1308 | struct usb_interface *data; |
| 1309 | }; |
| 1310 | |
| 1311 | static struct usb_driver usbnet_driver; |
| 1312 | |
| 1313 | /* |
| 1314 | * probes control interface, claims data interface, collects the bulk |
| 1315 | * endpoints, activates data interface (if needed), maybe sets MTU. |
| 1316 | * all pure cdc, except for certain firmware workarounds. |
| 1317 | */ |
| 1318 | static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf) |
| 1319 | { |
| 1320 | u8 *buf = intf->cur_altsetting->extra; |
| 1321 | int len = intf->cur_altsetting->extralen; |
| 1322 | struct usb_interface_descriptor *d; |
| 1323 | struct cdc_state *info = (void *) &dev->data; |
| 1324 | int status; |
| 1325 | int rndis; |
| 1326 | |
| 1327 | if (sizeof dev->data < sizeof *info) |
| 1328 | return -EDOM; |
| 1329 | |
| 1330 | /* expect strict spec conformance for the descriptors, but |
| 1331 | * cope with firmware which stores them in the wrong place |
| 1332 | */ |
| 1333 | if (len == 0 && dev->udev->actconfig->extralen) { |
| 1334 | /* Motorola SB4100 (and others: Brad Hards says it's |
| 1335 | * from a Broadcom design) put CDC descriptors here |
| 1336 | */ |
| 1337 | buf = dev->udev->actconfig->extra; |
| 1338 | len = dev->udev->actconfig->extralen; |
| 1339 | if (len) |
| 1340 | dev_dbg (&intf->dev, |
| 1341 | "CDC descriptors on config\n"); |
| 1342 | } |
| 1343 | |
| 1344 | /* this assumes that if there's a non-RNDIS vendor variant |
| 1345 | * of cdc-acm, it'll fail RNDIS requests cleanly. |
| 1346 | */ |
| 1347 | rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff); |
| 1348 | |
| 1349 | memset (info, 0, sizeof *info); |
| 1350 | info->control = intf; |
| 1351 | while (len > 3) { |
| 1352 | if (buf [1] != USB_DT_CS_INTERFACE) |
| 1353 | goto next_desc; |
| 1354 | |
| 1355 | /* use bDescriptorSubType to identify the CDC descriptors. |
| 1356 | * We expect devices with CDC header and union descriptors. |
| 1357 | * For CDC Ethernet we need the ethernet descriptor. |
| 1358 | * For RNDIS, ignore two (pointless) CDC modem descriptors |
| 1359 | * in favor of a complicated OID-based RPC scheme doing what |
| 1360 | * CDC Ethernet achieves with a simple descriptor. |
| 1361 | */ |
| 1362 | switch (buf [2]) { |
| 1363 | case USB_CDC_HEADER_TYPE: |
| 1364 | if (info->header) { |
| 1365 | dev_dbg (&intf->dev, "extra CDC header\n"); |
| 1366 | goto bad_desc; |
| 1367 | } |
| 1368 | info->header = (void *) buf; |
| 1369 | if (info->header->bLength != sizeof *info->header) { |
| 1370 | dev_dbg (&intf->dev, "CDC header len %u\n", |
| 1371 | info->header->bLength); |
| 1372 | goto bad_desc; |
| 1373 | } |
| 1374 | break; |
| 1375 | case USB_CDC_UNION_TYPE: |
| 1376 | if (info->u) { |
| 1377 | dev_dbg (&intf->dev, "extra CDC union\n"); |
| 1378 | goto bad_desc; |
| 1379 | } |
| 1380 | info->u = (void *) buf; |
| 1381 | if (info->u->bLength != sizeof *info->u) { |
| 1382 | dev_dbg (&intf->dev, "CDC union len %u\n", |
| 1383 | info->u->bLength); |
| 1384 | goto bad_desc; |
| 1385 | } |
| 1386 | |
| 1387 | /* we need a master/control interface (what we're |
| 1388 | * probed with) and a slave/data interface; union |
| 1389 | * descriptors sort this all out. |
| 1390 | */ |
| 1391 | info->control = usb_ifnum_to_if(dev->udev, |
| 1392 | info->u->bMasterInterface0); |
| 1393 | info->data = usb_ifnum_to_if(dev->udev, |
| 1394 | info->u->bSlaveInterface0); |
| 1395 | if (!info->control || !info->data) { |
| 1396 | dev_dbg (&intf->dev, |
| 1397 | "master #%u/%p slave #%u/%p\n", |
| 1398 | info->u->bMasterInterface0, |
| 1399 | info->control, |
| 1400 | info->u->bSlaveInterface0, |
| 1401 | info->data); |
| 1402 | goto bad_desc; |
| 1403 | } |
| 1404 | if (info->control != intf) { |
| 1405 | dev_dbg (&intf->dev, "bogus CDC Union\n"); |
| 1406 | /* Ambit USB Cable Modem (and maybe others) |
| 1407 | * interchanges master and slave interface. |
| 1408 | */ |
| 1409 | if (info->data == intf) { |
| 1410 | info->data = info->control; |
| 1411 | info->control = intf; |
| 1412 | } else |
| 1413 | goto bad_desc; |
| 1414 | } |
| 1415 | |
| 1416 | /* a data interface altsetting does the real i/o */ |
| 1417 | d = &info->data->cur_altsetting->desc; |
| 1418 | if (d->bInterfaceClass != USB_CLASS_CDC_DATA) { |
| 1419 | dev_dbg (&intf->dev, "slave class %u\n", |
| 1420 | d->bInterfaceClass); |
| 1421 | goto bad_desc; |
| 1422 | } |
| 1423 | break; |
| 1424 | case USB_CDC_ETHERNET_TYPE: |
| 1425 | if (info->ether) { |
| 1426 | dev_dbg (&intf->dev, "extra CDC ether\n"); |
| 1427 | goto bad_desc; |
| 1428 | } |
| 1429 | info->ether = (void *) buf; |
| 1430 | if (info->ether->bLength != sizeof *info->ether) { |
| 1431 | dev_dbg (&intf->dev, "CDC ether len %u\n", |
| 1432 | info->u->bLength); |
| 1433 | goto bad_desc; |
| 1434 | } |
| 1435 | dev->net->mtu = le16_to_cpup ( |
| 1436 | &info->ether->wMaxSegmentSize) |
| 1437 | - ETH_HLEN; |
| 1438 | /* because of Zaurus, we may be ignoring the host |
| 1439 | * side link address we were given. |
| 1440 | */ |
| 1441 | break; |
| 1442 | } |
| 1443 | next_desc: |
| 1444 | len -= buf [0]; /* bLength */ |
| 1445 | buf += buf [0]; |
| 1446 | } |
| 1447 | |
| 1448 | if (!info->header || !info->u || (!rndis && !info->ether)) { |
| 1449 | dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n", |
| 1450 | info->header ? "" : "header ", |
| 1451 | info->u ? "" : "union ", |
| 1452 | info->ether ? "" : "ether "); |
| 1453 | goto bad_desc; |
| 1454 | } |
| 1455 | |
| 1456 | /* claim data interface and set it up ... with side effects. |
| 1457 | * network traffic can't flow until an altsetting is enabled. |
| 1458 | */ |
| 1459 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); |
| 1460 | if (status < 0) |
| 1461 | return status; |
| 1462 | status = get_endpoints (dev, info->data); |
| 1463 | if (status < 0) { |
| 1464 | /* ensure immediate exit from usbnet_disconnect */ |
| 1465 | usb_set_intfdata(info->data, NULL); |
| 1466 | usb_driver_release_interface (&usbnet_driver, info->data); |
| 1467 | return status; |
| 1468 | } |
| 1469 | |
| 1470 | /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ |
| 1471 | dev->status = NULL; |
| 1472 | if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { |
| 1473 | struct usb_endpoint_descriptor *desc; |
| 1474 | |
| 1475 | dev->status = &info->control->cur_altsetting->endpoint [0]; |
| 1476 | desc = &dev->status->desc; |
| 1477 | if (desc->bmAttributes != USB_ENDPOINT_XFER_INT |
| 1478 | || !(desc->bEndpointAddress & USB_DIR_IN) |
| 1479 | || (le16_to_cpu(desc->wMaxPacketSize) |
| 1480 | < sizeof (struct usb_cdc_notification)) |
| 1481 | || !desc->bInterval) { |
| 1482 | dev_dbg (&intf->dev, "bad notification endpoint\n"); |
| 1483 | dev->status = NULL; |
| 1484 | } |
| 1485 | } |
| 1486 | if (rndis && !dev->status) { |
| 1487 | dev_dbg (&intf->dev, "missing RNDIS status endpoint\n"); |
| 1488 | usb_set_intfdata(info->data, NULL); |
| 1489 | usb_driver_release_interface (&usbnet_driver, info->data); |
| 1490 | return -ENODEV; |
| 1491 | } |
| 1492 | return 0; |
| 1493 | |
| 1494 | bad_desc: |
| 1495 | dev_info (&dev->udev->dev, "bad CDC descriptors\n"); |
| 1496 | return -ENODEV; |
| 1497 | } |
| 1498 | |
| 1499 | static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf) |
| 1500 | { |
| 1501 | struct cdc_state *info = (void *) &dev->data; |
| 1502 | |
| 1503 | /* disconnect master --> disconnect slave */ |
| 1504 | if (intf == info->control && info->data) { |
| 1505 | /* ensure immediate exit from usbnet_disconnect */ |
| 1506 | usb_set_intfdata(info->data, NULL); |
| 1507 | usb_driver_release_interface (&usbnet_driver, info->data); |
| 1508 | info->data = NULL; |
| 1509 | } |
| 1510 | |
| 1511 | /* and vice versa (just in case) */ |
| 1512 | else if (intf == info->data && info->control) { |
| 1513 | /* ensure immediate exit from usbnet_disconnect */ |
| 1514 | usb_set_intfdata(info->control, NULL); |
| 1515 | usb_driver_release_interface (&usbnet_driver, info->control); |
| 1516 | info->control = NULL; |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | static void dumpspeed (struct usbnet *dev, __le32 *speeds) |
| 1522 | { |
| 1523 | if (netif_msg_timer (dev)) |
| 1524 | devinfo (dev, "link speeds: %u kbps up, %u kbps down", |
| 1525 | __le32_to_cpu(speeds[0]) / 1000, |
| 1526 | __le32_to_cpu(speeds[1]) / 1000); |
| 1527 | } |
| 1528 | |
| 1529 | static void cdc_status (struct usbnet *dev, struct urb *urb) |
| 1530 | { |
| 1531 | struct usb_cdc_notification *event; |
| 1532 | |
| 1533 | if (urb->actual_length < sizeof *event) |
| 1534 | return; |
| 1535 | |
| 1536 | /* SPEED_CHANGE can get split into two 8-byte packets */ |
| 1537 | if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) { |
| 1538 | dumpspeed (dev, (__le32 *) urb->transfer_buffer); |
| 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | event = urb->transfer_buffer; |
| 1543 | switch (event->bNotificationType) { |
| 1544 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
| 1545 | if (netif_msg_timer (dev)) |
| 1546 | devdbg (dev, "CDC: carrier %s", |
| 1547 | event->wValue ? "on" : "off"); |
| 1548 | if (event->wValue) |
| 1549 | netif_carrier_on(dev->net); |
| 1550 | else |
| 1551 | netif_carrier_off(dev->net); |
| 1552 | break; |
| 1553 | case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */ |
| 1554 | if (netif_msg_timer (dev)) |
| 1555 | devdbg (dev, "CDC: speed change (len %d)", |
| 1556 | urb->actual_length); |
| 1557 | if (urb->actual_length != (sizeof *event + 8)) |
| 1558 | set_bit (EVENT_STS_SPLIT, &dev->flags); |
| 1559 | else |
| 1560 | dumpspeed (dev, (__le32 *) &event[1]); |
| 1561 | break; |
| 1562 | // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */ |
| 1563 | default: |
| 1564 | deverr (dev, "CDC: unexpected notification %02x!", |
| 1565 | event->bNotificationType); |
| 1566 | break; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | #endif /* NEED_GENERIC_CDC */ |
| 1571 | |
| 1572 | |
| 1573 | #ifdef CONFIG_USB_CDCETHER |
| 1574 | #define HAVE_HARDWARE |
| 1575 | |
| 1576 | /*------------------------------------------------------------------------- |
| 1577 | * |
| 1578 | * Communications Device Class, Ethernet Control model |
| 1579 | * |
| 1580 | * Takes two interfaces. The DATA interface is inactive till an altsetting |
| 1581 | * is selected. Configuration data includes class descriptors. |
| 1582 | * |
| 1583 | * This should interop with whatever the 2.4 "CDCEther.c" driver |
| 1584 | * (by Brad Hards) talked with. |
| 1585 | * |
| 1586 | *-------------------------------------------------------------------------*/ |
| 1587 | |
| 1588 | #include <linux/ctype.h> |
| 1589 | |
| 1590 | static u8 nibble (unsigned char c) |
| 1591 | { |
| 1592 | if (likely (isdigit (c))) |
| 1593 | return c - '0'; |
| 1594 | c = toupper (c); |
| 1595 | if (likely (isxdigit (c))) |
| 1596 | return 10 + c - 'A'; |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
| 1600 | static inline int |
| 1601 | get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e) |
| 1602 | { |
| 1603 | int tmp, i; |
| 1604 | unsigned char buf [13]; |
| 1605 | |
| 1606 | tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf); |
| 1607 | if (tmp != 12) { |
| 1608 | dev_dbg (&dev->udev->dev, |
| 1609 | "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp); |
| 1610 | if (tmp >= 0) |
| 1611 | tmp = -EINVAL; |
| 1612 | return tmp; |
| 1613 | } |
| 1614 | for (i = tmp = 0; i < 6; i++, tmp += 2) |
| 1615 | dev->net->dev_addr [i] = |
| 1616 | (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]); |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static int cdc_bind (struct usbnet *dev, struct usb_interface *intf) |
| 1621 | { |
| 1622 | int status; |
| 1623 | struct cdc_state *info = (void *) &dev->data; |
| 1624 | |
| 1625 | status = generic_cdc_bind (dev, intf); |
| 1626 | if (status < 0) |
| 1627 | return status; |
| 1628 | |
| 1629 | status = get_ethernet_addr (dev, info->ether); |
| 1630 | if (status < 0) { |
| 1631 | usb_set_intfdata(info->data, NULL); |
| 1632 | usb_driver_release_interface (&usbnet_driver, info->data); |
| 1633 | return status; |
| 1634 | } |
| 1635 | |
| 1636 | /* FIXME cdc-ether has some multicast code too, though it complains |
| 1637 | * in routine cases. info->ether describes the multicast support. |
| 1638 | */ |
| 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | static const struct driver_info cdc_info = { |
| 1643 | .description = "CDC Ethernet Device", |
| 1644 | .flags = FLAG_ETHER, |
| 1645 | // .check_connect = cdc_check_connect, |
| 1646 | .bind = cdc_bind, |
| 1647 | .unbind = cdc_unbind, |
| 1648 | .status = cdc_status, |
| 1649 | }; |
| 1650 | |
| 1651 | #endif /* CONFIG_USB_CDCETHER */ |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | #ifdef CONFIG_USB_EPSON2888 |
| 1656 | #define HAVE_HARDWARE |
| 1657 | |
| 1658 | /*------------------------------------------------------------------------- |
| 1659 | * |
| 1660 | * EPSON USB clients |
| 1661 | * |
| 1662 | * This is the same idea as Linux PDAs (below) except the firmware in the |
| 1663 | * device might not be Tux-powered. Epson provides reference firmware that |
| 1664 | * implements this interface. Product developers can reuse or modify that |
| 1665 | * code, such as by using their own product and vendor codes. |
| 1666 | * |
| 1667 | * Support was from Juro Bystricky <bystricky.juro@erd.epson.com> |
| 1668 | * |
| 1669 | *-------------------------------------------------------------------------*/ |
| 1670 | |
| 1671 | static const struct driver_info epson2888_info = { |
| 1672 | .description = "Epson USB Device", |
| 1673 | .check_connect = always_connected, |
| 1674 | |
| 1675 | .in = 4, .out = 3, |
| 1676 | }; |
| 1677 | |
| 1678 | #endif /* CONFIG_USB_EPSON2888 */ |
| 1679 | |
| 1680 | |
| 1681 | #ifdef CONFIG_USB_GENESYS |
| 1682 | #define HAVE_HARDWARE |
| 1683 | |
| 1684 | /*------------------------------------------------------------------------- |
| 1685 | * |
| 1686 | * GeneSys GL620USB-A (www.genesyslogic.com.tw) |
| 1687 | * |
| 1688 | * ... should partially interop with the Win32 driver for this hardware |
| 1689 | * The GeneSys docs imply there's some NDIS issue motivating this framing. |
| 1690 | * |
| 1691 | * Some info from GeneSys: |
| 1692 | * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk. |
| 1693 | * (Some cables, like the BAFO-100c, use the half duplex version.) |
| 1694 | * - For the full duplex model, the low bit of the version code says |
| 1695 | * which side is which ("left/right"). |
| 1696 | * - For the half duplex type, a control/interrupt handshake settles |
| 1697 | * the transfer direction. (That's disabled here, partially coded.) |
| 1698 | * A control URB would block until other side writes an interrupt. |
| 1699 | * |
| 1700 | * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw> |
| 1701 | * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>. |
| 1702 | * |
| 1703 | *-------------------------------------------------------------------------*/ |
| 1704 | |
| 1705 | // control msg write command |
| 1706 | #define GENELINK_CONNECT_WRITE 0xF0 |
| 1707 | // interrupt pipe index |
| 1708 | #define GENELINK_INTERRUPT_PIPE 0x03 |
| 1709 | // interrupt read buffer size |
| 1710 | #define INTERRUPT_BUFSIZE 0x08 |
| 1711 | // interrupt pipe interval value |
| 1712 | #define GENELINK_INTERRUPT_INTERVAL 0x10 |
| 1713 | // max transmit packet number per transmit |
| 1714 | #define GL_MAX_TRANSMIT_PACKETS 32 |
| 1715 | // max packet length |
| 1716 | #define GL_MAX_PACKET_LEN 1514 |
| 1717 | // max receive buffer size |
| 1718 | #define GL_RCV_BUF_SIZE \ |
| 1719 | (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4) |
| 1720 | |
| 1721 | struct gl_packet { |
| 1722 | u32 packet_length; |
| 1723 | char packet_data [1]; |
| 1724 | }; |
| 1725 | |
| 1726 | struct gl_header { |
| 1727 | u32 packet_count; |
| 1728 | struct gl_packet packets; |
| 1729 | }; |
| 1730 | |
| 1731 | #ifdef GENELINK_ACK |
| 1732 | |
| 1733 | // FIXME: this code is incomplete, not debugged; it doesn't |
| 1734 | // handle interrupts correctly. interrupts should be generic |
| 1735 | // code like all other device I/O, anyway. |
| 1736 | |
| 1737 | struct gl_priv { |
| 1738 | struct urb *irq_urb; |
| 1739 | char irq_buf [INTERRUPT_BUFSIZE]; |
| 1740 | }; |
| 1741 | |
| 1742 | static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value) |
| 1743 | { |
| 1744 | int retval; |
| 1745 | |
| 1746 | retval = usb_control_msg (dev->udev, |
| 1747 | usb_sndctrlpipe (dev->udev, 0), |
| 1748 | request, |
| 1749 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 1750 | value, |
| 1751 | 0, // index |
| 1752 | 0, // data buffer |
| 1753 | 0, // size |
| 1754 | CONTROL_TIMEOUT_MS); |
| 1755 | return retval; |
| 1756 | } |
| 1757 | |
| 1758 | static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs) |
| 1759 | { |
| 1760 | int status = urb->status; |
| 1761 | |
| 1762 | switch (status) { |
| 1763 | case 0: |
| 1764 | /* success */ |
| 1765 | break; |
| 1766 | case -ECONNRESET: |
| 1767 | case -ENOENT: |
| 1768 | case -ESHUTDOWN: |
| 1769 | /* this urb is terminated, clean up */ |
| 1770 | dbg("%s - urb shutting down with status: %d", |
| 1771 | __FUNCTION__, status); |
| 1772 | return; |
| 1773 | default: |
| 1774 | dbg("%s - nonzero urb status received: %d", |
| 1775 | __FUNCTION__, urb->status); |
| 1776 | } |
| 1777 | |
| 1778 | status = usb_submit_urb (urb, GFP_ATOMIC); |
| 1779 | if (status) |
| 1780 | err ("%s - usb_submit_urb failed with result %d", |
| 1781 | __FUNCTION__, status); |
| 1782 | } |
| 1783 | |
| 1784 | static int gl_interrupt_read (struct usbnet *dev) |
| 1785 | { |
| 1786 | struct gl_priv *priv = dev->priv_data; |
| 1787 | int retval; |
| 1788 | |
| 1789 | // issue usb interrupt read |
| 1790 | if (priv && priv->irq_urb) { |
| 1791 | // submit urb |
| 1792 | if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0) |
| 1793 | dbg ("gl_interrupt_read: submit fail - %X...", retval); |
| 1794 | else |
| 1795 | dbg ("gl_interrupt_read: submit success..."); |
| 1796 | } |
| 1797 | |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
| 1801 | // check whether another side is connected |
| 1802 | static int genelink_check_connect (struct usbnet *dev) |
| 1803 | { |
| 1804 | int retval; |
| 1805 | |
| 1806 | dbg ("genelink_check_connect..."); |
| 1807 | |
| 1808 | // detect whether another side is connected |
| 1809 | if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) { |
| 1810 | dbg ("%s: genelink_check_connect write fail - %X", |
| 1811 | dev->net->name, retval); |
| 1812 | return retval; |
| 1813 | } |
| 1814 | |
| 1815 | // usb interrupt read to ack another side |
| 1816 | if ((retval = gl_interrupt_read (dev)) != 0) { |
| 1817 | dbg ("%s: genelink_check_connect read fail - %X", |
| 1818 | dev->net->name, retval); |
| 1819 | return retval; |
| 1820 | } |
| 1821 | |
| 1822 | dbg ("%s: genelink_check_connect read success", dev->net->name); |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
| 1826 | // allocate and initialize the private data for genelink |
| 1827 | static int genelink_init (struct usbnet *dev) |
| 1828 | { |
| 1829 | struct gl_priv *priv; |
| 1830 | |
| 1831 | // allocate the private data structure |
| 1832 | if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) { |
| 1833 | dbg ("%s: cannot allocate private data per device", |
| 1834 | dev->net->name); |
| 1835 | return -ENOMEM; |
| 1836 | } |
| 1837 | |
| 1838 | // allocate irq urb |
| 1839 | if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) { |
| 1840 | dbg ("%s: cannot allocate private irq urb per device", |
| 1841 | dev->net->name); |
| 1842 | kfree (priv); |
| 1843 | return -ENOMEM; |
| 1844 | } |
| 1845 | |
| 1846 | // fill irq urb |
| 1847 | usb_fill_int_urb (priv->irq_urb, dev->udev, |
| 1848 | usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE), |
| 1849 | priv->irq_buf, INTERRUPT_BUFSIZE, |
| 1850 | gl_interrupt_complete, 0, |
| 1851 | GENELINK_INTERRUPT_INTERVAL); |
| 1852 | |
| 1853 | // set private data pointer |
| 1854 | dev->priv_data = priv; |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | // release the private data |
| 1860 | static int genelink_free (struct usbnet *dev) |
| 1861 | { |
| 1862 | struct gl_priv *priv = dev->priv_data; |
| 1863 | |
| 1864 | if (!priv) |
| 1865 | return 0; |
| 1866 | |
| 1867 | // FIXME: can't cancel here; it's synchronous, and |
| 1868 | // should have happened earlier in any case (interrupt |
| 1869 | // handling needs to be generic) |
| 1870 | |
| 1871 | // cancel irq urb first |
| 1872 | usb_kill_urb (priv->irq_urb); |
| 1873 | |
| 1874 | // free irq urb |
| 1875 | usb_free_urb (priv->irq_urb); |
| 1876 | |
| 1877 | // free the private data structure |
| 1878 | kfree (priv); |
| 1879 | |
| 1880 | return 0; |
| 1881 | } |
| 1882 | |
| 1883 | #endif |
| 1884 | |
| 1885 | static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb) |
| 1886 | { |
| 1887 | struct gl_header *header; |
| 1888 | struct gl_packet *packet; |
| 1889 | struct sk_buff *gl_skb; |
| 1890 | u32 size; |
| 1891 | |
| 1892 | header = (struct gl_header *) skb->data; |
| 1893 | |
| 1894 | // get the packet count of the received skb |
| 1895 | le32_to_cpus (&header->packet_count); |
| 1896 | if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS) |
| 1897 | || (header->packet_count < 0)) { |
| 1898 | dbg ("genelink: invalid received packet count %d", |
| 1899 | header->packet_count); |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | // set the current packet pointer to the first packet |
| 1904 | packet = &header->packets; |
| 1905 | |
| 1906 | // decrement the length for the packet count size 4 bytes |
| 1907 | skb_pull (skb, 4); |
| 1908 | |
| 1909 | while (header->packet_count > 1) { |
| 1910 | // get the packet length |
| 1911 | size = packet->packet_length; |
| 1912 | |
| 1913 | // this may be a broken packet |
| 1914 | if (size > GL_MAX_PACKET_LEN) { |
| 1915 | dbg ("genelink: invalid rx length %d", size); |
| 1916 | return 0; |
| 1917 | } |
| 1918 | |
| 1919 | // allocate the skb for the individual packet |
| 1920 | gl_skb = alloc_skb (size, GFP_ATOMIC); |
| 1921 | if (gl_skb) { |
| 1922 | |
| 1923 | // copy the packet data to the new skb |
| 1924 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); |
| 1925 | skb_return (dev, skb); |
| 1926 | } |
| 1927 | |
| 1928 | // advance to the next packet |
| 1929 | packet = (struct gl_packet *) |
| 1930 | &packet->packet_data [size]; |
| 1931 | header->packet_count--; |
| 1932 | |
| 1933 | // shift the data pointer to the next gl_packet |
| 1934 | skb_pull (skb, size + 4); |
| 1935 | } |
| 1936 | |
| 1937 | // skip the packet length field 4 bytes |
| 1938 | skb_pull (skb, 4); |
| 1939 | |
| 1940 | if (skb->len > GL_MAX_PACKET_LEN) { |
| 1941 | dbg ("genelink: invalid rx length %d", skb->len); |
| 1942 | return 0; |
| 1943 | } |
| 1944 | return 1; |
| 1945 | } |
| 1946 | |
| 1947 | static struct sk_buff * |
| 1948 | genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) |
| 1949 | { |
| 1950 | int padlen; |
| 1951 | int length = skb->len; |
| 1952 | int headroom = skb_headroom (skb); |
| 1953 | int tailroom = skb_tailroom (skb); |
| 1954 | u32 *packet_count; |
| 1955 | u32 *packet_len; |
| 1956 | |
| 1957 | // FIXME: magic numbers, bleech |
| 1958 | padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1; |
| 1959 | |
| 1960 | if ((!skb_cloned (skb)) |
| 1961 | && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) { |
| 1962 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) { |
| 1963 | skb->data = memmove (skb->head + (4 + 4*1), |
| 1964 | skb->data, skb->len); |
| 1965 | skb->tail = skb->data + skb->len; |
| 1966 | } |
| 1967 | } else { |
| 1968 | struct sk_buff *skb2; |
| 1969 | skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags); |
| 1970 | dev_kfree_skb_any (skb); |
| 1971 | skb = skb2; |
| 1972 | if (!skb) |
| 1973 | return NULL; |
| 1974 | } |
| 1975 | |
| 1976 | // attach the packet count to the header |
| 1977 | packet_count = (u32 *) skb_push (skb, (4 + 4*1)); |
| 1978 | packet_len = packet_count + 1; |
| 1979 | |
| 1980 | // FIXME little endian? |
| 1981 | *packet_count = 1; |
| 1982 | *packet_len = length; |
| 1983 | |
| 1984 | // add padding byte |
| 1985 | if ((skb->len % dev->maxpacket) == 0) |
| 1986 | skb_put (skb, 1); |
| 1987 | |
| 1988 | return skb; |
| 1989 | } |
| 1990 | |
| 1991 | static const struct driver_info genelink_info = { |
| 1992 | .description = "Genesys GeneLink", |
| 1993 | .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT, |
| 1994 | .rx_fixup = genelink_rx_fixup, |
| 1995 | .tx_fixup = genelink_tx_fixup, |
| 1996 | |
| 1997 | .in = 1, .out = 2, |
| 1998 | |
| 1999 | #ifdef GENELINK_ACK |
| 2000 | .check_connect =genelink_check_connect, |
| 2001 | #endif |
| 2002 | }; |
| 2003 | |
| 2004 | #endif /* CONFIG_USB_GENESYS */ |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | #ifdef CONFIG_USB_NET1080 |
| 2009 | #define HAVE_HARDWARE |
| 2010 | |
| 2011 | /*------------------------------------------------------------------------- |
| 2012 | * |
| 2013 | * Netchip 1080 driver ... http://www.netchip.com |
| 2014 | * Used in LapLink cables |
| 2015 | * |
| 2016 | *-------------------------------------------------------------------------*/ |
| 2017 | |
| 2018 | #define dev_packet_id data[0] |
| 2019 | #define frame_errors data[1] |
| 2020 | |
| 2021 | /* |
| 2022 | * NetChip framing of ethernet packets, supporting additional error |
| 2023 | * checks for links that may drop bulk packets from inside messages. |
| 2024 | * Odd USB length == always short read for last usb packet. |
| 2025 | * - nc_header |
| 2026 | * - Ethernet header (14 bytes) |
| 2027 | * - payload |
| 2028 | * - (optional padding byte, if needed so length becomes odd) |
| 2029 | * - nc_trailer |
| 2030 | * |
| 2031 | * This framing is to be avoided for non-NetChip devices. |
| 2032 | */ |
| 2033 | |
| 2034 | struct nc_header { // packed: |
| 2035 | __le16 hdr_len; // sizeof nc_header (LE, all) |
| 2036 | __le16 packet_len; // payload size (including ethhdr) |
| 2037 | __le16 packet_id; // detects dropped packets |
| 2038 | #define MIN_HEADER 6 |
| 2039 | |
| 2040 | // all else is optional, and must start with: |
| 2041 | // u16 vendorId; // from usb-if |
| 2042 | // u16 productId; |
| 2043 | } __attribute__((__packed__)); |
| 2044 | |
| 2045 | #define PAD_BYTE ((unsigned char)0xAC) |
| 2046 | |
| 2047 | struct nc_trailer { |
| 2048 | __le16 packet_id; |
| 2049 | } __attribute__((__packed__)); |
| 2050 | |
| 2051 | // packets may use FLAG_FRAMING_NC and optional pad |
| 2052 | #define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \ |
| 2053 | + sizeof (struct ethhdr) \ |
| 2054 | + (mtu) \ |
| 2055 | + 1 \ |
| 2056 | + sizeof (struct nc_trailer)) |
| 2057 | |
| 2058 | #define MIN_FRAMED FRAMED_SIZE(0) |
| 2059 | |
| 2060 | |
| 2061 | /* |
| 2062 | * Zero means no timeout; else, how long a 64 byte bulk packet may be queued |
| 2063 | * before the hardware drops it. If that's done, the driver will need to |
| 2064 | * frame network packets to guard against the dropped USB packets. The win32 |
| 2065 | * driver sets this for both sides of the link. |
| 2066 | */ |
| 2067 | #define NC_READ_TTL_MS ((u8)255) // ms |
| 2068 | |
| 2069 | /* |
| 2070 | * We ignore most registers and EEPROM contents. |
| 2071 | */ |
| 2072 | #define REG_USBCTL ((u8)0x04) |
| 2073 | #define REG_TTL ((u8)0x10) |
| 2074 | #define REG_STATUS ((u8)0x11) |
| 2075 | |
| 2076 | /* |
| 2077 | * Vendor specific requests to read/write data |
| 2078 | */ |
| 2079 | #define REQUEST_REGISTER ((u8)0x10) |
| 2080 | #define REQUEST_EEPROM ((u8)0x11) |
| 2081 | |
| 2082 | static int |
| 2083 | nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr) |
| 2084 | { |
| 2085 | int status = usb_control_msg (dev->udev, |
| 2086 | usb_rcvctrlpipe (dev->udev, 0), |
| 2087 | req, |
| 2088 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2089 | 0, regnum, |
| 2090 | retval_ptr, sizeof *retval_ptr, |
| 2091 | CONTROL_TIMEOUT_MS); |
| 2092 | if (status > 0) |
| 2093 | status = 0; |
| 2094 | if (!status) |
| 2095 | le16_to_cpus (retval_ptr); |
| 2096 | return status; |
| 2097 | } |
| 2098 | |
| 2099 | static inline int |
| 2100 | nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr) |
| 2101 | { |
| 2102 | return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr); |
| 2103 | } |
| 2104 | |
| 2105 | // no retval ... can become async, usable in_interrupt() |
| 2106 | static void |
| 2107 | nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value) |
| 2108 | { |
| 2109 | usb_control_msg (dev->udev, |
| 2110 | usb_sndctrlpipe (dev->udev, 0), |
| 2111 | req, |
| 2112 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2113 | value, regnum, |
| 2114 | NULL, 0, // data is in setup packet |
| 2115 | CONTROL_TIMEOUT_MS); |
| 2116 | } |
| 2117 | |
| 2118 | static inline void |
| 2119 | nc_register_write (struct usbnet *dev, u8 regnum, u16 value) |
| 2120 | { |
| 2121 | nc_vendor_write (dev, REQUEST_REGISTER, regnum, value); |
| 2122 | } |
| 2123 | |
| 2124 | |
| 2125 | #if 0 |
| 2126 | static void nc_dump_registers (struct usbnet *dev) |
| 2127 | { |
| 2128 | u8 reg; |
| 2129 | u16 *vp = kmalloc (sizeof (u16)); |
| 2130 | |
| 2131 | if (!vp) { |
| 2132 | dbg ("no memory?"); |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | dbg ("%s registers:", dev->net->name); |
| 2137 | for (reg = 0; reg < 0x20; reg++) { |
| 2138 | int retval; |
| 2139 | |
| 2140 | // reading some registers is trouble |
| 2141 | if (reg >= 0x08 && reg <= 0xf) |
| 2142 | continue; |
| 2143 | if (reg >= 0x12 && reg <= 0x1e) |
| 2144 | continue; |
| 2145 | |
| 2146 | retval = nc_register_read (dev, reg, vp); |
| 2147 | if (retval < 0) |
| 2148 | dbg ("%s reg [0x%x] ==> error %d", |
| 2149 | dev->net->name, reg, retval); |
| 2150 | else |
| 2151 | dbg ("%s reg [0x%x] = 0x%x", |
| 2152 | dev->net->name, reg, *vp); |
| 2153 | } |
| 2154 | kfree (vp); |
| 2155 | } |
| 2156 | #endif |
| 2157 | |
| 2158 | |
| 2159 | /*-------------------------------------------------------------------------*/ |
| 2160 | |
| 2161 | /* |
| 2162 | * Control register |
| 2163 | */ |
| 2164 | |
| 2165 | #define USBCTL_WRITABLE_MASK 0x1f0f |
| 2166 | // bits 15-13 reserved, r/o |
| 2167 | #define USBCTL_ENABLE_LANG (1 << 12) |
| 2168 | #define USBCTL_ENABLE_MFGR (1 << 11) |
| 2169 | #define USBCTL_ENABLE_PROD (1 << 10) |
| 2170 | #define USBCTL_ENABLE_SERIAL (1 << 9) |
| 2171 | #define USBCTL_ENABLE_DEFAULTS (1 << 8) |
| 2172 | // bits 7-4 reserved, r/o |
| 2173 | #define USBCTL_FLUSH_OTHER (1 << 3) |
| 2174 | #define USBCTL_FLUSH_THIS (1 << 2) |
| 2175 | #define USBCTL_DISCONN_OTHER (1 << 1) |
| 2176 | #define USBCTL_DISCONN_THIS (1 << 0) |
| 2177 | |
| 2178 | static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl) |
| 2179 | { |
| 2180 | if (!netif_msg_link (dev)) |
| 2181 | return; |
| 2182 | devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;" |
| 2183 | " this%s%s;" |
| 2184 | " other%s%s; r/o 0x%x", |
| 2185 | dev->udev->bus->bus_name, dev->udev->devpath, |
| 2186 | usbctl, |
| 2187 | (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "", |
| 2188 | (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "", |
| 2189 | (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "", |
| 2190 | (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "", |
| 2191 | (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "", |
| 2192 | |
| 2193 | (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "", |
| 2194 | (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "", |
| 2195 | (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "", |
| 2196 | (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "", |
| 2197 | usbctl & ~USBCTL_WRITABLE_MASK |
| 2198 | ); |
| 2199 | } |
| 2200 | |
| 2201 | /*-------------------------------------------------------------------------*/ |
| 2202 | |
| 2203 | /* |
| 2204 | * Status register |
| 2205 | */ |
| 2206 | |
| 2207 | #define STATUS_PORT_A (1 << 15) |
| 2208 | |
| 2209 | #define STATUS_CONN_OTHER (1 << 14) |
| 2210 | #define STATUS_SUSPEND_OTHER (1 << 13) |
| 2211 | #define STATUS_MAILBOX_OTHER (1 << 12) |
| 2212 | #define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03) |
| 2213 | |
| 2214 | #define STATUS_CONN_THIS (1 << 6) |
| 2215 | #define STATUS_SUSPEND_THIS (1 << 5) |
| 2216 | #define STATUS_MAILBOX_THIS (1 << 4) |
| 2217 | #define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03) |
| 2218 | |
| 2219 | #define STATUS_UNSPEC_MASK 0x0c8c |
| 2220 | #define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK)) |
| 2221 | |
| 2222 | |
| 2223 | static inline void nc_dump_status (struct usbnet *dev, u16 status) |
| 2224 | { |
| 2225 | if (!netif_msg_link (dev)) |
| 2226 | return; |
| 2227 | devdbg (dev, "net1080 %s-%s status 0x%x:" |
| 2228 | " this (%c) PKT=%d%s%s%s;" |
| 2229 | " other PKT=%d%s%s%s; unspec 0x%x", |
| 2230 | dev->udev->bus->bus_name, dev->udev->devpath, |
| 2231 | status, |
| 2232 | |
| 2233 | // XXX the packet counts don't seem right |
| 2234 | // (1 at reset, not 0); maybe UNSPEC too |
| 2235 | |
| 2236 | (status & STATUS_PORT_A) ? 'A' : 'B', |
| 2237 | STATUS_PACKETS_THIS (status), |
| 2238 | (status & STATUS_CONN_THIS) ? " CON" : "", |
| 2239 | (status & STATUS_SUSPEND_THIS) ? " SUS" : "", |
| 2240 | (status & STATUS_MAILBOX_THIS) ? " MBOX" : "", |
| 2241 | |
| 2242 | STATUS_PACKETS_OTHER (status), |
| 2243 | (status & STATUS_CONN_OTHER) ? " CON" : "", |
| 2244 | (status & STATUS_SUSPEND_OTHER) ? " SUS" : "", |
| 2245 | (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "", |
| 2246 | |
| 2247 | status & STATUS_UNSPEC_MASK |
| 2248 | ); |
| 2249 | } |
| 2250 | |
| 2251 | /*-------------------------------------------------------------------------*/ |
| 2252 | |
| 2253 | /* |
| 2254 | * TTL register |
| 2255 | */ |
| 2256 | |
| 2257 | #define TTL_THIS(ttl) (0x00ff & ttl) |
| 2258 | #define TTL_OTHER(ttl) (0x00ff & (ttl >> 8)) |
| 2259 | #define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this)))) |
| 2260 | |
| 2261 | static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl) |
| 2262 | { |
| 2263 | if (netif_msg_link (dev)) |
| 2264 | devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d", |
| 2265 | dev->udev->bus->bus_name, dev->udev->devpath, |
| 2266 | ttl, TTL_THIS (ttl), TTL_OTHER (ttl)); |
| 2267 | } |
| 2268 | |
| 2269 | /*-------------------------------------------------------------------------*/ |
| 2270 | |
| 2271 | static int net1080_reset (struct usbnet *dev) |
| 2272 | { |
| 2273 | u16 usbctl, status, ttl; |
| 2274 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); |
| 2275 | int retval; |
| 2276 | |
| 2277 | if (!vp) |
| 2278 | return -ENOMEM; |
| 2279 | |
| 2280 | // nc_dump_registers (dev); |
| 2281 | |
| 2282 | if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) { |
| 2283 | dbg ("can't read %s-%s status: %d", |
| 2284 | dev->udev->bus->bus_name, dev->udev->devpath, retval); |
| 2285 | goto done; |
| 2286 | } |
| 2287 | status = *vp; |
| 2288 | nc_dump_status (dev, status); |
| 2289 | |
| 2290 | if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) { |
| 2291 | dbg ("can't read USBCTL, %d", retval); |
| 2292 | goto done; |
| 2293 | } |
| 2294 | usbctl = *vp; |
| 2295 | nc_dump_usbctl (dev, usbctl); |
| 2296 | |
| 2297 | nc_register_write (dev, REG_USBCTL, |
| 2298 | USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER); |
| 2299 | |
| 2300 | if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) { |
| 2301 | dbg ("can't read TTL, %d", retval); |
| 2302 | goto done; |
| 2303 | } |
| 2304 | ttl = *vp; |
| 2305 | // nc_dump_ttl (dev, ttl); |
| 2306 | |
| 2307 | nc_register_write (dev, REG_TTL, |
| 2308 | MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) ); |
| 2309 | dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS); |
| 2310 | |
| 2311 | if (netif_msg_link (dev)) |
| 2312 | devinfo (dev, "port %c, peer %sconnected", |
| 2313 | (status & STATUS_PORT_A) ? 'A' : 'B', |
| 2314 | (status & STATUS_CONN_OTHER) ? "" : "dis" |
| 2315 | ); |
| 2316 | retval = 0; |
| 2317 | |
| 2318 | done: |
| 2319 | kfree (vp); |
| 2320 | return retval; |
| 2321 | } |
| 2322 | |
| 2323 | static int net1080_check_connect (struct usbnet *dev) |
| 2324 | { |
| 2325 | int retval; |
| 2326 | u16 status; |
| 2327 | u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL); |
| 2328 | |
| 2329 | if (!vp) |
| 2330 | return -ENOMEM; |
| 2331 | retval = nc_register_read (dev, REG_STATUS, vp); |
| 2332 | status = *vp; |
| 2333 | kfree (vp); |
| 2334 | if (retval != 0) { |
| 2335 | dbg ("%s net1080_check_conn read - %d", dev->net->name, retval); |
| 2336 | return retval; |
| 2337 | } |
| 2338 | if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER) |
| 2339 | return -ENOLINK; |
| 2340 | return 0; |
| 2341 | } |
| 2342 | |
| 2343 | static void nc_flush_complete (struct urb *urb, struct pt_regs *regs) |
| 2344 | { |
| 2345 | kfree (urb->context); |
| 2346 | usb_free_urb(urb); |
| 2347 | } |
| 2348 | |
| 2349 | static void nc_ensure_sync (struct usbnet *dev) |
| 2350 | { |
| 2351 | dev->frame_errors++; |
| 2352 | if (dev->frame_errors > 5) { |
| 2353 | struct urb *urb; |
| 2354 | struct usb_ctrlrequest *req; |
| 2355 | int status; |
| 2356 | |
| 2357 | /* Send a flush */ |
| 2358 | urb = usb_alloc_urb (0, SLAB_ATOMIC); |
| 2359 | if (!urb) |
| 2360 | return; |
| 2361 | |
| 2362 | req = kmalloc (sizeof *req, GFP_ATOMIC); |
| 2363 | if (!req) { |
| 2364 | usb_free_urb (urb); |
| 2365 | return; |
| 2366 | } |
| 2367 | |
| 2368 | req->bRequestType = USB_DIR_OUT |
| 2369 | | USB_TYPE_VENDOR |
| 2370 | | USB_RECIP_DEVICE; |
| 2371 | req->bRequest = REQUEST_REGISTER; |
| 2372 | req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS |
| 2373 | | USBCTL_FLUSH_OTHER); |
| 2374 | req->wIndex = cpu_to_le16 (REG_USBCTL); |
| 2375 | req->wLength = cpu_to_le16 (0); |
| 2376 | |
| 2377 | /* queue an async control request, we don't need |
| 2378 | * to do anything when it finishes except clean up. |
| 2379 | */ |
| 2380 | usb_fill_control_urb (urb, dev->udev, |
| 2381 | usb_sndctrlpipe (dev->udev, 0), |
| 2382 | (unsigned char *) req, |
| 2383 | NULL, 0, |
| 2384 | nc_flush_complete, req); |
| 2385 | status = usb_submit_urb (urb, GFP_ATOMIC); |
| 2386 | if (status) { |
| 2387 | kfree (req); |
| 2388 | usb_free_urb (urb); |
| 2389 | return; |
| 2390 | } |
| 2391 | |
| 2392 | if (netif_msg_rx_err (dev)) |
| 2393 | devdbg (dev, "flush net1080; too many framing errors"); |
| 2394 | dev->frame_errors = 0; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb) |
| 2399 | { |
| 2400 | struct nc_header *header; |
| 2401 | struct nc_trailer *trailer; |
| 2402 | u16 hdr_len, packet_len; |
| 2403 | |
| 2404 | if (!(skb->len & 0x01) |
| 2405 | || MIN_FRAMED > skb->len |
| 2406 | || skb->len > FRAMED_SIZE (dev->net->mtu)) { |
| 2407 | dev->stats.rx_frame_errors++; |
| 2408 | dbg ("rx framesize %d range %d..%d mtu %d", skb->len, |
| 2409 | (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu), |
| 2410 | dev->net->mtu); |
| 2411 | nc_ensure_sync (dev); |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | header = (struct nc_header *) skb->data; |
| 2416 | hdr_len = le16_to_cpup (&header->hdr_len); |
| 2417 | packet_len = le16_to_cpup (&header->packet_len); |
| 2418 | if (FRAMED_SIZE (packet_len) > MAX_PACKET) { |
| 2419 | dev->stats.rx_frame_errors++; |
| 2420 | dbg ("packet too big, %d", packet_len); |
| 2421 | nc_ensure_sync (dev); |
| 2422 | return 0; |
| 2423 | } else if (hdr_len < MIN_HEADER) { |
| 2424 | dev->stats.rx_frame_errors++; |
| 2425 | dbg ("header too short, %d", hdr_len); |
| 2426 | nc_ensure_sync (dev); |
| 2427 | return 0; |
| 2428 | } else if (hdr_len > MIN_HEADER) { |
| 2429 | // out of band data for us? |
| 2430 | dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER); |
| 2431 | nc_ensure_sync (dev); |
| 2432 | // switch (vendor/product ids) { ... } |
| 2433 | } |
| 2434 | skb_pull (skb, hdr_len); |
| 2435 | |
| 2436 | trailer = (struct nc_trailer *) |
| 2437 | (skb->data + skb->len - sizeof *trailer); |
| 2438 | skb_trim (skb, skb->len - sizeof *trailer); |
| 2439 | |
| 2440 | if ((packet_len & 0x01) == 0) { |
| 2441 | if (skb->data [packet_len] != PAD_BYTE) { |
| 2442 | dev->stats.rx_frame_errors++; |
| 2443 | dbg ("bad pad"); |
| 2444 | return 0; |
| 2445 | } |
| 2446 | skb_trim (skb, skb->len - 1); |
| 2447 | } |
| 2448 | if (skb->len != packet_len) { |
| 2449 | dev->stats.rx_frame_errors++; |
| 2450 | dbg ("bad packet len %d (expected %d)", |
| 2451 | skb->len, packet_len); |
| 2452 | nc_ensure_sync (dev); |
| 2453 | return 0; |
| 2454 | } |
| 2455 | if (header->packet_id != get_unaligned (&trailer->packet_id)) { |
| 2456 | dev->stats.rx_fifo_errors++; |
| 2457 | dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x", |
| 2458 | le16_to_cpu (header->packet_id), |
| 2459 | le16_to_cpu (trailer->packet_id)); |
| 2460 | return 0; |
| 2461 | } |
| 2462 | #if 0 |
| 2463 | devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len, |
| 2464 | header->packet_len, header->packet_id); |
| 2465 | #endif |
| 2466 | dev->frame_errors = 0; |
| 2467 | return 1; |
| 2468 | } |
| 2469 | |
| 2470 | static struct sk_buff * |
| 2471 | net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) |
| 2472 | { |
| 2473 | int padlen; |
| 2474 | struct sk_buff *skb2; |
| 2475 | |
| 2476 | padlen = ((skb->len + sizeof (struct nc_header) |
| 2477 | + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1; |
| 2478 | if (!skb_cloned (skb)) { |
| 2479 | int headroom = skb_headroom (skb); |
| 2480 | int tailroom = skb_tailroom (skb); |
| 2481 | |
| 2482 | if ((padlen + sizeof (struct nc_trailer)) <= tailroom |
| 2483 | && sizeof (struct nc_header) <= headroom) |
| 2484 | /* There's enough head and tail room */ |
| 2485 | return skb; |
| 2486 | |
| 2487 | if ((sizeof (struct nc_header) + padlen |
| 2488 | + sizeof (struct nc_trailer)) < |
| 2489 | (headroom + tailroom)) { |
| 2490 | /* There's enough total room, so just readjust */ |
| 2491 | skb->data = memmove (skb->head |
| 2492 | + sizeof (struct nc_header), |
| 2493 | skb->data, skb->len); |
| 2494 | skb->tail = skb->data + skb->len; |
| 2495 | return skb; |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | /* Create a new skb to use with the correct size */ |
| 2500 | skb2 = skb_copy_expand (skb, |
| 2501 | sizeof (struct nc_header), |
| 2502 | sizeof (struct nc_trailer) + padlen, |
| 2503 | flags); |
| 2504 | dev_kfree_skb_any (skb); |
| 2505 | return skb2; |
| 2506 | } |
| 2507 | |
| 2508 | static const struct driver_info net1080_info = { |
| 2509 | .description = "NetChip TurboCONNECT", |
| 2510 | .flags = FLAG_FRAMING_NC, |
| 2511 | .reset = net1080_reset, |
| 2512 | .check_connect =net1080_check_connect, |
| 2513 | .rx_fixup = net1080_rx_fixup, |
| 2514 | .tx_fixup = net1080_tx_fixup, |
| 2515 | }; |
| 2516 | |
| 2517 | #endif /* CONFIG_USB_NET1080 */ |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | #ifdef CONFIG_USB_PL2301 |
| 2522 | #define HAVE_HARDWARE |
| 2523 | |
| 2524 | /*------------------------------------------------------------------------- |
| 2525 | * |
| 2526 | * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com |
| 2527 | * |
| 2528 | * The protocol and handshaking used here should be bug-compatible |
| 2529 | * with the Linux 2.2 "plusb" driver, by Deti Fliegl. |
| 2530 | * |
| 2531 | *-------------------------------------------------------------------------*/ |
| 2532 | |
| 2533 | /* |
| 2534 | * Bits 0-4 can be used for software handshaking; they're set from |
| 2535 | * one end, cleared from the other, "read" with the interrupt byte. |
| 2536 | */ |
| 2537 | #define PL_S_EN (1<<7) /* (feature only) suspend enable */ |
| 2538 | /* reserved bit -- rx ready (6) ? */ |
| 2539 | #define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */ |
| 2540 | #define PL_RESET_OUT (1<<4) /* reset output pipe */ |
| 2541 | #define PL_RESET_IN (1<<3) /* reset input pipe */ |
| 2542 | #define PL_TX_C (1<<2) /* transmission complete */ |
| 2543 | #define PL_TX_REQ (1<<1) /* transmission received */ |
| 2544 | #define PL_PEER_E (1<<0) /* peer exists */ |
| 2545 | |
| 2546 | static inline int |
| 2547 | pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index) |
| 2548 | { |
| 2549 | return usb_control_msg (dev->udev, |
| 2550 | usb_rcvctrlpipe (dev->udev, 0), |
| 2551 | req, |
| 2552 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2553 | val, index, |
| 2554 | NULL, 0, |
| 2555 | CONTROL_TIMEOUT_MS); |
| 2556 | } |
| 2557 | |
| 2558 | static inline int |
| 2559 | pl_clear_QuickLink_features (struct usbnet *dev, int val) |
| 2560 | { |
| 2561 | return pl_vendor_req (dev, 1, (u8) val, 0); |
| 2562 | } |
| 2563 | |
| 2564 | static inline int |
| 2565 | pl_set_QuickLink_features (struct usbnet *dev, int val) |
| 2566 | { |
| 2567 | return pl_vendor_req (dev, 3, (u8) val, 0); |
| 2568 | } |
| 2569 | |
| 2570 | /*-------------------------------------------------------------------------*/ |
| 2571 | |
| 2572 | static int pl_reset (struct usbnet *dev) |
| 2573 | { |
| 2574 | /* some units seem to need this reset, others reject it utterly. |
| 2575 | * FIXME be more like "naplink" or windows drivers. |
| 2576 | */ |
| 2577 | (void) pl_set_QuickLink_features (dev, |
| 2578 | PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E); |
| 2579 | return 0; |
| 2580 | } |
| 2581 | |
| 2582 | static const struct driver_info prolific_info = { |
| 2583 | .description = "Prolific PL-2301/PL-2302", |
| 2584 | .flags = FLAG_NO_SETINT, |
| 2585 | /* some PL-2302 versions seem to fail usb_set_interface() */ |
| 2586 | .reset = pl_reset, |
| 2587 | }; |
| 2588 | |
| 2589 | #endif /* CONFIG_USB_PL2301 */ |
| 2590 | |
| 2591 | |
| 2592 | #ifdef CONFIG_USB_KC2190 |
| 2593 | #define HAVE_HARDWARE |
| 2594 | static const struct driver_info kc2190_info = { |
| 2595 | .description = "KC Technology KC-190", |
| 2596 | }; |
| 2597 | #endif /* CONFIG_USB_KC2190 */ |
| 2598 | |
| 2599 | |
| 2600 | #ifdef CONFIG_USB_ARMLINUX |
| 2601 | #define HAVE_HARDWARE |
| 2602 | |
| 2603 | /*------------------------------------------------------------------------- |
| 2604 | * |
| 2605 | * Intel's SA-1100 chip integrates basic USB support, and is used |
| 2606 | * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more. |
| 2607 | * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to |
| 2608 | * network using minimal USB framing data. |
| 2609 | * |
| 2610 | * This describes the driver currently in standard ARM Linux kernels. |
| 2611 | * The Zaurus uses a different driver (see later). |
| 2612 | * |
| 2613 | * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support |
| 2614 | * and different USB endpoint numbering than the SA1100 devices. The |
| 2615 | * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100 |
| 2616 | * so we rely on the endpoint descriptors. |
| 2617 | * |
| 2618 | *-------------------------------------------------------------------------*/ |
| 2619 | |
| 2620 | static const struct driver_info linuxdev_info = { |
| 2621 | .description = "Linux Device", |
| 2622 | .check_connect = always_connected, |
| 2623 | }; |
| 2624 | |
| 2625 | static const struct driver_info yopy_info = { |
| 2626 | .description = "Yopy", |
| 2627 | .check_connect = always_connected, |
| 2628 | }; |
| 2629 | |
| 2630 | static const struct driver_info blob_info = { |
| 2631 | .description = "Boot Loader OBject", |
| 2632 | .check_connect = always_connected, |
| 2633 | }; |
| 2634 | |
| 2635 | #endif /* CONFIG_USB_ARMLINUX */ |
| 2636 | |
| 2637 | |
| 2638 | #ifdef CONFIG_USB_ZAURUS |
| 2639 | #define HAVE_HARDWARE |
| 2640 | |
| 2641 | #include <linux/crc32.h> |
| 2642 | |
| 2643 | /*------------------------------------------------------------------------- |
| 2644 | * |
| 2645 | * Zaurus is also a SA-1110 based PDA, but one using a different driver |
| 2646 | * (and framing) for its USB slave/gadget controller than the case above. |
| 2647 | * |
| 2648 | * For the current version of that driver, the main way that framing is |
| 2649 | * nonstandard (also from perspective of the CDC ethernet model!) is a |
| 2650 | * crc32, added to help detect when some sa1100 usb-to-memory DMA errata |
| 2651 | * haven't been fully worked around. Also, all Zaurii use the same |
| 2652 | * default Ethernet address. |
| 2653 | * |
| 2654 | * PXA based models use the same framing, and also can't implement |
| 2655 | * set_interface properly. |
| 2656 | * |
| 2657 | * All known Zaurii lie about their standards conformance. Most lie by |
| 2658 | * saying they support CDC Ethernet. Some lie and say they support CDC |
| 2659 | * MDLM (as if for access to cell phone modems). Someone, please beat |
| 2660 | * on Sharp for a while with a cluestick. |
| 2661 | * |
| 2662 | *-------------------------------------------------------------------------*/ |
| 2663 | |
| 2664 | static struct sk_buff * |
| 2665 | zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags) |
| 2666 | { |
| 2667 | int padlen; |
| 2668 | struct sk_buff *skb2; |
| 2669 | |
| 2670 | padlen = 2; |
| 2671 | if (!skb_cloned (skb)) { |
| 2672 | int tailroom = skb_tailroom (skb); |
| 2673 | if ((padlen + 4) <= tailroom) |
| 2674 | goto done; |
| 2675 | } |
| 2676 | skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags); |
| 2677 | dev_kfree_skb_any (skb); |
| 2678 | skb = skb2; |
| 2679 | if (skb) { |
| 2680 | u32 fcs; |
| 2681 | done: |
| 2682 | fcs = crc32_le (~0, skb->data, skb->len); |
| 2683 | fcs = ~fcs; |
| 2684 | |
| 2685 | *skb_put (skb, 1) = fcs & 0xff; |
| 2686 | *skb_put (skb, 1) = (fcs>> 8) & 0xff; |
| 2687 | *skb_put (skb, 1) = (fcs>>16) & 0xff; |
| 2688 | *skb_put (skb, 1) = (fcs>>24) & 0xff; |
| 2689 | } |
| 2690 | return skb; |
| 2691 | } |
| 2692 | |
| 2693 | static const struct driver_info zaurus_sl5x00_info = { |
| 2694 | .description = "Sharp Zaurus SL-5x00", |
| 2695 | .flags = FLAG_FRAMING_Z, |
| 2696 | .check_connect = always_connected, |
| 2697 | .bind = generic_cdc_bind, |
| 2698 | .unbind = cdc_unbind, |
| 2699 | .tx_fixup = zaurus_tx_fixup, |
| 2700 | }; |
| 2701 | #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info) |
| 2702 | |
| 2703 | static const struct driver_info zaurus_pxa_info = { |
| 2704 | .description = "Sharp Zaurus, PXA-2xx based", |
| 2705 | .flags = FLAG_FRAMING_Z, |
| 2706 | .check_connect = always_connected, |
| 2707 | .bind = generic_cdc_bind, |
| 2708 | .unbind = cdc_unbind, |
| 2709 | .tx_fixup = zaurus_tx_fixup, |
| 2710 | }; |
| 2711 | #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info) |
| 2712 | |
| 2713 | static const struct driver_info zaurus_pxa_mdlm_info = { |
| 2714 | .description = "Sharp Zaurus, PXA-255 based", |
| 2715 | .flags = FLAG_FRAMING_Z, |
| 2716 | .check_connect = always_connected, |
| 2717 | .tx_fixup = zaurus_tx_fixup, |
| 2718 | }; |
| 2719 | |
| 2720 | static const struct driver_info olympus_mxl_info = { |
| 2721 | .description = "Olympus R1000", |
| 2722 | .flags = FLAG_FRAMING_Z, |
| 2723 | .check_connect = always_connected, |
| 2724 | .bind = generic_cdc_bind, |
| 2725 | .unbind = cdc_unbind, |
| 2726 | .tx_fixup = zaurus_tx_fixup, |
| 2727 | }; |
| 2728 | #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info) |
| 2729 | |
| 2730 | #else |
| 2731 | |
| 2732 | /* blacklist all those devices */ |
| 2733 | #define ZAURUS_STRONGARM_INFO 0 |
| 2734 | #define ZAURUS_PXA_INFO 0 |
| 2735 | #define OLYMPUS_MXL_INFO 0 |
| 2736 | |
| 2737 | #endif |
| 2738 | |
| 2739 | |
| 2740 | /*------------------------------------------------------------------------- |
| 2741 | * |
| 2742 | * Network Device Driver (peer link to "Host Device", from USB host) |
| 2743 | * |
| 2744 | *-------------------------------------------------------------------------*/ |
| 2745 | |
| 2746 | static int usbnet_change_mtu (struct net_device *net, int new_mtu) |
| 2747 | { |
| 2748 | struct usbnet *dev = netdev_priv(net); |
| 2749 | |
| 2750 | if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET) |
| 2751 | return -EINVAL; |
| 2752 | #ifdef CONFIG_USB_NET1080 |
| 2753 | if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) { |
| 2754 | if (FRAMED_SIZE (new_mtu) > MAX_PACKET) |
| 2755 | return -EINVAL; |
| 2756 | } |
| 2757 | #endif |
| 2758 | #ifdef CONFIG_USB_GENESYS |
| 2759 | if (((dev->driver_info->flags) & FLAG_FRAMING_GL) |
| 2760 | && new_mtu > GL_MAX_PACKET_LEN) |
| 2761 | return -EINVAL; |
| 2762 | #endif |
| 2763 | // no second zero-length packet read wanted after mtu-sized packets |
| 2764 | if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0) |
| 2765 | return -EDOM; |
| 2766 | net->mtu = new_mtu; |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | /*-------------------------------------------------------------------------*/ |
| 2771 | |
| 2772 | static struct net_device_stats *usbnet_get_stats (struct net_device *net) |
| 2773 | { |
| 2774 | struct usbnet *dev = netdev_priv(net); |
| 2775 | return &dev->stats; |
| 2776 | } |
| 2777 | |
| 2778 | /*-------------------------------------------------------------------------*/ |
| 2779 | |
| 2780 | /* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from |
| 2781 | * completion callbacks. 2.5 should have fixed those bugs... |
| 2782 | */ |
| 2783 | |
| 2784 | static void defer_bh (struct usbnet *dev, struct sk_buff *skb) |
| 2785 | { |
| 2786 | struct sk_buff_head *list = skb->list; |
| 2787 | unsigned long flags; |
| 2788 | |
| 2789 | spin_lock_irqsave (&list->lock, flags); |
| 2790 | __skb_unlink (skb, list); |
| 2791 | spin_unlock (&list->lock); |
| 2792 | spin_lock (&dev->done.lock); |
| 2793 | __skb_queue_tail (&dev->done, skb); |
| 2794 | if (dev->done.qlen == 1) |
| 2795 | tasklet_schedule (&dev->bh); |
| 2796 | spin_unlock_irqrestore (&dev->done.lock, flags); |
| 2797 | } |
| 2798 | |
| 2799 | /* some work can't be done in tasklets, so we use keventd |
| 2800 | * |
| 2801 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, |
| 2802 | * but tasklet_schedule() doesn't. hope the failure is rare. |
| 2803 | */ |
| 2804 | static void defer_kevent (struct usbnet *dev, int work) |
| 2805 | { |
| 2806 | set_bit (work, &dev->flags); |
| 2807 | if (!schedule_work (&dev->kevent)) |
| 2808 | deverr (dev, "kevent %d may have been dropped", work); |
| 2809 | else |
| 2810 | devdbg (dev, "kevent %d scheduled", work); |
| 2811 | } |
| 2812 | |
| 2813 | /*-------------------------------------------------------------------------*/ |
| 2814 | |
| 2815 | static void rx_complete (struct urb *urb, struct pt_regs *regs); |
| 2816 | |
| 2817 | static void rx_submit (struct usbnet *dev, struct urb *urb, int flags) |
| 2818 | { |
| 2819 | struct sk_buff *skb; |
| 2820 | struct skb_data *entry; |
| 2821 | int retval = 0; |
| 2822 | unsigned long lockflags; |
| 2823 | size_t size; |
| 2824 | |
| 2825 | #ifdef CONFIG_USB_NET1080 |
| 2826 | if (dev->driver_info->flags & FLAG_FRAMING_NC) |
| 2827 | size = FRAMED_SIZE (dev->net->mtu); |
| 2828 | else |
| 2829 | #endif |
| 2830 | #ifdef CONFIG_USB_GENESYS |
| 2831 | if (dev->driver_info->flags & FLAG_FRAMING_GL) |
| 2832 | size = GL_RCV_BUF_SIZE; |
| 2833 | else |
| 2834 | #endif |
| 2835 | #ifdef CONFIG_USB_ZAURUS |
| 2836 | if (dev->driver_info->flags & FLAG_FRAMING_Z) |
| 2837 | size = 6 + (sizeof (struct ethhdr) + dev->net->mtu); |
| 2838 | else |
| 2839 | #endif |
| 2840 | #ifdef CONFIG_USB_RNDIS |
| 2841 | if (dev->driver_info->flags & FLAG_FRAMING_RN) |
| 2842 | size = RNDIS_MAX_TRANSFER; |
| 2843 | else |
| 2844 | #endif |
| 2845 | #ifdef CONFIG_USB_AX8817X |
| 2846 | if (dev->driver_info->flags & FLAG_FRAMING_AX) |
| 2847 | size = 2048; |
| 2848 | else |
| 2849 | #endif |
| 2850 | size = (sizeof (struct ethhdr) + dev->net->mtu); |
| 2851 | |
| 2852 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { |
| 2853 | if (netif_msg_rx_err (dev)) |
| 2854 | devdbg (dev, "no rx skb"); |
| 2855 | defer_kevent (dev, EVENT_RX_MEMORY); |
| 2856 | usb_free_urb (urb); |
| 2857 | return; |
| 2858 | } |
| 2859 | skb_reserve (skb, NET_IP_ALIGN); |
| 2860 | |
| 2861 | entry = (struct skb_data *) skb->cb; |
| 2862 | entry->urb = urb; |
| 2863 | entry->dev = dev; |
| 2864 | entry->state = rx_start; |
| 2865 | entry->length = 0; |
| 2866 | |
| 2867 | usb_fill_bulk_urb (urb, dev->udev, dev->in, |
| 2868 | skb->data, size, rx_complete, skb); |
| 2869 | urb->transfer_flags |= URB_ASYNC_UNLINK; |
| 2870 | |
| 2871 | spin_lock_irqsave (&dev->rxq.lock, lockflags); |
| 2872 | |
| 2873 | if (netif_running (dev->net) |
| 2874 | && netif_device_present (dev->net) |
| 2875 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
| 2876 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ |
| 2877 | case -EPIPE: |
| 2878 | defer_kevent (dev, EVENT_RX_HALT); |
| 2879 | break; |
| 2880 | case -ENOMEM: |
| 2881 | defer_kevent (dev, EVENT_RX_MEMORY); |
| 2882 | break; |
| 2883 | case -ENODEV: |
| 2884 | if (netif_msg_ifdown (dev)) |
| 2885 | devdbg (dev, "device gone"); |
| 2886 | netif_device_detach (dev->net); |
| 2887 | break; |
| 2888 | default: |
| 2889 | if (netif_msg_rx_err (dev)) |
| 2890 | devdbg (dev, "rx submit, %d", retval); |
| 2891 | tasklet_schedule (&dev->bh); |
| 2892 | break; |
| 2893 | case 0: |
| 2894 | __skb_queue_tail (&dev->rxq, skb); |
| 2895 | } |
| 2896 | } else { |
| 2897 | if (netif_msg_ifdown (dev)) |
| 2898 | devdbg (dev, "rx: stopped"); |
| 2899 | retval = -ENOLINK; |
| 2900 | } |
| 2901 | spin_unlock_irqrestore (&dev->rxq.lock, lockflags); |
| 2902 | if (retval) { |
| 2903 | dev_kfree_skb_any (skb); |
| 2904 | usb_free_urb (urb); |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | |
| 2909 | /*-------------------------------------------------------------------------*/ |
| 2910 | |
| 2911 | static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) |
| 2912 | { |
| 2913 | if (dev->driver_info->rx_fixup |
| 2914 | && !dev->driver_info->rx_fixup (dev, skb)) |
| 2915 | goto error; |
| 2916 | // else network stack removes extra byte if we forced a short packet |
| 2917 | |
| 2918 | if (skb->len) |
| 2919 | skb_return (dev, skb); |
| 2920 | else { |
| 2921 | if (netif_msg_rx_err (dev)) |
| 2922 | devdbg (dev, "drop"); |
| 2923 | error: |
| 2924 | dev->stats.rx_errors++; |
| 2925 | skb_queue_tail (&dev->done, skb); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | /*-------------------------------------------------------------------------*/ |
| 2930 | |
| 2931 | static void rx_complete (struct urb *urb, struct pt_regs *regs) |
| 2932 | { |
| 2933 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
| 2934 | struct skb_data *entry = (struct skb_data *) skb->cb; |
| 2935 | struct usbnet *dev = entry->dev; |
| 2936 | int urb_status = urb->status; |
| 2937 | |
| 2938 | skb_put (skb, urb->actual_length); |
| 2939 | entry->state = rx_done; |
| 2940 | entry->urb = NULL; |
| 2941 | |
| 2942 | switch (urb_status) { |
| 2943 | // success |
| 2944 | case 0: |
| 2945 | if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) { |
| 2946 | entry->state = rx_cleanup; |
| 2947 | dev->stats.rx_errors++; |
| 2948 | dev->stats.rx_length_errors++; |
| 2949 | if (netif_msg_rx_err (dev)) |
| 2950 | devdbg (dev, "rx length %d", skb->len); |
| 2951 | } |
| 2952 | break; |
| 2953 | |
| 2954 | // stalls need manual reset. this is rare ... except that |
| 2955 | // when going through USB 2.0 TTs, unplug appears this way. |
| 2956 | // we avoid the highspeed version of the ETIMEOUT/EILSEQ |
| 2957 | // storm, recovering as needed. |
| 2958 | case -EPIPE: |
| 2959 | dev->stats.rx_errors++; |
| 2960 | defer_kevent (dev, EVENT_RX_HALT); |
| 2961 | // FALLTHROUGH |
| 2962 | |
| 2963 | // software-driven interface shutdown |
| 2964 | case -ECONNRESET: // async unlink |
| 2965 | case -ESHUTDOWN: // hardware gone |
| 2966 | if (netif_msg_ifdown (dev)) |
| 2967 | devdbg (dev, "rx shutdown, code %d", urb_status); |
| 2968 | goto block; |
| 2969 | |
| 2970 | // we get controller i/o faults during khubd disconnect() delays. |
| 2971 | // throttle down resubmits, to avoid log floods; just temporarily, |
| 2972 | // so we still recover when the fault isn't a khubd delay. |
| 2973 | case -EPROTO: // ehci |
| 2974 | case -ETIMEDOUT: // ohci |
| 2975 | case -EILSEQ: // uhci |
| 2976 | dev->stats.rx_errors++; |
| 2977 | if (!timer_pending (&dev->delay)) { |
| 2978 | mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES); |
| 2979 | if (netif_msg_link (dev)) |
| 2980 | devdbg (dev, "rx throttle %d", urb_status); |
| 2981 | } |
| 2982 | block: |
| 2983 | entry->state = rx_cleanup; |
| 2984 | entry->urb = urb; |
| 2985 | urb = NULL; |
| 2986 | break; |
| 2987 | |
| 2988 | // data overrun ... flush fifo? |
| 2989 | case -EOVERFLOW: |
| 2990 | dev->stats.rx_over_errors++; |
| 2991 | // FALLTHROUGH |
| 2992 | |
| 2993 | default: |
| 2994 | entry->state = rx_cleanup; |
| 2995 | dev->stats.rx_errors++; |
| 2996 | if (netif_msg_rx_err (dev)) |
| 2997 | devdbg (dev, "rx status %d", urb_status); |
| 2998 | break; |
| 2999 | } |
| 3000 | |
| 3001 | defer_bh (dev, skb); |
| 3002 | |
| 3003 | if (urb) { |
| 3004 | if (netif_running (dev->net) |
| 3005 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
| 3006 | rx_submit (dev, urb, GFP_ATOMIC); |
| 3007 | return; |
| 3008 | } |
| 3009 | usb_free_urb (urb); |
| 3010 | } |
| 3011 | if (netif_msg_rx_err (dev)) |
| 3012 | devdbg (dev, "no read resubmitted"); |
| 3013 | } |
| 3014 | |
| 3015 | static void intr_complete (struct urb *urb, struct pt_regs *regs) |
| 3016 | { |
| 3017 | struct usbnet *dev = urb->context; |
| 3018 | int status = urb->status; |
| 3019 | |
| 3020 | switch (status) { |
| 3021 | /* success */ |
| 3022 | case 0: |
| 3023 | dev->driver_info->status(dev, urb); |
| 3024 | break; |
| 3025 | |
| 3026 | /* software-driven interface shutdown */ |
| 3027 | case -ENOENT: // urb killed |
| 3028 | case -ESHUTDOWN: // hardware gone |
| 3029 | if (netif_msg_ifdown (dev)) |
| 3030 | devdbg (dev, "intr shutdown, code %d", status); |
| 3031 | return; |
| 3032 | |
| 3033 | /* NOTE: not throttling like RX/TX, since this endpoint |
| 3034 | * already polls infrequently |
| 3035 | */ |
| 3036 | default: |
| 3037 | devdbg (dev, "intr status %d", status); |
| 3038 | break; |
| 3039 | } |
| 3040 | |
| 3041 | if (!netif_running (dev->net)) |
| 3042 | return; |
| 3043 | |
| 3044 | memset(urb->transfer_buffer, 0, urb->transfer_buffer_length); |
| 3045 | status = usb_submit_urb (urb, GFP_ATOMIC); |
| 3046 | if (status != 0 && netif_msg_timer (dev)) |
| 3047 | deverr(dev, "intr resubmit --> %d", status); |
| 3048 | } |
| 3049 | |
| 3050 | /*-------------------------------------------------------------------------*/ |
| 3051 | |
| 3052 | // unlink pending rx/tx; completion handlers do all other cleanup |
| 3053 | |
| 3054 | static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) |
| 3055 | { |
| 3056 | unsigned long flags; |
| 3057 | struct sk_buff *skb, *skbnext; |
| 3058 | int count = 0; |
| 3059 | |
| 3060 | spin_lock_irqsave (&q->lock, flags); |
| 3061 | for (skb = q->next; skb != (struct sk_buff *) q; skb = skbnext) { |
| 3062 | struct skb_data *entry; |
| 3063 | struct urb *urb; |
| 3064 | int retval; |
| 3065 | |
| 3066 | entry = (struct skb_data *) skb->cb; |
| 3067 | urb = entry->urb; |
| 3068 | skbnext = skb->next; |
| 3069 | |
| 3070 | // during some PM-driven resume scenarios, |
| 3071 | // these (async) unlinks complete immediately |
| 3072 | retval = usb_unlink_urb (urb); |
| 3073 | if (retval != -EINPROGRESS && retval != 0) |
| 3074 | devdbg (dev, "unlink urb err, %d", retval); |
| 3075 | else |
| 3076 | count++; |
| 3077 | } |
| 3078 | spin_unlock_irqrestore (&q->lock, flags); |
| 3079 | return count; |
| 3080 | } |
| 3081 | |
| 3082 | |
| 3083 | /*-------------------------------------------------------------------------*/ |
| 3084 | |
| 3085 | // precondition: never called in_interrupt |
| 3086 | |
| 3087 | static int usbnet_stop (struct net_device *net) |
| 3088 | { |
| 3089 | struct usbnet *dev = netdev_priv(net); |
| 3090 | int temp; |
| 3091 | DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup); |
| 3092 | DECLARE_WAITQUEUE (wait, current); |
| 3093 | |
| 3094 | netif_stop_queue (net); |
| 3095 | |
| 3096 | if (netif_msg_ifdown (dev)) |
| 3097 | devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", |
| 3098 | dev->stats.rx_packets, dev->stats.tx_packets, |
| 3099 | dev->stats.rx_errors, dev->stats.tx_errors |
| 3100 | ); |
| 3101 | |
| 3102 | // ensure there are no more active urbs |
| 3103 | add_wait_queue (&unlink_wakeup, &wait); |
| 3104 | dev->wait = &unlink_wakeup; |
| 3105 | temp = unlink_urbs (dev, &dev->txq) + unlink_urbs (dev, &dev->rxq); |
| 3106 | |
| 3107 | // maybe wait for deletions to finish. |
| 3108 | while (skb_queue_len (&dev->rxq) |
| 3109 | && skb_queue_len (&dev->txq) |
| 3110 | && skb_queue_len (&dev->done)) { |
| 3111 | msleep(UNLINK_TIMEOUT_MS); |
| 3112 | if (netif_msg_ifdown (dev)) |
| 3113 | devdbg (dev, "waited for %d urb completions", temp); |
| 3114 | } |
| 3115 | dev->wait = NULL; |
| 3116 | remove_wait_queue (&unlink_wakeup, &wait); |
| 3117 | |
| 3118 | usb_kill_urb(dev->interrupt); |
| 3119 | |
| 3120 | /* deferred work (task, timer, softirq) must also stop. |
| 3121 | * can't flush_scheduled_work() until we drop rtnl (later), |
| 3122 | * else workers could deadlock; so make workers a NOP. |
| 3123 | */ |
| 3124 | dev->flags = 0; |
| 3125 | del_timer_sync (&dev->delay); |
| 3126 | tasklet_kill (&dev->bh); |
| 3127 | |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
| 3131 | /*-------------------------------------------------------------------------*/ |
| 3132 | |
| 3133 | // posts reads, and enables write queuing |
| 3134 | |
| 3135 | // precondition: never called in_interrupt |
| 3136 | |
| 3137 | static int usbnet_open (struct net_device *net) |
| 3138 | { |
| 3139 | struct usbnet *dev = netdev_priv(net); |
| 3140 | int retval = 0; |
| 3141 | struct driver_info *info = dev->driver_info; |
| 3142 | |
| 3143 | // put into "known safe" state |
| 3144 | if (info->reset && (retval = info->reset (dev)) < 0) { |
| 3145 | if (netif_msg_ifup (dev)) |
| 3146 | devinfo (dev, |
| 3147 | "open reset fail (%d) usbnet usb-%s-%s, %s", |
| 3148 | retval, |
| 3149 | dev->udev->bus->bus_name, dev->udev->devpath, |
| 3150 | info->description); |
| 3151 | goto done; |
| 3152 | } |
| 3153 | |
| 3154 | // insist peer be connected |
| 3155 | if (info->check_connect && (retval = info->check_connect (dev)) < 0) { |
| 3156 | if (netif_msg_ifup (dev)) |
| 3157 | devdbg (dev, "can't open; %d", retval); |
| 3158 | goto done; |
| 3159 | } |
| 3160 | |
| 3161 | /* start any status interrupt transfer */ |
| 3162 | if (dev->interrupt) { |
| 3163 | retval = usb_submit_urb (dev->interrupt, GFP_KERNEL); |
| 3164 | if (retval < 0) { |
| 3165 | if (netif_msg_ifup (dev)) |
| 3166 | deverr (dev, "intr submit %d", retval); |
| 3167 | goto done; |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | netif_start_queue (net); |
| 3172 | if (netif_msg_ifup (dev)) { |
| 3173 | char *framing; |
| 3174 | |
| 3175 | if (dev->driver_info->flags & FLAG_FRAMING_NC) |
| 3176 | framing = "NetChip"; |
| 3177 | else if (dev->driver_info->flags & FLAG_FRAMING_GL) |
| 3178 | framing = "GeneSys"; |
| 3179 | else if (dev->driver_info->flags & FLAG_FRAMING_Z) |
| 3180 | framing = "Zaurus"; |
| 3181 | else if (dev->driver_info->flags & FLAG_FRAMING_RN) |
| 3182 | framing = "RNDIS"; |
| 3183 | else if (dev->driver_info->flags & FLAG_FRAMING_AX) |
| 3184 | framing = "ASIX"; |
| 3185 | else |
| 3186 | framing = "simple"; |
| 3187 | |
| 3188 | devinfo (dev, "open: enable queueing " |
| 3189 | "(rx %d, tx %d) mtu %d %s framing", |
| 3190 | RX_QLEN (dev), TX_QLEN (dev), dev->net->mtu, |
| 3191 | framing); |
| 3192 | } |
| 3193 | |
| 3194 | // delay posting reads until we're fully open |
| 3195 | tasklet_schedule (&dev->bh); |
| 3196 | done: |
| 3197 | return retval; |
| 3198 | } |
| 3199 | |
| 3200 | /*-------------------------------------------------------------------------*/ |
| 3201 | |
| 3202 | static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) |
| 3203 | { |
| 3204 | struct usbnet *dev = netdev_priv(net); |
| 3205 | |
| 3206 | strncpy (info->driver, driver_name, sizeof info->driver); |
| 3207 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); |
| 3208 | strncpy (info->fw_version, dev->driver_info->description, |
| 3209 | sizeof info->fw_version); |
| 3210 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); |
| 3211 | } |
| 3212 | |
| 3213 | static u32 usbnet_get_link (struct net_device *net) |
| 3214 | { |
| 3215 | struct usbnet *dev = netdev_priv(net); |
| 3216 | |
| 3217 | /* If a check_connect is defined, return it's results */ |
| 3218 | if (dev->driver_info->check_connect) |
| 3219 | return dev->driver_info->check_connect (dev) == 0; |
| 3220 | |
| 3221 | /* Otherwise, we're up to avoid breaking scripts */ |
| 3222 | return 1; |
| 3223 | } |
| 3224 | |
| 3225 | static u32 usbnet_get_msglevel (struct net_device *net) |
| 3226 | { |
| 3227 | struct usbnet *dev = netdev_priv(net); |
| 3228 | |
| 3229 | return dev->msg_enable; |
| 3230 | } |
| 3231 | |
| 3232 | static void usbnet_set_msglevel (struct net_device *net, u32 level) |
| 3233 | { |
| 3234 | struct usbnet *dev = netdev_priv(net); |
| 3235 | |
| 3236 | dev->msg_enable = level; |
| 3237 | } |
| 3238 | |
| 3239 | static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) |
| 3240 | { |
| 3241 | #ifdef NEED_MII |
| 3242 | { |
| 3243 | struct usbnet *dev = netdev_priv(net); |
| 3244 | |
| 3245 | if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) |
| 3246 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); |
| 3247 | } |
| 3248 | #endif |
| 3249 | return -EOPNOTSUPP; |
| 3250 | } |
| 3251 | |
| 3252 | /*-------------------------------------------------------------------------*/ |
| 3253 | |
| 3254 | /* work that cannot be done in interrupt context uses keventd. |
| 3255 | * |
| 3256 | * NOTE: with 2.5 we could do more of this using completion callbacks, |
| 3257 | * especially now that control transfers can be queued. |
| 3258 | */ |
| 3259 | static void |
| 3260 | kevent (void *data) |
| 3261 | { |
| 3262 | struct usbnet *dev = data; |
| 3263 | int status; |
| 3264 | |
| 3265 | /* usb_clear_halt() needs a thread context */ |
| 3266 | if (test_bit (EVENT_TX_HALT, &dev->flags)) { |
| 3267 | unlink_urbs (dev, &dev->txq); |
| 3268 | status = usb_clear_halt (dev->udev, dev->out); |
| 3269 | if (status < 0 && status != -EPIPE) { |
| 3270 | if (netif_msg_tx_err (dev)) |
| 3271 | deverr (dev, "can't clear tx halt, status %d", |
| 3272 | status); |
| 3273 | } else { |
| 3274 | clear_bit (EVENT_TX_HALT, &dev->flags); |
| 3275 | netif_wake_queue (dev->net); |
| 3276 | } |
| 3277 | } |
| 3278 | if (test_bit (EVENT_RX_HALT, &dev->flags)) { |
| 3279 | unlink_urbs (dev, &dev->rxq); |
| 3280 | status = usb_clear_halt (dev->udev, dev->in); |
| 3281 | if (status < 0 && status != -EPIPE) { |
| 3282 | if (netif_msg_rx_err (dev)) |
| 3283 | deverr (dev, "can't clear rx halt, status %d", |
| 3284 | status); |
| 3285 | } else { |
| 3286 | clear_bit (EVENT_RX_HALT, &dev->flags); |
| 3287 | tasklet_schedule (&dev->bh); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | /* tasklet could resubmit itself forever if memory is tight */ |
| 3292 | if (test_bit (EVENT_RX_MEMORY, &dev->flags)) { |
| 3293 | struct urb *urb = NULL; |
| 3294 | |
| 3295 | if (netif_running (dev->net)) |
| 3296 | urb = usb_alloc_urb (0, GFP_KERNEL); |
| 3297 | else |
| 3298 | clear_bit (EVENT_RX_MEMORY, &dev->flags); |
| 3299 | if (urb != NULL) { |
| 3300 | clear_bit (EVENT_RX_MEMORY, &dev->flags); |
| 3301 | rx_submit (dev, urb, GFP_KERNEL); |
| 3302 | tasklet_schedule (&dev->bh); |
| 3303 | } |
| 3304 | } |
| 3305 | |
David Hollis | 7ea13c9 | 2005-04-22 15:07:02 -0700 | [diff] [blame^] | 3306 | if (test_bit (EVENT_LINK_RESET, &dev->flags)) { |
| 3307 | struct driver_info *info = dev->driver_info; |
| 3308 | int retval = 0; |
| 3309 | |
| 3310 | clear_bit (EVENT_LINK_RESET, &dev->flags); |
| 3311 | if(info->link_reset && (retval = info->link_reset(dev)) < 0) { |
| 3312 | devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s", |
| 3313 | retval, |
| 3314 | dev->udev->bus->bus_name, dev->udev->devpath, |
| 3315 | info->description); |
| 3316 | } |
| 3317 | } |
| 3318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | if (dev->flags) |
| 3320 | devdbg (dev, "kevent done, flags = 0x%lx", |
| 3321 | dev->flags); |
| 3322 | } |
| 3323 | |
| 3324 | /*-------------------------------------------------------------------------*/ |
| 3325 | |
| 3326 | static void tx_complete (struct urb *urb, struct pt_regs *regs) |
| 3327 | { |
| 3328 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
| 3329 | struct skb_data *entry = (struct skb_data *) skb->cb; |
| 3330 | struct usbnet *dev = entry->dev; |
| 3331 | |
| 3332 | if (urb->status == 0) { |
| 3333 | dev->stats.tx_packets++; |
| 3334 | dev->stats.tx_bytes += entry->length; |
| 3335 | } else { |
| 3336 | dev->stats.tx_errors++; |
| 3337 | |
| 3338 | switch (urb->status) { |
| 3339 | case -EPIPE: |
| 3340 | defer_kevent (dev, EVENT_TX_HALT); |
| 3341 | break; |
| 3342 | |
| 3343 | /* software-driven interface shutdown */ |
| 3344 | case -ECONNRESET: // async unlink |
| 3345 | case -ESHUTDOWN: // hardware gone |
| 3346 | break; |
| 3347 | |
| 3348 | // like rx, tx gets controller i/o faults during khubd delays |
| 3349 | // and so it uses the same throttling mechanism. |
| 3350 | case -EPROTO: // ehci |
| 3351 | case -ETIMEDOUT: // ohci |
| 3352 | case -EILSEQ: // uhci |
| 3353 | if (!timer_pending (&dev->delay)) { |
| 3354 | mod_timer (&dev->delay, |
| 3355 | jiffies + THROTTLE_JIFFIES); |
| 3356 | if (netif_msg_link (dev)) |
| 3357 | devdbg (dev, "tx throttle %d", |
| 3358 | urb->status); |
| 3359 | } |
| 3360 | netif_stop_queue (dev->net); |
| 3361 | break; |
| 3362 | default: |
| 3363 | if (netif_msg_tx_err (dev)) |
| 3364 | devdbg (dev, "tx err %d", entry->urb->status); |
| 3365 | break; |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | urb->dev = NULL; |
| 3370 | entry->state = tx_done; |
| 3371 | defer_bh (dev, skb); |
| 3372 | } |
| 3373 | |
| 3374 | /*-------------------------------------------------------------------------*/ |
| 3375 | |
| 3376 | static void usbnet_tx_timeout (struct net_device *net) |
| 3377 | { |
| 3378 | struct usbnet *dev = netdev_priv(net); |
| 3379 | |
| 3380 | unlink_urbs (dev, &dev->txq); |
| 3381 | tasklet_schedule (&dev->bh); |
| 3382 | |
| 3383 | // FIXME: device recovery -- reset? |
| 3384 | } |
| 3385 | |
| 3386 | /*-------------------------------------------------------------------------*/ |
| 3387 | |
| 3388 | static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) |
| 3389 | { |
| 3390 | struct usbnet *dev = netdev_priv(net); |
| 3391 | int length; |
| 3392 | int retval = NET_XMIT_SUCCESS; |
| 3393 | struct urb *urb = NULL; |
| 3394 | struct skb_data *entry; |
| 3395 | struct driver_info *info = dev->driver_info; |
| 3396 | unsigned long flags; |
| 3397 | #ifdef CONFIG_USB_NET1080 |
| 3398 | struct nc_header *header = NULL; |
| 3399 | struct nc_trailer *trailer = NULL; |
| 3400 | #endif /* CONFIG_USB_NET1080 */ |
| 3401 | |
| 3402 | // some devices want funky USB-level framing, for |
| 3403 | // win32 driver (usually) and/or hardware quirks |
| 3404 | if (info->tx_fixup) { |
| 3405 | skb = info->tx_fixup (dev, skb, GFP_ATOMIC); |
| 3406 | if (!skb) { |
| 3407 | if (netif_msg_tx_err (dev)) |
| 3408 | devdbg (dev, "can't tx_fixup skb"); |
| 3409 | goto drop; |
| 3410 | } |
| 3411 | } |
| 3412 | length = skb->len; |
| 3413 | |
| 3414 | if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) { |
| 3415 | if (netif_msg_tx_err (dev)) |
| 3416 | devdbg (dev, "no urb"); |
| 3417 | goto drop; |
| 3418 | } |
| 3419 | |
| 3420 | entry = (struct skb_data *) skb->cb; |
| 3421 | entry->urb = urb; |
| 3422 | entry->dev = dev; |
| 3423 | entry->state = tx_start; |
| 3424 | entry->length = length; |
| 3425 | |
| 3426 | // FIXME: reorganize a bit, so that fixup() fills out NetChip |
| 3427 | // framing too. (Packet ID update needs the spinlock...) |
| 3428 | // [ BETTER: we already own net->xmit_lock, that's enough ] |
| 3429 | |
| 3430 | #ifdef CONFIG_USB_NET1080 |
| 3431 | if (info->flags & FLAG_FRAMING_NC) { |
| 3432 | header = (struct nc_header *) skb_push (skb, sizeof *header); |
| 3433 | header->hdr_len = cpu_to_le16 (sizeof (*header)); |
| 3434 | header->packet_len = cpu_to_le16 (length); |
| 3435 | if (!((skb->len + sizeof *trailer) & 0x01)) |
| 3436 | *skb_put (skb, 1) = PAD_BYTE; |
| 3437 | trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer); |
| 3438 | } |
| 3439 | #endif /* CONFIG_USB_NET1080 */ |
| 3440 | |
| 3441 | usb_fill_bulk_urb (urb, dev->udev, dev->out, |
| 3442 | skb->data, skb->len, tx_complete, skb); |
| 3443 | urb->transfer_flags |= URB_ASYNC_UNLINK; |
| 3444 | |
| 3445 | /* don't assume the hardware handles USB_ZERO_PACKET |
| 3446 | * NOTE: strictly conforming cdc-ether devices should expect |
| 3447 | * the ZLP here, but ignore the one-byte packet. |
| 3448 | * |
| 3449 | * FIXME zero that byte, if it doesn't require a new skb. |
| 3450 | */ |
| 3451 | if ((length % dev->maxpacket) == 0) |
| 3452 | urb->transfer_buffer_length++; |
| 3453 | |
| 3454 | spin_lock_irqsave (&dev->txq.lock, flags); |
| 3455 | |
| 3456 | #ifdef CONFIG_USB_NET1080 |
| 3457 | if (info->flags & FLAG_FRAMING_NC) { |
| 3458 | header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++); |
| 3459 | put_unaligned (header->packet_id, &trailer->packet_id); |
| 3460 | #if 0 |
| 3461 | devdbg (dev, "frame >tx h %d p %d id %d", |
| 3462 | header->hdr_len, header->packet_len, |
| 3463 | header->packet_id); |
| 3464 | #endif |
| 3465 | } |
| 3466 | #endif /* CONFIG_USB_NET1080 */ |
| 3467 | |
| 3468 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { |
| 3469 | case -EPIPE: |
| 3470 | netif_stop_queue (net); |
| 3471 | defer_kevent (dev, EVENT_TX_HALT); |
| 3472 | break; |
| 3473 | default: |
| 3474 | if (netif_msg_tx_err (dev)) |
| 3475 | devdbg (dev, "tx: submit urb err %d", retval); |
| 3476 | break; |
| 3477 | case 0: |
| 3478 | net->trans_start = jiffies; |
| 3479 | __skb_queue_tail (&dev->txq, skb); |
| 3480 | if (dev->txq.qlen >= TX_QLEN (dev)) |
| 3481 | netif_stop_queue (net); |
| 3482 | } |
| 3483 | spin_unlock_irqrestore (&dev->txq.lock, flags); |
| 3484 | |
| 3485 | if (retval) { |
| 3486 | if (netif_msg_tx_err (dev)) |
| 3487 | devdbg (dev, "drop, code %d", retval); |
| 3488 | drop: |
| 3489 | retval = NET_XMIT_SUCCESS; |
| 3490 | dev->stats.tx_dropped++; |
| 3491 | if (skb) |
| 3492 | dev_kfree_skb_any (skb); |
| 3493 | usb_free_urb (urb); |
| 3494 | } else if (netif_msg_tx_queued (dev)) { |
| 3495 | devdbg (dev, "> tx, len %d, type 0x%x", |
| 3496 | length, skb->protocol); |
| 3497 | } |
| 3498 | return retval; |
| 3499 | } |
| 3500 | |
| 3501 | |
| 3502 | /*-------------------------------------------------------------------------*/ |
| 3503 | |
| 3504 | // tasklet (work deferred from completions, in_irq) or timer |
| 3505 | |
| 3506 | static void usbnet_bh (unsigned long param) |
| 3507 | { |
| 3508 | struct usbnet *dev = (struct usbnet *) param; |
| 3509 | struct sk_buff *skb; |
| 3510 | struct skb_data *entry; |
| 3511 | |
| 3512 | while ((skb = skb_dequeue (&dev->done))) { |
| 3513 | entry = (struct skb_data *) skb->cb; |
| 3514 | switch (entry->state) { |
| 3515 | case rx_done: |
| 3516 | entry->state = rx_cleanup; |
| 3517 | rx_process (dev, skb); |
| 3518 | continue; |
| 3519 | case tx_done: |
| 3520 | case rx_cleanup: |
| 3521 | usb_free_urb (entry->urb); |
| 3522 | dev_kfree_skb (skb); |
| 3523 | continue; |
| 3524 | default: |
| 3525 | devdbg (dev, "bogus skb state %d", entry->state); |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | // waiting for all pending urbs to complete? |
| 3530 | if (dev->wait) { |
| 3531 | if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) { |
| 3532 | wake_up (dev->wait); |
| 3533 | } |
| 3534 | |
| 3535 | // or are we maybe short a few urbs? |
| 3536 | } else if (netif_running (dev->net) |
| 3537 | && netif_device_present (dev->net) |
| 3538 | && !timer_pending (&dev->delay) |
| 3539 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
| 3540 | int temp = dev->rxq.qlen; |
| 3541 | int qlen = RX_QLEN (dev); |
| 3542 | |
| 3543 | if (temp < qlen) { |
| 3544 | struct urb *urb; |
| 3545 | int i; |
| 3546 | |
| 3547 | // don't refill the queue all at once |
| 3548 | for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) { |
| 3549 | urb = usb_alloc_urb (0, GFP_ATOMIC); |
| 3550 | if (urb != NULL) |
| 3551 | rx_submit (dev, urb, GFP_ATOMIC); |
| 3552 | } |
| 3553 | if (temp != dev->rxq.qlen && netif_msg_link (dev)) |
| 3554 | devdbg (dev, "rxqlen %d --> %d", |
| 3555 | temp, dev->rxq.qlen); |
| 3556 | if (dev->rxq.qlen < qlen) |
| 3557 | tasklet_schedule (&dev->bh); |
| 3558 | } |
| 3559 | if (dev->txq.qlen < TX_QLEN (dev)) |
| 3560 | netif_wake_queue (dev->net); |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | |
| 3565 | |
| 3566 | /*------------------------------------------------------------------------- |
| 3567 | * |
| 3568 | * USB Device Driver support |
| 3569 | * |
| 3570 | *-------------------------------------------------------------------------*/ |
| 3571 | |
| 3572 | // precondition: never called in_interrupt |
| 3573 | |
| 3574 | static void usbnet_disconnect (struct usb_interface *intf) |
| 3575 | { |
| 3576 | struct usbnet *dev; |
| 3577 | struct usb_device *xdev; |
| 3578 | struct net_device *net; |
| 3579 | |
| 3580 | dev = usb_get_intfdata(intf); |
| 3581 | usb_set_intfdata(intf, NULL); |
| 3582 | if (!dev) |
| 3583 | return; |
| 3584 | |
| 3585 | xdev = interface_to_usbdev (intf); |
| 3586 | |
| 3587 | if (netif_msg_probe (dev)) |
| 3588 | devinfo (dev, "unregister usbnet usb-%s-%s, %s", |
| 3589 | xdev->bus->bus_name, xdev->devpath, |
| 3590 | dev->driver_info->description); |
| 3591 | |
| 3592 | net = dev->net; |
| 3593 | unregister_netdev (net); |
| 3594 | |
| 3595 | /* we don't hold rtnl here ... */ |
| 3596 | flush_scheduled_work (); |
| 3597 | |
| 3598 | if (dev->driver_info->unbind) |
| 3599 | dev->driver_info->unbind (dev, intf); |
| 3600 | |
| 3601 | free_netdev(net); |
| 3602 | usb_put_dev (xdev); |
| 3603 | } |
| 3604 | |
| 3605 | |
| 3606 | /*-------------------------------------------------------------------------*/ |
| 3607 | |
| 3608 | static struct ethtool_ops usbnet_ethtool_ops; |
| 3609 | |
| 3610 | // precondition: never called in_interrupt |
| 3611 | |
| 3612 | static int |
| 3613 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) |
| 3614 | { |
| 3615 | struct usbnet *dev; |
| 3616 | struct net_device *net; |
| 3617 | struct usb_host_interface *interface; |
| 3618 | struct driver_info *info; |
| 3619 | struct usb_device *xdev; |
| 3620 | int status; |
| 3621 | |
| 3622 | info = (struct driver_info *) prod->driver_info; |
| 3623 | if (!info) { |
| 3624 | dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name); |
| 3625 | return -ENODEV; |
| 3626 | } |
| 3627 | xdev = interface_to_usbdev (udev); |
| 3628 | interface = udev->cur_altsetting; |
| 3629 | |
| 3630 | usb_get_dev (xdev); |
| 3631 | |
| 3632 | status = -ENOMEM; |
| 3633 | |
| 3634 | // set up our own records |
| 3635 | net = alloc_etherdev(sizeof(*dev)); |
| 3636 | if (!net) { |
| 3637 | dbg ("can't kmalloc dev"); |
| 3638 | goto out; |
| 3639 | } |
| 3640 | |
| 3641 | dev = netdev_priv(net); |
| 3642 | dev->udev = xdev; |
| 3643 | dev->driver_info = info; |
| 3644 | dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV |
| 3645 | | NETIF_MSG_PROBE | NETIF_MSG_LINK); |
| 3646 | skb_queue_head_init (&dev->rxq); |
| 3647 | skb_queue_head_init (&dev->txq); |
| 3648 | skb_queue_head_init (&dev->done); |
| 3649 | dev->bh.func = usbnet_bh; |
| 3650 | dev->bh.data = (unsigned long) dev; |
| 3651 | INIT_WORK (&dev->kevent, kevent, dev); |
| 3652 | dev->delay.function = usbnet_bh; |
| 3653 | dev->delay.data = (unsigned long) dev; |
| 3654 | init_timer (&dev->delay); |
| 3655 | |
| 3656 | SET_MODULE_OWNER (net); |
| 3657 | dev->net = net; |
| 3658 | strcpy (net->name, "usb%d"); |
| 3659 | memcpy (net->dev_addr, node_id, sizeof node_id); |
| 3660 | |
| 3661 | #if 0 |
| 3662 | // dma_supported() is deeply broken on almost all architectures |
| 3663 | // possible with some EHCI controllers |
| 3664 | if (dma_supported (&udev->dev, DMA_64BIT_MASK)) |
| 3665 | net->features |= NETIF_F_HIGHDMA; |
| 3666 | #endif |
| 3667 | |
| 3668 | net->change_mtu = usbnet_change_mtu; |
| 3669 | net->get_stats = usbnet_get_stats; |
| 3670 | net->hard_start_xmit = usbnet_start_xmit; |
| 3671 | net->open = usbnet_open; |
| 3672 | net->stop = usbnet_stop; |
| 3673 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; |
| 3674 | net->tx_timeout = usbnet_tx_timeout; |
| 3675 | net->do_ioctl = usbnet_ioctl; |
| 3676 | net->ethtool_ops = &usbnet_ethtool_ops; |
| 3677 | |
| 3678 | // allow device-specific bind/init procedures |
| 3679 | // NOTE net->name still not usable ... |
| 3680 | if (info->bind) { |
| 3681 | status = info->bind (dev, udev); |
| 3682 | // heuristic: "usb%d" for links we know are two-host, |
| 3683 | // else "eth%d" when there's reasonable doubt. userspace |
| 3684 | // can rename the link if it knows better. |
| 3685 | if ((dev->driver_info->flags & FLAG_ETHER) != 0 |
| 3686 | && (net->dev_addr [0] & 0x02) == 0) |
| 3687 | strcpy (net->name, "eth%d"); |
| 3688 | } else if (!info->in || info->out) |
| 3689 | status = get_endpoints (dev, udev); |
| 3690 | else { |
| 3691 | dev->in = usb_rcvbulkpipe (xdev, info->in); |
| 3692 | dev->out = usb_sndbulkpipe (xdev, info->out); |
| 3693 | if (!(info->flags & FLAG_NO_SETINT)) |
| 3694 | status = usb_set_interface (xdev, |
| 3695 | interface->desc.bInterfaceNumber, |
| 3696 | interface->desc.bAlternateSetting); |
| 3697 | else |
| 3698 | status = 0; |
| 3699 | |
| 3700 | } |
| 3701 | |
| 3702 | if (status == 0 && dev->status) |
| 3703 | status = init_status (dev, udev); |
| 3704 | if (status < 0) |
| 3705 | goto out1; |
| 3706 | |
| 3707 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); |
| 3708 | |
| 3709 | SET_NETDEV_DEV(net, &udev->dev); |
| 3710 | status = register_netdev (net); |
| 3711 | if (status) |
| 3712 | goto out3; |
| 3713 | if (netif_msg_probe (dev)) |
| 3714 | devinfo (dev, "register usbnet at usb-%s-%s, %s, " |
| 3715 | "%02x:%02x:%02x:%02x:%02x:%02x", |
| 3716 | xdev->bus->bus_name, xdev->devpath, |
| 3717 | dev->driver_info->description, |
| 3718 | net->dev_addr [0], net->dev_addr [1], |
| 3719 | net->dev_addr [2], net->dev_addr [3], |
| 3720 | net->dev_addr [4], net->dev_addr [5]); |
| 3721 | |
| 3722 | // ok, it's ready to go. |
| 3723 | usb_set_intfdata (udev, dev); |
| 3724 | |
| 3725 | // start as if the link is up |
| 3726 | netif_device_attach (net); |
| 3727 | |
| 3728 | return 0; |
| 3729 | |
| 3730 | out3: |
| 3731 | if (info->unbind) |
| 3732 | info->unbind (dev, udev); |
| 3733 | out1: |
| 3734 | free_netdev(net); |
| 3735 | out: |
| 3736 | usb_put_dev(xdev); |
| 3737 | return status; |
| 3738 | } |
| 3739 | |
| 3740 | /*-------------------------------------------------------------------------*/ |
| 3741 | |
| 3742 | #ifdef CONFIG_PM |
| 3743 | |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 3744 | static int usbnet_suspend (struct usb_interface *intf, pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | { |
| 3746 | struct usbnet *dev = usb_get_intfdata(intf); |
| 3747 | |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 3748 | /* accelerate emptying of the rx and queues, to avoid |
| 3749 | * having everything error out. |
| 3750 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | netif_device_detach (dev->net); |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 3752 | (void) unlink_urbs (dev, &dev->rxq); |
| 3753 | (void) unlink_urbs (dev, &dev->txq); |
| 3754 | intf->dev.power.power_state = PMSG_SUSPEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | return 0; |
| 3756 | } |
| 3757 | |
| 3758 | static int usbnet_resume (struct usb_interface *intf) |
| 3759 | { |
| 3760 | struct usbnet *dev = usb_get_intfdata(intf); |
| 3761 | |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 3762 | intf->dev.power.power_state = PMSG_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | netif_device_attach (dev->net); |
David Brownell | 27d72e8 | 2005-04-18 17:39:22 -0700 | [diff] [blame] | 3764 | tasklet_schedule (&dev->bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | return 0; |
| 3766 | } |
| 3767 | |
| 3768 | #else /* !CONFIG_PM */ |
| 3769 | |
| 3770 | #define usbnet_suspend NULL |
| 3771 | #define usbnet_resume NULL |
| 3772 | |
| 3773 | #endif /* CONFIG_PM */ |
| 3774 | |
| 3775 | /*-------------------------------------------------------------------------*/ |
| 3776 | |
| 3777 | #ifndef HAVE_HARDWARE |
| 3778 | #error You need to configure some hardware for this driver |
| 3779 | #endif |
| 3780 | |
| 3781 | /* |
| 3782 | * chip vendor names won't normally be on the cables, and |
| 3783 | * may not be on the device. |
| 3784 | */ |
| 3785 | |
| 3786 | static const struct usb_device_id products [] = { |
| 3787 | |
| 3788 | #ifdef CONFIG_USB_ALI_M5632 |
| 3789 | { |
| 3790 | USB_DEVICE (0x0402, 0x5632), // ALi defaults |
| 3791 | .driver_info = (unsigned long) &ali_m5632_info, |
| 3792 | }, |
| 3793 | #endif |
| 3794 | |
| 3795 | #ifdef CONFIG_USB_AN2720 |
| 3796 | { |
| 3797 | USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults |
| 3798 | .driver_info = (unsigned long) &an2720_info, |
| 3799 | }, { |
| 3800 | USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET |
| 3801 | .driver_info = (unsigned long) &an2720_info, |
| 3802 | }, |
| 3803 | #endif |
| 3804 | |
| 3805 | #ifdef CONFIG_USB_BELKIN |
| 3806 | { |
| 3807 | USB_DEVICE (0x050d, 0x0004), // Belkin |
| 3808 | .driver_info = (unsigned long) &belkin_info, |
| 3809 | }, { |
| 3810 | USB_DEVICE (0x056c, 0x8100), // eTEK |
| 3811 | .driver_info = (unsigned long) &belkin_info, |
| 3812 | }, { |
| 3813 | USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK) |
| 3814 | .driver_info = (unsigned long) &belkin_info, |
| 3815 | }, |
| 3816 | #endif |
| 3817 | |
| 3818 | #ifdef CONFIG_USB_AX8817X |
| 3819 | { |
| 3820 | // Linksys USB200M |
| 3821 | USB_DEVICE (0x077b, 0x2226), |
| 3822 | .driver_info = (unsigned long) &ax8817x_info, |
| 3823 | }, { |
| 3824 | // Netgear FA120 |
| 3825 | USB_DEVICE (0x0846, 0x1040), |
| 3826 | .driver_info = (unsigned long) &netgear_fa120_info, |
| 3827 | }, { |
| 3828 | // DLink DUB-E100 |
| 3829 | USB_DEVICE (0x2001, 0x1a00), |
| 3830 | .driver_info = (unsigned long) &dlink_dub_e100_info, |
| 3831 | }, { |
| 3832 | // Intellinet, ST Lab USB Ethernet |
| 3833 | USB_DEVICE (0x0b95, 0x1720), |
| 3834 | .driver_info = (unsigned long) &ax8817x_info, |
| 3835 | }, { |
| 3836 | // Hawking UF200, TrendNet TU2-ET100 |
| 3837 | USB_DEVICE (0x07b8, 0x420a), |
| 3838 | .driver_info = (unsigned long) &hawking_uf200_info, |
| 3839 | }, { |
| 3840 | // Billionton Systems, USB2AR |
| 3841 | USB_DEVICE (0x08dd, 0x90ff), |
| 3842 | .driver_info = (unsigned long) &ax8817x_info, |
| 3843 | }, { |
| 3844 | // ATEN UC210T |
| 3845 | USB_DEVICE (0x0557, 0x2009), |
| 3846 | .driver_info = (unsigned long) &ax8817x_info, |
| 3847 | }, { |
| 3848 | // Buffalo LUA-U2-KTX |
| 3849 | USB_DEVICE (0x0411, 0x003d), |
| 3850 | .driver_info = (unsigned long) &ax8817x_info, |
| 3851 | }, { |
| 3852 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" |
| 3853 | USB_DEVICE (0x6189, 0x182d), |
| 3854 | .driver_info = (unsigned long) &ax8817x_info, |
| 3855 | }, { |
| 3856 | // corega FEther USB2-TX |
| 3857 | USB_DEVICE (0x07aa, 0x0017), |
| 3858 | .driver_info = (unsigned long) &ax8817x_info, |
| 3859 | }, { |
| 3860 | // Surecom EP-1427X-2 |
| 3861 | USB_DEVICE (0x1189, 0x0893), |
| 3862 | .driver_info = (unsigned long) &ax8817x_info, |
| 3863 | }, { |
| 3864 | // goodway corp usb gwusb2e |
| 3865 | USB_DEVICE (0x1631, 0x6200), |
| 3866 | .driver_info = (unsigned long) &ax8817x_info, |
| 3867 | }, { |
| 3868 | // ASIX AX88772 10/100 |
| 3869 | USB_DEVICE (0x0b95, 0x7720), |
| 3870 | .driver_info = (unsigned long) &ax88772_info, |
| 3871 | }, |
| 3872 | #endif |
| 3873 | |
| 3874 | #ifdef CONFIG_USB_EPSON2888 |
| 3875 | { |
| 3876 | USB_DEVICE (0x0525, 0x2888), // EPSON USB client |
| 3877 | .driver_info = (unsigned long) &epson2888_info, |
| 3878 | }, |
| 3879 | #endif |
| 3880 | |
| 3881 | #ifdef CONFIG_USB_GENESYS |
| 3882 | { |
| 3883 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A |
| 3884 | .driver_info = (unsigned long) &genelink_info, |
| 3885 | }, |
| 3886 | /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB |
| 3887 | * that's half duplex, not currently supported |
| 3888 | */ |
| 3889 | #endif |
| 3890 | |
| 3891 | #ifdef CONFIG_USB_NET1080 |
| 3892 | { |
| 3893 | USB_DEVICE (0x0525, 0x1080), // NetChip ref design |
| 3894 | .driver_info = (unsigned long) &net1080_info, |
| 3895 | }, { |
| 3896 | USB_DEVICE (0x06D0, 0x0622), // Laplink Gold |
| 3897 | .driver_info = (unsigned long) &net1080_info, |
| 3898 | }, |
| 3899 | #endif |
| 3900 | |
| 3901 | #ifdef CONFIG_USB_PL2301 |
| 3902 | { |
| 3903 | USB_DEVICE (0x067b, 0x0000), // PL-2301 |
| 3904 | .driver_info = (unsigned long) &prolific_info, |
| 3905 | }, { |
| 3906 | USB_DEVICE (0x067b, 0x0001), // PL-2302 |
| 3907 | .driver_info = (unsigned long) &prolific_info, |
| 3908 | }, |
| 3909 | #endif |
| 3910 | |
| 3911 | #ifdef CONFIG_USB_KC2190 |
| 3912 | { |
| 3913 | USB_DEVICE (0x050f, 0x0190), // KC-190 |
| 3914 | .driver_info = (unsigned long) &kc2190_info, |
| 3915 | }, |
| 3916 | #endif |
| 3917 | |
| 3918 | #ifdef CONFIG_USB_RNDIS |
| 3919 | { |
| 3920 | /* RNDIS is MSFT's un-official variant of CDC ACM */ |
| 3921 | USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff), |
| 3922 | .driver_info = (unsigned long) &rndis_info, |
| 3923 | }, |
| 3924 | #endif |
| 3925 | |
| 3926 | #ifdef CONFIG_USB_ARMLINUX |
| 3927 | /* |
| 3928 | * SA-1100 using standard ARM Linux kernels, or compatible. |
| 3929 | * Often used when talking to Linux PDAs (iPaq, Yopy, etc). |
| 3930 | * The sa-1100 "usb-eth" driver handles the basic framing. |
| 3931 | * |
| 3932 | * PXA25x or PXA210 ... these use a "usb-eth" driver much like |
| 3933 | * the sa1100 one, but hardware uses different endpoint numbers. |
| 3934 | * |
| 3935 | * Or the Linux "Ethernet" gadget on hardware that can't talk |
| 3936 | * CDC Ethernet (e.g., no altsettings), in either of two modes: |
| 3937 | * - acting just like the old "usb-eth" firmware, though |
| 3938 | * the implementation is different |
| 3939 | * - supporting RNDIS as the first/default configuration for |
| 3940 | * MS-Windows interop; Linux needs to use the other config |
| 3941 | */ |
| 3942 | { |
| 3943 | // 1183 = 0x049F, both used as hex values? |
| 3944 | // Compaq "Itsy" vendor/product id |
| 3945 | USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible |
| 3946 | .driver_info = (unsigned long) &linuxdev_info, |
| 3947 | }, { |
| 3948 | USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy" |
| 3949 | .driver_info = (unsigned long) &yopy_info, |
| 3950 | }, { |
| 3951 | USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader |
| 3952 | .driver_info = (unsigned long) &blob_info, |
| 3953 | }, { |
| 3954 | // Linux Ethernet/RNDIS gadget on pxa210/25x/26x |
| 3955 | // e.g. Gumstix, current OpenZaurus, ... |
| 3956 | USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203), |
| 3957 | .driver_info = (unsigned long) &linuxdev_info, |
| 3958 | }, |
| 3959 | #endif |
| 3960 | |
| 3961 | #if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER) |
| 3962 | /* |
| 3963 | * SA-1100 based Sharp Zaurus ("collie"), or compatible. |
| 3964 | * Same idea as above, but different framing. |
| 3965 | * |
| 3966 | * PXA-2xx based models are also lying-about-cdc. |
| 3967 | * Some models don't even tell the same lies ... |
| 3968 | * |
| 3969 | * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries, |
| 3970 | * unlike the older ones with 2.4 "embedix" kernels. |
| 3971 | * |
| 3972 | * NOTE: These entries do double-duty, serving as blacklist entries |
| 3973 | * whenever Zaurus support isn't enabled, but CDC Ethernet is. |
| 3974 | */ |
| 3975 | #define ZAURUS_MASTER_INTERFACE \ |
| 3976 | .bInterfaceClass = USB_CLASS_COMM, \ |
| 3977 | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \ |
| 3978 | .bInterfaceProtocol = USB_CDC_PROTO_NONE |
| 3979 | { |
| 3980 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 3981 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 3982 | .idVendor = 0x04DD, |
| 3983 | .idProduct = 0x8004, |
| 3984 | ZAURUS_MASTER_INTERFACE, |
| 3985 | .driver_info = ZAURUS_STRONGARM_INFO, |
| 3986 | }, { |
| 3987 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 3988 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 3989 | .idVendor = 0x04DD, |
| 3990 | .idProduct = 0x8005, /* A-300 */ |
| 3991 | ZAURUS_MASTER_INTERFACE, |
| 3992 | .driver_info = ZAURUS_PXA_INFO, |
| 3993 | }, { |
| 3994 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 3995 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 3996 | .idVendor = 0x04DD, |
| 3997 | .idProduct = 0x8006, /* B-500/SL-5600 */ |
| 3998 | ZAURUS_MASTER_INTERFACE, |
| 3999 | .driver_info = ZAURUS_PXA_INFO, |
| 4000 | }, { |
| 4001 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4002 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4003 | .idVendor = 0x04DD, |
| 4004 | .idProduct = 0x8007, /* C-700 */ |
| 4005 | ZAURUS_MASTER_INTERFACE, |
| 4006 | .driver_info = ZAURUS_PXA_INFO, |
| 4007 | }, { |
| 4008 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4009 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4010 | .idVendor = 0x04DD, |
| 4011 | .idProduct = 0x9031, /* C-750 C-760 */ |
| 4012 | ZAURUS_MASTER_INTERFACE, |
| 4013 | .driver_info = ZAURUS_PXA_INFO, |
| 4014 | }, { |
| 4015 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4016 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4017 | .idVendor = 0x04DD, |
| 4018 | .idProduct = 0x9032, /* SL-6000 */ |
| 4019 | ZAURUS_MASTER_INTERFACE, |
| 4020 | .driver_info = ZAURUS_PXA_INFO, |
| 4021 | }, { |
| 4022 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4023 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4024 | .idVendor = 0x04DD, |
| 4025 | /* reported with some C860 units */ |
| 4026 | .idProduct = 0x9050, /* C-860 */ |
| 4027 | ZAURUS_MASTER_INTERFACE, |
| 4028 | .driver_info = ZAURUS_PXA_INFO, |
David Brownell | a2fe201 | 2005-04-18 17:39:29 -0700 | [diff] [blame] | 4029 | }, |
| 4030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | #ifdef CONFIG_USB_ZAURUS |
David Brownell | a2fe201 | 2005-04-18 17:39:29 -0700 | [diff] [blame] | 4032 | /* at least some (reports vary) PXA units have very different |
| 4033 | * lies about their standards support: they claim to be cell |
| 4034 | * phones giving direct radio access (which they aren't). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | */ |
David Brownell | a2fe201 | 2005-04-18 17:39:29 -0700 | [diff] [blame] | 4036 | { |
| 4037 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4038 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4039 | .idVendor = 0x04DD, |
| 4040 | /* Sharp ROM v1.32 */ |
| 4041 | .idProduct = 0x8006, /* SL-5600 */ |
| 4042 | .bInterfaceClass = USB_CLASS_COMM, |
| 4043 | .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM, |
| 4044 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 4045 | .driver_info = (unsigned long) &zaurus_pxa_mdlm_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | }, { |
| 4047 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4048 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4049 | .idVendor = 0x04DD, |
| 4050 | /* reported with some C860 units */ |
| 4051 | .idProduct = 0x9031, /* C-860 */ |
| 4052 | .bInterfaceClass = USB_CLASS_COMM, |
| 4053 | .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM, |
| 4054 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 4055 | .driver_info = (unsigned long) &zaurus_pxa_mdlm_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | }, |
David Brownell | a2fe201 | 2005-04-18 17:39:29 -0700 | [diff] [blame] | 4057 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | |
| 4059 | /* Olympus has some models with a Zaurus-compatible option. |
| 4060 | * R-1000 uses a FreeScale i.MXL cpu (ARMv4T) |
| 4061 | */ |
| 4062 | { |
| 4063 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 4064 | | USB_DEVICE_ID_MATCH_DEVICE, |
| 4065 | .idVendor = 0x07B4, |
| 4066 | .idProduct = 0x0F02, /* R-1000 */ |
| 4067 | ZAURUS_MASTER_INTERFACE, |
| 4068 | .driver_info = OLYMPUS_MXL_INFO, |
| 4069 | }, |
| 4070 | #endif |
| 4071 | |
| 4072 | #ifdef CONFIG_USB_CDCETHER |
| 4073 | { |
| 4074 | /* CDC Ether uses two interfaces, not necessarily consecutive. |
| 4075 | * We match the main interface, ignoring the optional device |
| 4076 | * class so we could handle devices that aren't exclusively |
| 4077 | * CDC ether. |
| 4078 | * |
| 4079 | * NOTE: this match must come AFTER entries working around |
| 4080 | * bugs/quirks in a given product (like Zaurus, above). |
| 4081 | */ |
| 4082 | USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET, |
| 4083 | USB_CDC_PROTO_NONE), |
| 4084 | .driver_info = (unsigned long) &cdc_info, |
| 4085 | }, |
| 4086 | #endif |
| 4087 | |
| 4088 | { }, // END |
| 4089 | }; |
| 4090 | MODULE_DEVICE_TABLE (usb, products); |
| 4091 | |
| 4092 | static struct usb_driver usbnet_driver = { |
| 4093 | .owner = THIS_MODULE, |
| 4094 | .name = driver_name, |
| 4095 | .id_table = products, |
| 4096 | .probe = usbnet_probe, |
| 4097 | .disconnect = usbnet_disconnect, |
| 4098 | .suspend = usbnet_suspend, |
| 4099 | .resume = usbnet_resume, |
| 4100 | }; |
| 4101 | |
| 4102 | /* Default ethtool_ops assigned. Devices can override in their bind() routine */ |
| 4103 | static struct ethtool_ops usbnet_ethtool_ops = { |
| 4104 | .get_drvinfo = usbnet_get_drvinfo, |
| 4105 | .get_link = usbnet_get_link, |
| 4106 | .get_msglevel = usbnet_get_msglevel, |
| 4107 | .set_msglevel = usbnet_set_msglevel, |
| 4108 | }; |
| 4109 | |
| 4110 | /*-------------------------------------------------------------------------*/ |
| 4111 | |
| 4112 | static int __init usbnet_init (void) |
| 4113 | { |
| 4114 | // compiler should optimize these out |
| 4115 | BUG_ON (sizeof (((struct sk_buff *)0)->cb) |
| 4116 | < sizeof (struct skb_data)); |
| 4117 | #ifdef CONFIG_USB_CDCETHER |
| 4118 | BUG_ON ((sizeof (((struct usbnet *)0)->data) |
| 4119 | < sizeof (struct cdc_state))); |
| 4120 | #endif |
| 4121 | |
| 4122 | random_ether_addr(node_id); |
| 4123 | |
| 4124 | return usb_register(&usbnet_driver); |
| 4125 | } |
| 4126 | module_init (usbnet_init); |
| 4127 | |
| 4128 | static void __exit usbnet_exit (void) |
| 4129 | { |
| 4130 | usb_deregister (&usbnet_driver); |
| 4131 | } |
| 4132 | module_exit (usbnet_exit); |
| 4133 | |
| 4134 | MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>"); |
| 4135 | MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)"); |
| 4136 | MODULE_LICENSE ("GPL"); |