xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs_random_chan_sel.h (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 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 #include <wlan_dfs_public_struct.h>
21 #include <reg_services_public_struct.h>
22 
23 /* Channel width definitions */
24 /* 20MHz channel width */
25 #define DFS_CH_WIDTH_20MHZ      0
26 
27 /* 40MHz channel width */
28 #define DFS_CH_WIDTH_40MHZ      1
29 
30 /* 80MHz channel width */
31 #define DFS_CH_WIDTH_80MHZ      2
32 
33 /* 160MHz channel width */
34 #define DFS_CH_WIDTH_160MHZ     3
35 
36 /* 80+80 non-contiguous */
37 #define DFS_CH_WIDTH_80P80MHZ   4
38 
39 /* 5MHz channel width */
40 #define DFS_CH_WIDTH_5MHZ       5
41 
42 /* 10MHz channel width */
43 #define DFS_CH_WIDTH_10MHZ      6
44 
45 #define DFS_CH_WIDTH_320MHZ     7
46 /* Invalid channel width */
47 #define DFS_CH_WIDTH_INVALID    8
48 
49 /* Max channel width */
50 #define DFS_CH_WIDTH_MAX        9
51 
52 /* Next 5GHz channel number */
53 #define DFS_80_NUM_SUB_CHANNEL                 4
54 
55 /* Next 5GHz channel freq offset */
56 #define DFS_80_NUM_SUB_CHANNEL_FREQ            20
57 
58 /* Next 5GHz channel number */
59 #define DFS_NEXT_5GHZ_CHANNEL                   4
60 
61 /* Next 5GHz channel number */
62 #define DFS_NEXT_5GHZ_CHANNEL_FREQ_OFFSET       20
63 
64 /* Number of 20MHz channels in bitmap */
65 #define DFS_MAX_NUM_160_SUBCHAN                 8
66 
67 #define DFS_MAX_NUM_240_SUBCHAN                 12
68 /* Frequency difference between 80+80 MHz */
69 #define DFS_80P80M_FREQ_DIFF                    40
70 
71 #ifdef CONFIG_BAND_6GHZ
72 /* Number of 80MHz channels in 5GHz and 6GHz band */
73 #define DFS_MAX_80MHZ_BANDS                     (7 + 14)
74 #else
75 /* Number of 80MHz channels in 5GHz band */
76 #define DFS_MAX_80MHZ_BANDS                     7
77 #endif
78 
79 /* Start channel and center channel diff in 80Mhz */
80 #define DFS_80MHZ_START_CENTER_CH_DIFF          6
81 
82 /* Start channel and center channel freq diff in 80Mhz */
83 #define DFS_80MHZ_START_CENTER_CH_FREQ_DIFF     30
84 
85 /* Bitmap mask for 80MHz */
86 #define DFS_80MHZ_MASK                          0x0F
87 
88 /* Bitmap mask for 40MHz lower */
89 #define DFS_40MHZ_MASK_L                        0x03
90 
91 /* Bitmap mask for 40MHz higher */
92 #define DFS_40MHZ_MASK_H                        0x0C
93 
94 /* Adjacent weather radar channel frequency */
95 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL      5580
96 
97 /* Adjacent weather radar channel number */
98 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_NUM  116
99 
100 /* Max 2.4 GHz channel number */
101 #define DFS_MAX_24GHZ_CHANNEL                   14
102 
103 /* Max 2.4 GHz channel frequency */
104 #define DFS_MAX_24GHZ_CHANNEL_FREQ              2484
105 
106 /* Adjacent weather radar channel frequency */
107 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_FREQ  5580
108 /* Max valid channel number */
109 #define MAX_CHANNEL_NUM                         184
110 
111 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
112 #define DFS_TX_LEAKAGE_THRES 310
113 #define DFS_TX_LEAKAGE_MAX  1000
114 #define DFS_TX_LEAKAGE_MIN  200
115 
116 /*
117  * This define is used to block additional channels
118  * based on the new data gathered on auto platforms
119  * and to differentiate the leakage data among different
120  * platforms.
121  */
122 
123 #define DFS_TX_LEAKAGE_AUTO_MIN  210
124 #endif
125 
126 #define DFS_IS_CHANNEL_WEATHER_RADAR(_f) (((_f) >= 5600) && ((_f) <= 5650))
127 
128 #ifdef CONFIG_CHAN_FREQ_API
129 #define DFS_IS_CHAN_JAPAN_INDOOR_FREQ(_ch)(((_ch) >= 5180)  && ((_ch) <= 5320))
130 #define DFS_IS_CHAN_JAPAN_OUTDOOR_FREQ(_ch)(((_ch) >= 5500) && ((_ch) <= 5720))
131 #define DFS_IS_CHAN_JAPAN_W53_FREQ(_ch)    (((_ch) >= 5260)  && ((_ch) <= 5320))
132 /*
133  * Spur or leakage transmissions is observed in Spruce HW in
134  * frequencies from 5260MHz to 5320MHz when one of the following
135  * conditions is true,
136  * i) The AP is transmitting in 52/56/60/64 in 80MHz mode and then the  AP
137  * moves to the adjacent channel 36/44/48 in 80MHz mode and starts
138  * transmitting.
139  * ii) The AP is transmitting in 36/44/48/52/56/60/64 in 160MHz mode and then
140  * the  AP moves to the adjacent channel 36/44/48 in 80MHz mode and starts
141  * transmitting.
142  * iii) The AP is transmitting in 52/56/60/64 in 20MHz or 40MHz mode and
143  * the AP moves to the adjacent channels 40/44/48 in 20MHz mode or
144  * 36/40/44/48 in 40MHz mode and starts transmitting.
145  * Hence, center frequencies from 5260MHz to 5320MHz in Spruce HW are called
146  * Spruce Spur 80MHz Frequencies and, center frequencies from 5180MHz and
147  * 5320MHz except 5200MHz are called Spruce Spur 160MHz Frequencies.
148  */
149 /* Channels 52/56/60/64 in 80MHz */
150 #define DFS_IS_CHAN_SPRUCE_SPUR_FREQ_80MHZ(_ch) \
151 		(((_ch) >= 5260) && ((_ch) <= 5320))
152 /* 36/44/48/52/56/60/64 in 160MHz mode */
153 #define DFS_IS_CHAN_SPRUCE_SPUR_FREQ_160MHZ(_ch) \
154 		(((_ch) >= 5180) && ((_ch) <= 5320) && ((_ch) != 5200))
155 /* Avoid channels 36/44/48 */
156 #define DFS_IS_SPRUCE_SPUR_AVOID_FREQS(_ch) \
157 		(((_ch) >= 5180) && ((_ch) <= 5240) && ((_ch) != 5200))
158 
159 /* Avoid channels 36/40/44/48 in HT40 mode and 40/44/48 in HT20 mode. */
160 #define DFS_IS_CHAN_SPRUCE_SPUR_FREQ_20_40_MHZ(_ch) \
161 		(((_ch) >= 5200) && ((_ch) <= 5240))
162 #endif
163 
164 /**
165  * struct chan_bonding_info - for holding channel bonding bitmap
166  * @chan_map: channel map
167  * @rsvd: reserved
168  * @start_chan: start channel
169  * @start_chan_freq: start channel frequency in MHZ.
170  */
171 struct chan_bonding_info {
172 	uint8_t chan_map:4;
173 	uint8_t rsvd:4;
174 	uint8_t start_chan;
175 	uint16_t start_chan_freq;
176 };
177 
178 /**
179  * struct chan_bonding_bitmap - bitmap structure which  represent
180  * all 5GHZ channels.
181  * @chan_bonding_set: channel bonding bitmap
182  */
183 struct chan_bonding_bitmap {
184 	struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS];
185 };
186 
187 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
188 /**
189  * struct dfs_tx_leak_info - DFS leakage info
190  * @leak_chan: leak channel.
191  * @leak_chan_freq: leak channel frequency.
192  * @leak_lvl: tx leakage lvl.
193  */
194 struct dfs_tx_leak_info {
195 	uint8_t leak_chan;
196 	uint16_t leak_chan_freq;
197 	uint32_t leak_lvl;
198 };
199 
200 /**
201  * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel.
202  * @channel: channel to switch from
203  * @channel_freq: channel frequency
204  * @chan_matrix: DFS leakage matrix info for given dfs channel.
205  */
206 struct dfs_matrix_tx_leak_info {
207 	uint8_t channel;
208 	uint16_t channel_freq;
209 	struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_5720 -
210 					    CHAN_ENUM_5180 + 1];
211 };
212 #endif
213 
214 /**
215  * dfs_mark_leaking_chan_for_freq() - to mark channel leaking in to nol
216  * @dfs: dfs handler.
217  * @ch_width: channel width
218  * @temp_chan_lst_sz: the target channel list size.
219  * @temp_freq_lst: the target frequency channel list
220  *
221  * This function removes the channels from temp channel list that
222  * (if selected as target channel) will cause leakage in one of
223  * the NOL channels
224  *
225  * Return: QDF_STATUS
226  */
227 #ifdef CONFIG_CHAN_FREQ_API
228 QDF_STATUS dfs_mark_leaking_chan_for_freq(struct wlan_dfs *dfs,
229 					enum phy_ch_width ch_width,
230 					uint8_t temp_chan_lst_sz,
231 					uint16_t *temp_freq_lst);
232 #endif
233 
234 /**
235  * dfs_prepare_random_channel_for_freq() - This function picks a random channel
236  * from the list of available channels.
237  * @dfs: dfs handler.
238  * @chan_list: channel list.
239  * @chan_cnt: Number of channels in given list.
240  * @flags: DFS_RANDOM_CH_FLAG_*
241  * @chan_params: channel parameters
242  * @dfs_region: DFS region.
243  * @acs_info: acs channel range information.
244  *
245  * Function used to find random channel selection from a given list.
246  * First this function removes channels  based on flags and then uses final
247  * list to find channel based on requested bandwidth, if requested bandwidth
248  * not available, it chooses next lower bandwidth and try.
249  *
250  * Return: channel frequency, else zero.
251  */
252 #ifdef CONFIG_CHAN_FREQ_API
253 uint16_t dfs_prepare_random_channel_for_freq(struct wlan_dfs *dfs,
254 					     struct dfs_channel *chan_list,
255 					     uint32_t chan_cnt,
256 					     uint32_t flags,
257 					     struct ch_params *chan_params,
258 					     uint8_t dfs_region,
259 					     struct dfs_acs_info *acs_info);
260 #endif
261