channel.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. #include "debug.h"
  28. /* QDB() macro takes a dB value and converts to a quarter dB value */
  29. #define QDB(n) ((n) * BRCMS_TXPWR_DB_FACTOR)
  30. #define LOCALE_MIMO_IDX_bn 0
  31. #define LOCALE_MIMO_IDX_11n 0
  32. /* max of BAND_5G_PWR_LVLS and 14 for 2.4 GHz */
  33. #define BRCMS_MAXPWR_MIMO_TBL_SIZE 14
  34. /* maxpwr mapping to 5GHz band channels:
  35. * maxpwr[0] - channels [34-48]
  36. * maxpwr[1] - channels [52-60]
  37. * maxpwr[2] - channels [62-64]
  38. * maxpwr[3] - channels [100-140]
  39. * maxpwr[4] - channels [149-165]
  40. */
  41. #define BAND_5G_PWR_LVLS 5 /* 5 power levels for 5G */
  42. #define LC(id) LOCALE_MIMO_IDX_ ## id
  43. #define LOCALES(mimo2, mimo5) \
  44. {LC(mimo2), LC(mimo5)}
  45. /* macro to get 5 GHz channel group index for tx power */
  46. #define CHANNEL_POWER_IDX_5G(c) (((c) < 52) ? 0 : \
  47. (((c) < 62) ? 1 : \
  48. (((c) < 100) ? 2 : \
  49. (((c) < 149) ? 3 : 4))))
  50. #define BRCM_2GHZ_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 19, 0)
  51. #define BRCM_2GHZ_2467_2472 REG_RULE(2467-10, 2472+10, 20, 0, 19, \
  52. NL80211_RRF_PASSIVE_SCAN | \
  53. NL80211_RRF_NO_IBSS)
  54. #define BRCM_5GHZ_5180_5240 REG_RULE(5180-10, 5240+10, 40, 0, 21, \
  55. NL80211_RRF_PASSIVE_SCAN | \
  56. NL80211_RRF_NO_IBSS)
  57. #define BRCM_5GHZ_5260_5320 REG_RULE(5260-10, 5320+10, 40, 0, 21, \
  58. NL80211_RRF_PASSIVE_SCAN | \
  59. NL80211_RRF_DFS | \
  60. NL80211_RRF_NO_IBSS)
  61. #define BRCM_5GHZ_5500_5700 REG_RULE(5500-10, 5700+10, 40, 0, 21, \
  62. NL80211_RRF_PASSIVE_SCAN | \
  63. NL80211_RRF_DFS | \
  64. NL80211_RRF_NO_IBSS)
  65. #define BRCM_5GHZ_5745_5825 REG_RULE(5745-10, 5825+10, 40, 0, 21, \
  66. NL80211_RRF_PASSIVE_SCAN | \
  67. NL80211_RRF_NO_IBSS)
  68. static const struct ieee80211_regdomain brcms_regdom_x2 = {
  69. .n_reg_rules = 6,
  70. .alpha2 = "X2",
  71. .reg_rules = {
  72. BRCM_2GHZ_2412_2462,
  73. BRCM_2GHZ_2467_2472,
  74. BRCM_5GHZ_5180_5240,
  75. BRCM_5GHZ_5260_5320,
  76. BRCM_5GHZ_5500_5700,
  77. BRCM_5GHZ_5745_5825,
  78. }
  79. };
  80. /* locale per-channel tx power limits for MIMO frames
  81. * maxpwr arrays are index by channel for 2.4 GHz limits, and
  82. * by sub-band for 5 GHz limits using CHANNEL_POWER_IDX_5G(channel)
  83. */
  84. struct locale_mimo_info {
  85. /* tx 20 MHz power limits, qdBm units */
  86. s8 maxpwr20[BRCMS_MAXPWR_MIMO_TBL_SIZE];
  87. /* tx 40 MHz power limits, qdBm units */
  88. s8 maxpwr40[BRCMS_MAXPWR_MIMO_TBL_SIZE];
  89. };
  90. /* Country names and abbreviations with locale defined from ISO 3166 */
  91. struct country_info {
  92. const u8 locale_mimo_2G; /* 2.4G mimo info */
  93. const u8 locale_mimo_5G; /* 5G mimo info */
  94. };
  95. struct brcms_regd {
  96. struct country_info country;
  97. const struct ieee80211_regdomain *regdomain;
  98. };
  99. struct brcms_cm_info {
  100. struct brcms_pub *pub;
  101. struct brcms_c_info *wlc;
  102. const struct brcms_regd *world_regd;
  103. };
  104. /*
  105. * MIMO Locale Definitions - 2.4 GHz
  106. */
  107. static const struct locale_mimo_info locale_bn = {
  108. {QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  109. QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  110. QDB(13), QDB(13), QDB(13)},
  111. {0, 0, QDB(13), QDB(13), QDB(13),
  112. QDB(13), QDB(13), QDB(13), QDB(13), QDB(13),
  113. QDB(13), 0, 0},
  114. };
  115. static const struct locale_mimo_info *g_mimo_2g_table[] = {
  116. &locale_bn
  117. };
  118. /*
  119. * MIMO Locale Definitions - 5 GHz
  120. */
  121. static const struct locale_mimo_info locale_11n = {
  122. { /* 12.5 dBm */ 50, 50, 50, QDB(15), QDB(15)},
  123. {QDB(14), QDB(15), QDB(15), QDB(15), QDB(15)},
  124. };
  125. static const struct locale_mimo_info *g_mimo_5g_table[] = {
  126. &locale_11n
  127. };
  128. static const struct brcms_regd cntry_locales[] = {
  129. /* Worldwide RoW 2, must always be at index 0 */
  130. {
  131. .country = LOCALES(bn, 11n),
  132. .regdomain = &brcms_regdom_x2,
  133. },
  134. };
  135. static const struct locale_mimo_info *brcms_c_get_mimo_2g(u8 locale_idx)
  136. {
  137. if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table))
  138. return NULL;
  139. return g_mimo_2g_table[locale_idx];
  140. }
  141. static const struct locale_mimo_info *brcms_c_get_mimo_5g(u8 locale_idx)
  142. {
  143. if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table))
  144. return NULL;
  145. return g_mimo_5g_table[locale_idx];
  146. }
  147. /*
  148. * Indicates whether the country provided is valid to pass
  149. * to cfg80211 or not.
  150. *
  151. * returns true if valid; false if not.
  152. */
  153. static bool brcms_c_country_valid(const char *ccode)
  154. {
  155. /*
  156. * only allow ascii alpha uppercase for the first 2
  157. * chars.
  158. */
  159. if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
  160. (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A))
  161. return false;
  162. /*
  163. * do not match ISO 3166-1 user assigned country codes
  164. * that may be in the driver table
  165. */
  166. if (!strcmp("AA", ccode) || /* AA */
  167. !strcmp("ZZ", ccode) || /* ZZ */
  168. ccode[0] == 'X' || /* XA - XZ */
  169. (ccode[0] == 'Q' && /* QM - QZ */
  170. (ccode[1] >= 'M' && ccode[1] <= 'Z')))
  171. return false;
  172. if (!strcmp("NA", ccode))
  173. return false;
  174. return true;
  175. }
  176. static const struct brcms_regd *brcms_world_regd(const char *regdom, int len)
  177. {
  178. const struct brcms_regd *regd = NULL;
  179. int i;
  180. for (i = 0; i < ARRAY_SIZE(cntry_locales); i++) {
  181. if (!strncmp(regdom, cntry_locales[i].regdomain->alpha2, len)) {
  182. regd = &cntry_locales[i];
  183. break;
  184. }
  185. }
  186. return regd;
  187. }
  188. static const struct brcms_regd *brcms_default_world_regd(void)
  189. {
  190. return &cntry_locales[0];
  191. }
  192. /* JP, J1 - J10 are Japan ccodes */
  193. static bool brcms_c_japan_ccode(const char *ccode)
  194. {
  195. return (ccode[0] == 'J' &&
  196. (ccode[1] == 'P' || (ccode[1] >= '1' && ccode[1] <= '9')));
  197. }
  198. static void
  199. brcms_c_channel_min_txpower_limits_with_local_constraint(
  200. struct brcms_cm_info *wlc_cm, struct txpwr_limits *txpwr,
  201. u8 local_constraint_qdbm)
  202. {
  203. int j;
  204. /* CCK Rates */
  205. for (j = 0; j < WL_TX_POWER_CCK_NUM; j++)
  206. txpwr->cck[j] = min(txpwr->cck[j], local_constraint_qdbm);
  207. /* 20 MHz Legacy OFDM SISO */
  208. for (j = 0; j < WL_TX_POWER_OFDM_NUM; j++)
  209. txpwr->ofdm[j] = min(txpwr->ofdm[j], local_constraint_qdbm);
  210. /* 20 MHz Legacy OFDM CDD */
  211. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  212. txpwr->ofdm_cdd[j] =
  213. min(txpwr->ofdm_cdd[j], local_constraint_qdbm);
  214. /* 40 MHz Legacy OFDM SISO */
  215. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  216. txpwr->ofdm_40_siso[j] =
  217. min(txpwr->ofdm_40_siso[j], local_constraint_qdbm);
  218. /* 40 MHz Legacy OFDM CDD */
  219. for (j = 0; j < BRCMS_NUM_RATES_OFDM; j++)
  220. txpwr->ofdm_40_cdd[j] =
  221. min(txpwr->ofdm_40_cdd[j], local_constraint_qdbm);
  222. /* 20MHz MCS 0-7 SISO */
  223. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  224. txpwr->mcs_20_siso[j] =
  225. min(txpwr->mcs_20_siso[j], local_constraint_qdbm);
  226. /* 20MHz MCS 0-7 CDD */
  227. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  228. txpwr->mcs_20_cdd[j] =
  229. min(txpwr->mcs_20_cdd[j], local_constraint_qdbm);
  230. /* 20MHz MCS 0-7 STBC */
  231. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  232. txpwr->mcs_20_stbc[j] =
  233. min(txpwr->mcs_20_stbc[j], local_constraint_qdbm);
  234. /* 20MHz MCS 8-15 MIMO */
  235. for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
  236. txpwr->mcs_20_mimo[j] =
  237. min(txpwr->mcs_20_mimo[j], local_constraint_qdbm);
  238. /* 40MHz MCS 0-7 SISO */
  239. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  240. txpwr->mcs_40_siso[j] =
  241. min(txpwr->mcs_40_siso[j], local_constraint_qdbm);
  242. /* 40MHz MCS 0-7 CDD */
  243. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  244. txpwr->mcs_40_cdd[j] =
  245. min(txpwr->mcs_40_cdd[j], local_constraint_qdbm);
  246. /* 40MHz MCS 0-7 STBC */
  247. for (j = 0; j < BRCMS_NUM_RATES_MCS_1_STREAM; j++)
  248. txpwr->mcs_40_stbc[j] =
  249. min(txpwr->mcs_40_stbc[j], local_constraint_qdbm);
  250. /* 40MHz MCS 8-15 MIMO */
  251. for (j = 0; j < BRCMS_NUM_RATES_MCS_2_STREAM; j++)
  252. txpwr->mcs_40_mimo[j] =
  253. min(txpwr->mcs_40_mimo[j], local_constraint_qdbm);
  254. /* 40MHz MCS 32 */
  255. txpwr->mcs32 = min(txpwr->mcs32, local_constraint_qdbm);
  256. }
  257. /*
  258. * set the driver's current country and regulatory information
  259. * using a country code as the source. Look up built in country
  260. * information found with the country code.
  261. */
  262. static void
  263. brcms_c_set_country(struct brcms_cm_info *wlc_cm,
  264. const struct brcms_regd *regd)
  265. {
  266. struct brcms_c_info *wlc = wlc_cm->wlc;
  267. if ((wlc->pub->_n_enab & SUPPORT_11N) !=
  268. wlc->protection->nmode_user)
  269. brcms_c_set_nmode(wlc);
  270. brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_2G_INDEX]);
  271. brcms_c_stf_ss_update(wlc, wlc->bandstate[BAND_5G_INDEX]);
  272. brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
  273. return;
  274. }
  275. struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
  276. {
  277. struct brcms_cm_info *wlc_cm;
  278. struct brcms_pub *pub = wlc->pub;
  279. struct ssb_sprom *sprom = &wlc->hw->d11core->bus->sprom;
  280. const char *ccode = sprom->alpha2;
  281. int ccode_len = sizeof(sprom->alpha2);
  282. wlc_cm = kzalloc(sizeof(struct brcms_cm_info), GFP_ATOMIC);
  283. if (wlc_cm == NULL)
  284. return NULL;
  285. wlc_cm->pub = pub;
  286. wlc_cm->wlc = wlc;
  287. wlc->cmi = wlc_cm;
  288. /* store the country code for passing up as a regulatory hint */
  289. wlc_cm->world_regd = brcms_world_regd(ccode, ccode_len);
  290. if (brcms_c_country_valid(ccode))
  291. strncpy(wlc->pub->srom_ccode, ccode, ccode_len);
  292. /*
  293. * If no custom world domain is found in the SROM, use the
  294. * default "X2" domain.
  295. */
  296. if (!wlc_cm->world_regd) {
  297. wlc_cm->world_regd = brcms_default_world_regd();
  298. ccode = wlc_cm->world_regd->regdomain->alpha2;
  299. ccode_len = BRCM_CNTRY_BUF_SZ - 1;
  300. }
  301. /* save default country for exiting 11d regulatory mode */
  302. strncpy(wlc->country_default, ccode, ccode_len);
  303. /* initialize autocountry_default to driver default */
  304. strncpy(wlc->autocountry_default, ccode, ccode_len);
  305. brcms_c_set_country(wlc_cm, wlc_cm->world_regd);
  306. return wlc_cm;
  307. }
  308. void brcms_c_channel_mgr_detach(struct brcms_cm_info *wlc_cm)
  309. {
  310. kfree(wlc_cm);
  311. }
  312. void
  313. brcms_c_channel_set_chanspec(struct brcms_cm_info *wlc_cm, u16 chanspec,
  314. u8 local_constraint_qdbm)
  315. {
  316. struct brcms_c_info *wlc = wlc_cm->wlc;
  317. struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel;
  318. struct txpwr_limits txpwr;
  319. brcms_c_channel_reg_limits(wlc_cm, chanspec, &txpwr);
  320. brcms_c_channel_min_txpower_limits_with_local_constraint(
  321. wlc_cm, &txpwr, local_constraint_qdbm
  322. );
  323. /* set or restore gmode as required by regulatory */
  324. if (ch->flags & IEEE80211_CHAN_NO_OFDM)
  325. brcms_c_set_gmode(wlc, GMODE_LEGACY_B, false);
  326. else
  327. brcms_c_set_gmode(wlc, wlc->protection->gmode_user, false);
  328. brcms_b_set_chanspec(wlc->hw, chanspec,
  329. !!(ch->flags & IEEE80211_CHAN_PASSIVE_SCAN),
  330. &txpwr);
  331. }
  332. void
  333. brcms_c_channel_reg_limits(struct brcms_cm_info *wlc_cm, u16 chanspec,
  334. struct txpwr_limits *txpwr)
  335. {
  336. struct brcms_c_info *wlc = wlc_cm->wlc;
  337. struct ieee80211_channel *ch = wlc->pub->ieee_hw->conf.channel;
  338. uint i;
  339. uint chan;
  340. int maxpwr;
  341. int delta;
  342. const struct country_info *country;
  343. struct brcms_band *band;
  344. int conducted_max = BRCMS_TXPWR_MAX;
  345. const struct locale_mimo_info *li_mimo;
  346. int maxpwr20, maxpwr40;
  347. int maxpwr_idx;
  348. uint j;
  349. memset(txpwr, 0, sizeof(struct txpwr_limits));
  350. if (WARN_ON(!ch))
  351. return;
  352. country = &wlc_cm->world_regd->country;
  353. chan = CHSPEC_CHANNEL(chanspec);
  354. band = wlc->bandstate[chspec_bandunit(chanspec)];
  355. li_mimo = (band->bandtype == BRCM_BAND_5G) ?
  356. brcms_c_get_mimo_5g(country->locale_mimo_5G) :
  357. brcms_c_get_mimo_2g(country->locale_mimo_2G);
  358. delta = band->antgain;
  359. if (band->bandtype == BRCM_BAND_2G)
  360. conducted_max = QDB(22);
  361. maxpwr = QDB(ch->max_power) - delta;
  362. maxpwr = max(maxpwr, 0);
  363. maxpwr = min(maxpwr, conducted_max);
  364. /* CCK txpwr limits for 2.4G band */
  365. if (band->bandtype == BRCM_BAND_2G) {
  366. for (i = 0; i < BRCMS_NUM_RATES_CCK; i++)
  367. txpwr->cck[i] = (u8) maxpwr;
  368. }
  369. for (i = 0; i < BRCMS_NUM_RATES_OFDM; i++) {
  370. txpwr->ofdm[i] = (u8) maxpwr;
  371. /*
  372. * OFDM 40 MHz SISO has the same power as the corresponding
  373. * MCS0-7 rate unless overriden by the locale specific code.
  374. * We set this value to 0 as a flag (presumably 0 dBm isn't
  375. * a possibility) and then copy the MCS0-7 value to the 40 MHz
  376. * value if it wasn't explicitly set.
  377. */
  378. txpwr->ofdm_40_siso[i] = 0;
  379. txpwr->ofdm_cdd[i] = (u8) maxpwr;
  380. txpwr->ofdm_40_cdd[i] = 0;
  381. }
  382. delta = 0;
  383. if (band->antgain > QDB(6))
  384. delta = band->antgain - QDB(6); /* Excess over 6 dB */
  385. if (band->bandtype == BRCM_BAND_2G)
  386. maxpwr_idx = (chan - 1);
  387. else
  388. maxpwr_idx = CHANNEL_POWER_IDX_5G(chan);
  389. maxpwr20 = li_mimo->maxpwr20[maxpwr_idx];
  390. maxpwr40 = li_mimo->maxpwr40[maxpwr_idx];
  391. maxpwr20 = maxpwr20 - delta;
  392. maxpwr20 = max(maxpwr20, 0);
  393. maxpwr40 = maxpwr40 - delta;
  394. maxpwr40 = max(maxpwr40, 0);
  395. /* Fill in the MCS 0-7 (SISO) rates */
  396. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  397. /*
  398. * 20 MHz has the same power as the corresponding OFDM rate
  399. * unless overriden by the locale specific code.
  400. */
  401. txpwr->mcs_20_siso[i] = txpwr->ofdm[i];
  402. txpwr->mcs_40_siso[i] = 0;
  403. }
  404. /* Fill in the MCS 0-7 CDD rates */
  405. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  406. txpwr->mcs_20_cdd[i] = (u8) maxpwr20;
  407. txpwr->mcs_40_cdd[i] = (u8) maxpwr40;
  408. }
  409. /*
  410. * These locales have SISO expressed in the
  411. * table and override CDD later
  412. */
  413. if (li_mimo == &locale_bn) {
  414. if (li_mimo == &locale_bn) {
  415. maxpwr20 = QDB(16);
  416. maxpwr40 = 0;
  417. if (chan >= 3 && chan <= 11)
  418. maxpwr40 = QDB(16);
  419. }
  420. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  421. txpwr->mcs_20_siso[i] = (u8) maxpwr20;
  422. txpwr->mcs_40_siso[i] = (u8) maxpwr40;
  423. }
  424. }
  425. /* Fill in the MCS 0-7 STBC rates */
  426. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  427. txpwr->mcs_20_stbc[i] = 0;
  428. txpwr->mcs_40_stbc[i] = 0;
  429. }
  430. /* Fill in the MCS 8-15 SDM rates */
  431. for (i = 0; i < BRCMS_NUM_RATES_MCS_2_STREAM; i++) {
  432. txpwr->mcs_20_mimo[i] = (u8) maxpwr20;
  433. txpwr->mcs_40_mimo[i] = (u8) maxpwr40;
  434. }
  435. /* Fill in MCS32 */
  436. txpwr->mcs32 = (u8) maxpwr40;
  437. for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
  438. if (txpwr->ofdm_40_cdd[i] == 0)
  439. txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
  440. if (i == 0) {
  441. i = i + 1;
  442. if (txpwr->ofdm_40_cdd[i] == 0)
  443. txpwr->ofdm_40_cdd[i] = txpwr->mcs_40_cdd[j];
  444. }
  445. }
  446. /*
  447. * Copy the 40 MHZ MCS 0-7 CDD value to the 40 MHZ MCS 0-7 SISO
  448. * value if it wasn't provided explicitly.
  449. */
  450. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  451. if (txpwr->mcs_40_siso[i] == 0)
  452. txpwr->mcs_40_siso[i] = txpwr->mcs_40_cdd[i];
  453. }
  454. for (i = 0, j = 0; i < BRCMS_NUM_RATES_OFDM; i++, j++) {
  455. if (txpwr->ofdm_40_siso[i] == 0)
  456. txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
  457. if (i == 0) {
  458. i = i + 1;
  459. if (txpwr->ofdm_40_siso[i] == 0)
  460. txpwr->ofdm_40_siso[i] = txpwr->mcs_40_siso[j];
  461. }
  462. }
  463. /*
  464. * Copy the 20 and 40 MHz MCS0-7 CDD values to the corresponding
  465. * STBC values if they weren't provided explicitly.
  466. */
  467. for (i = 0; i < BRCMS_NUM_RATES_MCS_1_STREAM; i++) {
  468. if (txpwr->mcs_20_stbc[i] == 0)
  469. txpwr->mcs_20_stbc[i] = txpwr->mcs_20_cdd[i];
  470. if (txpwr->mcs_40_stbc[i] == 0)
  471. txpwr->mcs_40_stbc[i] = txpwr->mcs_40_cdd[i];
  472. }
  473. return;
  474. }
  475. /*
  476. * Verify the chanspec is using a legal set of parameters, i.e. that the
  477. * chanspec specified a band, bw, ctl_sb and channel and that the
  478. * combination could be legal given any set of circumstances.
  479. * RETURNS: true is the chanspec is malformed, false if it looks good.
  480. */
  481. static bool brcms_c_chspec_malformed(u16 chanspec)
  482. {
  483. /* must be 2G or 5G band */
  484. if (!CHSPEC_IS5G(chanspec) && !CHSPEC_IS2G(chanspec))
  485. return true;
  486. /* must be 20 or 40 bandwidth */
  487. if (!CHSPEC_IS40(chanspec) && !CHSPEC_IS20(chanspec))
  488. return true;
  489. /* 20MHZ b/w must have no ctl sb, 40 must have a ctl sb */
  490. if (CHSPEC_IS20(chanspec)) {
  491. if (!CHSPEC_SB_NONE(chanspec))
  492. return true;
  493. } else if (!CHSPEC_SB_UPPER(chanspec) && !CHSPEC_SB_LOWER(chanspec)) {
  494. return true;
  495. }
  496. return false;
  497. }
  498. /*
  499. * Validate the chanspec for this locale, for 40MHZ we need to also
  500. * check that the sidebands are valid 20MZH channels in this locale
  501. * and they are also a legal HT combination
  502. */
  503. static bool
  504. brcms_c_valid_chanspec_ext(struct brcms_cm_info *wlc_cm, u16 chspec)
  505. {
  506. struct brcms_c_info *wlc = wlc_cm->wlc;
  507. u8 channel = CHSPEC_CHANNEL(chspec);
  508. /* check the chanspec */
  509. if (brcms_c_chspec_malformed(chspec)) {
  510. brcms_err(wlc->hw->d11core, "wl%d: malformed chanspec 0x%x\n",
  511. wlc->pub->unit, chspec);
  512. return false;
  513. }
  514. if (CHANNEL_BANDUNIT(wlc_cm->wlc, channel) !=
  515. chspec_bandunit(chspec))
  516. return false;
  517. return true;
  518. }
  519. bool brcms_c_valid_chanspec_db(struct brcms_cm_info *wlc_cm, u16 chspec)
  520. {
  521. return brcms_c_valid_chanspec_ext(wlc_cm, chspec);
  522. }
  523. static bool brcms_is_radar_freq(u16 center_freq)
  524. {
  525. return center_freq >= 5260 && center_freq <= 5700;
  526. }
  527. static void brcms_reg_apply_radar_flags(struct wiphy *wiphy)
  528. {
  529. struct ieee80211_supported_band *sband;
  530. struct ieee80211_channel *ch;
  531. int i;
  532. sband = wiphy->bands[IEEE80211_BAND_5GHZ];
  533. if (!sband)
  534. return;
  535. for (i = 0; i < sband->n_channels; i++) {
  536. ch = &sband->channels[i];
  537. if (!brcms_is_radar_freq(ch->center_freq))
  538. continue;
  539. /*
  540. * All channels in this range should be passive and have
  541. * DFS enabled.
  542. */
  543. if (!(ch->flags & IEEE80211_CHAN_DISABLED))
  544. ch->flags |= IEEE80211_CHAN_RADAR |
  545. IEEE80211_CHAN_NO_IBSS |
  546. IEEE80211_CHAN_PASSIVE_SCAN;
  547. }
  548. }
  549. static void
  550. brcms_reg_apply_beaconing_flags(struct wiphy *wiphy,
  551. enum nl80211_reg_initiator initiator)
  552. {
  553. struct ieee80211_supported_band *sband;
  554. struct ieee80211_channel *ch;
  555. const struct ieee80211_reg_rule *rule;
  556. int band, i;
  557. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  558. sband = wiphy->bands[band];
  559. if (!sband)
  560. continue;
  561. for (i = 0; i < sband->n_channels; i++) {
  562. ch = &sband->channels[i];
  563. if (ch->flags &
  564. (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_RADAR))
  565. continue;
  566. if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
  567. rule = freq_reg_info(wiphy, ch->center_freq);
  568. if (IS_ERR(rule))
  569. continue;
  570. if (!(rule->flags & NL80211_RRF_NO_IBSS))
  571. ch->flags &= ~IEEE80211_CHAN_NO_IBSS;
  572. if (!(rule->flags & NL80211_RRF_PASSIVE_SCAN))
  573. ch->flags &=
  574. ~IEEE80211_CHAN_PASSIVE_SCAN;
  575. } else if (ch->beacon_found) {
  576. ch->flags &= ~(IEEE80211_CHAN_NO_IBSS |
  577. IEEE80211_CHAN_PASSIVE_SCAN);
  578. }
  579. }
  580. }
  581. }
  582. static void brcms_reg_notifier(struct wiphy *wiphy,
  583. struct regulatory_request *request)
  584. {
  585. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  586. struct brcms_info *wl = hw->priv;
  587. struct brcms_c_info *wlc = wl->wlc;
  588. struct ieee80211_supported_band *sband;
  589. struct ieee80211_channel *ch;
  590. int band, i;
  591. bool ch_found = false;
  592. brcms_reg_apply_radar_flags(wiphy);
  593. if (request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
  594. brcms_reg_apply_beaconing_flags(wiphy, request->initiator);
  595. /* Disable radio if all channels disallowed by regulatory */
  596. for (band = 0; !ch_found && band < IEEE80211_NUM_BANDS; band++) {
  597. sband = wiphy->bands[band];
  598. if (!sband)
  599. continue;
  600. for (i = 0; !ch_found && i < sband->n_channels; i++) {
  601. ch = &sband->channels[i];
  602. if (!(ch->flags & IEEE80211_CHAN_DISABLED))
  603. ch_found = true;
  604. }
  605. }
  606. if (ch_found) {
  607. mboolclr(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
  608. } else {
  609. mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
  610. brcms_err(wlc->hw->d11core,
  611. "wl%d: %s: no valid channel for \"%s\"\n",
  612. wlc->pub->unit, __func__, request->alpha2);
  613. }
  614. if (wlc->pub->_nbands > 1 || wlc->band->bandtype == BRCM_BAND_2G)
  615. wlc_phy_chanspec_ch14_widefilter_set(wlc->band->pi,
  616. brcms_c_japan_ccode(request->alpha2));
  617. }
  618. void brcms_c_regd_init(struct brcms_c_info *wlc)
  619. {
  620. struct wiphy *wiphy = wlc->wiphy;
  621. const struct brcms_regd *regd = wlc->cmi->world_regd;
  622. struct ieee80211_supported_band *sband;
  623. struct ieee80211_channel *ch;
  624. struct brcms_chanvec sup_chan;
  625. struct brcms_band *band;
  626. int band_idx, i;
  627. /* Disable any channels not supported by the phy */
  628. for (band_idx = 0; band_idx < wlc->pub->_nbands; band_idx++) {
  629. band = wlc->bandstate[band_idx];
  630. wlc_phy_chanspec_band_validch(band->pi, band->bandtype,
  631. &sup_chan);
  632. if (band_idx == BAND_2G_INDEX)
  633. sband = wiphy->bands[IEEE80211_BAND_2GHZ];
  634. else
  635. sband = wiphy->bands[IEEE80211_BAND_5GHZ];
  636. for (i = 0; i < sband->n_channels; i++) {
  637. ch = &sband->channels[i];
  638. if (!isset(sup_chan.vec, ch->hw_value))
  639. ch->flags |= IEEE80211_CHAN_DISABLED;
  640. }
  641. }
  642. wlc->wiphy->reg_notifier = brcms_reg_notifier;
  643. wlc->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  644. WIPHY_FLAG_STRICT_REGULATORY;
  645. wiphy_apply_custom_regulatory(wlc->wiphy, regd->regdomain);
  646. brcms_reg_apply_beaconing_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER);
  647. }