htc_send.c 61 KB

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