blob: de5de6d492c0f0018c364b61f48d7e3b60f7631a [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;
Amir Patelac7d9462019-03-28 16:16:01 +0530109 cdp_rx_ppdu->retries = CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl) ?
110 ppdu_info->com_info.mpdu_cnt_fcs_ok : 0;
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);
Amir Patelac7d9462019-03-28 16:16:01 +0530191 ppdu->rx_ratekbps = ratekbps;
ydb247452018-08-08 00:23:16 +0530192
193 if (peer->vdev)
194 peer->vdev->stats.rx.last_rx_rate = ratekbps;
195}
196
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530197static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
198 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530199{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530200 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530201 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530202 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530203 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530204
205 mcs = ppdu->u.mcs;
206 preamble = ppdu->u.preamble;
207 num_msdu = ppdu->num_msdu;
208
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530209 if (pdev)
210 soc = pdev->soc;
211 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530212 return;
213
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530214 if (!peer) {
215 is_invalid_peer = true;
216 peer = pdev->invalid_peer;
217 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530218
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530219 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530220 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530221
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530222 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Surya Prakash07c81e72019-04-29 10:08:01 +0530223 if (peer->stats.rx.avg_rssi == INVALID_RSSI)
Amir Patelbb69cfa2019-03-28 16:16:01 +0530224 peer->stats.rx.avg_rssi = ppdu->rssi;
225 else
226 peer->stats.rx.avg_rssi =
227 DP_GET_AVG_RSSI(peer->stats.rx.avg_rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530228
229 if ((preamble == DOT11_A) || (preamble == DOT11_B))
230 ppdu->u.nss = 1;
231
232 if (ppdu->u.nss)
233 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
234
Pranita Solankea12b4b32017-11-20 23:04:14 +0530235 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530236 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530237 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530238 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
239 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
240 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530241 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530242 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530243 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
244 DP_STATS_INCC(peer,
245 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530246 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530247 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530248 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530249 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
250 DP_STATS_INCC(peer,
251 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530252 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530253 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530254 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530255 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
256 DP_STATS_INCC(peer,
257 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530258 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530259 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530260 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530261 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
262 DP_STATS_INCC(peer,
263 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
264 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
265 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530266 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530267 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
268 DP_STATS_INCC(peer,
269 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
270 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530271 /*
272 * If invalid TID, it could be a non-qos frame, hence do not update
273 * any AC counters
274 */
275 ac = TID_TO_WME_AC(ppdu->tid);
276 if (ppdu->tid != HAL_TID_INVALID)
277 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530278 dp_peer_stats_notify(peer);
279 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530280
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530281 if (is_invalid_peer)
282 return;
283
ydb247452018-08-08 00:23:16 +0530284 dp_rx_rate_stats_update(peer, ppdu);
285
Amir Patel756d05e2018-10-10 12:35:30 +0530286#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
287 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
288 &peer->stats, ppdu->peer_id,
289 UPDATE_PEER_STATS, pdev->pdev_id);
290#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530291}
292#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530293
294/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530295 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530296 * @soc: core txrx main context
297 * @pdev: pdev strcuture
298 * @ppdu_info: structure for rx ppdu ring
299 *
300 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
301 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530302 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530303#ifdef FEATURE_PERPKT_INFO
304static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530305dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530306 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
307{
308 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530309 struct ieee80211_frame *wh;
310 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530311
Jeff Johnsona8edf332019-03-18 09:51:52 -0700312 if (!ppdu_info->msdu_info.first_msdu_payload)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530313 return QDF_STATUS_SUCCESS;
314
Soumya Bhat2f54de22018-02-21 09:54:28 +0530315 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530316 return QDF_STATUS_SUCCESS;
317
Soumya Bhat2f54de22018-02-21 09:54:28 +0530318 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530319
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530320 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
321 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530322 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530323 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530324 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530325
326 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
327 return QDF_STATUS_SUCCESS;
328
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530329 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
330 IEEE80211_FC0_TYPE_MGT) ||
331 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
332 IEEE80211_FC0_TYPE_CTL)) {
333 return QDF_STATUS_SUCCESS;
334 }
335
336 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
337 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530338 /* only retain RX MSDU payload in the skb */
339 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
340 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530341 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
342 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
343 return QDF_STATUS_E_ALREADY;
344}
345#else
346static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530347dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530348 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
349{
350 return QDF_STATUS_SUCCESS;
351}
352#endif
353
sumedh baikady59a2d332018-05-22 01:50:38 -0700354/**
355 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
356 * @soc: Datapath SOC handle
357 * @pdev: Datapath PDEV handle
358 * @ppdu_info: Structure for rx ppdu info
359 * @nbuf: Qdf nbuf abstraction for linux skb
360 *
361 * Return: 0 on success, 1 on failure
362 */
363static inline int
364dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
365 struct hal_rx_ppdu_info *ppdu_info,
366 qdf_nbuf_t nbuf)
367{
368 uint8_t size = 0;
369
370 if (!pdev->monitor_vdev) {
371 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
372 "[%s]:[%d] Monitor vdev is NULL !!",
373 __func__, __LINE__);
374 return 1;
375 }
Jeff Johnsona8edf332019-03-18 09:51:52 -0700376 if (!ppdu_info->msdu_info.first_msdu_payload) {
sumedh baikady59a2d332018-05-22 01:50:38 -0700377 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
378 "[%s]:[%d] First msdu payload not present",
379 __func__, __LINE__);
380 return 1;
381 }
382
sumedh baikadyda159202018-11-01 17:31:23 -0700383 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700384 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700385 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700386 ppdu_info->msdu_info.first_msdu_payload = NULL;
387
388 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
389 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
390 "[%s]:[%d] No header present",
391 __func__, __LINE__);
392 return 1;
393 }
394
sumedh baikadyda159202018-11-01 17:31:23 -0700395 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700396 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
397 ppdu_info->msdu_info.payload_len);
398 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
399 nbuf, sizeof(struct rx_pkt_tlvs));
400 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
401 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700402 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700403 return 0;
404}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530405
406/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530407* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
408* @soc: core txrx main context
409* @pdev: pdev strcuture
410* @ppdu_info: structure for rx ppdu ring
411*
412* Return: none
413*/
414#ifdef FEATURE_PERPKT_INFO
415static inline void
416dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
417 struct hal_rx_ppdu_info *ppdu_info)
418{
419 qdf_nbuf_t ppdu_nbuf;
420 struct dp_peer *peer;
421 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
422
Anish Nataraj28490c42018-01-19 19:34:54 +0530423 /*
424 * Do not allocate if fcs error,
425 * ast idx invalid / fctl invalid
426 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530427 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
428 return;
429
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530430 if (ppdu_info->nac_info.fc_valid &&
431 ppdu_info->nac_info.to_ds_flag &&
432 ppdu_info->nac_info.mac_addr2_valid) {
433 struct dp_neighbour_peer *peer = NULL;
434 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
435
436 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
437 if (pdev->neighbour_peers_added) {
438 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
439 neighbour_peer_list_elem) {
440 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
441 &ppdu_info->nac_info.mac_addr2,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800442 QDF_MAC_ADDR_SIZE)) {
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530443 peer->rssi = rssi;
444 break;
445 }
446 }
447 }
448 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
449 }
450
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530451 /* need not generate wdi event when mcopy and
452 * enhanced stats are not enabled
453 */
454 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
455 return;
456
Soumya Bhat560f90c2018-03-30 13:53:26 +0530457 if (!pdev->mcopy_mode) {
458 if (!ppdu_info->rx_status.frame_control_info_valid)
459 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530460
Soumya Bhat560f90c2018-03-30 13:53:26 +0530461 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
462 return;
463 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530464 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Kiran Venkatappa4b50f332019-03-20 18:14:17 +0530465 sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
Anish Nataraj38a29562017-08-18 19:41:17 +0530466 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530467 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530468 qdf_nbuf_put_tail(ppdu_nbuf,
469 sizeof(struct cdp_rx_indication_ppdu));
470 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530471 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800472 if (peer) {
Amir Patel468bded2019-03-21 11:42:31 +0530473 cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530474 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800475 dp_peer_unref_del_find_by_id(peer);
476 }
477 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
478 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
479 soc, ppdu_nbuf,
480 cdp_rx_ppdu->peer_id,
481 WDI_NO_VAL, pdev->pdev_id);
482 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530483 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
484 ppdu_nbuf, HTT_INVALID_PEER,
485 WDI_NO_VAL, pdev->pdev_id);
486 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530487 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530488 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530489 }
490}
491#else
492static inline void
493dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
494 struct hal_rx_ppdu_info *ppdu_info)
495{
496}
497#endif
498
499/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800500* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
501* filtering enabled
502* @soc: core txrx main context
503* @ppdu_info: Structure for rx ppdu info
504* @status_nbuf: Qdf nbuf abstraction for linux skb
505* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
506*
507* Return: none
508*/
509static inline void
510dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
511 struct hal_rx_ppdu_info *ppdu_info,
512 qdf_nbuf_t status_nbuf, uint32_t mac_id)
513{
514 struct dp_peer *peer;
515 struct dp_ast_entry *ast_entry;
516 uint32_t ast_index;
517
518 ast_index = ppdu_info->rx_status.ast_index;
519 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
520 ast_entry = soc->ast_table[ast_index];
521 if (ast_entry) {
522 peer = ast_entry->peer;
523 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
524 if (peer->peer_based_pktlog_filter) {
525 dp_wdi_event_handler(
526 WDI_EVENT_RX_DESC, soc,
527 status_nbuf,
528 peer->peer_ids[0],
529 WDI_NO_VAL, mac_id);
530 }
531 }
532 }
533 }
534}
535
536/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800537* dp_rx_mon_status_process_tlv() - Process status TLV in status
538* buffer on Rx status Queue posted by status SRNG processing.
539* @soc: core txrx main context
540* @mac_id: mac_id which is one of 3 mac_ids _ring
541*
542* Return: none
543*/
544static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700545dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
546 uint32_t quota)
547{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800548 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800549 struct hal_rx_ppdu_info *ppdu_info;
550 qdf_nbuf_t status_nbuf;
551 uint8_t *rx_tlv;
552 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700553 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530554 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen52ef33f2019-03-05 18:33:40 -0800555 QDF_STATUS enh_log_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800556 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700557 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800558 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen52ef33f2019-03-05 18:33:40 -0800559 bool nbuf_used;
560 uint32_t rx_enh_capture_mode;
561
Kai Chen6eca1a62017-01-12 10:17:53 -0800562
Kai Chen6eca1a62017-01-12 10:17:53 -0800563 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800564 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800565
566 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
567 return;
568
Kai Chen52ef33f2019-03-05 18:33:40 -0800569 rx_enh_capture_mode = pdev->rx_enh_capture_mode;
570
Kai Chen6eca1a62017-01-12 10:17:53 -0800571 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
572
573 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530574
Kai Chen6eca1a62017-01-12 10:17:53 -0800575 rx_tlv = qdf_nbuf_data(status_nbuf);
576 rx_tlv_start = rx_tlv;
Kai Chen52ef33f2019-03-05 18:33:40 -0800577 nbuf_used = false;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700578
Jeff Johnsona8edf332019-03-18 09:51:52 -0700579 if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
Kai Chen52ef33f2019-03-05 18:33:40 -0800580 pdev->mcopy_mode ||
581 (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
Keyur Parekhfad6d082017-05-07 08:54:47 -0700582 do {
583 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530584 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800585
586 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
587 rx_mon_stats);
588
Kai Chen52ef33f2019-03-05 18:33:40 -0800589 dp_rx_mon_enh_capture_process(pdev, tlv_status,
590 status_nbuf, ppdu_info,
591 &nbuf_used, rx_enh_capture_mode);
592
Keyur Parekhfad6d082017-05-07 08:54:47 -0700593 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800594
Keyur Parekhfad6d082017-05-07 08:54:47 -0700595 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
596 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800597
Kai Chen52ef33f2019-03-05 18:33:40 -0800598 } while ((tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE) ||
599 (tlv_status == HAL_TLV_STATUS_HEADER) ||
600 (tlv_status == HAL_TLV_STATUS_MPDU_END));
Keyur Parekhfad6d082017-05-07 08:54:47 -0700601 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800602 if (pdev->dp_peer_based_pktlog) {
603 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
604 status_nbuf, mac_id);
605 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800606 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
607 pktlog_mode = WDI_EVENT_RX_DESC;
608 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
609 pktlog_mode = WDI_EVENT_LITE_RX;
610
611 if (pktlog_mode != WDI_NO_VAL)
612 dp_wdi_event_handler(pktlog_mode, soc,
613 status_nbuf,
614 HTT_INVALID_PEER,
615 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800616 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530617
618 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700619 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
620 && pdev->monitor_vdev) {
621 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
622 pdev, ppdu_info, status_nbuf);
623 if (smart_mesh_status)
624 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530625 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530626 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530627 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530628 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530629 qdf_nbuf_free(status_nbuf);
Kai Chen52ef33f2019-03-05 18:33:40 -0800630 } else if (rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED) {
631 if (!nbuf_used)
632 qdf_nbuf_free(status_nbuf);
633
634 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE)
635 enh_log_status =
636 dp_rx_handle_enh_capture(soc,
637 pdev, ppdu_info);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530638 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700639 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530640 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800641
chenguo1b880462018-07-11 15:34:56 +0800642 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
643 dp_rx_mon_deliver_non_std(soc, mac_id);
644 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800645 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530646 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700647 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530648 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530649
nobelj1c31fee2018-03-21 11:47:05 -0700650 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
651 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700652 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800653 }
654 }
655 return;
656}
657
658/*
659 * dp_rx_mon_status_srng_process() - Process monitor status ring
660 * post the status ring buffer to Rx status Queue for later
661 * processing when status ring is filled with status TLV.
662 * Allocate a new buffer to status ring if the filled buffer
663 * is posted.
664 *
665 * @soc: core txrx main context
666 * @mac_id: mac_id which is one of 3 mac_ids
667 * @quota: No. of ring entry that can be serviced in one shot.
668
669 * Return: uint32_t: No. of ring entry that is processed.
670 */
671static inline uint32_t
672dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
673 uint32_t quota)
674{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800675 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800676 void *hal_soc;
677 void *mon_status_srng;
678 void *rxdma_mon_status_ring_entry;
679 QDF_STATUS status;
680 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800681 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800682
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800683 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800684
685 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700686 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
687
688 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530689 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700690 __func__, __LINE__, mon_status_srng);
691 return work_done;
692 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800693
694 hal_soc = soc->hal_soc;
695
696 qdf_assert(hal_soc);
697
698 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
699 goto done;
700
701 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
702 * BUFFER_ADDR_INFO STRUCT
703 */
704 while (qdf_likely((rxdma_mon_status_ring_entry =
705 hal_srng_src_peek(hal_soc, mon_status_srng))
706 && quota--)) {
707 uint32_t rx_buf_cookie;
708 qdf_nbuf_t status_nbuf;
709 struct dp_rx_desc *rx_desc;
710 uint8_t *status_buf;
711 qdf_dma_addr_t paddr;
712 uint64_t buf_addr;
713
714 buf_addr =
715 (HAL_RX_BUFFER_ADDR_31_0_GET(
716 rxdma_mon_status_ring_entry) |
717 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
718 rxdma_mon_status_ring_entry)) << 32));
719
720 if (qdf_likely(buf_addr)) {
721
722 rx_buf_cookie =
723 HAL_RX_BUF_COOKIE_GET(
724 rxdma_mon_status_ring_entry);
725 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
726 rx_buf_cookie);
727
728 qdf_assert(rx_desc);
729
730 status_nbuf = rx_desc->nbuf;
731
732 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
733 QDF_DMA_FROM_DEVICE);
734
735 status_buf = qdf_nbuf_data(status_nbuf);
736
737 status = hal_get_rx_status_done(status_buf);
738
739 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800740 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700741 hal_get_sw_hptp(hal_soc, mon_status_srng,
742 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800743 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800744 QDF_TRACE_LEVEL_ERROR,
745 "[%s][%d] status not done - hp:%u, tp:%u",
746 __func__, __LINE__, hp, tp);
747 /* WAR for missing status: Skip status entry */
748 hal_srng_src_get_next(hal_soc, mon_status_srng);
749 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800750 }
751 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
752
753 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
754 QDF_DMA_FROM_DEVICE);
755
756 /* Put the status_nbuf to queue */
757 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
758
759 } else {
760 union dp_rx_desc_list_elem_t *desc_list = NULL;
761 union dp_rx_desc_list_elem_t *tail = NULL;
762 struct rx_desc_pool *rx_desc_pool;
763 uint32_t num_alloc_desc;
764
765 rx_desc_pool = &soc->rx_desc_status[mac_id];
766
767 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
768 rx_desc_pool,
769 1,
770 &desc_list,
771 &tail);
phadimanebf4cde2019-01-28 17:50:37 +0530772 /*
773 * No free descriptors available
774 */
775 if (qdf_unlikely(num_alloc_desc == 0)) {
776 work_done++;
777 break;
778 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800779
780 rx_desc = &desc_list->rx_desc;
781 }
782
jinweic chenc3546322018-02-02 15:03:41 +0800783 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800784
jinweic chenc3546322018-02-02 15:03:41 +0800785 /*
786 * qdf_nbuf alloc or map failed,
787 * free the dp rx desc to free list,
788 * fill in NULL dma address at current HP entry,
789 * keep HP in mon_status_ring unchanged,
790 * wait next time dp_rx_mon_status_srng_process
791 * to fill in buffer at current HP.
792 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700793 if (qdf_unlikely(!status_nbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800794 union dp_rx_desc_list_elem_t *desc_list = NULL;
795 union dp_rx_desc_list_elem_t *tail = NULL;
796 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800797
jinweic chenc3546322018-02-02 15:03:41 +0800798 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800799
jinweic chenc3546322018-02-02 15:03:41 +0800800 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
801 "%s: fail to allocate or map qdf_nbuf",
802 __func__);
803 dp_rx_add_to_free_desc_list(&desc_list,
804 &tail, rx_desc);
805 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
806 &tail, mac_id, rx_desc_pool);
807
808 hal_rxdma_buff_addr_info_set(
809 rxdma_mon_status_ring_entry,
810 0, 0, HAL_RX_BUF_RBM_SW3_BM);
811 work_done++;
812 break;
813 }
814
Kai Chen6eca1a62017-01-12 10:17:53 -0800815 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
816
817 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700818 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800819
820 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
821 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
822
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800823 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800824 work_done++;
825 }
826done:
827
828 hal_srng_access_end(hal_soc, mon_status_srng);
829
830 return work_done;
831
832}
833/*
834 * dp_rx_mon_status_process() - Process monitor status ring and
835 * TLV in status ring.
836 *
837 * @soc: core txrx main context
838 * @mac_id: mac_id which is one of 3 mac_ids
839 * @quota: No. of ring entry that can be serviced in one shot.
840
841 * Return: uint32_t: No. of ring entry that is processed.
842 */
843static inline uint32_t
844dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
845 uint32_t work_done;
846
847 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700848 quota -= work_done;
849 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800850
851 return work_done;
852}
853/**
854 * dp_mon_process() - Main monitor mode processing roution.
855 * This call monitor status ring process then monitor
856 * destination ring process.
857 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
858 * @soc: core txrx main context
859 * @mac_id: mac_id which is one of 3 mac_ids
860 * @quota: No. of status ring entry that can be serviced in one shot.
861
862 * Return: uint32_t: No. of ring entry that is processed.
863 */
864uint32_t
865dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700866 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800867}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700868
Kai Chen6eca1a62017-01-12 10:17:53 -0800869/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700870 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800871 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800872 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800873 *
874 * This function will detach DP RX status ring from
875 * main device context. will free DP Rx resources for
876 * status ring
877 *
878 * Return: QDF_STATUS_SUCCESS: success
879 * QDF_STATUS_E_RESOURCES: Error return
880 */
881QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800882dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800883{
Kai Chen6eca1a62017-01-12 10:17:53 -0800884 struct dp_soc *soc = pdev->soc;
885 struct rx_desc_pool *rx_desc_pool;
886
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800887 rx_desc_pool = &soc->rx_desc_status[mac_id];
phadiman449a2682019-02-20 14:00:00 +0530888 if (rx_desc_pool->pool_size != 0) {
889 if (!dp_is_soc_reinit(soc))
890 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
891 else
892 dp_rx_desc_nbuf_pool_free(soc, rx_desc_pool);
893 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800894
895 return QDF_STATUS_SUCCESS;
896}
897
898/*
899 * dp_rx_buffers_replenish() - replenish monitor status ring with
900 * rx nbufs called during dp rx
901 * monitor status ring initialization
902 *
903 * @soc: core txrx main context
904 * @mac_id: mac_id which is one of 3 mac_ids
905 * @dp_rxdma_srng: dp monitor status circular ring
906 * @rx_desc_pool; Pointer to Rx descriptor pool
907 * @num_req_buffers: number of buffer to be replenished
908 * @desc_list: list of descs if called from dp rx monitor status
909 * process or NULL during dp rx initialization or
910 * out of buffer interrupt
911 * @tail: tail of descs list
912 * @owner: who owns the nbuf (host, NSS etc...)
913 * Return: return success or failure
914 */
915static inline
916QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
917 uint32_t mac_id,
918 struct dp_srng *dp_rxdma_srng,
919 struct rx_desc_pool *rx_desc_pool,
920 uint32_t num_req_buffers,
921 union dp_rx_desc_list_elem_t **desc_list,
922 union dp_rx_desc_list_elem_t **tail,
923 uint8_t owner)
924{
925 uint32_t num_alloc_desc;
926 uint16_t num_desc_to_free = 0;
927 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800928 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800929 int sync_hw_ptr = 1;
930 qdf_dma_addr_t paddr;
931 qdf_nbuf_t rx_netbuf;
932 void *rxdma_ring_entry;
933 union dp_rx_desc_list_elem_t *next;
934 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800935 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800936
937 rxdma_srng = dp_rxdma_srng->hal_srng;
938
939 qdf_assert(rxdma_srng);
940
Houston Hoffmanae850c62017-08-11 16:47:50 -0700941 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530942 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800943 __func__, __LINE__, num_req_buffers);
944
945 /*
946 * if desc_list is NULL, allocate the descs from freelist
947 */
948 if (!(*desc_list)) {
949
950 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
951 rx_desc_pool,
952 num_req_buffers,
953 desc_list,
954 tail);
955
956 if (!num_alloc_desc) {
957 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530958 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800959 __func__, __LINE__);
960 return QDF_STATUS_E_NOMEM;
961 }
962
Houston Hoffmanae850c62017-08-11 16:47:50 -0700963 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530964 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800965 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700966
Kai Chen6eca1a62017-01-12 10:17:53 -0800967 num_req_buffers = num_alloc_desc;
968 }
969
970 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
971 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
972 rxdma_srng, sync_hw_ptr);
973
Houston Hoffmanae850c62017-08-11 16:47:50 -0700974 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530975 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800976 __func__, __LINE__, num_entries_avail);
977
978 if (num_entries_avail < num_req_buffers) {
979 num_desc_to_free = num_req_buffers - num_entries_avail;
980 num_req_buffers = num_entries_avail;
981 }
982
jinweic chenc3546322018-02-02 15:03:41 +0800983 while (count < num_req_buffers) {
984 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800985
jinweic chenc3546322018-02-02 15:03:41 +0800986 /*
987 * qdf_nbuf alloc or map failed,
988 * keep HP in mon_status_ring unchanged,
989 * wait dp_rx_mon_status_srng_process
990 * to fill in buffer at current HP.
991 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700992 if (qdf_unlikely(!rx_netbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800993 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
994 "%s: qdf_nbuf allocate or map fail, count %d",
995 __func__, count);
996 break;
997 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800998
999 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
1000
1001 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -07001002 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
1003 rxdma_srng);
1004
Jeff Johnsona8edf332019-03-18 09:51:52 -07001005 if (qdf_unlikely(!rxdma_ring_entry)) {
sumedh baikadyeca2de62018-04-11 14:20:38 -07001006 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +05301007 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -07001008 __func__, __LINE__, count);
1009 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
Ankit Kumar0ae4abc2019-05-02 15:08:42 +05301010 QDF_DMA_FROM_DEVICE);
sumedh baikadyeca2de62018-04-11 14:20:38 -07001011 qdf_nbuf_free(rx_netbuf);
1012 break;
1013 }
Kai Chen6eca1a62017-01-12 10:17:53 -08001014
1015 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -07001016 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +08001017 count++;
jinweic chenc3546322018-02-02 15:03:41 +08001018
Kai Chen6eca1a62017-01-12 10:17:53 -08001019 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
1020 (*desc_list)->rx_desc.cookie, owner);
1021
Karunakar Dasineni40555682017-03-26 22:44:39 -07001022 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -07001023 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +05301024 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -08001025 __func__, __LINE__, &(*desc_list)->rx_desc,
1026 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +08001027 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -08001028
1029 *desc_list = next;
1030 }
1031
1032 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
1033
Houston Hoffmanae850c62017-08-11 16:47:50 -07001034 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301035 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -08001036
Houston Hoffmanae850c62017-08-11 16:47:50 -07001037 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +05301038 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -08001039
Kai Chen6eca1a62017-01-12 10:17:53 -08001040 /*
1041 * add any available free desc back to the free list
1042 */
1043 if (*desc_list) {
1044 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
1045 mac_id, rx_desc_pool);
1046 }
1047
1048 return QDF_STATUS_SUCCESS;
1049}
1050/**
1051 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
1052 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001053 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -08001054 * This function will attach a DP RX monitor status ring into pDEV
1055 * and replenish monitor status ring with buffer.
1056 *
1057 * Return: QDF_STATUS_SUCCESS: success
1058 * QDF_STATUS_E_RESOURCES: Error return
1059 */
1060QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001061dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001062 struct dp_soc *soc = pdev->soc;
1063 union dp_rx_desc_list_elem_t *desc_list = NULL;
1064 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001065 struct dp_srng *mon_status_ring;
1066 uint32_t num_entries;
Kai Chen52ef33f2019-03-05 18:33:40 -08001067 uint32_t i;
Kai Chen6eca1a62017-01-12 10:17:53 -08001068 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001069 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001070 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001071
Mohit Khanna70514992018-11-12 18:39:03 -08001072 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001073
Mohit Khanna70514992018-11-12 18:39:03 -08001074 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001075
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001076 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001077
Mohit Khanna70514992018-11-12 18:39:03 -08001078 dp_info("Mon RX Status Pool[%d] entries=%d",
1079 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001080
Mohit Khanna70514992018-11-12 18:39:03 -08001081 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1082 rx_desc_pool);
1083 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001084 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001085
Mohit Khanna70514992018-11-12 18:39:03 -08001086 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001087
Mohit Khanna70514992018-11-12 18:39:03 -08001088 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1089 mon_status_ring,
1090 rx_desc_pool,
1091 num_entries,
1092 &desc_list, &tail,
1093 HAL_RX_BUF_RBM_SW3_BM);
1094
1095 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001096 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001097
1098 qdf_nbuf_queue_init(&pdev->rx_status_q);
1099
1100 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001101
Karunakar Dasineni40555682017-03-26 22:44:39 -07001102 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001103 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001104
Kai Chen783e0382018-01-25 16:29:08 -08001105 qdf_mem_zero(&pdev->rx_mon_stats,
1106 sizeof(pdev->rx_mon_stats));
1107
1108 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1109 &pdev->rx_mon_stats);
1110
Kai Chen52ef33f2019-03-05 18:33:40 -08001111 for (i = 0; i < MAX_MU_USERS; i++) {
1112 qdf_nbuf_queue_init(&pdev->mpdu_q[i]);
1113 pdev->is_mpdu_hdr[i] = true;
1114 }
1115 qdf_mem_zero(pdev->msdu_list, sizeof(pdev->msdu_list[MAX_MU_USERS]));
1116
1117 pdev->rx_enh_capture_mode = CDP_RX_ENH_CAPTURE_DISABLED;
1118
Kai Chen6eca1a62017-01-12 10:17:53 -08001119 return QDF_STATUS_SUCCESS;
1120}