blob: 2e871da09e1bb83115936a17434cdffafee11de2 [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);
Amir Patelbb69cfa2019-03-28 16:16:01 +0530202 if (!peer->stats.rx.avg_rssi)
203 peer->stats.rx.avg_rssi = ppdu->rssi;
204 else
205 peer->stats.rx.avg_rssi =
206 DP_GET_AVG_RSSI(peer->stats.rx.avg_rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530207
208 if ((preamble == DOT11_A) || (preamble == DOT11_B))
209 ppdu->u.nss = 1;
210
211 if (ppdu->u.nss)
212 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
213
Pranita Solankea12b4b32017-11-20 23:04:14 +0530214 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530215 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530216 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530217 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
218 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
219 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530220 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530221 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530222 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
223 DP_STATS_INCC(peer,
224 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530225 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530226 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530227 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530228 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
229 DP_STATS_INCC(peer,
230 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530231 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530232 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530233 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530234 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
235 DP_STATS_INCC(peer,
236 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530237 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530238 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530239 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530240 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
241 DP_STATS_INCC(peer,
242 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
243 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
244 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530245 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530246 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
247 DP_STATS_INCC(peer,
248 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
249 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530250 /*
251 * If invalid TID, it could be a non-qos frame, hence do not update
252 * any AC counters
253 */
254 ac = TID_TO_WME_AC(ppdu->tid);
255 if (ppdu->tid != HAL_TID_INVALID)
256 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530257 dp_peer_stats_notify(peer);
258 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530259
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530260 if (is_invalid_peer)
261 return;
262
ydb247452018-08-08 00:23:16 +0530263 dp_rx_rate_stats_update(peer, ppdu);
264
Amir Patel756d05e2018-10-10 12:35:30 +0530265#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
266 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
267 &peer->stats, ppdu->peer_id,
268 UPDATE_PEER_STATS, pdev->pdev_id);
269#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530270}
271#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530272
273/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530274 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530275 * @soc: core txrx main context
276 * @pdev: pdev strcuture
277 * @ppdu_info: structure for rx ppdu ring
278 *
279 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
280 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530281 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530282#ifdef FEATURE_PERPKT_INFO
283static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530284dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530285 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
286{
287 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530288 struct ieee80211_frame *wh;
289 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530290
Jeff Johnsona8edf332019-03-18 09:51:52 -0700291 if (!ppdu_info->msdu_info.first_msdu_payload)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530292 return QDF_STATUS_SUCCESS;
293
Soumya Bhat2f54de22018-02-21 09:54:28 +0530294 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530295 return QDF_STATUS_SUCCESS;
296
Soumya Bhat2f54de22018-02-21 09:54:28 +0530297 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530298
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530299 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
300 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530301 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530302 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530303 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530304
305 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
306 return QDF_STATUS_SUCCESS;
307
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530308 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
309 IEEE80211_FC0_TYPE_MGT) ||
310 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
311 IEEE80211_FC0_TYPE_CTL)) {
312 return QDF_STATUS_SUCCESS;
313 }
314
315 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
316 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530317 /* only retain RX MSDU payload in the skb */
318 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
319 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530320 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
321 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
322 return QDF_STATUS_E_ALREADY;
323}
324#else
325static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530326dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530327 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
328{
329 return QDF_STATUS_SUCCESS;
330}
331#endif
332
sumedh baikady59a2d332018-05-22 01:50:38 -0700333/**
334 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
335 * @soc: Datapath SOC handle
336 * @pdev: Datapath PDEV handle
337 * @ppdu_info: Structure for rx ppdu info
338 * @nbuf: Qdf nbuf abstraction for linux skb
339 *
340 * Return: 0 on success, 1 on failure
341 */
342static inline int
343dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
344 struct hal_rx_ppdu_info *ppdu_info,
345 qdf_nbuf_t nbuf)
346{
347 uint8_t size = 0;
348
349 if (!pdev->monitor_vdev) {
350 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
351 "[%s]:[%d] Monitor vdev is NULL !!",
352 __func__, __LINE__);
353 return 1;
354 }
Jeff Johnsona8edf332019-03-18 09:51:52 -0700355 if (!ppdu_info->msdu_info.first_msdu_payload) {
sumedh baikady59a2d332018-05-22 01:50:38 -0700356 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
357 "[%s]:[%d] First msdu payload not present",
358 __func__, __LINE__);
359 return 1;
360 }
361
sumedh baikadyda159202018-11-01 17:31:23 -0700362 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700363 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700364 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700365 ppdu_info->msdu_info.first_msdu_payload = NULL;
366
367 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
368 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
369 "[%s]:[%d] No header present",
370 __func__, __LINE__);
371 return 1;
372 }
373
sumedh baikadyda159202018-11-01 17:31:23 -0700374 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700375 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
376 ppdu_info->msdu_info.payload_len);
377 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
378 nbuf, sizeof(struct rx_pkt_tlvs));
379 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
380 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700381 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700382 return 0;
383}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530384
385/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530386* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
387* @soc: core txrx main context
388* @pdev: pdev strcuture
389* @ppdu_info: structure for rx ppdu ring
390*
391* Return: none
392*/
393#ifdef FEATURE_PERPKT_INFO
394static inline void
395dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
396 struct hal_rx_ppdu_info *ppdu_info)
397{
398 qdf_nbuf_t ppdu_nbuf;
399 struct dp_peer *peer;
400 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
401
Anish Nataraj28490c42018-01-19 19:34:54 +0530402 /*
403 * Do not allocate if fcs error,
404 * ast idx invalid / fctl invalid
405 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530406 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
407 return;
408
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530409 if (ppdu_info->nac_info.fc_valid &&
410 ppdu_info->nac_info.to_ds_flag &&
411 ppdu_info->nac_info.mac_addr2_valid) {
412 struct dp_neighbour_peer *peer = NULL;
413 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
414
415 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
416 if (pdev->neighbour_peers_added) {
417 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
418 neighbour_peer_list_elem) {
419 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
420 &ppdu_info->nac_info.mac_addr2,
Srinivas Girigowda2751b6d2019-02-27 12:28:13 -0800421 QDF_MAC_ADDR_SIZE)) {
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530422 peer->rssi = rssi;
423 break;
424 }
425 }
426 }
427 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
428 }
429
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530430 /* need not generate wdi event when mcopy and
431 * enhanced stats are not enabled
432 */
433 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
434 return;
435
Soumya Bhat560f90c2018-03-30 13:53:26 +0530436 if (!pdev->mcopy_mode) {
437 if (!ppdu_info->rx_status.frame_control_info_valid)
438 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530439
Soumya Bhat560f90c2018-03-30 13:53:26 +0530440 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
441 return;
442 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530443 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Kiran Venkatappa4b50f332019-03-20 18:14:17 +0530444 sizeof(struct cdp_rx_indication_ppdu), 0, 0, FALSE);
Anish Nataraj38a29562017-08-18 19:41:17 +0530445 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530446 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530447 qdf_nbuf_put_tail(ppdu_nbuf,
448 sizeof(struct cdp_rx_indication_ppdu));
449 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530450 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800451 if (peer) {
Amir Patel468bded2019-03-21 11:42:31 +0530452 cdp_rx_ppdu->cookie = (void *)peer->wlanstats_ctx;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530453 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800454 dp_peer_unref_del_find_by_id(peer);
455 }
456 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
457 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
458 soc, ppdu_nbuf,
459 cdp_rx_ppdu->peer_id,
460 WDI_NO_VAL, pdev->pdev_id);
461 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530462 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
463 ppdu_nbuf, HTT_INVALID_PEER,
464 WDI_NO_VAL, pdev->pdev_id);
465 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530466 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530467 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530468 }
469}
470#else
471static inline void
472dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
473 struct hal_rx_ppdu_info *ppdu_info)
474{
475}
476#endif
477
478/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800479* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
480* filtering enabled
481* @soc: core txrx main context
482* @ppdu_info: Structure for rx ppdu info
483* @status_nbuf: Qdf nbuf abstraction for linux skb
484* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
485*
486* Return: none
487*/
488static inline void
489dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
490 struct hal_rx_ppdu_info *ppdu_info,
491 qdf_nbuf_t status_nbuf, uint32_t mac_id)
492{
493 struct dp_peer *peer;
494 struct dp_ast_entry *ast_entry;
495 uint32_t ast_index;
496
497 ast_index = ppdu_info->rx_status.ast_index;
498 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
499 ast_entry = soc->ast_table[ast_index];
500 if (ast_entry) {
501 peer = ast_entry->peer;
502 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
503 if (peer->peer_based_pktlog_filter) {
504 dp_wdi_event_handler(
505 WDI_EVENT_RX_DESC, soc,
506 status_nbuf,
507 peer->peer_ids[0],
508 WDI_NO_VAL, mac_id);
509 }
510 }
511 }
512 }
513}
514
515/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800516* dp_rx_mon_status_process_tlv() - Process status TLV in status
517* buffer on Rx status Queue posted by status SRNG processing.
518* @soc: core txrx main context
519* @mac_id: mac_id which is one of 3 mac_ids _ring
520*
521* Return: none
522*/
523static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700524dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
525 uint32_t quota)
526{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800527 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800528 struct hal_rx_ppdu_info *ppdu_info;
529 qdf_nbuf_t status_nbuf;
530 uint8_t *rx_tlv;
531 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700532 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530533 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800534 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700535 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800536 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen6eca1a62017-01-12 10:17:53 -0800537
Kai Chen6eca1a62017-01-12 10:17:53 -0800538 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800539 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800540
541 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
542 return;
543
544 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
545
546 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530547
Kai Chen6eca1a62017-01-12 10:17:53 -0800548 rx_tlv = qdf_nbuf_data(status_nbuf);
549 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700550
Jeff Johnsona8edf332019-03-18 09:51:52 -0700551 if ((pdev->monitor_vdev) || (pdev->enhanced_stats_en) ||
Soumya Bhat2f54de22018-02-21 09:54:28 +0530552 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800553
Keyur Parekhfad6d082017-05-07 08:54:47 -0700554 do {
555 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530556 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800557
558 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
559 rx_mon_stats);
560
Keyur Parekhfad6d082017-05-07 08:54:47 -0700561 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800562
Keyur Parekhfad6d082017-05-07 08:54:47 -0700563 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
564 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800565
Keyur Parekhfad6d082017-05-07 08:54:47 -0700566 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
567 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800568 if (pdev->dp_peer_based_pktlog) {
569 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
570 status_nbuf, mac_id);
571 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800572 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
573 pktlog_mode = WDI_EVENT_RX_DESC;
574 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
575 pktlog_mode = WDI_EVENT_LITE_RX;
576
577 if (pktlog_mode != WDI_NO_VAL)
578 dp_wdi_event_handler(pktlog_mode, soc,
579 status_nbuf,
580 HTT_INVALID_PEER,
581 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800582 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530583
584 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700585 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
586 && pdev->monitor_vdev) {
587 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
588 pdev, ppdu_info, status_nbuf);
589 if (smart_mesh_status)
590 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530591 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530592 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530593 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530594 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530595 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530596 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700597 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530598 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800599
chenguo1b880462018-07-11 15:34:56 +0800600 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
601 dp_rx_mon_deliver_non_std(soc, mac_id);
602 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800603 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530604 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700605 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530606 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530607
nobelj1c31fee2018-03-21 11:47:05 -0700608 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
609 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700610 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800611 }
612 }
613 return;
614}
615
616/*
617 * dp_rx_mon_status_srng_process() - Process monitor status ring
618 * post the status ring buffer to Rx status Queue for later
619 * processing when status ring is filled with status TLV.
620 * Allocate a new buffer to status ring if the filled buffer
621 * is posted.
622 *
623 * @soc: core txrx main context
624 * @mac_id: mac_id which is one of 3 mac_ids
625 * @quota: No. of ring entry that can be serviced in one shot.
626
627 * Return: uint32_t: No. of ring entry that is processed.
628 */
629static inline uint32_t
630dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
631 uint32_t quota)
632{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800633 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800634 void *hal_soc;
635 void *mon_status_srng;
636 void *rxdma_mon_status_ring_entry;
637 QDF_STATUS status;
638 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800639 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800640
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800641 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800642
643 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700644 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
645
646 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530647 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700648 __func__, __LINE__, mon_status_srng);
649 return work_done;
650 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800651
652 hal_soc = soc->hal_soc;
653
654 qdf_assert(hal_soc);
655
656 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
657 goto done;
658
659 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
660 * BUFFER_ADDR_INFO STRUCT
661 */
662 while (qdf_likely((rxdma_mon_status_ring_entry =
663 hal_srng_src_peek(hal_soc, mon_status_srng))
664 && quota--)) {
665 uint32_t rx_buf_cookie;
666 qdf_nbuf_t status_nbuf;
667 struct dp_rx_desc *rx_desc;
668 uint8_t *status_buf;
669 qdf_dma_addr_t paddr;
670 uint64_t buf_addr;
671
672 buf_addr =
673 (HAL_RX_BUFFER_ADDR_31_0_GET(
674 rxdma_mon_status_ring_entry) |
675 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
676 rxdma_mon_status_ring_entry)) << 32));
677
678 if (qdf_likely(buf_addr)) {
679
680 rx_buf_cookie =
681 HAL_RX_BUF_COOKIE_GET(
682 rxdma_mon_status_ring_entry);
683 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
684 rx_buf_cookie);
685
686 qdf_assert(rx_desc);
687
688 status_nbuf = rx_desc->nbuf;
689
690 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
691 QDF_DMA_FROM_DEVICE);
692
693 status_buf = qdf_nbuf_data(status_nbuf);
694
695 status = hal_get_rx_status_done(status_buf);
696
697 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800698 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700699 hal_get_sw_hptp(hal_soc, mon_status_srng,
700 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800701 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800702 QDF_TRACE_LEVEL_ERROR,
703 "[%s][%d] status not done - hp:%u, tp:%u",
704 __func__, __LINE__, hp, tp);
705 /* WAR for missing status: Skip status entry */
706 hal_srng_src_get_next(hal_soc, mon_status_srng);
707 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800708 }
709 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
710
711 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
712 QDF_DMA_FROM_DEVICE);
713
714 /* Put the status_nbuf to queue */
715 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
716
717 } else {
718 union dp_rx_desc_list_elem_t *desc_list = NULL;
719 union dp_rx_desc_list_elem_t *tail = NULL;
720 struct rx_desc_pool *rx_desc_pool;
721 uint32_t num_alloc_desc;
722
723 rx_desc_pool = &soc->rx_desc_status[mac_id];
724
725 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
726 rx_desc_pool,
727 1,
728 &desc_list,
729 &tail);
phadimanebf4cde2019-01-28 17:50:37 +0530730 /*
731 * No free descriptors available
732 */
733 if (qdf_unlikely(num_alloc_desc == 0)) {
734 work_done++;
735 break;
736 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800737
738 rx_desc = &desc_list->rx_desc;
739 }
740
jinweic chenc3546322018-02-02 15:03:41 +0800741 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800742
jinweic chenc3546322018-02-02 15:03:41 +0800743 /*
744 * qdf_nbuf alloc or map failed,
745 * free the dp rx desc to free list,
746 * fill in NULL dma address at current HP entry,
747 * keep HP in mon_status_ring unchanged,
748 * wait next time dp_rx_mon_status_srng_process
749 * to fill in buffer at current HP.
750 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700751 if (qdf_unlikely(!status_nbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800752 union dp_rx_desc_list_elem_t *desc_list = NULL;
753 union dp_rx_desc_list_elem_t *tail = NULL;
754 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800755
jinweic chenc3546322018-02-02 15:03:41 +0800756 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800757
jinweic chenc3546322018-02-02 15:03:41 +0800758 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
759 "%s: fail to allocate or map qdf_nbuf",
760 __func__);
761 dp_rx_add_to_free_desc_list(&desc_list,
762 &tail, rx_desc);
763 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
764 &tail, mac_id, rx_desc_pool);
765
766 hal_rxdma_buff_addr_info_set(
767 rxdma_mon_status_ring_entry,
768 0, 0, HAL_RX_BUF_RBM_SW3_BM);
769 work_done++;
770 break;
771 }
772
Kai Chen6eca1a62017-01-12 10:17:53 -0800773 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
774
775 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700776 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800777
778 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
779 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
780
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800781 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800782 work_done++;
783 }
784done:
785
786 hal_srng_access_end(hal_soc, mon_status_srng);
787
788 return work_done;
789
790}
791/*
792 * dp_rx_mon_status_process() - Process monitor status ring and
793 * TLV in status ring.
794 *
795 * @soc: core txrx main context
796 * @mac_id: mac_id which is one of 3 mac_ids
797 * @quota: No. of ring entry that can be serviced in one shot.
798
799 * Return: uint32_t: No. of ring entry that is processed.
800 */
801static inline uint32_t
802dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
803 uint32_t work_done;
804
805 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700806 quota -= work_done;
807 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800808
809 return work_done;
810}
811/**
812 * dp_mon_process() - Main monitor mode processing roution.
813 * This call monitor status ring process then monitor
814 * destination ring process.
815 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
816 * @soc: core txrx main context
817 * @mac_id: mac_id which is one of 3 mac_ids
818 * @quota: No. of status ring entry that can be serviced in one shot.
819
820 * Return: uint32_t: No. of ring entry that is processed.
821 */
822uint32_t
823dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700824 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800825}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700826
Kai Chen6eca1a62017-01-12 10:17:53 -0800827/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700828 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800829 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800830 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800831 *
832 * This function will detach DP RX status ring from
833 * main device context. will free DP Rx resources for
834 * status ring
835 *
836 * Return: QDF_STATUS_SUCCESS: success
837 * QDF_STATUS_E_RESOURCES: Error return
838 */
839QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800840dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800841{
Kai Chen6eca1a62017-01-12 10:17:53 -0800842 struct dp_soc *soc = pdev->soc;
843 struct rx_desc_pool *rx_desc_pool;
844
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800845 rx_desc_pool = &soc->rx_desc_status[mac_id];
phadiman449a2682019-02-20 14:00:00 +0530846 if (rx_desc_pool->pool_size != 0) {
847 if (!dp_is_soc_reinit(soc))
848 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
849 else
850 dp_rx_desc_nbuf_pool_free(soc, rx_desc_pool);
851 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800852
853 return QDF_STATUS_SUCCESS;
854}
855
856/*
857 * dp_rx_buffers_replenish() - replenish monitor status ring with
858 * rx nbufs called during dp rx
859 * monitor status ring initialization
860 *
861 * @soc: core txrx main context
862 * @mac_id: mac_id which is one of 3 mac_ids
863 * @dp_rxdma_srng: dp monitor status circular ring
864 * @rx_desc_pool; Pointer to Rx descriptor pool
865 * @num_req_buffers: number of buffer to be replenished
866 * @desc_list: list of descs if called from dp rx monitor status
867 * process or NULL during dp rx initialization or
868 * out of buffer interrupt
869 * @tail: tail of descs list
870 * @owner: who owns the nbuf (host, NSS etc...)
871 * Return: return success or failure
872 */
873static inline
874QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
875 uint32_t mac_id,
876 struct dp_srng *dp_rxdma_srng,
877 struct rx_desc_pool *rx_desc_pool,
878 uint32_t num_req_buffers,
879 union dp_rx_desc_list_elem_t **desc_list,
880 union dp_rx_desc_list_elem_t **tail,
881 uint8_t owner)
882{
883 uint32_t num_alloc_desc;
884 uint16_t num_desc_to_free = 0;
885 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800886 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800887 int sync_hw_ptr = 1;
888 qdf_dma_addr_t paddr;
889 qdf_nbuf_t rx_netbuf;
890 void *rxdma_ring_entry;
891 union dp_rx_desc_list_elem_t *next;
892 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800893 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800894
895 rxdma_srng = dp_rxdma_srng->hal_srng;
896
897 qdf_assert(rxdma_srng);
898
Houston Hoffmanae850c62017-08-11 16:47:50 -0700899 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530900 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800901 __func__, __LINE__, num_req_buffers);
902
903 /*
904 * if desc_list is NULL, allocate the descs from freelist
905 */
906 if (!(*desc_list)) {
907
908 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
909 rx_desc_pool,
910 num_req_buffers,
911 desc_list,
912 tail);
913
914 if (!num_alloc_desc) {
915 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530916 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800917 __func__, __LINE__);
918 return QDF_STATUS_E_NOMEM;
919 }
920
Houston Hoffmanae850c62017-08-11 16:47:50 -0700921 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530922 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800923 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700924
Kai Chen6eca1a62017-01-12 10:17:53 -0800925 num_req_buffers = num_alloc_desc;
926 }
927
928 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
929 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
930 rxdma_srng, sync_hw_ptr);
931
Houston Hoffmanae850c62017-08-11 16:47:50 -0700932 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530933 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800934 __func__, __LINE__, num_entries_avail);
935
936 if (num_entries_avail < num_req_buffers) {
937 num_desc_to_free = num_req_buffers - num_entries_avail;
938 num_req_buffers = num_entries_avail;
939 }
940
jinweic chenc3546322018-02-02 15:03:41 +0800941 while (count < num_req_buffers) {
942 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800943
jinweic chenc3546322018-02-02 15:03:41 +0800944 /*
945 * qdf_nbuf alloc or map failed,
946 * keep HP in mon_status_ring unchanged,
947 * wait dp_rx_mon_status_srng_process
948 * to fill in buffer at current HP.
949 */
Jeff Johnsona8edf332019-03-18 09:51:52 -0700950 if (qdf_unlikely(!rx_netbuf)) {
jinweic chenc3546322018-02-02 15:03:41 +0800951 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
952 "%s: qdf_nbuf allocate or map fail, count %d",
953 __func__, count);
954 break;
955 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800956
957 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
958
959 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700960 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
961 rxdma_srng);
962
Jeff Johnsona8edf332019-03-18 09:51:52 -0700963 if (qdf_unlikely(!rxdma_ring_entry)) {
sumedh baikadyeca2de62018-04-11 14:20:38 -0700964 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530965 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700966 __func__, __LINE__, count);
967 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
968 QDF_DMA_BIDIRECTIONAL);
969 qdf_nbuf_free(rx_netbuf);
970 break;
971 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800972
973 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700974 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800975 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800976
Kai Chen6eca1a62017-01-12 10:17:53 -0800977 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
978 (*desc_list)->rx_desc.cookie, owner);
979
Karunakar Dasineni40555682017-03-26 22:44:39 -0700980 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700981 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530982 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800983 __func__, __LINE__, &(*desc_list)->rx_desc,
984 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800985 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800986
987 *desc_list = next;
988 }
989
990 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
991
Houston Hoffmanae850c62017-08-11 16:47:50 -0700992 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530993 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800994
Houston Hoffmanae850c62017-08-11 16:47:50 -0700995 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530996 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800997
Kai Chen6eca1a62017-01-12 10:17:53 -0800998 /*
999 * add any available free desc back to the free list
1000 */
1001 if (*desc_list) {
1002 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
1003 mac_id, rx_desc_pool);
1004 }
1005
1006 return QDF_STATUS_SUCCESS;
1007}
1008/**
1009 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
1010 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -07001011 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -08001012 * This function will attach a DP RX monitor status ring into pDEV
1013 * and replenish monitor status ring with buffer.
1014 *
1015 * Return: QDF_STATUS_SUCCESS: success
1016 * QDF_STATUS_E_RESOURCES: Error return
1017 */
1018QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001019dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001020 struct dp_soc *soc = pdev->soc;
1021 union dp_rx_desc_list_elem_t *desc_list = NULL;
1022 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001023 struct dp_srng *mon_status_ring;
1024 uint32_t num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001025 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001026 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001027 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001028
Mohit Khanna70514992018-11-12 18:39:03 -08001029 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001030
Mohit Khanna70514992018-11-12 18:39:03 -08001031 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001032
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001033 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001034
Mohit Khanna70514992018-11-12 18:39:03 -08001035 dp_info("Mon RX Status Pool[%d] entries=%d",
1036 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001037
Mohit Khanna70514992018-11-12 18:39:03 -08001038 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1039 rx_desc_pool);
1040 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001041 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001042
Mohit Khanna70514992018-11-12 18:39:03 -08001043 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001044
Mohit Khanna70514992018-11-12 18:39:03 -08001045 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1046 mon_status_ring,
1047 rx_desc_pool,
1048 num_entries,
1049 &desc_list, &tail,
1050 HAL_RX_BUF_RBM_SW3_BM);
1051
1052 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001053 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001054
1055 qdf_nbuf_queue_init(&pdev->rx_status_q);
1056
1057 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001058
Karunakar Dasineni40555682017-03-26 22:44:39 -07001059 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001060 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001061
Kai Chen783e0382018-01-25 16:29:08 -08001062 qdf_mem_zero(&pdev->rx_mon_stats,
1063 sizeof(pdev->rx_mon_stats));
1064
1065 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1066 &pdev->rx_mon_stats);
1067
Kai Chen6eca1a62017-01-12 10:17:53 -08001068 return QDF_STATUS_SUCCESS;
1069}