htc_send.c 73 KB

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