htc_send.c 64 KB

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