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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(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 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "EFUSE CONFIG OK\n");
876 RT_TRACE(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 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
964 "Failed to download FW. Init HW without FW now... "
965 "Please copy FW into /lib/firmware/rtlwifi\n");
970 /* After FW download, we have to reset MAC register */
971 _rtl92se_macconfig_after_fwdownload(hw
);
973 /*Retrieve default FW Cmd IO map. */
974 rtlhal
->fwcmd_iomap
= rtl_read_word(rtlpriv
, LBUS_MON_ADDR
);
975 rtlhal
->fwcmd_ioparam
= rtl_read_dword(rtlpriv
, LBUS_ADDR_MASK
);
977 /* 3. Initialize MAC/PHY Config by MACPHY_reg.txt */
978 if (!rtl92s_phy_mac_config(hw
)) {
979 pr_err("MAC Config failed\n");
984 /* because last function modify RCR, so we update
985 * rcr var here, or TP will unstable for receive_config
986 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
987 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
989 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, RCR
);
990 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
991 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
993 /* Make sure BB/RF write OK. We should prevent enter IPS. radio off. */
994 /* We must set flag avoid BB/RF config period later!! */
995 rtl_write_dword(rtlpriv
, CMDR
, 0x37FC);
997 /* 4. Initialize BB After MAC Config PHY_reg.txt, AGC_Tab.txt */
998 if (!rtl92s_phy_bb_config(hw
)) {
999 pr_err("BB Config failed\n");
1004 /* 5. Initiailze RF RAIO_A.txt RF RAIO_B.txt */
1005 /* Before initalizing RF. We can not use FW to do RF-R/W. */
1007 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1009 /* Before RF-R/W we must execute the IO from Scott's suggestion. */
1010 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, 0xDB);
1011 if (rtlhal
->version
== VERSION_8192S_ACUT
)
1012 rtl_write_byte(rtlpriv
, SPS1_CTRL
+ 3, 0x07);
1014 rtl_write_byte(rtlpriv
, RF_CTRL
, 0x07);
1016 if (!rtl92s_phy_rf_config(hw
)) {
1017 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "RF Config failed\n");
1022 /* After read predefined TXT, we must set BB/MAC/RF
1023 * register as our requirement */
1025 rtlphy
->rfreg_chnlval
[0] = rtl92s_phy_query_rf_reg(hw
,
1029 rtlphy
->rfreg_chnlval
[1] = rtl92s_phy_query_rf_reg(hw
,
1034 /*---- Set CCK and OFDM Block "ON"----*/
1035 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1036 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1038 /*3 Set Hardware(Do nothing now) */
1039 _rtl92se_hw_configure(hw
);
1041 /* Read EEPROM TX power index and PHY_REG_PG.txt to capture correct */
1042 /* TX power index for different rate set. */
1043 /* Get original hw reg values */
1044 rtl92s_phy_get_hw_reg_originalvalue(hw
);
1045 /* Write correct tx power index */
1046 rtl92s_phy_set_txpower(hw
, rtlphy
->current_channel
);
1048 /* We must set MAC address after firmware download. */
1049 for (i
= 0; i
< 6; i
++)
1050 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1052 /* EEPROM R/W workaround */
1053 tmp_u1b
= rtl_read_byte(rtlpriv
, MAC_PINMUX_CFG
);
1054 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, tmp_u1b
& (~BIT(3)));
1056 rtl_write_byte(rtlpriv
, 0x4d, 0x0);
1058 if (hal_get_firmwareversion(rtlpriv
) >= 0x49) {
1059 tmp_byte
= rtl_read_byte(rtlpriv
, FW_RSVD_PG_CRTL
) & (~BIT(4));
1060 tmp_byte
= tmp_byte
| BIT(5);
1061 rtl_write_byte(rtlpriv
, FW_RSVD_PG_CRTL
, tmp_byte
);
1062 rtl_write_dword(rtlpriv
, TXDESC_MSK
, 0xFFFFCFFF);
1065 /* We enable high power and RA related mechanism after NIC
1067 if (hal_get_firmwareversion(rtlpriv
) >= 0x35) {
1068 /* Fw v.53 and later. */
1069 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_INIT
);
1070 } else if (hal_get_firmwareversion(rtlpriv
) == 0x34) {
1072 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_INIT
);
1073 rtl92s_phy_chk_fwcmd_iodone(hw
);
1075 /* Compatible earlier FW version. */
1076 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_RESET
);
1077 rtl92s_phy_chk_fwcmd_iodone(hw
);
1078 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_ACTIVE
);
1079 rtl92s_phy_chk_fwcmd_iodone(hw
);
1080 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_REFRESH
);
1081 rtl92s_phy_chk_fwcmd_iodone(hw
);
1084 /* Add to prevent ASPM bug. */
1085 /* Always enable hst and NIC clock request. */
1086 rtl92s_phy_switch_ephy_parameter(hw
);
1089 * 1. Clear all H/W keys.
1090 * 2. Enable H/W encryption/decryption. */
1091 rtl_cam_reset_all_entry(hw
);
1092 secr_value
|= SCR_TXENCENABLE
;
1093 secr_value
|= SCR_RXENCENABLE
;
1094 secr_value
|= SCR_NOSKMC
;
1095 rtl_write_byte(rtlpriv
, REG_SECR
, secr_value
);
1097 for (i
= 0; i
< 4; i
++)
1098 rtl_write_dword(rtlpriv
, wdcapra_add
[i
], 0x5e4322);
1100 if (rtlphy
->rf_type
== RF_1T2R
) {
1101 bool mrc2set
= true;
1102 /* Turn on B-Path */
1103 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MRC
, (u8
*)&mrc2set
);
1106 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_ON
);
1109 local_irq_restore(flags
);
1110 rtlpci
->being_init_adapter
= false;
1114 void rtl92se_set_mac_addr(struct rtl_io
*io
, const u8
*addr
)
1116 /* This is a stub. */
1119 void rtl92se_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1121 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1124 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1127 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1130 reg_rcr
|= (RCR_CBSSID
);
1131 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1132 } else if (!check_bssid
) {
1133 reg_rcr
&= (~RCR_CBSSID
);
1134 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1139 static int _rtl92se_set_media_status(struct ieee80211_hw
*hw
,
1140 enum nl80211_iftype type
)
1142 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1143 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1145 bt_msr
&= ~MSR_LINK_MASK
;
1148 case NL80211_IFTYPE_UNSPECIFIED
:
1149 bt_msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
1150 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1151 "Set Network type to NO LINK!\n");
1153 case NL80211_IFTYPE_ADHOC
:
1154 bt_msr
|= (MSR_LINK_ADHOC
<< MSR_LINK_SHIFT
);
1155 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1156 "Set Network type to Ad Hoc!\n");
1158 case NL80211_IFTYPE_STATION
:
1159 bt_msr
|= (MSR_LINK_MANAGED
<< MSR_LINK_SHIFT
);
1160 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1161 "Set Network type to STA!\n");
1163 case NL80211_IFTYPE_AP
:
1164 bt_msr
|= (MSR_LINK_MASTER
<< MSR_LINK_SHIFT
);
1165 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1166 "Set Network type to AP!\n");
1169 pr_err("Network type %d not supported!\n", type
);
1174 if (type
!= NL80211_IFTYPE_AP
&&
1175 rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1176 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & ~MSR_LINK_MASK
;
1177 rtl_write_byte(rtlpriv
, MSR
, bt_msr
);
1179 temp
= rtl_read_dword(rtlpriv
, TCR
);
1180 rtl_write_dword(rtlpriv
, TCR
, temp
& (~BIT(8)));
1181 rtl_write_dword(rtlpriv
, TCR
, temp
| BIT(8));
1187 /* HW_VAR_MEDIA_STATUS & HW_VAR_CECHK_BSSID */
1188 int rtl92se_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1190 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1192 if (_rtl92se_set_media_status(hw
, type
))
1195 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1196 if (type
!= NL80211_IFTYPE_AP
)
1197 rtl92se_set_check_bssid(hw
, true);
1199 rtl92se_set_check_bssid(hw
, false);
1205 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1206 void rtl92se_set_qos(struct ieee80211_hw
*hw
, int aci
)
1208 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1209 rtl92s_dm_init_edca_turbo(hw
);
1213 rtl_write_dword(rtlpriv
, EDCAPARA_BK
, 0xa44f);
1216 /* rtl_write_dword(rtlpriv, EDCAPARA_BE, u4b_ac_param); */
1219 rtl_write_dword(rtlpriv
, EDCAPARA_VI
, 0x5e4322);
1222 rtl_write_dword(rtlpriv
, EDCAPARA_VO
, 0x2f3222);
1225 WARN_ONCE(true, "rtl8192se: invalid aci: %d !\n", aci
);
1230 void rtl92se_enable_interrupt(struct ieee80211_hw
*hw
)
1232 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1233 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1235 rtl_write_dword(rtlpriv
, INTA_MASK
, rtlpci
->irq_mask
[0]);
1236 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
1237 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, rtlpci
->irq_mask
[1] & 0x3F);
1238 rtlpci
->irq_enabled
= true;
1241 void rtl92se_disable_interrupt(struct ieee80211_hw
*hw
)
1243 struct rtl_priv
*rtlpriv
;
1244 struct rtl_pci
*rtlpci
;
1246 rtlpriv
= rtl_priv(hw
);
1247 /* if firmware not available, no interrupts */
1248 if (!rtlpriv
|| !rtlpriv
->max_fw_size
)
1250 rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1251 rtl_write_dword(rtlpriv
, INTA_MASK
, 0);
1252 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, 0);
1253 rtlpci
->irq_enabled
= false;
1256 static u8
_rtl92s_set_sysclk(struct ieee80211_hw
*hw
, u8 data
)
1258 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1260 bool result
= false;
1263 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, data
);
1265 /* Wait the MAC synchronized. */
1268 /* Check if it is set ready. */
1269 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1270 result
= ((tmp
& BIT(7)) == (data
& BIT(7)));
1272 if ((data
& (BIT(6) | BIT(7))) == false) {
1278 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1283 pr_err("wait for BIT(6) return value %x\n", tmp
);
1299 static void _rtl92s_phy_set_rfhalt(struct ieee80211_hw
*hw
)
1301 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1302 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1303 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1306 if (rtlhal
->driver_going2unload
)
1307 rtl_write_byte(rtlpriv
, 0x560, 0x0);
1309 /* Power save for BB/RF */
1310 u1btmp
= rtl_read_byte(rtlpriv
, LDOV12D_CTRL
);
1312 rtl_write_byte(rtlpriv
, LDOV12D_CTRL
, u1btmp
);
1313 rtl_write_byte(rtlpriv
, SPS1_CTRL
, 0x0);
1314 rtl_write_byte(rtlpriv
, TXPAUSE
, 0xFF);
1315 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1317 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1318 rtl_write_byte(rtlpriv
, PHY_CCA
, 0x0);
1320 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1322 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1324 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1325 rtl_write_word(rtlpriv
, CMDR
, 0x0000);
1327 if (rtlhal
->driver_going2unload
) {
1328 u1btmp
= rtl_read_byte(rtlpriv
, (REG_SYS_FUNC_EN
+ 1));
1329 u1btmp
&= ~(BIT(0));
1330 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, u1btmp
);
1333 u1btmp
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1335 /* Add description. After switch control path. register
1336 * after page1 will be invisible. We can not do any IO
1337 * for register>0x40. After resume&MACIO reset, we need
1338 * to remember previous reg content. */
1339 if (u1btmp
& BIT(7)) {
1340 u1btmp
&= ~(BIT(6) | BIT(7));
1341 if (!_rtl92s_set_sysclk(hw
, u1btmp
)) {
1342 pr_err("Switch ctrl path fail\n");
1347 /* Power save for MAC */
1348 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
&&
1349 !rtlhal
->driver_going2unload
) {
1350 /* enable LED function */
1351 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1352 /* SW/HW radio off or halt adapter!! For example S3/S4 */
1354 /* LED function disable. Power range is about 8mA now. */
1355 /* if write 0xF1 disconnect_pci power
1356 * ifconfig wlan0 down power are both high 35:70 */
1357 /* if write oxF9 disconnect_pci power
1358 * ifconfig wlan0 down power are both low 12:45*/
1359 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1362 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, 0x70);
1363 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, 0x68);
1364 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x00);
1365 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1366 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, 0x0E);
1367 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1371 static void _rtl92se_gen_refreshledstate(struct ieee80211_hw
*hw
)
1373 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1374 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1375 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
1377 if (rtlpci
->up_first_time
== 1)
1380 if (rtlpriv
->psc
.rfoff_reason
== RF_CHANGE_BY_IPS
)
1381 rtl92se_sw_led_on(hw
, pled0
);
1383 rtl92se_sw_led_off(hw
, pled0
);
1387 static void _rtl92se_power_domain_init(struct ieee80211_hw
*hw
)
1389 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1393 rtlpriv
->psc
.pwrdomain_protect
= true;
1395 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1396 if (tmpu1b
& BIT(7)) {
1397 tmpu1b
&= ~(BIT(6) | BIT(7));
1398 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1399 rtlpriv
->psc
.pwrdomain_protect
= false;
1404 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x0);
1405 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1407 /* Reset MAC-IO and CPU and Core Digital BIT10/11/15 */
1408 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1410 /* If IPS we need to turn LED on. So we not
1411 * not disable BIT 3/7 of reg3. */
1412 if (rtlpriv
->psc
.rfoff_reason
& (RF_CHANGE_BY_IPS
| RF_CHANGE_BY_HW
))
1417 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
1418 /* wait for BIT 10/11/15 to pull high automatically!! */
1421 rtl_write_byte(rtlpriv
, CMDR
, 0);
1422 rtl_write_byte(rtlpriv
, TCR
, 0);
1424 /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
1425 tmpu1b
= rtl_read_byte(rtlpriv
, 0x562);
1427 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1428 tmpu1b
&= ~(BIT(3));
1429 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1431 /* Enable AFE clock source */
1432 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
);
1433 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, (tmpu1b
| 0x01));
1436 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1);
1437 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, (tmpu1b
& 0xfb));
1439 /* Enable AFE Macro Block's Bandgap */
1440 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1441 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| BIT(0)));
1444 /* Enable AFE Mbias */
1445 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1446 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| 0x02));
1449 /* Enable LDOA15 block */
1450 tmpu1b
= rtl_read_byte(rtlpriv
, LDOA15_CTRL
);
1451 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, (tmpu1b
| BIT(0)));
1453 /* Set Digital Vdd to Retention isolation Path. */
1454 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
1455 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, (tmpu2b
| BIT(11)));
1458 /* For warm reboot NIC disappera bug. */
1459 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1460 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(13)));
1462 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, 0x68);
1464 /* Enable AFE PLL Macro Block */
1465 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
);
1466 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
1467 /* Enable MAC 80MHZ clock */
1468 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
+ 1);
1469 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, (tmpu1b
| BIT(0)));
1472 /* Release isolation AFE PLL & MD */
1473 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xA6);
1475 /* Enable MAC clock */
1476 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1477 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
| BIT(12) | BIT(11)));
1479 /* Enable Core digital and enable IOREG R/W */
1480 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1481 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11)));
1483 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11) | BIT(15)));
1485 /* Switch the control path. */
1486 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1487 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
& (~BIT(2))));
1489 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1490 tmpu1b
= ((tmpu1b
| BIT(7)) & (~BIT(6)));
1491 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1492 rtlpriv
->psc
.pwrdomain_protect
= false;
1496 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1498 /* After MACIO reset,we must refresh LED state. */
1499 _rtl92se_gen_refreshledstate(hw
);
1501 rtlpriv
->psc
.pwrdomain_protect
= false;
1504 void rtl92se_card_disable(struct ieee80211_hw
*hw
)
1506 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1507 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1508 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1509 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1510 enum nl80211_iftype opmode
;
1513 rtlpriv
->intf_ops
->enable_aspm(hw
);
1515 if (rtlpci
->driver_is_goingto_unload
||
1516 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1517 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1519 /* we should chnge GPIO to input mode
1520 * this will drop away current about 25mA*/
1521 rtl8192se_gpiobit3_cfg_inputmode(hw
);
1523 /* this is very important for ips power save */
1524 while (wait
-- >= 10 && rtlpriv
->psc
.pwrdomain_protect
) {
1525 if (rtlpriv
->psc
.pwrdomain_protect
)
1531 mac
->link_state
= MAC80211_NOLINK
;
1532 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1533 _rtl92se_set_media_status(hw
, opmode
);
1535 _rtl92s_phy_set_rfhalt(hw
);
1539 void rtl92se_interrupt_recognized(struct ieee80211_hw
*hw
,
1540 struct rtl_int
*intvec
)
1542 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1543 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1545 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1546 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1548 intvec
->intb
= rtl_read_dword(rtlpriv
, ISR
+ 4) & rtlpci
->irq_mask
[1];
1549 rtl_write_dword(rtlpriv
, ISR
+ 4, intvec
->intb
);
1552 void rtl92se_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1554 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1555 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1556 u16 bcntime_cfg
= 0;
1557 u16 bcn_cw
= 6, bcn_ifs
= 0xf;
1558 u16 atim_window
= 2;
1560 /* ATIM Window (in unit of TU). */
1561 rtl_write_word(rtlpriv
, ATIMWND
, atim_window
);
1563 /* Beacon interval (in unit of TU). */
1564 rtl_write_word(rtlpriv
, BCN_INTERVAL
, mac
->beacon_interval
);
1566 /* DrvErlyInt (in unit of TU). (Time to send
1567 * interrupt to notify driver to change
1568 * beacon content) */
1569 rtl_write_word(rtlpriv
, BCN_DRV_EARLY_INT
, 10 << 4);
1571 /* BcnDMATIM(in unit of us). Indicates the
1572 * time before TBTT to perform beacon queue DMA */
1573 rtl_write_word(rtlpriv
, BCN_DMATIME
, 256);
1575 /* Force beacon frame transmission even
1576 * after receiving beacon frame from
1577 * other ad hoc STA */
1578 rtl_write_byte(rtlpriv
, BCN_ERR_THRESH
, 100);
1580 /* Beacon Time Configuration */
1581 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1582 bcntime_cfg
|= (bcn_cw
<< BCN_TCFG_CW_SHIFT
);
1584 /* TODO: bcn_ifs may required to be changed on ASIC */
1585 bcntime_cfg
|= bcn_ifs
<< BCN_TCFG_IFS
;
1587 /*for beacon changed */
1588 rtl92s_phy_set_beacon_hwreg(hw
, mac
->beacon_interval
);
1591 void rtl92se_set_beacon_interval(struct ieee80211_hw
*hw
)
1593 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1594 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1595 u16 bcn_interval
= mac
->beacon_interval
;
1597 /* Beacon interval (in unit of TU). */
1598 rtl_write_word(rtlpriv
, BCN_INTERVAL
, bcn_interval
);
1599 /* 2008.10.24 added by tynli for beacon changed. */
1600 rtl92s_phy_set_beacon_hwreg(hw
, bcn_interval
);
1603 void rtl92se_update_interrupt_mask(struct ieee80211_hw
*hw
,
1604 u32 add_msr
, u32 rm_msr
)
1606 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1607 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1609 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
, "add_msr:%x, rm_msr:%x\n",
1613 rtlpci
->irq_mask
[0] |= add_msr
;
1616 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1618 rtl92se_disable_interrupt(hw
);
1619 rtl92se_enable_interrupt(hw
);
1622 static void _rtl8192se_get_ic_inferiority(struct ieee80211_hw
*hw
)
1624 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1625 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1628 rtlhal
->ic_class
= IC_INFERIORITY_A
;
1630 /* Only retrieving while using EFUSE. */
1631 if ((rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) &&
1632 !rtlefuse
->autoload_failflag
) {
1633 efuse_id
= efuse_read_1byte(hw
, EFUSE_IC_ID_OFFSET
);
1635 if (efuse_id
== 0xfe)
1636 rtlhal
->ic_class
= IC_INFERIORITY_B
;
1640 static void _rtl92se_read_adapter_info(struct ieee80211_hw
*hw
)
1642 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1643 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1644 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1645 struct device
*dev
= &rtl_pcipriv(hw
)->dev
.pdev
->dev
;
1649 u8 hwinfo
[HWSET_MAX_SIZE_92S
];
1652 switch (rtlefuse
->epromtype
) {
1653 case EEPROM_BOOT_EFUSE
:
1654 rtl_efuse_shadow_map_update(hw
);
1658 pr_err("RTL819X Not boot from eeprom, check it !!\n");
1662 dev_warn(dev
, "no efuse data\n");
1666 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
1667 HWSET_MAX_SIZE_92S
);
1669 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1670 hwinfo
, HWSET_MAX_SIZE_92S
);
1672 eeprom_id
= *((u16
*)&hwinfo
[0]);
1673 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
1674 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1675 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1676 rtlefuse
->autoload_failflag
= true;
1678 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1679 rtlefuse
->autoload_failflag
= false;
1682 if (rtlefuse
->autoload_failflag
)
1685 _rtl8192se_get_ic_inferiority(hw
);
1687 /* Read IC Version && Channel Plan */
1688 /* VID, DID SE 0xA-D */
1689 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
1690 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
1691 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[EEPROM_SVID
];
1692 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[EEPROM_SMID
];
1693 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
1695 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1696 "EEPROMId = 0x%4x\n", eeprom_id
);
1697 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1698 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1699 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1700 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1701 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1702 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1703 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1704 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1706 for (i
= 0; i
< 6; i
+= 2) {
1707 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
1708 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
1711 for (i
= 0; i
< 6; i
++)
1712 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1714 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1716 /* Get Tx Power Level by Channel */
1717 /* Read Tx power of Channel 1 ~ 14 from EEPROM. */
1718 /* 92S suupport RF A & B */
1719 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1720 for (i
= 0; i
< 3; i
++) {
1721 /* Read CCK RF A & B Tx power */
1722 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
1723 hwinfo
[EEPROM_TXPOWERBASE
+ rf_path
* 3 + i
];
1725 /* Read OFDM RF A & B Tx power for 1T */
1726 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
1727 hwinfo
[EEPROM_TXPOWERBASE
+ 6 + rf_path
* 3 + i
];
1729 /* Read OFDM RF A & B Tx power for 2T */
1730 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[rf_path
][i
]
1731 = hwinfo
[EEPROM_TXPOWERBASE
+ 12 +
1736 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1737 for (i
= 0; i
< 3; i
++)
1738 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1739 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
1741 rtlefuse
->eeprom_chnlarea_txpwr_cck
1743 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1744 for (i
= 0; i
< 3; i
++)
1745 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1746 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1748 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1750 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1751 for (i
= 0; i
< 3; i
++)
1752 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1753 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1755 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1758 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1760 /* Assign dedicated channel tx power */
1761 for (i
= 0; i
< 14; i
++) {
1762 /* channel 1~3 use the same Tx Power Level. */
1772 /* Record A & B CCK /OFDM - 1T/2T Channel area
1774 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1775 rtlefuse
->eeprom_chnlarea_txpwr_cck
1777 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1778 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1780 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
1781 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1785 for (i
= 0; i
< 14; i
++) {
1786 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1787 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
1789 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1790 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
1791 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
1795 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1796 for (i
= 0; i
< 3; i
++) {
1797 /* Read Power diff limit. */
1798 rtlefuse
->eeprom_pwrgroup
[rf_path
][i
] =
1799 hwinfo
[EEPROM_TXPWRGROUP
+ rf_path
* 3 + i
];
1803 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1804 /* Fill Pwr group */
1805 for (i
= 0; i
< 14; i
++) {
1816 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
1817 (rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1819 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
1820 ((rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1823 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1824 "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
1826 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
1827 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1828 "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
1830 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
1834 for (i
= 0; i
< 14; i
++) {
1835 /* Read tx power difference between HT OFDM 20/40 MHZ */
1846 tempval
= hwinfo
[EEPROM_TX_PWR_HT20_DIFF
+ index
] & 0xff;
1847 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
1848 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
1849 ((tempval
>> 4) & 0xF);
1851 /* Read OFDM<->HT tx power diff */
1862 tempval
= hwinfo
[EEPROM_TX_PWR_OFDM_DIFF
+ index
] & 0xff;
1863 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] =
1865 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
1866 ((tempval
>> 4) & 0xF);
1868 tempval
= hwinfo
[TX_PWR_SAFETY_CHK
];
1869 rtlefuse
->txpwr_safetyflag
= (tempval
& 0x01);
1872 rtlefuse
->eeprom_regulatory
= 0;
1873 if (rtlefuse
->eeprom_version
>= 2) {
1875 if (rtlefuse
->eeprom_version
>= 4)
1876 rtlefuse
->eeprom_regulatory
=
1877 (hwinfo
[EEPROM_REGULATORY
] & 0x7);
1879 rtlefuse
->eeprom_regulatory
=
1880 (hwinfo
[EEPROM_REGULATORY
] & 0x1);
1882 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1883 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1885 for (i
= 0; i
< 14; i
++)
1886 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1887 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
1888 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
1889 for (i
= 0; i
< 14; i
++)
1890 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1891 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
1892 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
1893 for (i
= 0; i
< 14; i
++)
1894 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1895 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
1896 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
1897 for (i
= 0; i
< 14; i
++)
1898 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1899 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
1900 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
1902 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1903 "TxPwrSafetyFlag = %d\n", rtlefuse
->txpwr_safetyflag
);
1905 /* Read RF-indication and Tx Power gain
1906 * index diff of legacy to HT OFDM rate. */
1907 tempval
= hwinfo
[EEPROM_RFIND_POWERDIFF
] & 0xff;
1908 rtlefuse
->eeprom_txpowerdiff
= tempval
;
1909 rtlefuse
->legacy_httxpowerdiff
=
1910 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][0];
1912 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1913 "TxPowerDiff = %#x\n", rtlefuse
->eeprom_txpowerdiff
);
1915 /* Get TSSI value for each path. */
1916 usvalue
= *(u16
*)&hwinfo
[EEPROM_TSSI_A
];
1917 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = (u8
)((usvalue
& 0xff00) >> 8);
1918 usvalue
= hwinfo
[EEPROM_TSSI_B
];
1919 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = (u8
)(usvalue
& 0xff);
1921 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1922 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
1923 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
1925 /* Read antenna tx power offset of B/C/D to A from EEPROM */
1926 /* and read ThermalMeter from EEPROM */
1927 tempval
= hwinfo
[EEPROM_THERMALMETER
];
1928 rtlefuse
->eeprom_thermalmeter
= tempval
;
1929 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1930 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1932 /* ThermalMeter, BIT(0)~3 for RFIC1, BIT(4)~7 for RFIC2 */
1933 rtlefuse
->thermalmeter
[0] = (rtlefuse
->eeprom_thermalmeter
& 0x1f);
1934 rtlefuse
->tssi_13dbm
= rtlefuse
->eeprom_thermalmeter
* 100;
1936 /* Read CrystalCap from EEPROM */
1937 tempval
= hwinfo
[EEPROM_CRYSTALCAP
] >> 4;
1938 rtlefuse
->eeprom_crystalcap
= tempval
;
1939 /* CrystalCap, BIT(12)~15 */
1940 rtlefuse
->crystalcap
= rtlefuse
->eeprom_crystalcap
;
1942 /* Read IC Version && Channel Plan */
1943 /* Version ID, Channel plan */
1944 rtlefuse
->eeprom_channelplan
= hwinfo
[EEPROM_CHANNELPLAN
];
1945 rtlefuse
->txpwr_fromeprom
= true;
1946 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1947 "EEPROM ChannelPlan = 0x%4x\n", rtlefuse
->eeprom_channelplan
);
1949 /* Read Customer ID or Board Type!!! */
1950 tempval
= hwinfo
[EEPROM_BOARDTYPE
];
1951 /* Change RF type definition */
1953 rtlphy
->rf_type
= RF_2T2R
;
1954 else if (tempval
== 1)
1955 rtlphy
->rf_type
= RF_1T2R
;
1956 else if (tempval
== 2)
1957 rtlphy
->rf_type
= RF_1T2R
;
1958 else if (tempval
== 3)
1959 rtlphy
->rf_type
= RF_1T1R
;
1961 /* 1T2R but 1SS (1x1 receive combining) */
1962 rtlefuse
->b1x1_recvcombine
= false;
1963 if (rtlphy
->rf_type
== RF_1T2R
) {
1964 tempval
= rtl_read_byte(rtlpriv
, 0x07);
1965 if (!(tempval
& BIT(0))) {
1966 rtlefuse
->b1x1_recvcombine
= true;
1967 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1968 "RF_TYPE=1T2R but only 1SS\n");
1971 rtlefuse
->b1ss_support
= rtlefuse
->b1x1_recvcombine
;
1972 rtlefuse
->eeprom_oemid
= *&hwinfo
[EEPROM_CUSTOMID
];
1974 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "EEPROM Customer ID: 0x%2x\n",
1975 rtlefuse
->eeprom_oemid
);
1977 /* set channel paln to world wide 13 */
1978 rtlefuse
->channel_plan
= COUNTRY_CODE_WORLD_WIDE_13
;
1981 void rtl92se_read_eeprom_info(struct ieee80211_hw
*hw
)
1983 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1984 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1987 tmp_u1b
= rtl_read_byte(rtlpriv
, EPROM_CMD
);
1989 if (tmp_u1b
& BIT(4)) {
1990 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1991 rtlefuse
->epromtype
= EEPROM_93C46
;
1993 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1994 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1997 if (tmp_u1b
& BIT(5)) {
1998 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1999 rtlefuse
->autoload_failflag
= false;
2000 _rtl92se_read_adapter_info(hw
);
2002 pr_err("Autoload ERR!!\n");
2003 rtlefuse
->autoload_failflag
= true;
2007 static void rtl92se_update_hal_rate_table(struct ieee80211_hw
*hw
,
2008 struct ieee80211_sta
*sta
)
2010 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2011 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2012 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2013 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2016 u8 nmode
= mac
->ht_enable
;
2017 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2018 u16 shortgi_rate
= 0;
2019 u32 tmp_ratr_value
= 0;
2020 u8 curtxbw_40mhz
= mac
->bw_40
;
2021 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2023 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2025 enum wireless_mode wirelessmode
= mac
->mode
;
2027 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2028 ratr_value
= sta
->supp_rates
[1] << 4;
2030 ratr_value
= sta
->supp_rates
[0];
2031 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2033 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2034 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2035 switch (wirelessmode
) {
2036 case WIRELESS_MODE_B
:
2037 ratr_value
&= 0x0000000D;
2039 case WIRELESS_MODE_G
:
2040 ratr_value
&= 0x00000FF5;
2042 case WIRELESS_MODE_N_24G
:
2043 case WIRELESS_MODE_N_5G
:
2045 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2046 ratr_value
&= 0x0007F005;
2050 if (get_rf_type(rtlphy
) == RF_1T2R
||
2051 get_rf_type(rtlphy
) == RF_1T1R
) {
2053 ratr_mask
= 0x000ff015;
2055 ratr_mask
= 0x000ff005;
2058 ratr_mask
= 0x0f0ff015;
2060 ratr_mask
= 0x0f0ff005;
2063 ratr_value
&= ratr_mask
;
2067 if (rtlphy
->rf_type
== RF_1T2R
)
2068 ratr_value
&= 0x000ff0ff;
2070 ratr_value
&= 0x0f0ff0ff;
2075 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2076 ratr_value
&= 0x0FFFFFFF;
2077 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2078 ratr_value
&= 0x0FFFFFF0;
2080 if (nmode
&& ((curtxbw_40mhz
&&
2081 curshortgi_40mhz
) || (!curtxbw_40mhz
&&
2082 curshortgi_20mhz
))) {
2084 ratr_value
|= 0x10000000;
2085 tmp_ratr_value
= (ratr_value
>> 12);
2087 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2088 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2092 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2093 (shortgi_rate
<< 4) | (shortgi_rate
);
2095 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2098 rtl_write_dword(rtlpriv
, ARFR0
+ ratr_index
* 4, ratr_value
);
2099 if (ratr_value
& 0xfffff000)
2100 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_N
);
2102 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_BG
);
2104 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, "%x\n",
2105 rtl_read_dword(rtlpriv
, ARFR0
));
2108 static void rtl92se_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2109 struct ieee80211_sta
*sta
,
2110 u8 rssi_level
, bool update_bw
)
2112 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2113 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2114 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2115 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2116 struct rtl_sta_info
*sta_entry
= NULL
;
2119 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
2120 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2122 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2124 enum wireless_mode wirelessmode
= 0;
2125 bool shortgi
= false;
2127 u8 shortgi_rate
= 0;
2130 bool bmulticast
= false;
2132 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2134 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
2135 wirelessmode
= sta_entry
->wireless_mode
;
2136 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
2137 curtxbw_40mhz
= mac
->bw_40
;
2138 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2139 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2140 macid
= sta
->aid
+ 1;
2142 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2143 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2145 ratr_bitmap
= sta
->supp_rates
[0];
2146 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2147 ratr_bitmap
= 0xfff;
2148 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2149 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2150 switch (wirelessmode
) {
2151 case WIRELESS_MODE_B
:
2152 band
|= WIRELESS_11B
;
2153 ratr_index
= RATR_INX_WIRELESS_B
;
2154 if (ratr_bitmap
& 0x0000000c)
2155 ratr_bitmap
&= 0x0000000d;
2157 ratr_bitmap
&= 0x0000000f;
2159 case WIRELESS_MODE_G
:
2160 band
|= (WIRELESS_11G
| WIRELESS_11B
);
2161 ratr_index
= RATR_INX_WIRELESS_GB
;
2163 if (rssi_level
== 1)
2164 ratr_bitmap
&= 0x00000f00;
2165 else if (rssi_level
== 2)
2166 ratr_bitmap
&= 0x00000ff0;
2168 ratr_bitmap
&= 0x00000ff5;
2170 case WIRELESS_MODE_A
:
2171 band
|= WIRELESS_11A
;
2172 ratr_index
= RATR_INX_WIRELESS_A
;
2173 ratr_bitmap
&= 0x00000ff0;
2175 case WIRELESS_MODE_N_24G
:
2176 case WIRELESS_MODE_N_5G
:
2177 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2178 ratr_index
= RATR_INX_WIRELESS_NGB
;
2180 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2181 if (rssi_level
== 1)
2182 ratr_bitmap
&= 0x00070000;
2183 else if (rssi_level
== 2)
2184 ratr_bitmap
&= 0x0007f000;
2186 ratr_bitmap
&= 0x0007f005;
2188 if (rtlphy
->rf_type
== RF_1T2R
||
2189 rtlphy
->rf_type
== RF_1T1R
) {
2190 if (rssi_level
== 1) {
2191 ratr_bitmap
&= 0x000f0000;
2192 } else if (rssi_level
== 3) {
2193 ratr_bitmap
&= 0x000fc000;
2194 } else if (rssi_level
== 5) {
2195 ratr_bitmap
&= 0x000ff000;
2198 ratr_bitmap
&= 0x000ff015;
2200 ratr_bitmap
&= 0x000ff005;
2203 if (rssi_level
== 1) {
2204 ratr_bitmap
&= 0x0f8f0000;
2205 } else if (rssi_level
== 3) {
2206 ratr_bitmap
&= 0x0f8fc000;
2207 } else if (rssi_level
== 5) {
2208 ratr_bitmap
&= 0x0f8ff000;
2211 ratr_bitmap
&= 0x0f8ff015;
2213 ratr_bitmap
&= 0x0f8ff005;
2218 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2219 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2222 else if (macid
== 1)
2227 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2228 ratr_index
= RATR_INX_WIRELESS_NGB
;
2230 if (rtlphy
->rf_type
== RF_1T2R
)
2231 ratr_bitmap
&= 0x000ff0ff;
2233 ratr_bitmap
&= 0x0f8ff0ff;
2236 sta_entry
->ratr_index
= ratr_index
;
2238 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2239 ratr_bitmap
&= 0x0FFFFFFF;
2240 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2241 ratr_bitmap
&= 0x0FFFFFF0;
2244 ratr_bitmap
|= 0x10000000;
2245 /* Get MAX MCS available. */
2246 ratr_value
= (ratr_bitmap
>> 12);
2247 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2248 if ((1 << shortgi_rate
) & ratr_value
)
2252 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2253 (shortgi_rate
<< 4) | (shortgi_rate
);
2254 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2257 mask
|= (bmulticast
? 1 : 0) << 9 | (macid
& 0x1f) << 4 | (band
& 0xf);
2259 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_TRACE
, "mask = %x, bitmap = %x\n",
2261 rtl_write_dword(rtlpriv
, 0x2c4, ratr_bitmap
);
2262 rtl_write_dword(rtlpriv
, WFM5
, (FW_RA_UPDATE_MASK
| (mask
<< 8)));
2265 sta_entry
->ratr_index
= ratr_index
;
2268 void rtl92se_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2269 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2273 if (rtlpriv
->dm
.useramask
)
2274 rtl92se_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2276 rtl92se_update_hal_rate_table(hw
, sta
);
2279 void rtl92se_update_channel_access_setting(struct ieee80211_hw
*hw
)
2281 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2282 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2285 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2287 sifs_timer
= 0x0e0e;
2288 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2292 /* this ifunction is for RFKILL, it's different with windows,
2293 * because UI will disable wireless when GPIO Radio Off.
2294 * And here we not check or Disable/Enable ASPM like windows*/
2295 bool rtl92se_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2297 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2298 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2299 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2300 enum rf_pwrstate rfpwr_toset
/*, cur_rfstate */;
2301 unsigned long flag
= 0;
2302 bool actuallyset
= false;
2303 bool turnonbypowerdomain
= false;
2305 /* just 8191se can check gpio before firstup, 92c/92d have fixed it */
2306 if ((rtlpci
->up_first_time
== 1) || (rtlpci
->being_init_adapter
))
2309 if (ppsc
->swrf_processing
)
2312 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2313 if (ppsc
->rfchange_inprogress
) {
2314 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2317 ppsc
->rfchange_inprogress
= true;
2318 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2321 /* cur_rfstate = ppsc->rfpwr_state;*/
2323 /* because after _rtl92s_phy_set_rfhalt, all power
2324 * closed, so we must open some power for GPIO check,
2325 * or we will always check GPIO RFOFF here,
2326 * And we should close power after GPIO check */
2327 if (RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2328 _rtl92se_power_domain_init(hw
);
2329 turnonbypowerdomain
= true;
2332 rfpwr_toset
= _rtl92se_rf_onoff_detect(hw
);
2334 if ((ppsc
->hwradiooff
) && (rfpwr_toset
== ERFON
)) {
2335 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2336 "RFKILL-HW Radio ON, RF ON\n");
2338 rfpwr_toset
= ERFON
;
2339 ppsc
->hwradiooff
= false;
2341 } else if ((!ppsc
->hwradiooff
) && (rfpwr_toset
== ERFOFF
)) {
2342 RT_TRACE(rtlpriv
, COMP_RF
,
2343 DBG_DMESG
, "RFKILL-HW Radio OFF, RF OFF\n");
2345 rfpwr_toset
= ERFOFF
;
2346 ppsc
->hwradiooff
= true;
2351 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2352 ppsc
->rfchange_inprogress
= false;
2353 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2355 /* this not include ifconfig wlan0 down case */
2356 /* } else if (rfpwr_toset == ERFOFF || cur_rfstate == ERFOFF) { */
2358 /* because power_domain_init may be happen when
2359 * _rtl92s_phy_set_rfhalt, this will open some powers
2360 * and cause current increasing about 40 mA for ips,
2361 * rfoff and ifconfig down, so we set
2362 * _rtl92s_phy_set_rfhalt again here */
2363 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
&&
2364 turnonbypowerdomain
) {
2365 _rtl92s_phy_set_rfhalt(hw
);
2366 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2369 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2370 ppsc
->rfchange_inprogress
= false;
2371 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2375 return !ppsc
->hwradiooff
;
2379 /* Is_wepkey just used for WEP used as group & pairwise key
2380 * if pairwise is AES ang group is WEP Is_wepkey == false.*/
2381 void rtl92se_set_key(struct ieee80211_hw
*hw
, u32 key_index
, u8
*p_macaddr
,
2382 bool is_group
, u8 enc_algo
, bool is_wepkey
, bool clear_all
)
2384 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2385 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2386 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2387 u8
*macaddr
= p_macaddr
;
2390 bool is_pairwise
= false;
2392 static u8 cam_const_addr
[4][6] = {
2393 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2394 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2395 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2396 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2398 static u8 cam_const_broad
[] = {
2399 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2405 u8 clear_number
= 5;
2407 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2409 for (idx
= 0; idx
< clear_number
; idx
++) {
2410 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2411 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2414 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2416 rtlpriv
->sec
.key_len
[idx
] = 0;
2422 case WEP40_ENCRYPTION
:
2423 enc_algo
= CAM_WEP40
;
2425 case WEP104_ENCRYPTION
:
2426 enc_algo
= CAM_WEP104
;
2428 case TKIP_ENCRYPTION
:
2429 enc_algo
= CAM_TKIP
;
2431 case AESCCMP_ENCRYPTION
:
2435 pr_err("switch case %#x not processed\n",
2437 enc_algo
= CAM_TKIP
;
2441 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2442 macaddr
= cam_const_addr
[key_index
];
2443 entry_id
= key_index
;
2446 macaddr
= cam_const_broad
;
2447 entry_id
= key_index
;
2449 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2450 entry_id
= rtl_cam_get_free_entry(hw
,
2452 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2453 pr_err("Can not find free hw security cam entry\n");
2457 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2460 key_index
= PAIRWISE_KEYIDX
;
2465 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2466 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2467 "delete one entry, entry_id is %d\n",
2469 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2470 rtl_cam_del_entry(hw
, p_macaddr
);
2471 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2473 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2476 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2477 "set Pairwise key\n");
2479 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2481 CAM_CONFIG_NO_USEDK
,
2482 rtlpriv
->sec
.key_buf
[key_index
]);
2484 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2487 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2488 rtl_cam_add_one_entry(hw
,
2491 CAM_PAIRWISE_KEY_POSITION
,
2492 enc_algo
, CAM_CONFIG_NO_USEDK
,
2493 rtlpriv
->sec
.key_buf
[entry_id
]);
2496 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2498 CAM_CONFIG_NO_USEDK
,
2499 rtlpriv
->sec
.key_buf
[entry_id
]);
2506 void rtl92se_suspend(struct ieee80211_hw
*hw
)
2508 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2510 rtlpci
->up_first_time
= true;
2513 void rtl92se_resume(struct ieee80211_hw
*hw
)
2515 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2518 pci_read_config_dword(rtlpci
->pdev
, 0x40, &val
);
2519 if ((val
& 0x0000ff00) != 0)
2520 pci_write_config_dword(rtlpci
->pdev
, 0x40,