htc_send.c 64 KB

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