162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause-Clear */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef ATH12K_REG_H
862306a36Sopenharmony_ci#define ATH12K_REG_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/kernel.h>
1162306a36Sopenharmony_ci#include <net/regulatory.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct ath12k_base;
1462306a36Sopenharmony_cistruct ath12k;
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* DFS regdomains supported by Firmware */
1762306a36Sopenharmony_cienum ath12k_dfs_region {
1862306a36Sopenharmony_ci	ATH12K_DFS_REG_UNSET,
1962306a36Sopenharmony_ci	ATH12K_DFS_REG_FCC,
2062306a36Sopenharmony_ci	ATH12K_DFS_REG_ETSI,
2162306a36Sopenharmony_ci	ATH12K_DFS_REG_MKK,
2262306a36Sopenharmony_ci	ATH12K_DFS_REG_CN,
2362306a36Sopenharmony_ci	ATH12K_DFS_REG_KR,
2462306a36Sopenharmony_ci	ATH12K_DFS_REG_MKK_N,
2562306a36Sopenharmony_ci	ATH12K_DFS_REG_UNDEF,
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cienum ath12k_reg_cc_code {
2962306a36Sopenharmony_ci	REG_SET_CC_STATUS_PASS = 0,
3062306a36Sopenharmony_ci	REG_CURRENT_ALPHA2_NOT_FOUND = 1,
3162306a36Sopenharmony_ci	REG_INIT_ALPHA2_NOT_FOUND = 2,
3262306a36Sopenharmony_ci	REG_SET_CC_CHANGE_NOT_ALLOWED = 3,
3362306a36Sopenharmony_ci	REG_SET_CC_STATUS_NO_MEMORY = 4,
3462306a36Sopenharmony_ci	REG_SET_CC_STATUS_FAIL = 5,
3562306a36Sopenharmony_ci};
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistruct ath12k_reg_rule {
3862306a36Sopenharmony_ci	u16 start_freq;
3962306a36Sopenharmony_ci	u16 end_freq;
4062306a36Sopenharmony_ci	u16 max_bw;
4162306a36Sopenharmony_ci	u8 reg_power;
4262306a36Sopenharmony_ci	u8 ant_gain;
4362306a36Sopenharmony_ci	u16 flags;
4462306a36Sopenharmony_ci	bool psd_flag;
4562306a36Sopenharmony_ci	u16 psd_eirp;
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistruct ath12k_reg_info {
4962306a36Sopenharmony_ci	enum ath12k_reg_cc_code status_code;
5062306a36Sopenharmony_ci	u8 num_phy;
5162306a36Sopenharmony_ci	u8 phy_id;
5262306a36Sopenharmony_ci	u16 reg_dmn_pair;
5362306a36Sopenharmony_ci	u16 ctry_code;
5462306a36Sopenharmony_ci	u8 alpha2[REG_ALPHA2_LEN + 1];
5562306a36Sopenharmony_ci	u32 dfs_region;
5662306a36Sopenharmony_ci	u32 phybitmap;
5762306a36Sopenharmony_ci	bool is_ext_reg_event;
5862306a36Sopenharmony_ci	u32 min_bw_2g;
5962306a36Sopenharmony_ci	u32 max_bw_2g;
6062306a36Sopenharmony_ci	u32 min_bw_5g;
6162306a36Sopenharmony_ci	u32 max_bw_5g;
6262306a36Sopenharmony_ci	u32 num_2g_reg_rules;
6362306a36Sopenharmony_ci	u32 num_5g_reg_rules;
6462306a36Sopenharmony_ci	struct ath12k_reg_rule *reg_rules_2g_ptr;
6562306a36Sopenharmony_ci	struct ath12k_reg_rule *reg_rules_5g_ptr;
6662306a36Sopenharmony_ci	enum wmi_reg_6g_client_type client_type;
6762306a36Sopenharmony_ci	bool rnr_tpe_usable;
6862306a36Sopenharmony_ci	bool unspecified_ap_usable;
6962306a36Sopenharmony_ci	/* TODO: All 6G related info can be stored only for required
7062306a36Sopenharmony_ci	 * combination instead of all types, to optimize memory usage.
7162306a36Sopenharmony_ci	 */
7262306a36Sopenharmony_ci	u8 domain_code_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
7362306a36Sopenharmony_ci	u8 domain_code_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
7462306a36Sopenharmony_ci	u32 domain_code_6g_super_id;
7562306a36Sopenharmony_ci	u32 min_bw_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
7662306a36Sopenharmony_ci	u32 max_bw_6g_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
7762306a36Sopenharmony_ci	u32 min_bw_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
7862306a36Sopenharmony_ci	u32 max_bw_6g_client[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
7962306a36Sopenharmony_ci	u32 num_6g_reg_rules_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
8062306a36Sopenharmony_ci	u32 num_6g_reg_rules_cl[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
8162306a36Sopenharmony_ci	struct ath12k_reg_rule *reg_rules_6g_ap_ptr[WMI_REG_CURRENT_MAX_AP_TYPE];
8262306a36Sopenharmony_ci	struct ath12k_reg_rule *reg_rules_6g_client_ptr
8362306a36Sopenharmony_ci		[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_civoid ath12k_reg_init(struct ath12k *ar);
8762306a36Sopenharmony_civoid ath12k_reg_free(struct ath12k_base *ab);
8862306a36Sopenharmony_civoid ath12k_regd_update_work(struct work_struct *work);
8962306a36Sopenharmony_cistruct ieee80211_regdomain *ath12k_reg_build_regd(struct ath12k_base *ab,
9062306a36Sopenharmony_ci						  struct ath12k_reg_info *reg_info,
9162306a36Sopenharmony_ci						  bool intersect);
9262306a36Sopenharmony_ciint ath12k_regd_update(struct ath12k *ar, bool init);
9362306a36Sopenharmony_ciint ath12k_reg_update_chan_list(struct ath12k *ar);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#endif
96