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