Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Rajeev Kumar | 926baab | 2016-01-06 18:11:55 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 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 "htc_debug.h" |
| 29 | #include "htc_internal.h" |
| 30 | #include <cdf_nbuf.h> /* cdf_nbuf_t */ |
| 31 | #include <cdf_memory.h> /* cdf_mem_malloc */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 32 | #include "epping_main.h" |
| 33 | |
| 34 | /* #define USB_HIF_SINGLE_PIPE_DATA_SCHED */ |
| 35 | /* #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED */ |
| 36 | #define DATA_EP_SIZE 4 |
| 37 | /* #endif */ |
| 38 | #define HTC_DATA_RESOURCE_THRS 256 |
| 39 | #define HTC_DATA_MINDESC_PERPACKET 2 |
| 40 | |
| 41 | typedef enum _HTC_SEND_QUEUE_RESULT { |
| 42 | HTC_SEND_QUEUE_OK = 0, /* packet was queued */ |
| 43 | HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */ |
| 44 | } HTC_SEND_QUEUE_RESULT; |
| 45 | |
| 46 | #ifndef DEBUG_CREDIT |
| 47 | #define DEBUG_CREDIT 0 |
| 48 | #endif |
| 49 | |
| 50 | #if DEBUG_CREDIT |
| 51 | /* bit mask to enable debug certain endpoint */ |
| 52 | static unsigned ep_debug_mask = |
| 53 | (1 << ENDPOINT_0) | (1 << ENDPOINT_1) | (1 << ENDPOINT_2); |
| 54 | #endif |
| 55 | |
| 56 | /* HTC Control Path Credit History */ |
| 57 | A_UINT32 g_htc_credit_history_idx = 0; |
| 58 | HTC_CREDIT_HISTORY htc_credit_history_buffer[HTC_CREDIT_HISTORY_MAX]; |
| 59 | |
| 60 | /** |
| 61 | * htc_credit_record() - records tx que state & credit transactions |
| 62 | * @type: type of echange can be HTC_REQUEST_CREDIT |
| 63 | * or HTC_PROCESS_CREDIT_REPORT |
| 64 | * @tx_credits: current number of tx_credits |
| 65 | * @htc_tx_queue_depth: current hct tx queue depth |
| 66 | * |
| 67 | * This function records the credits and pending commands whenever a command is |
| 68 | * sent or credits are returned. Call this after the credits have been updated |
| 69 | * according to the transaction. Call this before dequeing commands. |
| 70 | * |
| 71 | * Consider making this function accept an HTC_ENDPOINT and find the current |
| 72 | * credits and queue depth itself. |
| 73 | * |
| 74 | * Consider moving the LOCK_HTC_CREDIT(target); logic into this function as well. |
| 75 | */ |
| 76 | void htc_credit_record(htc_credit_exchange_type type, uint32_t tx_credit, |
| 77 | uint32_t htc_tx_queue_depth) { |
| 78 | if (HTC_CREDIT_HISTORY_MAX <= g_htc_credit_history_idx) |
| 79 | g_htc_credit_history_idx = 0; |
| 80 | |
| 81 | htc_credit_history_buffer[g_htc_credit_history_idx].type = type; |
| 82 | htc_credit_history_buffer[g_htc_credit_history_idx].time = |
| 83 | cdf_get_log_timestamp(); |
| 84 | htc_credit_history_buffer[g_htc_credit_history_idx].tx_credit = |
| 85 | tx_credit; |
| 86 | htc_credit_history_buffer[g_htc_credit_history_idx].htc_tx_queue_depth = |
| 87 | htc_tx_queue_depth; |
| 88 | g_htc_credit_history_idx++; |
| 89 | |
| 90 | #ifdef QCA_WIFI_3_0_EMU |
| 91 | if (type == HTC_REQUEST_CREDIT) |
| 92 | printk("\nrequest_credits-> current_credit %d, pending commands %d\n", |
| 93 | tx_credit, htc_tx_queue_depth); |
| 94 | |
| 95 | else if (type == HTC_PROCESS_CREDIT_REPORT) |
| 96 | printk("\ncredit_report<- current_credit %d, pending commands %d\n", |
| 97 | tx_credit, htc_tx_queue_depth); |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | void htc_dump_counter_info(HTC_HANDLE HTCHandle) |
| 102 | { |
| 103 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 104 | |
| 105 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 106 | ("\n%s: ce_send_cnt = %d, TX_comp_cnt = %d\n", |
| 107 | __func__, target->ce_send_cnt, target->TX_comp_cnt)); |
| 108 | } |
| 109 | |
| 110 | void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle, int *credits) |
| 111 | { |
| 112 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 113 | HTC_ENDPOINT *pEndpoint; |
| 114 | int i; |
| 115 | |
| 116 | if (!credits || !target) { |
| 117 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: invalid args", __func__)); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | *credits = 0; |
| 122 | LOCK_HTC_TX(target); |
| 123 | for (i = 0; i < ENDPOINT_MAX; i++) { |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 124 | pEndpoint = &target->endpoint[i]; |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 125 | if (pEndpoint->service_id == WMI_CONTROL_SVC) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 126 | *credits = pEndpoint->TxCredits; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | UNLOCK_HTC_TX(target); |
| 131 | } |
| 132 | |
| 133 | static INLINE void restore_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket) |
| 134 | { |
| 135 | if (pPacket->PktInfo.AsTx.Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) { |
| 136 | cdf_nbuf_t netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 137 | cdf_nbuf_unmap(target->osdev, netbuf, CDF_DMA_TO_DEVICE); |
| 138 | cdf_nbuf_pull_head(netbuf, sizeof(HTC_FRAME_HDR)); |
| 139 | pPacket->PktInfo.AsTx.Flags &= ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF; |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | |
| 144 | static void do_send_completion(HTC_ENDPOINT *pEndpoint, |
| 145 | HTC_PACKET_QUEUE *pQueueToIndicate) |
| 146 | { |
| 147 | do { |
| 148 | |
| 149 | if (HTC_QUEUE_EMPTY(pQueueToIndicate)) { |
| 150 | /* nothing to indicate */ |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | if (pEndpoint->EpCallBacks.EpTxCompleteMultiple != NULL) { |
| 155 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 156 | (" HTC calling ep %d, send complete multiple callback (%d pkts) \n", |
| 157 | pEndpoint->Id, |
| 158 | HTC_PACKET_QUEUE_DEPTH |
| 159 | (pQueueToIndicate))); |
| 160 | /* a multiple send complete handler is being used, pass the queue to the handler */ |
| 161 | pEndpoint->EpCallBacks.EpTxCompleteMultiple(pEndpoint-> |
| 162 | EpCallBacks. |
| 163 | pContext, |
| 164 | pQueueToIndicate); |
| 165 | /* all packets are now owned by the callback, reset queue to be safe */ |
| 166 | INIT_HTC_PACKET_QUEUE(pQueueToIndicate); |
| 167 | } else { |
| 168 | HTC_PACKET *pPacket; |
| 169 | /* using legacy EpTxComplete */ |
| 170 | do { |
| 171 | pPacket = htc_packet_dequeue(pQueueToIndicate); |
| 172 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 173 | (" HTC calling ep %d send complete callback on packet %p \n", |
| 174 | pEndpoint->Id, pPacket)); |
| 175 | pEndpoint->EpCallBacks.EpTxComplete(pEndpoint-> |
| 176 | EpCallBacks. |
| 177 | pContext, |
| 178 | pPacket); |
| 179 | } while (!HTC_QUEUE_EMPTY(pQueueToIndicate)); |
| 180 | } |
| 181 | |
| 182 | } while (false); |
| 183 | |
| 184 | } |
| 185 | |
| 186 | static void send_packet_completion(HTC_TARGET *target, HTC_PACKET *pPacket) |
| 187 | { |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 188 | HTC_ENDPOINT *pEndpoint = &target->endpoint[pPacket->Endpoint]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 189 | HTC_PACKET_QUEUE container; |
| 190 | |
| 191 | restore_tx_packet(target, pPacket); |
| 192 | INIT_HTC_PACKET_QUEUE_AND_ADD(&container, pPacket); |
| 193 | |
| 194 | /* do completion */ |
| 195 | do_send_completion(pEndpoint, &container); |
| 196 | } |
| 197 | |
| 198 | void htc_send_complete_check_cleanup(void *context) |
| 199 | { |
| 200 | HTC_ENDPOINT *pEndpoint = (HTC_ENDPOINT *) context; |
| 201 | htc_send_complete_check(pEndpoint, 1); |
| 202 | } |
| 203 | |
| 204 | HTC_PACKET *allocate_htc_bundle_packet(HTC_TARGET *target) |
| 205 | { |
| 206 | HTC_PACKET *pPacket; |
| 207 | HTC_PACKET_QUEUE *pQueueSave; |
| 208 | cdf_nbuf_t netbuf; |
| 209 | LOCK_HTC_TX(target); |
| 210 | if (NULL == target->pBundleFreeList) { |
| 211 | UNLOCK_HTC_TX(target); |
| 212 | netbuf = cdf_nbuf_alloc(NULL, |
| 213 | target->MaxMsgsPerHTCBundle * |
| 214 | target->TargetCreditSize, 0, 4, false); |
| 215 | AR_DEBUG_ASSERT(netbuf); |
| 216 | if (!netbuf) { |
| 217 | return NULL; |
| 218 | } |
| 219 | pPacket = cdf_mem_malloc(sizeof(HTC_PACKET)); |
| 220 | AR_DEBUG_ASSERT(pPacket); |
| 221 | if (!pPacket) { |
| 222 | cdf_nbuf_free(netbuf); |
| 223 | return NULL; |
| 224 | } |
| 225 | pQueueSave = cdf_mem_malloc(sizeof(HTC_PACKET_QUEUE)); |
| 226 | AR_DEBUG_ASSERT(pQueueSave); |
| 227 | if (!pQueueSave) { |
| 228 | cdf_nbuf_free(netbuf); |
| 229 | cdf_mem_free(pPacket); |
| 230 | return NULL; |
| 231 | } |
| 232 | INIT_HTC_PACKET_QUEUE(pQueueSave); |
| 233 | pPacket->pContext = pQueueSave; |
| 234 | SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf); |
| 235 | pPacket->pBuffer = cdf_nbuf_data(netbuf); |
| 236 | pPacket->BufferLength = cdf_nbuf_len(netbuf); |
| 237 | |
| 238 | /* store the original head room so that we can restore this when we "free" the packet */ |
| 239 | /* free packet puts the packet back on the free list */ |
| 240 | pPacket->netbufOrigHeadRoom = cdf_nbuf_headroom(netbuf); |
| 241 | return pPacket; |
| 242 | } |
| 243 | /* already done malloc - restore from free list */ |
| 244 | pPacket = target->pBundleFreeList; |
| 245 | AR_DEBUG_ASSERT(pPacket); |
| 246 | if (!pPacket) { |
| 247 | UNLOCK_HTC_TX(target); |
| 248 | return NULL; |
| 249 | } |
| 250 | target->pBundleFreeList = (HTC_PACKET *) pPacket->ListLink.pNext; |
| 251 | UNLOCK_HTC_TX(target); |
| 252 | pPacket->ListLink.pNext = NULL; |
| 253 | |
| 254 | return pPacket; |
| 255 | } |
| 256 | |
| 257 | void free_htc_bundle_packet(HTC_TARGET *target, HTC_PACKET *pPacket) |
| 258 | { |
| 259 | A_UINT32 curentHeadRoom; |
| 260 | cdf_nbuf_t netbuf; |
| 261 | HTC_PACKET_QUEUE *pQueueSave; |
| 262 | |
| 263 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 264 | AR_DEBUG_ASSERT(netbuf); |
| 265 | if (!netbuf) { |
| 266 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("\n%s: Invalid netbuf in HTC " |
| 267 | "Packet\n", __func__)); |
| 268 | return; |
| 269 | } |
| 270 | /* HIF adds data to the headroom section of the nbuf, restore the original */ |
| 271 | /* size. If this is not done, headroom keeps shrinking with every HIF send */ |
| 272 | /* and eventually HIF ends up doing another malloc big enough to store the */ |
| 273 | /* data + its header */ |
| 274 | |
| 275 | curentHeadRoom = cdf_nbuf_headroom(netbuf); |
| 276 | cdf_nbuf_pull_head(netbuf, |
| 277 | pPacket->netbufOrigHeadRoom - curentHeadRoom); |
| 278 | cdf_nbuf_trim_tail(netbuf, cdf_nbuf_len(netbuf)); |
| 279 | |
| 280 | /* restore the pBuffer pointer. HIF changes this */ |
| 281 | pPacket->pBuffer = cdf_nbuf_data(netbuf); |
| 282 | pPacket->BufferLength = cdf_nbuf_len(netbuf); |
| 283 | |
| 284 | /* restore queue */ |
| 285 | pQueueSave = (HTC_PACKET_QUEUE *) pPacket->pContext; |
| 286 | AR_DEBUG_ASSERT(pQueueSave); |
| 287 | |
| 288 | INIT_HTC_PACKET_QUEUE(pQueueSave); |
| 289 | |
| 290 | LOCK_HTC_TX(target); |
| 291 | if (target->pBundleFreeList == NULL) { |
| 292 | target->pBundleFreeList = pPacket; |
| 293 | pPacket->ListLink.pNext = NULL; |
| 294 | } else { |
| 295 | pPacket->ListLink.pNext = (DL_LIST *) target->pBundleFreeList; |
| 296 | target->pBundleFreeList = pPacket; |
| 297 | } |
| 298 | UNLOCK_HTC_TX(target); |
| 299 | } |
| 300 | |
| 301 | #if defined(HIF_USB) || defined(HIF_SDIO) |
| 302 | #ifdef ENABLE_BUNDLE_TX |
| 303 | static A_STATUS htc_send_bundled_netbuf(HTC_TARGET *target, |
| 304 | HTC_ENDPOINT *pEndpoint, |
| 305 | unsigned char *pBundleBuffer, |
| 306 | HTC_PACKET *pPacketTx) |
| 307 | { |
| 308 | cdf_size_t data_len; |
| 309 | A_STATUS status; |
| 310 | cdf_nbuf_t bundleBuf; |
| 311 | uint32_t data_attr = 0; |
| 312 | |
| 313 | bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx); |
| 314 | data_len = pBundleBuffer - cdf_nbuf_data(bundleBuf); |
| 315 | cdf_nbuf_put_tail(bundleBuf, data_len); |
| 316 | SET_HTC_PACKET_INFO_TX(pPacketTx, |
| 317 | target, |
| 318 | pBundleBuffer, |
| 319 | data_len, |
| 320 | pEndpoint->Id, HTC_TX_PACKET_TAG_BUNDLED); |
| 321 | LOCK_HTC_TX(target); |
| 322 | HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacketTx); |
| 323 | UNLOCK_HTC_TX(target); |
| 324 | #if DEBUG_BUNDLE |
| 325 | cdf_print(" Send bundle EP%d buffer size:0x%x, total:0x%x, count:%d.\n", |
| 326 | pEndpoint->Id, |
| 327 | pEndpoint->TxCreditSize, |
| 328 | data_len, data_len / pEndpoint->TxCreditSize); |
| 329 | #endif |
| 330 | status = hif_send_head(target->hif_dev, |
| 331 | pEndpoint->UL_PipeID, |
| 332 | pEndpoint->Id, data_len, bundleBuf, data_attr); |
| 333 | if (status != A_OK) { |
| 334 | cdf_print("%s:hif_send_head failed(len=%d).\n", __FUNCTION__, |
| 335 | data_len); |
| 336 | } |
| 337 | return status; |
| 338 | } |
| 339 | |
| 340 | static void htc_issue_packets_bundle(HTC_TARGET *target, |
| 341 | HTC_ENDPOINT *pEndpoint, |
| 342 | HTC_PACKET_QUEUE *pPktQueue) |
| 343 | { |
| 344 | int i, frag_count, nbytes; |
| 345 | cdf_nbuf_t netbuf, bundleBuf; |
| 346 | unsigned char *pBundleBuffer = NULL; |
| 347 | HTC_PACKET *pPacket = NULL, *pPacketTx = NULL; |
| 348 | HTC_FRAME_HDR *pHtcHdr; |
| 349 | int creditPad, creditRemainder, transferLength, bundlesSpaceRemaining = |
| 350 | 0; |
| 351 | HTC_PACKET_QUEUE *pQueueSave = NULL; |
| 352 | |
| 353 | bundlesSpaceRemaining = |
| 354 | target->MaxMsgsPerHTCBundle * pEndpoint->TxCreditSize; |
| 355 | pPacketTx = allocate_htc_bundle_packet(target); |
| 356 | if (!pPacketTx) { |
| 357 | /* good time to panic */ |
| 358 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 359 | ("allocate_htc_bundle_packet failed \n")); |
| 360 | AR_DEBUG_ASSERT(false); |
| 361 | return; |
| 362 | } |
| 363 | bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx); |
| 364 | pBundleBuffer = cdf_nbuf_data(bundleBuf); |
| 365 | pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext; |
| 366 | while (1) { |
| 367 | pPacket = htc_packet_dequeue(pPktQueue); |
| 368 | if (pPacket == NULL) { |
| 369 | break; |
| 370 | } |
| 371 | creditPad = 0; |
| 372 | transferLength = pPacket->ActualLength + HTC_HDR_LENGTH; |
| 373 | creditRemainder = transferLength % pEndpoint->TxCreditSize; |
| 374 | if (creditRemainder != 0) { |
| 375 | if (transferLength < pEndpoint->TxCreditSize) { |
| 376 | creditPad = |
| 377 | pEndpoint->TxCreditSize - transferLength; |
| 378 | } else { |
| 379 | creditPad = creditRemainder; |
| 380 | } |
| 381 | transferLength += creditPad; |
| 382 | } |
| 383 | |
| 384 | if (bundlesSpaceRemaining < transferLength) { |
| 385 | /* send out previous buffer */ |
| 386 | htc_send_bundled_netbuf(target, pEndpoint, pBundleBuffer, |
| 387 | pPacketTx); |
| 388 | if (HTC_PACKET_QUEUE_DEPTH(pPktQueue) < |
| 389 | HTC_MIN_MSG_PER_BUNDLE) { |
| 390 | return; |
| 391 | } |
| 392 | bundlesSpaceRemaining = |
| 393 | target->MaxMsgsPerHTCBundle * |
| 394 | pEndpoint->TxCreditSize; |
| 395 | pPacketTx = allocate_htc_bundle_packet(target); |
| 396 | if (!pPacketTx) { |
| 397 | /* good time to panic */ |
| 398 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 399 | ("allocate_htc_bundle_packet failed \n")); |
| 400 | AR_DEBUG_ASSERT(false); |
| 401 | return; |
| 402 | } |
| 403 | bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx); |
| 404 | pBundleBuffer = cdf_nbuf_data(bundleBuf); |
| 405 | pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext; |
| 406 | } |
| 407 | |
| 408 | bundlesSpaceRemaining -= transferLength; |
| 409 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 410 | pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0); |
| 411 | HTC_WRITE32(pHtcHdr, |
| 412 | SM(pPacket->ActualLength, |
| 413 | HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->PktInfo. |
| 414 | AsTx. |
| 415 | SendFlags | |
| 416 | HTC_FLAGS_SEND_BUNDLE, |
| 417 | HTC_FRAME_HDR_FLAGS) |
| 418 | | SM(pPacket->Endpoint, HTC_FRAME_HDR_ENDPOINTID)); |
| 419 | HTC_WRITE32((A_UINT32 *) pHtcHdr + 1, |
| 420 | SM(pPacket->PktInfo.AsTx.SeqNo, |
| 421 | HTC_FRAME_HDR_CONTROLBYTES1) | SM(creditPad, |
| 422 | HTC_FRAME_HDR_RESERVED)); |
| 423 | pHtcHdr->reserved = creditPad; |
| 424 | frag_count = cdf_nbuf_get_num_frags(netbuf); |
| 425 | nbytes = pPacket->ActualLength + HTC_HDR_LENGTH; |
| 426 | for (i = 0; i < frag_count && nbytes > 0; i++) { |
| 427 | int frag_len = cdf_nbuf_get_frag_len(netbuf, i); |
| 428 | unsigned char *frag_addr = |
| 429 | cdf_nbuf_get_frag_vaddr(netbuf, i); |
| 430 | if (frag_len > nbytes) { |
| 431 | frag_len = nbytes; |
| 432 | } |
| 433 | A_MEMCPY(pBundleBuffer, frag_addr, frag_len); |
| 434 | nbytes -= frag_len; |
| 435 | pBundleBuffer += frag_len; |
| 436 | } |
| 437 | HTC_PACKET_ENQUEUE(pQueueSave, pPacket); |
| 438 | pBundleBuffer += creditPad; |
| 439 | } |
| 440 | if (pBundleBuffer != cdf_nbuf_data(bundleBuf)) { |
| 441 | /* send out remaining buffer */ |
| 442 | htc_send_bundled_netbuf(target, pEndpoint, pBundleBuffer, |
| 443 | pPacketTx); |
| 444 | } else { |
| 445 | free_htc_bundle_packet(target, pPacketTx); |
| 446 | } |
| 447 | } |
| 448 | #endif /* ENABLE_BUNDLE_TX */ |
| 449 | #endif |
| 450 | |
| 451 | static A_STATUS htc_issue_packets(HTC_TARGET *target, |
| 452 | HTC_ENDPOINT *pEndpoint, |
| 453 | HTC_PACKET_QUEUE *pPktQueue) |
| 454 | { |
| 455 | A_STATUS status = A_OK; |
| 456 | cdf_nbuf_t netbuf; |
| 457 | HTC_PACKET *pPacket = NULL; |
| 458 | uint16_t payloadLen; |
| 459 | HTC_FRAME_HDR *pHtcHdr; |
| 460 | uint32_t data_attr = 0; |
| 461 | |
| 462 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 463 | ("+htc_issue_packets: Queue: %p, Pkts %d \n", pPktQueue, |
| 464 | HTC_PACKET_QUEUE_DEPTH(pPktQueue))); |
| 465 | while (true) { |
| 466 | #if defined(HIF_USB) || defined(HIF_SDIO) |
| 467 | #ifdef ENABLE_BUNDLE_TX |
| 468 | if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint) && |
| 469 | HTC_ENABLE_BUNDLE(target) && |
| 470 | HTC_PACKET_QUEUE_DEPTH(pPktQueue) >= |
| 471 | HTC_MIN_MSG_PER_BUNDLE) { |
| 472 | htc_issue_packets_bundle(target, pEndpoint, pPktQueue); |
| 473 | } |
| 474 | #endif |
| 475 | #endif |
| 476 | /* if not bundling or there was a packet that could not be placed in a bundle, |
| 477 | * and send it by normal way |
| 478 | */ |
| 479 | pPacket = htc_packet_dequeue(pPktQueue); |
| 480 | if (NULL == pPacket) { |
| 481 | /* local queue is fully drained */ |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 486 | AR_DEBUG_ASSERT(netbuf); |
| 487 | /* Non-credit enabled endpoints have been mapped and setup by now, |
| 488 | * so no need to revisit the HTC headers |
| 489 | */ |
| 490 | if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 491 | |
| 492 | payloadLen = pPacket->ActualLength; |
| 493 | /* setup HTC frame header */ |
| 494 | |
| 495 | pHtcHdr = |
| 496 | (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, |
| 497 | 0); |
| 498 | AR_DEBUG_ASSERT(pHtcHdr); |
| 499 | |
| 500 | HTC_WRITE32(pHtcHdr, |
| 501 | SM(payloadLen, |
| 502 | HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket-> |
| 503 | PktInfo. |
| 504 | AsTx. |
| 505 | SendFlags, |
| 506 | HTC_FRAME_HDR_FLAGS) |
| 507 | | SM(pPacket->Endpoint, |
| 508 | HTC_FRAME_HDR_ENDPOINTID)); |
| 509 | HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1, |
| 510 | SM(pPacket->PktInfo.AsTx.SeqNo, |
| 511 | HTC_FRAME_HDR_CONTROLBYTES1)); |
| 512 | |
| 513 | /* |
| 514 | * Now that the HTC frame header has been added, the netbuf can be |
| 515 | * mapped. This only applies to non-data frames, since data frames |
| 516 | * were already mapped as they entered into the driver. |
| 517 | * Check the "FIXUP_NETBUF" flag to see whether this is a data netbuf |
| 518 | * that is already mapped, or a non-data netbuf that needs to be |
| 519 | * mapped. |
| 520 | */ |
| 521 | if (pPacket->PktInfo.AsTx. |
| 522 | Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) { |
| 523 | cdf_nbuf_map(target->osdev, |
| 524 | GET_HTC_PACKET_NET_BUF_CONTEXT |
| 525 | (pPacket), CDF_DMA_TO_DEVICE); |
| 526 | } |
| 527 | } |
| 528 | LOCK_HTC_TX(target); |
| 529 | /* store in look up queue to match completions */ |
| 530 | HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket); |
| 531 | INC_HTC_EP_STAT(pEndpoint, TxIssued, 1); |
| 532 | pEndpoint->ul_outstanding_cnt++; |
| 533 | UNLOCK_HTC_TX(target); |
| 534 | |
Houston Hoffman | 3d0cda8 | 2015-12-03 13:25:05 -0800 | [diff] [blame] | 535 | hif_send_complete_check(target->hif_dev, pEndpoint->UL_PipeID, false); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 536 | status = hif_send_head(target->hif_dev, |
| 537 | pEndpoint->UL_PipeID, pEndpoint->Id, |
| 538 | HTC_HDR_LENGTH + pPacket->ActualLength, |
| 539 | netbuf, data_attr); |
| 540 | #if DEBUG_BUNDLE |
| 541 | cdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n", |
| 542 | pEndpoint->Id, |
| 543 | pEndpoint->TxCreditSize, |
| 544 | HTC_HDR_LENGTH + pPacket->ActualLength); |
| 545 | #endif |
| 546 | |
| 547 | target->ce_send_cnt++; |
| 548 | |
| 549 | if (cdf_unlikely(A_FAILED(status))) { |
| 550 | if (status != A_NO_RESOURCE) { |
| 551 | /* TODO : if more than 1 endpoint maps to the same PipeID it is possible |
| 552 | * to run out of resources in the HIF layer. Don't emit the error */ |
| 553 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 554 | ("hif_send Failed status:%d \n", |
| 555 | status)); |
| 556 | } |
| 557 | LOCK_HTC_TX(target); |
| 558 | target->ce_send_cnt--; |
| 559 | pEndpoint->ul_outstanding_cnt--; |
| 560 | HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket); |
| 561 | /* reclaim credits */ |
| 562 | #if defined(HIF_USB) |
| 563 | if (pEndpoint->Id >= ENDPOINT_2 |
| 564 | && pEndpoint->Id <= ENDPOINT_5) |
| 565 | target->avail_tx_credits += |
| 566 | pPacket->PktInfo.AsTx.CreditsUsed; |
| 567 | else |
| 568 | pEndpoint->TxCredits += |
| 569 | pPacket->PktInfo.AsTx.CreditsUsed; |
| 570 | #else |
| 571 | pEndpoint->TxCredits += |
| 572 | pPacket->PktInfo.AsTx.CreditsUsed; |
| 573 | #endif |
| 574 | /* put it back into the callers queue */ |
| 575 | HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket); |
| 576 | UNLOCK_HTC_TX(target); |
| 577 | break; |
| 578 | } |
| 579 | |
| 580 | } |
| 581 | if (cdf_unlikely(A_FAILED(status))) { |
| 582 | #if defined(HIF_USB) |
| 583 | if (pEndpoint->Id >= ENDPOINT_2 && pEndpoint->Id <= ENDPOINT_5) |
| 584 | target->avail_tx_credits += |
| 585 | pPacket->PktInfo.AsTx.CreditsUsed; |
| 586 | else |
| 587 | pEndpoint->TxCredits += |
| 588 | pPacket->PktInfo.AsTx.CreditsUsed; |
| 589 | #endif |
Manjunathappa Prakash | 3044c6e | 2015-12-04 00:08:58 -0800 | [diff] [blame] | 590 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 591 | ("htc_issue_packets, failed pkt:0x%p status:%d", |
| 592 | pPacket, status)); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets \n")); |
| 596 | |
| 597 | return status; |
| 598 | } |
| 599 | |
| 600 | /* get HTC send packets from the TX queue on an endpoint, based on available credits */ |
| 601 | void get_htc_send_packets_credit_based(HTC_TARGET *target, |
| 602 | HTC_ENDPOINT *pEndpoint, |
| 603 | HTC_PACKET_QUEUE *pQueue) |
| 604 | { |
| 605 | int creditsRequired; |
| 606 | int remainder; |
| 607 | A_UINT8 sendFlags; |
| 608 | HTC_PACKET *pPacket; |
| 609 | unsigned int transferLength; |
| 610 | |
| 611 | /****** NOTE : the TX lock is held when this function is called *****************/ |
| 612 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+get_htc_send_packets_credit_based \n")); |
| 613 | |
| 614 | /* loop until we can grab as many packets out of the queue as we can */ |
| 615 | while (true) { |
| 616 | |
| 617 | sendFlags = 0; |
| 618 | /* get packet at head, but don't remove it */ |
| 619 | pPacket = htc_get_pkt_at_head(&pEndpoint->TxQueue); |
| 620 | if (pPacket == NULL) { |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 625 | (" Got head packet:%p , Queue Depth: %d\n", |
| 626 | pPacket, |
| 627 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue))); |
| 628 | |
| 629 | transferLength = pPacket->ActualLength + HTC_HDR_LENGTH; |
| 630 | |
| 631 | if (transferLength <= pEndpoint->TxCreditSize) { |
| 632 | creditsRequired = 1; |
| 633 | } else { |
| 634 | /* figure out how many credits this message requires */ |
| 635 | creditsRequired = |
| 636 | transferLength / pEndpoint->TxCreditSize; |
| 637 | remainder = transferLength % pEndpoint->TxCreditSize; |
| 638 | |
| 639 | if (remainder) { |
| 640 | creditsRequired++; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 645 | (" Credits Required:%d Got:%d\n", |
| 646 | creditsRequired, pEndpoint->TxCredits)); |
| 647 | |
| 648 | if (pEndpoint->Id == ENDPOINT_0) { |
| 649 | /* endpoint 0 is special, it always has a credit and does not require credit based |
| 650 | * flow control */ |
| 651 | creditsRequired = 0; |
| 652 | #if defined(HIF_USB) |
| 653 | } else if (pEndpoint->Id >= ENDPOINT_2 |
| 654 | && pEndpoint->Id <= ENDPOINT_5) { |
| 655 | if (target->avail_tx_credits < creditsRequired) |
| 656 | break; |
| 657 | |
| 658 | target->avail_tx_credits -= creditsRequired; |
| 659 | |
| 660 | if (target->avail_tx_credits < 9) { |
| 661 | /* tell the target we need credits ASAP! */ |
| 662 | sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE; |
| 663 | INC_HTC_EP_STAT(pEndpoint, |
| 664 | TxCreditLowIndications, 1); |
| 665 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 666 | (" Host Needs Credits \n")); |
| 667 | } |
| 668 | #endif |
| 669 | } else { |
| 670 | |
| 671 | if (pEndpoint->TxCredits < creditsRequired) { |
| 672 | #if DEBUG_CREDIT |
| 673 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 674 | (" EP%d, No Credit now. %d < %d\n", |
| 675 | pEndpoint->Id, |
| 676 | pEndpoint->TxCredits, |
| 677 | creditsRequired)); |
| 678 | #endif |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | pEndpoint->TxCredits -= creditsRequired; |
| 683 | INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed, |
| 684 | creditsRequired); |
| 685 | |
| 686 | /* check if we need credits back from the target */ |
| 687 | if (pEndpoint->TxCredits <= |
| 688 | pEndpoint->TxCreditsPerMaxMsg) { |
| 689 | /* tell the target we need credits ASAP! */ |
| 690 | sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE; |
| 691 | |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 692 | if (pEndpoint->service_id == WMI_CONTROL_SVC) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 693 | LOCK_HTC_CREDIT(target); |
| 694 | htc_credit_record(HTC_REQUEST_CREDIT, |
| 695 | pEndpoint->TxCredits, |
| 696 | HTC_PACKET_QUEUE_DEPTH |
| 697 | (&pEndpoint-> |
| 698 | TxQueue)); |
| 699 | UNLOCK_HTC_CREDIT(target); |
| 700 | } |
| 701 | |
| 702 | INC_HTC_EP_STAT(pEndpoint, |
| 703 | TxCreditLowIndications, 1); |
| 704 | #if DEBUG_CREDIT |
| 705 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 706 | (" EP%d Needs Credits\n", |
| 707 | pEndpoint->Id)); |
| 708 | #endif |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | /* now we can fully dequeue */ |
| 713 | pPacket = htc_packet_dequeue(&pEndpoint->TxQueue); |
| 714 | if (pPacket) { |
| 715 | /* save the number of credits this packet consumed */ |
| 716 | pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired; |
| 717 | /* save send flags */ |
| 718 | pPacket->PktInfo.AsTx.SendFlags = sendFlags; |
| 719 | |
| 720 | /* queue this packet into the caller's queue */ |
| 721 | HTC_PACKET_ENQUEUE(pQueue, pPacket); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets_credit_based \n")); |
| 726 | |
| 727 | } |
| 728 | |
| 729 | void get_htc_send_packets(HTC_TARGET *target, |
| 730 | HTC_ENDPOINT *pEndpoint, |
| 731 | HTC_PACKET_QUEUE *pQueue, int Resources) |
| 732 | { |
| 733 | |
| 734 | HTC_PACKET *pPacket; |
| 735 | |
| 736 | /****** NOTE : the TX lock is held when this function is called *****************/ |
| 737 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 738 | ("+get_htc_send_packets %d resources\n", Resources)); |
| 739 | |
| 740 | /* loop until we can grab as many packets out of the queue as we can */ |
| 741 | while (Resources > 0) { |
| 742 | int num_frags; |
| 743 | |
| 744 | pPacket = htc_packet_dequeue(&pEndpoint->TxQueue); |
| 745 | if (pPacket == NULL) { |
| 746 | break; |
| 747 | } |
| 748 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 749 | (" Got packet:%p , New Queue Depth: %d\n", |
| 750 | pPacket, |
| 751 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue))); |
| 752 | /* For non-credit path the sequence number is already embedded |
| 753 | * in the constructed HTC header |
| 754 | */ |
| 755 | #if 0 |
| 756 | pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo; |
| 757 | pEndpoint->SeqNo++; |
| 758 | #endif |
| 759 | pPacket->PktInfo.AsTx.SendFlags = 0; |
| 760 | pPacket->PktInfo.AsTx.CreditsUsed = 0; |
| 761 | /* queue this packet into the caller's queue */ |
| 762 | HTC_PACKET_ENQUEUE(pQueue, pPacket); |
| 763 | |
| 764 | /* |
| 765 | * FIX THIS: |
| 766 | * For now, avoid calling cdf_nbuf_get_num_frags before calling |
| 767 | * cdf_nbuf_map, because the MacOS version of cdf_nbuf_t doesn't |
| 768 | * support cdf_nbuf_get_num_frags until after cdf_nbuf_map has |
| 769 | * been done. |
| 770 | * Assume that the non-data netbufs, i.e. the WMI message netbufs, |
| 771 | * consist of a single fragment. |
| 772 | */ |
| 773 | num_frags = |
| 774 | (pPacket->PktInfo.AsTx. |
| 775 | Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1 |
| 776 | /* WMI messages are in a single-fragment network buffer */ : |
| 777 | cdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT |
| 778 | (pPacket)); |
| 779 | Resources -= num_frags; |
| 780 | } |
| 781 | |
| 782 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets \n")); |
| 783 | |
| 784 | } |
| 785 | |
| 786 | static HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target, |
| 787 | HTC_ENDPOINT *pEndpoint, |
| 788 | HTC_PACKET_QUEUE *pCallersSendQueue) |
| 789 | { |
| 790 | HTC_PACKET_QUEUE sendQueue; /* temp queue to hold packets at various stages */ |
| 791 | HTC_PACKET *pPacket; |
| 792 | int tx_resources; |
| 793 | int overflow; |
| 794 | HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK; |
| 795 | |
| 796 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%p Depth:%d)\n", |
| 797 | pCallersSendQueue, |
| 798 | (pCallersSendQueue == |
| 799 | NULL) ? 0 : |
| 800 | HTC_PACKET_QUEUE_DEPTH |
| 801 | (pCallersSendQueue))); |
| 802 | |
| 803 | /* init the local send queue */ |
| 804 | INIT_HTC_PACKET_QUEUE(&sendQueue); |
| 805 | |
| 806 | do { |
| 807 | |
| 808 | if (NULL == pCallersSendQueue) { |
| 809 | /* caller didn't provide a queue, just wants us to check queues and send */ |
| 810 | break; |
| 811 | } |
| 812 | |
| 813 | if (HTC_QUEUE_EMPTY(pCallersSendQueue)) { |
| 814 | /* empty queue */ |
| 815 | OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, |
| 816 | HTC_PKT_Q_EMPTY); |
| 817 | result = HTC_SEND_QUEUE_DROP; |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >= |
| 822 | pEndpoint->MaxTxQueueDepth) { |
| 823 | /* we've already overflowed */ |
| 824 | overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue); |
| 825 | } else { |
| 826 | /* figure out how much we will overflow by */ |
| 827 | overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); |
| 828 | overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue); |
| 829 | /* figure out how much we will overflow the TX queue by */ |
| 830 | overflow -= pEndpoint->MaxTxQueueDepth; |
| 831 | } |
| 832 | |
| 833 | /* if overflow is negative or zero, we are okay */ |
| 834 | if (overflow > 0) { |
| 835 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 836 | (" Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d \n", |
| 837 | pEndpoint->Id, overflow, |
| 838 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint-> |
| 839 | TxQueue), |
| 840 | pEndpoint->MaxTxQueueDepth)); |
| 841 | } |
| 842 | if ((overflow <= 0) |
| 843 | || (pEndpoint->EpCallBacks.EpSendFull == NULL)) { |
| 844 | /* all packets will fit or caller did not provide send full indication handler |
| 845 | * -- just move all of them to the local sendQueue object */ |
| 846 | HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue, |
| 847 | pCallersSendQueue); |
| 848 | } else { |
| 849 | int i; |
| 850 | int goodPkts = |
| 851 | HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) - |
| 852 | overflow; |
| 853 | |
| 854 | A_ASSERT(goodPkts >= 0); |
| 855 | /* we have overflowed, and a callback is provided */ |
| 856 | /* dequeue all non-overflow packets into the sendqueue */ |
| 857 | for (i = 0; i < goodPkts; i++) { |
| 858 | /* pop off caller's queue */ |
| 859 | pPacket = htc_packet_dequeue(pCallersSendQueue); |
| 860 | A_ASSERT(pPacket != NULL); |
| 861 | /* insert into local queue */ |
| 862 | HTC_PACKET_ENQUEUE(&sendQueue, pPacket); |
| 863 | } |
| 864 | |
| 865 | /* the caller's queue has all the packets that won't fit */ |
| 866 | /* walk through the caller's queue and indicate each one to the send full handler */ |
| 867 | ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue-> |
| 868 | QueueHead, pPacket, |
| 869 | HTC_PACKET, ListLink) { |
| 870 | |
| 871 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 872 | (" Indicating overflowed TX packet: %p \n", |
| 873 | pPacket)); |
| 874 | /* |
| 875 | * Remove headroom reserved for HTC_FRAME_HDR before giving |
| 876 | * the packet back to the user via the EpSendFull callback. |
| 877 | */ |
| 878 | restore_tx_packet(target, pPacket); |
| 879 | |
| 880 | if (pEndpoint->EpCallBacks. |
| 881 | EpSendFull(pEndpoint->EpCallBacks.pContext, |
| 882 | pPacket) == HTC_SEND_FULL_DROP) { |
| 883 | /* callback wants the packet dropped */ |
| 884 | INC_HTC_EP_STAT(pEndpoint, TxDropped, |
| 885 | 1); |
| 886 | /* leave this one in the caller's queue for cleanup */ |
| 887 | } else { |
| 888 | /* callback wants to keep this packet, remove from caller's queue */ |
| 889 | HTC_PACKET_REMOVE(pCallersSendQueue, |
| 890 | pPacket); |
| 891 | /* put it in the send queue */ |
| 892 | /* add HTC_FRAME_HDR space reservation again */ |
| 893 | cdf_nbuf_push_head |
| 894 | (GET_HTC_PACKET_NET_BUF_CONTEXT |
| 895 | (pPacket), sizeof(HTC_FRAME_HDR)); |
| 896 | |
| 897 | HTC_PACKET_ENQUEUE(&sendQueue, pPacket); |
| 898 | } |
| 899 | |
| 900 | } |
| 901 | ITERATE_END; |
| 902 | |
| 903 | if (HTC_QUEUE_EMPTY(&sendQueue)) { |
| 904 | /* no packets made it in, caller will cleanup */ |
| 905 | OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, |
| 906 | HTC_SEND_Q_EMPTY); |
| 907 | result = HTC_SEND_QUEUE_DROP; |
| 908 | break; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | } while (false); |
| 913 | |
| 914 | if (result != HTC_SEND_QUEUE_OK) { |
| 915 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n")); |
| 916 | return result; |
| 917 | } |
| 918 | |
| 919 | if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 920 | tx_resources = |
| 921 | hif_get_free_queue_number(target->hif_dev, |
| 922 | pEndpoint->UL_PipeID); |
| 923 | } else { |
| 924 | tx_resources = 0; |
| 925 | } |
| 926 | |
| 927 | LOCK_HTC_TX(target); |
| 928 | |
| 929 | if (!HTC_QUEUE_EMPTY(&sendQueue)) { |
| 930 | /* transfer packets to tail */ |
| 931 | HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue, |
| 932 | &sendQueue); |
| 933 | A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue)); |
| 934 | INIT_HTC_PACKET_QUEUE(&sendQueue); |
| 935 | } |
| 936 | |
| 937 | /* increment tx processing count on entry */ |
| 938 | cdf_atomic_inc(&pEndpoint->TxProcessCount); |
| 939 | if (cdf_atomic_read(&pEndpoint->TxProcessCount) > 1) { |
| 940 | /* another thread or task is draining the TX queues on this endpoint |
| 941 | * that thread will reset the tx processing count when the queue is drained */ |
| 942 | cdf_atomic_dec(&pEndpoint->TxProcessCount); |
| 943 | UNLOCK_HTC_TX(target); |
| 944 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy) \n")); |
| 945 | return HTC_SEND_QUEUE_OK; |
| 946 | } |
| 947 | |
| 948 | /***** beyond this point only 1 thread may enter ******/ |
| 949 | |
| 950 | /* now drain the endpoint TX queue for transmission as long as we have enough |
| 951 | * transmit resources */ |
| 952 | while (true) { |
| 953 | |
| 954 | if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0) { |
| 955 | break; |
| 956 | } |
| 957 | |
| 958 | if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 959 | #if DEBUG_CREDIT |
| 960 | int cred = pEndpoint->TxCredits; |
| 961 | #endif |
| 962 | /* credit based mechanism provides flow control based on target transmit resource availability, we |
| 963 | * assume that the HIF layer will always have bus resources greater than target transmit resources */ |
| 964 | get_htc_send_packets_credit_based(target, pEndpoint, |
| 965 | &sendQueue); |
| 966 | #if DEBUG_CREDIT |
| 967 | if (ep_debug_mask & (1 << pEndpoint->Id)) { |
| 968 | if (cred - pEndpoint->TxCredits > 0) { |
| 969 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 970 | (" <HTC> Decrease EP%d %d - %d = %d credits.\n", |
| 971 | pEndpoint->Id, cred, |
| 972 | cred - |
| 973 | pEndpoint->TxCredits, |
| 974 | pEndpoint->TxCredits)); |
| 975 | } |
| 976 | } |
| 977 | #endif |
| 978 | } else { |
| 979 | /* get all the packets for this endpoint that we can for this pass */ |
| 980 | get_htc_send_packets(target, pEndpoint, &sendQueue, |
| 981 | tx_resources); |
| 982 | } |
| 983 | |
| 984 | if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) { |
| 985 | /* didn't get any packets due to a lack of resources or TX queue was drained */ |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | UNLOCK_HTC_TX(target); |
| 990 | |
| 991 | /* send what we can */ |
Manjunathappa Prakash | 3044c6e | 2015-12-04 00:08:58 -0800 | [diff] [blame] | 992 | result = htc_issue_packets(target, pEndpoint, &sendQueue); |
| 993 | if (result) { |
| 994 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 995 | ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue", |
| 996 | result)); |
| 997 | HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue, |
| 998 | &sendQueue); |
| 999 | LOCK_HTC_TX(target); |
| 1000 | break; |
| 1001 | } |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1002 | |
| 1003 | if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 1004 | tx_resources = |
| 1005 | hif_get_free_queue_number(target->hif_dev, |
| 1006 | pEndpoint->UL_PipeID); |
| 1007 | } |
| 1008 | |
| 1009 | LOCK_HTC_TX(target); |
| 1010 | |
| 1011 | } |
| 1012 | |
| 1013 | UNLOCK_HTC_TX(target); |
| 1014 | /* done with this endpoint, we can clear the count */ |
| 1015 | cdf_atomic_init(&pEndpoint->TxProcessCount); |
| 1016 | |
| 1017 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n")); |
| 1018 | |
| 1019 | return HTC_SEND_QUEUE_OK; |
| 1020 | } |
| 1021 | |
| 1022 | #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED |
| 1023 | static A_UINT16 htc_send_pkts_sched_check(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID id) |
| 1024 | { |
| 1025 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 1026 | HTC_ENDPOINT *pEndpoint; |
| 1027 | HTC_ENDPOINT_ID eid; |
| 1028 | HTC_PACKET_QUEUE *pTxQueue; |
| 1029 | A_UINT16 resources; |
| 1030 | A_UINT16 acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 }; |
| 1031 | |
| 1032 | if (id < ENDPOINT_2 || id > ENDPOINT_5) { |
| 1033 | return 1; |
| 1034 | } |
| 1035 | |
| 1036 | for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) { |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1037 | pEndpoint = &target->endpoint[eid]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1038 | pTxQueue = &pEndpoint->TxQueue; |
| 1039 | |
| 1040 | if (HTC_QUEUE_EMPTY(pTxQueue)) { |
| 1041 | acQueueStatus[eid - 2] = 1; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | switch (id) { |
| 1046 | case ENDPOINT_2: /* BE */ |
| 1047 | return (acQueueStatus[0] && acQueueStatus[2] |
| 1048 | && acQueueStatus[3]); |
| 1049 | case ENDPOINT_3: /* BK */ |
| 1050 | return (acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2] |
| 1051 | && acQueueStatus[3]); |
| 1052 | case ENDPOINT_4: /* VI */ |
| 1053 | return (acQueueStatus[2] && acQueueStatus[3]); |
| 1054 | case ENDPOINT_5: /* VO */ |
| 1055 | return (acQueueStatus[3]); |
| 1056 | default: |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | } |
| 1061 | |
| 1062 | static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target, |
| 1063 | HTC_PACKET_QUEUE *pPktQueue, |
| 1064 | HTC_ENDPOINT_ID eid) |
| 1065 | { |
| 1066 | HTC_ENDPOINT *pEndpoint; |
| 1067 | HTC_PACKET_QUEUE *pTxQueue; |
| 1068 | HTC_PACKET *pPacket; |
| 1069 | int goodPkts; |
| 1070 | |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1071 | pEndpoint = &target->endpoint[eid]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1072 | pTxQueue = &pEndpoint->TxQueue; |
| 1073 | |
| 1074 | LOCK_HTC_TX(target); |
| 1075 | |
| 1076 | goodPkts = |
| 1077 | pEndpoint->MaxTxQueueDepth - |
| 1078 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue); |
| 1079 | |
| 1080 | if (goodPkts > 0) { |
| 1081 | while (!HTC_QUEUE_EMPTY(pPktQueue)) { |
| 1082 | pPacket = htc_packet_dequeue(pPktQueue); |
| 1083 | HTC_PACKET_ENQUEUE(pTxQueue, pPacket); |
| 1084 | goodPkts--; |
| 1085 | |
| 1086 | if (goodPkts <= 0) { |
| 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) { |
| 1093 | ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket, |
| 1094 | HTC_PACKET, ListLink) { |
| 1095 | |
| 1096 | if (pEndpoint->EpCallBacks. |
| 1097 | EpSendFull(pEndpoint->EpCallBacks.pContext, |
| 1098 | pPacket) == HTC_SEND_FULL_DROP) { |
| 1099 | INC_HTC_EP_STAT(pEndpoint, TxDropped, 1); |
| 1100 | } else { |
| 1101 | HTC_PACKET_REMOVE(pPktQueue, pPacket); |
| 1102 | HTC_PACKET_ENQUEUE(pTxQueue, pPacket); |
| 1103 | } |
| 1104 | } |
| 1105 | ITERATE_END; |
| 1106 | } |
| 1107 | |
| 1108 | UNLOCK_HTC_TX(target); |
| 1109 | |
| 1110 | return A_OK; |
| 1111 | } |
| 1112 | |
| 1113 | #endif |
| 1114 | |
| 1115 | A_STATUS htc_send_pkts_multiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue) |
| 1116 | { |
| 1117 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 1118 | HTC_ENDPOINT *pEndpoint; |
| 1119 | HTC_PACKET *pPacket; |
| 1120 | cdf_nbuf_t netbuf; |
| 1121 | HTC_FRAME_HDR *pHtcHdr; |
| 1122 | |
| 1123 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 1124 | ("+htc_send_pkts_multiple: Queue: %p, Pkts %d \n", |
| 1125 | pPktQueue, HTC_PACKET_QUEUE_DEPTH(pPktQueue))); |
| 1126 | |
| 1127 | /* get packet at head to figure out which endpoint these packets will go into */ |
| 1128 | pPacket = htc_get_pkt_at_head(pPktQueue); |
| 1129 | if (NULL == pPacket) { |
| 1130 | OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL); |
| 1131 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n")); |
| 1132 | return A_EINVAL; |
| 1133 | } |
| 1134 | |
| 1135 | AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX); |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1136 | pEndpoint = &target->endpoint[pPacket->Endpoint]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1137 | |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 1138 | if (!pEndpoint->service_id) { |
| 1139 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n", |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1140 | __func__)); |
| 1141 | return A_EINVAL; |
| 1142 | } |
| 1143 | |
| 1144 | #ifdef HTC_EP_STAT_PROFILING |
| 1145 | LOCK_HTC_TX(target); |
| 1146 | INC_HTC_EP_STAT(pEndpoint, TxPosted, HTC_PACKET_QUEUE_DEPTH(pPktQueue)); |
| 1147 | UNLOCK_HTC_TX(target); |
| 1148 | #endif |
| 1149 | |
| 1150 | /* provide room in each packet's netbuf for the HTC frame header */ |
| 1151 | HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) { |
| 1152 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 1153 | AR_DEBUG_ASSERT(netbuf); |
| 1154 | |
| 1155 | cdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR)); |
| 1156 | /* setup HTC frame header */ |
| 1157 | pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0); |
| 1158 | AR_DEBUG_ASSERT(pHtcHdr); |
| 1159 | HTC_WRITE32(pHtcHdr, |
| 1160 | SM(pPacket->ActualLength, |
| 1161 | HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->Endpoint, |
| 1162 | HTC_FRAME_HDR_ENDPOINTID)); |
| 1163 | |
| 1164 | LOCK_HTC_TX(target); |
| 1165 | |
| 1166 | pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo; |
| 1167 | pEndpoint->SeqNo++; |
| 1168 | |
| 1169 | HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1, |
| 1170 | SM(pPacket->PktInfo.AsTx.SeqNo, |
| 1171 | HTC_FRAME_HDR_CONTROLBYTES1)); |
| 1172 | |
| 1173 | UNLOCK_HTC_TX(target); |
| 1174 | /* |
| 1175 | * Now that the HTC frame header has been added, the netbuf can be |
| 1176 | * mapped. This only applies to non-data frames, since data frames |
| 1177 | * were already mapped as they entered into the driver. |
| 1178 | */ |
| 1179 | cdf_nbuf_map(target->osdev, |
| 1180 | GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket), |
| 1181 | CDF_DMA_TO_DEVICE); |
| 1182 | |
| 1183 | pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF; |
| 1184 | } |
| 1185 | HTC_PACKET_QUEUE_ITERATE_END; |
| 1186 | |
| 1187 | #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED |
| 1188 | if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id)) { |
| 1189 | htc_send_pkts_sched_queue(HTCHandle, pPktQueue, pEndpoint->Id); |
| 1190 | } else { |
| 1191 | htc_try_send(target, pEndpoint, pPktQueue); |
| 1192 | } |
| 1193 | #else |
| 1194 | htc_try_send(target, pEndpoint, pPktQueue); |
| 1195 | #endif |
| 1196 | |
| 1197 | /* do completion on any packets that couldn't get in */ |
| 1198 | if (!HTC_QUEUE_EMPTY(pPktQueue)) { |
| 1199 | |
| 1200 | HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) { |
| 1201 | /* remove the headroom reserved for HTC_FRAME_HDR */ |
| 1202 | restore_tx_packet(target, pPacket); |
| 1203 | |
| 1204 | if (HTC_STOPPING(target)) { |
| 1205 | pPacket->Status = A_ECANCELED; |
| 1206 | } else { |
| 1207 | pPacket->Status = A_NO_RESOURCE; |
| 1208 | } |
| 1209 | } |
| 1210 | HTC_PACKET_QUEUE_ITERATE_END; |
| 1211 | |
| 1212 | do_send_completion(pEndpoint, pPktQueue); |
| 1213 | } |
| 1214 | |
| 1215 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n")); |
| 1216 | |
| 1217 | return A_OK; |
| 1218 | } |
| 1219 | |
| 1220 | /* HTC API - htc_send_pkt */ |
| 1221 | A_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket) |
| 1222 | { |
| 1223 | HTC_PACKET_QUEUE queue; |
| 1224 | |
Karthick S | dc40a35 | 2015-10-14 18:14:15 +0530 | [diff] [blame] | 1225 | if (HTCHandle == NULL || pPacket == NULL) { |
| 1226 | return A_ERROR; |
| 1227 | } |
| 1228 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1229 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 1230 | ("+-htc_send_pkt: Enter endPointId: %d, buffer: %p, length: %d \n", |
| 1231 | pPacket->Endpoint, pPacket->pBuffer, |
| 1232 | pPacket->ActualLength)); |
| 1233 | INIT_HTC_PACKET_QUEUE_AND_ADD(&queue, pPacket); |
| 1234 | return htc_send_pkts_multiple(HTCHandle, &queue); |
| 1235 | } |
| 1236 | |
| 1237 | #ifdef ATH_11AC_TXCOMPACT |
| 1238 | |
| 1239 | A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, cdf_nbuf_t netbuf, int Epid, |
| 1240 | int ActualLength) |
| 1241 | { |
| 1242 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 1243 | HTC_ENDPOINT *pEndpoint; |
| 1244 | HTC_FRAME_HDR *pHtcHdr; |
| 1245 | A_STATUS status = A_OK; |
| 1246 | int tx_resources; |
| 1247 | uint32_t data_attr = 0; |
| 1248 | |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1249 | pEndpoint = &target->endpoint[Epid]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1250 | |
| 1251 | tx_resources = |
| 1252 | hif_get_free_queue_number(target->hif_dev, pEndpoint->UL_PipeID); |
| 1253 | |
| 1254 | if (tx_resources < HTC_DATA_RESOURCE_THRS) { |
| 1255 | if (pEndpoint->ul_is_polled) { |
| 1256 | hif_send_complete_check(pEndpoint->target->hif_dev, |
| 1257 | pEndpoint->UL_PipeID, 1); |
| 1258 | tx_resources = |
| 1259 | hif_get_free_queue_number(target->hif_dev, |
| 1260 | pEndpoint->UL_PipeID); |
| 1261 | } |
| 1262 | if (tx_resources < HTC_DATA_MINDESC_PERPACKET) { |
| 1263 | return A_ERROR; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0); |
| 1268 | AR_DEBUG_ASSERT(pHtcHdr); |
| 1269 | |
| 1270 | data_attr = cdf_nbuf_data_attr_get(netbuf); |
| 1271 | |
| 1272 | HTC_WRITE32(pHtcHdr, SM(ActualLength, HTC_FRAME_HDR_PAYLOADLEN) | |
| 1273 | SM(Epid, HTC_FRAME_HDR_ENDPOINTID)); |
| 1274 | /* |
| 1275 | * If the HIF pipe for the data endpoint is polled rather than |
| 1276 | * interrupt-driven, this is a good point to check whether any |
| 1277 | * data previously sent through the HIF pipe have finished being |
| 1278 | * sent. |
| 1279 | * Since this may result in callbacks to htc_tx_completion_handler, |
| 1280 | * which can take the HTC tx lock, make the hif_send_complete_check |
| 1281 | * call before acquiring the HTC tx lock. |
| 1282 | * Call hif_send_complete_check directly, rather than calling |
| 1283 | * htc_send_complete_check, and call the PollTimerStart separately |
| 1284 | * after calling hif_send_head, so the timer will be started to |
| 1285 | * check for completion of the new outstanding download (in the |
| 1286 | * unexpected event that other polling calls don't catch it). |
| 1287 | */ |
| 1288 | |
| 1289 | LOCK_HTC_TX(target); |
| 1290 | |
| 1291 | HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1, |
| 1292 | SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1)); |
| 1293 | |
| 1294 | pEndpoint->SeqNo++; |
| 1295 | |
| 1296 | NBUF_UPDATE_TX_PKT_COUNT(netbuf, NBUF_TX_PKT_HTC); |
| 1297 | DPTRACE(cdf_dp_trace(netbuf, CDF_DP_TRACE_HTC_PACKET_PTR_RECORD, |
| 1298 | (uint8_t *)(cdf_nbuf_data(netbuf)), |
| 1299 | sizeof(cdf_nbuf_data(netbuf)))); |
| 1300 | status = hif_send_head(target->hif_dev, |
| 1301 | pEndpoint->UL_PipeID, |
| 1302 | pEndpoint->Id, ActualLength, netbuf, data_attr); |
| 1303 | |
| 1304 | UNLOCK_HTC_TX(target); |
| 1305 | return status; |
| 1306 | } |
| 1307 | #else /*ATH_11AC_TXCOMPACT */ |
| 1308 | |
| 1309 | A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket, |
| 1310 | A_UINT8 more_data) |
| 1311 | { |
| 1312 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 1313 | HTC_ENDPOINT *pEndpoint; |
| 1314 | HTC_FRAME_HDR *pHtcHdr; |
| 1315 | HTC_PACKET_QUEUE sendQueue; |
Rajeev Kumar | 926baab | 2016-01-06 18:11:55 -0800 | [diff] [blame] | 1316 | cdf_nbuf_t netbuf = NULL; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1317 | int tx_resources; |
| 1318 | A_STATUS status = A_OK; |
| 1319 | uint32_t data_attr = 0; |
| 1320 | |
| 1321 | if (pPacket) { |
| 1322 | AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX); |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1323 | pEndpoint = &target->endpoint[pPacket->Endpoint]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1324 | |
| 1325 | /* add HTC_FRAME_HDR in the initial fragment */ |
| 1326 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 1327 | pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0); |
| 1328 | AR_DEBUG_ASSERT(pHtcHdr); |
| 1329 | |
| 1330 | HTC_WRITE32(pHtcHdr, |
| 1331 | SM(pPacket->ActualLength, |
| 1332 | HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->PktInfo. |
| 1333 | AsTx.SendFlags, |
| 1334 | HTC_FRAME_HDR_FLAGS) |
| 1335 | | SM(pPacket->Endpoint, HTC_FRAME_HDR_ENDPOINTID)); |
| 1336 | /* |
| 1337 | * If the HIF pipe for the data endpoint is polled rather than |
| 1338 | * interrupt-driven, this is a good point to check whether any |
| 1339 | * data previously sent through the HIF pipe have finished being |
| 1340 | * sent. |
| 1341 | * Since this may result in callbacks to htc_tx_completion_handler, |
| 1342 | * which can take the HTC tx lock, make the hif_send_complete_check |
| 1343 | * call before acquiring the HTC tx lock. |
| 1344 | * Call hif_send_complete_check directly, rather than calling |
| 1345 | * htc_send_complete_check, and call the PollTimerStart separately |
| 1346 | * after calling hif_send_head, so the timer will be started to |
| 1347 | * check for completion of the new outstanding download (in the |
| 1348 | * unexpected event that other polling calls don't catch it). |
| 1349 | */ |
| 1350 | if (pEndpoint->ul_is_polled) { |
| 1351 | htc_send_complete_poll_timer_stop(pEndpoint); |
| 1352 | hif_send_complete_check(pEndpoint->target->hif_dev, |
| 1353 | pEndpoint->UL_PipeID, 0); |
| 1354 | } |
| 1355 | |
| 1356 | LOCK_HTC_TX(target); |
| 1357 | |
| 1358 | pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo; |
| 1359 | pEndpoint->SeqNo++; |
| 1360 | |
| 1361 | HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1, |
| 1362 | SM(pPacket->PktInfo.AsTx.SeqNo, |
| 1363 | HTC_FRAME_HDR_CONTROLBYTES1)); |
| 1364 | |
| 1365 | /* append new packet to pEndpoint->TxQueue */ |
| 1366 | HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket); |
| 1367 | #ifdef ENABLE_BUNDLE_TX |
| 1368 | if (HTC_ENABLE_BUNDLE(target) && (more_data)) { |
| 1369 | UNLOCK_HTC_TX(target); |
| 1370 | return A_OK; |
| 1371 | } |
| 1372 | #endif |
| 1373 | } else { |
| 1374 | LOCK_HTC_TX(target); |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1375 | pEndpoint = &target->endpoint[1]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /* increment tx processing count on entry */ |
| 1379 | cdf_atomic_inc(&pEndpoint->TxProcessCount); |
| 1380 | if (cdf_atomic_read(&pEndpoint->TxProcessCount) > 1) { |
| 1381 | /* |
| 1382 | * Another thread or task is draining the TX queues on this endpoint. |
| 1383 | * That thread will reset the tx processing count when the queue is |
| 1384 | * drained. |
| 1385 | */ |
| 1386 | cdf_atomic_dec(&pEndpoint->TxProcessCount); |
| 1387 | UNLOCK_HTC_TX(target); |
| 1388 | return A_OK; |
| 1389 | } |
| 1390 | |
| 1391 | /***** beyond this point only 1 thread may enter ******/ |
| 1392 | |
| 1393 | INIT_HTC_PACKET_QUEUE(&sendQueue); |
| 1394 | if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 1395 | #if DEBUG_CREDIT |
| 1396 | int cred = pEndpoint->TxCredits; |
| 1397 | #endif |
| 1398 | get_htc_send_packets_credit_based(target, pEndpoint, &sendQueue); |
| 1399 | #if DEBUG_CREDIT |
| 1400 | if (ep_debug_mask & (1 << pEndpoint->Id)) { |
| 1401 | if (cred - pEndpoint->TxCredits > 0) { |
| 1402 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 1403 | (" <HTC> Decrease EP%d %d - %d = %d credits.\n", |
| 1404 | pEndpoint->Id, cred, |
| 1405 | cred - pEndpoint->TxCredits, |
| 1406 | pEndpoint->TxCredits)); |
| 1407 | } |
| 1408 | } |
| 1409 | #endif |
| 1410 | UNLOCK_HTC_TX(target); |
| 1411 | } |
| 1412 | #ifdef ENABLE_BUNDLE_TX |
| 1413 | else if (HTC_ENABLE_BUNDLE(target)) { |
| 1414 | /* Dequeue max packets from endpoint tx queue */ |
| 1415 | get_htc_send_packets(target, pEndpoint, &sendQueue, |
| 1416 | HTC_MAX_TX_BUNDLE_SEND_LIMIT); |
| 1417 | UNLOCK_HTC_TX(target); |
| 1418 | } |
| 1419 | #endif |
| 1420 | else { |
| 1421 | /* |
| 1422 | * Now drain the endpoint TX queue for transmission as long as we have |
| 1423 | * enough transmit resources |
| 1424 | */ |
| 1425 | tx_resources = |
| 1426 | hif_get_free_queue_number(target->hif_dev, |
| 1427 | pEndpoint->UL_PipeID); |
| 1428 | get_htc_send_packets(target, pEndpoint, &sendQueue, tx_resources); |
| 1429 | UNLOCK_HTC_TX(target); |
| 1430 | } |
| 1431 | NBUF_UPDATE_TX_PKT_COUNT(netbuf, NBUF_TX_PKT_HTC); |
| 1432 | DPTRACE(cdf_dp_trace(netbuf, CDF_DP_TRACE_HTC_PACKET_PTR_RECORD, |
| 1433 | (uint8_t *)(cdf_nbuf_data(netbuf)), |
| 1434 | sizeof(cdf_nbuf_data(netbuf)))); |
| 1435 | |
| 1436 | /* send what we can */ |
| 1437 | while (true) { |
| 1438 | #if defined(HIF_USB) || defined(HIF_SDIO) |
| 1439 | #ifdef ENABLE_BUNDLE_TX |
| 1440 | if (HTC_ENABLE_BUNDLE(target) && |
| 1441 | HTC_PACKET_QUEUE_DEPTH(&sendQueue) >= |
| 1442 | HTC_MIN_MSG_PER_BUNDLE) { |
| 1443 | htc_issue_packets_bundle(target, pEndpoint, &sendQueue); |
| 1444 | } |
| 1445 | #endif |
| 1446 | #endif |
| 1447 | pPacket = htc_packet_dequeue(&sendQueue); |
| 1448 | if (pPacket == NULL) { |
| 1449 | break; |
| 1450 | } |
| 1451 | netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket); |
| 1452 | |
| 1453 | LOCK_HTC_TX(target); |
| 1454 | /* store in look up queue to match completions */ |
| 1455 | HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket); |
| 1456 | INC_HTC_EP_STAT(pEndpoint, TxIssued, 1); |
| 1457 | pEndpoint->ul_outstanding_cnt++; |
| 1458 | UNLOCK_HTC_TX(target); |
| 1459 | |
| 1460 | status = hif_send_head(target->hif_dev, |
| 1461 | pEndpoint->UL_PipeID, |
| 1462 | pEndpoint->Id, |
| 1463 | HTC_HDR_LENGTH + pPacket->ActualLength, |
| 1464 | netbuf, data_attr); |
| 1465 | #if DEBUG_BUNDLE |
| 1466 | cdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n", |
| 1467 | pEndpoint->Id, |
| 1468 | pEndpoint->TxCreditSize, |
| 1469 | HTC_HDR_LENGTH + pPacket->ActualLength); |
| 1470 | #endif |
| 1471 | |
| 1472 | if (cdf_unlikely(A_FAILED(status))) { |
| 1473 | LOCK_HTC_TX(target); |
| 1474 | pEndpoint->ul_outstanding_cnt--; |
| 1475 | /* remove this packet from the tx completion queue */ |
| 1476 | HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket); |
| 1477 | |
| 1478 | /* |
| 1479 | * Don't bother reclaiming credits - HTC flow control |
| 1480 | * is not applicable to tx data. |
| 1481 | * In LL systems, there is no download flow control, |
| 1482 | * since there's virtually no download delay. |
| 1483 | * In HL systems, the txrx SW explicitly performs the |
| 1484 | * tx flow control. |
| 1485 | */ |
| 1486 | /* pEndpoint->TxCredits += pPacket->PktInfo.AsTx.CreditsUsed; */ |
| 1487 | |
| 1488 | /* put this frame back at the front of the sendQueue */ |
| 1489 | HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket); |
| 1490 | |
| 1491 | /* put the sendQueue back at the front of pEndpoint->TxQueue */ |
| 1492 | HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue, |
| 1493 | &sendQueue); |
| 1494 | UNLOCK_HTC_TX(target); |
| 1495 | break; /* still need to reset TxProcessCount */ |
| 1496 | } |
| 1497 | } |
| 1498 | /* done with this endpoint, we can clear the count */ |
| 1499 | cdf_atomic_init(&pEndpoint->TxProcessCount); |
| 1500 | |
| 1501 | if (pEndpoint->ul_is_polled) { |
| 1502 | /* |
| 1503 | * Start a cleanup timer to poll for download completion. |
| 1504 | * The download completion should be noticed promptly from |
| 1505 | * other polling calls, but the timer provides a safety net |
| 1506 | * in case other polling calls don't occur as expected. |
| 1507 | */ |
| 1508 | htc_send_complete_poll_timer_start(pEndpoint); |
| 1509 | } |
| 1510 | |
| 1511 | return status; |
| 1512 | } |
| 1513 | #endif /*ATH_11AC_TXCOMPACT */ |
| 1514 | |
| 1515 | /* |
| 1516 | * In the adapted HIF layer, cdf_nbuf_t are passed between HIF and HTC, since upper layers expects |
| 1517 | * HTC_PACKET containers we use the completed netbuf and lookup its corresponding HTC packet buffer |
| 1518 | * from a lookup list. |
| 1519 | * This is extra overhead that can be fixed by re-aligning HIF interfaces with HTC. |
| 1520 | * |
| 1521 | */ |
| 1522 | static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target, |
| 1523 | HTC_ENDPOINT *pEndpoint, |
| 1524 | cdf_nbuf_t netbuf) |
| 1525 | { |
| 1526 | HTC_PACKET *pPacket = NULL; |
| 1527 | HTC_PACKET *pFoundPacket = NULL; |
| 1528 | HTC_PACKET_QUEUE lookupQueue; |
| 1529 | |
| 1530 | INIT_HTC_PACKET_QUEUE(&lookupQueue); |
| 1531 | LOCK_HTC_TX(target); |
| 1532 | |
| 1533 | /* mark that HIF has indicated the send complete for another packet */ |
| 1534 | pEndpoint->ul_outstanding_cnt--; |
| 1535 | |
| 1536 | /* Dequeue first packet directly because of in-order completion */ |
| 1537 | pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue); |
| 1538 | if (cdf_unlikely(!pPacket)) { |
| 1539 | UNLOCK_HTC_TX(target); |
| 1540 | return NULL; |
| 1541 | } |
| 1542 | if (netbuf == (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) { |
| 1543 | UNLOCK_HTC_TX(target); |
| 1544 | return pPacket; |
| 1545 | } else { |
| 1546 | HTC_PACKET_ENQUEUE(&lookupQueue, pPacket); |
| 1547 | } |
| 1548 | |
| 1549 | /* |
| 1550 | * Move TX lookup queue to temp queue because most of packets that are not index 0 |
| 1551 | * are not top 10 packets. |
| 1552 | */ |
| 1553 | HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue, |
| 1554 | &pEndpoint->TxLookupQueue); |
| 1555 | UNLOCK_HTC_TX(target); |
| 1556 | |
| 1557 | ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket, |
| 1558 | HTC_PACKET, ListLink) { |
| 1559 | |
| 1560 | if (NULL == pPacket) { |
| 1561 | pFoundPacket = pPacket; |
| 1562 | break; |
| 1563 | } |
| 1564 | /* check for removal */ |
| 1565 | if (netbuf == |
| 1566 | (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) { |
| 1567 | /* found it */ |
| 1568 | HTC_PACKET_REMOVE(&lookupQueue, pPacket); |
| 1569 | pFoundPacket = pPacket; |
| 1570 | break; |
| 1571 | } |
| 1572 | |
| 1573 | } |
| 1574 | ITERATE_END; |
| 1575 | |
| 1576 | LOCK_HTC_TX(target); |
| 1577 | HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue, |
| 1578 | &lookupQueue); |
| 1579 | UNLOCK_HTC_TX(target); |
| 1580 | |
| 1581 | return pFoundPacket; |
| 1582 | } |
| 1583 | |
| 1584 | CDF_STATUS htc_tx_completion_handler(void *Context, |
| 1585 | cdf_nbuf_t netbuf, unsigned int EpID, |
| 1586 | uint32_t toeplitz_hash_result) |
| 1587 | { |
| 1588 | HTC_TARGET *target = (HTC_TARGET *) Context; |
| 1589 | HTC_ENDPOINT *pEndpoint; |
| 1590 | HTC_PACKET *pPacket; |
| 1591 | #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED |
| 1592 | HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = |
| 1593 | { ENDPOINT_5, ENDPOINT_4, ENDPOINT_2, ENDPOINT_3 }; |
| 1594 | int epidIdx; |
| 1595 | A_UINT16 resourcesThresh[DATA_EP_SIZE]; /* urb resources */ |
| 1596 | A_UINT16 resources; |
| 1597 | A_UINT16 resourcesMax; |
| 1598 | #endif |
| 1599 | |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1600 | pEndpoint = &target->endpoint[EpID]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1601 | target->TX_comp_cnt++; |
| 1602 | |
| 1603 | do { |
| 1604 | pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf); |
| 1605 | if (NULL == pPacket) { |
| 1606 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 1607 | ("HTC TX lookup failed!\n")); |
| 1608 | /* may have already been flushed and freed */ |
| 1609 | netbuf = NULL; |
| 1610 | break; |
| 1611 | } |
| 1612 | if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) { |
| 1613 | HTC_PACKET *pPacketTemp; |
| 1614 | HTC_PACKET_QUEUE *pQueueSave = |
| 1615 | (HTC_PACKET_QUEUE *) pPacket->pContext; |
| 1616 | HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave, |
| 1617 | pPacketTemp) { |
| 1618 | pPacket->Status = A_OK; |
| 1619 | send_packet_completion(target, pPacketTemp); |
| 1620 | } |
| 1621 | HTC_PACKET_QUEUE_ITERATE_END; |
| 1622 | free_htc_bundle_packet(target, pPacket); |
| 1623 | return CDF_STATUS_SUCCESS; |
| 1624 | } |
| 1625 | /* will be giving this buffer back to upper layers */ |
| 1626 | netbuf = NULL; |
| 1627 | pPacket->Status = CDF_STATUS_SUCCESS; |
| 1628 | send_packet_completion(target, pPacket); |
| 1629 | |
| 1630 | } while (false); |
| 1631 | |
| 1632 | if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { |
| 1633 | /* note: when using TX credit flow, the re-checking of queues happens |
| 1634 | * when credits flow back from the target. |
| 1635 | * in the non-TX credit case, we recheck after the packet completes */ |
| 1636 | htc_try_send(target, pEndpoint, NULL); |
| 1637 | } |
| 1638 | |
| 1639 | return CDF_STATUS_SUCCESS; |
| 1640 | } |
| 1641 | |
| 1642 | /* callback when TX resources become available */ |
| 1643 | void htc_tx_resource_avail_handler(void *context, A_UINT8 pipeID) |
| 1644 | { |
| 1645 | int i; |
| 1646 | HTC_TARGET *target = (HTC_TARGET *) context; |
| 1647 | HTC_ENDPOINT *pEndpoint = NULL; |
| 1648 | |
| 1649 | for (i = 0; i < ENDPOINT_MAX; i++) { |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1650 | pEndpoint = &target->endpoint[i]; |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 1651 | if (pEndpoint->service_id != 0) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1652 | if (pEndpoint->UL_PipeID == pipeID) { |
| 1653 | break; |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | if (i >= ENDPOINT_MAX) { |
| 1659 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 1660 | ("Invalid pipe indicated for TX resource avail : %d!\n", |
| 1661 | pipeID)); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 1666 | ("HIF indicated more resources for pipe:%d \n", |
| 1667 | pipeID)); |
| 1668 | |
| 1669 | htc_try_send(target, pEndpoint, NULL); |
| 1670 | } |
| 1671 | |
| 1672 | /* flush endpoint TX queue */ |
| 1673 | void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint, |
| 1674 | HTC_TX_TAG Tag) |
| 1675 | { |
| 1676 | HTC_PACKET *pPacket; |
| 1677 | |
| 1678 | LOCK_HTC_TX(target); |
| 1679 | while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) { |
| 1680 | pPacket = htc_packet_dequeue(&pEndpoint->TxQueue); |
| 1681 | |
| 1682 | if (pPacket) { |
| 1683 | /* let the sender know the packet was not delivered */ |
| 1684 | pPacket->Status = A_ECANCELED; |
| 1685 | send_packet_completion(target, pPacket); |
| 1686 | } |
| 1687 | } |
| 1688 | UNLOCK_HTC_TX(target); |
| 1689 | } |
| 1690 | |
| 1691 | /* HTC API to flush an endpoint's TX queue*/ |
| 1692 | void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint, |
| 1693 | HTC_TX_TAG Tag) |
| 1694 | { |
| 1695 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1696 | HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1697 | |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 1698 | if (pEndpoint->service_id == 0) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1699 | AR_DEBUG_ASSERT(false); |
| 1700 | /* not in use.. */ |
| 1701 | return; |
| 1702 | } |
| 1703 | |
| 1704 | htc_flush_endpoint_tx(target, pEndpoint, Tag); |
| 1705 | } |
| 1706 | |
| 1707 | /* HTC API to indicate activity to the credit distribution function */ |
| 1708 | void htc_indicate_activity_change(HTC_HANDLE HTCHandle, |
| 1709 | HTC_ENDPOINT_ID Endpoint, A_BOOL Active) |
| 1710 | { |
| 1711 | /* TODO */ |
| 1712 | } |
| 1713 | |
| 1714 | A_BOOL htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint) |
| 1715 | { |
| 1716 | return true; |
| 1717 | } |
| 1718 | |
| 1719 | /* process credit reports and call distribution function */ |
| 1720 | void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt, |
| 1721 | int NumEntries, HTC_ENDPOINT_ID FromEndpoint) |
| 1722 | { |
| 1723 | int i; |
| 1724 | HTC_ENDPOINT *pEndpoint; |
| 1725 | int totalCredits = 0; |
| 1726 | A_UINT8 rpt_credits, rpt_ep_id; |
| 1727 | |
| 1728 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 1729 | ("+htc_process_credit_rpt, Credit Report Entries:%d \n", |
| 1730 | NumEntries)); |
| 1731 | |
| 1732 | /* lock out TX while we update credits */ |
| 1733 | LOCK_HTC_TX(target); |
| 1734 | |
| 1735 | for (i = 0; i < NumEntries; i++, pRpt++) { |
| 1736 | |
| 1737 | rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID); |
| 1738 | |
| 1739 | if (rpt_ep_id >= ENDPOINT_MAX) { |
| 1740 | AR_DEBUG_ASSERT(false); |
| 1741 | break; |
| 1742 | } |
| 1743 | |
| 1744 | rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS); |
| 1745 | |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1746 | pEndpoint = &target->endpoint[rpt_ep_id]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1747 | #if DEBUG_CREDIT |
| 1748 | if (ep_debug_mask & (1 << pEndpoint->Id)) { |
| 1749 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, |
| 1750 | (" <HTC> Increase EP%d %d + %d = %d credits\n", |
| 1751 | rpt_ep_id, pEndpoint->TxCredits, |
| 1752 | rpt_credits, |
| 1753 | pEndpoint->TxCredits + rpt_credits)); |
| 1754 | } |
| 1755 | #endif |
| 1756 | |
| 1757 | #ifdef HTC_EP_STAT_PROFILING |
| 1758 | |
| 1759 | INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1); |
| 1760 | INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits); |
| 1761 | |
| 1762 | if (FromEndpoint == rpt_ep_id) { |
| 1763 | /* this credit report arrived on the same endpoint indicating it arrived in an RX |
| 1764 | * packet */ |
| 1765 | INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx, |
| 1766 | rpt_credits); |
| 1767 | INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1); |
| 1768 | } else if (FromEndpoint == ENDPOINT_0) { |
| 1769 | /* this credit arrived on endpoint 0 as a NULL message */ |
| 1770 | INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0, |
| 1771 | rpt_credits); |
| 1772 | INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1); |
| 1773 | } else { |
| 1774 | /* arrived on another endpoint */ |
| 1775 | INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther, |
| 1776 | rpt_credits); |
| 1777 | INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1); |
| 1778 | } |
| 1779 | |
| 1780 | #endif |
| 1781 | #if defined(HIF_USB) |
| 1782 | if (pEndpoint->Id >= ENDPOINT_2 && pEndpoint->Id <= ENDPOINT_5) { |
| 1783 | HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = |
| 1784 | { ENDPOINT_5, ENDPOINT_4, ENDPOINT_2, ENDPOINT_3 }; |
| 1785 | int epid_idx; |
| 1786 | |
| 1787 | target->avail_tx_credits += rpt_credits; |
| 1788 | |
| 1789 | for (epid_idx = 0; epid_idx < DATA_EP_SIZE; epid_idx++) { |
Houston Hoffman | 29573d9 | 2015-10-20 17:49:44 -0700 | [diff] [blame] | 1790 | pEndpoint = &target->endpoint[eid[epid_idx]]; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1791 | if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) { |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | } |
| 1796 | UNLOCK_HTC_TX(target); |
| 1797 | htc_try_send(target, pEndpoint, NULL); |
| 1798 | LOCK_HTC_TX(target); |
| 1799 | } else { |
| 1800 | pEndpoint->TxCredits += rpt_credits; |
| 1801 | |
| 1802 | if (pEndpoint->TxCredits |
| 1803 | && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) { |
| 1804 | UNLOCK_HTC_TX(target); |
| 1805 | htc_try_send(target, pEndpoint, NULL); |
| 1806 | LOCK_HTC_TX(target); |
| 1807 | } |
| 1808 | } |
| 1809 | #else |
| 1810 | pEndpoint->TxCredits += rpt_credits; |
| 1811 | |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 1812 | if (pEndpoint->service_id == WMI_CONTROL_SVC) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1813 | LOCK_HTC_CREDIT(target); |
| 1814 | htc_credit_record(HTC_PROCESS_CREDIT_REPORT, |
| 1815 | pEndpoint->TxCredits, |
| 1816 | HTC_PACKET_QUEUE_DEPTH(&pEndpoint-> |
| 1817 | TxQueue)); |
| 1818 | UNLOCK_HTC_CREDIT(target); |
| 1819 | } |
| 1820 | |
| 1821 | if (pEndpoint->TxCredits |
| 1822 | && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) { |
| 1823 | UNLOCK_HTC_TX(target); |
| 1824 | #ifdef ATH_11AC_TXCOMPACT |
| 1825 | htc_try_send(target, pEndpoint, NULL); |
| 1826 | #else |
Houston Hoffman | 4f2f459 | 2015-10-20 18:00:29 -0700 | [diff] [blame] | 1827 | if (pEndpoint->service_id == HTT_DATA_MSG_SVC) { |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1828 | htc_send_data_pkt(target, NULL, 0); |
| 1829 | } else { |
| 1830 | htc_try_send(target, pEndpoint, NULL); |
| 1831 | } |
| 1832 | #endif |
| 1833 | LOCK_HTC_TX(target); |
| 1834 | } |
| 1835 | #endif |
| 1836 | totalCredits += rpt_credits; |
| 1837 | } |
| 1838 | |
| 1839 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, |
| 1840 | (" Report indicated %d credits to distribute \n", |
| 1841 | totalCredits)); |
| 1842 | |
| 1843 | UNLOCK_HTC_TX(target); |
| 1844 | |
| 1845 | AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt \n")); |
| 1846 | } |
| 1847 | |
| 1848 | /* function to fetch stats from htc layer*/ |
| 1849 | struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle) |
| 1850 | { |
| 1851 | HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); |
| 1852 | |
| 1853 | return (&(target->htc_pkt_stats)); |
| 1854 | } |