htc_send.c 64 KB

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