40 #include <linux/module.h>
41 #include <linux/slab.h>
45 #include <linux/device.h>
69 { USB_DEVICE(0x0cf3, 0x9170) },
71 { USB_DEVICE(0x0cf3, 0x1001) },
76 { USB_DEVICE(0x0cf3, 0x1010) },
78 { USB_DEVICE(0x0cf3, 0x1011) },
80 { USB_DEVICE(0xcace, 0x0300) },
82 { USB_DEVICE(0x07d1, 0x3c10) },
84 { USB_DEVICE(0x07d1, 0x3a09) },
86 { USB_DEVICE(0x07d1, 0x3a0f) },
88 { USB_DEVICE(0x0846, 0x9040) },
90 { USB_DEVICE(0x0846, 0x9010) },
94 { USB_DEVICE(0x0ace, 0x1221) },
96 { USB_DEVICE(0x1435, 0x0804) },
98 { USB_DEVICE(0x1435, 0x0326) },
100 { USB_DEVICE(0x0586, 0x3417) },
102 { USB_DEVICE(0x0cde, 0x0023) },
104 { USB_DEVICE(0x0cde, 0x0026) },
106 { USB_DEVICE(0x0cde, 0x0027) },
108 { USB_DEVICE(0x083a, 0xf522) },
110 { USB_DEVICE(0x2019, 0x5304) },
112 { USB_DEVICE(0x04bb, 0x093f) },
114 { USB_DEVICE(0x0409, 0x0249) },
116 { USB_DEVICE(0x0409, 0x02b4) },
118 { USB_DEVICE(0x057c, 0x8401) },
120 { USB_DEVICE(0x057c, 0x8402) },
122 { USB_DEVICE(0x1668, 0x1200) },
124 { USB_DEVICE(0x1b75, 0x9170) },
131 static void carl9170_usb_submit_data_urb(
struct ar9170 *
ar)
165 static void carl9170_usb_tx_data_complete(
struct urb *urb)
176 switch (urb->status) {
207 carl9170_usb_submit_data_urb(ar);
210 static int carl9170_usb_submit_cmd_urb(
struct ar9170 *ar)
237 static void carl9170_usb_cmd_complete(
struct urb *urb)
239 struct ar9170 *ar = urb->context;
247 switch (urb->status) {
268 dev_err(&ar->
udev->dev,
"submit cmd cb failed (%d).\n", err);
270 err = carl9170_usb_submit_cmd_urb(ar);
272 dev_err(&ar->
udev->dev,
"submit cmd failed (%d).\n", err);
275 static void carl9170_usb_rx_irq_complete(
struct urb *urb)
277 struct ar9170 *ar = urb->context;
282 switch (urb->status) {
307 static int carl9170_usb_submit_rx_urb(
struct ar9170 *ar,
gfp_t gfp)
310 int err = 0, runs = 0;
333 static void carl9170_usb_rx_work(
struct ar9170 *ar)
371 static void carl9170_usb_tasklet(
unsigned long data)
378 carl9170_usb_rx_work(ar);
389 static void carl9170_usb_rx_complete(
struct urb *urb)
399 switch (urb->status) {
420 err = carl9170_usb_submit_rx_urb(ar,
GFP_ATOMIC);
450 static struct urb *carl9170_usb_alloc_rx_urb(
struct ar9170 *ar,
gfp_t gfp)
465 usb_fill_bulk_urb(urb, ar->
udev, usb_rcvbulkpipe(ar->
udev,
467 carl9170_usb_rx_complete, ar);
469 urb->transfer_flags |= URB_FREE_BUFFER;
474 static int carl9170_usb_send_rx_irq_urb(
struct ar9170 *ar)
476 struct urb *urb =
NULL;
488 usb_fill_int_urb(urb, ar->
udev, usb_rcvintpipe(ar->
udev,
490 carl9170_usb_rx_irq_complete, ar, 1);
492 urb->transfer_flags |= URB_FREE_BUFFER;
504 static int carl9170_usb_init_rx_bulk_urbs(
struct ar9170 *ar)
520 urb = carl9170_usb_alloc_rx_urb(ar,
GFP_KERNEL);
531 err = carl9170_usb_submit_rx_urb(ar,
GFP_KERNEL);
547 static int carl9170_usb_flush(
struct ar9170 *ar)
574 static void carl9170_usb_cancel_urbs(
struct ar9170 *ar)
580 err = carl9170_usb_flush(ar);
617 usb_fill_int_urb(urb, ar->
udev, usb_sndintpipe(ar->
udev,
619 carl9170_usb_cmd_complete, ar, 1);
622 urb->transfer_flags |= URB_FREE_BUFFER;
627 return carl9170_usb_submit_cmd_urb(ar);
650 if (plen && payload != (
u8 *)(ar->
cmd.data))
660 if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
679 "received (%d).\n", err);
711 if (ar->
fw.tx_stream) {
712 tx_stream = (
void *) (skb->
data -
sizeof(*tx_stream));
714 len = skb->
len +
sizeof(*tx_stream);
723 usb_fill_bulk_urb(urb, ar->
udev, usb_sndbulkpipe(ar->
udev,
725 carl9170_usb_tx_data_complete, skb);
727 urb->transfer_flags |= URB_ZERO_PACKET;
733 carl9170_usb_submit_data_urb(ar);
741 static void carl9170_release_firmware(
struct ar9170 *ar)
755 ret = carl9170_usb_flush(ar);
757 dev_err(&ar->
udev->dev,
"kill pending tx urbs.\n");
786 static int carl9170_usb_load_firmware(
struct ar9170 *ar)
790 unsigned int transfer;
801 data = ar->
fw.fw->data;
802 len = ar->
fw.fw->size;
803 addr = ar->
fw.address;
806 data += ar->
fw.offset;
807 len -= ar->
fw.offset;
810 transfer =
min_t(
unsigned int, len, 4096
u);
811 memcpy(buf, data, transfer);
815 addr >> 8, 0, buf, transfer, 100);
847 dev_err(&ar->
udev->dev,
"firmware upload failed (%d).\n", err);
855 if (ar->
intf->condition != USB_INTERFACE_BOUND)
882 err = carl9170_usb_load_firmware(ar);
889 carl9170_usb_cancel_urbs(ar);
904 carl9170_usb_cancel_urbs(ar);
911 static int carl9170_usb_init_device(
struct ar9170 *ar)
924 err = carl9170_usb_send_rx_irq_urb(ar);
928 err = carl9170_usb_init_rx_bulk_urbs(ar);
937 err = carl9170_usb_load_firmware(ar);
948 carl9170_usb_cancel_urbs(ar);
954 static void carl9170_usb_firmware_failed(
struct ar9170 *ar)
957 struct usb_device *
udev;
975 device_unlock(parent);
980 static void carl9170_usb_firmware_finish(
struct ar9170 *ar)
988 err = carl9170_usb_init_device(ar);
1003 carl9170_usb_cancel_urbs(ar);
1006 carl9170_release_firmware(ar);
1007 carl9170_usb_firmware_failed(ar);
1010 static void carl9170_usb_firmware_step2(
const struct firmware *
fw,
1017 carl9170_usb_firmware_finish(ar);
1022 carl9170_usb_firmware_failed(ar);
1029 struct usb_device *
udev;
1040 udev = interface_to_usbdev(intf);
1046 usb_set_intfdata(intf, ar);
1047 SET_IEEE80211_DEV(ar->
hw, &intf->dev);
1049 init_usb_anchor(&ar->
rx_anch);
1050 init_usb_anchor(&ar->
rx_pool);
1051 init_usb_anchor(&ar->
rx_work);
1052 init_usb_anchor(&ar->
tx_wait);
1053 init_usb_anchor(&ar->
tx_anch);
1054 init_usb_anchor(&ar->
tx_cmd);
1055 init_usb_anchor(&ar->
tx_err);
1076 static void carl9170_usb_disconnect(
struct usb_interface *intf)
1078 struct ar9170 *ar = usb_get_intfdata(intf);
1079 struct usb_device *
udev;
1092 carl9170_usb_cancel_urbs(ar);
1095 usb_set_intfdata(intf,
NULL);
1097 carl9170_release_firmware(ar);
1106 struct ar9170 *ar = usb_get_intfdata(intf);
1111 carl9170_usb_cancel_urbs(ar);
1118 struct ar9170 *ar = usb_get_intfdata(intf);
1138 err = carl9170_usb_init_device(ar);
1145 carl9170_usb_cancel_urbs(ar);
1151 static struct usb_driver carl9170_driver = {
1152 .name = KBUILD_MODNAME,
1153 .probe = carl9170_usb_probe,
1154 .disconnect = carl9170_usb_disconnect,
1155 .id_table = carl9170_usb_ids,
1158 .suspend = carl9170_usb_suspend,
1159 .resume = carl9170_usb_resume,
1160 .reset_resume = carl9170_usb_resume,
1162 .disable_hub_initiated_lpm = 1,