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 *****************************************************************************/
44 #include "pwrseqcmd.h"
48 static void _rtl8723ae_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
49 u8 set_bits
, u8 clear_bits
)
51 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
52 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
54 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
55 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
57 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
60 static void _rtl8723ae_stop_tx_beacon(struct ieee80211_hw
*hw
)
62 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
65 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
66 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
67 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
68 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
69 tmp1byte
&= ~(BIT(0));
70 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
73 static void _rtl8723ae_resume_tx_beacon(struct ieee80211_hw
*hw
)
75 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
78 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
79 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
80 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
81 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
83 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
86 static void _rtl8723ae_enable_bcn_sufunc(struct ieee80211_hw
*hw
)
88 _rtl8723ae_set_bcn_ctrl_reg(hw
, 0, BIT(1));
91 static void _rtl8723ae_disable_bcn_sufunc(struct ieee80211_hw
*hw
)
93 _rtl8723ae_set_bcn_ctrl_reg(hw
, BIT(1), 0);
96 void rtl8723ae_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
98 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
99 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
100 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
104 *((u32
*) (val
)) = rtlpci
->receive_config
;
106 case HW_VAR_RF_STATE
:
107 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
109 case HW_VAR_FWLPS_RF_ON
:{
110 enum rf_pwrstate rfState
;
113 rtlpriv
->cfg
->ops
->get_hw_reg(hw
,
116 if (rfState
== ERFOFF
) {
117 *((bool *) (val
)) = true;
119 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
120 val_rcr
&= 0x00070000;
122 *((bool *) (val
)) = false;
124 *((bool *) (val
)) = true;
127 case HW_VAR_FW_PSMODE_STATUS
:
128 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
130 case HW_VAR_CORRECT_TSF
:{
132 u32
*ptsf_low
= (u32
*)&tsf
;
133 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
135 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
136 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
138 *((u64
*) (val
)) = tsf
;
142 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
143 "switch case not process\n");
148 void rtl8723ae_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
150 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
151 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
152 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
153 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
154 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
155 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
159 case HW_VAR_ETHER_ADDR
:
160 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
161 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
165 case HW_VAR_BASIC_RATE
:{
166 u16 rate_cfg
= ((u16
*) val
)[0];
168 rate_cfg
= rate_cfg
& 0x15f;
170 rtl_write_byte(rtlpriv
, REG_RRSR
, rate_cfg
& 0xff);
171 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
172 (rate_cfg
>> 8) & 0xff);
173 while (rate_cfg
> 0x1) {
174 rate_cfg
= (rate_cfg
>> 1);
177 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
181 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
182 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
187 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
188 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
190 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
191 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
194 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
197 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
200 case HW_VAR_SLOT_TIME
:{
203 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
204 "HW_VAR_SLOT_TIME %x\n", val
[0]);
206 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
208 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
209 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
214 case HW_VAR_ACK_PREAMBLE
:{
216 u8 short_preamble
= (bool) (*(u8
*) val
);
217 reg_tmp
= (mac
->cur_40_prime_sc
) << 5;
221 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_tmp
);
223 case HW_VAR_AMPDU_MIN_SPACE
:{
224 u8 min_spacing_to_set
;
227 min_spacing_to_set
= *((u8
*) val
);
228 if (min_spacing_to_set
<= 7) {
231 if (min_spacing_to_set
< sec_min_space
)
232 min_spacing_to_set
= sec_min_space
;
234 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
238 *val
= min_spacing_to_set
;
240 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
241 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
244 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
248 case HW_VAR_SHORTGI_DENSITY
:{
251 density_to_set
= *((u8
*) val
);
252 mac
->min_space_cfg
|= (density_to_set
<< 3);
254 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
255 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
258 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
262 case HW_VAR_AMPDU_FACTOR
:{
263 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
264 u8 regtoset_bt
[4] = {0x31, 0x74, 0x42, 0x97};
266 u8
*p_regtoset
= NULL
;
269 if ((pcipriv
->bt_coexist
.bt_coexistence
) &&
270 (pcipriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
))
271 p_regtoset
= regtoset_bt
;
273 p_regtoset
= regtoset_normal
;
275 factor_toset
= *((u8
*) val
);
276 if (factor_toset
<= 3) {
277 factor_toset
= (1 << (factor_toset
+ 2));
278 if (factor_toset
> 0xf)
281 for (index
= 0; index
< 4; index
++) {
282 if ((p_regtoset
[index
] & 0xf0) >
285 (p_regtoset
[index
] & 0x0f) |
288 if ((p_regtoset
[index
] & 0x0f) >
291 (p_regtoset
[index
] & 0xf0) |
294 rtl_write_byte(rtlpriv
,
295 (REG_AGGLEN_LMT
+ index
),
300 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
301 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
305 case HW_VAR_AC_PARAM
:{
306 u8 e_aci
= *((u8
*) val
);
307 rtl8723ae_dm_init_edca_turbo(hw
);
309 if (rtlpci
->acm_method
!= eAcmWay2_SW
)
310 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
314 case HW_VAR_ACM_CTRL
:{
315 u8 e_aci
= *((u8
*) val
);
316 union aci_aifsn
*p_aci_aifsn
=
317 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
318 u8 acm
= p_aci_aifsn
->f
.acm
;
319 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
321 acm_ctrl
|= ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
326 acm_ctrl
|= AcmHw_BeqEn
;
329 acm_ctrl
|= AcmHw_ViqEn
;
332 acm_ctrl
|= AcmHw_VoqEn
;
335 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
336 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
343 acm_ctrl
&= (~AcmHw_BeqEn
);
346 acm_ctrl
&= (~AcmHw_ViqEn
);
349 acm_ctrl
&= (~AcmHw_BeqEn
);
352 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
353 "switch case not processed\n");
358 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
359 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
361 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
364 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*) (val
))[0]);
365 rtlpci
->receive_config
= ((u32
*) (val
))[0];
367 case HW_VAR_RETRY_LIMIT
:{
368 u8 retry_limit
= ((u8
*) (val
))[0];
370 rtl_write_word(rtlpriv
, REG_RL
,
371 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
372 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
374 case HW_VAR_DUAL_TSF_RST
:
375 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
377 case HW_VAR_EFUSE_BYTES
:
378 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
380 case HW_VAR_EFUSE_USAGE
:
381 rtlefuse
->efuse_usedpercentage
= *((u8
*) val
);
384 rtl8723ae_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
386 case HW_VAR_WPA_CONFIG
:
387 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*) val
));
389 case HW_VAR_SET_RPWM
:{
392 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
395 if (rpwm_val
& BIT(7)) {
396 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
399 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
400 ((*(u8
*) val
) | BIT(7)));
404 case HW_VAR_H2C_FW_PWRMODE
:{
405 u8 psmode
= (*(u8
*) val
);
407 if (psmode
!= FW_PS_ACTIVE_MODE
)
408 rtl8723ae_dm_rf_saving(hw
, true);
410 rtl8723ae_set_fw_pwrmode_cmd(hw
, (*(u8
*) val
));
412 case HW_VAR_FW_PSMODE_STATUS
:
413 ppsc
->fw_current_inpsmode
= *((bool *) val
);
415 case HW_VAR_H2C_FW_JOINBSSRPT
:{
416 u8 mstatus
= (*(u8
*) val
);
417 u8 tmp_regcr
, tmp_reg422
;
418 bool recover
= false;
420 if (mstatus
== RT_MEDIA_CONNECT
) {
421 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
423 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
424 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
425 (tmp_regcr
| BIT(0)));
427 _rtl8723ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
428 _rtl8723ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
430 tmp_reg422
= rtl_read_byte(rtlpriv
,
431 REG_FWHW_TXQ_CTRL
+ 2);
432 if (tmp_reg422
& BIT(6))
434 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
435 tmp_reg422
& (~BIT(6)));
437 rtl8723ae_set_fw_rsvdpagepkt(hw
, 0);
439 _rtl8723ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
440 _rtl8723ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
443 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
446 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
447 (tmp_regcr
& ~(BIT(0))));
449 rtl8723ae_set_fw_joinbss_report_cmd(hw
, (*(u8
*) val
));
452 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
453 rtl8723ae_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
457 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
459 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
462 case HW_VAR_CORRECT_TSF
:{
463 u8 btype_ibss
= ((u8
*) (val
))[0];
465 if (btype_ibss
== true)
466 _rtl8723ae_stop_tx_beacon(hw
);
468 _rtl8723ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
470 rtl_write_dword(rtlpriv
, REG_TSFTR
,
471 (u32
) (mac
->tsf
& 0xffffffff));
472 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
473 (u32
) ((mac
->tsf
>> 32) & 0xffffffff));
475 _rtl8723ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
477 if (btype_ibss
== true)
478 _rtl8723ae_resume_tx_beacon(hw
);
480 case HW_VAR_FW_LPS_ACTION
: {
481 bool enter_fwlps
= *((bool *)val
);
482 u8 rpwm_val
, fw_pwrmode
;
483 bool fw_current_inps
;
486 rpwm_val
= 0x02; /* RF off */
487 fw_current_inps
= true;
488 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
489 HW_VAR_FW_PSMODE_STATUS
,
490 (u8
*)(&fw_current_inps
));
491 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
492 HW_VAR_H2C_FW_PWRMODE
,
493 (u8
*)(&ppsc
->fwctrl_psmode
));
495 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
499 rpwm_val
= 0x0C; /* RF on */
500 fw_pwrmode
= FW_PS_ACTIVE_MODE
;
501 fw_current_inps
= false;
502 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
504 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
505 HW_VAR_H2C_FW_PWRMODE
,
506 (u8
*)(&fw_pwrmode
));
508 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
509 HW_VAR_FW_PSMODE_STATUS
,
510 (u8
*)(&fw_current_inps
));
514 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
515 "switch case not processed\n");
520 static bool _rtl8723ae_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
522 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
525 u32 value
= _LLT_INIT_ADDR(address
) |
526 _LLT_INIT_DATA(data
) | _LLT_OP(_LLT_WRITE_ACCESS
);
528 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
531 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
532 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
535 if (count
> POLLING_LLT_THRESHOLD
) {
536 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
537 "Failed to polling write LLT done at address %d!\n",
547 static bool _rtl8723ae_llt_table_init(struct ieee80211_hw
*hw
)
549 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
559 rtl_write_byte(rtlpriv
, REG_CR
, 0x8B);
561 rtl_write_word(rtlpriv
, REG_RQPN_NPQ
, 0x0000);
563 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80ac1c29);
564 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x03);
566 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
, (0x27FF0000 | txpktbuf_bndy
));
567 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
569 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
570 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
572 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
573 rtl_write_byte(rtlpriv
, REG_PBP
, 0x11);
574 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
576 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
577 status
= _rtl8723ae_llt_write(hw
, i
, i
+ 1);
582 status
= _rtl8723ae_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
586 for (i
= txpktbuf_bndy
; i
< maxPage
; i
++) {
587 status
= _rtl8723ae_llt_write(hw
, i
, (i
+ 1));
592 status
= _rtl8723ae_llt_write(hw
, maxPage
, txpktbuf_bndy
);
596 rtl_write_byte(rtlpriv
, REG_CR
, 0xff);
597 ubyte
= rtl_read_byte(rtlpriv
, REG_RQPN
+ 3);
598 rtl_write_byte(rtlpriv
, REG_RQPN
+ 3, ubyte
| BIT(7));
603 static void _rtl8723ae_gen_refresh_led_state(struct ieee80211_hw
*hw
)
605 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
606 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
607 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
608 struct rtl_led
*pLed0
= &(pcipriv
->ledctl
.sw_led0
);
610 if (rtlpriv
->rtlhal
.up_first_time
)
613 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
614 rtl8723ae_sw_led_on(hw
, pLed0
);
615 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
616 rtl8723ae_sw_led_on(hw
, pLed0
);
618 rtl8723ae_sw_led_off(hw
, pLed0
);
621 static bool _rtl8712e_init_mac(struct ieee80211_hw
*hw
)
623 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
624 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
625 unsigned char bytetmp
;
626 unsigned short wordtmp
;
629 bool mac_func_enable
;
631 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
632 bytetmp
= rtl_read_byte(rtlpriv
, REG_CR
);
634 mac_func_enable
= true;
636 mac_func_enable
= false;
639 /* HW Power on sequence */
640 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
641 PWR_INTF_PCI_MSK
, Rtl8723_NIC_ENABLE_FLOW
))
644 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2);
645 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2, bytetmp
| BIT(4));
647 /* eMAC time out function enable, 0x369[7]=1 */
648 bytetmp
= rtl_read_byte(rtlpriv
, 0x369);
649 rtl_write_byte(rtlpriv
, 0x369, bytetmp
| BIT(7));
651 /* ePHY reg 0x1e bit[4]=1 using MDIO interface,
652 * we should do this before Enabling ASPM backdoor.
655 rtl_write_word(rtlpriv
, 0x358, 0x5e);
657 rtl_write_word(rtlpriv
, 0x356, 0xc280);
658 rtl_write_word(rtlpriv
, 0x354, 0xc290);
659 rtl_write_word(rtlpriv
, 0x358, 0x3e);
661 rtl_write_word(rtlpriv
, 0x358, 0x5e);
663 tmpu2b
= rtl_read_word(rtlpriv
, 0x356);
665 } while (tmpu2b
!= 0xc290 && retry
< 100);
668 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
669 "InitMAC(): ePHY configure fail!!!\n");
673 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
674 rtl_write_word(rtlpriv
, REG_CR
+ 1, 0x06);
676 if (!mac_func_enable
) {
677 if (_rtl8723ae_llt_table_init(hw
) == false)
681 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
682 rtl_write_byte(rtlpriv
, REG_HISRE
, 0xff);
684 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, 0x27ff);
686 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
) & 0xf;
688 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
690 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 1, 0x1F);
691 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
692 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xFFFF);
693 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
695 rtl_write_byte(rtlpriv
, 0x4d0, 0x0);
697 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
698 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
700 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
701 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
703 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
704 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
705 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
706 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
707 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
708 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
709 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
710 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
711 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
712 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
714 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
715 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
718 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3, 0x74);
720 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
722 bytetmp
= rtl_read_byte(rtlpriv
, REG_APSD_CTRL
);
723 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, bytetmp
& ~BIT(6));
726 bytetmp
= rtl_read_byte(rtlpriv
, REG_APSD_CTRL
);
727 } while ((retry
< 200) && (bytetmp
& BIT(7)));
729 _rtl8723ae_gen_refresh_led_state(hw
);
731 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
736 static void _rtl8723ae_hw_configure(struct ieee80211_hw
*hw
)
738 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
739 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
740 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
744 reg_bw_opmode
= BW_OPMODE_20MHZ
;
745 reg_prsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
747 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
, 0x8);
749 rtl_write_byte(rtlpriv
, REG_BWOPMODE
, reg_bw_opmode
);
751 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_prsr
);
753 rtl_write_byte(rtlpriv
, REG_SLOT
, 0x09);
755 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
, 0x0);
757 rtl_write_word(rtlpriv
, REG_FWHW_TXQ_CTRL
, 0x1F80);
759 rtl_write_word(rtlpriv
, REG_RL
, 0x0707);
761 rtl_write_dword(rtlpriv
, REG_BAR_MODE_CTRL
, 0x02012802);
763 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
765 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x01000000);
766 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4, 0x07060504);
767 rtl_write_dword(rtlpriv
, REG_RARFRC
, 0x01000000);
768 rtl_write_dword(rtlpriv
, REG_RARFRC
+ 4, 0x07060504);
770 if ((pcipriv
->bt_coexist
.bt_coexistence
) &&
771 (pcipriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
))
772 rtl_write_dword(rtlpriv
, REG_AGGLEN_LMT
, 0x97427431);
774 rtl_write_dword(rtlpriv
, REG_AGGLEN_LMT
, 0xb972a841);
776 rtl_write_byte(rtlpriv
, REG_ATIMWND
, 0x2);
778 rtl_write_byte(rtlpriv
, REG_BCN_MAX_ERR
, 0xff);
780 rtlpci
->reg_bcn_ctrl_val
= 0x1f;
781 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, rtlpci
->reg_bcn_ctrl_val
);
783 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
785 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
787 rtl_write_byte(rtlpriv
, REG_PIFS
, 0x1C);
788 rtl_write_byte(rtlpriv
, REG_AGGR_BREAK_TIME
, 0x16);
790 if ((pcipriv
->bt_coexist
.bt_coexistence
) &&
791 (pcipriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
)) {
792 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0020);
793 rtl_write_word(rtlpriv
, REG_PROT_MODE_CTRL
, 0x0402);
795 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0020);
796 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0020);
799 if ((pcipriv
->bt_coexist
.bt_coexistence
) &&
800 (pcipriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
))
801 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x03086666);
803 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x086666);
805 rtl_write_byte(rtlpriv
, REG_ACKTO
, 0x40);
807 rtl_write_word(rtlpriv
, REG_SPEC_SIFS
, 0x1010);
808 rtl_write_word(rtlpriv
, REG_MAC_SPEC_SIFS
, 0x1010);
810 rtl_write_word(rtlpriv
, REG_SIFS_CTX
, 0x1010);
812 rtl_write_word(rtlpriv
, REG_SIFS_TRX
, 0x1010);
814 rtl_write_dword(rtlpriv
, REG_MAR
, 0xffffffff);
815 rtl_write_dword(rtlpriv
, REG_MAR
+ 4, 0xffffffff);
817 rtl_write_dword(rtlpriv
, 0x394, 0x1);
820 static void _rtl8723ae_enable_aspm_back_door(struct ieee80211_hw
*hw
)
822 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
823 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
825 rtl_write_byte(rtlpriv
, 0x34b, 0x93);
826 rtl_write_word(rtlpriv
, 0x350, 0x870c);
827 rtl_write_byte(rtlpriv
, 0x352, 0x1);
829 if (ppsc
->support_backdoor
)
830 rtl_write_byte(rtlpriv
, 0x349, 0x1b);
832 rtl_write_byte(rtlpriv
, 0x349, 0x03);
834 rtl_write_word(rtlpriv
, 0x350, 0x2718);
835 rtl_write_byte(rtlpriv
, 0x352, 0x1);
838 void rtl8723ae_enable_hw_security_config(struct ieee80211_hw
*hw
)
840 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
843 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
844 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
845 rtlpriv
->sec
.pairwise_enc_algorithm
,
846 rtlpriv
->sec
.group_enc_algorithm
);
848 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
849 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
850 "not open hw encryption\n");
854 sec_reg_value
= SCR_TxEncEnable
| SCR_RxDecEnable
;
856 if (rtlpriv
->sec
.use_defaultkey
) {
857 sec_reg_value
|= SCR_TxUseDK
;
858 sec_reg_value
|= SCR_RxUseDK
;
861 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
863 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
865 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
866 "The SECR-value %x\n", sec_reg_value
);
868 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
872 int rtl8723ae_hw_init(struct ieee80211_hw
*hw
)
874 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
875 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
876 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
877 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
878 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
879 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
880 bool rtstatus
= true;
884 rtlpriv
->rtlhal
.being_init_adapter
= true;
885 rtlpriv
->intf_ops
->disable_aspm(hw
);
886 rtstatus
= _rtl8712e_init_mac(hw
);
887 if (rtstatus
!= true) {
888 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Init MAC failed\n");
893 err
= rtl8723ae_download_fw(hw
);
895 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
896 "Failed to download FW. Init HW without FW now..\n");
898 rtlhal
->fw_ready
= false;
901 rtlhal
->fw_ready
= true;
904 rtlhal
->last_hmeboxnum
= 0;
905 rtl8723ae_phy_mac_config(hw
);
906 /* because the last function modifies RCR, we update
907 * rcr var here, or TP will be unstable as ther receive_config
908 * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
909 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
911 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, REG_RCR
);
912 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
913 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
915 rtl8723ae_phy_bb_config(hw
);
916 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
917 rtl8723ae_phy_rf_config(hw
);
918 if (IS_VENDOR_UMC_A_CUT(rtlhal
->version
)) {
919 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G1
, MASKDWORD
, 0x30255);
920 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G2
, MASKDWORD
, 0x50a00);
921 } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal
->version
)) {
922 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x0C, MASKDWORD
, 0x894AE);
923 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x0A, MASKDWORD
, 0x1AF31);
924 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_IPA
, MASKDWORD
, 0x8F425);
925 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_SYN_G2
, MASKDWORD
, 0x4F200);
926 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK1
, MASKDWORD
, 0x44053);
927 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RCK2
, MASKDWORD
, 0x80201);
929 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
930 RF_CHNLBW
, RFREG_OFFSET_MASK
);
931 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
932 RF_CHNLBW
, RFREG_OFFSET_MASK
);
933 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
934 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
935 rtl_set_bbreg(hw
, RFPGA0_ANALOGPARAMETER2
, BIT(10), 1);
936 _rtl8723ae_hw_configure(hw
);
937 rtl_cam_reset_all_entry(hw
);
938 rtl8723ae_enable_hw_security_config(hw
);
940 ppsc
->rfpwr_state
= ERFON
;
942 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
943 _rtl8723ae_enable_aspm_back_door(hw
);
944 rtlpriv
->intf_ops
->enable_aspm(hw
);
946 rtl8723ae_bt_hw_init(hw
);
948 if (ppsc
->rfpwr_state
== ERFON
) {
949 rtl8723ae_phy_set_rfpath_switch(hw
, 1);
950 if (rtlphy
->iqk_initialized
) {
951 rtl8723ae_phy_iq_calibrate(hw
, true);
953 rtl8723ae_phy_iq_calibrate(hw
, false);
954 rtlphy
->iqk_initialized
= true;
957 rtl8723ae_phy_lc_calibrate(hw
);
960 tmp_u1b
= efuse_read_1byte(hw
, 0x1FA);
961 if (!(tmp_u1b
& BIT(0))) {
962 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0F, 0x05);
963 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "PA BIAS path A\n");
966 if (!(tmp_u1b
& BIT(4))) {
967 tmp_u1b
= rtl_read_byte(rtlpriv
, 0x16) & 0x0F;
968 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x80);
970 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x90);
971 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
, "under 1.5V\n");
973 rtl8723ae_dm_init(hw
);
974 rtlpriv
->rtlhal
.being_init_adapter
= false;
978 static enum version_8723e
_rtl8723ae_read_chip_version(struct ieee80211_hw
*hw
)
980 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
981 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
982 enum version_8723e version
= 0x0000;
985 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
986 if (value32
& TRP_VAUX_EN
) {
987 version
= (enum version_8723e
)(version
|
988 ((value32
& VENDOR_ID
) ? CHIP_VENDOR_UMC
: 0));
989 /* RTL8723 with BT function. */
990 version
= (enum version_8723e
)(version
|
991 ((value32
& BT_FUNC
) ? CHIP_8723
: 0));
994 /* Normal mass production chip. */
995 version
= (enum version_8723e
) NORMAL_CHIP
;
996 version
= (enum version_8723e
)(version
|
997 ((value32
& VENDOR_ID
) ? CHIP_VENDOR_UMC
: 0));
998 /* RTL8723 with BT function. */
999 version
= (enum version_8723e
)(version
|
1000 ((value32
& BT_FUNC
) ? CHIP_8723
: 0));
1001 if (IS_CHIP_VENDOR_UMC(version
))
1002 version
= (enum version_8723e
)(version
|
1003 ((value32
& CHIP_VER_RTL_MASK
)));/* IC version (CUT) */
1004 if (IS_8723_SERIES(version
)) {
1005 value32
= rtl_read_dword(rtlpriv
, REG_GPIO_OUTSTS
);
1006 /* ROM code version */
1007 version
= (enum version_8723e
)(version
|
1008 ((value32
& RF_RL_ID
)>>20));
1012 if (IS_8723_SERIES(version
)) {
1013 value32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
1014 rtlphy
->polarity_ctl
= ((value32
& WL_HWPDN_SL
) ?
1015 RT_POLARITY_HIGH_ACT
:
1016 RT_POLARITY_LOW_ACT
);
1019 case VERSION_TEST_UMC_CHIP_8723
:
1020 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1021 "Chip Version ID: VERSION_TEST_UMC_CHIP_8723.\n");
1023 case VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT
:
1024 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1025 "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT.\n");
1027 case VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT
:
1028 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1029 "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT.\n");
1032 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1033 "Chip Version ID: Unknown. Bug?\n");
1037 if (IS_8723_SERIES(version
))
1038 rtlphy
->rf_type
= RF_1T1R
;
1040 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Chip RF Type: %s\n",
1041 (rtlphy
->rf_type
== RF_2T2R
) ? "RF_2T2R" : "RF_1T1R");
1046 static int _rtl8723ae_set_media_status(struct ieee80211_hw
*hw
,
1047 enum nl80211_iftype type
)
1049 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1050 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & 0xfc;
1051 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1053 rtl_write_dword(rtlpriv
, REG_BCN_CTRL
, 0);
1054 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_LOUD
,
1055 "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
1057 if (type
== NL80211_IFTYPE_UNSPECIFIED
||
1058 type
== NL80211_IFTYPE_STATION
) {
1059 _rtl8723ae_stop_tx_beacon(hw
);
1060 _rtl8723ae_enable_bcn_sufunc(hw
);
1061 } else if (type
== NL80211_IFTYPE_ADHOC
||
1062 type
== NL80211_IFTYPE_AP
) {
1063 _rtl8723ae_resume_tx_beacon(hw
);
1064 _rtl8723ae_disable_bcn_sufunc(hw
);
1066 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1067 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1072 case NL80211_IFTYPE_UNSPECIFIED
:
1073 bt_msr
|= MSR_NOLINK
;
1074 ledaction
= LED_CTL_LINK
;
1075 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1076 "Set Network type to NO LINK!\n");
1078 case NL80211_IFTYPE_ADHOC
:
1079 bt_msr
|= MSR_ADHOC
;
1080 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1081 "Set Network type to Ad Hoc!\n");
1083 case NL80211_IFTYPE_STATION
:
1084 bt_msr
|= MSR_INFRA
;
1085 ledaction
= LED_CTL_LINK
;
1086 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1087 "Set Network type to STA!\n");
1089 case NL80211_IFTYPE_AP
:
1091 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1092 "Set Network type to AP!\n");
1095 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1096 "Network type %d not supported!\n",
1103 rtl_write_byte(rtlpriv
, (MSR
), bt_msr
);
1104 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1105 if ((bt_msr
& 0x03) == MSR_AP
)
1106 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1108 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1112 void rtl8723ae_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1114 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1115 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1116 u32 reg_rcr
= rtlpci
->receive_config
;
1118 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1121 if (check_bssid
== true) {
1122 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1123 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1125 _rtl8723ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1126 } else if (check_bssid
== false) {
1127 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1128 _rtl8723ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1129 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1130 HW_VAR_RCR
, (u8
*) (®_rcr
));
1134 int rtl8723ae_set_network_type(struct ieee80211_hw
*hw
,
1135 enum nl80211_iftype type
)
1137 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1139 if (_rtl8723ae_set_media_status(hw
, type
))
1142 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1143 if (type
!= NL80211_IFTYPE_AP
)
1144 rtl8723ae_set_check_bssid(hw
, true);
1146 rtl8723ae_set_check_bssid(hw
, false);
1151 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1152 void rtl8723ae_set_qos(struct ieee80211_hw
*hw
, int aci
)
1154 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1156 rtl8723ae_dm_init_edca_turbo(hw
);
1159 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1162 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4ac_param); */
1165 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1168 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1171 RT_ASSERT(false, "invalid aci: %d !\n", aci
);
1176 void rtl8723ae_enable_interrupt(struct ieee80211_hw
*hw
)
1178 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1179 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1181 rtl_write_dword(rtlpriv
, 0x3a8, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1182 rtl_write_dword(rtlpriv
, 0x3ac, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1183 rtlpci
->irq_enabled
= true;
1186 void rtl8723ae_disable_interrupt(struct ieee80211_hw
*hw
)
1188 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1189 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1191 rtl_write_dword(rtlpriv
, 0x3a8, IMR8190_DISABLED
);
1192 rtl_write_dword(rtlpriv
, 0x3ac, IMR8190_DISABLED
);
1193 rtlpci
->irq_enabled
= false;
1194 synchronize_irq(rtlpci
->pdev
->irq
);
1197 static void _rtl8723ae_poweroff_adapter(struct ieee80211_hw
*hw
)
1199 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1200 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1203 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1204 /* 1. Run LPS WL RFOFF flow */
1205 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1206 PWR_INTF_PCI_MSK
, Rtl8723_NIC_LPS_ENTER_FLOW
);
1208 /* 2. 0x1F[7:0] = 0 */
1210 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, 0x00);
1211 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) && rtlhal
->fw_ready
)
1212 rtl8723ae_firmware_selfreset(hw
);
1214 /* Reset MCU. Suggested by Filen. */
1215 u1tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1216 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+1, (u1tmp
& (~BIT(2))));
1218 /* g. MCUFWDL 0x80[1:0]=0 */
1219 /* reset MCU ready status */
1220 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1222 /* HW card disable configuration. */
1223 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1224 PWR_INTF_PCI_MSK
, Rtl8723_NIC_DISABLE_FLOW
);
1226 /* Reset MCU IO Wrapper */
1227 u1tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1228 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, (u1tmp
& (~BIT(0))));
1229 u1tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1230 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, u1tmp
| BIT(0));
1232 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1233 /* lock ISO/CLK/Power control register */
1234 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0e);
1237 void rtl8723ae_card_disable(struct ieee80211_hw
*hw
)
1239 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1240 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1241 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1242 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1243 enum nl80211_iftype opmode
;
1245 mac
->link_state
= MAC80211_NOLINK
;
1246 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1247 _rtl8723ae_set_media_status(hw
, opmode
);
1248 if (rtlpci
->driver_is_goingto_unload
||
1249 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1250 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1251 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1252 _rtl8723ae_poweroff_adapter(hw
);
1254 /* after power off we should do iqk again */
1255 rtlpriv
->phy
.iqk_initialized
= false;
1258 void rtl8723ae_interrupt_recognized(struct ieee80211_hw
*hw
,
1259 u32
*p_inta
, u32
*p_intb
)
1261 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1262 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1264 *p_inta
= rtl_read_dword(rtlpriv
, 0x3a0) & rtlpci
->irq_mask
[0];
1265 rtl_write_dword(rtlpriv
, 0x3a0, *p_inta
);
1268 void rtl8723ae_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1272 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1273 u16 bcn_interval
, atim_window
;
1275 bcn_interval
= mac
->beacon_interval
;
1276 atim_window
= 2; /*FIX MERGE */
1277 rtl8723ae_disable_interrupt(hw
);
1278 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1279 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1280 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1281 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1282 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1283 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1284 rtl8723ae_enable_interrupt(hw
);
1287 void rtl8723ae_set_beacon_interval(struct ieee80211_hw
*hw
)
1289 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1290 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1291 u16 bcn_interval
= mac
->beacon_interval
;
1293 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1294 "beacon_interval:%d\n", bcn_interval
);
1295 rtl8723ae_disable_interrupt(hw
);
1296 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1297 rtl8723ae_enable_interrupt(hw
);
1300 void rtl8723ae_update_interrupt_mask(struct ieee80211_hw
*hw
,
1301 u32 add_msr
, u32 rm_msr
)
1303 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1304 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1306 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1307 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1310 rtlpci
->irq_mask
[0] |= add_msr
;
1312 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1313 rtl8723ae_disable_interrupt(hw
);
1314 rtl8723ae_enable_interrupt(hw
);
1317 static u8
_rtl8723ae_get_chnl_group(u8 chnl
)
1330 static void _rtl8723ae_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1334 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1335 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1336 u8 rf_path
, index
, tempval
;
1339 for (rf_path
= 0; rf_path
< 1; rf_path
++) {
1340 for (i
= 0; i
< 3; i
++) {
1341 if (!autoload_fail
) {
1342 rtlefuse
->eeprom_chnlarea_txpwr_cck
1344 hwinfo
[EEPROM_TXPOWERCCK
+ rf_path
* 3 + i
];
1345 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1347 hwinfo
[EEPROM_TXPOWERHT40_1S
+ rf_path
*
1350 rtlefuse
->eeprom_chnlarea_txpwr_cck
1352 EEPROM_DEFAULT_TXPOWERLEVEL
;
1353 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1355 EEPROM_DEFAULT_TXPOWERLEVEL
;
1360 for (i
= 0; i
< 3; i
++) {
1362 tempval
= hwinfo
[EEPROM_TXPOWERHT40_2SDIFF
+ i
];
1364 tempval
= EEPROM_DEFAULT_HT40_2SDIFF
;
1365 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_A
][i
] =
1367 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_B
][i
] =
1368 ((tempval
& 0xf0) >> 4);
1371 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1372 for (i
= 0; i
< 3; i
++)
1373 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1374 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path
,
1375 i
, rtlefuse
->eeprom_chnlarea_txpwr_cck
1377 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1378 for (i
= 0; i
< 3; i
++)
1379 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1380 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1382 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1384 for (rf_path
= 0; rf_path
< 2; rf_path
++)
1385 for (i
= 0; i
< 3; i
++)
1386 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
1387 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1389 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1392 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1393 for (i
= 0; i
< 14; i
++) {
1394 index
= _rtl8723ae_get_chnl_group((u8
) i
);
1396 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1397 rtlefuse
->eeprom_chnlarea_txpwr_cck
1399 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1400 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1403 if ((rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1405 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[rf_path
]
1407 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
1408 rtlefuse
->eeprom_chnlarea_txpwr_ht40_1s
1410 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
1413 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] = 0;
1417 for (i
= 0; i
< 14; i
++) {
1418 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1419 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = "
1420 "[0x%x / 0x%x / 0x%x]\n", rf_path
, i
,
1421 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1422 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
1423 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
1427 for (i
= 0; i
< 3; i
++) {
1428 if (!autoload_fail
) {
1429 rtlefuse
->eeprom_pwrlimit_ht40
[i
] =
1430 hwinfo
[EEPROM_TXPWR_GROUP
+ i
];
1431 rtlefuse
->eeprom_pwrlimit_ht20
[i
] =
1432 hwinfo
[EEPROM_TXPWR_GROUP
+ 3 + i
];
1434 rtlefuse
->eeprom_pwrlimit_ht40
[i
] = 0;
1435 rtlefuse
->eeprom_pwrlimit_ht20
[i
] = 0;
1439 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1440 for (i
= 0; i
< 14; i
++) {
1441 index
= _rtl8723ae_get_chnl_group((u8
) i
);
1443 if (rf_path
== RF90_PATH_A
) {
1444 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
1445 (rtlefuse
->eeprom_pwrlimit_ht20
[index
] &
1447 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
1448 (rtlefuse
->eeprom_pwrlimit_ht40
[index
] &
1450 } else if (rf_path
== RF90_PATH_B
) {
1451 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
1452 ((rtlefuse
->eeprom_pwrlimit_ht20
[index
] &
1454 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
1455 ((rtlefuse
->eeprom_pwrlimit_ht40
[index
] &
1459 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1460 "RF-%d pwrgroup_ht20[%d] = 0x%x\n", rf_path
, i
,
1461 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
1462 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1463 "RF-%d pwrgroup_ht40[%d] = 0x%x\n", rf_path
, i
,
1464 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
1468 for (i
= 0; i
< 14; i
++) {
1469 index
= _rtl8723ae_get_chnl_group((u8
) i
);
1472 tempval
= hwinfo
[EEPROM_TXPOWERHT20DIFF
+ index
];
1474 tempval
= EEPROM_DEFAULT_HT20_DIFF
;
1476 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
1477 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
1478 ((tempval
>> 4) & 0xF);
1480 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] & BIT(3))
1481 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] |= 0xF0;
1483 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] & BIT(3))
1484 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] |= 0xF0;
1486 index
= _rtl8723ae_get_chnl_group((u8
) i
);
1489 tempval
= hwinfo
[EEPROM_TXPOWER_OFDMDIFF
+ index
];
1491 tempval
= EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF
;
1493 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
1494 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
1495 ((tempval
>> 4) & 0xF);
1498 rtlefuse
->legacy_ht_txpowerdiff
=
1499 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][7];
1501 for (i
= 0; i
< 14; i
++)
1502 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1503 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i
,
1504 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
1505 for (i
= 0; i
< 14; i
++)
1506 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1507 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i
,
1508 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
1509 for (i
= 0; i
< 14; i
++)
1510 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1511 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i
,
1512 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
1513 for (i
= 0; i
< 14; i
++)
1514 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1515 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i
,
1516 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
1519 rtlefuse
->eeprom_regulatory
= (hwinfo
[RF_OPTION1
] & 0x7);
1521 rtlefuse
->eeprom_regulatory
= 0;
1522 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1523 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1526 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = hwinfo
[EEPROM_TSSI_A
];
1528 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = EEPROM_DEFAULT_TSSI
;
1529 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1530 "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1531 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
1532 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
1535 tempval
= hwinfo
[EEPROM_THERMAL_METER
];
1537 tempval
= EEPROM_DEFAULT_THERMALMETER
;
1538 rtlefuse
->eeprom_thermalmeter
= (tempval
& 0x1f);
1540 if (rtlefuse
->eeprom_thermalmeter
== 0x1f || autoload_fail
)
1541 rtlefuse
->apk_thermalmeterignore
= true;
1543 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1544 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1545 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1548 static void _rtl8723ae_read_adapter_info(struct ieee80211_hw
*hw
,
1551 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1552 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1553 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1555 u8 hwinfo
[HWSET_MAX_SIZE
];
1562 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
1563 rtl_efuse_shadow_map_update(hw
);
1565 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
1567 } else if (rtlefuse
->epromtype
== EEPROM_93C46
) {
1568 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1569 "RTL819X Not boot from eeprom, check it !!");
1572 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("MAP\n"),
1573 hwinfo
, HWSET_MAX_SIZE
);
1575 eeprom_id
= *((u16
*)&hwinfo
[0]);
1576 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
1577 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1578 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1579 rtlefuse
->autoload_failflag
= true;
1581 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1582 rtlefuse
->autoload_failflag
= false;
1585 if (rtlefuse
->autoload_failflag
== true)
1588 rtlefuse
->eeprom_vid
= *(u16
*) &hwinfo
[EEPROM_VID
];
1589 rtlefuse
->eeprom_did
= *(u16
*) &hwinfo
[EEPROM_DID
];
1590 rtlefuse
->eeprom_svid
= *(u16
*) &hwinfo
[EEPROM_SVID
];
1591 rtlefuse
->eeprom_smid
= *(u16
*) &hwinfo
[EEPROM_SMID
];
1592 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1593 "EEPROMId = 0x%4x\n", eeprom_id
);
1594 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1595 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1596 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1597 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1598 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1599 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1600 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1601 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1603 for (i
= 0; i
< 6; i
+= 2) {
1604 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
1605 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
1608 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1609 "dev_addr: %pM\n", rtlefuse
->dev_addr
);
1611 _rtl8723ae_read_txpower_info_from_hwpg(hw
,
1612 rtlefuse
->autoload_failflag
, hwinfo
);
1614 rtl8723ae_read_bt_coexist_info_from_hwpg(hw
,
1615 rtlefuse
->autoload_failflag
, hwinfo
);
1617 rtlefuse
->eeprom_channelplan
= *(u8
*)&hwinfo
[EEPROM_CHANNELPLAN
];
1618 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
1619 rtlefuse
->txpwr_fromeprom
= true;
1620 rtlefuse
->eeprom_oemid
= *(u8
*)&hwinfo
[EEPROM_CUSTOMER_ID
];
1622 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1623 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1625 /* set channel paln to world wide 13 */
1626 rtlefuse
->channel_plan
= COUNTRY_CODE_WORLD_WIDE_13
;
1628 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
1629 switch (rtlefuse
->eeprom_oemid
) {
1630 case EEPROM_CID_DEFAULT
:
1631 if (rtlefuse
->eeprom_did
== 0x8176) {
1632 if (CHK_SVID_SMID(0x10EC, 0x6151) ||
1633 CHK_SVID_SMID(0x10EC, 0x6152) ||
1634 CHK_SVID_SMID(0x10EC, 0x6154) ||
1635 CHK_SVID_SMID(0x10EC, 0x6155) ||
1636 CHK_SVID_SMID(0x10EC, 0x6177) ||
1637 CHK_SVID_SMID(0x10EC, 0x6178) ||
1638 CHK_SVID_SMID(0x10EC, 0x6179) ||
1639 CHK_SVID_SMID(0x10EC, 0x6180) ||
1640 CHK_SVID_SMID(0x10EC, 0x8151) ||
1641 CHK_SVID_SMID(0x10EC, 0x8152) ||
1642 CHK_SVID_SMID(0x10EC, 0x8154) ||
1643 CHK_SVID_SMID(0x10EC, 0x8155) ||
1644 CHK_SVID_SMID(0x10EC, 0x8181) ||
1645 CHK_SVID_SMID(0x10EC, 0x8182) ||
1646 CHK_SVID_SMID(0x10EC, 0x8184) ||
1647 CHK_SVID_SMID(0x10EC, 0x8185) ||
1648 CHK_SVID_SMID(0x10EC, 0x9151) ||
1649 CHK_SVID_SMID(0x10EC, 0x9152) ||
1650 CHK_SVID_SMID(0x10EC, 0x9154) ||
1651 CHK_SVID_SMID(0x10EC, 0x9155) ||
1652 CHK_SVID_SMID(0x10EC, 0x9181) ||
1653 CHK_SVID_SMID(0x10EC, 0x9182) ||
1654 CHK_SVID_SMID(0x10EC, 0x9184) ||
1655 CHK_SVID_SMID(0x10EC, 0x9185))
1656 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1657 else if (rtlefuse
->eeprom_svid
== 0x1025)
1658 rtlhal
->oem_id
= RT_CID_819x_Acer
;
1659 else if (CHK_SVID_SMID(0x10EC, 0x6191) ||
1660 CHK_SVID_SMID(0x10EC, 0x6192) ||
1661 CHK_SVID_SMID(0x10EC, 0x6193) ||
1662 CHK_SVID_SMID(0x10EC, 0x7191) ||
1663 CHK_SVID_SMID(0x10EC, 0x7192) ||
1664 CHK_SVID_SMID(0x10EC, 0x7193) ||
1665 CHK_SVID_SMID(0x10EC, 0x8191) ||
1666 CHK_SVID_SMID(0x10EC, 0x8192) ||
1667 CHK_SVID_SMID(0x10EC, 0x8193))
1668 rtlhal
->oem_id
= RT_CID_819x_SAMSUNG
;
1669 else if (CHK_SVID_SMID(0x10EC, 0x8195) ||
1670 CHK_SVID_SMID(0x10EC, 0x9195) ||
1671 CHK_SVID_SMID(0x10EC, 0x7194) ||
1672 CHK_SVID_SMID(0x10EC, 0x8200) ||
1673 CHK_SVID_SMID(0x10EC, 0x8201) ||
1674 CHK_SVID_SMID(0x10EC, 0x8202) ||
1675 CHK_SVID_SMID(0x10EC, 0x9200))
1676 rtlhal
->oem_id
= RT_CID_819x_Lenovo
;
1677 else if (CHK_SVID_SMID(0x10EC, 0x8197) ||
1678 CHK_SVID_SMID(0x10EC, 0x9196))
1679 rtlhal
->oem_id
= RT_CID_819x_CLEVO
;
1680 else if (CHK_SVID_SMID(0x1028, 0x8194) ||
1681 CHK_SVID_SMID(0x1028, 0x8198) ||
1682 CHK_SVID_SMID(0x1028, 0x9197) ||
1683 CHK_SVID_SMID(0x1028, 0x9198))
1684 rtlhal
->oem_id
= RT_CID_819x_DELL
;
1685 else if (CHK_SVID_SMID(0x103C, 0x1629))
1686 rtlhal
->oem_id
= RT_CID_819x_HP
;
1687 else if (CHK_SVID_SMID(0x1A32, 0x2315))
1688 rtlhal
->oem_id
= RT_CID_819x_QMI
;
1689 else if (CHK_SVID_SMID(0x10EC, 0x8203))
1690 rtlhal
->oem_id
= RT_CID_819x_PRONETS
;
1691 else if (CHK_SVID_SMID(0x1043, 0x84B5))
1693 RT_CID_819x_Edimax_ASUS
;
1695 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1696 } else if (rtlefuse
->eeprom_did
== 0x8178) {
1697 if (CHK_SVID_SMID(0x10EC, 0x6181) ||
1698 CHK_SVID_SMID(0x10EC, 0x6182) ||
1699 CHK_SVID_SMID(0x10EC, 0x6184) ||
1700 CHK_SVID_SMID(0x10EC, 0x6185) ||
1701 CHK_SVID_SMID(0x10EC, 0x7181) ||
1702 CHK_SVID_SMID(0x10EC, 0x7182) ||
1703 CHK_SVID_SMID(0x10EC, 0x7184) ||
1704 CHK_SVID_SMID(0x10EC, 0x7185) ||
1705 CHK_SVID_SMID(0x10EC, 0x8181) ||
1706 CHK_SVID_SMID(0x10EC, 0x8182) ||
1707 CHK_SVID_SMID(0x10EC, 0x8184) ||
1708 CHK_SVID_SMID(0x10EC, 0x8185) ||
1709 CHK_SVID_SMID(0x10EC, 0x9181) ||
1710 CHK_SVID_SMID(0x10EC, 0x9182) ||
1711 CHK_SVID_SMID(0x10EC, 0x9184) ||
1712 CHK_SVID_SMID(0x10EC, 0x9185))
1713 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1714 else if (rtlefuse
->eeprom_svid
== 0x1025)
1715 rtlhal
->oem_id
= RT_CID_819x_Acer
;
1716 else if (CHK_SVID_SMID(0x10EC, 0x8186))
1717 rtlhal
->oem_id
= RT_CID_819x_PRONETS
;
1718 else if (CHK_SVID_SMID(0x1043, 0x8486))
1720 RT_CID_819x_Edimax_ASUS
;
1722 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1724 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1727 case EEPROM_CID_TOSHIBA
:
1728 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1730 case EEPROM_CID_CCX
:
1731 rtlhal
->oem_id
= RT_CID_CCX
;
1733 case EEPROM_CID_QMI
:
1734 rtlhal
->oem_id
= RT_CID_819x_QMI
;
1736 case EEPROM_CID_WHQL
:
1739 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1746 static void _rtl8723ae_hal_customized_behavior(struct ieee80211_hw
*hw
)
1748 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1749 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1750 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1752 pcipriv
->ledctl
.led_opendrain
= true;
1753 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1754 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
1757 void rtl8723ae_read_eeprom_info(struct ieee80211_hw
*hw
)
1759 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1760 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1761 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1762 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1766 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
]);
1767 value32
= (value32
& ~EFUSE_SEL_MASK
) | EFUSE_SEL(EFUSE_WIFI_SEL_0
);
1768 rtl_write_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
], value32
);
1770 rtlhal
->version
= _rtl8723ae_read_chip_version(hw
);
1772 if (get_rf_type(rtlphy
) == RF_1T1R
)
1773 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
1775 rtlpriv
->dm
.rfpath_rxenable
[0] =
1776 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
1777 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
1780 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
1781 if (tmp_u1b
& BIT(4)) {
1782 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1783 rtlefuse
->epromtype
= EEPROM_93C46
;
1785 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1786 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1788 if (tmp_u1b
& BIT(5)) {
1789 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1790 rtlefuse
->autoload_failflag
= false;
1791 _rtl8723ae_read_adapter_info(hw
, false);
1793 rtlefuse
->autoload_failflag
= true;
1794 _rtl8723ae_read_adapter_info(hw
, false);
1795 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Autoload ERR!!\n");
1797 _rtl8723ae_hal_customized_behavior(hw
);
1800 static void rtl8723ae_update_hal_rate_table(struct ieee80211_hw
*hw
,
1801 struct ieee80211_sta
*sta
)
1803 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1804 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1805 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1806 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1807 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1810 u8 nmode
= mac
->ht_enable
;
1811 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
1812 u8 curtxbw_40mhz
= mac
->bw_40
;
1813 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
1815 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
1817 enum wireless_mode wirelessmode
= mac
->mode
;
1819 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1820 ratr_value
= sta
->supp_rates
[1] << 4;
1822 ratr_value
= sta
->supp_rates
[0];
1823 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1825 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
1826 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
1827 switch (wirelessmode
) {
1828 case WIRELESS_MODE_B
:
1829 if (ratr_value
& 0x0000000c)
1830 ratr_value
&= 0x0000000d;
1832 ratr_value
&= 0x0000000f;
1834 case WIRELESS_MODE_G
:
1835 ratr_value
&= 0x00000FF5;
1837 case WIRELESS_MODE_N_24G
:
1838 case WIRELESS_MODE_N_5G
:
1840 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
1841 ratr_value
&= 0x0007F005;
1845 if (get_rf_type(rtlphy
) == RF_1T2R
||
1846 get_rf_type(rtlphy
) == RF_1T1R
)
1847 ratr_mask
= 0x000ff005;
1849 ratr_mask
= 0x0f0ff005;
1851 ratr_value
&= ratr_mask
;
1855 if (rtlphy
->rf_type
== RF_1T2R
)
1856 ratr_value
&= 0x000ff0ff;
1858 ratr_value
&= 0x0f0ff0ff;
1863 if ((pcipriv
->bt_coexist
.bt_coexistence
) &&
1864 (pcipriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
) &&
1865 (pcipriv
->bt_coexist
.bt_cur_state
) &&
1866 (pcipriv
->bt_coexist
.bt_ant_isolation
) &&
1867 ((pcipriv
->bt_coexist
.bt_service
== BT_SCO
) ||
1868 (pcipriv
->bt_coexist
.bt_service
== BT_BUSY
)))
1869 ratr_value
&= 0x0fffcfc0;
1871 ratr_value
&= 0x0FFFFFFF;
1873 if (nmode
&& ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
1874 (!curtxbw_40mhz
&& curshortgi_20mhz
)))
1875 ratr_value
|= 0x10000000;
1877 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
1879 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
1880 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
1883 static void rtl8723ae_update_hal_rate_mask(struct ieee80211_hw
*hw
,
1884 struct ieee80211_sta
*sta
, u8 rssi_level
)
1886 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1887 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1888 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1889 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1890 struct rtl_sta_info
*sta_entry
= NULL
;
1893 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
1894 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
1896 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
1898 enum wireless_mode wirelessmode
= 0;
1899 bool shortgi
= false;
1902 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
1904 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
1905 wirelessmode
= sta_entry
->wireless_mode
;
1906 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
1907 curtxbw_40mhz
= mac
->bw_40
;
1908 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
1909 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1910 macid
= sta
->aid
+ 1;
1912 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1913 ratr_bitmap
= sta
->supp_rates
[1] << 4;
1915 ratr_bitmap
= sta
->supp_rates
[0];
1916 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1917 ratr_bitmap
= 0xfff;
1918 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
1919 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
1920 switch (wirelessmode
) {
1921 case WIRELESS_MODE_B
:
1922 ratr_index
= RATR_INX_WIRELESS_B
;
1923 if (ratr_bitmap
& 0x0000000c)
1924 ratr_bitmap
&= 0x0000000d;
1926 ratr_bitmap
&= 0x0000000f;
1928 case WIRELESS_MODE_G
:
1929 ratr_index
= RATR_INX_WIRELESS_GB
;
1931 if (rssi_level
== 1)
1932 ratr_bitmap
&= 0x00000f00;
1933 else if (rssi_level
== 2)
1934 ratr_bitmap
&= 0x00000ff0;
1936 ratr_bitmap
&= 0x00000ff5;
1938 case WIRELESS_MODE_A
:
1939 ratr_index
= RATR_INX_WIRELESS_A
;
1940 ratr_bitmap
&= 0x00000ff0;
1942 case WIRELESS_MODE_N_24G
:
1943 case WIRELESS_MODE_N_5G
:
1944 ratr_index
= RATR_INX_WIRELESS_NGB
;
1946 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
1947 if (rssi_level
== 1)
1948 ratr_bitmap
&= 0x00070000;
1949 else if (rssi_level
== 2)
1950 ratr_bitmap
&= 0x0007f000;
1952 ratr_bitmap
&= 0x0007f005;
1954 if (rtlphy
->rf_type
== RF_1T2R
||
1955 rtlphy
->rf_type
== RF_1T1R
) {
1956 if (curtxbw_40mhz
) {
1957 if (rssi_level
== 1)
1958 ratr_bitmap
&= 0x000f0000;
1959 else if (rssi_level
== 2)
1960 ratr_bitmap
&= 0x000ff000;
1962 ratr_bitmap
&= 0x000ff015;
1964 if (rssi_level
== 1)
1965 ratr_bitmap
&= 0x000f0000;
1966 else if (rssi_level
== 2)
1967 ratr_bitmap
&= 0x000ff000;
1969 ratr_bitmap
&= 0x000ff005;
1972 if (curtxbw_40mhz
) {
1973 if (rssi_level
== 1)
1974 ratr_bitmap
&= 0x0f0f0000;
1975 else if (rssi_level
== 2)
1976 ratr_bitmap
&= 0x0f0ff000;
1978 ratr_bitmap
&= 0x0f0ff015;
1980 if (rssi_level
== 1)
1981 ratr_bitmap
&= 0x0f0f0000;
1982 else if (rssi_level
== 2)
1983 ratr_bitmap
&= 0x0f0ff000;
1985 ratr_bitmap
&= 0x0f0ff005;
1990 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
1991 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
1994 else if (macid
== 1)
1999 ratr_index
= RATR_INX_WIRELESS_NGB
;
2001 if (rtlphy
->rf_type
== RF_1T2R
)
2002 ratr_bitmap
&= 0x000ff0ff;
2004 ratr_bitmap
&= 0x0f0ff0ff;
2007 sta_entry
->ratr_index
= ratr_index
;
2009 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2010 "ratr_bitmap :%x\n", ratr_bitmap
);
2011 /* convert ratr_bitmap to le byte array */
2012 rate_mask
[0] = ratr_bitmap
;
2013 rate_mask
[1] = (ratr_bitmap
>>= 8);
2014 rate_mask
[2] = (ratr_bitmap
>>= 8);
2015 rate_mask
[3] = ((ratr_bitmap
>> 8) & 0x0f) | (ratr_index
<< 4);
2016 rate_mask
[4] = macid
| (shortgi
? 0x20 : 0x00) | 0x80;
2017 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2018 "Rate_index:%x, ratr_bitmap: %*phC\n",
2019 ratr_index
, 5, rate_mask
);
2020 rtl8723ae_fill_h2c_cmd(hw
, H2C_RA_MASK
, 5, rate_mask
);
2023 void rtl8723ae_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2024 struct ieee80211_sta
*sta
, u8 rssi_level
)
2026 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2028 if (rtlpriv
->dm
.useramask
)
2029 rtl8723ae_update_hal_rate_mask(hw
, sta
, rssi_level
);
2031 rtl8723ae_update_hal_rate_table(hw
, sta
);
2034 void rtl8723ae_update_channel_access_setting(struct ieee80211_hw
*hw
)
2036 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2037 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2040 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2041 (u8
*)&mac
->slot_time
);
2042 if (!mac
->ht_enable
)
2043 sifs_timer
= 0x0a0a;
2045 sifs_timer
= 0x1010;
2046 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2049 bool rtl8723ae_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2051 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2052 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2053 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2054 enum rf_pwrstate e_rfpowerstate_toset
;
2056 bool actuallyset
= false;
2058 if (rtlpriv
->rtlhal
.being_init_adapter
)
2061 if (ppsc
->swrf_processing
)
2064 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2065 if (ppsc
->rfchange_inprogress
) {
2066 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2069 ppsc
->rfchange_inprogress
= true;
2070 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2073 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL_2
,
2074 rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL_2
)&~(BIT(1)));
2076 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_PIN_CTRL_2
);
2078 if (rtlphy
->polarity_ctl
)
2079 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFOFF
: ERFON
;
2081 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFON
: ERFOFF
;
2083 if ((ppsc
->hwradiooff
== true) && (e_rfpowerstate_toset
== ERFON
)) {
2084 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2085 "GPIOChangeRF - HW Radio ON, RF ON\n");
2087 e_rfpowerstate_toset
= ERFON
;
2088 ppsc
->hwradiooff
= false;
2090 } else if ((ppsc
->hwradiooff
== false)
2091 && (e_rfpowerstate_toset
== ERFOFF
)) {
2092 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2093 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2095 e_rfpowerstate_toset
= ERFOFF
;
2096 ppsc
->hwradiooff
= true;
2101 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2102 ppsc
->rfchange_inprogress
= false;
2103 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2105 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2106 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2108 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2109 ppsc
->rfchange_inprogress
= false;
2110 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2114 return !ppsc
->hwradiooff
;
2117 void rtl8723ae_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
2118 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
2119 bool is_wepkey
, bool clear_all
)
2121 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2122 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2123 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2124 u8
*macaddr
= p_macaddr
;
2126 bool is_pairwise
= false;
2127 static u8 cam_const_addr
[4][6] = {
2128 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2129 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2130 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2131 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2133 static u8 cam_const_broad
[] = {
2134 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2140 u8 clear_number
= 5;
2142 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2144 for (idx
= 0; idx
< clear_number
; idx
++) {
2145 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2146 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2149 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2151 rtlpriv
->sec
.key_len
[idx
] = 0;
2156 case WEP40_ENCRYPTION
:
2157 enc_algo
= CAM_WEP40
;
2159 case WEP104_ENCRYPTION
:
2160 enc_algo
= CAM_WEP104
;
2162 case TKIP_ENCRYPTION
:
2163 enc_algo
= CAM_TKIP
;
2165 case AESCCMP_ENCRYPTION
:
2169 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2170 "switch case not processed\n");
2171 enc_algo
= CAM_TKIP
;
2175 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2176 macaddr
= cam_const_addr
[key_index
];
2177 entry_id
= key_index
;
2180 macaddr
= cam_const_broad
;
2181 entry_id
= key_index
;
2183 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2184 entry_id
= rtl_cam_get_free_entry(hw
,
2186 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2187 RT_TRACE(rtlpriv
, COMP_SEC
,
2189 "Can not find free hw security cam entry\n");
2193 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2196 key_index
= PAIRWISE_KEYIDX
;
2201 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2202 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2203 "delete one entry, entry_id is %d\n",
2205 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2206 rtl_cam_del_entry(hw
, p_macaddr
);
2207 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2209 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2212 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2213 "set Pairwiase key\n");
2215 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2217 CAM_CONFIG_NO_USEDK
,
2218 rtlpriv
->sec
.key_buf
[key_index
]);
2220 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2223 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2224 rtl_cam_add_one_entry(hw
,
2227 CAM_PAIRWISE_KEY_POSITION
,
2229 CAM_CONFIG_NO_USEDK
,
2230 rtlpriv
->sec
.key_buf
2234 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2236 CAM_CONFIG_NO_USEDK
,
2237 rtlpriv
->sec
.key_buf
[entry_id
]);
2244 static void rtl8723ae_bt_var_init(struct ieee80211_hw
*hw
)
2246 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2247 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2249 pcipriv
->bt_coexist
.bt_coexistence
=
2250 pcipriv
->bt_coexist
.eeprom_bt_coexist
;
2251 pcipriv
->bt_coexist
.bt_ant_num
=
2252 pcipriv
->bt_coexist
.eeprom_bt_ant_num
;
2253 pcipriv
->bt_coexist
.bt_coexist_type
=
2254 pcipriv
->bt_coexist
.eeprom_bt_type
;
2256 pcipriv
->bt_coexist
.bt_ant_isolation
=
2257 pcipriv
->bt_coexist
.eeprom_bt_ant_isol
;
2259 pcipriv
->bt_coexist
.bt_radio_shared_type
=
2260 pcipriv
->bt_coexist
.eeprom_bt_radio_shared
;
2262 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2263 "BT Coexistance = 0x%x\n",
2264 pcipriv
->bt_coexist
.bt_coexistence
);
2266 if (pcipriv
->bt_coexist
.bt_coexistence
) {
2267 pcipriv
->bt_coexist
.bt_busy_traffic
= false;
2268 pcipriv
->bt_coexist
.bt_traffic_mode_set
= false;
2269 pcipriv
->bt_coexist
.bt_non_traffic_mode_set
= false;
2271 pcipriv
->bt_coexist
.cstate
= 0;
2272 pcipriv
->bt_coexist
.previous_state
= 0;
2274 if (pcipriv
->bt_coexist
.bt_ant_num
== ANT_X2
) {
2275 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2276 "BlueTooth BT_Ant_Num = Antx2\n");
2277 } else if (pcipriv
->bt_coexist
.bt_ant_num
== ANT_X1
) {
2278 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2279 "BlueTooth BT_Ant_Num = Antx1\n");
2282 switch (pcipriv
->bt_coexist
.bt_coexist_type
) {
2284 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2285 "BlueTooth BT_CoexistType = BT_2Wire\n");
2288 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2289 "BlueTooth BT_CoexistType = BT_ISSC_3Wire\n");
2292 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2293 "BlueTooth BT_CoexistType = BT_ACCEL\n");
2296 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2297 "BlueTooth BT_CoexistType = BT_CSR_BC4\n");
2300 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2301 "BlueTooth BT_CoexistType = BT_CSR_BC8\n");
2304 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2305 "BlueTooth BT_CoexistType = BT_RTL8756\n");
2308 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2309 "BlueTooth BT_CoexistType = Unknown\n");
2312 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2313 "BlueTooth BT_Ant_isolation = %d\n",
2314 pcipriv
->bt_coexist
.bt_ant_isolation
);
2315 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_TRACE
,
2316 "BT_RadioSharedType = 0x%x\n",
2317 pcipriv
->bt_coexist
.bt_radio_shared_type
);
2318 pcipriv
->bt_coexist
.bt_active_zero_cnt
= 0;
2319 pcipriv
->bt_coexist
.cur_bt_disabled
= false;
2320 pcipriv
->bt_coexist
.pre_bt_disabled
= false;
2324 void rtl8723ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2325 bool auto_load_fail
, u8
*hwinfo
)
2327 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2328 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2332 if (!auto_load_fail
) {
2333 tmpu_32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
2334 if (tmpu_32
& BIT(18))
2335 pcipriv
->bt_coexist
.eeprom_bt_coexist
= 1;
2337 pcipriv
->bt_coexist
.eeprom_bt_coexist
= 0;
2338 value
= hwinfo
[RF_OPTION4
];
2339 pcipriv
->bt_coexist
.eeprom_bt_type
= BT_RTL8723A
;
2340 pcipriv
->bt_coexist
.eeprom_bt_ant_num
= (value
& 0x1);
2341 pcipriv
->bt_coexist
.eeprom_bt_ant_isol
= ((value
& 0x10) >> 4);
2342 pcipriv
->bt_coexist
.eeprom_bt_radio_shared
=
2343 ((value
& 0x20) >> 5);
2345 pcipriv
->bt_coexist
.eeprom_bt_coexist
= 0;
2346 pcipriv
->bt_coexist
.eeprom_bt_type
= BT_RTL8723A
;
2347 pcipriv
->bt_coexist
.eeprom_bt_ant_num
= ANT_X2
;
2348 pcipriv
->bt_coexist
.eeprom_bt_ant_isol
= 0;
2349 pcipriv
->bt_coexist
.eeprom_bt_radio_shared
= BT_RADIO_SHARED
;
2352 rtl8723ae_bt_var_init(hw
);
2355 void rtl8723ae_bt_reg_init(struct ieee80211_hw
*hw
)
2357 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
2359 /* 0:Low, 1:High, 2:From Efuse. */
2360 pcipriv
->bt_coexist
.reg_bt_iso
= 2;
2361 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2362 pcipriv
->bt_coexist
.reg_bt_sco
= 3;
2363 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2364 pcipriv
->bt_coexist
.reg_bt_sco
= 0;
2368 void rtl8723ae_bt_hw_init(struct ieee80211_hw
*hw
)
2372 void rtl8723ae_suspend(struct ieee80211_hw
*hw
)
2376 void rtl8723ae_resume(struct ieee80211_hw
*hw
)
2380 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
2381 void rtl8723ae_allow_all_destaddr(struct ieee80211_hw
*hw
,
2382 bool allow_all_da
, bool write_into_reg
)
2384 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2385 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2387 if (allow_all_da
) /* Set BIT0 */
2388 rtlpci
->receive_config
|= RCR_AAP
;
2389 else /* Clear BIT0 */
2390 rtlpci
->receive_config
&= ~RCR_AAP
;
2393 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
2396 RT_TRACE(rtlpriv
, COMP_TURBO
| COMP_INIT
, DBG_LOUD
,
2397 "receive_config=0x%08X, write_into_reg=%d\n",
2398 rtlpci
->receive_config
, write_into_reg
);