blob: f7130651efe042fe029485fbfd087178fe335065 [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;
84 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
85 cdp_rx_ppdu->timestamp = ppdu_info->com_info.ppdu_timestamp;
86 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_freq;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053087 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
88 cdp_rx_ppdu->udp_msdu_count +
89 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053090
91 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
92 cdp_rx_ppdu->is_ampdu = 1;
93 else
94 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053095
96 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj38a29562017-08-18 19:41:17 +053097}
98#else
99static inline void
100dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
101 struct hal_rx_ppdu_info *ppdu_info,
102 qdf_nbuf_t ppdu_nbuf)
103{
104}
105#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530106/**
107 * dp_rx_stats_update() - Update per-peer statistics
108 * @soc: Datapath SOC handle
109 * @peer: Datapath peer handle
110 * @ppdu: PPDU Descriptor
111 *
112 * Return: None
113 */
114#ifdef FEATURE_PERPKT_INFO
115static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
116 struct cdp_rx_indication_ppdu *ppdu)
117{
118 struct dp_pdev *pdev = NULL;
119 uint8_t mcs, preamble;
120 uint16_t num_msdu;
121
122 mcs = ppdu->u.mcs;
123 preamble = ppdu->u.preamble;
124 num_msdu = ppdu->num_msdu;
125
126 if (!peer)
127 return;
128
129 pdev = peer->vdev->pdev;
130
131 if (soc->process_rx_status)
132 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530133
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530134 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530135
136 if ((preamble == DOT11_A) || (preamble == DOT11_B))
137 ppdu->u.nss = 1;
138
139 if (ppdu->u.nss)
140 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
141
Pranita Solankea12b4b32017-11-20 23:04:14 +0530142 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530143 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530144 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
145 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
146 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530147 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530148 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530149 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
150 DP_STATS_INCC(peer,
151 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530152 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530153 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530154 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530155 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
156 DP_STATS_INCC(peer,
157 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530158 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530159 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530160 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530161 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
162 DP_STATS_INCC(peer,
163 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530164 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530165 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530166 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530167 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
168 DP_STATS_INCC(peer,
169 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
170 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
171 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530172 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530173 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
174 DP_STATS_INCC(peer,
175 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
176 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Pranita Solankea12b4b32017-11-20 23:04:14 +0530177 DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530178 if (soc->cdp_soc.ol_ops->update_dp_stats) {
179 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
180 &peer->stats, ppdu->peer_id,
181 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530182
183 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530184 }
185}
186#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530187
188/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530189 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530190 * @soc: core txrx main context
191 * @pdev: pdev strcuture
192 * @ppdu_info: structure for rx ppdu ring
193 *
194 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
195 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530196 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530197#ifdef FEATURE_PERPKT_INFO
198static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530199dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530200 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
201{
202 uint8_t size = 0;
203
204 if (ppdu_info->first_msdu_payload == NULL)
205 return QDF_STATUS_SUCCESS;
206
207 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
208 return QDF_STATUS_SUCCESS;
209
210 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
211
212 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
213 ppdu_info->first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530214
215 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
216 return QDF_STATUS_SUCCESS;
217
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530218 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
219 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
220 return QDF_STATUS_E_ALREADY;
221}
222#else
223static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530224dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530225 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
226{
227 return QDF_STATUS_SUCCESS;
228}
229#endif
230
231
232/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530233* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
234* @soc: core txrx main context
235* @pdev: pdev strcuture
236* @ppdu_info: structure for rx ppdu ring
237*
238* Return: none
239*/
240#ifdef FEATURE_PERPKT_INFO
241static inline void
242dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
243 struct hal_rx_ppdu_info *ppdu_info)
244{
245 qdf_nbuf_t ppdu_nbuf;
246 struct dp_peer *peer;
247 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
248
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530249 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530250 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
251 if (ppdu_nbuf) {
252 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
253 qdf_nbuf_put_tail(ppdu_nbuf,
254 sizeof(struct cdp_rx_indication_ppdu));
255 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
256
257 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
258 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530259 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530260 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
261 ppdu_nbuf, cdp_rx_ppdu->peer_id,
262 WDI_NO_VAL, pdev->pdev_id);
263 } else
264 qdf_nbuf_free(ppdu_nbuf);
265 }
266}
267#else
268static inline void
269dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
270 struct hal_rx_ppdu_info *ppdu_info)
271{
272}
273#endif
274
275/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800276* dp_rx_mon_status_process_tlv() - Process status TLV in status
277* buffer on Rx status Queue posted by status SRNG processing.
278* @soc: core txrx main context
279* @mac_id: mac_id which is one of 3 mac_ids _ring
280*
281* Return: none
282*/
283static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700284dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
285 uint32_t quota)
286{
Kai Chen6eca1a62017-01-12 10:17:53 -0800287 struct dp_pdev *pdev = soc->pdev_list[mac_id];
288 struct hal_rx_ppdu_info *ppdu_info;
289 qdf_nbuf_t status_nbuf;
290 uint8_t *rx_tlv;
291 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700292 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530293 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800294
Kai Chen6eca1a62017-01-12 10:17:53 -0800295 ppdu_info = &pdev->ppdu_info;
296
297 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
298 return;
299
300 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
301
302 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
303 rx_tlv = qdf_nbuf_data(status_nbuf);
304 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700305
Keyur Parekhfad6d082017-05-07 08:54:47 -0700306#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700307#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700308 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700309 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700310#endif
311#endif
Soumya Bhat7422db82017-12-15 13:48:53 +0530312 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800313
Keyur Parekhfad6d082017-05-07 08:54:47 -0700314 do {
315 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
316 ppdu_info);
317 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800318
Keyur Parekhfad6d082017-05-07 08:54:47 -0700319 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
320 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800321
Keyur Parekhfad6d082017-05-07 08:54:47 -0700322 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
323 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530324
Soumya Bhat7422db82017-12-15 13:48:53 +0530325 if (pdev->mcopy_mode) {
326 am_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530327 pdev, ppdu_info, status_nbuf);
328 if (am_copy_status == QDF_STATUS_SUCCESS)
329 qdf_nbuf_free(status_nbuf);
330 } else {
331 qdf_nbuf_free(status_nbuf);
332 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800333
334 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530335 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530336 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530337 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530338
Kai Chen6eca1a62017-01-12 10:17:53 -0800339 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700340 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700341 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800342 pdev->ppdu_info.com_info.last_ppdu_id =
343 pdev->ppdu_info.com_info.ppdu_id;
Kai Chen6eca1a62017-01-12 10:17:53 -0800344 }
345 }
346 return;
347}
348
349/*
350 * dp_rx_mon_status_srng_process() - Process monitor status ring
351 * post the status ring buffer to Rx status Queue for later
352 * processing when status ring is filled with status TLV.
353 * Allocate a new buffer to status ring if the filled buffer
354 * is posted.
355 *
356 * @soc: core txrx main context
357 * @mac_id: mac_id which is one of 3 mac_ids
358 * @quota: No. of ring entry that can be serviced in one shot.
359
360 * Return: uint32_t: No. of ring entry that is processed.
361 */
362static inline uint32_t
363dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
364 uint32_t quota)
365{
366 struct dp_pdev *pdev = soc->pdev_list[mac_id];
367 void *hal_soc;
368 void *mon_status_srng;
369 void *rxdma_mon_status_ring_entry;
370 QDF_STATUS status;
371 uint32_t work_done = 0;
372
Kai Chen6eca1a62017-01-12 10:17:53 -0800373 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
374
375 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700376 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
377
378 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700379 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700380 __func__, __LINE__, mon_status_srng);
381 return work_done;
382 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800383
384 hal_soc = soc->hal_soc;
385
386 qdf_assert(hal_soc);
387
388 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
389 goto done;
390
391 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
392 * BUFFER_ADDR_INFO STRUCT
393 */
394 while (qdf_likely((rxdma_mon_status_ring_entry =
395 hal_srng_src_peek(hal_soc, mon_status_srng))
396 && quota--)) {
397 uint32_t rx_buf_cookie;
398 qdf_nbuf_t status_nbuf;
399 struct dp_rx_desc *rx_desc;
400 uint8_t *status_buf;
401 qdf_dma_addr_t paddr;
402 uint64_t buf_addr;
403
404 buf_addr =
405 (HAL_RX_BUFFER_ADDR_31_0_GET(
406 rxdma_mon_status_ring_entry) |
407 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
408 rxdma_mon_status_ring_entry)) << 32));
409
410 if (qdf_likely(buf_addr)) {
411
412 rx_buf_cookie =
413 HAL_RX_BUF_COOKIE_GET(
414 rxdma_mon_status_ring_entry);
415 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
416 rx_buf_cookie);
417
418 qdf_assert(rx_desc);
419
420 status_nbuf = rx_desc->nbuf;
421
422 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
423 QDF_DMA_FROM_DEVICE);
424
425 status_buf = qdf_nbuf_data(status_nbuf);
426
427 status = hal_get_rx_status_done(status_buf);
428
429 if (status != QDF_STATUS_SUCCESS) {
430 QDF_TRACE(QDF_MODULE_ID_DP,
431 QDF_TRACE_LEVEL_WARN,
432 "[%s][%d] status not done",
433 __func__, __LINE__);
434 break;
435 }
436 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
437
438 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
439 QDF_DMA_FROM_DEVICE);
440
441 /* Put the status_nbuf to queue */
442 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
443
444 } else {
445 union dp_rx_desc_list_elem_t *desc_list = NULL;
446 union dp_rx_desc_list_elem_t *tail = NULL;
447 struct rx_desc_pool *rx_desc_pool;
448 uint32_t num_alloc_desc;
449
450 rx_desc_pool = &soc->rx_desc_status[mac_id];
451
452 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
453 rx_desc_pool,
454 1,
455 &desc_list,
456 &tail);
457
458 rx_desc = &desc_list->rx_desc;
459 }
460
461 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530462 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800463 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
464
465 status_buf = qdf_nbuf_data(status_nbuf);
466
467 hal_clear_rx_status_done(status_buf);
468
469 qdf_nbuf_map_single(soc->osdev, status_nbuf,
470 QDF_DMA_BIDIRECTIONAL);
471 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
472
473 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700474 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800475
476 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
477 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
478
479 rxdma_mon_status_ring_entry =
480 hal_srng_src_get_next(hal_soc, mon_status_srng);
481 work_done++;
482 }
483done:
484
485 hal_srng_access_end(hal_soc, mon_status_srng);
486
487 return work_done;
488
489}
490/*
491 * dp_rx_mon_status_process() - Process monitor status ring and
492 * TLV in status ring.
493 *
494 * @soc: core txrx main context
495 * @mac_id: mac_id which is one of 3 mac_ids
496 * @quota: No. of ring entry that can be serviced in one shot.
497
498 * Return: uint32_t: No. of ring entry that is processed.
499 */
500static inline uint32_t
501dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
502 uint32_t work_done;
503
504 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700505 quota -= work_done;
506 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800507
508 return work_done;
509}
510/**
511 * dp_mon_process() - Main monitor mode processing roution.
512 * This call monitor status ring process then monitor
513 * destination ring process.
514 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
515 * @soc: core txrx main context
516 * @mac_id: mac_id which is one of 3 mac_ids
517 * @quota: No. of status ring entry that can be serviced in one shot.
518
519 * Return: uint32_t: No. of ring entry that is processed.
520 */
521uint32_t
522dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700523 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800524}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700525
Kai Chen6eca1a62017-01-12 10:17:53 -0800526/**
527 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
528 * @pdev: core txrx pdev context
529 *
530 * This function will detach DP RX status ring from
531 * main device context. will free DP Rx resources for
532 * status ring
533 *
534 * Return: QDF_STATUS_SUCCESS: success
535 * QDF_STATUS_E_RESOURCES: Error return
536 */
537QDF_STATUS
538dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
539{
540 uint8_t pdev_id = pdev->pdev_id;
541 struct dp_soc *soc = pdev->soc;
542 struct rx_desc_pool *rx_desc_pool;
543
544 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700545 if (rx_desc_pool->pool_size != 0) {
546 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
547 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800548
549 return QDF_STATUS_SUCCESS;
550}
551
552/*
553 * dp_rx_buffers_replenish() - replenish monitor status ring with
554 * rx nbufs called during dp rx
555 * monitor status ring initialization
556 *
557 * @soc: core txrx main context
558 * @mac_id: mac_id which is one of 3 mac_ids
559 * @dp_rxdma_srng: dp monitor status circular ring
560 * @rx_desc_pool; Pointer to Rx descriptor pool
561 * @num_req_buffers: number of buffer to be replenished
562 * @desc_list: list of descs if called from dp rx monitor status
563 * process or NULL during dp rx initialization or
564 * out of buffer interrupt
565 * @tail: tail of descs list
566 * @owner: who owns the nbuf (host, NSS etc...)
567 * Return: return success or failure
568 */
569static inline
570QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
571 uint32_t mac_id,
572 struct dp_srng *dp_rxdma_srng,
573 struct rx_desc_pool *rx_desc_pool,
574 uint32_t num_req_buffers,
575 union dp_rx_desc_list_elem_t **desc_list,
576 union dp_rx_desc_list_elem_t **tail,
577 uint8_t owner)
578{
579 uint32_t num_alloc_desc;
580 uint16_t num_desc_to_free = 0;
581 uint32_t num_entries_avail;
582 uint32_t count;
583 int sync_hw_ptr = 1;
584 qdf_dma_addr_t paddr;
585 qdf_nbuf_t rx_netbuf;
586 void *rxdma_ring_entry;
587 union dp_rx_desc_list_elem_t *next;
588 void *rxdma_srng;
589 uint8_t *status_buf;
590
591 rxdma_srng = dp_rxdma_srng->hal_srng;
592
593 qdf_assert(rxdma_srng);
594
Houston Hoffmanae850c62017-08-11 16:47:50 -0700595 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800596 "[%s][%d] requested %d buffers for replenish\n",
597 __func__, __LINE__, num_req_buffers);
598
599 /*
600 * if desc_list is NULL, allocate the descs from freelist
601 */
602 if (!(*desc_list)) {
603
604 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
605 rx_desc_pool,
606 num_req_buffers,
607 desc_list,
608 tail);
609
610 if (!num_alloc_desc) {
611 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
612 "[%s][%d] no free rx_descs in freelist\n",
613 __func__, __LINE__);
614 return QDF_STATUS_E_NOMEM;
615 }
616
Houston Hoffmanae850c62017-08-11 16:47:50 -0700617 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800618 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
619 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700620
Kai Chen6eca1a62017-01-12 10:17:53 -0800621 num_req_buffers = num_alloc_desc;
622 }
623
624 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
625 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
626 rxdma_srng, sync_hw_ptr);
627
Houston Hoffmanae850c62017-08-11 16:47:50 -0700628 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800629 "[%s][%d] no of availble entries in rxdma ring: %d\n",
630 __func__, __LINE__, num_entries_avail);
631
632 if (num_entries_avail < num_req_buffers) {
633 num_desc_to_free = num_req_buffers - num_entries_avail;
634 num_req_buffers = num_entries_avail;
635 }
636
637 for (count = 0; count < num_req_buffers; count++) {
638 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
639 rxdma_srng);
640
641 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
642 RX_BUFFER_SIZE,
643 RX_BUFFER_RESERVATION,
644 RX_BUFFER_ALIGNMENT,
645 FALSE);
646
647 status_buf = qdf_nbuf_data(rx_netbuf);
648 hal_clear_rx_status_done(status_buf);
649
650 memset(status_buf, 0, RX_BUFFER_SIZE);
651
652 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
653 QDF_DMA_BIDIRECTIONAL);
654
655 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
656
657 next = (*desc_list)->next;
658
659 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700660 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800661 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
662 (*desc_list)->rx_desc.cookie, owner);
663
Karunakar Dasineni40555682017-03-26 22:44:39 -0700664 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700665 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
666 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800667 __func__, __LINE__, &(*desc_list)->rx_desc,
668 (*desc_list)->rx_desc.cookie, rx_netbuf,
669 status_buf, (void *)paddr);
670
671 *desc_list = next;
672 }
673
674 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
675
Houston Hoffmanae850c62017-08-11 16:47:50 -0700676 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800677 "successfully replenished %d buffers\n", num_req_buffers);
678
Houston Hoffmanae850c62017-08-11 16:47:50 -0700679 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800680 "%d rx desc added back to free list\n", num_desc_to_free);
681
Houston Hoffmanae850c62017-08-11 16:47:50 -0700682 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700683 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800684 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
685 (*desc_list)->rx_desc.cookie);
686
687 /*
688 * add any available free desc back to the free list
689 */
690 if (*desc_list) {
691 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
692 mac_id, rx_desc_pool);
693 }
694
695 return QDF_STATUS_SUCCESS;
696}
697/**
698 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
699 * @pdev: core txrx pdev context
700 *
701 * This function will attach a DP RX monitor status ring into pDEV
702 * and replenish monitor status ring with buffer.
703 *
704 * Return: QDF_STATUS_SUCCESS: success
705 * QDF_STATUS_E_RESOURCES: Error return
706 */
707QDF_STATUS
708dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
709 uint8_t pdev_id = pdev->pdev_id;
710 struct dp_soc *soc = pdev->soc;
711 union dp_rx_desc_list_elem_t *desc_list = NULL;
712 union dp_rx_desc_list_elem_t *tail = NULL;
713 struct dp_srng *rxdma_srng;
714 uint32_t rxdma_entries;
715 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700716 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800717
718 rxdma_srng = &pdev->rxdma_mon_status_ring;
719
720 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
721 soc->hal_soc, RXDMA_MONITOR_STATUS);
722
723 rx_desc_pool = &soc->rx_desc_status[pdev_id];
724
Houston Hoffman41b912c2017-08-30 14:27:51 -0700725 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800726 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
727 __func__, pdev_id, rxdma_entries);
728
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700729 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
730 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700731 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700732 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
733 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
734 return status;
735 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800736
Houston Hoffman41b912c2017-08-30 14:27:51 -0700737 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800738 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
739 __func__, pdev_id);
740
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700741 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
742 rx_desc_pool, rxdma_entries, &desc_list, &tail,
743 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700744 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700745 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
746 "%s: dp_rx_buffers_replenish() failed \n", __func__);
747 return status;
748 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800749
750 qdf_nbuf_queue_init(&pdev->rx_status_q);
751
752 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800753 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700754 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
755 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800756
757 return QDF_STATUS_SUCCESS;
758}