2 * Atheros AR9170 driver
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, Christian Lamparter <chunkeey@web.de>
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/usb.h>
42 #include <linux/firmware.h>
43 #include <linux/etherdevice.h>
44 #include <net/mac80211.h>
50 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
51 MODULE_AUTHOR("Christian Lamparter <chunkeey@web.de>");
52 MODULE_LICENSE("GPL");
53 MODULE_DESCRIPTION("Atheros AR9170 802.11n USB wireless");
54 MODULE_FIRMWARE("ar9170.fw");
55 MODULE_FIRMWARE("ar9170-1.fw");
56 MODULE_FIRMWARE("ar9170-2.fw");
58 enum ar9170_requirements
{
59 AR9170_REQ_FW1_ONLY
= 1,
62 static struct usb_device_id ar9170_usb_ids
[] = {
64 { USB_DEVICE(0x0cf3, 0x9170) },
66 { USB_DEVICE(0x0cf3, 0x1001) },
67 /* TP-Link TL-WN821N v2 */
68 { USB_DEVICE(0x0cf3, 0x1002) },
70 { USB_DEVICE(0xcace, 0x0300) },
71 /* D-Link DWA 160 A1 */
72 { USB_DEVICE(0x07d1, 0x3c10) },
73 /* D-Link DWA 160 A2 */
74 { USB_DEVICE(0x07d1, 0x3a09) },
75 /* Netgear WNDA3100 */
76 { USB_DEVICE(0x0846, 0x9010) },
77 /* Netgear WN111 v2 */
78 { USB_DEVICE(0x0846, 0x9001) },
80 { USB_DEVICE(0x0ace, 0x1221) },
82 { USB_DEVICE(0x0586, 0x3417) },
84 { USB_DEVICE(0x0cde, 0x0023) },
86 { USB_DEVICE(0x0cde, 0x0026) },
87 /* Sphairon Homelink 1202 */
88 { USB_DEVICE(0x0cde, 0x0027) },
90 { USB_DEVICE(0x083a, 0xf522) },
92 { USB_DEVICE(0x2019, 0x5304) },
93 /* IO-Data WNGDNUS2 */
94 { USB_DEVICE(0x04bb, 0x093f) },
95 /* AVM FRITZ!WLAN USB Stick N */
96 { USB_DEVICE(0x057C, 0x8401) },
98 { USB_DEVICE(0x0409, 0x0249) },
99 /* AVM FRITZ!WLAN USB Stick N 2.4 */
100 { USB_DEVICE(0x057C, 0x8402), .driver_info
= AR9170_REQ_FW1_ONLY
},
105 MODULE_DEVICE_TABLE(usb
, ar9170_usb_ids
);
107 static void ar9170_usb_submit_urb(struct ar9170_usb
*aru
)
113 if (unlikely(!IS_STARTED(&aru
->common
)))
116 spin_lock_irqsave(&aru
->tx_urb_lock
, flags
);
117 if (atomic_read(&aru
->tx_submitted_urbs
) >= AR9170_NUM_TX_URBS
) {
118 spin_unlock_irqrestore(&aru
->tx_urb_lock
, flags
);
121 atomic_inc(&aru
->tx_submitted_urbs
);
123 urb
= usb_get_from_anchor(&aru
->tx_pending
);
125 atomic_dec(&aru
->tx_submitted_urbs
);
126 spin_unlock_irqrestore(&aru
->tx_urb_lock
, flags
);
130 spin_unlock_irqrestore(&aru
->tx_urb_lock
, flags
);
132 aru
->tx_pending_urbs
--;
133 usb_anchor_urb(urb
, &aru
->tx_submitted
);
135 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
137 if (ar9170_nag_limiter(&aru
->common
))
138 dev_err(&aru
->udev
->dev
, "submit_urb failed (%d).\n",
141 usb_unanchor_urb(urb
);
142 atomic_dec(&aru
->tx_submitted_urbs
);
143 ar9170_tx_callback(&aru
->common
, urb
->context
);
149 static void ar9170_usb_tx_urb_complete_frame(struct urb
*urb
)
151 struct sk_buff
*skb
= urb
->context
;
152 struct ar9170_usb
*aru
= (struct ar9170_usb
*)
153 usb_get_intfdata(usb_ifnum_to_if(urb
->dev
, 0));
155 if (unlikely(!aru
)) {
156 dev_kfree_skb_irq(skb
);
160 atomic_dec(&aru
->tx_submitted_urbs
);
162 ar9170_tx_callback(&aru
->common
, skb
);
164 ar9170_usb_submit_urb(aru
);
167 static void ar9170_usb_tx_urb_complete(struct urb
*urb
)
171 static void ar9170_usb_irq_completed(struct urb
*urb
)
173 struct ar9170_usb
*aru
= urb
->context
;
175 switch (urb
->status
) {
176 /* everything is fine */
191 ar9170_handle_command_response(&aru
->common
, urb
->transfer_buffer
,
195 usb_anchor_urb(urb
, &aru
->rx_submitted
);
196 if (usb_submit_urb(urb
, GFP_ATOMIC
)) {
197 usb_unanchor_urb(urb
);
204 usb_buffer_free(aru
->udev
, 64, urb
->transfer_buffer
, urb
->transfer_dma
);
207 static void ar9170_usb_rx_completed(struct urb
*urb
)
209 struct sk_buff
*skb
= urb
->context
;
210 struct ar9170_usb
*aru
= (struct ar9170_usb
*)
211 usb_get_intfdata(usb_ifnum_to_if(urb
->dev
, 0));
217 switch (urb
->status
) {
218 /* everything is fine */
233 skb_put(skb
, urb
->actual_length
);
234 ar9170_rx(&aru
->common
, skb
);
237 skb_reset_tail_pointer(skb
);
240 usb_anchor_urb(urb
, &aru
->rx_submitted
);
241 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
243 usb_unanchor_urb(urb
);
250 dev_kfree_skb_irq(skb
);
253 static int ar9170_usb_prep_rx_urb(struct ar9170_usb
*aru
,
254 struct urb
*urb
, gfp_t gfp
)
258 skb
= __dev_alloc_skb(AR9170_MAX_RX_BUFFER_SIZE
+ 32, gfp
);
262 /* reserve some space for mac80211's radiotap */
263 skb_reserve(skb
, 32);
265 usb_fill_bulk_urb(urb
, aru
->udev
,
266 usb_rcvbulkpipe(aru
->udev
, AR9170_EP_RX
),
267 skb
->data
, min(skb_tailroom(skb
),
268 AR9170_MAX_RX_BUFFER_SIZE
),
269 ar9170_usb_rx_completed
, skb
);
274 static int ar9170_usb_alloc_rx_irq_urb(struct ar9170_usb
*aru
)
276 struct urb
*urb
= NULL
;
280 /* initialize interrupt endpoint */
281 urb
= usb_alloc_urb(0, GFP_KERNEL
);
285 ibuf
= usb_buffer_alloc(aru
->udev
, 64, GFP_KERNEL
, &urb
->transfer_dma
);
289 usb_fill_int_urb(urb
, aru
->udev
,
290 usb_rcvintpipe(aru
->udev
, AR9170_EP_IRQ
), ibuf
,
291 64, ar9170_usb_irq_completed
, aru
, 1);
292 urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
294 usb_anchor_urb(urb
, &aru
->rx_submitted
);
295 err
= usb_submit_urb(urb
, GFP_KERNEL
);
297 usb_unanchor_urb(urb
);
298 usb_buffer_free(aru
->udev
, 64, urb
->transfer_buffer
,
307 static int ar9170_usb_alloc_rx_bulk_urbs(struct ar9170_usb
*aru
)
313 for (i
= 0; i
< AR9170_NUM_RX_URBS
; i
++) {
315 urb
= usb_alloc_urb(0, GFP_KERNEL
);
319 err
= ar9170_usb_prep_rx_urb(aru
, urb
, GFP_KERNEL
);
325 usb_anchor_urb(urb
, &aru
->rx_submitted
);
326 err
= usb_submit_urb(urb
, GFP_KERNEL
);
328 usb_unanchor_urb(urb
);
329 dev_kfree_skb_any((void *) urb
->transfer_buffer
);
336 /* the device now waiting for a firmware. */
337 aru
->common
.state
= AR9170_IDLE
;
342 usb_kill_anchored_urbs(&aru
->rx_submitted
);
346 static int ar9170_usb_flush(struct ar9170
*ar
)
348 struct ar9170_usb
*aru
= (void *) ar
;
353 aru
->common
.state
= AR9170_IDLE
;
355 usb_wait_anchor_empty_timeout(&aru
->tx_pending
,
356 msecs_to_jiffies(800));
357 while ((urb
= usb_get_from_anchor(&aru
->tx_pending
))) {
358 ar9170_tx_callback(&aru
->common
, (void *) urb
->context
);
362 /* lets wait a while until the tx - queues are dried out */
363 ret
= usb_wait_anchor_empty_timeout(&aru
->tx_submitted
,
364 msecs_to_jiffies(100));
368 usb_kill_anchored_urbs(&aru
->tx_submitted
);
370 if (IS_ACCEPTING_CMD(ar
))
371 aru
->common
.state
= AR9170_STARTED
;
376 static void ar9170_usb_cancel_urbs(struct ar9170_usb
*aru
)
380 aru
->common
.state
= AR9170_UNKNOWN_STATE
;
382 err
= ar9170_usb_flush(&aru
->common
);
384 dev_err(&aru
->udev
->dev
, "stuck tx urbs!\n");
386 usb_poison_anchored_urbs(&aru
->tx_submitted
);
387 usb_poison_anchored_urbs(&aru
->rx_submitted
);
390 static int ar9170_usb_exec_cmd(struct ar9170
*ar
, enum ar9170_cmd cmd
,
391 unsigned int plen
, void *payload
,
392 unsigned int outlen
, void *out
)
394 struct ar9170_usb
*aru
= (void *) ar
;
395 struct urb
*urb
= NULL
;
399 if (unlikely(!IS_ACCEPTING_CMD(ar
)))
402 if (WARN_ON(plen
> AR9170_MAX_CMD_LEN
- 4))
405 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
409 ar
->cmdbuf
[0] = cpu_to_le32(plen
);
410 ar
->cmdbuf
[0] |= cpu_to_le32(cmd
<< 8);
411 /* writing multiple regs fills this buffer already */
412 if (plen
&& payload
!= (u8
*)(&ar
->cmdbuf
[1]))
413 memcpy(&ar
->cmdbuf
[1], payload
, plen
);
415 spin_lock_irqsave(&aru
->common
.cmdlock
, flags
);
416 aru
->readbuf
= (u8
*)out
;
417 aru
->readlen
= outlen
;
418 spin_unlock_irqrestore(&aru
->common
.cmdlock
, flags
);
420 usb_fill_int_urb(urb
, aru
->udev
,
421 usb_sndintpipe(aru
->udev
, AR9170_EP_CMD
),
422 aru
->common
.cmdbuf
, plen
+ 4,
423 ar9170_usb_tx_urb_complete
, NULL
, 1);
425 usb_anchor_urb(urb
, &aru
->tx_submitted
);
426 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
428 usb_unanchor_urb(urb
);
434 err
= wait_for_completion_timeout(&aru
->cmd_wait
, HZ
);
440 if (aru
->readlen
!= outlen
) {
448 /* Maybe the device was removed in the second we were waiting? */
449 if (IS_STARTED(ar
)) {
450 dev_err(&aru
->udev
->dev
, "no command feedback "
451 "received (%d).\n", err
);
453 /* provide some maybe useful debug information */
454 print_hex_dump_bytes("ar9170 cmd: ", DUMP_PREFIX_NONE
,
455 aru
->common
.cmdbuf
, plen
+ 4);
459 /* invalidate to avoid completing the next prematurely */
460 spin_lock_irqsave(&aru
->common
.cmdlock
, flags
);
463 spin_unlock_irqrestore(&aru
->common
.cmdlock
, flags
);
470 static int ar9170_usb_tx(struct ar9170
*ar
, struct sk_buff
*skb
)
472 struct ar9170_usb
*aru
= (struct ar9170_usb
*) ar
;
475 if (unlikely(!IS_STARTED(ar
))) {
476 /* Seriously, what were you drink... err... thinking!? */
480 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
484 usb_fill_bulk_urb(urb
, aru
->udev
,
485 usb_sndbulkpipe(aru
->udev
, AR9170_EP_TX
),
487 ar9170_usb_tx_urb_complete_frame
, skb
);
488 urb
->transfer_flags
|= URB_ZERO_PACKET
;
490 usb_anchor_urb(urb
, &aru
->tx_pending
);
491 aru
->tx_pending_urbs
++;
495 ar9170_usb_submit_urb(aru
);
499 static void ar9170_usb_callback_cmd(struct ar9170
*ar
, u32 len
, void *buffer
)
501 struct ar9170_usb
*aru
= (void *) ar
;
505 if (unlikely(!buffer
))
508 in
= le32_to_cpup((__le32
*)buffer
);
509 out
= le32_to_cpu(ar
->cmdbuf
[0]);
511 /* mask off length byte */
514 if (aru
->readlen
>= 0) {
515 /* add expected length */
518 /* add obtained length */
523 * Some commands (e.g: AR9170_CMD_FREQUENCY) have a variable response
524 * length and we cannot predict the correct length in advance.
525 * So we only check if we provided enough space for the data.
527 if (unlikely(out
< in
)) {
528 dev_warn(&aru
->udev
->dev
, "received invalid command response "
529 "got %d bytes, instead of %d bytes "
530 "and the resp length is %d bytes\n",
532 print_hex_dump_bytes("ar9170 invalid resp: ",
533 DUMP_PREFIX_OFFSET
, buffer
, len
);
535 * Do not complete, then the command times out,
536 * and we get a stack trace from there.
541 spin_lock_irqsave(&aru
->common
.cmdlock
, flags
);
542 if (aru
->readbuf
&& len
> 0) {
543 memcpy(aru
->readbuf
, buffer
+ 4, len
- 4);
546 complete(&aru
->cmd_wait
);
547 spin_unlock_irqrestore(&aru
->common
.cmdlock
, flags
);
550 static int ar9170_usb_upload(struct ar9170_usb
*aru
, const void *data
,
551 size_t len
, u32 addr
, bool complete
)
554 u8
*buf
= kmalloc(4096, GFP_KERNEL
);
560 transfer
= min_t(int, len
, 4096);
561 memcpy(buf
, data
, transfer
);
563 err
= usb_control_msg(aru
->udev
, usb_sndctrlpipe(aru
->udev
, 0),
564 0x30 /* FW DL */, 0x40 | USB_DIR_OUT
,
565 addr
>> 8, 0, buf
, transfer
, 1000);
579 err
= usb_control_msg(aru
->udev
, usb_sndctrlpipe(aru
->udev
, 0),
580 0x31 /* FW DL COMPLETE */,
581 0x40 | USB_DIR_OUT
, 0, 0, NULL
, 0, 5000);
587 static int ar9170_usb_reset(struct ar9170_usb
*aru
)
589 int ret
, lock
= (aru
->intf
->condition
!= USB_INTERFACE_BINDING
);
592 ret
= usb_lock_device_for_reset(aru
->udev
, aru
->intf
);
594 dev_err(&aru
->udev
->dev
, "unable to lock device "
595 "for reset (%d).\n", ret
);
600 ret
= usb_reset_device(aru
->udev
);
602 usb_unlock_device(aru
->udev
);
604 /* let it rest - for a second - */
610 static int ar9170_usb_upload_firmware(struct ar9170_usb
*aru
)
614 if (!aru
->init_values
)
615 goto upload_fw_start
;
617 /* First, upload initial values to device RAM */
618 err
= ar9170_usb_upload(aru
, aru
->init_values
->data
,
619 aru
->init_values
->size
, 0x102800, false);
621 dev_err(&aru
->udev
->dev
, "firmware part 1 "
622 "upload failed (%d).\n", err
);
628 /* Then, upload the firmware itself and start it */
629 return ar9170_usb_upload(aru
, aru
->firmware
->data
, aru
->firmware
->size
,
633 static int ar9170_usb_init_transport(struct ar9170_usb
*aru
)
635 struct ar9170
*ar
= (void *) &aru
->common
;
638 ar9170_regwrite_begin(ar
);
640 /* Set USB Rx stream mode MAX packet number to 2 */
641 ar9170_regwrite(AR9170_USB_REG_MAX_AGG_UPLOAD
, 0x4);
643 /* Set USB Rx stream mode timeout to 10us */
644 ar9170_regwrite(AR9170_USB_REG_UPLOAD_TIME_CTL
, 0x80);
646 ar9170_regwrite_finish();
648 err
= ar9170_regwrite_result();
650 dev_err(&aru
->udev
->dev
, "USB setup failed (%d).\n", err
);
655 static void ar9170_usb_stop(struct ar9170
*ar
)
657 struct ar9170_usb
*aru
= (void *) ar
;
660 if (IS_ACCEPTING_CMD(ar
))
661 aru
->common
.state
= AR9170_STOPPED
;
663 ret
= ar9170_usb_flush(ar
);
665 dev_err(&aru
->udev
->dev
, "kill pending tx urbs.\n");
667 usb_poison_anchored_urbs(&aru
->tx_submitted
);
671 * So far we freed all tx urbs, but we won't dare to touch any rx urbs.
672 * Else we would end up with a unresponsive device...
676 static int ar9170_usb_open(struct ar9170
*ar
)
678 struct ar9170_usb
*aru
= (void *) ar
;
681 usb_unpoison_anchored_urbs(&aru
->tx_submitted
);
682 err
= ar9170_usb_init_transport(aru
);
684 usb_poison_anchored_urbs(&aru
->tx_submitted
);
688 aru
->common
.state
= AR9170_IDLE
;
692 static int ar9170_usb_init_device(struct ar9170_usb
*aru
)
696 err
= ar9170_usb_alloc_rx_irq_urb(aru
);
700 err
= ar9170_usb_alloc_rx_bulk_urbs(aru
);
704 err
= ar9170_usb_upload_firmware(aru
);
706 err
= ar9170_echo_test(&aru
->common
, 0x60d43110);
708 /* force user invention, by disabling the device */
709 err
= usb_driver_set_configuration(aru
->udev
, -1);
710 dev_err(&aru
->udev
->dev
, "device is in a bad state. "
711 "please reconnect it!\n");
719 ar9170_usb_cancel_urbs(aru
);
725 static void ar9170_usb_firmware_failed(struct ar9170_usb
*aru
)
727 struct device
*parent
= aru
->udev
->dev
.parent
;
729 complete(&aru
->firmware_loading_complete
);
731 /* unbind anything failed */
734 device_release_driver(&aru
->udev
->dev
);
738 usb_put_dev(aru
->udev
);
741 static void ar9170_usb_firmware_finish(const struct firmware
*fw
, void *context
)
743 struct ar9170_usb
*aru
= context
;
749 dev_err(&aru
->udev
->dev
, "firmware file not found.\n");
753 err
= ar9170_usb_init_device(aru
);
757 err
= ar9170_usb_open(&aru
->common
);
761 err
= ar9170_register(&aru
->common
, &aru
->udev
->dev
);
763 ar9170_usb_stop(&aru
->common
);
767 complete(&aru
->firmware_loading_complete
);
768 usb_put_dev(aru
->udev
);
772 ar9170_usb_cancel_urbs(aru
);
775 ar9170_usb_firmware_failed(aru
);
778 static void ar9170_usb_firmware_inits(const struct firmware
*fw
,
781 struct ar9170_usb
*aru
= context
;
785 dev_err(&aru
->udev
->dev
, "file with init values not found.\n");
786 ar9170_usb_firmware_failed(aru
);
790 aru
->init_values
= fw
;
792 /* ok so we have the init values -- get code for two-stage */
794 err
= request_firmware_nowait(THIS_MODULE
, 1, "ar9170-2.fw",
795 &aru
->udev
->dev
, GFP_KERNEL
, aru
,
796 ar9170_usb_firmware_finish
);
798 ar9170_usb_firmware_failed(aru
);
801 static void ar9170_usb_firmware_step2(const struct firmware
*fw
, void *context
)
803 struct ar9170_usb
*aru
= context
;
807 ar9170_usb_firmware_finish(fw
, context
);
811 if (aru
->req_one_stage_fw
) {
812 dev_err(&aru
->udev
->dev
, "ar9170.fw firmware file "
813 "not found and is required for this device\n");
814 ar9170_usb_firmware_failed(aru
);
818 dev_err(&aru
->udev
->dev
, "ar9170.fw firmware file "
819 "not found, trying old firmware...\n");
821 err
= request_firmware_nowait(THIS_MODULE
, 1, "ar9170-1.fw",
822 &aru
->udev
->dev
, GFP_KERNEL
, aru
,
823 ar9170_usb_firmware_inits
);
825 ar9170_usb_firmware_failed(aru
);
828 static bool ar9170_requires_one_stage(const struct usb_device_id
*id
)
830 if (!id
->driver_info
)
832 if (id
->driver_info
== AR9170_REQ_FW1_ONLY
)
837 static int ar9170_usb_probe(struct usb_interface
*intf
,
838 const struct usb_device_id
*id
)
840 struct ar9170_usb
*aru
;
842 struct usb_device
*udev
;
845 aru
= ar9170_alloc(sizeof(*aru
));
851 udev
= interface_to_usbdev(intf
);
857 aru
->req_one_stage_fw
= ar9170_requires_one_stage(id
);
859 usb_set_intfdata(intf
, aru
);
860 SET_IEEE80211_DEV(ar
->hw
, &intf
->dev
);
862 init_usb_anchor(&aru
->rx_submitted
);
863 init_usb_anchor(&aru
->tx_pending
);
864 init_usb_anchor(&aru
->tx_submitted
);
865 init_completion(&aru
->cmd_wait
);
866 init_completion(&aru
->firmware_loading_complete
);
867 spin_lock_init(&aru
->tx_urb_lock
);
869 aru
->tx_pending_urbs
= 0;
870 atomic_set(&aru
->tx_submitted_urbs
, 0);
872 aru
->common
.stop
= ar9170_usb_stop
;
873 aru
->common
.flush
= ar9170_usb_flush
;
874 aru
->common
.open
= ar9170_usb_open
;
875 aru
->common
.tx
= ar9170_usb_tx
;
876 aru
->common
.exec_cmd
= ar9170_usb_exec_cmd
;
877 aru
->common
.callback_cmd
= ar9170_usb_callback_cmd
;
880 udev
->reset_resume
= 1;
881 #endif /* CONFIG_PM */
882 err
= ar9170_usb_reset(aru
);
886 usb_get_dev(aru
->udev
);
887 return request_firmware_nowait(THIS_MODULE
, 1, "ar9170.fw",
888 &aru
->udev
->dev
, GFP_KERNEL
, aru
,
889 ar9170_usb_firmware_step2
);
891 usb_set_intfdata(intf
, NULL
);
893 ieee80211_free_hw(ar
->hw
);
898 static void ar9170_usb_disconnect(struct usb_interface
*intf
)
900 struct ar9170_usb
*aru
= usb_get_intfdata(intf
);
905 aru
->common
.state
= AR9170_IDLE
;
907 wait_for_completion(&aru
->firmware_loading_complete
);
909 ar9170_unregister(&aru
->common
);
910 ar9170_usb_cancel_urbs(aru
);
912 usb_put_dev(aru
->udev
);
913 usb_set_intfdata(intf
, NULL
);
914 ieee80211_free_hw(aru
->common
.hw
);
916 release_firmware(aru
->init_values
);
917 release_firmware(aru
->firmware
);
921 static int ar9170_suspend(struct usb_interface
*intf
,
922 pm_message_t message
)
924 struct ar9170_usb
*aru
= usb_get_intfdata(intf
);
929 aru
->common
.state
= AR9170_IDLE
;
930 ar9170_usb_cancel_urbs(aru
);
935 static int ar9170_resume(struct usb_interface
*intf
)
937 struct ar9170_usb
*aru
= usb_get_intfdata(intf
);
943 usb_unpoison_anchored_urbs(&aru
->rx_submitted
);
944 usb_unpoison_anchored_urbs(&aru
->tx_submitted
);
946 err
= ar9170_usb_init_device(aru
);
950 err
= ar9170_usb_open(&aru
->common
);
957 aru
->common
.state
= AR9170_IDLE
;
958 ar9170_usb_cancel_urbs(aru
);
962 #endif /* CONFIG_PM */
964 static struct usb_driver ar9170_driver
= {
966 .probe
= ar9170_usb_probe
,
967 .disconnect
= ar9170_usb_disconnect
,
968 .id_table
= ar9170_usb_ids
,
971 .suspend
= ar9170_suspend
,
972 .resume
= ar9170_resume
,
973 .reset_resume
= ar9170_resume
,
974 #endif /* CONFIG_PM */
977 static int __init
ar9170_init(void)
979 return usb_register(&ar9170_driver
);
982 static void __exit
ar9170_exit(void)
984 usb_deregister(&ar9170_driver
);
987 module_init(ar9170_init
);
988 module_exit(ar9170_exit
);