blob: fd103940a3ee474304122c6f96152ea3e16b3b84 [file] [log] [blame]
David Brownell2b3d9422008-06-19 18:19:28 -07001/*
2 * u_ether.c -- Ethernet-over-USB link layer utilities for Gadget stack
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
David Brownell2b3d9422008-06-19 18:19:28 -070012 */
13
14/* #define VERBOSE_DEBUG */
15
16#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/gfp.h>
David Brownell2b3d9422008-06-19 18:19:28 -070018#include <linux/device.h>
19#include <linux/ctype.h>
20#include <linux/etherdevice.h>
21#include <linux/ethtool.h>
22
23#include "u_ether.h"
24
25
26/*
27 * This component encapsulates the Ethernet link glue needed to provide
28 * one (!) network link through the USB gadget stack, normally "usb0".
29 *
30 * The control and data models are handled by the function driver which
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050031 * connects to this code; such as CDC Ethernet (ECM or EEM),
32 * "CDC Subset", or RNDIS. That includes all descriptor and endpoint
33 * management.
David Brownell2b3d9422008-06-19 18:19:28 -070034 *
35 * Link level addressing is handled by this component using module
36 * parameters; if no such parameters are provided, random link level
37 * addresses are used. Each end of the link uses one address. The
38 * host end address is exported in various ways, and is often recorded
39 * in configuration databases.
40 *
41 * The driver which assembles each configuration using such a link is
42 * responsible for ensuring that each configuration includes at most one
43 * instance of is network link. (The network layer provides ways for
44 * this single "physical" link to be used by multiple virtual links.)
45 */
46
David Brownell8a1ce2c2008-08-18 17:43:56 -070047#define UETH__VERSION "29-May-2008"
David Brownell2b3d9422008-06-19 18:19:28 -070048
Hemant Kumar08eb78e2012-07-30 20:38:47 -070049static struct workqueue_struct *uether_wq;
50
David Brownell2b3d9422008-06-19 18:19:28 -070051struct eth_dev {
52 /* lock is held while accessing port_usb
53 * or updating its backlink port_usb->ioport
54 */
55 spinlock_t lock;
56 struct gether *port_usb;
57
58 struct net_device *net;
59 struct usb_gadget *gadget;
60
61 spinlock_t req_lock; /* guard {rx,tx}_reqs */
62 struct list_head tx_reqs, rx_reqs;
Vijayavardhan Vennapusa20b627e2012-03-06 14:26:11 +053063 unsigned tx_qlen;
Mayank Rana5b165cb2012-05-25 19:52:45 +053064/* Minimum number of TX USB request queued to UDC */
65#define TX_REQ_THRESHOLD 5
66 int no_tx_req_used;
67 int tx_skb_hold_count;
68 u32 tx_req_bufsize;
David Brownell2b3d9422008-06-19 18:19:28 -070069
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050070 struct sk_buff_head rx_frames;
71
David Brownell2b3d9422008-06-19 18:19:28 -070072 unsigned header_len;
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050073 struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb);
74 int (*unwrap)(struct gether *,
75 struct sk_buff *skb,
76 struct sk_buff_head *list);
David Brownell2b3d9422008-06-19 18:19:28 -070077
78 struct work_struct work;
Hemant Kumar08eb78e2012-07-30 20:38:47 -070079 struct work_struct rx_work;
David Brownell2b3d9422008-06-19 18:19:28 -070080
81 unsigned long todo;
82#define WORK_RX_MEMORY 0
83
84 bool zlp;
85 u8 host_mac[ETH_ALEN];
86};
87
88/*-------------------------------------------------------------------------*/
89
90#define RX_EXTRA 20 /* bytes guarding against rx overflows */
91
92#define DEFAULT_QLEN 2 /* double buffering by default */
93
David Brownell2b3d9422008-06-19 18:19:28 -070094#ifdef CONFIG_USB_GADGET_DUALSPEED
95
Mayank Rana5b165cb2012-05-25 19:52:45 +053096static unsigned qmult = 10;
David Brownell2b3d9422008-06-19 18:19:28 -070097module_param(qmult, uint, S_IRUGO|S_IWUSR);
Paul Zimmerman04617db2011-06-27 14:13:18 -070098MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
David Brownell2b3d9422008-06-19 18:19:28 -070099
100#else /* full speed (low speed doesn't do bulk) */
101#define qmult 1
102#endif
103
Paul Zimmerman04617db2011-06-27 14:13:18 -0700104/* for dual-speed hardware, use deeper queues at high/super speed */
David Brownell2b3d9422008-06-19 18:19:28 -0700105static inline int qlen(struct usb_gadget *gadget)
106{
Paul Zimmerman04617db2011-06-27 14:13:18 -0700107 if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH ||
108 gadget->speed == USB_SPEED_SUPER))
David Brownell2b3d9422008-06-19 18:19:28 -0700109 return qmult * DEFAULT_QLEN;
110 else
111 return DEFAULT_QLEN;
112}
113
114/*-------------------------------------------------------------------------*/
115
116/* REVISIT there must be a better way than having two sets
117 * of debug calls ...
118 */
119
120#undef DBG
121#undef VDBG
122#undef ERROR
David Brownell2b3d9422008-06-19 18:19:28 -0700123#undef INFO
124
125#define xprintk(d, level, fmt, args...) \
126 printk(level "%s: " fmt , (d)->net->name , ## args)
127
128#ifdef DEBUG
129#undef DEBUG
130#define DBG(dev, fmt, args...) \
131 xprintk(dev , KERN_DEBUG , fmt , ## args)
132#else
133#define DBG(dev, fmt, args...) \
134 do { } while (0)
135#endif /* DEBUG */
136
137#ifdef VERBOSE_DEBUG
138#define VDBG DBG
139#else
140#define VDBG(dev, fmt, args...) \
141 do { } while (0)
142#endif /* DEBUG */
143
144#define ERROR(dev, fmt, args...) \
145 xprintk(dev , KERN_ERR , fmt , ## args)
David Brownell2b3d9422008-06-19 18:19:28 -0700146#define INFO(dev, fmt, args...) \
147 xprintk(dev , KERN_INFO , fmt , ## args)
148
149/*-------------------------------------------------------------------------*/
150
151/* NETWORK DRIVER HOOKUP (to the layer above this driver) */
152
Stephen Hemmingerccad6372008-11-19 22:42:31 -0800153static int ueth_change_mtu(struct net_device *net, int new_mtu)
David Brownell2b3d9422008-06-19 18:19:28 -0700154{
155 struct eth_dev *dev = netdev_priv(net);
156 unsigned long flags;
157 int status = 0;
158
159 /* don't change MTU on "live" link (peer won't know) */
160 spin_lock_irqsave(&dev->lock, flags);
161 if (dev->port_usb)
162 status = -EBUSY;
163 else if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN)
164 status = -ERANGE;
165 else
166 net->mtu = new_mtu;
167 spin_unlock_irqrestore(&dev->lock, flags);
168
169 return status;
170}
171
172static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
173{
174 struct eth_dev *dev = netdev_priv(net);
175
176 strlcpy(p->driver, "g_ether", sizeof p->driver);
David Brownell8a1ce2c2008-08-18 17:43:56 -0700177 strlcpy(p->version, UETH__VERSION, sizeof p->version);
David Brownell2b3d9422008-06-19 18:19:28 -0700178 strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version);
179 strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info);
180}
181
David Brownell2b3d9422008-06-19 18:19:28 -0700182/* REVISIT can also support:
183 * - WOL (by tracking suspends and issuing remote wakeup)
184 * - msglevel (implies updated messaging)
185 * - ... probably more ethtool ops
186 */
187
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700188static const struct ethtool_ops ops = {
David Brownell2b3d9422008-06-19 18:19:28 -0700189 .get_drvinfo = eth_get_drvinfo,
Jonathan McDowell237e75b2009-03-26 00:45:27 -0700190 .get_link = ethtool_op_get_link,
David Brownell2b3d9422008-06-19 18:19:28 -0700191};
192
193static void defer_kevent(struct eth_dev *dev, int flag)
194{
195 if (test_and_set_bit(flag, &dev->todo))
196 return;
197 if (!schedule_work(&dev->work))
198 ERROR(dev, "kevent %d may have been dropped\n", flag);
199 else
200 DBG(dev, "kevent %d scheduled\n", flag);
201}
202
203static void rx_complete(struct usb_ep *ep, struct usb_request *req);
204
205static int
206rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
207{
208 struct sk_buff *skb;
209 int retval = -ENOMEM;
210 size_t size = 0;
211 struct usb_ep *out;
212 unsigned long flags;
213
214 spin_lock_irqsave(&dev->lock, flags);
215 if (dev->port_usb)
216 out = dev->port_usb->out_ep;
217 else
218 out = NULL;
219 spin_unlock_irqrestore(&dev->lock, flags);
220
221 if (!out)
222 return -ENOTCONN;
223
224
225 /* Padding up to RX_EXTRA handles minor disagreements with host.
226 * Normally we use the USB "terminate on short read" convention;
227 * so allow up to (N*maxpacket), since that memory is normally
228 * already allocated. Some hardware doesn't deal well with short
229 * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
230 * byte off the end (to force hardware errors on overflow).
231 *
232 * RNDIS uses internal framing, and explicitly allows senders to
233 * pad to end-of-packet. That's potentially nice for speed, but
234 * means receivers can't recover lost synch on their own (because
235 * new packets don't only start after a short RX).
236 */
237 size += sizeof(struct ethhdr) + dev->net->mtu + RX_EXTRA;
238 size += dev->port_usb->header_len;
239 size += out->maxpacket - 1;
240 size -= size % out->maxpacket;
241
Yauheni Kaliuta5c1168d2010-12-08 13:12:04 +0200242 if (dev->port_usb->is_fixed)
Stephen Hemminger45d1b7a2011-03-01 22:40:57 -0800243 size = max_t(size_t, size, dev->port_usb->fixed_out_len);
Yauheni Kaliuta5c1168d2010-12-08 13:12:04 +0200244
David Brownell2b3d9422008-06-19 18:19:28 -0700245 skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
246 if (skb == NULL) {
247 DBG(dev, "no rx skb\n");
248 goto enomem;
249 }
250
251 /* Some platforms perform better when IP packets are aligned,
252 * but on at least one, checksumming fails otherwise. Note:
253 * RNDIS headers involve variable numbers of LE32 values.
254 */
255 skb_reserve(skb, NET_IP_ALIGN);
256
257 req->buf = skb->data;
258 req->length = size;
259 req->complete = rx_complete;
260 req->context = skb;
261
262 retval = usb_ep_queue(out, req, gfp_flags);
263 if (retval == -ENOMEM)
264enomem:
265 defer_kevent(dev, WORK_RX_MEMORY);
266 if (retval) {
267 DBG(dev, "rx submit --> %d\n", retval);
268 if (skb)
269 dev_kfree_skb_any(skb);
David Brownell2b3d9422008-06-19 18:19:28 -0700270 }
271 return retval;
272}
273
274static void rx_complete(struct usb_ep *ep, struct usb_request *req)
275{
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700276 struct sk_buff *skb = req->context;
David Brownell2b3d9422008-06-19 18:19:28 -0700277 struct eth_dev *dev = ep->driver_data;
278 int status = req->status;
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700279 bool queue = 0;
David Brownell2b3d9422008-06-19 18:19:28 -0700280
281 switch (status) {
282
283 /* normal completion */
284 case 0:
285 skb_put(skb, req->actual);
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500286
287 if (dev->unwrap) {
288 unsigned long flags;
289
290 spin_lock_irqsave(&dev->lock, flags);
291 if (dev->port_usb) {
292 status = dev->unwrap(dev->port_usb,
293 skb,
294 &dev->rx_frames);
295 } else {
296 dev_kfree_skb_any(skb);
297 status = -ENOTCONN;
298 }
299 spin_unlock_irqrestore(&dev->lock, flags);
300 } else {
301 skb_queue_tail(&dev->rx_frames, skb);
David Brownell2b3d9422008-06-19 18:19:28 -0700302 }
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500303
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700304 if (!status)
305 queue = 1;
David Brownell2b3d9422008-06-19 18:19:28 -0700306 break;
307
308 /* software-driven interface shutdown */
309 case -ECONNRESET: /* unlink */
310 case -ESHUTDOWN: /* disconnect etc */
311 VDBG(dev, "rx shutdown, code %d\n", status);
312 goto quiesce;
313
314 /* for hardware automagic (such as pxa) */
315 case -ECONNABORTED: /* endpoint reset */
316 DBG(dev, "rx %s reset\n", ep->name);
317 defer_kevent(dev, WORK_RX_MEMORY);
318quiesce:
319 dev_kfree_skb_any(skb);
320 goto clean;
321
322 /* data overrun */
323 case -EOVERFLOW:
324 dev->net->stats.rx_over_errors++;
325 /* FALLTHROUGH */
326
327 default:
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700328 queue = 1;
329 dev_kfree_skb_any(skb);
David Brownell2b3d9422008-06-19 18:19:28 -0700330 dev->net->stats.rx_errors++;
331 DBG(dev, "rx status %d\n", status);
332 break;
333 }
334
David Brownell2b3d9422008-06-19 18:19:28 -0700335clean:
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700336 spin_lock(&dev->req_lock);
337 list_add(&req->list, &dev->rx_reqs);
338 spin_unlock(&dev->req_lock);
339
340 if (queue)
341 queue_work(uether_wq, &dev->rx_work);
David Brownell2b3d9422008-06-19 18:19:28 -0700342}
343
344static int prealloc(struct list_head *list, struct usb_ep *ep, unsigned n)
345{
346 unsigned i;
347 struct usb_request *req;
348
349 if (!n)
350 return -ENOMEM;
351
352 /* queue/recycle up to N requests */
353 i = n;
354 list_for_each_entry(req, list, list) {
355 if (i-- == 0)
356 goto extra;
357 }
358 while (i--) {
359 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
360 if (!req)
361 return list_empty(list) ? -ENOMEM : 0;
362 list_add(&req->list, list);
363 }
364 return 0;
365
366extra:
367 /* free extras */
368 for (;;) {
369 struct list_head *next;
370
371 next = req->list.next;
372 list_del(&req->list);
373 usb_ep_free_request(ep, req);
374
375 if (next == list)
376 break;
377
378 req = container_of(next, struct usb_request, list);
379 }
380 return 0;
381}
382
383static int alloc_requests(struct eth_dev *dev, struct gether *link, unsigned n)
384{
385 int status;
386
387 spin_lock(&dev->req_lock);
388 status = prealloc(&dev->tx_reqs, link->in_ep, n);
389 if (status < 0)
390 goto fail;
391 status = prealloc(&dev->rx_reqs, link->out_ep, n);
392 if (status < 0)
393 goto fail;
394 goto done;
395fail:
396 DBG(dev, "can't alloc requests\n");
397done:
398 spin_unlock(&dev->req_lock);
399 return status;
400}
401
402static void rx_fill(struct eth_dev *dev, gfp_t gfp_flags)
403{
404 struct usb_request *req;
405 unsigned long flags;
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700406 int req_cnt = 0;
David Brownell2b3d9422008-06-19 18:19:28 -0700407
408 /* fill unused rxq slots with some skb */
409 spin_lock_irqsave(&dev->req_lock, flags);
410 while (!list_empty(&dev->rx_reqs)) {
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700411 /* break the nexus of continuous completion and re-submission*/
412 if (++req_cnt > qlen(dev->gadget))
413 break;
414
David Brownell2b3d9422008-06-19 18:19:28 -0700415 req = container_of(dev->rx_reqs.next,
416 struct usb_request, list);
417 list_del_init(&req->list);
418 spin_unlock_irqrestore(&dev->req_lock, flags);
419
420 if (rx_submit(dev, req, gfp_flags) < 0) {
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700421 spin_lock_irqsave(&dev->req_lock, flags);
422 list_add(&req->list, &dev->rx_reqs);
423 spin_unlock_irqrestore(&dev->req_lock, flags);
David Brownell2b3d9422008-06-19 18:19:28 -0700424 defer_kevent(dev, WORK_RX_MEMORY);
425 return;
426 }
427
428 spin_lock_irqsave(&dev->req_lock, flags);
429 }
430 spin_unlock_irqrestore(&dev->req_lock, flags);
431}
432
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700433static void process_rx_w(struct work_struct *work)
434{
435 struct eth_dev *dev = container_of(work, struct eth_dev, rx_work);
436 struct sk_buff *skb;
437 int status = 0;
438
439 if (!dev->port_usb)
440 return;
441
442 while ((skb = skb_dequeue(&dev->rx_frames))) {
443 if (status < 0
444 || ETH_HLEN > skb->len
445 || skb->len > ETH_FRAME_LEN) {
446 dev->net->stats.rx_errors++;
447 dev->net->stats.rx_length_errors++;
448 DBG(dev, "rx length %d\n", skb->len);
449 dev_kfree_skb_any(skb);
450 continue;
451 }
452 skb->protocol = eth_type_trans(skb, dev->net);
453 dev->net->stats.rx_packets++;
454 dev->net->stats.rx_bytes += skb->len;
455
456 status = netif_rx_ni(skb);
457 }
458
459 if (netif_running(dev->net))
460 rx_fill(dev, GFP_KERNEL);
461}
462
David Brownell2b3d9422008-06-19 18:19:28 -0700463static void eth_work(struct work_struct *work)
464{
465 struct eth_dev *dev = container_of(work, struct eth_dev, work);
466
467 if (test_and_clear_bit(WORK_RX_MEMORY, &dev->todo)) {
468 if (netif_running(dev->net))
469 rx_fill(dev, GFP_KERNEL);
470 }
471
472 if (dev->todo)
473 DBG(dev, "work done, flags = 0x%lx\n", dev->todo);
474}
475
476static void tx_complete(struct usb_ep *ep, struct usb_request *req)
477{
478 struct sk_buff *skb = req->context;
479 struct eth_dev *dev = ep->driver_data;
Mayank Rana5b165cb2012-05-25 19:52:45 +0530480 struct net_device *net = dev->net;
481 struct usb_request *new_req;
482 struct usb_ep *in;
483 int length;
484 int retval;
David Brownell2b3d9422008-06-19 18:19:28 -0700485
486 switch (req->status) {
487 default:
488 dev->net->stats.tx_errors++;
489 VDBG(dev, "tx err %d\n", req->status);
490 /* FALLTHROUGH */
491 case -ECONNRESET: /* unlink */
492 case -ESHUTDOWN: /* disconnect etc */
493 break;
494 case 0:
Mayank Rana5b165cb2012-05-25 19:52:45 +0530495 if (!req->zero)
496 dev->net->stats.tx_bytes += req->length-1;
497 else
498 dev->net->stats.tx_bytes += req->length;
David Brownell2b3d9422008-06-19 18:19:28 -0700499 }
500 dev->net->stats.tx_packets++;
501
502 spin_lock(&dev->req_lock);
Mayank Rana5b165cb2012-05-25 19:52:45 +0530503 list_add_tail(&req->list, &dev->tx_reqs);
504
505 if (dev->port_usb->multi_pkt_xfer) {
506 dev->no_tx_req_used--;
507 req->length = 0;
508 in = dev->port_usb->in_ep;
509
510 if (!list_empty(&dev->tx_reqs)) {
511 new_req = container_of(dev->tx_reqs.next,
512 struct usb_request, list);
513 list_del(&new_req->list);
514 spin_unlock(&dev->req_lock);
515 if (new_req->length > 0) {
516 length = new_req->length;
517
518 /* NCM requires no zlp if transfer is
519 * dwNtbInMaxSize */
520 if (dev->port_usb->is_fixed &&
521 length == dev->port_usb->fixed_in_len &&
522 (length % in->maxpacket) == 0)
523 new_req->zero = 0;
524 else
525 new_req->zero = 1;
526
527 /* use zlp framing on tx for strict CDC-Ether
528 * conformance, though any robust network rx
529 * path ignores extra padding. and some hardware
530 * doesn't like to write zlps.
531 */
532 if (new_req->zero && !dev->zlp &&
533 (length % in->maxpacket) == 0) {
534 new_req->zero = 0;
535 length++;
536 }
537
538 new_req->length = length;
539 retval = usb_ep_queue(in, new_req, GFP_ATOMIC);
540 switch (retval) {
541 default:
542 DBG(dev, "tx queue err %d\n", retval);
543 break;
544 case 0:
545 spin_lock(&dev->req_lock);
546 dev->no_tx_req_used++;
547 spin_unlock(&dev->req_lock);
548 net->trans_start = jiffies;
549 }
550 } else {
551 spin_lock(&dev->req_lock);
552 list_add(&new_req->list, &dev->tx_reqs);
553 spin_unlock(&dev->req_lock);
554 }
555 } else {
556 spin_unlock(&dev->req_lock);
557 }
558 } else {
559 spin_unlock(&dev->req_lock);
560 dev_kfree_skb_any(skb);
561 }
David Brownell2b3d9422008-06-19 18:19:28 -0700562
David Brownell2b3d9422008-06-19 18:19:28 -0700563 if (netif_carrier_ok(dev->net))
564 netif_wake_queue(dev->net);
565}
566
567static inline int is_promisc(u16 cdc_filter)
568{
569 return cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
570}
571
Mayank Rana5b165cb2012-05-25 19:52:45 +0530572static void alloc_tx_buffer(struct eth_dev *dev)
573{
574 struct list_head *act;
575 struct usb_request *req;
576
577 dev->tx_req_bufsize = (TX_SKB_HOLD_THRESHOLD *
578 (dev->net->mtu
579 + sizeof(struct ethhdr)
580 /* size of rndis_packet_msg_type */
581 + 44
582 + 22));
583
584 list_for_each(act, &dev->tx_reqs) {
585 req = container_of(act, struct usb_request, list);
586 if (!req->buf)
587 req->buf = kmalloc(dev->tx_req_bufsize,
588 GFP_ATOMIC);
589 }
590}
591
Stephen Hemminger25a79c42009-08-31 19:50:45 +0000592static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
593 struct net_device *net)
David Brownell2b3d9422008-06-19 18:19:28 -0700594{
595 struct eth_dev *dev = netdev_priv(net);
596 int length = skb->len;
597 int retval;
598 struct usb_request *req = NULL;
599 unsigned long flags;
600 struct usb_ep *in;
601 u16 cdc_filter;
602
603 spin_lock_irqsave(&dev->lock, flags);
604 if (dev->port_usb) {
605 in = dev->port_usb->in_ep;
606 cdc_filter = dev->port_usb->cdc_filter;
607 } else {
608 in = NULL;
609 cdc_filter = 0;
610 }
611 spin_unlock_irqrestore(&dev->lock, flags);
612
613 if (!in) {
614 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000615 return NETDEV_TX_OK;
David Brownell2b3d9422008-06-19 18:19:28 -0700616 }
617
Mayank Rana5b165cb2012-05-25 19:52:45 +0530618 /* Allocate memory for tx_reqs to support multi packet transfer */
619 if (dev->port_usb->multi_pkt_xfer && !dev->tx_req_bufsize)
620 alloc_tx_buffer(dev);
621
David Brownell2b3d9422008-06-19 18:19:28 -0700622 /* apply outgoing CDC or RNDIS filters */
623 if (!is_promisc(cdc_filter)) {
624 u8 *dest = skb->data;
625
626 if (is_multicast_ether_addr(dest)) {
627 u16 type;
628
629 /* ignores USB_CDC_PACKET_TYPE_MULTICAST and host
630 * SET_ETHERNET_MULTICAST_FILTERS requests
631 */
632 if (is_broadcast_ether_addr(dest))
633 type = USB_CDC_PACKET_TYPE_BROADCAST;
634 else
635 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
636 if (!(cdc_filter & type)) {
637 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000638 return NETDEV_TX_OK;
David Brownell2b3d9422008-06-19 18:19:28 -0700639 }
640 }
641 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
642 }
643
644 spin_lock_irqsave(&dev->req_lock, flags);
645 /*
646 * this freelist can be empty if an interrupt triggered disconnect()
647 * and reconfigured the gadget (shutting down this queue) after the
648 * network stack decided to xmit but before we got the spinlock.
649 */
650 if (list_empty(&dev->tx_reqs)) {
651 spin_unlock_irqrestore(&dev->req_lock, flags);
Patrick McHardy5b548142009-06-12 06:22:29 +0000652 return NETDEV_TX_BUSY;
David Brownell2b3d9422008-06-19 18:19:28 -0700653 }
654
655 req = container_of(dev->tx_reqs.next, struct usb_request, list);
656 list_del(&req->list);
657
658 /* temporarily stop TX queue when the freelist empties */
659 if (list_empty(&dev->tx_reqs))
660 netif_stop_queue(net);
661 spin_unlock_irqrestore(&dev->req_lock, flags);
662
663 /* no buffer copies needed, unless the network stack did it
664 * or the hardware can't use skb buffers.
665 * or there's not enough space for extra headers we need
666 */
667 if (dev->wrap) {
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500668 unsigned long flags;
David Brownell2b3d9422008-06-19 18:19:28 -0700669
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500670 spin_lock_irqsave(&dev->lock, flags);
671 if (dev->port_usb)
672 skb = dev->wrap(dev->port_usb, skb);
673 spin_unlock_irqrestore(&dev->lock, flags);
674 if (!skb)
David Brownell2b3d9422008-06-19 18:19:28 -0700675 goto drop;
David Brownell2b3d9422008-06-19 18:19:28 -0700676 }
Mayank Rana5b165cb2012-05-25 19:52:45 +0530677
678 spin_lock_irqsave(&dev->req_lock, flags);
679 dev->tx_skb_hold_count++;
680 spin_unlock_irqrestore(&dev->req_lock, flags);
681
682 if (dev->port_usb->multi_pkt_xfer) {
683 memcpy(req->buf + req->length, skb->data, skb->len);
684 req->length = req->length + skb->len;
685 length = req->length;
686 dev_kfree_skb_any(skb);
687
688 spin_lock_irqsave(&dev->req_lock, flags);
689 if (dev->tx_skb_hold_count < TX_SKB_HOLD_THRESHOLD) {
690 if (dev->no_tx_req_used > TX_REQ_THRESHOLD) {
691 list_add(&req->list, &dev->tx_reqs);
692 spin_unlock_irqrestore(&dev->req_lock, flags);
693 goto success;
694 }
695 }
696
697 dev->no_tx_req_used++;
698 spin_unlock_irqrestore(&dev->req_lock, flags);
699
700 spin_lock_irqsave(&dev->lock, flags);
701 dev->tx_skb_hold_count = 0;
702 spin_unlock_irqrestore(&dev->lock, flags);
703 } else {
704 length = skb->len;
705 req->buf = skb->data;
706 req->context = skb;
707 }
708
David Brownell2b3d9422008-06-19 18:19:28 -0700709 req->complete = tx_complete;
710
Yauheni Kaliuta5c1168d2010-12-08 13:12:04 +0200711 /* NCM requires no zlp if transfer is dwNtbInMaxSize */
712 if (dev->port_usb->is_fixed &&
713 length == dev->port_usb->fixed_in_len &&
714 (length % in->maxpacket) == 0)
715 req->zero = 0;
716 else
717 req->zero = 1;
718
David Brownell2b3d9422008-06-19 18:19:28 -0700719 /* use zlp framing on tx for strict CDC-Ether conformance,
720 * though any robust network rx path ignores extra padding.
721 * and some hardware doesn't like to write zlps.
722 */
Mayank Rana5b165cb2012-05-25 19:52:45 +0530723 if (req->zero && !dev->zlp && (length % in->maxpacket) == 0) {
724 req->zero = 0;
David Brownell2b3d9422008-06-19 18:19:28 -0700725 length++;
Mayank Rana5b165cb2012-05-25 19:52:45 +0530726 }
David Brownell2b3d9422008-06-19 18:19:28 -0700727
728 req->length = length;
729
730 /* throttle highspeed IRQ rate back slightly */
Vijayavardhan Vennapusa20b627e2012-03-06 14:26:11 +0530731 if (gadget_is_dualspeed(dev->gadget) &&
732 (dev->gadget->speed == USB_SPEED_HIGH)) {
733 dev->tx_qlen++;
Mayank Rana5b165cb2012-05-25 19:52:45 +0530734 if (dev->tx_qlen == (qmult/2)) {
Vijayavardhan Vennapusa20b627e2012-03-06 14:26:11 +0530735 req->no_interrupt = 0;
736 dev->tx_qlen = 0;
737 } else {
738 req->no_interrupt = 1;
739 }
740 } else {
741 req->no_interrupt = 0;
742 }
David Brownell2b3d9422008-06-19 18:19:28 -0700743
744 retval = usb_ep_queue(in, req, GFP_ATOMIC);
745 switch (retval) {
746 default:
747 DBG(dev, "tx queue err %d\n", retval);
748 break;
749 case 0:
750 net->trans_start = jiffies;
David Brownell2b3d9422008-06-19 18:19:28 -0700751 }
752
753 if (retval) {
Mayank Rana5b165cb2012-05-25 19:52:45 +0530754 if (!dev->port_usb->multi_pkt_xfer)
755 dev_kfree_skb_any(skb);
David Brownell2b3d9422008-06-19 18:19:28 -0700756drop:
757 dev->net->stats.tx_dropped++;
David Brownell2b3d9422008-06-19 18:19:28 -0700758 spin_lock_irqsave(&dev->req_lock, flags);
759 if (list_empty(&dev->tx_reqs))
760 netif_start_queue(net);
761 list_add(&req->list, &dev->tx_reqs);
762 spin_unlock_irqrestore(&dev->req_lock, flags);
763 }
Mayank Rana5b165cb2012-05-25 19:52:45 +0530764success:
Patrick McHardy6ed10652009-06-23 06:03:08 +0000765 return NETDEV_TX_OK;
David Brownell2b3d9422008-06-19 18:19:28 -0700766}
767
768/*-------------------------------------------------------------------------*/
769
770static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
771{
772 DBG(dev, "%s\n", __func__);
773
774 /* fill the rx queue */
775 rx_fill(dev, gfp_flags);
776
777 /* and open the tx floodgates */
Vijayavardhan Vennapusa20b627e2012-03-06 14:26:11 +0530778 dev->tx_qlen = 0;
David Brownell2b3d9422008-06-19 18:19:28 -0700779 netif_wake_queue(dev->net);
780}
781
782static int eth_open(struct net_device *net)
783{
784 struct eth_dev *dev = netdev_priv(net);
785 struct gether *link;
786
787 DBG(dev, "%s\n", __func__);
788 if (netif_carrier_ok(dev->net))
789 eth_start(dev, GFP_KERNEL);
790
791 spin_lock_irq(&dev->lock);
792 link = dev->port_usb;
793 if (link && link->open)
794 link->open(link);
795 spin_unlock_irq(&dev->lock);
796
797 return 0;
798}
799
800static int eth_stop(struct net_device *net)
801{
802 struct eth_dev *dev = netdev_priv(net);
803 unsigned long flags;
804
805 VDBG(dev, "%s\n", __func__);
806 netif_stop_queue(net);
807
808 DBG(dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n",
809 dev->net->stats.rx_packets, dev->net->stats.tx_packets,
810 dev->net->stats.rx_errors, dev->net->stats.tx_errors
811 );
812
813 /* ensure there are no more active requests */
814 spin_lock_irqsave(&dev->lock, flags);
815 if (dev->port_usb) {
816 struct gether *link = dev->port_usb;
817
818 if (link->close)
819 link->close(link);
820
821 /* NOTE: we have no abort-queue primitive we could use
822 * to cancel all pending I/O. Instead, we disable then
823 * reenable the endpoints ... this idiom may leave toggle
824 * wrong, but that's a self-correcting error.
825 *
826 * REVISIT: we *COULD* just let the transfers complete at
827 * their own pace; the network stack can handle old packets.
828 * For the moment we leave this here, since it works.
829 */
830 usb_ep_disable(link->in_ep);
831 usb_ep_disable(link->out_ep);
832 if (netif_carrier_ok(net)) {
Rajkumar Raghupathye7c42322012-06-13 19:31:15 +0530833 if (config_ep_by_speed(dev->gadget, &link->func,
834 link->in_ep) ||
835 config_ep_by_speed(dev->gadget, &link->func,
836 link->out_ep)) {
837 link->in_ep->desc = NULL;
838 link->out_ep->desc = NULL;
839 return -EINVAL;
840 }
David Brownell2b3d9422008-06-19 18:19:28 -0700841 DBG(dev, "host still using in/out endpoints\n");
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300842 usb_ep_enable(link->in_ep);
843 usb_ep_enable(link->out_ep);
David Brownell2b3d9422008-06-19 18:19:28 -0700844 }
845 }
846 spin_unlock_irqrestore(&dev->lock, flags);
847
848 return 0;
849}
850
851/*-------------------------------------------------------------------------*/
852
853/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
854static char *dev_addr;
855module_param(dev_addr, charp, S_IRUGO);
856MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
857
858/* this address is invisible to ifconfig */
859static char *host_addr;
860module_param(host_addr, charp, S_IRUGO);
861MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
862
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200863static int get_ether_addr(const char *str, u8 *dev_addr)
David Brownell2b3d9422008-06-19 18:19:28 -0700864{
865 if (str) {
866 unsigned i;
867
868 for (i = 0; i < 6; i++) {
869 unsigned char num;
870
871 if ((*str == '.') || (*str == ':'))
872 str++;
Andy Shevchenkoe6448142010-06-15 17:04:44 +0300873 num = hex_to_bin(*str++) << 4;
874 num |= hex_to_bin(*str++);
David Brownell2b3d9422008-06-19 18:19:28 -0700875 dev_addr [i] = num;
876 }
877 if (is_valid_ether_addr(dev_addr))
878 return 0;
879 }
880 random_ether_addr(dev_addr);
881 return 1;
882}
883
884static struct eth_dev *the_dev;
885
Stephen Hemminger5ec38f32009-01-07 18:05:39 -0800886static const struct net_device_ops eth_netdev_ops = {
887 .ndo_open = eth_open,
888 .ndo_stop = eth_stop,
889 .ndo_start_xmit = eth_start_xmit,
890 .ndo_change_mtu = ueth_change_mtu,
891 .ndo_set_mac_address = eth_mac_addr,
892 .ndo_validate_addr = eth_validate_addr,
893};
David Brownell2b3d9422008-06-19 18:19:28 -0700894
Marcel Holtmannaa790742010-01-15 22:13:58 -0800895static struct device_type gadget_type = {
896 .name = "gadget",
897};
898
David Brownell2b3d9422008-06-19 18:19:28 -0700899/**
900 * gether_setup - initialize one ethernet-over-usb link
901 * @g: gadget to associated with these links
902 * @ethaddr: NULL, or a buffer in which the ethernet address of the
903 * host side of the link is recorded
904 * Context: may sleep
905 *
906 * This sets up the single network link that may be exported by a
907 * gadget driver using this framework. The link layer addresses are
908 * set up using module parameters.
909 *
910 * Returns negative errno, or zero on success
911 */
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200912int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
David Brownell2b3d9422008-06-19 18:19:28 -0700913{
Mike Lockwood735d20e2011-08-12 14:35:42 -0700914 return gether_setup_name(g, ethaddr, "usb");
915}
916
917/**
918 * gether_setup_name - initialize one ethernet-over-usb link
919 * @g: gadget to associated with these links
920 * @ethaddr: NULL, or a buffer in which the ethernet address of the
921 * host side of the link is recorded
922 * @netname: name for network device (for example, "usb")
923 * Context: may sleep
924 *
925 * This sets up the single network link that may be exported by a
926 * gadget driver using this framework. The link layer addresses are
927 * set up using module parameters.
928 *
929 * Returns negative errno, or zero on success
930 */
931int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
932 const char *netname)
933{
David Brownell2b3d9422008-06-19 18:19:28 -0700934 struct eth_dev *dev;
935 struct net_device *net;
936 int status;
937
938 if (the_dev)
939 return -EBUSY;
940
941 net = alloc_etherdev(sizeof *dev);
942 if (!net)
943 return -ENOMEM;
944
945 dev = netdev_priv(net);
946 spin_lock_init(&dev->lock);
947 spin_lock_init(&dev->req_lock);
948 INIT_WORK(&dev->work, eth_work);
Hemant Kumar08eb78e2012-07-30 20:38:47 -0700949 INIT_WORK(&dev->rx_work, process_rx_w);
David Brownell2b3d9422008-06-19 18:19:28 -0700950 INIT_LIST_HEAD(&dev->tx_reqs);
951 INIT_LIST_HEAD(&dev->rx_reqs);
952
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500953 skb_queue_head_init(&dev->rx_frames);
954
David Brownell2b3d9422008-06-19 18:19:28 -0700955 /* network device setup */
956 dev->net = net;
Mike Lockwood735d20e2011-08-12 14:35:42 -0700957 snprintf(net->name, sizeof(net->name), "%s%%d", netname);
David Brownell2b3d9422008-06-19 18:19:28 -0700958
959 if (get_ether_addr(dev_addr, net->dev_addr))
960 dev_warn(&g->dev,
961 "using random %s ethernet address\n", "self");
962 if (get_ether_addr(host_addr, dev->host_mac))
963 dev_warn(&g->dev,
964 "using random %s ethernet address\n", "host");
965
966 if (ethaddr)
967 memcpy(ethaddr, dev->host_mac, ETH_ALEN);
968
Stephen Hemminger5ec38f32009-01-07 18:05:39 -0800969 net->netdev_ops = &eth_netdev_ops;
970
David Brownell2b3d9422008-06-19 18:19:28 -0700971 SET_ETHTOOL_OPS(net, &ops);
972
973 /* two kinds of host-initiated state changes:
974 * - iff DATA transfer is active, carrier is "on"
975 * - tx queueing enabled if open *and* carrier is "on"
976 */
David Brownell2b3d9422008-06-19 18:19:28 -0700977 netif_carrier_off(net);
978
979 dev->gadget = g;
980 SET_NETDEV_DEV(net, &g->dev);
Marcel Holtmannaa790742010-01-15 22:13:58 -0800981 SET_NETDEV_DEVTYPE(net, &gadget_type);
David Brownell2b3d9422008-06-19 18:19:28 -0700982
983 status = register_netdev(net);
984 if (status < 0) {
985 dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
986 free_netdev(net);
987 } else {
Johannes Berge1749612008-10-27 15:59:26 -0700988 INFO(dev, "MAC %pM\n", net->dev_addr);
989 INFO(dev, "HOST MAC %pM\n", dev->host_mac);
David Brownell2b3d9422008-06-19 18:19:28 -0700990
991 the_dev = dev;
992 }
993
994 return status;
995}
996
997/**
998 * gether_cleanup - remove Ethernet-over-USB device
999 * Context: may sleep
1000 *
1001 * This is called to free all resources allocated by @gether_setup().
1002 */
1003void gether_cleanup(void)
1004{
1005 if (!the_dev)
1006 return;
1007
1008 unregister_netdev(the_dev->net);
Tejun Heo569ff2d2010-12-24 16:14:20 +01001009 flush_work_sync(&the_dev->work);
David Brownell2b3d9422008-06-19 18:19:28 -07001010 free_netdev(the_dev->net);
1011
David Brownell2b3d9422008-06-19 18:19:28 -07001012 the_dev = NULL;
1013}
1014
1015
1016/**
1017 * gether_connect - notify network layer that USB link is active
1018 * @link: the USB link, set up with endpoints, descriptors matching
1019 * current device speed, and any framing wrapper(s) set up.
1020 * Context: irqs blocked
1021 *
1022 * This is called to activate endpoints and let the network layer know
1023 * the connection is active ("carrier detect"). It may cause the I/O
1024 * queues to open and start letting network packets flow, but will in
1025 * any case activate the endpoints so that they respond properly to the
1026 * USB host.
1027 *
1028 * Verify net_device pointer returned using IS_ERR(). If it doesn't
1029 * indicate some error code (negative errno), ep->driver_data values
1030 * have been overwritten.
1031 */
1032struct net_device *gether_connect(struct gether *link)
1033{
1034 struct eth_dev *dev = the_dev;
1035 int result = 0;
1036
1037 if (!dev)
1038 return ERR_PTR(-EINVAL);
1039
1040 link->in_ep->driver_data = dev;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +03001041 result = usb_ep_enable(link->in_ep);
David Brownell2b3d9422008-06-19 18:19:28 -07001042 if (result != 0) {
1043 DBG(dev, "enable %s --> %d\n",
1044 link->in_ep->name, result);
1045 goto fail0;
1046 }
1047
1048 link->out_ep->driver_data = dev;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +03001049 result = usb_ep_enable(link->out_ep);
David Brownell2b3d9422008-06-19 18:19:28 -07001050 if (result != 0) {
1051 DBG(dev, "enable %s --> %d\n",
1052 link->out_ep->name, result);
1053 goto fail1;
1054 }
1055
1056 if (result == 0)
1057 result = alloc_requests(dev, link, qlen(dev->gadget));
1058
1059 if (result == 0) {
1060 dev->zlp = link->is_zlp_ok;
1061 DBG(dev, "qlen %d\n", qlen(dev->gadget));
1062
1063 dev->header_len = link->header_len;
1064 dev->unwrap = link->unwrap;
1065 dev->wrap = link->wrap;
1066
1067 spin_lock(&dev->lock);
Mayank Rana5b165cb2012-05-25 19:52:45 +05301068 dev->tx_skb_hold_count = 0;
1069 dev->no_tx_req_used = 0;
1070 dev->tx_req_bufsize = 0;
David Brownell2b3d9422008-06-19 18:19:28 -07001071 dev->port_usb = link;
1072 link->ioport = dev;
David Brownell29bac7b2008-09-06 21:33:49 -07001073 if (netif_running(dev->net)) {
1074 if (link->open)
1075 link->open(link);
1076 } else {
1077 if (link->close)
1078 link->close(link);
1079 }
David Brownell2b3d9422008-06-19 18:19:28 -07001080 spin_unlock(&dev->lock);
1081
1082 netif_carrier_on(dev->net);
1083 if (netif_running(dev->net))
1084 eth_start(dev, GFP_ATOMIC);
1085
1086 /* on error, disable any endpoints */
1087 } else {
1088 (void) usb_ep_disable(link->out_ep);
1089fail1:
1090 (void) usb_ep_disable(link->in_ep);
1091 }
1092fail0:
1093 /* caller is responsible for cleanup on error */
1094 if (result < 0)
1095 return ERR_PTR(result);
1096 return dev->net;
1097}
1098
1099/**
1100 * gether_disconnect - notify network layer that USB link is inactive
1101 * @link: the USB link, on which gether_connect() was called
1102 * Context: irqs blocked
1103 *
1104 * This is called to deactivate endpoints and let the network layer know
1105 * the connection went inactive ("no carrier").
1106 *
1107 * On return, the state is as if gether_connect() had never been called.
1108 * The endpoints are inactive, and accordingly without active USB I/O.
1109 * Pointers to endpoint descriptors and endpoint private data are nulled.
1110 */
1111void gether_disconnect(struct gether *link)
1112{
1113 struct eth_dev *dev = link->ioport;
1114 struct usb_request *req;
Hemant Kumar08eb78e2012-07-30 20:38:47 -07001115 struct sk_buff *skb;
David Brownell2b3d9422008-06-19 18:19:28 -07001116
David Brownell2b3d9422008-06-19 18:19:28 -07001117 if (!dev)
1118 return;
1119
1120 DBG(dev, "%s\n", __func__);
1121
1122 netif_stop_queue(dev->net);
1123 netif_carrier_off(dev->net);
1124
1125 /* disable endpoints, forcing (synchronous) completion
1126 * of all pending i/o. then free the request objects
1127 * and forget about the endpoints.
1128 */
1129 usb_ep_disable(link->in_ep);
1130 spin_lock(&dev->req_lock);
1131 while (!list_empty(&dev->tx_reqs)) {
1132 req = container_of(dev->tx_reqs.next,
1133 struct usb_request, list);
1134 list_del(&req->list);
1135
1136 spin_unlock(&dev->req_lock);
Mayank Rana5b165cb2012-05-25 19:52:45 +05301137 if (link->multi_pkt_xfer)
1138 kfree(req->buf);
David Brownell2b3d9422008-06-19 18:19:28 -07001139 usb_ep_free_request(link->in_ep, req);
1140 spin_lock(&dev->req_lock);
1141 }
1142 spin_unlock(&dev->req_lock);
1143 link->in_ep->driver_data = NULL;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +03001144 link->in_ep->desc = NULL;
David Brownell2b3d9422008-06-19 18:19:28 -07001145
1146 usb_ep_disable(link->out_ep);
1147 spin_lock(&dev->req_lock);
1148 while (!list_empty(&dev->rx_reqs)) {
1149 req = container_of(dev->rx_reqs.next,
1150 struct usb_request, list);
1151 list_del(&req->list);
1152
1153 spin_unlock(&dev->req_lock);
1154 usb_ep_free_request(link->out_ep, req);
1155 spin_lock(&dev->req_lock);
1156 }
1157 spin_unlock(&dev->req_lock);
Hemant Kumar08eb78e2012-07-30 20:38:47 -07001158
1159 spin_lock(&dev->rx_frames.lock);
1160 while ((skb = __skb_dequeue(&dev->rx_frames)))
1161 dev_kfree_skb_any(skb);
1162 spin_unlock(&dev->rx_frames.lock);
1163
David Brownell2b3d9422008-06-19 18:19:28 -07001164 link->out_ep->driver_data = NULL;
Tatyana Brokhman72c973d2011-06-28 16:33:48 +03001165 link->out_ep->desc = NULL;
David Brownell2b3d9422008-06-19 18:19:28 -07001166
1167 /* finish forgetting about this USB link episode */
1168 dev->header_len = 0;
1169 dev->unwrap = NULL;
1170 dev->wrap = NULL;
1171
1172 spin_lock(&dev->lock);
1173 dev->port_usb = NULL;
1174 link->ioport = NULL;
1175 spin_unlock(&dev->lock);
1176}
Hemant Kumar08eb78e2012-07-30 20:38:47 -07001177
1178static int __init gether_init(void)
1179{
1180 uether_wq = create_singlethread_workqueue("uether");
1181 if (!uether_wq) {
1182 pr_err("%s: Unable to create workqueue: uether\n", __func__);
1183 return -ENOMEM;
1184 }
1185 return 0;
1186}
1187module_init(gether_init);
1188
1189static void __exit gether_exit(void)
1190{
1191 destroy_workqueue(uether_wq);
1192
1193}
1194module_exit(gether_exit);
1195MODULE_DESCRIPTION("ethernet over USB driver");
1196MODULE_LICENSE("GPL v2");