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 dma_unmap_single(&rtlpci
->pdev
->dev
,
79 rtlpriv
->cfg
->ops
->get_desc(hw
, (u8
*)entry
,
80 true, HW_DESC_TXBUFF_ADDR
),
81 skb
->len
, DMA_TO_DEVICE
);
83 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
85 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
88 static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
90 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(1), 0);
93 static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw
*hw
,
94 u8 rpwm_val
, bool b_need_turn_off_ckk
)
96 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
97 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
98 bool b_support_remote_wake_up
;
99 u32 count
= 0, isr_regaddr
, content
;
100 bool schedule_timer
= b_need_turn_off_ckk
;
101 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
102 (u8
*)(&b_support_remote_wake_up
));
104 if (!rtlhal
->fw_ready
)
106 if (!rtlpriv
->psc
.fw_current_inpsmode
)
110 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
111 if (rtlhal
->fw_clk_change_in_progress
) {
112 while (rtlhal
->fw_clk_change_in_progress
) {
113 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
118 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
120 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
122 rtlhal
->fw_clk_change_in_progress
= false;
123 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
128 if (IS_IN_LOW_POWER_STATE_88E(rtlhal
->fw_ps_state
)) {
129 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
130 if (FW_PS_IS_ACK(rpwm_val
)) {
131 isr_regaddr
= REG_HISR
;
132 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
133 while (!(content
& IMR_CPWM
) && (count
< 500)) {
136 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
139 if (content
& IMR_CPWM
) {
140 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
141 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON_88E
;
142 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
143 "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
144 rtlhal
->fw_ps_state
);
148 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
149 rtlhal
->fw_clk_change_in_progress
= false;
150 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
151 if (schedule_timer
) {
152 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
153 jiffies
+ MSECS(10));
157 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
158 rtlhal
->fw_clk_change_in_progress
= false;
159 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
163 static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw
*hw
,
166 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
167 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
168 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
169 struct rtl8192_tx_ring
*ring
;
170 enum rf_pwrstate rtstate
;
171 bool schedule_timer
= false;
174 if (!rtlhal
->fw_ready
)
176 if (!rtlpriv
->psc
.fw_current_inpsmode
)
178 if (!rtlhal
->allow_sw_to_change_hwclc
)
180 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
181 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
184 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
185 ring
= &rtlpci
->tx_ring
[queue
];
186 if (skb_queue_len(&ring
->queue
)) {
187 schedule_timer
= true;
192 if (schedule_timer
) {
193 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
194 jiffies
+ MSECS(10));
198 if (FW_PS_STATE(rtlhal
->fw_ps_state
) !=
199 FW_PS_STATE_RF_OFF_LOW_PWR_88E
) {
200 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
201 if (!rtlhal
->fw_clk_change_in_progress
) {
202 rtlhal
->fw_clk_change_in_progress
= true;
203 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
204 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
205 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
206 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
208 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
209 rtlhal
->fw_clk_change_in_progress
= false;
210 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
212 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
213 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
214 jiffies
+ MSECS(10));
219 static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
223 rpwm_val
|= (FW_PS_STATE_RF_OFF_88E
| FW_PS_ACK
);
224 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, true);
227 static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw
*hw
)
230 rpwm_val
|= FW_PS_STATE_RF_OFF_LOW_PWR_88E
;
231 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
234 void rtl88ee_fw_clk_off_timer_callback(struct timer_list
*t
)
236 struct rtl_priv
*rtlpriv
= from_timer(rtlpriv
, t
,
237 works
.fw_clockoff_timer
);
238 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
240 _rtl88ee_set_fw_ps_rf_off_low_power(hw
);
243 static void _rtl88ee_fwlps_leave(struct ieee80211_hw
*hw
)
245 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
246 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
247 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
248 bool fw_current_inps
= false;
249 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
251 if (ppsc
->low_power_enable
) {
252 rpwm_val
= (FW_PS_STATE_ALL_ON_88E
|FW_PS_ACK
);/* RF on */
253 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, false);
254 rtlhal
->allow_sw_to_change_hwclc
= false;
255 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
257 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
258 (u8
*)(&fw_current_inps
));
260 rpwm_val
= FW_PS_STATE_ALL_ON_88E
; /* RF on */
261 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
262 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
264 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
265 (u8
*)(&fw_current_inps
));
269 static void _rtl88ee_fwlps_enter(struct ieee80211_hw
*hw
)
271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
272 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
273 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
274 bool fw_current_inps
= true;
277 if (ppsc
->low_power_enable
) {
278 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR_88E
; /* RF off */
279 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
280 (u8
*)(&fw_current_inps
));
281 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
282 &ppsc
->fwctrl_psmode
);
283 rtlhal
->allow_sw_to_change_hwclc
= true;
284 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
286 rpwm_val
= FW_PS_STATE_RF_OFF_88E
; /* RF off */
287 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
288 (u8
*)(&fw_current_inps
));
289 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
290 &ppsc
->fwctrl_psmode
);
291 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
, &rpwm_val
);
295 void rtl88ee_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
297 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
298 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
299 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
303 *((u32
*)(val
)) = rtlpci
->receive_config
;
305 case HW_VAR_RF_STATE
:
306 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
308 case HW_VAR_FWLPS_RF_ON
:{
309 enum rf_pwrstate rfstate
;
312 rtlpriv
->cfg
->ops
->get_hw_reg(hw
,
315 if (rfstate
== ERFOFF
) {
316 *((bool *)(val
)) = true;
318 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
319 val_rcr
&= 0x00070000;
321 *((bool *)(val
)) = false;
323 *((bool *)(val
)) = true;
326 case HW_VAR_FW_PSMODE_STATUS
:
327 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
329 case HW_VAR_CORRECT_TSF
:{
331 u32
*ptsf_low
= (u32
*)&tsf
;
332 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
334 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
335 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
337 *((u64
*)(val
)) = tsf
;
342 pr_err("switch case %#x not processed\n", variable
);
347 void rtl88ee_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
349 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
350 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
351 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
352 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
353 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
357 case HW_VAR_ETHER_ADDR
:
358 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
359 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
363 case HW_VAR_BASIC_RATE
:{
364 u16 b_rate_cfg
= ((u16
*)val
)[0];
366 b_rate_cfg
= b_rate_cfg
& 0x15f;
368 rtl_write_byte(rtlpriv
, REG_RRSR
, b_rate_cfg
& 0xff);
369 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
370 (b_rate_cfg
>> 8) & 0xff);
371 while (b_rate_cfg
> 0x1) {
372 b_rate_cfg
= (b_rate_cfg
>> 1);
375 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
380 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
381 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
386 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
387 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
389 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
390 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
393 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
396 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
399 case HW_VAR_SLOT_TIME
:{
402 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
403 "HW_VAR_SLOT_TIME %x\n", val
[0]);
405 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
407 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
408 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
413 case HW_VAR_ACK_PREAMBLE
:{
415 u8 short_preamble
= (bool)*val
;
416 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+2);
417 if (short_preamble
) {
419 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+
423 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+
427 case HW_VAR_WPA_CONFIG
:
428 rtl_write_byte(rtlpriv
, REG_SECCFG
, *val
);
430 case HW_VAR_AMPDU_MIN_SPACE
:{
431 u8 min_spacing_to_set
;
434 min_spacing_to_set
= *val
;
435 if (min_spacing_to_set
<= 7) {
438 if (min_spacing_to_set
< sec_min_space
)
439 min_spacing_to_set
= sec_min_space
;
441 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
445 *val
= min_spacing_to_set
;
447 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
448 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
451 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
455 case HW_VAR_SHORTGI_DENSITY
:{
458 density_to_set
= *val
;
459 mac
->min_space_cfg
|= (density_to_set
<< 3);
461 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
462 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
465 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
469 case HW_VAR_AMPDU_FACTOR
:{
470 u8 regtoset_normal
[4] = { 0x41, 0xa8, 0x72, 0xb9 };
472 u8
*p_regtoset
= NULL
;
475 p_regtoset
= regtoset_normal
;
478 if (factor_toset
<= 3) {
479 factor_toset
= (1 << (factor_toset
+ 2));
480 if (factor_toset
> 0xf)
483 for (index
= 0; index
< 4; index
++) {
484 if ((p_regtoset
[index
] & 0xf0) >
487 (p_regtoset
[index
] & 0x0f) |
490 if ((p_regtoset
[index
] & 0x0f) >
493 (p_regtoset
[index
] & 0xf0) |
496 rtl_write_byte(rtlpriv
,
497 (REG_AGGLEN_LMT
+ index
),
502 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
503 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
507 case HW_VAR_AC_PARAM
:{
509 rtl88e_dm_init_edca_turbo(hw
);
511 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
512 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
516 case HW_VAR_ACM_CTRL
:{
518 union aci_aifsn
*p_aci_aifsn
=
519 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
520 u8 acm
= p_aci_aifsn
->f
.acm
;
521 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
523 acm_ctrl
= acm_ctrl
|
524 ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
529 acm_ctrl
|= ACMHW_BEQEN
;
532 acm_ctrl
|= ACMHW_VIQEN
;
535 acm_ctrl
|= ACMHW_VOQEN
;
538 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
539 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
546 acm_ctrl
&= (~ACMHW_BEQEN
);
549 acm_ctrl
&= (~ACMHW_VIQEN
);
552 acm_ctrl
&= (~ACMHW_VOQEN
);
555 pr_err("switch case %#x not processed\n",
561 rtl_dbg(rtlpriv
, COMP_QOS
, DBG_TRACE
,
562 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
564 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
567 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
568 rtlpci
->receive_config
= ((u32
*)(val
))[0];
570 case HW_VAR_RETRY_LIMIT
:{
571 u8 retry_limit
= *val
;
573 rtl_write_word(rtlpriv
, REG_RL
,
574 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
575 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
577 case HW_VAR_DUAL_TSF_RST
:
578 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
580 case HW_VAR_EFUSE_BYTES
:
581 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
583 case HW_VAR_EFUSE_USAGE
:
584 rtlefuse
->efuse_usedpercentage
= *val
;
587 rtl88e_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
589 case HW_VAR_SET_RPWM
:{
592 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
595 if (rpwm_val
& BIT(7)) {
596 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, *val
);
598 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, *val
| BIT(7));
601 case HW_VAR_H2C_FW_PWRMODE
:
602 rtl88e_set_fw_pwrmode_cmd(hw
, *val
);
604 case HW_VAR_FW_PSMODE_STATUS
:
605 ppsc
->fw_current_inpsmode
= *((bool *)val
);
607 case HW_VAR_RESUME_CLK_ON
:
608 _rtl88ee_set_fw_ps_rf_on(hw
);
610 case HW_VAR_FW_LPS_ACTION
:{
611 bool enter_fwlps
= *((bool *)val
);
614 _rtl88ee_fwlps_enter(hw
);
616 _rtl88ee_fwlps_leave(hw
);
619 case HW_VAR_H2C_FW_JOINBSSRPT
:{
621 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
622 u8 count
= 0, dlbcn_count
= 0;
623 bool b_recover
= false;
625 if (mstatus
== RT_MEDIA_CONNECT
) {
626 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
,
629 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
630 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
631 (tmp_regcr
| BIT(0)));
633 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
634 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
637 rtl_read_byte(rtlpriv
,
638 REG_FWHW_TXQ_CTRL
+ 2);
639 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
640 tmp_reg422
& (~BIT(6)));
641 if (tmp_reg422
& BIT(6))
645 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
647 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2,
648 (bcnvalid_reg
| BIT(0)));
649 _rtl88ee_return_beacon_queue_skb(hw
);
651 rtl88e_set_fw_rsvdpagepkt(hw
, 0);
652 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
655 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
659 rtl_read_byte(rtlpriv
, REG_TDECTRL
+2);
662 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
664 if (bcnvalid_reg
& BIT(0))
665 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2, BIT(0));
667 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
668 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
671 rtl_write_byte(rtlpriv
,
672 REG_FWHW_TXQ_CTRL
+ 2,
676 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
677 (tmp_regcr
& ~(BIT(0))));
679 rtl88e_set_fw_joinbss_report_cmd(hw
, (*(u8
*)val
));
681 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
682 rtl88e_set_p2p_ps_offload_cmd(hw
, *val
);
687 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
689 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
692 case HW_VAR_CORRECT_TSF
:{
693 u8 btype_ibss
= *val
;
696 _rtl88ee_stop_tx_beacon(hw
);
698 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
700 rtl_write_dword(rtlpriv
, REG_TSFTR
,
701 (u32
)(mac
->tsf
& 0xffffffff));
702 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
703 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
705 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
708 _rtl88ee_resume_tx_beacon(hw
);
710 case HW_VAR_KEEP_ALIVE
: {
714 array
[1] = *((u8
*)val
);
715 rtl88e_fill_h2c_cmd(hw
, H2C_88E_KEEP_ALIVE_CTRL
,
719 pr_err("switch case %#x not processed\n", variable
);
724 static bool _rtl88ee_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
726 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
729 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
730 _LLT_OP(_LLT_WRITE_ACCESS
);
732 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
735 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
736 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
739 if (count
> POLLING_LLT_THRESHOLD
) {
740 pr_err("Failed to polling write LLT done at address %d!\n",
750 static bool _rtl88ee_llt_table_init(struct ieee80211_hw
*hw
)
752 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
759 txpktbuf_bndy
= 0xAB;
761 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x01);
762 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80730d29);
764 /*0x2600 MaxRxBuff=10k-max(TxReportSize(64*8), WOLPattern(16*24)) */
765 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
, (0x25FF0000 | txpktbuf_bndy
));
766 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
768 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
769 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
771 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
772 rtl_write_byte(rtlpriv
, REG_PBP
, 0x11);
773 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
775 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
776 status
= _rtl88ee_llt_write(hw
, i
, i
+ 1);
781 status
= _rtl88ee_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
785 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
786 status
= _rtl88ee_llt_write(hw
, i
, (i
+ 1));
791 status
= _rtl88ee_llt_write(hw
, maxpage
, txpktbuf_bndy
);
798 static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw
*hw
)
800 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
801 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
802 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
804 if (rtlpriv
->rtlhal
.up_first_time
)
807 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
808 rtl88ee_sw_led_on(hw
, pled0
);
809 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
810 rtl88ee_sw_led_on(hw
, pled0
);
812 rtl88ee_sw_led_off(hw
, pled0
);
815 static bool _rtl88ee_init_mac(struct ieee80211_hw
*hw
)
817 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
818 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
819 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
824 /*Disable XTAL OUTPUT for power saving. YJ,add,111206. */
825 bytetmp
= rtl_read_byte(rtlpriv
, REG_XCK_OUT_CTRL
) & (~BIT(0));
826 rtl_write_byte(rtlpriv
, REG_XCK_OUT_CTRL
, bytetmp
);
827 /*Auto Power Down to CHIP-off State*/
828 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
829 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
831 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
832 /* HW Power on sequence */
833 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
834 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
835 RTL8188EE_NIC_ENABLE_FLOW
)) {
836 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
837 "init MAC Fail as rtl_hal_pwrseqcmdparsing\n");
841 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
842 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
844 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2);
845 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2, bytetmp
|BIT(2));
847 bytetmp
= rtl_read_byte(rtlpriv
, REG_WATCH_DOG
+1);
848 rtl_write_byte(rtlpriv
, REG_WATCH_DOG
+1, bytetmp
|BIT(7));
850 bytetmp
= rtl_read_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1);
851 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1, bytetmp
|BIT(1));
853 bytetmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
854 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, bytetmp
|BIT(1)|BIT(0));
855 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
+1, 2);
856 rtl_write_word(rtlpriv
, REG_TX_RPT_TIME
, 0xcdf0);
858 /*Add for wake up online*/
859 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
861 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, bytetmp
|BIT(3));
862 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+1);
863 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+1, (bytetmp
& (~BIT(4))));
864 rtl_write_byte(rtlpriv
, 0x367, 0x80);
866 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
867 rtl_write_byte(rtlpriv
, REG_CR
+1, 0x06);
868 rtl_write_byte(rtlpriv
, MSR
, 0x00);
870 if (!rtlhal
->mac_func_enable
) {
871 if (!_rtl88ee_llt_table_init(hw
)) {
872 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
873 "LLT table init fail\n");
877 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
878 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
880 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
883 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
885 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
886 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xffff);
887 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
889 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
890 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
892 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
893 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
895 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
896 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
897 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
898 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
899 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
900 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
901 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
902 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
903 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
904 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
906 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
907 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
910 /* if we want to support 64 bit DMA, we should set it here,
911 * but now we do not support 64 bit DMA
913 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
915 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
916 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0);/*Enable RX DMA */
918 if (rtlhal
->earlymode_enable
) {/*Early mode enable*/
919 bytetmp
= rtl_read_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
);
921 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, bytetmp
);
922 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
+3, 0x81);
924 _rtl88ee_gen_refresh_led_state(hw
);
928 static void _rtl88ee_hw_configure(struct ieee80211_hw
*hw
)
930 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
933 reg_prsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
935 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_prsr
);
936 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
939 static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw
*hw
)
941 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
942 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
944 u32 tmp4byte
= 0, count
= 0;
946 rtl_write_word(rtlpriv
, 0x354, 0x8104);
947 rtl_write_word(rtlpriv
, 0x358, 0x24);
949 rtl_write_word(rtlpriv
, 0x350, 0x70c);
950 rtl_write_byte(rtlpriv
, 0x352, 0x2);
951 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
953 while (tmp1byte
&& count
< 20) {
955 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
959 tmp4byte
= rtl_read_dword(rtlpriv
, 0x34c);
960 rtl_write_dword(rtlpriv
, 0x348, tmp4byte
|BIT(31));
961 rtl_write_word(rtlpriv
, 0x350, 0xf70c);
962 rtl_write_byte(rtlpriv
, 0x352, 0x1);
965 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
967 while (tmp1byte
&& count
< 20) {
969 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
973 rtl_write_word(rtlpriv
, 0x350, 0x718);
974 rtl_write_byte(rtlpriv
, 0x352, 0x2);
975 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
977 while (tmp1byte
&& count
< 20) {
979 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
983 if (ppsc
->support_backdoor
|| (0 == tmp1byte
)) {
984 tmp4byte
= rtl_read_dword(rtlpriv
, 0x34c);
985 rtl_write_dword(rtlpriv
, 0x348, tmp4byte
|BIT(11)|BIT(12));
986 rtl_write_word(rtlpriv
, 0x350, 0xf718);
987 rtl_write_byte(rtlpriv
, 0x352, 0x1);
990 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
992 while (tmp1byte
&& count
< 20) {
994 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
999 void rtl88ee_enable_hw_security_config(struct ieee80211_hw
*hw
)
1001 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1004 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1005 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1006 rtlpriv
->sec
.pairwise_enc_algorithm
,
1007 rtlpriv
->sec
.group_enc_algorithm
);
1009 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1010 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1011 "not open hw encryption\n");
1015 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1017 if (rtlpriv
->sec
.use_defaultkey
) {
1018 sec_reg_value
|= SCR_TXUSEDK
;
1019 sec_reg_value
|= SCR_RXUSEDK
;
1022 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1024 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1026 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1027 "The SECR-value %x\n", sec_reg_value
);
1029 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1032 int rtl88ee_hw_init(struct ieee80211_hw
*hw
)
1034 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1035 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1036 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1037 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1038 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1039 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1040 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1044 unsigned long flags
;
1046 rtlpriv
->rtlhal
.being_init_adapter
= true;
1047 /* As this function can take a very long time (up to 350 ms)
1048 * and can be called with irqs disabled, reenable the irqs
1049 * to let the other devices continue being serviced.
1051 * It is safe doing so since our own interrupts will only be enabled
1052 * in a subsequent step.
1054 local_save_flags(flags
);
1056 rtlhal
->fw_ready
= false;
1058 rtlpriv
->intf_ops
->disable_aspm(hw
);
1060 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
+1);
1061 u1byte
= rtl_read_byte(rtlpriv
, REG_CR
);
1062 if ((tmp_u1b
& BIT(3)) && (u1byte
!= 0 && u1byte
!= 0xEA)) {
1063 rtlhal
->mac_func_enable
= true;
1065 rtlhal
->mac_func_enable
= false;
1066 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1069 rtstatus
= _rtl88ee_init_mac(hw
);
1071 pr_info("Init MAC failed\n");
1076 err
= rtl88e_download_fw(hw
, false);
1078 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1079 "Failed to download FW. Init HW without FW now..\n");
1083 rtlhal
->fw_ready
= true;
1084 /*fw related variable initialize */
1085 rtlhal
->last_hmeboxnum
= 0;
1086 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1087 rtlhal
->fw_clk_change_in_progress
= false;
1088 rtlhal
->allow_sw_to_change_hwclc
= false;
1089 ppsc
->fw_current_inpsmode
= false;
1091 rtl88e_phy_mac_config(hw
);
1092 /* because last function modify RCR, so we update
1093 * rcr var here, or TP will unstable for receive_config
1094 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1095 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1097 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1098 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1100 rtl88e_phy_bb_config(hw
);
1101 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1102 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1104 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1105 rtl88e_phy_rf_config(hw
);
1107 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1108 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1109 rtlphy
->rfreg_chnlval
[0] = rtlphy
->rfreg_chnlval
[0] & 0xfff00fff;
1111 _rtl88ee_hw_configure(hw
);
1112 rtl_cam_reset_all_entry(hw
);
1113 rtl88ee_enable_hw_security_config(hw
);
1115 rtlhal
->mac_func_enable
= true;
1116 ppsc
->rfpwr_state
= ERFON
;
1118 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1119 _rtl88ee_enable_aspm_back_door(hw
);
1120 rtlpriv
->intf_ops
->enable_aspm(hw
);
1122 if (ppsc
->rfpwr_state
== ERFON
) {
1123 if ((rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
) ||
1124 ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) &&
1125 (rtlhal
->oem_id
== RT_CID_819X_HP
))) {
1126 rtl88e_phy_set_rfpath_switch(hw
, true);
1127 rtlpriv
->dm
.fat_table
.rx_idle_ant
= MAIN_ANT
;
1129 rtl88e_phy_set_rfpath_switch(hw
, false);
1130 rtlpriv
->dm
.fat_table
.rx_idle_ant
= AUX_ANT
;
1132 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rx idle ant %s\n",
1133 (rtlpriv
->dm
.fat_table
.rx_idle_ant
== MAIN_ANT
) ?
1134 ("MAIN_ANT") : ("AUX_ANT"));
1136 if (rtlphy
->iqk_initialized
) {
1137 rtl88e_phy_iq_calibrate(hw
, true);
1139 rtl88e_phy_iq_calibrate(hw
, false);
1140 rtlphy
->iqk_initialized
= true;
1143 rtl88e_dm_check_txpower_tracking(hw
);
1144 rtl88e_phy_lc_calibrate(hw
);
1147 tmp_u1b
= efuse_read_1byte(hw
, 0x1FA);
1148 if (!(tmp_u1b
& BIT(0))) {
1149 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0F, 0x05);
1150 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "PA BIAS path A\n");
1153 if (!(tmp_u1b
& BIT(4))) {
1154 tmp_u1b
= rtl_read_byte(rtlpriv
, 0x16);
1156 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x80);
1158 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x90);
1159 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "under 1.5V\n");
1161 rtl_write_byte(rtlpriv
, REG_NAV_CTRL
+2, ((30000+127)/128));
1164 local_irq_restore(flags
);
1165 rtlpriv
->rtlhal
.being_init_adapter
= false;
1169 static enum version_8188e
_rtl88ee_read_chip_version(struct ieee80211_hw
*hw
)
1171 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1172 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1173 enum version_8188e version
= VERSION_UNKNOWN
;
1176 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
1177 if (value32
& TRP_VAUX_EN
) {
1178 version
= (enum version_8188e
) VERSION_TEST_CHIP_88E
;
1180 version
= NORMAL_CHIP
;
1181 version
= version
| ((value32
& TYPE_ID
) ? RF_TYPE_2T2R
: 0);
1182 version
= version
| ((value32
& VENDOR_ID
) ?
1183 CHIP_VENDOR_UMC
: 0);
1186 rtlphy
->rf_type
= RF_1T1R
;
1187 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1188 "Chip RF Type: %s\n", (rtlphy
->rf_type
== RF_2T2R
) ?
1189 "RF_2T2R" : "RF_1T1R");
1194 static int _rtl88ee_set_media_status(struct ieee80211_hw
*hw
,
1195 enum nl80211_iftype type
)
1197 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1198 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & 0xfc;
1199 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1200 u8 mode
= MSR_NOLINK
;
1203 case NL80211_IFTYPE_UNSPECIFIED
:
1205 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1206 "Set Network type to NO LINK!\n");
1208 case NL80211_IFTYPE_ADHOC
:
1209 case NL80211_IFTYPE_MESH_POINT
:
1211 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1212 "Set Network type to Ad Hoc!\n");
1214 case NL80211_IFTYPE_STATION
:
1216 ledaction
= LED_CTL_LINK
;
1217 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1218 "Set Network type to STA!\n");
1220 case NL80211_IFTYPE_AP
:
1222 ledaction
= LED_CTL_LINK
;
1223 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1224 "Set Network type to AP!\n");
1227 pr_err("Network type %d not support!\n", type
);
1231 /* MSR_INFRA == Link in infrastructure network;
1232 * MSR_ADHOC == Link in ad hoc network;
1233 * Therefore, check link state is necessary.
1235 * MSR_AP == AP mode; link state is not cared here.
1237 if (mode
!= MSR_AP
&& rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
) {
1239 ledaction
= LED_CTL_NO_LINK
;
1242 if (mode
== MSR_NOLINK
|| mode
== MSR_INFRA
) {
1243 _rtl88ee_stop_tx_beacon(hw
);
1244 _rtl88ee_enable_bcn_sub_func(hw
);
1245 } else if (mode
== MSR_ADHOC
|| mode
== MSR_AP
) {
1246 _rtl88ee_resume_tx_beacon(hw
);
1247 _rtl88ee_disable_bcn_sub_func(hw
);
1249 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1250 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1254 rtl_write_byte(rtlpriv
, MSR
, bt_msr
| mode
);
1255 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1257 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1259 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1263 void rtl88ee_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1265 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1266 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1267 u32 reg_rcr
= rtlpci
->receive_config
;
1269 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1272 if (check_bssid
== true) {
1273 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1274 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1276 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1277 } else if (check_bssid
== false) {
1278 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1279 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1280 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1281 HW_VAR_RCR
, (u8
*)(®_rcr
));
1286 int rtl88ee_set_network_type(struct ieee80211_hw
*hw
,
1287 enum nl80211_iftype type
)
1289 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1291 if (_rtl88ee_set_media_status(hw
, type
))
1294 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1295 if (type
!= NL80211_IFTYPE_AP
&&
1296 type
!= NL80211_IFTYPE_MESH_POINT
)
1297 rtl88ee_set_check_bssid(hw
, true);
1299 rtl88ee_set_check_bssid(hw
, false);
1305 /* don't set REG_EDCA_BE_PARAM here
1306 * because mac80211 will send pkt when scan
1308 void rtl88ee_set_qos(struct ieee80211_hw
*hw
, int aci
)
1310 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1311 rtl88e_dm_init_edca_turbo(hw
);
1314 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1319 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1322 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1325 WARN_ONCE(true, "rtl8188ee: invalid aci: %d !\n", aci
);
1330 void rtl88ee_enable_interrupt(struct ieee80211_hw
*hw
)
1332 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1333 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1335 rtl_write_dword(rtlpriv
, REG_HIMR
,
1336 rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1337 rtl_write_dword(rtlpriv
, REG_HIMRE
,
1338 rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1339 rtlpci
->irq_enabled
= true;
1340 /* there are some C2H CMDs have been sent
1341 * before system interrupt is enabled, e.g., C2H, CPWM.
1342 * So we need to clear all C2H events that FW has notified,
1343 * otherwise FW won't schedule any commands anymore.
1345 rtl_write_byte(rtlpriv
, REG_C2HEVT_CLEAR
, 0);
1346 /*enable system interrupt*/
1347 rtl_write_dword(rtlpriv
, REG_HSIMR
,
1348 rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
1351 void rtl88ee_disable_interrupt(struct ieee80211_hw
*hw
)
1353 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1354 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1356 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
1357 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
1358 rtlpci
->irq_enabled
= false;
1359 /*synchronize_irq(rtlpci->pdev->irq);*/
1362 static void _rtl88ee_poweroff_adapter(struct ieee80211_hw
*hw
)
1364 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1365 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1368 rtlhal
->mac_func_enable
= false;
1369 rtlpriv
->intf_ops
->enable_aspm(hw
);
1371 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "POWER OFF adapter\n");
1372 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
1373 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, u1b_tmp
& (~BIT(1)));
1375 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1376 while (!(u1b_tmp
& BIT(1)) && (count
++ < 100)) {
1378 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1381 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0xFF);
1383 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1385 RTL8188EE_NIC_LPS_ENTER_FLOW
);
1387 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, 0x00);
1389 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) && rtlhal
->fw_ready
)
1390 rtl88e_firmware_selfreset(hw
);
1392 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1393 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, (u1b_tmp
& (~BIT(2))));
1394 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1396 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_32K_CTRL
);
1397 rtl_write_byte(rtlpriv
, REG_32K_CTRL
, (u1b_tmp
& (~BIT(0))));
1399 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1400 PWR_INTF_PCI_MSK
, RTL8188EE_NIC_DISABLE_FLOW
);
1402 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1403 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
& (~BIT(3))));
1404 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1405 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
| BIT(3)));
1407 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1409 u1b_tmp
= rtl_read_byte(rtlpriv
, GPIO_IN
);
1410 rtl_write_byte(rtlpriv
, GPIO_OUT
, u1b_tmp
);
1411 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, 0x7F);
1413 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
1414 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
, (u1b_tmp
<< 4) | u1b_tmp
);
1415 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
+1);
1416 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
+1, u1b_tmp
| 0x0F);
1418 rtl_write_dword(rtlpriv
, REG_GPIO_IO_SEL_2
+2, 0x00080808);
1421 void rtl88ee_card_disable(struct ieee80211_hw
*hw
)
1423 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1424 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1425 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1426 enum nl80211_iftype opmode
;
1428 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "RTL8188ee card disable\n");
1430 mac
->link_state
= MAC80211_NOLINK
;
1431 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1433 _rtl88ee_set_media_status(hw
, opmode
);
1435 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1436 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1437 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1439 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1440 _rtl88ee_poweroff_adapter(hw
);
1442 /* after power off we should do iqk again */
1443 rtlpriv
->phy
.iqk_initialized
= false;
1446 void rtl88ee_interrupt_recognized(struct ieee80211_hw
*hw
,
1447 struct rtl_int
*intvec
)
1449 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1450 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1452 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1453 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1455 intvec
->intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) & rtlpci
->irq_mask
[1];
1456 rtl_write_dword(rtlpriv
, REG_HISRE
, intvec
->intb
);
1460 void rtl88ee_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1462 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1463 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1464 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1465 u16 bcn_interval
, atim_window
;
1467 bcn_interval
= mac
->beacon_interval
;
1468 atim_window
= 2; /*FIX MERGE */
1469 rtl88ee_disable_interrupt(hw
);
1470 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1471 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1472 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1473 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1474 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1475 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1476 rtlpci
->reg_bcn_ctrl_val
|= BIT(3);
1477 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
1478 /*rtl88ee_enable_interrupt(hw);*/
1481 void rtl88ee_set_beacon_interval(struct ieee80211_hw
*hw
)
1483 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1484 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1485 u16 bcn_interval
= mac
->beacon_interval
;
1487 rtl_dbg(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1488 "beacon_interval:%d\n", bcn_interval
);
1489 /*rtl88ee_disable_interrupt(hw);*/
1490 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1491 /*rtl88ee_enable_interrupt(hw);*/
1494 void rtl88ee_update_interrupt_mask(struct ieee80211_hw
*hw
,
1495 u32 add_msr
, u32 rm_msr
)
1497 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1498 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1500 rtl_dbg(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1501 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1504 rtlpci
->irq_mask
[0] |= add_msr
;
1506 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1507 rtl88ee_disable_interrupt(hw
);
1508 rtl88ee_enable_interrupt(hw
);
1511 static u8
_rtl88e_get_chnl_group(u8 chnl
)
1525 else if (chnl
== 14)
1531 static void set_24g_base(struct txpower_info_2g
*pwrinfo24g
, u32 rfpath
)
1535 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1536 pwrinfo24g
->index_cck_base
[rfpath
][group
] = 0x2D;
1537 pwrinfo24g
->index_bw40_base
[rfpath
][group
] = 0x2D;
1539 for (txcnt
= 0; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1541 pwrinfo24g
->bw20_diff
[rfpath
][0] = 0x02;
1542 pwrinfo24g
->ofdm_diff
[rfpath
][0] = 0x04;
1544 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] = 0xFE;
1545 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1546 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] = 0xFE;
1547 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1552 static void read_power_value_fromprom(struct ieee80211_hw
*hw
,
1553 struct txpower_info_2g
*pwrinfo24g
,
1554 struct txpower_info_5g
*pwrinfo5g
,
1555 bool autoload_fail
, u8
*hwinfo
)
1557 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1558 u32 rfpath
, eeaddr
= EEPROM_TX_PWR_INX
, group
, txcnt
= 0;
1560 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1561 "hal_ReadPowerValueFromPROM88E():PROMContent[0x%x]=0x%x\n",
1562 (eeaddr
+ 1), hwinfo
[eeaddr
+ 1]);
1563 if (0xFF == hwinfo
[eeaddr
+1]) /*YJ,add,120316*/
1564 autoload_fail
= true;
1566 if (autoload_fail
) {
1567 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1568 "auto load fail : Use Default value!\n");
1569 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
1570 /* 2.4G default value */
1571 set_24g_base(pwrinfo24g
, rfpath
);
1576 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
1577 /*2.4G default value*/
1578 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1579 pwrinfo24g
->index_cck_base
[rfpath
][group
] =
1581 if (pwrinfo24g
->index_cck_base
[rfpath
][group
] == 0xFF)
1582 pwrinfo24g
->index_cck_base
[rfpath
][group
] =
1585 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
-1; group
++) {
1586 pwrinfo24g
->index_bw40_base
[rfpath
][group
] =
1588 if (pwrinfo24g
->index_bw40_base
[rfpath
][group
] == 0xFF)
1589 pwrinfo24g
->index_bw40_base
[rfpath
][group
] =
1592 pwrinfo24g
->bw40_diff
[rfpath
][0] = 0;
1593 if (hwinfo
[eeaddr
] == 0xFF) {
1594 pwrinfo24g
->bw20_diff
[rfpath
][0] = 0x02;
1596 pwrinfo24g
->bw20_diff
[rfpath
][0] =
1597 (hwinfo
[eeaddr
]&0xf0)>>4;
1598 /*bit sign number to 8 bit sign number*/
1599 if (pwrinfo24g
->bw20_diff
[rfpath
][0] & BIT(3))
1600 pwrinfo24g
->bw20_diff
[rfpath
][0] |= 0xF0;
1603 if (hwinfo
[eeaddr
] == 0xFF) {
1604 pwrinfo24g
->ofdm_diff
[rfpath
][0] = 0x04;
1606 pwrinfo24g
->ofdm_diff
[rfpath
][0] =
1607 (hwinfo
[eeaddr
]&0x0f);
1608 /*bit sign number to 8 bit sign number*/
1609 if (pwrinfo24g
->ofdm_diff
[rfpath
][0] & BIT(3))
1610 pwrinfo24g
->ofdm_diff
[rfpath
][0] |= 0xF0;
1612 pwrinfo24g
->cck_diff
[rfpath
][0] = 0;
1614 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1615 if (hwinfo
[eeaddr
] == 0xFF) {
1616 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1618 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] =
1619 (hwinfo
[eeaddr
]&0xf0)>>4;
1620 if (pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] &
1622 pwrinfo24g
->bw40_diff
[rfpath
][txcnt
] |=
1626 if (hwinfo
[eeaddr
] == 0xFF) {
1627 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] =
1630 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] =
1631 (hwinfo
[eeaddr
]&0x0f);
1632 if (pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] &
1634 pwrinfo24g
->bw20_diff
[rfpath
][txcnt
] |=
1639 if (hwinfo
[eeaddr
] == 0xFF) {
1640 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1642 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] =
1643 (hwinfo
[eeaddr
]&0xf0)>>4;
1644 if (pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] &
1646 pwrinfo24g
->ofdm_diff
[rfpath
][txcnt
] |=
1650 if (hwinfo
[eeaddr
] == 0xFF) {
1651 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] = 0xFE;
1653 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] =
1654 (hwinfo
[eeaddr
]&0x0f);
1655 if (pwrinfo24g
->cck_diff
[rfpath
][txcnt
] &
1657 pwrinfo24g
->cck_diff
[rfpath
][txcnt
] |=
1663 /*5G default value*/
1664 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++) {
1665 pwrinfo5g
->index_bw40_base
[rfpath
][group
] =
1667 if (pwrinfo5g
->index_bw40_base
[rfpath
][group
] == 0xFF)
1668 pwrinfo5g
->index_bw40_base
[rfpath
][group
] =
1672 pwrinfo5g
->bw40_diff
[rfpath
][0] = 0;
1674 if (hwinfo
[eeaddr
] == 0xFF) {
1675 pwrinfo5g
->bw20_diff
[rfpath
][0] = 0;
1677 pwrinfo5g
->bw20_diff
[rfpath
][0] =
1678 (hwinfo
[eeaddr
]&0xf0)>>4;
1679 if (pwrinfo5g
->bw20_diff
[rfpath
][0] & BIT(3))
1680 pwrinfo5g
->bw20_diff
[rfpath
][0] |= 0xF0;
1683 if (hwinfo
[eeaddr
] == 0xFF) {
1684 pwrinfo5g
->ofdm_diff
[rfpath
][0] = 0x04;
1686 pwrinfo5g
->ofdm_diff
[rfpath
][0] = (hwinfo
[eeaddr
]&0x0f);
1687 if (pwrinfo5g
->ofdm_diff
[rfpath
][0] & BIT(3))
1688 pwrinfo5g
->ofdm_diff
[rfpath
][0] |= 0xF0;
1691 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1692 if (hwinfo
[eeaddr
] == 0xFF) {
1693 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] = 0xFE;
1695 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] =
1696 (hwinfo
[eeaddr
]&0xf0)>>4;
1697 if (pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] &
1699 pwrinfo5g
->bw40_diff
[rfpath
][txcnt
] |=
1703 if (hwinfo
[eeaddr
] == 0xFF) {
1704 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] = 0xFE;
1706 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] =
1707 (hwinfo
[eeaddr
]&0x0f);
1708 if (pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] &
1710 pwrinfo5g
->bw20_diff
[rfpath
][txcnt
] |=
1716 if (hwinfo
[eeaddr
] == 0xFF) {
1717 pwrinfo5g
->ofdm_diff
[rfpath
][1] = 0xFE;
1718 pwrinfo5g
->ofdm_diff
[rfpath
][2] = 0xFE;
1720 pwrinfo5g
->ofdm_diff
[rfpath
][1] =
1721 (hwinfo
[eeaddr
]&0xf0)>>4;
1722 pwrinfo5g
->ofdm_diff
[rfpath
][2] =
1723 (hwinfo
[eeaddr
]&0x0f);
1727 if (hwinfo
[eeaddr
] == 0xFF)
1728 pwrinfo5g
->ofdm_diff
[rfpath
][3] = 0xFE;
1730 pwrinfo5g
->ofdm_diff
[rfpath
][3] = (hwinfo
[eeaddr
]&0x0f);
1733 for (txcnt
= 1; txcnt
< MAX_TX_COUNT
; txcnt
++) {
1734 if (pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] == 0xFF)
1735 pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] = 0xFE;
1736 else if (pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] & BIT(3))
1737 pwrinfo5g
->ofdm_diff
[rfpath
][txcnt
] |= 0xF0;
1742 static void _rtl88ee_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1746 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1747 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1748 struct txpower_info_2g pwrinfo24g
;
1749 struct txpower_info_5g pwrinfo5g
;
1753 read_power_value_fromprom(hw
, &pwrinfo24g
,
1754 &pwrinfo5g
, autoload_fail
, hwinfo
);
1756 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1757 for (i
= 0; i
< 14; i
++) {
1758 index
= _rtl88e_get_chnl_group(i
+1);
1760 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1761 pwrinfo24g
.index_cck_base
[rf_path
][index
];
1762 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1763 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
1764 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
1765 pwrinfo24g
.bw20_diff
[rf_path
][0];
1766 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
1767 pwrinfo24g
.ofdm_diff
[rf_path
][0];
1770 for (i
= 0; i
< 14; i
++) {
1771 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1772 "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n",
1774 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1775 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
]);
1780 rtlefuse
->eeprom_thermalmeter
=
1781 hwinfo
[EEPROM_THERMAL_METER_88E
];
1783 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1785 if (rtlefuse
->eeprom_thermalmeter
== 0xff || autoload_fail
) {
1786 rtlefuse
->apk_thermalmeterignore
= true;
1787 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1790 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1791 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1792 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1794 if (!autoload_fail
) {
1795 rtlefuse
->eeprom_regulatory
=
1796 hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x07;/*bit0~2*/
1797 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
1798 rtlefuse
->eeprom_regulatory
= 0;
1800 rtlefuse
->eeprom_regulatory
= 0;
1802 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1803 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1806 static void _rtl88ee_read_adapter_info(struct ieee80211_hw
*hw
)
1808 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1809 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1810 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1811 int params
[] = {RTL8188E_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
1812 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
1813 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
1814 COUNTRY_CODE_WORLD_WIDE_13
};
1817 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
1821 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
1824 if (rtlefuse
->eeprom_oemid
== 0xFF)
1825 rtlefuse
->eeprom_oemid
= 0;
1827 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1828 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1829 /* set channel plan from efuse */
1830 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
1832 _rtl88ee_read_txpower_info_from_hwpg(hw
,
1833 rtlefuse
->autoload_failflag
,
1835 rtlefuse
->txpwr_fromeprom
= true;
1837 rtl8188ee_read_bt_coexist_info_from_hwpg(hw
,
1838 rtlefuse
->autoload_failflag
,
1842 rtlefuse
->board_type
=
1843 ((hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0xE0) >> 5);
1844 rtlhal
->board_type
= rtlefuse
->board_type
;
1846 rtlefuse
->wowlan_enable
=
1847 ((hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] & 0x40) >> 6);
1849 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_88E
];
1850 if (hwinfo
[EEPROM_XTAL_88E
])
1851 rtlefuse
->crystalcap
= 0x20;
1852 /*antenna diversity*/
1853 rtlefuse
->antenna_div_cfg
=
1854 (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x18) >> 3;
1855 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
1856 rtlefuse
->antenna_div_cfg
= 0;
1857 if (rtlpriv
->btcoexist
.eeprom_bt_coexist
!= 0 &&
1858 rtlpriv
->btcoexist
.eeprom_bt_ant_num
== ANT_X1
)
1859 rtlefuse
->antenna_div_cfg
= 0;
1861 rtlefuse
->antenna_div_type
= hwinfo
[EEPROM_RF_ANTENNA_OPT_88E
];
1862 if (rtlefuse
->antenna_div_type
== 0xFF)
1863 rtlefuse
->antenna_div_type
= 0x01;
1864 if (rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
||
1865 rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1866 rtlefuse
->antenna_div_cfg
= 1;
1868 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
1869 switch (rtlefuse
->eeprom_oemid
) {
1870 case EEPROM_CID_DEFAULT
:
1871 if (rtlefuse
->eeprom_did
== 0x8179) {
1872 if (rtlefuse
->eeprom_svid
== 0x1025) {
1873 rtlhal
->oem_id
= RT_CID_819X_ACER
;
1874 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
1875 rtlefuse
->eeprom_smid
== 0x0179) ||
1876 (rtlefuse
->eeprom_svid
== 0x17AA &&
1877 rtlefuse
->eeprom_smid
== 0x0179)) {
1878 rtlhal
->oem_id
= RT_CID_819X_LENOVO
;
1879 } else if (rtlefuse
->eeprom_svid
== 0x103c &&
1880 rtlefuse
->eeprom_smid
== 0x197d) {
1881 rtlhal
->oem_id
= RT_CID_819X_HP
;
1883 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1886 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1889 case EEPROM_CID_TOSHIBA
:
1890 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1892 case EEPROM_CID_QMI
:
1893 rtlhal
->oem_id
= RT_CID_819X_QMI
;
1895 case EEPROM_CID_WHQL
:
1897 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1906 static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw
*hw
)
1908 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1909 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1911 rtlpriv
->ledctl
.led_opendrain
= true;
1913 switch (rtlhal
->oem_id
) {
1914 case RT_CID_819X_HP
:
1915 rtlpriv
->ledctl
.led_opendrain
= true;
1917 case RT_CID_819X_LENOVO
:
1918 case RT_CID_DEFAULT
:
1919 case RT_CID_TOSHIBA
:
1921 case RT_CID_819X_ACER
:
1926 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1927 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
1930 void rtl88ee_read_eeprom_info(struct ieee80211_hw
*hw
)
1932 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1933 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1934 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1935 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1938 rtlhal
->version
= _rtl88ee_read_chip_version(hw
);
1939 if (get_rf_type(rtlphy
) == RF_1T1R
)
1940 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
1942 rtlpriv
->dm
.rfpath_rxenable
[0] =
1943 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
1944 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
1946 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
1947 if (tmp_u1b
& BIT(4)) {
1948 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1949 rtlefuse
->epromtype
= EEPROM_93C46
;
1951 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1952 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1954 if (tmp_u1b
& BIT(5)) {
1955 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1956 rtlefuse
->autoload_failflag
= false;
1957 _rtl88ee_read_adapter_info(hw
);
1959 pr_err("Autoload ERR!!\n");
1961 _rtl88ee_hal_customized_behavior(hw
);
1964 static void rtl88ee_update_hal_rate_table(struct ieee80211_hw
*hw
,
1965 struct ieee80211_sta
*sta
)
1967 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1968 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1969 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1970 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1973 u8 b_nmode
= mac
->ht_enable
;
1974 /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
1977 u8 curtxbw_40mhz
= mac
->bw_40
;
1978 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
1980 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
1982 enum wireless_mode wirelessmode
= mac
->mode
;
1985 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1986 ratr_value
= sta
->supp_rates
[1] << 4;
1988 ratr_value
= sta
->supp_rates
[0];
1989 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
1991 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
1992 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
1993 switch (wirelessmode
) {
1994 case WIRELESS_MODE_B
:
1995 if (ratr_value
& 0x0000000c)
1996 ratr_value
&= 0x0000000d;
1998 ratr_value
&= 0x0000000f;
2000 case WIRELESS_MODE_G
:
2001 ratr_value
&= 0x00000FF5;
2003 case WIRELESS_MODE_N_24G
:
2004 case WIRELESS_MODE_N_5G
:
2006 if (get_rf_type(rtlphy
) == RF_1T2R
||
2007 get_rf_type(rtlphy
) == RF_1T1R
)
2008 ratr_mask
= 0x000ff005;
2010 ratr_mask
= 0x0f0ff005;
2012 ratr_value
&= ratr_mask
;
2015 if (rtlphy
->rf_type
== RF_1T2R
)
2016 ratr_value
&= 0x000ff0ff;
2018 ratr_value
&= 0x0f0ff0ff;
2023 if ((rtlpriv
->btcoexist
.bt_coexistence
) &&
2024 (rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) &&
2025 (rtlpriv
->btcoexist
.bt_cur_state
) &&
2026 (rtlpriv
->btcoexist
.bt_ant_isolation
) &&
2027 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ||
2028 (rtlpriv
->btcoexist
.bt_service
== BT_BUSY
)))
2029 ratr_value
&= 0x0fffcfc0;
2031 ratr_value
&= 0x0FFFFFFF;
2034 ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2035 (!curtxbw_40mhz
&& curshortgi_20mhz
))) {
2036 ratr_value
|= 0x10000000;
2037 tmp_ratr_value
= (ratr_value
>> 12);
2039 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2040 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2044 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2045 (shortgi_rate
<< 4) | (shortgi_rate
);
2048 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2050 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2051 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
2054 static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2055 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2057 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2058 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2059 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2060 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2061 struct rtl_sta_info
*sta_entry
= NULL
;
2064 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)
2066 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2068 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2070 enum wireless_mode wirelessmode
= 0;
2071 bool b_shortgi
= false;
2074 /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
2076 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
2077 wirelessmode
= sta_entry
->wireless_mode
;
2078 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2079 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2080 curtxbw_40mhz
= mac
->bw_40
;
2081 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2082 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2083 macid
= sta
->aid
+ 1;
2085 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2086 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2088 ratr_bitmap
= sta
->supp_rates
[0];
2089 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2090 ratr_bitmap
= 0xfff;
2091 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2092 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2093 switch (wirelessmode
) {
2094 case WIRELESS_MODE_B
:
2095 ratr_index
= RATR_INX_WIRELESS_B
;
2096 if (ratr_bitmap
& 0x0000000c)
2097 ratr_bitmap
&= 0x0000000d;
2099 ratr_bitmap
&= 0x0000000f;
2101 case WIRELESS_MODE_G
:
2102 ratr_index
= RATR_INX_WIRELESS_GB
;
2104 if (rssi_level
== 1)
2105 ratr_bitmap
&= 0x00000f00;
2106 else if (rssi_level
== 2)
2107 ratr_bitmap
&= 0x00000ff0;
2109 ratr_bitmap
&= 0x00000ff5;
2111 case WIRELESS_MODE_N_24G
:
2112 case WIRELESS_MODE_N_5G
:
2113 ratr_index
= RATR_INX_WIRELESS_NGB
;
2114 if (rtlphy
->rf_type
== RF_1T2R
||
2115 rtlphy
->rf_type
== RF_1T1R
) {
2116 if (curtxbw_40mhz
) {
2117 if (rssi_level
== 1)
2118 ratr_bitmap
&= 0x000f0000;
2119 else if (rssi_level
== 2)
2120 ratr_bitmap
&= 0x000ff000;
2122 ratr_bitmap
&= 0x000ff015;
2124 if (rssi_level
== 1)
2125 ratr_bitmap
&= 0x000f0000;
2126 else if (rssi_level
== 2)
2127 ratr_bitmap
&= 0x000ff000;
2129 ratr_bitmap
&= 0x000ff005;
2132 if (curtxbw_40mhz
) {
2133 if (rssi_level
== 1)
2134 ratr_bitmap
&= 0x0f8f0000;
2135 else if (rssi_level
== 2)
2136 ratr_bitmap
&= 0x0f8ff000;
2138 ratr_bitmap
&= 0x0f8ff015;
2140 if (rssi_level
== 1)
2141 ratr_bitmap
&= 0x0f8f0000;
2142 else if (rssi_level
== 2)
2143 ratr_bitmap
&= 0x0f8ff000;
2145 ratr_bitmap
&= 0x0f8ff005;
2150 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2151 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2155 else if (macid
== 1)
2160 ratr_index
= RATR_INX_WIRELESS_NGB
;
2162 if (rtlphy
->rf_type
== RF_1T2R
)
2163 ratr_bitmap
&= 0x000ff0ff;
2165 ratr_bitmap
&= 0x0f0ff0ff;
2168 sta_entry
->ratr_index
= ratr_index
;
2170 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2171 "ratr_bitmap :%x\n", ratr_bitmap
);
2172 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2174 rate_mask
[4] = macid
| (b_shortgi
? 0x20 : 0x00) | 0x80;
2175 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2176 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
2177 ratr_index
, ratr_bitmap
,
2178 rate_mask
[0], rate_mask
[1],
2179 rate_mask
[2], rate_mask
[3],
2181 rtl88e_fill_h2c_cmd(hw
, H2C_88E_RA_MASK
, 5, rate_mask
);
2182 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2185 void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2186 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
2188 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2190 if (rtlpriv
->dm
.useramask
)
2191 rtl88ee_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2193 rtl88ee_update_hal_rate_table(hw
, sta
);
2196 void rtl88ee_update_channel_access_setting(struct ieee80211_hw
*hw
)
2198 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2199 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2202 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
, &mac
->slot_time
);
2203 if (!mac
->ht_enable
)
2204 sifs_timer
= 0x0a0a;
2206 sifs_timer
= 0x0e0e;
2207 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2210 bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2212 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2213 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2214 enum rf_pwrstate e_rfpowerstate_toset
;
2216 bool b_actuallyset
= false;
2218 if (rtlpriv
->rtlhal
.being_init_adapter
)
2221 if (ppsc
->swrf_processing
)
2224 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2225 if (ppsc
->rfchange_inprogress
) {
2226 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2229 ppsc
->rfchange_inprogress
= true;
2230 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2233 u4tmp
= rtl_read_dword(rtlpriv
, REG_GPIO_OUTPUT
);
2234 e_rfpowerstate_toset
= (u4tmp
& BIT(31)) ? ERFON
: ERFOFF
;
2236 if (ppsc
->hwradiooff
&& (e_rfpowerstate_toset
== ERFON
)) {
2237 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2238 "GPIOChangeRF - HW Radio ON, RF ON\n");
2240 e_rfpowerstate_toset
= ERFON
;
2241 ppsc
->hwradiooff
= false;
2242 b_actuallyset
= true;
2243 } else if ((!ppsc
->hwradiooff
) &&
2244 (e_rfpowerstate_toset
== ERFOFF
)) {
2245 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2246 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2248 e_rfpowerstate_toset
= ERFOFF
;
2249 ppsc
->hwradiooff
= true;
2250 b_actuallyset
= true;
2253 if (b_actuallyset
) {
2254 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2255 ppsc
->rfchange_inprogress
= false;
2256 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2258 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2259 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2261 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2262 ppsc
->rfchange_inprogress
= false;
2263 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2267 return !ppsc
->hwradiooff
;
2271 void rtl88ee_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
2272 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
2273 bool is_wepkey
, bool clear_all
)
2275 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2276 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2277 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2278 u8
*macaddr
= p_macaddr
;
2280 bool is_pairwise
= false;
2281 static u8 cam_const_addr
[4][6] = {
2282 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2283 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2284 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2285 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2287 static u8 cam_const_broad
[] = {
2288 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2294 u8 clear_number
= 5;
2296 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2298 for (idx
= 0; idx
< clear_number
; idx
++) {
2299 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2300 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2303 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2305 rtlpriv
->sec
.key_len
[idx
] = 0;
2311 case WEP40_ENCRYPTION
:
2312 enc_algo
= CAM_WEP40
;
2314 case WEP104_ENCRYPTION
:
2315 enc_algo
= CAM_WEP104
;
2317 case TKIP_ENCRYPTION
:
2318 enc_algo
= CAM_TKIP
;
2320 case AESCCMP_ENCRYPTION
:
2324 pr_err("switch case %#x not processed\n",
2326 enc_algo
= CAM_TKIP
;
2330 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2331 macaddr
= cam_const_addr
[key_index
];
2332 entry_id
= key_index
;
2335 macaddr
= cam_const_broad
;
2336 entry_id
= key_index
;
2338 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2339 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
2341 rtl_cam_get_free_entry(hw
, p_macaddr
);
2342 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2343 pr_err("Can not find free hw security cam entry\n");
2347 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2349 key_index
= PAIRWISE_KEYIDX
;
2354 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2355 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2356 "delete one entry, entry_id is %d\n",
2358 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2359 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2360 rtl_cam_del_entry(hw
, p_macaddr
);
2361 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2363 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2366 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2367 "set Pairwise key\n");
2369 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2371 CAM_CONFIG_NO_USEDK
,
2372 rtlpriv
->sec
.key_buf
[key_index
]);
2374 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2377 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2378 rtl_cam_add_one_entry(hw
,
2381 CAM_PAIRWISE_KEY_POSITION
,
2383 CAM_CONFIG_NO_USEDK
,
2384 rtlpriv
->sec
.key_buf
2388 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2390 CAM_CONFIG_NO_USEDK
,
2391 rtlpriv
->sec
.key_buf
[entry_id
]);
2398 static void rtl8188ee_bt_var_init(struct ieee80211_hw
*hw
)
2400 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2402 rtlpriv
->btcoexist
.bt_coexistence
=
2403 rtlpriv
->btcoexist
.eeprom_bt_coexist
;
2404 rtlpriv
->btcoexist
.bt_ant_num
= rtlpriv
->btcoexist
.eeprom_bt_ant_num
;
2405 rtlpriv
->btcoexist
.bt_coexist_type
= rtlpriv
->btcoexist
.eeprom_bt_type
;
2407 if (rtlpriv
->btcoexist
.reg_bt_iso
== 2)
2408 rtlpriv
->btcoexist
.bt_ant_isolation
=
2409 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
;
2411 rtlpriv
->btcoexist
.bt_ant_isolation
=
2412 rtlpriv
->btcoexist
.reg_bt_iso
;
2414 rtlpriv
->btcoexist
.bt_radio_shared_type
=
2415 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
;
2417 if (rtlpriv
->btcoexist
.bt_coexistence
) {
2418 if (rtlpriv
->btcoexist
.reg_bt_sco
== 1)
2419 rtlpriv
->btcoexist
.bt_service
= BT_OTHER_ACTION
;
2420 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 2)
2421 rtlpriv
->btcoexist
.bt_service
= BT_SCO
;
2422 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 4)
2423 rtlpriv
->btcoexist
.bt_service
= BT_BUSY
;
2424 else if (rtlpriv
->btcoexist
.reg_bt_sco
== 5)
2425 rtlpriv
->btcoexist
.bt_service
= BT_OTHERBUSY
;
2427 rtlpriv
->btcoexist
.bt_service
= BT_IDLE
;
2429 rtlpriv
->btcoexist
.bt_edca_ul
= 0;
2430 rtlpriv
->btcoexist
.bt_edca_dl
= 0;
2431 rtlpriv
->btcoexist
.bt_rssi_state
= 0xff;
2435 void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2436 bool auto_load_fail
, u8
*hwinfo
)
2438 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2441 if (!auto_load_fail
) {
2442 rtlpriv
->btcoexist
.eeprom_bt_coexist
=
2443 ((hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] & 0xe0) >> 5);
2444 if (hwinfo
[EEPROM_RF_FEATURE_OPTION_88E
] == 0xFF)
2445 rtlpriv
->btcoexist
.eeprom_bt_coexist
= 0;
2446 value
= hwinfo
[EEPROM_RF_BT_SETTING_88E
];
2447 rtlpriv
->btcoexist
.eeprom_bt_type
= ((value
& 0xe) >> 1);
2448 rtlpriv
->btcoexist
.eeprom_bt_ant_num
= (value
& 0x1);
2449 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
= ((value
& 0x10) >> 4);
2450 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
=
2451 ((value
& 0x20) >> 5);
2453 rtlpriv
->btcoexist
.eeprom_bt_coexist
= 0;
2454 rtlpriv
->btcoexist
.eeprom_bt_type
= BT_2WIRE
;
2455 rtlpriv
->btcoexist
.eeprom_bt_ant_num
= ANT_X2
;
2456 rtlpriv
->btcoexist
.eeprom_bt_ant_isol
= 0;
2457 rtlpriv
->btcoexist
.eeprom_bt_radio_shared
= BT_RADIO_SHARED
;
2460 rtl8188ee_bt_var_init(hw
);
2463 void rtl8188ee_bt_reg_init(struct ieee80211_hw
*hw
)
2465 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2467 /* 0:Low, 1:High, 2:From Efuse. */
2468 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
2469 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2470 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
2471 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2472 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
2475 void rtl8188ee_bt_hw_init(struct ieee80211_hw
*hw
)
2477 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2478 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2481 if (rtlpriv
->btcoexist
.bt_coexistence
&&
2482 ((rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) ||
2483 rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC8
)) {
2484 if (rtlpriv
->btcoexist
.bt_ant_isolation
)
2485 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
, 0xa0);
2487 u1_tmp
= rtl_read_byte(rtlpriv
, 0x4fd) & BIT(0);
2489 ((rtlpriv
->btcoexist
.bt_ant_isolation
== 1) ?
2491 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ?
2493 rtl_write_byte(rtlpriv
, 0x4fd, u1_tmp
);
2495 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+4, 0xaaaa9aaa);
2496 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+8, 0xffbd0040);
2497 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+0xc, 0x40000010);
2499 /* Config to 1T1R. */
2500 if (rtlphy
->rf_type
== RF_1T1R
) {
2501 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
);
2502 u1_tmp
&= ~(BIT(1));
2503 rtl_write_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
, u1_tmp
);
2505 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
);
2506 u1_tmp
&= ~(BIT(1));
2507 rtl_write_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
, u1_tmp
);
2512 void rtl88ee_suspend(struct ieee80211_hw
*hw
)
2516 void rtl88ee_resume(struct ieee80211_hw
*hw
)