rtw_rf.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _RTW_RF_C_
  21. #include <drv_types.h>
  22. #include <hal_data.h>
  23. u8 center_ch_2g[CENTER_CH_2G_NUM] = {
  24. /* G00 */1, 2,
  25. /* G01 */3, 4, 5,
  26. /* G02 */6, 7, 8,
  27. /* G03 */9, 10, 11,
  28. /* G04 */12, 13,
  29. /* G05 */14
  30. };
  31. u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM] = {
  32. 3,
  33. 4,
  34. 5,
  35. 6,
  36. 7,
  37. 8,
  38. 9,
  39. 10,
  40. 11,
  41. };
  42. u8 op_chs_of_cch_2g_40m[CENTER_CH_2G_40M_NUM][2] = {
  43. {1, 5}, /* 3 */
  44. {2, 6}, /* 4 */
  45. {3, 7}, /* 5 */
  46. {4, 8}, /* 6 */
  47. {5, 9}, /* 7 */
  48. {6, 10}, /* 8 */
  49. {7, 11}, /* 9 */
  50. {8, 12}, /* 10 */
  51. {9, 13}, /* 11 */
  52. };
  53. u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM] = {
  54. /* G00 */36, 38, 40,
  55. 42,
  56. /* G01 */44, 46, 48,
  57. /* 50, */
  58. /* G02 */52, 54, 56,
  59. 58,
  60. /* G03 */60, 62, 64,
  61. /* G04 */100, 102, 104,
  62. 106,
  63. /* G05 */108, 110, 112,
  64. /* 114, */
  65. /* G06 */116, 118, 120,
  66. 122,
  67. /* G07 */124, 126, 128,
  68. /* G08 */132, 134, 136,
  69. 138,
  70. /* G09 */140, 142, 144,
  71. /* G10 */149, 151, 153,
  72. 155,
  73. /* G11 */157, 159, 161,
  74. /* 163, */
  75. /* G12 */165, 167, 169,
  76. 171,
  77. /* G13 */173, 175, 177
  78. };
  79. u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM] = {
  80. /* G00 */36, 40,
  81. /* G01 */44, 48,
  82. /* G02 */52, 56,
  83. /* G03 */60, 64,
  84. /* G04 */100, 104,
  85. /* G05 */108, 112,
  86. /* G06 */116, 120,
  87. /* G07 */124, 128,
  88. /* G08 */132, 136,
  89. /* G09 */140, 144,
  90. /* G10 */149, 153,
  91. /* G11 */157, 161,
  92. /* G12 */165, 169,
  93. /* G13 */173, 177
  94. };
  95. u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM] = {
  96. /* G00 */38,
  97. /* G01 */46,
  98. /* G02 */54,
  99. /* G03 */62,
  100. /* G04 */102,
  101. /* G05 */110,
  102. /* G06 */118,
  103. /* G07 */126,
  104. /* G08 */134,
  105. /* G09 */142,
  106. /* G10 */151,
  107. /* G11 */159,
  108. /* G12 */167,
  109. /* G13 */175
  110. };
  111. u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM] = {
  112. /* G00 */36, 38, 40,
  113. /* G01 */44, 46, 48,
  114. /* G02 */52, 54, 56,
  115. /* G03 */60, 62, 64,
  116. /* G04 */100, 102, 104,
  117. /* G05 */108, 110, 112,
  118. /* G06 */116, 118, 120,
  119. /* G07 */124, 126, 128,
  120. /* G08 */132, 134, 136,
  121. /* G09 */140, 142, 144,
  122. /* G10 */149, 151, 153,
  123. /* G11 */157, 159, 161,
  124. /* G12 */165, 167, 169,
  125. /* G13 */173, 175, 177
  126. };
  127. u8 op_chs_of_cch_5g_40m[CENTER_CH_5G_40M_NUM][2] = {
  128. {36, 40}, /* 38 */
  129. {44, 48}, /* 46 */
  130. {52, 56}, /* 54 */
  131. {60, 64}, /* 62 */
  132. {100, 104}, /* 102 */
  133. {108, 112}, /* 110 */
  134. {116, 120}, /* 118 */
  135. {124, 128}, /* 126 */
  136. {132, 136}, /* 134 */
  137. {140, 144}, /* 142 */
  138. {149, 153}, /* 151 */
  139. {157, 161}, /* 159 */
  140. {165, 169}, /* 167 */
  141. {173, 177}, /* 175 */
  142. };
  143. u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM] = {
  144. /* G00 ~ G01*/42,
  145. /* G02 ~ G03*/58,
  146. /* G04 ~ G05*/106,
  147. /* G06 ~ G07*/122,
  148. /* G08 ~ G09*/138,
  149. /* G10 ~ G11*/155,
  150. /* G12 ~ G13*/171
  151. };
  152. u8 op_chs_of_cch_5g_80m[CENTER_CH_5G_80M_NUM][4] = {
  153. {36, 40, 44, 48}, /* 42 */
  154. {52, 56, 60, 64}, /* 58 */
  155. {100, 104, 108, 112}, /* 106 */
  156. {116, 120, 124, 128}, /* 122 */
  157. {132, 136, 140, 144}, /* 138 */
  158. {149, 153, 157, 161}, /* 155 */
  159. {165, 169, 173, 177}, /* 171 */
  160. };
  161. u8 center_ch_5g_160m[CENTER_CH_5G_160M_NUM] = {
  162. /* G00 ~ G03*/50,
  163. /* G04 ~ G07*/114,
  164. /* G10 ~ G13*/163
  165. };
  166. u8 op_chs_of_cch_5g_160m[CENTER_CH_5G_160M_NUM][8] = {
  167. {36, 40, 44, 48, 52, 56, 60, 64}, /* 50 */
  168. {100, 104, 108, 112, 116, 120, 124, 128}, /* 114 */
  169. {149, 153, 157, 161, 165, 169, 173, 177}, /* 163 */
  170. };
  171. struct center_chs_ent_t {
  172. u8 ch_num;
  173. u8 *chs;
  174. };
  175. struct center_chs_ent_t center_chs_2g_by_bw[] = {
  176. {CENTER_CH_2G_NUM, center_ch_2g},
  177. {CENTER_CH_2G_40M_NUM, center_ch_2g_40m},
  178. };
  179. struct center_chs_ent_t center_chs_5g_by_bw[] = {
  180. {CENTER_CH_5G_20M_NUM, center_ch_5g_20m},
  181. {CENTER_CH_5G_40M_NUM, center_ch_5g_40m},
  182. {CENTER_CH_5G_80M_NUM, center_ch_5g_80m},
  183. {CENTER_CH_5G_160M_NUM, center_ch_5g_160m},
  184. };
  185. /*
  186. * Get center channel of smaller bandwidth by @param cch, @param bw, @param offset
  187. * @cch: the given center channel
  188. * @bw: the given bandwidth
  189. * @offset: the given primary SC offset of the given bandwidth
  190. *
  191. * return center channel of smaller bandiwdth if valid, or 0
  192. */
  193. u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset)
  194. {
  195. int i;
  196. u8 t_cch = 0;
  197. if (bw == CHANNEL_WIDTH_20) {
  198. t_cch = cch;
  199. goto exit;
  200. }
  201. if (offset == HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
  202. rtw_warn_on(1);
  203. goto exit;
  204. }
  205. /* 2.4G, 40MHz */
  206. if (cch >= 3 && cch <= 11 && bw == CHANNEL_WIDTH_40) {
  207. t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 2 : cch - 2;
  208. goto exit;
  209. }
  210. /* 5G, 160MHz */
  211. if (cch >= 50 && cch <= 163 && bw == CHANNEL_WIDTH_160) {
  212. t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 8 : cch - 8;
  213. goto exit;
  214. /* 5G, 80MHz */
  215. } else if (cch >= 42 && cch <= 171 && bw == CHANNEL_WIDTH_80) {
  216. t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 4 : cch - 4;
  217. goto exit;
  218. /* 5G, 40MHz */
  219. } else if (cch >= 38 && cch <= 175 && bw == CHANNEL_WIDTH_40) {
  220. t_cch = (offset == HAL_PRIME_CHNL_OFFSET_UPPER) ? cch + 2 : cch - 2;
  221. goto exit;
  222. } else {
  223. rtw_warn_on(1);
  224. goto exit;
  225. }
  226. exit:
  227. return t_cch;
  228. }
  229. struct op_chs_ent_t {
  230. u8 ch_num;
  231. u8 *chs;
  232. };
  233. struct op_chs_ent_t op_chs_of_cch_2g_by_bw[] = {
  234. {1, center_ch_2g},
  235. {2, (u8 *)op_chs_of_cch_2g_40m},
  236. };
  237. struct op_chs_ent_t op_chs_of_cch_5g_by_bw[] = {
  238. {1, center_ch_5g_20m},
  239. {2, (u8 *)op_chs_of_cch_5g_40m},
  240. {4, (u8 *)op_chs_of_cch_5g_80m},
  241. {8, (u8 *)op_chs_of_cch_5g_160m},
  242. };
  243. inline u8 center_chs_2g_num(u8 bw)
  244. {
  245. if (bw > CHANNEL_WIDTH_40)
  246. return 0;
  247. return center_chs_2g_by_bw[bw].ch_num;
  248. }
  249. inline u8 center_chs_2g(u8 bw, u8 id)
  250. {
  251. if (bw > CHANNEL_WIDTH_40)
  252. return 0;
  253. if (id >= center_chs_2g_num(bw))
  254. return 0;
  255. return center_chs_2g_by_bw[bw].chs[id];
  256. }
  257. inline u8 center_chs_5g_num(u8 bw)
  258. {
  259. if (bw > CHANNEL_WIDTH_80)
  260. return 0;
  261. return center_chs_5g_by_bw[bw].ch_num;
  262. }
  263. inline u8 center_chs_5g(u8 bw, u8 id)
  264. {
  265. if (bw > CHANNEL_WIDTH_80)
  266. return 0;
  267. if (id >= center_chs_5g_num(bw))
  268. return 0;
  269. return center_chs_5g_by_bw[bw].chs[id];
  270. }
  271. /*
  272. * Get available op channels by @param cch, @param bw
  273. * @cch: the given center channel
  274. * @bw: the given bandwidth
  275. * @op_chs: the pointer to return pointer of op channel array
  276. * @op_ch_num: the pointer to return pointer of op channel number
  277. *
  278. * return valid (1) or not (0)
  279. */
  280. u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num)
  281. {
  282. int i;
  283. struct center_chs_ent_t *c_chs_ent = NULL;
  284. struct op_chs_ent_t *op_chs_ent = NULL;
  285. u8 valid = 1;
  286. if (cch <= 14
  287. && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_40
  288. ) {
  289. c_chs_ent = &center_chs_2g_by_bw[bw];
  290. op_chs_ent = &op_chs_of_cch_2g_by_bw[bw];
  291. } else if (cch >= 36 && cch <= 177
  292. && bw >= CHANNEL_WIDTH_20 && bw <= CHANNEL_WIDTH_160
  293. ) {
  294. c_chs_ent = &center_chs_5g_by_bw[bw];
  295. op_chs_ent = &op_chs_of_cch_5g_by_bw[bw];
  296. } else {
  297. valid = 0;
  298. goto exit;
  299. }
  300. for (i = 0; i < c_chs_ent->ch_num; i++)
  301. if (cch == *(c_chs_ent->chs + i))
  302. break;
  303. if (i == c_chs_ent->ch_num) {
  304. valid = 0;
  305. goto exit;
  306. }
  307. *op_chs = op_chs_ent->chs + op_chs_ent->ch_num * i;
  308. *op_ch_num = op_chs_ent->ch_num;
  309. exit:
  310. return valid;
  311. }
  312. u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group)
  313. {
  314. BAND_TYPE band = BAND_MAX;
  315. s8 gp = -1, cck_gp = -1;
  316. if (ch <= 14) {
  317. band = BAND_ON_2_4G;
  318. if (1 <= ch && ch <= 2)
  319. gp = 0;
  320. else if (3 <= ch && ch <= 5)
  321. gp = 1;
  322. else if (6 <= ch && ch <= 8)
  323. gp = 2;
  324. else if (9 <= ch && ch <= 11)
  325. gp = 3;
  326. else if (12 <= ch && ch <= 14)
  327. gp = 4;
  328. else
  329. band = BAND_MAX;
  330. if (ch == 14)
  331. cck_gp = 5;
  332. else
  333. cck_gp = gp;
  334. } else {
  335. band = BAND_ON_5G;
  336. if (36 <= ch && ch <= 42)
  337. gp = 0;
  338. else if (44 <= ch && ch <= 48)
  339. gp = 1;
  340. else if (50 <= ch && ch <= 58)
  341. gp = 2;
  342. else if (60 <= ch && ch <= 64)
  343. gp = 3;
  344. else if (100 <= ch && ch <= 106)
  345. gp = 4;
  346. else if (108 <= ch && ch <= 114)
  347. gp = 5;
  348. else if (116 <= ch && ch <= 122)
  349. gp = 6;
  350. else if (124 <= ch && ch <= 130)
  351. gp = 7;
  352. else if (132 <= ch && ch <= 138)
  353. gp = 8;
  354. else if (140 <= ch && ch <= 144)
  355. gp = 9;
  356. else if (149 <= ch && ch <= 155)
  357. gp = 10;
  358. else if (157 <= ch && ch <= 161)
  359. gp = 11;
  360. else if (165 <= ch && ch <= 171)
  361. gp = 12;
  362. else if (173 <= ch && ch <= 177)
  363. gp = 13;
  364. else
  365. band = BAND_MAX;
  366. }
  367. if (band == BAND_MAX
  368. || (band == BAND_ON_2_4G && cck_gp == -1)
  369. || gp == -1
  370. ) {
  371. RTW_WARN("%s invalid channel:%u", __func__, ch);
  372. rtw_warn_on(1);
  373. goto exit;
  374. }
  375. if (group)
  376. *group = gp;
  377. if (cck_group && band == BAND_ON_2_4G)
  378. *cck_group = cck_gp;
  379. exit:
  380. return band;
  381. }
  382. int rtw_ch2freq(int chan)
  383. {
  384. /* see 802.11 17.3.8.3.2 and Annex J
  385. * there are overlapping channel numbers in 5GHz and 2GHz bands */
  386. /*
  387. * RTK: don't consider the overlapping channel numbers: 5G channel <= 14,
  388. * because we don't support it. simply judge from channel number
  389. */
  390. if (chan >= 1 && chan <= 14) {
  391. if (chan == 14)
  392. return 2484;
  393. else if (chan < 14)
  394. return 2407 + chan * 5;
  395. } else if (chan >= 36 && chan <= 177)
  396. return 5000 + chan * 5;
  397. return 0; /* not supported */
  398. }
  399. int rtw_freq2ch(int freq)
  400. {
  401. /* see 802.11 17.3.8.3.2 and Annex J */
  402. if (freq == 2484)
  403. return 14;
  404. else if (freq < 2484)
  405. return (freq - 2407) / 5;
  406. else if (freq >= 4910 && freq <= 4980)
  407. return (freq - 4000) / 5;
  408. else if (freq <= 45000) /* DMG band lower limit */
  409. return (freq - 5000) / 5;
  410. else if (freq >= 58320 && freq <= 64800)
  411. return (freq - 56160) / 2160;
  412. else
  413. return 0;
  414. }
  415. bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo)
  416. {
  417. u8 c_ch;
  418. u32 freq;
  419. u32 hi_ret = 0, lo_ret = 0;
  420. int i;
  421. bool valid = _FALSE;
  422. if (hi)
  423. *hi = 0;
  424. if (lo)
  425. *lo = 0;
  426. c_ch = rtw_get_center_ch(ch, bw, offset);
  427. freq = rtw_ch2freq(c_ch);
  428. if (!freq) {
  429. rtw_warn_on(1);
  430. goto exit;
  431. }
  432. if (bw == CHANNEL_WIDTH_80) {
  433. hi_ret = freq + 40;
  434. lo_ret = freq - 40;
  435. } else if (bw == CHANNEL_WIDTH_40) {
  436. hi_ret = freq + 20;
  437. lo_ret = freq - 20;
  438. } else if (bw == CHANNEL_WIDTH_20) {
  439. hi_ret = freq + 10;
  440. lo_ret = freq - 10;
  441. } else
  442. rtw_warn_on(1);
  443. if (hi)
  444. *hi = hi_ret;
  445. if (lo)
  446. *lo = lo_ret;
  447. valid = _TRUE;
  448. exit:
  449. return valid;
  450. }
  451. const char *const _ch_width_str[] = {
  452. "20MHz",
  453. "40MHz",
  454. "80MHz",
  455. "160MHz",
  456. "80_80MHz",
  457. "CHANNEL_WIDTH_MAX",
  458. };
  459. const u8 _ch_width_to_bw_cap[] = {
  460. BW_CAP_20M,
  461. BW_CAP_40M,
  462. BW_CAP_80M,
  463. BW_CAP_160M,
  464. BW_CAP_80_80M,
  465. 0,
  466. };
  467. const char *const _band_str[] = {
  468. "2.4G",
  469. "5G",
  470. "BOTH",
  471. "BAND_MAX",
  472. };
  473. const u8 _band_to_band_cap[] = {
  474. BAND_CAP_2G,
  475. BAND_CAP_5G,
  476. 0,
  477. 0,
  478. };
  479. const u8 _rf_type_to_rf_tx_cnt[] = {
  480. 1,
  481. 2,
  482. 2,
  483. 1,
  484. 2,
  485. 2,
  486. 3,
  487. 3,
  488. 4,
  489. };
  490. const u8 _rf_type_to_rf_rx_cnt[] = {
  491. 2,
  492. 4,
  493. 2,
  494. 1,
  495. 2,
  496. 3,
  497. 3,
  498. 4,
  499. 4,
  500. };
  501. #ifdef CONFIG_80211AC_VHT
  502. #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val) , .en_11ac = (_val)
  503. #else
  504. #define COUNTRY_CHPLAN_ASSIGN_EN_11AC(_val)
  505. #endif
  506. #if RTW_DEF_MODULE_REGULATORY_CERT
  507. #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val) , .def_module_flags = (_val)
  508. #else
  509. #define COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_val)
  510. #endif
  511. /* has def_module_flags specified, used by common map and HAL dfference map */
  512. #define COUNTRY_CHPLAN_ENT(_alpha2, _chplan, _en_11ac, _def_module_flags) \
  513. {.alpha2 = (_alpha2), .chplan = (_chplan) \
  514. COUNTRY_CHPLAN_ASSIGN_EN_11AC(_en_11ac) \
  515. COUNTRY_CHPLAN_ASSIGN_DEF_MODULE_FLAGS(_def_module_flags) \
  516. }
  517. #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
  518. #include "../platform/custom_country_chplan.h"
  519. #elif RTW_DEF_MODULE_REGULATORY_CERT
  520. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AE_HMC_M2) /* 2013 certify */
  521. static const struct country_chplan RTL8821AE_HMC_M2_country_chplan_exc_map[] = {
  522. COUNTRY_CHPLAN_ENT("CN", 0x51, 1, 0x1FB), /* China */
  523. COUNTRY_CHPLAN_ENT("MY", 0x47, 1, 0x1F1), /* Malaysia */
  524. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  525. COUNTRY_CHPLAN_ENT("UA", 0x36, 0, 0x1FB), /* Ukraine */
  526. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  527. };
  528. #endif
  529. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8821AU) /* 2014 certify */
  530. static const struct country_chplan RTL8821AU_country_chplan_exc_map[] = {
  531. COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0x1FB), /* Russia(fac/gost), Kaliningrad */
  532. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  533. COUNTRY_CHPLAN_ENT("UA", 0x36, 0, 0x1FB), /* Ukraine */
  534. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  535. };
  536. #endif
  537. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AENF_NGFF) /* 2014 certify */
  538. static const struct country_chplan RTL8812AENF_NGFF_country_chplan_exc_map[] = {
  539. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  540. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  541. };
  542. #endif
  543. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8812AEBT_HMC) /* 2013 certify */
  544. static const struct country_chplan RTL8812AEBT_HMC_country_chplan_exc_map[] = {
  545. COUNTRY_CHPLAN_ENT("RU", 0x59, 0, 0x1FB), /* Russia(fac/gost), Kaliningrad */
  546. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  547. COUNTRY_CHPLAN_ENT("UA", 0x36, 0, 0x1FB), /* Ukraine */
  548. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  549. };
  550. #endif
  551. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8188EE_HMC_M2) /* 2012 certify */
  552. static const struct country_chplan RTL8188EE_HMC_M2_country_chplan_exc_map[] = {
  553. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  554. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  555. };
  556. #endif
  557. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BE_HMC_M2) /* 2013 certify */
  558. static const struct country_chplan RTL8723BE_HMC_M2_country_chplan_exc_map[] = {
  559. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  560. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  561. };
  562. #endif
  563. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723BS_NGFF1216) /* 2014 certify */
  564. static const struct country_chplan RTL8723BS_NGFF1216_country_chplan_exc_map[] = {
  565. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  566. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  567. };
  568. #endif
  569. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8192EEBT_HMC_M2) /* 2013 certify */
  570. static const struct country_chplan RTL8192EEBT_HMC_M2_country_chplan_exc_map[] = {
  571. COUNTRY_CHPLAN_ENT("TW", 0x39, 1, 0x1FF), /* Taiwan */
  572. COUNTRY_CHPLAN_ENT("US", 0x34, 1, 0x1FF), /* United States of America (USA) */
  573. };
  574. #endif
  575. #if (RTW_DEF_MODULE_REGULATORY_CERT & RTW_MODULE_RTL8723DE_NGFF1630) /* 2016 certify */
  576. static const struct country_chplan RTL8723DE_NGFF1630_country_chplan_exc_map[] = {
  577. };
  578. #endif
  579. /**
  580. * rtw_def_module_get_chplan_from_country -
  581. * @country_code: string of country code
  582. * @return:
  583. * Return NULL for case referring to common map
  584. */
  585. static const struct country_chplan *rtw_def_module_get_chplan_from_country(const char *country_code)
  586. {
  587. const struct country_chplan *ent = NULL;
  588. const struct country_chplan *hal_map = NULL;
  589. u16 hal_map_sz = 0;
  590. int i;
  591. /* TODO: runtime selection for multi driver */
  592. #if (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AE_HMC_M2)
  593. hal_map = RTL8821AE_HMC_M2_country_chplan_exc_map;
  594. hal_map_sz = sizeof(RTL8821AE_HMC_M2_country_chplan_exc_map) / sizeof(struct country_chplan);
  595. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8821AU)
  596. hal_map = RTL8821AU_country_chplan_exc_map;
  597. hal_map_sz = sizeof(RTL8821AU_country_chplan_exc_map) / sizeof(struct country_chplan);
  598. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AENF_NGFF)
  599. hal_map = RTL8812AENF_NGFF_country_chplan_exc_map;
  600. hal_map_sz = sizeof(RTL8812AENF_NGFF_country_chplan_exc_map) / sizeof(struct country_chplan);
  601. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8812AEBT_HMC)
  602. hal_map = RTL8812AEBT_HMC_country_chplan_exc_map;
  603. hal_map_sz = sizeof(RTL8812AEBT_HMC_country_chplan_exc_map) / sizeof(struct country_chplan);
  604. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8188EE_HMC_M2)
  605. hal_map = RTL8188EE_HMC_M2_country_chplan_exc_map;
  606. hal_map_sz = sizeof(RTL8188EE_HMC_M2_country_chplan_exc_map) / sizeof(struct country_chplan);
  607. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BE_HMC_M2)
  608. hal_map = RTL8723BE_HMC_M2_country_chplan_exc_map;
  609. hal_map_sz = sizeof(RTL8723BE_HMC_M2_country_chplan_exc_map) / sizeof(struct country_chplan);
  610. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723BS_NGFF1216)
  611. hal_map = RTL8723BS_NGFF1216_country_chplan_exc_map;
  612. hal_map_sz = sizeof(RTL8723BS_NGFF1216_country_chplan_exc_map) / sizeof(struct country_chplan);
  613. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8192EEBT_HMC_M2)
  614. hal_map = RTL8192EEBT_HMC_M2_country_chplan_exc_map;
  615. hal_map_sz = sizeof(RTL8192EEBT_HMC_M2_country_chplan_exc_map) / sizeof(struct country_chplan);
  616. #elif (RTW_DEF_MODULE_REGULATORY_CERT == RTW_MODULE_RTL8723DE_NGFF1630)
  617. hal_map = RTL8723DE_NGFF1630_country_chplan_exc_map;
  618. hal_map_sz = sizeof(RTL8723DE_NGFF1630_country_chplan_exc_map) / sizeof(struct country_chplan);
  619. #endif
  620. if (hal_map == NULL || hal_map_sz == 0)
  621. goto exit;
  622. for (i = 0; i < hal_map_sz; i++) {
  623. if (strncmp(country_code, hal_map[i].alpha2, 2) == 0) {
  624. ent = &hal_map[i];
  625. break;
  626. }
  627. }
  628. exit:
  629. return ent;
  630. }
  631. #endif /* CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP or RTW_DEF_MODULE_REGULATORY_CERT */
  632. static const struct country_chplan country_chplan_map[] = {
  633. COUNTRY_CHPLAN_ENT("AD", 0x26, 1, 0x000), /* Andorra */
  634. COUNTRY_CHPLAN_ENT("AE", 0x26, 1, 0x1FB), /* United Arab Emirates */
  635. COUNTRY_CHPLAN_ENT("AF", 0x42, 1, 0x000), /* Afghanistan */
  636. COUNTRY_CHPLAN_ENT("AG", 0x30, 1, 0x000), /* Antigua & Barbuda */
  637. COUNTRY_CHPLAN_ENT("AI", 0x26, 1, 0x000), /* Anguilla(UK) */
  638. COUNTRY_CHPLAN_ENT("AL", 0x26, 1, 0x1F1), /* Albania */
  639. COUNTRY_CHPLAN_ENT("AM", 0x26, 1, 0x0B0), /* Armenia */
  640. COUNTRY_CHPLAN_ENT("AO", 0x26, 1, 0x0E0), /* Angola */
  641. COUNTRY_CHPLAN_ENT("AQ", 0x26, 1, 0x000), /* Antarctica */
  642. COUNTRY_CHPLAN_ENT("AR", 0x57, 1, 0x1F3), /* Argentina */
  643. COUNTRY_CHPLAN_ENT("AS", 0x34, 1, 0x000), /* American Samoa */
  644. COUNTRY_CHPLAN_ENT("AT", 0x26, 1, 0x1FB), /* Austria */
  645. COUNTRY_CHPLAN_ENT("AU", 0x45, 1, 0x1FB), /* Australia */
  646. COUNTRY_CHPLAN_ENT("AW", 0x34, 1, 0x0B0), /* Aruba */
  647. COUNTRY_CHPLAN_ENT("AZ", 0x26, 1, 0x1F1), /* Azerbaijan */
  648. COUNTRY_CHPLAN_ENT("BA", 0x26, 1, 0x1F1), /* Bosnia & Herzegovina */
  649. COUNTRY_CHPLAN_ENT("BB", 0x34, 1, 0x050), /* Barbados */
  650. COUNTRY_CHPLAN_ENT("BD", 0x26, 1, 0x1F1), /* Bangladesh */
  651. COUNTRY_CHPLAN_ENT("BE", 0x26, 1, 0x1FB), /* Belgium */
  652. COUNTRY_CHPLAN_ENT("BF", 0x26, 1, 0x0B0), /* Burkina Faso */
  653. COUNTRY_CHPLAN_ENT("BG", 0x26, 1, 0x1F1), /* Bulgaria */
  654. COUNTRY_CHPLAN_ENT("BH", 0x47, 1, 0x1F1), /* Bahrain */
  655. COUNTRY_CHPLAN_ENT("BI", 0x26, 1, 0x0B0), /* Burundi */
  656. COUNTRY_CHPLAN_ENT("BJ", 0x26, 1, 0x0B0), /* Benin */
  657. COUNTRY_CHPLAN_ENT("BN", 0x47, 1, 0x010), /* Brunei */
  658. COUNTRY_CHPLAN_ENT("BO", 0x30, 1, 0x1F1), /* Bolivia */
  659. COUNTRY_CHPLAN_ENT("BR", 0x34, 1, 0x1F1), /* Brazil */
  660. COUNTRY_CHPLAN_ENT("BS", 0x34, 1, 0x020), /* Bahamas */
  661. COUNTRY_CHPLAN_ENT("BW", 0x26, 1, 0x0F1), /* Botswana */
  662. COUNTRY_CHPLAN_ENT("BY", 0x26, 1, 0x1F1), /* Belarus */
  663. COUNTRY_CHPLAN_ENT("BZ", 0x34, 1, 0x000), /* Belize */
  664. COUNTRY_CHPLAN_ENT("CA", 0x34, 1, 0x1FB), /* Canada */
  665. COUNTRY_CHPLAN_ENT("CC", 0x26, 1, 0x000), /* Cocos (Keeling) Islands (Australia) */
  666. COUNTRY_CHPLAN_ENT("CD", 0x26, 1, 0x0B0), /* Congo, Republic of the */
  667. COUNTRY_CHPLAN_ENT("CF", 0x26, 1, 0x0B0), /* Central African Republic */
  668. COUNTRY_CHPLAN_ENT("CG", 0x26, 1, 0x0B0), /* Congo, Democratic Republic of the. Zaire */
  669. COUNTRY_CHPLAN_ENT("CH", 0x26, 1, 0x1FB), /* Switzerland */
  670. COUNTRY_CHPLAN_ENT("CI", 0x26, 1, 0x1F1), /* Cote d'Ivoire */
  671. COUNTRY_CHPLAN_ENT("CK", 0x26, 1, 0x000), /* Cook Islands */
  672. COUNTRY_CHPLAN_ENT("CL", 0x30, 1, 0x1F1), /* Chile */
  673. COUNTRY_CHPLAN_ENT("CM", 0x26, 1, 0x0B0), /* Cameroon */
  674. COUNTRY_CHPLAN_ENT("CN", 0x48, 1, 0x1FB), /* China */
  675. COUNTRY_CHPLAN_ENT("CO", 0x34, 1, 0x1F1), /* Colombia */
  676. COUNTRY_CHPLAN_ENT("CR", 0x34, 1, 0x1F1), /* Costa Rica */
  677. COUNTRY_CHPLAN_ENT("CV", 0x26, 1, 0x0B0), /* Cape Verde */
  678. COUNTRY_CHPLAN_ENT("CX", 0x45, 1, 0x000), /* Christmas Island (Australia) */
  679. COUNTRY_CHPLAN_ENT("CY", 0x26, 1, 0x1FB), /* Cyprus */
  680. COUNTRY_CHPLAN_ENT("CZ", 0x26, 1, 0x1FB), /* Czech Republic */
  681. COUNTRY_CHPLAN_ENT("DE", 0x26, 1, 0x1FB), /* Germany */
  682. COUNTRY_CHPLAN_ENT("DJ", 0x26, 1, 0x080), /* Djibouti */
  683. COUNTRY_CHPLAN_ENT("DK", 0x26, 1, 0x1FB), /* Denmark */
  684. COUNTRY_CHPLAN_ENT("DM", 0x34, 1, 0x000), /* Dominica */
  685. COUNTRY_CHPLAN_ENT("DO", 0x34, 1, 0x1F1), /* Dominican Republic */
  686. COUNTRY_CHPLAN_ENT("DZ", 0x26, 1, 0x1F1), /* Algeria */
  687. COUNTRY_CHPLAN_ENT("EC", 0x34, 1, 0x1F1), /* Ecuador */
  688. COUNTRY_CHPLAN_ENT("EE", 0x26, 1, 0x1FB), /* Estonia */
  689. COUNTRY_CHPLAN_ENT("EG", 0x47, 0, 0x1F1), /* Egypt */
  690. COUNTRY_CHPLAN_ENT("EH", 0x47, 1, 0x080), /* Western Sahara */
  691. COUNTRY_CHPLAN_ENT("ER", 0x26, 1, 0x000), /* Eritrea */
  692. COUNTRY_CHPLAN_ENT("ES", 0x26, 1, 0x1FB), /* Spain, Canary Islands, Ceuta, Melilla */
  693. COUNTRY_CHPLAN_ENT("ET", 0x26, 1, 0x0B0), /* Ethiopia */
  694. COUNTRY_CHPLAN_ENT("FI", 0x26, 1, 0x1FB), /* Finland */
  695. COUNTRY_CHPLAN_ENT("FJ", 0x34, 1, 0x000), /* Fiji */
  696. COUNTRY_CHPLAN_ENT("FK", 0x26, 1, 0x000), /* Falkland Islands (Islas Malvinas) (UK) */
  697. COUNTRY_CHPLAN_ENT("FM", 0x34, 1, 0x000), /* Micronesia, Federated States of (USA) */
  698. COUNTRY_CHPLAN_ENT("FO", 0x26, 1, 0x000), /* Faroe Islands (Denmark) */
  699. COUNTRY_CHPLAN_ENT("FR", 0x26, 1, 0x1FB), /* France */
  700. COUNTRY_CHPLAN_ENT("GA", 0x26, 1, 0x0B0), /* Gabon */
  701. COUNTRY_CHPLAN_ENT("GB", 0x26, 1, 0x1FB), /* Great Britain (United Kingdom; England) */
  702. COUNTRY_CHPLAN_ENT("GD", 0x34, 1, 0x0B0), /* Grenada */
  703. COUNTRY_CHPLAN_ENT("GE", 0x26, 1, 0x000), /* Georgia */
  704. COUNTRY_CHPLAN_ENT("GF", 0x26, 1, 0x080), /* French Guiana */
  705. COUNTRY_CHPLAN_ENT("GG", 0x26, 1, 0x000), /* Guernsey (UK) */
  706. COUNTRY_CHPLAN_ENT("GH", 0x26, 1, 0x1F1), /* Ghana */
  707. COUNTRY_CHPLAN_ENT("GI", 0x26, 1, 0x000), /* Gibraltar (UK) */
  708. COUNTRY_CHPLAN_ENT("GL", 0x26, 1, 0x000), /* Greenland (Denmark) */
  709. COUNTRY_CHPLAN_ENT("GM", 0x26, 1, 0x0B0), /* Gambia */
  710. COUNTRY_CHPLAN_ENT("GN", 0x26, 1, 0x010), /* Guinea */
  711. COUNTRY_CHPLAN_ENT("GP", 0x26, 1, 0x000), /* Guadeloupe (France) */
  712. COUNTRY_CHPLAN_ENT("GQ", 0x26, 1, 0x0B0), /* Equatorial Guinea */
  713. COUNTRY_CHPLAN_ENT("GR", 0x26, 1, 0x1FB), /* Greece */
  714. COUNTRY_CHPLAN_ENT("GS", 0x26, 1, 0x000), /* South Georgia and the Sandwich Islands (UK) */
  715. COUNTRY_CHPLAN_ENT("GT", 0x34, 1, 0x1F1), /* Guatemala */
  716. COUNTRY_CHPLAN_ENT("GU", 0x34, 1, 0x000), /* Guam (USA) */
  717. COUNTRY_CHPLAN_ENT("GW", 0x26, 1, 0x0B0), /* Guinea-Bissau */
  718. COUNTRY_CHPLAN_ENT("GY", 0x44, 1, 0x000), /* Guyana */
  719. COUNTRY_CHPLAN_ENT("HK", 0x26, 1, 0x1FB), /* Hong Kong */
  720. COUNTRY_CHPLAN_ENT("HM", 0x45, 1, 0x000), /* Heard and McDonald Islands (Australia) */
  721. COUNTRY_CHPLAN_ENT("HN", 0x32, 1, 0x1F1), /* Honduras */
  722. COUNTRY_CHPLAN_ENT("HR", 0x26, 1, 0x1F9), /* Croatia */
  723. COUNTRY_CHPLAN_ENT("HT", 0x34, 1, 0x050), /* Haiti */
  724. COUNTRY_CHPLAN_ENT("HU", 0x26, 1, 0x1FB), /* Hungary */
  725. COUNTRY_CHPLAN_ENT("ID", 0x54, 0, 0x1F3), /* Indonesia */
  726. COUNTRY_CHPLAN_ENT("IE", 0x26, 1, 0x1FB), /* Ireland */
  727. COUNTRY_CHPLAN_ENT("IL", 0x47, 1, 0x1F1), /* Israel */
  728. COUNTRY_CHPLAN_ENT("IM", 0x26, 1, 0x000), /* Isle of Man (UK) */
  729. COUNTRY_CHPLAN_ENT("IN", 0x47, 1, 0x1F1), /* India */
  730. COUNTRY_CHPLAN_ENT("IQ", 0x26, 1, 0x000), /* Iraq */
  731. COUNTRY_CHPLAN_ENT("IR", 0x26, 0, 0x000), /* Iran */
  732. COUNTRY_CHPLAN_ENT("IS", 0x26, 1, 0x1FB), /* Iceland */
  733. COUNTRY_CHPLAN_ENT("IT", 0x26, 1, 0x1FB), /* Italy */
  734. COUNTRY_CHPLAN_ENT("JE", 0x26, 1, 0x000), /* Jersey (UK) */
  735. COUNTRY_CHPLAN_ENT("JM", 0x51, 1, 0x1F1), /* Jamaica */
  736. COUNTRY_CHPLAN_ENT("JO", 0x49, 1, 0x1FB), /* Jordan */
  737. COUNTRY_CHPLAN_ENT("JP", 0x27, 1, 0x1FF), /* Japan- Telec */
  738. COUNTRY_CHPLAN_ENT("KE", 0x47, 1, 0x1F9), /* Kenya */
  739. COUNTRY_CHPLAN_ENT("KG", 0x26, 1, 0x1F1), /* Kyrgyzstan */
  740. COUNTRY_CHPLAN_ENT("KH", 0x26, 1, 0x1F1), /* Cambodia */
  741. COUNTRY_CHPLAN_ENT("KI", 0x26, 1, 0x000), /* Kiribati */
  742. COUNTRY_CHPLAN_ENT("KN", 0x34, 1, 0x000), /* Saint Kitts and Nevis */
  743. COUNTRY_CHPLAN_ENT("KR", 0x28, 1, 0x1FB), /* South Korea */
  744. COUNTRY_CHPLAN_ENT("KW", 0x47, 1, 0x1FB), /* Kuwait */
  745. COUNTRY_CHPLAN_ENT("KY", 0x34, 1, 0x000), /* Cayman Islands (UK) */
  746. COUNTRY_CHPLAN_ENT("KZ", 0x26, 1, 0x100), /* Kazakhstan */
  747. COUNTRY_CHPLAN_ENT("LA", 0x26, 1, 0x000), /* Laos */
  748. COUNTRY_CHPLAN_ENT("LB", 0x26, 1, 0x1F1), /* Lebanon */
  749. COUNTRY_CHPLAN_ENT("LC", 0x34, 1, 0x000), /* Saint Lucia */
  750. COUNTRY_CHPLAN_ENT("LI", 0x26, 1, 0x1FB), /* Liechtenstein */
  751. COUNTRY_CHPLAN_ENT("LK", 0x26, 1, 0x1F1), /* Sri Lanka */
  752. COUNTRY_CHPLAN_ENT("LR", 0x26, 1, 0x0B0), /* Liberia */
  753. COUNTRY_CHPLAN_ENT("LS", 0x26, 1, 0x1F1), /* Lesotho */
  754. COUNTRY_CHPLAN_ENT("LT", 0x26, 1, 0x1FB), /* Lithuania */
  755. COUNTRY_CHPLAN_ENT("LU", 0x26, 1, 0x1FB), /* Luxembourg */
  756. COUNTRY_CHPLAN_ENT("LV", 0x26, 1, 0x1FB), /* Latvia */
  757. COUNTRY_CHPLAN_ENT("LY", 0x26, 1, 0x000), /* Libya */
  758. COUNTRY_CHPLAN_ENT("MA", 0x47, 1, 0x1F1), /* Morocco */
  759. COUNTRY_CHPLAN_ENT("MC", 0x26, 1, 0x1FB), /* Monaco */
  760. COUNTRY_CHPLAN_ENT("MD", 0x26, 1, 0x1F1), /* Moldova */
  761. COUNTRY_CHPLAN_ENT("ME", 0x26, 1, 0x1F1), /* Montenegro */
  762. COUNTRY_CHPLAN_ENT("MF", 0x34, 1, 0x000), /* Saint Martin */
  763. COUNTRY_CHPLAN_ENT("MG", 0x26, 1, 0x020), /* Madagascar */
  764. COUNTRY_CHPLAN_ENT("MH", 0x34, 1, 0x000), /* Marshall Islands (USA) */
  765. COUNTRY_CHPLAN_ENT("MK", 0x26, 1, 0x1F1), /* Republic of Macedonia (FYROM) */
  766. COUNTRY_CHPLAN_ENT("ML", 0x26, 1, 0x0B0), /* Mali */
  767. COUNTRY_CHPLAN_ENT("MM", 0x26, 1, 0x000), /* Burma (Myanmar) */
  768. COUNTRY_CHPLAN_ENT("MN", 0x26, 1, 0x000), /* Mongolia */
  769. COUNTRY_CHPLAN_ENT("MO", 0x26, 1, 0x000), /* Macau */
  770. COUNTRY_CHPLAN_ENT("MP", 0x34, 1, 0x000), /* Northern Mariana Islands (USA) */
  771. COUNTRY_CHPLAN_ENT("MQ", 0x26, 1, 0x040), /* Martinique (France) */
  772. COUNTRY_CHPLAN_ENT("MR", 0x26, 1, 0x0A0), /* Mauritania */
  773. COUNTRY_CHPLAN_ENT("MS", 0x26, 1, 0x000), /* Montserrat (UK) */
  774. COUNTRY_CHPLAN_ENT("MT", 0x26, 1, 0x1FB), /* Malta */
  775. COUNTRY_CHPLAN_ENT("MU", 0x26, 1, 0x0B0), /* Mauritius */
  776. COUNTRY_CHPLAN_ENT("MV", 0x26, 1, 0x000), /* Maldives */
  777. COUNTRY_CHPLAN_ENT("MW", 0x26, 1, 0x0B0), /* Malawi */
  778. COUNTRY_CHPLAN_ENT("MX", 0x34, 1, 0x1F1), /* Mexico */
  779. COUNTRY_CHPLAN_ENT("MY", 0x63, 1, 0x1F1), /* Malaysia */
  780. COUNTRY_CHPLAN_ENT("MZ", 0x26, 1, 0x1F1), /* Mozambique */
  781. COUNTRY_CHPLAN_ENT("NA", 0x26, 1, 0x100), /* Namibia */
  782. COUNTRY_CHPLAN_ENT("NC", 0x26, 1, 0x000), /* New Caledonia */
  783. COUNTRY_CHPLAN_ENT("NE", 0x26, 1, 0x0B0), /* Niger */
  784. COUNTRY_CHPLAN_ENT("NF", 0x45, 1, 0x000), /* Norfolk Island (Australia) */
  785. COUNTRY_CHPLAN_ENT("NG", 0x50, 1, 0x1F9), /* Nigeria */
  786. COUNTRY_CHPLAN_ENT("NI", 0x34, 1, 0x1F1), /* Nicaragua */
  787. COUNTRY_CHPLAN_ENT("NL", 0x26, 1, 0x1FB), /* Netherlands */
  788. COUNTRY_CHPLAN_ENT("NO", 0x26, 1, 0x1FB), /* Norway */
  789. COUNTRY_CHPLAN_ENT("NP", 0x47, 1, 0x0F0), /* Nepal */
  790. COUNTRY_CHPLAN_ENT("NR", 0x26, 1, 0x000), /* Nauru */
  791. COUNTRY_CHPLAN_ENT("NU", 0x45, 1, 0x000), /* Niue */
  792. COUNTRY_CHPLAN_ENT("NZ", 0x45, 1, 0x1FB), /* New Zealand */
  793. COUNTRY_CHPLAN_ENT("OM", 0x26, 1, 0x1F9), /* Oman */
  794. COUNTRY_CHPLAN_ENT("PA", 0x34, 1, 0x1F1), /* Panama */
  795. COUNTRY_CHPLAN_ENT("PE", 0x34, 1, 0x1F1), /* Peru */
  796. COUNTRY_CHPLAN_ENT("PF", 0x26, 1, 0x000), /* French Polynesia (France) */
  797. COUNTRY_CHPLAN_ENT("PG", 0x26, 1, 0x1F1), /* Papua New Guinea */
  798. COUNTRY_CHPLAN_ENT("PH", 0x26, 1, 0x1F1), /* Philippines */
  799. COUNTRY_CHPLAN_ENT("PK", 0x51, 1, 0x1F1), /* Pakistan */
  800. COUNTRY_CHPLAN_ENT("PL", 0x26, 1, 0x1FB), /* Poland */
  801. COUNTRY_CHPLAN_ENT("PM", 0x26, 1, 0x000), /* Saint Pierre and Miquelon (France) */
  802. COUNTRY_CHPLAN_ENT("PR", 0x34, 1, 0x1F1), /* Puerto Rico */
  803. COUNTRY_CHPLAN_ENT("PT", 0x26, 1, 0x1FB), /* Portugal */
  804. COUNTRY_CHPLAN_ENT("PW", 0x34, 1, 0x000), /* Palau */
  805. COUNTRY_CHPLAN_ENT("PY", 0x34, 1, 0x1F1), /* Paraguay */
  806. COUNTRY_CHPLAN_ENT("QA", 0x51, 1, 0x1F9), /* Qatar */
  807. COUNTRY_CHPLAN_ENT("RE", 0x26, 1, 0x000), /* Reunion (France) */
  808. COUNTRY_CHPLAN_ENT("RO", 0x26, 1, 0x1F1), /* Romania */
  809. COUNTRY_CHPLAN_ENT("RS", 0x26, 1, 0x1F1), /* Serbia, Kosovo */
  810. COUNTRY_CHPLAN_ENT("RU", 0x59, 1, 0x1FB), /* Russia(fac/gost), Kaliningrad */
  811. COUNTRY_CHPLAN_ENT("RW", 0x26, 1, 0x0B0), /* Rwanda */
  812. COUNTRY_CHPLAN_ENT("SA", 0x26, 1, 0x1FB), /* Saudi Arabia */
  813. COUNTRY_CHPLAN_ENT("SB", 0x26, 1, 0x000), /* Solomon Islands */
  814. COUNTRY_CHPLAN_ENT("SC", 0x34, 1, 0x090), /* Seychelles */
  815. COUNTRY_CHPLAN_ENT("SE", 0x26, 1, 0x1FB), /* Sweden */
  816. COUNTRY_CHPLAN_ENT("SG", 0x26, 1, 0x1FB), /* Singapore */
  817. COUNTRY_CHPLAN_ENT("SH", 0x26, 1, 0x000), /* Saint Helena (UK) */
  818. COUNTRY_CHPLAN_ENT("SI", 0x26, 1, 0x1FB), /* Slovenia */
  819. COUNTRY_CHPLAN_ENT("SJ", 0x26, 1, 0x000), /* Svalbard (Norway) */
  820. COUNTRY_CHPLAN_ENT("SK", 0x26, 1, 0x1FB), /* Slovakia */
  821. COUNTRY_CHPLAN_ENT("SL", 0x26, 1, 0x0B0), /* Sierra Leone */
  822. COUNTRY_CHPLAN_ENT("SM", 0x26, 1, 0x000), /* San Marino */
  823. COUNTRY_CHPLAN_ENT("SN", 0x26, 1, 0x1F1), /* Senegal */
  824. COUNTRY_CHPLAN_ENT("SO", 0x26, 1, 0x000), /* Somalia */
  825. COUNTRY_CHPLAN_ENT("SR", 0x34, 1, 0x000), /* Suriname */
  826. COUNTRY_CHPLAN_ENT("ST", 0x34, 1, 0x080), /* Sao Tome and Principe */
  827. COUNTRY_CHPLAN_ENT("SV", 0x30, 1, 0x1F1), /* El Salvador */
  828. COUNTRY_CHPLAN_ENT("SX", 0x34, 1, 0x000), /* Sint Marteen */
  829. COUNTRY_CHPLAN_ENT("SZ", 0x26, 1, 0x020), /* Swaziland */
  830. COUNTRY_CHPLAN_ENT("TC", 0x26, 1, 0x000), /* Turks and Caicos Islands (UK) */
  831. COUNTRY_CHPLAN_ENT("TD", 0x26, 1, 0x0B0), /* Chad */
  832. COUNTRY_CHPLAN_ENT("TF", 0x26, 1, 0x080), /* French Southern and Antarctic Lands (FR Southern Territories) */
  833. COUNTRY_CHPLAN_ENT("TG", 0x26, 1, 0x0B0), /* Togo */
  834. COUNTRY_CHPLAN_ENT("TH", 0x26, 1, 0x1F1), /* Thailand */
  835. COUNTRY_CHPLAN_ENT("TJ", 0x26, 1, 0x040), /* Tajikistan */
  836. COUNTRY_CHPLAN_ENT("TK", 0x45, 1, 0x000), /* Tokelau */
  837. COUNTRY_CHPLAN_ENT("TM", 0x26, 1, 0x000), /* Turkmenistan */
  838. COUNTRY_CHPLAN_ENT("TN", 0x47, 1, 0x1F1), /* Tunisia */
  839. COUNTRY_CHPLAN_ENT("TO", 0x26, 1, 0x000), /* Tonga */
  840. COUNTRY_CHPLAN_ENT("TR", 0x26, 1, 0x1F1), /* Turkey, Northern Cyprus */
  841. COUNTRY_CHPLAN_ENT("TT", 0x42, 1, 0x1F1), /* Trinidad & Tobago */
  842. COUNTRY_CHPLAN_ENT("TW", 0x62, 1, 0x1FF), /* Taiwan */
  843. COUNTRY_CHPLAN_ENT("TZ", 0x26, 1, 0x0F0), /* Tanzania */
  844. COUNTRY_CHPLAN_ENT("UA", 0x36, 1, 0x1FB), /* Ukraine */
  845. COUNTRY_CHPLAN_ENT("UG", 0x26, 1, 0x0F1), /* Uganda */
  846. COUNTRY_CHPLAN_ENT("US", 0x62, 1, 0x1FF), /* United States of America (USA) */
  847. COUNTRY_CHPLAN_ENT("UY", 0x34, 1, 0x1F1), /* Uruguay */
  848. COUNTRY_CHPLAN_ENT("UZ", 0x47, 1, 0x0F0), /* Uzbekistan */
  849. COUNTRY_CHPLAN_ENT("VA", 0x26, 1, 0x000), /* Holy See (Vatican City) */
  850. COUNTRY_CHPLAN_ENT("VC", 0x34, 1, 0x010), /* Saint Vincent and the Grenadines */
  851. COUNTRY_CHPLAN_ENT("VE", 0x30, 1, 0x1F1), /* Venezuela */
  852. COUNTRY_CHPLAN_ENT("VI", 0x34, 1, 0x000), /* United States Virgin Islands (USA) */
  853. COUNTRY_CHPLAN_ENT("VN", 0x26, 1, 0x1F1), /* Vietnam */
  854. COUNTRY_CHPLAN_ENT("VU", 0x26, 1, 0x000), /* Vanuatu */
  855. COUNTRY_CHPLAN_ENT("WF", 0x26, 1, 0x000), /* Wallis and Futuna (France) */
  856. COUNTRY_CHPLAN_ENT("WS", 0x34, 1, 0x000), /* Samoa */
  857. COUNTRY_CHPLAN_ENT("YE", 0x26, 1, 0x040), /* Yemen */
  858. COUNTRY_CHPLAN_ENT("YT", 0x26, 1, 0x080), /* Mayotte (France) */
  859. COUNTRY_CHPLAN_ENT("ZA", 0x26, 1, 0x1F1), /* South Africa */
  860. COUNTRY_CHPLAN_ENT("ZM", 0x26, 1, 0x0B0), /* Zambia */
  861. COUNTRY_CHPLAN_ENT("ZW", 0x26, 1, 0x1F1), /* Zimbabwe */
  862. };
  863. /*
  864. * rtw_get_chplan_from_country -
  865. * @country_code: string of country code
  866. *
  867. * Return pointer of struct country_chplan entry or NULL when unsupported country_code is given
  868. */
  869. const struct country_chplan *rtw_get_chplan_from_country(const char *country_code)
  870. {
  871. const struct country_chplan *ent = NULL;
  872. const struct country_chplan *map = NULL;
  873. u16 map_sz = 0;
  874. char code[2];
  875. int i;
  876. code[0] = alpha_to_upper(country_code[0]);
  877. code[1] = alpha_to_upper(country_code[1]);
  878. #if !defined(CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP) && RTW_DEF_MODULE_REGULATORY_CERT
  879. ent = rtw_def_module_get_chplan_from_country(code);
  880. if (ent != NULL)
  881. goto exit;
  882. #endif
  883. #ifdef CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP
  884. map = CUSTOMIZED_country_chplan_map;
  885. map_sz = sizeof(CUSTOMIZED_country_chplan_map) / sizeof(struct country_chplan);
  886. #else
  887. map = country_chplan_map;
  888. map_sz = sizeof(country_chplan_map) / sizeof(struct country_chplan);
  889. #endif
  890. for (i = 0; i < map_sz; i++) {
  891. if (strncmp(code, map[i].alpha2, 2) == 0) {
  892. ent = &map[i];
  893. break;
  894. }
  895. }
  896. exit:
  897. #if RTW_DEF_MODULE_REGULATORY_CERT
  898. if (ent && !(COUNTRY_CHPLAN_DEF_MODULE_FALGS(ent) & RTW_DEF_MODULE_REGULATORY_CERT))
  899. ent = NULL;
  900. #endif
  901. return ent;
  902. }
  903. int rtw_ch_to_bb_gain_sel(int ch)
  904. {
  905. int sel = -1;
  906. if (ch >= 1 && ch <= 14)
  907. sel = BB_GAIN_2G;
  908. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  909. else if (ch >= 36 && ch < 48)
  910. sel = BB_GAIN_5GLB1;
  911. else if (ch >= 52 && ch <= 64)
  912. sel = BB_GAIN_5GLB2;
  913. else if (ch >= 100 && ch <= 120)
  914. sel = BB_GAIN_5GMB1;
  915. else if (ch >= 124 && ch <= 144)
  916. sel = BB_GAIN_5GMB2;
  917. else if (ch >= 149 && ch <= 177)
  918. sel = BB_GAIN_5GHB;
  919. #endif
  920. return sel;
  921. }
  922. s8 rtw_rf_get_kfree_tx_gain_offset(_adapter *padapter, u8 path, u8 ch)
  923. {
  924. s8 kfree_offset = 0;
  925. #ifdef CONFIG_RF_POWER_TRIM
  926. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
  927. struct kfree_data_t *kfree_data = GET_KFREE_DATA(padapter);
  928. s8 bb_gain_sel = rtw_ch_to_bb_gain_sel(ch);
  929. if (bb_gain_sel < BB_GAIN_2G || bb_gain_sel >= BB_GAIN_NUM) {
  930. rtw_warn_on(1);
  931. goto exit;
  932. }
  933. if (kfree_data->flag & KFREE_FLAG_ON) {
  934. kfree_offset = kfree_data->bb_gain[bb_gain_sel][path];
  935. if (IS_HARDWARE_TYPE_8723D(padapter))
  936. RTW_INFO("%s path:%s, ch:%u, bb_gain_sel:%d, kfree_offset:%d\n"
  937. , __func__, (path == 0)?"S1":"S0",
  938. ch, bb_gain_sel, kfree_offset);
  939. else
  940. RTW_INFO("%s path:%u, ch:%u, bb_gain_sel:%d, kfree_offset:%d\n"
  941. , __func__, path, ch, bb_gain_sel, kfree_offset);
  942. }
  943. exit:
  944. #endif /* CONFIG_RF_POWER_TRIM */
  945. return kfree_offset;
  946. }
  947. void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset)
  948. {
  949. u8 write_value;
  950. u8 target_path = 0;
  951. u32 val32 = 0;
  952. if (IS_HARDWARE_TYPE_8723D(adapter)) {
  953. target_path = RF_PATH_A; /*in 8723D case path means S0/S1*/
  954. if (path == PPG_8723D_S1)
  955. RTW_INFO("kfree gain_offset 0x55:0x%x ",
  956. rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff));
  957. else if (path == PPG_8723D_S0)
  958. RTW_INFO("kfree gain_offset 0x65:0x%x ",
  959. rtw_hal_read_rfreg(adapter, target_path, 0x65, 0xffffffff));
  960. } else {
  961. target_path = path;
  962. RTW_INFO("kfree gain_offset 0x55:0x%x ", rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff));
  963. }
  964. switch (rtw_get_chip_type(adapter)) {
  965. #ifdef CONFIG_RTL8723D
  966. case RTL8723D:
  967. write_value = RF_TX_GAIN_OFFSET_8723D(offset);
  968. if (path == PPG_8723D_S1)
  969. rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
  970. else if (path == PPG_8723D_S0)
  971. rtw_hal_write_rfreg(adapter, target_path, 0x65, 0x0f8000, write_value);
  972. break;
  973. #endif /* CONFIG_RTL8723D */
  974. #ifdef CONFIG_RTL8703B
  975. case RTL8703B:
  976. write_value = RF_TX_GAIN_OFFSET_8703B(offset);
  977. rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0fc000, write_value);
  978. break;
  979. #endif /* CONFIG_RTL8703B */
  980. #ifdef CONFIG_RTL8188F
  981. case RTL8188F:
  982. write_value = RF_TX_GAIN_OFFSET_8188F(offset);
  983. rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0fc000, write_value);
  984. break;
  985. #endif /* CONFIG_RTL8188F */
  986. #ifdef CONFIG_RTL8192E
  987. case RTL8192E:
  988. write_value = RF_TX_GAIN_OFFSET_8192E(offset);
  989. rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
  990. break;
  991. #endif /* CONFIG_RTL8188F */
  992. #ifdef CONFIG_RTL8821A
  993. case RTL8821:
  994. write_value = RF_TX_GAIN_OFFSET_8821A(offset);
  995. rtw_hal_write_rfreg(adapter, target_path, 0x55, 0x0f8000, write_value);
  996. break;
  997. #endif /* CONFIG_RTL8821A */
  998. #if defined(CONFIG_RTL8814A) || defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C)
  999. case RTL8814A:
  1000. case RTL8822B:
  1001. case RTL8821C:
  1002. RTW_INFO("\nkfree by PhyDM on the sw CH. path %d\n", path);
  1003. break;
  1004. #endif /* CONFIG_RTL8814A || CONFIG_RTL8822B || CONFIG_RTL8821C */
  1005. default:
  1006. rtw_warn_on(1);
  1007. break;
  1008. }
  1009. if (IS_HARDWARE_TYPE_8723D(adapter)) {
  1010. if (path == PPG_8723D_S1)
  1011. val32 = rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff);
  1012. else if (path == PPG_8723D_S0)
  1013. val32 = rtw_hal_read_rfreg(adapter, target_path, 0x65, 0xffffffff);
  1014. } else {
  1015. val32 = rtw_hal_read_rfreg(adapter, target_path, 0x55, 0xffffffff);
  1016. }
  1017. RTW_INFO(" after :0x%x\n", val32);
  1018. }
  1019. void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch)
  1020. {
  1021. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  1022. s8 kfree_offset = 0;
  1023. s8 tx_pwr_track_offset = 0; /* TODO: 8814A should consider tx pwr track when setting tx gain offset */
  1024. s8 total_offset;
  1025. int i, total = 0;
  1026. if (IS_HARDWARE_TYPE_8723D(adapter))
  1027. total = 2; /* S1 and S0 */
  1028. else
  1029. total = hal_data->NumTotalRFPath;
  1030. for (i = 0; i < total; i++) {
  1031. kfree_offset = rtw_rf_get_kfree_tx_gain_offset(adapter, i, ch);
  1032. total_offset = kfree_offset + tx_pwr_track_offset;
  1033. rtw_rf_set_tx_gain_offset(adapter, i, total_offset);
  1034. }
  1035. }
  1036. inline u8 rtw_is_5g_band1(u8 ch)
  1037. {
  1038. if (ch >= 36 && ch <= 48)
  1039. return 1;
  1040. return 0;
  1041. }
  1042. inline u8 rtw_is_5g_band2(u8 ch)
  1043. {
  1044. if (ch >= 52 && ch <= 64)
  1045. return 1;
  1046. return 0;
  1047. }
  1048. inline u8 rtw_is_5g_band3(u8 ch)
  1049. {
  1050. if (ch >= 100 && ch <= 144)
  1051. return 1;
  1052. return 0;
  1053. }
  1054. inline u8 rtw_is_5g_band4(u8 ch)
  1055. {
  1056. if (ch >= 149 && ch <= 177)
  1057. return 1;
  1058. return 0;
  1059. }
  1060. inline u8 rtw_is_dfs_range(u32 hi, u32 lo)
  1061. {
  1062. return rtw_is_range_overlap(hi, lo, 5720 + 10, 5260 - 10);
  1063. }
  1064. u8 rtw_is_dfs_ch(u8 ch)
  1065. {
  1066. u32 hi, lo;
  1067. if (!rtw_chbw_to_freq_range(ch, CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE, &hi, &lo))
  1068. return 0;
  1069. return rtw_is_dfs_range(hi, lo);
  1070. }
  1071. u8 rtw_is_dfs_chbw(u8 ch, u8 bw, u8 offset)
  1072. {
  1073. u32 hi, lo;
  1074. if (!rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo))
  1075. return 0;
  1076. return rtw_is_dfs_range(hi, lo);
  1077. }
  1078. bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region)
  1079. {
  1080. return (dfs_region == PHYDM_DFS_DOMAIN_ETSI && rtw_is_range_overlap(hi, lo, 5660 + 10, 5600 - 10)) ? _TRUE : _FALSE;
  1081. }
  1082. bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region)
  1083. {
  1084. u32 hi, lo;
  1085. if (rtw_chbw_to_freq_range(ch, bw, offset, &hi, &lo) == _FALSE)
  1086. return _FALSE;
  1087. return rtw_is_long_cac_range(hi, lo, dfs_region) ? _TRUE : _FALSE;
  1088. }