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 | \
34 USB_DEVICE_ID_MATCH_INT_CLASS | \
35 USB_DEVICE_ID_MATCH_INT_SUBCLASS,\
38 .bInterfaceClass = USB_CLASS_COMM,\
39 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET
41 #define USB_DEVICE_MASS_DATA(vid, pid) \
42 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
43 USB_DEVICE_ID_MATCH_INT_INFO,\
46 .bInterfaceSubClass = USB_SC_SCSI, \
47 .bInterfaceClass = USB_CLASS_MASS_STORAGE,\
48 .bInterfaceProtocol = USB_PR_BULK
50 static const struct usb_device_id id_table[] = {
51 { USB_DEVICE_CDC_DATA(VID_GCT, PID_GDM7240) }, /* GCT GDM7240 */
52 { USB_DEVICE_CDC_DATA(VID_GCT, PID_GDM7243) }, /* GCT GDM7243 */
56 MODULE_DEVICE_TABLE(usb, id_table);
58 static struct workqueue_struct *usb_tx_wq;
59 static struct workqueue_struct *usb_rx_wq;
61 static void do_tx(struct work_struct *work);
62 static void do_rx(struct work_struct *work);
64 static int gdm_usb_recv(void *priv_dev,
65 int (*cb)(void *cb_data,
66 void *data, int len, int context),
70 static int request_mac_address(struct lte_udev *udev)
73 struct hci_packet *hci = (struct hci_packet *)buf;
74 struct usb_device *usbdev = udev->usbdev;
78 hci->cmd_evt = gdm_cpu_to_dev16(&udev->gdm_ed, LTE_GET_INFORMATION);
79 hci->len = gdm_cpu_to_dev16(&udev->gdm_ed, 1);
80 hci->data[0] = MAC_ADDRESS;
82 ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
85 udev->request_mac_addr = 1;
90 static struct usb_tx *alloc_tx_struct(int len)
92 struct usb_tx *t = NULL;
95 t = kzalloc(sizeof(*t), GFP_ATOMIC);
101 t->urb = usb_alloc_urb(0, GFP_ATOMIC);
105 t->buf = kmalloc(len, GFP_ATOMIC);
106 if (!t->urb || !t->buf) {
114 usb_free_urb(t->urb);
124 static struct usb_tx_sdu *alloc_tx_sdu_struct(void)
126 struct usb_tx_sdu *t_sdu;
128 t_sdu = kzalloc(sizeof(*t_sdu), GFP_KERNEL);
132 t_sdu->buf = kmalloc(SDU_BUF_SIZE, GFP_KERNEL);
141 static void free_tx_struct(struct usb_tx *t)
144 usb_free_urb(t->urb);
150 static void free_tx_sdu_struct(struct usb_tx_sdu *t_sdu)
158 static struct usb_tx_sdu *get_tx_sdu_struct(struct tx_cxt *tx, int *no_spc)
160 struct usb_tx_sdu *t_sdu;
162 if (list_empty(&tx->free_list))
165 t_sdu = list_entry(tx->free_list.next, struct usb_tx_sdu, list);
166 list_del(&t_sdu->list);
170 *no_spc = list_empty(&tx->free_list) ? 1 : 0;
175 static void put_tx_struct(struct tx_cxt *tx, struct usb_tx_sdu *t_sdu)
177 list_add_tail(&t_sdu->list, &tx->free_list);
181 static struct usb_rx *alloc_rx_struct(void)
183 struct usb_rx *r = NULL;
186 r = kmalloc(sizeof(*r), GFP_KERNEL);
192 r->urb = usb_alloc_urb(0, GFP_KERNEL);
193 r->buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
194 if (!r->urb || !r->buf) {
202 usb_free_urb(r->urb);
212 static void free_rx_struct(struct usb_rx *r)
215 usb_free_urb(r->urb);
221 static struct usb_rx *get_rx_struct(struct rx_cxt *rx, int *no_spc)
226 spin_lock_irqsave(&rx->rx_lock, flags);
228 if (list_empty(&rx->free_list)) {
229 spin_unlock_irqrestore(&rx->rx_lock, flags);
233 r = list_entry(rx->free_list.next, struct usb_rx, free_list);
234 list_del(&r->free_list);
238 *no_spc = list_empty(&rx->free_list) ? 1 : 0;
240 spin_unlock_irqrestore(&rx->rx_lock, flags);
245 static void put_rx_struct(struct rx_cxt *rx, struct usb_rx *r)
249 spin_lock_irqsave(&rx->rx_lock, flags);
251 list_add_tail(&r->free_list, &rx->free_list);
254 spin_unlock_irqrestore(&rx->rx_lock, flags);
257 static void release_usb(struct lte_udev *udev)
259 struct rx_cxt *rx = &udev->rx;
260 struct tx_cxt *tx = &udev->tx;
261 struct usb_tx *t, *t_next;
262 struct usb_rx *r, *r_next;
263 struct usb_tx_sdu *t_sdu, *t_sdu_next;
266 spin_lock_irqsave(&tx->lock, flags);
267 list_for_each_entry_safe(t_sdu, t_sdu_next, &tx->sdu_list, list) {
268 list_del(&t_sdu->list);
269 free_tx_sdu_struct(t_sdu);
272 list_for_each_entry_safe(t, t_next, &tx->hci_list, list) {
277 list_for_each_entry_safe(t_sdu, t_sdu_next, &tx->free_list, list) {
278 list_del(&t_sdu->list);
279 free_tx_sdu_struct(t_sdu);
281 spin_unlock_irqrestore(&tx->lock, flags);
283 spin_lock_irqsave(&rx->submit_lock, flags);
284 list_for_each_entry_safe(r, r_next, &rx->rx_submit_list,
286 spin_unlock_irqrestore(&rx->submit_lock, flags);
287 usb_kill_urb(r->urb);
288 spin_lock_irqsave(&rx->submit_lock, flags);
290 spin_unlock_irqrestore(&rx->submit_lock, flags);
292 spin_lock_irqsave(&rx->rx_lock, flags);
293 list_for_each_entry_safe(r, r_next, &rx->free_list, free_list) {
294 list_del(&r->free_list);
297 spin_unlock_irqrestore(&rx->rx_lock, flags);
299 spin_lock_irqsave(&rx->to_host_lock, flags);
300 list_for_each_entry_safe(r, r_next, &rx->to_host_list, to_host_list) {
301 if (r->index == (void *)udev) {
302 list_del(&r->to_host_list);
306 spin_unlock_irqrestore(&rx->to_host_lock, flags);
309 static int init_usb(struct lte_udev *udev)
313 struct tx_cxt *tx = &udev->tx;
314 struct rx_cxt *rx = &udev->rx;
315 struct usb_tx_sdu *t_sdu = NULL;
316 struct usb_rx *r = NULL;
318 udev->send_complete = 1;
320 udev->request_mac_addr = 0;
321 udev->usb_state = PM_NORMAL;
323 INIT_LIST_HEAD(&tx->sdu_list);
324 INIT_LIST_HEAD(&tx->hci_list);
325 INIT_LIST_HEAD(&tx->free_list);
326 INIT_LIST_HEAD(&rx->rx_submit_list);
327 INIT_LIST_HEAD(&rx->free_list);
328 INIT_LIST_HEAD(&rx->to_host_list);
329 spin_lock_init(&tx->lock);
330 spin_lock_init(&rx->rx_lock);
331 spin_lock_init(&rx->submit_lock);
332 spin_lock_init(&rx->to_host_lock);
339 for (i = 0; i < MAX_NUM_SDU_BUF; i++) {
340 t_sdu = alloc_tx_sdu_struct();
346 list_add(&t_sdu->list, &tx->free_list);
350 for (i = 0; i < MAX_RX_SUBMIT_COUNT * 2; i++) {
351 r = alloc_rx_struct();
357 list_add(&r->free_list, &rx->free_list);
360 INIT_DELAYED_WORK(&udev->work_tx, do_tx);
361 INIT_DELAYED_WORK(&udev->work_rx, do_rx);
368 static int set_mac_address(u8 *data, void *arg)
370 struct phy_dev *phy_dev = arg;
371 struct lte_udev *udev = phy_dev->priv_dev;
372 struct tlv *tlv = (struct tlv *)data;
373 u8 mac_address[ETH_ALEN] = {0, };
375 if (tlv->type == MAC_ADDRESS && udev->request_mac_addr) {
376 memcpy(mac_address, tlv->data, tlv->len);
378 if (register_lte_device(phy_dev,
379 &udev->intf->dev, mac_address) < 0)
380 pr_err("register lte device failed\n");
382 udev->request_mac_addr = 0;
390 static void do_rx(struct work_struct *work)
392 struct lte_udev *udev =
393 container_of(work, struct lte_udev, work_rx.work);
394 struct rx_cxt *rx = &udev->rx;
396 struct hci_packet *hci;
397 struct phy_dev *phy_dev;
403 spin_lock_irqsave(&rx->to_host_lock, flags);
404 if (list_empty(&rx->to_host_list)) {
405 spin_unlock_irqrestore(&rx->to_host_lock, flags);
408 r = list_entry(rx->to_host_list.next,
409 struct usb_rx, to_host_list);
410 list_del(&r->to_host_list);
411 spin_unlock_irqrestore(&rx->to_host_lock, flags);
413 phy_dev = r->cb_data;
414 udev = phy_dev->priv_dev;
415 hci = (struct hci_packet *)r->buf;
416 cmd_evt = gdm_dev16_to_cpu(&udev->gdm_ed, hci->cmd_evt);
419 case LTE_GET_INFORMATION_RESULT:
420 if (set_mac_address(hci->data, r->cb_data) == 0) {
421 ret = r->callback(r->cb_data,
423 r->urb->actual_length,
430 ret = r->callback(r->cb_data,
432 r->urb->actual_length,
436 pr_err("failed to send received data\n");
441 put_rx_struct(rx, r);
450 static void remove_rx_submit_list(struct usb_rx *r, struct rx_cxt *rx)
453 struct usb_rx *r_remove, *r_remove_next;
455 spin_lock_irqsave(&rx->submit_lock, flags);
456 list_for_each_entry_safe(r_remove, r_remove_next,
457 &rx->rx_submit_list, rx_submit_list) {
459 list_del(&r->rx_submit_list);
463 spin_unlock_irqrestore(&rx->submit_lock, flags);
466 static void gdm_usb_rcv_complete(struct urb *urb)
468 struct usb_rx *r = urb->context;
469 struct rx_cxt *rx = r->rx;
471 struct lte_udev *udev = container_of(r->rx, struct lte_udev, rx);
472 struct usb_device *usbdev = udev->usbdev;
474 remove_rx_submit_list(r, rx);
476 if (!urb->status && r->callback) {
477 spin_lock_irqsave(&rx->to_host_lock, flags);
478 list_add_tail(&r->to_host_list, &rx->to_host_list);
479 queue_work(usb_rx_wq, &udev->work_rx.work);
480 spin_unlock_irqrestore(&rx->to_host_lock, flags);
482 if (urb->status && udev->usb_state == PM_NORMAL)
483 dev_err(&urb->dev->dev, "%s: urb status error %d\n",
484 __func__, urb->status);
486 put_rx_struct(rx, r);
489 usb_mark_last_busy(usbdev);
492 static int gdm_usb_recv(void *priv_dev,
493 int (*cb)(void *cb_data,
494 void *data, int len, int context),
498 struct lte_udev *udev = priv_dev;
499 struct usb_device *usbdev = udev->usbdev;
500 struct rx_cxt *rx = &udev->rx;
507 pr_err("invalid device\n");
511 r = get_rx_struct(rx, &no_spc);
513 pr_err("Out of Memory\n");
519 r->cb_data = cb_data;
520 r->index = (void *)udev;
523 usb_fill_bulk_urb(r->urb,
525 usb_rcvbulkpipe(usbdev, 0x83),
528 gdm_usb_rcv_complete,
531 spin_lock_irqsave(&rx->submit_lock, flags);
532 list_add_tail(&r->rx_submit_list, &rx->rx_submit_list);
533 spin_unlock_irqrestore(&rx->submit_lock, flags);
535 if (context == KERNEL_THREAD)
536 ret = usb_submit_urb(r->urb, GFP_KERNEL);
538 ret = usb_submit_urb(r->urb, GFP_ATOMIC);
541 spin_lock_irqsave(&rx->submit_lock, flags);
542 list_del(&r->rx_submit_list);
543 spin_unlock_irqrestore(&rx->submit_lock, flags);
545 pr_err("usb_submit_urb failed (%p)\n", r);
546 put_rx_struct(rx, r);
552 static void gdm_usb_send_complete(struct urb *urb)
554 struct usb_tx *t = urb->context;
555 struct tx_cxt *tx = t->tx;
556 struct lte_udev *udev = container_of(tx, struct lte_udev, tx);
559 if (urb->status == -ECONNRESET) {
560 dev_info(&urb->dev->dev, "CONNRESET\n");
565 t->callback(t->cb_data);
569 spin_lock_irqsave(&tx->lock, flags);
570 udev->send_complete = 1;
571 queue_work(usb_tx_wq, &udev->work_tx.work);
572 spin_unlock_irqrestore(&tx->lock, flags);
575 static int send_tx_packet(struct usb_device *usbdev, struct usb_tx *t, u32 len)
582 usb_fill_bulk_urb(t->urb,
584 usb_sndbulkpipe(usbdev, 2),
587 gdm_usb_send_complete,
590 ret = usb_submit_urb(t->urb, GFP_ATOMIC);
593 dev_err(&usbdev->dev, "usb_submit_urb failed: %d\n",
596 usb_mark_last_busy(usbdev);
601 static u32 packet_aggregation(struct lte_udev *udev, u8 *send_buf)
603 struct tx_cxt *tx = &udev->tx;
604 struct usb_tx_sdu *t_sdu = NULL;
605 struct multi_sdu *multi_sdu = (struct multi_sdu *)send_buf;
610 multi_sdu->cmd_evt = gdm_cpu_to_dev16(&udev->gdm_ed, LTE_TX_MULTI_SDU);
612 while (num_packet < MAX_PACKET_IN_MULTI_SDU) {
613 spin_lock_irqsave(&tx->lock, flags);
614 if (list_empty(&tx->sdu_list)) {
615 spin_unlock_irqrestore(&tx->lock, flags);
619 t_sdu = list_entry(tx->sdu_list.next, struct usb_tx_sdu, list);
620 if (send_len + t_sdu->len > MAX_SDU_SIZE) {
621 spin_unlock_irqrestore(&tx->lock, flags);
625 list_del(&t_sdu->list);
626 spin_unlock_irqrestore(&tx->lock, flags);
628 memcpy(multi_sdu->data + send_len, t_sdu->buf, t_sdu->len);
630 send_len += (t_sdu->len + 3) & 0xfffc;
633 if (tx->avail_count > 10)
634 t_sdu->callback(t_sdu->cb_data);
636 spin_lock_irqsave(&tx->lock, flags);
637 put_tx_struct(tx, t_sdu);
638 spin_unlock_irqrestore(&tx->lock, flags);
641 multi_sdu->len = gdm_cpu_to_dev16(&udev->gdm_ed, send_len);
642 multi_sdu->num_packet = gdm_cpu_to_dev16(&udev->gdm_ed, num_packet);
644 return send_len + offsetof(struct multi_sdu, data);
647 static void do_tx(struct work_struct *work)
649 struct lte_udev *udev =
650 container_of(work, struct lte_udev, work_tx.work);
651 struct usb_device *usbdev = udev->usbdev;
652 struct tx_cxt *tx = &udev->tx;
653 struct usb_tx *t = NULL;
658 if (!usb_autopm_get_interface(udev->intf))
659 usb_autopm_put_interface(udev->intf);
661 if (udev->usb_state == PM_SUSPEND)
664 spin_lock_irqsave(&tx->lock, flags);
665 if (!udev->send_complete) {
666 spin_unlock_irqrestore(&tx->lock, flags);
669 udev->send_complete = 0;
671 if (!list_empty(&tx->hci_list)) {
672 t = list_entry(tx->hci_list.next, struct usb_tx, list);
677 } else if (!list_empty(&tx->sdu_list)) {
679 udev->send_complete = 1;
680 spin_unlock_irqrestore(&tx->lock, flags);
684 t = alloc_tx_struct(TX_BUF_SIZE);
686 spin_unlock_irqrestore(&tx->lock, flags);
696 udev->send_complete = 1;
697 spin_unlock_irqrestore(&tx->lock, flags);
700 spin_unlock_irqrestore(&tx->lock, flags);
703 len = packet_aggregation(udev, t->buf);
705 if (send_tx_packet(usbdev, t, len)) {
706 pr_err("send_tx_packet failed\n");
708 gdm_usb_send_complete(t->urb);
712 #define SDU_PARAM_LEN 12
713 static int gdm_usb_sdu_send(void *priv_dev, void *data, int len,
714 unsigned int dftEpsId, unsigned int epsId,
715 void (*cb)(void *data), void *cb_data,
716 int dev_idx, int nic_type)
718 struct lte_udev *udev = priv_dev;
719 struct tx_cxt *tx = &udev->tx;
720 struct usb_tx_sdu *t_sdu;
721 struct sdu *sdu = NULL;
727 pr_err("sdu send - invalid device\n");
731 spin_lock_irqsave(&tx->lock, flags);
732 t_sdu = get_tx_sdu_struct(tx, &no_spc);
733 spin_unlock_irqrestore(&tx->lock, flags);
736 pr_err("sdu send - free list empty\n");
740 sdu = (struct sdu *)t_sdu->buf;
741 sdu->cmd_evt = gdm_cpu_to_dev16(&udev->gdm_ed, LTE_TX_SDU);
742 if (nic_type == NIC_TYPE_ARP) {
743 send_len = len + SDU_PARAM_LEN;
744 memcpy(sdu->data, data, len);
746 send_len = len - ETH_HLEN;
747 send_len += SDU_PARAM_LEN;
748 memcpy(sdu->data, data + ETH_HLEN, len - ETH_HLEN);
751 sdu->len = gdm_cpu_to_dev16(&udev->gdm_ed, send_len);
752 sdu->dftEpsId = gdm_cpu_to_dev32(&udev->gdm_ed, dftEpsId);
753 sdu->bearer_ID = gdm_cpu_to_dev32(&udev->gdm_ed, epsId);
754 sdu->nic_type = gdm_cpu_to_dev32(&udev->gdm_ed, nic_type);
756 t_sdu->len = send_len + HCI_HEADER_SIZE;
757 t_sdu->callback = cb;
758 t_sdu->cb_data = cb_data;
760 spin_lock_irqsave(&tx->lock, flags);
761 list_add_tail(&t_sdu->list, &tx->sdu_list);
762 queue_work(usb_tx_wq, &udev->work_tx.work);
763 spin_unlock_irqrestore(&tx->lock, flags);
771 static int gdm_usb_hci_send(void *priv_dev, void *data, int len,
772 void (*cb)(void *data), void *cb_data)
774 struct lte_udev *udev = priv_dev;
775 struct tx_cxt *tx = &udev->tx;
780 pr_err("hci send - invalid device\n");
784 t = alloc_tx_struct(len);
786 pr_err("hci_send - out of memory\n");
790 memcpy(t->buf, data, len);
792 t->cb_data = cb_data;
797 spin_lock_irqsave(&tx->lock, flags);
798 list_add_tail(&t->list, &tx->hci_list);
799 queue_work(usb_tx_wq, &udev->work_tx.work);
800 spin_unlock_irqrestore(&tx->lock, flags);
805 static struct gdm_endian *gdm_usb_get_endian(void *priv_dev)
807 struct lte_udev *udev = priv_dev;
809 return &udev->gdm_ed;
812 static int gdm_usb_probe(struct usb_interface *intf,
813 const struct usb_device_id *id)
816 struct phy_dev *phy_dev = NULL;
817 struct lte_udev *udev = NULL;
818 u16 idVendor, idProduct;
819 int bInterfaceNumber;
820 struct usb_device *usbdev = interface_to_usbdev(intf);
822 bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
823 idVendor = __le16_to_cpu(usbdev->descriptor.idVendor);
824 idProduct = __le16_to_cpu(usbdev->descriptor.idProduct);
826 pr_info("net vid = 0x%04x pid = 0x%04x\n", idVendor, idProduct);
828 if (bInterfaceNumber > NETWORK_INTERFACE) {
829 pr_info("not a network device\n");
833 phy_dev = kzalloc(sizeof(*phy_dev), GFP_KERNEL);
837 udev = kzalloc(sizeof(*udev), GFP_KERNEL);
843 phy_dev->priv_dev = (void *)udev;
844 phy_dev->send_hci_func = gdm_usb_hci_send;
845 phy_dev->send_sdu_func = gdm_usb_sdu_send;
846 phy_dev->rcv_func = gdm_usb_recv;
847 phy_dev->get_endian = gdm_usb_get_endian;
849 udev->usbdev = usbdev;
850 ret = init_usb(udev);
852 dev_err(intf->usb_dev, "init_usb func failed\n");
857 intf->needs_remote_wakeup = 1;
858 usb_enable_autosuspend(usbdev);
859 pm_runtime_set_autosuspend_delay(&usbdev->dev, AUTO_SUSPEND_TIMER);
861 /* List up hosts with big endians, otherwise,
862 * defaults to little endian
864 if (idProduct == PID_GDM7243)
865 gdm_set_endian(&udev->gdm_ed, ENDIANNESS_BIG);
867 gdm_set_endian(&udev->gdm_ed, ENDIANNESS_LITTLE);
869 ret = request_mac_address(udev);
871 dev_err(intf->usb_dev, "request Mac address failed\n");
872 goto err_mac_address;
875 start_rx_proc(phy_dev);
877 usb_set_intfdata(intf, phy_dev);
891 static void gdm_usb_disconnect(struct usb_interface *intf)
893 struct phy_dev *phy_dev;
894 struct lte_udev *udev;
895 u16 idVendor, idProduct;
896 struct usb_device *usbdev;
898 usbdev = interface_to_usbdev(intf);
900 idVendor = __le16_to_cpu(usbdev->descriptor.idVendor);
901 idProduct = __le16_to_cpu(usbdev->descriptor.idProduct);
903 phy_dev = usb_get_intfdata(intf);
905 udev = phy_dev->priv_dev;
906 unregister_lte_device(phy_dev);
919 static int gdm_usb_suspend(struct usb_interface *intf, pm_message_t pm_msg)
921 struct phy_dev *phy_dev;
922 struct lte_udev *udev;
925 struct usb_rx *r_next;
928 phy_dev = usb_get_intfdata(intf);
929 udev = phy_dev->priv_dev;
931 if (udev->usb_state != PM_NORMAL) {
932 dev_err(intf->usb_dev, "usb suspend - invalid state\n");
936 udev->usb_state = PM_SUSPEND;
938 spin_lock_irqsave(&rx->submit_lock, flags);
939 list_for_each_entry_safe(r, r_next, &rx->rx_submit_list,
941 spin_unlock_irqrestore(&rx->submit_lock, flags);
942 usb_kill_urb(r->urb);
943 spin_lock_irqsave(&rx->submit_lock, flags);
945 spin_unlock_irqrestore(&rx->submit_lock, flags);
950 static int gdm_usb_resume(struct usb_interface *intf)
952 struct phy_dev *phy_dev;
953 struct lte_udev *udev;
960 phy_dev = usb_get_intfdata(intf);
961 udev = phy_dev->priv_dev;
964 if (udev->usb_state != PM_SUSPEND) {
965 dev_err(intf->usb_dev, "usb resume - invalid state\n");
968 udev->usb_state = PM_NORMAL;
970 spin_lock_irqsave(&rx->rx_lock, flags);
971 issue_count = rx->avail_count - MAX_RX_SUBMIT_COUNT;
972 spin_unlock_irqrestore(&rx->rx_lock, flags);
974 if (issue_count >= 0) {
975 for (i = 0; i < issue_count; i++)
976 gdm_usb_recv(phy_dev->priv_dev,
983 spin_lock_irqsave(&tx->lock, flags);
984 queue_work(usb_tx_wq, &udev->work_tx.work);
985 spin_unlock_irqrestore(&tx->lock, flags);
990 static struct usb_driver gdm_usb_lte_driver = {
992 .probe = gdm_usb_probe,
993 .disconnect = gdm_usb_disconnect,
994 .id_table = id_table,
995 .supports_autosuspend = 1,
996 .suspend = gdm_usb_suspend,
997 .resume = gdm_usb_resume,
998 .reset_resume = gdm_usb_resume,
1001 static int __init gdm_usb_lte_init(void)
1003 if (gdm_lte_event_init() < 0) {
1004 pr_err("error creating event\n");
1008 usb_tx_wq = create_workqueue("usb_tx_wq");
1012 usb_rx_wq = create_workqueue("usb_rx_wq");
1016 return usb_register(&gdm_usb_lte_driver);
1019 static void __exit gdm_usb_lte_exit(void)
1021 gdm_lte_event_exit();
1023 usb_deregister(&gdm_usb_lte_driver);
1026 flush_workqueue(usb_tx_wq);
1027 destroy_workqueue(usb_tx_wq);
1031 flush_workqueue(usb_rx_wq);
1032 destroy_workqueue(usb_rx_wq);
1036 module_init(gdm_usb_lte_init);
1037 module_exit(gdm_usb_lte_exit);
1039 MODULE_VERSION(DRIVER_VERSION);
1040 MODULE_DESCRIPTION("GCT LTE USB Device Driver");
1041 MODULE_LICENSE("GPL");