Skip to content

Commit da3932c

Browse files
jerome-pouillerjhedberg
authored andcommitted
drivers: wifi: siwx917: Make offloading optional
This new mode allows a better compatibility with Zephyr features. Support for offloading is still supported since it can provide better performances in some cases (power and memory consumption). Signed-off-by: Jérôme Pouiller <[email protected]>
1 parent c5e7299 commit da3932c

File tree

6 files changed

+151
-3
lines changed

6 files changed

+151
-3
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (c) 2024 Silicon Laboratories Inc.
33

4-
zephyr_library_sources_ifdef(CONFIG_WIFI_SIWX917 siwx917_wifi.c siwx917_wifi_socket.c)
4+
if(CONFIG_WIFI_SIWX917)
5+
6+
zephyr_library_sources(siwx917_wifi.c)
7+
zephyr_library_sources_ifdef(CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD siwx917_wifi_socket.c)
8+
9+
endif()

drivers/wifi/siwx917/Kconfig.siwx917

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,31 @@ config WIFI_SIWX917
77
depends on DT_HAS_SILABS_SIWX917_WIFI_ENABLED
88
select WISECONNECT_NETWORK_STACK
99
select EVENTS
10-
select WIFI_OFFLOAD
1110
select NET_L2_WIFI_MGMT
1211
help
1312
Enable WiFi driver for the Silabs SiWx917 SoC series.
1413

1514
if WIFI_SIWX917
1615

16+
choice
17+
prompt "Network stack"
18+
default WIFI_SIWX917_NET_STACK_NATIVE
19+
help
20+
Choose "Native" stack if you want a better compatibility with Zephyr
21+
features. "Offloaded" stack may provide better resource (power and
22+
memory) consumption.
23+
24+
config WIFI_SIWX917_NET_STACK_NATIVE
25+
bool "Native"
26+
select WIFI_USE_NATIVE_NETWORKING
27+
select NET_L2_ETHERNET
28+
29+
config WIFI_SIWX917_NET_STACK_OFFLOAD
30+
bool "Offloaded"
31+
select WIFI_OFFLOAD
32+
33+
endchoice
34+
1735
config NET_TCP_WORKQ_STACK_SIZE
1836
default 2048
1937

drivers/wifi/siwx917/siwx917_wifi.c

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "siwx917_wifi.h"
1111
#include "siwx917_wifi_socket.h"
1212

13+
#include "sl_rsi_utility.h"
1314
#include "sl_net_constants.h"
1415
#include "sl_wifi_types.h"
1516
#include "sl_wifi_callback_framework.h"
@@ -18,6 +19,8 @@
1819

1920
LOG_MODULE_REGISTER(siwx917_wifi);
2021

22+
NET_BUF_POOL_FIXED_DEFINE(siwx917_tx_pool, 1, NET_ETH_MTU, 0, NULL);
23+
2124
static unsigned int siwx917_on_join(sl_wifi_event_t event,
2225
char *result, uint32_t result_size, void *arg)
2326
{
@@ -32,6 +35,9 @@ static unsigned int siwx917_on_join(sl_wifi_event_t event,
3235

3336
wifi_mgmt_raise_connect_result_event(sidev->iface, WIFI_STATUS_CONN_SUCCESS);
3437
sidev->state = WIFI_STATE_COMPLETED;
38+
#ifndef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
39+
net_eth_carrier_on(sidev->iface);
40+
#endif
3541

3642
siwx917_on_join_ipv4(sidev);
3743
siwx917_on_join_ipv6(sidev);
@@ -124,6 +130,9 @@ static int siwx917_disconnect(const struct device *dev)
124130
if (ret) {
125131
return -EIO;
126132
}
133+
#ifndef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
134+
net_eth_carrier_off(sidev->iface);
135+
#endif
127136
sidev->state = WIFI_STATE_INACTIVE;
128137
return 0;
129138
}
@@ -220,6 +229,83 @@ static int siwx917_status(const struct device *dev, struct wifi_iface_status *st
220229
return 0;
221230
}
222231

232+
#ifndef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
233+
234+
static int siwx917_send(const struct device *dev, struct net_pkt *pkt)
235+
{
236+
size_t pkt_len = net_pkt_get_len(pkt);
237+
struct net_buf *buf = NULL;
238+
int ret;
239+
240+
if (net_pkt_get_len(pkt) > NET_ETH_MTU) {
241+
LOG_ERR("unexpected buffer size");
242+
return -ENOBUFS;
243+
}
244+
buf = net_buf_alloc(&siwx917_tx_pool, K_FOREVER);
245+
if (!buf) {
246+
return -ENOBUFS;
247+
}
248+
if (net_pkt_read(pkt, buf->data, pkt_len)) {
249+
net_buf_unref(buf);
250+
return -ENOBUFS;
251+
}
252+
net_buf_add(buf, pkt_len);
253+
254+
ret = sl_wifi_send_raw_data_frame(SL_WIFI_CLIENT_INTERFACE, buf->data, pkt_len);
255+
if (ret) {
256+
return -EIO;
257+
}
258+
259+
net_pkt_unref(pkt);
260+
net_buf_unref(buf);
261+
262+
return 0;
263+
}
264+
265+
/* Receive callback. Keep the name as it is declared weak in WiseConnect */
266+
sl_status_t sl_si91x_host_process_data_frame(sl_wifi_interface_t interface,
267+
sl_wifi_buffer_t *buffer)
268+
{
269+
sl_si91x_packet_t *si_pkt = sl_si91x_host_get_buffer_data(buffer, 0, NULL);
270+
struct net_if *iface = net_if_get_default();
271+
struct net_pkt *pkt;
272+
int ret;
273+
274+
pkt = net_pkt_rx_alloc_with_buffer(iface, buffer->length, AF_UNSPEC, 0, K_NO_WAIT);
275+
if (!pkt) {
276+
LOG_ERR("net_pkt_rx_alloc_with_buffer() failed");
277+
return SL_STATUS_FAIL;
278+
}
279+
ret = net_pkt_write(pkt, si_pkt->data, si_pkt->length);
280+
if (ret < 0) {
281+
LOG_ERR("net_pkt_write(): %d", ret);
282+
goto unref;
283+
}
284+
ret = net_recv_data(iface, pkt);
285+
if (ret < 0) {
286+
LOG_ERR("net_recv_data((): %d", ret);
287+
goto unref;
288+
}
289+
return 0;
290+
291+
unref:
292+
net_pkt_unref(pkt);
293+
return SL_STATUS_FAIL;
294+
}
295+
296+
#endif
297+
298+
static void siwx917_ethernet_init(struct net_if *iface)
299+
{
300+
#ifndef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
301+
struct ethernet_context *eth_ctx;
302+
303+
eth_ctx = net_if_l2_data(iface);
304+
eth_ctx->eth_if_type = L2_ETH_IF_TYPE_WIFI;
305+
ethernet_init(iface);
306+
#endif
307+
}
308+
223309
static void siwx917_iface_init(struct net_if *iface)
224310
{
225311
struct siwx917_dev *sidev = iface->if_dev->dev->data;
@@ -228,7 +314,6 @@ static void siwx917_iface_init(struct net_if *iface)
228314
sidev->state = WIFI_STATE_INTERFACE_DISABLED;
229315
sidev->iface = iface;
230316

231-
siwx917_sock_init(iface);
232317
sl_wifi_set_scan_callback(siwx917_on_scan, sidev);
233318
sl_wifi_set_join_callback(siwx917_on_join, sidev);
234319

@@ -239,6 +324,8 @@ static void siwx917_iface_init(struct net_if *iface)
239324
}
240325
net_if_set_link_addr(iface, sidev->macaddr.octet, sizeof(sidev->macaddr.octet),
241326
NET_LINK_ETHERNET);
327+
siwx917_sock_init(iface);
328+
siwx917_ethernet_init(iface);
242329

243330
sidev->state = WIFI_STATE_INACTIVE;
244331
}
@@ -257,10 +344,19 @@ static const struct wifi_mgmt_ops siwx917_mgmt = {
257344

258345
static const struct net_wifi_mgmt_offload siwx917_api = {
259346
.wifi_iface.iface_api.init = siwx917_iface_init,
347+
#ifdef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
260348
.wifi_iface.get_type = siwx917_get_type,
349+
#else
350+
.wifi_iface.send = siwx917_send,
351+
#endif
261352
.wifi_mgmt_api = &siwx917_mgmt,
262353
};
263354

264355
static struct siwx917_dev siwx917_dev;
356+
#ifdef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
265357
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, siwx917_dev_init, NULL, &siwx917_dev, NULL,
266358
CONFIG_WIFI_INIT_PRIORITY, &siwx917_api, NET_ETH_MTU);
359+
#else
360+
ETH_NET_DEVICE_DT_INST_DEFINE(0, siwx917_dev_init, NULL, &siwx917_dev, NULL,
361+
CONFIG_WIFI_INIT_PRIORITY, &siwx917_api, NET_ETH_MTU);
362+
#endif

drivers/wifi/siwx917/siwx917_wifi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ struct siwx917_dev {
2020
enum wifi_iface_state state;
2121
scan_result_cb_t scan_res_cb;
2222

23+
#ifdef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
2324
struct k_event fds_recv_event;
2425
sl_si91x_fd_set fds_watch;
2526
struct {
2627
net_context_recv_cb_t cb;
2728
void *user_data;
2829
struct net_context *context;
2930
} fds_cb[NUMBER_OF_BSD_SOCKETS];
31+
#endif
3032
};
3133

3234
#endif

drivers/wifi/siwx917/siwx917_wifi_socket.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,36 @@
88

99
#include <zephyr/net/net_if.h>
1010
#include <zephyr/net/offloaded_netdev.h>
11+
#include <assert.h>
1112

1213
struct siwx917_dev;
1314

15+
#ifdef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
16+
1417
enum offloaded_net_if_types siwx917_get_type(void);
1518
void siwx917_on_join_ipv4(struct siwx917_dev *sidev);
1619
void siwx917_on_join_ipv6(struct siwx917_dev *sidev);
20+
void siwx917_sock_init(struct net_if *iface);
21+
22+
#else /* CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD */
23+
24+
enum offloaded_net_if_types siwx917_get_type(void)
25+
{
26+
assert(0);
27+
}
28+
29+
void siwx917_on_join_ipv4(struct siwx917_dev *sidev)
30+
{
31+
}
32+
33+
void siwx917_on_join_ipv6(struct siwx917_dev *sidev)
34+
{
35+
}
36+
1737
void siwx917_sock_init(struct net_if *iface)
38+
{
39+
}
40+
41+
#endif /* CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD */
1842

1943
#endif

soc/silabs/silabs_siwx917/siwg917/nwp_init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static int silabs_siwx917_nwp_init(void)
5454
cfg->tcp_ip_feature_bit_map |=
5555
#ifdef CONFIG_NET_IPV6
5656
SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT | SL_SI91X_TCP_IP_FEAT_IPV6 |
57+
#endif
58+
#ifndef CONFIG_WIFI_SIWX917_NET_STACK_OFFLOAD
59+
SL_SI91X_TCP_IP_FEAT_BYPASS |
5760
#endif
5861
SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT | SL_SI91X_TCP_IP_FEAT_DNS_CLIENT |
5962
SL_SI91X_TCP_IP_FEAT_SSL | SL_SI91X_TCP_IP_FEAT_MDNSD | SL_SI91X_TCP_IP_FEAT_ICMP;

0 commit comments

Comments
 (0)