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