2 * Atheros CARL9170 driver
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
23 * This file incorporates work covered by the following copyright and
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/usb.h>
43 #include <linux/firmware.h>
44 #include <linux/etherdevice.h>
45 #include <linux/device.h>
46 #include <net/mac80211.h>
52 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
53 MODULE_AUTHOR("Christian Lamparter <chunkeey@googlemail.com>");
54 MODULE_LICENSE("GPL");
55 MODULE_DESCRIPTION("Atheros AR9170 802.11n USB wireless");
56 MODULE_FIRMWARE(CARL9170FW_NAME);
57 MODULE_ALIAS("ar9170usb");
58 MODULE_ALIAS("arusb_lnx");
63 * Always update our wiki's device list (located at:
64 * http://wireless.kernel.org/en/users/Drivers/ar9170/devices ),
65 * whenever you add a new device.
67 static struct usb_device_id carl9170_usb_ids[] = {
69 { USB_DEVICE(0x0cf3, 0x9170) },
71 { USB_DEVICE(0x0cf3, 0x1001) },
72 /* TP-Link TL-WN821N v2 */
73 { USB_DEVICE(0x0cf3, 0x1002), .driver_info = CARL9170_WPS_BUTTON |
75 /* 3Com Dual Band 802.11n USB Adapter */
76 { USB_DEVICE(0x0cf3, 0x1010) },
77 /* H3C Dual Band 802.11n USB Adapter */
78 { USB_DEVICE(0x0cf3, 0x1011) },
80 { USB_DEVICE(0xcace, 0x0300) },
81 /* D-Link DWA 160 A1 */
82 { USB_DEVICE(0x07d1, 0x3c10) },
83 /* D-Link DWA 160 A2 */
84 { USB_DEVICE(0x07d1, 0x3a09) },
85 /* D-Link DWA 130 D */
86 { USB_DEVICE(0x07d1, 0x3a0f) },
88 { USB_DEVICE(0x0846, 0x9040) },
89 /* Netgear WNDA3100 (v1) */
90 { USB_DEVICE(0x0846, 0x9010) },
91 /* Netgear WN111 v2 */
92 { USB_DEVICE(0x0846, 0x9001), .driver_info = CARL9170_ONE_LED },
94 { USB_DEVICE(0x0ace, 0x1221) },
95 /* Proxim ORiNOCO 802.11n USB */
96 { USB_DEVICE(0x1435, 0x0804) },
97 /* WNC Generic 11n USB Dongle */
98 { USB_DEVICE(0x1435, 0x0326) },
100 { USB_DEVICE(0x0586, 0x3417) },
102 { USB_DEVICE(0x0cde, 0x0023) },
104 { USB_DEVICE(0x0cde, 0x0026) },
105 /* Sphairon Homelink 1202 */
106 { USB_DEVICE(0x0cde, 0x0027) },
107 /* Arcadyan WN7512 */
108 { USB_DEVICE(0x083a, 0xf522) },
110 { USB_DEVICE(0x2019, 0x5304) },
111 /* IO-Data WNGDNUS2 */
112 { USB_DEVICE(0x04bb, 0x093f) },
114 { USB_DEVICE(0x0409, 0x0249) },
116 { USB_DEVICE(0x0409, 0x02b4) },
117 /* AVM FRITZ!WLAN USB Stick N */
118 { USB_DEVICE(0x057c, 0x8401) },
119 /* AVM FRITZ!WLAN USB Stick N 2.4 */
120 { USB_DEVICE(0x057c, 0x8402) },
121 /* Qwest/Actiontec 802AIN Wireless N USB Network Adapter */
122 { USB_DEVICE(0x1668, 0x1200) },
123 /* Airlive X.USB a/b/g/n */
124 { USB_DEVICE(0x1b75, 0x9170) },
129 MODULE_DEVICE_TABLE(usb, carl9170_usb_ids);
131 static void carl9170_usb_submit_data_urb(struct ar9170 *ar)
136 if (atomic_inc_return(&ar->tx_anch_urbs) > AR9170_NUM_TX_URBS)
139 urb = usb_get_from_anchor(&ar->tx_wait);
143 usb_anchor_urb(urb, &ar->tx_anch);
145 err = usb_submit_urb(urb, GFP_ATOMIC);
147 if (net_ratelimit()) {
148 dev_err(&ar->udev->dev, "tx submit failed (%d)\n",
152 usb_unanchor_urb(urb);
153 usb_anchor_urb(urb, &ar->tx_err);
158 if (likely(err == 0))
162 atomic_dec(&ar->tx_anch_urbs);
165 static void carl9170_usb_tx_data_complete(struct urb *urb)
167 struct ar9170 *ar = usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
169 if (WARN_ON_ONCE(!ar)) {
170 dev_kfree_skb_irq(urb->context);
174 atomic_dec(&ar->tx_anch_urbs);
176 switch (urb->status) {
177 /* everything is fine */
179 carl9170_tx_callback(ar, (void *)urb->context);
188 * Defer the frame clean-up to the tasklet worker.
189 * This is necessary, because carl9170_tx_drop
190 * does not work in an irqsave context.
192 usb_anchor_urb(urb, &ar->tx_err);
195 /* a random transmission error has occurred? */
197 if (net_ratelimit()) {
198 dev_err(&ar->udev->dev, "tx failed (%d)\n",
202 usb_anchor_urb(urb, &ar->tx_err);
206 if (likely(IS_STARTED(ar)))
207 carl9170_usb_submit_data_urb(ar);
210 static int carl9170_usb_submit_cmd_urb(struct ar9170 *ar)
215 if (atomic_inc_return(&ar->tx_cmd_urbs) != 1) {
216 atomic_dec(&ar->tx_cmd_urbs);
220 urb = usb_get_from_anchor(&ar->tx_cmd);
222 atomic_dec(&ar->tx_cmd_urbs);
226 usb_anchor_urb(urb, &ar->tx_anch);
227 err = usb_submit_urb(urb, GFP_ATOMIC);
229 usb_unanchor_urb(urb);
230 atomic_dec(&ar->tx_cmd_urbs);
237 static void carl9170_usb_cmd_complete(struct urb *urb)
239 struct ar9170 *ar = urb->context;
242 if (WARN_ON_ONCE(!ar))
245 atomic_dec(&ar->tx_cmd_urbs);
247 switch (urb->status) {
248 /* everything is fine */
264 if (!IS_INITIALIZED(ar))
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;
279 if (WARN_ON_ONCE(!ar))
282 switch (urb->status) {
283 /* everything is fine */
299 * While the carl9170 firmware does not use this EP, the
300 * firmware loader in the EEPROM unfortunately does.
301 * Therefore we need to be ready to handle out-of-band
302 * responses and traps in case the firmware crashed and
303 * the loader took over again.
305 carl9170_handle_command_response(ar, urb->transfer_buffer,
309 usb_anchor_urb(urb, &ar->rx_anch);
310 if (unlikely(usb_submit_urb(urb, GFP_ATOMIC)))
311 usb_unanchor_urb(urb);
314 static int carl9170_usb_submit_rx_urb(struct ar9170 *ar, gfp_t gfp)
317 int err = 0, runs = 0;
319 while ((atomic_read(&ar->rx_anch_urbs) < AR9170_NUM_RX_URBS) &&
320 (runs++ < AR9170_NUM_RX_URBS)) {
322 urb = usb_get_from_anchor(&ar->rx_pool);
324 usb_anchor_urb(urb, &ar->rx_anch);
325 err = usb_submit_urb(urb, gfp);
327 usb_unanchor_urb(urb);
328 usb_anchor_urb(urb, &ar->rx_pool);
330 atomic_dec(&ar->rx_pool_urbs);
331 atomic_inc(&ar->rx_anch_urbs);
340 static void carl9170_usb_rx_work(struct ar9170 *ar)
345 for (i = 0; i < AR9170_NUM_RX_URBS_POOL; i++) {
346 urb = usb_get_from_anchor(&ar->rx_work);
350 atomic_dec(&ar->rx_work_urbs);
351 if (IS_INITIALIZED(ar)) {
352 carl9170_rx(ar, urb->transfer_buffer,
356 usb_anchor_urb(urb, &ar->rx_pool);
357 atomic_inc(&ar->rx_pool_urbs);
361 carl9170_usb_submit_rx_urb(ar, GFP_ATOMIC);
365 void carl9170_usb_handle_tx_err(struct ar9170 *ar)
369 while ((urb = usb_get_from_anchor(&ar->tx_err))) {
370 struct sk_buff *skb = (void *)urb->context;
372 carl9170_tx_drop(ar, skb);
373 carl9170_tx_callback(ar, skb);
378 static void carl9170_usb_tasklet(unsigned long data)
380 struct ar9170 *ar = (struct ar9170 *) data;
382 if (!IS_INITIALIZED(ar))
385 carl9170_usb_rx_work(ar);
388 * Strictly speaking: The tx scheduler is not part of the USB system.
389 * But the rx worker returns frames back to the mac80211-stack and
390 * this is the _perfect_ place to generate the next transmissions.
393 carl9170_tx_scheduler(ar);
396 static void carl9170_usb_rx_complete(struct urb *urb)
398 struct ar9170 *ar = (struct ar9170 *)urb->context;
401 if (WARN_ON_ONCE(!ar))
404 atomic_dec(&ar->rx_anch_urbs);
406 switch (urb->status) {
409 usb_anchor_urb(urb, &ar->rx_work);
410 atomic_inc(&ar->rx_work_urbs);
417 /* handle disconnect events*/
421 /* handle all other errors */
422 usb_anchor_urb(urb, &ar->rx_pool);
423 atomic_inc(&ar->rx_pool_urbs);
427 err = carl9170_usb_submit_rx_urb(ar, GFP_ATOMIC);
430 * usb_submit_rx_urb reported a problem.
431 * In case this is due to a rx buffer shortage,
432 * elevate the tasklet worker priority to
433 * the highest available level.
435 tasklet_hi_schedule(&ar->usb_tasklet);
437 if (atomic_read(&ar->rx_anch_urbs) == 0) {
439 * The system is too slow to cope with
440 * the enormous workload. We have simply
441 * run out of active rx urbs and this
442 * unfortunately leads to an unpredictable
446 ieee80211_queue_work(ar->hw, &ar->ping_work);
450 * Using anything less than _high_ priority absolutely
451 * kills the rx performance my UP-System...
453 tasklet_hi_schedule(&ar->usb_tasklet);
457 static struct urb *carl9170_usb_alloc_rx_urb(struct ar9170 *ar, gfp_t gfp)
462 buf = kmalloc(ar->fw.rx_size, gfp);
466 urb = usb_alloc_urb(0, gfp);
472 usb_fill_bulk_urb(urb, ar->udev, usb_rcvbulkpipe(ar->udev,
473 AR9170_USB_EP_RX), buf, ar->fw.rx_size,
474 carl9170_usb_rx_complete, ar);
476 urb->transfer_flags |= URB_FREE_BUFFER;
481 static int carl9170_usb_send_rx_irq_urb(struct ar9170 *ar)
483 struct urb *urb = NULL;
487 urb = usb_alloc_urb(0, GFP_KERNEL);
491 ibuf = kmalloc(AR9170_USB_EP_CTRL_MAX, GFP_KERNEL);
495 usb_fill_int_urb(urb, ar->udev, usb_rcvintpipe(ar->udev,
496 AR9170_USB_EP_IRQ), ibuf, AR9170_USB_EP_CTRL_MAX,
497 carl9170_usb_rx_irq_complete, ar, 1);
499 urb->transfer_flags |= URB_FREE_BUFFER;
501 usb_anchor_urb(urb, &ar->rx_anch);
502 err = usb_submit_urb(urb, GFP_KERNEL);
504 usb_unanchor_urb(urb);
511 static int carl9170_usb_init_rx_bulk_urbs(struct ar9170 *ar)
514 int i, err = -EINVAL;
517 * The driver actively maintains a second shadow
518 * pool for inactive, but fully-prepared rx urbs.
520 * The pool should help the driver to master huge
521 * workload spikes without running the risk of
522 * undersupplying the hardware or wasting time by
523 * processing rx data (streams) inside the urb
524 * completion (hardirq context).
526 for (i = 0; i < AR9170_NUM_RX_URBS_POOL; i++) {
527 urb = carl9170_usb_alloc_rx_urb(ar, GFP_KERNEL);
533 usb_anchor_urb(urb, &ar->rx_pool);
534 atomic_inc(&ar->rx_pool_urbs);
538 err = carl9170_usb_submit_rx_urb(ar, GFP_KERNEL);
542 /* the device now waiting for the firmware. */
543 carl9170_set_state_when(ar, CARL9170_STOPPED, CARL9170_IDLE);
548 usb_scuttle_anchored_urbs(&ar->rx_pool);
549 usb_scuttle_anchored_urbs(&ar->rx_work);
550 usb_kill_anchored_urbs(&ar->rx_anch);
554 static int carl9170_usb_flush(struct ar9170 *ar)
559 while ((urb = usb_get_from_anchor(&ar->tx_wait))) {
560 struct sk_buff *skb = (void *)urb->context;
561 carl9170_tx_drop(ar, skb);
562 carl9170_tx_callback(ar, skb);
566 ret = usb_wait_anchor_empty_timeout(&ar->tx_cmd, 1000);
570 /* lets wait a while until the tx - queues are dried out */
571 ret = usb_wait_anchor_empty_timeout(&ar->tx_anch, 1000);
575 usb_kill_anchored_urbs(&ar->tx_anch);
576 carl9170_usb_handle_tx_err(ar);
581 static void carl9170_usb_cancel_urbs(struct ar9170 *ar)
585 carl9170_set_state(ar, CARL9170_UNKNOWN_STATE);
587 err = carl9170_usb_flush(ar);
589 dev_err(&ar->udev->dev, "stuck tx urbs!\n");
591 usb_poison_anchored_urbs(&ar->tx_anch);
592 carl9170_usb_handle_tx_err(ar);
593 usb_poison_anchored_urbs(&ar->rx_anch);
595 tasklet_kill(&ar->usb_tasklet);
597 usb_scuttle_anchored_urbs(&ar->rx_work);
598 usb_scuttle_anchored_urbs(&ar->rx_pool);
599 usb_scuttle_anchored_urbs(&ar->tx_cmd);
602 int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
608 if (!IS_INITIALIZED(ar)) {
613 if (WARN_ON(cmd->hdr.len > CARL9170_MAX_CMD_LEN - 4)) {
618 urb = usb_alloc_urb(0, GFP_ATOMIC);
624 usb_fill_int_urb(urb, ar->udev, usb_sndintpipe(ar->udev,
625 AR9170_USB_EP_CMD), cmd, cmd->hdr.len + 4,
626 carl9170_usb_cmd_complete, ar, 1);
629 urb->transfer_flags |= URB_FREE_BUFFER;
631 usb_anchor_urb(urb, &ar->tx_cmd);
634 return carl9170_usb_submit_cmd_urb(ar);
643 int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
644 unsigned int plen, void *payload, unsigned int outlen, void *out)
648 if (!IS_ACCEPTING_CMD(ar))
651 if (!(cmd & CARL9170_CMD_ASYNC_FLAG))
654 ar->cmd.hdr.len = plen;
655 ar->cmd.hdr.cmd = cmd;
656 /* writing multiple regs fills this buffer already */
657 if (plen && payload != (u8 *)(ar->cmd.data))
658 memcpy(ar->cmd.data, payload, plen);
660 spin_lock_bh(&ar->cmd_lock);
661 ar->readbuf = (u8 *)out;
662 ar->readlen = outlen;
663 spin_unlock_bh(&ar->cmd_lock);
665 err = __carl9170_exec_cmd(ar, &ar->cmd, false);
667 if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
668 err = wait_for_completion_timeout(&ar->cmd_wait, HZ);
674 if (ar->readlen != outlen) {
683 /* Maybe the device was removed in the moment we were waiting? */
684 if (IS_STARTED(ar)) {
685 dev_err(&ar->udev->dev, "no command feedback "
686 "received (%d).\n", err);
688 /* provide some maybe useful debug information */
689 print_hex_dump_bytes("carl9170 cmd: ", DUMP_PREFIX_NONE,
692 carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
695 /* invalidate to avoid completing the next command prematurely */
696 spin_lock_bh(&ar->cmd_lock);
699 spin_unlock_bh(&ar->cmd_lock);
704 void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb)
707 struct ar9170_stream *tx_stream;
714 urb = usb_alloc_urb(0, GFP_ATOMIC);
718 if (ar->fw.tx_stream) {
719 tx_stream = (void *) (skb->data - sizeof(*tx_stream));
721 len = skb->len + sizeof(*tx_stream);
722 tx_stream->length = cpu_to_le16(len);
723 tx_stream->tag = cpu_to_le16(AR9170_TX_STREAM_TAG);
730 usb_fill_bulk_urb(urb, ar->udev, usb_sndbulkpipe(ar->udev,
731 AR9170_USB_EP_TX), data, len,
732 carl9170_usb_tx_data_complete, skb);
734 urb->transfer_flags |= URB_ZERO_PACKET;
736 usb_anchor_urb(urb, &ar->tx_wait);
740 carl9170_usb_submit_data_urb(ar);
744 carl9170_tx_drop(ar, skb);
745 carl9170_tx_callback(ar, skb);
748 static void carl9170_release_firmware(struct ar9170 *ar)
751 release_firmware(ar->fw.fw);
752 memset(&ar->fw, 0, sizeof(ar->fw));
756 void carl9170_usb_stop(struct ar9170 *ar)
760 carl9170_set_state_when(ar, CARL9170_IDLE, CARL9170_STOPPED);
762 ret = carl9170_usb_flush(ar);
764 dev_err(&ar->udev->dev, "kill pending tx urbs.\n");
766 usb_poison_anchored_urbs(&ar->tx_anch);
767 carl9170_usb_handle_tx_err(ar);
769 /* kill any pending command */
770 spin_lock_bh(&ar->cmd_lock);
772 spin_unlock_bh(&ar->cmd_lock);
773 complete_all(&ar->cmd_wait);
775 /* This is required to prevent an early completion on _start */
776 reinit_completion(&ar->cmd_wait);
780 * So far we freed all tx urbs, but we won't dare to touch any rx urbs.
781 * Else we would end up with a unresponsive device...
785 int carl9170_usb_open(struct ar9170 *ar)
787 usb_unpoison_anchored_urbs(&ar->tx_anch);
789 carl9170_set_state_when(ar, CARL9170_STOPPED, CARL9170_IDLE);
793 static int carl9170_usb_load_firmware(struct ar9170 *ar)
797 unsigned int transfer;
802 buf = kmalloc(4096, GFP_KERNEL);
808 data = ar->fw.fw->data;
809 len = ar->fw.fw->size;
810 addr = ar->fw.address;
812 /* this removes the miniboot image */
813 data += ar->fw.offset;
814 len -= ar->fw.offset;
817 transfer = min_t(unsigned int, len, 4096u);
818 memcpy(buf, data, transfer);
820 err = usb_control_msg(ar->udev, usb_sndctrlpipe(ar->udev, 0),
821 0x30 /* FW DL */, 0x40 | USB_DIR_OUT,
822 addr >> 8, 0, buf, transfer, 100);
835 err = usb_control_msg(ar->udev, usb_sndctrlpipe(ar->udev, 0),
836 0x31 /* FW DL COMPLETE */,
837 0x40 | USB_DIR_OUT, 0, 0, NULL, 0, 200);
839 if (wait_for_completion_timeout(&ar->fw_boot_wait, HZ) == 0) {
844 err = carl9170_echo_test(ar, 0x4a110123);
848 /* now, start the command response counter */
854 dev_err(&ar->udev->dev, "firmware upload failed (%d).\n", err);
858 int carl9170_usb_restart(struct ar9170 *ar)
862 if (ar->intf->condition != USB_INTERFACE_BOUND)
866 * Disable the command response sequence counter check.
867 * We already know that the device/firmware is in a bad state.
868 * So, no extra points are awarded to anyone who reminds the
873 err = carl9170_reboot(ar);
875 carl9170_usb_stop(ar);
880 tasklet_schedule(&ar->usb_tasklet);
882 /* The reboot procedure can take quite a while to complete. */
885 err = carl9170_usb_open(ar);
889 err = carl9170_usb_load_firmware(ar);
896 carl9170_usb_cancel_urbs(ar);
900 void carl9170_usb_reset(struct ar9170 *ar)
903 * This is the last resort to get the device going again
904 * without any *user replugging action*.
906 * But there is a catch: usb_reset really is like a physical
907 * *reconnect*. The mac80211 state will be lost in the process.
908 * Therefore a userspace application, which is monitoring
909 * the link must step in.
911 carl9170_usb_cancel_urbs(ar);
913 carl9170_usb_stop(ar);
915 usb_queue_reset_device(ar->intf);
918 static int carl9170_usb_init_device(struct ar9170 *ar)
923 * The carl9170 firmware let's the driver know when it's
924 * ready for action. But we have to be prepared to gracefully
925 * handle all spurious [flushed] messages after each (re-)boot.
926 * Thus the command response counter remains disabled until it
927 * can be safely synchronized.
931 err = carl9170_usb_send_rx_irq_urb(ar);
935 err = carl9170_usb_init_rx_bulk_urbs(ar);
939 err = carl9170_usb_open(ar);
943 mutex_lock(&ar->mutex);
944 err = carl9170_usb_load_firmware(ar);
945 mutex_unlock(&ar->mutex);
952 carl9170_usb_stop(ar);
955 carl9170_usb_cancel_urbs(ar);
961 static void carl9170_usb_firmware_failed(struct ar9170 *ar)
963 struct device *parent = ar->udev->dev.parent;
964 struct usb_device *udev;
967 * Store a copy of the usb_device pointer locally.
968 * This is because device_release_driver initiates
969 * carl9170_usb_disconnect, which in turn frees our
970 * driver context (ar).
974 complete(&ar->fw_load_wait);
976 /* unbind anything failed */
980 device_release_driver(&udev->dev);
982 device_unlock(parent);
987 static void carl9170_usb_firmware_finish(struct ar9170 *ar)
991 err = carl9170_parse_firmware(ar);
995 err = carl9170_usb_init_device(ar);
999 err = carl9170_register(ar);
1001 carl9170_usb_stop(ar);
1005 complete(&ar->fw_load_wait);
1006 usb_put_dev(ar->udev);
1010 carl9170_usb_cancel_urbs(ar);
1013 carl9170_release_firmware(ar);
1014 carl9170_usb_firmware_failed(ar);
1017 static void carl9170_usb_firmware_step2(const struct firmware *fw,
1020 struct ar9170 *ar = context;
1024 carl9170_usb_firmware_finish(ar);
1028 dev_err(&ar->udev->dev, "firmware not found.\n");
1029 carl9170_usb_firmware_failed(ar);
1032 static int carl9170_usb_probe(struct usb_interface *intf,
1033 const struct usb_device_id *id)
1036 struct usb_device *udev;
1039 err = usb_reset_device(interface_to_usbdev(intf));
1043 ar = carl9170_alloc(sizeof(*ar));
1047 udev = interface_to_usbdev(intf);
1051 ar->features = id->driver_info;
1053 usb_set_intfdata(intf, ar);
1054 SET_IEEE80211_DEV(ar->hw, &intf->dev);
1056 init_usb_anchor(&ar->rx_anch);
1057 init_usb_anchor(&ar->rx_pool);
1058 init_usb_anchor(&ar->rx_work);
1059 init_usb_anchor(&ar->tx_wait);
1060 init_usb_anchor(&ar->tx_anch);
1061 init_usb_anchor(&ar->tx_cmd);
1062 init_usb_anchor(&ar->tx_err);
1063 init_completion(&ar->cmd_wait);
1064 init_completion(&ar->fw_boot_wait);
1065 init_completion(&ar->fw_load_wait);
1066 tasklet_init(&ar->usb_tasklet, carl9170_usb_tasklet,
1069 atomic_set(&ar->tx_cmd_urbs, 0);
1070 atomic_set(&ar->tx_anch_urbs, 0);
1071 atomic_set(&ar->rx_work_urbs, 0);
1072 atomic_set(&ar->rx_anch_urbs, 0);
1073 atomic_set(&ar->rx_pool_urbs, 0);
1075 usb_get_dev(ar->udev);
1077 carl9170_set_state(ar, CARL9170_STOPPED);
1079 err = request_firmware_nowait(THIS_MODULE, 1, CARL9170FW_NAME,
1080 &ar->udev->dev, GFP_KERNEL, ar, carl9170_usb_firmware_step2);
1089 static void carl9170_usb_disconnect(struct usb_interface *intf)
1091 struct ar9170 *ar = usb_get_intfdata(intf);
1092 struct usb_device *udev;
1098 wait_for_completion(&ar->fw_load_wait);
1100 if (IS_INITIALIZED(ar)) {
1101 carl9170_reboot(ar);
1102 carl9170_usb_stop(ar);
1105 carl9170_usb_cancel_urbs(ar);
1106 carl9170_unregister(ar);
1108 usb_set_intfdata(intf, NULL);
1110 carl9170_release_firmware(ar);
1116 static int carl9170_usb_suspend(struct usb_interface *intf,
1117 pm_message_t message)
1119 struct ar9170 *ar = usb_get_intfdata(intf);
1124 carl9170_usb_cancel_urbs(ar);
1129 static int carl9170_usb_resume(struct usb_interface *intf)
1131 struct ar9170 *ar = usb_get_intfdata(intf);
1137 usb_unpoison_anchored_urbs(&ar->rx_anch);
1138 carl9170_set_state(ar, CARL9170_STOPPED);
1141 * The USB documentation demands that [for suspend] all traffic
1142 * to and from the device has to stop. This would be fine, but
1143 * there's a catch: the device[usb phy] does not come back.
1145 * Upon resume the firmware will "kill" itself and the
1146 * boot-code sorts out the magic voodoo.
1147 * Not very nice, but there's not much what could go wrong.
1151 err = carl9170_usb_init_device(ar);
1158 carl9170_usb_cancel_urbs(ar);
1162 #endif /* CONFIG_PM */
1164 static struct usb_driver carl9170_driver = {
1165 .name = KBUILD_MODNAME,
1166 .probe = carl9170_usb_probe,
1167 .disconnect = carl9170_usb_disconnect,
1168 .id_table = carl9170_usb_ids,
1171 .suspend = carl9170_usb_suspend,
1172 .resume = carl9170_usb_resume,
1173 .reset_resume = carl9170_usb_resume,
1174 #endif /* CONFIG_PM */
1175 .disable_hub_initiated_lpm = 1,
1178 module_usb_driver(carl9170_driver);