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 inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
97 struct sk_buff_head *list)
101 while ((skb = __skb_dequeue(list)) != NULL) {
102 dev_kfree_skb_any(skb);
103 TX_STAT_INC(skb_dropped);
107 static void hif_usb_tx_cb(struct urb *urb)
109 struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
110 struct hif_device_usb *hif_dev;
113 if (!tx_buf || !tx_buf->hif_dev)
116 hif_dev = tx_buf->hif_dev;
118 switch (urb->status) {
126 * The URB has been killed, free the SKBs
129 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
135 /* Check if TX has been stopped */
136 spin_lock(&hif_dev->tx.tx_lock);
137 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
138 spin_unlock(&hif_dev->tx.tx_lock);
139 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
142 spin_unlock(&hif_dev->tx.tx_lock);
144 /* Complete the queued SKBs. */
145 while ((skb = __skb_dequeue(&tx_buf->skb_queue)) != NULL) {
146 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
148 TX_STAT_INC(skb_completed);
152 /* Re-initialize the SKB queue */
153 tx_buf->len = tx_buf->offset = 0;
154 __skb_queue_head_init(&tx_buf->skb_queue);
156 /* Add this TX buffer to the free list */
157 spin_lock(&hif_dev->tx.tx_lock);
158 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
159 hif_dev->tx.tx_buf_cnt++;
160 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
161 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
162 TX_STAT_INC(buf_completed);
163 spin_unlock(&hif_dev->tx.tx_lock);
166 /* TX lock has to be taken */
167 static int __hif_usb_tx(struct hif_device_usb *hif_dev)
169 struct tx_buf *tx_buf = NULL;
170 struct sk_buff *nskb = NULL;
172 u16 *hdr, tx_skb_cnt = 0;
175 if (hif_dev->tx.tx_skb_cnt == 0)
178 /* Check if a free TX buffer is available */
179 if (list_empty(&hif_dev->tx.tx_buf))
182 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
183 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
184 hif_dev->tx.tx_buf_cnt--;
186 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
188 for (i = 0; i < tx_skb_cnt; i++) {
189 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
191 /* Should never be NULL */
194 hif_dev->tx.tx_skb_cnt--;
197 buf += tx_buf->offset;
200 *hdr++ = ATH_USB_TX_STREAM_MODE_TAG;
202 memcpy(buf, nskb->data, nskb->len);
203 tx_buf->len = nskb->len + 4;
205 if (i < (tx_skb_cnt - 1))
206 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
208 if (i == (tx_skb_cnt - 1))
209 tx_buf->len += tx_buf->offset;
211 __skb_queue_tail(&tx_buf->skb_queue, nskb);
212 TX_STAT_INC(skb_queued);
215 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
216 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
217 tx_buf->buf, tx_buf->len,
218 hif_usb_tx_cb, tx_buf);
220 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
222 tx_buf->len = tx_buf->offset = 0;
223 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
224 __skb_queue_head_init(&tx_buf->skb_queue);
225 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
226 hif_dev->tx.tx_buf_cnt++;
230 TX_STAT_INC(buf_queued);
235 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb,
236 struct ath9k_htc_tx_ctl *tx_ctl)
240 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
242 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
243 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
247 /* Check if the max queue count has been reached */
248 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
249 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
253 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
254 hif_dev->tx.tx_skb_cnt++;
256 /* Send normal frames immediately */
257 if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL)))
258 __hif_usb_tx(hif_dev);
260 /* Check if AMPDUs have to be sent immediately */
261 if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) &&
262 (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
263 (hif_dev->tx.tx_skb_cnt < 2)) {
264 __hif_usb_tx(hif_dev);
267 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
272 static void hif_usb_start(void *hif_handle, u8 pipe_id)
274 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
277 hif_dev->flags |= HIF_USB_START;
279 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
280 hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
281 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
284 static void hif_usb_stop(void *hif_handle, u8 pipe_id)
286 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
289 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
290 ath9k_skb_queue_purge(hif_dev, &hif_dev->tx.tx_skb_queue);
291 hif_dev->tx.tx_skb_cnt = 0;
292 hif_dev->tx.flags |= HIF_USB_TX_STOP;
293 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
296 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb,
297 struct ath9k_htc_tx_ctl *tx_ctl)
299 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
303 case USB_WLAN_TX_PIPE:
304 ret = hif_usb_send_tx(hif_dev, skb, tx_ctl);
306 case USB_REG_OUT_PIPE:
307 ret = hif_usb_send_regout(hif_dev, skb);
310 dev_err(&hif_dev->udev->dev,
311 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
319 static struct ath9k_htc_hif hif_usb = {
320 .transport = ATH9K_HIF_USB,
321 .name = "ath9k_hif_usb",
323 .control_ul_pipe = USB_REG_OUT_PIPE,
324 .control_dl_pipe = USB_REG_IN_PIPE,
326 .start = hif_usb_start,
327 .stop = hif_usb_stop,
328 .send = hif_usb_send,
331 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
334 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
335 int index = 0, i = 0, chk_idx, len = skb->len;
336 int rx_remain_len = 0, rx_pkt_len = 0;
337 u16 pkt_len, pkt_tag, pool_index = 0;
340 spin_lock(&hif_dev->rx_lock);
342 rx_remain_len = hif_dev->rx_remain_len;
343 rx_pkt_len = hif_dev->rx_transfer_len;
345 if (rx_remain_len != 0) {
346 struct sk_buff *remain_skb = hif_dev->remain_skb;
349 ptr = (u8 *) remain_skb->data;
351 index = rx_remain_len;
352 rx_remain_len -= hif_dev->rx_pad_len;
355 memcpy(ptr, skb->data, rx_remain_len);
357 rx_pkt_len += rx_remain_len;
358 hif_dev->rx_remain_len = 0;
359 skb_put(remain_skb, rx_pkt_len);
361 skb_pool[pool_index++] = remain_skb;
364 index = rx_remain_len;
368 spin_unlock(&hif_dev->rx_lock);
370 while (index < len) {
371 ptr = (u8 *) skb->data;
373 pkt_len = ptr[index] + (ptr[index+1] << 8);
374 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
376 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
379 pad_len = 4 - (pkt_len & 0x3);
384 index = index + 4 + pkt_len + pad_len;
386 if (index > MAX_RX_BUF_SIZE) {
387 spin_lock(&hif_dev->rx_lock);
388 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
389 hif_dev->rx_transfer_len =
390 MAX_RX_BUF_SIZE - chk_idx - 4;
391 hif_dev->rx_pad_len = pad_len;
393 nskb = __dev_alloc_skb(pkt_len + 32,
396 dev_err(&hif_dev->udev->dev,
397 "ath9k_htc: RX memory allocation"
399 spin_unlock(&hif_dev->rx_lock);
402 skb_reserve(nskb, 32);
403 RX_STAT_INC(skb_allocated);
405 memcpy(nskb->data, &(skb->data[chk_idx+4]),
406 hif_dev->rx_transfer_len);
408 /* Record the buffer pointer */
409 hif_dev->remain_skb = nskb;
410 spin_unlock(&hif_dev->rx_lock);
412 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
414 dev_err(&hif_dev->udev->dev,
415 "ath9k_htc: RX memory allocation"
419 skb_reserve(nskb, 32);
420 RX_STAT_INC(skb_allocated);
422 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
423 skb_put(nskb, pkt_len);
424 skb_pool[pool_index++] = nskb;
427 RX_STAT_INC(skb_dropped);
433 for (i = 0; i < pool_index; i++) {
434 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
435 skb_pool[i]->len, USB_WLAN_RX_PIPE);
436 RX_STAT_INC(skb_completed);
440 static void ath9k_hif_usb_rx_cb(struct urb *urb)
442 struct sk_buff *skb = (struct sk_buff *) urb->context;
443 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
444 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
453 switch (urb->status) {
465 if (likely(urb->actual_length != 0)) {
466 skb_put(skb, urb->actual_length);
467 ath9k_hif_usb_rx_stream(hif_dev, skb);
471 skb_reset_tail_pointer(skb);
474 usb_anchor_urb(urb, &hif_dev->rx_submitted);
475 ret = usb_submit_urb(urb, GFP_ATOMIC);
477 usb_unanchor_urb(urb);
486 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
488 struct sk_buff *skb = (struct sk_buff *) urb->context;
489 struct sk_buff *nskb;
490 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
491 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
500 switch (urb->status) {
512 if (likely(urb->actual_length != 0)) {
513 skb_put(skb, urb->actual_length);
515 /* Process the command first */
516 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
517 skb->len, USB_REG_IN_PIPE);
520 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
522 dev_err(&hif_dev->udev->dev,
523 "ath9k_htc: REG_IN memory allocation failure\n");
528 usb_fill_int_urb(urb, hif_dev->udev,
529 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
530 nskb->data, MAX_REG_IN_BUF_SIZE,
531 ath9k_hif_usb_reg_in_cb, nskb, 1);
533 ret = usb_submit_urb(urb, GFP_ATOMIC);
543 skb_reset_tail_pointer(skb);
546 ret = usb_submit_urb(urb, GFP_ATOMIC);
556 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
558 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
560 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
561 &hif_dev->tx.tx_buf, list) {
562 usb_kill_urb(tx_buf->urb);
563 list_del(&tx_buf->list);
564 usb_free_urb(tx_buf->urb);
569 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
570 &hif_dev->tx.tx_pending, list) {
571 usb_kill_urb(tx_buf->urb);
572 list_del(&tx_buf->list);
573 usb_free_urb(tx_buf->urb);
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 void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
742 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
743 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
744 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
745 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
748 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
751 const void *data = hif_dev->firmware->data;
752 size_t len = hif_dev->firmware->size;
753 u32 addr = AR9271_FIRMWARE;
754 u8 *buf = kzalloc(4096, GFP_KERNEL);
760 transfer = min_t(int, len, 4096);
761 memcpy(buf, data, transfer);
763 err = usb_control_msg(hif_dev->udev,
764 usb_sndctrlpipe(hif_dev->udev, 0),
765 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
766 addr >> 8, 0, buf, transfer, HZ);
779 * Issue FW download complete command to firmware.
781 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
782 FIRMWARE_DOWNLOAD_COMP,
784 AR9271_FIRMWARE_TEXT >> 8, 0, NULL, 0, HZ);
788 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
789 "ar9271.fw", (unsigned long) hif_dev->firmware->size);
794 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev,
799 /* Request firmware */
800 ret = request_firmware(&hif_dev->firmware, fw_name, &hif_dev->udev->dev);
802 dev_err(&hif_dev->udev->dev,
803 "ath9k_htc: Firmware - %s not found\n", fw_name);
808 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
810 dev_err(&hif_dev->udev->dev,
811 "ath9k_htc: Unable to allocate URBs\n");
815 /* Download firmware */
816 ret = ath9k_hif_usb_download_fw(hif_dev);
818 dev_err(&hif_dev->udev->dev,
819 "ath9k_htc: Firmware - %s download failed\n", fw_name);
820 goto err_fw_download;
826 ath9k_hif_usb_dealloc_urbs(hif_dev);
828 release_firmware(hif_dev->firmware);
830 hif_dev->firmware = NULL;
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 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
865 &hif_dev->udev->dev);
866 if (hif_dev->htc_handle == NULL) {
868 goto err_htc_hw_alloc;
871 ret = ath9k_hif_usb_dev_init(hif_dev, fw_name);
874 goto err_hif_init_usb;
877 ret = ath9k_htc_hw_init(hif_dev->htc_handle,
878 &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_hif_usb_dev_deinit(hif_dev);
891 ath9k_htc_hw_free(hif_dev->htc_handle);
893 usb_set_intfdata(interface, NULL);
900 static void ath9k_hif_usb_reboot(struct usb_device *udev)
902 u32 reboot_cmd = 0xffffffff;
906 buf = kmalloc(4, GFP_KERNEL);
910 memcpy(buf, &reboot_cmd, 4);
912 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
915 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
920 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
922 struct usb_device *udev = interface_to_usbdev(interface);
923 struct hif_device_usb *hif_dev =
924 (struct hif_device_usb *) usb_get_intfdata(interface);
927 ath9k_htc_hw_deinit(hif_dev->htc_handle,
928 (udev->state == USB_STATE_NOTATTACHED) ? true : false);
929 ath9k_htc_hw_free(hif_dev->htc_handle);
930 ath9k_hif_usb_dev_deinit(hif_dev);
931 usb_set_intfdata(interface, NULL);
934 if (hif_dev->flags & HIF_USB_START)
935 ath9k_hif_usb_reboot(udev);
938 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
943 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
944 pm_message_t message)
946 struct hif_device_usb *hif_dev =
947 (struct hif_device_usb *) usb_get_intfdata(interface);
949 ath9k_hif_usb_dealloc_urbs(hif_dev);
954 static int ath9k_hif_usb_resume(struct usb_interface *interface)
956 struct hif_device_usb *hif_dev =
957 (struct hif_device_usb *) usb_get_intfdata(interface);
960 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
964 if (hif_dev->firmware) {
965 ret = ath9k_hif_usb_download_fw(hif_dev);
969 ath9k_hif_usb_dealloc_urbs(hif_dev);
975 ret = ath9k_htc_resume(hif_dev->htc_handle);
983 ath9k_hif_usb_dealloc_urbs(hif_dev);
989 static struct usb_driver ath9k_hif_usb_driver = {
990 .name = "ath9k_hif_usb",
991 .probe = ath9k_hif_usb_probe,
992 .disconnect = ath9k_hif_usb_disconnect,
994 .suspend = ath9k_hif_usb_suspend,
995 .resume = ath9k_hif_usb_resume,
996 .reset_resume = ath9k_hif_usb_resume,
998 .id_table = ath9k_hif_usb_ids,
1002 int ath9k_hif_usb_init(void)
1004 return usb_register(&ath9k_hif_usb_driver);
1007 void ath9k_hif_usb_exit(void)
1009 usb_deregister(&ath9k_hif_usb_driver);