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