htc_send.c 63 KB

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