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 rx_remain_len = hif_dev->rx_remain_len;
334 rx_pkt_len = hif_dev->rx_transfer_len;
336 if (rx_remain_len != 0) {
337 struct sk_buff *remain_skb = hif_dev->remain_skb;
340 ptr = (u8 *) remain_skb->data;
342 index = rx_remain_len;
343 rx_remain_len -= hif_dev->rx_pad_len;
346 memcpy(ptr, skb->data, rx_remain_len);
348 rx_pkt_len += rx_remain_len;
349 hif_dev->rx_remain_len = 0;
350 skb_put(remain_skb, rx_pkt_len);
352 skb_pool[pool_index++] = remain_skb;
355 index = rx_remain_len;
359 while (index < len) {
360 ptr = (u8 *) skb->data;
362 pkt_len = ptr[index] + (ptr[index+1] << 8);
363 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
365 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
368 pad_len = 4 - (pkt_len & 0x3);
373 index = index + 4 + pkt_len + pad_len;
375 if (index > MAX_RX_BUF_SIZE) {
376 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
377 hif_dev->rx_transfer_len =
378 MAX_RX_BUF_SIZE - chk_idx - 4;
379 hif_dev->rx_pad_len = pad_len;
381 nskb = __dev_alloc_skb(pkt_len + 32,
384 dev_err(&hif_dev->udev->dev,
385 "ath9k_htc: RX memory allocation"
389 skb_reserve(nskb, 32);
390 RX_STAT_INC(skb_allocated);
392 memcpy(nskb->data, &(skb->data[chk_idx+4]),
393 hif_dev->rx_transfer_len);
395 /* Record the buffer pointer */
396 hif_dev->remain_skb = nskb;
398 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
400 dev_err(&hif_dev->udev->dev,
401 "ath9k_htc: RX memory allocation"
405 skb_reserve(nskb, 32);
406 RX_STAT_INC(skb_allocated);
408 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
409 skb_put(nskb, pkt_len);
410 skb_pool[pool_index++] = nskb;
413 RX_STAT_INC(skb_dropped);
419 for (i = 0; i < pool_index; i++) {
420 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
421 skb_pool[i]->len, USB_WLAN_RX_PIPE);
422 RX_STAT_INC(skb_completed);
426 static void ath9k_hif_usb_rx_cb(struct urb *urb)
428 struct sk_buff *skb = (struct sk_buff *) urb->context;
429 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
430 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
439 switch (urb->status) {
451 if (likely(urb->actual_length != 0)) {
452 skb_put(skb, urb->actual_length);
453 ath9k_hif_usb_rx_stream(hif_dev, skb);
457 skb_reset_tail_pointer(skb);
460 usb_anchor_urb(urb, &hif_dev->rx_submitted);
461 ret = usb_submit_urb(urb, GFP_ATOMIC);
463 usb_unanchor_urb(urb);
469 dev_kfree_skb_any(skb);
472 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
474 struct sk_buff *skb = (struct sk_buff *) urb->context;
475 struct sk_buff *nskb;
476 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
477 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
486 switch (urb->status) {
498 if (likely(urb->actual_length != 0)) {
499 skb_put(skb, urb->actual_length);
501 nskb = __dev_alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
505 usb_fill_int_urb(urb, hif_dev->udev,
506 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
507 nskb->data, MAX_REG_IN_BUF_SIZE,
508 ath9k_hif_usb_reg_in_cb, nskb, 1);
510 ret = usb_submit_urb(urb, GFP_ATOMIC);
512 dev_kfree_skb_any(nskb);
516 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
517 skb->len, USB_REG_IN_PIPE);
523 skb_reset_tail_pointer(skb);
526 ret = usb_submit_urb(urb, GFP_ATOMIC);
532 dev_kfree_skb_any(skb);
536 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
539 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
541 list_for_each_entry_safe(tx_buf, tx_buf_tmp, &hif_dev->tx.tx_buf, list) {
542 list_del(&tx_buf->list);
543 usb_free_urb(tx_buf->urb);
548 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
549 hif_dev->tx.flags |= HIF_USB_TX_FLUSH;
550 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
552 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
553 &hif_dev->tx.tx_pending, list) {
554 usb_kill_urb(tx_buf->urb);
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);
566 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
568 struct tx_buf *tx_buf;
571 INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
572 INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
573 spin_lock_init(&hif_dev->tx.tx_lock);
574 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
576 for (i = 0; i < MAX_TX_URB_NUM; i++) {
577 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
581 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
585 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
589 tx_buf->hif_dev = hif_dev;
590 __skb_queue_head_init(&tx_buf->skb_queue);
592 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
595 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
599 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
603 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
605 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
608 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
610 struct urb *urb = NULL;
611 struct sk_buff *skb = NULL;
614 init_usb_anchor(&hif_dev->rx_submitted);
616 for (i = 0; i < MAX_RX_URB_NUM; i++) {
619 urb = usb_alloc_urb(0, GFP_KERNEL);
625 /* Allocate buffer */
626 skb = __dev_alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
632 usb_fill_bulk_urb(urb, hif_dev->udev,
633 usb_rcvbulkpipe(hif_dev->udev,
635 skb->data, MAX_RX_BUF_SIZE,
636 ath9k_hif_usb_rx_cb, skb);
639 usb_anchor_urb(urb, &hif_dev->rx_submitted);
642 ret = usb_submit_urb(urb, GFP_KERNEL);
644 usb_unanchor_urb(urb);
652 dev_kfree_skb_any(skb);
656 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
660 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
662 if (hif_dev->reg_in_urb) {
663 usb_kill_urb(hif_dev->reg_in_urb);
664 if (hif_dev->reg_in_urb->context)
665 dev_kfree_skb_any((void *)hif_dev->reg_in_urb->context);
666 usb_free_urb(hif_dev->reg_in_urb);
667 hif_dev->reg_in_urb = NULL;
671 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
675 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
676 if (hif_dev->reg_in_urb == NULL)
679 skb = __dev_alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
683 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
684 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
685 skb->data, MAX_REG_IN_BUF_SIZE,
686 ath9k_hif_usb_reg_in_cb, skb, 1);
688 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
694 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
698 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
701 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
705 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
708 /* Register Read/Write */
709 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
717 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
720 const void *data = hif_dev->firmware->data;
721 size_t len = hif_dev->firmware->size;
722 u32 addr = AR9271_FIRMWARE;
723 u8 *buf = kzalloc(4096, GFP_KERNEL);
729 transfer = min_t(int, len, 4096);
730 memcpy(buf, data, transfer);
732 err = usb_control_msg(hif_dev->udev,
733 usb_sndctrlpipe(hif_dev->udev, 0),
734 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
735 addr >> 8, 0, buf, transfer, HZ);
748 * Issue FW download complete command to firmware.
750 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
751 FIRMWARE_DOWNLOAD_COMP,
753 AR9271_FIRMWARE_TEXT >> 8, 0, NULL, 0, HZ);
757 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
758 "ar9271.fw", (unsigned long) hif_dev->firmware->size);
763 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev,
768 /* Request firmware */
769 ret = request_firmware(&hif_dev->firmware, fw_name, &hif_dev->udev->dev);
771 dev_err(&hif_dev->udev->dev,
772 "ath9k_htc: Firmware - %s not found\n", fw_name);
776 /* Download firmware */
777 ret = ath9k_hif_usb_download_fw(hif_dev);
779 dev_err(&hif_dev->udev->dev,
780 "ath9k_htc: Firmware - %s download failed\n", fw_name);
781 goto err_fw_download;
785 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
787 dev_err(&hif_dev->udev->dev,
788 "ath9k_htc: Unable to allocate URBs\n");
797 release_firmware(hif_dev->firmware);
799 hif_dev->firmware = NULL;
803 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
805 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
806 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
807 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
810 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
812 ath9k_hif_usb_dealloc_urbs(hif_dev);
813 if (hif_dev->firmware)
814 release_firmware(hif_dev->firmware);
817 static int ath9k_hif_usb_probe(struct usb_interface *interface,
818 const struct usb_device_id *id)
820 struct usb_device *udev = interface_to_usbdev(interface);
821 struct hif_device_usb *hif_dev;
822 const char *fw_name = (const char *) id->driver_info;
825 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
832 hif_dev->udev = udev;
833 hif_dev->interface = interface;
834 hif_dev->device_id = id->idProduct;
836 udev->reset_resume = 1;
838 usb_set_intfdata(interface, hif_dev);
840 ret = ath9k_hif_usb_dev_init(hif_dev, fw_name);
843 goto err_hif_init_usb;
846 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev);
847 if (hif_dev->htc_handle == NULL) {
849 goto err_htc_hw_alloc;
852 ret = ath9k_htc_hw_init(&hif_usb, hif_dev->htc_handle, hif_dev,
853 &hif_dev->udev->dev, hif_dev->device_id,
857 goto err_htc_hw_init;
860 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
865 ath9k_htc_hw_free(hif_dev->htc_handle);
867 ath9k_hif_usb_dev_deinit(hif_dev);
869 usb_set_intfdata(interface, NULL);
876 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
878 struct usb_device *udev = interface_to_usbdev(interface);
879 struct hif_device_usb *hif_dev =
880 (struct hif_device_usb *) usb_get_intfdata(interface);
883 ath9k_htc_hw_deinit(hif_dev->htc_handle, true);
884 ath9k_htc_hw_free(hif_dev->htc_handle);
885 ath9k_hif_usb_dev_deinit(hif_dev);
886 usb_set_intfdata(interface, NULL);
889 if (hif_dev->flags & HIF_USB_START)
890 usb_reset_device(udev);
893 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
898 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
899 pm_message_t message)
901 struct hif_device_usb *hif_dev =
902 (struct hif_device_usb *) usb_get_intfdata(interface);
904 ath9k_hif_usb_dealloc_urbs(hif_dev);
909 static int ath9k_hif_usb_resume(struct usb_interface *interface)
911 struct hif_device_usb *hif_dev =
912 (struct hif_device_usb *) usb_get_intfdata(interface);
915 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
919 if (hif_dev->firmware) {
920 ret = ath9k_hif_usb_download_fw(hif_dev);
924 ath9k_hif_usb_dealloc_urbs(hif_dev);
930 ret = ath9k_htc_resume(hif_dev->htc_handle);
938 ath9k_hif_usb_dealloc_urbs(hif_dev);
944 static struct usb_driver ath9k_hif_usb_driver = {
945 .name = "ath9k_hif_usb",
946 .probe = ath9k_hif_usb_probe,
947 .disconnect = ath9k_hif_usb_disconnect,
949 .suspend = ath9k_hif_usb_suspend,
950 .resume = ath9k_hif_usb_resume,
951 .reset_resume = ath9k_hif_usb_resume,
953 .id_table = ath9k_hif_usb_ids,
957 int ath9k_hif_usb_init(void)
959 return usb_register(&ath9k_hif_usb_driver);
962 void ath9k_hif_usb_exit(void)
964 usb_deregister(&ath9k_hif_usb_driver);