blob: 113ef4aeb886db12d1adf6443251f3d0d105240c [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;
96 if (ast_index > (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
97 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
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530251 if (soc->cdp_soc.ol_ops->update_dp_stats) {
Akshay Kosigi1a9c6d12018-04-26 00:54:23 +0530252 soc->cdp_soc.ol_ops->update_dp_stats(pdev->ctrl_pdev,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530253 &peer->stats, ppdu->peer_id,
254 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530255
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530256 }
257}
258#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530259
260/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530261 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530262 * @soc: core txrx main context
263 * @pdev: pdev strcuture
264 * @ppdu_info: structure for rx ppdu ring
265 *
266 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
267 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530268 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530269#ifdef FEATURE_PERPKT_INFO
270static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530271dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530272 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
273{
274 uint8_t size = 0;
275
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530276 if (ppdu_info->msdu_info.first_msdu_payload == NULL)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530277 return QDF_STATUS_SUCCESS;
278
Soumya Bhat2f54de22018-02-21 09:54:28 +0530279 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530280 return QDF_STATUS_SUCCESS;
281
Soumya Bhat2f54de22018-02-21 09:54:28 +0530282 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530283
Soumya Bhat2f54de22018-02-21 09:54:28 +0530284 /* Include 2 bytes of reserved space appended to the msdu payload */
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530285 size = (ppdu_info->msdu_info.first_msdu_payload -
286 qdf_nbuf_data(nbuf)) + 2;
287 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530288
289 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
290 return QDF_STATUS_SUCCESS;
291
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530292 /* only retain RX MSDU payload in the skb */
293 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
294 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530295 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
296 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
297 return QDF_STATUS_E_ALREADY;
298}
299#else
300static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530301dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530302 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
303{
304 return QDF_STATUS_SUCCESS;
305}
306#endif
307
sumedh baikady59a2d332018-05-22 01:50:38 -0700308/**
309 * dp_rx_handle_smart_mesh_mode() - Deliver header for smart mesh
310 * @soc: Datapath SOC handle
311 * @pdev: Datapath PDEV handle
312 * @ppdu_info: Structure for rx ppdu info
313 * @nbuf: Qdf nbuf abstraction for linux skb
314 *
315 * Return: 0 on success, 1 on failure
316 */
317static inline int
318dp_rx_handle_smart_mesh_mode(struct dp_soc *soc, struct dp_pdev *pdev,
319 struct hal_rx_ppdu_info *ppdu_info,
320 qdf_nbuf_t nbuf)
321{
322 uint8_t size = 0;
323
324 if (!pdev->monitor_vdev) {
325 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
326 "[%s]:[%d] Monitor vdev is NULL !!",
327 __func__, __LINE__);
328 return 1;
329 }
330 if (ppdu_info->msdu_info.first_msdu_payload == NULL) {
331 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
332 "[%s]:[%d] First msdu payload not present",
333 __func__, __LINE__);
334 return 1;
335 }
336
337 /* Include 2 bytes of reserved space appended to the msdu payload */
338 size = (ppdu_info->msdu_info.first_msdu_payload -
339 qdf_nbuf_data(nbuf)) + 2;
340 ppdu_info->msdu_info.first_msdu_payload = NULL;
341
342 if (qdf_nbuf_pull_head(nbuf, size) == NULL) {
343 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
344 "[%s]:[%d] No header present",
345 __func__, __LINE__);
346 return 1;
347 }
348
349 /* only retain RX MSDU payload in the skb */
350 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
351 ppdu_info->msdu_info.payload_len);
352 qdf_nbuf_update_radiotap(&(pdev->ppdu_info.rx_status),
353 nbuf, sizeof(struct rx_pkt_tlvs));
354 pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
355 nbuf, NULL);
356
357 return 0;
358}
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530359
360/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530361* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
362* @soc: core txrx main context
363* @pdev: pdev strcuture
364* @ppdu_info: structure for rx ppdu ring
365*
366* Return: none
367*/
368#ifdef FEATURE_PERPKT_INFO
369static inline void
370dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
371 struct hal_rx_ppdu_info *ppdu_info)
372{
373 qdf_nbuf_t ppdu_nbuf;
374 struct dp_peer *peer;
375 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
376
Anish Nataraj28490c42018-01-19 19:34:54 +0530377 /*
378 * Do not allocate if fcs error,
379 * ast idx invalid / fctl invalid
380 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530381 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
382 return;
383
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530384 if (ppdu_info->nac_info.fc_valid &&
385 ppdu_info->nac_info.to_ds_flag &&
386 ppdu_info->nac_info.mac_addr2_valid) {
387 struct dp_neighbour_peer *peer = NULL;
388 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
389
390 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
391 if (pdev->neighbour_peers_added) {
392 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
393 neighbour_peer_list_elem) {
394 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
395 &ppdu_info->nac_info.mac_addr2,
396 DP_MAC_ADDR_LEN)) {
397 peer->rssi = rssi;
398 break;
399 }
400 }
401 }
402 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
403 }
404
Soumya Bhat560f90c2018-03-30 13:53:26 +0530405 if (!pdev->mcopy_mode) {
406 if (!ppdu_info->rx_status.frame_control_info_valid)
407 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530408
Soumya Bhat560f90c2018-03-30 13:53:26 +0530409 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
410 return;
411 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530412 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530413 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
414 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530415 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530416 qdf_nbuf_put_tail(ppdu_nbuf,
417 sizeof(struct cdp_rx_indication_ppdu));
418 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530419 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
Sravan Kumar Kairam26d471e2018-08-14 23:51:58 +0530420 if (cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Sravan Kumar Kairam26d471e2018-08-14 23:51:58 +0530421 if (peer) {
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530422 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
Sravan Kumar Kairam26d471e2018-08-14 23:51:58 +0530423 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC,
424 soc, ppdu_nbuf, cdp_rx_ppdu->peer_id,
Anish Nataraj38a29562017-08-18 19:41:17 +0530425 WDI_NO_VAL, pdev->pdev_id);
Sravan Kumar Kairam26d471e2018-08-14 23:51:58 +0530426 dp_peer_unref_del_find_by_id(peer);
427 }
Soumya Bhat2f54de22018-02-21 09:54:28 +0530428 } else if (pdev->mcopy_mode) {
Ruchi, Agrawal4c5ade62018-09-27 21:52:11 +0530429 dp_rx_stats_update(pdev, peer, cdp_rx_ppdu);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530430 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
431 ppdu_nbuf, HTT_INVALID_PEER,
432 WDI_NO_VAL, pdev->pdev_id);
433 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530434 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530435 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530436 }
437}
438#else
439static inline void
440dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
441 struct hal_rx_ppdu_info *ppdu_info)
442{
443}
444#endif
445
446/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800447* dp_rx_mon_status_process_tlv() - Process status TLV in status
448* buffer on Rx status Queue posted by status SRNG processing.
449* @soc: core txrx main context
450* @mac_id: mac_id which is one of 3 mac_ids _ring
451*
452* Return: none
453*/
454static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700455dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
456 uint32_t quota)
457{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800458 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800459 struct hal_rx_ppdu_info *ppdu_info;
460 qdf_nbuf_t status_nbuf;
461 uint8_t *rx_tlv;
462 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700463 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530464 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800465 struct cdp_pdev_mon_stats *rx_mon_stats;
sumedh baikady59a2d332018-05-22 01:50:38 -0700466 int smart_mesh_status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800467
Kai Chen6eca1a62017-01-12 10:17:53 -0800468 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800469 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800470
471 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
472 return;
473
474 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
475
476 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
477 rx_tlv = qdf_nbuf_data(status_nbuf);
478 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700479
Keyur Parekhfad6d082017-05-07 08:54:47 -0700480#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700481#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700482 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700483 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700484#endif
485#endif
Soumya Bhat2f54de22018-02-21 09:54:28 +0530486 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en) ||
487 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800488
Keyur Parekhfad6d082017-05-07 08:54:47 -0700489 do {
490 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530491 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800492
493 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
494 rx_mon_stats);
495
Keyur Parekhfad6d082017-05-07 08:54:47 -0700496 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800497
Keyur Parekhfad6d082017-05-07 08:54:47 -0700498 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
499 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800500
Keyur Parekhfad6d082017-05-07 08:54:47 -0700501 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
502 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530503
sumedh baikady59a2d332018-05-22 01:50:38 -0700504 if (ppdu_info->rx_status.monitor_direct_used && pdev->neighbour_peers_added
505 && pdev->monitor_vdev) {
506 smart_mesh_status = dp_rx_handle_smart_mesh_mode(soc,
507 pdev, ppdu_info, status_nbuf);
508 if (smart_mesh_status)
509 qdf_nbuf_free(status_nbuf);
510 }
Soumya Bhat7422db82017-12-15 13:48:53 +0530511 if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530512 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530513 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530514 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530515 qdf_nbuf_free(status_nbuf);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530516 }
sumedh baikady59a2d332018-05-22 01:50:38 -0700517 if (!pdev->neighbour_peers_added && !pdev->mcopy_mode)
518 qdf_nbuf_free(status_nbuf);
Kai Chen6eca1a62017-01-12 10:17:53 -0800519
chenguo1b880462018-07-11 15:34:56 +0800520 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
521 dp_rx_mon_deliver_non_std(soc, mac_id);
522 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800523 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530524 if (pdev->enhanced_stats_en ||
sumedh baikady59a2d332018-05-22 01:50:38 -0700525 pdev->mcopy_mode || pdev->neighbour_peers_added)
Anish Nataraj38a29562017-08-18 19:41:17 +0530526 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530527
nobelj1c31fee2018-03-21 11:47:05 -0700528 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
529 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700530 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800531 }
532 }
533 return;
534}
535
536/*
537 * dp_rx_mon_status_srng_process() - Process monitor status ring
538 * post the status ring buffer to Rx status Queue for later
539 * processing when status ring is filled with status TLV.
540 * Allocate a new buffer to status ring if the filled buffer
541 * is posted.
542 *
543 * @soc: core txrx main context
544 * @mac_id: mac_id which is one of 3 mac_ids
545 * @quota: No. of ring entry that can be serviced in one shot.
546
547 * Return: uint32_t: No. of ring entry that is processed.
548 */
549static inline uint32_t
550dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
551 uint32_t quota)
552{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800553 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800554 void *hal_soc;
555 void *mon_status_srng;
556 void *rxdma_mon_status_ring_entry;
557 QDF_STATUS status;
558 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800559 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800560
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800561 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800562
563 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700564 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
565
566 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530567 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700568 __func__, __LINE__, mon_status_srng);
569 return work_done;
570 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800571
572 hal_soc = soc->hal_soc;
573
574 qdf_assert(hal_soc);
575
576 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
577 goto done;
578
579 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
580 * BUFFER_ADDR_INFO STRUCT
581 */
582 while (qdf_likely((rxdma_mon_status_ring_entry =
583 hal_srng_src_peek(hal_soc, mon_status_srng))
584 && quota--)) {
585 uint32_t rx_buf_cookie;
586 qdf_nbuf_t status_nbuf;
587 struct dp_rx_desc *rx_desc;
588 uint8_t *status_buf;
589 qdf_dma_addr_t paddr;
590 uint64_t buf_addr;
591
592 buf_addr =
593 (HAL_RX_BUFFER_ADDR_31_0_GET(
594 rxdma_mon_status_ring_entry) |
595 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
596 rxdma_mon_status_ring_entry)) << 32));
597
598 if (qdf_likely(buf_addr)) {
599
600 rx_buf_cookie =
601 HAL_RX_BUF_COOKIE_GET(
602 rxdma_mon_status_ring_entry);
603 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
604 rx_buf_cookie);
605
606 qdf_assert(rx_desc);
607
608 status_nbuf = rx_desc->nbuf;
609
610 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
611 QDF_DMA_FROM_DEVICE);
612
613 status_buf = qdf_nbuf_data(status_nbuf);
614
615 status = hal_get_rx_status_done(status_buf);
616
617 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800618 uint32_t hp, tp;
619 hal_api_get_tphp(hal_soc, mon_status_srng,
620 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800621 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800622 QDF_TRACE_LEVEL_ERROR,
623 "[%s][%d] status not done - hp:%u, tp:%u",
624 __func__, __LINE__, hp, tp);
625 /* WAR for missing status: Skip status entry */
626 hal_srng_src_get_next(hal_soc, mon_status_srng);
627 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800628 }
629 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
630
631 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
632 QDF_DMA_FROM_DEVICE);
633
634 /* Put the status_nbuf to queue */
635 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
636
637 } else {
638 union dp_rx_desc_list_elem_t *desc_list = NULL;
639 union dp_rx_desc_list_elem_t *tail = NULL;
640 struct rx_desc_pool *rx_desc_pool;
641 uint32_t num_alloc_desc;
642
643 rx_desc_pool = &soc->rx_desc_status[mac_id];
644
645 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
646 rx_desc_pool,
647 1,
648 &desc_list,
649 &tail);
650
651 rx_desc = &desc_list->rx_desc;
652 }
653
jinweic chenc3546322018-02-02 15:03:41 +0800654 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800655
jinweic chenc3546322018-02-02 15:03:41 +0800656 /*
657 * qdf_nbuf alloc or map failed,
658 * free the dp rx desc to free list,
659 * fill in NULL dma address at current HP entry,
660 * keep HP in mon_status_ring unchanged,
661 * wait next time dp_rx_mon_status_srng_process
662 * to fill in buffer at current HP.
663 */
664 if (qdf_unlikely(status_nbuf == NULL)) {
665 union dp_rx_desc_list_elem_t *desc_list = NULL;
666 union dp_rx_desc_list_elem_t *tail = NULL;
667 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800668
jinweic chenc3546322018-02-02 15:03:41 +0800669 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800670
jinweic chenc3546322018-02-02 15:03:41 +0800671 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
672 "%s: fail to allocate or map qdf_nbuf",
673 __func__);
674 dp_rx_add_to_free_desc_list(&desc_list,
675 &tail, rx_desc);
676 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
677 &tail, mac_id, rx_desc_pool);
678
679 hal_rxdma_buff_addr_info_set(
680 rxdma_mon_status_ring_entry,
681 0, 0, HAL_RX_BUF_RBM_SW3_BM);
682 work_done++;
683 break;
684 }
685
Kai Chen6eca1a62017-01-12 10:17:53 -0800686 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
687
688 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700689 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800690
691 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
692 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
693
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800694 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800695 work_done++;
696 }
697done:
698
699 hal_srng_access_end(hal_soc, mon_status_srng);
700
701 return work_done;
702
703}
704/*
705 * dp_rx_mon_status_process() - Process monitor status ring and
706 * TLV in status ring.
707 *
708 * @soc: core txrx main context
709 * @mac_id: mac_id which is one of 3 mac_ids
710 * @quota: No. of ring entry that can be serviced in one shot.
711
712 * Return: uint32_t: No. of ring entry that is processed.
713 */
714static inline uint32_t
715dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
716 uint32_t work_done;
717
718 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700719 quota -= work_done;
720 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800721
722 return work_done;
723}
724/**
725 * dp_mon_process() - Main monitor mode processing roution.
726 * This call monitor status ring process then monitor
727 * destination ring process.
728 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
729 * @soc: core txrx main context
730 * @mac_id: mac_id which is one of 3 mac_ids
731 * @quota: No. of status ring entry that can be serviced in one shot.
732
733 * Return: uint32_t: No. of ring entry that is processed.
734 */
735uint32_t
736dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700737 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800738}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700739
Kai Chen6eca1a62017-01-12 10:17:53 -0800740/**
741 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
742 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800743 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800744 *
745 * This function will detach DP RX status ring from
746 * main device context. will free DP Rx resources for
747 * status ring
748 *
749 * Return: QDF_STATUS_SUCCESS: success
750 * QDF_STATUS_E_RESOURCES: Error return
751 */
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700752#ifndef QCA_WIFI_QCA6390
Kai Chen6eca1a62017-01-12 10:17:53 -0800753QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800754dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800755{
Kai Chen6eca1a62017-01-12 10:17:53 -0800756 struct dp_soc *soc = pdev->soc;
757 struct rx_desc_pool *rx_desc_pool;
758
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800759 rx_desc_pool = &soc->rx_desc_status[mac_id];
760 if (rx_desc_pool->pool_size != 0)
761 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
Kai Chen6eca1a62017-01-12 10:17:53 -0800762
763 return QDF_STATUS_SUCCESS;
764}
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700765#endif
Kai Chen6eca1a62017-01-12 10:17:53 -0800766
767/*
768 * dp_rx_buffers_replenish() - replenish monitor status ring with
769 * rx nbufs called during dp rx
770 * monitor status ring initialization
771 *
772 * @soc: core txrx main context
773 * @mac_id: mac_id which is one of 3 mac_ids
774 * @dp_rxdma_srng: dp monitor status circular ring
775 * @rx_desc_pool; Pointer to Rx descriptor pool
776 * @num_req_buffers: number of buffer to be replenished
777 * @desc_list: list of descs if called from dp rx monitor status
778 * process or NULL during dp rx initialization or
779 * out of buffer interrupt
780 * @tail: tail of descs list
781 * @owner: who owns the nbuf (host, NSS etc...)
782 * Return: return success or failure
783 */
784static inline
785QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
786 uint32_t mac_id,
787 struct dp_srng *dp_rxdma_srng,
788 struct rx_desc_pool *rx_desc_pool,
789 uint32_t num_req_buffers,
790 union dp_rx_desc_list_elem_t **desc_list,
791 union dp_rx_desc_list_elem_t **tail,
792 uint8_t owner)
793{
794 uint32_t num_alloc_desc;
795 uint16_t num_desc_to_free = 0;
796 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800797 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800798 int sync_hw_ptr = 1;
799 qdf_dma_addr_t paddr;
800 qdf_nbuf_t rx_netbuf;
801 void *rxdma_ring_entry;
802 union dp_rx_desc_list_elem_t *next;
803 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800804 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800805
806 rxdma_srng = dp_rxdma_srng->hal_srng;
807
808 qdf_assert(rxdma_srng);
809
Houston Hoffmanae850c62017-08-11 16:47:50 -0700810 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530811 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800812 __func__, __LINE__, num_req_buffers);
813
814 /*
815 * if desc_list is NULL, allocate the descs from freelist
816 */
817 if (!(*desc_list)) {
818
819 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
820 rx_desc_pool,
821 num_req_buffers,
822 desc_list,
823 tail);
824
825 if (!num_alloc_desc) {
826 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530827 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800828 __func__, __LINE__);
829 return QDF_STATUS_E_NOMEM;
830 }
831
Houston Hoffmanae850c62017-08-11 16:47:50 -0700832 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530833 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800834 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700835
Kai Chen6eca1a62017-01-12 10:17:53 -0800836 num_req_buffers = num_alloc_desc;
837 }
838
839 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
840 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
841 rxdma_srng, sync_hw_ptr);
842
Houston Hoffmanae850c62017-08-11 16:47:50 -0700843 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530844 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800845 __func__, __LINE__, num_entries_avail);
846
847 if (num_entries_avail < num_req_buffers) {
848 num_desc_to_free = num_req_buffers - num_entries_avail;
849 num_req_buffers = num_entries_avail;
850 }
851
jinweic chenc3546322018-02-02 15:03:41 +0800852 while (count < num_req_buffers) {
853 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800854
jinweic chenc3546322018-02-02 15:03:41 +0800855 /*
856 * qdf_nbuf alloc or map failed,
857 * keep HP in mon_status_ring unchanged,
858 * wait dp_rx_mon_status_srng_process
859 * to fill in buffer at current HP.
860 */
861 if (qdf_unlikely(rx_netbuf == NULL)) {
862 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
863 "%s: qdf_nbuf allocate or map fail, count %d",
864 __func__, count);
865 break;
866 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800867
868 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
869
870 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700871 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
872 rxdma_srng);
873
874 if (qdf_unlikely(rxdma_ring_entry == NULL)) {
875 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530876 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700877 __func__, __LINE__, count);
878 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
879 QDF_DMA_BIDIRECTIONAL);
880 qdf_nbuf_free(rx_netbuf);
881 break;
882 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800883
884 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700885 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800886 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800887
Kai Chen6eca1a62017-01-12 10:17:53 -0800888 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
889 (*desc_list)->rx_desc.cookie, owner);
890
Karunakar Dasineni40555682017-03-26 22:44:39 -0700891 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700892 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530893 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800894 __func__, __LINE__, &(*desc_list)->rx_desc,
895 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800896 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800897
898 *desc_list = next;
899 }
900
901 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
902
Houston Hoffmanae850c62017-08-11 16:47:50 -0700903 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530904 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800905
Houston Hoffmanae850c62017-08-11 16:47:50 -0700906 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530907 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800908
Houston Hoffmanae850c62017-08-11 16:47:50 -0700909 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530910 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800911 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
912 (*desc_list)->rx_desc.cookie);
913
914 /*
915 * add any available free desc back to the free list
916 */
917 if (*desc_list) {
918 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
919 mac_id, rx_desc_pool);
920 }
921
922 return QDF_STATUS_SUCCESS;
923}
924/**
925 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
926 * @pdev: core txrx pdev context
927 *
928 * This function will attach a DP RX monitor status ring into pDEV
929 * and replenish monitor status ring with buffer.
930 *
931 * Return: QDF_STATUS_SUCCESS: success
932 * QDF_STATUS_E_RESOURCES: Error return
933 */
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700934#ifndef QCA_WIFI_QCA6390
Kai Chen6eca1a62017-01-12 10:17:53 -0800935QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800936dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800937 struct dp_soc *soc = pdev->soc;
938 union dp_rx_desc_list_elem_t *desc_list = NULL;
939 union dp_rx_desc_list_elem_t *tail = NULL;
940 struct dp_srng *rxdma_srng;
941 uint32_t rxdma_entries;
942 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700943 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800944 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800945
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800946 rxdma_srng = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -0800947
948 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
949 soc->hal_soc, RXDMA_MONITOR_STATUS);
950
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800951 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800952
Houston Hoffman41b912c2017-08-30 14:27:51 -0700953 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Aditya Sathishded018e2018-07-02 16:25:21 +0530954 "%s: Mon RX Status Pool[%d] allocation size=%d",
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800955 __func__, ring_id, rxdma_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -0800956
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800957 status = dp_rx_desc_pool_alloc(soc, ring_id, rxdma_entries+1,
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700958 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700959 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700960 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530961 "%s: dp_rx_desc_pool_alloc() failed ", __func__);
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700962 return status;
963 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800964
Houston Hoffman41b912c2017-08-30 14:27:51 -0700965 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Aditya Sathishded018e2018-07-02 16:25:21 +0530966 "%s: Mon RX Status Buffers Replenish ring_id=%d",
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800967 __func__, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800968
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800969 status = dp_rx_mon_status_buffers_replenish(soc, ring_id, rxdma_srng,
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700970 rx_desc_pool, rxdma_entries, &desc_list, &tail,
971 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700972 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700973 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530974 "%s: dp_rx_buffers_replenish() failed ", __func__);
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700975 return status;
976 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800977
978 qdf_nbuf_queue_init(&pdev->rx_status_q);
979
980 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen783e0382018-01-25 16:29:08 -0800981
Karunakar Dasineni40555682017-03-26 22:44:39 -0700982 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
983 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800984
Kai Chen783e0382018-01-25 16:29:08 -0800985 qdf_mem_zero(&pdev->rx_mon_stats,
986 sizeof(pdev->rx_mon_stats));
987
988 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
989 &pdev->rx_mon_stats);
990
Kai Chen6eca1a62017-01-12 10:17:53 -0800991 return QDF_STATUS_SUCCESS;
992}
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700993#endif