htc_send.c 61 KB

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