blob: a56b4808c8a57f5ad3667dba20c8cb3fe8a1a24b [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;
218
219 hal_rxdma_buff_addr_info_set(rxdma_mon_status_ring_entry,
220 paddr, rx_desc->cookie, HAL_RX_BUF_RBM_SW3_BM);
221
222 rxdma_mon_status_ring_entry =
223 hal_srng_src_get_next(hal_soc, mon_status_srng);
224 work_done++;
225 }
226done:
227
228 hal_srng_access_end(hal_soc, mon_status_srng);
229
230 return work_done;
231
232}
233/*
234 * dp_rx_mon_status_process() - Process monitor status ring and
235 * TLV in status ring.
236 *
237 * @soc: core txrx main context
238 * @mac_id: mac_id which is one of 3 mac_ids
239 * @quota: No. of ring entry that can be serviced in one shot.
240
241 * Return: uint32_t: No. of ring entry that is processed.
242 */
243static inline uint32_t
244dp_rx_mon_status_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
245 uint32_t work_done;
246
247 work_done = dp_rx_mon_status_srng_process(soc, mac_id, quota);
Karunakar Dasineni40555682017-03-26 22:44:39 -0700248 quota -= work_done;
249 dp_rx_mon_status_process_tlv(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800250
251 return work_done;
252}
253/**
254 * dp_mon_process() - Main monitor mode processing roution.
255 * This call monitor status ring process then monitor
256 * destination ring process.
257 * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
258 * @soc: core txrx main context
259 * @mac_id: mac_id which is one of 3 mac_ids
260 * @quota: No. of status ring entry that can be serviced in one shot.
261
262 * Return: uint32_t: No. of ring entry that is processed.
263 */
264uint32_t
265dp_mon_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota) {
Karunakar Dasineni40555682017-03-26 22:44:39 -0700266 return dp_rx_mon_status_process(soc, mac_id, quota);
Kai Chen6eca1a62017-01-12 10:17:53 -0800267}
Karunakar Dasineni40555682017-03-26 22:44:39 -0700268
Kai Chen6eca1a62017-01-12 10:17:53 -0800269/**
270 * dp_rx_pdev_mon_detach() - detach dp rx for status ring
271 * @pdev: core txrx pdev context
272 *
273 * This function will detach DP RX status ring from
274 * main device context. will free DP Rx resources for
275 * status ring
276 *
277 * Return: QDF_STATUS_SUCCESS: success
278 * QDF_STATUS_E_RESOURCES: Error return
279 */
280QDF_STATUS
281dp_rx_pdev_mon_status_detach(struct dp_pdev *pdev)
282{
283 uint8_t pdev_id = pdev->pdev_id;
284 struct dp_soc *soc = pdev->soc;
285 struct rx_desc_pool *rx_desc_pool;
286
287 rx_desc_pool = &soc->rx_desc_status[pdev_id];
288 dp_rx_desc_pool_free(soc, pdev_id, rx_desc_pool);
289
290 return QDF_STATUS_SUCCESS;
291}
292
293/*
294 * dp_rx_buffers_replenish() - replenish monitor status ring with
295 * rx nbufs called during dp rx
296 * monitor status ring initialization
297 *
298 * @soc: core txrx main context
299 * @mac_id: mac_id which is one of 3 mac_ids
300 * @dp_rxdma_srng: dp monitor status circular ring
301 * @rx_desc_pool; Pointer to Rx descriptor pool
302 * @num_req_buffers: number of buffer to be replenished
303 * @desc_list: list of descs if called from dp rx monitor status
304 * process or NULL during dp rx initialization or
305 * out of buffer interrupt
306 * @tail: tail of descs list
307 * @owner: who owns the nbuf (host, NSS etc...)
308 * Return: return success or failure
309 */
310static inline
311QDF_STATUS dp_rx_mon_status_buffers_replenish(struct dp_soc *dp_soc,
312 uint32_t mac_id,
313 struct dp_srng *dp_rxdma_srng,
314 struct rx_desc_pool *rx_desc_pool,
315 uint32_t num_req_buffers,
316 union dp_rx_desc_list_elem_t **desc_list,
317 union dp_rx_desc_list_elem_t **tail,
318 uint8_t owner)
319{
320 uint32_t num_alloc_desc;
321 uint16_t num_desc_to_free = 0;
322 uint32_t num_entries_avail;
323 uint32_t count;
324 int sync_hw_ptr = 1;
325 qdf_dma_addr_t paddr;
326 qdf_nbuf_t rx_netbuf;
327 void *rxdma_ring_entry;
328 union dp_rx_desc_list_elem_t *next;
329 void *rxdma_srng;
330 uint8_t *status_buf;
331
332 rxdma_srng = dp_rxdma_srng->hal_srng;
333
334 qdf_assert(rxdma_srng);
335
336 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
337 "[%s][%d] requested %d buffers for replenish\n",
338 __func__, __LINE__, num_req_buffers);
339
340 /*
341 * if desc_list is NULL, allocate the descs from freelist
342 */
343 if (!(*desc_list)) {
344
345 num_alloc_desc = dp_rx_get_free_desc_list(dp_soc, mac_id,
346 rx_desc_pool,
347 num_req_buffers,
348 desc_list,
349 tail);
350
351 if (!num_alloc_desc) {
352 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
353 "[%s][%d] no free rx_descs in freelist\n",
354 __func__, __LINE__);
355 return QDF_STATUS_E_NOMEM;
356 }
357
358 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
359 "[%s][%d] %d rx desc allocated\n", __func__, __LINE__,
360 num_alloc_desc);
361 num_req_buffers = num_alloc_desc;
362 }
363
364 hal_srng_access_start(dp_soc->hal_soc, rxdma_srng);
365 num_entries_avail = hal_srng_src_num_avail(dp_soc->hal_soc,
366 rxdma_srng, sync_hw_ptr);
367
368 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
369 "[%s][%d] no of availble entries in rxdma ring: %d\n",
370 __func__, __LINE__, num_entries_avail);
371
372 if (num_entries_avail < num_req_buffers) {
373 num_desc_to_free = num_req_buffers - num_entries_avail;
374 num_req_buffers = num_entries_avail;
375 }
376
377 for (count = 0; count < num_req_buffers; count++) {
378 rxdma_ring_entry = hal_srng_src_get_next(dp_soc->hal_soc,
379 rxdma_srng);
380
381 rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
382 RX_BUFFER_SIZE,
383 RX_BUFFER_RESERVATION,
384 RX_BUFFER_ALIGNMENT,
385 FALSE);
386
387 status_buf = qdf_nbuf_data(rx_netbuf);
388 hal_clear_rx_status_done(status_buf);
389
390 memset(status_buf, 0, RX_BUFFER_SIZE);
391
392 qdf_nbuf_map_single(dp_soc->osdev, rx_netbuf,
393 QDF_DMA_BIDIRECTIONAL);
394
395 paddr = qdf_nbuf_get_frag_paddr(rx_netbuf, 0);
396
397 next = (*desc_list)->next;
398
399 (*desc_list)->rx_desc.nbuf = rx_netbuf;
400 hal_rxdma_buff_addr_info_set(rxdma_ring_entry, paddr,
401 (*desc_list)->rx_desc.cookie, owner);
402
Karunakar Dasineni40555682017-03-26 22:44:39 -0700403 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
Kai Chen6eca1a62017-01-12 10:17:53 -0800404 "[%s][%d] rx_desc=%p, cookie=%d, nbuf=%p, \
405 status_buf=%p paddr=%p\n",
406 __func__, __LINE__, &(*desc_list)->rx_desc,
407 (*desc_list)->rx_desc.cookie, rx_netbuf,
408 status_buf, (void *)paddr);
409
410 *desc_list = next;
411 }
412
413 hal_srng_access_end(dp_soc->hal_soc, rxdma_srng);
414
415 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
416 "successfully replenished %d buffers\n", num_req_buffers);
417
418 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
419 "%d rx desc added back to free list\n", num_desc_to_free);
420
421 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
422 "[%s][%d] desc_list=%p, tail=%p rx_desc=%p, cookie=%d\n",
423 __func__, __LINE__, desc_list, tail, &(*desc_list)->rx_desc,
424 (*desc_list)->rx_desc.cookie);
425
426 /*
427 * add any available free desc back to the free list
428 */
429 if (*desc_list) {
430 dp_rx_add_desc_list_to_free_list(dp_soc, desc_list, tail,
431 mac_id, rx_desc_pool);
432 }
433
434 return QDF_STATUS_SUCCESS;
435}
436/**
437 * dp_rx_pdev_mon_status_attach() - attach DP RX monitor status ring
438 * @pdev: core txrx pdev context
439 *
440 * This function will attach a DP RX monitor status ring into pDEV
441 * and replenish monitor status ring with buffer.
442 *
443 * Return: QDF_STATUS_SUCCESS: success
444 * QDF_STATUS_E_RESOURCES: Error return
445 */
446QDF_STATUS
447dp_rx_pdev_mon_status_attach(struct dp_pdev *pdev) {
448 uint8_t pdev_id = pdev->pdev_id;
449 struct dp_soc *soc = pdev->soc;
450 union dp_rx_desc_list_elem_t *desc_list = NULL;
451 union dp_rx_desc_list_elem_t *tail = NULL;
452 struct dp_srng *rxdma_srng;
453 uint32_t rxdma_entries;
454 struct rx_desc_pool *rx_desc_pool;
455
456 rxdma_srng = &pdev->rxdma_mon_status_ring;
457
458 rxdma_entries = rxdma_srng->alloc_size/hal_srng_get_entrysize(
459 soc->hal_soc, RXDMA_MONITOR_STATUS);
460
461 rx_desc_pool = &soc->rx_desc_status[pdev_id];
462
463 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
464 "%s: Mon RX Status Pool[%d] allocation size=%d\n",
465 __func__, pdev_id, rxdma_entries);
466
467 dp_rx_desc_pool_alloc(soc, pdev_id, rxdma_entries+1, rx_desc_pool);
468
469 QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
470 "%s: Mon RX Status Buffers Replenish pdev_id=%d\n",
471 __func__, pdev_id);
472
473 dp_rx_mon_status_buffers_replenish(soc, pdev_id, rxdma_srng,
474 rx_desc_pool, rxdma_entries, &desc_list, &tail,
475 HAL_RX_BUF_RBM_SW3_BM);
476
477 qdf_nbuf_queue_init(&pdev->rx_status_q);
478
479 pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
Karunakar Dasineni40555682017-03-26 22:44:39 -0700480 qdf_mem_zero(&(pdev->ppdu_info.rx_status),
481 sizeof(pdev->ppdu_info.rx_status));
Kai Chen6eca1a62017-01-12 10:17:53 -0800482
483 return QDF_STATUS_SUCCESS;
484}