CHROMIUM: gobi: Make probe failures WARN, not ERROR.
[cascardo/linux.git] / drivers / net / usb / gobi / qcusbnet.c
1 /* qcusbnet.c - gobi network device
2  * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
3
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 and
6  * only version 2 as published by the Free Software Foundation.
7
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18
19 #include "structs.h"
20 #include "qmidevice.h"
21 #include "qmi.h"
22 #include "qcusbnet.h"
23
24 #include <linux/module.h>
25 #include <linux/ctype.h>
26
27 #define DRIVER_VERSION "1.0.110+google+w0"
28 #define DRIVER_AUTHOR "Qualcomm Innovation Center"
29 #define DRIVER_DESC "gobi"
30
31 static LIST_HEAD(qcusbnet_list);
32 static DEFINE_MUTEX(qcusbnet_lock);
33
34 int gobi_debug;
35 static struct class *devclass;
36
37 static void free_dev(struct kref *ref)
38 {
39         struct qcusbnet *dev = container_of(ref, struct qcusbnet, refcount);
40         list_del(&dev->node);
41         kfree(dev);
42 }
43
44 static void free_urb_with_skb(struct urb *urb)
45 {
46         struct sk_buff *skb = (struct sk_buff *)urb->context;
47         dev_kfree_skb_any(skb);
48         usb_free_urb(urb);
49 }
50
51 void qcusbnet_put(struct qcusbnet *dev)
52 {
53         mutex_lock(&qcusbnet_lock);
54         kref_put(&dev->refcount, free_dev);
55         mutex_unlock(&qcusbnet_lock);
56 }
57
58 struct qcusbnet *qcusbnet_get(struct qcusbnet *key)
59 {
60         /* Given a putative qcusbnet struct, return either the struct itself
61          * (with a ref taken) if the struct is still visible, or NULL if it's
62          * not. This prevents object-visibility races where someone is looking
63          * up an object as the last ref gets dropped; dropping the last ref and
64          * removing the object from the list are atomic with respect to getting
65          * a new ref. */
66         struct qcusbnet *entry;
67         mutex_lock(&qcusbnet_lock);
68         list_for_each_entry(entry, &qcusbnet_list, node) {
69                 if (entry == key) {
70                         kref_get(&entry->refcount);
71                         mutex_unlock(&qcusbnet_lock);
72                         return entry;
73                 }
74         }
75         mutex_unlock(&qcusbnet_lock);
76         return NULL;
77 }
78
79 int qc_suspend(struct usb_interface *iface, pm_message_t event)
80 {
81         struct usbnet *usbnet;
82         struct qcusbnet *dev;
83
84         BUG_ON(!iface);
85
86         usbnet = usb_get_intfdata(iface);
87         BUG_ON(!usbnet || !usbnet->net);
88
89         dev = (struct qcusbnet *)usbnet->data[0];
90         BUG_ON(!dev);
91
92         if (!(event.event & PM_EVENT_AUTO)) {
93                 GOBI_DEBUG("device suspended to power level %d",
94                     event.event);
95                 qc_setdown(dev, DOWN_DRIVER_SUSPENDED);
96         } else {
97                 GOBI_DEBUG("device autosuspend");
98         }
99
100         if (event.event & PM_EVENT_SUSPEND) {
101                 qc_stopread(dev);
102                 usbnet->udev->reset_resume = 0;
103                 iface->dev.power.power_state.event = event.event;
104         } else {
105                 usbnet->udev->reset_resume = 1;
106         }
107
108         return usbnet_suspend(iface, event);
109 }
110
111 static int qc_resume(struct usb_interface *iface)
112 {
113         struct usbnet *usbnet;
114         struct qcusbnet *dev;
115         int ret;
116         int oldstate;
117
118         BUG_ON(!iface);
119
120         usbnet = usb_get_intfdata(iface);
121         BUG_ON(!usbnet || !usbnet->net);
122
123         dev = (struct qcusbnet *)usbnet->data[0];
124         BUG_ON(!dev);
125
126         oldstate = iface->dev.power.power_state.event;
127         iface->dev.power.power_state.event = PM_EVENT_ON;
128         GOBI_DEBUG("resuming from power mode %d", oldstate);
129
130         if (oldstate & PM_EVENT_SUSPEND) {
131                 qc_cleardown(dev, DOWN_DRIVER_SUSPENDED);
132
133                 ret = usbnet_resume(iface);
134                 if (ret) {
135                         GOBI_ERROR("usbnet_resume failed: %d", ret);
136                         return ret;
137                 }
138
139                 ret = qc_startread(dev);
140                 if (ret) {
141                         GOBI_ERROR("qc_startread failed: %d", ret);
142                         return ret;
143                 }
144         } else {
145                 GOBI_DEBUG("nothing to resume");
146                 return 0;
147         }
148
149         return ret;
150 }
151
152 static int qcnet_bind(struct usbnet *usbnet, struct usb_interface *iface)
153 {
154         int numends;
155         int i;
156         struct usb_host_endpoint *endpoint = NULL;
157         struct usb_host_endpoint *in = NULL;
158         struct usb_host_endpoint *out = NULL;
159         int dir_in, dir_out, xfer_int;
160
161         if (iface->num_altsetting != 1) {
162                 GOBI_WARN("invalid num_altsetting %u", iface->num_altsetting);
163                 return -EINVAL;
164         }
165
166         if (iface->cur_altsetting->desc.bInterfaceNumber != 0
167             && iface->cur_altsetting->desc.bInterfaceNumber != 5) {
168                 GOBI_WARN("invalid interface %d",
169                           iface->cur_altsetting->desc.bInterfaceNumber);
170                 return -EINVAL;
171         }
172
173         GOBI_DEBUG("interface number: %d",
174                 iface->cur_altsetting->desc.bInterfaceNumber);
175
176         numends = iface->cur_altsetting->desc.bNumEndpoints;
177         for (i = 0; i < numends; i++) {
178                 endpoint = iface->cur_altsetting->endpoint + i;
179
180                 dir_in   = usb_endpoint_dir_in(&endpoint->desc);
181                 dir_out  = usb_endpoint_dir_out(&endpoint->desc);
182                 xfer_int = usb_endpoint_xfer_int(&endpoint->desc);
183
184                 GOBI_DEBUG("endpoint %d: addr %u "
185                         "dir_in %d dir_out %d xfer_int %d",
186                         i, endpoint->desc.bEndpointAddress,
187                         dir_in, dir_out, xfer_int);
188
189                 if (dir_in && !xfer_int) {
190                         if (in) {
191                                 GOBI_WARN("multiple in endpoints");
192                                 return -EINVAL;
193                         }
194                         GOBI_DEBUG("setting endpoint %d as in", i);
195                         in = endpoint;
196                 } else if (dir_out && !xfer_int) {
197                         if (out) {
198                                 GOBI_WARN("multiple out endpoints");
199                                 return -EINVAL;
200                         }
201                         GOBI_DEBUG("setting endpoint %d as out", i);
202                         out = endpoint;
203                 } else {
204                         GOBI_DEBUG("ignoring endpoint %d", i);
205                 }
206         }
207
208         if (!in || !out) {
209                 GOBI_WARN("missing endpoint(s)");
210                 if (in)
211                         GOBI_WARN("found in endpoint: %u",
212                                 in->desc.bEndpointAddress);
213                 else
214                         GOBI_WARN("didn't find in endpoint");
215                 if (out)
216                         GOBI_WARN("found out endpoint: %u",
217                                 out->desc.bEndpointAddress);
218                 else
219                         GOBI_WARN("didn't find out endpoint");
220                 return -EINVAL;
221         }
222
223         if (usb_set_interface(usbnet->udev,
224                               iface->cur_altsetting->desc.bInterfaceNumber, 0)) {
225                 GOBI_WARN("unable to set interface");
226                 return -EINVAL;
227         }
228
229         GOBI_DEBUG("found endpoints: in %u, out %u",
230                    in->desc.bEndpointAddress,
231                    out->desc.bEndpointAddress);
232
233         usbnet->in = usb_rcvbulkpipe(usbnet->udev,
234                 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
235         usbnet->out = usb_sndbulkpipe(usbnet->udev,
236                 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
237
238         return 0;
239 }
240
241 static void qcnet_unbind(struct usbnet *usbnet, struct usb_interface *iface)
242 {
243         struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
244
245         dev->dying = true;
246
247         kfree(usbnet->net->netdev_ops);
248         usbnet->net->netdev_ops = NULL;
249 }
250
251 static void qcnet_bg_complete(struct work_struct *work)
252 {
253         unsigned long listflags;
254         struct qcusbnet *dev = container_of(work, struct qcusbnet, complete);
255
256         BUG_ON(!dev->active);
257         free_urb_with_skb(dev->active);
258         dev->active = NULL;
259
260         usb_autopm_put_interface(dev->iface);
261
262         spin_lock_irqsave(&dev->urbs_lock, listflags);
263         if (!list_empty(&dev->urbs))
264                 queue_work(dev->workqueue, &dev->startxmit);
265         spin_unlock_irqrestore(&dev->urbs_lock, listflags);
266 }
267
268 static void qcnet_complete(struct urb *urb)
269 {
270         struct sk_buff *skb = urb->context;
271         struct qcusbnet *dev = *(struct qcusbnet **)skb->cb;
272
273         BUG_ON(urb != dev->active);
274         queue_work(dev->workqueue, &dev->complete);
275 }
276
277 static void qcnet_bg_txtimeout(struct work_struct *work)
278 {
279         struct qcusbnet *dev = container_of(work, struct qcusbnet, txtimeout);
280         struct list_head *node, *tmp;
281         struct urb *urb;
282         if (dev->active)
283                 usb_kill_urb(dev->active);
284         list_for_each_safe(node, tmp, &dev->urbs) {
285                 urb = list_entry(node, struct urb, urb_list);
286                 list_del(&urb->urb_list);
287                 free_urb_with_skb(urb);
288         }
289 }
290
291 static void qcnet_txtimeout(struct net_device *netdev)
292 {
293         struct usbnet *usbnet = netdev_priv(netdev);
294         struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
295         queue_work(dev->workqueue, &dev->txtimeout);
296 }
297
298 static void qcnet_bg_startxmit(struct work_struct *work)
299 {
300         unsigned long listflags;
301         struct qcusbnet *dev = container_of(work, struct qcusbnet, startxmit);
302         struct urb *urb = NULL;
303         int status;
304
305         if (dev->dying) {
306                 GOBI_WARN("dying device");
307                 /* Fear not; queued urbs will be freed in qcnet_disconnect. */
308                 return;
309         }
310
311         if (dev->active)
312                 return;
313
314         status = usb_autopm_get_interface(dev->iface);
315         if (status < 0) {
316                 GOBI_ERROR("failed to autoresume interface: %d", status);
317                 if (status == -EPERM)
318                         qc_suspend(dev->iface, PMSG_SUSPEND);
319                 /* We could just drop the packet here, right...? It seems like
320                  * if this ever happens, we'll spin, but the old driver did that
321                  * as well. */
322                 queue_work(dev->workqueue, &dev->startxmit);
323                 return;
324         }
325
326         spin_lock_irqsave(&dev->urbs_lock, listflags);
327         if (!list_empty(&dev->urbs)) {
328                 urb = list_first_entry(&dev->urbs, struct urb, urb_list);
329                 list_del(&urb->urb_list);
330         }
331         spin_unlock_irqrestore(&dev->urbs_lock, listflags);
332         if (urb == NULL) {
333                 /* If we hit this case, it means that we added our urb to the
334                  * list while there was an urb in flight, and that urb
335                  * completed, causing our urb to be submitted; in addition, our
336                  * urb completed too, all before we got to schedule this work.
337                  * Unlikely, but possible. */
338                 usb_autopm_put_interface(dev->iface);
339                 return;
340         }
341
342         dev->active = urb;
343         status = usb_submit_urb(urb, GFP_KERNEL);
344         if (status < 0) {
345                 GOBI_ERROR("failed to submit urb: %d (packet dropped)", status);
346                 free_urb_with_skb(urb);
347                 dev->active = NULL;
348                 usb_autopm_put_interface(dev->iface);
349         }
350 }
351
352 static int qcnet_startxmit(struct sk_buff *skb, struct net_device *netdev)
353 {
354         unsigned long listflags;
355         struct urb *urb;
356         struct usbnet *usbnet = netdev_priv(netdev);
357         struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
358
359         if (qc_isdown(dev, DOWN_DRIVER_SUSPENDED)) {
360                 GOBI_ERROR("device is suspended (packet requeued)");
361                 return NETDEV_TX_BUSY;
362         }
363
364         urb = usb_alloc_urb(0, GFP_ATOMIC);
365         if (!urb) {
366                 GOBI_ERROR("failed to allocate urb (packet requeued)");
367                 return NETDEV_TX_BUSY;
368         }
369
370         usb_fill_bulk_urb(urb, dev->usbnet->udev, dev->usbnet->out,
371                           skb->data, skb->len, qcnet_complete, skb);
372         *(struct qcusbnet **)skb->cb = dev;
373
374         spin_lock_irqsave(&dev->urbs_lock, listflags);
375         list_add_tail(&urb->urb_list, &dev->urbs);
376         spin_unlock_irqrestore(&dev->urbs_lock, listflags);
377
378         queue_work(dev->workqueue, &dev->startxmit);
379
380         netdev->trans_start = jiffies;
381
382         return NETDEV_TX_OK;
383 }
384
385 static int qcnet_open(struct net_device *netdev)
386 {
387         int status = 0;
388         struct qcusbnet *dev;
389         struct usbnet *usbnet = netdev_priv(netdev);
390
391         BUG_ON(!usbnet);
392
393         dev = (struct qcusbnet *)usbnet->data[0];
394         BUG_ON(!dev);
395
396         qc_cleardown(dev, DOWN_NET_IFACE_STOPPED);
397         if (dev->open) {
398                 status = dev->open(netdev);
399                 if (status == 0) {
400                         usb_autopm_put_interface(dev->iface);
401                 }
402         } else {
403                 GOBI_WARN("no USBNetOpen defined");
404         }
405
406         return status;
407 }
408
409 int qcnet_stop(struct net_device *netdev)
410 {
411         struct qcusbnet *dev;
412         struct usbnet *usbnet = netdev_priv(netdev);
413
414         BUG_ON(!usbnet);
415
416         dev = (struct qcusbnet *)usbnet->data[0];
417         BUG_ON(!dev);
418
419         qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
420
421         if (dev->stop != NULL)
422                 return dev->stop(netdev);
423         return 0;
424 }
425
426 static const struct driver_info qc_netinfo = {
427         .description   = "QCUSBNet Ethernet Device",
428         .flags         = FLAG_ETHER | FLAG_WWAN,
429         .bind          = qcnet_bind,
430         .unbind        = qcnet_unbind,
431         .data          = 0,
432 };
433
434 #define MKVIDPID(v, p)                                  \
435 {                                                       \
436         USB_DEVICE(v, p),                               \
437         .driver_info = (unsigned long)&qc_netinfo,      \
438 }
439
440 static const struct usb_device_id qc_vidpids[] = {
441         MKVIDPID(0x05c6, 0x9215),       /* Acer Gobi 2000 */
442         MKVIDPID(0x05c6, 0x9265),       /* Asus Gobi 2000 */
443         MKVIDPID(0x16d8, 0x8002),       /* CMOTech Gobi 2000 */
444         MKVIDPID(0x413c, 0x8186),       /* Dell Gobi 2000 */
445         MKVIDPID(0x1410, 0xa010),       /* Entourage Gobi 2000 */
446         MKVIDPID(0x1410, 0xa011),       /* Entourage Gobi 2000 */
447         MKVIDPID(0x1410, 0xa012),       /* Entourage Gobi 2000 */
448         MKVIDPID(0x1410, 0xa013),       /* Entourage Gobi 2000 */
449         MKVIDPID(0x03f0, 0x251d),       /* HP Gobi 2000 */
450         MKVIDPID(0x05c6, 0x9205),       /* Lenovo Gobi 2000 */
451         MKVIDPID(0x05c6, 0x920b),       /* Generic Gobi 2000 */
452         MKVIDPID(0x04da, 0x250f),       /* Panasonic Gobi 2000 */
453         MKVIDPID(0x05c6, 0x9245),       /* Samsung Gobi 2000 */
454         MKVIDPID(0x1199, 0x9001),       /* Sierra Wireless Gobi 2000 */
455         MKVIDPID(0x1199, 0x9002),       /* Sierra Wireless Gobi 2000 */
456         MKVIDPID(0x1199, 0x9003),       /* Sierra Wireless Gobi 2000 */
457         MKVIDPID(0x1199, 0x9004),       /* Sierra Wireless Gobi 2000 */
458         MKVIDPID(0x1199, 0x9005),       /* Sierra Wireless Gobi 2000 */
459         MKVIDPID(0x1199, 0x9006),       /* Sierra Wireless Gobi 2000 */
460         MKVIDPID(0x1199, 0x9007),       /* Sierra Wireless Gobi 2000 */
461         MKVIDPID(0x1199, 0x9008),       /* Sierra Wireless Gobi 2000 */
462         MKVIDPID(0x1199, 0x9009),       /* Sierra Wireless Gobi 2000 */
463         MKVIDPID(0x1199, 0x900a),       /* Sierra Wireless Gobi 2000 */
464         MKVIDPID(0x05c6, 0x9225),       /* Sony Gobi 2000 */
465         MKVIDPID(0x05c6, 0x9235),       /* Top Global Gobi 2000 */
466         MKVIDPID(0x05c6, 0x9275),       /* iRex Technologies Gobi 2000 */
467
468         MKVIDPID(0x05c6, 0x920d),       /* Qualcomm Gobi 3000 */
469         MKVIDPID(0x1410, 0xa021),       /* Novatel Gobi 3000 */
470         MKVIDPID(0x413c, 0x8194),       /* Dell Gobi 3000 */
471         MKVIDPID(0x12D1, 0x14F1),       /* Sony Gobi 3000 */
472         { }
473 };
474
475 MODULE_DEVICE_TABLE(usb, qc_vidpids);
476
477 static u8 nibble(unsigned char c)
478 {
479         if (likely(isdigit(c)))
480                 return c - '0';
481         c = toupper(c);
482         if (likely(isxdigit(c)))
483                 return 10 + c - 'A';
484         return 0;
485 }
486
487 static int discover_endpoints(struct qcusbnet *dev)
488 {
489         int numends;
490         int i;
491         struct usb_host_endpoint *endpoint = NULL;
492         struct usb_host_endpoint *int_in   = NULL;
493         struct usb_host_endpoint *bulk_in  = NULL;
494         struct usb_host_endpoint *bulk_out = NULL;
495         int dir_in, dir_out, xfer_int;
496
497         GOBI_DEBUG("interface number: %d",
498                 dev->iface->cur_altsetting->desc.bInterfaceNumber);
499
500         numends = dev->iface->cur_altsetting->desc.bNumEndpoints;
501         for (i = 0; i < numends; i++) {
502                 endpoint = dev->iface->cur_altsetting->endpoint + i;
503
504                 dir_in = usb_endpoint_dir_in(&endpoint->desc);
505                 dir_out = usb_endpoint_dir_out(&endpoint->desc);
506                 xfer_int = usb_endpoint_xfer_int(&endpoint->desc);
507
508                 GOBI_DEBUG("endpoint %d: addr %x "
509                         "dir_in %d dir_out %d xfer_int %d",
510                         i, endpoint->desc.bEndpointAddress,
511                         dir_in, dir_out, xfer_int);
512
513                 if (dir_in && xfer_int) {
514                         if (int_in) {
515                                 GOBI_ERROR("multiple int_in endpoints");
516                                 return -EINVAL;
517                         }
518                         GOBI_DEBUG("setting endpoint %d as int in", i);
519                         int_in = endpoint;
520                 } else if (dir_in && !xfer_int) {
521                         if (bulk_in) {
522                                 GOBI_ERROR("multiple bulk_in endpoints");
523                                 return -EINVAL;
524                         }
525                         GOBI_DEBUG("setting endpoint %d as bulk in", i);
526                         bulk_in = endpoint;
527                 } else if (dir_out && !xfer_int) {
528                         if (bulk_out) {
529                                 GOBI_ERROR("multiple bulk_out endpoints");
530                                 return -EINVAL;
531                         }
532                         GOBI_DEBUG("setting endpoint %d as bulk out", i);
533                         bulk_out = endpoint;
534                 } else {
535                         GOBI_DEBUG("ignoring endpoint %d", i);
536                 }
537         }
538
539         if (!int_in || !bulk_in || !bulk_out) {
540                 GOBI_ERROR("missing endpoint(s)");
541                 if (int_in)
542                         GOBI_ERROR("found int_in endpoint: %u",
543                                 int_in->desc.bEndpointAddress);
544                 else
545                         GOBI_ERROR("didn't find int_in endpoint");
546                 if (bulk_in)
547                         GOBI_ERROR("found bulk_in endpoint: %u",
548                                 bulk_in->desc.bEndpointAddress);
549                 else
550                         GOBI_ERROR("didn't find bulk_in endpoint");
551                 if (bulk_out)
552                         GOBI_ERROR("found bulk_out endpoint: %u",
553                                 bulk_out->desc.bEndpointAddress);
554                 else
555                         GOBI_ERROR("didn't find bulk_out endpoint");
556                 return -EINVAL;
557         }
558
559         dev->iface_num     = dev->iface->cur_altsetting->desc.bInterfaceNumber;
560         dev->int_in_endp   = int_in->desc.bEndpointAddress;
561         dev->bulk_in_endp  = bulk_in->desc.bEndpointAddress;
562         dev->bulk_out_endp = bulk_out->desc.bEndpointAddress;
563
564         GOBI_DEBUG("found endpoints: iface_num %u "
565                 "int_in %u bulk_in %u bulk_out %u",
566                 dev->iface_num,
567                 dev->int_in_endp, dev->bulk_in_endp, dev->bulk_out_endp);
568
569         return 0;
570 }
571
572 int qcnet_probe(struct usb_interface *iface, const struct usb_device_id *vidpids)
573 {
574         int status;
575         struct usbnet *usbnet;
576         struct qcusbnet *dev;
577         struct net_device_ops *netdevops;
578         int i;
579         u8 *addr;
580
581         status = usbnet_probe(iface, vidpids);
582         if (status < 0) {
583                 GOBI_WARN("usbnet_probe failed: %d", status);
584                 goto fail;
585         }
586
587         usbnet = usb_get_intfdata(iface);
588
589         if (!usbnet) {
590                 GOBI_ERROR("usbnet is NULL");
591                 status = -ENXIO;
592                 goto fail_disconnect;
593         }
594
595         if (!usbnet->net) {
596                 GOBI_ERROR("usbnet->net is NULL");
597                 status = -ENXIO;
598                 goto fail_disconnect;
599         }
600
601         dev = kmalloc(sizeof(struct qcusbnet), GFP_KERNEL);
602         if (!dev) {
603                 GOBI_ERROR("failed to allocate struct qcusbnet");
604                 status = -ENOMEM;
605                 goto fail_disconnect;
606         }
607
608         dev->dying = false;
609         dev->iface = iface;
610
611         status = discover_endpoints(dev);
612         if (status) {
613                 GOBI_ERROR("discover_endpoints failed: %d", status);
614                 goto fail_free;
615         }
616
617         usbnet->data[0] = (unsigned long)dev;
618
619         dev->usbnet = usbnet;
620
621         netdevops = kmalloc(sizeof(struct net_device_ops), GFP_KERNEL);
622         if (!netdevops) {
623                 GOBI_ERROR("failed to allocate net device ops");
624                 status = -ENOMEM;
625                 goto fail_free;
626         }
627         memcpy(netdevops, usbnet->net->netdev_ops, sizeof(struct net_device_ops));
628
629         /* TODO(ttuttle): Can we just make a static copy of this? */
630         dev->open = netdevops->ndo_open;
631         netdevops->ndo_open = qcnet_open;
632         dev->stop = netdevops->ndo_stop;
633         netdevops->ndo_stop = qcnet_stop;
634         netdevops->ndo_start_xmit = qcnet_startxmit;
635         netdevops->ndo_tx_timeout = qcnet_txtimeout;
636
637         usbnet->net->netdev_ops = netdevops;
638
639         memset(&(dev->usbnet->net->stats), 0, sizeof(struct net_device_stats));
640
641         memset(&(dev->meid), '0', 14);
642
643         dev->valid = false;
644         memset(&dev->qmi, 0, sizeof(dev->qmi));
645
646         dev->qmi.devclass = devclass;
647
648         kref_init(&dev->refcount);
649         INIT_LIST_HEAD(&dev->node);
650         INIT_LIST_HEAD(&dev->qmi.clients);
651         dev->workqueue = alloc_ordered_workqueue("gobi", 0);
652
653         spin_lock_init(&dev->urbs_lock);
654         INIT_LIST_HEAD(&dev->urbs);
655         dev->active = NULL;
656         INIT_WORK(&dev->startxmit, qcnet_bg_startxmit);
657         INIT_WORK(&dev->txtimeout, qcnet_bg_txtimeout);
658         INIT_WORK(&dev->complete, qcnet_bg_complete);
659
660         spin_lock_init(&dev->qmi.clients_lock);
661
662         dev->down = 0;
663         qc_setdown(dev, DOWN_NO_NDIS_CONNECTION);
664         qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
665
666         status = qc_register(dev);
667         if (status) {
668                 GOBI_ERROR("qc_register failed: %d", status);
669                 goto fail_destroy;
670         }
671
672         iface->needs_remote_wakeup = 1;
673
674         mutex_lock(&qcusbnet_lock);
675         /* Give our initial ref to the list */
676         list_add(&dev->node, &qcusbnet_list);
677         mutex_unlock(&qcusbnet_lock);
678
679         /* After calling qc_register, MEID is valid */
680         addr = &usbnet->net->dev_addr[0];
681         for (i = 0; i < 6; i++)
682                 addr[i] = (nibble(dev->meid[i*2+2]) << 4)+
683                         nibble(dev->meid[i*2+3]);
684         addr[0] &= 0xfe;                /* clear multicast bit */
685         addr[0] |= 0x02;                /* set local assignment bit (IEEE802) */
686
687         return 0;
688
689 fail_destroy:
690         destroy_workqueue(dev->workqueue);
691 fail_free:
692         kfree(dev);
693 fail_disconnect:
694         usbnet_disconnect(iface);
695 fail:
696         return status;
697 }
698 EXPORT_SYMBOL_GPL(qcnet_probe);
699
700 static void qcnet_disconnect(struct usb_interface *intf)
701 {
702         struct usbnet *usbnet = usb_get_intfdata(intf);
703         struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
704         struct list_head *node, *tmp;
705         struct urb *urb;
706
707         intf->needs_remote_wakeup = 0;
708         netif_carrier_off(usbnet->net);
709         usbnet_disconnect(intf);
710
711         qc_deregister(dev);
712
713         destroy_workqueue(dev->workqueue);
714         list_for_each_safe(node, tmp, &dev->urbs) {
715                 urb = list_entry(node, struct urb, urb_list);
716                 list_del(&urb->urb_list);
717                 free_urb_with_skb(urb);
718         }
719         qcusbnet_put(dev);
720 }
721
722 static struct usb_driver qcusbnet = {
723         .name       = "gobi",
724         .id_table   = qc_vidpids,
725         .probe      = qcnet_probe,
726         .disconnect = qcnet_disconnect,
727         .suspend    = qc_suspend,
728         .resume     = qc_resume,
729         .supports_autosuspend = true,
730 };
731
732 static int __init modinit(void)
733 {
734         devclass = class_create(THIS_MODULE, "QCQMI");
735         if (IS_ERR(devclass)) {
736                 GOBI_ERROR("class_create failed: %ld", PTR_ERR(devclass));
737                 return -ENOMEM;
738         }
739         printk(KERN_INFO "%s: %s", DRIVER_DESC, DRIVER_VERSION);
740         return usb_register(&qcusbnet);
741 }
742 module_init(modinit);
743
744 static void __exit modexit(void)
745 {
746         usb_deregister(&qcusbnet);
747         class_destroy(devclass);
748 }
749 module_exit(modexit);
750
751 MODULE_VERSION(DRIVER_VERSION);
752 MODULE_AUTHOR(DRIVER_AUTHOR);
753 MODULE_DESCRIPTION(DRIVER_DESC);
754 MODULE_LICENSE("Dual BSD/GPL");
755
756 module_param(gobi_debug, int, S_IRUGO | S_IWUSR);
757 MODULE_PARM_DESC(gobi_debug, "Debugging level");