channel.c 34 KB

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