htc_send.c 74 KB

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