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