channel.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/types.h>
  17. #include <net/cfg80211.h>
  18. #include <net/mac80211.h>
  19. #include <net/regulatory.h>
  20. #include <defs.h>
  21. #include "pub.h"
  22. #include "phy/phy_hal.h"
  23. #include "main.h"
  24. #include "stf.h"
  25. #include "channel.h"
  26. #include "mac80211_if.h"
  27. /* QDB() macro takes a dB value and converts to a quarter dB value */
  28. #define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
  29. #define LOCALE_CHAN_01_11 (1<<0)
  30. #define LOCALE_CHAN_12_13 (1<<1)
  31. #define LOCALE_CHAN_14 (1<<2)
  32. #define LOCALE_SET_5G_LOW_JP1 (1<<3) /* 34-48, step 2 */
  33. #define LOCALE_SET_5G_LOW_JP2 (1<<4) /* 34-46, step 4 */
  34. #define LOCALE_SET_5G_LOW1 (1<<5) /* 36-48, step 4 */
  35. #define LOCALE_SET_5G_LOW2 (1<<6) /* 52 */
  36. #define LOCALE_SET_5G_LOW3 (1<<7) /* 56-64, step 4 */
  37. #define LOCALE_SET_5G_MID1 (1<<8) /* 100-116, step 4 */
  38. #define LOCALE_SET_5G_MID2 (1<<9) /* 120-124, step 4 */
  39. #define LOCALE_SET_5G_MID3 (1<<10) /* 128 */
  40. #define LOCALE_SET_5G_HIGH1 (1<<11) /* 132-140, step 4 */
  41. #define LOCALE_SET_5G_HIGH2 (1<<12) /* 149-161, step 4 */
  42. #define LOCALE_SET_5G_HIGH3 (1<<13) /* 165 */
  43. #define LOCALE_CHAN_52_140_ALL (1<<14)
  44. #define LOCALE_SET_5G_HIGH4 (1<<15) /* 184-216 */
  45. #define LOCALE_CHAN_36_64 (LOCALE_SET_5G_LOW1 | \
  46. LOCALE_SET_5G_LOW2 | \
  47. LOCALE_SET_5G_LOW3)
  48. #define LOCALE_CHAN_52_64 (LOCALE_SET_5G_LOW2 | LOCALE_SET_5G_LOW3)
  49. #define LOCALE_CHAN_100_124 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2)
  50. #define LOCALE_CHAN_100_140 (LOCALE_SET_5G_MID1 | LOCALE_SET_5G_MID2 | \
  51. LOCALE_SET_5G_MID3 | LOCALE_SET_5G_HIGH1)
  52. #define LOCALE_CHAN_149_165 (LOCALE_SET_5G_HIGH2 | LOCALE_SET_5G_HIGH3)
  53. #define LOCALE_CHAN_184_216 LOCALE_SET_5G_HIGH4
  54. #define LOCALE_CHAN_01_14 (LOCALE_CHAN_01_11 | \
  55. LOCALE_CHAN_12_13 | \
  56. LOCALE_CHAN_14)
  57. #define LOCALE_RESTRICTED_NONE 0
  58. #define LOCALE_RESTRICTED_SET_2G_SHORT 1
  59. #define LOCALE_2G_IDX_i 0
  60. #define LOCALE_5G_IDX_11 0
  61. #define LOCALE_MIMO_IDX_bn 0
  62. #define LOCALE_MIMO_IDX_11n 0
  63. /* max of BAND_5G_PWR_LVLS and 6 for 2.4 GHz */
  64. #define BRCMS_MAXPWR_TBL_SIZE 6
  65. /* max of BAND_5G_PWR_LVLS and 14 for 2.4 GHz */
  66. #define BRCMS_MAXPWR_MIMO_TBL_SIZE 14
  67. /* power level in group of 2.4GHz band channels:
  68. * maxpwr[0] - CCK channels [1]
  69. * maxpwr[1] - CCK channels [2-10]
  70. * maxpwr[2] - CCK channels [11-14]
  71. * maxpwr[3] - OFDM channels [1]
  72. * maxpwr[4] - OFDM channels [2-10]
  73. * maxpwr[5] - OFDM channels [11-14]
  74. */
  75. /* maxpwr mapping to 5GHz band channels:
  76. * maxpwr[0] - channels [34-48]
  77. * maxpwr[1] - channels [52-60]
  78. * maxpwr[2] - channels [62-64]
  79. * maxpwr[3] - channels [100-140]
  80. * maxpwr[4] - channels [149-165]
  81. */
  82. #define BAND_5G_PWR_LVLS 5 /* 5 power levels for 5G */
  83. #define LC(id) LOCALE_MIMO_IDX_ ## id
  84. #define LC_2G(id) LOCALE_2G_IDX_ ## id
  85. #define LC_5G(id) LOCALE_5G_IDX_ ## id
  86. #define LOCALES(band2, band5, mimo2, mimo5) \
  87. {LC_2G(band2), LC_5G(band5), LC(mimo2), LC(mimo5)}
  88. /* macro to get 2.4 GHz channel group index for tx power */
  89. #define CHANNEL_POWER_IDX_2G_CCK(c) (((c) < 2) ? 0 : (((c) < 11) ? 1 : 2))
  90. #define CHANNEL_POWER_IDX_2G_OFDM(c) (((c) < 2) ? 3 : (((c) < 11) ? 4 : 5))
  91. /* macro to get 5 GHz channel group index for tx power */
  92. #define CHANNEL_POWER_IDX_5G(c) (((c) < 52) ? 0 : \
  93. (((c) < 62) ? 1 : \
  94. (((c) < 100) ? 2 : \
  95. (((c) < 149) ? 3 : 4))))
  96. #define BRCM_2GHZ_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
  97. #define BRCM_2GHZ_2467_2472 REG_RULE(2467-10, 2472+10, 20, 0, 19, \
  98. NL80211_RRF_PASSIVE_SCAN | \
  99. NL80211_RRF_NO_IBSS)
  100. #define BRCM_5GHZ_5180_5240 REG_RULE(5180-10, 5240+10, 40, 0, 21, \
  101. NL80211_RRF_PASSIVE_SCAN | \
  102. NL80211_RRF_NO_IBSS)
  103. #define BRCM_5GHZ_5260_5320 REG_RULE(5260-10, 5320+10, 40, 0, 21, \
  104. NL80211_RRF_PASSIVE_SCAN | \
  105. NL80211_RRF_DFS | \
  106. NL80211_RRF_NO_IBSS)
  107. #define BRCM_5GHZ_5500_5700 REG_RULE(5500-10, 5700+10, 40, 0, 21, \
  108. NL80211_RRF_PASSIVE_SCAN | \
  109. NL80211_RRF_DFS | \
  110. NL80211_RRF_NO_IBSS)
  111. #define BRCM_5GHZ_5745_5825 REG_RULE(5745-10, 5825+10, 40, 0, 21, \
  112. NL80211_RRF_PASSIVE_SCAN | \
  113. NL80211_RRF_NO_IBSS)
  114. static const struct ieee80211_regdomain brcms_regdom_x2 = {
  115. .n_reg_rules = 7,
  116. .alpha2 = "X2",
  117. .reg_rules = {
  118. BRCM_2GHZ_2412_2462,
  119. BRCM_2GHZ_2467_2472,
  120. BRCM_5GHZ_5180_5240,
  121. BRCM_5GHZ_5260_5320,
  122. BRCM_5GHZ_5500_5700,
  123. BRCM_5GHZ_5745_5825,
  124. }
  125. };
  126. struct brcms_cm_band {
  127. /* struct locale_info flags */
  128. u8 locale_flags;
  129. /* List of valid channels in the country */
  130. struct brcms_chanvec valid_channels;
  131. /* List of restricted use channels */
  132. const struct brcms_chanvec *restricted_channels;
  133. };
  134. /* locale per-channel tx power limits for MIMO frames
  135. * maxpwr arrays are index by channel for 2.4 GHz limits, and
  136. * by sub-band for 5 GHz limits using CHANNEL_POWER_IDX_5G(channel)
  137. */
  138. struct locale_mimo_info {
  139. /* tx 20 MHz power limits, qdBm units */
  140. s8 maxpwr20[BRCMS_MAXPWR_MIMO_TBL_SIZE];
  141. /* tx 40 MHz power limits, qdBm units */
  142. s8 maxpwr40[BRCMS_MAXPWR_MIMO_TBL_SIZE];
  143. u8 flags;
  144. };
  145. /* Country names and abbreviations with locale defined from ISO 3166 */
  146. struct country_info {
  147. const u8 locale_2G; /* 2.4G band locale */
  148. const u8 locale_5G; /* 5G band locale */
  149. const u8 locale_mimo_2G; /* 2.4G mimo info */
  150. const u8 locale_mimo_5G; /* 5G mimo info */
  151. };
  152. struct brcms_regd {
  153. struct country_info country;
  154. const struct ieee80211_regdomain *regdomain;
  155. };
  156. struct brcms_cm_info {
  157. struct brcms_pub *pub;
  158. struct brcms_c_info *wlc;
  159. const struct brcms_regd *world_regd;
  160. /* per-band state (one per phy/radio) */
  161. struct brcms_cm_band bandstate[MAXBANDS];
  162. /* quiet channels currently for radar sensitivity or 11h support */
  163. /* channels on which we cannot transmit */
  164. struct brcms_chanvec quiet_channels;
  165. };
  166. /* locale channel and power info. */
  167. struct locale_info {
  168. u32 valid_channels;
  169. /* List of channels used only if APs are detected */
  170. u8 restricted_channels;
  171. /* Max tx pwr in qdBm for each sub-band */
  172. s8 maxpwr[BRCMS_MAXPWR_TBL_SIZE];
  173. u8 flags;
  174. };
  175. /* Regulatory Matrix Spreadsheet (CLM) MIMO v3.7.9 */
  176. /*
  177. * Some common channel sets
  178. */
  179. /* No channels */
  180. static const struct brcms_chanvec chanvec_none = {
  181. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  182. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  183. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  184. 0x00, 0x00, 0x00, 0x00}
  185. };
  186. /*
  187. * Restricted channel sets
  188. */
  189. /* Channels 12, 13 */
  190. static const struct brcms_chanvec restricted_set_2g_short = {
  191. {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  192. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  193. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  194. 0x00, 0x00, 0x00, 0x00}
  195. };
  196. /* global memory to provide working buffer for expanded locale */
  197. static const struct brcms_chanvec *g_table_restricted_chan[] = {
  198. &chanvec_none, /* restricted_set_none */
  199. &restricted_set_2g_short,
  200. };
  201. static const struct brcms_chanvec locale_2g_01_11 = {
  202. {0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  205. 0x00, 0x00, 0x00, 0x00}
  206. };
  207. static const struct brcms_chanvec locale_2g_12_13 = {
  208. {0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x00, 0x00}
  212. };
  213. static const struct brcms_chanvec locale_2g_14 = {
  214. {0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  215. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  216. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  217. 0x00, 0x00, 0x00, 0x00}
  218. };
  219. static const struct brcms_chanvec locale_5g_LOW_JP1 = {
  220. {0x00, 0x00, 0x00, 0x00, 0x54, 0x55, 0x01, 0x00,
  221. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  222. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  223. 0x00, 0x00, 0x00, 0x00}
  224. };
  225. static const struct brcms_chanvec locale_5g_LOW_JP2 = {
  226. {0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
  227. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  228. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  229. 0x00, 0x00, 0x00, 0x00}
  230. };
  231. static const struct brcms_chanvec locale_5g_LOW1 = {
  232. {0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x01, 0x00,
  233. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  234. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  235. 0x00, 0x00, 0x00, 0x00}
  236. };
  237. static const struct brcms_chanvec locale_5g_LOW2 = {
  238. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  239. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  240. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  241. 0x00, 0x00, 0x00, 0x00}
  242. };
  243. static const struct brcms_chanvec locale_5g_LOW3 = {
  244. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
  245. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  246. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  247. 0x00, 0x00, 0x00, 0x00}
  248. };
  249. static const struct brcms_chanvec locale_5g_MID1 = {
  250. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  251. 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x11, 0x00,
  252. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  253. 0x00, 0x00, 0x00, 0x00}
  254. };
  255. static const struct brcms_chanvec locale_5g_MID2 = {
  256. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  257. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
  258. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  259. 0x00, 0x00, 0x00, 0x00}
  260. };
  261. static const struct brcms_chanvec locale_5g_MID3 = {
  262. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  263. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  264. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  265. 0x00, 0x00, 0x00, 0x00}
  266. };
  267. static const struct brcms_chanvec locale_5g_HIGH1 = {
  268. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  269. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  270. 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  271. 0x00, 0x00, 0x00, 0x00}
  272. };
  273. static const struct brcms_chanvec locale_5g_HIGH2 = {
  274. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  275. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  276. 0x00, 0x00, 0x20, 0x22, 0x02, 0x00, 0x00, 0x00,
  277. 0x00, 0x00, 0x00, 0x00}
  278. };
  279. static const struct brcms_chanvec locale_5g_HIGH3 = {
  280. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  281. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  282. 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  283. 0x00, 0x00, 0x00, 0x00}
  284. };
  285. static const struct brcms_chanvec locale_5g_52_140_ALL = {
  286. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11,
  287. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  288. 0x11, 0x11, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  289. 0x00, 0x00, 0x00, 0x00}
  290. };
  291. static const struct brcms_chanvec locale_5g_HIGH4 = {
  292. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
  295. 0x11, 0x11, 0x11, 0x11}
  296. };
  297. static const struct brcms_chanvec *g_table_locale_base[] = {
  298. &locale_2g_01_11,
  299. &locale_2g_12_13,
  300. &locale_2g_14,
  301. &locale_5g_LOW_JP1,
  302. &locale_5g_LOW_JP2,
  303. &locale_5g_LOW1,
  304. &locale_5g_LOW2,
  305. &locale_5g_LOW3,
  306. &locale_5g_MID1,
  307. &locale_5g_MID2,
  308. &locale_5g_MID3,
  309. &locale_5g_HIGH1,
  310. &locale_5g_HIGH2,
  311. &locale_5g_HIGH3,
  312. &locale_5g_52_140_ALL,
  313. &locale_5g_HIGH4
  314. };
  315. static void brcms_c_locale_add_channels(struct brcms_chanvec *target,
  316. const struct brcms_chanvec *channels)
  317. {
  318. u8 i;
  319. for (i = 0; i < sizeof(struct brcms_chanvec); i++)
  320. target->vec[i] |= channels->vec[i];
  321. }
  322. static void brcms_c_locale_get_channels(const struct locale_info *locale,
  323. struct brcms_chanvec *channels)
  324. {
  325. u8 i;
  326. memset(channels, 0, sizeof(struct brcms_chanvec));
  327. for (i = 0; i < ARRAY_SIZE(g_table_locale_base); i++) {
  328. if (locale->valid_channels & (1 << i))
  329. brcms_c_locale_add_channels(channels,
  330. g_table_locale_base[i]);
  331. }
  332. }
  333. /*
  334. * Locale Definitions - 2.4 GHz
  335. */
  336. static const struct locale_info locale_i = { /* locale i. channel 1 - 13 */
  337. LOCALE_CHAN_01_11 | LOCALE_CHAN_12_13,
  338. LOCALE_RESTRICTED_SET_2G_SHORT,
  339. {QDB(19), QDB(19), QDB(19),
  340. QDB(19), QDB(19), QDB(19)},
  341. BRCMS_EIRP
  342. };
  343. /*
  344. * Locale Definitions - 5 GHz
  345. */
  346. static const struct locale_info locale_11 = {
  347. /* locale 11. channel 36 - 48, 52 - 64, 100 - 140, 149 - 165 */
  348. LOCALE_CHAN_36_64 | LOCALE_CHAN_100_140 | LOCALE_CHAN_149_165,
  349. LOCALE_RESTRICTED_NONE,
  350. {QDB(21), QDB(21), QDB(21), QDB(21), QDB(21)},
  351. BRCMS_EIRP | BRCMS_DFS_EU
  352. };
  353. static const struct locale_info *g_locale_2g_table[] = {
  354. &locale_i
  355. };
  356. static const struct locale_info *g_locale_5g_table[] = {
  357. &locale_11
  358. };
  359. /*
  360. * MIMO Locale Definitions - 2.4 GHz
  361. */
  362. static const struct locale_mimo_info locale_bn = {
  363. {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  364. QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  365. QDB(13), QDB(13), QDB(13)},
  366. {0, 0, QDB(13), QDB(13), QDB(13),
  367. QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  368. QDB(13), 0, 0},
  369. 0
  370. };
  371. static const struct locale_mimo_info *g_mimo_2g_table[] = {
  372. &locale_bn
  373. };
  374. /*
  375. * MIMO Locale Definitions - 5 GHz
  376. */
  377. static const struct locale_mimo_info locale_11n = {
  378. { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
  379. {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
  380. 0
  381. };
  382. static const struct locale_mimo_info *g_mimo_5g_table[] = {
  383. &locale_11n
  384. };
  385. static const struct brcms_regd cntry_locales[] = {
  386. /* Worldwide RoW 2, must always be at index 0 */
  387. {
  388. .country = LOCALES(i, 11, bn, 11n),
  389. .regdomain = &brcms_regdom_x2,
  390. },
  391. };
  392. static const struct locale_info *brcms_c_get_locale_2g(u8 locale_idx)
  393. {
  394. if (locale_idx >= ARRAY_SIZE(g_locale_2g_table))
  395. return NULL; /* error condition */
  396. return g_locale_2g_table[locale_idx];
  397. }
  398. static const struct locale_info *brcms_c_get_locale_5g(u8 locale_idx)
  399. {
  400. if (locale_idx >= ARRAY_SIZE(g_locale_5g_table))
  401. return NULL; /* error condition */
  402. return g_locale_5g_table[locale_idx];
  403. }
  404. static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx)
  405. {
  406. if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table))
  407. return NULL;
  408. return g_mimo_2g_table[locale_idx];
  409. }
  410. static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx)
  411. {
  412. if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table))
  413. return NULL;
  414. return g_mimo_5g_table[locale_idx];
  415. }
  416. /*
  417. * Indicates whether the country provided is valid to pass
  418. * to cfg80211 or not.
  419. *
  420. * returns true if valid; false if not.
  421. */
  422. static bool brcms_c_country_valid(const char *ccode)
  423. {
  424. /*
  425. * only allow ascii alpha uppercase for the first 2
  426. * chars.
  427. */
  428. if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
  429. (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A &&
  430. ccode[2] == '\0'))
  431. return false;
  432. /*
  433. * do not match ISO 3166-1 user assigned country codes
  434. * that may be in the driver table
  435. */
  436. if (!strcmp("AA", ccode) || /* AA */
  437. !strcmp("ZZ", ccode) || /* ZZ */
  438. ccode[0] == 'X' || /* XA - XZ */
  439. (ccode[0] == 'Q' && /* QM - QZ */
  440. (ccode[1] >= 'M' && ccode[1] <= 'Z')))
  441. return false;
  442. if (!strcmp("NA", ccode))
  443. return false;
  444. return true;
  445. }
  446. static const struct brcms_regd *brcms_world_regd(const char *regdom, int len)
  447. {
  448. const struct brcms_regd *regd = NULL;
  449. int i;
  450. for (i = 0; i < ARRAY_SIZE(cntry_locales); i++) {
  451. if (!strncmp(regdom, cntry_locales[i].regdomain->alpha2, len)) {
  452. regd = &cntry_locales[i];
  453. break;
  454. }
  455. }
  456. return regd;
  457. }
  458. static const struct brcms_regd *brcms_default_world_regd(void)
  459. {
  460. return &cntry_locales[0];
  461. }
  462. /*
  463. * reset the quiet channels vector to the union
  464. * of the restricted and radar channel sets
  465. */
  466. static void brcms_c_quiet_channels_reset(struct brcms_cm_info *wlc_cm)
  467. {
  468. struct brcms_c_info *wlc = wlc_cm->wlc;
  469. uint i, j;
  470. struct brcms_band *band;
  471. const struct brcms_chanvec *chanvec;
  472. memset(&wlc_cm->quiet_channels, 0, sizeof(struct brcms_chanvec));
  473. band = wlc->band;
  474. for (i = 0; i < wlc->pub->_nbands;
  475. i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
  476. /* initialize quiet channels for restricted channels */
  477. chanvec = wlc_cm->bandstate[band->bandunit].restricted_channels;
  478. for (j = 0; j < sizeof(struct brcms_chanvec); j++)
  479. wlc_cm->quiet_channels.vec[j] |= chanvec->vec[j];
  480. }
  481. }
  482. /* Is the channel valid for the current locale and current band? */
  483. static bool brcms_c_valid_channel20(struct brcms_cm_info *wlc_cm, uint val)
  484. {
  485. struct brcms_c_info *wlc = wlc_cm->wlc;
  486. return ((val < MAXCHANNEL) &&
  487. isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec,
  488. val));
  489. }
  490. /* Is the channel valid for the current locale and specified band? */
  491. static bool brcms_c_valid_channel20_in_band(struct brcms_cm_info *wlc_cm,
  492. uint bandunit, uint val)
  493. {
  494. return ((val < MAXCHANNEL)
  495. && isset(wlc_cm->bandstate[bandunit].valid_channels.vec, val));
  496. }
  497. /* Is the channel valid for the current locale? (but don't consider channels not
  498. * available due to bandlocking)
  499. */
  500. static bool brcms_c_valid_channel20_db(struct brcms_cm_info *wlc_cm, uint val)
  501. {
  502. struct brcms_c_info *wlc = wlc_cm->wlc;
  503. return brcms_c_valid_channel20(wlc->cmi, val) ||
  504. (!wlc->bandlocked
  505. && brcms_c_valid_channel20_in_band(wlc->cmi,
  506. OTHERBANDUNIT(wlc), val));
  507. }
  508. /* JP, J1 - J10 are Japan ccodes */
  509. static bool brcms_c_japan_ccode(const char *ccode)
  510. {
  511. return (ccode[0] == 'J' &&
  512. (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
  513. }
  514. static void
  515. brcms_c_channel_min_txpower_limits_with_local_constraint(
  516. struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
  517. u8 local_constraint_qdbm)
  518. {
  519. int j;
  520. /* CCK Rates */
  521. for (j = 0; j < WL_TX_POWER_CCK_NUM; j++)
  522. txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
  523. /* 20 MHz Legacy OFDM SISO */
  524. for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++)
  525. txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
  526. /* 20 MHz Legacy OFDM CDD */
  527. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  528. txpwr->ofdm_cdd[j] =
  529. min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
  530. /* 40 MHz Legacy OFDM SISO */
  531. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  532. txpwr->ofdm_40_siso[j] =
  533. min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
  534. /* 40 MHz Legacy OFDM CDD */
  535. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  536. txpwr->ofdm_40_cdd[j] =
  537. min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
  538. /* 20MHz MCS 0-7 SISO */
  539. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  540. txpwr->mcs_20_siso[j] =
  541. min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
  542. /* 20MHz MCS 0-7 CDD */
  543. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  544. txpwr->mcs_20_cdd[j] =
  545. min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
  546. /* 20MHz MCS 0-7 STBC */
  547. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  548. txpwr->mcs_20_stbc[j] =
  549. min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
  550. /* 20MHz MCS 8-15 MIMO */
  551. for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
  552. txpwr->mcs_20_mimo[j] =
  553. min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
  554. /* 40MHz MCS 0-7 SISO */
  555. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  556. txpwr->mcs_40_siso[j] =
  557. min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
  558. /* 40MHz MCS 0-7 CDD */
  559. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  560. txpwr->mcs_40_cdd[j] =
  561. min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
  562. /* 40MHz MCS 0-7 STBC */
  563. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  564. txpwr->mcs_40_stbc[j] =
  565. min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
  566. /* 40MHz MCS 8-15 MIMO */
  567. for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
  568. txpwr->mcs_40_mimo[j] =
  569. min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
  570. /* 40MHz MCS 32 */
  571. txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
  572. }
  573. static int
  574. brcms_c_channels_init(struct brcms_cm_info *wlc_cm,
  575. const struct country_info *country)
  576. {
  577. struct brcms_c_info *wlc = wlc_cm->wlc;
  578. uint i, j;
  579. struct brcms_band *band;
  580. const struct locale_info *li;
  581. struct brcms_chanvec sup_chan;
  582. const struct locale_mimo_info *li_mimo;
  583. band = wlc->band;
  584. for (i = 0; i < wlc->pub->_nbands;
  585. i++, band = wlc->bandstate[OTHERBANDUNIT(wlc)]) {
  586. li = (band->bandtype == BRCM_BAND_5G) ?
  587. brcms_c_get_locale_5g(country->locale_5G) :
  588. brcms_c_get_locale_2g(country->locale_2G);
  589. wlc_cm->bandstate[band->bandunit].locale_flags = li->flags;
  590. li_mimo = (band->bandtype == BRCM_BAND_5G) ?
  591. brcms_c_get_mimo_5g(country->locale_mimo_5G) :
  592. brcms_c_get_mimo_2g(country->locale_mimo_2G);
  593. /* merge the mimo non-mimo locale flags */
  594. wlc_cm->bandstate[band->bandunit].locale_flags |=
  595. li_mimo->flags;
  596. wlc_cm->bandstate[band->bandunit].restricted_channels =
  597. g_table_restricted_chan[li->restricted_channels];
  598. /*
  599. * set the channel availability, masking out the channels
  600. * that may not be supported on this phy.
  601. */
  602. wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
  603. &sup_chan);
  604. brcms_c_locale_get_channels(li,
  605. &wlc_cm->bandstate[band->bandunit].
  606. valid_channels);
  607. for (j = 0; j < sizeof(struct brcms_chanvec); j++)
  608. wlc_cm->bandstate[band->bandunit].valid_channels.
  609. vec[j] &= sup_chan.vec[j];
  610. }
  611. brcms_c_quiet_channels_reset(wlc_cm);
  612. return 0;
  613. }
  614. /*
  615. * set the driver's current country and regulatory information
  616. * using a country code as the source. Look up built in country
  617. * information found with the country code.
  618. */
  619. static void
  620. brcms_c_set_country(struct brcms_cm_info *wlc_cm,
  621. const struct brcms_regd *regd)
  622. {
  623. const struct country_info *country = &regd->country;
  624. const struct locale_info *locale;
  625. struct brcms_c_info *wlc = wlc_cm->wlc;
  626. if ((wlc->pub->_n_enab & SUPPORT_11N) !=
  627. wlc->protection->nmode_user)
  628. brcms_c_set_nmode(wlc);
  629. brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
  630. brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
  631. /* set or restore gmode as required by regulatory */
  632. locale = brcms_c_get_locale_2g(country->locale_2G);
  633. if (locale && (locale->flags & BRCMS_NO_OFDM))
  634. brcms_c_set_gmode(wlc, GMODE_LEGACY_B, false);
  635. else
  636. brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
  637. brcms_c_channels_init(wlc_cm, country);
  638. return;
  639. }
  640. struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
  641. {
  642. struct brcms_cm_info *wlc_cm;
  643. struct brcms_pub *pub = wlc->pub;
  644. struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
  645. const char *ccode = sprom->alpha2;
  646. int ccode_len = sizeof(sprom->alpha2);
  647. BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
  648. wlc_cm = kzalloc(sizeof(struct brcms_cm_info), GFP_ATOMIC);
  649. if (wlc_cm == NULL)
  650. return NULL;
  651. wlc_cm->pub = pub;
  652. wlc_cm->wlc = wlc;
  653. wlc->cmi = wlc_cm;
  654. /* store the country code for passing up as a regulatory hint */
  655. wlc_cm->world_regd = brcms_world_regd(ccode, ccode_len);
  656. if (brcms_c_country_valid(ccode))
  657. strncpy(wlc->pub->srom_ccode, ccode, ccode_len);
  658. /*
  659. * If no custom world domain is found in the SROM, use the
  660. * default "X2" domain.
  661. */
  662. if (!wlc_cm->world_regd) {
  663. wlc_cm->world_regd = brcms_default_world_regd();
  664. ccode = wlc_cm->world_regd->regdomain->alpha2;
  665. ccode_len = BRCM_CNTRY_BUF_SZ - 1;
  666. }
  667. /* save default country for exiting 11d regulatory mode */
  668. strncpy(wlc->country_default, ccode, ccode_len);
  669. /* initialize autocountry_default to driver default */
  670. strncpy(wlc->autocountry_default, ccode, ccode_len);
  671. brcms_c_set_country(wlc_cm, wlc_cm->world_regd);
  672. return wlc_cm;
  673. }
  674. void brcms_c_channel_mgr_detach(struct brcms_cm_info *wlc_cm)
  675. {
  676. kfree(wlc_cm);
  677. }
  678. u8
  679. brcms_c_channel_locale_flags_in_band(struct brcms_cm_info *wlc_cm,
  680. uint bandunit)
  681. {
  682. return wlc_cm->bandstate[bandunit].locale_flags;
  683. }
  684. static bool
  685. brcms_c_quiet_chanspec(struct brcms_cm_info *wlc_cm, u16 chspec)
  686. {
  687. return (wlc_cm->wlc->pub->_n_enab & SUPPORT_11N) &&
  688. CHSPEC_IS40(chspec) ?
  689. (isset(wlc_cm->quiet_channels.vec,
  690. lower_20_sb(CHSPEC_CHANNEL(chspec))) ||
  691. isset(wlc_cm->quiet_channels.vec,
  692. upper_20_sb(CHSPEC_CHANNEL(chspec)))) :
  693. isset(wlc_cm->quiet_channels.vec, CHSPEC_CHANNEL(chspec));
  694. }
  695. void
  696. brcms_c_channel_set_chanspec(struct brcms_cm_info *wlc_cm, u16 chanspec,
  697. u8 local_constraint_qdbm)
  698. {
  699. struct brcms_c_info *wlc = wlc_cm->wlc;
  700. struct txpwr_limits txpwr;
  701. brcms_c_channel_reg_limits(wlc_cm, chanspec, &txpwr);
  702. brcms_c_channel_min_txpower_limits_with_local_constraint(
  703. wlc_cm, &txpwr, local_constraint_qdbm
  704. );
  705. brcms_b_set_chanspec(wlc->hw, chanspec,
  706. (brcms_c_quiet_chanspec(wlc_cm, chanspec) != 0),
  707. &txpwr);
  708. }
  709. void
  710. brcms_c_channel_reg_limits(struct brcms_cm_info *wlc_cm, u16 chanspec,
  711. struct txpwr_limits *txpwr)
  712. {
  713. struct brcms_c_info *wlc = wlc_cm->wlc;
  714. uint i;
  715. uint chan;
  716. int maxpwr;
  717. int delta;
  718. const struct country_info *country;
  719. struct brcms_band *band;
  720. const struct locale_info *li;
  721. int conducted_max = BRCMS_TXPWR_MAX;
  722. int conducted_ofdm_max = BRCMS_TXPWR_MAX;
  723. const struct locale_mimo_info *li_mimo;
  724. int maxpwr20, maxpwr40;
  725. int maxpwr_idx;
  726. uint j;
  727. memset(txpwr, 0, sizeof(struct txpwr_limits));
  728. country = &wlc_cm->world_regd->country;
  729. chan = CHSPEC_CHANNEL(chanspec);
  730. band = wlc->bandstate[chspec_bandunit(chanspec)];
  731. li = (band->bandtype == BRCM_BAND_5G) ?
  732. brcms_c_get_locale_5g(country->locale_5G) :
  733. brcms_c_get_locale_2g(country->locale_2G);
  734. li_mimo = (band->bandtype == BRCM_BAND_5G) ?
  735. brcms_c_get_mimo_5g(country->locale_mimo_5G) :
  736. brcms_c_get_mimo_2g(country->locale_mimo_2G);
  737. if (li->flags & BRCMS_EIRP) {
  738. delta = band->antgain;
  739. } else {
  740. delta = 0;
  741. if (band->antgain > QDB(6))
  742. delta = band->antgain - QDB(6); /* Excess over 6 dB */
  743. }
  744. if (li == &locale_i) {
  745. conducted_max = QDB(22);
  746. conducted_ofdm_max = QDB(22);
  747. }
  748. /* CCK txpwr limits for 2.4G band */
  749. if (band->bandtype == BRCM_BAND_2G) {
  750. maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_CCK(chan)];
  751. maxpwr = maxpwr - delta;
  752. maxpwr = max(maxpwr, 0);
  753. maxpwr = min(maxpwr, conducted_max);
  754. for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
  755. txpwr->cck[i] = (u8) maxpwr;
  756. }
  757. /* OFDM txpwr limits for 2.4G or 5G bands */
  758. if (band->bandtype == BRCM_BAND_2G)
  759. maxpwr = li->maxpwr[CHANNEL_POWER_IDX_2G_OFDM(chan)];
  760. else
  761. maxpwr = li->maxpwr[CHANNEL_POWER_IDX_5G(chan)];
  762. maxpwr = maxpwr - delta;
  763. maxpwr = max(maxpwr, 0);
  764. maxpwr = min(maxpwr, conducted_ofdm_max);
  765. /* Keep OFDM lmit below CCK limit */
  766. if (band->bandtype == BRCM_BAND_2G)
  767. maxpwr = min_t(int, maxpwr, txpwr->cck[0]);
  768. for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++)
  769. txpwr->ofdm[i] = (u8) maxpwr;
  770. for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++) {
  771. /*
  772. * OFDM 40 MHz SISO has the same power as the corresponding
  773. * MCS0-7 rate unless overriden by the locale specific code.
  774. * We set this value to 0 as a flag (presumably 0 dBm isn't
  775. * a possibility) and then copy the MCS0-7 value to the 40 MHz
  776. * value if it wasn't explicitly set.
  777. */
  778. txpwr->ofdm_40_siso[i] = 0;
  779. txpwr->ofdm_cdd[i] = (u8) maxpwr;
  780. txpwr->ofdm_40_cdd[i] = 0;
  781. }
  782. /* MIMO/HT specific limits */
  783. if (li_mimo->flags & BRCMS_EIRP) {
  784. delta = band->antgain;
  785. } else {
  786. delta = 0;
  787. if (band->antgain > QDB(6))
  788. delta = band->antgain - QDB(6); /* Excess over 6 dB */
  789. }
  790. if (band->bandtype == BRCM_BAND_2G)
  791. maxpwr_idx = (chan - 1);
  792. else
  793. maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
  794. maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
  795. maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
  796. maxpwr20 = maxpwr20 - delta;
  797. maxpwr20 = max(maxpwr20, 0);
  798. maxpwr40 = maxpwr40 - delta;
  799. maxpwr40 = max(maxpwr40, 0);
  800. /* Fill in the MCS 0-7 (SISO) rates */
  801. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  802. /*
  803. * 20 MHz has the same power as the corresponding OFDM rate
  804. * unless overriden by the locale specific code.
  805. */
  806. txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
  807. txpwr->mcs_40_siso[i] = 0;
  808. }
  809. /* Fill in the MCS 0-7 CDD rates */
  810. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  811. txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
  812. txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
  813. }
  814. /*
  815. * These locales have SISO expressed in the
  816. * table and override CDD later
  817. */
  818. if (li_mimo == &locale_bn) {
  819. if (li_mimo == &locale_bn) {
  820. maxpwr20 = QDB(16);
  821. maxpwr40 = 0;
  822. if (chan >= 3 && chan <= 11)
  823. maxpwr40 = QDB(16);
  824. }
  825. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  826. txpwr->mcs_20_siso[i] = (u8) maxpwr20;
  827. txpwr->mcs_40_siso[i] = (u8) maxpwr40;
  828. }
  829. }
  830. /* Fill in the MCS 0-7 STBC rates */
  831. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  832. txpwr->mcs_20_stbc[i] = 0;
  833. txpwr->mcs_40_stbc[i] = 0;
  834. }
  835. /* Fill in the MCS 8-15 SDM rates */
  836. for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++) {
  837. txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
  838. txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
  839. }
  840. /* Fill in MCS32 */
  841. txpwr->mcs32 = (u8) maxpwr40;
  842. for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
  843. if (txpwr->ofdm_40_cdd[i] == 0)
  844. txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
  845. if (i == 0) {
  846. i = i + 1;
  847. if (txpwr->ofdm_40_cdd[i] == 0)
  848. txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
  849. }
  850. }
  851. /*
  852. * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
  853. * value if it wasn't provided explicitly.
  854. */
  855. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  856. if (txpwr->mcs_40_siso[i] == 0)
  857. txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
  858. }
  859. for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
  860. if (txpwr->ofdm_40_siso[i] == 0)
  861. txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
  862. if (i == 0) {
  863. i = i + 1;
  864. if (txpwr->ofdm_40_siso[i] == 0)
  865. txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
  866. }
  867. }
  868. /*
  869. * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
  870. * STBC values if they weren't provided explicitly.
  871. */
  872. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  873. if (txpwr->mcs_20_stbc[i] == 0)
  874. txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
  875. if (txpwr->mcs_40_stbc[i] == 0)
  876. txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
  877. }
  878. return;
  879. }
  880. /*
  881. * Verify the chanspec is using a legal set of parameters, i.e. that the
  882. * chanspec specified a band, bw, ctl_sb and channel and that the
  883. * combination could be legal given any set of circumstances.
  884. * RETURNS: true is the chanspec is malformed, false if it looks good.
  885. */
  886. static bool brcms_c_chspec_malformed(u16 chanspec)
  887. {
  888. /* must be 2G or 5G band */
  889. if (!CHSPEC_IS5G(chanspec) && !CHSPEC_IS2G(chanspec))
  890. return true;
  891. /* must be 20 or 40 bandwidth */
  892. if (!CHSPEC_IS40(chanspec) && !CHSPEC_IS20(chanspec))
  893. return true;
  894. /* 20MHZ b/w must have no ctl sb, 40 must have a ctl sb */
  895. if (CHSPEC_IS20(chanspec)) {
  896. if (!CHSPEC_SB_NONE(chanspec))
  897. return true;
  898. } else if (!CHSPEC_SB_UPPER(chanspec) && !CHSPEC_SB_LOWER(chanspec)) {
  899. return true;
  900. }
  901. return false;
  902. }
  903. /*
  904. * Validate the chanspec for this locale, for 40MHZ we need to also
  905. * check that the sidebands are valid 20MZH channels in this locale
  906. * and they are also a legal HT combination
  907. */
  908. static bool
  909. brcms_c_valid_chanspec_ext(struct brcms_cm_info *wlc_cm, u16 chspec,
  910. bool dualband)
  911. {
  912. struct brcms_c_info *wlc = wlc_cm->wlc;
  913. u8 channel = CHSPEC_CHANNEL(chspec);
  914. /* check the chanspec */
  915. if (brcms_c_chspec_malformed(chspec)) {
  916. wiphy_err(wlc->wiphy, "wl%d: malformed chanspec 0x%x\n",
  917. wlc->pub->unit, chspec);
  918. return false;
  919. }
  920. if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
  921. chspec_bandunit(chspec))
  922. return false;
  923. /* Check a 20Mhz channel */
  924. if (CHSPEC_IS20(chspec)) {
  925. if (dualband)
  926. return brcms_c_valid_channel20_db(wlc_cm->wlc->cmi,
  927. channel);
  928. else
  929. return brcms_c_valid_channel20(wlc_cm->wlc->cmi,
  930. channel);
  931. }
  932. return false;
  933. }
  934. bool brcms_c_valid_chanspec_db(struct brcms_cm_info *wlc_cm, u16 chspec)
  935. {
  936. return brcms_c_valid_chanspec_ext(wlc_cm, chspec, true);
  937. }
  938. static bool brcms_is_radar_freq(u16 center_freq)
  939. {
  940. return center_freq >= 5260 && center_freq <= 5700;
  941. }
  942. static void brcms_reg_apply_radar_flags(struct wiphy *wiphy)
  943. {
  944. struct ieee80211_supported_band *sband;
  945. struct ieee80211_channel *ch;
  946. int i;
  947. sband = wiphy->bands[IEEE80211_BAND_5GHZ];
  948. if (!sband)
  949. return;
  950. for (i = 0; i < sband->n_channels; i++) {
  951. ch = &sband->channels[i];
  952. if (!brcms_is_radar_freq(ch->center_freq))
  953. continue;
  954. /*
  955. * All channels in this range should be passive and have
  956. * DFS enabled.
  957. */
  958. if (!(ch->flags & IEEE80211_CHAN_DISABLED))
  959. ch->flags |= IEEE80211_CHAN_RADAR |
  960. IEEE80211_CHAN_NO_IBSS |
  961. IEEE80211_CHAN_PASSIVE_SCAN;
  962. }
  963. }
  964. static void
  965. brcms_reg_apply_beaconing_flags(struct wiphy *wiphy,
  966. enum nl80211_reg_initiator initiator)
  967. {
  968. struct ieee80211_supported_band *sband;
  969. struct ieee80211_channel *ch;
  970. const struct ieee80211_reg_rule *rule;
  971. int band, i, ret;
  972. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  973. sband = wiphy->bands[band];
  974. if (!sband)
  975. continue;
  976. for (i = 0; i < sband->n_channels; i++) {
  977. ch = &sband->channels[i];
  978. if (ch->flags &
  979. (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_RADAR))
  980. continue;
  981. if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
  982. ret = freq_reg_info(wiphy, ch->center_freq,
  983. 0, &rule);
  984. if (ret)
  985. continue;
  986. if (!(rule->flags & NL80211_RRF_NO_IBSS))
  987. ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
  988. if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
  989. ch->flags &=
  990. ~IEEE80211_CHAN_PASSIVE_SCAN;
  991. } else if (ch->beacon_found) {
  992. ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
  993. IEEE80211_CHAN_PASSIVE_SCAN);
  994. }
  995. }
  996. }
  997. }
  998. static int brcms_reg_notifier(struct wiphy *wiphy,
  999. struct regulatory_request *request)
  1000. {
  1001. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1002. struct brcms_info *wl = hw->priv;
  1003. struct brcms_c_info *wlc = wl->wlc;
  1004. struct ieee80211_supported_band *sband;
  1005. struct ieee80211_channel *ch;
  1006. int band, i;
  1007. bool ch_found = false;
  1008. brcms_reg_apply_radar_flags(wiphy);
  1009. if (request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
  1010. brcms_reg_apply_beaconing_flags(wiphy, request->initiator);
  1011. /* Disable radio if all channels disallowed by regulatory */
  1012. for (band = 0; !ch_found && band < IEEE80211_NUM_BANDS; band++) {
  1013. sband = wiphy->bands[band];
  1014. if (!sband)
  1015. continue;
  1016. for (i = 0; !ch_found && i < sband->n_channels; i++) {
  1017. ch = &sband->channels[i];
  1018. if (!(ch->flags & IEEE80211_CHAN_DISABLED))
  1019. ch_found = true;
  1020. }
  1021. }
  1022. if (ch_found) {
  1023. mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
  1024. } else {
  1025. mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
  1026. wiphy_err(wlc->wiphy, "wl%d: %s: no valid channel for \"%s\"\n",
  1027. wlc->pub->unit, __func__, request->alpha2);
  1028. }
  1029. if (wlc->pub->_nbands > 1 || wlc->band->bandtype == BRCM_BAND_2G)
  1030. wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
  1031. brcms_c_japan_ccode(request->alpha2));
  1032. return 0;
  1033. }
  1034. void brcms_c_regd_init(struct brcms_c_info *wlc)
  1035. {
  1036. struct wiphy *wiphy = wlc->wiphy;
  1037. const struct brcms_regd *regd = wlc->cmi->world_regd;
  1038. struct ieee80211_supported_band *sband;
  1039. struct ieee80211_channel *ch;
  1040. struct brcms_chanvec sup_chan;
  1041. struct brcms_band *band;
  1042. int band_idx, i;
  1043. /* Disable any channels not supported by the phy */
  1044. for (band_idx = 0; band_idx < IEEE80211_NUM_BANDS; band_idx++) {
  1045. if (band_idx == IEEE80211_BAND_2GHZ)
  1046. band = wlc->bandstate[BAND_2G_INDEX];
  1047. else
  1048. band = wlc->bandstate[BAND_5G_INDEX];
  1049. wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
  1050. &sup_chan);
  1051. sband = wiphy->bands[band_idx];
  1052. for (i = 0; i < sband->n_channels; i++) {
  1053. ch = &sband->channels[i];
  1054. if (!isset(sup_chan.vec, ch->hw_value))
  1055. ch->flags |= IEEE80211_CHAN_DISABLED;
  1056. }
  1057. }
  1058. wlc->wiphy->reg_notifier = brcms_reg_notifier;
  1059. wlc->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  1060. WIPHY_FLAG_STRICT_REGULATORY;
  1061. wiphy_apply_custom_regulatory(wlc->wiphy, regd->regdomain);
  1062. brcms_reg_apply_beaconing_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER);
  1063. }