xref: /wlan-dirver/qca-wifi-host-cmn/wlan_cfg/wlan_cfg.c (revision e7e6e37448d88eb5242e98fb18533d18451b67b8)
1 /*
2  * Copyright (c) 2016-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 
19 #if defined(CONFIG_HL_SUPPORT)
20 #include "wlan_tgt_def_config_hl.h"
21 #else
22 #include "wlan_tgt_def_config.h"
23 #endif
24 
25 #include "qdf_trace.h"
26 #include "qdf_mem.h"
27 #include "wlan_cfg.h"
28 
29 /*
30  * FIX THIS -
31  * For now, all these configuration parameters are hardcoded.
32  * Many of these should actually be coming from dts file/ini file
33  */
34 #define WLAN_CFG_INT_NUM_CONTEXTS 4
35 
36 #define RXDMA_BUF_RING_SIZE 2048
37 #define RXDMA_MONITOR_BUF_RING_SIZE 2048
38 #define RXDMA_MONITOR_DEST_RING_SIZE 2048
39 #define RXDMA_MONITOR_STATUS_RING_SIZE 2048
40 
41 #define WLAN_CFG_NUM_TX_DESC  1024
42 #define WLAN_CFG_NUM_TX_EXT_DESC 1024
43 
44 #ifdef TX_PER_PDEV_DESC_POOL
45 #define WLAN_CFG_NUM_TX_DESC_POOL 	MAX_PDEV_CNT
46 #define WLAN_CFG_NUM_TXEXT_DESC_POOL	MAX_PDEV_CNT
47 #else
48 #define WLAN_CFG_NUM_TX_DESC_POOL 3
49 #define WLAN_CFG_NUM_TXEXT_DESC_POOL 3
50 #endif /* TX_PER_PDEV_DESC_POOL */
51 
52 
53 #define WLAN_CFG_TX_RING_MASK_0 0x1
54 #define WLAN_CFG_TX_RING_MASK_1 0x2
55 #define WLAN_CFG_TX_RING_MASK_2 0x4
56 #define WLAN_CFG_TX_RING_MASK_3 0x0
57 
58 #define WLAN_CFG_RX_RING_MASK_0 0x1
59 #define WLAN_CFG_RX_RING_MASK_1 0x2
60 #define WLAN_CFG_RX_RING_MASK_2 0x4
61 #define WLAN_CFG_RX_RING_MASK_3 0x8
62 
63 #define WLAN_CFG_RX_MON_RING_MASK_0 0x1
64 #define WLAN_CFG_RX_MON_RING_MASK_1 0x2
65 #define WLAN_CFG_RX_MON_RING_MASK_2 0x4
66 #define WLAN_CFG_RX_MON_RING_MASK_3 0x0
67 
68 #define WLAN_CFG_DP_TX_NUM_POOLS 3
69 /* Change this to a lower value to enforce scattered idle list mode */
70 #define WLAN_CFG_MAX_ALLOC_SIZE (2 << 20)
71 
72 #define WLAN_CFG_MAX_CLIENTS 64
73 
74 #define WLAN_CFG_PER_PDEV_TX_RING 1
75 #define WLAN_CFG_NUM_TCL_DATA_RINGS 3
76 #define WLAN_CFG_NUM_REO_DEST_RING 4
77 
78 #define WLAN_CFG_HTT_PKT_TYPE 2
79 #define WLAN_CFG_MAX_PEER_ID 64
80 
81 #ifdef CONFIG_MCL
82 #define WLAN_CFG_PER_PDEV_RX_RING 0
83 #define NUM_RXDMA_RINGS_PER_PDEV 2
84 #else
85 #define WLAN_CFG_PER_PDEV_RX_RING 1
86 #define NUM_RXDMA_RINGS_PER_PDEV 1
87 #endif
88 
89 #ifdef WLAN_RX_HASH
90 #define WLAN_RX_HASH_ENABLE 1
91 #else
92 #define WLAN_RX_HASH_ENABLE 0
93 #endif
94 #define WLAN_LRO_ENABLE 0
95 
96 static const int tx_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS] = {
97 						WLAN_CFG_TX_RING_MASK_0,
98 						WLAN_CFG_TX_RING_MASK_1,
99 						WLAN_CFG_TX_RING_MASK_2,
100 						WLAN_CFG_TX_RING_MASK_3};
101 
102 static const int rx_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS] = {
103 					WLAN_CFG_RX_RING_MASK_0,
104 					WLAN_CFG_RX_RING_MASK_1,
105 					WLAN_CFG_RX_RING_MASK_2,
106 					WLAN_CFG_RX_RING_MASK_3};
107 
108 static const int rx_mon_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS] = {
109 					WLAN_CFG_RX_MON_RING_MASK_0,
110 					WLAN_CFG_RX_MON_RING_MASK_1,
111 					WLAN_CFG_RX_MON_RING_MASK_2,
112 					WLAN_CFG_RX_MON_RING_MASK_3};
113 
114 /**
115  * struct wlan_cfg_dp_soc_ctxt - Configuration parameters for SoC (core TxRx)
116  * @num_int_ctxts - Number of NAPI/Interrupt contexts to be registered for DP
117  * @max_clients - Maximum number of peers/stations supported by device
118  * @max_alloc_size - Maximum allocation size for any dynamic memory
119  *			allocation request for this device
120  * @per_pdev_tx_ring - 0 - TCL ring is not mapped per radio
121  *		       1 - Each TCL ring is mapped to one radio/pdev
122  * @num_tcl_data_rings - Number of TCL Data rings supported by device
123  * @per_pdev_rx_ring - 0 - REO ring is not mapped per radio
124  *		       1 - Each REO ring is mapped to one radio/pdev
125  * @num_tx_desc_pool - Number of Tx Descriptor pools
126  * @num_tx_ext_desc_pool - Number of Tx MSDU extension Descriptor pools
127  * @num_tx_desc - Number of Tx Descriptors per pool
128  * @num_tx_ext_desc - Number of Tx MSDU extension Descriptors per pool
129  * @max_peer_id - Maximum value of peer id that FW can assign for a client
130  * @htt_packet_type - Default 802.11 encapsulation type for any VAP created
131  * @int_tx_ring_mask - Bitmap of Tx interrupts mapped to each NAPI/Intr context
132  * @int_rx_ring_mask - Bitmap of Rx interrupts mapped to each NAPI/Intr context
133  * @int_rx_mon_ring_mask - Bitmap of Rx monitor ring interrupts mapped to each
134  *			  NAPI/Intr context
135  * @int_ce_ring_mask - Bitmap of CE interrupts mapped to each NAPI/Intr context
136  * @lro_enabled - is LRO enabled
137  * @rx_hash - Enable hash based steering of rx packets
138  *
139  */
140 struct wlan_cfg_dp_soc_ctxt {
141 	int num_int_ctxts;
142 	int max_clients;
143 	int max_alloc_size;
144 	int per_pdev_tx_ring;
145 	int num_tcl_data_rings;
146 	int per_pdev_rx_ring;
147 	int num_reo_dest_rings;
148 	int num_tx_desc_pool;
149 	int num_tx_ext_desc_pool;
150 	int num_tx_desc;
151 	int num_tx_ext_desc;
152 	int max_peer_id;
153 	int htt_packet_type;
154 	int int_tx_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS];
155 	int int_rx_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS];
156 	int int_rx_mon_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS];
157 	int int_ce_ring_mask[WLAN_CFG_INT_NUM_CONTEXTS];
158 	bool lro_enabled;
159 	bool rx_hash;
160 	int nss_cfg;
161 };
162 
163 /**
164  * struct wlan_cfg_dp_pdev_ctxt - Configuration parameters for pdev (radio)
165  * @rx_dma_buf_ring_size - Size of RxDMA buffer ring
166  * @dma_mon_buf_ring_size - Size of RxDMA Monitor buffer ring
167  * @dma_mon_dest_ring_size - Size of RxDMA Monitor Destination ring
168  * @dma_mon_status_ring_size - Size of RxDMA Monitor Status ring
169  */
170 struct wlan_cfg_dp_pdev_ctxt {
171 	int rx_dma_buf_ring_size;
172 	int dma_mon_buf_ring_size;
173 	int dma_mon_dest_ring_size;
174 	int dma_mon_status_ring_size;
175 	int num_mac_rings;
176 	int nss_enabled;
177 };
178 
179 /**
180  * wlan_cfg_soc_attach() - Allocate and prepare SoC configuration
181  *
182  * Return: wlan_cfg_ctx - Handle to Configuration context
183  */
184 struct wlan_cfg_dp_soc_ctxt *wlan_cfg_soc_attach(void)
185 {
186 	int i = 0;
187 	struct wlan_cfg_dp_soc_ctxt *wlan_cfg_ctx =
188 		qdf_mem_malloc(sizeof(struct wlan_cfg_dp_soc_ctxt));
189 
190 	if (wlan_cfg_ctx == NULL)
191 		return NULL;
192 
193 	wlan_cfg_ctx->num_int_ctxts = WLAN_CFG_INT_NUM_CONTEXTS;
194 	wlan_cfg_ctx->max_clients = WLAN_CFG_MAX_CLIENTS;
195 	wlan_cfg_ctx->max_alloc_size = WLAN_CFG_MAX_ALLOC_SIZE;
196 	wlan_cfg_ctx->per_pdev_tx_ring = WLAN_CFG_PER_PDEV_TX_RING;
197 	wlan_cfg_ctx->num_tcl_data_rings = WLAN_CFG_NUM_TCL_DATA_RINGS;
198 	wlan_cfg_ctx->per_pdev_rx_ring = WLAN_CFG_PER_PDEV_RX_RING;
199 	wlan_cfg_ctx->num_reo_dest_rings = WLAN_CFG_NUM_REO_DEST_RING;
200 	wlan_cfg_ctx->num_tx_desc_pool = WLAN_CFG_NUM_TX_DESC_POOL;
201 	wlan_cfg_ctx->num_tx_ext_desc_pool = WLAN_CFG_NUM_TXEXT_DESC_POOL;
202 	wlan_cfg_ctx->num_tx_desc = WLAN_CFG_NUM_TX_DESC;
203 	wlan_cfg_ctx->num_tx_ext_desc = WLAN_CFG_NUM_TX_EXT_DESC;
204 	wlan_cfg_ctx->max_peer_id = WLAN_CFG_MAX_PEER_ID;
205 	wlan_cfg_ctx->htt_packet_type = WLAN_CFG_HTT_PKT_TYPE;
206 
207 	for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
208 		wlan_cfg_ctx->int_tx_ring_mask[i] = tx_ring_mask[i];
209 		wlan_cfg_ctx->int_rx_ring_mask[i] = rx_ring_mask[i];
210 		wlan_cfg_ctx->int_rx_mon_ring_mask[i] = rx_mon_ring_mask[i];
211 	}
212 
213 	wlan_cfg_ctx->rx_hash = WLAN_RX_HASH_ENABLE;
214 	wlan_cfg_ctx->lro_enabled = WLAN_LRO_ENABLE;
215 
216 	return wlan_cfg_ctx;
217 }
218 
219 void wlan_cfg_soc_detach(struct wlan_cfg_dp_soc_ctxt *wlan_cfg_ctx)
220 {
221 	qdf_mem_free(wlan_cfg_ctx);
222 }
223 
224 struct wlan_cfg_dp_pdev_ctxt *wlan_cfg_pdev_attach(void)
225 {
226 	struct wlan_cfg_dp_pdev_ctxt *wlan_cfg_ctx =
227 		qdf_mem_malloc(sizeof(struct wlan_cfg_dp_pdev_ctxt));
228 
229 	if (wlan_cfg_ctx == NULL)
230 		return NULL;
231 
232 	wlan_cfg_ctx->rx_dma_buf_ring_size = RXDMA_BUF_RING_SIZE;
233 	wlan_cfg_ctx->dma_mon_buf_ring_size = RXDMA_MONITOR_BUF_RING_SIZE;
234 	wlan_cfg_ctx->dma_mon_dest_ring_size = RXDMA_MONITOR_DEST_RING_SIZE;
235 	wlan_cfg_ctx->dma_mon_status_ring_size = RXDMA_MONITOR_STATUS_RING_SIZE;
236 	wlan_cfg_ctx->num_mac_rings = NUM_RXDMA_RINGS_PER_PDEV;
237 
238 	return wlan_cfg_ctx;
239 }
240 
241 void wlan_cfg_pdev_detach(struct wlan_cfg_dp_pdev_ctxt *wlan_cfg_ctx)
242 {
243 	qdf_mem_free(wlan_cfg_ctx);
244 }
245 
246 void wlan_cfg_set_num_contexts(struct wlan_cfg_dp_soc_ctxt *cfg, int num)
247 {
248 	cfg->num_int_ctxts = num;
249 }
250 
251 void wlan_cfg_set_tx_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg,
252 		int context, int mask)
253 {
254 	cfg->int_tx_ring_mask[context] = mask;
255 }
256 
257 void wlan_cfg_set_rx_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg,
258 		int context, int mask)
259 {
260 	cfg->int_rx_ring_mask[context] = mask;
261 }
262 
263 void wlan_cfg_set_rx_mon_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg,
264 		int context, int mask)
265 {
266 	cfg->int_rx_mon_ring_mask[context] = mask;
267 }
268 
269 void wlan_cfg_set_ce_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg,
270 		int context, int mask)
271 {
272 	cfg->int_ce_ring_mask[context] = mask;
273 }
274 
275 void wlan_cfg_set_rxbuf_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg, int context,
276 		int mask)
277 {
278 	cfg->int_rx_ring_mask[context] = mask;
279 }
280 
281 int wlan_cfg_get_num_contexts(struct wlan_cfg_dp_soc_ctxt *cfg)
282 {
283 	return cfg->num_int_ctxts;
284 }
285 
286 int wlan_cfg_get_tx_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg, int context)
287 {
288 	return cfg->int_tx_ring_mask[context];
289 }
290 
291 int wlan_cfg_get_rx_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg, int context)
292 {
293 	return cfg->int_rx_ring_mask[context];
294 }
295 
296 int wlan_cfg_get_rx_mon_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg, int context)
297 {
298 	return cfg->int_rx_mon_ring_mask[context];
299 }
300 
301 int wlan_cfg_get_ce_ring_mask(struct wlan_cfg_dp_soc_ctxt *cfg, int context)
302 {
303 	return cfg->int_ce_ring_mask[context];
304 }
305 
306 uint32_t wlan_cfg_get_max_clients(struct wlan_cfg_dp_soc_ctxt *cfg)
307 {
308 	return cfg->max_clients;
309 }
310 
311 uint32_t wlan_cfg_max_alloc_size(struct wlan_cfg_dp_soc_ctxt *cfg)
312 {
313 	return cfg->max_alloc_size;
314 }
315 
316 int wlan_cfg_per_pdev_tx_ring(struct wlan_cfg_dp_soc_ctxt *cfg)
317 {
318 	return cfg->per_pdev_tx_ring;
319 }
320 
321 int wlan_cfg_num_tcl_data_rings(struct wlan_cfg_dp_soc_ctxt *cfg)
322 {
323 	return cfg->num_tcl_data_rings;
324 }
325 
326 int wlan_cfg_per_pdev_rx_ring(struct wlan_cfg_dp_soc_ctxt *cfg)
327 {
328 	return cfg->per_pdev_rx_ring;
329 }
330 
331 int wlan_cfg_num_reo_dest_rings(struct wlan_cfg_dp_soc_ctxt *cfg)
332 {
333 	return cfg->num_reo_dest_rings;
334 }
335 
336 int wlan_cfg_pkt_type(struct wlan_cfg_dp_soc_ctxt *cfg)
337 {
338 	return cfg->htt_packet_type;            /*htt_pkt_type_ethernet*/
339 }
340 
341 int wlan_cfg_get_num_tx_desc_pool(struct wlan_cfg_dp_soc_ctxt *cfg)
342 {
343 	return cfg->num_tx_desc_pool;
344 }
345 
346 int wlan_cfg_get_num_tx_ext_desc_pool(struct wlan_cfg_dp_soc_ctxt *cfg)
347 {
348 	return cfg->num_tx_ext_desc_pool;
349 }
350 
351 int wlan_cfg_get_num_tx_desc(struct wlan_cfg_dp_soc_ctxt *cfg)
352 {
353 	return cfg->num_tx_desc;
354 }
355 
356 int wlan_cfg_get_num_tx_ext_desc(struct wlan_cfg_dp_soc_ctxt *cfg)
357 {
358 	return cfg->num_tx_ext_desc;
359 }
360 
361 uint32_t wlan_cfg_max_peer_id(struct wlan_cfg_dp_soc_ctxt *cfg)
362 {
363 	/* TODO: This should be calculated based on target capabilities */
364 	return cfg->max_peer_id;
365 }
366 
367 int wlan_cfg_get_dma_mon_buf_ring_size(struct wlan_cfg_dp_pdev_ctxt *cfg)
368 {
369 	return  cfg->dma_mon_buf_ring_size;
370 }
371 
372 int wlan_cfg_get_dma_mon_dest_ring_size(struct wlan_cfg_dp_pdev_ctxt *cfg)
373 {
374 	return  cfg->dma_mon_dest_ring_size;
375 }
376 
377 int wlan_cfg_get_dma_mon_stat_ring_size(struct wlan_cfg_dp_pdev_ctxt *cfg)
378 {
379 	return  cfg->dma_mon_status_ring_size;
380 }
381 
382 int wlan_cfg_get_rx_dma_buf_ring_size(struct wlan_cfg_dp_pdev_ctxt *cfg)
383 {
384 	return  cfg->rx_dma_buf_ring_size;
385 }
386 
387 int wlan_cfg_get_num_mac_rings(struct wlan_cfg_dp_pdev_ctxt *cfg)
388 {
389 	return  cfg->num_mac_rings;
390 }
391 
392 bool wlan_cfg_is_lro_enabled(struct wlan_cfg_dp_soc_ctxt *cfg)
393 {
394 	return  cfg->lro_enabled;
395 }
396 
397 bool wlan_cfg_is_rx_hash_enabled(struct wlan_cfg_dp_soc_ctxt *cfg)
398 {
399 	return  cfg->rx_hash;
400 }
401 
402 int wlan_cfg_get_dp_pdev_nss_enabled(struct wlan_cfg_dp_pdev_ctxt *cfg)
403 {
404 	return  cfg->nss_enabled;
405 }
406 
407 void wlan_cfg_set_dp_pdev_nss_enabled(struct wlan_cfg_dp_pdev_ctxt *cfg, int nss_enabled)
408 {
409 	cfg->nss_enabled = nss_enabled;
410 }
411 
412 int wlan_cfg_get_dp_soc_nss_cfg(struct wlan_cfg_dp_soc_ctxt *cfg)
413 {
414 	return  cfg->nss_cfg;
415 }
416 
417 void wlan_cfg_set_dp_soc_nss_cfg(struct wlan_cfg_dp_soc_ctxt *cfg, int nss_cfg)
418 {
419 	cfg->nss_cfg = nss_cfg;
420 }
421