Skip to content

Commit 7da32cf

Browse files
committed
drivers: wifi: ipc service support
IPC service support Signed-off-by: Ajay Parida <[email protected]>
1 parent 36a1e64 commit 7da32cf

File tree

9 files changed

+276
-26
lines changed

9 files changed

+276
-26
lines changed

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ endchoice
148148

149149
config NRF_WIFI_LOW_POWER
150150
bool "Low power mode in nRF Wi-Fi chipsets"
151-
default y
151+
default y if !NRF71_ON_IPC
152152

153153
config NRF70_TCP_IP_CHECKSUM_OFFLOAD
154154
bool "TCP/IP checksum offload"
@@ -192,6 +192,14 @@ config NRF70_ON_SPI
192192
DT_HAS_NORDIC_NRF7000_SPI_ENABLED
193193
select SPI
194194

195+
config NRF71_ON_IPC
196+
# TODO: Do this properly from DTS
197+
# def_bool NRF71_HAS_IPC
198+
bool "Enable IPC"
199+
# select IPC_SERVICE
200+
# select IPC_SERVICE_BACKEND_ICMSG
201+
# select MBOX
202+
195203
config NRF70_2_4G_ONLY
196204
def_bool y if WIFI_NRF7001
197205

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,13 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv
591591
}
592592

593593
rpu_ctx_zep->rpu_ctx = rpu_ctx;
594-
594+
#ifndef CONFIG_NRF71_ON_IPC
595595
status = nrf_wifi_fw_load(rpu_ctx);
596596
if (status != NRF_WIFI_STATUS_SUCCESS) {
597597
LOG_ERR("%s: nrf_wifi_fw_load failed", __func__);
598598
goto err;
599599
}
600-
600+
#endif /* !CONFIG_NRF71_ON_IPC */
601601
status = nrf_wifi_fmac_ver_get(rpu_ctx,
602602
&fw_ver);
603603

drivers/wifi/nrf_wifi/src/net_if.c

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

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

modules/nrf_wifi/bus/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ if (CONFIG_NRF70_BUSLIB)
1515
inc
1616
)
1717
zephyr_library_sources(
18-
rpu_hw_if.c
1918
device.c
2019
)
2120
zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI
21+
rpu_hw_if.c
2222
qspi_if.c
2323
)
2424
zephyr_library_sources_ifdef(CONFIG_NRF70_ON_SPI
25+
rpu_hw_if.c
2526
spi_if.c
2627
)
28+
zephyr_library_sources_ifdef(CONFIG_NRF71_ON_IPC
29+
ipc_if.c
30+
)
2731
endif()

modules/nrf_wifi/bus/device.c

Lines changed: 40 additions & 15 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));
@@ -65,18 +82,26 @@ struct qspi_config *qspi_defconfig(void)
6582
#endif /*CONFIG_NRF70_ON_QSPI && (NRF_QSPI_HAS_XIP_ENC || NRF_QSPI_HAS_DMA_ENC)*/
6683

6784
return &config;
68-
}
85+
}
6986

7087
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
96+
#if defined(CONFIG_NRF70_ON_QSPI)
7897
return &qspi;
7998
#else
8099
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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
2+
/*
3+
* Copyright (c) 2024 Nordic Semiconductor ASA
4+
*
5+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
6+
*/
7+
8+
#include "ipc_if.h"
9+
//#include "qspi.h"
10+
//#include "bal_structs.h"
11+
//#include "hal_structs.h"
12+
13+
/* Define addresses to use for the free queues */
14+
#define EVENT_FREEQ_ADDR 0x2FC08000
15+
#define CMD_FREEQ_ADDR 0x2FC05000
16+
17+
#define NUM_INSTANCES 3
18+
#define NUM_ENDPOINTS 1
19+
20+
struct device *ipc_instances[NUM_INSTANCES];
21+
struct ipc_ept ept[NUM_ENDPOINTS];
22+
struct ipc_ept_cfg ept_cfg[NUM_ENDPOINTS];
23+
24+
static WIFI_IPC_T wifi_event;
25+
static WIFI_IPC_T wifi_cmd;
26+
static WIFI_IPC_T wifi_tx;
27+
28+
static int (*callback_func)(void *data);
29+
30+
static void event_recv(void *data, void *priv)
31+
{
32+
// struct nrf_wifi_bus_qspi_dev_ctx *dev_ctx = NULL;
33+
// struct nrf_wifi_bal_dev_ctx *bal_dev_ctx = NULL;
34+
// struct nrf_wifi_hal_dev_ctx *hal_dev_ctx = NULL;
35+
printf(" EVENT RECIEVED\n ");
36+
printf(" data adress is 0x%x\n",data);
37+
// dev_ctx = (struct nrf_wifi_bus_qspi_dev_ctx *) priv;
38+
// bal_dev_ctx = (struct nrf_wifi_bal_dev_ctx *) dev_ctx->bal_dev_ctx;
39+
// hal_dev_ctx = (struct nrf_wifi_hal_dev_ctx *) bal_dev_ctx->hal_dev_ctx;
40+
41+
// hal_dev_ctx->ipc_msg = data;
42+
callback_func(priv);
43+
}
44+
45+
int ipc_init() {
46+
wifi_ipc_host_event_init(&wifi_event, EVENT_FREEQ_ADDR);
47+
wifi_ipc_host_cmd_init(&wifi_cmd, CMD_FREEQ_ADDR);
48+
return 0;
49+
}
50+
51+
int ipc_deinit(void) {
52+
return 0;
53+
}
54+
55+
int ipc_recv(ipc_ctx_t ctx, const void *data, int len) {
56+
return 0;
57+
}
58+
59+
int ipc_send(ipc_ctx_t ctx, void *data, int len) {
60+
61+
int ret;
62+
63+
switch (ctx.inst) {
64+
case IPC_INSTANCE_CMD_CTRL:
65+
66+
/* IPC service on RPU may not have been established. Keep trying. */
67+
do {
68+
ret = wifi_ipc_host_cmd_send_memcpy(&wifi_cmd, data, len);
69+
} while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY);
70+
71+
/* Critical error during IPC service transfer. Should never happen. */
72+
if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) {
73+
return -1;
74+
}
75+
76+
break;
77+
case IPC_INSTANCE_CMD_TX:
78+
79+
/* IPC service on RPU may not have been established. Keep trying. */
80+
81+
do {
82+
printf(" adress of data cmd is 0x%x\n",data);
83+
ret = wifi_ipc_host_tx_send(&wifi_tx, data);
84+
} while (ret == WIFI_IPC_STATUS_BUSYQ_NOTREADY);
85+
printf("Data cmd critical error is %d\n",ret);
86+
/* Critical error during IPC service transfer. Should never happen. */
87+
if (ret == WIFI_IPC_STATUS_BUSYQ_CRITICAL_ERR) {
88+
return -1;
89+
}
90+
91+
break;
92+
case IPC_INSTANCE_RX:
93+
break;
94+
default:
95+
break;
96+
}
97+
98+
return 0;
99+
}
100+
101+
int ipc_register_rx_cb(int (*rx_handler)(void *priv), void *data) {
102+
callback_func = rx_handler;
103+
#ifdef NOTYET
104+
int ret = wifi_ipc_bind_ipc_service_tx_rx(&wifi_cmd, &wifi_event, DEVICE_DT_GET(DT_NODELABEL(ipc0)), event_recv, data);
105+
if (ret != WIFI_IPC_STATUS_OK) {
106+
return -1;
107+
}
108+
109+
ret = wifi_ipc_bind_ipc_service(&wifi_tx, DEVICE_DT_GET(DT_NODELABEL(ipc1)), event_recv, data);
110+
return (ret == WIFI_IPC_STATUS_OK ? 0 : -1);
111+
#endif
112+
}

modules/nrf_wifi/bus/ipc_if.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef __IPC_IF_H__
8+
#define __IPC_IF_H__
9+
10+
#include <zephyr/kernel.h>
11+
#include "wifi_ipc_service.h"
12+
13+
typedef enum {
14+
IPC_INSTANCE_CMD_CTRL = 0,
15+
IPC_INSTANCE_CMD_TX,
16+
IPC_INSTANCE_EVT,
17+
IPC_INSTANCE_RX
18+
} ipc_instances_nrf71_t;
19+
20+
typedef enum {
21+
IPC_EPT_UMAC = 0,
22+
IPC_EPT_LMAC
23+
} ipc_epts_nrf71_t;
24+
25+
26+
typedef struct ipc_ctx {
27+
ipc_instances_nrf71_t inst;
28+
ipc_epts_nrf71_t ept;
29+
} ipc_ctx_t;
30+
31+
struct rpu_dev {
32+
int (*init)();
33+
int (*deinit)(void);
34+
int (*send)(ipc_ctx_t ctx, const void *data, int len);
35+
int (*recv)(ipc_ctx_t ctx, void *data, int len);
36+
int (*register_rx_cb)(void (*rx_handler)(void *priv), void *data);
37+
};
38+
39+
struct rpu_dev *rpu_dev(void);
40+
41+
int ipc_init();
42+
int ipc_deinit(void);
43+
int ipc_send(ipc_ctx_t ctx, void *data, int len);
44+
// Blocking Receive
45+
int ipc_recv(ipc_ctx_t ctx, const void *data, int len);
46+
// Non-blocking Receive (global, not per instance)
47+
int ipc_register_rx_cb(int (*rx_handler)(void *priv), void *data);
48+
49+
#endif /* __IPC_IF_H__ */

modules/nrf_wifi/os/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ else()
114114
)
115115
endif()
116116

117-
zephyr_library_sources(
117+
zephyr_library_sources_ifndef(CONFIG_NRF71_ON_IPC
118118
${NRF_WIFI_DIR}/os_if/src/osal.c
119119
${NRF_WIFI_DIR}/utils/src/list.c
120120
${NRF_WIFI_DIR}/utils/src/queue.c
@@ -133,6 +133,25 @@ zephyr_library_sources(
133133
${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_api_common.c
134134
)
135135

136+
zephyr_library_sources_ifdef(CONFIG_NRF71_ON_IPC
137+
${NRF_WIFI_DIR}/os_if/src/osal.c
138+
${NRF_WIFI_DIR}/utils/src/list.c
139+
${NRF_WIFI_DIR}/utils/src/queue.c
140+
${NRF_WIFI_DIR}/utils/src/util.c
141+
${NRF_WIFI_DIR}/hw_if/hal/src/hal_api.c
142+
${NRF_WIFI_DIR}/hw_if/hal/src/hal_mem.c
143+
${NRF_WIFI_DIR}/hw_if/hal/src/hal_reg.c
144+
${NRF_WIFI_DIR}/hw_if/hal/src/hpqm.c
145+
${NRF_WIFI_DIR}/hw_if/hal/src/pal.c
146+
${NRF_WIFI_DIR}/hw_if/hal/src/spsc_qm.c
147+
${NRF_WIFI_DIR}/hw_if/hal/src/wifi_ipc_service.c
148+
${NRF_WIFI_DIR}/bus_if/bal/src/bal.c
149+
${NRF_WIFI_DIR}/bus_if/bus/qspi/src/qspi.c
150+
${NRF_WIFI_DIR}/fw_if/umac_if/src/cmd.c
151+
${NRF_WIFI_DIR}/fw_if/umac_if/src/event.c
152+
${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_api_common.c
153+
)
154+
136155
if(CONFIG_NRF70_RADIO_TEST)
137156
zephyr_library_sources(
138157
${NRF_WIFI_DIR}/fw_if/umac_if/src/radio_test/fmac_api.c

0 commit comments

Comments
 (0)