xref: /wlan-dirver/qca-wifi-host-cmn/umac/regulatory/core/src/reg_build_chan_list.c (revision 503663c6daafffe652fa360bde17243568cd6d2a)
1 /*
2  * Copyright (c) 2014-2019 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 
39 #define MAX_PWR_FCC_CHAN_12 8
40 #define MAX_PWR_FCC_CHAN_13 2
41 #define CHAN_144_CENT_FREQ 5720
42 
43 /**
44  * reg_fill_channel_info() - Populate TX power, antenna gain, channel state,
45  * channel flags, min and max bandwidth to master channel list.
46  * @chan_enum: Channel enum.
47  * @reg_rule: Pointer to regulatory rule which has tx power and antenna gain.
48  * @master_list: Pointer to master channel list.
49  * @min_bw: minimum bandwidth to be used for given channel.
50  */
51 static void reg_fill_channel_info(enum channel_enum chan_enum,
52 				  struct cur_reg_rule *reg_rule,
53 				  struct regulatory_channel *master_list,
54 				  uint16_t min_bw)
55 {
56 	master_list[chan_enum].chan_flags &= ~REGULATORY_CHAN_DISABLED;
57 
58 	master_list[chan_enum].tx_power = reg_rule->reg_power;
59 	master_list[chan_enum].ant_gain = reg_rule->ant_gain;
60 	master_list[chan_enum].state = CHANNEL_STATE_ENABLE;
61 
62 	if (reg_rule->flags & REGULATORY_CHAN_NO_IR) {
63 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_IR;
64 		master_list[chan_enum].state = CHANNEL_STATE_DFS;
65 	}
66 
67 	if (reg_rule->flags & REGULATORY_CHAN_RADAR) {
68 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_RADAR;
69 		master_list[chan_enum].state = CHANNEL_STATE_DFS;
70 	}
71 
72 	if (reg_rule->flags & REGULATORY_CHAN_INDOOR_ONLY)
73 		master_list[chan_enum].chan_flags |=
74 			REGULATORY_CHAN_INDOOR_ONLY;
75 
76 	if (reg_rule->flags & REGULATORY_CHAN_NO_OFDM)
77 		master_list[chan_enum].chan_flags |= REGULATORY_CHAN_NO_OFDM;
78 
79 	master_list[chan_enum].min_bw = min_bw;
80 	if (master_list[chan_enum].max_bw == 20)
81 		master_list[chan_enum].max_bw = reg_rule->max_bw;
82 }
83 
84 /**
85  * reg_populate_band_channels() - For all the valid regdb channels in the master
86  * channel list, find the regulatory rules and call reg_fill_channel_info() to
87  * populate master channel list with txpower, antennagain, BW info, etc.
88  * @start_chan: Start channel enum.
89  * @end_chan: End channel enum.
90  * @rule_start_ptr: Pointer to regulatory rules.
91  * @num_reg_rules: Number of regulatory rules.
92  * @min_reg_bw: Minimum regulatory bandwidth.
93  * @mas_chan_list: Pointer to master channel list.
94  */
95 static void reg_populate_band_channels(enum channel_enum start_chan,
96 				       enum channel_enum end_chan,
97 				       struct cur_reg_rule *rule_start_ptr,
98 				       uint32_t num_reg_rules,
99 				       uint16_t min_reg_bw,
100 				       struct regulatory_channel *mas_chan_list)
101 {
102 	struct cur_reg_rule *found_rule_ptr;
103 	struct cur_reg_rule *cur_rule_ptr;
104 	struct regulatory_channel;
105 	enum channel_enum chan_enum;
106 	uint32_t rule_num, bw;
107 	uint16_t max_bw;
108 	uint16_t min_bw;
109 
110 	for (chan_enum = start_chan; chan_enum <= end_chan; chan_enum++) {
111 		found_rule_ptr = NULL;
112 
113 		max_bw = QDF_MIN((uint16_t)20, channel_map[chan_enum].max_bw);
114 		min_bw = QDF_MAX(min_reg_bw, channel_map[chan_enum].min_bw);
115 
116 		if (channel_map[chan_enum].chan_num == INVALID_CHANNEL_NUM)
117 			continue;
118 
119 		for (bw = max_bw; bw >= min_bw; bw = bw / 2) {
120 			for (rule_num = 0, cur_rule_ptr = rule_start_ptr;
121 			     rule_num < num_reg_rules;
122 			     cur_rule_ptr++, rule_num++) {
123 				if ((cur_rule_ptr->start_freq <=
124 				     mas_chan_list[chan_enum].center_freq -
125 				     bw / 2) &&
126 				    (cur_rule_ptr->end_freq >=
127 				     mas_chan_list[chan_enum].center_freq +
128 				     bw / 2) && (min_bw <= bw)) {
129 					found_rule_ptr = cur_rule_ptr;
130 					break;
131 				}
132 			}
133 
134 			if (found_rule_ptr)
135 				break;
136 		}
137 
138 		if (found_rule_ptr) {
139 			mas_chan_list[chan_enum].max_bw = bw;
140 			reg_fill_channel_info(chan_enum, found_rule_ptr,
141 					      mas_chan_list, min_bw);
142 			/* Disable 2.4 Ghz channels that dont have 20 mhz bw */
143 			if (start_chan == MIN_24GHZ_CHANNEL &&
144 			    mas_chan_list[chan_enum].max_bw < 20) {
145 				mas_chan_list[chan_enum].chan_flags |=
146 						REGULATORY_CHAN_DISABLED;
147 				mas_chan_list[chan_enum].state =
148 						CHANNEL_STATE_DISABLE;
149 			}
150 		}
151 	}
152 }
153 
154 /**
155  * reg_update_max_bw_per_rule() - Update max bandwidth value for given regrules.
156  * @num_reg_rules: Number of regulatory rules.
157  * @reg_rule_start: Pointer to regulatory rules.
158  * @max_bw: Maximum bandwidth
159  */
160 static void reg_update_max_bw_per_rule(uint32_t num_reg_rules,
161 				       struct cur_reg_rule *reg_rule_start,
162 				       uint16_t max_bw)
163 {
164 	uint32_t count;
165 
166 	for (count = 0; count < num_reg_rules; count++)
167 		reg_rule_start[count].max_bw =
168 			min(reg_rule_start[count].max_bw, max_bw);
169 }
170 
171 /**
172  * reg_do_auto_bw_correction() - Calculate and update the maximum bandwidth
173  * value.
174  * @num_reg_rules: Number of regulatory rules.
175  * @reg_rule_ptr: Pointer to regulatory rules.
176  * @max_bw: Maximum bandwidth
177  */
178 static void reg_do_auto_bw_correction(uint32_t num_reg_rules,
179 				      struct cur_reg_rule *reg_rule_ptr,
180 				      uint16_t max_bw)
181 {
182 	uint32_t count;
183 	uint16_t new_bw;
184 
185 	for (count = 0; count < num_reg_rules - 1; count++) {
186 		if ((reg_rule_ptr[count].end_freq ==
187 		     reg_rule_ptr[count + 1].start_freq) &&
188 		    ((reg_rule_ptr[count].max_bw +
189 		      reg_rule_ptr[count + 1].max_bw) <= max_bw)) {
190 			new_bw = reg_rule_ptr[count].max_bw +
191 				reg_rule_ptr[count + 1].max_bw;
192 			reg_rule_ptr[count].max_bw = new_bw;
193 			reg_rule_ptr[count + 1].max_bw = new_bw;
194 		}
195 	}
196 }
197 
198 /**
199  * reg_modify_chan_list_for_dfs_channels() - disable the DFS channels if
200  * dfs_enable set to false.
201  * @chan_list: Pointer to regulatory channel list.
202  * @dfs_enabled: if false, then disable the DFS channels.
203  */
204 static void reg_modify_chan_list_for_dfs_channels(
205 		struct regulatory_channel *chan_list, bool dfs_enabled)
206 {
207 	enum channel_enum chan_enum;
208 
209 	if (dfs_enabled)
210 		return;
211 
212 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
213 		if (chan_list[chan_enum].state == CHANNEL_STATE_DFS) {
214 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
215 			chan_list[chan_enum].chan_flags |=
216 				REGULATORY_CHAN_DISABLED;
217 		}
218 	}
219 }
220 
221 /**
222  * reg_modify_chan_list_for_indoor_channels() - Disable the indoor channels if
223  * indoor_chan_enabled flag is set to false.
224  * @pdev_priv_obj: Pointer to regulatory private pdev structure.
225  */
226 static void reg_modify_chan_list_for_indoor_channels(
227 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
228 {
229 	enum channel_enum chan_enum;
230 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
231 
232 	if (!pdev_priv_obj->indoor_chan_enabled) {
233 		for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
234 			if (REGULATORY_CHAN_INDOOR_ONLY &
235 			    chan_list[chan_enum].chan_flags) {
236 				chan_list[chan_enum].state =
237 					CHANNEL_STATE_DFS;
238 				chan_list[chan_enum].chan_flags |=
239 					REGULATORY_CHAN_NO_IR;
240 			}
241 		}
242 	}
243 
244 	if (pdev_priv_obj->force_ssc_disable_indoor_channel &&
245 	    pdev_priv_obj->sap_state) {
246 		for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
247 			if (REGULATORY_CHAN_INDOOR_ONLY &
248 			    chan_list[chan_enum].chan_flags) {
249 				chan_list[chan_enum].state =
250 					CHANNEL_STATE_DISABLE;
251 				chan_list[chan_enum].chan_flags |=
252 					REGULATORY_CHAN_DISABLED;
253 			}
254 		}
255 	}
256 }
257 
258 /**
259  * reg_modify_chan_list_for_band() - Based on the input band value, either
260  * disable 2GHz or 5GHz channels.
261  * @chan_list: Pointer to regulatory channel list.
262  * @band_val: Input band value.
263  */
264 static void reg_modify_chan_list_for_band(struct regulatory_channel *chan_list,
265 					  enum band_info band_val)
266 {
267 	enum channel_enum chan_enum;
268 
269 	if (band_val == BAND_2G) {
270 		for (chan_enum = MIN_5GHZ_CHANNEL;
271 		     chan_enum <= MAX_5GHZ_CHANNEL; chan_enum++) {
272 			chan_list[chan_enum].chan_flags |=
273 				REGULATORY_CHAN_DISABLED;
274 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
275 		}
276 	}
277 
278 	if (band_val == BAND_5G) {
279 		for (chan_enum = MIN_24GHZ_CHANNEL;
280 		     chan_enum <= MAX_24GHZ_CHANNEL; chan_enum++) {
281 			chan_list[chan_enum].chan_flags |=
282 				REGULATORY_CHAN_DISABLED;
283 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
284 		}
285 	}
286 }
287 
288 /**
289  * reg_modify_chan_list_for_fcc_channel() - Set maximum FCC txpower for channel
290  * 12 and 13 if set_fcc_channel flag is set to true.
291  * @chan_list: Pointer to regulatory channel list.
292  * @set_fcc_channel: If this flag is set to true, then set the max FCC txpower
293  * for channel 12 and 13.
294  */
295 static void reg_modify_chan_list_for_fcc_channel(
296 		struct regulatory_channel *chan_list, bool set_fcc_channel)
297 {
298 	enum channel_enum chan_enum;
299 
300 	if (!set_fcc_channel)
301 		return;
302 
303 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
304 		if (chan_list[chan_enum].center_freq == CHAN_12_CENT_FREQ)
305 			chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_12;
306 
307 		if (chan_list[chan_enum].center_freq == CHAN_13_CENT_FREQ)
308 			chan_list[chan_enum].tx_power = MAX_PWR_FCC_CHAN_13;
309 	}
310 }
311 
312 /**
313  * reg_modify_chan_list_for_chan_144() - Disable channel 144 if en_chan_144 flag
314  * is set to false.
315  * @chan_list: Pointer to regulatory channel list.
316  * @en_chan_144: if false, then disable channel 144.
317  */
318 static void reg_modify_chan_list_for_chan_144(
319 		struct regulatory_channel *chan_list, bool en_chan_144)
320 {
321 	enum channel_enum chan_enum;
322 
323 	if (en_chan_144)
324 		return;
325 
326 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
327 		if (chan_list[chan_enum].center_freq == CHAN_144_CENT_FREQ) {
328 			chan_list[chan_enum].chan_flags |=
329 				REGULATORY_CHAN_DISABLED;
330 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
331 		}
332 	}
333 }
334 
335 /**
336  * reg_modify_chan_list_for_nol_list() - Disable the channel if nol_chan flag is
337  * set.
338  * @chan_list: Pointer to regulatory channel list.
339  */
340 static void reg_modify_chan_list_for_nol_list(
341 		struct regulatory_channel *chan_list)
342 {
343 	enum channel_enum chan_enum;
344 
345 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
346 		if (chan_list[chan_enum].nol_chan) {
347 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
348 			chan_list[chan_enum].chan_flags |=
349 				REGULATORY_CHAN_DISABLED;
350 		}
351 	}
352 }
353 
354 /**
355  * reg_find_low_limit_chan_enum() - Find low limit 2G and 5G channel enums.
356  * @chan_list: Pointer to regulatory channel list.
357  * @low_freq: low limit frequency.
358  * @low_limit: pointer to output low limit enum.
359  *
360  * Return: None
361  */
362 static void reg_find_low_limit_chan_enum(
363 		struct regulatory_channel *chan_list, qdf_freq_t low_freq,
364 		uint32_t *low_limit)
365 {
366 	enum channel_enum chan_enum;
367 	uint16_t min_bw;
368 	uint16_t max_bw;
369 	qdf_freq_t center_freq;
370 
371 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
372 		min_bw = chan_list[chan_enum].min_bw;
373 		max_bw = chan_list[chan_enum].max_bw;
374 		center_freq = chan_list[chan_enum].center_freq;
375 
376 		if ((center_freq - min_bw / 2) >= low_freq) {
377 			if ((center_freq - max_bw / 2) < low_freq) {
378 				if (max_bw <= 20)
379 					max_bw = ((center_freq - low_freq) * 2);
380 				if (max_bw < min_bw)
381 					max_bw = min_bw;
382 				chan_list[chan_enum].max_bw = max_bw;
383 			}
384 			*low_limit = chan_enum;
385 			break;
386 		}
387 	}
388 }
389 
390 /**
391  * reg_find_high_limit_chan_enum() - Find high limit 2G and 5G channel enums.
392  * @chan_list: Pointer to regulatory channel list.
393  * @high_freq: high limit frequency.
394  * @high_limit: pointer to output high limit enum.
395  *
396  * Return: None
397  */
398 static void reg_find_high_limit_chan_enum(
399 		struct regulatory_channel *chan_list, qdf_freq_t high_freq,
400 		uint32_t *high_limit)
401 {
402 	enum channel_enum chan_enum;
403 	uint16_t min_bw;
404 	uint16_t max_bw;
405 	qdf_freq_t center_freq;
406 
407 	for (chan_enum = NUM_CHANNELS - 1; chan_enum >= 0; chan_enum--) {
408 		min_bw = chan_list[chan_enum].min_bw;
409 		max_bw = chan_list[chan_enum].max_bw;
410 		center_freq = chan_list[chan_enum].center_freq;
411 
412 		if (center_freq + min_bw / 2 <= high_freq) {
413 			if ((center_freq + max_bw / 2) > high_freq) {
414 				if (max_bw <= 20)
415 					max_bw = ((high_freq -
416 						   center_freq) * 2);
417 				if (max_bw < min_bw)
418 					max_bw = min_bw;
419 				chan_list[chan_enum].max_bw = max_bw;
420 			}
421 			*high_limit = chan_enum;
422 			break;
423 		}
424 
425 		if (chan_enum == 0)
426 			break;
427 	}
428 }
429 
430 #ifdef REG_DISABLE_JP_CH144
431 /**
432  * reg_modify_chan_list_for_japan() - Disable channel 144 for MKK17_MKKC
433  * regdomain by default.
434  * @pdev: Pointer to pdev
435  *
436  * Return: None
437  */
438 static void
439 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev)
440 {
441 #define MKK17_MKKC 0xE1
442 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
443 
444 	pdev_priv_obj = reg_get_pdev_obj(pdev);
445 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
446 		reg_err("reg pdev priv obj is NULL");
447 		return;
448 	}
449 
450 	if (pdev_priv_obj->reg_dmn_pair == MKK17_MKKC)
451 		pdev_priv_obj->en_chan_144 = false;
452 
453 #undef MKK17_MKKC
454 }
455 #else
456 static inline void
457 reg_modify_chan_list_for_japan(struct wlan_objmgr_pdev *pdev)
458 {
459 }
460 #endif
461 /**
462  * reg_modify_chan_list_for_freq_range() - Modify channel list for the given low
463  * and high frequency range.
464  * @chan_list: Pointer to regulatory channel list.
465  * @low_freq_2g: Low frequency 2G.
466  * @high_freq_2g: High frequency 2G.
467  * @low_freq_5g: Low frequency 5G.
468  * @high_freq_5g: High frequency 5G.
469  *
470  * Return: None
471  */
472 static void
473 reg_modify_chan_list_for_freq_range(struct regulatory_channel *chan_list,
474 				    qdf_freq_t low_freq_2g,
475 				    qdf_freq_t high_freq_2g,
476 				    qdf_freq_t low_freq_5g,
477 				    qdf_freq_t high_freq_5g)
478 {
479 	uint32_t low_limit_2g = NUM_CHANNELS;
480 	uint32_t high_limit_2g = NUM_CHANNELS;
481 	uint32_t low_limit_5g = NUM_CHANNELS;
482 	uint32_t high_limit_5g = NUM_CHANNELS;
483 	enum channel_enum chan_enum;
484 	bool chan_in_range;
485 
486 	reg_find_low_limit_chan_enum(chan_list, low_freq_2g, &low_limit_2g);
487 	reg_find_low_limit_chan_enum(chan_list, low_freq_5g, &low_limit_5g);
488 	reg_find_high_limit_chan_enum(chan_list, high_freq_2g, &high_limit_2g);
489 	reg_find_high_limit_chan_enum(chan_list, high_freq_5g, &high_limit_5g);
490 
491 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
492 		chan_in_range = false;
493 		if  ((low_limit_2g <= chan_enum) &&
494 		     (high_limit_2g >= chan_enum) &&
495 		     (low_limit_2g != NUM_CHANNELS) &&
496 		     (high_limit_2g != NUM_CHANNELS))
497 			chan_in_range = true;
498 
499 		if  ((low_limit_5g <= chan_enum) &&
500 		     (high_limit_5g >= chan_enum) &&
501 		     (low_limit_5g != NUM_CHANNELS) &&
502 		     (high_limit_5g != NUM_CHANNELS))
503 			chan_in_range = true;
504 
505 		if (!chan_in_range) {
506 			chan_list[chan_enum].chan_flags |=
507 				REGULATORY_CHAN_DISABLED;
508 			chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
509 		}
510 	}
511 }
512 
513 void reg_init_pdev_mas_chan_list(
514 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj,
515 		struct mas_chan_params *mas_chan_params)
516 {
517 	qdf_mem_copy(pdev_priv_obj->mas_chan_list,
518 		     mas_chan_params->mas_chan_list,
519 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
520 
521 	pdev_priv_obj->dfs_region = mas_chan_params->dfs_region;
522 
523 	pdev_priv_obj->phybitmap = mas_chan_params->phybitmap;
524 
525 	pdev_priv_obj->reg_dmn_pair = mas_chan_params->reg_dmn_pair;
526 	pdev_priv_obj->ctry_code =  mas_chan_params->ctry_code;
527 
528 	pdev_priv_obj->def_region_domain = mas_chan_params->reg_dmn_pair;
529 	pdev_priv_obj->def_country_code =  mas_chan_params->ctry_code;
530 
531 	qdf_mem_copy(pdev_priv_obj->default_country,
532 		     mas_chan_params->default_country, REG_ALPHA2_LEN + 1);
533 
534 	qdf_mem_copy(pdev_priv_obj->current_country,
535 		     mas_chan_params->current_country, REG_ALPHA2_LEN + 1);
536 }
537 
538 /**
539  * reg_modify_chan_list_for_cached_channels() - If num_cache_channels are
540  * non-zero, then disable the pdev channels which is given in
541  * cache_disable_chan_list.
542  * @pdev_priv_obj: Pointer to regulatory pdev private object.
543  */
544 #ifdef DISABLE_CHANNEL_LIST
545 static void reg_modify_chan_list_for_cached_channels(
546 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
547 {
548 	uint32_t i, j;
549 	uint32_t num_cache_channels = pdev_priv_obj->num_cache_channels;
550 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
551 	struct regulatory_channel *cache_chan_list =
552 					pdev_priv_obj->cache_disable_chan_list;
553 
554 	if (!num_cache_channels)
555 		return;
556 
557 	if (pdev_priv_obj->disable_cached_channels) {
558 		for (i = 0; i < num_cache_channels; i++)
559 			for (j = 0; j < NUM_CHANNELS; j++)
560 				if (cache_chan_list[i].chan_num ==
561 							chan_list[j].chan_num) {
562 					chan_list[j].state =
563 							CHANNEL_STATE_DISABLE;
564 					chan_list[j].chan_flags |=
565 						REGULATORY_CHAN_DISABLED;
566 				}
567 	}
568 }
569 #else
570 static void reg_modify_chan_list_for_cached_channels(
571 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
572 {
573 }
574 #endif
575 
576 #ifdef CONFIG_REG_CLIENT
577 /**
578  * reg_modify_chan_list_for_srd_channels() - Modify SRD channels in ETSI13
579  * @pdev: Pointer to pdev object
580  * @chan_list: Current channel list
581  *
582  * This function converts SRD channels to passive in ETSI13 regulatory domain
583  * when enable_srd_chan_in_master_mode is not set.
584  */
585 static void
586 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev,
587 				      struct regulatory_channel *chan_list)
588 {
589 	enum channel_enum chan_enum;
590 
591 	if (!reg_is_etsi13_regdmn(pdev))
592 		return;
593 
594 	if (reg_is_etsi13_srd_chan_allowed_master_mode(pdev))
595 		return;
596 
597 	for (chan_enum = 0; chan_enum < NUM_CHANNELS; chan_enum++) {
598 		if (chan_list[chan_enum].chan_flags & REGULATORY_CHAN_DISABLED)
599 			continue;
600 
601 		if (reg_is_etsi13_srd_chan(pdev,
602 					   chan_list[chan_enum].chan_num)) {
603 			chan_list[chan_enum].state =
604 				CHANNEL_STATE_DFS;
605 			chan_list[chan_enum].chan_flags |=
606 				REGULATORY_CHAN_NO_IR;
607 		}
608 	}
609 }
610 #else
611 static inline void
612 reg_modify_chan_list_for_srd_channels(struct wlan_objmgr_pdev *pdev,
613 				      struct regulatory_channel *chan_list)
614 {
615 }
616 #endif
617 
618 #ifdef DISABLE_UNII_SHARED_BANDS
619 /**
620  * reg_is_reg_unii_band_1_set() - Check UNII bitmap
621  * @unii_bitmap: 5G UNII band bitmap
622  *
623  * This function checks the input bitmap to disable UNII-1 band channels.
624  *
625  * Return: Return true if UNII-1 channels need to be disabled,
626  * else return false.
627  */
628 static bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap)
629 {
630 	return !!(unii_bitmap & BIT(REG_UNII_BAND_1));
631 }
632 
633 /**
634  * reg_is_reg_unii_band_2a_set() - Check UNII bitmap
635  * @unii_bitmap: 5G UNII band bitmap
636  *
637  * This function checks the input bitmap to disable UNII-2A band channels.
638  *
639  * Return: Return true if UNII-2A channels need to be disabled,
640  * else return false.
641  */
642 static bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap)
643 {
644 	return !!(unii_bitmap & BIT(REG_UNII_BAND_2A));
645 }
646 
647 /**
648  * reg_is_5g_enum() - Check if channel enum is a 5G channel enum
649  * @chan_enum: channel enum
650  *
651  * Return: Return true if the input channel enum is 5G, else return false.
652  */
653 static bool reg_is_5g_enum(enum channel_enum chan_enum)
654 {
655 	return (chan_enum >= MIN_5GHZ_CHANNEL && chan_enum <= MAX_5GHZ_CHANNEL);
656 }
657 
658 /**
659  * reg_remove_unii_chan_from_chan_list() - Remove UNII band channels
660  * @chan_list: Pointer to current channel list
661  * @start_enum: starting enum value
662  * @end_enum: ending enum value
663  *
664  * Remove channels in a unii band based in on the input start_enum and end_enum.
665  * Disable the state and flags. Set disable_coex flag to true.
666  *
667  * return: void.
668  */
669 static void
670 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list,
671 				    enum channel_enum start_enum,
672 				    enum channel_enum end_enum)
673 {
674 	enum channel_enum chan_enum;
675 
676 	if (!(reg_is_5g_enum(start_enum) && reg_is_5g_enum(end_enum))) {
677 		reg_err_rl("start_enum or end_enum is invalid");
678 		return;
679 	}
680 
681 	for (chan_enum = start_enum; chan_enum <= end_enum; chan_enum++) {
682 		chan_list[chan_enum].state = CHANNEL_STATE_DISABLE;
683 		chan_list[chan_enum].chan_flags |= REGULATORY_CHAN_DISABLED;
684 	}
685 }
686 
687 /**
688  * reg_modify_disable_chan_list_for_unii1_and_unii2a() - Disable UNII-1 and
689  * UNII2A band
690  * @pdev_priv_obj: Pointer to pdev private object
691  *
692  * This function disables the UNII-1 and UNII-2A band channels
693  * based on input unii_5g_bitmap.
694  *
695  * Return: void.
696  */
697 static void
698 reg_modify_disable_chan_list_for_unii1_and_unii2a(
699 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
700 {
701 	uint8_t unii_bitmap = pdev_priv_obj->unii_5g_bitmap;
702 	struct regulatory_channel *chan_list = pdev_priv_obj->cur_chan_list;
703 
704 	if (reg_is_reg_unii_band_1_set(unii_bitmap)) {
705 		reg_remove_unii_chan_from_chan_list(chan_list,
706 						    MIN_UNII_1_BAND_CHANNEL,
707 						    MAX_UNII_1_BAND_CHANNEL);
708 	}
709 
710 	if (reg_is_reg_unii_band_2a_set(unii_bitmap)) {
711 		reg_remove_unii_chan_from_chan_list(chan_list,
712 						    MIN_UNII_2A_BAND_CHANNEL,
713 						    MAX_UNII_2A_BAND_CHANNEL);
714 	}
715 }
716 #else
717 static inline bool reg_is_reg_unii_band_1_set(uint8_t unii_bitmap)
718 {
719 	return false;
720 }
721 
722 static inline bool reg_is_reg_unii_band_2a_set(uint8_t unii_bitmap)
723 {
724 	return false;
725 }
726 
727 static inline bool reg_is_5g_enum(enum channel_enum chan_enum)
728 {
729 	return false;
730 }
731 
732 static inline void
733 reg_remove_unii_chan_from_chan_list(struct regulatory_channel *chan_list,
734 				    enum channel_enum start_enum,
735 				    enum channel_enum end_enum)
736 {
737 }
738 
739 static inline void
740 reg_modify_disable_chan_list_for_unii1_and_unii2a(
741 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
742 {
743 }
744 #endif
745 
746 void reg_compute_pdev_current_chan_list(struct wlan_regulatory_pdev_priv_obj
747 					*pdev_priv_obj)
748 {
749 	qdf_mem_copy(pdev_priv_obj->cur_chan_list, pdev_priv_obj->mas_chan_list,
750 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
751 
752 	reg_modify_chan_list_for_freq_range(pdev_priv_obj->cur_chan_list,
753 					    pdev_priv_obj->range_2g_low,
754 					    pdev_priv_obj->range_2g_high,
755 					    pdev_priv_obj->range_5g_low,
756 					    pdev_priv_obj->range_5g_high);
757 
758 	reg_modify_chan_list_for_band(pdev_priv_obj->cur_chan_list,
759 				      pdev_priv_obj->band_capability);
760 
761 	reg_modify_disable_chan_list_for_unii1_and_unii2a(pdev_priv_obj);
762 
763 	reg_modify_chan_list_for_dfs_channels(pdev_priv_obj->cur_chan_list,
764 					      pdev_priv_obj->dfs_enabled);
765 
766 	reg_modify_chan_list_for_nol_list(pdev_priv_obj->cur_chan_list);
767 
768 	reg_modify_chan_list_for_indoor_channels(pdev_priv_obj);
769 
770 	reg_modify_chan_list_for_fcc_channel(pdev_priv_obj->cur_chan_list,
771 					     pdev_priv_obj->set_fcc_channel);
772 
773 	reg_modify_chan_list_for_chan_144(pdev_priv_obj->cur_chan_list,
774 					  pdev_priv_obj->en_chan_144);
775 
776 	reg_modify_chan_list_for_cached_channels(pdev_priv_obj);
777 
778 	reg_modify_chan_list_for_srd_channels(pdev_priv_obj->pdev_ptr,
779 					      pdev_priv_obj->cur_chan_list);
780 }
781 
782 void reg_reset_reg_rules(struct reg_rule_info *reg_rules)
783 {
784 	qdf_mem_zero(reg_rules, sizeof(*reg_rules));
785 }
786 
787 void reg_save_reg_rules_to_pdev(
788 		struct reg_rule_info *psoc_reg_rules,
789 		struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj)
790 {
791 	uint32_t reg_rule_len;
792 	struct reg_rule_info *pdev_reg_rules;
793 
794 	qdf_spin_lock_bh(&pdev_priv_obj->reg_rules_lock);
795 
796 	pdev_reg_rules = &pdev_priv_obj->reg_rules;
797 	reg_reset_reg_rules(pdev_reg_rules);
798 
799 	pdev_reg_rules->num_of_reg_rules = psoc_reg_rules->num_of_reg_rules;
800 	if (!pdev_reg_rules->num_of_reg_rules) {
801 		qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock);
802 		reg_err("no reg rules in psoc");
803 		return;
804 	}
805 
806 	reg_rule_len = pdev_reg_rules->num_of_reg_rules *
807 		       sizeof(struct cur_reg_rule);
808 	qdf_mem_copy(pdev_reg_rules->reg_rules, psoc_reg_rules->reg_rules,
809 		     reg_rule_len);
810 
811 	qdf_mem_copy(pdev_reg_rules->alpha2, pdev_priv_obj->current_country,
812 		     REG_ALPHA2_LEN + 1);
813 	pdev_reg_rules->dfs_region = pdev_priv_obj->dfs_region;
814 
815 	qdf_spin_unlock_bh(&pdev_priv_obj->reg_rules_lock);
816 }
817 
818 void reg_propagate_mas_chan_list_to_pdev(struct wlan_objmgr_psoc *psoc,
819 					 void *object, void *arg)
820 {
821 	struct wlan_objmgr_pdev *pdev = (struct wlan_objmgr_pdev *)object;
822 	struct wlan_regulatory_psoc_priv_obj *psoc_priv_obj;
823 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
824 	enum direction *dir = arg;
825 	uint32_t pdev_id;
826 	struct wlan_lmac_if_reg_tx_ops *reg_tx_ops;
827 	struct reg_rule_info *psoc_reg_rules;
828 
829 	psoc_priv_obj = (struct wlan_regulatory_psoc_priv_obj *)
830 		wlan_objmgr_psoc_get_comp_private_obj(
831 				psoc, WLAN_UMAC_COMP_REGULATORY);
832 
833 	if (!psoc_priv_obj) {
834 		reg_err("psoc priv obj is NULL");
835 		return;
836 	}
837 
838 	pdev_priv_obj = reg_get_pdev_obj(pdev);
839 
840 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
841 		reg_err("reg pdev priv obj is NULL");
842 		return;
843 	}
844 
845 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
846 	reg_init_pdev_mas_chan_list(
847 			pdev_priv_obj,
848 			&psoc_priv_obj->mas_chan_params[pdev_id]);
849 	psoc_reg_rules = &psoc_priv_obj->mas_chan_params[pdev_id].reg_rules;
850 	reg_save_reg_rules_to_pdev(psoc_reg_rules, pdev_priv_obj);
851 	reg_modify_chan_list_for_japan(pdev);
852 	pdev_priv_obj->chan_list_recvd =
853 		psoc_priv_obj->chan_list_recvd[pdev_id];
854 	reg_compute_pdev_current_chan_list(pdev_priv_obj);
855 
856 	reg_tx_ops = reg_get_psoc_tx_ops(psoc);
857 	if (reg_tx_ops->fill_umac_legacy_chanlist) {
858 		reg_tx_ops->fill_umac_legacy_chanlist(
859 				pdev, pdev_priv_obj->cur_chan_list);
860 	} else {
861 		if (*dir == NORTHBOUND)
862 			reg_send_scheduler_msg_nb(psoc, pdev);
863 		else
864 			reg_send_scheduler_msg_sb(psoc, pdev);
865 	}
866 }
867 
868 /**
869  * reg_populate_6g_band_channels() - For all the valid 6GHz regdb channels
870  * in the master channel list, find the regulatory rules and call
871  * reg_fill_channel_info() to populate master channel list with txpower,
872  * antennagain, BW info, etc.
873  * @reg_rule_5g: Pointer to regulatory rule.
874  * @num_5g_reg_rules: Number of regulatory rules.
875  * @min_bw_5g: Minimum regulatory bandwidth.
876  * @mas_chan_list: Pointer to the master channel list.
877  */
878 #ifdef CONFIG_BAND_6GHZ
879 static void
880 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g,
881 			      uint32_t num_5g_reg_rules,
882 			      uint16_t min_bw_5g,
883 			      struct regulatory_channel *mas_chan_list)
884 {
885 	reg_populate_band_channels(MIN_6GHZ_CHANNEL,
886 				   MAX_6GHZ_CHANNEL,
887 				   reg_rule_5g,
888 				   num_5g_reg_rules,
889 				   min_bw_5g,
890 				   mas_chan_list);
891 }
892 #else
893 static void
894 reg_populate_6g_band_channels(struct cur_reg_rule *reg_rule_5g,
895 			      uint32_t num_5g_reg_rules,
896 			      uint16_t min_bw_5g,
897 			      struct regulatory_channel *mas_chan_list)
898 {
899 }
900 #endif /* CONFIG_BAND_6GHZ */
901 
902 #ifdef CONFIG_REG_CLIENT
903 /**
904  * reg_send_ctl_info() - Send CTL info to firmware when regdb is not offloaded
905  * @soc_reg: soc private object for regulatory
906  * @regulatory_info: regulatory info
907  * @tx_ops: send operations for regulatory component
908  *
909  * Return: QDF_STATUS
910  */
911 static QDF_STATUS
912 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg,
913 		  struct cur_regulatory_info *regulatory_info,
914 		  struct wlan_lmac_if_reg_tx_ops *tx_ops)
915 {
916 	struct wlan_objmgr_psoc *psoc = regulatory_info->psoc;
917 	struct reg_ctl_params params = {0};
918 	QDF_STATUS status;
919 	uint16_t regd_index;
920 	uint32_t index_2g, index_5g;
921 
922 	if (soc_reg->offload_enabled)
923 		return QDF_STATUS_SUCCESS;
924 
925 	if (!tx_ops || !tx_ops->send_ctl_info) {
926 		reg_err("No regulatory tx_ops for send_ctl_info");
927 		return QDF_STATUS_E_FAULT;
928 	}
929 
930 	status = reg_get_rdpair_from_regdmn_id(regulatory_info->reg_dmn_pair,
931 					       &regd_index);
932 	if (QDF_IS_STATUS_ERROR(status)) {
933 		reg_err("Failed to get regdomain index for regdomain pair: %x",
934 			regulatory_info->reg_dmn_pair);
935 		return status;
936 	}
937 
938 	index_2g = g_reg_dmn_pairs[regd_index].dmn_id_2g;
939 	index_5g = g_reg_dmn_pairs[regd_index].dmn_id_5g;
940 	params.ctl_2g = regdomains_2g[index_2g].ctl_val;
941 	params.ctl_5g = regdomains_5g[index_5g].ctl_val;
942 	params.regd_2g = reg_2g_sub_dmn_code[index_2g];
943 	params.regd_5g = reg_5g_sub_dmn_code[index_5g];
944 
945 	if (reg_is_world_ctry_code(regulatory_info->reg_dmn_pair))
946 		params.regd = regulatory_info->reg_dmn_pair;
947 	else
948 		params.regd = regulatory_info->ctry_code | COUNTRY_ERD_FLAG;
949 
950 	reg_debug("regdomain pair = %u, regdomain index = %u",
951 		  regulatory_info->reg_dmn_pair, regd_index);
952 	reg_debug("index_2g = %u, index_5g = %u, ctl_2g = %x, ctl_5g = %x",
953 		  index_2g, index_5g, params.ctl_2g, params.ctl_5g);
954 	reg_debug("regd_2g = %x, regd_5g = %x, regd = %x",
955 		  params.regd_2g, params.regd_5g, params.regd);
956 
957 	status = tx_ops->send_ctl_info(psoc, &params);
958 	if (QDF_IS_STATUS_ERROR(status))
959 		reg_err("Failed to send CTL info to firmware");
960 
961 	return status;
962 }
963 #else
964 static QDF_STATUS
965 reg_send_ctl_info(struct wlan_regulatory_psoc_priv_obj *soc_reg,
966 		  struct cur_regulatory_info *regulatory_info,
967 		  struct wlan_lmac_if_reg_tx_ops *tx_ops)
968 {
969 	return QDF_STATUS_SUCCESS;
970 }
971 #endif
972 
973 QDF_STATUS reg_process_master_chan_list(
974 		struct cur_regulatory_info *regulat_info)
975 {
976 	struct wlan_regulatory_psoc_priv_obj *soc_reg;
977 	uint32_t num_2g_reg_rules, num_5g_reg_rules;
978 	struct cur_reg_rule *reg_rule_2g, *reg_rule_5g;
979 	uint16_t min_bw_2g, max_bw_2g, min_bw_5g, max_bw_5g;
980 	struct regulatory_channel *mas_chan_list;
981 	struct wlan_objmgr_psoc *psoc;
982 	enum channel_enum chan_enum;
983 	wlan_objmgr_ref_dbgid dbg_id;
984 	enum direction dir;
985 	uint8_t phy_id;
986 	struct wlan_objmgr_pdev *pdev;
987 	struct wlan_lmac_if_reg_tx_ops *tx_ops;
988 	struct reg_rule_info *reg_rules;
989 	QDF_STATUS status;
990 
991 	psoc = regulat_info->psoc;
992 	soc_reg = reg_get_psoc_obj(psoc);
993 
994 	if (!IS_VALID_PSOC_REG_OBJ(soc_reg)) {
995 		reg_err("psoc reg component is NULL");
996 		return QDF_STATUS_E_FAILURE;
997 	}
998 
999 	tx_ops = reg_get_psoc_tx_ops(psoc);
1000 	phy_id = regulat_info->phy_id;
1001 
1002 	if (reg_ignore_default_country(soc_reg, regulat_info)) {
1003 		status = reg_set_curr_country(soc_reg, regulat_info, tx_ops);
1004 		if (QDF_IS_STATUS_SUCCESS(status)) {
1005 			reg_debug("WLAN restart - Ignore default CC for phy_id: %u",
1006 				  phy_id);
1007 			return QDF_STATUS_SUCCESS;
1008 		}
1009 	}
1010 
1011 	reg_debug("process reg master chan list");
1012 
1013 	if (soc_reg->offload_enabled) {
1014 		dbg_id = WLAN_REGULATORY_NB_ID;
1015 		dir = NORTHBOUND;
1016 	} else {
1017 		dbg_id = WLAN_REGULATORY_SB_ID;
1018 		dir = SOUTHBOUND;
1019 	}
1020 
1021 	if (regulat_info->status_code != REG_SET_CC_STATUS_PASS) {
1022 		reg_err("Setting country code failed, status code is %d",
1023 			regulat_info->status_code);
1024 
1025 		pdev = wlan_objmgr_get_pdev_by_id(psoc, phy_id, dbg_id);
1026 		if (!pdev) {
1027 			reg_err("pdev is NULL");
1028 			return QDF_STATUS_E_FAILURE;
1029 		}
1030 
1031 		if (tx_ops->set_country_failed)
1032 			tx_ops->set_country_failed(pdev);
1033 
1034 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
1035 
1036 		if (regulat_info->status_code != REG_CURRENT_ALPHA2_NOT_FOUND)
1037 			return QDF_STATUS_E_FAILURE;
1038 
1039 		soc_reg->new_user_ctry_pending[phy_id] = false;
1040 		soc_reg->new_11d_ctry_pending[phy_id] = false;
1041 		soc_reg->world_country_pending[phy_id] = true;
1042 	}
1043 
1044 	mas_chan_list = soc_reg->mas_chan_params[phy_id].mas_chan_list;
1045 
1046 	reg_init_channel_map(regulat_info->dfs_region);
1047 
1048 	for (chan_enum = 0; chan_enum < NUM_CHANNELS;
1049 	     chan_enum++) {
1050 		mas_chan_list[chan_enum].chan_num =
1051 			channel_map[chan_enum].chan_num;
1052 		mas_chan_list[chan_enum].center_freq =
1053 			channel_map[chan_enum].center_freq;
1054 		mas_chan_list[chan_enum].chan_flags =
1055 			REGULATORY_CHAN_DISABLED;
1056 		mas_chan_list[chan_enum].state =
1057 			CHANNEL_STATE_DISABLE;
1058 		mas_chan_list[chan_enum].nol_chan = false;
1059 	}
1060 
1061 	soc_reg->num_phy = regulat_info->num_phy;
1062 	soc_reg->mas_chan_params[phy_id].phybitmap =
1063 		regulat_info->phybitmap;
1064 	soc_reg->mas_chan_params[phy_id].dfs_region =
1065 		regulat_info->dfs_region;
1066 	soc_reg->mas_chan_params[phy_id].ctry_code =
1067 		regulat_info->ctry_code;
1068 	soc_reg->mas_chan_params[phy_id].reg_dmn_pair =
1069 		regulat_info->reg_dmn_pair;
1070 	qdf_mem_copy(soc_reg->mas_chan_params[phy_id].current_country,
1071 		     regulat_info->alpha2,
1072 		     REG_ALPHA2_LEN + 1);
1073 	qdf_mem_copy(soc_reg->cur_country,
1074 		     regulat_info->alpha2,
1075 		     REG_ALPHA2_LEN + 1);
1076 	reg_debug("set cur_country %.2s", soc_reg->cur_country);
1077 
1078 	min_bw_2g = regulat_info->min_bw_2g;
1079 	max_bw_2g = regulat_info->max_bw_2g;
1080 	reg_rule_2g = regulat_info->reg_rules_2g_ptr;
1081 	num_2g_reg_rules = regulat_info->num_2g_reg_rules;
1082 	reg_update_max_bw_per_rule(num_2g_reg_rules,
1083 				   reg_rule_2g, max_bw_2g);
1084 
1085 	min_bw_5g = regulat_info->min_bw_5g;
1086 	max_bw_5g = regulat_info->max_bw_5g;
1087 	reg_rule_5g = regulat_info->reg_rules_5g_ptr;
1088 	num_5g_reg_rules = regulat_info->num_5g_reg_rules;
1089 	reg_update_max_bw_per_rule(num_5g_reg_rules,
1090 				   reg_rule_5g, max_bw_5g);
1091 
1092 	reg_rules = &soc_reg->mas_chan_params[phy_id].reg_rules;
1093 	reg_reset_reg_rules(reg_rules);
1094 
1095 	reg_rules->num_of_reg_rules = num_5g_reg_rules + num_2g_reg_rules;
1096 	if (reg_rules->num_of_reg_rules > MAX_REG_RULES) {
1097 		reg_err("number of reg rules exceeds limit");
1098 		return QDF_STATUS_E_FAILURE;
1099 	}
1100 
1101 	if (reg_rules->num_of_reg_rules) {
1102 		if (num_2g_reg_rules)
1103 			qdf_mem_copy(reg_rules->reg_rules,
1104 				     reg_rule_2g, num_2g_reg_rules *
1105 				     sizeof(struct cur_reg_rule));
1106 		if (num_5g_reg_rules)
1107 			qdf_mem_copy(reg_rules->reg_rules +
1108 				     num_2g_reg_rules, reg_rule_5g,
1109 				     num_5g_reg_rules *
1110 				     sizeof(struct cur_reg_rule));
1111 	}
1112 
1113 	if (num_5g_reg_rules != 0)
1114 		reg_do_auto_bw_correction(num_5g_reg_rules,
1115 					  reg_rule_5g, max_bw_5g);
1116 
1117 	if (num_2g_reg_rules != 0)
1118 		reg_populate_band_channels(MIN_24GHZ_CHANNEL, MAX_24GHZ_CHANNEL,
1119 					   reg_rule_2g, num_2g_reg_rules,
1120 					   min_bw_2g, mas_chan_list);
1121 
1122 	if (num_5g_reg_rules != 0) {
1123 		reg_populate_band_channels(MIN_5GHZ_CHANNEL, MAX_5GHZ_CHANNEL,
1124 					   reg_rule_5g, num_5g_reg_rules,
1125 					   min_bw_5g, mas_chan_list);
1126 		reg_populate_band_channels(MIN_49GHZ_CHANNEL,
1127 					   MAX_49GHZ_CHANNEL,
1128 					   reg_rule_5g, num_5g_reg_rules,
1129 					   min_bw_5g, mas_chan_list);
1130 		reg_populate_6g_band_channels(reg_rule_5g,
1131 					      num_5g_reg_rules,
1132 					      min_bw_5g,
1133 					      mas_chan_list);
1134 	}
1135 
1136 	soc_reg->chan_list_recvd[phy_id] = true;
1137 	status = reg_send_ctl_info(soc_reg, regulat_info, tx_ops);
1138 	if (!QDF_IS_STATUS_SUCCESS(status)) {
1139 		reg_err("Failed to send ctl info to fw");
1140 		return status;
1141 	}
1142 
1143 	if (soc_reg->new_user_ctry_pending[phy_id]) {
1144 		soc_reg->new_user_ctry_pending[phy_id] = false;
1145 		soc_reg->cc_src = SOURCE_USERSPACE;
1146 		soc_reg->user_ctry_set = true;
1147 		reg_debug("new user country is set");
1148 		reg_run_11d_state_machine(psoc);
1149 	} else if (soc_reg->new_init_ctry_pending[phy_id]) {
1150 		soc_reg->new_init_ctry_pending[phy_id] = false;
1151 		soc_reg->cc_src = SOURCE_USERSPACE;
1152 		reg_debug("new init country is set");
1153 	} else if (soc_reg->new_11d_ctry_pending[phy_id]) {
1154 		soc_reg->new_11d_ctry_pending[phy_id] = false;
1155 		soc_reg->cc_src = SOURCE_11D;
1156 		soc_reg->user_ctry_set = false;
1157 		reg_run_11d_state_machine(psoc);
1158 	} else if (soc_reg->world_country_pending[phy_id]) {
1159 		soc_reg->world_country_pending[phy_id] = false;
1160 		soc_reg->cc_src = SOURCE_CORE;
1161 		soc_reg->user_ctry_set = false;
1162 		reg_run_11d_state_machine(psoc);
1163 	} else {
1164 		if (soc_reg->cc_src == SOURCE_UNKNOWN &&
1165 		    soc_reg->num_phy == phy_id + 1)
1166 			soc_reg->cc_src = SOURCE_DRIVER;
1167 
1168 		qdf_mem_copy(soc_reg->mas_chan_params[phy_id].default_country,
1169 			     regulat_info->alpha2,
1170 			     REG_ALPHA2_LEN + 1);
1171 
1172 		soc_reg->mas_chan_params[phy_id].def_country_code =
1173 			regulat_info->ctry_code;
1174 		soc_reg->mas_chan_params[phy_id].def_region_domain =
1175 			regulat_info->reg_dmn_pair;
1176 
1177 		if (soc_reg->cc_src == SOURCE_DRIVER) {
1178 			qdf_mem_copy(soc_reg->def_country,
1179 				     regulat_info->alpha2,
1180 				     REG_ALPHA2_LEN + 1);
1181 
1182 			soc_reg->def_country_code = regulat_info->ctry_code;
1183 			soc_reg->def_region_domain =
1184 				regulat_info->reg_dmn_pair;
1185 
1186 			if (reg_is_world_alpha2(regulat_info->alpha2)) {
1187 				soc_reg->cc_src = SOURCE_CORE;
1188 				reg_run_11d_state_machine(psoc);
1189 			}
1190 		}
1191 	}
1192 
1193 	pdev = wlan_objmgr_get_pdev_by_id(psoc, phy_id, dbg_id);
1194 	if (pdev) {
1195 		reg_propagate_mas_chan_list_to_pdev(psoc, pdev, &dir);
1196 		wlan_objmgr_pdev_release_ref(pdev, dbg_id);
1197 	}
1198 
1199 	return QDF_STATUS_SUCCESS;
1200 }
1201 
1202 QDF_STATUS reg_get_current_chan_list(struct wlan_objmgr_pdev *pdev,
1203 				     struct regulatory_channel *chan_list)
1204 {
1205 	struct wlan_regulatory_pdev_priv_obj *pdev_priv_obj;
1206 
1207 	pdev_priv_obj = reg_get_pdev_obj(pdev);
1208 
1209 	if (!IS_VALID_PDEV_REG_OBJ(pdev_priv_obj)) {
1210 		reg_err("reg pdev private obj is NULL");
1211 		return QDF_STATUS_E_FAILURE;
1212 	}
1213 
1214 	qdf_mem_copy(chan_list, pdev_priv_obj->cur_chan_list,
1215 		     NUM_CHANNELS * sizeof(struct regulatory_channel));
1216 
1217 	return QDF_STATUS_SUCCESS;
1218 }
1219