blob: 2d316bd9537c06607fd42ac2e29867c80959b3e0 [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;
nobelj9ab76e22018-02-13 18:10:54 -080075 cdp_rx_ppdu->length = ppdu_info->rx_status.ppdu_len;
Anish Nataraj38a29562017-08-18 19:41:17 +053076 cdp_rx_ppdu->duration = ppdu_info->rx_status.duration;
77 cdp_rx_ppdu->u.bw = ppdu_info->rx_status.bw;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053078 cdp_rx_ppdu->tcp_msdu_count = ppdu_info->rx_status.tcp_msdu_count;
79 cdp_rx_ppdu->udp_msdu_count = ppdu_info->rx_status.udp_msdu_count;
80 cdp_rx_ppdu->other_msdu_count = ppdu_info->rx_status.other_msdu_count;
Anish Nataraj38a29562017-08-18 19:41:17 +053081 cdp_rx_ppdu->u.nss = ppdu_info->rx_status.nss;
82 cdp_rx_ppdu->u.mcs = ppdu_info->rx_status.mcs;
Anish Nataraj072d8972018-01-09 18:23:33 +053083 cdp_rx_ppdu->u.gi = ppdu_info->rx_status.sgi;
Anish Nataraj38a29562017-08-18 19:41:17 +053084 cdp_rx_ppdu->u.preamble = ppdu_info->rx_status.preamble_type;
Anish Nataraj28490c42018-01-19 19:34:54 +053085 cdp_rx_ppdu->u.ppdu_type = ppdu_info->rx_status.reception_type;
Anish Nataraj38a29562017-08-18 19:41:17 +053086 cdp_rx_ppdu->rssi = ppdu_info->rx_status.rssi_comb;
Anish Nataraj57614da2018-02-07 23:04:24 +053087 cdp_rx_ppdu->timestamp = ppdu_info->rx_status.tsft;
88 cdp_rx_ppdu->channel = ppdu_info->rx_status.chan_num;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053089 cdp_rx_ppdu->num_msdu = (cdp_rx_ppdu->tcp_msdu_count +
90 cdp_rx_ppdu->udp_msdu_count +
91 cdp_rx_ppdu->other_msdu_count);
Pranita Solankeed0aba62018-01-12 19:14:31 +053092
Anish Nataraj57614da2018-02-07 23:04:24 +053093 cdp_rx_ppdu->num_mpdu = ppdu_info->com_info.mpdu_cnt_fcs_ok;
Pranita Solankeed0aba62018-01-12 19:14:31 +053094 if (ppdu_info->com_info.mpdu_cnt_fcs_ok > 1)
95 cdp_rx_ppdu->is_ampdu = 1;
96 else
97 cdp_rx_ppdu->is_ampdu = 0;
Anish Nataraj45d282c2017-12-30 01:03:38 +053098
99 cdp_rx_ppdu->tid = ppdu_info->rx_status.tid;
Anish Nataraj57614da2018-02-07 23:04:24 +0530100 cdp_rx_ppdu->lsig_a = ppdu_info->rx_status.rate;
Anish Nataraj38a29562017-08-18 19:41:17 +0530101}
102#else
103static inline void
104dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
105 struct hal_rx_ppdu_info *ppdu_info,
106 qdf_nbuf_t ppdu_nbuf)
107{
108}
109#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530110/**
111 * dp_rx_stats_update() - Update per-peer statistics
112 * @soc: Datapath SOC handle
113 * @peer: Datapath peer handle
114 * @ppdu: PPDU Descriptor
115 *
116 * Return: None
117 */
118#ifdef FEATURE_PERPKT_INFO
119static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
120 struct cdp_rx_indication_ppdu *ppdu)
121{
122 struct dp_pdev *pdev = NULL;
Anish Nataraj28490c42018-01-19 19:34:54 +0530123 uint8_t mcs, preamble, ac = 0;
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530124 uint16_t num_msdu;
125
126 mcs = ppdu->u.mcs;
127 preamble = ppdu->u.preamble;
128 num_msdu = ppdu->num_msdu;
129
130 if (!peer)
131 return;
132
133 pdev = peer->vdev->pdev;
134
Subhranil Choudhuryeea67382018-01-18 20:24:36 +0530135 dp_mark_peer_inact(peer, false);
136
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530137 if (soc->process_rx_status)
138 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530139
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530140 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankeed0aba62018-01-12 19:14:31 +0530141
142 if ((preamble == DOT11_A) || (preamble == DOT11_B))
143 ppdu->u.nss = 1;
144
145 if (ppdu->u.nss)
146 DP_STATS_INC(peer, rx.nss[ppdu->u.nss - 1], num_msdu);
147
Pranita Solankea12b4b32017-11-20 23:04:14 +0530148 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530149 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Anish Nataraj28490c42018-01-19 19:34:54 +0530150 DP_STATS_INC(peer, rx.reception_type[ppdu->u.ppdu_type], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530151 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
152 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
153 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530154 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530155 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530156 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
157 DP_STATS_INCC(peer,
158 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530159 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530160 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530161 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530162 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
163 DP_STATS_INCC(peer,
164 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530165 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530166 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530167 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530168 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
169 DP_STATS_INCC(peer,
170 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530171 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530172 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530173 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530174 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
175 DP_STATS_INCC(peer,
176 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
177 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
178 DP_STATS_INCC(peer,
Pranita Solankeed0aba62018-01-12 19:14:31 +0530179 rx.pkt_type[preamble].mcs_count[MAX_MCS - 1], num_msdu,
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530180 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
181 DP_STATS_INCC(peer,
182 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
183 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Anish Nataraj28490c42018-01-19 19:34:54 +0530184 /*
185 * If invalid TID, it could be a non-qos frame, hence do not update
186 * any AC counters
187 */
188 ac = TID_TO_WME_AC(ppdu->tid);
189 if (ppdu->tid != HAL_TID_INVALID)
190 DP_STATS_INC(peer, rx.wme_ac_type[ac], num_msdu);
191
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530192 if (soc->cdp_soc.ol_ops->update_dp_stats) {
193 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
194 &peer->stats, ppdu->peer_id,
195 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530196
197 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530198 }
199}
200#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530201
202/**
Soumya Bhat7422db82017-12-15 13:48:53 +0530203 * dp_rx_handle_mcopy_mode() - Allocate and deliver first MSDU payload
Pranita Solankefc2ff392017-12-15 19:25:13 +0530204 * @soc: core txrx main context
205 * @pdev: pdev strcuture
206 * @ppdu_info: structure for rx ppdu ring
207 *
208 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
209 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat7422db82017-12-15 13:48:53 +0530210 */
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530211#ifdef FEATURE_PERPKT_INFO
212static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530213dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530214 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
215{
216 uint8_t size = 0;
217
218 if (ppdu_info->first_msdu_payload == NULL)
219 return QDF_STATUS_SUCCESS;
220
Soumya Bhat2f54de22018-02-21 09:54:28 +0530221 if (pdev->m_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530222 return QDF_STATUS_SUCCESS;
223
Soumya Bhat2f54de22018-02-21 09:54:28 +0530224 pdev->m_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530225
Soumya Bhat2f54de22018-02-21 09:54:28 +0530226 /* Include 2 bytes of reserved space appended to the msdu payload */
227 size = (ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf)) + 2;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530228 ppdu_info->first_msdu_payload = NULL;
Soumya Bhat7422db82017-12-15 13:48:53 +0530229
230 if (qdf_nbuf_pull_head(nbuf, size) == NULL)
231 return QDF_STATUS_SUCCESS;
232
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530233 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
234 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
235 return QDF_STATUS_E_ALREADY;
236}
237#else
238static inline QDF_STATUS
Soumya Bhat7422db82017-12-15 13:48:53 +0530239dp_rx_handle_mcopy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530240 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
241{
242 return QDF_STATUS_SUCCESS;
243}
244#endif
245
246
247/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530248* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
249* @soc: core txrx main context
250* @pdev: pdev strcuture
251* @ppdu_info: structure for rx ppdu ring
252*
253* Return: none
254*/
255#ifdef FEATURE_PERPKT_INFO
256static inline void
257dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
258 struct hal_rx_ppdu_info *ppdu_info)
259{
260 qdf_nbuf_t ppdu_nbuf;
261 struct dp_peer *peer;
262 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
263
Anish Nataraj28490c42018-01-19 19:34:54 +0530264 /*
265 * Do not allocate if fcs error,
266 * ast idx invalid / fctl invalid
267 */
Anish Nataraj28490c42018-01-19 19:34:54 +0530268 if (!ppdu_info->rx_status.frame_control_info_valid)
269 return;
270
271 if (ppdu_info->com_info.mpdu_cnt_fcs_ok == 0)
272 return;
273
274 if (ppdu_info->rx_status.ast_index == HAL_AST_IDX_INVALID)
275 return;
276
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530277 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530278 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
279 if (ppdu_nbuf) {
280 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
281 qdf_nbuf_put_tail(ppdu_nbuf,
282 sizeof(struct cdp_rx_indication_ppdu));
283 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
284
285 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
286 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530287 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530288 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
289 ppdu_nbuf, cdp_rx_ppdu->peer_id,
290 WDI_NO_VAL, pdev->pdev_id);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530291 } else if (pdev->mcopy_mode) {
292 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
293 ppdu_nbuf, HTT_INVALID_PEER,
294 WDI_NO_VAL, pdev->pdev_id);
295 } else {
Anish Nataraj38a29562017-08-18 19:41:17 +0530296 qdf_nbuf_free(ppdu_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530297 }
Anish Nataraj38a29562017-08-18 19:41:17 +0530298 }
299}
300#else
301static inline void
302dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
303 struct hal_rx_ppdu_info *ppdu_info)
304{
305}
306#endif
307
308/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800309* dp_rx_mon_status_process_tlv() - Process status TLV in status
310* buffer on Rx status Queue posted by status SRNG processing.
311* @soc: core txrx main context
312* @mac_id: mac_id which is one of 3 mac_ids _ring
313*
314* Return: none
315*/
316static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700317dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
318 uint32_t quota)
319{
Kai Chen6eca1a62017-01-12 10:17:53 -0800320 struct dp_pdev *pdev = soc->pdev_list[mac_id];
321 struct hal_rx_ppdu_info *ppdu_info;
322 qdf_nbuf_t status_nbuf;
323 uint8_t *rx_tlv;
324 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700325 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat2f54de22018-02-21 09:54:28 +0530326 QDF_STATUS m_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800327
Kai Chen6eca1a62017-01-12 10:17:53 -0800328 ppdu_info = &pdev->ppdu_info;
329
330 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
331 return;
332
333 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
334
335 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
336 rx_tlv = qdf_nbuf_data(status_nbuf);
337 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700338
Keyur Parekhfad6d082017-05-07 08:54:47 -0700339#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700340#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700341 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700342 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700343#endif
344#endif
Soumya Bhat2f54de22018-02-21 09:54:28 +0530345 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en) ||
346 pdev->mcopy_mode) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800347
Keyur Parekhfad6d082017-05-07 08:54:47 -0700348 do {
349 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
350 ppdu_info);
351 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800352
Keyur Parekhfad6d082017-05-07 08:54:47 -0700353 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
354 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800355
Keyur Parekhfad6d082017-05-07 08:54:47 -0700356 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
357 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530358
Soumya Bhat7422db82017-12-15 13:48:53 +0530359 if (pdev->mcopy_mode) {
Soumya Bhat2f54de22018-02-21 09:54:28 +0530360 m_copy_status = dp_rx_handle_mcopy_mode(soc,
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530361 pdev, ppdu_info, status_nbuf);
Soumya Bhat2f54de22018-02-21 09:54:28 +0530362 if (m_copy_status == QDF_STATUS_SUCCESS)
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530363 qdf_nbuf_free(status_nbuf);
364 } else {
365 qdf_nbuf_free(status_nbuf);
366 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800367
368 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
nobelj9ab76e22018-02-13 18:10:54 -0800369 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
370 dp_rx_mon_dest_process(soc, mac_id, quota);
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530371 if (pdev->enhanced_stats_en ||
Soumya Bhat7422db82017-12-15 13:48:53 +0530372 pdev->mcopy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530373 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530374
Kai Chencbe4c342017-06-12 20:06:35 -0700375 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800376 pdev->ppdu_info.com_info.last_ppdu_id =
377 pdev->ppdu_info.com_info.ppdu_id;
nobelj9ab76e22018-02-13 18:10:54 -0800378
379 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
380 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800381 }
382 }
383 return;
384}
385
386/*
387 * dp_rx_mon_status_srng_process() - Process monitor status ring
388 * post the status ring buffer to Rx status Queue for later
389 * processing when status ring is filled with status TLV.
390 * Allocate a new buffer to status ring if the filled buffer
391 * is posted.
392 *
393 * @soc: core txrx main context
394 * @mac_id: mac_id which is one of 3 mac_ids
395 * @quota: No. of ring entry that can be serviced in one shot.
396
397 * Return: uint32_t: No. of ring entry that is processed.
398 */
399static inline uint32_t
400dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
401 uint32_t quota)
402{
403 struct dp_pdev *pdev = soc->pdev_list[mac_id];
404 void *hal_soc;
405 void *mon_status_srng;
406 void *rxdma_mon_status_ring_entry;
407 QDF_STATUS status;
408 uint32_t work_done = 0;
409
Kai Chen6eca1a62017-01-12 10:17:53 -0800410 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
411
412 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700413 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
414
415 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Mohit Khanna9a6fdd52017-12-12 10:55:48 +0800416 "%s %d : HAL Monitor Status Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700417 __func__, __LINE__, mon_status_srng);
418 return work_done;
419 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800420
421 hal_soc = soc->hal_soc;
422
423 qdf_assert(hal_soc);
424
425 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
426 goto done;
427
428 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
429 * BUFFER_ADDR_INFO STRUCT
430 */
431 while (qdf_likely((rxdma_mon_status_ring_entry =
432 hal_srng_src_peek(hal_soc, mon_status_srng))
433 && quota--)) {
434 uint32_t rx_buf_cookie;
435 qdf_nbuf_t status_nbuf;
436 struct dp_rx_desc *rx_desc;
437 uint8_t *status_buf;
438 qdf_dma_addr_t paddr;
439 uint64_t buf_addr;
440
441 buf_addr =
442 (HAL_RX_BUFFER_ADDR_31_0_GET(
443 rxdma_mon_status_ring_entry) |
444 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
445 rxdma_mon_status_ring_entry)) << 32));
446
447 if (qdf_likely(buf_addr)) {
448
449 rx_buf_cookie =
450 HAL_RX_BUF_COOKIE_GET(
451 rxdma_mon_status_ring_entry);
452 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
453 rx_buf_cookie);
454
455 qdf_assert(rx_desc);
456
457 status_nbuf = rx_desc->nbuf;
458
459 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
460 QDF_DMA_FROM_DEVICE);
461
462 status_buf = qdf_nbuf_data(status_nbuf);
463
464 status = hal_get_rx_status_done(status_buf);
465
466 if (status != QDF_STATUS_SUCCESS) {
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800467 uint32_t hp, tp;
468 hal_api_get_tphp(hal_soc, mon_status_srng,
469 &tp, &hp);
Kai Chen6eca1a62017-01-12 10:17:53 -0800470 QDF_TRACE(QDF_MODULE_ID_DP,
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800471 QDF_TRACE_LEVEL_ERROR,
472 "[%s][%d] status not done - hp:%u, tp:%u",
473 __func__, __LINE__, hp, tp);
474 /* WAR for missing status: Skip status entry */
475 hal_srng_src_get_next(hal_soc, mon_status_srng);
476 continue;
Kai Chen6eca1a62017-01-12 10:17:53 -0800477 }
478 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
479
480 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
481 QDF_DMA_FROM_DEVICE);
482
483 /* Put the status_nbuf to queue */
484 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
485
486 } else {
487 union dp_rx_desc_list_elem_t *desc_list = NULL;
488 union dp_rx_desc_list_elem_t *tail = NULL;
489 struct rx_desc_pool *rx_desc_pool;
490 uint32_t num_alloc_desc;
491
492 rx_desc_pool = &soc->rx_desc_status[mac_id];
493
494 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
495 rx_desc_pool,
496 1,
497 &desc_list,
498 &tail);
499
500 rx_desc = &desc_list->rx_desc;
501 }
502
503 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530504 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800505 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
506
507 status_buf = qdf_nbuf_data(status_nbuf);
508
509 hal_clear_rx_status_done(status_buf);
510
511 qdf_nbuf_map_single(soc->osdev, status_nbuf,
512 QDF_DMA_BIDIRECTIONAL);
513 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
514
515 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700516 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800517
518 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
519 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
520
Karunakar Dasineni37995ac2018-02-06 12:37:30 -0800521 hal_srng_src_get_next(hal_soc, mon_status_srng);
Kai Chen6eca1a62017-01-12 10:17:53 -0800522 work_done++;
523 }
524done:
525
526 hal_srng_access_end(hal_soc, mon_status_srng);
527
528 return work_done;
529
530}
531/*
532 * dp_rx_mon_status_process() - Process monitor status ring and
533 * TLV in status ring.
534 *
535 * @soc: core txrx main context
536 * @mac_id: mac_id which is one of 3 mac_ids
537 * @quota: No. of ring entry that can be serviced in one shot.
538
539 * Return: uint32_t: No. of ring entry that is processed.
540 */
541static inline uint32_t
542dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
543 uint32_t work_done;
544
545 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700546 quota -= work_done;
547 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800548
549 return work_done;
550}
551/**
552 * dp_mon_process() - Main monitor mode processing roution.
553 * This call monitor status ring process then monitor
554 * destination ring process.
555 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
556 * @soc: core txrx main context
557 * @mac_id: mac_id which is one of 3 mac_ids
558 * @quota: No. of status ring entry that can be serviced in one shot.
559
560 * Return: uint32_t: No. of ring entry that is processed.
561 */
562uint32_t
563dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700564 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800565}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700566
Kai Chen6eca1a62017-01-12 10:17:53 -0800567/**
568 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
569 * @pdev: core txrx pdev context
570 *
571 * This function will detach DP RX status ring from
572 * main device context. will free DP Rx resources for
573 * status ring
574 *
575 * Return: QDF_STATUS_SUCCESS: success
576 * QDF_STATUS_E_RESOURCES: Error return
577 */
578QDF_STATUS
579dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
580{
581 uint8_t pdev_id = pdev->pdev_id;
582 struct dp_soc *soc = pdev->soc;
583 struct rx_desc_pool *rx_desc_pool;
584
585 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700586 if (rx_desc_pool->pool_size != 0) {
587 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
588 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800589
590 return QDF_STATUS_SUCCESS;
591}
592
593/*
594 * dp_rx_buffers_replenish() - replenish monitor status ring with
595 * rx nbufs called during dp rx
596 * monitor status ring initialization
597 *
598 * @soc: core txrx main context
599 * @mac_id: mac_id which is one of 3 mac_ids
600 * @dp_rxdma_srng: dp monitor status circular ring
601 * @rx_desc_pool; Pointer to Rx descriptor pool
602 * @num_req_buffers: number of buffer to be replenished
603 * @desc_list: list of descs if called from dp rx monitor status
604 * process or NULL during dp rx initialization or
605 * out of buffer interrupt
606 * @tail: tail of descs list
607 * @owner: who owns the nbuf (host, NSS etc...)
608 * Return: return success or failure
609 */
610static inline
611QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
612 uint32_t mac_id,
613 struct dp_srng *dp_rxdma_srng,
614 struct rx_desc_pool *rx_desc_pool,
615 uint32_t num_req_buffers,
616 union dp_rx_desc_list_elem_t **desc_list,
617 union dp_rx_desc_list_elem_t **tail,
618 uint8_t owner)
619{
620 uint32_t num_alloc_desc;
621 uint16_t num_desc_to_free = 0;
622 uint32_t num_entries_avail;
623 uint32_t count;
624 int sync_hw_ptr = 1;
625 qdf_dma_addr_t paddr;
626 qdf_nbuf_t rx_netbuf;
627 void *rxdma_ring_entry;
628 union dp_rx_desc_list_elem_t *next;
629 void *rxdma_srng;
630 uint8_t *status_buf;
631
632 rxdma_srng = dp_rxdma_srng->hal_srng;
633
634 qdf_assert(rxdma_srng);
635
Houston Hoffmanae850c62017-08-11 16:47:50 -0700636 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800637 "[%s][%d] requested %d buffers for replenish\n",
638 __func__, __LINE__, num_req_buffers);
639
640 /*
641 * if desc_list is NULL, allocate the descs from freelist
642 */
643 if (!(*desc_list)) {
644
645 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
646 rx_desc_pool,
647 num_req_buffers,
648 desc_list,
649 tail);
650
651 if (!num_alloc_desc) {
652 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
653 "[%s][%d] no free rx_descs in freelist\n",
654 __func__, __LINE__);
655 return QDF_STATUS_E_NOMEM;
656 }
657
Houston Hoffmanae850c62017-08-11 16:47:50 -0700658 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800659 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
660 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700661
Kai Chen6eca1a62017-01-12 10:17:53 -0800662 num_req_buffers = num_alloc_desc;
663 }
664
665 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
666 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
667 rxdma_srng, sync_hw_ptr);
668
Houston Hoffmanae850c62017-08-11 16:47:50 -0700669 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800670 "[%s][%d] no of availble entries in rxdma ring: %d\n",
671 __func__, __LINE__, num_entries_avail);
672
673 if (num_entries_avail < num_req_buffers) {
674 num_desc_to_free = num_req_buffers - num_entries_avail;
675 num_req_buffers = num_entries_avail;
676 }
677
678 for (count = 0; count < num_req_buffers; count++) {
679 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
680 rxdma_srng);
681
682 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
683 RX_BUFFER_SIZE,
684 RX_BUFFER_RESERVATION,
685 RX_BUFFER_ALIGNMENT,
686 FALSE);
687
688 status_buf = qdf_nbuf_data(rx_netbuf);
689 hal_clear_rx_status_done(status_buf);
690
691 memset(status_buf, 0, RX_BUFFER_SIZE);
692
693 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
694 QDF_DMA_BIDIRECTIONAL);
695
696 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
697
698 next = (*desc_list)->next;
699
700 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700701 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800702 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
703 (*desc_list)->rx_desc.cookie, owner);
704
Karunakar Dasineni40555682017-03-26 22:44:39 -0700705 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700706 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
707 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800708 __func__, __LINE__, &(*desc_list)->rx_desc,
709 (*desc_list)->rx_desc.cookie, rx_netbuf,
710 status_buf, (void *)paddr);
711
712 *desc_list = next;
713 }
714
715 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
716
Houston Hoffmanae850c62017-08-11 16:47:50 -0700717 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800718 "successfully replenished %d buffers\n", num_req_buffers);
719
Houston Hoffmanae850c62017-08-11 16:47:50 -0700720 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800721 "%d rx desc added back to free list\n", num_desc_to_free);
722
Houston Hoffmanae850c62017-08-11 16:47:50 -0700723 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700724 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800725 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
726 (*desc_list)->rx_desc.cookie);
727
728 /*
729 * add any available free desc back to the free list
730 */
731 if (*desc_list) {
732 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
733 mac_id, rx_desc_pool);
734 }
735
736 return QDF_STATUS_SUCCESS;
737}
738/**
739 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
740 * @pdev: core txrx pdev context
741 *
742 * This function will attach a DP RX monitor status ring into pDEV
743 * and replenish monitor status ring with buffer.
744 *
745 * Return: QDF_STATUS_SUCCESS: success
746 * QDF_STATUS_E_RESOURCES: Error return
747 */
748QDF_STATUS
749dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
750 uint8_t pdev_id = pdev->pdev_id;
751 struct dp_soc *soc = pdev->soc;
752 union dp_rx_desc_list_elem_t *desc_list = NULL;
753 union dp_rx_desc_list_elem_t *tail = NULL;
754 struct dp_srng *rxdma_srng;
755 uint32_t rxdma_entries;
756 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700757 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800758
759 rxdma_srng = &pdev->rxdma_mon_status_ring;
760
761 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
762 soc->hal_soc, RXDMA_MONITOR_STATUS);
763
764 rx_desc_pool = &soc->rx_desc_status[pdev_id];
765
Houston Hoffman41b912c2017-08-30 14:27:51 -0700766 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800767 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
768 __func__, pdev_id, rxdma_entries);
769
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700770 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
771 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700772 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700773 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
774 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
775 return status;
776 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800777
Houston Hoffman41b912c2017-08-30 14:27:51 -0700778 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800779 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
780 __func__, pdev_id);
781
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700782 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
783 rx_desc_pool, rxdma_entries, &desc_list, &tail,
784 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700785 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700786 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
787 "%s: dp_rx_buffers_replenish() failed \n", __func__);
788 return status;
789 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800790
791 qdf_nbuf_queue_init(&pdev->rx_status_q);
792
793 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni65b626e2017-12-18 22:17:29 -0800794 pdev->ppdu_info.com_info.last_ppdu_id = 0;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700795 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
796 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800797
798 return QDF_STATUS_SUCCESS;
799}