htc_send.c 79 KB

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