blob: 1867fe2c4e65ffdf9a79f2731b106a4c87108b53 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
David Brownell090ffa92005-08-31 09:54:50 -07002 * USB Network driver infrastructure
David Brownellf29fc252005-08-31 09:52:31 -07003 * Copyright (C) 2000-2005 by David Brownell
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * This is a generic "USB networking" framework that works with several
David Brownell090ffa92005-08-31 09:54:50 -070023 * kinds of full and high speed networking devices: host-to-host cables,
24 * smart usb peripherals, and actual Ethernet adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
David Brownell090ffa92005-08-31 09:54:50 -070026 * These devices usually differ in terms of control protocols (if they
27 * even have one!) and sometimes they define new framing to wrap or batch
28 * Ethernet packets. Otherwise, they talk to USB pretty much the same,
29 * so interface (un)binding, endpoint I/O queues, fault handling, and other
30 * issues can usefully be addressed by this framework.
31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33// #define DEBUG // error path messages, extra info
34// #define VERBOSE // more; success messages
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/init.h>
Hemant Kumar6d2c7472012-03-06 23:39:29 -080038#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/netdevice.h>
40#include <linux/etherdevice.h>
Peter Holik03ad0322009-04-18 07:24:17 +000041#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/ethtool.h>
43#include <linux/workqueue.h>
44#include <linux/mii.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/usb.h>
Jussi Kivilinna3692e942008-01-26 00:51:45 +020046#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Andy Shevchenkofd1f1702010-07-23 03:18:08 +000048#include <linux/kernel.h>
Ming Leib0786b42010-11-01 07:11:54 -070049#include <linux/pm_runtime.h>
David Brownellf29fc252005-08-31 09:52:31 -070050
51#define DRIVER_VERSION "22-Aug-2005"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53
54/*-------------------------------------------------------------------------*/
55
56/*
57 * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
58 * Several dozen bytes of IPv4 data can fit in two such transactions.
59 * One maximum size Ethernet packet takes twenty four of them.
60 * For high speed, each frame comfortably fits almost 36 max size
61 * Ethernet packets (so queues should be bigger).
David Brownellf29fc252005-08-31 09:52:31 -070062 *
63 * REVISIT qlens should be members of 'struct usbnet'; the goal is to
64 * let the USB host controller be busy for 5msec or more before an irq
65 * is required, under load. Jumbograms change the equation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
Jamie Paintera99c1942006-07-27 14:17:28 -040067#define RX_MAX_QUEUE_MEMORY (60 * 1518)
68#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
69 (RX_MAX_QUEUE_MEMORY/(dev)->rx_urb_size) : 4)
70#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? \
71 (RX_MAX_QUEUE_MEMORY/(dev)->hard_mtu) : 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073// reawaken network queue this soon after stopping; else watchdog barks
74#define TX_TIMEOUT_JIFFIES (5*HZ)
75
76// throttle rx/tx briefly after some faults, so khubd might disconnect()
77// us (it polls at HZ/4 usually) before we report too many false errors.
78#define THROTTLE_JIFFIES (HZ/8)
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080// between wakeups
81#define UNLINK_TIMEOUT_MS 3
82
83/*-------------------------------------------------------------------------*/
84
85// randomly generated ethernet address
86static u8 node_id [ETH_ALEN];
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static const char driver_name [] = "usbnet";
89
Hemant Kumar1e8ddb52012-07-02 13:39:22 -070090static struct workqueue_struct *usbnet_wq;
91
Hemant Kumaref59a422012-08-15 16:57:00 -070092static DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* use ethtool to change the level for any given device */
95static int msg_level = -1;
96module_param (msg_level, int, 0);
97MODULE_PARM_DESC (msg_level, "Override default message level");
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*-------------------------------------------------------------------------*/
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* handles CDC Ethernet and many other network "bulk data" interfaces */
David Brownell2e55cc72005-08-31 09:53:10 -0700102int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 int tmp;
105 struct usb_host_interface *alt = NULL;
106 struct usb_host_endpoint *in = NULL, *out = NULL;
107 struct usb_host_endpoint *status = NULL;
108
109 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
110 unsigned ep;
111
112 in = out = status = NULL;
113 alt = intf->altsetting + tmp;
114
115 /* take the first altsetting with in-bulk + out-bulk;
116 * remember any status endpoint, just in case;
Justin P. Mattock70f23fd2011-05-10 10:16:21 +0200117 * ignore other endpoints and altsettings.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 */
119 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
120 struct usb_host_endpoint *e;
121 int intr = 0;
122
123 e = alt->endpoint + ep;
124 switch (e->desc.bmAttributes) {
125 case USB_ENDPOINT_XFER_INT:
Luiz Fernando N. Capitulinofc6e2542006-10-26 13:03:01 -0300126 if (!usb_endpoint_dir_in(&e->desc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 continue;
128 intr = 1;
129 /* FALLTHROUGH */
130 case USB_ENDPOINT_XFER_BULK:
131 break;
132 default:
133 continue;
134 }
Luiz Fernando N. Capitulinofc6e2542006-10-26 13:03:01 -0300135 if (usb_endpoint_dir_in(&e->desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (!intr && !in)
137 in = e;
138 else if (intr && !status)
139 status = e;
140 } else {
141 if (!out)
142 out = e;
143 }
144 }
145 if (in && out)
146 break;
147 }
148 if (!alt || !in || !out)
149 return -EINVAL;
150
Joe Perches8e95a202009-12-03 07:58:21 +0000151 if (alt->desc.bAlternateSetting != 0 ||
152 !(dev->driver_info->flags & FLAG_NO_SETINT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
154 alt->desc.bAlternateSetting);
155 if (tmp < 0)
156 return tmp;
157 }
David Brownellcb1cebb2007-02-15 18:52:30 -0800158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 dev->in = usb_rcvbulkpipe (dev->udev,
160 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
161 dev->out = usb_sndbulkpipe (dev->udev,
162 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
163 dev->status = status;
164 return 0;
165}
David Brownell2e55cc72005-08-31 09:53:10 -0700166EXPORT_SYMBOL_GPL(usbnet_get_endpoints);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Peter Holik03ad0322009-04-18 07:24:17 +0000168int usbnet_get_ethernet_addr(struct usbnet *dev, int iMACAddress)
169{
170 int tmp, i;
171 unsigned char buf [13];
172
173 tmp = usb_string(dev->udev, iMACAddress, buf, sizeof buf);
174 if (tmp != 12) {
175 dev_dbg(&dev->udev->dev,
176 "bad MAC string %d fetch, %d\n", iMACAddress, tmp);
177 if (tmp >= 0)
178 tmp = -EINVAL;
179 return tmp;
180 }
181 for (i = tmp = 0; i < 6; i++, tmp += 2)
182 dev->net->dev_addr [i] =
Andy Shevchenkofd1f1702010-07-23 03:18:08 +0000183 (hex_to_bin(buf[tmp]) << 4) + hex_to_bin(buf[tmp + 1]);
Peter Holik03ad0322009-04-18 07:24:17 +0000184 return 0;
185}
186EXPORT_SYMBOL_GPL(usbnet_get_ethernet_addr);
187
David Howells7d12e782006-10-05 14:55:46 +0100188static void intr_complete (struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190static int init_status (struct usbnet *dev, struct usb_interface *intf)
191{
192 char *buf = NULL;
193 unsigned pipe = 0;
194 unsigned maxp;
195 unsigned period;
196
197 if (!dev->driver_info->status)
198 return 0;
199
200 pipe = usb_rcvintpipe (dev->udev,
201 dev->status->desc.bEndpointAddress
202 & USB_ENDPOINT_NUMBER_MASK);
203 maxp = usb_maxpacket (dev->udev, pipe, 0);
204
205 /* avoid 1 msec chatter: min 8 msec poll rate */
206 period = max ((int) dev->status->desc.bInterval,
207 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
208
Christoph Lametere94b1762006-12-06 20:33:17 -0800209 buf = kmalloc (maxp, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 if (buf) {
Christoph Lametere94b1762006-12-06 20:33:17 -0800211 dev->interrupt = usb_alloc_urb (0, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 if (!dev->interrupt) {
213 kfree (buf);
214 return -ENOMEM;
215 } else {
216 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
217 buf, maxp, intr_complete, dev, period);
tom.leiming@gmail.com720f3d72012-04-29 22:51:02 +0000218 dev->interrupt->transfer_flags |= URB_FREE_BUFFER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 dev_dbg(&intf->dev,
220 "status ep%din, %d bytes period %d\n",
221 usb_pipeendpoint(pipe), maxp, period);
222 }
223 }
David Brownell18ab4582007-05-25 12:31:32 -0700224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
David Brownell2e55cc72005-08-31 09:53:10 -0700227/* Passes this packet up the stack, updating its accounting.
228 * Some link protocols batch packets, so their rx_fixup paths
229 * can return clones as well as just modify the original skb.
230 */
231void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 int status;
234
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300235 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
236 skb_queue_tail(&dev->rxq_pause, skb);
237 return;
238 }
239
Hemant Kumar37c35e42011-09-14 23:44:19 -0700240 if (!skb->protocol)
241 skb->protocol = eth_type_trans(skb, dev->net);
242
Herbert Xu79638372009-06-29 16:53:28 +0000243 dev->net->stats.rx_packets++;
244 dev->net->stats.rx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Joe Perchesa475f602010-02-17 10:30:24 +0000246 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n",
247 skb->len + sizeof (struct ethhdr), skb->protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 memset (skb->cb, 0, sizeof (struct skb_data));
Michael Rieschf9b491e2011-09-29 04:06:26 +0000249
250 if (skb_defer_rx_timestamp(skb))
251 return;
252
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700253 status = netif_rx_ni(skb);
Joe Perchesa475f602010-02-17 10:30:24 +0000254 if (status != NET_RX_SUCCESS)
255 netif_dbg(dev, rx_err, dev->net,
256 "netif_rx status %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
David Brownell2e55cc72005-08-31 09:53:10 -0700258EXPORT_SYMBOL_GPL(usbnet_skb_return);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/*-------------------------------------------------------------------------
262 *
263 * Network Device Driver (peer link to "Host Device", from USB host)
264 *
265 *-------------------------------------------------------------------------*/
266
Stephen Hemminger777baa42009-03-20 19:35:54 +0000267int usbnet_change_mtu (struct net_device *net, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 struct usbnet *dev = netdev_priv(net);
David Brownellf29fc252005-08-31 09:52:31 -0700270 int ll_mtu = new_mtu + net->hard_header_len;
Jamie Paintera99c1942006-07-27 14:17:28 -0400271 int old_hard_mtu = dev->hard_mtu;
272 int old_rx_urb_size = dev->rx_urb_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Jamie Paintera99c1942006-07-27 14:17:28 -0400274 if (new_mtu <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 // no second zero-length packet read wanted after mtu-sized packets
David Brownellf29fc252005-08-31 09:52:31 -0700277 if ((ll_mtu % dev->maxpacket) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return -EDOM;
279 net->mtu = new_mtu;
Jamie Paintera99c1942006-07-27 14:17:28 -0400280
281 dev->hard_mtu = net->mtu + net->hard_header_len;
282 if (dev->rx_urb_size == old_hard_mtu) {
283 dev->rx_urb_size = dev->hard_mtu;
284 if (dev->rx_urb_size > old_rx_urb_size)
285 usbnet_unlink_rx_urbs(dev);
286 }
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return 0;
289}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000290EXPORT_SYMBOL_GPL(usbnet_change_mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800292/* The caller must hold list->lock */
293static void __usbnet_queue_skb(struct sk_buff_head *list,
294 struct sk_buff *newsk, enum skb_state state)
295{
296 struct skb_data *entry = (struct skb_data *) newsk->cb;
297
298 __skb_queue_tail(list, newsk);
299 entry->state = state;
300}
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302/*-------------------------------------------------------------------------*/
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
305 * completion callbacks. 2.5 should have fixed those bugs...
306 */
307
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800308static enum skb_state defer_bh(struct usbnet *dev, struct sk_buff *skb,
309 struct sk_buff_head *list, enum skb_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 unsigned long flags;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800312 enum skb_state old_state;
313 struct skb_data *entry = (struct skb_data *) skb->cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
David S. Miller8728b832005-08-09 19:25:21 -0700315 spin_lock_irqsave(&list->lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800316 old_state = entry->state;
317 entry->state = state;
David S. Miller8728b832005-08-09 19:25:21 -0700318 __skb_unlink(skb, list);
319 spin_unlock(&list->lock);
320 spin_lock(&dev->done.lock);
321 __skb_queue_tail(&dev->done, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (dev->done.qlen == 1)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700323 queue_work(usbnet_wq, &dev->bh_w);
David S. Miller8728b832005-08-09 19:25:21 -0700324 spin_unlock_irqrestore(&dev->done.lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800325 return old_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
328/* some work can't be done in tasklets, so we use keventd
329 *
330 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
331 * but tasklet_schedule() doesn't. hope the failure is rare.
332 */
David Brownell2e55cc72005-08-31 09:53:10 -0700333void usbnet_defer_kevent (struct usbnet *dev, int work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 set_bit (work, &dev->flags);
336 if (!schedule_work (&dev->kevent))
Joe Perches60b86752010-02-17 10:30:23 +0000337 netdev_err(dev->net, "kevent %d may have been dropped\n", work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
Joe Perches60b86752010-02-17 10:30:23 +0000339 netdev_dbg(dev->net, "kevent %d scheduled\n", work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
David Brownell2e55cc72005-08-31 09:53:10 -0700341EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343/*-------------------------------------------------------------------------*/
344
David Howells7d12e782006-10-05 14:55:46 +0100345static void rx_complete (struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
David S. Millerdacb3972010-08-10 02:50:55 -0700347static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 struct sk_buff *skb;
350 struct skb_data *entry;
351 int retval = 0;
352 unsigned long lockflags;
David Brownell2e55cc72005-08-31 09:53:10 -0700353 size_t size = dev->rx_urb_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Eric Dumazet7bdd4022012-03-14 06:56:25 +0000355 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
356 if (!skb) {
Joe Perchesa475f602010-02-17 10:30:24 +0000357 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
David Brownell2e55cc72005-08-31 09:53:10 -0700358 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 usb_free_urb (urb);
David S. Millerdacb3972010-08-10 02:50:55 -0700360 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Hemant Kumar6d2c7472012-03-06 23:39:29 -0800363 if (dev->net->type != ARPHRD_RAWIP)
364 skb_reserve(skb, NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 entry = (struct skb_data *) skb->cb;
367 entry->urb = urb;
368 entry->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 entry->length = 0;
370
371 usb_fill_bulk_urb (urb, dev->udev, dev->in,
372 skb->data, size, rx_complete, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 spin_lock_irqsave (&dev->rxq.lock, lockflags);
375
Joe Perches8e95a202009-12-03 07:58:21 +0000376 if (netif_running (dev->net) &&
377 netif_device_present (dev->net) &&
Oliver Neukum69ee4722009-12-03 15:31:18 -0800378 !test_bit (EVENT_RX_HALT, &dev->flags) &&
379 !test_bit (EVENT_DEV_ASLEEP, &dev->flags)) {
David Brownell18ab4582007-05-25 12:31:32 -0700380 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 case -EPIPE:
David Brownell2e55cc72005-08-31 09:53:10 -0700382 usbnet_defer_kevent (dev, EVENT_RX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384 case -ENOMEM:
David Brownell2e55cc72005-08-31 09:53:10 -0700385 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
387 case -ENODEV:
Joe Perchesa475f602010-02-17 10:30:24 +0000388 netif_dbg(dev, ifdown, dev->net, "device gone\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 netif_device_detach (dev->net);
390 break;
David S. Millerdacb3972010-08-10 02:50:55 -0700391 case -EHOSTUNREACH:
392 retval = -ENOLINK;
393 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 default:
Joe Perchesa475f602010-02-17 10:30:24 +0000395 netif_dbg(dev, rx_err, dev->net,
396 "rx submit, %d\n", retval);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700397 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
399 case 0:
Hemant Kumar279188a2012-04-03 13:32:48 -0700400 usb_mark_last_busy(dev->udev);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800401 __usbnet_queue_skb(&dev->rxq, skb, rx_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000404 netif_dbg(dev, ifdown, dev->net, "rx: stopped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 retval = -ENOLINK;
406 }
407 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
408 if (retval) {
409 dev_kfree_skb_any (skb);
410 usb_free_urb (urb);
411 }
David S. Millerdacb3972010-08-10 02:50:55 -0700412 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415
416/*-------------------------------------------------------------------------*/
417
418static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
419{
Joe Perches8e95a202009-12-03 07:58:21 +0000420 if (dev->driver_info->rx_fixup &&
Andrzej Zaborowski7a635ea2011-03-28 12:56:33 +0000421 !dev->driver_info->rx_fixup (dev, skb)) {
422 /* With RX_ASSEMBLE, rx_fixup() must update counters */
423 if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE))
424 dev->net->stats.rx_errors++;
425 goto done;
426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 // else network stack removes extra byte if we forced a short packet
428
Alexey Orishko073285f2010-11-29 23:23:27 +0000429 if (skb->len) {
430 /* all data was already cloned from skb inside the driver */
431 if (dev->driver_info->flags & FLAG_MULTI_PACKET)
432 dev_kfree_skb_any(skb);
433 else
434 usbnet_skb_return(dev, skb);
435 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
Alexey Orishko073285f2010-11-29 23:23:27 +0000437
438 netif_dbg(dev, rx_err, dev->net, "drop\n");
Alexey Orishko073285f2010-11-29 23:23:27 +0000439 dev->net->stats.rx_errors++;
Andrzej Zaborowski7a635ea2011-03-28 12:56:33 +0000440done:
Alexey Orishko073285f2010-11-29 23:23:27 +0000441 skb_queue_tail(&dev->done, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
444/*-------------------------------------------------------------------------*/
445
David Howells7d12e782006-10-05 14:55:46 +0100446static void rx_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
448 struct sk_buff *skb = (struct sk_buff *) urb->context;
449 struct skb_data *entry = (struct skb_data *) skb->cb;
450 struct usbnet *dev = entry->dev;
451 int urb_status = urb->status;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800452 enum skb_state state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 skb_put (skb, urb->actual_length);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800455 state = rx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 entry->urb = NULL;
457
458 switch (urb_status) {
David Brownell18ab4582007-05-25 12:31:32 -0700459 /* success */
460 case 0:
David Brownellf29fc252005-08-31 09:52:31 -0700461 if (skb->len < dev->net->hard_header_len) {
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800462 state = rx_cleanup;
Herbert Xu79638372009-06-29 16:53:28 +0000463 dev->net->stats.rx_errors++;
464 dev->net->stats.rx_length_errors++;
Joe Perchesa475f602010-02-17 10:30:24 +0000465 netif_dbg(dev, rx_err, dev->net,
466 "rx length %d\n", skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468 break;
469
David Brownell18ab4582007-05-25 12:31:32 -0700470 /* stalls need manual reset. this is rare ... except that
471 * when going through USB 2.0 TTs, unplug appears this way.
Jean Delvare3ac49a12009-06-04 16:20:28 +0200472 * we avoid the highspeed version of the ETIMEDOUT/EILSEQ
David Brownell18ab4582007-05-25 12:31:32 -0700473 * storm, recovering as needed.
474 */
475 case -EPIPE:
Herbert Xu79638372009-06-29 16:53:28 +0000476 dev->net->stats.rx_errors++;
David Brownell2e55cc72005-08-31 09:53:10 -0700477 usbnet_defer_kevent (dev, EVENT_RX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 // FALLTHROUGH
479
David Brownell18ab4582007-05-25 12:31:32 -0700480 /* software-driven interface shutdown */
481 case -ECONNRESET: /* async unlink */
482 case -ESHUTDOWN: /* hardware gone */
Joe Perchesa475f602010-02-17 10:30:24 +0000483 netif_dbg(dev, ifdown, dev->net,
484 "rx shutdown, code %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 goto block;
486
David Brownell18ab4582007-05-25 12:31:32 -0700487 /* we get controller i/o faults during khubd disconnect() delays.
488 * throttle down resubmits, to avoid log floods; just temporarily,
489 * so we still recover when the fault isn't a khubd delay.
490 */
491 case -EPROTO:
492 case -ETIME:
493 case -EILSEQ:
Herbert Xu79638372009-06-29 16:53:28 +0000494 dev->net->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (!timer_pending (&dev->delay)) {
496 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
Joe Perchesa475f602010-02-17 10:30:24 +0000497 netif_dbg(dev, link, dev->net,
498 "rx throttle %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500block:
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800501 state = rx_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 entry->urb = urb;
503 urb = NULL;
504 break;
505
David Brownell18ab4582007-05-25 12:31:32 -0700506 /* data overrun ... flush fifo? */
507 case -EOVERFLOW:
Herbert Xu79638372009-06-29 16:53:28 +0000508 dev->net->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 // FALLTHROUGH
David Brownellcb1cebb2007-02-15 18:52:30 -0800510
David Brownell18ab4582007-05-25 12:31:32 -0700511 default:
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800512 state = rx_cleanup;
Herbert Xu79638372009-06-29 16:53:28 +0000513 dev->net->stats.rx_errors++;
Joe Perchesa475f602010-02-17 10:30:24 +0000514 netif_dbg(dev, rx_err, dev->net, "rx status %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 break;
516 }
517
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800518 state = defer_bh(dev, skb, &dev->rxq, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 if (urb) {
Joe Perches8e95a202009-12-03 07:58:21 +0000521 if (netif_running (dev->net) &&
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800522 !test_bit (EVENT_RX_HALT, &dev->flags) &&
523 state != unlink_start) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 rx_submit (dev, urb, GFP_ATOMIC);
Oliver Neukum8a783352012-03-03 18:45:07 +0100525 usb_mark_last_busy(dev->udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return;
527 }
528 usb_free_urb (urb);
529 }
Joe Perchesa475f602010-02-17 10:30:24 +0000530 netif_dbg(dev, rx_err, dev->net, "no read resubmitted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
David Howells7d12e782006-10-05 14:55:46 +0100533static void intr_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
535 struct usbnet *dev = urb->context;
536 int status = urb->status;
537
538 switch (status) {
David Brownell18ab4582007-05-25 12:31:32 -0700539 /* success */
540 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 dev->driver_info->status(dev, urb);
542 break;
543
David Brownell18ab4582007-05-25 12:31:32 -0700544 /* software-driven interface shutdown */
545 case -ENOENT: /* urb killed */
546 case -ESHUTDOWN: /* hardware gone */
Joe Perchesa475f602010-02-17 10:30:24 +0000547 netif_dbg(dev, ifdown, dev->net,
548 "intr shutdown, code %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 return;
550
David Brownell18ab4582007-05-25 12:31:32 -0700551 /* NOTE: not throttling like RX/TX, since this endpoint
552 * already polls infrequently
553 */
554 default:
Joe Perches60b86752010-02-17 10:30:23 +0000555 netdev_dbg(dev->net, "intr status %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 break;
557 }
558
559 if (!netif_running (dev->net))
560 return;
561
562 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
563 status = usb_submit_urb (urb, GFP_ATOMIC);
Joe Perchesa475f602010-02-17 10:30:24 +0000564 if (status != 0)
565 netif_err(dev, timer, dev->net,
566 "intr resubmit --> %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569/*-------------------------------------------------------------------------*/
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300570void usbnet_pause_rx(struct usbnet *dev)
571{
572 set_bit(EVENT_RX_PAUSED, &dev->flags);
573
Joe Perchesa475f602010-02-17 10:30:24 +0000574 netif_dbg(dev, rx_status, dev->net, "paused rx queue enabled\n");
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300575}
576EXPORT_SYMBOL_GPL(usbnet_pause_rx);
577
578void usbnet_resume_rx(struct usbnet *dev)
579{
580 struct sk_buff *skb;
581 int num = 0;
582
583 clear_bit(EVENT_RX_PAUSED, &dev->flags);
584
585 while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
586 usbnet_skb_return(dev, skb);
587 num++;
588 }
589
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700590 queue_work(usbnet_wq, &dev->bh_w);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300591
Joe Perchesa475f602010-02-17 10:30:24 +0000592 netif_dbg(dev, rx_status, dev->net,
593 "paused rx queue disabled, %d skbs requeued\n", num);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300594}
595EXPORT_SYMBOL_GPL(usbnet_resume_rx);
596
597void usbnet_purge_paused_rxq(struct usbnet *dev)
598{
599 skb_queue_purge(&dev->rxq_pause);
600}
601EXPORT_SYMBOL_GPL(usbnet_purge_paused_rxq);
602
603/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605// unlink pending rx/tx; completion handlers do all other cleanup
606
607static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
608{
609 unsigned long flags;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800610 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 int count = 0;
612
613 spin_lock_irqsave (&q->lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800614 while (!skb_queue_empty(q)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 struct skb_data *entry;
616 struct urb *urb;
617 int retval;
618
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800619 skb_queue_walk(q, skb) {
620 entry = (struct skb_data *) skb->cb;
621 if (entry->state != unlink_start)
622 goto found;
623 }
624 break;
625found:
626 entry->state = unlink_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 urb = entry->urb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
tom.leiming@gmail.com0956a8c2012-03-22 03:22:18 +0000629 /*
630 * Get reference count of the URB to avoid it to be
631 * freed during usb_unlink_urb, which may trigger
632 * use-after-free problem inside usb_unlink_urb since
633 * usb_unlink_urb is always racing with .complete
634 * handler(include defer_bh).
635 */
636 usb_get_urb(urb);
Sebastian Siewior4231d472012-03-07 10:19:28 +0000637 spin_unlock_irqrestore(&q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 // during some PM-driven resume scenarios,
639 // these (async) unlinks complete immediately
640 retval = usb_unlink_urb (urb);
641 if (retval != -EINPROGRESS && retval != 0)
Joe Perches60b86752010-02-17 10:30:23 +0000642 netdev_dbg(dev->net, "unlink urb err, %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 else
644 count++;
tom.leiming@gmail.com0956a8c2012-03-22 03:22:18 +0000645 usb_put_urb(urb);
Sebastian Siewior4231d472012-03-07 10:19:28 +0000646 spin_lock_irqsave(&q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 spin_unlock_irqrestore (&q->lock, flags);
649 return count;
650}
651
Jamie Paintera99c1942006-07-27 14:17:28 -0400652// Flush all pending rx urbs
653// minidrivers may need to do this when the MTU changes
654
655void usbnet_unlink_rx_urbs(struct usbnet *dev)
656{
657 if (netif_running(dev->net)) {
658 (void) unlink_urbs (dev, &dev->rxq);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700659 queue_work(usbnet_wq, &dev->bh_w);
Jamie Paintera99c1942006-07-27 14:17:28 -0400660 }
661}
662EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664/*-------------------------------------------------------------------------*/
665
666// precondition: never called in_interrupt
Oliver Neukum69ee4722009-12-03 15:31:18 -0800667static void usbnet_terminate_urbs(struct usbnet *dev)
668{
Oliver Neukum69ee4722009-12-03 15:31:18 -0800669 DECLARE_WAITQUEUE(wait, current);
670 int temp;
671
672 /* ensure there are no more active urbs */
673 add_wait_queue(&unlink_wakeup, &wait);
674 set_current_state(TASK_UNINTERRUPTIBLE);
675 dev->wait = &unlink_wakeup;
676 temp = unlink_urbs(dev, &dev->txq) +
677 unlink_urbs(dev, &dev->rxq);
678
679 /* maybe wait for deletions to finish. */
680 while (!skb_queue_empty(&dev->rxq)
681 && !skb_queue_empty(&dev->txq)
682 && !skb_queue_empty(&dev->done)) {
Kulikov Vasiliy66cc42a2010-07-25 22:25:42 +0000683 schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS));
Oliver Neukum69ee4722009-12-03 15:31:18 -0800684 set_current_state(TASK_UNINTERRUPTIBLE);
Joe Perchesa475f602010-02-17 10:30:24 +0000685 netif_dbg(dev, ifdown, dev->net,
686 "waited for %d urb completions\n", temp);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800687 }
688 set_current_state(TASK_RUNNING);
689 dev->wait = NULL;
690 remove_wait_queue(&unlink_wakeup, &wait);
691}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Stephen Hemminger777baa42009-03-20 19:35:54 +0000693int usbnet_stop (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
695 struct usbnet *dev = netdev_priv(net);
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300696 struct driver_info *info = dev->driver_info;
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300697 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Ming Lei75bd0cb2011-04-28 22:37:09 +0000699 clear_bit(EVENT_DEV_OPEN, &dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 netif_stop_queue (net);
701
Joe Perchesa475f602010-02-17 10:30:24 +0000702 netif_info(dev, ifdown, dev->net,
Ben Hutchings8ccef432010-06-08 08:20:59 +0000703 "stop stats: rx/tx %lu/%lu, errs %lu/%lu\n",
Joe Perchesa475f602010-02-17 10:30:24 +0000704 net->stats.rx_packets, net->stats.tx_packets,
705 net->stats.rx_errors, net->stats.tx_errors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300707 /* allow minidriver to stop correctly (wireless devices to turn off
708 * radio etc) */
709 if (info->stop) {
710 retval = info->stop(dev);
Joe Perchesa475f602010-02-17 10:30:24 +0000711 if (retval < 0)
712 netif_info(dev, ifdown, dev->net,
713 "stop fail (%d) usbnet usb-%s-%s, %s\n",
714 retval,
715 dev->udev->bus->bus_name, dev->udev->devpath,
716 info->description);
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300717 }
718
Oliver Neukum69ee4722009-12-03 15:31:18 -0800719 if (!(info->flags & FLAG_AVOID_UNLINK_URBS))
720 usbnet_terminate_urbs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 usb_kill_urb(dev->interrupt);
723
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300724 usbnet_purge_paused_rxq(dev);
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* deferred work (task, timer, softirq) must also stop.
727 * can't flush_scheduled_work() until we drop rtnl (later),
728 * else workers could deadlock; so make workers a NOP.
729 */
730 dev->flags = 0;
731 del_timer_sync (&dev->delay);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700732 cancel_work_sync(&dev->bh_w);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800733 if (info->manage_power)
734 info->manage_power(dev, 0);
735 else
736 usb_autopm_put_interface(dev->intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 return 0;
739}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000740EXPORT_SYMBOL_GPL(usbnet_stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742/*-------------------------------------------------------------------------*/
743
744// posts reads, and enables write queuing
745
746// precondition: never called in_interrupt
747
Stephen Hemminger777baa42009-03-20 19:35:54 +0000748int usbnet_open (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 struct usbnet *dev = netdev_priv(net);
Oliver Neukuma11a6542007-08-03 13:52:19 +0200751 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct driver_info *info = dev->driver_info;
753
Oliver Neukuma11a6542007-08-03 13:52:19 +0200754 if ((retval = usb_autopm_get_interface(dev->intf)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000755 netif_info(dev, ifup, dev->net,
756 "resumption fail (%d) usbnet usb-%s-%s, %s\n",
757 retval,
758 dev->udev->bus->bus_name,
759 dev->udev->devpath,
760 info->description);
Oliver Neukuma11a6542007-08-03 13:52:19 +0200761 goto done_nopm;
762 }
763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 // put into "known safe" state
765 if (info->reset && (retval = info->reset (dev)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000766 netif_info(dev, ifup, dev->net,
767 "open reset fail (%d) usbnet usb-%s-%s, %s\n",
768 retval,
769 dev->udev->bus->bus_name,
770 dev->udev->devpath,
771 info->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 goto done;
773 }
774
775 // insist peer be connected
776 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000777 netif_dbg(dev, ifup, dev->net, "can't open; %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 goto done;
779 }
780
781 /* start any status interrupt transfer */
782 if (dev->interrupt) {
783 retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
784 if (retval < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000785 netif_err(dev, ifup, dev->net,
786 "intr submit %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 goto done;
788 }
789 }
790
Paul Stewart68972ef2011-04-28 05:43:37 +0000791 set_bit(EVENT_DEV_OPEN, &dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 netif_start_queue (net);
Joe Perchesa475f602010-02-17 10:30:24 +0000793 netif_info(dev, ifup, dev->net,
794 "open: enable queueing (rx %d, tx %d) mtu %d %s framing\n",
795 (int)RX_QLEN(dev), (int)TX_QLEN(dev),
796 dev->net->mtu,
797 (dev->driver_info->flags & FLAG_FRAMING_NC) ? "NetChip" :
798 (dev->driver_info->flags & FLAG_FRAMING_GL) ? "GeneSys" :
799 (dev->driver_info->flags & FLAG_FRAMING_Z) ? "Zaurus" :
800 (dev->driver_info->flags & FLAG_FRAMING_RN) ? "RNDIS" :
801 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
802 "simple");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 // delay posting reads until we're fully open
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700805 queue_work(usbnet_wq, &dev->bh_w);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800806 if (info->manage_power) {
807 retval = info->manage_power(dev, 1);
808 if (retval < 0)
809 goto done;
810 usb_autopm_put_interface(dev->intf);
811 }
Oliver Neukuma11a6542007-08-03 13:52:19 +0200812 return retval;
Joe Perchesa475f602010-02-17 10:30:24 +0000813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814done:
Oliver Neukuma11a6542007-08-03 13:52:19 +0200815 usb_autopm_put_interface(dev->intf);
816done_nopm:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 return retval;
818}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000819EXPORT_SYMBOL_GPL(usbnet_open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821/*-------------------------------------------------------------------------*/
822
David Brownell2e55cc72005-08-31 09:53:10 -0700823/* ethtool methods; minidrivers may need to add some more, but
824 * they'll probably want to use this base set.
825 */
826
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200827int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd)
828{
829 struct usbnet *dev = netdev_priv(net);
830
831 if (!dev->mii.mdio_read)
832 return -EOPNOTSUPP;
833
834 return mii_ethtool_gset(&dev->mii, cmd);
835}
836EXPORT_SYMBOL_GPL(usbnet_get_settings);
837
838int usbnet_set_settings (struct net_device *net, struct ethtool_cmd *cmd)
839{
840 struct usbnet *dev = netdev_priv(net);
841 int retval;
842
843 if (!dev->mii.mdio_write)
844 return -EOPNOTSUPP;
845
846 retval = mii_ethtool_sset(&dev->mii, cmd);
847
848 /* link speed/duplex might have changed */
849 if (dev->driver_info->link_reset)
850 dev->driver_info->link_reset(dev);
851
852 return retval;
853
854}
855EXPORT_SYMBOL_GPL(usbnet_set_settings);
856
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200857u32 usbnet_get_link (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
859 struct usbnet *dev = netdev_priv(net);
860
David Brownellf29fc252005-08-31 09:52:31 -0700861 /* If a check_connect is defined, return its result */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (dev->driver_info->check_connect)
863 return dev->driver_info->check_connect (dev) == 0;
864
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200865 /* if the device has mii operations, use those */
866 if (dev->mii.mdio_read)
867 return mii_link_ok(&dev->mii);
868
Bjørn Mork05ffb3e2009-03-01 20:45:40 -0800869 /* Otherwise, dtrt for drivers calling netif_carrier_{on,off} */
870 return ethtool_op_get_link(net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200872EXPORT_SYMBOL_GPL(usbnet_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
David Brownell18ee91fa2006-11-02 12:29:12 -0800874int usbnet_nway_reset(struct net_device *net)
875{
876 struct usbnet *dev = netdev_priv(net);
877
878 if (!dev->mii.mdio_write)
879 return -EOPNOTSUPP;
880
881 return mii_nway_restart(&dev->mii);
882}
883EXPORT_SYMBOL_GPL(usbnet_nway_reset);
884
David Brownell18ee91fa2006-11-02 12:29:12 -0800885void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
886{
887 struct usbnet *dev = netdev_priv(net);
888
David Brownell296c0242007-04-17 16:10:10 -0700889 strncpy (info->driver, dev->driver_name, sizeof info->driver);
David Brownell18ee91fa2006-11-02 12:29:12 -0800890 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
891 strncpy (info->fw_version, dev->driver_info->description,
892 sizeof info->fw_version);
893 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
894}
895EXPORT_SYMBOL_GPL(usbnet_get_drvinfo);
896
David Brownell2e55cc72005-08-31 09:53:10 -0700897u32 usbnet_get_msglevel (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 struct usbnet *dev = netdev_priv(net);
900
901 return dev->msg_enable;
902}
David Brownell2e55cc72005-08-31 09:53:10 -0700903EXPORT_SYMBOL_GPL(usbnet_get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
David Brownell2e55cc72005-08-31 09:53:10 -0700905void usbnet_set_msglevel (struct net_device *net, u32 level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
907 struct usbnet *dev = netdev_priv(net);
908
909 dev->msg_enable = level;
910}
David Brownell2e55cc72005-08-31 09:53:10 -0700911EXPORT_SYMBOL_GPL(usbnet_set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
David Brownell2e55cc72005-08-31 09:53:10 -0700913/* drivers may override default ethtool_ops in their bind() routine */
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700914static const struct ethtool_ops usbnet_ethtool_ops = {
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200915 .get_settings = usbnet_get_settings,
916 .set_settings = usbnet_set_settings,
David Brownell2e55cc72005-08-31 09:53:10 -0700917 .get_link = usbnet_get_link,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200918 .nway_reset = usbnet_nway_reset,
David Brownell18ee91fa2006-11-02 12:29:12 -0800919 .get_drvinfo = usbnet_get_drvinfo,
David Brownell2e55cc72005-08-31 09:53:10 -0700920 .get_msglevel = usbnet_get_msglevel,
921 .set_msglevel = usbnet_set_msglevel,
922};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924/*-------------------------------------------------------------------------*/
925
926/* work that cannot be done in interrupt context uses keventd.
927 *
928 * NOTE: with 2.5 we could do more of this using completion callbacks,
929 * especially now that control transfers can be queued.
930 */
931static void
David Howellsc4028952006-11-22 14:57:56 +0000932kevent (struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
David Howellsc4028952006-11-22 14:57:56 +0000934 struct usbnet *dev =
935 container_of(work, struct usbnet, kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 int status;
937
938 /* usb_clear_halt() needs a thread context */
939 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
940 unlink_urbs (dev, &dev->txq);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800941 status = usb_autopm_get_interface(dev->intf);
942 if (status < 0)
943 goto fail_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 status = usb_clear_halt (dev->udev, dev->out);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800945 usb_autopm_put_interface(dev->intf);
Joe Perches8e95a202009-12-03 07:58:21 +0000946 if (status < 0 &&
947 status != -EPIPE &&
948 status != -ESHUTDOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (netif_msg_tx_err (dev))
Oliver Neukum69ee4722009-12-03 15:31:18 -0800950fail_pipe:
Joe Perches60b86752010-02-17 10:30:23 +0000951 netdev_err(dev->net, "can't clear tx halt, status %d\n",
952 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 } else {
954 clear_bit (EVENT_TX_HALT, &dev->flags);
David Brownellf29fc252005-08-31 09:52:31 -0700955 if (status != -ESHUTDOWN)
956 netif_wake_queue (dev->net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958 }
959 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
960 unlink_urbs (dev, &dev->rxq);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800961 status = usb_autopm_get_interface(dev->intf);
962 if (status < 0)
963 goto fail_halt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 status = usb_clear_halt (dev->udev, dev->in);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800965 usb_autopm_put_interface(dev->intf);
Joe Perches8e95a202009-12-03 07:58:21 +0000966 if (status < 0 &&
967 status != -EPIPE &&
968 status != -ESHUTDOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (netif_msg_rx_err (dev))
Oliver Neukum69ee4722009-12-03 15:31:18 -0800970fail_halt:
Joe Perches60b86752010-02-17 10:30:23 +0000971 netdev_err(dev->net, "can't clear rx halt, status %d\n",
972 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 } else {
974 clear_bit (EVENT_RX_HALT, &dev->flags);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700975 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
977 }
978
979 /* tasklet could resubmit itself forever if memory is tight */
980 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
981 struct urb *urb = NULL;
David S. Millerdacb3972010-08-10 02:50:55 -0700982 int resched = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 if (netif_running (dev->net))
985 urb = usb_alloc_urb (0, GFP_KERNEL);
986 else
987 clear_bit (EVENT_RX_MEMORY, &dev->flags);
988 if (urb != NULL) {
989 clear_bit (EVENT_RX_MEMORY, &dev->flags);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800990 status = usb_autopm_get_interface(dev->intf);
Jesper Juhlab607072011-02-10 10:58:45 +0000991 if (status < 0) {
992 usb_free_urb(urb);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800993 goto fail_lowmem;
Jesper Juhlab607072011-02-10 10:58:45 +0000994 }
David S. Millerdacb3972010-08-10 02:50:55 -0700995 if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK)
996 resched = 0;
Oliver Neukum69ee4722009-12-03 15:31:18 -0800997 usb_autopm_put_interface(dev->intf);
998fail_lowmem:
David S. Millerdacb3972010-08-10 02:50:55 -0700999 if (resched)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001000 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002 }
1003
David Hollis7ea13c92005-04-22 15:07:02 -07001004 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
David Brownellcb1cebb2007-02-15 18:52:30 -08001005 struct driver_info *info = dev->driver_info;
David Hollis7ea13c92005-04-22 15:07:02 -07001006 int retval = 0;
1007
1008 clear_bit (EVENT_LINK_RESET, &dev->flags);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001009 status = usb_autopm_get_interface(dev->intf);
1010 if (status < 0)
1011 goto skip_reset;
David Hollis7ea13c92005-04-22 15:07:02 -07001012 if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001013 usb_autopm_put_interface(dev->intf);
1014skip_reset:
Joe Perches60b86752010-02-17 10:30:23 +00001015 netdev_info(dev->net, "link reset failed (%d) usbnet usb-%s-%s, %s\n",
1016 retval,
1017 dev->udev->bus->bus_name,
1018 dev->udev->devpath,
1019 info->description);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001020 } else {
1021 usb_autopm_put_interface(dev->intf);
David Hollis7ea13c92005-04-22 15:07:02 -07001022 }
1023 }
1024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 if (dev->flags)
Joe Perches60b86752010-02-17 10:30:23 +00001026 netdev_dbg(dev->net, "kevent done, flags = 0x%lx\n", dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
1029/*-------------------------------------------------------------------------*/
1030
David Howells7d12e782006-10-05 14:55:46 +01001031static void tx_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 struct sk_buff *skb = (struct sk_buff *) urb->context;
1034 struct skb_data *entry = (struct skb_data *) skb->cb;
1035 struct usbnet *dev = entry->dev;
1036
1037 if (urb->status == 0) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001038 if (!(dev->driver_info->flags & FLAG_MULTI_PACKET))
1039 dev->net->stats.tx_packets++;
Herbert Xu79638372009-06-29 16:53:28 +00001040 dev->net->stats.tx_bytes += entry->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 } else {
Herbert Xu79638372009-06-29 16:53:28 +00001042 dev->net->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 switch (urb->status) {
1045 case -EPIPE:
David Brownell2e55cc72005-08-31 09:53:10 -07001046 usbnet_defer_kevent (dev, EVENT_TX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 break;
1048
1049 /* software-driven interface shutdown */
1050 case -ECONNRESET: // async unlink
1051 case -ESHUTDOWN: // hardware gone
1052 break;
1053
1054 // like rx, tx gets controller i/o faults during khubd delays
1055 // and so it uses the same throttling mechanism.
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -07001056 case -EPROTO:
1057 case -ETIME:
1058 case -EILSEQ:
Oliver Neukum69ee4722009-12-03 15:31:18 -08001059 usb_mark_last_busy(dev->udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 if (!timer_pending (&dev->delay)) {
1061 mod_timer (&dev->delay,
1062 jiffies + THROTTLE_JIFFIES);
Joe Perchesa475f602010-02-17 10:30:24 +00001063 netif_dbg(dev, link, dev->net,
1064 "tx throttle %d\n", urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 netif_stop_queue (dev->net);
1067 break;
1068 default:
Joe Perchesa475f602010-02-17 10:30:24 +00001069 netif_dbg(dev, tx_err, dev->net,
1070 "tx err %d\n", entry->urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 break;
1072 }
1073 }
1074
Oliver Neukum69ee4722009-12-03 15:31:18 -08001075 usb_autopm_put_interface_async(dev->intf);
Ming Lei5b6e9bc2012-04-26 11:33:46 +08001076 (void) defer_bh(dev, skb, &dev->txq, tx_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
1079/*-------------------------------------------------------------------------*/
1080
Stephen Hemminger777baa42009-03-20 19:35:54 +00001081void usbnet_tx_timeout (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
1083 struct usbnet *dev = netdev_priv(net);
1084
1085 unlink_urbs (dev, &dev->txq);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001086 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088 // FIXME: device recovery -- reset?
1089}
Stephen Hemminger777baa42009-03-20 19:35:54 +00001090EXPORT_SYMBOL_GPL(usbnet_tx_timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092/*-------------------------------------------------------------------------*/
1093
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001094netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1095 struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096{
1097 struct usbnet *dev = netdev_priv(net);
1098 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 struct urb *urb = NULL;
1100 struct skb_data *entry;
1101 struct driver_info *info = dev->driver_info;
1102 unsigned long flags;
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001103 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Konstantin Khlebnikov23ba0792011-11-07 05:54:58 +00001105 if (skb)
1106 skb_tx_timestamp(skb);
Michael Rieschf9b491e2011-09-29 04:06:26 +00001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 // some devices want funky USB-level framing, for
1109 // win32 driver (usually) and/or hardware quirks
1110 if (info->tx_fixup) {
1111 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
1112 if (!skb) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001113 if (netif_msg_tx_err(dev)) {
1114 netif_dbg(dev, tx_err, dev->net, "can't tx_fixup skb\n");
1115 goto drop;
1116 } else {
1117 /* cdc_ncm collected packet; waits for more */
1118 goto not_drop;
1119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121 }
1122 length = skb->len;
1123
1124 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001125 netif_dbg(dev, tx_err, dev->net, "no urb\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 goto drop;
1127 }
1128
1129 entry = (struct skb_data *) skb->cb;
1130 entry->urb = urb;
1131 entry->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 entry->length = length;
1133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 usb_fill_bulk_urb (urb, dev->udev, dev->out,
1135 skb->data, skb->len, tx_complete, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137 /* don't assume the hardware handles USB_ZERO_PACKET
1138 * NOTE: strictly conforming cdc-ether devices should expect
1139 * the ZLP here, but ignore the one-byte packet.
Alexey Orishko073285f2010-11-29 23:23:27 +00001140 * NOTE2: CDC NCM specification is different from CDC ECM when
1141 * handling ZLP/short packets, so cdc_ncm driver will make short
1142 * packet itself if needed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 */
Elina Pashevab4d562e2010-04-06 14:23:07 +00001144 if (length % dev->maxpacket == 0) {
1145 if (!(info->flags & FLAG_SEND_ZLP)) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001146 if (!(info->flags & FLAG_MULTI_PACKET)) {
1147 urb->transfer_buffer_length++;
1148 if (skb_tailroom(skb)) {
1149 skb->data[skb->len] = 0;
1150 __skb_put(skb, 1);
1151 }
Elina Pashevab4d562e2010-04-06 14:23:07 +00001152 }
1153 } else
1154 urb->transfer_flags |= URB_ZERO_PACKET;
Peter Korsgaard3e323f32007-06-27 08:48:15 +02001155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Oliver Neukum69ee4722009-12-03 15:31:18 -08001157 spin_lock_irqsave(&dev->txq.lock, flags);
1158 retval = usb_autopm_get_interface_async(dev->intf);
1159 if (retval < 0) {
1160 spin_unlock_irqrestore(&dev->txq.lock, flags);
1161 goto drop;
1162 }
1163
1164#ifdef CONFIG_PM
1165 /* if this triggers the device is still a sleep */
1166 if (test_bit(EVENT_DEV_ASLEEP, &dev->flags)) {
1167 /* transmission will be done in resume */
1168 usb_anchor_urb(urb, &dev->deferred);
1169 /* no use to process more packets */
1170 netif_stop_queue(net);
1171 spin_unlock_irqrestore(&dev->txq.lock, flags);
Joe Perches60b86752010-02-17 10:30:23 +00001172 netdev_dbg(dev->net, "Delaying transmission for resumption\n");
Oliver Neukum69ee4722009-12-03 15:31:18 -08001173 goto deferred;
1174 }
1175#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
1178 case -EPIPE:
1179 netif_stop_queue (net);
David Brownell2e55cc72005-08-31 09:53:10 -07001180 usbnet_defer_kevent (dev, EVENT_TX_HALT);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001181 usb_autopm_put_interface_async(dev->intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183 default:
Oliver Neukum69ee4722009-12-03 15:31:18 -08001184 usb_autopm_put_interface_async(dev->intf);
Joe Perchesa475f602010-02-17 10:30:24 +00001185 netif_dbg(dev, tx_err, dev->net,
1186 "tx: submit urb err %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 break;
1188 case 0:
1189 net->trans_start = jiffies;
Ming Lei5b6e9bc2012-04-26 11:33:46 +08001190 __usbnet_queue_skb(&dev->txq, skb, tx_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 if (dev->txq.qlen >= TX_QLEN (dev))
1192 netif_stop_queue (net);
1193 }
1194 spin_unlock_irqrestore (&dev->txq.lock, flags);
1195
1196 if (retval) {
Joe Perchesa475f602010-02-17 10:30:24 +00001197 netif_dbg(dev, tx_err, dev->net, "drop, code %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198drop:
Herbert Xu79638372009-06-29 16:53:28 +00001199 dev->net->stats.tx_dropped++;
Alexey Orishko073285f2010-11-29 23:23:27 +00001200not_drop:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (skb)
1202 dev_kfree_skb_any (skb);
1203 usb_free_urb (urb);
Joe Perchesa475f602010-02-17 10:30:24 +00001204 } else
1205 netif_dbg(dev, tx_queued, dev->net,
1206 "> tx, len %d, type 0x%x\n", length, skb->protocol);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001207#ifdef CONFIG_PM
1208deferred:
1209#endif
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001210 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
Stephen Hemminger777baa42009-03-20 19:35:54 +00001212EXPORT_SYMBOL_GPL(usbnet_start_xmit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214/*-------------------------------------------------------------------------*/
1215
1216// tasklet (work deferred from completions, in_irq) or timer
1217
1218static void usbnet_bh (unsigned long param)
1219{
1220 struct usbnet *dev = (struct usbnet *) param;
1221 struct sk_buff *skb;
1222 struct skb_data *entry;
1223
1224 while ((skb = skb_dequeue (&dev->done))) {
1225 entry = (struct skb_data *) skb->cb;
1226 switch (entry->state) {
David Brownell18ab4582007-05-25 12:31:32 -07001227 case rx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 entry->state = rx_cleanup;
1229 rx_process (dev, skb);
1230 continue;
David Brownell18ab4582007-05-25 12:31:32 -07001231 case tx_done:
1232 case rx_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 usb_free_urb (entry->urb);
1234 dev_kfree_skb (skb);
1235 continue;
David Brownell18ab4582007-05-25 12:31:32 -07001236 default:
Joe Perches60b86752010-02-17 10:30:23 +00001237 netdev_dbg(dev->net, "bogus skb state %d\n", entry->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239 }
1240
1241 // waiting for all pending urbs to complete?
1242 if (dev->wait) {
1243 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
Hemant Kumaref59a422012-08-15 16:57:00 -07001244 wake_up(&unlink_wakeup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 }
1246
1247 // or are we maybe short a few urbs?
Joe Perches8e95a202009-12-03 07:58:21 +00001248 } else if (netif_running (dev->net) &&
1249 netif_device_present (dev->net) &&
1250 !timer_pending (&dev->delay) &&
1251 !test_bit (EVENT_RX_HALT, &dev->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 int temp = dev->rxq.qlen;
1253 int qlen = RX_QLEN (dev);
1254
1255 if (temp < qlen) {
1256 struct urb *urb;
1257 int i;
1258
1259 // don't refill the queue all at once
1260 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
1261 urb = usb_alloc_urb (0, GFP_ATOMIC);
David S. Millerdacb3972010-08-10 02:50:55 -07001262 if (urb != NULL) {
1263 if (rx_submit (dev, urb, GFP_ATOMIC) ==
1264 -ENOLINK)
1265 return;
1266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
Joe Perchesa475f602010-02-17 10:30:24 +00001268 if (temp != dev->rxq.qlen)
1269 netif_dbg(dev, link, dev->net,
1270 "rxqlen %d --> %d\n",
1271 temp, dev->rxq.qlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if (dev->rxq.qlen < qlen)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001273 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
1275 if (dev->txq.qlen < TX_QLEN (dev))
1276 netif_wake_queue (dev->net);
1277 }
1278}
1279
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001280static void usbnet_bh_w(struct work_struct *work)
1281{
1282 struct usbnet *dev =
1283 container_of(work, struct usbnet, bh_w);
1284 unsigned long param = (unsigned long)dev;
1285
1286 usbnet_bh(param);
1287}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289/*-------------------------------------------------------------------------
1290 *
1291 * USB Device Driver support
1292 *
1293 *-------------------------------------------------------------------------*/
David Brownellcb1cebb2007-02-15 18:52:30 -08001294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295// precondition: never called in_interrupt
1296
David Brownell38bde1d2005-08-31 09:52:45 -07001297void usbnet_disconnect (struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
1299 struct usbnet *dev;
1300 struct usb_device *xdev;
1301 struct net_device *net;
1302
1303 dev = usb_get_intfdata(intf);
1304 usb_set_intfdata(intf, NULL);
1305 if (!dev)
1306 return;
1307
1308 xdev = interface_to_usbdev (intf);
1309
Joe Perchesa475f602010-02-17 10:30:24 +00001310 netif_info(dev, probe, dev->net, "unregister '%s' usb-%s-%s, %s\n",
1311 intf->dev.driver->name,
1312 xdev->bus->bus_name, xdev->devpath,
1313 dev->driver_info->description);
David Brownellcb1cebb2007-02-15 18:52:30 -08001314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 net = dev->net;
1316 unregister_netdev (net);
1317
Tejun Heo23f333a2010-12-12 16:45:14 +01001318 cancel_work_sync(&dev->kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 if (dev->driver_info->unbind)
1321 dev->driver_info->unbind (dev, intf);
1322
Paul Stewart68972ef2011-04-28 05:43:37 +00001323 usb_kill_urb(dev->interrupt);
1324 usb_free_urb(dev->interrupt);
1325
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 free_netdev(net);
1327 usb_put_dev (xdev);
1328}
David Brownell38bde1d2005-08-31 09:52:45 -07001329EXPORT_SYMBOL_GPL(usbnet_disconnect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Stephen Hemminger777baa42009-03-20 19:35:54 +00001331static const struct net_device_ops usbnet_netdev_ops = {
1332 .ndo_open = usbnet_open,
1333 .ndo_stop = usbnet_stop,
1334 .ndo_start_xmit = usbnet_start_xmit,
1335 .ndo_tx_timeout = usbnet_tx_timeout,
1336 .ndo_change_mtu = usbnet_change_mtu,
1337 .ndo_set_mac_address = eth_mac_addr,
1338 .ndo_validate_addr = eth_validate_addr,
1339};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341/*-------------------------------------------------------------------------*/
1342
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343// precondition: never called in_interrupt
1344
Marcel Holtmann225794f2009-10-02 05:15:26 +00001345static struct device_type wlan_type = {
1346 .name = "wlan",
1347};
1348
1349static struct device_type wwan_type = {
1350 .name = "wwan",
1351};
1352
David Brownell38bde1d2005-08-31 09:52:45 -07001353int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1355{
1356 struct usbnet *dev;
David Brownellcb1cebb2007-02-15 18:52:30 -08001357 struct net_device *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 struct usb_host_interface *interface;
1359 struct driver_info *info;
1360 struct usb_device *xdev;
1361 int status;
David Brownell296c0242007-04-17 16:10:10 -07001362 const char *name;
Ming Leib0786b42010-11-01 07:11:54 -07001363 struct usb_driver *driver = to_usb_driver(udev->dev.driver);
1364
1365 /* usbnet already took usb runtime pm, so have to enable the feature
1366 * for usb interface, otherwise usb_autopm_get_interface may return
1367 * failure if USB_SUSPEND(RUNTIME_PM) is enabled.
1368 */
1369 if (!driver->supports_autosuspend) {
1370 driver->supports_autosuspend = 1;
1371 pm_runtime_enable(&udev->dev);
1372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
David Brownell296c0242007-04-17 16:10:10 -07001374 name = udev->dev.driver->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 info = (struct driver_info *) prod->driver_info;
1376 if (!info) {
David Brownell296c0242007-04-17 16:10:10 -07001377 dev_dbg (&udev->dev, "blacklisted by %s\n", name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 return -ENODEV;
1379 }
1380 xdev = interface_to_usbdev (udev);
1381 interface = udev->cur_altsetting;
1382
1383 usb_get_dev (xdev);
1384
1385 status = -ENOMEM;
1386
1387 // set up our own records
1388 net = alloc_etherdev(sizeof(*dev));
Joe Perches41de8d42012-01-29 13:47:52 +00001389 if (!net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Ben Hutchings0dacca72010-07-02 21:49:02 -07001392 /* netdev_printk() needs this so do it as early as possible */
1393 SET_NETDEV_DEV(net, &udev->dev);
1394
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 dev = netdev_priv(net);
1396 dev->udev = xdev;
Oliver Neukuma11a6542007-08-03 13:52:19 +02001397 dev->intf = udev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 dev->driver_info = info;
David Brownell296c0242007-04-17 16:10:10 -07001399 dev->driver_name = name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
1401 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1402 skb_queue_head_init (&dev->rxq);
1403 skb_queue_head_init (&dev->txq);
1404 skb_queue_head_init (&dev->done);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001405 skb_queue_head_init(&dev->rxq_pause);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001406 INIT_WORK(&dev->bh_w, usbnet_bh_w);
David Howellsc4028952006-11-22 14:57:56 +00001407 INIT_WORK (&dev->kevent, kevent);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001408 init_usb_anchor(&dev->deferred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 dev->delay.function = usbnet_bh;
1410 dev->delay.data = (unsigned long) dev;
1411 init_timer (&dev->delay);
Arnd Bergmanna9fc6332006-10-09 00:08:02 +02001412 mutex_init (&dev->phy_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 dev->net = net;
1415 strcpy (net->name, "usb%d");
1416 memcpy (net->dev_addr, node_id, sizeof node_id);
1417
David Brownell2e55cc72005-08-31 09:53:10 -07001418 /* rx and tx sides can use different message sizes;
1419 * bind() should set rx_urb_size in that case.
1420 */
1421 dev->hard_mtu = net->mtu + net->hard_header_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422#if 0
1423// dma_supported() is deeply broken on almost all architectures
1424 // possible with some EHCI controllers
Yang Hongyang6a355282009-04-06 19:01:13 -07001425 if (dma_supported (&udev->dev, DMA_BIT_MASK(64)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 net->features |= NETIF_F_HIGHDMA;
1427#endif
1428
Stephen Hemminger777baa42009-03-20 19:35:54 +00001429 net->netdev_ops = &usbnet_netdev_ops;
Stephen Hemminger777baa42009-03-20 19:35:54 +00001430 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 net->ethtool_ops = &usbnet_ethtool_ops;
1432
1433 // allow device-specific bind/init procedures
1434 // NOTE net->name still not usable ...
1435 if (info->bind) {
1436 status = info->bind (dev, udev);
David Brownellcb1cebb2007-02-15 18:52:30 -08001437 if (status < 0)
1438 goto out1;
1439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 // heuristic: "usb%d" for links we know are two-host,
1441 // else "eth%d" when there's reasonable doubt. userspace
1442 // can rename the link if it knows better.
Joe Perches8e95a202009-12-03 07:58:21 +00001443 if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
Arnd Bergmannc2613442011-04-01 20:12:02 -07001444 ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
1445 (net->dev_addr [0] & 0x02) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 strcpy (net->name, "eth%d");
Jussi Kivilinna6e3bbcc2008-01-26 00:51:06 +02001447 /* WLAN devices should always be named "wlan%d" */
1448 if ((dev->driver_info->flags & FLAG_WLAN) != 0)
1449 strcpy(net->name, "wlan%d");
Marcel Holtmanne1e499e2009-10-02 05:15:25 +00001450 /* WWAN devices should always be named "wwan%d" */
1451 if ((dev->driver_info->flags & FLAG_WWAN) != 0)
1452 strcpy(net->name, "wwan%d");
David Brownellf29fc252005-08-31 09:52:31 -07001453
1454 /* maybe the remote can't receive an Ethernet MTU */
1455 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
1456 net->mtu = dev->hard_mtu - net->hard_header_len;
David Brownell2e55cc72005-08-31 09:53:10 -07001457 } else if (!info->in || !info->out)
1458 status = usbnet_get_endpoints (dev, udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 else {
1460 dev->in = usb_rcvbulkpipe (xdev, info->in);
1461 dev->out = usb_sndbulkpipe (xdev, info->out);
1462 if (!(info->flags & FLAG_NO_SETINT))
1463 status = usb_set_interface (xdev,
1464 interface->desc.bInterfaceNumber,
1465 interface->desc.bAlternateSetting);
1466 else
1467 status = 0;
1468
1469 }
Peter Korsgaard9514bfe2007-07-03 00:46:42 +02001470 if (status >= 0 && dev->status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 status = init_status (dev, udev);
1472 if (status < 0)
David Brownellcb1cebb2007-02-15 18:52:30 -08001473 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
David Brownell2e55cc72005-08-31 09:53:10 -07001475 if (!dev->rx_urb_size)
1476 dev->rx_urb_size = dev->hard_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
David Brownellcb1cebb2007-02-15 18:52:30 -08001478
Marcel Holtmann225794f2009-10-02 05:15:26 +00001479 if ((dev->driver_info->flags & FLAG_WLAN) != 0)
1480 SET_NETDEV_DEVTYPE(net, &wlan_type);
1481 if ((dev->driver_info->flags & FLAG_WWAN) != 0)
1482 SET_NETDEV_DEVTYPE(net, &wwan_type);
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 status = register_netdev (net);
1485 if (status)
tom.leiming@gmail.coma4723842012-04-29 22:51:03 +00001486 goto out4;
Joe Perchesa475f602010-02-17 10:30:24 +00001487 netif_info(dev, probe, dev->net,
1488 "register '%s' at usb-%s-%s, %s, %pM\n",
1489 udev->dev.driver->name,
1490 xdev->bus->bus_name, xdev->devpath,
1491 dev->driver_info->description,
1492 net->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 // ok, it's ready to go.
1495 usb_set_intfdata (udev, dev);
1496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 netif_device_attach (net);
1498
Ben Hutchings37e82732009-11-04 15:29:52 +00001499 if (dev->driver_info->flags & FLAG_LINK_INTR)
1500 netif_carrier_off(net);
1501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 return 0;
1503
tom.leiming@gmail.coma4723842012-04-29 22:51:03 +00001504out4:
1505 usb_free_urb(dev->interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506out3:
1507 if (info->unbind)
1508 info->unbind (dev, udev);
1509out1:
1510 free_netdev(net);
1511out:
1512 usb_put_dev(xdev);
1513 return status;
1514}
David Brownell38bde1d2005-08-31 09:52:45 -07001515EXPORT_SYMBOL_GPL(usbnet_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517/*-------------------------------------------------------------------------*/
1518
Oliver Neukum36433122007-04-30 01:37:44 -07001519/*
1520 * suspend the whole driver as soon as the first interface is suspended
1521 * resume only when the last interface is resumed
David Brownell38bde1d2005-08-31 09:52:45 -07001522 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
David Brownell38bde1d2005-08-31 09:52:45 -07001524int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
1526 struct usbnet *dev = usb_get_intfdata(intf);
David Brownellcb1cebb2007-02-15 18:52:30 -08001527
Oliver Neukum36433122007-04-30 01:37:44 -07001528 if (!dev->suspend_count++) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001529 spin_lock_irq(&dev->txq.lock);
1530 /* don't autosuspend while transmitting */
Alan Stern5b1b0b82011-08-19 23:49:48 +02001531 if (dev->txq.qlen && PMSG_IS_AUTO(message)) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001532 spin_unlock_irq(&dev->txq.lock);
1533 return -EBUSY;
1534 } else {
1535 set_bit(EVENT_DEV_ASLEEP, &dev->flags);
1536 spin_unlock_irq(&dev->txq.lock);
1537 }
Oliver Neukuma11a6542007-08-03 13:52:19 +02001538 /*
1539 * accelerate emptying of the rx and queues, to avoid
Oliver Neukum36433122007-04-30 01:37:44 -07001540 * having everything error out.
1541 */
1542 netif_device_detach (dev->net);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001543 usbnet_terminate_urbs(dev);
1544 usb_kill_urb(dev->interrupt);
1545
Oliver Neukuma11a6542007-08-03 13:52:19 +02001546 /*
1547 * reattach so runtime management can use and
1548 * wake the device
1549 */
1550 netif_device_attach (dev->net);
Oliver Neukum36433122007-04-30 01:37:44 -07001551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 return 0;
1553}
David Brownell38bde1d2005-08-31 09:52:45 -07001554EXPORT_SYMBOL_GPL(usbnet_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
David Brownell38bde1d2005-08-31 09:52:45 -07001556int usbnet_resume (struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 struct usbnet *dev = usb_get_intfdata(intf);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001559 struct sk_buff *skb;
1560 struct urb *res;
1561 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Oliver Neukum69ee4722009-12-03 15:31:18 -08001563 if (!--dev->suspend_count) {
Paul Stewart68972ef2011-04-28 05:43:37 +00001564 /* resume interrupt URBs */
1565 if (dev->interrupt && test_bit(EVENT_DEV_OPEN, &dev->flags))
1566 usb_submit_urb(dev->interrupt, GFP_NOIO);
1567
Oliver Neukum69ee4722009-12-03 15:31:18 -08001568 spin_lock_irq(&dev->txq.lock);
1569 while ((res = usb_get_from_anchor(&dev->deferred))) {
1570
Oliver Neukum69ee4722009-12-03 15:31:18 -08001571 skb = (struct sk_buff *)res->context;
1572 retval = usb_submit_urb(res, GFP_ATOMIC);
1573 if (retval < 0) {
1574 dev_kfree_skb_any(skb);
1575 usb_free_urb(res);
1576 usb_autopm_put_interface_async(dev->intf);
1577 } else {
1578 dev->net->trans_start = jiffies;
1579 __skb_queue_tail(&dev->txq, skb);
1580 }
1581 }
1582
1583 smp_mb();
1584 clear_bit(EVENT_DEV_ASLEEP, &dev->flags);
1585 spin_unlock_irq(&dev->txq.lock);
Ming Lei75bd0cb2011-04-28 22:37:09 +00001586
1587 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
1588 if (!(dev->txq.qlen >= TX_QLEN(dev)))
Alexey Orishko1aa9bc52012-03-14 04:00:24 +00001589 netif_tx_wake_all_queues(dev->net);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001590 queue_work(usbnet_wq, &dev->bh_w);
Ming Lei75bd0cb2011-04-28 22:37:09 +00001591 }
Oliver Neukum69ee4722009-12-03 15:31:18 -08001592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return 0;
1594}
David Brownell38bde1d2005-08-31 09:52:45 -07001595EXPORT_SYMBOL_GPL(usbnet_resume);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
1598/*-------------------------------------------------------------------------*/
1599
David Brownellf29fc252005-08-31 09:52:31 -07001600static int __init usbnet_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Thiago Farinac582a952011-04-17 17:49:21 -07001602 /* Compiler should optimize this out. */
1603 BUILD_BUG_ON(
1604 FIELD_SIZEOF(struct sk_buff, cb) < sizeof(struct skb_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 random_ether_addr(node_id);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001607
1608 usbnet_wq = create_singlethread_workqueue("usbnet");
1609 if (!usbnet_wq) {
1610 pr_err("%s: Unable to create workqueue:usbnet\n", __func__);
1611 return -ENOMEM;
1612 }
1613
David Brownellcb1cebb2007-02-15 18:52:30 -08001614 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
David Brownellf29fc252005-08-31 09:52:31 -07001616module_init(usbnet_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
David Brownellf29fc252005-08-31 09:52:31 -07001618static void __exit usbnet_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001620 destroy_workqueue(usbnet_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
David Brownellf29fc252005-08-31 09:52:31 -07001622module_exit(usbnet_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
David Brownellf29fc252005-08-31 09:52:31 -07001624MODULE_AUTHOR("David Brownell");
David Brownell090ffa92005-08-31 09:54:50 -07001625MODULE_DESCRIPTION("USB network driver framework");
David Brownellf29fc252005-08-31 09:52:31 -07001626MODULE_LICENSE("GPL");