1 /* 2 * Copyright (c) 2012-2018 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 number */ 73 #define DFS_NEXT_5GHZ_CHANNEL 4 74 75 /* Number of 20MHz channels in bitmap */ 76 #define DFS_MAX_20M_SUB_CH 8 77 78 /* Number of 80MHz channels in 5GHz band */ 79 #define DFS_MAX_80MHZ_BANDS 6 80 81 /* Start channel and center channel diff in 80Mhz */ 82 #define DFS_80MHZ_START_CENTER_CH_DIFF 6 83 84 /* Max number of channels */ 85 #define DFS_MAX_NUM_CHAN 128 86 87 /* Bitmap mask for 80MHz */ 88 #define DFS_80MHZ_MASK 0x0F 89 90 /* Bitmap mask for 40MHz lower */ 91 #define DFS_40MHZ_MASK_L 0x03 92 93 /* Bitmap mask for 40MHz higher */ 94 #define DFS_40MHZ_MASK_H 0x0C 95 96 /* Adjacent weather radar channel frequency */ 97 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL 5580 98 99 /* Adjacent weather radar channel number */ 100 #define DFS_ADJACENT_WEATHER_RADAR_CHANNEL_NUM 116 101 102 /* Max 2.4 GHz channel number */ 103 #define DFS_MAX_24GHZ_CHANNEL 14 104 105 /* Max valid channel number */ 106 #define MAX_CHANNEL_NUM 184 107 108 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 109 #define DFS_TX_LEAKAGE_THRES 310 110 #define DFS_TX_LEAKAGE_MAX 1000 111 #define DFS_TX_LEAKAGE_MIN 200 112 113 /* 114 * This define is used to block additional channels 115 * based on the new data gathered on auto platforms 116 * and to differentiate the leakage data among different 117 * platforms. 118 */ 119 120 #define DFS_TX_LEAKAGE_AUTO_MIN 210 121 #endif 122 123 #define DFS_IS_CHANNEL_WEATHER_RADAR(_f) (((_f) >= 5600) && ((_f) <= 5650)) 124 #define DFS_IS_CHAN_JAPAN_INDOOR(_ch) (((_ch) >= 36) && ((_ch) <= 64)) 125 #define DFS_IS_CHAN_JAPAN_OUTDOOR(_ch) (((_ch) >= 100) && ((_ch) <= 140)) 126 127 /** 128 * struct chan_bonding_info - for holding channel bonding bitmap 129 * @chan_map: channel map 130 * @rsvd: reserved 131 * @start_chan: start channel 132 */ 133 struct chan_bonding_info { 134 uint8_t chan_map:4; 135 uint8_t rsvd:4; 136 uint8_t start_chan; 137 }; 138 139 /** 140 * struct chan_bonding_bitmap - bitmap structure which represent 141 * all 5GHZ channels. 142 * @chan_bonding_set: channel bonding bitmap 143 */ 144 struct chan_bonding_bitmap { 145 struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS]; 146 }; 147 148 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 149 /** 150 * struct dfs_tx_leak_info - DFS leakage info 151 * @leak_chan: leak channel. 152 * @leak_lvl: tx leakage lvl. 153 */ 154 struct dfs_tx_leak_info { 155 uint8_t leak_chan; 156 uint32_t leak_lvl; 157 }; 158 159 /** 160 * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel. 161 * @channel: channel to switch from 162 * @chan_matrix DFS leakage matrix info for given dfs channel. 163 */ 164 struct dfs_matrix_tx_leak_info { 165 uint8_t channel; 166 struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_144 - CHAN_ENUM_36 + 1]; 167 }; 168 #endif 169 170 /** 171 * dfs_mark_leaking_ch() - to mark channel leaking in to nol 172 * @dfs: dfs handler. 173 * @ch_width: channel width 174 * @temp_ch_lst_sz: the target channel list 175 * @temp_ch_lst: the target channel list 176 * 177 * This function removes the channels from temp channel list that 178 * (if selected as target channel) will cause leakage in one of 179 * the NOL channels 180 * 181 * Return: QDF_STATUS 182 */ 183 QDF_STATUS dfs_mark_leaking_ch(struct wlan_dfs *dfs, 184 enum phy_ch_width ch_width, 185 uint8_t temp_ch_lst_sz, 186 uint8_t *temp_ch_lst); 187 188 /** 189 * dfs_prepare_random_channel() - This function picks a random channel from 190 * the list of available channels. 191 * @dfs: dfs handler. 192 * @ch_list: channel list. 193 * @ch_count: Number of channels in given list. 194 * @flags: DFS_RANDOM_CH_FLAG_* 195 * @ch_wd: input channel width, used same variable to return new ch width. 196 * @cur_chan: current channel. 197 * @dfs_region: DFS region. 198 * @acs_info: acs channel range information. 199 * 200 * Function used to find random channel selection from a given list. 201 * First this function removes channels based on flags and then uses final 202 * list to find channel based on requested bandwidth, if requested bandwidth 203 * not available, it chooses next lower bandwidth and try. 204 * 205 * Return: channel number, else zero. 206 */ 207 uint8_t dfs_prepare_random_channel(struct wlan_dfs *dfs, 208 struct dfs_channel *ch_list, 209 uint32_t ch_count, 210 uint32_t flags, 211 uint8_t *ch_wd, 212 struct dfs_channel *cur_chan, 213 uint8_t dfs_region, 214 struct dfs_acs_info *acs_info); 215