htc_send.c 64 KB

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