2 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
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.
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.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/usb.h>
19 #include <linux/sched.h>
20 #include <linux/kthread.h>
21 #include <linux/usb/cdc.h>
22 #include <linux/wait.h>
23 #include <linux/if_ether.h>
24 #include <linux/pm_runtime.h>
29 #include "hci_packet.h"
30 #include "gdm_endian.h"
32 #define USB_DEVICE_CDC_DATA(vid, pid) \
33 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS,\
36 .bInterfaceClass = USB_CLASS_COMM,\
37 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET
39 #define USB_DEVICE_MASS_DATA(vid, pid) \
40 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO,\
43 .bInterfaceSubClass = USB_SC_SCSI, \
44 .bInterfaceClass = USB_CLASS_MASS_STORAGE,\
45 .bInterfaceProtocol = USB_PR_BULK
47 static const struct usb_device_id id_table
[] = {
48 { USB_DEVICE_CDC_DATA(VID_GCT
, PID_GDM7240
) }, /* GCT GDM7240 */
49 { USB_DEVICE_CDC_DATA(VID_GCT
, PID_GDM7243
) }, /* GCT GDM7243 */
53 MODULE_DEVICE_TABLE(usb
, id_table
);
55 static struct workqueue_struct
*usb_tx_wq
;
56 static struct workqueue_struct
*usb_rx_wq
;
58 static void do_tx(struct work_struct
*work
);
59 static void do_rx(struct work_struct
*work
);
61 static int gdm_usb_recv(void *priv_dev
,
62 int (*cb
)(void *cb_data
, void *data
, int len
, int context
),
66 static int request_mac_address(struct lte_udev
*udev
)
69 struct hci_packet
*hci
= (struct hci_packet
*)buf
;
70 struct usb_device
*usbdev
= udev
->usbdev
;
74 hci
->cmd_evt
= gdm_cpu_to_dev16(&udev
->gdm_ed
, LTE_GET_INFORMATION
);
75 hci
->len
= gdm_cpu_to_dev16(&udev
->gdm_ed
, 1);
76 hci
->data
[0] = MAC_ADDRESS
;
78 ret
= usb_bulk_msg(usbdev
, usb_sndbulkpipe(usbdev
, 2), buf
, 5,
81 udev
->request_mac_addr
= 1;
86 static struct usb_tx
*alloc_tx_struct(int len
)
88 struct usb_tx
*t
= NULL
;
91 t
= kzalloc(sizeof(struct usb_tx
), GFP_ATOMIC
);
97 t
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
101 t
->buf
= kmalloc(len
, GFP_ATOMIC
);
102 if (!t
->urb
|| !t
->buf
) {
110 usb_free_urb(t
->urb
);
120 static struct usb_tx_sdu
*alloc_tx_sdu_struct(void)
122 struct usb_tx_sdu
*t_sdu
= NULL
;
126 t_sdu
= kzalloc(sizeof(struct usb_tx_sdu
), GFP_ATOMIC
);
132 t_sdu
->buf
= kmalloc(SDU_BUF_SIZE
, GFP_ATOMIC
);
150 static void free_tx_struct(struct usb_tx
*t
)
153 usb_free_urb(t
->urb
);
159 static void free_tx_sdu_struct(struct usb_tx_sdu
*t_sdu
)
167 static struct usb_tx_sdu
*get_tx_sdu_struct(struct tx_cxt
*tx
, int *no_spc
)
169 struct usb_tx_sdu
*t_sdu
;
171 if (list_empty(&tx
->free_list
))
174 t_sdu
= list_entry(tx
->free_list
.next
, struct usb_tx_sdu
, list
);
175 list_del(&t_sdu
->list
);
179 *no_spc
= list_empty(&tx
->free_list
) ? 1 : 0;
184 static void put_tx_struct(struct tx_cxt
*tx
, struct usb_tx_sdu
*t_sdu
)
186 list_add_tail(&t_sdu
->list
, &tx
->free_list
);
190 static struct usb_rx
*alloc_rx_struct(void)
192 struct usb_rx
*r
= NULL
;
195 r
= kmalloc(sizeof(struct usb_rx
), GFP_ATOMIC
);
201 r
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
202 r
->buf
= kmalloc(RX_BUF_SIZE
, GFP_ATOMIC
);
203 if (!r
->urb
|| !r
->buf
) {
211 usb_free_urb(r
->urb
);
221 static void free_rx_struct(struct usb_rx
*r
)
224 usb_free_urb(r
->urb
);
230 static struct usb_rx
*get_rx_struct(struct rx_cxt
*rx
, int *no_spc
)
235 spin_lock_irqsave(&rx
->rx_lock
, flags
);
237 if (list_empty(&rx
->free_list
)) {
238 spin_unlock_irqrestore(&rx
->rx_lock
, flags
);
242 r
= list_entry(rx
->free_list
.next
, struct usb_rx
, free_list
);
243 list_del(&r
->free_list
);
247 *no_spc
= list_empty(&rx
->free_list
) ? 1 : 0;
249 spin_unlock_irqrestore(&rx
->rx_lock
, flags
);
254 static void put_rx_struct(struct rx_cxt
*rx
, struct usb_rx
*r
)
258 spin_lock_irqsave(&rx
->rx_lock
, flags
);
260 list_add_tail(&r
->free_list
, &rx
->free_list
);
263 spin_unlock_irqrestore(&rx
->rx_lock
, flags
);
266 static void release_usb(struct lte_udev
*udev
)
268 struct rx_cxt
*rx
= &udev
->rx
;
269 struct tx_cxt
*tx
= &udev
->tx
;
270 struct usb_tx
*t
, *t_next
;
271 struct usb_rx
*r
, *r_next
;
272 struct usb_tx_sdu
*t_sdu
, *t_sdu_next
;
275 spin_lock_irqsave(&tx
->lock
, flags
);
276 list_for_each_entry_safe(t_sdu
, t_sdu_next
, &tx
->sdu_list
, list
)
278 list_del(&t_sdu
->list
);
279 free_tx_sdu_struct(t_sdu
);
282 list_for_each_entry_safe(t
, t_next
, &tx
->hci_list
, list
)
288 list_for_each_entry_safe(t_sdu
, t_sdu_next
, &tx
->free_list
, list
)
290 list_del(&t_sdu
->list
);
291 free_tx_sdu_struct(t_sdu
);
293 spin_unlock_irqrestore(&tx
->lock
, flags
);
295 spin_lock_irqsave(&rx
->submit_lock
, flags
);
296 list_for_each_entry_safe(r
, r_next
, &rx
->rx_submit_list
, rx_submit_list
)
298 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
299 usb_kill_urb(r
->urb
);
300 spin_lock_irqsave(&rx
->submit_lock
, flags
);
302 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
304 spin_lock_irqsave(&rx
->rx_lock
, flags
);
305 list_for_each_entry_safe(r
, r_next
, &rx
->free_list
, free_list
)
307 list_del(&r
->free_list
);
310 spin_unlock_irqrestore(&rx
->rx_lock
, flags
);
312 spin_lock_irqsave(&rx
->to_host_lock
, flags
);
313 list_for_each_entry_safe(r
, r_next
, &rx
->to_host_list
, to_host_list
)
315 if (r
->index
== (void *)udev
) {
316 list_del(&r
->to_host_list
);
320 spin_unlock_irqrestore(&rx
->to_host_lock
, flags
);
323 static int init_usb(struct lte_udev
*udev
)
327 struct tx_cxt
*tx
= &udev
->tx
;
328 struct rx_cxt
*rx
= &udev
->rx
;
329 struct usb_tx_sdu
*t_sdu
= NULL
;
330 struct usb_rx
*r
= NULL
;
332 udev
->send_complete
= 1;
334 udev
->request_mac_addr
= 0;
335 udev
->usb_state
= PM_NORMAL
;
337 INIT_LIST_HEAD(&tx
->sdu_list
);
338 INIT_LIST_HEAD(&tx
->hci_list
);
339 INIT_LIST_HEAD(&tx
->free_list
);
340 INIT_LIST_HEAD(&rx
->rx_submit_list
);
341 INIT_LIST_HEAD(&rx
->free_list
);
342 INIT_LIST_HEAD(&rx
->to_host_list
);
343 spin_lock_init(&tx
->lock
);
344 spin_lock_init(&rx
->rx_lock
);
345 spin_lock_init(&rx
->submit_lock
);
346 spin_lock_init(&rx
->to_host_lock
);
353 for (i
= 0; i
< MAX_NUM_SDU_BUF
; i
++) {
354 t_sdu
= alloc_tx_sdu_struct();
360 list_add(&t_sdu
->list
, &tx
->free_list
);
364 for (i
= 0; i
< MAX_RX_SUBMIT_COUNT
*2; i
++) {
365 r
= alloc_rx_struct();
371 list_add(&r
->free_list
, &rx
->free_list
);
374 INIT_DELAYED_WORK(&udev
->work_tx
, do_tx
);
375 INIT_DELAYED_WORK(&udev
->work_rx
, do_rx
);
381 static int set_mac_address(u8
*data
, void *arg
)
383 struct phy_dev
*phy_dev
= (struct phy_dev
*)arg
;
384 struct lte_udev
*udev
= phy_dev
->priv_dev
;
385 struct tlv
*tlv
= (struct tlv
*)data
;
386 u8 mac_address
[ETH_ALEN
] = {0, };
388 if (tlv
->type
== MAC_ADDRESS
&& udev
->request_mac_addr
) {
389 memcpy(mac_address
, tlv
->data
, tlv
->len
);
391 if (register_lte_device(phy_dev
, &udev
->intf
->dev
, mac_address
) < 0)
392 pr_err("register lte device failed\n");
394 udev
->request_mac_addr
= 0;
402 static void do_rx(struct work_struct
*work
)
404 struct lte_udev
*udev
= container_of(work
, struct lte_udev
, work_rx
.work
);
405 struct rx_cxt
*rx
= &udev
->rx
;
407 struct hci_packet
*hci
;
408 struct phy_dev
*phy_dev
;
414 spin_lock_irqsave(&rx
->to_host_lock
, flags
);
415 if (list_empty(&rx
->to_host_list
)) {
416 spin_unlock_irqrestore(&rx
->to_host_lock
, flags
);
419 r
= list_entry(rx
->to_host_list
.next
, struct usb_rx
, to_host_list
);
420 list_del(&r
->to_host_list
);
421 spin_unlock_irqrestore(&rx
->to_host_lock
, flags
);
423 phy_dev
= (struct phy_dev
*)r
->cb_data
;
424 udev
= (struct lte_udev
*)phy_dev
->priv_dev
;
425 hci
= (struct hci_packet
*)r
->buf
;
426 cmd_evt
= gdm_dev16_to_cpu(&udev
->gdm_ed
, hci
->cmd_evt
);
429 case LTE_GET_INFORMATION_RESULT
:
430 if (set_mac_address(hci
->data
, r
->cb_data
) == 0) {
431 ret
= r
->callback(r
->cb_data
,
433 r
->urb
->actual_length
,
440 ret
= r
->callback(r
->cb_data
,
442 r
->urb
->actual_length
,
446 pr_err("failed to send received data\n");
451 put_rx_struct(rx
, r
);
460 static void remove_rx_submit_list(struct usb_rx
*r
, struct rx_cxt
*rx
)
463 struct usb_rx
*r_remove
, *r_remove_next
;
465 spin_lock_irqsave(&rx
->submit_lock
, flags
);
466 list_for_each_entry_safe(r_remove
, r_remove_next
, &rx
->rx_submit_list
, rx_submit_list
)
469 list_del(&r
->rx_submit_list
);
473 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
476 static void gdm_usb_rcv_complete(struct urb
*urb
)
478 struct usb_rx
*r
= urb
->context
;
479 struct rx_cxt
*rx
= r
->rx
;
481 struct lte_udev
*udev
= container_of(r
->rx
, struct lte_udev
, rx
);
482 struct usb_device
*usbdev
= udev
->usbdev
;
484 remove_rx_submit_list(r
, rx
);
486 if (!urb
->status
&& r
->callback
) {
487 spin_lock_irqsave(&rx
->to_host_lock
, flags
);
488 list_add_tail(&r
->to_host_list
, &rx
->to_host_list
);
489 queue_work(usb_rx_wq
, &udev
->work_rx
.work
);
490 spin_unlock_irqrestore(&rx
->to_host_lock
, flags
);
492 if (urb
->status
&& udev
->usb_state
== PM_NORMAL
)
493 pr_err("%s: urb status error %d\n",
494 __func__
, urb
->status
);
496 put_rx_struct(rx
, r
);
499 usb_mark_last_busy(usbdev
);
502 static int gdm_usb_recv(void *priv_dev
,
503 int (*cb
)(void *cb_data
, void *data
, int len
, int context
),
507 struct lte_udev
*udev
= priv_dev
;
508 struct usb_device
*usbdev
= udev
->usbdev
;
509 struct rx_cxt
*rx
= &udev
->rx
;
516 pr_err("invalid device\n");
520 r
= get_rx_struct(rx
, &no_spc
);
522 pr_err("Out of Memory\n");
528 r
->cb_data
= cb_data
;
529 r
->index
= (void *)udev
;
532 usb_fill_bulk_urb(r
->urb
,
534 usb_rcvbulkpipe(usbdev
, 0x83),
537 gdm_usb_rcv_complete
,
540 spin_lock_irqsave(&rx
->submit_lock
, flags
);
541 list_add_tail(&r
->rx_submit_list
, &rx
->rx_submit_list
);
542 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
544 if (context
== KERNEL_THREAD
)
545 ret
= usb_submit_urb(r
->urb
, GFP_KERNEL
);
547 ret
= usb_submit_urb(r
->urb
, GFP_ATOMIC
);
550 spin_lock_irqsave(&rx
->submit_lock
, flags
);
551 list_del(&r
->rx_submit_list
);
552 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
554 pr_err("usb_submit_urb failed (%p)\n", r
);
555 put_rx_struct(rx
, r
);
561 static void gdm_usb_send_complete(struct urb
*urb
)
563 struct usb_tx
*t
= urb
->context
;
564 struct tx_cxt
*tx
= t
->tx
;
565 struct lte_udev
*udev
= container_of(tx
, struct lte_udev
, tx
);
568 if (urb
->status
== -ECONNRESET
) {
569 pr_info("CONNRESET\n");
574 t
->callback(t
->cb_data
);
578 spin_lock_irqsave(&tx
->lock
, flags
);
579 udev
->send_complete
= 1;
580 queue_work(usb_tx_wq
, &udev
->work_tx
.work
);
581 spin_unlock_irqrestore(&tx
->lock
, flags
);
584 static int send_tx_packet(struct usb_device
*usbdev
, struct usb_tx
*t
, u32 len
)
591 usb_fill_bulk_urb(t
->urb
,
593 usb_sndbulkpipe(usbdev
, 2),
596 gdm_usb_send_complete
,
599 ret
= usb_submit_urb(t
->urb
, GFP_ATOMIC
);
602 pr_err("usb_submit_urb failed: %d\n", ret
);
604 usb_mark_last_busy(usbdev
);
609 static u32
packet_aggregation(struct lte_udev
*udev
, u8
*send_buf
)
611 struct tx_cxt
*tx
= &udev
->tx
;
612 struct usb_tx_sdu
*t_sdu
= NULL
;
613 struct multi_sdu
*multi_sdu
= (struct multi_sdu
*)send_buf
;
618 multi_sdu
->cmd_evt
= gdm_cpu_to_dev16(&udev
->gdm_ed
, LTE_TX_MULTI_SDU
);
620 while (num_packet
< MAX_PACKET_IN_MULTI_SDU
) {
621 spin_lock_irqsave(&tx
->lock
, flags
);
622 if (list_empty(&tx
->sdu_list
)) {
623 spin_unlock_irqrestore(&tx
->lock
, flags
);
627 t_sdu
= list_entry(tx
->sdu_list
.next
, struct usb_tx_sdu
, list
);
628 if (send_len
+ t_sdu
->len
> MAX_SDU_SIZE
) {
629 spin_unlock_irqrestore(&tx
->lock
, flags
);
633 list_del(&t_sdu
->list
);
634 spin_unlock_irqrestore(&tx
->lock
, flags
);
636 memcpy(multi_sdu
->data
+ send_len
, t_sdu
->buf
, t_sdu
->len
);
638 send_len
+= (t_sdu
->len
+ 3) & 0xfffc;
641 if (tx
->avail_count
> 10)
642 t_sdu
->callback(t_sdu
->cb_data
);
644 spin_lock_irqsave(&tx
->lock
, flags
);
645 put_tx_struct(tx
, t_sdu
);
646 spin_unlock_irqrestore(&tx
->lock
, flags
);
649 multi_sdu
->len
= gdm_cpu_to_dev16(&udev
->gdm_ed
, send_len
);
650 multi_sdu
->num_packet
= gdm_cpu_to_dev16(&udev
->gdm_ed
, num_packet
);
652 return send_len
+ offsetof(struct multi_sdu
, data
);
655 static void do_tx(struct work_struct
*work
)
657 struct lte_udev
*udev
= container_of(work
, struct lte_udev
, work_tx
.work
);
658 struct usb_device
*usbdev
= udev
->usbdev
;
659 struct tx_cxt
*tx
= &udev
->tx
;
660 struct usb_tx
*t
= NULL
;
665 if (!usb_autopm_get_interface(udev
->intf
))
666 usb_autopm_put_interface(udev
->intf
);
668 if (udev
->usb_state
== PM_SUSPEND
)
671 spin_lock_irqsave(&tx
->lock
, flags
);
672 if (!udev
->send_complete
) {
673 spin_unlock_irqrestore(&tx
->lock
, flags
);
676 udev
->send_complete
= 0;
679 if (!list_empty(&tx
->hci_list
)) {
680 t
= list_entry(tx
->hci_list
.next
, struct usb_tx
, list
);
685 } else if (!list_empty(&tx
->sdu_list
)) {
687 udev
->send_complete
= 1;
688 spin_unlock_irqrestore(&tx
->lock
, flags
);
692 t
= alloc_tx_struct(TX_BUF_SIZE
);
700 udev
->send_complete
= 1;
701 spin_unlock_irqrestore(&tx
->lock
, flags
);
704 spin_unlock_irqrestore(&tx
->lock
, flags
);
707 len
= packet_aggregation(udev
, t
->buf
);
709 if (send_tx_packet(usbdev
, t
, len
)) {
710 pr_err("send_tx_packet failed\n");
712 gdm_usb_send_complete(t
->urb
);
716 #define SDU_PARAM_LEN 12
717 static int gdm_usb_sdu_send(void *priv_dev
, void *data
, int len
,
718 unsigned int dftEpsId
, unsigned int epsId
,
719 void (*cb
)(void *data
), void *cb_data
,
720 int dev_idx
, int nic_type
)
722 struct lte_udev
*udev
= priv_dev
;
723 struct tx_cxt
*tx
= &udev
->tx
;
724 struct usb_tx_sdu
*t_sdu
;
725 struct sdu
*sdu
= NULL
;
731 pr_err("sdu send - invalid device\n");
735 spin_lock_irqsave(&tx
->lock
, flags
);
736 t_sdu
= get_tx_sdu_struct(tx
, &no_spc
);
737 spin_unlock_irqrestore(&tx
->lock
, flags
);
740 pr_err("sdu send - free list empty\n");
744 sdu
= (struct sdu
*)t_sdu
->buf
;
745 sdu
->cmd_evt
= gdm_cpu_to_dev16(&udev
->gdm_ed
, LTE_TX_SDU
);
746 if (nic_type
== NIC_TYPE_ARP
) {
747 send_len
= len
+ SDU_PARAM_LEN
;
748 memcpy(sdu
->data
, data
, len
);
750 send_len
= len
- ETH_HLEN
;
751 send_len
+= SDU_PARAM_LEN
;
752 memcpy(sdu
->data
, data
+ETH_HLEN
, len
-ETH_HLEN
);
755 sdu
->len
= gdm_cpu_to_dev16(&udev
->gdm_ed
, send_len
);
756 sdu
->dftEpsId
= gdm_cpu_to_dev32(&udev
->gdm_ed
, dftEpsId
);
757 sdu
->bearer_ID
= gdm_cpu_to_dev32(&udev
->gdm_ed
, epsId
);
758 sdu
->nic_type
= gdm_cpu_to_dev32(&udev
->gdm_ed
, nic_type
);
760 t_sdu
->len
= send_len
+ HCI_HEADER_SIZE
;
761 t_sdu
->callback
= cb
;
762 t_sdu
->cb_data
= cb_data
;
764 spin_lock_irqsave(&tx
->lock
, flags
);
765 list_add_tail(&t_sdu
->list
, &tx
->sdu_list
);
766 queue_work(usb_tx_wq
, &udev
->work_tx
.work
);
767 spin_unlock_irqrestore(&tx
->lock
, flags
);
775 static int gdm_usb_hci_send(void *priv_dev
, void *data
, int len
,
776 void (*cb
)(void *data
), void *cb_data
)
778 struct lte_udev
*udev
= priv_dev
;
779 struct tx_cxt
*tx
= &udev
->tx
;
784 pr_err("hci send - invalid device\n");
788 t
= alloc_tx_struct(len
);
790 pr_err("hci_send - out of memory\n");
794 memcpy(t
->buf
, data
, len
);
796 t
->cb_data
= cb_data
;
801 spin_lock_irqsave(&tx
->lock
, flags
);
802 list_add_tail(&t
->list
, &tx
->hci_list
);
803 queue_work(usb_tx_wq
, &udev
->work_tx
.work
);
804 spin_unlock_irqrestore(&tx
->lock
, flags
);
809 static struct gdm_endian
*gdm_usb_get_endian(void *priv_dev
)
811 struct lte_udev
*udev
= priv_dev
;
813 return &udev
->gdm_ed
;
816 static int gdm_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
819 struct phy_dev
*phy_dev
= NULL
;
820 struct lte_udev
*udev
= NULL
;
821 u16 idVendor
, idProduct
;
822 int bInterfaceNumber
;
823 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
825 bInterfaceNumber
= intf
->cur_altsetting
->desc
.bInterfaceNumber
;
826 idVendor
= __le16_to_cpu(usbdev
->descriptor
.idVendor
);
827 idProduct
= __le16_to_cpu(usbdev
->descriptor
.idProduct
);
829 pr_info("net vid = 0x%04x pid = 0x%04x\n", idVendor
, idProduct
);
831 if (bInterfaceNumber
> NETWORK_INTERFACE
) {
832 pr_info("not a network device\n");
836 phy_dev
= kmalloc(sizeof(struct phy_dev
), GFP_ATOMIC
);
842 udev
= kmalloc(sizeof(struct lte_udev
), GFP_ATOMIC
);
848 memset(phy_dev
, 0, sizeof(struct phy_dev
));
849 memset(udev
, 0, sizeof(struct lte_udev
));
851 phy_dev
->priv_dev
= (void *)udev
;
852 phy_dev
->send_hci_func
= gdm_usb_hci_send
;
853 phy_dev
->send_sdu_func
= gdm_usb_sdu_send
;
854 phy_dev
->rcv_func
= gdm_usb_recv
;
855 phy_dev
->get_endian
= gdm_usb_get_endian
;
857 udev
->usbdev
= usbdev
;
858 ret
= init_usb(udev
);
860 pr_err("init_usb func failed\n");
865 intf
->needs_remote_wakeup
= 1;
866 usb_enable_autosuspend(usbdev
);
867 pm_runtime_set_autosuspend_delay(&usbdev
->dev
, AUTO_SUSPEND_TIMER
);
869 /* List up hosts with big endians, otherwise, defaults to little endian */
870 if (idProduct
== PID_GDM7243
)
871 gdm_set_endian(&udev
->gdm_ed
, ENDIANNESS_BIG
);
873 gdm_set_endian(&udev
->gdm_ed
, ENDIANNESS_LITTLE
);
875 ret
= request_mac_address(udev
);
877 pr_err("request Mac address failed\n");
881 start_rx_proc(phy_dev
);
893 usb_set_intfdata(intf
, phy_dev
);
898 static void gdm_usb_disconnect(struct usb_interface
*intf
)
900 struct phy_dev
*phy_dev
;
901 struct lte_udev
*udev
;
902 u16 idVendor
, idProduct
;
903 struct usb_device
*usbdev
;
904 usbdev
= interface_to_usbdev(intf
);
906 idVendor
= __le16_to_cpu(usbdev
->descriptor
.idVendor
);
907 idProduct
= __le16_to_cpu(usbdev
->descriptor
.idProduct
);
909 phy_dev
= usb_get_intfdata(intf
);
911 udev
= phy_dev
->priv_dev
;
912 unregister_lte_device(phy_dev
);
925 static int gdm_usb_suspend(struct usb_interface
*intf
, pm_message_t pm_msg
)
927 struct phy_dev
*phy_dev
;
928 struct lte_udev
*udev
;
931 struct usb_rx
*r_next
;
934 phy_dev
= usb_get_intfdata(intf
);
935 udev
= phy_dev
->priv_dev
;
937 if (udev
->usb_state
!= PM_NORMAL
) {
938 pr_err("usb suspend - invalid state\n");
942 udev
->usb_state
= PM_SUSPEND
;
944 spin_lock_irqsave(&rx
->submit_lock
, flags
);
945 list_for_each_entry_safe(r
, r_next
, &rx
->rx_submit_list
, rx_submit_list
)
947 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
948 usb_kill_urb(r
->urb
);
949 spin_lock_irqsave(&rx
->submit_lock
, flags
);
951 spin_unlock_irqrestore(&rx
->submit_lock
, flags
);
956 static int gdm_usb_resume(struct usb_interface
*intf
)
958 struct phy_dev
*phy_dev
;
959 struct lte_udev
*udev
;
966 phy_dev
= usb_get_intfdata(intf
);
967 udev
= phy_dev
->priv_dev
;
970 if (udev
->usb_state
!= PM_SUSPEND
) {
971 pr_err("usb resume - invalid state\n");
974 udev
->usb_state
= PM_NORMAL
;
976 spin_lock_irqsave(&rx
->rx_lock
, flags
);
977 issue_count
= rx
->avail_count
- MAX_RX_SUBMIT_COUNT
;
978 spin_unlock_irqrestore(&rx
->rx_lock
, flags
);
980 if (issue_count
>= 0) {
981 for (i
= 0; i
< issue_count
; i
++)
982 gdm_usb_recv(phy_dev
->priv_dev
,
989 spin_lock_irqsave(&tx
->lock
, flags
);
990 queue_work(usb_tx_wq
, &udev
->work_tx
.work
);
991 spin_unlock_irqrestore(&tx
->lock
, flags
);
996 static struct usb_driver gdm_usb_lte_driver
= {
998 .probe
= gdm_usb_probe
,
999 .disconnect
= gdm_usb_disconnect
,
1000 .id_table
= id_table
,
1001 .supports_autosuspend
= 1,
1002 .suspend
= gdm_usb_suspend
,
1003 .resume
= gdm_usb_resume
,
1004 .reset_resume
= gdm_usb_resume
,
1007 static int __init
gdm_usb_lte_init(void)
1009 if (gdm_lte_event_init() < 0) {
1010 pr_err("error creating event\n");
1014 usb_tx_wq
= create_workqueue("usb_tx_wq");
1015 if (usb_tx_wq
== NULL
)
1018 usb_rx_wq
= create_workqueue("usb_rx_wq");
1019 if (usb_rx_wq
== NULL
)
1022 return usb_register(&gdm_usb_lte_driver
);
1025 static void __exit
gdm_usb_lte_exit(void)
1027 gdm_lte_event_exit();
1029 usb_deregister(&gdm_usb_lte_driver
);
1032 flush_workqueue(usb_tx_wq
);
1033 destroy_workqueue(usb_tx_wq
);
1037 flush_workqueue(usb_rx_wq
);
1038 destroy_workqueue(usb_rx_wq
);
1042 module_init(gdm_usb_lte_init
);
1043 module_exit(gdm_usb_lte_exit
);
1045 MODULE_VERSION(DRIVER_VERSION
);
1046 MODULE_DESCRIPTION("GCT LTE USB Device Driver");
1047 MODULE_LICENSE("GPL");