Skip to content

Commit 9901d89

Browse files
committed
drivers: wifi: nrf7002: Add support for multiple virtual interfaces (VIFs)
Description: The nRF7002 firmware supports two virtual interfaces (VIFs) that can operate in different modes (e.g., AP and STA). However, the existing Zephyr driver only utilizes a single VIF, preventing full multi-interface support. This commit extends the nRF7002 driver to support multiple VIFs by making the following modifications: * The driver already contains an array of vif_ctx_zep, but only the first item was being used. Now, a second Ethernet device is registered using vif_ctx_zep[1], enabling multi-VIF operation. * Introduced vif_ctx_cnt to keep track of active interfaces and manage their state effectively. * Ensured that FMAC (Firmware MAC) is initialized only once, avoiding redundant initializations when multiple VIFs are present. * The UMAC control commands previously did not associate responses with the issuing VIF. A queue is now introduced to track the originating VIF for each command and correctly route the response event to the corresponding interface. Signed-off-by: Hanan Arshad <hananarshad619@gmail.com>
1 parent 58527c1 commit 9901d89

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ config NRF70_AP_MODE
108108
depends on WIFI_NM_WPA_SUPPLICANT_AP
109109
default y if WIFI_USAGE_MODE_AP || WIFI_USAGE_MODE_STA_AP
110110

111+
config NRF70_ENABLE_DUAL_VIF
112+
bool "Dual virtual Wi-Fi interfaces"
113+
default y if WIFI_NM_MAX_MANAGED_INTERFACES = 2
114+
depends on (WIFI_NRF7002 || WIFI_NRF7001) && NET_L2_ETHERNET
115+
help
116+
Enable support for two virtual Wi-Fi interfaces (VIFs).
117+
When enabled, the driver can operate two VIFs simultaneously,
118+
allowing use cases such as one interface in AP mode and another in STA mode.
119+
111120
config NRF70_P2P_MODE
112121
bool "P2P support in driver"
113122

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,19 @@ static int nrf_wifi_drv_main_zep(const struct device *dev)
725725
struct nrf_wifi_data_config_params data_config = { 0 };
726726
struct rx_buf_pool_params rx_buf_pools[MAX_NUM_OF_RX_QUEUES];
727727
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = dev->data;
728+
static unsigned int vif_ctx_cnt;
728729

730+
if (vif_ctx_cnt >= MAX_NUM_VIFS) {
731+
LOG_ERR("%s: Max number of VIFs reached", __func__);
732+
return -ENOMEM;
733+
}
734+
735+
if (vif_ctx_cnt >= 1) {
736+
/* FMAC is already initialized for VIF-0 */
737+
return 0;
738+
}
739+
740+
++vif_ctx_cnt;
729741
vif_ctx_zep->rpu_ctx_zep = &rpu_drv_priv_zep.rpu_ctx_zep;
730742

731743
#ifdef CONFIG_NRF70_DATA_TX
@@ -953,6 +965,21 @@ ETH_NET_DEVICE_DT_INST_DEFINE(0,
953965
CONFIG_WIFI_INIT_PRIORITY, /* prio */
954966
&wifi_offload_ops, /* api */
955967
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
968+
#ifdef CONFIG_NRF70_ENABLE_DUAL_VIF
969+
/* Register second interface */
970+
ETH_NET_DEVICE_DT_INST_DEFINE(1,
971+
nrf_wifi_drv_main_zep, /* init_fn */
972+
NULL, /* pm_action_cb */
973+
&rpu_drv_priv_zep.rpu_ctx_zep.vif_ctx_zep[1], /* data */
974+
#ifdef CONFIG_NRF70_STA_MODE
975+
&wpa_supp_ops, /* cfg */
976+
#else /* CONFIG_NRF70_STA_MODE */
977+
NULL, /* cfg */
978+
#endif /* !CONFIG_NRF70_STA_MODE */
979+
CONFIG_WIFI_INIT_PRIORITY, /* prio */
980+
&wifi_offload_ops, /* api */
981+
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
982+
#endif /* NRF70_ENABLE_DUAL_VIF */
956983
#else
957984
DEVICE_DT_INST_DEFINE(0,
958985
nrf_wifi_drv_main_zep, /* init_fn */

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@ int nrf_wifi_if_start_zep(const struct device *dev)
794794
}
795795

796796
k_mutex_init(&vif_ctx_zep->vif_lock);
797-
rpu_ctx_zep->vif_ctx_zep[vif_ctx_zep->vif_idx].if_type =
798-
add_vif_info.iftype;
797+
vif_ctx_zep->if_type = add_vif_info.iftype;
799798

800799
/* Check if user has provided a valid MAC address, if not
801800
* fetch it from OTP.

drivers/wifi/nrf_wifi/src/wpa_supp_if.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,10 @@ void *nrf_wifi_wpa_supp_dev_init(void *supp_drv_if_ctx, const char *iface_name,
447447
struct zep_wpa_supp_dev_callbk_fns *supp_callbk_fns)
448448
{
449449
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
450-
const struct device *device = DEVICE_DT_GET(DT_CHOSEN(zephyr_wifi));
450+
/* Get device for each interface */
451+
int if_idx = net_if_get_by_name(iface_name);
452+
struct net_if *iface = net_if_get_by_index(if_idx);
453+
const struct device *device = net_if_get_device(iface);
451454

452455
if (!device) {
453456
LOG_ERR("%s: Interface %s not found", __func__, iface_name);

0 commit comments

Comments
 (0)