1 /* 2 * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <qdf_time.h> 20 #include <qdf_lock.h> 21 #include <qdf_mem.h> 22 #include <qdf_util.h> 23 #include <qdf_defer.h> 24 #include <qdf_atomic.h> 25 #include <qdf_nbuf.h> 26 #include "qdf_net_types.h" 27 #include <hif_usb_internal.h> 28 #include <htc_services.h> 29 #include <hif_debug.h> 30 #define ATH_MODULE_NAME hif 31 #include <a_debug.h> 32 #include "qdf_module.h" 33 #include "hif_usb_internal.h" 34 #include "if_usb.h" 35 #include "usb_api.h" 36 #include "target_type.h" 37 38 #if defined(WLAN_DEBUG) || defined(DEBUG) 39 static ATH_DEBUG_MASK_DESCRIPTION g_hif_debug_description[] = { 40 {USB_HIF_DEBUG_CTRL_TRANS, "Control Transfers"}, 41 {USB_HIF_DEBUG_BULK_IN, "BULK In Transfers"}, 42 {USB_HIF_DEBUG_BULK_OUT, "BULK Out Transfers"}, 43 {USB_HIF_DEBUG_DUMP_DATA, "Dump data"}, 44 {USB_HIF_DEBUG_ENUM, "Enumeration"}, 45 }; 46 47 ATH_DEBUG_INSTANTIATE_MODULE_VAR(hif, 48 "hif", 49 "USB Host Interface", 50 ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_INFO | 51 USB_HIF_DEBUG_ENUM, 52 ATH_DEBUG_DESCRIPTION_COUNT 53 (g_hif_debug_description), 54 g_hif_debug_description); 55 56 #endif 57 58 #ifdef USB_ISOC_SUPPORT 59 unsigned int hif_usb_isoch_vo = 1; 60 #else 61 unsigned int hif_usb_isoch_vo; 62 #endif 63 unsigned int hif_usb_disable_rxdata2 = 1; 64 65 /** 66 * usb_hif_usb_transmit_complete() - completion routing for tx urb's 67 * @urb: pointer to urb for which tx completion is called 68 * 69 * Return: none 70 */ 71 static void usb_hif_usb_transmit_complete(struct urb *urb) 72 { 73 struct HIF_URB_CONTEXT *urb_context = 74 (struct HIF_URB_CONTEXT *)urb->context; 75 qdf_nbuf_t buf; 76 struct HIF_USB_PIPE *pipe = urb_context->pipe; 77 struct hif_usb_send_context *send_context; 78 79 HIF_DBG("+%s: pipe: %d, stat:%d, len:%d", __func__, 80 pipe->logical_pipe_num, urb->status, urb->actual_length); 81 82 /* this urb is not pending anymore */ 83 usb_hif_remove_pending_transfer(urb_context); 84 85 if (urb->status != 0) { 86 HIF_ERROR("%s: pipe: %d, failed:%d", 87 __func__, pipe->logical_pipe_num, urb->status); 88 } 89 90 buf = urb_context->buf; 91 send_context = urb_context->send_context; 92 93 if (send_context->new_alloc) 94 qdf_mem_free(send_context); 95 else 96 qdf_nbuf_pull_head(buf, send_context->head_data_len); 97 98 urb_context->buf = NULL; 99 usb_hif_cleanup_transmit_urb(urb_context); 100 101 /* note: queue implements a lock */ 102 skb_queue_tail(&pipe->io_comp_queue, buf); 103 HIF_USB_SCHEDULE_WORK(pipe); 104 105 HIF_DBG("-%s", __func__); 106 } 107 108 /** 109 * hif_send_internal() - HIF internal routine to prepare and submit tx urbs 110 * @hif_usb_device: pointer to HIF_DEVICE_USB structure 111 * @pipe_id: HIF pipe on which data is to be sent 112 * @hdr_buf: any header buf to be prepended, currently ignored 113 * @buf: qdf_nbuf_t containing data to be transmitted 114 * @nbytes: number of bytes to be transmitted 115 * 116 * Return: QDF_STATUS_SUCCESS on success and error QDF status on failure 117 */ 118 static QDF_STATUS hif_send_internal(struct HIF_DEVICE_USB *hif_usb_device, 119 uint8_t pipe_id, 120 qdf_nbuf_t hdr_buf, 121 qdf_nbuf_t buf, unsigned int nbytes) 122 { 123 QDF_STATUS status = QDF_STATUS_SUCCESS; 124 struct HIF_DEVICE_USB *device = hif_usb_device; 125 struct HIF_USB_PIPE *pipe = &device->pipes[pipe_id]; 126 struct HIF_URB_CONTEXT *urb_context; 127 uint8_t *data; 128 uint32_t len; 129 struct urb *urb; 130 int usb_status; 131 int i; 132 struct hif_usb_send_context *send_context; 133 uint8_t frag_count; 134 uint32_t head_data_len, tmp_frag_count = 0; 135 unsigned char *data_ptr; 136 137 HIF_DBG("+%s pipe : %d, buf:0x%pK nbytes %u", 138 __func__, pipe_id, buf, nbytes); 139 140 frag_count = qdf_nbuf_get_num_frags(buf); 141 if (frag_count == 1) { 142 /* 143 * | hif_usb_send_context | netbuf->data 144 */ 145 head_data_len = sizeof(struct hif_usb_send_context); 146 } else if ((frag_count - 1) <= QDF_NBUF_CB_TX_MAX_EXTRA_FRAGS) { 147 /* 148 * means have extra fragment buf in skb 149 * header data length should be total sending length subtract 150 * internal data length of netbuf 151 * | hif_usb_send_context | fragments except internal buffer | 152 * netbuf->data 153 */ 154 head_data_len = sizeof(struct hif_usb_send_context); 155 while (tmp_frag_count < (frag_count - 1)) { 156 head_data_len = 157 head_data_len + qdf_nbuf_get_frag_len(buf, 158 tmp_frag_count); 159 tmp_frag_count = tmp_frag_count + 1; 160 } 161 } else { 162 /* Extra fragments overflow */ 163 HIF_ERROR("%s Extra fragments count overflow : %d\n", 164 __func__, frag_count); 165 status = QDF_STATUS_E_RESOURCES; 166 goto err; 167 } 168 169 /* Check whether head room is enough to save extra head data */ 170 if (head_data_len <= qdf_nbuf_headroom(buf)) { 171 send_context = (struct hif_usb_send_context *) 172 qdf_nbuf_push_head(buf, head_data_len); 173 send_context->new_alloc = false; 174 } else { 175 send_context = 176 qdf_mem_malloc(sizeof(struct hif_usb_send_context) 177 + head_data_len + nbytes); 178 if (!send_context) { 179 status = QDF_STATUS_E_NOMEM; 180 goto err; 181 } 182 send_context->new_alloc = true; 183 } 184 send_context->netbuf = buf; 185 send_context->hif_usb_device = hif_usb_device; 186 send_context->transfer_id = pipe_id; 187 send_context->head_data_len = head_data_len; 188 /* 189 * Copy data to head part of netbuf or head of allocated buffer. 190 * if buffer is new allocated, the last buffer should be copied also. 191 * It assume last fragment is internal buffer of netbuf 192 * sometime total length of fragments larger than nbytes 193 */ 194 data_ptr = (unsigned char *)send_context + 195 sizeof(struct hif_usb_send_context); 196 for (i = 0; 197 i < (send_context->new_alloc ? frag_count : frag_count - 1); i++) { 198 int frag_len = qdf_nbuf_get_frag_len(buf, i); 199 unsigned char *frag_addr = qdf_nbuf_get_frag_vaddr(buf, i); 200 201 qdf_mem_copy(data_ptr, frag_addr, frag_len); 202 data_ptr += frag_len; 203 } 204 /* Reset pData pointer and send out */ 205 data_ptr = (unsigned char *)send_context + 206 sizeof(struct hif_usb_send_context); 207 208 urb_context = usb_hif_alloc_urb_from_pipe(pipe); 209 if (NULL == urb_context) { 210 /* TODO : note, it is possible to run out of urbs if 2 211 * endpoints map to the same pipe ID 212 */ 213 HIF_ERROR("%s pipe:%d no urbs left. URB Cnt : %d", 214 __func__, pipe_id, pipe->urb_cnt); 215 status = QDF_STATUS_E_RESOURCES; 216 goto err; 217 } 218 urb_context->send_context = send_context; 219 urb = urb_context->urb; 220 urb_context->buf = buf; 221 data = data_ptr; 222 len = nbytes; 223 224 usb_fill_bulk_urb(urb, 225 device->udev, 226 pipe->usb_pipe_handle, 227 data, 228 (len % pipe->max_packet_size) == 229 0 ? (len + 1) : len, 230 usb_hif_usb_transmit_complete, urb_context); 231 232 if ((len % pipe->max_packet_size) == 0) 233 /* hit a max packet boundary on this pipe */ 234 235 HIF_DBG 236 ("athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes", 237 pipe->logical_pipe_num, pipe->usb_pipe_handle, 238 pipe->ep_address, nbytes); 239 240 usb_hif_enqueue_pending_transfer(pipe, urb_context); 241 usb_status = usb_submit_urb(urb, GFP_ATOMIC); 242 if (usb_status) { 243 if (send_context->new_alloc) 244 qdf_mem_free(send_context); 245 else 246 qdf_nbuf_pull_head(buf, head_data_len); 247 urb_context->buf = NULL; 248 HIF_ERROR("athusb : usb bulk transmit failed %d", 249 usb_status); 250 usb_hif_remove_pending_transfer(urb_context); 251 usb_hif_cleanup_transmit_urb(urb_context); 252 status = QDF_STATUS_E_FAILURE; 253 goto err; 254 } 255 256 err: 257 if (!QDF_IS_STATUS_SUCCESS(status) && 258 (status != QDF_STATUS_E_RESOURCES)) { 259 HIF_ERROR("athusb send failed %d", status); 260 } 261 262 HIF_DBG("-%s pipe : %d", __func__, pipe_id); 263 264 return status; 265 } 266 267 /** 268 * hif_send_head() - HIF routine exposed to upper layers to send data 269 * @scn: pointer to hif_opaque_softc structure 270 * @pipe_id: HIF pipe on which data is to be sent 271 * @transfer_id: endpoint ID on which data is to be sent 272 * @nbytes: number of bytes to be transmitted 273 * @wbuf: qdf_nbuf_t containing data to be transmitted 274 * @hdr_buf: any header buf to be prepended, currently ignored 275 * @data_attr: data_attr field from cvg_nbuf_cb of wbuf 276 * 277 * Return: QDF_STATUS_SUCCESS on success and error QDF status on failure 278 */ 279 QDF_STATUS hif_send_head(struct hif_opaque_softc *scn, uint8_t pipe_id, 280 uint32_t transfer_id, uint32_t nbytes, 281 qdf_nbuf_t wbuf, uint32_t data_attr) 282 { 283 QDF_STATUS status = QDF_STATUS_SUCCESS; 284 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 285 286 status = hif_send_internal(device, pipe_id, NULL, wbuf, nbytes); 287 return status; 288 } 289 290 /** 291 * hif_get_free_queue_number() - get # of free TX resources in a given HIF pipe 292 * @scn: pointer to hif_opaque_softc structure 293 * @pipe_id: HIF pipe which is being polled for free resources 294 * 295 * Return: # of free resources in pipe_id 296 */ 297 uint16_t hif_get_free_queue_number(struct hif_opaque_softc *scn, 298 uint8_t pipe_id) 299 { 300 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 301 302 return device->pipes[pipe_id].urb_cnt; 303 } 304 305 /** 306 * hif_post_init() - copy HTC callbacks to HIF 307 * @scn: pointer to hif_opaque_softc structure 308 * @target: pointer to HTC_TARGET structure 309 * @callbacks: htc callbacks 310 * 311 * Return: none 312 */ 313 void hif_post_init(struct hif_opaque_softc *scn, void *target, 314 struct hif_msg_callbacks *callbacks) 315 { 316 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 317 318 qdf_mem_copy(&device->htc_callbacks, callbacks, 319 sizeof(device->htc_callbacks)); 320 } 321 322 /** 323 * hif_detach_htc() - remove HTC callbacks from HIF 324 * @scn: pointer to hif_opaque_softc structure 325 * 326 * Return: none 327 */ 328 void hif_detach_htc(struct hif_opaque_softc *scn) 329 { 330 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 331 332 usb_hif_flush_all(device); 333 qdf_mem_zero(&device->htc_callbacks, sizeof(device->htc_callbacks)); 334 } 335 336 /** 337 * hif_usb_device_deinit() - de- init HIF_DEVICE_USB, cleanup pipe resources 338 * @sc: pointer to hif_usb_softc structure 339 * 340 * Return: None 341 */ 342 void hif_usb_device_deinit(struct hif_usb_softc *sc) 343 { 344 struct HIF_DEVICE_USB *device = &sc->hif_hdl; 345 346 HIF_TRACE("+%s", __func__); 347 348 usb_hif_cleanup_pipe_resources(device); 349 350 usb_set_intfdata(device->interface, NULL); 351 352 if (device->diag_cmd_buffer != NULL) 353 qdf_mem_free(device->diag_cmd_buffer); 354 355 if (device->diag_resp_buffer != NULL) 356 qdf_mem_free(device->diag_resp_buffer); 357 358 HIF_TRACE("-%s", __func__); 359 } 360 361 /** 362 * hif_usb_device_init() - init HIF_DEVICE_USB, setup pipe resources 363 * @sc: pointer to hif_usb_softc structure 364 * 365 * Return: QDF_STATUS_SUCCESS on success or a QDF error 366 */ 367 QDF_STATUS hif_usb_device_init(struct hif_usb_softc *sc) 368 { 369 int i; 370 struct HIF_DEVICE_USB *device = &sc->hif_hdl; 371 struct usb_interface *interface = sc->interface; 372 struct usb_device *dev = interface_to_usbdev(interface); 373 QDF_STATUS status = QDF_STATUS_SUCCESS; 374 struct HIF_USB_PIPE *pipe; 375 376 HIF_TRACE("+%s", __func__); 377 378 do { 379 380 usb_set_intfdata(interface, device); 381 qdf_spinlock_create(&(device->cs_lock)); 382 qdf_spinlock_create(&(device->rx_lock)); 383 qdf_spinlock_create(&(device->tx_lock)); 384 device->udev = dev; 385 device->interface = interface; 386 387 HIF_ERROR("%s device %pK device->udev %pK device->interface %pK", 388 __func__, 389 device, 390 device->udev, 391 device->interface); 392 393 for (i = 0; i < HIF_USB_PIPE_MAX; i++) { 394 pipe = &device->pipes[i]; 395 396 HIF_USB_INIT_WORK(pipe); 397 skb_queue_head_init(&pipe->io_comp_queue); 398 } 399 400 device->diag_cmd_buffer = 401 qdf_mem_malloc(USB_CTRL_MAX_DIAG_CMD_SIZE); 402 if (NULL == device->diag_cmd_buffer) { 403 status = QDF_STATUS_E_NOMEM; 404 break; 405 } 406 device->diag_resp_buffer = 407 qdf_mem_malloc(USB_CTRL_MAX_DIAG_RESP_SIZE); 408 if (NULL == device->diag_resp_buffer) { 409 status = QDF_STATUS_E_NOMEM; 410 break; 411 } 412 413 status = usb_hif_setup_pipe_resources(device); 414 415 } while (false); 416 417 if (hif_is_supported_rx_ctrl_pipe(HIF_GET_SOFTC(sc))) 418 device->rx_ctrl_pipe_supported = 1; 419 420 if (status != QDF_STATUS_SUCCESS) 421 HIF_ERROR("%s: abnormal condition", __func__); 422 423 HIF_TRACE("+%s", __func__); 424 return status; 425 } 426 427 /** 428 * hif_start() - Enable HIF TX and RX 429 * @scn: pointer to hif_opaque_softc structure 430 * 431 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 432 */ 433 QDF_STATUS hif_start(struct hif_opaque_softc *scn) 434 { 435 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 436 int i; 437 438 HIF_TRACE("+%s", __func__); 439 usb_hif_prestart_recv_pipes(device); 440 441 /* set the TX resource avail threshold for each TX pipe */ 442 for (i = HIF_TX_CTRL_PIPE; i <= HIF_TX_DATA_HP_PIPE; i++) { 443 device->pipes[i].urb_cnt_thresh = 444 device->pipes[i].urb_alloc / 2; 445 } 446 447 HIF_TRACE("-%s", __func__); 448 return QDF_STATUS_SUCCESS; 449 } 450 451 /** 452 * hif_usb_stop_device() - Stop/flush all HIF communication 453 * @scn: pointer to hif_opaque_softc structure 454 * 455 * Return: none 456 */ 457 void hif_usb_stop_device(struct hif_softc *hif_sc) 458 { 459 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(hif_sc); 460 461 HIF_TRACE("+%s", __func__); 462 463 usb_hif_flush_all(device); 464 465 HIF_TRACE("-%s", __func__); 466 } 467 468 /** 469 * hif_get_default_pipe() - get default pipes for HIF TX/RX 470 * @scn: pointer to hif_opaque_softc structure 471 * @ul_pipe: pointer to TX pipe 472 * @ul_pipe: pointer to TX pipe 473 * 474 * Return: none 475 */ 476 void hif_get_default_pipe(struct hif_opaque_softc *scn, uint8_t *ul_pipe, 477 uint8_t *dl_pipe) 478 { 479 *ul_pipe = HIF_TX_CTRL_PIPE; 480 *dl_pipe = HIF_RX_CTRL_PIPE; 481 } 482 483 #if defined(USB_MULTI_IN_TEST) || defined(USB_ISOC_TEST) 484 /** 485 * hif_map_service_to_pipe() - maps ul/dl pipe to service id. 486 * @scn: HIF context 487 * @svc_id: sevice index 488 * @ul_pipe: pointer to uplink pipe id 489 * @dl_pipe: pointer to down-linklink pipe id 490 * @ul_is_polled: if ul is polling based 491 * @ul_is_polled: if dl is polling based 492 * 493 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 494 */ 495 int hif_map_service_to_pipe(struct hif_opaque_softc *scn, uint16_t svc_id, 496 uint8_t *ul_pipe, uint8_t *dl_pipe, 497 int *ul_is_polled, int *dl_is_polled) 498 { 499 QDF_STATUS status = QDF_STATUS_SUCCESS; 500 501 switch (svc_id) { 502 case HTC_CTRL_RSVD_SVC: 503 case WMI_CONTROL_SVC: 504 case HTC_RAW_STREAMS_SVC: 505 *ul_pipe = HIF_TX_CTRL_PIPE; 506 *dl_pipe = HIF_RX_DATA_PIPE; 507 break; 508 case WMI_DATA_BE_SVC: 509 *ul_pipe = HIF_TX_DATA_LP_PIPE; 510 *dl_pipe = HIF_RX_DATA_PIPE; 511 break; 512 case WMI_DATA_BK_SVC: 513 *ul_pipe = HIF_TX_DATA_MP_PIPE; 514 *dl_pipe = HIF_RX_DATA2_PIPE; 515 break; 516 case WMI_DATA_VI_SVC: 517 *ul_pipe = HIF_TX_DATA_HP_PIPE; 518 *dl_pipe = HIF_RX_DATA_PIPE; 519 break; 520 case WMI_DATA_VO_SVC: 521 *ul_pipe = HIF_TX_DATA_LP_PIPE; 522 *dl_pipe = HIF_RX_DATA_PIPE; 523 break; 524 default: 525 status = QDF_STATUS_E_FAILURE; 526 break; 527 } 528 529 return status; 530 } 531 #else 532 533 #ifdef QCA_TX_HTT2_SUPPORT 534 #define USB_TX_CHECK_HTT2_SUPPORT 1 535 #else 536 #define USB_TX_CHECK_HTT2_SUPPORT 0 537 #endif 538 539 /** 540 * hif_map_service_to_pipe() - maps ul/dl pipe to service id. 541 * @scn: HIF context 542 * @svc_id: sevice index 543 * @ul_pipe: pointer to uplink pipe id 544 * @dl_pipe: pointer to down-linklink pipe id 545 * @ul_is_polled: if ul is polling based 546 * @ul_is_polled: if dl is polling based 547 * 548 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 549 */ 550 int hif_map_service_to_pipe(struct hif_opaque_softc *scn, uint16_t svc_id, 551 uint8_t *ul_pipe, uint8_t *dl_pipe, 552 int *ul_is_polled, int *dl_is_polled) 553 { 554 QDF_STATUS status = QDF_STATUS_SUCCESS; 555 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 556 557 switch (svc_id) { 558 case HTC_CTRL_RSVD_SVC: 559 case WMI_CONTROL_SVC: 560 *ul_pipe = HIF_TX_CTRL_PIPE; 561 if (device->rx_ctrl_pipe_supported) 562 *dl_pipe = HIF_RX_CTRL_PIPE; 563 else 564 *dl_pipe = HIF_RX_DATA_PIPE; 565 break; 566 case WMI_DATA_BE_SVC: 567 case WMI_DATA_BK_SVC: 568 *ul_pipe = HIF_TX_DATA_LP_PIPE; 569 if (hif_usb_disable_rxdata2) 570 *dl_pipe = HIF_RX_DATA_PIPE; 571 else 572 *dl_pipe = HIF_RX_DATA2_PIPE; 573 break; 574 case WMI_DATA_VI_SVC: 575 *ul_pipe = HIF_TX_DATA_MP_PIPE; 576 if (hif_usb_disable_rxdata2) 577 *dl_pipe = HIF_RX_DATA_PIPE; 578 else 579 *dl_pipe = HIF_RX_DATA2_PIPE; 580 break; 581 case WMI_DATA_VO_SVC: 582 *ul_pipe = HIF_TX_DATA_HP_PIPE; 583 if (hif_usb_disable_rxdata2) 584 *dl_pipe = HIF_RX_DATA_PIPE; 585 else 586 *dl_pipe = HIF_RX_DATA2_PIPE; 587 break; 588 case HTC_RAW_STREAMS_SVC: 589 *ul_pipe = HIF_TX_CTRL_PIPE; 590 *dl_pipe = HIF_RX_DATA_PIPE; 591 break; 592 case HTT_DATA_MSG_SVC: 593 *ul_pipe = HIF_TX_DATA_LP_PIPE; 594 if (hif_usb_disable_rxdata2) 595 *dl_pipe = HIF_RX_DATA_PIPE; 596 else 597 *dl_pipe = HIF_RX_DATA2_PIPE; 598 break; 599 case HTT_DATA2_MSG_SVC: 600 if (USB_TX_CHECK_HTT2_SUPPORT) { 601 *ul_pipe = HIF_TX_DATA_HP_PIPE; 602 if (hif_usb_disable_rxdata2) 603 *dl_pipe = HIF_RX_DATA_PIPE; 604 else 605 *dl_pipe = HIF_RX_DATA2_PIPE; 606 } 607 break; 608 default: 609 status = QDF_STATUS_E_FAILURE; 610 break; 611 } 612 613 return status; 614 } 615 #endif 616 617 /** 618 * hif_ctrl_msg_exchange() - send usb ctrl message and receive response 619 * @macp: pointer to HIF_DEVICE_USB 620 * @send_req_val: USB send message request value 621 * @send_msg: pointer to data to send 622 * @len: length in bytes of the data to send 623 * @response_req_val: USB response message request value 624 * @response_msg: pointer to response msg 625 * @response_len: length of the response message 626 * 627 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 628 */ 629 static QDF_STATUS hif_ctrl_msg_exchange(struct HIF_DEVICE_USB *macp, 630 uint8_t send_req_val, 631 uint8_t *send_msg, 632 uint32_t len, 633 uint8_t response_req_val, 634 uint8_t *response_msg, 635 uint32_t *response_len) 636 { 637 QDF_STATUS status; 638 639 do { 640 641 /* send command */ 642 status = usb_hif_submit_ctrl_out(macp, send_req_val, 0, 0, 643 send_msg, len); 644 645 if (!QDF_IS_STATUS_SUCCESS(status)) 646 break; 647 648 if (NULL == response_msg) { 649 /* no expected response */ 650 break; 651 } 652 653 /* get response */ 654 status = usb_hif_submit_ctrl_in(macp, response_req_val, 0, 0, 655 response_msg, *response_len); 656 657 if (!QDF_IS_STATUS_SUCCESS(status)) 658 break; 659 660 } while (false); 661 662 return status; 663 } 664 665 #ifdef WLAN_FEATURE_BMI 666 /** 667 * hif_exchange_bmi_msg() - send/recev ctrl message of type BMI_CMD/BMI_RESP 668 * @scn: pointer to hif_opaque_softc 669 * @bmi_request: pointer to data to send 670 * @request_length: length in bytes of the data to send 671 * @bmi_response: pointer to response msg 672 * @bmi_response_length: length of the response message 673 * @timeout_ms: timeout to wait for response (ignored in current implementation) 674 * 675 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 676 */ 677 678 QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *scn, 679 qdf_dma_addr_t cmd, qdf_dma_addr_t rsp, 680 uint8_t *bmi_request, 681 uint32_t request_length, 682 uint8_t *bmi_response, 683 uint32_t *bmi_response_lengthp, 684 uint32_t timeout_ms) 685 { 686 struct HIF_DEVICE_USB *macp = HIF_GET_USB_DEVICE(scn); 687 688 return hif_ctrl_msg_exchange(macp, 689 USB_CONTROL_REQ_SEND_BMI_CMD, 690 bmi_request, 691 request_length, 692 USB_CONTROL_REQ_RECV_BMI_RESP, 693 bmi_response, bmi_response_lengthp); 694 } 695 696 void hif_register_bmi_callbacks(struct hif_opaque_softc *hif_ctx) 697 { 698 } 699 #endif /* WLAN_FEATURE_BMI */ 700 701 /** 702 * hif_diag_read_access() - Read data from target memory or register 703 * @scn: pointer to hif_opaque_softc 704 * @address: register address to read from 705 * @data: pointer to buffer to store the value read from the register 706 * 707 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 708 */ 709 QDF_STATUS hif_diag_read_access(struct hif_opaque_softc *scn, uint32_t address, 710 uint32_t *data) 711 { 712 struct HIF_DEVICE_USB *macp = HIF_GET_USB_DEVICE(scn); 713 QDF_STATUS status; 714 USB_CTRL_DIAG_CMD_READ *cmd; 715 uint32_t respLength; 716 717 cmd = (USB_CTRL_DIAG_CMD_READ *) macp->diag_cmd_buffer; 718 719 qdf_mem_zero(cmd, sizeof(*cmd)); 720 cmd->Cmd = USB_CTRL_DIAG_CC_READ; 721 cmd->Address = address; 722 respLength = sizeof(USB_CTRL_DIAG_RESP_READ); 723 724 status = hif_ctrl_msg_exchange(macp, 725 USB_CONTROL_REQ_DIAG_CMD, 726 (uint8_t *) cmd, 727 sizeof(*cmd), 728 USB_CONTROL_REQ_DIAG_RESP, 729 macp->diag_resp_buffer, &respLength); 730 731 if (QDF_IS_STATUS_SUCCESS(status)) { 732 USB_CTRL_DIAG_RESP_READ *pResp = 733 (USB_CTRL_DIAG_RESP_READ *) macp->diag_resp_buffer; 734 *data = pResp->ReadValue; 735 status = QDF_STATUS_SUCCESS; 736 } else { 737 status = QDF_STATUS_E_FAILURE; 738 } 739 740 return status; 741 } 742 743 /** 744 * hif_diag_write_access() - write data to target memory or register 745 * @scn: pointer to hif_opaque_softc 746 * @address: register address to write to 747 * @data: value to be written to the address 748 * 749 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 750 */ 751 QDF_STATUS hif_diag_write_access(struct hif_opaque_softc *scn, 752 uint32_t address, 753 uint32_t data) 754 { 755 struct HIF_DEVICE_USB *macp = HIF_GET_USB_DEVICE(scn); 756 USB_CTRL_DIAG_CMD_WRITE *cmd; 757 758 cmd = (USB_CTRL_DIAG_CMD_WRITE *) macp->diag_cmd_buffer; 759 760 qdf_mem_zero(cmd, sizeof(*cmd)); 761 cmd->Cmd = USB_CTRL_DIAG_CC_WRITE; 762 cmd->Address = address; 763 cmd->Value = data; 764 765 return hif_ctrl_msg_exchange(macp, 766 USB_CONTROL_REQ_DIAG_CMD, 767 (uint8_t *) cmd, 768 sizeof(*cmd), 0, NULL, 0); 769 } 770 771 /** 772 * hif_dump_info() - dump info about all HIF pipes and endpoints 773 * @scn: pointer to hif_opaque_softc 774 * 775 * Return: none 776 */ 777 void hif_dump_info(struct hif_opaque_softc *scn) 778 { 779 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 780 struct HIF_USB_PIPE *pipe = NULL; 781 struct usb_host_interface *iface_desc = NULL; 782 struct usb_endpoint_descriptor *ep_desc; 783 uint8_t i = 0; 784 785 for (i = 0; i < HIF_USB_PIPE_MAX; i++) { 786 pipe = &device->pipes[i]; 787 HIF_ERROR("PipeIndex : %d URB Cnt : %d PipeHandle : %x", 788 i, pipe->urb_cnt, 789 pipe->usb_pipe_handle); 790 if (usb_pipeisoc(pipe->usb_pipe_handle)) 791 HIF_INFO("Pipe Type ISOC"); 792 else if (usb_pipebulk(pipe->usb_pipe_handle)) 793 HIF_INFO("Pipe Type BULK"); 794 else if (usb_pipeint(pipe->usb_pipe_handle)) 795 HIF_INFO("Pipe Type INT"); 796 else if (usb_pipecontrol(pipe->usb_pipe_handle)) 797 HIF_INFO("Pipe Type control"); 798 } 799 800 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 801 ep_desc = &iface_desc->endpoint[i].desc; 802 if (ep_desc) { 803 HIF_INFO( 804 "ep_desc : %pK Index : %d: DescType : %d Addr : %d Maxp : %d Atrrib : %d", 805 ep_desc, i, ep_desc->bDescriptorType, 806 ep_desc->bEndpointAddress, 807 ep_desc->wMaxPacketSize, 808 ep_desc->bmAttributes); 809 if ((ep_desc) && (usb_endpoint_type(ep_desc) == 810 USB_ENDPOINT_XFER_ISOC)) { 811 HIF_INFO("ISOC EP Detected"); 812 } 813 } 814 } 815 816 } 817 818 /** 819 * hif_flush_surprise_remove() - Cleanup residual buffers for device shutdown 820 * @scn: HIF context 821 * 822 * Not applicable to USB bus 823 * 824 * Return: none 825 */ 826 void hif_flush_surprise_remove(struct hif_opaque_softc *scn) 827 { 828 /* TO DO... */ 829 } 830 831 /** 832 * hif_diag_read_mem() -read nbytes of data from target memory or register 833 * @scn: pointer to hif_opaque_softc 834 * @address: register address to read from 835 * @data: buffer to store the value read 836 * @nbytes: number of bytes to be read from 'address' 837 * 838 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 839 */ 840 QDF_STATUS hif_diag_read_mem(struct hif_opaque_softc *scn, 841 uint32_t address, uint8_t *data, 842 int nbytes) 843 { 844 QDF_STATUS status = QDF_STATUS_SUCCESS; 845 846 HIF_TRACE("+%s", __func__); 847 848 if ((address & 0x3) || ((uintptr_t)data & 0x3)) 849 return QDF_STATUS_E_IO; 850 851 while ((nbytes >= 4) && 852 QDF_IS_STATUS_SUCCESS(status = 853 hif_diag_read_access(scn, 854 address, 855 (uint32_t *)data))) { 856 857 nbytes -= sizeof(uint32_t); 858 address += sizeof(uint32_t); 859 data += sizeof(uint32_t); 860 861 } 862 HIF_TRACE("-%s", __func__); 863 return status; 864 } 865 qdf_export_symbol(hif_diag_read_mem); 866 867 /** 868 * hif_diag_write_mem() -write nbytes of data to target memory or register 869 * @scn: pointer to hif_opaque_softc 870 * @address: register address to write to 871 * @data: buffer containing data to be written 872 * @nbytes: number of bytes to be written 873 * 874 * Return: QDF_STATUS_SUCCESS if success else an appropriate QDF_STATUS error 875 */ 876 QDF_STATUS hif_diag_write_mem(struct hif_opaque_softc *scn, 877 uint32_t address, 878 uint8_t *data, int nbytes) 879 { 880 QDF_STATUS status = QDF_STATUS_SUCCESS; 881 882 HIF_TRACE("+%s", __func__); 883 if ((address & 0x3) || ((uintptr_t)data & 0x3)) 884 return QDF_STATUS_E_IO; 885 886 while (nbytes >= 4 && 887 QDF_IS_STATUS_SUCCESS(status = 888 hif_diag_write_access(scn, 889 address, 890 *((uint32_t *)data)))) { 891 892 nbytes -= sizeof(uint32_t); 893 address += sizeof(uint32_t); 894 data += sizeof(uint32_t); 895 896 } 897 HIF_TRACE("-%s", __func__); 898 return status; 899 } 900 901 void hif_send_complete_check(struct hif_opaque_softc *scn, 902 uint8_t PipeID, int force) 903 { 904 /* NO-OP*/ 905 } 906 907 /* diagnostic command defnitions */ 908 #define USB_CTRL_DIAG_CC_READ 0 909 #define USB_CTRL_DIAG_CC_WRITE 1 910 #define USB_CTRL_DIAG_CC_WARM_RESET 2 911 912 void hif_suspend_wow(struct hif_opaque_softc *scn) 913 { 914 HIF_INFO("HIFsuspendwow - TODO"); 915 } 916 917 /** 918 * hif_usb_set_bundle_mode() - enable bundling and set default rx bundle cnt 919 * @scn: pointer to hif_opaque_softc structure 920 * @enabled: flag to enable/disable bundling 921 * @rx_bundle_cnt: bundle count to be used for RX 922 * 923 * Return: none 924 */ 925 void hif_usb_set_bundle_mode(struct hif_softc *scn, 926 bool enabled, int rx_bundle_cnt) 927 { 928 struct HIF_DEVICE_USB *device = HIF_GET_USB_DEVICE(scn); 929 930 device->is_bundle_enabled = enabled; 931 device->rx_bundle_cnt = rx_bundle_cnt; 932 if (device->is_bundle_enabled && (device->rx_bundle_cnt == 0)) 933 device->rx_bundle_cnt = 1; 934 935 device->rx_bundle_buf_len = device->rx_bundle_cnt * 936 HIF_USB_RX_BUNDLE_ONE_PKT_SIZE; 937 938 HIF_DBG("athusb bundle %s cnt %d", enabled ? "enabled" : "disabled", 939 rx_bundle_cnt); 940 } 941 942 /** 943 * hif_is_supported_rx_ctrl_pipe() - return true if device supports exclusive 944 * control pipe in the RX direction. 945 * @scn: hif context 946 * 947 * Return: true if device supports RX control pipe. 948 */ 949 bool hif_is_supported_rx_ctrl_pipe(struct hif_softc *scn) 950 { 951 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn); 952 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl); 953 954 switch (tgt_info->target_type) { 955 case TARGET_TYPE_QCN7605: 956 return true; 957 default: 958 return false; 959 } 960 } 961