blob: d26c84569a0ce579f7b78c60454040c5c7628d10 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/* use ethtool to change the level for any given device */
93static int msg_level = -1;
94module_param (msg_level, int, 0);
95MODULE_PARM_DESC (msg_level, "Override default message level");
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*-------------------------------------------------------------------------*/
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* handles CDC Ethernet and many other network "bulk data" interfaces */
David Brownell2e55cc72005-08-31 09:53:10 -0700100int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 int tmp;
103 struct usb_host_interface *alt = NULL;
104 struct usb_host_endpoint *in = NULL, *out = NULL;
105 struct usb_host_endpoint *status = NULL;
106
107 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
108 unsigned ep;
109
110 in = out = status = NULL;
111 alt = intf->altsetting + tmp;
112
113 /* take the first altsetting with in-bulk + out-bulk;
114 * remember any status endpoint, just in case;
Justin P. Mattock70f23fd2011-05-10 10:16:21 +0200115 * ignore other endpoints and altsettings.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 */
117 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
118 struct usb_host_endpoint *e;
119 int intr = 0;
120
121 e = alt->endpoint + ep;
122 switch (e->desc.bmAttributes) {
123 case USB_ENDPOINT_XFER_INT:
Luiz Fernando N. Capitulinofc6e2542006-10-26 13:03:01 -0300124 if (!usb_endpoint_dir_in(&e->desc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 continue;
126 intr = 1;
127 /* FALLTHROUGH */
128 case USB_ENDPOINT_XFER_BULK:
129 break;
130 default:
131 continue;
132 }
Luiz Fernando N. Capitulinofc6e2542006-10-26 13:03:01 -0300133 if (usb_endpoint_dir_in(&e->desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (!intr && !in)
135 in = e;
136 else if (intr && !status)
137 status = e;
138 } else {
139 if (!out)
140 out = e;
141 }
142 }
143 if (in && out)
144 break;
145 }
146 if (!alt || !in || !out)
147 return -EINVAL;
148
Joe Perches8e95a202009-12-03 07:58:21 +0000149 if (alt->desc.bAlternateSetting != 0 ||
150 !(dev->driver_info->flags & FLAG_NO_SETINT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 tmp = usb_set_interface (dev->udev, alt->desc.bInterfaceNumber,
152 alt->desc.bAlternateSetting);
153 if (tmp < 0)
154 return tmp;
155 }
David Brownellcb1cebb2007-02-15 18:52:30 -0800156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 dev->in = usb_rcvbulkpipe (dev->udev,
158 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
159 dev->out = usb_sndbulkpipe (dev->udev,
160 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
161 dev->status = status;
162 return 0;
163}
David Brownell2e55cc72005-08-31 09:53:10 -0700164EXPORT_SYMBOL_GPL(usbnet_get_endpoints);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Peter Holik03ad0322009-04-18 07:24:17 +0000166int usbnet_get_ethernet_addr(struct usbnet *dev, int iMACAddress)
167{
168 int tmp, i;
169 unsigned char buf [13];
170
171 tmp = usb_string(dev->udev, iMACAddress, buf, sizeof buf);
172 if (tmp != 12) {
173 dev_dbg(&dev->udev->dev,
174 "bad MAC string %d fetch, %d\n", iMACAddress, tmp);
175 if (tmp >= 0)
176 tmp = -EINVAL;
177 return tmp;
178 }
179 for (i = tmp = 0; i < 6; i++, tmp += 2)
180 dev->net->dev_addr [i] =
Andy Shevchenkofd1f1702010-07-23 03:18:08 +0000181 (hex_to_bin(buf[tmp]) << 4) + hex_to_bin(buf[tmp + 1]);
Peter Holik03ad0322009-04-18 07:24:17 +0000182 return 0;
183}
184EXPORT_SYMBOL_GPL(usbnet_get_ethernet_addr);
185
David Howells7d12e782006-10-05 14:55:46 +0100186static void intr_complete (struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188static int init_status (struct usbnet *dev, struct usb_interface *intf)
189{
190 char *buf = NULL;
191 unsigned pipe = 0;
192 unsigned maxp;
193 unsigned period;
194
195 if (!dev->driver_info->status)
196 return 0;
197
198 pipe = usb_rcvintpipe (dev->udev,
199 dev->status->desc.bEndpointAddress
200 & USB_ENDPOINT_NUMBER_MASK);
201 maxp = usb_maxpacket (dev->udev, pipe, 0);
202
203 /* avoid 1 msec chatter: min 8 msec poll rate */
204 period = max ((int) dev->status->desc.bInterval,
205 (dev->udev->speed == USB_SPEED_HIGH) ? 7 : 3);
206
Christoph Lametere94b1762006-12-06 20:33:17 -0800207 buf = kmalloc (maxp, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 if (buf) {
Christoph Lametere94b1762006-12-06 20:33:17 -0800209 dev->interrupt = usb_alloc_urb (0, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 if (!dev->interrupt) {
211 kfree (buf);
212 return -ENOMEM;
213 } else {
214 usb_fill_int_urb(dev->interrupt, dev->udev, pipe,
215 buf, maxp, intr_complete, dev, period);
tom.leiming@gmail.com720f3d72012-04-29 22:51:02 +0000216 dev->interrupt->transfer_flags |= URB_FREE_BUFFER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 dev_dbg(&intf->dev,
218 "status ep%din, %d bytes period %d\n",
219 usb_pipeendpoint(pipe), maxp, period);
220 }
221 }
David Brownell18ab4582007-05-25 12:31:32 -0700222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
David Brownell2e55cc72005-08-31 09:53:10 -0700225/* Passes this packet up the stack, updating its accounting.
226 * Some link protocols batch packets, so their rx_fixup paths
227 * can return clones as well as just modify the original skb.
228 */
229void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 int status;
232
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300233 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
234 skb_queue_tail(&dev->rxq_pause, skb);
235 return;
236 }
237
Hemant Kumar37c35e42011-09-14 23:44:19 -0700238 if (!skb->protocol)
239 skb->protocol = eth_type_trans(skb, dev->net);
240
Herbert Xu79638372009-06-29 16:53:28 +0000241 dev->net->stats.rx_packets++;
242 dev->net->stats.rx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Joe Perchesa475f602010-02-17 10:30:24 +0000244 netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n",
245 skb->len + sizeof (struct ethhdr), skb->protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 memset (skb->cb, 0, sizeof (struct skb_data));
Michael Rieschf9b491e2011-09-29 04:06:26 +0000247
248 if (skb_defer_rx_timestamp(skb))
249 return;
250
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700251 status = netif_rx_ni(skb);
Joe Perchesa475f602010-02-17 10:30:24 +0000252 if (status != NET_RX_SUCCESS)
253 netif_dbg(dev, rx_err, dev->net,
254 "netif_rx status %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
David Brownell2e55cc72005-08-31 09:53:10 -0700256EXPORT_SYMBOL_GPL(usbnet_skb_return);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/*-------------------------------------------------------------------------
260 *
261 * Network Device Driver (peer link to "Host Device", from USB host)
262 *
263 *-------------------------------------------------------------------------*/
264
Stephen Hemminger777baa42009-03-20 19:35:54 +0000265int usbnet_change_mtu (struct net_device *net, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 struct usbnet *dev = netdev_priv(net);
David Brownellf29fc252005-08-31 09:52:31 -0700268 int ll_mtu = new_mtu + net->hard_header_len;
Jamie Paintera99c1942006-07-27 14:17:28 -0400269 int old_hard_mtu = dev->hard_mtu;
270 int old_rx_urb_size = dev->rx_urb_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Jamie Paintera99c1942006-07-27 14:17:28 -0400272 if (new_mtu <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 // no second zero-length packet read wanted after mtu-sized packets
David Brownellf29fc252005-08-31 09:52:31 -0700275 if ((ll_mtu % dev->maxpacket) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return -EDOM;
277 net->mtu = new_mtu;
Jamie Paintera99c1942006-07-27 14:17:28 -0400278
279 dev->hard_mtu = net->mtu + net->hard_header_len;
280 if (dev->rx_urb_size == old_hard_mtu) {
281 dev->rx_urb_size = dev->hard_mtu;
282 if (dev->rx_urb_size > old_rx_urb_size)
283 usbnet_unlink_rx_urbs(dev);
284 }
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return 0;
287}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000288EXPORT_SYMBOL_GPL(usbnet_change_mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800290/* The caller must hold list->lock */
291static void __usbnet_queue_skb(struct sk_buff_head *list,
292 struct sk_buff *newsk, enum skb_state state)
293{
294 struct skb_data *entry = (struct skb_data *) newsk->cb;
295
296 __skb_queue_tail(list, newsk);
297 entry->state = state;
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*-------------------------------------------------------------------------*/
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
303 * completion callbacks. 2.5 should have fixed those bugs...
304 */
305
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800306static enum skb_state defer_bh(struct usbnet *dev, struct sk_buff *skb,
307 struct sk_buff_head *list, enum skb_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 unsigned long flags;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800310 enum skb_state old_state;
311 struct skb_data *entry = (struct skb_data *) skb->cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
David S. Miller8728b832005-08-09 19:25:21 -0700313 spin_lock_irqsave(&list->lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800314 old_state = entry->state;
315 entry->state = state;
David S. Miller8728b832005-08-09 19:25:21 -0700316 __skb_unlink(skb, list);
317 spin_unlock(&list->lock);
318 spin_lock(&dev->done.lock);
319 __skb_queue_tail(&dev->done, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (dev->done.qlen == 1)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700321 queue_work(usbnet_wq, &dev->bh_w);
David S. Miller8728b832005-08-09 19:25:21 -0700322 spin_unlock_irqrestore(&dev->done.lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800323 return old_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326/* some work can't be done in tasklets, so we use keventd
327 *
328 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
329 * but tasklet_schedule() doesn't. hope the failure is rare.
330 */
David Brownell2e55cc72005-08-31 09:53:10 -0700331void usbnet_defer_kevent (struct usbnet *dev, int work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 set_bit (work, &dev->flags);
334 if (!schedule_work (&dev->kevent))
Joe Perches60b86752010-02-17 10:30:23 +0000335 netdev_err(dev->net, "kevent %d may have been dropped\n", work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 else
Joe Perches60b86752010-02-17 10:30:23 +0000337 netdev_dbg(dev->net, "kevent %d scheduled\n", work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
David Brownell2e55cc72005-08-31 09:53:10 -0700339EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341/*-------------------------------------------------------------------------*/
342
David Howells7d12e782006-10-05 14:55:46 +0100343static void rx_complete (struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
David S. Millerdacb3972010-08-10 02:50:55 -0700345static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
347 struct sk_buff *skb;
348 struct skb_data *entry;
349 int retval = 0;
350 unsigned long lockflags;
David Brownell2e55cc72005-08-31 09:53:10 -0700351 size_t size = dev->rx_urb_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Eric Dumazet7bdd4022012-03-14 06:56:25 +0000353 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
354 if (!skb) {
Joe Perchesa475f602010-02-17 10:30:24 +0000355 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
David Brownell2e55cc72005-08-31 09:53:10 -0700356 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 usb_free_urb (urb);
David S. Millerdacb3972010-08-10 02:50:55 -0700358 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Hemant Kumar6d2c7472012-03-06 23:39:29 -0800361 if (dev->net->type != ARPHRD_RAWIP)
362 skb_reserve(skb, NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 entry = (struct skb_data *) skb->cb;
365 entry->urb = urb;
366 entry->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 entry->length = 0;
368
369 usb_fill_bulk_urb (urb, dev->udev, dev->in,
370 skb->data, size, rx_complete, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 spin_lock_irqsave (&dev->rxq.lock, lockflags);
373
Joe Perches8e95a202009-12-03 07:58:21 +0000374 if (netif_running (dev->net) &&
375 netif_device_present (dev->net) &&
Oliver Neukum69ee4722009-12-03 15:31:18 -0800376 !test_bit (EVENT_RX_HALT, &dev->flags) &&
377 !test_bit (EVENT_DEV_ASLEEP, &dev->flags)) {
David Brownell18ab4582007-05-25 12:31:32 -0700378 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 case -EPIPE:
David Brownell2e55cc72005-08-31 09:53:10 -0700380 usbnet_defer_kevent (dev, EVENT_RX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 break;
382 case -ENOMEM:
David Brownell2e55cc72005-08-31 09:53:10 -0700383 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 break;
385 case -ENODEV:
Joe Perchesa475f602010-02-17 10:30:24 +0000386 netif_dbg(dev, ifdown, dev->net, "device gone\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 netif_device_detach (dev->net);
388 break;
David S. Millerdacb3972010-08-10 02:50:55 -0700389 case -EHOSTUNREACH:
390 retval = -ENOLINK;
391 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 default:
Joe Perchesa475f602010-02-17 10:30:24 +0000393 netif_dbg(dev, rx_err, dev->net,
394 "rx submit, %d\n", retval);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700395 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397 case 0:
Hemant Kumar279188a2012-04-03 13:32:48 -0700398 usb_mark_last_busy(dev->udev);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800399 __usbnet_queue_skb(&dev->rxq, skb, rx_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000402 netif_dbg(dev, ifdown, dev->net, "rx: stopped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 retval = -ENOLINK;
404 }
405 spin_unlock_irqrestore (&dev->rxq.lock, lockflags);
406 if (retval) {
407 dev_kfree_skb_any (skb);
408 usb_free_urb (urb);
409 }
David S. Millerdacb3972010-08-10 02:50:55 -0700410 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413
414/*-------------------------------------------------------------------------*/
415
416static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
417{
Joe Perches8e95a202009-12-03 07:58:21 +0000418 if (dev->driver_info->rx_fixup &&
Andrzej Zaborowski7a635ea2011-03-28 12:56:33 +0000419 !dev->driver_info->rx_fixup (dev, skb)) {
420 /* With RX_ASSEMBLE, rx_fixup() must update counters */
421 if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE))
422 dev->net->stats.rx_errors++;
423 goto done;
424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 // else network stack removes extra byte if we forced a short packet
426
Alexey Orishko073285f2010-11-29 23:23:27 +0000427 if (skb->len) {
428 /* all data was already cloned from skb inside the driver */
429 if (dev->driver_info->flags & FLAG_MULTI_PACKET)
430 dev_kfree_skb_any(skb);
431 else
432 usbnet_skb_return(dev, skb);
433 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
Alexey Orishko073285f2010-11-29 23:23:27 +0000435
436 netif_dbg(dev, rx_err, dev->net, "drop\n");
Alexey Orishko073285f2010-11-29 23:23:27 +0000437 dev->net->stats.rx_errors++;
Andrzej Zaborowski7a635ea2011-03-28 12:56:33 +0000438done:
Alexey Orishko073285f2010-11-29 23:23:27 +0000439 skb_queue_tail(&dev->done, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442/*-------------------------------------------------------------------------*/
443
David Howells7d12e782006-10-05 14:55:46 +0100444static void rx_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 struct sk_buff *skb = (struct sk_buff *) urb->context;
447 struct skb_data *entry = (struct skb_data *) skb->cb;
448 struct usbnet *dev = entry->dev;
449 int urb_status = urb->status;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800450 enum skb_state state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 skb_put (skb, urb->actual_length);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800453 state = rx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 entry->urb = NULL;
455
456 switch (urb_status) {
David Brownell18ab4582007-05-25 12:31:32 -0700457 /* success */
458 case 0:
David Brownellf29fc252005-08-31 09:52:31 -0700459 if (skb->len < dev->net->hard_header_len) {
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800460 state = rx_cleanup;
Herbert Xu79638372009-06-29 16:53:28 +0000461 dev->net->stats.rx_errors++;
462 dev->net->stats.rx_length_errors++;
Joe Perchesa475f602010-02-17 10:30:24 +0000463 netif_dbg(dev, rx_err, dev->net,
464 "rx length %d\n", skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466 break;
467
David Brownell18ab4582007-05-25 12:31:32 -0700468 /* stalls need manual reset. this is rare ... except that
469 * when going through USB 2.0 TTs, unplug appears this way.
Jean Delvare3ac49a12009-06-04 16:20:28 +0200470 * we avoid the highspeed version of the ETIMEDOUT/EILSEQ
David Brownell18ab4582007-05-25 12:31:32 -0700471 * storm, recovering as needed.
472 */
473 case -EPIPE:
Herbert Xu79638372009-06-29 16:53:28 +0000474 dev->net->stats.rx_errors++;
David Brownell2e55cc72005-08-31 09:53:10 -0700475 usbnet_defer_kevent (dev, EVENT_RX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 // FALLTHROUGH
477
David Brownell18ab4582007-05-25 12:31:32 -0700478 /* software-driven interface shutdown */
479 case -ECONNRESET: /* async unlink */
480 case -ESHUTDOWN: /* hardware gone */
Joe Perchesa475f602010-02-17 10:30:24 +0000481 netif_dbg(dev, ifdown, dev->net,
482 "rx shutdown, code %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 goto block;
484
David Brownell18ab4582007-05-25 12:31:32 -0700485 /* we get controller i/o faults during khubd disconnect() delays.
486 * throttle down resubmits, to avoid log floods; just temporarily,
487 * so we still recover when the fault isn't a khubd delay.
488 */
489 case -EPROTO:
490 case -ETIME:
491 case -EILSEQ:
Herbert Xu79638372009-06-29 16:53:28 +0000492 dev->net->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (!timer_pending (&dev->delay)) {
494 mod_timer (&dev->delay, jiffies + THROTTLE_JIFFIES);
Joe Perchesa475f602010-02-17 10:30:24 +0000495 netif_dbg(dev, link, dev->net,
496 "rx throttle %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498block:
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800499 state = rx_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 entry->urb = urb;
501 urb = NULL;
502 break;
503
David Brownell18ab4582007-05-25 12:31:32 -0700504 /* data overrun ... flush fifo? */
505 case -EOVERFLOW:
Herbert Xu79638372009-06-29 16:53:28 +0000506 dev->net->stats.rx_over_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 // FALLTHROUGH
David Brownellcb1cebb2007-02-15 18:52:30 -0800508
David Brownell18ab4582007-05-25 12:31:32 -0700509 default:
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800510 state = rx_cleanup;
Herbert Xu79638372009-06-29 16:53:28 +0000511 dev->net->stats.rx_errors++;
Joe Perchesa475f602010-02-17 10:30:24 +0000512 netif_dbg(dev, rx_err, dev->net, "rx status %d\n", urb_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 }
515
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800516 state = defer_bh(dev, skb, &dev->rxq, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 if (urb) {
Joe Perches8e95a202009-12-03 07:58:21 +0000519 if (netif_running (dev->net) &&
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800520 !test_bit (EVENT_RX_HALT, &dev->flags) &&
521 state != unlink_start) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 rx_submit (dev, urb, GFP_ATOMIC);
Oliver Neukum8a783352012-03-03 18:45:07 +0100523 usb_mark_last_busy(dev->udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return;
525 }
526 usb_free_urb (urb);
527 }
Joe Perchesa475f602010-02-17 10:30:24 +0000528 netif_dbg(dev, rx_err, dev->net, "no read resubmitted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
David Howells7d12e782006-10-05 14:55:46 +0100531static void intr_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
533 struct usbnet *dev = urb->context;
534 int status = urb->status;
535
536 switch (status) {
David Brownell18ab4582007-05-25 12:31:32 -0700537 /* success */
538 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 dev->driver_info->status(dev, urb);
540 break;
541
David Brownell18ab4582007-05-25 12:31:32 -0700542 /* software-driven interface shutdown */
543 case -ENOENT: /* urb killed */
544 case -ESHUTDOWN: /* hardware gone */
Joe Perchesa475f602010-02-17 10:30:24 +0000545 netif_dbg(dev, ifdown, dev->net,
546 "intr shutdown, code %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return;
548
David Brownell18ab4582007-05-25 12:31:32 -0700549 /* NOTE: not throttling like RX/TX, since this endpoint
550 * already polls infrequently
551 */
552 default:
Joe Perches60b86752010-02-17 10:30:23 +0000553 netdev_dbg(dev->net, "intr status %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 break;
555 }
556
557 if (!netif_running (dev->net))
558 return;
559
560 memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
561 status = usb_submit_urb (urb, GFP_ATOMIC);
Joe Perchesa475f602010-02-17 10:30:24 +0000562 if (status != 0)
563 netif_err(dev, timer, dev->net,
564 "intr resubmit --> %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
567/*-------------------------------------------------------------------------*/
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300568void usbnet_pause_rx(struct usbnet *dev)
569{
570 set_bit(EVENT_RX_PAUSED, &dev->flags);
571
Joe Perchesa475f602010-02-17 10:30:24 +0000572 netif_dbg(dev, rx_status, dev->net, "paused rx queue enabled\n");
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300573}
574EXPORT_SYMBOL_GPL(usbnet_pause_rx);
575
576void usbnet_resume_rx(struct usbnet *dev)
577{
578 struct sk_buff *skb;
579 int num = 0;
580
581 clear_bit(EVENT_RX_PAUSED, &dev->flags);
582
583 while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
584 usbnet_skb_return(dev, skb);
585 num++;
586 }
587
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700588 queue_work(usbnet_wq, &dev->bh_w);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300589
Joe Perchesa475f602010-02-17 10:30:24 +0000590 netif_dbg(dev, rx_status, dev->net,
591 "paused rx queue disabled, %d skbs requeued\n", num);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300592}
593EXPORT_SYMBOL_GPL(usbnet_resume_rx);
594
595void usbnet_purge_paused_rxq(struct usbnet *dev)
596{
597 skb_queue_purge(&dev->rxq_pause);
598}
599EXPORT_SYMBOL_GPL(usbnet_purge_paused_rxq);
600
601/*-------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603// unlink pending rx/tx; completion handlers do all other cleanup
604
605static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
606{
607 unsigned long flags;
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800608 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 int count = 0;
610
611 spin_lock_irqsave (&q->lock, flags);
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800612 while (!skb_queue_empty(q)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 struct skb_data *entry;
614 struct urb *urb;
615 int retval;
616
Ming Lei5b6e9bc2012-04-26 11:33:46 +0800617 skb_queue_walk(q, skb) {
618 entry = (struct skb_data *) skb->cb;
619 if (entry->state != unlink_start)
620 goto found;
621 }
622 break;
623found:
624 entry->state = unlink_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 urb = entry->urb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
tom.leiming@gmail.com0956a8c2012-03-22 03:22:18 +0000627 /*
628 * Get reference count of the URB to avoid it to be
629 * freed during usb_unlink_urb, which may trigger
630 * use-after-free problem inside usb_unlink_urb since
631 * usb_unlink_urb is always racing with .complete
632 * handler(include defer_bh).
633 */
634 usb_get_urb(urb);
Sebastian Siewior4231d472012-03-07 10:19:28 +0000635 spin_unlock_irqrestore(&q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 // during some PM-driven resume scenarios,
637 // these (async) unlinks complete immediately
638 retval = usb_unlink_urb (urb);
639 if (retval != -EINPROGRESS && retval != 0)
Joe Perches60b86752010-02-17 10:30:23 +0000640 netdev_dbg(dev->net, "unlink urb err, %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 else
642 count++;
tom.leiming@gmail.com0956a8c2012-03-22 03:22:18 +0000643 usb_put_urb(urb);
Sebastian Siewior4231d472012-03-07 10:19:28 +0000644 spin_lock_irqsave(&q->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646 spin_unlock_irqrestore (&q->lock, flags);
647 return count;
648}
649
Jamie Paintera99c1942006-07-27 14:17:28 -0400650// Flush all pending rx urbs
651// minidrivers may need to do this when the MTU changes
652
653void usbnet_unlink_rx_urbs(struct usbnet *dev)
654{
655 if (netif_running(dev->net)) {
656 (void) unlink_urbs (dev, &dev->rxq);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700657 queue_work(usbnet_wq, &dev->bh_w);
Jamie Paintera99c1942006-07-27 14:17:28 -0400658 }
659}
660EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662/*-------------------------------------------------------------------------*/
663
664// precondition: never called in_interrupt
Oliver Neukum69ee4722009-12-03 15:31:18 -0800665static void usbnet_terminate_urbs(struct usbnet *dev)
666{
667 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
668 DECLARE_WAITQUEUE(wait, current);
669 int temp;
670
671 /* ensure there are no more active urbs */
672 add_wait_queue(&unlink_wakeup, &wait);
673 set_current_state(TASK_UNINTERRUPTIBLE);
674 dev->wait = &unlink_wakeup;
675 temp = unlink_urbs(dev, &dev->txq) +
676 unlink_urbs(dev, &dev->rxq);
677
678 /* maybe wait for deletions to finish. */
679 while (!skb_queue_empty(&dev->rxq)
680 && !skb_queue_empty(&dev->txq)
681 && !skb_queue_empty(&dev->done)) {
Kulikov Vasiliy66cc42a2010-07-25 22:25:42 +0000682 schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS));
Oliver Neukum69ee4722009-12-03 15:31:18 -0800683 set_current_state(TASK_UNINTERRUPTIBLE);
Joe Perchesa475f602010-02-17 10:30:24 +0000684 netif_dbg(dev, ifdown, dev->net,
685 "waited for %d urb completions\n", temp);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800686 }
687 set_current_state(TASK_RUNNING);
688 dev->wait = NULL;
689 remove_wait_queue(&unlink_wakeup, &wait);
690}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Stephen Hemminger777baa42009-03-20 19:35:54 +0000692int usbnet_stop (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 struct usbnet *dev = netdev_priv(net);
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300695 struct driver_info *info = dev->driver_info;
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300696 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Ming Lei75bd0cb2011-04-28 22:37:09 +0000698 clear_bit(EVENT_DEV_OPEN, &dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 netif_stop_queue (net);
700
Joe Perchesa475f602010-02-17 10:30:24 +0000701 netif_info(dev, ifdown, dev->net,
Ben Hutchings8ccef432010-06-08 08:20:59 +0000702 "stop stats: rx/tx %lu/%lu, errs %lu/%lu\n",
Joe Perchesa475f602010-02-17 10:30:24 +0000703 net->stats.rx_packets, net->stats.tx_packets,
704 net->stats.rx_errors, net->stats.tx_errors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300706 /* allow minidriver to stop correctly (wireless devices to turn off
707 * radio etc) */
708 if (info->stop) {
709 retval = info->stop(dev);
Joe Perchesa475f602010-02-17 10:30:24 +0000710 if (retval < 0)
711 netif_info(dev, ifdown, dev->net,
712 "stop fail (%d) usbnet usb-%s-%s, %s\n",
713 retval,
714 dev->udev->bus->bus_name, dev->udev->devpath,
715 info->description);
Jussi Kivilinnaa33e9e72009-06-16 17:17:27 +0300716 }
717
Oliver Neukum69ee4722009-12-03 15:31:18 -0800718 if (!(info->flags & FLAG_AVOID_UNLINK_URBS))
719 usbnet_terminate_urbs(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 usb_kill_urb(dev->interrupt);
722
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +0300723 usbnet_purge_paused_rxq(dev);
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /* deferred work (task, timer, softirq) must also stop.
726 * can't flush_scheduled_work() until we drop rtnl (later),
727 * else workers could deadlock; so make workers a NOP.
728 */
729 dev->flags = 0;
730 del_timer_sync (&dev->delay);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700731 cancel_work_sync(&dev->bh_w);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800732 if (info->manage_power)
733 info->manage_power(dev, 0);
734 else
735 usb_autopm_put_interface(dev->intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 return 0;
738}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000739EXPORT_SYMBOL_GPL(usbnet_stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741/*-------------------------------------------------------------------------*/
742
743// posts reads, and enables write queuing
744
745// precondition: never called in_interrupt
746
Stephen Hemminger777baa42009-03-20 19:35:54 +0000747int usbnet_open (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 struct usbnet *dev = netdev_priv(net);
Oliver Neukuma11a6542007-08-03 13:52:19 +0200750 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 struct driver_info *info = dev->driver_info;
752
Oliver Neukuma11a6542007-08-03 13:52:19 +0200753 if ((retval = usb_autopm_get_interface(dev->intf)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000754 netif_info(dev, ifup, dev->net,
755 "resumption fail (%d) usbnet usb-%s-%s, %s\n",
756 retval,
757 dev->udev->bus->bus_name,
758 dev->udev->devpath,
759 info->description);
Oliver Neukuma11a6542007-08-03 13:52:19 +0200760 goto done_nopm;
761 }
762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 // put into "known safe" state
764 if (info->reset && (retval = info->reset (dev)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000765 netif_info(dev, ifup, dev->net,
766 "open reset fail (%d) usbnet usb-%s-%s, %s\n",
767 retval,
768 dev->udev->bus->bus_name,
769 dev->udev->devpath,
770 info->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 goto done;
772 }
773
774 // insist peer be connected
775 if (info->check_connect && (retval = info->check_connect (dev)) < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000776 netif_dbg(dev, ifup, dev->net, "can't open; %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 goto done;
778 }
779
780 /* start any status interrupt transfer */
781 if (dev->interrupt) {
782 retval = usb_submit_urb (dev->interrupt, GFP_KERNEL);
783 if (retval < 0) {
Joe Perchesa475f602010-02-17 10:30:24 +0000784 netif_err(dev, ifup, dev->net,
785 "intr submit %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 goto done;
787 }
788 }
789
Paul Stewart68972ef2011-04-28 05:43:37 +0000790 set_bit(EVENT_DEV_OPEN, &dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 netif_start_queue (net);
Joe Perchesa475f602010-02-17 10:30:24 +0000792 netif_info(dev, ifup, dev->net,
793 "open: enable queueing (rx %d, tx %d) mtu %d %s framing\n",
794 (int)RX_QLEN(dev), (int)TX_QLEN(dev),
795 dev->net->mtu,
796 (dev->driver_info->flags & FLAG_FRAMING_NC) ? "NetChip" :
797 (dev->driver_info->flags & FLAG_FRAMING_GL) ? "GeneSys" :
798 (dev->driver_info->flags & FLAG_FRAMING_Z) ? "Zaurus" :
799 (dev->driver_info->flags & FLAG_FRAMING_RN) ? "RNDIS" :
800 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
801 "simple");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 // delay posting reads until we're fully open
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700804 queue_work(usbnet_wq, &dev->bh_w);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800805 if (info->manage_power) {
806 retval = info->manage_power(dev, 1);
807 if (retval < 0)
808 goto done;
809 usb_autopm_put_interface(dev->intf);
810 }
Oliver Neukuma11a6542007-08-03 13:52:19 +0200811 return retval;
Joe Perchesa475f602010-02-17 10:30:24 +0000812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813done:
Oliver Neukuma11a6542007-08-03 13:52:19 +0200814 usb_autopm_put_interface(dev->intf);
815done_nopm:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return retval;
817}
Stephen Hemminger777baa42009-03-20 19:35:54 +0000818EXPORT_SYMBOL_GPL(usbnet_open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820/*-------------------------------------------------------------------------*/
821
David Brownell2e55cc72005-08-31 09:53:10 -0700822/* ethtool methods; minidrivers may need to add some more, but
823 * they'll probably want to use this base set.
824 */
825
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200826int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd)
827{
828 struct usbnet *dev = netdev_priv(net);
829
830 if (!dev->mii.mdio_read)
831 return -EOPNOTSUPP;
832
833 return mii_ethtool_gset(&dev->mii, cmd);
834}
835EXPORT_SYMBOL_GPL(usbnet_get_settings);
836
837int usbnet_set_settings (struct net_device *net, struct ethtool_cmd *cmd)
838{
839 struct usbnet *dev = netdev_priv(net);
840 int retval;
841
842 if (!dev->mii.mdio_write)
843 return -EOPNOTSUPP;
844
845 retval = mii_ethtool_sset(&dev->mii, cmd);
846
847 /* link speed/duplex might have changed */
848 if (dev->driver_info->link_reset)
849 dev->driver_info->link_reset(dev);
850
851 return retval;
852
853}
854EXPORT_SYMBOL_GPL(usbnet_set_settings);
855
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200856u32 usbnet_get_link (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 struct usbnet *dev = netdev_priv(net);
859
David Brownellf29fc252005-08-31 09:52:31 -0700860 /* If a check_connect is defined, return its result */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 if (dev->driver_info->check_connect)
862 return dev->driver_info->check_connect (dev) == 0;
863
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200864 /* if the device has mii operations, use those */
865 if (dev->mii.mdio_read)
866 return mii_link_ok(&dev->mii);
867
Bjørn Mork05ffb3e2009-03-01 20:45:40 -0800868 /* Otherwise, dtrt for drivers calling netif_carrier_{on,off} */
869 return ethtool_op_get_link(net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200871EXPORT_SYMBOL_GPL(usbnet_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
David Brownell18ee91fa2006-11-02 12:29:12 -0800873int usbnet_nway_reset(struct net_device *net)
874{
875 struct usbnet *dev = netdev_priv(net);
876
877 if (!dev->mii.mdio_write)
878 return -EOPNOTSUPP;
879
880 return mii_nway_restart(&dev->mii);
881}
882EXPORT_SYMBOL_GPL(usbnet_nway_reset);
883
David Brownell18ee91fa2006-11-02 12:29:12 -0800884void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
885{
886 struct usbnet *dev = netdev_priv(net);
887
David Brownell296c0242007-04-17 16:10:10 -0700888 strncpy (info->driver, dev->driver_name, sizeof info->driver);
David Brownell18ee91fa2006-11-02 12:29:12 -0800889 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
890 strncpy (info->fw_version, dev->driver_info->description,
891 sizeof info->fw_version);
892 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
893}
894EXPORT_SYMBOL_GPL(usbnet_get_drvinfo);
895
David Brownell2e55cc72005-08-31 09:53:10 -0700896u32 usbnet_get_msglevel (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
898 struct usbnet *dev = netdev_priv(net);
899
900 return dev->msg_enable;
901}
David Brownell2e55cc72005-08-31 09:53:10 -0700902EXPORT_SYMBOL_GPL(usbnet_get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
David Brownell2e55cc72005-08-31 09:53:10 -0700904void usbnet_set_msglevel (struct net_device *net, u32 level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
906 struct usbnet *dev = netdev_priv(net);
907
908 dev->msg_enable = level;
909}
David Brownell2e55cc72005-08-31 09:53:10 -0700910EXPORT_SYMBOL_GPL(usbnet_set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
David Brownell2e55cc72005-08-31 09:53:10 -0700912/* drivers may override default ethtool_ops in their bind() routine */
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700913static const struct ethtool_ops usbnet_ethtool_ops = {
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200914 .get_settings = usbnet_get_settings,
915 .set_settings = usbnet_set_settings,
David Brownell2e55cc72005-08-31 09:53:10 -0700916 .get_link = usbnet_get_link,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200917 .nway_reset = usbnet_nway_reset,
David Brownell18ee91fa2006-11-02 12:29:12 -0800918 .get_drvinfo = usbnet_get_drvinfo,
David Brownell2e55cc72005-08-31 09:53:10 -0700919 .get_msglevel = usbnet_get_msglevel,
920 .set_msglevel = usbnet_set_msglevel,
921};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923/*-------------------------------------------------------------------------*/
924
925/* work that cannot be done in interrupt context uses keventd.
926 *
927 * NOTE: with 2.5 we could do more of this using completion callbacks,
928 * especially now that control transfers can be queued.
929 */
930static void
David Howellsc4028952006-11-22 14:57:56 +0000931kevent (struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
David Howellsc4028952006-11-22 14:57:56 +0000933 struct usbnet *dev =
934 container_of(work, struct usbnet, kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 int status;
936
937 /* usb_clear_halt() needs a thread context */
938 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
939 unlink_urbs (dev, &dev->txq);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800940 status = usb_autopm_get_interface(dev->intf);
941 if (status < 0)
942 goto fail_pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 status = usb_clear_halt (dev->udev, dev->out);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800944 usb_autopm_put_interface(dev->intf);
Joe Perches8e95a202009-12-03 07:58:21 +0000945 if (status < 0 &&
946 status != -EPIPE &&
947 status != -ESHUTDOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 if (netif_msg_tx_err (dev))
Oliver Neukum69ee4722009-12-03 15:31:18 -0800949fail_pipe:
Joe Perches60b86752010-02-17 10:30:23 +0000950 netdev_err(dev->net, "can't clear tx halt, status %d\n",
951 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 } else {
953 clear_bit (EVENT_TX_HALT, &dev->flags);
David Brownellf29fc252005-08-31 09:52:31 -0700954 if (status != -ESHUTDOWN)
955 netif_wake_queue (dev->net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957 }
958 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
959 unlink_urbs (dev, &dev->rxq);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800960 status = usb_autopm_get_interface(dev->intf);
961 if (status < 0)
962 goto fail_halt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 status = usb_clear_halt (dev->udev, dev->in);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800964 usb_autopm_put_interface(dev->intf);
Joe Perches8e95a202009-12-03 07:58:21 +0000965 if (status < 0 &&
966 status != -EPIPE &&
967 status != -ESHUTDOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (netif_msg_rx_err (dev))
Oliver Neukum69ee4722009-12-03 15:31:18 -0800969fail_halt:
Joe Perches60b86752010-02-17 10:30:23 +0000970 netdev_err(dev->net, "can't clear rx halt, status %d\n",
971 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 } else {
973 clear_bit (EVENT_RX_HALT, &dev->flags);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700974 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976 }
977
978 /* tasklet could resubmit itself forever if memory is tight */
979 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
980 struct urb *urb = NULL;
David S. Millerdacb3972010-08-10 02:50:55 -0700981 int resched = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (netif_running (dev->net))
984 urb = usb_alloc_urb (0, GFP_KERNEL);
985 else
986 clear_bit (EVENT_RX_MEMORY, &dev->flags);
987 if (urb != NULL) {
988 clear_bit (EVENT_RX_MEMORY, &dev->flags);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800989 status = usb_autopm_get_interface(dev->intf);
Jesper Juhlab607072011-02-10 10:58:45 +0000990 if (status < 0) {
991 usb_free_urb(urb);
Oliver Neukum69ee4722009-12-03 15:31:18 -0800992 goto fail_lowmem;
Jesper Juhlab607072011-02-10 10:58:45 +0000993 }
David S. Millerdacb3972010-08-10 02:50:55 -0700994 if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK)
995 resched = 0;
Oliver Neukum69ee4722009-12-03 15:31:18 -0800996 usb_autopm_put_interface(dev->intf);
997fail_lowmem:
David S. Millerdacb3972010-08-10 02:50:55 -0700998 if (resched)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -0700999 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001 }
1002
David Hollis7ea13c92005-04-22 15:07:02 -07001003 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
David Brownellcb1cebb2007-02-15 18:52:30 -08001004 struct driver_info *info = dev->driver_info;
David Hollis7ea13c92005-04-22 15:07:02 -07001005 int retval = 0;
1006
1007 clear_bit (EVENT_LINK_RESET, &dev->flags);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001008 status = usb_autopm_get_interface(dev->intf);
1009 if (status < 0)
1010 goto skip_reset;
David Hollis7ea13c92005-04-22 15:07:02 -07001011 if(info->link_reset && (retval = info->link_reset(dev)) < 0) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001012 usb_autopm_put_interface(dev->intf);
1013skip_reset:
Joe Perches60b86752010-02-17 10:30:23 +00001014 netdev_info(dev->net, "link reset failed (%d) usbnet usb-%s-%s, %s\n",
1015 retval,
1016 dev->udev->bus->bus_name,
1017 dev->udev->devpath,
1018 info->description);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001019 } else {
1020 usb_autopm_put_interface(dev->intf);
David Hollis7ea13c92005-04-22 15:07:02 -07001021 }
1022 }
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (dev->flags)
Joe Perches60b86752010-02-17 10:30:23 +00001025 netdev_dbg(dev->net, "kevent done, flags = 0x%lx\n", dev->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
1028/*-------------------------------------------------------------------------*/
1029
David Howells7d12e782006-10-05 14:55:46 +01001030static void tx_complete (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
1032 struct sk_buff *skb = (struct sk_buff *) urb->context;
1033 struct skb_data *entry = (struct skb_data *) skb->cb;
1034 struct usbnet *dev = entry->dev;
1035
1036 if (urb->status == 0) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001037 if (!(dev->driver_info->flags & FLAG_MULTI_PACKET))
1038 dev->net->stats.tx_packets++;
Herbert Xu79638372009-06-29 16:53:28 +00001039 dev->net->stats.tx_bytes += entry->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 } else {
Herbert Xu79638372009-06-29 16:53:28 +00001041 dev->net->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 switch (urb->status) {
1044 case -EPIPE:
David Brownell2e55cc72005-08-31 09:53:10 -07001045 usbnet_defer_kevent (dev, EVENT_TX_HALT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 break;
1047
1048 /* software-driven interface shutdown */
1049 case -ECONNRESET: // async unlink
1050 case -ESHUTDOWN: // hardware gone
1051 break;
1052
1053 // like rx, tx gets controller i/o faults during khubd delays
1054 // and so it uses the same throttling mechanism.
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -07001055 case -EPROTO:
1056 case -ETIME:
1057 case -EILSEQ:
Oliver Neukum69ee4722009-12-03 15:31:18 -08001058 usb_mark_last_busy(dev->udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 if (!timer_pending (&dev->delay)) {
1060 mod_timer (&dev->delay,
1061 jiffies + THROTTLE_JIFFIES);
Joe Perchesa475f602010-02-17 10:30:24 +00001062 netif_dbg(dev, link, dev->net,
1063 "tx throttle %d\n", urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 netif_stop_queue (dev->net);
1066 break;
1067 default:
Joe Perchesa475f602010-02-17 10:30:24 +00001068 netif_dbg(dev, tx_err, dev->net,
1069 "tx err %d\n", entry->urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 break;
1071 }
1072 }
1073
Oliver Neukum69ee4722009-12-03 15:31:18 -08001074 usb_autopm_put_interface_async(dev->intf);
Ming Lei5b6e9bc2012-04-26 11:33:46 +08001075 (void) defer_bh(dev, skb, &dev->txq, tx_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
1078/*-------------------------------------------------------------------------*/
1079
Stephen Hemminger777baa42009-03-20 19:35:54 +00001080void usbnet_tx_timeout (struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
1082 struct usbnet *dev = netdev_priv(net);
1083
1084 unlink_urbs (dev, &dev->txq);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001085 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 // FIXME: device recovery -- reset?
1088}
Stephen Hemminger777baa42009-03-20 19:35:54 +00001089EXPORT_SYMBOL_GPL(usbnet_tx_timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091/*-------------------------------------------------------------------------*/
1092
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001093netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1094 struct net_device *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
1096 struct usbnet *dev = netdev_priv(net);
1097 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 struct urb *urb = NULL;
1099 struct skb_data *entry;
1100 struct driver_info *info = dev->driver_info;
1101 unsigned long flags;
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001102 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Konstantin Khlebnikov23ba0792011-11-07 05:54:58 +00001104 if (skb)
1105 skb_tx_timestamp(skb);
Michael Rieschf9b491e2011-09-29 04:06:26 +00001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 // some devices want funky USB-level framing, for
1108 // win32 driver (usually) and/or hardware quirks
1109 if (info->tx_fixup) {
1110 skb = info->tx_fixup (dev, skb, GFP_ATOMIC);
1111 if (!skb) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001112 if (netif_msg_tx_err(dev)) {
1113 netif_dbg(dev, tx_err, dev->net, "can't tx_fixup skb\n");
1114 goto drop;
1115 } else {
1116 /* cdc_ncm collected packet; waits for more */
1117 goto not_drop;
1118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 }
1121 length = skb->len;
1122
1123 if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001124 netif_dbg(dev, tx_err, dev->net, "no urb\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 goto drop;
1126 }
1127
1128 entry = (struct skb_data *) skb->cb;
1129 entry->urb = urb;
1130 entry->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 entry->length = length;
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 usb_fill_bulk_urb (urb, dev->udev, dev->out,
1134 skb->data, skb->len, tx_complete, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 /* don't assume the hardware handles USB_ZERO_PACKET
1137 * NOTE: strictly conforming cdc-ether devices should expect
1138 * the ZLP here, but ignore the one-byte packet.
Alexey Orishko073285f2010-11-29 23:23:27 +00001139 * NOTE2: CDC NCM specification is different from CDC ECM when
1140 * handling ZLP/short packets, so cdc_ncm driver will make short
1141 * packet itself if needed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 */
Elina Pashevab4d562e2010-04-06 14:23:07 +00001143 if (length % dev->maxpacket == 0) {
1144 if (!(info->flags & FLAG_SEND_ZLP)) {
Alexey Orishko073285f2010-11-29 23:23:27 +00001145 if (!(info->flags & FLAG_MULTI_PACKET)) {
1146 urb->transfer_buffer_length++;
1147 if (skb_tailroom(skb)) {
1148 skb->data[skb->len] = 0;
1149 __skb_put(skb, 1);
1150 }
Elina Pashevab4d562e2010-04-06 14:23:07 +00001151 }
1152 } else
1153 urb->transfer_flags |= URB_ZERO_PACKET;
Peter Korsgaard3e323f32007-06-27 08:48:15 +02001154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Oliver Neukum69ee4722009-12-03 15:31:18 -08001156 spin_lock_irqsave(&dev->txq.lock, flags);
1157 retval = usb_autopm_get_interface_async(dev->intf);
1158 if (retval < 0) {
1159 spin_unlock_irqrestore(&dev->txq.lock, flags);
1160 goto drop;
1161 }
1162
1163#ifdef CONFIG_PM
1164 /* if this triggers the device is still a sleep */
1165 if (test_bit(EVENT_DEV_ASLEEP, &dev->flags)) {
1166 /* transmission will be done in resume */
1167 usb_anchor_urb(urb, &dev->deferred);
1168 /* no use to process more packets */
1169 netif_stop_queue(net);
1170 spin_unlock_irqrestore(&dev->txq.lock, flags);
Joe Perches60b86752010-02-17 10:30:23 +00001171 netdev_dbg(dev->net, "Delaying transmission for resumption\n");
Oliver Neukum69ee4722009-12-03 15:31:18 -08001172 goto deferred;
1173 }
1174#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
1177 case -EPIPE:
1178 netif_stop_queue (net);
David Brownell2e55cc72005-08-31 09:53:10 -07001179 usbnet_defer_kevent (dev, EVENT_TX_HALT);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001180 usb_autopm_put_interface_async(dev->intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 break;
1182 default:
Oliver Neukum69ee4722009-12-03 15:31:18 -08001183 usb_autopm_put_interface_async(dev->intf);
Joe Perchesa475f602010-02-17 10:30:24 +00001184 netif_dbg(dev, tx_err, dev->net,
1185 "tx: submit urb err %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 break;
1187 case 0:
1188 net->trans_start = jiffies;
Ming Lei5b6e9bc2012-04-26 11:33:46 +08001189 __usbnet_queue_skb(&dev->txq, skb, tx_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 if (dev->txq.qlen >= TX_QLEN (dev))
1191 netif_stop_queue (net);
1192 }
1193 spin_unlock_irqrestore (&dev->txq.lock, flags);
1194
1195 if (retval) {
Joe Perchesa475f602010-02-17 10:30:24 +00001196 netif_dbg(dev, tx_err, dev->net, "drop, code %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197drop:
Herbert Xu79638372009-06-29 16:53:28 +00001198 dev->net->stats.tx_dropped++;
Alexey Orishko073285f2010-11-29 23:23:27 +00001199not_drop:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (skb)
1201 dev_kfree_skb_any (skb);
1202 usb_free_urb (urb);
Joe Perchesa475f602010-02-17 10:30:24 +00001203 } else
1204 netif_dbg(dev, tx_queued, dev->net,
1205 "> tx, len %d, type 0x%x\n", length, skb->protocol);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001206#ifdef CONFIG_PM
1207deferred:
1208#endif
Stephen Hemminger25a79c42009-08-31 19:50:45 +00001209 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
Stephen Hemminger777baa42009-03-20 19:35:54 +00001211EXPORT_SYMBOL_GPL(usbnet_start_xmit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213/*-------------------------------------------------------------------------*/
1214
1215// tasklet (work deferred from completions, in_irq) or timer
1216
1217static void usbnet_bh (unsigned long param)
1218{
1219 struct usbnet *dev = (struct usbnet *) param;
1220 struct sk_buff *skb;
1221 struct skb_data *entry;
1222
1223 while ((skb = skb_dequeue (&dev->done))) {
1224 entry = (struct skb_data *) skb->cb;
1225 switch (entry->state) {
David Brownell18ab4582007-05-25 12:31:32 -07001226 case rx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 entry->state = rx_cleanup;
1228 rx_process (dev, skb);
1229 continue;
David Brownell18ab4582007-05-25 12:31:32 -07001230 case tx_done:
1231 case rx_cleanup:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 usb_free_urb (entry->urb);
1233 dev_kfree_skb (skb);
1234 continue;
David Brownell18ab4582007-05-25 12:31:32 -07001235 default:
Joe Perches60b86752010-02-17 10:30:23 +00001236 netdev_dbg(dev->net, "bogus skb state %d\n", entry->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
1238 }
1239
1240 // waiting for all pending urbs to complete?
1241 if (dev->wait) {
1242 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
1243 wake_up (dev->wait);
1244 }
1245
1246 // or are we maybe short a few urbs?
Joe Perches8e95a202009-12-03 07:58:21 +00001247 } else if (netif_running (dev->net) &&
1248 netif_device_present (dev->net) &&
1249 !timer_pending (&dev->delay) &&
1250 !test_bit (EVENT_RX_HALT, &dev->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 int temp = dev->rxq.qlen;
1252 int qlen = RX_QLEN (dev);
1253
1254 if (temp < qlen) {
1255 struct urb *urb;
1256 int i;
1257
1258 // don't refill the queue all at once
1259 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
1260 urb = usb_alloc_urb (0, GFP_ATOMIC);
David S. Millerdacb3972010-08-10 02:50:55 -07001261 if (urb != NULL) {
1262 if (rx_submit (dev, urb, GFP_ATOMIC) ==
1263 -ENOLINK)
1264 return;
1265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
Joe Perchesa475f602010-02-17 10:30:24 +00001267 if (temp != dev->rxq.qlen)
1268 netif_dbg(dev, link, dev->net,
1269 "rxqlen %d --> %d\n",
1270 temp, dev->rxq.qlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if (dev->rxq.qlen < qlen)
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001272 queue_work(usbnet_wq, &dev->bh_w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274 if (dev->txq.qlen < TX_QLEN (dev))
1275 netif_wake_queue (dev->net);
1276 }
1277}
1278
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001279static void usbnet_bh_w(struct work_struct *work)
1280{
1281 struct usbnet *dev =
1282 container_of(work, struct usbnet, bh_w);
1283 unsigned long param = (unsigned long)dev;
1284
1285 usbnet_bh(param);
1286}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288/*-------------------------------------------------------------------------
1289 *
1290 * USB Device Driver support
1291 *
1292 *-------------------------------------------------------------------------*/
David Brownellcb1cebb2007-02-15 18:52:30 -08001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294// precondition: never called in_interrupt
1295
David Brownell38bde1d2005-08-31 09:52:45 -07001296void usbnet_disconnect (struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
1298 struct usbnet *dev;
1299 struct usb_device *xdev;
1300 struct net_device *net;
1301
1302 dev = usb_get_intfdata(intf);
1303 usb_set_intfdata(intf, NULL);
1304 if (!dev)
1305 return;
1306
1307 xdev = interface_to_usbdev (intf);
1308
Joe Perchesa475f602010-02-17 10:30:24 +00001309 netif_info(dev, probe, dev->net, "unregister '%s' usb-%s-%s, %s\n",
1310 intf->dev.driver->name,
1311 xdev->bus->bus_name, xdev->devpath,
1312 dev->driver_info->description);
David Brownellcb1cebb2007-02-15 18:52:30 -08001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 net = dev->net;
1315 unregister_netdev (net);
1316
Tejun Heo23f333a2010-12-12 16:45:14 +01001317 cancel_work_sync(&dev->kevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 if (dev->driver_info->unbind)
1320 dev->driver_info->unbind (dev, intf);
1321
Paul Stewart68972ef2011-04-28 05:43:37 +00001322 usb_kill_urb(dev->interrupt);
1323 usb_free_urb(dev->interrupt);
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 free_netdev(net);
1326 usb_put_dev (xdev);
1327}
David Brownell38bde1d2005-08-31 09:52:45 -07001328EXPORT_SYMBOL_GPL(usbnet_disconnect);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Stephen Hemminger777baa42009-03-20 19:35:54 +00001330static const struct net_device_ops usbnet_netdev_ops = {
1331 .ndo_open = usbnet_open,
1332 .ndo_stop = usbnet_stop,
1333 .ndo_start_xmit = usbnet_start_xmit,
1334 .ndo_tx_timeout = usbnet_tx_timeout,
1335 .ndo_change_mtu = usbnet_change_mtu,
1336 .ndo_set_mac_address = eth_mac_addr,
1337 .ndo_validate_addr = eth_validate_addr,
1338};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340/*-------------------------------------------------------------------------*/
1341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342// precondition: never called in_interrupt
1343
Marcel Holtmann225794f2009-10-02 05:15:26 +00001344static struct device_type wlan_type = {
1345 .name = "wlan",
1346};
1347
1348static struct device_type wwan_type = {
1349 .name = "wwan",
1350};
1351
David Brownell38bde1d2005-08-31 09:52:45 -07001352int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1354{
1355 struct usbnet *dev;
David Brownellcb1cebb2007-02-15 18:52:30 -08001356 struct net_device *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 struct usb_host_interface *interface;
1358 struct driver_info *info;
1359 struct usb_device *xdev;
1360 int status;
David Brownell296c0242007-04-17 16:10:10 -07001361 const char *name;
Ming Leib0786b42010-11-01 07:11:54 -07001362 struct usb_driver *driver = to_usb_driver(udev->dev.driver);
1363
1364 /* usbnet already took usb runtime pm, so have to enable the feature
1365 * for usb interface, otherwise usb_autopm_get_interface may return
1366 * failure if USB_SUSPEND(RUNTIME_PM) is enabled.
1367 */
1368 if (!driver->supports_autosuspend) {
1369 driver->supports_autosuspend = 1;
1370 pm_runtime_enable(&udev->dev);
1371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
David Brownell296c0242007-04-17 16:10:10 -07001373 name = udev->dev.driver->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 info = (struct driver_info *) prod->driver_info;
1375 if (!info) {
David Brownell296c0242007-04-17 16:10:10 -07001376 dev_dbg (&udev->dev, "blacklisted by %s\n", name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 return -ENODEV;
1378 }
1379 xdev = interface_to_usbdev (udev);
1380 interface = udev->cur_altsetting;
1381
1382 usb_get_dev (xdev);
1383
1384 status = -ENOMEM;
1385
1386 // set up our own records
1387 net = alloc_etherdev(sizeof(*dev));
Joe Perches41de8d42012-01-29 13:47:52 +00001388 if (!net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Ben Hutchings0dacca72010-07-02 21:49:02 -07001391 /* netdev_printk() needs this so do it as early as possible */
1392 SET_NETDEV_DEV(net, &udev->dev);
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 dev = netdev_priv(net);
1395 dev->udev = xdev;
Oliver Neukuma11a6542007-08-03 13:52:19 +02001396 dev->intf = udev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 dev->driver_info = info;
David Brownell296c0242007-04-17 16:10:10 -07001398 dev->driver_name = name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
1400 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1401 skb_queue_head_init (&dev->rxq);
1402 skb_queue_head_init (&dev->txq);
1403 skb_queue_head_init (&dev->done);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001404 skb_queue_head_init(&dev->rxq_pause);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001405 INIT_WORK(&dev->bh_w, usbnet_bh_w);
David Howellsc4028952006-11-22 14:57:56 +00001406 INIT_WORK (&dev->kevent, kevent);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001407 init_usb_anchor(&dev->deferred);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 dev->delay.function = usbnet_bh;
1409 dev->delay.data = (unsigned long) dev;
1410 init_timer (&dev->delay);
Arnd Bergmanna9fc6332006-10-09 00:08:02 +02001411 mutex_init (&dev->phy_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 dev->net = net;
1414 strcpy (net->name, "usb%d");
1415 memcpy (net->dev_addr, node_id, sizeof node_id);
1416
David Brownell2e55cc72005-08-31 09:53:10 -07001417 /* rx and tx sides can use different message sizes;
1418 * bind() should set rx_urb_size in that case.
1419 */
1420 dev->hard_mtu = net->mtu + net->hard_header_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421#if 0
1422// dma_supported() is deeply broken on almost all architectures
1423 // possible with some EHCI controllers
Yang Hongyang6a355282009-04-06 19:01:13 -07001424 if (dma_supported (&udev->dev, DMA_BIT_MASK(64)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 net->features |= NETIF_F_HIGHDMA;
1426#endif
1427
Stephen Hemminger777baa42009-03-20 19:35:54 +00001428 net->netdev_ops = &usbnet_netdev_ops;
Stephen Hemminger777baa42009-03-20 19:35:54 +00001429 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 net->ethtool_ops = &usbnet_ethtool_ops;
1431
1432 // allow device-specific bind/init procedures
1433 // NOTE net->name still not usable ...
1434 if (info->bind) {
1435 status = info->bind (dev, udev);
David Brownellcb1cebb2007-02-15 18:52:30 -08001436 if (status < 0)
1437 goto out1;
1438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 // heuristic: "usb%d" for links we know are two-host,
1440 // else "eth%d" when there's reasonable doubt. userspace
1441 // can rename the link if it knows better.
Joe Perches8e95a202009-12-03 07:58:21 +00001442 if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&
Arnd Bergmannc2613442011-04-01 20:12:02 -07001443 ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||
1444 (net->dev_addr [0] & 0x02) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 strcpy (net->name, "eth%d");
Jussi Kivilinna6e3bbcc2008-01-26 00:51:06 +02001446 /* WLAN devices should always be named "wlan%d" */
1447 if ((dev->driver_info->flags & FLAG_WLAN) != 0)
1448 strcpy(net->name, "wlan%d");
Marcel Holtmanne1e499e2009-10-02 05:15:25 +00001449 /* WWAN devices should always be named "wwan%d" */
1450 if ((dev->driver_info->flags & FLAG_WWAN) != 0)
1451 strcpy(net->name, "wwan%d");
David Brownellf29fc252005-08-31 09:52:31 -07001452
1453 /* maybe the remote can't receive an Ethernet MTU */
1454 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
1455 net->mtu = dev->hard_mtu - net->hard_header_len;
David Brownell2e55cc72005-08-31 09:53:10 -07001456 } else if (!info->in || !info->out)
1457 status = usbnet_get_endpoints (dev, udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 else {
1459 dev->in = usb_rcvbulkpipe (xdev, info->in);
1460 dev->out = usb_sndbulkpipe (xdev, info->out);
1461 if (!(info->flags & FLAG_NO_SETINT))
1462 status = usb_set_interface (xdev,
1463 interface->desc.bInterfaceNumber,
1464 interface->desc.bAlternateSetting);
1465 else
1466 status = 0;
1467
1468 }
Peter Korsgaard9514bfe2007-07-03 00:46:42 +02001469 if (status >= 0 && dev->status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 status = init_status (dev, udev);
1471 if (status < 0)
David Brownellcb1cebb2007-02-15 18:52:30 -08001472 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
David Brownell2e55cc72005-08-31 09:53:10 -07001474 if (!dev->rx_urb_size)
1475 dev->rx_urb_size = dev->hard_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
David Brownellcb1cebb2007-02-15 18:52:30 -08001477
Marcel Holtmann225794f2009-10-02 05:15:26 +00001478 if ((dev->driver_info->flags & FLAG_WLAN) != 0)
1479 SET_NETDEV_DEVTYPE(net, &wlan_type);
1480 if ((dev->driver_info->flags & FLAG_WWAN) != 0)
1481 SET_NETDEV_DEVTYPE(net, &wwan_type);
1482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 status = register_netdev (net);
1484 if (status)
tom.leiming@gmail.coma4723842012-04-29 22:51:03 +00001485 goto out4;
Joe Perchesa475f602010-02-17 10:30:24 +00001486 netif_info(dev, probe, dev->net,
1487 "register '%s' at usb-%s-%s, %s, %pM\n",
1488 udev->dev.driver->name,
1489 xdev->bus->bus_name, xdev->devpath,
1490 dev->driver_info->description,
1491 net->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 // ok, it's ready to go.
1494 usb_set_intfdata (udev, dev);
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 netif_device_attach (net);
1497
Ben Hutchings37e82732009-11-04 15:29:52 +00001498 if (dev->driver_info->flags & FLAG_LINK_INTR)
1499 netif_carrier_off(net);
1500
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 return 0;
1502
tom.leiming@gmail.coma4723842012-04-29 22:51:03 +00001503out4:
1504 usb_free_urb(dev->interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505out3:
1506 if (info->unbind)
1507 info->unbind (dev, udev);
1508out1:
1509 free_netdev(net);
1510out:
1511 usb_put_dev(xdev);
1512 return status;
1513}
David Brownell38bde1d2005-08-31 09:52:45 -07001514EXPORT_SYMBOL_GPL(usbnet_probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516/*-------------------------------------------------------------------------*/
1517
Oliver Neukum36433122007-04-30 01:37:44 -07001518/*
1519 * suspend the whole driver as soon as the first interface is suspended
1520 * resume only when the last interface is resumed
David Brownell38bde1d2005-08-31 09:52:45 -07001521 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
David Brownell38bde1d2005-08-31 09:52:45 -07001523int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
1525 struct usbnet *dev = usb_get_intfdata(intf);
David Brownellcb1cebb2007-02-15 18:52:30 -08001526
Oliver Neukum36433122007-04-30 01:37:44 -07001527 if (!dev->suspend_count++) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001528 spin_lock_irq(&dev->txq.lock);
1529 /* don't autosuspend while transmitting */
Alan Stern5b1b0b82011-08-19 23:49:48 +02001530 if (dev->txq.qlen && PMSG_IS_AUTO(message)) {
Oliver Neukum69ee4722009-12-03 15:31:18 -08001531 spin_unlock_irq(&dev->txq.lock);
1532 return -EBUSY;
1533 } else {
1534 set_bit(EVENT_DEV_ASLEEP, &dev->flags);
1535 spin_unlock_irq(&dev->txq.lock);
1536 }
Oliver Neukuma11a6542007-08-03 13:52:19 +02001537 /*
1538 * accelerate emptying of the rx and queues, to avoid
Oliver Neukum36433122007-04-30 01:37:44 -07001539 * having everything error out.
1540 */
1541 netif_device_detach (dev->net);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001542 usbnet_terminate_urbs(dev);
1543 usb_kill_urb(dev->interrupt);
1544
Oliver Neukuma11a6542007-08-03 13:52:19 +02001545 /*
1546 * reattach so runtime management can use and
1547 * wake the device
1548 */
1549 netif_device_attach (dev->net);
Oliver Neukum36433122007-04-30 01:37:44 -07001550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return 0;
1552}
David Brownell38bde1d2005-08-31 09:52:45 -07001553EXPORT_SYMBOL_GPL(usbnet_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
David Brownell38bde1d2005-08-31 09:52:45 -07001555int usbnet_resume (struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
1557 struct usbnet *dev = usb_get_intfdata(intf);
Oliver Neukum69ee4722009-12-03 15:31:18 -08001558 struct sk_buff *skb;
1559 struct urb *res;
1560 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Oliver Neukum69ee4722009-12-03 15:31:18 -08001562 if (!--dev->suspend_count) {
Paul Stewart68972ef2011-04-28 05:43:37 +00001563 /* resume interrupt URBs */
1564 if (dev->interrupt && test_bit(EVENT_DEV_OPEN, &dev->flags))
1565 usb_submit_urb(dev->interrupt, GFP_NOIO);
1566
Oliver Neukum69ee4722009-12-03 15:31:18 -08001567 spin_lock_irq(&dev->txq.lock);
1568 while ((res = usb_get_from_anchor(&dev->deferred))) {
1569
Oliver Neukum69ee4722009-12-03 15:31:18 -08001570 skb = (struct sk_buff *)res->context;
1571 retval = usb_submit_urb(res, GFP_ATOMIC);
1572 if (retval < 0) {
1573 dev_kfree_skb_any(skb);
1574 usb_free_urb(res);
1575 usb_autopm_put_interface_async(dev->intf);
1576 } else {
1577 dev->net->trans_start = jiffies;
1578 __skb_queue_tail(&dev->txq, skb);
1579 }
1580 }
1581
1582 smp_mb();
1583 clear_bit(EVENT_DEV_ASLEEP, &dev->flags);
1584 spin_unlock_irq(&dev->txq.lock);
Ming Lei75bd0cb2011-04-28 22:37:09 +00001585
1586 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
1587 if (!(dev->txq.qlen >= TX_QLEN(dev)))
Alexey Orishko1aa9bc52012-03-14 04:00:24 +00001588 netif_tx_wake_all_queues(dev->net);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001589 queue_work(usbnet_wq, &dev->bh_w);
Ming Lei75bd0cb2011-04-28 22:37:09 +00001590 }
Oliver Neukum69ee4722009-12-03 15:31:18 -08001591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return 0;
1593}
David Brownell38bde1d2005-08-31 09:52:45 -07001594EXPORT_SYMBOL_GPL(usbnet_resume);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
1597/*-------------------------------------------------------------------------*/
1598
David Brownellf29fc252005-08-31 09:52:31 -07001599static int __init usbnet_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Thiago Farinac582a952011-04-17 17:49:21 -07001601 /* Compiler should optimize this out. */
1602 BUILD_BUG_ON(
1603 FIELD_SIZEOF(struct sk_buff, cb) < sizeof(struct skb_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605 random_ether_addr(node_id);
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001606
1607 usbnet_wq = create_singlethread_workqueue("usbnet");
1608 if (!usbnet_wq) {
1609 pr_err("%s: Unable to create workqueue:usbnet\n", __func__);
1610 return -ENOMEM;
1611 }
1612
David Brownellcb1cebb2007-02-15 18:52:30 -08001613 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
David Brownellf29fc252005-08-31 09:52:31 -07001615module_init(usbnet_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
David Brownellf29fc252005-08-31 09:52:31 -07001617static void __exit usbnet_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
Hemant Kumar1e8ddb52012-07-02 13:39:22 -07001619 destroy_workqueue(usbnet_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
David Brownellf29fc252005-08-31 09:52:31 -07001621module_exit(usbnet_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
David Brownellf29fc252005-08-31 09:52:31 -07001623MODULE_AUTHOR("David Brownell");
David Brownell090ffa92005-08-31 09:54:50 -07001624MODULE_DESCRIPTION("USB network driver framework");
David Brownellf29fc252005-08-31 09:52:31 -07001625MODULE_LICENSE("GPL");