htc_send.c 64 KB

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