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 /* Frequency difference between 80+80 MHz */ 85 #define DFS_80P80M_FREQ_DIFF 40 86 87 /* Number of 80MHz channels in 5GHz band */ 88 #define DFS_MAX_80MHZ_BANDS 6 89 90 /* Start channel and center channel diff in 80Mhz */ 91 #define DFS_80MHZ_START_CENTER_CH_DIFF 6 92 93 /* Start channel and center channel freq diff in 80Mhz */ 94 #define DFS_80MHZ_START_CENTER_CH_FREQ_DIFF 30 95 96 /* Max number of channels */ 97 #define DFS_MAX_NUM_CHAN 128 98 99 /* Bitmap mask for 80MHz */ 100 #define DFS_80MHZ_MASK 0x0F 101 102 /* Bitmap mask for 40MHz lower */ 103 #define DFS_40MHZ_MASK_L 0x03 104 105 /* Bitmap mask for 40MHz higher */ 106 #define DFS_40MHZ_MASK_H 0x0C 107 108 /* Adjacent weather radar channel frequency */ 109 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL 5580 110 111 /* Adjacent weather radar channel number */ 112 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_NUM 116 113 114 /* Max 2.4 GHz channel number */ 115 #define DFS_MAX_24GHZ_CHANNEL 14 116 117 /* Max 2.4 GHz channel frequency */ 118 #define DFS_MAX_24GHZ_CHANNEL_FREQ 2484 119 120 /* Adjacent weather radar channel frequency */ 121 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_FREQ 5580 122 /* Max valid channel number */ 123 #define MAX_CHANNEL_NUM 184 124 125 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 126 #define DFS_TX_LEAKAGE_THRES 310 127 #define DFS_TX_LEAKAGE_MAX 1000 128 #define DFS_TX_LEAKAGE_MIN 200 129 130 /* 131 * This define is used to block additional channels 132 * based on the new data gathered on auto platforms 133 * and to differentiate the leakage data among different 134 * platforms. 135 */ 136 137 #define DFS_TX_LEAKAGE_AUTO_MIN 210 138 #endif 139 140 #define DFS_IS_CHANNEL_WEATHER_RADAR(_f) (((_f) >= 5600) && ((_f) <= 5650)) 141 #ifdef CONFIG_CHAN_NUM_API 142 #define DFS_IS_CHAN_JAPAN_INDOOR(_ch) (((_ch) >= 36) && ((_ch) <= 64)) 143 #define DFS_IS_CHAN_JAPAN_W53(_ch) (((_ch) >= 52) && ((_ch) <= 64)) 144 #define DFS_IS_CHAN_JAPAN_OUTDOOR(_ch) (((_ch) >= 100) && ((_ch) <= 140)) 145 #endif 146 147 #ifdef CONFIG_CHAN_FREQ_API 148 #define DFS_IS_CHAN_JAPAN_INDOOR_FREQ(_ch)(((_ch) >= 5180) && ((_ch) <= 5320)) 149 #define DFS_IS_CHAN_JAPAN_OUTDOOR_FREQ(_ch)(((_ch) >= 5500) && ((_ch) <= 5700)) 150 #define DFS_IS_CHAN_JAPAN_W53_FREQ(_ch) (((_ch) >= 5260) && ((_ch) <= 5320)) 151 #endif 152 153 /** 154 * struct chan_bonding_info - for holding channel bonding bitmap 155 * @chan_map: channel map 156 * @rsvd: reserved 157 * @start_chan: start channel 158 * @start_chan_freq: start channel frequency in MHZ. 159 */ 160 struct chan_bonding_info { 161 uint8_t chan_map:4; 162 uint8_t rsvd:4; 163 uint8_t start_chan; 164 uint16_t start_chan_freq; 165 }; 166 167 /** 168 * struct chan_bonding_bitmap - bitmap structure which represent 169 * all 5GHZ channels. 170 * @chan_bonding_set: channel bonding bitmap 171 */ 172 struct chan_bonding_bitmap { 173 struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS]; 174 }; 175 176 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 177 /** 178 * struct dfs_tx_leak_info - DFS leakage info 179 * @leak_chan: leak channel. 180 * @leak_lvl: tx leakage lvl. 181 */ 182 struct dfs_tx_leak_info { 183 uint8_t leak_chan; 184 uint16_t leak_chan_freq; 185 uint32_t leak_lvl; 186 }; 187 188 /** 189 * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel. 190 * @channel: channel to switch from 191 * @chan_matrix DFS leakage matrix info for given dfs channel. 192 */ 193 struct dfs_matrix_tx_leak_info { 194 uint8_t channel; 195 uint16_t channel_freq; 196 struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_5720 - 197 CHAN_ENUM_5180 + 1]; 198 }; 199 #endif 200 201 /** 202 * dfs_mark_leaking_ch() - to mark channel leaking in to nol 203 * @dfs: dfs handler. 204 * @ch_width: channel width 205 * @temp_ch_lst_sz: the target channel list 206 * @temp_ch_lst: the target channel list 207 * 208 * This function removes the channels from temp channel list that 209 * (if selected as target channel) will cause leakage in one of 210 * the NOL channels 211 * 212 * Return: QDF_STATUS 213 */ 214 #ifdef CONFIG_CHAN_NUM_API 215 QDF_STATUS dfs_mark_leaking_ch(struct wlan_dfs *dfs, 216 enum phy_ch_width ch_width, 217 uint8_t temp_ch_lst_sz, 218 uint8_t *temp_ch_lst); 219 #endif 220 221 /** 222 * dfs_mark_leaking_chan_for_freq() - to mark channel leaking in to nol 223 * @dfs: dfs handler. 224 * @ch_width: channel width 225 * @temp_chan_lst_sz: the target channel list size. 226 * @temp_freq_lst: the target frequency channel list 227 * 228 * This function removes the channels from temp channel list that 229 * (if selected as target channel) will cause leakage in one of 230 * the NOL channels 231 * 232 * Return: QDF_STATUS 233 */ 234 #ifdef CONFIG_CHAN_FREQ_API 235 QDF_STATUS dfs_mark_leaking_chan_for_freq(struct wlan_dfs *dfs, 236 enum phy_ch_width ch_width, 237 uint8_t temp_chan_lst_sz, 238 uint16_t *temp_freq_lst); 239 #endif 240 241 /** 242 * dfs_prepare_random_channel() - This function picks a random channel from 243 * the list of available channels. 244 * @dfs: dfs handler. 245 * @ch_list: channel list. 246 * @ch_count: Number of channels in given list. 247 * @flags: DFS_RANDOM_CH_FLAG_* 248 * @ch_wd: input channel width, used same variable to return new ch width. 249 * @cur_chan: current channel. 250 * @dfs_region: DFS region. 251 * @acs_info: acs channel range information. 252 * 253 * Function used to find random channel selection from a given list. 254 * First this function removes channels based on flags and then uses final 255 * list to find channel based on requested bandwidth, if requested bandwidth 256 * not available, it chooses next lower bandwidth and try. 257 * 258 * Return: channel number, else zero. 259 */ 260 #ifdef CONFIG_CHAN_NUM_API 261 uint8_t dfs_prepare_random_channel(struct wlan_dfs *dfs, 262 struct dfs_channel *ch_list, 263 uint32_t ch_count, 264 uint32_t flags, 265 uint8_t *ch_wd, 266 struct dfs_channel *cur_chan, 267 uint8_t dfs_region, 268 struct dfs_acs_info *acs_info); 269 #endif 270 271 /** 272 * dfs_prepare_random_channel() - This function picks a random channel from 273 * the list of available channels. 274 * @dfs: dfs handler. 275 * @chan_list: channel list. 276 * @ch_count: Number of channels in given list. 277 * @flags: DFS_RANDOM_CH_FLAG_* 278 * @chan_wd: input channel width, used same variable to return new ch width. 279 * @cur_chan: current channel. 280 * @dfs_region: DFS region. 281 * @acs_info: acs channel range information. 282 * 283 * Function used to find random channel selection from a given list. 284 * First this function removes channels based on flags and then uses final 285 * list to find channel based on requested bandwidth, if requested bandwidth 286 * not available, it chooses next lower bandwidth and try. 287 * 288 * Return: channel frequency, else zero. 289 */ 290 #ifdef CONFIG_CHAN_FREQ_API 291 uint16_t dfs_prepare_random_channel_for_freq(struct wlan_dfs *dfs, 292 struct dfs_channel *ch_list, 293 uint32_t chan_count, 294 uint32_t flags, 295 uint8_t *chan_wd, 296 struct dfs_channel *cur_chan, 297 uint8_t dfs_region, 298 struct dfs_acs_info *acs_info); 299 #endif 300