blob: 2f6b1e9f0aee1cc005a57a0fc4f65873939f3dae [file] [log] [blame]
Sujithfb9987d2010-03-17 14:25:25 +05301/*
2 * Copyright (c) 2010 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
John W. Linvilled0ee0eb2010-06-23 14:20:45 -040019/* identify firmware images */
20#define FIRMWARE_AR7010 "ar7010.fw"
21#define FIRMWARE_AR7010_1_1 "ar7010_1_1.fw"
22#define FIRMWARE_AR9271 "ar9271.fw"
23
24MODULE_FIRMWARE(FIRMWARE_AR7010);
25MODULE_FIRMWARE(FIRMWARE_AR7010_1_1);
26MODULE_FIRMWARE(FIRMWARE_AR9271);
27
Sujithfb9987d2010-03-17 14:25:25 +053028static struct usb_device_id ath9k_hif_usb_ids[] = {
Sujith4e63f762010-06-17 10:29:01 +053029 { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */
30 { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */
31 { USB_DEVICE(0x0cf3, 0x7010) }, /* Atheros */
32 { USB_DEVICE(0x0cf3, 0x7015) }, /* Atheros */
33 { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */
34 { USB_DEVICE(0x0846, 0x9018) }, /* Netgear WNDA3200 */
35 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */
36 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
37 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */
Haitao Zhangac618d72010-11-07 12:50:24 +080038 { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */
Sujith4e63f762010-06-17 10:29:01 +053039 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
40 { USB_DEVICE(0x083A, 0xA704) }, /* SMC Networks */
Sujithfb9987d2010-03-17 14:25:25 +053041 { },
42};
43
44MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids);
45
46static int __hif_usb_tx(struct hif_device_usb *hif_dev);
47
48static void hif_usb_regout_cb(struct urb *urb)
49{
50 struct cmd_buf *cmd = (struct cmd_buf *)urb->context;
Sujithfb9987d2010-03-17 14:25:25 +053051
52 switch (urb->status) {
53 case 0:
54 break;
55 case -ENOENT:
56 case -ECONNRESET:
Sujithfb9987d2010-03-17 14:25:25 +053057 case -ENODEV:
58 case -ESHUTDOWN:
Sujith6f0f2662010-04-06 15:28:17 +053059 goto free;
Sujithfb9987d2010-03-17 14:25:25 +053060 default:
61 break;
62 }
63
64 if (cmd) {
65 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle,
66 cmd->skb, 1);
67 kfree(cmd);
Sujithfb9987d2010-03-17 14:25:25 +053068 }
Sujith6f0f2662010-04-06 15:28:17 +053069
70 return;
71free:
Ming Lei0fa35a52010-04-13 00:29:15 +080072 kfree_skb(cmd->skb);
Sujith6f0f2662010-04-06 15:28:17 +053073 kfree(cmd);
Sujithfb9987d2010-03-17 14:25:25 +053074}
75
76static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
77 struct sk_buff *skb)
78{
79 struct urb *urb;
80 struct cmd_buf *cmd;
81 int ret = 0;
82
83 urb = usb_alloc_urb(0, GFP_KERNEL);
84 if (urb == NULL)
85 return -ENOMEM;
86
87 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
88 if (cmd == NULL) {
89 usb_free_urb(urb);
90 return -ENOMEM;
91 }
92
93 cmd->skb = skb;
94 cmd->hif_dev = hif_dev;
95
Rajkumar Manoharan4a0e8ec2010-09-14 14:35:55 +053096 usb_fill_bulk_urb(urb, hif_dev->udev,
97 usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE),
Sujithfb9987d2010-03-17 14:25:25 +053098 skb->data, skb->len,
Rajkumar Manoharan4a0e8ec2010-09-14 14:35:55 +053099 hif_usb_regout_cb, cmd);
Sujithfb9987d2010-03-17 14:25:25 +0530100
Sujith6f0f2662010-04-06 15:28:17 +0530101 usb_anchor_urb(urb, &hif_dev->regout_submitted);
Sujithfb9987d2010-03-17 14:25:25 +0530102 ret = usb_submit_urb(urb, GFP_KERNEL);
103 if (ret) {
Sujith6f0f2662010-04-06 15:28:17 +0530104 usb_unanchor_urb(urb);
Sujithfb9987d2010-03-17 14:25:25 +0530105 kfree(cmd);
106 }
Sujith6f0f2662010-04-06 15:28:17 +0530107 usb_free_urb(urb);
Sujithfb9987d2010-03-17 14:25:25 +0530108
109 return ret;
110}
111
Sujitheac8e382010-04-16 11:54:00 +0530112static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev,
113 struct sk_buff_head *list)
Ming Leif8e1d082010-04-13 00:29:27 +0800114{
115 struct sk_buff *skb;
Sujitheac8e382010-04-16 11:54:00 +0530116
117 while ((skb = __skb_dequeue(list)) != NULL) {
Ming Leif8e1d082010-04-13 00:29:27 +0800118 dev_kfree_skb_any(skb);
Sujitheac8e382010-04-16 11:54:00 +0530119 TX_STAT_INC(skb_dropped);
120 }
Ming Leif8e1d082010-04-13 00:29:27 +0800121}
122
Sujithc11d8f82010-04-23 10:28:09 +0530123static void hif_usb_tx_cb(struct urb *urb)
124{
125 struct tx_buf *tx_buf = (struct tx_buf *) urb->context;
Dan Carpenter690e7812010-05-14 16:50:56 +0200126 struct hif_device_usb *hif_dev;
Sujithc11d8f82010-04-23 10:28:09 +0530127 struct sk_buff *skb;
128
Dan Carpenter690e7812010-05-14 16:50:56 +0200129 if (!tx_buf || !tx_buf->hif_dev)
Sujithc11d8f82010-04-23 10:28:09 +0530130 return;
131
Dan Carpenter690e7812010-05-14 16:50:56 +0200132 hif_dev = tx_buf->hif_dev;
133
Sujithc11d8f82010-04-23 10:28:09 +0530134 switch (urb->status) {
135 case 0:
136 break;
137 case -ENOENT:
138 case -ECONNRESET:
139 case -ENODEV:
140 case -ESHUTDOWN:
141 /*
142 * The URB has been killed, free the SKBs
143 * and return.
144 */
145 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
146 return;
147 default:
148 break;
149 }
150
151 /* Check if TX has been stopped */
152 spin_lock(&hif_dev->tx.tx_lock);
153 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
154 spin_unlock(&hif_dev->tx.tx_lock);
155 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
156 goto add_free;
157 }
158 spin_unlock(&hif_dev->tx.tx_lock);
159
160 /* Complete the queued SKBs. */
161 while ((skb = __skb_dequeue(&tx_buf->skb_queue)) != NULL) {
162 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
163 skb, 1);
164 TX_STAT_INC(skb_completed);
165 }
166
167add_free:
168 /* Re-initialize the SKB queue */
169 tx_buf->len = tx_buf->offset = 0;
170 __skb_queue_head_init(&tx_buf->skb_queue);
171
172 /* Add this TX buffer to the free list */
173 spin_lock(&hif_dev->tx.tx_lock);
174 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
175 hif_dev->tx.tx_buf_cnt++;
176 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
177 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
178 TX_STAT_INC(buf_completed);
179 spin_unlock(&hif_dev->tx.tx_lock);
180}
181
Sujithfb9987d2010-03-17 14:25:25 +0530182/* TX lock has to be taken */
183static int __hif_usb_tx(struct hif_device_usb *hif_dev)
184{
185 struct tx_buf *tx_buf = NULL;
186 struct sk_buff *nskb = NULL;
187 int ret = 0, i;
188 u16 *hdr, tx_skb_cnt = 0;
189 u8 *buf;
190
191 if (hif_dev->tx.tx_skb_cnt == 0)
192 return 0;
193
194 /* Check if a free TX buffer is available */
195 if (list_empty(&hif_dev->tx.tx_buf))
196 return 0;
197
198 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list);
Sujithc11d8f82010-04-23 10:28:09 +0530199 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending);
Sujithfb9987d2010-03-17 14:25:25 +0530200 hif_dev->tx.tx_buf_cnt--;
201
202 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
203
204 for (i = 0; i < tx_skb_cnt; i++) {
205 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
206
207 /* Should never be NULL */
208 BUG_ON(!nskb);
209
210 hif_dev->tx.tx_skb_cnt--;
211
212 buf = tx_buf->buf;
213 buf += tx_buf->offset;
214 hdr = (u16 *)buf;
215 *hdr++ = nskb->len;
216 *hdr++ = ATH_USB_TX_STREAM_MODE_TAG;
217 buf += 4;
218 memcpy(buf, nskb->data, nskb->len);
219 tx_buf->len = nskb->len + 4;
220
221 if (i < (tx_skb_cnt - 1))
222 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
223
224 if (i == (tx_skb_cnt - 1))
225 tx_buf->len += tx_buf->offset;
226
227 __skb_queue_tail(&tx_buf->skb_queue, nskb);
228 TX_STAT_INC(skb_queued);
229 }
230
231 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
232 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE),
233 tx_buf->buf, tx_buf->len,
234 hif_usb_tx_cb, tx_buf);
235
236 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC);
237 if (ret) {
238 tx_buf->len = tx_buf->offset = 0;
Sujitheac8e382010-04-16 11:54:00 +0530239 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue);
Sujithfb9987d2010-03-17 14:25:25 +0530240 __skb_queue_head_init(&tx_buf->skb_queue);
241 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
242 hif_dev->tx.tx_buf_cnt++;
243 }
244
245 if (!ret)
246 TX_STAT_INC(buf_queued);
247
248 return ret;
249}
250
251static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb,
252 struct ath9k_htc_tx_ctl *tx_ctl)
253{
254 unsigned long flags;
255
256 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
257
258 if (hif_dev->tx.flags & HIF_USB_TX_STOP) {
259 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
260 return -ENODEV;
261 }
262
263 /* Check if the max queue count has been reached */
264 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) {
265 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
266 return -ENOMEM;
267 }
268
269 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb);
270 hif_dev->tx.tx_skb_cnt++;
271
272 /* Send normal frames immediately */
273 if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL)))
274 __hif_usb_tx(hif_dev);
275
276 /* Check if AMPDUs have to be sent immediately */
277 if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) &&
278 (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) &&
279 (hif_dev->tx.tx_skb_cnt < 2)) {
280 __hif_usb_tx(hif_dev);
281 }
282
283 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
284
285 return 0;
286}
287
288static void hif_usb_start(void *hif_handle, u8 pipe_id)
289{
290 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
291 unsigned long flags;
292
293 hif_dev->flags |= HIF_USB_START;
294
295 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
296 hif_dev->tx.flags &= ~HIF_USB_TX_STOP;
297 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
298}
299
300static void hif_usb_stop(void *hif_handle, u8 pipe_id)
301{
302 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
303 unsigned long flags;
304
305 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
Sujitheac8e382010-04-16 11:54:00 +0530306 ath9k_skb_queue_purge(hif_dev, &hif_dev->tx.tx_skb_queue);
Sujithfb9987d2010-03-17 14:25:25 +0530307 hif_dev->tx.tx_skb_cnt = 0;
308 hif_dev->tx.flags |= HIF_USB_TX_STOP;
309 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
310}
311
312static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb,
313 struct ath9k_htc_tx_ctl *tx_ctl)
314{
315 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle;
316 int ret = 0;
317
318 switch (pipe_id) {
319 case USB_WLAN_TX_PIPE:
320 ret = hif_usb_send_tx(hif_dev, skb, tx_ctl);
321 break;
322 case USB_REG_OUT_PIPE:
323 ret = hif_usb_send_regout(hif_dev, skb);
324 break;
325 default:
Sujith6335ed02010-03-29 16:07:15 +0530326 dev_err(&hif_dev->udev->dev,
327 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id);
Sujithfb9987d2010-03-17 14:25:25 +0530328 ret = -EINVAL;
329 break;
330 }
331
332 return ret;
333}
334
335static struct ath9k_htc_hif hif_usb = {
336 .transport = ATH9K_HIF_USB,
337 .name = "ath9k_hif_usb",
338
339 .control_ul_pipe = USB_REG_OUT_PIPE,
340 .control_dl_pipe = USB_REG_IN_PIPE,
341
342 .start = hif_usb_start,
343 .stop = hif_usb_stop,
344 .send = hif_usb_send,
345};
346
347static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
348 struct sk_buff *skb)
349{
Sujithc5032692010-04-06 15:28:15 +0530350 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER];
Sujithfb9987d2010-03-17 14:25:25 +0530351 int index = 0, i = 0, chk_idx, len = skb->len;
352 int rx_remain_len = 0, rx_pkt_len = 0;
353 u16 pkt_len, pkt_tag, pool_index = 0;
354 u8 *ptr;
355
Sujith46baa1a2010-04-06 15:28:11 +0530356 spin_lock(&hif_dev->rx_lock);
357
Sujithfb9987d2010-03-17 14:25:25 +0530358 rx_remain_len = hif_dev->rx_remain_len;
359 rx_pkt_len = hif_dev->rx_transfer_len;
360
361 if (rx_remain_len != 0) {
362 struct sk_buff *remain_skb = hif_dev->remain_skb;
363
364 if (remain_skb) {
365 ptr = (u8 *) remain_skb->data;
366
367 index = rx_remain_len;
368 rx_remain_len -= hif_dev->rx_pad_len;
369 ptr += rx_pkt_len;
370
371 memcpy(ptr, skb->data, rx_remain_len);
372
373 rx_pkt_len += rx_remain_len;
374 hif_dev->rx_remain_len = 0;
375 skb_put(remain_skb, rx_pkt_len);
376
377 skb_pool[pool_index++] = remain_skb;
378
379 } else {
380 index = rx_remain_len;
381 }
382 }
383
Sujith46baa1a2010-04-06 15:28:11 +0530384 spin_unlock(&hif_dev->rx_lock);
385
Sujithfb9987d2010-03-17 14:25:25 +0530386 while (index < len) {
387 ptr = (u8 *) skb->data;
388
389 pkt_len = ptr[index] + (ptr[index+1] << 8);
390 pkt_tag = ptr[index+2] + (ptr[index+3] << 8);
391
392 if (pkt_tag == ATH_USB_RX_STREAM_MODE_TAG) {
393 u16 pad_len;
394
395 pad_len = 4 - (pkt_len & 0x3);
396 if (pad_len == 4)
397 pad_len = 0;
398
399 chk_idx = index;
400 index = index + 4 + pkt_len + pad_len;
401
402 if (index > MAX_RX_BUF_SIZE) {
Sujith46baa1a2010-04-06 15:28:11 +0530403 spin_lock(&hif_dev->rx_lock);
Sujithfb9987d2010-03-17 14:25:25 +0530404 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
405 hif_dev->rx_transfer_len =
406 MAX_RX_BUF_SIZE - chk_idx - 4;
407 hif_dev->rx_pad_len = pad_len;
408
409 nskb = __dev_alloc_skb(pkt_len + 32,
410 GFP_ATOMIC);
411 if (!nskb) {
412 dev_err(&hif_dev->udev->dev,
413 "ath9k_htc: RX memory allocation"
414 " error\n");
Sujith46baa1a2010-04-06 15:28:11 +0530415 spin_unlock(&hif_dev->rx_lock);
Sujithfb9987d2010-03-17 14:25:25 +0530416 goto err;
417 }
418 skb_reserve(nskb, 32);
419 RX_STAT_INC(skb_allocated);
420
421 memcpy(nskb->data, &(skb->data[chk_idx+4]),
422 hif_dev->rx_transfer_len);
423
424 /* Record the buffer pointer */
425 hif_dev->remain_skb = nskb;
Sujith46baa1a2010-04-06 15:28:11 +0530426 spin_unlock(&hif_dev->rx_lock);
Sujithfb9987d2010-03-17 14:25:25 +0530427 } else {
428 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
429 if (!nskb) {
430 dev_err(&hif_dev->udev->dev,
431 "ath9k_htc: RX memory allocation"
432 " error\n");
433 goto err;
434 }
435 skb_reserve(nskb, 32);
436 RX_STAT_INC(skb_allocated);
437
438 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
439 skb_put(nskb, pkt_len);
440 skb_pool[pool_index++] = nskb;
441 }
442 } else {
443 RX_STAT_INC(skb_dropped);
Sujithfb9987d2010-03-17 14:25:25 +0530444 return;
445 }
446 }
447
448err:
Sujithfb9987d2010-03-17 14:25:25 +0530449 for (i = 0; i < pool_index; i++) {
450 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
451 skb_pool[i]->len, USB_WLAN_RX_PIPE);
452 RX_STAT_INC(skb_completed);
453 }
454}
455
456static void ath9k_hif_usb_rx_cb(struct urb *urb)
457{
458 struct sk_buff *skb = (struct sk_buff *) urb->context;
Sujithfb9987d2010-03-17 14:25:25 +0530459 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
460 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
461 int ret;
462
Sujith6335ed02010-03-29 16:07:15 +0530463 if (!skb)
464 return;
465
Sujithfb9987d2010-03-17 14:25:25 +0530466 if (!hif_dev)
467 goto free;
468
469 switch (urb->status) {
470 case 0:
471 break;
472 case -ENOENT:
473 case -ECONNRESET:
474 case -ENODEV:
475 case -ESHUTDOWN:
476 goto free;
477 default:
478 goto resubmit;
479 }
480
481 if (likely(urb->actual_length != 0)) {
482 skb_put(skb, urb->actual_length);
Sujithfb9987d2010-03-17 14:25:25 +0530483 ath9k_hif_usb_rx_stream(hif_dev, skb);
Sujithfb9987d2010-03-17 14:25:25 +0530484 }
485
486resubmit:
487 skb_reset_tail_pointer(skb);
488 skb_trim(skb, 0);
489
Sujith6335ed02010-03-29 16:07:15 +0530490 usb_anchor_urb(urb, &hif_dev->rx_submitted);
Sujithfb9987d2010-03-17 14:25:25 +0530491 ret = usb_submit_urb(urb, GFP_ATOMIC);
Sujith6335ed02010-03-29 16:07:15 +0530492 if (ret) {
493 usb_unanchor_urb(urb);
Sujithfb9987d2010-03-17 14:25:25 +0530494 goto free;
Sujith6335ed02010-03-29 16:07:15 +0530495 }
Sujithfb9987d2010-03-17 14:25:25 +0530496
497 return;
498free:
Ming Leif28a7b32010-04-13 00:28:53 +0800499 kfree_skb(skb);
Sujithfb9987d2010-03-17 14:25:25 +0530500}
501
502static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
503{
504 struct sk_buff *skb = (struct sk_buff *) urb->context;
505 struct sk_buff *nskb;
506 struct hif_device_usb *hif_dev = (struct hif_device_usb *)
507 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
508 int ret;
509
Sujith6335ed02010-03-29 16:07:15 +0530510 if (!skb)
511 return;
512
Sujithfb9987d2010-03-17 14:25:25 +0530513 if (!hif_dev)
514 goto free;
515
516 switch (urb->status) {
517 case 0:
518 break;
519 case -ENOENT:
520 case -ECONNRESET:
521 case -ENODEV:
522 case -ESHUTDOWN:
523 goto free;
524 default:
525 goto resubmit;
526 }
527
528 if (likely(urb->actual_length != 0)) {
529 skb_put(skb, urb->actual_length);
530
Sujith5ab0af32010-04-23 10:28:17 +0530531 /* Process the command first */
532 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
533 skb->len, USB_REG_IN_PIPE);
534
535
Ming Leie6c6d332010-04-13 00:29:05 +0800536 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
Sujith5ab0af32010-04-23 10:28:17 +0530537 if (!nskb) {
538 dev_err(&hif_dev->udev->dev,
539 "ath9k_htc: REG_IN memory allocation failure\n");
540 urb->context = NULL;
541 return;
542 }
Sujithfb9987d2010-03-17 14:25:25 +0530543
544 usb_fill_int_urb(urb, hif_dev->udev,
Rajkumar Manoharan0f529e92010-09-16 19:56:55 +0530545 usb_rcvbulkpipe(hif_dev->udev,
546 USB_REG_IN_PIPE),
Sujithfb9987d2010-03-17 14:25:25 +0530547 nskb->data, MAX_REG_IN_BUF_SIZE,
548 ath9k_hif_usb_reg_in_cb, nskb, 1);
549
550 ret = usb_submit_urb(urb, GFP_ATOMIC);
551 if (ret) {
Ming Leie6c6d332010-04-13 00:29:05 +0800552 kfree_skb(nskb);
Sujith5ab0af32010-04-23 10:28:17 +0530553 urb->context = NULL;
Sujithfb9987d2010-03-17 14:25:25 +0530554 }
555
Sujithfb9987d2010-03-17 14:25:25 +0530556 return;
557 }
558
559resubmit:
560 skb_reset_tail_pointer(skb);
561 skb_trim(skb, 0);
562
563 ret = usb_submit_urb(urb, GFP_ATOMIC);
564 if (ret)
565 goto free;
566
567 return;
568free:
Ming Leie6c6d332010-04-13 00:29:05 +0800569 kfree_skb(skb);
Sujith6335ed02010-03-29 16:07:15 +0530570 urb->context = NULL;
Sujithfb9987d2010-03-17 14:25:25 +0530571}
572
573static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
574{
Sujithfb9987d2010-03-17 14:25:25 +0530575 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL;
576
Sujithc11d8f82010-04-23 10:28:09 +0530577 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
578 &hif_dev->tx.tx_buf, list) {
579 usb_kill_urb(tx_buf->urb);
Sujithfb9987d2010-03-17 14:25:25 +0530580 list_del(&tx_buf->list);
581 usb_free_urb(tx_buf->urb);
582 kfree(tx_buf->buf);
583 kfree(tx_buf);
584 }
585
Sujithfb9987d2010-03-17 14:25:25 +0530586 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
587 &hif_dev->tx.tx_pending, list) {
588 usb_kill_urb(tx_buf->urb);
589 list_del(&tx_buf->list);
590 usb_free_urb(tx_buf->urb);
591 kfree(tx_buf->buf);
592 kfree(tx_buf);
593 }
Sujithfb9987d2010-03-17 14:25:25 +0530594}
595
596static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)
597{
598 struct tx_buf *tx_buf;
599 int i;
600
601 INIT_LIST_HEAD(&hif_dev->tx.tx_buf);
602 INIT_LIST_HEAD(&hif_dev->tx.tx_pending);
603 spin_lock_init(&hif_dev->tx.tx_lock);
604 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue);
605
606 for (i = 0; i < MAX_TX_URB_NUM; i++) {
607 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL);
608 if (!tx_buf)
609 goto err;
610
611 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL);
612 if (!tx_buf->buf)
613 goto err;
614
615 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL);
616 if (!tx_buf->urb)
617 goto err;
618
619 tx_buf->hif_dev = hif_dev;
620 __skb_queue_head_init(&tx_buf->skb_queue);
621
622 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
623 }
624
625 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM;
626
627 return 0;
628err:
Dan Carpenter76066882010-05-14 16:52:37 +0200629 if (tx_buf) {
630 kfree(tx_buf->buf);
631 kfree(tx_buf);
632 }
Sujithfb9987d2010-03-17 14:25:25 +0530633 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
634 return -ENOMEM;
635}
636
Sujithfb9987d2010-03-17 14:25:25 +0530637static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
638{
Sujith6335ed02010-03-29 16:07:15 +0530639 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
Sujithfb9987d2010-03-17 14:25:25 +0530640}
641
642static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
643{
Sujith6335ed02010-03-29 16:07:15 +0530644 struct urb *urb = NULL;
645 struct sk_buff *skb = NULL;
Sujithfb9987d2010-03-17 14:25:25 +0530646 int i, ret;
647
Sujith6335ed02010-03-29 16:07:15 +0530648 init_usb_anchor(&hif_dev->rx_submitted);
Sujith46baa1a2010-04-06 15:28:11 +0530649 spin_lock_init(&hif_dev->rx_lock);
Sujith6335ed02010-03-29 16:07:15 +0530650
Sujithfb9987d2010-03-17 14:25:25 +0530651 for (i = 0; i < MAX_RX_URB_NUM; i++) {
652
653 /* Allocate URB */
Sujith6335ed02010-03-29 16:07:15 +0530654 urb = usb_alloc_urb(0, GFP_KERNEL);
655 if (urb == NULL) {
Sujithfb9987d2010-03-17 14:25:25 +0530656 ret = -ENOMEM;
Sujith6335ed02010-03-29 16:07:15 +0530657 goto err_urb;
Sujithfb9987d2010-03-17 14:25:25 +0530658 }
659
660 /* Allocate buffer */
Ming Leif28a7b32010-04-13 00:28:53 +0800661 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL);
Sujith6335ed02010-03-29 16:07:15 +0530662 if (!skb) {
663 ret = -ENOMEM;
664 goto err_skb;
665 }
666
667 usb_fill_bulk_urb(urb, hif_dev->udev,
668 usb_rcvbulkpipe(hif_dev->udev,
669 USB_WLAN_RX_PIPE),
670 skb->data, MAX_RX_BUF_SIZE,
671 ath9k_hif_usb_rx_cb, skb);
672
673 /* Anchor URB */
674 usb_anchor_urb(urb, &hif_dev->rx_submitted);
Sujithfb9987d2010-03-17 14:25:25 +0530675
676 /* Submit URB */
Sujith6335ed02010-03-29 16:07:15 +0530677 ret = usb_submit_urb(urb, GFP_KERNEL);
678 if (ret) {
679 usb_unanchor_urb(urb);
680 goto err_submit;
681 }
Sujith66b10e32010-04-06 15:28:13 +0530682
683 /*
684 * Drop reference count.
685 * This ensures that the URB is freed when killing them.
686 */
687 usb_free_urb(urb);
Sujithfb9987d2010-03-17 14:25:25 +0530688 }
689
690 return 0;
691
Sujith6335ed02010-03-29 16:07:15 +0530692err_submit:
Ming Leif28a7b32010-04-13 00:28:53 +0800693 kfree_skb(skb);
Sujith6335ed02010-03-29 16:07:15 +0530694err_skb:
695 usb_free_urb(urb);
696err_urb:
Sujithfb9987d2010-03-17 14:25:25 +0530697 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
698 return ret;
699}
700
701static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev)
702{
703 if (hif_dev->reg_in_urb) {
704 usb_kill_urb(hif_dev->reg_in_urb);
Sujith6335ed02010-03-29 16:07:15 +0530705 if (hif_dev->reg_in_urb->context)
Ming Leie6c6d332010-04-13 00:29:05 +0800706 kfree_skb((void *)hif_dev->reg_in_urb->context);
Sujithfb9987d2010-03-17 14:25:25 +0530707 usb_free_urb(hif_dev->reg_in_urb);
708 hif_dev->reg_in_urb = NULL;
709 }
710}
711
712static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev)
713{
714 struct sk_buff *skb;
715
716 hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL);
717 if (hif_dev->reg_in_urb == NULL)
718 return -ENOMEM;
719
Ming Leie6c6d332010-04-13 00:29:05 +0800720 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL);
Sujithfb9987d2010-03-17 14:25:25 +0530721 if (!skb)
722 goto err;
723
724 usb_fill_int_urb(hif_dev->reg_in_urb, hif_dev->udev,
Rajkumar Manoharan0f529e92010-09-16 19:56:55 +0530725 usb_rcvbulkpipe(hif_dev->udev,
726 USB_REG_IN_PIPE),
Sujithfb9987d2010-03-17 14:25:25 +0530727 skb->data, MAX_REG_IN_BUF_SIZE,
728 ath9k_hif_usb_reg_in_cb, skb, 1);
729
730 if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0)
Sujith6335ed02010-03-29 16:07:15 +0530731 goto err;
Sujithfb9987d2010-03-17 14:25:25 +0530732
733 return 0;
734
Sujithfb9987d2010-03-17 14:25:25 +0530735err:
736 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
737 return -ENOMEM;
738}
739
740static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev)
741{
Sujith6f0f2662010-04-06 15:28:17 +0530742 /* Register Write */
743 init_usb_anchor(&hif_dev->regout_submitted);
744
Sujithfb9987d2010-03-17 14:25:25 +0530745 /* TX */
746 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0)
747 goto err;
748
749 /* RX */
750 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0)
Rajkumar Manoharanf8036962010-07-07 15:19:18 +0530751 goto err_rx;
Sujithfb9987d2010-03-17 14:25:25 +0530752
Sujith6f0f2662010-04-06 15:28:17 +0530753 /* Register Read */
Sujithfb9987d2010-03-17 14:25:25 +0530754 if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0)
Rajkumar Manoharanf8036962010-07-07 15:19:18 +0530755 goto err_reg;
Sujithfb9987d2010-03-17 14:25:25 +0530756
757 return 0;
Rajkumar Manoharanf8036962010-07-07 15:19:18 +0530758err_reg:
759 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
760err_rx:
761 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
Sujithfb9987d2010-03-17 14:25:25 +0530762err:
763 return -ENOMEM;
764}
765
Sujith.Manoharan@atheros.com1d8af8c2010-05-11 16:24:40 +0530766static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev)
767{
768 usb_kill_anchored_urbs(&hif_dev->regout_submitted);
769 ath9k_hif_usb_dealloc_reg_in_urb(hif_dev);
770 ath9k_hif_usb_dealloc_tx_urbs(hif_dev);
771 ath9k_hif_usb_dealloc_rx_urbs(hif_dev);
772}
773
Sujithfb9987d2010-03-17 14:25:25 +0530774static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
775{
776 int transfer, err;
777 const void *data = hif_dev->firmware->data;
778 size_t len = hif_dev->firmware->size;
779 u32 addr = AR9271_FIRMWARE;
780 u8 *buf = kzalloc(4096, GFP_KERNEL);
Sujithb1762862010-06-02 15:53:34 +0530781 u32 firm_offset;
Sujithfb9987d2010-03-17 14:25:25 +0530782
783 if (!buf)
784 return -ENOMEM;
785
786 while (len) {
787 transfer = min_t(int, len, 4096);
788 memcpy(buf, data, transfer);
789
790 err = usb_control_msg(hif_dev->udev,
791 usb_sndctrlpipe(hif_dev->udev, 0),
792 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
793 addr >> 8, 0, buf, transfer, HZ);
794 if (err < 0) {
795 kfree(buf);
796 return err;
797 }
798
799 len -= transfer;
800 data += transfer;
801 addr += transfer;
802 }
803 kfree(buf);
804
Rajkumar Manoharand6545672010-10-27 12:02:54 +0530805 switch (hif_dev->device_id) {
806 case 0x7010:
807 case 0x7015:
808 case 0x9018:
Sujithb1762862010-06-02 15:53:34 +0530809 firm_offset = AR7010_FIRMWARE_TEXT;
Rajkumar Manoharand6545672010-10-27 12:02:54 +0530810 break;
811 default:
Sujithb1762862010-06-02 15:53:34 +0530812 firm_offset = AR9271_FIRMWARE_TEXT;
Rajkumar Manoharand6545672010-10-27 12:02:54 +0530813 break;
814 }
Sujithb1762862010-06-02 15:53:34 +0530815
Sujithfb9987d2010-03-17 14:25:25 +0530816 /*
817 * Issue FW download complete command to firmware.
818 */
819 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0),
820 FIRMWARE_DOWNLOAD_COMP,
821 0x40 | USB_DIR_OUT,
Sujithb1762862010-06-02 15:53:34 +0530822 firm_offset >> 8, 0, NULL, 0, HZ);
Sujithfb9987d2010-03-17 14:25:25 +0530823 if (err)
824 return -EIO;
825
826 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n",
Sujithce43cee2010-06-02 15:53:30 +0530827 hif_dev->fw_name, (unsigned long) hif_dev->firmware->size);
Sujithfb9987d2010-03-17 14:25:25 +0530828
829 return 0;
830}
831
Sujithce43cee2010-06-02 15:53:30 +0530832static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
Sujithfb9987d2010-03-17 14:25:25 +0530833{
Rajkumar Manoharan4a0e8ec2010-09-14 14:35:55 +0530834 int ret, idx;
835 struct usb_host_interface *alt = &hif_dev->interface->altsetting[0];
836 struct usb_endpoint_descriptor *endp;
Sujithfb9987d2010-03-17 14:25:25 +0530837
838 /* Request firmware */
Sujithce43cee2010-06-02 15:53:30 +0530839 ret = request_firmware(&hif_dev->firmware, hif_dev->fw_name,
840 &hif_dev->udev->dev);
Sujithfb9987d2010-03-17 14:25:25 +0530841 if (ret) {
842 dev_err(&hif_dev->udev->dev,
Sujithce43cee2010-06-02 15:53:30 +0530843 "ath9k_htc: Firmware - %s not found\n", hif_dev->fw_name);
Sujithfb9987d2010-03-17 14:25:25 +0530844 goto err_fw_req;
845 }
846
Sujithfb9987d2010-03-17 14:25:25 +0530847 /* Alloc URBs */
848 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
849 if (ret) {
850 dev_err(&hif_dev->udev->dev,
851 "ath9k_htc: Unable to allocate URBs\n");
852 goto err_urb;
853 }
854
Sujith.Manoharan@atheros.com1d8af8c2010-05-11 16:24:40 +0530855 /* Download firmware */
856 ret = ath9k_hif_usb_download_fw(hif_dev);
857 if (ret) {
858 dev_err(&hif_dev->udev->dev,
Sujithce43cee2010-06-02 15:53:30 +0530859 "ath9k_htc: Firmware - %s download failed\n",
860 hif_dev->fw_name);
Sujith.Manoharan@atheros.com1d8af8c2010-05-11 16:24:40 +0530861 goto err_fw_download;
862 }
863
Rajkumar Manoharan4a0e8ec2010-09-14 14:35:55 +0530864 /* On downloading the firmware to the target, the USB descriptor of EP4
865 * is 'patched' to change the type of the endpoint to Bulk. This will
866 * bring down CPU usage during the scan period.
867 */
868 for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
869 endp = &alt->endpoint[idx].desc;
870 if (((endp->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
871 == 0x04) &&
872 ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
873 == USB_ENDPOINT_XFER_INT)) {
874 endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
875 endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
876 endp->bInterval = 0;
877 }
878 }
879
Sujithfb9987d2010-03-17 14:25:25 +0530880 return 0;
881
Sujithfb9987d2010-03-17 14:25:25 +0530882err_fw_download:
Sujith.Manoharan@atheros.com1d8af8c2010-05-11 16:24:40 +0530883 ath9k_hif_usb_dealloc_urbs(hif_dev);
884err_urb:
Sujithfb9987d2010-03-17 14:25:25 +0530885 release_firmware(hif_dev->firmware);
886err_fw_req:
887 hif_dev->firmware = NULL;
888 return ret;
889}
890
Sujithfb9987d2010-03-17 14:25:25 +0530891static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev)
892{
893 ath9k_hif_usb_dealloc_urbs(hif_dev);
894 if (hif_dev->firmware)
895 release_firmware(hif_dev->firmware);
896}
897
898static int ath9k_hif_usb_probe(struct usb_interface *interface,
899 const struct usb_device_id *id)
900{
901 struct usb_device *udev = interface_to_usbdev(interface);
902 struct hif_device_usb *hif_dev;
Sujithfb9987d2010-03-17 14:25:25 +0530903 int ret = 0;
904
905 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL);
906 if (!hif_dev) {
907 ret = -ENOMEM;
908 goto err_alloc;
909 }
910
911 usb_get_dev(udev);
912 hif_dev->udev = udev;
913 hif_dev->interface = interface;
914 hif_dev->device_id = id->idProduct;
915#ifdef CONFIG_PM
916 udev->reset_resume = 1;
917#endif
918 usb_set_intfdata(interface, hif_dev);
919
Sujith.Manoharan@atheros.com47fce022010-05-11 16:24:41 +0530920 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb,
921 &hif_dev->udev->dev);
922 if (hif_dev->htc_handle == NULL) {
923 ret = -ENOMEM;
924 goto err_htc_hw_alloc;
925 }
926
Sujithce43cee2010-06-02 15:53:30 +0530927 /* Find out which firmware to load */
928
929 switch(hif_dev->device_id) {
Sujithb1762862010-06-02 15:53:34 +0530930 case 0x7010:
Rajkumar Manoharanca6cff12010-08-13 18:36:40 +0530931 case 0x7015:
Sujith4e63f762010-06-17 10:29:01 +0530932 case 0x9018:
Sujithb1762862010-06-02 15:53:34 +0530933 if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x0202)
John W. Linvilled0ee0eb2010-06-23 14:20:45 -0400934 hif_dev->fw_name = FIRMWARE_AR7010_1_1;
Sujithb1762862010-06-02 15:53:34 +0530935 else
John W. Linvilled0ee0eb2010-06-23 14:20:45 -0400936 hif_dev->fw_name = FIRMWARE_AR7010;
Sujithb1762862010-06-02 15:53:34 +0530937 break;
Sujithce43cee2010-06-02 15:53:30 +0530938 default:
John W. Linvilled0ee0eb2010-06-23 14:20:45 -0400939 hif_dev->fw_name = FIRMWARE_AR9271;
Sujithce43cee2010-06-02 15:53:30 +0530940 break;
941 }
942
Sujithce43cee2010-06-02 15:53:30 +0530943 ret = ath9k_hif_usb_dev_init(hif_dev);
Sujithfb9987d2010-03-17 14:25:25 +0530944 if (ret) {
945 ret = -EINVAL;
946 goto err_hif_init_usb;
947 }
948
Sujith.Manoharan@atheros.com47fce022010-05-11 16:24:41 +0530949 ret = ath9k_htc_hw_init(hif_dev->htc_handle,
Vivek Natarajan21cb9872010-08-18 19:57:49 +0530950 &hif_dev->udev->dev, hif_dev->device_id,
951 hif_dev->udev->product);
Sujithfb9987d2010-03-17 14:25:25 +0530952 if (ret) {
953 ret = -EINVAL;
954 goto err_htc_hw_init;
955 }
956
957 dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n");
958
959 return 0;
960
961err_htc_hw_init:
Sujithfb9987d2010-03-17 14:25:25 +0530962 ath9k_hif_usb_dev_deinit(hif_dev);
963err_hif_init_usb:
Sujith.Manoharan@atheros.com47fce022010-05-11 16:24:41 +0530964 ath9k_htc_hw_free(hif_dev->htc_handle);
965err_htc_hw_alloc:
Sujithfb9987d2010-03-17 14:25:25 +0530966 usb_set_intfdata(interface, NULL);
967 kfree(hif_dev);
968 usb_put_dev(udev);
969err_alloc:
970 return ret;
971}
972
Sujith62e47162010-04-23 10:28:16 +0530973static void ath9k_hif_usb_reboot(struct usb_device *udev)
974{
975 u32 reboot_cmd = 0xffffffff;
976 void *buf;
977 int ret;
978
Julia Lawalla465a2c2010-05-15 23:17:19 +0200979 buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL);
Sujith62e47162010-04-23 10:28:16 +0530980 if (!buf)
981 return;
982
Sujith62e47162010-04-23 10:28:16 +0530983 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
984 buf, 4, NULL, HZ);
985 if (ret)
986 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
987
988 kfree(buf);
989}
990
Sujithfb9987d2010-03-17 14:25:25 +0530991static void ath9k_hif_usb_disconnect(struct usb_interface *interface)
992{
993 struct usb_device *udev = interface_to_usbdev(interface);
994 struct hif_device_usb *hif_dev =
995 (struct hif_device_usb *) usb_get_intfdata(interface);
996
997 if (hif_dev) {
Sujithd8f996f2010-04-23 10:28:20 +0530998 ath9k_htc_hw_deinit(hif_dev->htc_handle,
999 (udev->state == USB_STATE_NOTATTACHED) ? true : false);
Sujithfb9987d2010-03-17 14:25:25 +05301000 ath9k_htc_hw_free(hif_dev->htc_handle);
1001 ath9k_hif_usb_dev_deinit(hif_dev);
1002 usb_set_intfdata(interface, NULL);
1003 }
1004
1005 if (hif_dev->flags & HIF_USB_START)
Sujith62e47162010-04-23 10:28:16 +05301006 ath9k_hif_usb_reboot(udev);
Sujithfb9987d2010-03-17 14:25:25 +05301007
1008 kfree(hif_dev);
1009 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n");
1010 usb_put_dev(udev);
1011}
1012
1013#ifdef CONFIG_PM
1014static int ath9k_hif_usb_suspend(struct usb_interface *interface,
1015 pm_message_t message)
1016{
1017 struct hif_device_usb *hif_dev =
1018 (struct hif_device_usb *) usb_get_intfdata(interface);
1019
1020 ath9k_hif_usb_dealloc_urbs(hif_dev);
1021
1022 return 0;
1023}
1024
1025static int ath9k_hif_usb_resume(struct usb_interface *interface)
1026{
1027 struct hif_device_usb *hif_dev =
1028 (struct hif_device_usb *) usb_get_intfdata(interface);
1029 int ret;
1030
1031 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
1032 if (ret)
1033 return ret;
1034
1035 if (hif_dev->firmware) {
1036 ret = ath9k_hif_usb_download_fw(hif_dev);
1037 if (ret)
1038 goto fail_resume;
1039 } else {
1040 ath9k_hif_usb_dealloc_urbs(hif_dev);
1041 return -EIO;
1042 }
1043
1044 mdelay(100);
1045
1046 ret = ath9k_htc_resume(hif_dev->htc_handle);
1047
1048 if (ret)
1049 goto fail_resume;
1050
1051 return 0;
1052
1053fail_resume:
1054 ath9k_hif_usb_dealloc_urbs(hif_dev);
1055
1056 return ret;
1057}
1058#endif
1059
1060static struct usb_driver ath9k_hif_usb_driver = {
1061 .name = "ath9k_hif_usb",
1062 .probe = ath9k_hif_usb_probe,
1063 .disconnect = ath9k_hif_usb_disconnect,
1064#ifdef CONFIG_PM
1065 .suspend = ath9k_hif_usb_suspend,
1066 .resume = ath9k_hif_usb_resume,
1067 .reset_resume = ath9k_hif_usb_resume,
1068#endif
1069 .id_table = ath9k_hif_usb_ids,
1070 .soft_unbind = 1,
1071};
1072
1073int ath9k_hif_usb_init(void)
1074{
1075 return usb_register(&ath9k_hif_usb_driver);
1076}
1077
1078void ath9k_hif_usb_exit(void)
1079{
1080 usb_deregister(&ath9k_hif_usb_driver);
1081}