bcmwifi_channels.h 32 KB

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