dp_rx_mon_status.c 55 KB

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