htc_send.c 75 KB

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