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