blob: 3a941bc52582c591bf1be94e921ee61baca2e6c2 [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 */
18#include "dp_types.h"
19#include "dp_rx.h"
20#include "dp_peer.h"
21#include "hal_rx.h"
22#include "hal_api.h"
23#include "qdf_trace.h"
24#include "qdf_nbuf.h"
25#include "hal_api_mon.h"
Kai Chen6eca1a62017-01-12 10:17:53 -080026#include "dp_rx_mon.h"
Keyur Parekhfad6d082017-05-07 08:54:47 -070027#include "dp_internal.h"
28#include "qdf_mem.h" /* qdf_mem_malloc,free */
Kai Chen6eca1a62017-01-12 10:17:53 -080029
Kai Chen6eca1a62017-01-12 10:17:53 -080030/**
Anish Nataraj38a29562017-08-18 19:41:17 +053031* dp_rx_populate_cdp_indication_ppdu() - Populate cdp rx indication structure
32* @soc: core txrx main context
33* @ppdu_info: ppdu info structure from ppdu ring
34* @ppdu_nbuf: qdf nbuf abstraction for linux skb
35*
36* Return: none
37*/
38#ifdef FEATURE_PERPKT_INFO
39static inline void
40dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
41 struct hal_rx_ppdu_info *ppdu_info,
42 qdf_nbuf_t ppdu_nbuf)
43{
44 struct dp_peer *peer;
45 struct dp_ast_entry *ast_entry;
46 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
47 uint32_t ast_index;
48
49 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
50
51 ast_index = ppdu_info->rx_status.ast_index;
52 if (ast_index > (WLAN_UMAC_PSOC_MAX_PEERS * 2)) {
53 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
54 return;
55 }
56
57 ast_entry = soc->ast_table[ast_index];
58 if (!ast_entry) {
59 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
60 return;
61 }
62 peer = ast_entry->peer;
63 if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
64 cdp_rx_ppdu->peer_id = HTT_INVALID_PEER;
65 return;
66 }
67
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +053068 qdf_mem_copy(cdp_rx_ppdu->mac_addr,
69 peer->mac_addr.raw, DP_MAC_ADDR_LEN);
70 cdp_rx_ppdu->first_data_seq_ctrl =
71 ppdu_info->rx_status.first_data_seq_ctrl;
Anish Nataraj38a29562017-08-18 19:41:17 +053072 cdp_rx_ppdu->peer_id = peer->peer_ids[0];
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +053073 cdp_rx_ppdu->vdev_id = peer->vdev->vdev_id;
Anish Nataraj38a29562017-08-18 19:41:17 +053074 cdp_rx_ppdu->ppdu_id = ppdu_info->com_info.ppdu_id;
75 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
76 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053077 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
78 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
79 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +053080 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
81 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Anish Nataraj072d8972018-01-09 18:23:33 +053082 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj38a29562017-08-18 19:41:17 +053083 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +053084 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Anish Nataraj38a29562017-08-18 19:41:17 +053085 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
86 cdp_rx_ppdu->timestamp = ppdu_info->com_info.ppdu_timestamp;
87 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_freq;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053088 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
89 cdp_rx_ppdu->udp_msdu_count +
90 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053091
92 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
93 cdp_rx_ppdu->is_ampdu = 1;
94 else
95 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053096
97 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj38a29562017-08-18 19:41:17 +053098}
99#else
100static inline void
101dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
102 struct hal_rx_ppdu_info *ppdu_info,
103 qdf_nbuf_t ppdu_nbuf)
104{
105}
106#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530107/**
108 * dp_rx_stats_update() - Update per-peer statistics
109 * @soc: Datapath SOC handle
110 * @peer: Datapath peer handle
111 * @ppdu: PPDU Descriptor
112 *
113 * Return: None
114 */
115#ifdef FEATURE_PERPKT_INFO
116static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
117 struct cdp_rx_indication_ppdu *ppdu)
118{
119 struct dp_pdev *pdev = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530120 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530121 uint16_t num_msdu;
122
123 mcs = ppdu->u.mcs;
124 preamble = ppdu->u.preamble;
125 num_msdu = ppdu->num_msdu;
126
127 if (!peer)
128 return;
129
130 pdev = peer->vdev->pdev;
131
Subhranil Choudhuryeea67382018-01-18 20:24:36 +0530132 dp_mark_peer_inact(peer, false);
133
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530134 if (soc->process_rx_status)
135 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530136
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530137 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530138
139 if ((preamble == DOT11_A) || (preamble == DOT11_B))
140 ppdu->u.nss = 1;
141
142 if (ppdu->u.nss)
143 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
144
Pranita Solankea12b4b32017-11-20 23:04:14 +0530145 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530146 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530147 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530148 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
149 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
150 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530151 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530152 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530153 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
154 DP_STATS_INCC(peer,
155 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530156 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530157 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530158 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530159 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
160 DP_STATS_INCC(peer,
161 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530162 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530163 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530164 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530165 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
166 DP_STATS_INCC(peer,
167 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530168 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530169 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530170 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530171 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
172 DP_STATS_INCC(peer,
173 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
174 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
175 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530176 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530177 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
178 DP_STATS_INCC(peer,
179 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
180 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530181 /*
182 * If invalid TID, it could be a non-qos frame, hence do not update
183 * any AC counters
184 */
185 ac = TID_TO_WME_AC(ppdu->tid);
186 if (ppdu->tid != HAL_TID_INVALID)
187 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
188
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530189 if (soc->cdp_soc.ol_ops->update_dp_stats) {
190 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
191 &peer->stats, ppdu->peer_id,
192 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530193
194 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530195 }
196}
197#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530198
199/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530200 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530201 * @soc: core txrx main context
202 * @pdev: pdev strcuture
203 * @ppdu_info: structure for rx ppdu ring
204 *
205 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
206 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530207 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530208#ifdef FEATURE_PERPKT_INFO
209static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530210dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530211 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
212{
213 uint8_t size = 0;
214
215 if (ppdu_info->first_msdu_payload == NULL)
216 return QDF_STATUS_SUCCESS;
217
218 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
219 return QDF_STATUS_SUCCESS;
220
221 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
222
223 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
224 ppdu_info->first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530225
226 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
227 return QDF_STATUS_SUCCESS;
228
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530229 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
230 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
231 return QDF_STATUS_E_ALREADY;
232}
233#else
234static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530235dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530236 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
237{
238 return QDF_STATUS_SUCCESS;
239}
240#endif
241
242
243/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530244* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
245* @soc: core txrx main context
246* @pdev: pdev strcuture
247* @ppdu_info: structure for rx ppdu ring
248*
249* Return: none
250*/
251#ifdef FEATURE_PERPKT_INFO
252static inline void
253dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
254 struct hal_rx_ppdu_info *ppdu_info)
255{
256 qdf_nbuf_t ppdu_nbuf;
257 struct dp_peer *peer;
258 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
259
Anish Nataraj28490c42018-01-19 19:34:54 +0530260 /*
261 * Do not allocate if fcs error,
262 * ast idx invalid / fctl invalid
263 */
264
265 if (!ppdu_info->rx_status.frame_control_info_valid)
266 return;
267
268 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
269 return;
270
271 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
272 return;
273
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530274 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530275 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
276 if (ppdu_nbuf) {
277 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
278 qdf_nbuf_put_tail(ppdu_nbuf,
279 sizeof(struct cdp_rx_indication_ppdu));
280 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
281
282 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
283 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530284 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530285 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
286 ppdu_nbuf, cdp_rx_ppdu->peer_id,
287 WDI_NO_VAL, pdev->pdev_id);
288 } else
289 qdf_nbuf_free(ppdu_nbuf);
290 }
291}
292#else
293static inline void
294dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
295 struct hal_rx_ppdu_info *ppdu_info)
296{
297}
298#endif
299
300/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800301* dp_rx_mon_status_process_tlv() - Process status TLV in status
302* buffer on Rx status Queue posted by status SRNG processing.
303* @soc: core txrx main context
304* @mac_id: mac_id which is one of 3 mac_ids _ring
305*
306* Return: none
307*/
308static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700309dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
310 uint32_t quota)
311{
Kai Chen6eca1a62017-01-12 10:17:53 -0800312 struct dp_pdev *pdev = soc->pdev_list[mac_id];
313 struct hal_rx_ppdu_info *ppdu_info;
314 qdf_nbuf_t status_nbuf;
315 uint8_t *rx_tlv;
316 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700317 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530318 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800319
Kai Chen6eca1a62017-01-12 10:17:53 -0800320 ppdu_info = &pdev->ppdu_info;
321
322 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
323 return;
324
325 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
326
327 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
328 rx_tlv = qdf_nbuf_data(status_nbuf);
329 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700330
Keyur Parekhfad6d082017-05-07 08:54:47 -0700331#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700332#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700333 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700334 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700335#endif
336#endif
Soumya Bhat7422db82017-12-15 13:48:53 +0530337 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800338
Keyur Parekhfad6d082017-05-07 08:54:47 -0700339 do {
340 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
341 ppdu_info);
342 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800343
Keyur Parekhfad6d082017-05-07 08:54:47 -0700344 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
345 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800346
Keyur Parekhfad6d082017-05-07 08:54:47 -0700347 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
348 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530349
Soumya Bhat7422db82017-12-15 13:48:53 +0530350 if (pdev->mcopy_mode) {
351 am_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530352 pdev, ppdu_info, status_nbuf);
353 if (am_copy_status == QDF_STATUS_SUCCESS)
354 qdf_nbuf_free(status_nbuf);
355 } else {
356 qdf_nbuf_free(status_nbuf);
357 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800358
359 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530360 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530361 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530362 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530363
Kai Chen6eca1a62017-01-12 10:17:53 -0800364 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700365 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700366 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800367 pdev->ppdu_info.com_info.last_ppdu_id =
368 pdev->ppdu_info.com_info.ppdu_id;
Kai Chen6eca1a62017-01-12 10:17:53 -0800369 }
370 }
371 return;
372}
373
374/*
375 * dp_rx_mon_status_srng_process() - Process monitor status ring
376 * post the status ring buffer to Rx status Queue for later
377 * processing when status ring is filled with status TLV.
378 * Allocate a new buffer to status ring if the filled buffer
379 * is posted.
380 *
381 * @soc: core txrx main context
382 * @mac_id: mac_id which is one of 3 mac_ids
383 * @quota: No. of ring entry that can be serviced in one shot.
384
385 * Return: uint32_t: No. of ring entry that is processed.
386 */
387static inline uint32_t
388dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
389 uint32_t quota)
390{
391 struct dp_pdev *pdev = soc->pdev_list[mac_id];
392 void *hal_soc;
393 void *mon_status_srng;
394 void *rxdma_mon_status_ring_entry;
395 QDF_STATUS status;
396 uint32_t work_done = 0;
397
Kai Chen6eca1a62017-01-12 10:17:53 -0800398 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
399
400 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700401 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
402
403 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700404 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700405 __func__, __LINE__, mon_status_srng);
406 return work_done;
407 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800408
409 hal_soc = soc->hal_soc;
410
411 qdf_assert(hal_soc);
412
413 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
414 goto done;
415
416 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
417 * BUFFER_ADDR_INFO STRUCT
418 */
419 while (qdf_likely((rxdma_mon_status_ring_entry =
420 hal_srng_src_peek(hal_soc, mon_status_srng))
421 && quota--)) {
422 uint32_t rx_buf_cookie;
423 qdf_nbuf_t status_nbuf;
424 struct dp_rx_desc *rx_desc;
425 uint8_t *status_buf;
426 qdf_dma_addr_t paddr;
427 uint64_t buf_addr;
428
429 buf_addr =
430 (HAL_RX_BUFFER_ADDR_31_0_GET(
431 rxdma_mon_status_ring_entry) |
432 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
433 rxdma_mon_status_ring_entry)) << 32));
434
435 if (qdf_likely(buf_addr)) {
436
437 rx_buf_cookie =
438 HAL_RX_BUF_COOKIE_GET(
439 rxdma_mon_status_ring_entry);
440 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
441 rx_buf_cookie);
442
443 qdf_assert(rx_desc);
444
445 status_nbuf = rx_desc->nbuf;
446
447 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
448 QDF_DMA_FROM_DEVICE);
449
450 status_buf = qdf_nbuf_data(status_nbuf);
451
452 status = hal_get_rx_status_done(status_buf);
453
454 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800455 uint32_t hp, tp;
456 hal_api_get_tphp(hal_soc, mon_status_srng,
457 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800458 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800459 QDF_TRACE_LEVEL_ERROR,
460 "[%s][%d] status not done - hp:%u, tp:%u",
461 __func__, __LINE__, hp, tp);
462 /* WAR for missing status: Skip status entry */
463 hal_srng_src_get_next(hal_soc, mon_status_srng);
464 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800465 }
466 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
467
468 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
469 QDF_DMA_FROM_DEVICE);
470
471 /* Put the status_nbuf to queue */
472 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
473
474 } else {
475 union dp_rx_desc_list_elem_t *desc_list = NULL;
476 union dp_rx_desc_list_elem_t *tail = NULL;
477 struct rx_desc_pool *rx_desc_pool;
478 uint32_t num_alloc_desc;
479
480 rx_desc_pool = &soc->rx_desc_status[mac_id];
481
482 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
483 rx_desc_pool,
484 1,
485 &desc_list,
486 &tail);
487
488 rx_desc = &desc_list->rx_desc;
489 }
490
491 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530492 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800493 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
494
495 status_buf = qdf_nbuf_data(status_nbuf);
496
497 hal_clear_rx_status_done(status_buf);
498
499 qdf_nbuf_map_single(soc->osdev, status_nbuf,
500 QDF_DMA_BIDIRECTIONAL);
501 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
502
503 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700504 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800505
506 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
507 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
508
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800509 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800510 work_done++;
511 }
512done:
513
514 hal_srng_access_end(hal_soc, mon_status_srng);
515
516 return work_done;
517
518}
519/*
520 * dp_rx_mon_status_process() - Process monitor status ring and
521 * TLV in status ring.
522 *
523 * @soc: core txrx main context
524 * @mac_id: mac_id which is one of 3 mac_ids
525 * @quota: No. of ring entry that can be serviced in one shot.
526
527 * Return: uint32_t: No. of ring entry that is processed.
528 */
529static inline uint32_t
530dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
531 uint32_t work_done;
532
533 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700534 quota -= work_done;
535 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800536
537 return work_done;
538}
539/**
540 * dp_mon_process() - Main monitor mode processing roution.
541 * This call monitor status ring process then monitor
542 * destination ring process.
543 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
544 * @soc: core txrx main context
545 * @mac_id: mac_id which is one of 3 mac_ids
546 * @quota: No. of status ring entry that can be serviced in one shot.
547
548 * Return: uint32_t: No. of ring entry that is processed.
549 */
550uint32_t
551dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700552 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800553}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700554
Kai Chen6eca1a62017-01-12 10:17:53 -0800555/**
556 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
557 * @pdev: core txrx pdev context
558 *
559 * This function will detach DP RX status ring from
560 * main device context. will free DP Rx resources for
561 * status ring
562 *
563 * Return: QDF_STATUS_SUCCESS: success
564 * QDF_STATUS_E_RESOURCES: Error return
565 */
566QDF_STATUS
567dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
568{
569 uint8_t pdev_id = pdev->pdev_id;
570 struct dp_soc *soc = pdev->soc;
571 struct rx_desc_pool *rx_desc_pool;
572
573 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700574 if (rx_desc_pool->pool_size != 0) {
575 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
576 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800577
578 return QDF_STATUS_SUCCESS;
579}
580
581/*
582 * dp_rx_buffers_replenish() - replenish monitor status ring with
583 * rx nbufs called during dp rx
584 * monitor status ring initialization
585 *
586 * @soc: core txrx main context
587 * @mac_id: mac_id which is one of 3 mac_ids
588 * @dp_rxdma_srng: dp monitor status circular ring
589 * @rx_desc_pool; Pointer to Rx descriptor pool
590 * @num_req_buffers: number of buffer to be replenished
591 * @desc_list: list of descs if called from dp rx monitor status
592 * process or NULL during dp rx initialization or
593 * out of buffer interrupt
594 * @tail: tail of descs list
595 * @owner: who owns the nbuf (host, NSS etc...)
596 * Return: return success or failure
597 */
598static inline
599QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
600 uint32_t mac_id,
601 struct dp_srng *dp_rxdma_srng,
602 struct rx_desc_pool *rx_desc_pool,
603 uint32_t num_req_buffers,
604 union dp_rx_desc_list_elem_t **desc_list,
605 union dp_rx_desc_list_elem_t **tail,
606 uint8_t owner)
607{
608 uint32_t num_alloc_desc;
609 uint16_t num_desc_to_free = 0;
610 uint32_t num_entries_avail;
611 uint32_t count;
612 int sync_hw_ptr = 1;
613 qdf_dma_addr_t paddr;
614 qdf_nbuf_t rx_netbuf;
615 void *rxdma_ring_entry;
616 union dp_rx_desc_list_elem_t *next;
617 void *rxdma_srng;
618 uint8_t *status_buf;
619
620 rxdma_srng = dp_rxdma_srng->hal_srng;
621
622 qdf_assert(rxdma_srng);
623
Houston Hoffmanae850c62017-08-11 16:47:50 -0700624 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800625 "[%s][%d] requested %d buffers for replenish\n",
626 __func__, __LINE__, num_req_buffers);
627
628 /*
629 * if desc_list is NULL, allocate the descs from freelist
630 */
631 if (!(*desc_list)) {
632
633 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
634 rx_desc_pool,
635 num_req_buffers,
636 desc_list,
637 tail);
638
639 if (!num_alloc_desc) {
640 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
641 "[%s][%d] no free rx_descs in freelist\n",
642 __func__, __LINE__);
643 return QDF_STATUS_E_NOMEM;
644 }
645
Houston Hoffmanae850c62017-08-11 16:47:50 -0700646 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800647 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
648 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700649
Kai Chen6eca1a62017-01-12 10:17:53 -0800650 num_req_buffers = num_alloc_desc;
651 }
652
653 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
654 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
655 rxdma_srng, sync_hw_ptr);
656
Houston Hoffmanae850c62017-08-11 16:47:50 -0700657 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800658 "[%s][%d] no of availble entries in rxdma ring: %d\n",
659 __func__, __LINE__, num_entries_avail);
660
661 if (num_entries_avail < num_req_buffers) {
662 num_desc_to_free = num_req_buffers - num_entries_avail;
663 num_req_buffers = num_entries_avail;
664 }
665
666 for (count = 0; count < num_req_buffers; count++) {
667 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
668 rxdma_srng);
669
670 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
671 RX_BUFFER_SIZE,
672 RX_BUFFER_RESERVATION,
673 RX_BUFFER_ALIGNMENT,
674 FALSE);
675
676 status_buf = qdf_nbuf_data(rx_netbuf);
677 hal_clear_rx_status_done(status_buf);
678
679 memset(status_buf, 0, RX_BUFFER_SIZE);
680
681 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
682 QDF_DMA_BIDIRECTIONAL);
683
684 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
685
686 next = (*desc_list)->next;
687
688 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700689 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800690 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
691 (*desc_list)->rx_desc.cookie, owner);
692
Karunakar Dasineni40555682017-03-26 22:44:39 -0700693 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700694 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
695 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800696 __func__, __LINE__, &(*desc_list)->rx_desc,
697 (*desc_list)->rx_desc.cookie, rx_netbuf,
698 status_buf, (void *)paddr);
699
700 *desc_list = next;
701 }
702
703 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
704
Houston Hoffmanae850c62017-08-11 16:47:50 -0700705 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800706 "successfully replenished %d buffers\n", num_req_buffers);
707
Houston Hoffmanae850c62017-08-11 16:47:50 -0700708 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800709 "%d rx desc added back to free list\n", num_desc_to_free);
710
Houston Hoffmanae850c62017-08-11 16:47:50 -0700711 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700712 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800713 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
714 (*desc_list)->rx_desc.cookie);
715
716 /*
717 * add any available free desc back to the free list
718 */
719 if (*desc_list) {
720 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
721 mac_id, rx_desc_pool);
722 }
723
724 return QDF_STATUS_SUCCESS;
725}
726/**
727 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
728 * @pdev: core txrx pdev context
729 *
730 * This function will attach a DP RX monitor status ring into pDEV
731 * and replenish monitor status ring with buffer.
732 *
733 * Return: QDF_STATUS_SUCCESS: success
734 * QDF_STATUS_E_RESOURCES: Error return
735 */
736QDF_STATUS
737dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
738 uint8_t pdev_id = pdev->pdev_id;
739 struct dp_soc *soc = pdev->soc;
740 union dp_rx_desc_list_elem_t *desc_list = NULL;
741 union dp_rx_desc_list_elem_t *tail = NULL;
742 struct dp_srng *rxdma_srng;
743 uint32_t rxdma_entries;
744 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700745 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800746
747 rxdma_srng = &pdev->rxdma_mon_status_ring;
748
749 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
750 soc->hal_soc, RXDMA_MONITOR_STATUS);
751
752 rx_desc_pool = &soc->rx_desc_status[pdev_id];
753
Houston Hoffman41b912c2017-08-30 14:27:51 -0700754 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800755 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
756 __func__, pdev_id, rxdma_entries);
757
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700758 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
759 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700760 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700761 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
762 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
763 return status;
764 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800765
Houston Hoffman41b912c2017-08-30 14:27:51 -0700766 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800767 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
768 __func__, pdev_id);
769
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700770 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
771 rx_desc_pool, rxdma_entries, &desc_list, &tail,
772 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700773 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700774 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
775 "%s: dp_rx_buffers_replenish() failed \n", __func__);
776 return status;
777 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800778
779 qdf_nbuf_queue_init(&pdev->rx_status_q);
780
781 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800782 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700783 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
784 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800785
786 return QDF_STATUS_SUCCESS;
787}