blob: 8899b8c019fb2d867583ebb0ce94b536cc9ddfca [file] [log] [blame]
Kai Chen6eca1a62017-01-12 10:17:53 -08001/*
Pranita Solankeed0aba62018-01-12 19:14:31 +05302 * Copyright (c) 2017-2018 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;
phadiman49757302018-12-18 16:13:59 +053096 if (ast_index >= (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
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;
140
141 if (!peer || !ppdu)
142 return;
143
144 if (ppdu->u.nss == 0)
145 nss = 0;
146 else
147 nss = ppdu->u.nss - 1;
148
Anish Nataraj376d9b12018-08-13 14:12:01 +0530149 ratekbps = dp_getrateindex(ppdu->u.gi,
150 ppdu->u.mcs,
ydb247452018-08-08 00:23:16 +0530151 nss,
152 ppdu->u.preamble,
153 ppdu->u.bw);
154
155 if (!ratekbps)
156 return;
157
158 DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
159 dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
160 ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
161 DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
162
163 if (peer->vdev)
164 peer->vdev->stats.rx.last_rx_rate = ratekbps;
165}
166
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530167static void dp_rx_stats_update(struct dp_pdev *pdev, struct dp_peer *peer,
168 struct cdp_rx_indication_ppdu *ppdu)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530169{
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530170 struct dp_soc *soc = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530171 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530172 uint16_t num_msdu;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530173 bool is_invalid_peer = false;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530174
175 mcs = ppdu->u.mcs;
176 preamble = ppdu->u.preamble;
177 num_msdu = ppdu->num_msdu;
178
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530179 if (pdev)
180 soc = pdev->soc;
181 else
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530182 return;
183
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530184 if (!peer) {
185 is_invalid_peer = true;
186 peer = pdev->invalid_peer;
187 }
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530188
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530189 if (!soc || soc->process_rx_status)
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530190 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530191
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530192 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530193
194 if ((preamble == DOT11_A) || (preamble == DOT11_B))
195 ppdu->u.nss = 1;
196
197 if (ppdu->u.nss)
198 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
199
Pranita Solankea12b4b32017-11-20 23:04:14 +0530200 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530201 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530202 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530203 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
204 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
205 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530206 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530207 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530208 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
209 DP_STATS_INCC(peer,
210 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530211 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530212 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530213 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530214 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
215 DP_STATS_INCC(peer,
216 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530217 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530218 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530219 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530220 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
221 DP_STATS_INCC(peer,
222 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530223 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530224 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530225 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530226 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
227 DP_STATS_INCC(peer,
228 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
229 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
230 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530231 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530232 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
233 DP_STATS_INCC(peer,
234 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
235 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530236 /*
237 * If invalid TID, it could be a non-qos frame, hence do not update
238 * any AC counters
239 */
240 ac = TID_TO_WME_AC(ppdu->tid);
241 if (ppdu->tid != HAL_TID_INVALID)
242 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530243 dp_peer_stats_notify(peer);
244 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530245
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530246 if (is_invalid_peer)
247 return;
248
ydb247452018-08-08 00:23:16 +0530249 dp_rx_rate_stats_update(peer, ppdu);
250
Amir Patel756d05e2018-10-10 12:35:30 +0530251#if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
252 dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
253 &peer->stats, ppdu->peer_id,
254 UPDATE_PEER_STATS, pdev->pdev_id);
255#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530256}
257#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530258
259/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530260 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530261 * @soc: core txrx main context
262 * @pdev: pdev strcuture
263 * @ppdu_info: structure for rx ppdu ring
264 *
265 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
266 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530267 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530268#ifdef FEATURE_PERPKT_INFO
269static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530270dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530271 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
272{
273 uint8_t size = 0;
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530274 struct ieee80211_frame *wh;
275 uint32_t *nbuf_data;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530276
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530277 if (ppdu_info->msdu_info.first_msdu_payload == NULL)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530278 return QDF_STATUS_SUCCESS;
279
Soumya Bhat2f54de22018-02-21 09:54:28 +0530280 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530281 return QDF_STATUS_SUCCESS;
282
Soumya Bhat2f54de22018-02-21 09:54:28 +0530283 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530284
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530285 wh = (struct ieee80211_frame *)(ppdu_info->msdu_info.first_msdu_payload
286 + 4);
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530287 size = (ppdu_info->msdu_info.first_msdu_payload -
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530288 qdf_nbuf_data(nbuf));
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530289 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530290
291 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
292 return QDF_STATUS_SUCCESS;
293
Chaithanya Garrepalli7ab76ae2018-07-05 14:53:50 +0530294 if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
295 IEEE80211_FC0_TYPE_MGT) ||
296 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
297 IEEE80211_FC0_TYPE_CTL)) {
298 return QDF_STATUS_SUCCESS;
299 }
300
301 nbuf_data = (uint32_t *)qdf_nbuf_data(nbuf);
302 *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530303 /* only retain RX MSDU payload in the skb */
304 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
305 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530306 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
307 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
308 return QDF_STATUS_E_ALREADY;
309}
310#else
311static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530312dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530313 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
314{
315 return QDF_STATUS_SUCCESS;
316}
317#endif
318
sumedh baikady59a2d332018-05-22 01:50:38 -0700319/**
320 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
321 * @soc: Datapath SOC handle
322 * @pdev: Datapath PDEV handle
323 * @ppdu_info: Structure for rx ppdu info
324 * @nbuf: Qdf nbuf abstraction for linux skb
325 *
326 * Return: 0 on success, 1 on failure
327 */
328static inline int
329dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
330 struct hal_rx_ppdu_info *ppdu_info,
331 qdf_nbuf_t nbuf)
332{
333 uint8_t size = 0;
334
335 if (!pdev->monitor_vdev) {
336 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
337 "[%s]:[%d] Monitor vdev is NULL !!",
338 __func__, __LINE__);
339 return 1;
340 }
341 if (ppdu_info->msdu_info.first_msdu_payload == NULL) {
342 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
343 "[%s]:[%d] First msdu payload not present",
344 __func__, __LINE__);
345 return 1;
346 }
347
sumedh baikadyda159202018-11-01 17:31:23 -0700348 /* Adding 4 bytes to get to start of 802.11 frame after phy_ppdu_id */
sumedh baikady59a2d332018-05-22 01:50:38 -0700349 size = (ppdu_info->msdu_info.first_msdu_payload -
sumedh baikadyda159202018-11-01 17:31:23 -0700350 qdf_nbuf_data(nbuf)) + 4;
sumedh baikady59a2d332018-05-22 01:50:38 -0700351 ppdu_info->msdu_info.first_msdu_payload = NULL;
352
353 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
354 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
355 "[%s]:[%d] No header present",
356 __func__, __LINE__);
357 return 1;
358 }
359
sumedh baikadyda159202018-11-01 17:31:23 -0700360 /* Only retain RX MSDU payload in the skb */
sumedh baikady59a2d332018-05-22 01:50:38 -0700361 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
362 ppdu_info->msdu_info.payload_len);
363 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
364 nbuf, sizeof(struct rx_pkt_tlvs));
365 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
366 nbuf, NULL);
sumedh baikadyda159202018-11-01 17:31:23 -0700367 pdev->ppdu_info.rx_status.monitor_direct_used = 0;
sumedh baikady59a2d332018-05-22 01:50:38 -0700368 return 0;
369}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530370
371/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530372* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
373* @soc: core txrx main context
374* @pdev: pdev strcuture
375* @ppdu_info: structure for rx ppdu ring
376*
377* Return: none
378*/
379#ifdef FEATURE_PERPKT_INFO
380static inline void
381dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
382 struct hal_rx_ppdu_info *ppdu_info)
383{
384 qdf_nbuf_t ppdu_nbuf;
385 struct dp_peer *peer;
386 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
387
Anish Nataraj28490c42018-01-19 19:34:54 +0530388 /*
389 * Do not allocate if fcs error,
390 * ast idx invalid / fctl invalid
391 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530392 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
393 return;
394
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530395 if (ppdu_info->nac_info.fc_valid &&
396 ppdu_info->nac_info.to_ds_flag &&
397 ppdu_info->nac_info.mac_addr2_valid) {
398 struct dp_neighbour_peer *peer = NULL;
399 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
400
401 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
402 if (pdev->neighbour_peers_added) {
403 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
404 neighbour_peer_list_elem) {
405 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
406 &ppdu_info->nac_info.mac_addr2,
407 DP_MAC_ADDR_LEN)) {
408 peer->rssi = rssi;
409 break;
410 }
411 }
412 }
413 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
414 }
415
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530416 /* need not generate wdi event when mcopy and
417 * enhanced stats are not enabled
418 */
419 if (!pdev->mcopy_mode && !pdev->enhanced_stats_en)
420 return;
421
Soumya Bhat560f90c2018-03-30 13:53:26 +0530422 if (!pdev->mcopy_mode) {
423 if (!ppdu_info->rx_status.frame_control_info_valid)
424 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530425
Soumya Bhat560f90c2018-03-30 13:53:26 +0530426 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
427 return;
428 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530429 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530430 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
431 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530432 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530433 qdf_nbuf_put_tail(ppdu_nbuf,
434 sizeof(struct cdp_rx_indication_ppdu));
435 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530436 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
chenguob21a49a2018-11-19 19:17:12 +0800437 if (peer) {
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530438 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
chenguob21a49a2018-11-19 19:17:12 +0800439 dp_peer_unref_del_find_by_id(peer);
440 }
441 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
442 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
443 soc, ppdu_nbuf,
444 cdp_rx_ppdu->peer_id,
445 WDI_NO_VAL, pdev->pdev_id);
446 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530447 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
448 ppdu_nbuf, HTT_INVALID_PEER,
449 WDI_NO_VAL, pdev->pdev_id);
450 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530451 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530452 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530453 }
454}
455#else
456static inline void
457dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
458 struct hal_rx_ppdu_info *ppdu_info)
459{
460}
461#endif
462
463/**
Keyur Parekhc28f8392018-11-21 02:50:56 -0800464* dp_rx_process_peer_based_pktlog() - Process Rx pktlog if peer based
465* filtering enabled
466* @soc: core txrx main context
467* @ppdu_info: Structure for rx ppdu info
468* @status_nbuf: Qdf nbuf abstraction for linux skb
469* @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
470*
471* Return: none
472*/
473static inline void
474dp_rx_process_peer_based_pktlog(struct dp_soc *soc,
475 struct hal_rx_ppdu_info *ppdu_info,
476 qdf_nbuf_t status_nbuf, uint32_t mac_id)
477{
478 struct dp_peer *peer;
479 struct dp_ast_entry *ast_entry;
480 uint32_t ast_index;
481
482 ast_index = ppdu_info->rx_status.ast_index;
483 if (ast_index < (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
484 ast_entry = soc->ast_table[ast_index];
485 if (ast_entry) {
486 peer = ast_entry->peer;
487 if (peer && (peer->peer_ids[0] != HTT_INVALID_PEER)) {
488 if (peer->peer_based_pktlog_filter) {
489 dp_wdi_event_handler(
490 WDI_EVENT_RX_DESC, soc,
491 status_nbuf,
492 peer->peer_ids[0],
493 WDI_NO_VAL, mac_id);
494 }
495 }
496 }
497 }
498}
499
500/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800501* dp_rx_mon_status_process_tlv() - Process status TLV in status
502* buffer on Rx status Queue posted by status SRNG processing.
503* @soc: core txrx main context
504* @mac_id: mac_id which is one of 3 mac_ids _ring
505*
506* Return: none
507*/
508static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700509dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
510 uint32_t quota)
511{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800512 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800513 struct hal_rx_ppdu_info *ppdu_info;
514 qdf_nbuf_t status_nbuf;
515 uint8_t *rx_tlv;
516 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700517 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530518 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800519 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700520 int smart_mesh_status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800521
Kai Chen6eca1a62017-01-12 10:17:53 -0800522 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800523 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800524
525 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
526 return;
527
528 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
529
530 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
phadiman49757302018-12-18 16:13:59 +0530531
Kai Chen6eca1a62017-01-12 10:17:53 -0800532 rx_tlv = qdf_nbuf_data(status_nbuf);
533 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700534
Soumya Bhat2f54de22018-02-21 09:54:28 +0530535 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en) ||
536 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800537
Keyur Parekhfad6d082017-05-07 08:54:47 -0700538 do {
539 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530540 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800541
542 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
543 rx_mon_stats);
544
Keyur Parekhfad6d082017-05-07 08:54:47 -0700545 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800546
Keyur Parekhfad6d082017-05-07 08:54:47 -0700547 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
548 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800549
Keyur Parekhfad6d082017-05-07 08:54:47 -0700550 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
551 }
Keyur Parekhc28f8392018-11-21 02:50:56 -0800552 if (pdev->dp_peer_based_pktlog) {
553 dp_rx_process_peer_based_pktlog(soc, ppdu_info,
554 status_nbuf, mac_id);
555 } else {
556 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
557 status_nbuf, HTT_INVALID_PEER,
558 WDI_NO_VAL, mac_id);
559 }
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530560
561 /* smart monitor vap and m_copy cannot co-exist */
sumedh baikady59a2d332018-05-22 01:50:38 -0700562 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
563 && pdev->monitor_vdev) {
564 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
565 pdev, ppdu_info, status_nbuf);
566 if (smart_mesh_status)
567 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530568 } else if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530569 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530570 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530571 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530572 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530573 } else {
sumedh baikady59a2d332018-05-22 01:50:38 -0700574 qdf_nbuf_free(status_nbuf);
Chaithanya Garrepalli3e4ac1c2018-12-12 20:50:45 +0530575 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800576
chenguo1b880462018-07-11 15:34:56 +0800577 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
578 dp_rx_mon_deliver_non_std(soc, mac_id);
579 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800580 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530581 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700582 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530583 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530584
nobelj1c31fee2018-03-21 11:47:05 -0700585 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
586 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700587 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800588 }
589 }
590 return;
591}
592
593/*
594 * dp_rx_mon_status_srng_process() - Process monitor status ring
595 * post the status ring buffer to Rx status Queue for later
596 * processing when status ring is filled with status TLV.
597 * Allocate a new buffer to status ring if the filled buffer
598 * is posted.
599 *
600 * @soc: core txrx main context
601 * @mac_id: mac_id which is one of 3 mac_ids
602 * @quota: No. of ring entry that can be serviced in one shot.
603
604 * Return: uint32_t: No. of ring entry that is processed.
605 */
606static inline uint32_t
607dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
608 uint32_t quota)
609{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800610 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800611 void *hal_soc;
612 void *mon_status_srng;
613 void *rxdma_mon_status_ring_entry;
614 QDF_STATUS status;
615 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800616 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800617
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800618 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800619
620 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700621 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
622
623 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530624 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700625 __func__, __LINE__, mon_status_srng);
626 return work_done;
627 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800628
629 hal_soc = soc->hal_soc;
630
631 qdf_assert(hal_soc);
632
633 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
634 goto done;
635
636 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
637 * BUFFER_ADDR_INFO STRUCT
638 */
639 while (qdf_likely((rxdma_mon_status_ring_entry =
640 hal_srng_src_peek(hal_soc, mon_status_srng))
641 && quota--)) {
642 uint32_t rx_buf_cookie;
643 qdf_nbuf_t status_nbuf;
644 struct dp_rx_desc *rx_desc;
645 uint8_t *status_buf;
646 qdf_dma_addr_t paddr;
647 uint64_t buf_addr;
648
649 buf_addr =
650 (HAL_RX_BUFFER_ADDR_31_0_GET(
651 rxdma_mon_status_ring_entry) |
652 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
653 rxdma_mon_status_ring_entry)) << 32));
654
655 if (qdf_likely(buf_addr)) {
656
657 rx_buf_cookie =
658 HAL_RX_BUF_COOKIE_GET(
659 rxdma_mon_status_ring_entry);
660 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
661 rx_buf_cookie);
662
663 qdf_assert(rx_desc);
664
665 status_nbuf = rx_desc->nbuf;
666
667 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
668 QDF_DMA_FROM_DEVICE);
669
670 status_buf = qdf_nbuf_data(status_nbuf);
671
672 status = hal_get_rx_status_done(status_buf);
673
674 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800675 uint32_t hp, tp;
Venkata Sharath Chandra Manchala443b9b42018-10-10 12:04:54 -0700676 hal_get_sw_hptp(hal_soc, mon_status_srng,
677 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800678 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800679 QDF_TRACE_LEVEL_ERROR,
680 "[%s][%d] status not done - hp:%u, tp:%u",
681 __func__, __LINE__, hp, tp);
682 /* WAR for missing status: Skip status entry */
683 hal_srng_src_get_next(hal_soc, mon_status_srng);
684 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800685 }
686 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
687
688 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
689 QDF_DMA_FROM_DEVICE);
690
691 /* Put the status_nbuf to queue */
692 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
693
694 } else {
695 union dp_rx_desc_list_elem_t *desc_list = NULL;
696 union dp_rx_desc_list_elem_t *tail = NULL;
697 struct rx_desc_pool *rx_desc_pool;
698 uint32_t num_alloc_desc;
699
700 rx_desc_pool = &soc->rx_desc_status[mac_id];
701
702 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
703 rx_desc_pool,
704 1,
705 &desc_list,
706 &tail);
707
708 rx_desc = &desc_list->rx_desc;
709 }
710
jinweic chenc3546322018-02-02 15:03:41 +0800711 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800712
jinweic chenc3546322018-02-02 15:03:41 +0800713 /*
714 * qdf_nbuf alloc or map failed,
715 * free the dp rx desc to free list,
716 * fill in NULL dma address at current HP entry,
717 * keep HP in mon_status_ring unchanged,
718 * wait next time dp_rx_mon_status_srng_process
719 * to fill in buffer at current HP.
720 */
721 if (qdf_unlikely(status_nbuf == NULL)) {
722 union dp_rx_desc_list_elem_t *desc_list = NULL;
723 union dp_rx_desc_list_elem_t *tail = NULL;
724 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800725
jinweic chenc3546322018-02-02 15:03:41 +0800726 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800727
jinweic chenc3546322018-02-02 15:03:41 +0800728 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
729 "%s: fail to allocate or map qdf_nbuf",
730 __func__);
731 dp_rx_add_to_free_desc_list(&desc_list,
732 &tail, rx_desc);
733 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
734 &tail, mac_id, rx_desc_pool);
735
736 hal_rxdma_buff_addr_info_set(
737 rxdma_mon_status_ring_entry,
738 0, 0, HAL_RX_BUF_RBM_SW3_BM);
739 work_done++;
740 break;
741 }
742
Kai Chen6eca1a62017-01-12 10:17:53 -0800743 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
744
745 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700746 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800747
748 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
749 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
750
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800751 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800752 work_done++;
753 }
754done:
755
756 hal_srng_access_end(hal_soc, mon_status_srng);
757
758 return work_done;
759
760}
761/*
762 * dp_rx_mon_status_process() - Process monitor status ring and
763 * TLV in status ring.
764 *
765 * @soc: core txrx main context
766 * @mac_id: mac_id which is one of 3 mac_ids
767 * @quota: No. of ring entry that can be serviced in one shot.
768
769 * Return: uint32_t: No. of ring entry that is processed.
770 */
771static inline uint32_t
772dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
773 uint32_t work_done;
774
775 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700776 quota -= work_done;
777 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800778
779 return work_done;
780}
781/**
782 * dp_mon_process() - Main monitor mode processing roution.
783 * This call monitor status ring process then monitor
784 * destination ring process.
785 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
786 * @soc: core txrx main context
787 * @mac_id: mac_id which is one of 3 mac_ids
788 * @quota: No. of status ring entry that can be serviced in one shot.
789
790 * Return: uint32_t: No. of ring entry that is processed.
791 */
792uint32_t
793dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700794 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800795}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700796
Kai Chen6eca1a62017-01-12 10:17:53 -0800797/**
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700798 * dp_rx_pdev_mon_status_detach() - detach dp rx for status ring
Kai Chen6eca1a62017-01-12 10:17:53 -0800799 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800800 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800801 *
802 * This function will detach DP RX status ring from
803 * main device context. will free DP Rx resources for
804 * status ring
805 *
806 * Return: QDF_STATUS_SUCCESS: success
807 * QDF_STATUS_E_RESOURCES: Error return
808 */
809QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800810dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800811{
Kai Chen6eca1a62017-01-12 10:17:53 -0800812 struct dp_soc *soc = pdev->soc;
813 struct rx_desc_pool *rx_desc_pool;
814
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800815 rx_desc_pool = &soc->rx_desc_status[mac_id];
816 if (rx_desc_pool->pool_size != 0)
817 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
Kai Chen6eca1a62017-01-12 10:17:53 -0800818
819 return QDF_STATUS_SUCCESS;
820}
821
822/*
823 * dp_rx_buffers_replenish() - replenish monitor status ring with
824 * rx nbufs called during dp rx
825 * monitor status ring initialization
826 *
827 * @soc: core txrx main context
828 * @mac_id: mac_id which is one of 3 mac_ids
829 * @dp_rxdma_srng: dp monitor status circular ring
830 * @rx_desc_pool; Pointer to Rx descriptor pool
831 * @num_req_buffers: number of buffer to be replenished
832 * @desc_list: list of descs if called from dp rx monitor status
833 * process or NULL during dp rx initialization or
834 * out of buffer interrupt
835 * @tail: tail of descs list
836 * @owner: who owns the nbuf (host, NSS etc...)
837 * Return: return success or failure
838 */
839static inline
840QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
841 uint32_t mac_id,
842 struct dp_srng *dp_rxdma_srng,
843 struct rx_desc_pool *rx_desc_pool,
844 uint32_t num_req_buffers,
845 union dp_rx_desc_list_elem_t **desc_list,
846 union dp_rx_desc_list_elem_t **tail,
847 uint8_t owner)
848{
849 uint32_t num_alloc_desc;
850 uint16_t num_desc_to_free = 0;
851 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800852 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800853 int sync_hw_ptr = 1;
854 qdf_dma_addr_t paddr;
855 qdf_nbuf_t rx_netbuf;
856 void *rxdma_ring_entry;
857 union dp_rx_desc_list_elem_t *next;
858 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800859 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800860
861 rxdma_srng = dp_rxdma_srng->hal_srng;
862
863 qdf_assert(rxdma_srng);
864
Houston Hoffmanae850c62017-08-11 16:47:50 -0700865 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530866 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800867 __func__, __LINE__, num_req_buffers);
868
869 /*
870 * if desc_list is NULL, allocate the descs from freelist
871 */
872 if (!(*desc_list)) {
873
874 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
875 rx_desc_pool,
876 num_req_buffers,
877 desc_list,
878 tail);
879
880 if (!num_alloc_desc) {
881 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530882 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800883 __func__, __LINE__);
884 return QDF_STATUS_E_NOMEM;
885 }
886
Houston Hoffmanae850c62017-08-11 16:47:50 -0700887 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530888 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800889 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700890
Kai Chen6eca1a62017-01-12 10:17:53 -0800891 num_req_buffers = num_alloc_desc;
892 }
893
894 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
895 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
896 rxdma_srng, sync_hw_ptr);
897
Houston Hoffmanae850c62017-08-11 16:47:50 -0700898 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530899 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800900 __func__, __LINE__, num_entries_avail);
901
902 if (num_entries_avail < num_req_buffers) {
903 num_desc_to_free = num_req_buffers - num_entries_avail;
904 num_req_buffers = num_entries_avail;
905 }
906
jinweic chenc3546322018-02-02 15:03:41 +0800907 while (count < num_req_buffers) {
908 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800909
jinweic chenc3546322018-02-02 15:03:41 +0800910 /*
911 * qdf_nbuf alloc or map failed,
912 * keep HP in mon_status_ring unchanged,
913 * wait dp_rx_mon_status_srng_process
914 * to fill in buffer at current HP.
915 */
916 if (qdf_unlikely(rx_netbuf == NULL)) {
917 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
918 "%s: qdf_nbuf allocate or map fail, count %d",
919 __func__, count);
920 break;
921 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800922
923 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
924
925 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700926 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
927 rxdma_srng);
928
929 if (qdf_unlikely(rxdma_ring_entry == NULL)) {
930 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530931 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700932 __func__, __LINE__, count);
933 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
934 QDF_DMA_BIDIRECTIONAL);
935 qdf_nbuf_free(rx_netbuf);
936 break;
937 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800938
939 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700940 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800941 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800942
Kai Chen6eca1a62017-01-12 10:17:53 -0800943 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
944 (*desc_list)->rx_desc.cookie, owner);
945
Karunakar Dasineni40555682017-03-26 22:44:39 -0700946 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700947 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530948 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800949 __func__, __LINE__, &(*desc_list)->rx_desc,
950 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800951 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800952
953 *desc_list = next;
954 }
955
956 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
957
Houston Hoffmanae850c62017-08-11 16:47:50 -0700958 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530959 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800960
Houston Hoffmanae850c62017-08-11 16:47:50 -0700961 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530962 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800963
Kai Chen6eca1a62017-01-12 10:17:53 -0800964 /*
965 * add any available free desc back to the free list
966 */
967 if (*desc_list) {
968 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
969 mac_id, rx_desc_pool);
970 }
971
972 return QDF_STATUS_SUCCESS;
973}
974/**
975 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
976 * @pdev: core txrx pdev context
Venkata Sharath Chandra Manchala87479582018-08-01 12:45:34 -0700977 * @ring_id: ring number
Kai Chen6eca1a62017-01-12 10:17:53 -0800978 * This function will attach a DP RX monitor status ring into pDEV
979 * and replenish monitor status ring with buffer.
980 *
981 * Return: QDF_STATUS_SUCCESS: success
982 * QDF_STATUS_E_RESOURCES: Error return
983 */
984QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800985dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800986 struct dp_soc *soc = pdev->soc;
987 union dp_rx_desc_list_elem_t *desc_list = NULL;
988 union dp_rx_desc_list_elem_t *tail = NULL;
Mohit Khanna70514992018-11-12 18:39:03 -0800989 struct dp_srng *mon_status_ring;
990 uint32_t num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -0800991 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700992 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800993 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800994
Mohit Khanna70514992018-11-12 18:39:03 -0800995 mon_status_ring = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -0800996
Mohit Khanna70514992018-11-12 18:39:03 -0800997 num_entries = mon_status_ring->num_entries;
Kai Chen6eca1a62017-01-12 10:17:53 -0800998
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800999 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -08001000
Mohit Khanna70514992018-11-12 18:39:03 -08001001 dp_info("Mon RX Status Pool[%d] entries=%d",
1002 ring_id, num_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -08001003
Mohit Khanna70514992018-11-12 18:39:03 -08001004 status = dp_rx_desc_pool_alloc(soc, ring_id, num_entries + 1,
1005 rx_desc_pool);
1006 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001007 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001008
Mohit Khanna70514992018-11-12 18:39:03 -08001009 dp_debug("Mon RX Status Buffers Replenish ring_id=%d", ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -08001010
Mohit Khanna70514992018-11-12 18:39:03 -08001011 status = dp_rx_mon_status_buffers_replenish(soc, ring_id,
1012 mon_status_ring,
1013 rx_desc_pool,
1014 num_entries,
1015 &desc_list, &tail,
1016 HAL_RX_BUF_RBM_SW3_BM);
1017
1018 if (!QDF_IS_STATUS_SUCCESS(status))
Ravi Joshia9ebe0a2017-06-17 16:43:02 -07001019 return status;
Kai Chen6eca1a62017-01-12 10:17:53 -08001020
1021 qdf_nbuf_queue_init(&pdev->rx_status_q);
1022
1023 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -08001024
Karunakar Dasineni40555682017-03-26 22:44:39 -07001025 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
Mohit Khanna70514992018-11-12 18:39:03 -08001026 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -08001027
Kai Chen783e0382018-01-25 16:29:08 -08001028 qdf_mem_zero(&pdev->rx_mon_stats,
1029 sizeof(pdev->rx_mon_stats));
1030
1031 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
1032 &pdev->rx_mon_stats);
1033
Kai Chen6eca1a62017-01-12 10:17:53 -08001034 return QDF_STATUS_SUCCESS;
1035}