dp_htt.c 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869
  1. /*
  2. * Copyright (c) 2016-2017 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 <htt.h>
  19. #include <hal_api.h>
  20. #include "dp_htt.h"
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "dp_rx_mon.h"
  25. #include "htt_stats.h"
  26. #include "htt_ppdu_stats.h"
  27. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  28. #include "cdp_txrx_cmn_struct.h"
  29. #define HTT_TLV_HDR_LEN HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE
  30. #define HTT_HTC_PKT_POOL_INIT_SIZE 64
  31. #define HTT_T2H_MAX_MSG_SIZE 2048
  32. #define HTT_MSG_BUF_SIZE(msg_bytes) \
  33. ((msg_bytes) + HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING)
  34. #define DP_EXT_MSG_LENGTH 2048
  35. #define DP_HTT_SEND_HTC_PKT(soc, pkt) \
  36. do { \
  37. if (htc_send_pkt(soc->htc_soc, &pkt->htc_pkt) == \
  38. QDF_STATUS_SUCCESS) \
  39. htt_htc_misc_pkt_list_add(soc, pkt); \
  40. } while (0)
  41. #define HTT_MGMT_CTRL_TLV_RESERVERD_LEN 12
  42. /*
  43. * dp_tx_stats_update() - Update per-peer statistics
  44. * @soc: Datapath soc handle
  45. * @peer: Datapath peer handle
  46. * @ppdu: PPDU Descriptor
  47. * @ack_rssi: RSSI of last ack received
  48. *
  49. * Return: None
  50. */
  51. #ifdef FEATURE_PERPKT_INFO
  52. static void dp_tx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
  53. struct cdp_tx_completion_ppdu_user *ppdu, uint32_t ack_rssi)
  54. {
  55. struct dp_pdev *pdev = peer->vdev->pdev;
  56. uint8_t preamble, mcs;
  57. uint16_t num_msdu;
  58. preamble = ppdu->preamble;
  59. mcs = ppdu->mcs;
  60. num_msdu = ppdu->num_msdu;
  61. /* If the peer statistics are already processed as part of
  62. * per-MSDU completion handler, do not process these again in per-PPDU
  63. * indications */
  64. if (soc->process_tx_status)
  65. return;
  66. DP_STATS_INC_PKT(peer, tx.comp_pkt,
  67. num_msdu, (ppdu->success_bytes +
  68. ppdu->retry_bytes + ppdu->failed_bytes));
  69. DP_STATS_INC(peer, tx.tx_failed, ppdu->failed_msdus);
  70. DP_STATS_UPD(peer, tx.tx_rate, ppdu->tx_rate);
  71. DP_STATS_INC(peer, tx.sgi_count[ppdu->gi], num_msdu);
  72. DP_STATS_INC(peer, tx.bw[ppdu->bw], num_msdu);
  73. DP_STATS_UPD(peer, tx.last_ack_rssi, ack_rssi);
  74. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
  75. DP_STATS_INCC(peer, tx.stbc, num_msdu, ppdu->stbc);
  76. DP_STATS_INCC(peer, tx.ldpc, num_msdu, ppdu->ldpc);
  77. DP_STATS_INC_PKT(peer, tx.tx_success, ppdu->success_msdus,
  78. ppdu->success_bytes);
  79. if (ppdu->is_mcast) {
  80. DP_STATS_INC_PKT(peer, tx.mcast, num_msdu, (ppdu->success_bytes
  81. + ppdu->retry_bytes +
  82. ppdu->failed_bytes));
  83. } else {
  84. DP_STATS_INC_PKT(peer, tx.ucast, num_msdu, (ppdu->success_bytes
  85. + ppdu->retry_bytes +
  86. ppdu->failed_bytes));
  87. }
  88. DP_STATS_INC(peer, tx.retries,
  89. (ppdu->long_retries + ppdu->short_retries));
  90. DP_STATS_INCC(peer,
  91. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  92. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  93. DP_STATS_INCC(peer,
  94. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  95. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  96. DP_STATS_INCC(peer,
  97. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  98. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  99. DP_STATS_INCC(peer,
  100. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  101. ((mcs < (MAX_MCS_11B)) && (preamble == DOT11_B)));
  102. DP_STATS_INCC(peer,
  103. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  104. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  105. DP_STATS_INCC(peer,
  106. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  107. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  108. DP_STATS_INCC(peer,
  109. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  110. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  111. DP_STATS_INCC(peer,
  112. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  113. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  114. DP_STATS_INCC(peer,
  115. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  116. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  117. DP_STATS_INCC(peer,
  118. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  119. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  120. if (soc->cdp_soc.ol_ops->update_dp_stats) {
  121. soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
  122. &peer->stats, ppdu->peer_id,
  123. UPDATE_PEER_STATS);
  124. }
  125. }
  126. #endif
  127. /*
  128. * htt_htc_pkt_alloc() - Allocate HTC packet buffer
  129. * @htt_soc: HTT SOC handle
  130. *
  131. * Return: Pointer to htc packet buffer
  132. */
  133. static struct dp_htt_htc_pkt *
  134. htt_htc_pkt_alloc(struct htt_soc *soc)
  135. {
  136. struct dp_htt_htc_pkt_union *pkt = NULL;
  137. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  138. if (soc->htt_htc_pkt_freelist) {
  139. pkt = soc->htt_htc_pkt_freelist;
  140. soc->htt_htc_pkt_freelist = soc->htt_htc_pkt_freelist->u.next;
  141. }
  142. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  143. if (pkt == NULL)
  144. pkt = qdf_mem_malloc(sizeof(*pkt));
  145. return &pkt->u.pkt; /* not actually a dereference */
  146. }
  147. /*
  148. * htt_htc_pkt_free() - Free HTC packet buffer
  149. * @htt_soc: HTT SOC handle
  150. */
  151. static void
  152. htt_htc_pkt_free(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  153. {
  154. struct dp_htt_htc_pkt_union *u_pkt =
  155. (struct dp_htt_htc_pkt_union *)pkt;
  156. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  157. u_pkt->u.next = soc->htt_htc_pkt_freelist;
  158. soc->htt_htc_pkt_freelist = u_pkt;
  159. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  160. }
  161. /*
  162. * htt_htc_pkt_pool_free() - Free HTC packet pool
  163. * @htt_soc: HTT SOC handle
  164. */
  165. static void
  166. htt_htc_pkt_pool_free(struct htt_soc *soc)
  167. {
  168. struct dp_htt_htc_pkt_union *pkt, *next;
  169. pkt = soc->htt_htc_pkt_freelist;
  170. while (pkt) {
  171. next = pkt->u.next;
  172. qdf_mem_free(pkt);
  173. pkt = next;
  174. }
  175. soc->htt_htc_pkt_freelist = NULL;
  176. }
  177. /*
  178. * htt_htc_misc_pkt_list_trim() - trim misc list
  179. * @htt_soc: HTT SOC handle
  180. * @level: max no. of pkts in list
  181. */
  182. static void
  183. htt_htc_misc_pkt_list_trim(struct htt_soc *soc, int level)
  184. {
  185. struct dp_htt_htc_pkt_union *pkt, *next, *prev = NULL;
  186. int i = 0;
  187. qdf_nbuf_t netbuf;
  188. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  189. pkt = soc->htt_htc_pkt_misclist;
  190. while (pkt) {
  191. next = pkt->u.next;
  192. /* trim the out grown list*/
  193. if (++i > level) {
  194. netbuf =
  195. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  196. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  197. qdf_nbuf_free(netbuf);
  198. qdf_mem_free(pkt);
  199. pkt = NULL;
  200. if (prev)
  201. prev->u.next = NULL;
  202. }
  203. prev = pkt;
  204. pkt = next;
  205. }
  206. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  207. }
  208. /*
  209. * htt_htc_misc_pkt_list_add() - Add pkt to misc list
  210. * @htt_soc: HTT SOC handle
  211. * @dp_htt_htc_pkt: pkt to be added to list
  212. */
  213. static void
  214. htt_htc_misc_pkt_list_add(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  215. {
  216. struct dp_htt_htc_pkt_union *u_pkt =
  217. (struct dp_htt_htc_pkt_union *)pkt;
  218. int misclist_trim_level = htc_get_tx_queue_depth(soc->htc_soc,
  219. pkt->htc_pkt.Endpoint)
  220. + DP_HTT_HTC_PKT_MISCLIST_SIZE;
  221. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  222. if (soc->htt_htc_pkt_misclist) {
  223. u_pkt->u.next = soc->htt_htc_pkt_misclist;
  224. soc->htt_htc_pkt_misclist = u_pkt;
  225. } else {
  226. soc->htt_htc_pkt_misclist = u_pkt;
  227. }
  228. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  229. /* only ce pipe size + tx_queue_depth could possibly be in use
  230. * free older packets in the misclist
  231. */
  232. htt_htc_misc_pkt_list_trim(soc, misclist_trim_level);
  233. }
  234. /*
  235. * htt_htc_misc_pkt_pool_free() - free pkts in misc list
  236. * @htt_soc: HTT SOC handle
  237. */
  238. static void
  239. htt_htc_misc_pkt_pool_free(struct htt_soc *soc)
  240. {
  241. struct dp_htt_htc_pkt_union *pkt, *next;
  242. qdf_nbuf_t netbuf;
  243. pkt = soc->htt_htc_pkt_misclist;
  244. while (pkt) {
  245. next = pkt->u.next;
  246. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  247. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  248. soc->stats.htc_pkt_free++;
  249. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  250. "%s: Pkt free count %d\n",
  251. __func__, soc->stats.htc_pkt_free);
  252. qdf_nbuf_free(netbuf);
  253. qdf_mem_free(pkt);
  254. pkt = next;
  255. }
  256. soc->htt_htc_pkt_misclist = NULL;
  257. }
  258. /*
  259. * htt_t2h_mac_addr_deswizzle() - Swap MAC addr bytes if FW endianess differ
  260. * @tgt_mac_addr: Target MAC
  261. * @buffer: Output buffer
  262. */
  263. static u_int8_t *
  264. htt_t2h_mac_addr_deswizzle(u_int8_t *tgt_mac_addr, u_int8_t *buffer)
  265. {
  266. #ifdef BIG_ENDIAN_HOST
  267. /*
  268. * The host endianness is opposite of the target endianness.
  269. * To make u_int32_t elements come out correctly, the target->host
  270. * upload has swizzled the bytes in each u_int32_t element of the
  271. * message.
  272. * For byte-array message fields like the MAC address, this
  273. * upload swizzling puts the bytes in the wrong order, and needs
  274. * to be undone.
  275. */
  276. buffer[0] = tgt_mac_addr[3];
  277. buffer[1] = tgt_mac_addr[2];
  278. buffer[2] = tgt_mac_addr[1];
  279. buffer[3] = tgt_mac_addr[0];
  280. buffer[4] = tgt_mac_addr[7];
  281. buffer[5] = tgt_mac_addr[6];
  282. return buffer;
  283. #else
  284. /*
  285. * The host endianness matches the target endianness -
  286. * we can use the mac addr directly from the message buffer.
  287. */
  288. return tgt_mac_addr;
  289. #endif
  290. }
  291. /*
  292. * dp_htt_h2t_send_complete_free_netbuf() - Free completed buffer
  293. * @soc: SOC handle
  294. * @status: Completion status
  295. * @netbuf: HTT buffer
  296. */
  297. static void
  298. dp_htt_h2t_send_complete_free_netbuf(
  299. void *soc, A_STATUS status, qdf_nbuf_t netbuf)
  300. {
  301. qdf_nbuf_free(netbuf);
  302. }
  303. /*
  304. * dp_htt_h2t_send_complete() - H2T completion handler
  305. * @context: Opaque context (HTT SOC handle)
  306. * @htc_pkt: HTC packet
  307. */
  308. static void
  309. dp_htt_h2t_send_complete(void *context, HTC_PACKET *htc_pkt)
  310. {
  311. void (*send_complete_part2)(
  312. void *soc, A_STATUS status, qdf_nbuf_t msdu);
  313. struct htt_soc *soc = (struct htt_soc *) context;
  314. struct dp_htt_htc_pkt *htt_pkt;
  315. qdf_nbuf_t netbuf;
  316. send_complete_part2 = htc_pkt->pPktContext;
  317. htt_pkt = container_of(htc_pkt, struct dp_htt_htc_pkt, htc_pkt);
  318. /* process (free or keep) the netbuf that held the message */
  319. netbuf = (qdf_nbuf_t) htc_pkt->pNetBufContext;
  320. /*
  321. * adf sendcomplete is required for windows only
  322. */
  323. /* qdf_nbuf_set_sendcompleteflag(netbuf, TRUE); */
  324. if (send_complete_part2 != NULL) {
  325. send_complete_part2(
  326. htt_pkt->soc_ctxt, htc_pkt->Status, netbuf);
  327. }
  328. /* free the htt_htc_pkt / HTC_PACKET object */
  329. htt_htc_pkt_free(soc, htt_pkt);
  330. }
  331. /*
  332. * htt_h2t_ver_req_msg() - Send HTT version request message to target
  333. * @htt_soc: HTT SOC handle
  334. *
  335. * Return: 0 on success; error code on failure
  336. */
  337. static int htt_h2t_ver_req_msg(struct htt_soc *soc)
  338. {
  339. struct dp_htt_htc_pkt *pkt;
  340. qdf_nbuf_t msg;
  341. uint32_t *msg_word;
  342. msg = qdf_nbuf_alloc(
  343. soc->osdev,
  344. HTT_MSG_BUF_SIZE(HTT_VER_REQ_BYTES),
  345. /* reserve room for the HTC header */
  346. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  347. if (!msg)
  348. return QDF_STATUS_E_NOMEM;
  349. /*
  350. * Set the length of the message.
  351. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  352. * separately during the below call to qdf_nbuf_push_head.
  353. * The contribution from the HTC header is added separately inside HTC.
  354. */
  355. if (qdf_nbuf_put_tail(msg, HTT_VER_REQ_BYTES) == NULL) {
  356. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  357. "%s: Failed to expand head for HTT_H2T_MSG_TYPE_VERSION_REQ msg\n",
  358. __func__);
  359. return QDF_STATUS_E_FAILURE;
  360. }
  361. /* fill in the message contents */
  362. msg_word = (u_int32_t *) qdf_nbuf_data(msg);
  363. /* rewind beyond alignment pad to get to the HTC header reserved area */
  364. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  365. *msg_word = 0;
  366. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_VERSION_REQ);
  367. pkt = htt_htc_pkt_alloc(soc);
  368. if (!pkt) {
  369. qdf_nbuf_free(msg);
  370. return QDF_STATUS_E_FAILURE;
  371. }
  372. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  373. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  374. dp_htt_h2t_send_complete_free_netbuf, qdf_nbuf_data(msg),
  375. qdf_nbuf_len(msg), soc->htc_endpoint,
  376. 1); /* tag - not relevant here */
  377. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  378. DP_HTT_SEND_HTC_PKT(soc, pkt);
  379. return 0;
  380. }
  381. /*
  382. * htt_srng_setup() - Send SRNG setup message to target
  383. * @htt_soc: HTT SOC handle
  384. * @mac_id: MAC Id
  385. * @hal_srng: Opaque HAL SRNG pointer
  386. * @hal_ring_type: SRNG ring type
  387. *
  388. * Return: 0 on success; error code on failure
  389. */
  390. int htt_srng_setup(void *htt_soc, int mac_id, void *hal_srng,
  391. int hal_ring_type)
  392. {
  393. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  394. struct dp_htt_htc_pkt *pkt;
  395. qdf_nbuf_t htt_msg;
  396. uint32_t *msg_word;
  397. struct hal_srng_params srng_params;
  398. qdf_dma_addr_t hp_addr, tp_addr;
  399. uint32_t ring_entry_size =
  400. hal_srng_get_entrysize(soc->hal_soc, hal_ring_type);
  401. int htt_ring_type, htt_ring_id;
  402. /* Sizes should be set in 4-byte words */
  403. ring_entry_size = ring_entry_size >> 2;
  404. htt_msg = qdf_nbuf_alloc(soc->osdev,
  405. HTT_MSG_BUF_SIZE(HTT_SRING_SETUP_SZ),
  406. /* reserve room for the HTC header */
  407. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  408. if (!htt_msg)
  409. goto fail0;
  410. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  411. hp_addr = hal_srng_get_hp_addr(soc->hal_soc, hal_srng);
  412. tp_addr = hal_srng_get_tp_addr(soc->hal_soc, hal_srng);
  413. switch (hal_ring_type) {
  414. case RXDMA_BUF:
  415. #ifdef QCA_HOST2FW_RXBUF_RING
  416. if (srng_params.ring_id ==
  417. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0)) {
  418. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  419. htt_ring_type = HTT_SW_TO_SW_RING;
  420. #ifdef IPA_OFFLOAD
  421. } else if (srng_params.ring_id ==
  422. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF2)) {
  423. htt_ring_id = HTT_HOST2_TO_FW_RXBUF_RING;
  424. htt_ring_type = HTT_SW_TO_SW_RING;
  425. #endif
  426. #else
  427. if (srng_params.ring_id ==
  428. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0 +
  429. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  430. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  431. htt_ring_type = HTT_SW_TO_HW_RING;
  432. #endif
  433. } else if (srng_params.ring_id ==
  434. #ifdef IPA_OFFLOAD
  435. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF1 +
  436. #else
  437. (HAL_SRNG_WMAC1_SW2RXDMA1_BUF +
  438. #endif
  439. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  440. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  441. htt_ring_type = HTT_SW_TO_HW_RING;
  442. } else {
  443. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  444. "%s: Ring %d currently not supported\n",
  445. __func__, srng_params.ring_id);
  446. goto fail1;
  447. }
  448. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  449. "%s: ring_type %d ring_id %d\n",
  450. __func__, hal_ring_type, srng_params.ring_id);
  451. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  452. "%s: hp_addr 0x%llx tp_addr 0x%llx\n",
  453. __func__, (uint64_t)hp_addr, (uint64_t)tp_addr);
  454. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  455. "%s: htt_ring_id %d\n", __func__, htt_ring_id);
  456. break;
  457. case RXDMA_MONITOR_BUF:
  458. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  459. htt_ring_type = HTT_SW_TO_HW_RING;
  460. break;
  461. case RXDMA_MONITOR_STATUS:
  462. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  463. htt_ring_type = HTT_SW_TO_HW_RING;
  464. break;
  465. case RXDMA_MONITOR_DST:
  466. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  467. htt_ring_type = HTT_HW_TO_SW_RING;
  468. break;
  469. case RXDMA_MONITOR_DESC:
  470. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  471. htt_ring_type = HTT_SW_TO_HW_RING;
  472. break;
  473. case RXDMA_DST:
  474. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  475. htt_ring_type = HTT_HW_TO_SW_RING;
  476. break;
  477. default:
  478. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  479. "%s: Ring currently not supported\n", __func__);
  480. goto fail1;
  481. }
  482. /*
  483. * Set the length of the message.
  484. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  485. * separately during the below call to qdf_nbuf_push_head.
  486. * The contribution from the HTC header is added separately inside HTC.
  487. */
  488. if (qdf_nbuf_put_tail(htt_msg, HTT_SRING_SETUP_SZ) == NULL) {
  489. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  490. "%s: Failed to expand head for SRING_SETUP msg\n",
  491. __func__);
  492. return QDF_STATUS_E_FAILURE;
  493. }
  494. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  495. /* rewind beyond alignment pad to get to the HTC header reserved area */
  496. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  497. /* word 0 */
  498. *msg_word = 0;
  499. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_SRING_SETUP);
  500. if ((htt_ring_type == HTT_SW_TO_HW_RING) ||
  501. (htt_ring_type == HTT_HW_TO_SW_RING))
  502. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word,
  503. DP_SW2HW_MACID(mac_id));
  504. else
  505. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word, mac_id);
  506. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  507. "%s: mac_id %d\n", __func__, mac_id);
  508. HTT_SRING_SETUP_RING_TYPE_SET(*msg_word, htt_ring_type);
  509. /* TODO: Discuss with FW on changing this to unique ID and using
  510. * htt_ring_type to send the type of ring
  511. */
  512. HTT_SRING_SETUP_RING_ID_SET(*msg_word, htt_ring_id);
  513. /* word 1 */
  514. msg_word++;
  515. *msg_word = 0;
  516. HTT_SRING_SETUP_RING_BASE_ADDR_LO_SET(*msg_word,
  517. srng_params.ring_base_paddr & 0xffffffff);
  518. /* word 2 */
  519. msg_word++;
  520. *msg_word = 0;
  521. HTT_SRING_SETUP_RING_BASE_ADDR_HI_SET(*msg_word,
  522. (uint64_t)srng_params.ring_base_paddr >> 32);
  523. /* word 3 */
  524. msg_word++;
  525. *msg_word = 0;
  526. HTT_SRING_SETUP_ENTRY_SIZE_SET(*msg_word, ring_entry_size);
  527. HTT_SRING_SETUP_RING_SIZE_SET(*msg_word,
  528. (ring_entry_size * srng_params.num_entries));
  529. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  530. "%s: entry_size %d\n", __func__,
  531. ring_entry_size);
  532. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  533. "%s: num_entries %d\n", __func__,
  534. srng_params.num_entries);
  535. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  536. "%s: ring_size %d\n", __func__,
  537. (ring_entry_size * srng_params.num_entries));
  538. if (htt_ring_type == HTT_SW_TO_HW_RING)
  539. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_LOOPCOUNT_DISABLE_SET(
  540. *msg_word, 1);
  541. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_MSI_SWAP_SET(*msg_word,
  542. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  543. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_TLV_SWAP_SET(*msg_word,
  544. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  545. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_HOST_FW_SWAP_SET(*msg_word,
  546. !!(srng_params.flags & HAL_SRNG_RING_PTR_SWAP));
  547. /* word 4 */
  548. msg_word++;
  549. *msg_word = 0;
  550. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  551. hp_addr & 0xffffffff);
  552. /* word 5 */
  553. msg_word++;
  554. *msg_word = 0;
  555. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  556. (uint64_t)hp_addr >> 32);
  557. /* word 6 */
  558. msg_word++;
  559. *msg_word = 0;
  560. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  561. tp_addr & 0xffffffff);
  562. /* word 7 */
  563. msg_word++;
  564. *msg_word = 0;
  565. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  566. (uint64_t)tp_addr >> 32);
  567. /* word 8 */
  568. msg_word++;
  569. *msg_word = 0;
  570. HTT_SRING_SETUP_RING_MSI_ADDR_LO_SET(*msg_word,
  571. srng_params.msi_addr & 0xffffffff);
  572. /* word 9 */
  573. msg_word++;
  574. *msg_word = 0;
  575. HTT_SRING_SETUP_RING_MSI_ADDR_HI_SET(*msg_word,
  576. (uint64_t)(srng_params.msi_addr) >> 32);
  577. /* word 10 */
  578. msg_word++;
  579. *msg_word = 0;
  580. HTT_SRING_SETUP_RING_MSI_DATA_SET(*msg_word,
  581. srng_params.msi_data);
  582. /* word 11 */
  583. msg_word++;
  584. *msg_word = 0;
  585. HTT_SRING_SETUP_INTR_BATCH_COUNTER_TH_SET(*msg_word,
  586. srng_params.intr_batch_cntr_thres_entries *
  587. ring_entry_size);
  588. HTT_SRING_SETUP_INTR_TIMER_TH_SET(*msg_word,
  589. srng_params.intr_timer_thres_us >> 3);
  590. /* word 12 */
  591. msg_word++;
  592. *msg_word = 0;
  593. if (srng_params.flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  594. /* TODO: Setting low threshold to 1/8th of ring size - see
  595. * if this needs to be configurable
  596. */
  597. HTT_SRING_SETUP_INTR_LOW_TH_SET(*msg_word,
  598. srng_params.low_threshold);
  599. }
  600. /* "response_required" field should be set if a HTT response message is
  601. * required after setting up the ring.
  602. */
  603. pkt = htt_htc_pkt_alloc(soc);
  604. if (!pkt)
  605. goto fail1;
  606. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  607. SET_HTC_PACKET_INFO_TX(
  608. &pkt->htc_pkt,
  609. dp_htt_h2t_send_complete_free_netbuf,
  610. qdf_nbuf_data(htt_msg),
  611. qdf_nbuf_len(htt_msg),
  612. soc->htc_endpoint,
  613. HTC_TX_PACKET_TAG_RUNTIME_PUT); /* tag for no FW response msg */
  614. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  615. DP_HTT_SEND_HTC_PKT(soc, pkt);
  616. return QDF_STATUS_SUCCESS;
  617. fail1:
  618. qdf_nbuf_free(htt_msg);
  619. fail0:
  620. return QDF_STATUS_E_FAILURE;
  621. }
  622. /*
  623. * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
  624. * config message to target
  625. * @htt_soc: HTT SOC handle
  626. * @pdev_id: PDEV Id
  627. * @hal_srng: Opaque HAL SRNG pointer
  628. * @hal_ring_type: SRNG ring type
  629. * @ring_buf_size: SRNG buffer size
  630. * @htt_tlv_filter: Rx SRNG TLV and filter setting
  631. * Return: 0 on success; error code on failure
  632. */
  633. int htt_h2t_rx_ring_cfg(void *htt_soc, int pdev_id, void *hal_srng,
  634. int hal_ring_type, int ring_buf_size,
  635. struct htt_rx_ring_tlv_filter *htt_tlv_filter)
  636. {
  637. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  638. struct dp_htt_htc_pkt *pkt;
  639. qdf_nbuf_t htt_msg;
  640. uint32_t *msg_word;
  641. struct hal_srng_params srng_params;
  642. uint32_t htt_ring_type, htt_ring_id;
  643. uint32_t tlv_filter;
  644. htt_msg = qdf_nbuf_alloc(soc->osdev,
  645. HTT_MSG_BUF_SIZE(HTT_RX_RING_SELECTION_CFG_SZ),
  646. /* reserve room for the HTC header */
  647. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  648. if (!htt_msg)
  649. goto fail0;
  650. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  651. switch (hal_ring_type) {
  652. case RXDMA_BUF:
  653. #if QCA_HOST2FW_RXBUF_RING
  654. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  655. htt_ring_type = HTT_SW_TO_SW_RING;
  656. #else
  657. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  658. htt_ring_type = HTT_SW_TO_HW_RING;
  659. #endif
  660. break;
  661. case RXDMA_MONITOR_BUF:
  662. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  663. htt_ring_type = HTT_SW_TO_HW_RING;
  664. break;
  665. case RXDMA_MONITOR_STATUS:
  666. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  667. htt_ring_type = HTT_SW_TO_HW_RING;
  668. break;
  669. case RXDMA_MONITOR_DST:
  670. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  671. htt_ring_type = HTT_HW_TO_SW_RING;
  672. break;
  673. case RXDMA_MONITOR_DESC:
  674. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  675. htt_ring_type = HTT_SW_TO_HW_RING;
  676. break;
  677. case RXDMA_DST:
  678. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  679. htt_ring_type = HTT_HW_TO_SW_RING;
  680. break;
  681. default:
  682. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  683. "%s: Ring currently not supported\n", __func__);
  684. goto fail1;
  685. }
  686. /*
  687. * Set the length of the message.
  688. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  689. * separately during the below call to qdf_nbuf_push_head.
  690. * The contribution from the HTC header is added separately inside HTC.
  691. */
  692. if (qdf_nbuf_put_tail(htt_msg, HTT_RX_RING_SELECTION_CFG_SZ) == NULL) {
  693. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  694. "%s: Failed to expand head for RX Ring Cfg msg\n",
  695. __func__);
  696. goto fail1; /* failure */
  697. }
  698. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  699. /* rewind beyond alignment pad to get to the HTC header reserved area */
  700. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  701. /* word 0 */
  702. *msg_word = 0;
  703. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG);
  704. /*
  705. * pdev_id is indexed from 0 whereas mac_id is indexed from 1
  706. * SW_TO_SW and SW_TO_HW rings are unaffected by this
  707. */
  708. if (htt_ring_type == HTT_SW_TO_SW_RING ||
  709. htt_ring_type == HTT_SW_TO_HW_RING)
  710. HTT_RX_RING_SELECTION_CFG_PDEV_ID_SET(*msg_word,
  711. DP_SW2HW_MACID(pdev_id));
  712. /* TODO: Discuss with FW on changing this to unique ID and using
  713. * htt_ring_type to send the type of ring
  714. */
  715. HTT_RX_RING_SELECTION_CFG_RING_ID_SET(*msg_word, htt_ring_id);
  716. HTT_RX_RING_SELECTION_CFG_STATUS_TLV_SET(*msg_word,
  717. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  718. HTT_RX_RING_SELECTION_CFG_PKT_TLV_SET(*msg_word,
  719. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  720. /* word 1 */
  721. msg_word++;
  722. *msg_word = 0;
  723. HTT_RX_RING_SELECTION_CFG_RING_BUFFER_SIZE_SET(*msg_word,
  724. ring_buf_size);
  725. /* word 2 */
  726. msg_word++;
  727. *msg_word = 0;
  728. if (htt_tlv_filter->enable_fp) {
  729. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  730. MGMT, 0000, 1);
  731. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  732. MGMT, 0001, 1);
  733. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  734. MGMT, 0010, 1);
  735. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  736. MGMT, 0011, 1);
  737. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  738. MGMT, 0100, 1);
  739. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  740. MGMT, 0101, 1);
  741. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  742. MGMT, 0110, 1);
  743. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  744. MGMT, 0111, 1);
  745. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  746. MGMT, 1000, 1);
  747. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  748. MGMT, 1001, 1);
  749. }
  750. if (htt_tlv_filter->enable_md) {
  751. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  752. MGMT, 0000, 1);
  753. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  754. MGMT, 0001, 1);
  755. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  756. MGMT, 0010, 1);
  757. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  758. MGMT, 0011, 1);
  759. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  760. MGMT, 0100, 1);
  761. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  762. MGMT, 0101, 1);
  763. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  764. MGMT, 0110, 1);
  765. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  766. MGMT, 0111, 1);
  767. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  768. MGMT, 1000, 1);
  769. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  770. MGMT, 1001, 1);
  771. }
  772. if (htt_tlv_filter->enable_mo) {
  773. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  774. MGMT, 0000, 1);
  775. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  776. MGMT, 0001, 1);
  777. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  778. MGMT, 0010, 1);
  779. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  780. MGMT, 0011, 1);
  781. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  782. MGMT, 0100, 1);
  783. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  784. MGMT, 0101, 1);
  785. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  786. MGMT, 0110, 1);
  787. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  788. MGMT, 0111, 1);
  789. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  790. MGMT, 1000, 1);
  791. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  792. MGMT, 1001, 1);
  793. }
  794. /* word 3 */
  795. msg_word++;
  796. *msg_word = 0;
  797. if (htt_tlv_filter->enable_fp) {
  798. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  799. MGMT, 1010, 1);
  800. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  801. MGMT, 1011, 1);
  802. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  803. MGMT, 1100, 1);
  804. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  805. MGMT, 1101, 1);
  806. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  807. MGMT, 1110, 1);
  808. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  809. MGMT, 1111, 1);
  810. }
  811. if (htt_tlv_filter->enable_md) {
  812. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  813. MGMT, 1010, 1);
  814. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  815. MGMT, 1011, 1);
  816. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  817. MGMT, 1100, 1);
  818. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  819. MGMT, 1101, 1);
  820. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  821. MGMT, 1110, 1);
  822. }
  823. if (htt_tlv_filter->enable_mo) {
  824. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  825. MGMT, 1010, 1);
  826. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  827. MGMT, 1011, 1);
  828. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  829. MGMT, 1100, 1);
  830. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  831. MGMT, 1101, 1);
  832. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  833. MGMT, 1110, 1);
  834. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  835. MGMT, 1111, 1);
  836. }
  837. /* word 4 */
  838. msg_word++;
  839. *msg_word = 0;
  840. if (htt_tlv_filter->enable_fp) {
  841. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  842. CTRL, 0000, 1);
  843. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  844. CTRL, 0001, 1);
  845. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  846. CTRL, 0010, 1);
  847. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  848. CTRL, 0011, 1);
  849. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  850. CTRL, 0100, 1);
  851. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  852. CTRL, 0101, 1);
  853. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  854. CTRL, 0110, 1);
  855. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  856. CTRL, 0111, 1);
  857. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  858. CTRL, 1000, 1);
  859. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  860. CTRL, 1001, 1);
  861. }
  862. if (htt_tlv_filter->enable_md) {
  863. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  864. CTRL, 0000, 1);
  865. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  866. CTRL, 0001, 1);
  867. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  868. CTRL, 0010, 1);
  869. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  870. CTRL, 0011, 1);
  871. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  872. CTRL, 0100, 1);
  873. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  874. CTRL, 0101, 1);
  875. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  876. CTRL, 0110, 1);
  877. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  878. CTRL, 0111, 1);
  879. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  880. CTRL, 1000, 1);
  881. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  882. CTRL, 1001, 1);
  883. }
  884. if (htt_tlv_filter->enable_mo) {
  885. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  886. CTRL, 0000, 1);
  887. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  888. CTRL, 0001, 1);
  889. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  890. CTRL, 0010, 1);
  891. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  892. CTRL, 0011, 1);
  893. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  894. CTRL, 0100, 1);
  895. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  896. CTRL, 0101, 1);
  897. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  898. CTRL, 0110, 1);
  899. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  900. CTRL, 0111, 1);
  901. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  902. CTRL, 1000, 1);
  903. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  904. CTRL, 1001, 1);
  905. }
  906. /* word 5 */
  907. msg_word++;
  908. *msg_word = 0;
  909. if (htt_tlv_filter->enable_fp) {
  910. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  911. CTRL, 1010, 1);
  912. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  913. CTRL, 1011, 1);
  914. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  915. CTRL, 1100, 1);
  916. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  917. CTRL, 1101, 1);
  918. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  919. CTRL, 1110, 1);
  920. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  921. CTRL, 1111, 1);
  922. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  923. DATA, MCAST, 1);
  924. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  925. DATA, UCAST, 1);
  926. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  927. DATA, NULL, 1);
  928. }
  929. if (htt_tlv_filter->enable_md) {
  930. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  931. CTRL, 1010, 1);
  932. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  933. CTRL, 1011, 1);
  934. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  935. CTRL, 1100, 1);
  936. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  937. CTRL, 1101, 1);
  938. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  939. CTRL, 1110, 1);
  940. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  941. CTRL, 1111, 1);
  942. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  943. DATA, MCAST, 1);
  944. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  945. DATA, UCAST, 1);
  946. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  947. DATA, NULL, 1);
  948. }
  949. if (htt_tlv_filter->enable_mo) {
  950. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  951. CTRL, 1010, 1);
  952. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  953. CTRL, 1011, 1);
  954. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  955. CTRL, 1100, 1);
  956. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  957. CTRL, 1101, 1);
  958. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  959. CTRL, 1110, 1);
  960. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  961. CTRL, 1111, 1);
  962. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  963. DATA, MCAST, 1);
  964. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  965. DATA, UCAST, 1);
  966. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  967. DATA, NULL, 1);
  968. }
  969. /* word 6 */
  970. msg_word++;
  971. *msg_word = 0;
  972. tlv_filter = 0;
  973. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_START,
  974. htt_tlv_filter->mpdu_start);
  975. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_START,
  976. htt_tlv_filter->msdu_start);
  977. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET,
  978. htt_tlv_filter->packet);
  979. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_END,
  980. htt_tlv_filter->msdu_end);
  981. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_END,
  982. htt_tlv_filter->mpdu_end);
  983. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET_HEADER,
  984. htt_tlv_filter->packet_header);
  985. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, ATTENTION,
  986. htt_tlv_filter->attention);
  987. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_START,
  988. htt_tlv_filter->ppdu_start);
  989. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END,
  990. htt_tlv_filter->ppdu_end);
  991. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_USER_STATS,
  992. htt_tlv_filter->ppdu_end_user_stats);
  993. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter,
  994. PPDU_END_USER_STATS_EXT,
  995. htt_tlv_filter->ppdu_end_user_stats_ext);
  996. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_STATUS_DONE,
  997. htt_tlv_filter->ppdu_end_status_done);
  998. /* RESERVED bit maps to header_per_msdu in htt_tlv_filter*/
  999. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, RESERVED,
  1000. htt_tlv_filter->header_per_msdu);
  1001. HTT_RX_RING_SELECTION_CFG_TLV_FILTER_IN_FLAG_SET(*msg_word, tlv_filter);
  1002. /* "response_required" field should be set if a HTT response message is
  1003. * required after setting up the ring.
  1004. */
  1005. pkt = htt_htc_pkt_alloc(soc);
  1006. if (!pkt)
  1007. goto fail1;
  1008. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  1009. SET_HTC_PACKET_INFO_TX(
  1010. &pkt->htc_pkt,
  1011. dp_htt_h2t_send_complete_free_netbuf,
  1012. qdf_nbuf_data(htt_msg),
  1013. qdf_nbuf_len(htt_msg),
  1014. soc->htc_endpoint,
  1015. 1); /* tag - not relevant here */
  1016. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  1017. DP_HTT_SEND_HTC_PKT(soc, pkt);
  1018. return QDF_STATUS_SUCCESS;
  1019. fail1:
  1020. qdf_nbuf_free(htt_msg);
  1021. fail0:
  1022. return QDF_STATUS_E_FAILURE;
  1023. }
  1024. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1025. static inline QDF_STATUS dp_send_htt_stat_resp(struct htt_stats_context *htt_stats,
  1026. struct dp_soc *soc, qdf_nbuf_t htt_msg)
  1027. {
  1028. uint32_t pdev_id;
  1029. uint32_t *msg_word = NULL;
  1030. uint32_t msg_remain_len = 0;
  1031. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1032. /*COOKIE MSB*/
  1033. pdev_id = *(msg_word + 2);
  1034. /* stats message length + 16 size of HTT header*/
  1035. msg_remain_len = qdf_min(htt_stats->msg_len + 16,
  1036. (uint32_t)DP_EXT_MSG_LENGTH);
  1037. dp_wdi_event_handler(WDI_EVENT_HTT_STATS, soc,
  1038. msg_word, msg_remain_len,
  1039. WDI_NO_VAL, pdev_id);
  1040. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1041. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1042. }
  1043. /* Need to be freed here as WDI handler will
  1044. * make a copy of pkt to send data to application
  1045. */
  1046. qdf_nbuf_free(htt_msg);
  1047. return QDF_STATUS_SUCCESS;
  1048. }
  1049. #else
  1050. static inline QDF_STATUS dp_send_htt_stat_resp(struct htt_stats_context *htt_stats,
  1051. struct dp_soc *soc, qdf_nbuf_t htt_msg)
  1052. {
  1053. return QDF_STATUS_E_NOSUPPORT;
  1054. }
  1055. #endif
  1056. /**
  1057. * dp_process_htt_stat_msg(): Process the list of buffers of HTT EXT stats
  1058. * @htt_stats: htt stats info
  1059. *
  1060. * The FW sends the HTT EXT STATS as a stream of T2H messages. Each T2H message
  1061. * contains sub messages which are identified by a TLV header.
  1062. * In this function we will process the stream of T2H messages and read all the
  1063. * TLV contained in the message.
  1064. *
  1065. * THe following cases have been taken care of
  1066. * Case 1: When the tlv_remain_length <= msg_remain_length of HTT MSG buffer
  1067. * In this case the buffer will contain multiple tlvs.
  1068. * Case 2: When the tlv_remain_length > msg_remain_length of HTT MSG buffer.
  1069. * Only one tlv will be contained in the HTT message and this tag
  1070. * will extend onto the next buffer.
  1071. * Case 3: When the buffer is the continuation of the previous message
  1072. * Case 4: tlv length is 0. which will indicate the end of message
  1073. *
  1074. * return: void
  1075. */
  1076. static inline void dp_process_htt_stat_msg(struct htt_stats_context *htt_stats,
  1077. struct dp_soc *soc)
  1078. {
  1079. htt_tlv_tag_t tlv_type = 0xff;
  1080. qdf_nbuf_t htt_msg = NULL;
  1081. uint32_t *msg_word;
  1082. uint8_t *tlv_buf_head = NULL;
  1083. uint8_t *tlv_buf_tail = NULL;
  1084. uint32_t msg_remain_len = 0;
  1085. uint32_t tlv_remain_len = 0;
  1086. uint32_t *tlv_start;
  1087. int cookie_val;
  1088. /* Process node in the HTT message queue */
  1089. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1090. != NULL) {
  1091. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1092. cookie_val = *(msg_word + 1);
  1093. if (cookie_val) {
  1094. if (dp_send_htt_stat_resp(htt_stats, soc, htt_msg)
  1095. == QDF_STATUS_SUCCESS) {
  1096. continue;
  1097. }
  1098. }
  1099. /* read 5th word */
  1100. msg_word = msg_word + 4;
  1101. msg_remain_len = qdf_min(htt_stats->msg_len,
  1102. (uint32_t) DP_EXT_MSG_LENGTH);
  1103. /* Keep processing the node till node length is 0 */
  1104. while (msg_remain_len) {
  1105. /*
  1106. * if message is not a continuation of previous message
  1107. * read the tlv type and tlv length
  1108. */
  1109. if (!tlv_buf_head) {
  1110. tlv_type = HTT_STATS_TLV_TAG_GET(
  1111. *msg_word);
  1112. tlv_remain_len = HTT_STATS_TLV_LENGTH_GET(
  1113. *msg_word);
  1114. }
  1115. if (tlv_remain_len == 0) {
  1116. msg_remain_len = 0;
  1117. if (tlv_buf_head) {
  1118. qdf_mem_free(tlv_buf_head);
  1119. tlv_buf_head = NULL;
  1120. tlv_buf_tail = NULL;
  1121. }
  1122. goto error;
  1123. }
  1124. tlv_remain_len += HTT_TLV_HDR_LEN;
  1125. if ((tlv_remain_len <= msg_remain_len)) {
  1126. /* Case 3 */
  1127. if (tlv_buf_head) {
  1128. qdf_mem_copy(tlv_buf_tail,
  1129. (uint8_t *)msg_word,
  1130. tlv_remain_len);
  1131. tlv_start = (uint32_t *)tlv_buf_head;
  1132. } else {
  1133. /* Case 1 */
  1134. tlv_start = msg_word;
  1135. }
  1136. dp_htt_stats_print_tag(tlv_type, tlv_start);
  1137. msg_remain_len -= tlv_remain_len;
  1138. msg_word = (uint32_t *)
  1139. (((uint8_t *)msg_word) +
  1140. tlv_remain_len);
  1141. tlv_remain_len = 0;
  1142. if (tlv_buf_head) {
  1143. qdf_mem_free(tlv_buf_head);
  1144. tlv_buf_head = NULL;
  1145. tlv_buf_tail = NULL;
  1146. }
  1147. } else { /* tlv_remain_len > msg_remain_len */
  1148. /* Case 2 & 3 */
  1149. if (!tlv_buf_head) {
  1150. tlv_buf_head = qdf_mem_malloc(
  1151. tlv_remain_len);
  1152. if (!tlv_buf_head) {
  1153. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1154. QDF_TRACE_LEVEL_ERROR,
  1155. "Alloc failed");
  1156. goto error;
  1157. }
  1158. tlv_buf_tail = tlv_buf_head;
  1159. }
  1160. qdf_mem_copy(tlv_buf_tail, (uint8_t *)msg_word,
  1161. msg_remain_len);
  1162. tlv_remain_len -= msg_remain_len;
  1163. tlv_buf_tail += msg_remain_len;
  1164. msg_remain_len = 0;
  1165. }
  1166. }
  1167. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1168. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1169. }
  1170. qdf_nbuf_free(htt_msg);
  1171. }
  1172. return;
  1173. error:
  1174. qdf_nbuf_free(htt_msg);
  1175. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1176. != NULL)
  1177. qdf_nbuf_free(htt_msg);
  1178. }
  1179. void htt_t2h_stats_handler(void *context)
  1180. {
  1181. struct dp_soc *soc = (struct dp_soc *)context;
  1182. struct htt_stats_context htt_stats;
  1183. uint32_t length;
  1184. uint32_t *msg_word;
  1185. qdf_nbuf_t htt_msg = NULL;
  1186. uint8_t done;
  1187. uint8_t rem_stats;
  1188. if (!soc || !qdf_atomic_read(&soc->cmn_init_done)) {
  1189. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1190. "soc: 0x%pK, init_done: %d", soc,
  1191. qdf_atomic_read(&soc->cmn_init_done));
  1192. return;
  1193. }
  1194. qdf_mem_zero(&htt_stats, sizeof(htt_stats));
  1195. qdf_nbuf_queue_init(&htt_stats.msg);
  1196. /* pull one completed stats from soc->htt_stats_msg and process */
  1197. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1198. if (!soc->htt_stats.num_stats) {
  1199. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1200. return;
  1201. }
  1202. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats.msg)) != NULL) {
  1203. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1204. msg_word = msg_word + HTT_T2H_EXT_STATS_TLV_START_OFFSET;
  1205. length = HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_GET(*msg_word);
  1206. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1207. qdf_nbuf_queue_add(&htt_stats.msg, htt_msg);
  1208. /*
  1209. * HTT EXT stats response comes as stream of TLVs which span over
  1210. * multiple T2H messages.
  1211. * The first message will carry length of the response.
  1212. * For rest of the messages length will be zero.
  1213. */
  1214. if (length)
  1215. htt_stats.msg_len = length;
  1216. /*
  1217. * Done bit signifies that this is the last T2H buffer in the
  1218. * stream of HTT EXT STATS message
  1219. */
  1220. if (done)
  1221. break;
  1222. }
  1223. rem_stats = --soc->htt_stats.num_stats;
  1224. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1225. dp_process_htt_stat_msg(&htt_stats, soc);
  1226. /* If there are more stats to process, schedule stats work again */
  1227. if (rem_stats)
  1228. qdf_sched_work(0, &soc->htt_stats.work);
  1229. }
  1230. /*
  1231. * dp_get_ppdu_info_user_index: Find place holder for the received
  1232. * ppdu stats info
  1233. * pdev: DP pdev handle
  1234. *
  1235. * return:user index to be populated
  1236. */
  1237. #ifdef FEATURE_PERPKT_INFO
  1238. static uint8_t dp_get_ppdu_info_user_index(struct dp_pdev *pdev,
  1239. uint16_t peer_id)
  1240. {
  1241. uint8_t user_index = 0;
  1242. struct cdp_tx_completion_ppdu *ppdu_desc;
  1243. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1244. ppdu_desc =
  1245. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1246. while ((user_index + 1) <= pdev->tx_ppdu_info.last_user) {
  1247. ppdu_user_desc = &ppdu_desc->user[user_index];
  1248. if (ppdu_user_desc->peer_id != peer_id) {
  1249. user_index++;
  1250. continue;
  1251. } else {
  1252. /* Max users possible is 8 so user array index should
  1253. * not exceed 7
  1254. */
  1255. qdf_assert_always(user_index <= CDP_MU_MAX_USER_INDEX);
  1256. return user_index;
  1257. }
  1258. }
  1259. pdev->tx_ppdu_info.last_user++;
  1260. /* Max users possible is 8 so last user should not exceed 8 */
  1261. qdf_assert_always(pdev->tx_ppdu_info.last_user <= CDP_MU_MAX_USERS);
  1262. return pdev->tx_ppdu_info.last_user - 1;
  1263. }
  1264. /*
  1265. * dp_process_ppdu_stats_common_tlv: Process htt_ppdu_stats_common_tlv
  1266. * pdev: DP pdev handle
  1267. * @tag_buf: buffer containing the tlv htt_ppdu_stats_common_tlv
  1268. *
  1269. * return:void
  1270. */
  1271. static void dp_process_ppdu_stats_common_tlv(struct dp_pdev *pdev,
  1272. uint32_t *tag_buf)
  1273. {
  1274. uint16_t frame_type;
  1275. uint16_t freq;
  1276. struct dp_soc *soc = NULL;
  1277. struct cdp_tx_completion_ppdu *ppdu_desc;
  1278. htt_ppdu_stats_common_tlv *dp_stats_buf =
  1279. (htt_ppdu_stats_common_tlv *)tag_buf;
  1280. ppdu_desc =
  1281. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1282. ppdu_desc->ppdu_id = dp_stats_buf->ppdu_id;
  1283. tag_buf += 2;
  1284. ppdu_desc->num_users =
  1285. HTT_PPDU_STATS_COMMON_TLV_NUM_USERS_GET(*tag_buf);
  1286. tag_buf++;
  1287. frame_type = HTT_PPDU_STATS_COMMON_TLV_FRM_TYPE_GET(*tag_buf);
  1288. if ((frame_type == HTT_STATS_FTYPE_TIDQ_DATA_SU) ||
  1289. (frame_type == HTT_STATS_FTYPE_TIDQ_DATA_MU))
  1290. ppdu_desc->frame_type = CDP_PPDU_FTYPE_DATA;
  1291. else
  1292. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1293. tag_buf += 2;
  1294. ppdu_desc->tx_duration = *tag_buf;
  1295. tag_buf += 3;
  1296. ppdu_desc->ppdu_start_timestamp = *tag_buf;
  1297. ppdu_desc->ppdu_end_timestamp = 0; /*TODO: value to be provided by FW */
  1298. tag_buf++;
  1299. freq = HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_GET(*tag_buf);
  1300. if (freq != ppdu_desc->channel) {
  1301. soc = pdev->soc;
  1302. ppdu_desc->channel = freq;
  1303. if (soc && soc->cdp_soc.ol_ops->freq_to_channel)
  1304. pdev->operating_channel =
  1305. soc->cdp_soc.ol_ops->freq_to_channel(pdev->osif_pdev, freq);
  1306. }
  1307. ppdu_desc->phy_mode = HTT_PPDU_STATS_COMMON_TLV_PHY_MODE_GET(*tag_buf);
  1308. }
  1309. /*
  1310. * dp_process_ppdu_stats_user_common_tlv: Process ppdu_stats_user_common
  1311. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_common_tlv
  1312. *
  1313. * return:void
  1314. */
  1315. static void dp_process_ppdu_stats_user_common_tlv(
  1316. struct dp_pdev *pdev, uint32_t *tag_buf)
  1317. {
  1318. uint16_t peer_id;
  1319. struct dp_peer *peer;
  1320. struct cdp_tx_completion_ppdu *ppdu_desc;
  1321. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1322. uint8_t curr_user_index = 0;
  1323. ppdu_desc =
  1324. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1325. tag_buf++;
  1326. peer_id = HTT_PPDU_STATS_USER_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1327. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1328. if (!peer)
  1329. return;
  1330. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1331. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1332. ppdu_user_desc->peer_id = peer_id;
  1333. tag_buf++;
  1334. if (HTT_PPDU_STATS_USER_COMMON_TLV_MCAST_GET(*tag_buf)) {
  1335. ppdu_user_desc->is_mcast = true;
  1336. ppdu_user_desc->mpdu_tried_mcast =
  1337. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1338. } else {
  1339. ppdu_user_desc->mpdu_tried_ucast =
  1340. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1341. }
  1342. tag_buf++;
  1343. ppdu_user_desc->qos_ctrl =
  1344. HTT_PPDU_STATS_USER_COMMON_TLV_QOS_CTRL_GET(*tag_buf);
  1345. ppdu_user_desc->frame_ctrl =
  1346. HTT_PPDU_STATS_USER_COMMON_TLV_FRAME_CTRL_GET(*tag_buf);
  1347. }
  1348. /**
  1349. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  1350. * @pdev: DP pdev handle
  1351. * @tag_buf: T2H message buffer carrying the user rate TLV
  1352. *
  1353. * return:void
  1354. */
  1355. static void dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  1356. uint32_t *tag_buf)
  1357. {
  1358. uint16_t peer_id;
  1359. struct dp_peer *peer;
  1360. struct cdp_tx_completion_ppdu *ppdu_desc;
  1361. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1362. uint8_t curr_user_index = 0;
  1363. ppdu_desc =
  1364. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1365. tag_buf++;
  1366. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1367. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1368. if (!peer)
  1369. return;
  1370. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1371. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1372. ppdu_user_desc->peer_id = peer_id;
  1373. ppdu_user_desc->tid =
  1374. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  1375. qdf_mem_copy(ppdu_user_desc->mac_addr, peer->mac_addr.raw,
  1376. DP_MAC_ADDR_LEN);
  1377. tag_buf += 2;
  1378. ppdu_user_desc->ru_tones = (HTT_PPDU_STATS_USER_RATE_TLV_RU_END_GET(*tag_buf) -
  1379. HTT_PPDU_STATS_USER_RATE_TLV_RU_START_GET(*tag_buf)) + 1;
  1380. tag_buf += 2;
  1381. ppdu_user_desc->ppdu_type =
  1382. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  1383. tag_buf++;
  1384. ppdu_user_desc->tx_rate = *tag_buf;
  1385. ppdu_user_desc->ltf_size =
  1386. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  1387. ppdu_user_desc->stbc =
  1388. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  1389. ppdu_user_desc->he_re =
  1390. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  1391. ppdu_user_desc->txbf =
  1392. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  1393. ppdu_user_desc->bw =
  1394. HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf);
  1395. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  1396. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  1397. ppdu_user_desc->preamble =
  1398. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  1399. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  1400. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  1401. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  1402. }
  1403. /*
  1404. * dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv: Process
  1405. * htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1406. * pdev: DP PDEV handle
  1407. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1408. *
  1409. * return:void
  1410. */
  1411. static void dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  1412. struct dp_pdev *pdev, uint32_t *tag_buf)
  1413. {
  1414. htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *dp_stats_buf =
  1415. (htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *)tag_buf;
  1416. struct cdp_tx_completion_ppdu *ppdu_desc;
  1417. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1418. uint8_t curr_user_index = 0;
  1419. uint16_t peer_id;
  1420. struct dp_peer *peer;
  1421. ppdu_desc =
  1422. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1423. tag_buf++;
  1424. peer_id =
  1425. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1426. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1427. if (!peer)
  1428. return;
  1429. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1430. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1431. ppdu_user_desc->peer_id = peer_id;
  1432. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1433. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1434. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1435. }
  1436. /*
  1437. * dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv: Process
  1438. * htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1439. * soc: DP SOC handle
  1440. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1441. *
  1442. * return:void
  1443. */
  1444. static void dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  1445. struct dp_pdev *pdev, uint32_t *tag_buf)
  1446. {
  1447. htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *dp_stats_buf =
  1448. (htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *)tag_buf;
  1449. struct cdp_tx_completion_ppdu *ppdu_desc;
  1450. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1451. uint8_t curr_user_index = 0;
  1452. uint16_t peer_id;
  1453. struct dp_peer *peer;
  1454. ppdu_desc =
  1455. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1456. tag_buf++;
  1457. peer_id =
  1458. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1459. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1460. if (!peer)
  1461. return;
  1462. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1463. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1464. ppdu_user_desc->peer_id = peer_id;
  1465. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1466. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1467. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1468. }
  1469. /*
  1470. * dp_process_ppdu_stats_user_cmpltn_common_tlv: Process
  1471. * htt_ppdu_stats_user_cmpltn_common_tlv
  1472. * soc: DP SOC handle
  1473. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_cmpltn_common_tlv
  1474. *
  1475. * return:void
  1476. */
  1477. static void dp_process_ppdu_stats_user_cmpltn_common_tlv(
  1478. struct dp_pdev *pdev, uint32_t *tag_buf)
  1479. {
  1480. uint16_t peer_id;
  1481. struct dp_peer *peer;
  1482. struct cdp_tx_completion_ppdu *ppdu_desc;
  1483. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1484. uint8_t curr_user_index = 0;
  1485. htt_ppdu_stats_user_cmpltn_common_tlv *dp_stats_buf =
  1486. (htt_ppdu_stats_user_cmpltn_common_tlv *)tag_buf;
  1487. ppdu_desc =
  1488. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1489. tag_buf++;
  1490. peer_id =
  1491. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1492. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1493. if (!peer)
  1494. return;
  1495. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1496. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1497. ppdu_user_desc->peer_id = peer_id;
  1498. ppdu_user_desc->completion_status =
  1499. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_COMPLETION_STATUS_GET(
  1500. *tag_buf);
  1501. ppdu_user_desc->tid =
  1502. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TID_NUM_GET(*tag_buf);
  1503. tag_buf++;
  1504. ppdu_desc->ack_rssi = dp_stats_buf->ack_rssi;
  1505. tag_buf++;
  1506. ppdu_user_desc->mpdu_success =
  1507. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_SUCCESS_GET(*tag_buf);
  1508. tag_buf++;
  1509. ppdu_user_desc->long_retries =
  1510. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_LONG_RETRY_GET(*tag_buf);
  1511. ppdu_user_desc->short_retries =
  1512. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SHORT_RETRY_GET(*tag_buf);
  1513. ppdu_user_desc->retry_msdus =
  1514. ppdu_user_desc->long_retries + ppdu_user_desc->short_retries;
  1515. ppdu_user_desc->is_ampdu =
  1516. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_AMPDU_GET(*tag_buf);
  1517. }
  1518. /*
  1519. * dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv: Process
  1520. * htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1521. * pdev: DP PDEV handle
  1522. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1523. *
  1524. * return:void
  1525. */
  1526. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  1527. struct dp_pdev *pdev, uint32_t *tag_buf)
  1528. {
  1529. htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *dp_stats_buf =
  1530. (htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *)tag_buf;
  1531. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1532. struct cdp_tx_completion_ppdu *ppdu_desc;
  1533. uint8_t curr_user_index = 0;
  1534. uint16_t peer_id;
  1535. struct dp_peer *peer;
  1536. ppdu_desc =
  1537. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1538. tag_buf++;
  1539. peer_id =
  1540. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1541. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1542. if (!peer)
  1543. return;
  1544. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1545. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1546. ppdu_user_desc->peer_id = peer_id;
  1547. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1548. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1549. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1550. }
  1551. /*
  1552. * dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv: Process
  1553. * htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1554. * pdev: DP PDEV handle
  1555. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1556. *
  1557. * return:void
  1558. */
  1559. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  1560. struct dp_pdev *pdev, uint32_t *tag_buf)
  1561. {
  1562. htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *dp_stats_buf =
  1563. (htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *)tag_buf;
  1564. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1565. struct cdp_tx_completion_ppdu *ppdu_desc;
  1566. uint8_t curr_user_index = 0;
  1567. uint16_t peer_id;
  1568. struct dp_peer *peer;
  1569. ppdu_desc =
  1570. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1571. tag_buf++;
  1572. peer_id =
  1573. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1574. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1575. if (!peer)
  1576. return;
  1577. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1578. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1579. ppdu_user_desc->peer_id = peer_id;
  1580. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1581. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1582. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1583. }
  1584. /*
  1585. * dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv: Process
  1586. * htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1587. * pdev: DP PDE handle
  1588. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1589. *
  1590. * return:void
  1591. */
  1592. static void dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  1593. struct dp_pdev *pdev, uint32_t *tag_buf)
  1594. {
  1595. uint16_t peer_id;
  1596. struct dp_peer *peer;
  1597. struct cdp_tx_completion_ppdu *ppdu_desc;
  1598. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1599. uint8_t curr_user_index = 0;
  1600. ppdu_desc =
  1601. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1602. tag_buf += 2;
  1603. peer_id =
  1604. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_SW_PEER_ID_GET(*tag_buf);
  1605. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1606. if (!peer)
  1607. return;
  1608. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1609. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1610. ppdu_user_desc->peer_id = peer_id;
  1611. tag_buf++;
  1612. ppdu_user_desc->num_mpdu =
  1613. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MPDU_GET(*tag_buf);
  1614. ppdu_user_desc->num_msdu =
  1615. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MSDU_GET(*tag_buf);
  1616. ppdu_user_desc->success_msdus = ppdu_user_desc->num_msdu;
  1617. tag_buf += 2;
  1618. ppdu_user_desc->success_bytes = *tag_buf;
  1619. }
  1620. /*
  1621. * dp_process_ppdu_stats_user_common_array_tlv: Process
  1622. * htt_ppdu_stats_user_common_array_tlv
  1623. * pdev: DP PDEV handle
  1624. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1625. *
  1626. * return:void
  1627. */
  1628. static void dp_process_ppdu_stats_user_common_array_tlv(struct dp_pdev *pdev,
  1629. uint32_t *tag_buf)
  1630. {
  1631. uint32_t peer_id;
  1632. struct dp_peer *peer;
  1633. struct cdp_tx_completion_ppdu *ppdu_desc;
  1634. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1635. uint8_t curr_user_index = 0;
  1636. struct htt_tx_ppdu_stats_info *dp_stats_buf;
  1637. ppdu_desc =
  1638. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1639. tag_buf++;
  1640. dp_stats_buf = (struct htt_tx_ppdu_stats_info *)tag_buf;
  1641. tag_buf += 3;
  1642. peer_id =
  1643. HTT_PPDU_STATS_ARRAY_ITEM_TLV_PEERID_GET(*tag_buf);
  1644. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1645. if (!peer) {
  1646. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1647. "Invalid peer");
  1648. return;
  1649. }
  1650. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1651. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1652. ppdu_user_desc->retry_bytes = dp_stats_buf->tx_retry_bytes;
  1653. ppdu_user_desc->failed_bytes = dp_stats_buf->tx_failed_bytes;
  1654. tag_buf++;
  1655. ppdu_user_desc->success_msdus =
  1656. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_SUCC_MSDUS_GET(*tag_buf);
  1657. ppdu_user_desc->retry_bytes =
  1658. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_RETRY_MSDUS_GET(*tag_buf);
  1659. tag_buf++;
  1660. ppdu_user_desc->failed_msdus =
  1661. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_FAILED_MSDUS_GET(*tag_buf);
  1662. }
  1663. /*
  1664. * dp_process_ppdu_stats_flush_tlv: Process
  1665. * htt_ppdu_stats_flush_tlv
  1666. * @pdev: DP PDEV handle
  1667. * @tag_buf: buffer containing the htt_ppdu_stats_flush_tlv
  1668. *
  1669. * return:void
  1670. */
  1671. static void dp_process_ppdu_stats_user_compltn_flush_tlv(struct dp_pdev *pdev,
  1672. uint32_t *tag_buf)
  1673. {
  1674. uint32_t peer_id;
  1675. uint32_t drop_reason;
  1676. uint8_t tid;
  1677. uint32_t num_msdu;
  1678. struct dp_peer *peer;
  1679. tag_buf++;
  1680. drop_reason = *tag_buf;
  1681. tag_buf++;
  1682. num_msdu = HTT_PPDU_STATS_FLUSH_TLV_NUM_MSDU_GET(*tag_buf);
  1683. tag_buf++;
  1684. peer_id =
  1685. HTT_PPDU_STATS_FLUSH_TLV_SW_PEER_ID_GET(*tag_buf);
  1686. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1687. if (!peer)
  1688. return;
  1689. tid = HTT_PPDU_STATS_FLUSH_TLV_TID_NUM_GET(*tag_buf);
  1690. if (drop_reason == HTT_FLUSH_EXCESS_RETRIES) {
  1691. DP_STATS_INC(peer, tx.excess_retries[TID_TO_WME_AC(tid)],
  1692. num_msdu);
  1693. }
  1694. }
  1695. /*
  1696. * dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv: Process
  1697. * htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1698. * @pdev: DP PDEV handle
  1699. * @tag_buf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1700. * @length: tlv_length
  1701. *
  1702. * return:void
  1703. */
  1704. static void dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(
  1705. struct dp_pdev *pdev, uint32_t *tag_buf, uint32_t length)
  1706. {
  1707. htt_ppdu_stats_tx_mgmtctrl_payload_tlv *dp_stats_buf =
  1708. (htt_ppdu_stats_tx_mgmtctrl_payload_tlv *)tag_buf;
  1709. qdf_nbuf_t nbuf = NULL;
  1710. uint32_t payload_size = length - HTT_MGMT_CTRL_TLV_RESERVERD_LEN;
  1711. nbuf = qdf_nbuf_alloc(pdev->soc->osdev, payload_size, 0, 4, true);
  1712. if (!nbuf) {
  1713. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1714. "Nbuf Allocation failed for Mgmt. payload");
  1715. qdf_assert(0);
  1716. return;
  1717. }
  1718. qdf_nbuf_put_tail(nbuf, payload_size);
  1719. qdf_mem_copy(qdf_nbuf_data(nbuf), dp_stats_buf->payload, payload_size);
  1720. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  1721. nbuf, HTT_INVALID_PEER,
  1722. WDI_NO_VAL, pdev->pdev_id);
  1723. }
  1724. /**
  1725. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  1726. * @soc: DP Physical device (radio) handle
  1727. * @tag_buf: TLV buffer
  1728. *
  1729. * return: void
  1730. */
  1731. static void dp_process_ppdu_tag(struct dp_pdev *pdev, uint32_t *tag_buf,
  1732. uint32_t tlv_len)
  1733. {
  1734. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  1735. switch (tlv_type) {
  1736. case HTT_PPDU_STATS_COMMON_TLV:
  1737. dp_process_ppdu_stats_common_tlv(pdev, tag_buf);
  1738. break;
  1739. case HTT_PPDU_STATS_USR_COMMON_TLV:
  1740. dp_process_ppdu_stats_user_common_tlv(pdev, tag_buf);
  1741. break;
  1742. case HTT_PPDU_STATS_USR_RATE_TLV:
  1743. qdf_assert_always(tlv_len ==
  1744. sizeof(htt_ppdu_stats_user_rate_tlv));
  1745. dp_process_ppdu_stats_user_rate_tlv(pdev, tag_buf);
  1746. break;
  1747. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_64_TLV:
  1748. dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(pdev, tag_buf);
  1749. break;
  1750. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_256_TLV:
  1751. dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(pdev, tag_buf);
  1752. break;
  1753. case HTT_PPDU_STATS_USR_COMPLTN_COMMON_TLV:
  1754. dp_process_ppdu_stats_user_cmpltn_common_tlv(pdev, tag_buf);
  1755. break;
  1756. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_64_TLV:
  1757. dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(pdev,
  1758. tag_buf);
  1759. break;
  1760. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_256_TLV:
  1761. dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(pdev,
  1762. tag_buf);
  1763. break;
  1764. case HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV:
  1765. dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(pdev,
  1766. tag_buf);
  1767. break;
  1768. case HTT_PPDU_STATS_USR_COMMON_ARRAY_TLV:
  1769. dp_process_ppdu_stats_user_common_array_tlv(pdev,
  1770. tag_buf);
  1771. break;
  1772. case HTT_PPDU_STATS_USR_COMPLTN_FLUSH_TLV:
  1773. dp_process_ppdu_stats_user_compltn_flush_tlv(pdev,
  1774. tag_buf);
  1775. break;
  1776. case HTT_PPDU_STATS_TX_MGMTCTRL_PAYLOAD_TLV:
  1777. dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(pdev,
  1778. tag_buf, tlv_len);
  1779. break;
  1780. default:
  1781. break;
  1782. }
  1783. }
  1784. static QDF_STATUS dp_htt_process_tlv(struct dp_pdev *pdev,
  1785. qdf_nbuf_t htt_t2h_msg)
  1786. {
  1787. uint32_t length;
  1788. uint32_t ppdu_id;
  1789. uint8_t tlv_type;
  1790. uint32_t tlv_length;
  1791. uint8_t *tlv_buf;
  1792. QDF_STATUS status = QDF_STATUS_E_PENDING;
  1793. uint32_t *msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1794. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  1795. msg_word = msg_word + 1;
  1796. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  1797. msg_word = msg_word + 3;
  1798. while (length > 0) {
  1799. tlv_buf = (uint8_t *)msg_word;
  1800. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  1801. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  1802. if (tlv_length == 0)
  1803. break;
  1804. if (tlv_type == HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)
  1805. status = QDF_STATUS_SUCCESS;
  1806. tlv_length += HTT_TLV_HDR_LEN;
  1807. dp_process_ppdu_tag(pdev, msg_word, tlv_length);
  1808. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  1809. length -= (tlv_length);
  1810. }
  1811. return status;
  1812. }
  1813. #endif /* FEATURE_PERPKT_INFO */
  1814. /**
  1815. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  1816. * @soc: DP SOC handle
  1817. * @pdev_id: pdev id
  1818. * @htt_t2h_msg: HTT message nbuf
  1819. *
  1820. * return:void
  1821. */
  1822. #if defined(WDI_EVENT_ENABLE)
  1823. #ifdef FEATURE_PERPKT_INFO
  1824. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1825. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1826. {
  1827. struct dp_pdev *pdev = soc->pdev_list[pdev_id];
  1828. struct dp_vdev *vdev;
  1829. struct dp_peer *peer;
  1830. struct cdp_tx_completion_ppdu *ppdu_desc;
  1831. int status;
  1832. int i;
  1833. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable &&
  1834. !pdev->am_copy_mode)
  1835. return;
  1836. if (!pdev->tx_ppdu_info.buf) {
  1837. /*
  1838. * Todo: For MU/OFDMA, we need to account for multiple user
  1839. * descriptors in a PPDU, in skb size.
  1840. * The allocation has to be moved to ppdu_cmn tlv processing
  1841. */
  1842. pdev->tx_ppdu_info.buf = qdf_nbuf_alloc(soc->osdev,
  1843. sizeof(struct cdp_tx_completion_ppdu), 0, 4,
  1844. TRUE);
  1845. if (!pdev->tx_ppdu_info.buf) {
  1846. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1847. "Nbuf Allocation failed for HTT PPDU");
  1848. return;
  1849. }
  1850. qdf_mem_zero(qdf_nbuf_data(pdev->tx_ppdu_info.buf),
  1851. sizeof(struct cdp_tx_completion_ppdu));
  1852. if (qdf_nbuf_put_tail(pdev->tx_ppdu_info.buf,
  1853. sizeof(struct cdp_tx_completion_ppdu)) == NULL) {
  1854. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1855. "No tailroom for HTT PPDU");
  1856. return;
  1857. }
  1858. }
  1859. status = dp_htt_process_tlv(pdev, htt_t2h_msg);
  1860. if (status == QDF_STATUS_SUCCESS) {
  1861. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  1862. qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1863. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  1864. ppdu_desc->vdev_id);
  1865. for (i = 0; i < ppdu_desc->num_users; i++) {
  1866. peer = dp_peer_find_by_id(soc,
  1867. ppdu_desc->user[i].peer_id);
  1868. if (!peer)
  1869. continue;
  1870. ppdu_desc->num_mpdu += ppdu_desc->user[i].num_mpdu;
  1871. ppdu_desc->num_msdu += ppdu_desc->user[i].num_msdu;
  1872. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA) {
  1873. dp_tx_stats_update(soc, peer,
  1874. &ppdu_desc->user[i],
  1875. ppdu_desc->ack_rssi);
  1876. }
  1877. }
  1878. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC, soc,
  1879. pdev->tx_ppdu_info.buf, HTT_INVALID_PEER,
  1880. WDI_NO_VAL, pdev_id);
  1881. pdev->tx_ppdu_info.buf = NULL;
  1882. pdev->tx_ppdu_info.last_user = 0;
  1883. }
  1884. }
  1885. #else
  1886. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1887. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1888. {
  1889. }
  1890. #endif
  1891. #endif
  1892. /**
  1893. * dp_txrx_fw_stats_handler() - Function to process HTT EXT stats
  1894. * @soc: DP SOC handle
  1895. * @htt_t2h_msg: HTT message nbuf
  1896. *
  1897. * return:void
  1898. */
  1899. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  1900. qdf_nbuf_t htt_t2h_msg)
  1901. {
  1902. uint8_t done;
  1903. qdf_nbuf_t msg_copy;
  1904. uint32_t *msg_word;
  1905. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1906. msg_word = msg_word + 3;
  1907. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1908. /*
  1909. * HTT EXT stats response comes as stream of TLVs which span over
  1910. * multiple T2H messages.
  1911. * The first message will carry length of the response.
  1912. * For rest of the messages length will be zero.
  1913. *
  1914. * Clone the T2H message buffer and store it in a list to process
  1915. * it later.
  1916. *
  1917. * The original T2H message buffers gets freed in the T2H HTT event
  1918. * handler
  1919. */
  1920. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  1921. if (!msg_copy) {
  1922. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1923. "T2H messge clone failed for HTT EXT STATS");
  1924. goto error;
  1925. }
  1926. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1927. qdf_nbuf_queue_add(&soc->htt_stats.msg, msg_copy);
  1928. /*
  1929. * Done bit signifies that this is the last T2H buffer in the stream of
  1930. * HTT EXT STATS message
  1931. */
  1932. if (done) {
  1933. soc->htt_stats.num_stats++;
  1934. qdf_sched_work(0, &soc->htt_stats.work);
  1935. }
  1936. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1937. return;
  1938. error:
  1939. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1940. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats.msg))
  1941. != NULL) {
  1942. qdf_nbuf_free(msg_copy);
  1943. }
  1944. soc->htt_stats.num_stats = 0;
  1945. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1946. return;
  1947. }
  1948. /*
  1949. * htt_soc_attach_target() - SOC level HTT setup
  1950. * @htt_soc: HTT SOC handle
  1951. *
  1952. * Return: 0 on success; error code on failure
  1953. */
  1954. int htt_soc_attach_target(void *htt_soc)
  1955. {
  1956. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1957. return htt_h2t_ver_req_msg(soc);
  1958. }
  1959. #if defined(WDI_EVENT_ENABLE) && !defined(REMOVE_PKT_LOG)
  1960. /*
  1961. * dp_ppdu_stats_ind_handler() - PPDU stats msg handler
  1962. * @htt_soc: HTT SOC handle
  1963. * @msg_word: Pointer to payload
  1964. * @htt_t2h_msg: HTT msg nbuf
  1965. *
  1966. * Return: None
  1967. */
  1968. static void
  1969. dp_ppdu_stats_ind_handler(struct htt_soc *soc,
  1970. uint32_t *msg_word,
  1971. qdf_nbuf_t htt_t2h_msg)
  1972. {
  1973. u_int8_t pdev_id;
  1974. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  1975. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1976. "received HTT_T2H_MSG_TYPE_PPDU_STATS_IND\n");
  1977. pdev_id = HTT_T2H_PPDU_STATS_MAC_ID_GET(*msg_word);
  1978. pdev_id = DP_HW2SW_MACID(pdev_id);
  1979. dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  1980. htt_t2h_msg);
  1981. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  1982. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  1983. pdev_id);
  1984. }
  1985. #else
  1986. dp_ppdu_stats_ind_handler(struct htt_soc *soc,
  1987. qdf_nbuf_t htt_t2h_msg)
  1988. {
  1989. }
  1990. #endif
  1991. #if defined(WDI_EVENT_ENABLE) && \
  1992. !defined(REMOVE_PKT_LOG) && defined(CONFIG_WIN)
  1993. /*
  1994. * dp_pktlog_msg_handler() - Pktlog msg handler
  1995. * @htt_soc: HTT SOC handle
  1996. * @msg_word: Pointer to payload
  1997. *
  1998. * Return: None
  1999. */
  2000. static void
  2001. dp_pktlog_msg_handler(struct htt_soc *soc,
  2002. uint32_t *msg_word)
  2003. {
  2004. uint8_t pdev_id;
  2005. uint32_t *pl_hdr;
  2006. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  2007. "received HTT_T2H_MSG_TYPE_PKTLOG\n");
  2008. pdev_id = HTT_T2H_PKTLOG_MAC_ID_GET(*msg_word);
  2009. pdev_id = DP_HW2SW_MACID(pdev_id);
  2010. pl_hdr = (msg_word + 1);
  2011. dp_wdi_event_handler(WDI_EVENT_OFFLOAD_ALL, soc->dp_soc,
  2012. pl_hdr, HTT_INVALID_PEER, WDI_NO_VAL,
  2013. pdev_id);
  2014. }
  2015. #else
  2016. static void
  2017. dp_pktlog_msg_handler(struct htt_soc *soc,
  2018. uint32_t *msg_word)
  2019. {
  2020. }
  2021. #endif
  2022. /*
  2023. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  2024. * @context: Opaque context (HTT SOC handle)
  2025. * @pkt: HTC packet
  2026. */
  2027. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  2028. {
  2029. struct htt_soc *soc = (struct htt_soc *) context;
  2030. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  2031. u_int32_t *msg_word;
  2032. enum htt_t2h_msg_type msg_type;
  2033. /* check for successful message reception */
  2034. if (pkt->Status != QDF_STATUS_SUCCESS) {
  2035. if (pkt->Status != QDF_STATUS_E_CANCELED)
  2036. soc->stats.htc_err_cnt++;
  2037. qdf_nbuf_free(htt_t2h_msg);
  2038. return;
  2039. }
  2040. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  2041. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  2042. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  2043. switch (msg_type) {
  2044. case HTT_T2H_MSG_TYPE_PEER_MAP:
  2045. {
  2046. u_int8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
  2047. u_int8_t *peer_mac_addr;
  2048. u_int16_t peer_id;
  2049. u_int16_t hw_peer_id;
  2050. u_int8_t vdev_id;
  2051. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  2052. hw_peer_id =
  2053. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  2054. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  2055. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  2056. (u_int8_t *) (msg_word+1),
  2057. &mac_addr_deswizzle_buf[0]);
  2058. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2059. QDF_TRACE_LEVEL_INFO,
  2060. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  2061. peer_id, vdev_id);
  2062. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  2063. vdev_id, peer_mac_addr);
  2064. break;
  2065. }
  2066. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  2067. {
  2068. u_int16_t peer_id;
  2069. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  2070. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id);
  2071. break;
  2072. }
  2073. case HTT_T2H_MSG_TYPE_SEC_IND:
  2074. {
  2075. u_int16_t peer_id;
  2076. enum htt_sec_type sec_type;
  2077. int is_unicast;
  2078. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  2079. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  2080. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  2081. /* point to the first part of the Michael key */
  2082. msg_word++;
  2083. dp_rx_sec_ind_handler(
  2084. soc->dp_soc, peer_id, sec_type, is_unicast,
  2085. msg_word, msg_word + 2);
  2086. break;
  2087. }
  2088. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  2089. {
  2090. dp_ppdu_stats_ind_handler(soc, msg_word, htt_t2h_msg);
  2091. break;
  2092. }
  2093. case HTT_T2H_MSG_TYPE_PKTLOG:
  2094. {
  2095. dp_pktlog_msg_handler(soc, msg_word);
  2096. break;
  2097. }
  2098. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  2099. {
  2100. htc_pm_runtime_put(soc->htc_soc);
  2101. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  2102. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  2103. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  2104. "target uses HTT version %d.%d; host uses %d.%d\n",
  2105. soc->tgt_ver.major, soc->tgt_ver.minor,
  2106. HTT_CURRENT_VERSION_MAJOR,
  2107. HTT_CURRENT_VERSION_MINOR);
  2108. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  2109. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2110. QDF_TRACE_LEVEL_ERROR,
  2111. "*** Incompatible host/target HTT versions!\n");
  2112. }
  2113. /* abort if the target is incompatible with the host */
  2114. qdf_assert(soc->tgt_ver.major ==
  2115. HTT_CURRENT_VERSION_MAJOR);
  2116. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  2117. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2118. QDF_TRACE_LEVEL_WARN,
  2119. "*** Warning: host/target HTT versions"
  2120. " are different, though compatible!\n");
  2121. }
  2122. break;
  2123. }
  2124. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  2125. {
  2126. uint16_t peer_id;
  2127. uint8_t tid;
  2128. uint8_t win_sz;
  2129. uint16_t status;
  2130. struct dp_peer *peer;
  2131. /*
  2132. * Update REO Queue Desc with new values
  2133. */
  2134. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  2135. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  2136. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  2137. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  2138. /*
  2139. * Window size needs to be incremented by 1
  2140. * since fw needs to represent a value of 256
  2141. * using just 8 bits
  2142. */
  2143. if (peer) {
  2144. status = dp_addba_requestprocess_wifi3(peer,
  2145. 0, tid, 0, win_sz + 1, 0xffff);
  2146. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2147. QDF_TRACE_LEVEL_INFO,
  2148. FL("PeerID %d BAW %d TID %d stat %d\n"),
  2149. peer_id, win_sz, tid, status);
  2150. } else {
  2151. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2152. QDF_TRACE_LEVEL_ERROR,
  2153. FL("Peer not found peer id %d\n"),
  2154. peer_id);
  2155. }
  2156. break;
  2157. }
  2158. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  2159. {
  2160. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  2161. break;
  2162. }
  2163. default:
  2164. break;
  2165. };
  2166. /* Free the indication buffer */
  2167. qdf_nbuf_free(htt_t2h_msg);
  2168. }
  2169. /*
  2170. * dp_htt_h2t_full() - Send full handler (called from HTC)
  2171. * @context: Opaque context (HTT SOC handle)
  2172. * @pkt: HTC packet
  2173. *
  2174. * Return: enum htc_send_full_action
  2175. */
  2176. static enum htc_send_full_action
  2177. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  2178. {
  2179. return HTC_SEND_FULL_KEEP;
  2180. }
  2181. /*
  2182. * dp_htt_hif_t2h_hp_callback() - HIF callback for high priority T2H messages
  2183. * @context: Opaque context (HTT SOC handle)
  2184. * @nbuf: nbuf containing T2H message
  2185. * @pipe_id: HIF pipe ID
  2186. *
  2187. * Return: QDF_STATUS
  2188. *
  2189. * TODO: Temporary change to bypass HTC connection for this new HIF pipe, which
  2190. * will be used for packet log and other high-priority HTT messsages. Proper
  2191. * HTC connection to be added later once required FW changes are available
  2192. */
  2193. static QDF_STATUS
  2194. dp_htt_hif_t2h_hp_callback (void *context, qdf_nbuf_t nbuf, uint8_t pipe_id)
  2195. {
  2196. A_STATUS rc = QDF_STATUS_SUCCESS;
  2197. HTC_PACKET htc_pkt;
  2198. qdf_assert_always(pipe_id == DP_HTT_T2H_HP_PIPE);
  2199. qdf_mem_zero(&htc_pkt, sizeof(htc_pkt));
  2200. htc_pkt.Status = QDF_STATUS_SUCCESS;
  2201. htc_pkt.pPktContext = (void *)nbuf;
  2202. dp_htt_t2h_msg_handler(context, &htc_pkt);
  2203. return rc;
  2204. }
  2205. /*
  2206. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  2207. * @htt_soc: HTT SOC handle
  2208. *
  2209. * Return: 0 on success; error code on failure
  2210. */
  2211. static int
  2212. htt_htc_soc_attach(struct htt_soc *soc)
  2213. {
  2214. struct htc_service_connect_req connect;
  2215. struct htc_service_connect_resp response;
  2216. A_STATUS status;
  2217. qdf_mem_set(&connect, sizeof(connect), 0);
  2218. qdf_mem_set(&response, sizeof(response), 0);
  2219. connect.pMetaData = NULL;
  2220. connect.MetaDataLength = 0;
  2221. connect.EpCallbacks.pContext = soc;
  2222. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  2223. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  2224. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  2225. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  2226. connect.EpCallbacks.EpRecvRefill = NULL;
  2227. /* N/A, fill is done by HIF */
  2228. connect.EpCallbacks.RecvRefillWaterMark = 1;
  2229. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  2230. /*
  2231. * Specify how deep to let a queue get before htc_send_pkt will
  2232. * call the EpSendFull function due to excessive send queue depth.
  2233. */
  2234. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  2235. /* disable flow control for HTT data message service */
  2236. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  2237. /* connect to control service */
  2238. connect.service_id = HTT_DATA_MSG_SVC;
  2239. status = htc_connect_service(soc->htc_soc, &connect, &response);
  2240. if (status != A_OK)
  2241. return QDF_STATUS_E_FAILURE;
  2242. soc->htc_endpoint = response.Endpoint;
  2243. dp_hif_update_pipe_callback(soc->dp_soc, (void *)soc,
  2244. dp_htt_hif_t2h_hp_callback, DP_HTT_T2H_HP_PIPE);
  2245. return 0; /* success */
  2246. }
  2247. /*
  2248. * htt_soc_attach() - SOC level HTT initialization
  2249. * @dp_soc: Opaque Data path SOC handle
  2250. * @osif_soc: Opaque OSIF SOC handle
  2251. * @htc_soc: SOC level HTC handle
  2252. * @hal_soc: Opaque HAL SOC handle
  2253. * @osdev: QDF device
  2254. *
  2255. * Return: HTT handle on success; NULL on failure
  2256. */
  2257. void *
  2258. htt_soc_attach(void *dp_soc, void *osif_soc, HTC_HANDLE htc_soc,
  2259. void *hal_soc, qdf_device_t osdev)
  2260. {
  2261. struct htt_soc *soc;
  2262. int i;
  2263. soc = qdf_mem_malloc(sizeof(*soc));
  2264. if (!soc)
  2265. goto fail1;
  2266. soc->osdev = osdev;
  2267. soc->osif_soc = osif_soc;
  2268. soc->dp_soc = dp_soc;
  2269. soc->htc_soc = htc_soc;
  2270. soc->hal_soc = hal_soc;
  2271. /* TODO: See if any NSS related context is requred in htt_soc */
  2272. soc->htt_htc_pkt_freelist = NULL;
  2273. if (htt_htc_soc_attach(soc))
  2274. goto fail2;
  2275. /* TODO: See if any Rx data specific intialization is required. For
  2276. * MCL use cases, the data will be received as single packet and
  2277. * should not required any descriptor or reorder handling
  2278. */
  2279. HTT_TX_MUTEX_INIT(&soc->htt_tx_mutex);
  2280. /* pre-allocate some HTC_PACKET objects */
  2281. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  2282. struct dp_htt_htc_pkt_union *pkt;
  2283. pkt = qdf_mem_malloc(sizeof(*pkt));
  2284. if (!pkt)
  2285. break;
  2286. htt_htc_pkt_free(soc, &pkt->u.pkt);
  2287. }
  2288. return soc;
  2289. fail2:
  2290. qdf_mem_free(soc);
  2291. fail1:
  2292. return NULL;
  2293. }
  2294. /*
  2295. * htt_soc_detach() - Detach SOC level HTT
  2296. * @htt_soc: HTT SOC handle
  2297. */
  2298. void
  2299. htt_soc_detach(void *htt_soc)
  2300. {
  2301. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  2302. htt_htc_misc_pkt_pool_free(soc);
  2303. htt_htc_pkt_pool_free(soc);
  2304. HTT_TX_MUTEX_DESTROY(&soc->htt_tx_mutex);
  2305. qdf_mem_free(soc);
  2306. }
  2307. /**
  2308. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  2309. * @pdev: DP PDEV handle
  2310. * @stats_type_upload_mask: stats type requested by user
  2311. * @config_param_0: extra configuration parameters
  2312. * @config_param_1: extra configuration parameters
  2313. * @config_param_2: extra configuration parameters
  2314. * @config_param_3: extra configuration parameters
  2315. *
  2316. * return: QDF STATUS
  2317. */
  2318. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  2319. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  2320. uint32_t config_param_1, uint32_t config_param_2,
  2321. uint32_t config_param_3, int cookie_val)
  2322. {
  2323. struct htt_soc *soc = pdev->soc->htt_handle;
  2324. struct dp_htt_htc_pkt *pkt;
  2325. qdf_nbuf_t msg;
  2326. uint32_t *msg_word;
  2327. uint8_t pdev_mask;
  2328. msg = qdf_nbuf_alloc(
  2329. soc->osdev,
  2330. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  2331. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  2332. if (!msg)
  2333. return QDF_STATUS_E_NOMEM;
  2334. /*TODO:Add support for SOC stats
  2335. * Bit 0: SOC Stats
  2336. * Bit 1: Pdev stats for pdev id 0
  2337. * Bit 2: Pdev stats for pdev id 1
  2338. * Bit 3: Pdev stats for pdev id 2
  2339. */
  2340. pdev_mask = 1 << (pdev->pdev_id + 1);
  2341. /*
  2342. * Set the length of the message.
  2343. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2344. * separately during the below call to qdf_nbuf_push_head.
  2345. * The contribution from the HTC header is added separately inside HTC.
  2346. */
  2347. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  2348. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2349. "Failed to expand head for HTT_EXT_STATS");
  2350. qdf_nbuf_free(msg);
  2351. return QDF_STATUS_E_FAILURE;
  2352. }
  2353. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2354. "-----%s:%d----\n cookie <-> %d\n config_param_0 %u\n"
  2355. "config_param_1 %u\n config_param_2 %u\n"
  2356. "config_param_4 %u\n -------------\n",
  2357. __func__, __LINE__, cookie_val, config_param_0,
  2358. config_param_1, config_param_2, config_param_3);
  2359. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2360. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2361. *msg_word = 0;
  2362. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  2363. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  2364. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  2365. /* word 1 */
  2366. msg_word++;
  2367. *msg_word = 0;
  2368. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  2369. /* word 2 */
  2370. msg_word++;
  2371. *msg_word = 0;
  2372. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  2373. /* word 3 */
  2374. msg_word++;
  2375. *msg_word = 0;
  2376. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  2377. /* word 4 */
  2378. msg_word++;
  2379. *msg_word = 0;
  2380. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  2381. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  2382. /* word 5 */
  2383. msg_word++;
  2384. /* word 6 */
  2385. msg_word++;
  2386. *msg_word = 0;
  2387. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, cookie_val);
  2388. /* word 7 */
  2389. msg_word++;
  2390. *msg_word = 0;
  2391. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, pdev->pdev_id);
  2392. pkt = htt_htc_pkt_alloc(soc);
  2393. if (!pkt) {
  2394. qdf_nbuf_free(msg);
  2395. return QDF_STATUS_E_NOMEM;
  2396. }
  2397. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2398. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2399. dp_htt_h2t_send_complete_free_netbuf,
  2400. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2401. soc->htc_endpoint,
  2402. 1); /* tag - not relevant here */
  2403. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2404. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2405. return 0;
  2406. }
  2407. /* This macro will revert once proper HTT header will define for
  2408. * HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in htt.h file
  2409. * */
  2410. #if defined(WDI_EVENT_ENABLE)
  2411. /**
  2412. * dp_h2t_cfg_stats_msg_send(): function to construct HTT message to pass to FW
  2413. * @pdev: DP PDEV handle
  2414. * @stats_type_upload_mask: stats type requested by user
  2415. * @mac_id: Mac id number
  2416. *
  2417. * return: QDF STATUS
  2418. */
  2419. QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
  2420. uint32_t stats_type_upload_mask, uint8_t mac_id)
  2421. {
  2422. struct htt_soc *soc = pdev->soc->htt_handle;
  2423. struct dp_htt_htc_pkt *pkt;
  2424. qdf_nbuf_t msg;
  2425. uint32_t *msg_word;
  2426. uint8_t pdev_mask;
  2427. msg = qdf_nbuf_alloc(
  2428. soc->osdev,
  2429. HTT_MSG_BUF_SIZE(HTT_H2T_PPDU_STATS_CFG_MSG_SZ),
  2430. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, true);
  2431. if (!msg) {
  2432. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2433. "Fail to allocate HTT_H2T_PPDU_STATS_CFG_MSG_SZ msg buffer\n");
  2434. qdf_assert(0);
  2435. return QDF_STATUS_E_NOMEM;
  2436. }
  2437. /*TODO:Add support for SOC stats
  2438. * Bit 0: SOC Stats
  2439. * Bit 1: Pdev stats for pdev id 0
  2440. * Bit 2: Pdev stats for pdev id 1
  2441. * Bit 3: Pdev stats for pdev id 2
  2442. */
  2443. pdev_mask = 1 << DP_SW2HW_MACID(mac_id);
  2444. /*
  2445. * Set the length of the message.
  2446. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2447. * separately during the below call to qdf_nbuf_push_head.
  2448. * The contribution from the HTC header is added separately inside HTC.
  2449. */
  2450. if (qdf_nbuf_put_tail(msg, HTT_H2T_PPDU_STATS_CFG_MSG_SZ) == NULL) {
  2451. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2452. "Failed to expand head for HTT_CFG_STATS\n");
  2453. qdf_nbuf_free(msg);
  2454. return QDF_STATUS_E_FAILURE;
  2455. }
  2456. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2457. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2458. *msg_word = 0;
  2459. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG);
  2460. HTT_H2T_PPDU_STATS_CFG_PDEV_MASK_SET(*msg_word, pdev_mask);
  2461. HTT_H2T_PPDU_STATS_CFG_TLV_BITMASK_SET(*msg_word,
  2462. stats_type_upload_mask);
  2463. pkt = htt_htc_pkt_alloc(soc);
  2464. if (!pkt) {
  2465. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2466. "Fail to allocate dp_htt_htc_pkt buffer\n");
  2467. qdf_assert(0);
  2468. qdf_nbuf_free(msg);
  2469. return QDF_STATUS_E_NOMEM;
  2470. }
  2471. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2472. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2473. dp_htt_h2t_send_complete_free_netbuf,
  2474. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2475. soc->htc_endpoint,
  2476. 1); /* tag - not relevant here */
  2477. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2478. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2479. return 0;
  2480. }
  2481. #endif