Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2013-2015 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #include "ol_if_athvar.h" |
| 29 | #include "htc_debug.h" |
| 30 | #include "htc_internal.h" |
| 31 | #include <cdf_nbuf.h> /* cdf_nbuf_t */ |
| 32 | #include <cdf_types.h> /* cdf_print */ |
| 33 | #include <hif.h> |
| 34 | #include <cds_get_bin.h> |
| 35 | #include "epping_main.h" |
| 36 | #include "hif_io32.h" |
| 37 | |
| 38 | #ifdef DEBUG |
| 39 | static ATH_DEBUG_MASK_DESCRIPTION g_htc_debug_description[] = { |
| 40 | {ATH_DEBUG_SEND, "Send"}, |
| 41 | {ATH_DEBUG_RECV, "Recv"}, |
| 42 | {ATH_DEBUG_SYNC, "Sync"}, |
| 43 | {ATH_DEBUG_DUMP, "Dump Data (RX or TX)"}, |
| 44 | {ATH_DEBUG_SETUP, "Setup"}, |
| 45 | }; |
| 46 | |
| 47 | ATH_DEBUG_INSTANTIATE_MODULE_VAR(htc, |
| 48 | "htc", |
| 49 | "Host Target Communications", |
| 50 | ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_INFO | |
| 51 | ATH_DEBUG_SETUP, |
| 52 | ATH_DEBUG_DESCRIPTION_COUNT |
| 53 | (g_htc_debug_description), |
| 54 | g_htc_debug_description); |
| 55 | |
| 56 | #endif |
| 57 | |
| 58 | extern unsigned int htc_credit_flow; |
| 59 | |
| 60 | static void reset_endpoint_states(HTC_TARGET *target); |
| 61 | |
| 62 | static void destroy_htc_tx_ctrl_packet(HTC_PACKET *pPacket) |
| 63 | { |
| 64 | cdf_nbuf_t netbuf; |
| 65 | netbuf = (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 66 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("free ctrl netbuf :0x%p \n", netbuf)); |
| 67 | if (netbuf != NULL) { |
| 68 | cdf_nbuf_free(netbuf); |
| 69 | } |
| 70 | |
| 71 | cdf_mem_free(pPacket); |
| 72 | } |
| 73 | |
| 74 | static HTC_PACKET *build_htc_tx_ctrl_packet(cdf_device_t osdev) |
| 75 | { |
| 76 | HTC_PACKET *pPacket = NULL; |
| 77 | cdf_nbuf_t netbuf; |
| 78 | |
| 79 | do { |
| 80 | pPacket = (HTC_PACKET *) cdf_mem_malloc(sizeof(HTC_PACKET)); |
| 81 | if (NULL == pPacket) { |
| 82 | break; |
| 83 | } |
| 84 | A_MEMZERO(pPacket, sizeof(HTC_PACKET)); |
| 85 | netbuf = |
| 86 | cdf_nbuf_alloc(osdev, HTC_CONTROL_BUFFER_SIZE, 20, 4, true); |
| 87 | if (NULL == netbuf) { |
| 88 | cdf_mem_free(pPacket); |
| 89 | pPacket = NULL; |
| 90 | cdf_print("%s: nbuf alloc failed\n", __func__); |
| 91 | break; |
| 92 | } |
| 93 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, |
| 94 | ("alloc ctrl netbuf :0x%p \n", netbuf)); |
| 95 | SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf); |
| 96 | } while (false); |
| 97 | |
| 98 | return pPacket; |
| 99 | } |
| 100 | |
| 101 | void htc_free_control_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket) |
| 102 | { |
| 103 | |
| 104 | #ifdef TODO_FIXME |
| 105 | LOCK_HTC(target); |
| 106 | HTC_PACKET_ENQUEUE(&target->ControlBufferTXFreeList, pPacket); |
| 107 | UNLOCK_HTC(target); |
| 108 | /* TODO_FIXME netbufs cannot be RESET! */ |
| 109 | #else |
| 110 | destroy_htc_tx_ctrl_packet(pPacket); |
| 111 | #endif |
| 112 | |
| 113 | } |
| 114 | |
| 115 | HTC_PACKET *htc_alloc_control_tx_packet(HTC_TARGET *target) |
| 116 | { |
| 117 | #ifdef TODO_FIXME |
| 118 | HTC_PACKET *pPacket; |
| 119 | |
| 120 | LOCK_HTC(target); |
| 121 | pPacket = htc_packet_dequeue(&target->ControlBufferTXFreeList); |
| 122 | UNLOCK_HTC(target); |
| 123 | |
| 124 | return pPacket; |
| 125 | #else |
| 126 | return build_htc_tx_ctrl_packet(target->osdev); |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | /* Set the target failure handling callback */ |
| 131 | void htc_set_target_failure_callback(HTC_HANDLE HTCHandle, |
| 132 | HTC_TARGET_FAILURE Callback) |
| 133 | { |
| 134 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 135 | target->HTCInitInfo.TargetFailure = Callback; |
| 136 | } |
| 137 | |
| 138 | void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start) |
| 139 | { |
| 140 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 141 | hif_dump(target->hif_dev, CmdId, start); |
| 142 | } |
| 143 | |
| 144 | /* cleanup the HTC instance */ |
| 145 | static void htc_cleanup(HTC_TARGET *target) |
| 146 | { |
| 147 | HTC_PACKET *pPacket; |
| 148 | /* cdf_nbuf_t netbuf; */ |
| 149 | |
| 150 | if (target->hif_dev != NULL) { |
| 151 | hif_detach_htc(target->hif_dev); |
| 152 | target->hif_dev = NULL; |
| 153 | } |
| 154 | |
| 155 | while (true) { |
| 156 | pPacket = allocate_htc_packet_container(target); |
| 157 | if (NULL == pPacket) { |
| 158 | break; |
| 159 | } |
| 160 | cdf_mem_free(pPacket); |
| 161 | } |
| 162 | |
| 163 | pPacket = target->pBundleFreeList; |
| 164 | while (pPacket) { |
| 165 | HTC_PACKET *pPacketTmp = (HTC_PACKET *) pPacket->ListLink.pNext; |
| 166 | cdf_mem_free(pPacket); |
| 167 | pPacket = pPacketTmp; |
| 168 | } |
| 169 | #ifdef TODO_FIXME |
| 170 | while (true) { |
| 171 | pPacket = htc_alloc_control_tx_packet(target); |
| 172 | if (NULL == pPacket) { |
| 173 | break; |
| 174 | } |
| 175 | netbuf = (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 176 | if (netbuf != NULL) { |
| 177 | cdf_nbuf_free(netbuf); |
| 178 | } |
| 179 | |
| 180 | cdf_mem_free(pPacket); |
| 181 | } |
| 182 | #endif |
| 183 | |
| 184 | cdf_spinlock_destroy(&target->HTCLock); |
| 185 | cdf_spinlock_destroy(&target->HTCRxLock); |
| 186 | cdf_spinlock_destroy(&target->HTCTxLock); |
| 187 | cdf_spinlock_destroy(&target->HTCCreditLock); |
| 188 | |
| 189 | /* free our instance */ |
| 190 | cdf_mem_free(target); |
| 191 | } |
| 192 | |
| 193 | /* registered target arrival callback from the HIF layer */ |
| 194 | HTC_HANDLE htc_create(void *ol_sc, HTC_INIT_INFO *pInfo, cdf_device_t osdev) |
| 195 | { |
| 196 | struct hif_msg_callbacks htcCallbacks; |
| 197 | HTC_ENDPOINT *pEndpoint = NULL; |
| 198 | HTC_TARGET *target = NULL; |
| 199 | int i; |
| 200 | |
| 201 | if (ol_sc == NULL) { |
| 202 | HTC_ERROR("%s: ol_sc = NULL", __func__); |
| 203 | return NULL; |
| 204 | } |
| 205 | HTC_TRACE("+htc_create .. HIF :%p", ol_sc); |
| 206 | |
| 207 | A_REGISTER_MODULE_DEBUG_INFO(htc); |
| 208 | |
| 209 | target = (HTC_TARGET *) cdf_mem_malloc(sizeof(HTC_TARGET)); |
| 210 | if (target == NULL) { |
| 211 | HTC_ERROR("%s: Unable to allocate memory", __func__); |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | A_MEMZERO(target, sizeof(HTC_TARGET)); |
| 216 | |
| 217 | cdf_spinlock_init(&target->HTCLock); |
| 218 | cdf_spinlock_init(&target->HTCRxLock); |
| 219 | cdf_spinlock_init(&target->HTCTxLock); |
| 220 | cdf_spinlock_init(&target->HTCCreditLock); |
| 221 | |
| 222 | do { |
| 223 | A_MEMCPY(&target->HTCInitInfo, pInfo, sizeof(HTC_INIT_INFO)); |
| 224 | target->host_handle = pInfo->pContext; |
| 225 | target->osdev = osdev; |
| 226 | |
| 227 | reset_endpoint_states(target); |
| 228 | |
| 229 | INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList); |
| 230 | |
| 231 | for (i = 0; i < HTC_PACKET_CONTAINER_ALLOCATION; i++) { |
| 232 | HTC_PACKET *pPacket = |
| 233 | (HTC_PACKET *) cdf_mem_malloc(sizeof(HTC_PACKET)); |
| 234 | if (pPacket != NULL) { |
| 235 | A_MEMZERO(pPacket, sizeof(HTC_PACKET)); |
| 236 | free_htc_packet_container(target, pPacket); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | #ifdef TODO_FIXME |
| 241 | for (i = 0; i < NUM_CONTROL_TX_BUFFERS; i++) { |
| 242 | pPacket = build_htc_tx_ctrl_packet(); |
| 243 | if (NULL == pPacket) { |
| 244 | break; |
| 245 | } |
| 246 | htc_free_control_tx_packet(target, pPacket); |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | /* setup HIF layer callbacks */ |
| 251 | cdf_mem_zero(&htcCallbacks, sizeof(struct hif_msg_callbacks)); |
| 252 | htcCallbacks.Context = target; |
| 253 | htcCallbacks.rxCompletionHandler = htc_rx_completion_handler; |
| 254 | htcCallbacks.txCompletionHandler = htc_tx_completion_handler; |
| 255 | htcCallbacks.txResourceAvailHandler = htc_tx_resource_avail_handler; |
| 256 | htcCallbacks.fwEventHandler = htc_fw_event_handler; |
| 257 | target->hif_dev = ol_sc; |
| 258 | |
| 259 | /* Get HIF default pipe for HTC message exchange */ |
| 260 | pEndpoint = &target->EndPoint[ENDPOINT_0]; |
| 261 | |
| 262 | hif_post_init(target->hif_dev, target, &htcCallbacks); |
| 263 | hif_get_default_pipe(target->hif_dev, &pEndpoint->UL_PipeID, |
| 264 | &pEndpoint->DL_PipeID); |
| 265 | |
| 266 | } while (false); |
| 267 | |
| 268 | htc_recv_init(target); |
| 269 | |
| 270 | HTC_TRACE("-htc_create: (0x%p)", target); |
| 271 | |
| 272 | return (HTC_HANDLE) target; |
| 273 | } |
| 274 | |
| 275 | void htc_destroy(HTC_HANDLE HTCHandle) |
| 276 | { |
| 277 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 278 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, |
| 279 | ("+htc_destroy .. Destroying :0x%p\n", target)); |
| 280 | if (target) |
| 281 | htc_cleanup(target); |
| 282 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_destroy\n")); |
| 283 | } |
| 284 | |
| 285 | /* get the low level HIF device for the caller , the caller may wish to do low level |
| 286 | * HIF requests */ |
| 287 | void *htc_get_hif_device(HTC_HANDLE HTCHandle) |
| 288 | { |
| 289 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 290 | return target->hif_dev; |
| 291 | } |
| 292 | |
| 293 | void htc_control_tx_complete(void *Context, HTC_PACKET *pPacket) |
| 294 | { |
| 295 | HTC_TARGET *target = (HTC_TARGET *) Context; |
| 296 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, |
| 297 | ("+-htc_control_tx_complete 0x%p (l:%d) \n", pPacket, |
| 298 | pPacket->ActualLength)); |
| 299 | htc_free_control_tx_packet(target, pPacket); |
| 300 | } |
| 301 | |
| 302 | /* TODO, this is just a temporary max packet size */ |
| 303 | #define MAX_MESSAGE_SIZE 1536 |
| 304 | |
| 305 | /** |
| 306 | * htc_setup_target_buffer_assignments() - setup target buffer assignments |
| 307 | * @target: HTC Target Pointer |
| 308 | * |
| 309 | * Return: A_STATUS |
| 310 | */ |
| 311 | A_STATUS htc_setup_target_buffer_assignments(HTC_TARGET *target) |
| 312 | { |
| 313 | HTC_SERVICE_TX_CREDIT_ALLOCATION *pEntry; |
| 314 | A_STATUS status; |
| 315 | int credits; |
| 316 | int creditsPerMaxMsg; |
| 317 | |
| 318 | creditsPerMaxMsg = MAX_MESSAGE_SIZE / target->TargetCreditSize; |
| 319 | if (MAX_MESSAGE_SIZE % target->TargetCreditSize) { |
| 320 | creditsPerMaxMsg++; |
| 321 | } |
| 322 | |
| 323 | /* TODO, this should be configured by the caller! */ |
| 324 | |
| 325 | credits = target->TotalTransmitCredits; |
| 326 | pEntry = &target->ServiceTxAllocTable[0]; |
| 327 | |
| 328 | /* |
| 329 | * Allocate all credists/HTC buffers to WMI. |
| 330 | * no buffers are used/required for data. data always |
| 331 | * remains on host. |
| 332 | */ |
| 333 | status = A_OK; |
| 334 | pEntry++; |
| 335 | pEntry->ServiceID = WMI_CONTROL_SVC; |
| 336 | pEntry->CreditAllocation = credits; |
| 337 | |
| 338 | if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) { |
| 339 | /* endpoint ping is a testing tool directly on top of HTC in |
| 340 | * both target and host sides. |
| 341 | * In target side, the endppint ping fw has no wlan stack and the |
| 342 | * FW mboxping app directly sits on HTC and it simply drops |
| 343 | * or loops back TX packets. For rx perf, FW mboxping app |
| 344 | * generates packets and passes packets to HTC to send to host. |
| 345 | * There is no WMI mesage exchanges between host and target |
| 346 | * in endpoint ping case. |
| 347 | * In host side, the endpoint ping driver is a Ethernet driver |
| 348 | * and it directly sits on HTC. Only HIF, HTC, CDF, ADF are |
| 349 | * used by the endpoint ping driver. There is no wifi stack |
| 350 | * at all in host side also. For tx perf use case, |
| 351 | * the user space mboxping app sends the raw packets to endpoint |
| 352 | * ping driver and it directly forwards to HTC for transmission |
| 353 | * to stress the bus. For the rx perf, HTC passes the received |
| 354 | * packets to endpoint ping driver and it is passed to the user |
| 355 | * space through the Ethernet interface. |
| 356 | * For credit allocation, in SDIO bus case, only BE service is |
| 357 | * used for tx/rx perf testing so that all credits are given |
| 358 | * to BE service. In PCIe and USB bus case, endpoint ping uses both |
| 359 | * BE and BK services to stress the bus so that the total credits |
| 360 | * are equally distributed to BE and BK services. |
| 361 | */ |
| 362 | pEntry->ServiceID = WMI_DATA_BE_SVC; |
| 363 | pEntry->CreditAllocation = (credits >> 1); |
| 364 | |
| 365 | pEntry++; |
| 366 | pEntry->ServiceID = WMI_DATA_BK_SVC; |
| 367 | pEntry->CreditAllocation = (credits >> 1); |
| 368 | } |
| 369 | |
| 370 | if (A_SUCCESS(status)) { |
| 371 | int i; |
| 372 | for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) { |
| 373 | if (target->ServiceTxAllocTable[i].ServiceID != 0) { |
| 374 | AR_DEBUG_PRINTF(ATH_DEBUG_INIT, |
| 375 | ("HTC Service Index : %d TX : 0x%2.2X : alloc:%d \n", |
| 376 | i, |
| 377 | target->ServiceTxAllocTable[i]. |
| 378 | ServiceID, |
| 379 | target->ServiceTxAllocTable[i]. |
| 380 | CreditAllocation)); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return status; |
| 386 | } |
| 387 | |
| 388 | A_UINT8 htc_get_credit_allocation(HTC_TARGET *target, A_UINT16 ServiceID) |
| 389 | { |
| 390 | A_UINT8 allocation = 0; |
| 391 | int i; |
| 392 | |
| 393 | for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) { |
| 394 | if (target->ServiceTxAllocTable[i].ServiceID == ServiceID) { |
| 395 | allocation = |
| 396 | target->ServiceTxAllocTable[i].CreditAllocation; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (0 == allocation) { |
| 401 | AR_DEBUG_PRINTF(ATH_DEBUG_INIT, |
| 402 | ("HTC Service TX : 0x%2.2X : allocation is zero! \n", |
| 403 | ServiceID)); |
| 404 | } |
| 405 | |
| 406 | return allocation; |
| 407 | } |
| 408 | |
| 409 | A_STATUS htc_wait_target(HTC_HANDLE HTCHandle) |
| 410 | { |
| 411 | A_STATUS status = A_OK; |
| 412 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 413 | HTC_READY_EX_MSG *pReadyMsg; |
| 414 | HTC_SERVICE_CONNECT_REQ connect; |
| 415 | HTC_SERVICE_CONNECT_RESP resp; |
| 416 | HTC_READY_MSG *rdy_msg; |
| 417 | A_UINT16 htc_rdy_msg_id; |
| 418 | |
| 419 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, |
| 420 | ("htc_wait_target - Enter (target:0x%p) \n", HTCHandle)); |
| 421 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("+HWT\n")); |
| 422 | |
| 423 | do { |
| 424 | |
| 425 | status = hif_start(target->hif_dev); |
| 426 | if (A_FAILED(status)) { |
| 427 | AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("hif_start failed\n")); |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | status = htc_wait_recv_ctrl_message(target); |
| 432 | |
| 433 | if (A_FAILED(status)) { |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | if (target->CtrlResponseLength < (sizeof(HTC_READY_EX_MSG))) { |
| 438 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 439 | ("Invalid HTC Ready Msg Len:%d! \n", |
| 440 | target->CtrlResponseLength)); |
| 441 | status = A_ECOMM; |
| 442 | break; |
| 443 | } |
| 444 | |
| 445 | pReadyMsg = (HTC_READY_EX_MSG *) target->CtrlResponseBuffer; |
| 446 | |
| 447 | rdy_msg = &pReadyMsg->Version2_0_Info; |
| 448 | htc_rdy_msg_id = |
| 449 | HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, MESSAGEID); |
| 450 | if (htc_rdy_msg_id != HTC_MSG_READY_ID) { |
| 451 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 452 | ("Invalid HTC Ready Msg : 0x%X ! \n", |
| 453 | htc_rdy_msg_id)); |
| 454 | status = A_ECOMM; |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | target->TotalTransmitCredits = |
| 459 | HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITCOUNT); |
| 460 | target->TargetCreditSize = |
| 461 | (int)HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITSIZE); |
| 462 | target->MaxMsgsPerHTCBundle = |
| 463 | (A_UINT8) pReadyMsg->MaxMsgsPerHTCBundle; |
| 464 | /* for old fw this value is set to 0. But the minimum value should be 1, |
| 465 | * i.e., no bundling */ |
| 466 | if (target->MaxMsgsPerHTCBundle < 1) |
| 467 | target->MaxMsgsPerHTCBundle = 1; |
| 468 | |
| 469 | AR_DEBUG_PRINTF(ATH_DEBUG_INIT, |
| 470 | ("Target Ready! : transmit resources : %d size:%d, MaxMsgsPerHTCBundle = %d\n", |
| 471 | target->TotalTransmitCredits, |
| 472 | target->TargetCreditSize, |
| 473 | target->MaxMsgsPerHTCBundle)); |
| 474 | |
| 475 | if ((0 == target->TotalTransmitCredits) |
| 476 | || (0 == target->TargetCreditSize)) { |
| 477 | status = A_ECOMM; |
| 478 | break; |
| 479 | } |
| 480 | /* done processing */ |
| 481 | target->CtrlResponseProcessing = false; |
| 482 | |
| 483 | htc_setup_target_buffer_assignments(target); |
| 484 | |
| 485 | /* setup our pseudo HTC control endpoint connection */ |
| 486 | A_MEMZERO(&connect, sizeof(connect)); |
| 487 | A_MEMZERO(&resp, sizeof(resp)); |
| 488 | connect.EpCallbacks.pContext = target; |
| 489 | connect.EpCallbacks.EpTxComplete = htc_control_tx_complete; |
| 490 | connect.EpCallbacks.EpRecv = htc_control_rx_complete; |
| 491 | connect.MaxSendQueueDepth = NUM_CONTROL_TX_BUFFERS; |
| 492 | connect.ServiceID = HTC_CTRL_RSVD_SVC; |
| 493 | |
| 494 | /* connect fake service */ |
| 495 | status = htc_connect_service((HTC_HANDLE) target, |
| 496 | &connect, &resp); |
| 497 | |
| 498 | } while (false); |
| 499 | |
| 500 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_wait_target - Exit (%d)\n", status)); |
| 501 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("-HWT\n")); |
| 502 | return status; |
| 503 | } |
| 504 | |
| 505 | /* start HTC, this is called after all services are connected */ |
| 506 | static A_STATUS htc_config_target_hif_pipe(HTC_TARGET *target) |
| 507 | { |
| 508 | |
| 509 | return A_OK; |
| 510 | } |
| 511 | |
| 512 | static void reset_endpoint_states(HTC_TARGET *target) |
| 513 | { |
| 514 | HTC_ENDPOINT *pEndpoint; |
| 515 | int i; |
| 516 | |
| 517 | for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) { |
| 518 | pEndpoint = &target->EndPoint[i]; |
| 519 | pEndpoint->ServiceID = 0; |
| 520 | pEndpoint->MaxMsgLength = 0; |
| 521 | pEndpoint->MaxTxQueueDepth = 0; |
| 522 | pEndpoint->Id = i; |
| 523 | INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue); |
| 524 | INIT_HTC_PACKET_QUEUE(&pEndpoint->TxLookupQueue); |
| 525 | INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBufferHoldQueue); |
| 526 | pEndpoint->target = target; |
| 527 | /* pEndpoint->TxCreditFlowEnabled = (A_BOOL)htc_credit_flow; */ |
| 528 | pEndpoint->TxCreditFlowEnabled = (A_BOOL) 1; |
| 529 | cdf_atomic_init(&pEndpoint->TxProcessCount); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | A_STATUS htc_start(HTC_HANDLE HTCHandle) |
| 534 | { |
| 535 | cdf_nbuf_t netbuf; |
| 536 | A_STATUS status = A_OK; |
| 537 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 538 | HTC_SETUP_COMPLETE_EX_MSG *pSetupComp; |
| 539 | HTC_PACKET *pSendPacket; |
| 540 | |
| 541 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Enter\n")); |
| 542 | |
| 543 | do { |
| 544 | |
| 545 | htc_config_target_hif_pipe(target); |
| 546 | |
| 547 | /* allocate a buffer to send */ |
| 548 | pSendPacket = htc_alloc_control_tx_packet(target); |
| 549 | if (NULL == pSendPacket) { |
| 550 | AR_DEBUG_ASSERT(false); |
| 551 | cdf_print("%s: allocControlTxPacket failed\n", |
| 552 | __func__); |
| 553 | status = A_NO_MEMORY; |
| 554 | break; |
| 555 | } |
| 556 | |
| 557 | netbuf = |
| 558 | (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket); |
| 559 | /* assemble setup complete message */ |
| 560 | cdf_nbuf_put_tail(netbuf, sizeof(HTC_SETUP_COMPLETE_EX_MSG)); |
| 561 | pSetupComp = |
| 562 | (HTC_SETUP_COMPLETE_EX_MSG *) cdf_nbuf_data(netbuf); |
| 563 | A_MEMZERO(pSetupComp, sizeof(HTC_SETUP_COMPLETE_EX_MSG)); |
| 564 | |
| 565 | HTC_SET_FIELD(pSetupComp, HTC_SETUP_COMPLETE_EX_MSG, |
| 566 | MESSAGEID, HTC_MSG_SETUP_COMPLETE_EX_ID); |
| 567 | |
| 568 | if (!htc_credit_flow) { |
| 569 | AR_DEBUG_PRINTF(ATH_DEBUG_INIT, |
| 570 | ("HTC will not use TX credit flow control\n")); |
| 571 | pSetupComp->SetupFlags |= |
| 572 | HTC_SETUP_COMPLETE_FLAGS_DISABLE_TX_CREDIT_FLOW; |
| 573 | } else { |
| 574 | AR_DEBUG_PRINTF(ATH_DEBUG_INIT, |
| 575 | ("HTC using TX credit flow control\n")); |
| 576 | } |
| 577 | |
| 578 | #ifdef HIF_SDIO |
| 579 | #if ENABLE_BUNDLE_RX |
| 580 | if (HTC_ENABLE_BUNDLE(target)) |
| 581 | pSetupComp->SetupFlags |= |
| 582 | HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV; |
| 583 | #endif /* ENABLE_BUNDLE_RX */ |
| 584 | #endif /* HIF_SDIO */ |
| 585 | |
| 586 | SET_HTC_PACKET_INFO_TX(pSendPacket, |
| 587 | NULL, |
| 588 | (A_UINT8 *) pSetupComp, |
| 589 | sizeof(HTC_SETUP_COMPLETE_EX_MSG), |
| 590 | ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG); |
| 591 | |
| 592 | status = htc_send_pkt((HTC_HANDLE) target, pSendPacket); |
| 593 | if (A_FAILED(status)) { |
| 594 | break; |
| 595 | } |
| 596 | |
| 597 | } while (false); |
| 598 | |
| 599 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Exit\n")); |
| 600 | return status; |
| 601 | } |
| 602 | |
| 603 | /*flush all queued buffers for surpriseremove case*/ |
| 604 | void htc_flush_surprise_remove(HTC_HANDLE HTCHandle) |
| 605 | { |
| 606 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 607 | int i; |
| 608 | HTC_ENDPOINT *pEndpoint; |
| 609 | #ifdef RX_SG_SUPPORT |
| 610 | cdf_nbuf_t netbuf; |
| 611 | cdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue; |
| 612 | #endif |
| 613 | |
| 614 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_flush_surprise_remove \n")); |
| 615 | |
| 616 | /* cleanup endpoints */ |
| 617 | for (i = 0; i < ENDPOINT_MAX; i++) { |
| 618 | pEndpoint = &target->EndPoint[i]; |
| 619 | htc_flush_rx_hold_queue(target, pEndpoint); |
| 620 | htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL); |
| 621 | } |
| 622 | |
| 623 | hif_flush_surprise_remove(target->hif_dev); |
| 624 | |
| 625 | #ifdef RX_SG_SUPPORT |
| 626 | LOCK_HTC_RX(target); |
| 627 | while ((netbuf = cdf_nbuf_queue_remove(rx_sg_queue)) != NULL) { |
| 628 | cdf_nbuf_free(netbuf); |
| 629 | } |
| 630 | RESET_RX_SG_CONFIG(target); |
| 631 | UNLOCK_HTC_RX(target); |
| 632 | #endif |
| 633 | |
| 634 | reset_endpoint_states(target); |
| 635 | |
| 636 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_flush_surprise_remove \n")); |
| 637 | } |
| 638 | |
| 639 | /* stop HTC communications, i.e. stop interrupt reception, and flush all queued buffers */ |
| 640 | void htc_stop(HTC_HANDLE HTCHandle) |
| 641 | { |
| 642 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 643 | int i; |
| 644 | HTC_ENDPOINT *pEndpoint; |
| 645 | #ifdef RX_SG_SUPPORT |
| 646 | cdf_nbuf_t netbuf; |
| 647 | cdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue; |
| 648 | #endif |
| 649 | |
| 650 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_stop \n")); |
| 651 | |
| 652 | /* cleanup endpoints */ |
| 653 | for (i = 0; i < ENDPOINT_MAX; i++) { |
| 654 | pEndpoint = &target->EndPoint[i]; |
| 655 | htc_flush_rx_hold_queue(target, pEndpoint); |
| 656 | htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL); |
| 657 | if (pEndpoint->ul_is_polled) { |
| 658 | cdf_softirq_timer_cancel(&pEndpoint->ul_poll_timer); |
| 659 | cdf_softirq_timer_free(&pEndpoint->ul_poll_timer); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | /* Note: htc_flush_endpoint_tx for all endpoints should be called before |
| 664 | * hif_stop - otherwise htc_tx_completion_handler called from |
| 665 | * hif_send_buffer_cleanup_on_pipe for residual tx frames in HIF layer, |
| 666 | * might queue the packet again to HIF Layer - which could cause tx |
| 667 | * buffer leak |
| 668 | */ |
| 669 | |
| 670 | hif_stop(target->hif_dev); |
| 671 | |
| 672 | #ifdef RX_SG_SUPPORT |
| 673 | LOCK_HTC_RX(target); |
| 674 | while ((netbuf = cdf_nbuf_queue_remove(rx_sg_queue)) != NULL) { |
| 675 | cdf_nbuf_free(netbuf); |
| 676 | } |
| 677 | RESET_RX_SG_CONFIG(target); |
| 678 | UNLOCK_HTC_RX(target); |
| 679 | #endif |
| 680 | |
| 681 | reset_endpoint_states(target); |
| 682 | |
| 683 | AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_stop \n")); |
| 684 | } |
| 685 | |
| 686 | void htc_dump_credit_states(HTC_HANDLE HTCHandle) |
| 687 | { |
| 688 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 689 | HTC_ENDPOINT *pEndpoint; |
| 690 | int i; |
| 691 | |
| 692 | for (i = 0; i < ENDPOINT_MAX; i++) { |
| 693 | pEndpoint = &target->EndPoint[i]; |
| 694 | if (0 == pEndpoint->ServiceID) { |
| 695 | continue; |
| 696 | } |
| 697 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 698 | ("--- EP : %d ServiceID: 0x%X --------------\n", |
| 699 | pEndpoint->Id, pEndpoint->ServiceID)); |
| 700 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 701 | (" TxCredits : %d \n", |
| 702 | pEndpoint->TxCredits)); |
| 703 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 704 | (" TxCreditSize : %d \n", |
| 705 | pEndpoint->TxCreditSize)); |
| 706 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 707 | (" TxCreditsPerMaxMsg : %d \n", |
| 708 | pEndpoint->TxCreditsPerMaxMsg)); |
| 709 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 710 | (" TxQueueDepth : %d \n", |
| 711 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue))); |
| 712 | AR_DEBUG_PRINTF(ATH_DEBUG_ANY, |
| 713 | ("----------------------------------------------------\n")); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | A_BOOL htc_get_endpoint_statistics(HTC_HANDLE HTCHandle, |
| 718 | HTC_ENDPOINT_ID Endpoint, |
| 719 | HTC_ENDPOINT_STAT_ACTION Action, |
| 720 | HTC_ENDPOINT_STATS *pStats) |
| 721 | { |
| 722 | #ifdef HTC_EP_STAT_PROFILING |
| 723 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 724 | A_BOOL clearStats = false; |
| 725 | A_BOOL sample = false; |
| 726 | |
| 727 | switch (Action) { |
| 728 | case HTC_EP_STAT_SAMPLE: |
| 729 | sample = true; |
| 730 | break; |
| 731 | case HTC_EP_STAT_SAMPLE_AND_CLEAR: |
| 732 | sample = true; |
| 733 | clearStats = true; |
| 734 | break; |
| 735 | case HTC_EP_STAT_CLEAR: |
| 736 | clearStats = true; |
| 737 | break; |
| 738 | default: |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | A_ASSERT(Endpoint < ENDPOINT_MAX); |
| 743 | |
| 744 | /* lock out TX and RX while we sample and/or clear */ |
| 745 | LOCK_HTC_TX(target); |
| 746 | LOCK_HTC_RX(target); |
| 747 | |
| 748 | if (sample) { |
| 749 | A_ASSERT(pStats != NULL); |
| 750 | /* return the stats to the caller */ |
| 751 | A_MEMCPY(pStats, &target->EndPoint[Endpoint].EndPointStats, |
| 752 | sizeof(HTC_ENDPOINT_STATS)); |
| 753 | } |
| 754 | |
| 755 | if (clearStats) { |
| 756 | /* reset stats */ |
| 757 | A_MEMZERO(&target->EndPoint[Endpoint].EndPointStats, |
| 758 | sizeof(HTC_ENDPOINT_STATS)); |
| 759 | } |
| 760 | |
| 761 | UNLOCK_HTC_RX(target); |
| 762 | UNLOCK_HTC_TX(target); |
| 763 | |
| 764 | return true; |
| 765 | #else |
| 766 | return false; |
| 767 | #endif |
| 768 | } |
| 769 | |
| 770 | void *htc_get_targetdef(HTC_HANDLE htc_handle) |
| 771 | { |
| 772 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle); |
| 773 | |
| 774 | return hif_get_targetdef(target->hif_dev); |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * htc_set_target_to_sleep() - set target to sleep |
| 779 | * @context: ol_softc context |
| 780 | * |
| 781 | * Return: none |
| 782 | */ |
| 783 | void htc_set_target_to_sleep(void *context) |
| 784 | { |
| 785 | struct ol_softc *scn = (struct ol_softc *)context; |
| 786 | |
| 787 | hif_set_target_sleep(scn, true, false); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * htc_cancel_deferred_target_sleep() - cancel deferred target sleep |
| 792 | * @context: ol_softc context |
| 793 | * |
| 794 | * Return: none |
| 795 | */ |
| 796 | void htc_cancel_deferred_target_sleep(void *context) |
| 797 | { |
| 798 | struct ol_softc *scn = (struct ol_softc *)context; |
| 799 | hif_cancel_deferred_target_sleep(scn); |
| 800 | } |
| 801 | |
| 802 | #ifdef IPA_OFFLOAD |
| 803 | void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle, |
| 804 | uint32_t *ce_sr_base_paddr, |
| 805 | uint32_t *ce_sr_ring_size, |
| 806 | cdf_dma_addr_t *ce_reg_paddr) |
| 807 | { |
| 808 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle); |
| 809 | |
| 810 | if (target->hif_dev != NULL) { |
| 811 | hif_ipa_get_ce_resource(target->hif_dev, |
| 812 | ce_sr_base_paddr, |
| 813 | ce_sr_ring_size, ce_reg_paddr); |
| 814 | } |
| 815 | } |
| 816 | #endif /* IPA_OFFLOAD */ |