htc_send.c 63 KB

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