htc_send.c 61 KB

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