Skip to content

Commit 34c8dd2

Browse files
committed
[nrf fromlist] nrf_wifi: Add nRF71 support
nRF7120 PDK support that uses IPC as comms b/w APP and Wi-Fi domains. Upstream PR #: 88816 Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 8d5092e commit 34c8dd2

File tree

16 files changed

+970
-27
lines changed

16 files changed

+970
-27
lines changed

drivers/wifi/nrf_wifi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ zephyr_library_sources_ifndef(CONFIG_NRF70_OFFLOADED_RAW_TX
2727
src/fmac_main.c
2828
)
2929

30+
if (NOT CONFIG_NRF71_ON_IPC)
3031
zephyr_library_sources_ifdef(CONFIG_NRF_WIFI_PATCHES_BUILTIN
3132
src/fw_load.c
3233
)
34+
endif()
3335

3436
if(NOT CONFIG_NRF70_RADIO_TEST AND NOT CONFIG_NRF70_OFFLOADED_RAW_TX)
3537
zephyr_library_sources(

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ menuconfig WIFI_NRF70
1616
depends on \
1717
DT_HAS_NORDIC_NRF7002_SPI_ENABLED || DT_HAS_NORDIC_NRF7002_QSPI_ENABLED || \
1818
DT_HAS_NORDIC_NRF7001_SPI_ENABLED || DT_HAS_NORDIC_NRF7001_QSPI_ENABLED || \
19-
DT_HAS_NORDIC_NRF7000_SPI_ENABLED || DT_HAS_NORDIC_NRF7000_QSPI_ENABLED
19+
DT_HAS_NORDIC_NRF7000_SPI_ENABLED || DT_HAS_NORDIC_NRF7000_QSPI_ENABLED || \
20+
DT_HAS_NORDIC_WIFI71_ENABLED
2021
help
2122
Nordic Wi-Fi Driver
2223

2324
if WIFI_NRF70
2425
# Hidden symbols for internal use
2526
config WIFI_NRF7002
2627
bool
27-
default y if DT_HAS_NORDIC_NRF7002_SPI_ENABLED || DT_HAS_NORDIC_NRF7002_QSPI_ENABLED
28+
default y if DT_HAS_NORDIC_NRF7002_SPI_ENABLED || DT_HAS_NORDIC_NRF7002_QSPI_ENABLED || DT_HAS_NORDIC_WIFI71_ENABLED
2829

2930
config WIFI_NRF7001
3031
bool
@@ -133,7 +134,8 @@ endchoice
133134

134135
config NRF_WIFI_LOW_POWER
135136
bool "Low power mode in nRF Wi-Fi chipsets"
136-
default y
137+
depends on !NRF71_ON_IPC
138+
default y if !NRF71_ON_IPC
137139

138140
config NRF70_TCP_IP_CHECKSUM_OFFLOAD
139141
bool "TCP/IP checksum offload"
@@ -184,6 +186,7 @@ config NRF70_SR_COEX_RF_SWITCH
184186

185187
config NRF70_SR_COEX_SLEEP_CTRL_GPIO_CTRL
186188
bool "Configuration of GPIO control for coexistence"
189+
depends on !NRF71_ON_IPC
187190
default y
188191

189192
config NRF70_SR_COEX_SWCTRL1_OUTPUT

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,12 @@ void reg_change_callbk_fn(void *vif_ctx,
479479
}
480480
#endif /* !CONFIG_NRF70_RADIO_TEST */
481481

482+
#ifdef CONFIG_DT_HAS_NORDIC_WIFI71_ENABLED
483+
#define MAX_TX_PWR(label) DT_PROP(DT_NODELABEL(wifi), label) * 4
484+
#else
482485
/* DTS uses 1dBm as the unit for TX power, while the RPU uses 0.25dBm */
483486
#define MAX_TX_PWR(label) DT_PROP(DT_NODELABEL(nrf70), label) * 4
487+
#endif /* CONFIG_DT_HAS_NORDIC_WIFI71_ENABLED */
484488

485489
void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_params,
486490
struct nrf_wifi_tx_pwr_ceil_params *tx_pwr_ceil_params)

drivers/wifi/nrf_wifi/src/fw_load.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx)
3131
LOG_ERR("%s: nrf_wifi_fmac_fw_parse failed", __func__);
3232
return status;
3333
}
34+
#ifndef CONFIG_NRF71_ON_IPC
3435
/* Load the FW patches to the RPU */
3536
status = nrf_wifi_fmac_fw_load(rpu_ctx, &fw_info);
3637

3738
if (status != NRF_WIFI_STATUS_SUCCESS) {
3839
LOG_ERR("%s: nrf_wifi_fmac_fw_load failed", __func__);
3940
}
40-
41+
#endif /* !CONFIG_NRF71_ON_IPC */
4142
return status;
4243
}

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ enum nrf_wifi_status nrf_wifi_get_mac_addr(struct nrf_wifi_vif_ctx_zep *vif_ctx_
565565
random_mac_addr,
566566
WIFI_MAC_ADDR_LEN);
567567
#elif CONFIG_WIFI_OTP_MAC_ADDRESS
568+
#ifndef CONFIG_NRF71_ON_IPC
568569
status = nrf_wifi_fmac_otp_mac_addr_get(fmac_dev_ctx,
569570
vif_ctx_zep->vif_idx,
570571
vif_ctx_zep->mac_addr.addr);
@@ -573,6 +574,15 @@ enum nrf_wifi_status nrf_wifi_get_mac_addr(struct nrf_wifi_vif_ctx_zep *vif_ctx_
573574
__func__);
574575
goto unlock;
575576
}
577+
#else
578+
/* Set dummy MAC address */
579+
vif_ctx_zep->mac_addr.addr[0] = 0x00;
580+
vif_ctx_zep->mac_addr.addr[1] = 0x00;
581+
vif_ctx_zep->mac_addr.addr[2] = 0x5E;
582+
vif_ctx_zep->mac_addr.addr[3] = 0x00;
583+
vif_ctx_zep->mac_addr.addr[4] = 0x10;
584+
vif_ctx_zep->mac_addr.addr[5] = 0x00;
585+
#endif /* !CONFIG_NRF71_ON_IPC */
576586
#endif
577587

578588
if (!nrf_wifi_utils_is_mac_addr_valid(vif_ctx_zep->mac_addr.addr)) {

modules/nrf_wifi/bus/CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ if (CONFIG_NRF70_BUSLIB)
1717
inc
1818
${NRF_WIFI_DIR}/os_if/inc
1919
)
20+
zephyr_library_include_directories_ifdef(CONFIG_NRF71_ON_IPC
21+
${NRF_WIFI_DIR}/bus_if/bal/inc
22+
# QSPI is common to (Q)SPI and IPC
23+
${NRF_WIFI_DIR}/bus_if/bus/qspi/inc
24+
${NRF_WIFI_DIR}/fw_if/umac_if/inc/fw
25+
${NRF_WIFI_DIR}/hw_if/hal/inc
26+
)
27+
28+
zephyr_library_compile_definitions_ifdef(CONFIG_NRF71_ON_IPC
29+
NRF71_ON_IPC
30+
)
2031
zephyr_library_sources(
21-
rpu_hw_if.c
2232
device.c
2333
)
2434
if(NOT CONFIG_WIFI_NRF70)
@@ -27,9 +37,16 @@ if (CONFIG_NRF70_BUSLIB)
2737
)
2838
endif()
2939
zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI
40+
rpu_hw_if.c
3041
qspi_if.c
3142
)
3243
zephyr_library_sources_ifdef(CONFIG_NRF70_ON_SPI
44+
rpu_hw_if.c
3345
spi_if.c
3446
)
47+
zephyr_library_sources_ifdef(CONFIG_NRF71_ON_IPC
48+
ipc_if.c
49+
ipc_service.c
50+
spsc_qm.c
51+
)
3552
endif()

modules/nrf_wifi/bus/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ config NRF70_ON_SPI
3030
$(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7000_SPI))
3131
select SPI
3232

33+
config NRF71_ON_IPC
34+
def_bool DT_HAS_NORDIC_WIFI71_ENABLED
35+
select MBOX
36+
select IPC
37+
select IPC_SERVICE
38+
select SPSC_PBUF
39+
3340
module = WIFI_NRF70_BUSLIB
3441
module-dep = LOG
3542
module-str = Log level for Wi-Fi nRF70 bus library

modules/nrf_wifi/bus/device.c

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,45 @@
1212
#include <zephyr/kernel.h>
1313
#include <zephyr/sys/printk.h>
1414
#include <zephyr/drivers/gpio.h>
15-
#include <zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h>
1615
#include <stdio.h>
1716
#include <string.h>
1817

18+
#if defined(CONFIG_NRF71_ON_IPC)
19+
#include "ipc_if.h"
20+
#else
21+
#include <zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h>
1922
#include "spi_if.h"
20-
2123
static struct qspi_config config;
24+
#endif
2225

23-
#if defined(CONFIG_NRF70_ON_QSPI)
24-
static struct qspi_dev qspi = {.init = qspi_init,
25-
.deinit = qspi_deinit,
26-
.read = qspi_read,
27-
.write = qspi_write,
28-
.hl_read = qspi_hl_read};
26+
27+
#if defined(CONFIG_NRF71_ON_IPC)
28+
static struct rpu_dev ipc = {
29+
.init = ipc_init,
30+
.deinit = ipc_deinit,
31+
.send = ipc_send,
32+
.recv = ipc_recv,
33+
.register_rx_cb = ipc_register_rx_cb,
34+
};
35+
#elif defined(CONFIG_NRF70_ON_QSPI)
36+
static struct qspi_dev qspi = {
37+
.init = qspi_init,
38+
.deinit = qspi_deinit,
39+
.read = qspi_read,
40+
.write = qspi_write,
41+
.hl_read = qspi_hl_read
42+
};
2943
#else
30-
static struct qspi_dev spim = {.init = spim_init,
31-
.deinit = spim_deinit,
32-
.read = spim_read,
33-
.write = spim_write,
34-
.hl_read = spim_hl_read};
44+
static struct qspi_dev spim = {
45+
.init = spim_init,
46+
.deinit = spim_deinit,
47+
.read = spim_read,
48+
.write = spim_write,
49+
.hl_read = spim_hl_read
50+
};
3551
#endif
3652

53+
#ifndef CONFIG_NRF71_ON_IPC
3754
struct qspi_config *qspi_defconfig(void)
3855
{
3956
memset(&config, 0, sizeof(struct qspi_config));
@@ -71,12 +88,20 @@ struct qspi_config *qspi_get_config(void)
7188
{
7289
return &config;
7390
}
91+
#endif
7492

93+
#ifndef CONFIG_NRF71_ON_IPC
7594
struct qspi_dev *qspi_dev(void)
7695
{
77-
#if CONFIG_NRF70_ON_QSPI
78-
return &qspi;
96+
#if defined(CONFIG_NRF70_ON_QSPI)
97+
return &qspi;
7998
#else
80-
return &spim;
99+
return &spim;
81100
#endif
82101
}
102+
#else
103+
struct rpu_dev *rpu_dev(void)
104+
{
105+
return &ipc;
106+
}
107+
#endif /*! CONFIG_NRF71_ON_IPC */

modules/nrf_wifi/bus/ipc_if.c

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
/*
3+
* Copyright (c) 2024 Nordic Semiconductor ASA
4+
*
5+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
6+
*/
7+
8+
/**
9+
* @brief File containing API definitions for the
10+
* IPC bus layer of the nRF71 Wi-Fi driver.
11+
*/
12+
#include <zephyr/kernel.h>
13+
#include <zephyr/logging/log.h>
14+
15+
LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL);
16+
17+
#include "ipc_if.h"
18+
#include "bal_structs.h"
19+
#include "qspi.h"
20+
#include "common/hal_structs_common.h"
21+
22+
/* Define addresses to use for the free queues */
23+
#define EVENT_FREEQ_ADDR 0x200C2000
24+
#define CMD_FREEQ_ADDR 0x200C3000
25+
26+
#define NUM_INSTANCES 3
27+
#define NUM_ENDPOINTS 1
28+
29+
struct device *ipc_instances[NUM_INSTANCES];
30+
struct ipc_ept ept[NUM_ENDPOINTS];
31+
struct ipc_ept_cfg ept_cfg[NUM_ENDPOINTS];
32+
33+
static WIFI_IPC_T wifi_event;
34+
static WIFI_IPC_T wifi_cmd;
35+
static WIFI_IPC_T wifi_tx;
36+
37+
static int (*callback_func)(void *data);
38+
39+
static void event_recv(void *data, void *priv)
40+
{
41+
struct nrf_wifi_bus_qspi_dev_ctx *dev_ctx = NULL;
42+
struct nrf_wifi_bal_dev_ctx *bal_dev_ctx = NULL;
43+
struct nrf_wifi_hal_dev_ctx *hal_dev_ctx = NULL;
44+
45+
dev_ctx = (struct nrf_wifi_bus_qspi_dev_ctx *) priv;
46+
bal_dev_ctx = (struct nrf_wifi_bal_dev_ctx *) dev_ctx->bal_dev_ctx;
47+
hal_dev_ctx = (struct nrf_wifi_hal_dev_ctx *) bal_dev_ctx->hal_dev_ctx;
48+
LOG_DBG("Event IPC received");
49+
50+
hal_dev_ctx->ipc_msg = data;
51+
callback_func(priv);
52+
LOG_DBG("Event IPC callback completed");
53+
}
54+
55+
int ipc_init() {
56+
wifi_ipc_host_event_init(&wifi_event, EVENT_FREEQ_ADDR);
57+
LOG_DBG("Event IPC initialized");
58+
wifi_ipc_host_cmd_init(&wifi_cmd, CMD_FREEQ_ADDR);
59+
LOG_DBG("Command IPC initialized");
60+
return 0;
61+
}
62+
63+
int ipc_deinit(void) {
64+
return 0;
65+
}
66+
67+
int ipc_recv(ipc_ctx_t ctx, void *data, int len) {
68+
return 0;
69+
}
70+
71+
int ipc_send(ipc_ctx_t ctx, const void *data, int len) {
72+
73+
int ret = 0;
74+
75+
switch (ctx.inst) {
76+
case IPC_INSTANCE_CMD_CTRL:
77+
/* IPC service on RPU may not have been established. Keep trying. */
78+
do {
79+
ret = wifi_ipc_host_cmd_send_memcpy(&wifi_cmd, data, len);
80+
} while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY);
81+
82+
/* Critical error during IPC service transfer. Should never happen. */
83+
if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) {
84+
LOG_ERR("Critical error during IPC CMD busyq transfer");
85+
return -1;
86+
}
87+
break;
88+
case IPC_INSTANCE_CMD_TX:
89+
/* IPC service on RPU may not have been established. Keep trying. */
90+
do {
91+
ret = wifi_ipc_host_tx_send(&wifi_tx, data);
92+
} while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY);
93+
94+
/* Critical error during IPC service transfer. Should never happen. */
95+
if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) {
96+
LOG_ERR("Critical error during IPC TX busyq transfer");
97+
return -1;
98+
}
99+
case IPC_INSTANCE_RX:
100+
break;
101+
default:
102+
break;
103+
}
104+
105+
LOG_DBG("IPC send completed: %d", ret);
106+
107+
return ret;
108+
}
109+
110+
int ipc_register_rx_cb(int (*rx_handler)(void *priv), void *data)
111+
{
112+
int ret;
113+
114+
callback_func = rx_handler;
115+
116+
ret = wifi_ipc_bind_ipc_service_tx_rx(&wifi_cmd, &wifi_event, DEVICE_DT_GET(DT_NODELABEL(ipc0)), event_recv, data);
117+
if (ret != WIFI_IPC_STATUS_OK) {
118+
LOG_ERR("Failed to bind IPC service: %d", ret);
119+
return -1;
120+
}
121+
122+
ret = wifi_ipc_bind_ipc_service(&wifi_tx, DEVICE_DT_GET(DT_NODELABEL(ipc1)), event_recv, data);
123+
if (ret != WIFI_IPC_STATUS_OK) {
124+
LOG_ERR("Failed to bind IPC service: %d", ret);
125+
return -1;
126+
}
127+
128+
return 0;
129+
}

0 commit comments

Comments
 (0)