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 /* identify firmware images */
20 #define FIRMWARE_AR7010 "ar7010.fw"
21 #define FIRMWARE_AR7010_1_1 "ar7010_1_1.fw"
22 #define FIRMWARE_AR9271 "ar9271.fw"
24 MODULE_FIRMWARE(FIRMWARE_AR7010);
25 MODULE_FIRMWARE(FIRMWARE_AR7010_1_1);
26 MODULE_FIRMWARE(FIRMWARE_AR9271);
28 static struct usb_device_id ath9k_hif_usb_ids[] = {
29 { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */
30 { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */
31 { USB_DEVICE(0x0cf3, 0x7010) }, /* Atheros */
32 { USB_DEVICE(0x0cf3, 0x7015) }, /* Atheros */
33 { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */
34 { USB_DEVICE(0x0846, 0x9018) }, /* Netgear WNDA3200 */
35 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */
36 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
37 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */
38 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
39 { USB_DEVICE(0x083A, 0xA704) }, /* SMC Networks */
43 MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids);
45 static int __hif_usb_tx(struct hif_device_usb *hif_dev);
47 static void hif_usb_regout_cb(struct urb *urb)
49 struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
51 switch (urb->status) {
64 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
75 static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
82 urb = usb_alloc_urb(0, GFP_KERNEL);
86 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
93 cmd->hif_dev = hif_dev;
95 usb_fill_bulk_urb(urb, hif_dev->udev,
96 usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE),
98 hif_usb_regout_cb, cmd);
100 usb_anchor_urb(urb, &hif_dev->regout_submitted);
101 ret = usb_submit_urb(urb, GFP_KERNEL);
103 usb_unanchor_urb(urb);
111 static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
112 struct sk_buff_head *list)
116 while ((skb = __skb_dequeue(list)) != NULL) {
117 dev_kfree_skb_any(skb);
118 TX_STAT_INC(skb_dropped);
122 static void hif_usb_tx_cb(struct urb *urb)
124 struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
125 struct hif_device_usb *hif_dev;
128 if (!tx_buf || !tx_buf->hif_dev)
131 hif_dev = tx_buf->hif_dev;
133 switch (urb->status) {
141 * The URB has been killed, free the SKBs
144 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
150 /* Check if TX has been stopped */
151 spin_lock(&hif_dev->tx.tx_lock);
152 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
153 spin_unlock(&hif_dev->tx.tx_lock);
154 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
157 spin_unlock(&hif_dev->tx.tx_lock);
159 /* Complete the queued SKBs. */
160 while ((skb = __skb_dequeue(&tx_buf->skb_queue)) != NULL) {
161 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
163 TX_STAT_INC(skb_completed);
167 /* Re-initialize the SKB queue */
168 tx_buf->len = tx_buf->offset = 0;
169 __skb_queue_head_init(&tx_buf->skb_queue);
171 /* Add this TX buffer to the free list */
172 spin_lock(&hif_dev->tx.tx_lock);
173 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
174 hif_dev->tx.tx_buf_cnt++;
175 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
176 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
177 TX_STAT_INC(buf_completed);
178 spin_unlock(&hif_dev->tx.tx_lock);
181 /* TX lock has to be taken */
182 static int __hif_usb_tx(struct hif_device_usb *hif_dev)
184 struct tx_buf *tx_buf = NULL;
185 struct sk_buff *nskb = NULL;
187 u16 *hdr, tx_skb_cnt = 0;
190 if (hif_dev->tx.tx_skb_cnt == 0)
193 /* Check if a free TX buffer is available */
194 if (list_empty(&hif_dev->tx.tx_buf))
197 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
198 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
199 hif_dev->tx.tx_buf_cnt--;
201 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
203 for (i = 0; i < tx_skb_cnt; i++) {
204 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
206 /* Should never be NULL */
209 hif_dev->tx.tx_skb_cnt--;
212 buf += tx_buf->offset;
215 *hdr++ = ATH_USB_TX_STREAM_MODE_TAG;
217 memcpy(buf, nskb->data, nskb->len);
218 tx_buf->len = nskb->len + 4;
220 if (i < (tx_skb_cnt - 1))
221 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
223 if (i == (tx_skb_cnt - 1))
224 tx_buf->len += tx_buf->offset;
226 __skb_queue_tail(&tx_buf->skb_queue, nskb);
227 TX_STAT_INC(skb_queued);
230 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
231 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
232 tx_buf->buf, tx_buf->len,
233 hif_usb_tx_cb, tx_buf);
235 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
237 tx_buf->len = tx_buf->offset = 0;
238 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
239 __skb_queue_head_init(&tx_buf->skb_queue);
240 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
241 hif_dev->tx.tx_buf_cnt++;
245 TX_STAT_INC(buf_queued);
250 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb,
251 struct ath9k_htc_tx_ctl *tx_ctl)
255 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
257 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
258 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
262 /* Check if the max queue count has been reached */
263 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
264 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
268 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
269 hif_dev->tx.tx_skb_cnt++;
271 /* Send normal frames immediately */
272 if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL)))
273 __hif_usb_tx(hif_dev);
275 /* Check if AMPDUs have to be sent immediately */
276 if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) &&
277 (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
278 (hif_dev->tx.tx_skb_cnt < 2)) {
279 __hif_usb_tx(hif_dev);
282 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
287 static void hif_usb_start(void *hif_handle, u8 pipe_id)
289 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
292 hif_dev->flags |= HIF_USB_START;
294 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
295 hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
296 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
299 static void hif_usb_stop(void *hif_handle, u8 pipe_id)
301 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
304 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
305 ath9k_skb_queue_purge(hif_dev, &hif_dev->tx.tx_skb_queue);
306 hif_dev->tx.tx_skb_cnt = 0;
307 hif_dev->tx.flags |= HIF_USB_TX_STOP;
308 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
311 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb,
312 struct ath9k_htc_tx_ctl *tx_ctl)
314 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
318 case USB_WLAN_TX_PIPE:
319 ret = hif_usb_send_tx(hif_dev, skb, tx_ctl);
321 case USB_REG_OUT_PIPE:
322 ret = hif_usb_send_regout(hif_dev, skb);
325 dev_err(&hif_dev->udev->dev,
326 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
334 static struct ath9k_htc_hif hif_usb = {
335 .transport = ATH9K_HIF_USB,
336 .name = "ath9k_hif_usb",
338 .control_ul_pipe = USB_REG_OUT_PIPE,
339 .control_dl_pipe = USB_REG_IN_PIPE,
341 .start = hif_usb_start,
342 .stop = hif_usb_stop,
343 .send = hif_usb_send,
346 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
349 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
350 int index = 0, i = 0, chk_idx, len = skb->len;
351 int rx_remain_len = 0, rx_pkt_len = 0;
352 u16 pkt_len, pkt_tag, pool_index = 0;
355 spin_lock(&hif_dev->rx_lock);
357 rx_remain_len = hif_dev->rx_remain_len;
358 rx_pkt_len = hif_dev->rx_transfer_len;
360 if (rx_remain_len != 0) {
361 struct sk_buff *remain_skb = hif_dev->remain_skb;
364 ptr = (u8 *) remain_skb->data;
366 index = rx_remain_len;
367 rx_remain_len -= hif_dev->rx_pad_len;
370 memcpy(ptr, skb->data, rx_remain_len);
372 rx_pkt_len += rx_remain_len;
373 hif_dev->rx_remain_len = 0;
374 skb_put(remain_skb, rx_pkt_len);
376 skb_pool[pool_index++] = remain_skb;
379 index = rx_remain_len;
383 spin_unlock(&hif_dev->rx_lock);
385 while (index < len) {
386 ptr = (u8 *) skb->data;
388 pkt_len = ptr[index] + (ptr[index+1] << 8);
389 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
391 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
394 pad_len = 4 - (pkt_len & 0x3);
399 index = index + 4 + pkt_len + pad_len;
401 if (index > MAX_RX_BUF_SIZE) {
402 spin_lock(&hif_dev->rx_lock);
403 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
404 hif_dev->rx_transfer_len =
405 MAX_RX_BUF_SIZE - chk_idx - 4;
406 hif_dev->rx_pad_len = pad_len;
408 nskb = __dev_alloc_skb(pkt_len + 32,
411 dev_err(&hif_dev->udev->dev,
412 "ath9k_htc: RX memory allocation"
414 spin_unlock(&hif_dev->rx_lock);
417 skb_reserve(nskb, 32);
418 RX_STAT_INC(skb_allocated);
420 memcpy(nskb->data, &(skb->data[chk_idx+4]),
421 hif_dev->rx_transfer_len);
423 /* Record the buffer pointer */
424 hif_dev->remain_skb = nskb;
425 spin_unlock(&hif_dev->rx_lock);
427 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
429 dev_err(&hif_dev->udev->dev,
430 "ath9k_htc: RX memory allocation"
434 skb_reserve(nskb, 32);
435 RX_STAT_INC(skb_allocated);
437 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
438 skb_put(nskb, pkt_len);
439 skb_pool[pool_index++] = nskb;
442 RX_STAT_INC(skb_dropped);
448 for (i = 0; i < pool_index; i++) {
449 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
450 skb_pool[i]->len, USB_WLAN_RX_PIPE);
451 RX_STAT_INC(skb_completed);
455 static void ath9k_hif_usb_rx_cb(struct urb *urb)
457 struct sk_buff *skb = (struct sk_buff *) urb->context;
458 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
459 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
468 switch (urb->status) {
480 if (likely(urb->actual_length != 0)) {
481 skb_put(skb, urb->actual_length);
482 ath9k_hif_usb_rx_stream(hif_dev, skb);
486 skb_reset_tail_pointer(skb);
489 usb_anchor_urb(urb, &hif_dev->rx_submitted);
490 ret = usb_submit_urb(urb, GFP_ATOMIC);
492 usb_unanchor_urb(urb);
501 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
503 struct sk_buff *skb = (struct sk_buff *) urb->context;
504 struct sk_buff *nskb;
505 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
506 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
515 switch (urb->status) {
527 if (likely(urb->actual_length != 0)) {
528 skb_put(skb, urb->actual_length);
530 /* Process the command first */
531 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
532 skb->len, USB_REG_IN_PIPE);
535 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
537 dev_err(&hif_dev->udev->dev,
538 "ath9k_htc: REG_IN memory allocation failure\n");
543 usb_fill_int_urb(urb, hif_dev->udev,
544 usb_rcvbulkpipe(hif_dev->udev,
546 nskb->data, MAX_REG_IN_BUF_SIZE,
547 ath9k_hif_usb_reg_in_cb, nskb, 1);
549 ret = usb_submit_urb(urb, GFP_ATOMIC);
559 skb_reset_tail_pointer(skb);
562 ret = usb_submit_urb(urb, GFP_ATOMIC);
572 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
574 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
576 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
577 &hif_dev->tx.tx_buf, list) {
578 usb_kill_urb(tx_buf->urb);
579 list_del(&tx_buf->list);
580 usb_free_urb(tx_buf->urb);
585 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
586 &hif_dev->tx.tx_pending, list) {
587 usb_kill_urb(tx_buf->urb);
588 list_del(&tx_buf->list);
589 usb_free_urb(tx_buf->urb);
595 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
597 struct tx_buf *tx_buf;
600 INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
601 INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
602 spin_lock_init(&hif_dev->tx.tx_lock);
603 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
605 for (i = 0; i < MAX_TX_URB_NUM; i++) {
606 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
610 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
614 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
618 tx_buf->hif_dev = hif_dev;
619 __skb_queue_head_init(&tx_buf->skb_queue);
621 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
624 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
632 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
636 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
638 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
641 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
643 struct urb *urb = NULL;
644 struct sk_buff *skb = NULL;
647 init_usb_anchor(&hif_dev->rx_submitted);
648 spin_lock_init(&hif_dev->rx_lock);
650 for (i = 0; i < MAX_RX_URB_NUM; i++) {
653 urb = usb_alloc_urb(0, GFP_KERNEL);
659 /* Allocate buffer */
660 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
666 usb_fill_bulk_urb(urb, hif_dev->udev,
667 usb_rcvbulkpipe(hif_dev->udev,
669 skb->data, MAX_RX_BUF_SIZE,
670 ath9k_hif_usb_rx_cb, skb);
673 usb_anchor_urb(urb, &hif_dev->rx_submitted);
676 ret = usb_submit_urb(urb, GFP_KERNEL);
678 usb_unanchor_urb(urb);
683 * Drop reference count.
684 * This ensures that the URB is freed when killing them.
696 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
700 static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
702 if (hif_dev->reg_in_urb) {
703 usb_kill_urb(hif_dev->reg_in_urb);
704 if (hif_dev->reg_in_urb->context)
705 kfree_skb((void *)hif_dev->reg_in_urb->context);
706 usb_free_urb(hif_dev->reg_in_urb);
707 hif_dev->reg_in_urb = NULL;
711 static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
715 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
716 if (hif_dev->reg_in_urb == NULL)
719 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
723 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
724 usb_rcvbulkpipe(hif_dev->udev,
726 skb->data, MAX_REG_IN_BUF_SIZE,
727 ath9k_hif_usb_reg_in_cb, skb, 1);
729 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
735 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
739 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
742 init_usb_anchor(&hif_dev->regout_submitted);
745 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
749 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
753 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
758 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
760 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
765 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
767 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
768 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
769 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
770 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
773 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
776 const void *data = hif_dev->firmware->data;
777 size_t len = hif_dev->firmware->size;
778 u32 addr = AR9271_FIRMWARE;
779 u8 *buf = kzalloc(4096, GFP_KERNEL);
786 transfer = min_t(int, len, 4096);
787 memcpy(buf, data, transfer);
789 err = usb_control_msg(hif_dev->udev,
790 usb_sndctrlpipe(hif_dev->udev, 0),
791 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
792 addr >> 8, 0, buf, transfer, HZ);
804 if ((hif_dev->device_id == 0x7010) || (hif_dev->device_id == 0x7015))
805 firm_offset = AR7010_FIRMWARE_TEXT;
807 firm_offset = AR9271_FIRMWARE_TEXT;
810 * Issue FW download complete command to firmware.
812 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
813 FIRMWARE_DOWNLOAD_COMP,
815 firm_offset >> 8, 0, NULL, 0, HZ);
819 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
820 hif_dev->fw_name, (unsigned long) hif_dev->firmware->size);
825 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
828 struct usb_host_interface *alt = &hif_dev->interface->altsetting[0];
829 struct usb_endpoint_descriptor *endp;
831 /* Request firmware */
832 ret = request_firmware(&hif_dev->firmware, hif_dev->fw_name,
833 &hif_dev->udev->dev);
835 dev_err(&hif_dev->udev->dev,
836 "ath9k_htc: Firmware - %s not found\n", hif_dev->fw_name);
841 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
843 dev_err(&hif_dev->udev->dev,
844 "ath9k_htc: Unable to allocate URBs\n");
848 /* Download firmware */
849 ret = ath9k_hif_usb_download_fw(hif_dev);
851 dev_err(&hif_dev->udev->dev,
852 "ath9k_htc: Firmware - %s download failed\n",
854 goto err_fw_download;
857 /* On downloading the firmware to the target, the USB descriptor of EP4
858 * is 'patched' to change the type of the endpoint to Bulk. This will
859 * bring down CPU usage during the scan period.
861 for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
862 endp = &alt->endpoint[idx].desc;
863 if (((endp->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
865 ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
866 == USB_ENDPOINT_XFER_INT)) {
867 endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
868 endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
876 ath9k_hif_usb_dealloc_urbs(hif_dev);
878 release_firmware(hif_dev->firmware);
880 hif_dev->firmware = NULL;
884 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
886 ath9k_hif_usb_dealloc_urbs(hif_dev);
887 if (hif_dev->firmware)
888 release_firmware(hif_dev->firmware);
891 static int ath9k_hif_usb_probe(struct usb_interface *interface,
892 const struct usb_device_id *id)
894 struct usb_device *udev = interface_to_usbdev(interface);
895 struct hif_device_usb *hif_dev;
898 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
905 hif_dev->udev = udev;
906 hif_dev->interface = interface;
907 hif_dev->device_id = id->idProduct;
909 udev->reset_resume = 1;
911 usb_set_intfdata(interface, hif_dev);
913 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
914 &hif_dev->udev->dev);
915 if (hif_dev->htc_handle == NULL) {
917 goto err_htc_hw_alloc;
920 /* Find out which firmware to load */
922 switch(hif_dev->device_id) {
926 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x0202)
927 hif_dev->fw_name = FIRMWARE_AR7010_1_1;
929 hif_dev->fw_name = FIRMWARE_AR7010;
932 hif_dev->fw_name = FIRMWARE_AR9271;
936 ret = ath9k_hif_usb_dev_init(hif_dev);
939 goto err_hif_init_usb;
942 ret = ath9k_htc_hw_init(hif_dev->htc_handle,
943 &hif_dev->udev->dev, hif_dev->device_id,
944 hif_dev->udev->product);
947 goto err_htc_hw_init;
950 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
955 ath9k_hif_usb_dev_deinit(hif_dev);
957 ath9k_htc_hw_free(hif_dev->htc_handle);
959 usb_set_intfdata(interface, NULL);
966 static void ath9k_hif_usb_reboot(struct usb_device *udev)
968 u32 reboot_cmd = 0xffffffff;
972 buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL);
976 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
979 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
984 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
986 struct usb_device *udev = interface_to_usbdev(interface);
987 struct hif_device_usb *hif_dev =
988 (struct hif_device_usb *) usb_get_intfdata(interface);
991 ath9k_htc_hw_deinit(hif_dev->htc_handle,
992 (udev->state == USB_STATE_NOTATTACHED) ? true : false);
993 ath9k_htc_hw_free(hif_dev->htc_handle);
994 ath9k_hif_usb_dev_deinit(hif_dev);
995 usb_set_intfdata(interface, NULL);
998 if (hif_dev->flags & HIF_USB_START)
999 ath9k_hif_usb_reboot(udev);
1002 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
1007 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
1008 pm_message_t message)
1010 struct hif_device_usb *hif_dev =
1011 (struct hif_device_usb *) usb_get_intfdata(interface);
1013 ath9k_hif_usb_dealloc_urbs(hif_dev);
1018 static int ath9k_hif_usb_resume(struct usb_interface *interface)
1020 struct hif_device_usb *hif_dev =
1021 (struct hif_device_usb *) usb_get_intfdata(interface);
1024 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
1028 if (hif_dev->firmware) {
1029 ret = ath9k_hif_usb_download_fw(hif_dev);
1033 ath9k_hif_usb_dealloc_urbs(hif_dev);
1039 ret = ath9k_htc_resume(hif_dev->htc_handle);
1047 ath9k_hif_usb_dealloc_urbs(hif_dev);
1053 static struct usb_driver ath9k_hif_usb_driver = {
1054 .name = "ath9k_hif_usb",
1055 .probe = ath9k_hif_usb_probe,
1056 .disconnect = ath9k_hif_usb_disconnect,
1058 .suspend = ath9k_hif_usb_suspend,
1059 .resume = ath9k_hif_usb_resume,
1060 .reset_resume = ath9k_hif_usb_resume,
1062 .id_table = ath9k_hif_usb_ids,
1066 int ath9k_hif_usb_init(void)
1068 return usb_register(&ath9k_hif_usb_driver);
1071 void ath9k_hif_usb_exit(void)
1073 usb_deregister(&ath9k_hif_usb_driver);