Initial commit
[kernel/linux-3.0.git] / drivers / net / wireless / ath / ath9k / hif_usb.c
1 /*
2  * Copyright (c) 2010-2011 Atheros Communications Inc.
3  *
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.
7  *
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.
15  */
16
17 #include "htc.h"
18
19 /* identify firmware images */
20 #define FIRMWARE_AR7010_1_1     "htc_7010.fw"
21 #define FIRMWARE_AR9271         "htc_9271.fw"
22
23 MODULE_FIRMWARE(FIRMWARE_AR7010_1_1);
24 MODULE_FIRMWARE(FIRMWARE_AR9271);
25
26 static struct usb_device_id ath9k_hif_usb_ids[] = {
27         { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */
28         { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */
29         { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */
30         { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */
31         { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
32         { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */
33         { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */
34         { USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */
35         { USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */
36         { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */
37         { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
38         { USB_DEVICE(0x040D, 0x3801) }, /* VIA */
39         { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */
40         { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
41
42         { USB_DEVICE(0x0cf3, 0x7015),
43           .driver_info = AR9287_USB },  /* Atheros */
44         { USB_DEVICE(0x1668, 0x1200),
45           .driver_info = AR9287_USB },  /* Verizon */
46
47         { USB_DEVICE(0x0cf3, 0x7010),
48           .driver_info = AR9280_USB },  /* Atheros */
49         { USB_DEVICE(0x0846, 0x9018),
50           .driver_info = AR9280_USB },  /* Netgear WNDA3200 */
51         { USB_DEVICE(0x083A, 0xA704),
52           .driver_info = AR9280_USB },  /* SMC Networks */
53
54         { USB_DEVICE(0x0cf3, 0x20ff),
55           .driver_info = STORAGE_DEVICE },
56
57         { },
58 };
59
60 MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids);
61
62 static int __hif_usb_tx(struct hif_device_usb *hif_dev);
63
64 static void hif_usb_regout_cb(struct urb *urb)
65 {
66         struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
67
68         switch (urb->status) {
69         case 0:
70                 break;
71         case -ENOENT:
72         case -ECONNRESET:
73         case -ENODEV:
74         case -ESHUTDOWN:
75                 goto free;
76         default:
77                 break;
78         }
79
80         if (cmd) {
81                 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
82                                           cmd->skb, true);
83                 kfree(cmd);
84         }
85
86         return;
87 free:
88         kfree_skb(cmd->skb);
89         kfree(cmd);
90 }
91
92 static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
93                                struct sk_buff *skb)
94 {
95         struct urb *urb;
96         struct cmd_buf *cmd;
97         int ret = 0;
98
99         urb = usb_alloc_urb(0, GFP_KERNEL);
100         if (urb == NULL)
101                 return -ENOMEM;
102
103         cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
104         if (cmd == NULL) {
105                 usb_free_urb(urb);
106                 return -ENOMEM;
107         }
108
109         cmd->skb = skb;
110         cmd->hif_dev = hif_dev;
111
112         usb_fill_bulk_urb(urb, hif_dev->udev,
113                          usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE),
114                          skb->data, skb->len,
115                          hif_usb_regout_cb, cmd);
116
117         usb_anchor_urb(urb, &hif_dev->regout_submitted);
118         ret = usb_submit_urb(urb, GFP_KERNEL);
119         if (ret) {
120                 usb_unanchor_urb(urb);
121                 kfree(cmd);
122         }
123         usb_free_urb(urb);
124
125         return ret;
126 }
127
128 static void hif_usb_mgmt_cb(struct urb *urb)
129 {
130         struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
131         struct hif_device_usb *hif_dev = cmd->hif_dev;
132         bool txok = true;
133
134         if (!cmd || !cmd->skb || !cmd->hif_dev)
135                 return;
136
137         switch (urb->status) {
138         case 0:
139                 break;
140         case -ENOENT:
141         case -ECONNRESET:
142         case -ENODEV:
143         case -ESHUTDOWN:
144                 txok = false;
145
146                 /*
147                  * If the URBs are being flushed, no need to complete
148                  * this packet.
149                  */
150                 spin_lock(&hif_dev->tx.tx_lock);
151                 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) {
152                         spin_unlock(&hif_dev->tx.tx_lock);
153                         dev_kfree_skb_any(cmd->skb);
154                         kfree(cmd);
155                         return;
156                 }
157                 spin_unlock(&hif_dev->tx.tx_lock);
158
159                 break;
160         default:
161                 txok = false;
162                 break;
163         }
164
165         skb_pull(cmd->skb, 4);
166         ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
167                                   cmd->skb, txok);
168         kfree(cmd);
169 }
170
171 static int hif_usb_send_mgmt(struct hif_device_usb *hif_dev,
172                              struct sk_buff *skb)
173 {
174         struct urb *urb;
175         struct cmd_buf *cmd;
176         int ret = 0;
177         __le16 *hdr;
178
179         urb = usb_alloc_urb(0, GFP_ATOMIC);
180         if (urb == NULL)
181                 return -ENOMEM;
182
183         cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
184         if (cmd == NULL) {
185                 usb_free_urb(urb);
186                 return -ENOMEM;
187         }
188
189         cmd->skb = skb;
190         cmd->hif_dev = hif_dev;
191
192         hdr = (__le16 *) skb_push(skb, 4);
193         *hdr++ = cpu_to_le16(skb->len - 4);
194         *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG);
195
196         usb_fill_bulk_urb(urb, hif_dev->udev,
197                          usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
198                          skb->data, skb->len,
199                          hif_usb_mgmt_cb, cmd);
200
201         usb_anchor_urb(urb, &hif_dev->mgmt_submitted);
202         ret = usb_submit_urb(urb, GFP_ATOMIC);
203         if (ret) {
204                 usb_unanchor_urb(urb);
205                 kfree(cmd);
206         }
207         usb_free_urb(urb);
208
209         return ret;
210 }
211
212 static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
213                                          struct sk_buff_head *list)
214 {
215         struct sk_buff *skb;
216
217         while ((skb = __skb_dequeue(list)) != NULL) {
218                 dev_kfree_skb_any(skb);
219         }
220 }
221
222 static inline void ath9k_skb_queue_complete(struct hif_device_usb *hif_dev,
223                                             struct sk_buff_head *queue,
224                                             bool txok)
225 {
226         struct sk_buff *skb;
227
228         while ((skb = __skb_dequeue(queue)) != NULL) {
229                 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
230                                           skb, txok);
231                 if (txok)
232                         TX_STAT_INC(skb_success);
233                 else
234                         TX_STAT_INC(skb_failed);
235         }
236 }
237
238 static void hif_usb_tx_cb(struct urb *urb)
239 {
240         struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
241         struct hif_device_usb *hif_dev;
242         bool txok = true;
243
244         if (!tx_buf || !tx_buf->hif_dev)
245                 return;
246
247         hif_dev = tx_buf->hif_dev;
248
249         switch (urb->status) {
250         case 0:
251                 break;
252         case -ENOENT:
253         case -ECONNRESET:
254         case -ENODEV:
255         case -ESHUTDOWN:
256                 txok = false;
257
258                 /*
259                  * If the URBs are being flushed, no need to add this
260                  * URB to the free list.
261                  */
262                 spin_lock(&hif_dev->tx.tx_lock);
263                 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) {
264                         spin_unlock(&hif_dev->tx.tx_lock);
265                         ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
266                         return;
267                 }
268                 spin_unlock(&hif_dev->tx.tx_lock);
269
270                 break;
271         default:
272                 txok = false;
273                 break;
274         }
275
276         ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, txok);
277
278         /* Re-initialize the SKB queue */
279         tx_buf->len = tx_buf->offset = 0;
280         __skb_queue_head_init(&tx_buf->skb_queue);
281
282         /* Add this TX buffer to the free list */
283         spin_lock(&hif_dev->tx.tx_lock);
284         list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
285         hif_dev->tx.tx_buf_cnt++;
286         if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
287                 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
288         TX_STAT_INC(buf_completed);
289         spin_unlock(&hif_dev->tx.tx_lock);
290 }
291
292 /* TX lock has to be taken */
293 static int __hif_usb_tx(struct hif_device_usb *hif_dev)
294 {
295         struct tx_buf *tx_buf = NULL;
296         struct sk_buff *nskb = NULL;
297         int ret = 0, i;
298         u16 tx_skb_cnt = 0;
299         u8 *buf;
300         __le16 *hdr;
301
302         if (hif_dev->tx.tx_skb_cnt == 0)
303                 return 0;
304
305         /* Check if a free TX buffer is available */
306         if (list_empty(&hif_dev->tx.tx_buf))
307                 return 0;
308
309         tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
310         list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
311         hif_dev->tx.tx_buf_cnt--;
312
313         tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
314
315         for (i = 0; i < tx_skb_cnt; i++) {
316                 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
317
318                 /* Should never be NULL */
319                 BUG_ON(!nskb);
320
321                 hif_dev->tx.tx_skb_cnt--;
322
323                 buf = tx_buf->buf;
324                 buf += tx_buf->offset;
325                 hdr = (__le16 *)buf;
326                 *hdr++ = cpu_to_le16(nskb->len);
327                 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG);
328                 buf += 4;
329                 memcpy(buf, nskb->data, nskb->len);
330                 tx_buf->len = nskb->len + 4;
331
332                 if (i < (tx_skb_cnt - 1))
333                         tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
334
335                 if (i == (tx_skb_cnt - 1))
336                         tx_buf->len += tx_buf->offset;
337
338                 __skb_queue_tail(&tx_buf->skb_queue, nskb);
339                 TX_STAT_INC(skb_queued);
340         }
341
342         usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
343                           usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
344                           tx_buf->buf, tx_buf->len,
345                           hif_usb_tx_cb, tx_buf);
346
347         ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
348         if (ret) {
349                 tx_buf->len = tx_buf->offset = 0;
350                 ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, false);
351                 __skb_queue_head_init(&tx_buf->skb_queue);
352                 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
353                 hif_dev->tx.tx_buf_cnt++;
354         }
355
356         if (!ret)
357                 TX_STAT_INC(buf_queued);
358
359         return ret;
360 }
361
362 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb)
363 {
364         struct ath9k_htc_tx_ctl *tx_ctl;
365         unsigned long flags;
366         int ret = 0;
367
368         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
369
370         if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
371                 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
372                 return -ENODEV;
373         }
374
375         /* Check if the max queue count has been reached */
376         if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
377                 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
378                 return -ENOMEM;
379         }
380
381         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
382
383         tx_ctl = HTC_SKB_CB(skb);
384
385         /* Mgmt/Beacon frames don't use the TX buffer pool */
386         if ((tx_ctl->type == ATH9K_HTC_MGMT) ||
387             (tx_ctl->type == ATH9K_HTC_BEACON)) {
388                 ret = hif_usb_send_mgmt(hif_dev, skb);
389         }
390
391         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
392
393         if ((tx_ctl->type == ATH9K_HTC_NORMAL) ||
394             (tx_ctl->type == ATH9K_HTC_AMPDU)) {
395                 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
396                 hif_dev->tx.tx_skb_cnt++;
397         }
398
399         /* Check if AMPDUs have to be sent immediately */
400         if ((hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
401             (hif_dev->tx.tx_skb_cnt < 2)) {
402                 __hif_usb_tx(hif_dev);
403         }
404
405         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
406
407         return ret;
408 }
409
410 static void hif_usb_start(void *hif_handle)
411 {
412         struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
413         unsigned long flags;
414
415         hif_dev->flags |= HIF_USB_START;
416
417         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
418         hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
419         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
420 }
421
422 static void hif_usb_stop(void *hif_handle)
423 {
424         struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
425         struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
426         unsigned long flags;
427
428         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
429         ath9k_skb_queue_complete(hif_dev, &hif_dev->tx.tx_skb_queue, false);
430         hif_dev->tx.tx_skb_cnt = 0;
431         hif_dev->tx.flags |= HIF_USB_TX_STOP;
432         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
433
434         /* The pending URBs have to be canceled. */
435         list_for_each_entry_safe(tx_buf, tx_buf_tmp,
436                                  &hif_dev->tx.tx_pending, list) {
437                 usb_kill_urb(tx_buf->urb);
438         }
439
440         usb_kill_anchored_urbs(&hif_dev->mgmt_submitted);
441 }
442
443 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb)
444 {
445         struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
446         int ret = 0;
447
448         switch (pipe_id) {
449         case USB_WLAN_TX_PIPE:
450                 ret = hif_usb_send_tx(hif_dev, skb);
451                 break;
452         case USB_REG_OUT_PIPE:
453                 ret = hif_usb_send_regout(hif_dev, skb);
454                 break;
455         default:
456                 dev_err(&hif_dev->udev->dev,
457                         "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
458                 ret = -EINVAL;
459                 break;
460         }
461
462         return ret;
463 }
464
465 static inline bool check_index(struct sk_buff *skb, u8 idx)
466 {
467         struct ath9k_htc_tx_ctl *tx_ctl;
468
469         tx_ctl = HTC_SKB_CB(skb);
470
471         if ((tx_ctl->type == ATH9K_HTC_AMPDU) &&
472             (tx_ctl->sta_idx == idx))
473                 return true;
474
475         return false;
476 }
477
478 static void hif_usb_sta_drain(void *hif_handle, u8 idx)
479 {
480         struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
481         struct sk_buff *skb, *tmp;
482         unsigned long flags;
483
484         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
485
486         skb_queue_walk_safe(&hif_dev->tx.tx_skb_queue, skb, tmp) {
487                 if (check_index(skb, idx)) {
488                         __skb_unlink(skb, &hif_dev->tx.tx_skb_queue);
489                         ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
490                                                   skb, false);
491                         hif_dev->tx.tx_skb_cnt--;
492                         TX_STAT_INC(skb_failed);
493                 }
494         }
495
496         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
497 }
498
499 static struct ath9k_htc_hif hif_usb = {
500         .transport = ATH9K_HIF_USB,
501         .name = "ath9k_hif_usb",
502
503         .control_ul_pipe = USB_REG_OUT_PIPE,
504         .control_dl_pipe = USB_REG_IN_PIPE,
505
506         .start = hif_usb_start,
507         .stop = hif_usb_stop,
508         .sta_drain = hif_usb_sta_drain,
509         .send = hif_usb_send,
510 };
511
512 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
513                                     struct sk_buff *skb)
514 {
515         struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
516         int index = 0, i = 0, len = skb->len;
517         int rx_remain_len, rx_pkt_len;
518         u16 pool_index = 0;
519         u8 *ptr;
520
521         spin_lock(&hif_dev->rx_lock);
522
523         rx_remain_len = hif_dev->rx_remain_len;
524         rx_pkt_len = hif_dev->rx_transfer_len;
525
526         if (rx_remain_len != 0) {
527                 struct sk_buff *remain_skb = hif_dev->remain_skb;
528
529                 if (remain_skb) {
530                         ptr = (u8 *) remain_skb->data;
531
532                         index = rx_remain_len;
533                         rx_remain_len -= hif_dev->rx_pad_len;
534                         ptr += rx_pkt_len;
535
536                         memcpy(ptr, skb->data, rx_remain_len);
537
538                         rx_pkt_len += rx_remain_len;
539                         hif_dev->rx_remain_len = 0;
540                         skb_put(remain_skb, rx_pkt_len);
541
542                         skb_pool[pool_index++] = remain_skb;
543
544                 } else {
545                         index = rx_remain_len;
546                 }
547         }
548
549         spin_unlock(&hif_dev->rx_lock);
550
551         while (index < len) {
552                 u16 pkt_len;
553                 u16 pkt_tag;
554                 u16 pad_len;
555                 int chk_idx;
556
557                 ptr = (u8 *) skb->data;
558
559                 pkt_len = ptr[index] + (ptr[index+1] << 8);
560                 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
561
562                 if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) {
563                         RX_STAT_INC(skb_dropped);
564                         return;
565                 }
566
567                 pad_len = 4 - (pkt_len & 0x3);
568                 if (pad_len == 4)
569                         pad_len = 0;
570
571                 chk_idx = index;
572                 index = index + 4 + pkt_len + pad_len;
573
574                 if (index > MAX_RX_BUF_SIZE) {
575                         spin_lock(&hif_dev->rx_lock);
576                         hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
577                         hif_dev->rx_transfer_len =
578                                 MAX_RX_BUF_SIZE - chk_idx - 4;
579                         hif_dev->rx_pad_len = pad_len;
580
581                         nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
582                         if (!nskb) {
583                                 dev_err(&hif_dev->udev->dev,
584                                         "ath9k_htc: RX memory allocation error\n");
585                                 spin_unlock(&hif_dev->rx_lock);
586                                 goto err;
587                         }
588                         skb_reserve(nskb, 32);
589                         RX_STAT_INC(skb_allocated);
590
591                         memcpy(nskb->data, &(skb->data[chk_idx+4]),
592                                hif_dev->rx_transfer_len);
593
594                         /* Record the buffer pointer */
595                         hif_dev->remain_skb = nskb;
596                         spin_unlock(&hif_dev->rx_lock);
597                 } else {
598                         nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
599                         if (!nskb) {
600                                 dev_err(&hif_dev->udev->dev,
601                                         "ath9k_htc: RX memory allocation error\n");
602                                 goto err;
603                         }
604                         skb_reserve(nskb, 32);
605                         RX_STAT_INC(skb_allocated);
606
607                         memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
608                         skb_put(nskb, pkt_len);
609                         skb_pool[pool_index++] = nskb;
610                 }
611         }
612
613 err:
614         for (i = 0; i < pool_index; i++) {
615                 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
616                                  skb_pool[i]->len, USB_WLAN_RX_PIPE);
617                 RX_STAT_INC(skb_completed);
618         }
619 }
620
621 static void ath9k_hif_usb_rx_cb(struct urb *urb)
622 {
623         struct sk_buff *skb = (struct sk_buff *) urb->context;
624         struct hif_device_usb *hif_dev =
625                 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
626         int ret;
627
628         if (!skb)
629                 return;
630
631         if (!hif_dev)
632                 goto free;
633
634         switch (urb->status) {
635         case 0:
636                 break;
637         case -ENOENT:
638         case -ECONNRESET:
639         case -ENODEV:
640         case -ESHUTDOWN:
641                 goto free;
642         default:
643                 goto resubmit;
644         }
645
646         if (likely(urb->actual_length != 0)) {
647                 skb_put(skb, urb->actual_length);
648                 ath9k_hif_usb_rx_stream(hif_dev, skb);
649         }
650
651 resubmit:
652         skb_reset_tail_pointer(skb);
653         skb_trim(skb, 0);
654
655         usb_anchor_urb(urb, &hif_dev->rx_submitted);
656         ret = usb_submit_urb(urb, GFP_ATOMIC);
657         if (ret) {
658                 usb_unanchor_urb(urb);
659                 goto free;
660         }
661
662         return;
663 free:
664         kfree_skb(skb);
665 }
666
667 static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
668 {
669         struct sk_buff *skb = (struct sk_buff *) urb->context;
670         struct sk_buff *nskb;
671         struct hif_device_usb *hif_dev =
672                 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
673         int ret;
674
675         if (!skb)
676                 return;
677
678         if (!hif_dev)
679                 goto free;
680
681         switch (urb->status) {
682         case 0:
683                 break;
684         case -ENOENT:
685         case -ECONNRESET:
686         case -ENODEV:
687         case -ESHUTDOWN:
688                 goto free;
689         default:
690                 skb_reset_tail_pointer(skb);
691                 skb_trim(skb, 0);
692
693                 goto resubmit;
694         }
695
696         if (likely(urb->actual_length != 0)) {
697                 skb_put(skb, urb->actual_length);
698
699                 /* Process the command first */
700                 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
701                                  skb->len, USB_REG_IN_PIPE);
702
703
704                 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
705                 if (!nskb) {
706                         dev_err(&hif_dev->udev->dev,
707                                 "ath9k_htc: REG_IN memory allocation failure\n");
708                         urb->context = NULL;
709                         return;
710                 }
711
712                 usb_fill_bulk_urb(urb, hif_dev->udev,
713                                  usb_rcvbulkpipe(hif_dev->udev,
714                                                  USB_REG_IN_PIPE),
715                                  nskb->data, MAX_REG_IN_BUF_SIZE,
716                                  ath9k_hif_usb_reg_in_cb, nskb);
717         }
718
719 resubmit:
720         usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
721         ret = usb_submit_urb(urb, GFP_ATOMIC);
722         if (ret) {
723                 usb_unanchor_urb(urb);
724                 goto free;
725         }
726
727         return;
728 free:
729         kfree_skb(skb);
730         urb->context = NULL;
731 }
732
733 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
734 {
735         struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
736         unsigned long flags;
737
738         list_for_each_entry_safe(tx_buf, tx_buf_tmp,
739                                  &hif_dev->tx.tx_buf, list) {
740                 usb_kill_urb(tx_buf->urb);
741                 list_del(&tx_buf->list);
742                 usb_free_urb(tx_buf->urb);
743                 kfree(tx_buf->buf);
744                 kfree(tx_buf);
745         }
746
747         spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
748         hif_dev->tx.flags |= HIF_USB_TX_FLUSH;
749         spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
750
751         list_for_each_entry_safe(tx_buf, tx_buf_tmp,
752                                  &hif_dev->tx.tx_pending, list) {
753                 usb_kill_urb(tx_buf->urb);
754                 list_del(&tx_buf->list);
755                 usb_free_urb(tx_buf->urb);
756                 kfree(tx_buf->buf);
757                 kfree(tx_buf);
758         }
759
760         usb_kill_anchored_urbs(&hif_dev->mgmt_submitted);
761 }
762
763 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
764 {
765         struct tx_buf *tx_buf;
766         int i;
767
768         INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
769         INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
770         spin_lock_init(&hif_dev->tx.tx_lock);
771         __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
772         init_usb_anchor(&hif_dev->mgmt_submitted);
773
774         for (i = 0; i < MAX_TX_URB_NUM; i++) {
775                 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
776                 if (!tx_buf)
777                         goto err;
778
779                 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
780                 if (!tx_buf->buf)
781                         goto err;
782
783                 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
784                 if (!tx_buf->urb)
785                         goto err;
786
787                 tx_buf->hif_dev = hif_dev;
788                 __skb_queue_head_init(&tx_buf->skb_queue);
789
790                 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
791         }
792
793         hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
794
795         return 0;
796 err:
797         if (tx_buf) {
798                 kfree(tx_buf->buf);
799                 kfree(tx_buf);
800         }
801         ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
802         return -ENOMEM;
803 }
804
805 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
806 {
807         usb_kill_anchored_urbs(&hif_dev->rx_submitted);
808 }
809
810 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
811 {
812         struct urb *urb = NULL;
813         struct sk_buff *skb = NULL;
814         int i, ret;
815
816         init_usb_anchor(&hif_dev->rx_submitted);
817         spin_lock_init(&hif_dev->rx_lock);
818
819         for (i = 0; i < MAX_RX_URB_NUM; i++) {
820
821                 /* Allocate URB */
822                 urb = usb_alloc_urb(0, GFP_KERNEL);
823                 if (urb == NULL) {
824                         ret = -ENOMEM;
825                         goto err_urb;
826                 }
827
828                 /* Allocate buffer */
829                 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
830                 if (!skb) {
831                         ret = -ENOMEM;
832                         goto err_skb;
833                 }
834
835                 usb_fill_bulk_urb(urb, hif_dev->udev,
836                                   usb_rcvbulkpipe(hif_dev->udev,
837                                                   USB_WLAN_RX_PIPE),
838                                   skb->data, MAX_RX_BUF_SIZE,
839                                   ath9k_hif_usb_rx_cb, skb);
840
841                 /* Anchor URB */
842                 usb_anchor_urb(urb, &hif_dev->rx_submitted);
843
844                 /* Submit URB */
845                 ret = usb_submit_urb(urb, GFP_KERNEL);
846                 if (ret) {
847                         usb_unanchor_urb(urb);
848                         goto err_submit;
849                 }
850
851                 /*
852                  * Drop reference count.
853                  * This ensures that the URB is freed when killing them.
854                  */
855                 usb_free_urb(urb);
856         }
857
858         return 0;
859
860 err_submit:
861         kfree_skb(skb);
862 err_skb:
863         usb_free_urb(urb);
864 err_urb:
865         ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
866         return ret;
867 }
868
869 static void ath9k_hif_usb_dealloc_reg_in_urbs(struct hif_device_usb *hif_dev)
870 {
871         usb_kill_anchored_urbs(&hif_dev->reg_in_submitted);
872 }
873
874 static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev)
875 {
876         struct urb *urb = NULL;
877         struct sk_buff *skb = NULL;
878         int i, ret;
879
880         init_usb_anchor(&hif_dev->reg_in_submitted);
881
882         for (i = 0; i < MAX_REG_IN_URB_NUM; i++) {
883
884                 /* Allocate URB */
885                 urb = usb_alloc_urb(0, GFP_KERNEL);
886                 if (urb == NULL) {
887                         ret = -ENOMEM;
888                         goto err_urb;
889                 }
890
891                 /* Allocate buffer */
892                 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
893                 if (!skb) {
894                         ret = -ENOMEM;
895                         goto err_skb;
896                 }
897
898                 usb_fill_bulk_urb(urb, hif_dev->udev,
899                                   usb_rcvbulkpipe(hif_dev->udev,
900                                                   USB_REG_IN_PIPE),
901                                   skb->data, MAX_REG_IN_BUF_SIZE,
902                                   ath9k_hif_usb_reg_in_cb, skb);
903
904                 /* Anchor URB */
905                 usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
906
907                 /* Submit URB */
908                 ret = usb_submit_urb(urb, GFP_KERNEL);
909                 if (ret) {
910                         usb_unanchor_urb(urb);
911                         goto err_submit;
912                 }
913
914                 /*
915                  * Drop reference count.
916                  * This ensures that the URB is freed when killing them.
917                  */
918                 usb_free_urb(urb);
919         }
920
921         return 0;
922
923 err_submit:
924         kfree_skb(skb);
925 err_skb:
926         usb_free_urb(urb);
927 err_urb:
928         ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev);
929         return ret;
930 }
931
932 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
933 {
934         /* Register Write */
935         init_usb_anchor(&hif_dev->regout_submitted);
936
937         /* TX */
938         if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
939                 goto err;
940
941         /* RX */
942         if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
943                 goto err_rx;
944
945         /* Register Read */
946         if (ath9k_hif_usb_alloc_reg_in_urbs(hif_dev) < 0)
947                 goto err_reg;
948
949         return 0;
950 err_reg:
951         ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
952 err_rx:
953         ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
954 err:
955         return -ENOMEM;
956 }
957
958 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
959 {
960         usb_kill_anchored_urbs(&hif_dev->regout_submitted);
961         ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev);
962         ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
963         ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
964 }
965
966 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev,
967                                      u32 drv_info)
968 {
969         int transfer, err;
970         const void *data = hif_dev->firmware->data;
971         size_t len = hif_dev->firmware->size;
972         u32 addr = AR9271_FIRMWARE;
973         u8 *buf = kzalloc(4096, GFP_KERNEL);
974         u32 firm_offset;
975
976         if (!buf)
977                 return -ENOMEM;
978
979         while (len) {
980                 transfer = min_t(int, len, 4096);
981                 memcpy(buf, data, transfer);
982
983                 err = usb_control_msg(hif_dev->udev,
984                                       usb_sndctrlpipe(hif_dev->udev, 0),
985                                       FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
986                                       addr >> 8, 0, buf, transfer, HZ);
987                 if (err < 0) {
988                         kfree(buf);
989                         return err;
990                 }
991
992                 len -= transfer;
993                 data += transfer;
994                 addr += transfer;
995         }
996         kfree(buf);
997
998         if (IS_AR7010_DEVICE(drv_info))
999                 firm_offset = AR7010_FIRMWARE_TEXT;
1000         else
1001                 firm_offset = AR9271_FIRMWARE_TEXT;
1002
1003         /*
1004          * Issue FW download complete command to firmware.
1005          */
1006         err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
1007                               FIRMWARE_DOWNLOAD_COMP,
1008                               0x40 | USB_DIR_OUT,
1009                               firm_offset >> 8, 0, NULL, 0, HZ);
1010         if (err)
1011                 return -EIO;
1012
1013         dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
1014                  hif_dev->fw_name, (unsigned long) hif_dev->firmware->size);
1015
1016         return 0;
1017 }
1018
1019 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev, u32 drv_info)
1020 {
1021         int ret, idx;
1022         struct usb_host_interface *alt = &hif_dev->interface->altsetting[0];
1023         struct usb_endpoint_descriptor *endp;
1024
1025         /* Request firmware */
1026         ret = request_firmware(&hif_dev->firmware, hif_dev->fw_name,
1027                                &hif_dev->udev->dev);
1028         if (ret) {
1029                 dev_err(&hif_dev->udev->dev,
1030                         "ath9k_htc: Firmware - %s not found\n", hif_dev->fw_name);
1031                 goto err_fw_req;
1032         }
1033
1034         /* Download firmware */
1035         ret = ath9k_hif_usb_download_fw(hif_dev, drv_info);
1036         if (ret) {
1037                 dev_err(&hif_dev->udev->dev,
1038                         "ath9k_htc: Firmware - %s download failed\n",
1039                         hif_dev->fw_name);
1040                 goto err_fw_download;
1041         }
1042
1043         /* On downloading the firmware to the target, the USB descriptor of EP4
1044          * is 'patched' to change the type of the endpoint to Bulk. This will
1045          * bring down CPU usage during the scan period.
1046          */
1047         for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
1048                 endp = &alt->endpoint[idx].desc;
1049                 if ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
1050                                 == USB_ENDPOINT_XFER_INT) {
1051                         endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
1052                         endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
1053                         endp->bInterval = 0;
1054                 }
1055         }
1056
1057         /* Alloc URBs */
1058         ret = ath9k_hif_usb_alloc_urbs(hif_dev);
1059         if (ret) {
1060                 dev_err(&hif_dev->udev->dev,
1061                         "ath9k_htc: Unable to allocate URBs\n");
1062                 goto err_fw_download;
1063         }
1064
1065         return 0;
1066
1067 err_fw_download:
1068         release_firmware(hif_dev->firmware);
1069 err_fw_req:
1070         hif_dev->firmware = NULL;
1071         return ret;
1072 }
1073
1074 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
1075 {
1076         ath9k_hif_usb_dealloc_urbs(hif_dev);
1077         if (hif_dev->firmware)
1078                 release_firmware(hif_dev->firmware);
1079 }
1080
1081 /*
1082  * An exact copy of the function from zd1211rw.
1083  */
1084 static int send_eject_command(struct usb_interface *interface)
1085 {
1086         struct usb_device *udev = interface_to_usbdev(interface);
1087         struct usb_host_interface *iface_desc = &interface->altsetting[0];
1088         struct usb_endpoint_descriptor *endpoint;
1089         unsigned char *cmd;
1090         u8 bulk_out_ep;
1091         int r;
1092
1093         /* Find bulk out endpoint */
1094         for (r = 1; r >= 0; r--) {
1095                 endpoint = &iface_desc->endpoint[r].desc;
1096                 if (usb_endpoint_dir_out(endpoint) &&
1097                     usb_endpoint_xfer_bulk(endpoint)) {
1098                         bulk_out_ep = endpoint->bEndpointAddress;
1099                         break;
1100                 }
1101         }
1102         if (r == -1) {
1103                 dev_err(&udev->dev,
1104                         "ath9k_htc: Could not find bulk out endpoint\n");
1105                 return -ENODEV;
1106         }
1107
1108         cmd = kzalloc(31, GFP_KERNEL);
1109         if (cmd == NULL)
1110                 return -ENODEV;
1111
1112         /* USB bulk command block */
1113         cmd[0] = 0x55;  /* bulk command signature */
1114         cmd[1] = 0x53;  /* bulk command signature */
1115         cmd[2] = 0x42;  /* bulk command signature */
1116         cmd[3] = 0x43;  /* bulk command signature */
1117         cmd[14] = 6;    /* command length */
1118
1119         cmd[15] = 0x1b; /* SCSI command: START STOP UNIT */
1120         cmd[19] = 0x2;  /* eject disc */
1121
1122         dev_info(&udev->dev, "Ejecting storage device...\n");
1123         r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, bulk_out_ep),
1124                 cmd, 31, NULL, 2000);
1125         kfree(cmd);
1126         if (r)
1127                 return r;
1128
1129         /* At this point, the device disconnects and reconnects with the real
1130          * ID numbers. */
1131
1132         usb_set_intfdata(interface, NULL);
1133         return 0;
1134 }
1135
1136 static int ath9k_hif_usb_probe(struct usb_interface *interface,
1137                                const struct usb_device_id *id)
1138 {
1139         struct usb_device *udev = interface_to_usbdev(interface);
1140         struct hif_device_usb *hif_dev;
1141         int ret = 0;
1142
1143         if (id->driver_info == STORAGE_DEVICE)
1144                 return send_eject_command(interface);
1145
1146         hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
1147         if (!hif_dev) {
1148                 ret = -ENOMEM;
1149                 goto err_alloc;
1150         }
1151
1152         usb_get_dev(udev);
1153         hif_dev->udev = udev;
1154         hif_dev->interface = interface;
1155         hif_dev->device_id = id->idProduct;
1156 #ifdef CONFIG_PM
1157         udev->reset_resume = 1;
1158 #endif
1159         usb_set_intfdata(interface, hif_dev);
1160
1161         hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
1162                                                  &hif_dev->udev->dev);
1163         if (hif_dev->htc_handle == NULL) {
1164                 ret = -ENOMEM;
1165                 goto err_htc_hw_alloc;
1166         }
1167
1168         /* Find out which firmware to load */
1169
1170         if (IS_AR7010_DEVICE(id->driver_info))
1171                 hif_dev->fw_name = FIRMWARE_AR7010_1_1;
1172         else
1173                 hif_dev->fw_name = FIRMWARE_AR9271;
1174
1175         ret = ath9k_hif_usb_dev_init(hif_dev, id->driver_info);
1176         if (ret) {
1177                 ret = -EINVAL;
1178                 goto err_hif_init_usb;
1179         }
1180
1181         ret = ath9k_htc_hw_init(hif_dev->htc_handle,
1182                                 &interface->dev, hif_dev->device_id,
1183                                 hif_dev->udev->product, id->driver_info);
1184         if (ret) {
1185                 ret = -EINVAL;
1186                 goto err_htc_hw_init;
1187         }
1188
1189         dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
1190
1191         return 0;
1192
1193 err_htc_hw_init:
1194         ath9k_hif_usb_dev_deinit(hif_dev);
1195 err_hif_init_usb:
1196         ath9k_htc_hw_free(hif_dev->htc_handle);
1197 err_htc_hw_alloc:
1198         usb_set_intfdata(interface, NULL);
1199         kfree(hif_dev);
1200         usb_put_dev(udev);
1201 err_alloc:
1202         return ret;
1203 }
1204
1205 static void ath9k_hif_usb_reboot(struct usb_device *udev)
1206 {
1207         u32 reboot_cmd = 0xffffffff;
1208         void *buf;
1209         int ret;
1210
1211         buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL);
1212         if (!buf)
1213                 return;
1214
1215         ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
1216                            buf, 4, NULL, HZ);
1217         if (ret)
1218                 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
1219
1220         kfree(buf);
1221 }
1222
1223 static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
1224 {
1225         struct usb_device *udev = interface_to_usbdev(interface);
1226         struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
1227         bool unplugged = (udev->state == USB_STATE_NOTATTACHED) ? true : false;
1228
1229         if (!hif_dev)
1230                 return;
1231
1232         ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged);
1233         ath9k_htc_hw_free(hif_dev->htc_handle);
1234         ath9k_hif_usb_dev_deinit(hif_dev);
1235         usb_set_intfdata(interface, NULL);
1236
1237         if (!unplugged && (hif_dev->flags & HIF_USB_START))
1238                 ath9k_hif_usb_reboot(udev);
1239
1240         kfree(hif_dev);
1241         dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
1242         usb_put_dev(udev);
1243 }
1244
1245 #ifdef CONFIG_PM
1246 static int ath9k_hif_usb_suspend(struct usb_interface *interface,
1247                                  pm_message_t message)
1248 {
1249         struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
1250
1251         /*
1252          * The device has to be set to FULLSLEEP mode in case no
1253          * interface is up.
1254          */
1255         if (!(hif_dev->flags & HIF_USB_START))
1256                 ath9k_htc_suspend(hif_dev->htc_handle);
1257
1258         ath9k_hif_usb_dealloc_urbs(hif_dev);
1259
1260         return 0;
1261 }
1262
1263 static int ath9k_hif_usb_resume(struct usb_interface *interface)
1264 {
1265         struct hif_device_usb *hif_dev = usb_get_intfdata(interface);
1266         struct htc_target *htc_handle = hif_dev->htc_handle;
1267         int ret;
1268
1269         ret = ath9k_hif_usb_alloc_urbs(hif_dev);
1270         if (ret)
1271                 return ret;
1272
1273         if (hif_dev->firmware) {
1274                 ret = ath9k_hif_usb_download_fw(hif_dev,
1275                                 htc_handle->drv_priv->ah->hw_version.usbdev);
1276                 if (ret)
1277                         goto fail_resume;
1278         } else {
1279                 ath9k_hif_usb_dealloc_urbs(hif_dev);
1280                 return -EIO;
1281         }
1282
1283         mdelay(100);
1284
1285         ret = ath9k_htc_resume(htc_handle);
1286
1287         if (ret)
1288                 goto fail_resume;
1289
1290         return 0;
1291
1292 fail_resume:
1293         ath9k_hif_usb_dealloc_urbs(hif_dev);
1294
1295         return ret;
1296 }
1297 #endif
1298
1299 static struct usb_driver ath9k_hif_usb_driver = {
1300         .name = KBUILD_MODNAME,
1301         .probe = ath9k_hif_usb_probe,
1302         .disconnect = ath9k_hif_usb_disconnect,
1303 #ifdef CONFIG_PM
1304         .suspend = ath9k_hif_usb_suspend,
1305         .resume = ath9k_hif_usb_resume,
1306         .reset_resume = ath9k_hif_usb_resume,
1307 #endif
1308         .id_table = ath9k_hif_usb_ids,
1309         .soft_unbind = 1,
1310 };
1311
1312 int ath9k_hif_usb_init(void)
1313 {
1314         return usb_register(&ath9k_hif_usb_driver);
1315 }
1316
1317 void ath9k_hif_usb_exit(void)
1318 {
1319         usb_deregister(&ath9k_hif_usb_driver);
1320 }