blob: df4fba1245ae5ce0b52128d3e7063bddf24bb26e [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"
26#include "ieee80211.h"
27#include "dp_rx_mon.h"
Keyur Parekhfad6d082017-05-07 08:54:47 -070028#include "dp_internal.h"
29#include "qdf_mem.h" /* qdf_mem_malloc,free */
Kai Chen6eca1a62017-01-12 10:17:53 -080030
Kai Chen6eca1a62017-01-12 10:17:53 -080031/**
32* dp_rx_mon_status_process_tlv() - Process status TLV in status
33* buffer on Rx status Queue posted by status SRNG processing.
34* @soc: core txrx main context
35* @mac_id: mac_id which is one of 3 mac_ids _ring
36*
37* Return: none
38*/
39static inline void
Karunakar Dasineni40555682017-03-26 22:44:39 -070040dp_rx_mon_status_process_tlv(struct dp_soc *soc, uint32_t mac_id,
41 uint32_t quota)
42{
Kai Chen6eca1a62017-01-12 10:17:53 -080043 struct dp_pdev *pdev = soc->pdev_list[mac_id];
44 struct hal_rx_ppdu_info *ppdu_info;
45 qdf_nbuf_t status_nbuf;
46 uint8_t *rx_tlv;
47 uint8_t *rx_tlv_start;
Keyur Parekhfad6d082017-05-07 08:54:47 -070048 uint32_t tlv_status = HAL_TLV_STATUS_DUMMY;
Kai Chen6eca1a62017-01-12 10:17:53 -080049
50#ifdef DP_INTR_POLL_BASED
51 if (!pdev)
52 return;
53#endif
54
55 ppdu_info = &pdev->ppdu_info;
56
57 if (pdev->mon_ppdu_status != DP_PPDU_STATUS_START)
58 return;
59
60 while (!qdf_nbuf_is_queue_empty(&pdev->rx_status_q)) {
61
62 status_nbuf = qdf_nbuf_queue_remove(&pdev->rx_status_q);
63 rx_tlv = qdf_nbuf_data(status_nbuf);
64 rx_tlv_start = rx_tlv;
65
Keyur Parekhfad6d082017-05-07 08:54:47 -070066#if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
67#ifndef REMOVE_PKT_LOG
68 dp_wdi_event_handler(WDI_EVENT_RX_DESC, soc,
69 status_nbuf, HTT_INVALID_PEER, WDI_NO_VAL, 0);
70#endif
71#endif
72 if (pdev->monitor_vdev != NULL) {
Kai Chen6eca1a62017-01-12 10:17:53 -080073
Keyur Parekhfad6d082017-05-07 08:54:47 -070074 do {
75 tlv_status = hal_rx_status_get_tlv_info(rx_tlv,
76 ppdu_info);
77 rx_tlv = hal_rx_status_get_next_tlv(rx_tlv);
Kai Chen6eca1a62017-01-12 10:17:53 -080078
Keyur Parekhfad6d082017-05-07 08:54:47 -070079 if ((rx_tlv - rx_tlv_start) >= RX_BUFFER_SIZE)
80 break;
Kai Chen6eca1a62017-01-12 10:17:53 -080081
Keyur Parekhfad6d082017-05-07 08:54:47 -070082 } while (tlv_status == HAL_TLV_STATUS_PPDU_NOT_DONE);
83 }
Kai Chen6eca1a62017-01-12 10:17:53 -080084 qdf_nbuf_free(status_nbuf);
85
86 if (tlv_status == HAL_TLV_STATUS_PPDU_DONE) {
Kai Chen6eca1a62017-01-12 10:17:53 -080087 pdev->mon_ppdu_status = DP_PPDU_STATUS_DONE;
Karunakar Dasineni40555682017-03-26 22:44:39 -070088 dp_rx_mon_dest_process(soc, mac_id, quota);
Kai Chencbe4c342017-06-12 20:06:35 -070089 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Kai Chen6eca1a62017-01-12 10:17:53 -080090 }
91 }
92 return;
93}
94
95/*
96 * dp_rx_mon_status_srng_process() - Process monitor status ring
97 * post the status ring buffer to Rx status Queue for later
98 * processing when status ring is filled with status TLV.
99 * Allocate a new buffer to status ring if the filled buffer
100 * is posted.
101 *
102 * @soc: core txrx main context
103 * @mac_id: mac_id which is one of 3 mac_ids
104 * @quota: No. of ring entry that can be serviced in one shot.
105
106 * Return: uint32_t: No. of ring entry that is processed.
107 */
108static inline uint32_t
109dp_rx_mon_status_srng_process(struct dp_soc *soc, uint32_t mac_id,
110 uint32_t quota)
111{
112 struct dp_pdev *pdev = soc->pdev_list[mac_id];
113 void *hal_soc;
114 void *mon_status_srng;
115 void *rxdma_mon_status_ring_entry;
116 QDF_STATUS status;
117 uint32_t work_done = 0;
118
119#ifdef DP_INTR_POLL_BASED
120 if (!pdev)
121 return work_done;
122#endif
123
124 mon_status_srng = pdev->rxdma_mon_status_ring.hal_srng;
125
126 qdf_assert(mon_status_srng);
127
128 hal_soc = soc->hal_soc;
129
130 qdf_assert(hal_soc);
131
132 if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_status_srng)))
133 goto done;
134
135 /* mon_status_ring_desc => WBM_BUFFER_RING STRUCT =>
136 * BUFFER_ADDR_INFO STRUCT
137 */
138 while (qdf_likely((rxdma_mon_status_ring_entry =
139 hal_srng_src_peek(hal_soc, mon_status_srng))
140 && quota--)) {
141 uint32_t rx_buf_cookie;
142 qdf_nbuf_t status_nbuf;
143 struct dp_rx_desc *rx_desc;
144 uint8_t *status_buf;
145 qdf_dma_addr_t paddr;
146 uint64_t buf_addr;
147
148 buf_addr =
149 (HAL_RX_BUFFER_ADDR_31_0_GET(
150 rxdma_mon_status_ring_entry) |
151 ((uint64_t)(HAL_RX_BUFFER_ADDR_39_32_GET(
152 rxdma_mon_status_ring_entry)) << 32));
153
154 if (qdf_likely(buf_addr)) {
155
156 rx_buf_cookie =
157 HAL_RX_BUF_COOKIE_GET(
158 rxdma_mon_status_ring_entry);
159 rx_desc = dp_rx_cookie_2_va_mon_status(soc,
160 rx_buf_cookie);
161
162 qdf_assert(rx_desc);
163
164 status_nbuf = rx_desc->nbuf;
165
166 qdf_nbuf_sync_for_cpu(soc->osdev, status_nbuf,
167 QDF_DMA_FROM_DEVICE);
168
169 status_buf = qdf_nbuf_data(status_nbuf);
170
171 status = hal_get_rx_status_done(status_buf);
172
173 if (status != QDF_STATUS_SUCCESS) {
174 QDF_TRACE(QDF_MODULE_ID_DP,
175 QDF_TRACE_LEVEL_WARN,
176 "[%s][%d] status not done",
177 __func__, __LINE__);
178 break;
179 }
180 qdf_nbuf_set_pktlen(status_nbuf, RX_BUFFER_SIZE);
181
182 qdf_nbuf_unmap_single(soc->osdev, status_nbuf,
183 QDF_DMA_FROM_DEVICE);
184
185 /* Put the status_nbuf to queue */
186 qdf_nbuf_queue_add(&pdev->rx_status_q, status_nbuf);
187
188 } else {
189 union dp_rx_desc_list_elem_t *desc_list = NULL;
190 union dp_rx_desc_list_elem_t *tail = NULL;
191 struct rx_desc_pool *rx_desc_pool;
192 uint32_t num_alloc_desc;
193
194 rx_desc_pool = &soc->rx_desc_status[mac_id];
195
196 num_alloc_desc = dp_rx_get_free_desc_list(soc, mac_id,
197 rx_desc_pool,
198 1,
199 &desc_list,
200 &tail);
201
202 rx_desc = &desc_list->rx_desc;
203 }
204
205 /* Allocate a new skb */
206 status_nbuf = qdf_nbuf_alloc(pdev->osif_pdev, RX_BUFFER_SIZE,
207 RX_BUFFER_RESERVATION, RX_BUFFER_ALIGNMENT, FALSE);
208
209 status_buf = qdf_nbuf_data(status_nbuf);
210
211 hal_clear_rx_status_done(status_buf);
212
213 qdf_nbuf_map_single(soc->osdev, status_nbuf,
214 QDF_DMA_BIDIRECTIONAL);
215 paddr = qdf_nbuf_get_frag_paddr(status_nbuf, 0);
216
217 rx_desc->nbuf = status_nbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700218 rx_desc->in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800219
220 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
221 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
222
223 rxdma_mon_status_ring_entry =
224 hal_srng_src_get_next(hal_soc, mon_status_srng);
225 work_done++;
226 }
227done:
228
229 hal_srng_access_end(hal_soc, mon_status_srng);
230
231 return work_done;
232
233}
234/*
235 * dp_rx_mon_status_process() - Process monitor status ring and
236 * TLV in status ring.
237 *
238 * @soc: core txrx main context
239 * @mac_id: mac_id which is one of 3 mac_ids
240 * @quota: No. of ring entry that can be serviced in one shot.
241
242 * Return: uint32_t: No. of ring entry that is processed.
243 */
244static inline uint32_t
245dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
246 uint32_t work_done;
247
248 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700249 quota -= work_done;
250 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800251
252 return work_done;
253}
254/**
255 * dp_mon_process() - Main monitor mode processing roution.
256 * This call monitor status ring process then monitor
257 * destination ring process.
258 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
259 * @soc: core txrx main context
260 * @mac_id: mac_id which is one of 3 mac_ids
261 * @quota: No. of status ring entry that can be serviced in one shot.
262
263 * Return: uint32_t: No. of ring entry that is processed.
264 */
265uint32_t
266dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700267 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800268}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700269
Kai Chen6eca1a62017-01-12 10:17:53 -0800270/**
271 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
272 * @pdev: core txrx pdev context
273 *
274 * This function will detach DP RX status ring from
275 * main device context. will free DP Rx resources for
276 * status ring
277 *
278 * Return: QDF_STATUS_SUCCESS: success
279 * QDF_STATUS_E_RESOURCES: Error return
280 */
281QDF_STATUS
282dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
283{
284 uint8_t pdev_id = pdev->pdev_id;
285 struct dp_soc *soc = pdev->soc;
286 struct rx_desc_pool *rx_desc_pool;
287
288 rx_desc_pool = &soc->rx_desc_status[pdev_id];
289 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
290
291 return QDF_STATUS_SUCCESS;
292}
293
294/*
295 * dp_rx_buffers_replenish() - replenish monitor status ring with
296 * rx nbufs called during dp rx
297 * monitor status ring initialization
298 *
299 * @soc: core txrx main context
300 * @mac_id: mac_id which is one of 3 mac_ids
301 * @dp_rxdma_srng: dp monitor status circular ring
302 * @rx_desc_pool; Pointer to Rx descriptor pool
303 * @num_req_buffers: number of buffer to be replenished
304 * @desc_list: list of descs if called from dp rx monitor status
305 * process or NULL during dp rx initialization or
306 * out of buffer interrupt
307 * @tail: tail of descs list
308 * @owner: who owns the nbuf (host, NSS etc...)
309 * Return: return success or failure
310 */
311static inline
312QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
313 uint32_t mac_id,
314 struct dp_srng *dp_rxdma_srng,
315 struct rx_desc_pool *rx_desc_pool,
316 uint32_t num_req_buffers,
317 union dp_rx_desc_list_elem_t **desc_list,
318 union dp_rx_desc_list_elem_t **tail,
319 uint8_t owner)
320{
321 uint32_t num_alloc_desc;
322 uint16_t num_desc_to_free = 0;
323 uint32_t num_entries_avail;
324 uint32_t count;
325 int sync_hw_ptr = 1;
326 qdf_dma_addr_t paddr;
327 qdf_nbuf_t rx_netbuf;
328 void *rxdma_ring_entry;
329 union dp_rx_desc_list_elem_t *next;
330 void *rxdma_srng;
331 uint8_t *status_buf;
332
333 rxdma_srng = dp_rxdma_srng->hal_srng;
334
335 qdf_assert(rxdma_srng);
336
337 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
338 "[%s][%d] requested %d buffers for replenish\n",
339 __func__, __LINE__, num_req_buffers);
340
341 /*
342 * if desc_list is NULL, allocate the descs from freelist
343 */
344 if (!(*desc_list)) {
345
346 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
347 rx_desc_pool,
348 num_req_buffers,
349 desc_list,
350 tail);
351
352 if (!num_alloc_desc) {
353 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
354 "[%s][%d] no free rx_descs in freelist\n",
355 __func__, __LINE__);
356 return QDF_STATUS_E_NOMEM;
357 }
358
359 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
360 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
361 num_alloc_desc);
362 num_req_buffers = num_alloc_desc;
363 }
364
365 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
366 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
367 rxdma_srng, sync_hw_ptr);
368
369 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
370 "[%s][%d] no of availble entries in rxdma ring: %d\n",
371 __func__, __LINE__, num_entries_avail);
372
373 if (num_entries_avail < num_req_buffers) {
374 num_desc_to_free = num_req_buffers - num_entries_avail;
375 num_req_buffers = num_entries_avail;
376 }
377
378 for (count = 0; count < num_req_buffers; count++) {
379 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
380 rxdma_srng);
381
382 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
383 RX_BUFFER_SIZE,
384 RX_BUFFER_RESERVATION,
385 RX_BUFFER_ALIGNMENT,
386 FALSE);
387
388 status_buf = qdf_nbuf_data(rx_netbuf);
389 hal_clear_rx_status_done(status_buf);
390
391 memset(status_buf, 0, RX_BUFFER_SIZE);
392
393 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
394 QDF_DMA_BIDIRECTIONAL);
395
396 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
397
398 next = (*desc_list)->next;
399
400 (*desc_list)->rx_desc.nbuf = rx_netbuf;
Pramod Simha59fcb312017-06-22 17:43:16 -0700401 (*desc_list)->rx_desc.in_use = 1;
Kai Chen6eca1a62017-01-12 10:17:53 -0800402 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
403 (*desc_list)->rx_desc.cookie, owner);
404
Karunakar Dasineni40555682017-03-26 22:44:39 -0700405 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800406 "[%s][%d] rx_desc=%p, cookie=%d, nbuf=%p, \
407 status_buf=%p paddr=%p\n",
408 __func__, __LINE__, &(*desc_list)->rx_desc,
409 (*desc_list)->rx_desc.cookie, rx_netbuf,
410 status_buf, (void *)paddr);
411
412 *desc_list = next;
413 }
414
415 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
416
417 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
418 "successfully replenished %d buffers\n", num_req_buffers);
419
420 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
421 "%d rx desc added back to free list\n", num_desc_to_free);
422
423 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
424 "[%s][%d] desc_list=%p, tail=%p rx_desc=%p, cookie=%d\n",
425 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
426 (*desc_list)->rx_desc.cookie);
427
428 /*
429 * add any available free desc back to the free list
430 */
431 if (*desc_list) {
432 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
433 mac_id, rx_desc_pool);
434 }
435
436 return QDF_STATUS_SUCCESS;
437}
438/**
439 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
440 * @pdev: core txrx pdev context
441 *
442 * This function will attach a DP RX monitor status ring into pDEV
443 * and replenish monitor status ring with buffer.
444 *
445 * Return: QDF_STATUS_SUCCESS: success
446 * QDF_STATUS_E_RESOURCES: Error return
447 */
448QDF_STATUS
449dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
450 uint8_t pdev_id = pdev->pdev_id;
451 struct dp_soc *soc = pdev->soc;
452 union dp_rx_desc_list_elem_t *desc_list = NULL;
453 union dp_rx_desc_list_elem_t *tail = NULL;
454 struct dp_srng *rxdma_srng;
455 uint32_t rxdma_entries;
456 struct rx_desc_pool *rx_desc_pool;
457
458 rxdma_srng = &pdev->rxdma_mon_status_ring;
459
460 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
461 soc->hal_soc, RXDMA_MONITOR_STATUS);
462
463 rx_desc_pool = &soc->rx_desc_status[pdev_id];
464
465 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
466 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
467 __func__, pdev_id, rxdma_entries);
468
469 dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1, rx_desc_pool);
470
471 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
472 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
473 __func__, pdev_id);
474
475 dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
476 rx_desc_pool, rxdma_entries, &desc_list, &tail,
477 HAL_RX_BUF_RBM_SW3_BM);
478
479 qdf_nbuf_queue_init(&pdev->rx_status_q);
480
481 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700482 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
483 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800484
485 return QDF_STATUS_SUCCESS;
486}