htc_send.c 78 KB

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