dp_rx_mon_status.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. /*
  2. * Copyright (c) 2017-2019 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. #ifdef FEATURE_PERPKT_INFO
  31. #include "dp_ratetable.h"
  32. #endif
  33. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  34. #include "dp_rx_mon_feature.h"
  35. #else
  36. static QDF_STATUS
  37. dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  38. struct hal_rx_ppdu_info *ppdu_info)
  39. {
  40. return QDF_STATUS_SUCCESS;
  41. }
  42. static void
  43. dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
  44. qdf_nbuf_t status_nbuf,
  45. struct hal_rx_ppdu_info *ppdu_info,
  46. bool *nbuf_used)
  47. {
  48. }
  49. #endif
  50. #ifdef FEATURE_PERPKT_INFO
  51. static inline void
  52. dp_rx_populate_rx_rssi_chain(struct hal_rx_ppdu_info *ppdu_info,
  53. struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
  54. {
  55. uint8_t chain, bw;
  56. int8_t rssi;
  57. for (chain = 0; chain < SS_COUNT; chain++) {
  58. for (bw = 0; bw < MAX_BW; bw++) {
  59. rssi = ppdu_info->rx_status.rssi_chain[chain][bw];
  60. if (rssi != DP_RSSI_INVAL)
  61. cdp_rx_ppdu->rssi_chain[chain][bw] = rssi;
  62. else
  63. cdp_rx_ppdu->rssi_chain[chain][bw] = 0;
  64. }
  65. }
  66. }
  67. /**
  68. * dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
  69. * @pdev: pdev ctx
  70. * @ppdu_info: ppdu info structure from ppdu ring
  71. * @ppdu_nbuf: qdf nbuf abstraction for linux skb
  72. *
  73. * Return: none
  74. */
  75. static inline void
  76. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  77. struct hal_rx_ppdu_info *ppdu_info,
  78. qdf_nbuf_t ppdu_nbuf)
  79. {
  80. struct dp_peer *peer;
  81. struct dp_soc *soc = pdev->soc;
  82. struct dp_ast_entry *ast_entry;
  83. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  84. uint32_t ast_index;
  85. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  86. cdp_rx_ppdu->first_data_seq_ctrl =
  87. ppdu_info->rx_status.first_data_seq_ctrl;
  88. cdp_rx_ppdu->frame_ctrl =
  89. ppdu_info->rx_status.frame_control;
  90. cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
  91. cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
  92. cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
  93. cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
  94. cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
  95. cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
  96. cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
  97. cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
  98. cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
  99. if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
  100. (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
  101. cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
  102. else
  103. cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
  104. cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
  105. cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
  106. cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
  107. cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
  108. QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
  109. cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
  110. cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
  111. cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
  112. cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
  113. cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
  114. cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
  115. cdp_rx_ppdu->udp_msdu_count +
  116. cdp_rx_ppdu->other_msdu_count);
  117. cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
  118. cdp_rx_ppdu->retries = CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl) ?
  119. ppdu_info->com_info.mpdu_cnt_fcs_ok : 0;
  120. if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
  121. cdp_rx_ppdu->is_ampdu = 1;
  122. else
  123. cdp_rx_ppdu->is_ampdu = 0;
  124. cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
  125. cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
  126. ast_index = ppdu_info->rx_status.ast_index;
  127. if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  128. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  129. return;
  130. }
  131. ast_entry = soc->ast_table[ast_index];
  132. if (!ast_entry) {
  133. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  134. return;
  135. }
  136. peer = ast_entry->peer;
  137. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  138. cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
  139. return;
  140. }
  141. qdf_mem_copy(cdp_rx_ppdu->mac_addr,
  142. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  143. cdp_rx_ppdu->peer_id = peer->peer_ids[0];
  144. cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
  145. cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
  146. dp_rx_populate_rx_rssi_chain(ppdu_info, cdp_rx_ppdu);
  147. }
  148. #else
  149. static inline void
  150. dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
  151. struct hal_rx_ppdu_info *ppdu_info,
  152. qdf_nbuf_t ppdu_nbuf)
  153. {
  154. }
  155. #endif
  156. /**
  157. * dp_rx_stats_update() - Update per-peer statistics
  158. * @soc: Datapath SOC handle
  159. * @peer: Datapath peer handle
  160. * @ppdu: PPDU Descriptor
  161. *
  162. * Return: None
  163. */
  164. #ifdef FEATURE_PERPKT_INFO
  165. static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
  166. struct cdp_rx_indication_ppdu *ppdu)
  167. {
  168. uint32_t ratekbps = 0;
  169. uint32_t ppdu_rx_rate = 0;
  170. uint32_t nss = 0;
  171. uint32_t rix;
  172. if (!peer || !ppdu)
  173. return;
  174. if (ppdu->u.nss == 0)
  175. nss = 0;
  176. else
  177. nss = ppdu->u.nss - 1;
  178. ratekbps = dp_getrateindex(ppdu->u.gi,
  179. ppdu->u.mcs,
  180. nss,
  181. ppdu->u.preamble,
  182. ppdu->u.bw,
  183. &rix);
  184. if (!ratekbps)
  185. return;
  186. ppdu->rix = rix;
  187. DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
  188. dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
  189. ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
  190. DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
  191. ppdu->rx_ratekbps = ratekbps;
  192. if (peer->vdev)
  193. peer->vdev->stats.rx.last_rx_rate = ratekbps;
  194. }
  195. static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
  196. struct cdp_rx_indication_ppdu *ppdu)
  197. {
  198. struct dp_soc *soc = NULL;
  199. uint8_t mcs, preamble, ac = 0;
  200. uint16_t num_msdu;
  201. bool is_invalid_peer = false;
  202. mcs = ppdu->u.mcs;
  203. preamble = ppdu->u.preamble;
  204. num_msdu = ppdu->num_msdu;
  205. if (pdev)
  206. soc = pdev->soc;
  207. else
  208. return;
  209. if (!peer) {
  210. is_invalid_peer = true;
  211. peer = pdev->invalid_peer;
  212. }
  213. if (!soc || soc->process_rx_status)
  214. return;
  215. DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
  216. if (peer->stats.rx.avg_rssi == INVALID_RSSI)
  217. peer->stats.rx.avg_rssi = ppdu->rssi;
  218. else
  219. peer->stats.rx.avg_rssi =
  220. DP_GET_AVG_RSSI(peer->stats.rx.avg_rssi, ppdu->rssi);
  221. if ((preamble == DOT11_A) || (preamble == DOT11_B))
  222. ppdu->u.nss = 1;
  223. if (ppdu->u.nss)
  224. DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
  225. DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
  226. DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
  227. DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
  228. DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
  229. DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
  230. DP_STATS_UPD(peer, rx.rx_rate, mcs);
  231. DP_STATS_INCC(peer,
  232. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  233. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  234. DP_STATS_INCC(peer,
  235. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  236. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  237. DP_STATS_INCC(peer,
  238. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  239. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  240. DP_STATS_INCC(peer,
  241. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  242. ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
  243. DP_STATS_INCC(peer,
  244. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  245. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  246. DP_STATS_INCC(peer,
  247. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  248. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  249. DP_STATS_INCC(peer,
  250. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  251. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  252. DP_STATS_INCC(peer,
  253. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  254. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  255. DP_STATS_INCC(peer,
  256. rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
  257. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  258. DP_STATS_INCC(peer,
  259. rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  260. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  261. /*
  262. * If invalid TID, it could be a non-qos frame, hence do not update
  263. * any AC counters
  264. */
  265. ac = TID_TO_WME_AC(ppdu->tid);
  266. if (ppdu->tid != HAL_TID_INVALID)
  267. DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
  268. dp_peer_stats_notify(peer);
  269. DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
  270. if (is_invalid_peer)
  271. return;
  272. if (dp_is_subtype_data(ppdu->frame_ctrl))
  273. dp_rx_rate_stats_update(peer, ppdu);
  274. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  275. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  276. &peer->stats, ppdu->peer_id,
  277. UPDATE_PEER_STATS, pdev->pdev_id);
  278. #endif
  279. }
  280. #endif
  281. /**
  282. * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
  283. * @soc: core txrx main context
  284. * @pdev: pdev strcuture
  285. * @ppdu_info: structure for rx ppdu ring
  286. *
  287. * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
  288. * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
  289. */
  290. #ifdef FEATURE_PERPKT_INFO
  291. static inline QDF_STATUS
  292. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  293. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  294. {
  295. uint8_t size = 0;
  296. struct ieee80211_frame *wh;
  297. uint32_t *nbuf_data;
  298. if (!ppdu_info->msdu_info.first_msdu_payload)
  299. return QDF_STATUS_SUCCESS;
  300. if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
  301. return QDF_STATUS_SUCCESS;
  302. pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
  303. wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
  304. + 4);
  305. size = (ppdu_info->msdu_info.first_msdu_payload -
  306. qdf_nbuf_data(nbuf));
  307. ppdu_info->msdu_info.first_msdu_payload = NULL;
  308. if (qdf_nbuf_pull_head(nbuf, size) == NULL)
  309. return QDF_STATUS_SUCCESS;
  310. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  311. IEEE80211_FC0_TYPE_MGT) ||
  312. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  313. IEEE80211_FC0_TYPE_CTL)) {
  314. return QDF_STATUS_SUCCESS;
  315. }
  316. nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
  317. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  318. /* only retain RX MSDU payload in the skb */
  319. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
  320. ppdu_info->msdu_info.payload_len);
  321. dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
  322. nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
  323. return QDF_STATUS_E_ALREADY;
  324. }
  325. #else
  326. static inline QDF_STATUS
  327. dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  328. struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
  329. {
  330. return QDF_STATUS_SUCCESS;
  331. }
  332. #endif
  333. /**
  334. * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
  335. * @soc: Datapath SOC handle
  336. * @pdev: Datapath PDEV handle
  337. * @ppdu_info: Structure for rx ppdu info
  338. * @nbuf: Qdf nbuf abstraction for linux skb
  339. *
  340. * Return: 0 on success, 1 on failure
  341. */
  342. static inline int
  343. dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
  344. struct hal_rx_ppdu_info *ppdu_info,
  345. qdf_nbuf_t nbuf)
  346. {
  347. uint8_t size = 0;
  348. if (!pdev->monitor_vdev) {
  349. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  350. "[%s]:[%d] Monitor vdev is NULL !!",
  351. __func__, __LINE__);
  352. return 1;
  353. }
  354. if (!ppdu_info->msdu_info.first_msdu_payload) {
  355. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  356. "[%s]:[%d] First msdu payload not present",
  357. __func__, __LINE__);
  358. return 1;
  359. }
  360. /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
  361. size = (ppdu_info->msdu_info.first_msdu_payload -
  362. qdf_nbuf_data(nbuf)) + 4;
  363. ppdu_info->msdu_info.first_msdu_payload = NULL;
  364. if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
  365. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  366. "[%s]:[%d] No header present",
  367. __func__, __LINE__);
  368. return 1;
  369. }
  370. /* Only retain RX MSDU payload in the skb */
  371. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
  372. ppdu_info->msdu_info.payload_len);
  373. qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
  374. nbuf, sizeof(struct rx_pkt_tlvs));
  375. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  376. nbuf, NULL);
  377. pdev->ppdu_info.rx_status.monitor_direct_used = 0;
  378. return 0;
  379. }
  380. /**
  381. * dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
  382. * @soc: core txrx main context
  383. * @pdev: pdev strcuture
  384. * @ppdu_info: structure for rx ppdu ring
  385. *
  386. * Return: none
  387. */
  388. #ifdef FEATURE_PERPKT_INFO
  389. static inline void
  390. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  391. struct hal_rx_ppdu_info *ppdu_info)
  392. {
  393. qdf_nbuf_t ppdu_nbuf;
  394. struct dp_peer *peer;
  395. struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
  396. /*
  397. * Do not allocate if fcs error,
  398. * ast idx invalid / fctl invalid
  399. */
  400. if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
  401. return;
  402. if (ppdu_info->nac_info.fc_valid &&
  403. ppdu_info->nac_info.to_ds_flag &&
  404. ppdu_info->nac_info.mac_addr2_valid) {
  405. struct dp_neighbour_peer *peer = NULL;
  406. uint8_t rssi = ppdu_info->rx_status.rssi_comb;
  407. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  408. if (pdev->neighbour_peers_added) {
  409. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  410. neighbour_peer_list_elem) {
  411. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
  412. &ppdu_info->nac_info.mac_addr2,
  413. QDF_MAC_ADDR_SIZE)) {
  414. peer->rssi = rssi;
  415. break;
  416. }
  417. }
  418. }
  419. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  420. }
  421. /* need not generate wdi event when mcopy and
  422. * enhanced stats are not enabled
  423. */
  424. if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
  425. return;
  426. if (!pdev->mcopy_mode) {
  427. if (!ppdu_info->rx_status.frame_control_info_valid)
  428. return;
  429. if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
  430. return;
  431. }
  432. ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
  433. sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
  434. if (ppdu_nbuf) {
  435. dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
  436. qdf_nbuf_put_tail(ppdu_nbuf,
  437. sizeof(struct cdp_rx_indication_ppdu));
  438. cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
  439. peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
  440. if (peer) {
  441. cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
  442. dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
  443. dp_peer_unref_del_find_by_id(peer);
  444. }
  445. if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
  446. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
  447. soc, ppdu_nbuf,
  448. cdp_rx_ppdu->peer_id,
  449. WDI_NO_VAL, pdev->pdev_id);
  450. } else if (pdev->mcopy_mode) {
  451. dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
  452. ppdu_nbuf, HTT_INVALID_PEER,
  453. WDI_NO_VAL, pdev->pdev_id);
  454. } else {
  455. qdf_nbuf_free(ppdu_nbuf);
  456. }
  457. }
  458. }
  459. #else
  460. static inline void
  461. dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
  462. struct hal_rx_ppdu_info *ppdu_info)
  463. {
  464. }
  465. #endif
  466. /**
  467. * dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
  468. * filtering enabled
  469. * @soc: core txrx main context
  470. * @ppdu_info: Structure for rx ppdu info
  471. * @status_nbuf: Qdf nbuf abstraction for linux skb
  472. * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
  473. *
  474. * Return: none
  475. */
  476. static inline void
  477. dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
  478. struct hal_rx_ppdu_info *ppdu_info,
  479. qdf_nbuf_t status_nbuf, uint32_t mac_id)
  480. {
  481. struct dp_peer *peer;
  482. struct dp_ast_entry *ast_entry;
  483. uint32_t ast_index;
  484. ast_index = ppdu_info->rx_status.ast_index;
  485. if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
  486. ast_entry = soc->ast_table[ast_index];
  487. if (ast_entry) {
  488. peer = ast_entry->peer;
  489. if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
  490. if (peer->peer_based_pktlog_filter) {
  491. dp_wdi_event_handler(
  492. WDI_EVENT_RX_DESC, soc,
  493. status_nbuf,
  494. peer->peer_ids[0],
  495. WDI_NO_VAL, mac_id);
  496. }
  497. }
  498. }
  499. }
  500. }
  501. /**
  502. * dp_rx_mon_status_process_tlv() - Process status TLV in status
  503. * buffer on Rx status Queue posted by status SRNG processing.
  504. * @soc: core txrx main context
  505. * @mac_id: mac_id which is one of 3 mac_ids _ring
  506. *
  507. * Return: none
  508. */
  509. static inline void
  510. dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
  511. uint32_t quota)
  512. {
  513. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  514. struct hal_rx_ppdu_info *ppdu_info;
  515. qdf_nbuf_t status_nbuf;
  516. uint8_t *rx_tlv;
  517. uint8_t *rx_tlv_start;
  518. uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
  519. QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
  520. QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
  521. struct cdp_pdev_mon_stats *rx_mon_stats;
  522. int smart_mesh_status;
  523. enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
  524. bool nbuf_used;
  525. uint32_t rx_enh_capture_mode;
  526. ppdu_info = &pdev->ppdu_info;
  527. rx_mon_stats = &pdev->rx_mon_stats;
  528. if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
  529. return;
  530. rx_enh_capture_mode = pdev->rx_enh_capture_mode;
  531. while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
  532. status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
  533. rx_tlv = qdf_nbuf_data(status_nbuf);
  534. rx_tlv_start = rx_tlv;
  535. nbuf_used = false;
  536. if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
  537. pdev->mcopy_mode ||
  538. (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  539. do {
  540. tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
  541. ppdu_info, pdev->soc->hal_soc);
  542. dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
  543. rx_mon_stats);
  544. dp_rx_mon_enh_capture_process(pdev, tlv_status,
  545. status_nbuf, ppdu_info,
  546. &nbuf_used);
  547. rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
  548. if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
  549. break;
  550. } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
  551. (tlv_status == HAL_TLV_STATUS_HEADER) ||
  552. (tlv_status == HAL_TLV_STATUS_MPDU_END) ||
  553. (tlv_status == HAL_TLV_STATUS_MSDU_END));
  554. }
  555. if (pdev->dp_peer_based_pktlog) {
  556. dp_rx_process_peer_based_pktlog(soc, ppdu_info,
  557. status_nbuf, mac_id);
  558. } else {
  559. if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
  560. pktlog_mode = WDI_EVENT_RX_DESC;
  561. else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
  562. pktlog_mode = WDI_EVENT_LITE_RX;
  563. if (pktlog_mode != WDI_NO_VAL)
  564. dp_wdi_event_handler(pktlog_mode, soc,
  565. status_nbuf,
  566. HTT_INVALID_PEER,
  567. WDI_NO_VAL, mac_id);
  568. }
  569. /* smart monitor vap and m_copy cannot co-exist */
  570. if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
  571. && pdev->monitor_vdev) {
  572. smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
  573. pdev, ppdu_info, status_nbuf);
  574. if (smart_mesh_status)
  575. qdf_nbuf_free(status_nbuf);
  576. } else if (pdev->mcopy_mode) {
  577. m_copy_status = dp_rx_handle_mcopy_mode(soc,
  578. pdev, ppdu_info, status_nbuf);
  579. if (m_copy_status == QDF_STATUS_SUCCESS)
  580. qdf_nbuf_free(status_nbuf);
  581. } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
  582. if (!nbuf_used)
  583. qdf_nbuf_free(status_nbuf);
  584. if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
  585. enh_log_status =
  586. dp_rx_handle_enh_capture(soc,
  587. pdev, ppdu_info);
  588. } else {
  589. qdf_nbuf_free(status_nbuf);
  590. }
  591. if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
  592. dp_rx_mon_deliver_non_std(soc, mac_id);
  593. } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
  594. rx_mon_stats->status_ppdu_done++;
  595. if (pdev->enhanced_stats_en ||
  596. pdev->mcopy_mode || pdev->neighbour_peers_added)
  597. dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
  598. pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
  599. dp_rx_mon_dest_process(soc, mac_id, quota);
  600. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  601. }
  602. }
  603. return;
  604. }
  605. /*
  606. * dp_rx_mon_status_srng_process() - Process monitor status ring
  607. * post the status ring buffer to Rx status Queue for later
  608. * processing when status ring is filled with status TLV.
  609. * Allocate a new buffer to status ring if the filled buffer
  610. * is posted.
  611. *
  612. * @soc: core txrx main context
  613. * @mac_id: mac_id which is one of 3 mac_ids
  614. * @quota: No. of ring entry that can be serviced in one shot.
  615. * Return: uint32_t: No. of ring entry that is processed.
  616. */
  617. static inline uint32_t
  618. dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
  619. uint32_t quota)
  620. {
  621. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  622. void *hal_soc;
  623. void *mon_status_srng;
  624. void *rxdma_mon_status_ring_entry;
  625. QDF_STATUS status;
  626. uint32_t work_done = 0;
  627. int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  628. mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
  629. qdf_assert(mon_status_srng);
  630. if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
  631. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  632. "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
  633. __func__, __LINE__, mon_status_srng);
  634. return work_done;
  635. }
  636. hal_soc = soc->hal_soc;
  637. qdf_assert(hal_soc);
  638. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
  639. goto done;
  640. /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
  641. * BUFFER_ADDR_INFO STRUCT
  642. */
  643. while (qdf_likely((rxdma_mon_status_ring_entry =
  644. hal_srng_src_peek(hal_soc, mon_status_srng))
  645. && quota--)) {
  646. uint32_t rx_buf_cookie;
  647. qdf_nbuf_t status_nbuf;
  648. struct dp_rx_desc *rx_desc;
  649. uint8_t *status_buf;
  650. qdf_dma_addr_t paddr;
  651. uint64_t buf_addr;
  652. buf_addr =
  653. (HAL_RX_BUFFER_ADDR_31_0_GET(
  654. rxdma_mon_status_ring_entry) |
  655. ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
  656. rxdma_mon_status_ring_entry)) << 32));
  657. if (qdf_likely(buf_addr)) {
  658. rx_buf_cookie =
  659. HAL_RX_BUF_COOKIE_GET(
  660. rxdma_mon_status_ring_entry);
  661. rx_desc = dp_rx_cookie_2_va_mon_status(soc,
  662. rx_buf_cookie);
  663. qdf_assert(rx_desc);
  664. status_nbuf = rx_desc->nbuf;
  665. qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
  666. QDF_DMA_FROM_DEVICE);
  667. status_buf = qdf_nbuf_data(status_nbuf);
  668. status = hal_get_rx_status_done(status_buf);
  669. if (status != QDF_STATUS_SUCCESS) {
  670. uint32_t hp, tp;
  671. hal_get_sw_hptp(hal_soc, mon_status_srng,
  672. &tp, &hp);
  673. QDF_TRACE(QDF_MODULE_ID_DP,
  674. QDF_TRACE_LEVEL_ERROR,
  675. "[%s][%d] status not done - hp:%u, tp:%u",
  676. __func__, __LINE__, hp, tp);
  677. /* WAR for missing status: Skip status entry */
  678. hal_srng_src_get_next(hal_soc, mon_status_srng);
  679. continue;
  680. }
  681. qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
  682. qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
  683. QDF_DMA_FROM_DEVICE);
  684. /* Put the status_nbuf to queue */
  685. qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
  686. } else {
  687. union dp_rx_desc_list_elem_t *desc_list = NULL;
  688. union dp_rx_desc_list_elem_t *tail = NULL;
  689. struct rx_desc_pool *rx_desc_pool;
  690. uint32_t num_alloc_desc;
  691. rx_desc_pool = &soc->rx_desc_status[mac_id];
  692. num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
  693. rx_desc_pool,
  694. 1,
  695. &desc_list,
  696. &tail);
  697. /*
  698. * No free descriptors available
  699. */
  700. if (qdf_unlikely(num_alloc_desc == 0)) {
  701. work_done++;
  702. break;
  703. }
  704. rx_desc = &desc_list->rx_desc;
  705. }
  706. status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
  707. /*
  708. * qdf_nbuf alloc or map failed,
  709. * free the dp rx desc to free list,
  710. * fill in NULL dma address at current HP entry,
  711. * keep HP in mon_status_ring unchanged,
  712. * wait next time dp_rx_mon_status_srng_process
  713. * to fill in buffer at current HP.
  714. */
  715. if (qdf_unlikely(!status_nbuf)) {
  716. union dp_rx_desc_list_elem_t *desc_list = NULL;
  717. union dp_rx_desc_list_elem_t *tail = NULL;
  718. struct rx_desc_pool *rx_desc_pool;
  719. rx_desc_pool = &soc->rx_desc_status[mac_id];
  720. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  721. "%s: fail to allocate or map qdf_nbuf",
  722. __func__);
  723. dp_rx_add_to_free_desc_list(&desc_list,
  724. &tail, rx_desc);
  725. dp_rx_add_desc_list_to_free_list(soc, &desc_list,
  726. &tail, mac_id, rx_desc_pool);
  727. hal_rxdma_buff_addr_info_set(
  728. rxdma_mon_status_ring_entry,
  729. 0, 0, HAL_RX_BUF_RBM_SW3_BM);
  730. work_done++;
  731. break;
  732. }
  733. paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
  734. rx_desc->nbuf = status_nbuf;
  735. rx_desc->in_use = 1;
  736. hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
  737. paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
  738. hal_srng_src_get_next(hal_soc, mon_status_srng);
  739. work_done++;
  740. }
  741. done:
  742. hal_srng_access_end(hal_soc, mon_status_srng);
  743. return work_done;
  744. }
  745. /*
  746. * dp_rx_mon_status_process() - Process monitor status ring and
  747. * TLV in status ring.
  748. *
  749. * @soc: core txrx main context
  750. * @mac_id: mac_id which is one of 3 mac_ids
  751. * @quota: No. of ring entry that can be serviced in one shot.
  752. * Return: uint32_t: No. of ring entry that is processed.
  753. */
  754. static inline uint32_t
  755. dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  756. uint32_t work_done;
  757. work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
  758. quota -= work_done;
  759. dp_rx_mon_status_process_tlv(soc, mac_id, quota);
  760. return work_done;
  761. }
  762. /**
  763. * dp_mon_process() - Main monitor mode processing roution.
  764. * This call monitor status ring process then monitor
  765. * destination ring process.
  766. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  767. * @soc: core txrx main context
  768. * @mac_id: mac_id which is one of 3 mac_ids
  769. * @quota: No. of status ring entry that can be serviced in one shot.
  770. * Return: uint32_t: No. of ring entry that is processed.
  771. */
  772. uint32_t
  773. dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
  774. return dp_rx_mon_status_process(soc, mac_id, quota);
  775. }
  776. /**
  777. * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
  778. * @pdev: core txrx pdev context
  779. * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
  780. *
  781. * This function will detach DP RX status ring from
  782. * main device context. will free DP Rx resources for
  783. * status ring
  784. *
  785. * Return: QDF_STATUS_SUCCESS: success
  786. * QDF_STATUS_E_RESOURCES: Error return
  787. */
  788. QDF_STATUS
  789. dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
  790. {
  791. struct dp_soc *soc = pdev->soc;
  792. struct rx_desc_pool *rx_desc_pool;
  793. rx_desc_pool = &soc->rx_desc_status[mac_id];
  794. if (rx_desc_pool->pool_size != 0) {
  795. if (!dp_is_soc_reinit(soc))
  796. dp_rx_desc_nbuf_and_pool_free(soc, mac_id,
  797. rx_desc_pool);
  798. else
  799. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  800. }
  801. return QDF_STATUS_SUCCESS;
  802. }
  803. /*
  804. * dp_rx_buffers_replenish() - replenish monitor status ring with
  805. * rx nbufs called during dp rx
  806. * monitor status ring initialization
  807. *
  808. * @soc: core txrx main context
  809. * @mac_id: mac_id which is one of 3 mac_ids
  810. * @dp_rxdma_srng: dp monitor status circular ring
  811. * @rx_desc_pool; Pointer to Rx descriptor pool
  812. * @num_req_buffers: number of buffer to be replenished
  813. * @desc_list: list of descs if called from dp rx monitor status
  814. * process or NULL during dp rx initialization or
  815. * out of buffer interrupt
  816. * @tail: tail of descs list
  817. * @owner: who owns the nbuf (host, NSS etc...)
  818. * Return: return success or failure
  819. */
  820. static inline
  821. QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
  822. uint32_t mac_id,
  823. struct dp_srng *dp_rxdma_srng,
  824. struct rx_desc_pool *rx_desc_pool,
  825. uint32_t num_req_buffers,
  826. union dp_rx_desc_list_elem_t **desc_list,
  827. union dp_rx_desc_list_elem_t **tail,
  828. uint8_t owner)
  829. {
  830. uint32_t num_alloc_desc;
  831. uint16_t num_desc_to_free = 0;
  832. uint32_t num_entries_avail;
  833. uint32_t count = 0;
  834. int sync_hw_ptr = 1;
  835. qdf_dma_addr_t paddr;
  836. qdf_nbuf_t rx_netbuf;
  837. void *rxdma_ring_entry;
  838. union dp_rx_desc_list_elem_t *next;
  839. void *rxdma_srng;
  840. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
  841. rxdma_srng = dp_rxdma_srng->hal_srng;
  842. qdf_assert(rxdma_srng);
  843. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  844. "[%s][%d] requested %d buffers for replenish",
  845. __func__, __LINE__, num_req_buffers);
  846. /*
  847. * if desc_list is NULL, allocate the descs from freelist
  848. */
  849. if (!(*desc_list)) {
  850. num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
  851. rx_desc_pool,
  852. num_req_buffers,
  853. desc_list,
  854. tail);
  855. if (!num_alloc_desc) {
  856. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  857. "[%s][%d] no free rx_descs in freelist",
  858. __func__, __LINE__);
  859. return QDF_STATUS_E_NOMEM;
  860. }
  861. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  862. "[%s][%d] %d rx desc allocated", __func__, __LINE__,
  863. num_alloc_desc);
  864. num_req_buffers = num_alloc_desc;
  865. }
  866. hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
  867. num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
  868. rxdma_srng, sync_hw_ptr);
  869. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  870. "[%s][%d] no of available entries in rxdma ring: %d",
  871. __func__, __LINE__, num_entries_avail);
  872. if (num_entries_avail < num_req_buffers) {
  873. num_desc_to_free = num_req_buffers - num_entries_avail;
  874. num_req_buffers = num_entries_avail;
  875. }
  876. while (count < num_req_buffers) {
  877. rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
  878. /*
  879. * qdf_nbuf alloc or map failed,
  880. * keep HP in mon_status_ring unchanged,
  881. * wait dp_rx_mon_status_srng_process
  882. * to fill in buffer at current HP.
  883. */
  884. if (qdf_unlikely(!rx_netbuf)) {
  885. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  886. "%s: qdf_nbuf allocate or map fail, count %d",
  887. __func__, count);
  888. break;
  889. }
  890. paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
  891. next = (*desc_list)->next;
  892. rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
  893. rxdma_srng);
  894. if (qdf_unlikely(!rxdma_ring_entry)) {
  895. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  896. "[%s][%d] rxdma_ring_entry is NULL, count - %d",
  897. __func__, __LINE__, count);
  898. qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
  899. QDF_DMA_FROM_DEVICE);
  900. qdf_nbuf_free(rx_netbuf);
  901. break;
  902. }
  903. (*desc_list)->rx_desc.nbuf = rx_netbuf;
  904. (*desc_list)->rx_desc.in_use = 1;
  905. count++;
  906. hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
  907. (*desc_list)->rx_desc.cookie, owner);
  908. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  909. "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
  910. paddr=%pK",
  911. __func__, __LINE__, &(*desc_list)->rx_desc,
  912. (*desc_list)->rx_desc.cookie, rx_netbuf,
  913. (void *)paddr);
  914. *desc_list = next;
  915. }
  916. hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
  917. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  918. "successfully replenished %d buffers", num_req_buffers);
  919. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  920. "%d rx desc added back to free list", num_desc_to_free);
  921. /*
  922. * add any available free desc back to the free list
  923. */
  924. if (*desc_list) {
  925. dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
  926. mac_id, rx_desc_pool);
  927. }
  928. return QDF_STATUS_SUCCESS;
  929. }
  930. /**
  931. * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
  932. * @pdev: core txrx pdev context
  933. * @ring_id: ring number
  934. * This function will attach a DP RX monitor status ring into pDEV
  935. * and replenish monitor status ring with buffer.
  936. *
  937. * Return: QDF_STATUS_SUCCESS: success
  938. * QDF_STATUS_E_RESOURCES: Error return
  939. */
  940. QDF_STATUS
  941. dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
  942. struct dp_soc *soc = pdev->soc;
  943. union dp_rx_desc_list_elem_t *desc_list = NULL;
  944. union dp_rx_desc_list_elem_t *tail = NULL;
  945. struct dp_srng *mon_status_ring;
  946. uint32_t num_entries;
  947. uint32_t i;
  948. struct rx_desc_pool *rx_desc_pool;
  949. QDF_STATUS status;
  950. int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
  951. mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
  952. num_entries = mon_status_ring->num_entries;
  953. rx_desc_pool = &soc->rx_desc_status[ring_id];
  954. dp_info("Mon RX Status Pool[%d] entries=%d",
  955. ring_id, num_entries);
  956. status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
  957. rx_desc_pool);
  958. if (!QDF_IS_STATUS_SUCCESS(status))
  959. return status;
  960. dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
  961. status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
  962. mon_status_ring,
  963. rx_desc_pool,
  964. num_entries,
  965. &desc_list, &tail,
  966. HAL_RX_BUF_RBM_SW3_BM);
  967. if (!QDF_IS_STATUS_SUCCESS(status))
  968. return status;
  969. qdf_nbuf_queue_init(&pdev->rx_status_q);
  970. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  971. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  972. sizeof(pdev->ppdu_info.rx_status));
  973. qdf_mem_zero(&pdev->rx_mon_stats,
  974. sizeof(pdev->rx_mon_stats));
  975. dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
  976. &pdev->rx_mon_stats);
  977. for (i = 0; i < MAX_MU_USERS; i++) {
  978. qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
  979. pdev->is_mpdu_hdr[i] = true;
  980. }
  981. qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
  982. pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
  983. return QDF_STATUS_SUCCESS;
  984. }