Home | History | Annotate | Download | only in include
      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  * Copyright (C) 1999-2012, Broadcom Corporation
      7  *
      8  * Permission to use, copy, modify, and/or distribute this software for any
      9  * purpose with or without fee is hereby granted, provided that the above
     10  * copyright notice and this permission notice appear in all copies.
     11  *
     12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     15  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
     17  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
     18  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     19  *
     20  * $Id: bcmwifi_channels.h 309193 2012-01-19 00:03:57Z $
     21  */
     22 
     23 #ifndef	_bcmwifi_channels_h_
     24 #define	_bcmwifi_channels_h_
     25 
     26 
     27 
     28 typedef uint16 chanspec_t;
     29 
     30 
     31 #define CH_UPPER_SB			0x01
     32 #define CH_LOWER_SB			0x02
     33 #define CH_EWA_VALID			0x04
     34 #define CH_80MHZ_APART			16
     35 #define CH_40MHZ_APART			8
     36 #define CH_20MHZ_APART			4
     37 #define CH_10MHZ_APART			2
     38 #define CH_5MHZ_APART			1
     39 #define CH_MAX_2G_CHANNEL		14
     40 #define	MAXCHANNEL		224
     41 #define CHSPEC_CTLOVLP(sp1, sp2, sep)	ABS(wf_chspec_ctlchan(sp1) - wf_chspec_ctlchan(sp2)) < (sep)
     42 
     43 
     44 #undef  D11AC_IOTYPES
     45 #define D11AC_IOTYPES
     46 
     47 #ifndef D11AC_IOTYPES
     48 
     49 #define WL_CHANSPEC_CHAN_MASK		0x00ff
     50 #define WL_CHANSPEC_CHAN_SHIFT		0
     51 
     52 #define WL_CHANSPEC_CTL_SB_MASK		0x0300
     53 #define WL_CHANSPEC_CTL_SB_SHIFT	     8
     54 #define WL_CHANSPEC_CTL_SB_LOWER	0x0100
     55 #define WL_CHANSPEC_CTL_SB_UPPER	0x0200
     56 #define WL_CHANSPEC_CTL_SB_NONE		0x0300
     57 
     58 #define WL_CHANSPEC_BW_MASK		0x0C00
     59 #define WL_CHANSPEC_BW_SHIFT		    10
     60 #define WL_CHANSPEC_BW_10		0x0400
     61 #define WL_CHANSPEC_BW_20		0x0800
     62 #define WL_CHANSPEC_BW_40		0x0C00
     63 
     64 #define WL_CHANSPEC_BAND_MASK		0xf000
     65 #define WL_CHANSPEC_BAND_SHIFT		12
     66 #define WL_CHANSPEC_BAND_5G		0x1000
     67 #define WL_CHANSPEC_BAND_2G		0x2000
     68 #define INVCHANSPEC			255
     69 
     70 
     71 #define LOWER_20_SB(channel)	(((channel) > CH_10MHZ_APART) ? ((channel) - CH_10MHZ_APART) : 0)
     72 #define UPPER_20_SB(channel)	(((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \
     73 				((channel) + CH_10MHZ_APART) : 0)
     74 #define CHSPEC_WLCBANDUNIT(chspec)	(CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX)
     75 #define CH20MHZ_CHSPEC(channel)	(chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \
     76 				WL_CHANSPEC_CTL_SB_NONE | (((channel) <= CH_MAX_2G_CHANNEL) ? \
     77 				WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G))
     78 #define NEXT_20MHZ_CHAN(channel)	(((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \
     79 					((channel) + CH_20MHZ_APART) : 0)
     80 #define CH40MHZ_CHSPEC(channel, ctlsb)	(chanspec_t) \
     81 					((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \
     82 					((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \
     83 					WL_CHANSPEC_BAND_5G))
     84 #define CHSPEC_CHANNEL(chspec)	((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK))
     85 #define CHSPEC_BAND(chspec)	((chspec) & WL_CHANSPEC_BAND_MASK)
     86 
     87 
     88 #define CHSPEC_CTL_SB(chspec)	((chspec) & WL_CHANSPEC_CTL_SB_MASK)
     89 #define CHSPEC_BW(chspec)	((chspec) & WL_CHANSPEC_BW_MASK)
     90 
     91 #ifdef WL11N_20MHZONLY
     92 
     93 #define CHSPEC_IS10(chspec)	0
     94 #define CHSPEC_IS20(chspec)	1
     95 #ifndef CHSPEC_IS40
     96 #define CHSPEC_IS40(chspec)	0
     97 #endif
     98 
     99 #else
    100 
    101 #define CHSPEC_IS10(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
    102 #define CHSPEC_IS20(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
    103 #ifndef CHSPEC_IS40
    104 #define CHSPEC_IS40(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
    105 #endif
    106 
    107 #endif
    108 
    109 #define CHSPEC_IS5G(chspec)	(((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
    110 #define CHSPEC_IS2G(chspec)	(((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
    111 #define CHSPEC_SB_NONE(chspec)	(((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_NONE)
    112 #define CHSPEC_SB_UPPER(chspec)	(((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER)
    113 #define CHSPEC_SB_LOWER(chspec)	(((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER)
    114 #define CHSPEC_CTL_CHAN(chspec)  ((CHSPEC_SB_LOWER(chspec)) ? \
    115 				  (LOWER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))) : \
    116 				  (UPPER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))))
    117 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G)
    118 
    119 #define CHANSPEC_STR_LEN    8
    120 
    121 #else
    122 
    123 #define WL_CHANSPEC_CHAN_MASK		0x00ff
    124 #define WL_CHANSPEC_CHAN_SHIFT		0
    125 #define WL_CHANSPEC_CHAN1_MASK		0x000f
    126 #define WL_CHANSPEC_CHAN1_SHIFT		0
    127 #define WL_CHANSPEC_CHAN2_MASK		0x00f0
    128 #define WL_CHANSPEC_CHAN2_SHIFT		4
    129 
    130 #define WL_CHANSPEC_CTL_SB_MASK		0x0700
    131 #define WL_CHANSPEC_CTL_SB_SHIFT	8
    132 #define WL_CHANSPEC_CTL_SB_LLL		0x0000
    133 #define WL_CHANSPEC_CTL_SB_LLU		0x0100
    134 #define WL_CHANSPEC_CTL_SB_LUL		0x0200
    135 #define WL_CHANSPEC_CTL_SB_LUU		0x0300
    136 #define WL_CHANSPEC_CTL_SB_ULL		0x0400
    137 #define WL_CHANSPEC_CTL_SB_ULU		0x0500
    138 #define WL_CHANSPEC_CTL_SB_UUL		0x0600
    139 #define WL_CHANSPEC_CTL_SB_UUU		0x0700
    140 #define WL_CHANSPEC_CTL_SB_LL		WL_CHANSPEC_CTL_SB_LLL
    141 #define WL_CHANSPEC_CTL_SB_LU		WL_CHANSPEC_CTL_SB_LLU
    142 #define WL_CHANSPEC_CTL_SB_UL		WL_CHANSPEC_CTL_SB_LUL
    143 #define WL_CHANSPEC_CTL_SB_UU		WL_CHANSPEC_CTL_SB_LUU
    144 #define WL_CHANSPEC_CTL_SB_L		WL_CHANSPEC_CTL_SB_LLL
    145 #define WL_CHANSPEC_CTL_SB_U		WL_CHANSPEC_CTL_SB_LLU
    146 #define WL_CHANSPEC_CTL_SB_LOWER 	WL_CHANSPEC_CTL_SB_LLL
    147 #define WL_CHANSPEC_CTL_SB_UPPER	WL_CHANSPEC_CTL_SB_LLU
    148 
    149 #define WL_CHANSPEC_BW_MASK		0x3800
    150 #define WL_CHANSPEC_BW_SHIFT		11
    151 #define WL_CHANSPEC_BW_5		0x0000
    152 #define WL_CHANSPEC_BW_10		0x0800
    153 #define WL_CHANSPEC_BW_20		0x1000
    154 #define WL_CHANSPEC_BW_40		0x1800
    155 #define WL_CHANSPEC_BW_80		0x2000
    156 #define WL_CHANSPEC_BW_160		0x2800
    157 #define WL_CHANSPEC_BW_8080		0x3000
    158 
    159 #define WL_CHANSPEC_BAND_MASK		0xc000
    160 #define WL_CHANSPEC_BAND_SHIFT		14
    161 #define WL_CHANSPEC_BAND_2G		0x0000
    162 #define WL_CHANSPEC_BAND_3G		0x4000
    163 #define WL_CHANSPEC_BAND_4G		0x8000
    164 #define WL_CHANSPEC_BAND_5G		0xc000
    165 #define INVCHANSPEC			255
    166 
    167 
    168 #define LOWER_20_SB(channel)		(((channel) > CH_10MHZ_APART) ? \
    169 					((channel) - CH_10MHZ_APART) : 0)
    170 #define UPPER_20_SB(channel)		(((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \
    171 					((channel) + CH_10MHZ_APART) : 0)
    172 #define LOWER_40_SB(channel)		((channel) - CH_20MHZ_APART)
    173 #define UPPER_40_SB(channel)		((channel) + CH_20MHZ_APART)
    174 #define CHSPEC_WLCBANDUNIT(chspec)	(CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX)
    175 #define CH20MHZ_CHSPEC(channel)		(chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \
    176 					(((channel) <= CH_MAX_2G_CHANNEL) ? \
    177 					WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G))
    178 #define NEXT_20MHZ_CHAN(channel)	(((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \
    179 					((channel) + CH_20MHZ_APART) : 0)
    180 #define CH40MHZ_CHSPEC(channel, ctlsb)	(chanspec_t) \
    181 					((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \
    182 					((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \
    183 					WL_CHANSPEC_BAND_5G))
    184 #define CH80MHZ_CHSPEC(channel, ctlsb)	(chanspec_t) \
    185 					((channel) | (ctlsb) | \
    186 					 WL_CHANSPEC_BW_80 | WL_CHANSPEC_BAND_5G)
    187 #define CH160MHZ_CHSPEC(channel, ctlsb)	(chanspec_t) \
    188 					((channel) | (ctlsb) | \
    189 					 WL_CHANSPEC_BW_160 | WL_CHANSPEC_BAND_5G)
    190 
    191 
    192 #define CHSPEC_CHANNEL(chspec)		((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK))
    193 #define CHSPEC_CHAN1(chspec)		((chspec) & WL_CHANSPEC_CHAN1_MASK)
    194 #define CHSPEC_CHAN2(chspec)		((chspec) & WL_CHANSPEC_CHAN2_MASK)
    195 #define CHSPEC_BAND(chspec)		((chspec) & WL_CHANSPEC_BAND_MASK)
    196 #define CHSPEC_CTL_SB(chspec)		((chspec) & WL_CHANSPEC_CTL_SB_MASK)
    197 #define CHSPEC_BW(chspec)		((chspec) & WL_CHANSPEC_BW_MASK)
    198 
    199 #ifdef WL11N_20MHZONLY
    200 
    201 #define CHSPEC_IS10(chspec)	0
    202 #define CHSPEC_IS20(chspec)	1
    203 #ifndef CHSPEC_IS40
    204 #define CHSPEC_IS40(chspec)	0
    205 #endif
    206 #ifndef CHSPEC_IS80
    207 #define CHSPEC_IS80(chspec)	0
    208 #endif
    209 #ifndef CHSPEC_IS160
    210 #define CHSPEC_IS160(chspec)	0
    211 #endif
    212 #ifndef CHSPEC_IS8080
    213 #define CHSPEC_IS8080(chspec)	0
    214 #endif
    215 
    216 #else
    217 
    218 #define CHSPEC_IS10(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
    219 #define CHSPEC_IS20(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
    220 #ifndef CHSPEC_IS40
    221 #define CHSPEC_IS40(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
    222 #endif
    223 #ifndef CHSPEC_IS80
    224 #define CHSPEC_IS80(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_80)
    225 #endif
    226 #ifndef CHSPEC_IS160
    227 #define CHSPEC_IS160(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_160)
    228 #endif
    229 #ifndef CHSPEC_IS8080
    230 #define CHSPEC_IS8080(chspec)	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_8080)
    231 #endif
    232 
    233 #endif
    234 
    235 #define CHSPEC_IS5G(chspec)	(((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
    236 #define CHSPEC_IS2G(chspec)	(((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
    237 #define CHSPEC_SB_UPPER(chspec)	\
    238 	((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER) && \
    239 	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40))
    240 #define CHSPEC_SB_LOWER(chspec)	\
    241 	((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER) && \
    242 	(((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40))
    243 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G)
    244 
    245 
    246 #define CHANSPEC_STR_LEN    20
    247 
    248 
    249 
    250 #define WL_LCHANSPEC_CHAN_MASK		0x00ff
    251 #define WL_LCHANSPEC_CHAN_SHIFT		     0
    252 
    253 #define WL_LCHANSPEC_CTL_SB_MASK	0x0300
    254 #define WL_LCHANSPEC_CTL_SB_SHIFT	     8
    255 #define WL_LCHANSPEC_CTL_SB_LOWER	0x0100
    256 #define WL_LCHANSPEC_CTL_SB_UPPER	0x0200
    257 #define WL_LCHANSPEC_CTL_SB_NONE	0x0300
    258 
    259 #define WL_LCHANSPEC_BW_MASK		0x0C00
    260 #define WL_LCHANSPEC_BW_SHIFT		    10
    261 #define WL_LCHANSPEC_BW_10		0x0400
    262 #define WL_LCHANSPEC_BW_20		0x0800
    263 #define WL_LCHANSPEC_BW_40		0x0C00
    264 
    265 #define WL_LCHANSPEC_BAND_MASK		0xf000
    266 #define WL_LCHANSPEC_BAND_SHIFT		    12
    267 #define WL_LCHANSPEC_BAND_5G		0x1000
    268 #define WL_LCHANSPEC_BAND_2G		0x2000
    269 
    270 #define LCHSPEC_CHANNEL(chspec)	((uint8)((chspec) & WL_LCHANSPEC_CHAN_MASK))
    271 #define LCHSPEC_BAND(chspec)	((chspec) & WL_LCHANSPEC_BAND_MASK)
    272 #define LCHSPEC_CTL_SB(chspec)	((chspec) & WL_LCHANSPEC_CTL_SB_MASK)
    273 #define LCHSPEC_BW(chspec)	((chspec) & WL_LCHANSPEC_BW_MASK)
    274 #define LCHSPEC_IS10(chspec)	(((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_10)
    275 #define LCHSPEC_IS20(chspec)	(((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_20)
    276 #define LCHSPEC_IS40(chspec)	(((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_40)
    277 #define LCHSPEC_IS5G(chspec)	(((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_5G)
    278 #define LCHSPEC_IS2G(chspec)	(((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_2G)
    279 
    280 #define LCHSPEC_CREATE(chan, band, bw, sb)  ((uint16)((chan) | (sb) | (bw) | (band)))
    281 
    282 #endif
    283 
    284 
    285 
    286 
    287 #define WF_CHAN_FACTOR_2_4_G		4814
    288 
    289 
    290 #define WF_CHAN_FACTOR_5_G		10000
    291 
    292 
    293 #define WF_CHAN_FACTOR_4_G		8000
    294 
    295 
    296 #define WLC_MAXRATE	108
    297 #define WLC_RATE_1M	2
    298 #define WLC_RATE_2M	4
    299 #define WLC_RATE_5M5	11
    300 #define WLC_RATE_11M	22
    301 #define WLC_RATE_6M	12
    302 #define WLC_RATE_9M	18
    303 #define WLC_RATE_12M	24
    304 #define WLC_RATE_18M	36
    305 #define WLC_RATE_24M	48
    306 #define WLC_RATE_36M	72
    307 #define WLC_RATE_48M	96
    308 #define WLC_RATE_54M	108
    309 
    310 #define WLC_2G_25MHZ_OFFSET		5
    311 
    312 
    313 extern char * wf_chspec_ntoa(chanspec_t chspec, char *buf);
    314 
    315 
    316 extern chanspec_t wf_chspec_aton(const char *a);
    317 
    318 
    319 extern bool wf_chspec_malformed(chanspec_t chanspec);
    320 
    321 
    322 extern bool wf_chspec_valid(chanspec_t chanspec);
    323 
    324 
    325 extern uint8 wf_chspec_ctlchan(chanspec_t chspec);
    326 
    327 
    328 extern chanspec_t wf_chspec_ctlchspec(chanspec_t chspec);
    329 
    330 
    331 extern chanspec_t wf_chspec_primary40_chspec(chanspec_t chspec);
    332 
    333 
    334 extern int wf_mhz2channel(uint freq, uint start_factor);
    335 
    336 
    337 extern int wf_channel2mhz(uint channel, uint start_factor);
    338 
    339 #endif
    340