htc_send.c 77 KB

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