1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #if !defined(HDD_CONFIG_H__)
21 #define HDD_CONFIG_H__
22 
23 /**
24  * DOC: wlan_hdd_config.h
25  *
26  * WLAN Adapter Configuration functions
27  */
28 
29 /* $HEADER$ */
30 
31 /* Include files */
32 #include <wlan_hdd_includes.h>
33 #include <wlan_hdd_wmm.h>
34 #include <qdf_types.h>
35 #include <csr_api.h>
36 #include <sap_api.h>
37 #include <sir_mac_prot_def.h>
38 #include "osapi_linux.h"
39 #include <wmi_unified.h>
40 #include "wlan_pmo_hw_filter_public_struct.h"
41 #include "wlan_action_oui_public_struct.h"
42 #include "hdd_config.h"
43 
44 struct hdd_context;
45 
46 #define CFG_DP_RPS_RX_QUEUE_CPU_MAP_LIST_LEN 30
47 
48 #define FW_MODULE_LOG_LEVEL_STRING_LENGTH  (512)
49 #define TX_SCHED_WRR_PARAMS_NUM            (5)
50 
51 /* Defines for all of the things we read from the configuration (registry). */
52 
53 #ifdef CONFIG_DP_TRACE
54 /* Max length of gDptraceConfig string. e.g.- "1, 6, 1, 62" */
55 #define DP_TRACE_CONFIG_STRING_LENGTH		(20)
56 
57 /* At max 4 DP Trace config parameters are allowed. Refer - gDptraceConfig */
58 #define DP_TRACE_CONFIG_NUM_PARAMS		(4)
59 
60 /*
61  * Default value of live mode in case it cannot be determined from cfg string
62  * gDptraceConfig
63  */
64 #define DP_TRACE_CONFIG_DEFAULT_LIVE_MODE	(1)
65 
66 /*
67  * Default value of thresh (packets/second) beyond which DP Trace is disabled.
68  * Use this default in case the value cannot be determined from cfg string
69  * gDptraceConfig
70  */
71 #define DP_TRACE_CONFIG_DEFAULT_THRESH		(6)
72 
73 /*
74  * Number of intervals of BW timer to wait before enabling/disabling DP Trace.
75  * Since throughput threshold to disable live logging for DP Trace is very low,
76  * we calculate throughput based on # packets received in a second.
77  * For example assuming bandwidth timer interval is 100ms, and if more than 6
78  * prints are received in 10 * 100 ms interval, we want to disable DP Trace
79  * live logging. DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT is the default
80  * value, to be used in case the real value cannot be derived from
81  * bw timer interval
82  */
83 #define DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT (10)
84 
85 /* Default proto bitmap in case its missing in gDptraceConfig string */
86 #define DP_TRACE_CONFIG_DEFAULT_BITMAP \
87 			(QDF_NBUF_PKT_TRAC_TYPE_EAPOL |\
88 			QDF_NBUF_PKT_TRAC_TYPE_DHCP |\
89 			QDF_NBUF_PKT_TRAC_TYPE_MGMT_ACTION |\
90 			QDF_NBUF_PKT_TRAC_TYPE_ARP |\
91 			QDF_NBUF_PKT_TRAC_TYPE_ICMP |\
92 			QDF_NBUF_PKT_TRAC_TYPE_ICMPv6)\
93 
94 /* Default verbosity, in case its missing in gDptraceConfig string*/
95 #define DP_TRACE_CONFIG_DEFAULT_VERBOSTY QDF_DP_TRACE_VERBOSITY_LOW
96 
97 #endif
98 
99 /*
100  * Type declarations
101  */
102 
103 struct hdd_config {
104 	/* Config parameters */
105 	enum hdd_dot11_mode dot11Mode;
106 
107 #ifdef FEATURE_WLAN_DYNAMIC_CVM
108 	/* Bitmap for operating voltage corner mode */
109 	uint32_t vc_mode_cfg_bitmap;
110 #endif
111 #ifdef ENABLE_MTRACE_LOG
112 	bool enable_mtrace;
113 #endif
114 	bool advertise_concurrent_operation;
115 #ifdef DHCP_SERVER_OFFLOAD
116 	struct dhcp_server dhcp_server_ip;
117 #endif /* DHCP_SERVER_OFFLOAD */
118 	bool apf_enabled;
119 	uint16_t sap_tx_leakage_threshold;
120 	bool sap_internal_restart;
121 	bool is_11k_offload_supported;
122 	bool is_unit_test_framework_enabled;
123 	bool disable_channel;
124 
125 	/* HDD converged ini items are listed below this*/
126 	bool bug_on_reinit_failure;
127 	bool is_ramdump_enabled;
128 	uint32_t iface_change_wait_time;
129 	uint8_t multicast_host_fw_msgs;
130 	enum hdd_wext_control private_wext_control;
131 	bool enablefwprint;
132 	uint8_t enable_fw_log;
133 
134 #ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
135 	/* WLAN Logging */
136 	bool wlan_logging_enable;
137 	uint32_t wlan_console_log_levels;
138 	uint8_t host_log_custom_nl_proto;
139 #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */
140 
141 #ifdef FEATURE_WLAN_AUTO_SHUTDOWN
142 	uint32_t wlan_auto_shutdown;
143 #endif
144 
145 #ifndef REMOVE_PKT_LOG
146 	bool enable_packet_log;
147 #endif
148 
149 #ifdef WLAN_FEATURE_MSCS
150 	uint32_t mscs_pkt_threshold;
151 	uint32_t mscs_voice_interval;
152 #endif /* WLAN_FEATURE_MSCS */
153 
154 #ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
155 	uint32_t tx_flow_low_watermark;
156 	uint32_t tx_flow_hi_watermark_offset;
157 	uint32_t tx_flow_max_queue_depth;
158 	uint32_t tx_lbw_flow_low_watermark;
159 	uint32_t tx_lbw_flow_hi_watermark_offset;
160 	uint32_t tx_lbw_flow_max_queue_depth;
161 	uint32_t tx_hbw_flow_low_watermark;
162 	uint32_t tx_hbw_flow_hi_watermark_offset;
163 	uint32_t tx_hbw_flow_max_queue_depth;
164 #endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
165 	uint32_t napi_cpu_affinity_mask;
166 	uint32_t operating_chan_freq;
167 	uint8_t num_vdevs;
168 	uint8_t enable_concurrent_sta[CFG_CONCURRENT_IFACE_MAX_LEN];
169 	uint8_t dbs_scan_selection[CFG_DBS_SCAN_PARAM_LENGTH];
170 #ifdef FEATURE_RUNTIME_PM
171 	uint8_t runtime_pm;
172 #endif
173 #ifdef WLAN_FEATURE_WMI_SEND_RECV_QMI
174 	bool is_qmi_stats_enabled;
175 #endif
176 	uint8_t inform_bss_rssi_raw;
177 
178 	bool mac_provision;
179 	uint32_t provisioned_intf_pool;
180 	uint32_t derived_intf_pool;
181 	uint32_t cfg_wmi_credit_cnt;
182 	uint32_t enable_sar_conversion;
183 #ifdef WLAN_FEATURE_TSF_PLUS
184 	uint8_t tsf_ptp_options;
185 #endif /* WLAN_FEATURE_TSF_PLUS */
186 
187 #ifdef SAR_SAFETY_FEATURE
188 	uint32_t sar_safety_timeout;
189 	uint32_t sar_safety_unsolicited_timeout;
190 	uint32_t sar_safety_req_resp_timeout;
191 	uint32_t sar_safety_req_resp_retry;
192 	uint32_t sar_safety_index;
193 	uint32_t sar_safety_sleep_index;
194 	uint8_t enable_sar_safety;
195 	bool config_sar_safety_sleep_index;
196 #endif
197 	uint8_t nb_commands_interval;
198 
199 #ifdef FEATURE_CLUB_LL_STATS_AND_GET_STATION
200 	uint32_t sta_stats_cache_expiry_time;
201 #endif
202 	bool read_mac_addr_from_mac_file;
203 #ifdef FEATURE_SET
204 	bool get_wifi_features;
205 #endif
206 #ifdef FEATURE_RUNTIME_PM
207 	uint16_t cpu_cxpc_threshold;
208 #endif
209 	bool exclude_selftx_from_cca_busy;
210 #ifdef WLAN_FEATURE_11BE_MLO
211 	/* ml link state cache expiry time*/
212 	qdf_time_t link_state_cache_expiry_time;
213 #endif
214 };
215 
216 /**
217  * hdd_to_csr_wmm_mode() - Utility function to convert HDD to CSR WMM mode
218  *
219  * @mode: hdd WMM user mode
220  *
221  * Return: CSR WMM mode
222  */
223 enum wmm_user_mode hdd_to_csr_wmm_mode(uint8_t mode);
224 
225 QDF_STATUS hdd_update_mac_config(struct hdd_context *hdd_ctx);
226 QDF_STATUS hdd_set_sme_config(struct hdd_context *hdd_ctx);
227 QDF_STATUS hdd_set_policy_mgr_user_cfg(struct hdd_context *hdd_ctx);
228 QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx);
229 bool hdd_update_config_cfg(struct hdd_context *hdd_ctx);
230 void hdd_cfg_get_global_config(struct hdd_context *hdd_ctx, char *buf,
231 			       int buflen);
232 
233 eCsrPhyMode hdd_cfg_xlate_to_csr_phy_mode(enum hdd_dot11_mode dot11Mode);
234 
235 QDF_STATUS hdd_set_idle_ps_config(struct hdd_context *hdd_ctx, bool val);
236 void hdd_get_pmkid_modes(struct hdd_context *hdd_ctx,
237 			 struct pmkid_mode_bits *pmkid_modes);
238 
239 int hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg);
240 
241 /**
242  * hdd_string_to_u8_array() - used to convert decimal string into u8 array
243  * @str: Decimal string
244  * @array: Array where converted value is stored
245  * @len: Length of the populated array
246  * @array_max_len: Maximum length of the array
247  *
248  * This API is called to convert decimal string (each byte separated by
249  * a comma) into an u8 array
250  *
251  * Return: QDF_STATUS
252  */
253 QDF_STATUS hdd_string_to_u8_array(char *str, uint8_t *array,
254 				  uint8_t *len, uint16_t array_max_len);
255 
256 QDF_STATUS hdd_hex_string_to_u16_array(char *str, uint16_t *int_array,
257 				uint8_t *len, uint8_t int_array_max_len);
258 
259 void hdd_cfg_print_global_config(struct hdd_context *hdd_ctx);
260 
261 /**
262  * hdd_update_nss() - Update the number of spatial streams supported.
263  * @link_info: Link info pointer in HDD adapter
264  * @tx_nss: the number of Tx spatial streams to be updated
265  * @rx_nss: the number of Rx spatial streams to be updated
266  *
267  * This function is used to modify the number of spatial streams
268  * supported when not in connected state.
269  *
270  * Return: QDF_STATUS_SUCCESS if nss is correctly updated,
271  *              otherwise QDF_STATUS_E_FAILURE would be returned
272  */
273 QDF_STATUS hdd_update_nss(struct wlan_hdd_link_info *link_info,
274 			  uint8_t tx_nss, uint8_t rx_nss);
275 
276 /**
277  * hdd_get_nss() - Get the number of spatial streams supported by the adapter
278  *
279  * @adapter: the pointer to adapter
280  * @nss: the number of spatial streams supported by the adapter
281  *
282  * This function is used to get the number of spatial streams supported by
283  * the adapter.
284  *
285  * Return: QDF_STATUS
286  */
287 QDF_STATUS hdd_get_nss(struct hdd_adapter *adapter, uint8_t *nss);
288 
289 /**
290  * hdd_get_num_tx_chains() - Get the number of tx chains supported by the
291  * adapter
292  * @link_info: Link info pointer in HDD adapter
293  * @tx_chains: the number of Tx chains supported by the adapter
294  *
295  * This function is used to get the number of Tx chains supported by
296  * the adapter.
297  *
298  * Return: QDF_STATUS
299  */
300 QDF_STATUS hdd_get_num_tx_chains(struct wlan_hdd_link_info *link_info,
301 				 uint8_t *tx_chains);
302 
303 /**
304  * hdd_get_tx_nss() - Get the number of spatial streams supported by the adapter
305  * @link_info: Link info pointer in HDD adapter
306  * @tx_nss: the number Tx of spatial streams supported by the adapter
307  *
308  * This function is used to get the number of Tx spatial streams supported by
309  * the adapter.
310  *
311  * Return: QDF_STATUS
312  */
313 QDF_STATUS hdd_get_tx_nss(struct wlan_hdd_link_info *link_info,
314 			  uint8_t *tx_nss);
315 
316 /**
317  * hdd_get_num_rx_chains() - Get the number of chains supported by the adapter
318  * @link_info: Link info pointer in HDD adapter
319  * @rx_chains: the number of Rx chains supported by the adapter
320  *
321  * This function is used to get the number of Rx chains supported by
322  * the adapter.
323  *
324  * Return: QDF_STATUS
325  */
326 QDF_STATUS hdd_get_num_rx_chains(struct wlan_hdd_link_info *link_info,
327 				 uint8_t *rx_chains);
328 
329 /**
330  * hdd_get_rx_nss() - Get the number of spatial streams supported by the adapter
331  * @link_info: Link info pointer in HDD adapter
332  * @rx_nss: the number Rx of spatial streams supported by the adapter
333  *
334  * This function is used to get the number of Rx spatial streams supported by
335  * the adapter.
336  *
337  * Return: QDF_STATUS
338  */
339 QDF_STATUS hdd_get_rx_nss(struct wlan_hdd_link_info *link_info,
340 			  uint8_t *rx_nss);
341 
342 
343 /**
344  * hdd_dfs_indicate_radar() - Block tx as radar found on the channel
345  * @hdd_ctx: HDD context pointer
346  *
347  * This function is invoked in atomic context when a radar
348  * is found on the SAP current operating channel and Data Tx
349  * from netif has to be stopped to honor the DFS regulations.
350  * Actions: Stop the netif Tx queues,Indicate Radar present
351  * in HDD context for future usage.
352  *
353  * Return: true on success, else false
354  */
355 bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx);
356 
357 /**
358  * hdd_restore_all_ps() - Restore all the powersave configuration overwritten
359  * by hdd_override_all_ps.
360  * @hdd_ctx: Pointer to HDD context.
361  *
362  * Return: None
363  */
364 void hdd_restore_all_ps(struct hdd_context *hdd_ctx);
365 
366 /**
367  * hdd_override_all_ps() - overrides to disables all the powersave features.
368  * @hdd_ctx: Pointer to HDD context.
369  * Overrides below powersave ini configurations.
370  * gEnableImps=0
371  * gEnableBmps=0
372  * gRuntimePM=0
373  * gWlanAutoShutdown = 0
374  * gEnableWoW=0
375  *
376  * Return: None
377  */
378 void hdd_override_all_ps(struct hdd_context *hdd_ctx);
379 
380 /**
381  * hdd_vendor_mode_to_phymode() - Get eCsrPhyMode according to vendor phy mode
382  * @vendor_phy_mode: vendor phy mode
383  * @csr_phy_mode: phy mode of eCsrPhyMode
384  *
385  * Return: 0 on success, negative errno value on error
386  */
387 int hdd_vendor_mode_to_phymode(enum qca_wlan_vendor_phy_mode vendor_phy_mode,
388 			       eCsrPhyMode *csr_phy_mode);
389 
390 /**
391  * hdd_phymode_to_vendor_mode() - Get vendor phy mode according to CSR phy mode.
392  * @csr_phy_mode: phy mode of eCsrPhyMode
393  * @vendor_phy_mode: vendor phy mode
394  *
395  * Return: 0 on success, negative error value on failure
396  */
397 int hdd_phymode_to_vendor_mode(eCsrPhyMode csr_phy_mode,
398 			       enum qca_wlan_vendor_phy_mode *vendor_phy_mode);
399 
400 /**
401  * hdd_vendor_mode_to_band() - Get band_info according to vendor phy mode
402  * @vendor_phy_mode: vendor phy mode
403  * @supported_band: supported band bitmap
404  * @is_6ghz_supported: whether 6ghz is supported
405  *
406  * Return: 0 on success, negative errno value on error
407  */
408 int hdd_vendor_mode_to_band(enum qca_wlan_vendor_phy_mode vendor_phy_mode,
409 			    uint8_t *supported_band, bool is_6ghz_supported);
410 
411 /**
412  * hdd_vendor_mode_to_bonding_mode() - Get channel bonding mode according to
413  * vendor phy mode
414  * @vendor_phy_mode: vendor phy mode
415  * @bonding_mode: channel bonding mode
416  *
417  * Return: 0 on success, negative errno value on error
418  */
419 int
420 hdd_vendor_mode_to_bonding_mode(enum qca_wlan_vendor_phy_mode vendor_phy_mode,
421 				uint32_t *bonding_mode);
422 
423 /**
424  * hdd_phymode_to_dot11_mode() - Mapping phymode to dot11mode
425  * @phymode: phy mode
426  * @dot11_mode: dot11 mode
427  *
428  * Return: 0 on success, negative errno value on error
429  */
430 int hdd_phymode_to_dot11_mode(eCsrPhyMode phymode,
431 			      enum hdd_dot11_mode *dot11_mode);
432 
433 /**
434  * hdd_update_phymode() - update the PHY mode of the adapter
435  * @adapter: adapter being modified
436  * @phymode: new PHY mode for the adapter
437  * @supported_band: supported band bitmap for the adapter
438  * @bonding_mode: new channel bonding mode for the adapter
439  *
440  * This function is called when the adapter is set to a new PHY mode.
441  * It takes a holistic look at the desired PHY mode along with the
442  * configured capabilities of the driver and the reported capabilities
443  * of the hardware in order to correctly configure all PHY-related
444  * parameters.
445  *
446  * Return: 0 on success, negative errno value on error
447  */
448 int hdd_update_phymode(struct hdd_adapter *adapter, eCsrPhyMode phymode,
449 		       uint8_t supported_band, uint32_t bonding_mode);
450 
451 /**
452  * hdd_get_ldpc() - Get adapter LDPC
453  * @adapter: adapter being queried
454  * @value: where to store the value
455  *
456  * Return: 0 on success, negative errno on failure
457  */
458 int hdd_get_ldpc(struct hdd_adapter *adapter, int *value);
459 
460 /**
461  * hdd_set_ldpc() - Set adapter LDPC
462  * @link_info: Link info pointer in adapter
463  * @value: new LDPC value
464  *
465  * Return: 0 on success, negative errno on failure
466  */
467 int hdd_set_ldpc(struct wlan_hdd_link_info *link_info, int value);
468 
469 /**
470  * hdd_get_tx_stbc() - Get adapter TX STBC
471  * @adapter: adapter being queried
472  * @value: where to store the value
473  *
474  * Return: 0 on success, negative errno on failure
475  */
476 int hdd_get_tx_stbc(struct hdd_adapter *adapter, int *value);
477 
478 /**
479  * hdd_set_tx_stbc() - Set adapter TX STBC
480  * @link_info: Link info pointer in HDD adapter
481  * @value: new TX STBC value
482  *
483  * Return: 0 on success, negative errno on failure
484  */
485 int hdd_set_tx_stbc(struct wlan_hdd_link_info *link_info, int value);
486 
487 /**
488  * hdd_get_rx_stbc() - Get adapter RX STBC
489  * @adapter: adapter being queried
490  * @value: where to store the value
491  *
492  * Return: 0 on success, negative errno on failure
493  */
494 int hdd_get_rx_stbc(struct hdd_adapter *adapter, int *value);
495 
496 /**
497  * hdd_set_rx_stbc() - Set adapter RX STBC
498  * @link_info: Link info pointer in HDD adapter
499  * @value: new RX STBC value
500  *
501  * Return: 0 on success, negative errno on failure
502  */
503 int hdd_set_rx_stbc(struct wlan_hdd_link_info *link_info, int value);
504 
505 /**
506  * hdd_update_channel_width() - Update adapter channel width settings
507  * @link_info: Link info in HDD adapter
508  * @chwidth: new channel width of enum eSirMacHTChannelWidth
509  * @bonding_mode: channel bonding mode of the new channel width
510  * @link_id: mlo link id
511  * @is_restore: is restore
512  *
513  * Return: 0 on success, negative errno on failure
514  */
515 int hdd_update_channel_width(struct wlan_hdd_link_info *link_info,
516 			     enum eSirMacHTChannelWidth chwidth,
517 			     uint32_t bonding_mode, uint8_t link_id,
518 			     bool is_restore);
519 #endif /* end #if !defined(HDD_CONFIG_H__) */
520