1
2
3
4#include "../wifi.h"
5#include "../core.h"
6#include "../pci.h"
7#include "reg.h"
8#include "def.h"
9#include "phy.h"
10#include "dm.h"
11#include "hw.h"
12#include "fw.h"
13#include "sw.h"
14#include "trx.h"
15#include "led.h"
16#include "table.h"
17#include "../btcoexist/rtl_btc.h"
18
19#include <linux/vmalloc.h>
20#include <linux/module.h>
21
22static void rtl8821ae_init_aspm_vars(struct ieee80211_hw *hw)
23{
24 struct rtl_priv *rtlpriv = rtl_priv(hw);
25 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
26
27
28 rtlpci->const_amdpci_aspm = 0;
29
30
31
32
33
34
35
36
37
38
39 rtlpci->const_pci_aspm = 3;
40
41
42 rtlpci->const_devicepci_aspm_setting = 0x03;
43
44
45 rtlpci->const_hostpci_aspm_setting = 0x02;
46
47
48
49
50
51
52
53
54
55 rtlpci->const_hwsw_rfoff_d3 = 0;
56
57
58
59
60
61
62
63
64 rtlpci->const_support_pciaspm = rtlpriv->cfg->mod_params->aspm_support;
65}
66
67
68int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
69{
70 int err = 0;
71 struct rtl_priv *rtlpriv = rtl_priv(hw);
72 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
73 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
74 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
75 char *fw_name, *wowlan_fw_name;
76
77 rtl8821ae_bt_reg_init(hw);
78 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer();
79
80 rtlpriv->dm.dm_initialgain_enable = 1;
81 rtlpriv->dm.dm_flag = 0;
82 rtlpriv->dm.disable_framebursting = 0;
83 rtlpriv->dm.thermalvalue = 0;
84 rtlpci->transmit_config = CFENDFORM | BIT(15) | BIT(24) | BIT(25);
85
86 mac->ht_enable = true;
87 mac->ht_cur_stbc = 0;
88 mac->ht_stbc_cap = 0;
89 mac->vht_cur_ldpc = 0;
90 mac->vht_ldpc_cap = 0;
91 mac->vht_cur_stbc = 0;
92 mac->vht_stbc_cap = 0;
93
94 rtlpriv->rtlhal.current_bandtype = BAND_ON_2_4G;
95
96 rtlpriv->rtlhal.bandset = BAND_ON_BOTH;
97 rtlpriv->rtlhal.macphymode = SINGLEMAC_SINGLEPHY;
98
99 rtlpci->receive_config = (RCR_APPFCS |
100 RCR_APP_MIC |
101 RCR_APP_ICV |
102 RCR_APP_PHYST_RXFF |
103 RCR_NONQOS_VHT |
104 RCR_HTC_LOC_CTRL |
105 RCR_AMF |
106 RCR_ACF |
107
108 RCR_ADF |
109 RCR_AICV |
110 RCR_ACRC32 |
111 RCR_AB |
112 RCR_AM |
113 RCR_APM |
114 0);
115
116 rtlpci->irq_mask[0] =
117 (u32)(IMR_PSTIMEOUT |
118 IMR_GTINT3 |
119 IMR_HSISR_IND_ON_INT |
120 IMR_C2HCMD |
121 IMR_HIGHDOK |
122 IMR_MGNTDOK |
123 IMR_BKDOK |
124 IMR_BEDOK |
125 IMR_VIDOK |
126 IMR_VODOK |
127 IMR_RDU |
128 IMR_ROK |
129 0);
130
131 rtlpci->irq_mask[1] =
132 (u32)(IMR_RXFOVW |
133 IMR_TXFOVW |
134 0);
135 rtlpci->sys_irq_mask = (u32)(HSIMR_PDN_INT_EN |
136 HSIMR_RON_INT_EN |
137 0);
138
139 rtlpriv->psc.wo_wlan_mode = WAKE_ON_MAGIC_PACKET |
140 WAKE_ON_PATTERN_MATCH;
141
142
143 rtlpriv->psc.inactiveps = rtlpriv->cfg->mod_params->inactiveps;
144 rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps;
145 rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps;
146 rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
147 rtlpci->int_clear = rtlpriv->cfg->mod_params->int_clear;
148 rtlpriv->cfg->mod_params->sw_crypto =
149 rtlpriv->cfg->mod_params->sw_crypto;
150 rtlpriv->cfg->mod_params->disable_watchdog =
151 rtlpriv->cfg->mod_params->disable_watchdog;
152 if (rtlpriv->cfg->mod_params->disable_watchdog)
153 pr_info("watchdog disabled\n");
154 rtlpriv->psc.reg_fwctrl_lps = 2;
155 rtlpriv->psc.reg_max_lps_awakeintvl = 2;
156
157
158
159
160 rtl8821ae_init_aspm_vars(hw);
161
162 if (rtlpriv->psc.reg_fwctrl_lps == 1)
163 rtlpriv->psc.fwctrl_psmode = FW_PS_MIN_MODE;
164 else if (rtlpriv->psc.reg_fwctrl_lps == 2)
165 rtlpriv->psc.fwctrl_psmode = FW_PS_MAX_MODE;
166 else if (rtlpriv->psc.reg_fwctrl_lps == 3)
167 rtlpriv->psc.fwctrl_psmode = FW_PS_DTIM_MODE;
168
169
170 rtlpriv->rtlhal.pfirmware = vzalloc(0x8000);
171 if (!rtlpriv->rtlhal.pfirmware) {
172 pr_err("Can't alloc buffer for fw.\n");
173 return 1;
174 }
175 rtlpriv->rtlhal.wowlan_firmware = vzalloc(0x8000);
176 if (!rtlpriv->rtlhal.wowlan_firmware) {
177 pr_err("Can't alloc buffer for wowlan fw.\n");
178 vfree(rtlpriv->rtlhal.pfirmware);
179 rtlpriv->rtlhal.pfirmware = NULL;
180 return 1;
181 }
182
183 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
184 fw_name = "rtlwifi/rtl8812aefw.bin";
185 wowlan_fw_name = "rtlwifi/rtl8812aefw_wowlan.bin";
186 } else {
187 fw_name = "rtlwifi/rtl8821aefw_29.bin";
188 wowlan_fw_name = "rtlwifi/rtl8821aefw_wowlan.bin";
189 }
190
191 rtlpriv->max_fw_size = 0x8000;
192
193 pr_info("Using firmware %s\n", fw_name);
194 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
195 rtlpriv->io.dev, GFP_KERNEL, hw,
196 rtl_fw_cb);
197 if (err) {
198 pr_err("Failed to request normal firmware!\n");
199 vfree(rtlpriv->rtlhal.wowlan_firmware);
200 vfree(rtlpriv->rtlhal.pfirmware);
201 return 1;
202 }
203
204 pr_info("Using firmware %s\n", wowlan_fw_name);
205 err = request_firmware_nowait(THIS_MODULE, 1,
206 wowlan_fw_name,
207 rtlpriv->io.dev, GFP_KERNEL, hw,
208 rtl_wowlan_fw_cb);
209 if (err) {
210 pr_err("Failed to request wowlan firmware!\n");
211 vfree(rtlpriv->rtlhal.wowlan_firmware);
212 vfree(rtlpriv->rtlhal.pfirmware);
213 return 1;
214 }
215 return 0;
216}
217
218void rtl8821ae_deinit_sw_vars(struct ieee80211_hw *hw)
219{
220 struct rtl_priv *rtlpriv = rtl_priv(hw);
221
222 if (rtlpriv->rtlhal.pfirmware) {
223 vfree(rtlpriv->rtlhal.pfirmware);
224 rtlpriv->rtlhal.pfirmware = NULL;
225 }
226#if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
227 if (rtlpriv->rtlhal.wowlan_firmware) {
228 vfree(rtlpriv->rtlhal.wowlan_firmware);
229 rtlpriv->rtlhal.wowlan_firmware = NULL;
230 }
231#endif
232}
233
234
235bool rtl8821ae_get_btc_status(void)
236{
237 return true;
238}
239
240static struct rtl_hal_ops rtl8821ae_hal_ops = {
241 .init_sw_vars = rtl8821ae_init_sw_vars,
242 .deinit_sw_vars = rtl8821ae_deinit_sw_vars,
243 .read_eeprom_info = rtl8821ae_read_eeprom_info,
244 .interrupt_recognized = rtl8821ae_interrupt_recognized,
245 .hw_init = rtl8821ae_hw_init,
246 .hw_disable = rtl8821ae_card_disable,
247 .hw_suspend = rtl8821ae_suspend,
248 .hw_resume = rtl8821ae_resume,
249 .enable_interrupt = rtl8821ae_enable_interrupt,
250 .disable_interrupt = rtl8821ae_disable_interrupt,
251 .set_network_type = rtl8821ae_set_network_type,
252 .set_chk_bssid = rtl8821ae_set_check_bssid,
253 .set_qos = rtl8821ae_set_qos,
254 .set_bcn_reg = rtl8821ae_set_beacon_related_registers,
255 .set_bcn_intv = rtl8821ae_set_beacon_interval,
256 .update_interrupt_mask = rtl8821ae_update_interrupt_mask,
257 .get_hw_reg = rtl8821ae_get_hw_reg,
258 .set_hw_reg = rtl8821ae_set_hw_reg,
259 .update_rate_tbl = rtl8821ae_update_hal_rate_tbl,
260 .fill_tx_desc = rtl8821ae_tx_fill_desc,
261 .fill_tx_cmddesc = rtl8821ae_tx_fill_cmddesc,
262 .query_rx_desc = rtl8821ae_rx_query_desc,
263 .set_channel_access = rtl8821ae_update_channel_access_setting,
264 .radio_onoff_checking = rtl8821ae_gpio_radio_on_off_checking,
265 .set_bw_mode = rtl8821ae_phy_set_bw_mode,
266 .switch_channel = rtl8821ae_phy_sw_chnl,
267 .dm_watchdog = rtl8821ae_dm_watchdog,
268 .scan_operation_backup = rtl8821ae_phy_scan_operation_backup,
269 .set_rf_power_state = rtl8821ae_phy_set_rf_power_state,
270 .led_control = rtl8821ae_led_control,
271 .set_desc = rtl8821ae_set_desc,
272 .get_desc = rtl8821ae_get_desc,
273 .is_tx_desc_closed = rtl8821ae_is_tx_desc_closed,
274 .tx_polling = rtl8821ae_tx_polling,
275 .enable_hw_sec = rtl8821ae_enable_hw_security_config,
276 .set_key = rtl8821ae_set_key,
277 .init_sw_leds = rtl8821ae_init_sw_leds,
278 .get_bbreg = rtl8821ae_phy_query_bb_reg,
279 .set_bbreg = rtl8821ae_phy_set_bb_reg,
280 .get_rfreg = rtl8821ae_phy_query_rf_reg,
281 .set_rfreg = rtl8821ae_phy_set_rf_reg,
282 .fill_h2c_cmd = rtl8821ae_fill_h2c_cmd,
283 .get_btc_status = rtl8821ae_get_btc_status,
284 .c2h_ra_report_handler = rtl8821ae_c2h_ra_report_handler,
285 .add_wowlan_pattern = rtl8821ae_add_wowlan_pattern,
286};
287
288static struct rtl_mod_params rtl8821ae_mod_params = {
289 .sw_crypto = false,
290 .inactiveps = true,
291 .swctrl_lps = false,
292 .fwctrl_lps = true,
293 .msi_support = true,
294 .aspm_support = 1,
295 .int_clear = true,
296 .debug_level = 0,
297 .debug_mask = 0,
298 .disable_watchdog = 0,
299};
300
301static const struct rtl_hal_cfg rtl8821ae_hal_cfg = {
302 .bar_id = 2,
303 .write_readback = true,
304 .name = "rtl8821ae_pci",
305 .alt_fw_name = "rtlwifi/rtl8821aefw.bin",
306 .ops = &rtl8821ae_hal_ops,
307 .mod_params = &rtl8821ae_mod_params,
308 .spec_ver = RTL_SPEC_SUPPORT_VHT,
309 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
310 .maps[SYS_FUNC_EN] = REG_SYS_FUNC_EN,
311 .maps[SYS_CLK] = REG_SYS_CLKR,
312 .maps[MAC_RCR_AM] = AM,
313 .maps[MAC_RCR_AB] = AB,
314 .maps[MAC_RCR_ACRC32] = ACRC32,
315 .maps[MAC_RCR_ACF] = ACF,
316 .maps[MAC_RCR_AAP] = AAP,
317 .maps[MAC_HIMR] = REG_HIMR,
318 .maps[MAC_HIMRE] = REG_HIMRE,
319
320 .maps[EFUSE_ACCESS] = REG_EFUSE_ACCESS,
321
322 .maps[EFUSE_TEST] = REG_EFUSE_TEST,
323 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
324 .maps[EFUSE_CLK] = 0,
325 .maps[EFUSE_CLK_CTRL] = REG_EFUSE_CTRL,
326 .maps[EFUSE_PWC_EV12V] = PWC_EV12V,
327 .maps[EFUSE_FEN_ELDR] = FEN_ELDR,
328 .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN,
329 .maps[EFUSE_ANA8M] = ANA8M,
330 .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE,
331 .maps[EFUSE_MAX_SECTION_MAP] = EFUSE_MAX_SECTION,
332 .maps[EFUSE_REAL_CONTENT_SIZE] = EFUSE_REAL_CONTENT_LEN,
333 .maps[EFUSE_OOB_PROTECT_BYTES_LEN] = EFUSE_OOB_PROTECT_BYTES,
334
335 .maps[RWCAM] = REG_CAMCMD,
336 .maps[WCAMI] = REG_CAMWRITE,
337 .maps[RCAMO] = REG_CAMREAD,
338 .maps[CAMDBG] = REG_CAMDBG,
339 .maps[SECR] = REG_SECCFG,
340 .maps[SEC_CAM_NONE] = CAM_NONE,
341 .maps[SEC_CAM_WEP40] = CAM_WEP40,
342 .maps[SEC_CAM_TKIP] = CAM_TKIP,
343 .maps[SEC_CAM_AES] = CAM_AES,
344 .maps[SEC_CAM_WEP104] = CAM_WEP104,
345
346 .maps[RTL_IMR_BCNDMAINT6] = IMR_BCNDMAINT6,
347 .maps[RTL_IMR_BCNDMAINT5] = IMR_BCNDMAINT5,
348 .maps[RTL_IMR_BCNDMAINT4] = IMR_BCNDMAINT4,
349 .maps[RTL_IMR_BCNDMAINT3] = IMR_BCNDMAINT3,
350 .maps[RTL_IMR_BCNDMAINT2] = IMR_BCNDMAINT2,
351 .maps[RTL_IMR_BCNDMAINT1] = IMR_BCNDMAINT1,
352
353 .maps[RTL_IMR_BCNDOK7] = IMR_BCNDOK7,
354 .maps[RTL_IMR_BCNDOK6] = IMR_BCNDOK6,
355 .maps[RTL_IMR_BCNDOK5] = IMR_BCNDOK5,
356 .maps[RTL_IMR_BCNDOK4] = IMR_BCNDOK4,
357 .maps[RTL_IMR_BCNDOK3] = IMR_BCNDOK3,
358 .maps[RTL_IMR_BCNDOK2] = IMR_BCNDOK2,
359 .maps[RTL_IMR_BCNDOK1] = IMR_BCNDOK1,
360
361
362
363 .maps[RTL_IMR_TXFOVW] = IMR_TXFOVW,
364 .maps[RTL_IMR_PSTIMEOUT] = IMR_PSTIMEOUT,
365 .maps[RTL_IMR_BCNINT] = IMR_BCNDMAINT0,
366 .maps[RTL_IMR_RXFOVW] = IMR_RXFOVW,
367 .maps[RTL_IMR_RDU] = IMR_RDU,
368 .maps[RTL_IMR_ATIMEND] = IMR_ATIMEND,
369 .maps[RTL_IMR_BDOK] = IMR_BCNDOK0,
370 .maps[RTL_IMR_MGNTDOK] = IMR_MGNTDOK,
371 .maps[RTL_IMR_TBDER] = IMR_TBDER,
372 .maps[RTL_IMR_HIGHDOK] = IMR_HIGHDOK,
373 .maps[RTL_IMR_TBDOK] = IMR_TBDOK,
374 .maps[RTL_IMR_BKDOK] = IMR_BKDOK,
375 .maps[RTL_IMR_BEDOK] = IMR_BEDOK,
376 .maps[RTL_IMR_VIDOK] = IMR_VIDOK,
377 .maps[RTL_IMR_VODOK] = IMR_VODOK,
378 .maps[RTL_IMR_ROK] = IMR_ROK,
379 .maps[RTL_IBSS_INT_MASKS] = (IMR_BCNDMAINT0 | IMR_TBDOK | IMR_TBDER),
380
381 .maps[RTL_RC_CCK_RATE1M] = DESC_RATE1M,
382 .maps[RTL_RC_CCK_RATE2M] = DESC_RATE2M,
383 .maps[RTL_RC_CCK_RATE5_5M] = DESC_RATE5_5M,
384 .maps[RTL_RC_CCK_RATE11M] = DESC_RATE11M,
385 .maps[RTL_RC_OFDM_RATE6M] = DESC_RATE6M,
386 .maps[RTL_RC_OFDM_RATE9M] = DESC_RATE9M,
387 .maps[RTL_RC_OFDM_RATE12M] = DESC_RATE12M,
388 .maps[RTL_RC_OFDM_RATE18M] = DESC_RATE18M,
389 .maps[RTL_RC_OFDM_RATE24M] = DESC_RATE24M,
390 .maps[RTL_RC_OFDM_RATE36M] = DESC_RATE36M,
391 .maps[RTL_RC_OFDM_RATE48M] = DESC_RATE48M,
392 .maps[RTL_RC_OFDM_RATE54M] = DESC_RATE54M,
393
394 .maps[RTL_RC_HT_RATEMCS7] = DESC_RATEMCS7,
395 .maps[RTL_RC_HT_RATEMCS15] = DESC_RATEMCS15,
396
397
398 .maps[RTL_RC_VHT_RATE_1SS_MCS7] = DESC_RATEVHT1SS_MCS7,
399 .maps[RTL_RC_VHT_RATE_1SS_MCS8] = DESC_RATEVHT1SS_MCS8,
400 .maps[RTL_RC_VHT_RATE_1SS_MCS9] = DESC_RATEVHT1SS_MCS9,
401 .maps[RTL_RC_VHT_RATE_2SS_MCS7] = DESC_RATEVHT2SS_MCS7,
402 .maps[RTL_RC_VHT_RATE_2SS_MCS8] = DESC_RATEVHT2SS_MCS8,
403 .maps[RTL_RC_VHT_RATE_2SS_MCS9] = DESC_RATEVHT2SS_MCS9,
404};
405
406static const struct pci_device_id rtl8821ae_pci_ids[] = {
407 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8812, rtl8821ae_hal_cfg)},
408 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8821, rtl8821ae_hal_cfg)},
409 {},
410};
411
412MODULE_DEVICE_TABLE(pci, rtl8821ae_pci_ids);
413
414MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
415MODULE_LICENSE("GPL");
416MODULE_DESCRIPTION("Realtek 8821ae 802.11ac PCI wireless");
417MODULE_FIRMWARE("rtlwifi/rtl8821aefw.bin");
418MODULE_FIRMWARE("rtlwifi/rtl8821aefw_29.bin");
419
420module_param_named(swenc, rtl8821ae_mod_params.sw_crypto, bool, 0444);
421module_param_named(debug_level, rtl8821ae_mod_params.debug_level, int, 0644);
422module_param_named(debug_mask, rtl8821ae_mod_params.debug_mask, ullong, 0644);
423module_param_named(ips, rtl8821ae_mod_params.inactiveps, bool, 0444);
424module_param_named(swlps, rtl8821ae_mod_params.swctrl_lps, bool, 0444);
425module_param_named(fwlps, rtl8821ae_mod_params.fwctrl_lps, bool, 0444);
426module_param_named(msi, rtl8821ae_mod_params.msi_support, bool, 0444);
427module_param_named(aspm, rtl8821ae_mod_params.aspm_support, int, 0444);
428module_param_named(disable_watchdog, rtl8821ae_mod_params.disable_watchdog,
429 bool, 0444);
430module_param_named(int_clear, rtl8821ae_mod_params.int_clear, bool, 0444);
431MODULE_PARM_DESC(swenc, "Set to 1 for software crypto (default 0)\n");
432MODULE_PARM_DESC(ips, "Set to 0 to not use link power save (default 1)\n");
433MODULE_PARM_DESC(swlps, "Set to 1 to use SW control power save (default 0)\n");
434MODULE_PARM_DESC(fwlps, "Set to 1 to use FW control power save (default 1)\n");
435MODULE_PARM_DESC(msi, "Set to 1 to use MSI interrupts mode (default 1)\n");
436MODULE_PARM_DESC(aspm, "Set to 1 to enable ASPM (default 1)\n");
437MODULE_PARM_DESC(debug_level, "Set debug level (0-5) (default 0)");
438MODULE_PARM_DESC(debug_mask, "Set debug mask (default 0)");
439MODULE_PARM_DESC(disable_watchdog, "Set to 1 to disable the watchdog (default 0)\n");
440MODULE_PARM_DESC(int_clear, "Set to 0 to disable interrupt clear before set (default 1)\n");
441
442static SIMPLE_DEV_PM_OPS(rtlwifi_pm_ops, rtl_pci_suspend, rtl_pci_resume);
443
444static struct pci_driver rtl8821ae_driver = {
445 .name = KBUILD_MODNAME,
446 .id_table = rtl8821ae_pci_ids,
447 .probe = rtl_pci_probe,
448 .remove = rtl_pci_disconnect,
449 .driver.pm = &rtlwifi_pm_ops,
450};
451
452module_pci_driver(rtl8821ae_driver);
453