Skip to content

Commit fc08ad1

Browse files
krish2718nordicjm
authored andcommitted
[nrf fromtree] 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 <[email protected]> Signed-off-by: Chaitanya Tata <[email protected]> (cherry picked from commit 1c6a00b)
1 parent be5d777 commit fc08ad1

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
@@ -743,9 +743,21 @@ static int nrf_wifi_drv_main_zep(const struct device *dev)
743743
struct nrf_wifi_data_config_params data_config = { 0 };
744744
struct rx_buf_pool_params rx_buf_pools[MAX_NUM_OF_RX_QUEUES];
745745
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = dev->data;
746+
static unsigned char fixed_vif_cnt;
746747

748+
if (fixed_vif_cnt >= MAX_NUM_VIFS) {
749+
LOG_ERR("%s: Max number of VIFs reached", __func__);
750+
return -ENOMEM;
751+
}
752+
753+
/* Setup the linkage between the FMAC and the VIF contexts */
747754
vif_ctx_zep->rpu_ctx_zep = &rpu_drv_priv_zep.rpu_ctx_zep;
748755

756+
if (fixed_vif_cnt++ > 0) {
757+
/* FMAC is already initialized for VIF-0 */
758+
return 0;
759+
}
760+
749761
#ifdef CONFIG_NRF70_DATA_TX
750762
data_config.aggregation = aggregation;
751763
data_config.wmm = IS_ENABLED(CONFIG_NRF_WIFI_FEAT_WMM);
@@ -979,6 +991,21 @@ ETH_NET_DEVICE_DT_INST_DEFINE(0,
979991
CONFIG_WIFI_INIT_PRIORITY, /* prio */
980992
&wifi_offload_ops, /* api */
981993
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
994+
#ifdef CONFIG_NRF70_ENABLE_DUAL_VIF
995+
/* Register second interface */
996+
ETH_NET_DEVICE_DT_INST_DEFINE(1,
997+
nrf_wifi_drv_main_zep, /* init_fn */
998+
NULL, /* pm_action_cb */
999+
&rpu_drv_priv_zep.rpu_ctx_zep.vif_ctx_zep[1], /* data */
1000+
#ifdef CONFIG_NRF70_STA_MODE
1001+
&wpa_supp_ops, /* cfg */
1002+
#else /* CONFIG_NRF70_STA_MODE */
1003+
NULL, /* cfg */
1004+
#endif /* !CONFIG_NRF70_STA_MODE */
1005+
CONFIG_WIFI_INIT_PRIORITY, /* prio */
1006+
&wifi_offload_ops, /* api */
1007+
CONFIG_NRF_WIFI_IFACE_MTU); /*mtu */
1008+
#endif /* NRF70_ENABLE_DUAL_VIF */
9821009
#else
9831010
DEVICE_DT_INST_DEFINE(0,
9841011
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
@@ -824,8 +824,7 @@ int nrf_wifi_if_start_zep(const struct device *dev)
824824
}
825825

826826
k_mutex_init(&vif_ctx_zep->vif_lock);
827-
rpu_ctx_zep->vif_ctx_zep[vif_ctx_zep->vif_idx].if_type =
828-
add_vif_info.iftype;
827+
vif_ctx_zep->if_type = add_vif_info.iftype;
829828

830829
/* Check if user has provided a valid MAC address, if not
831830
* 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)