blob: 485a00bf40aa8930513ccccb5724d08db42d830b [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 Chen6eca1a62017-01-12 10:17:53 -080035/**
Anish Nataraj38a29562017-08-18 19:41:17 +053036* dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
Soumya Bhat560f90c2018-03-30 13:53:26 +053037* @pdev: pdev ctx
Anish Nataraj38a29562017-08-18 19:41:17 +053038* @ppdu_info: ppdu info structure from ppdu ring
39* @ppdu_nbuf: qdf nbuf abstraction for linux skb
40*
41* Return: none
42*/
43#ifdef FEATURE_PERPKT_INFO
44static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +053045dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +053046 struct hal_rx_ppdu_info *ppdu_info,
47 qdf_nbuf_t ppdu_nbuf)
48{
49 struct dp_peer *peer;
Soumya Bhat560f90c2018-03-30 13:53:26 +053050 struct dp_soc *soc = pdev->soc;
Anish Nataraj38a29562017-08-18 19:41:17 +053051 struct dp_ast_entry *ast_entry;
52 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
53 uint32_t ast_index;
54
55 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
56
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +053057 cdp_rx_ppdu->first_data_seq_ctrl =
58 ppdu_info->rx_status.first_data_seq_ctrl;
Anish Natarajeb30aa72018-09-20 16:34:01 +053059 cdp_rx_ppdu->frame_ctrl =
60 ppdu_info->rx_status.frame_control;
Anish Nataraj38a29562017-08-18 19:41:17 +053061 cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
nobelj9ab76e22018-02-13 18:10:54 -080062 cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
Anish Nataraj38a29562017-08-18 19:41:17 +053063 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
64 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053065 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
66 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
67 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +053068 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
69 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Keyur Parekh49cdc742018-05-09 10:59:03 -070070 if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
71 (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
72 cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
73 else
74 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj50347012018-03-06 21:12:45 +053075 cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
Anish Nataraj38a29562017-08-18 19:41:17 +053076 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +053077 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Pamidipati, Vijayba4b57f2019-02-13 16:47:23 +053078 cdp_rx_ppdu->u.ltf_size = (ppdu_info->rx_status.he_data5 >>
79 QDF_MON_STATUS_HE_LTF_SIZE_SHIFT) & 0x3;
80 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Anish Nataraj38a29562017-08-18 19:41:17 +053081 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +053082 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
83 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
nobeljd8039592018-03-13 16:59:42 -070084 cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053085 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
86 cdp_rx_ppdu->udp_msdu_count +
87 cdp_rx_ppdu->other_msdu_count);
Amir Patel468bded2019-03-21 11:42:31 +053088 cdp_rx_ppdu->num_bytes = ppdu_info->rx_status.ppdu_len;
89 if (CDP_FC_IS_RETRY_SET(cdp_rx_ppdu->frame_ctrl))
90 cdp_rx_ppdu->retries += ppdu_info->com_info.mpdu_cnt_fcs_ok;
Pranita Solankeed0aba62018-01-12 19:14:31 +053091
92 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
93 cdp_rx_ppdu->is_ampdu = 1;
94 else
95 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053096
97 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +053098 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Soumya Bhat560f90c2018-03-30 13:53:26 +053099
100 ast_index = ppdu_info->rx_status.ast_index;
Tallapragada Kalyana7023622018-12-03 19:29:52 +0530101 if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530102 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
103 return;
104 }
105
106 ast_entry = soc->ast_table[ast_index];
107 if (!ast_entry) {
108 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
109 return;
110 }
111 peer = ast_entry->peer;
112 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
113 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
114 return;
115 }
116
117 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800118 peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
Soumya Bhat560f90c2018-03-30 13:53:26 +0530119 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
120 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Keyur Parekh44d8f8f2019-03-12 12:39:41 -0700121 cdp_rx_ppdu->u.ltf_size = ppdu_info->rx_status.ltf_size;
Anish Nataraj38a29562017-08-18 19:41:17 +0530122}
123#else
124static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530125dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530126 struct hal_rx_ppdu_info *ppdu_info,
127 qdf_nbuf_t ppdu_nbuf)
128{
129}
130#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530131/**
132 * dp_rx_stats_update() - Update per-peer statistics
133 * @soc: Datapath SOC handle
134 * @peer: Datapath peer handle
135 * @ppdu: PPDU Descriptor
136 *
137 * Return: None
138 */
139#ifdef FEATURE_PERPKT_INFO
ydb247452018-08-08 00:23:16 +0530140static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
141 struct cdp_rx_indication_ppdu *ppdu)
142{
143 uint32_t ratekbps = 0;
144 uint32_t ppdu_rx_rate = 0;
145 uint32_t nss = 0;
Amir Patel78824b12019-02-23 10:54:32 +0530146 uint32_t rix;
ydb247452018-08-08 00:23:16 +0530147
148 if (!peer || !ppdu)
149 return;
150
151 if (ppdu->u.nss == 0)
152 nss = 0;
153 else
154 nss = ppdu->u.nss - 1;
155
Anish Nataraj376d9b12018-08-13 14:12:01 +0530156 ratekbps = dp_getrateindex(ppdu->u.gi,
157 ppdu->u.mcs,
ydb247452018-08-08 00:23:16 +0530158 nss,
159 ppdu->u.preamble,
Amir Patel78824b12019-02-23 10:54:32 +0530160 ppdu->u.bw,
161 &rix);
ydb247452018-08-08 00:23:16 +0530162
163 if (!ratekbps)
164 return;
165
Amir Patel468bded2019-03-21 11:42:31 +0530166 ppdu->rix = rix;
ydb247452018-08-08 00:23:16 +0530167 DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
168 dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
169 ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
170 DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
171
172 if (peer->vdev)
173 peer->vdev->stats.rx.last_rx_rate = ratekbps;
174}
175
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530176static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
177 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530178{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530179 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530180 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530181 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530182 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530183
184 mcs = ppdu->u.mcs;
185 preamble = ppdu->u.preamble;
186 num_msdu = ppdu->num_msdu;
187
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530188 if (pdev)
189 soc = pdev->soc;
190 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530191 return;
192
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530193 if (!peer) {
194 is_invalid_peer = true;
195 peer = pdev->invalid_peer;
196 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530197
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530198 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530199 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530200
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530201 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530202
203 if ((preamble == DOT11_A) || (preamble == DOT11_B))
204 ppdu->u.nss = 1;
205
206 if (ppdu->u.nss)
207 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
208
Pranita Solankea12b4b32017-11-20 23:04:14 +0530209 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530210 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530211 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530212 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
213 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
214 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530215 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530216 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530217 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
218 DP_STATS_INCC(peer,
219 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530220 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530221 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530222 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530223 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
224 DP_STATS_INCC(peer,
225 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530226 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530227 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530228 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530229 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
230 DP_STATS_INCC(peer,
231 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530232 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530233 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530234 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530235 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
236 DP_STATS_INCC(peer,
237 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
238 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
239 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530240 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530241 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
242 DP_STATS_INCC(peer,
243 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
244 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530245 /*
246 * If invalid TID, it could be a non-qos frame, hence do not update
247 * any AC counters
248 */
249 ac = TID_TO_WME_AC(ppdu->tid);
250 if (ppdu->tid != HAL_TID_INVALID)
251 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530252 dp_peer_stats_notify(peer);
253 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530254
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530255 if (is_invalid_peer)
256 return;
257
ydb247452018-08-08 00:23:16 +0530258 dp_rx_rate_stats_update(peer, ppdu);
259
Amir Patel756d05e2018-10-10 12:35:30 +0530260#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
261 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
262 &peer->stats, ppdu->peer_id,
263 UPDATE_PEER_STATS, pdev->pdev_id);
264#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530265}
266#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530267
268/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530269 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530270 * @soc: core txrx main context
271 * @pdev: pdev strcuture
272 * @ppdu_info: structure for rx ppdu ring
273 *
274 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
275 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530276 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530277#ifdef FEATURE_PERPKT_INFO
278static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530279dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530280 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
281{
282 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530283 struct ieee80211_frame *wh;
284 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530285
Jeff Johnsona8edf332019-03-18 09:51:52 -0700286 if (!ppdu_info->msdu_info.first_msdu_payload)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530287 return QDF_STATUS_SUCCESS;
288
Soumya Bhat2f54de22018-02-21 09:54:28 +0530289 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530290 return QDF_STATUS_SUCCESS;
291
Soumya Bhat2f54de22018-02-21 09:54:28 +0530292 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530293
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530294 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
295 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530296 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530297 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530298 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530299
300 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
301 return QDF_STATUS_SUCCESS;
302
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530303 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
304 IEEE80211_FC0_TYPE_MGT) ||
305 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
306 IEEE80211_FC0_TYPE_CTL)) {
307 return QDF_STATUS_SUCCESS;
308 }
309
310 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
311 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530312 /* only retain RX MSDU payload in the skb */
313 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
314 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530315 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
316 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
317 return QDF_STATUS_E_ALREADY;
318}
319#else
320static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530321dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530322 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
323{
324 return QDF_STATUS_SUCCESS;
325}
326#endif
327
sumedh baikady59a2d332018-05-22 01:50:38 -0700328/**
329 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
330 * @soc: Datapath SOC handle
331 * @pdev: Datapath PDEV handle
332 * @ppdu_info: Structure for rx ppdu info
333 * @nbuf: Qdf nbuf abstraction for linux skb
334 *
335 * Return: 0 on success, 1 on failure
336 */
337static inline int
338dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
339 struct hal_rx_ppdu_info *ppdu_info,
340 qdf_nbuf_t nbuf)
341{
342 uint8_t size = 0;
343
344 if (!pdev->monitor_vdev) {
345 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
346 "[%s]:[%d] Monitor vdev is NULL !!",
347 __func__, __LINE__);
348 return 1;
349 }
Jeff Johnsona8edf332019-03-18 09:51:52 -0700350 if (!ppdu_info->msdu_info.first_msdu_payload) {
sumedh baikady59a2d332018-05-22 01:50:38 -0700351 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
352 "[%s]:[%d] First msdu payload not present",
353 __func__, __LINE__);
354 return 1;
355 }
356
sumedh baikadyda159202018-11-01 17:31:23 -0700357 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700358 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700359 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700360 ppdu_info->msdu_info.first_msdu_payload = NULL;
361
362 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
363 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
364 "[%s]:[%d] No header present",
365 __func__, __LINE__);
366 return 1;
367 }
368
sumedh baikadyda159202018-11-01 17:31:23 -0700369 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700370 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
371 ppdu_info->msdu_info.payload_len);
372 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
373 nbuf, sizeof(struct rx_pkt_tlvs));
374 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
375 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700376 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700377 return 0;
378}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530379
380/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530381* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
382* @soc: core txrx main context
383* @pdev: pdev strcuture
384* @ppdu_info: structure for rx ppdu ring
385*
386* Return: none
387*/
388#ifdef FEATURE_PERPKT_INFO
389static inline void
390dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
391 struct hal_rx_ppdu_info *ppdu_info)
392{
393 qdf_nbuf_t ppdu_nbuf;
394 struct dp_peer *peer;
395 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
396
Anish Nataraj28490c42018-01-19 19:34:54 +0530397 /*
398 * Do not allocate if fcs error,
399 * ast idx invalid / fctl invalid
400 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530401 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
402 return;
403
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530404 if (ppdu_info->nac_info.fc_valid &&
405 ppdu_info->nac_info.to_ds_flag &&
406 ppdu_info->nac_info.mac_addr2_valid) {
407 struct dp_neighbour_peer *peer = NULL;
408 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
409
410 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
411 if (pdev->neighbour_peers_added) {
412 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
413 neighbour_peer_list_elem) {
414 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
415 &ppdu_info->nac_info.mac_addr2,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800416 QDF_MAC_ADDR_SIZE)) {
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530417 peer->rssi = rssi;
418 break;
419 }
420 }
421 }
422 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
423 }
424
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530425 /* need not generate wdi event when mcopy and
426 * enhanced stats are not enabled
427 */
428 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
429 return;
430
Soumya Bhat560f90c2018-03-30 13:53:26 +0530431 if (!pdev->mcopy_mode) {
432 if (!ppdu_info->rx_status.frame_control_info_valid)
433 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530434
Soumya Bhat560f90c2018-03-30 13:53:26 +0530435 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
436 return;
437 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530438 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Kiran Venkatappa4b50f332019-03-20 18:14:17 +0530439 sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
Anish Nataraj38a29562017-08-18 19:41:17 +0530440 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530441 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530442 qdf_nbuf_put_tail(ppdu_nbuf,
443 sizeof(struct cdp_rx_indication_ppdu));
444 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530445 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800446 if (peer) {
Amir Patel468bded2019-03-21 11:42:31 +0530447 cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530448 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800449 dp_peer_unref_del_find_by_id(peer);
450 }
451 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
452 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
453 soc, ppdu_nbuf,
454 cdp_rx_ppdu->peer_id,
455 WDI_NO_VAL, pdev->pdev_id);
456 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530457 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
458 ppdu_nbuf, HTT_INVALID_PEER,
459 WDI_NO_VAL, pdev->pdev_id);
460 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530461 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530462 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530463 }
464}
465#else
466static inline void
467dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
468 struct hal_rx_ppdu_info *ppdu_info)
469{
470}
471#endif
472
473/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800474* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
475* filtering enabled
476* @soc: core txrx main context
477* @ppdu_info: Structure for rx ppdu info
478* @status_nbuf: Qdf nbuf abstraction for linux skb
479* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
480*
481* Return: none
482*/
483static inline void
484dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
485 struct hal_rx_ppdu_info *ppdu_info,
486 qdf_nbuf_t status_nbuf, uint32_t mac_id)
487{
488 struct dp_peer *peer;
489 struct dp_ast_entry *ast_entry;
490 uint32_t ast_index;
491
492 ast_index = ppdu_info->rx_status.ast_index;
493 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
494 ast_entry = soc->ast_table[ast_index];
495 if (ast_entry) {
496 peer = ast_entry->peer;
497 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
498 if (peer->peer_based_pktlog_filter) {
499 dp_wdi_event_handler(
500 WDI_EVENT_RX_DESC, soc,
501 status_nbuf,
502 peer->peer_ids[0],
503 WDI_NO_VAL, mac_id);
504 }
505 }
506 }
507 }
508}
509
510/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800511* dp_rx_mon_status_process_tlv() - Process status TLV in status
512* buffer on Rx status Queue posted by status SRNG processing.
513* @soc: core txrx main context
514* @mac_id: mac_id which is one of 3 mac_ids _ring
515*
516* Return: none
517*/
518static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700519dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
520 uint32_t quota)
521{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800522 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800523 struct hal_rx_ppdu_info *ppdu_info;
524 qdf_nbuf_t status_nbuf;
525 uint8_t *rx_tlv;
526 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700527 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530528 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800529 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700530 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800531 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen6eca1a62017-01-12 10:17:53 -0800532
Kai Chen6eca1a62017-01-12 10:17:53 -0800533 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800534 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800535
536 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
537 return;
538
539 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
540
541 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530542
Kai Chen6eca1a62017-01-12 10:17:53 -0800543 rx_tlv = qdf_nbuf_data(status_nbuf);
544 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700545
Jeff Johnsona8edf332019-03-18 09:51:52 -0700546 if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
Soumya Bhat2f54de22018-02-21 09:54:28 +0530547 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800548
Keyur Parekhfad6d082017-05-07 08:54:47 -0700549 do {
550 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530551 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800552
553 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
554 rx_mon_stats);
555
Keyur Parekhfad6d082017-05-07 08:54:47 -0700556 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800557
Keyur Parekhfad6d082017-05-07 08:54:47 -0700558 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
559 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800560
Keyur Parekhfad6d082017-05-07 08:54:47 -0700561 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
562 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800563 if (pdev->dp_peer_based_pktlog) {
564 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
565 status_nbuf, mac_id);
566 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800567 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
568 pktlog_mode = WDI_EVENT_RX_DESC;
569 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
570 pktlog_mode = WDI_EVENT_LITE_RX;
571
572 if (pktlog_mode != WDI_NO_VAL)
573 dp_wdi_event_handler(pktlog_mode, soc,
574 status_nbuf,
575 HTT_INVALID_PEER,
576 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800577 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530578
579 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700580 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
581 && pdev->monitor_vdev) {
582 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
583 pdev, ppdu_info, status_nbuf);
584 if (smart_mesh_status)
585 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530586 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530587 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530588 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530589 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530590 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530591 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700592 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530593 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800594
chenguo1b880462018-07-11 15:34:56 +0800595 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
596 dp_rx_mon_deliver_non_std(soc, mac_id);
597 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800598 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530599 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700600 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530601 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530602
nobelj1c31fee2018-03-21 11:47:05 -0700603 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
604 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700605 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800606 }
607 }
608 return;
609}
610
611/*
612 * dp_rx_mon_status_srng_process() - Process monitor status ring
613 * post the status ring buffer to Rx status Queue for later
614 * processing when status ring is filled with status TLV.
615 * Allocate a new buffer to status ring if the filled buffer
616 * is posted.
617 *
618 * @soc: core txrx main context
619 * @mac_id: mac_id which is one of 3 mac_ids
620 * @quota: No. of ring entry that can be serviced in one shot.
621
622 * Return: uint32_t: No. of ring entry that is processed.
623 */
624static inline uint32_t
625dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
626 uint32_t quota)
627{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800628 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800629 void *hal_soc;
630 void *mon_status_srng;
631 void *rxdma_mon_status_ring_entry;
632 QDF_STATUS status;
633 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800634 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800635
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800636 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800637
638 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700639 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
640
641 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530642 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700643 __func__, __LINE__, mon_status_srng);
644 return work_done;
645 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800646
647 hal_soc = soc->hal_soc;
648
649 qdf_assert(hal_soc);
650
651 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
652 goto done;
653
654 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
655 * BUFFER_ADDR_INFO STRUCT
656 */
657 while (qdf_likely((rxdma_mon_status_ring_entry =
658 hal_srng_src_peek(hal_soc, mon_status_srng))
659 && quota--)) {
660 uint32_t rx_buf_cookie;
661 qdf_nbuf_t status_nbuf;
662 struct dp_rx_desc *rx_desc;
663 uint8_t *status_buf;
664 qdf_dma_addr_t paddr;
665 uint64_t buf_addr;
666
667 buf_addr =
668 (HAL_RX_BUFFER_ADDR_31_0_GET(
669 rxdma_mon_status_ring_entry) |
670 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
671 rxdma_mon_status_ring_entry)) << 32));
672
673 if (qdf_likely(buf_addr)) {
674
675 rx_buf_cookie =
676 HAL_RX_BUF_COOKIE_GET(
677 rxdma_mon_status_ring_entry);
678 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
679 rx_buf_cookie);
680
681 qdf_assert(rx_desc);
682
683 status_nbuf = rx_desc->nbuf;
684
685 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
686 QDF_DMA_FROM_DEVICE);
687
688 status_buf = qdf_nbuf_data(status_nbuf);
689
690 status = hal_get_rx_status_done(status_buf);
691
692 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800693 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700694 hal_get_sw_hptp(hal_soc, mon_status_srng,
695 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800696 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800697 QDF_TRACE_LEVEL_ERROR,
698 "[%s][%d] status not done - hp:%u, tp:%u",
699 __func__, __LINE__, hp, tp);
700 /* WAR for missing status: Skip status entry */
701 hal_srng_src_get_next(hal_soc, mon_status_srng);
702 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800703 }
704 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
705
706 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
707 QDF_DMA_FROM_DEVICE);
708
709 /* Put the status_nbuf to queue */
710 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
711
712 } else {
713 union dp_rx_desc_list_elem_t *desc_list = NULL;
714 union dp_rx_desc_list_elem_t *tail = NULL;
715 struct rx_desc_pool *rx_desc_pool;
716 uint32_t num_alloc_desc;
717
718 rx_desc_pool = &soc->rx_desc_status[mac_id];
719
720 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
721 rx_desc_pool,
722 1,
723 &desc_list,
724 &tail);
phadimanebf4cde2019-01-28 17:50:37 +0530725 /*
726 * No free descriptors available
727 */
728 if (qdf_unlikely(num_alloc_desc == 0)) {
729 work_done++;
730 break;
731 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800732
733 rx_desc = &desc_list->rx_desc;
734 }
735
jinweic chenc3546322018-02-02 15:03:41 +0800736 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800737
jinweic chenc3546322018-02-02 15:03:41 +0800738 /*
739 * qdf_nbuf alloc or map failed,
740 * free the dp rx desc to free list,
741 * fill in NULL dma address at current HP entry,
742 * keep HP in mon_status_ring unchanged,
743 * wait next time dp_rx_mon_status_srng_process
744 * to fill in buffer at current HP.
745 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700746 if (qdf_unlikely(!status_nbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800747 union dp_rx_desc_list_elem_t *desc_list = NULL;
748 union dp_rx_desc_list_elem_t *tail = NULL;
749 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800750
jinweic chenc3546322018-02-02 15:03:41 +0800751 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800752
jinweic chenc3546322018-02-02 15:03:41 +0800753 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
754 "%s: fail to allocate or map qdf_nbuf",
755 __func__);
756 dp_rx_add_to_free_desc_list(&desc_list,
757 &tail, rx_desc);
758 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
759 &tail, mac_id, rx_desc_pool);
760
761 hal_rxdma_buff_addr_info_set(
762 rxdma_mon_status_ring_entry,
763 0, 0, HAL_RX_BUF_RBM_SW3_BM);
764 work_done++;
765 break;
766 }
767
Kai Chen6eca1a62017-01-12 10:17:53 -0800768 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
769
770 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700771 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800772
773 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
774 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
775
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800776 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800777 work_done++;
778 }
779done:
780
781 hal_srng_access_end(hal_soc, mon_status_srng);
782
783 return work_done;
784
785}
786/*
787 * dp_rx_mon_status_process() - Process monitor status ring and
788 * TLV in status ring.
789 *
790 * @soc: core txrx main context
791 * @mac_id: mac_id which is one of 3 mac_ids
792 * @quota: No. of ring entry that can be serviced in one shot.
793
794 * Return: uint32_t: No. of ring entry that is processed.
795 */
796static inline uint32_t
797dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
798 uint32_t work_done;
799
800 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700801 quota -= work_done;
802 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800803
804 return work_done;
805}
806/**
807 * dp_mon_process() - Main monitor mode processing roution.
808 * This call monitor status ring process then monitor
809 * destination ring process.
810 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
811 * @soc: core txrx main context
812 * @mac_id: mac_id which is one of 3 mac_ids
813 * @quota: No. of status ring entry that can be serviced in one shot.
814
815 * Return: uint32_t: No. of ring entry that is processed.
816 */
817uint32_t
818dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700819 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800820}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700821
Kai Chen6eca1a62017-01-12 10:17:53 -0800822/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700823 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800824 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800825 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800826 *
827 * This function will detach DP RX status ring from
828 * main device context. will free DP Rx resources for
829 * status ring
830 *
831 * Return: QDF_STATUS_SUCCESS: success
832 * QDF_STATUS_E_RESOURCES: Error return
833 */
834QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800835dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800836{
Kai Chen6eca1a62017-01-12 10:17:53 -0800837 struct dp_soc *soc = pdev->soc;
838 struct rx_desc_pool *rx_desc_pool;
839
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800840 rx_desc_pool = &soc->rx_desc_status[mac_id];
phadiman449a2682019-02-20 14:00:00 +0530841 if (rx_desc_pool->pool_size != 0) {
842 if (!dp_is_soc_reinit(soc))
843 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
844 else
845 dp_rx_desc_nbuf_pool_free(soc, rx_desc_pool);
846 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800847
848 return QDF_STATUS_SUCCESS;
849}
850
851/*
852 * dp_rx_buffers_replenish() - replenish monitor status ring with
853 * rx nbufs called during dp rx
854 * monitor status ring initialization
855 *
856 * @soc: core txrx main context
857 * @mac_id: mac_id which is one of 3 mac_ids
858 * @dp_rxdma_srng: dp monitor status circular ring
859 * @rx_desc_pool; Pointer to Rx descriptor pool
860 * @num_req_buffers: number of buffer to be replenished
861 * @desc_list: list of descs if called from dp rx monitor status
862 * process or NULL during dp rx initialization or
863 * out of buffer interrupt
864 * @tail: tail of descs list
865 * @owner: who owns the nbuf (host, NSS etc...)
866 * Return: return success or failure
867 */
868static inline
869QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
870 uint32_t mac_id,
871 struct dp_srng *dp_rxdma_srng,
872 struct rx_desc_pool *rx_desc_pool,
873 uint32_t num_req_buffers,
874 union dp_rx_desc_list_elem_t **desc_list,
875 union dp_rx_desc_list_elem_t **tail,
876 uint8_t owner)
877{
878 uint32_t num_alloc_desc;
879 uint16_t num_desc_to_free = 0;
880 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800881 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800882 int sync_hw_ptr = 1;
883 qdf_dma_addr_t paddr;
884 qdf_nbuf_t rx_netbuf;
885 void *rxdma_ring_entry;
886 union dp_rx_desc_list_elem_t *next;
887 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800888 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800889
890 rxdma_srng = dp_rxdma_srng->hal_srng;
891
892 qdf_assert(rxdma_srng);
893
Houston Hoffmanae850c62017-08-11 16:47:50 -0700894 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530895 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800896 __func__, __LINE__, num_req_buffers);
897
898 /*
899 * if desc_list is NULL, allocate the descs from freelist
900 */
901 if (!(*desc_list)) {
902
903 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
904 rx_desc_pool,
905 num_req_buffers,
906 desc_list,
907 tail);
908
909 if (!num_alloc_desc) {
910 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530911 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800912 __func__, __LINE__);
913 return QDF_STATUS_E_NOMEM;
914 }
915
Houston Hoffmanae850c62017-08-11 16:47:50 -0700916 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530917 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800918 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700919
Kai Chen6eca1a62017-01-12 10:17:53 -0800920 num_req_buffers = num_alloc_desc;
921 }
922
923 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
924 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
925 rxdma_srng, sync_hw_ptr);
926
Houston Hoffmanae850c62017-08-11 16:47:50 -0700927 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530928 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800929 __func__, __LINE__, num_entries_avail);
930
931 if (num_entries_avail < num_req_buffers) {
932 num_desc_to_free = num_req_buffers - num_entries_avail;
933 num_req_buffers = num_entries_avail;
934 }
935
jinweic chenc3546322018-02-02 15:03:41 +0800936 while (count < num_req_buffers) {
937 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800938
jinweic chenc3546322018-02-02 15:03:41 +0800939 /*
940 * qdf_nbuf alloc or map failed,
941 * keep HP in mon_status_ring unchanged,
942 * wait dp_rx_mon_status_srng_process
943 * to fill in buffer at current HP.
944 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700945 if (qdf_unlikely(!rx_netbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800946 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
947 "%s: qdf_nbuf allocate or map fail, count %d",
948 __func__, count);
949 break;
950 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800951
952 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
953
954 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700955 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
956 rxdma_srng);
957
Jeff Johnsona8edf332019-03-18 09:51:52 -0700958 if (qdf_unlikely(!rxdma_ring_entry)) {
sumedh baikadyeca2de62018-04-11 14:20:38 -0700959 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530960 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700961 __func__, __LINE__, count);
962 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
963 QDF_DMA_BIDIRECTIONAL);
964 qdf_nbuf_free(rx_netbuf);
965 break;
966 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800967
968 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700969 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800970 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800971
Kai Chen6eca1a62017-01-12 10:17:53 -0800972 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
973 (*desc_list)->rx_desc.cookie, owner);
974
Karunakar Dasineni40555682017-03-26 22:44:39 -0700975 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700976 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530977 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800978 __func__, __LINE__, &(*desc_list)->rx_desc,
979 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800980 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800981
982 *desc_list = next;
983 }
984
985 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
986
Houston Hoffmanae850c62017-08-11 16:47:50 -0700987 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530988 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800989
Houston Hoffmanae850c62017-08-11 16:47:50 -0700990 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530991 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800992
Kai Chen6eca1a62017-01-12 10:17:53 -0800993 /*
994 * add any available free desc back to the free list
995 */
996 if (*desc_list) {
997 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
998 mac_id, rx_desc_pool);
999 }
1000
1001 return QDF_STATUS_SUCCESS;
1002}
1003/**
1004 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
1005 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001006 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -08001007 * This function will attach a DP RX monitor status ring into pDEV
1008 * and replenish monitor status ring with buffer.
1009 *
1010 * Return: QDF_STATUS_SUCCESS: success
1011 * QDF_STATUS_E_RESOURCES: Error return
1012 */
1013QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001014dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001015 struct dp_soc *soc = pdev->soc;
1016 union dp_rx_desc_list_elem_t *desc_list = NULL;
1017 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001018 struct dp_srng *mon_status_ring;
1019 uint32_t num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001020 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001021 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001022 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001023
Mohit Khanna70514992018-11-12 18:39:03 -08001024 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001025
Mohit Khanna70514992018-11-12 18:39:03 -08001026 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001027
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001028 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001029
Mohit Khanna70514992018-11-12 18:39:03 -08001030 dp_info("Mon RX Status Pool[%d] entries=%d",
1031 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001032
Mohit Khanna70514992018-11-12 18:39:03 -08001033 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1034 rx_desc_pool);
1035 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001036 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001037
Mohit Khanna70514992018-11-12 18:39:03 -08001038 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001039
Mohit Khanna70514992018-11-12 18:39:03 -08001040 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1041 mon_status_ring,
1042 rx_desc_pool,
1043 num_entries,
1044 &desc_list, &tail,
1045 HAL_RX_BUF_RBM_SW3_BM);
1046
1047 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001048 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001049
1050 qdf_nbuf_queue_init(&pdev->rx_status_q);
1051
1052 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001053
Karunakar Dasineni40555682017-03-26 22:44:39 -07001054 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001055 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001056
Kai Chen783e0382018-01-25 16:29:08 -08001057 qdf_mem_zero(&pdev->rx_mon_stats,
1058 sizeof(pdev->rx_mon_stats));
1059
1060 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1061 &pdev->rx_mon_stats);
1062
Kai Chen6eca1a62017-01-12 10:17:53 -08001063 return QDF_STATUS_SUCCESS;
1064}