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;
616 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
620 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
622 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
625 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
627 struct urb *urb = NULL;
628 struct sk_buff *skb = NULL;
631 init_usb_anchor(&hif_dev->rx_submitted);
632 spin_lock_init(&hif_dev->rx_lock);
634 for (i = 0; i < MAX_RX_URB_NUM; i++) {
637 urb = usb_alloc_urb(0, GFP_KERNEL);
643 /* Allocate buffer */
644 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
650 usb_fill_bulk_urb(urb, hif_dev->udev,
651 usb_rcvbulkpipe(hif_dev->udev,
653 skb->data, MAX_RX_BUF_SIZE,
654 ath9k_hif_usb_rx_cb, skb);
657 usb_anchor_urb(urb, &hif_dev->rx_submitted);
660 ret = usb_submit_urb(urb, GFP_KERNEL);
662 usb_unanchor_urb(urb);
667 * Drop reference count.
668 * This ensures that the URB is freed when killing them.
680 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
684 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
686 if (hif_dev->reg_in_urb) {
687 usb_kill_urb(hif_dev->reg_in_urb);
688 if (hif_dev->reg_in_urb->context)
689 kfree_skb((void *)hif_dev->reg_in_urb->context);
690 usb_free_urb(hif_dev->reg_in_urb);
691 hif_dev->reg_in_urb = NULL;
695 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
699 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
700 if (hif_dev->reg_in_urb == NULL)
703 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
707 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
708 usb_rcvintpipe(hif_dev->udev, USB_REG_IN_PIPE),
709 skb->data, MAX_REG_IN_BUF_SIZE,
710 ath9k_hif_usb_reg_in_cb, skb, 1);
712 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
718 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
722 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
725 init_usb_anchor(&hif_dev->regout_submitted);
728 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
732 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
736 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
741 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
743 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
748 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
750 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
751 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
752 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
753 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
756 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
759 const void *data = hif_dev->firmware->data;
760 size_t len = hif_dev->firmware->size;
761 u32 addr = AR9271_FIRMWARE;
762 u8 *buf = kzalloc(4096, GFP_KERNEL);
768 transfer = min_t(int, len, 4096);
769 memcpy(buf, data, transfer);
771 err = usb_control_msg(hif_dev->udev,
772 usb_sndctrlpipe(hif_dev->udev, 0),
773 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
774 addr >> 8, 0, buf, transfer, HZ);
787 * Issue FW download complete command to firmware.
789 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
790 FIRMWARE_DOWNLOAD_COMP,
792 AR9271_FIRMWARE_TEXT >> 8, 0, NULL, 0, HZ);
796 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
797 "ar9271.fw", (unsigned long) hif_dev->firmware->size);
802 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev,
807 /* Request firmware */
808 ret = request_firmware(&hif_dev->firmware, fw_name, &hif_dev->udev->dev);
810 dev_err(&hif_dev->udev->dev,
811 "ath9k_htc: Firmware - %s not found\n", fw_name);
816 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
818 dev_err(&hif_dev->udev->dev,
819 "ath9k_htc: Unable to allocate URBs\n");
823 /* Download firmware */
824 ret = ath9k_hif_usb_download_fw(hif_dev);
826 dev_err(&hif_dev->udev->dev,
827 "ath9k_htc: Firmware - %s download failed\n", fw_name);
828 goto err_fw_download;
834 ath9k_hif_usb_dealloc_urbs(hif_dev);
836 release_firmware(hif_dev->firmware);
838 hif_dev->firmware = NULL;
842 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
844 ath9k_hif_usb_dealloc_urbs(hif_dev);
845 if (hif_dev->firmware)
846 release_firmware(hif_dev->firmware);
849 static int ath9k_hif_usb_probe(struct usb_interface *interface,
850 const struct usb_device_id *id)
852 struct usb_device *udev = interface_to_usbdev(interface);
853 struct hif_device_usb *hif_dev;
854 const char *fw_name = (const char *) id->driver_info;
857 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
864 hif_dev->udev = udev;
865 hif_dev->interface = interface;
866 hif_dev->device_id = id->idProduct;
868 udev->reset_resume = 1;
870 usb_set_intfdata(interface, hif_dev);
872 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
873 &hif_dev->udev->dev);
874 if (hif_dev->htc_handle == NULL) {
876 goto err_htc_hw_alloc;
879 ret = ath9k_hif_usb_dev_init(hif_dev, fw_name);
882 goto err_hif_init_usb;
885 ret = ath9k_htc_hw_init(hif_dev->htc_handle,
886 &hif_dev->udev->dev, hif_dev->device_id);
889 goto err_htc_hw_init;
892 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
897 ath9k_hif_usb_dev_deinit(hif_dev);
899 ath9k_htc_hw_free(hif_dev->htc_handle);
901 usb_set_intfdata(interface, NULL);
908 static void ath9k_hif_usb_reboot(struct usb_device *udev)
910 u32 reboot_cmd = 0xffffffff;
914 buf = kmalloc(4, GFP_KERNEL);
918 memcpy(buf, &reboot_cmd, 4);
920 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
923 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
928 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
930 struct usb_device *udev = interface_to_usbdev(interface);
931 struct hif_device_usb *hif_dev =
932 (struct hif_device_usb *) usb_get_intfdata(interface);
935 ath9k_htc_hw_deinit(hif_dev->htc_handle,
936 (udev->state == USB_STATE_NOTATTACHED) ? true : false);
937 ath9k_htc_hw_free(hif_dev->htc_handle);
938 ath9k_hif_usb_dev_deinit(hif_dev);
939 usb_set_intfdata(interface, NULL);
942 if (hif_dev->flags & HIF_USB_START)
943 ath9k_hif_usb_reboot(udev);
946 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
951 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
952 pm_message_t message)
954 struct hif_device_usb *hif_dev =
955 (struct hif_device_usb *) usb_get_intfdata(interface);
957 ath9k_hif_usb_dealloc_urbs(hif_dev);
962 static int ath9k_hif_usb_resume(struct usb_interface *interface)
964 struct hif_device_usb *hif_dev =
965 (struct hif_device_usb *) usb_get_intfdata(interface);
968 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
972 if (hif_dev->firmware) {
973 ret = ath9k_hif_usb_download_fw(hif_dev);
977 ath9k_hif_usb_dealloc_urbs(hif_dev);
983 ret = ath9k_htc_resume(hif_dev->htc_handle);
991 ath9k_hif_usb_dealloc_urbs(hif_dev);
997 static struct usb_driver ath9k_hif_usb_driver = {
998 .name = "ath9k_hif_usb",
999 .probe = ath9k_hif_usb_probe,
1000 .disconnect = ath9k_hif_usb_disconnect,
1002 .suspend = ath9k_hif_usb_suspend,
1003 .resume = ath9k_hif_usb_resume,
1004 .reset_resume = ath9k_hif_usb_resume,
1006 .id_table = ath9k_hif_usb_ids,
1010 int ath9k_hif_usb_init(void)
1012 return usb_register(&ath9k_hif_usb_driver);
1015 void ath9k_hif_usb_exit(void)
1017 usb_deregister(&ath9k_hif_usb_driver);