dp_rx_mon_status.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  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
  35. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  36. uint32_t mac_id,
  37. struct dp_srng *dp_rxdma_srng,
  38. struct rx_desc_pool *rx_desc_pool,
  39. uint32_t num_req_buffers,
  40. union dp_rx_desc_list_elem_t **desc_list,
  41. union dp_rx_desc_list_elem_t **tail,
  42. uint8_t owner);
  43. static inline void
  44. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  45. struct hal_rx_ppdu_info *ppdu_info,
  46. struct cdp_rx_indication_ppdu *cdp_rx_ppdu);
  47. #ifndef QCA_SUPPORT_FULL_MON
  48. /**
  49. * dp_rx_mon_process () - Core brain processing for monitor mode
  50. *
  51. * This API processes monitor destination ring followed by monitor status ring
  52. * Called from bottom half (tasklet/NET_RX_SOFTIRQ)
  53. *
  54. * @soc: datapath soc context
  55. * @int_ctx: interrupt context
  56. * @mac_id: mac_id on which interrupt is received
  57. * @quota: Number of status ring entry that can be serviced in one shot.
  58. *
  59. * @Return: Number of reaped status ring entries
  60. */
  61. static inline uint32_t
  62. dp_rx_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  63. uint32_t mac_id, uint32_t quota)
  64. {
  65. return quota;
  66. }
  67. #endif
  68. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  69. #include "dp_rx_mon_feature.h"
  70. #else
  71. static QDF_STATUS
  72. dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  73. struct hal_rx_ppdu_info *ppdu_info)
  74. {
  75. return QDF_STATUS_SUCCESS;
  76. }
  77. static void
  78. dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
  79. qdf_nbuf_t status_nbuf,
  80. struct hal_rx_ppdu_info *ppdu_info,
  81. bool *nbuf_used)
  82. {
  83. }
  84. #endif
  85. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  86. #include "dp_rx_mon_feature.h"
  87. #else
  88. static QDF_STATUS
  89. dp_send_ack_frame_to_stack(struct dp_soc *soc,
  90. struct dp_pdev *pdev,
  91. struct hal_rx_ppdu_info *ppdu_info)
  92. {
  93. return QDF_STATUS_SUCCESS;
  94. }
  95. #endif
  96. #ifdef FEATURE_PERPKT_INFO
  97. static inline void
  98. dp_rx_populate_rx_rssi_chain(struct hal_rx_ppdu_info *ppdu_info,
  99. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  100. {
  101. uint8_t chain, bw;
  102. int8_t rssi;
  103. for (chain = 0; chain < SS_COUNT; chain++) {
  104. for (bw = 0; bw < MAX_BW; bw++) {
  105. rssi = ppdu_info->rx_status.rssi_chain[chain][bw];
  106. if (rssi != DP_RSSI_INVAL)
  107. cdp_rx_ppdu->rssi_chain[chain][bw] = rssi;
  108. else
  109. cdp_rx_ppdu->rssi_chain[chain][bw] = 0;
  110. }
  111. }
  112. }
  113. /*
  114. * dp_rx_populate_su_evm_details() - Populate su evm info
  115. * @ppdu_info: ppdu info structure from ppdu ring
  116. * @cdp_rx_ppdu: rx ppdu indication structure
  117. */
  118. static inline void
  119. dp_rx_populate_su_evm_details(struct hal_rx_ppdu_info *ppdu_info,
  120. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  121. {
  122. uint8_t pilot_evm;
  123. uint8_t nss_count;
  124. uint8_t pilot_count;
  125. nss_count = ppdu_info->evm_info.nss_count;
  126. pilot_count = ppdu_info->evm_info.pilot_count;
  127. if ((nss_count * pilot_count) > DP_RX_MAX_SU_EVM_COUNT) {
  128. qdf_err("pilot evm count is more than expected");
  129. return;
  130. }
  131. cdp_rx_ppdu->evm_info.pilot_count = pilot_count;
  132. cdp_rx_ppdu->evm_info.nss_count = nss_count;
  133. /* Populate evm for pilot_evm = nss_count*pilot_count */
  134. for (pilot_evm = 0; pilot_evm < nss_count * pilot_count; pilot_evm++) {
  135. cdp_rx_ppdu->evm_info.pilot_evm[pilot_evm] =
  136. ppdu_info->evm_info.pilot_evm[pilot_evm];
  137. }
  138. }
  139. /**
  140. * dp_rx_inc_rusize_cnt() - increment pdev stats based on RU size
  141. * @pdev: pdev ctx
  142. * @rx_user_status: mon rx user status
  143. *
  144. * Return: bool
  145. */
  146. static inline bool
  147. dp_rx_inc_rusize_cnt(struct dp_pdev *pdev,
  148. struct mon_rx_user_status *rx_user_status)
  149. {
  150. uint32_t ru_size;
  151. bool is_data;
  152. ru_size = rx_user_status->ofdma_ru_size;
  153. if (dp_is_subtype_data(rx_user_status->frame_control)) {
  154. DP_STATS_INC(pdev,
  155. ul_ofdma.data_rx_ru_size[ru_size], 1);
  156. is_data = true;
  157. } else {
  158. DP_STATS_INC(pdev,
  159. ul_ofdma.nondata_rx_ru_size[ru_size], 1);
  160. is_data = false;
  161. }
  162. return is_data;
  163. }
  164. /**
  165. * dp_rx_populate_cdp_indication_ppdu_user() - Populate per user cdp indication
  166. * @pdev: pdev ctx
  167. * @ppdu_info: ppdu info structure from ppdu ring
  168. * @cdp_rx_ppdu: Rx PPDU indication structure
  169. *
  170. * Return: none
  171. */
  172. static inline void
  173. dp_rx_populate_cdp_indication_ppdu_user(struct dp_pdev *pdev,
  174. struct hal_rx_ppdu_info *ppdu_info,
  175. struct cdp_rx_indication_ppdu
  176. *cdp_rx_ppdu)
  177. {
  178. struct dp_peer *peer;
  179. struct dp_soc *soc = pdev->soc;
  180. struct dp_ast_entry *ast_entry;
  181. uint32_t ast_index;
  182. int i;
  183. struct mon_rx_user_status *rx_user_status;
  184. struct cdp_rx_stats_ppdu_user *rx_stats_peruser;
  185. int ru_size;
  186. bool is_data = false;
  187. uint32_t num_users;
  188. num_users = ppdu_info->com_info.num_users;
  189. for (i = 0; i < num_users; i++) {
  190. if (i > OFDMA_NUM_USERS)
  191. return;
  192. rx_user_status = &ppdu_info->rx_user_status[i];
  193. rx_stats_peruser = &cdp_rx_ppdu->user[i];
  194. ast_index = rx_user_status->ast_index;
  195. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  196. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  197. continue;
  198. }
  199. ast_entry = soc->ast_table[ast_index];
  200. if (!ast_entry || ast_entry->peer_id == HTT_INVALID_PEER) {
  201. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  202. continue;
  203. }
  204. peer = dp_peer_get_ref_by_id(soc, ast_entry->peer_id,
  205. DP_MOD_ID_RX_PPDU_STATS);
  206. if (!peer) {
  207. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  208. continue;
  209. }
  210. rx_stats_peruser->first_data_seq_ctrl =
  211. rx_user_status->first_data_seq_ctrl;
  212. rx_stats_peruser->frame_control_info_valid =
  213. rx_user_status->frame_control_info_valid;
  214. rx_stats_peruser->frame_control =
  215. rx_user_status->frame_control;
  216. rx_stats_peruser->tcp_msdu_count =
  217. rx_user_status->tcp_msdu_count;
  218. rx_stats_peruser->udp_msdu_count =
  219. rx_user_status->udp_msdu_count;
  220. rx_stats_peruser->other_msdu_count =
  221. rx_user_status->other_msdu_count;
  222. rx_stats_peruser->num_msdu =
  223. rx_stats_peruser->tcp_msdu_count +
  224. rx_stats_peruser->udp_msdu_count +
  225. rx_stats_peruser->other_msdu_count;
  226. rx_stats_peruser->preamble_type =
  227. rx_user_status->preamble_type;
  228. rx_stats_peruser->mpdu_cnt_fcs_ok =
  229. rx_user_status->mpdu_cnt_fcs_ok;
  230. rx_stats_peruser->mpdu_cnt_fcs_err =
  231. rx_user_status->mpdu_cnt_fcs_err;
  232. qdf_mem_copy(&rx_stats_peruser->mpdu_fcs_ok_bitmap,
  233. &rx_user_status->mpdu_fcs_ok_bitmap,
  234. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
  235. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  236. rx_stats_peruser->mpdu_ok_byte_count =
  237. rx_user_status->mpdu_ok_byte_count;
  238. rx_stats_peruser->mpdu_err_byte_count =
  239. rx_user_status->mpdu_err_byte_count;
  240. cdp_rx_ppdu->num_mpdu += rx_user_status->mpdu_cnt_fcs_ok;
  241. cdp_rx_ppdu->num_msdu += rx_stats_peruser->num_msdu;
  242. rx_stats_peruser->retries =
  243. CDP_FC_IS_RETRY_SET(rx_stats_peruser->frame_control) ?
  244. rx_stats_peruser->mpdu_cnt_fcs_ok : 0;
  245. if (rx_stats_peruser->mpdu_cnt_fcs_ok > 1)
  246. rx_stats_peruser->is_ampdu = 1;
  247. else
  248. rx_stats_peruser->is_ampdu = 0;
  249. rx_stats_peruser->tid = ppdu_info->rx_status.tid;
  250. qdf_mem_copy(rx_stats_peruser->mac_addr,
  251. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  252. rx_stats_peruser->peer_id = peer->peer_id;
  253. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  254. rx_stats_peruser->vdev_id = peer->vdev->vdev_id;
  255. rx_stats_peruser->mu_ul_info_valid = 0;
  256. dp_peer_unref_delete(peer, DP_MOD_ID_RX_PPDU_STATS);
  257. if (cdp_rx_ppdu->u.ppdu_type == HAL_RX_TYPE_MU_OFDMA ||
  258. cdp_rx_ppdu->u.ppdu_type == HAL_RX_TYPE_MU_MIMO) {
  259. if (rx_user_status->mu_ul_info_valid) {
  260. rx_stats_peruser->nss = rx_user_status->nss;
  261. rx_stats_peruser->mcs = rx_user_status->mcs;
  262. rx_stats_peruser->mu_ul_info_valid =
  263. rx_user_status->mu_ul_info_valid;
  264. rx_stats_peruser->ofdma_ru_start_index =
  265. rx_user_status->ofdma_ru_start_index;
  266. rx_stats_peruser->ofdma_ru_width =
  267. rx_user_status->ofdma_ru_width;
  268. rx_stats_peruser->user_index = i;
  269. ru_size = rx_user_status->ofdma_ru_size;
  270. /*
  271. * max RU size will be equal to
  272. * HTT_UL_OFDMA_V0_RU_SIZE_RU_996x2
  273. */
  274. if (ru_size >= OFDMA_NUM_RU_SIZE) {
  275. dp_err("invalid ru_size %d\n",
  276. ru_size);
  277. return;
  278. }
  279. is_data = dp_rx_inc_rusize_cnt(pdev,
  280. rx_user_status);
  281. }
  282. if (is_data) {
  283. /* counter to get number of MU OFDMA */
  284. pdev->stats.ul_ofdma.data_rx_ppdu++;
  285. pdev->stats.ul_ofdma.data_users[num_users]++;
  286. }
  287. }
  288. }
  289. }
  290. /**
  291. * dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
  292. * @pdev: pdev ctx
  293. * @ppdu_info: ppdu info structure from ppdu ring
  294. * @cdp_rx_ppdu: Rx PPDU indication structure
  295. *
  296. * Return: none
  297. */
  298. static inline void
  299. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  300. struct hal_rx_ppdu_info *ppdu_info,
  301. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  302. {
  303. struct dp_peer *peer;
  304. struct dp_soc *soc = pdev->soc;
  305. struct dp_ast_entry *ast_entry;
  306. uint32_t ast_index;
  307. uint32_t i;
  308. cdp_rx_ppdu->first_data_seq_ctrl =
  309. ppdu_info->rx_status.first_data_seq_ctrl;
  310. cdp_rx_ppdu->frame_ctrl =
  311. ppdu_info->rx_status.frame_control;
  312. cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
  313. cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
  314. cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
  315. cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
  316. /* num mpdu is consolidated and added together in num user loop */
  317. cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
  318. /* num msdu is consolidated and added together in num user loop */
  319. cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
  320. cdp_rx_ppdu->udp_msdu_count +
  321. cdp_rx_ppdu->other_msdu_count);
  322. cdp_rx_ppdu->retries = CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl) ?
  323. ppdu_info->com_info.mpdu_cnt_fcs_ok : 0;
  324. if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
  325. cdp_rx_ppdu->is_ampdu = 1;
  326. else
  327. cdp_rx_ppdu->is_ampdu = 0;
  328. cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
  329. ast_index = ppdu_info->rx_status.ast_index;
  330. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  331. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  332. cdp_rx_ppdu->num_users = 0;
  333. goto end;
  334. }
  335. ast_entry = soc->ast_table[ast_index];
  336. if (!ast_entry || ast_entry->peer_id == HTT_INVALID_PEER) {
  337. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  338. cdp_rx_ppdu->num_users = 0;
  339. goto end;
  340. }
  341. peer = dp_peer_get_ref_by_id(soc, ast_entry->peer_id,
  342. DP_MOD_ID_RX_PPDU_STATS);
  343. if (!peer) {
  344. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  345. cdp_rx_ppdu->num_users = 0;
  346. goto end;
  347. }
  348. qdf_mem_copy(cdp_rx_ppdu->mac_addr,
  349. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  350. cdp_rx_ppdu->peer_id = peer->peer_id;
  351. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  352. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  353. cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
  354. cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
  355. cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
  356. cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
  357. cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
  358. if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
  359. (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
  360. cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
  361. else
  362. cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
  363. cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
  364. cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
  365. cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
  366. QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
  367. cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
  368. cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
  369. cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
  370. cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
  371. cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
  372. cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
  373. cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
  374. dp_rx_populate_rx_rssi_chain(ppdu_info, cdp_rx_ppdu);
  375. dp_rx_populate_su_evm_details(ppdu_info, cdp_rx_ppdu);
  376. cdp_rx_ppdu->rx_antenna = ppdu_info->rx_status.rx_antenna;
  377. cdp_rx_ppdu->nf = ppdu_info->rx_status.chan_noise_floor;
  378. for (i = 0; i < MAX_CHAIN; i++)
  379. cdp_rx_ppdu->per_chain_rssi[i] = ppdu_info->rx_status.rssi[i];
  380. cdp_rx_ppdu->is_mcast_bcast = ppdu_info->nac_info.mcast_bcast;
  381. cdp_rx_ppdu->num_users = ppdu_info->com_info.num_users;
  382. cdp_rx_ppdu->num_mpdu = 0;
  383. cdp_rx_ppdu->num_msdu = 0;
  384. dp_rx_populate_cdp_indication_ppdu_user(pdev, ppdu_info, cdp_rx_ppdu);
  385. dp_peer_unref_delete(peer, DP_MOD_ID_RX_PPDU_STATS);
  386. return;
  387. end:
  388. dp_rx_populate_cfr_non_assoc_sta(pdev, ppdu_info, cdp_rx_ppdu);
  389. }
  390. #else
  391. static inline void
  392. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  393. struct hal_rx_ppdu_info *ppdu_info,
  394. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  395. {
  396. }
  397. #endif
  398. /**
  399. * dp_rx_stats_update() - Update per-peer statistics
  400. * @soc: Datapath SOC handle
  401. * @peer: Datapath peer handle
  402. * @ppdu: PPDU Descriptor
  403. *
  404. * Return: None
  405. */
  406. #ifdef FEATURE_PERPKT_INFO
  407. static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
  408. struct cdp_rx_indication_ppdu *ppdu,
  409. uint32_t user)
  410. {
  411. uint32_t ratekbps = 0;
  412. uint32_t ppdu_rx_rate = 0;
  413. uint32_t nss = 0;
  414. uint8_t mcs = 0;
  415. uint32_t rix;
  416. uint16_t ratecode;
  417. struct cdp_rx_stats_ppdu_user *ppdu_user = NULL;
  418. if (!peer || !ppdu)
  419. return;
  420. if (ppdu->u.ppdu_type != HAL_RX_TYPE_SU) {
  421. ppdu_user = &ppdu->user[user];
  422. if (ppdu_user->nss == 0)
  423. nss = 0;
  424. else
  425. nss = ppdu_user->nss - 1;
  426. mcs = ppdu_user->mcs;
  427. } else {
  428. if (ppdu->u.nss == 0)
  429. nss = 0;
  430. else
  431. nss = ppdu->u.nss - 1;
  432. mcs = ppdu->u.mcs;
  433. }
  434. ratekbps = dp_getrateindex(ppdu->u.gi,
  435. mcs,
  436. nss,
  437. ppdu->u.preamble,
  438. ppdu->u.bw,
  439. &rix,
  440. &ratecode);
  441. if (!ratekbps)
  442. return;
  443. ppdu->rix = rix;
  444. DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
  445. dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
  446. ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
  447. DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
  448. ppdu->rx_ratekbps = ratekbps;
  449. ppdu->rx_ratecode = ratecode;
  450. if (peer->vdev)
  451. peer->vdev->stats.rx.last_rx_rate = ratekbps;
  452. }
  453. static void dp_rx_stats_update(struct dp_pdev *pdev,
  454. struct cdp_rx_indication_ppdu *ppdu)
  455. {
  456. struct dp_soc *soc = NULL;
  457. uint8_t mcs, preamble, ac = 0, nss, ppdu_type;
  458. uint16_t num_msdu;
  459. uint8_t pkt_bw_offset;
  460. struct dp_peer *peer;
  461. struct cdp_rx_stats_ppdu_user *ppdu_user;
  462. uint32_t i;
  463. enum cdp_mu_packet_type mu_pkt_type;
  464. if (pdev)
  465. soc = pdev->soc;
  466. else
  467. return;
  468. if (!soc || soc->process_rx_status)
  469. return;
  470. preamble = ppdu->u.preamble;
  471. ppdu_type = ppdu->u.ppdu_type;
  472. for (i = 0; i < ppdu->num_users && i < CDP_MU_MAX_USERS; i++) {
  473. peer = NULL;
  474. ppdu_user = &ppdu->user[i];
  475. peer = dp_peer_get_ref_by_id(soc, ppdu_user->peer_id,
  476. DP_MOD_ID_RX_PPDU_STATS);
  477. if (!peer)
  478. peer = pdev->invalid_peer;
  479. if (ppdu_type == HAL_RX_TYPE_SU) {
  480. mcs = ppdu->u.mcs;
  481. nss = ppdu->u.nss;
  482. } else {
  483. mcs = ppdu_user->mcs;
  484. nss = ppdu_user->nss;
  485. }
  486. num_msdu = ppdu_user->num_msdu;
  487. switch (ppdu->u.bw) {
  488. case CMN_BW_20MHZ:
  489. pkt_bw_offset = PKT_BW_GAIN_20MHZ;
  490. break;
  491. case CMN_BW_40MHZ:
  492. pkt_bw_offset = PKT_BW_GAIN_40MHZ;
  493. break;
  494. case CMN_BW_80MHZ:
  495. pkt_bw_offset = PKT_BW_GAIN_80MHZ;
  496. break;
  497. case CMN_BW_160MHZ:
  498. pkt_bw_offset = PKT_BW_GAIN_160MHZ;
  499. break;
  500. default:
  501. pkt_bw_offset = 0;
  502. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  503. "Invalid BW index = %d", ppdu->u.bw);
  504. }
  505. DP_STATS_UPD(peer, rx.rssi, (ppdu->rssi + pkt_bw_offset));
  506. if (peer->stats.rx.avg_rssi == INVALID_RSSI)
  507. peer->stats.rx.avg_rssi =
  508. CDP_RSSI_IN(peer->stats.rx.rssi);
  509. else
  510. CDP_RSSI_UPDATE_AVG(peer->stats.rx.avg_rssi,
  511. peer->stats.rx.rssi);
  512. if ((preamble == DOT11_A) || (preamble == DOT11_B))
  513. nss = 1;
  514. if (ppdu_type == HAL_RX_TYPE_SU) {
  515. if (nss) {
  516. DP_STATS_INC(peer, rx.nss[nss - 1], num_msdu);
  517. DP_STATS_INC(peer, rx.ppdu_nss[nss - 1], 1);
  518. }
  519. DP_STATS_INC(peer, rx.mpdu_cnt_fcs_ok,
  520. ppdu_user->mpdu_cnt_fcs_ok);
  521. DP_STATS_INC(peer, rx.mpdu_cnt_fcs_err,
  522. ppdu_user->mpdu_cnt_fcs_err);
  523. }
  524. if (ppdu_type >= HAL_RX_TYPE_MU_MIMO &&
  525. ppdu_type <= HAL_RX_TYPE_MU_OFDMA) {
  526. if (ppdu_type == HAL_RX_TYPE_MU_MIMO)
  527. mu_pkt_type = RX_TYPE_MU_MIMO;
  528. else
  529. mu_pkt_type = RX_TYPE_MU_OFDMA;
  530. if (nss) {
  531. DP_STATS_INC(peer, rx.nss[nss - 1], num_msdu);
  532. DP_STATS_INC(peer,
  533. rx.rx_mu[mu_pkt_type].ppdu_nss[nss - 1],
  534. 1);
  535. }
  536. DP_STATS_INC(peer,
  537. rx.rx_mu[mu_pkt_type].mpdu_cnt_fcs_ok,
  538. ppdu_user->mpdu_cnt_fcs_ok);
  539. DP_STATS_INC(peer,
  540. rx.rx_mu[mu_pkt_type].mpdu_cnt_fcs_err,
  541. ppdu_user->mpdu_cnt_fcs_err);
  542. }
  543. DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
  544. DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
  545. DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type],
  546. num_msdu);
  547. DP_STATS_INC(peer, rx.ppdu_cnt[ppdu->u.ppdu_type], 1);
  548. DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu,
  549. ppdu_user->is_ampdu);
  550. DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu,
  551. !(ppdu_user->is_ampdu));
  552. DP_STATS_UPD(peer, rx.rx_rate, mcs);
  553. DP_STATS_INCC(peer,
  554. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  555. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  556. DP_STATS_INCC(peer,
  557. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  558. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  559. DP_STATS_INCC(peer,
  560. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  561. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  562. DP_STATS_INCC(peer,
  563. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  564. ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
  565. DP_STATS_INCC(peer,
  566. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  567. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  568. DP_STATS_INCC(peer,
  569. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  570. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  571. DP_STATS_INCC(peer,
  572. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  573. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  574. DP_STATS_INCC(peer,
  575. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  576. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  577. DP_STATS_INCC(peer,
  578. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  579. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  580. DP_STATS_INCC(peer,
  581. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  582. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  583. DP_STATS_INCC(peer,
  584. rx.su_ax_ppdu_cnt.mcs_count[MAX_MCS - 1], 1,
  585. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX) &&
  586. (ppdu_type == HAL_RX_TYPE_SU)));
  587. DP_STATS_INCC(peer,
  588. rx.su_ax_ppdu_cnt.mcs_count[mcs], 1,
  589. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX) &&
  590. (ppdu_type == HAL_RX_TYPE_SU)));
  591. DP_STATS_INCC(peer,
  592. rx.rx_mu[RX_TYPE_MU_OFDMA].ppdu.mcs_count[MAX_MCS - 1],
  593. 1, ((mcs >= (MAX_MCS - 1)) &&
  594. (preamble == DOT11_AX) &&
  595. (ppdu_type == HAL_RX_TYPE_MU_OFDMA)));
  596. DP_STATS_INCC(peer,
  597. rx.rx_mu[RX_TYPE_MU_OFDMA].ppdu.mcs_count[mcs],
  598. 1, ((mcs < (MAX_MCS - 1)) &&
  599. (preamble == DOT11_AX) &&
  600. (ppdu_type == HAL_RX_TYPE_MU_OFDMA)));
  601. DP_STATS_INCC(peer,
  602. rx.rx_mu[RX_TYPE_MU_MIMO].ppdu.mcs_count[MAX_MCS - 1],
  603. 1, ((mcs >= (MAX_MCS - 1)) &&
  604. (preamble == DOT11_AX) &&
  605. (ppdu_type == HAL_RX_TYPE_MU_MIMO)));
  606. DP_STATS_INCC(peer,
  607. rx.rx_mu[RX_TYPE_MU_MIMO].ppdu.mcs_count[mcs],
  608. 1, ((mcs < (MAX_MCS - 1)) &&
  609. (preamble == DOT11_AX) &&
  610. (ppdu_type == HAL_RX_TYPE_MU_MIMO)));
  611. /*
  612. * If invalid TID, it could be a non-qos frame, hence do not
  613. * update any AC counters
  614. */
  615. ac = TID_TO_WME_AC(ppdu_user->tid);
  616. if (ppdu->tid != HAL_TID_INVALID)
  617. DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
  618. dp_peer_stats_notify(pdev, peer);
  619. DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
  620. if (peer == pdev->invalid_peer)
  621. continue;
  622. if (dp_is_subtype_data(ppdu->frame_ctrl))
  623. dp_rx_rate_stats_update(peer, ppdu, i);
  624. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  625. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  626. &peer->stats, ppdu->peer_id,
  627. UPDATE_PEER_STATS, pdev->pdev_id);
  628. #endif
  629. dp_peer_unref_delete(peer, DP_MOD_ID_RX_PPDU_STATS);
  630. }
  631. }
  632. #endif
  633. /**
  634. * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
  635. * @soc: core txrx main context
  636. * @pdev: pdev structure
  637. * @ppdu_info: structure for rx ppdu ring
  638. * @nbuf: QDF nbuf
  639. * @fcs_ok_mpdu_cnt: fcs passsed mpdu index
  640. * @deliver_frame: flag to deliver wdi event
  641. *
  642. * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
  643. * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
  644. */
  645. #ifdef FEATURE_PERPKT_INFO
  646. static inline QDF_STATUS
  647. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  648. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf,
  649. uint8_t fcs_ok_mpdu_cnt, bool deliver_frame)
  650. {
  651. uint16_t size = 0;
  652. struct ieee80211_frame *wh;
  653. uint32_t *nbuf_data;
  654. if (!ppdu_info->ppdu_msdu_info[fcs_ok_mpdu_cnt].first_msdu_payload)
  655. return QDF_STATUS_SUCCESS;
  656. /* For M_COPY mode only one msdu per ppdu is sent to upper layer*/
  657. if (pdev->mcopy_mode == M_COPY) {
  658. if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
  659. return QDF_STATUS_SUCCESS;
  660. }
  661. wh = (struct ieee80211_frame *)(ppdu_info->ppdu_msdu_info[fcs_ok_mpdu_cnt].first_msdu_payload + 4);
  662. size = (ppdu_info->ppdu_msdu_info[fcs_ok_mpdu_cnt].first_msdu_payload -
  663. qdf_nbuf_data(nbuf));
  664. if (qdf_nbuf_pull_head(nbuf, size) == NULL)
  665. return QDF_STATUS_SUCCESS;
  666. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  667. IEEE80211_FC0_TYPE_MGT) ||
  668. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  669. IEEE80211_FC0_TYPE_CTL)) {
  670. return QDF_STATUS_SUCCESS;
  671. }
  672. nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
  673. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  674. /* only retain RX MSDU payload in the skb */
  675. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - ppdu_info->ppdu_msdu_info[fcs_ok_mpdu_cnt].payload_len);
  676. if (deliver_frame) {
  677. pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
  678. dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
  679. nbuf, HTT_INVALID_PEER,
  680. WDI_NO_VAL, pdev->pdev_id);
  681. }
  682. return QDF_STATUS_E_ALREADY;
  683. }
  684. #else
  685. static inline QDF_STATUS
  686. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  687. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf,
  688. uint8_t fcs_ok_cnt, bool deliver_frame)
  689. {
  690. return QDF_STATUS_SUCCESS;
  691. }
  692. #endif
  693. /**
  694. * dp_rx_mcopy_handle_last_mpdu() - cache and delive last MPDU header in a
  695. * status buffer if MPDU end tlv is received in different buffer
  696. * @soc: core txrx main context
  697. * @pdev: pdev structure
  698. * @ppdu_info: structure for rx ppdu ring
  699. * @status_nbuf: QDF nbuf
  700. *
  701. * Return: void
  702. */
  703. #ifdef FEATURE_PERPKT_INFO
  704. static inline void
  705. dp_rx_mcopy_handle_last_mpdu(struct dp_soc *soc, struct dp_pdev *pdev,
  706. struct hal_rx_ppdu_info *ppdu_info,
  707. qdf_nbuf_t status_nbuf)
  708. {
  709. QDF_STATUS mcopy_status;
  710. qdf_nbuf_t nbuf_clone = NULL;
  711. /* If the MPDU end tlv and RX header are received in different buffers,
  712. * process the RX header based on fcs status.
  713. */
  714. if (pdev->mcopy_status_nbuf) {
  715. /* For M_COPY mode only one msdu per ppdu is sent to upper layer*/
  716. if (pdev->mcopy_mode == M_COPY) {
  717. if (pdev->m_copy_id.rx_ppdu_id ==
  718. ppdu_info->com_info.ppdu_id)
  719. goto end1;
  720. }
  721. if (ppdu_info->is_fcs_passed) {
  722. nbuf_clone = qdf_nbuf_clone(pdev->mcopy_status_nbuf);
  723. if (!nbuf_clone) {
  724. QDF_TRACE(QDF_MODULE_ID_TXRX,
  725. QDF_TRACE_LEVEL_ERROR,
  726. "Failed to clone nbuf",
  727. __func__, __LINE__);
  728. goto end1;
  729. }
  730. pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
  731. dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
  732. nbuf_clone,
  733. HTT_INVALID_PEER,
  734. WDI_NO_VAL, pdev->pdev_id);
  735. ppdu_info->is_fcs_passed = false;
  736. }
  737. end1:
  738. qdf_nbuf_free(pdev->mcopy_status_nbuf);
  739. pdev->mcopy_status_nbuf = NULL;
  740. }
  741. /* If the MPDU end tlv and RX header are received in different buffers,
  742. * preserve the RX header as the fcs status will be received in MPDU
  743. * end tlv in next buffer. So, cache the buffer to be processd in next
  744. * iteration
  745. */
  746. if ((ppdu_info->fcs_ok_cnt + ppdu_info->fcs_err_cnt) !=
  747. ppdu_info->com_info.mpdu_cnt) {
  748. pdev->mcopy_status_nbuf = qdf_nbuf_clone(status_nbuf);
  749. if (pdev->mcopy_status_nbuf) {
  750. mcopy_status = dp_rx_handle_mcopy_mode(
  751. soc, pdev,
  752. ppdu_info,
  753. pdev->mcopy_status_nbuf,
  754. ppdu_info->fcs_ok_cnt,
  755. false);
  756. if (mcopy_status == QDF_STATUS_SUCCESS) {
  757. qdf_nbuf_free(pdev->mcopy_status_nbuf);
  758. pdev->mcopy_status_nbuf = NULL;
  759. }
  760. }
  761. }
  762. }
  763. #else
  764. static inline void
  765. dp_rx_mcopy_handle_last_mpdu(struct dp_soc *soc, struct dp_pdev *pdev,
  766. struct hal_rx_ppdu_info *ppdu_info,
  767. qdf_nbuf_t status_nbuf)
  768. {
  769. }
  770. #endif
  771. /**
  772. * dp_rx_mcopy_process_ppdu_info() - update mcopy ppdu info
  773. * @ppdu_info: structure for rx ppdu ring
  774. * @tlv_status: processed TLV status
  775. *
  776. * Return: void
  777. */
  778. #ifdef FEATURE_PERPKT_INFO
  779. static inline void
  780. dp_rx_mcopy_process_ppdu_info(struct dp_pdev *pdev,
  781. struct hal_rx_ppdu_info *ppdu_info,
  782. uint32_t tlv_status)
  783. {
  784. if (!pdev->mcopy_mode)
  785. return;
  786. /* The fcs status is received in MPDU end tlv. If the RX header
  787. * and its MPDU end tlv are received in different status buffer then
  788. * to process that header ppdu_info->is_fcs_passed is used.
  789. * If end tlv is received in next status buffer then com_info.mpdu_cnt
  790. * will be 0 at the time of receiving MPDU end tlv and we update the
  791. * is_fcs_passed flag based on ppdu_info->fcs_err.
  792. */
  793. if (tlv_status != HAL_TLV_STATUS_MPDU_END)
  794. return;
  795. if (!ppdu_info->fcs_err) {
  796. if (ppdu_info->fcs_ok_cnt >
  797. HAL_RX_MAX_MPDU_H_PER_STATUS_BUFFER) {
  798. dp_err("No. of MPDUs(%d) per status buff exceeded",
  799. ppdu_info->fcs_ok_cnt);
  800. return;
  801. }
  802. if (ppdu_info->com_info.mpdu_cnt)
  803. ppdu_info->fcs_ok_cnt++;
  804. else
  805. ppdu_info->is_fcs_passed = true;
  806. } else {
  807. if (ppdu_info->com_info.mpdu_cnt)
  808. ppdu_info->fcs_err_cnt++;
  809. else
  810. ppdu_info->is_fcs_passed = false;
  811. }
  812. }
  813. #else
  814. static inline void
  815. dp_rx_mcopy_process_ppdu_info(struct dp_pdev *pdev,
  816. struct hal_rx_ppdu_info *ppdu_info,
  817. uint32_t tlv_status)
  818. {
  819. }
  820. #endif
  821. #ifdef FEATURE_PERPKT_INFO
  822. static inline void
  823. dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  824. struct hal_rx_ppdu_info *ppdu_info,
  825. uint32_t tlv_status,
  826. qdf_nbuf_t status_nbuf)
  827. {
  828. QDF_STATUS mcopy_status;
  829. qdf_nbuf_t nbuf_clone = NULL;
  830. uint8_t fcs_ok_mpdu_cnt = 0;
  831. dp_rx_mcopy_handle_last_mpdu(soc, pdev, ppdu_info, status_nbuf);
  832. if (qdf_unlikely(!ppdu_info->com_info.mpdu_cnt))
  833. goto end;
  834. if (qdf_unlikely(!ppdu_info->fcs_ok_cnt))
  835. goto end;
  836. /* For M_COPY mode only one msdu per ppdu is sent to upper layer*/
  837. if (pdev->mcopy_mode == M_COPY)
  838. ppdu_info->fcs_ok_cnt = 1;
  839. while (fcs_ok_mpdu_cnt < ppdu_info->fcs_ok_cnt) {
  840. nbuf_clone = qdf_nbuf_clone(status_nbuf);
  841. if (!nbuf_clone) {
  842. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  843. "Failed to clone nbuf",
  844. __func__, __LINE__);
  845. goto end;
  846. }
  847. mcopy_status = dp_rx_handle_mcopy_mode(soc, pdev,
  848. ppdu_info,
  849. nbuf_clone,
  850. fcs_ok_mpdu_cnt,
  851. true);
  852. if (mcopy_status == QDF_STATUS_SUCCESS)
  853. qdf_nbuf_free(nbuf_clone);
  854. fcs_ok_mpdu_cnt++;
  855. }
  856. end:
  857. qdf_nbuf_free(status_nbuf);
  858. ppdu_info->fcs_ok_cnt = 0;
  859. ppdu_info->fcs_err_cnt = 0;
  860. ppdu_info->com_info.mpdu_cnt = 0;
  861. qdf_mem_zero(&ppdu_info->ppdu_msdu_info,
  862. HAL_RX_MAX_MPDU_H_PER_STATUS_BUFFER
  863. * sizeof(struct hal_rx_msdu_payload_info));
  864. }
  865. #else
  866. static inline void
  867. dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  868. struct hal_rx_ppdu_info *ppdu_info,
  869. uint32_t tlv_status,
  870. qdf_nbuf_t status_nbuf)
  871. {
  872. }
  873. #endif
  874. /**
  875. * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
  876. * @soc: Datapath SOC handle
  877. * @pdev: Datapath PDEV handle
  878. * @ppdu_info: Structure for rx ppdu info
  879. * @nbuf: Qdf nbuf abstraction for linux skb
  880. *
  881. * Return: 0 on success, 1 on failure
  882. */
  883. static inline int
  884. dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  885. struct hal_rx_ppdu_info *ppdu_info,
  886. qdf_nbuf_t nbuf)
  887. {
  888. uint8_t size = 0;
  889. if (!pdev->monitor_vdev) {
  890. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  891. "[%s]:[%d] Monitor vdev is NULL !!",
  892. __func__, __LINE__);
  893. return 1;
  894. }
  895. if (!ppdu_info->msdu_info.first_msdu_payload) {
  896. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  897. "[%s]:[%d] First msdu payload not present",
  898. __func__, __LINE__);
  899. return 1;
  900. }
  901. /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
  902. size = (ppdu_info->msdu_info.first_msdu_payload -
  903. qdf_nbuf_data(nbuf)) + 4;
  904. ppdu_info->msdu_info.first_msdu_payload = NULL;
  905. if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
  906. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  907. "[%s]:[%d] No header present",
  908. __func__, __LINE__);
  909. return 1;
  910. }
  911. /* Only retain RX MSDU payload in the skb */
  912. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
  913. ppdu_info->msdu_info.payload_len);
  914. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, nbuf,
  915. qdf_nbuf_headroom(nbuf))) {
  916. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  917. return 1;
  918. }
  919. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  920. nbuf, NULL);
  921. pdev->ppdu_info.rx_status.monitor_direct_used = 0;
  922. return 0;
  923. }
  924. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  925. /*
  926. * dp_rx_mon_handle_cfr_mu_info() - Gather macaddr and ast_index of peer(s) in
  927. * the PPDU received, this will be used for correlation of CFR data captured
  928. * for an UL-MU-PPDU
  929. * @pdev: pdev ctx
  930. * @ppdu_info: pointer to ppdu info structure populated from ppdu status TLVs
  931. * @cdp_rx_ppdu: Rx PPDU indication structure
  932. *
  933. * Return: none
  934. */
  935. static inline void
  936. dp_rx_mon_handle_cfr_mu_info(struct dp_pdev *pdev,
  937. struct hal_rx_ppdu_info *ppdu_info,
  938. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  939. {
  940. struct dp_peer *peer;
  941. struct dp_soc *soc = pdev->soc;
  942. struct dp_ast_entry *ast_entry;
  943. struct mon_rx_user_status *rx_user_status;
  944. struct cdp_rx_stats_ppdu_user *rx_stats_peruser;
  945. uint32_t num_users;
  946. int user_id;
  947. uint32_t ast_index;
  948. qdf_spin_lock_bh(&soc->ast_lock);
  949. num_users = ppdu_info->com_info.num_users;
  950. for (user_id = 0; user_id < num_users; user_id++) {
  951. if (user_id > OFDMA_NUM_USERS) {
  952. qdf_spin_unlock_bh(&soc->ast_lock);
  953. return;
  954. }
  955. rx_user_status = &ppdu_info->rx_user_status[user_id];
  956. rx_stats_peruser = &cdp_rx_ppdu->user[user_id];
  957. ast_index = rx_user_status->ast_index;
  958. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  959. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  960. continue;
  961. }
  962. ast_entry = soc->ast_table[ast_index];
  963. if (!ast_entry || ast_entry->peer_id == HTT_INVALID_PEER) {
  964. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  965. continue;
  966. }
  967. peer = dp_peer_get_ref_by_id(soc, ast_entry->peer_id,
  968. DP_MOD_ID_RX_PPDU_STATS);
  969. if (!peer) {
  970. rx_stats_peruser->peer_id = HTT_INVALID_PEER;
  971. continue;
  972. }
  973. qdf_mem_copy(rx_stats_peruser->mac_addr,
  974. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  975. dp_peer_unref_delete(peer, DP_MOD_ID_RX_PPDU_STATS);
  976. }
  977. qdf_spin_unlock_bh(&soc->ast_lock);
  978. }
  979. /*
  980. * dp_rx_mon_populate_cfr_ppdu_info() - Populate cdp ppdu info from hal ppdu
  981. * info
  982. * @pdev: pdev ctx
  983. * @ppdu_info: ppdu info structure from ppdu ring
  984. * @cdp_rx_ppdu : Rx PPDU indication structure
  985. *
  986. * Return: none
  987. */
  988. static inline void
  989. dp_rx_mon_populate_cfr_ppdu_info(struct dp_pdev *pdev,
  990. struct hal_rx_ppdu_info *ppdu_info,
  991. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  992. {
  993. int chain;
  994. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  995. cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
  996. cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
  997. cdp_rx_ppdu->num_users = ppdu_info->com_info.num_users;
  998. for (chain = 0; chain < MAX_CHAIN; chain++)
  999. cdp_rx_ppdu->per_chain_rssi[chain] =
  1000. ppdu_info->rx_status.rssi[chain];
  1001. dp_rx_mon_handle_cfr_mu_info(pdev, ppdu_info, cdp_rx_ppdu);
  1002. }
  1003. /**
  1004. * dp_cfr_rcc_mode_status() - Return status of cfr rcc mode
  1005. * @pdev: pdev ctx
  1006. *
  1007. * Return: True or False
  1008. */
  1009. static inline bool
  1010. dp_cfr_rcc_mode_status(struct dp_pdev *pdev)
  1011. {
  1012. return pdev->cfr_rcc_mode;
  1013. }
  1014. /*
  1015. * dp_rx_mon_populate_cfr_info() - Populate cdp ppdu info from hal cfr info
  1016. * @pdev: pdev ctx
  1017. * @ppdu_info: ppdu info structure from ppdu ring
  1018. * @cdp_rx_ppdu: Rx PPDU indication structure
  1019. *
  1020. * Return: none
  1021. */
  1022. static inline void
  1023. dp_rx_mon_populate_cfr_info(struct dp_pdev *pdev,
  1024. struct hal_rx_ppdu_info *ppdu_info,
  1025. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1026. {
  1027. struct cdp_rx_ppdu_cfr_info *cfr_info;
  1028. if (!dp_cfr_rcc_mode_status(pdev))
  1029. return;
  1030. cfr_info = &cdp_rx_ppdu->cfr_info;
  1031. cfr_info->bb_captured_channel
  1032. = ppdu_info->cfr_info.bb_captured_channel;
  1033. cfr_info->bb_captured_timeout
  1034. = ppdu_info->cfr_info.bb_captured_timeout;
  1035. cfr_info->bb_captured_reason
  1036. = ppdu_info->cfr_info.bb_captured_reason;
  1037. cfr_info->rx_location_info_valid
  1038. = ppdu_info->cfr_info.rx_location_info_valid;
  1039. cfr_info->chan_capture_status
  1040. = ppdu_info->cfr_info.chan_capture_status;
  1041. cfr_info->rtt_che_buffer_pointer_high8
  1042. = ppdu_info->cfr_info.rtt_che_buffer_pointer_high8;
  1043. cfr_info->rtt_che_buffer_pointer_low32
  1044. = ppdu_info->cfr_info.rtt_che_buffer_pointer_low32;
  1045. }
  1046. /**
  1047. * dp_update_cfr_dbg_stats() - Increment RCC debug statistics
  1048. * @pdev: pdev structure
  1049. * @ppdu_info: structure for rx ppdu ring
  1050. *
  1051. * Return: none
  1052. */
  1053. static inline void
  1054. dp_update_cfr_dbg_stats(struct dp_pdev *pdev,
  1055. struct hal_rx_ppdu_info *ppdu_info)
  1056. {
  1057. struct hal_rx_ppdu_cfr_info *cfr = &ppdu_info->cfr_info;
  1058. DP_STATS_INC(pdev,
  1059. rcc.chan_capture_status[cfr->chan_capture_status], 1);
  1060. if (cfr->rx_location_info_valid) {
  1061. DP_STATS_INC(pdev, rcc.rx_loc_info_valid_cnt, 1);
  1062. if (cfr->bb_captured_channel) {
  1063. DP_STATS_INC(pdev, rcc.bb_captured_channel_cnt, 1);
  1064. DP_STATS_INC(pdev,
  1065. rcc.reason_cnt[cfr->bb_captured_reason],
  1066. 1);
  1067. } else if (cfr->bb_captured_timeout) {
  1068. DP_STATS_INC(pdev, rcc.bb_captured_timeout_cnt, 1);
  1069. DP_STATS_INC(pdev,
  1070. rcc.reason_cnt[cfr->bb_captured_reason],
  1071. 1);
  1072. }
  1073. }
  1074. }
  1075. /*
  1076. * dp_rx_handle_cfr() - Gather cfr info from hal ppdu info
  1077. * @soc: core txrx main context
  1078. * @pdev: pdev ctx
  1079. * @ppdu_info: ppdu info structure from ppdu ring
  1080. *
  1081. * Return: none
  1082. */
  1083. static inline void
  1084. dp_rx_handle_cfr(struct dp_soc *soc, struct dp_pdev *pdev,
  1085. struct hal_rx_ppdu_info *ppdu_info)
  1086. {
  1087. qdf_nbuf_t ppdu_nbuf;
  1088. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  1089. dp_update_cfr_dbg_stats(pdev, ppdu_info);
  1090. if (!ppdu_info->cfr_info.bb_captured_channel)
  1091. return;
  1092. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  1093. sizeof(struct cdp_rx_indication_ppdu),
  1094. 0,
  1095. 0,
  1096. FALSE);
  1097. if (ppdu_nbuf) {
  1098. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  1099. dp_rx_mon_populate_cfr_info(pdev, ppdu_info, cdp_rx_ppdu);
  1100. dp_rx_mon_populate_cfr_ppdu_info(pdev, ppdu_info, cdp_rx_ppdu);
  1101. qdf_nbuf_put_tail(ppdu_nbuf,
  1102. sizeof(struct cdp_rx_indication_ppdu));
  1103. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  1104. ppdu_nbuf, HTT_INVALID_PEER,
  1105. WDI_NO_VAL, pdev->pdev_id);
  1106. }
  1107. }
  1108. /**
  1109. * dp_rx_populate_cfr_non_assoc_sta() - Populate cfr ppdu info for PPDUs from
  1110. * non-associated stations
  1111. * @pdev: pdev ctx
  1112. * @ppdu_info: ppdu info structure from ppdu ring
  1113. * @cdp_rx_ppdu: Rx PPDU indication structure
  1114. *
  1115. * Return: none
  1116. */
  1117. static inline void
  1118. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  1119. struct hal_rx_ppdu_info *ppdu_info,
  1120. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1121. {
  1122. if (!dp_cfr_rcc_mode_status(pdev))
  1123. return;
  1124. if (ppdu_info->cfr_info.bb_captured_channel)
  1125. dp_rx_mon_populate_cfr_ppdu_info(pdev, ppdu_info, cdp_rx_ppdu);
  1126. }
  1127. /**
  1128. * dp_bb_captured_chan_status() - Get the bb_captured_channel status
  1129. * @ppdu_info: structure for rx ppdu ring
  1130. *
  1131. * Return: Success/ Failure
  1132. */
  1133. static inline QDF_STATUS
  1134. dp_bb_captured_chan_status(struct dp_pdev *pdev,
  1135. struct hal_rx_ppdu_info *ppdu_info)
  1136. {
  1137. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  1138. struct hal_rx_ppdu_cfr_info *cfr = &ppdu_info->cfr_info;
  1139. if (dp_cfr_rcc_mode_status(pdev)) {
  1140. if (cfr->bb_captured_channel)
  1141. status = QDF_STATUS_SUCCESS;
  1142. }
  1143. return status;
  1144. }
  1145. #else
  1146. static inline void
  1147. dp_rx_mon_handle_cfr_mu_info(struct dp_pdev *pdev,
  1148. struct hal_rx_ppdu_info *ppdu_info,
  1149. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1150. {
  1151. }
  1152. static inline void
  1153. dp_rx_mon_populate_cfr_ppdu_info(struct dp_pdev *pdev,
  1154. struct hal_rx_ppdu_info *ppdu_info,
  1155. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1156. {
  1157. }
  1158. static inline void
  1159. dp_rx_mon_populate_cfr_info(struct dp_pdev *pdev,
  1160. struct hal_rx_ppdu_info *ppdu_info,
  1161. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1162. {
  1163. }
  1164. static inline void
  1165. dp_rx_handle_cfr(struct dp_soc *soc, struct dp_pdev *pdev,
  1166. struct hal_rx_ppdu_info *ppdu_info)
  1167. {
  1168. }
  1169. static inline void
  1170. dp_rx_populate_cfr_non_assoc_sta(struct dp_pdev *pdev,
  1171. struct hal_rx_ppdu_info *ppdu_info,
  1172. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  1173. {
  1174. }
  1175. static inline void
  1176. dp_update_cfr_dbg_stats(struct dp_pdev *pdev,
  1177. struct hal_rx_ppdu_info *ppdu_info)
  1178. {
  1179. }
  1180. static inline QDF_STATUS
  1181. dp_bb_captured_chan_status(struct dp_pdev *pdev,
  1182. struct hal_rx_ppdu_info *ppdu_info)
  1183. {
  1184. return QDF_STATUS_E_NOSUPPORT;
  1185. }
  1186. static inline bool
  1187. dp_cfr_rcc_mode_status(struct dp_pdev *pdev)
  1188. {
  1189. return false;
  1190. }
  1191. #endif
  1192. /**
  1193. * dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
  1194. * @soc: core txrx main context
  1195. * @pdev: pdev strcuture
  1196. * @ppdu_info: structure for rx ppdu ring
  1197. *
  1198. * Return: none
  1199. */
  1200. #ifdef FEATURE_PERPKT_INFO
  1201. static inline void
  1202. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  1203. struct hal_rx_ppdu_info *ppdu_info)
  1204. {
  1205. qdf_nbuf_t ppdu_nbuf;
  1206. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  1207. /*
  1208. * Do not allocate if fcs error,
  1209. * ast idx invalid / fctl invalid
  1210. *
  1211. * In CFR RCC mode - PPDU status TLVs of error pkts are also needed
  1212. */
  1213. if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
  1214. return;
  1215. if (ppdu_info->nac_info.fc_valid &&
  1216. ppdu_info->nac_info.to_ds_flag &&
  1217. ppdu_info->nac_info.mac_addr2_valid) {
  1218. struct dp_neighbour_peer *peer = NULL;
  1219. uint8_t rssi = ppdu_info->rx_status.rssi_comb;
  1220. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  1221. if (pdev->neighbour_peers_added) {
  1222. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  1223. neighbour_peer_list_elem) {
  1224. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
  1225. &ppdu_info->nac_info.mac_addr2,
  1226. QDF_MAC_ADDR_SIZE)) {
  1227. peer->rssi = rssi;
  1228. break;
  1229. }
  1230. }
  1231. }
  1232. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  1233. }
  1234. /* need not generate wdi event when mcopy, cfr rcc mode and
  1235. * enhanced stats are not enabled
  1236. */
  1237. if (!pdev->mcopy_mode && !pdev->enhanced_stats_en &&
  1238. !dp_cfr_rcc_mode_status(pdev))
  1239. return;
  1240. if (dp_cfr_rcc_mode_status(pdev))
  1241. dp_update_cfr_dbg_stats(pdev, ppdu_info);
  1242. if (!ppdu_info->rx_status.frame_control_info_valid ||
  1243. (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)) {
  1244. if (!(pdev->mcopy_mode ||
  1245. (dp_bb_captured_chan_status(pdev, ppdu_info) ==
  1246. QDF_STATUS_SUCCESS)))
  1247. return;
  1248. }
  1249. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  1250. sizeof(struct cdp_rx_indication_ppdu),
  1251. 0, 0, FALSE);
  1252. if (ppdu_nbuf) {
  1253. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  1254. dp_rx_mon_populate_cfr_info(pdev, ppdu_info, cdp_rx_ppdu);
  1255. dp_rx_populate_cdp_indication_ppdu(pdev,
  1256. ppdu_info, cdp_rx_ppdu);
  1257. if (!qdf_nbuf_put_tail(ppdu_nbuf,
  1258. sizeof(struct cdp_rx_indication_ppdu)))
  1259. return;
  1260. dp_rx_stats_update(pdev, cdp_rx_ppdu);
  1261. if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
  1262. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
  1263. soc, ppdu_nbuf,
  1264. cdp_rx_ppdu->peer_id,
  1265. WDI_NO_VAL, pdev->pdev_id);
  1266. } else if (pdev->mcopy_mode || dp_cfr_rcc_mode_status(pdev)) {
  1267. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  1268. ppdu_nbuf, HTT_INVALID_PEER,
  1269. WDI_NO_VAL, pdev->pdev_id);
  1270. } else {
  1271. qdf_nbuf_free(ppdu_nbuf);
  1272. }
  1273. }
  1274. }
  1275. #else
  1276. static inline void
  1277. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  1278. struct hal_rx_ppdu_info *ppdu_info)
  1279. {
  1280. }
  1281. #endif
  1282. /**
  1283. * dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
  1284. * filtering enabled
  1285. * @soc: core txrx main context
  1286. * @ppdu_info: Structure for rx ppdu info
  1287. * @status_nbuf: Qdf nbuf abstraction for linux skb
  1288. * @pdev_id: mac_id/pdev_id correspondinggly for MCL and WIN
  1289. *
  1290. * Return: none
  1291. */
  1292. static inline void
  1293. dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
  1294. struct hal_rx_ppdu_info *ppdu_info,
  1295. qdf_nbuf_t status_nbuf, uint32_t pdev_id)
  1296. {
  1297. struct dp_peer *peer;
  1298. struct dp_ast_entry *ast_entry;
  1299. uint32_t ast_index;
  1300. ast_index = ppdu_info->rx_status.ast_index;
  1301. if (ast_index < wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  1302. ast_entry = soc->ast_table[ast_index];
  1303. if (ast_entry) {
  1304. peer = dp_peer_get_ref_by_id(soc, ast_entry->peer_id,
  1305. DP_MOD_ID_RX_PPDU_STATS);
  1306. if (peer) {
  1307. if ((peer->peer_id != HTT_INVALID_PEER) &&
  1308. (peer->peer_based_pktlog_filter)) {
  1309. dp_wdi_event_handler(
  1310. WDI_EVENT_RX_DESC, soc,
  1311. status_nbuf,
  1312. peer->peer_id,
  1313. WDI_NO_VAL, pdev_id);
  1314. }
  1315. dp_peer_unref_delete(peer,
  1316. DP_MOD_ID_RX_PPDU_STATS);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. #if defined(HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_M)
  1322. static inline void
  1323. dp_rx_ul_ofdma_ru_size_to_width(
  1324. uint32_t ru_size,
  1325. uint32_t *ru_width)
  1326. {
  1327. uint32_t width;
  1328. width = 0;
  1329. switch (ru_size) {
  1330. case HTT_UL_OFDMA_V0_RU_SIZE_RU_26:
  1331. width = 1;
  1332. break;
  1333. case HTT_UL_OFDMA_V0_RU_SIZE_RU_52:
  1334. width = 2;
  1335. break;
  1336. case HTT_UL_OFDMA_V0_RU_SIZE_RU_106:
  1337. width = 4;
  1338. break;
  1339. case HTT_UL_OFDMA_V0_RU_SIZE_RU_242:
  1340. width = 9;
  1341. break;
  1342. case HTT_UL_OFDMA_V0_RU_SIZE_RU_484:
  1343. width = 18;
  1344. break;
  1345. case HTT_UL_OFDMA_V0_RU_SIZE_RU_996:
  1346. width = 37;
  1347. break;
  1348. case HTT_UL_OFDMA_V0_RU_SIZE_RU_996x2:
  1349. width = 74;
  1350. break;
  1351. default:
  1352. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1353. "RU size to width convert err");
  1354. break;
  1355. }
  1356. *ru_width = width;
  1357. }
  1358. static inline void
  1359. dp_rx_mon_handle_mu_ul_info(struct hal_rx_ppdu_info *ppdu_info)
  1360. {
  1361. struct mon_rx_user_status *mon_rx_user_status;
  1362. uint32_t num_users;
  1363. uint32_t i;
  1364. uint32_t mu_ul_user_v0_word0;
  1365. uint32_t mu_ul_user_v0_word1;
  1366. uint32_t ru_width;
  1367. uint32_t ru_size;
  1368. if (!(ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_OFDMA ||
  1369. ppdu_info->rx_status.reception_type == HAL_RX_TYPE_MU_MIMO))
  1370. return;
  1371. num_users = ppdu_info->com_info.num_users;
  1372. if (num_users > HAL_MAX_UL_MU_USERS)
  1373. num_users = HAL_MAX_UL_MU_USERS;
  1374. for (i = 0; i < num_users; i++) {
  1375. mon_rx_user_status = &ppdu_info->rx_user_status[i];
  1376. mu_ul_user_v0_word0 =
  1377. mon_rx_user_status->mu_ul_user_v0_word0;
  1378. mu_ul_user_v0_word1 =
  1379. mon_rx_user_status->mu_ul_user_v0_word1;
  1380. if (HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_GET(
  1381. mu_ul_user_v0_word0) &&
  1382. !HTT_UL_OFDMA_USER_INFO_V0_W0_VER_GET(
  1383. mu_ul_user_v0_word0)) {
  1384. mon_rx_user_status->mcs =
  1385. HTT_UL_OFDMA_USER_INFO_V0_W1_MCS_GET(
  1386. mu_ul_user_v0_word1);
  1387. mon_rx_user_status->nss =
  1388. HTT_UL_OFDMA_USER_INFO_V0_W1_NSS_GET(
  1389. mu_ul_user_v0_word1) + 1;
  1390. mon_rx_user_status->mu_ul_info_valid = 1;
  1391. mon_rx_user_status->ofdma_ru_start_index =
  1392. HTT_UL_OFDMA_USER_INFO_V0_W1_RU_START_GET(
  1393. mu_ul_user_v0_word1);
  1394. ru_size =
  1395. HTT_UL_OFDMA_USER_INFO_V0_W1_RU_SIZE_GET(
  1396. mu_ul_user_v0_word1);
  1397. dp_rx_ul_ofdma_ru_size_to_width(ru_size, &ru_width);
  1398. mon_rx_user_status->ofdma_ru_width = ru_width;
  1399. mon_rx_user_status->ofdma_ru_size = ru_size;
  1400. }
  1401. }
  1402. }
  1403. #else
  1404. static inline void
  1405. dp_rx_mon_handle_mu_ul_info(struct hal_rx_ppdu_info *ppdu_info)
  1406. {
  1407. }
  1408. #endif
  1409. /**
  1410. * dp_rx_mon_status_process_tlv() - Process status TLV in status
  1411. * buffer on Rx status Queue posted by status SRNG processing.
  1412. * @soc: core txrx main context
  1413. * @int_ctx: interrupt context
  1414. * @mac_id: mac_id which is one of 3 mac_ids _ring
  1415. * @quota: amount of work which can be done
  1416. *
  1417. * Return: none
  1418. */
  1419. static inline void
  1420. dp_rx_mon_status_process_tlv(struct dp_soc *soc, struct dp_intr *int_ctx,
  1421. uint32_t mac_id, uint32_t quota)
  1422. {
  1423. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1424. struct hal_rx_ppdu_info *ppdu_info;
  1425. qdf_nbuf_t status_nbuf;
  1426. uint8_t *rx_tlv;
  1427. uint8_t *rx_tlv_start;
  1428. uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
  1429. QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
  1430. struct cdp_pdev_mon_stats *rx_mon_stats;
  1431. int smart_mesh_status;
  1432. enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
  1433. bool nbuf_used;
  1434. uint32_t rx_enh_capture_mode;
  1435. if (!pdev) {
  1436. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1437. "pdev is null for mac_id = %d", mac_id);
  1438. return;
  1439. }
  1440. ppdu_info = &pdev->ppdu_info;
  1441. rx_mon_stats = &pdev->rx_mon_stats;
  1442. if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
  1443. return;
  1444. rx_enh_capture_mode = pdev->rx_enh_capture_mode;
  1445. while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
  1446. status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
  1447. rx_tlv = qdf_nbuf_data(status_nbuf);
  1448. rx_tlv_start = rx_tlv;
  1449. nbuf_used = false;
  1450. if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
  1451. (pdev->mcopy_mode) || (dp_cfr_rcc_mode_status(pdev)) ||
  1452. (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  1453. do {
  1454. tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
  1455. ppdu_info, pdev->soc->hal_soc,
  1456. status_nbuf);
  1457. dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
  1458. rx_mon_stats);
  1459. dp_rx_mon_enh_capture_process(pdev, tlv_status,
  1460. status_nbuf, ppdu_info,
  1461. &nbuf_used);
  1462. dp_rx_mcopy_process_ppdu_info(pdev,
  1463. ppdu_info,
  1464. tlv_status);
  1465. rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
  1466. if ((rx_tlv - rx_tlv_start) >=
  1467. RX_MON_STATUS_BUF_SIZE)
  1468. break;
  1469. } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
  1470. (tlv_status == HAL_TLV_STATUS_HEADER) ||
  1471. (tlv_status == HAL_TLV_STATUS_MPDU_END) ||
  1472. (tlv_status == HAL_TLV_STATUS_MSDU_END));
  1473. }
  1474. if (pdev->dp_peer_based_pktlog) {
  1475. dp_rx_process_peer_based_pktlog(soc, ppdu_info,
  1476. status_nbuf,
  1477. pdev->pdev_id);
  1478. } else {
  1479. if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
  1480. pktlog_mode = WDI_EVENT_RX_DESC;
  1481. else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
  1482. pktlog_mode = WDI_EVENT_LITE_RX;
  1483. if (pktlog_mode != WDI_NO_VAL)
  1484. dp_wdi_event_handler(pktlog_mode, soc,
  1485. status_nbuf,
  1486. HTT_INVALID_PEER,
  1487. WDI_NO_VAL, pdev->pdev_id);
  1488. }
  1489. /* smart monitor vap and m_copy cannot co-exist */
  1490. if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
  1491. && pdev->monitor_vdev) {
  1492. smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
  1493. pdev, ppdu_info, status_nbuf);
  1494. if (smart_mesh_status)
  1495. qdf_nbuf_free(status_nbuf);
  1496. } else if (qdf_unlikely(pdev->mcopy_mode)) {
  1497. dp_rx_process_mcopy_mode(soc, pdev,
  1498. ppdu_info, tlv_status,
  1499. status_nbuf);
  1500. } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
  1501. if (!nbuf_used)
  1502. qdf_nbuf_free(status_nbuf);
  1503. if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
  1504. enh_log_status =
  1505. dp_rx_handle_enh_capture(soc,
  1506. pdev, ppdu_info);
  1507. } else {
  1508. qdf_nbuf_free(status_nbuf);
  1509. }
  1510. if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
  1511. dp_rx_mon_deliver_non_std(soc, mac_id);
  1512. } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
  1513. rx_mon_stats->status_ppdu_done++;
  1514. dp_rx_mon_handle_mu_ul_info(ppdu_info);
  1515. if (pdev->tx_capture_enabled
  1516. != CDP_TX_ENH_CAPTURE_DISABLED)
  1517. dp_send_ack_frame_to_stack(soc, pdev,
  1518. ppdu_info);
  1519. if (pdev->enhanced_stats_en ||
  1520. pdev->mcopy_mode || pdev->neighbour_peers_added)
  1521. dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
  1522. else if (dp_cfr_rcc_mode_status(pdev))
  1523. dp_rx_handle_cfr(soc, pdev, ppdu_info);
  1524. pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
  1525. /*
  1526. * if chan_num is not fetched correctly from ppdu RX TLV,
  1527. * get it from pdev saved.
  1528. */
  1529. if (qdf_unlikely(pdev->ppdu_info.rx_status.chan_num == 0))
  1530. pdev->ppdu_info.rx_status.chan_num = pdev->mon_chan_num;
  1531. /*
  1532. * if chan_freq is not fetched correctly from ppdu RX TLV,
  1533. * get it from pdev saved.
  1534. */
  1535. if (qdf_unlikely(pdev->ppdu_info.rx_status.chan_freq == 0)) {
  1536. pdev->ppdu_info.rx_status.chan_freq =
  1537. pdev->mon_chan_freq;
  1538. }
  1539. if (!soc->full_mon_mode)
  1540. dp_rx_mon_dest_process(soc, int_ctx, mac_id,
  1541. quota);
  1542. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1543. }
  1544. }
  1545. return;
  1546. }
  1547. /*
  1548. * dp_rx_nbuf_prepare() - prepare RX nbuf
  1549. * @soc: core txrx main context
  1550. * @pdev: core txrx pdev context
  1551. *
  1552. * This function alloc & map nbuf for RX dma usage, retry it if failed
  1553. * until retry times reaches max threshold or succeeded.
  1554. *
  1555. * Return: qdf_nbuf_t pointer if succeeded, NULL if failed.
  1556. */
  1557. static inline qdf_nbuf_t
  1558. dp_rx_nbuf_prepare(struct dp_soc *soc, struct dp_pdev *pdev)
  1559. {
  1560. uint8_t *buf;
  1561. int32_t nbuf_retry_count;
  1562. QDF_STATUS ret;
  1563. qdf_nbuf_t nbuf = NULL;
  1564. for (nbuf_retry_count = 0; nbuf_retry_count <
  1565. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD;
  1566. nbuf_retry_count++) {
  1567. /* Allocate a new skb using alloc_skb */
  1568. nbuf = qdf_nbuf_alloc_no_recycler(RX_MON_STATUS_BUF_SIZE,
  1569. RX_BUFFER_RESERVATION,
  1570. RX_DATA_BUFFER_ALIGNMENT);
  1571. if (!nbuf) {
  1572. DP_STATS_INC(pdev, replenish.nbuf_alloc_fail, 1);
  1573. continue;
  1574. }
  1575. buf = qdf_nbuf_data(nbuf);
  1576. memset(buf, 0, RX_MON_STATUS_BUF_SIZE);
  1577. ret = qdf_nbuf_map_nbytes_single(soc->osdev, nbuf,
  1578. QDF_DMA_FROM_DEVICE,
  1579. RX_MON_STATUS_BUF_SIZE);
  1580. /* nbuf map failed */
  1581. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret))) {
  1582. qdf_nbuf_free(nbuf);
  1583. DP_STATS_INC(pdev, replenish.map_err, 1);
  1584. continue;
  1585. }
  1586. /* qdf_nbuf alloc and map succeeded */
  1587. break;
  1588. }
  1589. /* qdf_nbuf still alloc or map failed */
  1590. if (qdf_unlikely(nbuf_retry_count >=
  1591. QDF_NBUF_ALLOC_MAP_RETRY_THRESHOLD))
  1592. return NULL;
  1593. return nbuf;
  1594. }
  1595. /*
  1596. * dp_rx_mon_status_srng_process() - Process monitor status ring
  1597. * post the status ring buffer to Rx status Queue for later
  1598. * processing when status ring is filled with status TLV.
  1599. * Allocate a new buffer to status ring if the filled buffer
  1600. * is posted.
  1601. * @soc: core txrx main context
  1602. * @int_ctx: interrupt context
  1603. * @mac_id: mac_id which is one of 3 mac_ids
  1604. * @quota: No. of ring entry that can be serviced in one shot.
  1605. * Return: uint32_t: No. of ring entry that is processed.
  1606. */
  1607. static inline uint32_t
  1608. dp_rx_mon_status_srng_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1609. uint32_t mac_id, uint32_t quota)
  1610. {
  1611. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1612. hal_soc_handle_t hal_soc;
  1613. void *mon_status_srng;
  1614. void *rxdma_mon_status_ring_entry;
  1615. QDF_STATUS status;
  1616. uint32_t work_done = 0;
  1617. if (!pdev) {
  1618. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1619. "pdev is null for mac_id = %d", mac_id);
  1620. return work_done;
  1621. }
  1622. mon_status_srng = soc->rxdma_mon_status_ring[mac_id].hal_srng;
  1623. qdf_assert(mon_status_srng);
  1624. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  1625. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1626. "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
  1627. __func__, __LINE__, mon_status_srng);
  1628. return work_done;
  1629. }
  1630. hal_soc = soc->hal_soc;
  1631. qdf_assert(hal_soc);
  1632. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_status_srng)))
  1633. goto done;
  1634. /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
  1635. * BUFFER_ADDR_INFO STRUCT
  1636. */
  1637. while (qdf_likely((rxdma_mon_status_ring_entry =
  1638. hal_srng_src_peek_n_get_next(hal_soc, mon_status_srng))
  1639. && quota--)) {
  1640. uint32_t rx_buf_cookie;
  1641. qdf_nbuf_t status_nbuf;
  1642. struct dp_rx_desc *rx_desc;
  1643. uint8_t *status_buf;
  1644. qdf_dma_addr_t paddr;
  1645. uint64_t buf_addr;
  1646. struct rx_desc_pool *rx_desc_pool;
  1647. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1648. buf_addr =
  1649. (HAL_RX_BUFFER_ADDR_31_0_GET(
  1650. rxdma_mon_status_ring_entry) |
  1651. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
  1652. rxdma_mon_status_ring_entry)) << 32));
  1653. if (qdf_likely(buf_addr)) {
  1654. rx_buf_cookie =
  1655. HAL_RX_BUF_COOKIE_GET(
  1656. rxdma_mon_status_ring_entry);
  1657. rx_desc = dp_rx_cookie_2_va_mon_status(soc,
  1658. rx_buf_cookie);
  1659. qdf_assert(rx_desc);
  1660. status_nbuf = rx_desc->nbuf;
  1661. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  1662. QDF_DMA_FROM_DEVICE);
  1663. status_buf = qdf_nbuf_data(status_nbuf);
  1664. status = hal_get_rx_status_done(status_buf);
  1665. if (status != QDF_STATUS_SUCCESS) {
  1666. uint32_t hp, tp;
  1667. hal_get_sw_hptp(hal_soc, mon_status_srng,
  1668. &tp, &hp);
  1669. dp_info_rl("tlv tag status error hp:%u, tp:%u",
  1670. hp, tp);
  1671. pdev->rx_mon_stats.tlv_tag_status_err++;
  1672. /* RxDMA status done bit might not be set even
  1673. * though tp is moved by HW.
  1674. * So Hold on to current entry on
  1675. * monitor status ring
  1676. */
  1677. /* If done status is missing, hold onto status
  1678. * ring until status is done for this status
  1679. * ring buffer.
  1680. * Keep HP in mon_status_ring unchanged,
  1681. * and break from here.
  1682. * Check status for same buffer for next time
  1683. * dp_rx_mon_status_srng_process
  1684. */
  1685. break;
  1686. }
  1687. qdf_nbuf_set_pktlen(status_nbuf,
  1688. RX_MON_STATUS_BUF_SIZE);
  1689. qdf_nbuf_unmap_nbytes_single(soc->osdev, status_nbuf,
  1690. QDF_DMA_FROM_DEVICE,
  1691. rx_desc_pool->buf_size);
  1692. /* Put the status_nbuf to queue */
  1693. qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
  1694. } else {
  1695. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1696. union dp_rx_desc_list_elem_t *tail = NULL;
  1697. uint32_t num_alloc_desc;
  1698. num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
  1699. rx_desc_pool,
  1700. 1,
  1701. &desc_list,
  1702. &tail);
  1703. /*
  1704. * No free descriptors available
  1705. */
  1706. if (qdf_unlikely(num_alloc_desc == 0)) {
  1707. work_done++;
  1708. break;
  1709. }
  1710. rx_desc = &desc_list->rx_desc;
  1711. }
  1712. status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
  1713. /*
  1714. * qdf_nbuf alloc or map failed,
  1715. * free the dp rx desc to free list,
  1716. * fill in NULL dma address at current HP entry,
  1717. * keep HP in mon_status_ring unchanged,
  1718. * wait next time dp_rx_mon_status_srng_process
  1719. * to fill in buffer at current HP.
  1720. */
  1721. if (qdf_unlikely(!status_nbuf)) {
  1722. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1723. union dp_rx_desc_list_elem_t *tail = NULL;
  1724. struct rx_desc_pool *rx_desc_pool;
  1725. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1726. dp_info_rl("fail to allocate or map qdf_nbuf");
  1727. dp_rx_add_to_free_desc_list(&desc_list,
  1728. &tail, rx_desc);
  1729. dp_rx_add_desc_list_to_free_list(soc, &desc_list,
  1730. &tail, mac_id, rx_desc_pool);
  1731. hal_rxdma_buff_addr_info_set(
  1732. rxdma_mon_status_ring_entry,
  1733. 0, 0, HAL_RX_BUF_RBM_SW3_BM);
  1734. work_done++;
  1735. break;
  1736. }
  1737. paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
  1738. rx_desc->nbuf = status_nbuf;
  1739. rx_desc->in_use = 1;
  1740. hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
  1741. paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
  1742. hal_srng_src_get_next(hal_soc, mon_status_srng);
  1743. work_done++;
  1744. }
  1745. done:
  1746. dp_srng_access_end(int_ctx, soc, mon_status_srng);
  1747. return work_done;
  1748. }
  1749. uint32_t
  1750. dp_rx_mon_status_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1751. uint32_t mac_id, uint32_t quota)
  1752. {
  1753. uint32_t work_done;
  1754. work_done = dp_rx_mon_status_srng_process(soc, int_ctx, mac_id, quota);
  1755. quota -= work_done;
  1756. dp_rx_mon_status_process_tlv(soc, int_ctx, mac_id, quota);
  1757. return work_done;
  1758. }
  1759. #ifndef DISABLE_MON_CONFIG
  1760. uint32_t
  1761. dp_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1762. uint32_t mac_id, uint32_t quota)
  1763. {
  1764. if (qdf_unlikely(soc->full_mon_mode))
  1765. return dp_rx_mon_process(soc, int_ctx, mac_id, quota);
  1766. return dp_rx_mon_status_process(soc, int_ctx, mac_id, quota);
  1767. }
  1768. #else
  1769. uint32_t
  1770. dp_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1771. uint32_t mac_id, uint32_t quota)
  1772. {
  1773. return 0;
  1774. }
  1775. #endif
  1776. QDF_STATUS
  1777. dp_rx_pdev_mon_status_buffers_alloc(struct dp_pdev *pdev, uint32_t mac_id)
  1778. {
  1779. uint8_t pdev_id = pdev->pdev_id;
  1780. struct dp_soc *soc = pdev->soc;
  1781. struct dp_srng *mon_status_ring;
  1782. uint32_t num_entries;
  1783. struct rx_desc_pool *rx_desc_pool;
  1784. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  1785. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1786. union dp_rx_desc_list_elem_t *tail = NULL;
  1787. soc_cfg_ctx = soc->wlan_cfg_ctx;
  1788. mon_status_ring = &soc->rxdma_mon_status_ring[mac_id];
  1789. num_entries = mon_status_ring->num_entries;
  1790. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1791. dp_debug("Mon RX Desc Pool[%d] entries=%u",
  1792. pdev_id, num_entries);
  1793. return dp_rx_mon_status_buffers_replenish(soc, mac_id, mon_status_ring,
  1794. rx_desc_pool, num_entries,
  1795. &desc_list, &tail,
  1796. HAL_RX_BUF_RBM_SW3_BM);
  1797. }
  1798. QDF_STATUS
  1799. dp_rx_pdev_mon_status_desc_pool_alloc(struct dp_pdev *pdev, uint32_t mac_id)
  1800. {
  1801. uint8_t pdev_id = pdev->pdev_id;
  1802. struct dp_soc *soc = pdev->soc;
  1803. struct dp_srng *mon_status_ring;
  1804. uint32_t num_entries;
  1805. struct rx_desc_pool *rx_desc_pool;
  1806. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  1807. soc_cfg_ctx = soc->wlan_cfg_ctx;
  1808. mon_status_ring = &soc->rxdma_mon_status_ring[mac_id];
  1809. num_entries = mon_status_ring->num_entries;
  1810. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1811. dp_debug("Mon RX Desc Pool[%d] entries=%u", pdev_id, num_entries);
  1812. return dp_rx_desc_pool_alloc(soc, num_entries + 1, rx_desc_pool);
  1813. }
  1814. void
  1815. dp_rx_pdev_mon_status_desc_pool_init(struct dp_pdev *pdev, uint32_t mac_id)
  1816. {
  1817. uint32_t i;
  1818. uint8_t pdev_id = pdev->pdev_id;
  1819. struct dp_soc *soc = pdev->soc;
  1820. struct dp_srng *mon_status_ring;
  1821. uint32_t num_entries;
  1822. struct rx_desc_pool *rx_desc_pool;
  1823. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  1824. soc_cfg_ctx = soc->wlan_cfg_ctx;
  1825. mon_status_ring = &soc->rxdma_mon_status_ring[mac_id];
  1826. num_entries = mon_status_ring->num_entries;
  1827. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1828. dp_debug("Mon RX Desc status Pool[%d] init entries=%u",
  1829. pdev_id, num_entries);
  1830. rx_desc_pool->owner = HAL_RX_BUF_RBM_SW3_BM;
  1831. rx_desc_pool->buf_size = RX_MON_STATUS_BUF_SIZE;
  1832. rx_desc_pool->buf_alignment = RX_DATA_BUFFER_ALIGNMENT;
  1833. /* Disable frag processing flag */
  1834. dp_rx_enable_mon_dest_frag(rx_desc_pool, false);
  1835. dp_rx_desc_pool_init(soc, mac_id, num_entries + 1, rx_desc_pool);
  1836. qdf_nbuf_queue_init(&pdev->rx_status_q);
  1837. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1838. qdf_mem_zero(&pdev->ppdu_info, sizeof(pdev->ppdu_info));
  1839. /*
  1840. * Set last_ppdu_id to HAL_INVALID_PPDU_ID in order to avoid ppdu_id
  1841. * match with '0' ppdu_id from monitor status ring
  1842. */
  1843. pdev->ppdu_info.com_info.last_ppdu_id = HAL_INVALID_PPDU_ID;
  1844. qdf_mem_zero(&pdev->rx_mon_stats, sizeof(pdev->rx_mon_stats));
  1845. dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
  1846. &pdev->rx_mon_stats);
  1847. for (i = 0; i < MAX_MU_USERS; i++) {
  1848. qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
  1849. pdev->is_mpdu_hdr[i] = true;
  1850. }
  1851. qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
  1852. pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
  1853. }
  1854. void
  1855. dp_rx_pdev_mon_status_desc_pool_deinit(struct dp_pdev *pdev, uint32_t mac_id) {
  1856. uint8_t pdev_id = pdev->pdev_id;
  1857. struct dp_soc *soc = pdev->soc;
  1858. struct rx_desc_pool *rx_desc_pool;
  1859. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1860. dp_debug("Mon RX Desc status Pool[%d] deinit", pdev_id);
  1861. dp_rx_desc_pool_deinit(soc, rx_desc_pool);
  1862. }
  1863. void
  1864. dp_rx_pdev_mon_status_desc_pool_free(struct dp_pdev *pdev, uint32_t mac_id) {
  1865. uint8_t pdev_id = pdev->pdev_id;
  1866. struct dp_soc *soc = pdev->soc;
  1867. struct rx_desc_pool *rx_desc_pool;
  1868. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1869. dp_debug("Mon RX Status Desc Pool Free pdev[%d]", pdev_id);
  1870. dp_rx_desc_pool_free(soc, rx_desc_pool);
  1871. }
  1872. void
  1873. dp_rx_pdev_mon_status_buffers_free(struct dp_pdev *pdev, uint32_t mac_id)
  1874. {
  1875. uint8_t pdev_id = pdev->pdev_id;
  1876. struct dp_soc *soc = pdev->soc;
  1877. struct rx_desc_pool *rx_desc_pool;
  1878. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1879. dp_debug("Mon RX Status Desc Pool Free pdev[%d]", pdev_id);
  1880. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1881. }
  1882. /*
  1883. * dp_rx_buffers_replenish() - replenish monitor status ring with
  1884. * rx nbufs called during dp rx
  1885. * monitor status ring initialization
  1886. *
  1887. * @soc: core txrx main context
  1888. * @mac_id: mac_id which is one of 3 mac_ids
  1889. * @dp_rxdma_srng: dp monitor status circular ring
  1890. * @rx_desc_pool; Pointer to Rx descriptor pool
  1891. * @num_req_buffers: number of buffer to be replenished
  1892. * @desc_list: list of descs if called from dp rx monitor status
  1893. * process or NULL during dp rx initialization or
  1894. * out of buffer interrupt
  1895. * @tail: tail of descs list
  1896. * @owner: who owns the nbuf (host, NSS etc...)
  1897. * Return: return success or failure
  1898. */
  1899. static inline
  1900. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  1901. uint32_t mac_id,
  1902. struct dp_srng *dp_rxdma_srng,
  1903. struct rx_desc_pool *rx_desc_pool,
  1904. uint32_t num_req_buffers,
  1905. union dp_rx_desc_list_elem_t **desc_list,
  1906. union dp_rx_desc_list_elem_t **tail,
  1907. uint8_t owner)
  1908. {
  1909. uint32_t num_alloc_desc;
  1910. uint16_t num_desc_to_free = 0;
  1911. uint32_t num_entries_avail;
  1912. uint32_t count = 0;
  1913. int sync_hw_ptr = 1;
  1914. qdf_dma_addr_t paddr;
  1915. qdf_nbuf_t rx_netbuf;
  1916. void *rxdma_ring_entry;
  1917. union dp_rx_desc_list_elem_t *next;
  1918. void *rxdma_srng;
  1919. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(dp_soc, mac_id);
  1920. if (!dp_pdev) {
  1921. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1922. "pdev is null for mac_id = %d", mac_id);
  1923. return QDF_STATUS_E_FAILURE;
  1924. }
  1925. rxdma_srng = dp_rxdma_srng->hal_srng;
  1926. qdf_assert(rxdma_srng);
  1927. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1928. "[%s][%d] requested %d buffers for replenish",
  1929. __func__, __LINE__, num_req_buffers);
  1930. /*
  1931. * if desc_list is NULL, allocate the descs from freelist
  1932. */
  1933. if (!(*desc_list)) {
  1934. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  1935. rx_desc_pool,
  1936. num_req_buffers,
  1937. desc_list,
  1938. tail);
  1939. if (!num_alloc_desc) {
  1940. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1941. "[%s][%d] no free rx_descs in freelist",
  1942. __func__, __LINE__);
  1943. return QDF_STATUS_E_NOMEM;
  1944. }
  1945. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1946. "[%s][%d] %d rx desc allocated", __func__, __LINE__,
  1947. num_alloc_desc);
  1948. num_req_buffers = num_alloc_desc;
  1949. }
  1950. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  1951. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  1952. rxdma_srng, sync_hw_ptr);
  1953. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1954. "[%s][%d] no of available entries in rxdma ring: %d",
  1955. __func__, __LINE__, num_entries_avail);
  1956. if (num_entries_avail < num_req_buffers) {
  1957. num_desc_to_free = num_req_buffers - num_entries_avail;
  1958. num_req_buffers = num_entries_avail;
  1959. }
  1960. while (count <= num_req_buffers) {
  1961. rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
  1962. /*
  1963. * qdf_nbuf alloc or map failed,
  1964. * keep HP in mon_status_ring unchanged,
  1965. * wait dp_rx_mon_status_srng_process
  1966. * to fill in buffer at current HP.
  1967. */
  1968. if (qdf_unlikely(!rx_netbuf)) {
  1969. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1970. "%s: qdf_nbuf allocate or map fail, count %d",
  1971. __func__, count);
  1972. break;
  1973. }
  1974. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  1975. next = (*desc_list)->next;
  1976. rxdma_ring_entry = hal_srng_src_get_cur_hp_n_move_next(
  1977. dp_soc->hal_soc,
  1978. rxdma_srng);
  1979. if (qdf_unlikely(!rxdma_ring_entry)) {
  1980. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1981. "[%s][%d] rxdma_ring_entry is NULL, count - %d",
  1982. __func__, __LINE__, count);
  1983. qdf_nbuf_unmap_nbytes_single(dp_soc->osdev, rx_netbuf,
  1984. QDF_DMA_FROM_DEVICE,
  1985. rx_desc_pool->buf_size);
  1986. qdf_nbuf_free(rx_netbuf);
  1987. break;
  1988. }
  1989. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  1990. (*desc_list)->rx_desc.in_use = 1;
  1991. count++;
  1992. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  1993. (*desc_list)->rx_desc.cookie, owner);
  1994. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1995. "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
  1996. paddr=%pK",
  1997. __func__, __LINE__, &(*desc_list)->rx_desc,
  1998. (*desc_list)->rx_desc.cookie, rx_netbuf,
  1999. (void *)paddr);
  2000. *desc_list = next;
  2001. }
  2002. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  2003. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2004. "successfully replenished %d buffers", num_req_buffers);
  2005. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2006. "%d rx desc added back to free list", num_desc_to_free);
  2007. /*
  2008. * add any available free desc back to the free list
  2009. */
  2010. if (*desc_list) {
  2011. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  2012. mac_id, rx_desc_pool);
  2013. }
  2014. return QDF_STATUS_SUCCESS;
  2015. }