htc_send.c 64 KB

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