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);
138 tx_buf->len = tx_buf->offset = 0;
139 __skb_queue_head_init(&tx_buf->skb_queue);
141 spin_lock(&hif_dev->tx.tx_lock);
142 list_del(&tx_buf->list);
143 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
144 hif_dev->tx.tx_buf_cnt++;
146 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
147 TX_STAT_INC(buf_completed);
148 spin_unlock(&hif_dev->tx.tx_lock);
152 static inline void ath9k_skb_queue_purge(struct sk_buff_head *list)
155 while ((skb = __skb_dequeue(list)) != NULL)
156 dev_kfree_skb_any(skb);
159 /* TX lock has to be taken */
160 static int __hif_usb_tx(struct hif_device_usb *hif_dev)
162 struct tx_buf *tx_buf = NULL;
163 struct sk_buff *nskb = NULL;
165 u16 *hdr, tx_skb_cnt = 0;
168 if (hif_dev->tx.tx_skb_cnt == 0)
171 /* Check if a free TX buffer is available */
172 if (list_empty(&hif_dev->tx.tx_buf))
175 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
176 list_del(&tx_buf->list);
177 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
178 hif_dev->tx.tx_buf_cnt--;
180 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
182 for (i = 0; i < tx_skb_cnt; i++) {
183 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
185 /* Should never be NULL */
188 hif_dev->tx.tx_skb_cnt--;
191 buf += tx_buf->offset;
194 *hdr++ = ATH_USB_TX_STREAM_MODE_TAG;
196 memcpy(buf, nskb->data, nskb->len);
197 tx_buf->len = nskb->len + 4;
199 if (i < (tx_skb_cnt - 1))
200 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
202 if (i == (tx_skb_cnt - 1))
203 tx_buf->len += tx_buf->offset;
205 __skb_queue_tail(&tx_buf->skb_queue, nskb);
206 TX_STAT_INC(skb_queued);
209 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
210 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
211 tx_buf->buf, tx_buf->len,
212 hif_usb_tx_cb, tx_buf);
214 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
216 tx_buf->len = tx_buf->offset = 0;
217 ath9k_skb_queue_purge(&tx_buf->skb_queue);
218 __skb_queue_head_init(&tx_buf->skb_queue);
219 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
220 hif_dev->tx.tx_buf_cnt++;
224 TX_STAT_INC(buf_queued);
229 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb,
230 struct ath9k_htc_tx_ctl *tx_ctl)
234 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
236 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
237 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
241 /* Check if the max queue count has been reached */
242 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
243 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
247 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
248 hif_dev->tx.tx_skb_cnt++;
250 /* Send normal frames immediately */
251 if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL)))
252 __hif_usb_tx(hif_dev);
254 /* Check if AMPDUs have to be sent immediately */
255 if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) &&
256 (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
257 (hif_dev->tx.tx_skb_cnt < 2)) {
258 __hif_usb_tx(hif_dev);
261 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
266 static void hif_usb_start(void *hif_handle, u8 pipe_id)
268 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
271 hif_dev->flags |= HIF_USB_START;
273 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
274 hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
275 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
278 static void hif_usb_stop(void *hif_handle, u8 pipe_id)
280 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
283 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
284 ath9k_skb_queue_purge(&hif_dev->tx.tx_skb_queue);
285 hif_dev->tx.tx_skb_cnt = 0;
286 hif_dev->tx.flags |= HIF_USB_TX_STOP;
287 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
290 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb,
291 struct ath9k_htc_tx_ctl *tx_ctl)
293 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
297 case USB_WLAN_TX_PIPE:
298 ret = hif_usb_send_tx(hif_dev, skb, tx_ctl);
300 case USB_REG_OUT_PIPE:
301 ret = hif_usb_send_regout(hif_dev, skb);
304 dev_err(&hif_dev->udev->dev,
305 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
313 static struct ath9k_htc_hif hif_usb = {
314 .transport = ATH9K_HIF_USB,
315 .name = "ath9k_hif_usb",
317 .control_ul_pipe = USB_REG_OUT_PIPE,
318 .control_dl_pipe = USB_REG_IN_PIPE,
320 .start = hif_usb_start,
321 .stop = hif_usb_stop,
322 .send = hif_usb_send,
325 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
328 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
329 int index = 0, i = 0, chk_idx, len = skb->len;
330 int rx_remain_len = 0, rx_pkt_len = 0;
331 u16 pkt_len, pkt_tag, pool_index = 0;
334 spin_lock(&hif_dev->rx_lock);
336 rx_remain_len = hif_dev->rx_remain_len;
337 rx_pkt_len = hif_dev->rx_transfer_len;
339 if (rx_remain_len != 0) {
340 struct sk_buff *remain_skb = hif_dev->remain_skb;
343 ptr = (u8 *) remain_skb->data;
345 index = rx_remain_len;
346 rx_remain_len -= hif_dev->rx_pad_len;
349 memcpy(ptr, skb->data, rx_remain_len);
351 rx_pkt_len += rx_remain_len;
352 hif_dev->rx_remain_len = 0;
353 skb_put(remain_skb, rx_pkt_len);
355 skb_pool[pool_index++] = remain_skb;
358 index = rx_remain_len;
362 spin_unlock(&hif_dev->rx_lock);
364 while (index < len) {
365 ptr = (u8 *) skb->data;
367 pkt_len = ptr[index] + (ptr[index+1] << 8);
368 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
370 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
373 pad_len = 4 - (pkt_len & 0x3);
378 index = index + 4 + pkt_len + pad_len;
380 if (index > MAX_RX_BUF_SIZE) {
381 spin_lock(&hif_dev->rx_lock);
382 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
383 hif_dev->rx_transfer_len =
384 MAX_RX_BUF_SIZE - chk_idx - 4;
385 hif_dev->rx_pad_len = pad_len;
387 nskb = __dev_alloc_skb(pkt_len + 32,
390 dev_err(&hif_dev->udev->dev,
391 "ath9k_htc: RX memory allocation"
393 spin_unlock(&hif_dev->rx_lock);
396 skb_reserve(nskb, 32);
397 RX_STAT_INC(skb_allocated);
399 memcpy(nskb->data, &(skb->data[chk_idx+4]),
400 hif_dev->rx_transfer_len);
402 /* Record the buffer pointer */
403 hif_dev->remain_skb = nskb;
404 spin_unlock(&hif_dev->rx_lock);
406 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
408 dev_err(&hif_dev->udev->dev,
409 "ath9k_htc: RX memory allocation"
413 skb_reserve(nskb, 32);
414 RX_STAT_INC(skb_allocated);
416 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
417 skb_put(nskb, pkt_len);
418 skb_pool[pool_index++] = nskb;
421 RX_STAT_INC(skb_dropped);
427 for (i = 0; i < pool_index; i++) {
428 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
429 skb_pool[i]->len, USB_WLAN_RX_PIPE);
430 RX_STAT_INC(skb_completed);
434 static void ath9k_hif_usb_rx_cb(struct urb *urb)
436 struct sk_buff *skb = (struct sk_buff *) urb->context;
437 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
438 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
447 switch (urb->status) {
459 if (likely(urb->actual_length != 0)) {
460 skb_put(skb, urb->actual_length);
461 ath9k_hif_usb_rx_stream(hif_dev, skb);
465 skb_reset_tail_pointer(skb);
468 usb_anchor_urb(urb, &hif_dev->rx_submitted);
469 ret = usb_submit_urb(urb, GFP_ATOMIC);
471 usb_unanchor_urb(urb);
480 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
482 struct sk_buff *skb = (struct sk_buff *) urb->context;
483 struct sk_buff *nskb;
484 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
485 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
494 switch (urb->status) {
506 if (likely(urb->actual_length != 0)) {
507 skb_put(skb, urb->actual_length);
509 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
513 usb_fill_int_urb(urb, hif_dev->udev,
514 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
515 nskb->data, MAX_REG_IN_BUF_SIZE,
516 ath9k_hif_usb_reg_in_cb, nskb, 1);
518 ret = usb_submit_urb(urb, GFP_ATOMIC);
524 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
525 skb->len, USB_REG_IN_PIPE);
531 skb_reset_tail_pointer(skb);
534 ret = usb_submit_urb(urb, GFP_ATOMIC);
544 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
547 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
549 list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_buf, list) {
550 list_del(&tx_buf->list);
551 usb_free_urb(tx_buf->urb);
556 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
557 hif_dev->tx.flags |= HIF_USB_TX_FLUSH;
558 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
560 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
561 &hif_dev->tx.tx_pending, list) {
562 usb_kill_urb(tx_buf->urb);
563 list_del(&tx_buf->list);
564 usb_free_urb(tx_buf->urb);
569 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
570 hif_dev->tx.flags &= ~HIF_USB_TX_FLUSH;
571 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
574 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
576 struct tx_buf *tx_buf;
579 INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
580 INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
581 spin_lock_init(&hif_dev->tx.tx_lock);
582 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
584 for (i = 0; i < MAX_TX_URB_NUM; i++) {
585 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
589 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
593 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
597 tx_buf->hif_dev = hif_dev;
598 __skb_queue_head_init(&tx_buf->skb_queue);
600 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
603 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
607 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
611 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
613 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
616 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
618 struct urb *urb = NULL;
619 struct sk_buff *skb = NULL;
622 init_usb_anchor(&hif_dev->rx_submitted);
623 spin_lock_init(&hif_dev->rx_lock);
625 for (i = 0; i < MAX_RX_URB_NUM; i++) {
628 urb = usb_alloc_urb(0, GFP_KERNEL);
634 /* Allocate buffer */
635 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
641 usb_fill_bulk_urb(urb, hif_dev->udev,
642 usb_rcvbulkpipe(hif_dev->udev,
644 skb->data, MAX_RX_BUF_SIZE,
645 ath9k_hif_usb_rx_cb, skb);
648 usb_anchor_urb(urb, &hif_dev->rx_submitted);
651 ret = usb_submit_urb(urb, GFP_KERNEL);
653 usb_unanchor_urb(urb);
658 * Drop reference count.
659 * This ensures that the URB is freed when killing them.
671 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
675 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
677 if (hif_dev->reg_in_urb) {
678 usb_kill_urb(hif_dev->reg_in_urb);
679 if (hif_dev->reg_in_urb->context)
680 kfree_skb((void *)hif_dev->reg_in_urb->context);
681 usb_free_urb(hif_dev->reg_in_urb);
682 hif_dev->reg_in_urb = NULL;
686 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
690 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
691 if (hif_dev->reg_in_urb == NULL)
694 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
698 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
699 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
700 skb->data, MAX_REG_IN_BUF_SIZE,
701 ath9k_hif_usb_reg_in_cb, skb, 1);
703 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
709 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
713 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
716 init_usb_anchor(&hif_dev->regout_submitted);
719 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
723 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
727 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
735 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
738 const void *data = hif_dev->firmware->data;
739 size_t len = hif_dev->firmware->size;
740 u32 addr = AR9271_FIRMWARE;
741 u8 *buf = kzalloc(4096, GFP_KERNEL);
747 transfer = min_t(int, len, 4096);
748 memcpy(buf, data, transfer);
750 err = usb_control_msg(hif_dev->udev,
751 usb_sndctrlpipe(hif_dev->udev, 0),
752 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
753 addr >> 8, 0, buf, transfer, HZ);
766 * Issue FW download complete command to firmware.
768 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
769 FIRMWARE_DOWNLOAD_COMP,
771 AR9271_FIRMWARE_TEXT >> 8, 0, NULL, 0, HZ);
775 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
776 "ar9271.fw", (unsigned long) hif_dev->firmware->size);
781 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev,
786 /* Request firmware */
787 ret = request_firmware(&hif_dev->firmware, fw_name, &hif_dev->udev->dev);
789 dev_err(&hif_dev->udev->dev,
790 "ath9k_htc: Firmware - %s not found\n", fw_name);
794 /* Download firmware */
795 ret = ath9k_hif_usb_download_fw(hif_dev);
797 dev_err(&hif_dev->udev->dev,
798 "ath9k_htc: Firmware - %s download failed\n", fw_name);
799 goto err_fw_download;
803 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
805 dev_err(&hif_dev->udev->dev,
806 "ath9k_htc: Unable to allocate URBs\n");
815 release_firmware(hif_dev->firmware);
817 hif_dev->firmware = NULL;
821 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
823 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
824 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
825 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
826 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
829 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
831 ath9k_hif_usb_dealloc_urbs(hif_dev);
832 if (hif_dev->firmware)
833 release_firmware(hif_dev->firmware);
836 static int ath9k_hif_usb_probe(struct usb_interface *interface,
837 const struct usb_device_id *id)
839 struct usb_device *udev = interface_to_usbdev(interface);
840 struct hif_device_usb *hif_dev;
841 const char *fw_name = (const char *) id->driver_info;
844 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
851 hif_dev->udev = udev;
852 hif_dev->interface = interface;
853 hif_dev->device_id = id->idProduct;
855 udev->reset_resume = 1;
857 usb_set_intfdata(interface, hif_dev);
859 ret = ath9k_hif_usb_dev_init(hif_dev, fw_name);
862 goto err_hif_init_usb;
865 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev);
866 if (hif_dev->htc_handle == NULL) {
868 goto err_htc_hw_alloc;
871 ret = ath9k_htc_hw_init(&hif_usb, hif_dev->htc_handle, hif_dev,
872 &hif_dev->udev->dev, hif_dev->device_id,
876 goto err_htc_hw_init;
879 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
884 ath9k_htc_hw_free(hif_dev->htc_handle);
886 ath9k_hif_usb_dev_deinit(hif_dev);
888 usb_set_intfdata(interface, NULL);
895 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
897 struct usb_device *udev = interface_to_usbdev(interface);
898 struct hif_device_usb *hif_dev =
899 (struct hif_device_usb *) usb_get_intfdata(interface);
902 ath9k_htc_hw_deinit(hif_dev->htc_handle, true);
903 ath9k_htc_hw_free(hif_dev->htc_handle);
904 ath9k_hif_usb_dev_deinit(hif_dev);
905 usb_set_intfdata(interface, NULL);
908 if (hif_dev->flags & HIF_USB_START)
909 usb_reset_device(udev);
912 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
917 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
918 pm_message_t message)
920 struct hif_device_usb *hif_dev =
921 (struct hif_device_usb *) usb_get_intfdata(interface);
923 ath9k_hif_usb_dealloc_urbs(hif_dev);
928 static int ath9k_hif_usb_resume(struct usb_interface *interface)
930 struct hif_device_usb *hif_dev =
931 (struct hif_device_usb *) usb_get_intfdata(interface);
934 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
938 if (hif_dev->firmware) {
939 ret = ath9k_hif_usb_download_fw(hif_dev);
943 ath9k_hif_usb_dealloc_urbs(hif_dev);
949 ret = ath9k_htc_resume(hif_dev->htc_handle);
957 ath9k_hif_usb_dealloc_urbs(hif_dev);
963 static struct usb_driver ath9k_hif_usb_driver = {
964 .name = "ath9k_hif_usb",
965 .probe = ath9k_hif_usb_probe,
966 .disconnect = ath9k_hif_usb_disconnect,
968 .suspend = ath9k_hif_usb_suspend,
969 .resume = ath9k_hif_usb_resume,
970 .reset_resume = ath9k_hif_usb_resume,
972 .id_table = ath9k_hif_usb_ids,
976 int ath9k_hif_usb_init(void)
978 return usb_register(&ath9k_hif_usb_driver);
981 void ath9k_hif_usb_exit(void)
983 usb_deregister(&ath9k_hif_usb_driver);