2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #define ATH9K_FW_USB_DEV(devid, fw) \
20 { USB_DEVICE(0x0cf3, devid), .driver_info = (unsigned long) fw }
22 static struct usb_device_id ath9k_hif_usb_ids
[] = {
23 ATH9K_FW_USB_DEV(0x9271, "ar9271.fw"),
24 ATH9K_FW_USB_DEV(0x1006, "ar9271.fw"),
28 MODULE_DEVICE_TABLE(usb
, ath9k_hif_usb_ids
);
30 static int __hif_usb_tx(struct hif_device_usb
*hif_dev
);
32 static void hif_usb_regout_cb(struct urb
*urb
)
34 struct cmd_buf
*cmd
= (struct cmd_buf
*)urb
->context
;
35 struct hif_device_usb
*hif_dev
= cmd
->hif_dev
;
41 dev_kfree_skb_any(cmd
->skb
);
47 switch (urb
->status
) {
61 ath9k_htc_txcompletion_cb(cmd
->hif_dev
->htc_handle
,
68 static int hif_usb_send_regout(struct hif_device_usb
*hif_dev
,
75 urb
= usb_alloc_urb(0, GFP_KERNEL
);
79 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
86 cmd
->hif_dev
= hif_dev
;
88 usb_fill_int_urb(urb
, hif_dev
->udev
,
89 usb_sndintpipe(hif_dev
->udev
, USB_REG_OUT_PIPE
),
91 hif_usb_regout_cb
, cmd
, 1);
93 ret
= usb_submit_urb(urb
, GFP_KERNEL
);
102 static void hif_usb_tx_cb(struct urb
*urb
)
104 struct tx_buf
*tx_buf
= (struct tx_buf
*) urb
->context
;
105 struct hif_device_usb
*hif_dev
= tx_buf
->hif_dev
;
112 switch (urb
->status
) {
126 spin_lock(&hif_dev
->tx
.tx_lock
);
127 drop
= !!(hif_dev
->tx
.flags
& HIF_USB_TX_STOP
);
128 flush
= !!(hif_dev
->tx
.flags
& HIF_USB_TX_FLUSH
);
129 spin_unlock(&hif_dev
->tx
.tx_lock
);
131 while ((skb
= __skb_dequeue(&tx_buf
->skb_queue
)) != NULL
) {
132 if (!drop
&& !flush
) {
133 ath9k_htc_txcompletion_cb(hif_dev
->htc_handle
,
135 TX_STAT_INC(skb_completed
);
137 dev_kfree_skb_any(skb
);
144 tx_buf
->len
= tx_buf
->offset
= 0;
145 __skb_queue_head_init(&tx_buf
->skb_queue
);
147 spin_lock(&hif_dev
->tx
.tx_lock
);
148 list_del(&tx_buf
->list
);
149 list_add_tail(&tx_buf
->list
, &hif_dev
->tx
.tx_buf
);
150 hif_dev
->tx
.tx_buf_cnt
++;
152 __hif_usb_tx(hif_dev
); /* Check for pending SKBs */
153 TX_STAT_INC(buf_completed
);
154 spin_unlock(&hif_dev
->tx
.tx_lock
);
158 /* TX lock has to be taken */
159 static int __hif_usb_tx(struct hif_device_usb
*hif_dev
)
161 struct tx_buf
*tx_buf
= NULL
;
162 struct sk_buff
*nskb
= NULL
;
164 u16
*hdr
, tx_skb_cnt
= 0;
167 if (hif_dev
->tx
.tx_skb_cnt
== 0)
170 /* Check if a free TX buffer is available */
171 if (list_empty(&hif_dev
->tx
.tx_buf
))
174 tx_buf
= list_first_entry(&hif_dev
->tx
.tx_buf
, struct tx_buf
, list
);
175 list_del(&tx_buf
->list
);
176 list_add_tail(&tx_buf
->list
, &hif_dev
->tx
.tx_pending
);
177 hif_dev
->tx
.tx_buf_cnt
--;
179 tx_skb_cnt
= min_t(u16
, hif_dev
->tx
.tx_skb_cnt
, MAX_TX_AGGR_NUM
);
181 for (i
= 0; i
< tx_skb_cnt
; i
++) {
182 nskb
= __skb_dequeue(&hif_dev
->tx
.tx_skb_queue
);
184 /* Should never be NULL */
187 hif_dev
->tx
.tx_skb_cnt
--;
190 buf
+= tx_buf
->offset
;
193 *hdr
++ = ATH_USB_TX_STREAM_MODE_TAG
;
195 memcpy(buf
, nskb
->data
, nskb
->len
);
196 tx_buf
->len
= nskb
->len
+ 4;
198 if (i
< (tx_skb_cnt
- 1))
199 tx_buf
->offset
+= (((tx_buf
->len
- 1) / 4) + 1) * 4;
201 if (i
== (tx_skb_cnt
- 1))
202 tx_buf
->len
+= tx_buf
->offset
;
204 __skb_queue_tail(&tx_buf
->skb_queue
, nskb
);
205 TX_STAT_INC(skb_queued
);
208 usb_fill_bulk_urb(tx_buf
->urb
, hif_dev
->udev
,
209 usb_sndbulkpipe(hif_dev
->udev
, USB_WLAN_TX_PIPE
),
210 tx_buf
->buf
, tx_buf
->len
,
211 hif_usb_tx_cb
, tx_buf
);
213 ret
= usb_submit_urb(tx_buf
->urb
, GFP_ATOMIC
);
215 tx_buf
->len
= tx_buf
->offset
= 0;
216 __skb_queue_purge(&tx_buf
->skb_queue
);
217 __skb_queue_head_init(&tx_buf
->skb_queue
);
218 list_move_tail(&tx_buf
->list
, &hif_dev
->tx
.tx_buf
);
219 hif_dev
->tx
.tx_buf_cnt
++;
223 TX_STAT_INC(buf_queued
);
228 static int hif_usb_send_tx(struct hif_device_usb
*hif_dev
, struct sk_buff
*skb
,
229 struct ath9k_htc_tx_ctl
*tx_ctl
)
233 spin_lock_irqsave(&hif_dev
->tx
.tx_lock
, flags
);
235 if (hif_dev
->tx
.flags
& HIF_USB_TX_STOP
) {
236 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
240 /* Check if the max queue count has been reached */
241 if (hif_dev
->tx
.tx_skb_cnt
> MAX_TX_BUF_NUM
) {
242 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
246 __skb_queue_tail(&hif_dev
->tx
.tx_skb_queue
, skb
);
247 hif_dev
->tx
.tx_skb_cnt
++;
249 /* Send normal frames immediately */
250 if (!tx_ctl
|| (tx_ctl
&& (tx_ctl
->type
== ATH9K_HTC_NORMAL
)))
251 __hif_usb_tx(hif_dev
);
253 /* Check if AMPDUs have to be sent immediately */
254 if (tx_ctl
&& (tx_ctl
->type
== ATH9K_HTC_AMPDU
) &&
255 (hif_dev
->tx
.tx_buf_cnt
== MAX_TX_URB_NUM
) &&
256 (hif_dev
->tx
.tx_skb_cnt
< 2)) {
257 __hif_usb_tx(hif_dev
);
260 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
265 static void hif_usb_start(void *hif_handle
, u8 pipe_id
)
267 struct hif_device_usb
*hif_dev
= (struct hif_device_usb
*)hif_handle
;
270 hif_dev
->flags
|= HIF_USB_START
;
272 spin_lock_irqsave(&hif_dev
->tx
.tx_lock
, flags
);
273 hif_dev
->tx
.flags
&= ~HIF_USB_TX_STOP
;
274 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
277 static void hif_usb_stop(void *hif_handle
, u8 pipe_id
)
279 struct hif_device_usb
*hif_dev
= (struct hif_device_usb
*)hif_handle
;
282 spin_lock_irqsave(&hif_dev
->tx
.tx_lock
, flags
);
283 __skb_queue_purge(&hif_dev
->tx
.tx_skb_queue
);
284 hif_dev
->tx
.tx_skb_cnt
= 0;
285 hif_dev
->tx
.flags
|= HIF_USB_TX_STOP
;
286 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
289 static int hif_usb_send(void *hif_handle
, u8 pipe_id
, struct sk_buff
*skb
,
290 struct ath9k_htc_tx_ctl
*tx_ctl
)
292 struct hif_device_usb
*hif_dev
= (struct hif_device_usb
*)hif_handle
;
296 case USB_WLAN_TX_PIPE
:
297 ret
= hif_usb_send_tx(hif_dev
, skb
, tx_ctl
);
299 case USB_REG_OUT_PIPE
:
300 ret
= hif_usb_send_regout(hif_dev
, skb
);
303 dev_err(&hif_dev
->udev
->dev
,
304 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id
);
312 static struct ath9k_htc_hif hif_usb
= {
313 .transport
= ATH9K_HIF_USB
,
314 .name
= "ath9k_hif_usb",
316 .control_ul_pipe
= USB_REG_OUT_PIPE
,
317 .control_dl_pipe
= USB_REG_IN_PIPE
,
319 .start
= hif_usb_start
,
320 .stop
= hif_usb_stop
,
321 .send
= hif_usb_send
,
324 static void ath9k_hif_usb_rx_stream(struct hif_device_usb
*hif_dev
,
327 struct sk_buff
*nskb
, *skb_pool
[8];
328 int index
= 0, i
= 0, chk_idx
, len
= skb
->len
;
329 int rx_remain_len
= 0, rx_pkt_len
= 0;
330 u16 pkt_len
, pkt_tag
, pool_index
= 0;
333 spin_lock(&hif_dev
->rx_lock
);
335 rx_remain_len
= hif_dev
->rx_remain_len
;
336 rx_pkt_len
= hif_dev
->rx_transfer_len
;
338 if (rx_remain_len
!= 0) {
339 struct sk_buff
*remain_skb
= hif_dev
->remain_skb
;
342 ptr
= (u8
*) remain_skb
->data
;
344 index
= rx_remain_len
;
345 rx_remain_len
-= hif_dev
->rx_pad_len
;
348 memcpy(ptr
, skb
->data
, rx_remain_len
);
350 rx_pkt_len
+= rx_remain_len
;
351 hif_dev
->rx_remain_len
= 0;
352 skb_put(remain_skb
, rx_pkt_len
);
354 skb_pool
[pool_index
++] = remain_skb
;
357 index
= rx_remain_len
;
361 spin_unlock(&hif_dev
->rx_lock
);
363 while (index
< len
) {
364 ptr
= (u8
*) skb
->data
;
366 pkt_len
= ptr
[index
] + (ptr
[index
+1] << 8);
367 pkt_tag
= ptr
[index
+2] + (ptr
[index
+3] << 8);
369 if (pkt_tag
== ATH_USB_RX_STREAM_MODE_TAG
) {
372 pad_len
= 4 - (pkt_len
& 0x3);
377 index
= index
+ 4 + pkt_len
+ pad_len
;
379 if (index
> MAX_RX_BUF_SIZE
) {
380 spin_lock(&hif_dev
->rx_lock
);
381 hif_dev
->rx_remain_len
= index
- MAX_RX_BUF_SIZE
;
382 hif_dev
->rx_transfer_len
=
383 MAX_RX_BUF_SIZE
- chk_idx
- 4;
384 hif_dev
->rx_pad_len
= pad_len
;
386 nskb
= __dev_alloc_skb(pkt_len
+ 32,
389 dev_err(&hif_dev
->udev
->dev
,
390 "ath9k_htc: RX memory allocation"
392 spin_unlock(&hif_dev
->rx_lock
);
395 skb_reserve(nskb
, 32);
396 RX_STAT_INC(skb_allocated
);
398 memcpy(nskb
->data
, &(skb
->data
[chk_idx
+4]),
399 hif_dev
->rx_transfer_len
);
401 /* Record the buffer pointer */
402 hif_dev
->remain_skb
= nskb
;
403 spin_unlock(&hif_dev
->rx_lock
);
405 nskb
= __dev_alloc_skb(pkt_len
+ 32, GFP_ATOMIC
);
407 dev_err(&hif_dev
->udev
->dev
,
408 "ath9k_htc: RX memory allocation"
412 skb_reserve(nskb
, 32);
413 RX_STAT_INC(skb_allocated
);
415 memcpy(nskb
->data
, &(skb
->data
[chk_idx
+4]), pkt_len
);
416 skb_put(nskb
, pkt_len
);
417 skb_pool
[pool_index
++] = nskb
;
420 RX_STAT_INC(skb_dropped
);
426 for (i
= 0; i
< pool_index
; i
++) {
427 ath9k_htc_rx_msg(hif_dev
->htc_handle
, skb_pool
[i
],
428 skb_pool
[i
]->len
, USB_WLAN_RX_PIPE
);
429 RX_STAT_INC(skb_completed
);
433 static void ath9k_hif_usb_rx_cb(struct urb
*urb
)
435 struct sk_buff
*skb
= (struct sk_buff
*) urb
->context
;
436 struct hif_device_usb
*hif_dev
= (struct hif_device_usb
*)
437 usb_get_intfdata(usb_ifnum_to_if(urb
->dev
, 0));
446 switch (urb
->status
) {
458 if (likely(urb
->actual_length
!= 0)) {
459 skb_put(skb
, urb
->actual_length
);
460 ath9k_hif_usb_rx_stream(hif_dev
, skb
);
464 skb_reset_tail_pointer(skb
);
467 usb_anchor_urb(urb
, &hif_dev
->rx_submitted
);
468 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
470 usb_unanchor_urb(urb
);
476 dev_kfree_skb_any(skb
);
479 static void ath9k_hif_usb_reg_in_cb(struct urb
*urb
)
481 struct sk_buff
*skb
= (struct sk_buff
*) urb
->context
;
482 struct sk_buff
*nskb
;
483 struct hif_device_usb
*hif_dev
= (struct hif_device_usb
*)
484 usb_get_intfdata(usb_ifnum_to_if(urb
->dev
, 0));
493 switch (urb
->status
) {
505 if (likely(urb
->actual_length
!= 0)) {
506 skb_put(skb
, urb
->actual_length
);
508 nskb
= __dev_alloc_skb(MAX_REG_IN_BUF_SIZE
, GFP_ATOMIC
);
512 usb_fill_int_urb(urb
, hif_dev
->udev
,
513 usb_rcvintpipe(hif_dev
->udev
, USB_REG_IN_PIPE
),
514 nskb
->data
, MAX_REG_IN_BUF_SIZE
,
515 ath9k_hif_usb_reg_in_cb
, nskb
, 1);
517 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
519 dev_kfree_skb_any(nskb
);
523 ath9k_htc_rx_msg(hif_dev
->htc_handle
, skb
,
524 skb
->len
, USB_REG_IN_PIPE
);
530 skb_reset_tail_pointer(skb
);
533 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
539 dev_kfree_skb_any(skb
);
543 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb
*hif_dev
)
546 struct tx_buf
*tx_buf
= NULL
, *tx_buf_tmp
= NULL
;
548 list_for_each_entry_safe(tx_buf
, tx_buf_tmp
, &hif_dev
->tx
.tx_buf
, list
) {
549 list_del(&tx_buf
->list
);
550 usb_free_urb(tx_buf
->urb
);
555 spin_lock_irqsave(&hif_dev
->tx
.tx_lock
, flags
);
556 hif_dev
->tx
.flags
|= HIF_USB_TX_FLUSH
;
557 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
559 list_for_each_entry_safe(tx_buf
, tx_buf_tmp
,
560 &hif_dev
->tx
.tx_pending
, list
) {
561 usb_kill_urb(tx_buf
->urb
);
562 list_del(&tx_buf
->list
);
563 usb_free_urb(tx_buf
->urb
);
568 spin_lock_irqsave(&hif_dev
->tx
.tx_lock
, flags
);
569 hif_dev
->tx
.flags
&= ~HIF_USB_TX_FLUSH
;
570 spin_unlock_irqrestore(&hif_dev
->tx
.tx_lock
, flags
);
573 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb
*hif_dev
)
575 struct tx_buf
*tx_buf
;
578 INIT_LIST_HEAD(&hif_dev
->tx
.tx_buf
);
579 INIT_LIST_HEAD(&hif_dev
->tx
.tx_pending
);
580 spin_lock_init(&hif_dev
->tx
.tx_lock
);
581 __skb_queue_head_init(&hif_dev
->tx
.tx_skb_queue
);
583 for (i
= 0; i
< MAX_TX_URB_NUM
; i
++) {
584 tx_buf
= kzalloc(sizeof(struct tx_buf
), GFP_KERNEL
);
588 tx_buf
->buf
= kzalloc(MAX_TX_BUF_SIZE
, GFP_KERNEL
);
592 tx_buf
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
596 tx_buf
->hif_dev
= hif_dev
;
597 __skb_queue_head_init(&tx_buf
->skb_queue
);
599 list_add_tail(&tx_buf
->list
, &hif_dev
->tx
.tx_buf
);
602 hif_dev
->tx
.tx_buf_cnt
= MAX_TX_URB_NUM
;
606 ath9k_hif_usb_dealloc_tx_urbs(hif_dev
);
610 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb
*hif_dev
)
612 usb_kill_anchored_urbs(&hif_dev
->rx_submitted
);
615 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb
*hif_dev
)
617 struct urb
*urb
= NULL
;
618 struct sk_buff
*skb
= NULL
;
621 init_usb_anchor(&hif_dev
->rx_submitted
);
622 spin_lock_init(&hif_dev
->rx_lock
);
624 for (i
= 0; i
< MAX_RX_URB_NUM
; i
++) {
627 urb
= usb_alloc_urb(0, GFP_KERNEL
);
633 /* Allocate buffer */
634 skb
= __dev_alloc_skb(MAX_RX_BUF_SIZE
, GFP_KERNEL
);
640 usb_fill_bulk_urb(urb
, hif_dev
->udev
,
641 usb_rcvbulkpipe(hif_dev
->udev
,
643 skb
->data
, MAX_RX_BUF_SIZE
,
644 ath9k_hif_usb_rx_cb
, skb
);
647 usb_anchor_urb(urb
, &hif_dev
->rx_submitted
);
650 ret
= usb_submit_urb(urb
, GFP_KERNEL
);
652 usb_unanchor_urb(urb
);
657 * Drop reference count.
658 * This ensures that the URB is freed when killing them.
666 dev_kfree_skb_any(skb
);
670 ath9k_hif_usb_dealloc_rx_urbs(hif_dev
);
674 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb
*hif_dev
)
676 if (hif_dev
->reg_in_urb
) {
677 usb_kill_urb(hif_dev
->reg_in_urb
);
678 if (hif_dev
->reg_in_urb
->context
)
679 dev_kfree_skb_any((void *)hif_dev
->reg_in_urb
->context
);
680 usb_free_urb(hif_dev
->reg_in_urb
);
681 hif_dev
->reg_in_urb
= NULL
;
685 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb
*hif_dev
)
689 hif_dev
->reg_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
690 if (hif_dev
->reg_in_urb
== NULL
)
693 skb
= __dev_alloc_skb(MAX_REG_IN_BUF_SIZE
, GFP_KERNEL
);
697 usb_fill_int_urb(hif_dev
->reg_in_urb
, hif_dev
->udev
,
698 usb_rcvintpipe(hif_dev
->udev
, USB_REG_IN_PIPE
),
699 skb
->data
, MAX_REG_IN_BUF_SIZE
,
700 ath9k_hif_usb_reg_in_cb
, skb
, 1);
702 if (usb_submit_urb(hif_dev
->reg_in_urb
, GFP_KERNEL
) != 0)
708 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev
);
712 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb
*hif_dev
)
715 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev
) < 0)
719 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev
) < 0)
722 /* Register Read/Write */
723 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev
) < 0)
731 static int ath9k_hif_usb_download_fw(struct hif_device_usb
*hif_dev
)
734 const void *data
= hif_dev
->firmware
->data
;
735 size_t len
= hif_dev
->firmware
->size
;
736 u32 addr
= AR9271_FIRMWARE
;
737 u8
*buf
= kzalloc(4096, GFP_KERNEL
);
743 transfer
= min_t(int, len
, 4096);
744 memcpy(buf
, data
, transfer
);
746 err
= usb_control_msg(hif_dev
->udev
,
747 usb_sndctrlpipe(hif_dev
->udev
, 0),
748 FIRMWARE_DOWNLOAD
, 0x40 | USB_DIR_OUT
,
749 addr
>> 8, 0, buf
, transfer
, HZ
);
762 * Issue FW download complete command to firmware.
764 err
= usb_control_msg(hif_dev
->udev
, usb_sndctrlpipe(hif_dev
->udev
, 0),
765 FIRMWARE_DOWNLOAD_COMP
,
767 AR9271_FIRMWARE_TEXT
>> 8, 0, NULL
, 0, HZ
);
771 dev_info(&hif_dev
->udev
->dev
, "ath9k_htc: Transferred FW: %s, size: %ld\n",
772 "ar9271.fw", (unsigned long) hif_dev
->firmware
->size
);
777 static int ath9k_hif_usb_dev_init(struct hif_device_usb
*hif_dev
,
782 /* Request firmware */
783 ret
= request_firmware(&hif_dev
->firmware
, fw_name
, &hif_dev
->udev
->dev
);
785 dev_err(&hif_dev
->udev
->dev
,
786 "ath9k_htc: Firmware - %s not found\n", fw_name
);
790 /* Download firmware */
791 ret
= ath9k_hif_usb_download_fw(hif_dev
);
793 dev_err(&hif_dev
->udev
->dev
,
794 "ath9k_htc: Firmware - %s download failed\n", fw_name
);
795 goto err_fw_download
;
799 ret
= ath9k_hif_usb_alloc_urbs(hif_dev
);
801 dev_err(&hif_dev
->udev
->dev
,
802 "ath9k_htc: Unable to allocate URBs\n");
811 release_firmware(hif_dev
->firmware
);
813 hif_dev
->firmware
= NULL
;
817 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb
*hif_dev
)
819 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev
);
820 ath9k_hif_usb_dealloc_tx_urbs(hif_dev
);
821 ath9k_hif_usb_dealloc_rx_urbs(hif_dev
);
824 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb
*hif_dev
)
826 ath9k_hif_usb_dealloc_urbs(hif_dev
);
827 if (hif_dev
->firmware
)
828 release_firmware(hif_dev
->firmware
);
831 static int ath9k_hif_usb_probe(struct usb_interface
*interface
,
832 const struct usb_device_id
*id
)
834 struct usb_device
*udev
= interface_to_usbdev(interface
);
835 struct hif_device_usb
*hif_dev
;
836 const char *fw_name
= (const char *) id
->driver_info
;
839 hif_dev
= kzalloc(sizeof(struct hif_device_usb
), GFP_KERNEL
);
846 hif_dev
->udev
= udev
;
847 hif_dev
->interface
= interface
;
848 hif_dev
->device_id
= id
->idProduct
;
850 udev
->reset_resume
= 1;
852 usb_set_intfdata(interface
, hif_dev
);
854 ret
= ath9k_hif_usb_dev_init(hif_dev
, fw_name
);
857 goto err_hif_init_usb
;
860 hif_dev
->htc_handle
= ath9k_htc_hw_alloc(hif_dev
);
861 if (hif_dev
->htc_handle
== NULL
) {
863 goto err_htc_hw_alloc
;
866 ret
= ath9k_htc_hw_init(&hif_usb
, hif_dev
->htc_handle
, hif_dev
,
867 &hif_dev
->udev
->dev
, hif_dev
->device_id
,
871 goto err_htc_hw_init
;
874 dev_info(&hif_dev
->udev
->dev
, "ath9k_htc: USB layer initialized\n");
879 ath9k_htc_hw_free(hif_dev
->htc_handle
);
881 ath9k_hif_usb_dev_deinit(hif_dev
);
883 usb_set_intfdata(interface
, NULL
);
890 static void ath9k_hif_usb_disconnect(struct usb_interface
*interface
)
892 struct usb_device
*udev
= interface_to_usbdev(interface
);
893 struct hif_device_usb
*hif_dev
=
894 (struct hif_device_usb
*) usb_get_intfdata(interface
);
897 ath9k_htc_hw_deinit(hif_dev
->htc_handle
, true);
898 ath9k_htc_hw_free(hif_dev
->htc_handle
);
899 ath9k_hif_usb_dev_deinit(hif_dev
);
900 usb_set_intfdata(interface
, NULL
);
903 if (hif_dev
->flags
& HIF_USB_START
)
904 usb_reset_device(udev
);
907 dev_info(&udev
->dev
, "ath9k_htc: USB layer deinitialized\n");
912 static int ath9k_hif_usb_suspend(struct usb_interface
*interface
,
913 pm_message_t message
)
915 struct hif_device_usb
*hif_dev
=
916 (struct hif_device_usb
*) usb_get_intfdata(interface
);
918 ath9k_hif_usb_dealloc_urbs(hif_dev
);
923 static int ath9k_hif_usb_resume(struct usb_interface
*interface
)
925 struct hif_device_usb
*hif_dev
=
926 (struct hif_device_usb
*) usb_get_intfdata(interface
);
929 ret
= ath9k_hif_usb_alloc_urbs(hif_dev
);
933 if (hif_dev
->firmware
) {
934 ret
= ath9k_hif_usb_download_fw(hif_dev
);
938 ath9k_hif_usb_dealloc_urbs(hif_dev
);
944 ret
= ath9k_htc_resume(hif_dev
->htc_handle
);
952 ath9k_hif_usb_dealloc_urbs(hif_dev
);
958 static struct usb_driver ath9k_hif_usb_driver
= {
959 .name
= "ath9k_hif_usb",
960 .probe
= ath9k_hif_usb_probe
,
961 .disconnect
= ath9k_hif_usb_disconnect
,
963 .suspend
= ath9k_hif_usb_suspend
,
964 .resume
= ath9k_hif_usb_resume
,
965 .reset_resume
= ath9k_hif_usb_resume
,
967 .id_table
= ath9k_hif_usb_ids
,
971 int ath9k_hif_usb_init(void)
973 return usb_register(&ath9k_hif_usb_driver
);
976 void ath9k_hif_usb_exit(void)
978 usb_deregister(&ath9k_hif_usb_driver
);