xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs_random_chan_sel.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2012-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 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_lvl: tx leakage lvl.
192  */
193 struct dfs_tx_leak_info {
194 	uint8_t leak_chan;
195 	uint16_t leak_chan_freq;
196 	uint32_t leak_lvl;
197 };
198 
199 /**
200  * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel.
201  * @channel: channel to switch from
202  * @chan_matrix DFS leakage matrix info for given dfs channel.
203  */
204 struct dfs_matrix_tx_leak_info {
205 	uint8_t channel;
206 	uint16_t channel_freq;
207 	struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_5720 -
208 					    CHAN_ENUM_5180 + 1];
209 };
210 #endif
211 
212 /**
213  * dfs_mark_leaking_chan_for_freq() - to mark channel leaking in to nol
214  * @dfs: dfs handler.
215  * @ch_width: channel width
216  * @temp_chan_lst_sz: the target channel list size.
217  * @temp_freq_lst: the target frequency channel list
218  *
219  * This function removes the channels from temp channel list that
220  * (if selected as target channel) will cause leakage in one of
221  * the NOL channels
222  *
223  * Return: QDF_STATUS
224  */
225 #ifdef CONFIG_CHAN_FREQ_API
226 QDF_STATUS dfs_mark_leaking_chan_for_freq(struct wlan_dfs *dfs,
227 					enum phy_ch_width ch_width,
228 					uint8_t temp_chan_lst_sz,
229 					uint16_t *temp_freq_lst);
230 #endif
231 
232 /**
233  * dfs_prepare_random_channel_for_freq() - This function picks a random channel
234  * from the list of available channels.
235  * @dfs: dfs handler.
236  * @chan_list: channel list.
237  * @ch_count: Number of channels in given list.
238  * @flags: DFS_RANDOM_CH_FLAG_*
239  * @chan_wd: input channel width, used same variable to return new ch width.
240  * @cur_chan: current channel.
241  * @dfs_region: DFS region.
242  * @acs_info: acs channel range information.
243  *
244  * Function used to find random channel selection from a given list.
245  * First this function removes channels  based on flags and then uses final
246  * list to find channel based on requested bandwidth, if requested bandwidth
247  * not available, it chooses next lower bandwidth and try.
248  *
249  * Return: channel frequency, else zero.
250  */
251 #ifdef CONFIG_CHAN_FREQ_API
252 uint16_t dfs_prepare_random_channel_for_freq(struct wlan_dfs *dfs,
253 					     struct dfs_channel *ch_list,
254 					     uint32_t chan_count,
255 					     uint32_t flags,
256 					     struct ch_params *chan_params,
257 					     uint8_t dfs_region,
258 					     struct dfs_acs_info *acs_info);
259 #endif
260