xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_build_chan_list.c (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: reg_build_chan_list.c
21  * This file defines the API to build master and current channel list.
22  */
23 
24 #include <wlan_cmn.h>
25 #include <reg_services_public_struct.h>
26 #include <wlan_objmgr_psoc_obj.h>
27 #include <wlan_objmgr_pdev_obj.h>
28 #include "reg_priv_objs.h"
29 #include "reg_utils.h"
30 #include "reg_callbacks.h"
31 #include "reg_services_common.h"
32 #include "reg_db.h"
33 #include "reg_db_parser.h"
34 #include "reg_offload_11d_scan.h"
35 #include <scheduler_api.h>
36 #include "reg_build_chan_list.h"
37 #include <qdf_platform.h>
38 #include <wlan_reg_services_api.h>
39 
40 #define MAX_PWR_FCC_CHAN_12 8
41 #define MAX_PWR_FCC_CHAN_13 2
42 #define CHAN_144_CENT_FREQ 5720
43 
44 #ifdef CONFIG_BAND_6GHZ
45 static void reg_fill_psd_info(enum channel_enum chan_enum,
46 			      struct cur_reg_rule *reg_rule,
47 			      struct regulatory_channel *master_list)
48 {
49 	master_list[chan_enum].psd_flag = reg_rule->psd_flag;
50 
51 	master_list[chan_enum].psd_eirp = reg_rule->psd_eirp;
52 }
53 #else
54 static inline void reg_fill_psd_info(enum channel_enum chan_enum,
55 				     struct cur_reg_rule *reg_rule,
56 				     struct regulatory_channel *master_list)
57 {
58 }
59 #endif
60 
61 /**
62  * reg_fill_channel_info() - Populate TX power, antenna gain, channel state,
63  * channel flags, min and max bandwidth to master channel list.
64  * @chan_enum: Channel enum.
65  * @reg_rule: Pointer to regulatory rule which has tx power and antenna gain.
66  * @master_list: Pointer to master channel list.
67  * @min_bw: minimum bandwidth to be used for given channel.
68  */
69 static void reg_fill_channel_info(enum channel_enum chan_enum,
70 				  struct cur_reg_rule *reg_rule,
71 				  struct regulatory_channel *master_list,
72 				  uint16_t min_bw)
73 {
74 	master_list[chan_enum].chan_flags &= ~REGULATORY_CHAN_DISABLED;
75 
76 	reg_fill_psd_info(chan_enum, reg_rule, master_list);
77 	master_list[chan_enum].tx_power = reg_rule->reg_power;
78 	master_list[chan_enum].ant_gain = reg_rule->ant_gain;
79 	master_list[chan_enum].state = CHANNEL_STATE_ENABLE;
80 
81 	if (reg_rule->flags & REGULATORY_CHAN_NO_IR) {
82 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_IR;
83 		master_list[chan_enum].state = CHANNEL_STATE_DFS;
84 	}
85 
86 	if (reg_rule->flags & REGULATORY_CHAN_RADAR) {
87 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_RADAR;
88 		master_list[chan_enum].state = CHANNEL_STATE_DFS;
89 	}
90 
91 	if (reg_rule->flags & REGULATORY_CHAN_INDOOR_ONLY)
92 		master_list[chan_enum].chan_flags |=
93 			REGULATORY_CHAN_INDOOR_ONLY;
94 
95 	if (reg_rule->flags & REGULATORY_CHAN_NO_OFDM)
96 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_OFDM;
97 
98 	master_list[chan_enum].min_bw = min_bw;
99 	if (master_list[chan_enum].max_bw == 20)
100 		master_list[chan_enum].max_bw = reg_rule->max_bw;
101 }
102 
103 #ifdef CONFIG_BAND_6GHZ
104 /**
105  * reg_populate_band_channels_ext_for_6g() - For all the valid regdb channels in
106  *	the master channel list, find the regulatory rules and call
107  *	reg_fill_channel_info() to populate master channel list with txpower,
108  *	antennagain, BW info, etc.
109  * @start_idx: Start channel range in list
110  * @end_idx: End channel range in list
111  * @rule_start_ptr: Pointer to regulatory rules
112  * @num_reg_rules: Number of regulatory rules
113  * @min_reg_bw: Minimum regulatory bandwidth
114  * @mas_chan_list: Pointer to master channel list
115  */
116 static void reg_populate_band_channels_ext_for_6g(uint16_t start_idx,
117 				       uint16_t end_idx,
118 				       struct cur_reg_rule *rule_start_ptr,
119 				       uint32_t num_reg_rules,
120 				       uint16_t min_reg_bw,
121 				       struct regulatory_channel *mas_chan_list)
122 {
123 	struct cur_reg_rule *found_rule_ptr;
124 	struct cur_reg_rule *cur_rule_ptr;
125 	struct regulatory_channel;
126 	uint32_t rule_num, bw;
127 	uint16_t i, min_bw, max_bw;
128 
129 	for (i = start_idx; i <= end_idx; i++) {
130 		found_rule_ptr = NULL;
131 
132 		max_bw = QDF_MIN((uint16_t)20,
133 				 channel_map[MIN_6GHZ_CHANNEL + i].max_bw);
134 		min_bw = QDF_MAX(min_reg_bw,
135 				 channel_map[MIN_6GHZ_CHANNEL + i].min_bw);
136 
137 		if (channel_map[MIN_6GHZ_CHANNEL + i].chan_num ==
138 		    INVALID_CHANNEL_NUM)
139 			continue;
140 
141 		for (bw = max_bw; bw >= min_bw; bw = bw / 2) {
142 			for (rule_num = 0, cur_rule_ptr = rule_start_ptr;
143 			     rule_num < num_reg_rules;
144 			     cur_rule_ptr++, rule_num++) {
145 				if ((cur_rule_ptr->start_freq <=
146 				     mas_chan_list[i].center_freq -
147 				     bw / 2) &&
148 				    (cur_rule_ptr->end_freq >=
149 				     mas_chan_list[i].center_freq +
150 				     bw / 2) && (min_bw <= bw)) {
151 					found_rule_ptr = cur_rule_ptr;
152 					break;
153 				}
154 			}
155 
156 			if (found_rule_ptr)
157 				break;
158 		}
159 
160 		if (found_rule_ptr) {
161 			mas_chan_list[i].max_bw = bw;
162 			reg_fill_channel_info(i, found_rule_ptr,
163 					      mas_chan_list, min_bw);
164 		}
165 	}
166 }
167 #else
168 static inline void
169 reg_populate_band_channels_ext_for_6g(enum channel_enum start_chan,
170 				      enum channel_enum end_chan,
171 				      struct cur_reg_rule *rule_start_ptr,
172 				      uint32_t num_reg_rules,
173 				      uint16_t min_reg_bw,
174 				      struct regulatory_channel *mas_chan_list)
175 {
176 }
177 #endif
178 
179 /**
180  * reg_populate_band_channels() - For all the valid regdb channels in the master
181  * channel list, find the regulatory rules and call reg_fill_channel_info() to
182  * populate master channel list with txpower, antennagain, BW info, etc.
183  * @start_chan: Start channel enum.
184  * @end_chan: End channel enum.
185  * @rule_start_ptr: Pointer to regulatory rules.
186  * @num_reg_rules: Number of regulatory rules.
187  * @min_reg_bw: Minimum regulatory bandwidth.
188  * @mas_chan_list: Pointer to master channel list.
189  */
190 static void reg_populate_band_channels(enum channel_enum start_chan,
191 				       enum channel_enum end_chan,
192 				       struct cur_reg_rule *rule_start_ptr,
193 				       uint32_t num_reg_rules,
194 				       uint16_t min_reg_bw,
195 				       struct regulatory_channel *mas_chan_list)
196 {
197 	struct cur_reg_rule *found_rule_ptr;
198 	struct cur_reg_rule *cur_rule_ptr;
199 	struct regulatory_channel;
200 	enum channel_enum chan_enum;
201 	uint32_t rule_num, bw;
202 	uint16_t max_bw;
203 	uint16_t min_bw;
204 
205 	for (chan_enum = start_chan; chan_enum <= end_chan; chan_enum++) {
206 		found_rule_ptr = NULL;
207 
208 		max_bw = QDF_MIN((uint16_t)20, channel_map[chan_enum].max_bw);
209 		min_bw = QDF_MAX(min_reg_bw, channel_map[chan_enum].min_bw);
210 
211 		if (channel_map[chan_enum].chan_num == INVALID_CHANNEL_NUM)
212 			continue;
213 
214 		for (bw = max_bw; bw >= min_bw; bw = bw / 2) {
215 			for (rule_num = 0, cur_rule_ptr = rule_start_ptr;
216 			     rule_num < num_reg_rules;
217 			     cur_rule_ptr++, rule_num++) {
218 				if ((cur_rule_ptr->start_freq <=
219 				     mas_chan_list[chan_enum].center_freq -
220 				     bw / 2) &&
221 				    (cur_rule_ptr->end_freq >=
222 				     mas_chan_list[chan_enum].center_freq +
223 				     bw / 2) && (min_bw <= bw)) {
224 					found_rule_ptr = cur_rule_ptr;
225 					break;
226 				}
227 			}
228 
229 			if (found_rule_ptr)
230 				break;
231 		}
232 
233 		if (found_rule_ptr) {
234 			mas_chan_list[chan_enum].max_bw = bw;
235 			reg_fill_channel_info(chan_enum, found_rule_ptr,
236 					      mas_chan_list, min_bw);
237 			/* Disable 2.4 Ghz channels that dont have 20 mhz bw */
238 			if (start_chan == MIN_24GHZ_CHANNEL &&
239 			    mas_chan_list[chan_enum].max_bw < 20) {
240 				mas_chan_list[chan_enum].chan_flags |=
241 						REGULATORY_CHAN_DISABLED;
242 				mas_chan_list[chan_enum].state =
243 						CHANNEL_STATE_DISABLE;
244 			}
245 		}
246 	}
247 }
248 
249 /**
250  * reg_update_max_bw_per_rule() - Update max bandwidth value for given regrules.
251  * @num_reg_rules: Number of regulatory rules.
252  * @reg_rule_start: Pointer to regulatory rules.
253  * @max_bw: Maximum bandwidth
254  */
255 static void reg_update_max_bw_per_rule(uint32_t num_reg_rules,
256 				       struct cur_reg_rule *reg_rule_start,
257 				       uint16_t max_bw)
258 {
259 	uint32_t count;
260 
261 	for (count = 0; count < num_reg_rules; count++)
262 		reg_rule_start[count].max_bw =
263 			min(reg_rule_start[count].max_bw, max_bw);
264 }
265 
266 /**
267  * reg_do_auto_bw_correction() - Calculate and update the maximum bandwidth
268  * value.
269  * @num_reg_rules: Number of regulatory rules.
270  * @reg_rule_ptr: Pointer to regulatory rules.
271  * @max_bw: Maximum bandwidth
272  */
273 static void reg_do_auto_bw_correction(uint32_t num_reg_rules,
274 				      struct cur_reg_rule *reg_rule_ptr,
275 				      uint16_t max_bw)
276 {
277 	uint32_t count;
278 	uint16_t new_bw;
279 
280 	for (count = 0; count < num_reg_rules - 1; count++) {
281 		if (reg_rule_ptr[count].end_freq ==
282 		    reg_rule_ptr[count + 1].start_freq) {
283 			new_bw = QDF_MIN(max_bw, reg_rule_ptr[count].max_bw +
284 					 reg_rule_ptr[count + 1].max_bw);
285 			reg_rule_ptr[count].max_bw = new_bw;
286 			reg_rule_ptr[count + 1].max_bw = new_bw;
287 		}
288 	}
289 }
290 
291 /**
292  * reg_modify_chan_list_for_dfs_channels() - disable the DFS channels if
293  * dfs_enable set to false.
294  * @chan_list: Pointer to regulatory channel list.
295  * @dfs_enabled: if false, then disable the DFS channels.
296  */
297 static void reg_modify_chan_list_for_dfs_channels(
298 		struct regulatory_channel *chan_list, bool dfs_enabled)
299 {
300 	enum channel_enum chan_enum;
301 
302 	if (dfs_enabled)
303 		return;
304 
305 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
306 		if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_RADAR) {
307 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
308 			chan_list[chan_enum].chan_flags |=
309 				REGULATORY_CHAN_DISABLED;
310 		}
311 	}
312 }
313 
314 /**
315  * reg_modify_chan_list_for_indoor_channels() - Disable the indoor channels if
316  * indoor_chan_enabled flag is set to false.
317  * @pdev_priv_obj: Pointer to regulatory private pdev structure.
318  */
319 static void reg_modify_chan_list_for_indoor_channels(
320 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
321 {
322 	enum channel_enum chan_enum;
323 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
324 
325 	if (!pdev_priv_obj->indoor_chan_enabled) {
326 		for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
327 			if (REGULATORY_CHAN_INDOOR_ONLY &
328 			    chan_list[chan_enum].chan_flags) {
329 				chan_list[chan_enum].state =
330 					CHANNEL_STATE_DFS;
331 				chan_list[chan_enum].chan_flags |=
332 					REGULATORY_CHAN_NO_IR;
333 			}
334 		}
335 	}
336 
337 	if (pdev_priv_obj->force_ssc_disable_indoor_channel &&
338 	    pdev_priv_obj->sap_state) {
339 		for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
340 			if (REGULATORY_CHAN_INDOOR_ONLY &
341 			    chan_list[chan_enum].chan_flags) {
342 				chan_list[chan_enum].state =
343 					CHANNEL_STATE_DISABLE;
344 				chan_list[chan_enum].chan_flags |=
345 					REGULATORY_CHAN_DISABLED;
346 			}
347 		}
348 	}
349 }
350 
351 #ifdef CONFIG_BAND_6GHZ
352 static void reg_modify_chan_list_for_band_6G(
353 					struct regulatory_channel *chan_list)
354 {
355 	enum channel_enum chan_enum;
356 
357 	reg_debug("disabling 6G");
358 	for (chan_enum = MIN_6GHZ_CHANNEL;
359 	     chan_enum <= MAX_6GHZ_CHANNEL; chan_enum++) {
360 		chan_list[chan_enum].chan_flags |=
361 			REGULATORY_CHAN_DISABLED;
362 		chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
363 	}
364 }
365 #else
366 static inline void reg_modify_chan_list_for_band_6G(
367 					struct regulatory_channel *chan_list)
368 {
369 }
370 #endif
371 
372 /**
373  * reg_modify_chan_list_for_band() - Based on the input band bitmap, either
374  * disable 2GHz, 5GHz, or 6GHz channels.
375  * @chan_list: Pointer to regulatory channel list.
376  * @band_bitmap: Input bitmap of reg_wifi_band values.
377  */
378 static void reg_modify_chan_list_for_band(struct regulatory_channel *chan_list,
379 					  uint32_t band_bitmap)
380 {
381 	enum channel_enum chan_enum;
382 
383 	if (!band_bitmap)
384 		return;
385 
386 	if (!(band_bitmap & BIT(REG_BAND_5G))) {
387 		reg_debug("disabling 5G");
388 		for (chan_enum = MIN_5GHZ_CHANNEL;
389 		     chan_enum <= MAX_5GHZ_CHANNEL; chan_enum++) {
390 			chan_list[chan_enum].chan_flags |=
391 				REGULATORY_CHAN_DISABLED;
392 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
393 		}
394 	}
395 
396 	if (!(band_bitmap & BIT(REG_BAND_2G))) {
397 		reg_debug("disabling 2G");
398 		for (chan_enum = MIN_24GHZ_CHANNEL;
399 		     chan_enum <= MAX_24GHZ_CHANNEL; chan_enum++) {
400 			chan_list[chan_enum].chan_flags |=
401 				REGULATORY_CHAN_DISABLED;
402 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
403 		}
404 	}
405 
406 	if (!(band_bitmap & BIT(REG_BAND_6G)))
407 		reg_modify_chan_list_for_band_6G(chan_list);
408 
409 }
410 
411 /**
412  * reg_modify_chan_list_for_fcc_channel() - Set maximum FCC txpower for channel
413  * 12 and 13 if set_fcc_channel flag is set to true.
414  * @chan_list: Pointer to regulatory channel list.
415  * @set_fcc_channel: If this flag is set to true, then set the max FCC txpower
416  * for channel 12 and 13.
417  */
418 static void reg_modify_chan_list_for_fcc_channel(
419 		struct regulatory_channel *chan_list, bool set_fcc_channel)
420 {
421 	enum channel_enum chan_enum;
422 
423 	if (!set_fcc_channel)
424 		return;
425 
426 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
427 		if (chan_list[chan_enum].center_freq == CHAN_12_CENT_FREQ)
428 			chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_12;
429 
430 		if (chan_list[chan_enum].center_freq == CHAN_13_CENT_FREQ)
431 			chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_13;
432 	}
433 }
434 
435 /**
436  * reg_modify_chan_list_for_chan_144() - Disable channel 144 if en_chan_144 flag
437  * is set to false.
438  * @chan_list: Pointer to regulatory channel list.
439  * @en_chan_144: if false, then disable channel 144.
440  */
441 static void reg_modify_chan_list_for_chan_144(
442 		struct regulatory_channel *chan_list, bool en_chan_144)
443 {
444 	enum channel_enum chan_enum;
445 
446 	if (en_chan_144)
447 		return;
448 
449 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
450 		if (chan_list[chan_enum].center_freq == CHAN_144_CENT_FREQ) {
451 			chan_list[chan_enum].chan_flags |=
452 				REGULATORY_CHAN_DISABLED;
453 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
454 		}
455 	}
456 }
457 
458 /**
459  * reg_modify_chan_list_for_nol_list() - Disable the channel if nol_chan flag is
460  * set.
461  * @chan_list: Pointer to regulatory channel list.
462  */
463 static void reg_modify_chan_list_for_nol_list(
464 		struct regulatory_channel *chan_list)
465 {
466 	enum channel_enum chan_enum;
467 
468 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
469 		if (chan_list[chan_enum].nol_chan) {
470 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
471 			chan_list[chan_enum].chan_flags |=
472 				REGULATORY_CHAN_DISABLED;
473 		}
474 	}
475 }
476 
477 /**
478  * reg_find_low_limit_chan_enum() - Find low limit 2G and 5G channel enums.
479  * @chan_list: Pointer to regulatory channel list.
480  * @low_freq: low limit frequency.
481  * @low_limit: pointer to output low limit enum.
482  *
483  * Return: None
484  */
485 static void reg_find_low_limit_chan_enum(
486 		struct regulatory_channel *chan_list, qdf_freq_t low_freq,
487 		uint32_t *low_limit)
488 {
489 	enum channel_enum chan_enum;
490 	uint16_t min_bw;
491 	uint16_t max_bw;
492 	qdf_freq_t center_freq;
493 
494 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
495 		min_bw = chan_list[chan_enum].min_bw;
496 		max_bw = chan_list[chan_enum].max_bw;
497 		center_freq = chan_list[chan_enum].center_freq;
498 
499 		if ((center_freq - min_bw / 2) >= low_freq) {
500 			if ((center_freq - max_bw / 2) < low_freq) {
501 				if (max_bw <= 20)
502 					max_bw = ((center_freq - low_freq) * 2);
503 				if (max_bw < min_bw)
504 					max_bw = min_bw;
505 				chan_list[chan_enum].max_bw = max_bw;
506 			}
507 			*low_limit = chan_enum;
508 			break;
509 		}
510 	}
511 }
512 
513 /**
514  * reg_find_high_limit_chan_enum() - Find high limit 2G and 5G channel enums.
515  * @chan_list: Pointer to regulatory channel list.
516  * @high_freq: high limit frequency.
517  * @high_limit: pointer to output high limit enum.
518  *
519  * Return: None
520  */
521 static void reg_find_high_limit_chan_enum(
522 		struct regulatory_channel *chan_list,
523 		qdf_freq_t high_freq,
524 		uint32_t *high_limit)
525 {
526 	enum channel_enum chan_enum;
527 	uint16_t min_bw;
528 	uint16_t max_bw;
529 	qdf_freq_t center_freq;
530 
531 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
532 		min_bw = chan_list[chan_enum].min_bw;
533 		max_bw = chan_list[chan_enum].max_bw;
534 		center_freq = chan_list[chan_enum].center_freq;
535 
536 		if (center_freq + min_bw / 2 <= high_freq) {
537 			if ((center_freq + max_bw / 2) > high_freq) {
538 				if (max_bw <= 20)
539 					max_bw = ((high_freq -
540 						   center_freq) * 2);
541 				if (max_bw < min_bw)
542 					max_bw = min_bw;
543 				chan_list[chan_enum].max_bw = max_bw;
544 			}
545 			*high_limit = chan_enum;
546 			break;
547 		}
548 
549 		if (chan_enum == 0)
550 			break;
551 	}
552 }
553 
554 #ifdef REG_DISABLE_JP_CH144
555 /**
556  * reg_modify_chan_list_for_japan() - Disable channel 144 for MKK17_MKKC
557  * regdomain by default.
558  * @pdev: Pointer to pdev
559  *
560  * Return: None
561  */
562 static void
563 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev)
564 {
565 #define MKK17_MKKC 0xE1
566 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
567 
568 	pdev_priv_obj = reg_get_pdev_obj(pdev);
569 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
570 		reg_err("reg pdev priv obj is NULL");
571 		return;
572 	}
573 
574 	if (pdev_priv_obj->reg_dmn_pair == MKK17_MKKC)
575 		pdev_priv_obj->en_chan_144 = false;
576 
577 #undef MKK17_MKKC
578 }
579 #else
580 static inline void
581 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev)
582 {
583 }
584 #endif
585 /**
586  * reg_modify_chan_list_for_freq_range() - Modify channel list for the given low
587  * and high frequency range.
588  * @chan_list: Pointer to regulatory channel list.
589  * @low_freq_2g: Low frequency 2G.
590  * @high_freq_2g: High frequency 2G.
591  * @low_freq_5g: Low frequency 5G.
592  * @high_freq_5g: High frequency 5G.
593  *
594  * Return: None
595  */
596 static void
597 reg_modify_chan_list_for_freq_range(struct regulatory_channel *chan_list,
598 				    qdf_freq_t low_freq_2g,
599 				    qdf_freq_t high_freq_2g,
600 				    qdf_freq_t low_freq_5g,
601 				    qdf_freq_t high_freq_5g)
602 {
603 	uint32_t low_limit_2g = NUM_CHANNELS;
604 	uint32_t high_limit_2g = NUM_CHANNELS;
605 	uint32_t low_limit_5g = NUM_CHANNELS;
606 	uint32_t high_limit_5g = NUM_CHANNELS;
607 	enum channel_enum chan_enum;
608 	bool chan_in_range;
609 
610 	reg_find_low_limit_chan_enum(chan_list, low_freq_2g, &low_limit_2g);
611 	reg_find_low_limit_chan_enum(chan_list, low_freq_5g, &low_limit_5g);
612 	reg_find_high_limit_chan_enum(chan_list, high_freq_2g, &high_limit_2g);
613 	reg_find_high_limit_chan_enum(chan_list, high_freq_5g, &high_limit_5g);
614 
615 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
616 		chan_in_range = false;
617 		if  ((low_limit_2g <= chan_enum) &&
618 		     (high_limit_2g >= chan_enum) &&
619 		     (low_limit_2g != NUM_CHANNELS) &&
620 		     (high_limit_2g != NUM_CHANNELS))
621 			chan_in_range = true;
622 
623 		if  ((low_limit_5g <= chan_enum) &&
624 		     (high_limit_5g >= chan_enum) &&
625 		     (low_limit_5g != NUM_CHANNELS) &&
626 		     (high_limit_5g != NUM_CHANNELS))
627 			chan_in_range = true;
628 
629 		if (!chan_in_range) {
630 			chan_list[chan_enum].chan_flags |=
631 				REGULATORY_CHAN_DISABLED;
632 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
633 		}
634 	}
635 }
636 
637 #ifdef CONFIG_BAND_6GHZ
638 /**
639  * reg_propagate_6g_mas_channel_list() - Copy master chan list from PSOC to PDEV
640  * @pdev_priv_obj: Pointer to pdev
641  * @mas_chan_params: Master channel parameters
642  *
643  * Return: None
644  */
645 static void reg_propagate_6g_mas_channel_list(
646 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
647 		struct mas_chan_params *mas_chan_params)
648 {
649 	uint8_t i, j;
650 	struct regulatory_channel *src_6g_chan, *dst_6g_chan;
651 	uint32_t size_of_6g_chan_list =
652 		NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel);
653 
654 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
655 		qdf_mem_copy(pdev_priv_obj->mas_chan_list_6g_ap[i],
656 			     mas_chan_params->mas_chan_list_6g_ap[i],
657 			     size_of_6g_chan_list);
658 
659 		for (j = 0; j < REG_MAX_CLIENT_TYPE; j++) {
660 			dst_6g_chan =
661 				pdev_priv_obj->mas_chan_list_6g_client[i][j];
662 			src_6g_chan =
663 				mas_chan_params->mas_chan_list_6g_client[i][j];
664 			qdf_mem_copy(dst_6g_chan, src_6g_chan,
665 				     size_of_6g_chan_list);
666 		}
667 	}
668 
669 	pdev_priv_obj->reg_cur_6g_client_mobility_type =
670 				mas_chan_params->client_type;
671 	pdev_priv_obj->reg_rnr_tpe_usable = mas_chan_params->rnr_tpe_usable;
672 	pdev_priv_obj->reg_unspecified_ap_usable =
673 				mas_chan_params->unspecified_ap_usable;
674 	pdev_priv_obj->is_6g_channel_list_populated =
675 		mas_chan_params->is_6g_channel_list_populated;
676 	pdev_priv_obj->reg_6g_superid =
677 		mas_chan_params->reg_6g_superid;
678 	pdev_priv_obj->reg_cur_6g_ap_pwr_type = REG_INDOOR_AP;
679 }
680 #else
681 static inline void reg_propagate_6g_mas_channel_list(
682 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
683 		struct mas_chan_params *mas_chan_params)
684 {
685 }
686 #endif
687 
688 void reg_init_pdev_mas_chan_list(
689 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
690 		struct mas_chan_params *mas_chan_params)
691 {
692 	qdf_mem_copy(pdev_priv_obj->mas_chan_list,
693 		     mas_chan_params->mas_chan_list,
694 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
695 
696 	reg_propagate_6g_mas_channel_list(pdev_priv_obj, mas_chan_params);
697 
698 	pdev_priv_obj->dfs_region = mas_chan_params->dfs_region;
699 
700 	pdev_priv_obj->phybitmap = mas_chan_params->phybitmap;
701 
702 	pdev_priv_obj->reg_dmn_pair = mas_chan_params->reg_dmn_pair;
703 	pdev_priv_obj->ctry_code =  mas_chan_params->ctry_code;
704 
705 	pdev_priv_obj->def_region_domain = mas_chan_params->reg_dmn_pair;
706 	pdev_priv_obj->def_country_code =  mas_chan_params->ctry_code;
707 
708 	qdf_mem_copy(pdev_priv_obj->default_country,
709 		     mas_chan_params->default_country, REG_ALPHA2_LEN + 1);
710 
711 	qdf_mem_copy(pdev_priv_obj->current_country,
712 		     mas_chan_params->current_country, REG_ALPHA2_LEN + 1);
713 }
714 
715 /**
716  * reg_modify_chan_list_for_cached_channels() - If num_cache_channels are
717  * non-zero, then disable the pdev channels which is given in
718  * cache_disable_chan_list.
719  * @pdev_priv_obj: Pointer to regulatory pdev private object.
720  */
721 #ifdef DISABLE_CHANNEL_LIST
722 static void reg_modify_chan_list_for_cached_channels(
723 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
724 {
725 	uint32_t i, j;
726 	uint32_t num_cache_channels = pdev_priv_obj->num_cache_channels;
727 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
728 	struct regulatory_channel *cache_chan_list =
729 					pdev_priv_obj->cache_disable_chan_list;
730 
731 	if (!num_cache_channels)
732 		return;
733 
734 	if (pdev_priv_obj->disable_cached_channels) {
735 		for (i = 0; i < num_cache_channels; i++)
736 			for (j = 0; j < NUM_CHANNELS; j++)
737 				if (cache_chan_list[i].center_freq ==
738 				    chan_list[j].center_freq) {
739 					chan_list[j].state =
740 							CHANNEL_STATE_DISABLE;
741 					chan_list[j].chan_flags |=
742 						REGULATORY_CHAN_DISABLED;
743 				}
744 	}
745 }
746 #else
747 static void reg_modify_chan_list_for_cached_channels(
748 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
749 {
750 }
751 #endif
752 
753 #ifdef CONFIG_REG_CLIENT
754 /**
755  * reg_modify_chan_list_for_srd_channels() - Modify SRD channels in ETSI13
756  * @pdev: Pointer to pdev object
757  * @chan_list: Current channel list
758  *
759  * This function converts SRD channels to passive in ETSI13 regulatory domain
760  * when enable_srd_chan_in_master_mode is not set.
761  */
762 static void
763 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev,
764 				      struct regulatory_channel *chan_list)
765 {
766 	enum channel_enum chan_enum;
767 
768 	if (!reg_is_etsi13_regdmn(pdev))
769 		return;
770 
771 	if (reg_is_etsi13_srd_chan_allowed_master_mode(pdev))
772 		return;
773 
774 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
775 		if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_DISABLED)
776 			continue;
777 
778 		if (reg_is_etsi13_srd_chan_for_freq(
779 					pdev,
780 					chan_list[chan_enum].center_freq)) {
781 			chan_list[chan_enum].state =
782 				CHANNEL_STATE_DFS;
783 			chan_list[chan_enum].chan_flags |=
784 				REGULATORY_CHAN_NO_IR;
785 		}
786 	}
787 }
788 #else
789 static inline void
790 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev,
791 				      struct regulatory_channel *chan_list)
792 {
793 }
794 #endif
795 
796 #ifdef CONFIG_REG_CLIENT
797 
798 /**
799  * reg_is_disabling_5dot9_needed() - Checks if 5.9GHz channels should
800  * be disabled.
801  * @psoc: Pointer to psoc object
802  *
803  * This function checks only if F/W has enabled the BDF bit for 5.9GHz
804  * channels for AP target and both the BDF bit as well as if offload is
805  * enabled for STA target.
806  */
807 static inline bool
808 reg_is_disabling_5dot9_needed(struct wlan_objmgr_psoc *psoc)
809 {
810 	return (!reg_is_5dot9_ghz_supported(psoc) ||
811 		!reg_is_regdb_offloaded(psoc));
812 }
813 #else
814 static inline bool
815 reg_is_disabling_5dot9_needed(struct wlan_objmgr_psoc *psoc)
816 {
817 	return (!reg_is_5dot9_ghz_supported(psoc));
818 }
819 #endif
820 
821 /**
822  * reg_modify_chan_list_for_5dot9_ghz_channels() - Modify 5.9 GHz channels
823  * in FCC
824  * @pdev: Pointer to pdev object
825  * @chan_list: Current channel list
826  *
827  * This function disables 5.9 GHz channels if service bit
828  * wmi_service_5dot9_ghz_support is not set or the reg db is not offloaded
829  * to FW. If service bit is set but ini enable_5dot9_ghz_chan_in_master_mode
830  * is not set, it converts these channels to passive in FCC regulatory domain.
831  * If both service bit and ini are set, the channels remain enabled.
832  */
833 static void
834 reg_modify_chan_list_for_5dot9_ghz_channels(struct wlan_objmgr_pdev *pdev,
835 					    struct regulatory_channel
836 					    *chan_list)
837 {
838 	enum channel_enum chan_enum;
839 	struct wlan_objmgr_psoc *psoc;
840 
841 	psoc = wlan_pdev_get_psoc(pdev);
842 
843 	if (!reg_is_fcc_regdmn(pdev))
844 		return;
845 
846 	if (reg_is_disabling_5dot9_needed(psoc)) {
847 		for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
848 			if (reg_is_5dot9_ghz_freq(pdev, chan_list[chan_enum].
849 						  center_freq)) {
850 				chan_list[chan_enum].state =
851 					CHANNEL_STATE_DISABLE;
852 				chan_list[chan_enum].chan_flags =
853 					REGULATORY_CHAN_DISABLED;
854 			}
855 		}
856 		return;
857 	}
858 
859 	if (reg_is_5dot9_ghz_chan_allowed_master_mode(pdev))
860 		return;
861 
862 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
863 		if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_DISABLED)
864 			continue;
865 
866 		if (reg_is_5dot9_ghz_freq(pdev,
867 					  chan_list[chan_enum].center_freq)) {
868 			chan_list[chan_enum].state =
869 				CHANNEL_STATE_DFS;
870 			chan_list[chan_enum].chan_flags |=
871 				REGULATORY_CHAN_NO_IR;
872 		}
873 	}
874 }
875 
876 #if defined(CONFIG_BAND_6GHZ)
877 /**
878  * reg_modify_chan_list_for_6g_edge_channels() - Modify 6 GHz edge channels
879  *
880  * @pdev: Pointer to pdev object
881  * @chan_list: Current channel list
882  *
883  * This function disables lower 6G edge channel (5935MHz) if service bit
884  * wmi_service_lower_6g_edge_ch_supp is not set. If service bit is set
885  * the channels remain enabled. It disables upper 6G edge channel (7115MHz)
886  * if the service bit wmi_service_disable_upper_6g_edge_ch_supp is set, it
887  * is enabled by default.
888  *
889  */
890 static void
891 reg_modify_chan_list_for_6g_edge_channels(struct wlan_objmgr_pdev *pdev,
892 					  struct regulatory_channel
893 					  *chan_list)
894 {
895 	struct wlan_objmgr_psoc *psoc;
896 
897 	psoc = wlan_pdev_get_psoc(pdev);
898 
899 	if (!reg_is_lower_6g_edge_ch_supp(psoc)) {
900 		chan_list[CHAN_ENUM_5935].state = CHANNEL_STATE_DISABLE;
901 		chan_list[CHAN_ENUM_5935].chan_flags |=
902 						REGULATORY_CHAN_DISABLED;
903 	}
904 
905 	if (reg_is_upper_6g_edge_ch_disabled(psoc)) {
906 		chan_list[CHAN_ENUM_7115].state = CHANNEL_STATE_DISABLE;
907 		chan_list[CHAN_ENUM_7115].chan_flags |=
908 						REGULATORY_CHAN_DISABLED;
909 	}
910 }
911 #else
912 static inline void
913 reg_modify_chan_list_for_6g_edge_channels(struct wlan_objmgr_pdev *pdev,
914 					  struct regulatory_channel
915 					  *chan_list)
916 {
917 }
918 #endif
919 
920 #ifdef DISABLE_UNII_SHARED_BANDS
921 /**
922  * reg_is_reg_unii_band_1_set() - Check UNII bitmap
923  * @unii_bitmap: 5G UNII band bitmap
924  *
925  * This function checks the input bitmap to disable UNII-1 band channels.
926  *
927  * Return: Return true if UNII-1 channels need to be disabled,
928  * else return false.
929  */
930 static bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap)
931 {
932 	return !!(unii_bitmap & BIT(REG_UNII_BAND_1));
933 }
934 
935 /**
936  * reg_is_reg_unii_band_2a_set() - Check UNII bitmap
937  * @unii_bitmap: 5G UNII band bitmap
938  *
939  * This function checks the input bitmap to disable UNII-2A band channels.
940  *
941  * Return: Return true if UNII-2A channels need to be disabled,
942  * else return false.
943  */
944 static bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap)
945 {
946 	return !!(unii_bitmap & BIT(REG_UNII_BAND_2A));
947 }
948 
949 /**
950  * reg_is_5g_enum() - Check if channel enum is a 5G channel enum
951  * @chan_enum: channel enum
952  *
953  * Return: Return true if the input channel enum is 5G, else return false.
954  */
955 static bool reg_is_5g_enum(enum channel_enum chan_enum)
956 {
957 	return (chan_enum >= MIN_5GHZ_CHANNEL && chan_enum <= MAX_5GHZ_CHANNEL);
958 }
959 
960 /**
961  * reg_remove_unii_chan_from_chan_list() - Remove UNII band channels
962  * @chan_list: Pointer to current channel list
963  * @start_enum: starting enum value
964  * @end_enum: ending enum value
965  *
966  * Remove channels in a unii band based in on the input start_enum and end_enum.
967  * Disable the state and flags. Set disable_coex flag to true.
968  *
969  * return: void.
970  */
971 static void
972 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list,
973 				    enum channel_enum start_enum,
974 				    enum channel_enum end_enum)
975 {
976 	enum channel_enum chan_enum;
977 
978 	if (!(reg_is_5g_enum(start_enum) && reg_is_5g_enum(end_enum))) {
979 		reg_err_rl("start_enum or end_enum is invalid");
980 		return;
981 	}
982 
983 	for (chan_enum = start_enum; chan_enum <= end_enum; chan_enum++) {
984 		chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
985 		chan_list[chan_enum].chan_flags |= REGULATORY_CHAN_DISABLED;
986 	}
987 }
988 
989 /**
990  * reg_modify_disable_chan_list_for_unii1_and_unii2a() - Disable UNII-1 and
991  * UNII2A band
992  * @pdev_priv_obj: Pointer to pdev private object
993  *
994  * This function disables the UNII-1 and UNII-2A band channels
995  * based on input unii_5g_bitmap.
996  *
997  * Return: void.
998  */
999 static void
1000 reg_modify_disable_chan_list_for_unii1_and_unii2a(
1001 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1002 {
1003 	uint8_t unii_bitmap = pdev_priv_obj->unii_5g_bitmap;
1004 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
1005 
1006 	if (reg_is_reg_unii_band_1_set(unii_bitmap)) {
1007 		reg_remove_unii_chan_from_chan_list(chan_list,
1008 						    MIN_UNII_1_BAND_CHANNEL,
1009 						    MAX_UNII_1_BAND_CHANNEL);
1010 	}
1011 
1012 	if (reg_is_reg_unii_band_2a_set(unii_bitmap)) {
1013 		reg_remove_unii_chan_from_chan_list(chan_list,
1014 						    MIN_UNII_2A_BAND_CHANNEL,
1015 						    MAX_UNII_2A_BAND_CHANNEL);
1016 	}
1017 }
1018 #else
1019 static inline bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap)
1020 {
1021 	return false;
1022 }
1023 
1024 static inline bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap)
1025 {
1026 	return false;
1027 }
1028 
1029 static inline bool reg_is_5g_enum(enum channel_enum chan_enum)
1030 {
1031 	return false;
1032 }
1033 
1034 static inline void
1035 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list,
1036 				    enum channel_enum start_enum,
1037 				    enum channel_enum end_enum)
1038 {
1039 }
1040 
1041 static inline void
1042 reg_modify_disable_chan_list_for_unii1_and_unii2a(
1043 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1044 {
1045 }
1046 #endif
1047 
1048 #ifdef CONFIG_BAND_6GHZ
1049 #ifdef CONFIG_REG_CLIENT
1050 static void
1051 reg_append_mas_chan_list_for_6g(struct wlan_regulatory_pdev_priv_obj
1052 				*pdev_priv_obj)
1053 {
1054 	struct regulatory_channel *master_chan_list_6g_client;
1055 
1056 	if (pdev_priv_obj->reg_cur_6g_ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE ||
1057 	    pdev_priv_obj->reg_cur_6g_client_mobility_type >=
1058 	    REG_MAX_CLIENT_TYPE) {
1059 		reg_debug("invalid 6G AP or client power type");
1060 		return;
1061 	}
1062 
1063 	master_chan_list_6g_client =
1064 		pdev_priv_obj->mas_chan_list_6g_client[REG_INDOOR_AP]
1065 			[pdev_priv_obj->reg_cur_6g_client_mobility_type];
1066 
1067 	qdf_mem_copy(&pdev_priv_obj->mas_chan_list[MIN_6GHZ_CHANNEL],
1068 		     master_chan_list_6g_client,
1069 		     NUM_6GHZ_CHANNELS *
1070 		     sizeof(struct regulatory_channel));
1071 }
1072 
1073 static void
1074 reg_populate_secondary_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
1075 				     *pdev_priv_obj)
1076 {
1077 	struct wlan_objmgr_psoc *psoc;
1078 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
1079 
1080 	psoc = wlan_pdev_get_psoc(pdev_priv_obj->pdev_ptr);
1081 	if (!psoc) {
1082 		reg_err("psoc is NULL");
1083 		return;
1084 	}
1085 
1086 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
1087 	if (!reg_tx_ops) {
1088 		reg_err("reg_tx_ops null");
1089 		return;
1090 	}
1091 	if (reg_tx_ops->register_master_ext_handler &&
1092 	    wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_EXT_EVENT_SUPPORTED)) {
1093 		qdf_mem_copy(pdev_priv_obj->secondary_cur_chan_list,
1094 			     pdev_priv_obj->cur_chan_list,
1095 			     (NUM_CHANNELS - NUM_6GHZ_CHANNELS) *
1096 			     sizeof(struct regulatory_channel));
1097 
1098 		qdf_mem_copy(&pdev_priv_obj->
1099 		     secondary_cur_chan_list[MIN_6GHZ_CHANNEL],
1100 		     pdev_priv_obj->mas_chan_list_6g_ap
1101 		     [pdev_priv_obj->reg_cur_6g_ap_pwr_type],
1102 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
1103 	} else {
1104 		qdf_mem_copy(pdev_priv_obj->secondary_cur_chan_list,
1105 			     pdev_priv_obj->cur_chan_list,
1106 			     (NUM_CHANNELS) *
1107 			     sizeof(struct regulatory_channel));
1108 	}
1109 }
1110 #else /* CONFIG_REG_CLIENT */
1111 
1112 /**
1113  * reg_copy_ap_chan_list_to_mas_chan_list() - Copy the 6G ap channel list to
1114  * the MIN_6GHZ_CHANNEL index of the mas_chan_list based on the AP power type
1115  * In case of standard power type, if the afc channel list is available from
1116  * the afc server, use afc channel list (intersected with SP power list)
1117  * for the copy instead of using the standard power list directly.
1118  * @pdev_priv_obj: pointer to pdev_priv_obj.
1119  * @ap_pwr_type: 6G AP power type
1120  *
1121  * Return type: void.
1122  */
1123 #ifdef CONFIG_AFC_SUPPORT
1124 static void
1125 reg_copy_ap_chan_list_to_mas_chan_list(struct wlan_regulatory_pdev_priv_obj
1126 				       *pdev_priv_obj,
1127 				       enum reg_6g_ap_type ap_pwr_type)
1128 {
1129 	if (ap_pwr_type == REG_STANDARD_POWER_AP &&
1130 	    pdev_priv_obj->is_6g_afc_power_event_received) {
1131 		qdf_mem_copy(&pdev_priv_obj->mas_chan_list[MIN_6GHZ_CHANNEL],
1132 			     pdev_priv_obj->afc_chan_list,
1133 			     NUM_6GHZ_CHANNELS *
1134 			     sizeof(struct regulatory_channel));
1135 	} else {
1136 		qdf_mem_copy(&pdev_priv_obj->mas_chan_list[MIN_6GHZ_CHANNEL],
1137 			     pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type],
1138 			     NUM_6GHZ_CHANNELS *
1139 			     sizeof(struct regulatory_channel));
1140 	}
1141 }
1142 #else
1143 static void
1144 reg_copy_ap_chan_list_to_mas_chan_list(struct wlan_regulatory_pdev_priv_obj
1145 				       *pdev_priv_obj,
1146 				       enum reg_6g_ap_type ap_pwr_type)
1147 {
1148 	qdf_mem_copy(&pdev_priv_obj->mas_chan_list[MIN_6GHZ_CHANNEL],
1149 		     pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type],
1150 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
1151 }
1152 #endif
1153 static void
1154 reg_append_mas_chan_list_for_6g(struct wlan_regulatory_pdev_priv_obj
1155 				*pdev_priv_obj)
1156 {
1157 	enum reg_6g_ap_type ap_pwr_type = pdev_priv_obj->reg_cur_6g_ap_pwr_type;
1158 
1159 	if (ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE) {
1160 		reg_debug("invalid 6G AP power type");
1161 		return;
1162 	}
1163 
1164 	reg_copy_ap_chan_list_to_mas_chan_list(pdev_priv_obj, ap_pwr_type);
1165 }
1166 
1167 static inline void
1168 reg_populate_secondary_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
1169 				     *pdev_priv_obj)
1170 {
1171 }
1172 #endif /* CONFIG_REG_CLIENT */
1173 
1174 #ifdef CONFIG_AFC_SUPPORT
1175 /* reg_intersect_6g_afc_chan_list() - Do intersection of tx_powers of AFC master
1176  * channel list and SP channe list and store the power in the AFC channel list.
1177  * @pdev_priv_obj: pointer to pdev_priv_obj.
1178  *
1179  * Return type: void.
1180  */
1181 static void
1182 reg_intersect_6g_afc_chan_list(struct wlan_regulatory_pdev_priv_obj
1183 			       *pdev_priv_obj)
1184 {
1185 	struct regulatory_channel *afc_chan_list;
1186 	struct regulatory_channel *afc_mas_chan_list;
1187 	struct regulatory_channel *sp_chan_list;
1188 	uint8_t i;
1189 
1190 	afc_chan_list = pdev_priv_obj->afc_chan_list;
1191 	afc_mas_chan_list = pdev_priv_obj->mas_chan_list_6g_afc;
1192 	sp_chan_list =
1193 		pdev_priv_obj->mas_chan_list_6g_ap[REG_STANDARD_POWER_AP];
1194 
1195 	qdf_mem_copy(afc_chan_list, afc_mas_chan_list,
1196 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
1197 
1198 	for (i = 0; i < NUM_6GHZ_CHANNELS; i++) {
1199 		if ((afc_chan_list[i].state != CHANNEL_STATE_DISABLE) &&
1200 		    !(afc_chan_list[i].chan_flags &
1201 		      REGULATORY_CHAN_DISABLED)) {
1202 			afc_chan_list[i].tx_power =
1203 				QDF_MIN(sp_chan_list[i].tx_power,
1204 					afc_mas_chan_list[i].tx_power);
1205 			afc_chan_list[i].psd_eirp =
1206 				QDF_MIN((int16_t)sp_chan_list[i].psd_eirp,
1207 					(int16_t)afc_mas_chan_list[i].psd_eirp);
1208 		}
1209 	}
1210 }
1211 
1212 /* reg_modify_6g_afc_chan_list() - Modify the AFC channel list if the AFC WMI
1213  * power event is received from the target
1214  * @pdev_priv_obj: pointer to pdev_priv_obj.
1215  *
1216  * Return type: void.
1217  */
1218 static void
1219 reg_modify_6g_afc_chan_list(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1220 {
1221 	if (pdev_priv_obj->is_6g_afc_power_event_received)
1222 		reg_intersect_6g_afc_chan_list(pdev_priv_obj);
1223 }
1224 #else
1225 static inline void
1226 reg_modify_6g_afc_chan_list(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1227 {
1228 }
1229 #endif
1230 
1231 static void reg_copy_6g_cur_mas_chan_list_to_cmn(
1232 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1233 {
1234 	if (pdev_priv_obj->is_6g_channel_list_populated)
1235 		reg_append_mas_chan_list_for_6g(pdev_priv_obj);
1236 }
1237 #else /* CONFIG_BAND_6GHZ */
1238 static inline void
1239 reg_copy_6g_cur_mas_chan_list_to_cmn(
1240 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1241 {
1242 }
1243 
1244 static inline void
1245 reg_append_mas_chan_list_for_6g(
1246 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1247 {
1248 }
1249 
1250 #ifdef CONFIG_REG_CLIENT
1251 static void
1252 reg_populate_secondary_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
1253 				     *pdev_priv_obj)
1254 {
1255 	qdf_mem_copy(pdev_priv_obj->secondary_cur_chan_list,
1256 		     pdev_priv_obj->mas_chan_list,
1257 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
1258 }
1259 #else /* CONFIG_REG_CLIENT */
1260 static inline void
1261 reg_populate_secondary_cur_chan_list(struct wlan_regulatory_pdev_priv_obj
1262 				     *pdev_priv_obj)
1263 {
1264 }
1265 #endif /* CONFIG_REG_CLIENT */
1266 static inline void
1267 reg_modify_6g_afc_chan_list(struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1268 {
1269 }
1270 #endif /* CONFIG_BAND_6GHZ */
1271 
1272 #ifdef FEATURE_WLAN_CH_AVOID_EXT
1273 struct chan_5g_center_freq center_5g[MAX_5G_CHAN_NUM] = {
1274 	/*36*/
1275 	{5180, 5190, 5210, 5250},
1276 	/*40*/
1277 	{5200, 5190, 5210, 5250},
1278 	/*44*/
1279 	{5220, 5230, 5210, 5250},
1280 	/*48*/
1281 	{5240, 5230, 5210, 5250},
1282 
1283 	/*52*/
1284 	{5260, 5270, 5290, 5250},
1285 	/*56*/
1286 	{5280, 5270, 5290, 5250},
1287 	/*60*/
1288 	{5300, 5310, 5290, 5250},
1289 	/*64*/
1290 	{5320, 5310, 5290, 5250},
1291 
1292 	/*100*/
1293 	{5500, 5510, 5530, 5570},
1294 	/*104*/
1295 	{5520, 5510, 5530, 5570},
1296 	/*108*/
1297 	{5540, 5550, 5530, 5570},
1298 	/*112*/
1299 	{5560, 5550, 5530, 5570},
1300 
1301 	/*116*/
1302 	{5580, 5590, 5610, 5570},
1303 	/*120*/
1304 	{5600, 5590, 5610, 5570},
1305 	/*124*/
1306 	{5620, 5630, 5610, 5570},
1307 	/*128*/
1308 	{5640, 5630, 5610, 5570},
1309 
1310 	/*132*/
1311 	{5660, 5670, 5690, INVALID_CENTER_FREQ},
1312 	/*136*/
1313 	{5680, 5670, 5690, INVALID_CENTER_FREQ},
1314 	/*140*/
1315 	{5700, 5710, 5690, INVALID_CENTER_FREQ},
1316 	/*144*/
1317 	{5720, 5710, 5690, INVALID_CENTER_FREQ},
1318 
1319 	/*149*/
1320 	{5745, 5755, 5775, 5815},
1321 	/*153*/
1322 	{5765, 5755, 5775, 5815},
1323 	/*157*/
1324 	{5785, 5795, 5775, 5815},
1325 	/*161*/
1326 	{5805, 5795, 5775, 5815},
1327 
1328 	/*165*/
1329 	{5825, 5835, 5855, 5815},
1330 	/*169*/
1331 	{5845, 5835, 5855, 5815},
1332 	/*173*/
1333 	{5865, 5875, 5855, 5815},
1334 	/*177*/
1335 	{5885, 5875, 5855, 5815},
1336 };
1337 
1338 /**
1339  * reg_modify_5g_maxbw() - Update the max bandwidth for 5G channel
1340  * @chan: Pointer to current channel
1341  * @avoid_freq: current avoid frequency range
1342  *
1343  * This function updates the max bandwidth for the 5G channels if
1344  * it has overlap with avoid frequency range. For example, if the
1345  * avoid frequency range is []5755-5775], and current channel is 149 with
1346  * max bandwidth 80Mhz by default, then has to change the max bandwidth
1347  * to 20Mhz, since both 40Mhz [5735-5775] and 80M [5735-5815] has
1348  * overlap with avoid frequency [5755-5775].
1349  *
1350  * Return: void.
1351  */
1352 static void
1353 reg_modify_5g_maxbw(struct regulatory_channel *chan,
1354 		    struct ch_avoid_freq_type *avoid_freq)
1355 {
1356 	int i;
1357 	qdf_freq_t start, end, cur;
1358 	bool found = false;
1359 
1360 	for (i = 0; i < MAX_5G_CHAN_NUM; i++) {
1361 		cur = center_5g[i].center_freq_20;
1362 		if (chan->center_freq == cur) {
1363 			while (!found) {
1364 				uint16_t h_bw;
1365 
1366 				if (chan->max_bw < 20 ||
1367 				    chan->max_bw > 160)
1368 					break;
1369 
1370 				switch (chan->max_bw) {
1371 				case 160:
1372 					cur = center_5g[i].center_freq_160;
1373 					if (!cur) {
1374 						chan->max_bw = chan->max_bw / 2;
1375 						break;
1376 					}
1377 					start = cur - HALF_160MHZ_BW;
1378 					end = cur + HALF_160MHZ_BW;
1379 					break;
1380 				case 80:
1381 					cur = center_5g[i].center_freq_80;
1382 					start = cur - HALF_80MHZ_BW;
1383 					end = cur + HALF_80MHZ_BW;
1384 					break;
1385 				case 40:
1386 					cur = center_5g[i].center_freq_40;
1387 					start = cur - HALF_40MHZ_BW;
1388 					end = cur + HALF_40MHZ_BW;
1389 					break;
1390 				case 20:
1391 					cur = center_5g[i].center_freq_20;
1392 					start = cur - HALF_20MHZ_BW;
1393 					end = cur + HALF_20MHZ_BW;
1394 					break;
1395 				default:
1396 					break;
1397 				}
1398 
1399 				if (avoid_freq->end_freq <= end &&
1400 				    avoid_freq->start_freq >= start) {
1401 					/* avoid freq inside */
1402 					h_bw = chan->max_bw / 2;
1403 					chan->max_bw = min(chan->max_bw, h_bw);
1404 					continue;
1405 				} else if ((avoid_freq->start_freq > start &&
1406 					   avoid_freq->start_freq < end) ||
1407 					   (avoid_freq->end_freq > start &&
1408 					   avoid_freq->end_freq < end)) {
1409 					/* avoid freq part overlap */
1410 					h_bw = chan->max_bw / 2;
1411 					chan->max_bw = min(chan->max_bw, h_bw);
1412 					continue;
1413 				} else if (avoid_freq->start_freq >= end ||
1414 					   avoid_freq->end_freq <= start) {
1415 					/* beyond the range freq */
1416 					found = true;
1417 				}
1418 			}
1419 		}
1420 	}
1421 }
1422 
1423 /**
1424  * reg_modify_chan_list_for_avoid_chan_ext() - Update the state and bandwidth
1425  * for each channel in the current channel list.
1426  * @pdev_priv_obj: Pointer to wlan regulatory pdev private object.
1427  *
1428  * This function update the state and bandwidth for each channel in the current
1429  * channel list if it is affected by avoid frequency list.
1430  * For 2.4G/5G, all the center frequency of specific channel in the
1431  * avoid_chan_ext_list (avoid frequency list) will be disabled.
1432  * For example, avoid frequency list include [2412,2417,2422],
1433  * then channel 1, 2 and 3 will be disabled. Same logic apply for 5g.
1434  * For 5G, if the max bandwidth of the channel affected by avoid frequency
1435  * range then need to reduce the bandwidth or finally disabled.
1436  * For other bands, to-do in furture if need.
1437  *
1438  * Return: void.
1439  */
1440 static void
1441 reg_modify_chan_list_for_avoid_chan_ext(struct wlan_regulatory_pdev_priv_obj
1442 				     *pdev_priv_obj)
1443 {
1444 	uint32_t i, j, k;
1445 	struct wlan_objmgr_psoc *psoc;
1446 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1447 	uint32_t num_avoid_channels;
1448 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
1449 	struct regulatory_channel *sec_chan_list;
1450 	uint16_t *avoid_chan_ext_list;
1451 	uint32_t num_avoid_freq;
1452 	struct ch_avoid_freq_type *avoid_freq_ext, *avoid_freq_ext_t;
1453 
1454 	sec_chan_list = pdev_priv_obj->secondary_cur_chan_list;
1455 
1456 	avoid_chan_ext_list = pdev_priv_obj->avoid_chan_ext_list.chan_freq_list;
1457 	num_avoid_channels = pdev_priv_obj->avoid_chan_ext_list.chan_cnt;
1458 
1459 	psoc = wlan_pdev_get_psoc(pdev_priv_obj->pdev_ptr);
1460 	if (!psoc)
1461 		return;
1462 
1463 	psoc_priv_obj = reg_get_psoc_obj(psoc);
1464 	if (!psoc_priv_obj)
1465 		return;
1466 
1467 	if (!num_avoid_channels || !psoc_priv_obj->ch_avoid_ext_ind)
1468 		return;
1469 
1470 	num_avoid_freq = psoc_priv_obj->avoid_freq_ext_list.ch_avoid_range_cnt;
1471 	avoid_freq_ext = psoc_priv_obj->avoid_freq_ext_list.avoid_freq_range;
1472 
1473 	for (i = 0; i < num_avoid_channels; i++)
1474 		for (j = 0; j < NUM_CHANNELS; j++) {
1475 			qdf_freq_t c_freq, avoid_tmp = avoid_chan_ext_list[i];
1476 
1477 			if (chan_list[j].state == CHANNEL_STATE_DISABLE)
1478 				goto second_chan_handle;
1479 
1480 			/* For 2.4G, just only disable the channel if center
1481 			 * frequecy is in avoid_chan_ext_list.
1482 			 * For 5G, customer ask for bandwidth reduction if
1483 			 * it affect by the nearby channel that in the
1484 			 * avoid_chan_ext_list.
1485 			 * For example, if block out frequency range is
1486 			 * [5755-5775], then except for channel 153 need
1487 			 * to be disabled, and 149 has to change max 80Mhz
1488 			 * to 20Mhz, since 149 only has [5735-5755] available.
1489 			 * channel 157/161 [5775-5815] has to change max 80
1490 			 * to 40.
1491 			 * For 6G: to-do in future.
1492 			 */
1493 			c_freq = chan_list[j].center_freq;
1494 			if (avoid_tmp == c_freq) {
1495 				chan_list[j].state = CHANNEL_STATE_DISABLE;
1496 				chan_list[j].chan_flags |=
1497 					REGULATORY_CHAN_DISABLED;
1498 			} else if (reg_is_5ghz_ch_freq(c_freq)) {
1499 				for (k = 0; k < num_avoid_freq; k++) {
1500 					qdf_freq_t s_freq, e_freq;
1501 
1502 					avoid_freq_ext_t = &avoid_freq_ext[k];
1503 					s_freq = avoid_freq_ext_t->start_freq;
1504 					e_freq = avoid_freq_ext_t->end_freq;
1505 
1506 					/* need to cover [5170-5190] case*/
1507 					if ((!reg_is_5ghz_ch_freq(s_freq) &&
1508 					     ((s_freq + HALF_20MHZ_BW) <
1509 					       reg_min_5ghz_chan_freq())) ||
1510 					    (!reg_is_5ghz_ch_freq(e_freq) &&
1511 					      ((e_freq - HALF_20MHZ_BW) >
1512 					       reg_max_5ghz_chan_freq())))
1513 						continue;
1514 
1515 					/* if current center freq is in the
1516 					 * avoid rang, then skip it, it will be
1517 					 * handled in the branch (avoid_tmp
1518 					 * == c_freq)
1519 					 */
1520 					if ((c_freq > s_freq &&
1521 					     c_freq < e_freq))
1522 						continue;
1523 
1524 					reg_modify_5g_maxbw(&chan_list[j],
1525 							    avoid_freq_ext_t);
1526 
1527 					if (chan_list[j].max_bw <
1528 					    HALF_40MHZ_BW) {
1529 						chan_list[j].state =
1530 							CHANNEL_STATE_DISABLE;
1531 						chan_list[j].chan_flags |=
1532 						REGULATORY_CHAN_DISABLED;
1533 						break;
1534 					}
1535 				}
1536 			}
1537 second_chan_handle:
1538 
1539 			if (sec_chan_list[j].state ==
1540 			   CHANNEL_STATE_DISABLE)
1541 				continue;
1542 
1543 			c_freq = sec_chan_list[j].center_freq;
1544 			if (avoid_tmp == c_freq) {
1545 				sec_chan_list[j].state = CHANNEL_STATE_DISABLE;
1546 				sec_chan_list[j].chan_flags |=
1547 					REGULATORY_CHAN_DISABLED;
1548 			} else if (reg_is_5ghz_ch_freq(c_freq)) {
1549 				for (k = 0; k < num_avoid_freq; k++) {
1550 					qdf_freq_t s_freq, e_freq;
1551 
1552 					avoid_freq_ext_t = &avoid_freq_ext[k];
1553 					s_freq = avoid_freq_ext_t->start_freq;
1554 					e_freq = avoid_freq_ext_t->end_freq;
1555 
1556 					/* need to cover [5170-5190] case*/
1557 					if ((!reg_is_5ghz_ch_freq(s_freq) &&
1558 					     ((s_freq + HALF_20MHZ_BW) <
1559 					       reg_min_5ghz_chan_freq())) ||
1560 					    (!reg_is_5ghz_ch_freq(e_freq) &&
1561 					      ((e_freq - HALF_20MHZ_BW) >
1562 					       reg_max_5ghz_chan_freq())))
1563 						continue;
1564 
1565 					/* if current center freq is in the
1566 					 * avoid rang, then skip it, it will be
1567 					 * handled in the branch (avoid_tmp
1568 					 * == c_freq)
1569 					 */
1570 					if ((c_freq > s_freq &&
1571 					     c_freq < e_freq))
1572 						continue;
1573 
1574 					reg_modify_5g_maxbw(&sec_chan_list[j],
1575 							    avoid_freq_ext_t);
1576 
1577 					if (sec_chan_list[j].max_bw <
1578 					    HALF_40MHZ_BW) {
1579 						sec_chan_list[j].state =
1580 							CHANNEL_STATE_DISABLE;
1581 						sec_chan_list[j].chan_flags |=
1582 						REGULATORY_CHAN_DISABLED;
1583 						break;
1584 					}
1585 				}
1586 			}
1587 		}
1588 }
1589 #else
1590 static inline void
1591 reg_modify_chan_list_for_avoid_chan_ext(struct wlan_regulatory_pdev_priv_obj
1592 				     *pdev_priv_obj)
1593 {
1594 }
1595 #endif
1596 
1597 void reg_compute_pdev_current_chan_list(struct wlan_regulatory_pdev_priv_obj
1598 					*pdev_priv_obj)
1599 {
1600 	reg_modify_6g_afc_chan_list(pdev_priv_obj);
1601 
1602 	reg_copy_6g_cur_mas_chan_list_to_cmn(pdev_priv_obj);
1603 
1604 	qdf_mem_copy(pdev_priv_obj->cur_chan_list, pdev_priv_obj->mas_chan_list,
1605 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
1606 
1607 	reg_modify_chan_list_for_freq_range(pdev_priv_obj->cur_chan_list,
1608 					    pdev_priv_obj->range_2g_low,
1609 					    pdev_priv_obj->range_2g_high,
1610 					    pdev_priv_obj->range_5g_low,
1611 					    pdev_priv_obj->range_5g_high);
1612 
1613 	reg_modify_chan_list_for_band(pdev_priv_obj->cur_chan_list,
1614 				      pdev_priv_obj->band_capability);
1615 
1616 	reg_modify_disable_chan_list_for_unii1_and_unii2a(pdev_priv_obj);
1617 
1618 	reg_modify_chan_list_for_dfs_channels(pdev_priv_obj->cur_chan_list,
1619 					      pdev_priv_obj->dfs_enabled);
1620 
1621 	reg_modify_chan_list_for_nol_list(pdev_priv_obj->cur_chan_list);
1622 
1623 	reg_modify_chan_list_for_indoor_channels(pdev_priv_obj);
1624 
1625 	reg_modify_chan_list_for_fcc_channel(pdev_priv_obj->cur_chan_list,
1626 					     pdev_priv_obj->set_fcc_channel);
1627 
1628 	reg_modify_chan_list_for_chan_144(pdev_priv_obj->cur_chan_list,
1629 					  pdev_priv_obj->en_chan_144);
1630 
1631 	reg_modify_chan_list_for_cached_channels(pdev_priv_obj);
1632 
1633 	reg_modify_chan_list_for_srd_channels(pdev_priv_obj->pdev_ptr,
1634 					      pdev_priv_obj->cur_chan_list);
1635 
1636 	reg_modify_chan_list_for_5dot9_ghz_channels(pdev_priv_obj->pdev_ptr,
1637 						    pdev_priv_obj->
1638 						    cur_chan_list);
1639 
1640 	reg_modify_chan_list_for_max_chwidth(pdev_priv_obj->pdev_ptr,
1641 					     pdev_priv_obj->cur_chan_list);
1642 
1643 	reg_modify_chan_list_for_6g_edge_channels(pdev_priv_obj->pdev_ptr,
1644 						  pdev_priv_obj->
1645 						  cur_chan_list);
1646 
1647 	reg_populate_secondary_cur_chan_list(pdev_priv_obj);
1648 
1649 	reg_modify_chan_list_for_avoid_chan_ext(pdev_priv_obj);
1650 }
1651 
1652 void reg_reset_reg_rules(struct reg_rule_info *reg_rules)
1653 {
1654 	qdf_mem_zero(reg_rules, sizeof(*reg_rules));
1655 }
1656 
1657 #ifdef CONFIG_REG_CLIENT
1658 #ifdef CONFIG_BAND_6GHZ
1659 /**
1660  * reg_copy_6g_reg_rules() - Copy the 6G reg rules from PSOC to PDEV
1661  * @pdev_reg_rules: Pointer to pdev reg rules
1662  * @psoc_reg_rules: Pointer to psoc reg rules
1663  *
1664  * Return: void
1665  */
1666 static void reg_copy_6g_reg_rules(struct reg_rule_info *pdev_reg_rules,
1667 				  struct reg_rule_info *psoc_reg_rules)
1668 {
1669 	uint32_t reg_rule_len_6g_ap, reg_rule_len_6g_client;
1670 	uint8_t i;
1671 
1672 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
1673 		pdev_reg_rules->num_of_6g_ap_reg_rules[i] =
1674 			psoc_reg_rules->num_of_6g_ap_reg_rules[i];
1675 		reg_rule_len_6g_ap = psoc_reg_rules->num_of_6g_ap_reg_rules[i] *
1676 						sizeof(struct cur_reg_rule);
1677 		qdf_mem_copy(pdev_reg_rules->reg_rules_6g_ap[i],
1678 			     psoc_reg_rules->reg_rules_6g_ap[i],
1679 			     reg_rule_len_6g_ap);
1680 
1681 		pdev_reg_rules->num_of_6g_client_reg_rules[i] =
1682 			psoc_reg_rules->num_of_6g_client_reg_rules[i];
1683 		reg_rule_len_6g_client =
1684 			psoc_reg_rules->num_of_6g_client_reg_rules[i] *
1685 						sizeof(struct cur_reg_rule);
1686 		qdf_mem_copy(pdev_reg_rules->reg_rules_6g_client[i],
1687 			     psoc_reg_rules->reg_rules_6g_client[i],
1688 			     reg_rule_len_6g_client);
1689 	}
1690 }
1691 
1692 /**
1693  * reg_append_6g_reg_rules_in_pdev() - Append the 6G reg rules to the reg rules
1694  * list in pdev so that all currently used reg rules are in one common list
1695  * @pdev_priv_obj: Pointer to pdev private object
1696  *
1697  * Return: void
1698  */
1699 static void reg_append_6g_reg_rules_in_pdev(
1700 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1701 {
1702 	struct reg_rule_info *pdev_reg_rules;
1703 	enum reg_6g_ap_type cur_pwr_type = REG_INDOOR_AP;
1704 	uint8_t num_reg_rules;
1705 
1706 	pdev_reg_rules = &pdev_priv_obj->reg_rules;
1707 
1708 	num_reg_rules = pdev_reg_rules->num_of_reg_rules;
1709 	pdev_reg_rules->num_of_reg_rules +=
1710 		pdev_reg_rules->num_of_6g_client_reg_rules[cur_pwr_type];
1711 
1712 	qdf_mem_copy(&pdev_reg_rules->reg_rules[num_reg_rules],
1713 		     pdev_reg_rules->reg_rules_6g_client[cur_pwr_type],
1714 		     pdev_reg_rules->num_of_6g_client_reg_rules[cur_pwr_type] *
1715 		     sizeof(struct cur_reg_rule));
1716 }
1717 
1718 #else /* CONFIG_BAND_6GHZ */
1719 static inline void reg_copy_6g_reg_rules(struct reg_rule_info *pdev_reg_rules,
1720 					 struct reg_rule_info *psoc_reg_rules)
1721 {
1722 }
1723 
1724 static inline void reg_append_6g_reg_rules_in_pdev(
1725 			struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1726 {
1727 }
1728 #endif /* CONFIG_BAND_6GHZ */
1729 
1730 void reg_save_reg_rules_to_pdev(
1731 		struct reg_rule_info *psoc_reg_rules,
1732 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
1733 {
1734 	uint32_t reg_rule_len;
1735 	struct reg_rule_info *pdev_reg_rules;
1736 
1737 	qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock);
1738 
1739 	pdev_reg_rules = &pdev_priv_obj->reg_rules;
1740 	reg_reset_reg_rules(pdev_reg_rules);
1741 
1742 	pdev_reg_rules->num_of_reg_rules = psoc_reg_rules->num_of_reg_rules;
1743 	if (!pdev_reg_rules->num_of_reg_rules) {
1744 		qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock);
1745 		reg_err("no reg rules in psoc");
1746 		return;
1747 	}
1748 
1749 	reg_rule_len = pdev_reg_rules->num_of_reg_rules *
1750 		       sizeof(struct cur_reg_rule);
1751 	qdf_mem_copy(pdev_reg_rules->reg_rules, psoc_reg_rules->reg_rules,
1752 		     reg_rule_len);
1753 
1754 	reg_copy_6g_reg_rules(pdev_reg_rules, psoc_reg_rules);
1755 	reg_append_6g_reg_rules_in_pdev(pdev_priv_obj);
1756 
1757 	qdf_mem_copy(pdev_reg_rules->alpha2, pdev_priv_obj->current_country,
1758 		     REG_ALPHA2_LEN + 1);
1759 	pdev_reg_rules->dfs_region = pdev_priv_obj->dfs_region;
1760 
1761 	qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock);
1762 }
1763 #endif /* CONFIG_REG_CLIENT */
1764 
1765 void reg_propagate_mas_chan_list_to_pdev(struct wlan_objmgr_psoc *psoc,
1766 					 void *object, void *arg)
1767 {
1768 	struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object;
1769 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
1770 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1771 	enum direction *dir = arg;
1772 	uint8_t pdev_id;
1773 	uint8_t phy_id;
1774 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
1775 	struct reg_rule_info *psoc_reg_rules;
1776 
1777 	psoc_priv_obj = (struct wlan_regulatory_psoc_priv_obj *)
1778 		wlan_objmgr_psoc_get_comp_private_obj(
1779 				psoc, WLAN_UMAC_COMP_REGULATORY);
1780 
1781 	if (!psoc_priv_obj) {
1782 		reg_err("psoc priv obj is NULL");
1783 		return;
1784 	}
1785 
1786 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1787 
1788 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1789 		reg_err("reg pdev priv obj is NULL");
1790 		return;
1791 	}
1792 
1793 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
1794 
1795 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
1796 	if (reg_tx_ops->get_phy_id_from_pdev_id)
1797 		reg_tx_ops->get_phy_id_from_pdev_id(psoc, pdev_id, &phy_id);
1798 	else
1799 		phy_id = pdev_id;
1800 
1801 	reg_init_pdev_mas_chan_list(
1802 			pdev_priv_obj,
1803 			&psoc_priv_obj->mas_chan_params[phy_id]);
1804 	psoc_reg_rules = &psoc_priv_obj->mas_chan_params[phy_id].reg_rules;
1805 	reg_save_reg_rules_to_pdev(psoc_reg_rules, pdev_priv_obj);
1806 	reg_modify_chan_list_for_japan(pdev);
1807 	pdev_priv_obj->chan_list_recvd =
1808 		psoc_priv_obj->chan_list_recvd[phy_id];
1809 
1810 	reg_update_max_phymode_chwidth_for_pdev(pdev);
1811 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
1812 
1813 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
1814 		reg_tx_ops->fill_umac_legacy_chanlist(
1815 				pdev, pdev_priv_obj->cur_chan_list);
1816 	} else {
1817 		if (*dir == NORTHBOUND)
1818 			reg_send_scheduler_msg_nb(psoc, pdev);
1819 		else
1820 			reg_send_scheduler_msg_sb(psoc, pdev);
1821 	}
1822 }
1823 
1824 /**
1825  * reg_populate_49g_band_channels() - For all the valid 4.9GHz regdb channels
1826  * in the master channel list, find the regulatory rules and call
1827  * reg_fill_channel_info() to populate master channel list with txpower,
1828  * antennagain, BW info, etc.
1829  * @reg_rule_5g: Pointer to regulatory rule.
1830  * @num_5g_reg_rules: Number of regulatory rules.
1831  * @min_bw_5g: Minimum regulatory bandwidth.
1832  * @mas_chan_list: Pointer to the master channel list.
1833  */
1834 #ifdef CONFIG_49GHZ_CHAN
1835 static void
1836 reg_populate_49g_band_channels(struct cur_reg_rule *reg_rule_5g,
1837 			       uint32_t num_5g_reg_rules,
1838 			       uint16_t min_bw_5g,
1839 			       struct regulatory_channel *mas_chan_list)
1840 {
1841 	reg_populate_band_channels(MIN_49GHZ_CHANNEL,
1842 				   MAX_49GHZ_CHANNEL,
1843 				   reg_rule_5g,
1844 				   num_5g_reg_rules,
1845 				   min_bw_5g,
1846 				   mas_chan_list);
1847 }
1848 #else
1849 static void
1850 reg_populate_49g_band_channels(struct cur_reg_rule *reg_rule_5g,
1851 			       uint32_t num_5g_reg_rules,
1852 			       uint16_t min_bw_5g,
1853 			       struct regulatory_channel *mas_chan_list)
1854 {
1855 }
1856 #endif /* CONFIG_49GHZ_CHAN */
1857 
1858 /**
1859  * reg_populate_6g_band_channels() - For all the valid 6GHz regdb channels
1860  * in the master channel list, find the regulatory rules and call
1861  * reg_fill_channel_info() to populate master channel list with txpower,
1862  * antennagain, BW info, etc.
1863  * @reg_rule_5g: Pointer to regulatory rule.
1864  * @num_5g_reg_rules: Number of regulatory rules.
1865  * @min_bw_5g: Minimum regulatory bandwidth.
1866  * @mas_chan_list: Pointer to the master channel list.
1867  */
1868 #ifdef CONFIG_BAND_6GHZ
1869 static void
1870 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g,
1871 			      uint32_t num_5g_reg_rules,
1872 			      uint16_t min_bw_5g,
1873 			      struct regulatory_channel *mas_chan_list)
1874 {
1875 	reg_populate_band_channels(MIN_6GHZ_CHANNEL,
1876 				   MAX_6GHZ_CHANNEL,
1877 				   reg_rule_5g,
1878 				   num_5g_reg_rules,
1879 				   min_bw_5g,
1880 				   mas_chan_list);
1881 }
1882 #else
1883 static void
1884 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g,
1885 			      uint32_t num_5g_reg_rules,
1886 			      uint16_t min_bw_5g,
1887 			      struct regulatory_channel *mas_chan_list)
1888 {
1889 }
1890 #endif /* CONFIG_BAND_6GHZ */
1891 
1892 #ifdef CONFIG_REG_CLIENT
1893 /**
1894  * reg_send_ctl_info() - Send CTL info to firmware when regdb is not offloaded
1895  * @soc_reg: soc private object for regulatory
1896  * @regulatory_info: regulatory info
1897  * @tx_ops: send operations for regulatory component
1898  *
1899  * Return: QDF_STATUS
1900  */
1901 static QDF_STATUS
1902 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg,
1903 		  struct cur_regulatory_info *regulatory_info,
1904 		  struct wlan_lmac_if_reg_tx_ops *tx_ops)
1905 {
1906 	struct wlan_objmgr_psoc *psoc = regulatory_info->psoc;
1907 	struct reg_ctl_params params = {0};
1908 	QDF_STATUS status;
1909 	uint16_t regd_index;
1910 	uint32_t index_2g, index_5g;
1911 
1912 	if (soc_reg->offload_enabled)
1913 		return QDF_STATUS_SUCCESS;
1914 
1915 	if (!tx_ops || !tx_ops->send_ctl_info) {
1916 		reg_err("No regulatory tx_ops");
1917 		return QDF_STATUS_E_FAULT;
1918 	}
1919 
1920 	status = reg_get_rdpair_from_regdmn_id(regulatory_info->reg_dmn_pair,
1921 					       &regd_index);
1922 	if (QDF_IS_STATUS_ERROR(status)) {
1923 		reg_err("Failed to get regdomain index for regdomain pair: %x",
1924 			regulatory_info->reg_dmn_pair);
1925 		return status;
1926 	}
1927 
1928 	index_2g = g_reg_dmn_pairs[regd_index].dmn_id_2g;
1929 	index_5g = g_reg_dmn_pairs[regd_index].dmn_id_5g;
1930 	params.ctl_2g = regdomains_2g[index_2g].ctl_val;
1931 	params.ctl_5g = regdomains_5g[index_5g].ctl_val;
1932 	params.regd_2g = reg_2g_sub_dmn_code[index_2g];
1933 	params.regd_5g = reg_5g_sub_dmn_code[index_5g];
1934 
1935 	if (reg_is_world_ctry_code(regulatory_info->reg_dmn_pair))
1936 		params.regd = regulatory_info->reg_dmn_pair;
1937 	else
1938 		params.regd = regulatory_info->ctry_code | COUNTRY_ERD_FLAG;
1939 
1940 	reg_debug("regdomain pair = %u, regdomain index = %u",
1941 		  regulatory_info->reg_dmn_pair, regd_index);
1942 	reg_debug("index_2g = %u, index_5g = %u, ctl_2g = %x, ctl_5g = %x",
1943 		  index_2g, index_5g, params.ctl_2g, params.ctl_5g);
1944 	reg_debug("regd_2g = %x, regd_5g = %x, regd = %x",
1945 		  params.regd_2g, params.regd_5g, params.regd);
1946 
1947 	status = tx_ops->send_ctl_info(psoc, &params);
1948 	if (QDF_IS_STATUS_ERROR(status))
1949 		reg_err("Failed to send CTL info to firmware");
1950 
1951 	return status;
1952 }
1953 #else
1954 static QDF_STATUS
1955 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg,
1956 		  struct cur_regulatory_info *regulatory_info,
1957 		  struct wlan_lmac_if_reg_tx_ops *tx_ops)
1958 {
1959 	return QDF_STATUS_SUCCESS;
1960 }
1961 #endif
1962 
1963 /**
1964  * reg_soc_vars_reset_on_failure() - Reset the PSOC private object variables
1965  *	when there is a failure
1966  * @status_code: status code of CC setting event
1967  * @soc_reg: soc private object for regulatory
1968  * @tx_ops: send operations for regulatory component
1969  * @psoc: pointer to PSOC object
1970  * @dbg_id: object manager reference debug ID
1971  * @phy_id: physical ID
1972  *
1973  * Return: QDF_STATUS
1974  */
1975 static QDF_STATUS
1976 reg_soc_vars_reset_on_failure(enum cc_setting_code status_code,
1977 			      struct wlan_regulatory_psoc_priv_obj *soc_reg,
1978 			      struct wlan_lmac_if_reg_tx_ops *tx_ops,
1979 			      struct wlan_objmgr_psoc *psoc,
1980 			      wlan_objmgr_ref_dbgid dbg_id,
1981 			      uint8_t phy_id)
1982 {
1983 	struct wlan_objmgr_pdev *pdev;
1984 
1985 	if (status_code != REG_SET_CC_STATUS_PASS) {
1986 		reg_err("Set country code failed, status code %d",
1987 			status_code);
1988 
1989 		pdev = wlan_objmgr_get_pdev_by_id(psoc, phy_id, dbg_id);
1990 		if (!pdev) {
1991 			reg_err("pdev is NULL");
1992 			return QDF_STATUS_E_FAILURE;
1993 		}
1994 
1995 		if (tx_ops->set_country_failed)
1996 			tx_ops->set_country_failed(pdev);
1997 
1998 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
1999 
2000 		if (status_code != REG_CURRENT_ALPHA2_NOT_FOUND)
2001 			return QDF_STATUS_E_FAILURE;
2002 
2003 		soc_reg->new_user_ctry_pending[phy_id] = false;
2004 		soc_reg->new_11d_ctry_pending[phy_id] = false;
2005 		soc_reg->world_country_pending[phy_id] = true;
2006 	}
2007 
2008 	return QDF_STATUS_SUCCESS;
2009 }
2010 
2011 /**
2012  * reg_init_chan() - Initialize the channel list from the channel_map global
2013  *	list
2014  * @dst_list: list to initialize
2015  * @beg_enum: starting point in list(inclusive)
2016  * @end_enum: ending point in list(inclusive)
2017  * @dst_idx_adj: offset between channel_map and dst_list
2018  * @soc_reg: soc private object for regulatory
2019  *
2020  * Return: none
2021  */
2022 static void reg_init_chan(struct regulatory_channel *dst_list,
2023 			  enum channel_enum beg_enum,
2024 			  enum channel_enum end_enum, uint8_t dst_idx_adj,
2025 			  struct wlan_regulatory_psoc_priv_obj *soc_reg)
2026 {
2027 	enum channel_enum chan_enum;
2028 	uint8_t dst_idx;
2029 
2030 	for (chan_enum = beg_enum; chan_enum <= end_enum; chan_enum++) {
2031 		dst_idx = chan_enum - dst_idx_adj;
2032 
2033 		dst_list[dst_idx].chan_num = channel_map[chan_enum].chan_num;
2034 		dst_list[dst_idx].center_freq =
2035 					channel_map[chan_enum].center_freq;
2036 		dst_list[dst_idx].chan_flags = REGULATORY_CHAN_DISABLED;
2037 		dst_list[dst_idx].state = CHANNEL_STATE_DISABLE;
2038 		if (!soc_reg->retain_nol_across_regdmn_update)
2039 			dst_list[dst_idx].nol_chan = false;
2040 	}
2041 }
2042 
2043 static void reg_init_legacy_master_chan(struct regulatory_channel *dst_list,
2044 				struct wlan_regulatory_psoc_priv_obj *soc_reg)
2045 {
2046 	reg_init_chan(dst_list, 0, NUM_CHANNELS - 1, 0, soc_reg);
2047 }
2048 
2049 #ifdef CONFIG_BAND_6GHZ
2050 static void reg_init_2g_5g_master_chan(struct regulatory_channel *dst_list,
2051 				struct wlan_regulatory_psoc_priv_obj *soc_reg)
2052 {
2053 	reg_init_chan(dst_list, 0, MAX_5GHZ_CHANNEL, 0, soc_reg);
2054 }
2055 
2056 static void reg_init_6g_master_chan(struct regulatory_channel *dst_list,
2057 				struct wlan_regulatory_psoc_priv_obj *soc_reg)
2058 {
2059 	reg_init_chan(dst_list, MIN_6GHZ_CHANNEL, MAX_6GHZ_CHANNEL,
2060 		      MIN_6GHZ_CHANNEL, soc_reg);
2061 }
2062 
2063 /**
2064  * reg_store_regulatory_ext_info_to_socpriv() - Copy ext info from regulatory
2065  *	to regulatory PSOC private obj
2066  * @soc_reg: soc private object for regulatory
2067  * @regulat_info: regulatory info from CC event
2068  * @phy_id: physical ID
2069  *
2070  * Return: none
2071  */
2072 static void reg_store_regulatory_ext_info_to_socpriv(
2073 				struct wlan_regulatory_psoc_priv_obj *soc_reg,
2074 				struct cur_regulatory_info *regulat_info,
2075 				uint8_t phy_id)
2076 {
2077 	uint32_t i;
2078 
2079 	soc_reg->num_phy = regulat_info->num_phy;
2080 	soc_reg->mas_chan_params[phy_id].phybitmap = regulat_info->phybitmap;
2081 	soc_reg->mas_chan_params[phy_id].dfs_region = regulat_info->dfs_region;
2082 	soc_reg->mas_chan_params[phy_id].ctry_code = regulat_info->ctry_code;
2083 	soc_reg->mas_chan_params[phy_id].reg_dmn_pair =
2084 		regulat_info->reg_dmn_pair;
2085 	soc_reg->mas_chan_params[phy_id].reg_6g_superid =
2086 		regulat_info->domain_code_6g_super_id;
2087 	qdf_mem_copy(soc_reg->mas_chan_params[phy_id].current_country,
2088 		     regulat_info->alpha2,
2089 		     REG_ALPHA2_LEN + 1);
2090 	qdf_mem_copy(soc_reg->cur_country,
2091 		     regulat_info->alpha2,
2092 		     REG_ALPHA2_LEN + 1);
2093 	reg_debug("set cur_country %.2s", soc_reg->cur_country);
2094 
2095 	soc_reg->mas_chan_params[phy_id].ap_pwr_type = REG_INDOOR_AP;
2096 	soc_reg->mas_chan_params[phy_id].client_type =
2097 					regulat_info->client_type;
2098 	soc_reg->mas_chan_params[phy_id].rnr_tpe_usable =
2099 					regulat_info->rnr_tpe_usable;
2100 	soc_reg->mas_chan_params[phy_id].unspecified_ap_usable =
2101 					regulat_info->unspecified_ap_usable;
2102 
2103 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2104 		soc_reg->domain_code_6g_ap[i] =
2105 			regulat_info->domain_code_6g_ap[i];
2106 
2107 		soc_reg->mas_chan_params[phy_id].
2108 			is_6g_channel_list_populated = true;
2109 
2110 		qdf_mem_copy(soc_reg->domain_code_6g_client[i],
2111 			     regulat_info->domain_code_6g_client[i],
2112 			     REG_MAX_CLIENT_TYPE * sizeof(uint8_t));
2113 	}
2114 }
2115 
2116 /**
2117  * reg_fill_master_channels() - Fill the master channel lists based on the
2118  *	regulatory rules
2119  * @regulat_info: regulatory info
2120  * @reg_rules: regulatory rules
2121  * @client_mobility_type: client mobility type
2122  * @mas_chan_list_2g_5g: master chan list to fill with 2GHz and 5GHz channels
2123  * @mas_chan_list_6g_ap: master AP chan list to fill with 6GHz channels
2124  * @mas_chan_list_6g_client: master client chan list to fill with 6GHz channels
2125  *
2126  * Return: QDF_STATUS
2127  */
2128 static QDF_STATUS
2129 reg_fill_master_channels(struct cur_regulatory_info *regulat_info,
2130 			 struct reg_rule_info *reg_rules,
2131 			 enum reg_6g_client_type client_mobility_type,
2132 			 struct regulatory_channel *mas_chan_list_2g_5g,
2133 	struct regulatory_channel *mas_chan_list_6g_ap[REG_CURRENT_MAX_AP_TYPE],
2134 	struct regulatory_channel *mas_chan_list_6g_client
2135 		[REG_CURRENT_MAX_AP_TYPE][REG_MAX_CLIENT_TYPE])
2136 {
2137 	uint32_t i, j, k, curr_reg_rule_location;
2138 	uint32_t num_2g_reg_rules, num_5g_reg_rules;
2139 	uint32_t num_6g_reg_rules_ap[REG_CURRENT_MAX_AP_TYPE];
2140 	uint32_t *num_6g_reg_rules_client[REG_CURRENT_MAX_AP_TYPE];
2141 	struct cur_reg_rule *reg_rule_2g, *reg_rule_5g,
2142 		*reg_rule_6g_ap[REG_CURRENT_MAX_AP_TYPE],
2143 		**reg_rule_6g_client[REG_CURRENT_MAX_AP_TYPE];
2144 	uint32_t min_bw_2g, max_bw_2g, min_bw_5g, max_bw_5g,
2145 		min_bw_6g_ap[REG_CURRENT_MAX_AP_TYPE],
2146 		max_bw_6g_ap[REG_CURRENT_MAX_AP_TYPE],
2147 		*min_bw_6g_client[REG_CURRENT_MAX_AP_TYPE],
2148 		*max_bw_6g_client[REG_CURRENT_MAX_AP_TYPE];
2149 
2150 	min_bw_2g = regulat_info->min_bw_2g;
2151 	max_bw_2g = regulat_info->max_bw_2g;
2152 	reg_rule_2g = regulat_info->reg_rules_2g_ptr;
2153 	num_2g_reg_rules = regulat_info->num_2g_reg_rules;
2154 	reg_update_max_bw_per_rule(num_2g_reg_rules, reg_rule_2g, max_bw_2g);
2155 
2156 	min_bw_5g = regulat_info->min_bw_5g;
2157 	max_bw_5g = regulat_info->max_bw_5g;
2158 	reg_rule_5g = regulat_info->reg_rules_5g_ptr;
2159 	num_5g_reg_rules = regulat_info->num_5g_reg_rules;
2160 	reg_update_max_bw_per_rule(num_5g_reg_rules, reg_rule_5g, max_bw_5g);
2161 
2162 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2163 		min_bw_6g_ap[i] = regulat_info->min_bw_6g_ap[i];
2164 		max_bw_6g_ap[i] = regulat_info->max_bw_6g_ap[i];
2165 		reg_rule_6g_ap[i] = regulat_info->reg_rules_6g_ap_ptr[i];
2166 		num_6g_reg_rules_ap[i] = regulat_info->num_6g_reg_rules_ap[i];
2167 		reg_update_max_bw_per_rule(num_6g_reg_rules_ap[i],
2168 					   reg_rule_6g_ap[i], max_bw_6g_ap[i]);
2169 	}
2170 
2171 	for (j = 0; j < REG_CURRENT_MAX_AP_TYPE; j++) {
2172 		min_bw_6g_client[j] = regulat_info->min_bw_6g_client[j];
2173 		max_bw_6g_client[j] = regulat_info->max_bw_6g_client[j];
2174 		reg_rule_6g_client[j] =
2175 			regulat_info->reg_rules_6g_client_ptr[j];
2176 		num_6g_reg_rules_client[j] =
2177 			regulat_info->num_6g_reg_rules_client[j];
2178 		for (k = 0; k < REG_MAX_CLIENT_TYPE; k++) {
2179 			reg_update_max_bw_per_rule(
2180 						num_6g_reg_rules_client[j][k],
2181 						reg_rule_6g_client[j][k],
2182 						max_bw_6g_client[j][k]);
2183 		}
2184 	}
2185 
2186 	reg_reset_reg_rules(reg_rules);
2187 
2188 	reg_rules->num_of_reg_rules = num_5g_reg_rules + num_2g_reg_rules;
2189 
2190 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2191 		reg_rules->num_of_6g_ap_reg_rules[i] = num_6g_reg_rules_ap[i];
2192 		if (num_6g_reg_rules_ap[i] > MAX_6G_REG_RULES) {
2193 			reg_err("number of reg rules for 6g ap exceeds limit");
2194 			return QDF_STATUS_E_FAILURE;
2195 		}
2196 
2197 		reg_rules->num_of_6g_client_reg_rules[i] =
2198 			num_6g_reg_rules_client[i][client_mobility_type];
2199 		for (j = 0; j < REG_MAX_CLIENT_TYPE; j++) {
2200 			if (num_6g_reg_rules_client[i][j] > MAX_6G_REG_RULES) {
2201 				reg_err("number of reg rules for 6g client exceeds limit");
2202 				return QDF_STATUS_E_FAILURE;
2203 			}
2204 		}
2205 	}
2206 
2207 	if (reg_rules->num_of_reg_rules > MAX_REG_RULES) {
2208 		reg_err("number of reg rules exceeds limit");
2209 		return QDF_STATUS_E_FAILURE;
2210 	}
2211 
2212 	if (reg_rules->num_of_reg_rules) {
2213 		if (num_2g_reg_rules)
2214 			qdf_mem_copy(reg_rules->reg_rules,
2215 				     reg_rule_2g, num_2g_reg_rules *
2216 				     sizeof(struct cur_reg_rule));
2217 		curr_reg_rule_location = num_2g_reg_rules;
2218 		if (num_5g_reg_rules)
2219 			qdf_mem_copy(reg_rules->reg_rules +
2220 				     curr_reg_rule_location, reg_rule_5g,
2221 				     num_5g_reg_rules *
2222 				     sizeof(struct cur_reg_rule));
2223 	}
2224 
2225 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2226 		if (num_6g_reg_rules_ap[i])
2227 			qdf_mem_copy(reg_rules->reg_rules_6g_ap[i],
2228 				     reg_rule_6g_ap[i],
2229 				     num_6g_reg_rules_ap[i] *
2230 				     sizeof(struct cur_reg_rule));
2231 
2232 		if (num_6g_reg_rules_client[i][client_mobility_type])
2233 			qdf_mem_copy(reg_rules->reg_rules_6g_client[i],
2234 				reg_rule_6g_client[i][client_mobility_type],
2235 				num_6g_reg_rules_client[i]
2236 				[client_mobility_type] *
2237 				sizeof(struct cur_reg_rule));
2238 	}
2239 
2240 
2241 	if (num_5g_reg_rules)
2242 		reg_do_auto_bw_correction(num_5g_reg_rules,
2243 					  reg_rule_5g, max_bw_5g);
2244 
2245 	if (num_2g_reg_rules)
2246 		reg_populate_band_channels(MIN_24GHZ_CHANNEL, MAX_24GHZ_CHANNEL,
2247 					   reg_rule_2g, num_2g_reg_rules,
2248 					   min_bw_2g, mas_chan_list_2g_5g);
2249 
2250 	if (num_5g_reg_rules) {
2251 		reg_populate_band_channels(MIN_5GHZ_CHANNEL, MAX_5GHZ_CHANNEL,
2252 					   reg_rule_5g, num_5g_reg_rules,
2253 					   min_bw_5g, mas_chan_list_2g_5g);
2254 		reg_populate_49g_band_channels(reg_rule_5g,
2255 					       num_5g_reg_rules,
2256 					       min_bw_5g,
2257 					       mas_chan_list_2g_5g);
2258 	}
2259 
2260 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2261 		if (num_6g_reg_rules_ap[i])
2262 			reg_populate_band_channels_ext_for_6g(0,
2263 							NUM_6GHZ_CHANNELS - 1,
2264 							reg_rule_6g_ap[i],
2265 							num_6g_reg_rules_ap[i],
2266 							min_bw_6g_ap[i],
2267 							mas_chan_list_6g_ap[i]);
2268 
2269 		for (j = 0; j < REG_MAX_CLIENT_TYPE; j++) {
2270 			if (num_6g_reg_rules_client[i][j])
2271 				reg_populate_band_channels_ext_for_6g(0,
2272 						NUM_6GHZ_CHANNELS - 1,
2273 						reg_rule_6g_client[i][j],
2274 						num_6g_reg_rules_client[i][j],
2275 						min_bw_6g_client[i][j],
2276 						mas_chan_list_6g_client[i][j]);
2277 		}
2278 	}
2279 
2280 	return QDF_STATUS_SUCCESS;
2281 }
2282 
2283 /**
2284  * reg_set_socpriv_vars() - Set the regulatory PSOC variables based on
2285  *	pending country status
2286  * @soc_reg: regulatory PSOC private object
2287  * @regulat_info: regulatory info
2288  * @psoc: pointer to PSOC object
2289  * @phy_id: physical ID
2290  *
2291  * Return: none
2292  */
2293 static void reg_set_socpriv_vars(struct wlan_regulatory_psoc_priv_obj *soc_reg,
2294 				 struct cur_regulatory_info *regulat_info,
2295 				 struct wlan_objmgr_psoc *psoc,
2296 				 uint8_t phy_id)
2297 {
2298 	soc_reg->chan_list_recvd[phy_id] = true;
2299 
2300 	if (soc_reg->new_user_ctry_pending[phy_id]) {
2301 		soc_reg->new_user_ctry_pending[phy_id] = false;
2302 		soc_reg->cc_src = SOURCE_USERSPACE;
2303 		soc_reg->user_ctry_set = true;
2304 		reg_debug("new user country is set");
2305 		reg_run_11d_state_machine(psoc);
2306 	} else if (soc_reg->new_init_ctry_pending[phy_id]) {
2307 		soc_reg->new_init_ctry_pending[phy_id] = false;
2308 		soc_reg->cc_src = SOURCE_USERSPACE;
2309 		reg_debug("new init country is set");
2310 	} else if (soc_reg->new_11d_ctry_pending[phy_id]) {
2311 		soc_reg->new_11d_ctry_pending[phy_id] = false;
2312 		soc_reg->cc_src = SOURCE_11D;
2313 		soc_reg->user_ctry_set = false;
2314 		reg_run_11d_state_machine(psoc);
2315 	} else if (soc_reg->world_country_pending[phy_id]) {
2316 		soc_reg->world_country_pending[phy_id] = false;
2317 		soc_reg->cc_src = SOURCE_CORE;
2318 		soc_reg->user_ctry_set = false;
2319 		reg_run_11d_state_machine(psoc);
2320 	} else {
2321 		if (soc_reg->cc_src == SOURCE_UNKNOWN &&
2322 		    soc_reg->num_phy == phy_id + 1)
2323 			soc_reg->cc_src = SOURCE_DRIVER;
2324 
2325 		qdf_mem_copy(soc_reg->mas_chan_params[phy_id].default_country,
2326 			     regulat_info->alpha2,
2327 			     REG_ALPHA2_LEN + 1);
2328 
2329 		soc_reg->mas_chan_params[phy_id].def_country_code =
2330 			regulat_info->ctry_code;
2331 		soc_reg->mas_chan_params[phy_id].def_region_domain =
2332 			regulat_info->reg_dmn_pair;
2333 
2334 		if (soc_reg->cc_src == SOURCE_DRIVER) {
2335 			qdf_mem_copy(soc_reg->def_country,
2336 				     regulat_info->alpha2,
2337 				     REG_ALPHA2_LEN + 1);
2338 
2339 			soc_reg->def_country_code = regulat_info->ctry_code;
2340 			soc_reg->def_region_domain =
2341 				regulat_info->reg_dmn_pair;
2342 
2343 			if (reg_is_world_alpha2(regulat_info->alpha2)) {
2344 				soc_reg->cc_src = SOURCE_CORE;
2345 				reg_run_11d_state_machine(psoc);
2346 			}
2347 		}
2348 	}
2349 }
2350 
2351 QDF_STATUS reg_process_master_chan_list_ext(
2352 		struct cur_regulatory_info *regulat_info)
2353 {
2354 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
2355 	uint32_t i, j;
2356 	struct regulatory_channel *mas_chan_list_2g_5g,
2357 		*mas_chan_list_6g_ap[REG_CURRENT_MAX_AP_TYPE],
2358 		*mas_chan_list_6g_client[REG_CURRENT_MAX_AP_TYPE]
2359 							[REG_MAX_CLIENT_TYPE];
2360 	struct wlan_objmgr_psoc *psoc;
2361 	wlan_objmgr_ref_dbgid dbg_id;
2362 	enum direction dir;
2363 	uint8_t phy_id;
2364 	uint8_t pdev_id;
2365 	struct wlan_objmgr_pdev *pdev;
2366 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
2367 	QDF_STATUS status;
2368 	struct mas_chan_params *this_mchan_params;
2369 
2370 	psoc = regulat_info->psoc;
2371 	soc_reg = reg_get_psoc_obj(psoc);
2372 
2373 	if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) {
2374 		reg_err("psoc reg component is NULL");
2375 		return QDF_STATUS_E_FAILURE;
2376 	}
2377 
2378 	tx_ops = reg_get_psoc_tx_ops(psoc);
2379 	phy_id = regulat_info->phy_id;
2380 
2381 	if (tx_ops->get_pdev_id_from_phy_id)
2382 		tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id);
2383 	else
2384 		pdev_id = phy_id;
2385 
2386 	if (reg_ignore_default_country(soc_reg, regulat_info)) {
2387 		status = reg_set_curr_country(soc_reg, regulat_info, tx_ops);
2388 		if (QDF_IS_STATUS_SUCCESS(status)) {
2389 			reg_debug("WLAN restart - Ignore default CC for phy_id: %u",
2390 				  phy_id);
2391 			return QDF_STATUS_SUCCESS;
2392 		}
2393 	}
2394 
2395 	reg_debug("process reg master chan extended list");
2396 
2397 	if (soc_reg->offload_enabled) {
2398 		dbg_id = WLAN_REGULATORY_NB_ID;
2399 		dir = NORTHBOUND;
2400 	} else {
2401 		dbg_id = WLAN_REGULATORY_SB_ID;
2402 		dir = SOUTHBOUND;
2403 	}
2404 
2405 	status = reg_soc_vars_reset_on_failure(regulat_info->status_code,
2406 					       soc_reg, tx_ops, psoc, dbg_id,
2407 					       phy_id);
2408 
2409 	if (!QDF_IS_STATUS_SUCCESS(status))
2410 		return status;
2411 
2412 	this_mchan_params = &soc_reg->mas_chan_params[phy_id];
2413 	mas_chan_list_2g_5g = this_mchan_params->mas_chan_list;
2414 
2415 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2416 		mas_chan_list_6g_ap[i] =
2417 			this_mchan_params->mas_chan_list_6g_ap[i];
2418 
2419 		for (j = 0; j < REG_MAX_CLIENT_TYPE; j++)
2420 			mas_chan_list_6g_client[i][j] =
2421 				this_mchan_params->mas_chan_list_6g_client[i][j];
2422 	}
2423 
2424 	reg_init_channel_map(regulat_info->dfs_region);
2425 
2426 	reg_init_2g_5g_master_chan(mas_chan_list_2g_5g, soc_reg);
2427 
2428 	for (i = 0; i < REG_CURRENT_MAX_AP_TYPE; i++) {
2429 		reg_init_6g_master_chan(mas_chan_list_6g_ap[i], soc_reg);
2430 		for (j = 0; j < REG_MAX_CLIENT_TYPE; j++)
2431 			reg_init_6g_master_chan(mas_chan_list_6g_client[i][j],
2432 						soc_reg);
2433 	}
2434 
2435 	reg_store_regulatory_ext_info_to_socpriv(soc_reg, regulat_info, phy_id);
2436 
2437 	status = reg_fill_master_channels(regulat_info,
2438 					  &this_mchan_params->reg_rules,
2439 					  this_mchan_params->client_type,
2440 					  mas_chan_list_2g_5g,
2441 					  mas_chan_list_6g_ap,
2442 					  mas_chan_list_6g_client);
2443 	if (!QDF_IS_STATUS_SUCCESS(status))
2444 		return status;
2445 
2446 	status = reg_send_ctl_info(soc_reg, regulat_info, tx_ops);
2447 	if (!QDF_IS_STATUS_SUCCESS(status))
2448 		return status;
2449 
2450 	reg_set_socpriv_vars(soc_reg, regulat_info, psoc, phy_id);
2451 
2452 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id, dbg_id);
2453 	if (pdev) {
2454 		reg_propagate_mas_chan_list_to_pdev(psoc, pdev, &dir);
2455 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2456 	}
2457 
2458 	return QDF_STATUS_SUCCESS;
2459 }
2460 
2461 #ifdef CONFIG_AFC_SUPPORT
2462 static void reg_disable_afc_mas_chan_list_channels(
2463 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
2464 {
2465 	struct regulatory_channel *afc_mas_chan_list;
2466 	enum channel_enum chan_idx;
2467 
2468 	afc_mas_chan_list = pdev_priv_obj->mas_chan_list_6g_afc;
2469 
2470 	for (chan_idx = 0; chan_idx < NUM_6GHZ_CHANNELS; chan_idx++) {
2471 		if (afc_mas_chan_list[chan_idx].state == CHANNEL_STATE_ENABLE) {
2472 			afc_mas_chan_list[chan_idx].state =
2473 							CHANNEL_STATE_DISABLE;
2474 			afc_mas_chan_list[chan_idx].chan_flags |=
2475 						REGULATORY_CHAN_DISABLED;
2476 			afc_mas_chan_list[chan_idx].psd_eirp = 0;
2477 			afc_mas_chan_list[chan_idx].tx_power = 0;
2478 		}
2479 	}
2480 
2481 	qdf_mem_zero(pdev_priv_obj->afc_chan_list,
2482 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
2483 }
2484 
2485 static void reg_free_expiry_afc_info(struct afc_regulatory_info *afc_info)
2486 {
2487 	qdf_mem_free(afc_info->expiry_info);
2488 }
2489 
2490 /**
2491  * reg_process_afc_expiry_event() - Process the afc expiry event and get the
2492  * afc request id
2493  * @afc_info: Pointer to afc info
2494  *
2495  * Return: QDF_STATUS
2496  */
2497 static QDF_STATUS
2498 reg_process_afc_expiry_event(struct afc_regulatory_info *afc_info)
2499 {
2500 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2501 	uint8_t phy_id;
2502 	uint8_t pdev_id;
2503 	struct wlan_objmgr_psoc *psoc;
2504 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
2505 	struct wlan_objmgr_pdev *pdev;
2506 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
2507 	wlan_objmgr_ref_dbgid dbg_id;
2508 
2509 	psoc = afc_info->psoc;
2510 	soc_reg = reg_get_psoc_obj(psoc);
2511 
2512 	if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) {
2513 		reg_err("psoc reg component is NULL");
2514 		return QDF_STATUS_E_FAILURE;
2515 	}
2516 
2517 	phy_id = afc_info->phy_id;
2518 	tx_ops = reg_get_psoc_tx_ops(psoc);
2519 
2520 	if (soc_reg->offload_enabled)
2521 		dbg_id = WLAN_REGULATORY_NB_ID;
2522 	else
2523 		dbg_id = WLAN_REGULATORY_SB_ID;
2524 
2525 	if (tx_ops->get_pdev_id_from_phy_id)
2526 		tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id);
2527 	else
2528 		pdev_id = phy_id;
2529 
2530 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id, dbg_id);
2531 
2532 	if (!pdev) {
2533 		reg_err("pdev is NULL");
2534 		return QDF_STATUS_E_FAILURE;
2535 	}
2536 
2537 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2538 
2539 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2540 		reg_err("reg pdev priv obj is NULL");
2541 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2542 		return QDF_STATUS_E_FAILURE;
2543 	}
2544 
2545 	pdev_priv_obj->is_6g_afc_power_event_received = false;
2546 
2547 	reg_debug("AFC event subtype: %d",
2548 		  afc_info->expiry_info->event_subtype);
2549 	switch (afc_info->expiry_info->event_subtype) {
2550 	case REG_AFC_EXPIRY_EVENT_START:
2551 	case REG_AFC_EXPIRY_EVENT_RENEW:
2552 		pdev_priv_obj->afc_request_id =
2553 					afc_info->expiry_info->request_id;
2554 		pdev_priv_obj->is_6g_afc_expiry_event_received = true;
2555 		reg_afc_start(pdev, pdev_priv_obj->afc_request_id);
2556 		break;
2557 	case REG_AFC_EXPIRY_EVENT_SWITCH_TO_LPI:
2558 		reg_disable_afc_mas_chan_list_channels(pdev_priv_obj);
2559 		if (tx_ops->trigger_acs_for_afc)
2560 			tx_ops->trigger_acs_for_afc(pdev);
2561 		break;
2562 	default:
2563 		reg_err_rl("Invalid event subtype");
2564 	};
2565 
2566 	wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2567 	reg_free_expiry_afc_info(afc_info);
2568 
2569 	return QDF_STATUS_SUCCESS;
2570 }
2571 
2572 /**
2573  * reg_fill_min_max_bw_for_afc_list() - Fill min and max bw in afc list from
2574  * from the SP AFC list
2575  * @pdev_priv_obj: Pointer to pdev_priv_obj
2576  * @afc_chan_list: Pointer to afc_chan_list
2577  *
2578  * Return: void
2579  */
2580 static void
2581 reg_fill_min_max_bw_for_afc_list(
2582 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
2583 		struct regulatory_channel *afc_chan_list)
2584 {
2585 	uint8_t chan_idx;
2586 
2587 	for (chan_idx = 0; chan_idx < NUM_6GHZ_CHANNELS; chan_idx++) {
2588 		afc_chan_list[chan_idx].min_bw = MIN_AFC_BW;
2589 		afc_chan_list[chan_idx].max_bw = MAX_AFC_BW;
2590 	}
2591 }
2592 
2593 /**
2594  * reg_get_subchannels_for_opclass() - Get the list of subchannels based on the
2595  * the channel frequency index and opclass.
2596  * @cfi: Channel frequency index
2597  * @opclass: Operating class
2598  * @subchannels: Pointer to list of subchannels
2599  *
2600  * Return: void
2601  */
2602 static uint8_t reg_get_subchannels_for_opclass(uint8_t cfi,
2603 					       uint8_t opclass,
2604 					       uint8_t *subchannels)
2605 {
2606 	uint8_t nchans;
2607 
2608 	switch (opclass) {
2609 	case 131:
2610 	case 136:
2611 		nchans = 1;
2612 		subchannels[0] = cfi;
2613 		break;
2614 	case 132:
2615 		nchans = 2;
2616 		subchannels[0] = cfi - 2;
2617 		subchannels[1] = cfi + 2;
2618 		break;
2619 	case 133:
2620 		nchans = 4;
2621 		subchannels[0] = cfi - 6;
2622 		subchannels[1] = cfi - 2;
2623 		subchannels[2] = cfi + 2;
2624 		subchannels[3] = cfi + 6;
2625 		break;
2626 	case 134:
2627 		nchans = 8;
2628 		subchannels[0] = cfi - 14;
2629 		subchannels[1] = cfi - 10;
2630 		subchannels[2] = cfi - 6;
2631 		subchannels[3] = cfi - 2;
2632 		subchannels[4] = cfi + 2;
2633 		subchannels[5] = cfi + 6;
2634 		subchannels[6] = cfi + 10;
2635 		subchannels[7] = cfi + 14;
2636 		break;
2637 	default:
2638 		nchans = 0;
2639 		break;
2640 	}
2641 
2642 	return nchans;
2643 }
2644 
2645 /**
2646  * reg_search_afc_power_info_for_freq() - Search the chan_eirp object for the
2647  * eirp power for a given frequency
2648  * @pdev: Pointer to pdev
2649  * @afc_info: Pointer to afc_info
2650  * @freq: Channel frequency
2651  * @eirp_power: Pointer to eirp_power
2652  *
2653  * Return: QDF_STATUS
2654  */
2655 static QDF_STATUS
2656 reg_search_afc_power_info_for_freq(
2657 		struct wlan_objmgr_pdev *pdev,
2658 		struct afc_regulatory_info *afc_info,
2659 		qdf_freq_t freq,
2660 		uint16_t *eirp_power)
2661 {
2662 	struct reg_fw_afc_power_event *power_info;
2663 	uint8_t i;
2664 
2665 	if (!afc_info->power_info) {
2666 		reg_err("afc_info->power_info is NULL");
2667 		return QDF_STATUS_E_FAILURE;
2668 	}
2669 
2670 	if (!afc_info->power_info->num_chan_objs) {
2671 		reg_err("num chan objs cannot be zero");
2672 		return QDF_STATUS_E_FAILURE;
2673 	}
2674 
2675 	power_info = afc_info->power_info;
2676 
2677 	*eirp_power = 0;
2678 	for (i = 0; i < power_info->num_chan_objs; i++) {
2679 		uint8_t j;
2680 		struct afc_chan_obj *chan_obj = &power_info->afc_chan_info[i];
2681 
2682 		if (!chan_obj->num_chans) {
2683 			reg_err("num chans cannot be zero");
2684 			return QDF_STATUS_E_FAILURE;
2685 		}
2686 
2687 		for (j = 0; j < chan_obj->num_chans; j++) {
2688 			uint8_t k;
2689 			struct chan_eirp_obj *eirp_obj =
2690 						&chan_obj->chan_eirp_info[j];
2691 			uint8_t opclass = chan_obj->global_opclass;
2692 			uint8_t subchannels[REG_MAX_20M_SUB_CH];
2693 			uint8_t nchans;
2694 
2695 			nchans =
2696 			reg_get_subchannels_for_opclass(eirp_obj->cfi,
2697 							opclass, subchannels);
2698 
2699 			for (k = 0; k < nchans; k++) {
2700 				if (reg_chan_band_to_freq(pdev,
2701 							  subchannels[k],
2702 							  BIT(REG_BAND_6G)) ==
2703 							  freq) {
2704 					*eirp_power = eirp_obj->eirp_power;
2705 					break;
2706 				}
2707 			}
2708 		}
2709 	}
2710 
2711 	return QDF_STATUS_SUCCESS;
2712 }
2713 
2714 /**
2715  * reg_fill_eirp_pwr_in_afc_chan_list() - Fill max eirp power in the afc master
2716  * chan list
2717  * @pdev: Pointer to pdev
2718  * @afc_chan_list: Pointer to afc_chan_list
2719  * @afc_info: Pointer to afc_info
2720  *
2721  * Return: QDF_STATUS
2722  */
2723 static QDF_STATUS reg_fill_eirp_pwr_in_afc_chan_list(
2724 		struct wlan_objmgr_pdev *pdev,
2725 		struct regulatory_channel *afc_chan_list,
2726 		struct afc_regulatory_info *afc_info)
2727 
2728 {
2729 	uint8_t chan_idx;
2730 	uint16_t eirp_power;
2731 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2732 
2733 	for (chan_idx = 0; chan_idx < NUM_6GHZ_CHANNELS; chan_idx++) {
2734 		status =
2735 		reg_search_afc_power_info_for_freq(pdev,
2736 						   afc_info,
2737 						   afc_chan_list[chan_idx].
2738 						   center_freq,
2739 						   &eirp_power);
2740 		/*
2741 		 * The eirp_power is divided by 100 because the target
2742 		 * sends the EIRP in the units of 0.01 dbm.
2743 		 */
2744 		if (QDF_IS_STATUS_SUCCESS(status))
2745 			afc_chan_list[chan_idx].tx_power = eirp_power / 100;
2746 	}
2747 
2748 	return status;
2749 }
2750 
2751 /**
2752  * reg_find_low_limit_chan_enum_for_6g() - Find 6G channel enum for a given 6G
2753  * lower edge frequency in the input channel list
2754  * @chan_list: Pointer to regulatory channel list.
2755  * @low_freq: Channel frequency.
2756  * @channel_enum: pointer to output channel enum.
2757  *
2758  * Return: None
2759  */
2760 static void reg_find_low_limit_chan_enum_for_6g(
2761 		struct regulatory_channel *chan_list, qdf_freq_t low_freq,
2762 		uint32_t *channel_enum)
2763 {
2764 	enum channel_enum chan_enum;
2765 	uint16_t min_bw, max_bw, left_edge_of_min_band, left_edge_of_max_band;
2766 	qdf_freq_t center_freq;
2767 
2768 	for (chan_enum = 0; chan_enum < NUM_6GHZ_CHANNELS; chan_enum++) {
2769 		min_bw = chan_list[chan_enum].min_bw;
2770 		max_bw = chan_list[chan_enum].max_bw;
2771 		center_freq = chan_list[chan_enum].center_freq;
2772 		left_edge_of_min_band = center_freq - min_bw / 2;
2773 
2774 		if ((left_edge_of_min_band) >= low_freq) {
2775 			left_edge_of_max_band = center_freq - max_bw / 2;
2776 			if (left_edge_of_max_band < low_freq) {
2777 				if (max_bw <= 20)
2778 					max_bw = ((center_freq - low_freq) * 2);
2779 				if (max_bw < min_bw)
2780 					max_bw = min_bw;
2781 				chan_list[chan_enum].max_bw = max_bw;
2782 			}
2783 			*channel_enum = chan_enum;
2784 			break;
2785 		}
2786 	}
2787 }
2788 
2789 /**
2790  * reg_find_high_limit_chan_enum_for_6g() - Find 6G channel enum for a given
2791  * 6G higher edge frequency in the input channel list
2792  * @chan_list: Pointer to regulatory channel list.
2793  * @freq: Channel frequency.
2794  * @channel_enum: pointer to output channel enum.
2795  *
2796  * Return: None
2797  */
2798 static void reg_find_high_limit_chan_enum_for_6g(
2799 		struct regulatory_channel *chan_list,
2800 		qdf_freq_t high_freq,
2801 		uint32_t *high_limit)
2802 {
2803 	enum channel_enum chan_enum;
2804 	uint16_t min_bw, max_bw, right_edge_of_min_band, right_edge_of_max_band;
2805 	qdf_freq_t center_freq;
2806 
2807 	for (chan_enum = NUM_6GHZ_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
2808 		min_bw = chan_list[chan_enum].min_bw;
2809 		max_bw = chan_list[chan_enum].max_bw;
2810 		center_freq = chan_list[chan_enum].center_freq;
2811 		right_edge_of_min_band = center_freq + min_bw / 2;
2812 
2813 		if (right_edge_of_min_band <= high_freq) {
2814 			right_edge_of_max_band = center_freq + max_bw / 2;
2815 			if (right_edge_of_max_band > high_freq) {
2816 				if (max_bw <= 20)
2817 					max_bw = ((high_freq -
2818 						   center_freq) * 2);
2819 				if (max_bw < min_bw)
2820 					max_bw = min_bw;
2821 				chan_list[chan_enum].max_bw = max_bw;
2822 			}
2823 			*high_limit = chan_enum;
2824 			break;
2825 		}
2826 
2827 		if (chan_enum == 0)
2828 			break;
2829 	}
2830 }
2831 
2832 /**
2833  * reg_fill_max_psd_in_afc_chan_list() - Fill max_psd in the afc master chan
2834  * list
2835  * @pdev_priv_obj: Pointer to pdev_priv_obj
2836  * @afc_chan_list: Pointer to afc_chan_list
2837  * @power_info: Pointer to power_info
2838  *
2839  * Return: QDF_STATUS
2840  */
2841 static QDF_STATUS reg_fill_max_psd_in_afc_chan_list(
2842 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
2843 		struct regulatory_channel *afc_chan_list,
2844 		struct reg_fw_afc_power_event *power_info)
2845 {
2846 	uint8_t i;
2847 
2848 	if (!power_info) {
2849 		reg_err("power_info is NULL");
2850 		return QDF_STATUS_E_FAILURE;
2851 	}
2852 
2853 	if (!power_info->num_freq_objs) {
2854 		reg_err("num freq objs cannot be zero");
2855 		return QDF_STATUS_E_FAILURE;
2856 	}
2857 
2858 	for (i = 0; i < power_info->num_freq_objs; i++) {
2859 		struct afc_freq_obj *freq_obj = &power_info->afc_freq_info[i];
2860 		uint32_t low_limit_enum, high_limit_enum;
2861 		uint8_t j;
2862 
2863 		reg_find_low_limit_chan_enum_for_6g(afc_chan_list,
2864 						    freq_obj->low_freq,
2865 						    &low_limit_enum);
2866 		reg_find_high_limit_chan_enum_for_6g(afc_chan_list,
2867 						     freq_obj->high_freq,
2868 						     &high_limit_enum);
2869 		for (j = low_limit_enum; j <= high_limit_enum; j++) {
2870 			afc_chan_list[j].state = CHANNEL_STATE_ENABLE;
2871 			afc_chan_list[j].chan_flags &=
2872 						~REGULATORY_CHAN_DISABLED;
2873 			/*
2874 			 * The max_psd is divided by 100 because the target
2875 			 * sends the PSD in the units of 0.01 dbm/MHz.
2876 			 */
2877 			afc_chan_list[j].psd_eirp = freq_obj->max_psd / 100;
2878 			afc_chan_list[j].psd_flag = true;
2879 		}
2880 	}
2881 
2882 	return QDF_STATUS_SUCCESS;
2883 }
2884 
2885 /**
2886  * reg_process_afc_power_event() - Process the afc event and compute the 6G AFC
2887  * channel list based on the frequency range and channel frequency indice set.
2888  * @afc_info: Pointer to afc info
2889  *
2890  * Return: QDF_STATUS
2891  */
2892 static QDF_STATUS
2893 reg_process_afc_power_event(struct afc_regulatory_info *afc_info)
2894 {
2895 	struct wlan_objmgr_psoc *psoc;
2896 	uint8_t phy_id;
2897 	uint8_t pdev_id;
2898 	wlan_objmgr_ref_dbgid dbg_id;
2899 	struct wlan_objmgr_pdev *pdev;
2900 	struct mas_chan_params *this_mchan_params;
2901 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
2902 	struct regulatory_channel *afc_mas_chan_list;
2903 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
2904 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
2905 	uint32_t size_of_6g_chan_list =
2906 		NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel);
2907 	QDF_STATUS status;
2908 
2909 	if (afc_info->power_info->fw_status_code !=
2910 	    REG_FW_AFC_POWER_EVENT_SUCCESS) {
2911 		reg_err_rl("AFC Power event failure status code %d",
2912 			   afc_info->power_info->fw_status_code);
2913 		return QDF_STATUS_E_FAILURE;
2914 	}
2915 
2916 	psoc = afc_info->psoc;
2917 	soc_reg = reg_get_psoc_obj(psoc);
2918 
2919 	if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) {
2920 		reg_err("psoc reg component is NULL");
2921 		return QDF_STATUS_E_FAILURE;
2922 	}
2923 
2924 	tx_ops = reg_get_psoc_tx_ops(psoc);
2925 	phy_id = afc_info->phy_id;
2926 
2927 	if (tx_ops->get_pdev_id_from_phy_id)
2928 		tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id);
2929 	else
2930 		pdev_id = phy_id;
2931 
2932 	if (soc_reg->offload_enabled)
2933 		dbg_id = WLAN_REGULATORY_NB_ID;
2934 	else
2935 		dbg_id = WLAN_REGULATORY_SB_ID;
2936 
2937 	reg_debug("process reg afc master chan list");
2938 	this_mchan_params = &soc_reg->mas_chan_params[phy_id];
2939 	afc_mas_chan_list = this_mchan_params->mas_chan_list_6g_afc;
2940 	reg_init_6g_master_chan(afc_mas_chan_list, soc_reg);
2941 	soc_reg->mas_chan_params[phy_id].is_6g_afc_power_event_received = true;
2942 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id, dbg_id);
2943 
2944 	if (!pdev) {
2945 		reg_err("pdev is NULL");
2946 		return QDF_STATUS_E_FAILURE;
2947 	}
2948 
2949 	pdev_priv_obj = reg_get_pdev_obj(pdev);
2950 
2951 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
2952 		reg_err("reg pdev priv obj is NULL");
2953 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2954 		return QDF_STATUS_E_FAILURE;
2955 	}
2956 
2957 	/* Free the old power_info event if it was allocated */
2958 	if (pdev_priv_obj->power_info)
2959 		reg_free_afc_pwr_info(pdev_priv_obj);
2960 
2961 	pdev_priv_obj->power_info = afc_info->power_info;
2962 	reg_fill_min_max_bw_for_afc_list(pdev_priv_obj,
2963 					 afc_mas_chan_list);
2964 	status = reg_fill_max_psd_in_afc_chan_list(pdev_priv_obj,
2965 						   afc_mas_chan_list,
2966 						   afc_info->power_info);
2967 	if (QDF_IS_STATUS_ERROR(status)) {
2968 		reg_err("Error in filling max_psd in AFC chan list");
2969 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2970 		return status;
2971 	}
2972 
2973 	status = reg_fill_eirp_pwr_in_afc_chan_list(pdev,
2974 						    afc_mas_chan_list,
2975 						    afc_info);
2976 	if (QDF_IS_STATUS_ERROR(status)) {
2977 		reg_err("Error in filling EIRP power in AFC chan list");
2978 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2979 		return QDF_STATUS_E_FAILURE;
2980 	}
2981 
2982 	qdf_mem_copy(pdev_priv_obj->mas_chan_list_6g_afc,
2983 		     afc_mas_chan_list,
2984 		     size_of_6g_chan_list);
2985 	pdev_priv_obj->is_6g_afc_power_event_received =
2986 	soc_reg->mas_chan_params[phy_id].is_6g_afc_power_event_received;
2987 
2988 	reg_modify_6g_afc_chan_list(pdev_priv_obj);
2989 
2990 	if (tx_ops->trigger_acs_for_afc &&
2991 	    !wlan_reg_is_noaction_on_afc_pwr_evt(pdev))
2992 		tx_ops->trigger_acs_for_afc(pdev);
2993 
2994 	wlan_objmgr_pdev_release_ref(pdev, dbg_id);
2995 
2996 	return QDF_STATUS_SUCCESS;
2997 }
2998 
2999 /**
3000  * reg_process_afc_event() - Process the afc event received from the target.
3001  * @afc_info: Pointer to afc_info
3002  *
3003  * Return: QDF_STATUS
3004  */
3005 QDF_STATUS
3006 reg_process_afc_event(struct afc_regulatory_info *afc_info)
3007 {
3008 	switch (afc_info->event_type) {
3009 	case REG_AFC_EVENT_POWER_INFO:
3010 		return reg_process_afc_power_event(afc_info);
3011 	case REG_AFC_EVENT_TIMER_EXPIRY:
3012 		return reg_process_afc_expiry_event(afc_info);
3013 	default:
3014 		reg_err_rl("Invalid event type");
3015 		return QDF_STATUS_E_FAILURE;
3016 	}
3017 }
3018 #endif /* CONFIG_AFC_SUPPORT */
3019 #endif /* CONFIG_BAND_6GHZ */
3020 
3021 QDF_STATUS reg_process_master_chan_list(
3022 		struct cur_regulatory_info *regulat_info)
3023 {
3024 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
3025 	uint32_t num_2g_reg_rules, num_5g_reg_rules;
3026 	struct cur_reg_rule *reg_rule_2g, *reg_rule_5g;
3027 	uint16_t min_bw_2g, max_bw_2g, min_bw_5g, max_bw_5g;
3028 	struct regulatory_channel *mas_chan_list;
3029 	struct wlan_objmgr_psoc *psoc;
3030 	wlan_objmgr_ref_dbgid dbg_id;
3031 	enum direction dir;
3032 	uint8_t phy_id;
3033 	uint8_t pdev_id;
3034 	struct wlan_objmgr_pdev *pdev;
3035 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
3036 	struct reg_rule_info *reg_rules;
3037 	QDF_STATUS status;
3038 
3039 	psoc = regulat_info->psoc;
3040 	soc_reg = reg_get_psoc_obj(psoc);
3041 
3042 	if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) {
3043 		reg_err("psoc reg component is NULL");
3044 		return QDF_STATUS_E_FAILURE;
3045 	}
3046 
3047 	tx_ops = reg_get_psoc_tx_ops(psoc);
3048 	phy_id = regulat_info->phy_id;
3049 
3050 	if (tx_ops->get_pdev_id_from_phy_id)
3051 		tx_ops->get_pdev_id_from_phy_id(psoc, phy_id, &pdev_id);
3052 	else
3053 		pdev_id = phy_id;
3054 
3055 	if (reg_ignore_default_country(soc_reg, regulat_info)) {
3056 		status = reg_set_curr_country(soc_reg, regulat_info, tx_ops);
3057 		if (QDF_IS_STATUS_SUCCESS(status)) {
3058 			reg_debug("WLAN restart - Ignore default CC for phy_id: %u",
3059 				  phy_id);
3060 			return QDF_STATUS_SUCCESS;
3061 		}
3062 	}
3063 
3064 	reg_debug("process reg master chan list");
3065 
3066 	if (soc_reg->offload_enabled) {
3067 		dbg_id = WLAN_REGULATORY_NB_ID;
3068 		dir = NORTHBOUND;
3069 	} else {
3070 		dbg_id = WLAN_REGULATORY_SB_ID;
3071 		dir = SOUTHBOUND;
3072 	}
3073 
3074 	status = reg_soc_vars_reset_on_failure(regulat_info->status_code,
3075 					       soc_reg, tx_ops, psoc, dbg_id,
3076 					       phy_id);
3077 
3078 	if (!QDF_IS_STATUS_SUCCESS(status))
3079 		return status;
3080 
3081 	mas_chan_list = soc_reg->mas_chan_params[phy_id].mas_chan_list;
3082 
3083 	reg_init_channel_map(regulat_info->dfs_region);
3084 
3085 	reg_init_legacy_master_chan(mas_chan_list, soc_reg);
3086 
3087 	soc_reg->num_phy = regulat_info->num_phy;
3088 	soc_reg->mas_chan_params[phy_id].phybitmap =
3089 		regulat_info->phybitmap;
3090 	soc_reg->mas_chan_params[phy_id].dfs_region =
3091 		regulat_info->dfs_region;
3092 	soc_reg->mas_chan_params[phy_id].ctry_code =
3093 		regulat_info->ctry_code;
3094 	soc_reg->mas_chan_params[phy_id].reg_dmn_pair =
3095 		regulat_info->reg_dmn_pair;
3096 	qdf_mem_copy(soc_reg->mas_chan_params[phy_id].current_country,
3097 		     regulat_info->alpha2,
3098 		     REG_ALPHA2_LEN + 1);
3099 	qdf_mem_copy(soc_reg->cur_country,
3100 		     regulat_info->alpha2,
3101 		     REG_ALPHA2_LEN + 1);
3102 	reg_debug("set cur_country %.2s", soc_reg->cur_country);
3103 
3104 	min_bw_2g = regulat_info->min_bw_2g;
3105 	max_bw_2g = regulat_info->max_bw_2g;
3106 	reg_rule_2g = regulat_info->reg_rules_2g_ptr;
3107 	num_2g_reg_rules = regulat_info->num_2g_reg_rules;
3108 	reg_update_max_bw_per_rule(num_2g_reg_rules,
3109 				   reg_rule_2g, max_bw_2g);
3110 
3111 	min_bw_5g = regulat_info->min_bw_5g;
3112 	max_bw_5g = regulat_info->max_bw_5g;
3113 	reg_rule_5g = regulat_info->reg_rules_5g_ptr;
3114 	num_5g_reg_rules = regulat_info->num_5g_reg_rules;
3115 	reg_update_max_bw_per_rule(num_5g_reg_rules,
3116 				   reg_rule_5g, max_bw_5g);
3117 
3118 	reg_rules = &soc_reg->mas_chan_params[phy_id].reg_rules;
3119 	reg_reset_reg_rules(reg_rules);
3120 
3121 	reg_rules->num_of_reg_rules = num_5g_reg_rules + num_2g_reg_rules;
3122 	if (reg_rules->num_of_reg_rules > MAX_REG_RULES) {
3123 		reg_err("number of reg rules exceeds limit");
3124 		return QDF_STATUS_E_FAILURE;
3125 	}
3126 
3127 	if (reg_rules->num_of_reg_rules) {
3128 		if (num_2g_reg_rules)
3129 			qdf_mem_copy(reg_rules->reg_rules,
3130 				     reg_rule_2g, num_2g_reg_rules *
3131 				     sizeof(struct cur_reg_rule));
3132 		if (num_5g_reg_rules)
3133 			qdf_mem_copy(reg_rules->reg_rules +
3134 				     num_2g_reg_rules, reg_rule_5g,
3135 				     num_5g_reg_rules *
3136 				     sizeof(struct cur_reg_rule));
3137 	}
3138 
3139 	if (num_5g_reg_rules != 0)
3140 		reg_do_auto_bw_correction(num_5g_reg_rules,
3141 					  reg_rule_5g, max_bw_5g);
3142 
3143 	if (num_2g_reg_rules != 0)
3144 		reg_populate_band_channels(MIN_24GHZ_CHANNEL, MAX_24GHZ_CHANNEL,
3145 					   reg_rule_2g, num_2g_reg_rules,
3146 					   min_bw_2g, mas_chan_list);
3147 
3148 	if (num_5g_reg_rules != 0) {
3149 		reg_populate_band_channels(MIN_5GHZ_CHANNEL, MAX_5GHZ_CHANNEL,
3150 					   reg_rule_5g, num_5g_reg_rules,
3151 					   min_bw_5g, mas_chan_list);
3152 		reg_populate_49g_band_channels(reg_rule_5g,
3153 					       num_5g_reg_rules,
3154 					       min_bw_5g,
3155 					       mas_chan_list);
3156 		reg_populate_6g_band_channels(reg_rule_5g,
3157 					      num_5g_reg_rules,
3158 					      min_bw_5g,
3159 					      mas_chan_list);
3160 	}
3161 
3162 	soc_reg->chan_list_recvd[phy_id] = true;
3163 	status = reg_send_ctl_info(soc_reg, regulat_info, tx_ops);
3164 	if (!QDF_IS_STATUS_SUCCESS(status))
3165 		return status;
3166 
3167 	if (soc_reg->new_user_ctry_pending[phy_id]) {
3168 		soc_reg->new_user_ctry_pending[phy_id] = false;
3169 		soc_reg->cc_src = SOURCE_USERSPACE;
3170 		soc_reg->user_ctry_set = true;
3171 		reg_debug("new user country is set");
3172 		reg_run_11d_state_machine(psoc);
3173 	} else if (soc_reg->new_init_ctry_pending[phy_id]) {
3174 		soc_reg->new_init_ctry_pending[phy_id] = false;
3175 		soc_reg->cc_src = SOURCE_USERSPACE;
3176 		reg_debug("new init country is set");
3177 	} else if (soc_reg->new_11d_ctry_pending[phy_id]) {
3178 		soc_reg->new_11d_ctry_pending[phy_id] = false;
3179 		soc_reg->cc_src = SOURCE_11D;
3180 		soc_reg->user_ctry_set = false;
3181 		reg_run_11d_state_machine(psoc);
3182 	} else if (soc_reg->world_country_pending[phy_id]) {
3183 		soc_reg->world_country_pending[phy_id] = false;
3184 		soc_reg->cc_src = SOURCE_CORE;
3185 		soc_reg->user_ctry_set = false;
3186 		reg_run_11d_state_machine(psoc);
3187 	} else {
3188 		if (soc_reg->cc_src == SOURCE_UNKNOWN &&
3189 		    soc_reg->num_phy == phy_id + 1)
3190 			soc_reg->cc_src = SOURCE_DRIVER;
3191 
3192 		qdf_mem_copy(soc_reg->mas_chan_params[phy_id].default_country,
3193 			     regulat_info->alpha2,
3194 			     REG_ALPHA2_LEN + 1);
3195 
3196 		soc_reg->mas_chan_params[phy_id].def_country_code =
3197 			regulat_info->ctry_code;
3198 		soc_reg->mas_chan_params[phy_id].def_region_domain =
3199 			regulat_info->reg_dmn_pair;
3200 
3201 		if (soc_reg->cc_src == SOURCE_DRIVER) {
3202 			qdf_mem_copy(soc_reg->def_country,
3203 				     regulat_info->alpha2,
3204 				     REG_ALPHA2_LEN + 1);
3205 
3206 			soc_reg->def_country_code = regulat_info->ctry_code;
3207 			soc_reg->def_region_domain =
3208 				regulat_info->reg_dmn_pair;
3209 
3210 			if (reg_is_world_alpha2(regulat_info->alpha2)) {
3211 				soc_reg->cc_src = SOURCE_CORE;
3212 				reg_run_11d_state_machine(psoc);
3213 			}
3214 		}
3215 	}
3216 
3217 	pdev = wlan_objmgr_get_pdev_by_id(psoc, pdev_id, dbg_id);
3218 	if (pdev) {
3219 		reg_propagate_mas_chan_list_to_pdev(psoc, pdev, &dir);
3220 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
3221 	}
3222 
3223 	return QDF_STATUS_SUCCESS;
3224 }
3225 
3226 QDF_STATUS reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
3227 				     struct regulatory_channel *chan_list)
3228 {
3229 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3230 
3231 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3232 
3233 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3234 		reg_err("reg pdev private obj is NULL");
3235 		return QDF_STATUS_E_FAILURE;
3236 	}
3237 
3238 	qdf_mem_copy(chan_list, pdev_priv_obj->cur_chan_list,
3239 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
3240 
3241 	return QDF_STATUS_SUCCESS;
3242 }
3243 
3244 #ifdef CONFIG_REG_CLIENT
3245 QDF_STATUS
3246 reg_get_secondary_current_chan_list(struct wlan_objmgr_pdev *pdev,
3247 				    struct regulatory_channel *chan_list)
3248 {
3249 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3250 
3251 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3252 
3253 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3254 		reg_err("reg pdev private obj is NULL");
3255 		return QDF_STATUS_E_FAILURE;
3256 	}
3257 
3258 	qdf_mem_copy(chan_list, pdev_priv_obj->secondary_cur_chan_list,
3259 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
3260 
3261 	return QDF_STATUS_SUCCESS;
3262 }
3263 #endif
3264 
3265 #if defined(CONFIG_AFC_SUPPORT) && defined(CONFIG_BAND_6GHZ)
3266 QDF_STATUS reg_get_6g_ap_master_chan_list(struct wlan_objmgr_pdev *pdev,
3267 					  enum reg_6g_ap_type ap_pwr_type,
3268 					  struct regulatory_channel *chan_list)
3269 {
3270 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3271 	struct regulatory_channel *master_chan_list_6g;
3272 
3273 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3274 
3275 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3276 		reg_err("reg pdev private obj is NULL");
3277 		return QDF_STATUS_E_FAILURE;
3278 	}
3279 
3280 	if (ap_pwr_type >= REG_CURRENT_MAX_AP_TYPE)
3281 		return QDF_STATUS_E_FAILURE;
3282 
3283 	master_chan_list_6g = pdev_priv_obj->mas_chan_list_6g_ap[ap_pwr_type];
3284 	qdf_mem_copy(chan_list, master_chan_list_6g,
3285 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
3286 
3287 	return QDF_STATUS_SUCCESS;
3288 }
3289 
3290 QDF_STATUS reg_get_6g_afc_chan_list(struct wlan_objmgr_pdev *pdev,
3291 				    struct regulatory_channel *chan_list)
3292 {
3293 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3294 	struct regulatory_channel *afc_chan_list;
3295 
3296 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3297 
3298 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3299 		reg_err("reg pdev private obj is NULL");
3300 		return QDF_STATUS_E_FAILURE;
3301 	}
3302 
3303 	afc_chan_list = pdev_priv_obj->afc_chan_list;
3304 	qdf_mem_copy(chan_list, afc_chan_list,
3305 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
3306 
3307 	return QDF_STATUS_SUCCESS;
3308 }
3309 
3310 QDF_STATUS
3311 reg_get_6g_afc_mas_chan_list(struct wlan_objmgr_pdev *pdev,
3312 			     struct regulatory_channel *chan_list)
3313 {
3314 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3315 
3316 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3317 
3318 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3319 		reg_err("reg pdev private obj is NULL");
3320 		return QDF_STATUS_E_FAILURE;
3321 	}
3322 
3323 	qdf_mem_copy(chan_list, pdev_priv_obj->mas_chan_list_6g_afc,
3324 		     NUM_6GHZ_CHANNELS * sizeof(struct regulatory_channel));
3325 
3326 	return QDF_STATUS_SUCCESS;
3327 }
3328 
3329 /**
3330  * struct bw_10log10_pair - The bandwidth and 10*log10(bandwidth) pair.
3331  * ten_l_len = trunc(10*log10(bw)).  'trunc' is truncation function.
3332  * @bw: The input bandwidth
3333  * @ten_l_ten: Integer value of 10 times the Logarithm (to the base-10) of the
3334  * input bandwidth(@bw).
3335  */
3336 struct bw_10log10_pair {
3337 	uint16_t bw;
3338 	int16_t ten_l_ten;
3339 };
3340 
3341 /* The array of bandwidth to trunc(10log10(bandwidth)) mapping */
3342 static const struct bw_10log10_pair bw_to_10log10_map[] = {
3343 	{ 20, 13}, /* 10* 1.30102 = 13.0102 */
3344 	{ 40, 16}, /* 10* 1.60205 = 16.0205 */
3345 	{ 80, 19}, /* 10* 1.90308 = 19.0308 */
3346 	{160, 22}, /* 10* 2.20411 = 22.0411 */
3347 #ifdef WLAN_FEATURE_11BE
3348 	{320, 25}, /* 10* 2.50514 = 25.0514 */
3349 #endif
3350 };
3351 
3352 QDF_STATUS reg_psd_2_eirp(struct wlan_objmgr_pdev *pdev,
3353 			  int16_t psd,
3354 			  uint16_t ch_bw,
3355 			  int16_t *eirp)
3356 {
3357 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
3358 	int16_t ten_log10_bw;
3359 	uint8_t i;
3360 	uint8_t num_bws;
3361 
3362 	pdev_priv_obj = reg_get_pdev_obj(pdev);
3363 
3364 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
3365 		reg_err("reg pdev private obj is NULL");
3366 		return QDF_STATUS_E_FAILURE;
3367 	}
3368 
3369 	/* EIRP = PSD + (10 * log10(CH_BW)) */
3370 	num_bws = QDF_ARRAY_SIZE(bw_to_10log10_map);
3371 	for (i = 0; i < num_bws; i++) {
3372 		if (ch_bw == bw_to_10log10_map[i].bw) {
3373 			ten_log10_bw = bw_to_10log10_map[i].ten_l_ten;
3374 			*eirp = psd + ten_log10_bw;
3375 			return QDF_STATUS_SUCCESS;
3376 		}
3377 	}
3378 	reg_err("Invalid input bandwidth %hd", ch_bw);
3379 	return QDF_STATUS_E_FAILURE;
3380 }
3381 #endif
3382