xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_db.h (revision 2848159cbf2fd6863dcd893e613ae04648250714)
1 /*
2  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3  *
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 /**
21  * DOC: reg_db.h
22  * This file contains regulatory component data structures
23  */
24 
25 #ifndef __REG_DB_H
26 #define __REG_DB_H
27 
28 /*
29  * If COMPILE_REGDB_6G and CONFIG_BAND_6GHZ are defined, then
30  * reg_6ghz_super_dmn_id and max_bw_6g are part of the
31  * country_code_to_reg_domain table for a country
32  * entry. If COMPILE_REGDB_6G and CONFIG_BAND_6GHZ are not defined, then they
33  * are absent.
34  *
35  * COMPILE_REGDB_6G is not defined for the Partial offload platform.
36  *
37  * CE:- country entry
38  */
39 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
40 #define CE(country_code, reg_dmn_pair_id, reg_6ghz_super_dmn_id,         \
41 	   alpha2, max_bw_2g, max_bw_5g, max_bw_6g, phymode_bitmap)      \
42 	{CTRY_ ## country_code, reg_dmn_pair_id, reg_6ghz_super_dmn_id,  \
43 	 #alpha2, max_bw_2g, max_bw_5g, max_bw_6g, phymode_bitmap}
44 #else
45 #define CE(country_code, reg_dmn_pair_id, reg_6ghz_super_dmn_id, alpha2, \
46 	   max_bw_2g, max_bw_5g, max_bw_6g, phymode_bitmap)              \
47 	{CTRY_ ## country_code, reg_dmn_pair_id, #alpha2, max_bw_2g,     \
48 	 max_bw_5g, phymode_bitmap}
49 #endif
50 
51 /* Alpha2 code for world reg domain */
52 #define REG_WORLD_ALPHA2 "00"
53 
54 /**
55  * struct regulatory_rule
56  * @start_freq: start frequency
57  * @end_freq: end frequency
58  * @max_bw: maximum bandwidth
59  * @reg_power: regulatory power
60  * @flags: regulatory flags
61  */
62 struct regulatory_rule {
63 	uint16_t start_freq;
64 	uint16_t end_freq;
65 	uint16_t max_bw;
66 	uint8_t reg_power;
67 	uint16_t flags;
68 };
69 
70 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
71 /**
72  * struct regulatory_rule_ext
73  * @start_freq: start frequency in MHz
74  * @end_freq: end frequency in MHz
75  * @max_bw: maximum bandwidth in MHz
76  * @eirp_power: EIRP power in dBm
77  * @psd_power: Max PSD power in dBm per MHz
78  * @flags: regulatory flags
79  */
80 struct regulatory_rule_ext {
81 	uint16_t start_freq;
82 	uint16_t end_freq;
83 	uint16_t max_bw;
84 	uint8_t eirp_power;
85 	int8_t psd_power;
86 	uint16_t flags;
87 };
88 #endif
89 
90 /**
91  * struct regdomain
92  * @ctl_val: CTL value
93  * @dfs_region: dfs region
94  * @min_bw: minimum bandwidth
95  * @max_bw: maximum bandwidth
96  * @num_reg_rules: number of regulatory rules
97  * @reg_rules_id: regulatory rule index
98  */
99 struct regdomain   {
100 	uint8_t ctl_val;
101 	enum dfs_reg dfs_region;
102 	uint16_t min_bw;
103 	uint16_t max_bw;
104 	uint8_t ant_gain;
105 	uint8_t num_reg_rules;
106 	uint8_t reg_rule_id[MAX_REG_RULES];
107 };
108 
109 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
110 /**
111  * struct sub_6g_regdomain
112  * @min_bw: Minimum bandwidth in MHz
113  * @max_bw: Maximum bandwidth in MHz
114  * @num_reg_rules: number of regulatory rules
115  * @reg_rules_id: regulatory rule index
116  */
117 struct sub_6g_regdomain   {
118 	uint16_t min_bw;
119 	uint16_t max_bw;
120 	uint8_t num_reg_rules;
121 	uint8_t sixg_reg_rule_id[MAX_REG_RULES];
122 };
123 #endif
124 
125 /**
126  * struct country_code_to_reg_domain
127  * @country_code: country code
128  * @reg_dmn_pair_id: reg domainpair id
129  * @reg_6ghz_super_dmn_id: 6GHz super domain id
130  * @alpha2: iso-3166 alpha2
131  * @max_bw_2g: maximum 2g bandwidth in MHz
132  * @max_bw_5g: maximum 5g bandwidth in MHz
133  * @max_bw_6g: maximum 6g bandwidth in MHz
134  * @phymode_bitmap: phymodes not supported
135  */
136 struct country_code_to_reg_domain   {
137 	uint16_t country_code;
138 	uint16_t reg_dmn_pair_id;
139 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
140 	uint16_t reg_6ghz_super_dmn_id;
141 #endif
142 	uint8_t alpha2[REG_ALPHA2_LEN + 1];
143 	uint16_t max_bw_2g;
144 	uint16_t max_bw_5g;
145 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
146 	uint16_t max_bw_6g;
147 #endif
148 	uint16_t phymode_bitmap;
149 };
150 
151 /**
152  * struct reg_domain_pair
153  * @reg_dmn_pair_id: reg domainpiar value
154  * @dmn_id_5g: 5g reg domain value
155  * @dmn_id_2g: 2g regdomain value
156  */
157 struct reg_domain_pair {
158 	uint16_t reg_dmn_pair_id;
159 	uint8_t dmn_id_5g;
160 	uint8_t dmn_id_2g;
161 };
162 
163 #if defined(CONFIG_BAND_6GHZ) && defined(COMPILE_REGDB_6G)
164 /**
165  * struct sixghz_super_to_subdomains
166  * @reg_6ghz_super_dmn_id: 6G super domain id.
167  * @reg_domain_6g_id_ap_sp: 6G domain id for SP AP.
168  * @reg_domain_6g_id_ap_lpi: 6G domain id for LPI AP.
169  * @reg_domain_6g_id_ap_vlp: 6G domain id for VLP AP.
170  * @reg_domain_6g_id_client_sp: 6G domain id for clients of the SP AP.
171  * @reg_domain_6g_id_client_lpi: 6G domain id for clients of the LPI AP.
172  * @reg_domain_6g_id_client_vlp: 6G domain id for clients of the VLP AP.
173  */
174 struct sixghz_super_to_subdomains {
175 	uint16_t reg_6ghz_super_dmn_id;
176 	uint8_t reg_domain_6g_id_ap_sp;
177 	uint8_t reg_domain_6g_id_ap_lpi;
178 	uint8_t reg_domain_6g_id_ap_vlp;
179 	uint8_t reg_domain_6g_id_client_sp[REG_MAX_CLIENT_TYPE - 1];
180 	uint8_t reg_domain_6g_id_client_lpi[REG_MAX_CLIENT_TYPE - 1];
181 	uint8_t reg_domain_6g_id_client_vlp[REG_MAX_CLIENT_TYPE - 1];
182 };
183 #endif
184 
185 QDF_STATUS reg_get_num_countries(int *num_countries);
186 
187 QDF_STATUS reg_get_num_reg_dmn_pairs(int *num_reg_dmn);
188 
189 QDF_STATUS reg_get_default_country(uint16_t *default_country);
190 
191 /**
192  * reg_etsi13_regdmn () - Checks if the reg domain is ETSI13 or not
193  * @reg_dmn: reg domain
194  *
195  * Return: true or false
196  */
197 bool reg_etsi13_regdmn(uint8_t reg_dmn);
198 
199 /**
200  * reg_fcc_regdmn () - Checks if the reg domain is FCC3/FCC8/FCC15/FCC16 or not
201  * @reg_dmn: reg domain
202  *
203  * Return: true or false
204  */
205 bool reg_fcc_regdmn(uint8_t reg_dmn);
206 
207 /**
208  * reg_en302_502_regdmn() - Check if the reg domain is en302_502 applicable.
209  * @reg_dmn: Regulatory domain pair ID.
210  *
211  * Return: True if EN302_502 applicable, else false.
212  */
213 bool reg_en302_502_regdmn(uint16_t reg_dmn);
214 #endif
215