1 /* 2 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved. 3 * 4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc. 5 * 6 * 7 * Permission to use, copy, modify, and/or distribute this software for 8 * any purpose with or without fee is hereby granted, provided that the 9 * above copyright notice and this permission notice appear in all 10 * copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 19 * PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22 /* 23 * This file was originally distributed by Qualcomm Atheros, Inc. 24 * under proprietary terms before Copyright ownership was assigned 25 * to the Linux Foundation. 26 */ 27 28 /* dfs regions definitions */ 29 /* un-initialized region */ 30 #define DFS_UNINIT_REGION_VAL 0 31 32 /* FCC region */ 33 #define DFS_FCC_REGION_VAL 1 34 35 /* ETSI region */ 36 #define DFS_ETSI_REGION_VAL 2 37 38 /* MKK region */ 39 #define DFS_MKK_REGION_VAL 3 40 41 /* China region */ 42 #define DFS_CN_REGION_VAL 4 43 44 /* Korea region */ 45 #define DFS_KR_REGION_VAL 5 46 47 /* Undefined region */ 48 #define DFS_UNDEF_REGION_VAL 6 49 50 /* Channel width definitions */ 51 /* 20MHz channel width */ 52 #define DFS_CH_WIDTH_20MHZ 0 53 54 /* 40MHz channel width */ 55 #define DFS_CH_WIDTH_40MHZ 1 56 57 /* 80MHz channel width */ 58 #define DFS_CH_WIDTH_80MHZ 2 59 60 /* 160MHz channel width */ 61 #define DFS_CH_WIDTH_160MHZ 3 62 63 /* 80+80 non-contiguous */ 64 #define DFS_CH_WIDTH_80P80MHZ 4 65 66 /* 5MHz channel width */ 67 #define DFS_CH_WIDTH_5MHZ 5 68 69 /* 10MHz channel width */ 70 #define DFS_CH_WIDTH_10MHZ 6 71 72 /* Invalid channel width */ 73 #define DFS_CH_WIDTH_INVALID 7 74 75 /* Max channel width */ 76 #define DFS_CH_WIDTH_MAX 8 77 78 /* Next 5GHz channel number */ 79 #define DFS_80_NUM_SUB_CHANNNEL 4 80 81 /* Next 5GHz channel number */ 82 #define DFS_NEXT_5GHZ_CHANNEL 4 83 84 /* Number of 20MHz channels in bitmap */ 85 #define DFS_MAX_20M_SUB_CH 8 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 /* 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 valid channel number */ 115 #define MAX_CHANNEL_NUM 184 116 117 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 118 #define DFS_TX_LEAKAGE_THRES 310 119 #define DFS_TX_LEAKAGE_MAX 1000 120 #define DFS_TX_LEAKAGE_MIN 200 121 122 /* 123 * This define is used to block additional channels 124 * based on the new data gathered on auto platforms 125 * and to differentiate the leakage data among different 126 * platforms. 127 */ 128 129 #define DFS_TX_LEAKAGE_AUTO_MIN 210 130 #endif 131 132 #define DFS_IS_CHANNEL_WEATHER_RADAR(_f) (((_f) >= 5600) && ((_f) <= 5650)) 133 #define DFS_IS_CHAN_JAPAN_INDOOR(_ch) (((_ch) >= 36) && ((_ch) <= 64)) 134 #define DFS_IS_CHAN_JAPAN_OUTDOOR(_ch) (((_ch) >= 100) && ((_ch) <= 140)) 135 136 /** 137 * struct chan_bonding_info - for holding channel bonding bitmap 138 * @chan_map: channel map 139 * @rsvd: reserved 140 * @start_chan: start channel 141 */ 142 struct chan_bonding_info { 143 uint8_t chan_map:4; 144 uint8_t rsvd:4; 145 uint8_t start_chan; 146 }; 147 148 /** 149 * struct chan_bonding_bitmap - bitmap structure which represent 150 * all 5GHZ channels. 151 * @chan_bonding_set: channel bonding bitmap 152 */ 153 struct chan_bonding_bitmap { 154 struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS]; 155 }; 156 157 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 158 /** 159 * struct dfs_tx_leak_info - DFS leakage info 160 * @leak_chan: leak channel. 161 * @leak_lvl: tx leakage lvl. 162 */ 163 struct dfs_tx_leak_info { 164 uint8_t leak_chan; 165 uint32_t leak_lvl; 166 }; 167 168 /** 169 * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel. 170 * @channel: channel to switch from 171 * @chan_matrix DFS leakage matrix info for given dfs channel. 172 */ 173 struct dfs_matrix_tx_leak_info { 174 uint8_t channel; 175 struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_144 - CHAN_ENUM_36 + 1]; 176 }; 177 #endif 178 179 /** 180 * dfs_mark_leaking_ch() - to mark channel leaking in to nol 181 * @dfs: dfs handler. 182 * @ch_width: channel width 183 * @temp_ch_lst_sz: the target channel list 184 * @temp_ch_lst: the target channel list 185 * 186 * This function removes the channels from temp channel list that 187 * (if selected as target channel) will cause leakage in one of 188 * the NOL channels 189 * 190 * Return: QDF_STATUS 191 */ 192 QDF_STATUS dfs_mark_leaking_ch(struct wlan_dfs *dfs, 193 enum phy_ch_width ch_width, 194 uint8_t temp_ch_lst_sz, 195 uint8_t *temp_ch_lst); 196 197 /** 198 * dfs_prepare_random_channel() - This function picks a random channel from 199 * the list of available channels. 200 * @dfs: dfs handler. 201 * @ch_list: channel list. 202 * @ch_count: Number of channels in given list. 203 * @flags: DFS_RANDOM_CH_FLAG_* 204 * @ch_wd: input channel width, used same variable to return new ch width. 205 * @cur_chan: current channel. 206 * @dfs_region: DFS region. 207 * @acs_info: acs channel range information. 208 * 209 * Function used to find random channel selection from a given list. 210 * First this function removes channels based on flags and then uses final 211 * list to find channel based on requested bandwidth, if requested bandwidth 212 * not available, it chooses next lower bandwidth and try. 213 * 214 * Return: channel number, else zero. 215 */ 216 uint8_t dfs_prepare_random_channel(struct wlan_dfs *dfs, 217 struct dfs_channel *ch_list, 218 uint32_t ch_count, 219 uint32_t flags, 220 uint8_t *ch_wd, 221 struct dfs_channel *cur_chan, 222 uint8_t dfs_region, 223 struct dfs_acs_info *acs_info); 224