htc_send.c 64 KB

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