1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
11 #include "../pwrseqcmd.h"
23 static void _rtl88ee_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
24 u8 set_bits
, u8 clear_bits
)
26 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
27 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
29 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
30 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
32 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
35 static void _rtl88ee_stop_tx_beacon(struct ieee80211_hw
*hw
)
37 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
40 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
41 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
42 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
43 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
44 tmp1byte
&= ~(BIT(0));
45 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
48 static void _rtl88ee_resume_tx_beacon(struct ieee80211_hw
*hw
)
50 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
53 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
54 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
55 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
56 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
58 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
61 static void _rtl88ee_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
63 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(1));
66 static void _rtl88ee_return_beacon_queue_skb(struct ieee80211_hw
*hw
)
68 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
69 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
70 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
73 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
74 while (skb_queue_len(&ring
->queue
)) {
75 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
76 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
78 pci_unmap_single(rtlpci
->pdev
,
79 rtlpriv
->cfg
->ops
->get_desc(
81 (u8
*)entry
, true, HW_DESC_TXBUFF_ADDR
),
82 skb
->len
, PCI_DMA_TODEVICE
);
84 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
86 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
89 static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
91 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(1), 0);
94 static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw
*hw
,
95 u8 rpwm_val
, bool b_need_turn_off_ckk
)
97 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
98 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
99 bool b_support_remote_wake_up
;
100 u32 count
= 0, isr_regaddr
, content
;
101 bool schedule_timer
= b_need_turn_off_ckk
;
102 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
103 (u8
*)(&b_support_remote_wake_up
));
105 if (!rtlhal
->fw_ready
)
107 if (!rtlpriv
->psc
.fw_current_inpsmode
)
111 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
112 if (rtlhal
->fw_clk_change_in_progress
) {
113 while (rtlhal
->fw_clk_change_in_progress
) {
114 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
119 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
121 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
123 rtlhal
->fw_clk_change_in_progress
= false;
124 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
129 if (IS_IN_LOW_POWER_STATE_88E(rtlhal
->fw_ps_state
)) {
130 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
131 if (FW_PS_IS_ACK(rpwm_val
)) {
132 isr_regaddr
= REG_HISR
;
133 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
134 while (!(content
& IMR_CPWM
) && (count
< 500)) {
137 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
140 if (content
& IMR_CPWM
) {
141 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
142 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON_88E
;
143 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
144 "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
145 rtlhal
->fw_ps_state
);
149 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
150 rtlhal
->fw_clk_change_in_progress
= false;
151 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
152 if (schedule_timer
) {
153 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
154 jiffies
+ MSECS(10));
158 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
159 rtlhal
->fw_clk_change_in_progress
= false;
160 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
164 static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw
*hw
,
167 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
168 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
169 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
170 struct rtl8192_tx_ring
*ring
;
171 enum rf_pwrstate rtstate
;
172 bool schedule_timer
= false;
175 if (!rtlhal
->fw_ready
)
177 if (!rtlpriv
->psc
.fw_current_inpsmode
)
179 if (!rtlhal
->allow_sw_to_change_hwclc
)
181 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
182 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
185 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
186 ring
= &rtlpci
->tx_ring
[queue
];
187 if (skb_queue_len(&ring
->queue
)) {
188 schedule_timer
= true;
193 if (schedule_timer
) {
194 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
195 jiffies
+ MSECS(10));
199 if (FW_PS_STATE(rtlhal
->fw_ps_state
) !=
200 FW_PS_STATE_RF_OFF_LOW_PWR_88E
) {
201 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
202 if (!rtlhal
->fw_clk_change_in_progress
) {
203 rtlhal
->fw_clk_change_in_progress
= true;
204 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
205 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
206 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
207 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
209 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
210 rtlhal
->fw_clk_change_in_progress
= false;
211 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
213 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
214 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
215 jiffies
+ MSECS(10));
220 static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
224 rpwm_val
|= (FW_PS_STATE_RF_OFF_88E
| FW_PS_ACK
);
225 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, true);
228 static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw
*hw
)
231 rpwm_val
|= FW_PS_STATE_RF_OFF_LOW_PWR_88E
;
232 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
235 void rtl88ee_fw_clk_off_timer_callback(struct timer_list
*t
)
237 struct rtl_priv
*rtlpriv
= from_timer(rtlpriv
, t
,
238 works
.fw_clockoff_timer
);
239 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
241 _rtl88ee_set_fw_ps_rf_off_low_power(hw
);
244 static void _rtl88ee_fwlps_leave(struct ieee80211_hw
*hw
)
246 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
247 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
248 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
249 bool fw_current_inps
= false;
250 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
252 if (ppsc
->low_power_enable
) {
253 rpwm_val
= (FW_PS_STATE_ALL_ON_88E
|FW_PS_ACK
);/* RF on */
254 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, false);
255 rtlhal
->allow_sw_to_change_hwclc
= false;
256 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
258 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
259 (u8
*)(&fw_current_inps
));
261 rpwm_val
= FW_PS_STATE_ALL_ON_88E
; /* RF on */
262 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
263 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
265 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
266 (u8
*)(&fw_current_inps
));
270 static void _rtl88ee_fwlps_enter(struct ieee80211_hw
*hw
)
272 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
273 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
274 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
275 bool fw_current_inps
= true;
278 if (ppsc
->low_power_enable
) {
279 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR_88E
; /* RF off */
280 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
281 (u8
*)(&fw_current_inps
));
282 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
283 &ppsc
->fwctrl_psmode
);
284 rtlhal
->allow_sw_to_change_hwclc
= true;
285 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
287 rpwm_val
= FW_PS_STATE_RF_OFF_88E
; /* RF off */
288 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
289 (u8
*)(&fw_current_inps
));
290 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
291 &ppsc
->fwctrl_psmode
);
292 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
296 void rtl88ee_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
298 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
299 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
300 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
304 *((u32
*)(val
)) = rtlpci
->receive_config
;
306 case HW_VAR_RF_STATE
:
307 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
309 case HW_VAR_FWLPS_RF_ON
:{
310 enum rf_pwrstate rfstate
;
313 rtlpriv
->cfg
->ops
->get_hw_reg(hw
,
316 if (rfstate
== ERFOFF
) {
317 *((bool *)(val
)) = true;
319 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
320 val_rcr
&= 0x00070000;
322 *((bool *)(val
)) = false;
324 *((bool *)(val
)) = true;
327 case HW_VAR_FW_PSMODE_STATUS
:
328 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
330 case HW_VAR_CORRECT_TSF
:{
332 u32
*ptsf_low
= (u32
*)&tsf
;
333 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
335 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
336 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
338 *((u64
*)(val
)) = tsf
;
343 pr_err("switch case %#x not processed\n", variable
);
348 void rtl88ee_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
350 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
351 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
352 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
353 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
354 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
358 case HW_VAR_ETHER_ADDR
:
359 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
360 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
364 case HW_VAR_BASIC_RATE
:{
365 u16 b_rate_cfg
= ((u16
*)val
)[0];
367 b_rate_cfg
= b_rate_cfg
& 0x15f;
369 rtl_write_byte(rtlpriv
, REG_RRSR
, b_rate_cfg
& 0xff);
370 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
371 (b_rate_cfg
>> 8) & 0xff);
372 while (b_rate_cfg
> 0x1) {
373 b_rate_cfg
= (b_rate_cfg
>> 1);
376 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
381 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
382 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
387 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
388 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
390 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
391 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
394 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
397 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
400 case HW_VAR_SLOT_TIME
:{
403 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
404 "HW_VAR_SLOT_TIME %x\n", val
[0]);
406 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
408 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
409 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
414 case HW_VAR_ACK_PREAMBLE
:{
416 u8 short_preamble
= (bool)*val
;
417 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+2);
418 if (short_preamble
) {
420 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+
424 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+
428 case HW_VAR_WPA_CONFIG
:
429 rtl_write_byte(rtlpriv
, REG_SECCFG
, *val
);
431 case HW_VAR_AMPDU_MIN_SPACE
:{
432 u8 min_spacing_to_set
;
435 min_spacing_to_set
= *val
;
436 if (min_spacing_to_set
<= 7) {
439 if (min_spacing_to_set
< sec_min_space
)
440 min_spacing_to_set
= sec_min_space
;
442 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
446 *val
= min_spacing_to_set
;
448 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
449 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
452 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
456 case HW_VAR_SHORTGI_DENSITY
:{
459 density_to_set
= *val
;
460 mac
->min_space_cfg
|= (density_to_set
<< 3);
462 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
463 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
466 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
470 case HW_VAR_AMPDU_FACTOR
:{
471 u8 regtoset_normal
[4] = { 0x41, 0xa8, 0x72, 0xb9 };
473 u8
*p_regtoset
= NULL
;
476 p_regtoset
= regtoset_normal
;
479 if (factor_toset
<= 3) {
480 factor_toset
= (1 << (factor_toset
+ 2));
481 if (factor_toset
> 0xf)
484 for (index
= 0; index
< 4; index
++) {
485 if ((p_regtoset
[index
] & 0xf0) >
488 (p_regtoset
[index
] & 0x0f) |
491 if ((p_regtoset
[index
] & 0x0f) >
494 (p_regtoset
[index
] & 0xf0) |
497 rtl_write_byte(rtlpriv
,
498 (REG_AGGLEN_LMT
+ index
),
503 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
504 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
508 case HW_VAR_AC_PARAM
:{
510 rtl88e_dm_init_edca_turbo(hw
);
512 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
513 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
517 case HW_VAR_ACM_CTRL
:{
519 union aci_aifsn
*p_aci_aifsn
=
520 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
521 u8 acm
= p_aci_aifsn
->f
.acm
;
522 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
524 acm_ctrl
= acm_ctrl
|
525 ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
530 acm_ctrl
|= ACMHW_BEQEN
;
533 acm_ctrl
|= ACMHW_VIQEN
;
536 acm_ctrl
|= ACMHW_VOQEN
;
539 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
540 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
547 acm_ctrl
&= (~ACMHW_BEQEN
);
550 acm_ctrl
&= (~ACMHW_VIQEN
);
553 acm_ctrl
&= (~ACMHW_VOQEN
);
556 pr_err("switch case %#x not processed\n",
562 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
563 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
565 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
568 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
569 rtlpci
->receive_config
= ((u32
*)(val
))[0];
571 case HW_VAR_RETRY_LIMIT
:{
572 u8 retry_limit
= *val
;
574 rtl_write_word(rtlpriv
, REG_RL
,
575 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
576 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
578 case HW_VAR_DUAL_TSF_RST
:
579 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
581 case HW_VAR_EFUSE_BYTES
:
582 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
584 case HW_VAR_EFUSE_USAGE
:
585 rtlefuse
->efuse_usedpercentage
= *val
;
588 rtl88e_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
590 case HW_VAR_SET_RPWM
:{
593 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
596 if (rpwm_val
& BIT(7)) {
597 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, *val
);
599 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, *val
| BIT(7));
602 case HW_VAR_H2C_FW_PWRMODE
:
603 rtl88e_set_fw_pwrmode_cmd(hw
, *val
);
605 case HW_VAR_FW_PSMODE_STATUS
:
606 ppsc
->fw_current_inpsmode
= *((bool *)val
);
608 case HW_VAR_RESUME_CLK_ON
:
609 _rtl88ee_set_fw_ps_rf_on(hw
);
611 case HW_VAR_FW_LPS_ACTION
:{
612 bool enter_fwlps
= *((bool *)val
);
615 _rtl88ee_fwlps_enter(hw
);
617 _rtl88ee_fwlps_leave(hw
);
620 case HW_VAR_H2C_FW_JOINBSSRPT
:{
622 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
623 u8 count
= 0, dlbcn_count
= 0;
624 bool b_recover
= false;
626 if (mstatus
== RT_MEDIA_CONNECT
) {
627 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
,
630 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
631 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
632 (tmp_regcr
| BIT(0)));
634 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
635 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
638 rtl_read_byte(rtlpriv
,
639 REG_FWHW_TXQ_CTRL
+ 2);
640 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
641 tmp_reg422
& (~BIT(6)));
642 if (tmp_reg422
& BIT(6))
646 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
648 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2,
649 (bcnvalid_reg
| BIT(0)));
650 _rtl88ee_return_beacon_queue_skb(hw
);
652 rtl88e_set_fw_rsvdpagepkt(hw
, 0);
653 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
656 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
660 rtl_read_byte(rtlpriv
, REG_TDECTRL
+2);
663 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
665 if (bcnvalid_reg
& BIT(0))
666 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2, BIT(0));
668 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
669 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
672 rtl_write_byte(rtlpriv
,
673 REG_FWHW_TXQ_CTRL
+ 2,
677 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
678 (tmp_regcr
& ~(BIT(0))));
680 rtl88e_set_fw_joinbss_report_cmd(hw
, (*(u8
*)val
));
682 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
683 rtl88e_set_p2p_ps_offload_cmd(hw
, *val
);
688 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
690 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
693 case HW_VAR_CORRECT_TSF
:{
694 u8 btype_ibss
= *val
;
697 _rtl88ee_stop_tx_beacon(hw
);
699 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
701 rtl_write_dword(rtlpriv
, REG_TSFTR
,
702 (u32
)(mac
->tsf
& 0xffffffff));
703 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
704 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
706 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
709 _rtl88ee_resume_tx_beacon(hw
);
711 case HW_VAR_KEEP_ALIVE
: {
715 array
[1] = *((u8
*)val
);
716 rtl88e_fill_h2c_cmd(hw
, H2C_88E_KEEP_ALIVE_CTRL
,
720 pr_err("switch case %#x not processed\n", variable
);
725 static bool _rtl88ee_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
727 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
730 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
731 _LLT_OP(_LLT_WRITE_ACCESS
);
733 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
736 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
737 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
740 if (count
> POLLING_LLT_THRESHOLD
) {
741 pr_err("Failed to polling write LLT done at address %d!\n",
751 static bool _rtl88ee_llt_table_init(struct ieee80211_hw
*hw
)
753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
760 txpktbuf_bndy
= 0xAB;
762 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x01);
763 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80730d29);
765 /*0x2600 MaxRxBuff=10k-max(TxReportSize(64*8), WOLPattern(16*24)) */
766 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
, (0x25FF0000 | txpktbuf_bndy
));
767 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
769 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
770 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
772 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
773 rtl_write_byte(rtlpriv
, REG_PBP
, 0x11);
774 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
776 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
777 status
= _rtl88ee_llt_write(hw
, i
, i
+ 1);
782 status
= _rtl88ee_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
786 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
787 status
= _rtl88ee_llt_write(hw
, i
, (i
+ 1));
792 status
= _rtl88ee_llt_write(hw
, maxpage
, txpktbuf_bndy
);
799 static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw
*hw
)
801 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
802 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
803 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
805 if (rtlpriv
->rtlhal
.up_first_time
)
808 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
809 rtl88ee_sw_led_on(hw
, pled0
);
810 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
811 rtl88ee_sw_led_on(hw
, pled0
);
813 rtl88ee_sw_led_off(hw
, pled0
);
816 static bool _rtl88ee_init_mac(struct ieee80211_hw
*hw
)
818 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
819 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
820 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
825 /*Disable XTAL OUTPUT for power saving. YJ,add,111206. */
826 bytetmp
= rtl_read_byte(rtlpriv
, REG_XCK_OUT_CTRL
) & (~BIT(0));
827 rtl_write_byte(rtlpriv
, REG_XCK_OUT_CTRL
, bytetmp
);
828 /*Auto Power Down to CHIP-off State*/
829 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
830 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
832 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
833 /* HW Power on sequence */
834 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
835 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
836 RTL8188EE_NIC_ENABLE_FLOW
)) {
837 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
838 "init MAC Fail as rtl_hal_pwrseqcmdparsing\n");
842 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
843 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
845 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2);
846 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2, bytetmp
|BIT(2));
848 bytetmp
= rtl_read_byte(rtlpriv
, REG_WATCH_DOG
+1);
849 rtl_write_byte(rtlpriv
, REG_WATCH_DOG
+1, bytetmp
|BIT(7));
851 bytetmp
= rtl_read_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1);
852 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1, bytetmp
|BIT(1));
854 bytetmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
855 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, bytetmp
|BIT(1)|BIT(0));
856 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
+1, 2);
857 rtl_write_word(rtlpriv
, REG_TX_RPT_TIME
, 0xcdf0);
859 /*Add for wake up online*/
860 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
862 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, bytetmp
|BIT(3));
863 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+1);
864 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+1, (bytetmp
& (~BIT(4))));
865 rtl_write_byte(rtlpriv
, 0x367, 0x80);
867 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
868 rtl_write_byte(rtlpriv
, REG_CR
+1, 0x06);
869 rtl_write_byte(rtlpriv
, MSR
, 0x00);
871 if (!rtlhal
->mac_func_enable
) {
872 if (_rtl88ee_llt_table_init(hw
) == false) {
873 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
874 "LLT table init fail\n");
878 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
879 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
881 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
884 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
886 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
887 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xffff);
888 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
890 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
891 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
893 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
894 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
896 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
897 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
898 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
899 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
900 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
901 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
902 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
903 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
904 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
905 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
907 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
908 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
911 /* if we want to support 64 bit DMA, we should set it here,
912 * but now we do not support 64 bit DMA
914 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
916 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
917 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0);/*Enable RX DMA */
919 if (rtlhal
->earlymode_enable
) {/*Early mode enable*/
920 bytetmp
= rtl_read_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
);
922 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, bytetmp
);
923 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
+3, 0x81);
925 _rtl88ee_gen_refresh_led_state(hw
);
929 static void _rtl88ee_hw_configure(struct ieee80211_hw
*hw
)
931 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
934 reg_prsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
936 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_prsr
);
937 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
940 static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw
*hw
)
942 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
943 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
945 u32 tmp4byte
= 0, count
= 0;
947 rtl_write_word(rtlpriv
, 0x354, 0x8104);
948 rtl_write_word(rtlpriv
, 0x358, 0x24);
950 rtl_write_word(rtlpriv
, 0x350, 0x70c);
951 rtl_write_byte(rtlpriv
, 0x352, 0x2);
952 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
954 while (tmp1byte
&& count
< 20) {
956 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
960 tmp4byte
= rtl_read_dword(rtlpriv
, 0x34c);
961 rtl_write_dword(rtlpriv
, 0x348, tmp4byte
|BIT(31));
962 rtl_write_word(rtlpriv
, 0x350, 0xf70c);
963 rtl_write_byte(rtlpriv
, 0x352, 0x1);
966 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
968 while (tmp1byte
&& count
< 20) {
970 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
974 rtl_write_word(rtlpriv
, 0x350, 0x718);
975 rtl_write_byte(rtlpriv
, 0x352, 0x2);
976 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
978 while (tmp1byte
&& count
< 20) {
980 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
984 if (ppsc
->support_backdoor
|| (0 == tmp1byte
)) {
985 tmp4byte
= rtl_read_dword(rtlpriv
, 0x34c);
986 rtl_write_dword(rtlpriv
, 0x348, tmp4byte
|BIT(11)|BIT(12));
987 rtl_write_word(rtlpriv
, 0x350, 0xf718);
988 rtl_write_byte(rtlpriv
, 0x352, 0x1);
991 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
993 while (tmp1byte
&& count
< 20) {
995 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
1000 void rtl88ee_enable_hw_security_config(struct ieee80211_hw
*hw
)
1002 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1005 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1006 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1007 rtlpriv
->sec
.pairwise_enc_algorithm
,
1008 rtlpriv
->sec
.group_enc_algorithm
);
1010 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1011 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1012 "not open hw encryption\n");
1016 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1018 if (rtlpriv
->sec
.use_defaultkey
) {
1019 sec_reg_value
|= SCR_TXUSEDK
;
1020 sec_reg_value
|= SCR_RXUSEDK
;
1023 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1025 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1027 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1028 "The SECR-value %x\n", sec_reg_value
);
1030 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1033 int rtl88ee_hw_init(struct ieee80211_hw
*hw
)
1035 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1036 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1037 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1038 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1039 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1040 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1041 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1045 unsigned long flags
;
1047 rtlpriv
->rtlhal
.being_init_adapter
= true;
1048 /* As this function can take a very long time (up to 350 ms)
1049 * and can be called with irqs disabled, reenable the irqs
1050 * to let the other devices continue being serviced.
1052 * It is safe doing so since our own interrupts will only be enabled
1053 * in a subsequent step.
1055 local_save_flags(flags
);
1057 rtlhal
->fw_ready
= false;
1059 rtlpriv
->intf_ops
->disable_aspm(hw
);
1061 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
+1);
1062 u1byte
= rtl_read_byte(rtlpriv
, REG_CR
);
1063 if ((tmp_u1b
& BIT(3)) && (u1byte
!= 0 && u1byte
!= 0xEA)) {
1064 rtlhal
->mac_func_enable
= true;
1066 rtlhal
->mac_func_enable
= false;
1067 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1070 rtstatus
= _rtl88ee_init_mac(hw
);
1071 if (rtstatus
!= true) {
1072 pr_info("Init MAC failed\n");
1077 err
= rtl88e_download_fw(hw
, false);
1079 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1080 "Failed to download FW. Init HW without FW now..\n");
1084 rtlhal
->fw_ready
= true;
1085 /*fw related variable initialize */
1086 rtlhal
->last_hmeboxnum
= 0;
1087 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1088 rtlhal
->fw_clk_change_in_progress
= false;
1089 rtlhal
->allow_sw_to_change_hwclc
= false;
1090 ppsc
->fw_current_inpsmode
= false;
1092 rtl88e_phy_mac_config(hw
);
1093 /* because last function modify RCR, so we update
1094 * rcr var here, or TP will unstable for receive_config
1095 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1096 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1098 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1099 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1101 rtl88e_phy_bb_config(hw
);
1102 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1103 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1105 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1106 rtl88e_phy_rf_config(hw
);
1108 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1109 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1110 rtlphy
->rfreg_chnlval
[0] = rtlphy
->rfreg_chnlval
[0] & 0xfff00fff;
1112 _rtl88ee_hw_configure(hw
);
1113 rtl_cam_reset_all_entry(hw
);
1114 rtl88ee_enable_hw_security_config(hw
);
1116 rtlhal
->mac_func_enable
= true;
1117 ppsc
->rfpwr_state
= ERFON
;
1119 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1120 _rtl88ee_enable_aspm_back_door(hw
);
1121 rtlpriv
->intf_ops
->enable_aspm(hw
);
1123 if (ppsc
->rfpwr_state
== ERFON
) {
1124 if ((rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
) ||
1125 ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) &&
1126 (rtlhal
->oem_id
== RT_CID_819X_HP
))) {
1127 rtl88e_phy_set_rfpath_switch(hw
, true);
1128 rtlpriv
->dm
.fat_table
.rx_idle_ant
= MAIN_ANT
;
1130 rtl88e_phy_set_rfpath_switch(hw
, false);
1131 rtlpriv
->dm
.fat_table
.rx_idle_ant
= AUX_ANT
;
1133 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rx idle ant %s\n",
1134 (rtlpriv
->dm
.fat_table
.rx_idle_ant
== MAIN_ANT
) ?
1135 ("MAIN_ANT") : ("AUX_ANT"));
1137 if (rtlphy
->iqk_initialized
) {
1138 rtl88e_phy_iq_calibrate(hw
, true);
1140 rtl88e_phy_iq_calibrate(hw
, false);
1141 rtlphy
->iqk_initialized
= true;
1144 rtl88e_dm_check_txpower_tracking(hw
);
1145 rtl88e_phy_lc_calibrate(hw
);
1148 tmp_u1b
= efuse_read_1byte(hw
, 0x1FA);
1149 if (!(tmp_u1b
& BIT(0))) {
1150 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0F, 0x05);
1151 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "PA BIAS path A\n");
1154 if (!(tmp_u1b
& BIT(4))) {
1155 tmp_u1b
= rtl_read_byte(rtlpriv
, 0x16);
1157 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x80);
1159 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x90);
1160 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "under 1.5V\n");
1162 rtl_write_byte(rtlpriv
, REG_NAV_CTRL
+2, ((30000+127)/128));
1165 local_irq_restore(flags
);
1166 rtlpriv
->rtlhal
.being_init_adapter
= false;
1170 static enum version_8188e
_rtl88ee_read_chip_version(struct ieee80211_hw
*hw
)
1172 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1173 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1174 enum version_8188e version
= VERSION_UNKNOWN
;
1177 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
1178 if (value32
& TRP_VAUX_EN
) {
1179 version
= (enum version_8188e
) VERSION_TEST_CHIP_88E
;
1181 version
= NORMAL_CHIP
;
1182 version
= version
| ((value32
& TYPE_ID
) ? RF_TYPE_2T2R
: 0);
1183 version
= version
| ((value32
& VENDOR_ID
) ?
1184 CHIP_VENDOR_UMC
: 0);
1187 rtlphy
->rf_type
= RF_1T1R
;
1188 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1189 "Chip RF Type: %s\n", (rtlphy
->rf_type
== RF_2T2R
) ?
1190 "RF_2T2R" : "RF_1T1R");
1195 static int _rtl88ee_set_media_status(struct ieee80211_hw
*hw
,
1196 enum nl80211_iftype type
)
1198 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1199 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & 0xfc;
1200 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1201 u8 mode
= MSR_NOLINK
;
1204 case NL80211_IFTYPE_UNSPECIFIED
:
1206 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1207 "Set Network type to NO LINK!\n");
1209 case NL80211_IFTYPE_ADHOC
:
1210 case NL80211_IFTYPE_MESH_POINT
:
1212 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1213 "Set Network type to Ad Hoc!\n");
1215 case NL80211_IFTYPE_STATION
:
1217 ledaction
= LED_CTL_LINK
;
1218 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1219 "Set Network type to STA!\n");
1221 case NL80211_IFTYPE_AP
:
1223 ledaction
= LED_CTL_LINK
;
1224 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1225 "Set Network type to AP!\n");
1228 pr_err("Network type %d not support!\n", type
);
1233 /* MSR_INFRA == Link in infrastructure network;
1234 * MSR_ADHOC == Link in ad hoc network;
1235 * Therefore, check link state is necessary.
1237 * MSR_AP == AP mode; link state is not cared here.
1239 if (mode
!= MSR_AP
&& rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
) {
1241 ledaction
= LED_CTL_NO_LINK
;
1244 if (mode
== MSR_NOLINK
|| mode
== MSR_INFRA
) {
1245 _rtl88ee_stop_tx_beacon(hw
);
1246 _rtl88ee_enable_bcn_sub_func(hw
);
1247 } else if (mode
== MSR_ADHOC
|| mode
== MSR_AP
) {
1248 _rtl88ee_resume_tx_beacon(hw
);
1249 _rtl88ee_disable_bcn_sub_func(hw
);
1251 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1252 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1256 rtl_write_byte(rtlpriv
, MSR
, bt_msr
| mode
);
1257 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1259 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1261 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1265 void rtl88ee_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1267 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1268 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1269 u32 reg_rcr
= rtlpci
->receive_config
;
1271 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1274 if (check_bssid
== true) {
1275 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1276 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1278 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1279 } else if (check_bssid
== false) {
1280 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1281 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1282 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1283 HW_VAR_RCR
, (u8
*)(®_rcr
));
1288 int rtl88ee_set_network_type(struct ieee80211_hw
*hw
,
1289 enum nl80211_iftype type
)
1291 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1293 if (_rtl88ee_set_media_status(hw
, type
))
1296 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1297 if (type
!= NL80211_IFTYPE_AP
&&
1298 type
!= NL80211_IFTYPE_MESH_POINT
)
1299 rtl88ee_set_check_bssid(hw
, true);
1301 rtl88ee_set_check_bssid(hw
, false);
1307 /* don't set REG_EDCA_BE_PARAM here
1308 * because mac80211 will send pkt when scan
1310 void rtl88ee_set_qos(struct ieee80211_hw
*hw
, int aci
)
1312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1313 rtl88e_dm_init_edca_turbo(hw
);
1316 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1321 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1324 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1327 WARN_ONCE(true, "rtl8188ee: invalid aci: %d !\n", aci
);
1332 void rtl88ee_enable_interrupt(struct ieee80211_hw
*hw
)
1334 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1335 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1337 rtl_write_dword(rtlpriv
, REG_HIMR
,
1338 rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1339 rtl_write_dword(rtlpriv
, REG_HIMRE
,
1340 rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1341 rtlpci
->irq_enabled
= true;
1342 /* there are some C2H CMDs have been sent
1343 * before system interrupt is enabled, e.g., C2H, CPWM.
1344 * So we need to clear all C2H events that FW has notified,
1345 * otherwise FW won't schedule any commands anymore.
1347 rtl_write_byte(rtlpriv
, REG_C2HEVT_CLEAR
, 0);
1348 /*enable system interrupt*/
1349 rtl_write_dword(rtlpriv
, REG_HSIMR
,
1350 rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
1353 void rtl88ee_disable_interrupt(struct ieee80211_hw
*hw
)
1355 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1356 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1358 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
1359 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
1360 rtlpci
->irq_enabled
= false;
1361 /*synchronize_irq(rtlpci->pdev->irq);*/
1364 static void _rtl88ee_poweroff_adapter(struct ieee80211_hw
*hw
)
1366 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1367 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1370 rtlhal
->mac_func_enable
= false;
1371 rtlpriv
->intf_ops
->enable_aspm(hw
);
1373 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "POWER OFF adapter\n");
1374 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
1375 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, u1b_tmp
& (~BIT(1)));
1377 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1378 while (!(u1b_tmp
& BIT(1)) && (count
++ < 100)) {
1380 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1383 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0xFF);
1385 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1387 RTL8188EE_NIC_LPS_ENTER_FLOW
);
1389 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, 0x00);
1391 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) && rtlhal
->fw_ready
)
1392 rtl88e_firmware_selfreset(hw
);
1394 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1395 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, (u1b_tmp
& (~BIT(2))));
1396 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1398 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_32K_CTRL
);
1399 rtl_write_byte(rtlpriv
, REG_32K_CTRL
, (u1b_tmp
& (~BIT(0))));
1401 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1402 PWR_INTF_PCI_MSK
, RTL8188EE_NIC_DISABLE_FLOW
);
1404 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1405 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
& (~BIT(3))));
1406 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1407 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
| BIT(3)));
1409 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1411 u1b_tmp
= rtl_read_byte(rtlpriv
, GPIO_IN
);
1412 rtl_write_byte(rtlpriv
, GPIO_OUT
, u1b_tmp
);
1413 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, 0x7F);
1415 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
1416 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
, (u1b_tmp
<< 4) | u1b_tmp
);
1417 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
+1);
1418 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
+1, u1b_tmp
| 0x0F);
1420 rtl_write_dword(rtlpriv
, REG_GPIO_IO_SEL_2
+2, 0x00080808);
1423 void rtl88ee_card_disable(struct ieee80211_hw
*hw
)
1425 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1426 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1427 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1428 enum nl80211_iftype opmode
;
1430 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "RTL8188ee card disable\n");
1432 mac
->link_state
= MAC80211_NOLINK
;
1433 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1435 _rtl88ee_set_media_status(hw
, opmode
);
1437 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1438 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1439 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1441 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1442 _rtl88ee_poweroff_adapter(hw
);
1444 /* after power off we should do iqk again */
1445 rtlpriv
->phy
.iqk_initialized
= false;
1448 void rtl88ee_interrupt_recognized(struct ieee80211_hw
*hw
,
1449 struct rtl_int
*intvec
)
1451 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1452 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1454 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1455 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1457 intvec
->intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) & rtlpci
->irq_mask
[1];
1458 rtl_write_dword(rtlpriv
, REG_HISRE
, intvec
->intb
);
1462 void rtl88ee_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1464 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1465 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1466 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1467 u16 bcn_interval
, atim_window
;
1469 bcn_interval
= mac
->beacon_interval
;
1470 atim_window
= 2; /*FIX MERGE */
1471 rtl88ee_disable_interrupt(hw
);
1472 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1473 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1474 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1475 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1476 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1477 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1478 rtlpci
->reg_bcn_ctrl_val
|= BIT(3);
1479 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
1480 /*rtl88ee_enable_interrupt(hw);*/
1483 void rtl88ee_set_beacon_interval(struct ieee80211_hw
*hw
)
1485 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1486 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1487 u16 bcn_interval
= mac
->beacon_interval
;
1489 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1490 "beacon_interval:%d\n", bcn_interval
);
1491 /*rtl88ee_disable_interrupt(hw);*/
1492 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1493 /*rtl88ee_enable_interrupt(hw);*/
1496 void rtl88ee_update_interrupt_mask(struct ieee80211_hw
*hw
,
1497 u32 add_msr
, u32 rm_msr
)
1499 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1500 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1502 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1503 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1506 rtlpci
->irq_mask
[0] |= add_msr
;
1508 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1509 rtl88ee_disable_interrupt(hw
);
1510 rtl88ee_enable_interrupt(hw
);
1513 static u8
_rtl88e_get_chnl_group(u8 chnl
)
1527 else if (chnl
== 14)
1533 static void set_24g_base(struct txpower_info_2g
*pwrinfo24g
, u32 rfpath
)
1537 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1538 pwrinfo24g
->index_cck_base
[rfpath
][group
] = 0x2D;
1539 pwrinfo24g
->index_bw40_base
[rfpath
][group
] = 0x2D;
1541 for (txcnt
= 0; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1543 pwrinfo24g
->bw20_diff
[rfpath
][0] = 0x02;
1544 pwrinfo24g
->ofdm_diff
[rfpath
][0] = 0x04;
1546 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] = 0xFE;
1547 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1548 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] = 0xFE;
1549 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1554 static void read_power_value_fromprom(struct ieee80211_hw
*hw
,
1555 struct txpower_info_2g
*pwrinfo24g
,
1556 struct txpower_info_5g
*pwrinfo5g
,
1557 bool autoload_fail
, u8
*hwinfo
)
1559 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1560 u32 rfpath
, eeaddr
= EEPROM_TX_PWR_INX
, group
, txcnt
= 0;
1562 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1563 "hal_ReadPowerValueFromPROM88E():PROMContent[0x%x]=0x%x\n",
1564 (eeaddr
+1), hwinfo
[eeaddr
+1]);
1565 if (0xFF == hwinfo
[eeaddr
+1]) /*YJ,add,120316*/
1566 autoload_fail
= true;
1568 if (autoload_fail
) {
1569 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1570 "auto load fail : Use Default value!\n");
1571 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
1572 /* 2.4G default value */
1573 set_24g_base(pwrinfo24g
, rfpath
);
1578 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
1579 /*2.4G default value*/
1580 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1581 pwrinfo24g
->index_cck_base
[rfpath
][group
] =
1583 if (pwrinfo24g
->index_cck_base
[rfpath
][group
] == 0xFF)
1584 pwrinfo24g
->index_cck_base
[rfpath
][group
] =
1587 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
-1; group
++) {
1588 pwrinfo24g
->index_bw40_base
[rfpath
][group
] =
1590 if (pwrinfo24g
->index_bw40_base
[rfpath
][group
] == 0xFF)
1591 pwrinfo24g
->index_bw40_base
[rfpath
][group
] =
1594 pwrinfo24g
->bw40_diff
[rfpath
][0] = 0;
1595 if (hwinfo
[eeaddr
] == 0xFF) {
1596 pwrinfo24g
->bw20_diff
[rfpath
][0] = 0x02;
1598 pwrinfo24g
->bw20_diff
[rfpath
][0] =
1599 (hwinfo
[eeaddr
]&0xf0)>>4;
1600 /*bit sign number to 8 bit sign number*/
1601 if (pwrinfo24g
->bw20_diff
[rfpath
][0] & BIT(3))
1602 pwrinfo24g
->bw20_diff
[rfpath
][0] |= 0xF0;
1605 if (hwinfo
[eeaddr
] == 0xFF) {
1606 pwrinfo24g
->ofdm_diff
[rfpath
][0] = 0x04;
1608 pwrinfo24g
->ofdm_diff
[rfpath
][0] =
1609 (hwinfo
[eeaddr
]&0x0f);
1610 /*bit sign number to 8 bit sign number*/
1611 if (pwrinfo24g
->ofdm_diff
[rfpath
][0] & BIT(3))
1612 pwrinfo24g
->ofdm_diff
[rfpath
][0] |= 0xF0;
1614 pwrinfo24g
->cck_diff
[rfpath
][0] = 0;
1616 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1617 if (hwinfo
[eeaddr
] == 0xFF) {
1618 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1620 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] =
1621 (hwinfo
[eeaddr
]&0xf0)>>4;
1622 if (pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] &
1624 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] |=
1628 if (hwinfo
[eeaddr
] == 0xFF) {
1629 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] =
1632 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] =
1633 (hwinfo
[eeaddr
]&0x0f);
1634 if (pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] &
1636 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] |=
1641 if (hwinfo
[eeaddr
] == 0xFF) {
1642 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1644 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] =
1645 (hwinfo
[eeaddr
]&0xf0)>>4;
1646 if (pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] &
1648 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] |=
1652 if (hwinfo
[eeaddr
] == 0xFF) {
1653 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] = 0xFE;
1655 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] =
1656 (hwinfo
[eeaddr
]&0x0f);
1657 if (pwrinfo24g
->cck_diff
[rfpath
][txcnt
] &
1659 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] |=
1665 /*5G default value*/
1666 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++) {
1667 pwrinfo5g
->index_bw40_base
[rfpath
][group
] =
1669 if (pwrinfo5g
->index_bw40_base
[rfpath
][group
] == 0xFF)
1670 pwrinfo5g
->index_bw40_base
[rfpath
][group
] =
1674 pwrinfo5g
->bw40_diff
[rfpath
][0] = 0;
1676 if (hwinfo
[eeaddr
] == 0xFF) {
1677 pwrinfo5g
->bw20_diff
[rfpath
][0] = 0;
1679 pwrinfo5g
->bw20_diff
[rfpath
][0] =
1680 (hwinfo
[eeaddr
]&0xf0)>>4;
1681 if (pwrinfo5g
->bw20_diff
[rfpath
][0] & BIT(3))
1682 pwrinfo5g
->bw20_diff
[rfpath
][0] |= 0xF0;
1685 if (hwinfo
[eeaddr
] == 0xFF) {
1686 pwrinfo5g
->ofdm_diff
[rfpath
][0] = 0x04;
1688 pwrinfo5g
->ofdm_diff
[rfpath
][0] = (hwinfo
[eeaddr
]&0x0f);
1689 if (pwrinfo5g
->ofdm_diff
[rfpath
][0] & BIT(3))
1690 pwrinfo5g
->ofdm_diff
[rfpath
][0] |= 0xF0;
1693 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1694 if (hwinfo
[eeaddr
] == 0xFF) {
1695 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1697 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] =
1698 (hwinfo
[eeaddr
]&0xf0)>>4;
1699 if (pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] &
1701 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] |=
1705 if (hwinfo
[eeaddr
] == 0xFF) {
1706 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] = 0xFE;
1708 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] =
1709 (hwinfo
[eeaddr
]&0x0f);
1710 if (pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] &
1712 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] |=
1718 if (hwinfo
[eeaddr
] == 0xFF) {
1719 pwrinfo5g
->ofdm_diff
[rfpath
][1] = 0xFE;
1720 pwrinfo5g
->ofdm_diff
[rfpath
][2] = 0xFE;
1722 pwrinfo5g
->ofdm_diff
[rfpath
][1] =
1723 (hwinfo
[eeaddr
]&0xf0)>>4;
1724 pwrinfo5g
->ofdm_diff
[rfpath
][2] =
1725 (hwinfo
[eeaddr
]&0x0f);
1729 if (hwinfo
[eeaddr
] == 0xFF)
1730 pwrinfo5g
->ofdm_diff
[rfpath
][3] = 0xFE;
1732 pwrinfo5g
->ofdm_diff
[rfpath
][3] = (hwinfo
[eeaddr
]&0x0f);
1735 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1736 if (pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] == 0xFF)
1737 pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1738 else if (pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] & BIT(3))
1739 pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] |= 0xF0;
1744 static void _rtl88ee_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1748 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1749 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1750 struct txpower_info_2g pwrinfo24g
;
1751 struct txpower_info_5g pwrinfo5g
;
1755 read_power_value_fromprom(hw
, &pwrinfo24g
,
1756 &pwrinfo5g
, autoload_fail
, hwinfo
);
1758 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1759 for (i
= 0; i
< 14; i
++) {
1760 index
= _rtl88e_get_chnl_group(i
+1);
1762 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1763 pwrinfo24g
.index_cck_base
[rf_path
][index
];
1764 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1765 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
1766 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
1767 pwrinfo24g
.bw20_diff
[rf_path
][0];
1768 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
1769 pwrinfo24g
.ofdm_diff
[rf_path
][0];
1772 for (i
= 0; i
< 14; i
++) {
1773 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1774 "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n",
1776 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1777 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
]);
1782 rtlefuse
->eeprom_thermalmeter
=
1783 hwinfo
[EEPROM_THERMAL_METER_88E
];
1785 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1787 if (rtlefuse
->eeprom_thermalmeter
== 0xff || autoload_fail
) {
1788 rtlefuse
->apk_thermalmeterignore
= true;
1789 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1792 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1793 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1794 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1796 if (!autoload_fail
) {
1797 rtlefuse
->eeprom_regulatory
=
1798 hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x07;/*bit0~2*/
1799 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
1800 rtlefuse
->eeprom_regulatory
= 0;
1802 rtlefuse
->eeprom_regulatory
= 0;
1804 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1805 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1808 static void _rtl88ee_read_adapter_info(struct ieee80211_hw
*hw
)
1810 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1811 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1812 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1813 int params
[] = {RTL8188E_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
1814 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
1815 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
1816 COUNTRY_CODE_WORLD_WIDE_13
};
1819 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
1823 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
1826 if (rtlefuse
->eeprom_oemid
== 0xFF)
1827 rtlefuse
->eeprom_oemid
= 0;
1829 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1830 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1831 /* set channel plan from efuse */
1832 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
1834 _rtl88ee_read_txpower_info_from_hwpg(hw
,
1835 rtlefuse
->autoload_failflag
,
1837 rtlefuse
->txpwr_fromeprom
= true;
1839 rtl8188ee_read_bt_coexist_info_from_hwpg(hw
,
1840 rtlefuse
->autoload_failflag
,
1844 rtlefuse
->board_type
=
1845 ((hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0xE0) >> 5);
1846 rtlhal
->board_type
= rtlefuse
->board_type
;
1848 rtlefuse
->wowlan_enable
=
1849 ((hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] & 0x40) >> 6);
1851 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_88E
];
1852 if (hwinfo
[EEPROM_XTAL_88E
])
1853 rtlefuse
->crystalcap
= 0x20;
1854 /*antenna diversity*/
1855 rtlefuse
->antenna_div_cfg
=
1856 (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x18) >> 3;
1857 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
1858 rtlefuse
->antenna_div_cfg
= 0;
1859 if (rtlpriv
->btcoexist
.eeprom_bt_coexist
!= 0 &&
1860 rtlpriv
->btcoexist
.eeprom_bt_ant_num
== ANT_X1
)
1861 rtlefuse
->antenna_div_cfg
= 0;
1863 rtlefuse
->antenna_div_type
= hwinfo
[EEPROM_RF_ANTENNA_OPT_88E
];
1864 if (rtlefuse
->antenna_div_type
== 0xFF)
1865 rtlefuse
->antenna_div_type
= 0x01;
1866 if (rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
||
1867 rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1868 rtlefuse
->antenna_div_cfg
= 1;
1870 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
1871 switch (rtlefuse
->eeprom_oemid
) {
1872 case EEPROM_CID_DEFAULT
:
1873 if (rtlefuse
->eeprom_did
== 0x8179) {
1874 if (rtlefuse
->eeprom_svid
== 0x1025) {
1875 rtlhal
->oem_id
= RT_CID_819X_ACER
;
1876 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
1877 rtlefuse
->eeprom_smid
== 0x0179) ||
1878 (rtlefuse
->eeprom_svid
== 0x17AA &&
1879 rtlefuse
->eeprom_smid
== 0x0179)) {
1880 rtlhal
->oem_id
= RT_CID_819X_LENOVO
;
1881 } else if (rtlefuse
->eeprom_svid
== 0x103c &&
1882 rtlefuse
->eeprom_smid
== 0x197d) {
1883 rtlhal
->oem_id
= RT_CID_819X_HP
;
1885 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1888 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1891 case EEPROM_CID_TOSHIBA
:
1892 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1894 case EEPROM_CID_QMI
:
1895 rtlhal
->oem_id
= RT_CID_819X_QMI
;
1897 case EEPROM_CID_WHQL
:
1899 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1908 static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw
*hw
)
1910 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1911 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1913 rtlpriv
->ledctl
.led_opendrain
= true;
1915 switch (rtlhal
->oem_id
) {
1916 case RT_CID_819X_HP
:
1917 rtlpriv
->ledctl
.led_opendrain
= true;
1919 case RT_CID_819X_LENOVO
:
1920 case RT_CID_DEFAULT
:
1921 case RT_CID_TOSHIBA
:
1923 case RT_CID_819X_ACER
:
1928 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1929 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
1932 void rtl88ee_read_eeprom_info(struct ieee80211_hw
*hw
)
1934 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1935 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1936 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1937 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1940 rtlhal
->version
= _rtl88ee_read_chip_version(hw
);
1941 if (get_rf_type(rtlphy
) == RF_1T1R
)
1942 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
1944 rtlpriv
->dm
.rfpath_rxenable
[0] =
1945 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
1946 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
1948 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
1949 if (tmp_u1b
& BIT(4)) {
1950 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1951 rtlefuse
->epromtype
= EEPROM_93C46
;
1953 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1954 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1956 if (tmp_u1b
& BIT(5)) {
1957 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1958 rtlefuse
->autoload_failflag
= false;
1959 _rtl88ee_read_adapter_info(hw
);
1961 pr_err("Autoload ERR!!\n");
1963 _rtl88ee_hal_customized_behavior(hw
);
1966 static void rtl88ee_update_hal_rate_table(struct ieee80211_hw
*hw
,
1967 struct ieee80211_sta
*sta
)
1969 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1970 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1971 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1972 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1975 u8 b_nmode
= mac
->ht_enable
;
1976 /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
1979 u8 curtxbw_40mhz
= mac
->bw_40
;
1980 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
1982 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
1984 enum wireless_mode wirelessmode
= mac
->mode
;
1987 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1988 ratr_value
= sta
->supp_rates
[1] << 4;
1990 ratr_value
= sta
->supp_rates
[0];
1991 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1993 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
1994 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
1995 switch (wirelessmode
) {
1996 case WIRELESS_MODE_B
:
1997 if (ratr_value
& 0x0000000c)
1998 ratr_value
&= 0x0000000d;
2000 ratr_value
&= 0x0000000f;
2002 case WIRELESS_MODE_G
:
2003 ratr_value
&= 0x00000FF5;
2005 case WIRELESS_MODE_N_24G
:
2006 case WIRELESS_MODE_N_5G
:
2008 if (get_rf_type(rtlphy
) == RF_1T2R
||
2009 get_rf_type(rtlphy
) == RF_1T1R
)
2010 ratr_mask
= 0x000ff005;
2012 ratr_mask
= 0x0f0ff005;
2014 ratr_value
&= ratr_mask
;
2017 if (rtlphy
->rf_type
== RF_1T2R
)
2018 ratr_value
&= 0x000ff0ff;
2020 ratr_value
&= 0x0f0ff0ff;
2025 if ((rtlpriv
->btcoexist
.bt_coexistence
) &&
2026 (rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) &&
2027 (rtlpriv
->btcoexist
.bt_cur_state
) &&
2028 (rtlpriv
->btcoexist
.bt_ant_isolation
) &&
2029 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ||
2030 (rtlpriv
->btcoexist
.bt_service
== BT_BUSY
)))
2031 ratr_value
&= 0x0fffcfc0;
2033 ratr_value
&= 0x0FFFFFFF;
2036 ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2037 (!curtxbw_40mhz
&& curshortgi_20mhz
))) {
2038 ratr_value
|= 0x10000000;
2039 tmp_ratr_value
= (ratr_value
>> 12);
2041 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2042 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2046 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2047 (shortgi_rate
<< 4) | (shortgi_rate
);
2050 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2052 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2053 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
2056 static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2057 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2059 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2060 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2061 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2062 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2063 struct rtl_sta_info
*sta_entry
= NULL
;
2066 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)
2068 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2070 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2072 enum wireless_mode wirelessmode
= 0;
2073 bool b_shortgi
= false;
2076 /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
2078 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
2079 wirelessmode
= sta_entry
->wireless_mode
;
2080 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2081 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2082 curtxbw_40mhz
= mac
->bw_40
;
2083 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2084 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2085 macid
= sta
->aid
+ 1;
2087 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2088 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2090 ratr_bitmap
= sta
->supp_rates
[0];
2091 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2092 ratr_bitmap
= 0xfff;
2093 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2094 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2095 switch (wirelessmode
) {
2096 case WIRELESS_MODE_B
:
2097 ratr_index
= RATR_INX_WIRELESS_B
;
2098 if (ratr_bitmap
& 0x0000000c)
2099 ratr_bitmap
&= 0x0000000d;
2101 ratr_bitmap
&= 0x0000000f;
2103 case WIRELESS_MODE_G
:
2104 ratr_index
= RATR_INX_WIRELESS_GB
;
2106 if (rssi_level
== 1)
2107 ratr_bitmap
&= 0x00000f00;
2108 else if (rssi_level
== 2)
2109 ratr_bitmap
&= 0x00000ff0;
2111 ratr_bitmap
&= 0x00000ff5;
2113 case WIRELESS_MODE_N_24G
:
2114 case WIRELESS_MODE_N_5G
:
2115 ratr_index
= RATR_INX_WIRELESS_NGB
;
2116 if (rtlphy
->rf_type
== RF_1T2R
||
2117 rtlphy
->rf_type
== RF_1T1R
) {
2118 if (curtxbw_40mhz
) {
2119 if (rssi_level
== 1)
2120 ratr_bitmap
&= 0x000f0000;
2121 else if (rssi_level
== 2)
2122 ratr_bitmap
&= 0x000ff000;
2124 ratr_bitmap
&= 0x000ff015;
2126 if (rssi_level
== 1)
2127 ratr_bitmap
&= 0x000f0000;
2128 else if (rssi_level
== 2)
2129 ratr_bitmap
&= 0x000ff000;
2131 ratr_bitmap
&= 0x000ff005;
2134 if (curtxbw_40mhz
) {
2135 if (rssi_level
== 1)
2136 ratr_bitmap
&= 0x0f8f0000;
2137 else if (rssi_level
== 2)
2138 ratr_bitmap
&= 0x0f8ff000;
2140 ratr_bitmap
&= 0x0f8ff015;
2142 if (rssi_level
== 1)
2143 ratr_bitmap
&= 0x0f8f0000;
2144 else if (rssi_level
== 2)
2145 ratr_bitmap
&= 0x0f8ff000;
2147 ratr_bitmap
&= 0x0f8ff005;
2152 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2153 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2157 else if (macid
== 1)
2162 ratr_index
= RATR_INX_WIRELESS_NGB
;
2164 if (rtlphy
->rf_type
== RF_1T2R
)
2165 ratr_bitmap
&= 0x000ff0ff;
2167 ratr_bitmap
&= 0x0f0ff0ff;
2170 sta_entry
->ratr_index
= ratr_index
;
2172 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2173 "ratr_bitmap :%x\n", ratr_bitmap
);
2174 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2176 rate_mask
[4] = macid
| (b_shortgi
? 0x20 : 0x00) | 0x80;
2177 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2178 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
2179 ratr_index
, ratr_bitmap
,
2180 rate_mask
[0], rate_mask
[1],
2181 rate_mask
[2], rate_mask
[3],
2183 rtl88e_fill_h2c_cmd(hw
, H2C_88E_RA_MASK
, 5, rate_mask
);
2184 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2187 void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2188 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2190 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2192 if (rtlpriv
->dm
.useramask
)
2193 rtl88ee_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2195 rtl88ee_update_hal_rate_table(hw
, sta
);
2198 void rtl88ee_update_channel_access_setting(struct ieee80211_hw
*hw
)
2200 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2201 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2204 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
, &mac
->slot_time
);
2205 if (!mac
->ht_enable
)
2206 sifs_timer
= 0x0a0a;
2208 sifs_timer
= 0x0e0e;
2209 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2212 bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2214 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2215 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2216 enum rf_pwrstate e_rfpowerstate_toset
;
2218 bool b_actuallyset
= false;
2220 if (rtlpriv
->rtlhal
.being_init_adapter
)
2223 if (ppsc
->swrf_processing
)
2226 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2227 if (ppsc
->rfchange_inprogress
) {
2228 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2231 ppsc
->rfchange_inprogress
= true;
2232 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2235 u4tmp
= rtl_read_dword(rtlpriv
, REG_GPIO_OUTPUT
);
2236 e_rfpowerstate_toset
= (u4tmp
& BIT(31)) ? ERFON
: ERFOFF
;
2238 if (ppsc
->hwradiooff
&& (e_rfpowerstate_toset
== ERFON
)) {
2239 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2240 "GPIOChangeRF - HW Radio ON, RF ON\n");
2242 e_rfpowerstate_toset
= ERFON
;
2243 ppsc
->hwradiooff
= false;
2244 b_actuallyset
= true;
2245 } else if ((!ppsc
->hwradiooff
) &&
2246 (e_rfpowerstate_toset
== ERFOFF
)) {
2247 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2248 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2250 e_rfpowerstate_toset
= ERFOFF
;
2251 ppsc
->hwradiooff
= true;
2252 b_actuallyset
= true;
2255 if (b_actuallyset
) {
2256 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2257 ppsc
->rfchange_inprogress
= false;
2258 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2260 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2261 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2263 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2264 ppsc
->rfchange_inprogress
= false;
2265 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2269 return !ppsc
->hwradiooff
;
2273 void rtl88ee_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
2274 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
2275 bool is_wepkey
, bool clear_all
)
2277 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2278 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2279 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2280 u8
*macaddr
= p_macaddr
;
2282 bool is_pairwise
= false;
2283 static u8 cam_const_addr
[4][6] = {
2284 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2285 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2286 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2287 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2289 static u8 cam_const_broad
[] = {
2290 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2296 u8 clear_number
= 5;
2298 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2300 for (idx
= 0; idx
< clear_number
; idx
++) {
2301 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2302 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2305 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2307 rtlpriv
->sec
.key_len
[idx
] = 0;
2313 case WEP40_ENCRYPTION
:
2314 enc_algo
= CAM_WEP40
;
2316 case WEP104_ENCRYPTION
:
2317 enc_algo
= CAM_WEP104
;
2319 case TKIP_ENCRYPTION
:
2320 enc_algo
= CAM_TKIP
;
2322 case AESCCMP_ENCRYPTION
:
2326 pr_err("switch case %#x not processed\n",
2328 enc_algo
= CAM_TKIP
;
2332 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2333 macaddr
= cam_const_addr
[key_index
];
2334 entry_id
= key_index
;
2337 macaddr
= cam_const_broad
;
2338 entry_id
= key_index
;
2340 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2341 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
2343 rtl_cam_get_free_entry(hw
, p_macaddr
);
2344 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2345 pr_err("Can not find free hw security cam entry\n");
2349 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2351 key_index
= PAIRWISE_KEYIDX
;
2356 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2357 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2358 "delete one entry, entry_id is %d\n",
2360 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2361 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2362 rtl_cam_del_entry(hw
, p_macaddr
);
2363 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2365 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2368 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2369 "set Pairwise key\n");
2371 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2373 CAM_CONFIG_NO_USEDK
,
2374 rtlpriv
->sec
.key_buf
[key_index
]);
2376 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2379 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2380 rtl_cam_add_one_entry(hw
,
2383 CAM_PAIRWISE_KEY_POSITION
,
2385 CAM_CONFIG_NO_USEDK
,
2386 rtlpriv
->sec
.key_buf
2390 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2392 CAM_CONFIG_NO_USEDK
,
2393 rtlpriv
->sec
.key_buf
[entry_id
]);
2400 static void rtl8188ee_bt_var_init(struct ieee80211_hw
*hw
)
2402 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2404 rtlpriv
->btcoexist
.bt_coexistence
=
2405 rtlpriv
->btcoexist
.eeprom_bt_coexist
;
2406 rtlpriv
->btcoexist
.bt_ant_num
= rtlpriv
->btcoexist
.eeprom_bt_ant_num
;
2407 rtlpriv
->btcoexist
.bt_coexist_type
= rtlpriv
->btcoexist
.eeprom_bt_type
;
2409 if (rtlpriv
->btcoexist
.reg_bt_iso
== 2)
2410 rtlpriv
->btcoexist
.bt_ant_isolation
=
2411 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
;
2413 rtlpriv
->btcoexist
.bt_ant_isolation
=
2414 rtlpriv
->btcoexist
.reg_bt_iso
;
2416 rtlpriv
->btcoexist
.bt_radio_shared_type
=
2417 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
;
2419 if (rtlpriv
->btcoexist
.bt_coexistence
) {
2420 if (rtlpriv
->btcoexist
.reg_bt_sco
== 1)
2421 rtlpriv
->btcoexist
.bt_service
= BT_OTHER_ACTION
;
2422 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 2)
2423 rtlpriv
->btcoexist
.bt_service
= BT_SCO
;
2424 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 4)
2425 rtlpriv
->btcoexist
.bt_service
= BT_BUSY
;
2426 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 5)
2427 rtlpriv
->btcoexist
.bt_service
= BT_OTHERBUSY
;
2429 rtlpriv
->btcoexist
.bt_service
= BT_IDLE
;
2431 rtlpriv
->btcoexist
.bt_edca_ul
= 0;
2432 rtlpriv
->btcoexist
.bt_edca_dl
= 0;
2433 rtlpriv
->btcoexist
.bt_rssi_state
= 0xff;
2437 void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2438 bool auto_load_fail
, u8
*hwinfo
)
2440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2443 if (!auto_load_fail
) {
2444 rtlpriv
->btcoexist
.eeprom_bt_coexist
=
2445 ((hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] & 0xe0) >> 5);
2446 if (hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] == 0xFF)
2447 rtlpriv
->btcoexist
.eeprom_bt_coexist
= 0;
2448 value
= hwinfo
[EEPROM_RF_BT_SETTING_88E
];
2449 rtlpriv
->btcoexist
.eeprom_bt_type
= ((value
& 0xe) >> 1);
2450 rtlpriv
->btcoexist
.eeprom_bt_ant_num
= (value
& 0x1);
2451 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
= ((value
& 0x10) >> 4);
2452 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
=
2453 ((value
& 0x20) >> 5);
2455 rtlpriv
->btcoexist
.eeprom_bt_coexist
= 0;
2456 rtlpriv
->btcoexist
.eeprom_bt_type
= BT_2WIRE
;
2457 rtlpriv
->btcoexist
.eeprom_bt_ant_num
= ANT_X2
;
2458 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
= 0;
2459 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
= BT_RADIO_SHARED
;
2462 rtl8188ee_bt_var_init(hw
);
2465 void rtl8188ee_bt_reg_init(struct ieee80211_hw
*hw
)
2467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2469 /* 0:Low, 1:High, 2:From Efuse. */
2470 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
2471 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2472 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
2473 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2474 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
2477 void rtl8188ee_bt_hw_init(struct ieee80211_hw
*hw
)
2479 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2480 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2483 if (rtlpriv
->btcoexist
.bt_coexistence
&&
2484 ((rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) ||
2485 rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC8
)) {
2486 if (rtlpriv
->btcoexist
.bt_ant_isolation
)
2487 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
, 0xa0);
2489 u1_tmp
= rtl_read_byte(rtlpriv
, 0x4fd) & BIT(0);
2491 ((rtlpriv
->btcoexist
.bt_ant_isolation
== 1) ?
2493 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ?
2495 rtl_write_byte(rtlpriv
, 0x4fd, u1_tmp
);
2497 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+4, 0xaaaa9aaa);
2498 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+8, 0xffbd0040);
2499 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+0xc, 0x40000010);
2501 /* Config to 1T1R. */
2502 if (rtlphy
->rf_type
== RF_1T1R
) {
2503 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
);
2504 u1_tmp
&= ~(BIT(1));
2505 rtl_write_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
, u1_tmp
);
2507 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
);
2508 u1_tmp
&= ~(BIT(1));
2509 rtl_write_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
, u1_tmp
);
2514 void rtl88ee_suspend(struct ieee80211_hw
*hw
)
2518 void rtl88ee_resume(struct ieee80211_hw
*hw
)