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