htc_send.c 74 KB

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