1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
19 void rtl92se_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
21 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
22 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
23 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
27 *((u32
*) (val
)) = rtlpci
->receive_config
;
30 case HW_VAR_RF_STATE
: {
31 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
34 case HW_VAR_FW_PSMODE_STATUS
: {
35 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
38 case HW_VAR_CORRECT_TSF
: {
40 u32
*ptsf_low
= (u32
*)&tsf
;
41 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
43 *ptsf_high
= rtl_read_dword(rtlpriv
, (TSFR
+ 4));
44 *ptsf_low
= rtl_read_dword(rtlpriv
, TSFR
);
46 *((u64
*) (val
)) = tsf
;
51 *((bool *)(val
)) = rtlpriv
->dm
.current_mrc_switch
;
57 pr_err("switch case %#x not processed\n", variable
);
62 void rtl92se_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
64 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
65 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
66 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
67 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
68 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
69 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
72 case HW_VAR_ETHER_ADDR
:{
73 rtl_write_dword(rtlpriv
, IDR0
, ((u32
*)(val
))[0]);
74 rtl_write_word(rtlpriv
, IDR4
, ((u16
*)(val
+ 4))[0]);
77 case HW_VAR_BASIC_RATE
:{
78 u16 rate_cfg
= ((u16
*) val
)[0];
81 if (rtlhal
->version
== VERSION_8192S_ACUT
)
82 rate_cfg
= rate_cfg
& 0x150;
84 rate_cfg
= rate_cfg
& 0x15f;
88 rtl_write_byte(rtlpriv
, RRSR
, rate_cfg
& 0xff);
89 rtl_write_byte(rtlpriv
, RRSR
+ 1,
90 (rate_cfg
>> 8) & 0xff);
92 while (rate_cfg
> 0x1) {
93 rate_cfg
= (rate_cfg
>> 1);
96 rtl_write_byte(rtlpriv
, INIRTSMCS_SEL
, rate_index
);
101 rtl_write_dword(rtlpriv
, BSSIDR
, ((u32
*)(val
))[0]);
102 rtl_write_word(rtlpriv
, BSSIDR
+ 4,
103 ((u16
*)(val
+ 4))[0]);
107 rtl_write_byte(rtlpriv
, SIFS_OFDM
, val
[0]);
108 rtl_write_byte(rtlpriv
, SIFS_OFDM
+ 1, val
[1]);
111 case HW_VAR_SLOT_TIME
:{
114 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
115 "HW_VAR_SLOT_TIME %x\n", val
[0]);
117 rtl_write_byte(rtlpriv
, SLOT_TIME
, val
[0]);
119 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
120 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
126 case HW_VAR_ACK_PREAMBLE
:{
128 u8 short_preamble
= (bool) (*val
);
129 reg_tmp
= (mac
->cur_40_prime_sc
) << 5;
133 rtl_write_byte(rtlpriv
, RRSR
+ 2, reg_tmp
);
136 case HW_VAR_AMPDU_MIN_SPACE
:{
137 u8 min_spacing_to_set
;
140 min_spacing_to_set
= *val
;
141 if (min_spacing_to_set
<= 7) {
142 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
148 if (min_spacing_to_set
< sec_min_space
)
149 min_spacing_to_set
= sec_min_space
;
150 if (min_spacing_to_set
> 5)
151 min_spacing_to_set
= 5;
154 ((mac
->min_space_cfg
& 0xf8) |
157 *val
= min_spacing_to_set
;
159 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
160 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
163 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
,
168 case HW_VAR_SHORTGI_DENSITY
:{
171 density_to_set
= *val
;
172 mac
->min_space_cfg
= rtlpriv
->rtlhal
.minspace_cfg
;
173 mac
->min_space_cfg
|= (density_to_set
<< 3);
175 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
176 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
179 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
,
184 case HW_VAR_AMPDU_FACTOR
:{
187 u8 factorlevel
[18] = {
188 2, 4, 4, 7, 7, 13, 13,
194 if (factor_toset
<= 3) {
195 factor_toset
= (1 << (factor_toset
+ 2));
196 if (factor_toset
> 0xf)
199 for (index
= 0; index
< 17; index
++) {
200 if (factorlevel
[index
] > factor_toset
)
205 for (index
= 0; index
< 8; index
++) {
206 regtoset
= ((factorlevel
[index
* 2]) |
209 rtl_write_byte(rtlpriv
,
210 AGGLEN_LMT_L
+ index
,
214 regtoset
= ((factorlevel
[16]) |
215 (factorlevel
[17] << 4));
216 rtl_write_byte(rtlpriv
, AGGLEN_LMT_H
, regtoset
);
218 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
219 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
224 case HW_VAR_AC_PARAM
:{
226 rtl92s_dm_init_edca_turbo(hw
);
228 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
229 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
234 case HW_VAR_ACM_CTRL
:{
236 union aci_aifsn
*p_aci_aifsn
= (union aci_aifsn
*)(&(
238 u8 acm
= p_aci_aifsn
->f
.acm
;
239 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, ACMHWCTRL
);
241 acm_ctrl
= acm_ctrl
| ((rtlpci
->acm_method
== 2) ?
247 acm_ctrl
|= ACMHW_BEQEN
;
250 acm_ctrl
|= ACMHW_VIQEN
;
253 acm_ctrl
|= ACMHW_VOQEN
;
256 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
257 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
264 acm_ctrl
&= (~ACMHW_BEQEN
);
267 acm_ctrl
&= (~ACMHW_VIQEN
);
270 acm_ctrl
&= (~ACMHW_VOQEN
);
273 pr_err("switch case %#x not processed\n",
279 rtl_dbg(rtlpriv
, COMP_QOS
, DBG_TRACE
,
280 "HW_VAR_ACM_CTRL Write 0x%X\n", acm_ctrl
);
281 rtl_write_byte(rtlpriv
, ACMHWCTRL
, acm_ctrl
);
285 rtl_write_dword(rtlpriv
, RCR
, ((u32
*) (val
))[0]);
286 rtlpci
->receive_config
= ((u32
*) (val
))[0];
289 case HW_VAR_RETRY_LIMIT
:{
290 u8 retry_limit
= val
[0];
292 rtl_write_word(rtlpriv
, RETRY_LIMIT
,
293 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
294 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
297 case HW_VAR_DUAL_TSF_RST
: {
300 case HW_VAR_EFUSE_BYTES
: {
301 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
304 case HW_VAR_EFUSE_USAGE
: {
305 rtlefuse
->efuse_usedpercentage
= *val
;
308 case HW_VAR_IO_CMD
: {
311 case HW_VAR_WPA_CONFIG
: {
312 rtl_write_byte(rtlpriv
, REG_SECR
, *val
);
315 case HW_VAR_SET_RPWM
:{
318 case HW_VAR_H2C_FW_PWRMODE
:{
321 case HW_VAR_FW_PSMODE_STATUS
: {
322 ppsc
->fw_current_inpsmode
= *((bool *) val
);
325 case HW_VAR_H2C_FW_JOINBSSRPT
:{
331 case HW_VAR_CORRECT_TSF
:{
335 bool bmrc_toset
= *((bool *)val
);
339 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
341 u1bdata
= (u8
)rtl_get_bbreg(hw
,
342 ROFDM1_TRXPATHENABLE
,
344 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
,
346 ((u1bdata
& 0xf0) | 0x03));
347 u1bdata
= (u8
)rtl_get_bbreg(hw
,
348 ROFDM0_TRXPATHENABLE
,
350 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
354 /* Update current settings. */
355 rtlpriv
->dm
.current_mrc_switch
= bmrc_toset
;
357 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
359 u1bdata
= (u8
)rtl_get_bbreg(hw
,
360 ROFDM1_TRXPATHENABLE
,
362 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
,
364 ((u1bdata
& 0xf0) | 0x01));
365 u1bdata
= (u8
)rtl_get_bbreg(hw
,
366 ROFDM0_TRXPATHENABLE
,
368 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
369 MASKBYTE1
, (u1bdata
& 0xfb));
371 /* Update current settings. */
372 rtlpriv
->dm
.current_mrc_switch
= bmrc_toset
;
377 case HW_VAR_FW_LPS_ACTION
: {
378 bool enter_fwlps
= *((bool *)val
);
379 u8 rpwm_val
, fw_pwrmode
;
380 bool fw_current_inps
;
383 rpwm_val
= 0x02; /* RF off */
384 fw_current_inps
= true;
385 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
386 HW_VAR_FW_PSMODE_STATUS
,
387 (u8
*)(&fw_current_inps
));
388 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
389 HW_VAR_H2C_FW_PWRMODE
,
390 &ppsc
->fwctrl_psmode
);
392 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
395 rpwm_val
= 0x0C; /* RF on */
396 fw_pwrmode
= FW_PS_ACTIVE_MODE
;
397 fw_current_inps
= false;
398 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
400 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
403 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
404 HW_VAR_FW_PSMODE_STATUS
,
405 (u8
*)(&fw_current_inps
));
409 pr_err("switch case %#x not processed\n", variable
);
415 void rtl92se_enable_hw_security_config(struct ieee80211_hw
*hw
)
417 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
418 u8 sec_reg_value
= 0x0;
420 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
421 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
422 rtlpriv
->sec
.pairwise_enc_algorithm
,
423 rtlpriv
->sec
.group_enc_algorithm
);
425 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
426 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
427 "not open hw encryption\n");
431 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXENCENABLE
;
433 if (rtlpriv
->sec
.use_defaultkey
) {
434 sec_reg_value
|= SCR_TXUSEDK
;
435 sec_reg_value
|= SCR_RXUSEDK
;
438 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_LOUD
, "The SECR-value %x\n",
441 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
445 static u8
_rtl92se_halset_sysclk(struct ieee80211_hw
*hw
, u8 data
)
447 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
449 bool bresult
= false;
452 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, data
);
454 /* Wait the MAC synchronized. */
457 /* Check if it is set ready. */
458 tmpvalue
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
459 bresult
= ((tmpvalue
& BIT(7)) == (data
& BIT(7)));
461 if ((data
& (BIT(6) | BIT(7))) == false) {
468 tmpvalue
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
469 if ((tmpvalue
& BIT(6)))
472 pr_err("wait for BIT(6) return value %x\n", tmpvalue
);
488 void rtl8192se_gpiobit3_cfg_inputmode(struct ieee80211_hw
*hw
)
490 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
493 /* The following config GPIO function */
494 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, (GPIOMUX_EN
| GPIOSEL_GPIO
));
495 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IO_SEL
);
497 /* config GPIO3 to input */
498 u1tmp
&= HAL_8192S_HW_GPIO_OFF_MASK
;
499 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, u1tmp
);
503 static u8
_rtl92se_rf_onoff_detect(struct ieee80211_hw
*hw
)
505 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
509 /* The following config GPIO function */
510 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, (GPIOMUX_EN
| GPIOSEL_GPIO
));
511 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IO_SEL
);
513 /* config GPIO3 to input */
514 u1tmp
&= HAL_8192S_HW_GPIO_OFF_MASK
;
515 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, u1tmp
);
517 /* On some of the platform, driver cannot read correct
518 * value without delay between Write_GPIO_SEL and Read_GPIO_IN */
522 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IN_SE
);
523 retval
= (u1tmp
& HAL_8192S_HW_GPIO_OFF_BIT
) ? ERFON
: ERFOFF
;
528 static void _rtl92se_macconfig_before_fwdownload(struct ieee80211_hw
*hw
)
530 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
531 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
532 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
539 if (rtlpci
->first_init
) {
540 /* Reset PCIE Digital */
541 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
543 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
545 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
| BIT(0));
548 /* Switch to SW IO control */
549 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
550 if (tmpu1b
& BIT(7)) {
551 tmpu1b
&= ~(BIT(6) | BIT(7));
553 /* Set failed, return to prevent hang. */
554 if (!_rtl92se_halset_sysclk(hw
, tmpu1b
))
558 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x0);
560 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
563 /* Clear FW RPWM for FW control LPS.*/
564 rtl_write_byte(rtlpriv
, RPWM
, 0x0);
566 /* Reset MAC-IO and CPU and Core Digital BIT(10)/11/15 */
567 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
569 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
570 /* wait for BIT 10/11/15 to pull high automatically!! */
573 rtl_write_byte(rtlpriv
, CMDR
, 0);
574 rtl_write_byte(rtlpriv
, TCR
, 0);
576 /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
577 tmpu1b
= rtl_read_byte(rtlpriv
, 0x562);
579 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
581 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
583 /* Enable AFE clock source */
584 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
);
585 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, (tmpu1b
| 0x01));
588 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1);
589 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, (tmpu1b
& 0xfb));
591 /* Enable AFE Macro Block's Bandgap */
592 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
593 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| BIT(0)));
596 /* Enable AFE Mbias */
597 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
598 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| 0x02));
601 /* Enable LDOA15 block */
602 tmpu1b
= rtl_read_byte(rtlpriv
, LDOA15_CTRL
);
603 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, (tmpu1b
| BIT(0)));
605 /* Set Digital Vdd to Retention isolation Path. */
606 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
607 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, (tmpu2b
| BIT(11)));
609 /* For warm reboot NIC disappera bug. */
610 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
611 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(13)));
613 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, 0x68);
615 /* Enable AFE PLL Macro Block */
616 /* We need to delay 100u before enabling PLL. */
618 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
);
619 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
621 /* for divider reset */
623 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) |
626 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
629 /* Enable MAC 80MHZ clock */
630 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
+ 1);
631 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, (tmpu1b
| BIT(0)));
634 /* Release isolation AFE PLL & MD */
635 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xA6);
637 /* Enable MAC clock */
638 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
639 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
| BIT(12) | BIT(11)));
641 /* Enable Core digital and enable IOREG R/W */
642 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
643 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11)));
645 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
646 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
& ~(BIT(7)));
649 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11) | BIT(15)));
651 /* Switch the control path. */
652 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
653 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
& (~BIT(2))));
655 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
656 tmpu1b
= ((tmpu1b
| BIT(7)) & (~BIT(6)));
657 if (!_rtl92se_halset_sysclk(hw
, tmpu1b
))
658 return; /* Set failed, return to prevent hang. */
660 rtl_write_word(rtlpriv
, CMDR
, 0x07FC);
662 /* MH We must enable the section of code to prevent load IMEM fail. */
663 /* Load MAC register from WMAc temporarily We simulate macreg. */
664 /* txt HW will provide MAC txt later */
665 rtl_write_byte(rtlpriv
, 0x6, 0x30);
666 rtl_write_byte(rtlpriv
, 0x49, 0xf0);
668 rtl_write_byte(rtlpriv
, 0x4b, 0x81);
670 rtl_write_byte(rtlpriv
, 0xb5, 0x21);
672 rtl_write_byte(rtlpriv
, 0xdc, 0xff);
673 rtl_write_byte(rtlpriv
, 0xdd, 0xff);
674 rtl_write_byte(rtlpriv
, 0xde, 0xff);
675 rtl_write_byte(rtlpriv
, 0xdf, 0xff);
677 rtl_write_byte(rtlpriv
, 0x11a, 0x00);
678 rtl_write_byte(rtlpriv
, 0x11b, 0x00);
680 for (i
= 0; i
< 32; i
++)
681 rtl_write_byte(rtlpriv
, INIMCS_SEL
+ i
, 0x1b);
683 rtl_write_byte(rtlpriv
, 0x236, 0xff);
685 rtl_write_byte(rtlpriv
, 0x503, 0x22);
687 if (ppsc
->support_aspm
&& !ppsc
->support_backdoor
)
688 rtl_write_byte(rtlpriv
, 0x560, 0x40);
690 rtl_write_byte(rtlpriv
, 0x560, 0x00);
692 rtl_write_byte(rtlpriv
, DBG_PORT
, 0x91);
694 /* Set RX Desc Address */
695 rtl_write_dword(rtlpriv
, RDQDA
, rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
);
696 rtl_write_dword(rtlpriv
, RCDA
, rtlpci
->rx_ring
[RX_CMD_QUEUE
].dma
);
698 /* Set TX Desc Address */
699 rtl_write_dword(rtlpriv
, TBKDA
, rtlpci
->tx_ring
[BK_QUEUE
].dma
);
700 rtl_write_dword(rtlpriv
, TBEDA
, rtlpci
->tx_ring
[BE_QUEUE
].dma
);
701 rtl_write_dword(rtlpriv
, TVIDA
, rtlpci
->tx_ring
[VI_QUEUE
].dma
);
702 rtl_write_dword(rtlpriv
, TVODA
, rtlpci
->tx_ring
[VO_QUEUE
].dma
);
703 rtl_write_dword(rtlpriv
, TBDA
, rtlpci
->tx_ring
[BEACON_QUEUE
].dma
);
704 rtl_write_dword(rtlpriv
, TCDA
, rtlpci
->tx_ring
[TXCMD_QUEUE
].dma
);
705 rtl_write_dword(rtlpriv
, TMDA
, rtlpci
->tx_ring
[MGNT_QUEUE
].dma
);
706 rtl_write_dword(rtlpriv
, THPDA
, rtlpci
->tx_ring
[HIGH_QUEUE
].dma
);
707 rtl_write_dword(rtlpriv
, HDA
, rtlpci
->tx_ring
[HCCA_QUEUE
].dma
);
709 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
711 /* To make sure that TxDMA can ready to download FW. */
712 /* We should reset TxDMA if IMEM RPT was not ready. */
714 tmpu1b
= rtl_read_byte(rtlpriv
, TCR
);
715 if ((tmpu1b
& TXDMA_INIT_VALUE
) == TXDMA_INIT_VALUE
)
719 } while (pollingcnt
--);
721 if (pollingcnt
<= 0) {
722 pr_err("Polling TXDMA_INIT_VALUE timeout!! Current TCR(%#x)\n",
724 tmpu1b
= rtl_read_byte(rtlpriv
, CMDR
);
725 rtl_write_byte(rtlpriv
, CMDR
, tmpu1b
& (~TXDMA_EN
));
728 rtl_write_byte(rtlpriv
, CMDR
, tmpu1b
| TXDMA_EN
);
731 /* After MACIO reset,we must refresh LED state. */
732 if ((ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) ||
733 (ppsc
->rfoff_reason
== 0)) {
734 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
735 enum rf_pwrstate rfpwr_state_toset
;
736 rfpwr_state_toset
= _rtl92se_rf_onoff_detect(hw
);
738 if (rfpwr_state_toset
== ERFON
)
739 rtl92se_sw_led_on(hw
, pled0
);
743 static void _rtl92se_macconfig_after_fwdownload(struct ieee80211_hw
*hw
)
745 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
746 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
747 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
748 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
752 /* 1. System Configure Register (Offset: 0x0000 - 0x003F) */
754 /* 2. Command Control Register (Offset: 0x0040 - 0x004F) */
755 /* Turn on 0x40 Command register */
756 rtl_write_word(rtlpriv
, CMDR
, (BBRSTN
| BB_GLB_RSTN
|
757 SCHEDULE_EN
| MACRXEN
| MACTXEN
| DDMA_EN
| FW2HW_EN
|
758 RXDMA_EN
| TXDMA_EN
| HCI_RXDMA_EN
| HCI_TXDMA_EN
));
760 /* Set TCR TX DMA pre 2 FULL enable bit */
761 rtl_write_dword(rtlpriv
, TCR
, rtl_read_dword(rtlpriv
, TCR
) |
765 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
767 /* 3. MACID Setting Register (Offset: 0x0050 - 0x007F) */
769 /* 4. Timing Control Register (Offset: 0x0080 - 0x009F) */
770 /* Set CCK/OFDM SIFS */
771 /* CCK SIFS shall always be 10us. */
772 rtl_write_word(rtlpriv
, SIFS_CCK
, 0x0a0a);
773 rtl_write_word(rtlpriv
, SIFS_OFDM
, 0x1010);
776 rtl_write_byte(rtlpriv
, ACK_TIMEOUT
, 0x40);
779 rtl_write_word(rtlpriv
, BCN_INTERVAL
, 100);
780 rtl_write_word(rtlpriv
, ATIMWND
, 2);
782 /* 5. FIFO Control Register (Offset: 0x00A0 - 0x015F) */
783 /* 5.1 Initialize Number of Reserved Pages in Firmware Queue */
784 /* Firmware allocate now, associate with FW internal setting.!!! */
786 /* 5.2 Setting TX/RX page size 0/1/2/3/4=64/128/256/512/1024 */
787 /* 5.3 Set driver info, we only accept PHY status now. */
788 /* 5.4 Set RXDMA arbitration to control RXDMA/MAC/FW R/W for RXFIFO */
789 rtl_write_byte(rtlpriv
, RXDMA
, rtl_read_byte(rtlpriv
, RXDMA
) | BIT(6));
791 /* 6. Adaptive Control Register (Offset: 0x0160 - 0x01CF) */
792 /* Set RRSR to all legacy rate and HT rate
793 * CCK rate is supported by default.
794 * CCK rate will be filtered out only when associated
795 * AP does not support it.
796 * Only enable ACK rate to OFDM 24M
797 * Disable RRSR for CCK rate in A-Cut */
799 if (rtlhal
->version
== VERSION_8192S_ACUT
)
800 rtl_write_byte(rtlpriv
, RRSR
, 0xf0);
801 else if (rtlhal
->version
== VERSION_8192S_BCUT
)
802 rtl_write_byte(rtlpriv
, RRSR
, 0xff);
803 rtl_write_byte(rtlpriv
, RRSR
+ 1, 0x01);
804 rtl_write_byte(rtlpriv
, RRSR
+ 2, 0x00);
806 /* A-Cut IC do not support CCK rate. We forbid ARFR to */
807 /* fallback to CCK rate */
808 for (i
= 0; i
< 8; i
++) {
809 /*Disable RRSR for CCK rate in A-Cut */
810 if (rtlhal
->version
== VERSION_8192S_ACUT
)
811 rtl_write_dword(rtlpriv
, ARFR0
+ i
* 4, 0x1f0ff0f0);
814 /* Different rate use different AMPDU size */
815 /* MCS32/ MCS15_SG use max AMPDU size 15*2=30K */
816 rtl_write_byte(rtlpriv
, AGGLEN_LMT_H
, 0x0f);
817 /* MCS0/1/2/3 use max AMPDU size 4*2=8K */
818 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
, 0x7442);
819 /* MCS4/5 use max AMPDU size 8*2=16K 6/7 use 10*2=20K */
820 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 2, 0xddd7);
821 /* MCS8/9 use max AMPDU size 8*2=16K 10/11 use 10*2=20K */
822 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 4, 0xd772);
823 /* MCS12/13/14/15 use max AMPDU size 15*2=30K */
824 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 6, 0xfffd);
826 /* Set Data / Response auto rate fallack retry count */
827 rtl_write_dword(rtlpriv
, DARFRC
, 0x04010000);
828 rtl_write_dword(rtlpriv
, DARFRC
+ 4, 0x09070605);
829 rtl_write_dword(rtlpriv
, RARFRC
, 0x04010000);
830 rtl_write_dword(rtlpriv
, RARFRC
+ 4, 0x09070605);
832 /* 7. EDCA Setting Register (Offset: 0x01D0 - 0x01FF) */
833 /* Set all rate to support SG */
834 rtl_write_word(rtlpriv
, SG_RATE
, 0xFFFF);
836 /* 8. WMAC, BA, and CCX related Register (Offset: 0x0200 - 0x023F) */
837 /* Set NAV protection length */
838 rtl_write_word(rtlpriv
, NAV_PROT_LEN
, 0x0080);
839 /* CF-END Threshold */
840 rtl_write_byte(rtlpriv
, CFEND_TH
, 0xFF);
841 /* Set AMPDU minimum space */
842 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
, 0x07);
843 /* Set TXOP stall control for several queue/HI/BCN/MGT/ */
844 rtl_write_byte(rtlpriv
, TXOP_STALL_CTRL
, 0x00);
846 /* 9. Security Control Register (Offset: 0x0240 - 0x025F) */
847 /* 10. Power Save Control Register (Offset: 0x0260 - 0x02DF) */
848 /* 11. General Purpose Register (Offset: 0x02E0 - 0x02FF) */
849 /* 12. Host Interrupt Status Register (Offset: 0x0300 - 0x030F) */
850 /* 13. Test mode and Debug Control Register (Offset: 0x0310 - 0x034F) */
852 /* 14. Set driver info, we only accept PHY status now. */
853 rtl_write_byte(rtlpriv
, RXDRVINFO_SZ
, 4);
855 /* 15. For EEPROM R/W Workaround */
856 /* 16. For EFUSE to share REG_SYS_FUNC_EN with EEPROM!!! */
857 tmpu2b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
858 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, tmpu2b
| BIT(13));
859 tmpu2b
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
);
860 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, tmpu2b
& (~BIT(8)));
863 /* We may R/W EFUSE in EEPROM mode */
864 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
867 tempval
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1);
869 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, tempval
);
871 /* Change Program timing */
872 rtl_write_byte(rtlpriv
, REG_EFUSE_CTRL
+ 3, 0x72);
873 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "EFUSE CONFIG OK\n");
876 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "OK\n");
880 static void _rtl92se_hw_configure(struct ieee80211_hw
*hw
)
882 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
883 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
884 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
885 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
887 u8 reg_bw_opmode
= 0;
891 reg_bw_opmode
= BW_OPMODE_20MHZ
;
892 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
894 regtmp
= rtl_read_byte(rtlpriv
, INIRTSMCS_SEL
);
895 reg_rrsr
= ((reg_rrsr
& 0x000fffff) << 8) | regtmp
;
896 rtl_write_dword(rtlpriv
, INIRTSMCS_SEL
, reg_rrsr
);
897 rtl_write_byte(rtlpriv
, BW_OPMODE
, reg_bw_opmode
);
899 /* Set Retry Limit here */
900 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
901 (u8
*)(&rtlpci
->shortretry_limit
));
903 rtl_write_byte(rtlpriv
, MLT
, 0x8f);
905 /* For Min Spacing configuration. */
906 switch (rtlphy
->rf_type
) {
909 rtlhal
->minspace_cfg
= (MAX_MSS_DENSITY_1T
<< 3);
913 rtlhal
->minspace_cfg
= (MAX_MSS_DENSITY_2T
<< 3);
916 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
, rtlhal
->minspace_cfg
);
919 int rtl92se_hw_init(struct ieee80211_hw
*hw
)
921 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
922 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
923 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
924 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
925 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
928 bool rtstatus
= true;
932 int wdcapra_add
[] = {
933 EDCAPARA_BE
, EDCAPARA_BK
,
934 EDCAPARA_VI
, EDCAPARA_VO
};
937 rtlpci
->being_init_adapter
= true;
939 /* As this function can take a very long time (up to 350 ms)
940 * and can be called with irqs disabled, reenable the irqs
941 * to let the other devices continue being serviced.
943 * It is safe doing so since our own interrupts will only be enabled
944 * in a subsequent step.
946 local_save_flags(flags
);
949 rtlpriv
->intf_ops
->disable_aspm(hw
);
951 /* 1. MAC Initialize */
952 /* Before FW download, we have to set some MAC register */
953 _rtl92se_macconfig_before_fwdownload(hw
);
955 rtlhal
->version
= (enum version_8192s
)((rtl_read_dword(rtlpriv
,
956 PMC_FSM
) >> 16) & 0xF);
958 rtl8192se_gpiobit3_cfg_inputmode(hw
);
960 /* 2. download firmware */
961 rtstatus
= rtl92s_download_fw(hw
);
963 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
964 "Failed to download FW. Init HW without FW now... Please copy FW into /lib/firmware/rtlwifi\n");
969 /* After FW download, we have to reset MAC register */
970 _rtl92se_macconfig_after_fwdownload(hw
);
972 /*Retrieve default FW Cmd IO map. */
973 rtlhal
->fwcmd_iomap
= rtl_read_word(rtlpriv
, LBUS_MON_ADDR
);
974 rtlhal
->fwcmd_ioparam
= rtl_read_dword(rtlpriv
, LBUS_ADDR_MASK
);
976 /* 3. Initialize MAC/PHY Config by MACPHY_reg.txt */
977 if (!rtl92s_phy_mac_config(hw
)) {
978 pr_err("MAC Config failed\n");
983 /* because last function modify RCR, so we update
984 * rcr var here, or TP will unstable for receive_config
985 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
986 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
988 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, RCR
);
989 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
990 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
992 /* Make sure BB/RF write OK. We should prevent enter IPS. radio off. */
993 /* We must set flag avoid BB/RF config period later!! */
994 rtl_write_dword(rtlpriv
, CMDR
, 0x37FC);
996 /* 4. Initialize BB After MAC Config PHY_reg.txt, AGC_Tab.txt */
997 if (!rtl92s_phy_bb_config(hw
)) {
998 pr_err("BB Config failed\n");
1003 /* 5. Initiailze RF RAIO_A.txt RF RAIO_B.txt */
1004 /* Before initalizing RF. We can not use FW to do RF-R/W. */
1006 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1008 /* Before RF-R/W we must execute the IO from Scott's suggestion. */
1009 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, 0xDB);
1010 if (rtlhal
->version
== VERSION_8192S_ACUT
)
1011 rtl_write_byte(rtlpriv
, SPS1_CTRL
+ 3, 0x07);
1013 rtl_write_byte(rtlpriv
, RF_CTRL
, 0x07);
1015 if (!rtl92s_phy_rf_config(hw
)) {
1016 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "RF Config failed\n");
1021 /* After read predefined TXT, we must set BB/MAC/RF
1022 * register as our requirement */
1024 rtlphy
->rfreg_chnlval
[0] = rtl92s_phy_query_rf_reg(hw
,
1028 rtlphy
->rfreg_chnlval
[1] = rtl92s_phy_query_rf_reg(hw
,
1033 /*---- Set CCK and OFDM Block "ON"----*/
1034 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1035 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1037 /*3 Set Hardware(Do nothing now) */
1038 _rtl92se_hw_configure(hw
);
1040 /* Read EEPROM TX power index and PHY_REG_PG.txt to capture correct */
1041 /* TX power index for different rate set. */
1042 /* Get original hw reg values */
1043 rtl92s_phy_get_hw_reg_originalvalue(hw
);
1044 /* Write correct tx power index */
1045 rtl92s_phy_set_txpower(hw
, rtlphy
->current_channel
);
1047 /* We must set MAC address after firmware download. */
1048 for (i
= 0; i
< 6; i
++)
1049 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1051 /* EEPROM R/W workaround */
1052 tmp_u1b
= rtl_read_byte(rtlpriv
, MAC_PINMUX_CFG
);
1053 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, tmp_u1b
& (~BIT(3)));
1055 rtl_write_byte(rtlpriv
, 0x4d, 0x0);
1057 if (hal_get_firmwareversion(rtlpriv
) >= 0x49) {
1058 tmp_byte
= rtl_read_byte(rtlpriv
, FW_RSVD_PG_CRTL
) & (~BIT(4));
1059 tmp_byte
= tmp_byte
| BIT(5);
1060 rtl_write_byte(rtlpriv
, FW_RSVD_PG_CRTL
, tmp_byte
);
1061 rtl_write_dword(rtlpriv
, TXDESC_MSK
, 0xFFFFCFFF);
1064 /* We enable high power and RA related mechanism after NIC
1066 if (hal_get_firmwareversion(rtlpriv
) >= 0x35) {
1067 /* Fw v.53 and later. */
1068 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_INIT
);
1069 } else if (hal_get_firmwareversion(rtlpriv
) == 0x34) {
1071 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_INIT
);
1072 rtl92s_phy_chk_fwcmd_iodone(hw
);
1074 /* Compatible earlier FW version. */
1075 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_RESET
);
1076 rtl92s_phy_chk_fwcmd_iodone(hw
);
1077 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_ACTIVE
);
1078 rtl92s_phy_chk_fwcmd_iodone(hw
);
1079 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_REFRESH
);
1080 rtl92s_phy_chk_fwcmd_iodone(hw
);
1083 /* Add to prevent ASPM bug. */
1084 /* Always enable hst and NIC clock request. */
1085 rtl92s_phy_switch_ephy_parameter(hw
);
1088 * 1. Clear all H/W keys.
1089 * 2. Enable H/W encryption/decryption. */
1090 rtl_cam_reset_all_entry(hw
);
1091 secr_value
|= SCR_TXENCENABLE
;
1092 secr_value
|= SCR_RXENCENABLE
;
1093 secr_value
|= SCR_NOSKMC
;
1094 rtl_write_byte(rtlpriv
, REG_SECR
, secr_value
);
1096 for (i
= 0; i
< 4; i
++)
1097 rtl_write_dword(rtlpriv
, wdcapra_add
[i
], 0x5e4322);
1099 if (rtlphy
->rf_type
== RF_1T2R
) {
1100 bool mrc2set
= true;
1101 /* Turn on B-Path */
1102 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MRC
, (u8
*)&mrc2set
);
1105 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_ON
);
1108 local_irq_restore(flags
);
1109 rtlpci
->being_init_adapter
= false;
1113 void rtl92se_set_mac_addr(struct rtl_io
*io
, const u8
*addr
)
1115 /* This is a stub. */
1118 void rtl92se_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1120 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1123 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1126 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1129 reg_rcr
|= (RCR_CBSSID
);
1130 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1131 } else if (!check_bssid
) {
1132 reg_rcr
&= (~RCR_CBSSID
);
1133 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1138 static int _rtl92se_set_media_status(struct ieee80211_hw
*hw
,
1139 enum nl80211_iftype type
)
1141 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1142 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1144 bt_msr
&= ~MSR_LINK_MASK
;
1147 case NL80211_IFTYPE_UNSPECIFIED
:
1148 bt_msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
1149 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1150 "Set Network type to NO LINK!\n");
1152 case NL80211_IFTYPE_ADHOC
:
1153 bt_msr
|= (MSR_LINK_ADHOC
<< MSR_LINK_SHIFT
);
1154 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1155 "Set Network type to Ad Hoc!\n");
1157 case NL80211_IFTYPE_STATION
:
1158 bt_msr
|= (MSR_LINK_MANAGED
<< MSR_LINK_SHIFT
);
1159 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1160 "Set Network type to STA!\n");
1162 case NL80211_IFTYPE_AP
:
1163 bt_msr
|= (MSR_LINK_MASTER
<< MSR_LINK_SHIFT
);
1164 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1165 "Set Network type to AP!\n");
1168 pr_err("Network type %d not supported!\n", type
);
1173 if (type
!= NL80211_IFTYPE_AP
&&
1174 rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1175 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & ~MSR_LINK_MASK
;
1176 rtl_write_byte(rtlpriv
, MSR
, bt_msr
);
1178 temp
= rtl_read_dword(rtlpriv
, TCR
);
1179 rtl_write_dword(rtlpriv
, TCR
, temp
& (~BIT(8)));
1180 rtl_write_dword(rtlpriv
, TCR
, temp
| BIT(8));
1186 /* HW_VAR_MEDIA_STATUS & HW_VAR_CECHK_BSSID */
1187 int rtl92se_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1189 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1191 if (_rtl92se_set_media_status(hw
, type
))
1194 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1195 if (type
!= NL80211_IFTYPE_AP
)
1196 rtl92se_set_check_bssid(hw
, true);
1198 rtl92se_set_check_bssid(hw
, false);
1204 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1205 void rtl92se_set_qos(struct ieee80211_hw
*hw
, int aci
)
1207 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1208 rtl92s_dm_init_edca_turbo(hw
);
1212 rtl_write_dword(rtlpriv
, EDCAPARA_BK
, 0xa44f);
1215 /* rtl_write_dword(rtlpriv, EDCAPARA_BE, u4b_ac_param); */
1218 rtl_write_dword(rtlpriv
, EDCAPARA_VI
, 0x5e4322);
1221 rtl_write_dword(rtlpriv
, EDCAPARA_VO
, 0x2f3222);
1224 WARN_ONCE(true, "rtl8192se: invalid aci: %d !\n", aci
);
1229 void rtl92se_enable_interrupt(struct ieee80211_hw
*hw
)
1231 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1232 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1234 rtl_write_dword(rtlpriv
, INTA_MASK
, rtlpci
->irq_mask
[0]);
1235 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
1236 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, rtlpci
->irq_mask
[1] & 0x3F);
1237 rtlpci
->irq_enabled
= true;
1240 void rtl92se_disable_interrupt(struct ieee80211_hw
*hw
)
1242 struct rtl_priv
*rtlpriv
;
1243 struct rtl_pci
*rtlpci
;
1245 rtlpriv
= rtl_priv(hw
);
1246 /* if firmware not available, no interrupts */
1247 if (!rtlpriv
|| !rtlpriv
->max_fw_size
)
1249 rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1250 rtl_write_dword(rtlpriv
, INTA_MASK
, 0);
1251 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, 0);
1252 rtlpci
->irq_enabled
= false;
1255 static u8
_rtl92s_set_sysclk(struct ieee80211_hw
*hw
, u8 data
)
1257 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1259 bool result
= false;
1262 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, data
);
1264 /* Wait the MAC synchronized. */
1267 /* Check if it is set ready. */
1268 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1269 result
= ((tmp
& BIT(7)) == (data
& BIT(7)));
1271 if ((data
& (BIT(6) | BIT(7))) == false) {
1277 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1282 pr_err("wait for BIT(6) return value %x\n", tmp
);
1298 static void _rtl92s_phy_set_rfhalt(struct ieee80211_hw
*hw
)
1300 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1301 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1302 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1305 if (rtlhal
->driver_going2unload
)
1306 rtl_write_byte(rtlpriv
, 0x560, 0x0);
1308 /* Power save for BB/RF */
1309 u1btmp
= rtl_read_byte(rtlpriv
, LDOV12D_CTRL
);
1311 rtl_write_byte(rtlpriv
, LDOV12D_CTRL
, u1btmp
);
1312 rtl_write_byte(rtlpriv
, SPS1_CTRL
, 0x0);
1313 rtl_write_byte(rtlpriv
, TXPAUSE
, 0xFF);
1314 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1316 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1317 rtl_write_byte(rtlpriv
, PHY_CCA
, 0x0);
1319 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1321 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1323 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1324 rtl_write_word(rtlpriv
, CMDR
, 0x0000);
1326 if (rtlhal
->driver_going2unload
) {
1327 u1btmp
= rtl_read_byte(rtlpriv
, (REG_SYS_FUNC_EN
+ 1));
1328 u1btmp
&= ~(BIT(0));
1329 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, u1btmp
);
1332 u1btmp
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1334 /* Add description. After switch control path. register
1335 * after page1 will be invisible. We can not do any IO
1336 * for register>0x40. After resume&MACIO reset, we need
1337 * to remember previous reg content. */
1338 if (u1btmp
& BIT(7)) {
1339 u1btmp
&= ~(BIT(6) | BIT(7));
1340 if (!_rtl92s_set_sysclk(hw
, u1btmp
)) {
1341 pr_err("Switch ctrl path fail\n");
1346 /* Power save for MAC */
1347 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
&&
1348 !rtlhal
->driver_going2unload
) {
1349 /* enable LED function */
1350 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1351 /* SW/HW radio off or halt adapter!! For example S3/S4 */
1353 /* LED function disable. Power range is about 8mA now. */
1354 /* if write 0xF1 disconnect_pci power
1355 * ifconfig wlan0 down power are both high 35:70 */
1356 /* if write oxF9 disconnect_pci power
1357 * ifconfig wlan0 down power are both low 12:45*/
1358 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1361 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, 0x70);
1362 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, 0x68);
1363 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x00);
1364 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1365 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, 0x0E);
1366 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1370 static void _rtl92se_gen_refreshledstate(struct ieee80211_hw
*hw
)
1372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1373 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1374 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
1376 if (rtlpci
->up_first_time
== 1)
1379 if (rtlpriv
->psc
.rfoff_reason
== RF_CHANGE_BY_IPS
)
1380 rtl92se_sw_led_on(hw
, pled0
);
1382 rtl92se_sw_led_off(hw
, pled0
);
1386 static void _rtl92se_power_domain_init(struct ieee80211_hw
*hw
)
1388 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1392 rtlpriv
->psc
.pwrdomain_protect
= true;
1394 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1395 if (tmpu1b
& BIT(7)) {
1396 tmpu1b
&= ~(BIT(6) | BIT(7));
1397 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1398 rtlpriv
->psc
.pwrdomain_protect
= false;
1403 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x0);
1404 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1406 /* Reset MAC-IO and CPU and Core Digital BIT10/11/15 */
1407 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1409 /* If IPS we need to turn LED on. So we not
1410 * not disable BIT 3/7 of reg3. */
1411 if (rtlpriv
->psc
.rfoff_reason
& (RF_CHANGE_BY_IPS
| RF_CHANGE_BY_HW
))
1416 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
1417 /* wait for BIT 10/11/15 to pull high automatically!! */
1420 rtl_write_byte(rtlpriv
, CMDR
, 0);
1421 rtl_write_byte(rtlpriv
, TCR
, 0);
1423 /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
1424 tmpu1b
= rtl_read_byte(rtlpriv
, 0x562);
1426 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1427 tmpu1b
&= ~(BIT(3));
1428 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1430 /* Enable AFE clock source */
1431 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
);
1432 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, (tmpu1b
| 0x01));
1435 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1);
1436 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, (tmpu1b
& 0xfb));
1438 /* Enable AFE Macro Block's Bandgap */
1439 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1440 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| BIT(0)));
1443 /* Enable AFE Mbias */
1444 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1445 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| 0x02));
1448 /* Enable LDOA15 block */
1449 tmpu1b
= rtl_read_byte(rtlpriv
, LDOA15_CTRL
);
1450 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, (tmpu1b
| BIT(0)));
1452 /* Set Digital Vdd to Retention isolation Path. */
1453 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
1454 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, (tmpu2b
| BIT(11)));
1457 /* For warm reboot NIC disappera bug. */
1458 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1459 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(13)));
1461 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, 0x68);
1463 /* Enable AFE PLL Macro Block */
1464 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
);
1465 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
1466 /* Enable MAC 80MHZ clock */
1467 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
+ 1);
1468 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, (tmpu1b
| BIT(0)));
1471 /* Release isolation AFE PLL & MD */
1472 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xA6);
1474 /* Enable MAC clock */
1475 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1476 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
| BIT(12) | BIT(11)));
1478 /* Enable Core digital and enable IOREG R/W */
1479 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1480 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11)));
1482 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11) | BIT(15)));
1484 /* Switch the control path. */
1485 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1486 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
& (~BIT(2))));
1488 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1489 tmpu1b
= ((tmpu1b
| BIT(7)) & (~BIT(6)));
1490 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1491 rtlpriv
->psc
.pwrdomain_protect
= false;
1495 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1497 /* After MACIO reset,we must refresh LED state. */
1498 _rtl92se_gen_refreshledstate(hw
);
1500 rtlpriv
->psc
.pwrdomain_protect
= false;
1503 void rtl92se_card_disable(struct ieee80211_hw
*hw
)
1505 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1506 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1507 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1508 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1509 enum nl80211_iftype opmode
;
1512 rtlpriv
->intf_ops
->enable_aspm(hw
);
1514 if (rtlpci
->driver_is_goingto_unload
||
1515 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1516 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1518 /* we should chnge GPIO to input mode
1519 * this will drop away current about 25mA*/
1520 rtl8192se_gpiobit3_cfg_inputmode(hw
);
1522 /* this is very important for ips power save */
1523 while (wait
-- >= 10 && rtlpriv
->psc
.pwrdomain_protect
) {
1524 if (rtlpriv
->psc
.pwrdomain_protect
)
1530 mac
->link_state
= MAC80211_NOLINK
;
1531 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1532 _rtl92se_set_media_status(hw
, opmode
);
1534 _rtl92s_phy_set_rfhalt(hw
);
1538 void rtl92se_interrupt_recognized(struct ieee80211_hw
*hw
,
1539 struct rtl_int
*intvec
)
1541 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1542 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1544 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1545 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1547 intvec
->intb
= rtl_read_dword(rtlpriv
, ISR
+ 4) & rtlpci
->irq_mask
[1];
1548 rtl_write_dword(rtlpriv
, ISR
+ 4, intvec
->intb
);
1551 void rtl92se_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1553 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1554 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1555 u16 bcntime_cfg
= 0;
1556 u16 bcn_cw
= 6, bcn_ifs
= 0xf;
1557 u16 atim_window
= 2;
1559 /* ATIM Window (in unit of TU). */
1560 rtl_write_word(rtlpriv
, ATIMWND
, atim_window
);
1562 /* Beacon interval (in unit of TU). */
1563 rtl_write_word(rtlpriv
, BCN_INTERVAL
, mac
->beacon_interval
);
1565 /* DrvErlyInt (in unit of TU). (Time to send
1566 * interrupt to notify driver to change
1567 * beacon content) */
1568 rtl_write_word(rtlpriv
, BCN_DRV_EARLY_INT
, 10 << 4);
1570 /* BcnDMATIM(in unit of us). Indicates the
1571 * time before TBTT to perform beacon queue DMA */
1572 rtl_write_word(rtlpriv
, BCN_DMATIME
, 256);
1574 /* Force beacon frame transmission even
1575 * after receiving beacon frame from
1576 * other ad hoc STA */
1577 rtl_write_byte(rtlpriv
, BCN_ERR_THRESH
, 100);
1579 /* Beacon Time Configuration */
1580 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1581 bcntime_cfg
|= (bcn_cw
<< BCN_TCFG_CW_SHIFT
);
1583 /* TODO: bcn_ifs may required to be changed on ASIC */
1584 bcntime_cfg
|= bcn_ifs
<< BCN_TCFG_IFS
;
1586 /*for beacon changed */
1587 rtl92s_phy_set_beacon_hwreg(hw
, mac
->beacon_interval
);
1590 void rtl92se_set_beacon_interval(struct ieee80211_hw
*hw
)
1592 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1593 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1594 u16 bcn_interval
= mac
->beacon_interval
;
1596 /* Beacon interval (in unit of TU). */
1597 rtl_write_word(rtlpriv
, BCN_INTERVAL
, bcn_interval
);
1598 /* 2008.10.24 added by tynli for beacon changed. */
1599 rtl92s_phy_set_beacon_hwreg(hw
, bcn_interval
);
1602 void rtl92se_update_interrupt_mask(struct ieee80211_hw
*hw
,
1603 u32 add_msr
, u32 rm_msr
)
1605 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1606 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1608 rtl_dbg(rtlpriv
, COMP_INTR
, DBG_LOUD
, "add_msr:%x, rm_msr:%x\n",
1612 rtlpci
->irq_mask
[0] |= add_msr
;
1615 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1617 rtl92se_disable_interrupt(hw
);
1618 rtl92se_enable_interrupt(hw
);
1621 static void _rtl8192se_get_ic_inferiority(struct ieee80211_hw
*hw
)
1623 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1624 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1627 rtlhal
->ic_class
= IC_INFERIORITY_A
;
1629 /* Only retrieving while using EFUSE. */
1630 if ((rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) &&
1631 !rtlefuse
->autoload_failflag
) {
1632 efuse_id
= efuse_read_1byte(hw
, EFUSE_IC_ID_OFFSET
);
1634 if (efuse_id
== 0xfe)
1635 rtlhal
->ic_class
= IC_INFERIORITY_B
;
1639 static void _rtl92se_read_adapter_info(struct ieee80211_hw
*hw
)
1641 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1642 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1643 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1644 struct device
*dev
= &rtl_pcipriv(hw
)->dev
.pdev
->dev
;
1648 u8 hwinfo
[HWSET_MAX_SIZE_92S
];
1651 switch (rtlefuse
->epromtype
) {
1652 case EEPROM_BOOT_EFUSE
:
1653 rtl_efuse_shadow_map_update(hw
);
1657 pr_err("RTL819X Not boot from eeprom, check it !!\n");
1661 dev_warn(dev
, "no efuse data\n");
1665 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
1666 HWSET_MAX_SIZE_92S
);
1668 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1669 hwinfo
, HWSET_MAX_SIZE_92S
);
1671 eeprom_id
= *((u16
*)&hwinfo
[0]);
1672 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
1673 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1674 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1675 rtlefuse
->autoload_failflag
= true;
1677 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1678 rtlefuse
->autoload_failflag
= false;
1681 if (rtlefuse
->autoload_failflag
)
1684 _rtl8192se_get_ic_inferiority(hw
);
1686 /* Read IC Version && Channel Plan */
1687 /* VID, DID SE 0xA-D */
1688 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
1689 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
1690 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[EEPROM_SVID
];
1691 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[EEPROM_SMID
];
1692 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
1694 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1695 "EEPROMId = 0x%4x\n", eeprom_id
);
1696 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1697 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1698 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1699 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1700 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1701 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1702 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1703 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1705 for (i
= 0; i
< 6; i
+= 2) {
1706 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
1707 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
1710 for (i
= 0; i
< 6; i
++)
1711 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1713 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1715 /* Get Tx Power Level by Channel */
1716 /* Read Tx power of Channel 1 ~ 14 from EEPROM. */
1717 /* 92S suupport RF A & B */
1718 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1719 for (i
= 0; i
< 3; i
++) {
1720 /* Read CCK RF A & B Tx power */
1721 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
1722 hwinfo
[EEPROM_TXPOWERBASE
+ rf_path
* 3 + i
];
1724 /* Read OFDM RF A & B Tx power for 1T */
1725 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
1726 hwinfo
[EEPROM_TXPOWERBASE
+ 6 + rf_path
* 3 + i
];
1728 /* Read OFDM RF A & B Tx power for 2T */
1729 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[rf_path
][i
]
1730 = hwinfo
[EEPROM_TXPOWERBASE
+ 12 +
1735 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1736 for (i
= 0; i
< 3; i
++)
1737 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1738 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
1740 rtlefuse
->eeprom_chnlarea_txpwr_cck
1742 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1743 for (i
= 0; i
< 3; i
++)
1744 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1745 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1747 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1749 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1750 for (i
= 0; i
< 3; i
++)
1751 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1752 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1754 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1757 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1759 /* Assign dedicated channel tx power */
1760 for (i
= 0; i
< 14; i
++) {
1761 /* channel 1~3 use the same Tx Power Level. */
1771 /* Record A & B CCK /OFDM - 1T/2T Channel area
1773 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1774 rtlefuse
->eeprom_chnlarea_txpwr_cck
1776 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1777 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1779 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
1780 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1784 for (i
= 0; i
< 14; i
++) {
1785 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1786 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
1788 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1789 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
1790 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
1794 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1795 for (i
= 0; i
< 3; i
++) {
1796 /* Read Power diff limit. */
1797 rtlefuse
->eeprom_pwrgroup
[rf_path
][i
] =
1798 hwinfo
[EEPROM_TXPWRGROUP
+ rf_path
* 3 + i
];
1802 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1803 /* Fill Pwr group */
1804 for (i
= 0; i
< 14; i
++) {
1815 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
1816 (rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1818 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
1819 ((rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1822 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1823 "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
1825 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
1826 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1827 "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
1829 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
1833 for (i
= 0; i
< 14; i
++) {
1834 /* Read tx power difference between HT OFDM 20/40 MHZ */
1845 tempval
= hwinfo
[EEPROM_TX_PWR_HT20_DIFF
+ index
] & 0xff;
1846 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
1847 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
1848 ((tempval
>> 4) & 0xF);
1850 /* Read OFDM<->HT tx power diff */
1861 tempval
= hwinfo
[EEPROM_TX_PWR_OFDM_DIFF
+ index
] & 0xff;
1862 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] =
1864 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
1865 ((tempval
>> 4) & 0xF);
1867 tempval
= hwinfo
[TX_PWR_SAFETY_CHK
];
1868 rtlefuse
->txpwr_safetyflag
= (tempval
& 0x01);
1871 rtlefuse
->eeprom_regulatory
= 0;
1872 if (rtlefuse
->eeprom_version
>= 2) {
1874 if (rtlefuse
->eeprom_version
>= 4)
1875 rtlefuse
->eeprom_regulatory
=
1876 (hwinfo
[EEPROM_REGULATORY
] & 0x7);
1878 rtlefuse
->eeprom_regulatory
=
1879 (hwinfo
[EEPROM_REGULATORY
] & 0x1);
1881 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1882 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1884 for (i
= 0; i
< 14; i
++)
1885 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1886 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
1887 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
1888 for (i
= 0; i
< 14; i
++)
1889 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1890 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
1891 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
1892 for (i
= 0; i
< 14; i
++)
1893 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1894 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
1895 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
1896 for (i
= 0; i
< 14; i
++)
1897 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1898 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
1899 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
1901 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1902 "TxPwrSafetyFlag = %d\n", rtlefuse
->txpwr_safetyflag
);
1904 /* Read RF-indication and Tx Power gain
1905 * index diff of legacy to HT OFDM rate. */
1906 tempval
= hwinfo
[EEPROM_RFIND_POWERDIFF
] & 0xff;
1907 rtlefuse
->eeprom_txpowerdiff
= tempval
;
1908 rtlefuse
->legacy_ht_txpowerdiff
=
1909 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][0];
1911 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1912 "TxPowerDiff = %#x\n", rtlefuse
->eeprom_txpowerdiff
);
1914 /* Get TSSI value for each path. */
1915 usvalue
= *(u16
*)&hwinfo
[EEPROM_TSSI_A
];
1916 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = (u8
)((usvalue
& 0xff00) >> 8);
1917 usvalue
= hwinfo
[EEPROM_TSSI_B
];
1918 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = (u8
)(usvalue
& 0xff);
1920 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1921 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
1922 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
1924 /* Read antenna tx power offset of B/C/D to A from EEPROM */
1925 /* and read ThermalMeter from EEPROM */
1926 tempval
= hwinfo
[EEPROM_THERMALMETER
];
1927 rtlefuse
->eeprom_thermalmeter
= tempval
;
1928 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1929 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1931 /* ThermalMeter, BIT(0)~3 for RFIC1, BIT(4)~7 for RFIC2 */
1932 rtlefuse
->thermalmeter
[0] = (rtlefuse
->eeprom_thermalmeter
& 0x1f);
1933 rtlefuse
->tssi_13dbm
= rtlefuse
->eeprom_thermalmeter
* 100;
1935 /* Read CrystalCap from EEPROM */
1936 tempval
= hwinfo
[EEPROM_CRYSTALCAP
] >> 4;
1937 rtlefuse
->eeprom_crystalcap
= tempval
;
1938 /* CrystalCap, BIT(12)~15 */
1939 rtlefuse
->crystalcap
= rtlefuse
->eeprom_crystalcap
;
1941 /* Read IC Version && Channel Plan */
1942 /* Version ID, Channel plan */
1943 rtlefuse
->eeprom_channelplan
= hwinfo
[EEPROM_CHANNELPLAN
];
1944 rtlefuse
->txpwr_fromeprom
= true;
1945 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1946 "EEPROM ChannelPlan = 0x%4x\n", rtlefuse
->eeprom_channelplan
);
1948 /* Read Customer ID or Board Type!!! */
1949 tempval
= hwinfo
[EEPROM_BOARDTYPE
];
1950 /* Change RF type definition */
1952 rtlphy
->rf_type
= RF_2T2R
;
1953 else if (tempval
== 1)
1954 rtlphy
->rf_type
= RF_1T2R
;
1955 else if (tempval
== 2)
1956 rtlphy
->rf_type
= RF_1T2R
;
1957 else if (tempval
== 3)
1958 rtlphy
->rf_type
= RF_1T1R
;
1960 /* 1T2R but 1SS (1x1 receive combining) */
1961 rtlefuse
->b1x1_recvcombine
= false;
1962 if (rtlphy
->rf_type
== RF_1T2R
) {
1963 tempval
= rtl_read_byte(rtlpriv
, 0x07);
1964 if (!(tempval
& BIT(0))) {
1965 rtlefuse
->b1x1_recvcombine
= true;
1966 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1967 "RF_TYPE=1T2R but only 1SS\n");
1970 rtlefuse
->b1ss_support
= rtlefuse
->b1x1_recvcombine
;
1971 rtlefuse
->eeprom_oemid
= *&hwinfo
[EEPROM_CUSTOMID
];
1973 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "EEPROM Customer ID: 0x%2x\n",
1974 rtlefuse
->eeprom_oemid
);
1976 /* set channel paln to world wide 13 */
1977 rtlefuse
->channel_plan
= COUNTRY_CODE_WORLD_WIDE_13
;
1980 void rtl92se_read_eeprom_info(struct ieee80211_hw
*hw
)
1982 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1983 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1986 tmp_u1b
= rtl_read_byte(rtlpriv
, EPROM_CMD
);
1988 if (tmp_u1b
& BIT(4)) {
1989 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1990 rtlefuse
->epromtype
= EEPROM_93C46
;
1992 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1993 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1996 if (tmp_u1b
& BIT(5)) {
1997 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1998 rtlefuse
->autoload_failflag
= false;
1999 _rtl92se_read_adapter_info(hw
);
2001 pr_err("Autoload ERR!!\n");
2002 rtlefuse
->autoload_failflag
= true;
2006 static void rtl92se_update_hal_rate_table(struct ieee80211_hw
*hw
,
2007 struct ieee80211_sta
*sta
)
2009 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2010 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2011 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2012 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2015 u8 nmode
= mac
->ht_enable
;
2016 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2017 u16 shortgi_rate
= 0;
2018 u32 tmp_ratr_value
= 0;
2019 u8 curtxbw_40mhz
= mac
->bw_40
;
2020 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2022 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2024 enum wireless_mode wirelessmode
= mac
->mode
;
2026 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2027 ratr_value
= sta
->supp_rates
[1] << 4;
2029 ratr_value
= sta
->supp_rates
[0];
2030 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2032 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2033 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2034 switch (wirelessmode
) {
2035 case WIRELESS_MODE_B
:
2036 ratr_value
&= 0x0000000D;
2038 case WIRELESS_MODE_G
:
2039 ratr_value
&= 0x00000FF5;
2041 case WIRELESS_MODE_N_24G
:
2042 case WIRELESS_MODE_N_5G
:
2044 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2045 ratr_value
&= 0x0007F005;
2049 if (get_rf_type(rtlphy
) == RF_1T2R
||
2050 get_rf_type(rtlphy
) == RF_1T1R
) {
2052 ratr_mask
= 0x000ff015;
2054 ratr_mask
= 0x000ff005;
2057 ratr_mask
= 0x0f0ff015;
2059 ratr_mask
= 0x0f0ff005;
2062 ratr_value
&= ratr_mask
;
2066 if (rtlphy
->rf_type
== RF_1T2R
)
2067 ratr_value
&= 0x000ff0ff;
2069 ratr_value
&= 0x0f0ff0ff;
2074 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2075 ratr_value
&= 0x0FFFFFFF;
2076 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2077 ratr_value
&= 0x0FFFFFF0;
2079 if (nmode
&& ((curtxbw_40mhz
&&
2080 curshortgi_40mhz
) || (!curtxbw_40mhz
&&
2081 curshortgi_20mhz
))) {
2083 ratr_value
|= 0x10000000;
2084 tmp_ratr_value
= (ratr_value
>> 12);
2086 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2087 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2091 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2092 (shortgi_rate
<< 4) | (shortgi_rate
);
2094 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2097 rtl_write_dword(rtlpriv
, ARFR0
+ ratr_index
* 4, ratr_value
);
2098 if (ratr_value
& 0xfffff000)
2099 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_N
);
2101 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_BG
);
2103 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
, "%x\n",
2104 rtl_read_dword(rtlpriv
, ARFR0
));
2107 static void rtl92se_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2108 struct ieee80211_sta
*sta
,
2109 u8 rssi_level
, bool update_bw
)
2111 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2112 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2113 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2114 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2115 struct rtl_sta_info
*sta_entry
= NULL
;
2118 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
2119 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2121 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2123 enum wireless_mode wirelessmode
= 0;
2124 bool shortgi
= false;
2126 u8 shortgi_rate
= 0;
2129 bool bmulticast
= false;
2131 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2133 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
2134 wirelessmode
= sta_entry
->wireless_mode
;
2135 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
2136 curtxbw_40mhz
= mac
->bw_40
;
2137 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2138 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2139 macid
= sta
->aid
+ 1;
2141 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2142 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2144 ratr_bitmap
= sta
->supp_rates
[0];
2145 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2146 ratr_bitmap
= 0xfff;
2147 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2148 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2149 switch (wirelessmode
) {
2150 case WIRELESS_MODE_B
:
2151 band
|= WIRELESS_11B
;
2152 ratr_index
= RATR_INX_WIRELESS_B
;
2153 if (ratr_bitmap
& 0x0000000c)
2154 ratr_bitmap
&= 0x0000000d;
2156 ratr_bitmap
&= 0x0000000f;
2158 case WIRELESS_MODE_G
:
2159 band
|= (WIRELESS_11G
| WIRELESS_11B
);
2160 ratr_index
= RATR_INX_WIRELESS_GB
;
2162 if (rssi_level
== 1)
2163 ratr_bitmap
&= 0x00000f00;
2164 else if (rssi_level
== 2)
2165 ratr_bitmap
&= 0x00000ff0;
2167 ratr_bitmap
&= 0x00000ff5;
2169 case WIRELESS_MODE_A
:
2170 band
|= WIRELESS_11A
;
2171 ratr_index
= RATR_INX_WIRELESS_A
;
2172 ratr_bitmap
&= 0x00000ff0;
2174 case WIRELESS_MODE_N_24G
:
2175 case WIRELESS_MODE_N_5G
:
2176 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2177 ratr_index
= RATR_INX_WIRELESS_NGB
;
2179 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2180 if (rssi_level
== 1)
2181 ratr_bitmap
&= 0x00070000;
2182 else if (rssi_level
== 2)
2183 ratr_bitmap
&= 0x0007f000;
2185 ratr_bitmap
&= 0x0007f005;
2187 if (rtlphy
->rf_type
== RF_1T2R
||
2188 rtlphy
->rf_type
== RF_1T1R
) {
2189 if (rssi_level
== 1) {
2190 ratr_bitmap
&= 0x000f0000;
2191 } else if (rssi_level
== 3) {
2192 ratr_bitmap
&= 0x000fc000;
2193 } else if (rssi_level
== 5) {
2194 ratr_bitmap
&= 0x000ff000;
2197 ratr_bitmap
&= 0x000ff015;
2199 ratr_bitmap
&= 0x000ff005;
2202 if (rssi_level
== 1) {
2203 ratr_bitmap
&= 0x0f8f0000;
2204 } else if (rssi_level
== 3) {
2205 ratr_bitmap
&= 0x0f8fc000;
2206 } else if (rssi_level
== 5) {
2207 ratr_bitmap
&= 0x0f8ff000;
2210 ratr_bitmap
&= 0x0f8ff015;
2212 ratr_bitmap
&= 0x0f8ff005;
2217 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2218 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2221 else if (macid
== 1)
2226 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2227 ratr_index
= RATR_INX_WIRELESS_NGB
;
2229 if (rtlphy
->rf_type
== RF_1T2R
)
2230 ratr_bitmap
&= 0x000ff0ff;
2232 ratr_bitmap
&= 0x0f8ff0ff;
2235 sta_entry
->ratr_index
= ratr_index
;
2237 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2238 ratr_bitmap
&= 0x0FFFFFFF;
2239 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2240 ratr_bitmap
&= 0x0FFFFFF0;
2243 ratr_bitmap
|= 0x10000000;
2244 /* Get MAX MCS available. */
2245 ratr_value
= (ratr_bitmap
>> 12);
2246 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2247 if ((1 << shortgi_rate
) & ratr_value
)
2251 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2252 (shortgi_rate
<< 4) | (shortgi_rate
);
2253 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2256 mask
|= (bmulticast
? 1 : 0) << 9 | (macid
& 0x1f) << 4 | (band
& 0xf);
2258 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_TRACE
, "mask = %x, bitmap = %x\n",
2260 rtl_write_dword(rtlpriv
, 0x2c4, ratr_bitmap
);
2261 rtl_write_dword(rtlpriv
, WFM5
, (FW_RA_UPDATE_MASK
| (mask
<< 8)));
2264 sta_entry
->ratr_index
= ratr_index
;
2267 void rtl92se_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2268 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2270 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2272 if (rtlpriv
->dm
.useramask
)
2273 rtl92se_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2275 rtl92se_update_hal_rate_table(hw
, sta
);
2278 void rtl92se_update_channel_access_setting(struct ieee80211_hw
*hw
)
2280 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2281 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2284 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2286 sifs_timer
= 0x0e0e;
2287 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2291 /* this ifunction is for RFKILL, it's different with windows,
2292 * because UI will disable wireless when GPIO Radio Off.
2293 * And here we not check or Disable/Enable ASPM like windows*/
2294 bool rtl92se_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2296 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2297 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2298 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2299 enum rf_pwrstate rfpwr_toset
/*, cur_rfstate */;
2300 unsigned long flag
= 0;
2301 bool actuallyset
= false;
2302 bool turnonbypowerdomain
= false;
2304 /* just 8191se can check gpio before firstup, 92c/92d have fixed it */
2305 if ((rtlpci
->up_first_time
== 1) || (rtlpci
->being_init_adapter
))
2308 if (ppsc
->swrf_processing
)
2311 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2312 if (ppsc
->rfchange_inprogress
) {
2313 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2316 ppsc
->rfchange_inprogress
= true;
2317 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2320 /* cur_rfstate = ppsc->rfpwr_state;*/
2322 /* because after _rtl92s_phy_set_rfhalt, all power
2323 * closed, so we must open some power for GPIO check,
2324 * or we will always check GPIO RFOFF here,
2325 * And we should close power after GPIO check */
2326 if (RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2327 _rtl92se_power_domain_init(hw
);
2328 turnonbypowerdomain
= true;
2331 rfpwr_toset
= _rtl92se_rf_onoff_detect(hw
);
2333 if ((ppsc
->hwradiooff
) && (rfpwr_toset
== ERFON
)) {
2334 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2335 "RFKILL-HW Radio ON, RF ON\n");
2337 rfpwr_toset
= ERFON
;
2338 ppsc
->hwradiooff
= false;
2340 } else if ((!ppsc
->hwradiooff
) && (rfpwr_toset
== ERFOFF
)) {
2341 rtl_dbg(rtlpriv
, COMP_RF
,
2342 DBG_DMESG
, "RFKILL-HW Radio OFF, RF OFF\n");
2344 rfpwr_toset
= ERFOFF
;
2345 ppsc
->hwradiooff
= true;
2350 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2351 ppsc
->rfchange_inprogress
= false;
2352 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2354 /* this not include ifconfig wlan0 down case */
2355 /* } else if (rfpwr_toset == ERFOFF || cur_rfstate == ERFOFF) { */
2357 /* because power_domain_init may be happen when
2358 * _rtl92s_phy_set_rfhalt, this will open some powers
2359 * and cause current increasing about 40 mA for ips,
2360 * rfoff and ifconfig down, so we set
2361 * _rtl92s_phy_set_rfhalt again here */
2362 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
&&
2363 turnonbypowerdomain
) {
2364 _rtl92s_phy_set_rfhalt(hw
);
2365 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2368 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2369 ppsc
->rfchange_inprogress
= false;
2370 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2374 return !ppsc
->hwradiooff
;
2378 /* Is_wepkey just used for WEP used as group & pairwise key
2379 * if pairwise is AES ang group is WEP Is_wepkey == false.*/
2380 void rtl92se_set_key(struct ieee80211_hw
*hw
, u32 key_index
, u8
*p_macaddr
,
2381 bool is_group
, u8 enc_algo
, bool is_wepkey
, bool clear_all
)
2383 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2384 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2385 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2386 u8
*macaddr
= p_macaddr
;
2389 bool is_pairwise
= false;
2391 static u8 cam_const_addr
[4][6] = {
2392 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2393 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2394 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2395 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2397 static u8 cam_const_broad
[] = {
2398 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2404 u8 clear_number
= 5;
2406 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2408 for (idx
= 0; idx
< clear_number
; idx
++) {
2409 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2410 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2413 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2415 rtlpriv
->sec
.key_len
[idx
] = 0;
2421 case WEP40_ENCRYPTION
:
2422 enc_algo
= CAM_WEP40
;
2424 case WEP104_ENCRYPTION
:
2425 enc_algo
= CAM_WEP104
;
2427 case TKIP_ENCRYPTION
:
2428 enc_algo
= CAM_TKIP
;
2430 case AESCCMP_ENCRYPTION
:
2434 pr_err("switch case %#x not processed\n",
2436 enc_algo
= CAM_TKIP
;
2440 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2441 macaddr
= cam_const_addr
[key_index
];
2442 entry_id
= key_index
;
2445 macaddr
= cam_const_broad
;
2446 entry_id
= key_index
;
2448 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2449 entry_id
= rtl_cam_get_free_entry(hw
,
2451 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2452 pr_err("Can not find free hw security cam entry\n");
2456 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2459 key_index
= PAIRWISE_KEYIDX
;
2464 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2465 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2466 "delete one entry, entry_id is %d\n",
2468 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2469 rtl_cam_del_entry(hw
, p_macaddr
);
2470 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2472 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2475 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2476 "set Pairwise key\n");
2478 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2480 CAM_CONFIG_NO_USEDK
,
2481 rtlpriv
->sec
.key_buf
[key_index
]);
2483 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2486 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2487 rtl_cam_add_one_entry(hw
,
2490 CAM_PAIRWISE_KEY_POSITION
,
2491 enc_algo
, CAM_CONFIG_NO_USEDK
,
2492 rtlpriv
->sec
.key_buf
[entry_id
]);
2495 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2497 CAM_CONFIG_NO_USEDK
,
2498 rtlpriv
->sec
.key_buf
[entry_id
]);
2505 void rtl92se_suspend(struct ieee80211_hw
*hw
)
2507 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2509 rtlpci
->up_first_time
= true;
2512 void rtl92se_resume(struct ieee80211_hw
*hw
)
2514 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2517 pci_read_config_dword(rtlpci
->pdev
, 0x40, &val
);
2518 if ((val
& 0x0000ff00) != 0)
2519 pci_write_config_dword(rtlpci
->pdev
, 0x40,