CHROMIUM: Add Sony Gobi 3000 vid:pid.
[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"
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 qcusbnet_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 void qcusbnet_put(struct qcusbnet *dev)
45 {
46         mutex_lock(&qcusbnet_lock);
47         kref_put(&dev->refcount, free_dev);
48         mutex_unlock(&qcusbnet_lock);
49 }
50
51 struct qcusbnet *qcusbnet_get(struct qcusbnet *key)
52 {
53         /* Given a putative qcusbnet struct, return either the struct itself
54          * (with a ref taken) if the struct is still visible, or NULL if it's
55          * not. This prevents object-visibility races where someone is looking
56          * up an object as the last ref gets dropped; dropping the last ref and
57          * removing the object from the list are atomic with respect to getting
58          * a new ref. */
59         struct qcusbnet *entry;
60         mutex_lock(&qcusbnet_lock);
61         list_for_each_entry(entry, &qcusbnet_list, node) {
62                 if (entry == key) {
63                         kref_get(&entry->refcount);
64                         mutex_unlock(&qcusbnet_lock);
65                         return entry;
66                 }
67         }
68         mutex_unlock(&qcusbnet_lock);
69         return NULL;
70 }
71
72 static void wake_worker(struct worker *worker)
73 {
74         atomic_inc(&worker->work_count);
75         wake_up(&worker->waitq);
76 }
77
78 int qc_suspend(struct usb_interface *iface, pm_message_t event)
79 {
80         struct usbnet *usbnet;
81         struct qcusbnet *dev;
82
83         if (!iface)
84                 return -ENOMEM;
85
86         usbnet = usb_get_intfdata(iface);
87
88         if (!usbnet || !usbnet->net) {
89                 DBG("failed to get netdevice\n");
90                 return -ENXIO;
91         }
92
93         dev = (struct qcusbnet *)usbnet->data[0];
94         if (!dev) {
95                 DBG("failed to get QMIDevice\n");
96                 return -ENXIO;
97         }
98
99         if (!(event.event & PM_EVENT_AUTO)) {
100                 DBG("device suspended to power level %d\n",
101                     event.event);
102                 qc_setdown(dev, DOWN_DRIVER_SUSPENDED);
103         } else {
104                 DBG("device autosuspend\n");
105         }
106
107         if (event.event & PM_EVENT_SUSPEND) {
108                 qc_stopread(dev);
109                 usbnet->udev->reset_resume = 0;
110                 iface->dev.power.power_state.event = event.event;
111         } else {
112                 usbnet->udev->reset_resume = 1;
113         }
114
115         return usbnet_suspend(iface, event);
116 }
117
118 static int qc_resume(struct usb_interface *iface)
119 {
120         struct usbnet *usbnet;
121         struct qcusbnet *dev;
122         int ret;
123         int oldstate;
124
125         if (iface == 0)
126                 return -ENOMEM;
127
128         usbnet = usb_get_intfdata(iface);
129
130         if (!usbnet || !usbnet->net) {
131                 DBG("failed to get netdevice\n");
132                 return -ENXIO;
133         }
134
135         dev = (struct qcusbnet *)usbnet->data[0];
136         if (!dev) {
137                 DBG("failed to get QMIDevice\n");
138                 return -ENXIO;
139         }
140
141         oldstate = iface->dev.power.power_state.event;
142         iface->dev.power.power_state.event = PM_EVENT_ON;
143         DBG("resuming from power mode %d\n", oldstate);
144
145         if (oldstate & PM_EVENT_SUSPEND) {
146                 qc_cleardown(dev, DOWN_DRIVER_SUSPENDED);
147
148                 ret = usbnet_resume(iface);
149                 if (ret) {
150                         DBG("usbnet_resume error %d\n", ret);
151                         return ret;
152                 }
153
154                 ret = qc_startread(dev);
155                 if (ret) {
156                         DBG("qc_startread error %d\n", ret);
157                         return ret;
158                 }
159
160                 wake_worker(&dev->worker);
161         } else {
162                 DBG("nothing to resume\n");
163                 return 0;
164         }
165
166         return ret;
167 }
168
169 static int qcnet_bind(struct usbnet *usbnet, struct usb_interface *iface)
170 {
171         int numends;
172         int i;
173         struct usb_host_endpoint *endpoint = NULL;
174         struct usb_host_endpoint *in = NULL;
175         struct usb_host_endpoint *out = NULL;
176
177         if (iface->num_altsetting != 1) {
178                 DBG("invalid num_altsetting %u\n", iface->num_altsetting);
179                 return -EINVAL;
180         }
181
182         if (iface->cur_altsetting->desc.bInterfaceNumber != 0
183             && iface->cur_altsetting->desc.bInterfaceNumber != 5) {
184                 DBG("invalid interface %d\n",
185                           iface->cur_altsetting->desc.bInterfaceNumber);
186                 return -EINVAL;
187         }
188
189         numends = iface->cur_altsetting->desc.bNumEndpoints;
190         for (i = 0; i < numends; i++) {
191                 endpoint = iface->cur_altsetting->endpoint + i;
192                 if (!endpoint) {
193                         DBG("invalid endpoint %u\n", i);
194                         return -EINVAL;
195                 }
196
197                 if (usb_endpoint_dir_in(&endpoint->desc)
198                 &&  !usb_endpoint_xfer_int(&endpoint->desc)) {
199                         in = endpoint;
200                 } else if (!usb_endpoint_dir_out(&endpoint->desc)) {
201                         out = endpoint;
202                 }
203         }
204
205         if (!in || !out) {
206                 DBG("invalid endpoints\n");
207                 return -EINVAL;
208         }
209
210         if (usb_set_interface(usbnet->udev,
211                               iface->cur_altsetting->desc.bInterfaceNumber, 0)) {
212                 DBG("unable to set interface\n");
213                 return -EINVAL;
214         }
215
216         usbnet->in = usb_rcvbulkpipe(usbnet->udev, in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
217         usbnet->out = usb_sndbulkpipe(usbnet->udev, out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
218
219         DBG("in %x, out %x\n",
220             in->desc.bEndpointAddress,
221             out->desc.bEndpointAddress);
222
223         return 0;
224 }
225
226 static void qcnet_unbind(struct usbnet *usbnet, struct usb_interface *iface)
227 {
228         struct qcusbnet *dev = (struct qcusbnet *)usbnet->data[0];
229
230         netif_carrier_off(usbnet->net);
231         qc_deregister(dev);
232
233         kfree(usbnet->net->netdev_ops);
234         usbnet->net->netdev_ops = NULL;
235         /* drop the list's ref */
236         qcusbnet_put(dev);
237 }
238
239 static void qcnet_urbhook(struct urb *urb)
240 {
241         unsigned long flags;
242         struct worker *worker = urb->context;
243         if (!worker) {
244                 DBG("bad context\n");
245                 return;
246         }
247
248         if (urb->status) {
249                 DBG("urb finished with error %d\n", urb->status);
250         }
251
252         spin_lock_irqsave(&worker->active_lock, flags);
253         worker->active = ERR_PTR(-EAGAIN);
254         spin_unlock_irqrestore(&worker->active_lock, flags);
255         /* XXX-fix race against qcnet_stop()? */
256         wake_worker(worker);
257         usb_free_urb(urb);
258 }
259
260 static void qcnet_txtimeout(struct net_device *netdev)
261 {
262         struct list_head *node, *tmp;
263         struct qcusbnet *dev;
264         struct worker *worker;
265         struct urbreq *req;
266         unsigned long activeflags, listflags;
267         struct usbnet *usbnet = netdev_priv(netdev);
268
269         if (!usbnet || !usbnet->net) {
270                 DBG("failed to get usbnet device\n");
271                 return;
272         }
273
274         dev = (struct qcusbnet *)usbnet->data[0];
275         if (!dev) {
276                 DBG("failed to get QMIDevice\n");
277                 return;
278         }
279         worker = &dev->worker;
280
281         DBG("\n");
282
283         spin_lock_irqsave(&worker->active_lock, activeflags);
284         if (worker->active)
285                 usb_kill_urb(worker->active);
286         spin_unlock_irqrestore(&worker->active_lock, activeflags);
287
288         spin_lock_irqsave(&worker->urbs_lock, listflags);
289         list_for_each_safe(node, tmp, &worker->urbs) {
290                 req = list_entry(node, struct urbreq, node);
291                 usb_free_urb(req->urb);
292                 list_del(&req->node);
293                 kfree(req);
294         }
295         spin_unlock_irqrestore(&worker->urbs_lock, listflags);
296
297         wake_worker(worker);
298 }
299
300 static int worker_should_wake(struct worker *worker)
301 {
302         if (kthread_should_stop())
303                 return 1;
304         /* This is safe only because we are the only place that decrements this
305          * counter. */
306         if (atomic_read(&worker->work_count))
307                 return 1;
308         return 0;
309 }
310
311 static int qcnet_worker(void *arg)
312 {
313         struct list_head *node, *tmp;
314         unsigned long activeflags, listflags;
315         struct urbreq *req;
316         int status;
317         struct usb_device *usbdev;
318         struct worker *worker = arg;
319         if (!worker) {
320                 DBG("passed null pointer\n");
321                 return -EINVAL;
322         }
323
324         usbdev = interface_to_usbdev(worker->iface);
325
326         DBG("traffic thread started\n");
327
328         while (!kthread_should_stop()) {
329                 wait_event(worker->waitq, worker_should_wake(worker));
330
331                 if (kthread_should_stop())
332                         break;
333                 atomic_dec(&worker->work_count);
334
335                 spin_lock_irqsave(&worker->active_lock, activeflags);
336                 if (IS_ERR(worker->active) && PTR_ERR(worker->active) == -EAGAIN) {
337                         worker->active = NULL;
338                         spin_unlock_irqrestore(&worker->active_lock, activeflags);
339                         usb_autopm_put_interface(worker->iface);
340                         spin_lock_irqsave(&worker->active_lock, activeflags);
341                 }
342
343                 if (worker->active) {
344                         spin_unlock_irqrestore(&worker->active_lock, activeflags);
345                         continue;
346                 }
347
348                 spin_lock_irqsave(&worker->urbs_lock, listflags);
349                 if (list_empty(&worker->urbs)) {
350                         spin_unlock_irqrestore(&worker->urbs_lock, listflags);
351                         spin_unlock_irqrestore(&worker->active_lock, activeflags);
352                         continue;
353                 }
354
355                 req = list_first_entry(&worker->urbs, struct urbreq, node);
356                 list_del(&req->node);
357                 spin_unlock_irqrestore(&worker->urbs_lock, listflags);
358
359                 worker->active = req->urb;
360                 spin_unlock_irqrestore(&worker->active_lock, activeflags);
361
362                 status = usb_autopm_get_interface(worker->iface);
363                 if (status < 0) {
364                         DBG("unable to autoresume interface: %d\n", status);
365                         if (status == -EPERM) {
366                                 qc_suspend(worker->iface, PMSG_SUSPEND);
367                         }
368
369                         spin_lock_irqsave(&worker->urbs_lock, listflags);
370                         list_add(&req->node, &worker->urbs);
371                         spin_unlock_irqrestore(&worker->urbs_lock, listflags);
372
373                         spin_lock_irqsave(&worker->active_lock, activeflags);
374                         worker->active = NULL;
375                         spin_unlock_irqrestore(&worker->active_lock, activeflags);
376
377                         continue;
378                 }
379
380                 status = usb_submit_urb(worker->active, GFP_KERNEL);
381                 if (status < 0) {
382                         DBG("Failed to submit URB: %d.  Packet dropped\n", status);
383                         spin_lock_irqsave(&worker->active_lock, activeflags);
384                         usb_free_urb(worker->active);
385                         worker->active = NULL;
386                         spin_unlock_irqrestore(&worker->active_lock, activeflags);
387                         usb_autopm_put_interface(worker->iface);
388                         wake_worker(worker);
389                 }
390
391                 kfree(req);
392         }
393
394         spin_lock_irqsave(&worker->active_lock, activeflags);
395         if (worker->active) {
396                 usb_kill_urb(worker->active);
397         }
398         spin_unlock_irqrestore(&worker->active_lock, activeflags);
399
400         spin_lock_irqsave(&worker->urbs_lock, listflags);
401         list_for_each_safe(node, tmp, &worker->urbs) {
402                 req = list_entry(node, struct urbreq, node);
403                 usb_free_urb(req->urb);
404                 list_del(&req->node);
405                 kfree(req);
406         }
407         spin_unlock_irqrestore(&worker->urbs_lock, listflags);
408
409         DBG("traffic thread exiting\n");
410         worker->thread = NULL;
411         return 0;
412 }
413
414 static int qcnet_startxmit(struct sk_buff *skb, struct net_device *netdev)
415 {
416         unsigned long listflags;
417         struct qcusbnet *dev;
418         struct worker *worker;
419         struct urbreq *req;
420         void *data;
421         struct usbnet *usbnet = netdev_priv(netdev);
422
423         DBG("\n");
424
425         if (!usbnet || !usbnet->net) {
426                 DBG("failed to get usbnet device\n");
427                 return NETDEV_TX_BUSY;
428         }
429
430         dev = (struct qcusbnet *)usbnet->data[0];
431         if (!dev) {
432                 DBG("failed to get QMIDevice\n");
433                 return NETDEV_TX_BUSY;
434         }
435         worker = &dev->worker;
436
437         if (qc_isdown(dev, DOWN_DRIVER_SUSPENDED)) {
438                 DBG("device is suspended\n");
439                 dump_stack();
440                 return NETDEV_TX_BUSY;
441         }
442
443         req = kmalloc(sizeof(*req), GFP_ATOMIC);
444         if (!req) {
445                 DBG("unable to allocate URBList memory\n");
446                 return NETDEV_TX_BUSY;
447         }
448
449         req->urb = usb_alloc_urb(0, GFP_ATOMIC);
450
451         if (!req->urb) {
452                 kfree(req);
453                 DBG("unable to allocate URB\n");
454                 return NETDEV_TX_BUSY;
455         }
456
457         data = kmalloc(skb->len, GFP_ATOMIC);
458         if (!data) {
459                 usb_free_urb(req->urb);
460                 kfree(req);
461                 DBG("unable to allocate URB data\n");
462                 return NETDEV_TX_BUSY;
463         }
464         memcpy(data, skb->data, skb->len);
465
466         usb_fill_bulk_urb(req->urb, dev->usbnet->udev, dev->usbnet->out,
467                           data, skb->len, qcnet_urbhook, worker);
468
469         spin_lock_irqsave(&worker->urbs_lock, listflags);
470         list_add_tail(&req->node, &worker->urbs);
471         spin_unlock_irqrestore(&worker->urbs_lock, listflags);
472
473         wake_worker(worker);
474
475         netdev->trans_start = jiffies;
476         dev_kfree_skb_any(skb);
477
478         return NETDEV_TX_OK;
479 }
480
481 static int qcnet_open(struct net_device *netdev)
482 {
483         int status = 0;
484         struct qcusbnet *dev;
485         struct usbnet *usbnet = netdev_priv(netdev);
486
487         if (!usbnet) {
488                 DBG("failed to get usbnet device\n");
489                 return -ENXIO;
490         }
491
492         dev = (struct qcusbnet *)usbnet->data[0];
493         if (!dev) {
494                 DBG("failed to get QMIDevice\n");
495                 return -ENXIO;
496         }
497
498         DBG("\n");
499
500         dev->worker.iface = dev->iface;
501         INIT_LIST_HEAD(&dev->worker.urbs);
502         dev->worker.active = NULL;
503         spin_lock_init(&dev->worker.urbs_lock);
504         spin_lock_init(&dev->worker.active_lock);
505         atomic_set(&dev->worker.work_count, 0);
506         init_waitqueue_head(&dev->worker.waitq);
507
508         dev->worker.thread = kthread_run(qcnet_worker, &dev->worker, "qcnet_worker");
509         if (IS_ERR(dev->worker.thread)) {
510                 DBG("AutoPM thread creation error\n");
511                 return PTR_ERR(dev->worker.thread);
512         }
513
514         qc_cleardown(dev, DOWN_NET_IFACE_STOPPED);
515         if (dev->open) {
516                 status = dev->open(netdev);
517                 if (status == 0) {
518                         usb_autopm_put_interface(dev->iface);
519                 }
520         } else {
521                 DBG("no USBNetOpen defined\n");
522         }
523
524         return status;
525 }
526
527 int qcnet_stop(struct net_device *netdev)
528 {
529         struct qcusbnet *dev;
530         struct usbnet *usbnet = netdev_priv(netdev);
531
532         if (!usbnet || !usbnet->net) {
533                 DBG("failed to get netdevice\n");
534                 return -ENXIO;
535         }
536
537         dev = (struct qcusbnet *)usbnet->data[0];
538         if (!dev) {
539                 DBG("failed to get QMIDevice\n");
540                 return -ENXIO;
541         }
542
543         qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
544         kthread_stop(dev->worker.thread);
545         DBG("thread stopped\n");
546
547         if (dev->stop != NULL)
548                 return dev->stop(netdev);
549         return 0;
550 }
551
552 static const struct driver_info qc_netinfo = {
553         .description   = "QCUSBNet Ethernet Device",
554         .flags         = FLAG_ETHER,
555         .bind          = qcnet_bind,
556         .unbind        = qcnet_unbind,
557         .data          = 0,
558 };
559
560 #define MKVIDPID(v, p)                                  \
561 {                                                       \
562         USB_DEVICE(v, p),                               \
563         .driver_info = (unsigned long)&qc_netinfo,      \
564 }
565
566 static const struct usb_device_id qc_vidpids[] = {
567         MKVIDPID(0x05c6, 0x9215),       /* Acer Gobi 2000 */
568         MKVIDPID(0x05c6, 0x9265),       /* Asus Gobi 2000 */
569         MKVIDPID(0x16d8, 0x8002),       /* CMOTech Gobi 2000 */
570         MKVIDPID(0x413c, 0x8186),       /* Dell Gobi 2000 */
571         MKVIDPID(0x1410, 0xa010),       /* Entourage Gobi 2000 */
572         MKVIDPID(0x1410, 0xa011),       /* Entourage Gobi 2000 */
573         MKVIDPID(0x1410, 0xa012),       /* Entourage Gobi 2000 */
574         MKVIDPID(0x1410, 0xa013),       /* Entourage Gobi 2000 */
575         MKVIDPID(0x03f0, 0x251d),       /* HP Gobi 2000 */
576         MKVIDPID(0x05c6, 0x9205),       /* Lenovo Gobi 2000 */
577         MKVIDPID(0x05c6, 0x920b),       /* Generic Gobi 2000 */
578         MKVIDPID(0x04da, 0x250f),       /* Panasonic Gobi 2000 */
579         MKVIDPID(0x05c6, 0x9245),       /* Samsung Gobi 2000 */
580         MKVIDPID(0x1199, 0x9001),       /* Sierra Wireless Gobi 2000 */
581         MKVIDPID(0x1199, 0x9002),       /* Sierra Wireless Gobi 2000 */
582         MKVIDPID(0x1199, 0x9003),       /* Sierra Wireless Gobi 2000 */
583         MKVIDPID(0x1199, 0x9004),       /* Sierra Wireless Gobi 2000 */
584         MKVIDPID(0x1199, 0x9005),       /* Sierra Wireless Gobi 2000 */
585         MKVIDPID(0x1199, 0x9006),       /* Sierra Wireless Gobi 2000 */
586         MKVIDPID(0x1199, 0x9007),       /* Sierra Wireless Gobi 2000 */
587         MKVIDPID(0x1199, 0x9008),       /* Sierra Wireless Gobi 2000 */
588         MKVIDPID(0x1199, 0x9009),       /* Sierra Wireless Gobi 2000 */
589         MKVIDPID(0x1199, 0x900a),       /* Sierra Wireless Gobi 2000 */
590         MKVIDPID(0x05c6, 0x9225),       /* Sony Gobi 2000 */
591         MKVIDPID(0x05c6, 0x9235),       /* Top Global Gobi 2000 */
592         MKVIDPID(0x05c6, 0x9275),       /* iRex Technologies Gobi 2000 */
593
594         MKVIDPID(0x05c6, 0x920d),       /* Qualcomm Gobi 3000 */
595         MKVIDPID(0x1410, 0xa021),       /* Novatel Gobi 3000 */
596         MKVIDPID(0x413c, 0x8194),       /* Dell Gobi 3000 */
597         MKVIDPID(0x12D1, 0x14F1),       /* Sony Gobi 3000 */
598         { }
599 };
600
601 MODULE_DEVICE_TABLE(usb, qc_vidpids);
602
603 static u8 nibble(unsigned char c)
604 {
605         if (likely(isdigit(c)))
606                 return c - '0';
607         c = toupper(c);
608         if (likely(isxdigit(c)))
609                 return 10 + c - 'A';
610         return 0;
611 }
612
613 int qcnet_probe(struct usb_interface *iface, const struct usb_device_id *vidpids)
614 {
615         int status;
616         struct usbnet *usbnet;
617         struct qcusbnet *dev;
618         struct net_device_ops *netdevops;
619         int i;
620         u8 *addr;
621
622         status = usbnet_probe(iface, vidpids);
623         if (status < 0) {
624                 DBG("usbnet_probe failed %d\n", status);
625                 return status;
626         }
627
628         usbnet = usb_get_intfdata(iface);
629
630         if (!usbnet || !usbnet->net) {
631                 DBG("failed to get netdevice\n");
632                 return -ENXIO;
633         }
634
635         dev = kmalloc(sizeof(struct qcusbnet), GFP_KERNEL);
636         if (!dev) {
637                 DBG("failed to allocate device buffers\n");
638                 return -ENOMEM;
639         }
640
641         usbnet->data[0] = (unsigned long)dev;
642
643         dev->usbnet = usbnet;
644
645         netdevops = kmalloc(sizeof(struct net_device_ops), GFP_KERNEL);
646         if (!netdevops) {
647                 DBG("failed to allocate net device ops\n");
648                 return -ENOMEM;
649         }
650         memcpy(netdevops, usbnet->net->netdev_ops, sizeof(struct net_device_ops));
651
652         dev->open = netdevops->ndo_open;
653         netdevops->ndo_open = qcnet_open;
654         dev->stop = netdevops->ndo_stop;
655         netdevops->ndo_stop = qcnet_stop;
656         netdevops->ndo_start_xmit = qcnet_startxmit;
657         netdevops->ndo_tx_timeout = qcnet_txtimeout;
658
659         usbnet->net->netdev_ops = netdevops;
660
661         memset(&(dev->usbnet->net->stats), 0, sizeof(struct net_device_stats));
662
663         dev->iface = iface;
664         memset(&(dev->meid), '0', 14);
665
666         dev->valid = false;
667         memset(&dev->qmi, 0, sizeof(dev->qmi));
668
669         dev->qmi.devclass = devclass;
670
671         kref_init(&dev->refcount);
672         INIT_LIST_HEAD(&dev->node);
673         INIT_LIST_HEAD(&dev->qmi.clients);
674         atomic_set(&dev->worker.work_count, 0);
675         init_waitqueue_head(&dev->worker.waitq);
676         spin_lock_init(&dev->qmi.clients_lock);
677
678         dev->down = 0;
679         qc_setdown(dev, DOWN_NO_NDIS_CONNECTION);
680         qc_setdown(dev, DOWN_NET_IFACE_STOPPED);
681
682         status = qc_register(dev);
683         if (status) {
684                 qc_deregister(dev);
685         } else {
686                 mutex_lock(&qcusbnet_lock);
687                 /* Give our initial ref to the list */
688                 list_add(&dev->node, &qcusbnet_list);
689                 mutex_unlock(&qcusbnet_lock);
690         }
691         /* After calling qc_register, MEID is valid */
692         addr = &usbnet->net->dev_addr[0];
693         for (i = 0; i < 6; i++)
694                 addr[i] = (nibble(dev->meid[i*2+2]) << 4)+
695                         nibble(dev->meid[i*2+3]);
696         addr[0] &= 0xfe;                /* clear multicast bit */
697         addr[0] |= 0x02;                /* set local assignment bit (IEEE802) */
698
699         return status;
700 }
701 EXPORT_SYMBOL_GPL(qcnet_probe);
702
703 static struct usb_driver qcusbnet = {
704         .name       = "gobi",
705         .id_table   = qc_vidpids,
706         .probe      = qcnet_probe,
707         .disconnect = usbnet_disconnect,
708         .suspend    = qc_suspend,
709         .resume     = qc_resume,
710         .supports_autosuspend = true,
711 };
712
713 static int __init modinit(void)
714 {
715         devclass = class_create(THIS_MODULE, "QCQMI");
716         if (IS_ERR(devclass)) {
717                 DBG("error at class_create %ld\n", PTR_ERR(devclass));
718                 return -ENOMEM;
719         }
720         printk(KERN_INFO "%s: %s\n", DRIVER_DESC, DRIVER_VERSION);
721         return usb_register(&qcusbnet);
722 }
723 module_init(modinit);
724
725 static void __exit modexit(void)
726 {
727         usb_deregister(&qcusbnet);
728         class_destroy(devclass);
729 }
730 module_exit(modexit);
731
732 MODULE_VERSION(DRIVER_VERSION);
733 MODULE_AUTHOR(DRIVER_AUTHOR);
734 MODULE_DESCRIPTION(DRIVER_DESC);
735 MODULE_LICENSE("Dual BSD/GPL");
736
737 module_param(qcusbnet_debug, bool, S_IRUGO | S_IWUSR);
738 MODULE_PARM_DESC(qcusbnet_debug, "Debugging enabled or not");