xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_rx_buffer_pool.h (revision a64d8a0dbea74a9757ced8bd24c04bf658d196c7)
1 /*
2  * Copyright (c) 2020-2021 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 
19 #ifndef _DP_RX_BUFFER_POOL_H_
20 #define _DP_RX_BUFFER_POOL_H_
21 
22 #include "dp_types.h"
23 #include "qdf_nbuf.h"
24 #include "qdf_module.h"
25 #include "athdefs.h"
26 #include "wlan_cfg.h"
27 #include "dp_internal.h"
28 #include "dp_rx.h"
29 #include "dp_rx_mon.h"
30 
31 #ifdef WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL
32 /**
33  * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
34  * @soc: SoC handle
35  * @mac_id: MAC ID
36  *
37  * Return: None
38  */
39 void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id);
40 
41 /**
42  * dp_rx_buffer_pool_deinit() - De-Initialize emergency buffer pool
43  * @soc: SoC handle
44  * @mac_id: MAC ID
45  *
46  * Return: None
47  */
48 void dp_rx_buffer_pool_deinit(struct dp_soc *soc, u8 mac_id);
49 
50 /**
51  * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
52  * refill the emergency buffer pool
53  * @soc: SoC handle
54  * @nbuf: RX buffer
55  * @mac_id: MAC ID
56  *
57  * Return: Whether the rx nbuf is consumed into the pool or not.
58  */
59 bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id);
60 
61 /**
62  * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
63  * back into the pool
64  * @soc: SoC handle
65  * @nbuf: RX buffer
66  * @mac_id: MAC ID
67  *
68  * Return: None
69  */
70 void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
71 				 u8 mac_id);
72 
73 /**
74  * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
75  * give nbuf from the pool if allocation fails
76  * @soc: SoC handle
77  * @mac_id: MAC ID
78  * @rx_desc_pool: RX descriptor pool
79  * @num_available_buffers: number of available buffers in the ring.
80  *
81  * Return: nbuf
82  */
83 qdf_nbuf_t dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
84 					struct rx_desc_pool *rx_desc_pool,
85 					uint32_t num_available_buffers);
86 
87 /**
88  * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
89  * @soc: SoC handle
90  * @rx_desc_pool: RX descriptor pool
91  * @nbuf_frag_info_t: nbuf frag info
92  *
93  * Return: nbuf
94  */
95 QDF_STATUS
96 dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
97 			   struct rx_desc_pool *rx_desc_pool,
98 			   struct dp_rx_nbuf_frag_info *nbuf_frag_info_t);
99 
100 /**
101  * dp_rx_schedule_refill_thread() - Schedule RX refill thread to enqueue
102  * buffers in refill pool
103  * @soc: SoC handle
104  *
105  */
106 static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc)
107 {
108 	struct rx_refill_buff_pool *buff_pool = &soc->rx_refill_buff_pool;
109 	uint16_t head = buff_pool->head;
110 	uint16_t tail = buff_pool->tail;
111 	uint16_t num_refill;
112 
113 	if (!buff_pool->is_initialized)
114 		return;
115 
116 	if (tail > head)
117 		num_refill = (tail - head - 1);
118 	else
119 		num_refill = (DP_RX_REFILL_BUFF_POOL_SIZE - head + tail - 1);
120 
121 	if (soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread &&
122 	    num_refill >= DP_RX_REFILL_THRD_THRESHOLD)
123 		soc->cdp_soc.ol_ops->dp_rx_sched_refill_thread(
124 						dp_soc_to_cdp_soc_t(soc));
125 }
126 #else
127 /**
128  * dp_rx_buffer_pool_init() - Initialize emergency buffer pool
129  * @soc: SoC handle
130  * @mac_id: MAC ID
131  *
132  * Return: None
133  */
134 static inline
135 void dp_rx_buffer_pool_init(struct dp_soc *soc, u8 mac_id)
136 {
137 	soc->rx_buff_pool[mac_id].is_initialized = false;
138 }
139 
140 /**
141  * dp_rx_buffer_pool_deinit() - De-Initialize emergency buffer pool
142  * @soc: SoC handle
143  * @mac_id: MAC ID
144  *
145  * Return: None
146  */
147 static inline
148 void dp_rx_buffer_pool_deinit(struct dp_soc *soc, u8 mac_id)
149 {
150 }
151 
152 /**
153  * dp_rx_buffer_pool_refill() - Process the rx nbuf list and
154  * refill the emergency buffer pool
155  * @soc: SoC handle
156  * @nbuf: RX buffer
157  * @mac_id: MAC ID
158  *
159  * Return: Whether the rx nbuf is consumed into the pool or not.
160  */
161 static inline
162 bool dp_rx_buffer_pool_refill(struct dp_soc *soc, qdf_nbuf_t nbuf, u8 mac_id)
163 {
164 	return false;
165 }
166 
167 /**
168  * dp_rx_buffer_pool_nbuf_free() - Free the nbuf or queue it
169  * back into the pool
170  * @soc: SoC handle
171  * @nbuf: RX buffer
172  * @mac_id: MAC ID
173  *
174  * Return: None
175  */
176 static inline
177 void dp_rx_buffer_pool_nbuf_free(struct dp_soc *soc, qdf_nbuf_t nbuf,
178 				 u8 mac_id)
179 {
180 	qdf_nbuf_free(nbuf);
181 }
182 
183 /**
184  * dp_rx_buffer_pool_nbuf_alloc() - Allocate nbuf for buffer replenish,
185  * give nbuf from the pool if allocation fails
186  * @soc: SoC handle
187  * @mac_id: MAC ID
188  * @rx_desc_pool: RX descriptor pool
189  * @num_available_buffers: number of available buffers in the ring.
190  *
191  * Return: nbuf
192  */
193 static inline qdf_nbuf_t
194 dp_rx_buffer_pool_nbuf_alloc(struct dp_soc *soc, uint32_t mac_id,
195 			     struct rx_desc_pool *rx_desc_pool,
196 			     uint32_t num_available_buffers)
197 {
198 	return qdf_nbuf_alloc(soc->osdev, rx_desc_pool->buf_size,
199 			      RX_BUFFER_RESERVATION,
200 			      rx_desc_pool->buf_alignment, FALSE);
201 }
202 
203 /**
204  * dp_rx_buffer_pool_nbuf_map() - Map nbuff for buffer replenish
205  * @soc: SoC handle
206  * @rx_desc_pool: RX descriptor pool
207  * @nbuf_frag_info_t: nbuf frag info
208  *
209  * Return: nbuf
210  */
211 static inline QDF_STATUS
212 dp_rx_buffer_pool_nbuf_map(struct dp_soc *soc,
213 			   struct rx_desc_pool *rx_desc_pool,
214 			   struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
215 {
216 	return qdf_nbuf_map_nbytes_single(soc->osdev,
217 					 (nbuf_frag_info_t->virt_addr).nbuf,
218 					 QDF_DMA_FROM_DEVICE,
219 					 rx_desc_pool->buf_size);
220 }
221 
222 static inline void dp_rx_schedule_refill_thread(struct dp_soc *soc) { }
223 
224 #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
225 #endif /* _DP_RX_BUFFER_POOL_H_ */
226