xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_services_common.c (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: reg_services_common.c
21  * This file defines regulatory component service functions
22  */
23 
24 #include <wlan_cmn.h>
25 #include <reg_services_public_struct.h>
26 #ifdef CONFIG_AFC_SUPPORT
27 #include <wlan_reg_services_api.h>
28 #include "reg_opclass.h"
29 #endif
30 #include <wlan_objmgr_psoc_obj.h>
31 #include <qdf_lock.h>
32 #include "reg_priv_objs.h"
33 #include "reg_utils.h"
34 #include "reg_callbacks.h"
35 #include "reg_services_common.h"
36 #include <wlan_objmgr_psoc_obj.h>
37 #include "reg_db.h"
38 #include "reg_db_parser.h"
39 #include "reg_build_chan_list.h"
40 #include <wlan_objmgr_pdev_obj.h>
41 #include <target_if.h>
42 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST
43 #include "wlan_mlme_ucfg_api.h"
44 #include "wlan_nan_api.h"
45 #endif
46 
47 const struct chan_map *channel_map;
48 
49 #ifdef CONFIG_CHAN_FREQ_API
50 /* bonded_chan_40mhz_list_freq - List of 40MHz bonnded channel frequencies */
51 static const struct bonded_channel_freq bonded_chan_40mhz_list_freq[] = {
52 	{5180, 5200},
53 	{5220, 5240},
54 	{5260, 5280},
55 	{5300, 5320},
56 	{5500, 5520},
57 	{5540, 5560},
58 	{5580, 5600},
59 	{5620, 5640},
60 	{5660, 5680},
61 	{5700, 5720},
62 	{5745, 5765},
63 	{5785, 5805},
64 	{5825, 5845},
65 	{5865, 5885},
66 #ifdef CONFIG_BAND_6GHZ
67 	{5955, 5975},
68 	{5995, 6015},
69 	{6035, 6055},
70 	{6075, 6095},
71 	{6115, 6135},
72 	{6155, 6175},
73 	{6195, 6215},
74 	{6235, 6255},
75 	{6275, 6295},
76 	{6315, 6335},
77 	{6355, 6375},
78 	{6395, 6415},
79 	{6435, 6455},
80 	{6475, 6495},
81 	{6515, 6535},
82 	{6555, 6575},
83 	{6595, 6615},
84 	{6635, 6655},
85 	{6675, 6695},
86 	{6715, 6735},
87 	{6755, 6775},
88 	{6795, 6815},
89 	{6835, 6855},
90 	{6875, 6895},
91 	{6915, 6935},
92 	{6955, 6975},
93 	{6995, 7015},
94 	{7035, 7055},
95 	{7075, 7095}
96 #endif /*CONFIG_BAND_6GHZ*/
97 };
98 
99 /* bonded_chan_80mhz_list_freq - List of 80MHz bonnded channel frequencies */
100 static const struct bonded_channel_freq bonded_chan_80mhz_list_freq[] = {
101 	{5180, 5240},
102 	{5260, 5320},
103 	{5500, 5560},
104 	{5580, 5640},
105 	{5660, 5720},
106 	{5745, 5805},
107 	{5825, 5885},
108 #ifdef CONFIG_BAND_6GHZ
109 	{5955, 6015},
110 	{6035, 6095},
111 	{6115, 6175},
112 	{6195, 6255},
113 	{6275, 6335},
114 	{6355, 6415},
115 	{6435, 6495},
116 	{6515, 6575},
117 	{6595, 6655},
118 	{6675, 6735},
119 	{6755, 6815},
120 	{6835, 6895},
121 	{6915, 6975},
122 	{6995, 7055}
123 #endif /*CONFIG_BAND_6GHZ*/
124 };
125 
126 /* bonded_chan_160mhz_list_freq - List of 160MHz bonnded channel frequencies */
127 static const struct bonded_channel_freq bonded_chan_160mhz_list_freq[] = {
128 	{5180, 5320},
129 	{5500, 5640},
130 	{5745, 5885},
131 #ifdef CONFIG_BAND_6GHZ
132 	{5955, 6095},
133 	{6115, 6255},
134 	{6275, 6415},
135 	{6435, 6575},
136 	{6595, 6735},
137 	{6755, 6895},
138 	{6915, 7055}
139 #endif /*CONFIG_BAND_6GHZ*/
140 };
141 
142 const struct bonded_channel_freq *
143 reg_get_bonded_chan_entry(qdf_freq_t freq,
144 			  enum phy_ch_width chwidth)
145 {
146 	const struct bonded_channel_freq *bonded_chan_arr;
147 	uint16_t array_size, i;
148 
149 	switch (chwidth) {
150 	case CH_WIDTH_160MHZ:
151 		bonded_chan_arr = bonded_chan_160mhz_list_freq;
152 		array_size = QDF_ARRAY_SIZE(bonded_chan_160mhz_list_freq);
153 		break;
154 	case CH_WIDTH_80MHZ:
155 	case CH_WIDTH_80P80MHZ:
156 		bonded_chan_arr = bonded_chan_80mhz_list_freq;
157 		array_size = QDF_ARRAY_SIZE(bonded_chan_80mhz_list_freq);
158 		break;
159 	case CH_WIDTH_40MHZ:
160 		bonded_chan_arr = bonded_chan_40mhz_list_freq;
161 		array_size = QDF_ARRAY_SIZE(bonded_chan_40mhz_list_freq);
162 		break;
163 	default:
164 		reg_debug("Could not find bonded_chan_array for chwidth %d",
165 			  chwidth);
166 		return NULL;
167 	}
168 
169 	for (i = 0; i < array_size; i++) {
170 		if ((freq >= bonded_chan_arr[i].start_freq) &&
171 		    (freq <= bonded_chan_arr[i].end_freq)) {
172 			return &bonded_chan_arr[i];
173 		}
174 	}
175 
176 	reg_debug("Could not find a bonded pair for freq %d and width %d",
177 		  freq, chwidth);
178 	return NULL;
179 }
180 
181 #ifdef WLAN_FEATURE_11BE
182 /* bonded_chan_320mhz_list_freq - List of 320MHz bonnded channel frequencies */
183 static const struct bonded_channel_freq bonded_chan_320mhz_list_freq[] = {
184 	{5500, 5800}, /* center freq: 5650 */
185 #ifdef CONFIG_BAND_6GHZ
186 	{5955, 6255}, /* center freq: 6105 */
187 	{6115, 6415}, /* center freq: 6265 */
188 	{6275, 6575}, /* center freq: 6425 */
189 	{6435, 6735}, /* center freq: 6585 */
190 	{6595, 6895}, /* center freq: 6745 */
191 	{6755, 7055}  /* center freq: 6905 */
192 #endif /*CONFIG_BAND_6GHZ*/
193 };
194 #endif
195 
196 #endif /*CONFIG_CHAN_FREQ_API*/
197 
198 enum phy_ch_width get_next_lower_bandwidth(enum phy_ch_width ch_width)
199 {
200 	static const enum phy_ch_width get_next_lower_bw[] = {
201     /* 80+80 mode not supported in chips that support 320 mode */
202 #ifdef WLAN_FEATURE_11BE
203 		[CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
204 #endif
205 		[CH_WIDTH_80P80MHZ] = CH_WIDTH_160MHZ,
206 		[CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
207 		[CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
208 		[CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
209 		[CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
210 		[CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
211 		[CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
212 	};
213 
214 	return get_next_lower_bw[ch_width];
215 }
216 
217 const struct chan_map channel_map_us[NUM_CHANNELS] = {
218 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
219 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
220 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
221 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
222 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
223 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
224 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
225 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
226 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
227 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
228 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
229 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
230 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
231 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
232 #ifdef CONFIG_49GHZ_CHAN
233 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
234 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
235 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
236 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
237 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
238 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
239 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
240 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
241 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
242 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
243 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
244 	[CHAN_ENUM_4942] = {4942, 1, 5, 5},
245 	[CHAN_ENUM_4945] = {4945, 11, 10, 10},
246 	[CHAN_ENUM_4947] = {4947, 2, 5, 5},
247 	[CHAN_ENUM_4950] = {4950, 20, 10, 20},
248 	[CHAN_ENUM_4952] = {4952, 3, 5, 5},
249 	[CHAN_ENUM_4955] = {4955, 21, 10, 20},
250 	[CHAN_ENUM_4957] = {4957, 4, 5, 5},
251 	[CHAN_ENUM_4960] = {4960, 22, 10, 20},
252 	[CHAN_ENUM_4962] = {4962, 5, 5, 5},
253 	[CHAN_ENUM_4965] = {4965, 23, 10, 20},
254 	[CHAN_ENUM_4967] = {4967, 6, 5, 5},
255 	[CHAN_ENUM_4970] = {4970, 24, 10, 20},
256 	[CHAN_ENUM_4972] = {4972, 7, 5, 5},
257 	[CHAN_ENUM_4975] = {4975, 25, 10, 20},
258 	[CHAN_ENUM_4977] = {4977, 8, 5, 5},
259 	[CHAN_ENUM_4980] = {4980, 26, 10, 20},
260 	[CHAN_ENUM_4982] = {4982, 9, 5, 5},
261 	[CHAN_ENUM_4985] = {4985, 19, 10, 10},
262 	[CHAN_ENUM_4987] = {4987, 10, 5, 5},
263 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
264 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
265 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
266 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
267 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
268 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
269 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
270 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
271 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
272 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
273 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
274 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
275 #endif /* CONFIG_49GHZ_CHAN */
276 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
277 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
278 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
279 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
280 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
281 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
282 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
283 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
284 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
285 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
286 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
287 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
288 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
289 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
290 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
291 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
292 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
293 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
294 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
295 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
296 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
297 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
298 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
299 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
300 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
301 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
302 #ifdef WLAN_FEATURE_DSRC
303 	[CHAN_ENUM_5850] = {5850, 170, 2, 160},
304 	[CHAN_ENUM_5855] = {5855, 171, 2, 160},
305 	[CHAN_ENUM_5860] = {5860, 172, 2, 160},
306 #endif
307 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
308 #ifdef WLAN_FEATURE_DSRC
309 	[CHAN_ENUM_5870] = {5870, 174, 2, 160},
310 	[CHAN_ENUM_5875] = {5875, 175, 2, 160},
311 	[CHAN_ENUM_5880] = {5880, 176, 2, 160},
312 #endif
313 	[CHAN_ENUM_5885] = {5885, 177, 2, 160},
314 #ifdef WLAN_FEATURE_DSRC
315 	[CHAN_ENUM_5890] = {5890, 178, 2, 160},
316 	[CHAN_ENUM_5895] = {5895, 179, 2, 160},
317 	[CHAN_ENUM_5900] = {5900, 180, 2, 160},
318 	[CHAN_ENUM_5905] = {5905, 181, 2, 160},
319 	[CHAN_ENUM_5910] = {5910, 182, 2, 160},
320 	[CHAN_ENUM_5915] = {5915, 183, 2, 160},
321 	[CHAN_ENUM_5920] = {5920, 184, 2, 160},
322 #endif /* WLAN_FEATURE_DSRC */
323 #ifdef CONFIG_BAND_6GHZ
324 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
325 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
326 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
327 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
328 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
329 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
330 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
331 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
332 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
333 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
334 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
335 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
336 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
337 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
338 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
339 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
340 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
341 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
342 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
343 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
344 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
345 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
346 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
347 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
348 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
349 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
350 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
351 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
352 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
353 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
354 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
355 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
356 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
357 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
358 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
359 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
360 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
361 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
362 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
363 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
364 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
365 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
366 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
367 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
368 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
369 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
370 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
371 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
372 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
373 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
374 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
375 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
376 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
377 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
378 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
379 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
380 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
381 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
382 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
383 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
384 #endif /* CONFIG_BAND_6GHZ */
385 };
386 
387 const struct chan_map channel_map_eu[NUM_CHANNELS] = {
388 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
389 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
390 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
391 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
392 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
393 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
394 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
395 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
396 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
397 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
398 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
399 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
400 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
401 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
402 #ifdef CONFIG_49GHZ_CHAN
403 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
404 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
405 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
406 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
407 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
408 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
409 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
410 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
411 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
412 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
413 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
414 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
415 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
416 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
417 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
418 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
419 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
420 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
421 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
422 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
423 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
424 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
425 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
426 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
427 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
428 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
429 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
430 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
431 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
432 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
433 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
434 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
435 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
436 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
437 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
438 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
439 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
440 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
441 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
442 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
443 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
444 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
445 #endif /* CONFIG_49GHZ_CHAN */
446 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
447 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
448 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
449 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
450 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
451 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
452 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
453 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
454 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
455 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
456 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
457 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
458 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
459 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
460 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
461 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
462 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
463 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
464 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
465 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
466 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
467 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
468 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
469 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
470 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
471 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
472 #ifdef WLAN_FEATURE_DSRC
473 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
474 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
475 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
476 #endif
477 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
478 #ifdef WLAN_FEATURE_DSRC
479 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
480 	[CHAN_ENUM_5875] = {5875, 175, 2, 160},
481 	[CHAN_ENUM_5880] = {5880, 176, 2, 160},
482 #endif
483 	[CHAN_ENUM_5885] = {5885, 177, 2, 160},
484 #ifdef WLAN_FEATURE_DSRC
485 	[CHAN_ENUM_5890] = {5890, 178, 2, 160},
486 	[CHAN_ENUM_5895] = {5895, 179, 2, 160},
487 	[CHAN_ENUM_5900] = {5900, 180, 2, 160},
488 	[CHAN_ENUM_5905] = {5905, 181, 2, 160},
489 	[CHAN_ENUM_5910] = {5910, 182, 2, 160},
490 	[CHAN_ENUM_5915] = {5915, 183, 2, 160},
491 	[CHAN_ENUM_5920] = {5920, 184, 2, 160},
492 #endif /* WLAN_FEATURE_DSRC */
493 #ifdef CONFIG_BAND_6GHZ
494 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
495 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
496 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
497 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
498 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
499 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
500 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
501 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
502 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
503 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
504 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
505 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
506 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
507 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
508 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
509 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
510 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
511 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
512 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
513 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
514 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
515 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
516 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
517 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
518 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
519 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
520 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
521 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
522 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
523 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
524 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
525 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
526 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
527 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
528 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
529 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
530 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
531 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
532 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
533 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
534 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
535 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
536 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
537 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
538 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
539 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
540 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
541 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
542 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
543 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
544 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
545 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
546 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
547 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
548 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
549 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
550 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
551 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
552 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
553 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
554 #endif /* CONFIG_BAND_6GHZ */
555 };
556 
557 const struct chan_map channel_map_jp[NUM_CHANNELS] = {
558 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
559 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
560 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
561 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
562 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
563 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
564 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
565 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
566 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
567 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
568 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
569 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
570 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
571 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
572 #ifdef CONFIG_49GHZ_CHAN
573 	[CHAN_ENUM_4912] = {4912, 182, 5, 5},
574 	[CHAN_ENUM_4915] = {4915, 183, 10, 10},
575 	[CHAN_ENUM_4917] = {4917, 183, 5, 5},
576 	[CHAN_ENUM_4920] = {4920, 184, 10, 20},
577 	[CHAN_ENUM_4922] = {4922, 184, 5, 5},
578 	[CHAN_ENUM_4925] = {4925, 185, 10, 10},
579 	[CHAN_ENUM_4927] = {4927, 185, 5, 5},
580 	[CHAN_ENUM_4932] = {4932, 186, 5, 5},
581 	[CHAN_ENUM_4935] = {4935, 187, 10, 10},
582 	[CHAN_ENUM_4937] = {4937, 187, 5, 5},
583 	[CHAN_ENUM_4940] = {4940, 188, 10, 20},
584 	[CHAN_ENUM_4942] = {4942, 188, 5, 5},
585 	[CHAN_ENUM_4945] = {4945, 189, 10, 10},
586 	[CHAN_ENUM_4947] = {4947, 189, 5, 5},
587 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
588 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
589 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
590 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
591 	[CHAN_ENUM_4960] = {4960, 192, 20, 20},
592 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
593 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
594 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
595 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
596 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
597 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
598 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
599 	[CHAN_ENUM_4980] = {4980, 196, 20, 20},
600 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
601 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
602 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
603 	[CHAN_ENUM_5032] = {5032, 6, 5, 5},
604 	[CHAN_ENUM_5035] = {5035, 7, 10, 10},
605 	[CHAN_ENUM_5037] = {5037, 7, 5, 5},
606 	[CHAN_ENUM_5040] = {5040, 8, 10, 20},
607 	[CHAN_ENUM_5042] = {5042, 8, 5, 5},
608 	[CHAN_ENUM_5045] = {5045, 9, 10, 10},
609 	[CHAN_ENUM_5047] = {5047, 9, 5, 5},
610 	[CHAN_ENUM_5052] = {5052, 10, 5, 5},
611 	[CHAN_ENUM_5055] = {5055, 11, 10, 10},
612 	[CHAN_ENUM_5057] = {5057, 11, 5, 5},
613 	[CHAN_ENUM_5060] = {5060, 12, 20, 20},
614 	[CHAN_ENUM_5080] = {5080, 16, 20, 20},
615 #endif /* CONFIG_49GHZ_CHAN */
616 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
617 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
618 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
619 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
620 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
621 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
622 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
623 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
624 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
625 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
626 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
627 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
628 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
629 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
630 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
631 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
632 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
633 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
634 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
635 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
636 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
637 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
638 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
639 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
640 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
641 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
642 #ifdef WLAN_FEATURE_DSRC
643 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
644 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
645 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
646 #endif
647 	[CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160},
648 #ifdef WLAN_FEATURE_DSRC
649 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
650 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
651 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
652 #endif
653 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
654 #ifdef WLAN_FEATURE_DSRC
655 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
656 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
657 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
658 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
659 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
660 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
661 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
662 #endif /* WLAN_FEATURE_DSRC */
663 #ifdef CONFIG_BAND_6GHZ
664 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
665 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
666 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
667 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
668 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
669 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
670 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
671 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
672 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
673 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
674 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
675 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
676 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
677 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
678 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
679 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
680 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
681 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
682 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
683 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
684 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
685 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
686 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
687 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
688 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
689 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
690 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
691 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
692 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
693 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
694 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
695 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
696 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
697 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
698 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
699 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
700 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
701 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
702 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
703 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
704 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
705 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
706 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
707 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
708 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
709 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
710 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
711 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
712 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
713 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
714 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
715 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
716 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
717 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
718 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
719 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
720 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
721 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
722 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
723 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
724 #endif /* CONFIG_BAND_6GHZ */
725 };
726 
727 const struct chan_map channel_map_global[NUM_CHANNELS] = {
728 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
729 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
730 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
731 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
732 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
733 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
734 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
735 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
736 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
737 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
738 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
739 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
740 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
741 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
742 #ifdef CONFIG_49GHZ_CHAN
743 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
744 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
745 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
746 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
747 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
748 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
749 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
750 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
751 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
752 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
753 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
754 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
755 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
756 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
757 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
758 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
759 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
760 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
761 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
762 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
763 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
764 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
765 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
766 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
767 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
768 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
769 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
770 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
771 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
772 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
773 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
774 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
775 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
776 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
777 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
778 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
779 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
780 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
781 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
782 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
783 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
784 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
785 #endif /* CONFIG_49GHZ_CHAN */
786 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
787 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
788 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
789 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
790 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
791 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
792 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
793 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
794 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
795 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
796 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
797 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
798 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
799 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
800 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
801 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
802 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
803 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
804 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
805 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
806 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
807 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
808 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
809 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
810 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
811 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
812 #ifdef WLAN_FEATURE_DSRC
813 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
814 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
815 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
816 #endif
817 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
818 #ifdef WLAN_FEATURE_DSRC
819 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
820 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
821 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
822 #endif
823 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
824 #ifdef WLAN_FEATURE_DSRC
825 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
826 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
827 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
828 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
829 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
830 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
831 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
832 #endif /* WLAN_FEATURE_DSRC */
833 #ifdef CONFIG_BAND_6GHZ
834 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
835 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
836 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
837 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
838 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
839 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
840 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
841 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
842 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
843 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
844 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
845 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
846 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
847 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
848 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
849 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
850 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
851 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
852 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
853 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
854 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
855 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
856 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
857 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
858 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
859 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
860 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
861 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
862 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
863 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
864 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
865 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
866 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
867 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
868 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
869 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
870 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
871 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
872 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
873 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
874 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
875 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
876 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
877 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
878 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
879 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
880 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
881 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
882 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
883 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
884 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
885 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
886 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
887 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
888 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
889 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
890 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
891 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
892 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
893 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
894 #endif /* CONFIG_BAND_6GHZ */
895 };
896 
897 const struct chan_map channel_map_china[NUM_CHANNELS] = {
898 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
899 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
900 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
901 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
902 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
903 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
904 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
905 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
906 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
907 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
908 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
909 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
910 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
911 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
912 #ifdef CONFIG_49GHZ_CHAN
913 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
914 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
915 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
916 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
917 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
918 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
919 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
920 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
921 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
922 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
923 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
924 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
925 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
926 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
927 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
928 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
929 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
930 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
931 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
932 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
933 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
934 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
935 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
936 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
937 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
938 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
939 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
940 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
941 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
942 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
943 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
944 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
945 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
946 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
947 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
948 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
949 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
950 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
951 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
952 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
953 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
954 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
955 #endif /* CONFIG_49GHZ_CHAN */
956 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
957 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
958 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
959 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
960 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
961 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
962 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
963 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
964 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
965 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
966 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
967 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
968 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
969 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
970 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
971 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
972 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
973 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
974 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
975 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
976 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
977 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
978 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
979 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
980 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
981 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
982 #ifdef WLAN_FEATURE_DSRC
983 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
984 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
985 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
986 #endif
987 	[CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160},
988 #ifdef WLAN_FEATURE_DSRC
989 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
990 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
991 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
992 #endif
993 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
994 #ifdef WLAN_FEATURE_DSRC
995 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
996 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
997 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
998 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
999 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
1000 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
1001 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
1002 #endif /* WLAN_FEATURE_DSRC */
1003 #ifdef CONFIG_BAND_6GHZ
1004 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
1005 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
1006 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
1007 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
1008 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
1009 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
1010 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
1011 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
1012 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
1013 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
1014 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
1015 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
1016 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
1017 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
1018 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
1019 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
1020 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
1021 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
1022 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
1023 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
1024 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
1025 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
1026 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
1027 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
1028 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
1029 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
1030 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
1031 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
1032 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
1033 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
1034 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
1035 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
1036 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
1037 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
1038 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
1039 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
1040 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
1041 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
1042 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
1043 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
1044 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
1045 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
1046 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
1047 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
1048 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
1049 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
1050 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
1051 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
1052 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
1053 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
1054 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
1055 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
1056 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
1057 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
1058 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
1059 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
1060 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
1061 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
1062 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
1063 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
1064 #endif /* CONFIG_BAND_6GHZ */
1065 };
1066 
1067 void reg_init_channel_map(enum dfs_reg dfs_region)
1068 {
1069 	switch (dfs_region) {
1070 	case DFS_UNINIT_REGION:
1071 	case DFS_UNDEF_REGION:
1072 		channel_map = channel_map_global;
1073 		break;
1074 	case DFS_FCC_REGION:
1075 		channel_map = channel_map_us;
1076 		break;
1077 	case DFS_ETSI_REGION:
1078 		channel_map = channel_map_eu;
1079 		break;
1080 	case DFS_MKK_REGION:
1081 	case DFS_MKKN_REGION:
1082 		channel_map = channel_map_jp;
1083 		break;
1084 	case DFS_CN_REGION:
1085 		channel_map = channel_map_china;
1086 		break;
1087 	case DFS_KR_REGION:
1088 		channel_map = channel_map_global;
1089 		break;
1090 	}
1091 }
1092 
1093 #ifdef WLAN_FEATURE_11BE
1094 uint16_t reg_get_bw_value(enum phy_ch_width bw)
1095 {
1096 	switch (bw) {
1097 	case CH_WIDTH_20MHZ:
1098 		return 20;
1099 	case CH_WIDTH_40MHZ:
1100 		return 40;
1101 	case CH_WIDTH_80MHZ:
1102 		return 80;
1103 	case CH_WIDTH_160MHZ:
1104 		return 160;
1105 	case CH_WIDTH_80P80MHZ:
1106 		return 160;
1107 	case CH_WIDTH_INVALID:
1108 		return 0;
1109 	case CH_WIDTH_5MHZ:
1110 		return 5;
1111 	case CH_WIDTH_10MHZ:
1112 		return 10;
1113 	case CH_WIDTH_320MHZ:
1114 	case CH_WIDTH_MAX:
1115 		return 320;
1116 	default:
1117 		return 0;
1118 	}
1119 }
1120 #else
1121 uint16_t reg_get_bw_value(enum phy_ch_width bw)
1122 {
1123 	switch (bw) {
1124 	case CH_WIDTH_20MHZ:
1125 		return 20;
1126 	case CH_WIDTH_40MHZ:
1127 		return 40;
1128 	case CH_WIDTH_80MHZ:
1129 		return 80;
1130 	case CH_WIDTH_160MHZ:
1131 		return 160;
1132 	case CH_WIDTH_80P80MHZ:
1133 		return 160;
1134 	case CH_WIDTH_INVALID:
1135 		return 0;
1136 	case CH_WIDTH_5MHZ:
1137 		return 5;
1138 	case CH_WIDTH_10MHZ:
1139 		return 10;
1140 	case CH_WIDTH_MAX:
1141 		return 160;
1142 	default:
1143 		return 0;
1144 	}
1145 }
1146 #endif
1147 
1148 struct wlan_lmac_if_reg_tx_ops *reg_get_psoc_tx_ops(
1149 		struct wlan_objmgr_psoc *psoc)
1150 {
1151 	struct wlan_lmac_if_tx_ops *tx_ops;
1152 
1153 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
1154 	if (!tx_ops) {
1155 		reg_err("tx_ops is NULL");
1156 		return NULL;
1157 	}
1158 
1159 	return &tx_ops->reg_ops;
1160 }
1161 
1162 /**
1163  * reg_combine_channel_states() - Get minimum of channel state1 and state2
1164  * @chan_state1: Channel state1
1165  * @chan_state2: Channel state2
1166  *
1167  * Return: Channel state
1168  */
1169 enum channel_state reg_combine_channel_states(enum channel_state chan_state1,
1170 					      enum channel_state chan_state2)
1171 {
1172 	if ((chan_state1 == CHANNEL_STATE_INVALID) ||
1173 	    (chan_state2 == CHANNEL_STATE_INVALID))
1174 		return CHANNEL_STATE_INVALID;
1175 	else
1176 		return min(chan_state1, chan_state2);
1177 }
1178 
1179 QDF_STATUS reg_read_default_country(struct wlan_objmgr_psoc *psoc,
1180 				    uint8_t *country_code)
1181 {
1182 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1183 
1184 	if (!country_code) {
1185 		reg_err("country_code is NULL");
1186 		return QDF_STATUS_E_INVAL;
1187 	}
1188 
1189 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1190 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1191 		reg_err("psoc reg component is NULL");
1192 		return QDF_STATUS_E_INVAL;
1193 	}
1194 
1195 	qdf_mem_copy(country_code, psoc_priv_obj->def_country,
1196 		     REG_ALPHA2_LEN + 1);
1197 
1198 	return QDF_STATUS_SUCCESS;
1199 }
1200 
1201 QDF_STATUS reg_get_max_5g_bw_from_country_code(uint16_t cc,
1202 					       uint16_t *max_bw_5g)
1203 {
1204 	uint16_t i;
1205 	int num_countries;
1206 
1207 	*max_bw_5g = 0;
1208 	reg_get_num_countries(&num_countries);
1209 
1210 	for (i = 0; i < num_countries; i++) {
1211 		if (g_all_countries[i].country_code == cc)
1212 			break;
1213 	}
1214 
1215 	if (i == num_countries)
1216 		return QDF_STATUS_E_FAILURE;
1217 
1218 	*max_bw_5g = g_all_countries[i].max_bw_5g;
1219 
1220 	return QDF_STATUS_SUCCESS;
1221 }
1222 
1223 QDF_STATUS reg_get_max_5g_bw_from_regdomain(uint16_t regdmn,
1224 					    uint16_t *max_bw_5g)
1225 {
1226 	uint16_t i;
1227 	int num_reg_dmn;
1228 
1229 	*max_bw_5g = 0;
1230 	reg_get_num_reg_dmn_pairs(&num_reg_dmn);
1231 
1232 	for (i = 0; i < num_reg_dmn; i++) {
1233 		if (g_reg_dmn_pairs[i].reg_dmn_pair_id == regdmn)
1234 			break;
1235 	}
1236 
1237 	if (i == num_reg_dmn)
1238 		return QDF_STATUS_E_FAILURE;
1239 
1240 	*max_bw_5g = regdomains_5g[g_reg_dmn_pairs[i].dmn_id_5g].max_bw;
1241 
1242 	return QDF_STATUS_SUCCESS;
1243 }
1244 
1245 void reg_get_current_dfs_region(struct wlan_objmgr_pdev *pdev,
1246 				enum dfs_reg *dfs_reg)
1247 {
1248 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1249 
1250 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1251 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1252 		reg_err("reg component pdev priv is NULL");
1253 		return;
1254 	}
1255 
1256 	*dfs_reg = pdev_priv_obj->dfs_region;
1257 }
1258 
1259 void reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
1260 			enum dfs_reg dfs_reg)
1261 {
1262 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1263 
1264 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1265 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1266 		reg_err("psoc reg component is NULL");
1267 		return;
1268 	}
1269 
1270 	pdev_priv_obj->dfs_region = dfs_reg;
1271 
1272 	reg_init_channel_map(dfs_reg);
1273 }
1274 
1275 uint8_t reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
1276 			 qdf_freq_t freq)
1277 {
1278 	uint32_t count;
1279 	struct regulatory_channel *chan_list;
1280 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1281 
1282 	if (freq == 0) {
1283 		reg_err_rl("Invalid freq %d", freq);
1284 		return 0;
1285 	}
1286 
1287 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1288 
1289 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1290 		reg_err("reg pdev priv obj is NULL");
1291 		return 0;
1292 	}
1293 
1294 	chan_list = pdev_priv_obj->mas_chan_list;
1295 	for (count = 0; count < NUM_CHANNELS; count++) {
1296 		if (chan_list[count].center_freq >= freq)
1297 			break;
1298 	}
1299 
1300 	if (count == NUM_CHANNELS)
1301 		goto end;
1302 
1303 	if (chan_list[count].center_freq == freq)
1304 		return chan_list[count].chan_num;
1305 
1306 	if (count == 0)
1307 		goto end;
1308 
1309 	if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) ||
1310 	    (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) {
1311 		reg_err("Frequency %d invalid in current reg domain", freq);
1312 		return 0;
1313 	}
1314 
1315 	return (chan_list[count - 1].chan_num +
1316 		(freq - chan_list[count - 1].center_freq) / 5);
1317 
1318 end:
1319 	reg_err_rl("invalid frequency %d", freq);
1320 	return 0;
1321 }
1322 
1323 static uint16_t reg_compute_chan_to_freq(struct wlan_objmgr_pdev *pdev,
1324 					 uint8_t chan_num,
1325 					 enum channel_enum min_chan_range,
1326 					 enum channel_enum max_chan_range)
1327 {
1328 	uint16_t count;
1329 	struct regulatory_channel *chan_list;
1330 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1331 
1332 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1333 
1334 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1335 		reg_err("reg pdev priv obj is NULL");
1336 		return 0;
1337 	}
1338 
1339 	if (min_chan_range < MIN_CHANNEL || max_chan_range > MAX_CHANNEL) {
1340 		reg_err_rl("Channel range is invalid");
1341 		return 0;
1342 	}
1343 
1344 	chan_list = pdev_priv_obj->mas_chan_list;
1345 
1346 	for (count = min_chan_range; count <= max_chan_range; count++) {
1347 		if ((chan_list[count].state != CHANNEL_STATE_DISABLE) &&
1348 		    !(chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED)) {
1349 			if (REG_IS_49GHZ_FREQ(chan_list[count].center_freq)) {
1350 				if (chan_list[count].chan_num == chan_num)
1351 					break;
1352 				continue;
1353 			} else if ((chan_list[count].chan_num >= chan_num) &&
1354 				   (chan_list[count].chan_num !=
1355 							INVALID_CHANNEL_NUM))
1356 				break;
1357 		}
1358 	}
1359 
1360 	if (count == max_chan_range + 1)
1361 		goto end;
1362 
1363 	if (chan_list[count].chan_num == chan_num) {
1364 		if (chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED)
1365 			reg_err("Channel %d disabled in current reg domain",
1366 				chan_num);
1367 		return chan_list[count].center_freq;
1368 	}
1369 
1370 	if (count == min_chan_range)
1371 		goto end;
1372 
1373 	if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) ||
1374 	    REG_IS_49GHZ_FREQ(chan_list[count - 1].center_freq) ||
1375 	    (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) {
1376 		reg_err("Channel %d invalid in current reg domain",
1377 			chan_num);
1378 		return 0;
1379 	}
1380 
1381 	return (chan_list[count - 1].center_freq +
1382 		(chan_num - chan_list[count - 1].chan_num) * 5);
1383 
1384 end:
1385 
1386 	reg_debug_rl("Invalid channel %d", chan_num);
1387 	return 0;
1388 }
1389 
1390 uint16_t reg_legacy_chan_to_freq(struct wlan_objmgr_pdev *pdev,
1391 				 uint8_t chan_num)
1392 {
1393 	uint16_t min_chan_range = MIN_24GHZ_CHANNEL;
1394 	uint16_t max_chan_range = MAX_5GHZ_CHANNEL;
1395 
1396 	if (chan_num == 0) {
1397 		reg_err_rl("Invalid channel %d", chan_num);
1398 		return 0;
1399 	}
1400 
1401 	return reg_compute_chan_to_freq(pdev, chan_num,
1402 					min_chan_range,
1403 					max_chan_range);
1404 }
1405 
1406 QDF_STATUS reg_program_default_cc(struct wlan_objmgr_pdev *pdev,
1407 				  uint16_t regdmn)
1408 {
1409 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1410 	struct cur_regulatory_info *reg_info;
1411 	uint16_t cc = -1;
1412 	uint16_t country_index = -1, regdmn_pair = -1;
1413 	struct wlan_objmgr_psoc *psoc;
1414 	QDF_STATUS err;
1415 
1416 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1417 	if (!pdev_priv_obj) {
1418 		reg_err("reg soc is NULL");
1419 		return QDF_STATUS_E_FAILURE;
1420 	}
1421 
1422 	reg_info = (struct cur_regulatory_info *)qdf_mem_malloc
1423 		(sizeof(struct cur_regulatory_info));
1424 	if (!reg_info)
1425 		return QDF_STATUS_E_NOMEM;
1426 
1427 	psoc = wlan_pdev_get_psoc(pdev);
1428 	if (!psoc) {
1429 		reg_err("psoc is NULL");
1430 		return QDF_STATUS_E_INVAL;
1431 	}
1432 
1433 	reg_info->psoc = psoc;
1434 	reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1435 	reg_info->num_phy = 1;
1436 
1437 	if (regdmn == 0) {
1438 		reg_get_default_country(&regdmn);
1439 		regdmn |= COUNTRY_ERD_FLAG;
1440 	}
1441 
1442 	if (regdmn & COUNTRY_ERD_FLAG) {
1443 		cc = regdmn & ~COUNTRY_ERD_FLAG;
1444 
1445 		reg_get_rdpair_from_country_code(cc,
1446 						 &country_index,
1447 						 &regdmn_pair);
1448 
1449 		err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1450 		if (err == QDF_STATUS_E_FAILURE) {
1451 			reg_err("Unable to set country code\n");
1452 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1453 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1454 			qdf_mem_free(reg_info);
1455 			return QDF_STATUS_E_FAILURE;
1456 		}
1457 
1458 		pdev_priv_obj->ctry_code = cc;
1459 
1460 	} else {
1461 		reg_get_rdpair_from_regdmn_id(regdmn, &regdmn_pair);
1462 
1463 		err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1464 		if (err == QDF_STATUS_E_FAILURE) {
1465 			reg_err("Unable to set country code\n");
1466 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1467 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1468 			qdf_mem_free(reg_info);
1469 			return QDF_STATUS_E_FAILURE;
1470 		}
1471 
1472 		pdev_priv_obj->reg_dmn_pair = regdmn;
1473 	}
1474 
1475 	reg_info->offload_enabled = false;
1476 	reg_process_master_chan_list(reg_info);
1477 
1478 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
1479 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
1480 	qdf_mem_free(reg_info);
1481 
1482 	return QDF_STATUS_SUCCESS;
1483 }
1484 
1485 QDF_STATUS reg_program_chan_list(struct wlan_objmgr_pdev *pdev,
1486 				 struct cc_regdmn_s *rd)
1487 {
1488 	struct cur_regulatory_info *reg_info;
1489 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1490 	uint16_t country_index = -1, regdmn_pair = -1;
1491 	struct wlan_objmgr_psoc *psoc;
1492 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
1493 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1494 	uint8_t pdev_id;
1495 	uint8_t phy_id;
1496 	QDF_STATUS err;
1497 
1498 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1499 	if (!pdev_priv_obj) {
1500 		reg_err(" pdev priv obj is NULL");
1501 		return QDF_STATUS_E_FAILURE;
1502 	}
1503 
1504 	psoc = wlan_pdev_get_psoc(pdev);
1505 	if (!psoc) {
1506 		reg_err("psoc is NULL");
1507 		return QDF_STATUS_E_INVAL;
1508 	}
1509 
1510 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1511 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1512 		reg_err("psoc reg component is NULL");
1513 		return QDF_STATUS_E_FAILURE;
1514 	}
1515 
1516 	if (psoc_priv_obj->offload_enabled) {
1517 		if ((rd->flags == ALPHA_IS_SET) && (rd->cc.alpha[2] == 'O'))
1518 			pdev_priv_obj->indoor_chan_enabled = false;
1519 		else
1520 			pdev_priv_obj->indoor_chan_enabled = true;
1521 
1522 		pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1523 		tx_ops = reg_get_psoc_tx_ops(psoc);
1524 
1525 		if (tx_ops->get_phy_id_from_pdev_id)
1526 			tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
1527 		else
1528 			phy_id = pdev_id;
1529 
1530 		if (tx_ops->set_user_country_code) {
1531 			psoc_priv_obj->new_init_ctry_pending[phy_id] = true;
1532 			return tx_ops->set_user_country_code(psoc, pdev_id, rd);
1533 		}
1534 
1535 		return QDF_STATUS_E_FAILURE;
1536 	}
1537 
1538 	reg_info = (struct cur_regulatory_info *)qdf_mem_malloc
1539 		(sizeof(struct cur_regulatory_info));
1540 	if (!reg_info)
1541 		return QDF_STATUS_E_NOMEM;
1542 
1543 	reg_info->psoc = psoc;
1544 	reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1545 
1546 	if (rd->flags == CC_IS_SET) {
1547 		reg_get_rdpair_from_country_code(rd->cc.country_code,
1548 						 &country_index,
1549 						 &regdmn_pair);
1550 	} else if (rd->flags == ALPHA_IS_SET) {
1551 		reg_get_rdpair_from_country_iso(rd->cc.alpha,
1552 						&country_index,
1553 						&regdmn_pair);
1554 	} else if (rd->flags == REGDMN_IS_SET) {
1555 		reg_get_rdpair_from_regdmn_id(rd->cc.regdmn.reg_2g_5g_pair_id,
1556 					      &regdmn_pair);
1557 	}
1558 
1559 	err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1560 	if (err == QDF_STATUS_E_FAILURE) {
1561 		reg_err("Unable to set country code\n");
1562 		qdf_mem_free(reg_info->reg_rules_2g_ptr);
1563 		qdf_mem_free(reg_info->reg_rules_5g_ptr);
1564 		qdf_mem_free(reg_info);
1565 		return QDF_STATUS_E_FAILURE;
1566 	}
1567 
1568 	reg_info->offload_enabled = false;
1569 	reg_process_master_chan_list(reg_info);
1570 
1571 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
1572 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
1573 	qdf_mem_free(reg_info);
1574 
1575 	return QDF_STATUS_SUCCESS;
1576 }
1577 
1578 QDF_STATUS reg_get_current_cc(struct wlan_objmgr_pdev *pdev,
1579 			      struct cc_regdmn_s *rd)
1580 {
1581 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1582 
1583 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1584 	if (!pdev_priv_obj) {
1585 		reg_err("reg pdev priv is NULL");
1586 		return QDF_STATUS_E_FAILURE;
1587 	}
1588 
1589 	if (rd->flags == CC_IS_SET) {
1590 		rd->cc.country_code = pdev_priv_obj->ctry_code;
1591 	} else if (rd->flags == ALPHA_IS_SET) {
1592 		qdf_mem_copy(rd->cc.alpha, pdev_priv_obj->current_country,
1593 			     sizeof(rd->cc.alpha));
1594 	} else if (rd->flags == REGDMN_IS_SET) {
1595 		rd->cc.regdmn.reg_2g_5g_pair_id = pdev_priv_obj->reg_dmn_pair;
1596 		rd->cc.regdmn.sixg_superdmn_id = pdev_priv_obj->reg_6g_superid;
1597 	}
1598 
1599 	return QDF_STATUS_SUCCESS;
1600 }
1601 
1602 QDF_STATUS reg_set_regdb_offloaded(struct wlan_objmgr_psoc *psoc, bool val)
1603 {
1604 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1605 
1606 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1607 
1608 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1609 		reg_err("psoc reg component is NULL");
1610 		return QDF_STATUS_E_FAILURE;
1611 	}
1612 
1613 	psoc_priv_obj->offload_enabled = val;
1614 
1615 	return QDF_STATUS_SUCCESS;
1616 }
1617 
1618 QDF_STATUS reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
1619 				  struct cur_regdmn_info *cur_regdmn)
1620 {
1621 	struct wlan_objmgr_psoc *psoc;
1622 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1623 	uint16_t index;
1624 	int num_reg_dmn;
1625 	uint8_t phy_id;
1626 	uint8_t pdev_id;
1627 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
1628 
1629 	psoc = wlan_pdev_get_psoc(pdev);
1630 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1631 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1632 		reg_err("soc reg component is NULL");
1633 		return QDF_STATUS_E_INVAL;
1634 	}
1635 
1636 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1637 
1638 	tx_ops = reg_get_psoc_tx_ops(psoc);
1639 	if (tx_ops->get_phy_id_from_pdev_id)
1640 		tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
1641 	else
1642 		phy_id = pdev_id;
1643 
1644 	cur_regdmn->regdmn_pair_id =
1645 		psoc_priv_obj->mas_chan_params[phy_id].reg_dmn_pair;
1646 
1647 	reg_get_num_reg_dmn_pairs(&num_reg_dmn);
1648 	for (index = 0; index < num_reg_dmn; index++) {
1649 		if (g_reg_dmn_pairs[index].reg_dmn_pair_id ==
1650 				cur_regdmn->regdmn_pair_id)
1651 			break;
1652 	}
1653 
1654 	if (index == num_reg_dmn) {
1655 		reg_debug_rl("invalid regdomain");
1656 		return QDF_STATUS_E_FAILURE;
1657 	}
1658 
1659 	cur_regdmn->dmn_id_2g = g_reg_dmn_pairs[index].dmn_id_2g;
1660 	cur_regdmn->dmn_id_5g = g_reg_dmn_pairs[index].dmn_id_5g;
1661 	cur_regdmn->ctl_2g = regdomains_2g[cur_regdmn->dmn_id_2g].ctl_val;
1662 	cur_regdmn->ctl_5g = regdomains_5g[cur_regdmn->dmn_id_5g].ctl_val;
1663 	cur_regdmn->dfs_region =
1664 		regdomains_5g[cur_regdmn->dmn_id_5g].dfs_region;
1665 
1666 	return QDF_STATUS_SUCCESS;
1667 }
1668 
1669 QDF_STATUS reg_modify_chan_144(struct wlan_objmgr_pdev *pdev,
1670 			       bool enable_ch_144)
1671 {
1672 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1673 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1674 	struct wlan_objmgr_psoc *psoc;
1675 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
1676 	QDF_STATUS status;
1677 
1678 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1679 
1680 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1681 		reg_err("pdev reg component is NULL");
1682 		return QDF_STATUS_E_INVAL;
1683 	}
1684 
1685 	if (pdev_priv_obj->en_chan_144 == enable_ch_144) {
1686 		reg_info("chan 144 is already  %d", enable_ch_144);
1687 		return QDF_STATUS_SUCCESS;
1688 	}
1689 
1690 	psoc = wlan_pdev_get_psoc(pdev);
1691 	if (!psoc) {
1692 		reg_err("psoc is NULL");
1693 		return QDF_STATUS_E_INVAL;
1694 	}
1695 
1696 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1697 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1698 		reg_err("psoc reg component is NULL");
1699 		return QDF_STATUS_E_INVAL;
1700 	}
1701 
1702 	reg_debug("setting chan 144: %d", enable_ch_144);
1703 	pdev_priv_obj->en_chan_144 = enable_ch_144;
1704 
1705 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
1706 
1707 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
1708 	if (reg_tx_ops->fill_umac_legacy_chanlist)
1709 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
1710 				pdev_priv_obj->cur_chan_list);
1711 
1712 	status = reg_send_scheduler_msg_sb(psoc, pdev);
1713 
1714 	return status;
1715 }
1716 
1717 bool reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev)
1718 {
1719 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1720 
1721 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1722 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1723 		reg_err("pdev reg component is NULL");
1724 		return false;
1725 	}
1726 
1727 	return pdev_priv_obj->en_chan_144;
1728 }
1729 
1730 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_get_hal_reg_cap(
1731 						struct wlan_objmgr_psoc *psoc)
1732 {
1733 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1734 
1735 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1736 
1737 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1738 		reg_err("psoc reg component is NULL");
1739 		return NULL;
1740 	}
1741 
1742 	return psoc_priv_obj->reg_cap;
1743 }
1744 
1745 QDF_STATUS reg_set_hal_reg_cap(
1746 		struct wlan_objmgr_psoc *psoc,
1747 		struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap,
1748 		uint16_t phy_cnt)
1749 {
1750 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1751 
1752 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1753 
1754 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1755 		reg_err("psoc reg component is NULL");
1756 		return QDF_STATUS_E_FAILURE;
1757 	}
1758 
1759 	if (phy_cnt > PSOC_MAX_PHY_REG_CAP) {
1760 		reg_err("phy cnt:%d is more than %d", phy_cnt,
1761 			PSOC_MAX_PHY_REG_CAP);
1762 		return QDF_STATUS_E_FAILURE;
1763 	}
1764 
1765 	qdf_mem_copy(psoc_priv_obj->reg_cap, reg_cap,
1766 		     phy_cnt *
1767 		     sizeof(struct wlan_psoc_host_hal_reg_capabilities_ext));
1768 
1769 	return QDF_STATUS_SUCCESS;
1770 }
1771 
1772 QDF_STATUS reg_update_hal_reg_cap(struct wlan_objmgr_psoc *psoc,
1773 				  uint64_t wireless_modes, uint8_t phy_id)
1774 {
1775 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1776 
1777 	if (!psoc) {
1778 		reg_err("psoc is null");
1779 		return QDF_STATUS_E_FAILURE;
1780 	}
1781 
1782 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1783 
1784 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1785 		reg_err("psoc reg component is NULL");
1786 		return QDF_STATUS_E_FAILURE;
1787 	}
1788 
1789 	psoc_priv_obj->reg_cap[phy_id].wireless_modes |= wireless_modes;
1790 
1791 	return QDF_STATUS_SUCCESS;
1792 }
1793 
1794 bool reg_chan_in_range(struct regulatory_channel *chan_list,
1795 		       qdf_freq_t low_freq_2g, qdf_freq_t high_freq_2g,
1796 		       qdf_freq_t low_freq_5g, qdf_freq_t high_freq_5g,
1797 		       enum channel_enum ch_enum)
1798 {
1799 	uint32_t low_limit_2g = NUM_CHANNELS;
1800 	uint32_t high_limit_2g = NUM_CHANNELS;
1801 	uint32_t low_limit_5g = NUM_CHANNELS;
1802 	uint32_t high_limit_5g = NUM_CHANNELS;
1803 	bool chan_in_range;
1804 	enum channel_enum chan_enum;
1805 	uint16_t min_bw;
1806 	qdf_freq_t center_freq;
1807 
1808 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
1809 		min_bw = chan_list[chan_enum].min_bw;
1810 		center_freq = chan_list[chan_enum].center_freq;
1811 
1812 		if ((center_freq - min_bw / 2) >= low_freq_2g) {
1813 			low_limit_2g = chan_enum;
1814 			break;
1815 		}
1816 	}
1817 
1818 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
1819 		min_bw = chan_list[chan_enum].min_bw;
1820 		center_freq = chan_list[chan_enum].center_freq;
1821 
1822 		if ((center_freq - min_bw / 2) >= low_freq_5g) {
1823 			low_limit_5g = chan_enum;
1824 			break;
1825 		}
1826 	}
1827 
1828 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
1829 		min_bw = chan_list[chan_enum].min_bw;
1830 		center_freq = chan_list[chan_enum].center_freq;
1831 
1832 		if (center_freq + min_bw / 2 <= high_freq_2g) {
1833 			high_limit_2g = chan_enum;
1834 			break;
1835 		}
1836 		if (chan_enum == 0)
1837 			break;
1838 	}
1839 
1840 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
1841 		min_bw = chan_list[chan_enum].min_bw;
1842 		center_freq = chan_list[chan_enum].center_freq;
1843 
1844 		if (center_freq + min_bw / 2 <= high_freq_5g) {
1845 			high_limit_5g = chan_enum;
1846 			break;
1847 		}
1848 		if (chan_enum == 0)
1849 			break;
1850 	}
1851 
1852 	chan_in_range = false;
1853 	if  ((low_limit_2g <= ch_enum) &&
1854 	     (high_limit_2g >= ch_enum) &&
1855 	     (low_limit_2g != NUM_CHANNELS) &&
1856 	     (high_limit_2g != NUM_CHANNELS))
1857 		chan_in_range = true;
1858 	if  ((low_limit_5g <= ch_enum) &&
1859 	     (high_limit_5g >= ch_enum) &&
1860 	     (low_limit_5g != NUM_CHANNELS) &&
1861 	     (high_limit_5g != NUM_CHANNELS))
1862 		chan_in_range = true;
1863 
1864 	if (chan_in_range)
1865 		return true;
1866 	else
1867 		return false;
1868 }
1869 
1870 bool reg_is_24ghz_ch_freq(uint32_t freq)
1871 {
1872 	return REG_IS_24GHZ_CH_FREQ(freq);
1873 }
1874 
1875 bool reg_is_5ghz_ch_freq(uint32_t freq)
1876 {
1877 	return REG_IS_5GHZ_FREQ(freq);
1878 }
1879 
1880 /**
1881  * BAND_2G_PRESENT() - Check if REG_BAND_2G is set in the band_mask
1882  * @band_mask: Bitmask for bands
1883  *
1884  * Return: True if REG_BAND_2G is set in the band_mask, else false
1885  */
1886 static inline bool BAND_2G_PRESENT(uint8_t band_mask)
1887 {
1888 	return !!(band_mask & (BIT(REG_BAND_2G)));
1889 }
1890 
1891 /**
1892  * BAND_5G_PRESENT() - Check if REG_BAND_5G is set in the band_mask
1893  * @band_mask: Bitmask for bands
1894  *
1895  * Return: True if REG_BAND_5G is set in the band_mask, else false
1896  */
1897 static inline bool BAND_5G_PRESENT(uint8_t band_mask)
1898 {
1899 	return !!(band_mask & (BIT(REG_BAND_5G)));
1900 }
1901 
1902 /**
1903  * reg_is_freq_in_between() - Check whether freq falls within low_freq and
1904  * high_freq, inclusively.
1905  * @low_freq - Low frequency.
1906  * @high_freq - High frequency.
1907  * @freq - Frequency to be checked.
1908  *
1909  * Return: True if freq falls within low_freq and high_freq, else false.
1910  */
1911 static bool reg_is_freq_in_between(qdf_freq_t low_freq, qdf_freq_t high_freq,
1912 				   qdf_freq_t freq)
1913 {
1914 	return (low_freq <= freq && freq <= high_freq);
1915 }
1916 
1917 static bool reg_is_ranges_overlap(qdf_freq_t low_freq, qdf_freq_t high_freq,
1918 				  qdf_freq_t start_edge_freq,
1919 				  qdf_freq_t end_edge_freq)
1920 {
1921 	return (reg_is_freq_in_between(start_edge_freq,
1922 				       end_edge_freq,
1923 				       low_freq) ||
1924 		reg_is_freq_in_between(start_edge_freq,
1925 				       end_edge_freq,
1926 				       high_freq) ||
1927 		reg_is_freq_in_between(low_freq,
1928 				       high_freq,
1929 				       start_edge_freq) ||
1930 		reg_is_freq_in_between(low_freq,
1931 				       high_freq,
1932 				       end_edge_freq));
1933 }
1934 
1935 bool reg_is_range_overlap_2g(qdf_freq_t low_freq, qdf_freq_t high_freq)
1936 {
1937 	return reg_is_ranges_overlap(low_freq, high_freq,
1938 				     TWO_GIG_STARTING_EDGE_FREQ,
1939 				     TWO_GIG_ENDING_EDGE_FREQ);
1940 }
1941 
1942 bool reg_is_range_overlap_5g(qdf_freq_t low_freq, qdf_freq_t high_freq)
1943 {
1944 	return reg_is_ranges_overlap(low_freq, high_freq,
1945 				     FIVE_GIG_STARTING_EDGE_FREQ,
1946 				     FIVE_GIG_ENDING_EDGE_FREQ);
1947 }
1948 
1949 bool reg_is_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
1950 {
1951 	struct regulatory_channel *cur_chan_list;
1952 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1953 	enum channel_enum chan_enum;
1954 
1955 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1956 
1957 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1958 		reg_err("reg pdev priv obj is NULL");
1959 		return false;
1960 	}
1961 
1962 	chan_enum = reg_get_chan_enum_for_freq(freq);
1963 
1964 	if (chan_enum == INVALID_CHANNEL) {
1965 		reg_err_rl("Invalid chan enum %d", chan_enum);
1966 		return false;
1967 	}
1968 
1969 	cur_chan_list = pdev_priv_obj->cur_chan_list;
1970 
1971 	return (cur_chan_list[chan_enum].chan_flags &
1972 		REGULATORY_CHAN_INDOOR_ONLY);
1973 }
1974 
1975 #ifdef CONFIG_REG_CLIENT
1976 bool reg_is_freq_indoor_in_secondary_list(struct wlan_objmgr_pdev *pdev,
1977 					  qdf_freq_t freq)
1978 {
1979 	struct regulatory_channel *secondary_cur_chan_list;
1980 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1981 	enum channel_enum chan_enum;
1982 
1983 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1984 
1985 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1986 		reg_err("reg pdev priv obj is NULL");
1987 		return false;
1988 	}
1989 
1990 	chan_enum = reg_get_chan_enum_for_freq(freq);
1991 
1992 	if (chan_enum == INVALID_CHANNEL) {
1993 		reg_err_rl("Invalid chan enum %d", chan_enum);
1994 		return false;
1995 	}
1996 
1997 	secondary_cur_chan_list = pdev_priv_obj->secondary_cur_chan_list;
1998 
1999 	return (secondary_cur_chan_list[chan_enum].chan_flags &
2000 		REGULATORY_CHAN_INDOOR_ONLY);
2001 }
2002 #endif
2003 
2004 #ifdef CONFIG_BAND_6GHZ
2005 bool reg_is_6ghz_chan_freq(uint16_t freq)
2006 {
2007 	return REG_IS_6GHZ_FREQ(freq);
2008 }
2009 
2010 #ifdef CONFIG_6G_FREQ_OVERLAP
2011 bool reg_is_range_overlap_6g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2012 {
2013 	return reg_is_ranges_overlap(low_freq, high_freq,
2014 				     SIX_GIG_STARTING_EDGE_FREQ,
2015 				     SIX_GIG_ENDING_EDGE_FREQ);
2016 }
2017 
2018 bool reg_is_range_only6g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2019 {
2020 	if (low_freq >= high_freq) {
2021 		reg_err_rl("Low freq is greater than or equal to high freq");
2022 		return false;
2023 	}
2024 
2025 	if (reg_is_range_overlap_6g(low_freq, high_freq) &&
2026 	    !reg_is_range_overlap_5g(low_freq, high_freq)) {
2027 		reg_debug_rl("The device is 6G only");
2028 		return true;
2029 	}
2030 
2031 	reg_debug_rl("The device is not 6G only");
2032 
2033 	return false;
2034 }
2035 #endif
2036 
2037 uint16_t reg_min_6ghz_chan_freq(void)
2038 {
2039 	return REG_MIN_6GHZ_CHAN_FREQ;
2040 }
2041 
2042 uint16_t reg_max_6ghz_chan_freq(void)
2043 {
2044 	return REG_MAX_6GHZ_CHAN_FREQ;
2045 }
2046 
2047 bool reg_is_6ghz_psc_chan_freq(uint16_t freq)
2048 {
2049 	if (!REG_IS_6GHZ_FREQ(freq)) {
2050 		reg_debug(" Channel frequency is not a 6GHz frequency");
2051 		return false;
2052 	}
2053 
2054 	if (!(((freq - SIX_GHZ_NON_ORPHAN_START_FREQ) + FREQ_LEFT_SHIFT) %
2055 	      (FREQ_TO_CHAN_SCALE * NUM_80MHZ_BAND_IN_6G))) {
2056 		return true;
2057 	}
2058 
2059 	reg_debug_rl("Channel freq %d MHz is not a 6GHz PSC frequency", freq);
2060 
2061 	return false;
2062 }
2063 
2064 bool reg_is_6g_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2065 {
2066 	return (REG_IS_6GHZ_FREQ(freq) && reg_is_freq_indoor(pdev, freq));
2067 }
2068 
2069 /**
2070  * reg_get_max_psd() - Get max PSD.
2071  * @freq: Channel frequency.
2072  * @bw: Channel bandwidth.
2073  * @reg_ap: Regulatory 6G AP type.
2074  * @reg_client: Regulatory 6G client type.
2075  * @tx_power: Pointer to tx-power.
2076  *
2077  * Return: Return QDF_STATUS_SUCCESS, if PSD is filled for 6G TPE IE
2078  * else return QDF_STATUS_E_FAILURE.
2079  */
2080 static QDF_STATUS reg_get_max_psd(qdf_freq_t freq,
2081 				  uint16_t bw,
2082 				  enum reg_6g_ap_type reg_ap,
2083 				  enum reg_6g_client_type reg_client,
2084 				  uint8_t *tx_power)
2085 {
2086 	if (reg_ap == REG_INDOOR_AP) {
2087 		switch (reg_client) {
2088 		case REG_DEFAULT_CLIENT:
2089 			*tx_power = REG_PSD_MAX_TXPOWER_FOR_DEFAULT_CLIENT;
2090 			return QDF_STATUS_SUCCESS;
2091 		case REG_SUBORDINATE_CLIENT:
2092 			*tx_power = REG_PSD_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT;
2093 			return QDF_STATUS_SUCCESS;
2094 		default:
2095 			reg_err_rl("Invalid client type");
2096 			return QDF_STATUS_E_FAILURE;
2097 		}
2098 	}
2099 
2100 	return QDF_STATUS_E_FAILURE;
2101 }
2102 
2103 /**
2104  * reg_get_max_txpower_for_eirp() - Get max EIRP.
2105  * @pdev: Pointer to pdev.
2106  * @freq: Channel frequency.
2107  * @bw: Channel bandwidth.
2108  * @reg_ap: Regulatory 6G AP type.
2109  * @reg_client: Regulatory client type.
2110  * @tx_power: Pointer to tx-power.
2111  *
2112  * Return: Return QDF_STATUS_SUCCESS, if EIRP is filled for 6G TPE IE
2113  * else return QDF_STATUS_E_FAILURE.
2114  */
2115 static QDF_STATUS reg_get_max_eirp(struct wlan_objmgr_pdev *pdev,
2116 				   qdf_freq_t freq,
2117 				   uint16_t bw,
2118 				   enum reg_6g_ap_type reg_ap,
2119 				   enum reg_6g_client_type reg_client,
2120 				   uint8_t *tx_power)
2121 {
2122 	if (reg_ap == REG_INDOOR_AP) {
2123 		switch (reg_client) {
2124 		case REG_DEFAULT_CLIENT:
2125 			*tx_power = reg_get_channel_reg_power_for_freq(pdev,
2126 								       freq);
2127 			return QDF_STATUS_SUCCESS;
2128 		case REG_SUBORDINATE_CLIENT:
2129 			*tx_power = REG_EIRP_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT;
2130 			return QDF_STATUS_SUCCESS;
2131 		default:
2132 			reg_err_rl("Invalid client type");
2133 			return QDF_STATUS_E_FAILURE;
2134 		}
2135 	}
2136 
2137 	return QDF_STATUS_E_FAILURE;
2138 }
2139 
2140 QDF_STATUS reg_get_max_txpower_for_6g_tpe(struct wlan_objmgr_pdev *pdev,
2141 					  qdf_freq_t freq, uint8_t bw,
2142 					  enum reg_6g_ap_type reg_ap,
2143 					  enum reg_6g_client_type reg_client,
2144 					  bool is_psd,
2145 					  uint8_t *tx_power)
2146 {
2147 	if (!REG_IS_6GHZ_FREQ(freq)) {
2148 		reg_err_rl("%d is not a 6G channel frequency", freq);
2149 		return QDF_STATUS_E_FAILURE;
2150 	}
2151 
2152 	/*
2153 	 * For now, there is support only for Indoor AP and we have only
2154 	 * LPI power values.
2155 	 */
2156 	if (is_psd)
2157 		return reg_get_max_psd(freq, bw, reg_ap, reg_client, tx_power);
2158 
2159 	return reg_get_max_eirp(pdev, freq, bw, reg_ap, reg_client, tx_power);
2160 }
2161 
2162 /**
2163  * BAND_6G_PRESENT() - Check if REG_BAND_6G is set in the band_mask
2164  * @band_mask: Bitmask for bands
2165  *
2166  * Return: True if REG_BAND_6G is set in the band_mask, else false
2167  */
2168 static inline bool BAND_6G_PRESENT(uint8_t band_mask)
2169 {
2170 	return !!(band_mask & (BIT(REG_BAND_6G)));
2171 }
2172 #else
2173 static inline bool BAND_6G_PRESENT(uint8_t band_mask)
2174 {
2175 	return false;
2176 }
2177 #endif /* CONFIG_BAND_6GHZ */
2178 
2179 /**
2180  * reg_get_band_from_cur_chan_list() - Get channel list and number of channels
2181  * @pdev: pdev ptr
2182  * @band_mask: Input bitmap with band set
2183  * @channel_list: Pointer to Channel List
2184  * @cur_chan_list: Pointer to primary current channel list for non-beaconing
2185  * entites (STA, p2p client) and secondary channel list for beaconing entities
2186  * (SAP, p2p GO)
2187  *
2188  * Get the given channel list and number of channels from the current channel
2189  * list based on input band bitmap.
2190  *
2191  * Return: Number of channels, else 0 to indicate error
2192  */
2193 static uint16_t
2194 reg_get_band_from_cur_chan_list(struct wlan_objmgr_pdev *pdev,
2195 				uint8_t band_mask,
2196 				struct regulatory_channel *channel_list,
2197 				struct regulatory_channel *cur_chan_list)
2198 {
2199 	uint16_t i, num_channels = 0;
2200 
2201 	if (BAND_2G_PRESENT(band_mask)) {
2202 		for (i = MIN_24GHZ_CHANNEL; i <= MAX_24GHZ_CHANNEL; i++) {
2203 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2204 			    !(cur_chan_list[i].chan_flags &
2205 			      REGULATORY_CHAN_DISABLED)) {
2206 				channel_list[num_channels] = cur_chan_list[i];
2207 				num_channels++;
2208 			}
2209 		}
2210 	}
2211 	if (BAND_5G_PRESENT(band_mask)) {
2212 		for (i = BAND_5GHZ_START_CHANNEL; i <= MAX_5GHZ_CHANNEL; i++) {
2213 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2214 			    !(cur_chan_list[i].chan_flags &
2215 			      REGULATORY_CHAN_DISABLED)) {
2216 				channel_list[num_channels] = cur_chan_list[i];
2217 				num_channels++;
2218 			}
2219 		}
2220 	}
2221 	if (BAND_6G_PRESENT(band_mask)) {
2222 		for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) {
2223 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2224 			    !(cur_chan_list[i].chan_flags &
2225 			      REGULATORY_CHAN_DISABLED)) {
2226 				channel_list[num_channels] = cur_chan_list[i];
2227 				num_channels++;
2228 			}
2229 		}
2230 	}
2231 
2232 	if (!num_channels) {
2233 		reg_err("Failed to retrieve the channel list");
2234 		return 0;
2235 	}
2236 
2237 	return num_channels;
2238 }
2239 
2240 uint16_t
2241 reg_get_band_channel_list(struct wlan_objmgr_pdev *pdev,
2242 			  uint8_t band_mask,
2243 			  struct regulatory_channel *channel_list)
2244 {
2245 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2246 
2247 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2248 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2249 		reg_err("reg pdev priv obj is NULL");
2250 		return 0;
2251 	}
2252 
2253 	return reg_get_band_from_cur_chan_list(pdev, band_mask, channel_list,
2254 					       pdev_priv_obj->cur_chan_list);
2255 }
2256 
2257 #ifdef CONFIG_REG_CLIENT
2258 uint16_t
2259 reg_get_secondary_band_channel_list(struct wlan_objmgr_pdev *pdev,
2260 				    uint8_t band_mask,
2261 				    struct regulatory_channel *channel_list)
2262 {
2263 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2264 
2265 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2266 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2267 		reg_err("reg pdev priv obj is NULL");
2268 		return 0;
2269 	}
2270 
2271 	return reg_get_band_from_cur_chan_list(
2272 				pdev, band_mask, channel_list,
2273 				pdev_priv_obj->secondary_cur_chan_list);
2274 }
2275 #endif
2276 
2277 qdf_freq_t reg_chan_band_to_freq(struct wlan_objmgr_pdev *pdev,
2278 				 uint8_t chan_num,
2279 				 uint8_t band_mask)
2280 {
2281 	enum channel_enum min_chan, max_chan;
2282 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2283 	uint16_t freq;
2284 
2285 	if (chan_num == 0) {
2286 		reg_err_rl("Invalid channel %d", chan_num);
2287 		return 0;
2288 	}
2289 
2290 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2291 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2292 		reg_err("reg pdev priv obj is NULL");
2293 		return 0;
2294 	}
2295 
2296 	if (BAND_6G_PRESENT(band_mask)) {
2297 		if (BAND_2G_PRESENT(band_mask) ||
2298 		    BAND_5G_PRESENT(band_mask)) {
2299 			reg_err_rl("Incorrect band_mask %x", band_mask);
2300 				return 0;
2301 		}
2302 
2303 		/* Handle 6G channel 2 as a special case as it does not follow
2304 		 * the regular increasing order of channel numbers
2305 		 */
2306 		if (chan_num == SIXG_CHAN_2) {
2307 			struct regulatory_channel *mas_chan_list;
2308 
2309 			mas_chan_list = pdev_priv_obj->mas_chan_list;
2310 			/* Check if chan 2 is in the master list */
2311 			if ((mas_chan_list[CHAN_ENUM_SIXG_2].state !=
2312 			     CHANNEL_STATE_DISABLE) &&
2313 			    !(mas_chan_list[CHAN_ENUM_SIXG_2].chan_flags &
2314 			     REGULATORY_CHAN_DISABLED))
2315 				return mas_chan_list[CHAN_ENUM_SIXG_2].
2316 								center_freq;
2317 			else
2318 				return 0;
2319 		}
2320 
2321 		/* MIN_6GHZ_CHANNEL corresponds to CHAN_ENUM_5935
2322 		 * ( a.k.a SIXG_CHAN_2). Skip it from the search space
2323 		 */
2324 		min_chan = MIN_6GHZ_CHANNEL + 1;
2325 		max_chan = MAX_6GHZ_CHANNEL;
2326 		return reg_compute_chan_to_freq(pdev, chan_num,
2327 						min_chan,
2328 						max_chan);
2329 	} else {
2330 		if (BAND_2G_PRESENT(band_mask)) {
2331 			min_chan = MIN_24GHZ_CHANNEL;
2332 			max_chan = MAX_24GHZ_CHANNEL;
2333 			freq = reg_compute_chan_to_freq(pdev, chan_num,
2334 							min_chan,
2335 							max_chan);
2336 			if (freq != 0)
2337 				return freq;
2338 		}
2339 
2340 		if (BAND_5G_PRESENT(band_mask)) {
2341 			min_chan = BAND_5GHZ_START_CHANNEL;
2342 			max_chan = MAX_5GHZ_CHANNEL;
2343 
2344 			return reg_compute_chan_to_freq(pdev, chan_num,
2345 							min_chan,
2346 							max_chan);
2347 		}
2348 
2349 		reg_err_rl("Incorrect band_mask %x", band_mask);
2350 		return 0;
2351 	}
2352 }
2353 
2354 #ifdef CONFIG_49GHZ_CHAN
2355 bool reg_is_49ghz_freq(qdf_freq_t freq)
2356 {
2357 	return REG_IS_49GHZ_FREQ(freq);
2358 }
2359 #endif /* CONFIG_49GHZ_CHAN */
2360 
2361 qdf_freq_t reg_ch_num(uint32_t ch_enum)
2362 {
2363 	return REG_CH_NUM(ch_enum);
2364 }
2365 
2366 qdf_freq_t reg_ch_to_freq(uint32_t ch_enum)
2367 {
2368 	return REG_CH_TO_FREQ(ch_enum);
2369 }
2370 
2371 uint8_t reg_max_5ghz_ch_num(void)
2372 {
2373 	return REG_MAX_5GHZ_CH_NUM;
2374 }
2375 
2376 #ifdef CONFIG_CHAN_FREQ_API
2377 qdf_freq_t reg_min_24ghz_chan_freq(void)
2378 {
2379 	return REG_MIN_24GHZ_CH_FREQ;
2380 }
2381 
2382 qdf_freq_t reg_max_24ghz_chan_freq(void)
2383 {
2384 	return REG_MAX_24GHZ_CH_FREQ;
2385 }
2386 
2387 qdf_freq_t reg_min_5ghz_chan_freq(void)
2388 {
2389 	return REG_MIN_5GHZ_CH_FREQ;
2390 }
2391 
2392 qdf_freq_t reg_max_5ghz_chan_freq(void)
2393 {
2394 	return REG_MAX_5GHZ_CH_FREQ;
2395 }
2396 #endif /* CONFIG_CHAN_FREQ_API */
2397 
2398 QDF_STATUS reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev,
2399 				   bool enable)
2400 {
2401 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2402 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2403 	struct wlan_objmgr_psoc *psoc;
2404 	QDF_STATUS status;
2405 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2406 
2407 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2408 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2409 		reg_err("pdev reg component is NULL");
2410 		return QDF_STATUS_E_INVAL;
2411 	}
2412 
2413 	if (pdev_priv_obj->dfs_enabled == enable) {
2414 		reg_info("dfs_enabled is already set to %d", enable);
2415 		return QDF_STATUS_SUCCESS;
2416 	}
2417 
2418 	psoc = wlan_pdev_get_psoc(pdev);
2419 	if (!psoc) {
2420 		reg_err("psoc is NULL");
2421 		return QDF_STATUS_E_INVAL;
2422 	}
2423 
2424 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2425 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2426 		reg_err("psoc reg component is NULL");
2427 		return QDF_STATUS_E_INVAL;
2428 	}
2429 
2430 	reg_info("set dfs_enabled: %d", enable);
2431 
2432 	pdev_priv_obj->dfs_enabled = enable;
2433 
2434 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
2435 
2436 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
2437 
2438 	/* Fill the ic channel list with the updated current channel
2439 	 * chan list.
2440 	 */
2441 	if (reg_tx_ops->fill_umac_legacy_chanlist)
2442 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
2443 				pdev_priv_obj->cur_chan_list);
2444 
2445 	status = reg_send_scheduler_msg_sb(psoc, pdev);
2446 
2447 	return status;
2448 }
2449 
2450 bool reg_is_regdmn_en302502_applicable(struct wlan_objmgr_pdev *pdev)
2451 {
2452 	struct cur_regdmn_info cur_reg_dmn;
2453 	QDF_STATUS status;
2454 
2455 	status = reg_get_curr_regdomain(pdev, &cur_reg_dmn);
2456 	if (status != QDF_STATUS_SUCCESS) {
2457 		reg_err("Failed to get reg domain");
2458 		return false;
2459 	}
2460 
2461 	return reg_en302_502_regdmn(cur_reg_dmn.regdmn_pair_id);
2462 }
2463 
2464 QDF_STATUS reg_get_phybitmap(struct wlan_objmgr_pdev *pdev,
2465 			     uint16_t *phybitmap)
2466 {
2467 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2468 
2469 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2470 
2471 	if (!pdev_priv_obj) {
2472 		reg_err("reg pdev private obj is NULL");
2473 		return QDF_STATUS_E_FAULT;
2474 	}
2475 
2476 	*phybitmap = pdev_priv_obj->phybitmap;
2477 
2478 	return QDF_STATUS_SUCCESS;
2479 }
2480 
2481 QDF_STATUS reg_modify_pdev_chan_range(struct wlan_objmgr_pdev *pdev)
2482 {
2483 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2484 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2485 	struct wlan_objmgr_psoc *psoc;
2486 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2487 	struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr;
2488 	uint32_t cnt;
2489 	uint32_t phy_id;
2490 	enum direction dir;
2491 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2492 	struct target_pdev_info *tgt_pdev;
2493 
2494 	tgt_pdev = wlan_pdev_get_tgt_if_handle(pdev);
2495 	phy_id = (uint32_t)target_pdev_get_phy_idx(tgt_pdev);
2496 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2497 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2498 		reg_err("pdev reg component is NULL");
2499 		return QDF_STATUS_E_INVAL;
2500 	}
2501 
2502 	psoc = wlan_pdev_get_psoc(pdev);
2503 	if (!psoc) {
2504 		reg_err("psoc is NULL");
2505 		return QDF_STATUS_E_INVAL;
2506 	}
2507 
2508 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2509 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2510 		reg_err("psoc reg component is NULL");
2511 		return QDF_STATUS_E_INVAL;
2512 	}
2513 
2514 	reg_cap_ptr = psoc_priv_obj->reg_cap;
2515 
2516 	for (cnt = 0; cnt < PSOC_MAX_PHY_REG_CAP; cnt++) {
2517 		if (!reg_cap_ptr) {
2518 			qdf_mem_free(pdev_priv_obj);
2519 			reg_err("reg cap ptr is NULL");
2520 			return QDF_STATUS_E_FAULT;
2521 		}
2522 
2523 		if (reg_cap_ptr->phy_id == phy_id)
2524 			break;
2525 		reg_cap_ptr++;
2526 	}
2527 
2528 	if (cnt == PSOC_MAX_PHY_REG_CAP) {
2529 		qdf_mem_free(pdev_priv_obj);
2530 		reg_err("extended capabilities not found for pdev");
2531 		return QDF_STATUS_E_FAULT;
2532 	}
2533 
2534 	if (psoc_priv_obj->offload_enabled) {
2535 		dir = NORTHBOUND;
2536 	} else {
2537 		dir = SOUTHBOUND;
2538 	}
2539 
2540 	pdev_priv_obj->range_2g_low = reg_cap_ptr->low_2ghz_chan;
2541 	pdev_priv_obj->range_2g_high = reg_cap_ptr->high_2ghz_chan;
2542 	pdev_priv_obj->range_5g_low = reg_cap_ptr->low_5ghz_chan;
2543 	pdev_priv_obj->range_5g_high = reg_cap_ptr->high_5ghz_chan;
2544 	pdev_priv_obj->wireless_modes = reg_cap_ptr->wireless_modes;
2545 
2546 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
2547 
2548 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
2549 
2550 	/* Fill the ic channel list with the updated current channel
2551 	 * chan list.
2552 	 */
2553 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
2554 	    reg_tx_ops->fill_umac_legacy_chanlist(pdev,
2555 						  pdev_priv_obj->cur_chan_list);
2556 
2557 	} else {
2558 		if (dir == NORTHBOUND)
2559 			status = reg_send_scheduler_msg_nb(psoc, pdev);
2560 		else
2561 			status = reg_send_scheduler_msg_sb(psoc, pdev);
2562 	}
2563 
2564 	return status;
2565 }
2566 
2567 QDF_STATUS reg_update_pdev_wireless_modes(struct wlan_objmgr_pdev *pdev,
2568 					  uint32_t wireless_modes)
2569 {
2570 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2571 
2572 	pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
2573 							      WLAN_UMAC_COMP_REGULATORY);
2574 
2575 	if (!pdev_priv_obj) {
2576 		reg_err("reg pdev private obj is NULL");
2577 		return QDF_STATUS_E_INVAL;
2578 	}
2579 
2580 	pdev_priv_obj->wireless_modes = wireless_modes;
2581 
2582 	return QDF_STATUS_SUCCESS;
2583 }
2584 
2585 #ifdef DISABLE_UNII_SHARED_BANDS
2586 /**
2587  * reg_is_reg_unii_band_1_or_reg_unii_band_2a() - Check the input bitmap
2588  * @unii_5g_bitmap: 5G UNII band bitmap
2589  *
2590  * This function checks if either REG_UNII_BAND_1 or REG_UNII_BAND_2A,
2591  * are present in the 5G UNII band bitmap.
2592  *
2593  * Return: Return true if REG_UNII_BAND_1 or REG_UNII_BAND_2A, are present in
2594  * the UNII 5g bitmap else return false.
2595  */
2596 static bool
2597 reg_is_reg_unii_band_1_or_reg_unii_band_2a(uint8_t unii_5g_bitmap)
2598 {
2599 	if (!unii_5g_bitmap)
2600 		return false;
2601 
2602 	return ((unii_5g_bitmap & (BIT(REG_UNII_BAND_1) |
2603 		 BIT(REG_UNII_BAND_2A))) ==  unii_5g_bitmap);
2604 }
2605 
2606 QDF_STATUS reg_disable_chan_coex(struct wlan_objmgr_pdev *pdev,
2607 				 uint8_t unii_5g_bitmap)
2608 {
2609 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2610 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2611 	struct wlan_objmgr_psoc *psoc;
2612 
2613 	psoc = wlan_pdev_get_psoc(pdev);
2614 	if (!psoc) {
2615 		reg_err("psoc is NULL");
2616 		return QDF_STATUS_E_INVAL;
2617 	}
2618 
2619 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2620 
2621 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2622 		reg_err_rl("reg pdev priv obj is NULL");
2623 		return QDF_STATUS_E_FAILURE;
2624 	}
2625 
2626 	if (unii_5g_bitmap &&
2627 	    !reg_is_reg_unii_band_1_or_reg_unii_band_2a(unii_5g_bitmap)) {
2628 		reg_err_rl("Invalid unii_5g_bitmap =  %d", unii_5g_bitmap);
2629 		return QDF_STATUS_E_FAILURE;
2630 	}
2631 
2632 	if (pdev_priv_obj->unii_5g_bitmap == unii_5g_bitmap) {
2633 		reg_debug_rl("UNII bitmask for 5G channels is already set  %d",
2634 			    unii_5g_bitmap);
2635 		return QDF_STATUS_SUCCESS;
2636 	}
2637 
2638 	reg_debug_rl("Setting UNII bitmask for 5G: %d", unii_5g_bitmap);
2639 	pdev_priv_obj->unii_5g_bitmap = unii_5g_bitmap;
2640 
2641 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
2642 
2643 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
2644 
2645 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
2646 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
2647 				pdev_priv_obj->cur_chan_list);
2648 	}
2649 
2650 	return QDF_STATUS_SUCCESS;
2651 }
2652 #endif
2653 
2654 #ifdef CONFIG_CHAN_FREQ_API
2655 QDF_STATUS reg_get_channel_list_with_power_for_freq(struct wlan_objmgr_pdev
2656 						    *pdev,
2657 						    struct channel_power
2658 						    *ch_list,
2659 						    uint8_t *num_chan)
2660 {
2661 	int i, count;
2662 	struct regulatory_channel *reg_channels;
2663 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2664 
2665 	if (!num_chan || !ch_list) {
2666 		reg_err("chan_list or num_ch is NULL");
2667 		return QDF_STATUS_E_FAILURE;
2668 	}
2669 
2670 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2671 
2672 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2673 		reg_err("reg pdev priv obj is NULL");
2674 		return QDF_STATUS_E_FAILURE;
2675 	}
2676 
2677 	/* set the current channel list */
2678 	reg_channels = pdev_priv_obj->cur_chan_list;
2679 
2680 	for (i = 0, count = 0; i < NUM_CHANNELS; i++) {
2681 		if (reg_channels[i].state &&
2682 		    !(reg_channels[i].chan_flags & REGULATORY_CHAN_DISABLED)) {
2683 			ch_list[count].center_freq =
2684 				reg_channels[i].center_freq;
2685 			ch_list[count].chan_num = reg_channels[i].chan_num;
2686 			ch_list[count++].tx_power =
2687 				reg_channels[i].tx_power;
2688 		}
2689 	}
2690 
2691 	*num_chan = count;
2692 
2693 	return QDF_STATUS_SUCCESS;
2694 }
2695 
2696 enum channel_enum reg_get_chan_enum_for_freq(qdf_freq_t freq)
2697 {
2698 	uint32_t count;
2699 
2700 	for (count = 0; count < NUM_CHANNELS; count++)
2701 		if (channel_map[count].center_freq == freq)
2702 			return count;
2703 
2704 	reg_err_rl("invalid channel center frequency %d", freq);
2705 
2706 	return INVALID_CHANNEL;
2707 }
2708 
2709 bool
2710 reg_is_freq_present_in_cur_chan_list(struct wlan_objmgr_pdev *pdev,
2711 				     qdf_freq_t freq)
2712 {
2713 	enum channel_enum chan_enum;
2714 	struct regulatory_channel *cur_chan_list;
2715 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2716 
2717 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2718 
2719 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2720 		reg_err_rl("pdev reg obj is NULL");
2721 		return false;
2722 	}
2723 
2724 	cur_chan_list = pdev_priv_obj->cur_chan_list;
2725 
2726 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++)
2727 		if (cur_chan_list[chan_enum].center_freq == freq)
2728 			if ((cur_chan_list[chan_enum].state !=
2729 			     CHANNEL_STATE_DISABLE) &&
2730 			    !(cur_chan_list[chan_enum].chan_flags &
2731 			      REGULATORY_CHAN_DISABLED))
2732 				return true;
2733 
2734 	reg_debug_rl("Channel center frequency %d not found", freq);
2735 
2736 	return false;
2737 }
2738 
2739 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST
2740 /**
2741  * is_freq_present_in_resp_list() - is freq present in resp list
2742  *
2743  * @pcl_ch: pcl ch
2744  * @res_msg: Response msg
2745  * @count: no of usable channels
2746  *
2747  * Return: void
2748  */
2749 static bool
2750 is_freq_present_in_resp_list(uint32_t pcl_ch,
2751 			     struct get_usable_chan_res_params *res_msg,
2752 			     int count)
2753 {
2754 	int i;
2755 
2756 	for (i = 0; i < count; i++) {
2757 		if (res_msg[i].freq == pcl_ch)
2758 			return true;
2759 	}
2760 	return false;
2761 }
2762 
2763 /**
2764  * reg_update_usable_chan_resp() - Update response msg
2765  * @pdev: Pointer to pdev
2766  * @res_msg: Response msg
2767  * @pcl_ch: pcl channel
2768  * @len: calculated pcl len
2769  * @iface_mode_mask: interface type
2770  * @band_mask: requested band mask
2771  * @count: no of usable channels
2772  *
2773  * Return: void
2774  */
2775 static void
2776 reg_update_usable_chan_resp(struct wlan_objmgr_pdev *pdev,
2777 			    struct get_usable_chan_res_params *res_msg,
2778 			    uint32_t *pcl_ch, uint32_t len,
2779 			    uint32_t iface_mode_mask,
2780 			    uint32_t band_mask, int *count)
2781 {
2782 	int i;
2783 	struct ch_params ch_params = {0};
2784 	int index = *count;
2785 
2786 	for (i = 0; i < len; i++) {
2787 		/* In case usable channels are required for multiple filter
2788 		 * mask, Some frequencies may present in res_msg . To avoid
2789 		 * frequency duplication, only mode mask is updated for
2790 		 * existing freqency.
2791 		 */
2792 		if (is_freq_present_in_resp_list(pcl_ch[i], res_msg, *count))
2793 			continue;
2794 
2795 		if (!(band_mask & 1 << wlan_reg_freq_to_band(pcl_ch[i])))
2796 			continue;
2797 
2798 		ch_params.ch_width = CH_WIDTH_MAX;
2799 		reg_set_channel_params_for_freq(
2800 				pdev,
2801 				pcl_ch[i],
2802 				0, &ch_params);
2803 		res_msg[index].freq = (qdf_freq_t)pcl_ch[i];
2804 		res_msg[index].iface_mode_mask |= 1 << iface_mode_mask;
2805 		res_msg[index].bw = ch_params.ch_width;
2806 		if (ch_params.center_freq_seg0)
2807 			res_msg[index].seg0_freq =
2808 					ch_params.center_freq_seg0;
2809 		if (ch_params.center_freq_seg1)
2810 			res_msg[index].seg1_freq =
2811 					ch_params.center_freq_seg1;
2812 		index++;
2813 	}
2814 
2815 	*count = index;
2816 }
2817 
2818 /**
2819  * reg_update_conn_chan_list() - Get usable channels with conn filter
2820  *				 and policy mgr mask
2821  * @pdev: Pointer to pdev
2822  * @res_msg: Response msg
2823  * @policy_mgr_con_mode: policy mgr mode
2824  * @iftype: interface type
2825  * @band_mask: requested band mask
2826  * @count: no of usable channels
2827  *
2828  * Return: qdf status
2829  */
2830 static QDF_STATUS
2831 reg_update_conn_chan_list(struct wlan_objmgr_pdev *pdev,
2832 			  struct get_usable_chan_res_params *res_msg,
2833 			  enum policy_mgr_con_mode mode,
2834 			  uint32_t iftype,
2835 			  uint32_t band_mask,
2836 			  uint32_t *count)
2837 {
2838 	uint32_t *pcl_ch;
2839 	uint8_t *weight_list;
2840 	uint32_t len;
2841 	uint32_t weight_len;
2842 	struct wlan_objmgr_psoc *psoc;
2843 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2844 
2845 	pcl_ch = qdf_mem_malloc(NUM_CHANNELS *
2846 			sizeof(uint32_t));
2847 
2848 	if (!pcl_ch) {
2849 		reg_err("pcl_ch invalid");
2850 		return QDF_STATUS_E_FAILURE;
2851 	}
2852 
2853 	weight_list = qdf_mem_malloc(NUM_CHANNELS *
2854 			sizeof(uint8_t));
2855 
2856 	if (!weight_list) {
2857 		reg_err("weight_list invalid");
2858 		qdf_mem_free(pcl_ch);
2859 		return QDF_STATUS_E_FAILURE;
2860 	}
2861 
2862 	psoc = wlan_pdev_get_psoc(pdev);
2863 	if (!psoc) {
2864 		reg_err("invalid psoc");
2865 		status = QDF_STATUS_E_FAILURE;
2866 		goto err;
2867 	}
2868 
2869 	len = NUM_CHANNELS;
2870 	weight_len = NUM_CHANNELS;
2871 
2872 	status = policy_mgr_get_pcl(psoc, mode, pcl_ch, &len,
2873 				    weight_list, weight_len);
2874 	if (QDF_IS_STATUS_ERROR(status)) {
2875 		reg_err("get pcl failed for mode: %d", mode);
2876 		goto err;
2877 	}
2878 	reg_update_usable_chan_resp(pdev, res_msg, pcl_ch, len,
2879 				    iftype, band_mask, count);
2880 err:
2881 	qdf_mem_free(pcl_ch);
2882 	qdf_mem_free(weight_list);
2883 	return status;
2884 }
2885 
2886 /**
2887  * reg_get_usable_channel_con_filter() - Get usable channel with con filter mask
2888  * @pdev: Pointer to pdev
2889  * @req_msg: Request msg
2890  * @res_msg: Response msg
2891  * @chan_list: reg channel list
2892  * @count: no of usable channels
2893  *
2894  * Return: qdf status
2895  */
2896 static QDF_STATUS
2897 reg_get_usable_channel_con_filter(struct wlan_objmgr_pdev *pdev,
2898 				  struct get_usable_chan_req_params req_msg,
2899 				  struct get_usable_chan_res_params *res_msg,
2900 				  int *count)
2901 {
2902 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2903 	uint32_t iface_mode_mask = req_msg.iface_mode_mask;
2904 
2905 	while (iface_mode_mask) {
2906 		if (iface_mode_mask & 1 << IFTYPE_AP) {
2907 			status =
2908 			reg_update_conn_chan_list(pdev, res_msg, PM_SAP_MODE,
2909 						  IFTYPE_AP, req_msg.band_mask,
2910 						  count);
2911 			iface_mode_mask &= ~(1 << IFTYPE_AP);
2912 		} else if (iface_mode_mask & 1 << IFTYPE_STATION) {
2913 			status =
2914 			reg_update_conn_chan_list(pdev, res_msg, PM_STA_MODE,
2915 						  IFTYPE_STATION,
2916 						  req_msg.band_mask, count);
2917 			iface_mode_mask &= ~(1 << IFTYPE_STATION);
2918 		} else if (iface_mode_mask & 1 << IFTYPE_P2P_GO) {
2919 			status =
2920 			reg_update_conn_chan_list(pdev, res_msg, PM_P2P_GO_MODE,
2921 						  IFTYPE_P2P_GO,
2922 						  req_msg.band_mask, count);
2923 			iface_mode_mask &= ~(1 << IFTYPE_P2P_GO);
2924 		} else if (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) {
2925 			status =
2926 			reg_update_conn_chan_list(pdev, res_msg,
2927 						  PM_P2P_CLIENT_MODE,
2928 						  IFTYPE_P2P_CLIENT,
2929 						  req_msg.band_mask, count);
2930 			iface_mode_mask &= ~(1 << IFTYPE_P2P_CLIENT);
2931 		} else if (iface_mode_mask & 1 << IFTYPE_NAN) {
2932 			status =
2933 			reg_update_conn_chan_list(pdev, res_msg,
2934 						  PM_NAN_DISC_MODE, IFTYPE_NAN,
2935 						  req_msg.band_mask, count);
2936 			iface_mode_mask &= ~(1 << IFTYPE_NAN);
2937 		} else {
2938 			reg_err("invalid mode");
2939 			break;
2940 		}
2941 	}
2942 	return status;
2943 }
2944 
2945 /**
2946  * reg_remove_freq() - Remove invalid freq
2947  * @res_msg: Response msg
2948  * @index: index of freq that needs to be removed
2949  *
2950  * Return: void
2951  */
2952 static void
2953 reg_remove_freq(struct get_usable_chan_res_params *res_msg,
2954 		int index)
2955 {
2956 	reg_debug("removing freq %d", res_msg[index].freq);
2957 	qdf_mem_zero(&res_msg[index],
2958 		     sizeof(struct get_usable_chan_res_params));
2959 }
2960 
2961 /**
2962  * reg_skip_invalid_chan_freq() - Remove invalid freq for SAP, P2P GO
2963  *				  and NAN
2964  * @pdev: Pointer to pdev
2965  * @res_msg: Response msg
2966  * @count: no of usable channels
2967  * @iface_mode_mask: interface mode mask
2968  *
2969  * Return: qdf status
2970  */
2971 static QDF_STATUS
2972 reg_skip_invalid_chan_freq(struct wlan_objmgr_pdev *pdev,
2973 			   struct get_usable_chan_res_params *res_msg,
2974 			   uint32_t *no_usable_channels,
2975 			   uint32_t iface_mode_mask)
2976 {
2977 	uint32_t chan_enum, iface_mode = 0;
2978 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2979 	bool include_indoor_channel, dfs_master_capable;
2980 	uint8_t enable_srd_chan, srd_mask = 0;
2981 	struct wlan_objmgr_psoc *psoc;
2982 	psoc = wlan_pdev_get_psoc(pdev);
2983 	if (!psoc) {
2984 		reg_err("invalid psoc");
2985 		return QDF_STATUS_E_FAILURE;
2986 	}
2987 
2988 	status = ucfg_mlme_get_indoor_channel_support(psoc,
2989 						      &include_indoor_channel);
2990 	if (QDF_IS_STATUS_ERROR(status)) {
2991 		reg_err("failed to get indoor channel skip info");
2992 		return QDF_STATUS_E_FAILURE;
2993 	}
2994 
2995 	ucfg_mlme_get_etsi_srd_chan_in_master_mode(psoc,
2996 						   &enable_srd_chan);
2997 	if (QDF_IS_STATUS_ERROR(status)) {
2998 		reg_err("failed to get srd chan info");
2999 		return QDF_STATUS_E_FAILURE;
3000 	}
3001 
3002 	status = ucfg_mlme_get_dfs_master_capability(psoc, &dfs_master_capable);
3003 	if (QDF_IS_STATUS_ERROR(status)) {
3004 		reg_err("failed to get dfs master capable");
3005 		return status;
3006 	}
3007 
3008 	while (iface_mode_mask) {
3009 		if (iface_mode_mask & (1 << IFTYPE_AP)) {
3010 			srd_mask = 1;
3011 			iface_mode = 1 << IFTYPE_AP;
3012 		} else if (iface_mode_mask & (1 << IFTYPE_P2P_GO)) {
3013 			srd_mask = 2;
3014 			iface_mode = 1 << IFTYPE_P2P_GO;
3015 		} else if (iface_mode_mask & (1 << IFTYPE_NAN)) {
3016 			iface_mode = 1 << IFTYPE_NAN;
3017 		} else {
3018 			break;
3019 		}
3020 		for (chan_enum = 0; chan_enum < *no_usable_channels;
3021 		     chan_enum++) {
3022 			if (iface_mode_mask & (1 << IFTYPE_NAN)) {
3023 				if (!wlan_is_nan_allowed_on_freq(pdev,
3024 				     res_msg[chan_enum].freq))
3025 					res_msg[chan_enum].iface_mode_mask &=
3026 						~(iface_mode);
3027 				if (!res_msg[chan_enum].iface_mode_mask)
3028 					reg_remove_freq(res_msg, chan_enum);
3029 			} else {
3030 				if (wlan_reg_is_freq_indoor(
3031 					pdev, res_msg[chan_enum].freq) &&
3032 					!include_indoor_channel) {
3033 					res_msg[chan_enum].iface_mode_mask &=
3034 							~(iface_mode);
3035 					if (!res_msg[chan_enum].iface_mode_mask)
3036 						reg_remove_freq(res_msg,
3037 								chan_enum);
3038 				}
3039 
3040 				if (!(enable_srd_chan & srd_mask) &&
3041 				    reg_is_etsi13_srd_chan_for_freq(
3042 					pdev, res_msg[chan_enum].freq)) {
3043 					res_msg[chan_enum].iface_mode_mask &=
3044 						~(iface_mode);
3045 					if (!res_msg[chan_enum].iface_mode_mask)
3046 						reg_remove_freq(res_msg,
3047 								chan_enum);
3048 				}
3049 
3050 				if (!dfs_master_capable &&
3051 				    wlan_reg_is_dfs_for_freq(pdev,
3052 				    res_msg[chan_enum].freq)) {
3053 					res_msg[chan_enum].iface_mode_mask &=
3054 						~(iface_mode);
3055 					if (!res_msg[chan_enum].iface_mode_mask)
3056 						reg_remove_freq(res_msg,
3057 								chan_enum);
3058 				}
3059 			}
3060 		}
3061 
3062 		iface_mode_mask &= ~iface_mode;
3063 	}
3064 
3065 	return status;
3066 }
3067 
3068 /**
3069  * reg_get_usable_channel_no_filter() - Get usable channel with no filter mask
3070  * @pdev: Pointer to pdev
3071  * @req_msg: Request msg
3072  * @res_msg: Response msg
3073  * @chan_list: reg channel list
3074  * @count: no of usable channels
3075  *
3076  * Return: qdf status
3077  */
3078 static QDF_STATUS
3079 reg_get_usable_channel_no_filter(struct wlan_objmgr_pdev *pdev,
3080 				 struct get_usable_chan_req_params req_msg,
3081 				 struct get_usable_chan_res_params *res_msg,
3082 				 struct regulatory_channel *chan_list,
3083 				 int *count)
3084 {
3085 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3086 
3087 	status =
3088 	reg_skip_invalid_chan_freq(pdev, res_msg,
3089 				   count, req_msg.iface_mode_mask);
3090 	return status;
3091 }
3092 
3093 /**
3094  * reg_get_usable_channel_coex_filter() - Get usable channel with coex filter
3095  * @pdev: Pointer to pdev
3096  * @req_msg: Request msg
3097  * @res_msg: Response msg
3098  * @chan_list: reg channel list
3099  * @count: no of usable channels
3100  *
3101  * Return: qdf status
3102  */
3103 static QDF_STATUS
3104 reg_get_usable_channel_coex_filter(struct wlan_objmgr_pdev *pdev,
3105 				   struct get_usable_chan_req_params req_msg,
3106 				   struct get_usable_chan_res_params *res_msg,
3107 				   struct regulatory_channel *chan_list,
3108 				   int *count)
3109 {
3110 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
3111 	enum channel_enum chan_enum;
3112 	uint32_t i = 0;
3113 	struct ch_avoid_freq_type freq_range;
3114 	struct wlan_objmgr_psoc *psoc;
3115 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3116 
3117 	psoc = wlan_pdev_get_psoc(pdev);
3118 	if (!psoc) {
3119 		reg_err("invalid psoc");
3120 		return QDF_STATUS_E_FAILURE;
3121 	}
3122 
3123 	psoc_priv_obj = reg_get_psoc_obj(psoc);
3124 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
3125 		reg_alert("psoc reg component is NULL");
3126 		return QDF_STATUS_E_FAILURE;
3127 	}
3128 	for (chan_enum = 0; chan_enum < *count; chan_enum++) {
3129 		for (i = 0; i <
3130 		    psoc_priv_obj->avoid_freq_list.ch_avoid_range_cnt; i++) {
3131 			freq_range =
3132 			psoc_priv_obj->avoid_freq_list.avoid_freq_range[i];
3133 
3134 			if (freq_range.start_freq <=
3135 			    chan_list[chan_enum].center_freq &&
3136 			    freq_range.end_freq >=
3137 			    chan_list[chan_enum].center_freq) {
3138 				reg_remove_freq(res_msg, chan_enum);
3139 			}
3140 		}
3141 	}
3142 	if (req_msg.iface_mode_mask & 1 << IFTYPE_AP ||
3143 	    req_msg.iface_mode_mask & 1 << IFTYPE_P2P_GO ||
3144 	    req_msg.iface_mode_mask & 1 << IFTYPE_NAN)
3145 		status =
3146 		reg_skip_invalid_chan_freq(pdev, res_msg, count,
3147 					   req_msg.iface_mode_mask);
3148 	return status;
3149 }
3150 
3151 /**
3152  * reg_calculate_mode_mask() - calculate valid mode mask
3153  * @iface_mode_mask: interface mode mask
3154  *
3155  * Return: Valid mode mask
3156  */
3157 static uint32_t
3158 reg_calculate_mode_mask(uint32_t iface_mode_mask)
3159 {
3160 	int mode_mask = 0;
3161 
3162 	mode_mask = (iface_mode_mask & 1 << IFTYPE_STATION) |
3163 		    (iface_mode_mask & 1 << IFTYPE_AP) |
3164 		    (iface_mode_mask & 1 << IFTYPE_P2P_GO) |
3165 		    (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) |
3166 		    (iface_mode_mask & 1 << IFTYPE_P2P_DEVICE) |
3167 		    (iface_mode_mask & 1 << IFTYPE_NAN);
3168 
3169 	return mode_mask;
3170 }
3171 
3172 /**
3173  * reg_add_usable_channel_to_resp() - Add usable channels to resp structure
3174  * @pdev: Pointer to pdev
3175  * @res_msg: Response msg
3176  * @iface_mode_mask: interface mode mask
3177  * @chan_list: reg channel list
3178  * @count: no of usable channels
3179  *
3180  * Return: qdf status
3181  */
3182 static QDF_STATUS
3183 reg_add_usable_channel_to_resp(struct wlan_objmgr_pdev *pdev,
3184 			       struct get_usable_chan_res_params *res_msg,
3185 			       uint32_t iface_mode_mask,
3186 			       struct regulatory_channel *chan_list,
3187 			       int *count)
3188 {
3189 	enum channel_enum chan_enum;
3190 	struct ch_params ch_params = {0};
3191 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3192 	uint32_t mode_mask = 0;
3193 
3194 	mode_mask = reg_calculate_mode_mask(iface_mode_mask);
3195 
3196 	for (chan_enum = 0; chan_enum < *count &&
3197 	     chan_enum < NUM_CHANNELS; chan_enum++) {
3198 		ch_params.ch_width = CH_WIDTH_MAX;
3199 		reg_set_channel_params_for_freq(
3200 				pdev,
3201 				chan_list[chan_enum].center_freq,
3202 				chan_list[chan_enum].max_bw, &ch_params);
3203 
3204 		res_msg[chan_enum].freq = chan_list[chan_enum].center_freq;
3205 		res_msg[chan_enum].iface_mode_mask = mode_mask;
3206 		if (!res_msg[chan_enum].iface_mode_mask) {
3207 			reg_err("invalid iface mask");
3208 			return QDF_STATUS_E_FAILURE;
3209 		}
3210 		res_msg[chan_enum].bw = ch_params.ch_width;
3211 		res_msg[chan_enum].state = chan_list[chan_enum].state;
3212 		if (ch_params.center_freq_seg0)
3213 			res_msg[chan_enum].seg0_freq =
3214 					ch_params.center_freq_seg0;
3215 		if (ch_params.center_freq_seg1)
3216 			res_msg[chan_enum].seg1_freq =
3217 					ch_params.center_freq_seg1;
3218 	}
3219 
3220 	return status;
3221 }
3222 
3223 QDF_STATUS
3224 wlan_reg_get_usable_channel(struct wlan_objmgr_pdev *pdev,
3225 			    struct get_usable_chan_req_params req_msg,
3226 			    struct get_usable_chan_res_params *res_msg,
3227 			    uint32_t *usable_channels)
3228 {
3229 	struct regulatory_channel *chan_list;
3230 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3231 
3232 	chan_list = qdf_mem_malloc(NUM_CHANNELS *
3233 			sizeof(*chan_list));
3234 
3235 	if (!chan_list) {
3236 		reg_err("chan_list invalid");
3237 		return QDF_STATUS_E_FAILURE;
3238 	}
3239 
3240 	if ((req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) ||
3241 	    (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) &&
3242 	     !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))) {
3243 		*usable_channels = reg_get_band_channel_list(pdev,
3244 							     req_msg.band_mask,
3245 							     chan_list);
3246 		status =
3247 		reg_add_usable_channel_to_resp(pdev, res_msg,
3248 					       req_msg.iface_mode_mask,
3249 					       chan_list, usable_channels);
3250 		if (QDF_IS_STATUS_ERROR(status)) {
3251 			qdf_mem_free(chan_list);
3252 			return status;
3253 		}
3254 	}
3255 
3256 	if (req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX)
3257 		status =
3258 		reg_get_usable_channel_coex_filter(pdev, req_msg, res_msg,
3259 						   chan_list, usable_channels);
3260 
3261 	if (req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY)
3262 		status =
3263 		reg_get_usable_channel_con_filter(pdev, req_msg, res_msg,
3264 						  usable_channels);
3265 
3266 	if (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) &&
3267 	    !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))
3268 		status =
3269 		reg_get_usable_channel_no_filter(pdev, req_msg, res_msg,
3270 						 chan_list, usable_channels);
3271 	reg_debug("usable chan count is %d", *usable_channels);
3272 
3273 	qdf_mem_free(chan_list);
3274 	return status;
3275 }
3276 #endif
3277 
3278 enum channel_state reg_get_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
3279 						  qdf_freq_t freq)
3280 {
3281 	enum channel_enum ch_idx;
3282 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3283 
3284 	ch_idx = reg_get_chan_enum_for_freq(freq);
3285 
3286 	if (ch_idx == INVALID_CHANNEL)
3287 		return CHANNEL_STATE_INVALID;
3288 
3289 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3290 
3291 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3292 		reg_err("pdev reg obj is NULL");
3293 		return CHANNEL_STATE_INVALID;
3294 	}
3295 
3296 	return pdev_priv_obj->cur_chan_list[ch_idx].state;
3297 }
3298 
3299 static uint32_t reg_get_channel_flags_for_freq(struct wlan_objmgr_pdev *pdev,
3300 					       qdf_freq_t freq)
3301 {
3302 	enum channel_enum chan_enum;
3303 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3304 
3305 	chan_enum = reg_get_chan_enum_for_freq(freq);
3306 
3307 	if (chan_enum == INVALID_CHANNEL) {
3308 		reg_err("chan freq is not valid");
3309 		return REGULATORY_CHAN_INVALID;
3310 	}
3311 
3312 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3313 
3314 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3315 		reg_err("pdev reg obj is NULL");
3316 		return REGULATORY_CHAN_INVALID;
3317 	}
3318 
3319 	return pdev_priv_obj->cur_chan_list[chan_enum].chan_flags;
3320 }
3321 
3322 #ifdef CONFIG_REG_CLIENT
3323 enum channel_state reg_get_channel_state_from_secondary_list_for_freq(
3324 						struct wlan_objmgr_pdev *pdev,
3325 						qdf_freq_t freq)
3326 {
3327 	enum channel_enum ch_idx;
3328 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3329 
3330 	ch_idx = reg_get_chan_enum_for_freq(freq);
3331 
3332 	if (ch_idx == INVALID_CHANNEL)
3333 		return CHANNEL_STATE_INVALID;
3334 
3335 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3336 
3337 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3338 		reg_err("pdev reg obj is NULL");
3339 		return CHANNEL_STATE_INVALID;
3340 	}
3341 
3342 	return pdev_priv_obj->secondary_cur_chan_list[ch_idx].state;
3343 }
3344 
3345 static uint32_t reg_get_channel_flags_from_secondary_list_for_freq(
3346 						struct wlan_objmgr_pdev *pdev,
3347 						qdf_freq_t freq)
3348 {
3349 	enum channel_enum chan_enum;
3350 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3351 
3352 	chan_enum = reg_get_chan_enum_for_freq(freq);
3353 
3354 	if (chan_enum == INVALID_CHANNEL) {
3355 		reg_err_rl("chan freq %u is not valid", freq);
3356 		return REGULATORY_CHAN_INVALID;
3357 	}
3358 
3359 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3360 
3361 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3362 		reg_err("pdev reg obj is NULL");
3363 		return REGULATORY_CHAN_INVALID;
3364 	}
3365 
3366 	return pdev_priv_obj->secondary_cur_chan_list[chan_enum].chan_flags;
3367 }
3368 #endif
3369 
3370 /**
3371  * reg_get_5g_bonded_chan_array_for_freq()- Return the channel state for a
3372  * 5G or 6G channel frequency based on the bonded channel.
3373  * @pdev: Pointer to pdev.
3374  * @freq: Channel center frequency.
3375  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
3376  *
3377  * Return: Channel State
3378  */
3379 static enum channel_state
3380 reg_get_5g_bonded_chan_array_for_freq(struct wlan_objmgr_pdev *pdev,
3381 				      uint16_t freq,
3382 				      const struct bonded_channel_freq *
3383 				      bonded_chan_ptr)
3384 {
3385 	uint16_t chan_cfreq;
3386 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
3387 	enum channel_state temp_chan_state;
3388 
3389 	if (!bonded_chan_ptr) {
3390 		reg_debug("bonded chan ptr is NULL");
3391 		return chan_state;
3392 	}
3393 
3394 	chan_cfreq =  bonded_chan_ptr->start_freq;
3395 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
3396 		temp_chan_state = reg_get_channel_state_for_freq(pdev,
3397 								 chan_cfreq);
3398 		if (temp_chan_state < chan_state)
3399 			chan_state = temp_chan_state;
3400 		chan_cfreq = chan_cfreq + 20;
3401 	}
3402 
3403 	return chan_state;
3404 }
3405 
3406 enum channel_state
3407 reg_get_5g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
3408 					 qdf_freq_t freq,
3409 					 enum phy_ch_width bw)
3410 {
3411 	enum channel_enum ch_indx;
3412 	enum channel_state chan_state;
3413 	struct regulatory_channel *reg_channels;
3414 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3415 	bool bw_enabled = false;
3416 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
3417 
3418 	if (bw > CH_WIDTH_80P80MHZ) {
3419 		reg_err_rl("bw (%d) passed is not good", bw);
3420 		return CHANNEL_STATE_INVALID;
3421 	}
3422 
3423 	chan_state = reg_get_5g_bonded_channel_for_freq(pdev, freq, bw,
3424 							&bonded_chan_ptr);
3425 
3426 	if ((chan_state == CHANNEL_STATE_INVALID) ||
3427 	    (chan_state == CHANNEL_STATE_DISABLE))
3428 		return chan_state;
3429 
3430 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3431 
3432 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3433 		reg_err("pdev reg obj is NULL");
3434 		return CHANNEL_STATE_INVALID;
3435 	}
3436 	reg_channels = pdev_priv_obj->cur_chan_list;
3437 
3438 	ch_indx = reg_get_chan_enum_for_freq(freq);
3439 	if (ch_indx == INVALID_CHANNEL)
3440 		return CHANNEL_STATE_INVALID;
3441 	if (bw == CH_WIDTH_5MHZ)
3442 		bw_enabled = true;
3443 	else if (bw == CH_WIDTH_10MHZ)
3444 		bw_enabled = (reg_channels[ch_indx].min_bw <= 10) &&
3445 			(reg_channels[ch_indx].max_bw >= 10);
3446 	else if (bw == CH_WIDTH_20MHZ)
3447 		bw_enabled = (reg_channels[ch_indx].min_bw <= 20) &&
3448 			(reg_channels[ch_indx].max_bw >= 20);
3449 	else if (bw == CH_WIDTH_40MHZ)
3450 		bw_enabled = (reg_channels[ch_indx].min_bw <= 40) &&
3451 			(reg_channels[ch_indx].max_bw >= 40);
3452 	else if (bw == CH_WIDTH_80MHZ)
3453 		bw_enabled = (reg_channels[ch_indx].min_bw <= 80) &&
3454 			(reg_channels[ch_indx].max_bw >= 80);
3455 	else if (bw == CH_WIDTH_160MHZ)
3456 		bw_enabled = (reg_channels[ch_indx].min_bw <= 160) &&
3457 			(reg_channels[ch_indx].max_bw >= 160);
3458 	else if (bw == CH_WIDTH_80P80MHZ)
3459 		bw_enabled = (reg_channels[ch_indx].min_bw <= 80) &&
3460 			(reg_channels[ch_indx].max_bw >= 80);
3461 
3462 	if (bw_enabled)
3463 		return chan_state;
3464 	else
3465 		return CHANNEL_STATE_DISABLE;
3466 }
3467 
3468 enum channel_state
3469 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
3470 					 qdf_freq_t oper_ch_freq,
3471 					 qdf_freq_t sec_ch_freq,
3472 					 enum phy_ch_width bw)
3473 {
3474 	enum channel_enum chan_idx;
3475 	enum channel_state chan_state;
3476 	struct regulatory_channel *reg_channels;
3477 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3478 	bool bw_enabled = false;
3479 	enum channel_state chan_state2 = CHANNEL_STATE_INVALID;
3480 
3481 	if (bw > CH_WIDTH_40MHZ)
3482 		return CHANNEL_STATE_INVALID;
3483 
3484 	if (bw == CH_WIDTH_40MHZ) {
3485 		if ((sec_ch_freq + 20 != oper_ch_freq) &&
3486 		    (oper_ch_freq + 20 != sec_ch_freq))
3487 			return CHANNEL_STATE_INVALID;
3488 		chan_state2 = reg_get_channel_state_for_freq(pdev, sec_ch_freq);
3489 		if (chan_state2 == CHANNEL_STATE_INVALID)
3490 			return chan_state2;
3491 	}
3492 
3493 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3494 
3495 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3496 		reg_err("reg pdev priv obj is NULL");
3497 		return CHANNEL_STATE_INVALID;
3498 	}
3499 
3500 	reg_channels = pdev_priv_obj->cur_chan_list;
3501 
3502 	chan_state = reg_get_channel_state_for_freq(pdev, oper_ch_freq);
3503 	if (chan_state2 < chan_state)
3504 		chan_state = chan_state2;
3505 
3506 	if ((chan_state == CHANNEL_STATE_INVALID) ||
3507 	    (chan_state == CHANNEL_STATE_DISABLE))
3508 		return chan_state;
3509 
3510 	chan_idx = reg_get_chan_enum_for_freq(oper_ch_freq);
3511 	if (chan_idx == INVALID_CHANNEL)
3512 		return CHANNEL_STATE_INVALID;
3513 	if (bw == CH_WIDTH_5MHZ)
3514 		bw_enabled = true;
3515 	else if (bw == CH_WIDTH_10MHZ)
3516 		bw_enabled = (reg_channels[chan_idx].min_bw <= 10) &&
3517 			(reg_channels[chan_idx].max_bw >= 10);
3518 	else if (bw == CH_WIDTH_20MHZ)
3519 		bw_enabled = (reg_channels[chan_idx].min_bw <= 20) &&
3520 			(reg_channels[chan_idx].max_bw >= 20);
3521 	else if (bw == CH_WIDTH_40MHZ)
3522 		bw_enabled = (reg_channels[chan_idx].min_bw <= 40) &&
3523 			(reg_channels[chan_idx].max_bw >= 40);
3524 
3525 	if (bw_enabled)
3526 		return chan_state;
3527 	else
3528 		return CHANNEL_STATE_DISABLE;
3529 
3530 	return CHANNEL_STATE_ENABLE;
3531 }
3532 
3533 #ifdef WLAN_FEATURE_11BE
3534 /**
3535  * reg_get_320_bonded_chan_array() - Fetches a list of bonded channel pointers
3536  * for the given bonded channel array. If 320 band center is specified,
3537  * return the bonded channel pointer comprising of given band center else
3538  * return list of all available bonded channel pair.
3539  *
3540  * @pdev: Pointer to struct wlan_objmgr_pdev.
3541  * @freq: Input frequency in MHZ whose bonded channel pointer must be fetched.
3542  * @band_center_320: Channel center frequency of 320MHZ channel.
3543  * @bonded_chan_ar: Array of bonded channel list.
3544  * @array_size: Size of bonded channel array.
3545  * @bonded_chan_ptr: Pointer to hold the address of bonded_channel_freq index.
3546  *
3547  * Return: number of bonded channel arrays fetched.
3548  */
3549 
3550 #define MAX_NUM_BONDED_PAIR 2
3551 static uint8_t
3552 reg_get_320_bonded_chan_array(struct wlan_objmgr_pdev *pdev,
3553 			      qdf_freq_t freq,
3554 			      qdf_freq_t band_center_320,
3555 			      const struct bonded_channel_freq bonded_chan_ar[],
3556 			      uint16_t array_size,
3557 			      const struct bonded_channel_freq
3558 			      *bonded_chan_ptr[])
3559 {
3560 	int i;
3561 	uint8_t num_bonded_pairs = 0;
3562 
3563 	/* Fetch all possible bonded channel pointers for the given freq */
3564 	if (!band_center_320) {
3565 		for (i = 0 ; i < array_size &&
3566 		     num_bonded_pairs < MAX_NUM_BONDED_PAIR; i++) {
3567 			if ((freq >= bonded_chan_ar[i].start_freq) &&
3568 			    (freq <= bonded_chan_ar[i].end_freq)) {
3569 				bonded_chan_ptr[num_bonded_pairs] =
3570 					&bonded_chan_ar[i];
3571 				num_bonded_pairs++;
3572 			}
3573 		}
3574 	} else {
3575 		/* Fetch the bonded channel pointer for the given band_center */
3576 		for (i = 0; i < array_size; i++) {
3577 			if (((bonded_chan_ar[i].start_freq +
3578 			      bonded_chan_ar[i].end_freq) / 2) ==
3579 				band_center_320) {
3580 				bonded_chan_ptr[num_bonded_pairs] =
3581 					&bonded_chan_ar[i];
3582 				num_bonded_pairs++;
3583 				break;
3584 			}
3585 		}
3586 	}
3587 	return num_bonded_pairs;
3588 }
3589 
3590 static inline bool reg_is_state_allowed(enum channel_state chan_state)
3591 {
3592 	return !((chan_state == CHANNEL_STATE_INVALID) ||
3593 		 (chan_state == CHANNEL_STATE_DISABLE));
3594 }
3595 
3596 /**
3597  * reg_get_320_bonded_channel_state() - Given a bonded channel
3598  * pointer and freq, determine if the subchannels of the bonded pair
3599  * are valid and supported by the current regulatory.
3600  *
3601  * @pdev: Pointer to struct wlan_objmgr_pdev.
3602  * @freq: Frequency in MHZ.
3603  * @bonded_chan_ptr: Pointer to const struct bonded_channel_freq.
3604  * @bw: channel bandwidth
3605  * @out_punc_pat: Output puncturing pattern
3606  *
3607  * Return - The channel state of the bonded pair.
3608  */
3609 #define SUB_CHAN_BW 20 /* 20 MHZ */
3610 #define BW_160MHZ 160
3611 #define  REG_IS_TOT_CHAN_BW_BELOW_160(_x, _y) \
3612 	(reg_is_state_allowed((_x)) && (_y) < BW_160MHZ)
3613 #define REG_IS_PRIMARY_CHAN_NOT_ALLOWED(_x, _y) \
3614 	(!reg_is_state_allowed(reg_get_channel_state_for_freq((_x), (_y))))
3615 
3616 static enum channel_state
3617 reg_get_320_bonded_channel_state(struct wlan_objmgr_pdev *pdev,
3618 				 qdf_freq_t freq,
3619 				 const struct bonded_channel_freq
3620 				 *bonded_chan_ptr,
3621 				 enum phy_ch_width bw,
3622 				 uint16_t *out_punc_pat)
3623 {
3624 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
3625 	enum channel_state temp_chan_state;
3626 	uint16_t chan_cfreq;
3627 	uint16_t max_cont_bw, i;
3628 
3629 	*out_punc_pat = ALL_SCHANS_PUNC;
3630 
3631 	if (!bonded_chan_ptr)
3632 		return chan_state;
3633 
3634 	chan_cfreq =  bonded_chan_ptr->start_freq;
3635 
3636 	max_cont_bw = 0;
3637 	i = 0;
3638 
3639 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
3640 		temp_chan_state = reg_get_channel_state_for_freq(pdev,
3641 								 chan_cfreq);
3642 		if (reg_is_state_allowed(temp_chan_state)) {
3643 			max_cont_bw += SUB_CHAN_BW;
3644 			*out_punc_pat |= BIT(i);
3645 		}
3646 
3647 		if (temp_chan_state < chan_state)
3648 			chan_state = temp_chan_state;
3649 
3650 		chan_cfreq = chan_cfreq + SUB_CHAN_BW;
3651 		i++;
3652 	}
3653 
3654 	/* After iterating through all the subchannels, if the final channel
3655 	 * state is invalid/disable, it means all our subchannels are not
3656 	 * valid and we could not find a 320 MHZ channel.
3657 	 * If we have found a channel where the max width is:
3658 	 * 1. Less than 160: there is no puncturing needed. Hence return
3659 	 * the chan state as invalid. Or if the primary freq given is not
3660 	 * supported by regulatory, the channel cannot be enabled as a
3661 	 * punctured channel. So return channel state as invalid.
3662 	 * 2. If greater than 160: Mark the invalid channels as punctured.
3663 	 * and return channel state as ENABLE.
3664 	 */
3665 	if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) ||
3666 	    REG_IS_PRIMARY_CHAN_NOT_ALLOWED(pdev, freq))
3667 		return CHANNEL_STATE_INVALID;
3668 	else
3669 		return CHANNEL_STATE_ENABLE;
3670 }
3671 
3672 /**
3673  * reg_fill_primary_160mhz_centers() - Fill the primary 160MHz segment centers
3674  * for a 320MHz channel in the given channel param.
3675  * @pdev: Pointer to struct wlan_objmgr_pdev.
3676  * @ch_param: channel params to be filled.
3677  * @freq: Input primary frequency in MHZ.
3678  *
3679  * Return: void.
3680  */
3681 static void
3682 reg_fill_primary_160mhz_centers(struct wlan_objmgr_pdev *pdev,
3683 				struct ch_params *ch_param, qdf_freq_t freq)
3684 {
3685 	const struct bonded_channel_freq *t_bonded_ch_ptr;
3686 
3687 	t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ);
3688 	if (t_bonded_ch_ptr) {
3689 		ch_param->mhz_freq_seg0 =
3690 			(t_bonded_ch_ptr->start_freq +
3691 			 t_bonded_ch_ptr->end_freq) / 2;
3692 		ch_param->center_freq_seg0 =
3693 			reg_freq_to_chan(pdev,
3694 					 ch_param->mhz_freq_seg0);
3695 	} else {
3696 		reg_err("Cannot find 160Mhz centers for freq %d", freq);
3697 		ch_param->ch_width = CH_WIDTH_INVALID;
3698 	}
3699 }
3700 
3701 /**
3702  * reg_fill_channel_list_for_320() - Fill 320MHZ channel list. If we
3703  * are unable to find a channel whose width is greater than 160MHZ and less
3704  * than 320 with the help of puncturing, using the given freq, set "update_bw"
3705  * variable to be true, lower the channel width and return to the caller.
3706  * The caller fetches a channel of reduced mode based on "update_bw" flag.
3707  *
3708  * If 320 band center is 0, return all the 320 channels
3709  * that match the primary frequency else return only channel
3710  * that matches 320 band center.
3711  *
3712  * @pdev: Pointer to struct wlan_objmgr_pdev.
3713  * @freq: Input frequency in MHZ.
3714  * @ch_width: Input channel width, if a channel of the given width is not
3715  * found, reduce the channel width to the next lower mode and pass it to the
3716  * caller.
3717  * @band_center_320: Center of 320MHZ channel.
3718  * @chan_list: Pointer to reg_channel_list to be filled.
3719  * @update_bw: Flag to hold if bw is updated.
3720  *
3721  * Return - None.
3722  */
3723 static void
3724 reg_fill_channel_list_for_320(struct wlan_objmgr_pdev *pdev,
3725 			      qdf_freq_t freq,
3726 			      enum phy_ch_width *in_ch_width,
3727 			      qdf_freq_t band_center_320,
3728 			      struct reg_channel_list *chan_list,
3729 			      bool *update_bw)
3730 {
3731 	uint8_t num_bonded_pairs, i, num_ch_params;
3732 	enum channel_state chan_state;
3733 	uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq);
3734 	uint16_t out_punc_pat;
3735 	uint16_t max_reg_bw;
3736 	enum channel_enum chan_enum;
3737 	const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL};
3738 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3739 
3740 	*update_bw = false;
3741 
3742 	chan_enum = reg_get_chan_enum_for_freq(freq);
3743 	if (chan_enum == INVALID_CHANNEL) {
3744 		reg_err("chan freq is not valid");
3745 		return;
3746 	}
3747 
3748 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3749 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3750 		reg_err("reg pdev priv obj is NULL");
3751 		return;
3752 	}
3753 
3754 	/* Maximum bandwidth of the channel supported by regulatory for
3755 	 * the given freq.
3756 	 */
3757 	max_reg_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw;
3758 
3759 	/* Regulatory does not support BW greater than 160.
3760 	 * Try finding a channel in a lower mode.
3761 	 */
3762 	if (max_reg_bw <= BW_160MHZ) {
3763 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
3764 		*update_bw = true;
3765 		return;
3766 	}
3767 
3768 	num_bonded_pairs =
3769 		reg_get_320_bonded_chan_array(pdev, freq, band_center_320,
3770 					      bonded_chan_320mhz_list_freq,
3771 					      array_size,
3772 					      bonded_ch_ptr);
3773 
3774 	if (!num_bonded_pairs) {
3775 		if (band_center_320) {
3776 			reg_debug("No bonded pair for the given band_center\n");
3777 			chan_list->num_ch_params = 0;
3778 		} else {
3779 			/* Could not find a 320 MHZ bonded channel pair,
3780 			 * find a channel of lower BW.
3781 			 */
3782 			*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
3783 			*update_bw = true;
3784 		}
3785 		return;
3786 	}
3787 
3788 	for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) {
3789 		/* Chan_state to hold the channel state of bonding
3790 		 * pair of channels.
3791 		 */
3792 		chan_state =
3793 		    reg_get_320_bonded_channel_state(pdev, freq,
3794 						     bonded_ch_ptr[i],
3795 						     *in_ch_width,
3796 						     &out_punc_pat);
3797 		if (chan_state == CHANNEL_STATE_ENABLE) {
3798 			struct ch_params *t_chan_param =
3799 			    &chan_list->chan_param[num_ch_params];
3800 
3801 			t_chan_param->mhz_freq_seg1 =
3802 				(bonded_ch_ptr[i]->start_freq +
3803 				 bonded_ch_ptr[i]->end_freq) / 2;
3804 			t_chan_param->center_freq_seg1 =
3805 				reg_freq_to_chan(pdev,
3806 						 t_chan_param->mhz_freq_seg1);
3807 			t_chan_param->ch_width = *in_ch_width;
3808 			t_chan_param->reg_punc_pattern = out_punc_pat;
3809 
3810 			reg_fill_primary_160mhz_centers(pdev,
3811 							t_chan_param,
3812 							freq);
3813 			num_ch_params++;
3814 			chan_list->num_ch_params = num_ch_params;
3815 		}
3816 	}
3817 
3818 	/* The bonded pairs could not create any channels,
3819 	 * lower the bandwidth to find a channel.
3820 	 */
3821 	if (!chan_list->num_ch_params) {
3822 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
3823 		*update_bw = true;
3824 	}
3825 }
3826 
3827 /**
3828  * No subchannels are punctured
3829  * binary 0:- Punctured 1:- Not-Punctured.
3830  */
3831 #define NO_SCHANS_PUNC 0xFFFF
3832 
3833 /**
3834  * reg_fill_pre320mhz_channel() - Fill channel params for channel width
3835  * less than 320.
3836  * @pdev: Pointer to struct wlan_objmgr_pdev
3837  * @chan_list: Pointer to struct reg_channel_list
3838  * @ch_width: Channel width
3839  * @freq: Center frequency of the primary channel in MHz
3840  * @sec_ch_2g_freq:  Secondary 2G channel frequency in MHZ
3841  */
3842 static void
3843 reg_fill_pre320mhz_channel(struct wlan_objmgr_pdev *pdev,
3844 			   struct reg_channel_list *chan_list,
3845 			   enum phy_ch_width ch_width,
3846 			   qdf_freq_t freq,
3847 			   qdf_freq_t sec_ch_2g_freq)
3848 {
3849 	chan_list->num_ch_params = 1;
3850 	chan_list->chan_param[0].ch_width = ch_width;
3851 	chan_list->chan_param[0].reg_punc_pattern = NO_SCHANS_PUNC;
3852 	reg_set_channel_params_for_freq(pdev, freq, sec_ch_2g_freq,
3853 					&chan_list->chan_param[0]);
3854 }
3855 
3856 void
3857 reg_fill_channel_list(struct wlan_objmgr_pdev *pdev,
3858 		      qdf_freq_t freq,
3859 		      qdf_freq_t sec_ch_2g_freq,
3860 		      enum phy_ch_width in_ch_width,
3861 		      qdf_freq_t band_center_320,
3862 		      struct reg_channel_list *chan_list)
3863 {
3864 	bool update_bw;
3865 
3866 	if (!chan_list) {
3867 		reg_err("channel params is NULL");
3868 		return;
3869 	}
3870 
3871 	if (in_ch_width >= CH_WIDTH_MAX)
3872 		in_ch_width = CH_WIDTH_320MHZ;
3873 
3874 	if (in_ch_width == CH_WIDTH_320MHZ) {
3875 		update_bw = 0;
3876 		reg_fill_channel_list_for_320(pdev, freq, &in_ch_width,
3877 					      band_center_320, chan_list,
3878 					      &update_bw);
3879 		if (!update_bw)
3880 			return;
3881 	}
3882 
3883 	/* A 320 channel is not available (or) user has not requested
3884 	 * for a 320MHZ channel, look for channels in lower modes,
3885 	 * reg_set_5g_channel_params_for_freq() finds for the
3886 	 * next available mode and fills ch_params.
3887 	 */
3888 	reg_fill_pre320mhz_channel(pdev, chan_list, in_ch_width, freq,
3889 				   sec_ch_2g_freq);
3890 }
3891 #endif
3892 
3893 #if defined(WLAN_FEATURE_11BE) && defined(CONFIG_REG_CLIENT)
3894 enum channel_state
3895 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev,
3896 				   uint16_t freq,
3897 				   enum phy_ch_width ch_width,
3898 				   const struct bonded_channel_freq
3899 				   **bonded_chan_ptr_ptr)
3900 {
3901 	if (ch_width == CH_WIDTH_20MHZ)
3902 		return reg_get_channel_state_for_freq(pdev, freq);
3903 
3904 	if (ch_width == CH_WIDTH_320MHZ) {
3905 		uint8_t num_bonded_pairs;
3906 		uint16_t array_size =
3907 				QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq);
3908 		const struct bonded_channel_freq *bonded_ch_ptr[2] = {
3909 								NULL, NULL};
3910 		uint16_t punct_pattern;
3911 
3912 		/* For now sending band center freq as 0 */
3913 		num_bonded_pairs =
3914 			reg_get_320_bonded_chan_array(
3915 						pdev, freq, 0,
3916 						bonded_chan_320mhz_list_freq,
3917 						array_size, bonded_ch_ptr);
3918 		if (!num_bonded_pairs) {
3919 			reg_info("No 320MHz bonded pair for freq %d", freq);
3920 			return CHANNEL_STATE_INVALID;
3921 		}
3922 		/* Taking only first bonded pair */
3923 		*bonded_chan_ptr_ptr = bonded_ch_ptr[0];
3924 
3925 		return reg_get_320_bonded_channel_state(pdev, freq,
3926 							bonded_ch_ptr[0],
3927 							ch_width,
3928 							&punct_pattern);
3929 	} else {
3930 		*bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq,
3931 								 ch_width);
3932 		if (!(*bonded_chan_ptr_ptr))
3933 			return CHANNEL_STATE_INVALID;
3934 
3935 		return reg_get_5g_bonded_chan_array_for_freq(
3936 							pdev, freq,
3937 							*bonded_chan_ptr_ptr);
3938 	}
3939 }
3940 #else
3941 enum channel_state
3942 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev,
3943 				   uint16_t freq,
3944 				   enum phy_ch_width ch_width,
3945 				   const struct bonded_channel_freq
3946 				   **bonded_chan_ptr_ptr)
3947 
3948 {
3949 	if (ch_width == CH_WIDTH_20MHZ)
3950 		return reg_get_channel_state_for_freq(pdev, freq);
3951 
3952 	/* Fetch the bonded_chan_ptr for width greater than 20MHZ. */
3953 	*bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width);
3954 
3955 	if (!(*bonded_chan_ptr_ptr)) {
3956 		reg_debug_rl("bonded_chan_ptr_ptr is NULL");
3957 		return CHANNEL_STATE_INVALID;
3958 	}
3959 
3960 	return reg_get_5g_bonded_chan_array_for_freq(pdev, freq,
3961 						     *bonded_chan_ptr_ptr);
3962 }
3963 #endif
3964 
3965 /**
3966  * reg_set_5g_channel_params_for_freq()- Set channel parameters like center
3967  * frequency for a bonded channel state. Also return the maximum bandwidth
3968  * supported by the channel.
3969  * @pdev: Pointer to pdev.
3970  * @freq: Channel center frequency.
3971  * ch_params: Pointer to ch_params.
3972  *
3973  * Return: void
3974  */
3975 static void reg_set_5g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
3976 					       uint16_t freq,
3977 					       struct ch_params *ch_params)
3978 {
3979 	/*
3980 	 * Set channel parameters like center frequency for a bonded channel
3981 	 * state. Also return the maximum bandwidth supported by the channel.
3982 	 */
3983 
3984 	enum channel_state chan_state = CHANNEL_STATE_ENABLE;
3985 	enum channel_state chan_state2 = CHANNEL_STATE_ENABLE;
3986 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
3987 	const struct bonded_channel_freq *bonded_chan_ptr2 = NULL;
3988 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3989 	enum channel_enum chan_enum, sec_5g_chan_enum;
3990 	uint16_t max_bw, bw_80, sec_5g_freq_max_bw = 0;
3991 
3992 	if (!ch_params) {
3993 		reg_err("ch_params is NULL");
3994 		return;
3995 	}
3996 
3997 	chan_enum = reg_get_chan_enum_for_freq(freq);
3998 	if (chan_enum == INVALID_CHANNEL) {
3999 		reg_err("chan freq is not valid");
4000 		return;
4001 	}
4002 
4003 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4004 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4005 		reg_err("reg pdev priv obj is NULL");
4006 		return;
4007 	}
4008 
4009 	if (ch_params->ch_width >= CH_WIDTH_MAX) {
4010 		if (ch_params->mhz_freq_seg1 != 0)
4011 			ch_params->ch_width = CH_WIDTH_80P80MHZ;
4012 		else
4013 			ch_params->ch_width = CH_WIDTH_160MHZ;
4014 	}
4015 
4016 	max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw;
4017 	bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ);
4018 
4019 	if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
4020 		sec_5g_chan_enum =
4021 			reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 -
4022 					NEAREST_20MHZ_CHAN_FREQ_OFFSET);
4023 		if (sec_5g_chan_enum == INVALID_CHANNEL) {
4024 			reg_err("secondary channel freq is not valid");
4025 			return;
4026 		}
4027 
4028 		sec_5g_freq_max_bw =
4029 			pdev_priv_obj->cur_chan_list[sec_5g_chan_enum].max_bw;
4030 	}
4031 
4032 	while (ch_params->ch_width != CH_WIDTH_INVALID) {
4033 		if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
4034 			if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80))
4035 				goto update_bw;
4036 		} else if (max_bw < reg_get_bw_value(ch_params->ch_width)) {
4037 			goto update_bw;
4038 		}
4039 
4040 		bonded_chan_ptr = NULL;
4041 		bonded_chan_ptr2 = NULL;
4042 		chan_state = reg_get_5g_bonded_channel_for_freq(
4043 				pdev, freq, ch_params->ch_width,
4044 				&bonded_chan_ptr);
4045 
4046 		chan_state = reg_get_5g_bonded_channel_state_for_freq(
4047 				pdev, freq, ch_params->ch_width);
4048 
4049 		if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
4050 			chan_state2 = reg_get_5g_bonded_channel_state_for_freq(
4051 					pdev, ch_params->mhz_freq_seg1 -
4052 					NEAREST_20MHZ_CHAN_FREQ_OFFSET,
4053 					CH_WIDTH_80MHZ);
4054 
4055 			chan_state = reg_combine_channel_states(
4056 					chan_state, chan_state2);
4057 		}
4058 
4059 		if ((chan_state != CHANNEL_STATE_ENABLE) &&
4060 		    (chan_state != CHANNEL_STATE_DFS))
4061 			goto update_bw;
4062 		if (ch_params->ch_width <= CH_WIDTH_20MHZ) {
4063 			ch_params->sec_ch_offset = NO_SEC_CH;
4064 			ch_params->mhz_freq_seg0 = freq;
4065 				ch_params->center_freq_seg0 =
4066 				reg_freq_to_chan(pdev,
4067 						 ch_params->mhz_freq_seg0);
4068 			break;
4069 		} else if (ch_params->ch_width >= CH_WIDTH_40MHZ) {
4070 			bonded_chan_ptr2 =
4071 				reg_get_bonded_chan_entry(freq, CH_WIDTH_40MHZ);
4072 
4073 			if (!bonded_chan_ptr || !bonded_chan_ptr2)
4074 				goto update_bw;
4075 			if (freq == bonded_chan_ptr2->start_freq)
4076 				ch_params->sec_ch_offset = LOW_PRIMARY_CH;
4077 			else
4078 				ch_params->sec_ch_offset = HIGH_PRIMARY_CH;
4079 
4080 			ch_params->mhz_freq_seg0 =
4081 				(bonded_chan_ptr->start_freq +
4082 				 bonded_chan_ptr->end_freq) / 2;
4083 				ch_params->center_freq_seg0 =
4084 				reg_freq_to_chan(pdev,
4085 						 ch_params->mhz_freq_seg0);
4086 			break;
4087 		}
4088 update_bw:
4089 		ch_params->ch_width =
4090 		    get_next_lower_bandwidth(ch_params->ch_width);
4091 	}
4092 
4093 	if (ch_params->ch_width == CH_WIDTH_160MHZ) {
4094 		ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0;
4095 			ch_params->center_freq_seg1 =
4096 				reg_freq_to_chan(pdev,
4097 						 ch_params->mhz_freq_seg1);
4098 
4099 		chan_state = reg_get_5g_bonded_channel_for_freq(
4100 				pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr);
4101 		if (bonded_chan_ptr) {
4102 			ch_params->mhz_freq_seg0 =
4103 				(bonded_chan_ptr->start_freq +
4104 				 bonded_chan_ptr->end_freq) / 2;
4105 				ch_params->center_freq_seg0 =
4106 				reg_freq_to_chan(pdev,
4107 						 ch_params->mhz_freq_seg0);
4108 		}
4109 	}
4110 
4111 	/* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */
4112 	if (!(ch_params->ch_width == CH_WIDTH_160MHZ ||
4113 	      ch_params->ch_width == CH_WIDTH_80P80MHZ)) {
4114 		ch_params->mhz_freq_seg1 = 0;
4115 		ch_params->center_freq_seg1 = 0;
4116 	}
4117 }
4118 
4119 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
4120 					uint16_t oper_freq,
4121 					struct ch_params *ch_params,
4122 					uint16_t sec_ch_2g_freq)
4123 {
4124 	enum channel_state chan_state = CHANNEL_STATE_ENABLE;
4125 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4126 	enum channel_enum chan_enum;
4127 	uint16_t max_bw;
4128 
4129 	chan_enum = reg_get_chan_enum_for_freq(oper_freq);
4130 	if (chan_enum == INVALID_CHANNEL) {
4131 		reg_err("chan freq is not valid");
4132 		return;
4133 	}
4134 
4135 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4136 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4137 		reg_err("reg pdev priv obj is NULL");
4138 		return;
4139 	}
4140 
4141 	if (ch_params->ch_width >= CH_WIDTH_MAX)
4142 		ch_params->ch_width = CH_WIDTH_40MHZ;
4143 	if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq) {
4144 		if (oper_freq >= TWOG_CHAN_1_IN_MHZ && oper_freq <=
4145 				TWOG_CHAN_5_IN_MHZ)
4146 			sec_ch_2g_freq = oper_freq + 20;
4147 		else if (oper_freq >= TWOG_CHAN_6_IN_MHZ && oper_freq <=
4148 				TWOG_CHAN_13_IN_MHZ)
4149 			sec_ch_2g_freq = oper_freq - 20;
4150 	}
4151 
4152 	max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw;
4153 
4154 	while (ch_params->ch_width != CH_WIDTH_INVALID) {
4155 		if (max_bw < reg_get_bw_value(ch_params->ch_width))
4156 			goto update_bw;
4157 
4158 		chan_state =
4159 		reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq,
4160 							 sec_ch_2g_freq,
4161 							 ch_params->ch_width);
4162 		if ((chan_state == CHANNEL_STATE_ENABLE) ||
4163 		    (chan_state == CHANNEL_STATE_DFS)) {
4164 			if (ch_params->ch_width == CH_WIDTH_40MHZ) {
4165 				if (oper_freq < sec_ch_2g_freq)
4166 					ch_params->sec_ch_offset =
4167 						LOW_PRIMARY_CH;
4168 				else
4169 					ch_params->sec_ch_offset =
4170 						HIGH_PRIMARY_CH;
4171 				ch_params->mhz_freq_seg0 =
4172 					(oper_freq + sec_ch_2g_freq) / 2;
4173 				if (ch_params->mhz_freq_seg0 ==
4174 						TWOG_CHAN_14_IN_MHZ)
4175 					ch_params->center_freq_seg0 = 14;
4176 				else
4177 					ch_params->center_freq_seg0 =
4178 						(ch_params->mhz_freq_seg0 -
4179 						 TWOG_STARTING_FREQ) /
4180 						FREQ_TO_CHAN_SCALE;
4181 			} else {
4182 				ch_params->sec_ch_offset = NO_SEC_CH;
4183 				ch_params->mhz_freq_seg0 = oper_freq;
4184 				if (ch_params->mhz_freq_seg0 ==
4185 						TWOG_CHAN_14_IN_MHZ)
4186 					ch_params->center_freq_seg0 = 14;
4187 				else
4188 					ch_params->center_freq_seg0 =
4189 						(ch_params->mhz_freq_seg0 -
4190 						 TWOG_STARTING_FREQ) /
4191 						FREQ_TO_CHAN_SCALE;
4192 			}
4193 			break;
4194 		}
4195 update_bw:
4196 		ch_params->ch_width =
4197 		    get_next_lower_bandwidth(ch_params->ch_width);
4198 	}
4199 	/* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */
4200 	ch_params->mhz_freq_seg1 = 0;
4201 	ch_params->center_freq_seg1 = 0;
4202 }
4203 
4204 #if defined(WLAN_FEATURE_11BE) && defined(CONFIG_REG_CLIENT)
4205 static void reg_copy_ch_params(struct ch_params *ch_params,
4206 			       struct reg_channel_list chan_list)
4207 {
4208 	/* Taking only first set of chan params*/
4209 	if (chan_list.chan_param[0].ch_width != CH_WIDTH_320MHZ)
4210 		reg_info("coud not find ch_params for 320MHz downgrading to %d",
4211 			 chan_list.chan_param[0].ch_width);
4212 	ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0;
4213 	ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1;
4214 	ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0;
4215 	ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1;
4216 	ch_params->ch_width = chan_list.chan_param[0].ch_width;
4217 	ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset;
4218 	ch_params->reg_punc_pattern = chan_list.chan_param[0].reg_punc_pattern;
4219 }
4220 
4221 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
4222 				     qdf_freq_t freq,
4223 				     qdf_freq_t sec_ch_2g_freq,
4224 				     struct ch_params *ch_params)
4225 {
4226 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) {
4227 		if (ch_params->ch_width == CH_WIDTH_320MHZ) {
4228 			struct reg_channel_list chan_list;
4229 
4230 			qdf_mem_zero(&chan_list, sizeof(chan_list));
4231 			/* For now sending center freq as 0 */
4232 			reg_fill_channel_list(pdev, freq, sec_ch_2g_freq,
4233 					      ch_params->ch_width, 0,
4234 					      &chan_list);
4235 			reg_copy_ch_params(ch_params, chan_list);
4236 		} else {
4237 			reg_set_5g_channel_params_for_freq(pdev, freq,
4238 							   ch_params);
4239 		}
4240 	} else if  (reg_is_24ghz_ch_freq(freq)) {
4241 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
4242 						   sec_ch_2g_freq);
4243 	}
4244 }
4245 #else
4246 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
4247 				     qdf_freq_t freq,
4248 				     qdf_freq_t sec_ch_2g_freq,
4249 				     struct ch_params *ch_params)
4250 {
4251 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq))
4252 		reg_set_5g_channel_params_for_freq(pdev, freq, ch_params);
4253 	else if  (reg_is_24ghz_ch_freq(freq))
4254 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
4255 						   sec_ch_2g_freq);
4256 }
4257 #endif
4258 
4259 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev,
4260 					   qdf_freq_t freq)
4261 {
4262 	enum channel_enum chan_enum;
4263 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4264 	struct regulatory_channel *reg_channels;
4265 
4266 	chan_enum = reg_get_chan_enum_for_freq(freq);
4267 
4268 	if (chan_enum == INVALID_CHANNEL) {
4269 		reg_err("channel is invalid");
4270 		return REG_INVALID_TXPOWER;
4271 	}
4272 
4273 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4274 
4275 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4276 		reg_err("reg pdev priv obj is NULL");
4277 		return REG_INVALID_TXPOWER;
4278 	}
4279 
4280 	reg_channels = pdev_priv_obj->cur_chan_list;
4281 
4282 	return reg_channels[chan_enum].tx_power;
4283 }
4284 
4285 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
4286 {
4287 	uint32_t chan_flags;
4288 
4289 	chan_flags = reg_get_channel_flags_for_freq(pdev, freq);
4290 
4291 	return chan_flags & REGULATORY_CHAN_RADAR;
4292 }
4293 
4294 #ifdef CONFIG_REG_CLIENT
4295 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev,
4296 					   qdf_freq_t freq)
4297 {
4298 	uint32_t chan_flags;
4299 
4300 	chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev,
4301 									freq);
4302 
4303 	return chan_flags & REGULATORY_CHAN_RADAR;
4304 }
4305 
4306 /**
4307  * reg_get_psoc_mas_chan_list () - Get psoc master channel list
4308  * @pdev: pointer to pdev object
4309  * @psoc: pointer to psoc object
4310  *
4311  * Return: psoc master chanel list
4312  */
4313 static struct regulatory_channel *reg_get_psoc_mas_chan_list(
4314 						struct wlan_objmgr_pdev *pdev,
4315 						struct wlan_objmgr_psoc *psoc)
4316 {
4317 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
4318 	uint8_t pdev_id;
4319 	uint8_t phy_id;
4320 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
4321 
4322 	soc_reg = reg_get_psoc_obj(psoc);
4323 	if (!soc_reg) {
4324 		reg_err("reg psoc private obj is NULL");
4325 		return NULL;
4326 	}
4327 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
4328 
4329 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
4330 	if (reg_tx_ops->get_phy_id_from_pdev_id)
4331 		reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
4332 	else
4333 		phy_id = pdev_id;
4334 
4335 	return soc_reg->mas_chan_params[phy_id].mas_chan_list;
4336 }
4337 #else
4338 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list(
4339 						struct wlan_objmgr_pdev *pdev,
4340 						struct wlan_objmgr_psoc *psoc)
4341 {
4342 	return NULL;
4343 }
4344 #endif
4345 
4346 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev,
4347 				uint16_t *chan_freq_list,
4348 				uint8_t num_chan,
4349 				bool nol_chan)
4350 {
4351 	enum channel_enum chan_enum;
4352 	struct regulatory_channel *mas_chan_list, *psoc_mas_chan_list;
4353 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4354 	struct wlan_objmgr_psoc *psoc;
4355 	uint16_t i;
4356 
4357 	if (!num_chan || !chan_freq_list) {
4358 		reg_err("chan_freq_list or num_ch is NULL");
4359 		return;
4360 	}
4361 
4362 	psoc = wlan_pdev_get_psoc(pdev);
4363 
4364 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4365 	if (!pdev_priv_obj) {
4366 		reg_err("reg pdev private obj is NULL");
4367 		return;
4368 	}
4369 
4370 	psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc);
4371 
4372 	mas_chan_list = pdev_priv_obj->mas_chan_list;
4373 	for (i = 0; i < num_chan; i++) {
4374 		chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]);
4375 		if (chan_enum == INVALID_CHANNEL) {
4376 			reg_err("Invalid freq in nol list, freq %d",
4377 				chan_freq_list[i]);
4378 			continue;
4379 		}
4380 		mas_chan_list[chan_enum].nol_chan = nol_chan;
4381 		if (psoc_mas_chan_list)
4382 			psoc_mas_chan_list[chan_enum].nol_chan = nol_chan;
4383 	}
4384 
4385 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
4386 
4387 	reg_send_scheduler_msg_sb(psoc, pdev);
4388 }
4389 
4390 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev,
4391 					uint16_t *chan_list,
4392 					uint8_t num_chan,
4393 					bool nol_history_chan)
4394 {
4395 	enum channel_enum chan_enum;
4396 	struct regulatory_channel *mas_chan_list;
4397 	struct regulatory_channel *cur_chan_list;
4398 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4399 	uint16_t i;
4400 
4401 	if (!num_chan || !chan_list) {
4402 		reg_err("chan_list or num_ch is NULL");
4403 		return;
4404 	}
4405 
4406 	pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(
4407 			pdev, WLAN_UMAC_COMP_REGULATORY);
4408 
4409 	if (!pdev_priv_obj) {
4410 		reg_err("reg psoc private obj is NULL");
4411 		return;
4412 	}
4413 
4414 	mas_chan_list = pdev_priv_obj->mas_chan_list;
4415 	cur_chan_list = pdev_priv_obj->cur_chan_list;
4416 
4417 	for (i = 0; i < num_chan; i++) {
4418 		chan_enum = reg_get_chan_enum_for_freq(chan_list[i]);
4419 		if (chan_enum == INVALID_CHANNEL) {
4420 			reg_err("Invalid ch in nol list, chan %d",
4421 				chan_list[i]);
4422 			continue;
4423 		}
4424 		mas_chan_list[chan_enum].nol_history = nol_history_chan;
4425 		cur_chan_list[chan_enum].nol_history = nol_history_chan;
4426 	}
4427 }
4428 
4429 static inline bool REG_IS_FREQUENCY_VALID_5G_SBS(qdf_freq_t curfreq,
4430 						 qdf_freq_t newfreq)
4431 {
4432 	return ((curfreq) > (newfreq) ?
4433 	REG_CH_TO_FREQ(reg_get_chan_enum_for_freq(curfreq))
4434 	- REG_CH_TO_FREQ(reg_get_chan_enum_for_freq(newfreq))
4435 	> REG_SBS_SEPARATION_THRESHOLD :
4436 	REG_CH_TO_FREQ(reg_get_chan_enum_for_freq(newfreq))
4437 	- REG_CH_TO_FREQ(reg_get_chan_enum_for_freq(curfreq))
4438 	> REG_SBS_SEPARATION_THRESHOLD);
4439 }
4440 
4441 bool reg_is_frequency_valid_5g_sbs(qdf_freq_t curfreq, qdf_freq_t newfreq)
4442 {
4443 	return REG_IS_FREQUENCY_VALID_5G_SBS(curfreq, newfreq);
4444 }
4445 
4446 qdf_freq_t reg_min_chan_freq(void)
4447 {
4448 	return channel_map[MIN_24GHZ_CHANNEL].center_freq;
4449 }
4450 
4451 qdf_freq_t reg_max_chan_freq(void)
4452 {
4453 	return channel_map[NUM_CHANNELS - 1].center_freq;
4454 }
4455 
4456 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2)
4457 {
4458 	return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) &&
4459 				    REG_IS_6GHZ_FREQ(freq2)) ||
4460 				   (REG_IS_5GHZ_FREQ(freq1) &&
4461 				    REG_IS_5GHZ_FREQ(freq2)) ||
4462 				   (REG_IS_24GHZ_CH_FREQ(freq1) &&
4463 				    REG_IS_24GHZ_CH_FREQ(freq2))));
4464 }
4465 
4466 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq)
4467 {
4468 	if (REG_IS_24GHZ_CH_FREQ(freq))
4469 		return REG_BAND_2G;
4470 	else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq))
4471 		return REG_BAND_5G;
4472 	else if (REG_IS_6GHZ_FREQ(freq))
4473 		return REG_BAND_6G;
4474 	return REG_BAND_UNKNOWN;
4475 }
4476 
4477 bool reg_is_disable_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
4478 {
4479 	enum channel_state ch_state;
4480 
4481 	ch_state = reg_get_channel_state_for_freq(pdev, freq);
4482 
4483 	return ch_state == CHANNEL_STATE_DISABLE;
4484 }
4485 
4486 #ifdef CONFIG_REG_CLIENT
4487 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev,
4488 					       qdf_freq_t freq)
4489 {
4490 	enum channel_state ch_state;
4491 
4492 	ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev,
4493 								      freq);
4494 
4495 	return ch_state == CHANNEL_STATE_DISABLE;
4496 }
4497 #endif
4498 
4499 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
4500 {
4501 	uint32_t chan_flags;
4502 
4503 	chan_flags = reg_get_channel_flags_for_freq(pdev, freq);
4504 
4505 	return chan_flags & REGULATORY_CHAN_NO_IR;
4506 }
4507 #endif /* CONFIG_CHAN_FREQ_API */
4508 
4509 uint8_t  reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev)
4510 {
4511 	struct regulatory_channel *cur_chan_list;
4512 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4513 	uint8_t i, max_tx_power = 0;
4514 
4515 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4516 
4517 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4518 		reg_err("reg pdev private obj is NULL");
4519 		return QDF_STATUS_E_FAILURE;
4520 	}
4521 
4522 	cur_chan_list = pdev_priv_obj->cur_chan_list;
4523 
4524 	for (i = 0; i < NUM_CHANNELS; i++) {
4525 		if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE &&
4526 		    cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) {
4527 			if (cur_chan_list[i].tx_power > max_tx_power)
4528 				max_tx_power = cur_chan_list[i].tx_power;
4529 		}
4530 	}
4531 
4532 	if (!max_tx_power)
4533 		reg_err_rl("max_tx_power is zero");
4534 
4535 	return max_tx_power;
4536 }
4537 
4538 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc)
4539 {
4540 	struct wlan_regulatory_psoc_priv_obj *psoc_reg;
4541 
4542 	psoc_reg = reg_get_psoc_obj(psoc);
4543 	if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) {
4544 		reg_err("psoc reg component is NULL");
4545 		return QDF_STATUS_E_INVAL;
4546 	}
4547 
4548 	psoc_reg->ignore_fw_reg_offload_ind = true;
4549 	return QDF_STATUS_SUCCESS;
4550 }
4551 
4552 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc)
4553 {
4554 	struct wlan_regulatory_psoc_priv_obj *psoc_reg;
4555 
4556 	psoc_reg = reg_get_psoc_obj(psoc);
4557 	if (!IS_VALID_PSOC_REG_OBJ(psoc_reg))
4558 		return false;
4559 
4560 	return psoc_reg->ignore_fw_reg_offload_ind;
4561 }
4562 
4563 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val)
4564 {
4565 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
4566 
4567 	psoc_priv_obj = reg_get_psoc_obj(psoc);
4568 
4569 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
4570 		reg_err("psoc reg component is NULL");
4571 		return QDF_STATUS_E_FAILURE;
4572 	}
4573 
4574 	psoc_priv_obj->six_ghz_supported = val;
4575 
4576 	return QDF_STATUS_SUCCESS;
4577 }
4578 
4579 QDF_STATUS
4580 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val)
4581 {
4582 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
4583 
4584 	psoc_priv_obj = reg_get_psoc_obj(psoc);
4585 
4586 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
4587 		reg_err("psoc reg component is NULL");
4588 		return QDF_STATUS_E_FAILURE;
4589 	}
4590 
4591 	psoc_priv_obj->five_dot_nine_ghz_supported = val;
4592 
4593 	return QDF_STATUS_SUCCESS;
4594 }
4595 
4596 #ifdef CONFIG_REG_CLIENT
4597 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc)
4598 {
4599 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
4600 
4601 	psoc_priv_obj = reg_get_psoc_obj(psoc);
4602 
4603 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
4604 		reg_err("psoc reg component is NULL");
4605 		return  false;
4606 	}
4607 
4608 	return psoc_priv_obj->six_ghz_supported;
4609 }
4610 #endif
4611 
4612 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc)
4613 {
4614 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
4615 
4616 	psoc_priv_obj = reg_get_psoc_obj(psoc);
4617 
4618 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
4619 		reg_err("psoc reg component is NULL");
4620 		return  false;
4621 	}
4622 
4623 	return psoc_priv_obj->five_dot_nine_ghz_supported;
4624 }
4625 
4626 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev)
4627 {
4628 	struct cur_regdmn_info cur_reg_dmn;
4629 	QDF_STATUS status;
4630 
4631 	status = reg_get_curr_regdomain(pdev, &cur_reg_dmn);
4632 	if (status != QDF_STATUS_SUCCESS) {
4633 		reg_err_rl("Failed to get reg domain");
4634 		return false;
4635 	}
4636 
4637 	return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g);
4638 }
4639 
4640 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
4641 {
4642 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4643 
4644 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4645 
4646 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4647 		reg_err("reg pdev priv obj is NULL");
4648 		return false;
4649 	}
4650 
4651 	return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq &&
4652 		freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq);
4653 }
4654 
4655 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
4656 {
4657 	struct wlan_objmgr_psoc *psoc;
4658 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
4659 
4660 	if (!pdev) {
4661 		reg_alert("pdev is NULL");
4662 		return true;
4663 	}
4664 	psoc = wlan_pdev_get_psoc(pdev);
4665 
4666 	psoc_priv_obj = reg_get_psoc_obj(psoc);
4667 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
4668 		reg_alert("psoc reg component is NULL");
4669 		return true;
4670 	}
4671 
4672 	return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode;
4673 }
4674 
4675 #ifdef DISABLE_UNII_SHARED_BANDS
4676 QDF_STATUS
4677 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap)
4678 {
4679 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4680 
4681 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4682 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4683 		reg_err_rl("pdev reg component is NULL");
4684 		return QDF_STATUS_E_FAILURE;
4685 	}
4686 	*bitmap =  pdev_priv_obj->unii_5g_bitmap;
4687 
4688 	return QDF_STATUS_SUCCESS;
4689 }
4690 #endif
4691 
4692 #ifdef WLAN_FEATURE_11BE
4693 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap)
4694 {
4695 	if (!phymode_bitmap)
4696 		return false;
4697 
4698 	if (phy_in == REG_PHYMODE_11BE)
4699 		return phymode_bitmap & REGULATORY_PHYMODE_NO11BE;
4700 	else if (phy_in == REG_PHYMODE_11AX)
4701 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AX;
4702 	else if (phy_in == REG_PHYMODE_11AC)
4703 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AC;
4704 	else if (phy_in == REG_PHYMODE_11N)
4705 		return phymode_bitmap & REGULATORY_CHAN_NO11N;
4706 	else if (phy_in == REG_PHYMODE_11G)
4707 		return phymode_bitmap & REGULATORY_PHYMODE_NO11G;
4708 	else if (phy_in == REG_PHYMODE_11A)
4709 		return phymode_bitmap & REGULATORY_PHYMODE_NO11A;
4710 	else if (phy_in == REG_PHYMODE_11B)
4711 		return phymode_bitmap & REGULATORY_PHYMODE_NO11B;
4712 	else
4713 		return true;
4714 }
4715 #else
4716 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap)
4717 {
4718 	if (!phymode_bitmap)
4719 		return false;
4720 
4721 	if (phy_in == REG_PHYMODE_11AX)
4722 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AX;
4723 	else if (phy_in == REG_PHYMODE_11AC)
4724 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AC;
4725 	else if (phy_in == REG_PHYMODE_11N)
4726 		return phymode_bitmap & REGULATORY_CHAN_NO11N;
4727 	else if (phy_in == REG_PHYMODE_11G)
4728 		return phymode_bitmap & REGULATORY_PHYMODE_NO11G;
4729 	else if (phy_in == REG_PHYMODE_11A)
4730 		return phymode_bitmap & REGULATORY_PHYMODE_NO11A;
4731 	else if (phy_in == REG_PHYMODE_11B)
4732 		return phymode_bitmap & REGULATORY_PHYMODE_NO11B;
4733 	else
4734 		return true;
4735 }
4736 #endif
4737 
4738 #ifdef CHECK_REG_PHYMODE
4739 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev,
4740 				     enum reg_phymode phy_in,
4741 				     qdf_freq_t freq)
4742 {
4743 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4744 	uint32_t phymode_bitmap;
4745 	enum reg_phymode current_phymode = phy_in;
4746 
4747 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4748 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4749 		reg_err("pdev reg component is NULL");
4750 		return REG_PHYMODE_INVALID;
4751 	}
4752 
4753 	phymode_bitmap = pdev_priv_obj->phybitmap;
4754 
4755 	while (1) {
4756 		if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) {
4757 			if (current_phymode == REG_PHYMODE_11N) {
4758 				if (REG_IS_24GHZ_CH_FREQ(freq))
4759 					current_phymode = REG_PHYMODE_11G;
4760 				else
4761 					current_phymode = REG_PHYMODE_11A;
4762 			} else if (current_phymode == REG_PHYMODE_11A ||
4763 				   current_phymode == REG_PHYMODE_11B) {
4764 				reg_err("Couldn't find a suitable phymode");
4765 				return REG_PHYMODE_INVALID;
4766 			} else if (current_phymode > REG_PHYMODE_MAX) {
4767 				reg_err("Unknown phymode");
4768 				return REG_PHYMODE_INVALID;
4769 			} else {
4770 				current_phymode--;
4771 			}
4772 		} else {
4773 			return current_phymode;
4774 		}
4775 	}
4776 }
4777 #endif /* CHECK_REG_PHYMODE */
4778 
4779 #ifdef CONFIG_REG_CLIENT
4780 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap)
4781 {
4782 	if ((band_bitmap & BIT(REG_BAND_2G)) &&
4783 	    (band_bitmap & BIT(REG_BAND_5G)) &&
4784 	    (band_bitmap & BIT(REG_BAND_6G)))
4785 		return BAND_ALL;
4786 	else if ((band_bitmap & BIT(REG_BAND_5G)) &&
4787 		 (band_bitmap & BIT(REG_BAND_6G)))
4788 		return BAND_5G;
4789 	else if ((band_bitmap & BIT(REG_BAND_2G)) &&
4790 		 (band_bitmap & BIT(REG_BAND_6G)))
4791 		return BAND_2G;
4792 	else if ((band_bitmap & BIT(REG_BAND_2G)) &&
4793 		 (band_bitmap & BIT(REG_BAND_5G)))
4794 		return BAND_ALL;
4795 	else if (band_bitmap & BIT(REG_BAND_2G))
4796 		return BAND_2G;
4797 	else if (band_bitmap & BIT(REG_BAND_5G))
4798 		return BAND_5G;
4799 	else if (band_bitmap & BIT(REG_BAND_6G))
4800 		return BAND_2G;
4801 	else
4802 		return BAND_UNKNOWN;
4803 }
4804 #endif
4805 
4806 #if defined(CONFIG_BAND_6GHZ)
4807 QDF_STATUS
4808 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
4809 			   enum reg_6g_ap_type reg_cur_6g_ap_pwr_type)
4810 {
4811 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4812 
4813 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4814 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4815 		reg_err("pdev reg component is NULL");
4816 		return QDF_STATUS_E_FAILURE;
4817 	}
4818 
4819 	if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) {
4820 		reg_err("Unsupported 6G AP power type");
4821 		return QDF_STATUS_E_FAILURE;
4822 	}
4823 	/* should we validate the input reg_cur_6g_ap_type? */
4824 	pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type;
4825 	return QDF_STATUS_SUCCESS;
4826 }
4827 
4828 QDF_STATUS
4829 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
4830 			   enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type)
4831 {
4832 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4833 
4834 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4835 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4836 		reg_err("pdev reg component is NULL");
4837 		return QDF_STATUS_E_FAILURE;
4838 	}
4839 
4840 	if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE)
4841 		return QDF_STATUS_E_FAILURE;
4842 
4843 	*reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type;
4844 
4845 	return QDF_STATUS_SUCCESS;
4846 }
4847 
4848 /**
4849  * get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev
4850  * @pdev: Pointer to pdev
4851  *
4852  * Return: Pointer to Standard Power regulatory rules
4853  */
4854 static struct reg_rule_info *
4855 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev)
4856 {
4857 	struct wlan_objmgr_psoc *psoc;
4858 	struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv;
4859 	uint8_t phy_id;
4860 	struct reg_rule_info *psoc_reg_rules;
4861 
4862 	psoc = wlan_pdev_get_psoc(pdev);
4863 	psoc_reg_priv = reg_get_psoc_obj(psoc);
4864 	phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
4865 	psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules;
4866 
4867 	return psoc_reg_rules;
4868 }
4869 
4870 #ifdef CONFIG_AFC_SUPPORT
4871 /**
4872  * reg_is_empty_range() - If both left, right frquency edges in the input range
4873  * are zero then the range is empty, else not.
4874  * @in_range: Pointer to input range
4875  *
4876  * Return: True if the range is empty, else false
4877  */
4878 static bool reg_is_empty_range(struct freq_range *in_range)
4879 {
4880 	return !in_range->left && !in_range->right;
4881 }
4882 
4883 struct freq_range
4884 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right)
4885 {
4886 	struct freq_range out_range;
4887 
4888 	out_range.left = left;
4889 	out_range.right = right;
4890 
4891 	return out_range;
4892 }
4893 
4894 /**
4895  * reg_assign_vars_with_range_vals() - Assign input variables with the values of
4896  * the range variable values
4897  * @in_range: Pointer to input range object
4898  * @left: Pointer to the first variable to get the value of left frequency edge
4899  * @right: Pointer to the second variable to get the value of right frequency
4900  *         edge
4901  *
4902  * Return: void
4903  */
4904 static void
4905 reg_assign_vars_with_range_vals(struct freq_range *in_range,
4906 				qdf_freq_t *left,
4907 				qdf_freq_t *right)
4908 {
4909 	*left = in_range->left;
4910 	*right = in_range->right;
4911 }
4912 
4913 /**
4914  * reg_intersect_ranges() - Intersect two ranges and return the intesected range
4915  * @first: Pointer to first input range
4916  * @second: Pointer to second input range
4917  *
4918  * Return: Intersected output range
4919  */
4920 static struct freq_range
4921 reg_intersect_ranges(struct freq_range *first_range,
4922 		     struct freq_range *second_range)
4923 {
4924 	struct freq_range out_range;
4925 	qdf_freq_t l_freq;
4926 	qdf_freq_t r_freq;
4927 
4928 	/* validate if the ranges are proper */
4929 
4930 	l_freq = QDF_MAX(first_range->left, second_range->left);
4931 	r_freq = QDF_MIN(first_range->right, second_range->right);
4932 
4933 	if (l_freq > r_freq) {
4934 		l_freq = 0;
4935 		l_freq = 0;
4936 
4937 		reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]",
4938 			  first_range->left,
4939 			  first_range->right,
4940 			  second_range->left,
4941 			  second_range->right);
4942 	}
4943 
4944 	out_range.left = l_freq;
4945 	out_range.right = r_freq;
4946 
4947 	return out_range;
4948 }
4949 
4950 /**
4951  * reg_act_sp_rule_cb -  A function pointer type that calculate something
4952  * from the input frequency range
4953  * @rule_fr: Pointer to frequencey range
4954  * @arg: Pointer to generic argument (a.k.a. context)
4955  *
4956  * Return: Void
4957  */
4958 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr,
4959 				   void *arg);
4960 
4961 /**
4962  * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for
4963  * every reg rule call the call back function to take some action or calculate
4964  * something
4965  * @pdev: Pointer to pdev
4966  * @pdev_priv_obj: Pointer to pdev private object
4967  * @action_on_sp_rule: A function pointer to take some action or calculate
4968  * something for every sp rule
4969  * @arg: Pointer to opque object (argument/context)
4970  *
4971  * Return: Void
4972  */
4973 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev,
4974 				 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
4975 				 reg_act_sp_rule_cb sp_rule_action,
4976 				 void *arg)
4977 {
4978 	struct cur_reg_rule *p_sp_reg_rule;
4979 	struct reg_rule_info *psoc_reg_rules;
4980 	uint8_t n_6g_sp_ap_reg_rules;
4981 	qdf_freq_t low_5g;
4982 	qdf_freq_t high_5g;
4983 	uint8_t i;
4984 	struct freq_range chip_range;
4985 
4986 	psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev);
4987 	n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP];
4988 	p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP];
4989 
4990 	low_5g = pdev_priv_obj->range_5g_low;
4991 	high_5g = pdev_priv_obj->range_5g_high;
4992 
4993 	chip_range = reg_init_freq_range(low_5g, high_5g);
4994 
4995 	reg_debug("chip_range = [%u, %u]", low_5g, high_5g);
4996 	reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules);
4997 
4998 	for (i = 0; i < n_6g_sp_ap_reg_rules; i++) {
4999 		struct freq_range sp_range;
5000 		struct freq_range out_range;
5001 
5002 		sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq,
5003 					       p_sp_reg_rule->end_freq);
5004 		reg_debug("Rule:[%u, %u]",
5005 			  p_sp_reg_rule->start_freq,
5006 			  p_sp_reg_rule->end_freq);
5007 		out_range = reg_intersect_ranges(&chip_range, &sp_range);
5008 
5009 		if (sp_rule_action)
5010 			sp_rule_action(&out_range, arg);
5011 
5012 		p_sp_reg_rule++;
5013 	}
5014 }
5015 
5016 /**
5017  * reg_afc_incr_num_ranges() - Increment the number of frequency ranges
5018  * @p_range: Pointer to frequency range
5019  * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be
5020  * (Actual type: uint8_t *num_freq_ranges)
5021  * incremented by the function
5022  *
5023  * Return: Void
5024  */
5025 static void reg_afc_incr_num_ranges(struct freq_range *p_range,
5026 				    void *num_freq_ranges)
5027 {
5028 	if (!reg_is_empty_range(p_range))
5029 		(*(uint8_t *)num_freq_ranges)++;
5030 }
5031 
5032 /**
5033  * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard
5034  * power regulatory rules
5035  * @pdev: Pointer to pdev
5036  *
5037  * Return: number of frequency ranges
5038  */
5039 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev,
5040 					  struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
5041 {
5042 	uint8_t num_freq_ranges;
5043 
5044 	num_freq_ranges = 0;
5045 	reg_iterate_sp_rules(pdev,
5046 			     pdev_priv_obj,
5047 			     reg_afc_incr_num_ranges,
5048 			     &num_freq_ranges);
5049 
5050 	reg_debug("Num_freq_ranges=%u", num_freq_ranges);
5051 	return num_freq_ranges;
5052 }
5053 
5054 /**
5055  * reg_afc_get_intersected_ranges() - Get the intersected range into range obj
5056  * @rule_fr: Pointer to the rule for frequency range
5057  * @arg: Pointer to opaque object (argument/context)
5058  * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj)
5059  * incremented by the function
5060  *
5061  * Return: Void
5062  */
5063 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr,
5064 					   void *arg)
5065 {
5066 	struct wlan_afc_freq_range_obj *p_range;
5067 	struct wlan_afc_freq_range_obj **pp_range;
5068 
5069 	pp_range = (struct wlan_afc_freq_range_obj **)arg;
5070 	p_range = *pp_range;
5071 
5072 	if (!reg_is_empty_range(rule_fr)) {
5073 		reg_assign_vars_with_range_vals(rule_fr,
5074 						&p_range->lowfreq,
5075 						&p_range->highfreq);
5076 		reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq);
5077 		(*pp_range)++;
5078 	}
5079 }
5080 
5081 /**
5082  * reg_cp_freq_ranges() - Copy frequency ranges  from the Standard power
5083  * regulatory rules
5084  * @pdev: Pointer to pdev
5085  * @pdev_priv_obj: Pointer to pdev private object
5086  * @num_freq_ranges: Number of frequency ranges
5087  * @p_range_obj: Pointer to range object
5088  *
5089  * Return: void
5090  */
5091 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev,
5092 			       struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
5093 			       uint8_t num_freq_ranges,
5094 			       struct wlan_afc_freq_range_obj *p_range_obj)
5095 {
5096 	struct wlan_afc_freq_range_obj *p_range;
5097 
5098 	reg_debug("Num freq ranges = %u", num_freq_ranges);
5099 
5100 	p_range = p_range_obj;
5101 	reg_iterate_sp_rules(pdev,
5102 			     pdev_priv_obj,
5103 			     reg_afc_get_intersected_ranges,
5104 			     &p_range);
5105 }
5106 
5107 /**
5108  * reg_get_frange_list_len() - Calculate the length of the list of the
5109  * frequency ranges
5110  * @num_freq_ranges: Number of frequency ranges
5111  *
5112  * Return: Length of the frequency range list
5113  */
5114 static uint16_t reg_get_frange_list_len(uint8_t num_freq_ranges)
5115 {
5116 	uint16_t frange_lst_len;
5117 
5118 	if (!num_freq_ranges)
5119 		reg_err("AFC:There is no freq ranges");
5120 
5121 	frange_lst_len =
5122 		sizeof(struct wlan_afc_frange_list) +
5123 		sizeof(struct wlan_afc_freq_range_obj) * num_freq_ranges;
5124 
5125 	return frange_lst_len;
5126 }
5127 
5128 /**
5129  * reg_get_opclasses_array_len() - Calculate the length of the array of
5130  * opclasses objects
5131  * @num_opclasses: The number of opclasses
5132  * @chansize_lst: The array of sizes of channel lists
5133  *
5134  * Return: Length of the array of opclass object
5135  */
5136 static uint16_t reg_get_opclasses_array_len(struct wlan_objmgr_pdev *pdev,
5137 					    uint8_t num_opclasses,
5138 					    uint8_t *chansize_lst)
5139 {
5140 	uint16_t opclasses_arr_len = 0;
5141 	uint16_t i;
5142 
5143 	for (i = 0; i < num_opclasses; i++) {
5144 		opclasses_arr_len +=
5145 			sizeof(struct wlan_afc_opclass_obj) +
5146 			sizeof(uint8_t) * chansize_lst[i];
5147 	}
5148 
5149 	return opclasses_arr_len;
5150 }
5151 
5152 /**
5153  * reg_get_afc_req_length() - Calculate the length of the AFC partial request
5154  * @num_opclasses: The number of opclasses
5155  * @num_freq_ranges: The number of frequency ranges
5156  * @chansize_lst: The array of sizes of channel lists
5157  *
5158  * Return: Length of the partial AFC request
5159  */
5160 static uint16_t reg_get_afc_req_length(struct wlan_objmgr_pdev *pdev,
5161 				       uint8_t num_opclasses,
5162 				       uint8_t num_freq_ranges,
5163 				       uint8_t *chansize_lst)
5164 {
5165 	uint16_t afc_req_len;
5166 	uint16_t frange_lst_len;
5167 	uint16_t fixed_param_len;
5168 	uint16_t num_opclasses_len;
5169 	uint16_t opclasses_arr_len;
5170 
5171 	fixed_param_len = sizeof(struct wlan_afc_host_req_fixed_params);
5172 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
5173 	num_opclasses_len = sizeof(struct wlan_afc_num_opclasses);
5174 	opclasses_arr_len = reg_get_opclasses_array_len(pdev,
5175 							num_opclasses,
5176 							chansize_lst);
5177 
5178 	afc_req_len =
5179 		fixed_param_len +
5180 		frange_lst_len +
5181 		num_opclasses_len +
5182 		opclasses_arr_len;
5183 
5184 	return afc_req_len;
5185 }
5186 
5187 /**
5188  * reg_fill_afc_fixed_params() - Fill the AFC fixed params
5189  * @p_fixed_params: Pointer to afc fixed params object
5190  * @afc_req_len: Length of the partial AFC request
5191  *
5192  * Return: Void
5193  */
5194 static inline void
5195 reg_fill_afc_fixed_params(struct wlan_afc_host_req_fixed_params *p_fixed_params,
5196 			  uint16_t afc_req_len)
5197 {
5198 	p_fixed_params->req_length = afc_req_len;
5199 	p_fixed_params->req_id = DEFAULT_REQ_ID;
5200 	p_fixed_params->min_des_power = DEFAULT_MIN_POWER;
5201 }
5202 
5203 /**
5204  * reg_fill_afc_freq_ranges() - Fill the AFC fixed params
5205  * @pdev: Pointer to pdev
5206  * @pdev_priv_obj: Pointer to pdev private object
5207  * @p_frange_lst: Pointer to frequency range list
5208  * @num_freq_ranges: Number of frequency ranges
5209  *
5210  * Return: Void
5211  */
5212 static inline void
5213 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev,
5214 			 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
5215 			 struct wlan_afc_frange_list *p_frange_lst,
5216 			 uint8_t num_freq_ranges)
5217 {
5218 	struct wlan_afc_freq_range_obj *p_range_obj;
5219 
5220 	p_frange_lst->num_ranges = num_freq_ranges;
5221 
5222 	p_range_obj = &p_frange_lst->range_objs[0];
5223 
5224 	reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj);
5225 }
5226 
5227 /**
5228  * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to
5229  *                              next AFC opclass object
5230  * @p_obj_opclass_obj: Pointer to opclass object
5231  * @opclass: Operating class
5232  * @num_chans: Number of channels in the opclass
5233  * @p_chan_lst: Pointer to channel list
5234  *
5235  * Return: Pointer to the next AFC opclass object
5236  */
5237 static struct wlan_afc_opclass_obj *
5238 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj,
5239 			 uint8_t opclass,
5240 			 uint8_t num_chans,
5241 			 uint8_t *p_chan_lst)
5242 {
5243 	uint16_t len_obj;
5244 	uint8_t *out_p;
5245 	uint8_t *src, *dst;
5246 	uint8_t copy_len;
5247 
5248 	p_obj_opclass_obj->opclass_num_cfis = num_chans;
5249 	p_obj_opclass_obj->opclass = opclass;
5250 	src = p_chan_lst;
5251 	dst = p_obj_opclass_obj->cfis;
5252 	copy_len = num_chans * sizeof(uint8_t);
5253 
5254 	qdf_mem_copy(dst, src, copy_len);
5255 
5256 	len_obj = sizeof(struct wlan_afc_opclass_obj) + copy_len;
5257 	out_p = (uint8_t *)p_obj_opclass_obj + len_obj;
5258 
5259 	return (struct wlan_afc_opclass_obj *)out_p;
5260 }
5261 
5262 /**
5263  * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects
5264  * @num_opclasses: The number of opclasses
5265  * @opclass_lst: The array of Operating classes
5266  * @chansize_lst: The array of sizes of channel lists
5267  * @channel_lists: The array of channel lists
5268  * @p_opclass_obj_arr: Pointer to the first opclass object
5269  *
5270  * Return: Void
5271  */
5272 static inline void
5273 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev,
5274 			   uint8_t num_opclasses,
5275 			   uint8_t *opclass_lst,
5276 			   uint8_t *chansize_lst,
5277 			   uint8_t *channel_lists[],
5278 			   struct wlan_afc_opclass_obj *p_opclass_obj_arr)
5279 {
5280 	uint16_t i;
5281 	struct wlan_afc_opclass_obj *p_opclass_obj;
5282 
5283 	p_opclass_obj = p_opclass_obj_arr;
5284 
5285 	for (i = 0; i < num_opclasses; i++) {
5286 		p_opclass_obj = reg_fill_afc_opclass_obj(p_opclass_obj,
5287 							 opclass_lst[i],
5288 							 chansize_lst[i],
5289 							 channel_lists[i]);
5290 	}
5291 }
5292 
5293 /**
5294  * reg_next_opcls_ptr() - Get the pointer to the next opclass object
5295  * @p_cur_opcls_obj: Pointer to the current operating class object
5296  * @num_cfis: number of center frequencey indices
5297  *
5298  * Return: Pointer to next opclss object
5299  */
5300 static struct wlan_afc_opclass_obj *
5301 reg_next_opcls_ptr(struct wlan_afc_opclass_obj *p_cur_opcls_obj,
5302 		   uint8_t num_cfis)
5303 {
5304 	uint8_t cur_obj_sz;
5305 	uint8_t fixed_opcls_sz;
5306 	struct wlan_afc_opclass_obj *p_next_opcls_obj;
5307 	uint8_t *p_tmp_next;
5308 
5309 	fixed_opcls_sz = sizeof(struct wlan_afc_opclass_obj);
5310 	cur_obj_sz = fixed_opcls_sz + num_cfis * sizeof(uint8_t);
5311 	p_tmp_next = (uint8_t *)p_cur_opcls_obj + cur_obj_sz;
5312 	p_next_opcls_obj = (struct wlan_afc_opclass_obj *)p_tmp_next;
5313 
5314 	return p_next_opcls_obj;
5315 }
5316 
5317 void reg_print_partial_afc_req_info(struct wlan_objmgr_pdev *pdev,
5318 				    struct wlan_afc_host_partial_request *afc_req)
5319 {
5320 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
5321 	struct wlan_afc_frange_list *p_frange_lst;
5322 	struct wlan_afc_num_opclasses *p_num_opclasses;
5323 	uint8_t i;
5324 	uint8_t j;
5325 	uint16_t frange_lst_len;
5326 	uint8_t num_opclasses;
5327 	struct wlan_afc_opclass_obj *p_obj_opclass_arr;
5328 	struct wlan_afc_opclass_obj *p_opclass_obj;
5329 	uint8_t num_freq_ranges;
5330 	uint8_t *p_temp;
5331 
5332 	p_fixed_params = &afc_req->fixed_params;
5333 	reg_debug("req_length=%hu", p_fixed_params->req_length);
5334 	reg_debug("req_id=%llu", p_fixed_params->req_id);
5335 	reg_debug("min_des_power=%hd", p_fixed_params->min_des_power);
5336 
5337 	p_temp = (uint8_t *)p_fixed_params;
5338 	p_temp += sizeof(*p_fixed_params);
5339 	p_frange_lst = (struct wlan_afc_frange_list *)p_temp;
5340 	reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges);
5341 	for (i = 0; i < p_frange_lst->num_ranges; i++) {
5342 		struct wlan_afc_freq_range_obj *p_range_obj;
5343 
5344 		p_range_obj = &p_frange_lst->range_objs[i];
5345 		reg_debug("lowfreq=%hu", p_range_obj->lowfreq);
5346 		reg_debug("highfreq=%hu", p_range_obj->highfreq);
5347 	}
5348 
5349 	num_freq_ranges = p_frange_lst->num_ranges;
5350 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
5351 	p_temp += frange_lst_len;
5352 	p_num_opclasses = (struct wlan_afc_num_opclasses *)p_temp;
5353 	num_opclasses = p_num_opclasses->num_opclasses;
5354 	reg_debug("num_opclasses=%hhu", num_opclasses);
5355 
5356 	p_temp += sizeof(*p_num_opclasses);
5357 	p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)p_temp;
5358 	p_opclass_obj = p_obj_opclass_arr;
5359 	for (i = 0; i < num_opclasses; i++) {
5360 		uint8_t opclass = p_opclass_obj->opclass;
5361 		uint8_t num_cfis = p_opclass_obj->opclass_num_cfis;
5362 		uint8_t *cfis = p_opclass_obj->cfis;
5363 
5364 		reg_debug("opclass[%hhu]=%hhu", i, opclass);
5365 		reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis);
5366 		reg_debug("[");
5367 		for (j = 0; j < num_cfis; j++)
5368 			reg_debug("%hhu,", cfis[j]);
5369 		reg_debug("]");
5370 
5371 		p_opclass_obj = reg_next_opcls_ptr(p_opclass_obj, num_cfis);
5372 	}
5373 }
5374 
5375 /**
5376  * reg_get_frange_filled_buf() - Allocate and fill the frange buffer and return
5377  * the buffer. Also return the number of frequence ranges
5378  * @pdev: Pointer to pdev
5379  * @pdev_priv_obj: Pointer to pdev private object
5380  * @num_freq_ranges: Pointer to number of frequency ranges (output param)
5381  *
5382  * Return: Pointer to the frange buffer
5383  */
5384 static struct wlan_afc_frange_list *
5385 reg_get_frange_filled_buf(struct wlan_objmgr_pdev *pdev,
5386 			  struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
5387 			  uint8_t *num_freq_ranges)
5388 {
5389 	uint16_t frange_lst_len;
5390 	struct wlan_afc_frange_list *p_frange_lst_local;
5391 
5392 	*num_freq_ranges =  reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj);
5393 	frange_lst_len = reg_get_frange_list_len(*num_freq_ranges);
5394 
5395 	p_frange_lst_local = qdf_mem_malloc(frange_lst_len);
5396 	if (!p_frange_lst_local)
5397 		return NULL;
5398 
5399 	reg_fill_afc_freq_ranges(pdev,
5400 				 pdev_priv_obj,
5401 				 p_frange_lst_local,
5402 				 *num_freq_ranges);
5403 	return p_frange_lst_local;
5404 }
5405 
5406 QDF_STATUS
5407 reg_get_partial_afc_req_info(struct wlan_objmgr_pdev *pdev,
5408 			     struct wlan_afc_host_partial_request **afc_req)
5409 {
5410 	/* allocate the memory for the partial request */
5411 	struct wlan_afc_host_partial_request *temp_afc_req;
5412 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
5413 	struct wlan_afc_frange_list *p_frange_lst_local;
5414 	struct wlan_afc_frange_list *p_frange_lst_afc;
5415 	struct wlan_afc_num_opclasses *p_num_opclasses;
5416 	uint16_t afc_req_len;
5417 	uint16_t frange_lst_len;
5418 	uint8_t num_freq_ranges;
5419 	uint8_t num_opclasses;
5420 	struct wlan_afc_opclass_obj *p_obj_opclass_arr;
5421 
5422 	uint8_t *opclass_lst;
5423 	uint8_t *chansize_lst;
5424 	uint8_t **channel_lists;
5425 	QDF_STATUS status;
5426 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5427 
5428 	temp_afc_req = NULL;
5429 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5430 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5431 		reg_err("pdev reg component is NULL");
5432 		status = QDF_STATUS_E_INVAL;
5433 		goto handle_invalid_priv_object;
5434 	}
5435 
5436 	p_frange_lst_local = reg_get_frange_filled_buf(pdev,
5437 						       pdev_priv_obj,
5438 						       &num_freq_ranges);
5439 	if (!p_frange_lst_local) {
5440 		reg_err("Frange lst not allocated");
5441 		status = QDF_STATUS_E_NOMEM;
5442 		goto handle_invalid_priv_object;
5443 	}
5444 
5445 	status = reg_dmn_get_6g_opclasses_and_channels(pdev,
5446 						       p_frange_lst_local,
5447 						       &num_opclasses,
5448 						       &opclass_lst,
5449 						       &chansize_lst,
5450 						       &channel_lists);
5451 	if (status != QDF_STATUS_SUCCESS) {
5452 		reg_err("Opclasses and chans not allocated");
5453 		status = QDF_STATUS_E_NOMEM;
5454 		goto free_frange_lst_local;
5455 	}
5456 
5457 	afc_req_len = reg_get_afc_req_length(pdev,
5458 					     num_opclasses,
5459 					     num_freq_ranges,
5460 					     chansize_lst);
5461 
5462 	temp_afc_req = qdf_mem_malloc(afc_req_len);
5463 	if (!temp_afc_req) {
5464 		reg_err("AFC request not allocated");
5465 		status = QDF_STATUS_E_NOMEM;
5466 		goto free_opcls_chan_mem;
5467 	}
5468 
5469 	p_fixed_params = &temp_afc_req->fixed_params;
5470 	reg_fill_afc_fixed_params(p_fixed_params, afc_req_len);
5471 
5472 	/* frange list is already filled just copy it */
5473 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
5474 	p_frange_lst_afc = (struct wlan_afc_frange_list *)&p_fixed_params[1];
5475 	qdf_mem_copy(p_frange_lst_afc, p_frange_lst_local, frange_lst_len);
5476 
5477 	p_num_opclasses = (struct wlan_afc_num_opclasses *)
5478 	    ((char *)(p_frange_lst_afc) + frange_lst_len);
5479 	p_num_opclasses->num_opclasses = num_opclasses;
5480 
5481 	p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)&p_num_opclasses[1];
5482 	reg_fill_afc_opclasses_arr(pdev,
5483 				   num_opclasses,
5484 				   opclass_lst,
5485 				   chansize_lst,
5486 				   channel_lists,
5487 				   p_obj_opclass_arr);
5488 free_opcls_chan_mem:
5489 	reg_dmn_free_6g_opclasses_and_channels(pdev,
5490 					       num_opclasses,
5491 					       opclass_lst,
5492 					       chansize_lst,
5493 					       channel_lists);
5494 
5495 free_frange_lst_local:
5496 	qdf_mem_free(p_frange_lst_local);
5497 
5498 handle_invalid_priv_object:
5499 	*afc_req = temp_afc_req;
5500 
5501 	return status;
5502 }
5503 
5504 void reg_dmn_set_afc_req_id(struct wlan_afc_host_partial_request *afc_req,
5505 			    uint64_t req_id)
5506 {
5507 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
5508 
5509 	p_fixed_params = &afc_req->fixed_params;
5510 	p_fixed_params->req_id = req_id;
5511 }
5512 
5513 /**
5514  * reg_send_afc_partial_request() - Send AFC partial request to registered
5515  * recipient
5516  * @pdev: Pointer to pdev
5517  * @afc_req: Pointer to afc partial request
5518  *
5519  * Return: void
5520  */
5521 static
5522 void reg_send_afc_partial_request(struct wlan_objmgr_pdev *pdev,
5523 				  struct wlan_afc_host_partial_request *afc_req)
5524 {
5525 	afc_req_rx_evt_handler cbf;
5526 	void *arg;
5527 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5528 
5529 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5530 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5531 		reg_err("pdev reg component is NULL");
5532 		return;
5533 	}
5534 
5535 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
5536 	cbf = pdev_priv_obj->afc_cb_obj.func;
5537 	if (cbf) {
5538 		arg = pdev_priv_obj->afc_cb_obj.arg;
5539 		cbf(pdev, afc_req, arg);
5540 	}
5541 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
5542 }
5543 
5544 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id)
5545 {
5546 	struct wlan_afc_host_partial_request *afc_req;
5547 	QDF_STATUS status;
5548 
5549 	status = reg_get_partial_afc_req_info(pdev, &afc_req);
5550 	if (status != QDF_STATUS_SUCCESS) {
5551 		reg_err("Creating AFC Request failed");
5552 		return QDF_STATUS_E_FAILURE;
5553 	}
5554 
5555 	reg_dmn_set_afc_req_id(afc_req, req_id);
5556 
5557 	reg_print_partial_afc_req_info(pdev, afc_req);
5558 
5559 	reg_send_afc_partial_request(pdev, afc_req);
5560 
5561 	qdf_mem_free(afc_req);
5562 
5563 	return QDF_STATUS_SUCCESS;
5564 }
5565 
5566 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
5567 					    afc_req_rx_evt_handler cbf,
5568 					    void *arg)
5569 {
5570 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5571 
5572 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5573 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5574 		reg_err("pdev reg component is NULL");
5575 		return QDF_STATUS_E_FAILURE;
5576 	}
5577 
5578 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
5579 	pdev_priv_obj->afc_cb_obj.func = cbf;
5580 	pdev_priv_obj->afc_cb_obj.arg = arg;
5581 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
5582 	reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg);
5583 
5584 	return QDF_STATUS_SUCCESS;
5585 }
5586 
5587 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
5588 					      afc_req_rx_evt_handler cbf)
5589 {
5590 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5591 
5592 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5593 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5594 		reg_err("pdev reg component is NULL");
5595 		return QDF_STATUS_E_FAILURE;
5596 	}
5597 
5598 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
5599 	if (pdev_priv_obj->afc_cb_obj.func == cbf) {
5600 		pdev_priv_obj->afc_cb_obj.func = NULL;
5601 		pdev_priv_obj->afc_cb_obj.arg = NULL;
5602 	} else {
5603 		reg_err("cb function=0x%pK not found", cbf);
5604 	}
5605 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
5606 
5607 	return QDF_STATUS_SUCCESS;
5608 }
5609 
5610 #endif /* CONFIG_AFC_SUPPORT */
5611 
5612 QDF_STATUS
5613 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev,
5614 			   enum reg_6g_client_type
5615 			   *reg_cur_6g_client_mobility_type)
5616 {
5617 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5618 
5619 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5620 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5621 		reg_err("pdev reg component is NULL");
5622 		return QDF_STATUS_E_FAILURE;
5623 	}
5624 
5625 	if (pdev_priv_obj->reg_cur_6g_client_mobility_type >=
5626 	    REG_MAX_CLIENT_TYPE)
5627 		return QDF_STATUS_E_FAILURE;
5628 
5629 	*reg_cur_6g_client_mobility_type =
5630 	    pdev_priv_obj->reg_cur_6g_client_mobility_type;
5631 
5632 	return QDF_STATUS_SUCCESS;
5633 }
5634 
5635 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev,
5636 				  bool *reg_rnr_tpe_usable)
5637 {
5638 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5639 
5640 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5641 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5642 		reg_err("pdev reg component is NULL");
5643 		return QDF_STATUS_E_FAILURE;
5644 	}
5645 	*reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable;
5646 	return QDF_STATUS_SUCCESS;
5647 }
5648 
5649 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev,
5650 					 bool *reg_unspecified_ap_usable)
5651 {
5652 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5653 
5654 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5655 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5656 		reg_err("pdev reg component is NULL");
5657 		return QDF_STATUS_E_FAILURE;
5658 	}
5659 	*reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable;
5660 	return QDF_STATUS_SUCCESS;
5661 }
5662 
5663 QDF_STATUS
5664 reg_find_txpower_from_6g_list(qdf_freq_t freq,
5665 			      struct regulatory_channel *chan_list,
5666 			      uint16_t *txpower)
5667 {
5668 	enum channel_enum chan_enum;
5669 
5670 	*txpower = 0;
5671 
5672 	for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) {
5673 		if (chan_list[chan_enum].center_freq == freq) {
5674 			*txpower = chan_list[chan_enum].tx_power;
5675 			return QDF_STATUS_SUCCESS;
5676 		}
5677 	}
5678 
5679 	return QDF_STATUS_E_FAILURE;
5680 }
5681 
5682 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev)
5683 {
5684 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5685 	struct regulatory_channel *cur_chan_list;
5686 	enum channel_enum i;
5687 
5688 	if (!pdev) {
5689 		reg_err("pdev is NULL");
5690 		return false;
5691 	}
5692 
5693 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5694 	if (!pdev_priv_obj) {
5695 		reg_err("pdev priv obj is NULL");
5696 		return false;
5697 	}
5698 
5699 	cur_chan_list = pdev_priv_obj->cur_chan_list;
5700 
5701 	for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) {
5702 		if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED))
5703 			return cur_chan_list[i].psd_flag;
5704 	}
5705 
5706 	return false;
5707 }
5708 
5709 QDF_STATUS
5710 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq,
5711 			       struct regulatory_channel *mas_chan_list,
5712 			       uint16_t *eirp_psd_power)
5713 {
5714 	uint16_t i;
5715 
5716 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
5717 		if (freq == mas_chan_list[i].center_freq) {
5718 			*eirp_psd_power = mas_chan_list[i].psd_eirp;
5719 			return QDF_STATUS_SUCCESS;
5720 		}
5721 	}
5722 
5723 	return QDF_STATUS_E_FAILURE;
5724 }
5725 
5726 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev,
5727 				    qdf_freq_t chan_freq, bool *is_psd,
5728 				    uint16_t *tx_power,
5729 				    uint16_t *eirp_psd_power)
5730 {
5731 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5732 	struct regulatory_channel *master_chan_list;
5733 	enum reg_6g_ap_type ap_pwr_type;
5734 	QDF_STATUS status = QDF_STATUS_SUCCESS;
5735 
5736 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5737 	if (!pdev_priv_obj) {
5738 		reg_err("pdev priv obj is NULL");
5739 		return QDF_STATUS_E_FAILURE;
5740 	}
5741 
5742 	status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type);
5743 	if (!QDF_IS_STATUS_SUCCESS(status))
5744 		return status;
5745 
5746 	master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type];
5747 
5748 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
5749 				      tx_power);
5750 
5751 	*is_psd = reg_is_6g_psd_power(pdev);
5752 	if (*is_psd)
5753 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
5754 							master_chan_list,
5755 							eirp_psd_power);
5756 
5757 	return status;
5758 }
5759 
5760 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev,
5761 						  enum reg_6g_ap_type ap_type,
5762 						  qdf_freq_t chan_freq,
5763 						  bool *is_psd,
5764 						  uint16_t *tx_power,
5765 						  uint16_t *eirp_psd_power)
5766 {
5767 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5768 	enum reg_6g_client_type client_type;
5769 	struct regulatory_channel *master_chan_list;
5770 	QDF_STATUS status = QDF_STATUS_SUCCESS;
5771 
5772 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5773 	if (!pdev_priv_obj) {
5774 		reg_err("pdev priv obj is NULL");
5775 		return QDF_STATUS_E_FAILURE;
5776 	}
5777 
5778 	reg_get_cur_6g_client_type(pdev, &client_type);
5779 
5780 	master_chan_list =
5781 		pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type];
5782 
5783 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
5784 				      tx_power);
5785 
5786 	*is_psd = reg_is_6g_psd_power(pdev);
5787 	if (*is_psd)
5788 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
5789 							master_chan_list,
5790 							eirp_psd_power);
5791 
5792 	return status;
5793 }
5794 
5795 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev,
5796 					    enum reg_6g_client_type client_type,
5797 					    qdf_freq_t chan_freq,
5798 					    bool *is_psd, uint16_t *tx_power,
5799 					    uint16_t *eirp_psd_power)
5800 {
5801 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5802 	enum reg_6g_ap_type ap_pwr_type;
5803 	struct regulatory_channel *master_chan_list;
5804 	QDF_STATUS status = QDF_STATUS_SUCCESS;
5805 
5806 	status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type);
5807 	if (!QDF_IS_STATUS_SUCCESS(status))
5808 		return status;
5809 
5810 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5811 	if (!pdev_priv_obj) {
5812 		reg_err("pdev priv obj is NULL");
5813 		return QDF_STATUS_E_FAILURE;
5814 	}
5815 
5816 	master_chan_list = pdev_priv_obj->
5817 			mas_chan_list_6g_client[ap_pwr_type][client_type];
5818 
5819 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
5820 				      tx_power);
5821 
5822 	*is_psd = reg_is_6g_psd_power(pdev);
5823 	if (*is_psd)
5824 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
5825 							master_chan_list,
5826 							eirp_psd_power);
5827 
5828 	return status;
5829 }
5830 
5831 /**
5832  * reg_get_num_rules_of_ap_pwr_type() - Get the number of reg rules present
5833  * for a given ap power type
5834  * @pdev - Pointer to pdev
5835  * @ap_pwr_type - AP power type
5836  *
5837  * Return: Return the number of reg rules for a given ap power type
5838  */
5839 static uint8_t
5840 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
5841 				 enum reg_6g_ap_type ap_pwr_type)
5842 {
5843 	struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev);
5844 
5845 	if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) {
5846 		reg_err("Unsupported 6G AP power type");
5847 		return 0;
5848 	}
5849 
5850 	return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type];
5851 }
5852 
5853 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev,
5854 					       enum reg_6g_ap_type ap_pwr_type)
5855 {
5856 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5857 	QDF_STATUS status;
5858 
5859 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5860 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5861 		reg_err("pdev reg component is NULL");
5862 		return QDF_STATUS_E_INVAL;
5863 	}
5864 
5865 	if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type))
5866 		return QDF_STATUS_E_FAILURE;
5867 
5868 	status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type);
5869 	if (QDF_IS_STATUS_ERROR(status)) {
5870 		reg_debug("failed to set AP power type to %d", ap_pwr_type);
5871 		return status;
5872 	}
5873 
5874 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
5875 
5876 	return QDF_STATUS_SUCCESS;
5877 }
5878 #endif
5879 
5880 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc)
5881 {
5882 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5883 
5884 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5885 	if (!psoc_priv_obj) {
5886 		reg_err("reg psoc private obj is NULL");
5887 		return false;
5888 	}
5889 
5890 	return psoc_priv_obj->offload_enabled;
5891 }
5892 
5893 QDF_STATUS
5894 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val)
5895 {
5896 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5897 
5898 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5899 
5900 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5901 		reg_err("psoc reg component is NULL");
5902 		return QDF_STATUS_E_FAILURE;
5903 	}
5904 
5905 	psoc_priv_obj->is_ext_tpc_supported = val;
5906 
5907 	return QDF_STATUS_SUCCESS;
5908 }
5909 
5910 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc)
5911 {
5912 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5913 
5914 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5915 
5916 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5917 		reg_err("psoc reg component is NULL");
5918 		return  false;
5919 	}
5920 
5921 	return psoc_priv_obj->is_ext_tpc_supported;
5922 }
5923 
5924 #if defined(CONFIG_BAND_6GHZ)
5925 QDF_STATUS
5926 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val)
5927 {
5928 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5929 
5930 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5931 
5932 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5933 		reg_err("psoc reg component is NULL");
5934 		return QDF_STATUS_E_FAILURE;
5935 	}
5936 
5937 	psoc_priv_obj->is_lower_6g_edge_ch_supported = val;
5938 
5939 	return QDF_STATUS_SUCCESS;
5940 }
5941 
5942 QDF_STATUS
5943 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val)
5944 {
5945 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5946 
5947 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5948 
5949 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5950 		reg_err("psoc reg component is NULL");
5951 		return QDF_STATUS_E_FAILURE;
5952 	}
5953 
5954 	psoc_priv_obj->is_upper_6g_edge_ch_disabled = val;
5955 
5956 	return QDF_STATUS_SUCCESS;
5957 }
5958 
5959 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc)
5960 {
5961 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5962 
5963 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5964 
5965 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5966 		reg_err("psoc reg component is NULL");
5967 		return  false;
5968 	}
5969 
5970 	return psoc_priv_obj->is_lower_6g_edge_ch_supported;
5971 }
5972 
5973 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc)
5974 {
5975 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
5976 
5977 	psoc_priv_obj = reg_get_psoc_obj(psoc);
5978 
5979 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
5980 		reg_err("psoc reg component is NULL");
5981 		return  false;
5982 	}
5983 
5984 	return psoc_priv_obj->is_upper_6g_edge_ch_disabled;
5985 }
5986 #endif
5987 
5988 #ifdef FEATURE_WLAN_CH_AVOID_EXT
5989 /**
5990  * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in
5991  * psoc_priv_obj
5992  * @psoc: Pointer to psoc structure
5993  * @pdev: pointer to pdev object
5994  *
5995  * Return: None
5996  */
5997 static QDF_STATUS
5998 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc,
5999 			      struct wlan_objmgr_pdev *pdev)
6000 {
6001 	uint32_t i;
6002 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6003 	uint8_t start_channel;
6004 	uint8_t end_channel;
6005 	struct ch_avoid_freq_type *range;
6006 	enum channel_enum ch_loop;
6007 	enum channel_enum start_ch_idx;
6008 	enum channel_enum end_ch_idx;
6009 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6010 
6011 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6012 
6013 	if (!pdev_priv_obj) {
6014 		reg_err("reg pdev private obj is NULL");
6015 		return QDF_STATUS_E_FAILURE;
6016 	}
6017 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6018 	if (!psoc_priv_obj) {
6019 		reg_err("reg psoc private obj is NULL");
6020 		return QDF_STATUS_E_FAILURE;
6021 	}
6022 
6023 	if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) {
6024 		uint32_t len;
6025 
6026 		len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list);
6027 		pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0;
6028 		qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list,
6029 			     len);
6030 	}
6031 
6032 	for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt;
6033 		i++) {
6034 		if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >=
6035 		    NUM_CHANNELS) {
6036 			reg_debug("ext avoid channel list full");
6037 			break;
6038 		}
6039 
6040 		start_ch_idx = INVALID_CHANNEL;
6041 		end_ch_idx = INVALID_CHANNEL;
6042 		range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i];
6043 
6044 		start_channel = reg_freq_to_chan(pdev, range->start_freq);
6045 		end_channel = reg_freq_to_chan(pdev, range->end_freq);
6046 		reg_debug("start: freq %d, ch %d, end: freq %d, ch %d",
6047 			  range->start_freq, start_channel, range->end_freq,
6048 			  end_channel);
6049 
6050 		/* do not process frequency bands that are not mapped to
6051 		 * predefined channels
6052 		 */
6053 		if (start_channel == 0 || end_channel == 0)
6054 			continue;
6055 
6056 		for (ch_loop = 0; ch_loop < NUM_CHANNELS;
6057 			ch_loop++) {
6058 			if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) {
6059 				start_ch_idx = ch_loop;
6060 				break;
6061 			}
6062 		}
6063 		for (ch_loop = 0; ch_loop < NUM_CHANNELS;
6064 			ch_loop++) {
6065 			if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) {
6066 				end_ch_idx = ch_loop;
6067 				if (REG_CH_TO_FREQ(ch_loop) > range->end_freq)
6068 					end_ch_idx--;
6069 				break;
6070 			}
6071 		}
6072 
6073 		if (start_ch_idx == INVALID_CHANNEL ||
6074 		    end_ch_idx == INVALID_CHANNEL)
6075 			continue;
6076 
6077 		for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx;
6078 			ch_loop++) {
6079 			pdev_priv_obj->avoid_chan_ext_list.chan_freq_list
6080 			[pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] =
6081 			REG_CH_TO_FREQ(ch_loop);
6082 
6083 			if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >=
6084 				NUM_CHANNELS) {
6085 				reg_debug("avoid freq ext list full");
6086 				break;
6087 			}
6088 		}
6089 		/* if start == end for 5G, meanwhile it only have one valid
6090 		 * channel updated, then disable 20M by default around
6091 		 * this center freq. For example input [5805-5805], it
6092 		 * will disable 20Mhz around 5805, then the range change
6093 		 * to [5705-5815], otherwise, not sure about how many width
6094 		 * need to disabled for such case.
6095 		 */
6096 		if ((ch_loop - start_ch_idx) == 1 &&
6097 		    (range->end_freq - range->start_freq == 0) &&
6098 			reg_is_5ghz_ch_freq(range->start_freq)) {
6099 			range->start_freq = range->start_freq - HALF_20MHZ_BW;
6100 			range->end_freq = range->end_freq + HALF_20MHZ_BW;
6101 		}
6102 	}
6103 
6104 	return QDF_STATUS_SUCCESS;
6105 }
6106 
6107 /**
6108  * reg_update_avoid_ch_ext() - Updates the current channel list that block out
6109  * by extended avoid frequency list
6110  * @psoc: Pointer to psoc structure
6111  * @object: Pointer to pdev structure
6112  * @arg: List of arguments
6113  *
6114  * Return: None
6115  */
6116 static void
6117 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc,
6118 			void *object, void *arg)
6119 {
6120 	struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object;
6121 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6122 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6123 	QDF_STATUS status;
6124 
6125 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6126 	if (!psoc_priv_obj) {
6127 		reg_err("reg psoc private obj is NULL");
6128 		return;
6129 	}
6130 
6131 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6132 
6133 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6134 		reg_err("reg pdev priv obj is NULL");
6135 		return;
6136 	}
6137 
6138 	if (psoc_priv_obj->ch_avoid_ext_ind) {
6139 		status = reg_process_ch_avoid_freq_ext(psoc, pdev);
6140 		if (QDF_IS_STATUS_ERROR(status))
6141 			psoc_priv_obj->ch_avoid_ext_ind = false;
6142 	}
6143 
6144 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
6145 	status = reg_send_scheduler_msg_sb(psoc, pdev);
6146 
6147 	if (QDF_IS_STATUS_ERROR(status))
6148 		reg_err("channel change msg schedule failed");
6149 }
6150 
6151 QDF_STATUS
6152 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc,
6153 			       struct ch_avoid_ind_type *ch_avoid_event)
6154 {
6155 	uint32_t i;
6156 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6157 	QDF_STATUS status;
6158 	struct ch_avoid_freq_type *range;
6159 
6160 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6161 	if (!psoc_priv_obj) {
6162 		reg_err("reg psoc private obj is NULL");
6163 		return QDF_STATUS_E_FAILURE;
6164 	}
6165 
6166 	reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt);
6167 
6168 	qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list,
6169 		     sizeof(struct ch_avoid_ind_type));
6170 
6171 	for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) {
6172 		range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i];
6173 		range->start_freq =
6174 			ch_avoid_event->avoid_freq_range[i].start_freq;
6175 		range->end_freq =
6176 			ch_avoid_event->avoid_freq_range[i].end_freq;
6177 	}
6178 	psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt =
6179 		ch_avoid_event->ch_avoid_range_cnt;
6180 
6181 	psoc_priv_obj->ch_avoid_ext_ind = true;
6182 
6183 	status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID);
6184 
6185 	if (QDF_IS_STATUS_ERROR(status)) {
6186 		reg_err("error taking psoc ref cnt");
6187 		return status;
6188 	}
6189 
6190 	status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP,
6191 					      reg_update_avoid_ch_ext,
6192 					      NULL, 1,
6193 					      WLAN_REGULATORY_SB_ID);
6194 
6195 	wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID);
6196 
6197 	return status;
6198 }
6199 #endif
6200 
6201 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
6202 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev,
6203 			    struct reg_afc_resp_rx_ind_info *afc_ind_obj)
6204 {
6205 	uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
6206 	struct wlan_objmgr_psoc *psoc;
6207 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
6208 
6209 	psoc = wlan_pdev_get_psoc(pdev);
6210 	if (!psoc) {
6211 		reg_err("psoc is NULL");
6212 		return QDF_STATUS_E_INVAL;
6213 	}
6214 
6215 	tx_ops = reg_get_psoc_tx_ops(psoc);
6216 	if (tx_ops->send_afc_ind)
6217 		return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj);
6218 
6219 	return QDF_STATUS_E_FAILURE;
6220 }
6221 
6222 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev)
6223 {
6224 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6225 
6226 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6227 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6228 		reg_err("pdev reg component is NULL");
6229 		return false;
6230 	}
6231 
6232 	return pdev_priv_obj->is_6g_afc_power_event_received;
6233 }
6234 
6235 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id)
6236 {
6237 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6238 
6239 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6240 
6241 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6242 		reg_err("reg pdev priv obj is NULL");
6243 		return QDF_STATUS_E_FAILURE;
6244 	}
6245 
6246 	*req_id = pdev_priv_obj->afc_request_id;
6247 
6248 	return QDF_STATUS_SUCCESS;
6249 }
6250 
6251 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev)
6252 {
6253 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6254 
6255 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6256 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6257 		reg_err("pdev reg component is NULL");
6258 		return false;
6259 	}
6260 
6261 	return pdev_priv_obj->is_6g_afc_expiry_event_received;
6262 }
6263 
6264 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev)
6265 {
6266 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6267 
6268 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6269 
6270 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6271 		reg_err("reg pdev priv obj is NULL");
6272 		return QDF_STATUS_E_FAILURE;
6273 	}
6274 
6275 	return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt;
6276 }
6277 #endif
6278