blob: 93b2e9f791c6b286ee8445c831586fbfaa11862e [file] [log] [blame]
Kai Chen6eca1a62017-01-12 10:17:53 -08001/*
2 * Copyright (c) 2017 The Linux Foundation. All rights reserved.
3 *
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);
Anish Nataraj38a29562017-08-18 19:41:17 +053089}
90#else
91static inline void
92dp_rx_populate_cdp_indication_ppdu(struct dp_soc *soc,
93 struct hal_rx_ppdu_info *ppdu_info,
94 qdf_nbuf_t ppdu_nbuf)
95{
96}
97#endif
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +053098/**
99 * dp_rx_stats_update() - Update per-peer statistics
100 * @soc: Datapath SOC handle
101 * @peer: Datapath peer handle
102 * @ppdu: PPDU Descriptor
103 *
104 * Return: None
105 */
106#ifdef FEATURE_PERPKT_INFO
107static void dp_rx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
108 struct cdp_rx_indication_ppdu *ppdu)
109{
110 struct dp_pdev *pdev = NULL;
111 uint8_t mcs, preamble;
112 uint16_t num_msdu;
113
114 mcs = ppdu->u.mcs;
115 preamble = ppdu->u.preamble;
116 num_msdu = ppdu->num_msdu;
117
118 if (!peer)
119 return;
120
121 pdev = peer->vdev->pdev;
122
123 if (soc->process_rx_status)
124 return;
Pranita Solankefc2ff392017-12-15 19:25:13 +0530125
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530126 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530127 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530128 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530129 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
130 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
131 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530132 DP_STATS_INCC(peer,
133 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
134 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
135 DP_STATS_INCC(peer,
136 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530137 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530138 DP_STATS_INCC(peer,
139 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
140 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
141 DP_STATS_INCC(peer,
142 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530143 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530144 DP_STATS_INCC(peer,
145 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
146 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
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_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530150 DP_STATS_INCC(peer,
151 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
152 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
153 DP_STATS_INCC(peer,
154 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
155 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
156 DP_STATS_INCC(peer,
157 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
158 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
159 DP_STATS_INCC(peer,
160 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
161 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Pranita Solankea12b4b32017-11-20 23:04:14 +0530162 DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530163
164 if (soc->cdp_soc.ol_ops->update_dp_stats) {
165 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
166 &peer->stats, ppdu->peer_id,
167 UPDATE_PEER_STATS);
Pranita Solankefc2ff392017-12-15 19:25:13 +0530168
169 dp_aggregate_vdev_stats(peer->vdev);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530170 }
171}
172#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530173
174/**
Pranita Solankefc2ff392017-12-15 19:25:13 +0530175 * dp_rx_handle_am_copy_mode() - Allocate and deliver first MSDU payload
176 * @soc: core txrx main context
177 * @pdev: pdev strcuture
178 * @ppdu_info: structure for rx ppdu ring
179 *
180 * Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
181 * QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530182*/
183#ifdef FEATURE_PERPKT_INFO
184static inline QDF_STATUS
185dp_rx_handle_am_copy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
186 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
187{
188 uint8_t size = 0;
189
190 if (ppdu_info->first_msdu_payload == NULL)
191 return QDF_STATUS_SUCCESS;
192
193 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
194 return QDF_STATUS_SUCCESS;
195
196 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
197
198 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
199 ppdu_info->first_msdu_payload = NULL;
200 qdf_nbuf_pull_head(nbuf, size);
201 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
202 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
203 return QDF_STATUS_E_ALREADY;
204}
205#else
206static inline QDF_STATUS
207dp_rx_handle_am_copy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
208 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
209{
210 return QDF_STATUS_SUCCESS;
211}
212#endif
213
214
215/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530216* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
217* @soc: core txrx main context
218* @pdev: pdev strcuture
219* @ppdu_info: structure for rx ppdu ring
220*
221* Return: none
222*/
223#ifdef FEATURE_PERPKT_INFO
224static inline void
225dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
226 struct hal_rx_ppdu_info *ppdu_info)
227{
228 qdf_nbuf_t ppdu_nbuf;
229 struct dp_peer *peer;
230 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
231
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530232 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530233 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
234 if (ppdu_nbuf) {
235 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
236 qdf_nbuf_put_tail(ppdu_nbuf,
237 sizeof(struct cdp_rx_indication_ppdu));
238 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
239
240 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
241 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530242 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530243 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
244 ppdu_nbuf, cdp_rx_ppdu->peer_id,
245 WDI_NO_VAL, pdev->pdev_id);
246 } else
247 qdf_nbuf_free(ppdu_nbuf);
248 }
249}
250#else
251static inline void
252dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
253 struct hal_rx_ppdu_info *ppdu_info)
254{
255}
256#endif
257
258/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800259* dp_rx_mon_status_process_tlv() - Process status TLV in status
260* buffer on Rx status Queue posted by status SRNG processing.
261* @soc: core txrx main context
262* @mac_id: mac_id which is one of 3 mac_ids _ring
263*
264* Return: none
265*/
266static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700267dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
268 uint32_t quota)
269{
Kai Chen6eca1a62017-01-12 10:17:53 -0800270 struct dp_pdev *pdev = soc->pdev_list[mac_id];
271 struct hal_rx_ppdu_info *ppdu_info;
272 qdf_nbuf_t status_nbuf;
273 uint8_t *rx_tlv;
274 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700275 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530276 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800277
Kai Chen6eca1a62017-01-12 10:17:53 -0800278 ppdu_info = &pdev->ppdu_info;
279
280 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
281 return;
282
283 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
284
285 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
286 rx_tlv = qdf_nbuf_data(status_nbuf);
287 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700288
Keyur Parekhfad6d082017-05-07 08:54:47 -0700289#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700290#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700291 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700292 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700293#endif
294#endif
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530295 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)
296 || (pdev->am_copy_mode)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800297
Keyur Parekhfad6d082017-05-07 08:54:47 -0700298 do {
299 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
300 ppdu_info);
301 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800302
Keyur Parekhfad6d082017-05-07 08:54:47 -0700303 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
304 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800305
Keyur Parekhfad6d082017-05-07 08:54:47 -0700306 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
307 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530308
309 if (pdev->am_copy_mode) {
310 am_copy_status = dp_rx_handle_am_copy_mode(soc,
311 pdev, ppdu_info, status_nbuf);
312 if (am_copy_status == QDF_STATUS_SUCCESS)
313 qdf_nbuf_free(status_nbuf);
314 } else {
315 qdf_nbuf_free(status_nbuf);
316 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800317
318 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Soumya Bhat5c60deb2017-12-12 16:42:04 +0530319 if (pdev->enhanced_stats_en ||
320 pdev->am_copy_mode)
Anish Nataraj38a29562017-08-18 19:41:17 +0530321 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530322
Kai Chen6eca1a62017-01-12 10:17:53 -0800323 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700324 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700325 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800326 }
327 }
328 return;
329}
330
331/*
332 * dp_rx_mon_status_srng_process() - Process monitor status ring
333 * post the status ring buffer to Rx status Queue for later
334 * processing when status ring is filled with status TLV.
335 * Allocate a new buffer to status ring if the filled buffer
336 * is posted.
337 *
338 * @soc: core txrx main context
339 * @mac_id: mac_id which is one of 3 mac_ids
340 * @quota: No. of ring entry that can be serviced in one shot.
341
342 * Return: uint32_t: No. of ring entry that is processed.
343 */
344static inline uint32_t
345dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
346 uint32_t quota)
347{
348 struct dp_pdev *pdev = soc->pdev_list[mac_id];
349 void *hal_soc;
350 void *mon_status_srng;
351 void *rxdma_mon_status_ring_entry;
352 QDF_STATUS status;
353 uint32_t work_done = 0;
354
Kai Chen6eca1a62017-01-12 10:17:53 -0800355 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
356
357 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700358 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
359
360 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700361 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700362 __func__, __LINE__, mon_status_srng);
363 return work_done;
364 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800365
366 hal_soc = soc->hal_soc;
367
368 qdf_assert(hal_soc);
369
370 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
371 goto done;
372
373 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
374 * BUFFER_ADDR_INFO STRUCT
375 */
376 while (qdf_likely((rxdma_mon_status_ring_entry =
377 hal_srng_src_peek(hal_soc, mon_status_srng))
378 && quota--)) {
379 uint32_t rx_buf_cookie;
380 qdf_nbuf_t status_nbuf;
381 struct dp_rx_desc *rx_desc;
382 uint8_t *status_buf;
383 qdf_dma_addr_t paddr;
384 uint64_t buf_addr;
385
386 buf_addr =
387 (HAL_RX_BUFFER_ADDR_31_0_GET(
388 rxdma_mon_status_ring_entry) |
389 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
390 rxdma_mon_status_ring_entry)) << 32));
391
392 if (qdf_likely(buf_addr)) {
393
394 rx_buf_cookie =
395 HAL_RX_BUF_COOKIE_GET(
396 rxdma_mon_status_ring_entry);
397 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
398 rx_buf_cookie);
399
400 qdf_assert(rx_desc);
401
402 status_nbuf = rx_desc->nbuf;
403
404 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
405 QDF_DMA_FROM_DEVICE);
406
407 status_buf = qdf_nbuf_data(status_nbuf);
408
409 status = hal_get_rx_status_done(status_buf);
410
411 if (status != QDF_STATUS_SUCCESS) {
412 QDF_TRACE(QDF_MODULE_ID_DP,
413 QDF_TRACE_LEVEL_WARN,
414 "[%s][%d] status not done",
415 __func__, __LINE__);
416 break;
417 }
418 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
419
420 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
421 QDF_DMA_FROM_DEVICE);
422
423 /* Put the status_nbuf to queue */
424 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
425
426 } else {
427 union dp_rx_desc_list_elem_t *desc_list = NULL;
428 union dp_rx_desc_list_elem_t *tail = NULL;
429 struct rx_desc_pool *rx_desc_pool;
430 uint32_t num_alloc_desc;
431
432 rx_desc_pool = &soc->rx_desc_status[mac_id];
433
434 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
435 rx_desc_pool,
436 1,
437 &desc_list,
438 &tail);
439
440 rx_desc = &desc_list->rx_desc;
441 }
442
443 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530444 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800445 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
446
447 status_buf = qdf_nbuf_data(status_nbuf);
448
449 hal_clear_rx_status_done(status_buf);
450
451 qdf_nbuf_map_single(soc->osdev, status_nbuf,
452 QDF_DMA_BIDIRECTIONAL);
453 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
454
455 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700456 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800457
458 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
459 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
460
461 rxdma_mon_status_ring_entry =
462 hal_srng_src_get_next(hal_soc, mon_status_srng);
463 work_done++;
464 }
465done:
466
467 hal_srng_access_end(hal_soc, mon_status_srng);
468
469 return work_done;
470
471}
472/*
473 * dp_rx_mon_status_process() - Process monitor status ring and
474 * TLV in status ring.
475 *
476 * @soc: core txrx main context
477 * @mac_id: mac_id which is one of 3 mac_ids
478 * @quota: No. of ring entry that can be serviced in one shot.
479
480 * Return: uint32_t: No. of ring entry that is processed.
481 */
482static inline uint32_t
483dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
484 uint32_t work_done;
485
486 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700487 quota -= work_done;
488 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800489
490 return work_done;
491}
492/**
493 * dp_mon_process() - Main monitor mode processing roution.
494 * This call monitor status ring process then monitor
495 * destination ring process.
496 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
497 * @soc: core txrx main context
498 * @mac_id: mac_id which is one of 3 mac_ids
499 * @quota: No. of status ring entry that can be serviced in one shot.
500
501 * Return: uint32_t: No. of ring entry that is processed.
502 */
503uint32_t
504dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700505 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800506}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700507
Kai Chen6eca1a62017-01-12 10:17:53 -0800508/**
509 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
510 * @pdev: core txrx pdev context
511 *
512 * This function will detach DP RX status ring from
513 * main device context. will free DP Rx resources for
514 * status ring
515 *
516 * Return: QDF_STATUS_SUCCESS: success
517 * QDF_STATUS_E_RESOURCES: Error return
518 */
519QDF_STATUS
520dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
521{
522 uint8_t pdev_id = pdev->pdev_id;
523 struct dp_soc *soc = pdev->soc;
524 struct rx_desc_pool *rx_desc_pool;
525
526 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700527 if (rx_desc_pool->pool_size != 0) {
528 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
529 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800530
531 return QDF_STATUS_SUCCESS;
532}
533
534/*
535 * dp_rx_buffers_replenish() - replenish monitor status ring with
536 * rx nbufs called during dp rx
537 * monitor status ring initialization
538 *
539 * @soc: core txrx main context
540 * @mac_id: mac_id which is one of 3 mac_ids
541 * @dp_rxdma_srng: dp monitor status circular ring
542 * @rx_desc_pool; Pointer to Rx descriptor pool
543 * @num_req_buffers: number of buffer to be replenished
544 * @desc_list: list of descs if called from dp rx monitor status
545 * process or NULL during dp rx initialization or
546 * out of buffer interrupt
547 * @tail: tail of descs list
548 * @owner: who owns the nbuf (host, NSS etc...)
549 * Return: return success or failure
550 */
551static inline
552QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
553 uint32_t mac_id,
554 struct dp_srng *dp_rxdma_srng,
555 struct rx_desc_pool *rx_desc_pool,
556 uint32_t num_req_buffers,
557 union dp_rx_desc_list_elem_t **desc_list,
558 union dp_rx_desc_list_elem_t **tail,
559 uint8_t owner)
560{
561 uint32_t num_alloc_desc;
562 uint16_t num_desc_to_free = 0;
563 uint32_t num_entries_avail;
564 uint32_t count;
565 int sync_hw_ptr = 1;
566 qdf_dma_addr_t paddr;
567 qdf_nbuf_t rx_netbuf;
568 void *rxdma_ring_entry;
569 union dp_rx_desc_list_elem_t *next;
570 void *rxdma_srng;
571 uint8_t *status_buf;
572
573 rxdma_srng = dp_rxdma_srng->hal_srng;
574
575 qdf_assert(rxdma_srng);
576
Houston Hoffmanae850c62017-08-11 16:47:50 -0700577 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800578 "[%s][%d] requested %d buffers for replenish\n",
579 __func__, __LINE__, num_req_buffers);
580
581 /*
582 * if desc_list is NULL, allocate the descs from freelist
583 */
584 if (!(*desc_list)) {
585
586 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
587 rx_desc_pool,
588 num_req_buffers,
589 desc_list,
590 tail);
591
592 if (!num_alloc_desc) {
593 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
594 "[%s][%d] no free rx_descs in freelist\n",
595 __func__, __LINE__);
596 return QDF_STATUS_E_NOMEM;
597 }
598
Houston Hoffmanae850c62017-08-11 16:47:50 -0700599 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800600 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
601 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700602
Kai Chen6eca1a62017-01-12 10:17:53 -0800603 num_req_buffers = num_alloc_desc;
604 }
605
606 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
607 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
608 rxdma_srng, sync_hw_ptr);
609
Houston Hoffmanae850c62017-08-11 16:47:50 -0700610 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800611 "[%s][%d] no of availble entries in rxdma ring: %d\n",
612 __func__, __LINE__, num_entries_avail);
613
614 if (num_entries_avail < num_req_buffers) {
615 num_desc_to_free = num_req_buffers - num_entries_avail;
616 num_req_buffers = num_entries_avail;
617 }
618
619 for (count = 0; count < num_req_buffers; count++) {
620 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
621 rxdma_srng);
622
623 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
624 RX_BUFFER_SIZE,
625 RX_BUFFER_RESERVATION,
626 RX_BUFFER_ALIGNMENT,
627 FALSE);
628
629 status_buf = qdf_nbuf_data(rx_netbuf);
630 hal_clear_rx_status_done(status_buf);
631
632 memset(status_buf, 0, RX_BUFFER_SIZE);
633
634 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
635 QDF_DMA_BIDIRECTIONAL);
636
637 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
638
639 next = (*desc_list)->next;
640
641 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700642 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800643 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
644 (*desc_list)->rx_desc.cookie, owner);
645
Karunakar Dasineni40555682017-03-26 22:44:39 -0700646 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700647 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
648 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800649 __func__, __LINE__, &(*desc_list)->rx_desc,
650 (*desc_list)->rx_desc.cookie, rx_netbuf,
651 status_buf, (void *)paddr);
652
653 *desc_list = next;
654 }
655
656 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
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 "successfully replenished %d buffers\n", num_req_buffers);
660
Houston Hoffmanae850c62017-08-11 16:47:50 -0700661 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800662 "%d rx desc added back to free list\n", num_desc_to_free);
663
Houston Hoffmanae850c62017-08-11 16:47:50 -0700664 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700665 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800666 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
667 (*desc_list)->rx_desc.cookie);
668
669 /*
670 * add any available free desc back to the free list
671 */
672 if (*desc_list) {
673 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
674 mac_id, rx_desc_pool);
675 }
676
677 return QDF_STATUS_SUCCESS;
678}
679/**
680 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
681 * @pdev: core txrx pdev context
682 *
683 * This function will attach a DP RX monitor status ring into pDEV
684 * and replenish monitor status ring with buffer.
685 *
686 * Return: QDF_STATUS_SUCCESS: success
687 * QDF_STATUS_E_RESOURCES: Error return
688 */
689QDF_STATUS
690dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
691 uint8_t pdev_id = pdev->pdev_id;
692 struct dp_soc *soc = pdev->soc;
693 union dp_rx_desc_list_elem_t *desc_list = NULL;
694 union dp_rx_desc_list_elem_t *tail = NULL;
695 struct dp_srng *rxdma_srng;
696 uint32_t rxdma_entries;
697 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700698 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800699
700 rxdma_srng = &pdev->rxdma_mon_status_ring;
701
702 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
703 soc->hal_soc, RXDMA_MONITOR_STATUS);
704
705 rx_desc_pool = &soc->rx_desc_status[pdev_id];
706
Houston Hoffman41b912c2017-08-30 14:27:51 -0700707 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800708 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
709 __func__, pdev_id, rxdma_entries);
710
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700711 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
712 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700713 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700714 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
715 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
716 return status;
717 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800718
Houston Hoffman41b912c2017-08-30 14:27:51 -0700719 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800720 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
721 __func__, pdev_id);
722
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700723 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
724 rx_desc_pool, rxdma_entries, &desc_list, &tail,
725 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700726 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700727 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
728 "%s: dp_rx_buffers_replenish() failed \n", __func__);
729 return status;
730 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800731
732 qdf_nbuf_queue_init(&pdev->rx_status_q);
733
734 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700735 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
736 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800737
738 return QDF_STATUS_SUCCESS;
739}