blob: 3a748af36c7cd892548b08fbd32307db3fa7f4cd [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;
82 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
83 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
84 cdp_rx_ppdu->timestamp = ppdu_info->com_info.ppdu_timestamp;
85 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_freq;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053086 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
87 cdp_rx_ppdu->udp_msdu_count +
88 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053089
90 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
91 cdp_rx_ppdu->is_ampdu = 1;
92 else
93 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj38a29562017-08-18 19:41:17 +053094}
95#else
96static inline void
97dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
98 struct hal_rx_ppdu_info *ppdu_info,
99 qdf_nbuf_t ppdu_nbuf)
100{
101}
102#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530103/**
104 * dp_rx_stats_update() - Update per-peer statistics
105 * @soc: Datapath SOC handle
106 * @peer: Datapath peer handle
107 * @ppdu: PPDU Descriptor
108 *
109 * Return: None
110 */
111#ifdef FEATURE_PERPKT_INFO
112static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
113 struct cdp_rx_indication_ppdu *ppdu)
114{
115 struct dp_pdev *pdev = NULL;
116 uint8_t mcs, preamble;
117 uint16_t num_msdu;
118
119 mcs = ppdu->u.mcs;
120 preamble = ppdu->u.preamble;
121 num_msdu = ppdu->num_msdu;
122
123 if (!peer)
124 return;
125
126 pdev = peer->vdev->pdev;
127
128 if (soc->process_rx_status)
129 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530130
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530131 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530132
133 if ((preamble == DOT11_A) || (preamble == DOT11_B))
134 ppdu->u.nss = 1;
135
136 if (ppdu->u.nss)
137 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
138
Pranita Solankea12b4b32017-11-20 23:04:14 +0530139 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530140 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530141 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
142 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
143 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530144 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530145 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530146 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
147 DP_STATS_INCC(peer,
148 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530149 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530150 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530151 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530152 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
153 DP_STATS_INCC(peer,
154 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530155 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530156 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530157 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530158 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
159 DP_STATS_INCC(peer,
160 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530161 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530162 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530163 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530164 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
165 DP_STATS_INCC(peer,
166 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
167 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
168 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530169 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530170 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
171 DP_STATS_INCC(peer,
172 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
173 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Pranita Solankea12b4b32017-11-20 23:04:14 +0530174 DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530175
176 if (soc->cdp_soc.ol_ops->update_dp_stats) {
177 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
178 &peer->stats, ppdu->peer_id,
179 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530180
181 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530182 }
183}
184#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530185
186/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530187 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530188 * @soc: core txrx main context
189 * @pdev: pdev strcuture
190 * @ppdu_info: structure for rx ppdu ring
191 *
192 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
193 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530194 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530195#ifdef FEATURE_PERPKT_INFO
196static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530197dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530198 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
199{
200 uint8_t size = 0;
201
202 if (ppdu_info->first_msdu_payload == NULL)
203 return QDF_STATUS_SUCCESS;
204
205 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
206 return QDF_STATUS_SUCCESS;
207
208 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
209
210 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
211 ppdu_info->first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530212
213 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
214 return QDF_STATUS_SUCCESS;
215
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530216 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
217 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
218 return QDF_STATUS_E_ALREADY;
219}
220#else
221static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530222dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530223 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
224{
225 return QDF_STATUS_SUCCESS;
226}
227#endif
228
229
230/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530231* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
232* @soc: core txrx main context
233* @pdev: pdev strcuture
234* @ppdu_info: structure for rx ppdu ring
235*
236* Return: none
237*/
238#ifdef FEATURE_PERPKT_INFO
239static inline void
240dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
241 struct hal_rx_ppdu_info *ppdu_info)
242{
243 qdf_nbuf_t ppdu_nbuf;
244 struct dp_peer *peer;
245 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
246
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530247 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530248 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
249 if (ppdu_nbuf) {
250 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
251 qdf_nbuf_put_tail(ppdu_nbuf,
252 sizeof(struct cdp_rx_indication_ppdu));
253 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
254
255 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
256 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530257 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530258 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
259 ppdu_nbuf, cdp_rx_ppdu->peer_id,
260 WDI_NO_VAL, pdev->pdev_id);
261 } else
262 qdf_nbuf_free(ppdu_nbuf);
263 }
264}
265#else
266static inline void
267dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
268 struct hal_rx_ppdu_info *ppdu_info)
269{
270}
271#endif
272
273/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800274* dp_rx_mon_status_process_tlv() - Process status TLV in status
275* buffer on Rx status Queue posted by status SRNG processing.
276* @soc: core txrx main context
277* @mac_id: mac_id which is one of 3 mac_ids _ring
278*
279* Return: none
280*/
281static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700282dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
283 uint32_t quota)
284{
Kai Chen6eca1a62017-01-12 10:17:53 -0800285 struct dp_pdev *pdev = soc->pdev_list[mac_id];
286 struct hal_rx_ppdu_info *ppdu_info;
287 qdf_nbuf_t status_nbuf;
288 uint8_t *rx_tlv;
289 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700290 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530291 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800292
Kai Chen6eca1a62017-01-12 10:17:53 -0800293 ppdu_info = &pdev->ppdu_info;
294
295 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
296 return;
297
298 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
299
300 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
301 rx_tlv = qdf_nbuf_data(status_nbuf);
302 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700303
Keyur Parekhfad6d082017-05-07 08:54:47 -0700304#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700305#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700306 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700307 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700308#endif
309#endif
Soumya Bhat7422db82017-12-15 13:48:53 +0530310 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800311
Keyur Parekhfad6d082017-05-07 08:54:47 -0700312 do {
313 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
314 ppdu_info);
315 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800316
Keyur Parekhfad6d082017-05-07 08:54:47 -0700317 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
318 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800319
Keyur Parekhfad6d082017-05-07 08:54:47 -0700320 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
321 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530322
Soumya Bhat7422db82017-12-15 13:48:53 +0530323 if (pdev->mcopy_mode) {
324 am_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530325 pdev, ppdu_info, status_nbuf);
326 if (am_copy_status == QDF_STATUS_SUCCESS)
327 qdf_nbuf_free(status_nbuf);
328 } else {
329 qdf_nbuf_free(status_nbuf);
330 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800331
332 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530333 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530334 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530335 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530336
Kai Chen6eca1a62017-01-12 10:17:53 -0800337 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700338 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700339 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800340 pdev->ppdu_info.com_info.last_ppdu_id =
341 pdev->ppdu_info.com_info.ppdu_id;
Kai Chen6eca1a62017-01-12 10:17:53 -0800342 }
343 }
344 return;
345}
346
347/*
348 * dp_rx_mon_status_srng_process() - Process monitor status ring
349 * post the status ring buffer to Rx status Queue for later
350 * processing when status ring is filled with status TLV.
351 * Allocate a new buffer to status ring if the filled buffer
352 * is posted.
353 *
354 * @soc: core txrx main context
355 * @mac_id: mac_id which is one of 3 mac_ids
356 * @quota: No. of ring entry that can be serviced in one shot.
357
358 * Return: uint32_t: No. of ring entry that is processed.
359 */
360static inline uint32_t
361dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
362 uint32_t quota)
363{
364 struct dp_pdev *pdev = soc->pdev_list[mac_id];
365 void *hal_soc;
366 void *mon_status_srng;
367 void *rxdma_mon_status_ring_entry;
368 QDF_STATUS status;
369 uint32_t work_done = 0;
370
Kai Chen6eca1a62017-01-12 10:17:53 -0800371 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
372
373 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700374 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
375
376 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700377 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700378 __func__, __LINE__, mon_status_srng);
379 return work_done;
380 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800381
382 hal_soc = soc->hal_soc;
383
384 qdf_assert(hal_soc);
385
386 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
387 goto done;
388
389 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
390 * BUFFER_ADDR_INFO STRUCT
391 */
392 while (qdf_likely((rxdma_mon_status_ring_entry =
393 hal_srng_src_peek(hal_soc, mon_status_srng))
394 && quota--)) {
395 uint32_t rx_buf_cookie;
396 qdf_nbuf_t status_nbuf;
397 struct dp_rx_desc *rx_desc;
398 uint8_t *status_buf;
399 qdf_dma_addr_t paddr;
400 uint64_t buf_addr;
401
402 buf_addr =
403 (HAL_RX_BUFFER_ADDR_31_0_GET(
404 rxdma_mon_status_ring_entry) |
405 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
406 rxdma_mon_status_ring_entry)) << 32));
407
408 if (qdf_likely(buf_addr)) {
409
410 rx_buf_cookie =
411 HAL_RX_BUF_COOKIE_GET(
412 rxdma_mon_status_ring_entry);
413 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
414 rx_buf_cookie);
415
416 qdf_assert(rx_desc);
417
418 status_nbuf = rx_desc->nbuf;
419
420 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
421 QDF_DMA_FROM_DEVICE);
422
423 status_buf = qdf_nbuf_data(status_nbuf);
424
425 status = hal_get_rx_status_done(status_buf);
426
427 if (status != QDF_STATUS_SUCCESS) {
428 QDF_TRACE(QDF_MODULE_ID_DP,
429 QDF_TRACE_LEVEL_WARN,
430 "[%s][%d] status not done",
431 __func__, __LINE__);
432 break;
433 }
434 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
435
436 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
437 QDF_DMA_FROM_DEVICE);
438
439 /* Put the status_nbuf to queue */
440 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
441
442 } else {
443 union dp_rx_desc_list_elem_t *desc_list = NULL;
444 union dp_rx_desc_list_elem_t *tail = NULL;
445 struct rx_desc_pool *rx_desc_pool;
446 uint32_t num_alloc_desc;
447
448 rx_desc_pool = &soc->rx_desc_status[mac_id];
449
450 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
451 rx_desc_pool,
452 1,
453 &desc_list,
454 &tail);
455
456 rx_desc = &desc_list->rx_desc;
457 }
458
459 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530460 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800461 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
462
463 status_buf = qdf_nbuf_data(status_nbuf);
464
465 hal_clear_rx_status_done(status_buf);
466
467 qdf_nbuf_map_single(soc->osdev, status_nbuf,
468 QDF_DMA_BIDIRECTIONAL);
469 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
470
471 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700472 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800473
474 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
475 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
476
477 rxdma_mon_status_ring_entry =
478 hal_srng_src_get_next(hal_soc, mon_status_srng);
479 work_done++;
480 }
481done:
482
483 hal_srng_access_end(hal_soc, mon_status_srng);
484
485 return work_done;
486
487}
488/*
489 * dp_rx_mon_status_process() - Process monitor status ring and
490 * TLV in status ring.
491 *
492 * @soc: core txrx main context
493 * @mac_id: mac_id which is one of 3 mac_ids
494 * @quota: No. of ring entry that can be serviced in one shot.
495
496 * Return: uint32_t: No. of ring entry that is processed.
497 */
498static inline uint32_t
499dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
500 uint32_t work_done;
501
502 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700503 quota -= work_done;
504 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800505
506 return work_done;
507}
508/**
509 * dp_mon_process() - Main monitor mode processing roution.
510 * This call monitor status ring process then monitor
511 * destination ring process.
512 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
513 * @soc: core txrx main context
514 * @mac_id: mac_id which is one of 3 mac_ids
515 * @quota: No. of status ring entry that can be serviced in one shot.
516
517 * Return: uint32_t: No. of ring entry that is processed.
518 */
519uint32_t
520dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700521 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800522}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700523
Kai Chen6eca1a62017-01-12 10:17:53 -0800524/**
525 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
526 * @pdev: core txrx pdev context
527 *
528 * This function will detach DP RX status ring from
529 * main device context. will free DP Rx resources for
530 * status ring
531 *
532 * Return: QDF_STATUS_SUCCESS: success
533 * QDF_STATUS_E_RESOURCES: Error return
534 */
535QDF_STATUS
536dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
537{
538 uint8_t pdev_id = pdev->pdev_id;
539 struct dp_soc *soc = pdev->soc;
540 struct rx_desc_pool *rx_desc_pool;
541
542 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700543 if (rx_desc_pool->pool_size != 0) {
544 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
545 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800546
547 return QDF_STATUS_SUCCESS;
548}
549
550/*
551 * dp_rx_buffers_replenish() - replenish monitor status ring with
552 * rx nbufs called during dp rx
553 * monitor status ring initialization
554 *
555 * @soc: core txrx main context
556 * @mac_id: mac_id which is one of 3 mac_ids
557 * @dp_rxdma_srng: dp monitor status circular ring
558 * @rx_desc_pool; Pointer to Rx descriptor pool
559 * @num_req_buffers: number of buffer to be replenished
560 * @desc_list: list of descs if called from dp rx monitor status
561 * process or NULL during dp rx initialization or
562 * out of buffer interrupt
563 * @tail: tail of descs list
564 * @owner: who owns the nbuf (host, NSS etc...)
565 * Return: return success or failure
566 */
567static inline
568QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
569 uint32_t mac_id,
570 struct dp_srng *dp_rxdma_srng,
571 struct rx_desc_pool *rx_desc_pool,
572 uint32_t num_req_buffers,
573 union dp_rx_desc_list_elem_t **desc_list,
574 union dp_rx_desc_list_elem_t **tail,
575 uint8_t owner)
576{
577 uint32_t num_alloc_desc;
578 uint16_t num_desc_to_free = 0;
579 uint32_t num_entries_avail;
580 uint32_t count;
581 int sync_hw_ptr = 1;
582 qdf_dma_addr_t paddr;
583 qdf_nbuf_t rx_netbuf;
584 void *rxdma_ring_entry;
585 union dp_rx_desc_list_elem_t *next;
586 void *rxdma_srng;
587 uint8_t *status_buf;
588
589 rxdma_srng = dp_rxdma_srng->hal_srng;
590
591 qdf_assert(rxdma_srng);
592
Houston Hoffmanae850c62017-08-11 16:47:50 -0700593 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800594 "[%s][%d] requested %d buffers for replenish\n",
595 __func__, __LINE__, num_req_buffers);
596
597 /*
598 * if desc_list is NULL, allocate the descs from freelist
599 */
600 if (!(*desc_list)) {
601
602 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
603 rx_desc_pool,
604 num_req_buffers,
605 desc_list,
606 tail);
607
608 if (!num_alloc_desc) {
609 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
610 "[%s][%d] no free rx_descs in freelist\n",
611 __func__, __LINE__);
612 return QDF_STATUS_E_NOMEM;
613 }
614
Houston Hoffmanae850c62017-08-11 16:47:50 -0700615 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800616 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
617 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700618
Kai Chen6eca1a62017-01-12 10:17:53 -0800619 num_req_buffers = num_alloc_desc;
620 }
621
622 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
623 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
624 rxdma_srng, sync_hw_ptr);
625
Houston Hoffmanae850c62017-08-11 16:47:50 -0700626 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800627 "[%s][%d] no of availble entries in rxdma ring: %d\n",
628 __func__, __LINE__, num_entries_avail);
629
630 if (num_entries_avail < num_req_buffers) {
631 num_desc_to_free = num_req_buffers - num_entries_avail;
632 num_req_buffers = num_entries_avail;
633 }
634
635 for (count = 0; count < num_req_buffers; count++) {
636 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
637 rxdma_srng);
638
639 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
640 RX_BUFFER_SIZE,
641 RX_BUFFER_RESERVATION,
642 RX_BUFFER_ALIGNMENT,
643 FALSE);
644
645 status_buf = qdf_nbuf_data(rx_netbuf);
646 hal_clear_rx_status_done(status_buf);
647
648 memset(status_buf, 0, RX_BUFFER_SIZE);
649
650 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
651 QDF_DMA_BIDIRECTIONAL);
652
653 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
654
655 next = (*desc_list)->next;
656
657 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700658 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800659 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
660 (*desc_list)->rx_desc.cookie, owner);
661
Karunakar Dasineni40555682017-03-26 22:44:39 -0700662 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700663 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
664 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800665 __func__, __LINE__, &(*desc_list)->rx_desc,
666 (*desc_list)->rx_desc.cookie, rx_netbuf,
667 status_buf, (void *)paddr);
668
669 *desc_list = next;
670 }
671
672 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
673
Houston Hoffmanae850c62017-08-11 16:47:50 -0700674 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800675 "successfully replenished %d buffers\n", num_req_buffers);
676
Houston Hoffmanae850c62017-08-11 16:47:50 -0700677 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800678 "%d rx desc added back to free list\n", num_desc_to_free);
679
Houston Hoffmanae850c62017-08-11 16:47:50 -0700680 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700681 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800682 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
683 (*desc_list)->rx_desc.cookie);
684
685 /*
686 * add any available free desc back to the free list
687 */
688 if (*desc_list) {
689 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
690 mac_id, rx_desc_pool);
691 }
692
693 return QDF_STATUS_SUCCESS;
694}
695/**
696 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
697 * @pdev: core txrx pdev context
698 *
699 * This function will attach a DP RX monitor status ring into pDEV
700 * and replenish monitor status ring with buffer.
701 *
702 * Return: QDF_STATUS_SUCCESS: success
703 * QDF_STATUS_E_RESOURCES: Error return
704 */
705QDF_STATUS
706dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
707 uint8_t pdev_id = pdev->pdev_id;
708 struct dp_soc *soc = pdev->soc;
709 union dp_rx_desc_list_elem_t *desc_list = NULL;
710 union dp_rx_desc_list_elem_t *tail = NULL;
711 struct dp_srng *rxdma_srng;
712 uint32_t rxdma_entries;
713 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700714 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800715
716 rxdma_srng = &pdev->rxdma_mon_status_ring;
717
718 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
719 soc->hal_soc, RXDMA_MONITOR_STATUS);
720
721 rx_desc_pool = &soc->rx_desc_status[pdev_id];
722
Houston Hoffman41b912c2017-08-30 14:27:51 -0700723 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800724 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
725 __func__, pdev_id, rxdma_entries);
726
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700727 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
728 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700729 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700730 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
731 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
732 return status;
733 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800734
Houston Hoffman41b912c2017-08-30 14:27:51 -0700735 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800736 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
737 __func__, pdev_id);
738
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700739 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
740 rx_desc_pool, rxdma_entries, &desc_list, &tail,
741 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700742 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700743 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
744 "%s: dp_rx_buffers_replenish() failed \n", __func__);
745 return status;
746 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800747
748 qdf_nbuf_queue_init(&pdev->rx_status_q);
749
750 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800751 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700752 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
753 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800754
755 return QDF_STATUS_SUCCESS;
756}