1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief Header containing FMAC interface specific declarations for the
9  * Zephyr OS layer of the Wi-Fi driver.
10  */
11 
12 #ifndef __ZEPHYR_FMAC_MAIN_H__
13 #define __ZEPHYR_FMAC_MAIN_H__
14 
15 #include <stdio.h>
16 
17 #include <version.h>
18 
19 #include <zephyr/kernel.h>
20 #include <zephyr/net/net_if.h>
21 #ifndef CONFIG_NRF70_RADIO_TEST
22 #include <zephyr/net/wifi_mgmt.h>
23 #include <zephyr/net/ethernet.h>
24 #ifdef CONFIG_NETWORKING
25 #include <net_if.h>
26 #endif /* CONFIG_NETWORKING */
27 #ifdef CONFIG_NRF70_STA_MODE
28 #include <drivers/driver_zephyr.h>
29 #endif /* CONFIG_NRF70_STA_MODE */
30 #endif /* !CONFIG_NRF70_RADIO_TEST */
31 
32 #include <fmac_api.h>
33 #include <host_rpu_umac_if.h>
34 
35 #define NRF70_DRIVER_VERSION "1."KERNEL_VERSION_STRING
36 
37 #ifndef CONFIG_NRF70_OFFLOADED_RAW_TX
38 #ifndef CONFIG_NRF70_RADIO_TEST
39 struct nrf_wifi_vif_ctx_zep {
40 	const struct device *zep_dev_ctx;
41 	struct net_if *zep_net_if_ctx;
42 	void *supp_drv_if_ctx;
43 	void *rpu_ctx_zep;
44 	unsigned char vif_idx;
45 	struct k_mutex vif_lock;
46 
47 	scan_result_cb_t disp_scan_cb;
48 	bool scan_in_progress;
49 	int scan_type;
50 	uint16_t max_bss_cnt;
51 	unsigned int scan_res_cnt;
52 	struct k_work_delayable scan_timeout_work;
53 
54 	struct net_eth_addr mac_addr;
55 	int if_type;
56 	char ifname[16];
57 	enum nrf_wifi_fmac_if_op_state if_op_state;
58 	bool set_if_event_received;
59 	int set_if_status;
60 #ifdef CONFIG_NET_STATISTICS_ETHERNET
61 	struct net_stats_eth eth_stats;
62 #endif /* CONFIG_NET_STATISTICS_ETHERNET */
63 #ifdef CONFIG_NRF70_STA_MODE
64 	unsigned int assoc_freq;
65 	enum nrf_wifi_fmac_if_carr_state if_carr_state;
66 	struct wpa_signal_info *signal_info;
67 	struct wpa_conn_info *conn_info;
68 	struct zep_wpa_supp_dev_callbk_fns supp_callbk_fns;
69 	unsigned char twt_flows_map;
70 	unsigned char twt_flow_in_progress_map;
71 	struct wifi_ps_config *ps_info;
72 	bool ps_config_info_evnt;
73 	bool authorized;
74 	bool cookie_resp_received;
75 #ifdef CONFIG_NRF70_DATA_TX
76 	struct k_work nrf_wifi_net_iface_work;
77 #endif /* CONFIG_NRF70_DATA_TX */
78 	unsigned long rssi_record_timestamp_us;
79 	signed short rssi;
80 #endif /* CONFIG_NRF70_STA_MODE */
81 #ifdef CONFIG_NRF70_AP_MODE
82 	int inactive_time_sec;
83 #endif /* CONFIG_NRF70_AP_MODE */
84 #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY
85 	struct k_work nrf_wifi_rpu_recovery_work;
86 #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
87 	int rts_threshold_value;
88 };
89 
90 struct nrf_wifi_vif_ctx_map {
91 	const char *ifname;
92 	struct nrf_wifi_vif_ctx_zep *vif_ctx;
93 };
94 #endif /* !CONFIG_NRF70_RADIO_TEST */
95 
96 struct nrf_wifi_ctx_zep {
97 	void *drv_priv_zep;
98 	void *rpu_ctx;
99 #ifdef CONFIG_NRF70_RADIO_TEST
100 	struct rpu_conf_params conf_params;
101 	bool rf_test_run;
102 	unsigned char rf_test;
103 #else /* CONFIG_NRF70_RADIO_TEST */
104 	struct nrf_wifi_vif_ctx_zep vif_ctx_zep[MAX_NUM_VIFS];
105 #ifdef CONFIG_NRF70_UTIL
106 	struct rpu_conf_params conf_params;
107 #endif /* CONFIG_NRF70_UTIL */
108 #endif /* CONFIG_NRF70_RADIO_TEST */
109 	unsigned char *extended_capa, *extended_capa_mask;
110 	unsigned int extended_capa_len;
111 	struct k_mutex rpu_lock;
112 #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY
113 	bool rpu_recovery_in_progress;
114 	unsigned long last_rpu_recovery_time_ms;
115 	unsigned int rpu_recovery_retries;
116 	int rpu_recovery_success;
117 	int rpu_recovery_failure;
118 #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
119 };
120 
121 struct nrf_wifi_drv_priv_zep {
122 	struct nrf_wifi_fmac_priv *fmac_priv;
123 	/* TODO: Replace with a linked list to handle unlimited RPUs */
124 	struct nrf_wifi_ctx_zep rpu_ctx_zep;
125 };
126 
127 extern struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep;
128 
129 void nrf_wifi_scan_timeout_work(struct k_work *work);
130 
131 void configure_tx_pwr_settings(struct nrf_wifi_tx_pwr_ctrl_params *tx_pwr_ctrl_params,
132 				struct nrf_wifi_tx_pwr_ceil_params *tx_pwr_ceil_params);
133 void configure_board_dep_params(struct nrf_wifi_board_params *board_params);
134 void set_tx_pwr_ceil_default(struct nrf_wifi_tx_pwr_ceil_params *pwr_ceil_params);
135 const char *nrf_wifi_get_drv_version(void);
136 enum nrf_wifi_status nrf_wifi_fmac_dev_add_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep);
137 enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv_priv_zep);
138 struct nrf_wifi_vif_ctx_zep *nrf_wifi_get_vif_ctx(struct net_if *iface);
139 #ifdef CONFIG_NRF_WIFI_RPU_RECOVERY
140 void nrf_wifi_rpu_recovery_cb(void *vif_ctx,
141 		void *event_data,
142 		unsigned int event_len);
143 #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
144 #endif /* !CONFIG_NRF70_OFFLOADED_RAW_TX */
145 #ifdef CONFIG_BUILD_ONLY_NO_BLOBS
nrf_wifi_fw_load(void * rpu_ctx)146 inline enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx)
147 {
148 	(void)rpu_ctx;
149 
150 	return NRF_WIFI_STATUS_SUCCESS;
151 }
152 #else
153 enum nrf_wifi_status nrf_wifi_fw_load(void *rpu_ctx);
154 #endif /* CONFIG_BUILD_ONLY_NO_BLOBS */
155 #endif /* __ZEPHYR_FMAC_MAIN_H__ */
156