1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2010 Realtek Corporation.*/
16 #include "../btcoexist/rtl_btc.h"
18 #include <linux/vmalloc.h>
19 #include <linux/module.h>
21 static void rtl8821ae_init_aspm_vars(struct ieee80211_hw
*hw
)
23 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
24 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
26 /*close ASPM for AMD defaultly */
27 rtlpci
->const_amdpci_aspm
= 0;
32 * 1 - Enable ASPM without Clock Req,
33 * 2 - Enable ASPM with Clock Req,
34 * 3 - Alwyas Enable ASPM with Clock Req,
35 * 4 - Always Enable ASPM without Clock Req.
36 * set defult to RTL8192CE:3 RTL8192E:2
38 rtlpci
->const_pci_aspm
= 3;
40 /*Setting for PCI-E device */
41 rtlpci
->const_devicepci_aspm_setting
= 0x03;
43 /*Setting for PCI-E bridge */
44 rtlpci
->const_hostpci_aspm_setting
= 0x02;
47 * In Hw/Sw Radio Off situation.
49 * 1 - From ASPM setting without low Mac Pwr,
50 * 2 - From ASPM setting with low Mac Pwr,
52 * set default to RTL8192CE:0 RTL8192SE:2
54 rtlpci
->const_hwsw_rfoff_d3
= 0;
57 * This setting works for those device with
58 * backdoor ASPM setting such as EPHY setting.
59 * 0 - Not support ASPM,
61 * 2 - According to chipset.
63 rtlpci
->const_support_pciaspm
= rtlpriv
->cfg
->mod_params
->aspm_support
;
66 /*InitializeVariables8812E*/
67 static int rtl8821ae_init_sw_vars(struct ieee80211_hw
*hw
)
70 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
71 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
72 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
73 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
74 char *fw_name
, *wowlan_fw_name
;
76 rtl8821ae_bt_reg_init(hw
);
77 rtlpriv
->btcoexist
.btc_ops
= rtl_btc_get_ops_pointer();
79 rtlpriv
->dm
.dm_initialgain_enable
= 1;
80 rtlpriv
->dm
.dm_flag
= 0;
81 rtlpriv
->dm
.disable_framebursting
= 0;
82 rtlpriv
->dm
.thermalvalue
= 0;
83 rtlpci
->transmit_config
= CFENDFORM
| BIT(15) | BIT(24) | BIT(25);
85 mac
->ht_enable
= true;
88 mac
->vht_cur_ldpc
= 0;
89 mac
->vht_ldpc_cap
= 0;
90 mac
->vht_cur_stbc
= 0;
91 mac
->vht_stbc_cap
= 0;
93 rtlpriv
->rtlhal
.current_bandtype
= BAND_ON_2_4G
;
94 /*following 2 is for register 5G band, refer to _rtl_init_mac80211()*/
95 rtlpriv
->rtlhal
.bandset
= BAND_ON_BOTH
;
96 rtlpriv
->rtlhal
.macphymode
= SINGLEMAC_SINGLEPHY
;
98 rtlpci
->receive_config
= (RCR_APPFCS
|
106 /*This bit controls the PS-Poll packet filter.*/
115 rtlpci
->irq_mask
[0] =
116 (u32
)(IMR_PSTIMEOUT
|
118 IMR_HSISR_IND_ON_INT
|
130 rtlpci
->irq_mask
[1] =
134 rtlpci
->sys_irq_mask
= (u32
)(HSIMR_PDN_INT_EN
|
138 rtlpriv
->psc
.wo_wlan_mode
= WAKE_ON_MAGIC_PACKET
|
139 WAKE_ON_PATTERN_MATCH
;
142 rtlpriv
->psc
.inactiveps
= rtlpriv
->cfg
->mod_params
->inactiveps
;
143 rtlpriv
->psc
.swctrl_lps
= rtlpriv
->cfg
->mod_params
->swctrl_lps
;
144 rtlpriv
->psc
.fwctrl_lps
= rtlpriv
->cfg
->mod_params
->fwctrl_lps
;
145 rtlpci
->msi_support
= rtlpriv
->cfg
->mod_params
->msi_support
;
146 rtlpci
->int_clear
= rtlpriv
->cfg
->mod_params
->int_clear
;
147 if (rtlpriv
->cfg
->mod_params
->disable_watchdog
)
148 pr_info("watchdog disabled\n");
149 rtlpriv
->psc
.reg_fwctrl_lps
= 2;
150 rtlpriv
->psc
.reg_max_lps_awakeintvl
= 2;
152 /* for ASPM, you can close aspm through
153 * set const_support_pciaspm = 0
155 rtl8821ae_init_aspm_vars(hw
);
157 if (rtlpriv
->psc
.reg_fwctrl_lps
== 1)
158 rtlpriv
->psc
.fwctrl_psmode
= FW_PS_MIN_MODE
;
159 else if (rtlpriv
->psc
.reg_fwctrl_lps
== 2)
160 rtlpriv
->psc
.fwctrl_psmode
= FW_PS_MAX_MODE
;
161 else if (rtlpriv
->psc
.reg_fwctrl_lps
== 3)
162 rtlpriv
->psc
.fwctrl_psmode
= FW_PS_DTIM_MODE
;
164 /* for firmware buf */
165 rtlpriv
->rtlhal
.pfirmware
= vzalloc(0x8000);
166 if (!rtlpriv
->rtlhal
.pfirmware
) {
167 pr_err("Can't alloc buffer for fw.\n");
170 rtlpriv
->rtlhal
.wowlan_firmware
= vzalloc(0x8000);
171 if (!rtlpriv
->rtlhal
.wowlan_firmware
) {
172 pr_err("Can't alloc buffer for wowlan fw.\n");
173 vfree(rtlpriv
->rtlhal
.pfirmware
);
174 rtlpriv
->rtlhal
.pfirmware
= NULL
;
178 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
179 fw_name
= "rtlwifi/rtl8812aefw.bin";
180 wowlan_fw_name
= "rtlwifi/rtl8812aefw_wowlan.bin";
182 fw_name
= "rtlwifi/rtl8821aefw_29.bin";
183 wowlan_fw_name
= "rtlwifi/rtl8821aefw_wowlan.bin";
186 rtlpriv
->max_fw_size
= 0x8000;
187 /*load normal firmware*/
188 pr_info("Using firmware %s\n", fw_name
);
189 err
= request_firmware_nowait(THIS_MODULE
, 1, fw_name
,
190 rtlpriv
->io
.dev
, GFP_KERNEL
, hw
,
193 pr_err("Failed to request normal firmware!\n");
194 vfree(rtlpriv
->rtlhal
.wowlan_firmware
);
195 vfree(rtlpriv
->rtlhal
.pfirmware
);
198 /*load wowlan firmware*/
199 pr_info("Using firmware %s\n", wowlan_fw_name
);
200 err
= request_firmware_nowait(THIS_MODULE
, 1,
202 rtlpriv
->io
.dev
, GFP_KERNEL
, hw
,
205 pr_err("Failed to request wowlan firmware!\n");
206 vfree(rtlpriv
->rtlhal
.wowlan_firmware
);
207 vfree(rtlpriv
->rtlhal
.pfirmware
);
213 static void rtl8821ae_deinit_sw_vars(struct ieee80211_hw
*hw
)
215 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
217 if (rtlpriv
->rtlhal
.pfirmware
) {
218 vfree(rtlpriv
->rtlhal
.pfirmware
);
219 rtlpriv
->rtlhal
.pfirmware
= NULL
;
221 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
222 if (rtlpriv
->rtlhal
.wowlan_firmware
) {
223 vfree(rtlpriv
->rtlhal
.wowlan_firmware
);
224 rtlpriv
->rtlhal
.wowlan_firmware
= NULL
;
229 /* get bt coexist status */
230 static bool rtl8821ae_get_btc_status(void)
235 static struct rtl_hal_ops rtl8821ae_hal_ops
= {
236 .init_sw_vars
= rtl8821ae_init_sw_vars
,
237 .deinit_sw_vars
= rtl8821ae_deinit_sw_vars
,
238 .read_eeprom_info
= rtl8821ae_read_eeprom_info
,
239 .interrupt_recognized
= rtl8821ae_interrupt_recognized
,
240 .hw_init
= rtl8821ae_hw_init
,
241 .hw_disable
= rtl8821ae_card_disable
,
242 .hw_suspend
= rtl8821ae_suspend
,
243 .hw_resume
= rtl8821ae_resume
,
244 .enable_interrupt
= rtl8821ae_enable_interrupt
,
245 .disable_interrupt
= rtl8821ae_disable_interrupt
,
246 .set_network_type
= rtl8821ae_set_network_type
,
247 .set_chk_bssid
= rtl8821ae_set_check_bssid
,
248 .set_qos
= rtl8821ae_set_qos
,
249 .set_bcn_reg
= rtl8821ae_set_beacon_related_registers
,
250 .set_bcn_intv
= rtl8821ae_set_beacon_interval
,
251 .update_interrupt_mask
= rtl8821ae_update_interrupt_mask
,
252 .get_hw_reg
= rtl8821ae_get_hw_reg
,
253 .set_hw_reg
= rtl8821ae_set_hw_reg
,
254 .update_rate_tbl
= rtl8821ae_update_hal_rate_tbl
,
255 .fill_tx_desc
= rtl8821ae_tx_fill_desc
,
256 .fill_tx_cmddesc
= rtl8821ae_tx_fill_cmddesc
,
257 .query_rx_desc
= rtl8821ae_rx_query_desc
,
258 .set_channel_access
= rtl8821ae_update_channel_access_setting
,
259 .radio_onoff_checking
= rtl8821ae_gpio_radio_on_off_checking
,
260 .set_bw_mode
= rtl8821ae_phy_set_bw_mode
,
261 .switch_channel
= rtl8821ae_phy_sw_chnl
,
262 .dm_watchdog
= rtl8821ae_dm_watchdog
,
263 .scan_operation_backup
= rtl8821ae_phy_scan_operation_backup
,
264 .set_rf_power_state
= rtl8821ae_phy_set_rf_power_state
,
265 .led_control
= rtl8821ae_led_control
,
266 .set_desc
= rtl8821ae_set_desc
,
267 .get_desc
= rtl8821ae_get_desc
,
268 .is_tx_desc_closed
= rtl8821ae_is_tx_desc_closed
,
269 .tx_polling
= rtl8821ae_tx_polling
,
270 .enable_hw_sec
= rtl8821ae_enable_hw_security_config
,
271 .set_key
= rtl8821ae_set_key
,
272 .init_sw_leds
= rtl8821ae_init_sw_leds
,
273 .get_bbreg
= rtl8821ae_phy_query_bb_reg
,
274 .set_bbreg
= rtl8821ae_phy_set_bb_reg
,
275 .get_rfreg
= rtl8821ae_phy_query_rf_reg
,
276 .set_rfreg
= rtl8821ae_phy_set_rf_reg
,
277 .fill_h2c_cmd
= rtl8821ae_fill_h2c_cmd
,
278 .get_btc_status
= rtl8821ae_get_btc_status
,
279 .c2h_ra_report_handler
= rtl8821ae_c2h_ra_report_handler
,
280 .add_wowlan_pattern
= rtl8821ae_add_wowlan_pattern
,
283 static struct rtl_mod_params rtl8821ae_mod_params
= {
293 .disable_watchdog
= 0,
296 static const struct rtl_hal_cfg rtl8821ae_hal_cfg
= {
298 .write_readback
= true,
299 .name
= "rtl8821ae_pci",
300 .alt_fw_name
= "rtlwifi/rtl8821aefw.bin",
301 .ops
= &rtl8821ae_hal_ops
,
302 .mod_params
= &rtl8821ae_mod_params
,
303 .spec_ver
= RTL_SPEC_SUPPORT_VHT
,
304 .maps
[SYS_ISO_CTRL
] = REG_SYS_ISO_CTRL
,
305 .maps
[SYS_FUNC_EN
] = REG_SYS_FUNC_EN
,
306 .maps
[SYS_CLK
] = REG_SYS_CLKR
,
307 .maps
[MAC_RCR_AM
] = AM
,
308 .maps
[MAC_RCR_AB
] = AB
,
309 .maps
[MAC_RCR_ACRC32
] = ACRC32
,
310 .maps
[MAC_RCR_ACF
] = ACF
,
311 .maps
[MAC_RCR_AAP
] = AAP
,
312 .maps
[MAC_HIMR
] = REG_HIMR
,
313 .maps
[MAC_HIMRE
] = REG_HIMRE
,
315 .maps
[EFUSE_ACCESS
] = REG_EFUSE_ACCESS
,
317 .maps
[EFUSE_TEST
] = REG_EFUSE_TEST
,
318 .maps
[EFUSE_CTRL
] = REG_EFUSE_CTRL
,
319 .maps
[EFUSE_CLK
] = 0,
320 .maps
[EFUSE_CLK_CTRL
] = REG_EFUSE_CTRL
,
321 .maps
[EFUSE_PWC_EV12V
] = PWC_EV12V
,
322 .maps
[EFUSE_FEN_ELDR
] = FEN_ELDR
,
323 .maps
[EFUSE_LOADER_CLK_EN
] = LOADER_CLK_EN
,
324 .maps
[EFUSE_ANA8M
] = ANA8M
,
325 .maps
[EFUSE_HWSET_MAX_SIZE
] = HWSET_MAX_SIZE
,
326 .maps
[EFUSE_MAX_SECTION_MAP
] = EFUSE_MAX_SECTION
,
327 .maps
[EFUSE_REAL_CONTENT_SIZE
] = EFUSE_REAL_CONTENT_LEN
,
328 .maps
[EFUSE_OOB_PROTECT_BYTES_LEN
] = EFUSE_OOB_PROTECT_BYTES
,
330 .maps
[RWCAM
] = REG_CAMCMD
,
331 .maps
[WCAMI
] = REG_CAMWRITE
,
332 .maps
[RCAMO
] = REG_CAMREAD
,
333 .maps
[CAMDBG
] = REG_CAMDBG
,
334 .maps
[SECR
] = REG_SECCFG
,
335 .maps
[SEC_CAM_NONE
] = CAM_NONE
,
336 .maps
[SEC_CAM_WEP40
] = CAM_WEP40
,
337 .maps
[SEC_CAM_TKIP
] = CAM_TKIP
,
338 .maps
[SEC_CAM_AES
] = CAM_AES
,
339 .maps
[SEC_CAM_WEP104
] = CAM_WEP104
,
341 .maps
[RTL_IMR_BCNDMAINT6
] = IMR_BCNDMAINT6
,
342 .maps
[RTL_IMR_BCNDMAINT5
] = IMR_BCNDMAINT5
,
343 .maps
[RTL_IMR_BCNDMAINT4
] = IMR_BCNDMAINT4
,
344 .maps
[RTL_IMR_BCNDMAINT3
] = IMR_BCNDMAINT3
,
345 .maps
[RTL_IMR_BCNDMAINT2
] = IMR_BCNDMAINT2
,
346 .maps
[RTL_IMR_BCNDMAINT1
] = IMR_BCNDMAINT1
,
347 /* .maps[RTL_IMR_BCNDOK8] = IMR_BCNDOK8, */ /*need check*/
348 .maps
[RTL_IMR_BCNDOK7
] = IMR_BCNDOK7
,
349 .maps
[RTL_IMR_BCNDOK6
] = IMR_BCNDOK6
,
350 .maps
[RTL_IMR_BCNDOK5
] = IMR_BCNDOK5
,
351 .maps
[RTL_IMR_BCNDOK4
] = IMR_BCNDOK4
,
352 .maps
[RTL_IMR_BCNDOK3
] = IMR_BCNDOK3
,
353 .maps
[RTL_IMR_BCNDOK2
] = IMR_BCNDOK2
,
354 .maps
[RTL_IMR_BCNDOK1
] = IMR_BCNDOK1
,
355 /* .maps[RTL_IMR_TIMEOUT2] = IMR_TIMEOUT2,*/
356 /* .maps[RTL_IMR_TIMEOUT1] = IMR_TIMEOUT1,*/
358 .maps
[RTL_IMR_TXFOVW
] = IMR_TXFOVW
,
359 .maps
[RTL_IMR_PSTIMEOUT
] = IMR_PSTIMEOUT
,
360 .maps
[RTL_IMR_BCNINT
] = IMR_BCNDMAINT0
,
361 .maps
[RTL_IMR_RXFOVW
] = IMR_RXFOVW
,
362 .maps
[RTL_IMR_RDU
] = IMR_RDU
,
363 .maps
[RTL_IMR_ATIMEND
] = IMR_ATIMEND
,
364 .maps
[RTL_IMR_BDOK
] = IMR_BCNDOK0
,
365 .maps
[RTL_IMR_MGNTDOK
] = IMR_MGNTDOK
,
366 .maps
[RTL_IMR_TBDER
] = IMR_TBDER
,
367 .maps
[RTL_IMR_HIGHDOK
] = IMR_HIGHDOK
,
368 .maps
[RTL_IMR_TBDOK
] = IMR_TBDOK
,
369 .maps
[RTL_IMR_BKDOK
] = IMR_BKDOK
,
370 .maps
[RTL_IMR_BEDOK
] = IMR_BEDOK
,
371 .maps
[RTL_IMR_VIDOK
] = IMR_VIDOK
,
372 .maps
[RTL_IMR_VODOK
] = IMR_VODOK
,
373 .maps
[RTL_IMR_ROK
] = IMR_ROK
,
374 .maps
[RTL_IBSS_INT_MASKS
] = (IMR_BCNDMAINT0
| IMR_TBDOK
| IMR_TBDER
),
376 .maps
[RTL_RC_CCK_RATE1M
] = DESC_RATE1M
,
377 .maps
[RTL_RC_CCK_RATE2M
] = DESC_RATE2M
,
378 .maps
[RTL_RC_CCK_RATE5_5M
] = DESC_RATE5_5M
,
379 .maps
[RTL_RC_CCK_RATE11M
] = DESC_RATE11M
,
380 .maps
[RTL_RC_OFDM_RATE6M
] = DESC_RATE6M
,
381 .maps
[RTL_RC_OFDM_RATE9M
] = DESC_RATE9M
,
382 .maps
[RTL_RC_OFDM_RATE12M
] = DESC_RATE12M
,
383 .maps
[RTL_RC_OFDM_RATE18M
] = DESC_RATE18M
,
384 .maps
[RTL_RC_OFDM_RATE24M
] = DESC_RATE24M
,
385 .maps
[RTL_RC_OFDM_RATE36M
] = DESC_RATE36M
,
386 .maps
[RTL_RC_OFDM_RATE48M
] = DESC_RATE48M
,
387 .maps
[RTL_RC_OFDM_RATE54M
] = DESC_RATE54M
,
389 .maps
[RTL_RC_HT_RATEMCS7
] = DESC_RATEMCS7
,
390 .maps
[RTL_RC_HT_RATEMCS15
] = DESC_RATEMCS15
,
392 /*VHT hightest rate*/
393 .maps
[RTL_RC_VHT_RATE_1SS_MCS7
] = DESC_RATEVHT1SS_MCS7
,
394 .maps
[RTL_RC_VHT_RATE_1SS_MCS8
] = DESC_RATEVHT1SS_MCS8
,
395 .maps
[RTL_RC_VHT_RATE_1SS_MCS9
] = DESC_RATEVHT1SS_MCS9
,
396 .maps
[RTL_RC_VHT_RATE_2SS_MCS7
] = DESC_RATEVHT2SS_MCS7
,
397 .maps
[RTL_RC_VHT_RATE_2SS_MCS8
] = DESC_RATEVHT2SS_MCS8
,
398 .maps
[RTL_RC_VHT_RATE_2SS_MCS9
] = DESC_RATEVHT2SS_MCS9
,
401 static const struct pci_device_id rtl8821ae_pci_ids
[] = {
402 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK
, 0x8812, rtl8821ae_hal_cfg
)},
403 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK
, 0x8821, rtl8821ae_hal_cfg
)},
407 MODULE_DEVICE_TABLE(pci
, rtl8821ae_pci_ids
);
409 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
410 MODULE_LICENSE("GPL");
411 MODULE_DESCRIPTION("Realtek 8821ae 802.11ac PCI wireless");
412 MODULE_FIRMWARE("rtlwifi/rtl8821aefw.bin");
413 MODULE_FIRMWARE("rtlwifi/rtl8821aefw_29.bin");
415 module_param_named(swenc
, rtl8821ae_mod_params
.sw_crypto
, bool, 0444);
416 module_param_named(debug_level
, rtl8821ae_mod_params
.debug_level
, int, 0644);
417 module_param_named(debug_mask
, rtl8821ae_mod_params
.debug_mask
, ullong
, 0644);
418 module_param_named(ips
, rtl8821ae_mod_params
.inactiveps
, bool, 0444);
419 module_param_named(swlps
, rtl8821ae_mod_params
.swctrl_lps
, bool, 0444);
420 module_param_named(fwlps
, rtl8821ae_mod_params
.fwctrl_lps
, bool, 0444);
421 module_param_named(msi
, rtl8821ae_mod_params
.msi_support
, bool, 0444);
422 module_param_named(aspm
, rtl8821ae_mod_params
.aspm_support
, int, 0444);
423 module_param_named(disable_watchdog
, rtl8821ae_mod_params
.disable_watchdog
,
425 module_param_named(int_clear
, rtl8821ae_mod_params
.int_clear
, bool, 0444);
426 MODULE_PARM_DESC(swenc
, "Set to 1 for software crypto (default 0)\n");
427 MODULE_PARM_DESC(ips
, "Set to 0 to not use link power save (default 1)\n");
428 MODULE_PARM_DESC(swlps
, "Set to 1 to use SW control power save (default 0)\n");
429 MODULE_PARM_DESC(fwlps
, "Set to 1 to use FW control power save (default 1)\n");
430 MODULE_PARM_DESC(msi
, "Set to 1 to use MSI interrupts mode (default 1)\n");
431 MODULE_PARM_DESC(aspm
, "Set to 1 to enable ASPM (default 1)\n");
432 MODULE_PARM_DESC(debug_level
, "Set debug level (0-5) (default 0)");
433 MODULE_PARM_DESC(debug_mask
, "Set debug mask (default 0)");
434 MODULE_PARM_DESC(disable_watchdog
, "Set to 1 to disable the watchdog (default 0)\n");
435 MODULE_PARM_DESC(int_clear
, "Set to 0 to disable interrupt clear before set (default 1)\n");
437 static SIMPLE_DEV_PM_OPS(rtlwifi_pm_ops
, rtl_pci_suspend
, rtl_pci_resume
);
439 static struct pci_driver rtl8821ae_driver
= {
440 .name
= KBUILD_MODNAME
,
441 .id_table
= rtl8821ae_pci_ids
,
442 .probe
= rtl_pci_probe
,
443 .remove
= rtl_pci_disconnect
,
444 .driver
.pm
= &rtlwifi_pm_ops
,
447 module_pci_driver(rtl8821ae_driver
);