htc_send.c 64 KB

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