htc_send.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  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. /**
  340. * htc_issue_packets_bundle() - HTC function to send bundle packets from a queue
  341. * @target: HTC target on which packets need to be sent
  342. * @pEndpoint: logical endpoint on which packets needs to be sent
  343. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  344. *
  345. * Return: void
  346. */
  347. static void htc_issue_packets_bundle(HTC_TARGET *target,
  348. HTC_ENDPOINT *pEndpoint,
  349. HTC_PACKET_QUEUE *pPktQueue)
  350. {
  351. int i, frag_count, nbytes;
  352. qdf_nbuf_t netbuf, bundleBuf;
  353. unsigned char *pBundleBuffer = NULL;
  354. HTC_PACKET *pPacket = NULL, *pPacketTx = NULL;
  355. HTC_FRAME_HDR *pHtcHdr;
  356. int last_credit_pad = 0;
  357. int creditPad, creditRemainder, transferLength, bundlesSpaceRemaining =
  358. 0;
  359. HTC_PACKET_QUEUE *pQueueSave = NULL;
  360. bundlesSpaceRemaining =
  361. target->MaxMsgsPerHTCBundle * pEndpoint->TxCreditSize;
  362. pPacketTx = allocate_htc_bundle_packet(target);
  363. if (!pPacketTx) {
  364. /* good time to panic */
  365. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  366. ("allocate_htc_bundle_packet failed \n"));
  367. AR_DEBUG_ASSERT(false);
  368. return;
  369. }
  370. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  371. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  372. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  373. while (1) {
  374. pPacket = htc_packet_dequeue(pPktQueue);
  375. if (pPacket == NULL) {
  376. break;
  377. }
  378. creditPad = 0;
  379. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  380. creditRemainder = transferLength % pEndpoint->TxCreditSize;
  381. if (creditRemainder != 0) {
  382. if (transferLength < pEndpoint->TxCreditSize) {
  383. creditPad =
  384. pEndpoint->TxCreditSize - transferLength;
  385. } else {
  386. creditPad = creditRemainder;
  387. }
  388. transferLength += creditPad;
  389. }
  390. if (bundlesSpaceRemaining < transferLength) {
  391. /* send out previous buffer */
  392. htc_send_bundled_netbuf(target, pEndpoint,
  393. pBundleBuffer - last_credit_pad,
  394. pPacketTx);
  395. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue) <
  396. HTC_MIN_MSG_PER_BUNDLE) {
  397. return;
  398. }
  399. bundlesSpaceRemaining =
  400. target->MaxMsgsPerHTCBundle *
  401. pEndpoint->TxCreditSize;
  402. pPacketTx = allocate_htc_bundle_packet(target);
  403. if (!pPacketTx) {
  404. /* good time to panic */
  405. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  406. ("allocate_htc_bundle_packet failed \n"));
  407. AR_DEBUG_ASSERT(false);
  408. return;
  409. }
  410. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  411. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  412. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  413. }
  414. bundlesSpaceRemaining -= transferLength;
  415. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  416. if (hif_get_bus_type(target->hif_dev) != QDF_BUS_TYPE_USB) {
  417. pHtcHdr =
  418. (HTC_FRAME_HDR *)
  419. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  420. HTC_WRITE32(pHtcHdr,
  421. SM(pPacket->ActualLength,
  422. HTC_FRAME_HDR_PAYLOADLEN) |
  423. SM(pPacket->PktInfo.AsTx.SendFlags |
  424. HTC_FLAGS_SEND_BUNDLE,
  425. HTC_FRAME_HDR_FLAGS) |
  426. SM(pPacket->Endpoint,
  427. HTC_FRAME_HDR_ENDPOINTID));
  428. HTC_WRITE32((uint32_t *) pHtcHdr + 1,
  429. SM(pPacket->PktInfo.AsTx.SeqNo,
  430. HTC_FRAME_HDR_CONTROLBYTES1) | SM(creditPad,
  431. HTC_FRAME_HDR_RESERVED));
  432. pHtcHdr->reserved = creditPad;
  433. }
  434. frag_count = qdf_nbuf_get_num_frags(netbuf);
  435. nbytes = pPacket->ActualLength + HTC_HDR_LENGTH;
  436. for (i = 0; i < frag_count && nbytes > 0; i++) {
  437. int frag_len = qdf_nbuf_get_frag_len(netbuf, i);
  438. unsigned char *frag_addr =
  439. qdf_nbuf_get_frag_vaddr(netbuf, i);
  440. if (frag_len > nbytes) {
  441. frag_len = nbytes;
  442. }
  443. qdf_mem_copy(pBundleBuffer, frag_addr, frag_len);
  444. nbytes -= frag_len;
  445. pBundleBuffer += frag_len;
  446. }
  447. HTC_PACKET_ENQUEUE(pQueueSave, pPacket);
  448. pBundleBuffer += creditPad;
  449. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) {
  450. /* last one can't be packed. */
  451. last_credit_pad = creditPad;
  452. }
  453. }
  454. if (pBundleBuffer != qdf_nbuf_data(bundleBuf)) {
  455. /* send out remaining buffer */
  456. htc_send_bundled_netbuf(target, pEndpoint,
  457. pBundleBuffer - last_credit_pad,
  458. pPacketTx);
  459. } else {
  460. free_htc_bundle_packet(target, pPacketTx);
  461. }
  462. }
  463. #endif /* ENABLE_BUNDLE_TX */
  464. #else
  465. static void htc_issue_packets_bundle(HTC_TARGET *target,
  466. HTC_ENDPOINT *pEndpoint,
  467. HTC_PACKET_QUEUE *pPktQueue)
  468. {
  469. }
  470. #endif
  471. /**
  472. * htc_issue_packets() - HTC function to send packets from a queue
  473. * @target: HTC target on which packets need to be sent
  474. * @pEndpoint: logical endpoint on which packets needs to be sent
  475. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  476. *
  477. * Return: QDF_STATUS_SUCCESS on success and error QDF status on failure
  478. */
  479. static A_STATUS htc_issue_packets(HTC_TARGET *target,
  480. HTC_ENDPOINT *pEndpoint,
  481. HTC_PACKET_QUEUE *pPktQueue)
  482. {
  483. A_STATUS status = A_OK;
  484. qdf_nbuf_t netbuf;
  485. HTC_PACKET *pPacket = NULL;
  486. uint16_t payloadLen;
  487. HTC_FRAME_HDR *pHtcHdr;
  488. uint32_t data_attr = 0;
  489. enum qdf_bus_type bus_type;
  490. bus_type = hif_get_bus_type(target->hif_dev);
  491. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  492. ("+htc_issue_packets: Queue: %p, Pkts %d \n", pPktQueue,
  493. HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  494. while (true) {
  495. if (HTC_TX_BUNDLE_ENABLED(target) &&
  496. HTC_PACKET_QUEUE_DEPTH(pPktQueue) >=
  497. HTC_MIN_MSG_PER_BUNDLE) {
  498. switch (bus_type) {
  499. case QDF_BUS_TYPE_SDIO:
  500. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  501. break;
  502. case QDF_BUS_TYPE_USB:
  503. htc_issue_packets_bundle(target,
  504. pEndpoint,
  505. pPktQueue);
  506. break;
  507. default:
  508. break;
  509. }
  510. }
  511. /* if not bundling or there was a packet that could not be placed in a bundle,
  512. * and send it by normal way
  513. */
  514. pPacket = htc_packet_dequeue(pPktQueue);
  515. if (NULL == pPacket) {
  516. /* local queue is fully drained */
  517. break;
  518. }
  519. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  520. AR_DEBUG_ASSERT(netbuf);
  521. /* Non-credit enabled endpoints have been mapped and setup by now,
  522. * so no need to revisit the HTC headers
  523. */
  524. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  525. payloadLen = pPacket->ActualLength;
  526. /* setup HTC frame header */
  527. pHtcHdr = (HTC_FRAME_HDR *)
  528. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  529. AR_DEBUG_ASSERT(pHtcHdr);
  530. HTC_WRITE32(pHtcHdr,
  531. SM(payloadLen,
  532. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->
  533. PktInfo.
  534. AsTx.
  535. SendFlags,
  536. HTC_FRAME_HDR_FLAGS)
  537. | SM(pPacket->Endpoint,
  538. HTC_FRAME_HDR_ENDPOINTID));
  539. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  540. SM(pPacket->PktInfo.AsTx.SeqNo,
  541. HTC_FRAME_HDR_CONTROLBYTES1));
  542. /*
  543. * Now that the HTC frame header has been added, the netbuf can be
  544. * mapped. This only applies to non-data frames, since data frames
  545. * were already mapped as they entered into the driver.
  546. * Check the "FIXUP_NETBUF" flag to see whether this is a data netbuf
  547. * that is already mapped, or a non-data netbuf that needs to be
  548. * mapped.
  549. */
  550. if (pPacket->PktInfo.AsTx.
  551. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
  552. qdf_nbuf_map(target->osdev,
  553. GET_HTC_PACKET_NET_BUF_CONTEXT
  554. (pPacket), QDF_DMA_TO_DEVICE);
  555. }
  556. }
  557. LOCK_HTC_TX(target);
  558. /* store in look up queue to match completions */
  559. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  560. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  561. pEndpoint->ul_outstanding_cnt++;
  562. UNLOCK_HTC_TX(target);
  563. hif_send_complete_check(target->hif_dev, pEndpoint->UL_PipeID, false);
  564. status = hif_send_head(target->hif_dev,
  565. pEndpoint->UL_PipeID, pEndpoint->Id,
  566. HTC_HDR_LENGTH + pPacket->ActualLength,
  567. netbuf, data_attr);
  568. #if DEBUG_BUNDLE
  569. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  570. pEndpoint->Id,
  571. pEndpoint->TxCreditSize,
  572. HTC_HDR_LENGTH + pPacket->ActualLength);
  573. #endif
  574. htc_issue_tx_bundle_stats_inc(target);
  575. target->ce_send_cnt++;
  576. if (qdf_unlikely(A_FAILED(status))) {
  577. if (status != A_NO_RESOURCE) {
  578. /* TODO : if more than 1 endpoint maps to the same PipeID it is possible
  579. * to run out of resources in the HIF layer. Don't emit the error */
  580. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  581. ("hif_send Failed status:%d \n",
  582. status));
  583. }
  584. LOCK_HTC_TX(target);
  585. target->ce_send_cnt--;
  586. pEndpoint->ul_outstanding_cnt--;
  587. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  588. /* reclaim credits */
  589. pEndpoint->TxCredits +=
  590. pPacket->PktInfo.AsTx.CreditsUsed;
  591. /* put it back into the callers queue */
  592. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  593. UNLOCK_HTC_TX(target);
  594. break;
  595. }
  596. /*
  597. * For HTT messages without a response from fw,
  598. * do the runtime put here.
  599. * otherwise runtime put will be done when the fw response comes
  600. */
  601. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
  602. hif_pm_runtime_put(target->hif_dev);
  603. }
  604. if (qdf_unlikely(A_FAILED(status))) {
  605. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  606. ("htc_issue_packets, failed pkt:0x%p status:%d",
  607. pPacket, status));
  608. }
  609. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets \n"));
  610. return status;
  611. }
  612. #ifdef FEATURE_RUNTIME_PM
  613. /**
  614. * extract_htc_pm_packtes(): move pm packets from endpoint into queue
  615. * @endpoint: which enpoint to extract packets from
  616. * @queue: a queue to store extracted packets in.
  617. *
  618. * remove pm packets from the endpoint's tx queue.
  619. * queue them into a queue
  620. */
  621. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  622. HTC_PACKET_QUEUE *queue)
  623. {
  624. HTC_PACKET *packet;
  625. /* only WMI endpoint has power management packets */
  626. if (endpoint->service_id != WMI_CONTROL_SVC)
  627. return;
  628. ITERATE_OVER_LIST_ALLOW_REMOVE(&endpoint->TxQueue.QueueHead, packet,
  629. HTC_PACKET, ListLink) {
  630. if (packet->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_AUTO_PM) {
  631. HTC_PACKET_REMOVE(&endpoint->TxQueue, packet);
  632. HTC_PACKET_ENQUEUE(queue, packet);
  633. }
  634. } ITERATE_END
  635. }
  636. /**
  637. * queue_htc_pm_packets(): queue pm packets with priority
  638. * @endpoint: enpoint to queue packets to
  639. * @queue: queue of pm packets to enque
  640. *
  641. * suspend resume packets get special treatment & priority.
  642. * need to queue them at the front of the queue.
  643. */
  644. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  645. HTC_PACKET_QUEUE *queue)
  646. {
  647. if (endpoint->service_id != WMI_CONTROL_SVC)
  648. return;
  649. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&endpoint->TxQueue, queue);
  650. }
  651. #else
  652. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  653. HTC_PACKET_QUEUE *queue)
  654. {}
  655. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  656. HTC_PACKET_QUEUE *queue)
  657. {}
  658. #endif
  659. /**
  660. * get_htc_send_packets_credit_based() - get packets based on available credits
  661. * @target: HTC target on which packets need to be sent
  662. * @pEndpoint: logical endpoint on which packets needs to be sent
  663. * @pQueue: HTC packet queue containing the list of packets to be sent
  664. *
  665. * Get HTC send packets from TX queue on an endpoint based on available credits.
  666. * The function moves the packets from TX queue of the endpoint to pQueue.
  667. *
  668. * Return: None
  669. */
  670. void get_htc_send_packets_credit_based(HTC_TARGET *target,
  671. HTC_ENDPOINT *pEndpoint,
  672. HTC_PACKET_QUEUE *pQueue)
  673. {
  674. int creditsRequired;
  675. int remainder;
  676. uint8_t sendFlags;
  677. HTC_PACKET *pPacket;
  678. unsigned int transferLength;
  679. HTC_PACKET_QUEUE *tx_queue;
  680. HTC_PACKET_QUEUE pm_queue;
  681. bool do_pm_get = false;
  682. /****** NOTE : the TX lock is held when this function is called *****************/
  683. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+get_htc_send_packets_credit_based\n"));
  684. INIT_HTC_PACKET_QUEUE(&pm_queue);
  685. extract_htc_pm_packets(pEndpoint, &pm_queue);
  686. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  687. tx_queue = &pEndpoint->TxQueue;
  688. do_pm_get = true;
  689. } else {
  690. tx_queue = &pm_queue;
  691. }
  692. /* loop until we can grab as many packets out of the queue as we can */
  693. while (true) {
  694. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  695. /* bus suspended, runtime resume issued */
  696. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  697. break;
  698. }
  699. sendFlags = 0;
  700. /* get packet at head, but don't remove it */
  701. pPacket = htc_get_pkt_at_head(tx_queue);
  702. if (pPacket == NULL) {
  703. if (do_pm_get)
  704. hif_pm_runtime_put(target->hif_dev);
  705. break;
  706. }
  707. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  708. (" Got head packet:%p , Queue Depth: %d\n",
  709. pPacket,
  710. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  711. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  712. if (transferLength <= pEndpoint->TxCreditSize) {
  713. creditsRequired = 1;
  714. } else {
  715. /* figure out how many credits this message requires */
  716. creditsRequired =
  717. transferLength / pEndpoint->TxCreditSize;
  718. remainder = transferLength % pEndpoint->TxCreditSize;
  719. if (remainder) {
  720. creditsRequired++;
  721. }
  722. }
  723. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  724. (" Credits Required:%d Got:%d\n",
  725. creditsRequired, pEndpoint->TxCredits));
  726. if (pEndpoint->Id == ENDPOINT_0) {
  727. /*
  728. * endpoint 0 is special, it always has a credit and
  729. * does not require credit based flow control
  730. */
  731. creditsRequired = 0;
  732. } else {
  733. if (pEndpoint->TxCredits < creditsRequired) {
  734. #if DEBUG_CREDIT
  735. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  736. (" EP%d, No Credit now. %d < %d\n",
  737. pEndpoint->Id,
  738. pEndpoint->TxCredits,
  739. creditsRequired));
  740. #endif
  741. if (do_pm_get)
  742. hif_pm_runtime_put(target->hif_dev);
  743. break;
  744. }
  745. pEndpoint->TxCredits -= creditsRequired;
  746. INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed,
  747. creditsRequired);
  748. /* check if we need credits back from the target */
  749. if (pEndpoint->TxCredits <=
  750. pEndpoint->TxCreditsPerMaxMsg) {
  751. /* tell the target we need credits ASAP! */
  752. sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
  753. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  754. LOCK_HTC_CREDIT(target);
  755. htc_credit_record(HTC_REQUEST_CREDIT,
  756. pEndpoint->TxCredits,
  757. HTC_PACKET_QUEUE_DEPTH
  758. (tx_queue));
  759. UNLOCK_HTC_CREDIT(target);
  760. }
  761. INC_HTC_EP_STAT(pEndpoint,
  762. TxCreditLowIndications, 1);
  763. #if DEBUG_CREDIT
  764. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  765. (" EP%d Needs Credits\n",
  766. pEndpoint->Id));
  767. #endif
  768. }
  769. }
  770. /* now we can fully dequeue */
  771. pPacket = htc_packet_dequeue(tx_queue);
  772. if (pPacket) {
  773. /* save the number of credits this packet consumed */
  774. pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired;
  775. /* save send flags */
  776. pPacket->PktInfo.AsTx.SendFlags = sendFlags;
  777. /* queue this packet into the caller's queue */
  778. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  779. }
  780. }
  781. if (!HTC_QUEUE_EMPTY(&pm_queue))
  782. queue_htc_pm_packets(pEndpoint, &pm_queue);
  783. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  784. ("-get_htc_send_packets_credit_based\n"));
  785. }
  786. void get_htc_send_packets(HTC_TARGET *target,
  787. HTC_ENDPOINT *pEndpoint,
  788. HTC_PACKET_QUEUE *pQueue, int Resources)
  789. {
  790. HTC_PACKET *pPacket;
  791. HTC_PACKET_QUEUE *tx_queue;
  792. HTC_PACKET_QUEUE pm_queue;
  793. bool do_pm_get;
  794. /****** NOTE : the TX lock is held when this function is called *****************/
  795. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  796. ("+get_htc_send_packets %d resources\n", Resources));
  797. INIT_HTC_PACKET_QUEUE(&pm_queue);
  798. extract_htc_pm_packets(pEndpoint, &pm_queue);
  799. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  800. tx_queue = &pEndpoint->TxQueue;
  801. do_pm_get = true;
  802. } else {
  803. tx_queue = &pm_queue;
  804. }
  805. /* loop until we can grab as many packets out of the queue as we can */
  806. while (Resources > 0) {
  807. int num_frags;
  808. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  809. /* bus suspended, runtime resume issued */
  810. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  811. break;
  812. }
  813. pPacket = htc_packet_dequeue(tx_queue);
  814. if (pPacket == NULL) {
  815. if (do_pm_get)
  816. hif_pm_runtime_put(target->hif_dev);
  817. break;
  818. }
  819. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  820. (" Got packet:%p , New Queue Depth: %d\n",
  821. pPacket,
  822. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  823. /* For non-credit path the sequence number is already embedded
  824. * in the constructed HTC header
  825. */
  826. #if 0
  827. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  828. pEndpoint->SeqNo++;
  829. #endif
  830. pPacket->PktInfo.AsTx.SendFlags = 0;
  831. pPacket->PktInfo.AsTx.CreditsUsed = 0;
  832. /* queue this packet into the caller's queue */
  833. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  834. /*
  835. * FIX THIS:
  836. * For now, avoid calling qdf_nbuf_get_num_frags before calling
  837. * qdf_nbuf_map, because the MacOS version of qdf_nbuf_t doesn't
  838. * support qdf_nbuf_get_num_frags until after qdf_nbuf_map has
  839. * been done.
  840. * Assume that the non-data netbufs, i.e. the WMI message netbufs,
  841. * consist of a single fragment.
  842. */
  843. num_frags =
  844. (pPacket->PktInfo.AsTx.
  845. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1
  846. /* WMI messages are in a single-fragment network buffer */ :
  847. qdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT
  848. (pPacket));
  849. Resources -= num_frags;
  850. }
  851. if (!HTC_QUEUE_EMPTY(&pm_queue))
  852. queue_htc_pm_packets(pEndpoint, &pm_queue);
  853. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets\n"));
  854. }
  855. /**
  856. * htc_try_send() - Send packets in a queue on an endpoint
  857. * @target: HTC target on which packets need to be sent
  858. * @pEndpoint: logical endpoint on which packets needs to be sent
  859. * @pCallersSendQueue: packet queue containing the list of packets to be sent
  860. *
  861. * Return: HTC_SEND_QUEUE_RESULT indicates whether the packet was queued to be
  862. * sent or the packet should be dropped by the upper layer
  863. */
  864. static HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target,
  865. HTC_ENDPOINT *pEndpoint,
  866. HTC_PACKET_QUEUE *pCallersSendQueue)
  867. {
  868. HTC_PACKET_QUEUE sendQueue; /* temp queue to hold packets at various stages */
  869. HTC_PACKET *pPacket;
  870. int tx_resources;
  871. int overflow;
  872. HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK;
  873. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%p Depth:%d)\n",
  874. pCallersSendQueue,
  875. (pCallersSendQueue ==
  876. NULL) ? 0 :
  877. HTC_PACKET_QUEUE_DEPTH
  878. (pCallersSendQueue)));
  879. /* init the local send queue */
  880. INIT_HTC_PACKET_QUEUE(&sendQueue);
  881. do {
  882. if (NULL == pCallersSendQueue) {
  883. /* caller didn't provide a queue, just wants us to check queues and send */
  884. break;
  885. }
  886. if (HTC_QUEUE_EMPTY(pCallersSendQueue)) {
  887. /* empty queue */
  888. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  889. HTC_PKT_Q_EMPTY);
  890. result = HTC_SEND_QUEUE_DROP;
  891. break;
  892. }
  893. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >=
  894. pEndpoint->MaxTxQueueDepth) {
  895. /* we've already overflowed */
  896. overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  897. } else {
  898. /* figure out how much we will overflow by */
  899. overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  900. overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  901. /* figure out how much we will overflow the TX queue by */
  902. overflow -= pEndpoint->MaxTxQueueDepth;
  903. }
  904. /* if overflow is negative or zero, we are okay */
  905. if (overflow > 0) {
  906. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  907. (" Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d \n",
  908. pEndpoint->Id, overflow,
  909. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  910. TxQueue),
  911. pEndpoint->MaxTxQueueDepth));
  912. }
  913. if ((overflow <= 0)
  914. || (pEndpoint->EpCallBacks.EpSendFull == NULL)) {
  915. /* all packets will fit or caller did not provide send full indication handler
  916. * -- just move all of them to the local sendQueue object */
  917. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue,
  918. pCallersSendQueue);
  919. } else {
  920. int i;
  921. int goodPkts =
  922. HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) -
  923. overflow;
  924. A_ASSERT(goodPkts >= 0);
  925. /* we have overflowed, and a callback is provided */
  926. /* dequeue all non-overflow packets into the sendqueue */
  927. for (i = 0; i < goodPkts; i++) {
  928. /* pop off caller's queue */
  929. pPacket = htc_packet_dequeue(pCallersSendQueue);
  930. A_ASSERT(pPacket != NULL);
  931. /* insert into local queue */
  932. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  933. }
  934. /* the caller's queue has all the packets that won't fit */
  935. /* walk through the caller's queue and indicate each one to the send full handler */
  936. ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->
  937. QueueHead, pPacket,
  938. HTC_PACKET, ListLink) {
  939. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  940. (" Indicating overflowed TX packet: %p \n",
  941. pPacket));
  942. /*
  943. * Remove headroom reserved for HTC_FRAME_HDR before giving
  944. * the packet back to the user via the EpSendFull callback.
  945. */
  946. restore_tx_packet(target, pPacket);
  947. if (pEndpoint->EpCallBacks.
  948. EpSendFull(pEndpoint->EpCallBacks.pContext,
  949. pPacket) == HTC_SEND_FULL_DROP) {
  950. /* callback wants the packet dropped */
  951. INC_HTC_EP_STAT(pEndpoint, TxDropped,
  952. 1);
  953. /* leave this one in the caller's queue for cleanup */
  954. } else {
  955. /* callback wants to keep this packet, remove from caller's queue */
  956. HTC_PACKET_REMOVE(pCallersSendQueue,
  957. pPacket);
  958. /* put it in the send queue */
  959. /* add HTC_FRAME_HDR space reservation again */
  960. qdf_nbuf_push_head
  961. (GET_HTC_PACKET_NET_BUF_CONTEXT
  962. (pPacket), sizeof(HTC_FRAME_HDR));
  963. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  964. }
  965. }
  966. ITERATE_END;
  967. if (HTC_QUEUE_EMPTY(&sendQueue)) {
  968. /* no packets made it in, caller will cleanup */
  969. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  970. HTC_SEND_Q_EMPTY);
  971. result = HTC_SEND_QUEUE_DROP;
  972. break;
  973. }
  974. }
  975. } while (false);
  976. if (result != HTC_SEND_QUEUE_OK) {
  977. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: %d\n",
  978. result));
  979. return result;
  980. }
  981. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  982. tx_resources =
  983. hif_get_free_queue_number(target->hif_dev,
  984. pEndpoint->UL_PipeID);
  985. } else {
  986. tx_resources = 0;
  987. }
  988. LOCK_HTC_TX(target);
  989. if (!HTC_QUEUE_EMPTY(&sendQueue)) {
  990. /* transfer packets to tail */
  991. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,
  992. &sendQueue);
  993. A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue));
  994. INIT_HTC_PACKET_QUEUE(&sendQueue);
  995. }
  996. /* increment tx processing count on entry */
  997. if (qdf_atomic_inc_return(&pEndpoint->TxProcessCount) > 1) {
  998. /* another thread or task is draining the TX queues on this endpoint
  999. * that thread will reset the tx processing count when the queue is drained */
  1000. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1001. UNLOCK_HTC_TX(target);
  1002. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy) \n"));
  1003. return HTC_SEND_QUEUE_OK;
  1004. }
  1005. /***** beyond this point only 1 thread may enter ******/
  1006. /* now drain the endpoint TX queue for transmission as long as we have enough
  1007. * transmit resources */
  1008. while (true) {
  1009. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0) {
  1010. break;
  1011. }
  1012. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1013. #if DEBUG_CREDIT
  1014. int cred = pEndpoint->TxCredits;
  1015. #endif
  1016. /* credit based mechanism provides flow control based on target transmit resource availability, we
  1017. * assume that the HIF layer will always have bus resources greater than target transmit resources */
  1018. get_htc_send_packets_credit_based(target, pEndpoint,
  1019. &sendQueue);
  1020. #if DEBUG_CREDIT
  1021. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1022. if (cred - pEndpoint->TxCredits > 0) {
  1023. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1024. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1025. pEndpoint->Id, cred,
  1026. cred -
  1027. pEndpoint->TxCredits,
  1028. pEndpoint->TxCredits));
  1029. }
  1030. }
  1031. #endif
  1032. } else {
  1033. /*
  1034. * Header and payload belongs to the different fragments and
  1035. * consume 2 resource for one HTC package but USB combine into
  1036. * one transfer.
  1037. */
  1038. if (HTC_TX_BUNDLE_ENABLED(target) && tx_resources &&
  1039. hif_get_bus_type(target->hif_dev) ==
  1040. QDF_BUS_TYPE_USB)
  1041. tx_resources = (HTC_MAX_MSG_PER_BUNDLE_TX * 2);
  1042. /* get all the packets for this endpoint that we can for this pass */
  1043. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1044. tx_resources);
  1045. }
  1046. if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) {
  1047. /* didn't get any packets due to a lack of resources or TX queue was drained */
  1048. break;
  1049. }
  1050. UNLOCK_HTC_TX(target);
  1051. /* send what we can */
  1052. result = htc_issue_packets(target, pEndpoint, &sendQueue);
  1053. if (result) {
  1054. int i;
  1055. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1056. ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue",
  1057. result));
  1058. for (i = HTC_PACKET_QUEUE_DEPTH(&sendQueue); i > 0; i--)
  1059. hif_pm_runtime_put(target->hif_dev);
  1060. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1061. &sendQueue);
  1062. LOCK_HTC_TX(target);
  1063. break;
  1064. }
  1065. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1066. tx_resources =
  1067. hif_get_free_queue_number(target->hif_dev,
  1068. pEndpoint->UL_PipeID);
  1069. }
  1070. LOCK_HTC_TX(target);
  1071. }
  1072. /* done with this endpoint, we can clear the count */
  1073. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1074. UNLOCK_HTC_TX(target);
  1075. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n"));
  1076. return HTC_SEND_QUEUE_OK;
  1077. }
  1078. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1079. static uint16_t htc_send_pkts_sched_check(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID id)
  1080. {
  1081. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1082. HTC_ENDPOINT *pEndpoint;
  1083. HTC_ENDPOINT_ID eid;
  1084. HTC_PACKET_QUEUE *pTxQueue;
  1085. uint16_t resources;
  1086. uint16_t acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 };
  1087. if (id < ENDPOINT_2 || id > ENDPOINT_5) {
  1088. return 1;
  1089. }
  1090. for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) {
  1091. pEndpoint = &target->endpoint[eid];
  1092. pTxQueue = &pEndpoint->TxQueue;
  1093. if (HTC_QUEUE_EMPTY(pTxQueue)) {
  1094. acQueueStatus[eid - 2] = 1;
  1095. }
  1096. }
  1097. switch (id) {
  1098. case ENDPOINT_2: /* BE */
  1099. return acQueueStatus[0] && acQueueStatus[2]
  1100. && acQueueStatus[3];
  1101. case ENDPOINT_3: /* BK */
  1102. return acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2]
  1103. && acQueueStatus[3];
  1104. case ENDPOINT_4: /* VI */
  1105. return acQueueStatus[2] && acQueueStatus[3];
  1106. case ENDPOINT_5: /* VO */
  1107. return acQueueStatus[3];
  1108. default:
  1109. return 0;
  1110. }
  1111. }
  1112. static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target,
  1113. HTC_PACKET_QUEUE *pPktQueue,
  1114. HTC_ENDPOINT_ID eid)
  1115. {
  1116. HTC_ENDPOINT *pEndpoint;
  1117. HTC_PACKET_QUEUE *pTxQueue;
  1118. HTC_PACKET *pPacket;
  1119. int goodPkts;
  1120. pEndpoint = &target->endpoint[eid];
  1121. pTxQueue = &pEndpoint->TxQueue;
  1122. LOCK_HTC_TX(target);
  1123. goodPkts =
  1124. pEndpoint->MaxTxQueueDepth -
  1125. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  1126. if (goodPkts > 0) {
  1127. while (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1128. pPacket = htc_packet_dequeue(pPktQueue);
  1129. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1130. goodPkts--;
  1131. if (goodPkts <= 0) {
  1132. break;
  1133. }
  1134. }
  1135. }
  1136. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) {
  1137. ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket,
  1138. HTC_PACKET, ListLink) {
  1139. if (pEndpoint->EpCallBacks.
  1140. EpSendFull(pEndpoint->EpCallBacks.pContext,
  1141. pPacket) == HTC_SEND_FULL_DROP) {
  1142. INC_HTC_EP_STAT(pEndpoint, TxDropped, 1);
  1143. } else {
  1144. HTC_PACKET_REMOVE(pPktQueue, pPacket);
  1145. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1146. }
  1147. }
  1148. ITERATE_END;
  1149. }
  1150. UNLOCK_HTC_TX(target);
  1151. return A_OK;
  1152. }
  1153. #endif
  1154. A_STATUS htc_send_pkts_multiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue)
  1155. {
  1156. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1157. HTC_ENDPOINT *pEndpoint;
  1158. HTC_PACKET *pPacket;
  1159. qdf_nbuf_t netbuf;
  1160. HTC_FRAME_HDR *pHtcHdr;
  1161. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1162. ("+htc_send_pkts_multiple: Queue: %p, Pkts %d \n",
  1163. pPktQueue, HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  1164. /* get packet at head to figure out which endpoint these packets will go into */
  1165. pPacket = htc_get_pkt_at_head(pPktQueue);
  1166. if (NULL == pPacket) {
  1167. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL);
  1168. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
  1169. return A_EINVAL;
  1170. }
  1171. AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
  1172. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1173. if (!pEndpoint->service_id) {
  1174. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n",
  1175. __func__));
  1176. return A_EINVAL;
  1177. }
  1178. #ifdef HTC_EP_STAT_PROFILING
  1179. LOCK_HTC_TX(target);
  1180. INC_HTC_EP_STAT(pEndpoint, TxPosted, HTC_PACKET_QUEUE_DEPTH(pPktQueue));
  1181. UNLOCK_HTC_TX(target);
  1182. #endif
  1183. /* provide room in each packet's netbuf for the HTC frame header */
  1184. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  1185. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1186. AR_DEBUG_ASSERT(netbuf);
  1187. qdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR));
  1188. /* setup HTC frame header */
  1189. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1190. AR_DEBUG_ASSERT(pHtcHdr);
  1191. HTC_WRITE32(pHtcHdr,
  1192. SM(pPacket->ActualLength,
  1193. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->Endpoint,
  1194. HTC_FRAME_HDR_ENDPOINTID));
  1195. LOCK_HTC_TX(target);
  1196. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1197. pEndpoint->SeqNo++;
  1198. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1199. SM(pPacket->PktInfo.AsTx.SeqNo,
  1200. HTC_FRAME_HDR_CONTROLBYTES1));
  1201. UNLOCK_HTC_TX(target);
  1202. /*
  1203. * Now that the HTC frame header has been added, the netbuf can be
  1204. * mapped. This only applies to non-data frames, since data frames
  1205. * were already mapped as they entered into the driver.
  1206. */
  1207. qdf_nbuf_map(target->osdev,
  1208. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  1209. QDF_DMA_TO_DEVICE);
  1210. pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  1211. }
  1212. HTC_PACKET_QUEUE_ITERATE_END;
  1213. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1214. if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id)) {
  1215. htc_send_pkts_sched_queue(HTCHandle, pPktQueue, pEndpoint->Id);
  1216. } else {
  1217. htc_try_send(target, pEndpoint, pPktQueue);
  1218. }
  1219. #else
  1220. htc_try_send(target, pEndpoint, pPktQueue);
  1221. #endif
  1222. /* do completion on any packets that couldn't get in */
  1223. if (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1224. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  1225. /* remove the headroom reserved for HTC_FRAME_HDR */
  1226. restore_tx_packet(target, pPacket);
  1227. if (HTC_STOPPING(target)) {
  1228. pPacket->Status = A_ECANCELED;
  1229. } else {
  1230. pPacket->Status = A_NO_RESOURCE;
  1231. }
  1232. }
  1233. HTC_PACKET_QUEUE_ITERATE_END;
  1234. do_send_completion(pEndpoint, pPktQueue);
  1235. }
  1236. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
  1237. return A_OK;
  1238. }
  1239. /* HTC API - htc_send_pkt */
  1240. A_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket)
  1241. {
  1242. HTC_PACKET_QUEUE queue;
  1243. if (HTCHandle == NULL || pPacket == NULL) {
  1244. return A_ERROR;
  1245. }
  1246. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1247. ("+-htc_send_pkt: Enter endPointId: %d, buffer: %p, length: %d \n",
  1248. pPacket->Endpoint, pPacket->pBuffer,
  1249. pPacket->ActualLength));
  1250. INIT_HTC_PACKET_QUEUE_AND_ADD(&queue, pPacket);
  1251. return htc_send_pkts_multiple(HTCHandle, &queue);
  1252. }
  1253. #ifdef ATH_11AC_TXCOMPACT
  1254. /**
  1255. * htc_send_data_pkt() - send single data packet on an endpoint
  1256. * @HTCHandle: pointer to HTC handle
  1257. * @netbuf: network buffer containing the data to be sent
  1258. * @ActualLength: length of data that needs to be transmitted
  1259. *
  1260. * Return: A_OK for success or an appropriate A_STATUS error
  1261. */
  1262. A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf, int Epid,
  1263. int ActualLength)
  1264. {
  1265. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1266. HTC_ENDPOINT *pEndpoint;
  1267. HTC_FRAME_HDR *pHtcHdr;
  1268. A_STATUS status = A_OK;
  1269. int tx_resources;
  1270. uint32_t data_attr = 0;
  1271. pEndpoint = &target->endpoint[Epid];
  1272. tx_resources =
  1273. hif_get_free_queue_number(target->hif_dev, pEndpoint->UL_PipeID);
  1274. if (tx_resources < HTC_DATA_RESOURCE_THRS) {
  1275. if (pEndpoint->ul_is_polled) {
  1276. hif_send_complete_check(pEndpoint->target->hif_dev,
  1277. pEndpoint->UL_PipeID, 1);
  1278. tx_resources =
  1279. hif_get_free_queue_number(target->hif_dev,
  1280. pEndpoint->UL_PipeID);
  1281. }
  1282. if (tx_resources < HTC_DATA_MINDESC_PERPACKET) {
  1283. return A_ERROR;
  1284. }
  1285. }
  1286. if (hif_pm_runtime_get(target->hif_dev))
  1287. return A_ERROR;
  1288. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1289. AR_DEBUG_ASSERT(pHtcHdr);
  1290. data_attr = qdf_nbuf_data_attr_get(netbuf);
  1291. HTC_WRITE32(pHtcHdr, SM(ActualLength, HTC_FRAME_HDR_PAYLOADLEN) |
  1292. SM(Epid, HTC_FRAME_HDR_ENDPOINTID));
  1293. /*
  1294. * If the HIF pipe for the data endpoint is polled rather than
  1295. * interrupt-driven, this is a good point to check whether any
  1296. * data previously sent through the HIF pipe have finished being
  1297. * sent.
  1298. * Since this may result in callbacks to htc_tx_completion_handler,
  1299. * which can take the HTC tx lock, make the hif_send_complete_check
  1300. * call before acquiring the HTC tx lock.
  1301. * Call hif_send_complete_check directly, rather than calling
  1302. * htc_send_complete_check, and call the PollTimerStart separately
  1303. * after calling hif_send_head, so the timer will be started to
  1304. * check for completion of the new outstanding download (in the
  1305. * unexpected event that other polling calls don't catch it).
  1306. */
  1307. LOCK_HTC_TX(target);
  1308. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1309. SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1));
  1310. pEndpoint->SeqNo++;
  1311. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1312. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1313. qdf_nbuf_data_addr(netbuf),
  1314. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1315. status = hif_send_head(target->hif_dev,
  1316. pEndpoint->UL_PipeID,
  1317. pEndpoint->Id, ActualLength, netbuf, data_attr);
  1318. UNLOCK_HTC_TX(target);
  1319. return status;
  1320. }
  1321. #else /*ATH_11AC_TXCOMPACT */
  1322. /**
  1323. * htc_send_data_pkt() - htc_send_data_pkt
  1324. * @HTCHandle: pointer to HTC handle
  1325. * @pPacket: pointer to HTC_PACKET
  1326. * @more_data: indicates whether more data is to follow
  1327. *
  1328. * Return: A_OK for success or an appropriate A_STATUS error
  1329. */
  1330. A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  1331. uint8_t more_data)
  1332. {
  1333. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1334. HTC_ENDPOINT *pEndpoint;
  1335. HTC_FRAME_HDR *pHtcHdr;
  1336. HTC_PACKET_QUEUE sendQueue;
  1337. qdf_nbuf_t netbuf = NULL;
  1338. int tx_resources;
  1339. A_STATUS status = A_OK;
  1340. uint32_t data_attr = 0;
  1341. if (pPacket) {
  1342. AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
  1343. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1344. /* add HTC_FRAME_HDR in the initial fragment */
  1345. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1346. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1347. AR_DEBUG_ASSERT(pHtcHdr);
  1348. HTC_WRITE32(pHtcHdr,
  1349. SM(pPacket->ActualLength,
  1350. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->PktInfo.
  1351. AsTx.SendFlags,
  1352. HTC_FRAME_HDR_FLAGS)
  1353. | SM(pPacket->Endpoint, HTC_FRAME_HDR_ENDPOINTID));
  1354. /*
  1355. * If the HIF pipe for the data endpoint is polled rather than
  1356. * interrupt-driven, this is a good point to check whether any
  1357. * data previously sent through the HIF pipe have finished being
  1358. * sent.
  1359. * Since this may result in callbacks to htc_tx_completion_handler,
  1360. * which can take the HTC tx lock, make the hif_send_complete_check
  1361. * call before acquiring the HTC tx lock.
  1362. * Call hif_send_complete_check directly, rather than calling
  1363. * htc_send_complete_check, and call the PollTimerStart separately
  1364. * after calling hif_send_head, so the timer will be started to
  1365. * check for completion of the new outstanding download (in the
  1366. * unexpected event that other polling calls don't catch it).
  1367. */
  1368. if (pEndpoint->ul_is_polled) {
  1369. htc_send_complete_poll_timer_stop(pEndpoint);
  1370. hif_send_complete_check(pEndpoint->target->hif_dev,
  1371. pEndpoint->UL_PipeID, 0);
  1372. }
  1373. LOCK_HTC_TX(target);
  1374. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1375. pEndpoint->SeqNo++;
  1376. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1377. SM(pPacket->PktInfo.AsTx.SeqNo,
  1378. HTC_FRAME_HDR_CONTROLBYTES1));
  1379. /* append new packet to pEndpoint->TxQueue */
  1380. HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket);
  1381. if (HTC_TX_BUNDLE_ENABLED(target) && (more_data)) {
  1382. UNLOCK_HTC_TX(target);
  1383. return A_OK;
  1384. }
  1385. } else {
  1386. LOCK_HTC_TX(target);
  1387. pEndpoint = &target->endpoint[1];
  1388. }
  1389. /* increment tx processing count on entry */
  1390. qdf_atomic_inc(&pEndpoint->TxProcessCount);
  1391. if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
  1392. /*
  1393. * Another thread or task is draining the TX queues on this endpoint.
  1394. * That thread will reset the tx processing count when the queue is
  1395. * drained.
  1396. */
  1397. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1398. UNLOCK_HTC_TX(target);
  1399. return A_OK;
  1400. }
  1401. /***** beyond this point only 1 thread may enter ******/
  1402. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1403. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1404. #if DEBUG_CREDIT
  1405. int cred = pEndpoint->TxCredits;
  1406. #endif
  1407. get_htc_send_packets_credit_based(target, pEndpoint, &sendQueue);
  1408. #if DEBUG_CREDIT
  1409. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1410. if (cred - pEndpoint->TxCredits > 0) {
  1411. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1412. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1413. pEndpoint->Id, cred,
  1414. cred - pEndpoint->TxCredits,
  1415. pEndpoint->TxCredits));
  1416. }
  1417. }
  1418. #endif
  1419. UNLOCK_HTC_TX(target);
  1420. }
  1421. else if (HTC_TX_BUNDLE_ENABLED(target)) {
  1422. if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) &&
  1423. hif_get_free_queue_number(target->hif_dev,
  1424. pEndpoint->UL_PipeID)) {
  1425. /*
  1426. * Header and payload belongs to the different fragments
  1427. * and consume 2 resource for one HTC package but USB
  1428. * combine into one transfer.
  1429. */
  1430. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1431. (HTC_MAX_MSG_PER_BUNDLE_TX * 2));
  1432. } else {
  1433. /* Dequeue max packets from endpoint tx queue */
  1434. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1435. HTC_MAX_TX_BUNDLE_SEND_LIMIT);
  1436. }
  1437. UNLOCK_HTC_TX(target);
  1438. }
  1439. else {
  1440. /*
  1441. * Now drain the endpoint TX queue for transmission as long as we have
  1442. * enough transmit resources
  1443. */
  1444. tx_resources =
  1445. hif_get_free_queue_number(target->hif_dev,
  1446. pEndpoint->UL_PipeID);
  1447. get_htc_send_packets(target, pEndpoint, &sendQueue, tx_resources);
  1448. UNLOCK_HTC_TX(target);
  1449. }
  1450. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1451. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1452. qdf_nbuf_data_addr(netbuf),
  1453. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1454. /* send what we can */
  1455. while (true) {
  1456. if (HTC_TX_BUNDLE_ENABLED(target) &&
  1457. (HTC_PACKET_QUEUE_DEPTH(&sendQueue) >=
  1458. HTC_MIN_MSG_PER_BUNDLE) &&
  1459. (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO ||
  1460. hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB)) {
  1461. htc_issue_packets_bundle(target, pEndpoint, &sendQueue);
  1462. }
  1463. pPacket = htc_packet_dequeue(&sendQueue);
  1464. if (pPacket == NULL) {
  1465. break;
  1466. }
  1467. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1468. LOCK_HTC_TX(target);
  1469. /* store in look up queue to match completions */
  1470. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  1471. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  1472. pEndpoint->ul_outstanding_cnt++;
  1473. UNLOCK_HTC_TX(target);
  1474. status = hif_send_head(target->hif_dev,
  1475. pEndpoint->UL_PipeID,
  1476. pEndpoint->Id,
  1477. HTC_HDR_LENGTH + pPacket->ActualLength,
  1478. netbuf, data_attr);
  1479. #if DEBUG_BUNDLE
  1480. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  1481. pEndpoint->Id,
  1482. pEndpoint->TxCreditSize,
  1483. HTC_HDR_LENGTH + pPacket->ActualLength);
  1484. #endif
  1485. htc_issue_tx_bundle_stats_inc(target);
  1486. if (qdf_unlikely(A_FAILED(status))) {
  1487. LOCK_HTC_TX(target);
  1488. pEndpoint->ul_outstanding_cnt--;
  1489. /* remove this packet from the tx completion queue */
  1490. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  1491. /*
  1492. * Don't bother reclaiming credits - HTC flow control
  1493. * is not applicable to tx data.
  1494. * In LL systems, there is no download flow control,
  1495. * since there's virtually no download delay.
  1496. * In HL systems, the txrx SW explicitly performs the
  1497. * tx flow control.
  1498. */
  1499. /* pEndpoint->TxCredits += pPacket->PktInfo.AsTx.CreditsUsed; */
  1500. /* put this frame back at the front of the sendQueue */
  1501. HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket);
  1502. /* put the sendQueue back at the front of pEndpoint->TxQueue */
  1503. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1504. &sendQueue);
  1505. UNLOCK_HTC_TX(target);
  1506. break; /* still need to reset TxProcessCount */
  1507. }
  1508. }
  1509. /* done with this endpoint, we can clear the count */
  1510. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1511. if (pEndpoint->ul_is_polled) {
  1512. /*
  1513. * Start a cleanup timer to poll for download completion.
  1514. * The download completion should be noticed promptly from
  1515. * other polling calls, but the timer provides a safety net
  1516. * in case other polling calls don't occur as expected.
  1517. */
  1518. htc_send_complete_poll_timer_start(pEndpoint);
  1519. }
  1520. return status;
  1521. }
  1522. #endif /*ATH_11AC_TXCOMPACT */
  1523. /*
  1524. * In the adapted HIF layer, qdf_nbuf_t are passed between HIF and HTC,
  1525. * since upper layers expects HTC_PACKET containers we use the completed netbuf
  1526. * and lookup its corresponding HTC packet buffer from a lookup list.
  1527. * This is extra overhead that can be fixed by re-aligning HIF interfaces
  1528. * with HTC.
  1529. *
  1530. */
  1531. static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target,
  1532. HTC_ENDPOINT *pEndpoint,
  1533. qdf_nbuf_t netbuf)
  1534. {
  1535. HTC_PACKET *pPacket = NULL;
  1536. HTC_PACKET *pFoundPacket = NULL;
  1537. HTC_PACKET_QUEUE lookupQueue;
  1538. INIT_HTC_PACKET_QUEUE(&lookupQueue);
  1539. LOCK_HTC_TX(target);
  1540. /* mark that HIF has indicated the send complete for another packet */
  1541. pEndpoint->ul_outstanding_cnt--;
  1542. /* Dequeue first packet directly because of in-order completion */
  1543. pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue);
  1544. if (qdf_unlikely(!pPacket)) {
  1545. UNLOCK_HTC_TX(target);
  1546. return NULL;
  1547. }
  1548. if (netbuf == (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1549. UNLOCK_HTC_TX(target);
  1550. return pPacket;
  1551. } else {
  1552. HTC_PACKET_ENQUEUE(&lookupQueue, pPacket);
  1553. }
  1554. /*
  1555. * Move TX lookup queue to temp queue because most of packets that are not index 0
  1556. * are not top 10 packets.
  1557. */
  1558. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue,
  1559. &pEndpoint->TxLookupQueue);
  1560. UNLOCK_HTC_TX(target);
  1561. ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket,
  1562. HTC_PACKET, ListLink) {
  1563. if (NULL == pPacket) {
  1564. pFoundPacket = pPacket;
  1565. break;
  1566. }
  1567. /* check for removal */
  1568. if (netbuf ==
  1569. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1570. /* found it */
  1571. HTC_PACKET_REMOVE(&lookupQueue, pPacket);
  1572. pFoundPacket = pPacket;
  1573. break;
  1574. }
  1575. }
  1576. ITERATE_END;
  1577. LOCK_HTC_TX(target);
  1578. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue,
  1579. &lookupQueue);
  1580. UNLOCK_HTC_TX(target);
  1581. return pFoundPacket;
  1582. }
  1583. /**
  1584. * htc_tx_completion_handler() - htc tx completion handler
  1585. * @Context: pointer to HTC_TARGET structure
  1586. * @netbuf: pointer to netbuf for which completion handler is being called
  1587. * @EpID: end point Id on which the packet was sent
  1588. * @toeplitz_hash_result: toeplitz hash result
  1589. *
  1590. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1591. */
  1592. QDF_STATUS htc_tx_completion_handler(void *Context,
  1593. qdf_nbuf_t netbuf, unsigned int EpID,
  1594. uint32_t toeplitz_hash_result)
  1595. {
  1596. HTC_TARGET *target = (HTC_TARGET *) Context;
  1597. HTC_ENDPOINT *pEndpoint;
  1598. HTC_PACKET *pPacket;
  1599. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1600. HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5, ENDPOINT_4,
  1601. ENDPOINT_2, ENDPOINT_3 };
  1602. int epidIdx;
  1603. uint16_t resourcesThresh[DATA_EP_SIZE]; /* urb resources */
  1604. uint16_t resources;
  1605. uint16_t resourcesMax;
  1606. #endif
  1607. pEndpoint = &target->endpoint[EpID];
  1608. target->TX_comp_cnt++;
  1609. do {
  1610. pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf);
  1611. if (NULL == pPacket) {
  1612. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1613. ("HTC TX lookup failed!\n"));
  1614. /* may have already been flushed and freed */
  1615. netbuf = NULL;
  1616. break;
  1617. }
  1618. if (pPacket->PktInfo.AsTx.Tag != HTC_TX_PACKET_TAG_AUTO_PM)
  1619. hif_pm_runtime_put(target->hif_dev);
  1620. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
  1621. HTC_PACKET *pPacketTemp;
  1622. HTC_PACKET_QUEUE *pQueueSave =
  1623. (HTC_PACKET_QUEUE *) pPacket->pContext;
  1624. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave,
  1625. pPacketTemp) {
  1626. pPacket->Status = A_OK;
  1627. send_packet_completion(target, pPacketTemp);
  1628. }
  1629. HTC_PACKET_QUEUE_ITERATE_END;
  1630. free_htc_bundle_packet(target, pPacket);
  1631. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) {
  1632. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  1633. htc_try_send(target, pEndpoint, NULL);
  1634. }
  1635. return QDF_STATUS_SUCCESS;
  1636. }
  1637. /* will be giving this buffer back to upper layers */
  1638. netbuf = NULL;
  1639. pPacket->Status = QDF_STATUS_SUCCESS;
  1640. send_packet_completion(target, pPacket);
  1641. } while (false);
  1642. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1643. /* note: when using TX credit flow, the re-checking of queues happens
  1644. * when credits flow back from the target.
  1645. * in the non-TX credit case, we recheck after the packet completes */
  1646. htc_try_send(target, pEndpoint, NULL);
  1647. }
  1648. return QDF_STATUS_SUCCESS;
  1649. }
  1650. #ifdef WLAN_FEATURE_FASTPATH
  1651. /**
  1652. * htc_ctrl_msg_cmpl(): checks for tx completion for the endpoint specified
  1653. * @HTC_HANDLE : pointer to the htc target context
  1654. * @htc_ep_id : end point id
  1655. *
  1656. * checks HTC tx completion
  1657. *
  1658. * Return: none
  1659. */
  1660. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id)
  1661. {
  1662. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_pdev);
  1663. HTC_ENDPOINT *pendpoint = &target->endpoint[htc_ep_id];
  1664. htc_send_complete_check(pendpoint, 1);
  1665. }
  1666. #endif
  1667. /* callback when TX resources become available */
  1668. void htc_tx_resource_avail_handler(void *context, uint8_t pipeID)
  1669. {
  1670. int i;
  1671. HTC_TARGET *target = (HTC_TARGET *) context;
  1672. HTC_ENDPOINT *pEndpoint = NULL;
  1673. for (i = 0; i < ENDPOINT_MAX; i++) {
  1674. pEndpoint = &target->endpoint[i];
  1675. if (pEndpoint->service_id != 0) {
  1676. if (pEndpoint->UL_PipeID == pipeID) {
  1677. break;
  1678. }
  1679. }
  1680. }
  1681. if (i >= ENDPOINT_MAX) {
  1682. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1683. ("Invalid pipe indicated for TX resource avail : %d!\n",
  1684. pipeID));
  1685. return;
  1686. }
  1687. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1688. ("HIF indicated more resources for pipe:%d \n",
  1689. pipeID));
  1690. htc_try_send(target, pEndpoint, NULL);
  1691. }
  1692. #ifdef FEATURE_RUNTIME_PM
  1693. /**
  1694. * htc_kick_queues(): resumes tx transactions of suspended endpoints
  1695. * @context: pointer to the htc target context
  1696. *
  1697. * Iterates throught the enpoints and provides a context to empty queues
  1698. * int the hif layer when they are stalled due to runtime suspend.
  1699. *
  1700. * Return: none
  1701. */
  1702. void htc_kick_queues(void *context)
  1703. {
  1704. int i;
  1705. HTC_TARGET *target = (HTC_TARGET *)context;
  1706. HTC_ENDPOINT *endpoint = NULL;
  1707. for (i = 0; i < ENDPOINT_MAX; i++) {
  1708. endpoint = &target->endpoint[i];
  1709. if (endpoint->service_id == 0)
  1710. continue;
  1711. if (endpoint->EpCallBacks.ep_resume_tx_queue)
  1712. endpoint->EpCallBacks.ep_resume_tx_queue(
  1713. endpoint->EpCallBacks.pContext);
  1714. htc_try_send(target, endpoint, NULL);
  1715. }
  1716. }
  1717. #endif
  1718. /* flush endpoint TX queue */
  1719. void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
  1720. HTC_TX_TAG Tag)
  1721. {
  1722. HTC_PACKET *pPacket;
  1723. LOCK_HTC_TX(target);
  1724. while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1725. pPacket = htc_packet_dequeue(&pEndpoint->TxQueue);
  1726. if (pPacket) {
  1727. /* let the sender know the packet was not delivered */
  1728. pPacket->Status = A_ECANCELED;
  1729. send_packet_completion(target, pPacket);
  1730. }
  1731. }
  1732. UNLOCK_HTC_TX(target);
  1733. }
  1734. /* HTC API to flush an endpoint's TX queue*/
  1735. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  1736. HTC_TX_TAG Tag)
  1737. {
  1738. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1739. HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
  1740. if (pEndpoint->service_id == 0) {
  1741. AR_DEBUG_ASSERT(false);
  1742. /* not in use.. */
  1743. return;
  1744. }
  1745. htc_flush_endpoint_tx(target, pEndpoint, Tag);
  1746. }
  1747. /* HTC API to indicate activity to the credit distribution function */
  1748. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  1749. HTC_ENDPOINT_ID Endpoint, bool Active)
  1750. {
  1751. /* TODO */
  1752. }
  1753. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
  1754. {
  1755. return true;
  1756. }
  1757. /**
  1758. * htc_process_credit_rpt() - process credit report, call distribution function
  1759. * @target: pointer to HTC_TARGET
  1760. * @pRpt: pointer to HTC_CREDIT_REPORT
  1761. * @NumEntries: number of entries in credit report
  1762. * @FromEndpoint: endpoint for which credit report is received
  1763. *
  1764. * Return: A_OK for success or an appropriate A_STATUS error
  1765. */
  1766. void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt,
  1767. int NumEntries, HTC_ENDPOINT_ID FromEndpoint)
  1768. {
  1769. int i;
  1770. HTC_ENDPOINT *pEndpoint;
  1771. int totalCredits = 0;
  1772. uint8_t rpt_credits, rpt_ep_id;
  1773. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1774. ("+htc_process_credit_rpt, Credit Report Entries:%d \n",
  1775. NumEntries));
  1776. /* lock out TX while we update credits */
  1777. LOCK_HTC_TX(target);
  1778. for (i = 0; i < NumEntries; i++, pRpt++) {
  1779. rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID);
  1780. if (rpt_ep_id >= ENDPOINT_MAX) {
  1781. AR_DEBUG_ASSERT(false);
  1782. break;
  1783. }
  1784. rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS);
  1785. pEndpoint = &target->endpoint[rpt_ep_id];
  1786. #if DEBUG_CREDIT
  1787. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1788. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1789. (" <HTC> Increase EP%d %d + %d = %d credits\n",
  1790. rpt_ep_id, pEndpoint->TxCredits,
  1791. rpt_credits,
  1792. pEndpoint->TxCredits + rpt_credits));
  1793. }
  1794. #endif
  1795. #ifdef HTC_EP_STAT_PROFILING
  1796. INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1);
  1797. INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits);
  1798. if (FromEndpoint == rpt_ep_id) {
  1799. /* this credit report arrived on the same endpoint indicating it arrived in an RX
  1800. * packet */
  1801. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx,
  1802. rpt_credits);
  1803. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1);
  1804. } else if (FromEndpoint == ENDPOINT_0) {
  1805. /* this credit arrived on endpoint 0 as a NULL message */
  1806. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0,
  1807. rpt_credits);
  1808. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1);
  1809. } else {
  1810. /* arrived on another endpoint */
  1811. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther,
  1812. rpt_credits);
  1813. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1);
  1814. }
  1815. #endif
  1816. pEndpoint->TxCredits += rpt_credits;
  1817. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  1818. LOCK_HTC_CREDIT(target);
  1819. htc_credit_record(HTC_PROCESS_CREDIT_REPORT,
  1820. pEndpoint->TxCredits,
  1821. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  1822. TxQueue));
  1823. UNLOCK_HTC_CREDIT(target);
  1824. }
  1825. if (pEndpoint->TxCredits
  1826. && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1827. UNLOCK_HTC_TX(target);
  1828. #ifdef ATH_11AC_TXCOMPACT
  1829. htc_try_send(target, pEndpoint, NULL);
  1830. #else
  1831. if (pEndpoint->service_id == HTT_DATA_MSG_SVC) {
  1832. htc_send_data_pkt(target, NULL, 0);
  1833. } else {
  1834. htc_try_send(target, pEndpoint, NULL);
  1835. }
  1836. #endif
  1837. LOCK_HTC_TX(target);
  1838. }
  1839. totalCredits += rpt_credits;
  1840. }
  1841. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1842. (" Report indicated %d credits to distribute \n",
  1843. totalCredits));
  1844. UNLOCK_HTC_TX(target);
  1845. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt \n"));
  1846. }
  1847. /* function to fetch stats from htc layer*/
  1848. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle)
  1849. {
  1850. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1851. return &(target->htc_pkt_stats);
  1852. }