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