blob: 72a5f7ee8339cc4d2a78baa59050157d22010486 [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,
49 bool *nbuf_used,
50 uint32_t rx_enh_capture_mode)
51{
52}
53#endif
54
Kai Chen6eca1a62017-01-12 10:17:53 -080055/**
Anish Nataraj38a29562017-08-18 19:41:17 +053056* dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
Soumya Bhat560f90c2018-03-30 13:53:26 +053057* @pdev: pdev ctx
Anish Nataraj38a29562017-08-18 19:41:17 +053058* @ppdu_info: ppdu info structure from ppdu ring
59* @ppdu_nbuf: qdf nbuf abstraction for linux skb
60*
61* Return: none
62*/
63#ifdef FEATURE_PERPKT_INFO
64static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +053065dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +053066 struct hal_rx_ppdu_info *ppdu_info,
67 qdf_nbuf_t ppdu_nbuf)
68{
69 struct dp_peer *peer;
Soumya Bhat560f90c2018-03-30 13:53:26 +053070 struct dp_soc *soc = pdev->soc;
Anish Nataraj38a29562017-08-18 19:41:17 +053071 struct dp_ast_entry *ast_entry;
72 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
73 uint32_t ast_index;
74
75 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
76
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +053077 cdp_rx_ppdu->first_data_seq_ctrl =
78 ppdu_info->rx_status.first_data_seq_ctrl;
Anish Natarajeb30aa72018-09-20 16:34:01 +053079 cdp_rx_ppdu->frame_ctrl =
80 ppdu_info->rx_status.frame_control;
Anish Nataraj38a29562017-08-18 19:41:17 +053081 cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
nobelj9ab76e22018-02-13 18:10:54 -080082 cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
Anish Nataraj38a29562017-08-18 19:41:17 +053083 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
84 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053085 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
86 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
87 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +053088 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
89 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Keyur Parekh49cdc742018-05-09 10:59:03 -070090 if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
91 (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
92 cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
93 else
94 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj50347012018-03-06 21:12:45 +053095 cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
Anish Nataraj38a29562017-08-18 19:41:17 +053096 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +053097 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Pamidipati, Vijayba4b57f2019-02-13 16:47:23 +053098 cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
99 QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
100 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Anish Nataraj38a29562017-08-18 19:41:17 +0530101 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +0530102 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
103 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
nobeljd8039592018-03-13 16:59:42 -0700104 cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530105 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
106 cdp_rx_ppdu->udp_msdu_count +
107 cdp_rx_ppdu->other_msdu_count);
Amir Patel468bded2019-03-21 11:42:31 +0530108 cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
109 if (CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl))
110 cdp_rx_ppdu->retries += ppdu_info->com_info.mpdu_cnt_fcs_ok;
Pranita Solankeed0aba62018-01-12 19:14:31 +0530111
112 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
113 cdp_rx_ppdu->is_ampdu = 1;
114 else
115 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +0530116
117 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +0530118 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Soumya Bhat560f90c2018-03-30 13:53:26 +0530119
120 ast_index = ppdu_info->rx_status.ast_index;
Tallapragada Kalyana7023622018-12-03 19:29:52 +0530121 if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530122 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
123 return;
124 }
125
126 ast_entry = soc->ast_table[ast_index];
127 if (!ast_entry) {
128 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
129 return;
130 }
131 peer = ast_entry->peer;
132 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
133 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
134 return;
135 }
136
137 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800138 peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
Soumya Bhat560f90c2018-03-30 13:53:26 +0530139 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
140 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Keyur Parekh44d8f8f2019-03-12 12:39:41 -0700141 cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
Anish Nataraj38a29562017-08-18 19:41:17 +0530142}
143#else
144static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530145dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530146 struct hal_rx_ppdu_info *ppdu_info,
147 qdf_nbuf_t ppdu_nbuf)
148{
149}
150#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530151/**
152 * dp_rx_stats_update() - Update per-peer statistics
153 * @soc: Datapath SOC handle
154 * @peer: Datapath peer handle
155 * @ppdu: PPDU Descriptor
156 *
157 * Return: None
158 */
159#ifdef FEATURE_PERPKT_INFO
ydb247452018-08-08 00:23:16 +0530160static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
161 struct cdp_rx_indication_ppdu *ppdu)
162{
163 uint32_t ratekbps = 0;
164 uint32_t ppdu_rx_rate = 0;
165 uint32_t nss = 0;
Amir Patel78824b12019-02-23 10:54:32 +0530166 uint32_t rix;
ydb247452018-08-08 00:23:16 +0530167
168 if (!peer || !ppdu)
169 return;
170
171 if (ppdu->u.nss == 0)
172 nss = 0;
173 else
174 nss = ppdu->u.nss - 1;
175
Anish Nataraj376d9b12018-08-13 14:12:01 +0530176 ratekbps = dp_getrateindex(ppdu->u.gi,
177 ppdu->u.mcs,
ydb247452018-08-08 00:23:16 +0530178 nss,
179 ppdu->u.preamble,
Amir Patel78824b12019-02-23 10:54:32 +0530180 ppdu->u.bw,
181 &rix);
ydb247452018-08-08 00:23:16 +0530182
183 if (!ratekbps)
184 return;
185
Amir Patel468bded2019-03-21 11:42:31 +0530186 ppdu->rix = rix;
ydb247452018-08-08 00:23:16 +0530187 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
192 if (peer->vdev)
193 peer->vdev->stats.rx.last_rx_rate = ratekbps;
194}
195
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530196static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
197 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530198{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530199 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530200 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530201 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530202 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530203
204 mcs = ppdu->u.mcs;
205 preamble = ppdu->u.preamble;
206 num_msdu = ppdu->num_msdu;
207
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530208 if (pdev)
209 soc = pdev->soc;
210 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530211 return;
212
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530213 if (!peer) {
214 is_invalid_peer = true;
215 peer = pdev->invalid_peer;
216 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530217
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530218 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530219 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530220
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530221 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Amir Patelbb69cfa2019-03-28 16:16:01 +0530222 if (!peer->stats.rx.avg_rssi)
223 peer->stats.rx.avg_rssi = ppdu->rssi;
224 else
225 peer->stats.rx.avg_rssi =
226 DP_GET_AVG_RSSI(peer->stats.rx.avg_rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530227
228 if ((preamble == DOT11_A) || (preamble == DOT11_B))
229 ppdu->u.nss = 1;
230
231 if (ppdu->u.nss)
232 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
233
Pranita Solankea12b4b32017-11-20 23:04:14 +0530234 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530235 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530236 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530237 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
238 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
239 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530240 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530241 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530242 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
243 DP_STATS_INCC(peer,
244 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530245 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530246 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530247 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530248 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
249 DP_STATS_INCC(peer,
250 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530251 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530252 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530253 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530254 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
255 DP_STATS_INCC(peer,
256 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530257 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530258 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530259 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530260 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
261 DP_STATS_INCC(peer,
262 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
263 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
264 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530265 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530266 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
267 DP_STATS_INCC(peer,
268 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
269 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530270 /*
271 * If invalid TID, it could be a non-qos frame, hence do not update
272 * any AC counters
273 */
274 ac = TID_TO_WME_AC(ppdu->tid);
275 if (ppdu->tid != HAL_TID_INVALID)
276 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530277 dp_peer_stats_notify(peer);
278 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530279
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530280 if (is_invalid_peer)
281 return;
282
ydb247452018-08-08 00:23:16 +0530283 dp_rx_rate_stats_update(peer, ppdu);
284
Amir Patel756d05e2018-10-10 12:35:30 +0530285#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
286 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
287 &peer->stats, ppdu->peer_id,
288 UPDATE_PEER_STATS, pdev->pdev_id);
289#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530290}
291#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530292
293/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530294 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530295 * @soc: core txrx main context
296 * @pdev: pdev strcuture
297 * @ppdu_info: structure for rx ppdu ring
298 *
299 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
300 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530301 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530302#ifdef FEATURE_PERPKT_INFO
303static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530304dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530305 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
306{
307 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530308 struct ieee80211_frame *wh;
309 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530310
Jeff Johnsona8edf332019-03-18 09:51:52 -0700311 if (!ppdu_info->msdu_info.first_msdu_payload)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530312 return QDF_STATUS_SUCCESS;
313
Soumya Bhat2f54de22018-02-21 09:54:28 +0530314 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530315 return QDF_STATUS_SUCCESS;
316
Soumya Bhat2f54de22018-02-21 09:54:28 +0530317 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530318
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530319 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
320 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530321 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530322 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530323 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530324
325 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
326 return QDF_STATUS_SUCCESS;
327
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530328 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
329 IEEE80211_FC0_TYPE_MGT) ||
330 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
331 IEEE80211_FC0_TYPE_CTL)) {
332 return QDF_STATUS_SUCCESS;
333 }
334
335 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
336 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530337 /* only retain RX MSDU payload in the skb */
338 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
339 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530340 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
341 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
342 return QDF_STATUS_E_ALREADY;
343}
344#else
345static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530346dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530347 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
348{
349 return QDF_STATUS_SUCCESS;
350}
351#endif
352
sumedh baikady59a2d332018-05-22 01:50:38 -0700353/**
354 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
355 * @soc: Datapath SOC handle
356 * @pdev: Datapath PDEV handle
357 * @ppdu_info: Structure for rx ppdu info
358 * @nbuf: Qdf nbuf abstraction for linux skb
359 *
360 * Return: 0 on success, 1 on failure
361 */
362static inline int
363dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
364 struct hal_rx_ppdu_info *ppdu_info,
365 qdf_nbuf_t nbuf)
366{
367 uint8_t size = 0;
368
369 if (!pdev->monitor_vdev) {
370 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
371 "[%s]:[%d] Monitor vdev is NULL !!",
372 __func__, __LINE__);
373 return 1;
374 }
Jeff Johnsona8edf332019-03-18 09:51:52 -0700375 if (!ppdu_info->msdu_info.first_msdu_payload) {
sumedh baikady59a2d332018-05-22 01:50:38 -0700376 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
377 "[%s]:[%d] First msdu payload not present",
378 __func__, __LINE__);
379 return 1;
380 }
381
sumedh baikadyda159202018-11-01 17:31:23 -0700382 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700383 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700384 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700385 ppdu_info->msdu_info.first_msdu_payload = NULL;
386
387 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
388 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
389 "[%s]:[%d] No header present",
390 __func__, __LINE__);
391 return 1;
392 }
393
sumedh baikadyda159202018-11-01 17:31:23 -0700394 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700395 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
396 ppdu_info->msdu_info.payload_len);
397 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
398 nbuf, sizeof(struct rx_pkt_tlvs));
399 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
400 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700401 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700402 return 0;
403}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530404
405/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530406* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
407* @soc: core txrx main context
408* @pdev: pdev strcuture
409* @ppdu_info: structure for rx ppdu ring
410*
411* Return: none
412*/
413#ifdef FEATURE_PERPKT_INFO
414static inline void
415dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
416 struct hal_rx_ppdu_info *ppdu_info)
417{
418 qdf_nbuf_t ppdu_nbuf;
419 struct dp_peer *peer;
420 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
421
Anish Nataraj28490c42018-01-19 19:34:54 +0530422 /*
423 * Do not allocate if fcs error,
424 * ast idx invalid / fctl invalid
425 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530426 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
427 return;
428
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530429 if (ppdu_info->nac_info.fc_valid &&
430 ppdu_info->nac_info.to_ds_flag &&
431 ppdu_info->nac_info.mac_addr2_valid) {
432 struct dp_neighbour_peer *peer = NULL;
433 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
434
435 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
436 if (pdev->neighbour_peers_added) {
437 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
438 neighbour_peer_list_elem) {
439 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
440 &ppdu_info->nac_info.mac_addr2,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800441 QDF_MAC_ADDR_SIZE)) {
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530442 peer->rssi = rssi;
443 break;
444 }
445 }
446 }
447 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
448 }
449
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530450 /* need not generate wdi event when mcopy and
451 * enhanced stats are not enabled
452 */
453 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
454 return;
455
Soumya Bhat560f90c2018-03-30 13:53:26 +0530456 if (!pdev->mcopy_mode) {
457 if (!ppdu_info->rx_status.frame_control_info_valid)
458 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530459
Soumya Bhat560f90c2018-03-30 13:53:26 +0530460 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
461 return;
462 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530463 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Kiran Venkatappa4b50f332019-03-20 18:14:17 +0530464 sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
Anish Nataraj38a29562017-08-18 19:41:17 +0530465 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530466 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530467 qdf_nbuf_put_tail(ppdu_nbuf,
468 sizeof(struct cdp_rx_indication_ppdu));
469 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530470 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800471 if (peer) {
Amir Patel468bded2019-03-21 11:42:31 +0530472 cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530473 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800474 dp_peer_unref_del_find_by_id(peer);
475 }
476 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
477 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
478 soc, ppdu_nbuf,
479 cdp_rx_ppdu->peer_id,
480 WDI_NO_VAL, pdev->pdev_id);
481 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530482 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
483 ppdu_nbuf, HTT_INVALID_PEER,
484 WDI_NO_VAL, pdev->pdev_id);
485 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530486 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530487 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530488 }
489}
490#else
491static inline void
492dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
493 struct hal_rx_ppdu_info *ppdu_info)
494{
495}
496#endif
497
498/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800499* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
500* filtering enabled
501* @soc: core txrx main context
502* @ppdu_info: Structure for rx ppdu info
503* @status_nbuf: Qdf nbuf abstraction for linux skb
504* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
505*
506* Return: none
507*/
508static inline void
509dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
510 struct hal_rx_ppdu_info *ppdu_info,
511 qdf_nbuf_t status_nbuf, uint32_t mac_id)
512{
513 struct dp_peer *peer;
514 struct dp_ast_entry *ast_entry;
515 uint32_t ast_index;
516
517 ast_index = ppdu_info->rx_status.ast_index;
518 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
519 ast_entry = soc->ast_table[ast_index];
520 if (ast_entry) {
521 peer = ast_entry->peer;
522 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
523 if (peer->peer_based_pktlog_filter) {
524 dp_wdi_event_handler(
525 WDI_EVENT_RX_DESC, soc,
526 status_nbuf,
527 peer->peer_ids[0],
528 WDI_NO_VAL, mac_id);
529 }
530 }
531 }
532 }
533}
534
535/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800536* dp_rx_mon_status_process_tlv() - Process status TLV in status
537* buffer on Rx status Queue posted by status SRNG processing.
538* @soc: core txrx main context
539* @mac_id: mac_id which is one of 3 mac_ids _ring
540*
541* Return: none
542*/
543static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700544dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
545 uint32_t quota)
546{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800547 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800548 struct hal_rx_ppdu_info *ppdu_info;
549 qdf_nbuf_t status_nbuf;
550 uint8_t *rx_tlv;
551 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700552 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530553 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen52ef33f2019-03-05 18:33:40 -0800554 QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800555 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700556 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800557 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen52ef33f2019-03-05 18:33:40 -0800558 bool nbuf_used;
559 uint32_t rx_enh_capture_mode;
560
Kai Chen6eca1a62017-01-12 10:17:53 -0800561
Kai Chen6eca1a62017-01-12 10:17:53 -0800562 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800563 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800564
565 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
566 return;
567
Kai Chen52ef33f2019-03-05 18:33:40 -0800568 rx_enh_capture_mode = pdev->rx_enh_capture_mode;
569
Kai Chen6eca1a62017-01-12 10:17:53 -0800570 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
571
572 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530573
Kai Chen6eca1a62017-01-12 10:17:53 -0800574 rx_tlv = qdf_nbuf_data(status_nbuf);
575 rx_tlv_start = rx_tlv;
Kai Chen52ef33f2019-03-05 18:33:40 -0800576 nbuf_used = false;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700577
Jeff Johnsona8edf332019-03-18 09:51:52 -0700578 if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
Kai Chen52ef33f2019-03-05 18:33:40 -0800579 pdev->mcopy_mode ||
580 (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
Keyur Parekhfad6d082017-05-07 08:54:47 -0700581 do {
582 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530583 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800584
585 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
586 rx_mon_stats);
587
Kai Chen52ef33f2019-03-05 18:33:40 -0800588 dp_rx_mon_enh_capture_process(pdev, tlv_status,
589 status_nbuf, ppdu_info,
590 &nbuf_used, rx_enh_capture_mode);
591
Keyur Parekhfad6d082017-05-07 08:54:47 -0700592 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800593
Keyur Parekhfad6d082017-05-07 08:54:47 -0700594 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
595 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800596
Kai Chen52ef33f2019-03-05 18:33:40 -0800597 } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
598 (tlv_status == HAL_TLV_STATUS_HEADER) ||
599 (tlv_status == HAL_TLV_STATUS_MPDU_END));
Keyur Parekhfad6d082017-05-07 08:54:47 -0700600 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800601 if (pdev->dp_peer_based_pktlog) {
602 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
603 status_nbuf, mac_id);
604 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800605 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
606 pktlog_mode = WDI_EVENT_RX_DESC;
607 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
608 pktlog_mode = WDI_EVENT_LITE_RX;
609
610 if (pktlog_mode != WDI_NO_VAL)
611 dp_wdi_event_handler(pktlog_mode, soc,
612 status_nbuf,
613 HTT_INVALID_PEER,
614 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800615 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530616
617 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700618 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
619 && pdev->monitor_vdev) {
620 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
621 pdev, ppdu_info, status_nbuf);
622 if (smart_mesh_status)
623 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530624 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530625 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530626 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530627 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530628 qdf_nbuf_free(status_nbuf);
Kai Chen52ef33f2019-03-05 18:33:40 -0800629 } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
630 if (!nbuf_used)
631 qdf_nbuf_free(status_nbuf);
632
633 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
634 enh_log_status =
635 dp_rx_handle_enh_capture(soc,
636 pdev, ppdu_info);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530637 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700638 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530639 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800640
chenguo1b880462018-07-11 15:34:56 +0800641 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
642 dp_rx_mon_deliver_non_std(soc, mac_id);
643 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800644 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530645 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700646 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530647 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530648
nobelj1c31fee2018-03-21 11:47:05 -0700649 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
650 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700651 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800652 }
653 }
654 return;
655}
656
657/*
658 * dp_rx_mon_status_srng_process() - Process monitor status ring
659 * post the status ring buffer to Rx status Queue for later
660 * processing when status ring is filled with status TLV.
661 * Allocate a new buffer to status ring if the filled buffer
662 * is posted.
663 *
664 * @soc: core txrx main context
665 * @mac_id: mac_id which is one of 3 mac_ids
666 * @quota: No. of ring entry that can be serviced in one shot.
667
668 * Return: uint32_t: No. of ring entry that is processed.
669 */
670static inline uint32_t
671dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
672 uint32_t quota)
673{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800674 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800675 void *hal_soc;
676 void *mon_status_srng;
677 void *rxdma_mon_status_ring_entry;
678 QDF_STATUS status;
679 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800680 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800681
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800682 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800683
684 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700685 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
686
687 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530688 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700689 __func__, __LINE__, mon_status_srng);
690 return work_done;
691 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800692
693 hal_soc = soc->hal_soc;
694
695 qdf_assert(hal_soc);
696
697 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
698 goto done;
699
700 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
701 * BUFFER_ADDR_INFO STRUCT
702 */
703 while (qdf_likely((rxdma_mon_status_ring_entry =
704 hal_srng_src_peek(hal_soc, mon_status_srng))
705 && quota--)) {
706 uint32_t rx_buf_cookie;
707 qdf_nbuf_t status_nbuf;
708 struct dp_rx_desc *rx_desc;
709 uint8_t *status_buf;
710 qdf_dma_addr_t paddr;
711 uint64_t buf_addr;
712
713 buf_addr =
714 (HAL_RX_BUFFER_ADDR_31_0_GET(
715 rxdma_mon_status_ring_entry) |
716 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
717 rxdma_mon_status_ring_entry)) << 32));
718
719 if (qdf_likely(buf_addr)) {
720
721 rx_buf_cookie =
722 HAL_RX_BUF_COOKIE_GET(
723 rxdma_mon_status_ring_entry);
724 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
725 rx_buf_cookie);
726
727 qdf_assert(rx_desc);
728
729 status_nbuf = rx_desc->nbuf;
730
731 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
732 QDF_DMA_FROM_DEVICE);
733
734 status_buf = qdf_nbuf_data(status_nbuf);
735
736 status = hal_get_rx_status_done(status_buf);
737
738 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800739 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700740 hal_get_sw_hptp(hal_soc, mon_status_srng,
741 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800742 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800743 QDF_TRACE_LEVEL_ERROR,
744 "[%s][%d] status not done - hp:%u, tp:%u",
745 __func__, __LINE__, hp, tp);
746 /* WAR for missing status: Skip status entry */
747 hal_srng_src_get_next(hal_soc, mon_status_srng);
748 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800749 }
750 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
751
752 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
753 QDF_DMA_FROM_DEVICE);
754
755 /* Put the status_nbuf to queue */
756 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
757
758 } else {
759 union dp_rx_desc_list_elem_t *desc_list = NULL;
760 union dp_rx_desc_list_elem_t *tail = NULL;
761 struct rx_desc_pool *rx_desc_pool;
762 uint32_t num_alloc_desc;
763
764 rx_desc_pool = &soc->rx_desc_status[mac_id];
765
766 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
767 rx_desc_pool,
768 1,
769 &desc_list,
770 &tail);
phadimanebf4cde2019-01-28 17:50:37 +0530771 /*
772 * No free descriptors available
773 */
774 if (qdf_unlikely(num_alloc_desc == 0)) {
775 work_done++;
776 break;
777 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800778
779 rx_desc = &desc_list->rx_desc;
780 }
781
jinweic chenc3546322018-02-02 15:03:41 +0800782 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800783
jinweic chenc3546322018-02-02 15:03:41 +0800784 /*
785 * qdf_nbuf alloc or map failed,
786 * free the dp rx desc to free list,
787 * fill in NULL dma address at current HP entry,
788 * keep HP in mon_status_ring unchanged,
789 * wait next time dp_rx_mon_status_srng_process
790 * to fill in buffer at current HP.
791 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700792 if (qdf_unlikely(!status_nbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800793 union dp_rx_desc_list_elem_t *desc_list = NULL;
794 union dp_rx_desc_list_elem_t *tail = NULL;
795 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800796
jinweic chenc3546322018-02-02 15:03:41 +0800797 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800798
jinweic chenc3546322018-02-02 15:03:41 +0800799 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
800 "%s: fail to allocate or map qdf_nbuf",
801 __func__);
802 dp_rx_add_to_free_desc_list(&desc_list,
803 &tail, rx_desc);
804 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
805 &tail, mac_id, rx_desc_pool);
806
807 hal_rxdma_buff_addr_info_set(
808 rxdma_mon_status_ring_entry,
809 0, 0, HAL_RX_BUF_RBM_SW3_BM);
810 work_done++;
811 break;
812 }
813
Kai Chen6eca1a62017-01-12 10:17:53 -0800814 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
815
816 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700817 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800818
819 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
820 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
821
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800822 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800823 work_done++;
824 }
825done:
826
827 hal_srng_access_end(hal_soc, mon_status_srng);
828
829 return work_done;
830
831}
832/*
833 * dp_rx_mon_status_process() - Process monitor status ring and
834 * TLV in status ring.
835 *
836 * @soc: core txrx main context
837 * @mac_id: mac_id which is one of 3 mac_ids
838 * @quota: No. of ring entry that can be serviced in one shot.
839
840 * Return: uint32_t: No. of ring entry that is processed.
841 */
842static inline uint32_t
843dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
844 uint32_t work_done;
845
846 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700847 quota -= work_done;
848 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800849
850 return work_done;
851}
852/**
853 * dp_mon_process() - Main monitor mode processing roution.
854 * This call monitor status ring process then monitor
855 * destination ring process.
856 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
857 * @soc: core txrx main context
858 * @mac_id: mac_id which is one of 3 mac_ids
859 * @quota: No. of status ring entry that can be serviced in one shot.
860
861 * Return: uint32_t: No. of ring entry that is processed.
862 */
863uint32_t
864dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700865 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800866}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700867
Kai Chen6eca1a62017-01-12 10:17:53 -0800868/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700869 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800870 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800871 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800872 *
873 * This function will detach DP RX status ring from
874 * main device context. will free DP Rx resources for
875 * status ring
876 *
877 * Return: QDF_STATUS_SUCCESS: success
878 * QDF_STATUS_E_RESOURCES: Error return
879 */
880QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800881dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800882{
Kai Chen6eca1a62017-01-12 10:17:53 -0800883 struct dp_soc *soc = pdev->soc;
884 struct rx_desc_pool *rx_desc_pool;
885
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800886 rx_desc_pool = &soc->rx_desc_status[mac_id];
phadiman449a2682019-02-20 14:00:00 +0530887 if (rx_desc_pool->pool_size != 0) {
888 if (!dp_is_soc_reinit(soc))
889 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
890 else
891 dp_rx_desc_nbuf_pool_free(soc, rx_desc_pool);
892 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800893
894 return QDF_STATUS_SUCCESS;
895}
896
897/*
898 * dp_rx_buffers_replenish() - replenish monitor status ring with
899 * rx nbufs called during dp rx
900 * monitor status ring initialization
901 *
902 * @soc: core txrx main context
903 * @mac_id: mac_id which is one of 3 mac_ids
904 * @dp_rxdma_srng: dp monitor status circular ring
905 * @rx_desc_pool; Pointer to Rx descriptor pool
906 * @num_req_buffers: number of buffer to be replenished
907 * @desc_list: list of descs if called from dp rx monitor status
908 * process or NULL during dp rx initialization or
909 * out of buffer interrupt
910 * @tail: tail of descs list
911 * @owner: who owns the nbuf (host, NSS etc...)
912 * Return: return success or failure
913 */
914static inline
915QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
916 uint32_t mac_id,
917 struct dp_srng *dp_rxdma_srng,
918 struct rx_desc_pool *rx_desc_pool,
919 uint32_t num_req_buffers,
920 union dp_rx_desc_list_elem_t **desc_list,
921 union dp_rx_desc_list_elem_t **tail,
922 uint8_t owner)
923{
924 uint32_t num_alloc_desc;
925 uint16_t num_desc_to_free = 0;
926 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800927 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800928 int sync_hw_ptr = 1;
929 qdf_dma_addr_t paddr;
930 qdf_nbuf_t rx_netbuf;
931 void *rxdma_ring_entry;
932 union dp_rx_desc_list_elem_t *next;
933 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800934 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800935
936 rxdma_srng = dp_rxdma_srng->hal_srng;
937
938 qdf_assert(rxdma_srng);
939
Houston Hoffmanae850c62017-08-11 16:47:50 -0700940 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530941 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800942 __func__, __LINE__, num_req_buffers);
943
944 /*
945 * if desc_list is NULL, allocate the descs from freelist
946 */
947 if (!(*desc_list)) {
948
949 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
950 rx_desc_pool,
951 num_req_buffers,
952 desc_list,
953 tail);
954
955 if (!num_alloc_desc) {
956 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530957 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800958 __func__, __LINE__);
959 return QDF_STATUS_E_NOMEM;
960 }
961
Houston Hoffmanae850c62017-08-11 16:47:50 -0700962 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530963 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800964 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700965
Kai Chen6eca1a62017-01-12 10:17:53 -0800966 num_req_buffers = num_alloc_desc;
967 }
968
969 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
970 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
971 rxdma_srng, sync_hw_ptr);
972
Houston Hoffmanae850c62017-08-11 16:47:50 -0700973 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530974 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800975 __func__, __LINE__, num_entries_avail);
976
977 if (num_entries_avail < num_req_buffers) {
978 num_desc_to_free = num_req_buffers - num_entries_avail;
979 num_req_buffers = num_entries_avail;
980 }
981
jinweic chenc3546322018-02-02 15:03:41 +0800982 while (count < num_req_buffers) {
983 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800984
jinweic chenc3546322018-02-02 15:03:41 +0800985 /*
986 * qdf_nbuf alloc or map failed,
987 * keep HP in mon_status_ring unchanged,
988 * wait dp_rx_mon_status_srng_process
989 * to fill in buffer at current HP.
990 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700991 if (qdf_unlikely(!rx_netbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800992 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
993 "%s: qdf_nbuf allocate or map fail, count %d",
994 __func__, count);
995 break;
996 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800997
998 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
999
1000 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -07001001 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
1002 rxdma_srng);
1003
Jeff Johnsona8edf332019-03-18 09:51:52 -07001004 if (qdf_unlikely(!rxdma_ring_entry)) {
sumedh baikadyeca2de62018-04-11 14:20:38 -07001005 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +05301006 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -07001007 __func__, __LINE__, count);
1008 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
1009 QDF_DMA_BIDIRECTIONAL);
1010 qdf_nbuf_free(rx_netbuf);
1011 break;
1012 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001013
1014 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -07001015 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +08001016 count++;
jinweic chenc3546322018-02-02 15:03:41 +08001017
Kai Chen6eca1a62017-01-12 10:17:53 -08001018 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
1019 (*desc_list)->rx_desc.cookie, owner);
1020
Karunakar Dasineni40555682017-03-26 22:44:39 -07001021 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -07001022 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +05301023 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -08001024 __func__, __LINE__, &(*desc_list)->rx_desc,
1025 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +08001026 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -08001027
1028 *desc_list = next;
1029 }
1030
1031 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
1032
Houston Hoffmanae850c62017-08-11 16:47:50 -07001033 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301034 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -08001035
Houston Hoffmanae850c62017-08-11 16:47:50 -07001036 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301037 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -08001038
Kai Chen6eca1a62017-01-12 10:17:53 -08001039 /*
1040 * add any available free desc back to the free list
1041 */
1042 if (*desc_list) {
1043 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
1044 mac_id, rx_desc_pool);
1045 }
1046
1047 return QDF_STATUS_SUCCESS;
1048}
1049/**
1050 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
1051 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001052 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -08001053 * This function will attach a DP RX monitor status ring into pDEV
1054 * and replenish monitor status ring with buffer.
1055 *
1056 * Return: QDF_STATUS_SUCCESS: success
1057 * QDF_STATUS_E_RESOURCES: Error return
1058 */
1059QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001060dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001061 struct dp_soc *soc = pdev->soc;
1062 union dp_rx_desc_list_elem_t *desc_list = NULL;
1063 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001064 struct dp_srng *mon_status_ring;
1065 uint32_t num_entries;
Kai Chen52ef33f2019-03-05 18:33:40 -08001066 uint32_t i;
Kai Chen6eca1a62017-01-12 10:17:53 -08001067 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001068 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001069 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001070
Mohit Khanna70514992018-11-12 18:39:03 -08001071 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001072
Mohit Khanna70514992018-11-12 18:39:03 -08001073 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001074
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001075 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001076
Mohit Khanna70514992018-11-12 18:39:03 -08001077 dp_info("Mon RX Status Pool[%d] entries=%d",
1078 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001079
Mohit Khanna70514992018-11-12 18:39:03 -08001080 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1081 rx_desc_pool);
1082 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001083 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001084
Mohit Khanna70514992018-11-12 18:39:03 -08001085 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001086
Mohit Khanna70514992018-11-12 18:39:03 -08001087 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1088 mon_status_ring,
1089 rx_desc_pool,
1090 num_entries,
1091 &desc_list, &tail,
1092 HAL_RX_BUF_RBM_SW3_BM);
1093
1094 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001095 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001096
1097 qdf_nbuf_queue_init(&pdev->rx_status_q);
1098
1099 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001100
Karunakar Dasineni40555682017-03-26 22:44:39 -07001101 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001102 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001103
Kai Chen783e0382018-01-25 16:29:08 -08001104 qdf_mem_zero(&pdev->rx_mon_stats,
1105 sizeof(pdev->rx_mon_stats));
1106
1107 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1108 &pdev->rx_mon_stats);
1109
Kai Chen52ef33f2019-03-05 18:33:40 -08001110 for (i = 0; i < MAX_MU_USERS; i++) {
1111 qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
1112 pdev->is_mpdu_hdr[i] = true;
1113 }
1114 qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
1115
1116 pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
1117
Kai Chen6eca1a62017-01-12 10:17:53 -08001118 return QDF_STATUS_SUCCESS;
1119}