xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/core/rtw_chplan.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef __RTW_CHPLAN_H__
16 #define __RTW_CHPLAN_H__
17 
18 #define RTW_CHPLAN_IOCTL_NULL			0xFFFE /* special value by ioctl: null(empty) chplan */
19 #define RTW_CHPLAN_IOCTL_UNSPECIFIED	0xFFFF /* special value by ioctl: no change (keep original) */
20 
21 #define RTW_CHPLAN_NULL			0x1A
22 #define RTW_CHPLAN_WORLDWIDE	0x7F
23 #define RTW_CHPLAN_UNSPECIFIED	0xFF
24 #define RTW_CHPLAN_6G_NULL			0x00
25 #define RTW_CHPLAN_6G_WORLDWIDE		0x7F
26 #define RTW_CHPLAN_6G_UNSPECIFIED	0xFF
27 
28 u8 rtw_chplan_get_default_regd_2g(u8 id);
29 u8 rtw_chplan_get_default_regd_5g(u8 id);
30 bool rtw_is_channel_plan_valid(u8 id);
31 bool rtw_regsty_is_excl_chs(struct registry_priv *regsty, u8 ch);
32 
33 #if CONFIG_IEEE80211_BAND_6GHZ
34 u8 rtw_chplan_get_default_regd_6g(u8 id);
35 bool rtw_is_channel_plan_6g_valid(u8 id);
36 bool rtw_regsty_is_excl_chs_6g(struct registry_priv *regsty, u8 ch);
37 #endif
38 
39 u8 rtw_chplan_is_chbw_valid(u8 id, u8 id_6g, enum band_type band, u8 ch, u8 bw, u8 offset
40 	, bool allow_primary_passive, bool allow_passive, struct registry_priv *regsty);
41 
42 enum regd_src_t {
43 	REGD_SRC_RTK_PRIV = 0, /* Regulatory settings from Realtek framework (Realtek defined or customized) */
44 	REGD_SRC_OS = 1, /* Regulatory settings from OS */
45 	REGD_SRC_NUM,
46 };
47 
48 #define regd_src_is_valid(src) ((src) < REGD_SRC_NUM)
49 
50 extern const char *_regd_src_str[];
51 #define regd_src_str(src) ((src) >= REGD_SRC_NUM ? _regd_src_str[REGD_SRC_NUM] : _regd_src_str[src])
52 
53 struct _RT_CHANNEL_INFO;
54 u8 init_channel_set(_adapter *adapter);
55 bool rtw_chset_is_dfs_range(struct _RT_CHANNEL_INFO *chset, u32 hi, u32 lo);
56 bool rtw_chset_is_dfs_ch(struct _RT_CHANNEL_INFO *chset, u8 ch);
57 bool rtw_chset_is_dfs_chbw(struct _RT_CHANNEL_INFO *chset, u8 ch, u8 bw, u8 offset);
58 bool rtw_chinfo_allow_beacon_hint(struct _RT_CHANNEL_INFO *chinfo);
59 u8 rtw_process_beacon_hint(_adapter *adapter, WLAN_BSSID_EX *bss);
60 
61 #define ALPHA2_FMT "%c%c"
62 #define ALPHA2_ARG(a2) ((is_alpha(a2[0]) || is_decimal(a2[0])) ? a2[0] : '-'), ((is_alpha(a2[1]) || is_decimal(a2[1])) ? a2[1] : '-')
63 
64 #define WORLDWIDE_ALPHA2	"00"
65 #define UNSPEC_ALPHA2		"99"
66 
67 #define IS_ALPHA2_WORLDWIDE(_alpha2)	(strncmp(_alpha2, WORLDWIDE_ALPHA2, 2) == 0)
68 #define IS_ALPHA2_UNSPEC(_alpha2)		(strncmp(_alpha2, UNSPEC_ALPHA2, 2) == 0)
69 #define SET_UNSPEC_ALPHA2(_alpha2)		do { _rtw_memcpy(_alpha2, UNSPEC_ALPHA2, 2); } while (0)
70 
71 #define RTW_MODULE_RTL8821AE_HMC_M2		BIT0	/* RTL8821AE(HMC + M.2) */
72 #define RTW_MODULE_RTL8821AU			BIT1	/* RTL8821AU */
73 #define RTW_MODULE_RTL8812AENF_NGFF		BIT2	/* RTL8812AENF(8812AE+8761)_NGFF */
74 #define RTW_MODULE_RTL8812AEBT_HMC		BIT3	/* RTL8812AEBT(8812AE+8761)_HMC */
75 #define RTW_MODULE_RTL8188EE_HMC_M2		BIT4	/* RTL8188EE(HMC + M.2) */
76 #define RTW_MODULE_RTL8723BE_HMC_M2		BIT5	/* RTL8723BE(HMC + M.2) */
77 #define RTW_MODULE_RTL8723BS_NGFF1216	BIT6	/* RTL8723BS(NGFF1216) */
78 #define RTW_MODULE_RTL8192EEBT_HMC_M2	BIT7	/* RTL8192EEBT(8192EE+8761AU)_(HMC + M.2) */
79 #define RTW_MODULE_RTL8723DE_NGFF1630	BIT8	/* RTL8723DE(NGFF1630) */
80 #define RTW_MODULE_RTL8822BE			BIT9	/* RTL8822BE */
81 #define RTW_MODULE_RTL8821CE			BIT10	/* RTL8821CE */
82 
83 enum rtw_regd_inr {
84 	RTW_REGD_SET_BY_INIT = 0,
85 	RTW_REGD_SET_BY_USER = 1,
86 	RTW_REGD_SET_BY_COUNTRY_IE = 2,
87 
88 	/* below is not used for REGD_SRC_RTK_PRIV */
89 	RTW_REGD_SET_BY_DRIVER = 3,
90 	RTW_REGD_SET_BY_CORE = 4,
91 
92 	RTW_REGD_SET_BY_NUM,
93 };
94 
95 extern const char *const _regd_inr_str[];
96 #define regd_inr_str(inr) (((inr) >= RTW_REGD_SET_BY_NUM) ? _regd_inr_str[RTW_REGD_SET_BY_NUM] : _regd_inr_str[(inr)])
97 
98 enum rtw_regd {
99 	RTW_REGD_NA = 0,
100 	RTW_REGD_FCC = 1,
101 	RTW_REGD_MKK = 2,
102 	RTW_REGD_ETSI = 3,
103 	RTW_REGD_IC = 4,
104 	RTW_REGD_KCC = 5,
105 	RTW_REGD_NCC = 6,
106 	RTW_REGD_ACMA = 7,
107 	RTW_REGD_CHILE = 8,
108 	RTW_REGD_MEX = 9,
109 	RTW_REGD_WW,
110 	RTW_REGD_NUM,
111 };
112 
113 extern const char *const _regd_str[];
114 #define regd_str(regd) (((regd) >= RTW_REGD_NUM) ? _regd_str[RTW_REGD_NA] : _regd_str[(regd)])
115 
116 enum rtw_edcca_mode_t {
117 	RTW_EDCCA_NORM		= 0, /* normal */
118 	RTW_EDCCA_ADAPT		= 1, /* adaptivity */
119 	RTW_EDCCA_CS		= 2, /* carrier sense */
120 
121 	RTW_EDCCA_MODE_NUM,
122 	RTW_EDCCA_DEF		= RTW_EDCCA_MODE_NUM, /* default (ref to domain code), used at country chplan map's override field */
123 };
124 
125 extern const char *const _rtw_edcca_mode_str[];
126 #define rtw_edcca_mode_str(mode) (((mode) >= RTW_EDCCA_MODE_NUM) ? _rtw_edcca_mode_str[RTW_EDCCA_NORM] : _rtw_edcca_mode_str[(mode)])
127 
128 enum rtw_dfs_regd {
129 	RTW_DFS_REGD_NONE	= 0,
130 	RTW_DFS_REGD_FCC	= 1,
131 	RTW_DFS_REGD_MKK	= 2,
132 	RTW_DFS_REGD_ETSI	= 3,
133 	RTW_DFS_REGD_NUM,
134 	RTW_DFS_REGD_AUTO	= 0xFF, /* follow channel plan */
135 };
136 
137 extern const char *const _rtw_dfs_regd_str[];
138 #define rtw_dfs_regd_str(region) (((region) >= RTW_DFS_REGD_NUM) ? _rtw_dfs_regd_str[RTW_DFS_REGD_NONE] : _rtw_dfs_regd_str[(region)])
139 
140 typedef enum _REGULATION_TXPWR_LMT {
141 	TXPWR_LMT_NONE = 0, /* no limit */
142 	TXPWR_LMT_FCC = 1,
143 	TXPWR_LMT_MKK = 2,
144 	TXPWR_LMT_ETSI = 3,
145 	TXPWR_LMT_IC = 4,
146 	TXPWR_LMT_KCC = 5,
147 	TXPWR_LMT_NCC = 6,
148 	TXPWR_LMT_ACMA = 7,
149 	TXPWR_LMT_CHILE = 8,
150 	TXPWR_LMT_UKRAINE = 9,
151 	TXPWR_LMT_MEXICO = 10,
152 	TXPWR_LMT_CN = 11,
153 	TXPWR_LMT_QATAR = 12,
154 	TXPWR_LMT_WW, /* smallest of all available limit, keep last */
155 
156 	TXPWR_LMT_NUM,
157 	TXPWR_LMT_DEF = TXPWR_LMT_NUM, /* default (ref to domain code), used at country chplan map's override field */
158 } REGULATION_TXPWR_LMT;
159 
160 extern const char *const _txpwr_lmt_str[];
161 #define txpwr_lmt_str(regd) (((regd) >= TXPWR_LMT_NUM) ? _txpwr_lmt_str[TXPWR_LMT_NUM] : _txpwr_lmt_str[(regd)])
162 
163 extern const REGULATION_TXPWR_LMT _txpwr_lmt_alternate[];
164 #define txpwr_lmt_alternate(ori) (((ori) > TXPWR_LMT_NUM) ? _txpwr_lmt_alternate[TXPWR_LMT_WW] : _txpwr_lmt_alternate[(ori)])
165 
166 #define TXPWR_LMT_ALTERNATE_DEFINED(txpwr_lmt) (txpwr_lmt_alternate(txpwr_lmt) != txpwr_lmt)
167 
168 extern const enum rtw_edcca_mode_t _rtw_regd_to_edcca_mode[RTW_REGD_NUM];
169 #define rtw_regd_to_edcca_mode(regd) (((regd) >= RTW_REGD_NUM) ? RTW_EDCCA_NORM : _rtw_regd_to_edcca_mode[(regd)])
170 
171 extern const REGULATION_TXPWR_LMT _rtw_regd_to_txpwr_lmt[];
172 #define rtw_regd_to_txpwr_lmt(regd) (((regd) >= RTW_REGD_NUM) ? TXPWR_LMT_WW : _rtw_regd_to_txpwr_lmt[(regd)])
173 
174 #define EDCCA_MODES_STR_LEN (((6 + 3 + 1) * BAND_MAX) + 1)
175 char *rtw_get_edcca_modes_str(char *buf, u8 modes[]);
176 void rtw_edcca_mode_update(struct dvobj_priv *dvobj);
177 u8 rtw_get_edcca_mode(struct dvobj_priv *dvobj, enum band_type band);
178 
179 #define TXPWR_NAMES_STR_LEN (((1 + 7 + 1) * BAND_MAX) + 1)
180 char *rtw_get_txpwr_lmt_names_str(char *buf, const char *names[], u8 unknown_bmp);
181 
182 #define CHPLAN_PROTO_EN_AC		BIT0
183 #define CHPLAN_PROTO_EN_AX		BIT1
184 #define CHPLAN_PROTO_EN_ALL	0xFF
185 
186 struct country_chplan {
187 	char alpha2[2];
188 	u8 chplan;
189 #if CONFIG_IEEE80211_BAND_6GHZ
190 	u8 chplan_6g;
191 #endif
192 	u8 edcca_mode_2g_override:2;
193 #if CONFIG_IEEE80211_BAND_5GHZ
194 	u8 edcca_mode_5g_override:2;
195 #endif
196 #if CONFIG_IEEE80211_BAND_6GHZ
197 	u8 edcca_mode_6g_override:2;
198 #endif
199 	u8 txpwr_lmt_override;
200 #if defined(CONFIG_80211AX_HE) || defined(CONFIG_80211AC_VHT)
201 	u8 proto_en;
202 #endif
203 };
204 
205 #ifdef CONFIG_80211AC_VHT
206 #define COUNTRY_CHPLAN_EN_11AC(_ent) (((_ent)->proto_en & CHPLAN_PROTO_EN_AC) ? 1 : 0)
207 #else
208 #define COUNTRY_CHPLAN_EN_11AC(_ent) 0
209 #endif
210 
211 #ifdef CONFIG_80211AX_HE
212 #define COUNTRY_CHPLAN_EN_11AX(_ent) (((_ent)->proto_en & CHPLAN_PROTO_EN_AX) ? 1 : 0)
213 #else
214 #define COUNTRY_CHPLAN_EN_11AX(_ent) 0
215 #endif
216 
217 void rtw_get_chplan_worldwide(struct country_chplan *ent);
218 bool rtw_get_chplan_from_country(const char *country_code, struct country_chplan *ent);
219 
220 void rtw_chplan_ioctl_input_mapping(u16 *chplan, u16 *chplan_6g);
221 bool rtw_chplan_ids_is_world_wide(u8 chplan, u8 chplan_6g);
222 
223 u8 rtw_country_chplan_is_chbw_valid(struct country_chplan *ent, enum band_type band, u8 ch, u8 bw, u8 offset
224 	, bool allow_primary_passive, bool allow_passive, struct registry_priv *regsty);
225 
226 enum country_ie_slave_status {
227 	COUNTRY_IE_SLAVE_NOCOUNTRY		= 0,
228 	COUNTRY_IE_SLAVE_UNKNOWN		= 1,
229 	COUNTRY_IE_SLAVE_OPCH_NOEXIST	= 2,
230 	COUNTRY_IE_SLAVE_APPLICABLE		= 3,
231 
232 	COUNTRY_IE_SLAVE_STATUS_NUM,
233 };
234 
235 struct country_ie_slave_record {
236 	char alpha2[2]; /* country code get from connected AP of STA ifaces, "\x00\x00" is not set */
237 	enum band_type band;
238 	u8 opch;
239 	enum country_ie_slave_status status;
240 };
241 
242 #ifdef CONFIG_80211D
243 extern const char *const _cis_status_str[];
244 #define cis_status_str(s) (((s) >= COUNTRY_IE_SLAVE_STATUS_NUM) ? _cis_status_str[COUNTRY_IE_SLAVE_STATUS_NUM] : _cis_status_str[(s)])
245 
246 void dump_country_ie_slave_records(void *sel, struct rf_ctl_t *rfctl, bool skip_noset);
247 
248 enum country_ie_slave_status rtw_get_chplan_from_recv_country_ie(_adapter *adapter
249 		, enum band_type band, u8 opch, const u8 *country_ie, struct country_chplan *ent
250 		, struct country_ie_slave_record *cisr, const char *caller_msg);
251 
252 enum country_ie_slave_status rtw_get_chplan_from_cisrs(struct rf_ctl_t *rfctl
253 	, struct country_chplan *ent, const char *caller_msg);
254 #endif
255 
256 void dump_country_chplan(void *sel, const struct country_chplan *ent, bool regd_info);
257 void dump_country_chplan_map(void *sel, bool regd_info);
258 void dump_country_list(void *sel);
259 void dump_chplan_id_list(void *sel);
260 void dump_chplan_country_list(void *sel);
261 #if CONFIG_IEEE80211_BAND_6GHZ
262 void dump_chplan_6g_id_list(void *sel);
263 void dump_chplan_6g_country_list(void *sel);
264 #endif
265 #ifdef CONFIG_RTW_DEBUG
266 void dump_chplan_test(void *sel);
267 #endif
268 void dump_chplan_ver(void *sel);
269 
270 void rtw_set_phl_regulation_ctx(struct dvobj_priv *dvobj);
271 void rtw_clear_phl_regulation_ctx(struct dvobj_priv *dvobj);
272 
273 #endif /* __RTW_CHPLAN_H__ */
274