This source file includes following definitions.
- rtl8821ae_init_aspm_vars
- rtl8821ae_init_sw_vars
- rtl8821ae_deinit_sw_vars
- rtl8821ae_get_btc_status
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
22 static 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
68 int 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 if (rtlpriv->cfg->mod_params->disable_watchdog)
149 pr_info("watchdog disabled\n");
150 rtlpriv->psc.reg_fwctrl_lps = 2;
151 rtlpriv->psc.reg_max_lps_awakeintvl = 2;
152
153
154
155
156 rtl8821ae_init_aspm_vars(hw);
157
158 if (rtlpriv->psc.reg_fwctrl_lps == 1)
159 rtlpriv->psc.fwctrl_psmode = FW_PS_MIN_MODE;
160 else if (rtlpriv->psc.reg_fwctrl_lps == 2)
161 rtlpriv->psc.fwctrl_psmode = FW_PS_MAX_MODE;
162 else if (rtlpriv->psc.reg_fwctrl_lps == 3)
163 rtlpriv->psc.fwctrl_psmode = FW_PS_DTIM_MODE;
164
165
166 rtlpriv->rtlhal.pfirmware = vzalloc(0x8000);
167 if (!rtlpriv->rtlhal.pfirmware) {
168 pr_err("Can't alloc buffer for fw.\n");
169 return 1;
170 }
171 rtlpriv->rtlhal.wowlan_firmware = vzalloc(0x8000);
172 if (!rtlpriv->rtlhal.wowlan_firmware) {
173 pr_err("Can't alloc buffer for wowlan fw.\n");
174 vfree(rtlpriv->rtlhal.pfirmware);
175 rtlpriv->rtlhal.pfirmware = NULL;
176 return 1;
177 }
178
179 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
180 fw_name = "rtlwifi/rtl8812aefw.bin";
181 wowlan_fw_name = "rtlwifi/rtl8812aefw_wowlan.bin";
182 } else {
183 fw_name = "rtlwifi/rtl8821aefw_29.bin";
184 wowlan_fw_name = "rtlwifi/rtl8821aefw_wowlan.bin";
185 }
186
187 rtlpriv->max_fw_size = 0x8000;
188
189 pr_info("Using firmware %s\n", fw_name);
190 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
191 rtlpriv->io.dev, GFP_KERNEL, hw,
192 rtl_fw_cb);
193 if (err) {
194 pr_err("Failed to request normal firmware!\n");
195 vfree(rtlpriv->rtlhal.wowlan_firmware);
196 vfree(rtlpriv->rtlhal.pfirmware);
197 return 1;
198 }
199
200 pr_info("Using firmware %s\n", wowlan_fw_name);
201 err = request_firmware_nowait(THIS_MODULE, 1,
202 wowlan_fw_name,
203 rtlpriv->io.dev, GFP_KERNEL, hw,
204 rtl_wowlan_fw_cb);
205 if (err) {
206 pr_err("Failed to request wowlan firmware!\n");
207 vfree(rtlpriv->rtlhal.wowlan_firmware);
208 vfree(rtlpriv->rtlhal.pfirmware);
209 return 1;
210 }
211 return 0;
212 }
213
214 void rtl8821ae_deinit_sw_vars(struct ieee80211_hw *hw)
215 {
216 struct rtl_priv *rtlpriv = rtl_priv(hw);
217
218 if (rtlpriv->rtlhal.pfirmware) {
219 vfree(rtlpriv->rtlhal.pfirmware);
220 rtlpriv->rtlhal.pfirmware = NULL;
221 }
222 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
223 if (rtlpriv->rtlhal.wowlan_firmware) {
224 vfree(rtlpriv->rtlhal.wowlan_firmware);
225 rtlpriv->rtlhal.wowlan_firmware = NULL;
226 }
227 #endif
228 }
229
230
231 bool rtl8821ae_get_btc_status(void)
232 {
233 return true;
234 }
235
236 static struct rtl_hal_ops rtl8821ae_hal_ops = {
237 .init_sw_vars = rtl8821ae_init_sw_vars,
238 .deinit_sw_vars = rtl8821ae_deinit_sw_vars,
239 .read_eeprom_info = rtl8821ae_read_eeprom_info,
240 .interrupt_recognized = rtl8821ae_interrupt_recognized,
241 .hw_init = rtl8821ae_hw_init,
242 .hw_disable = rtl8821ae_card_disable,
243 .hw_suspend = rtl8821ae_suspend,
244 .hw_resume = rtl8821ae_resume,
245 .enable_interrupt = rtl8821ae_enable_interrupt,
246 .disable_interrupt = rtl8821ae_disable_interrupt,
247 .set_network_type = rtl8821ae_set_network_type,
248 .set_chk_bssid = rtl8821ae_set_check_bssid,
249 .set_qos = rtl8821ae_set_qos,
250 .set_bcn_reg = rtl8821ae_set_beacon_related_registers,
251 .set_bcn_intv = rtl8821ae_set_beacon_interval,
252 .update_interrupt_mask = rtl8821ae_update_interrupt_mask,
253 .get_hw_reg = rtl8821ae_get_hw_reg,
254 .set_hw_reg = rtl8821ae_set_hw_reg,
255 .update_rate_tbl = rtl8821ae_update_hal_rate_tbl,
256 .fill_tx_desc = rtl8821ae_tx_fill_desc,
257 .fill_tx_cmddesc = rtl8821ae_tx_fill_cmddesc,
258 .query_rx_desc = rtl8821ae_rx_query_desc,
259 .set_channel_access = rtl8821ae_update_channel_access_setting,
260 .radio_onoff_checking = rtl8821ae_gpio_radio_on_off_checking,
261 .set_bw_mode = rtl8821ae_phy_set_bw_mode,
262 .switch_channel = rtl8821ae_phy_sw_chnl,
263 .dm_watchdog = rtl8821ae_dm_watchdog,
264 .scan_operation_backup = rtl8821ae_phy_scan_operation_backup,
265 .set_rf_power_state = rtl8821ae_phy_set_rf_power_state,
266 .led_control = rtl8821ae_led_control,
267 .set_desc = rtl8821ae_set_desc,
268 .get_desc = rtl8821ae_get_desc,
269 .is_tx_desc_closed = rtl8821ae_is_tx_desc_closed,
270 .tx_polling = rtl8821ae_tx_polling,
271 .enable_hw_sec = rtl8821ae_enable_hw_security_config,
272 .set_key = rtl8821ae_set_key,
273 .init_sw_leds = rtl8821ae_init_sw_leds,
274 .get_bbreg = rtl8821ae_phy_query_bb_reg,
275 .set_bbreg = rtl8821ae_phy_set_bb_reg,
276 .get_rfreg = rtl8821ae_phy_query_rf_reg,
277 .set_rfreg = rtl8821ae_phy_set_rf_reg,
278 .fill_h2c_cmd = rtl8821ae_fill_h2c_cmd,
279 .get_btc_status = rtl8821ae_get_btc_status,
280 .c2h_ra_report_handler = rtl8821ae_c2h_ra_report_handler,
281 .add_wowlan_pattern = rtl8821ae_add_wowlan_pattern,
282 };
283
284 static struct rtl_mod_params rtl8821ae_mod_params = {
285 .sw_crypto = false,
286 .inactiveps = true,
287 .swctrl_lps = false,
288 .fwctrl_lps = true,
289 .msi_support = true,
290 .aspm_support = 1,
291 .int_clear = true,
292 .debug_level = 0,
293 .debug_mask = 0,
294 .disable_watchdog = 0,
295 };
296
297 static const struct rtl_hal_cfg rtl8821ae_hal_cfg = {
298 .bar_id = 2,
299 .write_readback = true,
300 .name = "rtl8821ae_pci",
301 .alt_fw_name = "rtlwifi/rtl8821aefw.bin",
302 .ops = &rtl8821ae_hal_ops,
303 .mod_params = &rtl8821ae_mod_params,
304 .spec_ver = RTL_SPEC_SUPPORT_VHT,
305 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
306 .maps[SYS_FUNC_EN] = REG_SYS_FUNC_EN,
307 .maps[SYS_CLK] = REG_SYS_CLKR,
308 .maps[MAC_RCR_AM] = AM,
309 .maps[MAC_RCR_AB] = AB,
310 .maps[MAC_RCR_ACRC32] = ACRC32,
311 .maps[MAC_RCR_ACF] = ACF,
312 .maps[MAC_RCR_AAP] = AAP,
313 .maps[MAC_HIMR] = REG_HIMR,
314 .maps[MAC_HIMRE] = REG_HIMRE,
315
316 .maps[EFUSE_ACCESS] = REG_EFUSE_ACCESS,
317
318 .maps[EFUSE_TEST] = REG_EFUSE_TEST,
319 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
320 .maps[EFUSE_CLK] = 0,
321 .maps[EFUSE_CLK_CTRL] = REG_EFUSE_CTRL,
322 .maps[EFUSE_PWC_EV12V] = PWC_EV12V,
323 .maps[EFUSE_FEN_ELDR] = FEN_ELDR,
324 .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN,
325 .maps[EFUSE_ANA8M] = ANA8M,
326 .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE,
327 .maps[EFUSE_MAX_SECTION_MAP] = EFUSE_MAX_SECTION,
328 .maps[EFUSE_REAL_CONTENT_SIZE] = EFUSE_REAL_CONTENT_LEN,
329 .maps[EFUSE_OOB_PROTECT_BYTES_LEN] = EFUSE_OOB_PROTECT_BYTES,
330
331 .maps[RWCAM] = REG_CAMCMD,
332 .maps[WCAMI] = REG_CAMWRITE,
333 .maps[RCAMO] = REG_CAMREAD,
334 .maps[CAMDBG] = REG_CAMDBG,
335 .maps[SECR] = REG_SECCFG,
336 .maps[SEC_CAM_NONE] = CAM_NONE,
337 .maps[SEC_CAM_WEP40] = CAM_WEP40,
338 .maps[SEC_CAM_TKIP] = CAM_TKIP,
339 .maps[SEC_CAM_AES] = CAM_AES,
340 .maps[SEC_CAM_WEP104] = CAM_WEP104,
341
342 .maps[RTL_IMR_BCNDMAINT6] = IMR_BCNDMAINT6,
343 .maps[RTL_IMR_BCNDMAINT5] = IMR_BCNDMAINT5,
344 .maps[RTL_IMR_BCNDMAINT4] = IMR_BCNDMAINT4,
345 .maps[RTL_IMR_BCNDMAINT3] = IMR_BCNDMAINT3,
346 .maps[RTL_IMR_BCNDMAINT2] = IMR_BCNDMAINT2,
347 .maps[RTL_IMR_BCNDMAINT1] = IMR_BCNDMAINT1,
348
349 .maps[RTL_IMR_BCNDOK7] = IMR_BCNDOK7,
350 .maps[RTL_IMR_BCNDOK6] = IMR_BCNDOK6,
351 .maps[RTL_IMR_BCNDOK5] = IMR_BCNDOK5,
352 .maps[RTL_IMR_BCNDOK4] = IMR_BCNDOK4,
353 .maps[RTL_IMR_BCNDOK3] = IMR_BCNDOK3,
354 .maps[RTL_IMR_BCNDOK2] = IMR_BCNDOK2,
355 .maps[RTL_IMR_BCNDOK1] = IMR_BCNDOK1,
356
357
358
359 .maps[RTL_IMR_TXFOVW] = IMR_TXFOVW,
360 .maps[RTL_IMR_PSTIMEOUT] = IMR_PSTIMEOUT,
361 .maps[RTL_IMR_BCNINT] = IMR_BCNDMAINT0,
362 .maps[RTL_IMR_RXFOVW] = IMR_RXFOVW,
363 .maps[RTL_IMR_RDU] = IMR_RDU,
364 .maps[RTL_IMR_ATIMEND] = IMR_ATIMEND,
365 .maps[RTL_IMR_BDOK] = IMR_BCNDOK0,
366 .maps[RTL_IMR_MGNTDOK] = IMR_MGNTDOK,
367 .maps[RTL_IMR_TBDER] = IMR_TBDER,
368 .maps[RTL_IMR_HIGHDOK] = IMR_HIGHDOK,
369 .maps[RTL_IMR_TBDOK] = IMR_TBDOK,
370 .maps[RTL_IMR_BKDOK] = IMR_BKDOK,
371 .maps[RTL_IMR_BEDOK] = IMR_BEDOK,
372 .maps[RTL_IMR_VIDOK] = IMR_VIDOK,
373 .maps[RTL_IMR_VODOK] = IMR_VODOK,
374 .maps[RTL_IMR_ROK] = IMR_ROK,
375 .maps[RTL_IBSS_INT_MASKS] = (IMR_BCNDMAINT0 | IMR_TBDOK | IMR_TBDER),
376
377 .maps[RTL_RC_CCK_RATE1M] = DESC_RATE1M,
378 .maps[RTL_RC_CCK_RATE2M] = DESC_RATE2M,
379 .maps[RTL_RC_CCK_RATE5_5M] = DESC_RATE5_5M,
380 .maps[RTL_RC_CCK_RATE11M] = DESC_RATE11M,
381 .maps[RTL_RC_OFDM_RATE6M] = DESC_RATE6M,
382 .maps[RTL_RC_OFDM_RATE9M] = DESC_RATE9M,
383 .maps[RTL_RC_OFDM_RATE12M] = DESC_RATE12M,
384 .maps[RTL_RC_OFDM_RATE18M] = DESC_RATE18M,
385 .maps[RTL_RC_OFDM_RATE24M] = DESC_RATE24M,
386 .maps[RTL_RC_OFDM_RATE36M] = DESC_RATE36M,
387 .maps[RTL_RC_OFDM_RATE48M] = DESC_RATE48M,
388 .maps[RTL_RC_OFDM_RATE54M] = DESC_RATE54M,
389
390 .maps[RTL_RC_HT_RATEMCS7] = DESC_RATEMCS7,
391 .maps[RTL_RC_HT_RATEMCS15] = DESC_RATEMCS15,
392
393
394 .maps[RTL_RC_VHT_RATE_1SS_MCS7] = DESC_RATEVHT1SS_MCS7,
395 .maps[RTL_RC_VHT_RATE_1SS_MCS8] = DESC_RATEVHT1SS_MCS8,
396 .maps[RTL_RC_VHT_RATE_1SS_MCS9] = DESC_RATEVHT1SS_MCS9,
397 .maps[RTL_RC_VHT_RATE_2SS_MCS7] = DESC_RATEVHT2SS_MCS7,
398 .maps[RTL_RC_VHT_RATE_2SS_MCS8] = DESC_RATEVHT2SS_MCS8,
399 .maps[RTL_RC_VHT_RATE_2SS_MCS9] = DESC_RATEVHT2SS_MCS9,
400 };
401
402 static const struct pci_device_id rtl8821ae_pci_ids[] = {
403 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8812, rtl8821ae_hal_cfg)},
404 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8821, rtl8821ae_hal_cfg)},
405 {},
406 };
407
408 MODULE_DEVICE_TABLE(pci, rtl8821ae_pci_ids);
409
410 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
411 MODULE_LICENSE("GPL");
412 MODULE_DESCRIPTION("Realtek 8821ae 802.11ac PCI wireless");
413 MODULE_FIRMWARE("rtlwifi/rtl8821aefw.bin");
414 MODULE_FIRMWARE("rtlwifi/rtl8821aefw_29.bin");
415
416 module_param_named(swenc, rtl8821ae_mod_params.sw_crypto, bool, 0444);
417 module_param_named(debug_level, rtl8821ae_mod_params.debug_level, int, 0644);
418 module_param_named(debug_mask, rtl8821ae_mod_params.debug_mask, ullong, 0644);
419 module_param_named(ips, rtl8821ae_mod_params.inactiveps, bool, 0444);
420 module_param_named(swlps, rtl8821ae_mod_params.swctrl_lps, bool, 0444);
421 module_param_named(fwlps, rtl8821ae_mod_params.fwctrl_lps, bool, 0444);
422 module_param_named(msi, rtl8821ae_mod_params.msi_support, bool, 0444);
423 module_param_named(aspm, rtl8821ae_mod_params.aspm_support, int, 0444);
424 module_param_named(disable_watchdog, rtl8821ae_mod_params.disable_watchdog,
425 bool, 0444);
426 module_param_named(int_clear, rtl8821ae_mod_params.int_clear, bool, 0444);
427 MODULE_PARM_DESC(swenc, "Set to 1 for software crypto (default 0)\n");
428 MODULE_PARM_DESC(ips, "Set to 0 to not use link power save (default 1)\n");
429 MODULE_PARM_DESC(swlps, "Set to 1 to use SW control power save (default 0)\n");
430 MODULE_PARM_DESC(fwlps, "Set to 1 to use FW control power save (default 1)\n");
431 MODULE_PARM_DESC(msi, "Set to 1 to use MSI interrupts mode (default 1)\n");
432 MODULE_PARM_DESC(aspm, "Set to 1 to enable ASPM (default 1)\n");
433 MODULE_PARM_DESC(debug_level, "Set debug level (0-5) (default 0)");
434 MODULE_PARM_DESC(debug_mask, "Set debug mask (default 0)");
435 MODULE_PARM_DESC(disable_watchdog, "Set to 1 to disable the watchdog (default 0)\n");
436 MODULE_PARM_DESC(int_clear, "Set to 0 to disable interrupt clear before set (default 1)\n");
437
438 static SIMPLE_DEV_PM_OPS(rtlwifi_pm_ops, rtl_pci_suspend, rtl_pci_resume);
439
440 static struct pci_driver rtl8821ae_driver = {
441 .name = KBUILD_MODNAME,
442 .id_table = rtl8821ae_pci_ids,
443 .probe = rtl_pci_probe,
444 .remove = rtl_pci_disconnect,
445 .driver.pm = &rtlwifi_pm_ops,
446 };
447
448 module_pci_driver(rtl8821ae_driver);