htc_send.c 78 KB

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