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