dp_rx_mon_status.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  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. dp_rx_mon_dest_process(soc, mac_id, quota);
  1309. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1310. }
  1311. }
  1312. return;
  1313. }
  1314. /*
  1315. * dp_rx_mon_status_srng_process() - Process monitor status ring
  1316. * post the status ring buffer to Rx status Queue for later
  1317. * processing when status ring is filled with status TLV.
  1318. * Allocate a new buffer to status ring if the filled buffer
  1319. * is posted.
  1320. *
  1321. * @soc: core txrx main context
  1322. * @mac_id: mac_id which is one of 3 mac_ids
  1323. * @quota: No. of ring entry that can be serviced in one shot.
  1324. * Return: uint32_t: No. of ring entry that is processed.
  1325. */
  1326. static inline uint32_t
  1327. dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
  1328. uint32_t quota)
  1329. {
  1330. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  1331. hal_soc_handle_t hal_soc;
  1332. void *mon_status_srng;
  1333. void *rxdma_mon_status_ring_entry;
  1334. QDF_STATUS status;
  1335. uint32_t work_done = 0;
  1336. int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  1337. mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
  1338. qdf_assert(mon_status_srng);
  1339. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  1340. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1341. "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
  1342. __func__, __LINE__, mon_status_srng);
  1343. return work_done;
  1344. }
  1345. hal_soc = soc->hal_soc;
  1346. qdf_assert(hal_soc);
  1347. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
  1348. goto done;
  1349. /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
  1350. * BUFFER_ADDR_INFO STRUCT
  1351. */
  1352. while (qdf_likely((rxdma_mon_status_ring_entry =
  1353. hal_srng_src_peek(hal_soc, mon_status_srng))
  1354. && quota--)) {
  1355. uint32_t rx_buf_cookie;
  1356. qdf_nbuf_t status_nbuf;
  1357. struct dp_rx_desc *rx_desc;
  1358. uint8_t *status_buf;
  1359. qdf_dma_addr_t paddr;
  1360. uint64_t buf_addr;
  1361. buf_addr =
  1362. (HAL_RX_BUFFER_ADDR_31_0_GET(
  1363. rxdma_mon_status_ring_entry) |
  1364. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
  1365. rxdma_mon_status_ring_entry)) << 32));
  1366. if (qdf_likely(buf_addr)) {
  1367. rx_buf_cookie =
  1368. HAL_RX_BUF_COOKIE_GET(
  1369. rxdma_mon_status_ring_entry);
  1370. rx_desc = dp_rx_cookie_2_va_mon_status(soc,
  1371. rx_buf_cookie);
  1372. qdf_assert(rx_desc);
  1373. status_nbuf = rx_desc->nbuf;
  1374. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  1375. QDF_DMA_FROM_DEVICE);
  1376. status_buf = qdf_nbuf_data(status_nbuf);
  1377. status = hal_get_rx_status_done(status_buf);
  1378. if (status != QDF_STATUS_SUCCESS) {
  1379. uint32_t hp, tp;
  1380. hal_get_sw_hptp(hal_soc, mon_status_srng,
  1381. &tp, &hp);
  1382. dp_info_rl("tlv tag status error hp:%u, tp:%u",
  1383. hp, tp);
  1384. pdev->rx_mon_stats.tlv_tag_status_err++;
  1385. /* WAR for missing status: Skip status entry */
  1386. hal_srng_src_get_next(hal_soc, mon_status_srng);
  1387. continue;
  1388. }
  1389. qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
  1390. qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
  1391. QDF_DMA_FROM_DEVICE);
  1392. /* Put the status_nbuf to queue */
  1393. qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
  1394. } else {
  1395. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1396. union dp_rx_desc_list_elem_t *tail = NULL;
  1397. struct rx_desc_pool *rx_desc_pool;
  1398. uint32_t num_alloc_desc;
  1399. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1400. num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
  1401. rx_desc_pool,
  1402. 1,
  1403. &desc_list,
  1404. &tail);
  1405. /*
  1406. * No free descriptors available
  1407. */
  1408. if (qdf_unlikely(num_alloc_desc == 0)) {
  1409. work_done++;
  1410. break;
  1411. }
  1412. rx_desc = &desc_list->rx_desc;
  1413. }
  1414. status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
  1415. /*
  1416. * qdf_nbuf alloc or map failed,
  1417. * free the dp rx desc to free list,
  1418. * fill in NULL dma address at current HP entry,
  1419. * keep HP in mon_status_ring unchanged,
  1420. * wait next time dp_rx_mon_status_srng_process
  1421. * to fill in buffer at current HP.
  1422. */
  1423. if (qdf_unlikely(!status_nbuf)) {
  1424. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1425. union dp_rx_desc_list_elem_t *tail = NULL;
  1426. struct rx_desc_pool *rx_desc_pool;
  1427. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1428. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1429. "%s: fail to allocate or map qdf_nbuf",
  1430. __func__);
  1431. dp_rx_add_to_free_desc_list(&desc_list,
  1432. &tail, rx_desc);
  1433. dp_rx_add_desc_list_to_free_list(soc, &desc_list,
  1434. &tail, mac_id, rx_desc_pool);
  1435. hal_rxdma_buff_addr_info_set(
  1436. rxdma_mon_status_ring_entry,
  1437. 0, 0, HAL_RX_BUF_RBM_SW3_BM);
  1438. work_done++;
  1439. break;
  1440. }
  1441. paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
  1442. rx_desc->nbuf = status_nbuf;
  1443. rx_desc->in_use = 1;
  1444. hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
  1445. paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
  1446. hal_srng_src_get_next(hal_soc, mon_status_srng);
  1447. work_done++;
  1448. }
  1449. done:
  1450. hal_srng_access_end(hal_soc, mon_status_srng);
  1451. return work_done;
  1452. }
  1453. /*
  1454. * dp_rx_mon_status_process() - Process monitor status ring and
  1455. * TLV in status ring.
  1456. *
  1457. * @soc: core txrx main context
  1458. * @mac_id: mac_id which is one of 3 mac_ids
  1459. * @quota: No. of ring entry that can be serviced in one shot.
  1460. * Return: uint32_t: No. of ring entry that is processed.
  1461. */
  1462. static inline uint32_t
  1463. dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  1464. uint32_t work_done;
  1465. work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
  1466. quota -= work_done;
  1467. dp_rx_mon_status_process_tlv(soc, mac_id, quota);
  1468. return work_done;
  1469. }
  1470. /**
  1471. * dp_mon_process() - Main monitor mode processing roution.
  1472. * This call monitor status ring process then monitor
  1473. * destination ring process.
  1474. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  1475. * @soc: core txrx main context
  1476. * @mac_id: mac_id which is one of 3 mac_ids
  1477. * @quota: No. of status ring entry that can be serviced in one shot.
  1478. * Return: uint32_t: No. of ring entry that is processed.
  1479. */
  1480. uint32_t
  1481. dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  1482. return dp_rx_mon_status_process(soc, mac_id, quota);
  1483. }
  1484. /**
  1485. * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
  1486. * @pdev: core txrx pdev context
  1487. * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
  1488. *
  1489. * This function will detach DP RX status ring from
  1490. * main device context. will free DP Rx resources for
  1491. * status ring
  1492. *
  1493. * Return: QDF_STATUS_SUCCESS: success
  1494. * QDF_STATUS_E_RESOURCES: Error return
  1495. */
  1496. QDF_STATUS
  1497. dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
  1498. {
  1499. struct dp_soc *soc = pdev->soc;
  1500. struct rx_desc_pool *rx_desc_pool;
  1501. rx_desc_pool = &soc->rx_desc_status[mac_id];
  1502. if (rx_desc_pool->pool_size != 0) {
  1503. if (!dp_is_soc_reinit(soc))
  1504. dp_rx_desc_nbuf_and_pool_free(soc, mac_id,
  1505. rx_desc_pool);
  1506. else
  1507. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1508. }
  1509. return QDF_STATUS_SUCCESS;
  1510. }
  1511. /*
  1512. * dp_rx_buffers_replenish() - replenish monitor status ring with
  1513. * rx nbufs called during dp rx
  1514. * monitor status ring initialization
  1515. *
  1516. * @soc: core txrx main context
  1517. * @mac_id: mac_id which is one of 3 mac_ids
  1518. * @dp_rxdma_srng: dp monitor status circular ring
  1519. * @rx_desc_pool; Pointer to Rx descriptor pool
  1520. * @num_req_buffers: number of buffer to be replenished
  1521. * @desc_list: list of descs if called from dp rx monitor status
  1522. * process or NULL during dp rx initialization or
  1523. * out of buffer interrupt
  1524. * @tail: tail of descs list
  1525. * @owner: who owns the nbuf (host, NSS etc...)
  1526. * Return: return success or failure
  1527. */
  1528. static inline
  1529. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  1530. uint32_t mac_id,
  1531. struct dp_srng *dp_rxdma_srng,
  1532. struct rx_desc_pool *rx_desc_pool,
  1533. uint32_t num_req_buffers,
  1534. union dp_rx_desc_list_elem_t **desc_list,
  1535. union dp_rx_desc_list_elem_t **tail,
  1536. uint8_t owner)
  1537. {
  1538. uint32_t num_alloc_desc;
  1539. uint16_t num_desc_to_free = 0;
  1540. uint32_t num_entries_avail;
  1541. uint32_t count = 0;
  1542. int sync_hw_ptr = 1;
  1543. qdf_dma_addr_t paddr;
  1544. qdf_nbuf_t rx_netbuf;
  1545. void *rxdma_ring_entry;
  1546. union dp_rx_desc_list_elem_t *next;
  1547. void *rxdma_srng;
  1548. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
  1549. rxdma_srng = dp_rxdma_srng->hal_srng;
  1550. qdf_assert(rxdma_srng);
  1551. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1552. "[%s][%d] requested %d buffers for replenish",
  1553. __func__, __LINE__, num_req_buffers);
  1554. /*
  1555. * if desc_list is NULL, allocate the descs from freelist
  1556. */
  1557. if (!(*desc_list)) {
  1558. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  1559. rx_desc_pool,
  1560. num_req_buffers,
  1561. desc_list,
  1562. tail);
  1563. if (!num_alloc_desc) {
  1564. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1565. "[%s][%d] no free rx_descs in freelist",
  1566. __func__, __LINE__);
  1567. return QDF_STATUS_E_NOMEM;
  1568. }
  1569. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1570. "[%s][%d] %d rx desc allocated", __func__, __LINE__,
  1571. num_alloc_desc);
  1572. num_req_buffers = num_alloc_desc;
  1573. }
  1574. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  1575. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  1576. rxdma_srng, sync_hw_ptr);
  1577. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1578. "[%s][%d] no of available entries in rxdma ring: %d",
  1579. __func__, __LINE__, num_entries_avail);
  1580. if (num_entries_avail < num_req_buffers) {
  1581. num_desc_to_free = num_req_buffers - num_entries_avail;
  1582. num_req_buffers = num_entries_avail;
  1583. }
  1584. while (count < num_req_buffers) {
  1585. rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
  1586. /*
  1587. * qdf_nbuf alloc or map failed,
  1588. * keep HP in mon_status_ring unchanged,
  1589. * wait dp_rx_mon_status_srng_process
  1590. * to fill in buffer at current HP.
  1591. */
  1592. if (qdf_unlikely(!rx_netbuf)) {
  1593. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1594. "%s: qdf_nbuf allocate or map fail, count %d",
  1595. __func__, count);
  1596. break;
  1597. }
  1598. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  1599. next = (*desc_list)->next;
  1600. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  1601. rxdma_srng);
  1602. if (qdf_unlikely(!rxdma_ring_entry)) {
  1603. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1604. "[%s][%d] rxdma_ring_entry is NULL, count - %d",
  1605. __func__, __LINE__, count);
  1606. qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
  1607. QDF_DMA_FROM_DEVICE);
  1608. qdf_nbuf_free(rx_netbuf);
  1609. break;
  1610. }
  1611. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  1612. (*desc_list)->rx_desc.in_use = 1;
  1613. count++;
  1614. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  1615. (*desc_list)->rx_desc.cookie, owner);
  1616. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1617. "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
  1618. paddr=%pK",
  1619. __func__, __LINE__, &(*desc_list)->rx_desc,
  1620. (*desc_list)->rx_desc.cookie, rx_netbuf,
  1621. (void *)paddr);
  1622. *desc_list = next;
  1623. }
  1624. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  1625. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1626. "successfully replenished %d buffers", num_req_buffers);
  1627. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1628. "%d rx desc added back to free list", num_desc_to_free);
  1629. /*
  1630. * add any available free desc back to the free list
  1631. */
  1632. if (*desc_list) {
  1633. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  1634. mac_id, rx_desc_pool);
  1635. }
  1636. return QDF_STATUS_SUCCESS;
  1637. }
  1638. /**
  1639. * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
  1640. * @pdev: core txrx pdev context
  1641. * @ring_id: ring number
  1642. * This function will attach a DP RX monitor status ring into pDEV
  1643. * and replenish monitor status ring with buffer.
  1644. *
  1645. * Return: QDF_STATUS_SUCCESS: success
  1646. * QDF_STATUS_E_RESOURCES: Error return
  1647. */
  1648. QDF_STATUS
  1649. dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
  1650. struct dp_soc *soc = pdev->soc;
  1651. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1652. union dp_rx_desc_list_elem_t *tail = NULL;
  1653. struct dp_srng *mon_status_ring;
  1654. uint32_t num_entries;
  1655. uint32_t i;
  1656. struct rx_desc_pool *rx_desc_pool;
  1657. QDF_STATUS status;
  1658. int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
  1659. mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
  1660. num_entries = mon_status_ring->num_entries;
  1661. rx_desc_pool = &soc->rx_desc_status[ring_id];
  1662. dp_info("Mon RX Status Pool[%d] entries=%d",
  1663. ring_id, num_entries);
  1664. status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
  1665. rx_desc_pool);
  1666. if (!QDF_IS_STATUS_SUCCESS(status))
  1667. return status;
  1668. dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
  1669. status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
  1670. mon_status_ring,
  1671. rx_desc_pool,
  1672. num_entries,
  1673. &desc_list, &tail,
  1674. HAL_RX_BUF_RBM_SW3_BM);
  1675. if (!QDF_IS_STATUS_SUCCESS(status))
  1676. return status;
  1677. qdf_nbuf_queue_init(&pdev->rx_status_q);
  1678. qdf_nbuf_queue_init(&pdev->rx_ppdu_buf_q);
  1679. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1680. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  1681. sizeof(pdev->ppdu_info.rx_status));
  1682. qdf_mem_zero(&pdev->rx_mon_stats,
  1683. sizeof(pdev->rx_mon_stats));
  1684. dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
  1685. &pdev->rx_mon_stats);
  1686. for (i = 0; i < MAX_MU_USERS; i++) {
  1687. qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
  1688. pdev->is_mpdu_hdr[i] = true;
  1689. }
  1690. qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
  1691. pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
  1692. return QDF_STATUS_SUCCESS;
  1693. }