htc_send.c 62 KB

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