blob: 6861b15b8133d101c72c87f6e564bb82f025cc06 [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;
125 DP_STATS_UPD(peer, rx.rssi, ppdu->rssi);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530126 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530127 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
Pranita Solankea12b4b32017-11-20 23:04:14 +0530128 DP_STATS_INCC(peer, rx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
129 DP_STATS_INCC(peer, rx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
130 DP_STATS_UPD(peer, rx.rx_rate, mcs);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530131 DP_STATS_INCC(peer,
132 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
133 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
134 DP_STATS_INCC(peer,
135 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530136 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530137 DP_STATS_INCC(peer,
138 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
139 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
140 DP_STATS_INCC(peer,
141 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530142 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530143 DP_STATS_INCC(peer,
144 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
145 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
146 DP_STATS_INCC(peer,
147 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
Pranita Solankea12b4b32017-11-20 23:04:14 +0530148 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530149 DP_STATS_INCC(peer,
150 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
151 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
152 DP_STATS_INCC(peer,
153 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
154 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
155 DP_STATS_INCC(peer,
156 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
157 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
158 DP_STATS_INCC(peer,
159 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
160 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
Pranita Solankea12b4b32017-11-20 23:04:14 +0530161 DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], num_msdu);
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530162
163 if (soc->cdp_soc.ol_ops->update_dp_stats) {
164 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
165 &peer->stats, ppdu->peer_id,
166 UPDATE_PEER_STATS);
167 }
168}
169#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530170
171/**
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530172* dp_rx_handle_am_copy_mode() - Allocate and deliver first MSDU payload
173* @soc: core txrx main context
174* @pdev: pdev strcuture
175* @ppdu_info: structure for rx ppdu ring
176*
177* Return: QDF_STATUS_SUCCESS - If nbuf to be freed by caller
178* QDF_STATUS_E_ALREADY - If nbuf not to be freed by caller
179*/
180#ifdef FEATURE_PERPKT_INFO
181static inline QDF_STATUS
182dp_rx_handle_am_copy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
183 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
184{
185 uint8_t size = 0;
186
187 if (ppdu_info->first_msdu_payload == NULL)
188 return QDF_STATUS_SUCCESS;
189
190 if (pdev->am_copy_id.rx_ppdu_id == ppdu_info->com_info.ppdu_id)
191 return QDF_STATUS_SUCCESS;
192
193 pdev->am_copy_id.rx_ppdu_id = ppdu_info->com_info.ppdu_id;
194
195 size = ppdu_info->first_msdu_payload - qdf_nbuf_data(nbuf);
196 ppdu_info->first_msdu_payload = NULL;
197 qdf_nbuf_pull_head(nbuf, size);
198 dp_wdi_event_handler(WDI_EVENT_RX_DATA, soc,
199 nbuf, HTT_INVALID_PEER, WDI_NO_VAL, pdev->pdev_id);
200 return QDF_STATUS_E_ALREADY;
201}
202#else
203static inline QDF_STATUS
204dp_rx_handle_am_copy_mode(struct dp_soc *soc, struct dp_pdev *pdev,
205 struct hal_rx_ppdu_info *ppdu_info, qdf_nbuf_t nbuf)
206{
207 return QDF_STATUS_SUCCESS;
208}
209#endif
210
211
212/**
Anish Nataraj38a29562017-08-18 19:41:17 +0530213* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
214* @soc: core txrx main context
215* @pdev: pdev strcuture
216* @ppdu_info: structure for rx ppdu ring
217*
218* Return: none
219*/
220#ifdef FEATURE_PERPKT_INFO
221static inline void
222dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
223 struct hal_rx_ppdu_info *ppdu_info)
224{
225 qdf_nbuf_t ppdu_nbuf;
226 struct dp_peer *peer;
227 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
228
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530229 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530230 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
231 if (ppdu_nbuf) {
232 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
233 qdf_nbuf_put_tail(ppdu_nbuf,
234 sizeof(struct cdp_rx_indication_ppdu));
235 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
236
237 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
238 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530239 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530240 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
241 ppdu_nbuf, cdp_rx_ppdu->peer_id,
242 WDI_NO_VAL, pdev->pdev_id);
243 } else
244 qdf_nbuf_free(ppdu_nbuf);
245 }
246}
247#else
248static inline void
249dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
250 struct hal_rx_ppdu_info *ppdu_info)
251{
252}
253#endif
254
255/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800256* dp_rx_mon_status_process_tlv() - Process status TLV in status
257* buffer on Rx status Queue posted by status SRNG processing.
258* @soc: core txrx main context
259* @mac_id: mac_id which is one of 3 mac_ids _ring
260*
261* Return: none
262*/
263static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700264dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
265 uint32_t quota)
266{
Kai Chen6eca1a62017-01-12 10:17:53 -0800267 struct dp_pdev *pdev = soc->pdev_list[mac_id];
268 struct hal_rx_ppdu_info *ppdu_info;
269 qdf_nbuf_t status_nbuf;
270 uint8_t *rx_tlv;
271 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700272 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530273 QDF_STATUS am_copy_status = QDF_STATUS_SUCCESS;
Kai Chen6eca1a62017-01-12 10:17:53 -0800274
Kai Chen6eca1a62017-01-12 10:17:53 -0800275 ppdu_info = &pdev->ppdu_info;
276
277 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
278 return;
279
280 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
281
282 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
283 rx_tlv = qdf_nbuf_data(status_nbuf);
284 rx_tlv_start = rx_tlv;
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700285
Keyur Parekhfad6d082017-05-07 08:54:47 -0700286#ifndef REMOVE_PKT_LOG
Venkata Sharath Chandra Manchala5a6f4292017-11-03 14:57:41 -0700287#if defined(WDI_EVENT_ENABLE)
Keyur Parekhfad6d082017-05-07 08:54:47 -0700288 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700289 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700290#endif
291#endif
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530292 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)
293 || (pdev->am_copy_mode)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800294
Keyur Parekhfad6d082017-05-07 08:54:47 -0700295 do {
296 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
297 ppdu_info);
298 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800299
Keyur Parekhfad6d082017-05-07 08:54:47 -0700300 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
301 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800302
Keyur Parekhfad6d082017-05-07 08:54:47 -0700303 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
304 }
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530305
306 if (pdev->am_copy_mode) {
307 am_copy_status = dp_rx_handle_am_copy_mode(soc,
308 pdev, ppdu_info, status_nbuf);
309 if (am_copy_status == QDF_STATUS_SUCCESS)
310 qdf_nbuf_free(status_nbuf);
311 } else {
312 qdf_nbuf_free(status_nbuf);
313 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800314
315 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Anish Nataraj38a29562017-08-18 19:41:17 +0530316 if (pdev->enhanced_stats_en)
317 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Soumya Bhat6fee59c2017-10-31 13:12:37 +0530318
Kai Chen6eca1a62017-01-12 10:17:53 -0800319 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700320 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700321 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800322 }
323 }
324 return;
325}
326
327/*
328 * dp_rx_mon_status_srng_process() - Process monitor status ring
329 * post the status ring buffer to Rx status Queue for later
330 * processing when status ring is filled with status TLV.
331 * Allocate a new buffer to status ring if the filled buffer
332 * is posted.
333 *
334 * @soc: core txrx main context
335 * @mac_id: mac_id which is one of 3 mac_ids
336 * @quota: No. of ring entry that can be serviced in one shot.
337
338 * Return: uint32_t: No. of ring entry that is processed.
339 */
340static inline uint32_t
341dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
342 uint32_t quota)
343{
344 struct dp_pdev *pdev = soc->pdev_list[mac_id];
345 void *hal_soc;
346 void *mon_status_srng;
347 void *rxdma_mon_status_ring_entry;
348 QDF_STATUS status;
349 uint32_t work_done = 0;
350
Kai Chen6eca1a62017-01-12 10:17:53 -0800351 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
352
353 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700354 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
355
356 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700357 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700358 __func__, __LINE__, mon_status_srng);
359 return work_done;
360 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800361
362 hal_soc = soc->hal_soc;
363
364 qdf_assert(hal_soc);
365
366 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
367 goto done;
368
369 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
370 * BUFFER_ADDR_INFO STRUCT
371 */
372 while (qdf_likely((rxdma_mon_status_ring_entry =
373 hal_srng_src_peek(hal_soc, mon_status_srng))
374 && quota--)) {
375 uint32_t rx_buf_cookie;
376 qdf_nbuf_t status_nbuf;
377 struct dp_rx_desc *rx_desc;
378 uint8_t *status_buf;
379 qdf_dma_addr_t paddr;
380 uint64_t buf_addr;
381
382 buf_addr =
383 (HAL_RX_BUFFER_ADDR_31_0_GET(
384 rxdma_mon_status_ring_entry) |
385 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
386 rxdma_mon_status_ring_entry)) << 32));
387
388 if (qdf_likely(buf_addr)) {
389
390 rx_buf_cookie =
391 HAL_RX_BUF_COOKIE_GET(
392 rxdma_mon_status_ring_entry);
393 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
394 rx_buf_cookie);
395
396 qdf_assert(rx_desc);
397
398 status_nbuf = rx_desc->nbuf;
399
400 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
401 QDF_DMA_FROM_DEVICE);
402
403 status_buf = qdf_nbuf_data(status_nbuf);
404
405 status = hal_get_rx_status_done(status_buf);
406
407 if (status != QDF_STATUS_SUCCESS) {
408 QDF_TRACE(QDF_MODULE_ID_DP,
409 QDF_TRACE_LEVEL_WARN,
410 "[%s][%d] status not done",
411 __func__, __LINE__);
412 break;
413 }
414 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
415
416 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
417 QDF_DMA_FROM_DEVICE);
418
419 /* Put the status_nbuf to queue */
420 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
421
422 } else {
423 union dp_rx_desc_list_elem_t *desc_list = NULL;
424 union dp_rx_desc_list_elem_t *tail = NULL;
425 struct rx_desc_pool *rx_desc_pool;
426 uint32_t num_alloc_desc;
427
428 rx_desc_pool = &soc->rx_desc_status[mac_id];
429
430 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
431 rx_desc_pool,
432 1,
433 &desc_list,
434 &tail);
435
436 rx_desc = &desc_list->rx_desc;
437 }
438
439 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530440 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800441 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
442
443 status_buf = qdf_nbuf_data(status_nbuf);
444
445 hal_clear_rx_status_done(status_buf);
446
447 qdf_nbuf_map_single(soc->osdev, status_nbuf,
448 QDF_DMA_BIDIRECTIONAL);
449 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
450
451 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700452 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800453
454 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
455 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
456
457 rxdma_mon_status_ring_entry =
458 hal_srng_src_get_next(hal_soc, mon_status_srng);
459 work_done++;
460 }
461done:
462
463 hal_srng_access_end(hal_soc, mon_status_srng);
464
465 return work_done;
466
467}
468/*
469 * dp_rx_mon_status_process() - Process monitor status ring and
470 * TLV in status ring.
471 *
472 * @soc: core txrx main context
473 * @mac_id: mac_id which is one of 3 mac_ids
474 * @quota: No. of ring entry that can be serviced in one shot.
475
476 * Return: uint32_t: No. of ring entry that is processed.
477 */
478static inline uint32_t
479dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
480 uint32_t work_done;
481
482 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700483 quota -= work_done;
484 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800485
486 return work_done;
487}
488/**
489 * dp_mon_process() - Main monitor mode processing roution.
490 * This call monitor status ring process then monitor
491 * destination ring process.
492 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
493 * @soc: core txrx main context
494 * @mac_id: mac_id which is one of 3 mac_ids
495 * @quota: No. of status ring entry that can be serviced in one shot.
496
497 * Return: uint32_t: No. of ring entry that is processed.
498 */
499uint32_t
500dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700501 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800502}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700503
Kai Chen6eca1a62017-01-12 10:17:53 -0800504/**
505 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
506 * @pdev: core txrx pdev context
507 *
508 * This function will detach DP RX status ring from
509 * main device context. will free DP Rx resources for
510 * status ring
511 *
512 * Return: QDF_STATUS_SUCCESS: success
513 * QDF_STATUS_E_RESOURCES: Error return
514 */
515QDF_STATUS
516dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
517{
518 uint8_t pdev_id = pdev->pdev_id;
519 struct dp_soc *soc = pdev->soc;
520 struct rx_desc_pool *rx_desc_pool;
521
522 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700523 if (rx_desc_pool->pool_size != 0) {
524 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
525 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800526
527 return QDF_STATUS_SUCCESS;
528}
529
530/*
531 * dp_rx_buffers_replenish() - replenish monitor status ring with
532 * rx nbufs called during dp rx
533 * monitor status ring initialization
534 *
535 * @soc: core txrx main context
536 * @mac_id: mac_id which is one of 3 mac_ids
537 * @dp_rxdma_srng: dp monitor status circular ring
538 * @rx_desc_pool; Pointer to Rx descriptor pool
539 * @num_req_buffers: number of buffer to be replenished
540 * @desc_list: list of descs if called from dp rx monitor status
541 * process or NULL during dp rx initialization or
542 * out of buffer interrupt
543 * @tail: tail of descs list
544 * @owner: who owns the nbuf (host, NSS etc...)
545 * Return: return success or failure
546 */
547static inline
548QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
549 uint32_t mac_id,
550 struct dp_srng *dp_rxdma_srng,
551 struct rx_desc_pool *rx_desc_pool,
552 uint32_t num_req_buffers,
553 union dp_rx_desc_list_elem_t **desc_list,
554 union dp_rx_desc_list_elem_t **tail,
555 uint8_t owner)
556{
557 uint32_t num_alloc_desc;
558 uint16_t num_desc_to_free = 0;
559 uint32_t num_entries_avail;
560 uint32_t count;
561 int sync_hw_ptr = 1;
562 qdf_dma_addr_t paddr;
563 qdf_nbuf_t rx_netbuf;
564 void *rxdma_ring_entry;
565 union dp_rx_desc_list_elem_t *next;
566 void *rxdma_srng;
567 uint8_t *status_buf;
568
569 rxdma_srng = dp_rxdma_srng->hal_srng;
570
571 qdf_assert(rxdma_srng);
572
Houston Hoffmanae850c62017-08-11 16:47:50 -0700573 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800574 "[%s][%d] requested %d buffers for replenish\n",
575 __func__, __LINE__, num_req_buffers);
576
577 /*
578 * if desc_list is NULL, allocate the descs from freelist
579 */
580 if (!(*desc_list)) {
581
582 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
583 rx_desc_pool,
584 num_req_buffers,
585 desc_list,
586 tail);
587
588 if (!num_alloc_desc) {
589 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
590 "[%s][%d] no free rx_descs in freelist\n",
591 __func__, __LINE__);
592 return QDF_STATUS_E_NOMEM;
593 }
594
Houston Hoffmanae850c62017-08-11 16:47:50 -0700595 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800596 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
597 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700598
Kai Chen6eca1a62017-01-12 10:17:53 -0800599 num_req_buffers = num_alloc_desc;
600 }
601
602 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
603 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
604 rxdma_srng, sync_hw_ptr);
605
Houston Hoffmanae850c62017-08-11 16:47:50 -0700606 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800607 "[%s][%d] no of availble entries in rxdma ring: %d\n",
608 __func__, __LINE__, num_entries_avail);
609
610 if (num_entries_avail < num_req_buffers) {
611 num_desc_to_free = num_req_buffers - num_entries_avail;
612 num_req_buffers = num_entries_avail;
613 }
614
615 for (count = 0; count < num_req_buffers; count++) {
616 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
617 rxdma_srng);
618
619 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
620 RX_BUFFER_SIZE,
621 RX_BUFFER_RESERVATION,
622 RX_BUFFER_ALIGNMENT,
623 FALSE);
624
625 status_buf = qdf_nbuf_data(rx_netbuf);
626 hal_clear_rx_status_done(status_buf);
627
628 memset(status_buf, 0, RX_BUFFER_SIZE);
629
630 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
631 QDF_DMA_BIDIRECTIONAL);
632
633 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
634
635 next = (*desc_list)->next;
636
637 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700638 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800639 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
640 (*desc_list)->rx_desc.cookie, owner);
641
Karunakar Dasineni40555682017-03-26 22:44:39 -0700642 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700643 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
644 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800645 __func__, __LINE__, &(*desc_list)->rx_desc,
646 (*desc_list)->rx_desc.cookie, rx_netbuf,
647 status_buf, (void *)paddr);
648
649 *desc_list = next;
650 }
651
652 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
653
Houston Hoffmanae850c62017-08-11 16:47:50 -0700654 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800655 "successfully replenished %d buffers\n", num_req_buffers);
656
Houston Hoffmanae850c62017-08-11 16:47:50 -0700657 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800658 "%d rx desc added back to free list\n", num_desc_to_free);
659
Houston Hoffmanae850c62017-08-11 16:47:50 -0700660 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700661 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800662 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
663 (*desc_list)->rx_desc.cookie);
664
665 /*
666 * add any available free desc back to the free list
667 */
668 if (*desc_list) {
669 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
670 mac_id, rx_desc_pool);
671 }
672
673 return QDF_STATUS_SUCCESS;
674}
675/**
676 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
677 * @pdev: core txrx pdev context
678 *
679 * This function will attach a DP RX monitor status ring into pDEV
680 * and replenish monitor status ring with buffer.
681 *
682 * Return: QDF_STATUS_SUCCESS: success
683 * QDF_STATUS_E_RESOURCES: Error return
684 */
685QDF_STATUS
686dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
687 uint8_t pdev_id = pdev->pdev_id;
688 struct dp_soc *soc = pdev->soc;
689 union dp_rx_desc_list_elem_t *desc_list = NULL;
690 union dp_rx_desc_list_elem_t *tail = NULL;
691 struct dp_srng *rxdma_srng;
692 uint32_t rxdma_entries;
693 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700694 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800695
696 rxdma_srng = &pdev->rxdma_mon_status_ring;
697
698 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
699 soc->hal_soc, RXDMA_MONITOR_STATUS);
700
701 rx_desc_pool = &soc->rx_desc_status[pdev_id];
702
Houston Hoffman41b912c2017-08-30 14:27:51 -0700703 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800704 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
705 __func__, pdev_id, rxdma_entries);
706
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700707 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
708 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700709 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700710 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
711 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
712 return status;
713 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800714
Houston Hoffman41b912c2017-08-30 14:27:51 -0700715 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800716 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
717 __func__, pdev_id);
718
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700719 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
720 rx_desc_pool, rxdma_entries, &desc_list, &tail,
721 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700722 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700723 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
724 "%s: dp_rx_buffers_replenish() failed \n", __func__);
725 return status;
726 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800727
728 qdf_nbuf_queue_init(&pdev->rx_status_q);
729
730 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700731 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
732 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800733
734 return QDF_STATUS_SUCCESS;
735}