1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
45 void rtl92se_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
47 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
48 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
49 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
53 *((u32
*) (val
)) = rtlpci
->receive_config
;
56 case HW_VAR_RF_STATE
: {
57 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
60 case HW_VAR_FW_PSMODE_STATUS
: {
61 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
64 case HW_VAR_CORRECT_TSF
: {
66 u32
*ptsf_low
= (u32
*)&tsf
;
67 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
69 *ptsf_high
= rtl_read_dword(rtlpriv
, (TSFR
+ 4));
70 *ptsf_low
= rtl_read_dword(rtlpriv
, TSFR
);
72 *((u64
*) (val
)) = tsf
;
77 *((bool *)(val
)) = rtlpriv
->dm
.current_mrc_switch
;
81 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
82 "switch case not processed\n");
88 void rtl92se_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
90 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
91 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
92 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
93 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
94 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
95 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
98 case HW_VAR_ETHER_ADDR
:{
99 rtl_write_dword(rtlpriv
, IDR0
, ((u32
*)(val
))[0]);
100 rtl_write_word(rtlpriv
, IDR4
, ((u16
*)(val
+ 4))[0]);
103 case HW_VAR_BASIC_RATE
:{
104 u16 rate_cfg
= ((u16
*) val
)[0];
107 if (rtlhal
->version
== VERSION_8192S_ACUT
)
108 rate_cfg
= rate_cfg
& 0x150;
110 rate_cfg
= rate_cfg
& 0x15f;
114 rtl_write_byte(rtlpriv
, RRSR
, rate_cfg
& 0xff);
115 rtl_write_byte(rtlpriv
, RRSR
+ 1,
116 (rate_cfg
>> 8) & 0xff);
118 while (rate_cfg
> 0x1) {
119 rate_cfg
= (rate_cfg
>> 1);
122 rtl_write_byte(rtlpriv
, INIRTSMCS_SEL
, rate_index
);
127 rtl_write_dword(rtlpriv
, BSSIDR
, ((u32
*)(val
))[0]);
128 rtl_write_word(rtlpriv
, BSSIDR
+ 4,
129 ((u16
*)(val
+ 4))[0]);
133 rtl_write_byte(rtlpriv
, SIFS_OFDM
, val
[0]);
134 rtl_write_byte(rtlpriv
, SIFS_OFDM
+ 1, val
[1]);
137 case HW_VAR_SLOT_TIME
:{
140 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
141 "HW_VAR_SLOT_TIME %x\n", val
[0]);
143 rtl_write_byte(rtlpriv
, SLOT_TIME
, val
[0]);
145 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
146 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
152 case HW_VAR_ACK_PREAMBLE
:{
154 u8 short_preamble
= (bool) (*val
);
155 reg_tmp
= (mac
->cur_40_prime_sc
) << 5;
159 rtl_write_byte(rtlpriv
, RRSR
+ 2, reg_tmp
);
162 case HW_VAR_AMPDU_MIN_SPACE
:{
163 u8 min_spacing_to_set
;
166 min_spacing_to_set
= *val
;
167 if (min_spacing_to_set
<= 7) {
168 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
174 if (min_spacing_to_set
< sec_min_space
)
175 min_spacing_to_set
= sec_min_space
;
176 if (min_spacing_to_set
> 5)
177 min_spacing_to_set
= 5;
180 ((mac
->min_space_cfg
& 0xf8) |
183 *val
= min_spacing_to_set
;
185 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
186 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
189 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
,
194 case HW_VAR_SHORTGI_DENSITY
:{
197 density_to_set
= *val
;
198 mac
->min_space_cfg
= rtlpriv
->rtlhal
.minspace_cfg
;
199 mac
->min_space_cfg
|= (density_to_set
<< 3);
201 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
202 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
205 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
,
210 case HW_VAR_AMPDU_FACTOR
:{
213 u8 factorlevel
[18] = {
214 2, 4, 4, 7, 7, 13, 13,
220 if (factor_toset
<= 3) {
221 factor_toset
= (1 << (factor_toset
+ 2));
222 if (factor_toset
> 0xf)
225 for (index
= 0; index
< 17; index
++) {
226 if (factorlevel
[index
] > factor_toset
)
231 for (index
= 0; index
< 8; index
++) {
232 regtoset
= ((factorlevel
[index
* 2]) |
235 rtl_write_byte(rtlpriv
,
236 AGGLEN_LMT_L
+ index
,
240 regtoset
= ((factorlevel
[16]) |
241 (factorlevel
[17] << 4));
242 rtl_write_byte(rtlpriv
, AGGLEN_LMT_H
, regtoset
);
244 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
245 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
250 case HW_VAR_AC_PARAM
:{
252 rtl92s_dm_init_edca_turbo(hw
);
254 if (rtlpci
->acm_method
!= eAcmWay2_SW
)
255 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
260 case HW_VAR_ACM_CTRL
:{
262 union aci_aifsn
*p_aci_aifsn
= (union aci_aifsn
*)(&(
264 u8 acm
= p_aci_aifsn
->f
.acm
;
265 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, AcmHwCtrl
);
267 acm_ctrl
= acm_ctrl
| ((rtlpci
->acm_method
== 2) ?
273 acm_ctrl
|= AcmHw_BeqEn
;
276 acm_ctrl
|= AcmHw_ViqEn
;
279 acm_ctrl
|= AcmHw_VoqEn
;
282 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
283 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
290 acm_ctrl
&= (~AcmHw_BeqEn
);
293 acm_ctrl
&= (~AcmHw_ViqEn
);
296 acm_ctrl
&= (~AcmHw_BeqEn
);
299 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
300 "switch case not processed\n");
305 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
306 "HW_VAR_ACM_CTRL Write 0x%X\n", acm_ctrl
);
307 rtl_write_byte(rtlpriv
, AcmHwCtrl
, acm_ctrl
);
311 rtl_write_dword(rtlpriv
, RCR
, ((u32
*) (val
))[0]);
312 rtlpci
->receive_config
= ((u32
*) (val
))[0];
315 case HW_VAR_RETRY_LIMIT
:{
316 u8 retry_limit
= val
[0];
318 rtl_write_word(rtlpriv
, RETRY_LIMIT
,
319 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
320 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
323 case HW_VAR_DUAL_TSF_RST
: {
326 case HW_VAR_EFUSE_BYTES
: {
327 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
330 case HW_VAR_EFUSE_USAGE
: {
331 rtlefuse
->efuse_usedpercentage
= *val
;
334 case HW_VAR_IO_CMD
: {
337 case HW_VAR_WPA_CONFIG
: {
338 rtl_write_byte(rtlpriv
, REG_SECR
, *val
);
341 case HW_VAR_SET_RPWM
:{
344 case HW_VAR_H2C_FW_PWRMODE
:{
347 case HW_VAR_FW_PSMODE_STATUS
: {
348 ppsc
->fw_current_inpsmode
= *((bool *) val
);
351 case HW_VAR_H2C_FW_JOINBSSRPT
:{
357 case HW_VAR_CORRECT_TSF
:{
361 bool bmrc_toset
= *((bool *)val
);
365 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
367 u1bdata
= (u8
)rtl_get_bbreg(hw
,
368 ROFDM1_TRXPATHENABLE
,
370 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
,
372 ((u1bdata
& 0xf0) | 0x03));
373 u1bdata
= (u8
)rtl_get_bbreg(hw
,
374 ROFDM0_TRXPATHENABLE
,
376 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
380 /* Update current settings. */
381 rtlpriv
->dm
.current_mrc_switch
= bmrc_toset
;
383 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
385 u1bdata
= (u8
)rtl_get_bbreg(hw
,
386 ROFDM1_TRXPATHENABLE
,
388 rtl_set_bbreg(hw
, ROFDM1_TRXPATHENABLE
,
390 ((u1bdata
& 0xf0) | 0x01));
391 u1bdata
= (u8
)rtl_get_bbreg(hw
,
392 ROFDM0_TRXPATHENABLE
,
394 rtl_set_bbreg(hw
, ROFDM0_TRXPATHENABLE
,
395 MASKBYTE1
, (u1bdata
& 0xfb));
397 /* Update current settings. */
398 rtlpriv
->dm
.current_mrc_switch
= bmrc_toset
;
403 case HW_VAR_FW_LPS_ACTION
: {
404 bool enter_fwlps
= *((bool *)val
);
405 u8 rpwm_val
, fw_pwrmode
;
406 bool fw_current_inps
;
409 rpwm_val
= 0x02; /* RF off */
410 fw_current_inps
= true;
411 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
412 HW_VAR_FW_PSMODE_STATUS
,
413 (u8
*)(&fw_current_inps
));
414 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
415 HW_VAR_H2C_FW_PWRMODE
,
416 (u8
*)(&ppsc
->fwctrl_psmode
));
418 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
422 rpwm_val
= 0x0C; /* RF on */
423 fw_pwrmode
= FW_PS_ACTIVE_MODE
;
424 fw_current_inps
= false;
425 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
427 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
428 HW_VAR_H2C_FW_PWRMODE
,
429 (u8
*)(&fw_pwrmode
));
431 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
432 HW_VAR_FW_PSMODE_STATUS
,
433 (u8
*)(&fw_current_inps
));
437 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
438 "switch case not processed\n");
444 void rtl92se_enable_hw_security_config(struct ieee80211_hw
*hw
)
446 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
447 u8 sec_reg_value
= 0x0;
449 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
450 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
451 rtlpriv
->sec
.pairwise_enc_algorithm
,
452 rtlpriv
->sec
.group_enc_algorithm
);
454 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
455 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
456 "not open hw encryption\n");
460 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXENCENABLE
;
462 if (rtlpriv
->sec
.use_defaultkey
) {
463 sec_reg_value
|= SCR_TXUSEDK
;
464 sec_reg_value
|= SCR_RXUSEDK
;
467 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_LOUD
, "The SECR-value %x\n",
470 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
474 static u8
_rtl92se_halset_sysclk(struct ieee80211_hw
*hw
, u8 data
)
476 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
478 bool bresult
= false;
481 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, data
);
483 /* Wait the MAC synchronized. */
486 /* Check if it is set ready. */
487 tmpvalue
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
488 bresult
= ((tmpvalue
& BIT(7)) == (data
& BIT(7)));
490 if ((data
& (BIT(6) | BIT(7))) == false) {
497 tmpvalue
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
498 if ((tmpvalue
& BIT(6)))
501 pr_err("wait for BIT(6) return value %x\n", tmpvalue
);
517 void rtl8192se_gpiobit3_cfg_inputmode(struct ieee80211_hw
*hw
)
519 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
522 /* The following config GPIO function */
523 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, (GPIOMUX_EN
| GPIOSEL_GPIO
));
524 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IO_SEL
);
526 /* config GPIO3 to input */
527 u1tmp
&= HAL_8192S_HW_GPIO_OFF_MASK
;
528 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, u1tmp
);
532 static u8
_rtl92se_rf_onoff_detect(struct ieee80211_hw
*hw
)
534 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
538 /* The following config GPIO function */
539 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, (GPIOMUX_EN
| GPIOSEL_GPIO
));
540 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IO_SEL
);
542 /* config GPIO3 to input */
543 u1tmp
&= HAL_8192S_HW_GPIO_OFF_MASK
;
544 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, u1tmp
);
546 /* On some of the platform, driver cannot read correct
547 * value without delay between Write_GPIO_SEL and Read_GPIO_IN */
551 u1tmp
= rtl_read_byte(rtlpriv
, GPIO_IN_SE
);
552 retval
= (u1tmp
& HAL_8192S_HW_GPIO_OFF_BIT
) ? ERFON
: ERFOFF
;
557 static void _rtl92se_macconfig_before_fwdownload(struct ieee80211_hw
*hw
)
559 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
560 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
561 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
568 if (rtlpci
->first_init
) {
569 /* Reset PCIE Digital */
570 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
572 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
574 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
| BIT(0));
577 /* Switch to SW IO control */
578 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
579 if (tmpu1b
& BIT(7)) {
580 tmpu1b
&= ~(BIT(6) | BIT(7));
582 /* Set failed, return to prevent hang. */
583 if (!_rtl92se_halset_sysclk(hw
, tmpu1b
))
587 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x0);
589 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
592 /* Clear FW RPWM for FW control LPS.*/
593 rtl_write_byte(rtlpriv
, RPWM
, 0x0);
595 /* Reset MAC-IO and CPU and Core Digital BIT(10)/11/15 */
596 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
598 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
599 /* wait for BIT 10/11/15 to pull high automatically!! */
602 rtl_write_byte(rtlpriv
, CMDR
, 0);
603 rtl_write_byte(rtlpriv
, TCR
, 0);
605 /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
606 tmpu1b
= rtl_read_byte(rtlpriv
, 0x562);
608 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
610 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
612 /* Enable AFE clock source */
613 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
);
614 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, (tmpu1b
| 0x01));
617 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1);
618 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, (tmpu1b
& 0xfb));
620 /* Enable AFE Macro Block's Bandgap */
621 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
622 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| BIT(0)));
625 /* Enable AFE Mbias */
626 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
627 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| 0x02));
630 /* Enable LDOA15 block */
631 tmpu1b
= rtl_read_byte(rtlpriv
, LDOA15_CTRL
);
632 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, (tmpu1b
| BIT(0)));
634 /* Set Digital Vdd to Retention isolation Path. */
635 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
636 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, (tmpu2b
| BIT(11)));
638 /* For warm reboot NIC disappera bug. */
639 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
640 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(13)));
642 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, 0x68);
644 /* Enable AFE PLL Macro Block */
645 /* We need to delay 100u before enabling PLL. */
647 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
);
648 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
650 /* for divider reset */
652 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) |
655 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
658 /* Enable MAC 80MHZ clock */
659 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
+ 1);
660 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, (tmpu1b
| BIT(0)));
663 /* Release isolation AFE PLL & MD */
664 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xA6);
666 /* Enable MAC clock */
667 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
668 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
| BIT(12) | BIT(11)));
670 /* Enable Core digital and enable IOREG R/W */
671 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
672 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11)));
674 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
675 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
& ~(BIT(7)));
678 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11) | BIT(15)));
680 /* Switch the control path. */
681 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
682 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
& (~BIT(2))));
684 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
685 tmpu1b
= ((tmpu1b
| BIT(7)) & (~BIT(6)));
686 if (!_rtl92se_halset_sysclk(hw
, tmpu1b
))
687 return; /* Set failed, return to prevent hang. */
689 rtl_write_word(rtlpriv
, CMDR
, 0x07FC);
691 /* MH We must enable the section of code to prevent load IMEM fail. */
692 /* Load MAC register from WMAc temporarily We simulate macreg. */
693 /* txt HW will provide MAC txt later */
694 rtl_write_byte(rtlpriv
, 0x6, 0x30);
695 rtl_write_byte(rtlpriv
, 0x49, 0xf0);
697 rtl_write_byte(rtlpriv
, 0x4b, 0x81);
699 rtl_write_byte(rtlpriv
, 0xb5, 0x21);
701 rtl_write_byte(rtlpriv
, 0xdc, 0xff);
702 rtl_write_byte(rtlpriv
, 0xdd, 0xff);
703 rtl_write_byte(rtlpriv
, 0xde, 0xff);
704 rtl_write_byte(rtlpriv
, 0xdf, 0xff);
706 rtl_write_byte(rtlpriv
, 0x11a, 0x00);
707 rtl_write_byte(rtlpriv
, 0x11b, 0x00);
709 for (i
= 0; i
< 32; i
++)
710 rtl_write_byte(rtlpriv
, INIMCS_SEL
+ i
, 0x1b);
712 rtl_write_byte(rtlpriv
, 0x236, 0xff);
714 rtl_write_byte(rtlpriv
, 0x503, 0x22);
716 if (ppsc
->support_aspm
&& !ppsc
->support_backdoor
)
717 rtl_write_byte(rtlpriv
, 0x560, 0x40);
719 rtl_write_byte(rtlpriv
, 0x560, 0x00);
721 rtl_write_byte(rtlpriv
, DBG_PORT
, 0x91);
723 /* Set RX Desc Address */
724 rtl_write_dword(rtlpriv
, RDQDA
, rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
);
725 rtl_write_dword(rtlpriv
, RCDA
, rtlpci
->rx_ring
[RX_CMD_QUEUE
].dma
);
727 /* Set TX Desc Address */
728 rtl_write_dword(rtlpriv
, TBKDA
, rtlpci
->tx_ring
[BK_QUEUE
].dma
);
729 rtl_write_dword(rtlpriv
, TBEDA
, rtlpci
->tx_ring
[BE_QUEUE
].dma
);
730 rtl_write_dword(rtlpriv
, TVIDA
, rtlpci
->tx_ring
[VI_QUEUE
].dma
);
731 rtl_write_dword(rtlpriv
, TVODA
, rtlpci
->tx_ring
[VO_QUEUE
].dma
);
732 rtl_write_dword(rtlpriv
, TBDA
, rtlpci
->tx_ring
[BEACON_QUEUE
].dma
);
733 rtl_write_dword(rtlpriv
, TCDA
, rtlpci
->tx_ring
[TXCMD_QUEUE
].dma
);
734 rtl_write_dword(rtlpriv
, TMDA
, rtlpci
->tx_ring
[MGNT_QUEUE
].dma
);
735 rtl_write_dword(rtlpriv
, THPDA
, rtlpci
->tx_ring
[HIGH_QUEUE
].dma
);
736 rtl_write_dword(rtlpriv
, HDA
, rtlpci
->tx_ring
[HCCA_QUEUE
].dma
);
738 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
740 /* To make sure that TxDMA can ready to download FW. */
741 /* We should reset TxDMA if IMEM RPT was not ready. */
743 tmpu1b
= rtl_read_byte(rtlpriv
, TCR
);
744 if ((tmpu1b
& TXDMA_INIT_VALUE
) == TXDMA_INIT_VALUE
)
748 } while (pollingcnt
--);
750 if (pollingcnt
<= 0) {
751 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
752 "Polling TXDMA_INIT_VALUE timeout!! Current TCR(%#x)\n",
754 tmpu1b
= rtl_read_byte(rtlpriv
, CMDR
);
755 rtl_write_byte(rtlpriv
, CMDR
, tmpu1b
& (~TXDMA_EN
));
758 rtl_write_byte(rtlpriv
, CMDR
, tmpu1b
| TXDMA_EN
);
761 /* After MACIO reset,we must refresh LED state. */
762 if ((ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
) ||
763 (ppsc
->rfoff_reason
== 0)) {
764 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
765 struct rtl_led
*pLed0
= &(pcipriv
->ledctl
.sw_led0
);
766 enum rf_pwrstate rfpwr_state_toset
;
767 rfpwr_state_toset
= _rtl92se_rf_onoff_detect(hw
);
769 if (rfpwr_state_toset
== ERFON
)
770 rtl92se_sw_led_on(hw
, pLed0
);
774 static void _rtl92se_macconfig_after_fwdownload(struct ieee80211_hw
*hw
)
776 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
777 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
778 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
779 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
783 /* 1. System Configure Register (Offset: 0x0000 - 0x003F) */
785 /* 2. Command Control Register (Offset: 0x0040 - 0x004F) */
786 /* Turn on 0x40 Command register */
787 rtl_write_word(rtlpriv
, CMDR
, (BBRSTN
| BB_GLB_RSTN
|
788 SCHEDULE_EN
| MACRXEN
| MACTXEN
| DDMA_EN
| FW2HW_EN
|
789 RXDMA_EN
| TXDMA_EN
| HCI_RXDMA_EN
| HCI_TXDMA_EN
));
791 /* Set TCR TX DMA pre 2 FULL enable bit */
792 rtl_write_dword(rtlpriv
, TCR
, rtl_read_dword(rtlpriv
, TCR
) |
796 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
798 /* 3. MACID Setting Register (Offset: 0x0050 - 0x007F) */
800 /* 4. Timing Control Register (Offset: 0x0080 - 0x009F) */
801 /* Set CCK/OFDM SIFS */
802 /* CCK SIFS shall always be 10us. */
803 rtl_write_word(rtlpriv
, SIFS_CCK
, 0x0a0a);
804 rtl_write_word(rtlpriv
, SIFS_OFDM
, 0x1010);
807 rtl_write_byte(rtlpriv
, ACK_TIMEOUT
, 0x40);
810 rtl_write_word(rtlpriv
, BCN_INTERVAL
, 100);
811 rtl_write_word(rtlpriv
, ATIMWND
, 2);
813 /* 5. FIFO Control Register (Offset: 0x00A0 - 0x015F) */
814 /* 5.1 Initialize Number of Reserved Pages in Firmware Queue */
815 /* Firmware allocate now, associate with FW internal setting.!!! */
817 /* 5.2 Setting TX/RX page size 0/1/2/3/4=64/128/256/512/1024 */
818 /* 5.3 Set driver info, we only accept PHY status now. */
819 /* 5.4 Set RXDMA arbitration to control RXDMA/MAC/FW R/W for RXFIFO */
820 rtl_write_byte(rtlpriv
, RXDMA
, rtl_read_byte(rtlpriv
, RXDMA
) | BIT(6));
822 /* 6. Adaptive Control Register (Offset: 0x0160 - 0x01CF) */
823 /* Set RRSR to all legacy rate and HT rate
824 * CCK rate is supported by default.
825 * CCK rate will be filtered out only when associated
826 * AP does not support it.
827 * Only enable ACK rate to OFDM 24M
828 * Disable RRSR for CCK rate in A-Cut */
830 if (rtlhal
->version
== VERSION_8192S_ACUT
)
831 rtl_write_byte(rtlpriv
, RRSR
, 0xf0);
832 else if (rtlhal
->version
== VERSION_8192S_BCUT
)
833 rtl_write_byte(rtlpriv
, RRSR
, 0xff);
834 rtl_write_byte(rtlpriv
, RRSR
+ 1, 0x01);
835 rtl_write_byte(rtlpriv
, RRSR
+ 2, 0x00);
837 /* A-Cut IC do not support CCK rate. We forbid ARFR to */
838 /* fallback to CCK rate */
839 for (i
= 0; i
< 8; i
++) {
840 /*Disable RRSR for CCK rate in A-Cut */
841 if (rtlhal
->version
== VERSION_8192S_ACUT
)
842 rtl_write_dword(rtlpriv
, ARFR0
+ i
* 4, 0x1f0ff0f0);
845 /* Different rate use different AMPDU size */
846 /* MCS32/ MCS15_SG use max AMPDU size 15*2=30K */
847 rtl_write_byte(rtlpriv
, AGGLEN_LMT_H
, 0x0f);
848 /* MCS0/1/2/3 use max AMPDU size 4*2=8K */
849 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
, 0x7442);
850 /* MCS4/5 use max AMPDU size 8*2=16K 6/7 use 10*2=20K */
851 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 2, 0xddd7);
852 /* MCS8/9 use max AMPDU size 8*2=16K 10/11 use 10*2=20K */
853 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 4, 0xd772);
854 /* MCS12/13/14/15 use max AMPDU size 15*2=30K */
855 rtl_write_word(rtlpriv
, AGGLEN_LMT_L
+ 6, 0xfffd);
857 /* Set Data / Response auto rate fallack retry count */
858 rtl_write_dword(rtlpriv
, DARFRC
, 0x04010000);
859 rtl_write_dword(rtlpriv
, DARFRC
+ 4, 0x09070605);
860 rtl_write_dword(rtlpriv
, RARFRC
, 0x04010000);
861 rtl_write_dword(rtlpriv
, RARFRC
+ 4, 0x09070605);
863 /* 7. EDCA Setting Register (Offset: 0x01D0 - 0x01FF) */
864 /* Set all rate to support SG */
865 rtl_write_word(rtlpriv
, SG_RATE
, 0xFFFF);
867 /* 8. WMAC, BA, and CCX related Register (Offset: 0x0200 - 0x023F) */
868 /* Set NAV protection length */
869 rtl_write_word(rtlpriv
, NAV_PROT_LEN
, 0x0080);
870 /* CF-END Threshold */
871 rtl_write_byte(rtlpriv
, CFEND_TH
, 0xFF);
872 /* Set AMPDU minimum space */
873 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
, 0x07);
874 /* Set TXOP stall control for several queue/HI/BCN/MGT/ */
875 rtl_write_byte(rtlpriv
, TXOP_STALL_CTRL
, 0x00);
877 /* 9. Security Control Register (Offset: 0x0240 - 0x025F) */
878 /* 10. Power Save Control Register (Offset: 0x0260 - 0x02DF) */
879 /* 11. General Purpose Register (Offset: 0x02E0 - 0x02FF) */
880 /* 12. Host Interrupt Status Register (Offset: 0x0300 - 0x030F) */
881 /* 13. Test Mode and Debug Control Register (Offset: 0x0310 - 0x034F) */
883 /* 14. Set driver info, we only accept PHY status now. */
884 rtl_write_byte(rtlpriv
, RXDRVINFO_SZ
, 4);
886 /* 15. For EEPROM R/W Workaround */
887 /* 16. For EFUSE to share REG_SYS_FUNC_EN with EEPROM!!! */
888 tmpu2b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
889 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, tmpu2b
| BIT(13));
890 tmpu2b
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
);
891 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, tmpu2b
& (~BIT(8)));
894 /* We may R/W EFUSE in EEPROM mode */
895 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
898 tempval
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1);
900 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, tempval
);
902 /* Change Program timing */
903 rtl_write_byte(rtlpriv
, REG_EFUSE_CTRL
+ 3, 0x72);
904 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "EFUSE CONFIG OK\n");
907 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "OK\n");
911 static void _rtl92se_hw_configure(struct ieee80211_hw
*hw
)
913 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
914 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
915 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
916 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
918 u8 reg_bw_opmode
= 0;
922 reg_bw_opmode
= BW_OPMODE_20MHZ
;
923 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
925 regtmp
= rtl_read_byte(rtlpriv
, INIRTSMCS_SEL
);
926 reg_rrsr
= ((reg_rrsr
& 0x000fffff) << 8) | regtmp
;
927 rtl_write_dword(rtlpriv
, INIRTSMCS_SEL
, reg_rrsr
);
928 rtl_write_byte(rtlpriv
, BW_OPMODE
, reg_bw_opmode
);
930 /* Set Retry Limit here */
931 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
932 (u8
*)(&rtlpci
->shortretry_limit
));
934 rtl_write_byte(rtlpriv
, MLT
, 0x8f);
936 /* For Min Spacing configuration. */
937 switch (rtlphy
->rf_type
) {
940 rtlhal
->minspace_cfg
= (MAX_MSS_DENSITY_1T
<< 3);
944 rtlhal
->minspace_cfg
= (MAX_MSS_DENSITY_2T
<< 3);
947 rtl_write_byte(rtlpriv
, AMPDU_MIN_SPACE
, rtlhal
->minspace_cfg
);
950 int rtl92se_hw_init(struct ieee80211_hw
*hw
)
952 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
953 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
954 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
955 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
956 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
959 bool rtstatus
= true;
963 int wdcapra_add
[] = {
964 EDCAPARA_BE
, EDCAPARA_BK
,
965 EDCAPARA_VI
, EDCAPARA_VO
};
968 rtlpci
->being_init_adapter
= true;
970 /* As this function can take a very long time (up to 350 ms)
971 * and can be called with irqs disabled, reenable the irqs
972 * to let the other devices continue being serviced.
974 * It is safe doing so since our own interrupts will only be enabled
975 * in a subsequent step.
977 local_save_flags(flags
);
980 rtlpriv
->intf_ops
->disable_aspm(hw
);
982 /* 1. MAC Initialize */
983 /* Before FW download, we have to set some MAC register */
984 _rtl92se_macconfig_before_fwdownload(hw
);
986 rtlhal
->version
= (enum version_8192s
)((rtl_read_dword(rtlpriv
,
987 PMC_FSM
) >> 16) & 0xF);
989 rtl8192se_gpiobit3_cfg_inputmode(hw
);
991 /* 2. download firmware */
992 rtstatus
= rtl92s_download_fw(hw
);
994 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
995 "Failed to download FW. Init HW without FW now... "
996 "Please copy FW into /lib/firmware/rtlwifi\n");
1001 /* After FW download, we have to reset MAC register */
1002 _rtl92se_macconfig_after_fwdownload(hw
);
1004 /*Retrieve default FW Cmd IO map. */
1005 rtlhal
->fwcmd_iomap
= rtl_read_word(rtlpriv
, LBUS_MON_ADDR
);
1006 rtlhal
->fwcmd_ioparam
= rtl_read_dword(rtlpriv
, LBUS_ADDR_MASK
);
1008 /* 3. Initialize MAC/PHY Config by MACPHY_reg.txt */
1009 if (!rtl92s_phy_mac_config(hw
)) {
1010 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "MAC Config failed\n");
1015 /* because last function modify RCR, so we update
1016 * rcr var here, or TP will unstable for receive_config
1017 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1018 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1020 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, RCR
);
1021 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1022 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
1024 /* Make sure BB/RF write OK. We should prevent enter IPS. radio off. */
1025 /* We must set flag avoid BB/RF config period later!! */
1026 rtl_write_dword(rtlpriv
, CMDR
, 0x37FC);
1028 /* 4. Initialize BB After MAC Config PHY_reg.txt, AGC_Tab.txt */
1029 if (!rtl92s_phy_bb_config(hw
)) {
1030 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
, "BB Config failed\n");
1035 /* 5. Initiailze RF RAIO_A.txt RF RAIO_B.txt */
1036 /* Before initalizing RF. We can not use FW to do RF-R/W. */
1038 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1040 /* Before RF-R/W we must execute the IO from Scott's suggestion. */
1041 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, 0xDB);
1042 if (rtlhal
->version
== VERSION_8192S_ACUT
)
1043 rtl_write_byte(rtlpriv
, SPS1_CTRL
+ 3, 0x07);
1045 rtl_write_byte(rtlpriv
, RF_CTRL
, 0x07);
1047 if (!rtl92s_phy_rf_config(hw
)) {
1048 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "RF Config failed\n");
1053 /* After read predefined TXT, we must set BB/MAC/RF
1054 * register as our requirement */
1056 rtlphy
->rfreg_chnlval
[0] = rtl92s_phy_query_rf_reg(hw
,
1060 rtlphy
->rfreg_chnlval
[1] = rtl92s_phy_query_rf_reg(hw
,
1065 /*---- Set CCK and OFDM Block "ON"----*/
1066 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1067 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1069 /*3 Set Hardware(Do nothing now) */
1070 _rtl92se_hw_configure(hw
);
1072 /* Read EEPROM TX power index and PHY_REG_PG.txt to capture correct */
1073 /* TX power index for different rate set. */
1074 /* Get original hw reg values */
1075 rtl92s_phy_get_hw_reg_originalvalue(hw
);
1076 /* Write correct tx power index */
1077 rtl92s_phy_set_txpower(hw
, rtlphy
->current_channel
);
1079 /* We must set MAC address after firmware download. */
1080 for (i
= 0; i
< 6; i
++)
1081 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1083 /* EEPROM R/W workaround */
1084 tmp_u1b
= rtl_read_byte(rtlpriv
, MAC_PINMUX_CFG
);
1085 rtl_write_byte(rtlpriv
, MAC_PINMUX_CFG
, tmp_u1b
& (~BIT(3)));
1087 rtl_write_byte(rtlpriv
, 0x4d, 0x0);
1089 if (hal_get_firmwareversion(rtlpriv
) >= 0x49) {
1090 tmp_byte
= rtl_read_byte(rtlpriv
, FW_RSVD_PG_CRTL
) & (~BIT(4));
1091 tmp_byte
= tmp_byte
| BIT(5);
1092 rtl_write_byte(rtlpriv
, FW_RSVD_PG_CRTL
, tmp_byte
);
1093 rtl_write_dword(rtlpriv
, TXDESC_MSK
, 0xFFFFCFFF);
1096 /* We enable high power and RA related mechanism after NIC
1098 if (hal_get_firmwareversion(rtlpriv
) >= 0x35) {
1099 /* Fw v.53 and later. */
1100 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_INIT
);
1101 } else if (hal_get_firmwareversion(rtlpriv
) == 0x34) {
1103 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_INIT
);
1104 rtl92s_phy_chk_fwcmd_iodone(hw
);
1106 /* Compatible earlier FW version. */
1107 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_RESET
);
1108 rtl92s_phy_chk_fwcmd_iodone(hw
);
1109 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_ACTIVE
);
1110 rtl92s_phy_chk_fwcmd_iodone(hw
);
1111 rtl_write_dword(rtlpriv
, WFM5
, FW_RA_REFRESH
);
1112 rtl92s_phy_chk_fwcmd_iodone(hw
);
1115 /* Add to prevent ASPM bug. */
1116 /* Always enable hst and NIC clock request. */
1117 rtl92s_phy_switch_ephy_parameter(hw
);
1120 * 1. Clear all H/W keys.
1121 * 2. Enable H/W encryption/decryption. */
1122 rtl_cam_reset_all_entry(hw
);
1123 secr_value
|= SCR_TXENCENABLE
;
1124 secr_value
|= SCR_RXENCENABLE
;
1125 secr_value
|= SCR_NOSKMC
;
1126 rtl_write_byte(rtlpriv
, REG_SECR
, secr_value
);
1128 for (i
= 0; i
< 4; i
++)
1129 rtl_write_dword(rtlpriv
, wdcapra_add
[i
], 0x5e4322);
1131 if (rtlphy
->rf_type
== RF_1T2R
) {
1132 bool mrc2set
= true;
1133 /* Turn on B-Path */
1134 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MRC
, (u8
*)&mrc2set
);
1137 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_ON
);
1140 local_irq_restore(flags
);
1141 rtlpci
->being_init_adapter
= false;
1145 void rtl92se_set_mac_addr(struct rtl_io
*io
, const u8
*addr
)
1147 /* This is a stub. */
1150 void rtl92se_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1152 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1153 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1154 u32 reg_rcr
= rtlpci
->receive_config
;
1156 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1160 reg_rcr
|= (RCR_CBSSID
);
1161 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1162 } else if (!check_bssid
) {
1163 reg_rcr
&= (~RCR_CBSSID
);
1164 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
, (u8
*)(®_rcr
));
1169 static int _rtl92se_set_media_status(struct ieee80211_hw
*hw
,
1170 enum nl80211_iftype type
)
1172 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1173 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1175 bt_msr
&= ~MSR_LINK_MASK
;
1178 case NL80211_IFTYPE_UNSPECIFIED
:
1179 bt_msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
1180 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1181 "Set Network type to NO LINK!\n");
1183 case NL80211_IFTYPE_ADHOC
:
1184 bt_msr
|= (MSR_LINK_ADHOC
<< MSR_LINK_SHIFT
);
1185 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1186 "Set Network type to Ad Hoc!\n");
1188 case NL80211_IFTYPE_STATION
:
1189 bt_msr
|= (MSR_LINK_MANAGED
<< MSR_LINK_SHIFT
);
1190 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1191 "Set Network type to STA!\n");
1193 case NL80211_IFTYPE_AP
:
1194 bt_msr
|= (MSR_LINK_MASTER
<< MSR_LINK_SHIFT
);
1195 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1196 "Set Network type to AP!\n");
1199 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1200 "Network type %d not supported!\n", type
);
1206 rtl_write_byte(rtlpriv
, (MSR
), bt_msr
);
1208 temp
= rtl_read_dword(rtlpriv
, TCR
);
1209 rtl_write_dword(rtlpriv
, TCR
, temp
& (~BIT(8)));
1210 rtl_write_dword(rtlpriv
, TCR
, temp
| BIT(8));
1216 /* HW_VAR_MEDIA_STATUS & HW_VAR_CECHK_BSSID */
1217 int rtl92se_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1219 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1221 if (_rtl92se_set_media_status(hw
, type
))
1224 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1225 if (type
!= NL80211_IFTYPE_AP
)
1226 rtl92se_set_check_bssid(hw
, true);
1228 rtl92se_set_check_bssid(hw
, false);
1234 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1235 void rtl92se_set_qos(struct ieee80211_hw
*hw
, int aci
)
1237 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1238 rtl92s_dm_init_edca_turbo(hw
);
1242 rtl_write_dword(rtlpriv
, EDCAPARA_BK
, 0xa44f);
1245 /* rtl_write_dword(rtlpriv, EDCAPARA_BE, u4b_ac_param); */
1248 rtl_write_dword(rtlpriv
, EDCAPARA_VI
, 0x5e4322);
1251 rtl_write_dword(rtlpriv
, EDCAPARA_VO
, 0x2f3222);
1254 RT_ASSERT(false, "invalid aci: %d !\n", aci
);
1259 void rtl92se_enable_interrupt(struct ieee80211_hw
*hw
)
1261 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1262 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1264 rtl_write_dword(rtlpriv
, INTA_MASK
, rtlpci
->irq_mask
[0]);
1265 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
1266 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, rtlpci
->irq_mask
[1] & 0x3F);
1269 void rtl92se_disable_interrupt(struct ieee80211_hw
*hw
)
1271 struct rtl_priv
*rtlpriv
;
1272 struct rtl_pci
*rtlpci
;
1274 rtlpriv
= rtl_priv(hw
);
1275 /* if firmware not available, no interrupts */
1276 if (!rtlpriv
|| !rtlpriv
->max_fw_size
)
1278 rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1279 rtl_write_dword(rtlpriv
, INTA_MASK
, 0);
1280 rtl_write_dword(rtlpriv
, INTA_MASK
+ 4, 0);
1282 synchronize_irq(rtlpci
->pdev
->irq
);
1285 static u8
_rtl92s_set_sysclk(struct ieee80211_hw
*hw
, u8 data
)
1287 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1289 bool result
= false;
1292 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, data
);
1294 /* Wait the MAC synchronized. */
1297 /* Check if it is set ready. */
1298 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1299 result
= ((tmp
& BIT(7)) == (data
& BIT(7)));
1301 if ((data
& (BIT(6) | BIT(7))) == false) {
1307 tmp
= rtl_read_byte(rtlpriv
, SYS_CLKR
+ 1);
1312 pr_err("wait for BIT(6) return value %x\n", tmp
);
1328 static void _rtl92s_phy_set_rfhalt(struct ieee80211_hw
*hw
)
1330 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1331 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1332 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1335 if (rtlhal
->driver_going2unload
)
1336 rtl_write_byte(rtlpriv
, 0x560, 0x0);
1338 /* Power save for BB/RF */
1339 u1btmp
= rtl_read_byte(rtlpriv
, LDOV12D_CTRL
);
1341 rtl_write_byte(rtlpriv
, LDOV12D_CTRL
, u1btmp
);
1342 rtl_write_byte(rtlpriv
, SPS1_CTRL
, 0x0);
1343 rtl_write_byte(rtlpriv
, TXPAUSE
, 0xFF);
1344 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1346 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1347 rtl_write_byte(rtlpriv
, PHY_CCA
, 0x0);
1349 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1351 rtl_write_word(rtlpriv
, CMDR
, 0x77FC);
1353 rtl_write_word(rtlpriv
, CMDR
, 0x57FC);
1354 rtl_write_word(rtlpriv
, CMDR
, 0x0000);
1356 if (rtlhal
->driver_going2unload
) {
1357 u1btmp
= rtl_read_byte(rtlpriv
, (REG_SYS_FUNC_EN
+ 1));
1358 u1btmp
&= ~(BIT(0));
1359 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, u1btmp
);
1362 u1btmp
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1364 /* Add description. After switch control path. register
1365 * after page1 will be invisible. We can not do any IO
1366 * for register>0x40. After resume&MACIO reset, we need
1367 * to remember previous reg content. */
1368 if (u1btmp
& BIT(7)) {
1369 u1btmp
&= ~(BIT(6) | BIT(7));
1370 if (!_rtl92s_set_sysclk(hw
, u1btmp
)) {
1371 pr_err("Switch ctrl path fail\n");
1376 /* Power save for MAC */
1377 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
&&
1378 !rtlhal
->driver_going2unload
) {
1379 /* enable LED function */
1380 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1381 /* SW/HW radio off or halt adapter!! For example S3/S4 */
1383 /* LED function disable. Power range is about 8mA now. */
1384 /* if write 0xF1 disconnet_pci power
1385 * ifconfig wlan0 down power are both high 35:70 */
1386 /* if write oxF9 disconnet_pci power
1387 * ifconfig wlan0 down power are both low 12:45*/
1388 rtl_write_byte(rtlpriv
, 0x03, 0xF9);
1391 rtl_write_byte(rtlpriv
, SYS_CLKR
+ 1, 0x70);
1392 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, 0x68);
1393 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x00);
1394 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1395 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, 0x0E);
1396 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1400 static void _rtl92se_gen_refreshledstate(struct ieee80211_hw
*hw
)
1402 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1403 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1404 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1405 struct rtl_led
*pLed0
= &(pcipriv
->ledctl
.sw_led0
);
1407 if (rtlpci
->up_first_time
== 1)
1410 if (rtlpriv
->psc
.rfoff_reason
== RF_CHANGE_BY_IPS
)
1411 rtl92se_sw_led_on(hw
, pLed0
);
1413 rtl92se_sw_led_off(hw
, pLed0
);
1417 static void _rtl92se_power_domain_init(struct ieee80211_hw
*hw
)
1419 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1423 rtlpriv
->psc
.pwrdomain_protect
= true;
1425 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1426 if (tmpu1b
& BIT(7)) {
1427 tmpu1b
&= ~(BIT(6) | BIT(7));
1428 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1429 rtlpriv
->psc
.pwrdomain_protect
= false;
1434 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, 0x0);
1435 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, 0x34);
1437 /* Reset MAC-IO and CPU and Core Digital BIT10/11/15 */
1438 tmpu1b
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1440 /* If IPS we need to turn LED on. So we not
1441 * not disable BIT 3/7 of reg3. */
1442 if (rtlpriv
->psc
.rfoff_reason
& (RF_CHANGE_BY_IPS
| RF_CHANGE_BY_HW
))
1447 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmpu1b
);
1448 /* wait for BIT 10/11/15 to pull high automatically!! */
1451 rtl_write_byte(rtlpriv
, CMDR
, 0);
1452 rtl_write_byte(rtlpriv
, TCR
, 0);
1454 /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
1455 tmpu1b
= rtl_read_byte(rtlpriv
, 0x562);
1457 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1458 tmpu1b
&= ~(BIT(3));
1459 rtl_write_byte(rtlpriv
, 0x562, tmpu1b
);
1461 /* Enable AFE clock source */
1462 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
);
1463 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
, (tmpu1b
| 0x01));
1466 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1);
1467 rtl_write_byte(rtlpriv
, AFE_XTAL_CTRL
+ 1, (tmpu1b
& 0xfb));
1469 /* Enable AFE Macro Block's Bandgap */
1470 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1471 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| BIT(0)));
1474 /* Enable AFE Mbias */
1475 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_MISC
);
1476 rtl_write_byte(rtlpriv
, AFE_MISC
, (tmpu1b
| 0x02));
1479 /* Enable LDOA15 block */
1480 tmpu1b
= rtl_read_byte(rtlpriv
, LDOA15_CTRL
);
1481 rtl_write_byte(rtlpriv
, LDOA15_CTRL
, (tmpu1b
| BIT(0)));
1483 /* Set Digital Vdd to Retention isolation Path. */
1484 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
1485 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, (tmpu2b
| BIT(11)));
1488 /* For warm reboot NIC disappera bug. */
1489 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1490 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(13)));
1492 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+ 1, 0x68);
1494 /* Enable AFE PLL Macro Block */
1495 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
);
1496 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
, (tmpu1b
| BIT(0) | BIT(4)));
1497 /* Enable MAC 80MHZ clock */
1498 tmpu1b
= rtl_read_byte(rtlpriv
, AFE_PLL_CTRL
+ 1);
1499 rtl_write_byte(rtlpriv
, AFE_PLL_CTRL
+ 1, (tmpu1b
| BIT(0)));
1502 /* Release isolation AFE PLL & MD */
1503 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xA6);
1505 /* Enable MAC clock */
1506 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1507 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
| BIT(12) | BIT(11)));
1509 /* Enable Core digital and enable IOREG R/W */
1510 tmpu2b
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1511 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11)));
1513 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (tmpu2b
| BIT(11) | BIT(15)));
1515 /* Switch the control path. */
1516 tmpu2b
= rtl_read_word(rtlpriv
, SYS_CLKR
);
1517 rtl_write_word(rtlpriv
, SYS_CLKR
, (tmpu2b
& (~BIT(2))));
1519 tmpu1b
= rtl_read_byte(rtlpriv
, (SYS_CLKR
+ 1));
1520 tmpu1b
= ((tmpu1b
| BIT(7)) & (~BIT(6)));
1521 if (!_rtl92s_set_sysclk(hw
, tmpu1b
)) {
1522 rtlpriv
->psc
.pwrdomain_protect
= false;
1526 rtl_write_word(rtlpriv
, CMDR
, 0x37FC);
1528 /* After MACIO reset,we must refresh LED state. */
1529 _rtl92se_gen_refreshledstate(hw
);
1531 rtlpriv
->psc
.pwrdomain_protect
= false;
1534 void rtl92se_card_disable(struct ieee80211_hw
*hw
)
1536 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1537 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1538 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1539 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1540 enum nl80211_iftype opmode
;
1543 rtlpriv
->intf_ops
->enable_aspm(hw
);
1545 if (rtlpci
->driver_is_goingto_unload
||
1546 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1547 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1549 /* we should chnge GPIO to input mode
1550 * this will drop away current about 25mA*/
1551 rtl8192se_gpiobit3_cfg_inputmode(hw
);
1553 /* this is very important for ips power save */
1554 while (wait
-- >= 10 && rtlpriv
->psc
.pwrdomain_protect
) {
1555 if (rtlpriv
->psc
.pwrdomain_protect
)
1561 mac
->link_state
= MAC80211_NOLINK
;
1562 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1563 _rtl92se_set_media_status(hw
, opmode
);
1565 _rtl92s_phy_set_rfhalt(hw
);
1569 void rtl92se_interrupt_recognized(struct ieee80211_hw
*hw
, u32
*p_inta
,
1572 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1573 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1575 *p_inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1576 rtl_write_dword(rtlpriv
, ISR
, *p_inta
);
1578 *p_intb
= rtl_read_dword(rtlpriv
, ISR
+ 4) & rtlpci
->irq_mask
[1];
1579 rtl_write_dword(rtlpriv
, ISR
+ 4, *p_intb
);
1582 void rtl92se_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1584 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1585 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1586 u16 bcntime_cfg
= 0;
1587 u16 bcn_cw
= 6, bcn_ifs
= 0xf;
1588 u16 atim_window
= 2;
1590 /* ATIM Window (in unit of TU). */
1591 rtl_write_word(rtlpriv
, ATIMWND
, atim_window
);
1593 /* Beacon interval (in unit of TU). */
1594 rtl_write_word(rtlpriv
, BCN_INTERVAL
, mac
->beacon_interval
);
1596 /* DrvErlyInt (in unit of TU). (Time to send
1597 * interrupt to notify driver to change
1598 * beacon content) */
1599 rtl_write_word(rtlpriv
, BCN_DRV_EARLY_INT
, 10 << 4);
1601 /* BcnDMATIM(in unit of us). Indicates the
1602 * time before TBTT to perform beacon queue DMA */
1603 rtl_write_word(rtlpriv
, BCN_DMATIME
, 256);
1605 /* Force beacon frame transmission even
1606 * after receiving beacon frame from
1607 * other ad hoc STA */
1608 rtl_write_byte(rtlpriv
, BCN_ERR_THRESH
, 100);
1610 /* Beacon Time Configuration */
1611 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1612 bcntime_cfg
|= (bcn_cw
<< BCN_TCFG_CW_SHIFT
);
1614 /* TODO: bcn_ifs may required to be changed on ASIC */
1615 bcntime_cfg
|= bcn_ifs
<< BCN_TCFG_IFS
;
1617 /*for beacon changed */
1618 rtl92s_phy_set_beacon_hwreg(hw
, mac
->beacon_interval
);
1621 void rtl92se_set_beacon_interval(struct ieee80211_hw
*hw
)
1623 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1624 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1625 u16 bcn_interval
= mac
->beacon_interval
;
1627 /* Beacon interval (in unit of TU). */
1628 rtl_write_word(rtlpriv
, BCN_INTERVAL
, bcn_interval
);
1629 /* 2008.10.24 added by tynli for beacon changed. */
1630 rtl92s_phy_set_beacon_hwreg(hw
, bcn_interval
);
1633 void rtl92se_update_interrupt_mask(struct ieee80211_hw
*hw
,
1634 u32 add_msr
, u32 rm_msr
)
1636 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1637 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1639 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
, "add_msr:%x, rm_msr:%x\n",
1643 rtlpci
->irq_mask
[0] |= add_msr
;
1646 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1648 rtl92se_disable_interrupt(hw
);
1649 rtl92se_enable_interrupt(hw
);
1652 static void _rtl8192se_get_IC_Inferiority(struct ieee80211_hw
*hw
)
1654 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1655 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1658 rtlhal
->ic_class
= IC_INFERIORITY_A
;
1660 /* Only retrieving while using EFUSE. */
1661 if ((rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) &&
1662 !rtlefuse
->autoload_failflag
) {
1663 efuse_id
= efuse_read_1byte(hw
, EFUSE_IC_ID_OFFSET
);
1665 if (efuse_id
== 0xfe)
1666 rtlhal
->ic_class
= IC_INFERIORITY_B
;
1670 static void _rtl92se_read_adapter_info(struct ieee80211_hw
*hw
)
1672 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1673 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1674 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1678 u8 hwinfo
[HWSET_MAX_SIZE_92S
];
1681 if (rtlefuse
->epromtype
== EEPROM_93C46
) {
1682 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1683 "RTL819X Not boot from eeprom, check it !!\n");
1684 } else if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
1685 rtl_efuse_shadow_map_update(hw
);
1687 memcpy((void *)hwinfo
, (void *)
1688 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
1689 HWSET_MAX_SIZE_92S
);
1692 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1693 hwinfo
, HWSET_MAX_SIZE_92S
);
1695 eeprom_id
= *((u16
*)&hwinfo
[0]);
1696 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
1697 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1698 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1699 rtlefuse
->autoload_failflag
= true;
1701 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1702 rtlefuse
->autoload_failflag
= false;
1705 if (rtlefuse
->autoload_failflag
)
1708 _rtl8192se_get_IC_Inferiority(hw
);
1710 /* Read IC Version && Channel Plan */
1711 /* VID, DID SE 0xA-D */
1712 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
1713 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
1714 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[EEPROM_SVID
];
1715 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[EEPROM_SMID
];
1716 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
1718 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1719 "EEPROMId = 0x%4x\n", eeprom_id
);
1720 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1721 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1722 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1723 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1724 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1725 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1726 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1727 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1729 for (i
= 0; i
< 6; i
+= 2) {
1730 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
1731 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
1734 for (i
= 0; i
< 6; i
++)
1735 rtl_write_byte(rtlpriv
, MACIDR0
+ i
, rtlefuse
->dev_addr
[i
]);
1737 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1739 /* Get Tx Power Level by Channel */
1740 /* Read Tx power of Channel 1 ~ 14 from EEPROM. */
1741 /* 92S suupport RF A & B */
1742 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1743 for (i
= 0; i
< 3; i
++) {
1744 /* Read CCK RF A & B Tx power */
1745 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
1746 hwinfo
[EEPROM_TXPOWERBASE
+ rf_path
* 3 + i
];
1748 /* Read OFDM RF A & B Tx power for 1T */
1749 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
1750 hwinfo
[EEPROM_TXPOWERBASE
+ 6 + rf_path
* 3 + i
];
1752 /* Read OFDM RF A & B Tx power for 2T */
1753 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[rf_path
][i
]
1754 = hwinfo
[EEPROM_TXPOWERBASE
+ 12 +
1759 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1760 for (i
= 0; i
< 3; i
++)
1761 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1762 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
1764 rtlefuse
->eeprom_chnlarea_txpwr_cck
1766 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1767 for (i
= 0; i
< 3; i
++)
1768 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1769 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1771 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1773 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1774 for (i
= 0; i
< 3; i
++)
1775 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1776 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1778 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1781 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1783 /* Assign dedicated channel tx power */
1784 for (i
= 0; i
< 14; i
++) {
1785 /* channel 1~3 use the same Tx Power Level. */
1795 /* Record A & B CCK /OFDM - 1T/2T Channel area
1797 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1798 rtlefuse
->eeprom_chnlarea_txpwr_cck
1800 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1801 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1803 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
1804 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1808 for (i
= 0; i
< 14; i
++) {
1809 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1810 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
1812 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1813 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
1814 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
1818 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1819 for (i
= 0; i
< 3; i
++) {
1820 /* Read Power diff limit. */
1821 rtlefuse
->eeprom_pwrgroup
[rf_path
][i
] =
1822 hwinfo
[EEPROM_TXPWRGROUP
+ rf_path
* 3 + i
];
1826 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1827 /* Fill Pwr group */
1828 for (i
= 0; i
< 14; i
++) {
1839 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
1840 (rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1842 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
1843 ((rtlefuse
->eeprom_pwrgroup
[rf_path
][index
] &
1846 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1847 "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
1849 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
1850 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1851 "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
1853 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
1857 for (i
= 0; i
< 14; i
++) {
1858 /* Read tx power difference between HT OFDM 20/40 MHZ */
1869 tempval
= hwinfo
[EEPROM_TX_PWR_HT20_DIFF
+ index
] & 0xff;
1870 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
1871 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
1872 ((tempval
>> 4) & 0xF);
1874 /* Read OFDM<->HT tx power diff */
1885 tempval
= hwinfo
[EEPROM_TX_PWR_OFDM_DIFF
+ index
] & 0xff;
1886 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] =
1888 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
1889 ((tempval
>> 4) & 0xF);
1891 tempval
= hwinfo
[TX_PWR_SAFETY_CHK
];
1892 rtlefuse
->txpwr_safetyflag
= (tempval
& 0x01);
1895 rtlefuse
->eeprom_regulatory
= 0;
1896 if (rtlefuse
->eeprom_version
>= 2) {
1898 if (rtlefuse
->eeprom_version
>= 4)
1899 rtlefuse
->eeprom_regulatory
=
1900 (hwinfo
[EEPROM_REGULATORY
] & 0x7);
1902 rtlefuse
->eeprom_regulatory
=
1903 (hwinfo
[EEPROM_REGULATORY
] & 0x1);
1905 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1906 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1908 for (i
= 0; i
< 14; i
++)
1909 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1910 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
1911 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
1912 for (i
= 0; i
< 14; i
++)
1913 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1914 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
1915 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
1916 for (i
= 0; i
< 14; i
++)
1917 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1918 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
1919 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
1920 for (i
= 0; i
< 14; i
++)
1921 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1922 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
1923 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
1925 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1926 "TxPwrSafetyFlag = %d\n", rtlefuse
->txpwr_safetyflag
);
1928 /* Read RF-indication and Tx Power gain
1929 * index diff of legacy to HT OFDM rate. */
1930 tempval
= hwinfo
[EEPROM_RFIND_POWERDIFF
] & 0xff;
1931 rtlefuse
->eeprom_txpowerdiff
= tempval
;
1932 rtlefuse
->legacy_httxpowerdiff
=
1933 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][0];
1935 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1936 "TxPowerDiff = %#x\n", rtlefuse
->eeprom_txpowerdiff
);
1938 /* Get TSSI value for each path. */
1939 usvalue
= *(u16
*)&hwinfo
[EEPROM_TSSI_A
];
1940 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = (u8
)((usvalue
& 0xff00) >> 8);
1941 usvalue
= hwinfo
[EEPROM_TSSI_B
];
1942 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = (u8
)(usvalue
& 0xff);
1944 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1945 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
1946 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
1948 /* Read antenna tx power offset of B/C/D to A from EEPROM */
1949 /* and read ThermalMeter from EEPROM */
1950 tempval
= hwinfo
[EEPROM_THERMALMETER
];
1951 rtlefuse
->eeprom_thermalmeter
= tempval
;
1952 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1953 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1955 /* ThermalMeter, BIT(0)~3 for RFIC1, BIT(4)~7 for RFIC2 */
1956 rtlefuse
->thermalmeter
[0] = (rtlefuse
->eeprom_thermalmeter
& 0x1f);
1957 rtlefuse
->tssi_13dbm
= rtlefuse
->eeprom_thermalmeter
* 100;
1959 /* Read CrystalCap from EEPROM */
1960 tempval
= hwinfo
[EEPROM_CRYSTALCAP
] >> 4;
1961 rtlefuse
->eeprom_crystalcap
= tempval
;
1962 /* CrystalCap, BIT(12)~15 */
1963 rtlefuse
->crystalcap
= rtlefuse
->eeprom_crystalcap
;
1965 /* Read IC Version && Channel Plan */
1966 /* Version ID, Channel plan */
1967 rtlefuse
->eeprom_channelplan
= hwinfo
[EEPROM_CHANNELPLAN
];
1968 rtlefuse
->txpwr_fromeprom
= true;
1969 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1970 "EEPROM ChannelPlan = 0x%4x\n", rtlefuse
->eeprom_channelplan
);
1972 /* Read Customer ID or Board Type!!! */
1973 tempval
= hwinfo
[EEPROM_BOARDTYPE
];
1974 /* Change RF type definition */
1976 rtlphy
->rf_type
= RF_2T2R
;
1977 else if (tempval
== 1)
1978 rtlphy
->rf_type
= RF_1T2R
;
1979 else if (tempval
== 2)
1980 rtlphy
->rf_type
= RF_1T2R
;
1981 else if (tempval
== 3)
1982 rtlphy
->rf_type
= RF_1T1R
;
1984 /* 1T2R but 1SS (1x1 receive combining) */
1985 rtlefuse
->b1x1_recvcombine
= false;
1986 if (rtlphy
->rf_type
== RF_1T2R
) {
1987 tempval
= rtl_read_byte(rtlpriv
, 0x07);
1988 if (!(tempval
& BIT(0))) {
1989 rtlefuse
->b1x1_recvcombine
= true;
1990 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1991 "RF_TYPE=1T2R but only 1SS\n");
1994 rtlefuse
->b1ss_support
= rtlefuse
->b1x1_recvcombine
;
1995 rtlefuse
->eeprom_oemid
= *&hwinfo
[EEPROM_CUSTOMID
];
1997 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "EEPROM Customer ID: 0x%2x",
1998 rtlefuse
->eeprom_oemid
);
2000 /* set channel paln to world wide 13 */
2001 rtlefuse
->channel_plan
= COUNTRY_CODE_WORLD_WIDE_13
;
2004 void rtl92se_read_eeprom_info(struct ieee80211_hw
*hw
)
2006 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2007 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2010 tmp_u1b
= rtl_read_byte(rtlpriv
, EPROM_CMD
);
2012 if (tmp_u1b
& BIT(4)) {
2013 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
2014 rtlefuse
->epromtype
= EEPROM_93C46
;
2016 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
2017 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
2020 if (tmp_u1b
& BIT(5)) {
2021 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
2022 rtlefuse
->autoload_failflag
= false;
2023 _rtl92se_read_adapter_info(hw
);
2025 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Autoload ERR!!\n");
2026 rtlefuse
->autoload_failflag
= true;
2030 static void rtl92se_update_hal_rate_table(struct ieee80211_hw
*hw
,
2031 struct ieee80211_sta
*sta
)
2033 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2034 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2035 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2036 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2039 u8 nmode
= mac
->ht_enable
;
2040 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2041 u16 shortgi_rate
= 0;
2042 u32 tmp_ratr_value
= 0;
2043 u8 curtxbw_40mhz
= mac
->bw_40
;
2044 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2046 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2048 enum wireless_mode wirelessmode
= mac
->mode
;
2050 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2051 ratr_value
= sta
->supp_rates
[1] << 4;
2053 ratr_value
= sta
->supp_rates
[0];
2054 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2056 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2057 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2058 switch (wirelessmode
) {
2059 case WIRELESS_MODE_B
:
2060 ratr_value
&= 0x0000000D;
2062 case WIRELESS_MODE_G
:
2063 ratr_value
&= 0x00000FF5;
2065 case WIRELESS_MODE_N_24G
:
2066 case WIRELESS_MODE_N_5G
:
2068 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2069 ratr_value
&= 0x0007F005;
2073 if (get_rf_type(rtlphy
) == RF_1T2R
||
2074 get_rf_type(rtlphy
) == RF_1T1R
) {
2076 ratr_mask
= 0x000ff015;
2078 ratr_mask
= 0x000ff005;
2081 ratr_mask
= 0x0f0ff015;
2083 ratr_mask
= 0x0f0ff005;
2086 ratr_value
&= ratr_mask
;
2090 if (rtlphy
->rf_type
== RF_1T2R
)
2091 ratr_value
&= 0x000ff0ff;
2093 ratr_value
&= 0x0f0ff0ff;
2098 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2099 ratr_value
&= 0x0FFFFFFF;
2100 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2101 ratr_value
&= 0x0FFFFFF0;
2103 if (nmode
&& ((curtxbw_40mhz
&&
2104 curshortgi_40mhz
) || (!curtxbw_40mhz
&&
2105 curshortgi_20mhz
))) {
2107 ratr_value
|= 0x10000000;
2108 tmp_ratr_value
= (ratr_value
>> 12);
2110 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2111 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2115 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2116 (shortgi_rate
<< 4) | (shortgi_rate
);
2118 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2121 rtl_write_dword(rtlpriv
, ARFR0
+ ratr_index
* 4, ratr_value
);
2122 if (ratr_value
& 0xfffff000)
2123 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_N
);
2125 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_RA_REFRESH_BG
);
2127 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, "%x\n",
2128 rtl_read_dword(rtlpriv
, ARFR0
));
2131 static void rtl92se_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2132 struct ieee80211_sta
*sta
,
2135 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2136 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2137 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2138 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2139 struct rtl_sta_info
*sta_entry
= NULL
;
2142 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
2143 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2145 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2147 enum wireless_mode wirelessmode
= 0;
2148 bool shortgi
= false;
2150 u8 shortgi_rate
= 0;
2153 bool bmulticast
= false;
2155 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2157 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
2158 wirelessmode
= sta_entry
->wireless_mode
;
2159 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
2160 curtxbw_40mhz
= mac
->bw_40
;
2161 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2162 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2163 macid
= sta
->aid
+ 1;
2165 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2166 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2168 ratr_bitmap
= sta
->supp_rates
[0];
2169 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2170 ratr_bitmap
= 0xfff;
2171 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2172 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2173 switch (wirelessmode
) {
2174 case WIRELESS_MODE_B
:
2175 band
|= WIRELESS_11B
;
2176 ratr_index
= RATR_INX_WIRELESS_B
;
2177 if (ratr_bitmap
& 0x0000000c)
2178 ratr_bitmap
&= 0x0000000d;
2180 ratr_bitmap
&= 0x0000000f;
2182 case WIRELESS_MODE_G
:
2183 band
|= (WIRELESS_11G
| WIRELESS_11B
);
2184 ratr_index
= RATR_INX_WIRELESS_GB
;
2186 if (rssi_level
== 1)
2187 ratr_bitmap
&= 0x00000f00;
2188 else if (rssi_level
== 2)
2189 ratr_bitmap
&= 0x00000ff0;
2191 ratr_bitmap
&= 0x00000ff5;
2193 case WIRELESS_MODE_A
:
2194 band
|= WIRELESS_11A
;
2195 ratr_index
= RATR_INX_WIRELESS_A
;
2196 ratr_bitmap
&= 0x00000ff0;
2198 case WIRELESS_MODE_N_24G
:
2199 case WIRELESS_MODE_N_5G
:
2200 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2201 ratr_index
= RATR_INX_WIRELESS_NGB
;
2203 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2204 if (rssi_level
== 1)
2205 ratr_bitmap
&= 0x00070000;
2206 else if (rssi_level
== 2)
2207 ratr_bitmap
&= 0x0007f000;
2209 ratr_bitmap
&= 0x0007f005;
2211 if (rtlphy
->rf_type
== RF_1T2R
||
2212 rtlphy
->rf_type
== RF_1T1R
) {
2213 if (rssi_level
== 1) {
2214 ratr_bitmap
&= 0x000f0000;
2215 } else if (rssi_level
== 3) {
2216 ratr_bitmap
&= 0x000fc000;
2217 } else if (rssi_level
== 5) {
2218 ratr_bitmap
&= 0x000ff000;
2221 ratr_bitmap
&= 0x000ff015;
2223 ratr_bitmap
&= 0x000ff005;
2226 if (rssi_level
== 1) {
2227 ratr_bitmap
&= 0x0f8f0000;
2228 } else if (rssi_level
== 3) {
2229 ratr_bitmap
&= 0x0f8fc000;
2230 } else if (rssi_level
== 5) {
2231 ratr_bitmap
&= 0x0f8ff000;
2234 ratr_bitmap
&= 0x0f8ff015;
2236 ratr_bitmap
&= 0x0f8ff005;
2241 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2242 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2245 else if (macid
== 1)
2250 band
|= (WIRELESS_11N
| WIRELESS_11G
| WIRELESS_11B
);
2251 ratr_index
= RATR_INX_WIRELESS_NGB
;
2253 if (rtlphy
->rf_type
== RF_1T2R
)
2254 ratr_bitmap
&= 0x000ff0ff;
2256 ratr_bitmap
&= 0x0f8ff0ff;
2259 sta_entry
->ratr_index
= ratr_index
;
2261 if (rtlpriv
->rtlhal
.version
>= VERSION_8192S_BCUT
)
2262 ratr_bitmap
&= 0x0FFFFFFF;
2263 else if (rtlpriv
->rtlhal
.version
== VERSION_8192S_ACUT
)
2264 ratr_bitmap
&= 0x0FFFFFF0;
2267 ratr_bitmap
|= 0x10000000;
2268 /* Get MAX MCS available. */
2269 ratr_value
= (ratr_bitmap
>> 12);
2270 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2271 if ((1 << shortgi_rate
) & ratr_value
)
2275 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2276 (shortgi_rate
<< 4) | (shortgi_rate
);
2277 rtl_write_byte(rtlpriv
, SG_RATE
, shortgi_rate
);
2280 mask
|= (bmulticast
? 1 : 0) << 9 | (macid
& 0x1f) << 4 | (band
& 0xf);
2282 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_TRACE
, "mask = %x, bitmap = %x\n",
2284 rtl_write_dword(rtlpriv
, 0x2c4, ratr_bitmap
);
2285 rtl_write_dword(rtlpriv
, WFM5
, (FW_RA_UPDATE_MASK
| (mask
<< 8)));
2288 sta_entry
->ratr_index
= ratr_index
;
2291 void rtl92se_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2292 struct ieee80211_sta
*sta
, u8 rssi_level
)
2294 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2296 if (rtlpriv
->dm
.useramask
)
2297 rtl92se_update_hal_rate_mask(hw
, sta
, rssi_level
);
2299 rtl92se_update_hal_rate_table(hw
, sta
);
2302 void rtl92se_update_channel_access_setting(struct ieee80211_hw
*hw
)
2304 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2305 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2308 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2310 sifs_timer
= 0x0e0e;
2311 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2315 /* this ifunction is for RFKILL, it's different with windows,
2316 * because UI will disable wireless when GPIO Radio Off.
2317 * And here we not check or Disable/Enable ASPM like windows*/
2318 bool rtl92se_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2320 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2321 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2322 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2323 enum rf_pwrstate rfpwr_toset
/*, cur_rfstate */;
2324 unsigned long flag
= 0;
2325 bool actuallyset
= false;
2326 bool turnonbypowerdomain
= false;
2328 /* just 8191se can check gpio before firstup, 92c/92d have fixed it */
2329 if ((rtlpci
->up_first_time
== 1) || (rtlpci
->being_init_adapter
))
2332 if (ppsc
->swrf_processing
)
2335 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2336 if (ppsc
->rfchange_inprogress
) {
2337 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2340 ppsc
->rfchange_inprogress
= true;
2341 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2344 /* cur_rfstate = ppsc->rfpwr_state;*/
2346 /* because after _rtl92s_phy_set_rfhalt, all power
2347 * closed, so we must open some power for GPIO check,
2348 * or we will always check GPIO RFOFF here,
2349 * And we should close power after GPIO check */
2350 if (RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
)) {
2351 _rtl92se_power_domain_init(hw
);
2352 turnonbypowerdomain
= true;
2355 rfpwr_toset
= _rtl92se_rf_onoff_detect(hw
);
2357 if ((ppsc
->hwradiooff
) && (rfpwr_toset
== ERFON
)) {
2358 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2359 "RFKILL-HW Radio ON, RF ON\n");
2361 rfpwr_toset
= ERFON
;
2362 ppsc
->hwradiooff
= false;
2364 } else if ((!ppsc
->hwradiooff
) && (rfpwr_toset
== ERFOFF
)) {
2365 RT_TRACE(rtlpriv
, COMP_RF
,
2366 DBG_DMESG
, "RFKILL-HW Radio OFF, RF OFF\n");
2368 rfpwr_toset
= ERFOFF
;
2369 ppsc
->hwradiooff
= true;
2374 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2375 ppsc
->rfchange_inprogress
= false;
2376 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2378 /* this not include ifconfig wlan0 down case */
2379 /* } else if (rfpwr_toset == ERFOFF || cur_rfstate == ERFOFF) { */
2381 /* because power_domain_init may be happen when
2382 * _rtl92s_phy_set_rfhalt, this will open some powers
2383 * and cause current increasing about 40 mA for ips,
2384 * rfoff and ifconfig down, so we set
2385 * _rtl92s_phy_set_rfhalt again here */
2386 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
&&
2387 turnonbypowerdomain
) {
2388 _rtl92s_phy_set_rfhalt(hw
);
2389 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2392 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2393 ppsc
->rfchange_inprogress
= false;
2394 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2398 return !ppsc
->hwradiooff
;
2402 /* Is_wepkey just used for WEP used as group & pairwise key
2403 * if pairwise is AES ang group is WEP Is_wepkey == false.*/
2404 void rtl92se_set_key(struct ieee80211_hw
*hw
, u32 key_index
, u8
*p_macaddr
,
2405 bool is_group
, u8 enc_algo
, bool is_wepkey
, bool clear_all
)
2407 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2408 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2409 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2410 u8
*macaddr
= p_macaddr
;
2413 bool is_pairwise
= false;
2415 static u8 cam_const_addr
[4][6] = {
2416 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2417 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2418 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2419 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2421 static u8 cam_const_broad
[] = {
2422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2428 u8 clear_number
= 5;
2430 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2432 for (idx
= 0; idx
< clear_number
; idx
++) {
2433 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2434 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2437 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2439 rtlpriv
->sec
.key_len
[idx
] = 0;
2445 case WEP40_ENCRYPTION
:
2446 enc_algo
= CAM_WEP40
;
2448 case WEP104_ENCRYPTION
:
2449 enc_algo
= CAM_WEP104
;
2451 case TKIP_ENCRYPTION
:
2452 enc_algo
= CAM_TKIP
;
2454 case AESCCMP_ENCRYPTION
:
2458 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2459 "switch case not processed\n");
2460 enc_algo
= CAM_TKIP
;
2464 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2465 macaddr
= cam_const_addr
[key_index
];
2466 entry_id
= key_index
;
2469 macaddr
= cam_const_broad
;
2470 entry_id
= key_index
;
2472 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2473 entry_id
= rtl_cam_get_free_entry(hw
,
2475 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2477 COMP_SEC
, DBG_EMERG
,
2478 "Can not find free hw security cam entry\n");
2482 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2485 key_index
= PAIRWISE_KEYIDX
;
2490 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2491 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2492 "delete one entry, entry_id is %d\n",
2494 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2495 rtl_cam_del_entry(hw
, p_macaddr
);
2496 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2498 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2501 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2502 "set Pairwise key\n");
2504 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2506 CAM_CONFIG_NO_USEDK
,
2507 rtlpriv
->sec
.key_buf
[key_index
]);
2509 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2512 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2513 rtl_cam_add_one_entry(hw
,
2516 CAM_PAIRWISE_KEY_POSITION
,
2517 enc_algo
, CAM_CONFIG_NO_USEDK
,
2518 rtlpriv
->sec
.key_buf
[entry_id
]);
2521 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2523 CAM_CONFIG_NO_USEDK
,
2524 rtlpriv
->sec
.key_buf
[entry_id
]);
2531 void rtl92se_suspend(struct ieee80211_hw
*hw
)
2533 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2535 rtlpci
->up_first_time
= true;
2538 void rtl92se_resume(struct ieee80211_hw
*hw
)
2540 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2543 pci_read_config_dword(rtlpci
->pdev
, 0x40, &val
);
2544 if ((val
& 0x0000ff00) != 0)
2545 pci_write_config_dword(rtlpci
->pdev
, 0x40,
2549 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
2550 void rtl92se_allow_all_destaddr(struct ieee80211_hw
*hw
,
2551 bool allow_all_da
, bool write_into_reg
)
2553 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2554 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2556 if (allow_all_da
) /* Set BIT0 */
2557 rtlpci
->receive_config
|= RCR_AAP
;
2558 else /* Clear BIT0 */
2559 rtlpci
->receive_config
&= ~RCR_AAP
;
2562 rtl_write_dword(rtlpriv
, RCR
, rtlpci
->receive_config
);
2564 RT_TRACE(rtlpriv
, COMP_TURBO
| COMP_INIT
, DBG_LOUD
,
2565 "receive_config=0x%08X, write_into_reg=%d\n",
2566 rtlpci
->receive_config
, write_into_reg
);