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