blob: b13902befec84a4f212aa829fdc55af8999a3f13 [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;
Anish Nataraj38a29562017-08-18 19:41:17 +053078 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +053079 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
80 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
nobeljd8039592018-03-13 16:59:42 -070081 cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053082 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
83 cdp_rx_ppdu->udp_msdu_count +
84 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053085
Anish Nataraj57614da2018-02-07 23:04:24 +053086 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Pranita Solankeed0aba62018-01-12 19:14:31 +053087 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
88 cdp_rx_ppdu->is_ampdu = 1;
89 else
90 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053091
92 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +053093 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Soumya Bhat560f90c2018-03-30 13:53:26 +053094
95 ast_index = ppdu_info->rx_status.ast_index;
Tallapragada Kalyana7023622018-12-03 19:29:52 +053096 if (ast_index >= wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
Soumya Bhat560f90c2018-03-30 13:53:26 +053097 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
98 return;
99 }
100
101 ast_entry = soc->ast_table[ast_index];
102 if (!ast_entry) {
103 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
104 return;
105 }
106 peer = ast_entry->peer;
107 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
108 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
109 return;
110 }
111
112 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
113 peer->mac_addr.raw, DP_MAC_ADDR_LEN);
114 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
115 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Anish Nataraj38a29562017-08-18 19:41:17 +0530116}
117#else
118static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530119dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530120 struct hal_rx_ppdu_info *ppdu_info,
121 qdf_nbuf_t ppdu_nbuf)
122{
123}
124#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530125/**
126 * dp_rx_stats_update() - Update per-peer statistics
127 * @soc: Datapath SOC handle
128 * @peer: Datapath peer handle
129 * @ppdu: PPDU Descriptor
130 *
131 * Return: None
132 */
133#ifdef FEATURE_PERPKT_INFO
ydb247452018-08-08 00:23:16 +0530134static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
135 struct cdp_rx_indication_ppdu *ppdu)
136{
137 uint32_t ratekbps = 0;
138 uint32_t ppdu_rx_rate = 0;
139 uint32_t nss = 0;
Amir Patel78824b12019-02-23 10:54:32 +0530140 uint32_t rix;
ydb247452018-08-08 00:23:16 +0530141
142 if (!peer || !ppdu)
143 return;
144
145 if (ppdu->u.nss == 0)
146 nss = 0;
147 else
148 nss = ppdu->u.nss - 1;
149
Anish Nataraj376d9b12018-08-13 14:12:01 +0530150 ratekbps = dp_getrateindex(ppdu->u.gi,
151 ppdu->u.mcs,
ydb247452018-08-08 00:23:16 +0530152 nss,
153 ppdu->u.preamble,
Amir Patel78824b12019-02-23 10:54:32 +0530154 ppdu->u.bw,
155 &rix);
ydb247452018-08-08 00:23:16 +0530156
157 if (!ratekbps)
158 return;
159
160 DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
161 dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
162 ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
163 DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
164
165 if (peer->vdev)
166 peer->vdev->stats.rx.last_rx_rate = ratekbps;
167}
168
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530169static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
170 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530171{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530172 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530173 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530174 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530175 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530176
177 mcs = ppdu->u.mcs;
178 preamble = ppdu->u.preamble;
179 num_msdu = ppdu->num_msdu;
180
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530181 if (pdev)
182 soc = pdev->soc;
183 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530184 return;
185
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530186 if (!peer) {
187 is_invalid_peer = true;
188 peer = pdev->invalid_peer;
189 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530190
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530191 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530192 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530193
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530194 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530195
196 if ((preamble == DOT11_A) || (preamble == DOT11_B))
197 ppdu->u.nss = 1;
198
199 if (ppdu->u.nss)
200 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
201
Pranita Solankea12b4b32017-11-20 23:04:14 +0530202 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530203 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530204 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530205 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
206 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
207 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530208 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530209 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530210 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
211 DP_STATS_INCC(peer,
212 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530213 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530214 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530215 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530216 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
217 DP_STATS_INCC(peer,
218 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530219 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
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_N)));
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_N)));
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_11AC) && (preamble == DOT11_AC)));
229 DP_STATS_INCC(peer,
230 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
231 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
232 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 - 1)) && (preamble == DOT11_AX)));
235 DP_STATS_INCC(peer,
236 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
237 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530238 /*
239 * If invalid TID, it could be a non-qos frame, hence do not update
240 * any AC counters
241 */
242 ac = TID_TO_WME_AC(ppdu->tid);
243 if (ppdu->tid != HAL_TID_INVALID)
244 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530245 dp_peer_stats_notify(peer);
246 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530247
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530248 if (is_invalid_peer)
249 return;
250
ydb247452018-08-08 00:23:16 +0530251 dp_rx_rate_stats_update(peer, ppdu);
252
Amir Patel756d05e2018-10-10 12:35:30 +0530253#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
254 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
255 &peer->stats, ppdu->peer_id,
256 UPDATE_PEER_STATS, pdev->pdev_id);
257#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530258}
259#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530260
261/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530262 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530263 * @soc: core txrx main context
264 * @pdev: pdev strcuture
265 * @ppdu_info: structure for rx ppdu ring
266 *
267 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
268 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530269 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530270#ifdef FEATURE_PERPKT_INFO
271static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530272dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530273 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
274{
275 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530276 struct ieee80211_frame *wh;
277 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530278
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530279 if (ppdu_info->msdu_info.first_msdu_payload == NULL)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530280 return QDF_STATUS_SUCCESS;
281
Soumya Bhat2f54de22018-02-21 09:54:28 +0530282 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530283 return QDF_STATUS_SUCCESS;
284
Soumya Bhat2f54de22018-02-21 09:54:28 +0530285 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530286
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530287 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
288 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530289 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530290 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530291 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530292
293 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
294 return QDF_STATUS_SUCCESS;
295
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530296 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
297 IEEE80211_FC0_TYPE_MGT) ||
298 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
299 IEEE80211_FC0_TYPE_CTL)) {
300 return QDF_STATUS_SUCCESS;
301 }
302
303 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
304 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530305 /* only retain RX MSDU payload in the skb */
306 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
307 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530308 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
309 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
310 return QDF_STATUS_E_ALREADY;
311}
312#else
313static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530314dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530315 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
316{
317 return QDF_STATUS_SUCCESS;
318}
319#endif
320
sumedh baikady59a2d332018-05-22 01:50:38 -0700321/**
322 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
323 * @soc: Datapath SOC handle
324 * @pdev: Datapath PDEV handle
325 * @ppdu_info: Structure for rx ppdu info
326 * @nbuf: Qdf nbuf abstraction for linux skb
327 *
328 * Return: 0 on success, 1 on failure
329 */
330static inline int
331dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
332 struct hal_rx_ppdu_info *ppdu_info,
333 qdf_nbuf_t nbuf)
334{
335 uint8_t size = 0;
336
337 if (!pdev->monitor_vdev) {
338 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
339 "[%s]:[%d] Monitor vdev is NULL !!",
340 __func__, __LINE__);
341 return 1;
342 }
343 if (ppdu_info->msdu_info.first_msdu_payload == NULL) {
344 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
345 "[%s]:[%d] First msdu payload not present",
346 __func__, __LINE__);
347 return 1;
348 }
349
sumedh baikadyda159202018-11-01 17:31:23 -0700350 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700351 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700352 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700353 ppdu_info->msdu_info.first_msdu_payload = NULL;
354
355 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
356 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
357 "[%s]:[%d] No header present",
358 __func__, __LINE__);
359 return 1;
360 }
361
sumedh baikadyda159202018-11-01 17:31:23 -0700362 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700363 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
364 ppdu_info->msdu_info.payload_len);
365 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
366 nbuf, sizeof(struct rx_pkt_tlvs));
367 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
368 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700369 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700370 return 0;
371}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530372
373/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530374* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
375* @soc: core txrx main context
376* @pdev: pdev strcuture
377* @ppdu_info: structure for rx ppdu ring
378*
379* Return: none
380*/
381#ifdef FEATURE_PERPKT_INFO
382static inline void
383dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
384 struct hal_rx_ppdu_info *ppdu_info)
385{
386 qdf_nbuf_t ppdu_nbuf;
387 struct dp_peer *peer;
388 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
389
Anish Nataraj28490c42018-01-19 19:34:54 +0530390 /*
391 * Do not allocate if fcs error,
392 * ast idx invalid / fctl invalid
393 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530394 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
395 return;
396
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530397 if (ppdu_info->nac_info.fc_valid &&
398 ppdu_info->nac_info.to_ds_flag &&
399 ppdu_info->nac_info.mac_addr2_valid) {
400 struct dp_neighbour_peer *peer = NULL;
401 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
402
403 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
404 if (pdev->neighbour_peers_added) {
405 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
406 neighbour_peer_list_elem) {
407 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
408 &ppdu_info->nac_info.mac_addr2,
409 DP_MAC_ADDR_LEN)) {
410 peer->rssi = rssi;
411 break;
412 }
413 }
414 }
415 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
416 }
417
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530418 /* need not generate wdi event when mcopy and
419 * enhanced stats are not enabled
420 */
421 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
422 return;
423
Soumya Bhat560f90c2018-03-30 13:53:26 +0530424 if (!pdev->mcopy_mode) {
425 if (!ppdu_info->rx_status.frame_control_info_valid)
426 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530427
Soumya Bhat560f90c2018-03-30 13:53:26 +0530428 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
429 return;
430 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530431 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530432 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
433 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530434 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530435 qdf_nbuf_put_tail(ppdu_nbuf,
436 sizeof(struct cdp_rx_indication_ppdu));
437 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530438 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800439 if (peer) {
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530440 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800441 dp_peer_unref_del_find_by_id(peer);
442 }
443 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
444 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
445 soc, ppdu_nbuf,
446 cdp_rx_ppdu->peer_id,
447 WDI_NO_VAL, pdev->pdev_id);
448 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530449 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
450 ppdu_nbuf, HTT_INVALID_PEER,
451 WDI_NO_VAL, pdev->pdev_id);
452 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530453 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530454 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530455 }
456}
457#else
458static inline void
459dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
460 struct hal_rx_ppdu_info *ppdu_info)
461{
462}
463#endif
464
465/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800466* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
467* filtering enabled
468* @soc: core txrx main context
469* @ppdu_info: Structure for rx ppdu info
470* @status_nbuf: Qdf nbuf abstraction for linux skb
471* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
472*
473* Return: none
474*/
475static inline void
476dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
477 struct hal_rx_ppdu_info *ppdu_info,
478 qdf_nbuf_t status_nbuf, uint32_t mac_id)
479{
480 struct dp_peer *peer;
481 struct dp_ast_entry *ast_entry;
482 uint32_t ast_index;
483
484 ast_index = ppdu_info->rx_status.ast_index;
485 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
486 ast_entry = soc->ast_table[ast_index];
487 if (ast_entry) {
488 peer = ast_entry->peer;
489 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
490 if (peer->peer_based_pktlog_filter) {
491 dp_wdi_event_handler(
492 WDI_EVENT_RX_DESC, soc,
493 status_nbuf,
494 peer->peer_ids[0],
495 WDI_NO_VAL, mac_id);
496 }
497 }
498 }
499 }
500}
501
502/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800503* dp_rx_mon_status_process_tlv() - Process status TLV in status
504* buffer on Rx status Queue posted by status SRNG processing.
505* @soc: core txrx main context
506* @mac_id: mac_id which is one of 3 mac_ids _ring
507*
508* Return: none
509*/
510static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700511dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
512 uint32_t quota)
513{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800514 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800515 struct hal_rx_ppdu_info *ppdu_info;
516 qdf_nbuf_t status_nbuf;
517 uint8_t *rx_tlv;
518 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700519 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530520 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800521 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700522 int smart_mesh_status;
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800523 enum WDI_EVENT pktlog_mode = WDI_NO_VAL;
Kai Chen6eca1a62017-01-12 10:17:53 -0800524
Kai Chen6eca1a62017-01-12 10:17:53 -0800525 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800526 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800527
528 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
529 return;
530
531 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
532
533 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530534
Kai Chen6eca1a62017-01-12 10:17:53 -0800535 rx_tlv = qdf_nbuf_data(status_nbuf);
536 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700537
Soumya Bhat2f54de22018-02-21 09:54:28 +0530538 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en) ||
539 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800540
Keyur Parekhfad6d082017-05-07 08:54:47 -0700541 do {
542 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530543 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800544
545 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
546 rx_mon_stats);
547
Keyur Parekhfad6d082017-05-07 08:54:47 -0700548 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800549
Keyur Parekhfad6d082017-05-07 08:54:47 -0700550 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
551 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800552
Keyur Parekhfad6d082017-05-07 08:54:47 -0700553 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
554 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800555 if (pdev->dp_peer_based_pktlog) {
556 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
557 status_nbuf, mac_id);
558 } else {
Venkata Sharath Chandra Manchalacad74ad2019-01-28 11:36:47 -0800559 if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_FULL)
560 pktlog_mode = WDI_EVENT_RX_DESC;
561 else if (pdev->rx_pktlog_mode == DP_RX_PKTLOG_LITE)
562 pktlog_mode = WDI_EVENT_LITE_RX;
563
564 if (pktlog_mode != WDI_NO_VAL)
565 dp_wdi_event_handler(pktlog_mode, soc,
566 status_nbuf,
567 HTT_INVALID_PEER,
568 WDI_NO_VAL, mac_id);
Keyur Parekhc28f8392018-11-21 02:50:56 -0800569 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530570
571 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700572 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
573 && pdev->monitor_vdev) {
574 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
575 pdev, ppdu_info, status_nbuf);
576 if (smart_mesh_status)
577 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530578 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530579 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530580 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530581 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530582 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530583 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700584 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530585 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800586
chenguo1b880462018-07-11 15:34:56 +0800587 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
588 dp_rx_mon_deliver_non_std(soc, mac_id);
589 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800590 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530591 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700592 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530593 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530594
nobelj1c31fee2018-03-21 11:47:05 -0700595 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
596 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700597 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800598 }
599 }
600 return;
601}
602
603/*
604 * dp_rx_mon_status_srng_process() - Process monitor status ring
605 * post the status ring buffer to Rx status Queue for later
606 * processing when status ring is filled with status TLV.
607 * Allocate a new buffer to status ring if the filled buffer
608 * is posted.
609 *
610 * @soc: core txrx main context
611 * @mac_id: mac_id which is one of 3 mac_ids
612 * @quota: No. of ring entry that can be serviced in one shot.
613
614 * Return: uint32_t: No. of ring entry that is processed.
615 */
616static inline uint32_t
617dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
618 uint32_t quota)
619{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800620 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800621 void *hal_soc;
622 void *mon_status_srng;
623 void *rxdma_mon_status_ring_entry;
624 QDF_STATUS status;
625 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800626 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800627
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800628 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800629
630 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700631 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
632
633 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530634 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700635 __func__, __LINE__, mon_status_srng);
636 return work_done;
637 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800638
639 hal_soc = soc->hal_soc;
640
641 qdf_assert(hal_soc);
642
643 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
644 goto done;
645
646 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
647 * BUFFER_ADDR_INFO STRUCT
648 */
649 while (qdf_likely((rxdma_mon_status_ring_entry =
650 hal_srng_src_peek(hal_soc, mon_status_srng))
651 && quota--)) {
652 uint32_t rx_buf_cookie;
653 qdf_nbuf_t status_nbuf;
654 struct dp_rx_desc *rx_desc;
655 uint8_t *status_buf;
656 qdf_dma_addr_t paddr;
657 uint64_t buf_addr;
658
659 buf_addr =
660 (HAL_RX_BUFFER_ADDR_31_0_GET(
661 rxdma_mon_status_ring_entry) |
662 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
663 rxdma_mon_status_ring_entry)) << 32));
664
665 if (qdf_likely(buf_addr)) {
666
667 rx_buf_cookie =
668 HAL_RX_BUF_COOKIE_GET(
669 rxdma_mon_status_ring_entry);
670 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
671 rx_buf_cookie);
672
673 qdf_assert(rx_desc);
674
675 status_nbuf = rx_desc->nbuf;
676
677 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
678 QDF_DMA_FROM_DEVICE);
679
680 status_buf = qdf_nbuf_data(status_nbuf);
681
682 status = hal_get_rx_status_done(status_buf);
683
684 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800685 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700686 hal_get_sw_hptp(hal_soc, mon_status_srng,
687 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800688 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800689 QDF_TRACE_LEVEL_ERROR,
690 "[%s][%d] status not done - hp:%u, tp:%u",
691 __func__, __LINE__, hp, tp);
692 /* WAR for missing status: Skip status entry */
693 hal_srng_src_get_next(hal_soc, mon_status_srng);
694 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800695 }
696 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
697
698 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
699 QDF_DMA_FROM_DEVICE);
700
701 /* Put the status_nbuf to queue */
702 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
703
704 } else {
705 union dp_rx_desc_list_elem_t *desc_list = NULL;
706 union dp_rx_desc_list_elem_t *tail = NULL;
707 struct rx_desc_pool *rx_desc_pool;
708 uint32_t num_alloc_desc;
709
710 rx_desc_pool = &soc->rx_desc_status[mac_id];
711
712 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
713 rx_desc_pool,
714 1,
715 &desc_list,
716 &tail);
phadimanebf4cde2019-01-28 17:50:37 +0530717 /*
718 * No free descriptors available
719 */
720 if (qdf_unlikely(num_alloc_desc == 0)) {
721 work_done++;
722 break;
723 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800724
725 rx_desc = &desc_list->rx_desc;
726 }
727
jinweic chenc3546322018-02-02 15:03:41 +0800728 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800729
jinweic chenc3546322018-02-02 15:03:41 +0800730 /*
731 * qdf_nbuf alloc or map failed,
732 * free the dp rx desc to free list,
733 * fill in NULL dma address at current HP entry,
734 * keep HP in mon_status_ring unchanged,
735 * wait next time dp_rx_mon_status_srng_process
736 * to fill in buffer at current HP.
737 */
738 if (qdf_unlikely(status_nbuf == NULL)) {
739 union dp_rx_desc_list_elem_t *desc_list = NULL;
740 union dp_rx_desc_list_elem_t *tail = NULL;
741 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800742
jinweic chenc3546322018-02-02 15:03:41 +0800743 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800744
jinweic chenc3546322018-02-02 15:03:41 +0800745 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
746 "%s: fail to allocate or map qdf_nbuf",
747 __func__);
748 dp_rx_add_to_free_desc_list(&desc_list,
749 &tail, rx_desc);
750 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
751 &tail, mac_id, rx_desc_pool);
752
753 hal_rxdma_buff_addr_info_set(
754 rxdma_mon_status_ring_entry,
755 0, 0, HAL_RX_BUF_RBM_SW3_BM);
756 work_done++;
757 break;
758 }
759
Kai Chen6eca1a62017-01-12 10:17:53 -0800760 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
761
762 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700763 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800764
765 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
766 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
767
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800768 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800769 work_done++;
770 }
771done:
772
773 hal_srng_access_end(hal_soc, mon_status_srng);
774
775 return work_done;
776
777}
778/*
779 * dp_rx_mon_status_process() - Process monitor status ring and
780 * TLV in status ring.
781 *
782 * @soc: core txrx main context
783 * @mac_id: mac_id which is one of 3 mac_ids
784 * @quota: No. of ring entry that can be serviced in one shot.
785
786 * Return: uint32_t: No. of ring entry that is processed.
787 */
788static inline uint32_t
789dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
790 uint32_t work_done;
791
792 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700793 quota -= work_done;
794 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800795
796 return work_done;
797}
798/**
799 * dp_mon_process() - Main monitor mode processing roution.
800 * This call monitor status ring process then monitor
801 * destination ring process.
802 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
803 * @soc: core txrx main context
804 * @mac_id: mac_id which is one of 3 mac_ids
805 * @quota: No. of status ring entry that can be serviced in one shot.
806
807 * Return: uint32_t: No. of ring entry that is processed.
808 */
809uint32_t
810dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700811 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800812}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700813
Kai Chen6eca1a62017-01-12 10:17:53 -0800814/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700815 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800816 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800817 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800818 *
819 * This function will detach DP RX status ring from
820 * main device context. will free DP Rx resources for
821 * status ring
822 *
823 * Return: QDF_STATUS_SUCCESS: success
824 * QDF_STATUS_E_RESOURCES: Error return
825 */
826QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800827dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800828{
Kai Chen6eca1a62017-01-12 10:17:53 -0800829 struct dp_soc *soc = pdev->soc;
830 struct rx_desc_pool *rx_desc_pool;
831
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800832 rx_desc_pool = &soc->rx_desc_status[mac_id];
833 if (rx_desc_pool->pool_size != 0)
834 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
Kai Chen6eca1a62017-01-12 10:17:53 -0800835
836 return QDF_STATUS_SUCCESS;
837}
838
839/*
840 * dp_rx_buffers_replenish() - replenish monitor status ring with
841 * rx nbufs called during dp rx
842 * monitor status ring initialization
843 *
844 * @soc: core txrx main context
845 * @mac_id: mac_id which is one of 3 mac_ids
846 * @dp_rxdma_srng: dp monitor status circular ring
847 * @rx_desc_pool; Pointer to Rx descriptor pool
848 * @num_req_buffers: number of buffer to be replenished
849 * @desc_list: list of descs if called from dp rx monitor status
850 * process or NULL during dp rx initialization or
851 * out of buffer interrupt
852 * @tail: tail of descs list
853 * @owner: who owns the nbuf (host, NSS etc...)
854 * Return: return success or failure
855 */
856static inline
857QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
858 uint32_t mac_id,
859 struct dp_srng *dp_rxdma_srng,
860 struct rx_desc_pool *rx_desc_pool,
861 uint32_t num_req_buffers,
862 union dp_rx_desc_list_elem_t **desc_list,
863 union dp_rx_desc_list_elem_t **tail,
864 uint8_t owner)
865{
866 uint32_t num_alloc_desc;
867 uint16_t num_desc_to_free = 0;
868 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800869 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800870 int sync_hw_ptr = 1;
871 qdf_dma_addr_t paddr;
872 qdf_nbuf_t rx_netbuf;
873 void *rxdma_ring_entry;
874 union dp_rx_desc_list_elem_t *next;
875 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800876 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800877
878 rxdma_srng = dp_rxdma_srng->hal_srng;
879
880 qdf_assert(rxdma_srng);
881
Houston Hoffmanae850c62017-08-11 16:47:50 -0700882 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530883 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800884 __func__, __LINE__, num_req_buffers);
885
886 /*
887 * if desc_list is NULL, allocate the descs from freelist
888 */
889 if (!(*desc_list)) {
890
891 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
892 rx_desc_pool,
893 num_req_buffers,
894 desc_list,
895 tail);
896
897 if (!num_alloc_desc) {
898 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530899 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800900 __func__, __LINE__);
901 return QDF_STATUS_E_NOMEM;
902 }
903
Houston Hoffmanae850c62017-08-11 16:47:50 -0700904 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530905 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800906 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700907
Kai Chen6eca1a62017-01-12 10:17:53 -0800908 num_req_buffers = num_alloc_desc;
909 }
910
911 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
912 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
913 rxdma_srng, sync_hw_ptr);
914
Houston Hoffmanae850c62017-08-11 16:47:50 -0700915 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530916 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800917 __func__, __LINE__, num_entries_avail);
918
919 if (num_entries_avail < num_req_buffers) {
920 num_desc_to_free = num_req_buffers - num_entries_avail;
921 num_req_buffers = num_entries_avail;
922 }
923
jinweic chenc3546322018-02-02 15:03:41 +0800924 while (count < num_req_buffers) {
925 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800926
jinweic chenc3546322018-02-02 15:03:41 +0800927 /*
928 * qdf_nbuf alloc or map failed,
929 * keep HP in mon_status_ring unchanged,
930 * wait dp_rx_mon_status_srng_process
931 * to fill in buffer at current HP.
932 */
933 if (qdf_unlikely(rx_netbuf == NULL)) {
934 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
935 "%s: qdf_nbuf allocate or map fail, count %d",
936 __func__, count);
937 break;
938 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800939
940 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
941
942 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700943 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
944 rxdma_srng);
945
946 if (qdf_unlikely(rxdma_ring_entry == NULL)) {
947 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530948 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700949 __func__, __LINE__, count);
950 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
951 QDF_DMA_BIDIRECTIONAL);
952 qdf_nbuf_free(rx_netbuf);
953 break;
954 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800955
956 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700957 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800958 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800959
Kai Chen6eca1a62017-01-12 10:17:53 -0800960 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
961 (*desc_list)->rx_desc.cookie, owner);
962
Karunakar Dasineni40555682017-03-26 22:44:39 -0700963 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700964 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530965 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800966 __func__, __LINE__, &(*desc_list)->rx_desc,
967 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800968 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800969
970 *desc_list = next;
971 }
972
973 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
974
Houston Hoffmanae850c62017-08-11 16:47:50 -0700975 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530976 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800977
Houston Hoffmanae850c62017-08-11 16:47:50 -0700978 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530979 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800980
Kai Chen6eca1a62017-01-12 10:17:53 -0800981 /*
982 * add any available free desc back to the free list
983 */
984 if (*desc_list) {
985 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
986 mac_id, rx_desc_pool);
987 }
988
989 return QDF_STATUS_SUCCESS;
990}
991/**
992 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
993 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700994 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -0800995 * This function will attach a DP RX monitor status ring into pDEV
996 * and replenish monitor status ring with buffer.
997 *
998 * Return: QDF_STATUS_SUCCESS: success
999 * QDF_STATUS_E_RESOURCES: Error return
1000 */
1001QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001002dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -08001003 struct dp_soc *soc = pdev->soc;
1004 union dp_rx_desc_list_elem_t *desc_list = NULL;
1005 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -08001006 struct dp_srng *mon_status_ring;
1007 uint32_t num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001008 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001009 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001010 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001011
Mohit Khanna70514992018-11-12 18:39:03 -08001012 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -08001013
Mohit Khanna70514992018-11-12 18:39:03 -08001014 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -08001015
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -08001016 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001017
Mohit Khanna70514992018-11-12 18:39:03 -08001018 dp_info("Mon RX Status Pool[%d] entries=%d",
1019 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001020
Mohit Khanna70514992018-11-12 18:39:03 -08001021 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1022 rx_desc_pool);
1023 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001024 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001025
Mohit Khanna70514992018-11-12 18:39:03 -08001026 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001027
Mohit Khanna70514992018-11-12 18:39:03 -08001028 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1029 mon_status_ring,
1030 rx_desc_pool,
1031 num_entries,
1032 &desc_list, &tail,
1033 HAL_RX_BUF_RBM_SW3_BM);
1034
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
1038 qdf_nbuf_queue_init(&pdev->rx_status_q);
1039
1040 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001041
Karunakar Dasineni40555682017-03-26 22:44:39 -07001042 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001043 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001044
Kai Chen783e0382018-01-25 16:29:08 -08001045 qdf_mem_zero(&pdev->rx_mon_stats,
1046 sizeof(pdev->rx_mon_stats));
1047
1048 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1049 &pdev->rx_mon_stats);
1050
Kai Chen6eca1a62017-01-12 10:17:53 -08001051 return QDF_STATUS_SUCCESS;
1052}