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;
36 switch (urb->status) {
49 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
60 static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
67 urb = usb_alloc_urb(0, GFP_KERNEL);
71 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
78 cmd->hif_dev = hif_dev;
80 usb_fill_int_urb(urb, hif_dev->udev,
81 usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE),
83 hif_usb_regout_cb, cmd, 1);
85 usb_anchor_urb(urb, &hif_dev->regout_submitted);
86 ret = usb_submit_urb(urb, GFP_KERNEL);
88 usb_unanchor_urb(urb);
96 static void hif_usb_tx_cb(struct urb *urb)
98 struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
99 struct hif_device_usb *hif_dev = tx_buf->hif_dev;
106 switch (urb->status) {
120 spin_lock(&hif_dev->tx.tx_lock);
121 drop = !!(hif_dev->tx.flags & HIF_USB_TX_STOP);
122 flush = !!(hif_dev->tx.flags & HIF_USB_TX_FLUSH);
123 spin_unlock(&hif_dev->tx.tx_lock);
125 while ((skb = __skb_dequeue(&tx_buf->skb_queue)) != NULL) {
126 if (!drop && !flush) {
127 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
129 TX_STAT_INC(skb_completed);
131 dev_kfree_skb_any(skb);
132 TX_STAT_INC(skb_dropped);
139 tx_buf->len = tx_buf->offset = 0;
140 __skb_queue_head_init(&tx_buf->skb_queue);
142 spin_lock(&hif_dev->tx.tx_lock);
143 list_del(&tx_buf->list);
144 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
145 hif_dev->tx.tx_buf_cnt++;
147 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
148 TX_STAT_INC(buf_completed);
149 spin_unlock(&hif_dev->tx.tx_lock);
153 static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
154 struct sk_buff_head *list)
158 while ((skb = __skb_dequeue(list)) != NULL) {
159 dev_kfree_skb_any(skb);
160 TX_STAT_INC(skb_dropped);
164 /* TX lock has to be taken */
165 static int __hif_usb_tx(struct hif_device_usb *hif_dev)
167 struct tx_buf *tx_buf = NULL;
168 struct sk_buff *nskb = NULL;
170 u16 *hdr, tx_skb_cnt = 0;
173 if (hif_dev->tx.tx_skb_cnt == 0)
176 /* Check if a free TX buffer is available */
177 if (list_empty(&hif_dev->tx.tx_buf))
180 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
181 list_del(&tx_buf->list);
182 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
183 hif_dev->tx.tx_buf_cnt--;
185 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
187 for (i = 0; i < tx_skb_cnt; i++) {
188 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
190 /* Should never be NULL */
193 hif_dev->tx.tx_skb_cnt--;
196 buf += tx_buf->offset;
199 *hdr++ = ATH_USB_TX_STREAM_MODE_TAG;
201 memcpy(buf, nskb->data, nskb->len);
202 tx_buf->len = nskb->len + 4;
204 if (i < (tx_skb_cnt - 1))
205 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
207 if (i == (tx_skb_cnt - 1))
208 tx_buf->len += tx_buf->offset;
210 __skb_queue_tail(&tx_buf->skb_queue, nskb);
211 TX_STAT_INC(skb_queued);
214 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
215 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
216 tx_buf->buf, tx_buf->len,
217 hif_usb_tx_cb, tx_buf);
219 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
221 tx_buf->len = tx_buf->offset = 0;
222 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
223 __skb_queue_head_init(&tx_buf->skb_queue);
224 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
225 hif_dev->tx.tx_buf_cnt++;
229 TX_STAT_INC(buf_queued);
234 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb,
235 struct ath9k_htc_tx_ctl *tx_ctl)
239 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
241 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
242 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
246 /* Check if the max queue count has been reached */
247 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
248 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
252 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
253 hif_dev->tx.tx_skb_cnt++;
255 /* Send normal frames immediately */
256 if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL)))
257 __hif_usb_tx(hif_dev);
259 /* Check if AMPDUs have to be sent immediately */
260 if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) &&
261 (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
262 (hif_dev->tx.tx_skb_cnt < 2)) {
263 __hif_usb_tx(hif_dev);
266 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
271 static void hif_usb_start(void *hif_handle, u8 pipe_id)
273 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
276 hif_dev->flags |= HIF_USB_START;
278 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
279 hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
280 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
283 static void hif_usb_stop(void *hif_handle, u8 pipe_id)
285 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
288 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
289 ath9k_skb_queue_purge(hif_dev, &hif_dev->tx.tx_skb_queue);
290 hif_dev->tx.tx_skb_cnt = 0;
291 hif_dev->tx.flags |= HIF_USB_TX_STOP;
292 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
295 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb,
296 struct ath9k_htc_tx_ctl *tx_ctl)
298 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
302 case USB_WLAN_TX_PIPE:
303 ret = hif_usb_send_tx(hif_dev, skb, tx_ctl);
305 case USB_REG_OUT_PIPE:
306 ret = hif_usb_send_regout(hif_dev, skb);
309 dev_err(&hif_dev->udev->dev,
310 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
318 static struct ath9k_htc_hif hif_usb = {
319 .transport = ATH9K_HIF_USB,
320 .name = "ath9k_hif_usb",
322 .control_ul_pipe = USB_REG_OUT_PIPE,
323 .control_dl_pipe = USB_REG_IN_PIPE,
325 .start = hif_usb_start,
326 .stop = hif_usb_stop,
327 .send = hif_usb_send,
330 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
333 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
334 int index = 0, i = 0, chk_idx, len = skb->len;
335 int rx_remain_len = 0, rx_pkt_len = 0;
336 u16 pkt_len, pkt_tag, pool_index = 0;
339 spin_lock(&hif_dev->rx_lock);
341 rx_remain_len = hif_dev->rx_remain_len;
342 rx_pkt_len = hif_dev->rx_transfer_len;
344 if (rx_remain_len != 0) {
345 struct sk_buff *remain_skb = hif_dev->remain_skb;
348 ptr = (u8 *) remain_skb->data;
350 index = rx_remain_len;
351 rx_remain_len -= hif_dev->rx_pad_len;
354 memcpy(ptr, skb->data, rx_remain_len);
356 rx_pkt_len += rx_remain_len;
357 hif_dev->rx_remain_len = 0;
358 skb_put(remain_skb, rx_pkt_len);
360 skb_pool[pool_index++] = remain_skb;
363 index = rx_remain_len;
367 spin_unlock(&hif_dev->rx_lock);
369 while (index < len) {
370 ptr = (u8 *) skb->data;
372 pkt_len = ptr[index] + (ptr[index+1] << 8);
373 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
375 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
378 pad_len = 4 - (pkt_len & 0x3);
383 index = index + 4 + pkt_len + pad_len;
385 if (index > MAX_RX_BUF_SIZE) {
386 spin_lock(&hif_dev->rx_lock);
387 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
388 hif_dev->rx_transfer_len =
389 MAX_RX_BUF_SIZE - chk_idx - 4;
390 hif_dev->rx_pad_len = pad_len;
392 nskb = __dev_alloc_skb(pkt_len + 32,
395 dev_err(&hif_dev->udev->dev,
396 "ath9k_htc: RX memory allocation"
398 spin_unlock(&hif_dev->rx_lock);
401 skb_reserve(nskb, 32);
402 RX_STAT_INC(skb_allocated);
404 memcpy(nskb->data, &(skb->data[chk_idx+4]),
405 hif_dev->rx_transfer_len);
407 /* Record the buffer pointer */
408 hif_dev->remain_skb = nskb;
409 spin_unlock(&hif_dev->rx_lock);
411 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
413 dev_err(&hif_dev->udev->dev,
414 "ath9k_htc: RX memory allocation"
418 skb_reserve(nskb, 32);
419 RX_STAT_INC(skb_allocated);
421 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
422 skb_put(nskb, pkt_len);
423 skb_pool[pool_index++] = nskb;
426 RX_STAT_INC(skb_dropped);
432 for (i = 0; i < pool_index; i++) {
433 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
434 skb_pool[i]->len, USB_WLAN_RX_PIPE);
435 RX_STAT_INC(skb_completed);
439 static void ath9k_hif_usb_rx_cb(struct urb *urb)
441 struct sk_buff *skb = (struct sk_buff *) urb->context;
442 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
443 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
452 switch (urb->status) {
464 if (likely(urb->actual_length != 0)) {
465 skb_put(skb, urb->actual_length);
466 ath9k_hif_usb_rx_stream(hif_dev, skb);
470 skb_reset_tail_pointer(skb);
473 usb_anchor_urb(urb, &hif_dev->rx_submitted);
474 ret = usb_submit_urb(urb, GFP_ATOMIC);
476 usb_unanchor_urb(urb);
485 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
487 struct sk_buff *skb = (struct sk_buff *) urb->context;
488 struct sk_buff *nskb;
489 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
490 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
499 switch (urb->status) {
511 if (likely(urb->actual_length != 0)) {
512 skb_put(skb, urb->actual_length);
514 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
518 usb_fill_int_urb(urb, hif_dev->udev,
519 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
520 nskb->data, MAX_REG_IN_BUF_SIZE,
521 ath9k_hif_usb_reg_in_cb, nskb, 1);
523 ret = usb_submit_urb(urb, GFP_ATOMIC);
529 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
530 skb->len, USB_REG_IN_PIPE);
536 skb_reset_tail_pointer(skb);
539 ret = usb_submit_urb(urb, GFP_ATOMIC);
549 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
552 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
554 list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_buf, list) {
555 list_del(&tx_buf->list);
556 usb_free_urb(tx_buf->urb);
561 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
562 hif_dev->tx.flags |= HIF_USB_TX_FLUSH;
563 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
565 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
566 &hif_dev->tx.tx_pending, list) {
567 usb_kill_urb(tx_buf->urb);
568 list_del(&tx_buf->list);
569 usb_free_urb(tx_buf->urb);
574 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
575 hif_dev->tx.flags &= ~HIF_USB_TX_FLUSH;
576 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
579 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
581 struct tx_buf *tx_buf;
584 INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
585 INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
586 spin_lock_init(&hif_dev->tx.tx_lock);
587 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
589 for (i = 0; i < MAX_TX_URB_NUM; i++) {
590 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
594 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
598 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
602 tx_buf->hif_dev = hif_dev;
603 __skb_queue_head_init(&tx_buf->skb_queue);
605 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
608 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
612 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
616 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
618 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
621 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
623 struct urb *urb = NULL;
624 struct sk_buff *skb = NULL;
627 init_usb_anchor(&hif_dev->rx_submitted);
628 spin_lock_init(&hif_dev->rx_lock);
630 for (i = 0; i < MAX_RX_URB_NUM; i++) {
633 urb = usb_alloc_urb(0, GFP_KERNEL);
639 /* Allocate buffer */
640 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
646 usb_fill_bulk_urb(urb, hif_dev->udev,
647 usb_rcvbulkpipe(hif_dev->udev,
649 skb->data, MAX_RX_BUF_SIZE,
650 ath9k_hif_usb_rx_cb, skb);
653 usb_anchor_urb(urb, &hif_dev->rx_submitted);
656 ret = usb_submit_urb(urb, GFP_KERNEL);
658 usb_unanchor_urb(urb);
663 * Drop reference count.
664 * This ensures that the URB is freed when killing them.
676 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
680 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
682 if (hif_dev->reg_in_urb) {
683 usb_kill_urb(hif_dev->reg_in_urb);
684 if (hif_dev->reg_in_urb->context)
685 kfree_skb((void *)hif_dev->reg_in_urb->context);
686 usb_free_urb(hif_dev->reg_in_urb);
687 hif_dev->reg_in_urb = NULL;
691 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
695 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
696 if (hif_dev->reg_in_urb == NULL)
699 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
703 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
704 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
705 skb->data, MAX_REG_IN_BUF_SIZE,
706 ath9k_hif_usb_reg_in_cb, skb, 1);
708 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
714 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
718 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
721 init_usb_anchor(&hif_dev->regout_submitted);
724 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
728 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
732 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
740 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
743 const void *data = hif_dev->firmware->data;
744 size_t len = hif_dev->firmware->size;
745 u32 addr = AR9271_FIRMWARE;
746 u8 *buf = kzalloc(4096, GFP_KERNEL);
752 transfer = min_t(int, len, 4096);
753 memcpy(buf, data, transfer);
755 err = usb_control_msg(hif_dev->udev,
756 usb_sndctrlpipe(hif_dev->udev, 0),
757 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
758 addr >> 8, 0, buf, transfer, HZ);
771 * Issue FW download complete command to firmware.
773 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
774 FIRMWARE_DOWNLOAD_COMP,
776 AR9271_FIRMWARE_TEXT >> 8, 0, NULL, 0, HZ);
780 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
781 "ar9271.fw", (unsigned long) hif_dev->firmware->size);
786 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev,
791 /* Request firmware */
792 ret = request_firmware(&hif_dev->firmware, fw_name, &hif_dev->udev->dev);
794 dev_err(&hif_dev->udev->dev,
795 "ath9k_htc: Firmware - %s not found\n", fw_name);
799 /* Download firmware */
800 ret = ath9k_hif_usb_download_fw(hif_dev);
802 dev_err(&hif_dev->udev->dev,
803 "ath9k_htc: Firmware - %s download failed\n", fw_name);
804 goto err_fw_download;
808 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
810 dev_err(&hif_dev->udev->dev,
811 "ath9k_htc: Unable to allocate URBs\n");
820 release_firmware(hif_dev->firmware);
822 hif_dev->firmware = NULL;
826 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
828 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
829 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
830 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
831 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
834 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
836 ath9k_hif_usb_dealloc_urbs(hif_dev);
837 if (hif_dev->firmware)
838 release_firmware(hif_dev->firmware);
841 static int ath9k_hif_usb_probe(struct usb_interface *interface,
842 const struct usb_device_id *id)
844 struct usb_device *udev = interface_to_usbdev(interface);
845 struct hif_device_usb *hif_dev;
846 const char *fw_name = (const char *) id->driver_info;
849 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
856 hif_dev->udev = udev;
857 hif_dev->interface = interface;
858 hif_dev->device_id = id->idProduct;
860 udev->reset_resume = 1;
862 usb_set_intfdata(interface, hif_dev);
864 ret = ath9k_hif_usb_dev_init(hif_dev, fw_name);
867 goto err_hif_init_usb;
870 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev);
871 if (hif_dev->htc_handle == NULL) {
873 goto err_htc_hw_alloc;
876 ret = ath9k_htc_hw_init(&hif_usb, hif_dev->htc_handle, hif_dev,
877 &hif_dev->udev->dev, hif_dev->device_id,
881 goto err_htc_hw_init;
884 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
889 ath9k_htc_hw_free(hif_dev->htc_handle);
891 ath9k_hif_usb_dev_deinit(hif_dev);
893 usb_set_intfdata(interface, NULL);
900 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
902 struct usb_device *udev = interface_to_usbdev(interface);
903 struct hif_device_usb *hif_dev =
904 (struct hif_device_usb *) usb_get_intfdata(interface);
907 ath9k_htc_hw_deinit(hif_dev->htc_handle, true);
908 ath9k_htc_hw_free(hif_dev->htc_handle);
909 ath9k_hif_usb_dev_deinit(hif_dev);
910 usb_set_intfdata(interface, NULL);
913 if (hif_dev->flags & HIF_USB_START)
914 usb_reset_device(udev);
917 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
922 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
923 pm_message_t message)
925 struct hif_device_usb *hif_dev =
926 (struct hif_device_usb *) usb_get_intfdata(interface);
928 ath9k_hif_usb_dealloc_urbs(hif_dev);
933 static int ath9k_hif_usb_resume(struct usb_interface *interface)
935 struct hif_device_usb *hif_dev =
936 (struct hif_device_usb *) usb_get_intfdata(interface);
939 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
943 if (hif_dev->firmware) {
944 ret = ath9k_hif_usb_download_fw(hif_dev);
948 ath9k_hif_usb_dealloc_urbs(hif_dev);
954 ret = ath9k_htc_resume(hif_dev->htc_handle);
962 ath9k_hif_usb_dealloc_urbs(hif_dev);
968 static struct usb_driver ath9k_hif_usb_driver = {
969 .name = "ath9k_hif_usb",
970 .probe = ath9k_hif_usb_probe,
971 .disconnect = ath9k_hif_usb_disconnect,
973 .suspend = ath9k_hif_usb_suspend,
974 .resume = ath9k_hif_usb_resume,
975 .reset_resume = ath9k_hif_usb_resume,
977 .id_table = ath9k_hif_usb_ids,
981 int ath9k_hif_usb_init(void)
983 return usb_register(&ath9k_hif_usb_driver);
986 void ath9k_hif_usb_exit(void)
988 usb_deregister(&ath9k_hif_usb_driver);