xref: /wlan-dirver/qca-wifi-host-cmn/umac/dfs/core/src/dfs_random_chan_sel.h (revision 11f5a63a6cbdda84849a730de22f0a71e635d58c)
1 /*
2  * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* dfs regions definitions */
20 /* un-initialized region */
21 #define DFS_UNINIT_REGION_VAL   0
22 
23 /* FCC region */
24 #define DFS_FCC_REGION_VAL      1
25 
26 /* ETSI region */
27 #define DFS_ETSI_REGION_VAL     2
28 
29 /* MKK region */
30 #define DFS_MKK_REGION_VAL      3
31 
32 /* China region */
33 #define DFS_CN_REGION_VAL       4
34 
35 /* Korea region */
36 #define DFS_KR_REGION_VAL       5
37 
38 /* Undefined region */
39 #define DFS_UNDEF_REGION_VAL    6
40 
41 /* Channel width definitions */
42 /* 20MHz channel width */
43 #define DFS_CH_WIDTH_20MHZ      0
44 
45 /* 40MHz channel width */
46 #define DFS_CH_WIDTH_40MHZ      1
47 
48 /* 80MHz channel width */
49 #define DFS_CH_WIDTH_80MHZ      2
50 
51 /* 160MHz channel width */
52 #define DFS_CH_WIDTH_160MHZ     3
53 
54 /* 80+80 non-contiguous */
55 #define DFS_CH_WIDTH_80P80MHZ   4
56 
57 /* 5MHz channel width */
58 #define DFS_CH_WIDTH_5MHZ       5
59 
60 /* 10MHz channel width */
61 #define DFS_CH_WIDTH_10MHZ      6
62 
63 /* Invalid channel width */
64 #define DFS_CH_WIDTH_INVALID    7
65 
66 /* Max channel width */
67 #define DFS_CH_WIDTH_MAX        8
68 
69 /* Next 5GHz channel number */
70 #define DFS_80_NUM_SUB_CHANNEL                 4
71 
72 /* Next 5GHz channel freq offset */
73 #define DFS_80_NUM_SUB_CHANNEL_FREQ            20
74 
75 /* Next 5GHz channel number */
76 #define DFS_NEXT_5GHZ_CHANNEL                   4
77 
78 /* Next 5GHz channel number */
79 #define DFS_NEXT_5GHZ_CHANNEL_FREQ_OFFSET       20
80 
81 /* Number of 20MHz channels in bitmap */
82 #define DFS_MAX_20M_SUB_CH                      8
83 
84 /* Number of 80MHz channels in 5GHz band */
85 #define DFS_MAX_80MHZ_BANDS                     6
86 
87 /* Start channel and center channel diff in 80Mhz */
88 #define DFS_80MHZ_START_CENTER_CH_DIFF          6
89 
90 /* Start channel and center channel freq diff in 80Mhz */
91 #define DFS_80MHZ_START_CENTER_CH_FREQ_DIFF     30
92 
93 /* Max number of channels */
94 #define DFS_MAX_NUM_CHAN                        128
95 
96 /* Bitmap mask for 80MHz */
97 #define DFS_80MHZ_MASK                          0x0F
98 
99 /* Bitmap mask for 40MHz lower */
100 #define DFS_40MHZ_MASK_L                        0x03
101 
102 /* Bitmap mask for 40MHz higher */
103 #define DFS_40MHZ_MASK_H                        0x0C
104 
105 /* Adjacent weather radar channel frequency */
106 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL      5580
107 
108 /* Adjacent weather radar channel number */
109 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_NUM  116
110 
111 /* Max 2.4 GHz channel number */
112 #define DFS_MAX_24GHZ_CHANNEL                   14
113 
114 /* Max 2.4 GHz channel frequency */
115 #define DFS_MAX_24GHZ_CHANNEL_FREQ              2484
116 
117 /* Adjacent weather radar channel frequency */
118 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_FREQ  5580
119 /* Max valid channel number */
120 #define MAX_CHANNEL_NUM                         184
121 
122 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
123 #define DFS_TX_LEAKAGE_THRES 310
124 #define DFS_TX_LEAKAGE_MAX  1000
125 #define DFS_TX_LEAKAGE_MIN  200
126 
127 /*
128  * This define is used to block additional channels
129  * based on the new data gathered on auto platforms
130  * and to differentiate the leakage data among different
131  * platforms.
132  */
133 
134 #define DFS_TX_LEAKAGE_AUTO_MIN  210
135 #endif
136 
137 #define DFS_IS_CHANNEL_WEATHER_RADAR(_f) (((_f) >= 5600) && ((_f) <= 5650))
138 #ifdef CONFIG_CHAN_NUM_API
139 #define DFS_IS_CHAN_JAPAN_INDOOR(_ch)    (((_ch) >= 36)  && ((_ch) <= 64))
140 #define DFS_IS_CHAN_JAPAN_W53(_ch)       (((_ch) >= 52)  && ((_ch) <= 64))
141 #define DFS_IS_CHAN_JAPAN_OUTDOOR(_ch)   (((_ch) >= 100) && ((_ch) <= 140))
142 #endif
143 
144 #ifdef CONFIG_CHAN_FREQ_API
145 #define DFS_IS_CHAN_JAPAN_INDOOR_FREQ(_ch)(((_ch) >= 5180)  && ((_ch) <= 5320))
146 #define DFS_IS_CHAN_JAPAN_OUTDOOR_FREQ(_ch)(((_ch) >= 5500) && ((_ch) <= 5700))
147 #define DFS_IS_CHAN_JAPAN_W53_FREQ(_ch)    (((_ch) >= 5260)  && ((_ch) <= 5320))
148 #endif
149 
150 /**
151  * struct chan_bonding_info - for holding channel bonding bitmap
152  * @chan_map: channel map
153  * @rsvd: reserved
154  * @start_chan: start channel
155  * @start_chan_freq: start channel frequency in MHZ.
156  */
157 struct chan_bonding_info {
158 	uint8_t chan_map:4;
159 	uint8_t rsvd:4;
160 	uint8_t start_chan;
161 	uint16_t start_chan_freq;
162 };
163 
164 /**
165  * struct chan_bonding_bitmap - bitmap structure which  represent
166  * all 5GHZ channels.
167  * @chan_bonding_set: channel bonding bitmap
168  */
169 struct chan_bonding_bitmap {
170 	struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS];
171 };
172 
173 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION
174 /**
175  * struct dfs_tx_leak_info - DFS leakage info
176  * @leak_chan: leak channel.
177  * @leak_lvl: tx leakage lvl.
178  */
179 struct dfs_tx_leak_info {
180 	uint8_t leak_chan;
181 	uint16_t leak_chan_freq;
182 	uint32_t leak_lvl;
183 };
184 
185 /**
186  * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel.
187  * @channel: channel to switch from
188  * @chan_matrix DFS leakage matrix info for given dfs channel.
189  */
190 struct dfs_matrix_tx_leak_info {
191 	uint8_t channel;
192 	uint16_t channel_freq;
193 	struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_5720 -
194 					    CHAN_ENUM_5180 + 1];
195 };
196 #endif
197 
198 /**
199  * dfs_mark_leaking_ch() - to mark channel leaking in to nol
200  * @dfs: dfs handler.
201  * @ch_width: channel width
202  * @temp_ch_lst_sz: the target channel list
203  * @temp_ch_lst: the target channel list
204  *
205  * This function removes the channels from temp channel list that
206  * (if selected as target channel) will cause leakage in one of
207  * the NOL channels
208  *
209  * Return: QDF_STATUS
210  */
211 #ifdef CONFIG_CHAN_NUM_API
212 QDF_STATUS dfs_mark_leaking_ch(struct wlan_dfs *dfs,
213 		enum phy_ch_width ch_width,
214 		uint8_t temp_ch_lst_sz,
215 		uint8_t *temp_ch_lst);
216 #endif
217 
218 /**
219  * dfs_mark_leaking_chan_for_freq() - to mark channel leaking in to nol
220  * @dfs: dfs handler.
221  * @ch_width: channel width
222  * @temp_chan_lst_sz: the target channel list size.
223  * @temp_freq_lst: the target frequency channel list
224  *
225  * This function removes the channels from temp channel list that
226  * (if selected as target channel) will cause leakage in one of
227  * the NOL channels
228  *
229  * Return: QDF_STATUS
230  */
231 #ifdef CONFIG_CHAN_FREQ_API
232 QDF_STATUS dfs_mark_leaking_chan_for_freq(struct wlan_dfs *dfs,
233 					enum phy_ch_width ch_width,
234 					uint8_t temp_chan_lst_sz,
235 					uint16_t *temp_freq_lst);
236 #endif
237 
238 /**
239  * dfs_prepare_random_channel() - This function picks a random channel from
240  * the list of available channels.
241  * @dfs: dfs handler.
242  * @ch_list: channel list.
243  * @ch_count: Number of channels in given list.
244  * @flags: DFS_RANDOM_CH_FLAG_*
245  * @ch_wd: input channel width, used same variable to return new ch width.
246  * @cur_chan: current channel.
247  * @dfs_region: DFS region.
248  * @acs_info: acs channel range information.
249  *
250  * Function used to find random channel selection from a given list.
251  * First this function removes channels  based on flags and then uses final
252  * list to find channel based on requested bandwidth, if requested bandwidth
253  * not available, it chooses next lower bandwidth and try.
254  *
255  * Return: channel number, else zero.
256  */
257 #ifdef CONFIG_CHAN_NUM_API
258 uint8_t dfs_prepare_random_channel(struct wlan_dfs *dfs,
259 	struct dfs_channel *ch_list,
260 	uint32_t ch_count,
261 	uint32_t flags,
262 	uint8_t *ch_wd,
263 	struct dfs_channel *cur_chan,
264 	uint8_t dfs_region,
265 	struct dfs_acs_info *acs_info);
266 #endif
267 
268 /**
269  * dfs_prepare_random_channel() - This function picks a random channel from
270  * the list of available channels.
271  * @dfs: dfs handler.
272  * @chan_list: channel list.
273  * @ch_count: Number of channels in given list.
274  * @flags: DFS_RANDOM_CH_FLAG_*
275  * @chan_wd: input channel width, used same variable to return new ch width.
276  * @cur_chan: current channel.
277  * @dfs_region: DFS region.
278  * @acs_info: acs channel range information.
279  *
280  * Function used to find random channel selection from a given list.
281  * First this function removes channels  based on flags and then uses final
282  * list to find channel based on requested bandwidth, if requested bandwidth
283  * not available, it chooses next lower bandwidth and try.
284  *
285  * Return: channel frequency, else zero.
286  */
287 #ifdef CONFIG_CHAN_FREQ_API
288 uint16_t dfs_prepare_random_channel_for_freq(struct wlan_dfs *dfs,
289 					     struct dfs_channel *ch_list,
290 					     uint32_t chan_count,
291 					     uint32_t flags,
292 					     uint8_t *chan_wd,
293 					     struct dfs_channel *cur_chan,
294 					     uint8_t dfs_region,
295 					     struct dfs_acs_info *acs_info);
296 #endif
297