blob: b2a1b701e4358724ce7f55a6f2fdca4b8fb4e838 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Rajeev Kumar926baab2016-01-06 18:11:55 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
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 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053031#include <qdf_mem.h> /* qdf_mem_malloc */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080032#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
41typedef 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 */
52static unsigned ep_debug_mask =
53 (1 << ENDPOINT_0) | (1 << ENDPOINT_1) | (1 << ENDPOINT_2);
54#endif
55
56/* HTC Control Path Credit History */
57A_UINT32 g_htc_credit_history_idx = 0;
58HTC_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 */
76void 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 =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053083 qdf_get_log_timestamp();
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080084 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
101void 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
110void 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 Hoffman29573d92015-10-20 17:49:44 -0700124 pEndpoint = &target->endpoint[i];
Houston Hoffman4f2f4592015-10-20 18:00:29 -0700125 if (pEndpoint->service_id == WMI_CONTROL_SVC) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800126 *credits = pEndpoint->TxCredits;
127 break;
128 }
129 }
130 UNLOCK_HTC_TX(target);
131}
132
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530133static inline void restore_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800134{
135 if (pPacket->PktInfo.AsTx.Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
136 cdf_nbuf_t netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530137 cdf_nbuf_unmap(target->osdev, netbuf, QDF_DMA_TO_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800138 cdf_nbuf_pull_head(netbuf, sizeof(HTC_FRAME_HDR));
139 pPacket->PktInfo.AsTx.Flags &= ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
140 }
141
142}
143
144static 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
186static void send_packet_completion(HTC_TARGET *target, HTC_PACKET *pPacket)
187{
Houston Hoffman29573d92015-10-20 17:49:44 -0700188 HTC_ENDPOINT *pEndpoint = &target->endpoint[pPacket->Endpoint];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189 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
198void htc_send_complete_check_cleanup(void *context)
199{
200 HTC_ENDPOINT *pEndpoint = (HTC_ENDPOINT *) context;
201 htc_send_complete_check(pEndpoint, 1);
202}
203
204HTC_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 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219 pPacket = qdf_mem_malloc(sizeof(HTC_PACKET));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800220 AR_DEBUG_ASSERT(pPacket);
221 if (!pPacket) {
222 cdf_nbuf_free(netbuf);
223 return NULL;
224 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530225 pQueueSave = qdf_mem_malloc(sizeof(HTC_PACKET_QUEUE));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800226 AR_DEBUG_ASSERT(pQueueSave);
227 if (!pQueueSave) {
228 cdf_nbuf_free(netbuf);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530229 qdf_mem_free(pPacket);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800230 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
257void 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
303static A_STATUS htc_send_bundled_netbuf(HTC_TARGET *target,
304 HTC_ENDPOINT *pEndpoint,
305 unsigned char *pBundleBuffer,
306 HTC_PACKET *pPacketTx)
307{
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530308 qdf_size_t data_len;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800309 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
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530325 qdf_print(" Send bundle EP%d buffer size:0x%x, total:0x%x, count:%d.\n",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800326 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) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530334 qdf_print("%s:hif_send_head failed(len=%d).\n", __FUNCTION__,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800335 data_len);
336 }
337 return status;
338}
339
340static 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
451static 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
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530525 (pPacket), QDF_DMA_TO_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800526 }
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 Hoffman3d0cda82015-12-03 13:25:05 -0800535 hif_send_complete_check(target->hif_dev, pEndpoint->UL_PipeID, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800536 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
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530541 qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800542 pEndpoint->Id,
543 pEndpoint->TxCreditSize,
544 HTC_HDR_LENGTH + pPacket->ActualLength);
545#endif
546
547 target->ce_send_cnt++;
548
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530549 if (qdf_unlikely(A_FAILED(status))) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800550 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
Houston Hoffman1dd22762015-11-10 11:35:49 -0800580 /*
581 * For HTT messages without a response from fw,
582 * do the runtime put here.
583 * otherwise runtime put will be done when the fw response comes
584 */
585 if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
586 hif_pm_runtime_put(target->hif_dev);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800587 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530588 if (qdf_unlikely(A_FAILED(status))) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800589#if defined(HIF_USB)
590 if (pEndpoint->Id >= ENDPOINT_2 && pEndpoint->Id <= ENDPOINT_5)
591 target->avail_tx_credits +=
592 pPacket->PktInfo.AsTx.CreditsUsed;
593 else
594 pEndpoint->TxCredits +=
595 pPacket->PktInfo.AsTx.CreditsUsed;
596#endif
Manjunathappa Prakash3044c6e2015-12-04 00:08:58 -0800597 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
598 ("htc_issue_packets, failed pkt:0x%p status:%d",
599 pPacket, status));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800600 }
601
602 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets \n"));
603
604 return status;
605}
606
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800607#ifdef FEATURE_RUNTIME_PM
608/**
609 * extract_htc_pm_packtes(): move pm packets from endpoint into queue
610 * @endpoint: which enpoint to extract packets from
611 * @queue: a queue to store extracted packets in.
612 *
613 * remove pm packets from the endpoint's tx queue.
614 * queue them into a queue
615 */
616static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
617 HTC_PACKET_QUEUE *queue)
618{
619 HTC_PACKET *packet;
620
621 /* only WMI endpoint has power management packets */
622 if (endpoint->service_id != WMI_CONTROL_SVC)
623 return;
624
625 ITERATE_OVER_LIST_ALLOW_REMOVE(&endpoint->TxQueue.QueueHead, packet,
626 HTC_PACKET, ListLink) {
627 if (packet->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_AUTO_PM) {
628 HTC_PACKET_REMOVE(&endpoint->TxQueue, packet);
629 HTC_PACKET_ENQUEUE(queue, packet);
630 }
631 } ITERATE_END
632}
633
634/**
635 * queue_htc_pm_packets(): queue pm packets with priority
636 * @endpoint: enpoint to queue packets to
637 * @queue: queue of pm packets to enque
638 *
639 * suspend resume packets get special treatment & priority.
640 * need to queue them at the front of the queue.
641 */
642static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
643 HTC_PACKET_QUEUE *queue)
644{
645 if (endpoint->service_id != WMI_CONTROL_SVC)
646 return;
647
648 HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&endpoint->TxQueue, queue);
649}
650#else
651static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
652 HTC_PACKET_QUEUE *queue)
653{}
654
655static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
656 HTC_PACKET_QUEUE *queue)
657{}
658#endif
659
660
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800661/* get HTC send packets from the TX queue on an endpoint, based on available credits */
662void get_htc_send_packets_credit_based(HTC_TARGET *target,
663 HTC_ENDPOINT *pEndpoint,
664 HTC_PACKET_QUEUE *pQueue)
665{
666 int creditsRequired;
667 int remainder;
668 A_UINT8 sendFlags;
669 HTC_PACKET *pPacket;
670 unsigned int transferLength;
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800671 HTC_PACKET_QUEUE *tx_queue;
672 HTC_PACKET_QUEUE pm_queue;
673 bool do_pm_get = false;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800674
675 /****** NOTE : the TX lock is held when this function is called *****************/
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800676 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+get_htc_send_packets_credit_based\n"));
677
678 INIT_HTC_PACKET_QUEUE(&pm_queue);
679 extract_htc_pm_packets(pEndpoint, &pm_queue);
680 if (HTC_QUEUE_EMPTY(&pm_queue)) {
681 tx_queue = &pEndpoint->TxQueue;
682 do_pm_get = true;
683 } else {
684 tx_queue = &pm_queue;
685 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800686
687 /* loop until we can grab as many packets out of the queue as we can */
688 while (true) {
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800689 if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
690 /* bus suspended, runtime resume issued */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530691 QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800692 break;
693 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800694
695 sendFlags = 0;
696 /* get packet at head, but don't remove it */
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800697 pPacket = htc_get_pkt_at_head(tx_queue);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800698 if (pPacket == NULL) {
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800699 if (do_pm_get)
700 hif_pm_runtime_put(target->hif_dev);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800701 break;
702 }
703
704 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
705 (" Got head packet:%p , Queue Depth: %d\n",
706 pPacket,
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800707 HTC_PACKET_QUEUE_DEPTH(tx_queue)));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800708
709 transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
710
711 if (transferLength <= pEndpoint->TxCreditSize) {
712 creditsRequired = 1;
713 } else {
714 /* figure out how many credits this message requires */
715 creditsRequired =
716 transferLength / pEndpoint->TxCreditSize;
717 remainder = transferLength % pEndpoint->TxCreditSize;
718
719 if (remainder) {
720 creditsRequired++;
721 }
722 }
723
724 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
725 (" Credits Required:%d Got:%d\n",
726 creditsRequired, pEndpoint->TxCredits));
727
728 if (pEndpoint->Id == ENDPOINT_0) {
729 /* endpoint 0 is special, it always has a credit and does not require credit based
730 * flow control */
731 creditsRequired = 0;
732#if defined(HIF_USB)
733 } else if (pEndpoint->Id >= ENDPOINT_2
734 && pEndpoint->Id <= ENDPOINT_5) {
735 if (target->avail_tx_credits < creditsRequired)
736 break;
737
738 target->avail_tx_credits -= creditsRequired;
739
740 if (target->avail_tx_credits < 9) {
741 /* tell the target we need credits ASAP! */
742 sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
743 INC_HTC_EP_STAT(pEndpoint,
744 TxCreditLowIndications, 1);
745 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
746 (" Host Needs Credits \n"));
747 }
748#endif
749 } else {
750
751 if (pEndpoint->TxCredits < creditsRequired) {
752#if DEBUG_CREDIT
753 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
754 (" EP%d, No Credit now. %d < %d\n",
755 pEndpoint->Id,
756 pEndpoint->TxCredits,
757 creditsRequired));
758#endif
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800759 if (do_pm_get)
760 hif_pm_runtime_put(target->hif_dev);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800761 break;
762 }
763
764 pEndpoint->TxCredits -= creditsRequired;
765 INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed,
766 creditsRequired);
767
768 /* check if we need credits back from the target */
769 if (pEndpoint->TxCredits <=
770 pEndpoint->TxCreditsPerMaxMsg) {
771 /* tell the target we need credits ASAP! */
772 sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
773
Houston Hoffman4f2f4592015-10-20 18:00:29 -0700774 if (pEndpoint->service_id == WMI_CONTROL_SVC) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800775 LOCK_HTC_CREDIT(target);
776 htc_credit_record(HTC_REQUEST_CREDIT,
777 pEndpoint->TxCredits,
778 HTC_PACKET_QUEUE_DEPTH
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800779 (tx_queue));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800780 UNLOCK_HTC_CREDIT(target);
781 }
782
783 INC_HTC_EP_STAT(pEndpoint,
784 TxCreditLowIndications, 1);
785#if DEBUG_CREDIT
786 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
787 (" EP%d Needs Credits\n",
788 pEndpoint->Id));
789#endif
790 }
791 }
792
793 /* now we can fully dequeue */
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800794 pPacket = htc_packet_dequeue(tx_queue);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800795 if (pPacket) {
796 /* save the number of credits this packet consumed */
797 pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired;
798 /* save send flags */
799 pPacket->PktInfo.AsTx.SendFlags = sendFlags;
800
801 /* queue this packet into the caller's queue */
802 HTC_PACKET_ENQUEUE(pQueue, pPacket);
803 }
804 }
805
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800806 if (!HTC_QUEUE_EMPTY(&pm_queue))
807 queue_htc_pm_packets(pEndpoint, &pm_queue);
808
809 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
810 ("-get_htc_send_packets_credit_based\n"));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800811
812}
813
814void get_htc_send_packets(HTC_TARGET *target,
815 HTC_ENDPOINT *pEndpoint,
816 HTC_PACKET_QUEUE *pQueue, int Resources)
817{
818
819 HTC_PACKET *pPacket;
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800820 HTC_PACKET_QUEUE *tx_queue;
821 HTC_PACKET_QUEUE pm_queue;
822 bool do_pm_get;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800823
824 /****** NOTE : the TX lock is held when this function is called *****************/
825 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
826 ("+get_htc_send_packets %d resources\n", Resources));
827
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800828 INIT_HTC_PACKET_QUEUE(&pm_queue);
829 extract_htc_pm_packets(pEndpoint, &pm_queue);
830 if (HTC_QUEUE_EMPTY(&pm_queue)) {
831 tx_queue = &pEndpoint->TxQueue;
832 do_pm_get = true;
833 } else {
834 tx_queue = &pm_queue;
835 }
836
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800837 /* loop until we can grab as many packets out of the queue as we can */
838 while (Resources > 0) {
839 int num_frags;
840
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800841 if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
842 /* bus suspended, runtime resume issued */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530843 QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800844 break;
845 }
846
847 pPacket = htc_packet_dequeue(tx_queue);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800848 if (pPacket == NULL) {
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800849 if (do_pm_get)
850 hif_pm_runtime_put(target->hif_dev);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800851 break;
852 }
853 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
854 (" Got packet:%p , New Queue Depth: %d\n",
855 pPacket,
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800856 HTC_PACKET_QUEUE_DEPTH(tx_queue)));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800857 /* For non-credit path the sequence number is already embedded
858 * in the constructed HTC header
859 */
860#if 0
861 pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
862 pEndpoint->SeqNo++;
863#endif
864 pPacket->PktInfo.AsTx.SendFlags = 0;
865 pPacket->PktInfo.AsTx.CreditsUsed = 0;
866 /* queue this packet into the caller's queue */
867 HTC_PACKET_ENQUEUE(pQueue, pPacket);
868
869 /*
870 * FIX THIS:
871 * For now, avoid calling cdf_nbuf_get_num_frags before calling
872 * cdf_nbuf_map, because the MacOS version of cdf_nbuf_t doesn't
873 * support cdf_nbuf_get_num_frags until after cdf_nbuf_map has
874 * been done.
875 * Assume that the non-data netbufs, i.e. the WMI message netbufs,
876 * consist of a single fragment.
877 */
878 num_frags =
879 (pPacket->PktInfo.AsTx.
880 Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530881 /* WMI messages are in a single-fragment network buffer */ :
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800882 cdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT
883 (pPacket));
884 Resources -= num_frags;
885 }
886
Houston Hoffmanc5141b02015-11-18 02:36:30 -0800887 if (!HTC_QUEUE_EMPTY(&pm_queue))
888 queue_htc_pm_packets(pEndpoint, &pm_queue);
889
890 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets\n"));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800891
892}
893
894static HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target,
895 HTC_ENDPOINT *pEndpoint,
896 HTC_PACKET_QUEUE *pCallersSendQueue)
897{
898 HTC_PACKET_QUEUE sendQueue; /* temp queue to hold packets at various stages */
899 HTC_PACKET *pPacket;
900 int tx_resources;
901 int overflow;
902 HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK;
903
904 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%p Depth:%d)\n",
905 pCallersSendQueue,
906 (pCallersSendQueue ==
907 NULL) ? 0 :
908 HTC_PACKET_QUEUE_DEPTH
909 (pCallersSendQueue)));
910
911 /* init the local send queue */
912 INIT_HTC_PACKET_QUEUE(&sendQueue);
913
914 do {
915
916 if (NULL == pCallersSendQueue) {
917 /* caller didn't provide a queue, just wants us to check queues and send */
918 break;
919 }
920
921 if (HTC_QUEUE_EMPTY(pCallersSendQueue)) {
922 /* empty queue */
923 OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
924 HTC_PKT_Q_EMPTY);
925 result = HTC_SEND_QUEUE_DROP;
926 break;
927 }
928
929 if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >=
930 pEndpoint->MaxTxQueueDepth) {
931 /* we've already overflowed */
932 overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
933 } else {
934 /* figure out how much we will overflow by */
935 overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
936 overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
937 /* figure out how much we will overflow the TX queue by */
938 overflow -= pEndpoint->MaxTxQueueDepth;
939 }
940
941 /* if overflow is negative or zero, we are okay */
942 if (overflow > 0) {
943 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
944 (" Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d \n",
945 pEndpoint->Id, overflow,
946 HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
947 TxQueue),
948 pEndpoint->MaxTxQueueDepth));
949 }
950 if ((overflow <= 0)
951 || (pEndpoint->EpCallBacks.EpSendFull == NULL)) {
952 /* all packets will fit or caller did not provide send full indication handler
953 * -- just move all of them to the local sendQueue object */
954 HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue,
955 pCallersSendQueue);
956 } else {
957 int i;
958 int goodPkts =
959 HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) -
960 overflow;
961
962 A_ASSERT(goodPkts >= 0);
963 /* we have overflowed, and a callback is provided */
964 /* dequeue all non-overflow packets into the sendqueue */
965 for (i = 0; i < goodPkts; i++) {
966 /* pop off caller's queue */
967 pPacket = htc_packet_dequeue(pCallersSendQueue);
968 A_ASSERT(pPacket != NULL);
969 /* insert into local queue */
970 HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
971 }
972
973 /* the caller's queue has all the packets that won't fit */
974 /* walk through the caller's queue and indicate each one to the send full handler */
975 ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->
976 QueueHead, pPacket,
977 HTC_PACKET, ListLink) {
978
979 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
980 (" Indicating overflowed TX packet: %p \n",
981 pPacket));
982 /*
983 * Remove headroom reserved for HTC_FRAME_HDR before giving
984 * the packet back to the user via the EpSendFull callback.
985 */
986 restore_tx_packet(target, pPacket);
987
988 if (pEndpoint->EpCallBacks.
989 EpSendFull(pEndpoint->EpCallBacks.pContext,
990 pPacket) == HTC_SEND_FULL_DROP) {
991 /* callback wants the packet dropped */
992 INC_HTC_EP_STAT(pEndpoint, TxDropped,
993 1);
994 /* leave this one in the caller's queue for cleanup */
995 } else {
996 /* callback wants to keep this packet, remove from caller's queue */
997 HTC_PACKET_REMOVE(pCallersSendQueue,
998 pPacket);
999 /* put it in the send queue */
1000 /* add HTC_FRAME_HDR space reservation again */
1001 cdf_nbuf_push_head
1002 (GET_HTC_PACKET_NET_BUF_CONTEXT
1003 (pPacket), sizeof(HTC_FRAME_HDR));
1004
1005 HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
1006 }
1007
1008 }
1009 ITERATE_END;
1010
1011 if (HTC_QUEUE_EMPTY(&sendQueue)) {
1012 /* no packets made it in, caller will cleanup */
1013 OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
1014 HTC_SEND_Q_EMPTY);
1015 result = HTC_SEND_QUEUE_DROP;
1016 break;
1017 }
1018 }
1019
1020 } while (false);
1021
1022 if (result != HTC_SEND_QUEUE_OK) {
1023 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n"));
1024 return result;
1025 }
1026
1027 if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
1028 tx_resources =
1029 hif_get_free_queue_number(target->hif_dev,
1030 pEndpoint->UL_PipeID);
1031 } else {
1032 tx_resources = 0;
1033 }
1034
1035 LOCK_HTC_TX(target);
1036
1037 if (!HTC_QUEUE_EMPTY(&sendQueue)) {
1038 /* transfer packets to tail */
1039 HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,
1040 &sendQueue);
1041 A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue));
1042 INIT_HTC_PACKET_QUEUE(&sendQueue);
1043 }
1044
1045 /* increment tx processing count on entry */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301046 qdf_atomic_inc(&pEndpoint->TxProcessCount);
1047 if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001048 /* another thread or task is draining the TX queues on this endpoint
1049 * that thread will reset the tx processing count when the queue is drained */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301050 qdf_atomic_dec(&pEndpoint->TxProcessCount);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001051 UNLOCK_HTC_TX(target);
1052 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy) \n"));
1053 return HTC_SEND_QUEUE_OK;
1054 }
1055
1056 /***** beyond this point only 1 thread may enter ******/
1057
1058 /* now drain the endpoint TX queue for transmission as long as we have enough
1059 * transmit resources */
1060 while (true) {
1061
1062 if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0) {
1063 break;
1064 }
1065
1066 if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
1067#if DEBUG_CREDIT
1068 int cred = pEndpoint->TxCredits;
1069#endif
1070 /* credit based mechanism provides flow control based on target transmit resource availability, we
1071 * assume that the HIF layer will always have bus resources greater than target transmit resources */
1072 get_htc_send_packets_credit_based(target, pEndpoint,
1073 &sendQueue);
1074#if DEBUG_CREDIT
1075 if (ep_debug_mask & (1 << pEndpoint->Id)) {
1076 if (cred - pEndpoint->TxCredits > 0) {
1077 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1078 (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
1079 pEndpoint->Id, cred,
1080 cred -
1081 pEndpoint->TxCredits,
1082 pEndpoint->TxCredits));
1083 }
1084 }
1085#endif
1086 } else {
1087 /* get all the packets for this endpoint that we can for this pass */
1088 get_htc_send_packets(target, pEndpoint, &sendQueue,
1089 tx_resources);
1090 }
1091
1092 if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) {
1093 /* didn't get any packets due to a lack of resources or TX queue was drained */
1094 break;
1095 }
1096
1097 UNLOCK_HTC_TX(target);
1098
1099 /* send what we can */
Manjunathappa Prakash3044c6e2015-12-04 00:08:58 -08001100 result = htc_issue_packets(target, pEndpoint, &sendQueue);
1101 if (result) {
Houston Hoffmanc5141b02015-11-18 02:36:30 -08001102 int i;
Manjunathappa Prakash3044c6e2015-12-04 00:08:58 -08001103 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1104 ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue",
1105 result));
Houston Hoffmanc5141b02015-11-18 02:36:30 -08001106
1107 for (i = HTC_PACKET_QUEUE_DEPTH(&sendQueue); i > 0; i--)
1108 hif_pm_runtime_put(target->hif_dev);
1109
Manjunathappa Prakash3044c6e2015-12-04 00:08:58 -08001110 HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
1111 &sendQueue);
1112 LOCK_HTC_TX(target);
1113 break;
1114 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001115
1116 if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
1117 tx_resources =
1118 hif_get_free_queue_number(target->hif_dev,
1119 pEndpoint->UL_PipeID);
1120 }
1121
1122 LOCK_HTC_TX(target);
1123
1124 }
1125
1126 UNLOCK_HTC_TX(target);
1127 /* done with this endpoint, we can clear the count */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301128 qdf_atomic_init(&pEndpoint->TxProcessCount);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001129
1130 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n"));
1131
1132 return HTC_SEND_QUEUE_OK;
1133}
1134
1135#ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
1136static A_UINT16 htc_send_pkts_sched_check(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID id)
1137{
1138 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1139 HTC_ENDPOINT *pEndpoint;
1140 HTC_ENDPOINT_ID eid;
1141 HTC_PACKET_QUEUE *pTxQueue;
1142 A_UINT16 resources;
1143 A_UINT16 acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 };
1144
1145 if (id < ENDPOINT_2 || id > ENDPOINT_5) {
1146 return 1;
1147 }
1148
1149 for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) {
Houston Hoffman29573d92015-10-20 17:49:44 -07001150 pEndpoint = &target->endpoint[eid];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001151 pTxQueue = &pEndpoint->TxQueue;
1152
1153 if (HTC_QUEUE_EMPTY(pTxQueue)) {
1154 acQueueStatus[eid - 2] = 1;
1155 }
1156 }
1157
1158 switch (id) {
1159 case ENDPOINT_2: /* BE */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301160 return acQueueStatus[0] && acQueueStatus[2]
1161 && acQueueStatus[3];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001162 case ENDPOINT_3: /* BK */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301163 return acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2]
1164 && acQueueStatus[3];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001165 case ENDPOINT_4: /* VI */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301166 return acQueueStatus[2] && acQueueStatus[3];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001167 case ENDPOINT_5: /* VO */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301168 return acQueueStatus[3];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001169 default:
1170 return 0;
1171 }
1172
1173}
1174
1175static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target,
1176 HTC_PACKET_QUEUE *pPktQueue,
1177 HTC_ENDPOINT_ID eid)
1178{
1179 HTC_ENDPOINT *pEndpoint;
1180 HTC_PACKET_QUEUE *pTxQueue;
1181 HTC_PACKET *pPacket;
1182 int goodPkts;
1183
Houston Hoffman29573d92015-10-20 17:49:44 -07001184 pEndpoint = &target->endpoint[eid];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001185 pTxQueue = &pEndpoint->TxQueue;
1186
1187 LOCK_HTC_TX(target);
1188
1189 goodPkts =
1190 pEndpoint->MaxTxQueueDepth -
1191 HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
1192
1193 if (goodPkts > 0) {
1194 while (!HTC_QUEUE_EMPTY(pPktQueue)) {
1195 pPacket = htc_packet_dequeue(pPktQueue);
1196 HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
1197 goodPkts--;
1198
1199 if (goodPkts <= 0) {
1200 break;
1201 }
1202 }
1203 }
1204
1205 if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) {
1206 ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket,
1207 HTC_PACKET, ListLink) {
1208
1209 if (pEndpoint->EpCallBacks.
1210 EpSendFull(pEndpoint->EpCallBacks.pContext,
1211 pPacket) == HTC_SEND_FULL_DROP) {
1212 INC_HTC_EP_STAT(pEndpoint, TxDropped, 1);
1213 } else {
1214 HTC_PACKET_REMOVE(pPktQueue, pPacket);
1215 HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
1216 }
1217 }
1218 ITERATE_END;
1219 }
1220
1221 UNLOCK_HTC_TX(target);
1222
1223 return A_OK;
1224}
1225
1226#endif
1227
1228A_STATUS htc_send_pkts_multiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue)
1229{
1230 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1231 HTC_ENDPOINT *pEndpoint;
1232 HTC_PACKET *pPacket;
1233 cdf_nbuf_t netbuf;
1234 HTC_FRAME_HDR *pHtcHdr;
1235
1236 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
1237 ("+htc_send_pkts_multiple: Queue: %p, Pkts %d \n",
1238 pPktQueue, HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
1239
1240 /* get packet at head to figure out which endpoint these packets will go into */
1241 pPacket = htc_get_pkt_at_head(pPktQueue);
1242 if (NULL == pPacket) {
1243 OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL);
1244 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
1245 return A_EINVAL;
1246 }
1247
1248 AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
Houston Hoffman29573d92015-10-20 17:49:44 -07001249 pEndpoint = &target->endpoint[pPacket->Endpoint];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001250
Houston Hoffman4f2f4592015-10-20 18:00:29 -07001251 if (!pEndpoint->service_id) {
1252 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001253 __func__));
1254 return A_EINVAL;
1255 }
1256
1257#ifdef HTC_EP_STAT_PROFILING
1258 LOCK_HTC_TX(target);
1259 INC_HTC_EP_STAT(pEndpoint, TxPosted, HTC_PACKET_QUEUE_DEPTH(pPktQueue));
1260 UNLOCK_HTC_TX(target);
1261#endif
1262
1263 /* provide room in each packet's netbuf for the HTC frame header */
1264 HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
1265 netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
1266 AR_DEBUG_ASSERT(netbuf);
1267
1268 cdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR));
1269 /* setup HTC frame header */
1270 pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0);
1271 AR_DEBUG_ASSERT(pHtcHdr);
1272 HTC_WRITE32(pHtcHdr,
1273 SM(pPacket->ActualLength,
1274 HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->Endpoint,
1275 HTC_FRAME_HDR_ENDPOINTID));
1276
1277 LOCK_HTC_TX(target);
1278
1279 pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
1280 pEndpoint->SeqNo++;
1281
1282 HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1,
1283 SM(pPacket->PktInfo.AsTx.SeqNo,
1284 HTC_FRAME_HDR_CONTROLBYTES1));
1285
1286 UNLOCK_HTC_TX(target);
1287 /*
1288 * Now that the HTC frame header has been added, the netbuf can be
1289 * mapped. This only applies to non-data frames, since data frames
1290 * were already mapped as they entered into the driver.
1291 */
1292 cdf_nbuf_map(target->osdev,
1293 GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301294 QDF_DMA_TO_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001295
1296 pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
1297 }
1298 HTC_PACKET_QUEUE_ITERATE_END;
1299
1300#ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
1301 if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id)) {
1302 htc_send_pkts_sched_queue(HTCHandle, pPktQueue, pEndpoint->Id);
1303 } else {
1304 htc_try_send(target, pEndpoint, pPktQueue);
1305 }
1306#else
1307 htc_try_send(target, pEndpoint, pPktQueue);
1308#endif
1309
1310 /* do completion on any packets that couldn't get in */
1311 if (!HTC_QUEUE_EMPTY(pPktQueue)) {
1312
1313 HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
1314 /* remove the headroom reserved for HTC_FRAME_HDR */
1315 restore_tx_packet(target, pPacket);
1316
1317 if (HTC_STOPPING(target)) {
1318 pPacket->Status = A_ECANCELED;
1319 } else {
1320 pPacket->Status = A_NO_RESOURCE;
1321 }
1322 }
1323 HTC_PACKET_QUEUE_ITERATE_END;
1324
1325 do_send_completion(pEndpoint, pPktQueue);
1326 }
1327
1328 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
1329
1330 return A_OK;
1331}
1332
1333/* HTC API - htc_send_pkt */
1334A_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket)
1335{
1336 HTC_PACKET_QUEUE queue;
1337
Karthick Sdc40a352015-10-14 18:14:15 +05301338 if (HTCHandle == NULL || pPacket == NULL) {
1339 return A_ERROR;
1340 }
1341
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001342 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
1343 ("+-htc_send_pkt: Enter endPointId: %d, buffer: %p, length: %d \n",
1344 pPacket->Endpoint, pPacket->pBuffer,
1345 pPacket->ActualLength));
1346 INIT_HTC_PACKET_QUEUE_AND_ADD(&queue, pPacket);
1347 return htc_send_pkts_multiple(HTCHandle, &queue);
1348}
1349
1350#ifdef ATH_11AC_TXCOMPACT
1351
1352A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, cdf_nbuf_t netbuf, int Epid,
1353 int ActualLength)
1354{
1355 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1356 HTC_ENDPOINT *pEndpoint;
1357 HTC_FRAME_HDR *pHtcHdr;
1358 A_STATUS status = A_OK;
1359 int tx_resources;
1360 uint32_t data_attr = 0;
1361
Houston Hoffman29573d92015-10-20 17:49:44 -07001362 pEndpoint = &target->endpoint[Epid];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001363
1364 tx_resources =
1365 hif_get_free_queue_number(target->hif_dev, pEndpoint->UL_PipeID);
1366
1367 if (tx_resources < HTC_DATA_RESOURCE_THRS) {
1368 if (pEndpoint->ul_is_polled) {
1369 hif_send_complete_check(pEndpoint->target->hif_dev,
1370 pEndpoint->UL_PipeID, 1);
1371 tx_resources =
1372 hif_get_free_queue_number(target->hif_dev,
1373 pEndpoint->UL_PipeID);
1374 }
1375 if (tx_resources < HTC_DATA_MINDESC_PERPACKET) {
1376 return A_ERROR;
1377 }
1378 }
1379
Houston Hoffmanc5141b02015-11-18 02:36:30 -08001380 if (hif_pm_runtime_get(target->hif_dev))
1381 return A_ERROR;
1382
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001383 pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0);
1384 AR_DEBUG_ASSERT(pHtcHdr);
1385
1386 data_attr = cdf_nbuf_data_attr_get(netbuf);
1387
1388 HTC_WRITE32(pHtcHdr, SM(ActualLength, HTC_FRAME_HDR_PAYLOADLEN) |
1389 SM(Epid, HTC_FRAME_HDR_ENDPOINTID));
1390 /*
1391 * If the HIF pipe for the data endpoint is polled rather than
1392 * interrupt-driven, this is a good point to check whether any
1393 * data previously sent through the HIF pipe have finished being
1394 * sent.
1395 * Since this may result in callbacks to htc_tx_completion_handler,
1396 * which can take the HTC tx lock, make the hif_send_complete_check
1397 * call before acquiring the HTC tx lock.
1398 * Call hif_send_complete_check directly, rather than calling
1399 * htc_send_complete_check, and call the PollTimerStart separately
1400 * after calling hif_send_head, so the timer will be started to
1401 * check for completion of the new outstanding download (in the
1402 * unexpected event that other polling calls don't catch it).
1403 */
1404
1405 LOCK_HTC_TX(target);
1406
1407 HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1,
1408 SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1));
1409
1410 pEndpoint->SeqNo++;
1411
1412 NBUF_UPDATE_TX_PKT_COUNT(netbuf, NBUF_TX_PKT_HTC);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301413 DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001414 (uint8_t *)(cdf_nbuf_data(netbuf)),
1415 sizeof(cdf_nbuf_data(netbuf))));
1416 status = hif_send_head(target->hif_dev,
1417 pEndpoint->UL_PipeID,
1418 pEndpoint->Id, ActualLength, netbuf, data_attr);
1419
1420 UNLOCK_HTC_TX(target);
1421 return status;
1422}
1423#else /*ATH_11AC_TXCOMPACT */
1424
1425A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
1426 A_UINT8 more_data)
1427{
1428 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1429 HTC_ENDPOINT *pEndpoint;
1430 HTC_FRAME_HDR *pHtcHdr;
1431 HTC_PACKET_QUEUE sendQueue;
Rajeev Kumar926baab2016-01-06 18:11:55 -08001432 cdf_nbuf_t netbuf = NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001433 int tx_resources;
1434 A_STATUS status = A_OK;
1435 uint32_t data_attr = 0;
1436
1437 if (pPacket) {
1438 AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
Houston Hoffman29573d92015-10-20 17:49:44 -07001439 pEndpoint = &target->endpoint[pPacket->Endpoint];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001440
1441 /* add HTC_FRAME_HDR in the initial fragment */
1442 netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
1443 pHtcHdr = (HTC_FRAME_HDR *) cdf_nbuf_get_frag_vaddr(netbuf, 0);
1444 AR_DEBUG_ASSERT(pHtcHdr);
1445
1446 HTC_WRITE32(pHtcHdr,
1447 SM(pPacket->ActualLength,
1448 HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->PktInfo.
1449 AsTx.SendFlags,
1450 HTC_FRAME_HDR_FLAGS)
1451 | SM(pPacket->Endpoint, HTC_FRAME_HDR_ENDPOINTID));
1452 /*
1453 * If the HIF pipe for the data endpoint is polled rather than
1454 * interrupt-driven, this is a good point to check whether any
1455 * data previously sent through the HIF pipe have finished being
1456 * sent.
1457 * Since this may result in callbacks to htc_tx_completion_handler,
1458 * which can take the HTC tx lock, make the hif_send_complete_check
1459 * call before acquiring the HTC tx lock.
1460 * Call hif_send_complete_check directly, rather than calling
1461 * htc_send_complete_check, and call the PollTimerStart separately
1462 * after calling hif_send_head, so the timer will be started to
1463 * check for completion of the new outstanding download (in the
1464 * unexpected event that other polling calls don't catch it).
1465 */
1466 if (pEndpoint->ul_is_polled) {
1467 htc_send_complete_poll_timer_stop(pEndpoint);
1468 hif_send_complete_check(pEndpoint->target->hif_dev,
1469 pEndpoint->UL_PipeID, 0);
1470 }
1471
1472 LOCK_HTC_TX(target);
1473
1474 pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
1475 pEndpoint->SeqNo++;
1476
1477 HTC_WRITE32(((A_UINT32 *) pHtcHdr) + 1,
1478 SM(pPacket->PktInfo.AsTx.SeqNo,
1479 HTC_FRAME_HDR_CONTROLBYTES1));
1480
1481 /* append new packet to pEndpoint->TxQueue */
1482 HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket);
1483#ifdef ENABLE_BUNDLE_TX
1484 if (HTC_ENABLE_BUNDLE(target) && (more_data)) {
1485 UNLOCK_HTC_TX(target);
1486 return A_OK;
1487 }
1488#endif
1489 } else {
1490 LOCK_HTC_TX(target);
Houston Hoffman29573d92015-10-20 17:49:44 -07001491 pEndpoint = &target->endpoint[1];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001492 }
1493
1494 /* increment tx processing count on entry */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301495 qdf_atomic_inc(&pEndpoint->TxProcessCount);
1496 if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001497 /*
1498 * Another thread or task is draining the TX queues on this endpoint.
1499 * That thread will reset the tx processing count when the queue is
1500 * drained.
1501 */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301502 qdf_atomic_dec(&pEndpoint->TxProcessCount);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001503 UNLOCK_HTC_TX(target);
1504 return A_OK;
1505 }
1506
1507 /***** beyond this point only 1 thread may enter ******/
1508
1509 INIT_HTC_PACKET_QUEUE(&sendQueue);
1510 if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
1511#if DEBUG_CREDIT
1512 int cred = pEndpoint->TxCredits;
1513#endif
1514 get_htc_send_packets_credit_based(target, pEndpoint, &sendQueue);
1515#if DEBUG_CREDIT
1516 if (ep_debug_mask & (1 << pEndpoint->Id)) {
1517 if (cred - pEndpoint->TxCredits > 0) {
1518 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1519 (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
1520 pEndpoint->Id, cred,
1521 cred - pEndpoint->TxCredits,
1522 pEndpoint->TxCredits));
1523 }
1524 }
1525#endif
1526 UNLOCK_HTC_TX(target);
1527 }
1528#ifdef ENABLE_BUNDLE_TX
1529 else if (HTC_ENABLE_BUNDLE(target)) {
1530 /* Dequeue max packets from endpoint tx queue */
1531 get_htc_send_packets(target, pEndpoint, &sendQueue,
1532 HTC_MAX_TX_BUNDLE_SEND_LIMIT);
1533 UNLOCK_HTC_TX(target);
1534 }
1535#endif
1536 else {
1537 /*
1538 * Now drain the endpoint TX queue for transmission as long as we have
1539 * enough transmit resources
1540 */
1541 tx_resources =
1542 hif_get_free_queue_number(target->hif_dev,
1543 pEndpoint->UL_PipeID);
1544 get_htc_send_packets(target, pEndpoint, &sendQueue, tx_resources);
1545 UNLOCK_HTC_TX(target);
1546 }
1547 NBUF_UPDATE_TX_PKT_COUNT(netbuf, NBUF_TX_PKT_HTC);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301548 DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001549 (uint8_t *)(cdf_nbuf_data(netbuf)),
1550 sizeof(cdf_nbuf_data(netbuf))));
1551
1552 /* send what we can */
1553 while (true) {
1554#if defined(HIF_USB) || defined(HIF_SDIO)
1555#ifdef ENABLE_BUNDLE_TX
1556 if (HTC_ENABLE_BUNDLE(target) &&
1557 HTC_PACKET_QUEUE_DEPTH(&sendQueue) >=
1558 HTC_MIN_MSG_PER_BUNDLE) {
1559 htc_issue_packets_bundle(target, pEndpoint, &sendQueue);
1560 }
1561#endif
1562#endif
1563 pPacket = htc_packet_dequeue(&sendQueue);
1564 if (pPacket == NULL) {
1565 break;
1566 }
1567 netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
1568
1569 LOCK_HTC_TX(target);
1570 /* store in look up queue to match completions */
1571 HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
1572 INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
1573 pEndpoint->ul_outstanding_cnt++;
1574 UNLOCK_HTC_TX(target);
1575
1576 status = hif_send_head(target->hif_dev,
1577 pEndpoint->UL_PipeID,
1578 pEndpoint->Id,
1579 HTC_HDR_LENGTH + pPacket->ActualLength,
1580 netbuf, data_attr);
1581#if DEBUG_BUNDLE
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301582 qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001583 pEndpoint->Id,
1584 pEndpoint->TxCreditSize,
1585 HTC_HDR_LENGTH + pPacket->ActualLength);
1586#endif
1587
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301588 if (qdf_unlikely(A_FAILED(status))) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001589 LOCK_HTC_TX(target);
1590 pEndpoint->ul_outstanding_cnt--;
1591 /* remove this packet from the tx completion queue */
1592 HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
1593
1594 /*
1595 * Don't bother reclaiming credits - HTC flow control
1596 * is not applicable to tx data.
1597 * In LL systems, there is no download flow control,
1598 * since there's virtually no download delay.
1599 * In HL systems, the txrx SW explicitly performs the
1600 * tx flow control.
1601 */
1602 /* pEndpoint->TxCredits += pPacket->PktInfo.AsTx.CreditsUsed; */
1603
1604 /* put this frame back at the front of the sendQueue */
1605 HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket);
1606
1607 /* put the sendQueue back at the front of pEndpoint->TxQueue */
1608 HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
1609 &sendQueue);
1610 UNLOCK_HTC_TX(target);
1611 break; /* still need to reset TxProcessCount */
1612 }
1613 }
1614 /* done with this endpoint, we can clear the count */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301615 qdf_atomic_init(&pEndpoint->TxProcessCount);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001616
1617 if (pEndpoint->ul_is_polled) {
1618 /*
1619 * Start a cleanup timer to poll for download completion.
1620 * The download completion should be noticed promptly from
1621 * other polling calls, but the timer provides a safety net
1622 * in case other polling calls don't occur as expected.
1623 */
1624 htc_send_complete_poll_timer_start(pEndpoint);
1625 }
1626
1627 return status;
1628}
1629#endif /*ATH_11AC_TXCOMPACT */
1630
1631/*
1632 * In the adapted HIF layer, cdf_nbuf_t are passed between HIF and HTC, since upper layers expects
1633 * HTC_PACKET containers we use the completed netbuf and lookup its corresponding HTC packet buffer
1634 * from a lookup list.
1635 * This is extra overhead that can be fixed by re-aligning HIF interfaces with HTC.
1636 *
1637 */
1638static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target,
1639 HTC_ENDPOINT *pEndpoint,
1640 cdf_nbuf_t netbuf)
1641{
1642 HTC_PACKET *pPacket = NULL;
1643 HTC_PACKET *pFoundPacket = NULL;
1644 HTC_PACKET_QUEUE lookupQueue;
1645
1646 INIT_HTC_PACKET_QUEUE(&lookupQueue);
1647 LOCK_HTC_TX(target);
1648
1649 /* mark that HIF has indicated the send complete for another packet */
1650 pEndpoint->ul_outstanding_cnt--;
1651
1652 /* Dequeue first packet directly because of in-order completion */
1653 pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301654 if (qdf_unlikely(!pPacket)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001655 UNLOCK_HTC_TX(target);
1656 return NULL;
1657 }
1658 if (netbuf == (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
1659 UNLOCK_HTC_TX(target);
1660 return pPacket;
1661 } else {
1662 HTC_PACKET_ENQUEUE(&lookupQueue, pPacket);
1663 }
1664
1665 /*
1666 * Move TX lookup queue to temp queue because most of packets that are not index 0
1667 * are not top 10 packets.
1668 */
1669 HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue,
1670 &pEndpoint->TxLookupQueue);
1671 UNLOCK_HTC_TX(target);
1672
1673 ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket,
1674 HTC_PACKET, ListLink) {
1675
1676 if (NULL == pPacket) {
1677 pFoundPacket = pPacket;
1678 break;
1679 }
1680 /* check for removal */
1681 if (netbuf ==
1682 (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
1683 /* found it */
1684 HTC_PACKET_REMOVE(&lookupQueue, pPacket);
1685 pFoundPacket = pPacket;
1686 break;
1687 }
1688
1689 }
1690 ITERATE_END;
1691
1692 LOCK_HTC_TX(target);
1693 HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue,
1694 &lookupQueue);
1695 UNLOCK_HTC_TX(target);
1696
1697 return pFoundPacket;
1698}
1699
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301700QDF_STATUS htc_tx_completion_handler(void *Context,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701 cdf_nbuf_t netbuf, unsigned int EpID,
1702 uint32_t toeplitz_hash_result)
1703{
1704 HTC_TARGET *target = (HTC_TARGET *) Context;
1705 HTC_ENDPOINT *pEndpoint;
1706 HTC_PACKET *pPacket;
1707#ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301708 HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5, ENDPOINT_4,
1709 ENDPOINT_2, ENDPOINT_3 };
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001710 int epidIdx;
1711 A_UINT16 resourcesThresh[DATA_EP_SIZE]; /* urb resources */
1712 A_UINT16 resources;
1713 A_UINT16 resourcesMax;
1714#endif
1715
Houston Hoffman29573d92015-10-20 17:49:44 -07001716 pEndpoint = &target->endpoint[EpID];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001717 target->TX_comp_cnt++;
1718
1719 do {
1720 pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf);
1721 if (NULL == pPacket) {
1722 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1723 ("HTC TX lookup failed!\n"));
1724 /* may have already been flushed and freed */
1725 netbuf = NULL;
1726 break;
1727 }
Houston Hoffmanc5141b02015-11-18 02:36:30 -08001728 if (pPacket->PktInfo.AsTx.Tag != HTC_TX_PACKET_TAG_AUTO_PM)
1729 hif_pm_runtime_put(target->hif_dev);
1730
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001731 if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
1732 HTC_PACKET *pPacketTemp;
1733 HTC_PACKET_QUEUE *pQueueSave =
1734 (HTC_PACKET_QUEUE *) pPacket->pContext;
1735 HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave,
1736 pPacketTemp) {
1737 pPacket->Status = A_OK;
1738 send_packet_completion(target, pPacketTemp);
1739 }
1740 HTC_PACKET_QUEUE_ITERATE_END;
1741 free_htc_bundle_packet(target, pPacket);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301742 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001743 }
1744 /* will be giving this buffer back to upper layers */
1745 netbuf = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301746 pPacket->Status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001747 send_packet_completion(target, pPacket);
1748
1749 } while (false);
1750
1751 if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
1752 /* note: when using TX credit flow, the re-checking of queues happens
1753 * when credits flow back from the target.
1754 * in the non-TX credit case, we recheck after the packet completes */
1755 htc_try_send(target, pEndpoint, NULL);
1756 }
1757
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301758 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001759}
1760
1761/* callback when TX resources become available */
1762void htc_tx_resource_avail_handler(void *context, A_UINT8 pipeID)
1763{
1764 int i;
1765 HTC_TARGET *target = (HTC_TARGET *) context;
1766 HTC_ENDPOINT *pEndpoint = NULL;
1767
1768 for (i = 0; i < ENDPOINT_MAX; i++) {
Houston Hoffman29573d92015-10-20 17:49:44 -07001769 pEndpoint = &target->endpoint[i];
Houston Hoffman4f2f4592015-10-20 18:00:29 -07001770 if (pEndpoint->service_id != 0) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001771 if (pEndpoint->UL_PipeID == pipeID) {
1772 break;
1773 }
1774 }
1775 }
1776
1777 if (i >= ENDPOINT_MAX) {
1778 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1779 ("Invalid pipe indicated for TX resource avail : %d!\n",
1780 pipeID));
1781 return;
1782 }
1783
1784 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
1785 ("HIF indicated more resources for pipe:%d \n",
1786 pipeID));
1787
1788 htc_try_send(target, pEndpoint, NULL);
1789}
1790
Houston Hoffman47e387b2015-10-20 17:04:42 -07001791/**
1792 * htc_kick_queues(): resumes tx transactions of suspended endpoints
1793 * @context: pointer to the htc target context
1794 *
1795 * Iterates throught the enpoints and provides a context to empty queues
1796 * int the hif layer when they are stalled due to runtime suspend.
1797 *
1798 * Return: none
1799 */
1800void htc_kick_queues(void *context)
1801{
1802 int i;
1803 HTC_TARGET *target = (HTC_TARGET *)context;
1804 HTC_ENDPOINT *endpoint = NULL;
1805
1806 for (i = 0; i < ENDPOINT_MAX; i++) {
1807 endpoint = &target->endpoint[i];
1808
1809 if (endpoint->service_id == 0)
1810 continue;
1811
1812 if (endpoint->EpCallBacks.ep_resume_tx_queue)
1813 endpoint->EpCallBacks.ep_resume_tx_queue(
1814 endpoint->EpCallBacks.pContext);
1815
1816 htc_try_send(target, endpoint, NULL);
1817 }
1818}
1819
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001820/* flush endpoint TX queue */
1821void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
1822 HTC_TX_TAG Tag)
1823{
1824 HTC_PACKET *pPacket;
1825
1826 LOCK_HTC_TX(target);
1827 while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
1828 pPacket = htc_packet_dequeue(&pEndpoint->TxQueue);
1829
1830 if (pPacket) {
1831 /* let the sender know the packet was not delivered */
1832 pPacket->Status = A_ECANCELED;
1833 send_packet_completion(target, pPacket);
1834 }
1835 }
1836 UNLOCK_HTC_TX(target);
1837}
1838
1839/* HTC API to flush an endpoint's TX queue*/
1840void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
1841 HTC_TX_TAG Tag)
1842{
1843 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
Houston Hoffman29573d92015-10-20 17:49:44 -07001844 HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001845
Houston Hoffman4f2f4592015-10-20 18:00:29 -07001846 if (pEndpoint->service_id == 0) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001847 AR_DEBUG_ASSERT(false);
1848 /* not in use.. */
1849 return;
1850 }
1851
1852 htc_flush_endpoint_tx(target, pEndpoint, Tag);
1853}
1854
1855/* HTC API to indicate activity to the credit distribution function */
1856void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
1857 HTC_ENDPOINT_ID Endpoint, A_BOOL Active)
1858{
1859 /* TODO */
1860}
1861
1862A_BOOL htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
1863{
1864 return true;
1865}
1866
1867/* process credit reports and call distribution function */
1868void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt,
1869 int NumEntries, HTC_ENDPOINT_ID FromEndpoint)
1870{
1871 int i;
1872 HTC_ENDPOINT *pEndpoint;
1873 int totalCredits = 0;
1874 A_UINT8 rpt_credits, rpt_ep_id;
1875
1876 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
1877 ("+htc_process_credit_rpt, Credit Report Entries:%d \n",
1878 NumEntries));
1879
1880 /* lock out TX while we update credits */
1881 LOCK_HTC_TX(target);
1882
1883 for (i = 0; i < NumEntries; i++, pRpt++) {
1884
1885 rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID);
1886
1887 if (rpt_ep_id >= ENDPOINT_MAX) {
1888 AR_DEBUG_ASSERT(false);
1889 break;
1890 }
1891
1892 rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS);
1893
Houston Hoffman29573d92015-10-20 17:49:44 -07001894 pEndpoint = &target->endpoint[rpt_ep_id];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001895#if DEBUG_CREDIT
1896 if (ep_debug_mask & (1 << pEndpoint->Id)) {
1897 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1898 (" <HTC> Increase EP%d %d + %d = %d credits\n",
1899 rpt_ep_id, pEndpoint->TxCredits,
1900 rpt_credits,
1901 pEndpoint->TxCredits + rpt_credits));
1902 }
1903#endif
1904
1905#ifdef HTC_EP_STAT_PROFILING
1906
1907 INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1);
1908 INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits);
1909
1910 if (FromEndpoint == rpt_ep_id) {
1911 /* this credit report arrived on the same endpoint indicating it arrived in an RX
1912 * packet */
1913 INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx,
1914 rpt_credits);
1915 INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1);
1916 } else if (FromEndpoint == ENDPOINT_0) {
1917 /* this credit arrived on endpoint 0 as a NULL message */
1918 INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0,
1919 rpt_credits);
1920 INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1);
1921 } else {
1922 /* arrived on another endpoint */
1923 INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther,
1924 rpt_credits);
1925 INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1);
1926 }
1927
1928#endif
1929#if defined(HIF_USB)
1930 if (pEndpoint->Id >= ENDPOINT_2 && pEndpoint->Id <= ENDPOINT_5) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301931 HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5,
1932 ENDPOINT_4, ENDPOINT_2, ENDPOINT_3 };
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001933 int epid_idx;
1934
1935 target->avail_tx_credits += rpt_credits;
1936
1937 for (epid_idx = 0; epid_idx < DATA_EP_SIZE; epid_idx++) {
Houston Hoffman29573d92015-10-20 17:49:44 -07001938 pEndpoint = &target->endpoint[eid[epid_idx]];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001939 if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
1940 break;
1941 }
1942
1943 }
1944 UNLOCK_HTC_TX(target);
1945 htc_try_send(target, pEndpoint, NULL);
1946 LOCK_HTC_TX(target);
1947 } else {
1948 pEndpoint->TxCredits += rpt_credits;
1949
1950 if (pEndpoint->TxCredits
1951 && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
1952 UNLOCK_HTC_TX(target);
1953 htc_try_send(target, pEndpoint, NULL);
1954 LOCK_HTC_TX(target);
1955 }
1956 }
1957#else
1958 pEndpoint->TxCredits += rpt_credits;
1959
Houston Hoffman4f2f4592015-10-20 18:00:29 -07001960 if (pEndpoint->service_id == WMI_CONTROL_SVC) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001961 LOCK_HTC_CREDIT(target);
1962 htc_credit_record(HTC_PROCESS_CREDIT_REPORT,
1963 pEndpoint->TxCredits,
1964 HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
1965 TxQueue));
1966 UNLOCK_HTC_CREDIT(target);
1967 }
1968
1969 if (pEndpoint->TxCredits
1970 && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
1971 UNLOCK_HTC_TX(target);
1972#ifdef ATH_11AC_TXCOMPACT
1973 htc_try_send(target, pEndpoint, NULL);
1974#else
Houston Hoffman4f2f4592015-10-20 18:00:29 -07001975 if (pEndpoint->service_id == HTT_DATA_MSG_SVC) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001976 htc_send_data_pkt(target, NULL, 0);
1977 } else {
1978 htc_try_send(target, pEndpoint, NULL);
1979 }
1980#endif
1981 LOCK_HTC_TX(target);
1982 }
1983#endif
1984 totalCredits += rpt_credits;
1985 }
1986
1987 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
1988 (" Report indicated %d credits to distribute \n",
1989 totalCredits));
1990
1991 UNLOCK_HTC_TX(target);
1992
1993 AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt \n"));
1994}
1995
1996/* function to fetch stats from htc layer*/
1997struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle)
1998{
1999 HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
2000
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302001 return &(target->htc_pkt_stats);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002002}