1 /**
2  * @file
3  * @brief Network Processor Initialization for SiWx91x.
4  *
5  * This file contains the initialization routine for the (ThreadArch) network processor
6  * on the SiWx91x platform. The component is responsible for setting up the necessary
7  * hardware and software components to enable network communication.
8  *
9  * Copyright (c) 2024 Silicon Laboratories Inc.
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #include <zephyr/kernel.h>
14 
15 #include "sl_wifi.h"
16 #include "sl_wifi_callback_framework.h"
17 #ifdef CONFIG_BT_SILABS_SIWX91X
18 #include "rsi_ble_common_config.h"
19 #endif
20 
siwg917_nwp_init(void)21 static int siwg917_nwp_init(void)
22 {
23 	sl_wifi_device_configuration_t network_config = {
24 		.boot_option = LOAD_NWP_FW,
25 		.band = SL_SI91X_WIFI_BAND_2_4GHZ,
26 		.region_code = DEFAULT_REGION,
27 		.boot_config = {
28 			.oper_mode = SL_SI91X_CLIENT_MODE,
29 			.tcp_ip_feature_bit_map = SL_SI91X_TCP_IP_FEAT_EXTENSION_VALID,
30 			.ext_tcp_ip_feature_bit_map = SL_SI91X_CONFIG_FEAT_EXTENSION_VALID,
31 			.config_feature_bit_map = SL_SI91X_ENABLE_ENHANCED_MAX_PSP,
32 			.custom_feature_bit_map = SL_SI91X_CUSTOM_FEAT_EXTENSION_VALID,
33 			.ext_custom_feature_bit_map =
34 				MEMORY_CONFIG |
35 				SL_SI91X_EXT_FEAT_XTAL_CLK |
36 				SL_SI91X_EXT_FEAT_FRONT_END_SWITCH_PINS_ULP_GPIO_4_5_0,
37 		}
38 	};
39 	sl_si91x_boot_configuration_t *cfg = &network_config.boot_config;
40 
41 	if (IS_ENABLED(CONFIG_WIFI_SILABS_SIWX91X) && IS_ENABLED(CONFIG_BT_SILABS_SIWX91X)) {
42 		cfg->coex_mode = SL_SI91X_WLAN_BLE_MODE;
43 	} else if (IS_ENABLED(CONFIG_WIFI_SILABS_SIWX91X)) {
44 		cfg->coex_mode = SL_SI91X_WLAN_ONLY_MODE;
45 	} else if (IS_ENABLED(CONFIG_BT_SILABS_SIWX91X)) {
46 		cfg->coex_mode = SL_SI91X_BLE_MODE;
47 	} else {
48 		/*
49 		 * Even if neither WiFi or BLE is used we have to specify a Coex mode
50 		 */
51 		cfg->coex_mode = SL_SI91X_BLE_MODE;
52 	}
53 
54 #ifdef CONFIG_WIFI_SILABS_SIWX91X
55 	cfg->feature_bit_map |= SL_SI91X_FEAT_SECURITY_OPEN | SL_SI91X_FEAT_WPS_DISABLE,
56 	cfg->ext_custom_feature_bit_map |= SL_SI91X_EXT_FEAT_IEEE_80211W;
57 	if (IS_ENABLED(CONFIG_WIFI_SILABS_SIWX91X_NET_STACK_OFFLOAD)) {
58 		cfg->ext_tcp_ip_feature_bit_map |= SL_SI91X_EXT_TCP_IP_WINDOW_SCALING;
59 		cfg->ext_tcp_ip_feature_bit_map |= SL_SI91X_EXT_TCP_IP_TOTAL_SELECTS(10);
60 		cfg->tcp_ip_feature_bit_map |= SL_SI91X_TCP_IP_FEAT_ICMP;
61 		if (IS_ENABLED(CONFIG_NET_IPV6)) {
62 			cfg->tcp_ip_feature_bit_map |= SL_SI91X_TCP_IP_FEAT_DHCPV6_CLIENT;
63 			cfg->tcp_ip_feature_bit_map |= SL_SI91X_TCP_IP_FEAT_IPV6;
64 		}
65 		if (IS_ENABLED(CONFIG_NET_IPV4)) {
66 			cfg->tcp_ip_feature_bit_map |= SL_SI91X_TCP_IP_FEAT_DHCPV4_CLIENT;
67 		}
68 	} else {
69 		cfg->tcp_ip_feature_bit_map |= SL_SI91X_TCP_IP_FEAT_BYPASS;
70 	}
71 #endif
72 
73 #ifdef CONFIG_BT_SILABS_SIWX91X
74 	cfg->ext_custom_feature_bit_map |= SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE;
75 	cfg->bt_feature_bit_map |= SL_SI91X_BT_RF_TYPE | SL_SI91X_ENABLE_BLE_PROTOCOL;
76 	cfg->ble_feature_bit_map |= SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) |
77 				    SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) |
78 				    SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) |
79 				    SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC) |
80 				    SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) |
81 				    SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) |
82 				    SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE |
83 				    SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENSION_VALID;
84 	cfg->ble_ext_feature_bit_map |= SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) |
85 					SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES) |
86 					SL_SI91X_BLE_ENABLE_ADV_EXTN |
87 					SL_SI91X_BLE_AE_MAX_ADV_SETS(RSI_BLE_AE_MAX_ADV_SETS);
88 #endif
89 
90 	/* TODO: If sl_net_*_profile() functions will be needed for WiFi then call
91 	 * sl_net_set_profile() here. Currently these are unused.
92 	 */
93 	return sl_wifi_init(&network_config, NULL, sl_wifi_default_event_handler);
94 }
95 SYS_INIT(siwg917_nwp_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
96 
97 /* IRQn 74 is used for communication with co-processor */
98 Z_ISR_DECLARE(74, 0, IRQ074_Handler, 0);
99 
100 /* Co-processor will use value stored in IVT to store its stack.
101  *
102  * FIXME: We can't use Z_ISR_DECLARE() to declare this entry
103  * FIXME: Allow to configure size of buffer
104  */
105 static uint8_t __aligned(8) siwg917_nwp_stack[10 * 1024];
106 static Z_DECL_ALIGN(struct _isr_list) Z_GENERIC_SECTION(.intList)
107 	__used __isr_siwg917_coprocessor_stack_irq = {
108 		.irq = 30,
109 		.flags = ISR_FLAG_DIRECT,
110 		.func = &siwg917_nwp_stack[sizeof(siwg917_nwp_stack) - 1],
111 	};
112