mac.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. ****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../pci.h"
  27. #include "../usb.h"
  28. #include "../ps.h"
  29. #include "../cam.h"
  30. #include "../stats.h"
  31. #include "reg.h"
  32. #include "def.h"
  33. #include "phy.h"
  34. #include "rf.h"
  35. #include "dm.h"
  36. #include "mac.h"
  37. #include "trx.h"
  38. #include "../rtl8192c/fw_common.h"
  39. #include <linux/module.h>
  40. /* macro to shorten lines */
  41. #define LINK_Q ui_link_quality
  42. #define RX_EVM rx_evm_percentage
  43. #define RX_SIGQ rx_mimo_sig_qual
  44. void rtl92c_read_chip_version(struct ieee80211_hw *hw)
  45. {
  46. struct rtl_priv *rtlpriv = rtl_priv(hw);
  47. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  48. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  49. enum version_8192c chip_version = VERSION_UNKNOWN;
  50. const char *versionid;
  51. u32 value32;
  52. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  53. if (value32 & TRP_VAUX_EN) {
  54. chip_version = (value32 & TYPE_ID) ? VERSION_TEST_CHIP_92C :
  55. VERSION_TEST_CHIP_88C;
  56. } else {
  57. /* Normal mass production chip. */
  58. chip_version = NORMAL_CHIP;
  59. chip_version |= ((value32 & TYPE_ID) ? CHIP_92C : 0);
  60. chip_version |= ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0);
  61. if (IS_VENDOR_UMC(chip_version))
  62. chip_version |= ((value32 & CHIP_VER_RTL_MASK) ?
  63. CHIP_VENDOR_UMC_B_CUT : 0);
  64. if (IS_92C_SERIAL(chip_version)) {
  65. value32 = rtl_read_dword(rtlpriv, REG_HPON_FSM);
  66. chip_version |= ((CHIP_BONDING_IDENTIFIER(value32) ==
  67. CHIP_BONDING_92C_1T2R) ? CHIP_92C_1T2R : 0);
  68. }
  69. }
  70. rtlhal->version = (enum version_8192c)chip_version;
  71. pr_info("Chip version 0x%x\n", chip_version);
  72. switch (rtlhal->version) {
  73. case VERSION_NORMAL_TSMC_CHIP_92C_1T2R:
  74. versionid = "NORMAL_B_CHIP_92C";
  75. break;
  76. case VERSION_NORMAL_TSMC_CHIP_92C:
  77. versionid = "NORMAL_TSMC_CHIP_92C";
  78. break;
  79. case VERSION_NORMAL_TSMC_CHIP_88C:
  80. versionid = "NORMAL_TSMC_CHIP_88C";
  81. break;
  82. case VERSION_NORMAL_UMC_CHIP_92C_1T2R_A_CUT:
  83. versionid = "NORMAL_UMC_CHIP_i92C_1T2R_A_CUT";
  84. break;
  85. case VERSION_NORMAL_UMC_CHIP_92C_A_CUT:
  86. versionid = "NORMAL_UMC_CHIP_92C_A_CUT";
  87. break;
  88. case VERSION_NORMAL_UMC_CHIP_88C_A_CUT:
  89. versionid = "NORMAL_UMC_CHIP_88C_A_CUT";
  90. break;
  91. case VERSION_NORMAL_UMC_CHIP_92C_1T2R_B_CUT:
  92. versionid = "NORMAL_UMC_CHIP_92C_1T2R_B_CUT";
  93. break;
  94. case VERSION_NORMAL_UMC_CHIP_92C_B_CUT:
  95. versionid = "NORMAL_UMC_CHIP_92C_B_CUT";
  96. break;
  97. case VERSION_NORMAL_UMC_CHIP_88C_B_CUT:
  98. versionid = "NORMAL_UMC_CHIP_88C_B_CUT";
  99. break;
  100. case VERSION_TEST_CHIP_92C:
  101. versionid = "TEST_CHIP_92C";
  102. break;
  103. case VERSION_TEST_CHIP_88C:
  104. versionid = "TEST_CHIP_88C";
  105. break;
  106. default:
  107. versionid = "UNKNOWN";
  108. break;
  109. }
  110. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  111. "Chip Version ID: %s\n", versionid);
  112. if (IS_92C_SERIAL(rtlhal->version))
  113. rtlphy->rf_type =
  114. (IS_92C_1T2R(rtlhal->version)) ? RF_1T2R : RF_2T2R;
  115. else
  116. rtlphy->rf_type = RF_1T1R;
  117. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  118. "Chip RF Type: %s\n",
  119. rtlphy->rf_type == RF_2T2R ? "RF_2T2R" : "RF_1T1R");
  120. if (get_rf_type(rtlphy) == RF_1T1R)
  121. rtlpriv->dm.rfpath_rxenable[0] = true;
  122. else
  123. rtlpriv->dm.rfpath_rxenable[0] =
  124. rtlpriv->dm.rfpath_rxenable[1] = true;
  125. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  126. rtlhal->version);
  127. }
  128. /**
  129. * writeLLT - LLT table write access
  130. * @io: io callback
  131. * @address: LLT logical address.
  132. * @data: LLT data content
  133. *
  134. * Realtek hardware access function.
  135. *
  136. */
  137. bool rtl92c_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  138. {
  139. struct rtl_priv *rtlpriv = rtl_priv(hw);
  140. bool status = true;
  141. long count = 0;
  142. u32 value = _LLT_INIT_ADDR(address) |
  143. _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
  144. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  145. do {
  146. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  147. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  148. break;
  149. if (count > POLLING_LLT_THRESHOLD) {
  150. pr_err("Failed to polling write LLT done at address %d! _LLT_OP_VALUE(%x)\n",
  151. address, _LLT_OP_VALUE(value));
  152. status = false;
  153. break;
  154. }
  155. } while (++count);
  156. return status;
  157. }
  158. /**
  159. * rtl92c_init_LLT_table - Init LLT table
  160. * @io: io callback
  161. * @boundary:
  162. *
  163. * Realtek hardware access function.
  164. *
  165. */
  166. bool rtl92c_init_llt_table(struct ieee80211_hw *hw, u32 boundary)
  167. {
  168. bool rst = true;
  169. u32 i;
  170. for (i = 0; i < (boundary - 1); i++) {
  171. rst = rtl92c_llt_write(hw, i , i + 1);
  172. if (true != rst) {
  173. pr_err("===> %s #1 fail\n", __func__);
  174. return rst;
  175. }
  176. }
  177. /* end of list */
  178. rst = rtl92c_llt_write(hw, (boundary - 1), 0xFF);
  179. if (true != rst) {
  180. pr_err("===> %s #2 fail\n", __func__);
  181. return rst;
  182. }
  183. /* Make the other pages as ring buffer
  184. * This ring buffer is used as beacon buffer if we config this MAC
  185. * as two MAC transfer.
  186. * Otherwise used as local loopback buffer.
  187. */
  188. for (i = boundary; i < LLT_LAST_ENTRY_OF_TX_PKT_BUFFER; i++) {
  189. rst = rtl92c_llt_write(hw, i, (i + 1));
  190. if (true != rst) {
  191. pr_err("===> %s #3 fail\n", __func__);
  192. return rst;
  193. }
  194. }
  195. /* Let last entry point to the start entry of ring buffer */
  196. rst = rtl92c_llt_write(hw, LLT_LAST_ENTRY_OF_TX_PKT_BUFFER, boundary);
  197. if (true != rst) {
  198. pr_err("===> %s #4 fail\n", __func__);
  199. return rst;
  200. }
  201. return rst;
  202. }
  203. void rtl92c_set_key(struct ieee80211_hw *hw, u32 key_index,
  204. u8 *p_macaddr, bool is_group, u8 enc_algo,
  205. bool is_wepkey, bool clear_all)
  206. {
  207. struct rtl_priv *rtlpriv = rtl_priv(hw);
  208. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  209. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  210. u8 *macaddr = p_macaddr;
  211. u32 entry_id = 0;
  212. bool is_pairwise = false;
  213. static u8 cam_const_addr[4][6] = {
  214. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  215. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  216. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  217. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  218. };
  219. static u8 cam_const_broad[] = {
  220. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  221. };
  222. if (clear_all) {
  223. u8 idx = 0;
  224. u8 cam_offset = 0;
  225. u8 clear_number = 5;
  226. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  227. for (idx = 0; idx < clear_number; idx++) {
  228. rtl_cam_mark_invalid(hw, cam_offset + idx);
  229. rtl_cam_empty_entry(hw, cam_offset + idx);
  230. if (idx < 5) {
  231. memset(rtlpriv->sec.key_buf[idx], 0,
  232. MAX_KEY_LEN);
  233. rtlpriv->sec.key_len[idx] = 0;
  234. }
  235. }
  236. } else {
  237. switch (enc_algo) {
  238. case WEP40_ENCRYPTION:
  239. enc_algo = CAM_WEP40;
  240. break;
  241. case WEP104_ENCRYPTION:
  242. enc_algo = CAM_WEP104;
  243. break;
  244. case TKIP_ENCRYPTION:
  245. enc_algo = CAM_TKIP;
  246. break;
  247. case AESCCMP_ENCRYPTION:
  248. enc_algo = CAM_AES;
  249. break;
  250. default:
  251. pr_err("illegal switch case\n");
  252. enc_algo = CAM_TKIP;
  253. break;
  254. }
  255. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  256. macaddr = cam_const_addr[key_index];
  257. entry_id = key_index;
  258. } else {
  259. if (is_group) {
  260. macaddr = cam_const_broad;
  261. entry_id = key_index;
  262. } else {
  263. if (mac->opmode == NL80211_IFTYPE_AP ||
  264. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  265. entry_id = rtl_cam_get_free_entry(hw,
  266. p_macaddr);
  267. if (entry_id >= TOTAL_CAM_ENTRY) {
  268. pr_err("Can not find free hw security cam entry\n");
  269. return;
  270. }
  271. } else {
  272. entry_id = CAM_PAIRWISE_KEY_POSITION;
  273. }
  274. key_index = PAIRWISE_KEYIDX;
  275. is_pairwise = true;
  276. }
  277. }
  278. if (rtlpriv->sec.key_len[key_index] == 0) {
  279. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  280. "delete one entry\n");
  281. if (mac->opmode == NL80211_IFTYPE_AP ||
  282. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  283. rtl_cam_del_entry(hw, p_macaddr);
  284. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  285. } else {
  286. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  287. "The insert KEY length is %d\n",
  288. rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
  289. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  290. "The insert KEY is %x %x\n",
  291. rtlpriv->sec.key_buf[0][0],
  292. rtlpriv->sec.key_buf[0][1]);
  293. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  294. "add one entry\n");
  295. if (is_pairwise) {
  296. RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
  297. "Pairwise Key content",
  298. rtlpriv->sec.pairwise_key,
  299. rtlpriv->sec.
  300. key_len[PAIRWISE_KEYIDX]);
  301. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  302. "set Pairwise key\n");
  303. rtl_cam_add_one_entry(hw, macaddr, key_index,
  304. entry_id, enc_algo,
  305. CAM_CONFIG_NO_USEDK,
  306. rtlpriv->sec.
  307. key_buf[key_index]);
  308. } else {
  309. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  310. "set group key\n");
  311. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  312. rtl_cam_add_one_entry(hw,
  313. rtlefuse->dev_addr,
  314. PAIRWISE_KEYIDX,
  315. CAM_PAIRWISE_KEY_POSITION,
  316. enc_algo,
  317. CAM_CONFIG_NO_USEDK,
  318. rtlpriv->sec.key_buf
  319. [entry_id]);
  320. }
  321. rtl_cam_add_one_entry(hw, macaddr, key_index,
  322. entry_id, enc_algo,
  323. CAM_CONFIG_NO_USEDK,
  324. rtlpriv->sec.key_buf[entry_id]);
  325. }
  326. }
  327. }
  328. }
  329. u32 rtl92c_get_txdma_status(struct ieee80211_hw *hw)
  330. {
  331. struct rtl_priv *rtlpriv = rtl_priv(hw);
  332. return rtl_read_dword(rtlpriv, REG_TXDMA_STATUS);
  333. }
  334. void rtl92c_enable_interrupt(struct ieee80211_hw *hw)
  335. {
  336. struct rtl_priv *rtlpriv = rtl_priv(hw);
  337. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  338. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  339. struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
  340. if (IS_HARDWARE_TYPE_8192CE(rtlhal)) {
  341. rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] &
  342. 0xFFFFFFFF);
  343. rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] &
  344. 0xFFFFFFFF);
  345. } else {
  346. rtl_write_dword(rtlpriv, REG_HIMR, rtlusb->irq_mask[0] &
  347. 0xFFFFFFFF);
  348. rtl_write_dword(rtlpriv, REG_HIMRE, rtlusb->irq_mask[1] &
  349. 0xFFFFFFFF);
  350. }
  351. }
  352. void rtl92c_init_interrupt(struct ieee80211_hw *hw)
  353. {
  354. rtl92c_enable_interrupt(hw);
  355. }
  356. void rtl92c_disable_interrupt(struct ieee80211_hw *hw)
  357. {
  358. struct rtl_priv *rtlpriv = rtl_priv(hw);
  359. rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
  360. rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
  361. }
  362. void rtl92c_set_qos(struct ieee80211_hw *hw, int aci)
  363. {
  364. struct rtl_priv *rtlpriv = rtl_priv(hw);
  365. rtl92c_dm_init_edca_turbo(hw);
  366. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, (u8 *)&aci);
  367. }
  368. void rtl92c_init_driver_info_size(struct ieee80211_hw *hw, u8 size)
  369. {
  370. struct rtl_priv *rtlpriv = rtl_priv(hw);
  371. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, size);
  372. }
  373. int rtl92c_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
  374. {
  375. u8 value;
  376. struct rtl_priv *rtlpriv = rtl_priv(hw);
  377. switch (type) {
  378. case NL80211_IFTYPE_UNSPECIFIED:
  379. value = NT_NO_LINK;
  380. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  381. "Set Network type to NO LINK!\n");
  382. break;
  383. case NL80211_IFTYPE_ADHOC:
  384. value = NT_LINK_AD_HOC;
  385. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  386. "Set Network type to Ad Hoc!\n");
  387. break;
  388. case NL80211_IFTYPE_STATION:
  389. value = NT_LINK_AP;
  390. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  391. "Set Network type to STA!\n");
  392. break;
  393. case NL80211_IFTYPE_AP:
  394. value = NT_AS_AP;
  395. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  396. "Set Network type to AP!\n");
  397. break;
  398. default:
  399. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  400. "Network type %d not supported!\n", type);
  401. return -EOPNOTSUPP;
  402. }
  403. rtl_write_byte(rtlpriv, MSR, value);
  404. return 0;
  405. }
  406. void rtl92c_init_network_type(struct ieee80211_hw *hw)
  407. {
  408. rtl92c_set_network_type(hw, NL80211_IFTYPE_UNSPECIFIED);
  409. }
  410. void rtl92c_init_adaptive_ctrl(struct ieee80211_hw *hw)
  411. {
  412. u16 value16;
  413. u32 value32;
  414. struct rtl_priv *rtlpriv = rtl_priv(hw);
  415. /* Response Rate Set */
  416. value32 = rtl_read_dword(rtlpriv, REG_RRSR);
  417. value32 &= ~RATE_BITMAP_ALL;
  418. value32 |= RATE_RRSR_CCK_ONLY_1M;
  419. rtl_write_dword(rtlpriv, REG_RRSR, value32);
  420. /* SIFS (used in NAV) */
  421. value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
  422. rtl_write_word(rtlpriv, REG_SPEC_SIFS, value16);
  423. /* Retry Limit */
  424. value16 = _LRL(0x30) | _SRL(0x30);
  425. rtl_write_dword(rtlpriv, REG_RL, value16);
  426. }
  427. void rtl92c_init_rate_fallback(struct ieee80211_hw *hw)
  428. {
  429. struct rtl_priv *rtlpriv = rtl_priv(hw);
  430. /* Set Data Auto Rate Fallback Retry Count register. */
  431. rtl_write_dword(rtlpriv, REG_DARFRC, 0x00000000);
  432. rtl_write_dword(rtlpriv, REG_DARFRC+4, 0x10080404);
  433. rtl_write_dword(rtlpriv, REG_RARFRC, 0x04030201);
  434. rtl_write_dword(rtlpriv, REG_RARFRC+4, 0x08070605);
  435. }
  436. static void rtl92c_set_cck_sifs(struct ieee80211_hw *hw, u8 trx_sifs,
  437. u8 ctx_sifs)
  438. {
  439. struct rtl_priv *rtlpriv = rtl_priv(hw);
  440. rtl_write_byte(rtlpriv, REG_SIFS_CCK, trx_sifs);
  441. rtl_write_byte(rtlpriv, (REG_SIFS_CCK + 1), ctx_sifs);
  442. }
  443. static void rtl92c_set_ofdm_sifs(struct ieee80211_hw *hw, u8 trx_sifs,
  444. u8 ctx_sifs)
  445. {
  446. struct rtl_priv *rtlpriv = rtl_priv(hw);
  447. rtl_write_byte(rtlpriv, REG_SIFS_OFDM, trx_sifs);
  448. rtl_write_byte(rtlpriv, (REG_SIFS_OFDM + 1), ctx_sifs);
  449. }
  450. void rtl92c_init_edca_param(struct ieee80211_hw *hw,
  451. u16 queue, u16 txop, u8 cw_min, u8 cw_max, u8 aifs)
  452. {
  453. /* sequence: VO, VI, BE, BK ==> the same as 92C hardware design.
  454. * referenc : enum nl80211_txq_q or ieee80211_set_wmm_default function.
  455. */
  456. u32 value;
  457. struct rtl_priv *rtlpriv = rtl_priv(hw);
  458. value = (u32)aifs;
  459. value |= ((u32)cw_min & 0xF) << 8;
  460. value |= ((u32)cw_max & 0xF) << 12;
  461. value |= (u32)txop << 16;
  462. /* 92C hardware register sequence is the same as queue number. */
  463. rtl_write_dword(rtlpriv, (REG_EDCA_VO_PARAM + (queue * 4)), value);
  464. }
  465. void rtl92c_init_edca(struct ieee80211_hw *hw)
  466. {
  467. u16 value16;
  468. struct rtl_priv *rtlpriv = rtl_priv(hw);
  469. /* disable EDCCA count down, to reduce collison and retry */
  470. value16 = rtl_read_word(rtlpriv, REG_RD_CTRL);
  471. value16 |= DIS_EDCA_CNT_DWN;
  472. rtl_write_word(rtlpriv, REG_RD_CTRL, value16);
  473. /* Update SIFS timing. ??????????
  474. * pHalData->SifsTime = 0x0e0e0a0a; */
  475. rtl92c_set_cck_sifs(hw, 0xa, 0xa);
  476. rtl92c_set_ofdm_sifs(hw, 0xe, 0xe);
  477. /* Set CCK/OFDM SIFS to be 10us. */
  478. rtl_write_word(rtlpriv, REG_SIFS_CCK, 0x0a0a);
  479. rtl_write_word(rtlpriv, REG_SIFS_OFDM, 0x1010);
  480. rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0204);
  481. rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x014004);
  482. /* TXOP */
  483. rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, 0x005EA42B);
  484. rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0x0000A44F);
  485. rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x005EA324);
  486. rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x002FA226);
  487. /* PIFS */
  488. rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
  489. /* AGGR BREAK TIME Register */
  490. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  491. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0040);
  492. rtl_write_byte(rtlpriv, REG_BCNDMATIM, 0x02);
  493. rtl_write_byte(rtlpriv, REG_ATIMWND, 0x02);
  494. }
  495. void rtl92c_init_ampdu_aggregation(struct ieee80211_hw *hw)
  496. {
  497. struct rtl_priv *rtlpriv = rtl_priv(hw);
  498. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x99997631);
  499. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  500. /* init AMPDU aggregation number, tuning for Tx's TP, */
  501. rtl_write_word(rtlpriv, 0x4CA, 0x0708);
  502. }
  503. void rtl92c_init_beacon_max_error(struct ieee80211_hw *hw)
  504. {
  505. struct rtl_priv *rtlpriv = rtl_priv(hw);
  506. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xFF);
  507. }
  508. void rtl92c_init_rdg_setting(struct ieee80211_hw *hw)
  509. {
  510. struct rtl_priv *rtlpriv = rtl_priv(hw);
  511. rtl_write_byte(rtlpriv, REG_RD_CTRL, 0xFF);
  512. rtl_write_word(rtlpriv, REG_RD_NAV_NXT, 0x200);
  513. rtl_write_byte(rtlpriv, REG_RD_RESP_PKT_TH, 0x05);
  514. }
  515. void rtl92c_init_retry_function(struct ieee80211_hw *hw)
  516. {
  517. u8 value8;
  518. struct rtl_priv *rtlpriv = rtl_priv(hw);
  519. value8 = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL);
  520. value8 |= EN_AMPDU_RTY_NEW;
  521. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL, value8);
  522. /* Set ACK timeout */
  523. rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
  524. }
  525. void rtl92c_disable_fast_edca(struct ieee80211_hw *hw)
  526. {
  527. struct rtl_priv *rtlpriv = rtl_priv(hw);
  528. rtl_write_word(rtlpriv, REG_FAST_EDCA_CTRL, 0);
  529. }
  530. void rtl92c_set_min_space(struct ieee80211_hw *hw, bool is2T)
  531. {
  532. struct rtl_priv *rtlpriv = rtl_priv(hw);
  533. u8 value = is2T ? MAX_MSS_DENSITY_2T : MAX_MSS_DENSITY_1T;
  534. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, value);
  535. }
  536. /*==============================================================*/
  537. static u8 _rtl92c_query_rxpwrpercentage(s8 antpower)
  538. {
  539. if ((antpower <= -100) || (antpower >= 20))
  540. return 0;
  541. else if (antpower >= 0)
  542. return 100;
  543. else
  544. return 100 + antpower;
  545. }
  546. static u8 _rtl92c_evm_db_to_percentage(s8 value)
  547. {
  548. s8 ret_val;
  549. ret_val = value;
  550. if (ret_val >= 0)
  551. ret_val = 0;
  552. if (ret_val <= -33)
  553. ret_val = -33;
  554. ret_val = 0 - ret_val;
  555. ret_val *= 3;
  556. if (ret_val == 99)
  557. ret_val = 100;
  558. return ret_val;
  559. }
  560. static long _rtl92c_signal_scale_mapping(struct ieee80211_hw *hw,
  561. long currsig)
  562. {
  563. long retsig;
  564. if (currsig >= 61 && currsig <= 100)
  565. retsig = 90 + ((currsig - 60) / 4);
  566. else if (currsig >= 41 && currsig <= 60)
  567. retsig = 78 + ((currsig - 40) / 2);
  568. else if (currsig >= 31 && currsig <= 40)
  569. retsig = 66 + (currsig - 30);
  570. else if (currsig >= 21 && currsig <= 30)
  571. retsig = 54 + (currsig - 20);
  572. else if (currsig >= 5 && currsig <= 20)
  573. retsig = 42 + (((currsig - 5) * 2) / 3);
  574. else if (currsig == 4)
  575. retsig = 36;
  576. else if (currsig == 3)
  577. retsig = 27;
  578. else if (currsig == 2)
  579. retsig = 18;
  580. else if (currsig == 1)
  581. retsig = 9;
  582. else
  583. retsig = currsig;
  584. return retsig;
  585. }
  586. static void _rtl92c_query_rxphystatus(struct ieee80211_hw *hw,
  587. struct rtl_stats *pstats,
  588. struct rx_desc_92c *p_desc,
  589. struct rx_fwinfo_92c *p_drvinfo,
  590. bool packet_match_bssid,
  591. bool packet_toself,
  592. bool packet_beacon)
  593. {
  594. struct rtl_priv *rtlpriv = rtl_priv(hw);
  595. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  596. struct phy_sts_cck_8192s_t *cck_buf;
  597. s8 rx_pwr_all = 0, rx_pwr[4];
  598. u8 rf_rx_num = 0, evm, pwdb_all;
  599. u8 i, max_spatial_stream;
  600. u32 rssi, total_rssi = 0;
  601. bool in_powersavemode = false;
  602. bool is_cck_rate;
  603. u8 *pdesc = (u8 *)p_desc;
  604. is_cck_rate = RX_HAL_IS_CCK_RATE(p_desc->rxmcs);
  605. pstats->packet_matchbssid = packet_match_bssid;
  606. pstats->packet_toself = packet_toself;
  607. pstats->packet_beacon = packet_beacon;
  608. pstats->is_cck = is_cck_rate;
  609. pstats->RX_SIGQ[0] = -1;
  610. pstats->RX_SIGQ[1] = -1;
  611. if (is_cck_rate) {
  612. u8 report, cck_highpwr;
  613. cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
  614. if (!in_powersavemode)
  615. cck_highpwr = rtlphy->cck_high_power;
  616. else
  617. cck_highpwr = false;
  618. if (!cck_highpwr) {
  619. u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
  620. report = cck_buf->cck_agc_rpt & 0xc0;
  621. report = report >> 6;
  622. switch (report) {
  623. case 0x3:
  624. rx_pwr_all = -46 - (cck_agc_rpt & 0x3e);
  625. break;
  626. case 0x2:
  627. rx_pwr_all = -26 - (cck_agc_rpt & 0x3e);
  628. break;
  629. case 0x1:
  630. rx_pwr_all = -12 - (cck_agc_rpt & 0x3e);
  631. break;
  632. case 0x0:
  633. rx_pwr_all = 16 - (cck_agc_rpt & 0x3e);
  634. break;
  635. }
  636. } else {
  637. u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
  638. report = p_drvinfo->cfosho[0] & 0x60;
  639. report = report >> 5;
  640. switch (report) {
  641. case 0x3:
  642. rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1);
  643. break;
  644. case 0x2:
  645. rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1);
  646. break;
  647. case 0x1:
  648. rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1);
  649. break;
  650. case 0x0:
  651. rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1);
  652. break;
  653. }
  654. }
  655. pwdb_all = _rtl92c_query_rxpwrpercentage(rx_pwr_all);
  656. pstats->rx_pwdb_all = pwdb_all;
  657. pstats->recvsignalpower = rx_pwr_all;
  658. if (packet_match_bssid) {
  659. u8 sq;
  660. if (pstats->rx_pwdb_all > 40)
  661. sq = 100;
  662. else {
  663. sq = cck_buf->sq_rpt;
  664. if (sq > 64)
  665. sq = 0;
  666. else if (sq < 20)
  667. sq = 100;
  668. else
  669. sq = ((64 - sq) * 100) / 44;
  670. }
  671. pstats->signalquality = sq;
  672. pstats->RX_SIGQ[0] = sq;
  673. pstats->RX_SIGQ[1] = -1;
  674. }
  675. } else {
  676. rtlpriv->dm.rfpath_rxenable[0] =
  677. rtlpriv->dm.rfpath_rxenable[1] = true;
  678. for (i = RF90_PATH_A; i < RF90_PATH_MAX; i++) {
  679. if (rtlpriv->dm.rfpath_rxenable[i])
  680. rf_rx_num++;
  681. rx_pwr[i] =
  682. ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110;
  683. rssi = _rtl92c_query_rxpwrpercentage(rx_pwr[i]);
  684. total_rssi += rssi;
  685. rtlpriv->stats.rx_snr_db[i] =
  686. (long)(p_drvinfo->rxsnr[i] / 2);
  687. if (packet_match_bssid)
  688. pstats->rx_mimo_signalstrength[i] = (u8) rssi;
  689. }
  690. rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
  691. pwdb_all = _rtl92c_query_rxpwrpercentage(rx_pwr_all);
  692. pstats->rx_pwdb_all = pwdb_all;
  693. pstats->rxpower = rx_pwr_all;
  694. pstats->recvsignalpower = rx_pwr_all;
  695. if (GET_RX_DESC_RX_MCS(pdesc) &&
  696. GET_RX_DESC_RX_MCS(pdesc) >= DESC_RATEMCS8 &&
  697. GET_RX_DESC_RX_MCS(pdesc) <= DESC_RATEMCS15)
  698. max_spatial_stream = 2;
  699. else
  700. max_spatial_stream = 1;
  701. for (i = 0; i < max_spatial_stream; i++) {
  702. evm = _rtl92c_evm_db_to_percentage(p_drvinfo->rxevm[i]);
  703. if (packet_match_bssid) {
  704. if (i == 0)
  705. pstats->signalquality =
  706. (u8) (evm & 0xff);
  707. pstats->RX_SIGQ[i] =
  708. (u8) (evm & 0xff);
  709. }
  710. }
  711. }
  712. if (is_cck_rate)
  713. pstats->signalstrength =
  714. (u8) (_rtl92c_signal_scale_mapping(hw, pwdb_all));
  715. else if (rf_rx_num != 0)
  716. pstats->signalstrength =
  717. (u8) (_rtl92c_signal_scale_mapping
  718. (hw, total_rssi /= rf_rx_num));
  719. }
  720. void rtl92c_translate_rx_signal_stuff(struct ieee80211_hw *hw,
  721. struct sk_buff *skb,
  722. struct rtl_stats *pstats,
  723. struct rx_desc_92c *pdesc,
  724. struct rx_fwinfo_92c *p_drvinfo)
  725. {
  726. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  727. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  728. struct ieee80211_hdr *hdr;
  729. u8 *tmp_buf;
  730. u8 *praddr;
  731. __le16 fc;
  732. u16 type, cpu_fc;
  733. bool packet_matchbssid, packet_toself, packet_beacon = false;
  734. tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
  735. hdr = (struct ieee80211_hdr *)tmp_buf;
  736. fc = hdr->frame_control;
  737. cpu_fc = le16_to_cpu(fc);
  738. type = WLAN_FC_GET_TYPE(fc);
  739. praddr = hdr->addr1;
  740. packet_matchbssid =
  741. ((IEEE80211_FTYPE_CTL != type) &&
  742. ether_addr_equal(mac->bssid,
  743. (cpu_fc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
  744. (cpu_fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
  745. hdr->addr3) &&
  746. (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
  747. packet_toself = packet_matchbssid &&
  748. ether_addr_equal(praddr, rtlefuse->dev_addr);
  749. if (ieee80211_is_beacon(fc))
  750. packet_beacon = true;
  751. _rtl92c_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
  752. packet_matchbssid, packet_toself,
  753. packet_beacon);
  754. rtl_process_phyinfo(hw, tmp_buf, pstats);
  755. }