blob: 7c20de7a195c892df4fc0c977c3d5ce3409c3385 [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 Nataraj38a29562017-08-18 19:41:17 +053059 cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
nobelj9ab76e22018-02-13 18:10:54 -080060 cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
Anish Nataraj38a29562017-08-18 19:41:17 +053061 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
62 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053063 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
64 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
65 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +053066 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
67 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Keyur Parekh49cdc742018-05-09 10:59:03 -070068 if ((ppdu_info->rx_status.sgi == VHT_SGI_NYSM) &&
69 (ppdu_info->rx_status.preamble_type == HAL_RX_PKT_TYPE_11AC))
70 cdp_rx_ppdu->u.gi = CDP_SGI_0_4_US;
71 else
72 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj50347012018-03-06 21:12:45 +053073 cdp_rx_ppdu->u.ldpc = ppdu_info->rx_status.ldpc;
Anish Nataraj38a29562017-08-18 19:41:17 +053074 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +053075 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Anish Nataraj38a29562017-08-18 19:41:17 +053076 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +053077 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
78 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
nobeljd8039592018-03-13 16:59:42 -070079 cdp_rx_ppdu->beamformed = ppdu_info->rx_status.beamformed;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053080 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
81 cdp_rx_ppdu->udp_msdu_count +
82 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053083
Anish Nataraj57614da2018-02-07 23:04:24 +053084 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Pranita Solankeed0aba62018-01-12 19:14:31 +053085 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
86 cdp_rx_ppdu->is_ampdu = 1;
87 else
88 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053089
90 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +053091 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Soumya Bhat560f90c2018-03-30 13:53:26 +053092
93 ast_index = ppdu_info->rx_status.ast_index;
94 if (ast_index > (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
95 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
96 return;
97 }
98
99 ast_entry = soc->ast_table[ast_index];
100 if (!ast_entry) {
101 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
102 return;
103 }
104 peer = ast_entry->peer;
105 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
106 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
107 return;
108 }
109
110 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
111 peer->mac_addr.raw, DP_MAC_ADDR_LEN);
112 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
113 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Anish Nataraj38a29562017-08-18 19:41:17 +0530114}
115#else
116static inline void
Soumya Bhat560f90c2018-03-30 13:53:26 +0530117dp_rx_populate_cdp_indication_ppdu(struct dp_pdev *pdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530118 struct hal_rx_ppdu_info *ppdu_info,
119 qdf_nbuf_t ppdu_nbuf)
120{
121}
122#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530123/**
124 * dp_rx_stats_update() - Update per-peer statistics
125 * @soc: Datapath SOC handle
126 * @peer: Datapath peer handle
127 * @ppdu: PPDU Descriptor
128 *
129 * Return: None
130 */
131#ifdef FEATURE_PERPKT_INFO
ydb247452018-08-08 00:23:16 +0530132static inline void dp_rx_rate_stats_update(struct dp_peer *peer,
133 struct cdp_rx_indication_ppdu *ppdu)
134{
135 uint32_t ratekbps = 0;
136 uint32_t ppdu_rx_rate = 0;
137 uint32_t nss = 0;
138
139 if (!peer || !ppdu)
140 return;
141
142 if (ppdu->u.nss == 0)
143 nss = 0;
144 else
145 nss = ppdu->u.nss - 1;
146
147 ratekbps = dp_getrateindex(ppdu->u.mcs,
148 nss,
149 ppdu->u.preamble,
150 ppdu->u.bw);
151
152 if (!ratekbps)
153 return;
154
155 DP_STATS_UPD(peer, rx.last_rx_rate, ratekbps);
156 dp_ath_rate_lpf(peer->stats.rx.avg_rx_rate, ratekbps);
157 ppdu_rx_rate = dp_ath_rate_out(peer->stats.rx.avg_rx_rate);
158 DP_STATS_UPD(peer, rx.rnd_avg_rx_rate, ppdu_rx_rate);
159
160 if (peer->vdev)
161 peer->vdev->stats.rx.last_rx_rate = ratekbps;
162}
163
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530164static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
165 struct cdp_rx_indication_ppdu *ppdu)
166{
167 struct dp_pdev *pdev = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530168 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530169 uint16_t num_msdu;
170
171 mcs = ppdu->u.mcs;
172 preamble = ppdu->u.preamble;
173 num_msdu = ppdu->num_msdu;
174
175 if (!peer)
176 return;
177
178 pdev = peer->vdev->pdev;
179
Subhranil Choudhuryeea67382018-01-18 20:24:36 +0530180 dp_mark_peer_inact(peer, false);
181
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530182 if (soc->process_rx_status)
183 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530184
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530185 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530186
187 if ((preamble == DOT11_A) || (preamble == DOT11_B))
188 ppdu->u.nss = 1;
189
190 if (ppdu->u.nss)
191 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
192
Pranita Solankea12b4b32017-11-20 23:04:14 +0530193 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530194 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530195 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530196 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
197 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
198 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530199 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530200 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530201 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
202 DP_STATS_INCC(peer,
203 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530204 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530205 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530206 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530207 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
208 DP_STATS_INCC(peer,
209 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530210 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530211 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530212 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530213 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
214 DP_STATS_INCC(peer,
215 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530216 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530217 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530218 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530219 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
220 DP_STATS_INCC(peer,
221 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
222 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
223 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530224 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530225 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
226 DP_STATS_INCC(peer,
227 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
228 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530229 /*
230 * If invalid TID, it could be a non-qos frame, hence do not update
231 * any AC counters
232 */
233 ac = TID_TO_WME_AC(ppdu->tid);
234 if (ppdu->tid != HAL_TID_INVALID)
235 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
Amir Patel52c6b732018-08-03 12:13:22 +0530236 dp_peer_stats_notify(peer);
237 DP_STATS_UPD(peer, rx.last_rssi, ppdu->rssi);
Anish Nataraj28490c42018-01-19 19:34:54 +0530238
ydb247452018-08-08 00:23:16 +0530239 dp_rx_rate_stats_update(peer, ppdu);
240
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530241 if (soc->cdp_soc.ol_ops->update_dp_stats) {
Akshay Kosigi1a9c6d12018-04-26 00:54:23 +0530242 soc->cdp_soc.ol_ops->update_dp_stats(pdev->ctrl_pdev,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530243 &peer->stats, ppdu->peer_id,
244 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530245
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530246 }
247}
248#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530249
250/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530251 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530252 * @soc: core txrx main context
253 * @pdev: pdev strcuture
254 * @ppdu_info: structure for rx ppdu ring
255 *
256 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
257 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530258 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530259#ifdef FEATURE_PERPKT_INFO
260static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530261dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530262 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
263{
264 uint8_t size = 0;
265
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530266 if (ppdu_info->msdu_info.first_msdu_payload == NULL)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530267 return QDF_STATUS_SUCCESS;
268
Soumya Bhat2f54de22018-02-21 09:54:28 +0530269 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530270 return QDF_STATUS_SUCCESS;
271
Soumya Bhat2f54de22018-02-21 09:54:28 +0530272 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530273
Soumya Bhat2f54de22018-02-21 09:54:28 +0530274 /* Include 2 bytes of reserved space appended to the msdu payload */
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530275 size = (ppdu_info->msdu_info.first_msdu_payload -
276 qdf_nbuf_data(nbuf)) + 2;
277 ppdu_info->msdu_info.first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530278
279 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
280 return QDF_STATUS_SUCCESS;
281
Soumya Bhatdc8aca82018-03-13 14:10:24 +0530282 /* only retain RX MSDU payload in the skb */
283 qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) -
284 ppdu_info->msdu_info.payload_len);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530285 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
286 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
287 return QDF_STATUS_E_ALREADY;
288}
289#else
290static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530291dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530292 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
293{
294 return QDF_STATUS_SUCCESS;
295}
296#endif
297
298
299/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530300* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
301* @soc: core txrx main context
302* @pdev: pdev strcuture
303* @ppdu_info: structure for rx ppdu ring
304*
305* Return: none
306*/
307#ifdef FEATURE_PERPKT_INFO
308static inline void
309dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
310 struct hal_rx_ppdu_info *ppdu_info)
311{
312 qdf_nbuf_t ppdu_nbuf;
313 struct dp_peer *peer;
314 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
315
Anish Nataraj28490c42018-01-19 19:34:54 +0530316 /*
317 * Do not allocate if fcs error,
318 * ast idx invalid / fctl invalid
319 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530320 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
321 return;
322
Chaithanya Garrepalli95fc62f2018-07-24 18:52:27 +0530323 if (ppdu_info->nac_info.fc_valid &&
324 ppdu_info->nac_info.to_ds_flag &&
325 ppdu_info->nac_info.mac_addr2_valid) {
326 struct dp_neighbour_peer *peer = NULL;
327 uint8_t rssi = ppdu_info->rx_status.rssi_comb;
328
329 qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
330 if (pdev->neighbour_peers_added) {
331 TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
332 neighbour_peer_list_elem) {
333 if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr,
334 &ppdu_info->nac_info.mac_addr2,
335 DP_MAC_ADDR_LEN)) {
336 peer->rssi = rssi;
337 break;
338 }
339 }
340 }
341 qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
342 }
343
Soumya Bhat560f90c2018-03-30 13:53:26 +0530344 if (!pdev->mcopy_mode) {
345 if (!ppdu_info->rx_status.frame_control_info_valid)
346 return;
Anish Nataraj28490c42018-01-19 19:34:54 +0530347
Soumya Bhat560f90c2018-03-30 13:53:26 +0530348 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
349 return;
350 }
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530351 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530352 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
353 if (ppdu_nbuf) {
Soumya Bhat560f90c2018-03-30 13:53:26 +0530354 dp_rx_populate_cdp_indication_ppdu(pdev, ppdu_info, ppdu_nbuf);
Anish Nataraj38a29562017-08-18 19:41:17 +0530355 qdf_nbuf_put_tail(ppdu_nbuf,
356 sizeof(struct cdp_rx_indication_ppdu));
357 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
358
359 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
360 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530361 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530362 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
363 ppdu_nbuf, cdp_rx_ppdu->peer_id,
364 WDI_NO_VAL, pdev->pdev_id);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530365 } else if (pdev->mcopy_mode) {
366 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
367 ppdu_nbuf, HTT_INVALID_PEER,
368 WDI_NO_VAL, pdev->pdev_id);
369 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530370 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530371 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530372 }
373}
374#else
375static inline void
376dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
377 struct hal_rx_ppdu_info *ppdu_info)
378{
379}
380#endif
381
382/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800383* dp_rx_mon_status_process_tlv() - Process status TLV in status
384* buffer on Rx status Queue posted by status SRNG processing.
385* @soc: core txrx main context
386* @mac_id: mac_id which is one of 3 mac_ids _ring
387*
388* Return: none
389*/
390static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700391dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
392 uint32_t quota)
393{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800394 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800395 struct hal_rx_ppdu_info *ppdu_info;
396 qdf_nbuf_t status_nbuf;
397 uint8_t *rx_tlv;
398 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700399 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530400 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen783e0382018-01-25 16:29:08 -0800401 struct cdp_pdev_mon_stats *rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800402
Kai Chen6eca1a62017-01-12 10:17:53 -0800403 ppdu_info = &pdev->ppdu_info;
Kai Chen783e0382018-01-25 16:29:08 -0800404 rx_mon_stats = &pdev->rx_mon_stats;
Kai Chen6eca1a62017-01-12 10:17:53 -0800405
406 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
407 return;
408
409 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
410
411 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
412 rx_tlv = qdf_nbuf_data(status_nbuf);
413 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700414
Keyur Parekhfad6d082017-05-07 08:54:47 -0700415#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700416#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700417 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700418 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700419#endif
420#endif
Soumya Bhat2f54de22018-02-21 09:54:28 +0530421 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en) ||
422 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800423
Keyur Parekhfad6d082017-05-07 08:54:47 -0700424 do {
425 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
Balamurugan Mahalingamd0159642018-07-11 15:02:29 +0530426 ppdu_info, pdev->soc->hal_soc);
Kai Chen783e0382018-01-25 16:29:08 -0800427
428 dp_rx_mon_update_dbg_ppdu_stats(ppdu_info,
429 rx_mon_stats);
430
Keyur Parekhfad6d082017-05-07 08:54:47 -0700431 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800432
Keyur Parekhfad6d082017-05-07 08:54:47 -0700433 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
434 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800435
Keyur Parekhfad6d082017-05-07 08:54:47 -0700436 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
437 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530438
Soumya Bhat7422db82017-12-15 13:48:53 +0530439 if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530440 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530441 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530442 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530443 qdf_nbuf_free(status_nbuf);
444 } else {
445 qdf_nbuf_free(status_nbuf);
446 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800447
chenguo1b880462018-07-11 15:34:56 +0800448 if (tlv_status == HAL_TLV_STATUS_PPDU_NON_STD_DONE) {
449 dp_rx_mon_deliver_non_std(soc, mac_id);
450 } else if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen783e0382018-01-25 16:29:08 -0800451 rx_mon_stats->status_ppdu_done++;
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530452 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530453 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530454 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530455
nobelj1c31fee2018-03-21 11:47:05 -0700456 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
457 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700458 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800459 pdev->ppdu_info.com_info.last_ppdu_id =
460 pdev->ppdu_info.com_info.ppdu_id;
Kai Chen6eca1a62017-01-12 10:17:53 -0800461 }
462 }
463 return;
464}
465
466/*
467 * dp_rx_mon_status_srng_process() - Process monitor status ring
468 * post the status ring buffer to Rx status Queue for later
469 * processing when status ring is filled with status TLV.
470 * Allocate a new buffer to status ring if the filled buffer
471 * is posted.
472 *
473 * @soc: core txrx main context
474 * @mac_id: mac_id which is one of 3 mac_ids
475 * @quota: No. of ring entry that can be serviced in one shot.
476
477 * Return: uint32_t: No. of ring entry that is processed.
478 */
479static inline uint32_t
480dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
481 uint32_t quota)
482{
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800483 struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800484 void *hal_soc;
485 void *mon_status_srng;
486 void *rxdma_mon_status_ring_entry;
487 QDF_STATUS status;
488 uint32_t work_done = 0;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800489 int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800490
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800491 mon_status_srng = pdev->rxdma_mon_status_ring[mac_for_pdev].hal_srng;
Kai Chen6eca1a62017-01-12 10:17:53 -0800492
493 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700494 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
495
496 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530497 "%s %d : HAL Monitor Status Ring Init Failed -- %pK",
Houston Hoffman648a9182017-05-21 23:27:50 -0700498 __func__, __LINE__, mon_status_srng);
499 return work_done;
500 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800501
502 hal_soc = soc->hal_soc;
503
504 qdf_assert(hal_soc);
505
506 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
507 goto done;
508
509 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
510 * BUFFER_ADDR_INFO STRUCT
511 */
512 while (qdf_likely((rxdma_mon_status_ring_entry =
513 hal_srng_src_peek(hal_soc, mon_status_srng))
514 && quota--)) {
515 uint32_t rx_buf_cookie;
516 qdf_nbuf_t status_nbuf;
517 struct dp_rx_desc *rx_desc;
518 uint8_t *status_buf;
519 qdf_dma_addr_t paddr;
520 uint64_t buf_addr;
521
522 buf_addr =
523 (HAL_RX_BUFFER_ADDR_31_0_GET(
524 rxdma_mon_status_ring_entry) |
525 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
526 rxdma_mon_status_ring_entry)) << 32));
527
528 if (qdf_likely(buf_addr)) {
529
530 rx_buf_cookie =
531 HAL_RX_BUF_COOKIE_GET(
532 rxdma_mon_status_ring_entry);
533 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
534 rx_buf_cookie);
535
536 qdf_assert(rx_desc);
537
538 status_nbuf = rx_desc->nbuf;
539
540 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
541 QDF_DMA_FROM_DEVICE);
542
543 status_buf = qdf_nbuf_data(status_nbuf);
544
545 status = hal_get_rx_status_done(status_buf);
546
547 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800548 uint32_t hp, tp;
549 hal_api_get_tphp(hal_soc, mon_status_srng,
550 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800551 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800552 QDF_TRACE_LEVEL_ERROR,
553 "[%s][%d] status not done - hp:%u, tp:%u",
554 __func__, __LINE__, hp, tp);
555 /* WAR for missing status: Skip status entry */
556 hal_srng_src_get_next(hal_soc, mon_status_srng);
557 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800558 }
559 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
560
561 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
562 QDF_DMA_FROM_DEVICE);
563
564 /* Put the status_nbuf to queue */
565 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
566
567 } else {
568 union dp_rx_desc_list_elem_t *desc_list = NULL;
569 union dp_rx_desc_list_elem_t *tail = NULL;
570 struct rx_desc_pool *rx_desc_pool;
571 uint32_t num_alloc_desc;
572
573 rx_desc_pool = &soc->rx_desc_status[mac_id];
574
575 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
576 rx_desc_pool,
577 1,
578 &desc_list,
579 &tail);
580
581 rx_desc = &desc_list->rx_desc;
582 }
583
jinweic chenc3546322018-02-02 15:03:41 +0800584 status_nbuf = dp_rx_nbuf_prepare(soc, pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800585
jinweic chenc3546322018-02-02 15:03:41 +0800586 /*
587 * qdf_nbuf alloc or map failed,
588 * free the dp rx desc to free list,
589 * fill in NULL dma address at current HP entry,
590 * keep HP in mon_status_ring unchanged,
591 * wait next time dp_rx_mon_status_srng_process
592 * to fill in buffer at current HP.
593 */
594 if (qdf_unlikely(status_nbuf == NULL)) {
595 union dp_rx_desc_list_elem_t *desc_list = NULL;
596 union dp_rx_desc_list_elem_t *tail = NULL;
597 struct rx_desc_pool *rx_desc_pool;
Kai Chen6eca1a62017-01-12 10:17:53 -0800598
jinweic chenc3546322018-02-02 15:03:41 +0800599 rx_desc_pool = &soc->rx_desc_status[mac_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800600
jinweic chenc3546322018-02-02 15:03:41 +0800601 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
602 "%s: fail to allocate or map qdf_nbuf",
603 __func__);
604 dp_rx_add_to_free_desc_list(&desc_list,
605 &tail, rx_desc);
606 dp_rx_add_desc_list_to_free_list(soc, &desc_list,
607 &tail, mac_id, rx_desc_pool);
608
609 hal_rxdma_buff_addr_info_set(
610 rxdma_mon_status_ring_entry,
611 0, 0, HAL_RX_BUF_RBM_SW3_BM);
612 work_done++;
613 break;
614 }
615
Kai Chen6eca1a62017-01-12 10:17:53 -0800616 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
617
618 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700619 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800620
621 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
622 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
623
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800624 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800625 work_done++;
626 }
627done:
628
629 hal_srng_access_end(hal_soc, mon_status_srng);
630
631 return work_done;
632
633}
634/*
635 * dp_rx_mon_status_process() - Process monitor status ring and
636 * TLV in status ring.
637 *
638 * @soc: core txrx main context
639 * @mac_id: mac_id which is one of 3 mac_ids
640 * @quota: No. of ring entry that can be serviced in one shot.
641
642 * Return: uint32_t: No. of ring entry that is processed.
643 */
644static inline uint32_t
645dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
646 uint32_t work_done;
647
648 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700649 quota -= work_done;
650 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800651
652 return work_done;
653}
654/**
655 * dp_mon_process() - Main monitor mode processing roution.
656 * This call monitor status ring process then monitor
657 * destination ring process.
658 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
659 * @soc: core txrx main context
660 * @mac_id: mac_id which is one of 3 mac_ids
661 * @quota: No. of status ring entry that can be serviced in one shot.
662
663 * Return: uint32_t: No. of ring entry that is processed.
664 */
665uint32_t
666dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700667 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800668}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700669
Kai Chen6eca1a62017-01-12 10:17:53 -0800670/**
671 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
672 * @pdev: core txrx pdev context
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800673 * @mac_id: mac_id/pdev_id correspondinggly for MCL and WIN
Kai Chen6eca1a62017-01-12 10:17:53 -0800674 *
675 * This function will detach DP RX status ring from
676 * main device context. will free DP Rx resources for
677 * status ring
678 *
679 * Return: QDF_STATUS_SUCCESS: success
680 * QDF_STATUS_E_RESOURCES: Error return
681 */
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700682#ifndef QCA_WIFI_QCA6390
Kai Chen6eca1a62017-01-12 10:17:53 -0800683QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800684dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev, int mac_id)
Kai Chen6eca1a62017-01-12 10:17:53 -0800685{
Kai Chen6eca1a62017-01-12 10:17:53 -0800686 struct dp_soc *soc = pdev->soc;
687 struct rx_desc_pool *rx_desc_pool;
688
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800689 rx_desc_pool = &soc->rx_desc_status[mac_id];
690 if (rx_desc_pool->pool_size != 0)
691 dp_rx_desc_pool_free(soc, mac_id, rx_desc_pool);
Kai Chen6eca1a62017-01-12 10:17:53 -0800692
693 return QDF_STATUS_SUCCESS;
694}
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700695#endif
Kai Chen6eca1a62017-01-12 10:17:53 -0800696
697/*
698 * dp_rx_buffers_replenish() - replenish monitor status ring with
699 * rx nbufs called during dp rx
700 * monitor status ring initialization
701 *
702 * @soc: core txrx main context
703 * @mac_id: mac_id which is one of 3 mac_ids
704 * @dp_rxdma_srng: dp monitor status circular ring
705 * @rx_desc_pool; Pointer to Rx descriptor pool
706 * @num_req_buffers: number of buffer to be replenished
707 * @desc_list: list of descs if called from dp rx monitor status
708 * process or NULL during dp rx initialization or
709 * out of buffer interrupt
710 * @tail: tail of descs list
711 * @owner: who owns the nbuf (host, NSS etc...)
712 * Return: return success or failure
713 */
714static inline
715QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
716 uint32_t mac_id,
717 struct dp_srng *dp_rxdma_srng,
718 struct rx_desc_pool *rx_desc_pool,
719 uint32_t num_req_buffers,
720 union dp_rx_desc_list_elem_t **desc_list,
721 union dp_rx_desc_list_elem_t **tail,
722 uint8_t owner)
723{
724 uint32_t num_alloc_desc;
725 uint16_t num_desc_to_free = 0;
726 uint32_t num_entries_avail;
jinweic chenc3546322018-02-02 15:03:41 +0800727 uint32_t count = 0;
Kai Chen6eca1a62017-01-12 10:17:53 -0800728 int sync_hw_ptr = 1;
729 qdf_dma_addr_t paddr;
730 qdf_nbuf_t rx_netbuf;
731 void *rxdma_ring_entry;
732 union dp_rx_desc_list_elem_t *next;
733 void *rxdma_srng;
jinweic chenc3546322018-02-02 15:03:41 +0800734 struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(dp_soc, mac_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800735
736 rxdma_srng = dp_rxdma_srng->hal_srng;
737
738 qdf_assert(rxdma_srng);
739
Houston Hoffmanae850c62017-08-11 16:47:50 -0700740 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530741 "[%s][%d] requested %d buffers for replenish",
Kai Chen6eca1a62017-01-12 10:17:53 -0800742 __func__, __LINE__, num_req_buffers);
743
744 /*
745 * if desc_list is NULL, allocate the descs from freelist
746 */
747 if (!(*desc_list)) {
748
749 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
750 rx_desc_pool,
751 num_req_buffers,
752 desc_list,
753 tail);
754
755 if (!num_alloc_desc) {
756 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530757 "[%s][%d] no free rx_descs in freelist",
Kai Chen6eca1a62017-01-12 10:17:53 -0800758 __func__, __LINE__);
759 return QDF_STATUS_E_NOMEM;
760 }
761
Houston Hoffmanae850c62017-08-11 16:47:50 -0700762 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530763 "[%s][%d] %d rx desc allocated", __func__, __LINE__,
Kai Chen6eca1a62017-01-12 10:17:53 -0800764 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700765
Kai Chen6eca1a62017-01-12 10:17:53 -0800766 num_req_buffers = num_alloc_desc;
767 }
768
769 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
770 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
771 rxdma_srng, sync_hw_ptr);
772
Houston Hoffmanae850c62017-08-11 16:47:50 -0700773 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530774 "[%s][%d] no of available entries in rxdma ring: %d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800775 __func__, __LINE__, num_entries_avail);
776
777 if (num_entries_avail < num_req_buffers) {
778 num_desc_to_free = num_req_buffers - num_entries_avail;
779 num_req_buffers = num_entries_avail;
780 }
781
jinweic chenc3546322018-02-02 15:03:41 +0800782 while (count < num_req_buffers) {
783 rx_netbuf = dp_rx_nbuf_prepare(dp_soc, dp_pdev);
Kai Chen6eca1a62017-01-12 10:17:53 -0800784
jinweic chenc3546322018-02-02 15:03:41 +0800785 /*
786 * qdf_nbuf alloc or map failed,
787 * keep HP in mon_status_ring unchanged,
788 * wait dp_rx_mon_status_srng_process
789 * to fill in buffer at current HP.
790 */
791 if (qdf_unlikely(rx_netbuf == NULL)) {
792 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
793 "%s: qdf_nbuf allocate or map fail, count %d",
794 __func__, count);
795 break;
796 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800797
798 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
799
800 next = (*desc_list)->next;
sumedh baikadyeca2de62018-04-11 14:20:38 -0700801 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
802 rxdma_srng);
803
804 if (qdf_unlikely(rxdma_ring_entry == NULL)) {
805 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530806 "[%s][%d] rxdma_ring_entry is NULL, count - %d",
sumedh baikadyeca2de62018-04-11 14:20:38 -0700807 __func__, __LINE__, count);
808 qdf_nbuf_unmap_single(dp_soc->osdev, rx_netbuf,
809 QDF_DMA_BIDIRECTIONAL);
810 qdf_nbuf_free(rx_netbuf);
811 break;
812 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800813
814 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700815 (*desc_list)->rx_desc.in_use = 1;
jinweic chenc3546322018-02-02 15:03:41 +0800816 count++;
jinweic chenc3546322018-02-02 15:03:41 +0800817
Kai Chen6eca1a62017-01-12 10:17:53 -0800818 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
819 (*desc_list)->rx_desc.cookie, owner);
820
Karunakar Dasineni40555682017-03-26 22:44:39 -0700821 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700822 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
Aditya Sathishded018e2018-07-02 16:25:21 +0530823 paddr=%pK",
Kai Chen6eca1a62017-01-12 10:17:53 -0800824 __func__, __LINE__, &(*desc_list)->rx_desc,
825 (*desc_list)->rx_desc.cookie, rx_netbuf,
jinweic chenc3546322018-02-02 15:03:41 +0800826 (void *)paddr);
Kai Chen6eca1a62017-01-12 10:17:53 -0800827
828 *desc_list = next;
829 }
830
831 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
832
Houston Hoffmanae850c62017-08-11 16:47:50 -0700833 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530834 "successfully replenished %d buffers", num_req_buffers);
Kai Chen6eca1a62017-01-12 10:17:53 -0800835
Houston Hoffmanae850c62017-08-11 16:47:50 -0700836 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530837 "%d rx desc added back to free list", num_desc_to_free);
Kai Chen6eca1a62017-01-12 10:17:53 -0800838
Houston Hoffmanae850c62017-08-11 16:47:50 -0700839 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathishded018e2018-07-02 16:25:21 +0530840 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d",
Kai Chen6eca1a62017-01-12 10:17:53 -0800841 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
842 (*desc_list)->rx_desc.cookie);
843
844 /*
845 * add any available free desc back to the free list
846 */
847 if (*desc_list) {
848 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
849 mac_id, rx_desc_pool);
850 }
851
852 return QDF_STATUS_SUCCESS;
853}
854/**
855 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
856 * @pdev: core txrx pdev context
857 *
858 * This function will attach a DP RX monitor status ring into pDEV
859 * and replenish monitor status ring with buffer.
860 *
861 * Return: QDF_STATUS_SUCCESS: success
862 * QDF_STATUS_E_RESOURCES: Error return
863 */
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700864#ifndef QCA_WIFI_QCA6390
Kai Chen6eca1a62017-01-12 10:17:53 -0800865QDF_STATUS
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800866dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev, int ring_id) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800867 struct dp_soc *soc = pdev->soc;
868 union dp_rx_desc_list_elem_t *desc_list = NULL;
869 union dp_rx_desc_list_elem_t *tail = NULL;
870 struct dp_srng *rxdma_srng;
871 uint32_t rxdma_entries;
872 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700873 QDF_STATUS status;
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800874 int mac_for_pdev = dp_get_mac_id_for_mac(soc, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800875
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800876 rxdma_srng = &pdev->rxdma_mon_status_ring[mac_for_pdev];
Kai Chen6eca1a62017-01-12 10:17:53 -0800877
878 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
879 soc->hal_soc, RXDMA_MONITOR_STATUS);
880
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800881 rx_desc_pool = &soc->rx_desc_status[ring_id];
Kai Chen6eca1a62017-01-12 10:17:53 -0800882
Houston Hoffman41b912c2017-08-30 14:27:51 -0700883 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Aditya Sathishded018e2018-07-02 16:25:21 +0530884 "%s: Mon RX Status Pool[%d] allocation size=%d",
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800885 __func__, ring_id, rxdma_entries);
Kai Chen6eca1a62017-01-12 10:17:53 -0800886
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800887 status = dp_rx_desc_pool_alloc(soc, ring_id, rxdma_entries+1,
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700888 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700889 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700890 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530891 "%s: dp_rx_desc_pool_alloc() failed ", __func__);
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700892 return status;
893 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800894
Houston Hoffman41b912c2017-08-30 14:27:51 -0700895 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Aditya Sathishded018e2018-07-02 16:25:21 +0530896 "%s: Mon RX Status Buffers Replenish ring_id=%d",
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800897 __func__, ring_id);
Kai Chen6eca1a62017-01-12 10:17:53 -0800898
Manjunathappa Prakashd9ce3502018-02-05 14:09:17 -0800899 status = dp_rx_mon_status_buffers_replenish(soc, ring_id, rxdma_srng,
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700900 rx_desc_pool, rxdma_entries, &desc_list, &tail,
901 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700902 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700903 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
Aditya Sathishded018e2018-07-02 16:25:21 +0530904 "%s: dp_rx_buffers_replenish() failed ", __func__);
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700905 return status;
906 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800907
908 qdf_nbuf_queue_init(&pdev->rx_status_q);
909
910 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800911 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Kai Chen783e0382018-01-25 16:29:08 -0800912
Karunakar Dasineni40555682017-03-26 22:44:39 -0700913 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
914 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800915
Kai Chen783e0382018-01-25 16:29:08 -0800916 qdf_mem_zero(&pdev->rx_mon_stats,
917 sizeof(pdev->rx_mon_stats));
918
919 dp_rx_mon_init_dbg_ppdu_stats(&pdev->ppdu_info,
920 &pdev->rx_mon_stats);
921
Kai Chen6eca1a62017-01-12 10:17:53 -0800922 return QDF_STATUS_SUCCESS;
923}
Venkata Sharath Chandra Manchala30e442b2018-06-26 12:29:24 -0700924#endif