htc_send.c 64 KB

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