htc_send.c 63 KB

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