1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief File containing FMAC interface specific definitions for the
9  * Zephyr OS layer of the Wi-Fi driver.
10  */
11 
12 #include <stdlib.h>
13 
14 #include <zephyr/kernel.h>
15 #ifdef CONFIG_NET_L2_ETHERNET
16 #include <zephyr/net/ethernet.h>
17 #endif
18 #include <zephyr/logging/log.h>
19 #include <zephyr/net/wifi_mgmt.h>
20 #include <zephyr/net/conn_mgr_connectivity.h>
21 #include <zephyr/net/conn_mgr_connectivity_impl.h>
22 #include <zephyr/net/conn_mgr/connectivity_wifi_mgmt.h>
23 
24 
25 #include <util.h>
26 #include "common/fmac_util.h"
27 #include <fmac_main.h>
28 
29 #ifndef CONFIG_NRF70_RADIO_TEST
30 #ifdef CONFIG_NRF70_STA_MODE
31 #include <zephyr/net/wifi_nm.h>
32 #include <wifi_mgmt_scan.h>
33 #include <wifi_mgmt.h>
34 #include <wpa_supp_if.h>
35 #else
36 #include <wifi_mgmt.h>
37 #include <wifi_mgmt_scan.h>
38 #endif /* CONFIG_NRF70_STA_MODE */
39 
40 #include <system/fmac_api.h>
41 #include <zephyr/net/conn_mgr_connectivity.h>
42 #else
43 #include <radio_test/fmac_api.h>
44 #endif /* !CONFIG_NRF70_RADIO_TEST */
45 
46 #define DT_DRV_COMPAT nordic_wlan
47 LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
48 
49 struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep;
50 extern const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops;
51 
52 /* 3 bytes for addreess, 3 bytes for length */
53 #define MAX_PKT_RAM_TX_ALIGN_OVERHEAD 6
54 #ifndef CONFIG_NRF70_RADIO_TEST
55 #ifdef CONFIG_NRF70_DATA_TX
56 
57 #define MAX_RX_QUEUES 3
58 
59 #define MAX_TX_FRAME_SIZE \
60 	(CONFIG_NRF_WIFI_IFACE_MTU + NRF_WIFI_FMAC_ETH_HDR_LEN + TX_BUF_HEADROOM)
61 #define TOTAL_TX_SIZE \
62 	(CONFIG_NRF70_MAX_TX_TOKENS * CONFIG_NRF70_TX_MAX_DATA_SIZE)
63 #define TOTAL_RX_SIZE \
64 	(CONFIG_NRF70_RX_NUM_BUFS * CONFIG_NRF70_RX_MAX_DATA_SIZE)
65 
66 BUILD_ASSERT(CONFIG_NRF70_MAX_TX_TOKENS >= 1,
67 	"At least one TX token is required");
68 BUILD_ASSERT(CONFIG_NRF70_MAX_TX_AGGREGATION <= 15,
69 	"Max TX aggregation is 15");
70 BUILD_ASSERT(CONFIG_NRF70_RX_NUM_BUFS >= 1,
71 	"At least one RX buffer is required");
72 BUILD_ASSERT(RPU_PKTRAM_SIZE - TOTAL_RX_SIZE >= TOTAL_TX_SIZE,
73 	"Packet RAM overflow: not enough memory for TX");
74 
75 BUILD_ASSERT(CONFIG_NRF70_TX_MAX_DATA_SIZE >= MAX_TX_FRAME_SIZE,
76 	"TX buffer size must be at least as big as the MTU and headroom");
77 
78 static const unsigned char aggregation = 1;
79 static const unsigned char max_num_tx_agg_sessions = 4;
80 static const unsigned char max_num_rx_agg_sessions = 8;
81 static const unsigned char reorder_buf_size = 16;
82 static const unsigned char max_rxampdu_size = MAX_RX_AMPDU_SIZE_64KB;
83 
84 static const unsigned char max_tx_aggregation = CONFIG_NRF70_MAX_TX_AGGREGATION;
85 
86 static const unsigned int rx1_num_bufs = CONFIG_NRF70_RX_NUM_BUFS / MAX_RX_QUEUES;
87 static const unsigned int rx2_num_bufs = CONFIG_NRF70_RX_NUM_BUFS / MAX_RX_QUEUES;
88 static const unsigned int rx3_num_bufs = CONFIG_NRF70_RX_NUM_BUFS / MAX_RX_QUEUES;
89 
90 static const unsigned int rx1_buf_sz = CONFIG_NRF70_RX_MAX_DATA_SIZE;
91 static const unsigned int rx2_buf_sz = CONFIG_NRF70_RX_MAX_DATA_SIZE;
92 static const unsigned int rx3_buf_sz = CONFIG_NRF70_RX_MAX_DATA_SIZE;
93 
94 static const unsigned char rate_protection_type;
95 #else
96 /* Reduce buffers to Scan only operation */
97 static const unsigned int rx1_num_bufs = 2;
98 static const unsigned int rx2_num_bufs = 2;
99 static const unsigned int rx3_num_bufs = 2;
100 
101 static const unsigned int rx1_buf_sz = 1000;
102 static const unsigned int rx2_buf_sz = 1000;
103 static const unsigned int rx3_buf_sz = 1000;
104 #endif
105 
106 struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep;
107 static K_MUTEX_DEFINE(reg_lock);
108 
nrf_wifi_get_drv_version(void)109 const char *nrf_wifi_get_drv_version(void)
110 {
111 	return NRF70_DRIVER_VERSION;
112 }
113 
114 /* If the interface is not Wi-Fi then errors are expected, so, fail silently */
nrf_wifi_get_vif_ctx(struct net_if * iface)115 struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface)
116 {
117 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
118 	struct nrf_wifi_ctx_zep *rpu_ctx = &rpu_drv_priv_zep.rpu_ctx_zep;
119 
120 	if (!iface || !rpu_ctx || !rpu_ctx->rpu_ctx) {
121 		return NULL;
122 	}
123 
124 	for (int i = 0; i < ARRAY_SIZE(rpu_ctx->vif_ctx_zep); i++) {
125 		if (rpu_ctx->vif_ctx_zep[i].zep_net_if_ctx == iface) {
126 			vif_ctx_zep = &rpu_ctx->vif_ctx_zep[i];
127 			break;
128 		}
129 	}
130 
131 	return vif_ctx_zep;
132 }
133 
nrf_wifi_event_proc_scan_start_zep(void * if_priv,struct nrf_wifi_umac_event_trigger_scan * scan_start_event,unsigned int event_len)134 void nrf_wifi_event_proc_scan_start_zep(void *if_priv,
135 					struct nrf_wifi_umac_event_trigger_scan *scan_start_event,
136 					unsigned int event_len)
137 {
138 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
139 
140 	vif_ctx_zep = if_priv;
141 
142 	if (vif_ctx_zep->scan_type == SCAN_DISPLAY) {
143 		return;
144 	}
145 
146 #ifdef CONFIG_NRF70_STA_MODE
147 	nrf_wifi_wpa_supp_event_proc_scan_start(if_priv);
148 #endif /* CONFIG_NRF70_STA_MODE */
149 }
150 
151 
nrf_wifi_event_proc_scan_done_zep(void * vif_ctx,struct nrf_wifi_umac_event_trigger_scan * scan_done_event,unsigned int event_len)152 void nrf_wifi_event_proc_scan_done_zep(void *vif_ctx,
153 				       struct nrf_wifi_umac_event_trigger_scan *scan_done_event,
154 				       unsigned int event_len)
155 {
156 	enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
157 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
158 
159 	vif_ctx_zep = vif_ctx;
160 
161 	if (!vif_ctx_zep) {
162 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
163 		return;
164 	}
165 
166 	switch (vif_ctx_zep->scan_type) {
167 #ifdef CONFIG_NET_L2_WIFI_MGMT
168 	case SCAN_DISPLAY:
169 		status = nrf_wifi_disp_scan_res_get_zep(vif_ctx_zep);
170 		if (status != NRF_WIFI_STATUS_SUCCESS) {
171 			LOG_ERR("%s: nrf_wifi_disp_scan_res_get_zep failed", __func__);
172 			return;
173 		}
174 		vif_ctx_zep->scan_in_progress = false;
175 		break;
176 #endif /* CONFIG_NET_L2_WIFI_MGMT */
177 #ifdef CONFIG_NRF70_STA_MODE
178 	case SCAN_CONNECT:
179 		nrf_wifi_wpa_supp_event_proc_scan_done(vif_ctx_zep,
180 						       scan_done_event,
181 						       event_len,
182 						       0);
183 		break;
184 #endif /* CONFIG_NRF70_STA_MODE */
185 	default:
186 		LOG_ERR("%s: Scan type = %d not supported yet", __func__, vif_ctx_zep->scan_type);
187 		return;
188 	}
189 
190 	status = NRF_WIFI_STATUS_SUCCESS;
191 }
192 
nrf_wifi_scan_timeout_work(struct k_work * work)193 void nrf_wifi_scan_timeout_work(struct k_work *work)
194 {
195 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
196 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
197 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
198 
199 	vif_ctx_zep = CONTAINER_OF(work, struct nrf_wifi_vif_ctx_zep, scan_timeout_work.work);
200 
201 	if (!vif_ctx_zep->scan_in_progress) {
202 		LOG_INF("%s: Scan not in progress", __func__);
203 		return;
204 	}
205 
206 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
207 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
208 
209 #ifdef CONFIG_NET_L2_WIFI_MGMT
210 	if (vif_ctx_zep->disp_scan_cb) {
211 		vif_ctx_zep->disp_scan_cb(vif_ctx_zep->zep_net_if_ctx, -ETIMEDOUT, NULL);
212 		vif_ctx_zep->disp_scan_cb = NULL;
213 	} else
214 #endif /* CONFIG_NET_L2_WIFI_MGMT */
215 	{
216 #ifdef CONFIG_NRF70_STA_MODE
217 		/* WPA supplicant scan */
218 		union wpa_event_data event;
219 		struct scan_info *info = NULL;
220 
221 		memset(&event, 0, sizeof(event));
222 
223 		info = &event.scan_info;
224 
225 		info->aborted = 0;
226 		info->external_scan = 0;
227 		info->nl_scan_event = 1;
228 
229 		if (vif_ctx_zep->supp_drv_if_ctx &&
230 			vif_ctx_zep->supp_callbk_fns.scan_done) {
231 			vif_ctx_zep->supp_callbk_fns.scan_done(vif_ctx_zep->supp_drv_if_ctx,
232 				&event);
233 		}
234 #endif /* CONFIG_NRF70_STA_MODE */
235 	}
236 
237 	vif_ctx_zep->scan_in_progress = false;
238 }
239 
240 #ifdef CONFIG_NRF70_STA_MODE
nrf_wifi_process_rssi_from_rx(void * vif_ctx,signed short signal)241 static void nrf_wifi_process_rssi_from_rx(void *vif_ctx,
242 				   signed short signal)
243 {
244 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = vif_ctx;
245 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
246 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
247 
248 	vif_ctx_zep = vif_ctx;
249 
250 	if (!vif_ctx_zep) {
251 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
252 		return;
253 	}
254 
255 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
256 
257 	if (!(rpu_ctx_zep && rpu_ctx_zep->rpu_ctx)) {
258 		LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
259 		return;
260 	}
261 
262 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
263 
264 	vif_ctx_zep->rssi = MBM_TO_DBM(signal);
265 	vif_ctx_zep->rssi_record_timestamp_us =
266 		nrf_wifi_osal_time_get_curr_us();
267 }
268 #endif /* CONFIG_NRF70_STA_MODE */
269 
270 
nrf_wifi_event_get_reg_zep(void * vif_ctx,struct nrf_wifi_reg * get_reg_event,unsigned int event_len)271 void nrf_wifi_event_get_reg_zep(void *vif_ctx,
272 				struct nrf_wifi_reg *get_reg_event,
273 				unsigned int event_len)
274 {
275 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
276 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
277 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
278 
279 	LOG_DBG("%s: alpha2 = %c%c", __func__,
280 		   get_reg_event->nrf_wifi_alpha2[0],
281 		   get_reg_event->nrf_wifi_alpha2[1]);
282 	vif_ctx_zep = vif_ctx;
283 
284 	if (!vif_ctx_zep) {
285 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
286 		return;
287 	}
288 
289 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
290 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
291 
292 	if (fmac_dev_ctx->alpha2_valid) {
293 		LOG_ERR("%s: Unsolicited regulatory get!", __func__);
294 		return;
295 	}
296 
297 	memcpy(&fmac_dev_ctx->alpha2,
298 		   &get_reg_event->nrf_wifi_alpha2,
299 		   sizeof(get_reg_event->nrf_wifi_alpha2));
300 
301 	fmac_dev_ctx->reg_chan_count = get_reg_event->num_channels;
302 	memcpy(fmac_dev_ctx->reg_chan_info,
303 	       &get_reg_event->chn_info,
304 	       fmac_dev_ctx->reg_chan_count *
305 		   sizeof(struct nrf_wifi_get_reg_chn_info));
306 
307 	fmac_dev_ctx->alpha2_valid = true;
308 }
309 
nrf_wifi_reg_domain(const struct device * dev,struct wifi_reg_domain * reg_domain)310 int nrf_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain)
311 {
312 	enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
313 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
314 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
315 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
316 	struct nrf_wifi_fmac_reg_info reg_domain_info = {0};
317 	struct wifi_reg_chan_info *chan_info = NULL;
318 	struct nrf_wifi_get_reg_chn_info *reg_domain_chan_info = NULL;
319 	int ret = -1;
320 	int chan_idx = 0;
321 
322 	k_mutex_lock(&reg_lock, K_FOREVER);
323 
324 	if (!dev || !reg_domain) {
325 		goto out;
326 	}
327 
328 	vif_ctx_zep = dev->data;
329 
330 	if (!vif_ctx_zep) {
331 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
332 		goto out;
333 	}
334 
335 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
336 
337 	if (!rpu_ctx_zep) {
338 		LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
339 		goto out;
340 	}
341 
342 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
343 	if (!fmac_dev_ctx) {
344 		LOG_ERR("%s: fmac_dev_ctx is NULL", __func__);
345 		goto out;
346 	}
347 
348 #ifdef CONFIG_NRF70_SCAN_ONLY
349 	if (reg_domain->oper == WIFI_MGMT_SET) {
350 		memcpy(reg_domain_info.alpha2, reg_domain->country_code, WIFI_COUNTRY_CODE_LEN);
351 
352 		reg_domain_info.force = reg_domain->force;
353 
354 		status = nrf_wifi_fmac_set_reg(fmac_dev_ctx, &reg_domain_info);
355 		if (status != NRF_WIFI_STATUS_SUCCESS) {
356 			LOG_ERR("%s: Failed to set regulatory domain", __func__);
357 			goto out;
358 		}
359 
360 		ret = 0;
361 		goto out;
362 	}
363 #endif
364 	if (reg_domain->oper != WIFI_MGMT_GET) {
365 		LOG_ERR("%s: Invalid operation: %d", __func__, reg_domain->oper);
366 		goto out;
367 	}
368 
369 	if (!reg_domain->chan_info)	{
370 		LOG_ERR("%s: Invalid regulatory info (NULL)\n", __func__);
371 		goto out;
372 	}
373 
374 	status = nrf_wifi_fmac_get_reg(fmac_dev_ctx, &reg_domain_info);
375 	if (status != NRF_WIFI_STATUS_SUCCESS) {
376 		LOG_ERR("%s: Failed to get regulatory domain", __func__);
377 		goto out;
378 	}
379 
380 	memcpy(reg_domain->country_code, reg_domain_info.alpha2, WIFI_COUNTRY_CODE_LEN);
381 	reg_domain->num_channels = reg_domain_info.reg_chan_count;
382 
383 	for (chan_idx = 0; chan_idx < reg_domain_info.reg_chan_count; chan_idx++) {
384 		chan_info = &(reg_domain->chan_info[chan_idx]);
385 		reg_domain_chan_info = &(reg_domain_info.reg_chan_info[chan_idx]);
386 		chan_info->center_frequency = reg_domain_chan_info->center_frequency;
387 		chan_info->dfs = !!reg_domain_chan_info->dfs;
388 		chan_info->max_power = reg_domain_chan_info->max_power;
389 		chan_info->passive_only = !!reg_domain_chan_info->passive_channel;
390 		chan_info->supported = !!reg_domain_chan_info->supported;
391 	}
392 
393 	ret = 0;
394 out:
395 	k_mutex_unlock(&reg_lock);
396 	return ret;
397 }
398 #ifdef CONFIG_NRF70_STA_MODE
nrf_wifi_event_proc_cookie_rsp(void * vif_ctx,struct nrf_wifi_umac_event_cookie_rsp * cookie_rsp_event,unsigned int event_len)399 void nrf_wifi_event_proc_cookie_rsp(void *vif_ctx,
400 				    struct nrf_wifi_umac_event_cookie_rsp *cookie_rsp_event,
401 				    unsigned int event_len)
402 {
403 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
404 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
405 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
406 
407 	vif_ctx_zep = vif_ctx;
408 
409 	if (!vif_ctx_zep) {
410 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
411 		return;
412 	}
413 
414 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
415 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
416 
417 	LOG_DBG("%s: cookie_rsp_event->cookie = %llx", __func__, cookie_rsp_event->cookie);
418 	LOG_DBG("%s: host_cookie = %llx", __func__, cookie_rsp_event->host_cookie);
419 	LOG_DBG("%s: mac_addr = %x:%x:%x:%x:%x:%x", __func__,
420 		cookie_rsp_event->mac_addr[0],
421 		cookie_rsp_event->mac_addr[1],
422 		cookie_rsp_event->mac_addr[2],
423 		cookie_rsp_event->mac_addr[3],
424 		cookie_rsp_event->mac_addr[4],
425 		cookie_rsp_event->mac_addr[5]);
426 
427 	vif_ctx_zep->cookie_resp_received = true;
428 	/* TODO: When supp_callbk_fns.mgmt_tx_status is implemented, add logic
429 	 * here to use the cookie and host_cookie to map requests to responses.
430 	 */
431 }
432 #endif /* CONFIG_NRF70_STA_MODE */
433 
reg_change_callbk_fn(void * vif_ctx,struct nrf_wifi_event_regulatory_change * reg_change_event,unsigned int event_len)434 void reg_change_callbk_fn(void *vif_ctx,
435 			  struct nrf_wifi_event_regulatory_change *reg_change_event,
436 			  unsigned int event_len)
437 {
438 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
439 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
440 	struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
441 
442 	LOG_DBG("%s: Regulatory change event received", __func__);
443 
444 	vif_ctx_zep = vif_ctx;
445 
446 	if (!vif_ctx_zep) {
447 		LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
448 		return;
449 	}
450 
451 	rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
452 	if (!rpu_ctx_zep) {
453 		LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
454 		return;
455 	}
456 
457 	fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
458 	if (!fmac_dev_ctx) {
459 		LOG_ERR("%s: fmac_dev_ctx is NULL", __func__);
460 		return;
461 	}
462 
463 	if (!fmac_dev_ctx->waiting_for_reg_event) {
464 		LOG_DBG("%s: Unsolicited regulatory change event", __func__);
465 		/* TODO: Handle unsolicited regulatory change event */
466 		return;
467 	}
468 
469 	fmac_dev_ctx->reg_change = nrf_wifi_osal_mem_alloc(sizeof(struct
470 							   nrf_wifi_event_regulatory_change));
471 	if (!fmac_dev_ctx->reg_change) {
472 		LOG_ERR("%s: Failed to allocate memory for reg_change", __func__);
473 		return;
474 	}
475 
476 	memcpy(fmac_dev_ctx->reg_change,
477 		   reg_change_event,
478 		   sizeof(struct nrf_wifi_event_regulatory_change));
479 	fmac_dev_ctx->reg_set_status = true;
480 }
481 #endif /* !CONFIG_NRF70_RADIO_TEST */
482 
483 /* DTS uses 1dBm as the unit for TX power, while the RPU uses 0.25dBm */
484 #define MAX_TX_PWR(label) DT_PROP(DT_NODELABEL(nrf70), label) * 4
485 
configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params * tx_pwr_ctrl_params,struct nrf_wifi_tx_pwr_ceil_params * tx_pwr_ceil_params)486 void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_params,
487 				struct nrf_wifi_tx_pwr_ceil_params *tx_pwr_ceil_params)
488 {
489 	tx_pwr_ctrl_params->ant_gain_2g = CONFIG_NRF70_ANT_GAIN_2G;
490 	tx_pwr_ctrl_params->ant_gain_5g_band1 = CONFIG_NRF70_ANT_GAIN_5G_BAND1;
491 	tx_pwr_ctrl_params->ant_gain_5g_band2 = CONFIG_NRF70_ANT_GAIN_5G_BAND2;
492 	tx_pwr_ctrl_params->ant_gain_5g_band3 = CONFIG_NRF70_ANT_GAIN_5G_BAND3;
493 	tx_pwr_ctrl_params->band_edge_2g_lo_dss = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS;
494 	tx_pwr_ctrl_params->band_edge_2g_lo_ht = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT;
495 	tx_pwr_ctrl_params->band_edge_2g_lo_he = CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE;
496 	tx_pwr_ctrl_params->band_edge_2g_hi_dsss = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS;
497 	tx_pwr_ctrl_params->band_edge_2g_hi_ht = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT;
498 	tx_pwr_ctrl_params->band_edge_2g_hi_he = CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE;
499 	tx_pwr_ctrl_params->band_edge_5g_unii_1_lo_ht =
500 		CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT;
501 	tx_pwr_ctrl_params->band_edge_5g_unii_1_lo_he =
502 		CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE;
503 	tx_pwr_ctrl_params->band_edge_5g_unii_1_hi_ht =
504 		CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT;
505 	tx_pwr_ctrl_params->band_edge_5g_unii_1_hi_he =
506 		CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE;
507 	tx_pwr_ctrl_params->band_edge_5g_unii_2a_lo_ht =
508 		CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT;
509 	tx_pwr_ctrl_params->band_edge_5g_unii_2a_lo_he =
510 		CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE;
511 	tx_pwr_ctrl_params->band_edge_5g_unii_2a_hi_ht =
512 		CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT;
513 	tx_pwr_ctrl_params->band_edge_5g_unii_2a_hi_he =
514 		CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE;
515 	tx_pwr_ctrl_params->band_edge_5g_unii_2c_lo_ht =
516 		CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT;
517 	tx_pwr_ctrl_params->band_edge_5g_unii_2c_lo_he =
518 		CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE;
519 	tx_pwr_ctrl_params->band_edge_5g_unii_2c_hi_ht =
520 		CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT;
521 	tx_pwr_ctrl_params->band_edge_5g_unii_2c_hi_he =
522 		CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE;
523 	tx_pwr_ctrl_params->band_edge_5g_unii_3_lo_ht =
524 		CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT;
525 	tx_pwr_ctrl_params->band_edge_5g_unii_3_lo_he =
526 		CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE;
527 	tx_pwr_ctrl_params->band_edge_5g_unii_3_hi_ht =
528 		CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT;
529 	tx_pwr_ctrl_params->band_edge_5g_unii_3_hi_he =
530 		CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE;
531 	tx_pwr_ctrl_params->band_edge_5g_unii_4_lo_ht =
532 		CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT;
533 	tx_pwr_ctrl_params->band_edge_5g_unii_4_lo_he =
534 		CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE;
535 	tx_pwr_ctrl_params->band_edge_5g_unii_4_hi_ht =
536 		CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT;
537 	tx_pwr_ctrl_params->band_edge_5g_unii_4_hi_he =
538 		CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE;
539 
540 
541 	tx_pwr_ceil_params->max_pwr_2g_dsss = MAX_TX_PWR(wifi_max_tx_pwr_2g_dsss);
542 	tx_pwr_ceil_params->max_pwr_2g_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs7);
543 	tx_pwr_ceil_params->max_pwr_2g_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_2g_mcs0);
544 #ifndef CONFIG_NRF70_2_4G_ONLY
545 	tx_pwr_ceil_params->max_pwr_5g_low_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs7);
546 	tx_pwr_ceil_params->max_pwr_5g_mid_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs7);
547 	tx_pwr_ceil_params->max_pwr_5g_high_mcs7 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs7);
548 	tx_pwr_ceil_params->max_pwr_5g_low_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_low_mcs0);
549 	tx_pwr_ceil_params->max_pwr_5g_mid_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_mid_mcs0);
550 	tx_pwr_ceil_params->max_pwr_5g_high_mcs0 = MAX_TX_PWR(wifi_max_tx_pwr_5g_high_mcs0);
551 #endif /* CONFIG_NRF70_2_4G_ONLY */
552 }
553 
configure_board_dep_params(struct nrf_wifi_board_params * board_params)554 void configure_board_dep_params(struct nrf_wifi_board_params *board_params)
555 {
556 	board_params->pcb_loss_2g = CONFIG_NRF70_PCB_LOSS_2G;
557 #ifndef CONFIG_NRF70_2_4G_ONLY
558 	board_params->pcb_loss_5g_band1 = CONFIG_NRF70_PCB_LOSS_5G_BAND1;
559 	board_params->pcb_loss_5g_band2 = CONFIG_NRF70_PCB_LOSS_5G_BAND2;
560 	board_params->pcb_loss_5g_band3 = CONFIG_NRF70_PCB_LOSS_5G_BAND3;
561 #endif /* CONFIG_NRF70_2_4G_ONLY */
562 }
563 
nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep * drv_priv_zep)564 enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep)
565 {
566 	enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
567 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
568 	void *rpu_ctx = NULL;
569 	enum op_band op_band = CONFIG_NRF_WIFI_OP_BAND;
570 #ifdef CONFIG_NRF_WIFI_LOW_POWER
571 	int sleep_type = -1;
572 
573 #ifndef CONFIG_NRF70_RADIO_TEST
574 	sleep_type = HW_SLEEP_ENABLE;
575 #else
576 	sleep_type = SLEEP_DISABLE;
577 #endif /* CONFIG_NRF70_RADIO_TEST */
578 #endif /* CONFIG_NRF_WIFI_LOW_POWER */
579 	struct nrf_wifi_tx_pwr_ctrl_params tx_pwr_ctrl_params;
580 	struct nrf_wifi_tx_pwr_ceil_params tx_pwr_ceil_params;
581 	struct nrf_wifi_board_params board_params;
582 
583 	unsigned int fw_ver = 0;
584 
585 	rpu_ctx_zep = &drv_priv_zep->rpu_ctx_zep;
586 
587 	rpu_ctx_zep->drv_priv_zep = drv_priv_zep;
588 
589 #ifdef CONFIG_NRF70_RADIO_TEST
590 	rpu_ctx = nrf_wifi_rt_fmac_dev_add(drv_priv_zep->fmac_priv, rpu_ctx_zep);
591 #else
592 	rpu_ctx = nrf_wifi_sys_fmac_dev_add(drv_priv_zep->fmac_priv, rpu_ctx_zep);
593 #endif /* CONFIG_NRF70_RADIO_TEST */
594 
595 	if (!rpu_ctx) {
596 		LOG_ERR("%s: nrf_wifi_fmac_dev_add failed", __func__);
597 		rpu_ctx_zep = NULL;
598 		goto err;
599 	}
600 
601 	rpu_ctx_zep->rpu_ctx = rpu_ctx;
602 
603 	status = nrf_wifi_fw_load(rpu_ctx);
604 	if (status != NRF_WIFI_STATUS_SUCCESS) {
605 		LOG_ERR("%s: nrf_wifi_fw_load failed", __func__);
606 		goto err;
607 	}
608 
609 	status = nrf_wifi_fmac_ver_get(rpu_ctx,
610 				       &fw_ver);
611 
612 	if (status != NRF_WIFI_STATUS_SUCCESS) {
613 		LOG_ERR("%s: FW version read failed", __func__);
614 		goto err;
615 	}
616 
617 	LOG_DBG("Firmware (v%d.%d.%d.%d) booted successfully",
618 		NRF_WIFI_UMAC_VER(fw_ver),
619 		NRF_WIFI_UMAC_VER_MAJ(fw_ver),
620 		NRF_WIFI_UMAC_VER_MIN(fw_ver),
621 		NRF_WIFI_UMAC_VER_EXTRA(fw_ver));
622 
623 	configure_tx_pwr_settings(&tx_pwr_ctrl_params,
624 				  &tx_pwr_ceil_params);
625 
626 	configure_board_dep_params(&board_params);
627 
628 #ifdef CONFIG_NRF70_RADIO_TEST
629 	status = nrf_wifi_rt_fmac_dev_init(rpu_ctx_zep->rpu_ctx,
630 #ifdef CONFIG_NRF_WIFI_LOW_POWER
631 					sleep_type,
632 #endif /* CONFIG_NRF_WIFI_LOW_POWER */
633 					NRF_WIFI_DEF_PHY_CALIB,
634 					op_band,
635 					IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING),
636 					&tx_pwr_ctrl_params,
637 					&tx_pwr_ceil_params,
638 					&board_params,
639 					STRINGIFY(CONFIG_NRF70_REG_DOMAIN));
640 #else
641 	status = nrf_wifi_sys_fmac_dev_init(rpu_ctx_zep->rpu_ctx,
642 #ifdef CONFIG_NRF_WIFI_LOW_POWER
643 					sleep_type,
644 #endif /* CONFIG_NRF_WIFI_LOW_POWER */
645 					NRF_WIFI_DEF_PHY_CALIB,
646 					op_band,
647 					IS_ENABLED(CONFIG_NRF_WIFI_BEAMFORMING),
648 					&tx_pwr_ctrl_params,
649 					&tx_pwr_ceil_params,
650 					&board_params,
651 					STRINGIFY(CONFIG_NRF70_REG_DOMAIN));
652 #endif /* CONFIG_NRF70_RADIO_TEST */
653 
654 
655 	if (status != NRF_WIFI_STATUS_SUCCESS) {
656 		LOG_ERR("%s: nrf_wifi_sys_fmac_dev_init failed", __func__);
657 		goto err;
658 	}
659 
660 	return status;
661 err:
662 	if (rpu_ctx) {
663 		nrf_wifi_fmac_dev_rem(rpu_ctx);
664 		rpu_ctx_zep->rpu_ctx = NULL;
665 	}
666 	return status;
667 }
668 
nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep * drv_priv_zep)669 enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep)
670 {
671 	struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
672 
673 	rpu_ctx_zep = &drv_priv_zep->rpu_ctx_zep;
674 #ifdef CONFIG_NRF70_RADIO_TEST
675 	nrf_wifi_rt_fmac_dev_deinit(rpu_ctx_zep->rpu_ctx);
676 #else
677 	nrf_wifi_sys_fmac_dev_deinit(rpu_ctx_zep->rpu_ctx);
678 #endif /* CONFIG_NRF70_RADIO_TEST */
679 
680 	nrf_wifi_fmac_dev_rem(rpu_ctx_zep->rpu_ctx);
681 
682 	nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
683 	rpu_ctx_zep->extended_capa = NULL;
684 	nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa_mask);
685 	rpu_ctx_zep->extended_capa_mask = NULL;
686 
687 	rpu_ctx_zep->rpu_ctx = NULL;
688 	LOG_DBG("%s: FMAC device removed", __func__);
689 
690 	return NRF_WIFI_STATUS_SUCCESS;
691 }
692 
nrf_wifi_drv_main_zep(const struct device * dev)693 static int nrf_wifi_drv_main_zep(const struct device *dev)
694 {
695 #ifndef CONFIG_NRF70_RADIO_TEST
696 	struct nrf_wifi_fmac_callbk_fns callbk_fns = { 0 };
697 	struct nrf_wifi_data_config_params data_config = { 0 };
698 	struct rx_buf_pool_params rx_buf_pools[MAX_NUM_OF_RX_QUEUES];
699 	struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = dev->data;
700 
701 	vif_ctx_zep->rpu_ctx_zep = &rpu_drv_priv_zep.rpu_ctx_zep;
702 
703 #ifdef CONFIG_NRF70_DATA_TX
704 	data_config.aggregation = aggregation;
705 	data_config.wmm = IS_ENABLED(CONFIG_NRF_WIFI_FEAT_WMM);
706 	data_config.max_num_tx_agg_sessions = max_num_tx_agg_sessions;
707 	data_config.max_num_rx_agg_sessions = max_num_rx_agg_sessions;
708 	data_config.max_tx_aggregation = max_tx_aggregation;
709 	data_config.reorder_buf_size = reorder_buf_size;
710 	data_config.max_rxampdu_size = max_rxampdu_size;
711 	data_config.rate_protection_type = rate_protection_type;
712 	callbk_fns.if_carr_state_chg_callbk_fn = nrf_wifi_if_carr_state_chg;
713 	callbk_fns.rx_frm_callbk_fn = nrf_wifi_if_rx_frm;
714 #if defined(CONFIG_NRF70_RAW_DATA_RX) || defined(CONFIG_NRF70_PROMISC_DATA_RX)
715 	callbk_fns.sniffer_callbk_fn = nrf_wifi_if_sniffer_rx_frm;
716 #endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */
717 #endif
718 	rx_buf_pools[0].num_bufs = rx1_num_bufs;
719 	rx_buf_pools[1].num_bufs = rx2_num_bufs;
720 	rx_buf_pools[2].num_bufs = rx3_num_bufs;
721 	rx_buf_pools[0].buf_sz = rx1_buf_sz;
722 	rx_buf_pools[1].buf_sz = rx2_buf_sz;
723 	rx_buf_pools[2].buf_sz = rx3_buf_sz;
724 
725 #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY
726 	callbk_fns.rpu_recovery_callbk_fn = nrf_wifi_rpu_recovery_cb;
727 #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
728 	callbk_fns.scan_start_callbk_fn = nrf_wifi_event_proc_scan_start_zep;
729 	callbk_fns.scan_done_callbk_fn = nrf_wifi_event_proc_scan_done_zep;
730 	callbk_fns.reg_change_callbk_fn = reg_change_callbk_fn;
731 #ifdef CONFIG_NET_L2_WIFI_MGMT
732 	callbk_fns.disp_scan_res_callbk_fn = nrf_wifi_event_proc_disp_scan_res_zep;
733 #endif /* CONFIG_NET_L2_WIFI_MGMT */
734 #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
735 	callbk_fns.rx_bcn_prb_resp_callbk_fn = nrf_wifi_rx_bcn_prb_resp_frm;
736 #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
737 #ifdef CONFIG_NRF70_SYSTEM_MODE
738 	callbk_fns.set_if_callbk_fn = nrf_wifi_set_iface_event_handler;
739 #endif /* CONFIG_NRF70_SYSTEM_MODE */
740 #ifdef CONFIG_NRF70_STA_MODE
741 	callbk_fns.twt_config_callbk_fn = nrf_wifi_event_proc_twt_setup_zep;
742 	callbk_fns.twt_teardown_callbk_fn = nrf_wifi_event_proc_twt_teardown_zep;
743 	callbk_fns.twt_sleep_callbk_fn = nrf_wifi_event_proc_twt_sleep_zep;
744 	callbk_fns.event_get_reg = nrf_wifi_event_get_reg_zep;
745 	callbk_fns.event_get_ps_info = nrf_wifi_event_proc_get_power_save_info;
746 	callbk_fns.cookie_rsp_callbk_fn = nrf_wifi_event_proc_cookie_rsp;
747 	callbk_fns.process_rssi_from_rx = nrf_wifi_process_rssi_from_rx;
748 	callbk_fns.scan_res_callbk_fn = nrf_wifi_wpa_supp_event_proc_scan_res;
749 	callbk_fns.auth_resp_callbk_fn = nrf_wifi_wpa_supp_event_proc_auth_resp;
750 	callbk_fns.assoc_resp_callbk_fn = nrf_wifi_wpa_supp_event_proc_assoc_resp;
751 	callbk_fns.deauth_callbk_fn = nrf_wifi_wpa_supp_event_proc_deauth;
752 	callbk_fns.disassoc_callbk_fn = nrf_wifi_wpa_supp_event_proc_disassoc;
753 	callbk_fns.get_station_callbk_fn = nrf_wifi_wpa_supp_event_proc_get_sta;
754 	callbk_fns.get_interface_callbk_fn = nrf_wifi_wpa_supp_event_proc_get_if;
755 	callbk_fns.mgmt_tx_status = nrf_wifi_wpa_supp_event_mgmt_tx_status;
756 	callbk_fns.unprot_mlme_mgmt_rx_callbk_fn = nrf_wifi_wpa_supp_event_proc_unprot_mgmt;
757 	callbk_fns.event_get_wiphy = nrf_wifi_wpa_supp_event_get_wiphy;
758 	callbk_fns.mgmt_rx_callbk_fn = nrf_wifi_wpa_supp_event_mgmt_rx_callbk_fn;
759 	callbk_fns.get_conn_info_callbk_fn = nrf_wifi_supp_event_proc_get_conn_info;
760 #endif /* CONFIG_NRF70_STA_MODE */
761 
762 	/* The OSAL layer needs to be initialized before any other initialization
763 	 * so that other layers (like FW IF,HW IF etc) have access to OS ops
764 	 */
765 	nrf_wifi_osal_init(&nrf_wifi_os_zep_ops);
766 
767 	rpu_drv_priv_zep.fmac_priv = nrf_wifi_sys_fmac_init(&data_config,
768 							    rx_buf_pools,
769 							    &callbk_fns);
770 #else /* !CONFIG_NRF70_RADIO_TEST */
771 	enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
772 
773 	/* The OSAL layer needs to be initialized before any other initialization
774 	 * so that other layers (like FW IF,HW IF etc) have access to OS ops
775 	 */
776 	nrf_wifi_osal_init(&nrf_wifi_os_zep_ops);
777 
778 	rpu_drv_priv_zep.fmac_priv = nrf_wifi_rt_fmac_init();
779 #endif /* CONFIG_NRF70_RADIO_TEST */
780 
781 	if (rpu_drv_priv_zep.fmac_priv == NULL) {
782 		LOG_ERR("%s: nrf_wifi_fmac_init failed",
783 			__func__);
784 		goto err;
785 	}
786 
787 #ifdef CONFIG_NRF70_DATA_TX
788 	struct nrf_wifi_sys_fmac_priv *sys_fpriv = NULL;
789 
790 	sys_fpriv = wifi_fmac_priv(rpu_drv_priv_zep.fmac_priv);
791 	sys_fpriv->max_ampdu_len_per_token =
792 		(RPU_PKTRAM_SIZE - (CONFIG_NRF70_RX_NUM_BUFS * CONFIG_NRF70_RX_MAX_DATA_SIZE)) /
793 		CONFIG_NRF70_MAX_TX_TOKENS;
794 	/* Align to 4-byte */
795 	sys_fpriv->max_ampdu_len_per_token &= ~0x3;
796 
797 	/* Alignment overhead for size based coalesce */
798 	sys_fpriv->avail_ampdu_len_per_token =
799 	sys_fpriv->max_ampdu_len_per_token -
800 		(MAX_PKT_RAM_TX_ALIGN_OVERHEAD * max_tx_aggregation);
801 #endif /* CONFIG_NRF70_DATA_TX */
802 
803 #ifdef CONFIG_NRF70_RADIO_TEST
804 	status = nrf_wifi_fmac_dev_add_zep(&rpu_drv_priv_zep);
805 	if (status != NRF_WIFI_STATUS_SUCCESS) {
806 		LOG_ERR("%s: nrf_wifi_fmac_dev_add_zep failed", __func__);
807 		goto fmac_deinit;
808 	}
809 #else
810 	k_work_init_delayable(&vif_ctx_zep->scan_timeout_work,
811 			      nrf_wifi_scan_timeout_work);
812 #endif /* CONFIG_NRF70_RADIO_TEST */
813 
814 	k_mutex_init(&rpu_drv_priv_zep.rpu_ctx_zep.rpu_lock);
815 	return 0;
816 #ifdef CONFIG_NRF70_RADIO_TEST
817 fmac_deinit:
818 	nrf_wifi_fmac_deinit(rpu_drv_priv_zep.fmac_priv);
819 	nrf_wifi_osal_deinit();
820 #endif /* CONFIG_NRF70_RADIO_TEST */
821 err:
822 	return -1;
823 }
824 
825 #ifndef CONFIG_NRF70_RADIO_TEST
826 #ifdef CONFIG_NET_L2_WIFI_MGMT
827 static struct wifi_mgmt_ops nrf_wifi_mgmt_ops = {
828 	.scan = nrf_wifi_disp_scan_zep,
829 #ifdef CONFIG_NET_STATISTICS_WIFI
830 	.get_stats = nrf_wifi_stats_get,
831 	.reset_stats = nrf_wifi_stats_reset,
832 #endif /* CONFIG_NET_STATISTICS_WIFI */
833 #ifdef CONFIG_NRF70_STA_MODE
834 	.set_power_save = nrf_wifi_set_power_save,
835 	.set_twt = nrf_wifi_set_twt,
836 	.reg_domain = nrf_wifi_reg_domain,
837 	.get_power_save_config = nrf_wifi_get_power_save_config,
838 	.set_rts_threshold = nrf_wifi_set_rts_threshold,
839 	.get_rts_threshold = nrf_wifi_get_rts_threshold,
840 #endif
841 #ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES
842 	.mode = nrf_wifi_mode,
843 #endif
844 #if defined(CONFIG_NRF70_RAW_DATA_TX) || defined(CONFIG_NRF70_RAW_DATA_RX)
845 	.channel = nrf_wifi_channel,
846 #endif /* CONFIG_NRF70_RAW_DATA_TX || CONFIG_NRF70_RAW_DATA_RX */
847 #if defined(CONFIG_NRF70_RAW_DATA_RX) || defined(CONFIG_NRF70_PROMISC_DATA_RX)
848 	.filter = nrf_wifi_filter,
849 #endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */
850 };
851 #endif /* CONFIG_NET_L2_WIFI_MGMT */
852 
853 
854 
855 #ifdef CONFIG_NRF70_STA_MODE
856 static struct zep_wpa_supp_dev_ops wpa_supp_ops = {
857 	.init = nrf_wifi_wpa_supp_dev_init,
858 	.deinit = nrf_wifi_wpa_supp_dev_deinit,
859 	.scan2 = nrf_wifi_wpa_supp_scan2,
860 	.scan_abort = nrf_wifi_wpa_supp_scan_abort,
861 	.get_scan_results2 = nrf_wifi_wpa_supp_scan_results_get,
862 	.deauthenticate = nrf_wifi_wpa_supp_deauthenticate,
863 	.authenticate = nrf_wifi_wpa_supp_authenticate,
864 	.associate = nrf_wifi_wpa_supp_associate,
865 	.set_supp_port = nrf_wifi_wpa_set_supp_port,
866 	.set_key = nrf_wifi_wpa_supp_set_key,
867 	.signal_poll = nrf_wifi_wpa_supp_signal_poll,
868 	.send_mlme = nrf_wifi_nl80211_send_mlme,
869 	.get_wiphy = nrf_wifi_supp_get_wiphy,
870 	.register_frame = nrf_wifi_supp_register_frame,
871 	.get_capa = nrf_wifi_supp_get_capa,
872 	.get_conn_info = nrf_wifi_supp_get_conn_info,
873 	.set_country = nrf_wifi_supp_set_country,
874 	.get_country = nrf_wifi_supp_get_country,
875 #ifdef CONFIG_NRF70_AP_MODE
876 	.init_ap = nrf_wifi_wpa_supp_init_ap,
877 	.start_ap = nrf_wifi_wpa_supp_start_ap,
878 	.change_beacon = nrf_wifi_wpa_supp_change_beacon,
879 	.stop_ap = nrf_wifi_wpa_supp_stop_ap,
880 	.deinit_ap = nrf_wifi_wpa_supp_deinit_ap,
881 	.sta_add = nrf_wifi_wpa_supp_sta_add,
882 	.sta_remove = nrf_wifi_wpa_supp_sta_remove,
883 	.register_mgmt_frame = nrf_wifi_supp_register_mgmt_frame,
884 	.sta_set_flags = nrf_wifi_wpa_supp_sta_set_flags,
885 	.get_inact_sec = nrf_wifi_wpa_supp_sta_get_inact_sec,
886 #endif /* CONFIG_NRF70_AP_MODE */
887 };
888 #endif /* CONFIG_NRF70_STA_MODE */
889 #endif /* !CONFIG_NRF70_RADIO_TEST */
890 
891 
892 #ifdef CONFIG_NET_L2_ETHERNET
893 static const struct net_wifi_mgmt_offload wifi_offload_ops = {
894 	.wifi_iface.iface_api.init = nrf_wifi_if_init_zep,
895 	.wifi_iface.start = nrf_wifi_if_start_zep,
896 	.wifi_iface.stop = nrf_wifi_if_stop_zep,
897 	.wifi_iface.set_config = nrf_wifi_if_set_config_zep,
898 	.wifi_iface.get_config = nrf_wifi_if_get_config_zep,
899 	.wifi_iface.get_capabilities = nrf_wifi_if_caps_get,
900 	.wifi_iface.send = nrf_wifi_if_send,
901 #ifdef CONFIG_NET_STATISTICS_ETHERNET
902 	.wifi_iface.get_stats = nrf_wifi_eth_stats_get,
903 #endif /* CONFIG_NET_STATISTICS_ETHERNET */
904 #ifdef CONFIG_NET_L2_WIFI_MGMT
905 	.wifi_mgmt_api = &nrf_wifi_mgmt_ops,
906 #endif /* CONFIG_NET_L2_WIFI_MGMT */
907 #ifdef CONFIG_NRF70_STA_MODE
908 	.wifi_drv_ops = &wpa_supp_ops,
909 #endif /* CONFIG_NRF70_STA_MODE */
910 };
911 #endif /* CONFIG_NET_L2_ETHERNET */
912 
913 
914 
915 #ifdef CONFIG_NET_L2_ETHERNET
916 ETH_NET_DEVICE_DT_INST_DEFINE(0,
917 		    nrf_wifi_drv_main_zep, /* init_fn */
918 		    NULL, /* pm_action_cb */
919 		    &rpu_drv_priv_zep.rpu_ctx_zep.vif_ctx_zep[0], /* data */
920 #ifdef CONFIG_NRF70_STA_MODE
921 		    &wpa_supp_ops, /* cfg */
922 #else /* CONFIG_NRF70_STA_MODE */
923 		    NULL, /* cfg */
924 #endif /* !CONFIG_NRF70_STA_MODE */
925 		    CONFIG_WIFI_INIT_PRIORITY, /* prio */
926 		    &wifi_offload_ops, /* api */
927 		    CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
928 #else
929 DEVICE_DT_INST_DEFINE(0,
930 	      nrf_wifi_drv_main_zep, /* init_fn */
931 	      NULL, /* pm_action_cb */
932 #ifndef CONFIG_NRF70_RADIO_TEST
933 	      &rpu_drv_priv_zep, /* data */
934 #else /* !CONFIG_NRF70_RADIO_TEST */
935 	      NULL,
936 #endif /* CONFIG_NRF70_RADIO_TEST */
937 	      NULL, /* cfg */
938 	      POST_KERNEL,
939 	      CONFIG_WIFI_INIT_PRIORITY, /* prio */
940 	      NULL); /* api */
941 #endif /* CONFIG_NET_L2_ETHERNET */
942 
943 #ifdef CONFIG_NET_CONNECTION_MANAGER_CONNECTIVITY_WIFI_MGMT
944 CONNECTIVITY_WIFI_MGMT_BIND(Z_DEVICE_DT_DEV_ID(DT_DRV_INST(0)));
945 #endif /* CONFIG_NET_CONNECTION_MANAGER_CONNECTIVITY_WIFI_MGMT */
946