| 1 |
/* |
| 2 |
* Copyright (c) 2007-2011 Atheros Communications Inc. |
| 3 |
* Copyright (c) 2011-2012 Qualcomm Atheros, Inc. |
| 4 |
* |
| 5 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
* purpose with or without fee is hereby granted, provided that the above |
| 7 |
* copyright notice and this permission notice appear in all copies. |
| 8 |
* |
| 9 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include <linux/module.h> |
| 19 |
#include <linux/usb.h> |
| 20 |
|
| 21 |
#include "debug.h" |
| 22 |
#include "core.h" |
| 23 |
|
| 24 |
/* constants */ |
| 25 |
#define TX_URB_COUNT 32 |
| 26 |
#define RX_URB_COUNT 32 |
| 27 |
#define ATH6KL_USB_RX_BUFFER_SIZE 4096 |
| 28 |
|
| 29 |
/* tx/rx pipes for usb */ |
| 30 |
enum ATH6KL_USB_PIPE_ID { |
| 31 |
ATH6KL_USB_PIPE_TX_CTRL = 0, |
| 32 |
ATH6KL_USB_PIPE_TX_DATA_LP, |
| 33 |
ATH6KL_USB_PIPE_TX_DATA_MP, |
| 34 |
ATH6KL_USB_PIPE_TX_DATA_HP, |
| 35 |
ATH6KL_USB_PIPE_RX_CTRL, |
| 36 |
ATH6KL_USB_PIPE_RX_DATA, |
| 37 |
ATH6KL_USB_PIPE_RX_DATA2, |
| 38 |
ATH6KL_USB_PIPE_RX_INT, |
| 39 |
ATH6KL_USB_PIPE_MAX |
| 40 |
}; |
| 41 |
|
| 42 |
#define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX |
| 43 |
|
| 44 |
struct ath6kl_usb_pipe { |
| 45 |
struct list_head urb_list_head; |
| 46 |
struct usb_anchor urb_submitted; |
| 47 |
u32 urb_alloc; |
| 48 |
u32 urb_cnt; |
| 49 |
u32 urb_cnt_thresh; |
| 50 |
unsigned int usb_pipe_handle; |
| 51 |
u32 flags; |
| 52 |
u8 ep_address; |
| 53 |
u8 logical_pipe_num; |
| 54 |
struct ath6kl_usb *ar_usb; |
| 55 |
u16 max_packet_size; |
| 56 |
struct work_struct io_complete_work; |
| 57 |
struct sk_buff_head io_comp_queue; |
| 58 |
struct usb_endpoint_descriptor *ep_desc; |
| 59 |
}; |
| 60 |
|
| 61 |
#define ATH6KL_USB_PIPE_FLAG_TX (1 << 0) |
| 62 |
|
| 63 |
/* usb device object */ |
| 64 |
struct ath6kl_usb { |
| 65 |
/* protects pipe->urb_list_head and pipe->urb_cnt */ |
| 66 |
spinlock_t cs_lock; |
| 67 |
|
| 68 |
struct usb_device *udev; |
| 69 |
struct usb_interface *interface; |
| 70 |
struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX]; |
| 71 |
u8 *diag_cmd_buffer; |
| 72 |
u8 *diag_resp_buffer; |
| 73 |
struct ath6kl *ar; |
| 74 |
struct workqueue_struct *wq; |
| 75 |
}; |
| 76 |
|
| 77 |
/* usb urb object */ |
| 78 |
struct ath6kl_urb_context { |
| 79 |
struct list_head link; |
| 80 |
struct ath6kl_usb_pipe *pipe; |
| 81 |
struct sk_buff *skb; |
| 82 |
struct ath6kl *ar; |
| 83 |
}; |
| 84 |
|
| 85 |
/* USB endpoint definitions */ |
| 86 |
#define ATH6KL_USB_EP_ADDR_APP_CTRL_IN 0x81 |
| 87 |
#define ATH6KL_USB_EP_ADDR_APP_DATA_IN 0x82 |
| 88 |
#define ATH6KL_USB_EP_ADDR_APP_DATA2_IN 0x83 |
| 89 |
#define ATH6KL_USB_EP_ADDR_APP_INT_IN 0x84 |
| 90 |
|
| 91 |
#define ATH6KL_USB_EP_ADDR_APP_CTRL_OUT 0x01 |
| 92 |
#define ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT 0x02 |
| 93 |
#define ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT 0x03 |
| 94 |
#define ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT 0x04 |
| 95 |
|
| 96 |
/* diagnostic command definitions */ |
| 97 |
#define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD 1 |
| 98 |
#define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP 2 |
| 99 |
#define ATH6KL_USB_CONTROL_REQ_DIAG_CMD 3 |
| 100 |
#define ATH6KL_USB_CONTROL_REQ_DIAG_RESP 4 |
| 101 |
|
| 102 |
#define ATH6KL_USB_CTRL_DIAG_CC_READ 0 |
| 103 |
#define ATH6KL_USB_CTRL_DIAG_CC_WRITE 1 |
| 104 |
|
| 105 |
struct ath6kl_usb_ctrl_diag_cmd_write { |
| 106 |
__le32 cmd; |
| 107 |
__le32 address; |
| 108 |
__le32 value; |
| 109 |
__le32 _pad[1]; |
| 110 |
} __packed; |
| 111 |
|
| 112 |
struct ath6kl_usb_ctrl_diag_cmd_read { |
| 113 |
__le32 cmd; |
| 114 |
__le32 address; |
| 115 |
} __packed; |
| 116 |
|
| 117 |
struct ath6kl_usb_ctrl_diag_resp_read { |
| 118 |
__le32 value; |
| 119 |
} __packed; |
| 120 |
|
| 121 |
/* function declarations */ |
| 122 |
static void ath6kl_usb_recv_complete(struct urb *urb); |
| 123 |
|
| 124 |
#define ATH6KL_USB_IS_BULK_EP(attr) (((attr) & 3) == 0x02) |
| 125 |
#define ATH6KL_USB_IS_INT_EP(attr) (((attr) & 3) == 0x03) |
| 126 |
#define ATH6KL_USB_IS_ISOC_EP(attr) (((attr) & 3) == 0x01) |
| 127 |
#define ATH6KL_USB_IS_DIR_IN(addr) ((addr) & 0x80) |
| 128 |
|
| 129 |
/* pipe/urb operations */ |
| 130 |
static struct ath6kl_urb_context * |
| 131 |
ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe) |
| 132 |
{ |
| 133 |
struct ath6kl_urb_context *urb_context = NULL; |
| 134 |
unsigned long flags; |
| 135 |
|
| 136 |
/* bail if this pipe is not initialized */ |
| 137 |
if (!pipe->ar_usb) |
| 138 |
return NULL; |
| 139 |
|
| 140 |
spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags); |
| 141 |
if (!list_empty(&pipe->urb_list_head)) { |
| 142 |
urb_context = |
| 143 |
list_first_entry(&pipe->urb_list_head, |
| 144 |
struct ath6kl_urb_context, link); |
| 145 |
list_del(&urb_context->link); |
| 146 |
pipe->urb_cnt--; |
| 147 |
} |
| 148 |
spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags); |
| 149 |
|
| 150 |
return urb_context; |
| 151 |
} |
| 152 |
|
| 153 |
static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe, |
| 154 |
struct ath6kl_urb_context *urb_context) |
| 155 |
{ |
| 156 |
unsigned long flags; |
| 157 |
|
| 158 |
/* bail if this pipe is not initialized */ |
| 159 |
if (!pipe->ar_usb) |
| 160 |
return; |
| 161 |
|
| 162 |
spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags); |
| 163 |
pipe->urb_cnt++; |
| 164 |
|
| 165 |
list_add(&urb_context->link, &pipe->urb_list_head); |
| 166 |
spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags); |
| 167 |
} |
| 168 |
|
| 169 |
static void ath6kl_usb_cleanup_recv_urb(struct ath6kl_urb_context *urb_context) |
| 170 |
{ |
| 171 |
dev_kfree_skb(urb_context->skb); |
| 172 |
urb_context->skb = NULL; |
| 173 |
|
| 174 |
ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context); |
| 175 |
} |
| 176 |
|
| 177 |
static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar) |
| 178 |
{ |
| 179 |
return ar->hif_priv; |
| 180 |
} |
| 181 |
|
| 182 |
/* pipe resource allocation/cleanup */ |
| 183 |
static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe, |
| 184 |
int urb_cnt) |
| 185 |
{ |
| 186 |
struct ath6kl_urb_context *urb_context; |
| 187 |
int status = 0, i; |
| 188 |
|
| 189 |
INIT_LIST_HEAD(&pipe->urb_list_head); |
| 190 |
init_usb_anchor(&pipe->urb_submitted); |
| 191 |
|
| 192 |
for (i = 0; i < urb_cnt; i++) { |
| 193 |
urb_context = kzalloc_obj(struct ath6kl_urb_context); |
| 194 |
if (urb_context == NULL) { |
| 195 |
status = -ENOMEM; |
| 196 |
goto fail_alloc_pipe_resources; |
| 197 |
} |
| 198 |
|
| 199 |
urb_context->pipe = pipe; |
| 200 |
|
| 201 |
/* |
| 202 |
* we are only allocate the urb contexts here, the actual URB |
| 203 |
* is allocated from the kernel as needed to do a transaction |
| 204 |
*/ |
| 205 |
pipe->urb_alloc++; |
| 206 |
ath6kl_usb_free_urb_to_pipe(pipe, urb_context); |
| 207 |
} |
| 208 |
|
| 209 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 210 |
"ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n", |
| 211 |
pipe->logical_pipe_num, pipe->usb_pipe_handle, |
| 212 |
pipe->urb_alloc); |
| 213 |
|
| 214 |
fail_alloc_pipe_resources: |
| 215 |
return status; |
| 216 |
} |
| 217 |
|
| 218 |
static void ath6kl_usb_free_pipe_resources(struct ath6kl_usb_pipe *pipe) |
| 219 |
{ |
| 220 |
struct ath6kl_urb_context *urb_context; |
| 221 |
|
| 222 |
if (pipe->ar_usb == NULL) { |
| 223 |
/* nothing allocated for this pipe */ |
| 224 |
return; |
| 225 |
} |
| 226 |
|
| 227 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 228 |
"ath6kl usb: free resources lpipe:%d" |
| 229 |
"hpipe:0x%X urbs:%d avail:%d\n", |
| 230 |
pipe->logical_pipe_num, pipe->usb_pipe_handle, |
| 231 |
pipe->urb_alloc, pipe->urb_cnt); |
| 232 |
|
| 233 |
if (pipe->urb_alloc != pipe->urb_cnt) { |
| 234 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 235 |
"ath6kl usb: urb leak! lpipe:%d" |
| 236 |
"hpipe:0x%X urbs:%d avail:%d\n", |
| 237 |
pipe->logical_pipe_num, pipe->usb_pipe_handle, |
| 238 |
pipe->urb_alloc, pipe->urb_cnt); |
| 239 |
} |
| 240 |
|
| 241 |
while (true) { |
| 242 |
urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe); |
| 243 |
if (urb_context == NULL) |
| 244 |
break; |
| 245 |
kfree(urb_context); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
static void ath6kl_usb_cleanup_pipe_resources(struct ath6kl_usb *ar_usb) |
| 250 |
{ |
| 251 |
int i; |
| 252 |
|
| 253 |
for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) |
| 254 |
ath6kl_usb_free_pipe_resources(&ar_usb->pipes[i]); |
| 255 |
} |
| 256 |
|
| 257 |
static u8 ath6kl_usb_get_logical_pipe_num(struct ath6kl_usb *ar_usb, |
| 258 |
u8 ep_address, int *urb_count) |
| 259 |
{ |
| 260 |
u8 pipe_num = ATH6KL_USB_PIPE_INVALID; |
| 261 |
|
| 262 |
switch (ep_address) { |
| 263 |
case ATH6KL_USB_EP_ADDR_APP_CTRL_IN: |
| 264 |
pipe_num = ATH6KL_USB_PIPE_RX_CTRL; |
| 265 |
*urb_count = RX_URB_COUNT; |
| 266 |
break; |
| 267 |
case ATH6KL_USB_EP_ADDR_APP_DATA_IN: |
| 268 |
pipe_num = ATH6KL_USB_PIPE_RX_DATA; |
| 269 |
*urb_count = RX_URB_COUNT; |
| 270 |
break; |
| 271 |
case ATH6KL_USB_EP_ADDR_APP_INT_IN: |
| 272 |
pipe_num = ATH6KL_USB_PIPE_RX_INT; |
| 273 |
*urb_count = RX_URB_COUNT; |
| 274 |
break; |
| 275 |
case ATH6KL_USB_EP_ADDR_APP_DATA2_IN: |
| 276 |
pipe_num = ATH6KL_USB_PIPE_RX_DATA2; |
| 277 |
*urb_count = RX_URB_COUNT; |
| 278 |
break; |
| 279 |
case ATH6KL_USB_EP_ADDR_APP_CTRL_OUT: |
| 280 |
pipe_num = ATH6KL_USB_PIPE_TX_CTRL; |
| 281 |
*urb_count = TX_URB_COUNT; |
| 282 |
break; |
| 283 |
case ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT: |
| 284 |
pipe_num = ATH6KL_USB_PIPE_TX_DATA_LP; |
| 285 |
*urb_count = TX_URB_COUNT; |
| 286 |
break; |
| 287 |
case ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT: |
| 288 |
pipe_num = ATH6KL_USB_PIPE_TX_DATA_MP; |
| 289 |
*urb_count = TX_URB_COUNT; |
| 290 |
break; |
| 291 |
case ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT: |
| 292 |
pipe_num = ATH6KL_USB_PIPE_TX_DATA_HP; |
| 293 |
*urb_count = TX_URB_COUNT; |
| 294 |
break; |
| 295 |
default: |
| 296 |
/* note: there may be endpoints not currently used */ |
| 297 |
break; |
| 298 |
} |
| 299 |
|
| 300 |
return pipe_num; |
| 301 |
} |
| 302 |
|
| 303 |
static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb) |
| 304 |
{ |
| 305 |
struct usb_interface *interface = ar_usb->interface; |
| 306 |
struct usb_host_interface *iface_desc = interface->cur_altsetting; |
| 307 |
struct usb_endpoint_descriptor *endpoint; |
| 308 |
struct ath6kl_usb_pipe *pipe; |
| 309 |
int i, urbcount, status = 0; |
| 310 |
u8 pipe_num; |
| 311 |
|
| 312 |
ath6kl_dbg(ATH6KL_DBG_USB, "setting up USB Pipes using interface\n"); |
| 313 |
|
| 314 |
/* walk descriptors and setup pipes */ |
| 315 |
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
| 316 |
endpoint = &iface_desc->endpoint[i].desc; |
| 317 |
|
| 318 |
if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) { |
| 319 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 320 |
"%s Bulk Ep:0x%2.2X maxpktsz:%d\n", |
| 321 |
ATH6KL_USB_IS_DIR_IN |
| 322 |
(endpoint->bEndpointAddress) ? |
| 323 |
"RX" : "TX", endpoint->bEndpointAddress, |
| 324 |
le16_to_cpu(endpoint->wMaxPacketSize)); |
| 325 |
} else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) { |
| 326 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 327 |
"%s Int Ep:0x%2.2X maxpktsz:%d interval:%d\n", |
| 328 |
ATH6KL_USB_IS_DIR_IN |
| 329 |
(endpoint->bEndpointAddress) ? |
| 330 |
"RX" : "TX", endpoint->bEndpointAddress, |
| 331 |
le16_to_cpu(endpoint->wMaxPacketSize), |
| 332 |
endpoint->bInterval); |
| 333 |
} else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) { |
| 334 |
/* TODO for ISO */ |
| 335 |
ath6kl_dbg(ATH6KL_DBG_USB, |
| 336 |
"%s ISOC Ep:0x%2.2X maxpktsz:%d interval:%d\n", |
| 337 |
ATH6KL_USB_IS_DIR_IN |
| 338 |
(endpoint->bEndpointAddress) ? |
| 339 |
"RX" : "TX", endpoint->bEndpointAddress, |
| 340 |
le16_to_cpu(endpoint->wMaxPacketSize), |
| 341 |
endpoint->bInterval); |
| 342 |
} |
| 343 |
|
| 344 |
/* Ignore broken descriptors. */ |
| 345 |
if (usb_endpoint_maxp(endpoint) == 0) |
| 346 |
continue; |
| 347 |
|
| 348 |
urbcount = 0; |
| 349 |
|
| 350 |
pipe_num = |
| 351 |
ath6kl_usb_get_logical_pipe_num(ar_usb, |
| 352 |
endpoint->bEndpointAddress, |
| 353 |
&urbcount); |
| 354 |
if (pipe_num == ATH6KL_USB_PIPE_INVALID) |
| 355 |
continue; |
| 356 |
|
| 357 |
pipe = &ar_usb->pipes[pipe_num]; |
| 358 |
if (pipe->ar_usb != NULL) { |
| 359 |
/* hmmm..pipe was already setup */ |
| 360 |
continue; |
| 361 |
} |
| 362 |
|
| 363 |
pipe->ar_usb = ar_usb; |
| 364 |
pipe->logical_pipe_num = pipe_num; |
| 365 |
pipe->ep_address = endpoint->bEndpointAddress; |
| 366 |
pipe->max_packet_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 367 |
|
| 368 |
if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) { |
| 369 |
if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) { |
| 370 |
pipe->usb_pipe_handle = |
| 371 |
usb_rcvbulkpipe(ar_usb->udev, |
| 372 |
pipe->ep_address); |
| 373 |
} else { |
| 374 |
pipe->usb_pipe_handle = |
| 375 |
usb_sndbulkpipe(ar_usb->udev, |
| 376 |
pipe->ep_address); |
| 377 |
} |
| 378 |
} else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) { |
| 379 |
if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) { |
| 380 |
pipe->usb_pipe_handle = |
| 381 |
usb_rcvintpipe(ar_usb->udev, |
| 382 |
pipe->ep_address); |
| 383 |
} else { |
| 384 |
pipe->usb_pipe_handle = |
| 385 |
usb_sndintpipe(ar_usb->udev, |
| 386 |
pipe->ep_address); |
| 387 |
} |
| 388 |
} else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) { |
| 389 |
/* TODO for ISO */ |
| 390 |
if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) { |
| 391 |
pipe->usb_pipe_handle = |
| 392 |
usb_rcvisocpipe(ar_usb->udev, |
| 393 |
pipe->ep_address); |
| 394 |
} else { |
| 395 |
pipe->usb_pipe_handle = |
| 396 |
usb_sndisocpipe(ar_usb->udev, |
| 397 |
pipe->ep_address); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
pipe->ep_desc = endpoint; |
| 402 |
|
| 403 |
if (!ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) |
| 404 |
pipe->flags |= ATH6KL_USB_PIPE_FLAG_TX; |
| 405 |
|
| 406 |
status = ath6kl_usb_alloc_pipe_resources(pipe, urbcount); |
| 407 |
if (status != 0) |
| 408 |
break; |
| 409 |
} |
| 410 |
|
| 411 |
return status; |
| 412 |
} |
| 413 |
|
| 414 |
/* pipe operations */ |
| 415 |
static void ath6kl_usb_post_recv_transfers(struct ath6kl_usb_pipe *recv_pipe, |
| 416 |
int buffer_length) |
| 417 |
{ |
| 418 |
struct ath6kl_urb_context *urb_context; |
| 419 |
struct urb *urb; |
| 420 |
int usb_status; |
| 421 |
|
| 422 |
while (true) { |
| 423 |
urb_context = ath6kl_usb_alloc_urb_from_pipe(recv_pipe); |
| 424 |
if (urb_context == NULL) |
| 425 |
break; |
| 426 |
|
| 427 |
urb_context->skb = dev_alloc_skb(buffer_length); |
| 428 |
if (urb_context->skb == NULL) |
| 429 |
goto err_cleanup_urb; |
| 430 |
|
| 431 |
urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 432 |
if (urb == NULL) |
| 433 |
goto err_cleanup_urb; |
| 434 |
|
| 435 |
usb_fill_bulk_urb(urb, |
| 436 |
recv_pipe->ar_usb->udev, |
| 437 |
recv_pipe->usb_pipe_handle, |
| 438 |
urb_context->skb->data, |
| 439 |
buffer_length, |
| 440 |
ath6kl_usb_recv_complete, urb_context); |
| 441 |
|
| 442 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 443 |
"ath6kl usb: bulk recv submit:%d, 0x%X (ep:0x%2.2X), %d bytes buf:0x%p\n", |
| 444 |
recv_pipe->logical_pipe_num, |
| 445 |
recv_pipe->usb_pipe_handle, recv_pipe->ep_address, |
| 446 |
buffer_length, urb_context->skb); |
| 447 |
|
| 448 |
usb_anchor_urb(urb, &recv_pipe->urb_submitted); |
| 449 |
usb_status = usb_submit_urb(urb, GFP_ATOMIC); |
| 450 |
|
| 451 |
if (usb_status) { |
| 452 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 453 |
"ath6kl usb : usb bulk recv failed %d\n", |
| 454 |
usb_status); |
| 455 |
usb_unanchor_urb(urb); |
| 456 |
usb_free_urb(urb); |
| 457 |
goto err_cleanup_urb; |
| 458 |
} |
| 459 |
usb_free_urb(urb); |
| 460 |
} |
| 461 |
return; |
| 462 |
|
| 463 |
err_cleanup_urb: |
| 464 |
ath6kl_usb_cleanup_recv_urb(urb_context); |
| 465 |
return; |
| 466 |
} |
| 467 |
|
| 468 |
static void ath6kl_usb_flush_all(struct ath6kl_usb *ar_usb) |
| 469 |
{ |
| 470 |
int i; |
| 471 |
|
| 472 |
for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) { |
| 473 |
if (ar_usb->pipes[i].ar_usb != NULL) |
| 474 |
usb_kill_anchored_urbs(&ar_usb->pipes[i].urb_submitted); |
| 475 |
} |
| 476 |
|
| 477 |
/* |
| 478 |
* Flushing any pending I/O may schedule work this call will block |
| 479 |
* until all scheduled work runs to completion. |
| 480 |
*/ |
| 481 |
flush_workqueue(ar_usb->wq); |
| 482 |
} |
| 483 |
|
| 484 |
static void ath6kl_usb_start_recv_pipes(struct ath6kl_usb *ar_usb) |
| 485 |
{ |
| 486 |
/* |
| 487 |
* note: control pipe is no longer used |
| 488 |
* ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_cnt_thresh = |
| 489 |
* ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_alloc/2; |
| 490 |
* ath6kl_usb_post_recv_transfers(&ar_usb-> |
| 491 |
* pipes[ATH6KL_USB_PIPE_RX_CTRL], |
| 492 |
* ATH6KL_USB_RX_BUFFER_SIZE); |
| 493 |
*/ |
| 494 |
|
| 495 |
ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_cnt_thresh = 1; |
| 496 |
|
| 497 |
ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA], |
| 498 |
ATH6KL_USB_RX_BUFFER_SIZE); |
| 499 |
} |
| 500 |
|
| 501 |
/* hif usb rx/tx completion functions */ |
| 502 |
static void ath6kl_usb_recv_complete(struct urb *urb) |
| 503 |
{ |
| 504 |
struct ath6kl_urb_context *urb_context = urb->context; |
| 505 |
struct ath6kl_usb_pipe *pipe = urb_context->pipe; |
| 506 |
struct sk_buff *skb = NULL; |
| 507 |
int status = 0; |
| 508 |
|
| 509 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 510 |
"%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__, |
| 511 |
pipe->logical_pipe_num, urb->status, urb->actual_length, |
| 512 |
urb); |
| 513 |
|
| 514 |
if (urb->status != 0) { |
| 515 |
status = -EIO; |
| 516 |
switch (urb->status) { |
| 517 |
case -ECONNRESET: |
| 518 |
case -ENOENT: |
| 519 |
case -ESHUTDOWN: |
| 520 |
/* |
| 521 |
* no need to spew these errors when device |
| 522 |
* removed or urb killed due to driver shutdown |
| 523 |
*/ |
| 524 |
status = -ECANCELED; |
| 525 |
break; |
| 526 |
default: |
| 527 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 528 |
"%s recv pipe: %d (ep:0x%2.2X), failed:%d\n", |
| 529 |
__func__, pipe->logical_pipe_num, |
| 530 |
pipe->ep_address, urb->status); |
| 531 |
break; |
| 532 |
} |
| 533 |
goto cleanup_recv_urb; |
| 534 |
} |
| 535 |
|
| 536 |
if (urb->actual_length == 0) |
| 537 |
goto cleanup_recv_urb; |
| 538 |
|
| 539 |
skb = urb_context->skb; |
| 540 |
|
| 541 |
/* we are going to pass it up */ |
| 542 |
urb_context->skb = NULL; |
| 543 |
skb_put(skb, urb->actual_length); |
| 544 |
|
| 545 |
/* note: queue implements a lock */ |
| 546 |
skb_queue_tail(&pipe->io_comp_queue, skb); |
| 547 |
queue_work(pipe->ar_usb->wq, &pipe->io_complete_work); |
| 548 |
|
| 549 |
cleanup_recv_urb: |
| 550 |
ath6kl_usb_cleanup_recv_urb(urb_context); |
| 551 |
|
| 552 |
if (status == 0 && |
| 553 |
pipe->urb_cnt >= pipe->urb_cnt_thresh) { |
| 554 |
/* our free urbs are piling up, post more transfers */ |
| 555 |
ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
static void ath6kl_usb_usb_transmit_complete(struct urb *urb) |
| 560 |
{ |
| 561 |
struct ath6kl_urb_context *urb_context = urb->context; |
| 562 |
struct ath6kl_usb_pipe *pipe = urb_context->pipe; |
| 563 |
struct sk_buff *skb; |
| 564 |
|
| 565 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 566 |
"%s: pipe: %d, stat:%d, len:%d\n", |
| 567 |
__func__, pipe->logical_pipe_num, urb->status, |
| 568 |
urb->actual_length); |
| 569 |
|
| 570 |
if (urb->status != 0) { |
| 571 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 572 |
"%s: pipe: %d, failed:%d\n", |
| 573 |
__func__, pipe->logical_pipe_num, urb->status); |
| 574 |
} |
| 575 |
|
| 576 |
skb = urb_context->skb; |
| 577 |
urb_context->skb = NULL; |
| 578 |
ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context); |
| 579 |
|
| 580 |
/* note: queue implements a lock */ |
| 581 |
skb_queue_tail(&pipe->io_comp_queue, skb); |
| 582 |
queue_work(pipe->ar_usb->wq, &pipe->io_complete_work); |
| 583 |
} |
| 584 |
|
| 585 |
static void ath6kl_usb_io_comp_work(struct work_struct *work) |
| 586 |
{ |
| 587 |
struct ath6kl_usb_pipe *pipe = container_of(work, |
| 588 |
struct ath6kl_usb_pipe, |
| 589 |
io_complete_work); |
| 590 |
struct ath6kl_usb *ar_usb; |
| 591 |
struct sk_buff *skb; |
| 592 |
|
| 593 |
ar_usb = pipe->ar_usb; |
| 594 |
|
| 595 |
while ((skb = skb_dequeue(&pipe->io_comp_queue))) { |
| 596 |
if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) { |
| 597 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 598 |
"ath6kl usb xmit callback buf:0x%p\n", skb); |
| 599 |
ath6kl_core_tx_complete(ar_usb->ar, skb); |
| 600 |
} else { |
| 601 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 602 |
"ath6kl usb recv callback buf:0x%p\n", skb); |
| 603 |
ath6kl_core_rx_complete(ar_usb->ar, skb, |
| 604 |
pipe->logical_pipe_num); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
#define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write)) |
| 610 |
#define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read)) |
| 611 |
|
| 612 |
static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb) |
| 613 |
{ |
| 614 |
ath6kl_usb_flush_all(ar_usb); |
| 615 |
|
| 616 |
ath6kl_usb_cleanup_pipe_resources(ar_usb); |
| 617 |
|
| 618 |
usb_set_intfdata(ar_usb->interface, NULL); |
| 619 |
|
| 620 |
kfree(ar_usb->diag_cmd_buffer); |
| 621 |
kfree(ar_usb->diag_resp_buffer); |
| 622 |
destroy_workqueue(ar_usb->wq); |
| 623 |
|
| 624 |
kfree(ar_usb); |
| 625 |
} |
| 626 |
|
| 627 |
static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface) |
| 628 |
{ |
| 629 |
struct usb_device *dev = interface_to_usbdev(interface); |
| 630 |
struct ath6kl_usb *ar_usb; |
| 631 |
struct ath6kl_usb_pipe *pipe; |
| 632 |
int status = 0; |
| 633 |
int i; |
| 634 |
|
| 635 |
/* ath6kl_usb_destroy() needs ar_usb != NULL && ar_usb->wq != NULL. */ |
| 636 |
ar_usb = kzalloc_obj(struct ath6kl_usb); |
| 637 |
if (ar_usb == NULL) |
| 638 |
return NULL; |
| 639 |
ar_usb->wq = alloc_workqueue("ath6kl_wq", 0, 0); |
| 640 |
if (!ar_usb->wq) { |
| 641 |
kfree(ar_usb); |
| 642 |
return NULL; |
| 643 |
} |
| 644 |
|
| 645 |
usb_set_intfdata(interface, ar_usb); |
| 646 |
spin_lock_init(&(ar_usb->cs_lock)); |
| 647 |
ar_usb->udev = dev; |
| 648 |
ar_usb->interface = interface; |
| 649 |
|
| 650 |
for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) { |
| 651 |
pipe = &ar_usb->pipes[i]; |
| 652 |
INIT_WORK(&pipe->io_complete_work, |
| 653 |
ath6kl_usb_io_comp_work); |
| 654 |
skb_queue_head_init(&pipe->io_comp_queue); |
| 655 |
} |
| 656 |
|
| 657 |
ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL); |
| 658 |
if (ar_usb->diag_cmd_buffer == NULL) { |
| 659 |
status = -ENOMEM; |
| 660 |
goto fail_ath6kl_usb_create; |
| 661 |
} |
| 662 |
|
| 663 |
ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP, |
| 664 |
GFP_KERNEL); |
| 665 |
if (ar_usb->diag_resp_buffer == NULL) { |
| 666 |
status = -ENOMEM; |
| 667 |
goto fail_ath6kl_usb_create; |
| 668 |
} |
| 669 |
|
| 670 |
status = ath6kl_usb_setup_pipe_resources(ar_usb); |
| 671 |
|
| 672 |
fail_ath6kl_usb_create: |
| 673 |
if (status != 0) { |
| 674 |
ath6kl_usb_destroy(ar_usb); |
| 675 |
ar_usb = NULL; |
| 676 |
} |
| 677 |
return ar_usb; |
| 678 |
} |
| 679 |
|
| 680 |
static void ath6kl_usb_device_detached(struct usb_interface *interface) |
| 681 |
{ |
| 682 |
struct ath6kl_usb *ar_usb; |
| 683 |
|
| 684 |
ar_usb = usb_get_intfdata(interface); |
| 685 |
if (ar_usb == NULL) |
| 686 |
return; |
| 687 |
|
| 688 |
ath6kl_stop_txrx(ar_usb->ar); |
| 689 |
|
| 690 |
/* Delay to wait for the target to reboot */ |
| 691 |
mdelay(20); |
| 692 |
ath6kl_core_cleanup(ar_usb->ar); |
| 693 |
ath6kl_usb_destroy(ar_usb); |
| 694 |
} |
| 695 |
|
| 696 |
/* exported hif usb APIs for htc pipe */ |
| 697 |
static void hif_start(struct ath6kl *ar) |
| 698 |
{ |
| 699 |
struct ath6kl_usb *device = ath6kl_usb_priv(ar); |
| 700 |
int i; |
| 701 |
|
| 702 |
ath6kl_usb_start_recv_pipes(device); |
| 703 |
|
| 704 |
/* set the TX resource avail threshold for each TX pipe */ |
| 705 |
for (i = ATH6KL_USB_PIPE_TX_CTRL; |
| 706 |
i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) { |
| 707 |
device->pipes[i].urb_cnt_thresh = |
| 708 |
device->pipes[i].urb_alloc / 2; |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID, |
| 713 |
struct sk_buff *hdr_skb, struct sk_buff *skb) |
| 714 |
{ |
| 715 |
struct ath6kl_usb *device = ath6kl_usb_priv(ar); |
| 716 |
struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID]; |
| 717 |
struct ath6kl_urb_context *urb_context; |
| 718 |
int usb_status, status = 0; |
| 719 |
struct urb *urb; |
| 720 |
u8 *data; |
| 721 |
u32 len; |
| 722 |
|
| 723 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n", |
| 724 |
__func__, PipeID, skb); |
| 725 |
|
| 726 |
urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe); |
| 727 |
|
| 728 |
if (urb_context == NULL) { |
| 729 |
/* |
| 730 |
* TODO: it is possible to run out of urbs if |
| 731 |
* 2 endpoints map to the same pipe ID |
| 732 |
*/ |
| 733 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 734 |
"%s pipe:%d no urbs left. URB Cnt : %d\n", |
| 735 |
__func__, PipeID, pipe->urb_cnt); |
| 736 |
status = -ENOMEM; |
| 737 |
goto fail_hif_send; |
| 738 |
} |
| 739 |
|
| 740 |
urb_context->skb = skb; |
| 741 |
|
| 742 |
data = skb->data; |
| 743 |
len = skb->len; |
| 744 |
|
| 745 |
urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 746 |
if (urb == NULL) { |
| 747 |
status = -ENOMEM; |
| 748 |
ath6kl_usb_free_urb_to_pipe(urb_context->pipe, |
| 749 |
urb_context); |
| 750 |
goto fail_hif_send; |
| 751 |
} |
| 752 |
|
| 753 |
usb_fill_bulk_urb(urb, |
| 754 |
device->udev, |
| 755 |
pipe->usb_pipe_handle, |
| 756 |
data, |
| 757 |
len, |
| 758 |
ath6kl_usb_usb_transmit_complete, urb_context); |
| 759 |
|
| 760 |
if ((len % pipe->max_packet_size) == 0) { |
| 761 |
/* hit a max packet boundary on this pipe */ |
| 762 |
urb->transfer_flags |= URB_ZERO_PACKET; |
| 763 |
} |
| 764 |
|
| 765 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 766 |
"athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n", |
| 767 |
pipe->logical_pipe_num, pipe->usb_pipe_handle, |
| 768 |
pipe->ep_address, len); |
| 769 |
|
| 770 |
usb_anchor_urb(urb, &pipe->urb_submitted); |
| 771 |
usb_status = usb_submit_urb(urb, GFP_ATOMIC); |
| 772 |
|
| 773 |
if (usb_status) { |
| 774 |
ath6kl_dbg(ATH6KL_DBG_USB_BULK, |
| 775 |
"ath6kl usb : usb bulk transmit failed %d\n", |
| 776 |
usb_status); |
| 777 |
usb_unanchor_urb(urb); |
| 778 |
ath6kl_usb_free_urb_to_pipe(urb_context->pipe, |
| 779 |
urb_context); |
| 780 |
status = -EINVAL; |
| 781 |
} |
| 782 |
usb_free_urb(urb); |
| 783 |
|
| 784 |
fail_hif_send: |
| 785 |
return status; |
| 786 |
} |
| 787 |
|
| 788 |
static void hif_stop(struct ath6kl *ar) |
| 789 |
{ |
| 790 |
struct ath6kl_usb *device = ath6kl_usb_priv(ar); |
| 791 |
|
| 792 |
ath6kl_usb_flush_all(device); |
| 793 |
} |
| 794 |
|
| 795 |
static void ath6kl_usb_get_default_pipe(struct ath6kl *ar, |
| 796 |
u8 *ul_pipe, u8 *dl_pipe) |
| 797 |
{ |
| 798 |
*ul_pipe = ATH6KL_USB_PIPE_TX_CTRL; |
| 799 |
*dl_pipe = ATH6KL_USB_PIPE_RX_CTRL; |
| 800 |
} |
| 801 |
|
| 802 |
static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id, |
| 803 |
u8 *ul_pipe, u8 *dl_pipe) |
| 804 |
{ |
| 805 |
int status = 0; |
| 806 |
|
| 807 |
switch (svc_id) { |
| 808 |
case HTC_CTRL_RSVD_SVC: |
| 809 |
case WMI_CONTROL_SVC: |
| 810 |
*ul_pipe = ATH6KL_USB_PIPE_TX_CTRL; |
| 811 |
/* due to large control packets, shift to data pipe */ |
| 812 |
*dl_pipe = ATH6KL_USB_PIPE_RX_DATA; |
| 813 |
break; |
| 814 |
case WMI_DATA_BE_SVC: |
| 815 |
case WMI_DATA_BK_SVC: |
| 816 |
*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP; |
| 817 |
/* |
| 818 |
* Disable rxdata2 directly, it will be enabled |
| 819 |
* if FW enable rxdata2 |
| 820 |
*/ |
| 821 |
*dl_pipe = ATH6KL_USB_PIPE_RX_DATA; |
| 822 |
break; |
| 823 |
case WMI_DATA_VI_SVC: |
| 824 |
|
| 825 |
if (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT, |
| 826 |
ar->fw_capabilities)) |
| 827 |
*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP; |
| 828 |
else |
| 829 |
*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP; |
| 830 |
/* |
| 831 |
* Disable rxdata2 directly, it will be enabled |
| 832 |
* if FW enable rxdata2 |
| 833 |
*/ |
| 834 |
*dl_pipe = ATH6KL_USB_PIPE_RX_DATA; |
| 835 |
break; |
| 836 |
case WMI_DATA_VO_SVC: |
| 837 |
|
| 838 |
if (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT, |
| 839 |
ar->fw_capabilities)) |
| 840 |
*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP; |
| 841 |
else |
| 842 |
*ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP; |
| 843 |
/* |
| 844 |
* Disable rxdata2 directly, it will be enabled |
| 845 |
* if FW enable rxdata2 |
| 846 |
*/ |
| 847 |
*dl_pipe = ATH6KL_USB_PIPE_RX_DATA; |
| 848 |
break; |
| 849 |
default: |
| 850 |
status = -EPERM; |
| 851 |
break; |
| 852 |
} |
| 853 |
|
| 854 |
return status; |
| 855 |
} |
| 856 |
|
| 857 |
static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id) |
| 858 |
{ |
| 859 |
struct ath6kl_usb *device = ath6kl_usb_priv(ar); |
| 860 |
|
| 861 |
return device->pipes[pipe_id].urb_cnt; |
| 862 |
} |
| 863 |
|
| 864 |
static void hif_detach_htc(struct ath6kl *ar) |
| 865 |
{ |
| 866 |
struct ath6kl_usb *device = ath6kl_usb_priv(ar); |
| 867 |
|
| 868 |
ath6kl_usb_flush_all(device); |
| 869 |
} |
| 870 |
|
| 871 |
static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb, |
| 872 |
u8 req, u16 value, u16 index, void *data, |
| 873 |
u32 size) |
| 874 |
{ |
| 875 |
u8 *buf = NULL; |
| 876 |
int ret; |
| 877 |
|
| 878 |
if (size > 0) { |
| 879 |
buf = kmemdup(data, size, GFP_KERNEL); |
| 880 |
if (buf == NULL) |
| 881 |
return -ENOMEM; |
| 882 |
} |
| 883 |
|
| 884 |
/* note: if successful returns number of bytes transferred */ |
| 885 |
ret = usb_control_msg(ar_usb->udev, |
| 886 |
usb_sndctrlpipe(ar_usb->udev, 0), |
| 887 |
req, |
| 888 |
USB_DIR_OUT | USB_TYPE_VENDOR | |
| 889 |
USB_RECIP_DEVICE, value, index, buf, |
| 890 |
size, 1000); |
| 891 |
|
| 892 |
if (ret < 0) { |
| 893 |
ath6kl_warn("Failed to submit usb control message: %d\n", ret); |
| 894 |
kfree(buf); |
| 895 |
return ret; |
| 896 |
} |
| 897 |
|
| 898 |
kfree(buf); |
| 899 |
|
| 900 |
return 0; |
| 901 |
} |
| 902 |
|
| 903 |
static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb, |
| 904 |
u8 req, u16 value, u16 index, void *data, |
| 905 |
u32 size) |
| 906 |
{ |
| 907 |
u8 *buf = NULL; |
| 908 |
int ret; |
| 909 |
|
| 910 |
if (size > 0) { |
| 911 |
buf = kmalloc(size, GFP_KERNEL); |
| 912 |
if (buf == NULL) |
| 913 |
return -ENOMEM; |
| 914 |
} |
| 915 |
|
| 916 |
/* note: if successful returns number of bytes transferred */ |
| 917 |
ret = usb_control_msg(ar_usb->udev, |
| 918 |
usb_rcvctrlpipe(ar_usb->udev, 0), |
| 919 |
req, |
| 920 |
USB_DIR_IN | USB_TYPE_VENDOR | |
| 921 |
USB_RECIP_DEVICE, value, index, buf, |
| 922 |
size, 2000); |
| 923 |
|
| 924 |
if (ret < 0) { |
| 925 |
ath6kl_warn("Failed to read usb control message: %d\n", ret); |
| 926 |
kfree(buf); |
| 927 |
return ret; |
| 928 |
} |
| 929 |
|
| 930 |
memcpy((u8 *) data, buf, size); |
| 931 |
|
| 932 |
kfree(buf); |
| 933 |
|
| 934 |
return 0; |
| 935 |
} |
| 936 |
|
| 937 |
static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb, |
| 938 |
u8 req_val, u8 *req_buf, u32 req_len, |
| 939 |
u8 resp_val, u8 *resp_buf, u32 *resp_len) |
| 940 |
{ |
| 941 |
int ret; |
| 942 |
|
| 943 |
/* send command */ |
| 944 |
ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0, |
| 945 |
req_buf, req_len); |
| 946 |
|
| 947 |
if (ret != 0) |
| 948 |
return ret; |
| 949 |
|
| 950 |
if (resp_buf == NULL) { |
| 951 |
/* no expected response */ |
| 952 |
return ret; |
| 953 |
} |
| 954 |
|
| 955 |
/* get response */ |
| 956 |
ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0, |
| 957 |
resp_buf, *resp_len); |
| 958 |
|
| 959 |
return ret; |
| 960 |
} |
| 961 |
|
| 962 |
static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data) |
| 963 |
{ |
| 964 |
struct ath6kl_usb *ar_usb = ar->hif_priv; |
| 965 |
struct ath6kl_usb_ctrl_diag_resp_read *resp; |
| 966 |
struct ath6kl_usb_ctrl_diag_cmd_read *cmd; |
| 967 |
u32 resp_len; |
| 968 |
int ret; |
| 969 |
|
| 970 |
cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer; |
| 971 |
|
| 972 |
memset(cmd, 0, sizeof(*cmd)); |
| 973 |
cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ; |
| 974 |
cmd->address = cpu_to_le32(address); |
| 975 |
resp_len = sizeof(*resp); |
| 976 |
|
| 977 |
ret = ath6kl_usb_ctrl_msg_exchange(ar_usb, |
| 978 |
ATH6KL_USB_CONTROL_REQ_DIAG_CMD, |
| 979 |
(u8 *) cmd, |
| 980 |
sizeof(struct ath6kl_usb_ctrl_diag_cmd_write), |
| 981 |
ATH6KL_USB_CONTROL_REQ_DIAG_RESP, |
| 982 |
ar_usb->diag_resp_buffer, &resp_len); |
| 983 |
|
| 984 |
if (ret) { |
| 985 |
ath6kl_warn("diag read32 failed: %d\n", ret); |
| 986 |
return ret; |
| 987 |
} |
| 988 |
|
| 989 |
resp = (struct ath6kl_usb_ctrl_diag_resp_read *) |
| 990 |
ar_usb->diag_resp_buffer; |
| 991 |
|
| 992 |
*data = le32_to_cpu(resp->value); |
| 993 |
|
| 994 |
return ret; |
| 995 |
} |
| 996 |
|
| 997 |
static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data) |
| 998 |
{ |
| 999 |
struct ath6kl_usb *ar_usb = ar->hif_priv; |
| 1000 |
struct ath6kl_usb_ctrl_diag_cmd_write *cmd; |
| 1001 |
int ret; |
| 1002 |
|
| 1003 |
cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer; |
| 1004 |
|
| 1005 |
memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write)); |
| 1006 |
cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE); |
| 1007 |
cmd->address = cpu_to_le32(address); |
| 1008 |
cmd->value = data; |
| 1009 |
|
| 1010 |
ret = ath6kl_usb_ctrl_msg_exchange(ar_usb, |
| 1011 |
ATH6KL_USB_CONTROL_REQ_DIAG_CMD, |
| 1012 |
(u8 *) cmd, |
| 1013 |
sizeof(*cmd), |
| 1014 |
0, NULL, NULL); |
| 1015 |
if (ret) { |
| 1016 |
ath6kl_warn("diag_write32 failed: %d\n", ret); |
| 1017 |
return ret; |
| 1018 |
} |
| 1019 |
|
| 1020 |
return 0; |
| 1021 |
} |
| 1022 |
|
| 1023 |
static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len) |
| 1024 |
{ |
| 1025 |
struct ath6kl_usb *ar_usb = ar->hif_priv; |
| 1026 |
int ret; |
| 1027 |
|
| 1028 |
/* get response */ |
| 1029 |
ret = ath6kl_usb_submit_ctrl_in(ar_usb, |
| 1030 |
ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP, |
| 1031 |
0, 0, buf, len); |
| 1032 |
if (ret) { |
| 1033 |
ath6kl_err("Unable to read the bmi data from the device: %d\n", |
| 1034 |
ret); |
| 1035 |
return ret; |
| 1036 |
} |
| 1037 |
|
| 1038 |
return 0; |
| 1039 |
} |
| 1040 |
|
| 1041 |
static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len) |
| 1042 |
{ |
| 1043 |
struct ath6kl_usb *ar_usb = ar->hif_priv; |
| 1044 |
int ret; |
| 1045 |
|
| 1046 |
/* send command */ |
| 1047 |
ret = ath6kl_usb_submit_ctrl_out(ar_usb, |
| 1048 |
ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD, |
| 1049 |
0, 0, buf, len); |
| 1050 |
if (ret) { |
| 1051 |
ath6kl_err("unable to send the bmi data to the device: %d\n", |
| 1052 |
ret); |
| 1053 |
return ret; |
| 1054 |
} |
| 1055 |
|
| 1056 |
return 0; |
| 1057 |
} |
| 1058 |
|
| 1059 |
static int ath6kl_usb_power_on(struct ath6kl *ar) |
| 1060 |
{ |
| 1061 |
hif_start(ar); |
| 1062 |
return 0; |
| 1063 |
} |
| 1064 |
|
| 1065 |
static int ath6kl_usb_power_off(struct ath6kl *ar) |
| 1066 |
{ |
| 1067 |
hif_detach_htc(ar); |
| 1068 |
return 0; |
| 1069 |
} |
| 1070 |
|
| 1071 |
static void ath6kl_usb_stop(struct ath6kl *ar) |
| 1072 |
{ |
| 1073 |
hif_stop(ar); |
| 1074 |
} |
| 1075 |
|
| 1076 |
static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar) |
| 1077 |
{ |
| 1078 |
/* |
| 1079 |
* USB doesn't support it. Just return. |
| 1080 |
*/ |
| 1081 |
return; |
| 1082 |
} |
| 1083 |
|
| 1084 |
static int ath6kl_usb_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow) |
| 1085 |
{ |
| 1086 |
/* |
| 1087 |
* cfg80211 suspend/WOW currently not supported for USB. |
| 1088 |
*/ |
| 1089 |
return 0; |
| 1090 |
} |
| 1091 |
|
| 1092 |
static int ath6kl_usb_resume(struct ath6kl *ar) |
| 1093 |
{ |
| 1094 |
/* |
| 1095 |
* cfg80211 resume currently not supported for USB. |
| 1096 |
*/ |
| 1097 |
return 0; |
| 1098 |
} |
| 1099 |
|
| 1100 |
static const struct ath6kl_hif_ops ath6kl_usb_ops = { |
| 1101 |
.diag_read32 = ath6kl_usb_diag_read32, |
| 1102 |
.diag_write32 = ath6kl_usb_diag_write32, |
| 1103 |
.bmi_read = ath6kl_usb_bmi_read, |
| 1104 |
.bmi_write = ath6kl_usb_bmi_write, |
| 1105 |
.power_on = ath6kl_usb_power_on, |
| 1106 |
.power_off = ath6kl_usb_power_off, |
| 1107 |
.stop = ath6kl_usb_stop, |
| 1108 |
.pipe_send = ath6kl_usb_send, |
| 1109 |
.pipe_get_default = ath6kl_usb_get_default_pipe, |
| 1110 |
.pipe_map_service = ath6kl_usb_map_service_pipe, |
| 1111 |
.pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number, |
| 1112 |
.cleanup_scatter = ath6kl_usb_cleanup_scatter, |
| 1113 |
.suspend = ath6kl_usb_suspend, |
| 1114 |
.resume = ath6kl_usb_resume, |
| 1115 |
}; |
| 1116 |
|
| 1117 |
/* ath6kl usb driver registered functions */ |
| 1118 |
static int ath6kl_usb_probe(struct usb_interface *interface, |
| 1119 |
const struct usb_device_id *id) |
| 1120 |
{ |
| 1121 |
struct usb_device *dev = interface_to_usbdev(interface); |
| 1122 |
struct ath6kl *ar; |
| 1123 |
struct ath6kl_usb *ar_usb = NULL; |
| 1124 |
int vendor_id, product_id; |
| 1125 |
int ret = 0; |
| 1126 |
|
| 1127 |
usb_get_dev(dev); |
| 1128 |
|
| 1129 |
vendor_id = le16_to_cpu(dev->descriptor.idVendor); |
| 1130 |
product_id = le16_to_cpu(dev->descriptor.idProduct); |
| 1131 |
|
| 1132 |
ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id); |
| 1133 |
ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id); |
| 1134 |
|
| 1135 |
if (interface->cur_altsetting) |
| 1136 |
ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n", |
| 1137 |
interface->cur_altsetting->desc.bInterfaceNumber); |
| 1138 |
|
| 1139 |
|
| 1140 |
if (dev->speed == USB_SPEED_HIGH) |
| 1141 |
ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n"); |
| 1142 |
else |
| 1143 |
ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n"); |
| 1144 |
|
| 1145 |
ar_usb = ath6kl_usb_create(interface); |
| 1146 |
|
| 1147 |
if (ar_usb == NULL) { |
| 1148 |
ret = -ENOMEM; |
| 1149 |
goto err_usb_put; |
| 1150 |
} |
| 1151 |
|
| 1152 |
ar = ath6kl_core_create(&ar_usb->udev->dev); |
| 1153 |
if (ar == NULL) { |
| 1154 |
ath6kl_err("Failed to alloc ath6kl core\n"); |
| 1155 |
ret = -ENOMEM; |
| 1156 |
goto err_usb_destroy; |
| 1157 |
} |
| 1158 |
|
| 1159 |
ar->hif_priv = ar_usb; |
| 1160 |
ar->hif_type = ATH6KL_HIF_TYPE_USB; |
| 1161 |
ar->hif_ops = &ath6kl_usb_ops; |
| 1162 |
ar->mbox_info.block_size = 16; |
| 1163 |
ar->bmi.max_data_size = 252; |
| 1164 |
|
| 1165 |
ar_usb->ar = ar; |
| 1166 |
|
| 1167 |
ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE); |
| 1168 |
if (ret) { |
| 1169 |
ath6kl_err("Failed to init ath6kl core: %d\n", ret); |
| 1170 |
goto err_core_free; |
| 1171 |
} |
| 1172 |
|
| 1173 |
return ret; |
| 1174 |
|
| 1175 |
err_core_free: |
| 1176 |
ath6kl_core_destroy(ar); |
| 1177 |
err_usb_destroy: |
| 1178 |
ath6kl_usb_destroy(ar_usb); |
| 1179 |
err_usb_put: |
| 1180 |
usb_put_dev(dev); |
| 1181 |
|
| 1182 |
return ret; |
| 1183 |
} |
| 1184 |
|
| 1185 |
static void ath6kl_usb_remove(struct usb_interface *interface) |
| 1186 |
{ |
| 1187 |
usb_put_dev(interface_to_usbdev(interface)); |
| 1188 |
ath6kl_usb_device_detached(interface); |
| 1189 |
} |
| 1190 |
|
| 1191 |
#ifdef CONFIG_PM |
| 1192 |
|
| 1193 |
static int ath6kl_usb_pm_suspend(struct usb_interface *interface, |
| 1194 |
pm_message_t message) |
| 1195 |
{ |
| 1196 |
struct ath6kl_usb *device; |
| 1197 |
device = usb_get_intfdata(interface); |
| 1198 |
|
| 1199 |
ath6kl_usb_flush_all(device); |
| 1200 |
return 0; |
| 1201 |
} |
| 1202 |
|
| 1203 |
static int ath6kl_usb_pm_resume(struct usb_interface *interface) |
| 1204 |
{ |
| 1205 |
struct ath6kl_usb *device; |
| 1206 |
device = usb_get_intfdata(interface); |
| 1207 |
|
| 1208 |
ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA], |
| 1209 |
ATH6KL_USB_RX_BUFFER_SIZE); |
| 1210 |
ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2], |
| 1211 |
ATH6KL_USB_RX_BUFFER_SIZE); |
| 1212 |
|
| 1213 |
return 0; |
| 1214 |
} |
| 1215 |
|
| 1216 |
#else |
| 1217 |
|
| 1218 |
#define ath6kl_usb_pm_suspend NULL |
| 1219 |
#define ath6kl_usb_pm_resume NULL |
| 1220 |
|
| 1221 |
#endif |
| 1222 |
|
| 1223 |
/* table of devices that work with this driver */ |
| 1224 |
static const struct usb_device_id ath6kl_usb_ids[] = { |
| 1225 |
{USB_DEVICE(0x0cf3, 0x9375)}, |
| 1226 |
{USB_DEVICE(0x0cf3, 0x9374)}, |
| 1227 |
{USB_DEVICE(0x04da, 0x390d)}, |
| 1228 |
{ /* Terminating entry */ }, |
| 1229 |
}; |
| 1230 |
|
| 1231 |
MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids); |
| 1232 |
|
| 1233 |
static struct usb_driver ath6kl_usb_driver = { |
| 1234 |
.name = "ath6kl_usb", |
| 1235 |
.probe = ath6kl_usb_probe, |
| 1236 |
.suspend = ath6kl_usb_pm_suspend, |
| 1237 |
.resume = ath6kl_usb_pm_resume, |
| 1238 |
.disconnect = ath6kl_usb_remove, |
| 1239 |
.id_table = ath6kl_usb_ids, |
| 1240 |
.supports_autosuspend = true, |
| 1241 |
.disable_hub_initiated_lpm = 1, |
| 1242 |
}; |
| 1243 |
|
| 1244 |
module_usb_driver(ath6kl_usb_driver); |
| 1245 |
|
| 1246 |
MODULE_AUTHOR("Atheros Communications, Inc."); |
| 1247 |
MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices"); |
| 1248 |
MODULE_LICENSE("Dual BSD/GPL"); |
| 1249 |
MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE); |
| 1250 |
MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE); |
| 1251 |
MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE); |
| 1252 |
MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE); |
| 1253 |
MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE); |
| 1254 |
MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE); |
| 1255 |
MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE); |
| 1256 |
MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE); |
| 1257 |
MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE); |
| 1258 |
MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE); |
| 1259 |
MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE); |
| 1260 |
MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE); |