htc_send.c 74 KB

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