htc_send.c 65 KB

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