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