xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_services_common.c (revision 8b3dca18206e1a0461492f082fa6e270b092c035)
1 /*
2  * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: reg_services_common.c
22  * This file defines regulatory component service functions
23  */
24 
25 #include <wlan_cmn.h>
26 #include <reg_services_public_struct.h>
27 #include <wlan_reg_services_api.h>
28 #ifdef CONFIG_AFC_SUPPORT
29 #include "reg_opclass.h"
30 #endif
31 #include <wlan_objmgr_psoc_obj.h>
32 #include <qdf_lock.h>
33 #include "reg_priv_objs.h"
34 #include "reg_utils.h"
35 #include "reg_callbacks.h"
36 #include "reg_services_common.h"
37 #include <wlan_objmgr_psoc_obj.h>
38 #include "reg_db.h"
39 #include "reg_db_parser.h"
40 #include "reg_build_chan_list.h"
41 #include <wlan_objmgr_pdev_obj.h>
42 #include <target_if.h>
43 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST
44 #include "wlan_mlme_ucfg_api.h"
45 #include "wlan_nan_api.h"
46 #endif
47 #ifndef CONFIG_REG_CLIENT
48 #include <wlan_reg_channel_api.h>
49 #endif
50 
51 const struct chan_map *channel_map;
52 
53 #ifdef CONFIG_CHAN_FREQ_API
54 /* bonded_chan_40mhz_list_freq - List of 40MHz bonnded channel frequencies */
55 static const struct bonded_channel_freq bonded_chan_40mhz_list_freq[] = {
56 	{5180, 5200},
57 	{5220, 5240},
58 	{5260, 5280},
59 	{5300, 5320},
60 	{5500, 5520},
61 	{5540, 5560},
62 	{5580, 5600},
63 	{5620, 5640},
64 	{5660, 5680},
65 	{5700, 5720},
66 	{5745, 5765},
67 	{5785, 5805},
68 	{5825, 5845},
69 	{5865, 5885},
70 #ifdef CONFIG_BAND_6GHZ
71 	{5955, 5975},
72 	{5995, 6015},
73 	{6035, 6055},
74 	{6075, 6095},
75 	{6115, 6135},
76 	{6155, 6175},
77 	{6195, 6215},
78 	{6235, 6255},
79 	{6275, 6295},
80 	{6315, 6335},
81 	{6355, 6375},
82 	{6395, 6415},
83 	{6435, 6455},
84 	{6475, 6495},
85 	{6515, 6535},
86 	{6555, 6575},
87 	{6595, 6615},
88 	{6635, 6655},
89 	{6675, 6695},
90 	{6715, 6735},
91 	{6755, 6775},
92 	{6795, 6815},
93 	{6835, 6855},
94 	{6875, 6895},
95 	{6915, 6935},
96 	{6955, 6975},
97 	{6995, 7015},
98 	{7035, 7055},
99 	{7075, 7095}
100 #endif /*CONFIG_BAND_6GHZ*/
101 };
102 
103 /* bonded_chan_80mhz_list_freq - List of 80MHz bonnded channel frequencies */
104 static const struct bonded_channel_freq bonded_chan_80mhz_list_freq[] = {
105 	{5180, 5240},
106 	{5260, 5320},
107 	{5500, 5560},
108 	{5580, 5640},
109 	{5660, 5720},
110 	{5745, 5805},
111 	{5825, 5885},
112 #ifdef CONFIG_BAND_6GHZ
113 	{5955, 6015},
114 	{6035, 6095},
115 	{6115, 6175},
116 	{6195, 6255},
117 	{6275, 6335},
118 	{6355, 6415},
119 	{6435, 6495},
120 	{6515, 6575},
121 	{6595, 6655},
122 	{6675, 6735},
123 	{6755, 6815},
124 	{6835, 6895},
125 	{6915, 6975},
126 	{6995, 7055}
127 #endif /*CONFIG_BAND_6GHZ*/
128 };
129 
130 /* bonded_chan_160mhz_list_freq - List of 160MHz bonnded channel frequencies */
131 static const struct bonded_channel_freq bonded_chan_160mhz_list_freq[] = {
132 	{5180, 5320},
133 	{5500, 5640},
134 	{5745, 5885},
135 #ifdef CONFIG_BAND_6GHZ
136 	{5955, 6095},
137 	{6115, 6255},
138 	{6275, 6415},
139 	{6435, 6575},
140 	{6595, 6735},
141 	{6755, 6895},
142 	{6915, 7055}
143 #endif /*CONFIG_BAND_6GHZ*/
144 };
145 
146 #ifdef WLAN_FEATURE_11BE
147 /* bonded_chan_320mhz_list_freq - List of 320MHz bonnded channel frequencies */
148 static const struct bonded_channel_freq bonded_chan_320mhz_list_freq[] = {
149 	{5500, 5720}, /* center freq: 5650: The 5Ghz 240MHz chan */
150 #ifdef CONFIG_BAND_6GHZ
151 	{5955, 6255}, /* center freq: 6105 */
152 	{6115, 6415}, /* center freq: 6265 */
153 	{6275, 6575}, /* center freq: 6425 */
154 	{6435, 6735}, /* center freq: 6585 */
155 	{6595, 6895}, /* center freq: 6745 */
156 	{6755, 7055}  /* center freq: 6905 */
157 #endif /*CONFIG_BAND_6GHZ*/
158 };
159 #endif
160 
161 /**
162  * struct bw_bonded_array_pair - Structure containing bandwidth, bonded_array
163  * corresponding to bandwidth and the size of the bonded array.
164  * @chwidth: channel width
165  * @bonded_chan_arr: bonded array corresponding to chwidth.
166  * @array_size: size of the bonded_chan_arr.
167  */
168 struct bw_bonded_array_pair {
169 	enum phy_ch_width chwidth;
170 	const struct bonded_channel_freq *bonded_chan_arr;
171 	uint16_t array_size;
172 };
173 
174 /* Mapping of chwidth to bonded array and size of bonded array */
175 static const
176 struct bw_bonded_array_pair bw_bonded_array_pair_map[] = {
177 #ifdef WLAN_FEATURE_11BE
178 	{CH_WIDTH_320MHZ, bonded_chan_320mhz_list_freq,
179 		QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq)},
180 #endif
181 	{CH_WIDTH_160MHZ, bonded_chan_160mhz_list_freq,
182 		QDF_ARRAY_SIZE(bonded_chan_160mhz_list_freq)},
183 	{CH_WIDTH_80P80MHZ, bonded_chan_80mhz_list_freq,
184 		QDF_ARRAY_SIZE(bonded_chan_80mhz_list_freq)},
185 	{CH_WIDTH_80MHZ, bonded_chan_80mhz_list_freq,
186 		QDF_ARRAY_SIZE(bonded_chan_80mhz_list_freq)},
187 	{CH_WIDTH_40MHZ, bonded_chan_40mhz_list_freq,
188 		QDF_ARRAY_SIZE(bonded_chan_40mhz_list_freq)},
189 };
190 
191 #ifdef WLAN_FEATURE_11BE
192 /** Binary bitmap pattern
193  * 1: Punctured 20Mhz chan 0:non-Punctured 20Mhz Chan
194  *
195  * Band: 80MHz  Puncturing Unit: 20Mhz
196  *  B0001 = 0x1  : BIT(0)
197  *  B0010 = 0x2  : BIT(1)
198  *  B0100 = 0x4  : BIT(2)
199  *  B1000 = 0x8  : BIT(3)
200  *
201  * Band: 160MHz  Puncturing Unit: 20Mhz
202  *  B0000_0001 = 0x01  : BIT(0)
203  *  B0000_0010 = 0x02  : BIT(1)
204  *  B0000_0100 = 0x04  : BIT(2)
205  *  B0000_1000 = 0x08  : BIT(3)
206  *  B0001_0000 = 0x10  : BIT(4)
207  *  B0010_0000 = 0x20  : BIT(5)
208  *  B0100_0000 = 0x40  : BIT(6)
209  *  B1000_0000 = 0x80  : BIT(7)
210  *
211  * Band: 160MHz  Puncturing Unit: 40Mhz
212  *  B0000_0011 = 0x03  : BIT(0) | BIT(1)
213  *  B0000_1100 = 0x0C  : BIT(2) | BIT(3)
214  *  B0011_0000 = 0x30  : BIT(4) | BIT(5)
215  *  B1100_0000 = 0xC0  : BIT(6) | BIT(7)
216  *
217  * Band: 320MHz  Puncturing Unit: 40Mhz
218  *  B0000_0000_0000_0011 = 0x0003  : BIT(0)  | BIT(1)
219  *  B0000_0000_0000_1100 = 0x000C  : BIT(2)  | BIT(3)
220  *  B0000_0000_0011_0000 = 0x0030  : BIT(4)  | BIT(5)
221  *  B0000_0000_1100_0000 = 0x00C0  : BIT(6)  | BIT(7)
222  *  B0000_0011_0000_0000 = 0x0300  : BIT(8)  | BIT(9)
223  *  B0000_1100_0000_0000 = 0x0C00  : BIT(10) | BIT(11)
224  *  B0011_0000_0000_0000 = 0x3000  : BIT(12) | BIT(13)
225  *  B1100_0000_0000_0000 = 0xC000  : BIT(13) | BIT(15)
226  *
227  * Band: 320MHz  Puncturing Unit: 80Mhz
228  *  B0000_0000_0000_1111 = 0x000F  : BIT(0)  | BIT(1) | BIT(2) | BIT(3)
229  *  B0000_0000_1111_0000 = 0x00F0  : BIT(4)  | BIT(5) | BIT(6) | BIT(7)
230  *  B0000_1111_0000_0000 = 0x0F00  : BIT(8)  | BIT(9) | BIT(10) | BIT(11)
231  *  B1111_0000_0000_0000 = 0xF000  : BIT(12) | BIT(13) | BIT(14) | BIT(15)
232  *
233  * Band: 320MHz  Puncturing Unit: 80Mhz+40Mhz (Right 80Mhz punctured)
234  *  B0000_0000_0011_1111 = 0x003F  : BIT(4)  | BIT(5)   [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
235  *  B0000_0000_1100_1111 = 0x00CF  : BIT(6)  | BIT(7)   [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
236  *  B0000_0011_0000_1111 = 0x030F  : BIT(8)  | BIT(9)   [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
237  *  B0000_1100_0000_1111 = 0x0C0F  : BIT(10) | BIT(11)  [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
238  *  B0011_0000_0000_1111 = 0x300F  : BIT(12) | BIT(13)  [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
239  *  B1100_0000_0000_1111 = 0xC00F  : BIT(14) | BIT(15)  [right 80MHz: BIT(0) | BIT(1) | BIT(2) | BIT(3)]
240  *
241  * Band: 320MHz  Puncturing Unit: 80Mhz+40Mhz (Left 80Mhz punctured)
242  *  B1111_0000_0000_0011 = 0xF003  : BIT(4)  | BIT(5)   [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
243  *  B1111_0000_0000_1100 = 0xF00C  : BIT(6)  | BIT(7)   [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
244  *  B1111_0000_0011_0000 = 0xF030  : BIT(8)  | BIT(9)   [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
245  *  B1111_0000_1100_0000 = 0xF0C0  : BIT(10) | BIT(11)  [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
246  *  B1111_0011_0000_0000 = 0xF300  : BIT(12) | BIT(13)  [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
247  *  B1111_1100_0000_0000 = 0xFC00  : BIT(14) | BIT(15)  [left 80MHz: BIT(12) | BIT(13) | BIT(14) | BIT(15)]
248  */
249 static const uint16_t chan_80mhz_puncture_bitmap[] = {
250 	/* 20Mhz puncturing pattern */
251 	0x1,
252 	0x2,
253 	0x4,
254 	0x8
255 };
256 
257 static const uint16_t chan_160mhz_puncture_bitmap[] = {
258 	/* 20Mhz puncturing pattern */
259 	0x1,
260 	0x2,
261 	0x4,
262 	0x8,
263 	0x10,
264 	0x20,
265 	0x40,
266 	0x80,
267 	/* 40Mhz puncturing pattern */
268 	0x3,
269 	0xc,
270 	0x30,
271 	0xc0
272 };
273 
274 static const uint16_t chan_320mhz_puncture_bitmap[] = {
275 	/* 40Mhz puncturing pattern */
276 	0x3,
277 	0xc,
278 	0x30,
279 	0xc0,
280 	0x300,
281 	0xc00,
282 	0x3000,
283 	0xc000,
284 	/* 80Mhz puncturing pattern */
285 	0xf,
286 	0xf0,
287 	0xf00,
288 	0xf000,
289 	/* 80+40Mhz puncturing pattern: Left 80MHz punctured */
290 	0x3f,
291 	0xcf,
292 	0x30f,
293 	0xc0f,
294 	0x300f,
295 	0xc00f,
296 	/* 80+40Mhz puncturing pattern: Right 80MHz punctured */
297 	0xf003,
298 	0xf00c,
299 	0xf030,
300 	0xf0c0,
301 	0xf300,
302 	0xfc00
303 };
304 
305 struct bw_puncture_bitmap_pair {
306 	enum phy_ch_width chwidth;
307 	const uint16_t *puncture_bitmap_arr;
308 	uint16_t array_size;
309 };
310 
311 static const
312 struct bw_puncture_bitmap_pair bw_puncture_bitmap_pair_map[] = {
313 	{CH_WIDTH_320MHZ, chan_320mhz_puncture_bitmap,
314 		QDF_ARRAY_SIZE(chan_320mhz_puncture_bitmap)},
315 	{CH_WIDTH_160MHZ, chan_160mhz_puncture_bitmap,
316 		QDF_ARRAY_SIZE(chan_160mhz_puncture_bitmap)},
317 	{CH_WIDTH_80MHZ, chan_80mhz_puncture_bitmap,
318 		QDF_ARRAY_SIZE(chan_80mhz_puncture_bitmap)},
319 };
320 
321 static inline qdf_freq_t
322 reg_get_band_cen_from_bandstart(uint16_t bw, qdf_freq_t bandstart)
323 {
324 	return bandstart - BW_10_MHZ + bw / 2;
325 }
326 #else /* WLAN_FEATURE_11BE */
327 static inline qdf_freq_t
328 reg_get_band_cen_from_bandstart(uint16_t bw, qdf_freq_t bandstart)
329 {
330 	return 0;
331 }
332 #endif /* WLAN_FEATURE_11BE */
333 
334 static bool reg_is_freq_within_bonded_chan(
335 		qdf_freq_t freq,
336 		const struct bonded_channel_freq *bonded_chan_arr,
337 		enum phy_ch_width chwidth, qdf_freq_t cen320_freq)
338 {
339 	qdf_freq_t band_center;
340 
341 	if (reg_is_ch_width_320(chwidth) && cen320_freq) {
342 		/*
343 		 * For the 5GHz 320/240 MHz channel, bonded pair ends are not
344 		 * symmetric around the center of the channel. Use the start
345 		 * frequency of the bonded channel to calculate the center
346 		 */
347 		if (REG_IS_5GHZ_FREQ(freq)) {
348 			qdf_freq_t start_freq = bonded_chan_arr->start_freq;
349 			uint16_t bw = reg_get_bw_value(chwidth);
350 
351 			band_center =
352 				reg_get_band_cen_from_bandstart(bw,
353 								start_freq);
354 		} else
355 			band_center = (bonded_chan_arr->start_freq +
356 					bonded_chan_arr->end_freq) >> 1;
357 		if (band_center != cen320_freq)
358 			return false;
359 	}
360 
361 	if (freq >= bonded_chan_arr->start_freq &&
362 	    freq <= bonded_chan_arr->end_freq)
363 		return true;
364 
365 	return false;
366 }
367 
368 const struct bonded_channel_freq *
369 reg_get_bonded_chan_entry(qdf_freq_t freq,
370 			  enum phy_ch_width chwidth,
371 			  qdf_freq_t cen320_freq)
372 {
373 	const struct bonded_channel_freq *bonded_chan_arr;
374 	uint16_t array_size, i, num_bws;
375 
376 	num_bws = QDF_ARRAY_SIZE(bw_bonded_array_pair_map);
377 	for (i = 0; i < num_bws; i++) {
378 		if (chwidth == bw_bonded_array_pair_map[i].chwidth) {
379 			bonded_chan_arr =
380 				bw_bonded_array_pair_map[i].bonded_chan_arr;
381 			array_size = bw_bonded_array_pair_map[i].array_size;
382 			break;
383 		}
384 	}
385 	if (i == num_bws) {
386 		reg_debug("Could not find bonded_chan_array for chwidth %d",
387 			  chwidth);
388 		return NULL;
389 	}
390 
391 	for (i = 0; i < array_size; i++) {
392 		if (reg_is_freq_within_bonded_chan(freq, &bonded_chan_arr[i],
393 						   chwidth, cen320_freq))
394 			return &bonded_chan_arr[i];
395 	}
396 
397 	reg_debug("Could not find a bonded pair for freq %d and width %d",
398 		  freq, chwidth);
399 	return NULL;
400 }
401 
402 #endif /*CONFIG_CHAN_FREQ_API*/
403 
404 enum phy_ch_width get_next_lower_bandwidth(enum phy_ch_width ch_width)
405 {
406 	static const enum phy_ch_width get_next_lower_bw[] = {
407     /* 80+80 mode not supported in chips that support 320 mode */
408 #ifdef WLAN_FEATURE_11BE
409 		[CH_WIDTH_320MHZ] = CH_WIDTH_160MHZ,
410 #endif
411 		[CH_WIDTH_80P80MHZ] = CH_WIDTH_160MHZ,
412 		[CH_WIDTH_160MHZ] = CH_WIDTH_80MHZ,
413 		[CH_WIDTH_80MHZ] = CH_WIDTH_40MHZ,
414 		[CH_WIDTH_40MHZ] = CH_WIDTH_20MHZ,
415 		[CH_WIDTH_20MHZ] = CH_WIDTH_10MHZ,
416 		[CH_WIDTH_10MHZ] = CH_WIDTH_5MHZ,
417 		[CH_WIDTH_5MHZ] = CH_WIDTH_INVALID
418 	};
419 
420 	return get_next_lower_bw[ch_width];
421 }
422 
423 const struct chan_map channel_map_us[NUM_CHANNELS] = {
424 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
425 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
426 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
427 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
428 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
429 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
430 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
431 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
432 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
433 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
434 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
435 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
436 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
437 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
438 #ifdef CONFIG_49GHZ_CHAN
439 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
440 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
441 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
442 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
443 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
444 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
445 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
446 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
447 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
448 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
449 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
450 	[CHAN_ENUM_4942] = {4942, 1, 5, 5},
451 	[CHAN_ENUM_4945] = {4945, 11, 10, 10},
452 	[CHAN_ENUM_4947] = {4947, 2, 5, 5},
453 	[CHAN_ENUM_4950] = {4950, 20, 10, 20},
454 	[CHAN_ENUM_4952] = {4952, 3, 5, 5},
455 	[CHAN_ENUM_4955] = {4955, 21, 10, 20},
456 	[CHAN_ENUM_4957] = {4957, 4, 5, 5},
457 	[CHAN_ENUM_4960] = {4960, 22, 10, 20},
458 	[CHAN_ENUM_4962] = {4962, 5, 5, 5},
459 	[CHAN_ENUM_4965] = {4965, 23, 10, 20},
460 	[CHAN_ENUM_4967] = {4967, 6, 5, 5},
461 	[CHAN_ENUM_4970] = {4970, 24, 10, 20},
462 	[CHAN_ENUM_4972] = {4972, 7, 5, 5},
463 	[CHAN_ENUM_4975] = {4975, 25, 10, 20},
464 	[CHAN_ENUM_4977] = {4977, 8, 5, 5},
465 	[CHAN_ENUM_4980] = {4980, 26, 10, 20},
466 	[CHAN_ENUM_4982] = {4982, 9, 5, 5},
467 	[CHAN_ENUM_4985] = {4985, 19, 10, 10},
468 	[CHAN_ENUM_4987] = {4987, 10, 5, 5},
469 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
470 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
471 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
472 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
473 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
474 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
475 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
476 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
477 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
478 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
479 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
480 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
481 #endif /* CONFIG_49GHZ_CHAN */
482 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
483 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
484 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
485 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
486 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
487 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
488 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
489 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
490 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
491 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
492 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
493 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
494 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
495 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
496 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
497 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
498 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
499 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
500 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
501 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
502 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
503 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
504 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
505 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
506 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
507 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
508 #ifdef WLAN_FEATURE_DSRC
509 	[CHAN_ENUM_5850] = {5850, 170, 2, 160},
510 	[CHAN_ENUM_5855] = {5855, 171, 2, 160},
511 	[CHAN_ENUM_5860] = {5860, 172, 2, 160},
512 #endif
513 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
514 #ifdef WLAN_FEATURE_DSRC
515 	[CHAN_ENUM_5870] = {5870, 174, 2, 160},
516 	[CHAN_ENUM_5875] = {5875, 175, 2, 160},
517 	[CHAN_ENUM_5880] = {5880, 176, 2, 160},
518 #endif
519 	[CHAN_ENUM_5885] = {5885, 177, 2, 160},
520 #ifdef WLAN_FEATURE_DSRC
521 	[CHAN_ENUM_5890] = {5890, 178, 2, 160},
522 	[CHAN_ENUM_5895] = {5895, 179, 2, 160},
523 	[CHAN_ENUM_5900] = {5900, 180, 2, 160},
524 	[CHAN_ENUM_5905] = {5905, 181, 2, 160},
525 	[CHAN_ENUM_5910] = {5910, 182, 2, 160},
526 	[CHAN_ENUM_5915] = {5915, 183, 2, 160},
527 	[CHAN_ENUM_5920] = {5920, 184, 2, 160},
528 #endif /* WLAN_FEATURE_DSRC */
529 #ifdef CONFIG_BAND_6GHZ
530 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
531 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
532 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
533 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
534 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
535 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
536 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
537 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
538 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
539 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
540 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
541 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
542 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
543 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
544 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
545 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
546 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
547 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
548 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
549 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
550 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
551 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
552 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
553 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
554 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
555 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
556 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
557 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
558 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
559 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
560 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
561 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
562 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
563 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
564 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
565 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
566 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
567 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
568 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
569 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
570 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
571 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
572 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
573 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
574 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
575 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
576 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
577 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
578 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
579 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
580 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
581 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
582 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
583 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
584 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
585 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
586 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
587 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
588 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
589 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
590 #endif /* CONFIG_BAND_6GHZ */
591 };
592 
593 const struct chan_map channel_map_eu[NUM_CHANNELS] = {
594 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
595 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
596 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
597 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
598 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
599 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
600 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
601 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
602 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
603 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
604 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
605 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
606 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
607 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
608 #ifdef CONFIG_49GHZ_CHAN
609 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
610 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
611 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
612 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
613 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
614 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
615 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
616 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
617 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
618 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
619 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
620 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
621 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
622 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
623 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
624 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
625 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
626 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
627 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
628 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
629 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
630 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
631 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
632 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
633 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
634 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
635 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
636 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
637 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
638 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
639 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
640 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
641 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
642 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
643 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
644 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
645 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
646 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
647 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
648 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
649 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
650 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
651 #endif /* CONFIG_49GHZ_CHAN */
652 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
653 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
654 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
655 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
656 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
657 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
658 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
659 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
660 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
661 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
662 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
663 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
664 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
665 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
666 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
667 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
668 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
669 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
670 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
671 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
672 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
673 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
674 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
675 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
676 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
677 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
678 #ifdef WLAN_FEATURE_DSRC
679 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
680 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
681 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
682 #endif
683 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
684 #ifdef WLAN_FEATURE_DSRC
685 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
686 	[CHAN_ENUM_5875] = {5875, 175, 2, 160},
687 	[CHAN_ENUM_5880] = {5880, 176, 2, 160},
688 #endif
689 	[CHAN_ENUM_5885] = {5885, 177, 2, 160},
690 #ifdef WLAN_FEATURE_DSRC
691 	[CHAN_ENUM_5890] = {5890, 178, 2, 160},
692 	[CHAN_ENUM_5895] = {5895, 179, 2, 160},
693 	[CHAN_ENUM_5900] = {5900, 180, 2, 160},
694 	[CHAN_ENUM_5905] = {5905, 181, 2, 160},
695 	[CHAN_ENUM_5910] = {5910, 182, 2, 160},
696 	[CHAN_ENUM_5915] = {5915, 183, 2, 160},
697 	[CHAN_ENUM_5920] = {5920, 184, 2, 160},
698 #endif /* WLAN_FEATURE_DSRC */
699 #ifdef CONFIG_BAND_6GHZ
700 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
701 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
702 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
703 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
704 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
705 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
706 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
707 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
708 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
709 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
710 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
711 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
712 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
713 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
714 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
715 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
716 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
717 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
718 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
719 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
720 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
721 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
722 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
723 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
724 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
725 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
726 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
727 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
728 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
729 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
730 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
731 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
732 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
733 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
734 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
735 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
736 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
737 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
738 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
739 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
740 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
741 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
742 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
743 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
744 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
745 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
746 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
747 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
748 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
749 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
750 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
751 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
752 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
753 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
754 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
755 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
756 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
757 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
758 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
759 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
760 #endif /* CONFIG_BAND_6GHZ */
761 };
762 
763 const struct chan_map channel_map_jp[NUM_CHANNELS] = {
764 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
765 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
766 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
767 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
768 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
769 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
770 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
771 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
772 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
773 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
774 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
775 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
776 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
777 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
778 #ifdef CONFIG_49GHZ_CHAN
779 	[CHAN_ENUM_4912] = {4912, 182, 5, 5},
780 	[CHAN_ENUM_4915] = {4915, 183, 10, 10},
781 	[CHAN_ENUM_4917] = {4917, 183, 5, 5},
782 	[CHAN_ENUM_4920] = {4920, 184, 10, 20},
783 	[CHAN_ENUM_4922] = {4922, 184, 5, 5},
784 	[CHAN_ENUM_4925] = {4925, 185, 10, 10},
785 	[CHAN_ENUM_4927] = {4927, 185, 5, 5},
786 	[CHAN_ENUM_4932] = {4932, 186, 5, 5},
787 	[CHAN_ENUM_4935] = {4935, 187, 10, 10},
788 	[CHAN_ENUM_4937] = {4937, 187, 5, 5},
789 	[CHAN_ENUM_4940] = {4940, 188, 10, 20},
790 	[CHAN_ENUM_4942] = {4942, 188, 5, 5},
791 	[CHAN_ENUM_4945] = {4945, 189, 10, 10},
792 	[CHAN_ENUM_4947] = {4947, 189, 5, 5},
793 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
794 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
795 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
796 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
797 	[CHAN_ENUM_4960] = {4960, 192, 20, 20},
798 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
799 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
800 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
801 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
802 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
803 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
804 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
805 	[CHAN_ENUM_4980] = {4980, 196, 20, 20},
806 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
807 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
808 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
809 	[CHAN_ENUM_5032] = {5032, 6, 5, 5},
810 	[CHAN_ENUM_5035] = {5035, 7, 10, 10},
811 	[CHAN_ENUM_5037] = {5037, 7, 5, 5},
812 	[CHAN_ENUM_5040] = {5040, 8, 10, 20},
813 	[CHAN_ENUM_5042] = {5042, 8, 5, 5},
814 	[CHAN_ENUM_5045] = {5045, 9, 10, 10},
815 	[CHAN_ENUM_5047] = {5047, 9, 5, 5},
816 	[CHAN_ENUM_5052] = {5052, 10, 5, 5},
817 	[CHAN_ENUM_5055] = {5055, 11, 10, 10},
818 	[CHAN_ENUM_5057] = {5057, 11, 5, 5},
819 	[CHAN_ENUM_5060] = {5060, 12, 20, 20},
820 	[CHAN_ENUM_5080] = {5080, 16, 20, 20},
821 #endif /* CONFIG_49GHZ_CHAN */
822 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
823 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
824 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
825 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
826 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
827 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
828 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
829 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
830 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
831 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
832 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
833 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
834 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
835 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
836 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
837 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
838 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
839 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
840 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
841 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
842 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
843 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
844 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
845 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
846 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
847 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
848 #ifdef WLAN_FEATURE_DSRC
849 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
850 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
851 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
852 #endif
853 	[CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160},
854 #ifdef WLAN_FEATURE_DSRC
855 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
856 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
857 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
858 #endif
859 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
860 #ifdef WLAN_FEATURE_DSRC
861 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
862 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
863 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
864 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
865 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
866 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
867 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
868 #endif /* WLAN_FEATURE_DSRC */
869 #ifdef CONFIG_BAND_6GHZ
870 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
871 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
872 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
873 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
874 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
875 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
876 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
877 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
878 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
879 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
880 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
881 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
882 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
883 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
884 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
885 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
886 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
887 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
888 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
889 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
890 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
891 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
892 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
893 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
894 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
895 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
896 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
897 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
898 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
899 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
900 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
901 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
902 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
903 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
904 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
905 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
906 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
907 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
908 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
909 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
910 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
911 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
912 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
913 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
914 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
915 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
916 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
917 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
918 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
919 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
920 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
921 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
922 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
923 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
924 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
925 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
926 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
927 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
928 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
929 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
930 #endif /* CONFIG_BAND_6GHZ */
931 };
932 
933 const struct chan_map channel_map_global[NUM_CHANNELS] = {
934 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
935 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
936 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
937 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
938 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
939 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
940 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
941 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
942 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
943 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
944 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
945 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
946 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
947 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
948 #ifdef CONFIG_49GHZ_CHAN
949 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
950 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
951 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
952 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
953 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
954 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
955 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
956 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
957 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
958 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
959 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
960 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
961 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
962 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
963 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
964 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
965 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
966 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
967 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
968 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
969 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
970 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
971 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
972 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
973 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
974 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
975 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
976 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
977 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
978 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
979 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
980 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
981 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
982 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
983 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
984 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
985 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
986 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
987 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
988 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
989 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
990 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
991 #endif /* CONFIG_49GHZ_CHAN */
992 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
993 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
994 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
995 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
996 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
997 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
998 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
999 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
1000 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
1001 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
1002 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
1003 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
1004 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
1005 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
1006 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
1007 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
1008 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
1009 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
1010 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
1011 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
1012 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
1013 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
1014 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
1015 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
1016 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
1017 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
1018 #ifdef WLAN_FEATURE_DSRC
1019 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
1020 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
1021 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
1022 #endif
1023 	[CHAN_ENUM_5865] = {5865, 173, 2, 160},
1024 #ifdef WLAN_FEATURE_DSRC
1025 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
1026 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
1027 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
1028 #endif
1029 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
1030 #ifdef WLAN_FEATURE_DSRC
1031 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
1032 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
1033 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
1034 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
1035 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
1036 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
1037 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
1038 #endif /* WLAN_FEATURE_DSRC */
1039 #ifdef CONFIG_BAND_6GHZ
1040 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
1041 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
1042 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
1043 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
1044 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
1045 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
1046 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
1047 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
1048 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
1049 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
1050 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
1051 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
1052 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
1053 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
1054 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
1055 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
1056 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
1057 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
1058 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
1059 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
1060 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
1061 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
1062 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
1063 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
1064 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
1065 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
1066 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
1067 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
1068 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
1069 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
1070 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
1071 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
1072 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
1073 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
1074 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
1075 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
1076 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
1077 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
1078 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
1079 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
1080 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
1081 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
1082 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
1083 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
1084 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
1085 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
1086 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
1087 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
1088 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
1089 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
1090 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
1091 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
1092 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
1093 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
1094 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
1095 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
1096 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
1097 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
1098 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
1099 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
1100 #endif /* CONFIG_BAND_6GHZ */
1101 };
1102 
1103 const struct chan_map channel_map_china[NUM_CHANNELS] = {
1104 	[CHAN_ENUM_2412] = {2412, 1, 20, 40},
1105 	[CHAN_ENUM_2417] = {2417, 2, 20, 40},
1106 	[CHAN_ENUM_2422] = {2422, 3, 20, 40},
1107 	[CHAN_ENUM_2427] = {2427, 4, 20, 40},
1108 	[CHAN_ENUM_2432] = {2432, 5, 20, 40},
1109 	[CHAN_ENUM_2437] = {2437, 6, 20, 40},
1110 	[CHAN_ENUM_2442] = {2442, 7, 20, 40},
1111 	[CHAN_ENUM_2447] = {2447, 8, 20, 40},
1112 	[CHAN_ENUM_2452] = {2452, 9, 20, 40},
1113 	[CHAN_ENUM_2457] = {2457, 10, 20, 40},
1114 	[CHAN_ENUM_2462] = {2462, 11, 20, 40},
1115 	[CHAN_ENUM_2467] = {2467, 12, 20, 40},
1116 	[CHAN_ENUM_2472] = {2472, 13, 20, 40},
1117 	[CHAN_ENUM_2484] = {2484, 14, 20, 20},
1118 #ifdef CONFIG_49GHZ_CHAN
1119 	[CHAN_ENUM_4912] = {4912, INVALID_CHANNEL_NUM, 2, 20},
1120 	[CHAN_ENUM_4915] = {4915, INVALID_CHANNEL_NUM, 2, 20},
1121 	[CHAN_ENUM_4917] = {4917, INVALID_CHANNEL_NUM, 2, 20},
1122 	[CHAN_ENUM_4920] = {4920, INVALID_CHANNEL_NUM, 2, 20},
1123 	[CHAN_ENUM_4922] = {4922, INVALID_CHANNEL_NUM, 2, 20},
1124 	[CHAN_ENUM_4925] = {4925, INVALID_CHANNEL_NUM, 2, 20},
1125 	[CHAN_ENUM_4927] = {4927, INVALID_CHANNEL_NUM, 2, 20},
1126 	[CHAN_ENUM_4932] = {4932, INVALID_CHANNEL_NUM, 2, 20},
1127 	[CHAN_ENUM_4935] = {4935, INVALID_CHANNEL_NUM, 2, 20},
1128 	[CHAN_ENUM_4937] = {4937, INVALID_CHANNEL_NUM, 2, 20},
1129 	[CHAN_ENUM_4940] = {4940, INVALID_CHANNEL_NUM, 2, 20},
1130 	[CHAN_ENUM_4942] = {4942, INVALID_CHANNEL_NUM, 2, 20},
1131 	[CHAN_ENUM_4945] = {4945, INVALID_CHANNEL_NUM, 2, 20},
1132 	[CHAN_ENUM_4947] = {4947, INVALID_CHANNEL_NUM, 2, 20},
1133 	[CHAN_ENUM_4950] = {4950, INVALID_CHANNEL_NUM, 2, 20},
1134 	[CHAN_ENUM_4952] = {4952, INVALID_CHANNEL_NUM, 2, 20},
1135 	[CHAN_ENUM_4955] = {4955, INVALID_CHANNEL_NUM, 2, 20},
1136 	[CHAN_ENUM_4957] = {4957, INVALID_CHANNEL_NUM, 2, 20},
1137 	[CHAN_ENUM_4960] = {4960, INVALID_CHANNEL_NUM, 2, 20},
1138 	[CHAN_ENUM_4962] = {4962, INVALID_CHANNEL_NUM, 2, 20},
1139 	[CHAN_ENUM_4965] = {4965, INVALID_CHANNEL_NUM, 2, 20},
1140 	[CHAN_ENUM_4967] = {4967, INVALID_CHANNEL_NUM, 2, 20},
1141 	[CHAN_ENUM_4970] = {4970, INVALID_CHANNEL_NUM, 2, 20},
1142 	[CHAN_ENUM_4972] = {4972, INVALID_CHANNEL_NUM, 2, 20},
1143 	[CHAN_ENUM_4975] = {4975, INVALID_CHANNEL_NUM, 2, 20},
1144 	[CHAN_ENUM_4977] = {4977, INVALID_CHANNEL_NUM, 2, 20},
1145 	[CHAN_ENUM_4980] = {4980, INVALID_CHANNEL_NUM, 2, 20},
1146 	[CHAN_ENUM_4982] = {4982, INVALID_CHANNEL_NUM, 2, 20},
1147 	[CHAN_ENUM_4985] = {4985, INVALID_CHANNEL_NUM, 2, 20},
1148 	[CHAN_ENUM_4987] = {4987, INVALID_CHANNEL_NUM, 2, 20},
1149 	[CHAN_ENUM_5032] = {5032, INVALID_CHANNEL_NUM, 2, 20},
1150 	[CHAN_ENUM_5035] = {5035, INVALID_CHANNEL_NUM, 2, 20},
1151 	[CHAN_ENUM_5037] = {5037, INVALID_CHANNEL_NUM, 2, 20},
1152 	[CHAN_ENUM_5040] = {5040, INVALID_CHANNEL_NUM, 2, 20},
1153 	[CHAN_ENUM_5042] = {5042, INVALID_CHANNEL_NUM, 2, 20},
1154 	[CHAN_ENUM_5045] = {5045, INVALID_CHANNEL_NUM, 2, 20},
1155 	[CHAN_ENUM_5047] = {5047, INVALID_CHANNEL_NUM, 2, 20},
1156 	[CHAN_ENUM_5052] = {5052, INVALID_CHANNEL_NUM, 2, 20},
1157 	[CHAN_ENUM_5055] = {5055, INVALID_CHANNEL_NUM, 2, 20},
1158 	[CHAN_ENUM_5057] = {5057, INVALID_CHANNEL_NUM, 2, 20},
1159 	[CHAN_ENUM_5060] = {5060, INVALID_CHANNEL_NUM, 2, 20},
1160 	[CHAN_ENUM_5080] = {5080, INVALID_CHANNEL_NUM, 2, 20},
1161 #endif /* CONFIG_49GHZ_CHAN */
1162 	[CHAN_ENUM_5180] = {5180, 36, 2, 160},
1163 	[CHAN_ENUM_5200] = {5200, 40, 2, 160},
1164 	[CHAN_ENUM_5220] = {5220, 44, 2, 160},
1165 	[CHAN_ENUM_5240] = {5240, 48, 2, 160},
1166 	[CHAN_ENUM_5260] = {5260, 52, 2, 160},
1167 	[CHAN_ENUM_5280] = {5280, 56, 2, 160},
1168 	[CHAN_ENUM_5300] = {5300, 60, 2, 160},
1169 	[CHAN_ENUM_5320] = {5320, 64, 2, 160},
1170 	[CHAN_ENUM_5500] = {5500, 100, 2, 240},
1171 	[CHAN_ENUM_5520] = {5520, 104, 2, 240},
1172 	[CHAN_ENUM_5540] = {5540, 108, 2, 240},
1173 	[CHAN_ENUM_5560] = {5560, 112, 2, 240},
1174 	[CHAN_ENUM_5580] = {5580, 116, 2, 240},
1175 	[CHAN_ENUM_5600] = {5600, 120, 2, 240},
1176 	[CHAN_ENUM_5620] = {5620, 124, 2, 240},
1177 	[CHAN_ENUM_5640] = {5640, 128, 2, 240},
1178 	[CHAN_ENUM_5660] = {5660, 132, 2, 240},
1179 	[CHAN_ENUM_5680] = {5680, 136, 2, 240},
1180 	[CHAN_ENUM_5700] = {5700, 140, 2, 240},
1181 	[CHAN_ENUM_5720] = {5720, 144, 2, 240},
1182 	[CHAN_ENUM_5745] = {5745, 149, 2, 160},
1183 	[CHAN_ENUM_5765] = {5765, 153, 2, 160},
1184 	[CHAN_ENUM_5785] = {5785, 157, 2, 160},
1185 	[CHAN_ENUM_5805] = {5805, 161, 2, 160},
1186 	[CHAN_ENUM_5825] = {5825, 165, 2, 160},
1187 	[CHAN_ENUM_5845] = {5845, 169, 2, 160},
1188 #ifdef WLAN_FEATURE_DSRC
1189 	[CHAN_ENUM_5850] = {5850, INVALID_CHANNEL_NUM, 2, 160},
1190 	[CHAN_ENUM_5855] = {5855, INVALID_CHANNEL_NUM, 2, 160},
1191 	[CHAN_ENUM_5860] = {5860, INVALID_CHANNEL_NUM, 2, 160},
1192 #endif
1193 	[CHAN_ENUM_5865] = {5865, INVALID_CHANNEL_NUM, 2, 160},
1194 #ifdef WLAN_FEATURE_DSRC
1195 	[CHAN_ENUM_5870] = {5870, INVALID_CHANNEL_NUM, 2, 160},
1196 	[CHAN_ENUM_5875] = {5875, INVALID_CHANNEL_NUM, 2, 160},
1197 	[CHAN_ENUM_5880] = {5880, INVALID_CHANNEL_NUM, 2, 160},
1198 #endif
1199 	[CHAN_ENUM_5885] = {5885, INVALID_CHANNEL_NUM, 2, 160},
1200 #ifdef WLAN_FEATURE_DSRC
1201 	[CHAN_ENUM_5890] = {5890, INVALID_CHANNEL_NUM, 2, 160},
1202 	[CHAN_ENUM_5895] = {5895, INVALID_CHANNEL_NUM, 2, 160},
1203 	[CHAN_ENUM_5900] = {5900, INVALID_CHANNEL_NUM, 2, 160},
1204 	[CHAN_ENUM_5905] = {5905, INVALID_CHANNEL_NUM, 2, 160},
1205 	[CHAN_ENUM_5910] = {5910, INVALID_CHANNEL_NUM, 2, 160},
1206 	[CHAN_ENUM_5915] = {5915, INVALID_CHANNEL_NUM, 2, 160},
1207 	[CHAN_ENUM_5920] = {5920, INVALID_CHANNEL_NUM, 2, 160},
1208 #endif /* WLAN_FEATURE_DSRC */
1209 #ifdef CONFIG_BAND_6GHZ
1210 	[CHAN_ENUM_5935] = {5935, 2, 2, 20},
1211 	[CHAN_ENUM_5955] = {5955, 1, 2, 320},
1212 	[CHAN_ENUM_5975] = {5975, 5, 2, 320},
1213 	[CHAN_ENUM_5995] = {5995, 9, 2, 320},
1214 	[CHAN_ENUM_6015] = {6015, 13, 2, 320},
1215 	[CHAN_ENUM_6035] = {6035, 17, 2, 320},
1216 	[CHAN_ENUM_6055] = {6055, 21, 2, 320},
1217 	[CHAN_ENUM_6075] = {6075, 25, 2, 320},
1218 	[CHAN_ENUM_6095] = {6095, 29, 2, 320},
1219 	[CHAN_ENUM_6115] = {6115, 33, 2, 320},
1220 	[CHAN_ENUM_6135] = {6135, 37, 2, 320},
1221 	[CHAN_ENUM_6155] = {6155, 41, 2, 320},
1222 	[CHAN_ENUM_6175] = {6175, 45, 2, 320},
1223 	[CHAN_ENUM_6195] = {6195, 49, 2, 320},
1224 	[CHAN_ENUM_6215] = {6215, 53, 2, 320},
1225 	[CHAN_ENUM_6235] = {6235, 57, 2, 320},
1226 	[CHAN_ENUM_6255] = {6255, 61, 2, 320},
1227 	[CHAN_ENUM_6275] = {6275, 65, 2, 320},
1228 	[CHAN_ENUM_6295] = {6295, 69, 2, 320},
1229 	[CHAN_ENUM_6315] = {6315, 73, 2, 320},
1230 	[CHAN_ENUM_6335] = {6335, 77, 2, 320},
1231 	[CHAN_ENUM_6355] = {6355, 81, 2, 320},
1232 	[CHAN_ENUM_6375] = {6375, 85, 2, 320},
1233 	[CHAN_ENUM_6395] = {6395, 89, 2, 320},
1234 	[CHAN_ENUM_6415] = {6415, 93, 2, 320},
1235 	[CHAN_ENUM_6435] = {6435, 97, 2, 320},
1236 	[CHAN_ENUM_6455] = {6455, 101, 2, 320},
1237 	[CHAN_ENUM_6475] = {6475, 105, 2, 320},
1238 	[CHAN_ENUM_6495] = {6495, 109, 2, 320},
1239 	[CHAN_ENUM_6515] = {6515, 113, 2, 320},
1240 	[CHAN_ENUM_6535] = {6535, 117, 2, 320},
1241 	[CHAN_ENUM_6555] = {6555, 121, 2, 320},
1242 	[CHAN_ENUM_6575] = {6575, 125, 2, 320},
1243 	[CHAN_ENUM_6595] = {6595, 129, 2, 320},
1244 	[CHAN_ENUM_6615] = {6615, 133, 2, 320},
1245 	[CHAN_ENUM_6635] = {6635, 137, 2, 320},
1246 	[CHAN_ENUM_6655] = {6655, 141, 2, 320},
1247 	[CHAN_ENUM_6675] = {6675, 145, 2, 320},
1248 	[CHAN_ENUM_6695] = {6695, 149, 2, 320},
1249 	[CHAN_ENUM_6715] = {6715, 153, 2, 320},
1250 	[CHAN_ENUM_6735] = {6735, 157, 2, 320},
1251 	[CHAN_ENUM_6755] = {6755, 161, 2, 320},
1252 	[CHAN_ENUM_6775] = {6775, 165, 2, 320},
1253 	[CHAN_ENUM_6795] = {6795, 169, 2, 320},
1254 	[CHAN_ENUM_6815] = {6815, 173, 2, 320},
1255 	[CHAN_ENUM_6835] = {6835, 177, 2, 320},
1256 	[CHAN_ENUM_6855] = {6855, 181, 2, 320},
1257 	[CHAN_ENUM_6875] = {6875, 185, 2, 320},
1258 	[CHAN_ENUM_6895] = {6895, 189, 2, 320},
1259 	[CHAN_ENUM_6915] = {6915, 193, 2, 320},
1260 	[CHAN_ENUM_6935] = {6935, 197, 2, 320},
1261 	[CHAN_ENUM_6955] = {6955, 201, 2, 320},
1262 	[CHAN_ENUM_6975] = {6975, 205, 2, 320},
1263 	[CHAN_ENUM_6995] = {6995, 209, 2, 320},
1264 	[CHAN_ENUM_7015] = {7015, 213, 2, 320},
1265 	[CHAN_ENUM_7035] = {7035, 217, 2, 320},
1266 	[CHAN_ENUM_7055] = {7055, 221, 2, 320},
1267 	[CHAN_ENUM_7075] = {7075, 225, 2, 160},
1268 	[CHAN_ENUM_7095] = {7095, 229, 2, 160},
1269 	[CHAN_ENUM_7115] = {7115, 233, 2, 160}
1270 #endif /* CONFIG_BAND_6GHZ */
1271 };
1272 
1273 void reg_init_channel_map(enum dfs_reg dfs_region)
1274 {
1275 	switch (dfs_region) {
1276 	case DFS_UNINIT_REGION:
1277 	case DFS_UNDEF_REGION:
1278 		channel_map = channel_map_global;
1279 		break;
1280 	case DFS_FCC_REGION:
1281 		channel_map = channel_map_us;
1282 		break;
1283 	case DFS_ETSI_REGION:
1284 		channel_map = channel_map_eu;
1285 		break;
1286 	case DFS_MKK_REGION:
1287 	case DFS_MKKN_REGION:
1288 		channel_map = channel_map_jp;
1289 		break;
1290 	case DFS_CN_REGION:
1291 		channel_map = channel_map_china;
1292 		break;
1293 	case DFS_KR_REGION:
1294 		channel_map = channel_map_global;
1295 		break;
1296 	}
1297 }
1298 
1299 #ifdef WLAN_FEATURE_11BE
1300 uint16_t reg_get_bw_value(enum phy_ch_width bw)
1301 {
1302 	switch (bw) {
1303 	case CH_WIDTH_20MHZ:
1304 		return 20;
1305 	case CH_WIDTH_40MHZ:
1306 		return 40;
1307 	case CH_WIDTH_80MHZ:
1308 		return 80;
1309 	case CH_WIDTH_160MHZ:
1310 		return 160;
1311 	case CH_WIDTH_80P80MHZ:
1312 		return 160;
1313 	case CH_WIDTH_INVALID:
1314 		return 0;
1315 	case CH_WIDTH_5MHZ:
1316 		return 5;
1317 	case CH_WIDTH_10MHZ:
1318 		return 10;
1319 	case CH_WIDTH_320MHZ:
1320 	case CH_WIDTH_MAX:
1321 		return 320;
1322 	default:
1323 		return 0;
1324 	}
1325 }
1326 #else
1327 uint16_t reg_get_bw_value(enum phy_ch_width bw)
1328 {
1329 	switch (bw) {
1330 	case CH_WIDTH_20MHZ:
1331 		return 20;
1332 	case CH_WIDTH_40MHZ:
1333 		return 40;
1334 	case CH_WIDTH_80MHZ:
1335 		return 80;
1336 	case CH_WIDTH_160MHZ:
1337 		return 160;
1338 	case CH_WIDTH_80P80MHZ:
1339 		return 160;
1340 	case CH_WIDTH_INVALID:
1341 		return 0;
1342 	case CH_WIDTH_5MHZ:
1343 		return 5;
1344 	case CH_WIDTH_10MHZ:
1345 		return 10;
1346 	case CH_WIDTH_MAX:
1347 		return 160;
1348 	default:
1349 		return 0;
1350 	}
1351 }
1352 #endif
1353 
1354 struct wlan_lmac_if_reg_tx_ops *reg_get_psoc_tx_ops(
1355 		struct wlan_objmgr_psoc *psoc)
1356 {
1357 	struct wlan_lmac_if_tx_ops *tx_ops;
1358 
1359 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
1360 	if (!tx_ops) {
1361 		reg_err("tx_ops is NULL");
1362 		return NULL;
1363 	}
1364 
1365 	return &tx_ops->reg_ops;
1366 }
1367 
1368 /**
1369  * reg_combine_channel_states() - Get minimum of channel state1 and state2
1370  * @chan_state1: Channel state1
1371  * @chan_state2: Channel state2
1372  *
1373  * Return: Channel state
1374  */
1375 enum channel_state reg_combine_channel_states(enum channel_state chan_state1,
1376 					      enum channel_state chan_state2)
1377 {
1378 	if ((chan_state1 == CHANNEL_STATE_INVALID) ||
1379 	    (chan_state2 == CHANNEL_STATE_INVALID))
1380 		return CHANNEL_STATE_INVALID;
1381 	else
1382 		return min(chan_state1, chan_state2);
1383 }
1384 
1385 QDF_STATUS reg_read_default_country(struct wlan_objmgr_psoc *psoc,
1386 				    uint8_t *country_code)
1387 {
1388 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1389 
1390 	if (!country_code) {
1391 		reg_err("country_code is NULL");
1392 		return QDF_STATUS_E_INVAL;
1393 	}
1394 
1395 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1396 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1397 		reg_err("psoc reg component is NULL");
1398 		return QDF_STATUS_E_INVAL;
1399 	}
1400 
1401 	qdf_mem_copy(country_code, psoc_priv_obj->def_country,
1402 		     REG_ALPHA2_LEN + 1);
1403 
1404 	return QDF_STATUS_SUCCESS;
1405 }
1406 
1407 #ifdef WLAN_REG_PARTIAL_OFFLOAD
1408 QDF_STATUS reg_get_max_5g_bw_from_country_code(struct wlan_objmgr_pdev *pdev,
1409 					       uint16_t cc,
1410 					       uint16_t *max_bw_5g)
1411 {
1412 	uint16_t i;
1413 	int num_countries;
1414 
1415 	*max_bw_5g = 0;
1416 	reg_get_num_countries(&num_countries);
1417 
1418 	for (i = 0; i < num_countries; i++) {
1419 		if (g_all_countries[i].country_code == cc)
1420 			break;
1421 	}
1422 
1423 	if (i == num_countries)
1424 		return QDF_STATUS_E_FAILURE;
1425 
1426 	*max_bw_5g = g_all_countries[i].max_bw_5g;
1427 
1428 	return QDF_STATUS_SUCCESS;
1429 }
1430 
1431 QDF_STATUS reg_get_max_5g_bw_from_regdomain(struct wlan_objmgr_pdev *pdev,
1432 					    uint16_t regdmn,
1433 					    uint16_t *max_bw_5g)
1434 {
1435 	uint16_t i;
1436 	int num_reg_dmn;
1437 
1438 	*max_bw_5g = 0;
1439 	reg_get_num_reg_dmn_pairs(&num_reg_dmn);
1440 
1441 	for (i = 0; i < num_reg_dmn; i++) {
1442 		if (g_reg_dmn_pairs[i].reg_dmn_pair_id == regdmn)
1443 			break;
1444 	}
1445 
1446 	if (i == num_reg_dmn)
1447 		return QDF_STATUS_E_FAILURE;
1448 
1449 	*max_bw_5g = regdomains_5g[g_reg_dmn_pairs[i].dmn_id_5g].max_bw;
1450 
1451 	return QDF_STATUS_SUCCESS;
1452 }
1453 #else
1454 
1455 QDF_STATUS reg_get_max_5g_bw_from_country_code(struct wlan_objmgr_pdev *pdev,
1456 					       uint16_t cc,
1457 					       uint16_t *max_bw_5g)
1458 {
1459 	*max_bw_5g = reg_get_max_bw_5G_for_fo(pdev);
1460 
1461 	return QDF_STATUS_SUCCESS;
1462 }
1463 
1464 QDF_STATUS reg_get_max_5g_bw_from_regdomain(struct wlan_objmgr_pdev *pdev,
1465 					    uint16_t regdmn,
1466 					    uint16_t *max_bw_5g)
1467 {
1468 	*max_bw_5g = reg_get_max_bw_5G_for_fo(pdev);
1469 
1470 	return QDF_STATUS_SUCCESS;
1471 }
1472 #endif
1473 
1474 uint16_t reg_get_max_bw_5G_for_fo(struct wlan_objmgr_pdev *pdev)
1475 {
1476 	struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev);
1477 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
1478 	uint8_t pdev_id;
1479 	uint8_t phy_id;
1480 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
1481 
1482 	soc_reg = reg_get_psoc_obj(psoc);
1483 	if (!soc_reg) {
1484 		reg_err("soc_reg is NULL");
1485 		return 0;
1486 	}
1487 
1488 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1489 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
1490 	if (reg_tx_ops->get_phy_id_from_pdev_id)
1491 		reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
1492 	else
1493 		phy_id = pdev_id;
1494 
1495 	return soc_reg->mas_chan_params[phy_id].max_bw_5g;
1496 }
1497 
1498 void reg_get_current_dfs_region(struct wlan_objmgr_pdev *pdev,
1499 				enum dfs_reg *dfs_reg)
1500 {
1501 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1502 
1503 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1504 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1505 		reg_err("reg component pdev priv is NULL");
1506 		return;
1507 	}
1508 
1509 	*dfs_reg = pdev_priv_obj->dfs_region;
1510 }
1511 
1512 void reg_set_dfs_region(struct wlan_objmgr_pdev *pdev,
1513 			enum dfs_reg dfs_reg)
1514 {
1515 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1516 
1517 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1518 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1519 		reg_err("psoc reg component is NULL");
1520 		return;
1521 	}
1522 
1523 	pdev_priv_obj->dfs_region = dfs_reg;
1524 
1525 	reg_init_channel_map(dfs_reg);
1526 }
1527 
1528 static uint8_t reg_freq_to_chan_direct(qdf_freq_t freq)
1529 {
1530 	if (freq >= TWOG_CHAN_1_IN_MHZ && freq <= TWOG_CHAN_13_IN_MHZ)
1531 		return IEEE_2GHZ_CH1 +
1532 			(freq - TWOG_CHAN_1_IN_MHZ) / IEEE_CH_SEP;
1533 
1534 	if (freq == TWOG_CHAN_14_IN_MHZ)
1535 		return IEEE_2GHZ_CH14;
1536 
1537 	if (freq >= FIVEG_CHAN_36_IN_MHZ && freq <= FIVEG_CHAN_177_IN_MHZ)
1538 		return IEEE_5GHZ_CH36 +
1539 			(freq - FIVEG_CHAN_36_IN_MHZ) / IEEE_CH_SEP;
1540 
1541 	if (freq == SIXG_CHAN_2_IN_MHZ)
1542 		return IEEE_6GHZ_CH2;
1543 
1544 	if (freq >= SIXG_CHAN_1_IN_MHZ && freq <= SIXG_CHAN_233_IN_MHZ)
1545 		return IEEE_6GHZ_CH1 +
1546 			(freq - SIXG_CHAN_1_IN_MHZ) / IEEE_CH_SEP;
1547 
1548 	return 0;
1549 }
1550 
1551 static uint8_t
1552 reg_freq_to_chan_for_chlist(struct regulatory_channel *chan_list,
1553 			    qdf_freq_t freq,
1554 			    enum channel_enum num_chans)
1555 {
1556 	uint32_t count;
1557 	uint8_t chan_ieee;
1558 
1559 	if (num_chans > NUM_CHANNELS) {
1560 		reg_err_rl("invalid num_chans");
1561 		return 0;
1562 	}
1563 
1564 	chan_ieee = reg_freq_to_chan_direct(freq);
1565 	if (chan_ieee)
1566 		return chan_ieee;
1567 
1568 	for (count = 0; count < num_chans; count++) {
1569 		if (chan_list[count].center_freq >= freq)
1570 			break;
1571 	}
1572 
1573 	if (count == num_chans)
1574 		goto end;
1575 
1576 	if (chan_list[count].center_freq == freq)
1577 		return chan_list[count].chan_num;
1578 
1579 	if (count == 0)
1580 		goto end;
1581 
1582 	if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) ||
1583 	    (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) {
1584 		reg_err("Frequency %d invalid in current reg domain", freq);
1585 		return 0;
1586 	}
1587 
1588 	return (chan_list[count - 1].chan_num +
1589 		(freq - chan_list[count - 1].center_freq) / 5);
1590 
1591 end:
1592 	reg_err_rl("invalid frequency %d", freq);
1593 	return 0;
1594 }
1595 
1596 uint8_t reg_freq_to_chan(struct wlan_objmgr_pdev *pdev,
1597 			 qdf_freq_t freq)
1598 {
1599 	struct regulatory_channel *chan_list;
1600 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1601 	uint8_t chan;
1602 	enum supported_6g_pwr_types input_6g_pwr_mode = REG_AP_LPI;
1603 
1604 	if (freq == 0) {
1605 		reg_debug_rl("Invalid freq %d", freq);
1606 		return 0;
1607 	}
1608 
1609 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1610 
1611 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1612 		reg_err("reg pdev priv obj is NULL");
1613 		return 0;
1614 	}
1615 
1616 	chan_list = pdev_priv_obj->mas_chan_list;
1617 	chan = reg_freq_to_chan_for_chlist(chan_list, freq, NUM_CHANNELS);
1618 
1619 	if (chan)
1620 		return chan;
1621 
1622 	if (!REG_IS_6GHZ_FREQ(freq))
1623 		return chan;
1624 
1625 	input_6g_pwr_mode = REG_AP_LPI;
1626 
1627 	while (input_6g_pwr_mode < REG_INVALID_PWR_MODE) {
1628 		chan_list = reg_get_reg_maschan_lst_frm_6g_pwr_mode(
1629 							input_6g_pwr_mode,
1630 							pdev_priv_obj, 0);
1631 		if (!chan_list)
1632 			return 0;
1633 
1634 		chan = reg_freq_to_chan_for_chlist(chan_list, freq,
1635 						   NUM_6GHZ_CHANNELS);
1636 		if (chan)
1637 			break;
1638 		input_6g_pwr_mode++;
1639 	}
1640 
1641 	return chan;
1642 }
1643 
1644 static uint16_t
1645 reg_compute_chan_to_freq_for_chlist(struct regulatory_channel *chan_list,
1646 				    uint8_t chan_num,
1647 				    enum channel_enum min_chan_range,
1648 				    enum channel_enum max_chan_range)
1649 {
1650 	uint16_t count;
1651 
1652 	if (reg_is_chan_enum_invalid(min_chan_range) ||
1653 	    reg_is_chan_enum_invalid(max_chan_range)) {
1654 		reg_debug_rl("Invalid channel range: min_chan_range: 0x%X max_chan_range: 0x%X",
1655 			     min_chan_range,
1656 			     max_chan_range);
1657 		return 0;
1658 	}
1659 
1660 	for (count = min_chan_range; count <= max_chan_range; count++) {
1661 		if ((chan_list[count].state != CHANNEL_STATE_DISABLE) &&
1662 		    !(chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED)) {
1663 			if (REG_IS_49GHZ_FREQ(chan_list[count].center_freq)) {
1664 				if (chan_list[count].chan_num == chan_num)
1665 					break;
1666 				continue;
1667 			} else if ((chan_list[count].chan_num >= chan_num) &&
1668 				   (chan_list[count].chan_num !=
1669 							INVALID_CHANNEL_NUM))
1670 				break;
1671 		}
1672 	}
1673 
1674 	if (count == max_chan_range + 1)
1675 		goto end;
1676 
1677 	if (chan_list[count].chan_num == chan_num) {
1678 		if (chan_list[count].chan_flags & REGULATORY_CHAN_DISABLED)
1679 			reg_err("Channel %d disabled in current reg domain",
1680 				chan_num);
1681 		return chan_list[count].center_freq;
1682 	}
1683 
1684 	if (count == min_chan_range)
1685 		goto end;
1686 
1687 	if ((chan_list[count - 1].chan_num == INVALID_CHANNEL_NUM) ||
1688 	    REG_IS_49GHZ_FREQ(chan_list[count - 1].center_freq) ||
1689 	    (chan_list[count].chan_num == INVALID_CHANNEL_NUM)) {
1690 		reg_err("Channel %d invalid in current reg domain",
1691 			chan_num);
1692 		return 0;
1693 	}
1694 
1695 	return (chan_list[count - 1].center_freq +
1696 		(chan_num - chan_list[count - 1].chan_num) * 5);
1697 
1698 end:
1699 
1700 	reg_debug_rl("Invalid channel %d", chan_num);
1701 	return 0;
1702 }
1703 
1704 static uint16_t reg_compute_chan_to_freq(struct wlan_objmgr_pdev *pdev,
1705 					 uint8_t chan_num,
1706 					 enum channel_enum min_chan_range,
1707 					 enum channel_enum max_chan_range)
1708 {
1709 	struct regulatory_channel *chan_list;
1710 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1711 	uint16_t freq;
1712 	enum supported_6g_pwr_types input_6g_pwr_mode;
1713 
1714 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1715 
1716 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1717 		reg_err("reg pdev priv obj is NULL");
1718 		return 0;
1719 	}
1720 
1721 	if (min_chan_range < MIN_CHANNEL || max_chan_range > MAX_CHANNEL) {
1722 		reg_err_rl("Channel range is invalid");
1723 		return 0;
1724 	}
1725 
1726 	chan_list = pdev_priv_obj->mas_chan_list;
1727 
1728 	freq = reg_compute_chan_to_freq_for_chlist(chan_list, chan_num,
1729 						   min_chan_range,
1730 						   max_chan_range);
1731 
1732 	/* If the frequency is a 2G or 5G frequency, then it should be found
1733 	 * in the regulatory mas_chan_list.
1734 	 * If a valid 6G frequency has been returned with the current power mode
1735 	 * itself, then return the freq computed.
1736 	 */
1737 	if (freq)
1738 		return freq;
1739 
1740 	min_chan_range = reg_convert_enum_to_6g_idx(min_chan_range);
1741 	max_chan_range = reg_convert_enum_to_6g_idx(max_chan_range);
1742 	if (reg_is_chan_enum_invalid(min_chan_range) ||
1743 	    reg_is_chan_enum_invalid(max_chan_range))
1744 		return freq;
1745 
1746 	/* If a valid 6G frequency has not been found, then search in a
1747 	 * power mode's master channel list.
1748 	 */
1749 	input_6g_pwr_mode = REG_AP_LPI;
1750 	while (input_6g_pwr_mode <= REG_CLI_SUB_VLP) {
1751 		chan_list = reg_get_reg_maschan_lst_frm_6g_pwr_mode(
1752 							input_6g_pwr_mode,
1753 							pdev_priv_obj, 0);
1754 		if (!chan_list)
1755 			return 0;
1756 
1757 		freq = reg_compute_chan_to_freq_for_chlist(chan_list, chan_num,
1758 							   min_chan_range,
1759 							   max_chan_range);
1760 		if (freq)
1761 			break;
1762 		input_6g_pwr_mode++;
1763 	}
1764 
1765 	return freq;
1766 }
1767 
1768 uint16_t reg_legacy_chan_to_freq(struct wlan_objmgr_pdev *pdev,
1769 				 uint8_t chan_num)
1770 {
1771 	uint16_t min_chan_range = MIN_24GHZ_CHANNEL;
1772 	uint16_t max_chan_range = MAX_5GHZ_CHANNEL;
1773 
1774 	if (chan_num == 0) {
1775 		reg_debug_rl("Invalid channel %d", chan_num);
1776 		return 0;
1777 	}
1778 
1779 	return reg_compute_chan_to_freq(pdev, chan_num,
1780 					min_chan_range,
1781 					max_chan_range);
1782 }
1783 
1784 #ifdef WLAN_REG_PARTIAL_OFFLOAD
1785 QDF_STATUS reg_program_default_cc(struct wlan_objmgr_pdev *pdev,
1786 				  uint16_t regdmn)
1787 {
1788 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1789 	struct cur_regulatory_info *reg_info;
1790 	uint16_t cc = -1;
1791 	uint16_t country_index = -1, regdmn_pair = -1;
1792 	struct wlan_objmgr_psoc *psoc;
1793 	QDF_STATUS err;
1794 
1795 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1796 	if (!pdev_priv_obj) {
1797 		reg_err("reg soc is NULL");
1798 		return QDF_STATUS_E_FAILURE;
1799 	}
1800 
1801 	reg_info = (struct cur_regulatory_info *)qdf_mem_malloc
1802 		(sizeof(struct cur_regulatory_info));
1803 	if (!reg_info)
1804 		return QDF_STATUS_E_NOMEM;
1805 
1806 	psoc = wlan_pdev_get_psoc(pdev);
1807 	if (!psoc) {
1808 		reg_err("psoc is NULL");
1809 		return QDF_STATUS_E_INVAL;
1810 	}
1811 
1812 	reg_info->psoc = psoc;
1813 	reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1814 	reg_info->num_phy = 1;
1815 
1816 	if (regdmn == 0) {
1817 		reg_get_default_country(&regdmn);
1818 		regdmn |= COUNTRY_ERD_FLAG;
1819 	}
1820 
1821 	if (regdmn & COUNTRY_ERD_FLAG) {
1822 		cc = regdmn & ~COUNTRY_ERD_FLAG;
1823 
1824 		reg_get_rdpair_from_country_code(cc,
1825 						 &country_index,
1826 						 &regdmn_pair);
1827 
1828 		err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1829 		if (err == QDF_STATUS_E_FAILURE) {
1830 			reg_err("Unable to set country code\n");
1831 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1832 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1833 			qdf_mem_free(reg_info);
1834 			return QDF_STATUS_E_FAILURE;
1835 		}
1836 
1837 		pdev_priv_obj->ctry_code = cc;
1838 
1839 	} else {
1840 		err = reg_get_rdpair_from_regdmn_id(regdmn, &regdmn_pair);
1841 		if (err == QDF_STATUS_E_FAILURE) {
1842 			reg_err("Failed to get regdmn idx for regdmn pair: %x",
1843 				regdmn);
1844 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1845 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1846 			qdf_mem_free(reg_info);
1847 			return QDF_STATUS_E_FAILURE;
1848 		}
1849 
1850 		err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1851 		if (err == QDF_STATUS_E_FAILURE) {
1852 			reg_err("Unable to set country code\n");
1853 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1854 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1855 			qdf_mem_free(reg_info);
1856 			return QDF_STATUS_E_FAILURE;
1857 		}
1858 
1859 		pdev_priv_obj->reg_dmn_pair = regdmn;
1860 	}
1861 
1862 	reg_info->offload_enabled = false;
1863 	reg_process_master_chan_list(reg_info);
1864 
1865 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
1866 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
1867 	qdf_mem_free(reg_info);
1868 
1869 	return QDF_STATUS_SUCCESS;
1870 }
1871 
1872 /**
1873  * reg_program_chan_list_po() - API to program channel list in Partial Offload
1874  * @psoc: Pointer to psoc object manager
1875  * @pdev: Pointer to pdev object
1876  * @rd: Pointer to cc_regdmn_s structure
1877  *
1878  * Return: QDF_STATUS
1879  */
1880 static QDF_STATUS reg_program_chan_list_po(struct wlan_objmgr_psoc *psoc,
1881 					   struct wlan_objmgr_pdev *pdev,
1882 					   struct cc_regdmn_s *rd)
1883 {
1884 	struct cur_regulatory_info *reg_info;
1885 	uint16_t country_index = -1, regdmn_pair = -1;
1886 	QDF_STATUS err;
1887 
1888 	reg_info = (struct cur_regulatory_info *)qdf_mem_malloc
1889 		(sizeof(struct cur_regulatory_info));
1890 	if (!reg_info)
1891 		return QDF_STATUS_E_NOMEM;
1892 
1893 	reg_info->psoc = psoc;
1894 	reg_info->phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1895 
1896 	if (rd->flags == CC_IS_SET) {
1897 		reg_get_rdpair_from_country_code(rd->cc.country_code,
1898 						 &country_index,
1899 						 &regdmn_pair);
1900 	} else if (rd->flags == ALPHA_IS_SET) {
1901 		reg_get_rdpair_from_country_iso(rd->cc.alpha,
1902 						&country_index,
1903 						&regdmn_pair);
1904 	} else if (rd->flags == REGDMN_IS_SET) {
1905 		err = reg_get_rdpair_from_regdmn_id(
1906 				rd->cc.regdmn.reg_2g_5g_pair_id,
1907 				&regdmn_pair);
1908 		if (err == QDF_STATUS_E_FAILURE) {
1909 			reg_err("Failed to get regdmn idx for regdmn pair: %x",
1910 				rd->cc.regdmn.reg_2g_5g_pair_id);
1911 			qdf_mem_free(reg_info->reg_rules_2g_ptr);
1912 			qdf_mem_free(reg_info->reg_rules_5g_ptr);
1913 			qdf_mem_free(reg_info);
1914 			return QDF_STATUS_E_FAILURE;
1915 		}
1916 	}
1917 
1918 	err = reg_get_cur_reginfo(reg_info, country_index, regdmn_pair);
1919 	if (err == QDF_STATUS_E_FAILURE) {
1920 		reg_err("Unable to set country code\n");
1921 		qdf_mem_free(reg_info->reg_rules_2g_ptr);
1922 		qdf_mem_free(reg_info->reg_rules_5g_ptr);
1923 		qdf_mem_free(reg_info);
1924 		return QDF_STATUS_E_FAILURE;
1925 	}
1926 
1927 	reg_info->offload_enabled = false;
1928 	reg_process_master_chan_list(reg_info);
1929 
1930 	qdf_mem_free(reg_info->reg_rules_2g_ptr);
1931 	qdf_mem_free(reg_info->reg_rules_5g_ptr);
1932 	qdf_mem_free(reg_info);
1933 
1934 	return QDF_STATUS_SUCCESS;
1935 }
1936 #else
1937 static QDF_STATUS reg_program_chan_list_po(struct wlan_objmgr_psoc *psoc,
1938 					   struct wlan_objmgr_pdev *pdev,
1939 					   struct cc_regdmn_s *rd)
1940 {
1941 	return QDF_STATUS_SUCCESS;
1942 }
1943 #endif /* WLAN_REG_PARTIAL_OFFLOAD */
1944 
1945 QDF_STATUS reg_program_chan_list(struct wlan_objmgr_pdev *pdev,
1946 				 struct cc_regdmn_s *rd)
1947 {
1948 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1949 	struct wlan_objmgr_psoc *psoc;
1950 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
1951 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1952 	uint8_t pdev_id;
1953 	uint8_t phy_id;
1954 
1955 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1956 	if (!pdev_priv_obj) {
1957 		reg_err(" pdev priv obj is NULL");
1958 		return QDF_STATUS_E_FAILURE;
1959 	}
1960 
1961 	psoc = wlan_pdev_get_psoc(pdev);
1962 	if (!psoc) {
1963 		reg_err("psoc is NULL");
1964 		return QDF_STATUS_E_INVAL;
1965 	}
1966 
1967 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1968 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
1969 		reg_err("psoc reg component is NULL");
1970 		return QDF_STATUS_E_FAILURE;
1971 	}
1972 
1973 	if (psoc_priv_obj->offload_enabled) {
1974 		if ((rd->flags == ALPHA_IS_SET) && (rd->cc.alpha[2] == 'O'))
1975 			pdev_priv_obj->indoor_chan_enabled = false;
1976 		else
1977 			pdev_priv_obj->indoor_chan_enabled = true;
1978 
1979 		pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1980 		tx_ops = reg_get_psoc_tx_ops(psoc);
1981 
1982 		if (tx_ops->get_phy_id_from_pdev_id)
1983 			tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
1984 		else
1985 			phy_id = pdev_id;
1986 
1987 		if (tx_ops->set_user_country_code) {
1988 			psoc_priv_obj->new_init_ctry_pending[phy_id] = true;
1989 			return tx_ops->set_user_country_code(psoc, pdev_id, rd);
1990 		}
1991 
1992 		return QDF_STATUS_E_FAILURE;
1993 	}
1994 
1995 	return reg_program_chan_list_po(psoc, pdev, rd);
1996 }
1997 
1998 QDF_STATUS reg_get_current_cc(struct wlan_objmgr_pdev *pdev,
1999 			      struct cc_regdmn_s *rd)
2000 {
2001 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2002 
2003 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2004 	if (!pdev_priv_obj) {
2005 		reg_err("reg pdev priv is NULL");
2006 		return QDF_STATUS_E_FAILURE;
2007 	}
2008 
2009 	if (rd->flags == CC_IS_SET) {
2010 		rd->cc.country_code = pdev_priv_obj->ctry_code;
2011 	} else if (rd->flags == ALPHA_IS_SET) {
2012 		qdf_mem_copy(rd->cc.alpha, pdev_priv_obj->current_country,
2013 			     sizeof(rd->cc.alpha));
2014 	} else if (rd->flags == REGDMN_IS_SET) {
2015 		rd->cc.regdmn.reg_2g_5g_pair_id = pdev_priv_obj->reg_dmn_pair;
2016 		rd->cc.regdmn.sixg_superdmn_id = pdev_priv_obj->reg_6g_superid;
2017 	}
2018 
2019 	return QDF_STATUS_SUCCESS;
2020 }
2021 
2022 QDF_STATUS reg_set_regdb_offloaded(struct wlan_objmgr_psoc *psoc, bool val)
2023 {
2024 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2025 
2026 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2027 
2028 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2029 		reg_err("psoc reg component is NULL");
2030 		return QDF_STATUS_E_FAILURE;
2031 	}
2032 
2033 	psoc_priv_obj->offload_enabled = val;
2034 
2035 	return QDF_STATUS_SUCCESS;
2036 }
2037 
2038 QDF_STATUS reg_get_curr_regdomain(struct wlan_objmgr_pdev *pdev,
2039 				  struct cur_regdmn_info *cur_regdmn)
2040 {
2041 	struct wlan_objmgr_psoc *psoc;
2042 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2043 	uint16_t index;
2044 	int num_reg_dmn;
2045 	uint8_t phy_id;
2046 	uint8_t pdev_id;
2047 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
2048 
2049 	psoc = wlan_pdev_get_psoc(pdev);
2050 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2051 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2052 		reg_err("soc reg component is NULL");
2053 		return QDF_STATUS_E_INVAL;
2054 	}
2055 
2056 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
2057 
2058 	tx_ops = reg_get_psoc_tx_ops(psoc);
2059 	if (tx_ops->get_phy_id_from_pdev_id)
2060 		tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
2061 	else
2062 		phy_id = pdev_id;
2063 
2064 	cur_regdmn->regdmn_pair_id =
2065 		psoc_priv_obj->mas_chan_params[phy_id].reg_dmn_pair;
2066 
2067 	reg_get_num_reg_dmn_pairs(&num_reg_dmn);
2068 	for (index = 0; index < num_reg_dmn; index++) {
2069 		if (g_reg_dmn_pairs[index].reg_dmn_pair_id ==
2070 				cur_regdmn->regdmn_pair_id)
2071 			break;
2072 	}
2073 
2074 	if (index == num_reg_dmn) {
2075 		reg_debug_rl("invalid regdomain");
2076 		return QDF_STATUS_E_FAILURE;
2077 	}
2078 
2079 	cur_regdmn->dmn_id_2g = g_reg_dmn_pairs[index].dmn_id_2g;
2080 	cur_regdmn->dmn_id_5g = g_reg_dmn_pairs[index].dmn_id_5g;
2081 	cur_regdmn->ctl_2g = regdomains_2g[cur_regdmn->dmn_id_2g].ctl_val;
2082 	cur_regdmn->ctl_5g = regdomains_5g[cur_regdmn->dmn_id_5g].ctl_val;
2083 	cur_regdmn->dfs_region =
2084 		regdomains_5g[cur_regdmn->dmn_id_5g].dfs_region;
2085 
2086 	return QDF_STATUS_SUCCESS;
2087 }
2088 
2089 QDF_STATUS reg_modify_chan_144(struct wlan_objmgr_pdev *pdev,
2090 			       bool enable_ch_144)
2091 {
2092 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2093 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2094 	struct wlan_objmgr_psoc *psoc;
2095 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2096 	QDF_STATUS status;
2097 
2098 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2099 
2100 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2101 		reg_err("pdev reg component is NULL");
2102 		return QDF_STATUS_E_INVAL;
2103 	}
2104 
2105 	if (pdev_priv_obj->en_chan_144 == enable_ch_144) {
2106 		reg_info("chan 144 is already  %d", enable_ch_144);
2107 		return QDF_STATUS_SUCCESS;
2108 	}
2109 
2110 	psoc = wlan_pdev_get_psoc(pdev);
2111 	if (!psoc) {
2112 		reg_err("psoc is NULL");
2113 		return QDF_STATUS_E_INVAL;
2114 	}
2115 
2116 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2117 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2118 		reg_err("psoc reg component is NULL");
2119 		return QDF_STATUS_E_INVAL;
2120 	}
2121 
2122 	reg_debug("setting chan 144: %d", enable_ch_144);
2123 	pdev_priv_obj->en_chan_144 = enable_ch_144;
2124 
2125 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
2126 
2127 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
2128 	if (reg_tx_ops->fill_umac_legacy_chanlist)
2129 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
2130 				pdev_priv_obj->cur_chan_list);
2131 
2132 	status = reg_send_scheduler_msg_sb(psoc, pdev);
2133 
2134 	return status;
2135 }
2136 
2137 bool reg_get_en_chan_144(struct wlan_objmgr_pdev *pdev)
2138 {
2139 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2140 
2141 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2142 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2143 		reg_err("pdev reg component is NULL");
2144 		return false;
2145 	}
2146 
2147 	return pdev_priv_obj->en_chan_144;
2148 }
2149 
2150 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_get_hal_reg_cap(
2151 						struct wlan_objmgr_psoc *psoc)
2152 {
2153 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2154 
2155 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2156 
2157 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2158 		reg_err("psoc reg component is NULL");
2159 		return NULL;
2160 	}
2161 
2162 	return psoc_priv_obj->reg_cap;
2163 }
2164 
2165 QDF_STATUS reg_set_hal_reg_cap(
2166 		struct wlan_objmgr_psoc *psoc,
2167 		struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap,
2168 		uint16_t phy_cnt)
2169 {
2170 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2171 
2172 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2173 
2174 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2175 		reg_err("psoc reg component is NULL");
2176 		return QDF_STATUS_E_FAILURE;
2177 	}
2178 
2179 	if (phy_cnt > PSOC_MAX_PHY_REG_CAP) {
2180 		reg_err("phy cnt:%d is more than %d", phy_cnt,
2181 			PSOC_MAX_PHY_REG_CAP);
2182 		return QDF_STATUS_E_FAILURE;
2183 	}
2184 
2185 	qdf_mem_copy(psoc_priv_obj->reg_cap, reg_cap,
2186 		     phy_cnt *
2187 		     sizeof(struct wlan_psoc_host_hal_reg_capabilities_ext));
2188 
2189 	return QDF_STATUS_SUCCESS;
2190 }
2191 
2192 QDF_STATUS reg_update_hal_reg_cap(struct wlan_objmgr_psoc *psoc,
2193 				  uint64_t wireless_modes, uint8_t phy_id)
2194 {
2195 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2196 
2197 	if (!psoc) {
2198 		reg_err("psoc is null");
2199 		return QDF_STATUS_E_FAILURE;
2200 	}
2201 
2202 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2203 
2204 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2205 		reg_err("psoc reg component is NULL");
2206 		return QDF_STATUS_E_FAILURE;
2207 	}
2208 
2209 	psoc_priv_obj->reg_cap[phy_id].wireless_modes |= wireless_modes;
2210 
2211 	return QDF_STATUS_SUCCESS;
2212 }
2213 
2214 bool reg_chan_in_range(struct regulatory_channel *chan_list,
2215 		       qdf_freq_t low_freq_2g, qdf_freq_t high_freq_2g,
2216 		       qdf_freq_t low_freq_5g, qdf_freq_t high_freq_5g,
2217 		       enum channel_enum ch_enum)
2218 {
2219 	uint32_t low_limit_2g = NUM_CHANNELS;
2220 	uint32_t high_limit_2g = NUM_CHANNELS;
2221 	uint32_t low_limit_5g = NUM_CHANNELS;
2222 	uint32_t high_limit_5g = NUM_CHANNELS;
2223 	bool chan_in_range;
2224 	enum channel_enum chan_enum;
2225 	uint16_t min_bw;
2226 	qdf_freq_t center_freq;
2227 
2228 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
2229 		min_bw = chan_list[chan_enum].min_bw;
2230 		center_freq = chan_list[chan_enum].center_freq;
2231 
2232 		if ((center_freq - min_bw / 2) >= low_freq_2g) {
2233 			low_limit_2g = chan_enum;
2234 			break;
2235 		}
2236 	}
2237 
2238 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
2239 		min_bw = chan_list[chan_enum].min_bw;
2240 		center_freq = chan_list[chan_enum].center_freq;
2241 
2242 		if ((center_freq - min_bw / 2) >= low_freq_5g) {
2243 			low_limit_5g = chan_enum;
2244 			break;
2245 		}
2246 	}
2247 
2248 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
2249 		min_bw = chan_list[chan_enum].min_bw;
2250 		center_freq = chan_list[chan_enum].center_freq;
2251 
2252 		if (center_freq + min_bw / 2 <= high_freq_2g) {
2253 			high_limit_2g = chan_enum;
2254 			break;
2255 		}
2256 		if (chan_enum == 0)
2257 			break;
2258 	}
2259 
2260 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
2261 		min_bw = chan_list[chan_enum].min_bw;
2262 		center_freq = chan_list[chan_enum].center_freq;
2263 
2264 		if (center_freq + min_bw / 2 <= high_freq_5g) {
2265 			high_limit_5g = chan_enum;
2266 			break;
2267 		}
2268 		if (chan_enum == 0)
2269 			break;
2270 	}
2271 
2272 	chan_in_range = false;
2273 	if  ((low_limit_2g <= ch_enum) &&
2274 	     (high_limit_2g >= ch_enum) &&
2275 	     (low_limit_2g != NUM_CHANNELS) &&
2276 	     (high_limit_2g != NUM_CHANNELS))
2277 		chan_in_range = true;
2278 	if  ((low_limit_5g <= ch_enum) &&
2279 	     (high_limit_5g >= ch_enum) &&
2280 	     (low_limit_5g != NUM_CHANNELS) &&
2281 	     (high_limit_5g != NUM_CHANNELS))
2282 		chan_in_range = true;
2283 
2284 	if (chan_in_range)
2285 		return true;
2286 	else
2287 		return false;
2288 }
2289 
2290 bool reg_is_24ghz_ch_freq(uint32_t freq)
2291 {
2292 	return REG_IS_24GHZ_CH_FREQ(freq);
2293 }
2294 
2295 bool reg_is_5ghz_ch_freq(uint32_t freq)
2296 {
2297 	return REG_IS_5GHZ_FREQ(freq);
2298 }
2299 
2300 /**
2301  * BAND_2G_PRESENT() - Check if REG_BAND_2G is set in the band_mask
2302  * @band_mask: Bitmask for bands
2303  *
2304  * Return: True if REG_BAND_2G is set in the band_mask, else false
2305  */
2306 static inline bool BAND_2G_PRESENT(uint8_t band_mask)
2307 {
2308 	return !!(band_mask & (BIT(REG_BAND_2G)));
2309 }
2310 
2311 /**
2312  * BAND_5G_PRESENT() - Check if REG_BAND_5G is set in the band_mask
2313  * @band_mask: Bitmask for bands
2314  *
2315  * Return: True if REG_BAND_5G is set in the band_mask, else false
2316  */
2317 static inline bool BAND_5G_PRESENT(uint8_t band_mask)
2318 {
2319 	return !!(band_mask & (BIT(REG_BAND_5G)));
2320 }
2321 
2322 /**
2323  * reg_is_freq_in_between() - Check whether freq falls within low_freq and
2324  * high_freq, inclusively.
2325  * @low_freq - Low frequency.
2326  * @high_freq - High frequency.
2327  * @freq - Frequency to be checked.
2328  *
2329  * Return: True if freq falls within low_freq and high_freq, else false.
2330  */
2331 static bool reg_is_freq_in_between(qdf_freq_t low_freq, qdf_freq_t high_freq,
2332 				   qdf_freq_t freq)
2333 {
2334 	return (low_freq <= freq && freq <= high_freq);
2335 }
2336 
2337 static bool reg_is_ranges_overlap(qdf_freq_t low_freq, qdf_freq_t high_freq,
2338 				  qdf_freq_t start_edge_freq,
2339 				  qdf_freq_t end_edge_freq)
2340 {
2341 	return (reg_is_freq_in_between(start_edge_freq,
2342 				       end_edge_freq,
2343 				       low_freq) ||
2344 		reg_is_freq_in_between(start_edge_freq,
2345 				       end_edge_freq,
2346 				       high_freq) ||
2347 		reg_is_freq_in_between(low_freq,
2348 				       high_freq,
2349 				       start_edge_freq) ||
2350 		reg_is_freq_in_between(low_freq,
2351 				       high_freq,
2352 				       end_edge_freq));
2353 }
2354 
2355 bool reg_is_range_overlap_2g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2356 {
2357 	return reg_is_ranges_overlap(low_freq, high_freq,
2358 				     TWO_GIG_STARTING_EDGE_FREQ,
2359 				     TWO_GIG_ENDING_EDGE_FREQ);
2360 }
2361 
2362 bool reg_is_range_overlap_5g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2363 {
2364 	return reg_is_ranges_overlap(low_freq, high_freq,
2365 				     FIVE_GIG_STARTING_EDGE_FREQ,
2366 				     FIVE_GIG_ENDING_EDGE_FREQ);
2367 }
2368 
2369 static struct regulatory_channel *
2370 reg_get_reg_chan(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2371 {
2372 	struct regulatory_channel *cur_chan_list;
2373 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2374 	enum channel_enum chan_enum;
2375 
2376 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2377 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2378 		reg_err("reg pdev priv obj is NULL");
2379 		return NULL;
2380 	}
2381 
2382 	chan_enum = reg_get_chan_enum_for_freq(freq);
2383 	if (reg_is_chan_enum_invalid(chan_enum)) {
2384 		reg_err_rl("Invalid chan enum %d", chan_enum);
2385 		return NULL;
2386 	}
2387 
2388 	cur_chan_list = pdev_priv_obj->cur_chan_list;
2389 	if (cur_chan_list[chan_enum].state == CHANNEL_STATE_DISABLE) {
2390 		reg_err("Channel %u is not enabled for this pdev", freq);
2391 		return NULL;
2392 	}
2393 
2394 	return &cur_chan_list[chan_enum];
2395 }
2396 
2397 bool reg_is_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2398 {
2399 	struct regulatory_channel *reg_chan;
2400 
2401 	reg_chan = reg_get_reg_chan(pdev, freq);
2402 
2403 	if (!reg_chan) {
2404 		reg_err("reg channel is NULL");
2405 		return false;
2406 	}
2407 
2408 	return (reg_chan->chan_flags &
2409 		REGULATORY_CHAN_INDOOR_ONLY);
2410 }
2411 
2412 uint16_t reg_get_min_chwidth(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2413 {
2414 	struct regulatory_channel *reg_chan;
2415 
2416 	reg_chan = reg_get_reg_chan(pdev, freq);
2417 
2418 	if (!reg_chan) {
2419 		reg_err("reg channel is NULL");
2420 		return 0;
2421 	}
2422 
2423 	return reg_chan->min_bw;
2424 }
2425 
2426 uint16_t reg_get_max_chwidth(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2427 {
2428 	struct regulatory_channel *reg_chan;
2429 
2430 	reg_chan = reg_get_reg_chan(pdev, freq);
2431 
2432 	if (!reg_chan) {
2433 		reg_err("reg channel is NULL");
2434 		return 0;
2435 	}
2436 
2437 	return reg_chan->max_bw;
2438 }
2439 
2440 #ifdef CONFIG_REG_CLIENT
2441 bool reg_is_freq_indoor_in_secondary_list(struct wlan_objmgr_pdev *pdev,
2442 					  qdf_freq_t freq)
2443 {
2444 	struct regulatory_channel *secondary_cur_chan_list;
2445 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2446 	enum channel_enum chan_enum;
2447 
2448 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2449 
2450 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2451 		reg_err("reg pdev priv obj is NULL");
2452 		return false;
2453 	}
2454 
2455 	chan_enum = reg_get_chan_enum_for_freq(freq);
2456 
2457 	if (reg_is_chan_enum_invalid(chan_enum)) {
2458 		reg_err_rl("Invalid chan enum %d", chan_enum);
2459 		return false;
2460 	}
2461 
2462 	secondary_cur_chan_list = pdev_priv_obj->secondary_cur_chan_list;
2463 
2464 	return (secondary_cur_chan_list[chan_enum].chan_flags &
2465 		REGULATORY_CHAN_INDOOR_ONLY);
2466 }
2467 #endif
2468 
2469 #ifdef CONFIG_BAND_6GHZ
2470 bool reg_is_6ghz_chan_freq(uint16_t freq)
2471 {
2472 	return REG_IS_6GHZ_FREQ(freq);
2473 }
2474 
2475 #ifdef CONFIG_6G_FREQ_OVERLAP
2476 bool reg_is_range_overlap_6g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2477 {
2478 	return reg_is_ranges_overlap(low_freq, high_freq,
2479 				     SIX_GIG_STARTING_EDGE_FREQ,
2480 				     SIX_GIG_ENDING_EDGE_FREQ);
2481 }
2482 
2483 bool reg_is_range_only6g(qdf_freq_t low_freq, qdf_freq_t high_freq)
2484 {
2485 	if (low_freq >= high_freq) {
2486 		reg_err_rl("Low freq is greater than or equal to high freq");
2487 		return false;
2488 	}
2489 
2490 	if (reg_is_range_overlap_6g(low_freq, high_freq) &&
2491 	    !reg_is_range_overlap_5g(low_freq, high_freq)) {
2492 		reg_debug_rl("The device is 6G only");
2493 		return true;
2494 	}
2495 
2496 	reg_debug_rl("The device is not 6G only");
2497 
2498 	return false;
2499 }
2500 #endif
2501 
2502 uint16_t reg_min_6ghz_chan_freq(void)
2503 {
2504 	return REG_MIN_6GHZ_CHAN_FREQ;
2505 }
2506 
2507 uint16_t reg_max_6ghz_chan_freq(void)
2508 {
2509 	return REG_MAX_6GHZ_CHAN_FREQ;
2510 }
2511 
2512 bool reg_is_6ghz_psc_chan_freq(uint16_t freq)
2513 {
2514 	if (!REG_IS_6GHZ_FREQ(freq)) {
2515 		reg_debug(" Channel frequency is not a 6GHz frequency");
2516 		return false;
2517 	}
2518 
2519 	if (!(((freq - SIX_GHZ_NON_ORPHAN_START_FREQ) + FREQ_LEFT_SHIFT) %
2520 	      (FREQ_TO_CHAN_SCALE * NUM_80MHZ_BAND_IN_6G))) {
2521 		return true;
2522 	}
2523 
2524 	reg_debug_rl("Channel freq %d MHz is not a 6GHz PSC frequency", freq);
2525 
2526 	return false;
2527 }
2528 
2529 bool reg_is_6g_freq_indoor(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
2530 {
2531 	return (REG_IS_6GHZ_FREQ(freq) && reg_is_freq_indoor(pdev, freq));
2532 }
2533 
2534 /**
2535  * reg_get_max_psd() - Get max PSD.
2536  * @freq: Channel frequency.
2537  * @bw: Channel bandwidth.
2538  * @reg_ap: Regulatory 6G AP type.
2539  * @reg_client: Regulatory 6G client type.
2540  * @tx_power: Pointer to tx-power.
2541  *
2542  * Return: Return QDF_STATUS_SUCCESS, if PSD is filled for 6G TPE IE
2543  * else return QDF_STATUS_E_FAILURE.
2544  */
2545 static QDF_STATUS reg_get_max_psd(qdf_freq_t freq,
2546 				  uint16_t bw,
2547 				  enum reg_6g_ap_type reg_ap,
2548 				  enum reg_6g_client_type reg_client,
2549 				  uint8_t *tx_power)
2550 {
2551 	if (reg_ap == REG_INDOOR_AP) {
2552 		switch (reg_client) {
2553 		case REG_DEFAULT_CLIENT:
2554 			*tx_power = REG_PSD_MAX_TXPOWER_FOR_DEFAULT_CLIENT;
2555 			return QDF_STATUS_SUCCESS;
2556 		case REG_SUBORDINATE_CLIENT:
2557 			*tx_power = REG_PSD_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT;
2558 			return QDF_STATUS_SUCCESS;
2559 		default:
2560 			reg_err_rl("Invalid client type");
2561 			return QDF_STATUS_E_FAILURE;
2562 		}
2563 	}
2564 
2565 	return QDF_STATUS_E_FAILURE;
2566 }
2567 
2568 /**
2569  * reg_get_max_txpower_for_eirp() - Get max EIRP.
2570  * @pdev: Pointer to pdev.
2571  * @freq: Channel frequency.
2572  * @bw: Channel bandwidth.
2573  * @reg_ap: Regulatory 6G AP type.
2574  * @reg_client: Regulatory client type.
2575  * @tx_power: Pointer to tx-power.
2576  *
2577  * Return: Return QDF_STATUS_SUCCESS, if EIRP is filled for 6G TPE IE
2578  * else return QDF_STATUS_E_FAILURE.
2579  */
2580 static QDF_STATUS reg_get_max_eirp(struct wlan_objmgr_pdev *pdev,
2581 				   qdf_freq_t freq,
2582 				   uint16_t bw,
2583 				   enum reg_6g_ap_type reg_ap,
2584 				   enum reg_6g_client_type reg_client,
2585 				   uint8_t *tx_power)
2586 {
2587 	if (reg_ap == REG_INDOOR_AP) {
2588 		switch (reg_client) {
2589 		case REG_DEFAULT_CLIENT:
2590 			*tx_power = reg_get_channel_reg_power_for_freq(pdev,
2591 								       freq);
2592 			return QDF_STATUS_SUCCESS;
2593 		case REG_SUBORDINATE_CLIENT:
2594 			*tx_power = REG_EIRP_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT;
2595 			return QDF_STATUS_SUCCESS;
2596 		default:
2597 			reg_err_rl("Invalid client type");
2598 			return QDF_STATUS_E_FAILURE;
2599 		}
2600 	}
2601 
2602 	return QDF_STATUS_E_FAILURE;
2603 }
2604 
2605 QDF_STATUS reg_get_max_txpower_for_6g_tpe(struct wlan_objmgr_pdev *pdev,
2606 					  qdf_freq_t freq, uint8_t bw,
2607 					  enum reg_6g_ap_type reg_ap,
2608 					  enum reg_6g_client_type reg_client,
2609 					  bool is_psd,
2610 					  uint8_t *tx_power)
2611 {
2612 	if (!REG_IS_6GHZ_FREQ(freq)) {
2613 		reg_err_rl("%d is not a 6G channel frequency", freq);
2614 		return QDF_STATUS_E_FAILURE;
2615 	}
2616 
2617 	/*
2618 	 * For now, there is support only for Indoor AP and we have only
2619 	 * LPI power values.
2620 	 */
2621 	if (is_psd)
2622 		return reg_get_max_psd(freq, bw, reg_ap, reg_client, tx_power);
2623 
2624 	return reg_get_max_eirp(pdev, freq, bw, reg_ap, reg_client, tx_power);
2625 }
2626 
2627 /**
2628  * BAND_6G_PRESENT() - Check if REG_BAND_6G is set in the band_mask
2629  * @band_mask: Bitmask for bands
2630  *
2631  * Return: True if REG_BAND_6G is set in the band_mask, else false
2632  */
2633 static inline bool BAND_6G_PRESENT(uint8_t band_mask)
2634 {
2635 	return !!(band_mask & (BIT(REG_BAND_6G)));
2636 }
2637 #else
2638 static inline bool BAND_6G_PRESENT(uint8_t band_mask)
2639 {
2640 	return false;
2641 }
2642 #endif /* CONFIG_BAND_6GHZ */
2643 
2644 /**
2645  * reg_get_band_from_cur_chan_list() - Get channel list and number of channels
2646  * @pdev: pdev ptr
2647  * @band_mask: Input bitmap with band set
2648  * @channel_list: Pointer to Channel List
2649  * @cur_chan_list: Pointer to primary current channel list for non-beaconing
2650  * entites (STA, p2p client) and secondary channel list for beaconing entities
2651  * (SAP, p2p GO)
2652  *
2653  * Get the given channel list and number of channels from the current channel
2654  * list based on input band bitmap.
2655  *
2656  * Return: Number of channels, else 0 to indicate error
2657  */
2658 static uint16_t
2659 reg_get_band_from_cur_chan_list(struct wlan_objmgr_pdev *pdev,
2660 				uint8_t band_mask,
2661 				struct regulatory_channel *channel_list,
2662 				struct regulatory_channel *cur_chan_list)
2663 {
2664 	uint16_t i, num_channels = 0;
2665 
2666 	if (BAND_2G_PRESENT(band_mask)) {
2667 		for (i = MIN_24GHZ_CHANNEL; i <= MAX_24GHZ_CHANNEL; i++) {
2668 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2669 			    !(cur_chan_list[i].chan_flags &
2670 			      REGULATORY_CHAN_DISABLED)) {
2671 				channel_list[num_channels] = cur_chan_list[i];
2672 				num_channels++;
2673 			}
2674 		}
2675 	}
2676 	if (BAND_5G_PRESENT(band_mask)) {
2677 		for (i = BAND_5GHZ_START_CHANNEL; i <= MAX_5GHZ_CHANNEL; i++) {
2678 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2679 			    !(cur_chan_list[i].chan_flags &
2680 			      REGULATORY_CHAN_DISABLED)) {
2681 				channel_list[num_channels] = cur_chan_list[i];
2682 				num_channels++;
2683 			}
2684 		}
2685 	}
2686 	if (BAND_6G_PRESENT(band_mask)) {
2687 		for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) {
2688 			if ((cur_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
2689 			    !(cur_chan_list[i].chan_flags &
2690 			      REGULATORY_CHAN_DISABLED)) {
2691 				channel_list[num_channels] = cur_chan_list[i];
2692 				num_channels++;
2693 			}
2694 		}
2695 	}
2696 
2697 	if (!num_channels) {
2698 		reg_err("Failed to retrieve the channel list");
2699 		return 0;
2700 	}
2701 
2702 	return num_channels;
2703 }
2704 
2705 uint16_t
2706 reg_get_band_channel_list(struct wlan_objmgr_pdev *pdev,
2707 			  uint8_t band_mask,
2708 			  struct regulatory_channel *channel_list)
2709 {
2710 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2711 
2712 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2713 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2714 		reg_err("reg pdev priv obj is NULL");
2715 		return 0;
2716 	}
2717 
2718 	return reg_get_band_from_cur_chan_list(pdev, band_mask, channel_list,
2719 					       pdev_priv_obj->cur_chan_list);
2720 }
2721 
2722 #ifdef CONFIG_REG_6G_PWRMODE
2723 uint16_t
2724 reg_get_band_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev,
2725 				      uint8_t band_mask,
2726 				      struct regulatory_channel *channel_list,
2727 				      enum supported_6g_pwr_types
2728 				      in_6g_pwr_mode)
2729 {
2730 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2731 	struct regulatory_channel *reg_chan_list;
2732 	uint16_t nchan = 0;
2733 
2734 	reg_chan_list = qdf_mem_malloc(NUM_CHANNELS * sizeof(*reg_chan_list));
2735 
2736 	if (!reg_chan_list)
2737 		return 0;
2738 
2739 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2740 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2741 		reg_err("reg pdev priv obj is NULL");
2742 		goto err;
2743 	}
2744 
2745 	if (reg_get_pwrmode_chan_list(pdev, reg_chan_list, in_6g_pwr_mode)) {
2746 		reg_debug_rl("Unable to get powermode channel list");
2747 		goto err;
2748 	}
2749 
2750 	nchan = reg_get_band_from_cur_chan_list(pdev, band_mask, channel_list,
2751 						reg_chan_list);
2752 err:
2753 	qdf_mem_free(reg_chan_list);
2754 	return nchan;
2755 }
2756 #endif
2757 
2758 #ifdef CONFIG_REG_CLIENT
2759 uint16_t
2760 reg_get_secondary_band_channel_list(struct wlan_objmgr_pdev *pdev,
2761 				    uint8_t band_mask,
2762 				    struct regulatory_channel *channel_list)
2763 {
2764 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2765 
2766 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2767 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2768 		reg_err("reg pdev priv obj is NULL");
2769 		return 0;
2770 	}
2771 
2772 	return reg_get_band_from_cur_chan_list(
2773 				pdev, band_mask, channel_list,
2774 				pdev_priv_obj->secondary_cur_chan_list);
2775 }
2776 #endif
2777 
2778 qdf_freq_t reg_chan_band_to_freq(struct wlan_objmgr_pdev *pdev,
2779 				 uint8_t chan_num,
2780 				 uint8_t band_mask)
2781 {
2782 	enum channel_enum min_chan, max_chan;
2783 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2784 	uint16_t freq;
2785 
2786 	if (chan_num == 0) {
2787 		reg_debug_rl("Invalid channel %d", chan_num);
2788 		return 0;
2789 	}
2790 
2791 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2792 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2793 		reg_err("reg pdev priv obj is NULL");
2794 		return 0;
2795 	}
2796 
2797 	if (BAND_6G_PRESENT(band_mask)) {
2798 		if (BAND_2G_PRESENT(band_mask) ||
2799 		    BAND_5G_PRESENT(band_mask)) {
2800 			reg_err_rl("Incorrect band_mask %x", band_mask);
2801 				return 0;
2802 		}
2803 
2804 		/* Handle 6G channel 2 as a special case as it does not follow
2805 		 * the regular increasing order of channel numbers
2806 		 */
2807 		if (chan_num == SIXG_CHAN_2) {
2808 			struct regulatory_channel *mas_chan_list;
2809 
2810 			mas_chan_list = pdev_priv_obj->mas_chan_list;
2811 			/* Check if chan 2 is in the master list */
2812 			if ((mas_chan_list[CHAN_ENUM_SIXG_2].state !=
2813 			     CHANNEL_STATE_DISABLE) &&
2814 			    !(mas_chan_list[CHAN_ENUM_SIXG_2].chan_flags &
2815 			     REGULATORY_CHAN_DISABLED))
2816 				return mas_chan_list[CHAN_ENUM_SIXG_2].
2817 								center_freq;
2818 			else
2819 				return 0;
2820 		}
2821 
2822 		/* MIN_6GHZ_CHANNEL corresponds to CHAN_ENUM_5935
2823 		 * ( a.k.a SIXG_CHAN_2). Skip it from the search space
2824 		 */
2825 		min_chan = MIN_6GHZ_CHANNEL + 1;
2826 		max_chan = MAX_6GHZ_CHANNEL;
2827 		return reg_compute_chan_to_freq(pdev, chan_num,
2828 						min_chan,
2829 						max_chan);
2830 	} else {
2831 		if (BAND_2G_PRESENT(band_mask)) {
2832 			min_chan = MIN_24GHZ_CHANNEL;
2833 			max_chan = MAX_24GHZ_CHANNEL;
2834 			freq = reg_compute_chan_to_freq(pdev, chan_num,
2835 							min_chan,
2836 							max_chan);
2837 			if (freq != 0)
2838 				return freq;
2839 		}
2840 
2841 		if (BAND_5G_PRESENT(band_mask)) {
2842 			min_chan = BAND_5GHZ_START_CHANNEL;
2843 			max_chan = MAX_5GHZ_CHANNEL;
2844 
2845 			return reg_compute_chan_to_freq(pdev, chan_num,
2846 							min_chan,
2847 							max_chan);
2848 		}
2849 
2850 		reg_err_rl("Incorrect band_mask %x", band_mask);
2851 		return 0;
2852 	}
2853 }
2854 
2855 #ifdef CONFIG_49GHZ_CHAN
2856 bool reg_is_49ghz_freq(qdf_freq_t freq)
2857 {
2858 	return REG_IS_49GHZ_FREQ(freq);
2859 }
2860 #endif /* CONFIG_49GHZ_CHAN */
2861 
2862 qdf_freq_t reg_ch_num(uint32_t ch_enum)
2863 {
2864 	return REG_CH_NUM(ch_enum);
2865 }
2866 
2867 qdf_freq_t reg_ch_to_freq(uint32_t ch_enum)
2868 {
2869 	return REG_CH_TO_FREQ(ch_enum);
2870 }
2871 
2872 uint8_t reg_max_5ghz_ch_num(void)
2873 {
2874 	return REG_MAX_5GHZ_CH_NUM;
2875 }
2876 
2877 #ifdef CONFIG_CHAN_FREQ_API
2878 qdf_freq_t reg_min_24ghz_chan_freq(void)
2879 {
2880 	return REG_MIN_24GHZ_CH_FREQ;
2881 }
2882 
2883 qdf_freq_t reg_max_24ghz_chan_freq(void)
2884 {
2885 	return REG_MAX_24GHZ_CH_FREQ;
2886 }
2887 
2888 qdf_freq_t reg_min_5ghz_chan_freq(void)
2889 {
2890 	return REG_MIN_5GHZ_CH_FREQ;
2891 }
2892 
2893 qdf_freq_t reg_max_5ghz_chan_freq(void)
2894 {
2895 	return REG_MAX_5GHZ_CH_FREQ;
2896 }
2897 #endif /* CONFIG_CHAN_FREQ_API */
2898 
2899 QDF_STATUS reg_enable_dfs_channels(struct wlan_objmgr_pdev *pdev,
2900 				   bool enable)
2901 {
2902 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2903 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2904 	struct wlan_objmgr_psoc *psoc;
2905 	QDF_STATUS status;
2906 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2907 
2908 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2909 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2910 		reg_err("pdev reg component is NULL");
2911 		return QDF_STATUS_E_INVAL;
2912 	}
2913 
2914 	if (pdev_priv_obj->dfs_enabled == enable) {
2915 		reg_info("dfs_enabled is already set to %d", enable);
2916 		return QDF_STATUS_SUCCESS;
2917 	}
2918 
2919 	psoc = wlan_pdev_get_psoc(pdev);
2920 	if (!psoc) {
2921 		reg_err("psoc is NULL");
2922 		return QDF_STATUS_E_INVAL;
2923 	}
2924 
2925 	psoc_priv_obj = reg_get_psoc_obj(psoc);
2926 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
2927 		reg_err("psoc reg component is NULL");
2928 		return QDF_STATUS_E_INVAL;
2929 	}
2930 
2931 	reg_info("set dfs_enabled: %d", enable);
2932 
2933 	pdev_priv_obj->dfs_enabled = enable;
2934 
2935 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
2936 
2937 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
2938 
2939 	/* Fill the ic channel list with the updated current channel
2940 	 * chan list.
2941 	 */
2942 	if (reg_tx_ops->fill_umac_legacy_chanlist)
2943 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
2944 				pdev_priv_obj->cur_chan_list);
2945 
2946 	status = reg_send_scheduler_msg_sb(psoc, pdev);
2947 
2948 	return status;
2949 }
2950 
2951 #ifdef WLAN_REG_PARTIAL_OFFLOAD
2952 bool reg_is_regdmn_en302502_applicable(struct wlan_objmgr_pdev *pdev)
2953 {
2954 	struct cur_regdmn_info cur_reg_dmn;
2955 	QDF_STATUS status;
2956 
2957 	status = reg_get_curr_regdomain(pdev, &cur_reg_dmn);
2958 	if (status != QDF_STATUS_SUCCESS) {
2959 		reg_err("Failed to get reg domain");
2960 		return false;
2961 	}
2962 
2963 	return reg_en302_502_regdmn(cur_reg_dmn.regdmn_pair_id);
2964 }
2965 #endif
2966 
2967 QDF_STATUS reg_get_phybitmap(struct wlan_objmgr_pdev *pdev,
2968 			     uint16_t *phybitmap)
2969 {
2970 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2971 
2972 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2973 
2974 	if (!pdev_priv_obj) {
2975 		reg_err("reg pdev private obj is NULL");
2976 		return QDF_STATUS_E_FAULT;
2977 	}
2978 
2979 	*phybitmap = pdev_priv_obj->phybitmap;
2980 
2981 	return QDF_STATUS_SUCCESS;
2982 }
2983 
2984 QDF_STATUS reg_update_channel_ranges(struct wlan_objmgr_pdev *pdev)
2985 {
2986 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2987 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
2988 	struct wlan_objmgr_psoc *psoc;
2989 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
2990 	struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr;
2991 	uint32_t cnt;
2992 	uint8_t phy_id;
2993 	uint8_t pdev_id;
2994 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2995 
2996 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
2997 
2998 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2999 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3000 		reg_err("pdev reg component is NULL");
3001 		return QDF_STATUS_E_INVAL;
3002 	}
3003 
3004 	psoc = wlan_pdev_get_psoc(pdev);
3005 	if (!psoc) {
3006 		reg_err("psoc is NULL");
3007 		return QDF_STATUS_E_INVAL;
3008 	}
3009 
3010 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
3011 	if (reg_tx_ops->get_phy_id_from_pdev_id)
3012 		reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
3013 	else
3014 		phy_id = pdev_id;
3015 
3016 	psoc_priv_obj = reg_get_psoc_obj(psoc);
3017 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
3018 		reg_err("psoc reg component is NULL");
3019 		return QDF_STATUS_E_INVAL;
3020 	}
3021 
3022 	reg_cap_ptr = psoc_priv_obj->reg_cap;
3023 
3024 	for (cnt = 0; cnt < PSOC_MAX_PHY_REG_CAP; cnt++) {
3025 		if (!reg_cap_ptr) {
3026 			qdf_mem_free(pdev_priv_obj);
3027 			reg_err("reg cap ptr is NULL");
3028 			return QDF_STATUS_E_FAULT;
3029 		}
3030 
3031 		if (reg_cap_ptr->phy_id == phy_id)
3032 			break;
3033 		reg_cap_ptr++;
3034 	}
3035 
3036 	if (cnt == PSOC_MAX_PHY_REG_CAP) {
3037 		qdf_mem_free(pdev_priv_obj);
3038 		reg_err("extended capabilities not found for pdev");
3039 		return QDF_STATUS_E_FAULT;
3040 	}
3041 	pdev_priv_obj->range_2g_low = reg_cap_ptr->low_2ghz_chan;
3042 	pdev_priv_obj->range_2g_high = reg_cap_ptr->high_2ghz_chan;
3043 	pdev_priv_obj->range_5g_low = reg_cap_ptr->low_5ghz_chan;
3044 	pdev_priv_obj->range_5g_high = reg_cap_ptr->high_5ghz_chan;
3045 	pdev_priv_obj->wireless_modes = reg_cap_ptr->wireless_modes;
3046 
3047 	return status;
3048 }
3049 
3050 QDF_STATUS reg_modify_pdev_chan_range(struct wlan_objmgr_pdev *pdev)
3051 {
3052 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3053 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
3054 	struct wlan_objmgr_psoc *psoc;
3055 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
3056 	enum direction dir;
3057 	QDF_STATUS status;
3058 
3059 	status = reg_update_channel_ranges(pdev);
3060 	if (status != QDF_STATUS_SUCCESS)
3061 		return status;
3062 
3063 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3064 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3065 		reg_err("pdev reg component is NULL");
3066 		return QDF_STATUS_E_INVAL;
3067 	}
3068 
3069 	psoc = wlan_pdev_get_psoc(pdev);
3070 	if (!psoc) {
3071 		reg_err("psoc is NULL");
3072 		return QDF_STATUS_E_INVAL;
3073 	}
3074 
3075 	psoc_priv_obj = reg_get_psoc_obj(psoc);
3076 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
3077 		reg_err("psoc reg component is NULL");
3078 		return QDF_STATUS_E_INVAL;
3079 	}
3080 
3081 	if (psoc_priv_obj->offload_enabled) {
3082 		dir = NORTHBOUND;
3083 	} else {
3084 		dir = SOUTHBOUND;
3085 	}
3086 
3087 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
3088 
3089 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
3090 
3091 	/* Fill the ic channel list with the updated current channel
3092 	 * chan list.
3093 	 */
3094 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
3095 	    reg_tx_ops->fill_umac_legacy_chanlist(pdev,
3096 						  pdev_priv_obj->cur_chan_list);
3097 
3098 	} else {
3099 		if (dir == NORTHBOUND)
3100 			status = reg_send_scheduler_msg_nb(psoc, pdev);
3101 		else
3102 			status = reg_send_scheduler_msg_sb(psoc, pdev);
3103 	}
3104 
3105 	return status;
3106 }
3107 
3108 QDF_STATUS reg_update_pdev_wireless_modes(struct wlan_objmgr_pdev *pdev,
3109 					  uint64_t wireless_modes)
3110 {
3111 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3112 
3113 	pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
3114 							      WLAN_UMAC_COMP_REGULATORY);
3115 
3116 	if (!pdev_priv_obj) {
3117 		reg_err("reg pdev private obj is NULL");
3118 		return QDF_STATUS_E_INVAL;
3119 	}
3120 
3121 	pdev_priv_obj->wireless_modes = wireless_modes;
3122 
3123 	return QDF_STATUS_SUCCESS;
3124 }
3125 
3126 #ifdef DISABLE_UNII_SHARED_BANDS
3127 /**
3128  * reg_is_reg_unii_band_1_or_reg_unii_band_2a() - Check the input bitmap
3129  * @unii_5g_bitmap: 5G UNII band bitmap
3130  *
3131  * This function checks if either REG_UNII_BAND_1 or REG_UNII_BAND_2A,
3132  * are present in the 5G UNII band bitmap.
3133  *
3134  * Return: Return true if REG_UNII_BAND_1 or REG_UNII_BAND_2A, are present in
3135  * the UNII 5g bitmap else return false.
3136  */
3137 static bool
3138 reg_is_reg_unii_band_1_or_reg_unii_band_2a(uint8_t unii_5g_bitmap)
3139 {
3140 	if (!unii_5g_bitmap)
3141 		return false;
3142 
3143 	return ((unii_5g_bitmap & (BIT(REG_UNII_BAND_1) |
3144 		 BIT(REG_UNII_BAND_2A))) ==  unii_5g_bitmap);
3145 }
3146 
3147 QDF_STATUS reg_disable_chan_coex(struct wlan_objmgr_pdev *pdev,
3148 				 uint8_t unii_5g_bitmap)
3149 {
3150 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3151 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
3152 	struct wlan_objmgr_psoc *psoc;
3153 
3154 	psoc = wlan_pdev_get_psoc(pdev);
3155 	if (!psoc) {
3156 		reg_err("psoc is NULL");
3157 		return QDF_STATUS_E_INVAL;
3158 	}
3159 
3160 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3161 
3162 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3163 		reg_err_rl("reg pdev priv obj is NULL");
3164 		return QDF_STATUS_E_FAILURE;
3165 	}
3166 
3167 	if (unii_5g_bitmap &&
3168 	    !reg_is_reg_unii_band_1_or_reg_unii_band_2a(unii_5g_bitmap)) {
3169 		reg_err_rl("Invalid unii_5g_bitmap =  %d", unii_5g_bitmap);
3170 		return QDF_STATUS_E_FAILURE;
3171 	}
3172 
3173 	if (pdev_priv_obj->unii_5g_bitmap == unii_5g_bitmap) {
3174 		reg_debug_rl("UNII bitmask for 5G channels is already set  %d",
3175 			    unii_5g_bitmap);
3176 		return QDF_STATUS_SUCCESS;
3177 	}
3178 
3179 	reg_debug_rl("Setting UNII bitmask for 5G: %d", unii_5g_bitmap);
3180 	pdev_priv_obj->unii_5g_bitmap = unii_5g_bitmap;
3181 
3182 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
3183 
3184 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
3185 
3186 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
3187 		reg_tx_ops->fill_umac_legacy_chanlist(pdev,
3188 				pdev_priv_obj->cur_chan_list);
3189 	}
3190 
3191 	return QDF_STATUS_SUCCESS;
3192 }
3193 #endif
3194 
3195 bool reg_is_chan_disabled(uint32_t chan_flags, enum channel_state chan_state)
3196 {
3197 	return (REGULATORY_CHAN_DISABLED & chan_flags ||
3198 		chan_state == CHANNEL_STATE_DISABLE);
3199 }
3200 
3201 #ifdef CONFIG_REG_CLIENT
3202 #ifdef CONFIG_BAND_6GHZ
3203 static void reg_append_6g_channel_list_with_power(
3204 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
3205 			struct channel_power *ch_list,
3206 			uint8_t *count,
3207 			enum supported_6g_pwr_types in_6g_pwr_type)
3208 {
3209 	struct super_chan_info *sc_entry;
3210 	enum supported_6g_pwr_types pwr_type;
3211 	uint8_t i, count_6g = *count;
3212 
3213 	pwr_type = in_6g_pwr_type;
3214 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
3215 		sc_entry = &pdev_priv_obj->super_chan_list[i];
3216 
3217 		if (in_6g_pwr_type == REG_BEST_PWR_MODE)
3218 			pwr_type = sc_entry->best_power_mode;
3219 
3220 		if (reg_is_supp_pwr_mode_invalid(pwr_type))
3221 			continue;
3222 
3223 		if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type],
3224 					  sc_entry->state_arr[pwr_type])) {
3225 			ch_list[count_6g].center_freq =
3226 					reg_ch_to_freq(i + MIN_6GHZ_CHANNEL);
3227 			ch_list[count_6g].chan_num =
3228 					reg_ch_num(i + MIN_6GHZ_CHANNEL);
3229 			ch_list[count_6g++].tx_power =
3230 				sc_entry->reg_chan_pwr[pwr_type].tx_power;
3231 		}
3232 	}
3233 	*count = count_6g;
3234 }
3235 #else
3236 static inline void reg_append_6g_channel_list_with_power(
3237 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
3238 			struct channel_power *ch_list,
3239 			uint8_t *count,
3240 			enum supported_6g_pwr_types in_6g_pwr_type)
3241 {
3242 }
3243 #endif
3244 
3245 QDF_STATUS reg_get_channel_list_with_power(
3246 				struct wlan_objmgr_pdev *pdev,
3247 				struct channel_power *ch_list,
3248 				uint8_t *num_chan,
3249 				enum supported_6g_pwr_types in_6g_pwr_type)
3250 {
3251 	uint8_t i, count;
3252 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3253 	uint8_t max_curr_num_chan;
3254 
3255 	if (!pdev) {
3256 		reg_err_rl("invalid pdev");
3257 		return QDF_STATUS_E_INVAL;
3258 	}
3259 
3260 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3261 
3262 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3263 		reg_err_rl("reg pdev priv obj is NULL");
3264 		return QDF_STATUS_E_INVAL;
3265 	}
3266 
3267 	if (!num_chan || !ch_list) {
3268 		reg_err("chan_list or num_ch is NULL");
3269 		return QDF_STATUS_E_FAILURE;
3270 	}
3271 
3272 	*num_chan = 0;
3273 
3274 	if (in_6g_pwr_type == REG_CURRENT_PWR_MODE)
3275 		max_curr_num_chan = NUM_CHANNELS;
3276 	else
3277 		max_curr_num_chan = MAX_5GHZ_CHANNEL;
3278 
3279 	for (i = 0, count = 0; i < max_curr_num_chan; i++) {
3280 		if (!reg_is_chan_disabled(
3281 				pdev_priv_obj->cur_chan_list[i].chan_flags,
3282 				pdev_priv_obj->cur_chan_list[i].state)) {
3283 			ch_list[count].center_freq =
3284 				pdev_priv_obj->cur_chan_list[i].center_freq;
3285 			ch_list[count].chan_num =
3286 				pdev_priv_obj->cur_chan_list[i].chan_num;
3287 			ch_list[count++].tx_power =
3288 				pdev_priv_obj->cur_chan_list[i].tx_power;
3289 		}
3290 	}
3291 
3292 	if (in_6g_pwr_type == REG_CURRENT_PWR_MODE) {
3293 		*num_chan = count;
3294 		return QDF_STATUS_SUCCESS;
3295 	}
3296 
3297 	reg_append_6g_channel_list_with_power(pdev_priv_obj, ch_list, &count,
3298 					      in_6g_pwr_type);
3299 	*num_chan = count;
3300 
3301 	return QDF_STATUS_SUCCESS;
3302 }
3303 #endif
3304 
3305 #ifdef CONFIG_CHAN_FREQ_API
3306 QDF_STATUS reg_get_channel_list_with_power_for_freq(struct wlan_objmgr_pdev
3307 						    *pdev,
3308 						    struct channel_power
3309 						    *ch_list,
3310 						    uint8_t *num_chan)
3311 {
3312 	int i, count;
3313 	struct regulatory_channel *reg_channels;
3314 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3315 
3316 	if (!num_chan || !ch_list) {
3317 		reg_err("chan_list or num_ch is NULL");
3318 		return QDF_STATUS_E_FAILURE;
3319 	}
3320 
3321 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3322 
3323 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3324 		reg_err("reg pdev priv obj is NULL");
3325 		return QDF_STATUS_E_FAILURE;
3326 	}
3327 
3328 	/* set the current channel list */
3329 	reg_channels = pdev_priv_obj->cur_chan_list;
3330 
3331 	for (i = 0, count = 0; i < NUM_CHANNELS; i++) {
3332 		if (reg_channels[i].state &&
3333 		    !(reg_channels[i].chan_flags & REGULATORY_CHAN_DISABLED)) {
3334 			ch_list[count].center_freq =
3335 				reg_channels[i].center_freq;
3336 			ch_list[count].chan_num = reg_channels[i].chan_num;
3337 			ch_list[count++].tx_power =
3338 				reg_channels[i].tx_power;
3339 		}
3340 	}
3341 
3342 	*num_chan = count;
3343 
3344 	return QDF_STATUS_SUCCESS;
3345 }
3346 
3347 enum channel_enum reg_get_chan_enum_for_freq(qdf_freq_t freq)
3348 {
3349 	int16_t start = 0;
3350 	int16_t end = NUM_CHANNELS - 1;
3351 
3352 	while (start <= end) {
3353 		int16_t middle = (start + end) / 2;
3354 		qdf_freq_t mid_freq_elem = channel_map[middle].center_freq;
3355 
3356 		if (freq == mid_freq_elem)
3357 			return middle;
3358 		if (freq > mid_freq_elem)
3359 			start = middle + 1;
3360 		else
3361 			end = middle - 1;
3362 	}
3363 
3364 	reg_debug_rl("invalid channel center frequency %d", freq);
3365 
3366 	return INVALID_CHANNEL;
3367 }
3368 
3369 bool
3370 reg_is_freq_present_in_cur_chan_list(struct wlan_objmgr_pdev *pdev,
3371 				     qdf_freq_t freq)
3372 {
3373 	enum channel_enum chan_enum;
3374 	struct regulatory_channel *cur_chan_list;
3375 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3376 
3377 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3378 
3379 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3380 		reg_err_rl("pdev reg obj is NULL");
3381 		return false;
3382 	}
3383 
3384 	cur_chan_list = pdev_priv_obj->cur_chan_list;
3385 
3386 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++)
3387 		if (cur_chan_list[chan_enum].center_freq == freq)
3388 			if ((cur_chan_list[chan_enum].state !=
3389 			     CHANNEL_STATE_DISABLE) &&
3390 			    !(cur_chan_list[chan_enum].chan_flags &
3391 			      REGULATORY_CHAN_DISABLED))
3392 				return true;
3393 
3394 	reg_debug_rl("Channel center frequency %d not found", freq);
3395 
3396 	return false;
3397 }
3398 
3399 #ifdef WLAN_FEATURE_GET_USABLE_CHAN_LIST
3400 /**
3401  * is_freq_present_in_resp_list() - is freq present in resp list
3402  *
3403  * @pcl_ch: pcl ch
3404  * @res_msg: Response msg
3405  * @count: no of usable channels
3406  *
3407  * Return: void
3408  */
3409 static bool
3410 is_freq_present_in_resp_list(uint32_t pcl_ch,
3411 			     struct get_usable_chan_res_params *res_msg,
3412 			     int count)
3413 {
3414 	int i;
3415 
3416 	for (i = 0; i < count; i++) {
3417 		if (res_msg[i].freq == pcl_ch)
3418 			return true;
3419 	}
3420 	return false;
3421 }
3422 
3423 /**
3424  * reg_update_usable_chan_resp() - Update response msg
3425  * @pdev: Pointer to pdev
3426  * @res_msg: Response msg
3427  * @pcl_ch: pcl channel
3428  * @len: calculated pcl len
3429  * @iface_mode_mask: interface type
3430  * @band_mask: requested band mask
3431  * @count: no of usable channels
3432  *
3433  * Return: void
3434  */
3435 static void
3436 reg_update_usable_chan_resp(struct wlan_objmgr_pdev *pdev,
3437 			    struct get_usable_chan_res_params *res_msg,
3438 			    uint32_t *pcl_ch, uint32_t len,
3439 			    uint32_t iface_mode_mask,
3440 			    uint32_t band_mask, int *count)
3441 {
3442 	int i;
3443 	struct ch_params ch_params = {0};
3444 	int index = *count;
3445 
3446 	for (i = 0; i < len && index < NUM_CHANNELS; i++) {
3447 		/* In case usable channels are required for multiple filter
3448 		 * mask, Some frequencies may present in res_msg . To avoid
3449 		 * frequency duplication, only mode mask is updated for
3450 		 * existing freqency.
3451 		 */
3452 		if (is_freq_present_in_resp_list(pcl_ch[i], res_msg, *count))
3453 			continue;
3454 
3455 		if (!(band_mask & 1 << wlan_reg_freq_to_band(pcl_ch[i])))
3456 			continue;
3457 
3458 		ch_params.ch_width = CH_WIDTH_MAX;
3459 		reg_set_channel_params_for_freq(
3460 				pdev,
3461 				pcl_ch[i],
3462 				0, &ch_params, true);
3463 		res_msg[index].freq = (qdf_freq_t)pcl_ch[i];
3464 		res_msg[index].iface_mode_mask |= 1 << iface_mode_mask;
3465 		res_msg[index].bw = ch_params.ch_width;
3466 		if (ch_params.center_freq_seg0)
3467 			res_msg[index].seg0_freq =
3468 					ch_params.center_freq_seg0;
3469 		if (ch_params.center_freq_seg1)
3470 			res_msg[index].seg1_freq =
3471 					ch_params.center_freq_seg1;
3472 		index++;
3473 	}
3474 
3475 	*count = index;
3476 }
3477 
3478 /**
3479  * reg_update_conn_chan_list() - Get usable channels with conn filter
3480  *				 and policy mgr mask
3481  * @pdev: Pointer to pdev
3482  * @res_msg: Response msg
3483  * @policy_mgr_con_mode: policy mgr mode
3484  * @iftype: interface type
3485  * @band_mask: requested band mask
3486  * @count: no of usable channels
3487  *
3488  * Return: qdf status
3489  */
3490 static QDF_STATUS
3491 reg_update_conn_chan_list(struct wlan_objmgr_pdev *pdev,
3492 			  struct get_usable_chan_res_params *res_msg,
3493 			  enum policy_mgr_con_mode mode,
3494 			  uint32_t iftype,
3495 			  uint32_t band_mask,
3496 			  uint32_t *count)
3497 {
3498 	uint32_t *pcl_ch;
3499 	uint8_t *weight_list;
3500 	uint32_t len;
3501 	uint32_t weight_len;
3502 	struct wlan_objmgr_psoc *psoc;
3503 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3504 
3505 	pcl_ch = qdf_mem_malloc(NUM_CHANNELS *
3506 			sizeof(uint32_t));
3507 
3508 	if (!pcl_ch) {
3509 		reg_err("pcl_ch invalid");
3510 		return QDF_STATUS_E_FAILURE;
3511 	}
3512 
3513 	weight_list = qdf_mem_malloc(NUM_CHANNELS *
3514 			sizeof(uint8_t));
3515 
3516 	if (!weight_list) {
3517 		reg_err("weight_list invalid");
3518 		qdf_mem_free(pcl_ch);
3519 		return QDF_STATUS_E_FAILURE;
3520 	}
3521 
3522 	psoc = wlan_pdev_get_psoc(pdev);
3523 	if (!psoc) {
3524 		reg_err("invalid psoc");
3525 		status = QDF_STATUS_E_FAILURE;
3526 		goto err;
3527 	}
3528 
3529 	len = NUM_CHANNELS;
3530 	weight_len = NUM_CHANNELS;
3531 
3532 	status = policy_mgr_get_pcl(psoc, mode, pcl_ch, &len,
3533 				    weight_list, weight_len);
3534 	if (QDF_IS_STATUS_ERROR(status)) {
3535 		reg_err("get pcl failed for mode: %d", mode);
3536 		goto err;
3537 	}
3538 	reg_update_usable_chan_resp(pdev, res_msg, pcl_ch, len,
3539 				    iftype, band_mask, count);
3540 err:
3541 	qdf_mem_free(pcl_ch);
3542 	qdf_mem_free(weight_list);
3543 	return status;
3544 }
3545 
3546 /**
3547  * reg_get_usable_channel_con_filter() - Get usable channel with con filter mask
3548  * @pdev: Pointer to pdev
3549  * @req_msg: Request msg
3550  * @res_msg: Response msg
3551  * @chan_list: reg channel list
3552  * @count: no of usable channels
3553  *
3554  * Return: qdf status
3555  */
3556 static QDF_STATUS
3557 reg_get_usable_channel_con_filter(struct wlan_objmgr_pdev *pdev,
3558 				  struct get_usable_chan_req_params req_msg,
3559 				  struct get_usable_chan_res_params *res_msg,
3560 				  int *count)
3561 {
3562 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3563 	uint32_t iface_mode_mask = req_msg.iface_mode_mask;
3564 
3565 	while (iface_mode_mask) {
3566 		if (iface_mode_mask & 1 << IFTYPE_AP) {
3567 			status =
3568 			reg_update_conn_chan_list(pdev, res_msg, PM_SAP_MODE,
3569 						  IFTYPE_AP, req_msg.band_mask,
3570 						  count);
3571 			iface_mode_mask &= ~(1 << IFTYPE_AP);
3572 		} else if (iface_mode_mask & 1 << IFTYPE_STATION) {
3573 			status =
3574 			reg_update_conn_chan_list(pdev, res_msg, PM_STA_MODE,
3575 						  IFTYPE_STATION,
3576 						  req_msg.band_mask, count);
3577 			iface_mode_mask &= ~(1 << IFTYPE_STATION);
3578 		} else if (iface_mode_mask & 1 << IFTYPE_P2P_GO) {
3579 			status =
3580 			reg_update_conn_chan_list(pdev, res_msg, PM_P2P_GO_MODE,
3581 						  IFTYPE_P2P_GO,
3582 						  req_msg.band_mask, count);
3583 			iface_mode_mask &= ~(1 << IFTYPE_P2P_GO);
3584 		} else if (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) {
3585 			status =
3586 			reg_update_conn_chan_list(pdev, res_msg,
3587 						  PM_P2P_CLIENT_MODE,
3588 						  IFTYPE_P2P_CLIENT,
3589 						  req_msg.band_mask, count);
3590 			iface_mode_mask &= ~(1 << IFTYPE_P2P_CLIENT);
3591 		} else if (iface_mode_mask & 1 << IFTYPE_NAN) {
3592 			status =
3593 			reg_update_conn_chan_list(pdev, res_msg,
3594 						  PM_NAN_DISC_MODE, IFTYPE_NAN,
3595 						  req_msg.band_mask, count);
3596 			iface_mode_mask &= ~(1 << IFTYPE_NAN);
3597 		} else {
3598 			reg_err("invalid mode");
3599 			break;
3600 		}
3601 	}
3602 	return status;
3603 }
3604 
3605 /**
3606  * reg_remove_freq() - Remove invalid freq
3607  * @res_msg: Response msg
3608  * @index: index of freq that needs to be removed
3609  *
3610  * Return: void
3611  */
3612 static void
3613 reg_remove_freq(struct get_usable_chan_res_params *res_msg,
3614 		int index)
3615 {
3616 	reg_debug("removing freq %d", res_msg[index].freq);
3617 	qdf_mem_zero(&res_msg[index],
3618 		     sizeof(struct get_usable_chan_res_params));
3619 }
3620 
3621 /**
3622  * reg_skip_invalid_chan_freq() - Remove invalid freq for SAP, P2P GO
3623  *				  and NAN
3624  * @pdev: Pointer to pdev
3625  * @res_msg: Response msg
3626  * @count: no of usable channels
3627  * @iface_mode_mask: interface mode mask
3628  *
3629  * Return: qdf status
3630  */
3631 static QDF_STATUS
3632 reg_skip_invalid_chan_freq(struct wlan_objmgr_pdev *pdev,
3633 			   struct get_usable_chan_res_params *res_msg,
3634 			   uint32_t *no_usable_channels,
3635 			   uint32_t iface_mode_mask)
3636 {
3637 	uint32_t chan_enum, iface_mode = 0;
3638 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3639 	bool include_indoor_channel, dfs_master_capable;
3640 	uint8_t enable_srd_chan, srd_mask = 0;
3641 	struct wlan_objmgr_psoc *psoc;
3642 	psoc = wlan_pdev_get_psoc(pdev);
3643 	if (!psoc) {
3644 		reg_err("invalid psoc");
3645 		return QDF_STATUS_E_FAILURE;
3646 	}
3647 
3648 	status = ucfg_mlme_get_indoor_channel_support(psoc,
3649 						      &include_indoor_channel);
3650 	if (QDF_IS_STATUS_ERROR(status)) {
3651 		reg_err("failed to get indoor channel skip info");
3652 		return QDF_STATUS_E_FAILURE;
3653 	}
3654 
3655 	ucfg_mlme_get_etsi_srd_chan_in_master_mode(psoc,
3656 						   &enable_srd_chan);
3657 	if (QDF_IS_STATUS_ERROR(status)) {
3658 		reg_err("failed to get srd chan info");
3659 		return QDF_STATUS_E_FAILURE;
3660 	}
3661 
3662 	status = ucfg_mlme_get_dfs_master_capability(psoc, &dfs_master_capable);
3663 	if (QDF_IS_STATUS_ERROR(status)) {
3664 		reg_err("failed to get dfs master capable");
3665 		return status;
3666 	}
3667 
3668 	while (iface_mode_mask) {
3669 		if (iface_mode_mask & (1 << IFTYPE_AP)) {
3670 			srd_mask = 1;
3671 			iface_mode = 1 << IFTYPE_AP;
3672 		} else if (iface_mode_mask & (1 << IFTYPE_P2P_GO)) {
3673 			srd_mask = 2;
3674 			iface_mode = 1 << IFTYPE_P2P_GO;
3675 		} else if (iface_mode_mask & (1 << IFTYPE_NAN)) {
3676 			iface_mode = 1 << IFTYPE_NAN;
3677 		} else {
3678 			break;
3679 		}
3680 		for (chan_enum = 0; chan_enum < *no_usable_channels;
3681 		     chan_enum++) {
3682 			if (iface_mode_mask & (1 << IFTYPE_NAN)) {
3683 				if (!wlan_is_nan_allowed_on_freq(pdev,
3684 				     res_msg[chan_enum].freq))
3685 					res_msg[chan_enum].iface_mode_mask &=
3686 						~(iface_mode);
3687 				if (!res_msg[chan_enum].iface_mode_mask)
3688 					reg_remove_freq(res_msg, chan_enum);
3689 			} else {
3690 				if (wlan_reg_is_freq_indoor(
3691 					pdev, res_msg[chan_enum].freq) &&
3692 					!include_indoor_channel) {
3693 					res_msg[chan_enum].iface_mode_mask &=
3694 							~(iface_mode);
3695 					if (!res_msg[chan_enum].iface_mode_mask)
3696 						reg_remove_freq(res_msg,
3697 								chan_enum);
3698 				}
3699 
3700 				if (!(enable_srd_chan & srd_mask) &&
3701 				    reg_is_etsi13_srd_chan_for_freq(
3702 					pdev, res_msg[chan_enum].freq)) {
3703 					res_msg[chan_enum].iface_mode_mask &=
3704 						~(iface_mode);
3705 					if (!res_msg[chan_enum].iface_mode_mask)
3706 						reg_remove_freq(res_msg,
3707 								chan_enum);
3708 				}
3709 
3710 				if (!dfs_master_capable &&
3711 				    wlan_reg_is_dfs_for_freq(pdev,
3712 				    res_msg[chan_enum].freq)) {
3713 					res_msg[chan_enum].iface_mode_mask &=
3714 						~(iface_mode);
3715 					if (!res_msg[chan_enum].iface_mode_mask)
3716 						reg_remove_freq(res_msg,
3717 								chan_enum);
3718 				}
3719 			}
3720 		}
3721 
3722 		iface_mode_mask &= ~iface_mode;
3723 	}
3724 
3725 	return status;
3726 }
3727 
3728 /**
3729  * reg_get_usable_channel_no_filter() - Get usable channel with no filter mask
3730  * @pdev: Pointer to pdev
3731  * @req_msg: Request msg
3732  * @res_msg: Response msg
3733  * @chan_list: reg channel list
3734  * @count: no of usable channels
3735  *
3736  * Return: qdf status
3737  */
3738 static QDF_STATUS
3739 reg_get_usable_channel_no_filter(struct wlan_objmgr_pdev *pdev,
3740 				 struct get_usable_chan_req_params req_msg,
3741 				 struct get_usable_chan_res_params *res_msg,
3742 				 struct regulatory_channel *chan_list,
3743 				 int *count)
3744 {
3745 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3746 
3747 	status =
3748 	reg_skip_invalid_chan_freq(pdev, res_msg,
3749 				   count, req_msg.iface_mode_mask);
3750 	return status;
3751 }
3752 
3753 /**
3754  * reg_get_usable_channel_coex_filter() - Get usable channel with coex filter
3755  * @pdev: Pointer to pdev
3756  * @req_msg: Request msg
3757  * @res_msg: Response msg
3758  * @chan_list: reg channel list
3759  * @count: no of usable channels
3760  *
3761  * Return: qdf status
3762  */
3763 static QDF_STATUS
3764 reg_get_usable_channel_coex_filter(struct wlan_objmgr_pdev *pdev,
3765 				   struct get_usable_chan_req_params req_msg,
3766 				   struct get_usable_chan_res_params *res_msg,
3767 				   struct regulatory_channel *chan_list,
3768 				   int *count)
3769 {
3770 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
3771 	enum channel_enum chan_enum;
3772 	uint32_t i = 0;
3773 	struct ch_avoid_freq_type freq_range;
3774 	struct wlan_objmgr_psoc *psoc;
3775 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3776 
3777 	psoc = wlan_pdev_get_psoc(pdev);
3778 	if (!psoc) {
3779 		reg_err("invalid psoc");
3780 		return QDF_STATUS_E_FAILURE;
3781 	}
3782 
3783 	psoc_priv_obj = reg_get_psoc_obj(psoc);
3784 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
3785 		reg_alert("psoc reg component is NULL");
3786 		return QDF_STATUS_E_FAILURE;
3787 	}
3788 	for (chan_enum = 0; chan_enum < *count; chan_enum++) {
3789 		for (i = 0; i <
3790 		    psoc_priv_obj->avoid_freq_list.ch_avoid_range_cnt; i++) {
3791 			freq_range =
3792 			psoc_priv_obj->avoid_freq_list.avoid_freq_range[i];
3793 
3794 			if (freq_range.start_freq <=
3795 			    chan_list[chan_enum].center_freq &&
3796 			    freq_range.end_freq >=
3797 			    chan_list[chan_enum].center_freq) {
3798 				reg_debug("avoid freq %d",
3799 					  chan_list[chan_enum].center_freq);
3800 				reg_remove_freq(res_msg, chan_enum);
3801 			}
3802 		}
3803 	}
3804 	if (req_msg.iface_mode_mask & 1 << IFTYPE_AP ||
3805 	    req_msg.iface_mode_mask & 1 << IFTYPE_P2P_GO ||
3806 	    req_msg.iface_mode_mask & 1 << IFTYPE_NAN)
3807 		status =
3808 		reg_skip_invalid_chan_freq(pdev, res_msg, count,
3809 					   req_msg.iface_mode_mask);
3810 	return status;
3811 }
3812 
3813 /**
3814  * reg_calculate_mode_mask() - calculate valid mode mask
3815  * @iface_mode_mask: interface mode mask
3816  *
3817  * Return: Valid mode mask
3818  */
3819 static uint32_t
3820 reg_calculate_mode_mask(uint32_t iface_mode_mask)
3821 {
3822 	int mode_mask = 0;
3823 
3824 	mode_mask = (iface_mode_mask & 1 << IFTYPE_STATION) |
3825 		    (iface_mode_mask & 1 << IFTYPE_AP) |
3826 		    (iface_mode_mask & 1 << IFTYPE_P2P_GO) |
3827 		    (iface_mode_mask & 1 << IFTYPE_P2P_CLIENT) |
3828 		    (iface_mode_mask & 1 << IFTYPE_P2P_DEVICE) |
3829 		    (iface_mode_mask & 1 << IFTYPE_NAN);
3830 
3831 	return mode_mask;
3832 }
3833 
3834 /**
3835  * reg_add_usable_channel_to_resp() - Add usable channels to resp structure
3836  * @pdev: Pointer to pdev
3837  * @res_msg: Response msg
3838  * @iface_mode_mask: interface mode mask
3839  * @chan_list: reg channel list
3840  * @count: no of usable channels
3841  *
3842  * Return: qdf status
3843  */
3844 static QDF_STATUS
3845 reg_add_usable_channel_to_resp(struct wlan_objmgr_pdev *pdev,
3846 			       struct get_usable_chan_res_params *res_msg,
3847 			       uint32_t iface_mode_mask,
3848 			       struct regulatory_channel *chan_list,
3849 			       int *count)
3850 {
3851 	enum channel_enum chan_enum;
3852 	struct ch_params ch_params = {0};
3853 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3854 	uint32_t mode_mask = 0;
3855 
3856 	mode_mask = reg_calculate_mode_mask(iface_mode_mask);
3857 
3858 	for (chan_enum = 0; chan_enum < *count &&
3859 	     chan_enum < NUM_CHANNELS; chan_enum++) {
3860 		ch_params.ch_width = CH_WIDTH_MAX;
3861 		reg_set_channel_params_for_freq(
3862 				pdev,
3863 				chan_list[chan_enum].center_freq,
3864 				chan_list[chan_enum].max_bw, &ch_params, true);
3865 
3866 		res_msg[chan_enum].freq = chan_list[chan_enum].center_freq;
3867 		res_msg[chan_enum].iface_mode_mask = mode_mask;
3868 		if (!res_msg[chan_enum].iface_mode_mask) {
3869 			reg_err("invalid iface mask");
3870 			return QDF_STATUS_E_FAILURE;
3871 		}
3872 		res_msg[chan_enum].bw = ch_params.ch_width;
3873 		res_msg[chan_enum].state = chan_list[chan_enum].state;
3874 		if (ch_params.center_freq_seg0)
3875 			res_msg[chan_enum].seg0_freq =
3876 					ch_params.center_freq_seg0;
3877 		if (ch_params.center_freq_seg1)
3878 			res_msg[chan_enum].seg1_freq =
3879 					ch_params.center_freq_seg1;
3880 	}
3881 
3882 	return status;
3883 }
3884 
3885 QDF_STATUS
3886 wlan_reg_get_usable_channel(struct wlan_objmgr_pdev *pdev,
3887 			    struct get_usable_chan_req_params req_msg,
3888 			    struct get_usable_chan_res_params *res_msg,
3889 			    uint32_t *usable_channels)
3890 {
3891 	struct regulatory_channel *chan_list;
3892 	QDF_STATUS status = QDF_STATUS_SUCCESS;
3893 
3894 	chan_list = qdf_mem_malloc(NUM_CHANNELS *
3895 			sizeof(*chan_list));
3896 
3897 	if (!chan_list) {
3898 		reg_err("chan_list invalid");
3899 		return QDF_STATUS_E_FAILURE;
3900 	}
3901 
3902 	if ((req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) ||
3903 	    (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) &&
3904 	     !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))) {
3905 		*usable_channels = reg_get_band_channel_list(pdev,
3906 							     req_msg.band_mask,
3907 							     chan_list);
3908 		status =
3909 		reg_add_usable_channel_to_resp(pdev, res_msg,
3910 					       req_msg.iface_mode_mask,
3911 					       chan_list, usable_channels);
3912 		if (QDF_IS_STATUS_ERROR(status)) {
3913 			qdf_mem_free(chan_list);
3914 			return status;
3915 		}
3916 	}
3917 
3918 	if (req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY)
3919 		status =
3920 		reg_get_usable_channel_con_filter(pdev, req_msg, res_msg,
3921 						  usable_channels);
3922 
3923 	if (req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX)
3924 		status =
3925 		reg_get_usable_channel_coex_filter(pdev, req_msg, res_msg,
3926 						   chan_list, usable_channels);
3927 	if (!(req_msg.filter_mask & 1 << FILTER_CELLULAR_COEX) &&
3928 	    !(req_msg.filter_mask & 1 << FILTER_WLAN_CONCURRENCY))
3929 		status =
3930 		reg_get_usable_channel_no_filter(pdev, req_msg, res_msg,
3931 						 chan_list, usable_channels);
3932 	reg_debug("usable chan count is %d", *usable_channels);
3933 
3934 	qdf_mem_free(chan_list);
3935 	return status;
3936 }
3937 #endif
3938 
3939 enum channel_state reg_get_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
3940 						  qdf_freq_t freq)
3941 {
3942 	enum channel_enum ch_idx;
3943 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3944 
3945 	ch_idx = reg_get_chan_enum_for_freq(freq);
3946 
3947 	if (reg_is_chan_enum_invalid(ch_idx))
3948 		return CHANNEL_STATE_INVALID;
3949 
3950 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3951 
3952 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3953 		reg_err("pdev reg obj is NULL");
3954 		return CHANNEL_STATE_INVALID;
3955 	}
3956 
3957 	return pdev_priv_obj->cur_chan_list[ch_idx].state;
3958 }
3959 
3960 /**
3961  * reg_get_nol_channel_state () - Get channel state from regulatory
3962  * and treat NOL channels as enabled channels
3963  * @pdev: Pointer to pdev
3964  * @freq: channel center frequency.
3965  *
3966  * Return: channel state
3967  */
3968 static enum channel_state
3969 reg_get_nol_channel_state(struct wlan_objmgr_pdev *pdev,
3970 			  qdf_freq_t freq,
3971 			  enum supported_6g_pwr_types in_6g_pwr_mode)
3972 {
3973 	enum channel_enum ch_idx;
3974 	enum channel_state chan_state;
3975 
3976 	ch_idx = reg_get_chan_enum_for_freq(freq);
3977 
3978 	if (reg_is_chan_enum_invalid(ch_idx))
3979 		return CHANNEL_STATE_INVALID;
3980 
3981 	chan_state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_mode, false);
3982 
3983 	return chan_state;
3984 }
3985 
3986 /**
3987  * reg_get_5g_bonded_chan_state()- Return the channel state for a
3988  * 5G or 6G channel frequency based on the bonded channel.
3989  * @pdev: Pointer to pdev.
3990  * @freq: Channel center frequency.
3991  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
3992  *
3993  * Return: Channel State
3994  */
3995 static enum channel_state
3996 reg_get_5g_bonded_chan_state(struct wlan_objmgr_pdev *pdev,
3997 			     uint16_t freq,
3998 			     const struct bonded_channel_freq *bonded_chan_ptr,
3999 			     enum supported_6g_pwr_types in_6g_pwr_mode)
4000 {
4001 	uint16_t chan_cfreq;
4002 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
4003 	enum channel_state temp_chan_state;
4004 
4005 	chan_cfreq =  bonded_chan_ptr->start_freq;
4006 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
4007 		temp_chan_state = reg_get_nol_channel_state(pdev, chan_cfreq,
4008 							    in_6g_pwr_mode);
4009 		if (temp_chan_state < chan_state)
4010 			chan_state = temp_chan_state;
4011 		chan_cfreq = chan_cfreq + 20;
4012 	}
4013 
4014 	return chan_state;
4015 }
4016 
4017 enum channel_state
4018 reg_get_5g_chan_state(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq,
4019 		      enum phy_ch_width bw,
4020 		      enum supported_6g_pwr_types in_6g_pwr_mode)
4021 {
4022 	enum channel_enum ch_indx;
4023 	enum channel_state chan_state;
4024 	bool bw_enabled = false;
4025 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
4026 	uint16_t min_bw, max_bw;
4027 
4028 	if (bw > CH_WIDTH_80P80MHZ) {
4029 		reg_err_rl("bw passed is not good");
4030 		return CHANNEL_STATE_INVALID;
4031 	}
4032 
4033 	if (bw == CH_WIDTH_20MHZ)
4034 		return reg_get_nol_channel_state(pdev, freq, in_6g_pwr_mode);
4035 
4036 	/* Fetch the bonded_chan_ptr for width greater than 20MHZ. */
4037 	bonded_chan_ptr = reg_get_bonded_chan_entry(freq, bw, 0);
4038 
4039 	if (!bonded_chan_ptr)
4040 		return CHANNEL_STATE_INVALID;
4041 
4042 	chan_state = reg_get_5g_bonded_chan_state(pdev, freq, bonded_chan_ptr,
4043 						  in_6g_pwr_mode);
4044 
4045 	if ((chan_state == CHANNEL_STATE_INVALID) ||
4046 	    (chan_state == CHANNEL_STATE_DISABLE))
4047 		return chan_state;
4048 
4049 	ch_indx = reg_get_chan_enum_for_freq(freq);
4050 	if (reg_is_chan_enum_invalid(ch_indx))
4051 		return CHANNEL_STATE_INVALID;
4052 
4053 	if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode,
4054 					     &min_bw, &max_bw)) {
4055 		return CHANNEL_STATE_INVALID;
4056 	}
4057 
4058 	if (bw == CH_WIDTH_5MHZ)
4059 		bw_enabled = true;
4060 	else if (bw == CH_WIDTH_10MHZ)
4061 		bw_enabled = (min_bw <= 10) &&
4062 			(max_bw >= 10);
4063 	else if (bw == CH_WIDTH_20MHZ)
4064 		bw_enabled = (min_bw <= 20) &&
4065 			(max_bw >= 20);
4066 	else if (bw == CH_WIDTH_40MHZ)
4067 		bw_enabled = (min_bw <= 40) &&
4068 			(max_bw >= 40);
4069 	else if (bw == CH_WIDTH_80MHZ)
4070 		bw_enabled = (min_bw <= 80) &&
4071 			(max_bw >= 80);
4072 	else if (bw == CH_WIDTH_160MHZ)
4073 		bw_enabled = (min_bw <= 160) &&
4074 			(max_bw >= 160);
4075 	else if (bw == CH_WIDTH_80P80MHZ)
4076 		bw_enabled = (min_bw <= 80) &&
4077 			(max_bw >= 80);
4078 
4079 	if (bw_enabled)
4080 		return chan_state;
4081 	else
4082 		return CHANNEL_STATE_DISABLE;
4083 }
4084 
4085 enum channel_state
4086 reg_get_ch_state_based_on_nol_flag(struct wlan_objmgr_pdev *pdev,
4087 				   qdf_freq_t freq,
4088 				   struct ch_params *ch_params,
4089 				   enum supported_6g_pwr_types
4090 				   in_6g_pwr_mode,
4091 				   bool treat_nol_chan_as_disabled)
4092 {
4093 	if (treat_nol_chan_as_disabled)
4094 		return wlan_reg_get_5g_bonded_channel_state_for_pwrmode(pdev,
4095 									freq,
4096 									ch_params,
4097 									in_6g_pwr_mode);
4098 
4099 	return reg_get_5g_chan_state(pdev, freq, ch_params->ch_width,
4100 				     in_6g_pwr_mode);
4101 }
4102 
4103 #ifdef WLAN_FEATURE_11BE
4104 bool reg_is_ch_width_320(enum phy_ch_width ch_width)
4105 {
4106 	if (ch_width == CH_WIDTH_320MHZ)
4107 		return true;
4108 	return false;
4109 }
4110 #else
4111 bool reg_is_ch_width_320(enum phy_ch_width ch_width)
4112 {
4113 	return false;
4114 }
4115 #endif
4116 
4117 #ifdef CONFIG_REG_6G_PWRMODE
4118 enum channel_state
4119 reg_get_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev,
4120 				  qdf_freq_t freq,
4121 				  enum supported_6g_pwr_types in_6g_pwr_type)
4122 {
4123 	enum channel_enum ch_idx;
4124 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4125 	enum channel_state state;
4126 
4127 	ch_idx = reg_get_chan_enum_for_freq(freq);
4128 
4129 	if (reg_is_chan_enum_invalid(ch_idx))
4130 		return CHANNEL_STATE_INVALID;
4131 
4132 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4133 
4134 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4135 		reg_err("pdev reg obj is NULL");
4136 		return CHANNEL_STATE_INVALID;
4137 	}
4138 
4139 	state = reg_get_chan_state(pdev, ch_idx, in_6g_pwr_type, true);
4140 	return state;
4141 }
4142 #endif
4143 
4144 static uint32_t reg_get_channel_flags_for_freq(struct wlan_objmgr_pdev *pdev,
4145 					       qdf_freq_t freq)
4146 {
4147 	enum channel_enum chan_enum;
4148 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4149 
4150 	chan_enum = reg_get_chan_enum_for_freq(freq);
4151 
4152 	if (reg_is_chan_enum_invalid(chan_enum)) {
4153 		reg_err("chan freq is not valid");
4154 		return REGULATORY_CHAN_INVALID;
4155 	}
4156 
4157 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4158 
4159 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4160 		reg_err("pdev reg obj is NULL");
4161 		return REGULATORY_CHAN_INVALID;
4162 	}
4163 
4164 	return pdev_priv_obj->cur_chan_list[chan_enum].chan_flags;
4165 }
4166 
4167 #ifdef CONFIG_REG_CLIENT
4168 enum channel_state reg_get_channel_state_from_secondary_list_for_freq(
4169 						struct wlan_objmgr_pdev *pdev,
4170 						qdf_freq_t freq)
4171 {
4172 	enum channel_enum ch_idx;
4173 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4174 
4175 	ch_idx = reg_get_chan_enum_for_freq(freq);
4176 
4177 	if (reg_is_chan_enum_invalid(ch_idx))
4178 		return CHANNEL_STATE_INVALID;
4179 
4180 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4181 
4182 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4183 		reg_err("pdev reg obj is NULL");
4184 		return CHANNEL_STATE_INVALID;
4185 	}
4186 
4187 	return pdev_priv_obj->secondary_cur_chan_list[ch_idx].state;
4188 }
4189 
4190 static uint32_t reg_get_channel_flags_from_secondary_list_for_freq(
4191 						struct wlan_objmgr_pdev *pdev,
4192 						qdf_freq_t freq)
4193 {
4194 	enum channel_enum chan_enum;
4195 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4196 
4197 	chan_enum = reg_get_chan_enum_for_freq(freq);
4198 
4199 	if (reg_is_chan_enum_invalid(chan_enum)) {
4200 		reg_err_rl("chan freq %u is not valid", freq);
4201 		return REGULATORY_CHAN_INVALID;
4202 	}
4203 
4204 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4205 
4206 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4207 		reg_err("pdev reg obj is NULL");
4208 		return REGULATORY_CHAN_INVALID;
4209 	}
4210 
4211 	return pdev_priv_obj->secondary_cur_chan_list[chan_enum].chan_flags;
4212 }
4213 #endif
4214 
4215 /**
4216  * reg_get_5g_bonded_chan_array_for_freq()- Return the channel state for a
4217  * 5G or 6G channel frequency based on the bonded channel.
4218  * @pdev: Pointer to pdev.
4219  * @freq: Channel center frequency.
4220  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
4221  *
4222  * Return: Channel State
4223  */
4224 static enum channel_state
4225 reg_get_5g_bonded_chan_array_for_freq(struct wlan_objmgr_pdev *pdev,
4226 				      uint16_t freq,
4227 				      const struct bonded_channel_freq *
4228 				      bonded_chan_ptr)
4229 {
4230 	uint16_t chan_cfreq;
4231 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
4232 	enum channel_state temp_chan_state;
4233 
4234 	if (!bonded_chan_ptr) {
4235 		reg_debug("bonded chan ptr is NULL");
4236 		return chan_state;
4237 	}
4238 
4239 	chan_cfreq =  bonded_chan_ptr->start_freq;
4240 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
4241 		temp_chan_state = reg_get_channel_state_for_freq(pdev,
4242 								 chan_cfreq);
4243 		if (temp_chan_state < chan_state)
4244 			chan_state = temp_chan_state;
4245 		chan_cfreq = chan_cfreq + 20;
4246 	}
4247 
4248 	return chan_state;
4249 }
4250 
4251 #ifdef CONFIG_REG_6G_PWRMODE
4252 /**
4253  * reg_get_5g_bonded_chan_array_for_pwrmode()- Return the channel state for a
4254  * 5G or 6G channel frequency based on the bonded channel.
4255  * @pdev: Pointer to pdev.
4256  * @freq: Channel center frequency.
4257  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
4258  * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based
4259  * channel list will be chosen.
4260  *
4261  * Return: Channel State
4262  */
4263 static enum channel_state
4264 reg_get_5g_bonded_chan_array_for_pwrmode(struct wlan_objmgr_pdev *pdev,
4265 					 uint16_t freq,
4266 					 const struct bonded_channel_freq *
4267 					 bonded_chan_ptr,
4268 					 enum supported_6g_pwr_types
4269 					 in_6g_pwr_type)
4270 {
4271 	uint16_t chan_cfreq;
4272 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
4273 	enum channel_state temp_chan_state;
4274 
4275 	if (!bonded_chan_ptr) {
4276 		reg_debug("bonded chan ptr is NULL");
4277 		return chan_state;
4278 	}
4279 
4280 	chan_cfreq =  bonded_chan_ptr->start_freq;
4281 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
4282 		temp_chan_state = reg_get_channel_state_for_pwrmode(
4283 								pdev,
4284 								chan_cfreq,
4285 								in_6g_pwr_type);
4286 		if (temp_chan_state < chan_state)
4287 			chan_state = temp_chan_state;
4288 		chan_cfreq = chan_cfreq + 20;
4289 	}
4290 
4291 	return chan_state;
4292 }
4293 #endif
4294 
4295 #ifdef WLAN_FEATURE_11BE
4296 
4297 QDF_STATUS reg_extract_puncture_by_bw(enum phy_ch_width ori_bw,
4298 				      uint16_t ori_puncture_bitmap,
4299 				      qdf_freq_t freq,
4300 				      qdf_freq_t cen320_freq,
4301 				      enum phy_ch_width new_bw,
4302 				      uint16_t *new_puncture_bitmap)
4303 {
4304 	const struct bonded_channel_freq *ori_bonded_chan;
4305 	const struct bonded_channel_freq *new_bonded_chan;
4306 	uint16_t chan_cfreq;
4307 	uint16_t new_bit;
4308 
4309 	if (ori_bw < new_bw) {
4310 		reg_err_rl("freq %d, ori bw %d can't be smaller than new bw %d",
4311 			   freq, ori_bw, new_bw);
4312 		return QDF_STATUS_E_FAILURE;
4313 	}
4314 
4315 	if (ori_bw == new_bw) {
4316 		*new_puncture_bitmap = ori_puncture_bitmap;
4317 		return QDF_STATUS_SUCCESS;
4318 	}
4319 
4320 	ori_bonded_chan = reg_get_bonded_chan_entry(freq, ori_bw, cen320_freq);
4321 	new_bonded_chan = reg_get_bonded_chan_entry(freq, new_bw, 0);
4322 	if (!ori_bonded_chan) {
4323 		reg_err_rl("bonded chan fails, freq %d, ori bw %d, new bw %d",
4324 			   freq, ori_bw, new_bw);
4325 		return QDF_STATUS_E_FAILURE;
4326 	}
4327 
4328 	new_bit = 0;
4329 	*new_puncture_bitmap = 0;
4330 	chan_cfreq =  ori_bonded_chan->start_freq;
4331 	while (chan_cfreq <= ori_bonded_chan->end_freq) {
4332 		/*
4333 		 * If the "new_bw" is 20, then new_bonded_chan = NULL and the
4334 		 * output puncturing bitmap (*new_puncture_bitmap) as per spec
4335 		 * should be 0. However, if the "ori_puncture_bitmap" has
4336 		 * punctured the primary channel (the only channel in 20Mhz
4337 		 * case), then the output "(*ori_puncture_bitmap) should contain
4338 		 * the same so that the caller can recognize the error in the
4339 		 * input pattern.
4340 		 */
4341 		if (freq == chan_cfreq ||
4342 		    (new_bonded_chan &&
4343 		     chan_cfreq >= new_bonded_chan->start_freq &&
4344 		     chan_cfreq <= new_bonded_chan->end_freq)) {
4345 			/* this frequency is in new bw */
4346 			*new_puncture_bitmap |=
4347 					(ori_puncture_bitmap & 1) << new_bit;
4348 			new_bit++;
4349 		}
4350 
4351 		ori_puncture_bitmap >>= 1;
4352 		chan_cfreq = chan_cfreq + BW_20_MHZ;
4353 	}
4354 
4355 	return QDF_STATUS_SUCCESS;
4356 }
4357 
4358 void reg_set_create_punc_bitmap(struct ch_params *ch_params,
4359 				bool is_create_punc_bitmap)
4360 {
4361 	ch_params->is_create_punc_bitmap = is_create_punc_bitmap;
4362 }
4363 
4364 bool reg_is_punc_bitmap_valid(enum phy_ch_width bw, uint16_t puncture_bitmap)
4365 {
4366 	int i, num_bws;
4367 	const uint16_t *bonded_puncture_bitmap = NULL;
4368 	uint16_t array_size = 0;
4369 	bool is_punc_bitmap_valid = false;
4370 
4371 	num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map);
4372 	for (i = 0; i < num_bws; i++) {
4373 		if (bw == bw_puncture_bitmap_pair_map[i].chwidth) {
4374 			bonded_puncture_bitmap =
4375 			    bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr;
4376 			array_size = bw_puncture_bitmap_pair_map[i].array_size;
4377 			break;
4378 		}
4379 	}
4380 
4381 	if (array_size && bonded_puncture_bitmap) {
4382 		for (i = 0; i < array_size; i++) {
4383 			if (puncture_bitmap == bonded_puncture_bitmap[i]) {
4384 				is_punc_bitmap_valid = true;
4385 				break;
4386 			}
4387 		}
4388 	}
4389 
4390 	return is_punc_bitmap_valid;
4391 }
4392 
4393 #ifdef QCA_DFS_BW_PUNCTURE
4394 uint16_t reg_find_nearest_puncture_pattern(enum phy_ch_width bw,
4395 					   uint16_t proposed_bitmap)
4396 {
4397 	int i, num_bws;
4398 	const uint16_t *bonded_puncture_bitmap = NULL;
4399 	uint16_t array_size;
4400 	uint16_t final_bitmap;
4401 
4402 	/* An input pattern = 0 will match any pattern
4403 	 * Therefore, ignore '0' pattern and return '0', as '0' matches '0'.
4404 	 */
4405 	if (!proposed_bitmap)
4406 		return 0;
4407 
4408 	array_size = 0;
4409 	final_bitmap = 0;
4410 
4411 	num_bws = QDF_ARRAY_SIZE(bw_puncture_bitmap_pair_map);
4412 	for (i = 0; i < num_bws; i++) {
4413 		if (bw == bw_puncture_bitmap_pair_map[i].chwidth) {
4414 			bonded_puncture_bitmap =
4415 			    bw_puncture_bitmap_pair_map[i].puncture_bitmap_arr;
4416 			array_size = bw_puncture_bitmap_pair_map[i].array_size;
4417 			break;
4418 		}
4419 	}
4420 
4421 	if (array_size && bonded_puncture_bitmap) {
4422 		for (i = 0; i < array_size; i++) {
4423 			uint16_t valid_bitmap = bonded_puncture_bitmap[i];
4424 
4425 			if ((proposed_bitmap | valid_bitmap) == valid_bitmap) {
4426 				final_bitmap = valid_bitmap;
4427 				break;
4428 			}
4429 		}
4430 	}
4431 
4432 	return final_bitmap;
4433 }
4434 #endif /* QCA_DFS_BW_PUNCTURE */
4435 
4436 /**
4437  * reg_update_5g_bonded_channel_state_punc_for_freq() - update channel state
4438  * with static puncturing feature
4439  * @pdev: pointer to pdev
4440  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
4441  * @ch_params: pointer to ch_params
4442  * @chan_state: chan_state to be updated
4443  *
4444  * Return: void
4445  */
4446 static void reg_update_5g_bonded_channel_state_punc_for_freq(
4447 			struct wlan_objmgr_pdev *pdev,
4448 			const struct bonded_channel_freq *bonded_chan_ptr,
4449 			struct ch_params *ch_params,
4450 			enum channel_state *chan_state)
4451 {
4452 	qdf_freq_t chan_cfreq;
4453 	enum channel_state temp_chan_state;
4454 	uint16_t puncture_bitmap = 0;
4455 	int i = 0;
4456 	enum channel_state update_state = CHANNEL_STATE_ENABLE;
4457 
4458 	if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state ||
4459 	    !ch_params->is_create_punc_bitmap)
4460 		return;
4461 
4462 	chan_cfreq =  bonded_chan_ptr->start_freq;
4463 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
4464 		temp_chan_state =
4465 				reg_get_channel_state_for_freq(pdev,
4466 							       chan_cfreq);
4467 		if (!reg_is_state_allowed(temp_chan_state))
4468 			puncture_bitmap |= BIT(i);
4469 		/* Remember of any of the sub20 channel is a DFS channel */
4470 		if (temp_chan_state == CHANNEL_STATE_DFS)
4471 			update_state = CHANNEL_STATE_DFS;
4472 		chan_cfreq = chan_cfreq + BW_20_MHZ;
4473 		i++;
4474 	}
4475 	/* Validate puncture bitmap. Update channel state. */
4476 	if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) {
4477 		*chan_state = update_state;
4478 		ch_params->reg_punc_bitmap = puncture_bitmap;
4479 	}
4480 }
4481 
4482 #ifdef CONFIG_REG_6G_PWRMODE
4483 /**
4484  * reg_update_5g_bonded_channel_state_punc_for_pwrmode() - update channel state
4485  * with static puncturing feature
4486  * @pdev: pointer to pdev
4487  * @bonded_chan_ptr: Pointer to bonded_channel_freq.
4488  * @ch_params: pointer to ch_params
4489  * @chan_state: chan_state to be updated
4490  *
4491  * Return: void
4492  */
4493 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode(
4494 			struct wlan_objmgr_pdev *pdev,
4495 			const struct bonded_channel_freq *bonded_chan_ptr,
4496 			struct ch_params *ch_params,
4497 			enum channel_state *chan_state,
4498 			enum supported_6g_pwr_types in_6g_pwr_mode)
4499 {
4500 	qdf_freq_t chan_cfreq;
4501 	enum channel_state temp_chan_state;
4502 	uint16_t puncture_bitmap = 0;
4503 	int i = 0;
4504 	enum channel_state update_state = CHANNEL_STATE_ENABLE;
4505 
4506 	if (!pdev || !bonded_chan_ptr || !ch_params || !chan_state ||
4507 	    !ch_params->is_create_punc_bitmap)
4508 		return;
4509 
4510 	chan_cfreq =  bonded_chan_ptr->start_freq;
4511 	while (chan_cfreq <= bonded_chan_ptr->end_freq) {
4512 		temp_chan_state =
4513 			reg_get_channel_state_for_pwrmode(pdev, chan_cfreq,
4514 							  in_6g_pwr_mode);
4515 		if (!reg_is_state_allowed(temp_chan_state))
4516 			puncture_bitmap |= BIT(i);
4517 		/* Remember of any of the sub20 channel is a DFS channel */
4518 		if (temp_chan_state == CHANNEL_STATE_DFS)
4519 			update_state = CHANNEL_STATE_DFS;
4520 		chan_cfreq = chan_cfreq + BW_20_MHZ;
4521 		i++;
4522 	}
4523 	/* Validate puncture bitmap. Update channel state. */
4524 	if (reg_is_punc_bitmap_valid(ch_params->ch_width, puncture_bitmap)) {
4525 		*chan_state = update_state;
4526 		ch_params->reg_punc_bitmap = puncture_bitmap;
4527 	}
4528 }
4529 #endif
4530 #else
4531 static void reg_update_5g_bonded_channel_state_punc_for_freq(
4532 			struct wlan_objmgr_pdev *pdev,
4533 			const struct bonded_channel_freq *bonded_chan_ptr,
4534 			struct ch_params *ch_params,
4535 			enum channel_state *chan_state)
4536 {
4537 }
4538 
4539 static void reg_update_5g_bonded_channel_state_punc_for_pwrmode(
4540 			struct wlan_objmgr_pdev *pdev,
4541 			const struct bonded_channel_freq *bonded_chan_ptr,
4542 			struct ch_params *ch_params,
4543 			enum channel_state *chan_state,
4544 			enum supported_6g_pwr_types in_6g_pwr_mode)
4545 {
4546 }
4547 #endif
4548 
4549 enum channel_state
4550 reg_get_5g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
4551 					 qdf_freq_t freq,
4552 					 struct ch_params *ch_params)
4553 {
4554 	enum phy_ch_width bw;
4555 	enum channel_enum ch_indx;
4556 	enum channel_state chan_state;
4557 	struct regulatory_channel *reg_channels;
4558 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4559 	bool bw_enabled = false;
4560 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
4561 
4562 	if (!ch_params) {
4563 		reg_err_rl("Invalid ch_params");
4564 		return CHANNEL_STATE_INVALID;
4565 	}
4566 	bw = ch_params->ch_width;
4567 	if (bw > CH_WIDTH_80P80MHZ) {
4568 		reg_err_rl("bw (%d) passed is not good", bw);
4569 		return CHANNEL_STATE_INVALID;
4570 	}
4571 
4572 	chan_state = reg_get_5g_bonded_channel_for_freq(pdev, freq, bw,
4573 							&bonded_chan_ptr);
4574 
4575 	reg_update_5g_bonded_channel_state_punc_for_freq(pdev,
4576 							 bonded_chan_ptr,
4577 							 ch_params,
4578 							 &chan_state);
4579 
4580 	if ((chan_state == CHANNEL_STATE_INVALID) ||
4581 	    (chan_state == CHANNEL_STATE_DISABLE))
4582 		return chan_state;
4583 
4584 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4585 
4586 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4587 		reg_err("pdev reg obj is NULL");
4588 		return CHANNEL_STATE_INVALID;
4589 	}
4590 	reg_channels = pdev_priv_obj->cur_chan_list;
4591 
4592 	ch_indx = reg_get_chan_enum_for_freq(freq);
4593 	if (reg_is_chan_enum_invalid(ch_indx))
4594 		return CHANNEL_STATE_INVALID;
4595 	if (bw == CH_WIDTH_5MHZ)
4596 		bw_enabled = true;
4597 	else if (bw == CH_WIDTH_10MHZ)
4598 		bw_enabled = (reg_channels[ch_indx].min_bw <= 10) &&
4599 			(reg_channels[ch_indx].max_bw >= 10);
4600 	else if (bw == CH_WIDTH_20MHZ)
4601 		bw_enabled = (reg_channels[ch_indx].min_bw <= 20) &&
4602 			(reg_channels[ch_indx].max_bw >= 20);
4603 	else if (bw == CH_WIDTH_40MHZ)
4604 		bw_enabled = (reg_channels[ch_indx].min_bw <= 40) &&
4605 			(reg_channels[ch_indx].max_bw >= 40);
4606 	else if (bw == CH_WIDTH_80MHZ)
4607 		bw_enabled = (reg_channels[ch_indx].min_bw <= 80) &&
4608 			(reg_channels[ch_indx].max_bw >= 80);
4609 	else if (bw == CH_WIDTH_160MHZ)
4610 		bw_enabled = (reg_channels[ch_indx].min_bw <= 160) &&
4611 			(reg_channels[ch_indx].max_bw >= 160);
4612 	else if (bw == CH_WIDTH_80P80MHZ)
4613 		bw_enabled = (reg_channels[ch_indx].min_bw <= 80) &&
4614 			(reg_channels[ch_indx].max_bw >= 80);
4615 
4616 	if (bw_enabled)
4617 		return chan_state;
4618 	return CHANNEL_STATE_DISABLE;
4619 }
4620 
4621 #ifdef CONFIG_REG_6G_PWRMODE
4622 enum channel_state
4623 reg_get_5g_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev,
4624 					    qdf_freq_t freq,
4625 					    struct ch_params *ch_params,
4626 					    enum supported_6g_pwr_types
4627 					    in_6g_pwr_mode)
4628 {
4629 	enum phy_ch_width bw;
4630 	enum channel_enum ch_indx;
4631 	enum channel_state chan_state;
4632 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4633 	bool bw_enabled = false;
4634 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
4635 	uint16_t min_bw, max_bw;
4636 
4637 	if (!ch_params) {
4638 		reg_err_rl("Invalid ch_params");
4639 		return CHANNEL_STATE_INVALID;
4640 	}
4641 	bw = ch_params->ch_width;
4642 	if (bw > CH_WIDTH_80P80MHZ) {
4643 		reg_err_rl("bw (%d) passed is not good", bw);
4644 		return CHANNEL_STATE_INVALID;
4645 	}
4646 
4647 	chan_state = reg_get_5g_bonded_channel_for_pwrmode(pdev, freq, bw,
4648 							   &bonded_chan_ptr,
4649 							   in_6g_pwr_mode);
4650 
4651 	reg_update_5g_bonded_channel_state_punc_for_pwrmode(
4652 						pdev, bonded_chan_ptr,
4653 						ch_params, &chan_state,
4654 						in_6g_pwr_mode);
4655 
4656 	if ((chan_state == CHANNEL_STATE_INVALID) ||
4657 	    (chan_state == CHANNEL_STATE_DISABLE))
4658 		return chan_state;
4659 
4660 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4661 
4662 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4663 		reg_err("pdev reg obj is NULL");
4664 		return CHANNEL_STATE_INVALID;
4665 	}
4666 
4667 	ch_indx = reg_get_chan_enum_for_freq(freq);
4668 	if (reg_is_chan_enum_invalid(ch_indx))
4669 		return CHANNEL_STATE_INVALID;
4670 
4671 	if (reg_get_min_max_bw_reg_chan_list(pdev, ch_indx, in_6g_pwr_mode,
4672 					     &min_bw, &max_bw))
4673 		return CHANNEL_STATE_INVALID;
4674 
4675 	if (bw == CH_WIDTH_5MHZ)
4676 		bw_enabled = true;
4677 	else if (bw == CH_WIDTH_10MHZ)
4678 		bw_enabled = (min_bw <= 10) &&
4679 			(max_bw >= 10);
4680 	else if (bw == CH_WIDTH_20MHZ)
4681 		bw_enabled = (min_bw <= 20) &&
4682 			(max_bw >= 20);
4683 	else if (bw == CH_WIDTH_40MHZ)
4684 		bw_enabled = (min_bw <= 40) &&
4685 			(max_bw >= 40);
4686 	else if (bw == CH_WIDTH_80MHZ)
4687 		bw_enabled = (min_bw <= 80) &&
4688 			(max_bw >= 80);
4689 	else if (bw == CH_WIDTH_160MHZ)
4690 		bw_enabled = (min_bw <= 160) &&
4691 			(max_bw >= 160);
4692 	else if (bw == CH_WIDTH_80P80MHZ)
4693 		bw_enabled = (min_bw <= 80) &&
4694 			(max_bw >= 80);
4695 
4696 	if (bw_enabled)
4697 		return chan_state;
4698 	return CHANNEL_STATE_DISABLE;
4699 }
4700 #endif
4701 
4702 enum channel_state
4703 reg_get_2g_bonded_channel_state_for_freq(struct wlan_objmgr_pdev *pdev,
4704 					 qdf_freq_t oper_ch_freq,
4705 					 qdf_freq_t sec_ch_freq,
4706 					 enum phy_ch_width bw)
4707 {
4708 	enum channel_enum chan_idx;
4709 	enum channel_state chan_state;
4710 	struct regulatory_channel *reg_channels;
4711 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
4712 	bool bw_enabled = false;
4713 	enum channel_state chan_state2 = CHANNEL_STATE_INVALID;
4714 
4715 	if (bw > CH_WIDTH_40MHZ)
4716 		return CHANNEL_STATE_INVALID;
4717 
4718 	if (bw == CH_WIDTH_40MHZ) {
4719 		if ((sec_ch_freq + 20 != oper_ch_freq) &&
4720 		    (oper_ch_freq + 20 != sec_ch_freq))
4721 			return CHANNEL_STATE_INVALID;
4722 		chan_state2 =
4723 		    reg_get_channel_state_for_pwrmode(pdev,
4724 						      sec_ch_freq,
4725 						      REG_CURRENT_PWR_MODE);
4726 		if (chan_state2 == CHANNEL_STATE_INVALID)
4727 			return chan_state2;
4728 	}
4729 	pdev_priv_obj = reg_get_pdev_obj(pdev);
4730 
4731 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
4732 		reg_err("reg pdev priv obj is NULL");
4733 		return CHANNEL_STATE_INVALID;
4734 	}
4735 
4736 	reg_channels = pdev_priv_obj->cur_chan_list;
4737 
4738 	chan_state = reg_get_channel_state_for_pwrmode(pdev,
4739 						       oper_ch_freq,
4740 						       REG_CURRENT_PWR_MODE);
4741 	if (chan_state2 < chan_state)
4742 		chan_state = chan_state2;
4743 
4744 	if ((chan_state == CHANNEL_STATE_INVALID) ||
4745 	    (chan_state == CHANNEL_STATE_DISABLE))
4746 		return chan_state;
4747 
4748 	chan_idx = reg_get_chan_enum_for_freq(oper_ch_freq);
4749 	if (reg_is_chan_enum_invalid(chan_idx))
4750 		return CHANNEL_STATE_INVALID;
4751 	if (bw == CH_WIDTH_5MHZ)
4752 		bw_enabled = true;
4753 	else if (bw == CH_WIDTH_10MHZ)
4754 		bw_enabled = (reg_channels[chan_idx].min_bw <= 10) &&
4755 			(reg_channels[chan_idx].max_bw >= 10);
4756 	else if (bw == CH_WIDTH_20MHZ)
4757 		bw_enabled = (reg_channels[chan_idx].min_bw <= 20) &&
4758 			(reg_channels[chan_idx].max_bw >= 20);
4759 	else if (bw == CH_WIDTH_40MHZ)
4760 		bw_enabled = (reg_channels[chan_idx].min_bw <= 40) &&
4761 			(reg_channels[chan_idx].max_bw >= 40);
4762 
4763 	if (bw_enabled)
4764 		return chan_state;
4765 	else
4766 		return CHANNEL_STATE_DISABLE;
4767 
4768 	return CHANNEL_STATE_ENABLE;
4769 }
4770 
4771 #ifdef WLAN_FEATURE_11BE
4772 
4773 /**
4774  * reg_get_20mhz_channel_state_based_on_nol() - Get channel state of the
4775  * given 20MHZ channel. If the freq is in NOL/NOL history, it is considered
4776  * as enabled if "treat_nol_chan_as_disabled" is false, else the state is
4777  * considered as "disabled".
4778  * @pdev: Pointer to struct wlan_objmgr_pdev
4779  * @freq: Primary frequency
4780  * @treat_nol_chan_as_disabled: Flag to treat nol chan as enabled/disabled
4781  * @in_6g_pwr_type: Input 6g power type
4782  *
4783  * Return - Channel state
4784  */
4785 static enum channel_state
4786 reg_get_20mhz_channel_state_based_on_nol(struct wlan_objmgr_pdev *pdev,
4787 					 qdf_freq_t freq,
4788 					 bool treat_nol_chan_as_disabled,
4789 					 enum supported_6g_pwr_types in_6g_pwr_type)
4790 {
4791 	if (treat_nol_chan_as_disabled)
4792 		return  reg_get_channel_state_for_pwrmode(pdev, freq,
4793 							  in_6g_pwr_type);
4794 	return reg_get_nol_channel_state(pdev, freq,
4795 					 in_6g_pwr_type);
4796 }
4797 
4798 /**
4799  * reg_get_320_bonded_chan_array() - Fetches a list of bonded channel pointers
4800  * for the given bonded channel array. If 320 band center is specified,
4801  * return the bonded channel pointer comprising of given band center else
4802  * return list of all available bonded channel pair.
4803  *
4804  * @pdev: Pointer to struct wlan_objmgr_pdev.
4805  * @freq: Input frequency in MHZ whose bonded channel pointer must be fetched.
4806  * @band_center_320: Channel center frequency of 320MHZ channel.
4807  * @bonded_chan_ar: Array of bonded channel list.
4808  * @array_size: Size of bonded channel array.
4809  * @bonded_chan_ptr: Pointer to hold the address of bonded_channel_freq index.
4810  *
4811  * Return: number of bonded channel arrays fetched.
4812  */
4813 
4814 #define MAX_NUM_BONDED_PAIR 2
4815 static uint8_t
4816 reg_get_320_bonded_chan_array(struct wlan_objmgr_pdev *pdev,
4817 			      qdf_freq_t freq,
4818 			      qdf_freq_t band_center_320,
4819 			      const struct bonded_channel_freq bonded_chan_ar[],
4820 			      uint16_t array_size,
4821 			      const struct bonded_channel_freq
4822 			      *bonded_chan_ptr[])
4823 {
4824 	int i;
4825 	uint8_t num_bonded_pairs = 0;
4826 
4827 	/* Fetch all possible bonded channel pointers for the given freq */
4828 	if (!band_center_320) {
4829 		for (i = 0 ; i < array_size &&
4830 		     num_bonded_pairs < MAX_NUM_BONDED_PAIR; i++) {
4831 			if ((freq >= bonded_chan_ar[i].start_freq) &&
4832 			    (freq <= bonded_chan_ar[i].end_freq)) {
4833 				bonded_chan_ptr[num_bonded_pairs] =
4834 					&bonded_chan_ar[i];
4835 				num_bonded_pairs++;
4836 			}
4837 		}
4838 	} else {
4839 		/* Fetch the bonded channel pointer for the given band_center */
4840 		for (i = 0; i < array_size; i++) {
4841 			qdf_freq_t bandstart = bonded_chan_ar[i].start_freq;
4842 
4843 			if (band_center_320 ==
4844 			    reg_get_band_cen_from_bandstart(BW_320_MHZ,
4845 							    bandstart)) {
4846 				bonded_chan_ptr[num_bonded_pairs] =
4847 					&bonded_chan_ar[i];
4848 				num_bonded_pairs++;
4849 				break;
4850 			}
4851 		}
4852 	}
4853 	return num_bonded_pairs;
4854 }
4855 
4856 #define SUB_CHAN_BW 20 /* 20 MHZ */
4857 #define BW_160MHZ 160
4858 #define  REG_IS_TOT_CHAN_BW_BELOW_160(_x, _y) \
4859 	(reg_is_state_allowed((_x)) && (_y) < BW_160MHZ)
4860 
4861 static inline qdf_freq_t
4862 reg_get_endchan_cen_from_bandstart(qdf_freq_t band_start,
4863 				   uint16_t bw)
4864 {
4865 	uint16_t left_edge_freq = band_start - BW_10_MHZ;
4866 
4867 	return left_edge_freq + bw - BW_10_MHZ;
4868 }
4869 
4870 /**
4871  * reg_get_320_bonded_channel_state() - Given a bonded channel
4872  * pointer and freq, determine if the subchannels of the bonded pair
4873  * are valid and supported by the current regulatory.
4874  *
4875  * @pdev: Pointer to struct wlan_objmgr_pdev.
4876  * @freq: Frequency in MHZ.
4877  * @bonded_chan_ptr: Pointer to const struct bonded_channel_freq.
4878  * @bw: channel bandwidth
4879  * @out_punc_bitmap: Output puncturing bitmap
4880  * @treat_nol_chan_as_disabled: Bool to treat nol as disabled/enabled
4881  *
4882  * Return - The channel state of the bonded pair.
4883  */
4884 static enum channel_state
4885 reg_get_320_bonded_channel_state(struct wlan_objmgr_pdev *pdev,
4886 				 qdf_freq_t freq,
4887 				 const struct bonded_channel_freq
4888 				 *bonded_chan_ptr,
4889 				 enum phy_ch_width bw,
4890 				 uint16_t *out_punc_bitmap,
4891 				 bool treat_nol_chan_as_disabled)
4892 {
4893 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
4894 	enum channel_state temp_chan_state, prim_chan_state;
4895 	uint16_t startchan_cfreq, endchan_cfreq;
4896 	uint16_t max_cont_bw, i;
4897 
4898 	*out_punc_bitmap = ALL_SCHANS_PUNC;
4899 
4900 	if (!bonded_chan_ptr)
4901 		return chan_state;
4902 
4903 	startchan_cfreq =  bonded_chan_ptr->start_freq;
4904 	endchan_cfreq =
4905 		reg_get_endchan_cen_from_bandstart(startchan_cfreq,
4906 						   BW_320_MHZ);
4907 	max_cont_bw = 0;
4908 	i = 0;
4909 
4910 	while (startchan_cfreq <= endchan_cfreq) {
4911 		temp_chan_state =
4912 		    reg_get_20mhz_channel_state_based_on_nol(pdev,
4913 							     startchan_cfreq,
4914 							     treat_nol_chan_as_disabled,
4915 							     REG_CURRENT_PWR_MODE);
4916 
4917 		if (reg_is_state_allowed(temp_chan_state)) {
4918 			max_cont_bw += SUB_CHAN_BW;
4919 			*out_punc_bitmap &= ~BIT(i);
4920 		}
4921 
4922 		if (temp_chan_state < chan_state)
4923 			chan_state = temp_chan_state;
4924 
4925 		startchan_cfreq = startchan_cfreq + SUB_CHAN_BW;
4926 		i++;
4927 	}
4928 
4929 	prim_chan_state =
4930 		reg_get_20mhz_channel_state_based_on_nol(pdev,
4931 							 freq,
4932 							 treat_nol_chan_as_disabled,
4933 							 REG_CURRENT_PWR_MODE);
4934 
4935 	/* After iterating through all the subchannels, if the final channel
4936 	 * state is invalid/disable, it means all our subchannels are not
4937 	 * valid and we could not find a 320 MHZ channel.
4938 	 * If we have found a channel where the max width is:
4939 	 * 1. Less than 160: there is no puncturing needed. Hence return
4940 	 * the chan state as invalid. Or if the primary freq given is not
4941 	 * supported by regulatory, the channel cannot be enabled as a
4942 	 * punctured channel. So return channel state as invalid.
4943 	 * 2. If greater than 160: Mark the invalid channels as punctured.
4944 	 * and return channel state as ENABLE.
4945 	 */
4946 	if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) ||
4947 		!reg_is_state_allowed(prim_chan_state))
4948 		return CHANNEL_STATE_INVALID;
4949 
4950 	return chan_state;
4951 }
4952 #endif
4953 
4954 #ifdef WLAN_FEATURE_11BE
4955 enum channel_state
4956 reg_get_chan_state_for_320(struct wlan_objmgr_pdev *pdev,
4957 			   uint16_t freq,
4958 			   qdf_freq_t band_center_320,
4959 			   enum phy_ch_width ch_width,
4960 			   const struct bonded_channel_freq
4961 			   **bonded_chan_ptr_ptr,
4962 			   enum supported_6g_pwr_types in_6g_pwr_type,
4963 			   bool treat_nol_chan_as_disabled)
4964 {
4965 	uint8_t num_bonded_pairs;
4966 	uint16_t array_size =
4967 		QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq);
4968 	const struct bonded_channel_freq *bonded_ch_ptr[2] = {
4969 		NULL, NULL};
4970 	uint16_t punct_pattern;
4971 
4972 	/* For now sending band center freq as 0 */
4973 	num_bonded_pairs =
4974 		reg_get_320_bonded_chan_array(pdev, freq, band_center_320,
4975 					      bonded_chan_320mhz_list_freq,
4976 					      array_size, bonded_ch_ptr);
4977 	if (!num_bonded_pairs) {
4978 		reg_info("No 320MHz bonded pair for freq %d", freq);
4979 		return CHANNEL_STATE_INVALID;
4980 	}
4981 	/* Taking only first bonded pair */
4982 	*bonded_chan_ptr_ptr = bonded_ch_ptr[0];
4983 
4984 	return reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq,
4985 							     bonded_ch_ptr[0],
4986 							     ch_width,
4987 							     &punct_pattern,
4988 							     in_6g_pwr_type,
4989 							     treat_nol_chan_as_disabled);
4990 }
4991 #endif
4992 
4993 #ifdef WLAN_FEATURE_11BE
4994 enum channel_state
4995 reg_get_320_bonded_channel_state_for_pwrmode(struct wlan_objmgr_pdev *pdev,
4996 					     qdf_freq_t freq,
4997 					     const struct bonded_channel_freq
4998 					     *bonded_chan_ptr,
4999 					     enum phy_ch_width bw,
5000 					     uint16_t *out_punc_bitmap,
5001 					     enum supported_6g_pwr_types
5002 					     in_6g_pwr_type,
5003 					     bool treat_nol_chan_as_disabled)
5004 {
5005 	enum channel_state chan_state = CHANNEL_STATE_INVALID;
5006 	enum channel_state temp_chan_state, prim_chan_state;
5007 	uint16_t startchan_cfreq, endchan_cfreq;
5008 	uint16_t max_cont_bw, i;
5009 
5010 	*out_punc_bitmap = ALL_SCHANS_PUNC;
5011 
5012 	if (!bonded_chan_ptr)
5013 		return chan_state;
5014 
5015 	startchan_cfreq =  bonded_chan_ptr->start_freq;
5016 	endchan_cfreq =
5017 		reg_get_endchan_cen_from_bandstart(startchan_cfreq,
5018 						   BW_320_MHZ);
5019 	max_cont_bw = 0;
5020 	i = 0;
5021 
5022 	while (startchan_cfreq <= endchan_cfreq) {
5023 		temp_chan_state =
5024 			reg_get_20mhz_channel_state_based_on_nol(pdev,
5025 								 startchan_cfreq,
5026 								 treat_nol_chan_as_disabled,
5027 								 in_6g_pwr_type);
5028 
5029 		if (reg_is_state_allowed(temp_chan_state)) {
5030 			max_cont_bw += SUB_CHAN_BW;
5031 			*out_punc_bitmap &= ~BIT(i);
5032 		}
5033 
5034 		if (temp_chan_state < chan_state)
5035 			chan_state = temp_chan_state;
5036 
5037 		startchan_cfreq = startchan_cfreq + SUB_CHAN_BW;
5038 		i++;
5039 	}
5040 
5041 	prim_chan_state =
5042 		reg_get_20mhz_channel_state_based_on_nol(pdev, freq,
5043 							 treat_nol_chan_as_disabled,
5044 							 in_6g_pwr_type);
5045 
5046 	/* After iterating through all the subchannels, if the final channel
5047 	 * state is invalid/disable, it means all our subchannels are not
5048 	 * valid and we could not find a 320 MHZ channel.
5049 	 * If we have found a channel where the max width is:
5050 	 * 1. Less than 160: there is no puncturing needed. Hence return
5051 	 * the chan state as invalid. Or if the primary freq given is not
5052 	 * supported by regulatory, the channel cannot be enabled as a
5053 	 * punctured channel. So return channel state as invalid.
5054 	 * 2. If greater than 160: Mark the invalid channels as punctured.
5055 	 * and return channel state as ENABLE.
5056 	 */
5057 	if (REG_IS_TOT_CHAN_BW_BELOW_160(chan_state, max_cont_bw) ||
5058 		!reg_is_state_allowed(prim_chan_state))
5059 		return CHANNEL_STATE_INVALID;
5060 
5061 	return chan_state;
5062 }
5063 
5064 static inline bool reg_is_pri_within_240mhz_chan(qdf_freq_t freq)
5065 {
5066 	return (freq >= CHAN_FREQ_5660 && freq <= CHAN_FREQ_5720);
5067 }
5068 
5069 /**
5070  * reg_fill_chan320mhz_seg0_center() - Fill the primary segment center
5071  * for a 320MHz channel in the given channel param. Primary segment center
5072  * of a 320MHZ is the 160MHZ segment center of the given freq.
5073  * @pdev: Pointer to struct wlan_objmgr_pdev.
5074  * @ch_param: channel params to be filled.
5075  * @freq: Input primary frequency in MHZ.
5076  *
5077  * Return: void.
5078  */
5079 static void
5080 reg_fill_chan320mhz_seg0_center(struct wlan_objmgr_pdev *pdev,
5081 				struct ch_params *ch_param, qdf_freq_t freq)
5082 {
5083 	const struct bonded_channel_freq *t_bonded_ch_ptr;
5084 
5085 	t_bonded_ch_ptr = reg_get_bonded_chan_entry(freq, CH_WIDTH_160MHZ, 0);
5086 	if (t_bonded_ch_ptr) {
5087 		ch_param->mhz_freq_seg0 =
5088 			(t_bonded_ch_ptr->start_freq +
5089 			 t_bonded_ch_ptr->end_freq) / 2;
5090 		ch_param->center_freq_seg0 =
5091 			reg_freq_to_chan(pdev,
5092 					 ch_param->mhz_freq_seg0);
5093 	} else {
5094 		/**
5095 		 * If we do not find a 160Mhz  bonded  pair, since it is
5096 		 * for a 320Mhz channel we need to also see if we can find a
5097 		 * pseudo 160Mhz channel for the special case of
5098 		 * 5Ghz 240Mhz channel.
5099 		 */
5100 		if (reg_is_pri_within_240mhz_chan(freq)) {
5101 			ch_param->mhz_freq_seg0 =
5102 				PRIM_SEG_FREQ_CENTER_240MHZ_5G_CHAN;
5103 			ch_param->center_freq_seg0 =
5104 				PRIM_SEG_IEEE_CENTER_240MHZ_5G_CHAN;
5105 		} else {
5106 			ch_param->ch_width = CH_WIDTH_INVALID;
5107 			reg_err("Cannot find 160Mhz centers for freq %d", freq);
5108 		}
5109 	}
5110 }
5111 
5112 /**
5113  * reg_fill_channel_list_for_320() - Fill 320MHZ channel list. If we
5114  * are unable to find a channel whose width is greater than 160MHZ and less
5115  * than 320 with the help of puncturing, using the given freq, set "update_bw"
5116  * variable to be true, lower the channel width and return to the caller.
5117  * The caller fetches a channel of reduced mode based on "update_bw" flag.
5118  *
5119  * If 320 band center is 0, return all the 320 channels
5120  * that match the primary frequency else return only channel
5121  * that matches 320 band center.
5122  *
5123  * @pdev: Pointer to struct wlan_objmgr_pdev.
5124  * @freq: Input frequency in MHZ.
5125  * @ch_width: Input channel width, if a channel of the given width is not
5126  * found, reduce the channel width to the next lower mode and pass it to the
5127  * caller.
5128  * @band_center_320: Center of 320MHZ channel.
5129  * @chan_list: Pointer to reg_channel_list to be filled.
5130  * @update_bw: Flag to hold if bw is updated.
5131  * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled
5132  *
5133  * Return - None.
5134  */
5135 static void
5136 reg_fill_channel_list_for_320(struct wlan_objmgr_pdev *pdev,
5137 			      qdf_freq_t freq,
5138 			      enum phy_ch_width *in_ch_width,
5139 			      qdf_freq_t band_center_320,
5140 			      struct reg_channel_list *chan_list,
5141 			      bool *update_bw,
5142 			      bool treat_nol_chan_as_disabled)
5143 {
5144 	uint8_t num_bonded_pairs, i, num_ch_params;
5145 	enum channel_state chan_state;
5146 	uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq);
5147 	uint16_t out_punc_bitmap;
5148 	uint16_t max_reg_bw;
5149 	enum channel_enum chan_enum;
5150 	const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL};
5151 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5152 
5153 	*update_bw = false;
5154 
5155 	chan_enum = reg_get_chan_enum_for_freq(freq);
5156 	if (reg_is_chan_enum_invalid(chan_enum)) {
5157 		reg_err("chan freq is not valid");
5158 		return;
5159 	}
5160 
5161 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5162 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5163 		reg_err("reg pdev priv obj is NULL");
5164 		return;
5165 	}
5166 
5167 	/* Maximum bandwidth of the channel supported by regulatory for
5168 	 * the given freq.
5169 	 */
5170 	max_reg_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw;
5171 
5172 	/* Regulatory does not support BW greater than 160.
5173 	 * Try finding a channel in a lower mode.
5174 	 */
5175 	if (max_reg_bw <= BW_160MHZ) {
5176 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5177 		*update_bw = true;
5178 		return;
5179 	}
5180 
5181 	num_bonded_pairs =
5182 		reg_get_320_bonded_chan_array(pdev, freq, band_center_320,
5183 					      bonded_chan_320mhz_list_freq,
5184 					      array_size,
5185 					      bonded_ch_ptr);
5186 
5187 	if (!num_bonded_pairs) {
5188 		if (band_center_320) {
5189 			reg_debug("No bonded pair for the given band_center\n");
5190 			chan_list->num_ch_params = 0;
5191 		} else {
5192 			/* Could not find a 320 MHZ bonded channel pair,
5193 			 * find a channel of lower BW.
5194 			 */
5195 			*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5196 			*update_bw = true;
5197 		}
5198 		return;
5199 	}
5200 
5201 	for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) {
5202 		/* Chan_state to hold the channel state of bonding
5203 		 * pair of channels.
5204 		 */
5205 		chan_state =
5206 		    reg_get_320_bonded_channel_state(pdev, freq,
5207 						     bonded_ch_ptr[i],
5208 						     *in_ch_width,
5209 						     &out_punc_bitmap,
5210 						     treat_nol_chan_as_disabled);
5211 
5212 		if (reg_is_state_allowed(chan_state)) {
5213 			struct ch_params *t_chan_param =
5214 			    &chan_list->chan_param[num_ch_params];
5215 
5216 			t_chan_param->mhz_freq_seg1 =
5217 				(bonded_ch_ptr[i]->start_freq +
5218 				 bonded_ch_ptr[i]->end_freq) / 2;
5219 			t_chan_param->center_freq_seg1 =
5220 				reg_freq_to_chan(pdev,
5221 						 t_chan_param->mhz_freq_seg1);
5222 			t_chan_param->ch_width = *in_ch_width;
5223 			t_chan_param->reg_punc_bitmap = out_punc_bitmap;
5224 
5225 			reg_fill_chan320mhz_seg0_center(pdev,
5226 							t_chan_param,
5227 							freq);
5228 			num_ch_params++;
5229 			chan_list->num_ch_params = num_ch_params;
5230 		}
5231 	}
5232 
5233 	/* The bonded pairs could not create any channels,
5234 	 * lower the bandwidth to find a channel.
5235 	 */
5236 	if (!chan_list->num_ch_params) {
5237 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5238 		*update_bw = true;
5239 	}
5240 }
5241 
5242 #ifdef CONFIG_REG_6G_PWRMODE
5243 /**
5244  * reg_fill_channel_list_for_320_for_pwrmode() - Fill 320MHZ channel list. If we
5245  * are unable to find a channel whose width is greater than 160MHZ and less
5246  * than 320 with the help of puncturing, using the given freq, set "update_bw"
5247  * variable to be true, lower the channel width and return to the caller.
5248  * The caller fetches a channel of reduced mode based on "update_bw" flag.
5249  *
5250  * If 320 band center is 0, return all the 320 channels
5251  * that match the primary frequency else return only channel
5252  * that matches 320 band center.
5253  *
5254  * @pdev: Pointer to struct wlan_objmgr_pdev.
5255  * @freq: Input frequency in MHZ.
5256  * @ch_width: Input channel width, if a channel of the given width is not
5257  * found, reduce the channel width to the next lower mode and pass it to the
5258  * caller.
5259  * @band_center_320: Center of 320MHZ channel.
5260  * @chan_list: Pointer to reg_channel_list to be filled.
5261  * @update_bw: Flag to hold if bw is updated.
5262  * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based
5263  * channel list will be chosen.
5264  * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled
5265  *
5266  * Return - None.
5267  */
5268 static void
5269 reg_fill_channel_list_for_320_for_pwrmode(
5270 			      struct wlan_objmgr_pdev *pdev,
5271 			      qdf_freq_t freq,
5272 			      enum phy_ch_width *in_ch_width,
5273 			      qdf_freq_t band_center_320,
5274 			      struct reg_channel_list *chan_list,
5275 			      bool *update_bw,
5276 			      enum supported_6g_pwr_types in_6g_pwr_mode,
5277 			      bool treat_nol_chan_as_disabled)
5278 {
5279 	uint8_t num_bonded_pairs, i, num_ch_params;
5280 	enum channel_state chan_state;
5281 	uint16_t array_size = QDF_ARRAY_SIZE(bonded_chan_320mhz_list_freq);
5282 	uint16_t out_punc_bitmap;
5283 	uint16_t max_reg_bw;
5284 	enum channel_enum chan_enum;
5285 	const struct bonded_channel_freq *bonded_ch_ptr[2] = {NULL, NULL};
5286 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5287 
5288 	*update_bw = false;
5289 
5290 	chan_enum = reg_get_chan_enum_for_freq(freq);
5291 	if (reg_is_chan_enum_invalid(chan_enum)) {
5292 		reg_err("chan freq is not valid");
5293 		return;
5294 	}
5295 
5296 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5297 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5298 		reg_err("reg pdev priv obj is NULL");
5299 		return;
5300 	}
5301 
5302 	/* Maximum bandwidth of the channel supported by regulatory for
5303 	 * the given freq.
5304 	 */
5305 	if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_mode,
5306 					     NULL, &max_reg_bw))
5307 		return;
5308 
5309 	/* Regulatory does not support BW greater than 160.
5310 	 * Try finding a channel in a lower mode.
5311 	 */
5312 	if (max_reg_bw <= BW_160MHZ) {
5313 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5314 		*update_bw = true;
5315 		return;
5316 	}
5317 
5318 	num_bonded_pairs =
5319 		reg_get_320_bonded_chan_array(pdev, freq, band_center_320,
5320 					      bonded_chan_320mhz_list_freq,
5321 					      array_size,
5322 					      bonded_ch_ptr);
5323 
5324 	if (!num_bonded_pairs) {
5325 		if (band_center_320) {
5326 			reg_debug("No bonded pair for the given band_center\n");
5327 			chan_list->num_ch_params = 0;
5328 		} else {
5329 			/* Could not find a 320 MHZ bonded channel pair,
5330 			 * find a channel of lower BW.
5331 			 */
5332 			*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5333 			*update_bw = true;
5334 		}
5335 		return;
5336 	}
5337 
5338 	for (i = 0, num_ch_params = 0 ; i < num_bonded_pairs; i++) {
5339 		/* Chan_state to hold the channel state of bonding
5340 		 * pair of channels.
5341 		 */
5342 		chan_state =
5343 			reg_get_320_bonded_channel_state_for_pwrmode(pdev, freq,
5344 								     bonded_ch_ptr[i],
5345 								     *in_ch_width,
5346 								     &out_punc_bitmap,
5347 								     in_6g_pwr_mode,
5348 								     treat_nol_chan_as_disabled);
5349 
5350 		if (reg_is_state_allowed(chan_state)) {
5351 			struct ch_params *t_chan_param =
5352 			    &chan_list->chan_param[num_ch_params];
5353 			qdf_freq_t start_freq = bonded_ch_ptr[i]->start_freq;
5354 
5355 			t_chan_param->mhz_freq_seg1 =
5356 				reg_get_band_cen_from_bandstart(BW_320_MHZ,
5357 								start_freq);
5358 			t_chan_param->center_freq_seg1 =
5359 				reg_freq_to_chan(pdev,
5360 						 t_chan_param->mhz_freq_seg1);
5361 			t_chan_param->ch_width = *in_ch_width;
5362 			t_chan_param->reg_punc_bitmap = out_punc_bitmap;
5363 
5364 			reg_fill_chan320mhz_seg0_center(pdev,
5365 							t_chan_param,
5366 							freq);
5367 			num_ch_params++;
5368 			chan_list->num_ch_params = num_ch_params;
5369 		}
5370 	}
5371 
5372 	/* The bonded pairs could not create any channels,
5373 	 * lower the bandwidth to find a channel.
5374 	 */
5375 	if (!chan_list->num_ch_params) {
5376 		*in_ch_width =  get_next_lower_bandwidth(*in_ch_width);
5377 		*update_bw = true;
5378 	}
5379 }
5380 #endif
5381 
5382 /**
5383  * No subchannels are punctured
5384  * binary 1:- Punctured 0:- Not-Punctured.
5385  */
5386 #define NO_SCHANS_PUNC 0x0000
5387 
5388 /**
5389  * reg_fill_pre320mhz_channel() - Fill channel params for channel width
5390  * less than 320.
5391  * @pdev: Pointer to struct wlan_objmgr_pdev
5392  * @chan_list: Pointer to struct reg_channel_list
5393  * @ch_width: Channel width
5394  * @freq: Center frequency of the primary channel in MHz
5395  * @sec_ch_2g_freq:  Secondary 2G channel frequency in MHZ
5396  * @treat_nol_chan_as_disabled: Bool to treat NOL channels as
5397  * disabled/enabled
5398  */
5399 static void
5400 reg_fill_pre320mhz_channel(struct wlan_objmgr_pdev *pdev,
5401 			   struct reg_channel_list *chan_list,
5402 			   enum phy_ch_width ch_width,
5403 			   qdf_freq_t freq,
5404 			   qdf_freq_t sec_ch_2g_freq,
5405 			   bool treat_nol_chan_as_disabled)
5406 {
5407 	chan_list->num_ch_params = 1;
5408 	chan_list->chan_param[0].ch_width = ch_width;
5409 	chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC;
5410 	reg_set_channel_params_for_freq(pdev, freq, sec_ch_2g_freq,
5411 					&chan_list->chan_param[0],
5412 					treat_nol_chan_as_disabled);
5413 }
5414 
5415 #ifdef CONFIG_REG_6G_PWRMODE
5416 /**
5417  * reg_fill_pre320mhz_channel_for_pwrmode() - Fill channel params for channel
5418  * width less than 320.
5419  * @pdev: Pointer to struct wlan_objmgr_pdev
5420  * @chan_list: Pointer to struct reg_channel_list
5421  * @ch_width: Channel width
5422  * @freq: Center frequency of the primary channel in MHz
5423  * @sec_ch_2g_freq:  Secondary 2G channel frequency in MHZ
5424  * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based
5425  * channel list will be chosen.
5426  * @treat_nol_chan_as_disabled: Bool to consider nol chan as enabled/disabled
5427  */
5428 static void
5429 reg_fill_pre320mhz_channel_for_pwrmode(
5430 			   struct wlan_objmgr_pdev *pdev,
5431 			   struct reg_channel_list *chan_list,
5432 			   enum phy_ch_width ch_width,
5433 			   qdf_freq_t freq,
5434 			   qdf_freq_t sec_ch_2g_freq,
5435 			   enum supported_6g_pwr_types in_6g_pwr_mode,
5436 			   bool treat_nol_chan_as_disabled)
5437 {
5438 	chan_list->num_ch_params = 1;
5439 	chan_list->chan_param[0].ch_width = ch_width;
5440 	chan_list->chan_param[0].reg_punc_bitmap = NO_SCHANS_PUNC;
5441 	reg_set_channel_params_for_pwrmode(pdev, freq, sec_ch_2g_freq,
5442 					   &chan_list->chan_param[0],
5443 					   in_6g_pwr_mode,
5444 					   treat_nol_chan_as_disabled);
5445 }
5446 #endif
5447 
5448 void
5449 reg_fill_channel_list(struct wlan_objmgr_pdev *pdev,
5450 		      qdf_freq_t freq,
5451 		      qdf_freq_t sec_ch_2g_freq,
5452 		      enum phy_ch_width in_ch_width,
5453 		      qdf_freq_t band_center_320,
5454 		      struct reg_channel_list *chan_list,
5455 		      bool treat_nol_chan_as_disabled)
5456 {
5457 	bool update_bw;
5458 
5459 	if (!chan_list) {
5460 		reg_err("channel params is NULL");
5461 		return;
5462 	}
5463 
5464 	if (in_ch_width >= CH_WIDTH_MAX)
5465 		in_ch_width = CH_WIDTH_320MHZ;
5466 
5467 	if (in_ch_width == CH_WIDTH_320MHZ) {
5468 		update_bw = 0;
5469 		reg_fill_channel_list_for_320(pdev, freq, &in_ch_width,
5470 					      band_center_320, chan_list,
5471 					      &update_bw,
5472 					      treat_nol_chan_as_disabled);
5473 		if (!update_bw)
5474 			return;
5475 	}
5476 
5477 	/* A 320 channel is not available (or) user has not requested
5478 	 * for a 320MHZ channel, look for channels in lower modes,
5479 	 * reg_set_5g_channel_params_for_freq() finds for the
5480 	 * next available mode and fills ch_params.
5481 	 */
5482 	reg_fill_pre320mhz_channel(pdev, chan_list, in_ch_width, freq,
5483 				   sec_ch_2g_freq,
5484 				   treat_nol_chan_as_disabled);
5485 }
5486 
5487 #ifdef CONFIG_REG_6G_PWRMODE
5488 void
5489 reg_fill_channel_list_for_pwrmode(struct wlan_objmgr_pdev *pdev,
5490 				  qdf_freq_t freq,
5491 				  qdf_freq_t sec_ch_2g_freq,
5492 				  enum phy_ch_width in_ch_width,
5493 				  qdf_freq_t band_center_320,
5494 				  struct reg_channel_list *chan_list,
5495 				  enum supported_6g_pwr_types in_6g_pwr_mode,
5496 				  bool treat_nol_chan_as_disabled)
5497 {
5498 	bool update_bw;
5499 
5500 	if (!chan_list) {
5501 		reg_err("channel params is NULL");
5502 		return;
5503 	}
5504 
5505 	if (in_ch_width >= CH_WIDTH_MAX)
5506 		in_ch_width = CH_WIDTH_320MHZ;
5507 
5508 	if (in_ch_width == CH_WIDTH_320MHZ) {
5509 		update_bw = 0;
5510 		reg_fill_channel_list_for_320_for_pwrmode(
5511 					      pdev, freq, &in_ch_width,
5512 					      band_center_320, chan_list,
5513 					      &update_bw, in_6g_pwr_mode,
5514 					      treat_nol_chan_as_disabled);
5515 		if (!update_bw)
5516 			return;
5517 	}
5518 
5519 	/* A 320 channel is not available (or) user has not requested
5520 	 * for a 320MHZ channel, look for channels in lower modes,
5521 	 * reg_set_5g_channel_params_for_freq() finds for the
5522 	 * next available mode and fills ch_params.
5523 	 */
5524 	reg_fill_pre320mhz_channel_for_pwrmode(
5525 				   pdev, chan_list, in_ch_width, freq,
5526 				   sec_ch_2g_freq, in_6g_pwr_mode,
5527 				   treat_nol_chan_as_disabled);
5528 }
5529 #endif
5530 #endif
5531 
5532 enum channel_state
5533 reg_get_5g_bonded_channel_for_freq(struct wlan_objmgr_pdev *pdev,
5534 				   uint16_t freq,
5535 				   enum phy_ch_width ch_width,
5536 				   const struct bonded_channel_freq
5537 				   **bonded_chan_ptr_ptr)
5538 {
5539 	if (ch_width == CH_WIDTH_20MHZ)
5540 		return reg_get_channel_state_for_freq(pdev, freq);
5541 
5542 	if (reg_is_ch_width_320(ch_width)) {
5543 		return reg_get_chan_state_for_320(pdev, freq, 0,
5544 						  ch_width,
5545 						  bonded_chan_ptr_ptr,
5546 						  REG_CURRENT_PWR_MODE,
5547 						  true);
5548 	} else {
5549 		*bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq,
5550 								 ch_width, 0);
5551 		if (!(*bonded_chan_ptr_ptr))
5552 			return CHANNEL_STATE_INVALID;
5553 
5554 		return reg_get_5g_bonded_chan_array_for_freq(
5555 							pdev, freq,
5556 							*bonded_chan_ptr_ptr);
5557 	}
5558 }
5559 
5560 #ifdef CONFIG_REG_6G_PWRMODE
5561 enum channel_state
5562 reg_get_5g_bonded_channel_for_pwrmode(struct wlan_objmgr_pdev *pdev,
5563 				      uint16_t freq,
5564 				      enum phy_ch_width ch_width,
5565 				      const struct bonded_channel_freq
5566 				      **bonded_chan_ptr_ptr,
5567 				      enum supported_6g_pwr_types
5568 				      in_6g_pwr_mode)
5569 {
5570 	if (ch_width == CH_WIDTH_20MHZ)
5571 		return reg_get_channel_state_for_pwrmode(pdev, freq,
5572 						      in_6g_pwr_mode);
5573 
5574 	if (reg_is_ch_width_320(ch_width))
5575 		return reg_get_chan_state_for_320(pdev, freq, 0,
5576 						  ch_width,
5577 						  bonded_chan_ptr_ptr,
5578 						  in_6g_pwr_mode, true);
5579 	/* Fetch the bonded_chan_ptr for width greater than 20MHZ. */
5580 	*bonded_chan_ptr_ptr = reg_get_bonded_chan_entry(freq, ch_width, 0);
5581 
5582 	if (!(*bonded_chan_ptr_ptr)) {
5583 		reg_debug_rl("bonded_chan_ptr_ptr is NULL");
5584 		return CHANNEL_STATE_INVALID;
5585 	}
5586 
5587 	return reg_get_5g_bonded_chan_array_for_pwrmode(pdev, freq,
5588 						     *bonded_chan_ptr_ptr,
5589 						     in_6g_pwr_mode);
5590 }
5591 #endif
5592 
5593 #ifdef CONFIG_REG_6G_PWRMODE
5594 /**
5595  * reg_set_5g_channel_params_for_pwrmode()- Set channel parameters like center
5596  * frequency for a bonded channel state. Also return the maximum bandwidth
5597  * supported by the channel.
5598  * @pdev: Pointer to pdev.
5599  * @freq: Channel center frequency.
5600  * ch_params: Pointer to ch_params.
5601  * @in_6g_pwr_type: Input 6g power mode which decides the which power mode based
5602  * channel list will be chosen.
5603  * @treat_nol_chan_as_disabled: Bool to treat NOL channels as disabled/enabled
5604  *
5605  * Return: void
5606  */
5607 static void reg_set_5g_channel_params_for_pwrmode(
5608 					       struct wlan_objmgr_pdev *pdev,
5609 					       uint16_t freq,
5610 					       struct ch_params *ch_params,
5611 					       enum supported_6g_pwr_types
5612 					       in_6g_pwr_type,
5613 					       bool treat_nol_chan_as_disabled)
5614 {
5615 	/*
5616 	 * Set channel parameters like center frequency for a bonded channel
5617 	 * state. Also return the maximum bandwidth supported by the channel.
5618 	 */
5619 
5620 	enum channel_state chan_state = CHANNEL_STATE_ENABLE;
5621 	enum channel_state chan_state2 = CHANNEL_STATE_ENABLE;
5622 	const struct bonded_channel_freq *bonded_chan_ptr = NULL;
5623 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5624 	enum channel_enum chan_enum, sec_5g_chan_enum;
5625 	uint16_t bw_80 = 0;
5626 	uint16_t max_bw, sec_5g_freq_max_bw = 0;
5627 
5628 	if (!ch_params) {
5629 		reg_err("ch_params is NULL");
5630 		return;
5631 	}
5632 
5633 	chan_enum = reg_get_chan_enum_for_freq(freq);
5634 	if (reg_is_chan_enum_invalid(chan_enum)) {
5635 		reg_err("chan freq is not valid");
5636 		return;
5637 	}
5638 
5639 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5640 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5641 		reg_err("reg pdev priv obj is NULL");
5642 		return;
5643 	}
5644 
5645 	if (ch_params->ch_width >= CH_WIDTH_MAX) {
5646 		if (ch_params->mhz_freq_seg1 != 0)
5647 			ch_params->ch_width = CH_WIDTH_80P80MHZ;
5648 		else
5649 			ch_params->ch_width = CH_WIDTH_160MHZ;
5650 	}
5651 
5652 	if (reg_get_min_max_bw_reg_chan_list(pdev, chan_enum, in_6g_pwr_type,
5653 					     NULL, &max_bw))
5654 		return;
5655 
5656 	bw_80 = reg_get_bw_value(CH_WIDTH_80MHZ);
5657 
5658 	if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
5659 		sec_5g_chan_enum =
5660 			reg_get_chan_enum_for_freq(ch_params->mhz_freq_seg1 -
5661 					NEAREST_20MHZ_CHAN_FREQ_OFFSET);
5662 		if (reg_is_chan_enum_invalid(sec_5g_chan_enum)) {
5663 			reg_err("secondary channel freq is not valid");
5664 			return;
5665 		}
5666 
5667 		if (reg_get_min_max_bw_reg_chan_list(pdev, sec_5g_chan_enum,
5668 						     in_6g_pwr_type,
5669 						     NULL, &sec_5g_freq_max_bw))
5670 			return;
5671 	}
5672 
5673 	while (ch_params->ch_width != CH_WIDTH_INVALID) {
5674 		if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
5675 			if ((max_bw < bw_80) || (sec_5g_freq_max_bw < bw_80))
5676 				goto update_bw;
5677 		} else if (max_bw < reg_get_bw_value(ch_params->ch_width)) {
5678 			goto update_bw;
5679 		}
5680 
5681 		bonded_chan_ptr = NULL;
5682 		chan_state = reg_get_5g_bonded_channel_for_pwrmode(
5683 				pdev, freq, ch_params->ch_width,
5684 				&bonded_chan_ptr, in_6g_pwr_type);
5685 		chan_state =
5686 			reg_get_ch_state_based_on_nol_flag(pdev, freq,
5687 							   ch_params,
5688 							   in_6g_pwr_type,
5689 							   treat_nol_chan_as_disabled);
5690 
5691 		if (ch_params->ch_width == CH_WIDTH_80P80MHZ) {
5692 			struct ch_params temp_ch_params = {0};
5693 
5694 			temp_ch_params.ch_width = CH_WIDTH_80MHZ;
5695 			/* Puncturing patter is not needed for 80+80 */
5696 			reg_set_create_punc_bitmap(&temp_ch_params, false);
5697 			chan_state2 =
5698 				reg_get_ch_state_based_on_nol_flag(pdev,
5699 								   ch_params->mhz_freq_seg1 -
5700 								   NEAREST_20MHZ_CHAN_FREQ_OFFSET,
5701 								   &temp_ch_params, in_6g_pwr_type,
5702 								   treat_nol_chan_as_disabled);
5703 			chan_state = reg_combine_channel_states(
5704 					chan_state, chan_state2);
5705 		}
5706 
5707 		if ((chan_state != CHANNEL_STATE_ENABLE) &&
5708 		    (chan_state != CHANNEL_STATE_DFS))
5709 			goto update_bw;
5710 		if (ch_params->ch_width <= CH_WIDTH_20MHZ) {
5711 			ch_params->sec_ch_offset = NO_SEC_CH;
5712 			ch_params->mhz_freq_seg0 = freq;
5713 				ch_params->center_freq_seg0 =
5714 				reg_freq_to_chan(pdev,
5715 						 ch_params->mhz_freq_seg0);
5716 			break;
5717 		} else if (ch_params->ch_width >= CH_WIDTH_40MHZ) {
5718 			const struct bonded_channel_freq *bonded_chan_ptr2;
5719 
5720 			bonded_chan_ptr2 =
5721 					reg_get_bonded_chan_entry(
5722 								freq,
5723 								CH_WIDTH_40MHZ,
5724 								0);
5725 
5726 			if (!bonded_chan_ptr || !bonded_chan_ptr2)
5727 				goto update_bw;
5728 			if (freq == bonded_chan_ptr2->start_freq)
5729 				ch_params->sec_ch_offset = LOW_PRIMARY_CH;
5730 			else
5731 				ch_params->sec_ch_offset = HIGH_PRIMARY_CH;
5732 
5733 			ch_params->mhz_freq_seg0 =
5734 				(bonded_chan_ptr->start_freq +
5735 				 bonded_chan_ptr->end_freq) / 2;
5736 				ch_params->center_freq_seg0 =
5737 				reg_freq_to_chan(pdev,
5738 						 ch_params->mhz_freq_seg0);
5739 			break;
5740 		}
5741 update_bw:
5742 		ch_params->ch_width =
5743 		    get_next_lower_bandwidth(ch_params->ch_width);
5744 	}
5745 
5746 	if (ch_params->ch_width == CH_WIDTH_160MHZ) {
5747 		ch_params->mhz_freq_seg1 = ch_params->mhz_freq_seg0;
5748 			ch_params->center_freq_seg1 =
5749 				reg_freq_to_chan(pdev,
5750 						 ch_params->mhz_freq_seg1);
5751 
5752 		chan_state = reg_get_5g_bonded_channel_for_pwrmode(
5753 				pdev, freq, CH_WIDTH_80MHZ, &bonded_chan_ptr,
5754 				in_6g_pwr_type);
5755 		if (bonded_chan_ptr) {
5756 			ch_params->mhz_freq_seg0 =
5757 				(bonded_chan_ptr->start_freq +
5758 				 bonded_chan_ptr->end_freq) / 2;
5759 				ch_params->center_freq_seg0 =
5760 				reg_freq_to_chan(pdev,
5761 						 ch_params->mhz_freq_seg0);
5762 		}
5763 	}
5764 
5765 	/* Overwrite mhz_freq_seg1 to 0 for non 160 and 80+80 width */
5766 	if (!(ch_params->ch_width == CH_WIDTH_160MHZ ||
5767 	      ch_params->ch_width == CH_WIDTH_80P80MHZ)) {
5768 		ch_params->mhz_freq_seg1 = 0;
5769 		ch_params->center_freq_seg1 = 0;
5770 	}
5771 }
5772 #endif
5773 
5774 #ifdef CONFIG_REG_CLIENT
5775 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev,
5776 					 qdf_freq_t primary_freq)
5777 {
5778 	qdf_freq_t sec_ch_2g_freq = 0;
5779 
5780 	if (primary_freq >= TWOG_CHAN_1_IN_MHZ &&
5781 	    primary_freq <= TWOG_CHAN_5_IN_MHZ)
5782 		sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET;
5783 	else if (primary_freq >= TWOG_CHAN_6_IN_MHZ &&
5784 		 primary_freq <= TWOG_CHAN_13_IN_MHZ)
5785 		sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET;
5786 
5787 	return sec_ch_2g_freq;
5788 }
5789 #else
5790 static qdf_freq_t reg_get_sec_ch_2g_freq(struct wlan_objmgr_pdev *pdev,
5791 					 qdf_freq_t primary_freq)
5792 {
5793 	qdf_freq_t sec_ch_2g_freq;
5794 
5795 	if (primary_freq < TWOG_CHAN_1_IN_MHZ ||
5796 	    primary_freq > TWOG_CHAN_13_IN_MHZ)
5797 		return 0;
5798 
5799 	sec_ch_2g_freq = primary_freq + HT40_SEC_OFFSET;
5800 
5801 	/* For 2G primary frequencies > 2452 (IEEE9), return HT40-. */
5802 	if (primary_freq > TWOG_CHAN_9_IN_MHZ)
5803 		sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET;
5804 
5805 	/*
5806 	 * For 2G primary frequencies <= 2452 (IEEE9), return HT40+ if
5807 	 * the secondary is available, else return HT40-.
5808 	 */
5809 	else if (!reg_is_freq_present_in_cur_chan_list(pdev, sec_ch_2g_freq))
5810 		sec_ch_2g_freq = primary_freq - HT40_SEC_OFFSET;
5811 
5812 	return sec_ch_2g_freq;
5813 }
5814 #endif
5815 
5816 void reg_set_2g_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
5817 					uint16_t oper_freq,
5818 					struct ch_params *ch_params,
5819 					uint16_t sec_ch_2g_freq)
5820 {
5821 	enum channel_state chan_state = CHANNEL_STATE_ENABLE;
5822 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
5823 	enum channel_enum chan_enum;
5824 	uint16_t max_bw;
5825 
5826 	chan_enum = reg_get_chan_enum_for_freq(oper_freq);
5827 	if (reg_is_chan_enum_invalid(chan_enum)) {
5828 		reg_err("chan freq is not valid");
5829 		return;
5830 	}
5831 
5832 	pdev_priv_obj = reg_get_pdev_obj(pdev);
5833 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
5834 		reg_err("reg pdev priv obj is NULL");
5835 		return;
5836 	}
5837 
5838 	if (ch_params->ch_width >= CH_WIDTH_MAX)
5839 		ch_params->ch_width = CH_WIDTH_40MHZ;
5840 	if ((reg_get_bw_value(ch_params->ch_width) > 20) && !sec_ch_2g_freq)
5841 		sec_ch_2g_freq = reg_get_sec_ch_2g_freq(pdev, oper_freq);
5842 
5843 	max_bw = pdev_priv_obj->cur_chan_list[chan_enum].max_bw;
5844 
5845 	while (ch_params->ch_width != CH_WIDTH_INVALID) {
5846 		if (max_bw < reg_get_bw_value(ch_params->ch_width))
5847 			goto update_bw;
5848 
5849 		chan_state =
5850 		reg_get_2g_bonded_channel_state_for_freq(pdev, oper_freq,
5851 							 sec_ch_2g_freq,
5852 							 ch_params->ch_width);
5853 		if ((chan_state == CHANNEL_STATE_ENABLE) ||
5854 		    (chan_state == CHANNEL_STATE_DFS)) {
5855 			if (ch_params->ch_width == CH_WIDTH_40MHZ) {
5856 				if (oper_freq < sec_ch_2g_freq)
5857 					ch_params->sec_ch_offset =
5858 						LOW_PRIMARY_CH;
5859 				else
5860 					ch_params->sec_ch_offset =
5861 						HIGH_PRIMARY_CH;
5862 				ch_params->mhz_freq_seg0 =
5863 					(oper_freq + sec_ch_2g_freq) / 2;
5864 				if (ch_params->mhz_freq_seg0 ==
5865 						TWOG_CHAN_14_IN_MHZ)
5866 					ch_params->center_freq_seg0 = 14;
5867 				else
5868 					ch_params->center_freq_seg0 =
5869 						(ch_params->mhz_freq_seg0 -
5870 						 TWOG_STARTING_FREQ) /
5871 						FREQ_TO_CHAN_SCALE;
5872 			} else {
5873 				ch_params->sec_ch_offset = NO_SEC_CH;
5874 				ch_params->mhz_freq_seg0 = oper_freq;
5875 				if (ch_params->mhz_freq_seg0 ==
5876 						TWOG_CHAN_14_IN_MHZ)
5877 					ch_params->center_freq_seg0 = 14;
5878 				else
5879 					ch_params->center_freq_seg0 =
5880 						(ch_params->mhz_freq_seg0 -
5881 						 TWOG_STARTING_FREQ) /
5882 						FREQ_TO_CHAN_SCALE;
5883 			}
5884 			break;
5885 		}
5886 update_bw:
5887 		ch_params->ch_width =
5888 		    get_next_lower_bandwidth(ch_params->ch_width);
5889 	}
5890 	/* Overwrite mhz_freq_seg1 and center_freq_seg1 to 0 for 2.4 Ghz */
5891 	ch_params->mhz_freq_seg1 = 0;
5892 	ch_params->center_freq_seg1 = 0;
5893 }
5894 
5895 #ifdef WLAN_FEATURE_11BE
5896 static void reg_copy_ch_params(struct ch_params *ch_params,
5897 			       struct reg_channel_list chan_list)
5898 {
5899 	ch_params->center_freq_seg0 = chan_list.chan_param[0].center_freq_seg0;
5900 	ch_params->center_freq_seg1 = chan_list.chan_param[0].center_freq_seg1;
5901 	ch_params->mhz_freq_seg0 = chan_list.chan_param[0].mhz_freq_seg0;
5902 	ch_params->mhz_freq_seg1 = chan_list.chan_param[0].mhz_freq_seg1;
5903 	ch_params->ch_width = chan_list.chan_param[0].ch_width;
5904 	ch_params->sec_ch_offset = chan_list.chan_param[0].sec_ch_offset;
5905 	ch_params->reg_punc_bitmap = chan_list.chan_param[0].reg_punc_bitmap;
5906 }
5907 
5908 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
5909 				     qdf_freq_t freq,
5910 				     qdf_freq_t sec_ch_2g_freq,
5911 				     struct ch_params *ch_params,
5912 				     bool treat_nol_chan_as_disabled)
5913 {
5914 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) {
5915 		if (reg_is_ch_width_320(ch_params->ch_width)) {
5916 			struct reg_channel_list chan_list;
5917 
5918 			qdf_mem_zero(&chan_list, sizeof(chan_list));
5919 			/* For now sending center freq as 0 */
5920 			reg_fill_channel_list(pdev, freq, sec_ch_2g_freq,
5921 					      ch_params->ch_width, 0,
5922 					      &chan_list,
5923 					      treat_nol_chan_as_disabled);
5924 			reg_copy_ch_params(ch_params, chan_list);
5925 		} else {
5926 			reg_set_5g_channel_params_for_pwrmode(
5927 						pdev, freq,
5928 						ch_params,
5929 						REG_CURRENT_PWR_MODE,
5930 						treat_nol_chan_as_disabled);
5931 		}
5932 	} else if  (reg_is_24ghz_ch_freq(freq)) {
5933 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
5934 						   sec_ch_2g_freq);
5935 	}
5936 }
5937 #else /* WLAN_FEATURE_11BE */
5938 void reg_set_channel_params_for_freq(struct wlan_objmgr_pdev *pdev,
5939 				     qdf_freq_t freq,
5940 				     qdf_freq_t sec_ch_2g_freq,
5941 				     struct ch_params *ch_params,
5942 				     bool treat_nol_chan_as_disabled)
5943 {
5944 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq))
5945 		reg_set_5g_channel_params_for_pwrmode(
5946 						pdev, freq, ch_params,
5947 						REG_CURRENT_PWR_MODE,
5948 						treat_nol_chan_as_disabled);
5949 	else if  (reg_is_24ghz_ch_freq(freq))
5950 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
5951 						   sec_ch_2g_freq);
5952 }
5953 #endif /* WLAN_FEATURE_11BE */
5954 
5955 #ifdef CONFIG_REG_6G_PWRMODE
5956 #ifdef WLAN_FEATURE_11BE
5957 void
5958 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev,
5959 				   qdf_freq_t freq,
5960 				   qdf_freq_t sec_ch_2g_freq,
5961 				   struct ch_params *ch_params,
5962 				   enum supported_6g_pwr_types in_6g_pwr_mode,
5963 				   bool is_treat_nol_dis)
5964 {
5965 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq)) {
5966 		if (reg_is_ch_width_320(ch_params->ch_width)) {
5967 			struct reg_channel_list chan_list;
5968 
5969 			qdf_mem_zero(&chan_list, sizeof(chan_list));
5970 			/* For now sending center freq as 0 */
5971 			reg_fill_channel_list_for_pwrmode(pdev, freq,
5972 							  sec_ch_2g_freq,
5973 							  ch_params->ch_width,
5974 							  0, &chan_list,
5975 							  in_6g_pwr_mode,
5976 							  is_treat_nol_dis);
5977 			reg_copy_ch_params(ch_params, chan_list);
5978 		} else {
5979 			reg_set_5g_channel_params_for_pwrmode(pdev, freq,
5980 							      ch_params,
5981 							      in_6g_pwr_mode,
5982 							      is_treat_nol_dis);
5983 		}
5984 	} else if  (reg_is_24ghz_ch_freq(freq)) {
5985 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
5986 						   sec_ch_2g_freq);
5987 	}
5988 }
5989 #else
5990 void
5991 reg_set_channel_params_for_pwrmode(struct wlan_objmgr_pdev *pdev,
5992 				   qdf_freq_t freq,
5993 				   qdf_freq_t sec_ch_2g_freq,
5994 				   struct ch_params *ch_params,
5995 				   enum supported_6g_pwr_types in_6g_pwr_mode,
5996 				   bool is_treat_nol_dis)
5997 {
5998 	if (reg_is_5ghz_ch_freq(freq) || reg_is_6ghz_chan_freq(freq))
5999 		reg_set_5g_channel_params_for_pwrmode(pdev, freq, ch_params,
6000 						      in_6g_pwr_mode,
6001 						      is_treat_nol_dis);
6002 	else if  (reg_is_24ghz_ch_freq(freq))
6003 		reg_set_2g_channel_params_for_freq(pdev, freq, ch_params,
6004 						   sec_ch_2g_freq);
6005 }
6006 #endif
6007 #endif
6008 
6009 uint8_t reg_get_channel_reg_power_for_freq(struct wlan_objmgr_pdev *pdev,
6010 					   qdf_freq_t freq)
6011 {
6012 	enum channel_enum chan_enum;
6013 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6014 	struct regulatory_channel *reg_channels;
6015 
6016 	chan_enum = reg_get_chan_enum_for_freq(freq);
6017 
6018 	if (reg_is_chan_enum_invalid(chan_enum)) {
6019 		reg_err("channel is invalid");
6020 		return REG_INVALID_TXPOWER;
6021 	}
6022 
6023 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6024 
6025 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6026 		reg_err("reg pdev priv obj is NULL");
6027 		return REG_INVALID_TXPOWER;
6028 	}
6029 
6030 	reg_channels = pdev_priv_obj->cur_chan_list;
6031 
6032 	return reg_channels[chan_enum].tx_power;
6033 }
6034 
6035 bool reg_is_dfs_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
6036 {
6037 	uint32_t chan_flags;
6038 
6039 	chan_flags = reg_get_channel_flags_for_freq(pdev, freq);
6040 
6041 	return chan_flags & REGULATORY_CHAN_RADAR;
6042 }
6043 
6044 #ifdef CONFIG_REG_CLIENT
6045 bool reg_is_dfs_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev,
6046 					   qdf_freq_t freq)
6047 {
6048 	uint32_t chan_flags;
6049 
6050 	chan_flags = reg_get_channel_flags_from_secondary_list_for_freq(pdev,
6051 									freq);
6052 
6053 	return chan_flags & REGULATORY_CHAN_RADAR;
6054 }
6055 
6056 /**
6057  * reg_get_psoc_mas_chan_list () - Get psoc master channel list
6058  * @pdev: pointer to pdev object
6059  * @psoc: pointer to psoc object
6060  *
6061  * Return: psoc master chanel list
6062  */
6063 static struct regulatory_channel *reg_get_psoc_mas_chan_list(
6064 						struct wlan_objmgr_pdev *pdev,
6065 						struct wlan_objmgr_psoc *psoc)
6066 {
6067 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
6068 	uint8_t pdev_id;
6069 	uint8_t phy_id;
6070 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
6071 
6072 	soc_reg = reg_get_psoc_obj(psoc);
6073 	if (!soc_reg) {
6074 		reg_err("reg psoc private obj is NULL");
6075 		return NULL;
6076 	}
6077 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
6078 
6079 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
6080 	if (reg_tx_ops->get_phy_id_from_pdev_id)
6081 		reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
6082 	else
6083 		phy_id = pdev_id;
6084 
6085 	return soc_reg->mas_chan_params[phy_id].mas_chan_list;
6086 }
6087 #else
6088 static inline struct regulatory_channel *reg_get_psoc_mas_chan_list(
6089 						struct wlan_objmgr_pdev *pdev,
6090 						struct wlan_objmgr_psoc *psoc)
6091 {
6092 	return NULL;
6093 }
6094 #endif
6095 
6096 void reg_update_nol_ch_for_freq(struct wlan_objmgr_pdev *pdev,
6097 				uint16_t *chan_freq_list,
6098 				uint8_t num_chan,
6099 				bool nol_chan)
6100 {
6101 	enum channel_enum chan_enum;
6102 	struct regulatory_channel *mas_chan_list = NULL, *psoc_mas_chan_list;
6103 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6104 	struct wlan_objmgr_psoc *psoc;
6105 	uint16_t i;
6106 
6107 	if (!num_chan || !chan_freq_list) {
6108 		reg_err("chan_freq_list or num_ch is NULL");
6109 		return;
6110 	}
6111 
6112 	psoc = wlan_pdev_get_psoc(pdev);
6113 
6114 
6115 	psoc_mas_chan_list = reg_get_psoc_mas_chan_list(pdev, psoc);
6116 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6117 
6118 	if (pdev_priv_obj)
6119 		mas_chan_list = pdev_priv_obj->mas_chan_list;
6120 
6121 	for (i = 0; i < num_chan; i++) {
6122 		chan_enum = reg_get_chan_enum_for_freq(chan_freq_list[i]);
6123 		if (reg_is_chan_enum_invalid(chan_enum)) {
6124 			reg_err("Invalid freq in nol list, freq %d",
6125 				chan_freq_list[i]);
6126 			continue;
6127 		}
6128 		if (mas_chan_list)
6129 			mas_chan_list[chan_enum].nol_chan = nol_chan;
6130 		if (psoc_mas_chan_list)
6131 			psoc_mas_chan_list[chan_enum].nol_chan = nol_chan;
6132 	}
6133 
6134 	if (!pdev_priv_obj) {
6135 		reg_err("reg pdev private obj is NULL");
6136 		return;
6137 	}
6138 
6139 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
6140 
6141 	reg_send_scheduler_msg_sb(psoc, pdev);
6142 }
6143 
6144 void reg_update_nol_history_ch_for_freq(struct wlan_objmgr_pdev *pdev,
6145 					uint16_t *chan_list,
6146 					uint8_t num_chan,
6147 					bool nol_history_chan)
6148 {
6149 	enum channel_enum chan_enum;
6150 	struct regulatory_channel *mas_chan_list;
6151 	struct regulatory_channel *cur_chan_list;
6152 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6153 	uint16_t i;
6154 
6155 	if (!num_chan || !chan_list) {
6156 		reg_err("chan_list or num_ch is NULL");
6157 		return;
6158 	}
6159 
6160 	pdev_priv_obj = wlan_objmgr_pdev_get_comp_private_obj(
6161 			pdev, WLAN_UMAC_COMP_REGULATORY);
6162 
6163 	if (!pdev_priv_obj) {
6164 		reg_err("reg psoc private obj is NULL");
6165 		return;
6166 	}
6167 
6168 	mas_chan_list = pdev_priv_obj->mas_chan_list;
6169 	cur_chan_list = pdev_priv_obj->cur_chan_list;
6170 
6171 	for (i = 0; i < num_chan; i++) {
6172 		chan_enum = reg_get_chan_enum_for_freq(chan_list[i]);
6173 		if (reg_is_chan_enum_invalid(chan_enum)) {
6174 			reg_err("Invalid ch in nol list, chan %d",
6175 				chan_list[i]);
6176 			continue;
6177 		}
6178 		mas_chan_list[chan_enum].nol_history = nol_history_chan;
6179 		cur_chan_list[chan_enum].nol_history = nol_history_chan;
6180 	}
6181 }
6182 
6183 qdf_freq_t reg_min_chan_freq(void)
6184 {
6185 	return channel_map[MIN_24GHZ_CHANNEL].center_freq;
6186 }
6187 
6188 qdf_freq_t reg_max_chan_freq(void)
6189 {
6190 	return channel_map[NUM_CHANNELS - 1].center_freq;
6191 }
6192 
6193 bool reg_is_same_band_freqs(qdf_freq_t freq1, qdf_freq_t freq2)
6194 {
6195 	return (freq1 && freq2 && ((REG_IS_6GHZ_FREQ(freq1) &&
6196 				    REG_IS_6GHZ_FREQ(freq2)) ||
6197 				   (REG_IS_5GHZ_FREQ(freq1) &&
6198 				    REG_IS_5GHZ_FREQ(freq2)) ||
6199 				   (REG_IS_24GHZ_CH_FREQ(freq1) &&
6200 				    REG_IS_24GHZ_CH_FREQ(freq2))));
6201 }
6202 
6203 enum reg_wifi_band reg_freq_to_band(qdf_freq_t freq)
6204 {
6205 	if (REG_IS_24GHZ_CH_FREQ(freq))
6206 		return REG_BAND_2G;
6207 	else if (REG_IS_5GHZ_FREQ(freq) || REG_IS_49GHZ_FREQ(freq))
6208 		return REG_BAND_5G;
6209 	else if (REG_IS_6GHZ_FREQ(freq))
6210 		return REG_BAND_6G;
6211 	return REG_BAND_UNKNOWN;
6212 }
6213 
6214 #ifdef CONFIG_REG_6G_PWRMODE
6215 bool reg_is_disable_for_pwrmode(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq,
6216 				enum supported_6g_pwr_types in_6g_pwr_mode)
6217 {
6218 	enum channel_state ch_state;
6219 
6220 	ch_state = reg_get_channel_state_for_pwrmode(pdev,
6221 						     freq,
6222 						     in_6g_pwr_mode);
6223 
6224 	return (ch_state == CHANNEL_STATE_DISABLE) ||
6225 		(ch_state == CHANNEL_STATE_INVALID);
6226 }
6227 #endif
6228 
6229 #ifdef CONFIG_REG_CLIENT
6230 bool reg_is_disable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev,
6231 					       qdf_freq_t freq)
6232 {
6233 	enum channel_state ch_state;
6234 
6235 	ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev,
6236 								      freq);
6237 
6238 	return ch_state == CHANNEL_STATE_DISABLE;
6239 }
6240 
6241 bool reg_is_enable_in_secondary_list_for_freq(struct wlan_objmgr_pdev *pdev,
6242 					      qdf_freq_t freq)
6243 {
6244 	enum channel_state ch_state;
6245 
6246 	ch_state = reg_get_channel_state_from_secondary_list_for_freq(pdev,
6247 								      freq);
6248 
6249 	return ch_state == CHANNEL_STATE_ENABLE;
6250 }
6251 
6252 #ifdef CONFIG_BAND_6GHZ
6253 static uint8_t reg_get_max_tx_power_from_super_chan_list(
6254 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
6255 			enum supported_6g_pwr_types in_6g_pwr_type)
6256 {
6257 	struct super_chan_info *sc_entry;
6258 	enum supported_6g_pwr_types pwr_type;
6259 	uint8_t i, max_tx_power = 0;
6260 
6261 	pwr_type = in_6g_pwr_type;
6262 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
6263 		sc_entry = &pdev_priv_obj->super_chan_list[i];
6264 
6265 		if (in_6g_pwr_type == REG_BEST_PWR_MODE)
6266 			pwr_type = sc_entry->best_power_mode;
6267 
6268 		if (reg_is_supp_pwr_mode_invalid(pwr_type))
6269 			continue;
6270 
6271 		if (!reg_is_chan_disabled(sc_entry->chan_flags_arr[pwr_type],
6272 					  sc_entry->state_arr[pwr_type]) &&
6273 		    (sc_entry->reg_chan_pwr[pwr_type].tx_power > max_tx_power))
6274 			max_tx_power =
6275 				sc_entry->reg_chan_pwr[pwr_type].tx_power;
6276 	}
6277 	return max_tx_power;
6278 }
6279 #else
6280 static inline uint8_t reg_get_max_tx_power_from_super_chan_list(
6281 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
6282 			enum supported_6g_pwr_types in_6g_pwr_type)
6283 {
6284 	return 0;
6285 }
6286 #endif
6287 
6288 uint8_t reg_get_max_tx_power_for_pwr_mode(
6289 				struct wlan_objmgr_pdev *pdev,
6290 				enum supported_6g_pwr_types in_6g_pwr_type)
6291 {
6292 	uint8_t i, max_tx_power = 0, max_super_chan_power = 0;
6293 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6294 	uint16_t max_curr_num_chan;
6295 
6296 	if (!pdev) {
6297 		reg_err_rl("invalid pdev");
6298 		return QDF_STATUS_E_INVAL;
6299 	}
6300 
6301 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6302 
6303 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6304 		reg_err_rl("reg pdev priv obj is NULL");
6305 		return QDF_STATUS_E_INVAL;
6306 	}
6307 
6308 	if (in_6g_pwr_type == REG_CURRENT_PWR_MODE)
6309 		max_curr_num_chan = NUM_CHANNELS;
6310 	else
6311 		max_curr_num_chan = MAX_5GHZ_CHANNEL;
6312 
6313 	for (i = 0; i < max_curr_num_chan; i++) {
6314 		if (!reg_is_chan_disabled(
6315 			pdev_priv_obj->cur_chan_list[i].chan_flags,
6316 			pdev_priv_obj->cur_chan_list[i].state) &&
6317 		    (pdev_priv_obj->cur_chan_list[i].tx_power > max_tx_power))
6318 			max_tx_power =
6319 			pdev_priv_obj->cur_chan_list[i].tx_power;
6320 	}
6321 
6322 	if (in_6g_pwr_type == REG_CURRENT_PWR_MODE)
6323 		goto return_max_tx_power;
6324 
6325 	max_super_chan_power = reg_get_max_tx_power_from_super_chan_list(
6326 								pdev_priv_obj,
6327 								in_6g_pwr_type);
6328 
6329 	if (max_super_chan_power > max_tx_power)
6330 		max_tx_power = max_super_chan_power;
6331 
6332 return_max_tx_power:
6333 
6334 	if (!max_tx_power)
6335 		reg_err_rl("max_tx_power is zero");
6336 
6337 	return max_tx_power;
6338 }
6339 #endif
6340 
6341 bool reg_is_passive_for_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
6342 {
6343 	uint32_t chan_flags;
6344 
6345 	chan_flags = reg_get_channel_flags_for_freq(pdev, freq);
6346 
6347 	return chan_flags & REGULATORY_CHAN_NO_IR;
6348 }
6349 #endif /* CONFIG_CHAN_FREQ_API */
6350 
6351 uint8_t  reg_get_max_tx_power(struct wlan_objmgr_pdev *pdev)
6352 {
6353 	struct regulatory_channel *cur_chan_list;
6354 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6355 	uint8_t i, max_tx_power = 0;
6356 
6357 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6358 
6359 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6360 		reg_err("reg pdev private obj is NULL");
6361 		return QDF_STATUS_E_FAILURE;
6362 	}
6363 
6364 	cur_chan_list = pdev_priv_obj->cur_chan_list;
6365 
6366 	for (i = 0; i < NUM_CHANNELS; i++) {
6367 		if (cur_chan_list[i].state != CHANNEL_STATE_DISABLE &&
6368 		    cur_chan_list[i].chan_flags != REGULATORY_CHAN_DISABLED) {
6369 			if (cur_chan_list[i].tx_power > max_tx_power)
6370 				max_tx_power = cur_chan_list[i].tx_power;
6371 		}
6372 	}
6373 
6374 	if (!max_tx_power)
6375 		reg_err_rl("max_tx_power is zero");
6376 
6377 	return max_tx_power;
6378 }
6379 
6380 QDF_STATUS reg_set_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc)
6381 {
6382 	struct wlan_regulatory_psoc_priv_obj *psoc_reg;
6383 
6384 	psoc_reg = reg_get_psoc_obj(psoc);
6385 	if (!IS_VALID_PSOC_REG_OBJ(psoc_reg)) {
6386 		reg_err("psoc reg component is NULL");
6387 		return QDF_STATUS_E_INVAL;
6388 	}
6389 
6390 	psoc_reg->ignore_fw_reg_offload_ind = true;
6391 	return QDF_STATUS_SUCCESS;
6392 }
6393 
6394 bool reg_get_ignore_fw_reg_offload_ind(struct wlan_objmgr_psoc *psoc)
6395 {
6396 	struct wlan_regulatory_psoc_priv_obj *psoc_reg;
6397 
6398 	psoc_reg = reg_get_psoc_obj(psoc);
6399 	if (!IS_VALID_PSOC_REG_OBJ(psoc_reg))
6400 		return false;
6401 
6402 	return psoc_reg->ignore_fw_reg_offload_ind;
6403 }
6404 
6405 QDF_STATUS reg_set_6ghz_supported(struct wlan_objmgr_psoc *psoc, bool val)
6406 {
6407 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6408 
6409 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6410 
6411 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
6412 		reg_err("psoc reg component is NULL");
6413 		return QDF_STATUS_E_FAILURE;
6414 	}
6415 
6416 	psoc_priv_obj->six_ghz_supported = val;
6417 
6418 	return QDF_STATUS_SUCCESS;
6419 }
6420 
6421 QDF_STATUS
6422 reg_set_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc, bool val)
6423 {
6424 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6425 
6426 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6427 
6428 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
6429 		reg_err("psoc reg component is NULL");
6430 		return QDF_STATUS_E_FAILURE;
6431 	}
6432 
6433 	psoc_priv_obj->five_dot_nine_ghz_supported = val;
6434 
6435 	return QDF_STATUS_SUCCESS;
6436 }
6437 
6438 #ifdef CONFIG_REG_CLIENT
6439 bool reg_is_6ghz_supported(struct wlan_objmgr_psoc *psoc)
6440 {
6441 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6442 
6443 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6444 
6445 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
6446 		reg_err("psoc reg component is NULL");
6447 		return  false;
6448 	}
6449 
6450 	return psoc_priv_obj->six_ghz_supported;
6451 }
6452 #endif
6453 
6454 bool reg_is_5dot9_ghz_supported(struct wlan_objmgr_psoc *psoc)
6455 {
6456 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6457 
6458 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6459 
6460 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
6461 		reg_err("psoc reg component is NULL");
6462 		return  false;
6463 	}
6464 
6465 	return psoc_priv_obj->five_dot_nine_ghz_supported;
6466 }
6467 
6468 bool reg_is_fcc_regdmn(struct wlan_objmgr_pdev *pdev)
6469 {
6470 	struct cur_regdmn_info cur_reg_dmn;
6471 	QDF_STATUS status;
6472 
6473 	status = reg_get_curr_regdomain(pdev, &cur_reg_dmn);
6474 	if (status != QDF_STATUS_SUCCESS) {
6475 		reg_err_rl("Failed to get reg domain");
6476 		return false;
6477 	}
6478 
6479 	return reg_fcc_regdmn(cur_reg_dmn.dmn_id_5g);
6480 }
6481 
6482 bool reg_is_5dot9_ghz_freq(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
6483 {
6484 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6485 
6486 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6487 
6488 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6489 		reg_err("reg pdev priv obj is NULL");
6490 		return false;
6491 	}
6492 
6493 	return (freq >= channel_map_us[MIN_5DOT9_CHANNEL].center_freq &&
6494 		freq <= channel_map_us[MAX_5DOT9_CHANNEL].center_freq);
6495 }
6496 
6497 bool reg_is_5dot9_ghz_chan_allowed_master_mode(struct wlan_objmgr_pdev *pdev)
6498 {
6499 	struct wlan_objmgr_psoc *psoc;
6500 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
6501 
6502 	if (!pdev) {
6503 		reg_alert("pdev is NULL");
6504 		return true;
6505 	}
6506 	psoc = wlan_pdev_get_psoc(pdev);
6507 
6508 	psoc_priv_obj = reg_get_psoc_obj(psoc);
6509 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
6510 		reg_alert("psoc reg component is NULL");
6511 		return true;
6512 	}
6513 
6514 	return psoc_priv_obj->enable_5dot9_ghz_chan_in_master_mode;
6515 }
6516 
6517 #ifdef DISABLE_UNII_SHARED_BANDS
6518 QDF_STATUS
6519 reg_get_unii_5g_bitmap(struct wlan_objmgr_pdev *pdev, uint8_t *bitmap)
6520 {
6521 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6522 
6523 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6524 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6525 		reg_err_rl("pdev reg component is NULL");
6526 		return QDF_STATUS_E_FAILURE;
6527 	}
6528 	*bitmap =  pdev_priv_obj->unii_5g_bitmap;
6529 
6530 	return QDF_STATUS_SUCCESS;
6531 }
6532 #endif
6533 
6534 #ifdef WLAN_FEATURE_11BE
6535 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap)
6536 {
6537 	if (!phymode_bitmap)
6538 		return false;
6539 
6540 	if (phy_in == REG_PHYMODE_11BE)
6541 		return phymode_bitmap & REGULATORY_PHYMODE_NO11BE;
6542 	else if (phy_in == REG_PHYMODE_11AX)
6543 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AX;
6544 	else if (phy_in == REG_PHYMODE_11AC)
6545 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AC;
6546 	else if (phy_in == REG_PHYMODE_11N)
6547 		return phymode_bitmap & REGULATORY_CHAN_NO11N;
6548 	else if (phy_in == REG_PHYMODE_11G)
6549 		return phymode_bitmap & REGULATORY_PHYMODE_NO11G;
6550 	else if (phy_in == REG_PHYMODE_11A)
6551 		return phymode_bitmap & REGULATORY_PHYMODE_NO11A;
6552 	else if (phy_in == REG_PHYMODE_11B)
6553 		return phymode_bitmap & REGULATORY_PHYMODE_NO11B;
6554 	else
6555 		return true;
6556 }
6557 #else
6558 bool reg_is_phymode_unallowed(enum reg_phymode phy_in, uint32_t phymode_bitmap)
6559 {
6560 	if (!phymode_bitmap)
6561 		return false;
6562 
6563 	if (phy_in == REG_PHYMODE_11AX)
6564 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AX;
6565 	else if (phy_in == REG_PHYMODE_11AC)
6566 		return phymode_bitmap & REGULATORY_PHYMODE_NO11AC;
6567 	else if (phy_in == REG_PHYMODE_11N)
6568 		return phymode_bitmap & REGULATORY_CHAN_NO11N;
6569 	else if (phy_in == REG_PHYMODE_11G)
6570 		return phymode_bitmap & REGULATORY_PHYMODE_NO11G;
6571 	else if (phy_in == REG_PHYMODE_11A)
6572 		return phymode_bitmap & REGULATORY_PHYMODE_NO11A;
6573 	else if (phy_in == REG_PHYMODE_11B)
6574 		return phymode_bitmap & REGULATORY_PHYMODE_NO11B;
6575 	else
6576 		return true;
6577 }
6578 #endif
6579 
6580 #ifdef CHECK_REG_PHYMODE
6581 enum reg_phymode reg_get_max_phymode(struct wlan_objmgr_pdev *pdev,
6582 				     enum reg_phymode phy_in,
6583 				     qdf_freq_t freq)
6584 {
6585 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6586 	uint32_t phymode_bitmap;
6587 	enum reg_phymode current_phymode = phy_in;
6588 
6589 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6590 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6591 		reg_err("pdev reg component is NULL");
6592 		return REG_PHYMODE_INVALID;
6593 	}
6594 
6595 	phymode_bitmap = pdev_priv_obj->phybitmap;
6596 
6597 	while (1) {
6598 		if (reg_is_phymode_unallowed(current_phymode, phymode_bitmap)) {
6599 			if (current_phymode == REG_PHYMODE_11N) {
6600 				if (REG_IS_24GHZ_CH_FREQ(freq))
6601 					current_phymode = REG_PHYMODE_11G;
6602 				else
6603 					current_phymode = REG_PHYMODE_11A;
6604 			} else if (current_phymode == REG_PHYMODE_11A ||
6605 				   current_phymode == REG_PHYMODE_11B) {
6606 				reg_err("Couldn't find a suitable phymode");
6607 				return REG_PHYMODE_INVALID;
6608 			} else if (current_phymode > REG_PHYMODE_MAX) {
6609 				reg_err("Unknown phymode");
6610 				return REG_PHYMODE_INVALID;
6611 			} else {
6612 				current_phymode--;
6613 			}
6614 		} else {
6615 			return current_phymode;
6616 		}
6617 	}
6618 }
6619 #endif /* CHECK_REG_PHYMODE */
6620 
6621 #ifdef CONFIG_REG_CLIENT
6622 enum band_info reg_band_bitmap_to_band_info(uint32_t band_bitmap)
6623 {
6624 	if ((band_bitmap & BIT(REG_BAND_2G)) &&
6625 	    (band_bitmap & BIT(REG_BAND_5G)) &&
6626 	    (band_bitmap & BIT(REG_BAND_6G)))
6627 		return BAND_ALL;
6628 	else if ((band_bitmap & BIT(REG_BAND_5G)) &&
6629 		 (band_bitmap & BIT(REG_BAND_6G)))
6630 		return BAND_5G;
6631 	else if ((band_bitmap & BIT(REG_BAND_2G)) &&
6632 		 (band_bitmap & BIT(REG_BAND_6G)))
6633 		return BAND_2G;
6634 	else if ((band_bitmap & BIT(REG_BAND_2G)) &&
6635 		 (band_bitmap & BIT(REG_BAND_5G)))
6636 		return BAND_ALL;
6637 	else if (band_bitmap & BIT(REG_BAND_2G))
6638 		return BAND_2G;
6639 	else if (band_bitmap & BIT(REG_BAND_5G))
6640 		return BAND_5G;
6641 	else if (band_bitmap & BIT(REG_BAND_6G))
6642 		return BAND_2G;
6643 	else
6644 		return BAND_UNKNOWN;
6645 }
6646 #endif
6647 
6648 #if defined(CONFIG_BAND_6GHZ)
6649 QDF_STATUS
6650 reg_set_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
6651 			   enum reg_6g_ap_type reg_cur_6g_ap_pwr_type)
6652 {
6653 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6654 
6655 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6656 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6657 		reg_err("pdev reg component is NULL");
6658 		return QDF_STATUS_E_FAILURE;
6659 	}
6660 
6661 	if (reg_cur_6g_ap_pwr_type > REG_MAX_SUPP_AP_TYPE) {
6662 		reg_err("Unsupported 6G AP power type");
6663 		return QDF_STATUS_E_FAILURE;
6664 	}
6665 	/* should we validate the input reg_cur_6g_ap_type? */
6666 	pdev_priv_obj->reg_cur_6g_ap_pwr_type = reg_cur_6g_ap_pwr_type;
6667 	return QDF_STATUS_SUCCESS;
6668 }
6669 
6670 QDF_STATUS
6671 reg_get_cur_6g_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
6672 			   enum reg_6g_ap_type *reg_cur_6g_ap_pwr_type)
6673 {
6674 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
6675 
6676 	pdev_priv_obj = reg_get_pdev_obj(pdev);
6677 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
6678 		reg_err("pdev reg component is NULL");
6679 		return QDF_STATUS_E_FAILURE;
6680 	}
6681 
6682 	if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE)
6683 		return QDF_STATUS_E_FAILURE;
6684 
6685 	*reg_cur_6g_ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type;
6686 
6687 	return QDF_STATUS_SUCCESS;
6688 }
6689 
6690 /**
6691  * get_reg_rules_for_pdev() - Get the pointer to the reg rules for the pdev
6692  * @pdev: Pointer to pdev
6693  *
6694  * Return: Pointer to Standard Power regulatory rules
6695  */
6696 static struct reg_rule_info *
6697 reg_get_reg_rules_for_pdev(struct wlan_objmgr_pdev *pdev)
6698 {
6699 	struct wlan_objmgr_psoc *psoc;
6700 	struct wlan_regulatory_psoc_priv_obj *psoc_reg_priv;
6701 	uint8_t phy_id;
6702 	struct reg_rule_info *psoc_reg_rules;
6703 
6704 	psoc = wlan_pdev_get_psoc(pdev);
6705 	psoc_reg_priv = reg_get_psoc_obj(psoc);
6706 
6707 	if (!psoc_reg_priv) {
6708 		reg_debug("Regulatory psoc private object is NULL");
6709 		return NULL;
6710 	}
6711 
6712 	phy_id = wlan_objmgr_pdev_get_pdev_id(pdev);
6713 	psoc_reg_rules = &psoc_reg_priv->mas_chan_params[phy_id].reg_rules;
6714 
6715 	return psoc_reg_rules;
6716 }
6717 
6718 /**
6719  * reg_get_num_rules_of_ap_pwr_type() - Get the number of reg rules present
6720  * for a given ap power type
6721  * @pdev: Pointer to pdev
6722  * @ap_pwr_type: AP power type
6723  *
6724  * Return: Return the number of reg rules for a given ap power type
6725  */
6726 static uint8_t
6727 reg_get_num_rules_of_ap_pwr_type(struct wlan_objmgr_pdev *pdev,
6728 				 enum reg_6g_ap_type ap_pwr_type)
6729 {
6730 	struct reg_rule_info *psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev);
6731 
6732 	if (!psoc_reg_rules) {
6733 		reg_debug("No psoc_reg_rules");
6734 		return 0;
6735 	}
6736 
6737 	if (ap_pwr_type > REG_MAX_SUPP_AP_TYPE) {
6738 		reg_err("Unsupported 6G AP power type");
6739 		return 0;
6740 	}
6741 
6742 	return psoc_reg_rules->num_of_6g_ap_reg_rules[ap_pwr_type];
6743 }
6744 
6745 #ifdef CONFIG_AFC_SUPPORT
6746 /**
6747  * reg_is_empty_range() - If both left, right frquency edges in the input range
6748  * are zero then the range is empty, else not.
6749  * @in_range: Pointer to input range
6750  *
6751  * Return: True if the range is empty, else false
6752  */
6753 static bool reg_is_empty_range(struct freq_range *in_range)
6754 {
6755 	return !in_range->left && !in_range->right;
6756 }
6757 
6758 struct freq_range
6759 reg_init_freq_range(qdf_freq_t left, qdf_freq_t right)
6760 {
6761 	struct freq_range out_range;
6762 
6763 	out_range.left = left;
6764 	out_range.right = right;
6765 
6766 	return out_range;
6767 }
6768 
6769 /**
6770  * reg_assign_vars_with_range_vals() - Assign input variables with the values of
6771  * the range variable values
6772  * @in_range: Pointer to input range object
6773  * @left: Pointer to the first variable to get the value of left frequency edge
6774  * @right: Pointer to the second variable to get the value of right frequency
6775  *         edge
6776  *
6777  * Return: void
6778  */
6779 static void
6780 reg_assign_vars_with_range_vals(struct freq_range *in_range,
6781 				qdf_freq_t *left,
6782 				qdf_freq_t *right)
6783 {
6784 	*left = in_range->left;
6785 	*right = in_range->right;
6786 }
6787 
6788 /**
6789  * reg_intersect_ranges() - Intersect two ranges and return the intesected range
6790  * @first: Pointer to first input range
6791  * @second: Pointer to second input range
6792  *
6793  * Return: Intersected output range
6794  */
6795 static struct freq_range
6796 reg_intersect_ranges(struct freq_range *first_range,
6797 		     struct freq_range *second_range)
6798 {
6799 	struct freq_range out_range;
6800 	qdf_freq_t l_freq;
6801 	qdf_freq_t r_freq;
6802 
6803 	/* validate if the ranges are proper */
6804 
6805 	l_freq = QDF_MAX(first_range->left, second_range->left);
6806 	r_freq = QDF_MIN(first_range->right, second_range->right);
6807 
6808 	if (l_freq > r_freq) {
6809 		l_freq = 0;
6810 		l_freq = 0;
6811 
6812 		reg_debug("Ranges do not overlap first= [%u, %u], second = [%u, %u]",
6813 			  first_range->left,
6814 			  first_range->right,
6815 			  second_range->left,
6816 			  second_range->right);
6817 	}
6818 
6819 	out_range.left = l_freq;
6820 	out_range.right = r_freq;
6821 
6822 	return out_range;
6823 }
6824 
6825 /**
6826  * reg_act_sp_rule_cb -  A function pointer type that calculate something
6827  * from the input frequency range
6828  * @rule_fr: Pointer to frequencey range
6829  * @arg: Pointer to generic argument (a.k.a. context)
6830  *
6831  * Return: Void
6832  */
6833 typedef void (*reg_act_sp_rule_cb)(struct freq_range *rule_fr,
6834 				   void *arg);
6835 
6836 /**
6837  * reg_iterate_sp_rules() - Iterate through the Standard Power reg rules, for
6838  * every reg rule call the call back function to take some action or calculate
6839  * something
6840  * @pdev: Pointer to pdev
6841  * @pdev_priv_obj: Pointer to pdev private object
6842  * @action_on_sp_rule: A function pointer to take some action or calculate
6843  * something for every sp rule
6844  * @arg: Pointer to opque object (argument/context)
6845  *
6846  * Return: Void
6847  */
6848 static void reg_iterate_sp_rules(struct wlan_objmgr_pdev *pdev,
6849 				 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
6850 				 reg_act_sp_rule_cb sp_rule_action,
6851 				 void *arg)
6852 {
6853 	struct cur_reg_rule *p_sp_reg_rule;
6854 	struct reg_rule_info *psoc_reg_rules;
6855 	uint8_t n_6g_sp_ap_reg_rules;
6856 	qdf_freq_t low_5g;
6857 	qdf_freq_t high_5g;
6858 	uint8_t i;
6859 	struct freq_range chip_range;
6860 
6861 	psoc_reg_rules = reg_get_reg_rules_for_pdev(pdev);
6862 
6863 	if (!psoc_reg_rules) {
6864 		reg_debug("psoc reg rule pointer is NULL");
6865 		return;
6866 	}
6867 
6868 	n_6g_sp_ap_reg_rules = psoc_reg_rules->num_of_6g_ap_reg_rules[REG_STANDARD_POWER_AP];
6869 	p_sp_reg_rule = psoc_reg_rules->reg_rules_6g_ap[REG_STANDARD_POWER_AP];
6870 
6871 	low_5g = pdev_priv_obj->range_5g_low;
6872 	high_5g = pdev_priv_obj->range_5g_high;
6873 
6874 	chip_range = reg_init_freq_range(low_5g, high_5g);
6875 
6876 	reg_debug("chip_range = [%u, %u]", low_5g, high_5g);
6877 	reg_debug("Num_6g_rules = %u", n_6g_sp_ap_reg_rules);
6878 
6879 	for (i = 0; i < n_6g_sp_ap_reg_rules; i++) {
6880 		struct freq_range sp_range;
6881 		struct freq_range out_range;
6882 
6883 		sp_range = reg_init_freq_range(p_sp_reg_rule->start_freq,
6884 					       p_sp_reg_rule->end_freq);
6885 		reg_debug("Rule:[%u, %u]",
6886 			  p_sp_reg_rule->start_freq,
6887 			  p_sp_reg_rule->end_freq);
6888 		out_range = reg_intersect_ranges(&chip_range, &sp_range);
6889 
6890 		if (sp_rule_action)
6891 			sp_rule_action(&out_range, arg);
6892 
6893 		p_sp_reg_rule++;
6894 	}
6895 }
6896 
6897 /**
6898  * reg_afc_incr_num_ranges() - Increment the number of frequency ranges
6899  * @p_range: Pointer to frequency range
6900  * @num_freq_ranges: Pointer to number of frequency ranges. This needs to be
6901  * (Actual type: uint8_t *num_freq_ranges)
6902  * incremented by the function
6903  *
6904  * Return: Void
6905  */
6906 static void reg_afc_incr_num_ranges(struct freq_range *p_range,
6907 				    void *num_freq_ranges)
6908 {
6909 	if (!reg_is_empty_range(p_range))
6910 		(*(uint8_t *)num_freq_ranges)++;
6911 }
6912 
6913 /**
6914  * reg_get_num_sp_freq_ranges() - Find the number of reg rules from the Standard
6915  * power regulatory rules
6916  * @pdev: Pointer to pdev
6917  *
6918  * Return: number of frequency ranges
6919  */
6920 static uint8_t reg_get_num_sp_freq_ranges(struct wlan_objmgr_pdev *pdev,
6921 					  struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
6922 {
6923 	uint8_t num_freq_ranges;
6924 
6925 	num_freq_ranges = 0;
6926 	reg_iterate_sp_rules(pdev,
6927 			     pdev_priv_obj,
6928 			     reg_afc_incr_num_ranges,
6929 			     &num_freq_ranges);
6930 
6931 	reg_debug("Num_freq_ranges=%u", num_freq_ranges);
6932 	return num_freq_ranges;
6933 }
6934 
6935 /**
6936  * reg_afc_get_intersected_ranges() - Get the intersected range into range obj
6937  * @rule_fr: Pointer to the rule for frequency range
6938  * @arg: Pointer to opaque object (argument/context)
6939  * (Actual type: struct wlan_afc_freq_range_obj **p_range_obj)
6940  * incremented by the function
6941  *
6942  * Return: Void
6943  */
6944 static void reg_afc_get_intersected_ranges(struct freq_range *rule_fr,
6945 					   void *arg)
6946 {
6947 	struct wlan_afc_freq_range_obj *p_range;
6948 	struct wlan_afc_freq_range_obj **pp_range;
6949 	qdf_freq_t low, high;
6950 
6951 	pp_range = (struct wlan_afc_freq_range_obj **)arg;
6952 	p_range = *pp_range;
6953 
6954 	if (!reg_is_empty_range(rule_fr)) {
6955 		reg_assign_vars_with_range_vals(rule_fr, &low, &high);
6956 		p_range->lowfreq = (uint16_t)low;
6957 		p_range->highfreq = (uint16_t)high;
6958 		reg_debug("Range = [%u, %u]", p_range->lowfreq, p_range->highfreq);
6959 		(*pp_range)++;
6960 	}
6961 }
6962 
6963 /**
6964  * reg_cp_freq_ranges() - Copy frequency ranges  from the Standard power
6965  * regulatory rules
6966  * @pdev: Pointer to pdev
6967  * @pdev_priv_obj: Pointer to pdev private object
6968  * @num_freq_ranges: Number of frequency ranges
6969  * @p_range_obj: Pointer to range object
6970  *
6971  * Return: void
6972  */
6973 static void reg_cp_freq_ranges(struct wlan_objmgr_pdev *pdev,
6974 			       struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
6975 			       uint8_t num_freq_ranges,
6976 			       struct wlan_afc_freq_range_obj *p_range_obj)
6977 {
6978 	struct wlan_afc_freq_range_obj *p_range;
6979 
6980 	reg_debug("Num freq ranges = %u", num_freq_ranges);
6981 
6982 	p_range = p_range_obj;
6983 	reg_iterate_sp_rules(pdev,
6984 			     pdev_priv_obj,
6985 			     reg_afc_get_intersected_ranges,
6986 			     &p_range);
6987 }
6988 
6989 /**
6990  * reg_get_frange_list_len() - Calculate the length of the list of the
6991  * frequency ranges
6992  * @num_freq_ranges: Number of frequency ranges
6993  *
6994  * Return: Length of the frequency range list
6995  */
6996 static uint16_t reg_get_frange_list_len(uint8_t num_freq_ranges)
6997 {
6998 	uint16_t frange_lst_len;
6999 
7000 	if (!num_freq_ranges)
7001 		reg_err("AFC:There is no freq ranges");
7002 
7003 	frange_lst_len =
7004 		sizeof(struct wlan_afc_frange_list) +
7005 		sizeof(struct wlan_afc_freq_range_obj) * num_freq_ranges;
7006 
7007 	return frange_lst_len;
7008 }
7009 
7010 /**
7011  * reg_get_opclasses_array_len() - Calculate the length of the array of
7012  * opclasses objects
7013  * @num_opclasses: The number of opclasses
7014  * @chansize_lst: The array of sizes of channel lists
7015  *
7016  * Return: Length of the array of opclass object
7017  */
7018 static uint16_t reg_get_opclasses_array_len(struct wlan_objmgr_pdev *pdev,
7019 					    uint8_t num_opclasses,
7020 					    uint8_t *chansize_lst)
7021 {
7022 	uint16_t opclasses_arr_len = 0;
7023 	uint16_t i;
7024 
7025 	for (i = 0; i < num_opclasses; i++) {
7026 		opclasses_arr_len +=
7027 			sizeof(struct wlan_afc_opclass_obj) +
7028 			sizeof(uint8_t) * chansize_lst[i];
7029 	}
7030 
7031 	return opclasses_arr_len;
7032 }
7033 
7034 /**
7035  * reg_get_afc_req_length() - Calculate the length of the AFC partial request
7036  * @num_opclasses: The number of opclasses
7037  * @num_freq_ranges: The number of frequency ranges
7038  * @chansize_lst: The array of sizes of channel lists
7039  *
7040  * Return: Length of the partial AFC request
7041  */
7042 static uint16_t reg_get_afc_req_length(struct wlan_objmgr_pdev *pdev,
7043 				       uint8_t num_opclasses,
7044 				       uint8_t num_freq_ranges,
7045 				       uint8_t *chansize_lst)
7046 {
7047 	uint16_t afc_req_len;
7048 	uint16_t frange_lst_len;
7049 	uint16_t fixed_param_len;
7050 	uint16_t num_opclasses_len;
7051 	uint16_t opclasses_arr_len;
7052 	uint16_t afc_location_len;
7053 
7054 	fixed_param_len = sizeof(struct wlan_afc_host_req_fixed_params);
7055 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
7056 	num_opclasses_len = sizeof(struct wlan_afc_num_opclasses);
7057 	opclasses_arr_len = reg_get_opclasses_array_len(pdev,
7058 							num_opclasses,
7059 							chansize_lst);
7060 	afc_location_len = sizeof(struct wlan_afc_location);
7061 
7062 	afc_req_len =
7063 		fixed_param_len +
7064 		frange_lst_len +
7065 		num_opclasses_len +
7066 		opclasses_arr_len +
7067 		afc_location_len;
7068 
7069 	return afc_req_len;
7070 }
7071 
7072 /**
7073  * reg_fill_afc_fixed_params() - Fill the AFC fixed params
7074  * @p_fixed_params: Pointer to afc fixed params object
7075  * @afc_req_len: Length of the partial AFC request
7076  *
7077  * Return: Void
7078  */
7079 static inline void
7080 reg_fill_afc_fixed_params(struct wlan_afc_host_req_fixed_params *p_fixed_params,
7081 			  uint16_t afc_req_len)
7082 {
7083 	p_fixed_params->req_length = afc_req_len;
7084 	p_fixed_params->req_id = DEFAULT_REQ_ID;
7085 	p_fixed_params->min_des_power = DEFAULT_MIN_POWER;
7086 }
7087 
7088 /**
7089  * reg_fill_afc_freq_ranges() - Fill the AFC fixed params
7090  * @pdev: Pointer to pdev
7091  * @pdev_priv_obj: Pointer to pdev private object
7092  * @p_frange_lst: Pointer to frequency range list
7093  * @num_freq_ranges: Number of frequency ranges
7094  *
7095  * Return: Void
7096  */
7097 static inline void
7098 reg_fill_afc_freq_ranges(struct wlan_objmgr_pdev *pdev,
7099 			 struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
7100 			 struct wlan_afc_frange_list *p_frange_lst,
7101 			 uint8_t num_freq_ranges)
7102 {
7103 	struct wlan_afc_freq_range_obj *p_range_obj;
7104 
7105 	p_frange_lst->num_ranges = num_freq_ranges;
7106 
7107 	p_range_obj = &p_frange_lst->range_objs[0];
7108 
7109 	reg_cp_freq_ranges(pdev, pdev_priv_obj, num_freq_ranges, p_range_obj);
7110 }
7111 
7112 /**
7113  * reg_fill_afc_opclass_obj() - Fill the opclass object and return pointer to
7114  *                              next AFC opclass object
7115  * @p_obj_opclass_obj: Pointer to opclass object
7116  * @opclass: Operating class
7117  * @num_chans: Number of channels in the opclass
7118  * @p_chan_lst: Pointer to channel list
7119  *
7120  * Return: Pointer to the next AFC opclass object
7121  */
7122 static struct wlan_afc_opclass_obj *
7123 reg_fill_afc_opclass_obj(struct wlan_afc_opclass_obj *p_obj_opclass_obj,
7124 			 uint8_t opclass,
7125 			 uint8_t num_chans,
7126 			 uint8_t *p_chan_lst)
7127 {
7128 	uint16_t len_obj;
7129 	uint8_t *out_p;
7130 	uint8_t *src, *dst;
7131 	uint8_t copy_len;
7132 
7133 	p_obj_opclass_obj->opclass_num_cfis = num_chans;
7134 	p_obj_opclass_obj->opclass = opclass;
7135 	src = p_chan_lst;
7136 	dst = p_obj_opclass_obj->cfis;
7137 	copy_len = num_chans * sizeof(uint8_t);
7138 
7139 	qdf_mem_copy(dst, src, copy_len);
7140 
7141 	len_obj = sizeof(struct wlan_afc_opclass_obj) + copy_len;
7142 	out_p = (uint8_t *)p_obj_opclass_obj + len_obj;
7143 
7144 	return (struct wlan_afc_opclass_obj *)out_p;
7145 }
7146 
7147 /**
7148  * reg_fill_afc_opclasses_arr() - Fill the array of opclass objects
7149  * @num_opclasses: The number of opclasses
7150  * @opclass_lst: The array of Operating classes
7151  * @chansize_lst: The array of sizes of channel lists
7152  * @channel_lists: The array of channel lists
7153  * @p_opclass_obj_arr: Pointer to the first opclass object
7154  *
7155  * Return: Pointer to the end of last opclass object
7156  */
7157 static inline struct wlan_afc_opclass_obj *
7158 reg_fill_afc_opclasses_arr(struct wlan_objmgr_pdev *pdev,
7159 			   uint8_t num_opclasses,
7160 			   uint8_t *opclass_lst,
7161 			   uint8_t *chansize_lst,
7162 			   uint8_t *channel_lists[],
7163 			   struct wlan_afc_opclass_obj *p_opclass_obj_arr)
7164 {
7165 	uint16_t i;
7166 	struct wlan_afc_opclass_obj *p_opclass_obj;
7167 
7168 	p_opclass_obj = p_opclass_obj_arr;
7169 
7170 	for (i = 0; i < num_opclasses; i++) {
7171 		p_opclass_obj = reg_fill_afc_opclass_obj(p_opclass_obj,
7172 							 opclass_lst[i],
7173 							 chansize_lst[i],
7174 							 channel_lists[i]);
7175 	}
7176 	return p_opclass_obj;
7177 }
7178 
7179 /**
7180  * reg_next_opcls_ptr() - Get the pointer to the next opclass object
7181  * @p_cur_opcls_obj: Pointer to the current operating class object
7182  * @num_cfis: number of center frequencey indices
7183  *
7184  * Return: Pointer to next opclss object
7185  */
7186 static struct wlan_afc_opclass_obj *
7187 reg_next_opcls_ptr(struct wlan_afc_opclass_obj *p_cur_opcls_obj,
7188 		   uint8_t num_cfis)
7189 {
7190 	uint8_t cur_obj_sz;
7191 	uint8_t fixed_opcls_sz;
7192 	struct wlan_afc_opclass_obj *p_next_opcls_obj;
7193 	uint8_t *p_tmp_next;
7194 
7195 	fixed_opcls_sz = sizeof(struct wlan_afc_opclass_obj);
7196 	cur_obj_sz = fixed_opcls_sz + num_cfis * sizeof(uint8_t);
7197 	p_tmp_next = (uint8_t *)p_cur_opcls_obj + cur_obj_sz;
7198 	p_next_opcls_obj = (struct wlan_afc_opclass_obj *)p_tmp_next;
7199 
7200 	return p_next_opcls_obj;
7201 }
7202 
7203 void reg_print_partial_afc_req_info(struct wlan_objmgr_pdev *pdev,
7204 				    struct wlan_afc_host_partial_request *afc_req)
7205 {
7206 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
7207 	struct wlan_afc_frange_list *p_frange_lst;
7208 	struct wlan_afc_num_opclasses *p_num_opclasses;
7209 	uint8_t i;
7210 	uint8_t j;
7211 	uint16_t frange_lst_len;
7212 	uint8_t num_opclasses;
7213 	struct wlan_afc_opclass_obj *p_obj_opclass_arr;
7214 	struct wlan_afc_opclass_obj *p_opclass_obj;
7215 	uint8_t num_freq_ranges;
7216 	uint8_t *p_temp;
7217 	struct wlan_afc_location *p_afc_location;
7218 	uint8_t *deployment_type_str;
7219 
7220 	p_fixed_params = &afc_req->fixed_params;
7221 	reg_debug("req_length=%hu", p_fixed_params->req_length);
7222 	reg_debug("req_id=%llu", p_fixed_params->req_id);
7223 	reg_debug("min_des_power=%hd", p_fixed_params->min_des_power);
7224 
7225 	p_temp = (uint8_t *)p_fixed_params;
7226 	p_temp += sizeof(*p_fixed_params);
7227 	p_frange_lst = (struct wlan_afc_frange_list *)p_temp;
7228 	reg_debug("num_ranges=%hhu", p_frange_lst->num_ranges);
7229 	for (i = 0; i < p_frange_lst->num_ranges; i++) {
7230 		struct wlan_afc_freq_range_obj *p_range_obj;
7231 
7232 		p_range_obj = &p_frange_lst->range_objs[i];
7233 		reg_debug("lowfreq=%hu", p_range_obj->lowfreq);
7234 		reg_debug("highfreq=%hu", p_range_obj->highfreq);
7235 	}
7236 
7237 	num_freq_ranges = p_frange_lst->num_ranges;
7238 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
7239 	p_temp += frange_lst_len;
7240 	p_num_opclasses = (struct wlan_afc_num_opclasses *)p_temp;
7241 	num_opclasses = p_num_opclasses->num_opclasses;
7242 	reg_debug("num_opclasses=%hhu", num_opclasses);
7243 
7244 	p_temp += sizeof(*p_num_opclasses);
7245 	p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)p_temp;
7246 	p_opclass_obj = p_obj_opclass_arr;
7247 	for (i = 0; i < num_opclasses; i++) {
7248 		uint8_t opclass = p_opclass_obj->opclass;
7249 		uint8_t num_cfis = p_opclass_obj->opclass_num_cfis;
7250 		uint8_t *cfis = p_opclass_obj->cfis;
7251 
7252 		reg_debug("opclass[%hhu]=%hhu", i, opclass);
7253 		reg_debug("num_cfis[%hhu]=%hhu", i, num_cfis);
7254 		reg_debug("[");
7255 		for (j = 0; j < num_cfis; j++)
7256 			reg_debug("%hhu,", cfis[j]);
7257 		reg_debug("]");
7258 
7259 		p_opclass_obj = reg_next_opcls_ptr(p_opclass_obj, num_cfis);
7260 	}
7261 
7262 	p_afc_location = (struct wlan_afc_location *)p_opclass_obj;
7263 	switch (p_afc_location->deployment_type) {
7264 	case AFC_DEPLOYMENT_INDOOR:
7265 		deployment_type_str = "Indoor";
7266 		break;
7267 	case AFC_DEPLOYMENT_OUTDOOR:
7268 		deployment_type_str = "Outdoor";
7269 		break;
7270 	default:
7271 		deployment_type_str = "Unknown";
7272 	}
7273 	reg_debug("AFC location=%s", deployment_type_str);
7274 }
7275 
7276 /**
7277  * reg_get_frange_filled_buf() - Allocate and fill the frange buffer and return
7278  * the buffer. Also return the number of frequence ranges
7279  * @pdev: Pointer to pdev
7280  * @pdev_priv_obj: Pointer to pdev private object
7281  * @num_freq_ranges: Pointer to number of frequency ranges (output param)
7282  *
7283  * Return: Pointer to the frange buffer
7284  */
7285 static struct wlan_afc_frange_list *
7286 reg_get_frange_filled_buf(struct wlan_objmgr_pdev *pdev,
7287 			  struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
7288 			  uint8_t *num_freq_ranges)
7289 {
7290 	uint16_t frange_lst_len;
7291 	struct wlan_afc_frange_list *p_frange_lst_local;
7292 
7293 	*num_freq_ranges =  reg_get_num_sp_freq_ranges(pdev, pdev_priv_obj);
7294 	frange_lst_len = reg_get_frange_list_len(*num_freq_ranges);
7295 
7296 	p_frange_lst_local = qdf_mem_malloc(frange_lst_len);
7297 	if (!p_frange_lst_local)
7298 		return NULL;
7299 
7300 	reg_fill_afc_freq_ranges(pdev,
7301 				 pdev_priv_obj,
7302 				 p_frange_lst_local,
7303 				 *num_freq_ranges);
7304 	return p_frange_lst_local;
7305 }
7306 
7307 QDF_STATUS
7308 reg_get_partial_afc_req_info(struct wlan_objmgr_pdev *pdev,
7309 			     struct wlan_afc_host_partial_request **afc_req)
7310 {
7311 	/* allocate the memory for the partial request */
7312 	struct wlan_afc_host_partial_request *temp_afc_req;
7313 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
7314 	struct wlan_afc_frange_list *p_frange_lst_local;
7315 	struct wlan_afc_frange_list *p_frange_lst_afc;
7316 	struct wlan_afc_num_opclasses *p_num_opclasses;
7317 	uint16_t afc_req_len;
7318 	uint16_t frange_lst_len;
7319 	uint8_t num_freq_ranges;
7320 	uint8_t num_opclasses;
7321 	struct wlan_afc_opclass_obj *p_obj_opclass_arr;
7322 	struct wlan_afc_location *p_afc_location;
7323 
7324 	uint8_t *opclass_lst;
7325 	uint8_t *chansize_lst;
7326 	uint8_t **channel_lists;
7327 	QDF_STATUS status;
7328 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7329 
7330 	if (!afc_req) {
7331 		reg_err("afc_req is NULL");
7332 		status = QDF_STATUS_E_INVAL;
7333 		return status;
7334 	}
7335 
7336 	temp_afc_req = NULL;
7337 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7338 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7339 		reg_err("pdev reg component is NULL");
7340 		status = QDF_STATUS_E_INVAL;
7341 		goto handle_invalid_priv_object;
7342 	}
7343 
7344 	p_frange_lst_local = reg_get_frange_filled_buf(pdev,
7345 						       pdev_priv_obj,
7346 						       &num_freq_ranges);
7347 	if (!p_frange_lst_local) {
7348 		reg_err("Frange lst not allocated");
7349 		status = QDF_STATUS_E_NOMEM;
7350 		goto handle_invalid_priv_object;
7351 	}
7352 
7353 	status = reg_dmn_get_6g_opclasses_and_channels(pdev,
7354 						       p_frange_lst_local,
7355 						       &num_opclasses,
7356 						       &opclass_lst,
7357 						       &chansize_lst,
7358 						       &channel_lists);
7359 	if (status != QDF_STATUS_SUCCESS) {
7360 		reg_err("Opclasses and chans not allocated");
7361 		status = QDF_STATUS_E_NOMEM;
7362 		goto free_frange_lst_local;
7363 	}
7364 
7365 	afc_req_len = reg_get_afc_req_length(pdev,
7366 					     num_opclasses,
7367 					     num_freq_ranges,
7368 					     chansize_lst);
7369 
7370 	temp_afc_req = qdf_mem_malloc(afc_req_len);
7371 	if (!temp_afc_req) {
7372 		reg_err("AFC request not allocated");
7373 		status = QDF_STATUS_E_NOMEM;
7374 		goto free_opcls_chan_mem;
7375 	}
7376 
7377 	p_fixed_params = &temp_afc_req->fixed_params;
7378 	reg_fill_afc_fixed_params(p_fixed_params, afc_req_len);
7379 
7380 	/* frange list is already filled just copy it */
7381 	frange_lst_len = reg_get_frange_list_len(num_freq_ranges);
7382 	p_frange_lst_afc = (struct wlan_afc_frange_list *)&p_fixed_params[1];
7383 	qdf_mem_copy(p_frange_lst_afc, p_frange_lst_local, frange_lst_len);
7384 
7385 	p_num_opclasses = (struct wlan_afc_num_opclasses *)
7386 	    ((char *)(p_frange_lst_afc) + frange_lst_len);
7387 	p_num_opclasses->num_opclasses = num_opclasses;
7388 
7389 	p_obj_opclass_arr = (struct wlan_afc_opclass_obj *)&p_num_opclasses[1];
7390 	p_obj_opclass_arr = reg_fill_afc_opclasses_arr(pdev,
7391 						       num_opclasses,
7392 						       opclass_lst,
7393 						       chansize_lst,
7394 						       channel_lists,
7395 						       p_obj_opclass_arr);
7396 
7397 	p_afc_location = (struct wlan_afc_location *)p_obj_opclass_arr;
7398 	p_afc_location->deployment_type =
7399 				pdev_priv_obj->reg_afc_dev_deployment_type;
7400 	p_afc_location->afc_elem_type = AFC_OBJ_LOCATION;
7401 	p_afc_location->afc_elem_len =
7402 				sizeof(*p_afc_location) -
7403 				sizeof(p_afc_location->afc_elem_type) -
7404 				sizeof(p_afc_location->afc_elem_len);
7405 free_opcls_chan_mem:
7406 	reg_dmn_free_6g_opclasses_and_channels(pdev,
7407 					       num_opclasses,
7408 					       opclass_lst,
7409 					       chansize_lst,
7410 					       channel_lists);
7411 
7412 free_frange_lst_local:
7413 	qdf_mem_free(p_frange_lst_local);
7414 
7415 handle_invalid_priv_object:
7416 	*afc_req = temp_afc_req;
7417 
7418 	return status;
7419 }
7420 
7421 void reg_dmn_set_afc_req_id(struct wlan_afc_host_partial_request *afc_req,
7422 			    uint64_t req_id)
7423 {
7424 	struct wlan_afc_host_req_fixed_params *p_fixed_params;
7425 
7426 	p_fixed_params = &afc_req->fixed_params;
7427 	p_fixed_params->req_id = req_id;
7428 }
7429 
7430 /**
7431  * reg_send_afc_partial_request() - Send AFC partial request to registered
7432  * recipient
7433  * @pdev: Pointer to pdev
7434  * @afc_req: Pointer to afc partial request
7435  *
7436  * Return: void
7437  */
7438 static
7439 void reg_send_afc_partial_request(struct wlan_objmgr_pdev *pdev,
7440 				  struct wlan_afc_host_partial_request *afc_req)
7441 {
7442 	afc_req_rx_evt_handler cbf;
7443 	void *arg;
7444 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7445 
7446 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7447 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7448 		reg_err("pdev reg component is NULL");
7449 		return;
7450 	}
7451 
7452 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7453 	cbf = pdev_priv_obj->afc_cb_obj.func;
7454 	if (cbf) {
7455 		arg = pdev_priv_obj->afc_cb_obj.arg;
7456 		cbf(pdev, afc_req, arg);
7457 	}
7458 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7459 }
7460 
7461 QDF_STATUS reg_afc_start(struct wlan_objmgr_pdev *pdev, uint64_t req_id)
7462 {
7463 	struct wlan_afc_host_partial_request *afc_req;
7464 	QDF_STATUS status;
7465 
7466 	status = reg_get_partial_afc_req_info(pdev, &afc_req);
7467 	if (status != QDF_STATUS_SUCCESS) {
7468 		reg_err("Creating AFC Request failed");
7469 		return QDF_STATUS_E_FAILURE;
7470 	}
7471 
7472 	QDF_TRACE(QDF_MODULE_ID_AFC, QDF_TRACE_LEVEL_DEBUG,
7473 		  "Processing AFC Start/Renew Expiry event");
7474 
7475 	reg_dmn_set_afc_req_id(afc_req, req_id);
7476 
7477 	reg_print_partial_afc_req_info(pdev, afc_req);
7478 
7479 	reg_send_afc_partial_request(pdev, afc_req);
7480 
7481 	qdf_mem_free(afc_req);
7482 
7483 	return QDF_STATUS_SUCCESS;
7484 }
7485 
7486 QDF_STATUS reg_send_afc_power_event(struct wlan_objmgr_pdev *pdev,
7487 				    struct reg_fw_afc_power_event *power_info)
7488 {
7489 	afc_power_tx_evt_handler cbf;
7490 	void *arg;
7491 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7492 
7493 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7494 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7495 		reg_err("pdev reg component is NULL");
7496 		return QDF_STATUS_E_FAILURE;
7497 	}
7498 
7499 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7500 	cbf = pdev_priv_obj->afc_pow_evt_cb_obj.func;
7501 	if (cbf) {
7502 		arg = pdev_priv_obj->afc_pow_evt_cb_obj.arg;
7503 		cbf(pdev, power_info, arg);
7504 	}
7505 
7506 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7507 
7508 	return QDF_STATUS_SUCCESS;
7509 }
7510 
7511 QDF_STATUS reg_register_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
7512 					    afc_req_rx_evt_handler cbf,
7513 					    void *arg)
7514 {
7515 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7516 
7517 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7518 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7519 		reg_err("pdev reg component is NULL");
7520 		return QDF_STATUS_E_FAILURE;
7521 	}
7522 
7523 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7524 	pdev_priv_obj->afc_cb_obj.func = cbf;
7525 	pdev_priv_obj->afc_cb_obj.arg = arg;
7526 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7527 	reg_debug("afc_event_cb: 0x%pK, arg: 0x%pK", cbf, arg);
7528 
7529 	return QDF_STATUS_SUCCESS;
7530 }
7531 
7532 QDF_STATUS reg_unregister_afc_req_rx_callback(struct wlan_objmgr_pdev *pdev,
7533 					      afc_req_rx_evt_handler cbf)
7534 {
7535 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7536 
7537 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7538 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7539 		reg_err("pdev reg component is NULL");
7540 		return QDF_STATUS_E_FAILURE;
7541 	}
7542 
7543 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7544 	if (pdev_priv_obj->afc_cb_obj.func == cbf) {
7545 		pdev_priv_obj->afc_cb_obj.func = NULL;
7546 		pdev_priv_obj->afc_cb_obj.arg = NULL;
7547 	} else {
7548 		reg_err("cb function=0x%pK not found", cbf);
7549 	}
7550 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7551 
7552 	return QDF_STATUS_SUCCESS;
7553 }
7554 
7555 QDF_STATUS
7556 reg_register_afc_power_event_callback(struct wlan_objmgr_pdev *pdev,
7557 				      afc_power_tx_evt_handler cbf,
7558 				      void *arg)
7559 {
7560 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7561 
7562 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7563 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7564 		reg_err("pdev reg component is NULL");
7565 		return QDF_STATUS_E_FAILURE;
7566 	}
7567 
7568 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7569 	pdev_priv_obj->afc_pow_evt_cb_obj.func = cbf;
7570 	pdev_priv_obj->afc_pow_evt_cb_obj.arg = arg;
7571 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7572 	reg_debug("afc_power_event_cb: 0x%pK, arg: 0x%pK", cbf, arg);
7573 
7574 	return QDF_STATUS_SUCCESS;
7575 }
7576 
7577 QDF_STATUS
7578 reg_unregister_afc_power_event_callback(struct wlan_objmgr_pdev *pdev,
7579 					afc_power_tx_evt_handler cbf)
7580 {
7581 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7582 
7583 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7584 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7585 		reg_err("pdev reg component is NULL");
7586 		return QDF_STATUS_E_FAILURE;
7587 	}
7588 
7589 	qdf_spin_lock_bh(&pdev_priv_obj->afc_cb_lock);
7590 	if (pdev_priv_obj->afc_pow_evt_cb_obj.func == cbf) {
7591 		pdev_priv_obj->afc_pow_evt_cb_obj.func = NULL;
7592 		pdev_priv_obj->afc_pow_evt_cb_obj.arg = NULL;
7593 	} else {
7594 		reg_err("cb function=0x%pK not found", cbf);
7595 	}
7596 	qdf_spin_unlock_bh(&pdev_priv_obj->afc_cb_lock);
7597 
7598 	return QDF_STATUS_SUCCESS;
7599 }
7600 
7601 QDF_STATUS
7602 reg_get_afc_dev_deploy_type(struct wlan_objmgr_pdev *pdev,
7603 			    enum reg_afc_dev_deploy_type *reg_afc_dev_type)
7604 {
7605 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7606 
7607 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7608 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7609 		reg_err("pdev reg component is NULL");
7610 		return QDF_STATUS_E_FAILURE;
7611 	}
7612 
7613 	*reg_afc_dev_type = pdev_priv_obj->reg_afc_dev_deployment_type;
7614 
7615 	return QDF_STATUS_SUCCESS;
7616 }
7617 
7618 bool
7619 reg_is_sta_connect_allowed(struct wlan_objmgr_pdev *pdev,
7620 			   enum reg_6g_ap_type root_ap_pwr_mode)
7621 {
7622 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7623 
7624 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7625 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7626 		reg_err("pdev reg component is NULL");
7627 		return false;
7628 	}
7629 
7630 	if (reg_get_num_rules_of_ap_pwr_type(pdev, REG_STANDARD_POWER_AP) &&
7631 	    (pdev_priv_obj->reg_afc_dev_deployment_type == AFC_DEPLOYMENT_OUTDOOR)) {
7632 		if (root_ap_pwr_mode == REG_STANDARD_POWER_AP)
7633 			return true;
7634 		else
7635 			return false;
7636 	}
7637 
7638 	return true;
7639 }
7640 
7641 QDF_STATUS reg_set_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc,
7642 				    enum reg_afc_dev_deploy_type
7643 				    reg_afc_dev_type)
7644 {
7645 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7646 
7647 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7648 
7649 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7650 		reg_err("psoc reg component is NULL");
7651 		return QDF_STATUS_E_FAILURE;
7652 	}
7653 
7654 	psoc_priv_obj->reg_afc_dev_type = reg_afc_dev_type;
7655 
7656 	return QDF_STATUS_SUCCESS;
7657 }
7658 
7659 QDF_STATUS
7660 reg_get_afc_soc_dev_type(struct wlan_objmgr_psoc *psoc,
7661 			 enum reg_afc_dev_deploy_type *reg_afc_dev_type)
7662 {
7663 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7664 
7665 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7666 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7667 		reg_err("psoc reg component is NULL");
7668 		return QDF_STATUS_E_FAILURE;
7669 	}
7670 
7671 	*reg_afc_dev_type = psoc_priv_obj->reg_afc_dev_type;
7672 
7673 	return QDF_STATUS_SUCCESS;
7674 }
7675 #endif /* CONFIG_AFC_SUPPORT */
7676 
7677 QDF_STATUS
7678 reg_get_cur_6g_client_type(struct wlan_objmgr_pdev *pdev,
7679 			   enum reg_6g_client_type
7680 			   *reg_cur_6g_client_mobility_type)
7681 {
7682 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7683 
7684 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7685 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7686 		reg_err("pdev reg component is NULL");
7687 		return QDF_STATUS_E_FAILURE;
7688 	}
7689 
7690 	if (pdev_priv_obj->reg_cur_6g_client_mobility_type >=
7691 	    REG_MAX_CLIENT_TYPE)
7692 		return QDF_STATUS_E_FAILURE;
7693 
7694 	*reg_cur_6g_client_mobility_type =
7695 	    pdev_priv_obj->reg_cur_6g_client_mobility_type;
7696 
7697 	return QDF_STATUS_SUCCESS;
7698 }
7699 
7700 QDF_STATUS reg_get_rnr_tpe_usable(struct wlan_objmgr_pdev *pdev,
7701 				  bool *reg_rnr_tpe_usable)
7702 {
7703 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7704 
7705 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7706 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7707 		reg_err("pdev reg component is NULL");
7708 		return QDF_STATUS_E_FAILURE;
7709 	}
7710 	*reg_rnr_tpe_usable = pdev_priv_obj->reg_rnr_tpe_usable;
7711 	return QDF_STATUS_SUCCESS;
7712 }
7713 
7714 QDF_STATUS reg_get_unspecified_ap_usable(struct wlan_objmgr_pdev *pdev,
7715 					 bool *reg_unspecified_ap_usable)
7716 {
7717 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7718 
7719 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7720 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7721 		reg_err("pdev reg component is NULL");
7722 		return QDF_STATUS_E_FAILURE;
7723 	}
7724 	*reg_unspecified_ap_usable = pdev_priv_obj->reg_unspecified_ap_usable;
7725 	return QDF_STATUS_SUCCESS;
7726 }
7727 
7728 QDF_STATUS
7729 reg_find_txpower_from_6g_list(qdf_freq_t freq,
7730 			      struct regulatory_channel *chan_list,
7731 			      uint16_t *txpower)
7732 {
7733 	enum channel_enum chan_enum;
7734 
7735 	*txpower = 0;
7736 
7737 	for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) {
7738 		if (chan_list[chan_enum].center_freq == freq) {
7739 			*txpower = chan_list[chan_enum].tx_power;
7740 			return QDF_STATUS_SUCCESS;
7741 		}
7742 	}
7743 
7744 	return QDF_STATUS_E_FAILURE;
7745 }
7746 
7747 bool reg_is_6g_psd_power(struct wlan_objmgr_pdev *pdev)
7748 {
7749 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7750 	struct regulatory_channel *cur_chan_list;
7751 	enum channel_enum i;
7752 
7753 	if (!pdev) {
7754 		reg_err("pdev is NULL");
7755 		return false;
7756 	}
7757 
7758 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7759 	if (!pdev_priv_obj) {
7760 		reg_err("pdev priv obj is NULL");
7761 		return false;
7762 	}
7763 
7764 	cur_chan_list = pdev_priv_obj->cur_chan_list;
7765 
7766 	for (i = MIN_6GHZ_CHANNEL; i <= MAX_6GHZ_CHANNEL; i++) {
7767 		if (!(cur_chan_list[i].chan_flags & REGULATORY_CHAN_DISABLED))
7768 			return cur_chan_list[i].psd_flag;
7769 	}
7770 
7771 	return false;
7772 }
7773 
7774 QDF_STATUS
7775 reg_get_6g_chan_psd_eirp_power(qdf_freq_t freq,
7776 			       struct regulatory_channel *mas_chan_list,
7777 			       uint16_t *eirp_psd_power)
7778 {
7779 	uint16_t i;
7780 
7781 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
7782 		if (freq == mas_chan_list[i].center_freq) {
7783 			*eirp_psd_power = mas_chan_list[i].psd_eirp;
7784 			return QDF_STATUS_SUCCESS;
7785 		}
7786 	}
7787 
7788 	return QDF_STATUS_E_FAILURE;
7789 }
7790 
7791 QDF_STATUS reg_get_6g_chan_ap_power(struct wlan_objmgr_pdev *pdev,
7792 				    qdf_freq_t chan_freq, bool *is_psd,
7793 				    uint16_t *tx_power,
7794 				    uint16_t *eirp_psd_power)
7795 {
7796 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7797 	struct regulatory_channel *master_chan_list;
7798 	enum reg_6g_ap_type ap_pwr_type;
7799 	QDF_STATUS status = QDF_STATUS_SUCCESS;
7800 
7801 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7802 	if (!pdev_priv_obj) {
7803 		reg_err("pdev priv obj is NULL");
7804 		return QDF_STATUS_E_FAILURE;
7805 	}
7806 
7807 	status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type);
7808 	if (!QDF_IS_STATUS_SUCCESS(status))
7809 		return status;
7810 
7811 	master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type];
7812 
7813 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
7814 				      tx_power);
7815 
7816 	*is_psd = reg_is_6g_psd_power(pdev);
7817 	if (*is_psd)
7818 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
7819 							master_chan_list,
7820 							eirp_psd_power);
7821 
7822 	return status;
7823 }
7824 
7825 QDF_STATUS reg_get_client_power_for_connecting_ap(struct wlan_objmgr_pdev *pdev,
7826 						  enum reg_6g_ap_type ap_type,
7827 						  qdf_freq_t chan_freq,
7828 						  bool is_psd,
7829 						  uint16_t *tx_power,
7830 						  uint16_t *eirp_psd_power)
7831 {
7832 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7833 	enum reg_6g_client_type client_type;
7834 	struct regulatory_channel *master_chan_list;
7835 	QDF_STATUS status = QDF_STATUS_SUCCESS;
7836 
7837 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7838 	if (!pdev_priv_obj) {
7839 		reg_err("pdev priv obj is NULL");
7840 		return QDF_STATUS_E_FAILURE;
7841 	}
7842 
7843 	reg_get_cur_6g_client_type(pdev, &client_type);
7844 
7845 	master_chan_list =
7846 		pdev_priv_obj->mas_chan_list_6g_client[ap_type][client_type];
7847 
7848 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
7849 				      tx_power);
7850 
7851 	if (is_psd)
7852 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
7853 							master_chan_list,
7854 							eirp_psd_power);
7855 
7856 	return status;
7857 }
7858 
7859 QDF_STATUS reg_get_client_power_for_6ghz_ap(struct wlan_objmgr_pdev *pdev,
7860 					    enum reg_6g_client_type client_type,
7861 					    qdf_freq_t chan_freq,
7862 					    bool *is_psd, uint16_t *tx_power,
7863 					    uint16_t *eirp_psd_power)
7864 {
7865 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7866 	enum reg_6g_ap_type ap_pwr_type;
7867 	struct regulatory_channel *master_chan_list;
7868 	QDF_STATUS status = QDF_STATUS_SUCCESS;
7869 
7870 	status = reg_get_cur_6g_ap_pwr_type(pdev, &ap_pwr_type);
7871 	if (!QDF_IS_STATUS_SUCCESS(status))
7872 		return status;
7873 
7874 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7875 	if (!pdev_priv_obj) {
7876 		reg_err("pdev priv obj is NULL");
7877 		return QDF_STATUS_E_FAILURE;
7878 	}
7879 
7880 	master_chan_list = pdev_priv_obj->
7881 			mas_chan_list_6g_client[ap_pwr_type][client_type];
7882 
7883 	reg_find_txpower_from_6g_list(chan_freq, master_chan_list,
7884 				      tx_power);
7885 
7886 	*is_psd = reg_is_6g_psd_power(pdev);
7887 	if (*is_psd)
7888 		status = reg_get_6g_chan_psd_eirp_power(chan_freq,
7889 							master_chan_list,
7890 							eirp_psd_power);
7891 
7892 	return status;
7893 }
7894 
7895 QDF_STATUS reg_set_ap_pwr_and_update_chan_list(struct wlan_objmgr_pdev *pdev,
7896 					       enum reg_6g_ap_type ap_pwr_type)
7897 {
7898 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
7899 	QDF_STATUS status;
7900 
7901 	pdev_priv_obj = reg_get_pdev_obj(pdev);
7902 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
7903 		reg_err("pdev reg component is NULL");
7904 		return QDF_STATUS_E_INVAL;
7905 	}
7906 
7907 	if (!reg_get_num_rules_of_ap_pwr_type(pdev, ap_pwr_type))
7908 		return QDF_STATUS_E_FAILURE;
7909 
7910 	status = reg_set_cur_6g_ap_pwr_type(pdev, ap_pwr_type);
7911 	if (QDF_IS_STATUS_ERROR(status)) {
7912 		reg_debug("failed to set AP power type to %d", ap_pwr_type);
7913 		return status;
7914 	}
7915 
7916 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
7917 
7918 	return QDF_STATUS_SUCCESS;
7919 }
7920 #endif
7921 
7922 bool reg_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc)
7923 {
7924 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7925 
7926 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7927 	if (!psoc_priv_obj) {
7928 		reg_err("reg psoc private obj is NULL");
7929 		return false;
7930 	}
7931 
7932 	return psoc_priv_obj->offload_enabled;
7933 }
7934 
7935 QDF_STATUS
7936 reg_set_ext_tpc_supported(struct wlan_objmgr_psoc *psoc, bool val)
7937 {
7938 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7939 
7940 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7941 
7942 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7943 		reg_err("psoc reg component is NULL");
7944 		return QDF_STATUS_E_FAILURE;
7945 	}
7946 
7947 	psoc_priv_obj->is_ext_tpc_supported = val;
7948 
7949 	return QDF_STATUS_SUCCESS;
7950 }
7951 
7952 bool reg_is_ext_tpc_supported(struct wlan_objmgr_psoc *psoc)
7953 {
7954 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7955 
7956 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7957 
7958 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7959 		reg_err("psoc reg component is NULL");
7960 		return  false;
7961 	}
7962 
7963 	return psoc_priv_obj->is_ext_tpc_supported;
7964 }
7965 
7966 #if defined(CONFIG_BAND_6GHZ)
7967 QDF_STATUS
7968 reg_set_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val)
7969 {
7970 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7971 
7972 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7973 
7974 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7975 		reg_err("psoc reg component is NULL");
7976 		return QDF_STATUS_E_FAILURE;
7977 	}
7978 
7979 	psoc_priv_obj->is_lower_6g_edge_ch_supported = val;
7980 
7981 	return QDF_STATUS_SUCCESS;
7982 }
7983 
7984 QDF_STATUS
7985 reg_set_disable_upper_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc, bool val)
7986 {
7987 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
7988 
7989 	psoc_priv_obj = reg_get_psoc_obj(psoc);
7990 
7991 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
7992 		reg_err("psoc reg component is NULL");
7993 		return QDF_STATUS_E_FAILURE;
7994 	}
7995 
7996 	psoc_priv_obj->is_upper_6g_edge_ch_disabled = val;
7997 
7998 	return QDF_STATUS_SUCCESS;
7999 }
8000 
8001 bool reg_is_lower_6g_edge_ch_supp(struct wlan_objmgr_psoc *psoc)
8002 {
8003 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8004 
8005 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8006 
8007 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
8008 		reg_err("psoc reg component is NULL");
8009 		return  false;
8010 	}
8011 
8012 	return psoc_priv_obj->is_lower_6g_edge_ch_supported;
8013 }
8014 
8015 bool reg_is_upper_6g_edge_ch_disabled(struct wlan_objmgr_psoc *psoc)
8016 {
8017 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8018 
8019 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8020 
8021 	if (!IS_VALID_PSOC_REG_OBJ(psoc_priv_obj)) {
8022 		reg_err("psoc reg component is NULL");
8023 		return  false;
8024 	}
8025 
8026 	return psoc_priv_obj->is_upper_6g_edge_ch_disabled;
8027 }
8028 
8029 static inline bool reg_is_within_range_inclusive(enum channel_enum left,
8030 						 enum channel_enum right,
8031 						 enum channel_enum idx)
8032 {
8033 	return (idx >= left) && (idx <= right);
8034 }
8035 
8036 uint16_t reg_convert_enum_to_6g_idx(enum channel_enum ch_idx)
8037 {
8038 	if (!reg_is_within_range_inclusive(MIN_6GHZ_CHANNEL,
8039 					   MAX_6GHZ_CHANNEL,
8040 					   ch_idx))
8041 		return INVALID_CHANNEL;
8042 
8043 	return (ch_idx - MIN_6GHZ_CHANNEL);
8044 }
8045 
8046 QDF_STATUS
8047 reg_get_superchan_entry(struct wlan_objmgr_pdev *pdev,
8048 			enum channel_enum chan_enum,
8049 			const struct super_chan_info **p_sup_chan_entry)
8050 {
8051 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8052 	uint16_t sup_idx;
8053 
8054 	sup_idx = reg_convert_enum_to_6g_idx(chan_enum);
8055 
8056 	if (reg_is_chan_enum_invalid(sup_idx)) {
8057 		reg_debug("super channel idx is invalid for the chan_enum %d",
8058 			  chan_enum);
8059 		return QDF_STATUS_E_INVAL;
8060 	}
8061 
8062 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8063 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8064 		reg_err_rl("pdev reg component is NULL");
8065 		return QDF_STATUS_E_INVAL;
8066 	}
8067 
8068 	if (!p_sup_chan_entry) {
8069 		reg_err_rl("p_sup_chan_entry is NULL");
8070 		return QDF_STATUS_E_INVAL;
8071 	}
8072 
8073 	if (sup_idx >= NUM_6GHZ_CHANNELS) {
8074 		reg_debug("sup_idx is out of bounds");
8075 		return QDF_STATUS_E_INVAL;
8076 	}
8077 
8078 	*p_sup_chan_entry = &pdev_priv_obj->super_chan_list[sup_idx];
8079 
8080 	return QDF_STATUS_SUCCESS;
8081 }
8082 #endif
8083 
8084 #ifdef FEATURE_WLAN_CH_AVOID_EXT
8085 /**
8086  * reg_process_ch_avoid_freq_ext() - Update extended avoid frequencies in
8087  * psoc_priv_obj
8088  * @psoc: Pointer to psoc structure
8089  * @pdev: pointer to pdev object
8090  *
8091  * Return: None
8092  */
8093 static QDF_STATUS
8094 reg_process_ch_avoid_freq_ext(struct wlan_objmgr_psoc *psoc,
8095 			      struct wlan_objmgr_pdev *pdev)
8096 {
8097 	uint32_t i;
8098 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8099 	uint8_t start_channel;
8100 	uint8_t end_channel;
8101 	int32_t txpower;
8102 	bool is_valid_txpower;
8103 	struct ch_avoid_freq_type *range;
8104 	enum channel_enum ch_loop;
8105 	enum channel_enum start_ch_idx;
8106 	enum channel_enum end_ch_idx;
8107 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8108 	uint32_t len;
8109 	struct unsafe_ch_list *unsafe_ch_list;
8110 	bool coex_unsafe_nb_user_prefer;
8111 
8112 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8113 
8114 	if (!pdev_priv_obj) {
8115 		reg_err("reg pdev private obj is NULL");
8116 		return QDF_STATUS_E_FAILURE;
8117 	}
8118 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8119 	if (!psoc_priv_obj) {
8120 		reg_err("reg psoc private obj is NULL");
8121 		return QDF_STATUS_E_FAILURE;
8122 	}
8123 
8124 	unsafe_ch_list = &psoc_priv_obj->unsafe_chan_list;
8125 	coex_unsafe_nb_user_prefer =
8126 		psoc_priv_obj->coex_unsafe_chan_nb_user_prefer;
8127 
8128 	if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt > 0) {
8129 		len = sizeof(pdev_priv_obj->avoid_chan_ext_list.chan_freq_list);
8130 		pdev_priv_obj->avoid_chan_ext_list.chan_cnt = 0;
8131 		qdf_mem_zero(&pdev_priv_obj->avoid_chan_ext_list.chan_freq_list,
8132 			     len);
8133 	}
8134 
8135 	if (unsafe_ch_list->chan_cnt > 0) {
8136 		len = sizeof(unsafe_ch_list->chan_freq_list);
8137 		unsafe_ch_list->chan_cnt = 0;
8138 		qdf_mem_zero(unsafe_ch_list->chan_freq_list, len);
8139 	}
8140 
8141 	for (i = 0; i < psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt;
8142 		i++) {
8143 		if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >=
8144 		    NUM_CHANNELS) {
8145 			reg_debug("ext avoid channel list full");
8146 			break;
8147 		}
8148 
8149 		if (unsafe_ch_list->chan_cnt >= NUM_CHANNELS) {
8150 			reg_warn("LTE Coex unsafe channel list full");
8151 			break;
8152 		}
8153 
8154 		start_ch_idx = INVALID_CHANNEL;
8155 		end_ch_idx = INVALID_CHANNEL;
8156 		range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i];
8157 
8158 		start_channel = reg_freq_to_chan(pdev, range->start_freq);
8159 		end_channel = reg_freq_to_chan(pdev, range->end_freq);
8160 		txpower = range->txpower;
8161 		is_valid_txpower = range->is_valid_txpower;
8162 
8163 		reg_debug("start: freq %d, ch %d, end: freq %d, ch %d txpower %d",
8164 			  range->start_freq, start_channel, range->end_freq,
8165 			  end_channel, txpower);
8166 
8167 		/* do not process frequency bands that are not mapped to
8168 		 * predefined channels
8169 		 */
8170 		if (start_channel == 0 || end_channel == 0)
8171 			continue;
8172 
8173 		for (ch_loop = 0; ch_loop < NUM_CHANNELS;
8174 			ch_loop++) {
8175 			if (REG_CH_TO_FREQ(ch_loop) >= range->start_freq) {
8176 				start_ch_idx = ch_loop;
8177 				break;
8178 			}
8179 		}
8180 		for (ch_loop = 0; ch_loop < NUM_CHANNELS;
8181 			ch_loop++) {
8182 			if (REG_CH_TO_FREQ(ch_loop) >= range->end_freq) {
8183 				end_ch_idx = ch_loop;
8184 				if (REG_CH_TO_FREQ(ch_loop) > range->end_freq)
8185 					end_ch_idx--;
8186 				break;
8187 			}
8188 		}
8189 
8190 		if (reg_is_chan_enum_invalid(start_ch_idx) ||
8191 		    reg_is_chan_enum_invalid(end_ch_idx))
8192 			continue;
8193 
8194 		for (ch_loop = start_ch_idx; ch_loop <= end_ch_idx;
8195 			ch_loop++) {
8196 			pdev_priv_obj->avoid_chan_ext_list.chan_freq_list
8197 			[pdev_priv_obj->avoid_chan_ext_list.chan_cnt++] =
8198 			REG_CH_TO_FREQ(ch_loop);
8199 
8200 			if (coex_unsafe_nb_user_prefer) {
8201 				if (unsafe_ch_list->chan_cnt >=
8202 					NUM_CHANNELS) {
8203 					reg_warn("LTECoex unsafe ch list full");
8204 					break;
8205 				}
8206 				unsafe_ch_list->txpower[
8207 				unsafe_ch_list->chan_cnt] =
8208 					txpower;
8209 				unsafe_ch_list->is_valid_txpower[
8210 				unsafe_ch_list->chan_cnt] =
8211 					is_valid_txpower;
8212 				unsafe_ch_list->chan_freq_list[
8213 				unsafe_ch_list->chan_cnt++] =
8214 					REG_CH_TO_FREQ(ch_loop);
8215 			}
8216 
8217 			if (pdev_priv_obj->avoid_chan_ext_list.chan_cnt >=
8218 				NUM_CHANNELS) {
8219 				reg_debug("avoid freq ext list full");
8220 				break;
8221 			}
8222 		}
8223 		/* if start == end for 5G, meanwhile it only have one valid
8224 		 * channel updated, then disable 20M by default around
8225 		 * this center freq. For example input [5805-5805], it
8226 		 * will disable 20Mhz around 5805, then the range change
8227 		 * to [5705-5815], otherwise, not sure about how many width
8228 		 * need to disabled for such case.
8229 		 */
8230 		if ((ch_loop - start_ch_idx) == 1 &&
8231 		    (range->end_freq - range->start_freq == 0) &&
8232 			reg_is_5ghz_ch_freq(range->start_freq)) {
8233 			range->start_freq = range->start_freq - HALF_20MHZ_BW;
8234 			range->end_freq = range->end_freq + HALF_20MHZ_BW;
8235 		}
8236 
8237 		for (ch_loop = 0; ch_loop <
8238 			unsafe_ch_list->chan_cnt; ch_loop++) {
8239 			if (ch_loop >= NUM_CHANNELS)
8240 				break;
8241 			reg_debug("Unsafe freq %d",
8242 				  unsafe_ch_list->chan_freq_list[ch_loop]);
8243 		}
8244 	}
8245 
8246 	return QDF_STATUS_SUCCESS;
8247 }
8248 
8249 /**
8250  * reg_update_avoid_ch_ext() - Updates the current channel list that block out
8251  * by extended avoid frequency list
8252  * @psoc: Pointer to psoc structure
8253  * @object: Pointer to pdev structure
8254  * @arg: List of arguments
8255  *
8256  * Return: None
8257  */
8258 static void
8259 reg_update_avoid_ch_ext(struct wlan_objmgr_psoc *psoc,
8260 			void *object, void *arg)
8261 {
8262 	struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object;
8263 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8264 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8265 	QDF_STATUS status;
8266 
8267 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8268 	if (!psoc_priv_obj) {
8269 		reg_err("reg psoc private obj is NULL");
8270 		return;
8271 	}
8272 
8273 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8274 
8275 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8276 		reg_err("reg pdev priv obj is NULL");
8277 		return;
8278 	}
8279 
8280 	if (psoc_priv_obj->ch_avoid_ext_ind) {
8281 		status = reg_process_ch_avoid_freq_ext(psoc, pdev);
8282 		if (QDF_IS_STATUS_ERROR(status))
8283 			psoc_priv_obj->ch_avoid_ext_ind = false;
8284 	}
8285 
8286 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
8287 	status = reg_send_scheduler_msg_sb(psoc, pdev);
8288 
8289 	if (QDF_IS_STATUS_ERROR(status))
8290 		reg_err("channel change msg schedule failed");
8291 }
8292 
8293 QDF_STATUS
8294 reg_process_ch_avoid_ext_event(struct wlan_objmgr_psoc *psoc,
8295 			       struct ch_avoid_ind_type *ch_avoid_event)
8296 {
8297 	uint32_t i;
8298 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8299 	QDF_STATUS status;
8300 	struct ch_avoid_freq_type *range;
8301 
8302 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8303 	if (!psoc_priv_obj) {
8304 		reg_err("reg psoc private obj is NULL");
8305 		return QDF_STATUS_E_FAILURE;
8306 	}
8307 
8308 	reg_debug("freq range count %d", ch_avoid_event->ch_avoid_range_cnt);
8309 
8310 	qdf_mem_zero(&psoc_priv_obj->avoid_freq_ext_list,
8311 		     sizeof(struct ch_avoid_ind_type));
8312 
8313 	for (i = 0; i < ch_avoid_event->ch_avoid_range_cnt; i++) {
8314 		range = &psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range[i];
8315 		range->start_freq =
8316 			ch_avoid_event->avoid_freq_range[i].start_freq;
8317 		range->end_freq =
8318 			ch_avoid_event->avoid_freq_range[i].end_freq;
8319 		range->txpower =
8320 			ch_avoid_event->avoid_freq_range[i].txpower;
8321 		range->is_valid_txpower =
8322 			ch_avoid_event->avoid_freq_range[i].is_valid_txpower;
8323 	}
8324 
8325 	psoc_priv_obj->avoid_freq_ext_list.restriction_mask =
8326 		ch_avoid_event->restriction_mask;
8327 	psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt =
8328 		ch_avoid_event->ch_avoid_range_cnt;
8329 
8330 	psoc_priv_obj->ch_avoid_ext_ind = true;
8331 
8332 	status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_REGULATORY_SB_ID);
8333 
8334 	if (QDF_IS_STATUS_ERROR(status)) {
8335 		reg_err("error taking psoc ref cnt");
8336 		return status;
8337 	}
8338 
8339 	status = wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP,
8340 					      reg_update_avoid_ch_ext,
8341 					      NULL, 1,
8342 					      WLAN_REGULATORY_SB_ID);
8343 
8344 	wlan_objmgr_psoc_release_ref(psoc, WLAN_REGULATORY_SB_ID);
8345 
8346 	return status;
8347 }
8348 
8349 bool reg_check_coex_unsafe_nb_user_prefer(struct wlan_objmgr_psoc *psoc)
8350 {
8351 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8352 
8353 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8354 	if (!psoc_priv_obj) {
8355 		reg_err("reg psoc private obj is NULL");
8356 		return false;
8357 	}
8358 
8359 	return psoc_priv_obj->coex_unsafe_chan_nb_user_prefer;
8360 }
8361 
8362 bool reg_check_coex_unsafe_chan_reg_disable(struct wlan_objmgr_psoc *psoc)
8363 {
8364 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
8365 
8366 	psoc_priv_obj = reg_get_psoc_obj(psoc);
8367 	if (!psoc_priv_obj) {
8368 		reg_err("reg psoc private obj is NULL");
8369 		return false;
8370 	}
8371 
8372 	return psoc_priv_obj->coex_unsafe_chan_reg_disable;
8373 }
8374 #endif
8375 
8376 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
8377 QDF_STATUS reg_send_afc_cmd(struct wlan_objmgr_pdev *pdev,
8378 			    struct reg_afc_resp_rx_ind_info *afc_ind_obj)
8379 {
8380 	uint8_t pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
8381 	struct wlan_objmgr_psoc *psoc;
8382 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
8383 
8384 	psoc = wlan_pdev_get_psoc(pdev);
8385 	if (!psoc) {
8386 		reg_err("psoc is NULL");
8387 		return QDF_STATUS_E_INVAL;
8388 	}
8389 
8390 	tx_ops = reg_get_psoc_tx_ops(psoc);
8391 	if (tx_ops->send_afc_ind)
8392 		return tx_ops->send_afc_ind(psoc, pdev_id, afc_ind_obj);
8393 
8394 	return QDF_STATUS_E_FAILURE;
8395 }
8396 
8397 bool reg_is_afc_power_event_received(struct wlan_objmgr_pdev *pdev)
8398 {
8399 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8400 
8401 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8402 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8403 		reg_err("pdev reg component is NULL");
8404 		return false;
8405 	}
8406 
8407 	return pdev_priv_obj->is_6g_afc_power_event_received;
8408 }
8409 
8410 bool reg_is_afc_done(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
8411 {
8412 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8413 	uint32_t chan_flags;
8414 
8415 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8416 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8417 		reg_err("pdev reg component is NULL");
8418 		return false;
8419 	}
8420 
8421 	chan_flags = reg_get_channel_flags_for_freq(pdev, freq);
8422 
8423 	return !(chan_flags & REGULATORY_CHAN_AFC_NOT_DONE);
8424 }
8425 
8426 QDF_STATUS reg_get_afc_req_id(struct wlan_objmgr_pdev *pdev, uint64_t *req_id)
8427 {
8428 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8429 
8430 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8431 
8432 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8433 		reg_err("reg pdev priv obj is NULL");
8434 		return QDF_STATUS_E_FAILURE;
8435 	}
8436 
8437 	*req_id = pdev_priv_obj->afc_request_id;
8438 
8439 	return QDF_STATUS_SUCCESS;
8440 }
8441 
8442 bool reg_is_afc_expiry_event_received(struct wlan_objmgr_pdev *pdev)
8443 {
8444 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8445 
8446 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8447 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8448 		reg_err("pdev reg component is NULL");
8449 		return false;
8450 	}
8451 
8452 	return pdev_priv_obj->is_6g_afc_expiry_event_received;
8453 }
8454 
8455 bool reg_is_noaction_on_afc_pwr_evt(struct wlan_objmgr_pdev *pdev)
8456 {
8457 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8458 
8459 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8460 
8461 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8462 		reg_err("reg pdev priv obj is NULL");
8463 		return QDF_STATUS_E_FAILURE;
8464 	}
8465 
8466 	return pdev_priv_obj->is_reg_noaction_on_afc_pwr_evt;
8467 }
8468 #endif
8469 
8470 /**
8471  * struct bw_wireless_modes_pair - structure containing bandwidth and wireless
8472  * modes corresponding to the bandwidth
8473  * @ch_width: channel width
8474  * @wireless_modes: wireless modes bitmap corresponding to @ch_width. This
8475  * bitmap is a combination of enum values HOST_REGDMN_MODE
8476  */
8477 struct bw_wireless_modes_pair {
8478 	enum phy_ch_width ch_width;
8479 	uint64_t wireless_modes;
8480 };
8481 
8482 /* Mapping of bandwidth to wireless modes */
8483 static const struct bw_wireless_modes_pair bw_wireless_modes_pair_map[] = {
8484 #ifdef WLAN_FEATURE_11BE
8485 	{CH_WIDTH_320MHZ, WIRELESS_320_MODES},
8486 #endif
8487 	{CH_WIDTH_80P80MHZ, WIRELESS_80P80_MODES},
8488 	{CH_WIDTH_160MHZ, WIRELESS_160_MODES},
8489 	{CH_WIDTH_80MHZ, WIRELESS_80_MODES},
8490 	{CH_WIDTH_40MHZ, WIRELESS_40_MODES},
8491 	{CH_WIDTH_20MHZ, WIRELESS_20_MODES},
8492 	{CH_WIDTH_10MHZ, WIRELESS_10_MODES},
8493 	{CH_WIDTH_5MHZ, WIRELESS_5_MODES},
8494 };
8495 
8496 QDF_STATUS reg_is_chwidth_supported(struct wlan_objmgr_pdev *pdev,
8497 				    enum phy_ch_width ch_width,
8498 				    bool *is_supported)
8499 {
8500 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8501 	uint64_t wireless_modes;
8502 	uint8_t num_bws, idx;
8503 
8504 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8505 
8506 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8507 		reg_err("reg pdev priv obj is NULL");
8508 		return QDF_STATUS_E_FAILURE;
8509 	}
8510 
8511 	*is_supported = false;
8512 
8513 	wireless_modes = pdev_priv_obj->wireless_modes;
8514 	num_bws = QDF_ARRAY_SIZE(bw_wireless_modes_pair_map);
8515 
8516 	for (idx = 0; idx < num_bws; ++idx) {
8517 		if (bw_wireless_modes_pair_map[idx].ch_width == ch_width) {
8518 			*is_supported = !!(wireless_modes &
8519 					   bw_wireless_modes_pair_map[idx].wireless_modes);
8520 			break;
8521 		}
8522 	}
8523 
8524 	return QDF_STATUS_SUCCESS;
8525 }
8526 
8527 bool reg_is_state_allowed(enum channel_state chan_state)
8528 {
8529 	return !((chan_state == CHANNEL_STATE_INVALID) ||
8530 		 (chan_state == CHANNEL_STATE_DISABLE));
8531 }
8532 
8533 static bool
8534 reg_is_freq_idx_enabled_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
8535 					 *pdev_priv_obj,
8536 					 enum channel_enum freq_idx)
8537 {
8538 	struct regulatory_channel *cur_chan_list;
8539 
8540 	if (freq_idx >= NUM_CHANNELS)
8541 		return false;
8542 
8543 	cur_chan_list = pdev_priv_obj->cur_chan_list;
8544 
8545 	return !reg_is_chan_disabled_and_not_nol(&cur_chan_list[freq_idx]);
8546 }
8547 
8548 static QDF_STATUS
8549 reg_get_min_max_bw_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
8550 				*pdev_priv_obj,
8551 				enum channel_enum freq_idx,
8552 				uint16_t *min_bw,
8553 				uint16_t *max_bw)
8554 {
8555 	struct regulatory_channel *cur_chan_list;
8556 
8557 	if (freq_idx >= NUM_CHANNELS)
8558 		return QDF_STATUS_E_FAILURE;
8559 
8560 	cur_chan_list = pdev_priv_obj->cur_chan_list;
8561 	if (min_bw)
8562 		*min_bw = cur_chan_list[freq_idx].min_bw;
8563 	if (max_bw)
8564 		*max_bw = cur_chan_list[freq_idx].max_bw;
8565 
8566 	return QDF_STATUS_SUCCESS;
8567 }
8568 
8569 static enum channel_state
8570 reg_get_chan_state_on_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
8571 				    *pdev_priv_obj,
8572 				    enum channel_enum freq_idx)
8573 {
8574 	struct regulatory_channel *cur_chan_list;
8575 	enum channel_state chan_state;
8576 
8577 	if (freq_idx >= NUM_CHANNELS)
8578 		return CHANNEL_STATE_INVALID;
8579 
8580 	cur_chan_list = pdev_priv_obj->cur_chan_list;
8581 	chan_state = cur_chan_list[freq_idx].state;
8582 
8583 	return chan_state;
8584 }
8585 
8586 static enum channel_state
8587 reg_get_chan_state_based_on_nol_flag_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
8588 						   *pdev_priv_obj,
8589 						   enum channel_enum freq_idx)
8590 {
8591 	struct regulatory_channel *cur_chan_list;
8592 	enum channel_state chan_state;
8593 
8594 	if (freq_idx >= NUM_CHANNELS)
8595 		return CHANNEL_STATE_INVALID;
8596 
8597 	cur_chan_list = pdev_priv_obj->cur_chan_list;
8598 	chan_state = cur_chan_list[freq_idx].state;
8599 
8600 	if ((cur_chan_list[freq_idx].nol_chan ||
8601 	     cur_chan_list[freq_idx].nol_history) &&
8602 	     chan_state == CHANNEL_STATE_DISABLE)
8603 		chan_state = CHANNEL_STATE_DFS;
8604 
8605 	return chan_state;
8606 }
8607 
8608 #ifdef CONFIG_BAND_6GHZ
8609 static inline bool
8610 reg_is_supr_entry_mode_disabled(const struct super_chan_info *super_chan_ent,
8611 				enum supported_6g_pwr_types in_6g_pwr_mode)
8612 {
8613 	return ((super_chan_ent->chan_flags_arr[in_6g_pwr_mode] &
8614 		 REGULATORY_CHAN_DISABLED) &&
8615 		super_chan_ent->state_arr[in_6g_pwr_mode] ==
8616 		CHANNEL_STATE_DISABLE);
8617 }
8618 
8619 static bool
8620 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8621 					  *pdev_priv_obj,
8622 					  enum channel_enum freq_idx,
8623 					  enum supported_6g_pwr_types
8624 					  in_6g_pwr_mode)
8625 {
8626 	const struct super_chan_info *super_chan_ent;
8627 	QDF_STATUS status;
8628 
8629 	if (freq_idx >= NUM_CHANNELS)
8630 		return false;
8631 
8632 	if (freq_idx < MIN_6GHZ_CHANNEL)
8633 		return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj,
8634 								freq_idx);
8635 
8636 	status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx,
8637 					 &super_chan_ent);
8638 	if (QDF_IS_STATUS_ERROR(status)) {
8639 		reg_debug("Failed to get super channel entry for freq_idx %d",
8640 			  freq_idx);
8641 		return false;
8642 	}
8643 
8644 	/* If the input 6G power mode is best power mode, get the best power
8645 	 * mode type from the super channel entry.
8646 	 */
8647 	if (in_6g_pwr_mode == REG_BEST_PWR_MODE)
8648 		in_6g_pwr_mode = super_chan_ent->best_power_mode;
8649 
8650 	return !reg_is_supr_entry_mode_disabled(super_chan_ent, in_6g_pwr_mode);
8651 }
8652 
8653 static QDF_STATUS
8654 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8655 				     *pdev_priv_obj,
8656 				     enum channel_enum freq_idx,
8657 				     enum supported_6g_pwr_types
8658 				     in_6g_pwr_mode,
8659 				     uint16_t *min_bw,
8660 				     uint16_t *max_bw)
8661 {
8662 	const struct super_chan_info *super_chan_ent;
8663 	QDF_STATUS status;
8664 
8665 	if (freq_idx >= NUM_CHANNELS)
8666 		return QDF_STATUS_E_FAILURE;
8667 
8668 	if (freq_idx < MIN_6GHZ_CHANNEL)
8669 		return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj,
8670 						       freq_idx,
8671 						       min_bw, max_bw);
8672 
8673 	status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx,
8674 					 &super_chan_ent);
8675 	if (QDF_IS_STATUS_ERROR(status)) {
8676 		reg_debug("Failed to get super channel entry for freq_idx %d",
8677 			  freq_idx);
8678 		return QDF_STATUS_E_FAILURE;
8679 	}
8680 
8681 	/* If the input 6G power mode is best power mode, get the best power
8682 	 * mode type from the super channel entry.
8683 	 */
8684 	if (in_6g_pwr_mode == REG_BEST_PWR_MODE)
8685 		in_6g_pwr_mode = super_chan_ent->best_power_mode;
8686 
8687 	if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) {
8688 		reg_debug("pwr_type invalid");
8689 		return QDF_STATUS_E_FAILURE;
8690 	}
8691 
8692 	if (min_bw)
8693 		*min_bw = super_chan_ent->min_bw[in_6g_pwr_mode];
8694 	if (max_bw)
8695 		*max_bw = super_chan_ent->max_bw[in_6g_pwr_mode];
8696 
8697 	return QDF_STATUS_SUCCESS;
8698 }
8699 
8700 static enum channel_state
8701 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8702 				     *pdev_priv_obj,
8703 				     enum channel_enum freq_idx,
8704 				     enum supported_6g_pwr_types
8705 				     in_6g_pwr_mode)
8706 {
8707 	const struct super_chan_info *super_chan_ent;
8708 	enum channel_state chan_state;
8709 	QDF_STATUS status;
8710 
8711 	if (freq_idx >= NUM_CHANNELS)
8712 		return CHANNEL_STATE_INVALID;
8713 
8714 	if (freq_idx < MIN_6GHZ_CHANNEL)
8715 		return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj,
8716 				freq_idx);
8717 
8718 	status = reg_get_superchan_entry(pdev_priv_obj->pdev_ptr, freq_idx,
8719 					 &super_chan_ent);
8720 	if (QDF_IS_STATUS_ERROR(status)) {
8721 		reg_debug("Failed to get super channel entry for freq_idx %d",
8722 			  freq_idx);
8723 		return CHANNEL_STATE_INVALID;
8724 	}
8725 
8726 	/* If the input 6G power mode is best power mode, get the best power
8727 	 * mode type from the super channel entry.
8728 	 */
8729 	if (in_6g_pwr_mode == REG_BEST_PWR_MODE)
8730 		in_6g_pwr_mode = super_chan_ent->best_power_mode;
8731 
8732 	if (reg_is_supp_pwr_mode_invalid(in_6g_pwr_mode)) {
8733 		reg_debug("pwr_type invalid");
8734 		return CHANNEL_STATE_INVALID;
8735 	}
8736 
8737 	chan_state = super_chan_ent->state_arr[in_6g_pwr_mode];
8738 
8739 	return chan_state;
8740 }
8741 
8742 enum supported_6g_pwr_types
8743 reg_get_best_6g_pwr_type(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq)
8744 {
8745 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8746 	enum channel_enum freq_idx;
8747 	enum channel_enum sixg_freq_idx;
8748 
8749 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8750 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8751 		reg_err_rl("pdev reg component is NULL");
8752 		return REG_INVALID_PWR_MODE;
8753 	}
8754 
8755 	freq_idx = reg_get_chan_enum_for_freq(freq);
8756 
8757 	if (reg_is_chan_enum_invalid(freq_idx))
8758 		return REG_INVALID_PWR_MODE;
8759 
8760 	sixg_freq_idx = reg_convert_enum_to_6g_idx(freq_idx);
8761 	if (reg_is_chan_enum_invalid(sixg_freq_idx) ||
8762 	    sixg_freq_idx >= NUM_6GHZ_CHANNELS)
8763 		return REG_INVALID_PWR_MODE;
8764 
8765 	return pdev_priv_obj->super_chan_list[sixg_freq_idx].best_power_mode;
8766 }
8767 
8768 static inline bool reg_is_6g_ap_type_invalid(enum reg_6g_ap_type ap_pwr_type)
8769 {
8770 	return ((ap_pwr_type < REG_INDOOR_AP) ||
8771 		(ap_pwr_type > REG_MAX_SUPP_AP_TYPE));
8772 }
8773 
8774 enum supported_6g_pwr_types
8775 reg_conv_6g_ap_type_to_supported_6g_pwr_types(enum reg_6g_ap_type ap_pwr_type)
8776 {
8777 	static const enum supported_6g_pwr_types reg_enum_conv[] = {
8778 		[REG_INDOOR_AP] = REG_AP_LPI,
8779 		[REG_STANDARD_POWER_AP] = REG_AP_SP,
8780 		[REG_VERY_LOW_POWER_AP] = REG_AP_VLP,
8781 	};
8782 
8783 	if (reg_is_6g_ap_type_invalid(ap_pwr_type))
8784 		return REG_INVALID_PWR_MODE;
8785 
8786 	return reg_enum_conv[ap_pwr_type];
8787 }
8788 #else
8789 static inline bool
8790 reg_is_freq_idx_enabled_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8791 					  *pdev_priv_obj,
8792 					  enum channel_enum freq_idx,
8793 					  enum supported_6g_pwr_types
8794 					  in_6g_pwr_mode)
8795 {
8796 	return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj,
8797 							freq_idx);
8798 }
8799 
8800 static inline QDF_STATUS
8801 reg_get_min_max_bw_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8802 				     *pdev_priv_obj,
8803 				     enum channel_enum freq_idx,
8804 				     enum supported_6g_pwr_types
8805 				     in_6g_pwr_mode,
8806 				     uint16_t *min_bw,
8807 				     uint16_t *max_bw)
8808 {
8809 	return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj,
8810 						   freq_idx,
8811 						   min_bw, max_bw);
8812 }
8813 
8814 static inline enum channel_state
8815 reg_get_chan_state_on_given_pwr_mode(struct wlan_regulatory_pdev_priv_obj
8816 				     *pdev_priv_obj,
8817 				     enum channel_enum freq_idx,
8818 				     enum supported_6g_pwr_types
8819 				     in_6g_pwr_mode)
8820 {
8821 	return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj,
8822 						   freq_idx);
8823 }
8824 #endif /* CONFIG_BAND_6GHZ */
8825 
8826 bool
8827 reg_is_freq_enabled(struct wlan_objmgr_pdev *pdev,
8828 		    qdf_freq_t freq,
8829 		    enum supported_6g_pwr_types in_6g_pwr_mode)
8830 {
8831 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8832 	enum channel_enum freq_idx;
8833 
8834 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8835 
8836 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8837 		reg_err("reg pdev private obj is NULL");
8838 		return false;
8839 	}
8840 
8841 	freq_idx = reg_get_chan_enum_for_freq(freq);
8842 
8843 	if (reg_is_chan_enum_invalid(freq_idx))
8844 		return false;
8845 
8846 	return reg_is_freq_idx_enabled(pdev, freq_idx, in_6g_pwr_mode);
8847 }
8848 
8849 bool reg_is_freq_idx_enabled(struct wlan_objmgr_pdev *pdev,
8850 			     enum channel_enum freq_idx,
8851 			     enum supported_6g_pwr_types in_6g_pwr_mode)
8852 {
8853 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8854 
8855 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8856 
8857 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8858 		reg_err("reg pdev private obj is NULL");
8859 		return false;
8860 	}
8861 
8862 	if (freq_idx < MIN_6GHZ_CHANNEL)
8863 		return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj,
8864 								freq_idx);
8865 
8866 	switch (in_6g_pwr_mode) {
8867 	case REG_CURRENT_PWR_MODE:
8868 		return reg_is_freq_idx_enabled_on_cur_chan_list(pdev_priv_obj,
8869 								freq_idx);
8870 
8871 	case REG_BEST_PWR_MODE:
8872 	default:
8873 		return reg_is_freq_idx_enabled_on_given_pwr_mode(pdev_priv_obj,
8874 								 freq_idx,
8875 								 in_6g_pwr_mode
8876 								 );
8877 	}
8878 }
8879 
8880 QDF_STATUS reg_get_min_max_bw_reg_chan_list(struct wlan_objmgr_pdev *pdev,
8881 					    enum channel_enum freq_idx,
8882 					    enum supported_6g_pwr_types
8883 					    in_6g_pwr_mode,
8884 					    uint16_t *min_bw,
8885 					    uint16_t *max_bw)
8886 {
8887 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8888 
8889 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8890 
8891 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8892 		reg_err("reg pdev private obj is NULL");
8893 		return QDF_STATUS_E_FAILURE;
8894 	}
8895 
8896 	if (freq_idx < MIN_6GHZ_CHANNEL)
8897 		return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj,
8898 							   freq_idx,
8899 							   min_bw, max_bw);
8900 
8901 	switch (in_6g_pwr_mode) {
8902 	case REG_CURRENT_PWR_MODE:
8903 		return reg_get_min_max_bw_on_cur_chan_list(pdev_priv_obj,
8904 							   freq_idx,
8905 							   min_bw, max_bw);
8906 
8907 	case REG_BEST_PWR_MODE:
8908 	default:
8909 		return reg_get_min_max_bw_on_given_pwr_mode(pdev_priv_obj,
8910 							    freq_idx,
8911 							    in_6g_pwr_mode,
8912 							    min_bw, max_bw);
8913 	}
8914 }
8915 
8916 enum channel_state reg_get_chan_state(struct wlan_objmgr_pdev *pdev,
8917 				      enum channel_enum freq_idx,
8918 				      enum supported_6g_pwr_types
8919 				      in_6g_pwr_mode,
8920 				      bool treat_nol_chan_as_disabled)
8921 {
8922 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
8923 
8924 	pdev_priv_obj = reg_get_pdev_obj(pdev);
8925 
8926 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
8927 		reg_err("reg pdev private obj is NULL");
8928 		return CHANNEL_STATE_INVALID;
8929 	}
8930 
8931 	if (freq_idx < MIN_6GHZ_CHANNEL) {
8932 		if (treat_nol_chan_as_disabled)
8933 			return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj,
8934 								   freq_idx);
8935 		else
8936 			return reg_get_chan_state_based_on_nol_flag_cur_chan_list(
8937 								pdev_priv_obj,
8938 								freq_idx);
8939 	}
8940 
8941 	switch (in_6g_pwr_mode) {
8942 	case REG_CURRENT_PWR_MODE:
8943 		return reg_get_chan_state_on_cur_chan_list(pdev_priv_obj,
8944 							   freq_idx);
8945 
8946 	case REG_BEST_PWR_MODE:
8947 	default:
8948 		return reg_get_chan_state_on_given_pwr_mode(pdev_priv_obj,
8949 							    freq_idx,
8950 							    in_6g_pwr_mode
8951 							   );
8952 	}
8953 }
8954 
8955 #ifdef WLAN_FEATURE_11BE
8956 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw)
8957 {
8958 	switch (bw) {
8959 	case BW_5_MHZ:
8960 		return CH_WIDTH_5MHZ;
8961 	case BW_10_MHZ:
8962 		return CH_WIDTH_10MHZ;
8963 	case BW_20_MHZ:
8964 		return CH_WIDTH_20MHZ;
8965 	case BW_40_MHZ:
8966 		return CH_WIDTH_40MHZ;
8967 	case BW_80_MHZ:
8968 		return CH_WIDTH_80MHZ;
8969 	case BW_160_MHZ:
8970 		return CH_WIDTH_160MHZ;
8971 	case BW_320_MHZ:
8972 		return CH_WIDTH_320MHZ;
8973 	default:
8974 		return CH_WIDTH_INVALID;
8975 	}
8976 }
8977 #else
8978 enum phy_ch_width reg_find_chwidth_from_bw(uint16_t bw)
8979 {
8980 	switch (bw) {
8981 	case BW_5_MHZ:
8982 		return CH_WIDTH_5MHZ;
8983 	case BW_10_MHZ:
8984 		return CH_WIDTH_10MHZ;
8985 	case BW_20_MHZ:
8986 		return CH_WIDTH_20MHZ;
8987 	case BW_40_MHZ:
8988 		return CH_WIDTH_40MHZ;
8989 	case BW_80_MHZ:
8990 		return CH_WIDTH_80MHZ;
8991 	case BW_160_MHZ:
8992 		return CH_WIDTH_160MHZ;
8993 	default:
8994 		return CH_WIDTH_INVALID;
8995 	}
8996 }
8997 #endif
8998 
8999 #ifdef CONFIG_BAND_6GHZ
9000 qdf_freq_t reg_get_thresh_priority_freq(struct wlan_objmgr_pdev *pdev)
9001 {
9002 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9003 
9004 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9005 
9006 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
9007 		reg_err("reg pdev private obj is NULL");
9008 		return 0;
9009 	}
9010 
9011 	return pdev_priv_obj->reg_6g_thresh_priority_freq;
9012 }
9013 
9014 /**
9015  * reg_get_eirp_for_non_sp() -  For the given power mode, using the bandwidth
9016  * and psd(from master channel entry), calculate an EIRP value. The minimum
9017  * of calculated EIRP and regulatory max EIRP is returned.
9018  * @pdev: Pointer to pdev
9019  * @freq: Frequency in mhz
9020  * @bw: Bandwidth in mhz
9021  * @ap_pwr_type: AP Power type
9022  *
9023  * Return: EIRP
9024  */
9025 static uint8_t
9026 reg_get_eirp_for_non_sp(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq,
9027 			uint16_t bw, enum reg_6g_ap_type ap_pwr_type)
9028 {
9029 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9030 	bool is_psd;
9031 	struct regulatory_channel *master_chan_list;
9032 	uint16_t txpower = 0;
9033 
9034 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9035 	if (!pdev_priv_obj) {
9036 		reg_err("pdev priv obj is NULL");
9037 		return 0;
9038 	}
9039 
9040 	if (!((ap_pwr_type == REG_INDOOR_AP) ||
9041 	      (ap_pwr_type == REG_VERY_LOW_POWER_AP))) {
9042 		reg_err("Only LPI and VLP are supported in this function ");
9043 		return 0;
9044 	}
9045 
9046 	master_chan_list = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type];
9047 	is_psd = reg_is_6g_psd_power(pdev);
9048 	reg_find_txpower_from_6g_list(freq, master_chan_list, &txpower);
9049 
9050 	if (is_psd) {
9051 		int16_t eirp = 0, psd = 0;
9052 
9053 		reg_get_6g_chan_psd_eirp_power(freq, master_chan_list, &psd);
9054 		reg_psd_2_eirp(pdev, psd, bw, &eirp);
9055 		return QDF_MIN(txpower, eirp);
9056 	}
9057 
9058 	return txpower;
9059 }
9060 
9061 #ifdef CONFIG_AFC_SUPPORT
9062 /**
9063  * reg_compute_6g_center_freq_from_cfi() - Given the IEEE value of the
9064  * 6 GHz center frequency, find the 6 GHz center frequency.
9065  * @ieee_6g_cfi: IEEE value of 6 GHz cfi
9066  * Return: Center frequency in MHz
9067  */
9068 static qdf_freq_t
9069 reg_compute_6g_center_freq_from_cfi(uint8_t ieee_6g_cfi)
9070 {
9071 	return (SIXG_START_FREQ + ieee_6g_cfi * FREQ_TO_CHAN_SCALE);
9072 }
9073 
9074 #ifdef WLAN_FEATURE_11BE
9075 /**
9076  * reg_is_320_opclass: Find out if the opclass computed from freq and
9077  * width of 320 is same as the input op_class.
9078  * @freq: Frequency in MHz
9079  * @in_opclass: Input Opclass number
9080  * Return: true if opclass is 320 supported, false otherwise.
9081  */
9082 static bool reg_is_320_opclass(qdf_freq_t freq, uint8_t in_opclass)
9083 {
9084 	uint8_t local_op_class =
9085 		reg_dmn_get_opclass_from_freq_width(NULL, freq, BW_320_MHZ,
9086 						    BIT(BEHAV_NONE));
9087 	return (in_opclass == local_op_class);
9088 }
9089 #else
9090 static inline bool reg_is_320_opclass(qdf_freq_t freq, uint8_t op_class)
9091 {
9092 	return false;
9093 }
9094 #endif
9095 
9096 /**
9097  * reg_find_eirp_in_afc_eirp_obj() - Get eirp power from the AFC eirp object
9098  * based on the channel center frequency and operating class
9099  * @pdev: Pointer to pdev
9100  * @eirp_obj: Pointer to eirp_obj
9101  * @freq: Frequency in MHz
9102  * @cen320: 320 MHz band center frequency
9103  * @op_class: Operating class
9104  *
9105  * Return: EIRP power
9106  */
9107 static uint8_t reg_find_eirp_in_afc_eirp_obj(struct wlan_objmgr_pdev *pdev,
9108 					     struct chan_eirp_obj *eirp_obj,
9109 					     qdf_freq_t freq,
9110 					     qdf_freq_t cen320,
9111 					     uint8_t op_class)
9112 {
9113 	uint8_t k;
9114 	uint8_t subchannels[NUM_20_MHZ_CHAN_IN_320_MHZ_CHAN];
9115 	uint8_t nchans;
9116 
9117 	if (reg_is_320_opclass(freq, op_class)) {
9118 		qdf_freq_t cfi_freq =
9119 			reg_compute_6g_center_freq_from_cfi(eirp_obj->cfi);
9120 
9121 		if (cfi_freq == cen320)
9122 			return eirp_obj->eirp_power / EIRP_PWR_SCALE;
9123 
9124 		return 0;
9125 	}
9126 
9127 	nchans = reg_get_subchannels_for_opclass(eirp_obj->cfi,
9128 						 op_class,
9129 						 subchannels);
9130 
9131 	for (k = 0; k < nchans; k++)
9132 		if (reg_chan_band_to_freq(pdev, subchannels[k],
9133 					  BIT(REG_BAND_6G)) == freq)
9134 			return eirp_obj->eirp_power / EIRP_PWR_SCALE;
9135 
9136 	return 0;
9137 }
9138 
9139 /**
9140  * reg_find_eirp_in_afc_chan_obj() - Get eirp power from the AFC channel
9141  * object based on the channel center frequency and operating class
9142  * @pdev: Pointer to pdev
9143  * @chan_obj: Pointer to chan_obj
9144  * @freq: Frequency in MHz
9145  * @cen320: 320 MHz band center frequency
9146  * @op_class: Operating class
9147  *
9148  * Return: EIRP power
9149  */
9150 static uint8_t reg_find_eirp_in_afc_chan_obj(struct wlan_objmgr_pdev *pdev,
9151 					     struct afc_chan_obj *chan_obj,
9152 					     qdf_freq_t freq,
9153 					     qdf_freq_t cen320,
9154 					     uint8_t op_class)
9155 {
9156 	uint8_t j;
9157 
9158 	if (chan_obj->global_opclass != op_class)
9159 		return 0;
9160 
9161 	for (j = 0; j < chan_obj->num_chans; j++) {
9162 		uint8_t afc_eirp;
9163 		struct chan_eirp_obj *eirp_obj = &chan_obj->chan_eirp_info[j];
9164 
9165 		afc_eirp = reg_find_eirp_in_afc_eirp_obj(pdev, eirp_obj,
9166 							 freq, cen320,
9167 							 op_class);
9168 
9169 		if (afc_eirp)
9170 			return afc_eirp;
9171 	}
9172 
9173 	return 0;
9174 }
9175 
9176 /**
9177  * reg_get_sp_eirp() - For the given power mode, using the bandwidth, find the
9178  * corresponding EIRP values from the afc power info array. The minimum of found
9179  * EIRP and regulatory max EIRP is returned
9180  * @pdev: Pointer to pdev
9181  * @freq: Frequency in MHz
9182  * @cen320: 320 MHz band center frequency
9183  * @bw: Bandwidth in mhz
9184  *
9185  * Return: EIRP
9186  */
9187 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev,
9188 			       qdf_freq_t freq,
9189 			       qdf_freq_t cen320,
9190 			       uint16_t bw)
9191 {
9192 	uint8_t i, op_class = 0, chan_num = 0, afc_eirp_pwr = 0;
9193 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9194 	struct regulatory_channel *sp_ap_master_chan_list;
9195 	struct reg_fw_afc_power_event *power_info;
9196 	uint16_t reg_sp_eirp_pwr = 0;
9197 
9198 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9199 
9200 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
9201 		reg_err("reg pdev priv obj is NULL");
9202 		return 0;
9203 	}
9204 
9205 	if (!reg_is_afc_power_event_received(pdev))
9206 		return 0;
9207 
9208 	power_info = pdev_priv_obj->power_info;
9209 	if (!power_info) {
9210 		reg_err("power_info is NULL");
9211 		return 0;
9212 	}
9213 
9214 	reg_freq_width_to_chan_op_class(pdev,
9215 					freq,
9216 					bw,
9217 					true,
9218 					BIT(BEHAV_NONE),
9219 					&op_class,
9220 					&chan_num);
9221 	sp_ap_master_chan_list =
9222 		pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP];
9223 	reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list,
9224 				      &reg_sp_eirp_pwr);
9225 
9226 	if (!reg_sp_eirp_pwr)
9227 		return 0;
9228 
9229 	for (i = 0; i < power_info->num_chan_objs; i++) {
9230 		struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i];
9231 
9232 		afc_eirp_pwr = reg_find_eirp_in_afc_chan_obj(pdev,
9233 							     chan_obj,
9234 							     freq,
9235 							     cen320,
9236 							     op_class);
9237 		if (afc_eirp_pwr)
9238 			break;
9239 	}
9240 
9241 	if (afc_eirp_pwr)
9242 		return QDF_MIN(afc_eirp_pwr, reg_sp_eirp_pwr);
9243 
9244 	return 0;
9245 }
9246 #else
9247 static uint8_t reg_get_sp_eirp(struct wlan_objmgr_pdev *pdev,
9248 			       qdf_freq_t freq,
9249 			       qdf_freq_t cen320,
9250 			       uint16_t bw)
9251 {
9252 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9253 	struct regulatory_channel *sp_ap_master_chan_list;
9254 	uint16_t reg_sp_eirp_pwr = 0;
9255 
9256 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9257 
9258 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
9259 		reg_err("reg pdev priv obj is NULL");
9260 		return 0;
9261 	}
9262 
9263 	sp_ap_master_chan_list =
9264 		pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP];
9265 	reg_find_txpower_from_6g_list(freq, sp_ap_master_chan_list,
9266 				      &reg_sp_eirp_pwr);
9267 
9268 	return reg_sp_eirp_pwr;
9269 }
9270 #endif
9271 
9272 /**
9273  * reg_get_best_pwr_mode_from_eirp_list() - Get best power mode from the input
9274  * EIRP list
9275  * @eirp_list: EIRP list
9276  * @size: Size of eirp list
9277  *
9278  * Return: Best power mode
9279  */
9280 static enum reg_6g_ap_type
9281 reg_get_best_pwr_mode_from_eirp_list(uint8_t *eirp_list, uint8_t size)
9282 {
9283 	uint8_t max = 0, i;
9284 	enum reg_6g_ap_type best_pwr_mode = REG_INDOOR_AP;
9285 
9286 	for (i = 0; i < size; i++) {
9287 		if (eirp_list[i] > max) {
9288 			max = eirp_list[i];
9289 			best_pwr_mode = i;
9290 		}
9291 	}
9292 
9293 	return best_pwr_mode;
9294 }
9295 
9296 uint8_t reg_get_eirp_pwr(struct wlan_objmgr_pdev *pdev, qdf_freq_t freq,
9297 			 qdf_freq_t cen320,
9298 			 uint16_t bw, enum reg_6g_ap_type ap_pwr_type)
9299 {
9300 	if (ap_pwr_type == REG_STANDARD_POWER_AP)
9301 		return reg_get_sp_eirp(pdev, freq, cen320, bw);
9302 
9303 	return reg_get_eirp_for_non_sp(pdev, freq, bw, ap_pwr_type);
9304 }
9305 
9306 enum reg_6g_ap_type reg_get_best_pwr_mode(struct wlan_objmgr_pdev *pdev,
9307 					  qdf_freq_t freq,
9308 					  qdf_freq_t cen320,
9309 					  uint16_t bw)
9310 {
9311 	uint8_t eirp_list[REG_MAX_SUPP_AP_TYPE + 1];
9312 	enum reg_6g_ap_type ap_pwr_type;
9313 
9314 	for (ap_pwr_type = REG_INDOOR_AP; ap_pwr_type <= REG_VERY_LOW_POWER_AP;
9315 	     ap_pwr_type++)
9316 		eirp_list[ap_pwr_type] =
9317 				reg_get_eirp_pwr(pdev, freq, cen320, bw,
9318 						 ap_pwr_type);
9319 
9320 	return reg_get_best_pwr_mode_from_eirp_list(eirp_list,
9321 						    REG_MAX_SUPP_AP_TYPE + 1);
9322 }
9323 #endif
9324 
9325 QDF_STATUS reg_get_regd_rules(struct wlan_objmgr_pdev *pdev,
9326 			      struct reg_rule_info *reg_rules)
9327 {
9328 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9329 
9330 	if (!pdev) {
9331 		reg_err("pdev is NULL");
9332 		return QDF_STATUS_E_FAILURE;
9333 	}
9334 
9335 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9336 	if (!pdev_priv_obj) {
9337 		reg_err("pdev priv obj is NULL");
9338 		return QDF_STATUS_E_FAILURE;
9339 	}
9340 
9341 	qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock);
9342 	qdf_mem_copy(reg_rules, &pdev_priv_obj->reg_rules,
9343 		     sizeof(struct reg_rule_info));
9344 	qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock);
9345 
9346 	return QDF_STATUS_SUCCESS;
9347 }
9348 
9349 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
9350 bool
9351 reg_is_sup_chan_entry_afc_done(struct wlan_objmgr_pdev *pdev,
9352 			       enum channel_enum chan_idx,
9353 			       enum supported_6g_pwr_types in_6g_pwr_mode)
9354 {
9355 	const struct super_chan_info *super_chan_ent;
9356 	QDF_STATUS status;
9357 
9358 	status = reg_get_superchan_entry(pdev, chan_idx,
9359 					 &super_chan_ent);
9360 	if (QDF_IS_STATUS_ERROR(status)) {
9361 		reg_debug("Failed to get super channel entry for chan_idx %d",
9362 			  chan_idx);
9363 		return false;
9364 	}
9365 
9366 	if (in_6g_pwr_mode == REG_BEST_PWR_MODE)
9367 		in_6g_pwr_mode = super_chan_ent->best_power_mode;
9368 
9369 	if (in_6g_pwr_mode != REG_AP_SP)
9370 		return false;
9371 
9372 	return !(super_chan_ent->chan_flags_arr[in_6g_pwr_mode] &
9373 		 REGULATORY_CHAN_AFC_NOT_DONE);
9374 }
9375 #endif
9376 
9377 #ifdef CONFIG_BAND_6GHZ
9378 QDF_STATUS
9379 reg_display_super_chan_list(struct wlan_objmgr_pdev *pdev)
9380 {
9381 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
9382 	struct super_chan_info *super_chan_list;
9383 	uint8_t i;
9384 
9385 	pdev_priv_obj = reg_get_pdev_obj(pdev);
9386 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
9387 		reg_err_rl("pdev reg component is NULL");
9388 		return QDF_STATUS_E_FAILURE;
9389 	}
9390 
9391 	super_chan_list = pdev_priv_obj->super_chan_list;
9392 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
9393 		struct super_chan_info *chan_info = &super_chan_list[i];
9394 		struct regulatory_channel  cur_chan_list =
9395 			pdev_priv_obj->cur_chan_list[MIN_6GHZ_CHANNEL + i];
9396 		uint8_t j;
9397 
9398 		qdf_print("Freq = %d\tPower types = 0x%x\t"
9399 			  "Best power mode = 0x%x\n",
9400 			  cur_chan_list.center_freq, chan_info->power_types,
9401 			  chan_info->best_power_mode);
9402 		for (j = REG_AP_LPI; j <= REG_CLI_SUB_VLP; j++) {
9403 			bool afc_not_done_bit;
9404 
9405 			afc_not_done_bit = chan_info->chan_flags_arr[j] &
9406 						REGULATORY_CHAN_AFC_NOT_DONE;
9407 			qdf_print("Power mode = %d\tPSD flag = %d\t"
9408 				  "PSD power = %d\tEIRP power = %d\t"
9409 				  "Chan flags = 0x%x\tChannel state = %d\t"
9410 				  "Min bw = %d\tMax bw = %d\t"
9411 				  "AFC_NOT_DONE = %d\n",
9412 				  j, chan_info->reg_chan_pwr[j].psd_flag,
9413 				  chan_info->reg_chan_pwr[j].psd_eirp,
9414 				  chan_info->reg_chan_pwr[j].tx_power,
9415 				  chan_info->chan_flags_arr[j],
9416 				  chan_info->state_arr[j],
9417 				  chan_info->min_bw[j], chan_info->max_bw[j],
9418 				  afc_not_done_bit);
9419 		}
9420 	}
9421 
9422 	return QDF_STATUS_SUCCESS;
9423 }
9424 #endif
9425