htc_send.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  1. /*
  2. * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #include "htc_debug.h"
  27. #include "htc_internal.h"
  28. #include <qdf_mem.h> /* qdf_mem_malloc */
  29. #include <qdf_nbuf.h> /* qdf_nbuf_t */
  30. /* #define USB_HIF_SINGLE_PIPE_DATA_SCHED */
  31. /* #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED */
  32. #define DATA_EP_SIZE 4
  33. /* #endif */
  34. #define HTC_DATA_RESOURCE_THRS 256
  35. #define HTC_DATA_MINDESC_PERPACKET 2
  36. typedef enum _HTC_SEND_QUEUE_RESULT {
  37. HTC_SEND_QUEUE_OK = 0, /* packet was queued */
  38. HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */
  39. } HTC_SEND_QUEUE_RESULT;
  40. #ifndef DEBUG_CREDIT
  41. #define DEBUG_CREDIT 0
  42. #endif
  43. #if DEBUG_CREDIT
  44. /* bit mask to enable debug certain endpoint */
  45. static unsigned ep_debug_mask =
  46. (1 << ENDPOINT_0) | (1 << ENDPOINT_1) | (1 << ENDPOINT_2);
  47. #endif
  48. /* HTC Control Path Credit History */
  49. uint32_t g_htc_credit_history_idx = 0;
  50. HTC_CREDIT_HISTORY htc_credit_history_buffer[HTC_CREDIT_HISTORY_MAX];
  51. /**
  52. * htc_credit_record() - records tx que state & credit transactions
  53. * @type: type of echange can be HTC_REQUEST_CREDIT
  54. * or HTC_PROCESS_CREDIT_REPORT
  55. * @tx_credits: current number of tx_credits
  56. * @htc_tx_queue_depth: current hct tx queue depth
  57. *
  58. * This function records the credits and pending commands whenever a command is
  59. * sent or credits are returned. Call this after the credits have been updated
  60. * according to the transaction. Call this before dequeing commands.
  61. *
  62. * Consider making this function accept an HTC_ENDPOINT and find the current
  63. * credits and queue depth itself.
  64. *
  65. * Consider moving the LOCK_HTC_CREDIT(target); logic into this function as well.
  66. */
  67. void htc_credit_record(htc_credit_exchange_type type, uint32_t tx_credit,
  68. uint32_t htc_tx_queue_depth) {
  69. if (HTC_CREDIT_HISTORY_MAX <= g_htc_credit_history_idx)
  70. g_htc_credit_history_idx = 0;
  71. htc_credit_history_buffer[g_htc_credit_history_idx].type = type;
  72. htc_credit_history_buffer[g_htc_credit_history_idx].time =
  73. qdf_get_log_timestamp();
  74. htc_credit_history_buffer[g_htc_credit_history_idx].tx_credit =
  75. tx_credit;
  76. htc_credit_history_buffer[g_htc_credit_history_idx].htc_tx_queue_depth =
  77. htc_tx_queue_depth;
  78. g_htc_credit_history_idx++;
  79. }
  80. void htc_dump_counter_info(HTC_HANDLE HTCHandle)
  81. {
  82. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  83. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  84. ("\n%s: ce_send_cnt = %d, TX_comp_cnt = %d\n",
  85. __func__, target->ce_send_cnt, target->TX_comp_cnt));
  86. }
  87. void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle, int *credits)
  88. {
  89. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  90. HTC_ENDPOINT *pEndpoint;
  91. int i;
  92. if (!credits || !target) {
  93. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: invalid args", __func__));
  94. return;
  95. }
  96. *credits = 0;
  97. LOCK_HTC_TX(target);
  98. for (i = 0; i < ENDPOINT_MAX; i++) {
  99. pEndpoint = &target->endpoint[i];
  100. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  101. *credits = pEndpoint->TxCredits;
  102. break;
  103. }
  104. }
  105. UNLOCK_HTC_TX(target);
  106. }
  107. static inline void restore_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
  108. {
  109. if (pPacket->PktInfo.AsTx.Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
  110. qdf_nbuf_t netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  111. qdf_nbuf_unmap(target->osdev, netbuf, QDF_DMA_TO_DEVICE);
  112. qdf_nbuf_pull_head(netbuf, sizeof(HTC_FRAME_HDR));
  113. pPacket->PktInfo.AsTx.Flags &= ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  114. }
  115. }
  116. static void do_send_completion(HTC_ENDPOINT *pEndpoint,
  117. HTC_PACKET_QUEUE *pQueueToIndicate)
  118. {
  119. do {
  120. if (HTC_QUEUE_EMPTY(pQueueToIndicate)) {
  121. /* nothing to indicate */
  122. break;
  123. }
  124. if (pEndpoint->EpCallBacks.EpTxCompleteMultiple != NULL) {
  125. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  126. (" HTC calling ep %d, send complete multiple callback (%d pkts) \n",
  127. pEndpoint->Id,
  128. HTC_PACKET_QUEUE_DEPTH
  129. (pQueueToIndicate)));
  130. /* a multiple send complete handler is being used, pass the queue to the handler */
  131. pEndpoint->EpCallBacks.EpTxCompleteMultiple(pEndpoint->
  132. EpCallBacks.
  133. pContext,
  134. pQueueToIndicate);
  135. /* all packets are now owned by the callback, reset queue to be safe */
  136. INIT_HTC_PACKET_QUEUE(pQueueToIndicate);
  137. } else {
  138. HTC_PACKET *pPacket;
  139. /* using legacy EpTxComplete */
  140. do {
  141. pPacket = htc_packet_dequeue(pQueueToIndicate);
  142. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  143. (" HTC calling ep %d send complete callback on packet %p \n",
  144. pEndpoint->Id, pPacket));
  145. pEndpoint->EpCallBacks.EpTxComplete(pEndpoint->
  146. EpCallBacks.
  147. pContext,
  148. pPacket);
  149. } while (!HTC_QUEUE_EMPTY(pQueueToIndicate));
  150. }
  151. } while (false);
  152. }
  153. static void send_packet_completion(HTC_TARGET *target, HTC_PACKET *pPacket)
  154. {
  155. HTC_ENDPOINT *pEndpoint = &target->endpoint[pPacket->Endpoint];
  156. HTC_PACKET_QUEUE container;
  157. restore_tx_packet(target, pPacket);
  158. INIT_HTC_PACKET_QUEUE_AND_ADD(&container, pPacket);
  159. /* do completion */
  160. do_send_completion(pEndpoint, &container);
  161. }
  162. void htc_send_complete_check_cleanup(void *context)
  163. {
  164. HTC_ENDPOINT *pEndpoint = (HTC_ENDPOINT *) context;
  165. htc_send_complete_check(pEndpoint, 1);
  166. }
  167. HTC_PACKET *allocate_htc_bundle_packet(HTC_TARGET *target)
  168. {
  169. HTC_PACKET *pPacket;
  170. HTC_PACKET_QUEUE *pQueueSave;
  171. qdf_nbuf_t netbuf;
  172. LOCK_HTC_TX(target);
  173. if (NULL == target->pBundleFreeList) {
  174. UNLOCK_HTC_TX(target);
  175. netbuf = qdf_nbuf_alloc(NULL,
  176. target->MaxMsgsPerHTCBundle *
  177. target->TargetCreditSize, 0, 4, false);
  178. AR_DEBUG_ASSERT(netbuf);
  179. if (!netbuf) {
  180. return NULL;
  181. }
  182. pPacket = qdf_mem_malloc(sizeof(HTC_PACKET));
  183. AR_DEBUG_ASSERT(pPacket);
  184. if (!pPacket) {
  185. qdf_nbuf_free(netbuf);
  186. return NULL;
  187. }
  188. pQueueSave = qdf_mem_malloc(sizeof(HTC_PACKET_QUEUE));
  189. AR_DEBUG_ASSERT(pQueueSave);
  190. if (!pQueueSave) {
  191. qdf_nbuf_free(netbuf);
  192. qdf_mem_free(pPacket);
  193. return NULL;
  194. }
  195. INIT_HTC_PACKET_QUEUE(pQueueSave);
  196. pPacket->pContext = pQueueSave;
  197. SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf);
  198. pPacket->pBuffer = qdf_nbuf_data(netbuf);
  199. pPacket->BufferLength = qdf_nbuf_len(netbuf);
  200. /* store the original head room so that we can restore this when we "free" the packet */
  201. /* free packet puts the packet back on the free list */
  202. pPacket->netbufOrigHeadRoom = qdf_nbuf_headroom(netbuf);
  203. return pPacket;
  204. }
  205. /* already done malloc - restore from free list */
  206. pPacket = target->pBundleFreeList;
  207. AR_DEBUG_ASSERT(pPacket);
  208. if (!pPacket) {
  209. UNLOCK_HTC_TX(target);
  210. return NULL;
  211. }
  212. target->pBundleFreeList = (HTC_PACKET *) pPacket->ListLink.pNext;
  213. UNLOCK_HTC_TX(target);
  214. pPacket->ListLink.pNext = NULL;
  215. return pPacket;
  216. }
  217. void free_htc_bundle_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
  218. {
  219. uint32_t curentHeadRoom;
  220. qdf_nbuf_t netbuf;
  221. HTC_PACKET_QUEUE *pQueueSave;
  222. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  223. AR_DEBUG_ASSERT(netbuf);
  224. if (!netbuf) {
  225. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("\n%s: Invalid netbuf in HTC "
  226. "Packet\n", __func__));
  227. return;
  228. }
  229. /* HIF adds data to the headroom section of the nbuf, restore the original */
  230. /* size. If this is not done, headroom keeps shrinking with every HIF send */
  231. /* and eventually HIF ends up doing another malloc big enough to store the */
  232. /* data + its header */
  233. curentHeadRoom = qdf_nbuf_headroom(netbuf);
  234. qdf_nbuf_pull_head(netbuf,
  235. pPacket->netbufOrigHeadRoom - curentHeadRoom);
  236. qdf_nbuf_trim_tail(netbuf, qdf_nbuf_len(netbuf));
  237. /* restore the pBuffer pointer. HIF changes this */
  238. pPacket->pBuffer = qdf_nbuf_data(netbuf);
  239. pPacket->BufferLength = qdf_nbuf_len(netbuf);
  240. /* restore queue */
  241. pQueueSave = (HTC_PACKET_QUEUE *) pPacket->pContext;
  242. AR_DEBUG_ASSERT(pQueueSave);
  243. INIT_HTC_PACKET_QUEUE(pQueueSave);
  244. LOCK_HTC_TX(target);
  245. if (target->pBundleFreeList == NULL) {
  246. target->pBundleFreeList = pPacket;
  247. pPacket->ListLink.pNext = NULL;
  248. } else {
  249. pPacket->ListLink.pNext = (DL_LIST *) target->pBundleFreeList;
  250. target->pBundleFreeList = pPacket;
  251. }
  252. UNLOCK_HTC_TX(target);
  253. }
  254. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  255. /**
  256. * htc_send_update_tx_bundle_stats() - update tx bundle stats depends
  257. * on max bundle size
  258. * @target: hif context
  259. * @data_len: tx data len
  260. * @TxCreditSize: endpoint tx credit size
  261. *
  262. * Return: None
  263. */
  264. static inline void
  265. htc_send_update_tx_bundle_stats(HTC_TARGET *target,
  266. qdf_size_t data_len,
  267. int TxCreditSize)
  268. {
  269. if ((data_len / TxCreditSize) <= HTC_MAX_MSG_PER_BUNDLE_TX)
  270. target->tx_bundle_stats[(data_len / TxCreditSize) - 1]++;
  271. return;
  272. }
  273. /**
  274. * htc_issue_tx_bundle_stats_inc() - increment in tx bundle stats
  275. * on max bundle size
  276. * @target: hif context
  277. *
  278. * Return: None
  279. */
  280. static inline void
  281. htc_issue_tx_bundle_stats_inc(HTC_TARGET *target)
  282. {
  283. target->tx_bundle_stats[0]++;
  284. }
  285. #else
  286. static inline void
  287. htc_send_update_tx_bundle_stats(HTC_TARGET *target,
  288. qdf_size_t data_len,
  289. int TxCreditSize)
  290. {
  291. return;
  292. }
  293. static inline void
  294. htc_issue_tx_bundle_stats_inc(HTC_TARGET *target)
  295. {
  296. return;
  297. }
  298. #endif
  299. #if defined(HIF_USB) || defined(HIF_SDIO)
  300. #ifdef ENABLE_BUNDLE_TX
  301. static A_STATUS htc_send_bundled_netbuf(HTC_TARGET *target,
  302. HTC_ENDPOINT *pEndpoint,
  303. unsigned char *pBundleBuffer,
  304. HTC_PACKET *pPacketTx)
  305. {
  306. qdf_size_t data_len;
  307. A_STATUS status;
  308. qdf_nbuf_t bundleBuf;
  309. uint32_t data_attr = 0;
  310. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  311. data_len = pBundleBuffer - qdf_nbuf_data(bundleBuf);
  312. qdf_nbuf_put_tail(bundleBuf, data_len);
  313. SET_HTC_PACKET_INFO_TX(pPacketTx,
  314. target,
  315. pBundleBuffer,
  316. data_len,
  317. pEndpoint->Id, HTC_TX_PACKET_TAG_BUNDLED);
  318. LOCK_HTC_TX(target);
  319. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacketTx);
  320. UNLOCK_HTC_TX(target);
  321. #if DEBUG_BUNDLE
  322. qdf_print(" Send bundle EP%d buffer size:0x%x, total:0x%x, count:%d.\n",
  323. pEndpoint->Id,
  324. pEndpoint->TxCreditSize,
  325. data_len, data_len / pEndpoint->TxCreditSize);
  326. #endif
  327. htc_send_update_tx_bundle_stats(target, data_len,
  328. pEndpoint->TxCreditSize);
  329. status = hif_send_head(target->hif_dev,
  330. pEndpoint->UL_PipeID,
  331. pEndpoint->Id, data_len,
  332. bundleBuf, data_attr);
  333. if (status != A_OK) {
  334. qdf_print("%s:hif_send_head failed(len=%zu).\n", __func__,
  335. data_len);
  336. }
  337. return status;
  338. }
  339. /**
  340. * htc_issue_packets_bundle() - HTC function to send bundle packets from a queue
  341. * @target: HTC target on which packets need to be sent
  342. * @pEndpoint: logical endpoint on which packets needs to be sent
  343. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  344. *
  345. * Return: void
  346. */
  347. static void htc_issue_packets_bundle(HTC_TARGET *target,
  348. HTC_ENDPOINT *pEndpoint,
  349. HTC_PACKET_QUEUE *pPktQueue)
  350. {
  351. int i, frag_count, nbytes;
  352. qdf_nbuf_t netbuf, bundleBuf;
  353. unsigned char *pBundleBuffer = NULL;
  354. HTC_PACKET *pPacket = NULL, *pPacketTx = NULL;
  355. HTC_FRAME_HDR *pHtcHdr;
  356. int last_credit_pad = 0;
  357. int creditPad, creditRemainder, transferLength, bundlesSpaceRemaining =
  358. 0;
  359. HTC_PACKET_QUEUE *pQueueSave = NULL;
  360. bundlesSpaceRemaining =
  361. target->MaxMsgsPerHTCBundle * pEndpoint->TxCreditSize;
  362. pPacketTx = allocate_htc_bundle_packet(target);
  363. if (!pPacketTx) {
  364. /* good time to panic */
  365. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  366. ("allocate_htc_bundle_packet failed \n"));
  367. AR_DEBUG_ASSERT(false);
  368. return;
  369. }
  370. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  371. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  372. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  373. while (1) {
  374. pPacket = htc_packet_dequeue(pPktQueue);
  375. if (pPacket == NULL) {
  376. break;
  377. }
  378. creditPad = 0;
  379. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  380. creditRemainder = transferLength % pEndpoint->TxCreditSize;
  381. if (creditRemainder != 0) {
  382. if (transferLength < pEndpoint->TxCreditSize) {
  383. creditPad =
  384. pEndpoint->TxCreditSize - transferLength;
  385. } else {
  386. creditPad = creditRemainder;
  387. }
  388. transferLength += creditPad;
  389. }
  390. if (bundlesSpaceRemaining < transferLength) {
  391. /* send out previous buffer */
  392. htc_send_bundled_netbuf(target, pEndpoint,
  393. pBundleBuffer - last_credit_pad,
  394. pPacketTx);
  395. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue) <
  396. HTC_MIN_MSG_PER_BUNDLE) {
  397. return;
  398. }
  399. bundlesSpaceRemaining =
  400. target->MaxMsgsPerHTCBundle *
  401. pEndpoint->TxCreditSize;
  402. pPacketTx = allocate_htc_bundle_packet(target);
  403. if (!pPacketTx) {
  404. /* good time to panic */
  405. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  406. ("allocate_htc_bundle_packet failed \n"));
  407. AR_DEBUG_ASSERT(false);
  408. return;
  409. }
  410. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  411. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  412. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  413. }
  414. bundlesSpaceRemaining -= transferLength;
  415. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  416. if (hif_get_bus_type(target->hif_dev) != QDF_BUS_TYPE_USB) {
  417. pHtcHdr =
  418. (HTC_FRAME_HDR *)
  419. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  420. HTC_WRITE32(pHtcHdr,
  421. SM(pPacket->ActualLength,
  422. HTC_FRAME_HDR_PAYLOADLEN) |
  423. SM(pPacket->PktInfo.AsTx.SendFlags |
  424. HTC_FLAGS_SEND_BUNDLE,
  425. HTC_FRAME_HDR_FLAGS) |
  426. SM(pPacket->Endpoint,
  427. HTC_FRAME_HDR_ENDPOINTID));
  428. HTC_WRITE32((uint32_t *) pHtcHdr + 1,
  429. SM(pPacket->PktInfo.AsTx.SeqNo,
  430. HTC_FRAME_HDR_CONTROLBYTES1) | SM(creditPad,
  431. HTC_FRAME_HDR_RESERVED));
  432. pHtcHdr->reserved = creditPad;
  433. }
  434. frag_count = qdf_nbuf_get_num_frags(netbuf);
  435. nbytes = pPacket->ActualLength + HTC_HDR_LENGTH;
  436. for (i = 0; i < frag_count && nbytes > 0; i++) {
  437. int frag_len = qdf_nbuf_get_frag_len(netbuf, i);
  438. unsigned char *frag_addr =
  439. qdf_nbuf_get_frag_vaddr(netbuf, i);
  440. if (frag_len > nbytes) {
  441. frag_len = nbytes;
  442. }
  443. qdf_mem_copy(pBundleBuffer, frag_addr, frag_len);
  444. nbytes -= frag_len;
  445. pBundleBuffer += frag_len;
  446. }
  447. HTC_PACKET_ENQUEUE(pQueueSave, pPacket);
  448. pBundleBuffer += creditPad;
  449. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) {
  450. /* last one can't be packed. */
  451. last_credit_pad = creditPad;
  452. }
  453. }
  454. if (pBundleBuffer != qdf_nbuf_data(bundleBuf)) {
  455. /* send out remaining buffer */
  456. htc_send_bundled_netbuf(target, pEndpoint,
  457. pBundleBuffer - last_credit_pad,
  458. pPacketTx);
  459. } else {
  460. free_htc_bundle_packet(target, pPacketTx);
  461. }
  462. }
  463. #endif /* ENABLE_BUNDLE_TX */
  464. #else
  465. static void htc_issue_packets_bundle(HTC_TARGET *target,
  466. HTC_ENDPOINT *pEndpoint,
  467. HTC_PACKET_QUEUE *pPktQueue)
  468. {
  469. }
  470. #endif
  471. /**
  472. * htc_issue_packets() - HTC function to send packets from a queue
  473. * @target: HTC target on which packets need to be sent
  474. * @pEndpoint: logical endpoint on which packets needs to be sent
  475. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  476. *
  477. * Return: QDF_STATUS_SUCCESS on success and error QDF status on failure
  478. */
  479. static A_STATUS htc_issue_packets(HTC_TARGET *target,
  480. HTC_ENDPOINT *pEndpoint,
  481. HTC_PACKET_QUEUE *pPktQueue)
  482. {
  483. A_STATUS status = A_OK;
  484. qdf_nbuf_t netbuf;
  485. HTC_PACKET *pPacket = NULL;
  486. uint16_t payloadLen;
  487. HTC_FRAME_HDR *pHtcHdr;
  488. uint32_t data_attr = 0;
  489. enum qdf_bus_type bus_type;
  490. bus_type = hif_get_bus_type(target->hif_dev);
  491. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  492. ("+htc_issue_packets: Queue: %p, Pkts %d \n", pPktQueue,
  493. HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  494. while (true) {
  495. if (HTC_TX_BUNDLE_ENABLED(target) &&
  496. HTC_PACKET_QUEUE_DEPTH(pPktQueue) >=
  497. HTC_MIN_MSG_PER_BUNDLE) {
  498. switch (bus_type) {
  499. case QDF_BUS_TYPE_SDIO:
  500. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  501. break;
  502. case QDF_BUS_TYPE_USB:
  503. htc_issue_packets_bundle(target,
  504. pEndpoint,
  505. pPktQueue);
  506. break;
  507. default:
  508. break;
  509. }
  510. }
  511. /* if not bundling or there was a packet that could not be placed in a bundle,
  512. * and send it by normal way
  513. */
  514. pPacket = htc_packet_dequeue(pPktQueue);
  515. if (NULL == pPacket) {
  516. /* local queue is fully drained */
  517. break;
  518. }
  519. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  520. AR_DEBUG_ASSERT(netbuf);
  521. /* Non-credit enabled endpoints have been mapped and setup by now,
  522. * so no need to revisit the HTC headers
  523. */
  524. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  525. payloadLen = pPacket->ActualLength;
  526. /* setup HTC frame header */
  527. pHtcHdr = (HTC_FRAME_HDR *)
  528. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  529. AR_DEBUG_ASSERT(pHtcHdr);
  530. HTC_WRITE32(pHtcHdr,
  531. SM(payloadLen,
  532. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->
  533. PktInfo.
  534. AsTx.
  535. SendFlags,
  536. HTC_FRAME_HDR_FLAGS)
  537. | SM(pPacket->Endpoint,
  538. HTC_FRAME_HDR_ENDPOINTID));
  539. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  540. SM(pPacket->PktInfo.AsTx.SeqNo,
  541. HTC_FRAME_HDR_CONTROLBYTES1));
  542. /*
  543. * Now that the HTC frame header has been added, the netbuf can be
  544. * mapped. This only applies to non-data frames, since data frames
  545. * were already mapped as they entered into the driver.
  546. * Check the "FIXUP_NETBUF" flag to see whether this is a data netbuf
  547. * that is already mapped, or a non-data netbuf that needs to be
  548. * mapped.
  549. */
  550. if (pPacket->PktInfo.AsTx.
  551. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
  552. qdf_nbuf_map(target->osdev,
  553. GET_HTC_PACKET_NET_BUF_CONTEXT
  554. (pPacket), QDF_DMA_TO_DEVICE);
  555. }
  556. }
  557. if (!pEndpoint->async_update) {
  558. LOCK_HTC_TX(target);
  559. }
  560. /* store in look up queue to match completions */
  561. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  562. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  563. pEndpoint->ul_outstanding_cnt++;
  564. if (!pEndpoint->async_update) {
  565. UNLOCK_HTC_TX(target);
  566. hif_send_complete_check(target->hif_dev,
  567. pEndpoint->UL_PipeID, false);
  568. }
  569. status = hif_send_head(target->hif_dev,
  570. pEndpoint->UL_PipeID, pEndpoint->Id,
  571. HTC_HDR_LENGTH + pPacket->ActualLength,
  572. netbuf, data_attr);
  573. #if DEBUG_BUNDLE
  574. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  575. pEndpoint->Id,
  576. pEndpoint->TxCreditSize,
  577. HTC_HDR_LENGTH + pPacket->ActualLength);
  578. #endif
  579. htc_issue_tx_bundle_stats_inc(target);
  580. target->ce_send_cnt++;
  581. if (qdf_unlikely(A_FAILED(status))) {
  582. if (status != A_NO_RESOURCE) {
  583. /* TODO : if more than 1 endpoint maps to the same PipeID it is possible
  584. * to run out of resources in the HIF layer. Don't emit the error */
  585. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  586. ("hif_send Failed status:%d \n",
  587. status));
  588. }
  589. if (!pEndpoint->async_update) {
  590. LOCK_HTC_TX(target);
  591. }
  592. target->ce_send_cnt--;
  593. pEndpoint->ul_outstanding_cnt--;
  594. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  595. /* reclaim credits */
  596. pEndpoint->TxCredits +=
  597. pPacket->PktInfo.AsTx.CreditsUsed;
  598. /* put it back into the callers queue */
  599. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  600. if (!pEndpoint->async_update) {
  601. UNLOCK_HTC_TX(target);
  602. }
  603. break;
  604. }
  605. /*
  606. * For HTT messages without a response from fw,
  607. * do the runtime put here.
  608. * otherwise runtime put will be done when the fw response comes
  609. */
  610. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
  611. hif_pm_runtime_put(target->hif_dev);
  612. }
  613. if (qdf_unlikely(A_FAILED(status))) {
  614. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  615. ("htc_issue_packets, failed pkt:0x%p status:%d",
  616. pPacket, status));
  617. }
  618. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets \n"));
  619. return status;
  620. }
  621. #ifdef FEATURE_RUNTIME_PM
  622. /**
  623. * extract_htc_pm_packtes(): move pm packets from endpoint into queue
  624. * @endpoint: which enpoint to extract packets from
  625. * @queue: a queue to store extracted packets in.
  626. *
  627. * remove pm packets from the endpoint's tx queue.
  628. * queue them into a queue
  629. */
  630. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  631. HTC_PACKET_QUEUE *queue)
  632. {
  633. HTC_PACKET *packet;
  634. /* only WMI endpoint has power management packets */
  635. if (endpoint->service_id != WMI_CONTROL_SVC)
  636. return;
  637. ITERATE_OVER_LIST_ALLOW_REMOVE(&endpoint->TxQueue.QueueHead, packet,
  638. HTC_PACKET, ListLink) {
  639. if (packet->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_AUTO_PM) {
  640. HTC_PACKET_REMOVE(&endpoint->TxQueue, packet);
  641. HTC_PACKET_ENQUEUE(queue, packet);
  642. }
  643. } ITERATE_END
  644. }
  645. /**
  646. * queue_htc_pm_packets(): queue pm packets with priority
  647. * @endpoint: enpoint to queue packets to
  648. * @queue: queue of pm packets to enque
  649. *
  650. * suspend resume packets get special treatment & priority.
  651. * need to queue them at the front of the queue.
  652. */
  653. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  654. HTC_PACKET_QUEUE *queue)
  655. {
  656. if (endpoint->service_id != WMI_CONTROL_SVC)
  657. return;
  658. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&endpoint->TxQueue, queue);
  659. }
  660. #else
  661. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  662. HTC_PACKET_QUEUE *queue)
  663. {}
  664. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  665. HTC_PACKET_QUEUE *queue)
  666. {}
  667. #endif
  668. /**
  669. * get_htc_send_packets_credit_based() - get packets based on available credits
  670. * @target: HTC target on which packets need to be sent
  671. * @pEndpoint: logical endpoint on which packets needs to be sent
  672. * @pQueue: HTC packet queue containing the list of packets to be sent
  673. *
  674. * Get HTC send packets from TX queue on an endpoint based on available credits.
  675. * The function moves the packets from TX queue of the endpoint to pQueue.
  676. *
  677. * Return: None
  678. */
  679. static void get_htc_send_packets_credit_based(HTC_TARGET *target,
  680. HTC_ENDPOINT *pEndpoint,
  681. HTC_PACKET_QUEUE *pQueue)
  682. {
  683. int creditsRequired;
  684. int remainder;
  685. uint8_t sendFlags;
  686. HTC_PACKET *pPacket;
  687. unsigned int transferLength;
  688. HTC_PACKET_QUEUE *tx_queue;
  689. HTC_PACKET_QUEUE pm_queue;
  690. bool do_pm_get = false;
  691. /****** NOTE : the TX lock is held when this function is called *****************/
  692. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+get_htc_send_packets_credit_based\n"));
  693. INIT_HTC_PACKET_QUEUE(&pm_queue);
  694. extract_htc_pm_packets(pEndpoint, &pm_queue);
  695. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  696. tx_queue = &pEndpoint->TxQueue;
  697. do_pm_get = true;
  698. } else {
  699. tx_queue = &pm_queue;
  700. }
  701. /* loop until we can grab as many packets out of the queue as we can */
  702. while (true) {
  703. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  704. /* bus suspended, runtime resume issued */
  705. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  706. break;
  707. }
  708. sendFlags = 0;
  709. /* get packet at head, but don't remove it */
  710. pPacket = htc_get_pkt_at_head(tx_queue);
  711. if (pPacket == NULL) {
  712. if (do_pm_get)
  713. hif_pm_runtime_put(target->hif_dev);
  714. break;
  715. }
  716. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  717. (" Got head packet:%p , Queue Depth: %d\n",
  718. pPacket,
  719. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  720. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  721. if (transferLength <= pEndpoint->TxCreditSize) {
  722. creditsRequired = 1;
  723. } else {
  724. /* figure out how many credits this message requires */
  725. creditsRequired =
  726. transferLength / pEndpoint->TxCreditSize;
  727. remainder = transferLength % pEndpoint->TxCreditSize;
  728. if (remainder) {
  729. creditsRequired++;
  730. }
  731. }
  732. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  733. (" Credits Required:%d Got:%d\n",
  734. creditsRequired, pEndpoint->TxCredits));
  735. if (pEndpoint->Id == ENDPOINT_0) {
  736. /*
  737. * endpoint 0 is special, it always has a credit and
  738. * does not require credit based flow control
  739. */
  740. creditsRequired = 0;
  741. } else {
  742. if (pEndpoint->TxCredits < creditsRequired) {
  743. #if DEBUG_CREDIT
  744. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  745. (" EP%d, No Credit now. %d < %d\n",
  746. pEndpoint->Id,
  747. pEndpoint->TxCredits,
  748. creditsRequired));
  749. #endif
  750. if (do_pm_get)
  751. hif_pm_runtime_put(target->hif_dev);
  752. break;
  753. }
  754. pEndpoint->TxCredits -= creditsRequired;
  755. INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed,
  756. creditsRequired);
  757. /* check if we need credits back from the target */
  758. if (pEndpoint->TxCredits <=
  759. pEndpoint->TxCreditsPerMaxMsg) {
  760. /* tell the target we need credits ASAP! */
  761. sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
  762. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  763. LOCK_HTC_CREDIT(target);
  764. htc_credit_record(HTC_REQUEST_CREDIT,
  765. pEndpoint->TxCredits,
  766. HTC_PACKET_QUEUE_DEPTH
  767. (tx_queue));
  768. UNLOCK_HTC_CREDIT(target);
  769. }
  770. INC_HTC_EP_STAT(pEndpoint,
  771. TxCreditLowIndications, 1);
  772. #if DEBUG_CREDIT
  773. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  774. (" EP%d Needs Credits\n",
  775. pEndpoint->Id));
  776. #endif
  777. }
  778. }
  779. /* now we can fully dequeue */
  780. pPacket = htc_packet_dequeue(tx_queue);
  781. if (pPacket) {
  782. /* save the number of credits this packet consumed */
  783. pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired;
  784. /* save send flags */
  785. pPacket->PktInfo.AsTx.SendFlags = sendFlags;
  786. /* queue this packet into the caller's queue */
  787. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  788. }
  789. }
  790. if (!HTC_QUEUE_EMPTY(&pm_queue))
  791. queue_htc_pm_packets(pEndpoint, &pm_queue);
  792. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  793. ("-get_htc_send_packets_credit_based\n"));
  794. }
  795. static void get_htc_send_packets(HTC_TARGET *target,
  796. HTC_ENDPOINT *pEndpoint,
  797. HTC_PACKET_QUEUE *pQueue, int Resources)
  798. {
  799. HTC_PACKET *pPacket;
  800. HTC_PACKET_QUEUE *tx_queue;
  801. HTC_PACKET_QUEUE pm_queue;
  802. bool do_pm_get;
  803. /****** NOTE : the TX lock is held when this function is called *****************/
  804. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  805. ("+get_htc_send_packets %d resources\n", Resources));
  806. INIT_HTC_PACKET_QUEUE(&pm_queue);
  807. extract_htc_pm_packets(pEndpoint, &pm_queue);
  808. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  809. tx_queue = &pEndpoint->TxQueue;
  810. do_pm_get = true;
  811. } else {
  812. tx_queue = &pm_queue;
  813. }
  814. /* loop until we can grab as many packets out of the queue as we can */
  815. while (Resources > 0) {
  816. int num_frags;
  817. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  818. /* bus suspended, runtime resume issued */
  819. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  820. break;
  821. }
  822. pPacket = htc_packet_dequeue(tx_queue);
  823. if (pPacket == NULL) {
  824. if (do_pm_get)
  825. hif_pm_runtime_put(target->hif_dev);
  826. break;
  827. }
  828. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  829. (" Got packet:%p , New Queue Depth: %d\n",
  830. pPacket,
  831. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  832. /* For non-credit path the sequence number is already embedded
  833. * in the constructed HTC header
  834. */
  835. #if 0
  836. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  837. pEndpoint->SeqNo++;
  838. #endif
  839. pPacket->PktInfo.AsTx.SendFlags = 0;
  840. pPacket->PktInfo.AsTx.CreditsUsed = 0;
  841. /* queue this packet into the caller's queue */
  842. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  843. /*
  844. * FIX THIS:
  845. * For now, avoid calling qdf_nbuf_get_num_frags before calling
  846. * qdf_nbuf_map, because the MacOS version of qdf_nbuf_t doesn't
  847. * support qdf_nbuf_get_num_frags until after qdf_nbuf_map has
  848. * been done.
  849. * Assume that the non-data netbufs, i.e. the WMI message netbufs,
  850. * consist of a single fragment.
  851. */
  852. num_frags =
  853. (pPacket->PktInfo.AsTx.
  854. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1
  855. /* WMI messages are in a single-fragment network buffer */ :
  856. qdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT
  857. (pPacket));
  858. Resources -= num_frags;
  859. }
  860. if (!HTC_QUEUE_EMPTY(&pm_queue))
  861. queue_htc_pm_packets(pEndpoint, &pm_queue);
  862. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets\n"));
  863. }
  864. /**
  865. * htc_try_send() - Send packets in a queue on an endpoint
  866. * @target: HTC target on which packets need to be sent
  867. * @pEndpoint: logical endpoint on which packets needs to be sent
  868. * @pCallersSendQueue: packet queue containing the list of packets to be sent
  869. *
  870. * Return: HTC_SEND_QUEUE_RESULT indicates whether the packet was queued to be
  871. * sent or the packet should be dropped by the upper layer
  872. */
  873. static HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target,
  874. HTC_ENDPOINT *pEndpoint,
  875. HTC_PACKET_QUEUE *pCallersSendQueue)
  876. {
  877. HTC_PACKET_QUEUE sendQueue; /* temp queue to hold packets at various stages */
  878. HTC_PACKET *pPacket;
  879. int tx_resources;
  880. int overflow;
  881. HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK;
  882. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%p Depth:%d)\n",
  883. pCallersSendQueue,
  884. (pCallersSendQueue ==
  885. NULL) ? 0 :
  886. HTC_PACKET_QUEUE_DEPTH
  887. (pCallersSendQueue)));
  888. /* init the local send queue */
  889. INIT_HTC_PACKET_QUEUE(&sendQueue);
  890. do {
  891. if (NULL == pCallersSendQueue) {
  892. /* caller didn't provide a queue, just wants us to check queues and send */
  893. break;
  894. }
  895. if (HTC_QUEUE_EMPTY(pCallersSendQueue)) {
  896. /* empty queue */
  897. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  898. HTC_PKT_Q_EMPTY);
  899. result = HTC_SEND_QUEUE_DROP;
  900. break;
  901. }
  902. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >=
  903. pEndpoint->MaxTxQueueDepth) {
  904. /* we've already overflowed */
  905. overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  906. } else {
  907. /* figure out how much we will overflow by */
  908. overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  909. overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  910. /* figure out how much we will overflow the TX queue by */
  911. overflow -= pEndpoint->MaxTxQueueDepth;
  912. }
  913. /* if overflow is negative or zero, we are okay */
  914. if (overflow > 0) {
  915. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  916. (" Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d \n",
  917. pEndpoint->Id, overflow,
  918. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  919. TxQueue),
  920. pEndpoint->MaxTxQueueDepth));
  921. }
  922. if ((overflow <= 0)
  923. || (pEndpoint->EpCallBacks.EpSendFull == NULL)) {
  924. /* all packets will fit or caller did not provide send full indication handler
  925. * -- just move all of them to the local sendQueue object */
  926. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue,
  927. pCallersSendQueue);
  928. } else {
  929. int i;
  930. int goodPkts =
  931. HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) -
  932. overflow;
  933. A_ASSERT(goodPkts >= 0);
  934. /* we have overflowed, and a callback is provided */
  935. /* dequeue all non-overflow packets into the sendqueue */
  936. for (i = 0; i < goodPkts; i++) {
  937. /* pop off caller's queue */
  938. pPacket = htc_packet_dequeue(pCallersSendQueue);
  939. A_ASSERT(pPacket != NULL);
  940. /* insert into local queue */
  941. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  942. }
  943. /* the caller's queue has all the packets that won't fit */
  944. /* walk through the caller's queue and indicate each one to the send full handler */
  945. ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->
  946. QueueHead, pPacket,
  947. HTC_PACKET, ListLink) {
  948. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  949. (" Indicating overflowed TX packet: %p \n",
  950. pPacket));
  951. /*
  952. * Remove headroom reserved for HTC_FRAME_HDR before giving
  953. * the packet back to the user via the EpSendFull callback.
  954. */
  955. restore_tx_packet(target, pPacket);
  956. if (pEndpoint->EpCallBacks.
  957. EpSendFull(pEndpoint->EpCallBacks.pContext,
  958. pPacket) == HTC_SEND_FULL_DROP) {
  959. /* callback wants the packet dropped */
  960. INC_HTC_EP_STAT(pEndpoint, TxDropped,
  961. 1);
  962. /* leave this one in the caller's queue for cleanup */
  963. } else {
  964. /* callback wants to keep this packet, remove from caller's queue */
  965. HTC_PACKET_REMOVE(pCallersSendQueue,
  966. pPacket);
  967. /* put it in the send queue */
  968. /* add HTC_FRAME_HDR space reservation again */
  969. qdf_nbuf_push_head
  970. (GET_HTC_PACKET_NET_BUF_CONTEXT
  971. (pPacket), sizeof(HTC_FRAME_HDR));
  972. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  973. }
  974. }
  975. ITERATE_END;
  976. if (HTC_QUEUE_EMPTY(&sendQueue)) {
  977. /* no packets made it in, caller will cleanup */
  978. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  979. HTC_SEND_Q_EMPTY);
  980. result = HTC_SEND_QUEUE_DROP;
  981. break;
  982. }
  983. }
  984. } while (false);
  985. if (result != HTC_SEND_QUEUE_OK) {
  986. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: %d\n",
  987. result));
  988. return result;
  989. }
  990. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  991. tx_resources =
  992. hif_get_free_queue_number(target->hif_dev,
  993. pEndpoint->UL_PipeID);
  994. } else {
  995. tx_resources = 0;
  996. }
  997. LOCK_HTC_TX(target);
  998. if (!HTC_QUEUE_EMPTY(&sendQueue)) {
  999. if (target->is_nodrop_pkt) {
  1000. /*
  1001. * nodrop pkts have higher priority than normal pkts,
  1002. * insert nodrop pkt to head for proper
  1003. * start/termination of test.
  1004. */
  1005. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1006. &sendQueue);
  1007. target->is_nodrop_pkt = false;
  1008. } else {
  1009. /* transfer packets to tail */
  1010. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,
  1011. &sendQueue);
  1012. A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue));
  1013. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1014. }
  1015. }
  1016. /* increment tx processing count on entry */
  1017. if (qdf_atomic_inc_return(&pEndpoint->TxProcessCount) > 1) {
  1018. /* another thread or task is draining the TX queues on this endpoint
  1019. * that thread will reset the tx processing count when the queue is drained */
  1020. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1021. UNLOCK_HTC_TX(target);
  1022. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy) \n"));
  1023. return HTC_SEND_QUEUE_OK;
  1024. }
  1025. /***** beyond this point only 1 thread may enter ******/
  1026. /* now drain the endpoint TX queue for transmission as long as we have enough
  1027. * transmit resources */
  1028. while (true) {
  1029. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0)
  1030. break;
  1031. if (pEndpoint->async_update &&
  1032. (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) &&
  1033. (!tx_resources)) {
  1034. break;
  1035. }
  1036. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1037. #if DEBUG_CREDIT
  1038. int cred = pEndpoint->TxCredits;
  1039. #endif
  1040. /* credit based mechanism provides flow control based on target transmit resource availability, we
  1041. * assume that the HIF layer will always have bus resources greater than target transmit resources */
  1042. get_htc_send_packets_credit_based(target, pEndpoint,
  1043. &sendQueue);
  1044. #if DEBUG_CREDIT
  1045. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1046. if (cred - pEndpoint->TxCredits > 0) {
  1047. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1048. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1049. pEndpoint->Id, cred,
  1050. cred -
  1051. pEndpoint->TxCredits,
  1052. pEndpoint->TxCredits));
  1053. }
  1054. }
  1055. #endif
  1056. } else {
  1057. /*
  1058. * Header and payload belongs to the different fragments and
  1059. * consume 2 resource for one HTC package but USB combine into
  1060. * one transfer.And one WMI message only consumes one single
  1061. * resource.
  1062. */
  1063. if (HTC_TX_BUNDLE_ENABLED(target) && tx_resources &&
  1064. hif_get_bus_type(target->hif_dev) ==
  1065. QDF_BUS_TYPE_USB) {
  1066. if (pEndpoint->service_id ==
  1067. WMI_CONTROL_SVC)
  1068. tx_resources =
  1069. HTC_MAX_MSG_PER_BUNDLE_TX;
  1070. else
  1071. tx_resources =
  1072. (HTC_MAX_MSG_PER_BUNDLE_TX * 2);
  1073. }
  1074. /* get all the packets for this endpoint that we can for this pass */
  1075. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1076. tx_resources);
  1077. }
  1078. if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) {
  1079. /* didn't get any packets due to a lack of resources or TX queue was drained */
  1080. break;
  1081. }
  1082. if (!pEndpoint->async_update) {
  1083. UNLOCK_HTC_TX(target);
  1084. }
  1085. /* send what we can */
  1086. result = htc_issue_packets(target, pEndpoint, &sendQueue);
  1087. if (result) {
  1088. int i;
  1089. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1090. ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue",
  1091. result));
  1092. for (i = HTC_PACKET_QUEUE_DEPTH(&sendQueue); i > 0; i--)
  1093. hif_pm_runtime_put(target->hif_dev);
  1094. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1095. &sendQueue);
  1096. if (!pEndpoint->async_update) {
  1097. LOCK_HTC_TX(target);
  1098. }
  1099. break;
  1100. }
  1101. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1102. tx_resources =
  1103. hif_get_free_queue_number(target->hif_dev,
  1104. pEndpoint->UL_PipeID);
  1105. }
  1106. if (!pEndpoint->async_update) {
  1107. LOCK_HTC_TX(target);
  1108. }
  1109. }
  1110. /* done with this endpoint, we can clear the count */
  1111. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1112. UNLOCK_HTC_TX(target);
  1113. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: \n"));
  1114. return HTC_SEND_QUEUE_OK;
  1115. }
  1116. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1117. static uint16_t htc_send_pkts_sched_check(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID id)
  1118. {
  1119. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1120. HTC_ENDPOINT *pEndpoint;
  1121. HTC_ENDPOINT_ID eid;
  1122. HTC_PACKET_QUEUE *pTxQueue;
  1123. uint16_t resources;
  1124. uint16_t acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 };
  1125. if (id < ENDPOINT_2 || id > ENDPOINT_5) {
  1126. return 1;
  1127. }
  1128. for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) {
  1129. pEndpoint = &target->endpoint[eid];
  1130. pTxQueue = &pEndpoint->TxQueue;
  1131. if (HTC_QUEUE_EMPTY(pTxQueue)) {
  1132. acQueueStatus[eid - 2] = 1;
  1133. }
  1134. }
  1135. switch (id) {
  1136. case ENDPOINT_2: /* BE */
  1137. return acQueueStatus[0] && acQueueStatus[2]
  1138. && acQueueStatus[3];
  1139. case ENDPOINT_3: /* BK */
  1140. return acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2]
  1141. && acQueueStatus[3];
  1142. case ENDPOINT_4: /* VI */
  1143. return acQueueStatus[2] && acQueueStatus[3];
  1144. case ENDPOINT_5: /* VO */
  1145. return acQueueStatus[3];
  1146. default:
  1147. return 0;
  1148. }
  1149. }
  1150. static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target,
  1151. HTC_PACKET_QUEUE *pPktQueue,
  1152. HTC_ENDPOINT_ID eid)
  1153. {
  1154. HTC_ENDPOINT *pEndpoint;
  1155. HTC_PACKET_QUEUE *pTxQueue;
  1156. HTC_PACKET *pPacket;
  1157. int goodPkts;
  1158. pEndpoint = &target->endpoint[eid];
  1159. pTxQueue = &pEndpoint->TxQueue;
  1160. LOCK_HTC_TX(target);
  1161. goodPkts =
  1162. pEndpoint->MaxTxQueueDepth -
  1163. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  1164. if (goodPkts > 0) {
  1165. while (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1166. pPacket = htc_packet_dequeue(pPktQueue);
  1167. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1168. goodPkts--;
  1169. if (goodPkts <= 0) {
  1170. break;
  1171. }
  1172. }
  1173. }
  1174. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) {
  1175. ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket,
  1176. HTC_PACKET, ListLink) {
  1177. if (pEndpoint->EpCallBacks.
  1178. EpSendFull(pEndpoint->EpCallBacks.pContext,
  1179. pPacket) == HTC_SEND_FULL_DROP) {
  1180. INC_HTC_EP_STAT(pEndpoint, TxDropped, 1);
  1181. } else {
  1182. HTC_PACKET_REMOVE(pPktQueue, pPacket);
  1183. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1184. }
  1185. }
  1186. ITERATE_END;
  1187. }
  1188. UNLOCK_HTC_TX(target);
  1189. return A_OK;
  1190. }
  1191. #endif
  1192. A_STATUS htc_send_pkts_multiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue)
  1193. {
  1194. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1195. HTC_ENDPOINT *pEndpoint;
  1196. HTC_PACKET *pPacket;
  1197. qdf_nbuf_t netbuf;
  1198. HTC_FRAME_HDR *pHtcHdr;
  1199. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1200. ("+htc_send_pkts_multiple: Queue: %p, Pkts %d \n",
  1201. pPktQueue, HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  1202. /* get packet at head to figure out which endpoint these packets will go into */
  1203. pPacket = htc_get_pkt_at_head(pPktQueue);
  1204. if (NULL == pPacket) {
  1205. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL);
  1206. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
  1207. return A_EINVAL;
  1208. }
  1209. AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
  1210. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1211. if (!pEndpoint->service_id) {
  1212. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n",
  1213. __func__));
  1214. return A_EINVAL;
  1215. }
  1216. #ifdef HTC_EP_STAT_PROFILING
  1217. LOCK_HTC_TX(target);
  1218. INC_HTC_EP_STAT(pEndpoint, TxPosted, HTC_PACKET_QUEUE_DEPTH(pPktQueue));
  1219. UNLOCK_HTC_TX(target);
  1220. #endif
  1221. /* provide room in each packet's netbuf for the HTC frame header */
  1222. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  1223. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1224. AR_DEBUG_ASSERT(netbuf);
  1225. qdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR));
  1226. /* setup HTC frame header */
  1227. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1228. AR_DEBUG_ASSERT(pHtcHdr);
  1229. HTC_WRITE32(pHtcHdr,
  1230. SM(pPacket->ActualLength,
  1231. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->Endpoint,
  1232. HTC_FRAME_HDR_ENDPOINTID));
  1233. LOCK_HTC_TX(target);
  1234. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1235. pEndpoint->SeqNo++;
  1236. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1237. SM(pPacket->PktInfo.AsTx.SeqNo,
  1238. HTC_FRAME_HDR_CONTROLBYTES1));
  1239. UNLOCK_HTC_TX(target);
  1240. /*
  1241. * Now that the HTC frame header has been added, the netbuf can be
  1242. * mapped. This only applies to non-data frames, since data frames
  1243. * were already mapped as they entered into the driver.
  1244. */
  1245. qdf_nbuf_map(target->osdev,
  1246. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  1247. QDF_DMA_TO_DEVICE);
  1248. pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  1249. }
  1250. HTC_PACKET_QUEUE_ITERATE_END;
  1251. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1252. if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id)) {
  1253. htc_send_pkts_sched_queue(HTCHandle, pPktQueue, pEndpoint->Id);
  1254. } else {
  1255. htc_try_send(target, pEndpoint, pPktQueue);
  1256. }
  1257. #else
  1258. htc_try_send(target, pEndpoint, pPktQueue);
  1259. #endif
  1260. /* do completion on any packets that couldn't get in */
  1261. if (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1262. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  1263. /* remove the headroom reserved for HTC_FRAME_HDR */
  1264. restore_tx_packet(target, pPacket);
  1265. if (HTC_STOPPING(target)) {
  1266. pPacket->Status = A_ECANCELED;
  1267. } else {
  1268. pPacket->Status = A_NO_RESOURCE;
  1269. }
  1270. }
  1271. HTC_PACKET_QUEUE_ITERATE_END;
  1272. do_send_completion(pEndpoint, pPktQueue);
  1273. }
  1274. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_send_pkts_multiple \n"));
  1275. return A_OK;
  1276. }
  1277. /* HTC API - htc_send_pkt */
  1278. A_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket)
  1279. {
  1280. HTC_PACKET_QUEUE queue;
  1281. if (HTCHandle == NULL || pPacket == NULL) {
  1282. return A_ERROR;
  1283. }
  1284. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1285. ("+-htc_send_pkt: Enter endPointId: %d, buffer: %p, length: %d \n",
  1286. pPacket->Endpoint, pPacket->pBuffer,
  1287. pPacket->ActualLength));
  1288. INIT_HTC_PACKET_QUEUE_AND_ADD(&queue, pPacket);
  1289. return htc_send_pkts_multiple(HTCHandle, &queue);
  1290. }
  1291. #ifdef ATH_11AC_TXCOMPACT
  1292. /**
  1293. * htc_send_data_pkt() - send single data packet on an endpoint
  1294. * @HTCHandle: pointer to HTC handle
  1295. * @netbuf: network buffer containing the data to be sent
  1296. * @ActualLength: length of data that needs to be transmitted
  1297. *
  1298. * Return: A_OK for success or an appropriate A_STATUS error
  1299. */
  1300. A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf, int Epid,
  1301. int ActualLength)
  1302. {
  1303. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1304. HTC_ENDPOINT *pEndpoint;
  1305. HTC_FRAME_HDR *pHtcHdr;
  1306. A_STATUS status = A_OK;
  1307. int tx_resources;
  1308. uint32_t data_attr = 0;
  1309. pEndpoint = &target->endpoint[Epid];
  1310. tx_resources =
  1311. hif_get_free_queue_number(target->hif_dev, pEndpoint->UL_PipeID);
  1312. if (tx_resources < HTC_DATA_RESOURCE_THRS) {
  1313. if (pEndpoint->ul_is_polled) {
  1314. hif_send_complete_check(pEndpoint->target->hif_dev,
  1315. pEndpoint->UL_PipeID, 1);
  1316. tx_resources =
  1317. hif_get_free_queue_number(target->hif_dev,
  1318. pEndpoint->UL_PipeID);
  1319. }
  1320. if (tx_resources < HTC_DATA_MINDESC_PERPACKET) {
  1321. return A_ERROR;
  1322. }
  1323. }
  1324. if (hif_pm_runtime_get(target->hif_dev))
  1325. return A_ERROR;
  1326. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1327. AR_DEBUG_ASSERT(pHtcHdr);
  1328. data_attr = qdf_nbuf_data_attr_get(netbuf);
  1329. HTC_WRITE32(pHtcHdr, SM(ActualLength, HTC_FRAME_HDR_PAYLOADLEN) |
  1330. SM(Epid, HTC_FRAME_HDR_ENDPOINTID));
  1331. /*
  1332. * If the HIF pipe for the data endpoint is polled rather than
  1333. * interrupt-driven, this is a good point to check whether any
  1334. * data previously sent through the HIF pipe have finished being
  1335. * sent.
  1336. * Since this may result in callbacks to htc_tx_completion_handler,
  1337. * which can take the HTC tx lock, make the hif_send_complete_check
  1338. * call before acquiring the HTC tx lock.
  1339. * Call hif_send_complete_check directly, rather than calling
  1340. * htc_send_complete_check, and call the PollTimerStart separately
  1341. * after calling hif_send_head, so the timer will be started to
  1342. * check for completion of the new outstanding download (in the
  1343. * unexpected event that other polling calls don't catch it).
  1344. */
  1345. LOCK_HTC_TX(target);
  1346. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1347. SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1));
  1348. pEndpoint->SeqNo++;
  1349. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1350. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1351. qdf_nbuf_data_addr(netbuf),
  1352. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1353. status = hif_send_head(target->hif_dev,
  1354. pEndpoint->UL_PipeID,
  1355. pEndpoint->Id, ActualLength, netbuf, data_attr);
  1356. UNLOCK_HTC_TX(target);
  1357. return status;
  1358. }
  1359. #else /*ATH_11AC_TXCOMPACT */
  1360. /**
  1361. * htc_send_data_pkt() - htc_send_data_pkt
  1362. * @HTCHandle: pointer to HTC handle
  1363. * @pPacket: pointer to HTC_PACKET
  1364. * @more_data: indicates whether more data is to follow
  1365. *
  1366. * Return: A_OK for success or an appropriate A_STATUS error
  1367. */
  1368. A_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  1369. uint8_t more_data)
  1370. {
  1371. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1372. HTC_ENDPOINT *pEndpoint;
  1373. HTC_FRAME_HDR *pHtcHdr;
  1374. HTC_PACKET_QUEUE sendQueue;
  1375. qdf_nbuf_t netbuf = NULL;
  1376. int tx_resources;
  1377. A_STATUS status = A_OK;
  1378. uint32_t data_attr = 0;
  1379. if (pPacket) {
  1380. AR_DEBUG_ASSERT(pPacket->Endpoint < ENDPOINT_MAX);
  1381. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1382. /* add HTC_FRAME_HDR in the initial fragment */
  1383. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1384. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1385. AR_DEBUG_ASSERT(pHtcHdr);
  1386. HTC_WRITE32(pHtcHdr,
  1387. SM(pPacket->ActualLength,
  1388. HTC_FRAME_HDR_PAYLOADLEN) | SM(pPacket->PktInfo.
  1389. AsTx.SendFlags,
  1390. HTC_FRAME_HDR_FLAGS)
  1391. | SM(pPacket->Endpoint, HTC_FRAME_HDR_ENDPOINTID));
  1392. /*
  1393. * If the HIF pipe for the data endpoint is polled rather than
  1394. * interrupt-driven, this is a good point to check whether any
  1395. * data previously sent through the HIF pipe have finished being
  1396. * sent.
  1397. * Since this may result in callbacks to htc_tx_completion_handler,
  1398. * which can take the HTC tx lock, make the hif_send_complete_check
  1399. * call before acquiring the HTC tx lock.
  1400. * Call hif_send_complete_check directly, rather than calling
  1401. * htc_send_complete_check, and call the PollTimerStart separately
  1402. * after calling hif_send_head, so the timer will be started to
  1403. * check for completion of the new outstanding download (in the
  1404. * unexpected event that other polling calls don't catch it).
  1405. */
  1406. if (pEndpoint->ul_is_polled) {
  1407. htc_send_complete_poll_timer_stop(pEndpoint);
  1408. hif_send_complete_check(pEndpoint->target->hif_dev,
  1409. pEndpoint->UL_PipeID, 0);
  1410. }
  1411. LOCK_HTC_TX(target);
  1412. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1413. pEndpoint->SeqNo++;
  1414. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1415. SM(pPacket->PktInfo.AsTx.SeqNo,
  1416. HTC_FRAME_HDR_CONTROLBYTES1));
  1417. /* append new packet to pEndpoint->TxQueue */
  1418. HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket);
  1419. if (HTC_TX_BUNDLE_ENABLED(target) && (more_data)) {
  1420. UNLOCK_HTC_TX(target);
  1421. return A_OK;
  1422. }
  1423. } else {
  1424. LOCK_HTC_TX(target);
  1425. pEndpoint = &target->endpoint[1];
  1426. }
  1427. /* increment tx processing count on entry */
  1428. qdf_atomic_inc(&pEndpoint->TxProcessCount);
  1429. if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
  1430. /*
  1431. * Another thread or task is draining the TX queues on this endpoint.
  1432. * That thread will reset the tx processing count when the queue is
  1433. * drained.
  1434. */
  1435. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1436. UNLOCK_HTC_TX(target);
  1437. return A_OK;
  1438. }
  1439. /***** beyond this point only 1 thread may enter ******/
  1440. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1441. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1442. #if DEBUG_CREDIT
  1443. int cred = pEndpoint->TxCredits;
  1444. #endif
  1445. get_htc_send_packets_credit_based(target, pEndpoint, &sendQueue);
  1446. #if DEBUG_CREDIT
  1447. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1448. if (cred - pEndpoint->TxCredits > 0) {
  1449. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1450. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1451. pEndpoint->Id, cred,
  1452. cred - pEndpoint->TxCredits,
  1453. pEndpoint->TxCredits));
  1454. }
  1455. }
  1456. #endif
  1457. UNLOCK_HTC_TX(target);
  1458. }
  1459. else if (HTC_TX_BUNDLE_ENABLED(target)) {
  1460. if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) &&
  1461. hif_get_free_queue_number(target->hif_dev,
  1462. pEndpoint->UL_PipeID)) {
  1463. /*
  1464. * Header and payload belongs to the different fragments
  1465. * and consume 2 resource for one HTC package but USB
  1466. * combine into one transfer.
  1467. */
  1468. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1469. (HTC_MAX_MSG_PER_BUNDLE_TX * 2));
  1470. } else {
  1471. /* Dequeue max packets from endpoint tx queue */
  1472. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1473. HTC_MAX_TX_BUNDLE_SEND_LIMIT);
  1474. }
  1475. UNLOCK_HTC_TX(target);
  1476. }
  1477. else {
  1478. /*
  1479. * Now drain the endpoint TX queue for transmission as long as we have
  1480. * enough transmit resources
  1481. */
  1482. tx_resources =
  1483. hif_get_free_queue_number(target->hif_dev,
  1484. pEndpoint->UL_PipeID);
  1485. get_htc_send_packets(target, pEndpoint, &sendQueue, tx_resources);
  1486. UNLOCK_HTC_TX(target);
  1487. }
  1488. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1489. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1490. qdf_nbuf_data_addr(netbuf),
  1491. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1492. /* send what we can */
  1493. while (true) {
  1494. if (HTC_TX_BUNDLE_ENABLED(target) &&
  1495. (HTC_PACKET_QUEUE_DEPTH(&sendQueue) >=
  1496. HTC_MIN_MSG_PER_BUNDLE) &&
  1497. (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO ||
  1498. hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB)) {
  1499. htc_issue_packets_bundle(target, pEndpoint, &sendQueue);
  1500. }
  1501. pPacket = htc_packet_dequeue(&sendQueue);
  1502. if (pPacket == NULL) {
  1503. break;
  1504. }
  1505. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1506. LOCK_HTC_TX(target);
  1507. /* store in look up queue to match completions */
  1508. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  1509. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  1510. pEndpoint->ul_outstanding_cnt++;
  1511. UNLOCK_HTC_TX(target);
  1512. status = hif_send_head(target->hif_dev,
  1513. pEndpoint->UL_PipeID,
  1514. pEndpoint->Id,
  1515. HTC_HDR_LENGTH + pPacket->ActualLength,
  1516. netbuf, data_attr);
  1517. #if DEBUG_BUNDLE
  1518. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  1519. pEndpoint->Id,
  1520. pEndpoint->TxCreditSize,
  1521. HTC_HDR_LENGTH + pPacket->ActualLength);
  1522. #endif
  1523. htc_issue_tx_bundle_stats_inc(target);
  1524. if (qdf_unlikely(A_FAILED(status))) {
  1525. LOCK_HTC_TX(target);
  1526. pEndpoint->ul_outstanding_cnt--;
  1527. /* remove this packet from the tx completion queue */
  1528. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  1529. /*
  1530. * Don't bother reclaiming credits - HTC flow control
  1531. * is not applicable to tx data.
  1532. * In LL systems, there is no download flow control,
  1533. * since there's virtually no download delay.
  1534. * In HL systems, the txrx SW explicitly performs the
  1535. * tx flow control.
  1536. */
  1537. /* pEndpoint->TxCredits += pPacket->PktInfo.AsTx.CreditsUsed; */
  1538. /* put this frame back at the front of the sendQueue */
  1539. HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket);
  1540. /* put the sendQueue back at the front of pEndpoint->TxQueue */
  1541. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1542. &sendQueue);
  1543. UNLOCK_HTC_TX(target);
  1544. break; /* still need to reset TxProcessCount */
  1545. }
  1546. }
  1547. /* done with this endpoint, we can clear the count */
  1548. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1549. if (pEndpoint->ul_is_polled) {
  1550. /*
  1551. * Start a cleanup timer to poll for download completion.
  1552. * The download completion should be noticed promptly from
  1553. * other polling calls, but the timer provides a safety net
  1554. * in case other polling calls don't occur as expected.
  1555. */
  1556. htc_send_complete_poll_timer_start(pEndpoint);
  1557. }
  1558. return status;
  1559. }
  1560. #endif /*ATH_11AC_TXCOMPACT */
  1561. /*
  1562. * In the adapted HIF layer, qdf_nbuf_t are passed between HIF and HTC,
  1563. * since upper layers expects HTC_PACKET containers we use the completed netbuf
  1564. * and lookup its corresponding HTC packet buffer from a lookup list.
  1565. * This is extra overhead that can be fixed by re-aligning HIF interfaces
  1566. * with HTC.
  1567. *
  1568. */
  1569. static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target,
  1570. HTC_ENDPOINT *pEndpoint,
  1571. qdf_nbuf_t netbuf)
  1572. {
  1573. HTC_PACKET *pPacket = NULL;
  1574. HTC_PACKET *pFoundPacket = NULL;
  1575. HTC_PACKET_QUEUE lookupQueue;
  1576. INIT_HTC_PACKET_QUEUE(&lookupQueue);
  1577. LOCK_HTC_TX(target);
  1578. /* mark that HIF has indicated the send complete for another packet */
  1579. pEndpoint->ul_outstanding_cnt--;
  1580. /* Dequeue first packet directly because of in-order completion */
  1581. pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue);
  1582. if (qdf_unlikely(!pPacket)) {
  1583. UNLOCK_HTC_TX(target);
  1584. return NULL;
  1585. }
  1586. if (netbuf == (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1587. UNLOCK_HTC_TX(target);
  1588. return pPacket;
  1589. } else {
  1590. HTC_PACKET_ENQUEUE(&lookupQueue, pPacket);
  1591. }
  1592. /*
  1593. * Move TX lookup queue to temp queue because most of packets that are not index 0
  1594. * are not top 10 packets.
  1595. */
  1596. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue,
  1597. &pEndpoint->TxLookupQueue);
  1598. UNLOCK_HTC_TX(target);
  1599. ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket,
  1600. HTC_PACKET, ListLink) {
  1601. if (NULL == pPacket) {
  1602. pFoundPacket = pPacket;
  1603. break;
  1604. }
  1605. /* check for removal */
  1606. if (netbuf ==
  1607. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1608. /* found it */
  1609. HTC_PACKET_REMOVE(&lookupQueue, pPacket);
  1610. pFoundPacket = pPacket;
  1611. break;
  1612. }
  1613. }
  1614. ITERATE_END;
  1615. LOCK_HTC_TX(target);
  1616. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue,
  1617. &lookupQueue);
  1618. UNLOCK_HTC_TX(target);
  1619. return pFoundPacket;
  1620. }
  1621. /**
  1622. * htc_tx_completion_handler() - htc tx completion handler
  1623. * @Context: pointer to HTC_TARGET structure
  1624. * @netbuf: pointer to netbuf for which completion handler is being called
  1625. * @EpID: end point Id on which the packet was sent
  1626. * @toeplitz_hash_result: toeplitz hash result
  1627. *
  1628. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1629. */
  1630. QDF_STATUS htc_tx_completion_handler(void *Context,
  1631. qdf_nbuf_t netbuf, unsigned int EpID,
  1632. uint32_t toeplitz_hash_result)
  1633. {
  1634. HTC_TARGET *target = (HTC_TARGET *) Context;
  1635. HTC_ENDPOINT *pEndpoint;
  1636. HTC_PACKET *pPacket;
  1637. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1638. HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5, ENDPOINT_4,
  1639. ENDPOINT_2, ENDPOINT_3 };
  1640. int epidIdx;
  1641. uint16_t resourcesThresh[DATA_EP_SIZE]; /* urb resources */
  1642. uint16_t resources;
  1643. uint16_t resourcesMax;
  1644. #endif
  1645. pEndpoint = &target->endpoint[EpID];
  1646. target->TX_comp_cnt++;
  1647. do {
  1648. pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf);
  1649. if (NULL == pPacket) {
  1650. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1651. ("HTC TX lookup failed!\n"));
  1652. /* may have already been flushed and freed */
  1653. netbuf = NULL;
  1654. break;
  1655. }
  1656. if (pPacket->PktInfo.AsTx.Tag != HTC_TX_PACKET_TAG_AUTO_PM)
  1657. hif_pm_runtime_put(target->hif_dev);
  1658. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
  1659. HTC_PACKET *pPacketTemp;
  1660. HTC_PACKET_QUEUE *pQueueSave =
  1661. (HTC_PACKET_QUEUE *) pPacket->pContext;
  1662. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave,
  1663. pPacketTemp) {
  1664. pPacket->Status = A_OK;
  1665. send_packet_completion(target, pPacketTemp);
  1666. }
  1667. HTC_PACKET_QUEUE_ITERATE_END;
  1668. free_htc_bundle_packet(target, pPacket);
  1669. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) {
  1670. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  1671. htc_try_send(target, pEndpoint, NULL);
  1672. }
  1673. return QDF_STATUS_SUCCESS;
  1674. }
  1675. /* will be giving this buffer back to upper layers */
  1676. netbuf = NULL;
  1677. pPacket->Status = QDF_STATUS_SUCCESS;
  1678. send_packet_completion(target, pPacket);
  1679. } while (false);
  1680. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1681. /* note: when using TX credit flow, the re-checking of queues happens
  1682. * when credits flow back from the target.
  1683. * in the non-TX credit case, we recheck after the packet completes */
  1684. if ((qdf_atomic_read(&pEndpoint->TxProcessCount) == 0) ||
  1685. (!pEndpoint->async_update)) {
  1686. htc_try_send(target, pEndpoint, NULL);
  1687. }
  1688. }
  1689. return QDF_STATUS_SUCCESS;
  1690. }
  1691. #ifdef WLAN_FEATURE_FASTPATH
  1692. /**
  1693. * htc_ctrl_msg_cmpl(): checks for tx completion for the endpoint specified
  1694. * @HTC_HANDLE : pointer to the htc target context
  1695. * @htc_ep_id : end point id
  1696. *
  1697. * checks HTC tx completion
  1698. *
  1699. * Return: none
  1700. */
  1701. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id)
  1702. {
  1703. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_pdev);
  1704. HTC_ENDPOINT *pendpoint = &target->endpoint[htc_ep_id];
  1705. htc_send_complete_check(pendpoint, 1);
  1706. }
  1707. #endif
  1708. /* callback when TX resources become available */
  1709. void htc_tx_resource_avail_handler(void *context, uint8_t pipeID)
  1710. {
  1711. int i;
  1712. HTC_TARGET *target = (HTC_TARGET *) context;
  1713. HTC_ENDPOINT *pEndpoint = NULL;
  1714. for (i = 0; i < ENDPOINT_MAX; i++) {
  1715. pEndpoint = &target->endpoint[i];
  1716. if (pEndpoint->service_id != 0) {
  1717. if (pEndpoint->UL_PipeID == pipeID) {
  1718. break;
  1719. }
  1720. }
  1721. }
  1722. if (i >= ENDPOINT_MAX) {
  1723. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1724. ("Invalid pipe indicated for TX resource avail : %d!\n",
  1725. pipeID));
  1726. return;
  1727. }
  1728. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1729. ("HIF indicated more resources for pipe:%d \n",
  1730. pipeID));
  1731. htc_try_send(target, pEndpoint, NULL);
  1732. }
  1733. #ifdef FEATURE_RUNTIME_PM
  1734. /**
  1735. * htc_kick_queues(): resumes tx transactions of suspended endpoints
  1736. * @context: pointer to the htc target context
  1737. *
  1738. * Iterates throught the enpoints and provides a context to empty queues
  1739. * int the hif layer when they are stalled due to runtime suspend.
  1740. *
  1741. * Return: none
  1742. */
  1743. void htc_kick_queues(void *context)
  1744. {
  1745. int i;
  1746. HTC_TARGET *target = (HTC_TARGET *)context;
  1747. HTC_ENDPOINT *endpoint = NULL;
  1748. for (i = 0; i < ENDPOINT_MAX; i++) {
  1749. endpoint = &target->endpoint[i];
  1750. if (endpoint->service_id == 0)
  1751. continue;
  1752. if (endpoint->EpCallBacks.ep_resume_tx_queue)
  1753. endpoint->EpCallBacks.ep_resume_tx_queue(
  1754. endpoint->EpCallBacks.pContext);
  1755. htc_try_send(target, endpoint, NULL);
  1756. }
  1757. }
  1758. #endif
  1759. /* flush endpoint TX queue */
  1760. void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
  1761. HTC_TX_TAG Tag)
  1762. {
  1763. HTC_PACKET *pPacket;
  1764. LOCK_HTC_TX(target);
  1765. while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1766. pPacket = htc_packet_dequeue(&pEndpoint->TxQueue);
  1767. if (pPacket) {
  1768. /* let the sender know the packet was not delivered */
  1769. pPacket->Status = A_ECANCELED;
  1770. send_packet_completion(target, pPacket);
  1771. }
  1772. }
  1773. UNLOCK_HTC_TX(target);
  1774. }
  1775. /* HTC API to flush an endpoint's TX queue*/
  1776. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  1777. HTC_TX_TAG Tag)
  1778. {
  1779. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1780. HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
  1781. if (pEndpoint->service_id == 0) {
  1782. AR_DEBUG_ASSERT(false);
  1783. /* not in use.. */
  1784. return;
  1785. }
  1786. htc_flush_endpoint_tx(target, pEndpoint, Tag);
  1787. }
  1788. /* HTC API to indicate activity to the credit distribution function */
  1789. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  1790. HTC_ENDPOINT_ID Endpoint, bool Active)
  1791. {
  1792. /* TODO */
  1793. }
  1794. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
  1795. {
  1796. return true;
  1797. }
  1798. void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt)
  1799. {
  1800. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1801. target->is_nodrop_pkt = isNodropPkt;
  1802. }
  1803. /**
  1804. * htc_process_credit_rpt() - process credit report, call distribution function
  1805. * @target: pointer to HTC_TARGET
  1806. * @pRpt: pointer to HTC_CREDIT_REPORT
  1807. * @NumEntries: number of entries in credit report
  1808. * @FromEndpoint: endpoint for which credit report is received
  1809. *
  1810. * Return: A_OK for success or an appropriate A_STATUS error
  1811. */
  1812. void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt,
  1813. int NumEntries, HTC_ENDPOINT_ID FromEndpoint)
  1814. {
  1815. int i;
  1816. HTC_ENDPOINT *pEndpoint;
  1817. int totalCredits = 0;
  1818. uint8_t rpt_credits, rpt_ep_id;
  1819. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1820. ("+htc_process_credit_rpt, Credit Report Entries:%d \n",
  1821. NumEntries));
  1822. /* lock out TX while we update credits */
  1823. LOCK_HTC_TX(target);
  1824. for (i = 0; i < NumEntries; i++, pRpt++) {
  1825. rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID);
  1826. if (rpt_ep_id >= ENDPOINT_MAX) {
  1827. AR_DEBUG_ASSERT(false);
  1828. break;
  1829. }
  1830. rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS);
  1831. pEndpoint = &target->endpoint[rpt_ep_id];
  1832. #if DEBUG_CREDIT
  1833. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1834. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1835. (" <HTC> Increase EP%d %d + %d = %d credits\n",
  1836. rpt_ep_id, pEndpoint->TxCredits,
  1837. rpt_credits,
  1838. pEndpoint->TxCredits + rpt_credits));
  1839. }
  1840. #endif
  1841. #ifdef HTC_EP_STAT_PROFILING
  1842. INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1);
  1843. INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits);
  1844. if (FromEndpoint == rpt_ep_id) {
  1845. /* this credit report arrived on the same endpoint indicating it arrived in an RX
  1846. * packet */
  1847. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx,
  1848. rpt_credits);
  1849. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1);
  1850. } else if (FromEndpoint == ENDPOINT_0) {
  1851. /* this credit arrived on endpoint 0 as a NULL message */
  1852. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0,
  1853. rpt_credits);
  1854. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1);
  1855. } else {
  1856. /* arrived on another endpoint */
  1857. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther,
  1858. rpt_credits);
  1859. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1);
  1860. }
  1861. #endif
  1862. pEndpoint->TxCredits += rpt_credits;
  1863. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  1864. LOCK_HTC_CREDIT(target);
  1865. htc_credit_record(HTC_PROCESS_CREDIT_REPORT,
  1866. pEndpoint->TxCredits,
  1867. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  1868. TxQueue));
  1869. UNLOCK_HTC_CREDIT(target);
  1870. }
  1871. if (pEndpoint->TxCredits
  1872. && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1873. UNLOCK_HTC_TX(target);
  1874. #ifdef ATH_11AC_TXCOMPACT
  1875. htc_try_send(target, pEndpoint, NULL);
  1876. #else
  1877. if (pEndpoint->service_id == HTT_DATA_MSG_SVC) {
  1878. htc_send_data_pkt(target, NULL, 0);
  1879. } else {
  1880. htc_try_send(target, pEndpoint, NULL);
  1881. }
  1882. #endif
  1883. LOCK_HTC_TX(target);
  1884. }
  1885. totalCredits += rpt_credits;
  1886. }
  1887. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1888. (" Report indicated %d credits to distribute \n",
  1889. totalCredits));
  1890. UNLOCK_HTC_TX(target);
  1891. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt \n"));
  1892. }
  1893. /* function to fetch stats from htc layer*/
  1894. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle)
  1895. {
  1896. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1897. return &(target->htc_pkt_stats);
  1898. }