dp_htt.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044
  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. 1); /* tag - not relevant here */
  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. HTT_RX_RING_SELECTION_CFG_TLV_FILTER_IN_FLAG_SET(*msg_word, tlv_filter);
  951. /* "response_required" field should be set if a HTT response message is
  952. * required after setting up the ring.
  953. */
  954. pkt = htt_htc_pkt_alloc(soc);
  955. if (!pkt)
  956. goto fail1;
  957. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  958. SET_HTC_PACKET_INFO_TX(
  959. &pkt->htc_pkt,
  960. dp_htt_h2t_send_complete_free_netbuf,
  961. qdf_nbuf_data(htt_msg),
  962. qdf_nbuf_len(htt_msg),
  963. soc->htc_endpoint,
  964. 1); /* tag - not relevant here */
  965. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  966. DP_HTT_SEND_HTC_PKT(soc, pkt);
  967. return QDF_STATUS_SUCCESS;
  968. fail1:
  969. qdf_nbuf_free(htt_msg);
  970. fail0:
  971. return QDF_STATUS_E_FAILURE;
  972. }
  973. /**
  974. * dp_process_htt_stat_msg(): Process the list of buffers of HTT EXT stats
  975. * @htt_stats: htt stats info
  976. *
  977. * The FW sends the HTT EXT STATS as a stream of T2H messages. Each T2H message
  978. * contains sub messages which are identified by a TLV header.
  979. * In this function we will process the stream of T2H messages and read all the
  980. * TLV contained in the message.
  981. *
  982. * THe following cases have been taken care of
  983. * Case 1: When the tlv_remain_length <= msg_remain_length of HTT MSG buffer
  984. * In this case the buffer will contain multiple tlvs.
  985. * Case 2: When the tlv_remain_length > msg_remain_length of HTT MSG buffer.
  986. * Only one tlv will be contained in the HTT message and this tag
  987. * will extend onto the next buffer.
  988. * Case 3: When the buffer is the continuation of the previous message
  989. * Case 4: tlv length is 0. which will indicate the end of message
  990. *
  991. * return: void
  992. */
  993. static inline void dp_process_htt_stat_msg(struct htt_stats_context *htt_stats)
  994. {
  995. htt_tlv_tag_t tlv_type = 0xff;
  996. qdf_nbuf_t htt_msg = NULL;
  997. uint32_t *msg_word;
  998. uint8_t *tlv_buf_head = NULL;
  999. uint8_t *tlv_buf_tail = NULL;
  1000. uint32_t msg_remain_len = 0;
  1001. uint32_t tlv_remain_len = 0;
  1002. uint32_t *tlv_start;
  1003. /* Process node in the HTT message queue */
  1004. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1005. != NULL) {
  1006. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1007. /* read 5th word */
  1008. msg_word = msg_word + 4;
  1009. msg_remain_len = qdf_min(htt_stats->msg_len,
  1010. (uint32_t) DP_EXT_MSG_LENGTH);
  1011. /* Keep processing the node till node length is 0 */
  1012. while (msg_remain_len) {
  1013. /*
  1014. * if message is not a continuation of previous message
  1015. * read the tlv type and tlv length
  1016. */
  1017. if (!tlv_buf_head) {
  1018. tlv_type = HTT_STATS_TLV_TAG_GET(
  1019. *msg_word);
  1020. tlv_remain_len = HTT_STATS_TLV_LENGTH_GET(
  1021. *msg_word);
  1022. }
  1023. if (tlv_remain_len == 0) {
  1024. msg_remain_len = 0;
  1025. if (tlv_buf_head) {
  1026. qdf_mem_free(tlv_buf_head);
  1027. tlv_buf_head = NULL;
  1028. tlv_buf_tail = NULL;
  1029. }
  1030. goto error;
  1031. }
  1032. tlv_remain_len += HTT_TLV_HDR_LEN;
  1033. if ((tlv_remain_len <= msg_remain_len)) {
  1034. /* Case 3 */
  1035. if (tlv_buf_head) {
  1036. qdf_mem_copy(tlv_buf_tail,
  1037. (uint8_t *)msg_word,
  1038. tlv_remain_len);
  1039. tlv_start = (uint32_t *)tlv_buf_head;
  1040. } else {
  1041. /* Case 1 */
  1042. tlv_start = msg_word;
  1043. }
  1044. dp_htt_stats_print_tag(tlv_type, tlv_start);
  1045. msg_remain_len -= tlv_remain_len;
  1046. msg_word = (uint32_t *)
  1047. (((uint8_t *)msg_word) +
  1048. tlv_remain_len);
  1049. tlv_remain_len = 0;
  1050. if (tlv_buf_head) {
  1051. qdf_mem_free(tlv_buf_head);
  1052. tlv_buf_head = NULL;
  1053. tlv_buf_tail = NULL;
  1054. }
  1055. } else { /* tlv_remain_len > msg_remain_len */
  1056. /* Case 2 & 3 */
  1057. if (!tlv_buf_head) {
  1058. tlv_buf_head = qdf_mem_malloc(
  1059. tlv_remain_len);
  1060. if (!tlv_buf_head) {
  1061. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1062. QDF_TRACE_LEVEL_ERROR,
  1063. "Alloc failed");
  1064. goto error;
  1065. }
  1066. tlv_buf_tail = tlv_buf_head;
  1067. }
  1068. qdf_mem_copy(tlv_buf_tail, (uint8_t *)msg_word,
  1069. msg_remain_len);
  1070. tlv_remain_len -= msg_remain_len;
  1071. tlv_buf_tail += msg_remain_len;
  1072. msg_remain_len = 0;
  1073. }
  1074. }
  1075. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1076. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1077. }
  1078. qdf_nbuf_free(htt_msg);
  1079. }
  1080. return;
  1081. error:
  1082. qdf_nbuf_free(htt_msg);
  1083. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1084. != NULL)
  1085. qdf_nbuf_free(htt_msg);
  1086. }
  1087. void htt_t2h_stats_handler(void *context)
  1088. {
  1089. struct dp_soc *soc = (struct dp_soc *)context;
  1090. struct htt_stats_context htt_stats;
  1091. uint32_t length;
  1092. uint32_t *msg_word;
  1093. qdf_nbuf_t htt_msg = NULL;
  1094. uint8_t done;
  1095. uint8_t rem_stats;
  1096. if (!soc || !qdf_atomic_read(&soc->cmn_init_done)) {
  1097. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1098. "soc: 0x%p, init_done: %d", soc,
  1099. qdf_atomic_read(&soc->cmn_init_done));
  1100. return;
  1101. }
  1102. qdf_mem_zero(&htt_stats, sizeof(htt_stats));
  1103. qdf_nbuf_queue_init(&htt_stats.msg);
  1104. /* pull one completed stats from soc->htt_stats_msg and process */
  1105. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1106. if (!soc->htt_stats.num_stats) {
  1107. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1108. return;
  1109. }
  1110. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats.msg)) != NULL) {
  1111. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1112. msg_word = msg_word + HTT_T2H_EXT_STATS_TLV_START_OFFSET;
  1113. length = HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_GET(*msg_word);
  1114. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1115. qdf_nbuf_queue_add(&htt_stats.msg, htt_msg);
  1116. /*
  1117. * HTT EXT stats response comes as stream of TLVs which span over
  1118. * multiple T2H messages.
  1119. * The first message will carry length of the response.
  1120. * For rest of the messages length will be zero.
  1121. */
  1122. if (length)
  1123. htt_stats.msg_len = length;
  1124. /*
  1125. * Done bit signifies that this is the last T2H buffer in the
  1126. * stream of HTT EXT STATS message
  1127. */
  1128. if (done)
  1129. break;
  1130. }
  1131. rem_stats = --soc->htt_stats.num_stats;
  1132. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1133. dp_process_htt_stat_msg(&htt_stats);
  1134. /* If there are more stats to process, schedule stats work again */
  1135. if (rem_stats)
  1136. qdf_sched_work(0, &soc->htt_stats.work);
  1137. }
  1138. /**
  1139. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  1140. * @pdev: DP pdev handle
  1141. * @tag_buf: T2H message buffer carrying the user rate TLV
  1142. *
  1143. * return:void
  1144. */
  1145. static void dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  1146. uint32_t *tag_buf)
  1147. {
  1148. uint32_t peer_id;
  1149. struct dp_peer *peer;
  1150. struct cdp_tx_completion_ppdu *ppdu_desc;
  1151. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1152. ppdu_desc =
  1153. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1154. tag_buf++;
  1155. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1156. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1157. if (!peer)
  1158. return;
  1159. ppdu_user_desc = &ppdu_desc->user[pdev->tx_ppdu_info.curr_user];
  1160. ppdu_user_desc->tid =
  1161. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  1162. ppdu_user_desc->peer_id = peer_id;
  1163. qdf_mem_copy(ppdu_user_desc->mac_addr, peer->mac_addr.raw,
  1164. DP_MAC_ADDR_LEN);
  1165. tag_buf += 5;
  1166. ppdu_user_desc->ltf_size =
  1167. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  1168. ppdu_user_desc->stbc =
  1169. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  1170. ppdu_user_desc->he_re =
  1171. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  1172. ppdu_user_desc->txbf =
  1173. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  1174. ppdu_user_desc->bw =
  1175. HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf);
  1176. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  1177. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  1178. ppdu_user_desc->preamble =
  1179. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  1180. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  1181. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  1182. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  1183. ppdu_user_desc->ppdu_type =
  1184. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  1185. }
  1186. /**
  1187. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  1188. * @soc: DP Physical device (radio) handle
  1189. * @tag_buf: TLV buffer
  1190. *
  1191. * return: void
  1192. */
  1193. static void dp_process_ppdu_tag(struct dp_pdev *pdev, uint32_t *tag_buf,
  1194. uint32_t tlv_len)
  1195. {
  1196. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  1197. switch (tlv_type) {
  1198. case HTT_PPDU_STATS_USR_RATE_TLV:
  1199. qdf_assert_always(tlv_len ==
  1200. sizeof(htt_ppdu_stats_user_rate_tlv));
  1201. dp_process_ppdu_stats_user_rate_tlv(pdev, tag_buf);
  1202. break;
  1203. default:
  1204. break;
  1205. }
  1206. }
  1207. static QDF_STATUS dp_htt_process_tlv(struct dp_pdev *pdev,
  1208. qdf_nbuf_t htt_t2h_msg)
  1209. {
  1210. uint32_t length;
  1211. uint32_t ppdu_id;
  1212. uint8_t tlv_type;
  1213. uint32_t tlv_length;
  1214. uint8_t *tlv_buf;
  1215. QDF_STATUS status = QDF_STATUS_E_PENDING;
  1216. uint32_t *msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1217. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  1218. msg_word = msg_word + 1;
  1219. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  1220. msg_word = msg_word + 3;
  1221. while (length > 0) {
  1222. tlv_buf = (uint8_t *)msg_word;
  1223. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  1224. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  1225. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1226. "HTT PPDU Tag %d, Length %d", tlv_type,
  1227. tlv_length);
  1228. if (tlv_length == 0)
  1229. break;
  1230. if (tlv_type == HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)
  1231. status = QDF_STATUS_SUCCESS;
  1232. tlv_length += HTT_TLV_HDR_LEN;
  1233. dp_process_ppdu_tag(pdev, msg_word, tlv_length);
  1234. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  1235. length -= (tlv_length);
  1236. }
  1237. return status;
  1238. }
  1239. /**
  1240. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  1241. * @soc: DP SOC handle
  1242. * @pdev_id: pdev id
  1243. * @htt_t2h_msg: HTT message nbuf
  1244. *
  1245. * return:void
  1246. */
  1247. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1248. #ifdef FEATURE_PERPKT_INFO
  1249. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1250. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1251. {
  1252. struct dp_pdev *pdev = soc->pdev_list[pdev_id];
  1253. struct dp_vdev *vdev;
  1254. struct dp_peer *peer;
  1255. struct cdp_tx_completion_ppdu *ppdu_desc;
  1256. int status;
  1257. int i;
  1258. if (!pdev->enhanced_stats_en)
  1259. return;
  1260. if (!pdev->tx_ppdu_info.buf) {
  1261. /*
  1262. * Todo: For MU/OFDMA, we need to account for multiple user
  1263. * descriptors in a PPDU, in skb size.
  1264. * The allocation has to be moved to ppdu_cmn tlv processing
  1265. */
  1266. pdev->tx_ppdu_info.buf = qdf_nbuf_alloc(soc->osdev,
  1267. sizeof(struct cdp_tx_completion_ppdu), 0, 4,
  1268. TRUE);
  1269. if (!pdev->tx_ppdu_info.buf) {
  1270. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1271. "Nbuf Allocation failed for HTT PPDU");
  1272. return;
  1273. }
  1274. if (qdf_nbuf_put_tail(pdev->tx_ppdu_info.buf,
  1275. sizeof(struct cdp_tx_completion_ppdu)) == NULL) {
  1276. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1277. "No tailroom for HTT PPDU");
  1278. return;
  1279. }
  1280. }
  1281. status = dp_htt_process_tlv(pdev, htt_t2h_msg);
  1282. if (status == QDF_STATUS_SUCCESS) {
  1283. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  1284. qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1285. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  1286. ppdu_desc->vdev_id);
  1287. for (i = 0; i < ppdu_desc->num_users; i++) {
  1288. peer = dp_peer_find_by_id(soc,
  1289. ppdu_desc->user[i].peer_id);
  1290. dp_tx_stats_update(soc, peer, &ppdu_desc->user[i],
  1291. ppdu_desc->ack_rssi);
  1292. }
  1293. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC, soc,
  1294. pdev->tx_ppdu_info.buf, HTT_INVALID_PEER,
  1295. WDI_NO_VAL, pdev_id);
  1296. pdev->tx_ppdu_info.buf = NULL;
  1297. pdev->tx_ppdu_info.curr_user = 0;
  1298. }
  1299. }
  1300. #else
  1301. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1302. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1303. {
  1304. }
  1305. #endif
  1306. #endif
  1307. /**
  1308. * dp_txrx_fw_stats_handler() - Function to process HTT EXT stats
  1309. * @soc: DP SOC handle
  1310. * @htt_t2h_msg: HTT message nbuf
  1311. *
  1312. * return:void
  1313. */
  1314. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  1315. qdf_nbuf_t htt_t2h_msg)
  1316. {
  1317. uint8_t done;
  1318. qdf_nbuf_t msg_copy;
  1319. uint32_t *msg_word;
  1320. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1321. msg_word = msg_word + 3;
  1322. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1323. /*
  1324. * HTT EXT stats response comes as stream of TLVs which span over
  1325. * multiple T2H messages.
  1326. * The first message will carry length of the response.
  1327. * For rest of the messages length will be zero.
  1328. *
  1329. * Clone the T2H message buffer and store it in a list to process
  1330. * it later.
  1331. *
  1332. * The original T2H message buffers gets freed in the T2H HTT event
  1333. * handler
  1334. */
  1335. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  1336. if (!msg_copy) {
  1337. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1338. "T2H messge clone failed for HTT EXT STATS");
  1339. goto error;
  1340. }
  1341. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1342. qdf_nbuf_queue_add(&soc->htt_stats.msg, msg_copy);
  1343. /*
  1344. * Done bit signifies that this is the last T2H buffer in the stream of
  1345. * HTT EXT STATS message
  1346. */
  1347. if (done) {
  1348. soc->htt_stats.num_stats++;
  1349. qdf_sched_work(0, &soc->htt_stats.work);
  1350. }
  1351. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1352. return;
  1353. error:
  1354. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1355. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats.msg))
  1356. != NULL) {
  1357. qdf_nbuf_free(msg_copy);
  1358. }
  1359. soc->htt_stats.num_stats = 0;
  1360. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1361. return;
  1362. }
  1363. /*
  1364. * htt_soc_attach_target() - SOC level HTT setup
  1365. * @htt_soc: HTT SOC handle
  1366. *
  1367. * Return: 0 on success; error code on failure
  1368. */
  1369. int htt_soc_attach_target(void *htt_soc)
  1370. {
  1371. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1372. return htt_h2t_ver_req_msg(soc);
  1373. }
  1374. /*
  1375. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  1376. * @context: Opaque context (HTT SOC handle)
  1377. * @pkt: HTC packet
  1378. */
  1379. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  1380. {
  1381. struct htt_soc *soc = (struct htt_soc *) context;
  1382. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  1383. u_int32_t *msg_word;
  1384. enum htt_t2h_msg_type msg_type;
  1385. /* check for successful message reception */
  1386. if (pkt->Status != QDF_STATUS_SUCCESS) {
  1387. if (pkt->Status != QDF_STATUS_E_CANCELED)
  1388. soc->stats.htc_err_cnt++;
  1389. qdf_nbuf_free(htt_t2h_msg);
  1390. return;
  1391. }
  1392. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  1393. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  1394. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  1395. switch (msg_type) {
  1396. case HTT_T2H_MSG_TYPE_PEER_MAP:
  1397. {
  1398. u_int8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
  1399. u_int8_t *peer_mac_addr;
  1400. u_int16_t peer_id;
  1401. u_int16_t hw_peer_id;
  1402. u_int8_t vdev_id;
  1403. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  1404. hw_peer_id =
  1405. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  1406. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  1407. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  1408. (u_int8_t *) (msg_word+1),
  1409. &mac_addr_deswizzle_buf[0]);
  1410. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1411. QDF_TRACE_LEVEL_INFO,
  1412. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  1413. peer_id, vdev_id);
  1414. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  1415. vdev_id, peer_mac_addr);
  1416. break;
  1417. }
  1418. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  1419. {
  1420. u_int16_t peer_id;
  1421. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  1422. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id);
  1423. break;
  1424. }
  1425. case HTT_T2H_MSG_TYPE_SEC_IND:
  1426. {
  1427. u_int16_t peer_id;
  1428. enum htt_sec_type sec_type;
  1429. int is_unicast;
  1430. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  1431. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  1432. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  1433. /* point to the first part of the Michael key */
  1434. msg_word++;
  1435. dp_rx_sec_ind_handler(
  1436. soc->dp_soc, peer_id, sec_type, is_unicast,
  1437. msg_word, msg_word + 2);
  1438. break;
  1439. }
  1440. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1441. #ifndef REMOVE_PKT_LOG
  1442. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  1443. {
  1444. u_int8_t pdev_id;
  1445. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  1446. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1447. "received HTT_T2H_MSG_TYPE_PPDU_STATS_IND\n");
  1448. pdev_id = HTT_T2H_PPDU_STATS_MAC_ID_GET(*msg_word);
  1449. pdev_id = DP_HW2SW_MACID(pdev_id);
  1450. dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  1451. htt_t2h_msg);
  1452. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  1453. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  1454. pdev_id);
  1455. break;
  1456. }
  1457. #endif
  1458. #endif
  1459. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  1460. {
  1461. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  1462. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  1463. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1464. "target uses HTT version %d.%d; host uses %d.%d\n",
  1465. soc->tgt_ver.major, soc->tgt_ver.minor,
  1466. HTT_CURRENT_VERSION_MAJOR,
  1467. HTT_CURRENT_VERSION_MINOR);
  1468. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  1469. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1470. QDF_TRACE_LEVEL_ERROR,
  1471. "*** Incompatible host/target HTT versions!\n");
  1472. }
  1473. /* abort if the target is incompatible with the host */
  1474. qdf_assert(soc->tgt_ver.major ==
  1475. HTT_CURRENT_VERSION_MAJOR);
  1476. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  1477. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1478. QDF_TRACE_LEVEL_WARN,
  1479. "*** Warning: host/target HTT versions"
  1480. " are different, though compatible!\n");
  1481. }
  1482. break;
  1483. }
  1484. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  1485. {
  1486. uint16_t peer_id;
  1487. uint8_t tid;
  1488. uint8_t win_sz;
  1489. uint16_t status;
  1490. struct dp_peer *peer;
  1491. /*
  1492. * Update REO Queue Desc with new values
  1493. */
  1494. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  1495. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  1496. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  1497. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  1498. /*
  1499. * Window size needs to be incremented by 1
  1500. * since fw needs to represent a value of 256
  1501. * using just 8 bits
  1502. */
  1503. if (peer) {
  1504. status = dp_addba_requestprocess_wifi3(peer,
  1505. 0, tid, 0, win_sz + 1, 0xffff);
  1506. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1507. QDF_TRACE_LEVEL_INFO,
  1508. FL("PeerID %d BAW %d TID %d stat %d\n"),
  1509. peer_id, win_sz, tid, status);
  1510. } else {
  1511. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1512. QDF_TRACE_LEVEL_ERROR,
  1513. FL("Peer not found peer id %d\n"),
  1514. peer_id);
  1515. }
  1516. break;
  1517. }
  1518. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  1519. {
  1520. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  1521. break;
  1522. }
  1523. default:
  1524. break;
  1525. };
  1526. /* Free the indication buffer */
  1527. qdf_nbuf_free(htt_t2h_msg);
  1528. }
  1529. /*
  1530. * dp_htt_h2t_full() - Send full handler (called from HTC)
  1531. * @context: Opaque context (HTT SOC handle)
  1532. * @pkt: HTC packet
  1533. *
  1534. * Return: enum htc_send_full_action
  1535. */
  1536. static enum htc_send_full_action
  1537. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  1538. {
  1539. return HTC_SEND_FULL_KEEP;
  1540. }
  1541. /*
  1542. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  1543. * @htt_soc: HTT SOC handle
  1544. *
  1545. * Return: 0 on success; error code on failure
  1546. */
  1547. static int
  1548. htt_htc_soc_attach(struct htt_soc *soc)
  1549. {
  1550. struct htc_service_connect_req connect;
  1551. struct htc_service_connect_resp response;
  1552. A_STATUS status;
  1553. qdf_mem_set(&connect, sizeof(connect), 0);
  1554. qdf_mem_set(&response, sizeof(response), 0);
  1555. connect.pMetaData = NULL;
  1556. connect.MetaDataLength = 0;
  1557. connect.EpCallbacks.pContext = soc;
  1558. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  1559. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  1560. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  1561. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  1562. connect.EpCallbacks.EpRecvRefill = NULL;
  1563. /* N/A, fill is done by HIF */
  1564. connect.EpCallbacks.RecvRefillWaterMark = 1;
  1565. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  1566. /*
  1567. * Specify how deep to let a queue get before htc_send_pkt will
  1568. * call the EpSendFull function due to excessive send queue depth.
  1569. */
  1570. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  1571. /* disable flow control for HTT data message service */
  1572. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  1573. /* connect to control service */
  1574. connect.service_id = HTT_DATA_MSG_SVC;
  1575. status = htc_connect_service(soc->htc_soc, &connect, &response);
  1576. if (status != A_OK)
  1577. return QDF_STATUS_E_FAILURE;
  1578. soc->htc_endpoint = response.Endpoint;
  1579. return 0; /* success */
  1580. }
  1581. /*
  1582. * htt_soc_attach() - SOC level HTT initialization
  1583. * @dp_soc: Opaque Data path SOC handle
  1584. * @osif_soc: Opaque OSIF SOC handle
  1585. * @htc_soc: SOC level HTC handle
  1586. * @hal_soc: Opaque HAL SOC handle
  1587. * @osdev: QDF device
  1588. *
  1589. * Return: HTT handle on success; NULL on failure
  1590. */
  1591. void *
  1592. htt_soc_attach(void *dp_soc, void *osif_soc, HTC_HANDLE htc_soc,
  1593. void *hal_soc, qdf_device_t osdev)
  1594. {
  1595. struct htt_soc *soc;
  1596. int i;
  1597. soc = qdf_mem_malloc(sizeof(*soc));
  1598. if (!soc)
  1599. goto fail1;
  1600. soc->osdev = osdev;
  1601. soc->osif_soc = osif_soc;
  1602. soc->dp_soc = dp_soc;
  1603. soc->htc_soc = htc_soc;
  1604. soc->hal_soc = hal_soc;
  1605. /* TODO: See if any NSS related context is requred in htt_soc */
  1606. soc->htt_htc_pkt_freelist = NULL;
  1607. if (htt_htc_soc_attach(soc))
  1608. goto fail2;
  1609. /* TODO: See if any Rx data specific intialization is required. For
  1610. * MCL use cases, the data will be received as single packet and
  1611. * should not required any descriptor or reorder handling
  1612. */
  1613. HTT_TX_MUTEX_INIT(&soc->htt_tx_mutex);
  1614. /* pre-allocate some HTC_PACKET objects */
  1615. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  1616. struct dp_htt_htc_pkt_union *pkt;
  1617. pkt = qdf_mem_malloc(sizeof(*pkt));
  1618. if (!pkt)
  1619. break;
  1620. htt_htc_pkt_free(soc, &pkt->u.pkt);
  1621. }
  1622. return soc;
  1623. fail2:
  1624. qdf_mem_free(soc);
  1625. fail1:
  1626. return NULL;
  1627. }
  1628. /*
  1629. * htt_soc_detach() - Detach SOC level HTT
  1630. * @htt_soc: HTT SOC handle
  1631. */
  1632. void
  1633. htt_soc_detach(void *htt_soc)
  1634. {
  1635. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1636. htt_htc_misc_pkt_pool_free(soc);
  1637. htt_htc_pkt_pool_free(soc);
  1638. HTT_TX_MUTEX_DESTROY(&soc->htt_tx_mutex);
  1639. qdf_mem_free(soc);
  1640. }
  1641. /**
  1642. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  1643. * @pdev: DP PDEV handle
  1644. * @stats_type_upload_mask: stats type requested by user
  1645. * @config_param_0: extra configuration parameters
  1646. * @config_param_1: extra configuration parameters
  1647. * @config_param_2: extra configuration parameters
  1648. * @config_param_3: extra configuration parameters
  1649. *
  1650. * return: QDF STATUS
  1651. */
  1652. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  1653. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  1654. uint32_t config_param_1, uint32_t config_param_2,
  1655. uint32_t config_param_3)
  1656. {
  1657. struct htt_soc *soc = pdev->soc->htt_handle;
  1658. struct dp_htt_htc_pkt *pkt;
  1659. qdf_nbuf_t msg;
  1660. uint32_t *msg_word;
  1661. uint8_t pdev_mask;
  1662. msg = qdf_nbuf_alloc(
  1663. soc->osdev,
  1664. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  1665. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  1666. if (!msg)
  1667. return QDF_STATUS_E_NOMEM;
  1668. /*TODO:Add support for SOC stats
  1669. * Bit 0: SOC Stats
  1670. * Bit 1: Pdev stats for pdev id 0
  1671. * Bit 2: Pdev stats for pdev id 1
  1672. * Bit 3: Pdev stats for pdev id 2
  1673. */
  1674. pdev_mask = 1 << (pdev->pdev_id + 1);
  1675. /*
  1676. * Set the length of the message.
  1677. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  1678. * separately during the below call to qdf_nbuf_push_head.
  1679. * The contribution from the HTC header is added separately inside HTC.
  1680. */
  1681. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  1682. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1683. "Failed to expand head for HTT_EXT_STATS");
  1684. qdf_nbuf_free(msg);
  1685. return QDF_STATUS_E_FAILURE;
  1686. }
  1687. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  1688. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  1689. *msg_word = 0;
  1690. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  1691. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  1692. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  1693. /* word 1 */
  1694. msg_word++;
  1695. *msg_word = 0;
  1696. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  1697. /* word 2 */
  1698. msg_word++;
  1699. *msg_word = 0;
  1700. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  1701. /* word 3 */
  1702. msg_word++;
  1703. *msg_word = 0;
  1704. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  1705. /* word 4 */
  1706. msg_word++;
  1707. *msg_word = 0;
  1708. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  1709. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  1710. pkt = htt_htc_pkt_alloc(soc);
  1711. if (!pkt) {
  1712. qdf_nbuf_free(msg);
  1713. return QDF_STATUS_E_NOMEM;
  1714. }
  1715. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  1716. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  1717. dp_htt_h2t_send_complete_free_netbuf,
  1718. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  1719. soc->htc_endpoint,
  1720. 1); /* tag - not relevant here */
  1721. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  1722. DP_HTT_SEND_HTC_PKT(soc, pkt);
  1723. return 0;
  1724. }
  1725. /* This macro will revert once proper HTT header will define for
  1726. * HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in htt.h file
  1727. * */
  1728. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1729. /**
  1730. * dp_h2t_cfg_stats_msg_send(): function to construct HTT message to pass to FW
  1731. * @pdev: DP PDEV handle
  1732. * @stats_type_upload_mask: stats type requested by user
  1733. *
  1734. * return: QDF STATUS
  1735. */
  1736. QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
  1737. uint32_t stats_type_upload_mask)
  1738. {
  1739. struct htt_soc *soc = pdev->soc->htt_handle;
  1740. struct dp_htt_htc_pkt *pkt;
  1741. qdf_nbuf_t msg;
  1742. uint32_t *msg_word;
  1743. uint8_t pdev_mask;
  1744. msg = qdf_nbuf_alloc(
  1745. soc->osdev,
  1746. HTT_MSG_BUF_SIZE(HTT_H2T_PPDU_STATS_CFG_MSG_SZ),
  1747. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, true);
  1748. if (!msg) {
  1749. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1750. "Fail to allocate HTT_H2T_PPDU_STATS_CFG_MSG_SZ msg buffer\n");
  1751. qdf_assert(0);
  1752. return QDF_STATUS_E_NOMEM;
  1753. }
  1754. /*TODO:Add support for SOC stats
  1755. * Bit 0: SOC Stats
  1756. * Bit 1: Pdev stats for pdev id 0
  1757. * Bit 2: Pdev stats for pdev id 1
  1758. * Bit 3: Pdev stats for pdev id 2
  1759. */
  1760. pdev_mask = 1 << DP_SW2HW_MACID(pdev->pdev_id);
  1761. /*
  1762. * Set the length of the message.
  1763. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  1764. * separately during the below call to qdf_nbuf_push_head.
  1765. * The contribution from the HTC header is added separately inside HTC.
  1766. */
  1767. if (qdf_nbuf_put_tail(msg, HTT_H2T_PPDU_STATS_CFG_MSG_SZ) == NULL) {
  1768. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1769. "Failed to expand head for HTT_CFG_STATS\n");
  1770. qdf_nbuf_free(msg);
  1771. return QDF_STATUS_E_FAILURE;
  1772. }
  1773. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  1774. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  1775. *msg_word = 0;
  1776. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG);
  1777. HTT_H2T_PPDU_STATS_CFG_PDEV_MASK_SET(*msg_word, pdev_mask);
  1778. HTT_H2T_PPDU_STATS_CFG_TLV_BITMASK_SET(*msg_word,
  1779. stats_type_upload_mask);
  1780. pkt = htt_htc_pkt_alloc(soc);
  1781. if (!pkt) {
  1782. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1783. "Fail to allocate dp_htt_htc_pkt buffer\n");
  1784. qdf_assert(0);
  1785. qdf_nbuf_free(msg);
  1786. return QDF_STATUS_E_NOMEM;
  1787. }
  1788. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  1789. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  1790. dp_htt_h2t_send_complete_free_netbuf,
  1791. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  1792. soc->htc_endpoint,
  1793. 1); /* tag - not relevant here */
  1794. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  1795. DP_HTT_SEND_HTC_PKT(soc, pkt);
  1796. return 0;
  1797. }
  1798. #endif