blob: 9d1859615e973c520d17d21b2fa46ece6d488e9d [file] [log] [blame]
Kai Chen6eca1a62017-01-12 10:17:53 -08001/*
phadimanebf4cde2019-01-28 17:50:37 +05302 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
Kai Chen6eca1a62017-01-12 10:17:53 -08003 *
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 */
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +053018#include "hal_hw_headers.h"
Kai Chen6eca1a62017-01-12 10:17:53 -080019#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"
Kai Chen6eca1a62017-01-12 10:17:53 -080027#include "dp_rx_mon.h"
Keyur Parekhfad6d082017-05-07 08:54:47 -070028#include "dp_internal.h"
29#include "qdf_mem.h" /* qdf_mem_malloc,free */
Kai Chen6eca1a62017-01-12 10:17:53 -080030
ydb247452018-08-08 00:23:16 +053031#ifdef FEATURE_PERPKT_INFO
32#include "dp_ratetable.h"
33#endif
34
Kai Chen52ef33f2019-03-05 18:33:40 -080035#ifdef WLAN_RX_PKT_CAPTURE_ENH
36#include "dp_rx_mon_feature.h"
37#else
38static QDF_STATUS
39dp_rx_handle_enh_capture(struct dp_soc *soc, struct dp_pdev *pdev,
40 struct hal_rx_ppdu_info *ppdu_info)
41{
42 return QDF_STATUS_SUCCESS;
43}
44
45static void
46dp_rx_mon_enh_capture_process(struct dp_pdev *pdev, uint32_t tlv_status,
47 qdf_nbuf_t status_nbuf,
48 struct hal_rx_ppdu_info *ppdu_info,
Karunakar Dasineniacc8b562019-05-07 07:00:24 -070049 bool *nbuf_used)
Kai Chen52ef33f2019-03-05 18:33:40 -080050{
51}
52#endif
53
Amir Patel1d4ac982019-04-25 11:49:01 +053054#ifdef FEATURE_PERPKT_INFO
55static inline void
56dp_rx_populate_rx_rssi_chain(struct hal_rx_ppdu_info *ppdu_info,
57 struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
58{
59 uint8_t chain, bw;
60 int8_t rssi;
61
62 for (chain = 0; chain < SS_COUNT; chain++) {
63 for (bw = 0; bw < MAX_BW; bw++) {
64 rssi = ppdu_info->rx_status.rssi_chain[chain][bw];
65 if (rssi != DP_RSSI_INVAL)
66 cdp_rx_ppdu->rssi_chain[chain][bw] = rssi;
67 else
68 cdp_rx_ppdu->rssi_chain[chain][bw] = 0;
69 }
70 }
71}
72
Amir Patel5a8bbbe2019-07-17 21:59:39 +053073/*
74 * dp_rx_populate_su_evm_details() - Populate su evm info
75 * @ppdu_info: ppdu info structure from ppdu ring
76 * @cdp_rx_ppdu: rx ppdu indication structure
77 */
78static inline void
79dp_rx_populate_su_evm_details(struct hal_rx_ppdu_info *ppdu_info,
80 struct cdp_rx_indication_ppdu *cdp_rx_ppdu)
81{
82 uint8_t pilot_evm;
83 uint8_t nss_count;
84 uint8_t pilot_count;
85
86 nss_count = ppdu_info->evm_info.nss_count;
87 pilot_count = ppdu_info->evm_info.pilot_count;
88
89 if ((nss_count * pilot_count) > DP_RX_MAX_SU_EVM_COUNT) {
90 qdf_err("pilot evm count is more than expected");
91 return;
92 }
93 cdp_rx_ppdu->evm_info.pilot_count = pilot_count;
94 cdp_rx_ppdu->evm_info.nss_count = nss_count;
95
96 /* Populate evm for pilot_evm = nss_count*pilot_count */
97 for (pilot_evm = 0; pilot_evm < nss_count * pilot_count; pilot_evm++) {
98 cdp_rx_ppdu->evm_info.pilot_evm[pilot_evm] =
99 ppdu_info->evm_info.pilot_evm[pilot_evm];
100 }
101}
102
Kai Chen6eca1a62017-01-12 10:17:53 -0800103/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530104* dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
Soumya Bhat560f90c2018-03-30 13:53:26 +0530105* @pdev: pdev ctx
Anish Nataraj38a29562017-08-18 19:41:17 +0530106* @ppdu_info: ppdu info structure from ppdu ring
107* @ppdu_nbuf: qdf nbuf abstraction for linux skb
108*
109* Return: none
110*/
Anish Nataraj38a29562017-08-18 19:41:17 +0530111static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530112dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530113 struct hal_rx_ppdu_info *ppdu_info,
114 qdf_nbuf_t ppdu_nbuf)
115{
116 struct dp_peer *peer;
Soumya Bhat560f90c2018-03-30 13:53:26 +0530117 struct dp_soc *soc = pdev->soc;
Anish Nataraj38a29562017-08-18 19:41:17 +0530118 struct dp_ast_entry *ast_entry;
119 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
120 uint32_t ast_index;
121
122 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
123
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +0530124 cdp_rx_ppdu->first_data_seq_ctrl =
125 ppdu_info->rx_status.first_data_seq_ctrl;
Anish Natarajeb30aa72018-09-20 16:34:01 +0530126 cdp_rx_ppdu->frame_ctrl =
127 ppdu_info->rx_status.frame_control;
Anish Nataraj38a29562017-08-18 19:41:17 +0530128 cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
nobelj9ab76e22018-02-13 18:10:54 -0800129 cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
Anish Nataraj38a29562017-08-18 19:41:17 +0530130 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
131 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530132 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
133 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
134 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +0530135 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
136 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Keyur Parekh49cdc742018-05-09 10:59:03 -0700137 if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
138 (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
139 cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
140 else
141 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj50347012018-03-06 21:12:45 +0530142 cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
Anish Nataraj38a29562017-08-18 19:41:17 +0530143 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +0530144 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Pamidipati, Vijayba4b57f2019-02-13 16:47:23 +0530145 cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
146 QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
147 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Anish Nataraj38a29562017-08-18 19:41:17 +0530148 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +0530149 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
150 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
nobeljd8039592018-03-13 16:59:42 -0700151 cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530152 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
153 cdp_rx_ppdu->udp_msdu_count +
154 cdp_rx_ppdu->other_msdu_count);
Amir Patel468bded2019-03-21 11:42:31 +0530155 cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
Amir Patelac7d9462019-03-28 16:16:01 +0530156 cdp_rx_ppdu->retries = CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl) ?
157 ppdu_info->com_info.mpdu_cnt_fcs_ok : 0;
Pranita Solankeed0aba62018-01-12 19:14:31 +0530158
159 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
160 cdp_rx_ppdu->is_ampdu = 1;
161 else
162 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +0530163
164 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +0530165 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Soumya Bhat560f90c2018-03-30 13:53:26 +0530166
167 ast_index = ppdu_info->rx_status.ast_index;
Tallapragada Kalyana7023622018-12-03 19:29:52 +0530168 if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530169 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
170 return;
171 }
172
173 ast_entry = soc->ast_table[ast_index];
174 if (!ast_entry) {
175 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
176 return;
177 }
178 peer = ast_entry->peer;
179 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
180 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
181 return;
182 }
183
184 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800185 peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
Soumya Bhat560f90c2018-03-30 13:53:26 +0530186 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
187 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Keyur Parekh44d8f8f2019-03-12 12:39:41 -0700188 cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
Amir Patel1d4ac982019-04-25 11:49:01 +0530189
190 dp_rx_populate_rx_rssi_chain(ppdu_info, cdp_rx_ppdu);
Amir Patel5a8bbbe2019-07-17 21:59:39 +0530191 dp_rx_populate_su_evm_details(ppdu_info, cdp_rx_ppdu);
192 cdp_rx_ppdu->rx_antenna = ppdu_info->rx_status.rx_antenna;
Anish Nataraj38a29562017-08-18 19:41:17 +0530193}
194#else
195static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530196dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530197 struct hal_rx_ppdu_info *ppdu_info,
198 qdf_nbuf_t ppdu_nbuf)
199{
200}
201#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530202/**
203 * dp_rx_stats_update() - Update per-peer statistics
204 * @soc: Datapath SOC handle
205 * @peer: Datapath peer handle
206 * @ppdu: PPDU Descriptor
207 *
208 * Return: None
209 */
210#ifdef FEATURE_PERPKT_INFO
ydb247452018-08-08 00:23:16 +0530211static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
212 struct cdp_rx_indication_ppdu *ppdu)
213{
214 uint32_t ratekbps = 0;
215 uint32_t ppdu_rx_rate = 0;
216 uint32_t nss = 0;
Amir Patel78824b12019-02-23 10:54:32 +0530217 uint32_t rix;
ydb247452018-08-08 00:23:16 +0530218
219 if (!peer || !ppdu)
220 return;
221
222 if (ppdu->u.nss == 0)
223 nss = 0;
224 else
225 nss = ppdu->u.nss - 1;
226
Anish Nataraj376d9b12018-08-13 14:12:01 +0530227 ratekbps = dp_getrateindex(ppdu->u.gi,
228 ppdu->u.mcs,
ydb247452018-08-08 00:23:16 +0530229 nss,
230 ppdu->u.preamble,
Amir Patel78824b12019-02-23 10:54:32 +0530231 ppdu->u.bw,
232 &rix);
ydb247452018-08-08 00:23:16 +0530233
234 if (!ratekbps)
235 return;
236
Amir Patel468bded2019-03-21 11:42:31 +0530237 ppdu->rix = rix;
ydb247452018-08-08 00:23:16 +0530238 DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
239 dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
240 ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
241 DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
Amir Patelac7d9462019-03-28 16:16:01 +0530242 ppdu->rx_ratekbps = ratekbps;
Amir Patel5a8bbbe2019-07-17 21:59:39 +0530243 ppdu->rx_ratecode = CDP_TXRX_RATECODE(ppdu->u.mcs,
244 nss,
245 ppdu->u.preamble);
ydb247452018-08-08 00:23:16 +0530246
247 if (peer->vdev)
248 peer->vdev->stats.rx.last_rx_rate = ratekbps;
249}
250
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530251static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
252 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530253{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530254 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530255 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530256 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530257 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530258
259 mcs = ppdu->u.mcs;
260 preamble = ppdu->u.preamble;
261 num_msdu = ppdu->num_msdu;
262
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530263 if (pdev)
264 soc = pdev->soc;
265 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530266 return;
267
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530268 if (!peer) {
269 is_invalid_peer = true;
270 peer = pdev->invalid_peer;
271 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530272
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530273 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530274 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530275
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530276 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Surya Prakash07c81e72019-04-29 10:08:01 +0530277 if (peer->stats.rx.avg_rssi == INVALID_RSSI)
Amir Patelbb69cfa2019-03-28 16:16:01 +0530278 peer->stats.rx.avg_rssi = ppdu->rssi;
279 else
280 peer->stats.rx.avg_rssi =
281 DP_GET_AVG_RSSI(peer->stats.rx.avg_rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530282
283 if ((preamble == DOT11_A) || (preamble == DOT11_B))
284 ppdu->u.nss = 1;
285
286 if (ppdu->u.nss)
287 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
288
Pranita Solankea12b4b32017-11-20 23:04:14 +0530289 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530290 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530291 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530292 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
293 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
294 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530295 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530296 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530297 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
298 DP_STATS_INCC(peer,
299 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530300 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530301 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530302 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530303 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
304 DP_STATS_INCC(peer,
305 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530306 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530307 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530308 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530309 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
310 DP_STATS_INCC(peer,
311 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530312 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530313 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530314 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530315 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
316 DP_STATS_INCC(peer,
317 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
318 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
319 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530320 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530321 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
322 DP_STATS_INCC(peer,
323 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
324 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530325 /*
326 * If invalid TID, it could be a non-qos frame, hence do not update
327 * any AC counters
328 */
329 ac = TID_TO_WME_AC(ppdu->tid);
330 if (ppdu->tid != HAL_TID_INVALID)
331 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530332 dp_peer_stats_notify(peer);
333 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530334
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530335 if (is_invalid_peer)
336 return;
337
Jeffin Mammen1514e792019-05-20 10:30:44 +0530338 if (dp_is_subtype_data(ppdu->frame_ctrl))
339 dp_rx_rate_stats_update(peer, ppdu);
ydb247452018-08-08 00:23:16 +0530340
Amir Patel756d05e2018-10-10 12:35:30 +0530341#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
342 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
343 &peer->stats, ppdu->peer_id,
344 UPDATE_PEER_STATS, pdev->pdev_id);
345#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530346}
347#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530348
Amir Patel57e7e052019-05-15 20:49:57 +0530349/*
350 * dp_rx_get_fcs_ok_msdu() - get ppdu status buffer containing fcs_ok msdu
351 * @pdev: pdev object
352 * @ppdu_info: ppdu info object
353 *
354 * Return: nbuf
355 */
356
357static inline qdf_nbuf_t
358dp_rx_get_fcs_ok_msdu(struct dp_pdev *pdev,
359 struct hal_rx_ppdu_info *ppdu_info)
360{
361 uint16_t mpdu_fcs_ok;
362 qdf_nbuf_t status_nbuf = NULL;
363 unsigned long int fcs_ok_bitmap;
364
365 /* If fcs_ok_bitmap is zero, no need to procees further */
366 if (qdf_unlikely(!ppdu_info->com_info.mpdu_fcs_ok_bitmap))
367 return NULL;
368
369 /* Obtain fcs_ok passed index from bitmap
370 * this index is used to get fcs passed first msdu payload
371 */
372
373 fcs_ok_bitmap = ppdu_info->com_info.mpdu_fcs_ok_bitmap;
374 mpdu_fcs_ok = qdf_find_first_bit(&fcs_ok_bitmap, HAL_RX_MAX_MPDU);
375
376 /* Get status buffer by indexing mpdu_fcs_ok index
377 * containing first msdu payload with fcs passed
378 * and clone the buffer
379 */
380 status_nbuf = ppdu_info->ppdu_msdu_info[mpdu_fcs_ok].nbuf;
381 /* Take ref of status nbuf as this nbuf is to be
382 * freeed by upper layer.
383 */
384 qdf_nbuf_ref(status_nbuf);
385
386 /* Free the ppdu status buffer queue */
387 qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
388
389 return status_nbuf;
390}
391
392static inline void
393dp_rx_handle_ppdu_status_buf(struct dp_pdev *pdev,
394 struct hal_rx_ppdu_info *ppdu_info,
395 qdf_nbuf_t status_nbuf)
396{
397 qdf_nbuf_queue_add(&pdev->rx_ppdu_buf_q, status_nbuf);
398}
Anish Nataraj38a29562017-08-18 19:41:17 +0530399/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530400 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530401 * @soc: core txrx main context
402 * @pdev: pdev strcuture
403 * @ppdu_info: structure for rx ppdu ring
404 *
405 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
406 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530407 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530408#ifdef FEATURE_PERPKT_INFO
409static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530410dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530411 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
412{
413 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530414 struct ieee80211_frame *wh;
415 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530416
Amir Patel57e7e052019-05-15 20:49:57 +0530417 if (!ppdu_info->fcs_ok_msdu_info.first_msdu_payload)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530418 return QDF_STATUS_SUCCESS;
419
Soumya Bhat2f54de22018-02-21 09:54:28 +0530420 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530421 return QDF_STATUS_SUCCESS;
422
Soumya Bhat2f54de22018-02-21 09:54:28 +0530423 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530424
Amir Patel57e7e052019-05-15 20:49:57 +0530425 wh = (struct ieee80211_frame *)
426 (ppdu_info->fcs_ok_msdu_info.first_msdu_payload + 4);
427
428 size = (ppdu_info->fcs_ok_msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530429 qdf_nbuf_data(nbuf));
Amir Patel57e7e052019-05-15 20:49:57 +0530430 ppdu_info->fcs_ok_msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530431
432 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
433 return QDF_STATUS_SUCCESS;
434
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530435 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
436 IEEE80211_FC0_TYPE_MGT) ||
437 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
438 IEEE80211_FC0_TYPE_CTL)) {
439 return QDF_STATUS_SUCCESS;
440 }
441
442 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
443 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530444 /* only retain RX MSDU payload in the skb */
445 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
Amir Patel57e7e052019-05-15 20:49:57 +0530446 ppdu_info->fcs_ok_msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530447 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
448 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
449 return QDF_STATUS_E_ALREADY;
450}
451#else
452static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530453dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530454 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
455{
456 return QDF_STATUS_SUCCESS;
457}
458#endif
459
Amir Patel57e7e052019-05-15 20:49:57 +0530460#ifdef FEATURE_PERPKT_INFO
461static inline void
462dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
463 struct hal_rx_ppdu_info *ppdu_info,
464 uint32_t tlv_status,
465 qdf_nbuf_t status_nbuf)
466{
467 QDF_STATUS mcopy_status;
468
469 if (qdf_unlikely(!ppdu_info->com_info.mpdu_cnt)) {
470 qdf_nbuf_free(status_nbuf);
471 return;
472 }
473 /* Add buffers to queue until we receive
474 * HAL_TLV_STATUS_PPDU_DONE
475 */
476 dp_rx_handle_ppdu_status_buf(pdev, ppdu_info, status_nbuf);
477
478 /* If tlv_status is PPDU_DONE, process rx_ppdu_buf_q
479 * and devliver fcs_ok msdu buffer
480 */
481 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
482 /* Get rx ppdu status buffer having fcs ok msdu */
483 status_nbuf = dp_rx_get_fcs_ok_msdu(pdev, ppdu_info);
484 if (status_nbuf) {
485 mcopy_status = dp_rx_handle_mcopy_mode(soc, pdev,
486 ppdu_info,
487 status_nbuf);
488 if (mcopy_status == QDF_STATUS_SUCCESS)
489 qdf_nbuf_free(status_nbuf);
490 }
491 }
492}
493#else
494static inline void
495dp_rx_process_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
496 struct hal_rx_ppdu_info *ppdu_info,
497 uint32_t tlv_status,
498 qdf_nbuf_t status_nbuf)
499{
500}
501#endif
502
sumedh baikady59a2d332018-05-22 01:50:38 -0700503/**
504 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
505 * @soc: Datapath SOC handle
506 * @pdev: Datapath PDEV handle
507 * @ppdu_info: Structure for rx ppdu info
508 * @nbuf: Qdf nbuf abstraction for linux skb
509 *
510 * Return: 0 on success, 1 on failure
511 */
512static inline int
513dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
514 struct hal_rx_ppdu_info *ppdu_info,
515 qdf_nbuf_t nbuf)
516{
517 uint8_t size = 0;
518
519 if (!pdev->monitor_vdev) {
520 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
521 "[%s]:[%d] Monitor vdev is NULL !!",
522 __func__, __LINE__);
523 return 1;
524 }
Jeff Johnsona8edf332019-03-18 09:51:52 -0700525 if (!ppdu_info->msdu_info.first_msdu_payload) {
sumedh baikady59a2d332018-05-22 01:50:38 -0700526 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
527 "[%s]:[%d] First msdu payload not present",
528 __func__, __LINE__);
529 return 1;
530 }
531
sumedh baikadyda159202018-11-01 17:31:23 -0700532 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700533 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700534 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700535 ppdu_info->msdu_info.first_msdu_payload = NULL;
536
537 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
538 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
539 "[%s]:[%d] No header present",
540 __func__, __LINE__);
541 return 1;
542 }
543
sumedh baikadyda159202018-11-01 17:31:23 -0700544 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700545 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
546 ppdu_info->msdu_info.payload_len);
Shashikala Prabhu08434382019-07-16 15:42:03 +0530547 if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, nbuf,
548 qdf_nbuf_headroom(nbuf))) {
549 DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
550 return 1;
551 }
552
sumedh baikady59a2d332018-05-22 01:50:38 -0700553 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
554 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700555 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700556 return 0;
557}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530558
559/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530560* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
561* @soc: core txrx main context
562* @pdev: pdev strcuture
563* @ppdu_info: structure for rx ppdu ring
564*
565* Return: none
566*/
567#ifdef FEATURE_PERPKT_INFO
568static inline void
569dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
570 struct hal_rx_ppdu_info *ppdu_info)
571{
572 qdf_nbuf_t ppdu_nbuf;
573 struct dp_peer *peer;
574 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
575
Anish Nataraj28490c42018-01-19 19:34:54 +0530576 /*
577 * Do not allocate if fcs error,
578 * ast idx invalid / fctl invalid
579 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530580 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
581 return;
582
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530583 if (ppdu_info->nac_info.fc_valid &&
584 ppdu_info->nac_info.to_ds_flag &&
585 ppdu_info->nac_info.mac_addr2_valid) {
586 struct dp_neighbour_peer *peer = NULL;
587 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
588
589 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
590 if (pdev->neighbour_peers_added) {
591 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
592 neighbour_peer_list_elem) {
593 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
594 &ppdu_info->nac_info.mac_addr2,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800595 QDF_MAC_ADDR_SIZE)) {
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530596 peer->rssi = rssi;
597 break;
598 }
599 }
600 }
601 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
602 }
603
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530604 /* need not generate wdi event when mcopy and
605 * enhanced stats are not enabled
606 */
607 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
608 return;
609
Soumya Bhat560f90c2018-03-30 13:53:26 +0530610 if (!pdev->mcopy_mode) {
611 if (!ppdu_info->rx_status.frame_control_info_valid)
612 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530613
Soumya Bhat560f90c2018-03-30 13:53:26 +0530614 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
615 return;
616 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530617 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Kiran Venkatappa4b50f332019-03-20 18:14:17 +0530618 sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
Anish Nataraj38a29562017-08-18 19:41:17 +0530619 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530620 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530621 qdf_nbuf_put_tail(ppdu_nbuf,
622 sizeof(struct cdp_rx_indication_ppdu));
623 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530624 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800625 if (peer) {
Amir Patel468bded2019-03-21 11:42:31 +0530626 cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530627 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800628 dp_peer_unref_del_find_by_id(peer);
629 }
630 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
631 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
632 soc, ppdu_nbuf,
633 cdp_rx_ppdu->peer_id,
634 WDI_NO_VAL, pdev->pdev_id);
635 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530636 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
637 ppdu_nbuf, HTT_INVALID_PEER,
638 WDI_NO_VAL, pdev->pdev_id);
639 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530640 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530641 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530642 }
643}
644#else
645static inline void
646dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
647 struct hal_rx_ppdu_info *ppdu_info)
648{
649}
650#endif
651
652/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800653* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
654* filtering enabled
655* @soc: core txrx main context
656* @ppdu_info: Structure for rx ppdu info
657* @status_nbuf: Qdf nbuf abstraction for linux skb
658* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
659*
660* Return: none
661*/
662static inline void
663dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
664 struct hal_rx_ppdu_info *ppdu_info,
665 qdf_nbuf_t status_nbuf, uint32_t mac_id)
666{
667 struct dp_peer *peer;
668 struct dp_ast_entry *ast_entry;
669 uint32_t ast_index;
670
671 ast_index = ppdu_info->rx_status.ast_index;
672 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
673 ast_entry = soc->ast_table[ast_index];
674 if (ast_entry) {
675 peer = ast_entry->peer;
676 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
677 if (peer->peer_based_pktlog_filter) {
678 dp_wdi_event_handler(
679 WDI_EVENT_RX_DESC, soc,
680 status_nbuf,
681 peer->peer_ids[0],
682 WDI_NO_VAL, mac_id);
683 }
684 }
685 }
686 }
687}
688
Kai Chen93f7e1b2019-07-10 16:13:48 -0700689#if defined(HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_M)
690static inline void
691dp_rx_ul_ofdma_ru_size_to_width(
692 uint32_t ru_size,
693 uint32_t *ru_width)
694{
695 uint32_t width;
696
697 width = 0;
698 switch (ru_size) {
699 case HTT_UL_OFDMA_V0_RU_SIZE_RU_26:
700 width = 1;
701 break;
702 case HTT_UL_OFDMA_V0_RU_SIZE_RU_52:
703 width = 2;
704 break;
705 case HTT_UL_OFDMA_V0_RU_SIZE_RU_106:
706 width = 4;
707 break;
708 case HTT_UL_OFDMA_V0_RU_SIZE_RU_242:
709 width = 9;
710 break;
711 case HTT_UL_OFDMA_V0_RU_SIZE_RU_484:
712 width = 18;
713 break;
714 case HTT_UL_OFDMA_V0_RU_SIZE_RU_996:
715 width = 37;
716 break;
717 case HTT_UL_OFDMA_V0_RU_SIZE_RU_996x2:
718 width = 74;
719 break;
720 default:
721 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
722 "RU size to width convert err");
723 break;
724 }
725 *ru_width = width;
726}
727
728static inline void
729dp_rx_mon_handle_ofdma_info(struct hal_rx_ppdu_info *ppdu_info)
730{
731 struct mon_rx_user_status *mon_rx_user_status;
732 uint32_t num_users;
733 uint32_t i;
734 uint32_t ul_ofdma_user_v0_word0;
735 uint32_t ul_ofdma_user_v0_word1;
736 uint32_t ru_width;
737
738 if (ppdu_info->rx_status.reception_type != HAL_RX_TYPE_MU_OFDMA)
739 return;
740
741 num_users = ppdu_info->com_info.num_users;
742 if (num_users > HAL_MAX_UL_MU_USERS)
743 num_users = HAL_MAX_UL_MU_USERS;
744 for (i = 0; i < num_users; i++) {
745 mon_rx_user_status = &ppdu_info->rx_user_status[i];
746 ul_ofdma_user_v0_word0 =
747 mon_rx_user_status->ul_ofdma_user_v0_word0;
748 ul_ofdma_user_v0_word1 =
749 mon_rx_user_status->ul_ofdma_user_v0_word1;
750
751 if (HTT_UL_OFDMA_USER_INFO_V0_W0_VALID_GET(
752 ul_ofdma_user_v0_word0) &&
753 !HTT_UL_OFDMA_USER_INFO_V0_W0_VER_GET(
754 ul_ofdma_user_v0_word0)) {
755 mon_rx_user_status->mcs =
756 HTT_UL_OFDMA_USER_INFO_V0_W1_MCS_GET(
757 ul_ofdma_user_v0_word1);
758 mon_rx_user_status->nss =
759 HTT_UL_OFDMA_USER_INFO_V0_W1_NSS_GET(
760 ul_ofdma_user_v0_word1);
761
762 mon_rx_user_status->ofdma_info_valid = 1;
763 mon_rx_user_status->dl_ofdma_ru_start_index =
764 HTT_UL_OFDMA_USER_INFO_V0_W1_RU_START_GET(
765 ul_ofdma_user_v0_word1);
766
767 dp_rx_ul_ofdma_ru_size_to_width(
768 HTT_UL_OFDMA_USER_INFO_V0_W1_RU_SIZE_GET(
769 ul_ofdma_user_v0_word1),
770 &ru_width);
771 mon_rx_user_status->dl_ofdma_ru_width = ru_width;
772 }
773 }
774}
775#else
776static inline void
777dp_rx_mon_handle_ofdma_info(struct hal_rx_ppdu_info *ppdu_info)
778{
779}
780#endif
781
Keyur Parekhc28f8392018-11-21 02:50:56 -0800782/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800783* dp_rx_mon_status_process_tlv() - Process status TLV in status
784* buffer on Rx status Queue posted by status SRNG processing.
785* @soc: core txrx main context
786* @mac_id: mac_id which is one of 3 mac_ids _ring
787*
788* Return: none
789*/
790static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700791dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
792 uint32_t quota)
793{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800794 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800795 struct hal_rx_ppdu_info *ppdu_info;
796 qdf_nbuf_t status_nbuf;
797 uint8_t *rx_tlv;
798 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700799 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Kai Chen52ef33f2019-03-05 18:33:40 -0800800 QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800801 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700802 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800803 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen52ef33f2019-03-05 18:33:40 -0800804 bool nbuf_used;
805 uint32_t rx_enh_capture_mode;
806
Kai Chen6eca1a62017-01-12 10:17:53 -0800807
Kai Chen6eca1a62017-01-12 10:17:53 -0800808 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800809 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800810
811 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
812 return;
813
Kai Chen52ef33f2019-03-05 18:33:40 -0800814 rx_enh_capture_mode = pdev->rx_enh_capture_mode;
815
Kai Chen6eca1a62017-01-12 10:17:53 -0800816 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
817
818 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530819
Kai Chen6eca1a62017-01-12 10:17:53 -0800820 rx_tlv = qdf_nbuf_data(status_nbuf);
821 rx_tlv_start = rx_tlv;
Kai Chen52ef33f2019-03-05 18:33:40 -0800822 nbuf_used = false;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700823
Jeff Johnsona8edf332019-03-18 09:51:52 -0700824 if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
Kai Chen52ef33f2019-03-05 18:33:40 -0800825 pdev->mcopy_mode ||
826 (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
Keyur Parekhfad6d082017-05-07 08:54:47 -0700827 do {
828 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Amir Patel57e7e052019-05-15 20:49:57 +0530829 ppdu_info, pdev->soc->hal_soc,
830 status_nbuf);
Kai Chen783e0382018-01-25 16:29:08 -0800831
832 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
833 rx_mon_stats);
834
Kai Chen52ef33f2019-03-05 18:33:40 -0800835 dp_rx_mon_enh_capture_process(pdev, tlv_status,
836 status_nbuf, ppdu_info,
Karunakar Dasineniacc8b562019-05-07 07:00:24 -0700837 &nbuf_used);
Kai Chen52ef33f2019-03-05 18:33:40 -0800838
Keyur Parekhfad6d082017-05-07 08:54:47 -0700839 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800840
Keyur Parekhfad6d082017-05-07 08:54:47 -0700841 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
842 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800843
Kai Chen52ef33f2019-03-05 18:33:40 -0800844 } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
845 (tlv_status == HAL_TLV_STATUS_HEADER) ||
Karunakar Dasineniacc8b562019-05-07 07:00:24 -0700846 (tlv_status == HAL_TLV_STATUS_MPDU_END) ||
847 (tlv_status == HAL_TLV_STATUS_MSDU_END));
Keyur Parekhfad6d082017-05-07 08:54:47 -0700848 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800849 if (pdev->dp_peer_based_pktlog) {
850 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
851 status_nbuf, mac_id);
852 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800853 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
854 pktlog_mode = WDI_EVENT_RX_DESC;
855 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
856 pktlog_mode = WDI_EVENT_LITE_RX;
857
858 if (pktlog_mode != WDI_NO_VAL)
859 dp_wdi_event_handler(pktlog_mode, soc,
860 status_nbuf,
861 HTT_INVALID_PEER,
862 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800863 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530864
865 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700866 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
867 && pdev->monitor_vdev) {
868 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
869 pdev, ppdu_info, status_nbuf);
870 if (smart_mesh_status)
871 qdf_nbuf_free(status_nbuf);
Amir Patel57e7e052019-05-15 20:49:57 +0530872 } else if (qdf_unlikely(pdev->mcopy_mode)) {
873 dp_rx_process_mcopy_mode(soc, pdev,
874 ppdu_info, tlv_status,
875 status_nbuf);
Kai Chen52ef33f2019-03-05 18:33:40 -0800876 } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
877 if (!nbuf_used)
878 qdf_nbuf_free(status_nbuf);
879
880 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
881 enh_log_status =
882 dp_rx_handle_enh_capture(soc,
883 pdev, ppdu_info);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530884 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700885 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530886 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800887
chenguo1b880462018-07-11 15:34:56 +0800888 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
889 dp_rx_mon_deliver_non_std(soc, mac_id);
890 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800891 rx_mon_stats->status_ppdu_done++;
Kai Chen93f7e1b2019-07-10 16:13:48 -0700892 dp_rx_mon_handle_ofdma_info(ppdu_info);
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530893 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700894 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530895 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530896
nobelj1c31fee2018-03-21 11:47:05 -0700897 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
898 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700899 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800900 }
901 }
902 return;
903}
904
905/*
906 * dp_rx_mon_status_srng_process() - Process monitor status ring
907 * post the status ring buffer to Rx status Queue for later
908 * processing when status ring is filled with status TLV.
909 * Allocate a new buffer to status ring if the filled buffer
910 * is posted.
911 *
912 * @soc: core txrx main context
913 * @mac_id: mac_id which is one of 3 mac_ids
914 * @quota: No. of ring entry that can be serviced in one shot.
915
916 * Return: uint32_t: No. of ring entry that is processed.
917 */
918static inline uint32_t
919dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
920 uint32_t quota)
921{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800922 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Akshay Kosigia870c612019-07-08 23:10:30 +0530923 hal_soc_handle_t hal_soc;
Kai Chen6eca1a62017-01-12 10:17:53 -0800924 void *mon_status_srng;
925 void *rxdma_mon_status_ring_entry;
926 QDF_STATUS status;
927 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800928 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800929
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800930 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800931
932 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700933 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
934
935 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530936 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700937 __func__, __LINE__, mon_status_srng);
938 return work_done;
939 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800940
941 hal_soc = soc->hal_soc;
942
943 qdf_assert(hal_soc);
944
945 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
946 goto done;
947
948 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
949 * BUFFER_ADDR_INFO STRUCT
950 */
951 while (qdf_likely((rxdma_mon_status_ring_entry =
952 hal_srng_src_peek(hal_soc, mon_status_srng))
953 && quota--)) {
954 uint32_t rx_buf_cookie;
955 qdf_nbuf_t status_nbuf;
956 struct dp_rx_desc *rx_desc;
957 uint8_t *status_buf;
958 qdf_dma_addr_t paddr;
959 uint64_t buf_addr;
960
961 buf_addr =
962 (HAL_RX_BUFFER_ADDR_31_0_GET(
963 rxdma_mon_status_ring_entry) |
964 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
965 rxdma_mon_status_ring_entry)) << 32));
966
967 if (qdf_likely(buf_addr)) {
968
969 rx_buf_cookie =
970 HAL_RX_BUF_COOKIE_GET(
971 rxdma_mon_status_ring_entry);
972 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
973 rx_buf_cookie);
974
975 qdf_assert(rx_desc);
976
977 status_nbuf = rx_desc->nbuf;
978
979 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
980 QDF_DMA_FROM_DEVICE);
981
982 status_buf = qdf_nbuf_data(status_nbuf);
983
984 status = hal_get_rx_status_done(status_buf);
985
986 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800987 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700988 hal_get_sw_hptp(hal_soc, mon_status_srng,
989 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800990 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800991 QDF_TRACE_LEVEL_ERROR,
992 "[%s][%d] status not done - hp:%u, tp:%u",
993 __func__, __LINE__, hp, tp);
994 /* WAR for missing status: Skip status entry */
995 hal_srng_src_get_next(hal_soc, mon_status_srng);
996 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800997 }
998 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
999
1000 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
1001 QDF_DMA_FROM_DEVICE);
1002
1003 /* Put the status_nbuf to queue */
1004 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
1005
1006 } else {
1007 union dp_rx_desc_list_elem_t *desc_list = NULL;
1008 union dp_rx_desc_list_elem_t *tail = NULL;
1009 struct rx_desc_pool *rx_desc_pool;
1010 uint32_t num_alloc_desc;
1011
1012 rx_desc_pool = &soc->rx_desc_status[mac_id];
1013
1014 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
1015 rx_desc_pool,
1016 1,
1017 &desc_list,
1018 &tail);
phadimanebf4cde2019-01-28 17:50:37 +05301019 /*
1020 * No free descriptors available
1021 */
1022 if (qdf_unlikely(num_alloc_desc == 0)) {
1023 work_done++;
1024 break;
1025 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001026
1027 rx_desc = &desc_list->rx_desc;
1028 }
1029
jinweic chenc3546322018-02-02 15:03:41 +08001030 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -08001031
jinweic chenc3546322018-02-02 15:03:41 +08001032 /*
1033 * qdf_nbuf alloc or map failed,
1034 * free the dp rx desc to free list,
1035 * fill in NULL dma address at current HP entry,
1036 * keep HP in mon_status_ring unchanged,
1037 * wait next time dp_rx_mon_status_srng_process
1038 * to fill in buffer at current HP.
1039 */
Jeff Johnsona8edf332019-03-18 09:51:52 -07001040 if (qdf_unlikely(!status_nbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +08001041 union dp_rx_desc_list_elem_t *desc_list = NULL;
1042 union dp_rx_desc_list_elem_t *tail = NULL;
1043 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -08001044
jinweic chenc3546322018-02-02 15:03:41 +08001045 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001046
jinweic chenc3546322018-02-02 15:03:41 +08001047 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
1048 "%s: fail to allocate or map qdf_nbuf",
1049 __func__);
1050 dp_rx_add_to_free_desc_list(&desc_list,
1051 &tail, rx_desc);
1052 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
1053 &tail, mac_id, rx_desc_pool);
1054
1055 hal_rxdma_buff_addr_info_set(
1056 rxdma_mon_status_ring_entry,
1057 0, 0, HAL_RX_BUF_RBM_SW3_BM);
1058 work_done++;
1059 break;
1060 }
1061
Kai Chen6eca1a62017-01-12 10:17:53 -08001062 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
1063
1064 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -07001065 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -08001066
1067 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
1068 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
1069
Karunakar Dasineni37995ac2018-02-06 12:37:30 -08001070 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -08001071 work_done++;
1072 }
1073done:
1074
1075 hal_srng_access_end(hal_soc, mon_status_srng);
1076
1077 return work_done;
1078
1079}
1080/*
1081 * dp_rx_mon_status_process() - Process monitor status ring and
1082 * TLV in status ring.
1083 *
1084 * @soc: core txrx main context
1085 * @mac_id: mac_id which is one of 3 mac_ids
1086 * @quota: No. of ring entry that can be serviced in one shot.
1087
1088 * Return: uint32_t: No. of ring entry that is processed.
1089 */
1090static inline uint32_t
1091dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
1092 uint32_t work_done;
1093
1094 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -07001095 quota -= work_done;
1096 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -08001097
1098 return work_done;
1099}
1100/**
1101 * dp_mon_process() - Main monitor mode processing roution.
1102 * This call monitor status ring process then monitor
1103 * destination ring process.
1104 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
1105 * @soc: core txrx main context
1106 * @mac_id: mac_id which is one of 3 mac_ids
1107 * @quota: No. of status ring entry that can be serviced in one shot.
1108
1109 * Return: uint32_t: No. of ring entry that is processed.
1110 */
1111uint32_t
1112dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -07001113 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -08001114}
Karunakar Dasineni40555682017-03-26 22:44:39 -07001115
Kai Chen6eca1a62017-01-12 10:17:53 -08001116/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001117 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -08001118 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001119 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -08001120 *
1121 * This function will detach DP RX status ring from
1122 * main device context. will free DP Rx resources for
1123 * status ring
1124 *
1125 * Return: QDF_STATUS_SUCCESS: success
1126 * QDF_STATUS_E_RESOURCES: Error return
1127 */
1128QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001129dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -08001130{
Kai Chen6eca1a62017-01-12 10:17:53 -08001131 struct dp_soc *soc = pdev->soc;
1132 struct rx_desc_pool *rx_desc_pool;
1133
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001134 rx_desc_pool = &soc->rx_desc_status[mac_id];
phadiman449a2682019-02-20 14:00:00 +05301135 if (rx_desc_pool->pool_size != 0) {
1136 if (!dp_is_soc_reinit(soc))
Varun Reddy Yeturua7c21dc2019-05-16 14:03:46 -07001137 dp_rx_desc_nbuf_and_pool_free(soc, mac_id,
1138 rx_desc_pool);
phadiman449a2682019-02-20 14:00:00 +05301139 else
Varun Reddy Yeturua7c21dc2019-05-16 14:03:46 -07001140 dp_rx_desc_nbuf_free(soc, rx_desc_pool);
phadiman449a2682019-02-20 14:00:00 +05301141 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001142
1143 return QDF_STATUS_SUCCESS;
1144}
1145
1146/*
1147 * dp_rx_buffers_replenish() - replenish monitor status ring with
1148 * rx nbufs called during dp rx
1149 * monitor status ring initialization
1150 *
1151 * @soc: core txrx main context
1152 * @mac_id: mac_id which is one of 3 mac_ids
1153 * @dp_rxdma_srng: dp monitor status circular ring
1154 * @rx_desc_pool; Pointer to Rx descriptor pool
1155 * @num_req_buffers: number of buffer to be replenished
1156 * @desc_list: list of descs if called from dp rx monitor status
1157 * process or NULL during dp rx initialization or
1158 * out of buffer interrupt
1159 * @tail: tail of descs list
1160 * @owner: who owns the nbuf (host, NSS etc...)
1161 * Return: return success or failure
1162 */
1163static inline
1164QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
1165 uint32_t mac_id,
1166 struct dp_srng *dp_rxdma_srng,
1167 struct rx_desc_pool *rx_desc_pool,
1168 uint32_t num_req_buffers,
1169 union dp_rx_desc_list_elem_t **desc_list,
1170 union dp_rx_desc_list_elem_t **tail,
1171 uint8_t owner)
1172{
1173 uint32_t num_alloc_desc;
1174 uint16_t num_desc_to_free = 0;
1175 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +08001176 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -08001177 int sync_hw_ptr = 1;
1178 qdf_dma_addr_t paddr;
1179 qdf_nbuf_t rx_netbuf;
1180 void *rxdma_ring_entry;
1181 union dp_rx_desc_list_elem_t *next;
1182 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +08001183 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001184
1185 rxdma_srng = dp_rxdma_srng->hal_srng;
1186
1187 qdf_assert(rxdma_srng);
1188
Houston Hoffmanae850c62017-08-11 16:47:50 -07001189 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301190 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -08001191 __func__, __LINE__, num_req_buffers);
1192
1193 /*
1194 * if desc_list is NULL, allocate the descs from freelist
1195 */
1196 if (!(*desc_list)) {
1197
1198 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
1199 rx_desc_pool,
1200 num_req_buffers,
1201 desc_list,
1202 tail);
1203
1204 if (!num_alloc_desc) {
1205 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +05301206 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -08001207 __func__, __LINE__);
1208 return QDF_STATUS_E_NOMEM;
1209 }
1210
Houston Hoffmanae850c62017-08-11 16:47:50 -07001211 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301212 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -08001213 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -07001214
Kai Chen6eca1a62017-01-12 10:17:53 -08001215 num_req_buffers = num_alloc_desc;
1216 }
1217
1218 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
1219 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
1220 rxdma_srng, sync_hw_ptr);
1221
Houston Hoffmanae850c62017-08-11 16:47:50 -07001222 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301223 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -08001224 __func__, __LINE__, num_entries_avail);
1225
1226 if (num_entries_avail < num_req_buffers) {
1227 num_desc_to_free = num_req_buffers - num_entries_avail;
1228 num_req_buffers = num_entries_avail;
1229 }
1230
jinweic chenc3546322018-02-02 15:03:41 +08001231 while (count < num_req_buffers) {
1232 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -08001233
jinweic chenc3546322018-02-02 15:03:41 +08001234 /*
1235 * qdf_nbuf alloc or map failed,
1236 * keep HP in mon_status_ring unchanged,
1237 * wait dp_rx_mon_status_srng_process
1238 * to fill in buffer at current HP.
1239 */
Jeff Johnsona8edf332019-03-18 09:51:52 -07001240 if (qdf_unlikely(!rx_netbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +08001241 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
1242 "%s: qdf_nbuf allocate or map fail, count %d",
1243 __func__, count);
1244 break;
1245 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001246
1247 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
1248
1249 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -07001250 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
1251 rxdma_srng);
1252
Jeff Johnsona8edf332019-03-18 09:51:52 -07001253 if (qdf_unlikely(!rxdma_ring_entry)) {
sumedh baikadyeca2de62018-04-11 14:20:38 -07001254 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +05301255 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -07001256 __func__, __LINE__, count);
1257 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
Ankit Kumar0ae4abc2019-05-02 15:08:42 +05301258 QDF_DMA_FROM_DEVICE);
sumedh baikadyeca2de62018-04-11 14:20:38 -07001259 qdf_nbuf_free(rx_netbuf);
1260 break;
1261 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001262
1263 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -07001264 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +08001265 count++;
jinweic chenc3546322018-02-02 15:03:41 +08001266
Kai Chen6eca1a62017-01-12 10:17:53 -08001267 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
1268 (*desc_list)->rx_desc.cookie, owner);
1269
Karunakar Dasineni40555682017-03-26 22:44:39 -07001270 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -07001271 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +05301272 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -08001273 __func__, __LINE__, &(*desc_list)->rx_desc,
1274 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +08001275 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -08001276
1277 *desc_list = next;
1278 }
1279
1280 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
1281
Houston Hoffmanae850c62017-08-11 16:47:50 -07001282 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301283 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -08001284
Houston Hoffmanae850c62017-08-11 16:47:50 -07001285 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301286 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -08001287
Kai Chen6eca1a62017-01-12 10:17:53 -08001288 /*
1289 * add any available free desc back to the free list
1290 */
1291 if (*desc_list) {
1292 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
1293 mac_id, rx_desc_pool);
1294 }
1295
1296 return QDF_STATUS_SUCCESS;
1297}
1298/**
1299 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
1300 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001301 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -08001302 * This function will attach a DP RX monitor status ring into pDEV
1303 * and replenish monitor status ring with buffer.
1304 *
1305 * Return: QDF_STATUS_SUCCESS: success
1306 * QDF_STATUS_E_RESOURCES: Error return
1307 */
1308QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001309dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001310 struct dp_soc *soc = pdev->soc;
1311 union dp_rx_desc_list_elem_t *desc_list = NULL;
1312 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001313 struct dp_srng *mon_status_ring;
1314 uint32_t num_entries;
Kai Chen52ef33f2019-03-05 18:33:40 -08001315 uint32_t i;
Kai Chen6eca1a62017-01-12 10:17:53 -08001316 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001317 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001318 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001319
Mohit Khanna70514992018-11-12 18:39:03 -08001320 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001321
Mohit Khanna70514992018-11-12 18:39:03 -08001322 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001323
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001324 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001325
Mohit Khanna70514992018-11-12 18:39:03 -08001326 dp_info("Mon RX Status Pool[%d] entries=%d",
1327 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001328
Mohit Khanna70514992018-11-12 18:39:03 -08001329 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1330 rx_desc_pool);
1331 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001332 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001333
Mohit Khanna70514992018-11-12 18:39:03 -08001334 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001335
Mohit Khanna70514992018-11-12 18:39:03 -08001336 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1337 mon_status_ring,
1338 rx_desc_pool,
1339 num_entries,
1340 &desc_list, &tail,
1341 HAL_RX_BUF_RBM_SW3_BM);
1342
1343 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001344 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001345
1346 qdf_nbuf_queue_init(&pdev->rx_status_q);
Amir Patel57e7e052019-05-15 20:49:57 +05301347 qdf_nbuf_queue_init(&pdev->rx_ppdu_buf_q);
Kai Chen6eca1a62017-01-12 10:17:53 -08001348
1349 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001350
Karunakar Dasineni40555682017-03-26 22:44:39 -07001351 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001352 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001353
Kai Chen783e0382018-01-25 16:29:08 -08001354 qdf_mem_zero(&pdev->rx_mon_stats,
1355 sizeof(pdev->rx_mon_stats));
1356
1357 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1358 &pdev->rx_mon_stats);
1359
Kai Chen52ef33f2019-03-05 18:33:40 -08001360 for (i = 0; i < MAX_MU_USERS; i++) {
1361 qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
1362 pdev->is_mpdu_hdr[i] = true;
1363 }
1364 qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
1365
1366 pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
1367
Kai Chen6eca1a62017-01-12 10:17:53 -08001368 return QDF_STATUS_SUCCESS;
1369}