1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Misc utility routines for WL and Apps 4 * This header file housing the define and function prototype use by 5 * both the wl driver, tools & Apps. 6 * 7 * Copyright (C) 1999-2019, Broadcom. 8 * 9 * Unless you and Broadcom execute a separate written software license 10 * agreement governing use of this software, this software is licensed to you 11 * under the terms of the GNU General Public License version 2 (the "GPL"), 12 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 13 * following added to such license: 14 * 15 * As a special exception, the copyright holders of this software give you 16 * permission to link this software with independent modules, and to copy and 17 * distribute the resulting executable under terms of your choice, provided that 18 * you also meet, for each linked independent module, the terms and conditions of 19 * the license of that module. An independent module is a module which is not 20 * derived from this software. The special exception does not apply to any 21 * modifications of the software. 22 * 23 * Notwithstanding the above, under no circumstances may you combine this 24 * software in any way with any other Broadcom software provided under a license 25 * other than the GPL, without Broadcom's express prior written consent. 26 * 27 * 28 * <<Broadcom-WL-IPTag/Open:>> 29 * 30 * $Id: bcmwifi_channels.h 806092 2019-02-21 08:19:13Z $ 31 */ 32 33 #ifndef _bcmwifi_channels_h_ 34 #define _bcmwifi_channels_h_ 35 36 /* A chanspec holds the channel number, band, bandwidth and primary 20MHz sideband */ 37 typedef uint16 chanspec_t; 38 typedef uint16 chanspec_band_t; 39 typedef uint16 chanspec_bw_t; 40 typedef uint16 chanspec_subband_t; 41 42 /* channel defines */ 43 #define CH_80MHZ_APART 16 44 #define CH_40MHZ_APART 8 45 #define CH_20MHZ_APART 4 46 #define CH_10MHZ_APART 2 47 #define CH_5MHZ_APART 1 /* 2G band channels are 5 Mhz apart */ 48 49 #define CH_MIN_2G_CHANNEL 1u /* Min channel in 2G band */ 50 #define CH_MAX_2G_CHANNEL 14u /* Max channel in 2G band */ 51 #define CH_MIN_2G_40M_CHANNEL 3u /* Min 40MHz center channel in 2G band */ 52 #define CH_MAX_2G_40M_CHANNEL 11u /* Max 40MHz center channel in 2G band */ 53 54 /* maximum # channels the s/w supports */ 55 #define MAXCHANNEL 224 /* max # supported channels. The max channel no is above, 56 * this is that + 1 rounded up to a multiple of NBBY (8). 57 * DO NOT MAKE it > 255: channels are uint8's all over 58 */ 59 #define MAXCHANNEL_NUM (MAXCHANNEL - 1) /* max channel number */ 60 61 #define INVCHANNEL 255 /* error value for a bad channel */ 62 63 /* channel bitvec */ 64 typedef struct { 65 uint8 vec[MAXCHANNEL/8]; /* bitvec of channels */ 66 } chanvec_t; 67 68 /* make sure channel num is within valid range */ 69 #define CH_NUM_VALID_RANGE(ch_num) ((ch_num) > 0 && (ch_num) <= MAXCHANNEL_NUM) 70 71 #define CHSPEC_CTLOVLP(sp1, sp2, sep) \ 72 (ABS(wf_chspec_ctlchan(sp1) - wf_chspec_ctlchan(sp2)) < (sep)) 73 74 /* All builds use the new 11ac ratespec/chanspec */ 75 #undef D11AC_IOTYPES 76 #define D11AC_IOTYPES 77 78 #define WL_CHANSPEC_CHAN_MASK 0x00ff 79 #define WL_CHANSPEC_CHAN_SHIFT 0 80 #define WL_CHANSPEC_CHAN1_MASK 0x000f 81 #define WL_CHANSPEC_CHAN1_SHIFT 0 82 #define WL_CHANSPEC_CHAN2_MASK 0x00f0 83 #define WL_CHANSPEC_CHAN2_SHIFT 4 84 85 #define WL_CHANSPEC_CTL_SB_MASK 0x0700 86 #define WL_CHANSPEC_CTL_SB_SHIFT 8 87 #define WL_CHANSPEC_CTL_SB_LLL 0x0000 88 #define WL_CHANSPEC_CTL_SB_LLU 0x0100 89 #define WL_CHANSPEC_CTL_SB_LUL 0x0200 90 #define WL_CHANSPEC_CTL_SB_LUU 0x0300 91 #define WL_CHANSPEC_CTL_SB_ULL 0x0400 92 #define WL_CHANSPEC_CTL_SB_ULU 0x0500 93 #define WL_CHANSPEC_CTL_SB_UUL 0x0600 94 #define WL_CHANSPEC_CTL_SB_UUU 0x0700 95 #define WL_CHANSPEC_CTL_SB_LL WL_CHANSPEC_CTL_SB_LLL 96 #define WL_CHANSPEC_CTL_SB_LU WL_CHANSPEC_CTL_SB_LLU 97 #define WL_CHANSPEC_CTL_SB_UL WL_CHANSPEC_CTL_SB_LUL 98 #define WL_CHANSPEC_CTL_SB_UU WL_CHANSPEC_CTL_SB_LUU 99 #define WL_CHANSPEC_CTL_SB_L WL_CHANSPEC_CTL_SB_LLL 100 #define WL_CHANSPEC_CTL_SB_U WL_CHANSPEC_CTL_SB_LLU 101 #define WL_CHANSPEC_CTL_SB_LOWER WL_CHANSPEC_CTL_SB_LLL 102 #define WL_CHANSPEC_CTL_SB_UPPER WL_CHANSPEC_CTL_SB_LLU 103 #define WL_CHANSPEC_CTL_SB_NONE WL_CHANSPEC_CTL_SB_LLL 104 105 #define WL_CHANSPEC_BW_MASK 0x3800u 106 #define WL_CHANSPEC_BW_SHIFT 11u 107 #define WL_CHANSPEC_BW_5 0x0000u 108 #define WL_CHANSPEC_BW_10 0x0800u 109 #define WL_CHANSPEC_BW_20 0x1000u 110 #define WL_CHANSPEC_BW_40 0x1800u 111 #define WL_CHANSPEC_BW_80 0x2000u 112 #define WL_CHANSPEC_BW_160 0x2800u 113 #define WL_CHANSPEC_BW_8080 0x3000u 114 115 #define WL_CHANSPEC_BAND_MASK 0xc000u 116 #define WL_CHANSPEC_BAND_SHIFT 14u 117 #define WL_CHANSPEC_BAND_2G 0x0000u 118 #define WL_CHANSPEC_BAND_3G 0x4000u 119 #define WL_CHANSPEC_BAND_4G 0x8000u 120 #define WL_CHANSPEC_BAND_5G 0xc000u 121 #define INVCHANSPEC 255u 122 #define MAX_CHANSPEC 0xFFFFu 123 124 #define WL_CHANNEL_BAND(ch) (((ch) <= CH_MAX_2G_CHANNEL) ? \ 125 WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G) 126 127 /* channel defines */ 128 #define LOWER_20_SB(channel) (((channel) > CH_10MHZ_APART) ? \ 129 ((channel) - CH_10MHZ_APART) : 0) 130 #define UPPER_20_SB(channel) (((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \ 131 ((channel) + CH_10MHZ_APART) : 0) 132 133 /* pass a 80MHz channel number (uint8) to get respective LL, UU, LU, UL */ 134 #define LL_20_SB(channel) (((channel) > 3 * CH_10MHZ_APART) ? ((channel) - 3 * CH_10MHZ_APART) : 0) 135 #define UU_20_SB(channel) (((channel) < (MAXCHANNEL - 3 * CH_10MHZ_APART)) ? \ 136 ((channel) + 3 * CH_10MHZ_APART) : 0) 137 #define LU_20_SB(channel) LOWER_20_SB(channel) 138 #define UL_20_SB(channel) UPPER_20_SB(channel) 139 140 #define LOWER_40_SB(channel) ((channel) - CH_20MHZ_APART) 141 #define UPPER_40_SB(channel) ((channel) + CH_20MHZ_APART) 142 #define CHSPEC_WLCBANDUNIT(chspec) (CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX) 143 #define CH20MHZ_CHSPEC(channel) (chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \ 144 (((channel) <= CH_MAX_2G_CHANNEL) ? \ 145 WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G)) 146 #define NEXT_20MHZ_CHAN(channel) (((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \ 147 ((channel) + CH_20MHZ_APART) : 0) 148 #define CH40MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \ 149 ((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \ 150 ((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \ 151 WL_CHANSPEC_BAND_5G)) 152 #define CH80MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \ 153 ((channel) | (ctlsb) | \ 154 WL_CHANSPEC_BW_80 | WL_CHANSPEC_BAND_5G) 155 #define CH160MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \ 156 ((channel) | (ctlsb) | \ 157 WL_CHANSPEC_BW_160 | WL_CHANSPEC_BAND_5G) 158 159 /* simple MACROs to get different fields of chanspec */ 160 #ifdef WL11AC_80P80 161 #define CHSPEC_CHANNEL(chspec) wf_chspec_channel(chspec) 162 #else 163 #define CHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK)) 164 #endif // endif 165 #define CHSPEC_CHAN1(chspec) ((chspec) & WL_CHANSPEC_CHAN1_MASK) >> WL_CHANSPEC_CHAN1_SHIFT 166 #define CHSPEC_CHAN2(chspec) ((chspec) & WL_CHANSPEC_CHAN2_MASK) >> WL_CHANSPEC_CHAN2_SHIFT 167 #define CHSPEC_BAND(chspec) ((chspec) & WL_CHANSPEC_BAND_MASK) 168 #define CHSPEC_CTL_SB(chspec) ((chspec) & WL_CHANSPEC_CTL_SB_MASK) 169 #define CHSPEC_BW(chspec) ((chspec) & WL_CHANSPEC_BW_MASK) 170 171 #ifdef WL11N_20MHZONLY 172 #define CHSPEC_IS20(chspec) 1 173 #define CHSPEC_IS20_2G(chspec) ((((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20) && \ 174 CHSPEC_IS2G(chspec)) 175 #ifndef CHSPEC_IS40 176 #define CHSPEC_IS40(chspec) 0 177 #endif // endif 178 #ifndef CHSPEC_IS80 179 #define CHSPEC_IS80(chspec) 0 180 #endif // endif 181 #ifndef CHSPEC_IS160 182 #define CHSPEC_IS160(chspec) 0 183 #endif // endif 184 #ifndef CHSPEC_IS8080 185 #define CHSPEC_IS8080(chspec) 0 186 #endif // endif 187 188 /* see FOREACH_20_SB in !WL11N_20MHZONLY section */ 189 #define FOREACH_20_SB(chspec, channel) \ 190 for (channel = CHSPEC_CHANNEL(chspec); channel; channel = 0) 191 192 /* see GET_ALL_SB in !WL11N_20MHZONLY section */ 193 #define GET_ALL_SB(chspec, psb) do { \ 194 psb[0] = CHSPEC_CHANNEL(chspec); \ 195 } while (0) 196 197 #else /* !WL11N_20MHZONLY */ 198 199 #define CHSPEC_IS20(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20) 200 #define CHSPEC_IS20_5G(chspec) ((((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20) && \ 201 CHSPEC_IS5G(chspec)) 202 #ifndef CHSPEC_IS40 203 #define CHSPEC_IS40(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40) 204 #endif // endif 205 #ifndef CHSPEC_IS80 206 #define CHSPEC_IS80(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_80) 207 #endif // endif 208 #ifndef CHSPEC_IS160 209 #define CHSPEC_IS160(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_160) 210 #endif // endif 211 #ifndef CHSPEC_IS8080 212 #define CHSPEC_IS8080(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_8080) 213 #endif // endif 214 215 /* pass a center channel and get channel offset from it by 10MHz */ 216 #define CH_OFF_10MHZ_MULTIPLES(channel, offset) ((uint8) (((offset) < 0) ? \ 217 (((channel) > (WL_CHANSPEC_CHAN_MASK & ((uint16)((-(offset)) * CH_10MHZ_APART)))) ?\ 218 ((channel) + (offset) * CH_10MHZ_APART) : 0) : \ 219 (((channel) < (uint16)(MAXCHANNEL - (offset) * CH_10MHZ_APART)) ? \ 220 ((channel) + (offset) * CH_10MHZ_APART) : 0))) 221 222 #if defined(WL11AC_80P80) || defined(WL11AC_160) 223 /* pass a 160MHz center channel to get 20MHz subband channel numbers */ 224 #define LLL_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, -7) 225 #define LLU_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, -5) 226 #define LUL_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, -3) 227 #define LUU_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, -1) 228 #define ULL_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, 1) 229 #define ULU_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, 3) 230 #define UUL_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, 5) 231 #define UUU_20_SB_160(channel) CH_OFF_10MHZ_MULTIPLES(channel, 7) 232 233 /* given an 80p80 channel, return the lower 80MHz sideband */ 234 #define LOWER_80_SB(chspec) (wf_chspec_primary80_channel(chspec) < \ 235 wf_chspec_secondary80_channel(chspec) ? \ 236 wf_chspec_primary80_channel(chspec) : wf_chspec_secondary80_channel(chspec)) 237 238 /* given an 80p80 channel, return the upper 80MHz sideband */ 239 #define UPPER_80_SB(chspec) (wf_chspec_primary80_channel(chspec) > \ 240 wf_chspec_secondary80_channel(chspec) ? \ 241 wf_chspec_primary80_channel(chspec) : wf_chspec_secondary80_channel(chspec)) 242 243 /* pass an 80P80 chanspec (not channel) to get 20MHz subnand channel numbers */ 244 #define LLL_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(LOWER_80_SB(chspec), -3) 245 #define LLU_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(LOWER_80_SB(chspec), -1) 246 #define LUL_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(LOWER_80_SB(chspec), 1) 247 #define LUU_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(LOWER_80_SB(chspec), 3) 248 #define ULL_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(UPPER_80_SB(chspec), -3) 249 #define ULU_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(UPPER_80_SB(chspec), -1) 250 #define UUL_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(UPPER_80_SB(chspec), 1) 251 #define UUU_20_SB_8080(chspec) CH_OFF_10MHZ_MULTIPLES(UPPER_80_SB(chspec), 3) 252 253 /* get lowest 20MHz sideband of a given chspec 254 * (works with 20, 40, 80, 160, 80p80) 255 */ 256 #define CH_FIRST_20_SB(chspec) ((uint8) (\ 257 CHSPEC_IS160(chspec) ? LLL_20_SB_160(CHSPEC_CHANNEL(chspec)) : (\ 258 CHSPEC_IS8080(chspec) ? LLL_20_SB_8080(chspec) : (\ 259 CHSPEC_IS80(chspec) ? LL_20_SB(CHSPEC_CHANNEL(chspec)) : (\ 260 CHSPEC_IS40(chspec) ? LOWER_20_SB(CHSPEC_CHANNEL(chspec)) : \ 261 CHSPEC_CHANNEL(chspec)))))) 262 263 /* get upper most 20MHz sideband of a given chspec 264 * (works with 20, 40, 80, 160, 80p80) 265 */ 266 #define CH_LAST_20_SB(chspec) ((uint8) (\ 267 CHSPEC_IS160(chspec) ? UUU_20_SB_160(CHSPEC_CHANNEL(chspec)) : (\ 268 CHSPEC_IS8080(chspec) ? UUU_20_SB_8080(chspec) : (\ 269 CHSPEC_IS80(chspec) ? UU_20_SB(CHSPEC_CHANNEL(chspec)) : (\ 270 CHSPEC_IS40(chspec) ? UPPER_20_SB(CHSPEC_CHANNEL(chspec)) : \ 271 CHSPEC_CHANNEL(chspec)))))) 272 273 /* call this with chspec and a valid 20MHz sideband of this channel to get the next 20MHz sideband 274 * (works with 80p80 only) 275 * resolves to 0 if called with upper most channel 276 */ 277 #define CH_NEXT_20_SB_IN_8080(chspec, channel) ((uint8) (\ 278 ((uint8) ((channel) + CH_20MHZ_APART) > CH_LAST_20_SB(chspec) ? 0 : \ 279 ((channel) == LUU_20_SB_8080(chspec) ? ULL_20_SB_8080(chspec) : \ 280 (channel) + CH_20MHZ_APART)))) 281 282 /* call this with chspec and a valid 20MHz sideband of this channel to get the next 20MHz sideband 283 * (works with 20, 40, 80, 160, 80p80) 284 * resolves to 0 if called with upper most channel 285 */ 286 #define CH_NEXT_20_SB(chspec, channel) ((uint8) (\ 287 (CHSPEC_IS8080(chspec) ? CH_NEXT_20_SB_IN_8080((chspec), (channel)) : \ 288 ((uint8) ((channel) + CH_20MHZ_APART) > CH_LAST_20_SB(chspec) ? 0 : \ 289 ((channel) + CH_20MHZ_APART))))) 290 291 #else /* WL11AC_80P80, WL11AC_160 */ 292 293 #define LLL_20_SB_160(channel) 0 294 #define LLU_20_SB_160(channel) 0 295 #define LUL_20_SB_160(channel) 0 296 #define LUU_20_SB_160(channel) 0 297 #define ULL_20_SB_160(channel) 0 298 #define ULU_20_SB_160(channel) 0 299 #define UUL_20_SB_160(channel) 0 300 #define UUU_20_SB_160(channel) 0 301 302 #define LOWER_80_SB(chspec) 0 303 304 #define UPPER_80_SB(chspec) 0 305 306 #define LLL_20_SB_8080(chspec) 0 307 #define LLU_20_SB_8080(chspec) 0 308 #define LUL_20_SB_8080(chspec) 0 309 #define LUU_20_SB_8080(chspec) 0 310 #define ULL_20_SB_8080(chspec) 0 311 #define ULU_20_SB_8080(chspec) 0 312 #define UUL_20_SB_8080(chspec) 0 313 #define UUU_20_SB_8080(chspec) 0 314 315 /* get lowest 20MHz sideband of a given chspec 316 * (works with 20, 40, 80) 317 */ 318 #define CH_FIRST_20_SB(chspec) ((uint8) (\ 319 CHSPEC_IS80(chspec) ? LL_20_SB(CHSPEC_CHANNEL(chspec)) : (\ 320 CHSPEC_IS40(chspec) ? LOWER_20_SB(CHSPEC_CHANNEL(chspec)) : \ 321 CHSPEC_CHANNEL(chspec)))) 322 /* get upper most 20MHz sideband of a given chspec 323 * (works with 20, 40, 80, 160, 80p80) 324 */ 325 #define CH_LAST_20_SB(chspec) ((uint8) (\ 326 CHSPEC_IS80(chspec) ? UU_20_SB(CHSPEC_CHANNEL(chspec)) : (\ 327 CHSPEC_IS40(chspec) ? UPPER_20_SB(CHSPEC_CHANNEL(chspec)) : \ 328 CHSPEC_CHANNEL(chspec)))) 329 330 /* call this with chspec and a valid 20MHz sideband of this channel to get the next 20MHz sideband 331 * (works with 20, 40, 80, 160, 80p80) 332 * resolves to 0 if called with upper most channel 333 */ 334 #define CH_NEXT_20_SB(chspec, channel) ((uint8) (\ 335 ((uint8) ((channel) + CH_20MHZ_APART) > CH_LAST_20_SB(chspec) ? 0 : \ 336 ((channel) + CH_20MHZ_APART)))) 337 338 #endif /* WL11AC_80P80, WL11AC_160 */ 339 340 /* Iterator for 20MHz side bands of a chanspec: (chanspec_t chspec, uint8 channel) 341 * 'chspec' chanspec_t of interest (used in loop, better to pass a resolved value than a macro) 342 * 'channel' must be a variable (not an expression). 343 */ 344 #define FOREACH_20_SB(chspec, channel) \ 345 for (channel = CH_FIRST_20_SB(chspec); channel; \ 346 channel = CH_NEXT_20_SB((chspec), channel)) 347 348 /* Uses iterator to populate array with all side bands involved (sorted lower to upper). 349 * 'chspec' chanspec_t of interest 350 * 'psb' pointer to uint8 array of enough size to hold all side bands for the given chspec 351 */ 352 #define GET_ALL_SB(chspec, psb) do { \ 353 uint8 channel, idx = 0; \ 354 chanspec_t chspec_local = chspec; \ 355 FOREACH_20_SB(chspec_local, channel) \ 356 (psb)[idx++] = channel; \ 357 } while (0) 358 359 /* given a chanspec of any bw, tests if primary20 SB is in lower 20, 40, 80 respectively */ 360 #define IS_CTL_IN_L20(chspec) !((chspec) & WL_CHANSPEC_CTL_SB_U) /* CTL SB is in low 20 of any 40 */ 361 #define IS_CTL_IN_L40(chspec) !((chspec) & WL_CHANSPEC_CTL_SB_UL) /* in low 40 of any 80 */ 362 #define IS_CTL_IN_L80(chspec) !((chspec) & WL_CHANSPEC_CTL_SB_ULL) /* in low 80 of 80p80/160 */ 363 364 #endif /* !WL11N_20MHZONLY */ 365 366 /* ULB introduced macros. Remove once ULB is cleaned from phy code */ 367 #define CHSPEC_IS2P5(chspec) 0 368 #define CHSPEC_IS5(chspec) 0 369 #define CHSPEC_IS10(chspec) 0 370 #define CHSPEC_ISLE20(chspec) (CHSPEC_IS20(chspec)) 371 #define CHSPEC_BW_LE20(chspec) (CHSPEC_IS20(chspec)) 372 373 #define BW_LE40(bw) ((bw) == WL_CHANSPEC_BW_20 || ((bw) == WL_CHANSPEC_BW_40)) 374 #define BW_LE80(bw) (BW_LE40(bw) || ((bw) == WL_CHANSPEC_BW_80)) 375 #define BW_LE160(bw) (BW_LE80(bw) || ((bw) == WL_CHANSPEC_BW_160)) 376 377 #define CHSPEC_IS5G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G) 378 #define CHSPEC_IS2G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G) 379 #define CHSPEC_SB_UPPER(chspec) \ 380 ((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER) && \ 381 (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)) 382 #define CHSPEC_SB_LOWER(chspec) \ 383 ((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER) && \ 384 (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)) 385 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G) 386 387 /** 388 * Number of chars needed for wf_chspec_ntoa() destination character buffer. 389 */ 390 #define CHANSPEC_STR_LEN 20 391 392 /* 393 * This function returns TRUE if both the chanspec can co-exist in PHY. 394 * Addition to primary20 channel, the function checks for side band for 2g 40 channels 395 */ 396 extern bool wf_chspec_coexist(chanspec_t chspec1, chanspec_t chspec2); 397 398 #define CHSPEC_IS_BW_160_WIDE(chspec) (CHSPEC_BW(chspec) == WL_CHANSPEC_BW_160 ||\ 399 CHSPEC_BW(chspec) == WL_CHANSPEC_BW_8080) 400 401 /* BW inequality comparisons, LE (<=), GE (>=), LT (<), GT (>), comparisons can be made 402 * as simple numeric comparisons, with the exception that 160 is the same BW as 80+80, 403 * but have different numeric values; (WL_CHANSPEC_BW_160 < WL_CHANSPEC_BW_8080). 404 * 405 * The LT/LE/GT/GE macros check first checks whether both chspec bandwidth and bw are 160 wide. 406 * If both chspec bandwidth and bw is not 160 wide, then the comparison is made. 407 */ 408 #define CHSPEC_BW_GE(chspec, bw) \ 409 ((CHSPEC_IS_BW_160_WIDE(chspec) &&\ 410 ((bw) == WL_CHANSPEC_BW_160 || (bw) == WL_CHANSPEC_BW_8080)) ||\ 411 (CHSPEC_BW(chspec) >= (bw))) 412 413 #define CHSPEC_BW_LE(chspec, bw) \ 414 ((CHSPEC_IS_BW_160_WIDE(chspec) &&\ 415 ((bw) == WL_CHANSPEC_BW_160 || (bw) == WL_CHANSPEC_BW_8080)) ||\ 416 (CHSPEC_BW(chspec) <= (bw))) 417 418 #define CHSPEC_BW_GT(chspec, bw) \ 419 (!(CHSPEC_IS_BW_160_WIDE(chspec) &&\ 420 ((bw) == WL_CHANSPEC_BW_160 || (bw) == WL_CHANSPEC_BW_8080)) &&\ 421 (CHSPEC_BW(chspec) > (bw))) 422 423 #define CHSPEC_BW_LT(chspec, bw) \ 424 (!(CHSPEC_IS_BW_160_WIDE(chspec) &&\ 425 ((bw) == WL_CHANSPEC_BW_160 || (bw) == WL_CHANSPEC_BW_8080)) &&\ 426 (CHSPEC_BW(chspec) < (bw))) 427 428 /* Legacy Chanspec defines 429 * These are the defines for the previous format of the chanspec_t 430 */ 431 #define WL_LCHANSPEC_CHAN_MASK 0x00ff 432 #define WL_LCHANSPEC_CHAN_SHIFT 0 433 434 #define WL_LCHANSPEC_CTL_SB_MASK 0x0300 435 #define WL_LCHANSPEC_CTL_SB_SHIFT 8 436 #define WL_LCHANSPEC_CTL_SB_LOWER 0x0100 437 #define WL_LCHANSPEC_CTL_SB_UPPER 0x0200 438 #define WL_LCHANSPEC_CTL_SB_NONE 0x0300 439 440 #define WL_LCHANSPEC_BW_MASK 0x0C00 441 #define WL_LCHANSPEC_BW_SHIFT 10 442 #define WL_LCHANSPEC_BW_10 0x0400 443 #define WL_LCHANSPEC_BW_20 0x0800 444 #define WL_LCHANSPEC_BW_40 0x0C00 445 446 #define WL_LCHANSPEC_BAND_MASK 0xf000 447 #define WL_LCHANSPEC_BAND_SHIFT 12 448 #define WL_LCHANSPEC_BAND_5G 0x1000 449 #define WL_LCHANSPEC_BAND_2G 0x2000 450 451 #define LCHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_LCHANSPEC_CHAN_MASK)) 452 #define LCHSPEC_BAND(chspec) ((chspec) & WL_LCHANSPEC_BAND_MASK) 453 #define LCHSPEC_CTL_SB(chspec) ((chspec) & WL_LCHANSPEC_CTL_SB_MASK) 454 #define LCHSPEC_BW(chspec) ((chspec) & WL_LCHANSPEC_BW_MASK) 455 #define LCHSPEC_IS10(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_10) 456 #define LCHSPEC_IS20(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_20) 457 #define LCHSPEC_IS40(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_40) 458 #define LCHSPEC_IS5G(chspec) (((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_5G) 459 #define LCHSPEC_IS2G(chspec) (((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_2G) 460 461 #define LCHSPEC_SB_UPPER(chspec) \ 462 ((((chspec) & WL_LCHANSPEC_CTL_SB_MASK) == WL_LCHANSPEC_CTL_SB_UPPER) && \ 463 (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_40)) 464 #define LCHSPEC_SB_LOWER(chspec) \ 465 ((((chspec) & WL_LCHANSPEC_CTL_SB_MASK) == WL_LCHANSPEC_CTL_SB_LOWER) && \ 466 (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_40)) 467 468 #define LCHSPEC_CREATE(chan, band, bw, sb) ((uint16)((chan) | (sb) | (bw) | (band))) 469 470 #define CH20MHZ_LCHSPEC(channel) \ 471 (chanspec_t)((chanspec_t)(channel) | WL_LCHANSPEC_BW_20 | \ 472 WL_LCHANSPEC_CTL_SB_NONE | (((channel) <= CH_MAX_2G_CHANNEL) ? \ 473 WL_LCHANSPEC_BAND_2G : WL_LCHANSPEC_BAND_5G)) 474 475 #define GET_ALL_EXT wf_get_all_ext 476 477 /* 478 * WF_CHAN_FACTOR_* constants are used to calculate channel frequency 479 * given a channel number. 480 * chan_freq = chan_factor * 500Mhz + chan_number * 5 481 */ 482 483 /** 484 * Channel Factor for the starting frequence of 2.4 GHz channels. 485 * The value corresponds to 2407 MHz. 486 */ 487 #define WF_CHAN_FACTOR_2_4_G 4814 /* 2.4 GHz band, 2407 MHz */ 488 489 /** 490 * Channel Factor for the starting frequence of 5 GHz channels. 491 * The value corresponds to 5000 MHz. 492 */ 493 #define WF_CHAN_FACTOR_5_G 10000 /* 5 GHz band, 5000 MHz */ 494 495 /** 496 * Channel Factor for the starting frequence of 4.9 GHz channels. 497 * The value corresponds to 4000 MHz. 498 */ 499 #define WF_CHAN_FACTOR_4_G 8000 /* 4.9 GHz band for Japan */ 500 501 #define WLC_2G_25MHZ_OFFSET 5 /* 2.4GHz band channel offset */ 502 503 /** 504 * No of sub-band vlaue of the specified Mhz chanspec 505 */ 506 #define WF_NUM_SIDEBANDS_40MHZ 2 507 #define WF_NUM_SIDEBANDS_80MHZ 4 508 #define WF_NUM_SIDEBANDS_8080MHZ 4 509 #define WF_NUM_SIDEBANDS_160MHZ 8 510 511 /** 512 * Return the chanspec bandwidth in MHz 513 * Bandwidth of 160 MHz will be returned for 80+80MHz chanspecs. 514 * 515 * @param chspec chanspec_t 516 * 517 * @return bandwidth of chspec in MHz units 518 */ 519 extern uint wf_bw_chspec_to_mhz(chanspec_t chspec); 520 521 /** 522 * Convert chanspec to ascii string 523 * 524 * @param chspec chanspec format 525 * @param buf ascii string of chanspec 526 * 527 * @return pointer to buf with room for at least CHANSPEC_STR_LEN bytes 528 * Original chanspec in case of error 529 * 530 * @see CHANSPEC_STR_LEN 531 */ 532 extern char * wf_chspec_ntoa_ex(chanspec_t chspec, char *buf); 533 534 /** 535 * Convert chanspec to ascii string 536 * 537 * @param chspec chanspec format 538 * @param buf ascii string of chanspec 539 * 540 * @return pointer to buf with room for at least CHANSPEC_STR_LEN bytes 541 * NULL in case of error 542 * 543 * @see CHANSPEC_STR_LEN 544 */ 545 extern char * wf_chspec_ntoa(chanspec_t chspec, char *buf); 546 547 /** 548 * Convert ascii string to chanspec 549 * 550 * @param a pointer to input string 551 * 552 * @return >= 0 if successful or 0 otherwise 553 */ 554 extern chanspec_t wf_chspec_aton(const char *a); 555 556 /** 557 * Verify the chanspec fields are valid. 558 * 559 * Verify the chanspec is using a legal set field values, i.e. that the chanspec 560 * specified a band, bw, primary_sb, and channel and that the combination could be 561 * legal given some set of circumstances. 562 * 563 * @param chanspec input chanspec to verify 564 * 565 * @return TRUE if the chanspec is malformed, FALSE if it looks good. 566 */ 567 extern bool wf_chspec_malformed(chanspec_t chanspec); 568 569 /** 570 * Verify the chanspec specifies a valid channel according to 802.11. 571 * 572 * @param chanspec input chanspec to verify 573 * 574 * @return TRUE if the chanspec is a valid 802.11 channel 575 */ 576 extern bool wf_chspec_valid(chanspec_t chanspec); 577 578 /** 579 * Return the primary 20MHz channel. 580 * 581 * This function returns the channel number of the primary 20MHz channel. For 582 * 20MHz channels this is just the channel number. For 40MHz or wider channels 583 * it is the primary 20MHz channel specified by the chanspec. 584 * 585 * @param chspec input chanspec 586 * 587 * @return Returns the channel number of the primary 20MHz channel 588 */ 589 extern uint8 wf_chspec_primary20_chan(chanspec_t chspec); 590 591 /* alias for old function name */ 592 #define wf_chspec_ctlchan(c) wf_chspec_primary20_chan(c) 593 594 /** 595 * Return the bandwidth string. 596 * 597 * This function returns the bandwidth string for the passed chanspec. 598 * 599 * @param chspec input chanspec 600 * 601 * @return Returns the bandwidth string: 602 * "5", "10", "20", "40", "80", "160", "80+80" 603 */ 604 extern const char *wf_chspec_to_bw_str(chanspec_t chspec); 605 606 /** 607 * Create a 20MHz chanspec for the given band. 608 */ 609 chanspec_t wf_create_20MHz_chspec(uint channel, chanspec_band_t band); 610 611 /** 612 * Return the primary 20MHz chanspec. 613 * 614 * This function returns the chanspec of the primary 20MHz channel. For 20MHz 615 * channels this is just the chanspec. For 40MHz or wider channels it is the 616 * chanspec of the primary 20MHZ channel specified by the chanspec. 617 * 618 * @param chspec input chanspec 619 * 620 * @return Returns the chanspec of the primary 20MHz channel 621 */ 622 extern chanspec_t wf_chspec_primary20_chspec(chanspec_t chspec); 623 624 /* alias for old function name */ 625 #define wf_chspec_ctlchspec(c) wf_chspec_primary20_chspec(c) 626 627 /** 628 * Return the primary 40MHz chanspec. 629 * 630 * This function returns the chanspec for the primary 40MHz of an 80MHz or wider channel. 631 * The primary 20MHz channel of the returned 40MHz chanspec is the same as the primary 20MHz 632 * channel of the input chanspec. 633 */ 634 extern chanspec_t wf_chspec_primary40_chspec(chanspec_t chspec); 635 636 /* 637 * Return the channel number for a given frequency and base frequency. 638 * The returned channel number is relative to the given base frequency. 639 * If the given base frequency is zero, a base frequency of 5 GHz is assumed for 640 * frequencies from 5 - 6 GHz, and 2.407 GHz is assumed for 2.4 - 2.5 GHz. 641 * 642 * Frequency is specified in MHz. 643 * The base frequency is specified as (start_factor * 500 kHz). 644 * Constants WF_CHAN_FACTOR_2_4_G, WF_CHAN_FACTOR_5_G are defined for 645 * 2.4 GHz and 5 GHz bands. 646 * 647 * The returned channel will be in the range [1, 14] in the 2.4 GHz band 648 * and [0, 200] otherwise. 649 * -1 is returned if the start_factor is WF_CHAN_FACTOR_2_4_G and the 650 * frequency is not a 2.4 GHz channel, or if the frequency is not and even 651 * multiple of 5 MHz from the base frequency to the base plus 1 GHz. 652 * 653 * Reference 802.11-2016, section 17.3.8.3 and section 16.3.6.3 654 * 655 * @param freq frequency in MHz 656 * @param start_factor base frequency in 500 kHz units, e.g. 10000 for 5 GHz 657 * 658 * @return Returns a channel number 659 * 660 * @see WF_CHAN_FACTOR_2_4_G 661 * @see WF_CHAN_FACTOR_5_G 662 */ 663 extern int wf_mhz2channel(uint freq, uint start_factor); 664 665 /** 666 * Return the center frequency in MHz of the given channel and base frequency. 667 * 668 * Return the center frequency in MHz of the given channel and base frequency. 669 * The channel number is interpreted relative to the given base frequency. 670 * 671 * The valid channel range is [1, 14] in the 2.4 GHz band and [0, 200] otherwise. 672 * The base frequency is specified as (start_factor * 500 kHz). 673 * Constants WF_CHAN_FACTOR_2_4_G, WF_CHAN_FACTOR_5_G are defined for 674 * 2.4 GHz and 5 GHz bands. 675 * The channel range of [1, 14] is only checked for a start_factor of 676 * WF_CHAN_FACTOR_2_4_G (4814). 677 * Odd start_factors produce channels on .5 MHz boundaries, in which case 678 * the answer is rounded down to an integral MHz. 679 * -1 is returned for an out of range channel. 680 * 681 * Reference 802.11-2016, section 17.3.8.3 and section 16.3.6.3 682 * 683 * @param channel input channel number 684 * @param start_factor base frequency in 500 kHz units, e.g. 10000 for 5 GHz 685 * 686 * @return Returns a frequency in MHz 687 * 688 * @see WF_CHAN_FACTOR_2_4_G 689 * @see WF_CHAN_FACTOR_5_G 690 */ 691 extern int wf_channel2mhz(uint channel, uint start_factor); 692 693 /** 694 * Returns the chanspec 80Mhz channel corresponding to the following input 695 * parameters 696 * 697 * primary_channel - primary 20Mhz channel 698 * center_channel - center frequecny of the 80Mhz channel 699 * 700 * The center_channel can be one of {42, 58, 106, 122, 138, 155} 701 * 702 * returns INVCHANSPEC in case of error 703 */ 704 extern chanspec_t wf_chspec_80(uint8 center_channel, uint8 primary_channel); 705 706 /** 707 * Convert ctl chan and bw to chanspec 708 * 709 * @param ctl_ch channel 710 * @param bw bandwidth 711 * 712 * @return > 0 if successful or 0 otherwise 713 * 714 */ 715 extern uint16 wf_channel2chspec(uint ctl_ch, uint bw); 716 717 extern uint wf_channel2freq(uint channel); 718 extern uint wf_freq2channel(uint freq); 719 720 /* 721 * Returns the 80+80 MHz chanspec corresponding to the following input parameters 722 * 723 * primary_20mhz - Primary 20 MHz channel 724 * chan0_80MHz - center channel number of one frequency segment 725 * chan1_80MHz - center channel number of the other frequency segment 726 * 727 * Parameters chan0_80MHz and chan1_80MHz are channel numbers in {42, 58, 106, 122, 138, 155}. 728 * The primary channel must be contained in one of the 80MHz channels. This routine 729 * will determine which frequency segment is the primary 80 MHz segment. 730 * 731 * Returns INVCHANSPEC in case of error. 732 * 733 * Refer to 802.11-2016 section 22.3.14 "Channelization". 734 */ 735 extern chanspec_t wf_chspec_get8080_chspec(uint8 primary_20mhz, 736 uint8 chan0_80Mhz, uint8 chan1_80Mhz); 737 738 /** 739 * Returns the center channel of the primary 80 MHz sub-band of the provided chanspec 740 * 741 * @param chspec input chanspec 742 * 743 * @return center channel number of the primary 80MHz sub-band of the input. 744 * Will return the center channel of an input 80MHz chspec. 745 * Will return INVCHANNEL if the chspec is malformed or less than 80MHz bw. 746 */ 747 extern uint8 wf_chspec_primary80_channel(chanspec_t chanspec); 748 749 /** 750 * Returns the center channel of the secondary 80 MHz sub-band of the provided chanspec 751 * 752 * @param chspec input chanspec 753 * 754 * @return center channel number of the secondary 80MHz sub-band of the input. 755 * Will return INVCHANNEL if the chspec is malformed or bw is not greater than 80MHz. 756 */ 757 extern uint8 wf_chspec_secondary80_channel(chanspec_t chanspec); 758 759 /** 760 * Returns the chanspec for the primary 80MHz sub-band of an 160MHz or 80+80 channel 761 * 762 * @param chspec input chanspec 763 * 764 * @return An 80MHz chanspec describing the primary 80MHz sub-band of the input. 765 * Will return an input 80MHz chspec as is. 766 * Will return INVCHANSPEC if the chspec is malformed or less than 80MHz bw. 767 */ 768 extern chanspec_t wf_chspec_primary80_chspec(chanspec_t chspec); 769 770 /** 771 * Returns the chanspec for the secondary 80MHz sub-band of an 160MHz or 80+80 channel 772 * The sideband in the chanspec is always set to WL_CHANSPEC_CTL_SB_LL since this sub-band 773 * does not contain the primary 20MHz channel. 774 * 775 * @param chspec input chanspec 776 * 777 * @return An 80MHz chanspec describing the secondary 80MHz sub-band of the input. 778 * Will return INVCHANSPEC if the chspec is malformed or bw is not greater than 80MHz. 779 */ 780 extern chanspec_t wf_chspec_secondary80_chspec(chanspec_t chspec); 781 782 /* 783 * For 160MHz or 80P80 chanspec, set ch[0]/ch[1] to be the low/high 80 Mhz channels 784 * 785 * For 20/40/80MHz chanspec, set ch[0] to be the center freq, and chan[1]=-1 786 */ 787 extern void wf_chspec_get_80p80_channels(chanspec_t chspec, uint8 *ch); 788 789 #ifdef WL11AC_80P80 790 /* 791 * This function returns the centre chanel for the given chanspec. 792 * In case of 80+80 chanspec it returns the primary 80 Mhz centre channel 793 */ 794 extern uint8 wf_chspec_channel(chanspec_t chspec); 795 #endif // endif 796 extern chanspec_t wf_channel_create_chspec_frm_opclass(uint8 opclass, uint8 channel); 797 extern int wf_channel_create_opclass_frm_chspec(chanspec_t chspec); 798 799 /* Populates array with all 20MHz side bands of a given chanspec_t in the following order: 800 * primary20, ext20, two ext40s, four ext80s. 801 * 'chspec' is the chanspec of interest 802 * 'pext' must point to an uint8 array of long enough to hold all side bands of the given chspec 803 * 804 * Works with 20, 40, 80, 80p80 and 160MHz chspec 805 */ 806 807 extern void wf_get_all_ext(chanspec_t chspec, uint8 *chan_ptr); 808 809 /* 810 * Given two chanspecs, returns true if they overlap. 811 * (Overlap: At least one 20MHz subband is common between the two chanspecs provided) 812 */ 813 extern bool wf_chspec_overlap(chanspec_t chspec0, chanspec_t chspec1); 814 815 extern uint8 channel_bw_to_width(chanspec_t chspec); 816 #endif /* _bcmwifi_channels_h_ */ 817