xref: /freebsd/sys/contrib/dev/rtw89/regd.c (revision 8e93258f2686c76b4e3b384a904d8b4413976229)
1*8e93258fSBjoern A. Zeeb // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2*8e93258fSBjoern A. Zeeb /* Copyright(c) 2019-2020  Realtek Corporation
3*8e93258fSBjoern A. Zeeb  */
4*8e93258fSBjoern A. Zeeb 
5*8e93258fSBjoern A. Zeeb #include "debug.h"
6*8e93258fSBjoern A. Zeeb #include "ps.h"
7*8e93258fSBjoern A. Zeeb 
8*8e93258fSBjoern A. Zeeb #define COUNTRY_REGD(_alpha2, _txpwr_regd...) \
9*8e93258fSBjoern A. Zeeb 	{.alpha2 = (_alpha2), \
10*8e93258fSBjoern A. Zeeb 	 .txpwr_regd = {_txpwr_regd}, \
11*8e93258fSBjoern A. Zeeb 	}
12*8e93258fSBjoern A. Zeeb 
13*8e93258fSBjoern A. Zeeb static const struct rtw89_regulatory rtw89_ww_regd =
14*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("00", RTW89_WW, RTW89_WW);
15*8e93258fSBjoern A. Zeeb 
16*8e93258fSBjoern A. Zeeb static const struct rtw89_regulatory rtw89_regd_map[] = {
17*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AR", RTW89_MEXICO, RTW89_MEXICO, RTW89_NA),
18*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BO", RTW89_FCC, RTW89_FCC, RTW89_NA),
19*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BR", RTW89_FCC, RTW89_FCC, RTW89_FCC),
20*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CL", RTW89_CHILE, RTW89_CHILE, RTW89_CHILE),
21*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CO", RTW89_FCC, RTW89_FCC, RTW89_NA),
22*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CR", RTW89_FCC, RTW89_FCC, RTW89_FCC),
23*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("EC", RTW89_FCC, RTW89_FCC, RTW89_NA),
24*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SV", RTW89_FCC, RTW89_FCC, RTW89_NA),
25*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GT", RTW89_FCC, RTW89_FCC, RTW89_NA),
26*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HN", RTW89_FCC, RTW89_FCC, RTW89_FCC),
27*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MX", RTW89_MEXICO, RTW89_MEXICO, RTW89_NA),
28*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NI", RTW89_FCC, RTW89_FCC, RTW89_NA),
29*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PA", RTW89_FCC, RTW89_FCC, RTW89_NA),
30*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PY", RTW89_FCC, RTW89_FCC, RTW89_NA),
31*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PE", RTW89_FCC, RTW89_FCC, RTW89_NA),
32*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("US", RTW89_FCC, RTW89_FCC, RTW89_FCC),
33*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("UY", RTW89_FCC, RTW89_FCC, RTW89_NA),
34*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VE", RTW89_FCC, RTW89_FCC, RTW89_NA),
35*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PR", RTW89_FCC, RTW89_FCC, RTW89_NA),
36*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DO", RTW89_FCC, RTW89_FCC, RTW89_NA),
37*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
38*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
39*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CY", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
40*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CZ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
41*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
42*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("EE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
43*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
44*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
45*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
46*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
47*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HU", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
48*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IS", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
49*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
50*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
51*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LV", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
52*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
53*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
54*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LU", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
55*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
56*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MC", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
57*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
58*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NO", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
59*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
60*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
61*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
62*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
63*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ES", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
64*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
65*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CH", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
66*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GB", RTW89_UK, RTW89_UK, RTW89_UK),
67*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
68*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
69*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
70*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
71*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
72*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
73*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("EG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
74*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
75*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
76*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
77*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("JO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
78*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
79*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
80*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
81*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
82*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LB", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
83*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
84*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
85*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
86*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
87*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
88*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
89*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("OM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
90*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("QA", RTW89_QATAR, RTW89_QATAR, RTW89_QATAR),
91*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("RO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
92*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("RU", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
93*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
94*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
95*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("RS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
96*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ME", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
97*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ZA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
98*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
99*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("UA", RTW89_UKRAINE, RTW89_UKRAINE, RTW89_UKRAINE),
100*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
101*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("YE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
102*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ZW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
103*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
104*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
105*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CN", RTW89_CN, RTW89_CN, RTW89_CN),
106*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
107*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
108*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ID", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
109*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KR", RTW89_KCC, RTW89_KCC, RTW89_KCC),
110*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MY", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
111*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
112*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
113*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
114*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
115*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TW", RTW89_FCC, RTW89_FCC, RTW89_NA),
116*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
117*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
118*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AU", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
119*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NZ", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
120*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
121*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CA", RTW89_IC, RTW89_IC, RTW89_IC),
122*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("JP", RTW89_MKK, RTW89_MKK, RTW89_NA),
123*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("JM", RTW89_FCC, RTW89_FCC, RTW89_NA),
124*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AN", RTW89_FCC, RTW89_FCC, RTW89_NA),
125*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TT", RTW89_FCC, RTW89_FCC, RTW89_NA),
126*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
127*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
128*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
129*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AS", RTW89_FCC, RTW89_FCC, RTW89_NA),
130*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
131*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
132*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
133*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
134*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AG", RTW89_FCC, RTW89_FCC, RTW89_NA),
135*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
136*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("AW", RTW89_FCC, RTW89_FCC, RTW89_NA),
137*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BS", RTW89_FCC, RTW89_FCC, RTW89_NA),
138*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BB", RTW89_FCC, RTW89_FCC, RTW89_NA),
139*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BY", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
140*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BZ", RTW89_FCC, RTW89_FCC, RTW89_NA),
141*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
142*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BM", RTW89_FCC, RTW89_FCC, RTW89_NA),
143*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BT", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
144*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
145*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
146*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
147*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VG", RTW89_FCC, RTW89_FCC, RTW89_NA),
148*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
149*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
150*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
151*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("BI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
152*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
153*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
154*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KY", RTW89_FCC, RTW89_FCC, RTW89_NA),
155*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
156*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
157*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CX", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
158*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CC", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
159*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
160*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
161*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
162*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
163*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("CI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
164*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
165*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("DM", RTW89_FCC, RTW89_FCC, RTW89_NA),
166*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
167*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ER", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
168*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ET", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
169*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
170*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
171*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FJ", RTW89_FCC, RTW89_FCC, RTW89_NA),
172*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
173*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
174*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
175*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
176*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
177*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
178*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
179*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
180*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GD", RTW89_FCC, RTW89_FCC, RTW89_NA),
181*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GP", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
182*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GU", RTW89_FCC, RTW89_FCC, RTW89_NA),
183*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
184*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
185*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
186*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GY", RTW89_NCC, RTW89_NCC, RTW89_NA),
187*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HT", RTW89_FCC, RTW89_FCC, RTW89_NA),
188*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("HM", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
189*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
190*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
191*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("JE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
192*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
193*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
194*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
195*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LY", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
196*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
197*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
198*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
199*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
200*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ML", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
201*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MH", RTW89_FCC, RTW89_FCC, RTW89_NA),
202*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
203*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
204*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MU", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
205*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("YT", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
206*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("FM", RTW89_FCC, RTW89_FCC, RTW89_NA),
207*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
208*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
209*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
210*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
211*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NP", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
212*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NC", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
213*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
214*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NU", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
215*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("NF", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
216*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MP", RTW89_FCC, RTW89_FCC, RTW89_NA),
217*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PW", RTW89_FCC, RTW89_FCC, RTW89_NA),
218*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("RE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
219*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("RW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
220*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
221*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("KN", RTW89_FCC, RTW89_FCC, RTW89_NA),
222*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("LC", RTW89_FCC, RTW89_FCC, RTW89_NA),
223*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("MF", RTW89_FCC, RTW89_FCC, RTW89_NA),
224*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SX", RTW89_FCC, RTW89_FCC, RTW89_NA),
225*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
226*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VC", RTW89_FCC, RTW89_FCC, RTW89_NA),
227*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("WS", RTW89_FCC, RTW89_FCC, RTW89_NA),
228*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
229*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ST", RTW89_FCC, RTW89_FCC, RTW89_NA),
230*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SC", RTW89_FCC, RTW89_FCC, RTW89_NA),
231*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
232*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SB", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
233*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
234*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("GS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
235*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SR", RTW89_FCC, RTW89_FCC, RTW89_NA),
236*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
237*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("SZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
238*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
239*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
240*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
241*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TK", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
242*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
243*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
244*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TC", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
245*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("TV", RTW89_ETSI, RTW89_NA, RTW89_NA),
246*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("UG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
247*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VI", RTW89_FCC, RTW89_FCC, RTW89_NA),
248*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("UZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
249*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("VU", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
250*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("WF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
251*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("EH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
252*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("ZM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
253*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("IR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
254*8e93258fSBjoern A. Zeeb 	COUNTRY_REGD("PS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
255*8e93258fSBjoern A. Zeeb };
256*8e93258fSBjoern A. Zeeb 
257*8e93258fSBjoern A. Zeeb static const struct rtw89_regulatory *rtw89_regd_find_reg_by_name(char *alpha2)
258*8e93258fSBjoern A. Zeeb {
259*8e93258fSBjoern A. Zeeb 	u32 i;
260*8e93258fSBjoern A. Zeeb 
261*8e93258fSBjoern A. Zeeb 	for (i = 0; i < ARRAY_SIZE(rtw89_regd_map); i++) {
262*8e93258fSBjoern A. Zeeb 		if (!memcmp(rtw89_regd_map[i].alpha2, alpha2, 2))
263*8e93258fSBjoern A. Zeeb 			return &rtw89_regd_map[i];
264*8e93258fSBjoern A. Zeeb 	}
265*8e93258fSBjoern A. Zeeb 
266*8e93258fSBjoern A. Zeeb 	return &rtw89_ww_regd;
267*8e93258fSBjoern A. Zeeb }
268*8e93258fSBjoern A. Zeeb 
269*8e93258fSBjoern A. Zeeb static bool rtw89_regd_is_ww(const struct rtw89_regulatory *regd)
270*8e93258fSBjoern A. Zeeb {
271*8e93258fSBjoern A. Zeeb 	return regd == &rtw89_ww_regd;
272*8e93258fSBjoern A. Zeeb }
273*8e93258fSBjoern A. Zeeb 
274*8e93258fSBjoern A. Zeeb #define rtw89_debug_regd(_dev, _regd, _desc, _argv...) \
275*8e93258fSBjoern A. Zeeb do { \
276*8e93258fSBjoern A. Zeeb 	typeof(_regd) __r = _regd; \
277*8e93258fSBjoern A. Zeeb 	rtw89_debug(_dev, RTW89_DBG_REGD, _desc \
278*8e93258fSBjoern A. Zeeb 		    ": %c%c: mapping txregd to {2g: %d, 5g: %d, 6g: %d}\n", \
279*8e93258fSBjoern A. Zeeb 		    ##_argv, __r->alpha2[0], __r->alpha2[1], \
280*8e93258fSBjoern A. Zeeb 		    __r->txpwr_regd[RTW89_BAND_2G], \
281*8e93258fSBjoern A. Zeeb 		    __r->txpwr_regd[RTW89_BAND_5G], \
282*8e93258fSBjoern A. Zeeb 		    __r->txpwr_regd[RTW89_BAND_6G]); \
283*8e93258fSBjoern A. Zeeb } while (0)
284*8e93258fSBjoern A. Zeeb 
285*8e93258fSBjoern A. Zeeb int rtw89_regd_init(struct rtw89_dev *rtwdev,
286*8e93258fSBjoern A. Zeeb 		    void (*reg_notifier)(struct wiphy *wiphy,
287*8e93258fSBjoern A. Zeeb 					 struct regulatory_request *request))
288*8e93258fSBjoern A. Zeeb {
289*8e93258fSBjoern A. Zeeb 	const struct rtw89_regulatory *chip_regd;
290*8e93258fSBjoern A. Zeeb 	struct wiphy *wiphy = rtwdev->hw->wiphy;
291*8e93258fSBjoern A. Zeeb 	int ret;
292*8e93258fSBjoern A. Zeeb 
293*8e93258fSBjoern A. Zeeb 	if (!wiphy)
294*8e93258fSBjoern A. Zeeb 		return -EINVAL;
295*8e93258fSBjoern A. Zeeb 
296*8e93258fSBjoern A. Zeeb 	chip_regd = rtw89_regd_find_reg_by_name(rtwdev->efuse.country_code);
297*8e93258fSBjoern A. Zeeb #if defined(__FreeBSD__)
298*8e93258fSBjoern A. Zeeb 	rtwdev->regd = chip_regd;
299*8e93258fSBjoern A. Zeeb #endif
300*8e93258fSBjoern A. Zeeb 	if (!rtw89_regd_is_ww(chip_regd)) {
301*8e93258fSBjoern A. Zeeb #if defined(__linux__)
302*8e93258fSBjoern A. Zeeb 		rtwdev->regd = chip_regd;
303*8e93258fSBjoern A. Zeeb #endif
304*8e93258fSBjoern A. Zeeb 		/* Ignore country ie if there is a country domain programmed in chip */
305*8e93258fSBjoern A. Zeeb 		wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
306*8e93258fSBjoern A. Zeeb 		wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
307*8e93258fSBjoern A. Zeeb 
308*8e93258fSBjoern A. Zeeb 		ret = regulatory_hint(rtwdev->hw->wiphy, rtwdev->regd->alpha2);
309*8e93258fSBjoern A. Zeeb 		if (ret)
310*8e93258fSBjoern A. Zeeb 			rtw89_warn(rtwdev, "failed to hint regulatory:%d\n", ret);
311*8e93258fSBjoern A. Zeeb 
312*8e93258fSBjoern A. Zeeb 		rtw89_debug_regd(rtwdev, chip_regd, "efuse country code");
313*8e93258fSBjoern A. Zeeb 		return 0;
314*8e93258fSBjoern A. Zeeb 	}
315*8e93258fSBjoern A. Zeeb 
316*8e93258fSBjoern A. Zeeb 	rtw89_debug_regd(rtwdev, rtwdev->regd,
317*8e93258fSBjoern A. Zeeb 			 "worldwide roaming chip, follow the setting of stack");
318*8e93258fSBjoern A. Zeeb 	return 0;
319*8e93258fSBjoern A. Zeeb }
320*8e93258fSBjoern A. Zeeb 
321*8e93258fSBjoern A. Zeeb static void rtw89_regd_notifier_apply(struct rtw89_dev *rtwdev,
322*8e93258fSBjoern A. Zeeb 				      struct wiphy *wiphy,
323*8e93258fSBjoern A. Zeeb 				      struct regulatory_request *request)
324*8e93258fSBjoern A. Zeeb {
325*8e93258fSBjoern A. Zeeb 	rtwdev->regd = rtw89_regd_find_reg_by_name(request->alpha2);
326*8e93258fSBjoern A. Zeeb 	/* This notification might be set from the system of distros,
327*8e93258fSBjoern A. Zeeb 	 * and it does not expect the regulatory will be modified by
328*8e93258fSBjoern A. Zeeb 	 * connecting to an AP (i.e. country ie).
329*8e93258fSBjoern A. Zeeb 	 */
330*8e93258fSBjoern A. Zeeb 	if (request->initiator == NL80211_REGDOM_SET_BY_USER &&
331*8e93258fSBjoern A. Zeeb 	    !rtw89_regd_is_ww(rtwdev->regd))
332*8e93258fSBjoern A. Zeeb 		wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
333*8e93258fSBjoern A. Zeeb 	else
334*8e93258fSBjoern A. Zeeb 		wiphy->regulatory_flags &= ~REGULATORY_COUNTRY_IE_IGNORE;
335*8e93258fSBjoern A. Zeeb }
336*8e93258fSBjoern A. Zeeb 
337*8e93258fSBjoern A. Zeeb void rtw89_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request)
338*8e93258fSBjoern A. Zeeb {
339*8e93258fSBjoern A. Zeeb 	struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
340*8e93258fSBjoern A. Zeeb 	struct rtw89_dev *rtwdev = hw->priv;
341*8e93258fSBjoern A. Zeeb 
342*8e93258fSBjoern A. Zeeb 	mutex_lock(&rtwdev->mutex);
343*8e93258fSBjoern A. Zeeb 	rtw89_leave_ps_mode(rtwdev);
344*8e93258fSBjoern A. Zeeb 
345*8e93258fSBjoern A. Zeeb 	if (wiphy->regd) {
346*8e93258fSBjoern A. Zeeb 		rtw89_debug(rtwdev, RTW89_DBG_REGD,
347*8e93258fSBjoern A. Zeeb 			    "There is a country domain programmed in chip, ignore notifications\n");
348*8e93258fSBjoern A. Zeeb 		goto exit;
349*8e93258fSBjoern A. Zeeb 	}
350*8e93258fSBjoern A. Zeeb 	rtw89_regd_notifier_apply(rtwdev, wiphy, request);
351*8e93258fSBjoern A. Zeeb 	rtw89_debug_regd(rtwdev, rtwdev->regd, "get from initiator %d, alpha2",
352*8e93258fSBjoern A. Zeeb 			 request->initiator);
353*8e93258fSBjoern A. Zeeb 
354*8e93258fSBjoern A. Zeeb 	rtw89_core_set_chip_txpwr(rtwdev);
355*8e93258fSBjoern A. Zeeb 
356*8e93258fSBjoern A. Zeeb exit:
357*8e93258fSBjoern A. Zeeb 	mutex_unlock(&rtwdev->mutex);
358*8e93258fSBjoern A. Zeeb }
359