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_W53(_ch) (((_ch) >= 52) && ((_ch) <= 64)) 126 #define DFS_IS_CHAN_JAPAN_OUTDOOR(_ch) (((_ch) >= 100) && ((_ch) <= 140)) 127 128 /** 129 * struct chan_bonding_info - for holding channel bonding bitmap 130 * @chan_map: channel map 131 * @rsvd: reserved 132 * @start_chan: start channel 133 */ 134 struct chan_bonding_info { 135 uint8_t chan_map:4; 136 uint8_t rsvd:4; 137 uint8_t start_chan; 138 }; 139 140 /** 141 * struct chan_bonding_bitmap - bitmap structure which represent 142 * all 5GHZ channels. 143 * @chan_bonding_set: channel bonding bitmap 144 */ 145 struct chan_bonding_bitmap { 146 struct chan_bonding_info chan_bonding_set[DFS_MAX_80MHZ_BANDS]; 147 }; 148 149 #ifdef WLAN_ENABLE_CHNL_MATRIX_RESTRICTION 150 /** 151 * struct dfs_tx_leak_info - DFS leakage info 152 * @leak_chan: leak channel. 153 * @leak_lvl: tx leakage lvl. 154 */ 155 struct dfs_tx_leak_info { 156 uint8_t leak_chan; 157 uint32_t leak_lvl; 158 }; 159 160 /** 161 * struct dfs_matrix_tx_leak_info - DFS leakage matrix info for dfs channel. 162 * @channel: channel to switch from 163 * @chan_matrix DFS leakage matrix info for given dfs channel. 164 */ 165 struct dfs_matrix_tx_leak_info { 166 uint8_t channel; 167 struct dfs_tx_leak_info chan_matrix[CHAN_ENUM_144 - CHAN_ENUM_36 + 1]; 168 }; 169 #endif 170 171 /** 172 * dfs_mark_leaking_ch() - to mark channel leaking in to nol 173 * @dfs: dfs handler. 174 * @ch_width: channel width 175 * @temp_ch_lst_sz: the target channel list 176 * @temp_ch_lst: the target channel list 177 * 178 * This function removes the channels from temp channel list that 179 * (if selected as target channel) will cause leakage in one of 180 * the NOL channels 181 * 182 * Return: QDF_STATUS 183 */ 184 QDF_STATUS dfs_mark_leaking_ch(struct wlan_dfs *dfs, 185 enum phy_ch_width ch_width, 186 uint8_t temp_ch_lst_sz, 187 uint8_t *temp_ch_lst); 188 189 /** 190 * dfs_prepare_random_channel() - This function picks a random channel from 191 * the list of available channels. 192 * @dfs: dfs handler. 193 * @ch_list: channel list. 194 * @ch_count: Number of channels in given list. 195 * @flags: DFS_RANDOM_CH_FLAG_* 196 * @ch_wd: input channel width, used same variable to return new ch width. 197 * @cur_chan: current channel. 198 * @dfs_region: DFS region. 199 * @acs_info: acs channel range information. 200 * 201 * Function used to find random channel selection from a given list. 202 * First this function removes channels based on flags and then uses final 203 * list to find channel based on requested bandwidth, if requested bandwidth 204 * not available, it chooses next lower bandwidth and try. 205 * 206 * Return: channel number, else zero. 207 */ 208 uint8_t dfs_prepare_random_channel(struct wlan_dfs *dfs, 209 struct dfs_channel *ch_list, 210 uint32_t ch_count, 211 uint32_t flags, 212 uint8_t *ch_wd, 213 struct dfs_channel *cur_chan, 214 uint8_t dfs_region, 215 struct dfs_acs_info *acs_info); 216