htc_send.c 58 KB

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