sw.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  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 "../core.h"
  27. #include "../pci.h"
  28. #include "../base.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "phy.h"
  32. #include "dm.h"
  33. #include "hw.h"
  34. #include "sw.h"
  35. #include "trx.h"
  36. #include "led.h"
  37. #include <linux/module.h>
  38. static void rtl92d_init_aspm_vars(struct ieee80211_hw *hw)
  39. {
  40. struct rtl_priv *rtlpriv = rtl_priv(hw);
  41. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  42. /*close ASPM for AMD defaultly */
  43. rtlpci->const_amdpci_aspm = 0;
  44. /*
  45. * ASPM PS mode.
  46. * 0 - Disable ASPM,
  47. * 1 - Enable ASPM without Clock Req,
  48. * 2 - Enable ASPM with Clock Req,
  49. * 3 - Alwyas Enable ASPM with Clock Req,
  50. * 4 - Always Enable ASPM without Clock Req.
  51. * set defult to RTL8192CE:3 RTL8192E:2
  52. * */
  53. rtlpci->const_pci_aspm = 3;
  54. /*Setting for PCI-E device */
  55. rtlpci->const_devicepci_aspm_setting = 0x03;
  56. /*Setting for PCI-E bridge */
  57. rtlpci->const_hostpci_aspm_setting = 0x02;
  58. /*
  59. * In Hw/Sw Radio Off situation.
  60. * 0 - Default,
  61. * 1 - From ASPM setting without low Mac Pwr,
  62. * 2 - From ASPM setting with low Mac Pwr,
  63. * 3 - Bus D3
  64. * set default to RTL8192CE:0 RTL8192SE:2
  65. */
  66. rtlpci->const_hwsw_rfoff_d3 = 0;
  67. /*
  68. * This setting works for those device with
  69. * backdoor ASPM setting such as EPHY setting.
  70. * 0 - Not support ASPM,
  71. * 1 - Support ASPM,
  72. * 2 - According to chipset.
  73. */
  74. rtlpci->const_support_pciaspm = rtlpriv->cfg->mod_params->aspm_support;
  75. }
  76. static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
  77. {
  78. int err;
  79. u8 tid;
  80. struct rtl_priv *rtlpriv = rtl_priv(hw);
  81. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  82. char *fw_name = "rtlwifi/rtl8192defw.bin";
  83. rtlpriv->dm.dm_initialgain_enable = true;
  84. rtlpriv->dm.dm_flag = 0;
  85. rtlpriv->dm.disable_framebursting = false;
  86. rtlpriv->dm.thermalvalue = 0;
  87. rtlpriv->dm.useramask = true;
  88. /* dual mac */
  89. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G)
  90. rtlpriv->phy.current_channel = 36;
  91. else
  92. rtlpriv->phy.current_channel = 1;
  93. if (rtlpriv->rtlhal.macphymode != SINGLEMAC_SINGLEPHY) {
  94. rtlpriv->rtlhal.disable_amsdu_8k = true;
  95. /* No long RX - reduce fragmentation */
  96. rtlpci->rxbuffersize = 4096;
  97. }
  98. rtlpci->transmit_config = CFENDFORM | BIT(12) | BIT(13);
  99. rtlpci->receive_config = (
  100. RCR_APPFCS
  101. | RCR_AMF
  102. | RCR_ADF
  103. | RCR_APP_MIC
  104. | RCR_APP_ICV
  105. | RCR_AICV
  106. | RCR_ACRC32
  107. | RCR_AB
  108. | RCR_AM
  109. | RCR_APM
  110. | RCR_APP_PHYST_RXFF
  111. | RCR_HTC_LOC_CTRL
  112. );
  113. rtlpci->irq_mask[0] = (u32) (
  114. IMR_ROK
  115. | IMR_VODOK
  116. | IMR_VIDOK
  117. | IMR_BEDOK
  118. | IMR_BKDOK
  119. | IMR_MGNTDOK
  120. | IMR_HIGHDOK
  121. | IMR_BDOK
  122. | IMR_RDU
  123. | IMR_RXFOVW
  124. );
  125. rtlpci->irq_mask[1] = (u32) (IMR_CPWM | IMR_C2HCMD);
  126. /* for LPS & IPS */
  127. rtlpriv->psc.inactiveps = rtlpriv->cfg->mod_params->inactiveps;
  128. rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps;
  129. rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps;
  130. if (!rtlpriv->psc.inactiveps)
  131. pr_info("Power Save off (module option)\n");
  132. if (!rtlpriv->psc.fwctrl_lps)
  133. pr_info("FW Power Save off (module option)\n");
  134. rtlpriv->psc.reg_fwctrl_lps = 3;
  135. rtlpriv->psc.reg_max_lps_awakeintvl = 5;
  136. /* for ASPM, you can close aspm through
  137. * set const_support_pciaspm = 0 */
  138. rtl92d_init_aspm_vars(hw);
  139. if (rtlpriv->psc.reg_fwctrl_lps == 1)
  140. rtlpriv->psc.fwctrl_psmode = FW_PS_MIN_MODE;
  141. else if (rtlpriv->psc.reg_fwctrl_lps == 2)
  142. rtlpriv->psc.fwctrl_psmode = FW_PS_MAX_MODE;
  143. else if (rtlpriv->psc.reg_fwctrl_lps == 3)
  144. rtlpriv->psc.fwctrl_psmode = FW_PS_DTIM_MODE;
  145. /* for early mode */
  146. rtlpriv->rtlhal.earlymode_enable = false;
  147. for (tid = 0; tid < 8; tid++)
  148. skb_queue_head_init(&rtlpriv->mac80211.skb_waitq[tid]);
  149. /* for firmware buf */
  150. rtlpriv->rtlhal.pfirmware = vzalloc(0x8000);
  151. if (!rtlpriv->rtlhal.pfirmware) {
  152. pr_err("Can't alloc buffer for fw\n");
  153. return 1;
  154. }
  155. rtlpriv->max_fw_size = 0x8000;
  156. pr_info("Driver for Realtek RTL8192DE WLAN interface\n");
  157. pr_info("Loading firmware file %s\n", fw_name);
  158. /* request fw */
  159. err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
  160. rtlpriv->io.dev, GFP_KERNEL, hw,
  161. rtl_fw_cb);
  162. if (err) {
  163. pr_err("Failed to request firmware!\n");
  164. vfree(rtlpriv->rtlhal.pfirmware);
  165. rtlpriv->rtlhal.pfirmware = NULL;
  166. return 1;
  167. }
  168. return 0;
  169. }
  170. static void rtl92d_deinit_sw_vars(struct ieee80211_hw *hw)
  171. {
  172. struct rtl_priv *rtlpriv = rtl_priv(hw);
  173. u8 tid;
  174. if (rtlpriv->rtlhal.pfirmware) {
  175. vfree(rtlpriv->rtlhal.pfirmware);
  176. rtlpriv->rtlhal.pfirmware = NULL;
  177. }
  178. for (tid = 0; tid < 8; tid++)
  179. skb_queue_purge(&rtlpriv->mac80211.skb_waitq[tid]);
  180. }
  181. static struct rtl_hal_ops rtl8192de_hal_ops = {
  182. .init_sw_vars = rtl92d_init_sw_vars,
  183. .deinit_sw_vars = rtl92d_deinit_sw_vars,
  184. .read_eeprom_info = rtl92de_read_eeprom_info,
  185. .interrupt_recognized = rtl92de_interrupt_recognized,
  186. .hw_init = rtl92de_hw_init,
  187. .hw_disable = rtl92de_card_disable,
  188. .hw_suspend = rtl92de_suspend,
  189. .hw_resume = rtl92de_resume,
  190. .enable_interrupt = rtl92de_enable_interrupt,
  191. .disable_interrupt = rtl92de_disable_interrupt,
  192. .set_network_type = rtl92de_set_network_type,
  193. .set_chk_bssid = rtl92de_set_check_bssid,
  194. .set_qos = rtl92de_set_qos,
  195. .set_bcn_reg = rtl92de_set_beacon_related_registers,
  196. .set_bcn_intv = rtl92de_set_beacon_interval,
  197. .update_interrupt_mask = rtl92de_update_interrupt_mask,
  198. .get_hw_reg = rtl92de_get_hw_reg,
  199. .set_hw_reg = rtl92de_set_hw_reg,
  200. .update_rate_tbl = rtl92de_update_hal_rate_tbl,
  201. .fill_tx_desc = rtl92de_tx_fill_desc,
  202. .fill_tx_cmddesc = rtl92de_tx_fill_cmddesc,
  203. .query_rx_desc = rtl92de_rx_query_desc,
  204. .set_channel_access = rtl92de_update_channel_access_setting,
  205. .radio_onoff_checking = rtl92de_gpio_radio_on_off_checking,
  206. .set_bw_mode = rtl92d_phy_set_bw_mode,
  207. .switch_channel = rtl92d_phy_sw_chnl,
  208. .dm_watchdog = rtl92d_dm_watchdog,
  209. .scan_operation_backup = rtl_phy_scan_operation_backup,
  210. .set_rf_power_state = rtl92d_phy_set_rf_power_state,
  211. .led_control = rtl92de_led_control,
  212. .set_desc = rtl92de_set_desc,
  213. .get_desc = rtl92de_get_desc,
  214. .is_tx_desc_closed = rtl92de_is_tx_desc_closed,
  215. .tx_polling = rtl92de_tx_polling,
  216. .enable_hw_sec = rtl92de_enable_hw_security_config,
  217. .set_key = rtl92de_set_key,
  218. .init_sw_leds = rtl92de_init_sw_leds,
  219. .get_bbreg = rtl92d_phy_query_bb_reg,
  220. .set_bbreg = rtl92d_phy_set_bb_reg,
  221. .get_rfreg = rtl92d_phy_query_rf_reg,
  222. .set_rfreg = rtl92d_phy_set_rf_reg,
  223. .linked_set_reg = rtl92d_linked_set_reg,
  224. .get_btc_status = rtl_btc_status_false,
  225. };
  226. static struct rtl_mod_params rtl92de_mod_params = {
  227. .sw_crypto = false,
  228. .inactiveps = true,
  229. .swctrl_lps = true,
  230. .fwctrl_lps = false,
  231. .aspm_support = 1,
  232. .debug_level = 0,
  233. .debug_mask = 0,
  234. };
  235. static const struct rtl_hal_cfg rtl92de_hal_cfg = {
  236. .bar_id = 2,
  237. .write_readback = true,
  238. .name = "rtl8192de",
  239. .ops = &rtl8192de_hal_ops,
  240. .mod_params = &rtl92de_mod_params,
  241. .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
  242. .maps[SYS_FUNC_EN] = REG_SYS_FUNC_EN,
  243. .maps[SYS_CLK] = REG_SYS_CLKR,
  244. .maps[MAC_RCR_AM] = RCR_AM,
  245. .maps[MAC_RCR_AB] = RCR_AB,
  246. .maps[MAC_RCR_ACRC32] = RCR_ACRC32,
  247. .maps[MAC_RCR_ACF] = RCR_ACF,
  248. .maps[MAC_RCR_AAP] = RCR_AAP,
  249. .maps[EFUSE_TEST] = REG_EFUSE_TEST,
  250. .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
  251. .maps[EFUSE_CLK] = 0, /* just for 92se */
  252. .maps[EFUSE_CLK_CTRL] = REG_EFUSE_CTRL,
  253. .maps[EFUSE_PWC_EV12V] = PWC_EV12V,
  254. .maps[EFUSE_FEN_ELDR] = FEN_ELDR,
  255. .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN,
  256. .maps[EFUSE_ANA8M] = 0, /* just for 92se */
  257. .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE,
  258. .maps[EFUSE_MAX_SECTION_MAP] = EFUSE_MAX_SECTION,
  259. .maps[EFUSE_REAL_CONTENT_SIZE] = EFUSE_REAL_CONTENT_LEN,
  260. .maps[RWCAM] = REG_CAMCMD,
  261. .maps[WCAMI] = REG_CAMWRITE,
  262. .maps[RCAMO] = REG_CAMREAD,
  263. .maps[CAMDBG] = REG_CAMDBG,
  264. .maps[SECR] = REG_SECCFG,
  265. .maps[SEC_CAM_NONE] = CAM_NONE,
  266. .maps[SEC_CAM_WEP40] = CAM_WEP40,
  267. .maps[SEC_CAM_TKIP] = CAM_TKIP,
  268. .maps[SEC_CAM_AES] = CAM_AES,
  269. .maps[SEC_CAM_WEP104] = CAM_WEP104,
  270. .maps[RTL_IMR_BCNDMAINT6] = IMR_BCNDMAINT6,
  271. .maps[RTL_IMR_BCNDMAINT5] = IMR_BCNDMAINT5,
  272. .maps[RTL_IMR_BCNDMAINT4] = IMR_BCNDMAINT4,
  273. .maps[RTL_IMR_BCNDMAINT3] = IMR_BCNDMAINT3,
  274. .maps[RTL_IMR_BCNDMAINT2] = IMR_BCNDMAINT2,
  275. .maps[RTL_IMR_BCNDMAINT1] = IMR_BCNDMAINT1,
  276. .maps[RTL_IMR_BCNDOK8] = IMR_BCNDOK8,
  277. .maps[RTL_IMR_BCNDOK7] = IMR_BCNDOK7,
  278. .maps[RTL_IMR_BCNDOK6] = IMR_BCNDOK6,
  279. .maps[RTL_IMR_BCNDOK5] = IMR_BCNDOK5,
  280. .maps[RTL_IMR_BCNDOK4] = IMR_BCNDOK4,
  281. .maps[RTL_IMR_BCNDOK3] = IMR_BCNDOK3,
  282. .maps[RTL_IMR_BCNDOK2] = IMR_BCNDOK2,
  283. .maps[RTL_IMR_BCNDOK1] = IMR_BCNDOK1,
  284. .maps[RTL_IMR_TIMEOUT2] = IMR_TIMEOUT2,
  285. .maps[RTL_IMR_TIMEOUT1] = IMR_TIMEOUT1,
  286. .maps[RTL_IMR_TXFOVW] = IMR_TXFOVW,
  287. .maps[RTL_IMR_PSTIMEOUT] = IMR_PSTIMEOUT,
  288. .maps[RTL_IMR_BCNINT] = IMR_BCNINT,
  289. .maps[RTL_IMR_RXFOVW] = IMR_RXFOVW,
  290. .maps[RTL_IMR_RDU] = IMR_RDU,
  291. .maps[RTL_IMR_ATIMEND] = IMR_ATIMEND,
  292. .maps[RTL_IMR_BDOK] = IMR_BDOK,
  293. .maps[RTL_IMR_MGNTDOK] = IMR_MGNTDOK,
  294. .maps[RTL_IMR_TBDER] = IMR_TBDER,
  295. .maps[RTL_IMR_HIGHDOK] = IMR_HIGHDOK,
  296. .maps[RTL_IMR_TBDOK] = IMR_TBDOK,
  297. .maps[RTL_IMR_BKDOK] = IMR_BKDOK,
  298. .maps[RTL_IMR_BEDOK] = IMR_BEDOK,
  299. .maps[RTL_IMR_VIDOK] = IMR_VIDOK,
  300. .maps[RTL_IMR_VODOK] = IMR_VODOK,
  301. .maps[RTL_IMR_ROK] = IMR_ROK,
  302. .maps[RTL_IBSS_INT_MASKS] = (IMR_BCNINT | IMR_TBDOK | IMR_TBDER),
  303. .maps[RTL_RC_CCK_RATE1M] = DESC_RATE1M,
  304. .maps[RTL_RC_CCK_RATE2M] = DESC_RATE2M,
  305. .maps[RTL_RC_CCK_RATE5_5M] = DESC_RATE5_5M,
  306. .maps[RTL_RC_CCK_RATE11M] = DESC_RATE11M,
  307. .maps[RTL_RC_OFDM_RATE6M] = DESC_RATE6M,
  308. .maps[RTL_RC_OFDM_RATE9M] = DESC_RATE9M,
  309. .maps[RTL_RC_OFDM_RATE12M] = DESC_RATE12M,
  310. .maps[RTL_RC_OFDM_RATE18M] = DESC_RATE18M,
  311. .maps[RTL_RC_OFDM_RATE24M] = DESC_RATE24M,
  312. .maps[RTL_RC_OFDM_RATE36M] = DESC_RATE36M,
  313. .maps[RTL_RC_OFDM_RATE48M] = DESC_RATE48M,
  314. .maps[RTL_RC_OFDM_RATE54M] = DESC_RATE54M,
  315. .maps[RTL_RC_HT_RATEMCS7] = DESC_RATEMCS7,
  316. .maps[RTL_RC_HT_RATEMCS15] = DESC_RATEMCS15,
  317. };
  318. static const struct pci_device_id rtl92de_pci_ids[] = {
  319. {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8193, rtl92de_hal_cfg)},
  320. {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x002B, rtl92de_hal_cfg)},
  321. {},
  322. };
  323. MODULE_DEVICE_TABLE(pci, rtl92de_pci_ids);
  324. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  325. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  326. MODULE_AUTHOR("Larry Finger <Larry.Finger@lwfinger.net>");
  327. MODULE_LICENSE("GPL");
  328. MODULE_DESCRIPTION("Realtek 8192DE 802.11n Dual Mac PCI wireless");
  329. MODULE_FIRMWARE("rtlwifi/rtl8192defw.bin");
  330. module_param_named(swenc, rtl92de_mod_params.sw_crypto, bool, 0444);
  331. module_param_named(debug_level, rtl92de_mod_params.debug_level, int, 0644);
  332. module_param_named(ips, rtl92de_mod_params.inactiveps, bool, 0444);
  333. module_param_named(swlps, rtl92de_mod_params.swctrl_lps, bool, 0444);
  334. module_param_named(fwlps, rtl92de_mod_params.fwctrl_lps, bool, 0444);
  335. module_param_named(aspm, rtl92de_mod_params.aspm_support, int, 0444);
  336. module_param_named(debug_mask, rtl92de_mod_params.debug_mask, ullong, 0644);
  337. MODULE_PARM_DESC(swenc, "Set to 1 for software crypto (default 0)\n");
  338. MODULE_PARM_DESC(ips, "Set to 0 to not use link power save (default 1)\n");
  339. MODULE_PARM_DESC(swlps, "Set to 1 to use SW control power save (default 1)\n");
  340. MODULE_PARM_DESC(fwlps, "Set to 1 to use FW control power save (default 0)\n");
  341. MODULE_PARM_DESC(aspm, "Set to 1 to enable ASPM (default 1)\n");
  342. MODULE_PARM_DESC(debug_level, "Set debug level (0-5) (default 0)");
  343. MODULE_PARM_DESC(debug_mask, "Set debug mask (default 0)");
  344. static SIMPLE_DEV_PM_OPS(rtlwifi_pm_ops, rtl_pci_suspend, rtl_pci_resume);
  345. static struct pci_driver rtl92de_driver = {
  346. .name = KBUILD_MODNAME,
  347. .id_table = rtl92de_pci_ids,
  348. .probe = rtl_pci_probe,
  349. .remove = rtl_pci_disconnect,
  350. .driver.pm = &rtlwifi_pm_ops,
  351. };
  352. /* add global spin lock to solve the problem that
  353. * Dul mac register operation on the same time */
  354. spinlock_t globalmutex_power;
  355. spinlock_t globalmutex_for_fwdownload;
  356. spinlock_t globalmutex_for_power_and_efuse;
  357. static int __init rtl92de_module_init(void)
  358. {
  359. int ret = 0;
  360. spin_lock_init(&globalmutex_power);
  361. spin_lock_init(&globalmutex_for_fwdownload);
  362. spin_lock_init(&globalmutex_for_power_and_efuse);
  363. ret = pci_register_driver(&rtl92de_driver);
  364. if (ret)
  365. WARN_ONCE(true, "rtl8192de: No device found\n");
  366. return ret;
  367. }
  368. static void __exit rtl92de_module_exit(void)
  369. {
  370. pci_unregister_driver(&rtl92de_driver);
  371. }
  372. module_init(rtl92de_module_init);
  373. module_exit(rtl92de_module_exit);