dp_rx_mon_status.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972
  1. /*
  2. * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "hal_hw_headers.h"
  19. #include "dp_types.h"
  20. #include "dp_rx.h"
  21. #include "dp_peer.h"
  22. #include "hal_rx.h"
  23. #include "hal_api.h"
  24. #include "qdf_trace.h"
  25. #include "qdf_nbuf.h"
  26. #include "hal_api_mon.h"
  27. #include "dp_rx_mon.h"
  28. #include "dp_internal.h"
  29. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  30. #include "htt.h"
  31. #ifdef FEATURE_PERPKT_INFO
  32. #include "dp_ratetable.h"
  33. #endif
  34. static inline void
  35. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  36. struct hal_rx_ppdu_info *ppdu_info,
  37. qdf_nbuf_t ppdu_nbuf);
  38. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  39. #include "dp_rx_mon_feature.h"
  40. #else
  41. static QDF_STATUS
  42. dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  43. struct hal_rx_ppdu_info *ppdu_info)
  44. {
  45. return QDF_STATUS_SUCCESS;
  46. }
  47. static void
  48. dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
  49. qdf_nbuf_t status_nbuf,
  50. struct hal_rx_ppdu_info *ppdu_info,
  51. bool *nbuf_used)
  52. {
  53. }
  54. #endif
  55. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  56. #include "dp_rx_mon_feature.h"
  57. #else
  58. static QDF_STATUS
  59. dp_send_ack_frame_to_stack(struct dp_soc *soc,
  60. struct dp_pdev *pdev,
  61. struct hal_rx_ppdu_info *ppdu_info)
  62. {
  63. return QDF_STATUS_SUCCESS;
  64. }
  65. #endif
  66. #ifdef FEATURE_PERPKT_INFO
  67. static inline void
  68. dp_rx_populate_rx_rssi_chain(struct hal_rx_ppdu_info *ppdu_info,
  69. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  70. {
  71. uint8_t chain, bw;
  72. int8_t rssi;
  73. for (chain = 0; chain < SS_COUNT; chain++) {
  74. for (bw = 0; bw < MAX_BW; bw++) {
  75. rssi = ppdu_info->rx_status.rssi_chain[chain][bw];
  76. if (rssi != DP_RSSI_INVAL)
  77. cdp_rx_ppdu->rssi_chain[chain][bw] = rssi;
  78. else
  79. cdp_rx_ppdu->rssi_chain[chain][bw] = 0;
  80. }
  81. }
  82. }
  83. /*
  84. * dp_rx_populate_su_evm_details() - Populate su evm info
  85. * @ppdu_info: ppdu info structure from ppdu ring
  86. * @cdp_rx_ppdu: rx ppdu indication structure
  87. */
  88. static inline void
  89. dp_rx_populate_su_evm_details(struct hal_rx_ppdu_info *ppdu_info,
  90. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  91. {
  92. uint8_t pilot_evm;
  93. uint8_t nss_count;
  94. uint8_t pilot_count;
  95. nss_count = ppdu_info->evm_info.nss_count;
  96. pilot_count = ppdu_info->evm_info.pilot_count;
  97. if ((nss_count * pilot_count) > DP_RX_MAX_SU_EVM_COUNT) {
  98. qdf_err("pilot evm count is more than expected");
  99. return;
  100. }
  101. cdp_rx_ppdu->evm_info.pilot_count = pilot_count;
  102. cdp_rx_ppdu->evm_info.nss_count = nss_count;
  103. /* Populate evm for pilot_evm = nss_count*pilot_count */
  104. for (pilot_evm = 0; pilot_evm < nss_count * pilot_count; pilot_evm++) {
  105. cdp_rx_ppdu->evm_info.pilot_evm[pilot_evm] =
  106. ppdu_info->evm_info.pilot_evm[pilot_evm];
  107. }
  108. }
  109. /**
  110. * dp_rx_inc_rusize_cnt() - increment pdev stats based on RU size
  111. * @pdev: pdev ctx
  112. * @rx_user_status: mon rx user status
  113. *
  114. * Return: bool
  115. */
  116. static inline bool
  117. dp_rx_inc_rusize_cnt(struct dp_pdev *pdev,
  118. struct mon_rx_user_status *rx_user_status)
  119. {
  120. uint32_t ru_size;
  121. bool is_data;
  122. ru_size = rx_user_status->ofdma_ru_size;
  123. if (dp_is_subtype_data(rx_user_status->frame_control)) {
  124. DP_STATS_INC(pdev,
  125. ul_ofdma.data_rx_ru_size[ru_size], 1);
  126. is_data = true;
  127. } else {
  128. DP_STATS_INC(pdev,
  129. ul_ofdma.nondata_rx_ru_size[ru_size], 1);
  130. is_data = false;
  131. }
  132. return is_data;
  133. }
  134. /**
  135. * dp_rx_populate_cdp_indication_ppdu_user() - Populate per user cdp indication
  136. * @pdev: pdev ctx
  137. * @ppdu_info: ppdu info structure from ppdu ring
  138. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  139. *
  140. * Return: none
  141. */
  142. static inline void
  143. dp_rx_populate_cdp_indication_ppdu_user(struct dp_pdev *pdev,
  144. struct hal_rx_ppdu_info *ppdu_info,
  145. qdf_nbuf_t ppdu_nbuf)
  146. {
  147. struct dp_peer *peer;
  148. struct dp_soc *soc = pdev->soc;
  149. struct dp_ast_entry *ast_entry;
  150. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  151. uint32_t ast_index;
  152. int i;
  153. struct mon_rx_user_status *rx_user_status;
  154. struct cdp_rx_stats_ppdu_user *rx_stats_peruser;
  155. int ru_size;
  156. bool is_data = false;
  157. uint32_t num_users;
  158. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  159. num_users = ppdu_info->com_info.num_users;
  160. for (i = 0; i < num_users; i++) {
  161. if (i > OFDMA_NUM_USERS)
  162. return;
  163. rx_user_status = &ppdu_info->rx_user_status[i];
  164. rx_stats_peruser = &cdp_rx_ppdu->user[i];
  165. ast_index = rx_user_status->ast_index;
  166. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  167. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  168. continue;
  169. }
  170. ast_entry = soc->ast_table[ast_index];
  171. if (!ast_entry) {
  172. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  173. continue;
  174. }
  175. peer = ast_entry->peer;
  176. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  177. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  178. continue;
  179. }
  180. rx_stats_peruser->first_data_seq_ctrl =
  181. rx_user_status->first_data_seq_ctrl;
  182. rx_stats_peruser->frame_control_info_valid =
  183. rx_user_status->frame_control_info_valid;
  184. rx_stats_peruser->frame_control =
  185. rx_user_status->frame_control;
  186. rx_stats_peruser->tcp_msdu_count =
  187. rx_user_status->tcp_msdu_count;
  188. rx_stats_peruser->udp_msdu_count =
  189. rx_user_status->udp_msdu_count;
  190. rx_stats_peruser->other_msdu_count =
  191. rx_user_status->other_msdu_count;
  192. rx_stats_peruser->num_msdu =
  193. rx_stats_peruser->tcp_msdu_count +
  194. rx_stats_peruser->udp_msdu_count +
  195. rx_stats_peruser->other_msdu_count;
  196. rx_stats_peruser->preamble_type =
  197. rx_user_status->preamble_type;
  198. rx_stats_peruser->mpdu_cnt_fcs_ok =
  199. rx_user_status->mpdu_cnt_fcs_ok;
  200. rx_stats_peruser->mpdu_cnt_fcs_err =
  201. rx_user_status->mpdu_cnt_fcs_err;
  202. qdf_mem_copy(&rx_stats_peruser->mpdu_fcs_ok_bitmap,
  203. &rx_user_status->mpdu_fcs_ok_bitmap,
  204. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
  205. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  206. rx_stats_peruser->mpdu_ok_byte_count =
  207. rx_user_status->mpdu_ok_byte_count;
  208. rx_stats_peruser->mpdu_err_byte_count =
  209. rx_user_status->mpdu_err_byte_count;
  210. cdp_rx_ppdu->num_mpdu += rx_user_status->mpdu_cnt_fcs_ok;
  211. cdp_rx_ppdu->num_msdu += rx_stats_peruser->num_msdu;
  212. rx_stats_peruser->retries =
  213. CDP_FC_IS_RETRY_SET(rx_stats_peruser->frame_control) ?
  214. rx_stats_peruser->mpdu_cnt_fcs_ok : 0;
  215. if (rx_stats_peruser->mpdu_cnt_fcs_ok > 1)
  216. rx_stats_peruser->is_ampdu = 1;
  217. else
  218. rx_stats_peruser->is_ampdu = 0;
  219. rx_stats_peruser->tid = ppdu_info->rx_status.tid;
  220. qdf_mem_copy(rx_stats_peruser->mac_addr,
  221. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  222. rx_stats_peruser->peer_id = peer->peer_ids[0];
  223. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  224. rx_stats_peruser->vdev_id = peer->vdev->vdev_id;
  225. rx_stats_peruser->mu_ul_info_valid = 0;
  226. if (cdp_rx_ppdu->u.ppdu_type == HAL_RX_TYPE_MU_OFDMA ||
  227. cdp_rx_ppdu->u.ppdu_type == HAL_RX_TYPE_MU_MIMO) {
  228. if (rx_user_status->mu_ul_info_valid) {
  229. rx_stats_peruser->nss = rx_user_status->nss;
  230. rx_stats_peruser->mcs = rx_user_status->mcs;
  231. rx_stats_peruser->mu_ul_info_valid =
  232. rx_user_status->mu_ul_info_valid;
  233. rx_stats_peruser->ofdma_ru_start_index =
  234. rx_user_status->ofdma_ru_start_index;
  235. rx_stats_peruser->ofdma_ru_width =
  236. rx_user_status->ofdma_ru_width;
  237. rx_stats_peruser->user_index = i;
  238. ru_size = rx_user_status->ofdma_ru_size;
  239. /*
  240. * max RU size will be equal to
  241. * HTT_UL_OFDMA_V0_RU_SIZE_RU_996x2
  242. */
  243. if (ru_size >= OFDMA_NUM_RU_SIZE) {
  244. dp_err("invalid ru_size %d\n",
  245. ru_size);
  246. return;
  247. }
  248. is_data = dp_rx_inc_rusize_cnt(pdev,
  249. rx_user_status);
  250. }
  251. if (is_data) {
  252. /* counter to get number of MU OFDMA */
  253. pdev->stats.ul_ofdma.data_rx_ppdu++;
  254. pdev->stats.ul_ofdma.data_users[num_users]++;
  255. }
  256. }
  257. }
  258. }
  259. /**
  260. * dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
  261. * @pdev: pdev ctx
  262. * @ppdu_info: ppdu info structure from ppdu ring
  263. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  264. *
  265. * Return: none
  266. */
  267. static inline void
  268. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  269. struct hal_rx_ppdu_info *ppdu_info,
  270. qdf_nbuf_t ppdu_nbuf)
  271. {
  272. struct dp_peer *peer;
  273. struct dp_soc *soc = pdev->soc;
  274. struct dp_ast_entry *ast_entry;
  275. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  276. uint32_t ast_index;
  277. uint32_t i;
  278. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  279. cdp_rx_ppdu->first_data_seq_ctrl =
  280. ppdu_info->rx_status.first_data_seq_ctrl;
  281. cdp_rx_ppdu->frame_ctrl =
  282. ppdu_info->rx_status.frame_control;
  283. cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
  284. cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
  285. cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
  286. cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
  287. /* num mpdu is consolidated and added together in num user loop */
  288. cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
  289. /* num msdu is consolidated and added together in num user loop */
  290. cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
  291. cdp_rx_ppdu->udp_msdu_count +
  292. cdp_rx_ppdu->other_msdu_count);
  293. cdp_rx_ppdu->retries = CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl) ?
  294. ppdu_info->com_info.mpdu_cnt_fcs_ok : 0;
  295. if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
  296. cdp_rx_ppdu->is_ampdu = 1;
  297. else
  298. cdp_rx_ppdu->is_ampdu = 0;
  299. cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
  300. ast_index = ppdu_info->rx_status.ast_index;
  301. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  302. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  303. cdp_rx_ppdu->num_users = 0;
  304. goto end;
  305. }
  306. ast_entry = soc->ast_table[ast_index];
  307. if (!ast_entry) {
  308. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  309. cdp_rx_ppdu->num_users = 0;
  310. goto end;
  311. }
  312. peer = ast_entry->peer;
  313. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  314. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  315. cdp_rx_ppdu->num_users = 0;
  316. goto end;
  317. }
  318. qdf_mem_copy(cdp_rx_ppdu->mac_addr,
  319. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  320. cdp_rx_ppdu->peer_id = peer->peer_ids[0];
  321. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  322. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  323. cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
  324. cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
  325. cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
  326. cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
  327. cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
  328. if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
  329. (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
  330. cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
  331. else
  332. cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
  333. cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
  334. cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
  335. cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
  336. QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
  337. cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
  338. cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
  339. cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
  340. cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
  341. cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
  342. cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
  343. cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
  344. dp_rx_populate_rx_rssi_chain(ppdu_info, cdp_rx_ppdu);
  345. dp_rx_populate_su_evm_details(ppdu_info, cdp_rx_ppdu);
  346. cdp_rx_ppdu->rx_antenna = ppdu_info->rx_status.rx_antenna;
  347. cdp_rx_ppdu->nf = ppdu_info->rx_status.chan_noise_floor;
  348. for (i = 0; i < MAX_CHAIN; i++)
  349. cdp_rx_ppdu->per_chain_rssi[i] = ppdu_info->rx_status.rssi[i];
  350. cdp_rx_ppdu->is_mcast_bcast = ppdu_info->nac_info.mcast_bcast;
  351. cdp_rx_ppdu->num_users = ppdu_info->com_info.num_users;
  352. cdp_rx_ppdu->num_mpdu = 0;
  353. cdp_rx_ppdu->num_msdu = 0;
  354. dp_rx_populate_cdp_indication_ppdu_user(pdev, ppdu_info, ppdu_nbuf);
  355. return;
  356. end:
  357. dp_rx_populate_cfr_non_assoc_sta(pdev, ppdu_info, ppdu_nbuf);
  358. }
  359. #else
  360. static inline void
  361. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  362. struct hal_rx_ppdu_info *ppdu_info,
  363. qdf_nbuf_t ppdu_nbuf)
  364. {
  365. }
  366. #endif
  367. /**
  368. * dp_rx_stats_update() - Update per-peer statistics
  369. * @soc: Datapath SOC handle
  370. * @peer: Datapath peer handle
  371. * @ppdu: PPDU Descriptor
  372. *
  373. * Return: None
  374. */
  375. #ifdef FEATURE_PERPKT_INFO
  376. static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
  377. struct cdp_rx_indication_ppdu *ppdu,
  378. uint32_t user)
  379. {
  380. uint32_t ratekbps = 0;
  381. uint32_t ppdu_rx_rate = 0;
  382. uint32_t nss = 0;
  383. uint32_t rix;
  384. uint16_t ratecode;
  385. struct cdp_rx_stats_ppdu_user *ppdu_user;
  386. if (!peer || !ppdu)
  387. return;
  388. ppdu_user = &ppdu->user[user];
  389. if (ppdu_user->nss == 0)
  390. nss = 0;
  391. else
  392. nss = ppdu_user->nss - 1;
  393. ratekbps = dp_getrateindex(ppdu->u.gi,
  394. ppdu_user->mcs,
  395. nss,
  396. ppdu->u.preamble,
  397. ppdu->u.bw,
  398. &rix,
  399. &ratecode);
  400. if (!ratekbps)
  401. return;
  402. ppdu->rix = rix;
  403. DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
  404. dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
  405. ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
  406. DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
  407. ppdu->rx_ratekbps = ratekbps;
  408. ppdu->rx_ratecode = ratecode;
  409. if (peer->vdev)
  410. peer->vdev->stats.rx.last_rx_rate = ratekbps;
  411. }
  412. static void dp_rx_stats_update(struct dp_pdev *pdev,
  413. struct cdp_rx_indication_ppdu *ppdu)
  414. {
  415. struct dp_soc *soc = NULL;
  416. uint8_t mcs, preamble, ac = 0, nss, ppdu_type;
  417. uint16_t num_msdu;
  418. uint8_t pkt_bw_offset;
  419. struct dp_peer *peer;
  420. struct cdp_rx_stats_ppdu_user *ppdu_user;
  421. uint32_t i;
  422. enum cdp_mu_packet_type mu_pkt_type;
  423. if (pdev)
  424. soc = pdev->soc;
  425. else
  426. return;
  427. if (!soc || soc->process_rx_status)
  428. return;
  429. preamble = ppdu->u.preamble;
  430. ppdu_type = ppdu->u.ppdu_type;
  431. for (i = 0; i < ppdu->num_users; i++) {
  432. ppdu_user = &ppdu->user[i];
  433. peer = dp_peer_find_by_id(soc, ppdu_user->peer_id);
  434. if (!peer)
  435. peer = pdev->invalid_peer;
  436. ppdu->cookie = (void *)peer->wlanstats_ctx;
  437. if (ppdu_type == HAL_RX_TYPE_SU) {
  438. mcs = ppdu->u.mcs;
  439. nss = ppdu->u.nss;
  440. } else {
  441. mcs = ppdu_user->mcs;
  442. nss = ppdu_user->nss;
  443. }
  444. num_msdu = ppdu_user->num_msdu;
  445. switch (ppdu->u.bw) {
  446. case CMN_BW_20MHZ:
  447. pkt_bw_offset = PKT_BW_GAIN_20MHZ;
  448. break;
  449. case CMN_BW_40MHZ:
  450. pkt_bw_offset = PKT_BW_GAIN_40MHZ;
  451. break;
  452. case CMN_BW_80MHZ:
  453. pkt_bw_offset = PKT_BW_GAIN_80MHZ;
  454. break;
  455. case CMN_BW_160MHZ:
  456. pkt_bw_offset = PKT_BW_GAIN_160MHZ;
  457. break;
  458. default:
  459. pkt_bw_offset = 0;
  460. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  461. "Invalid BW index = %d", ppdu->u.bw);
  462. }
  463. DP_STATS_UPD(peer, rx.rssi, (ppdu->rssi + pkt_bw_offset));
  464. if (peer->stats.rx.avg_rssi == INVALID_RSSI)
  465. peer->stats.rx.avg_rssi =
  466. CDP_RSSI_IN(peer->stats.rx.rssi);
  467. else
  468. CDP_RSSI_UPDATE_AVG(peer->stats.rx.avg_rssi,
  469. peer->stats.rx.rssi);
  470. if ((preamble == DOT11_A) || (preamble == DOT11_B))
  471. nss = 1;
  472. if (ppdu_type == HAL_RX_TYPE_SU) {
  473. if (nss) {
  474. DP_STATS_INC(peer, rx.nss[nss - 1], num_msdu);
  475. DP_STATS_INC(peer, rx.ppdu_nss[nss - 1], 1);
  476. }
  477. DP_STATS_INC(peer, rx.mpdu_cnt_fcs_ok,
  478. ppdu_user->mpdu_cnt_fcs_ok);
  479. DP_STATS_INC(peer, rx.mpdu_cnt_fcs_err,
  480. ppdu_user->mpdu_cnt_fcs_err);
  481. }
  482. if (ppdu_type >= HAL_RX_TYPE_MU_MIMO &&
  483. ppdu_type <= HAL_RX_TYPE_MU_OFDMA) {
  484. if (ppdu_type == HAL_RX_TYPE_MU_MIMO)
  485. mu_pkt_type = RX_TYPE_MU_MIMO;
  486. else
  487. mu_pkt_type = RX_TYPE_MU_OFDMA;
  488. if (nss) {
  489. DP_STATS_INC(peer, rx.nss[nss - 1], num_msdu);
  490. DP_STATS_INC(peer,
  491. rx.rx_mu[mu_pkt_type].ppdu_nss[nss - 1],
  492. 1);
  493. }
  494. DP_STATS_INC(peer,
  495. rx.rx_mu[mu_pkt_type].mpdu_cnt_fcs_ok,
  496. ppdu_user->mpdu_cnt_fcs_ok);
  497. DP_STATS_INC(peer,
  498. rx.rx_mu[mu_pkt_type].mpdu_cnt_fcs_err,
  499. ppdu_user->mpdu_cnt_fcs_err);
  500. }
  501. DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
  502. DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
  503. DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type],
  504. num_msdu);
  505. DP_STATS_INC(peer, rx.ppdu_cnt[ppdu->u.ppdu_type], 1);
  506. DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu,
  507. ppdu_user->is_ampdu);
  508. DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu,
  509. !(ppdu_user->is_ampdu));
  510. DP_STATS_UPD(peer, rx.rx_rate, mcs);
  511. DP_STATS_INCC(peer,
  512. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  513. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  514. DP_STATS_INCC(peer,
  515. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  516. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  517. DP_STATS_INCC(peer,
  518. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  519. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  520. DP_STATS_INCC(peer,
  521. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  522. ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
  523. DP_STATS_INCC(peer,
  524. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  525. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  526. DP_STATS_INCC(peer,
  527. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  528. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  529. DP_STATS_INCC(peer,
  530. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  531. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  532. DP_STATS_INCC(peer,
  533. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  534. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  535. DP_STATS_INCC(peer,
  536. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  537. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  538. DP_STATS_INCC(peer,
  539. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  540. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  541. DP_STATS_INCC(peer,
  542. rx.su_ax_ppdu_cnt.mcs_count[MAX_MCS - 1], 1,
  543. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX) &&
  544. (ppdu_type == HAL_RX_TYPE_SU)));
  545. DP_STATS_INCC(peer,
  546. rx.su_ax_ppdu_cnt.mcs_count[mcs], 1,
  547. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX) &&
  548. (ppdu_type == HAL_RX_TYPE_SU)));
  549. DP_STATS_INCC(peer,
  550. rx.rx_mu[RX_TYPE_MU_OFDMA].ppdu.mcs_count[MAX_MCS - 1],
  551. 1, ((mcs >= (MAX_MCS - 1)) &&
  552. (preamble == DOT11_AX) &&
  553. (ppdu_type == HAL_RX_TYPE_MU_OFDMA)));
  554. DP_STATS_INCC(peer,
  555. rx.rx_mu[RX_TYPE_MU_OFDMA].ppdu.mcs_count[mcs],
  556. 1, ((mcs < (MAX_MCS - 1)) &&
  557. (preamble == DOT11_AX) &&
  558. (ppdu_type == HAL_RX_TYPE_MU_OFDMA)));
  559. DP_STATS_INCC(peer,
  560. rx.rx_mu[RX_TYPE_MU_MIMO].ppdu.mcs_count[MAX_MCS - 1],
  561. 1, ((mcs >= (MAX_MCS - 1)) &&
  562. (preamble == DOT11_AX) &&
  563. (ppdu_type == HAL_RX_TYPE_MU_MIMO)));
  564. DP_STATS_INCC(peer,
  565. rx.rx_mu[RX_TYPE_MU_MIMO].ppdu.mcs_count[mcs],
  566. 1, ((mcs < (MAX_MCS - 1)) &&
  567. (preamble == DOT11_AX) &&
  568. (ppdu_type == HAL_RX_TYPE_MU_MIMO)));
  569. /*
  570. * If invalid TID, it could be a non-qos frame, hence do not
  571. * update any AC counters
  572. */
  573. ac = TID_TO_WME_AC(ppdu_user->tid);
  574. if (ppdu->tid != HAL_TID_INVALID)
  575. DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
  576. dp_peer_stats_notify(pdev, peer);
  577. DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
  578. if (peer == pdev->invalid_peer)
  579. continue;
  580. if (dp_is_subtype_data(ppdu->frame_ctrl))
  581. dp_rx_rate_stats_update(peer, ppdu, i);
  582. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  583. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  584. &peer->stats, ppdu->peer_id,
  585. UPDATE_PEER_STATS, pdev->pdev_id);
  586. #endif
  587. dp_peer_unref_del_find_by_id(peer);
  588. }
  589. }
  590. #endif
  591. /*
  592. * dp_rx_get_fcs_ok_msdu() - get ppdu status buffer containing fcs_ok msdu
  593. * @pdev: pdev object
  594. * @ppdu_info: ppdu info object
  595. *
  596. * Return: nbuf
  597. */
  598. static inline qdf_nbuf_t
  599. dp_rx_get_fcs_ok_msdu(struct dp_pdev *pdev,
  600. struct hal_rx_ppdu_info *ppdu_info)
  601. {
  602. uint16_t mpdu_fcs_ok;
  603. qdf_nbuf_t status_nbuf = NULL;
  604. unsigned long *fcs_ok_bitmap;
  605. if (qdf_unlikely(qdf_nbuf_is_queue_empty(&pdev->rx_ppdu_buf_q)))
  606. return NULL;
  607. /* Obtain fcs_ok passed index from bitmap
  608. * this index is used to get fcs passed first msdu payload
  609. */
  610. fcs_ok_bitmap =
  611. (unsigned long *)&ppdu_info->com_info.mpdu_fcs_ok_bitmap[0];
  612. mpdu_fcs_ok = qdf_find_first_bit(fcs_ok_bitmap,
  613. HAL_RX_MAX_MPDU);
  614. if (qdf_unlikely(mpdu_fcs_ok >= HAL_RX_MAX_MPDU))
  615. goto end;
  616. if (qdf_unlikely(!ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].nbuf))
  617. goto end;
  618. /* Get status buffer by indexing mpdu_fcs_ok index
  619. * containing first msdu payload with fcs passed
  620. * and clone the buffer
  621. */
  622. status_nbuf = ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].nbuf;
  623. ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].nbuf = NULL;
  624. /* Take ref of status nbuf as this nbuf is to be
  625. * freeed by upper layer.
  626. */
  627. qdf_nbuf_ref(status_nbuf);
  628. ppdu_info->fcs_ok_msdu_info.first_msdu_payload =
  629. ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].first_msdu_payload;
  630. ppdu_info->fcs_ok_msdu_info.payload_len =
  631. ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].payload_len;
  632. end:
  633. /* Free the ppdu status buffer queue */
  634. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  635. qdf_mem_zero(&ppdu_info->ppdu_msdu_info,
  636. (ppdu_info->com_info.mpdu_cnt_fcs_ok +
  637. ppdu_info->com_info.mpdu_cnt_fcs_err)
  638. * sizeof(struct hal_rx_msdu_payload_info));
  639. return status_nbuf;
  640. }
  641. static inline void
  642. dp_rx_handle_ppdu_status_buf(struct dp_pdev *pdev,
  643. struct hal_rx_ppdu_info *ppdu_info,
  644. qdf_nbuf_t status_nbuf)
  645. {
  646. qdf_nbuf_t dropnbuf;
  647. if (qdf_nbuf_queue_len(&pdev->rx_ppdu_buf_q) >
  648. HAL_RX_MAX_MPDU) {
  649. dropnbuf = qdf_nbuf_queue_remove(&pdev->rx_ppdu_buf_q);
  650. qdf_nbuf_free(dropnbuf);
  651. }
  652. qdf_nbuf_queue_add(&pdev->rx_ppdu_buf_q, status_nbuf);
  653. }
  654. /**
  655. * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
  656. * @soc: core txrx main context
  657. * @pdev: pdev strcuture
  658. * @ppdu_info: structure for rx ppdu ring
  659. *
  660. * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
  661. * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
  662. */
  663. #ifdef FEATURE_PERPKT_INFO
  664. static inline QDF_STATUS
  665. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  666. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  667. {
  668. uint8_t size = 0;
  669. struct ieee80211_frame *wh;
  670. uint32_t *nbuf_data;
  671. if (!ppdu_info->fcs_ok_msdu_info.first_msdu_payload)
  672. return QDF_STATUS_SUCCESS;
  673. if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
  674. return QDF_STATUS_SUCCESS;
  675. pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
  676. wh = (struct ieee80211_frame *)
  677. (ppdu_info->fcs_ok_msdu_info.first_msdu_payload + 4);
  678. size = (ppdu_info->fcs_ok_msdu_info.first_msdu_payload -
  679. qdf_nbuf_data(nbuf));
  680. if (qdf_nbuf_pull_head(nbuf, size) == NULL)
  681. return QDF_STATUS_SUCCESS;
  682. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  683. IEEE80211_FC0_TYPE_MGT) ||
  684. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  685. IEEE80211_FC0_TYPE_CTL)) {
  686. return QDF_STATUS_SUCCESS;
  687. }
  688. ppdu_info->fcs_ok_msdu_info.first_msdu_payload = NULL;
  689. nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
  690. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  691. /* only retain RX MSDU payload in the skb */
  692. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
  693. ppdu_info->fcs_ok_msdu_info.payload_len);
  694. dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
  695. nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
  696. return QDF_STATUS_E_ALREADY;
  697. }
  698. #else
  699. static inline QDF_STATUS
  700. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  701. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  702. {
  703. return QDF_STATUS_SUCCESS;
  704. }
  705. #endif
  706. #ifdef FEATURE_PERPKT_INFO
  707. static inline void
  708. dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  709. struct hal_rx_ppdu_info *ppdu_info,
  710. uint32_t tlv_status,
  711. qdf_nbuf_t status_nbuf)
  712. {
  713. QDF_STATUS mcopy_status;
  714. if (qdf_unlikely(!ppdu_info->com_info.mpdu_cnt)) {
  715. qdf_nbuf_free(status_nbuf);
  716. return;
  717. }
  718. /* Add buffers to queue until we receive
  719. * HAL_TLV_STATUS_PPDU_DONE
  720. */
  721. dp_rx_handle_ppdu_status_buf(pdev, ppdu_info, status_nbuf);
  722. /* If tlv_status is PPDU_DONE, process rx_ppdu_buf_q
  723. * and devliver fcs_ok msdu buffer
  724. */
  725. if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
  726. if (qdf_unlikely(ppdu_info->com_info.mpdu_cnt !=
  727. (ppdu_info->com_info.mpdu_cnt_fcs_ok +
  728. ppdu_info->com_info.mpdu_cnt_fcs_err))) {
  729. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  730. return;
  731. }
  732. /* Get rx ppdu status buffer having fcs ok msdu */
  733. status_nbuf = dp_rx_get_fcs_ok_msdu(pdev, ppdu_info);
  734. if (status_nbuf) {
  735. mcopy_status = dp_rx_handle_mcopy_mode(soc, pdev,
  736. ppdu_info,
  737. status_nbuf);
  738. if (mcopy_status == QDF_STATUS_SUCCESS)
  739. qdf_nbuf_free(status_nbuf);
  740. }
  741. }
  742. }
  743. #else
  744. static inline void
  745. dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  746. struct hal_rx_ppdu_info *ppdu_info,
  747. uint32_t tlv_status,
  748. qdf_nbuf_t status_nbuf)
  749. {
  750. }
  751. #endif
  752. /**
  753. * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
  754. * @soc: Datapath SOC handle
  755. * @pdev: Datapath PDEV handle
  756. * @ppdu_info: Structure for rx ppdu info
  757. * @nbuf: Qdf nbuf abstraction for linux skb
  758. *
  759. * Return: 0 on success, 1 on failure
  760. */
  761. static inline int
  762. dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  763. struct hal_rx_ppdu_info *ppdu_info,
  764. qdf_nbuf_t nbuf)
  765. {
  766. uint8_t size = 0;
  767. if (!pdev->monitor_vdev) {
  768. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  769. "[%s]:[%d] Monitor vdev is NULL !!",
  770. __func__, __LINE__);
  771. return 1;
  772. }
  773. if (!ppdu_info->msdu_info.first_msdu_payload) {
  774. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  775. "[%s]:[%d] First msdu payload not present",
  776. __func__, __LINE__);
  777. return 1;
  778. }
  779. /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
  780. size = (ppdu_info->msdu_info.first_msdu_payload -
  781. qdf_nbuf_data(nbuf)) + 4;
  782. ppdu_info->msdu_info.first_msdu_payload = NULL;
  783. if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
  784. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  785. "[%s]:[%d] No header present",
  786. __func__, __LINE__);
  787. return 1;
  788. }
  789. /* Only retain RX MSDU payload in the skb */
  790. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
  791. ppdu_info->msdu_info.payload_len);
  792. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, nbuf,
  793. qdf_nbuf_headroom(nbuf))) {
  794. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  795. return 1;
  796. }
  797. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  798. nbuf, NULL);
  799. pdev->ppdu_info.rx_status.monitor_direct_used = 0;
  800. return 0;
  801. }
  802. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  803. /*
  804. * dp_rx_mon_handle_cfr_mu_info() - Gather macaddr and ast_index of peer(s) in
  805. * the PPDU received, this will be used for correlation of CFR data captured
  806. * for an UL-MU-PPDU
  807. * @pdev: pdev ctx
  808. * @ppdu_info: pointer to ppdu info structure populated from ppdu status TLVs
  809. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  810. *
  811. * Return: none
  812. */
  813. static inline void
  814. dp_rx_mon_handle_cfr_mu_info(struct dp_pdev *pdev,
  815. struct hal_rx_ppdu_info *ppdu_info,
  816. qdf_nbuf_t ppdu_nbuf)
  817. {
  818. struct dp_peer *peer;
  819. struct dp_soc *soc = pdev->soc;
  820. struct dp_ast_entry *ast_entry;
  821. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  822. struct mon_rx_user_status *rx_user_status;
  823. struct cdp_rx_stats_ppdu_user *rx_stats_peruser;
  824. uint32_t num_users;
  825. int user_id;
  826. uint32_t ast_index;
  827. if (!ppdu_info->cfr_info.bb_captured_channel)
  828. return;
  829. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  830. qdf_spin_lock_bh(&soc->ast_lock);
  831. num_users = ppdu_info->com_info.num_users;
  832. for (user_id = 0; user_id < num_users; user_id++) {
  833. if (user_id > OFDMA_NUM_USERS) {
  834. qdf_spin_unlock_bh(&soc->ast_lock);
  835. return;
  836. }
  837. rx_user_status = &ppdu_info->rx_user_status[user_id];
  838. rx_stats_peruser = &cdp_rx_ppdu->user[user_id];
  839. ast_index = rx_user_status->ast_index;
  840. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  841. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  842. continue;
  843. }
  844. ast_entry = soc->ast_table[ast_index];
  845. if (!ast_entry) {
  846. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  847. continue;
  848. }
  849. peer = ast_entry->peer;
  850. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  851. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  852. continue;
  853. }
  854. qdf_mem_copy(rx_stats_peruser->mac_addr,
  855. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  856. }
  857. qdf_spin_unlock_bh(&soc->ast_lock);
  858. }
  859. /*
  860. * dp_rx_mon_populate_cfr_ppdu_info() - Populate cdp ppdu info from hal ppdu
  861. * info
  862. * @pdev: pdev ctx
  863. * @ppdu_info: ppdu info structure from ppdu ring
  864. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  865. *
  866. * Return: none
  867. */
  868. static inline void
  869. dp_rx_mon_populate_cfr_ppdu_info(struct dp_pdev *pdev,
  870. struct hal_rx_ppdu_info *ppdu_info,
  871. qdf_nbuf_t ppdu_nbuf)
  872. {
  873. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  874. int chain;
  875. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  876. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  877. cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
  878. cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
  879. cdp_rx_ppdu->num_users = ppdu_info->com_info.num_users;
  880. for (chain = 0; chain < MAX_CHAIN; chain++)
  881. cdp_rx_ppdu->per_chain_rssi[chain] =
  882. ppdu_info->rx_status.rssi[chain];
  883. dp_rx_mon_handle_cfr_mu_info(pdev, ppdu_info, ppdu_nbuf);
  884. }
  885. /*
  886. * dp_rx_mon_populate_cfr_info() - Populate cdp ppdu info from hal cfr info
  887. * @pdev: pdev ctx
  888. * @ppdu_info: ppdu info structure from ppdu ring
  889. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  890. *
  891. * Return: none
  892. */
  893. static inline void
  894. dp_rx_mon_populate_cfr_info(struct dp_pdev *pdev,
  895. struct hal_rx_ppdu_info *ppdu_info,
  896. qdf_nbuf_t ppdu_nbuf)
  897. {
  898. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  899. struct cdp_rx_ppdu_cfr_info *cfr_info;
  900. if (qdf_unlikely(!pdev->cfr_rcc_mode))
  901. return;
  902. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  903. cfr_info = &cdp_rx_ppdu->cfr_info;
  904. cfr_info->bb_captured_channel
  905. = ppdu_info->cfr_info.bb_captured_channel;
  906. cfr_info->bb_captured_timeout
  907. = ppdu_info->cfr_info.bb_captured_timeout;
  908. cfr_info->bb_captured_reason
  909. = ppdu_info->cfr_info.bb_captured_reason;
  910. cfr_info->rx_location_info_valid
  911. = ppdu_info->cfr_info.rx_location_info_valid;
  912. cfr_info->chan_capture_status
  913. = ppdu_info->cfr_info.chan_capture_status;
  914. cfr_info->rtt_che_buffer_pointer_high8
  915. = ppdu_info->cfr_info.rtt_che_buffer_pointer_high8;
  916. cfr_info->rtt_che_buffer_pointer_low32
  917. = ppdu_info->cfr_info.rtt_che_buffer_pointer_low32;
  918. }
  919. /*
  920. * dp_rx_handle_cfr() - Gather cfr info from hal ppdu info
  921. * @soc: core txrx main context
  922. * @pdev: pdev ctx
  923. * @ppdu_info: ppdu info structure from ppdu ring
  924. *
  925. * Return: none
  926. */
  927. static inline void
  928. dp_rx_handle_cfr(struct dp_soc *soc, struct dp_pdev *pdev,
  929. struct hal_rx_ppdu_info *ppdu_info)
  930. {
  931. qdf_nbuf_t ppdu_nbuf;
  932. if (!ppdu_info->cfr_info.bb_captured_channel &&
  933. !ppdu_info->cfr_info.bb_captured_timeout)
  934. return;
  935. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  936. sizeof(struct cdp_rx_indication_ppdu),
  937. 0,
  938. 0,
  939. FALSE);
  940. if (ppdu_nbuf) {
  941. dp_rx_mon_populate_cfr_info(pdev, ppdu_info, ppdu_nbuf);
  942. dp_rx_mon_populate_cfr_ppdu_info(pdev, ppdu_info, ppdu_nbuf);
  943. qdf_nbuf_put_tail(ppdu_nbuf,
  944. sizeof(struct cdp_rx_indication_ppdu));
  945. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  946. ppdu_nbuf, HTT_INVALID_PEER,
  947. WDI_NO_VAL, pdev->pdev_id);
  948. }
  949. }
  950. /**
  951. * dp_rx_populate_cfr_non_assoc_sta() - Populate cfr ppdu info for PPDUs from
  952. * non-associated stations
  953. * @pdev: pdev ctx
  954. * @ppdu_info: ppdu info structure from ppdu ring
  955. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  956. *
  957. * Return: none
  958. */
  959. static inline void
  960. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  961. struct hal_rx_ppdu_info *ppdu_info,
  962. qdf_nbuf_t ppdu_nbuf)
  963. {
  964. if (!pdev->cfr_rcc_mode)
  965. return;
  966. if (ppdu_info->cfr_info.bb_captured_channel)
  967. dp_rx_mon_populate_cfr_ppdu_info(pdev, ppdu_info, ppdu_nbuf);
  968. }
  969. #else
  970. static inline void
  971. dp_rx_mon_handle_cfr_mu_info(struct dp_pdev *pdev,
  972. struct hal_rx_ppdu_info *ppdu_info,
  973. qdf_nbuf_t ppdu_nbuf)
  974. {
  975. }
  976. static inline void
  977. dp_rx_mon_populate_cfr_ppdu_info(struct dp_pdev *pdev,
  978. struct hal_rx_ppdu_info *ppdu_info,
  979. qdf_nbuf_t ppdu_nbuf)
  980. {
  981. }
  982. static inline void
  983. dp_rx_mon_populate_cfr_info(struct dp_pdev *pdev,
  984. struct hal_rx_ppdu_info *ppdu_info,
  985. qdf_nbuf_t ppdu_nbuf)
  986. {
  987. }
  988. static inline void
  989. dp_rx_handle_cfr(struct dp_soc *soc, struct dp_pdev *pdev,
  990. struct hal_rx_ppdu_info *ppdu_info)
  991. {
  992. }
  993. static inline void
  994. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  995. struct hal_rx_ppdu_info *ppdu_info,
  996. qdf_nbuf_t ppdu_nbuf)
  997. {
  998. }
  999. #endif
  1000. /**
  1001. * dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
  1002. * @soc: core txrx main context
  1003. * @pdev: pdev strcuture
  1004. * @ppdu_info: structure for rx ppdu ring
  1005. *
  1006. * Return: none
  1007. */
  1008. #ifdef FEATURE_PERPKT_INFO
  1009. static inline void
  1010. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  1011. struct hal_rx_ppdu_info *ppdu_info)
  1012. {
  1013. qdf_nbuf_t ppdu_nbuf;
  1014. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  1015. /*
  1016. * Do not allocate if fcs error,
  1017. * ast idx invalid / fctl invalid
  1018. *
  1019. * In CFR RCC mode - PPDU status TLVs of error pkts are also needed
  1020. */
  1021. if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
  1022. return;
  1023. if (ppdu_info->nac_info.fc_valid &&
  1024. ppdu_info->nac_info.to_ds_flag &&
  1025. ppdu_info->nac_info.mac_addr2_valid) {
  1026. struct dp_neighbour_peer *peer = NULL;
  1027. uint8_t rssi = ppdu_info->rx_status.rssi_comb;
  1028. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  1029. if (pdev->neighbour_peers_added) {
  1030. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  1031. neighbour_peer_list_elem) {
  1032. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
  1033. &ppdu_info->nac_info.mac_addr2,
  1034. QDF_MAC_ADDR_SIZE)) {
  1035. peer->rssi = rssi;
  1036. break;
  1037. }
  1038. }
  1039. }
  1040. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  1041. }
  1042. /* need not generate wdi event when mcopy and
  1043. * enhanced stats are not enabled
  1044. */
  1045. if (!pdev->mcopy_mode && !pdev->enhanced_stats_en &&
  1046. !pdev->cfr_rcc_mode)
  1047. return;
  1048. if (!pdev->mcopy_mode && !pdev->cfr_rcc_mode) {
  1049. if (!ppdu_info->rx_status.frame_control_info_valid)
  1050. return;
  1051. if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
  1052. return;
  1053. }
  1054. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  1055. sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
  1056. if (ppdu_nbuf) {
  1057. dp_rx_mon_populate_cfr_info(pdev, ppdu_info, ppdu_nbuf);
  1058. dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
  1059. qdf_nbuf_put_tail(ppdu_nbuf,
  1060. sizeof(struct cdp_rx_indication_ppdu));
  1061. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  1062. dp_rx_stats_update(pdev, cdp_rx_ppdu);
  1063. if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
  1064. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
  1065. soc, ppdu_nbuf,
  1066. cdp_rx_ppdu->peer_id,
  1067. WDI_NO_VAL, pdev->pdev_id);
  1068. } else if (pdev->mcopy_mode || pdev->cfr_rcc_mode) {
  1069. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  1070. ppdu_nbuf, HTT_INVALID_PEER,
  1071. WDI_NO_VAL, pdev->pdev_id);
  1072. } else {
  1073. qdf_nbuf_free(ppdu_nbuf);
  1074. }
  1075. }
  1076. }
  1077. #else
  1078. static inline void
  1079. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  1080. struct hal_rx_ppdu_info *ppdu_info)
  1081. {
  1082. }
  1083. #endif
  1084. /**
  1085. * dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
  1086. * filtering enabled
  1087. * @soc: core txrx main context
  1088. * @ppdu_info: Structure for rx ppdu info
  1089. * @status_nbuf: Qdf nbuf abstraction for linux skb
  1090. * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
  1091. *
  1092. * Return: none
  1093. */
  1094. static inline void
  1095. dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
  1096. struct hal_rx_ppdu_info *ppdu_info,
  1097. qdf_nbuf_t status_nbuf, uint32_t mac_id)
  1098. {
  1099. struct dp_peer *peer;
  1100. struct dp_ast_entry *ast_entry;
  1101. uint32_t ast_index;
  1102. ast_index = ppdu_info->rx_status.ast_index;
  1103. if (ast_index < wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  1104. ast_entry = soc->ast_table[ast_index];
  1105. if (ast_entry) {
  1106. peer = ast_entry->peer;
  1107. if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
  1108. if (peer->peer_based_pktlog_filter) {
  1109. dp_wdi_event_handler(
  1110. WDI_EVENT_RX_DESC, soc,
  1111. status_nbuf,
  1112. peer->peer_ids[0],
  1113. WDI_NO_VAL, mac_id);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. #if defined(HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_M)
  1120. static inline void
  1121. dp_rx_ul_ofdma_ru_size_to_width(
  1122. uint32_t ru_size,
  1123. uint32_t *ru_width)
  1124. {
  1125. uint32_t width;
  1126. width = 0;
  1127. switch (ru_size) {
  1128. case HTT_UL_OFDMA_V0_RU_SIZE_RU_26:
  1129. width = 1;
  1130. break;
  1131. case HTT_UL_OFDMA_V0_RU_SIZE_RU_52:
  1132. width = 2;
  1133. break;
  1134. case HTT_UL_OFDMA_V0_RU_SIZE_RU_106:
  1135. width = 4;
  1136. break;
  1137. case HTT_UL_OFDMA_V0_RU_SIZE_RU_242:
  1138. width = 9;
  1139. break;
  1140. case HTT_UL_OFDMA_V0_RU_SIZE_RU_484:
  1141. width = 18;
  1142. break;
  1143. case HTT_UL_OFDMA_V0_RU_SIZE_RU_996:
  1144. width = 37;
  1145. break;
  1146. case HTT_UL_OFDMA_V0_RU_SIZE_RU_996x2:
  1147. width = 74;
  1148. break;
  1149. default:
  1150. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1151. "RU size to width convert err");
  1152. break;
  1153. }
  1154. *ru_width = width;
  1155. }
  1156. static inline void
  1157. dp_rx_mon_handle_mu_ul_info(struct hal_rx_ppdu_info *ppdu_info)
  1158. {
  1159. struct mon_rx_user_status *mon_rx_user_status;
  1160. uint32_t num_users;
  1161. uint32_t i;
  1162. uint32_t mu_ul_user_v0_word0;
  1163. uint32_t mu_ul_user_v0_word1;
  1164. uint32_t ru_width;
  1165. uint32_t ru_size;
  1166. if (!(ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_OFDMA ||
  1167. ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_MIMO))
  1168. return;
  1169. num_users = ppdu_info->com_info.num_users;
  1170. if (num_users > HAL_MAX_UL_MU_USERS)
  1171. num_users = HAL_MAX_UL_MU_USERS;
  1172. for (i = 0; i < num_users; i++) {
  1173. mon_rx_user_status = &ppdu_info->rx_user_status[i];
  1174. mu_ul_user_v0_word0 =
  1175. mon_rx_user_status->mu_ul_user_v0_word0;
  1176. mu_ul_user_v0_word1 =
  1177. mon_rx_user_status->mu_ul_user_v0_word1;
  1178. if (HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_GET(
  1179. mu_ul_user_v0_word0) &&
  1180. !HTT_UL_OFDMA_USER_INFO_V0_W0_VER_GET(
  1181. mu_ul_user_v0_word0)) {
  1182. mon_rx_user_status->mcs =
  1183. HTT_UL_OFDMA_USER_INFO_V0_W1_MCS_GET(
  1184. mu_ul_user_v0_word1);
  1185. mon_rx_user_status->nss =
  1186. HTT_UL_OFDMA_USER_INFO_V0_W1_NSS_GET(
  1187. mu_ul_user_v0_word1) + 1;
  1188. mon_rx_user_status->mu_ul_info_valid = 1;
  1189. mon_rx_user_status->ofdma_ru_start_index =
  1190. HTT_UL_OFDMA_USER_INFO_V0_W1_RU_START_GET(
  1191. mu_ul_user_v0_word1);
  1192. ru_size =
  1193. HTT_UL_OFDMA_USER_INFO_V0_W1_RU_SIZE_GET(
  1194. mu_ul_user_v0_word1);
  1195. dp_rx_ul_ofdma_ru_size_to_width(ru_size, &ru_width);
  1196. mon_rx_user_status->ofdma_ru_width = ru_width;
  1197. mon_rx_user_status->ofdma_ru_size = ru_size;
  1198. }
  1199. }
  1200. }
  1201. #else
  1202. static inline void
  1203. dp_rx_mon_handle_mu_ul_info(struct hal_rx_ppdu_info *ppdu_info)
  1204. {
  1205. }
  1206. #endif
  1207. /**
  1208. * dp_rx_mon_status_process_tlv() - Process status TLV in status
  1209. * buffer on Rx status Queue posted by status SRNG processing.
  1210. * @soc: core txrx main context
  1211. * @mac_id: mac_id which is one of 3 mac_ids _ring
  1212. *
  1213. * Return: none
  1214. */
  1215. static inline void
  1216. dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
  1217. uint32_t quota)
  1218. {
  1219. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1220. struct hal_rx_ppdu_info *ppdu_info;
  1221. qdf_nbuf_t status_nbuf;
  1222. uint8_t *rx_tlv;
  1223. uint8_t *rx_tlv_start;
  1224. uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
  1225. QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
  1226. struct cdp_pdev_mon_stats *rx_mon_stats;
  1227. int smart_mesh_status;
  1228. enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
  1229. bool nbuf_used;
  1230. uint32_t rx_enh_capture_mode;
  1231. ppdu_info = &pdev->ppdu_info;
  1232. rx_mon_stats = &pdev->rx_mon_stats;
  1233. if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
  1234. return;
  1235. rx_enh_capture_mode = pdev->rx_enh_capture_mode;
  1236. while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
  1237. status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
  1238. rx_tlv = qdf_nbuf_data(status_nbuf);
  1239. rx_tlv_start = rx_tlv;
  1240. nbuf_used = false;
  1241. if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
  1242. pdev->mcopy_mode ||
  1243. (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  1244. do {
  1245. tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
  1246. ppdu_info, pdev->soc->hal_soc,
  1247. status_nbuf);
  1248. dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
  1249. rx_mon_stats);
  1250. dp_rx_mon_enh_capture_process(pdev, tlv_status,
  1251. status_nbuf, ppdu_info,
  1252. &nbuf_used);
  1253. rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
  1254. if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
  1255. break;
  1256. } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
  1257. (tlv_status == HAL_TLV_STATUS_HEADER) ||
  1258. (tlv_status == HAL_TLV_STATUS_MPDU_END) ||
  1259. (tlv_status == HAL_TLV_STATUS_MSDU_END));
  1260. }
  1261. if (pdev->dp_peer_based_pktlog) {
  1262. dp_rx_process_peer_based_pktlog(soc, ppdu_info,
  1263. status_nbuf, mac_id);
  1264. } else {
  1265. if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
  1266. pktlog_mode = WDI_EVENT_RX_DESC;
  1267. else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
  1268. pktlog_mode = WDI_EVENT_LITE_RX;
  1269. if (pktlog_mode != WDI_NO_VAL)
  1270. dp_wdi_event_handler(pktlog_mode, soc,
  1271. status_nbuf,
  1272. HTT_INVALID_PEER,
  1273. WDI_NO_VAL, mac_id);
  1274. }
  1275. /* smart monitor vap and m_copy cannot co-exist */
  1276. if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
  1277. && pdev->monitor_vdev) {
  1278. smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
  1279. pdev, ppdu_info, status_nbuf);
  1280. if (smart_mesh_status)
  1281. qdf_nbuf_free(status_nbuf);
  1282. } else if (qdf_unlikely(pdev->mcopy_mode)) {
  1283. dp_rx_process_mcopy_mode(soc, pdev,
  1284. ppdu_info, tlv_status,
  1285. status_nbuf);
  1286. } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
  1287. if (!nbuf_used)
  1288. qdf_nbuf_free(status_nbuf);
  1289. if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
  1290. enh_log_status =
  1291. dp_rx_handle_enh_capture(soc,
  1292. pdev, ppdu_info);
  1293. } else {
  1294. qdf_nbuf_free(status_nbuf);
  1295. }
  1296. if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
  1297. dp_rx_mon_deliver_non_std(soc, mac_id);
  1298. } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
  1299. rx_mon_stats->status_ppdu_done++;
  1300. dp_rx_mon_handle_mu_ul_info(ppdu_info);
  1301. if (pdev->tx_capture_enabled
  1302. != CDP_TX_ENH_CAPTURE_DISABLED)
  1303. dp_send_ack_frame_to_stack(soc, pdev,
  1304. ppdu_info);
  1305. if (pdev->enhanced_stats_en ||
  1306. pdev->mcopy_mode || pdev->neighbour_peers_added)
  1307. dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
  1308. else if (pdev->cfr_rcc_mode)
  1309. dp_rx_handle_cfr(soc, pdev, ppdu_info);
  1310. pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
  1311. /*
  1312. * if chan_num is not fetched correctly from ppdu RX TLV,
  1313. * get it from pdev saved.
  1314. */
  1315. if (qdf_unlikely(pdev->ppdu_info.rx_status.chan_num == 0))
  1316. pdev->ppdu_info.rx_status.chan_num = pdev->mon_chan_num;
  1317. /*
  1318. * if chan_freq is not fetched correctly from ppdu RX TLV,
  1319. * get it from pdev saved.
  1320. */
  1321. if (qdf_unlikely(pdev->ppdu_info.rx_status.chan_freq == 0)) {
  1322. pdev->ppdu_info.rx_status.chan_freq =
  1323. pdev->mon_chan_freq;
  1324. }
  1325. dp_rx_mon_dest_process(soc, mac_id, quota);
  1326. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1327. }
  1328. }
  1329. return;
  1330. }
  1331. /*
  1332. * dp_rx_mon_status_srng_process() - Process monitor status ring
  1333. * post the status ring buffer to Rx status Queue for later
  1334. * processing when status ring is filled with status TLV.
  1335. * Allocate a new buffer to status ring if the filled buffer
  1336. * is posted.
  1337. *
  1338. * @soc: core txrx main context
  1339. * @mac_id: mac_id which is one of 3 mac_ids
  1340. * @quota: No. of ring entry that can be serviced in one shot.
  1341. * Return: uint32_t: No. of ring entry that is processed.
  1342. */
  1343. static inline uint32_t
  1344. dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
  1345. uint32_t quota)
  1346. {
  1347. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1348. hal_soc_handle_t hal_soc;
  1349. void *mon_status_srng;
  1350. void *rxdma_mon_status_ring_entry;
  1351. QDF_STATUS status;
  1352. uint32_t work_done = 0;
  1353. mon_status_srng = soc->rxdma_mon_status_ring[mac_id].hal_srng;
  1354. qdf_assert(mon_status_srng);
  1355. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  1356. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1357. "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
  1358. __func__, __LINE__, mon_status_srng);
  1359. return work_done;
  1360. }
  1361. hal_soc = soc->hal_soc;
  1362. qdf_assert(hal_soc);
  1363. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
  1364. goto done;
  1365. /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
  1366. * BUFFER_ADDR_INFO STRUCT
  1367. */
  1368. while (qdf_likely((rxdma_mon_status_ring_entry =
  1369. hal_srng_src_peek(hal_soc, mon_status_srng))
  1370. && quota--)) {
  1371. uint32_t rx_buf_cookie;
  1372. qdf_nbuf_t status_nbuf;
  1373. struct dp_rx_desc *rx_desc;
  1374. uint8_t *status_buf;
  1375. qdf_dma_addr_t paddr;
  1376. uint64_t buf_addr;
  1377. buf_addr =
  1378. (HAL_RX_BUFFER_ADDR_31_0_GET(
  1379. rxdma_mon_status_ring_entry) |
  1380. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
  1381. rxdma_mon_status_ring_entry)) << 32));
  1382. if (qdf_likely(buf_addr)) {
  1383. rx_buf_cookie =
  1384. HAL_RX_BUF_COOKIE_GET(
  1385. rxdma_mon_status_ring_entry);
  1386. rx_desc = dp_rx_cookie_2_va_mon_status(soc,
  1387. rx_buf_cookie);
  1388. qdf_assert(rx_desc);
  1389. status_nbuf = rx_desc->nbuf;
  1390. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  1391. QDF_DMA_FROM_DEVICE);
  1392. status_buf = qdf_nbuf_data(status_nbuf);
  1393. status = hal_get_rx_status_done(status_buf);
  1394. if (status != QDF_STATUS_SUCCESS) {
  1395. uint32_t hp, tp;
  1396. hal_get_sw_hptp(hal_soc, mon_status_srng,
  1397. &tp, &hp);
  1398. dp_info_rl("tlv tag status error hp:%u, tp:%u",
  1399. hp, tp);
  1400. pdev->rx_mon_stats.tlv_tag_status_err++;
  1401. /* WAR for missing status: Skip status entry */
  1402. hal_srng_src_get_next(hal_soc, mon_status_srng);
  1403. continue;
  1404. }
  1405. qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
  1406. qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
  1407. QDF_DMA_FROM_DEVICE);
  1408. /* Put the status_nbuf to queue */
  1409. qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
  1410. } else {
  1411. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1412. union dp_rx_desc_list_elem_t *tail = NULL;
  1413. struct rx_desc_pool *rx_desc_pool;
  1414. uint32_t num_alloc_desc;
  1415. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1416. num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
  1417. rx_desc_pool,
  1418. 1,
  1419. &desc_list,
  1420. &tail);
  1421. /*
  1422. * No free descriptors available
  1423. */
  1424. if (qdf_unlikely(num_alloc_desc == 0)) {
  1425. work_done++;
  1426. break;
  1427. }
  1428. rx_desc = &desc_list->rx_desc;
  1429. }
  1430. status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
  1431. /*
  1432. * qdf_nbuf alloc or map failed,
  1433. * free the dp rx desc to free list,
  1434. * fill in NULL dma address at current HP entry,
  1435. * keep HP in mon_status_ring unchanged,
  1436. * wait next time dp_rx_mon_status_srng_process
  1437. * to fill in buffer at current HP.
  1438. */
  1439. if (qdf_unlikely(!status_nbuf)) {
  1440. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1441. union dp_rx_desc_list_elem_t *tail = NULL;
  1442. struct rx_desc_pool *rx_desc_pool;
  1443. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1444. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1445. "%s: fail to allocate or map qdf_nbuf",
  1446. __func__);
  1447. dp_rx_add_to_free_desc_list(&desc_list,
  1448. &tail, rx_desc);
  1449. dp_rx_add_desc_list_to_free_list(soc, &desc_list,
  1450. &tail, mac_id, rx_desc_pool);
  1451. hal_rxdma_buff_addr_info_set(
  1452. rxdma_mon_status_ring_entry,
  1453. 0, 0, HAL_RX_BUF_RBM_SW3_BM);
  1454. work_done++;
  1455. break;
  1456. }
  1457. paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
  1458. rx_desc->nbuf = status_nbuf;
  1459. rx_desc->in_use = 1;
  1460. hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
  1461. paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
  1462. hal_srng_src_get_next(hal_soc, mon_status_srng);
  1463. work_done++;
  1464. }
  1465. done:
  1466. hal_srng_access_end(hal_soc, mon_status_srng);
  1467. return work_done;
  1468. }
  1469. /*
  1470. * dp_rx_mon_status_process() - Process monitor status ring and
  1471. * TLV in status ring.
  1472. *
  1473. * @soc: core txrx main context
  1474. * @mac_id: mac_id which is one of 3 mac_ids
  1475. * @quota: No. of ring entry that can be serviced in one shot.
  1476. * Return: uint32_t: No. of ring entry that is processed.
  1477. */
  1478. static inline uint32_t
  1479. dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  1480. uint32_t work_done;
  1481. work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
  1482. quota -= work_done;
  1483. dp_rx_mon_status_process_tlv(soc, mac_id, quota);
  1484. return work_done;
  1485. }
  1486. /**
  1487. * dp_mon_process() - Main monitor mode processing roution.
  1488. * This call monitor status ring process then monitor
  1489. * destination ring process.
  1490. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  1491. * @soc: core txrx main context
  1492. * @mac_id: mac_id which is one of 3 mac_ids
  1493. * @quota: No. of status ring entry that can be serviced in one shot.
  1494. * Return: uint32_t: No. of ring entry that is processed.
  1495. */
  1496. uint32_t
  1497. dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  1498. return dp_rx_mon_status_process(soc, mac_id, quota);
  1499. }
  1500. /**
  1501. * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
  1502. * @pdev: core txrx pdev context
  1503. * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
  1504. *
  1505. * This function will detach DP RX status ring from
  1506. * main device context. will free DP Rx resources for
  1507. * status ring
  1508. *
  1509. * Return: QDF_STATUS_SUCCESS: success
  1510. * QDF_STATUS_E_RESOURCES: Error return
  1511. */
  1512. QDF_STATUS
  1513. dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
  1514. {
  1515. struct dp_soc *soc = pdev->soc;
  1516. struct rx_desc_pool *rx_desc_pool;
  1517. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1518. if (rx_desc_pool->pool_size != 0) {
  1519. if (!dp_is_soc_reinit(soc))
  1520. dp_rx_desc_nbuf_and_pool_free(soc, mac_id,
  1521. rx_desc_pool);
  1522. else
  1523. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1524. }
  1525. return QDF_STATUS_SUCCESS;
  1526. }
  1527. /*
  1528. * dp_rx_buffers_replenish() - replenish monitor status ring with
  1529. * rx nbufs called during dp rx
  1530. * monitor status ring initialization
  1531. *
  1532. * @soc: core txrx main context
  1533. * @mac_id: mac_id which is one of 3 mac_ids
  1534. * @dp_rxdma_srng: dp monitor status circular ring
  1535. * @rx_desc_pool; Pointer to Rx descriptor pool
  1536. * @num_req_buffers: number of buffer to be replenished
  1537. * @desc_list: list of descs if called from dp rx monitor status
  1538. * process or NULL during dp rx initialization or
  1539. * out of buffer interrupt
  1540. * @tail: tail of descs list
  1541. * @owner: who owns the nbuf (host, NSS etc...)
  1542. * Return: return success or failure
  1543. */
  1544. static inline
  1545. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  1546. uint32_t mac_id,
  1547. struct dp_srng *dp_rxdma_srng,
  1548. struct rx_desc_pool *rx_desc_pool,
  1549. uint32_t num_req_buffers,
  1550. union dp_rx_desc_list_elem_t **desc_list,
  1551. union dp_rx_desc_list_elem_t **tail,
  1552. uint8_t owner)
  1553. {
  1554. uint32_t num_alloc_desc;
  1555. uint16_t num_desc_to_free = 0;
  1556. uint32_t num_entries_avail;
  1557. uint32_t count = 0;
  1558. int sync_hw_ptr = 1;
  1559. qdf_dma_addr_t paddr;
  1560. qdf_nbuf_t rx_netbuf;
  1561. void *rxdma_ring_entry;
  1562. union dp_rx_desc_list_elem_t *next;
  1563. void *rxdma_srng;
  1564. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(dp_soc, mac_id);
  1565. rxdma_srng = dp_rxdma_srng->hal_srng;
  1566. qdf_assert(rxdma_srng);
  1567. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1568. "[%s][%d] requested %d buffers for replenish",
  1569. __func__, __LINE__, num_req_buffers);
  1570. /*
  1571. * if desc_list is NULL, allocate the descs from freelist
  1572. */
  1573. if (!(*desc_list)) {
  1574. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  1575. rx_desc_pool,
  1576. num_req_buffers,
  1577. desc_list,
  1578. tail);
  1579. if (!num_alloc_desc) {
  1580. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1581. "[%s][%d] no free rx_descs in freelist",
  1582. __func__, __LINE__);
  1583. return QDF_STATUS_E_NOMEM;
  1584. }
  1585. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1586. "[%s][%d] %d rx desc allocated", __func__, __LINE__,
  1587. num_alloc_desc);
  1588. num_req_buffers = num_alloc_desc;
  1589. }
  1590. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  1591. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  1592. rxdma_srng, sync_hw_ptr);
  1593. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1594. "[%s][%d] no of available entries in rxdma ring: %d",
  1595. __func__, __LINE__, num_entries_avail);
  1596. if (num_entries_avail < num_req_buffers) {
  1597. num_desc_to_free = num_req_buffers - num_entries_avail;
  1598. num_req_buffers = num_entries_avail;
  1599. }
  1600. while (count < num_req_buffers) {
  1601. rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
  1602. /*
  1603. * qdf_nbuf alloc or map failed,
  1604. * keep HP in mon_status_ring unchanged,
  1605. * wait dp_rx_mon_status_srng_process
  1606. * to fill in buffer at current HP.
  1607. */
  1608. if (qdf_unlikely(!rx_netbuf)) {
  1609. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1610. "%s: qdf_nbuf allocate or map fail, count %d",
  1611. __func__, count);
  1612. break;
  1613. }
  1614. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  1615. next = (*desc_list)->next;
  1616. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  1617. rxdma_srng);
  1618. if (qdf_unlikely(!rxdma_ring_entry)) {
  1619. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1620. "[%s][%d] rxdma_ring_entry is NULL, count - %d",
  1621. __func__, __LINE__, count);
  1622. qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
  1623. QDF_DMA_FROM_DEVICE);
  1624. qdf_nbuf_free(rx_netbuf);
  1625. break;
  1626. }
  1627. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  1628. (*desc_list)->rx_desc.in_use = 1;
  1629. count++;
  1630. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  1631. (*desc_list)->rx_desc.cookie, owner);
  1632. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1633. "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
  1634. paddr=%pK",
  1635. __func__, __LINE__, &(*desc_list)->rx_desc,
  1636. (*desc_list)->rx_desc.cookie, rx_netbuf,
  1637. (void *)paddr);
  1638. *desc_list = next;
  1639. }
  1640. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  1641. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1642. "successfully replenished %d buffers", num_req_buffers);
  1643. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1644. "%d rx desc added back to free list", num_desc_to_free);
  1645. /*
  1646. * add any available free desc back to the free list
  1647. */
  1648. if (*desc_list) {
  1649. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  1650. mac_id, rx_desc_pool);
  1651. }
  1652. return QDF_STATUS_SUCCESS;
  1653. }
  1654. /**
  1655. * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
  1656. * @pdev: core txrx pdev context
  1657. * @ring_id: ring number
  1658. * This function will attach a DP RX monitor status ring into pDEV
  1659. * and replenish monitor status ring with buffer.
  1660. *
  1661. * Return: QDF_STATUS_SUCCESS: success
  1662. * QDF_STATUS_E_RESOURCES: Error return
  1663. */
  1664. QDF_STATUS
  1665. dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
  1666. struct dp_soc *soc = pdev->soc;
  1667. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1668. union dp_rx_desc_list_elem_t *tail = NULL;
  1669. struct dp_srng *mon_status_ring;
  1670. uint32_t num_entries;
  1671. uint32_t i;
  1672. struct rx_desc_pool *rx_desc_pool;
  1673. QDF_STATUS status;
  1674. mon_status_ring = &soc->rxdma_mon_status_ring[ring_id];
  1675. num_entries = mon_status_ring->num_entries;
  1676. rx_desc_pool = &soc->rx_desc_status[ring_id];
  1677. dp_info("Mon RX Status Pool[%d] entries=%d",
  1678. ring_id, num_entries);
  1679. status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
  1680. rx_desc_pool);
  1681. if (!QDF_IS_STATUS_SUCCESS(status))
  1682. return status;
  1683. dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
  1684. status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
  1685. mon_status_ring,
  1686. rx_desc_pool,
  1687. num_entries,
  1688. &desc_list, &tail,
  1689. HAL_RX_BUF_RBM_SW3_BM);
  1690. if (!QDF_IS_STATUS_SUCCESS(status))
  1691. return status;
  1692. qdf_nbuf_queue_init(&pdev->rx_status_q);
  1693. qdf_nbuf_queue_init(&pdev->rx_ppdu_buf_q);
  1694. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1695. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  1696. sizeof(pdev->ppdu_info.rx_status));
  1697. qdf_mem_zero(&pdev->rx_mon_stats,
  1698. sizeof(pdev->rx_mon_stats));
  1699. dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
  1700. &pdev->rx_mon_stats);
  1701. for (i = 0; i < MAX_MU_USERS; i++) {
  1702. qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
  1703. pdev->is_mpdu_hdr[i] = true;
  1704. }
  1705. qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
  1706. pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
  1707. return QDF_STATUS_SUCCESS;
  1708. }