blob: b31fab379b7471b6e19e3bb7851e833d927c2f35 [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);
126 DP_STATS_INC(peer, rx.sgi_count[ppdu->u.gi], 1);
127 DP_STATS_INC(peer, rx.bw[ppdu->u.bw], num_msdu);
128 DP_STATS_INCC(peer, rx.ampdu_cnt, 1, ppdu->is_ampdu);
129 DP_STATS_INCC(peer, rx.non_ampdu_cnt, 1, !(ppdu->is_ampdu));
130 DP_STATS_INCC(peer,
131 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
132 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
133 DP_STATS_INCC(peer,
134 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
135 ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
136 DP_STATS_INCC(peer,
137 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
138 ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
139 DP_STATS_INCC(peer,
140 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
141 ((mcs < MAX_MCS_11B) && (preamble == DOT11_B)));
142 DP_STATS_INCC(peer,
143 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
144 ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
145 DP_STATS_INCC(peer,
146 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
147 ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
148 DP_STATS_INCC(peer,
149 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
150 ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
151 DP_STATS_INCC(peer,
152 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
153 ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
154 DP_STATS_INCC(peer,
155 rx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
156 ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
157 DP_STATS_INCC(peer,
158 rx.pkt_type[preamble].mcs_count[mcs], num_msdu,
159 ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
160 DP_STATS_INC(peer, rx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], 1);
161
162 if (soc->cdp_soc.ol_ops->update_dp_stats) {
163 soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
164 &peer->stats, ppdu->peer_id,
165 UPDATE_PEER_STATS);
166 }
167}
168#endif
Anish Nataraj38a29562017-08-18 19:41:17 +0530169
170/**
171* dp_rx_handle_ppdu_stats() - Allocate and deliver ppdu stats to cdp layer
172* @soc: core txrx main context
173* @pdev: pdev strcuture
174* @ppdu_info: structure for rx ppdu ring
175*
176* Return: none
177*/
178#ifdef FEATURE_PERPKT_INFO
179static inline void
180dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
181 struct hal_rx_ppdu_info *ppdu_info)
182{
183 qdf_nbuf_t ppdu_nbuf;
184 struct dp_peer *peer;
185 struct cdp_rx_indication_ppdu *cdp_rx_ppdu;
186
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530187 ppdu_nbuf = qdf_nbuf_alloc(soc->osdev,
Anish Nataraj38a29562017-08-18 19:41:17 +0530188 sizeof(struct hal_rx_ppdu_info), 0, 0, FALSE);
189 if (ppdu_nbuf) {
190 dp_rx_populate_cdp_indication_ppdu(soc, ppdu_info, ppdu_nbuf);
191 qdf_nbuf_put_tail(ppdu_nbuf,
192 sizeof(struct cdp_rx_indication_ppdu));
193 cdp_rx_ppdu = (struct cdp_rx_indication_ppdu *)ppdu_nbuf->data;
194
195 peer = dp_peer_find_by_id(soc, cdp_rx_ppdu->peer_id);
196 if (peer && cdp_rx_ppdu->peer_id != HTT_INVALID_PEER) {
Pamidipati, Vijay57a435a2017-10-17 11:03:39 +0530197 dp_rx_stats_update(soc, peer, cdp_rx_ppdu);
Anish Nataraj38a29562017-08-18 19:41:17 +0530198 dp_wdi_event_handler(WDI_EVENT_RX_PPDU_DESC, soc,
199 ppdu_nbuf, cdp_rx_ppdu->peer_id,
200 WDI_NO_VAL, pdev->pdev_id);
201 } else
202 qdf_nbuf_free(ppdu_nbuf);
203 }
204}
205#else
206static inline void
207dp_rx_handle_ppdu_stats(struct dp_soc *soc, struct dp_pdev *pdev,
208 struct hal_rx_ppdu_info *ppdu_info)
209{
210}
211#endif
212
213/**
Kai Chen6eca1a62017-01-12 10:17:53 -0800214* dp_rx_mon_status_process_tlv() - Process status TLV in status
215* buffer on Rx status Queue posted by status SRNG processing.
216* @soc: core txrx main context
217* @mac_id: mac_id which is one of 3 mac_ids _ring
218*
219* Return: none
220*/
221static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -0700222dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
223 uint32_t quota)
224{
Kai Chen6eca1a62017-01-12 10:17:53 -0800225 struct dp_pdev *pdev = soc->pdev_list[mac_id];
226 struct hal_rx_ppdu_info *ppdu_info;
227 qdf_nbuf_t status_nbuf;
228 uint8_t *rx_tlv;
229 uint8_t *rx_tlv_start;
Kai Chenad516ae2017-09-08 18:35:47 -0700230 uint32_t tlv_status = HAL_TLV_STATUS_BUF_DONE;
Kai Chen6eca1a62017-01-12 10:17:53 -0800231
Kai Chen6eca1a62017-01-12 10:17:53 -0800232 ppdu_info = &pdev->ppdu_info;
233
234 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
235 return;
236
237 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
238
239 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
240 rx_tlv = qdf_nbuf_data(status_nbuf);
241 rx_tlv_start = rx_tlv;
242
Keyur Parekhfad6d082017-05-07 08:54:47 -0700243#if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
244#ifndef REMOVE_PKT_LOG
245 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
Keyur Parekhdb0fa142017-07-13 19:40:22 -0700246 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, mac_id);
Keyur Parekhfad6d082017-05-07 08:54:47 -0700247#endif
248#endif
Pamidipati, Vijayd7eb83e2017-09-20 21:19:56 +0530249 if ((pdev->monitor_vdev != NULL) || (pdev->enhanced_stats_en)) {
Kai Chen6eca1a62017-01-12 10:17:53 -0800250
Keyur Parekhfad6d082017-05-07 08:54:47 -0700251 do {
252 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
253 ppdu_info);
254 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -0800255
Keyur Parekhfad6d082017-05-07 08:54:47 -0700256 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
257 break;
Kai Chen6eca1a62017-01-12 10:17:53 -0800258
Keyur Parekhfad6d082017-05-07 08:54:47 -0700259 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
260 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800261 qdf_nbuf_free(status_nbuf);
262
263 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Anish Nataraj38a29562017-08-18 19:41:17 +0530264 if (pdev->enhanced_stats_en)
265 dp_rx_handle_ppdu_stats(soc, pdev, ppdu_info);
Kai Chen6eca1a62017-01-12 10:17:53 -0800266 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700267 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -0700268 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -0800269 }
270 }
271 return;
272}
273
274/*
275 * dp_rx_mon_status_srng_process() - Process monitor status ring
276 * post the status ring buffer to Rx status Queue for later
277 * processing when status ring is filled with status TLV.
278 * Allocate a new buffer to status ring if the filled buffer
279 * is posted.
280 *
281 * @soc: core txrx main context
282 * @mac_id: mac_id which is one of 3 mac_ids
283 * @quota: No. of ring entry that can be serviced in one shot.
284
285 * Return: uint32_t: No. of ring entry that is processed.
286 */
287static inline uint32_t
288dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
289 uint32_t quota)
290{
291 struct dp_pdev *pdev = soc->pdev_list[mac_id];
292 void *hal_soc;
293 void *mon_status_srng;
294 void *rxdma_mon_status_ring_entry;
295 QDF_STATUS status;
296 uint32_t work_done = 0;
297
Kai Chen6eca1a62017-01-12 10:17:53 -0800298 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
299
300 qdf_assert(mon_status_srng);
Houston Hoffman648a9182017-05-21 23:27:50 -0700301 if (!mon_status_srng || !hal_srng_initialized(mon_status_srng)) {
302
303 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700304 "%s %d : HAL Monitor Destination Ring Init Failed -- %pK\n",
Houston Hoffman648a9182017-05-21 23:27:50 -0700305 __func__, __LINE__, mon_status_srng);
306 return work_done;
307 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800308
309 hal_soc = soc->hal_soc;
310
311 qdf_assert(hal_soc);
312
313 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
314 goto done;
315
316 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
317 * BUFFER_ADDR_INFO STRUCT
318 */
319 while (qdf_likely((rxdma_mon_status_ring_entry =
320 hal_srng_src_peek(hal_soc, mon_status_srng))
321 && quota--)) {
322 uint32_t rx_buf_cookie;
323 qdf_nbuf_t status_nbuf;
324 struct dp_rx_desc *rx_desc;
325 uint8_t *status_buf;
326 qdf_dma_addr_t paddr;
327 uint64_t buf_addr;
328
329 buf_addr =
330 (HAL_RX_BUFFER_ADDR_31_0_GET(
331 rxdma_mon_status_ring_entry) |
332 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
333 rxdma_mon_status_ring_entry)) << 32));
334
335 if (qdf_likely(buf_addr)) {
336
337 rx_buf_cookie =
338 HAL_RX_BUF_COOKIE_GET(
339 rxdma_mon_status_ring_entry);
340 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
341 rx_buf_cookie);
342
343 qdf_assert(rx_desc);
344
345 status_nbuf = rx_desc->nbuf;
346
347 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
348 QDF_DMA_FROM_DEVICE);
349
350 status_buf = qdf_nbuf_data(status_nbuf);
351
352 status = hal_get_rx_status_done(status_buf);
353
354 if (status != QDF_STATUS_SUCCESS) {
355 QDF_TRACE(QDF_MODULE_ID_DP,
356 QDF_TRACE_LEVEL_WARN,
357 "[%s][%d] status not done",
358 __func__, __LINE__);
359 break;
360 }
361 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
362
363 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
364 QDF_DMA_FROM_DEVICE);
365
366 /* Put the status_nbuf to queue */
367 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
368
369 } else {
370 union dp_rx_desc_list_elem_t *desc_list = NULL;
371 union dp_rx_desc_list_elem_t *tail = NULL;
372 struct rx_desc_pool *rx_desc_pool;
373 uint32_t num_alloc_desc;
374
375 rx_desc_pool = &soc->rx_desc_status[mac_id];
376
377 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
378 rx_desc_pool,
379 1,
380 &desc_list,
381 &tail);
382
383 rx_desc = &desc_list->rx_desc;
384 }
385
386 /* Allocate a new skb */
Tallapragada Kalyana867edf2017-11-14 12:26:41 +0530387 status_nbuf = qdf_nbuf_alloc(soc->osdev, RX_BUFFER_SIZE,
Kai Chen6eca1a62017-01-12 10:17:53 -0800388 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
389
390 status_buf = qdf_nbuf_data(status_nbuf);
391
392 hal_clear_rx_status_done(status_buf);
393
394 qdf_nbuf_map_single(soc->osdev, status_nbuf,
395 QDF_DMA_BIDIRECTIONAL);
396 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
397
398 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700399 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800400
401 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
402 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
403
404 rxdma_mon_status_ring_entry =
405 hal_srng_src_get_next(hal_soc, mon_status_srng);
406 work_done++;
407 }
408done:
409
410 hal_srng_access_end(hal_soc, mon_status_srng);
411
412 return work_done;
413
414}
415/*
416 * dp_rx_mon_status_process() - Process monitor status ring and
417 * TLV in status ring.
418 *
419 * @soc: core txrx main context
420 * @mac_id: mac_id which is one of 3 mac_ids
421 * @quota: No. of ring entry that can be serviced in one shot.
422
423 * Return: uint32_t: No. of ring entry that is processed.
424 */
425static inline uint32_t
426dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
427 uint32_t work_done;
428
429 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700430 quota -= work_done;
431 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800432
433 return work_done;
434}
435/**
436 * dp_mon_process() - Main monitor mode processing roution.
437 * This call monitor status ring process then monitor
438 * destination ring process.
439 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
440 * @soc: core txrx main context
441 * @mac_id: mac_id which is one of 3 mac_ids
442 * @quota: No. of status ring entry that can be serviced in one shot.
443
444 * Return: uint32_t: No. of ring entry that is processed.
445 */
446uint32_t
447dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700448 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800449}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700450
Kai Chen6eca1a62017-01-12 10:17:53 -0800451/**
452 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
453 * @pdev: core txrx pdev context
454 *
455 * This function will detach DP RX status ring from
456 * main device context. will free DP Rx resources for
457 * status ring
458 *
459 * Return: QDF_STATUS_SUCCESS: success
460 * QDF_STATUS_E_RESOURCES: Error return
461 */
462QDF_STATUS
463dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
464{
465 uint8_t pdev_id = pdev->pdev_id;
466 struct dp_soc *soc = pdev->soc;
467 struct rx_desc_pool *rx_desc_pool;
468
469 rx_desc_pool = &soc->rx_desc_status[pdev_id];
psimhaeae1b412017-08-25 16:10:13 -0700470 if (rx_desc_pool->pool_size != 0) {
471 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
472 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800473
474 return QDF_STATUS_SUCCESS;
475}
476
477/*
478 * dp_rx_buffers_replenish() - replenish monitor status ring with
479 * rx nbufs called during dp rx
480 * monitor status ring initialization
481 *
482 * @soc: core txrx main context
483 * @mac_id: mac_id which is one of 3 mac_ids
484 * @dp_rxdma_srng: dp monitor status circular ring
485 * @rx_desc_pool; Pointer to Rx descriptor pool
486 * @num_req_buffers: number of buffer to be replenished
487 * @desc_list: list of descs if called from dp rx monitor status
488 * process or NULL during dp rx initialization or
489 * out of buffer interrupt
490 * @tail: tail of descs list
491 * @owner: who owns the nbuf (host, NSS etc...)
492 * Return: return success or failure
493 */
494static inline
495QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
496 uint32_t mac_id,
497 struct dp_srng *dp_rxdma_srng,
498 struct rx_desc_pool *rx_desc_pool,
499 uint32_t num_req_buffers,
500 union dp_rx_desc_list_elem_t **desc_list,
501 union dp_rx_desc_list_elem_t **tail,
502 uint8_t owner)
503{
504 uint32_t num_alloc_desc;
505 uint16_t num_desc_to_free = 0;
506 uint32_t num_entries_avail;
507 uint32_t count;
508 int sync_hw_ptr = 1;
509 qdf_dma_addr_t paddr;
510 qdf_nbuf_t rx_netbuf;
511 void *rxdma_ring_entry;
512 union dp_rx_desc_list_elem_t *next;
513 void *rxdma_srng;
514 uint8_t *status_buf;
515
516 rxdma_srng = dp_rxdma_srng->hal_srng;
517
518 qdf_assert(rxdma_srng);
519
Houston Hoffmanae850c62017-08-11 16:47:50 -0700520 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800521 "[%s][%d] requested %d buffers for replenish\n",
522 __func__, __LINE__, num_req_buffers);
523
524 /*
525 * if desc_list is NULL, allocate the descs from freelist
526 */
527 if (!(*desc_list)) {
528
529 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
530 rx_desc_pool,
531 num_req_buffers,
532 desc_list,
533 tail);
534
535 if (!num_alloc_desc) {
536 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
537 "[%s][%d] no free rx_descs in freelist\n",
538 __func__, __LINE__);
539 return QDF_STATUS_E_NOMEM;
540 }
541
Houston Hoffmanae850c62017-08-11 16:47:50 -0700542 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800543 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
544 num_alloc_desc);
Houston Hoffmanae850c62017-08-11 16:47:50 -0700545
Kai Chen6eca1a62017-01-12 10:17:53 -0800546 num_req_buffers = num_alloc_desc;
547 }
548
549 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
550 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
551 rxdma_srng, sync_hw_ptr);
552
Houston Hoffmanae850c62017-08-11 16:47:50 -0700553 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800554 "[%s][%d] no of availble entries in rxdma ring: %d\n",
555 __func__, __LINE__, num_entries_avail);
556
557 if (num_entries_avail < num_req_buffers) {
558 num_desc_to_free = num_req_buffers - num_entries_avail;
559 num_req_buffers = num_entries_avail;
560 }
561
562 for (count = 0; count < num_req_buffers; count++) {
563 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
564 rxdma_srng);
565
566 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
567 RX_BUFFER_SIZE,
568 RX_BUFFER_RESERVATION,
569 RX_BUFFER_ALIGNMENT,
570 FALSE);
571
572 status_buf = qdf_nbuf_data(rx_netbuf);
573 hal_clear_rx_status_done(status_buf);
574
575 memset(status_buf, 0, RX_BUFFER_SIZE);
576
577 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
578 QDF_DMA_BIDIRECTIONAL);
579
580 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
581
582 next = (*desc_list)->next;
583
584 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700585 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800586 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
587 (*desc_list)->rx_desc.cookie, owner);
588
Karunakar Dasineni40555682017-03-26 22:44:39 -0700589 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700590 "[%s][%d] rx_desc=%pK, cookie=%d, nbuf=%pK, \
591 status_buf=%pK paddr=%pK\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800592 __func__, __LINE__, &(*desc_list)->rx_desc,
593 (*desc_list)->rx_desc.cookie, rx_netbuf,
594 status_buf, (void *)paddr);
595
596 *desc_list = next;
597 }
598
599 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
600
Houston Hoffmanae850c62017-08-11 16:47:50 -0700601 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800602 "successfully replenished %d buffers\n", num_req_buffers);
603
Houston Hoffmanae850c62017-08-11 16:47:50 -0700604 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800605 "%d rx desc added back to free list\n", num_desc_to_free);
606
Houston Hoffmanae850c62017-08-11 16:47:50 -0700607 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Jeff Johnson3f217e22017-09-18 10:13:35 -0700608 "[%s][%d] desc_list=%pK, tail=%pK rx_desc=%pK, cookie=%d\n",
Kai Chen6eca1a62017-01-12 10:17:53 -0800609 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
610 (*desc_list)->rx_desc.cookie);
611
612 /*
613 * add any available free desc back to the free list
614 */
615 if (*desc_list) {
616 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
617 mac_id, rx_desc_pool);
618 }
619
620 return QDF_STATUS_SUCCESS;
621}
622/**
623 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
624 * @pdev: core txrx pdev context
625 *
626 * This function will attach a DP RX monitor status ring into pDEV
627 * and replenish monitor status ring with buffer.
628 *
629 * Return: QDF_STATUS_SUCCESS: success
630 * QDF_STATUS_E_RESOURCES: Error return
631 */
632QDF_STATUS
633dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
634 uint8_t pdev_id = pdev->pdev_id;
635 struct dp_soc *soc = pdev->soc;
636 union dp_rx_desc_list_elem_t *desc_list = NULL;
637 union dp_rx_desc_list_elem_t *tail = NULL;
638 struct dp_srng *rxdma_srng;
639 uint32_t rxdma_entries;
640 struct rx_desc_pool *rx_desc_pool;
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700641 QDF_STATUS status;
Kai Chen6eca1a62017-01-12 10:17:53 -0800642
643 rxdma_srng = &pdev->rxdma_mon_status_ring;
644
645 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
646 soc->hal_soc, RXDMA_MONITOR_STATUS);
647
648 rx_desc_pool = &soc->rx_desc_status[pdev_id];
649
Houston Hoffman41b912c2017-08-30 14:27:51 -0700650 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800651 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
652 __func__, pdev_id, rxdma_entries);
653
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700654 status = dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1,
655 rx_desc_pool);
Ravi Joshi73a05512017-07-10 13:53:32 -0700656 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700657 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
658 "%s: dp_rx_desc_pool_alloc() failed \n", __func__);
659 return status;
660 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800661
Houston Hoffman41b912c2017-08-30 14:27:51 -0700662 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
Kai Chen6eca1a62017-01-12 10:17:53 -0800663 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
664 __func__, pdev_id);
665
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700666 status = dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
667 rx_desc_pool, rxdma_entries, &desc_list, &tail,
668 HAL_RX_BUF_RBM_SW3_BM);
Ravi Joshi73a05512017-07-10 13:53:32 -0700669 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshia9ebe0a2017-06-17 16:43:02 -0700670 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
671 "%s: dp_rx_buffers_replenish() failed \n", __func__);
672 return status;
673 }
Kai Chen6eca1a62017-01-12 10:17:53 -0800674
675 qdf_nbuf_queue_init(&pdev->rx_status_q);
676
677 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700678 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
679 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800680
681 return QDF_STATUS_SUCCESS;
682}