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