dp_htt.c 71 KB

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