htc_send.c 63 KB

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