staging: gdm72xx: WIMAX_GDM72XX_USB_PM should depend on USB_SUSPEND
[deliverable/linux.git] / drivers / staging / gdm72xx / gdm_usb.c
1 /*
2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
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
14 #include <linux/module.h>
15 #include <linux/version.h>
16 #include <linux/kernel.h>
17 #include <linux/usb.h>
18 #include <asm/byteorder.h>
19
20 #include "gdm_usb.h"
21 #include "gdm_wimax.h"
22 #include "usb_boot.h"
23 #include "hci.h"
24
25 #include "usb_ids.h"
26
27 MODULE_DEVICE_TABLE(usb, id_table);
28
29 #define TX_BUF_SIZE 2048
30 #if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
31 #define RX_BUF_SIZE (128*1024) /* For packet aggregation */
32 #else
33 #define RX_BUF_SIZE 2048
34 #endif
35
36 #define GDM7205_PADDING 256
37
38 #define H2B(x) __cpu_to_be16(x)
39 #define B2H(x) __be16_to_cpu(x)
40 #define DB2H(x) __be32_to_cpu(x)
41
42 #define DOWNLOAD_CONF_VALUE 0x21
43
44 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
45
46 static DECLARE_WAIT_QUEUE_HEAD(k_wait);
47 static LIST_HEAD(k_list);
48 static DEFINE_SPINLOCK(k_lock);
49 static int k_mode_stop;
50
51 #define K_WAIT_TIME (2 * HZ / 100)
52
53 #endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
54
55 static int init_usb(struct usbwm_dev *udev);
56 static void release_usb(struct usbwm_dev *udev);
57
58 /*#define DEBUG */
59 #ifdef DEBUG
60 static void hexdump(char *title, u8 *data, int len)
61 {
62 int i;
63
64 printk(KERN_DEBUG "%s: length = %d\n", title, len);
65 for (i = 0; i < len; i++) {
66 printk(KERN_DEBUG "%02x ", data[i]);
67 if ((i & 0xf) == 0xf)
68 printk(KERN_DEBUG "\n");
69 }
70 printk(KERN_DEBUG "\n");
71 }
72 #endif
73
74 static struct usb_tx *alloc_tx_struct(struct tx_cxt *tx)
75 {
76 struct usb_tx *t = NULL;
77
78 t = kmalloc(sizeof(*t), GFP_ATOMIC);
79 if (t == NULL)
80 goto out;
81
82 memset(t, 0, sizeof(*t));
83
84 t->urb = usb_alloc_urb(0, GFP_ATOMIC);
85 t->buf = kmalloc(TX_BUF_SIZE, GFP_ATOMIC);
86 if (t->urb == NULL || t->buf == NULL)
87 goto out;
88
89 t->tx_cxt = tx;
90
91 return t;
92 out:
93 if (t) {
94 usb_free_urb(t->urb);
95 kfree(t->buf);
96 kfree(t);
97 }
98 return NULL;
99 }
100
101 static void free_tx_struct(struct usb_tx *t)
102 {
103 if (t) {
104 usb_free_urb(t->urb);
105 kfree(t->buf);
106 kfree(t);
107 }
108 }
109
110 static struct usb_rx *alloc_rx_struct(struct rx_cxt *rx)
111 {
112 struct usb_rx *r = NULL;
113
114 r = kmalloc(sizeof(*r), GFP_ATOMIC);
115 if (r == NULL)
116 goto out;
117
118 memset(r, 0, sizeof(*r));
119
120 r->urb = usb_alloc_urb(0, GFP_ATOMIC);
121 r->buf = kmalloc(RX_BUF_SIZE, GFP_ATOMIC);
122 if (r->urb == NULL || r->buf == NULL)
123 goto out;
124
125 r->rx_cxt = rx;
126 return r;
127 out:
128 if (r) {
129 usb_free_urb(r->urb);
130 kfree(r->buf);
131 kfree(r);
132 }
133 return NULL;
134 }
135
136 static void free_rx_struct(struct usb_rx *r)
137 {
138 if (r) {
139 usb_free_urb(r->urb);
140 kfree(r->buf);
141 kfree(r);
142 }
143 }
144
145 /* Before this function is called, spin lock should be locked. */
146 static struct usb_tx *get_tx_struct(struct tx_cxt *tx, int *no_spc)
147 {
148 struct usb_tx *t;
149
150 if (list_empty(&tx->free_list)) {
151 *no_spc = 1;
152 return NULL;
153 }
154
155 t = list_entry(tx->free_list.next, struct usb_tx, list);
156 list_del(&t->list);
157
158 *no_spc = list_empty(&tx->free_list) ? 1 : 0;
159
160 return t;
161 }
162
163 /* Before this function is called, spin lock should be locked. */
164 static void put_tx_struct(struct tx_cxt *tx, struct usb_tx *t)
165 {
166 list_add_tail(&t->list, &tx->free_list);
167 }
168
169 /* Before this function is called, spin lock should be locked. */
170 static struct usb_rx *get_rx_struct(struct rx_cxt *rx)
171 {
172 struct usb_rx *r;
173
174 if (list_empty(&rx->free_list)) {
175 r = alloc_rx_struct(rx);
176 if (r == NULL)
177 return NULL;
178
179 list_add(&r->list, &rx->free_list);
180 }
181
182 r = list_entry(rx->free_list.next, struct usb_rx, list);
183 list_del(&r->list);
184 list_add_tail(&r->list, &rx->used_list);
185
186 return r;
187 }
188
189 /* Before this function is called, spin lock should be locked. */
190 static void put_rx_struct(struct rx_cxt *rx, struct usb_rx *r)
191 {
192 list_del(&r->list);
193 list_add(&r->list, &rx->free_list);
194 }
195
196 static int init_usb(struct usbwm_dev *udev)
197 {
198 int ret = 0, i;
199 struct tx_cxt *tx = &udev->tx;
200 struct rx_cxt *rx = &udev->rx;
201 struct usb_tx *t;
202 struct usb_rx *r;
203
204 INIT_LIST_HEAD(&tx->free_list);
205 INIT_LIST_HEAD(&tx->sdu_list);
206 INIT_LIST_HEAD(&tx->hci_list);
207 #if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
208 INIT_LIST_HEAD(&tx->pending_list);
209 #endif
210
211 INIT_LIST_HEAD(&rx->free_list);
212 INIT_LIST_HEAD(&rx->used_list);
213
214 spin_lock_init(&tx->lock);
215 spin_lock_init(&rx->lock);
216
217 for (i = 0; i < MAX_NR_SDU_BUF; i++) {
218 t = alloc_tx_struct(tx);
219 if (t == NULL) {
220 ret = -ENOMEM;
221 goto fail;
222 }
223 list_add(&t->list, &tx->free_list);
224 }
225
226 r = alloc_rx_struct(rx);
227 if (r == NULL) {
228 ret = -ENOMEM;
229 goto fail;
230 }
231
232 list_add(&r->list, &rx->free_list);
233 return ret;
234
235 fail:
236 release_usb(udev);
237 return ret;
238 }
239
240 static void release_usb(struct usbwm_dev *udev)
241 {
242 struct tx_cxt *tx = &udev->tx;
243 struct rx_cxt *rx = &udev->rx;
244 struct usb_tx *t, *t_next;
245 struct usb_rx *r, *r_next;
246
247 list_for_each_entry_safe(t, t_next, &tx->sdu_list, list) {
248 list_del(&t->list);
249 free_tx_struct(t);
250 }
251
252 list_for_each_entry_safe(t, t_next, &tx->hci_list, list) {
253 list_del(&t->list);
254 free_tx_struct(t);
255 }
256
257 list_for_each_entry_safe(t, t_next, &tx->free_list, list) {
258 list_del(&t->list);
259 free_tx_struct(t);
260 }
261
262 list_for_each_entry_safe(r, r_next, &rx->free_list, list) {
263 list_del(&r->list);
264 free_rx_struct(r);
265 }
266
267 list_for_each_entry_safe(r, r_next, &rx->used_list, list) {
268 list_del(&r->list);
269 free_rx_struct(r);
270 }
271 }
272
273 static void gdm_usb_send_complete(struct urb *urb)
274 {
275 struct usb_tx *t = urb->context;
276 struct tx_cxt *tx = t->tx_cxt;
277 u8 *pkt = t->buf;
278 u16 cmd_evt;
279 unsigned long flags;
280
281 /* Completion by usb_unlink_urb */
282 if (urb->status == -ECONNRESET)
283 return;
284
285 spin_lock_irqsave(&tx->lock, flags);
286
287 if (t->callback)
288 t->callback(t->cb_data);
289
290 /* Delete from sdu list or hci list. */
291 list_del(&t->list);
292
293 cmd_evt = (pkt[0] << 8) | pkt[1];
294 if (cmd_evt == WIMAX_TX_SDU)
295 put_tx_struct(tx, t);
296 else
297 free_tx_struct(t);
298
299 spin_unlock_irqrestore(&tx->lock, flags);
300 }
301
302 static int gdm_usb_send(void *priv_dev, void *data, int len,
303 void (*cb)(void *data), void *cb_data)
304 {
305 struct usbwm_dev *udev = priv_dev;
306 struct usb_device *usbdev = udev->usbdev;
307 struct tx_cxt *tx = &udev->tx;
308 struct usb_tx *t;
309 int padding = udev->padding;
310 int no_spc = 0, ret;
311 u8 *pkt = data;
312 u16 cmd_evt;
313 unsigned long flags;
314
315 if (!udev->usbdev) {
316 printk(KERN_ERR "%s: No such device\n", __func__);
317 return -ENODEV;
318 }
319
320 BUG_ON(len > TX_BUF_SIZE - padding - 1);
321
322 spin_lock_irqsave(&tx->lock, flags);
323
324 cmd_evt = (pkt[0] << 8) | pkt[1];
325 if (cmd_evt == WIMAX_TX_SDU) {
326 t = get_tx_struct(tx, &no_spc);
327 if (t == NULL) {
328 /* This case must not happen. */
329 spin_unlock_irqrestore(&tx->lock, flags);
330 return -ENOSPC;
331 }
332 list_add_tail(&t->list, &tx->sdu_list);
333 } else {
334 t = alloc_tx_struct(tx);
335 if (t == NULL) {
336 spin_unlock_irqrestore(&tx->lock, flags);
337 return -ENOMEM;
338 }
339 list_add_tail(&t->list, &tx->hci_list);
340 }
341
342 memcpy(t->buf + padding, data, len);
343 t->callback = cb;
344 t->cb_data = cb_data;
345
346 /*
347 * In some cases, USB Module of WiMax is blocked when data size is
348 * the multiple of 512. So, increment length by one in that case.
349 */
350 if ((len % 512) == 0)
351 len++;
352
353 usb_fill_bulk_urb(t->urb,
354 usbdev,
355 usb_sndbulkpipe(usbdev, 1),
356 t->buf,
357 len + padding,
358 gdm_usb_send_complete,
359 t);
360
361 #ifdef DEBUG
362 hexdump("usb_send", t->buf, len + padding);
363 #endif
364 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
365 if (usbdev->state & USB_STATE_SUSPENDED) {
366 list_add_tail(&t->p_list, &tx->pending_list);
367 schedule_work(&udev->pm_ws);
368 goto out;
369 }
370 #endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
371
372 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
373 if (udev->bw_switch) {
374 list_add_tail(&t->p_list, &tx->pending_list);
375 goto out;
376 } else if (cmd_evt == WIMAX_SCAN) {
377 struct rx_cxt *rx;
378 struct usb_rx *r;
379
380 rx = &udev->rx;
381
382 list_for_each_entry(r, &rx->used_list, list)
383 usb_unlink_urb(r->urb);
384 udev->bw_switch = 1;
385
386 spin_lock(&k_lock);
387 list_add_tail(&udev->list, &k_list);
388 spin_unlock(&k_lock);
389
390 wake_up(&k_wait);
391 }
392 #endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
393
394 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
395 if (ret)
396 goto send_fail;
397
398 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
399 usb_mark_last_busy(usbdev);
400 #endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
401
402 #if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
403 out:
404 #endif
405 spin_unlock_irqrestore(&tx->lock, flags);
406
407 if (no_spc)
408 return -ENOSPC;
409
410 return 0;
411
412 send_fail:
413 t->callback = NULL;
414 gdm_usb_send_complete(t->urb);
415 spin_unlock_irqrestore(&tx->lock, flags);
416 return ret;
417 }
418
419 static void gdm_usb_rcv_complete(struct urb *urb)
420 {
421 struct usb_rx *r = urb->context;
422 struct rx_cxt *rx = r->rx_cxt;
423 struct usbwm_dev *udev = container_of(r->rx_cxt, struct usbwm_dev, rx);
424 struct tx_cxt *tx = &udev->tx;
425 struct usb_tx *t;
426 u16 cmd_evt;
427 unsigned long flags;
428
429 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
430 struct usb_device *dev = urb->dev;
431 #endif
432
433 /* Completion by usb_unlink_urb */
434 if (urb->status == -ECONNRESET)
435 return;
436
437 spin_lock_irqsave(&tx->lock, flags);
438
439 if (!urb->status) {
440 cmd_evt = (r->buf[0] << 8) | (r->buf[1]);
441 #ifdef DEBUG
442 hexdump("usb_receive", r->buf, urb->actual_length);
443 #endif
444 if (cmd_evt == WIMAX_SDU_TX_FLOW) {
445 if (r->buf[4] == 0) {
446 #ifdef DEBUG
447 printk(KERN_DEBUG "WIMAX ==> STOP SDU TX\n");
448 #endif
449 list_for_each_entry(t, &tx->sdu_list, list)
450 usb_unlink_urb(t->urb);
451 } else if (r->buf[4] == 1) {
452 #ifdef DEBUG
453 printk(KERN_DEBUG "WIMAX ==> START SDU TX\n");
454 #endif
455 list_for_each_entry(t, &tx->sdu_list, list) {
456 usb_submit_urb(t->urb, GFP_ATOMIC);
457 }
458 /*
459 * If free buffer for sdu tx doesn't
460 * exist, then tx queue should not be
461 * woken. For this reason, don't pass
462 * the command, START_SDU_TX.
463 */
464 if (list_empty(&tx->free_list))
465 urb->actual_length = 0;
466 }
467 }
468 }
469
470 if (!urb->status && r->callback)
471 r->callback(r->cb_data, r->buf, urb->actual_length);
472
473 spin_lock(&rx->lock);
474 put_rx_struct(rx, r);
475 spin_unlock(&rx->lock);
476
477 spin_unlock_irqrestore(&tx->lock, flags);
478
479 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
480 usb_mark_last_busy(dev);
481 #endif
482 }
483
484 static int gdm_usb_receive(void *priv_dev,
485 void (*cb)(void *cb_data, void *data, int len),
486 void *cb_data)
487 {
488 struct usbwm_dev *udev = priv_dev;
489 struct usb_device *usbdev = udev->usbdev;
490 struct rx_cxt *rx = &udev->rx;
491 struct usb_rx *r;
492 unsigned long flags;
493
494 if (!udev->usbdev) {
495 printk(KERN_ERR "%s: No such device\n", __func__);
496 return -ENODEV;
497 }
498
499 spin_lock_irqsave(&rx->lock, flags);
500 r = get_rx_struct(rx);
501 spin_unlock_irqrestore(&rx->lock, flags);
502
503 if (r == NULL)
504 return -ENOMEM;
505
506 r->callback = cb;
507 r->cb_data = cb_data;
508
509 usb_fill_bulk_urb(r->urb,
510 usbdev,
511 usb_rcvbulkpipe(usbdev, 0x82),
512 r->buf,
513 RX_BUF_SIZE,
514 gdm_usb_rcv_complete,
515 r);
516
517 return usb_submit_urb(r->urb, GFP_ATOMIC);
518 }
519
520 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
521 static void do_pm_control(struct work_struct *work)
522 {
523 struct usbwm_dev *udev = container_of(work, struct usbwm_dev, pm_ws);
524 struct tx_cxt *tx = &udev->tx;
525 int ret;
526 unsigned long flags;
527
528 ret = usb_autopm_get_interface(udev->intf);
529 if (!ret)
530 usb_autopm_put_interface(udev->intf);
531
532 spin_lock_irqsave(&tx->lock, flags);
533 if (!(udev->usbdev->state & USB_STATE_SUSPENDED)
534 && (!list_empty(&tx->hci_list) || !list_empty(&tx->sdu_list))) {
535 struct usb_tx *t, *temp;
536
537 list_for_each_entry_safe(t, temp, &tx->pending_list, p_list) {
538 list_del(&t->p_list);
539 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
540
541 if (ret) {
542 t->callback = NULL;
543 gdm_usb_send_complete(t->urb);
544 }
545 }
546 }
547 spin_unlock_irqrestore(&tx->lock, flags);
548 }
549 #endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
550
551 static int gdm_usb_probe(struct usb_interface *intf,
552 const struct usb_device_id *id)
553 {
554 int ret = 0;
555 u8 bConfigurationValue;
556 struct phy_dev *phy_dev = NULL;
557 struct usbwm_dev *udev = NULL;
558 u16 idVendor, idProduct, bcdDevice;
559
560 struct usb_device *usbdev = interface_to_usbdev(intf);
561
562 usb_get_dev(usbdev);
563 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
564
565 /*USB description is set up with Little-Endian*/
566 idVendor = L2H(usbdev->descriptor.idVendor);
567 idProduct = L2H(usbdev->descriptor.idProduct);
568 bcdDevice = L2H(usbdev->descriptor.bcdDevice);
569
570 printk(KERN_INFO "Found GDM USB VID = 0x%04x PID = 0x%04x...\n",
571 idVendor, idProduct);
572 printk(KERN_INFO "GCT WiMax driver version %s\n", DRIVER_VERSION);
573
574
575 if (idProduct == EMERGENCY_PID) {
576 ret = usb_emergency(usbdev);
577 goto out;
578 }
579
580 /* Support for EEPROM bootloader */
581 if (bConfigurationValue == DOWNLOAD_CONF_VALUE ||
582 idProduct & B_DOWNLOAD) {
583 ret = usb_boot(usbdev, bcdDevice);
584 goto out;
585 }
586
587 phy_dev = kmalloc(sizeof(*phy_dev), GFP_KERNEL);
588 if (phy_dev == NULL) {
589 ret = -ENOMEM;
590 goto out;
591 }
592 udev = kmalloc(sizeof(*udev), GFP_KERNEL);
593 if (udev == NULL) {
594 ret = -ENOMEM;
595 goto out;
596 }
597
598 memset(phy_dev, 0, sizeof(*phy_dev));
599 memset(udev, 0, sizeof(*udev));
600
601 if (idProduct == 0x7205 || idProduct == 0x7206)
602 udev->padding = GDM7205_PADDING;
603 else
604 udev->padding = 0;
605
606 phy_dev->priv_dev = (void *)udev;
607 phy_dev->send_func = gdm_usb_send;
608 phy_dev->rcv_func = gdm_usb_receive;
609
610 ret = init_usb(udev);
611 if (ret < 0)
612 goto out;
613
614 udev->usbdev = usbdev;
615
616 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
617 udev->intf = intf;
618
619 intf->needs_remote_wakeup = 1;
620 device_init_wakeup(&intf->dev, 1);
621
622 pm_runtime_set_autosuspend_delay(&usbdev->dev, 10 * 1000); /* msec */
623
624 INIT_WORK(&udev->pm_ws, do_pm_control);
625 #endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
626
627 ret = register_wimax_device(phy_dev);
628
629 out:
630 if (ret) {
631 kfree(phy_dev);
632 kfree(udev);
633 }
634 usb_set_intfdata(intf, phy_dev);
635 return ret;
636 }
637
638 static void gdm_usb_disconnect(struct usb_interface *intf)
639 {
640 u8 bConfigurationValue;
641 struct phy_dev *phy_dev;
642 struct usbwm_dev *udev;
643 u16 idProduct;
644 struct usb_device *usbdev = interface_to_usbdev(intf);
645
646 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
647 phy_dev = usb_get_intfdata(intf);
648
649 /*USB description is set up with Little-Endian*/
650 idProduct = L2H(usbdev->descriptor.idProduct);
651
652 if (idProduct != EMERGENCY_PID &&
653 bConfigurationValue != DOWNLOAD_CONF_VALUE &&
654 (idProduct & B_DOWNLOAD) == 0) {
655 udev = phy_dev->priv_dev;
656 udev->usbdev = NULL;
657
658 unregister_wimax_device(phy_dev);
659 release_usb(udev);
660 kfree(udev);
661 kfree(phy_dev);
662 }
663
664 usb_put_dev(usbdev);
665 }
666
667 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
668 static int gdm_suspend(struct usb_interface *intf, pm_message_t pm_msg)
669 {
670 struct phy_dev *phy_dev;
671 struct usbwm_dev *udev;
672 struct rx_cxt *rx;
673 struct usb_rx *r;
674
675 phy_dev = usb_get_intfdata(intf);
676 udev = phy_dev->priv_dev;
677 rx = &udev->rx;
678
679 list_for_each_entry(r, &rx->used_list, list)
680 usb_unlink_urb(r->urb);
681
682 return 0;
683 }
684
685 static int gdm_resume(struct usb_interface *intf)
686 {
687 struct phy_dev *phy_dev;
688 struct usbwm_dev *udev;
689 struct rx_cxt *rx;
690 struct usb_rx *r;
691
692 phy_dev = usb_get_intfdata(intf);
693 udev = phy_dev->priv_dev;
694 rx = &udev->rx;
695
696 list_for_each_entry(r, &rx->used_list, list)
697 usb_submit_urb(r->urb, GFP_ATOMIC);
698
699 return 0;
700 }
701
702 #endif /* CONFIG_WIMAX_GDM72XX_USB_PM */
703
704 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
705 static int k_mode_thread(void *arg)
706 {
707 struct usbwm_dev *udev;
708 struct tx_cxt *tx;
709 struct rx_cxt *rx;
710 struct usb_tx *t, *temp;
711 struct usb_rx *r;
712 unsigned long flags, flags2, expire;
713 int ret;
714
715 daemonize("k_mode_wimax");
716
717 while (!k_mode_stop) {
718
719 spin_lock_irqsave(&k_lock, flags2);
720 while (!list_empty(&k_list)) {
721
722 udev = list_entry(k_list.next, struct usbwm_dev, list);
723 tx = &udev->tx;
724 rx = &udev->rx;
725
726 list_del(&udev->list);
727 spin_unlock_irqrestore(&k_lock, flags2);
728
729 expire = jiffies + K_WAIT_TIME;
730 while (jiffies < expire)
731 schedule_timeout(K_WAIT_TIME);
732
733 list_for_each_entry(r, &rx->used_list, list)
734 usb_submit_urb(r->urb, GFP_ATOMIC);
735
736 spin_lock_irqsave(&tx->lock, flags);
737
738 list_for_each_entry_safe(t, temp, &tx->pending_list,
739 p_list) {
740 list_del(&t->p_list);
741 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
742
743 if (ret) {
744 t->callback = NULL;
745 gdm_usb_send_complete(t->urb);
746 }
747 }
748
749 udev->bw_switch = 0;
750 spin_unlock_irqrestore(&tx->lock, flags);
751
752 spin_lock_irqsave(&k_lock, flags2);
753 }
754 spin_unlock_irqrestore(&k_lock, flags2);
755
756 interruptible_sleep_on(&k_wait);
757 }
758 return 0;
759 }
760 #endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
761
762 static struct usb_driver gdm_usb_driver = {
763 .name = "gdm_wimax",
764 .probe = gdm_usb_probe,
765 .disconnect = gdm_usb_disconnect,
766 .id_table = id_table,
767 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
768 .supports_autosuspend = 1,
769 .suspend = gdm_suspend,
770 .resume = gdm_resume,
771 .reset_resume = gdm_resume,
772 #endif
773 };
774
775 static int __init usb_gdm_wimax_init(void)
776 {
777 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
778 kernel_thread(k_mode_thread, NULL, CLONE_KERNEL);
779 #endif /* CONFIG_WIMAX_GDM72XX_K_MODE */
780 return usb_register(&gdm_usb_driver);
781 }
782
783 static void __exit usb_gdm_wimax_exit(void)
784 {
785 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
786 k_mode_stop = 1;
787 wake_up(&k_wait);
788 #endif
789 usb_deregister(&gdm_usb_driver);
790 }
791
792 module_init(usb_gdm_wimax_init);
793 module_exit(usb_gdm_wimax_exit);
794
795 MODULE_VERSION(DRIVER_VERSION);
796 MODULE_DESCRIPTION("GCT WiMax Device Driver");
797 MODULE_AUTHOR("Ethan Park");
798 MODULE_LICENSE("GPL");
This page took 0.066334 seconds and 5 git commands to generate.