Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1 | /* |
| 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. Linville | d0ee0eb | 2010-06-23 14:20:45 -0400 | [diff] [blame] | 19 | /* identify firmware images */ |
| 20 | #define FIRMWARE_AR7010 "ar7010.fw" |
| 21 | #define FIRMWARE_AR7010_1_1 "ar7010_1_1.fw" |
| 22 | #define FIRMWARE_AR9271 "ar9271.fw" |
| 23 | |
| 24 | MODULE_FIRMWARE(FIRMWARE_AR7010); |
| 25 | MODULE_FIRMWARE(FIRMWARE_AR7010_1_1); |
| 26 | MODULE_FIRMWARE(FIRMWARE_AR9271); |
| 27 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 28 | static struct usb_device_id ath9k_hif_usb_ids[] = { |
Sujith | 4e63f76 | 2010-06-17 10:29:01 +0530 | [diff] [blame] | 29 | { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */ |
| 30 | { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */ |
Sujith | 4e63f76 | 2010-06-17 10:29:01 +0530 | [diff] [blame] | 31 | { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */ |
Sujith | 4e63f76 | 2010-06-17 10:29:01 +0530 | [diff] [blame] | 32 | { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */ |
| 33 | { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */ |
| 34 | { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */ |
Haitao Zhang | ac618d7 | 2010-11-07 12:50:24 +0800 | [diff] [blame] | 35 | { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */ |
Rajkumar Manoharan | 32b0895 | 2010-11-10 17:51:24 +0530 | [diff] [blame] | 36 | { USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */ |
| 37 | { USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */ |
| 38 | { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */ |
Sujith | 4e63f76 | 2010-06-17 10:29:01 +0530 | [diff] [blame] | 39 | { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */ |
Rajkumar Manoharan | 32b0895 | 2010-11-10 17:51:24 +0530 | [diff] [blame] | 40 | { USB_DEVICE(0x040D, 0x3801) }, /* VIA */ |
Sujith Manoharan | 452d7dd | 2010-12-13 07:39:32 +0530 | [diff] [blame] | 41 | { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */ |
Sujith Manoharan | 0b5ead9 | 2010-12-07 16:31:38 +0530 | [diff] [blame] | 42 | |
| 43 | { USB_DEVICE(0x0cf3, 0x7015), |
| 44 | .driver_info = AR9287_USB }, /* Atheros */ |
Rajkumar Manoharan | 64f1217 | 2010-11-19 16:53:20 +0530 | [diff] [blame] | 45 | { USB_DEVICE(0x1668, 0x1200), |
Sujith Manoharan | 0b5ead9 | 2010-12-07 16:31:38 +0530 | [diff] [blame] | 46 | .driver_info = AR9287_USB }, /* Verizon */ |
| 47 | |
| 48 | { USB_DEVICE(0x0cf3, 0x7010), |
| 49 | .driver_info = AR9280_USB }, /* Atheros */ |
| 50 | { USB_DEVICE(0x0846, 0x9018), |
| 51 | .driver_info = AR9280_USB }, /* Netgear WNDA3200 */ |
| 52 | { USB_DEVICE(0x083A, 0xA704), |
| 53 | .driver_info = AR9280_USB }, /* SMC Networks */ |
| 54 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 55 | { }, |
| 56 | }; |
| 57 | |
| 58 | MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids); |
| 59 | |
| 60 | static int __hif_usb_tx(struct hif_device_usb *hif_dev); |
| 61 | |
| 62 | static void hif_usb_regout_cb(struct urb *urb) |
| 63 | { |
| 64 | struct cmd_buf *cmd = (struct cmd_buf *)urb->context; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 65 | |
| 66 | switch (urb->status) { |
| 67 | case 0: |
| 68 | break; |
| 69 | case -ENOENT: |
| 70 | case -ECONNRESET: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 71 | case -ENODEV: |
| 72 | case -ESHUTDOWN: |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 73 | goto free; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 74 | default: |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | if (cmd) { |
| 79 | ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle, |
| 80 | cmd->skb, 1); |
| 81 | kfree(cmd); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 82 | } |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 83 | |
| 84 | return; |
| 85 | free: |
Ming Lei | 0fa35a5 | 2010-04-13 00:29:15 +0800 | [diff] [blame] | 86 | kfree_skb(cmd->skb); |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 87 | kfree(cmd); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static int hif_usb_send_regout(struct hif_device_usb *hif_dev, |
| 91 | struct sk_buff *skb) |
| 92 | { |
| 93 | struct urb *urb; |
| 94 | struct cmd_buf *cmd; |
| 95 | int ret = 0; |
| 96 | |
| 97 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 98 | if (urb == NULL) |
| 99 | return -ENOMEM; |
| 100 | |
| 101 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 102 | if (cmd == NULL) { |
| 103 | usb_free_urb(urb); |
| 104 | return -ENOMEM; |
| 105 | } |
| 106 | |
| 107 | cmd->skb = skb; |
| 108 | cmd->hif_dev = hif_dev; |
| 109 | |
Rajkumar Manoharan | 4a0e8ec | 2010-09-14 14:35:55 +0530 | [diff] [blame] | 110 | usb_fill_bulk_urb(urb, hif_dev->udev, |
| 111 | usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE), |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 112 | skb->data, skb->len, |
Rajkumar Manoharan | 4a0e8ec | 2010-09-14 14:35:55 +0530 | [diff] [blame] | 113 | hif_usb_regout_cb, cmd); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 114 | |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 115 | usb_anchor_urb(urb, &hif_dev->regout_submitted); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 116 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 117 | if (ret) { |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 118 | usb_unanchor_urb(urb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 119 | kfree(cmd); |
| 120 | } |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 121 | usb_free_urb(urb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 126 | static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev, |
| 127 | struct sk_buff_head *list) |
Ming Lei | f8e1d08 | 2010-04-13 00:29:27 +0800 | [diff] [blame] | 128 | { |
| 129 | struct sk_buff *skb; |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 130 | |
| 131 | while ((skb = __skb_dequeue(list)) != NULL) { |
Ming Lei | f8e1d08 | 2010-04-13 00:29:27 +0800 | [diff] [blame] | 132 | dev_kfree_skb_any(skb); |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 133 | TX_STAT_INC(skb_dropped); |
| 134 | } |
Ming Lei | f8e1d08 | 2010-04-13 00:29:27 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 137 | static void hif_usb_tx_cb(struct urb *urb) |
| 138 | { |
| 139 | struct tx_buf *tx_buf = (struct tx_buf *) urb->context; |
Dan Carpenter | 690e781 | 2010-05-14 16:50:56 +0200 | [diff] [blame] | 140 | struct hif_device_usb *hif_dev; |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 141 | struct sk_buff *skb; |
| 142 | |
Dan Carpenter | 690e781 | 2010-05-14 16:50:56 +0200 | [diff] [blame] | 143 | if (!tx_buf || !tx_buf->hif_dev) |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 144 | return; |
| 145 | |
Dan Carpenter | 690e781 | 2010-05-14 16:50:56 +0200 | [diff] [blame] | 146 | hif_dev = tx_buf->hif_dev; |
| 147 | |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 148 | switch (urb->status) { |
| 149 | case 0: |
| 150 | break; |
| 151 | case -ENOENT: |
| 152 | case -ECONNRESET: |
| 153 | case -ENODEV: |
| 154 | case -ESHUTDOWN: |
| 155 | /* |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 156 | * The URB has been killed, free the SKBs. |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 157 | */ |
| 158 | ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue); |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * If the URBs are being flushed, no need to add this |
| 162 | * URB to the free list. |
| 163 | */ |
| 164 | spin_lock(&hif_dev->tx.tx_lock); |
| 165 | if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) { |
| 166 | spin_unlock(&hif_dev->tx.tx_lock); |
| 167 | return; |
| 168 | } |
| 169 | spin_unlock(&hif_dev->tx.tx_lock); |
| 170 | |
| 171 | /* |
| 172 | * In the stop() case, this URB has to be added to |
| 173 | * the free list. |
| 174 | */ |
| 175 | goto add_free; |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 176 | default: |
| 177 | break; |
| 178 | } |
| 179 | |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 180 | /* |
| 181 | * Check if TX has been stopped, this is needed because |
| 182 | * this CB could have been invoked just after the TX lock |
| 183 | * was released in hif_stop() and kill_urb() hasn't been |
| 184 | * called yet. |
| 185 | */ |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 186 | spin_lock(&hif_dev->tx.tx_lock); |
| 187 | if (hif_dev->tx.flags & HIF_USB_TX_STOP) { |
| 188 | spin_unlock(&hif_dev->tx.tx_lock); |
| 189 | ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue); |
| 190 | goto add_free; |
| 191 | } |
| 192 | spin_unlock(&hif_dev->tx.tx_lock); |
| 193 | |
| 194 | /* Complete the queued SKBs. */ |
| 195 | while ((skb = __skb_dequeue(&tx_buf->skb_queue)) != NULL) { |
| 196 | ath9k_htc_txcompletion_cb(hif_dev->htc_handle, |
| 197 | skb, 1); |
| 198 | TX_STAT_INC(skb_completed); |
| 199 | } |
| 200 | |
| 201 | add_free: |
| 202 | /* Re-initialize the SKB queue */ |
| 203 | tx_buf->len = tx_buf->offset = 0; |
| 204 | __skb_queue_head_init(&tx_buf->skb_queue); |
| 205 | |
| 206 | /* Add this TX buffer to the free list */ |
| 207 | spin_lock(&hif_dev->tx.tx_lock); |
| 208 | list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); |
| 209 | hif_dev->tx.tx_buf_cnt++; |
| 210 | if (!(hif_dev->tx.flags & HIF_USB_TX_STOP)) |
| 211 | __hif_usb_tx(hif_dev); /* Check for pending SKBs */ |
| 212 | TX_STAT_INC(buf_completed); |
| 213 | spin_unlock(&hif_dev->tx.tx_lock); |
| 214 | } |
| 215 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 216 | /* TX lock has to be taken */ |
| 217 | static int __hif_usb_tx(struct hif_device_usb *hif_dev) |
| 218 | { |
| 219 | struct tx_buf *tx_buf = NULL; |
| 220 | struct sk_buff *nskb = NULL; |
| 221 | int ret = 0, i; |
| 222 | u16 *hdr, tx_skb_cnt = 0; |
| 223 | u8 *buf; |
| 224 | |
| 225 | if (hif_dev->tx.tx_skb_cnt == 0) |
| 226 | return 0; |
| 227 | |
| 228 | /* Check if a free TX buffer is available */ |
| 229 | if (list_empty(&hif_dev->tx.tx_buf)) |
| 230 | return 0; |
| 231 | |
| 232 | tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list); |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 233 | list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 234 | hif_dev->tx.tx_buf_cnt--; |
| 235 | |
| 236 | tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM); |
| 237 | |
| 238 | for (i = 0; i < tx_skb_cnt; i++) { |
| 239 | nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue); |
| 240 | |
| 241 | /* Should never be NULL */ |
| 242 | BUG_ON(!nskb); |
| 243 | |
| 244 | hif_dev->tx.tx_skb_cnt--; |
| 245 | |
| 246 | buf = tx_buf->buf; |
| 247 | buf += tx_buf->offset; |
| 248 | hdr = (u16 *)buf; |
| 249 | *hdr++ = nskb->len; |
| 250 | *hdr++ = ATH_USB_TX_STREAM_MODE_TAG; |
| 251 | buf += 4; |
| 252 | memcpy(buf, nskb->data, nskb->len); |
| 253 | tx_buf->len = nskb->len + 4; |
| 254 | |
| 255 | if (i < (tx_skb_cnt - 1)) |
| 256 | tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4; |
| 257 | |
| 258 | if (i == (tx_skb_cnt - 1)) |
| 259 | tx_buf->len += tx_buf->offset; |
| 260 | |
| 261 | __skb_queue_tail(&tx_buf->skb_queue, nskb); |
| 262 | TX_STAT_INC(skb_queued); |
| 263 | } |
| 264 | |
| 265 | usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev, |
| 266 | usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE), |
| 267 | tx_buf->buf, tx_buf->len, |
| 268 | hif_usb_tx_cb, tx_buf); |
| 269 | |
| 270 | ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC); |
| 271 | if (ret) { |
| 272 | tx_buf->len = tx_buf->offset = 0; |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 273 | ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 274 | __skb_queue_head_init(&tx_buf->skb_queue); |
| 275 | list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); |
| 276 | hif_dev->tx.tx_buf_cnt++; |
| 277 | } |
| 278 | |
| 279 | if (!ret) |
| 280 | TX_STAT_INC(buf_queued); |
| 281 | |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb, |
| 286 | struct ath9k_htc_tx_ctl *tx_ctl) |
| 287 | { |
| 288 | unsigned long flags; |
| 289 | |
| 290 | spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); |
| 291 | |
| 292 | if (hif_dev->tx.flags & HIF_USB_TX_STOP) { |
| 293 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
| 294 | return -ENODEV; |
| 295 | } |
| 296 | |
| 297 | /* Check if the max queue count has been reached */ |
| 298 | if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) { |
| 299 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
| 300 | return -ENOMEM; |
| 301 | } |
| 302 | |
| 303 | __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb); |
| 304 | hif_dev->tx.tx_skb_cnt++; |
| 305 | |
| 306 | /* Send normal frames immediately */ |
| 307 | if (!tx_ctl || (tx_ctl && (tx_ctl->type == ATH9K_HTC_NORMAL))) |
| 308 | __hif_usb_tx(hif_dev); |
| 309 | |
| 310 | /* Check if AMPDUs have to be sent immediately */ |
| 311 | if (tx_ctl && (tx_ctl->type == ATH9K_HTC_AMPDU) && |
| 312 | (hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) && |
| 313 | (hif_dev->tx.tx_skb_cnt < 2)) { |
| 314 | __hif_usb_tx(hif_dev); |
| 315 | } |
| 316 | |
| 317 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static void hif_usb_start(void *hif_handle, u8 pipe_id) |
| 323 | { |
| 324 | struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; |
| 325 | unsigned long flags; |
| 326 | |
| 327 | hif_dev->flags |= HIF_USB_START; |
| 328 | |
| 329 | spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); |
| 330 | hif_dev->tx.flags &= ~HIF_USB_TX_STOP; |
| 331 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
| 332 | } |
| 333 | |
| 334 | static void hif_usb_stop(void *hif_handle, u8 pipe_id) |
| 335 | { |
| 336 | struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 337 | struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 338 | unsigned long flags; |
| 339 | |
| 340 | spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); |
Sujith | eac8e38 | 2010-04-16 11:54:00 +0530 | [diff] [blame] | 341 | ath9k_skb_queue_purge(hif_dev, &hif_dev->tx.tx_skb_queue); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 342 | hif_dev->tx.tx_skb_cnt = 0; |
| 343 | hif_dev->tx.flags |= HIF_USB_TX_STOP; |
| 344 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 345 | |
| 346 | /* The pending URBs have to be canceled. */ |
| 347 | list_for_each_entry_safe(tx_buf, tx_buf_tmp, |
| 348 | &hif_dev->tx.tx_pending, list) { |
| 349 | usb_kill_urb(tx_buf->urb); |
| 350 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb, |
| 354 | struct ath9k_htc_tx_ctl *tx_ctl) |
| 355 | { |
| 356 | struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; |
| 357 | int ret = 0; |
| 358 | |
| 359 | switch (pipe_id) { |
| 360 | case USB_WLAN_TX_PIPE: |
| 361 | ret = hif_usb_send_tx(hif_dev, skb, tx_ctl); |
| 362 | break; |
| 363 | case USB_REG_OUT_PIPE: |
| 364 | ret = hif_usb_send_regout(hif_dev, skb); |
| 365 | break; |
| 366 | default: |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 367 | dev_err(&hif_dev->udev->dev, |
| 368 | "ath9k_htc: Invalid TX pipe: %d\n", pipe_id); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 369 | ret = -EINVAL; |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | return ret; |
| 374 | } |
| 375 | |
| 376 | static struct ath9k_htc_hif hif_usb = { |
| 377 | .transport = ATH9K_HIF_USB, |
| 378 | .name = "ath9k_hif_usb", |
| 379 | |
| 380 | .control_ul_pipe = USB_REG_OUT_PIPE, |
| 381 | .control_dl_pipe = USB_REG_IN_PIPE, |
| 382 | |
| 383 | .start = hif_usb_start, |
| 384 | .stop = hif_usb_stop, |
| 385 | .send = hif_usb_send, |
| 386 | }; |
| 387 | |
| 388 | static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, |
| 389 | struct sk_buff *skb) |
| 390 | { |
Sujith | c503269 | 2010-04-06 15:28:15 +0530 | [diff] [blame] | 391 | struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER]; |
Joe Perches | 44b23b4 | 2010-11-30 12:19:11 -0800 | [diff] [blame] | 392 | int index = 0, i = 0, len = skb->len; |
| 393 | int rx_remain_len, rx_pkt_len; |
| 394 | u16 pool_index = 0; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 395 | u8 *ptr; |
| 396 | |
Sujith | 46baa1a | 2010-04-06 15:28:11 +0530 | [diff] [blame] | 397 | spin_lock(&hif_dev->rx_lock); |
| 398 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 399 | rx_remain_len = hif_dev->rx_remain_len; |
| 400 | rx_pkt_len = hif_dev->rx_transfer_len; |
| 401 | |
| 402 | if (rx_remain_len != 0) { |
| 403 | struct sk_buff *remain_skb = hif_dev->remain_skb; |
| 404 | |
| 405 | if (remain_skb) { |
| 406 | ptr = (u8 *) remain_skb->data; |
| 407 | |
| 408 | index = rx_remain_len; |
| 409 | rx_remain_len -= hif_dev->rx_pad_len; |
| 410 | ptr += rx_pkt_len; |
| 411 | |
| 412 | memcpy(ptr, skb->data, rx_remain_len); |
| 413 | |
| 414 | rx_pkt_len += rx_remain_len; |
| 415 | hif_dev->rx_remain_len = 0; |
| 416 | skb_put(remain_skb, rx_pkt_len); |
| 417 | |
| 418 | skb_pool[pool_index++] = remain_skb; |
| 419 | |
| 420 | } else { |
| 421 | index = rx_remain_len; |
| 422 | } |
| 423 | } |
| 424 | |
Sujith | 46baa1a | 2010-04-06 15:28:11 +0530 | [diff] [blame] | 425 | spin_unlock(&hif_dev->rx_lock); |
| 426 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 427 | while (index < len) { |
Joe Perches | 44b23b4 | 2010-11-30 12:19:11 -0800 | [diff] [blame] | 428 | u16 pkt_len; |
| 429 | u16 pkt_tag; |
| 430 | u16 pad_len; |
| 431 | int chk_idx; |
| 432 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 433 | ptr = (u8 *) skb->data; |
| 434 | |
| 435 | pkt_len = ptr[index] + (ptr[index+1] << 8); |
| 436 | pkt_tag = ptr[index+2] + (ptr[index+3] << 8); |
| 437 | |
Joe Perches | 44b23b4 | 2010-11-30 12:19:11 -0800 | [diff] [blame] | 438 | if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 439 | RX_STAT_INC(skb_dropped); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 440 | return; |
| 441 | } |
Joe Perches | 44b23b4 | 2010-11-30 12:19:11 -0800 | [diff] [blame] | 442 | |
| 443 | pad_len = 4 - (pkt_len & 0x3); |
| 444 | if (pad_len == 4) |
| 445 | pad_len = 0; |
| 446 | |
| 447 | chk_idx = index; |
| 448 | index = index + 4 + pkt_len + pad_len; |
| 449 | |
| 450 | if (index > MAX_RX_BUF_SIZE) { |
| 451 | spin_lock(&hif_dev->rx_lock); |
| 452 | hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE; |
| 453 | hif_dev->rx_transfer_len = |
| 454 | MAX_RX_BUF_SIZE - chk_idx - 4; |
| 455 | hif_dev->rx_pad_len = pad_len; |
| 456 | |
| 457 | nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); |
| 458 | if (!nskb) { |
| 459 | dev_err(&hif_dev->udev->dev, |
| 460 | "ath9k_htc: RX memory allocation error\n"); |
| 461 | spin_unlock(&hif_dev->rx_lock); |
| 462 | goto err; |
| 463 | } |
| 464 | skb_reserve(nskb, 32); |
| 465 | RX_STAT_INC(skb_allocated); |
| 466 | |
| 467 | memcpy(nskb->data, &(skb->data[chk_idx+4]), |
| 468 | hif_dev->rx_transfer_len); |
| 469 | |
| 470 | /* Record the buffer pointer */ |
| 471 | hif_dev->remain_skb = nskb; |
| 472 | spin_unlock(&hif_dev->rx_lock); |
| 473 | } else { |
| 474 | nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); |
| 475 | if (!nskb) { |
| 476 | dev_err(&hif_dev->udev->dev, |
| 477 | "ath9k_htc: RX memory allocation error\n"); |
| 478 | goto err; |
| 479 | } |
| 480 | skb_reserve(nskb, 32); |
| 481 | RX_STAT_INC(skb_allocated); |
| 482 | |
| 483 | memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len); |
| 484 | skb_put(nskb, pkt_len); |
| 485 | skb_pool[pool_index++] = nskb; |
| 486 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | err: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 490 | for (i = 0; i < pool_index; i++) { |
| 491 | ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i], |
| 492 | skb_pool[i]->len, USB_WLAN_RX_PIPE); |
| 493 | RX_STAT_INC(skb_completed); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | static void ath9k_hif_usb_rx_cb(struct urb *urb) |
| 498 | { |
| 499 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 500 | struct hif_device_usb *hif_dev = |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 501 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); |
| 502 | int ret; |
| 503 | |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 504 | if (!skb) |
| 505 | return; |
| 506 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 507 | if (!hif_dev) |
| 508 | goto free; |
| 509 | |
| 510 | switch (urb->status) { |
| 511 | case 0: |
| 512 | break; |
| 513 | case -ENOENT: |
| 514 | case -ECONNRESET: |
| 515 | case -ENODEV: |
| 516 | case -ESHUTDOWN: |
| 517 | goto free; |
| 518 | default: |
| 519 | goto resubmit; |
| 520 | } |
| 521 | |
| 522 | if (likely(urb->actual_length != 0)) { |
| 523 | skb_put(skb, urb->actual_length); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 524 | ath9k_hif_usb_rx_stream(hif_dev, skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | resubmit: |
| 528 | skb_reset_tail_pointer(skb); |
| 529 | skb_trim(skb, 0); |
| 530 | |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 531 | usb_anchor_urb(urb, &hif_dev->rx_submitted); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 532 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 533 | if (ret) { |
| 534 | usb_unanchor_urb(urb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 535 | goto free; |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 536 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 537 | |
| 538 | return; |
| 539 | free: |
Ming Lei | f28a7b3 | 2010-04-13 00:28:53 +0800 | [diff] [blame] | 540 | kfree_skb(skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static void ath9k_hif_usb_reg_in_cb(struct urb *urb) |
| 544 | { |
| 545 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
| 546 | struct sk_buff *nskb; |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 547 | struct hif_device_usb *hif_dev = |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 548 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); |
| 549 | int ret; |
| 550 | |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 551 | if (!skb) |
| 552 | return; |
| 553 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 554 | if (!hif_dev) |
| 555 | goto free; |
| 556 | |
| 557 | switch (urb->status) { |
| 558 | case 0: |
| 559 | break; |
| 560 | case -ENOENT: |
| 561 | case -ECONNRESET: |
| 562 | case -ENODEV: |
| 563 | case -ESHUTDOWN: |
| 564 | goto free; |
| 565 | default: |
| 566 | goto resubmit; |
| 567 | } |
| 568 | |
| 569 | if (likely(urb->actual_length != 0)) { |
| 570 | skb_put(skb, urb->actual_length); |
| 571 | |
Sujith | 5ab0af3 | 2010-04-23 10:28:17 +0530 | [diff] [blame] | 572 | /* Process the command first */ |
| 573 | ath9k_htc_rx_msg(hif_dev->htc_handle, skb, |
| 574 | skb->len, USB_REG_IN_PIPE); |
| 575 | |
| 576 | |
Ming Lei | e6c6d33 | 2010-04-13 00:29:05 +0800 | [diff] [blame] | 577 | nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC); |
Sujith | 5ab0af3 | 2010-04-23 10:28:17 +0530 | [diff] [blame] | 578 | if (!nskb) { |
| 579 | dev_err(&hif_dev->udev->dev, |
| 580 | "ath9k_htc: REG_IN memory allocation failure\n"); |
| 581 | urb->context = NULL; |
| 582 | return; |
| 583 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 584 | |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 585 | usb_fill_bulk_urb(urb, hif_dev->udev, |
Rajkumar Manoharan | 0f529e9 | 2010-09-16 19:56:55 +0530 | [diff] [blame] | 586 | usb_rcvbulkpipe(hif_dev->udev, |
| 587 | USB_REG_IN_PIPE), |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 588 | nskb->data, MAX_REG_IN_BUF_SIZE, |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 589 | ath9k_hif_usb_reg_in_cb, nskb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 590 | |
| 591 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
| 592 | if (ret) { |
Ming Lei | e6c6d33 | 2010-04-13 00:29:05 +0800 | [diff] [blame] | 593 | kfree_skb(nskb); |
Sujith | 5ab0af3 | 2010-04-23 10:28:17 +0530 | [diff] [blame] | 594 | urb->context = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 595 | } |
| 596 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 597 | return; |
| 598 | } |
| 599 | |
| 600 | resubmit: |
| 601 | skb_reset_tail_pointer(skb); |
| 602 | skb_trim(skb, 0); |
| 603 | |
| 604 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
| 605 | if (ret) |
| 606 | goto free; |
| 607 | |
| 608 | return; |
| 609 | free: |
Ming Lei | e6c6d33 | 2010-04-13 00:29:05 +0800 | [diff] [blame] | 610 | kfree_skb(skb); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 611 | urb->context = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev) |
| 615 | { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 616 | struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 617 | unsigned long flags; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 618 | |
Sujith | c11d8f8 | 2010-04-23 10:28:09 +0530 | [diff] [blame] | 619 | list_for_each_entry_safe(tx_buf, tx_buf_tmp, |
| 620 | &hif_dev->tx.tx_buf, list) { |
| 621 | usb_kill_urb(tx_buf->urb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 622 | list_del(&tx_buf->list); |
| 623 | usb_free_urb(tx_buf->urb); |
| 624 | kfree(tx_buf->buf); |
| 625 | kfree(tx_buf); |
| 626 | } |
| 627 | |
Sujith Manoharan | ff8f59b | 2010-12-28 14:28:05 +0530 | [diff] [blame] | 628 | spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); |
| 629 | hif_dev->tx.flags |= HIF_USB_TX_FLUSH; |
| 630 | spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); |
| 631 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 632 | list_for_each_entry_safe(tx_buf, tx_buf_tmp, |
| 633 | &hif_dev->tx.tx_pending, list) { |
| 634 | usb_kill_urb(tx_buf->urb); |
| 635 | list_del(&tx_buf->list); |
| 636 | usb_free_urb(tx_buf->urb); |
| 637 | kfree(tx_buf->buf); |
| 638 | kfree(tx_buf); |
| 639 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev) |
| 643 | { |
| 644 | struct tx_buf *tx_buf; |
| 645 | int i; |
| 646 | |
| 647 | INIT_LIST_HEAD(&hif_dev->tx.tx_buf); |
| 648 | INIT_LIST_HEAD(&hif_dev->tx.tx_pending); |
| 649 | spin_lock_init(&hif_dev->tx.tx_lock); |
| 650 | __skb_queue_head_init(&hif_dev->tx.tx_skb_queue); |
| 651 | |
| 652 | for (i = 0; i < MAX_TX_URB_NUM; i++) { |
| 653 | tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL); |
| 654 | if (!tx_buf) |
| 655 | goto err; |
| 656 | |
| 657 | tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL); |
| 658 | if (!tx_buf->buf) |
| 659 | goto err; |
| 660 | |
| 661 | tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL); |
| 662 | if (!tx_buf->urb) |
| 663 | goto err; |
| 664 | |
| 665 | tx_buf->hif_dev = hif_dev; |
| 666 | __skb_queue_head_init(&tx_buf->skb_queue); |
| 667 | |
| 668 | list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf); |
| 669 | } |
| 670 | |
| 671 | hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM; |
| 672 | |
| 673 | return 0; |
| 674 | err: |
Dan Carpenter | 7606688 | 2010-05-14 16:52:37 +0200 | [diff] [blame] | 675 | if (tx_buf) { |
| 676 | kfree(tx_buf->buf); |
| 677 | kfree(tx_buf); |
| 678 | } |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 679 | ath9k_hif_usb_dealloc_tx_urbs(hif_dev); |
| 680 | return -ENOMEM; |
| 681 | } |
| 682 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 683 | static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev) |
| 684 | { |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 685 | usb_kill_anchored_urbs(&hif_dev->rx_submitted); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev) |
| 689 | { |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 690 | struct urb *urb = NULL; |
| 691 | struct sk_buff *skb = NULL; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 692 | int i, ret; |
| 693 | |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 694 | init_usb_anchor(&hif_dev->rx_submitted); |
Sujith | 46baa1a | 2010-04-06 15:28:11 +0530 | [diff] [blame] | 695 | spin_lock_init(&hif_dev->rx_lock); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 696 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 697 | for (i = 0; i < MAX_RX_URB_NUM; i++) { |
| 698 | |
| 699 | /* Allocate URB */ |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 700 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 701 | if (urb == NULL) { |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 702 | ret = -ENOMEM; |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 703 | goto err_urb; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /* Allocate buffer */ |
Ming Lei | f28a7b3 | 2010-04-13 00:28:53 +0800 | [diff] [blame] | 707 | skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 708 | if (!skb) { |
| 709 | ret = -ENOMEM; |
| 710 | goto err_skb; |
| 711 | } |
| 712 | |
| 713 | usb_fill_bulk_urb(urb, hif_dev->udev, |
| 714 | usb_rcvbulkpipe(hif_dev->udev, |
| 715 | USB_WLAN_RX_PIPE), |
| 716 | skb->data, MAX_RX_BUF_SIZE, |
| 717 | ath9k_hif_usb_rx_cb, skb); |
| 718 | |
| 719 | /* Anchor URB */ |
| 720 | usb_anchor_urb(urb, &hif_dev->rx_submitted); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 721 | |
| 722 | /* Submit URB */ |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 723 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 724 | if (ret) { |
| 725 | usb_unanchor_urb(urb); |
| 726 | goto err_submit; |
| 727 | } |
Sujith | 66b10e3 | 2010-04-06 15:28:13 +0530 | [diff] [blame] | 728 | |
| 729 | /* |
| 730 | * Drop reference count. |
| 731 | * This ensures that the URB is freed when killing them. |
| 732 | */ |
| 733 | usb_free_urb(urb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | return 0; |
| 737 | |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 738 | err_submit: |
Ming Lei | f28a7b3 | 2010-04-13 00:28:53 +0800 | [diff] [blame] | 739 | kfree_skb(skb); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 740 | err_skb: |
| 741 | usb_free_urb(urb); |
| 742 | err_urb: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 743 | ath9k_hif_usb_dealloc_rx_urbs(hif_dev); |
| 744 | return ret; |
| 745 | } |
| 746 | |
| 747 | static void ath9k_hif_usb_dealloc_reg_in_urb(struct hif_device_usb *hif_dev) |
| 748 | { |
| 749 | if (hif_dev->reg_in_urb) { |
| 750 | usb_kill_urb(hif_dev->reg_in_urb); |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 751 | if (hif_dev->reg_in_urb->context) |
Ming Lei | e6c6d33 | 2010-04-13 00:29:05 +0800 | [diff] [blame] | 752 | kfree_skb((void *)hif_dev->reg_in_urb->context); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 753 | usb_free_urb(hif_dev->reg_in_urb); |
| 754 | hif_dev->reg_in_urb = NULL; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | static int ath9k_hif_usb_alloc_reg_in_urb(struct hif_device_usb *hif_dev) |
| 759 | { |
| 760 | struct sk_buff *skb; |
| 761 | |
| 762 | hif_dev->reg_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 763 | if (hif_dev->reg_in_urb == NULL) |
| 764 | return -ENOMEM; |
| 765 | |
Ming Lei | e6c6d33 | 2010-04-13 00:29:05 +0800 | [diff] [blame] | 766 | skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 767 | if (!skb) |
| 768 | goto err; |
| 769 | |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 770 | usb_fill_bulk_urb(hif_dev->reg_in_urb, hif_dev->udev, |
Rajkumar Manoharan | 0f529e9 | 2010-09-16 19:56:55 +0530 | [diff] [blame] | 771 | usb_rcvbulkpipe(hif_dev->udev, |
| 772 | USB_REG_IN_PIPE), |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 773 | skb->data, MAX_REG_IN_BUF_SIZE, |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 774 | ath9k_hif_usb_reg_in_cb, skb); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 775 | |
| 776 | if (usb_submit_urb(hif_dev->reg_in_urb, GFP_KERNEL) != 0) |
Sujith | 6335ed0 | 2010-03-29 16:07:15 +0530 | [diff] [blame] | 777 | goto err; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 778 | |
| 779 | return 0; |
| 780 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 781 | err: |
| 782 | ath9k_hif_usb_dealloc_reg_in_urb(hif_dev); |
| 783 | return -ENOMEM; |
| 784 | } |
| 785 | |
| 786 | static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev) |
| 787 | { |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 788 | /* Register Write */ |
| 789 | init_usb_anchor(&hif_dev->regout_submitted); |
| 790 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 791 | /* TX */ |
| 792 | if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0) |
| 793 | goto err; |
| 794 | |
| 795 | /* RX */ |
| 796 | if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0) |
Rajkumar Manoharan | f803696 | 2010-07-07 15:19:18 +0530 | [diff] [blame] | 797 | goto err_rx; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 798 | |
Sujith | 6f0f266 | 2010-04-06 15:28:17 +0530 | [diff] [blame] | 799 | /* Register Read */ |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 800 | if (ath9k_hif_usb_alloc_reg_in_urb(hif_dev) < 0) |
Rajkumar Manoharan | f803696 | 2010-07-07 15:19:18 +0530 | [diff] [blame] | 801 | goto err_reg; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 802 | |
| 803 | return 0; |
Rajkumar Manoharan | f803696 | 2010-07-07 15:19:18 +0530 | [diff] [blame] | 804 | err_reg: |
| 805 | ath9k_hif_usb_dealloc_rx_urbs(hif_dev); |
| 806 | err_rx: |
| 807 | ath9k_hif_usb_dealloc_tx_urbs(hif_dev); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 808 | err: |
| 809 | return -ENOMEM; |
| 810 | } |
| 811 | |
Sujith.Manoharan@atheros.com | 1d8af8c | 2010-05-11 16:24:40 +0530 | [diff] [blame] | 812 | static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev) |
| 813 | { |
| 814 | usb_kill_anchored_urbs(&hif_dev->regout_submitted); |
| 815 | ath9k_hif_usb_dealloc_reg_in_urb(hif_dev); |
| 816 | ath9k_hif_usb_dealloc_tx_urbs(hif_dev); |
| 817 | ath9k_hif_usb_dealloc_rx_urbs(hif_dev); |
| 818 | } |
| 819 | |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 820 | static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev, |
| 821 | u32 drv_info) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 822 | { |
| 823 | int transfer, err; |
| 824 | const void *data = hif_dev->firmware->data; |
| 825 | size_t len = hif_dev->firmware->size; |
| 826 | u32 addr = AR9271_FIRMWARE; |
| 827 | u8 *buf = kzalloc(4096, GFP_KERNEL); |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 828 | u32 firm_offset; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 829 | |
| 830 | if (!buf) |
| 831 | return -ENOMEM; |
| 832 | |
| 833 | while (len) { |
| 834 | transfer = min_t(int, len, 4096); |
| 835 | memcpy(buf, data, transfer); |
| 836 | |
| 837 | err = usb_control_msg(hif_dev->udev, |
| 838 | usb_sndctrlpipe(hif_dev->udev, 0), |
| 839 | FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT, |
| 840 | addr >> 8, 0, buf, transfer, HZ); |
| 841 | if (err < 0) { |
| 842 | kfree(buf); |
| 843 | return err; |
| 844 | } |
| 845 | |
| 846 | len -= transfer; |
| 847 | data += transfer; |
| 848 | addr += transfer; |
| 849 | } |
| 850 | kfree(buf); |
| 851 | |
Sujith Manoharan | 0b5ead9 | 2010-12-07 16:31:38 +0530 | [diff] [blame] | 852 | if (IS_AR7010_DEVICE(drv_info)) |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 853 | firm_offset = AR7010_FIRMWARE_TEXT; |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 854 | else |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 855 | firm_offset = AR9271_FIRMWARE_TEXT; |
| 856 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 857 | /* |
| 858 | * Issue FW download complete command to firmware. |
| 859 | */ |
| 860 | err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0), |
| 861 | FIRMWARE_DOWNLOAD_COMP, |
| 862 | 0x40 | USB_DIR_OUT, |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 863 | firm_offset >> 8, 0, NULL, 0, HZ); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 864 | if (err) |
| 865 | return -EIO; |
| 866 | |
| 867 | dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n", |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 868 | hif_dev->fw_name, (unsigned long) hif_dev->firmware->size); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 873 | static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev, u32 drv_info) |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 874 | { |
Rajkumar Manoharan | 4a0e8ec | 2010-09-14 14:35:55 +0530 | [diff] [blame] | 875 | int ret, idx; |
| 876 | struct usb_host_interface *alt = &hif_dev->interface->altsetting[0]; |
| 877 | struct usb_endpoint_descriptor *endp; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 878 | |
| 879 | /* Request firmware */ |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 880 | ret = request_firmware(&hif_dev->firmware, hif_dev->fw_name, |
| 881 | &hif_dev->udev->dev); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 882 | if (ret) { |
| 883 | dev_err(&hif_dev->udev->dev, |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 884 | "ath9k_htc: Firmware - %s not found\n", hif_dev->fw_name); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 885 | goto err_fw_req; |
| 886 | } |
| 887 | |
Sujith.Manoharan@atheros.com | 1d8af8c | 2010-05-11 16:24:40 +0530 | [diff] [blame] | 888 | /* Download firmware */ |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 889 | ret = ath9k_hif_usb_download_fw(hif_dev, drv_info); |
Sujith.Manoharan@atheros.com | 1d8af8c | 2010-05-11 16:24:40 +0530 | [diff] [blame] | 890 | if (ret) { |
| 891 | dev_err(&hif_dev->udev->dev, |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 892 | "ath9k_htc: Firmware - %s download failed\n", |
| 893 | hif_dev->fw_name); |
Sujith.Manoharan@atheros.com | 1d8af8c | 2010-05-11 16:24:40 +0530 | [diff] [blame] | 894 | goto err_fw_download; |
| 895 | } |
| 896 | |
Rajkumar Manoharan | 4a0e8ec | 2010-09-14 14:35:55 +0530 | [diff] [blame] | 897 | /* On downloading the firmware to the target, the USB descriptor of EP4 |
| 898 | * is 'patched' to change the type of the endpoint to Bulk. This will |
| 899 | * bring down CPU usage during the scan period. |
| 900 | */ |
| 901 | for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) { |
| 902 | endp = &alt->endpoint[idx].desc; |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 903 | if ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 904 | == USB_ENDPOINT_XFER_INT) { |
Rajkumar Manoharan | 4a0e8ec | 2010-09-14 14:35:55 +0530 | [diff] [blame] | 905 | endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK; |
| 906 | endp->bmAttributes |= USB_ENDPOINT_XFER_BULK; |
| 907 | endp->bInterval = 0; |
| 908 | } |
| 909 | } |
| 910 | |
Rajkumar Manoharan | 490b3f4 | 2010-11-08 12:49:12 +0530 | [diff] [blame] | 911 | /* Alloc URBs */ |
| 912 | ret = ath9k_hif_usb_alloc_urbs(hif_dev); |
| 913 | if (ret) { |
| 914 | dev_err(&hif_dev->udev->dev, |
| 915 | "ath9k_htc: Unable to allocate URBs\n"); |
| 916 | goto err_urb; |
| 917 | } |
| 918 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 919 | return 0; |
| 920 | |
Sujith.Manoharan@atheros.com | 1d8af8c | 2010-05-11 16:24:40 +0530 | [diff] [blame] | 921 | err_urb: |
Sujith Manoharan | caa0a99 | 2010-12-07 16:32:02 +0530 | [diff] [blame] | 922 | ath9k_hif_usb_dealloc_urbs(hif_dev); |
| 923 | err_fw_download: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 924 | release_firmware(hif_dev->firmware); |
| 925 | err_fw_req: |
| 926 | hif_dev->firmware = NULL; |
| 927 | return ret; |
| 928 | } |
| 929 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 930 | static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev) |
| 931 | { |
| 932 | ath9k_hif_usb_dealloc_urbs(hif_dev); |
| 933 | if (hif_dev->firmware) |
| 934 | release_firmware(hif_dev->firmware); |
| 935 | } |
| 936 | |
| 937 | static int ath9k_hif_usb_probe(struct usb_interface *interface, |
| 938 | const struct usb_device_id *id) |
| 939 | { |
| 940 | struct usb_device *udev = interface_to_usbdev(interface); |
| 941 | struct hif_device_usb *hif_dev; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 942 | int ret = 0; |
| 943 | |
| 944 | hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL); |
| 945 | if (!hif_dev) { |
| 946 | ret = -ENOMEM; |
| 947 | goto err_alloc; |
| 948 | } |
| 949 | |
| 950 | usb_get_dev(udev); |
| 951 | hif_dev->udev = udev; |
| 952 | hif_dev->interface = interface; |
| 953 | hif_dev->device_id = id->idProduct; |
| 954 | #ifdef CONFIG_PM |
| 955 | udev->reset_resume = 1; |
| 956 | #endif |
| 957 | usb_set_intfdata(interface, hif_dev); |
| 958 | |
Sujith.Manoharan@atheros.com | 47fce02 | 2010-05-11 16:24:41 +0530 | [diff] [blame] | 959 | hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb, |
| 960 | &hif_dev->udev->dev); |
| 961 | if (hif_dev->htc_handle == NULL) { |
| 962 | ret = -ENOMEM; |
| 963 | goto err_htc_hw_alloc; |
| 964 | } |
| 965 | |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 966 | /* Find out which firmware to load */ |
| 967 | |
Sujith Manoharan | 0b5ead9 | 2010-12-07 16:31:38 +0530 | [diff] [blame] | 968 | if (IS_AR7010_DEVICE(id->driver_info)) |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 969 | if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x0202) |
John W. Linville | d0ee0eb | 2010-06-23 14:20:45 -0400 | [diff] [blame] | 970 | hif_dev->fw_name = FIRMWARE_AR7010_1_1; |
Sujith | b176286 | 2010-06-02 15:53:34 +0530 | [diff] [blame] | 971 | else |
John W. Linville | d0ee0eb | 2010-06-23 14:20:45 -0400 | [diff] [blame] | 972 | hif_dev->fw_name = FIRMWARE_AR7010; |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 973 | else |
John W. Linville | d0ee0eb | 2010-06-23 14:20:45 -0400 | [diff] [blame] | 974 | hif_dev->fw_name = FIRMWARE_AR9271; |
Sujith | ce43cee | 2010-06-02 15:53:30 +0530 | [diff] [blame] | 975 | |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 976 | ret = ath9k_hif_usb_dev_init(hif_dev, id->driver_info); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 977 | if (ret) { |
| 978 | ret = -EINVAL; |
| 979 | goto err_hif_init_usb; |
| 980 | } |
| 981 | |
Sujith.Manoharan@atheros.com | 47fce02 | 2010-05-11 16:24:41 +0530 | [diff] [blame] | 982 | ret = ath9k_htc_hw_init(hif_dev->htc_handle, |
Vivek Natarajan | 21cb987 | 2010-08-18 19:57:49 +0530 | [diff] [blame] | 983 | &hif_dev->udev->dev, hif_dev->device_id, |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 984 | hif_dev->udev->product, id->driver_info); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 985 | if (ret) { |
| 986 | ret = -EINVAL; |
| 987 | goto err_htc_hw_init; |
| 988 | } |
| 989 | |
| 990 | dev_info(&hif_dev->udev->dev, "ath9k_htc: USB layer initialized\n"); |
| 991 | |
| 992 | return 0; |
| 993 | |
| 994 | err_htc_hw_init: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 995 | ath9k_hif_usb_dev_deinit(hif_dev); |
| 996 | err_hif_init_usb: |
Sujith.Manoharan@atheros.com | 47fce02 | 2010-05-11 16:24:41 +0530 | [diff] [blame] | 997 | ath9k_htc_hw_free(hif_dev->htc_handle); |
| 998 | err_htc_hw_alloc: |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 999 | usb_set_intfdata(interface, NULL); |
| 1000 | kfree(hif_dev); |
| 1001 | usb_put_dev(udev); |
| 1002 | err_alloc: |
| 1003 | return ret; |
| 1004 | } |
| 1005 | |
Sujith | 62e4716 | 2010-04-23 10:28:16 +0530 | [diff] [blame] | 1006 | static void ath9k_hif_usb_reboot(struct usb_device *udev) |
| 1007 | { |
| 1008 | u32 reboot_cmd = 0xffffffff; |
| 1009 | void *buf; |
| 1010 | int ret; |
| 1011 | |
Julia Lawall | a465a2c | 2010-05-15 23:17:19 +0200 | [diff] [blame] | 1012 | buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL); |
Sujith | 62e4716 | 2010-04-23 10:28:16 +0530 | [diff] [blame] | 1013 | if (!buf) |
| 1014 | return; |
| 1015 | |
Sujith | 62e4716 | 2010-04-23 10:28:16 +0530 | [diff] [blame] | 1016 | ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE), |
| 1017 | buf, 4, NULL, HZ); |
| 1018 | if (ret) |
| 1019 | dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n"); |
| 1020 | |
| 1021 | kfree(buf); |
| 1022 | } |
| 1023 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1024 | static void ath9k_hif_usb_disconnect(struct usb_interface *interface) |
| 1025 | { |
| 1026 | struct usb_device *udev = interface_to_usbdev(interface); |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 1027 | struct hif_device_usb *hif_dev = usb_get_intfdata(interface); |
Sujith Manoharan | 97dcec5 | 2010-12-20 08:02:42 +0530 | [diff] [blame] | 1028 | bool unplugged = (udev->state == USB_STATE_NOTATTACHED) ? true : false; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1029 | |
| 1030 | if (hif_dev) { |
Sujith Manoharan | 97dcec5 | 2010-12-20 08:02:42 +0530 | [diff] [blame] | 1031 | ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1032 | ath9k_htc_hw_free(hif_dev->htc_handle); |
| 1033 | ath9k_hif_usb_dev_deinit(hif_dev); |
| 1034 | usb_set_intfdata(interface, NULL); |
| 1035 | } |
| 1036 | |
Sujith Manoharan | 97dcec5 | 2010-12-20 08:02:42 +0530 | [diff] [blame] | 1037 | if (!unplugged && (hif_dev->flags & HIF_USB_START)) |
Sujith | 62e4716 | 2010-04-23 10:28:16 +0530 | [diff] [blame] | 1038 | ath9k_hif_usb_reboot(udev); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1039 | |
| 1040 | kfree(hif_dev); |
| 1041 | dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n"); |
| 1042 | usb_put_dev(udev); |
| 1043 | } |
| 1044 | |
| 1045 | #ifdef CONFIG_PM |
| 1046 | static int ath9k_hif_usb_suspend(struct usb_interface *interface, |
| 1047 | pm_message_t message) |
| 1048 | { |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 1049 | struct hif_device_usb *hif_dev = usb_get_intfdata(interface); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1050 | |
Sujith Manoharan | f933ebe | 2010-12-01 12:30:27 +0530 | [diff] [blame] | 1051 | /* |
| 1052 | * The device has to be set to FULLSLEEP mode in case no |
| 1053 | * interface is up. |
| 1054 | */ |
| 1055 | if (!(hif_dev->flags & HIF_USB_START)) |
| 1056 | ath9k_htc_suspend(hif_dev->htc_handle); |
| 1057 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1058 | ath9k_hif_usb_dealloc_urbs(hif_dev); |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int ath9k_hif_usb_resume(struct usb_interface *interface) |
| 1064 | { |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 1065 | struct hif_device_usb *hif_dev = usb_get_intfdata(interface); |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 1066 | struct htc_target *htc_handle = hif_dev->htc_handle; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1067 | int ret; |
| 1068 | |
| 1069 | ret = ath9k_hif_usb_alloc_urbs(hif_dev); |
| 1070 | if (ret) |
| 1071 | return ret; |
| 1072 | |
| 1073 | if (hif_dev->firmware) { |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 1074 | ret = ath9k_hif_usb_download_fw(hif_dev, |
Sujith Manoharan | 0b5ead9 | 2010-12-07 16:31:38 +0530 | [diff] [blame] | 1075 | htc_handle->drv_priv->ah->hw_version.usbdev); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1076 | if (ret) |
| 1077 | goto fail_resume; |
| 1078 | } else { |
| 1079 | ath9k_hif_usb_dealloc_urbs(hif_dev); |
| 1080 | return -EIO; |
| 1081 | } |
| 1082 | |
| 1083 | mdelay(100); |
| 1084 | |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 1085 | ret = ath9k_htc_resume(htc_handle); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1086 | |
| 1087 | if (ret) |
| 1088 | goto fail_resume; |
| 1089 | |
| 1090 | return 0; |
| 1091 | |
| 1092 | fail_resume: |
| 1093 | ath9k_hif_usb_dealloc_urbs(hif_dev); |
| 1094 | |
| 1095 | return ret; |
| 1096 | } |
| 1097 | #endif |
| 1098 | |
| 1099 | static struct usb_driver ath9k_hif_usb_driver = { |
| 1100 | .name = "ath9k_hif_usb", |
| 1101 | .probe = ath9k_hif_usb_probe, |
| 1102 | .disconnect = ath9k_hif_usb_disconnect, |
| 1103 | #ifdef CONFIG_PM |
| 1104 | .suspend = ath9k_hif_usb_suspend, |
| 1105 | .resume = ath9k_hif_usb_resume, |
| 1106 | .reset_resume = ath9k_hif_usb_resume, |
| 1107 | #endif |
| 1108 | .id_table = ath9k_hif_usb_ids, |
| 1109 | .soft_unbind = 1, |
| 1110 | }; |
| 1111 | |
| 1112 | int ath9k_hif_usb_init(void) |
| 1113 | { |
| 1114 | return usb_register(&ath9k_hif_usb_driver); |
| 1115 | } |
| 1116 | |
| 1117 | void ath9k_hif_usb_exit(void) |
| 1118 | { |
| 1119 | usb_deregister(&ath9k_hif_usb_driver); |
| 1120 | } |