blob: 66ced11cbf5ce086e3468f567c117d3b9e003bd0 [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
132 if (soc->process_rx_status)
133 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530134
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530135 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530136
137 if ((preamble == DOT11_A) || (preamble == DOT11_B))
138 ppdu->u.nss = 1;
139
140 if (ppdu->u.nss)
141 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
142
Pranita Solankea12b4b32017-11-20 23:04:14 +0530143 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530144 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530145 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530146 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
147 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
148 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530149 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530150 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530151 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
152 DP_STATS_INCC(peer,
153 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530154 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530155 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530156 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530157 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
158 DP_STATS_INCC(peer,
159 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530160 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530161 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530162 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530163 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
164 DP_STATS_INCC(peer,
165 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530166 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530167 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530168 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530169 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
170 DP_STATS_INCC(peer,
171 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
172 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
173 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530174 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530175 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
176 DP_STATS_INCC(peer,
177 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
178 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530179 /*
180 * If invalid TID, it could be a non-qos frame, hence do not update
181 * any AC counters
182 */
183 ac = TID_TO_WME_AC(ppdu->tid);
184 if (ppdu->tid != HAL_TID_INVALID)
185 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
186
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530187 if (soc->cdp_soc.ol_ops->update_dp_stats) {
188 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
189 &peer->stats, ppdu->peer_id,
190 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530191
192 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530193 }
194}
195#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530196
197/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530198 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530199 * @soc: core txrx main context
200 * @pdev: pdev strcuture
201 * @ppdu_info: structure for rx ppdu ring
202 *
203 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
204 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530205 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530206#ifdef FEATURE_PERPKT_INFO
207static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530208dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530209 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
210{
211 uint8_t size = 0;
212
213 if (ppdu_info->first_msdu_payload == NULL)
214 return QDF_STATUS_SUCCESS;
215
216 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
217 return QDF_STATUS_SUCCESS;
218
219 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
220
221 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
222 ppdu_info->first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530223
224 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
225 return QDF_STATUS_SUCCESS;
226
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530227 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
228 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
229 return QDF_STATUS_E_ALREADY;
230}
231#else
232static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530233dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530234 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
235{
236 return QDF_STATUS_SUCCESS;
237}
238#endif
239
240
241/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530242* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
243* @soc: core txrx main context
244* @pdev: pdev strcuture
245* @ppdu_info: structure for rx ppdu ring
246*
247* Return: none
248*/
249#ifdef FEATURE_PERPKT_INFO
250static inline void
251dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
252 struct hal_rx_ppdu_info *ppdu_info)
253{
254 qdf_nbuf_t ppdu_nbuf;
255 struct dp_peer *peer;
256 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
257
Anish Nataraj28490c42018-01-19 19:34:54 +0530258 /*
259 * Do not allocate if fcs error,
260 * ast idx invalid / fctl invalid
261 */
262
263 if (!ppdu_info->rx_status.frame_control_info_valid)
264 return;
265
266 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
267 return;
268
269 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
270 return;
271
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530272 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530273 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
274 if (ppdu_nbuf) {
275 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
276 qdf_nbuf_put_tail(ppdu_nbuf,
277 sizeof(struct cdp_rx_indication_ppdu));
278 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
279
280 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
281 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530282 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530283 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
284 ppdu_nbuf, cdp_rx_ppdu->peer_id,
285 WDI_NO_VAL, pdev->pdev_id);
286 } else
287 qdf_nbuf_free(ppdu_nbuf);
288 }
289}
290#else
291static inline void
292dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
293 struct hal_rx_ppdu_info *ppdu_info)
294{
295}
296#endif
297
298/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800299* dp_rx_mon_status_process_tlv() - Process status TLV in status
300* buffer on Rx status Queue posted by status SRNG processing.
301* @soc: core txrx main context
302* @mac_id: mac_id which is one of 3 mac_ids _ring
303*
304* Return: none
305*/
306static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700307dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
308 uint32_t quota)
309{
Kai Chen6eca1a62017-01-12 10:17:53 -0800310 struct dp_pdev *pdev = soc->pdev_list[mac_id];
311 struct hal_rx_ppdu_info *ppdu_info;
312 qdf_nbuf_t status_nbuf;
313 uint8_t *rx_tlv;
314 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700315 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530316 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800317
Kai Chen6eca1a62017-01-12 10:17:53 -0800318 ppdu_info = &pdev->ppdu_info;
319
320 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
321 return;
322
323 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
324
325 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
326 rx_tlv = qdf_nbuf_data(status_nbuf);
327 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700328
Keyur Parekhfad6d082017-05-07 08:54:47 -0700329#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700330#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700331 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700332 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700333#endif
334#endif
Soumya Bhat7422db82017-12-15 13:48:53 +0530335 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800336
Keyur Parekhfad6d082017-05-07 08:54:47 -0700337 do {
338 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
339 ppdu_info);
340 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800341
Keyur Parekhfad6d082017-05-07 08:54:47 -0700342 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
343 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800344
Keyur Parekhfad6d082017-05-07 08:54:47 -0700345 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
346 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530347
Soumya Bhat7422db82017-12-15 13:48:53 +0530348 if (pdev->mcopy_mode) {
349 am_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530350 pdev, ppdu_info, status_nbuf);
351 if (am_copy_status == QDF_STATUS_SUCCESS)
352 qdf_nbuf_free(status_nbuf);
353 } else {
354 qdf_nbuf_free(status_nbuf);
355 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800356
357 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530358 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530359 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530360 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530361
Kai Chen6eca1a62017-01-12 10:17:53 -0800362 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700363 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700364 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800365 pdev->ppdu_info.com_info.last_ppdu_id =
366 pdev->ppdu_info.com_info.ppdu_id;
Kai Chen6eca1a62017-01-12 10:17:53 -0800367 }
368 }
369 return;
370}
371
372/*
373 * dp_rx_mon_status_srng_process() - Process monitor status ring
374 * post the status ring buffer to Rx status Queue for later
375 * processing when status ring is filled with status TLV.
376 * Allocate a new buffer to status ring if the filled buffer
377 * is posted.
378 *
379 * @soc: core txrx main context
380 * @mac_id: mac_id which is one of 3 mac_ids
381 * @quota: No. of ring entry that can be serviced in one shot.
382
383 * Return: uint32_t: No. of ring entry that is processed.
384 */
385static inline uint32_t
386dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
387 uint32_t quota)
388{
389 struct dp_pdev *pdev = soc->pdev_list[mac_id];
390 void *hal_soc;
391 void *mon_status_srng;
392 void *rxdma_mon_status_ring_entry;
393 QDF_STATUS status;
394 uint32_t work_done = 0;
395
Kai Chen6eca1a62017-01-12 10:17:53 -0800396 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
397
398 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700399 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
400
401 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700402 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700403 __func__, __LINE__, mon_status_srng);
404 return work_done;
405 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800406
407 hal_soc = soc->hal_soc;
408
409 qdf_assert(hal_soc);
410
411 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
412 goto done;
413
414 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
415 * BUFFER_ADDR_INFO STRUCT
416 */
417 while (qdf_likely((rxdma_mon_status_ring_entry =
418 hal_srng_src_peek(hal_soc, mon_status_srng))
419 && quota--)) {
420 uint32_t rx_buf_cookie;
421 qdf_nbuf_t status_nbuf;
422 struct dp_rx_desc *rx_desc;
423 uint8_t *status_buf;
424 qdf_dma_addr_t paddr;
425 uint64_t buf_addr;
426
427 buf_addr =
428 (HAL_RX_BUFFER_ADDR_31_0_GET(
429 rxdma_mon_status_ring_entry) |
430 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
431 rxdma_mon_status_ring_entry)) << 32));
432
433 if (qdf_likely(buf_addr)) {
434
435 rx_buf_cookie =
436 HAL_RX_BUF_COOKIE_GET(
437 rxdma_mon_status_ring_entry);
438 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
439 rx_buf_cookie);
440
441 qdf_assert(rx_desc);
442
443 status_nbuf = rx_desc->nbuf;
444
445 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
446 QDF_DMA_FROM_DEVICE);
447
448 status_buf = qdf_nbuf_data(status_nbuf);
449
450 status = hal_get_rx_status_done(status_buf);
451
452 if (status != QDF_STATUS_SUCCESS) {
453 QDF_TRACE(QDF_MODULE_ID_DP,
454 QDF_TRACE_LEVEL_WARN,
455 "[%s][%d] status not done",
456 __func__, __LINE__);
457 break;
458 }
459 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
460
461 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
462 QDF_DMA_FROM_DEVICE);
463
464 /* Put the status_nbuf to queue */
465 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
466
467 } else {
468 union dp_rx_desc_list_elem_t *desc_list = NULL;
469 union dp_rx_desc_list_elem_t *tail = NULL;
470 struct rx_desc_pool *rx_desc_pool;
471 uint32_t num_alloc_desc;
472
473 rx_desc_pool = &soc->rx_desc_status[mac_id];
474
475 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
476 rx_desc_pool,
477 1,
478 &desc_list,
479 &tail);
480
481 rx_desc = &desc_list->rx_desc;
482 }
483
484 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530485 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800486 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
487
488 status_buf = qdf_nbuf_data(status_nbuf);
489
490 hal_clear_rx_status_done(status_buf);
491
492 qdf_nbuf_map_single(soc->osdev, status_nbuf,
493 QDF_DMA_BIDIRECTIONAL);
494 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
495
496 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700497 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800498
499 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
500 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
501
502 rxdma_mon_status_ring_entry =
503 hal_srng_src_get_next(hal_soc, mon_status_srng);
504 work_done++;
505 }
506done:
507
508 hal_srng_access_end(hal_soc, mon_status_srng);
509
510 return work_done;
511
512}
513/*
514 * dp_rx_mon_status_process() - Process monitor status ring and
515 * TLV in status ring.
516 *
517 * @soc: core txrx main context
518 * @mac_id: mac_id which is one of 3 mac_ids
519 * @quota: No. of ring entry that can be serviced in one shot.
520
521 * Return: uint32_t: No. of ring entry that is processed.
522 */
523static inline uint32_t
524dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
525 uint32_t work_done;
526
527 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700528 quota -= work_done;
529 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800530
531 return work_done;
532}
533/**
534 * dp_mon_process() - Main monitor mode processing roution.
535 * This call monitor status ring process then monitor
536 * destination ring process.
537 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
538 * @soc: core txrx main context
539 * @mac_id: mac_id which is one of 3 mac_ids
540 * @quota: No. of status ring entry that can be serviced in one shot.
541
542 * Return: uint32_t: No. of ring entry that is processed.
543 */
544uint32_t
545dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700546 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800547}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700548
Kai Chen6eca1a62017-01-12 10:17:53 -0800549/**
550 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
551 * @pdev: core txrx pdev context
552 *
553 * This function will detach DP RX status ring from
554 * main device context. will free DP Rx resources for
555 * status ring
556 *
557 * Return: QDF_STATUS_SUCCESS: success
558 * QDF_STATUS_E_RESOURCES: Error return
559 */
560QDF_STATUS
561dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
562{
563 uint8_t pdev_id = pdev->pdev_id;
564 struct dp_soc *soc = pdev->soc;
565 struct rx_desc_pool *rx_desc_pool;
566
567 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700568 if (rx_desc_pool->pool_size != 0) {
569 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
570 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800571
572 return QDF_STATUS_SUCCESS;
573}
574
575/*
576 * dp_rx_buffers_replenish() - replenish monitor status ring with
577 * rx nbufs called during dp rx
578 * monitor status ring initialization
579 *
580 * @soc: core txrx main context
581 * @mac_id: mac_id which is one of 3 mac_ids
582 * @dp_rxdma_srng: dp monitor status circular ring
583 * @rx_desc_pool; Pointer to Rx descriptor pool
584 * @num_req_buffers: number of buffer to be replenished
585 * @desc_list: list of descs if called from dp rx monitor status
586 * process or NULL during dp rx initialization or
587 * out of buffer interrupt
588 * @tail: tail of descs list
589 * @owner: who owns the nbuf (host, NSS etc...)
590 * Return: return success or failure
591 */
592static inline
593QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
594 uint32_t mac_id,
595 struct dp_srng *dp_rxdma_srng,
596 struct rx_desc_pool *rx_desc_pool,
597 uint32_t num_req_buffers,
598 union dp_rx_desc_list_elem_t **desc_list,
599 union dp_rx_desc_list_elem_t **tail,
600 uint8_t owner)
601{
602 uint32_t num_alloc_desc;
603 uint16_t num_desc_to_free = 0;
604 uint32_t num_entries_avail;
605 uint32_t count;
606 int sync_hw_ptr = 1;
607 qdf_dma_addr_t paddr;
608 qdf_nbuf_t rx_netbuf;
609 void *rxdma_ring_entry;
610 union dp_rx_desc_list_elem_t *next;
611 void *rxdma_srng;
612 uint8_t *status_buf;
613
614 rxdma_srng = dp_rxdma_srng->hal_srng;
615
616 qdf_assert(rxdma_srng);
617
Houston Hoffmanae850c62017-08-11 16:47:50 -0700618 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800619 "[%s][%d] requested %d buffers for replenish\n",
620 __func__, __LINE__, num_req_buffers);
621
622 /*
623 * if desc_list is NULL, allocate the descs from freelist
624 */
625 if (!(*desc_list)) {
626
627 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
628 rx_desc_pool,
629 num_req_buffers,
630 desc_list,
631 tail);
632
633 if (!num_alloc_desc) {
634 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
635 "[%s][%d] no free rx_descs in freelist\n",
636 __func__, __LINE__);
637 return QDF_STATUS_E_NOMEM;
638 }
639
Houston Hoffmanae850c62017-08-11 16:47:50 -0700640 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800641 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
642 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700643
Kai Chen6eca1a62017-01-12 10:17:53 -0800644 num_req_buffers = num_alloc_desc;
645 }
646
647 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
648 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
649 rxdma_srng, sync_hw_ptr);
650
Houston Hoffmanae850c62017-08-11 16:47:50 -0700651 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800652 "[%s][%d] no of availble entries in rxdma ring: %d\n",
653 __func__, __LINE__, num_entries_avail);
654
655 if (num_entries_avail < num_req_buffers) {
656 num_desc_to_free = num_req_buffers - num_entries_avail;
657 num_req_buffers = num_entries_avail;
658 }
659
660 for (count = 0; count < num_req_buffers; count++) {
661 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
662 rxdma_srng);
663
664 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
665 RX_BUFFER_SIZE,
666 RX_BUFFER_RESERVATION,
667 RX_BUFFER_ALIGNMENT,
668 FALSE);
669
670 status_buf = qdf_nbuf_data(rx_netbuf);
671 hal_clear_rx_status_done(status_buf);
672
673 memset(status_buf, 0, RX_BUFFER_SIZE);
674
675 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
676 QDF_DMA_BIDIRECTIONAL);
677
678 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
679
680 next = (*desc_list)->next;
681
682 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700683 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800684 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
685 (*desc_list)->rx_desc.cookie, owner);
686
Karunakar Dasineni40555682017-03-26 22:44:39 -0700687 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700688 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
689 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800690 __func__, __LINE__, &(*desc_list)->rx_desc,
691 (*desc_list)->rx_desc.cookie, rx_netbuf,
692 status_buf, (void *)paddr);
693
694 *desc_list = next;
695 }
696
697 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
698
Houston Hoffmanae850c62017-08-11 16:47:50 -0700699 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800700 "successfully replenished %d buffers\n", num_req_buffers);
701
Houston Hoffmanae850c62017-08-11 16:47:50 -0700702 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800703 "%d rx desc added back to free list\n", num_desc_to_free);
704
Houston Hoffmanae850c62017-08-11 16:47:50 -0700705 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700706 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800707 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
708 (*desc_list)->rx_desc.cookie);
709
710 /*
711 * add any available free desc back to the free list
712 */
713 if (*desc_list) {
714 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
715 mac_id, rx_desc_pool);
716 }
717
718 return QDF_STATUS_SUCCESS;
719}
720/**
721 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
722 * @pdev: core txrx pdev context
723 *
724 * This function will attach a DP RX monitor status ring into pDEV
725 * and replenish monitor status ring with buffer.
726 *
727 * Return: QDF_STATUS_SUCCESS: success
728 * QDF_STATUS_E_RESOURCES: Error return
729 */
730QDF_STATUS
731dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
732 uint8_t pdev_id = pdev->pdev_id;
733 struct dp_soc *soc = pdev->soc;
734 union dp_rx_desc_list_elem_t *desc_list = NULL;
735 union dp_rx_desc_list_elem_t *tail = NULL;
736 struct dp_srng *rxdma_srng;
737 uint32_t rxdma_entries;
738 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700739 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800740
741 rxdma_srng = &pdev->rxdma_mon_status_ring;
742
743 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
744 soc->hal_soc, RXDMA_MONITOR_STATUS);
745
746 rx_desc_pool = &soc->rx_desc_status[pdev_id];
747
Houston Hoffman41b912c2017-08-30 14:27:51 -0700748 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800749 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
750 __func__, pdev_id, rxdma_entries);
751
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700752 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
753 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700754 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700755 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
756 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
757 return status;
758 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800759
Houston Hoffman41b912c2017-08-30 14:27:51 -0700760 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800761 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
762 __func__, pdev_id);
763
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700764 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
765 rx_desc_pool, rxdma_entries, &desc_list, &tail,
766 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700767 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700768 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
769 "%s: dp_rx_buffers_replenish() failed \n", __func__);
770 return status;
771 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800772
773 qdf_nbuf_queue_init(&pdev->rx_status_q);
774
775 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800776 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700777 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
778 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800779
780 return QDF_STATUS_SUCCESS;
781}