1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2010 Realtek Corporation.*/
18 #include "../pwrseqcmd.h"
20 #include "../btcoexist/rtl_btc.h"
24 static void _rtl8821ae_return_beacon_queue_skb(struct ieee80211_hw
*hw
)
26 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
27 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
28 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
31 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
32 while (skb_queue_len(&ring
->queue
)) {
33 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
34 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
36 pci_unmap_single(rtlpci
->pdev
,
37 rtlpriv
->cfg
->ops
->get_desc(
39 (u8
*)entry
, true, HW_DESC_TXBUFF_ADDR
),
40 skb
->len
, PCI_DMA_TODEVICE
);
42 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
44 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
47 static void _rtl8821ae_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
48 u8 set_bits
, u8 clear_bits
)
50 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
51 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
53 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
54 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
56 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
59 void _rtl8821ae_stop_tx_beacon(struct ieee80211_hw
*hw
)
61 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
64 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
65 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
66 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
67 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
68 tmp1byte
&= ~(BIT(0));
69 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
72 void _rtl8821ae_resume_tx_beacon(struct ieee80211_hw
*hw
)
74 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
77 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
78 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
79 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
80 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
82 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
85 static void _rtl8821ae_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
87 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(1));
90 static void _rtl8821ae_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
92 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(1), 0);
95 static void _rtl8821ae_set_fw_clock_on(struct ieee80211_hw
*hw
,
96 u8 rpwm_val
, bool b_need_turn_off_ckk
)
98 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
99 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
100 bool b_support_remote_wake_up
;
101 u32 count
= 0, isr_regaddr
, content
;
102 bool b_schedule_timer
= b_need_turn_off_ckk
;
104 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
105 (u8
*)(&b_support_remote_wake_up
));
107 if (!rtlhal
->fw_ready
)
109 if (!rtlpriv
->psc
.fw_current_inpsmode
)
113 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
114 if (rtlhal
->fw_clk_change_in_progress
) {
115 while (rtlhal
->fw_clk_change_in_progress
) {
116 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
121 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
123 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
125 rtlhal
->fw_clk_change_in_progress
= false;
126 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
131 if (IS_IN_LOW_POWER_STATE_8821AE(rtlhal
->fw_ps_state
)) {
132 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
,
134 if (FW_PS_IS_ACK(rpwm_val
)) {
135 isr_regaddr
= REG_HISR
;
136 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
137 while (!(content
& IMR_CPWM
) && (count
< 500)) {
140 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
143 if (content
& IMR_CPWM
) {
144 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
145 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON_8821AE
;
146 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
147 "Receive CPWM INT!!! Set rtlhal->FwPSState = %X\n",
148 rtlhal
->fw_ps_state
);
152 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
153 rtlhal
->fw_clk_change_in_progress
= false;
154 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
155 if (b_schedule_timer
)
156 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
157 jiffies
+ MSECS(10));
159 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
160 rtlhal
->fw_clk_change_in_progress
= false;
161 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
165 static void _rtl8821ae_set_fw_clock_off(struct ieee80211_hw
*hw
,
168 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
169 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
170 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
171 struct rtl8192_tx_ring
*ring
;
172 enum rf_pwrstate rtstate
;
173 bool b_schedule_timer
= false;
176 if (!rtlhal
->fw_ready
)
178 if (!rtlpriv
->psc
.fw_current_inpsmode
)
180 if (!rtlhal
->allow_sw_to_change_hwclc
)
182 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
183 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
186 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
187 ring
= &rtlpci
->tx_ring
[queue
];
188 if (skb_queue_len(&ring
->queue
)) {
189 b_schedule_timer
= true;
194 if (b_schedule_timer
) {
195 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
196 jiffies
+ MSECS(10));
200 if (FW_PS_STATE(rtlhal
->fw_ps_state
) !=
201 FW_PS_STATE_RF_OFF_LOW_PWR_8821AE
) {
202 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
203 if (!rtlhal
->fw_clk_change_in_progress
) {
204 rtlhal
->fw_clk_change_in_progress
= true;
205 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
206 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
207 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
208 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
210 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
211 rtlhal
->fw_clk_change_in_progress
= false;
212 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
214 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
215 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
216 jiffies
+ MSECS(10));
221 static void _rtl8821ae_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
225 rpwm_val
|= (FW_PS_STATE_RF_OFF_8821AE
| FW_PS_ACK
);
226 _rtl8821ae_set_fw_clock_on(hw
, rpwm_val
, true);
229 static void _rtl8821ae_fwlps_leave(struct ieee80211_hw
*hw
)
231 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
232 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
233 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
234 bool fw_current_inps
= false;
235 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
237 if (ppsc
->low_power_enable
) {
238 rpwm_val
= (FW_PS_STATE_ALL_ON_8821AE
|FW_PS_ACK
);/* RF on */
239 _rtl8821ae_set_fw_clock_on(hw
, rpwm_val
, false);
240 rtlhal
->allow_sw_to_change_hwclc
= false;
241 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
242 (u8
*)(&fw_pwrmode
));
243 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
244 (u8
*)(&fw_current_inps
));
246 rpwm_val
= FW_PS_STATE_ALL_ON_8821AE
; /* RF on */
247 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
249 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
250 (u8
*)(&fw_pwrmode
));
251 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
252 (u8
*)(&fw_current_inps
));
256 static void _rtl8821ae_fwlps_enter(struct ieee80211_hw
*hw
)
258 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
259 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
260 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
261 bool fw_current_inps
= true;
264 if (ppsc
->low_power_enable
) {
265 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR_8821AE
; /* RF off */
266 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
267 HW_VAR_FW_PSMODE_STATUS
,
268 (u8
*)(&fw_current_inps
));
269 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
270 HW_VAR_H2C_FW_PWRMODE
,
271 (u8
*)(&ppsc
->fwctrl_psmode
));
272 rtlhal
->allow_sw_to_change_hwclc
= true;
273 _rtl8821ae_set_fw_clock_off(hw
, rpwm_val
);
275 rpwm_val
= FW_PS_STATE_RF_OFF_8821AE
; /* RF off */
276 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
277 HW_VAR_FW_PSMODE_STATUS
,
278 (u8
*)(&fw_current_inps
));
279 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
280 HW_VAR_H2C_FW_PWRMODE
,
281 (u8
*)(&ppsc
->fwctrl_psmode
));
282 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
288 static void _rtl8821ae_download_rsvd_page(struct ieee80211_hw
*hw
,
289 bool dl_whole_packets
)
291 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
292 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
293 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
294 u8 count
= 0, dlbcn_count
= 0;
295 bool send_beacon
= false;
297 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
298 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
| BIT(0)));
300 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
301 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
303 tmp_reg422
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
304 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
305 tmp_reg422
& (~BIT(6)));
306 if (tmp_reg422
& BIT(6))
310 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
311 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
312 (bcnvalid_reg
| BIT(0)));
313 _rtl8821ae_return_beacon_queue_skb(hw
);
315 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
316 rtl8812ae_set_fw_rsvdpagepkt(hw
, false,
319 rtl8821ae_set_fw_rsvdpagepkt(hw
, false,
322 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
324 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
327 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
330 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
332 if (!(bcnvalid_reg
& BIT(0)))
333 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
334 "Download RSVD page failed!\n");
335 if (bcnvalid_reg
& BIT(0) && rtlhal
->enter_pnp_sleep
) {
336 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, bcnvalid_reg
| BIT(0));
337 _rtl8821ae_return_beacon_queue_skb(hw
);
341 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
342 bcnvalid_reg
| BIT(0));
344 _rtl8821ae_return_beacon_queue_skb(hw
);
346 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
347 rtl8812ae_set_fw_rsvdpagepkt(hw
, true,
350 rtl8821ae_set_fw_rsvdpagepkt(hw
, true,
353 /* check rsvd page download OK. */
354 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
357 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
361 rtl_read_byte(rtlpriv
,
365 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
367 if (!(bcnvalid_reg
& BIT(0)))
368 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
369 "2 Download RSVD page failed!\n");
373 if (bcnvalid_reg
& BIT(0))
374 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, BIT(0));
376 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
377 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
380 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
);
382 if (!rtlhal
->enter_pnp_sleep
) {
383 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
384 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
& ~(BIT(0))));
388 void rtl8821ae_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
390 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
391 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
392 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
393 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
396 case HW_VAR_ETHER_ADDR
:
397 *((u32
*)(val
)) = rtl_read_dword(rtlpriv
, REG_MACID
);
398 *((u16
*)(val
+4)) = rtl_read_word(rtlpriv
, REG_MACID
+ 4);
401 *((u32
*)(val
)) = rtl_read_dword(rtlpriv
, REG_BSSID
);
402 *((u16
*)(val
+4)) = rtl_read_word(rtlpriv
, REG_BSSID
+4);
404 case HW_VAR_MEDIA_STATUS
:
405 val
[0] = rtl_read_byte(rtlpriv
, MSR
) & 0x3;
407 case HW_VAR_SLOT_TIME
:
408 *((u8
*)(val
)) = mac
->slot_time
;
410 case HW_VAR_BEACON_INTERVAL
:
411 *((u16
*)(val
)) = rtl_read_word(rtlpriv
, REG_BCN_INTERVAL
);
413 case HW_VAR_ATIM_WINDOW
:
414 *((u16
*)(val
)) = rtl_read_word(rtlpriv
, REG_ATIMWND
);
417 *((u32
*)(val
)) = rtlpci
->receive_config
;
419 case HW_VAR_RF_STATE
:
420 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
422 case HW_VAR_FWLPS_RF_ON
:{
423 enum rf_pwrstate rfstate
;
426 rtlpriv
->cfg
->ops
->get_hw_reg(hw
,
429 if (rfstate
== ERFOFF
) {
430 *((bool *)(val
)) = true;
432 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
433 val_rcr
&= 0x00070000;
435 *((bool *)(val
)) = false;
437 *((bool *)(val
)) = true;
440 case HW_VAR_FW_PSMODE_STATUS
:
441 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
443 case HW_VAR_CORRECT_TSF
:{
445 u32
*ptsf_low
= (u32
*)&tsf
;
446 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
448 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
449 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
451 *((u64
*)(val
)) = tsf
;
455 if (ppsc
->wo_wlan_mode
)
456 *((bool *)(val
)) = true;
458 *((bool *)(val
)) = false;
461 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
462 "switch case %#x not processed\n", variable
);
467 void rtl8821ae_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
470 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
471 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
472 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
473 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
474 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
478 case HW_VAR_ETHER_ADDR
:{
479 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
480 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
485 case HW_VAR_BASIC_RATE
:{
486 u16 b_rate_cfg
= ((u16
*)val
)[0];
487 b_rate_cfg
= b_rate_cfg
& 0x15f;
488 rtl_write_word(rtlpriv
, REG_RRSR
, b_rate_cfg
);
492 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
493 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
499 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
500 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[0]);
502 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
503 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
505 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
+ 1, val
[0]);
506 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
, val
[0]);
508 case HW_VAR_R2T_SIFS
:
509 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
+ 1, val
[0]);
511 case HW_VAR_SLOT_TIME
:{
514 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
515 "HW_VAR_SLOT_TIME %x\n", val
[0]);
517 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
519 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
520 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
525 case HW_VAR_ACK_PREAMBLE
:{
527 u8 short_preamble
= (bool)(*(u8
*)val
);
529 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+2);
530 if (short_preamble
) {
532 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2,
535 reg_tmp
&= (~BIT(1));
536 rtl_write_byte(rtlpriv
,
541 case HW_VAR_WPA_CONFIG
:
542 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*)val
));
544 case HW_VAR_AMPDU_MIN_SPACE
:{
545 u8 min_spacing_to_set
;
548 min_spacing_to_set
= *((u8
*)val
);
549 if (min_spacing_to_set
<= 7) {
552 if (min_spacing_to_set
< sec_min_space
)
553 min_spacing_to_set
= sec_min_space
;
555 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
559 *val
= min_spacing_to_set
;
561 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
562 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
565 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
569 case HW_VAR_SHORTGI_DENSITY
:{
572 density_to_set
= *((u8
*)val
);
573 mac
->min_space_cfg
|= (density_to_set
<< 3);
575 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
576 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
579 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
583 case HW_VAR_AMPDU_FACTOR
:{
584 u32 ampdu_len
= (*((u8
*)val
));
586 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
587 if (ampdu_len
< VHT_AGG_SIZE_128K
)
589 (0x2000 << (*((u8
*)val
))) - 1;
592 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
593 if (ampdu_len
< HT_AGG_SIZE_64K
)
595 (0x2000 << (*((u8
*)val
))) - 1;
599 ampdu_len
|= BIT(31);
601 rtl_write_dword(rtlpriv
,
602 REG_AMPDU_MAX_LENGTH_8812
, ampdu_len
);
604 case HW_VAR_AC_PARAM
:{
605 u8 e_aci
= *((u8
*)val
);
607 rtl8821ae_dm_init_edca_turbo(hw
);
608 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
609 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
613 case HW_VAR_ACM_CTRL
:{
614 u8 e_aci
= *((u8
*)val
);
615 union aci_aifsn
*p_aci_aifsn
=
616 (union aci_aifsn
*)(&mac
->ac
[0].aifs
);
617 u8 acm
= p_aci_aifsn
->f
.acm
;
618 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
621 acm_ctrl
| ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
626 acm_ctrl
|= ACMHW_BEQEN
;
629 acm_ctrl
|= ACMHW_VIQEN
;
632 acm_ctrl
|= ACMHW_VOQEN
;
635 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
636 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
643 acm_ctrl
&= (~ACMHW_BEQEN
);
646 acm_ctrl
&= (~ACMHW_VIQEN
);
649 acm_ctrl
&= (~ACMHW_VOQEN
);
652 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
653 "switch case %#x not processed\n",
659 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
660 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
662 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
665 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
666 rtlpci
->receive_config
= ((u32
*)(val
))[0];
668 case HW_VAR_RETRY_LIMIT
:{
669 u8 retry_limit
= ((u8
*)(val
))[0];
671 rtl_write_word(rtlpriv
, REG_RL
,
672 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
673 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
675 case HW_VAR_DUAL_TSF_RST
:
676 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
678 case HW_VAR_EFUSE_BYTES
:
679 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
681 case HW_VAR_EFUSE_USAGE
:
682 rtlefuse
->efuse_usedpercentage
= *((u8
*)val
);
685 rtl8821ae_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
687 case HW_VAR_SET_RPWM
:{
690 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
693 if (rpwm_val
& BIT(7)) {
694 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
697 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
698 ((*(u8
*)val
) | BIT(7)));
702 case HW_VAR_H2C_FW_PWRMODE
:
703 rtl8821ae_set_fw_pwrmode_cmd(hw
, (*(u8
*)val
));
705 case HW_VAR_FW_PSMODE_STATUS
:
706 ppsc
->fw_current_inpsmode
= *((bool *)val
);
708 case HW_VAR_INIT_RTS_RATE
:
710 case HW_VAR_RESUME_CLK_ON
:
711 _rtl8821ae_set_fw_ps_rf_on(hw
);
713 case HW_VAR_FW_LPS_ACTION
:{
714 bool b_enter_fwlps
= *((bool *)val
);
717 _rtl8821ae_fwlps_enter(hw
);
719 _rtl8821ae_fwlps_leave(hw
);
721 case HW_VAR_H2C_FW_JOINBSSRPT
:{
722 u8 mstatus
= (*(u8
*)val
);
724 if (mstatus
== RT_MEDIA_CONNECT
) {
725 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
,
727 _rtl8821ae_download_rsvd_page(hw
, false);
729 rtl8821ae_set_fw_media_status_rpt_cmd(hw
, mstatus
);
732 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
733 rtl8821ae_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
737 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
739 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
742 case HW_VAR_CORRECT_TSF
:{
743 u8 btype_ibss
= ((u8
*)(val
))[0];
746 _rtl8821ae_stop_tx_beacon(hw
);
748 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
750 rtl_write_dword(rtlpriv
, REG_TSFTR
,
751 (u32
)(mac
->tsf
& 0xffffffff));
752 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
753 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
755 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
758 _rtl8821ae_resume_tx_beacon(hw
);
760 case HW_VAR_NAV_UPPER
: {
761 u32 us_nav_upper
= *(u32
*)val
;
763 if (us_nav_upper
> HAL_92C_NAV_UPPER_UNIT
* 0xFF) {
764 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
765 "The setting value (0x%08X us) of NAV_UPPER is larger than (%d * 0xFF)!!!\n",
766 us_nav_upper
, HAL_92C_NAV_UPPER_UNIT
);
769 rtl_write_byte(rtlpriv
, REG_NAV_UPPER
,
770 ((u8
)((us_nav_upper
+
771 HAL_92C_NAV_UPPER_UNIT
- 1) /
772 HAL_92C_NAV_UPPER_UNIT
)));
774 case HW_VAR_KEEP_ALIVE
: {
777 array
[1] = *((u8
*)val
);
778 rtl8821ae_fill_h2c_cmd(hw
, H2C_8821AE_KEEP_ALIVE_CTRL
, 2,
782 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
783 "switch case %#x not processed\n", variable
);
788 static bool _rtl8821ae_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
790 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
793 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
794 _LLT_OP(_LLT_WRITE_ACCESS
);
796 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
799 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
800 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
803 if (count
> POLLING_LLT_THRESHOLD
) {
804 pr_err("Failed to polling write LLT done at address %d!\n",
814 static bool _rtl8821ae_llt_table_init(struct ieee80211_hw
*hw
)
816 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
824 txpktbuf_bndy
= 0xF7;
827 rtl_write_byte(rtlpriv
, REG_TRXFF_BNDY
, txpktbuf_bndy
);
828 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, MAX_RX_DMA_BUFFER_SIZE
- 1);
830 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
832 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
833 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
835 rtl_write_byte(rtlpriv
, REG_PBP
, 0x31);
836 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
838 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
839 status
= _rtl8821ae_llt_write(hw
, i
, i
+ 1);
844 status
= _rtl8821ae_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
848 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
849 status
= _rtl8821ae_llt_write(hw
, i
, (i
+ 1));
854 status
= _rtl8821ae_llt_write(hw
, maxpage
, txpktbuf_bndy
);
858 rtl_write_dword(rtlpriv
, REG_RQPN
, rqpn
);
860 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x00);
865 static void _rtl8821ae_gen_refresh_led_state(struct ieee80211_hw
*hw
)
867 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
868 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
869 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
870 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
872 if (rtlpriv
->rtlhal
.up_first_time
)
875 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
876 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
877 rtl8812ae_sw_led_on(hw
, pled0
);
879 rtl8821ae_sw_led_on(hw
, pled0
);
880 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
881 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
882 rtl8812ae_sw_led_on(hw
, pled0
);
884 rtl8821ae_sw_led_on(hw
, pled0
);
886 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
887 rtl8812ae_sw_led_off(hw
, pled0
);
889 rtl8821ae_sw_led_off(hw
, pled0
);
892 static bool _rtl8821ae_init_mac(struct ieee80211_hw
*hw
)
894 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
895 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
896 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
900 bool mac_func_enable
= rtlhal
->mac_func_enable
;
902 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
904 /*Auto Power Down to CHIP-off State*/
905 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
906 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
908 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
909 /* HW Power on sequence*/
910 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
911 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
912 RTL8812_NIC_ENABLE_FLOW
)) {
913 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
914 "init 8812 MAC Fail as power on failure\n");
918 /* HW Power on sequence */
919 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_A_MSK
,
920 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
921 RTL8821A_NIC_ENABLE_FLOW
)){
922 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
923 "init 8821 MAC Fail as power on failure\n");
928 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
929 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
931 bytetmp
= rtl_read_byte(rtlpriv
, REG_CR
);
933 rtl_write_byte(rtlpriv
, REG_CR
, bytetmp
);
937 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, bytetmp
);
940 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
941 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
+ 3);
942 if (bytetmp
& BIT(0)) {
943 bytetmp
= rtl_read_byte(rtlpriv
, 0x7c);
945 rtl_write_byte(rtlpriv
, 0x7c, bytetmp
);
949 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1);
951 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1, bytetmp
);
953 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
955 if (!mac_func_enable
) {
956 if (!_rtl8821ae_llt_table_init(hw
))
960 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
961 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
963 /* Enable FW Beamformer Interrupt */
964 bytetmp
= rtl_read_byte(rtlpriv
, REG_FWIMR
+ 3);
965 rtl_write_byte(rtlpriv
, REG_FWIMR
+ 3, bytetmp
| BIT(6));
967 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
970 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
972 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 1, 0x1F);
973 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
974 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xFFFF);
976 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
977 rtlpci
->tx_ring
[BEACON_QUEUE
].dma
& DMA_BIT_MASK(32));
978 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
979 rtlpci
->tx_ring
[MGNT_QUEUE
].dma
& DMA_BIT_MASK(32));
980 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
981 rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
982 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
983 rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
984 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
985 rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
986 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
987 rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
988 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
989 rtlpci
->tx_ring
[HIGH_QUEUE
].dma
& DMA_BIT_MASK(32));
990 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
991 rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
& DMA_BIT_MASK(32));
993 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3, 0x77);
995 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
997 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0);
999 rtl_write_byte(rtlpriv
, REG_SECONDARY_CCA_CTRL
, 0x3);
1000 _rtl8821ae_gen_refresh_led_state(hw
);
1005 static void _rtl8821ae_hw_configure(struct ieee80211_hw
*hw
)
1007 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1008 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1011 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
1013 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_rrsr
);
1014 /* ARFB table 9 for 11ac 5G 2SS */
1015 rtl_write_dword(rtlpriv
, REG_ARFR0
+ 4, 0xfffff000);
1016 /* ARFB table 10 for 11ac 5G 1SS */
1017 rtl_write_dword(rtlpriv
, REG_ARFR1
+ 4, 0x003ff000);
1018 /* ARFB table 11 for 11ac 24G 1SS */
1019 rtl_write_dword(rtlpriv
, REG_ARFR2
, 0x00000015);
1020 rtl_write_dword(rtlpriv
, REG_ARFR2
+ 4, 0x003ff000);
1021 /* ARFB table 12 for 11ac 24G 1SS */
1022 rtl_write_dword(rtlpriv
, REG_ARFR3
, 0x00000015);
1023 rtl_write_dword(rtlpriv
, REG_ARFR3
+ 4, 0xffcff000);
1024 /* 0x420[7] = 0 , enable retry AMPDU in new AMPD not singal MPDU. */
1025 rtl_write_word(rtlpriv
, REG_FWHW_TXQ_CTRL
, 0x1F00);
1026 rtl_write_byte(rtlpriv
, REG_AMPDU_MAX_TIME
, 0x70);
1029 rtl_write_word(rtlpriv
, REG_RL
, 0x0707);
1031 /* Set Data / Response auto rate fallack retry count*/
1032 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x01000000);
1033 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4, 0x07060504);
1034 rtl_write_dword(rtlpriv
, REG_RARFRC
, 0x01000000);
1035 rtl_write_dword(rtlpriv
, REG_RARFRC
+ 4, 0x07060504);
1037 rtlpci
->reg_bcn_ctrl_val
= 0x1d;
1038 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, rtlpci
->reg_bcn_ctrl_val
);
1040 /* TBTT prohibit hold time. Suggested by designer TimChen. */
1041 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1043 /* AGGR_BK_TIME Reg51A 0x16 */
1044 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0040);
1046 /*For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
1047 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x03086666);
1049 rtl_write_byte(rtlpriv
, REG_HT_SINGLE_AMPDU
, 0x80);
1050 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x20);
1051 rtl_write_word(rtlpriv
, REG_MAX_AGGR_NUM
, 0x1F1F);
1054 static u16
_rtl8821ae_mdio_read(struct rtl_priv
*rtlpriv
, u8 addr
)
1057 u8 tmp
= 0, count
= 0;
1059 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(6));
1060 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1062 while (tmp
&& count
< 20) {
1064 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1068 ret
= rtl_read_word(rtlpriv
, REG_MDIO_RDATA
);
1073 static void _rtl8821ae_mdio_write(struct rtl_priv
*rtlpriv
, u8 addr
, u16 data
)
1075 u8 tmp
= 0, count
= 0;
1077 rtl_write_word(rtlpriv
, REG_MDIO_WDATA
, data
);
1078 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(5));
1079 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1081 while (tmp
&& count
< 20) {
1083 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1088 static u8
_rtl8821ae_dbi_read(struct rtl_priv
*rtlpriv
, u16 addr
)
1090 u16 read_addr
= addr
& 0xfffc;
1091 u8 tmp
= 0, count
= 0, ret
= 0;
1093 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, read_addr
);
1094 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x2);
1095 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1097 while (tmp
&& count
< 20) {
1099 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1103 read_addr
= REG_DBI_RDATA
+ addr
% 4;
1104 ret
= rtl_read_byte(rtlpriv
, read_addr
);
1109 static void _rtl8821ae_dbi_write(struct rtl_priv
*rtlpriv
, u16 addr
, u8 data
)
1111 u8 tmp
= 0, count
= 0;
1112 u16 write_addr
, remainder
= addr
% 4;
1114 write_addr
= REG_DBI_WDATA
+ remainder
;
1115 rtl_write_byte(rtlpriv
, write_addr
, data
);
1117 write_addr
= (addr
& 0xfffc) | (BIT(0) << (remainder
+ 12));
1118 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, write_addr
);
1120 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x1);
1122 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1124 while (tmp
&& count
< 20) {
1126 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1131 static void _rtl8821ae_enable_aspm_back_door(struct ieee80211_hw
*hw
)
1133 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1134 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1137 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1138 if (_rtl8821ae_mdio_read(rtlpriv
, 0x04) != 0x8544)
1139 _rtl8821ae_mdio_write(rtlpriv
, 0x04, 0x8544);
1141 if (_rtl8821ae_mdio_read(rtlpriv
, 0x0b) != 0x0070)
1142 _rtl8821ae_mdio_write(rtlpriv
, 0x0b, 0x0070);
1145 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x70f);
1146 _rtl8821ae_dbi_write(rtlpriv
, 0x70f, tmp
| BIT(7) |
1147 ASPM_L1_LATENCY
<< 3);
1149 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x719);
1150 _rtl8821ae_dbi_write(rtlpriv
, 0x719, tmp
| BIT(3) | BIT(4));
1152 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1153 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x718);
1154 _rtl8821ae_dbi_write(rtlpriv
, 0x718, tmp
|BIT(4));
1158 void rtl8821ae_enable_hw_security_config(struct ieee80211_hw
*hw
)
1160 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1164 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1165 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1166 rtlpriv
->sec
.pairwise_enc_algorithm
,
1167 rtlpriv
->sec
.group_enc_algorithm
);
1169 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1170 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1171 "not open hw encryption\n");
1175 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1177 if (rtlpriv
->sec
.use_defaultkey
) {
1178 sec_reg_value
|= SCR_TXUSEDK
;
1179 sec_reg_value
|= SCR_RXUSEDK
;
1182 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1184 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1185 rtl_write_byte(rtlpriv
, REG_CR
+ 1, tmp
| BIT(1));
1187 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1188 "The SECR-value %x\n", sec_reg_value
);
1190 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1193 /* Static MacID Mapping (cf. Used in MacIdDoStaticMapping) ---------- */
1194 #define MAC_ID_STATIC_FOR_DEFAULT_PORT 0
1195 #define MAC_ID_STATIC_FOR_BROADCAST_MULTICAST 1
1196 #define MAC_ID_STATIC_FOR_BT_CLIENT_START 2
1197 #define MAC_ID_STATIC_FOR_BT_CLIENT_END 3
1198 /* ----------------------------------------------------------- */
1200 static void rtl8821ae_macid_initialize_mediastatus(struct ieee80211_hw
*hw
)
1202 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1203 u8 media_rpt
[4] = {RT_MEDIA_CONNECT
, 1,
1204 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
,
1205 MAC_ID_STATIC_FOR_BT_CLIENT_END
};
1207 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1208 HW_VAR_H2C_FW_MEDIASTATUSRPT
, media_rpt
);
1210 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1211 "Initialize MacId media status: from %d to %d\n",
1212 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
,
1213 MAC_ID_STATIC_FOR_BT_CLIENT_END
);
1216 static bool _rtl8821ae_check_pcie_dma_hang(struct ieee80211_hw
*hw
)
1218 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1221 /* write reg 0x350 Bit[26]=1. Enable debug port. */
1222 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1223 if (!(tmp
& BIT(2))) {
1224 rtl_write_byte(rtlpriv
, REG_DBI_CTRL
+ 3, (tmp
| BIT(2)));
1228 /* read reg 0x350 Bit[25] if 1 : RX hang */
1229 /* read reg 0x350 Bit[24] if 1 : TX hang */
1230 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1231 if ((tmp
& BIT(0)) || (tmp
& BIT(1))) {
1232 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1233 "CheckPcieDMAHang8821AE(): true! Reset PCIE DMA!\n");
1240 static bool _rtl8821ae_reset_pcie_interface_dma(struct ieee80211_hw
*hw
,
1244 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1245 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1247 bool release_mac_rx_pause
;
1248 u8 backup_pcie_dma_pause
;
1250 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1252 /* 1. Disable register write lock. 0x1c[1] = 0 */
1253 tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
);
1255 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, tmp
);
1256 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1257 /* write 0xCC bit[2] = 1'b1 */
1258 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1260 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1263 /* 2. Check and pause TRX DMA */
1264 /* write 0x284 bit[18] = 1'b1 */
1265 /* write 0x301 = 0xFF */
1266 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1268 /* Already pause before the function for another purpose. */
1269 release_mac_rx_pause
= false;
1271 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1272 release_mac_rx_pause
= true;
1274 backup_pcie_dma_pause
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1);
1275 if (backup_pcie_dma_pause
!= 0xFF)
1276 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFF);
1279 /* 3. reset TRX function */
1280 /* write 0x100 = 0x00 */
1281 rtl_write_byte(rtlpriv
, REG_CR
, 0);
1284 /* 4. Reset PCIe DMA. 0x3[0] = 0 */
1285 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1287 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1289 /* 5. Enable PCIe DMA. 0x3[0] = 1 */
1290 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1292 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1295 /* 6. enable TRX function */
1296 /* write 0x100 = 0xFF */
1297 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1299 /* We should init LLT & RQPN and
1300 * prepare Tx/Rx descrptor address later
1301 * because MAC function is reset.*/
1304 /* 7. Restore PCIe autoload down bit */
1305 /* 8812AE does not has the defination. */
1306 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1307 /* write 0xF8 bit[17] = 1'b1 */
1308 tmp
= rtl_read_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2);
1310 rtl_write_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2, tmp
);
1313 /* In MAC power on state, BB and RF maybe in ON state,
1314 * if we release TRx DMA here.
1315 * it will cause packets to be started to Tx/Rx,
1316 * so we release Tx/Rx DMA later.*/
1317 if (!mac_power_on
/* || in_watchdog*/) {
1318 /* 8. release TRX DMA */
1319 /* write 0x284 bit[18] = 1'b0 */
1320 /* write 0x301 = 0x00 */
1321 if (release_mac_rx_pause
) {
1322 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1323 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
,
1326 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1,
1327 backup_pcie_dma_pause
);
1330 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1331 /* 9. lock system register */
1332 /* write 0xCC bit[2] = 1'b0 */
1333 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1335 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1340 static void _rtl8821ae_get_wakeup_reason(struct ieee80211_hw
*hw
)
1342 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1343 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1344 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
1347 fw_reason
= rtl_read_byte(rtlpriv
, REG_MCUTST_WOWLAN
);
1349 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "WOL Read 0x1c7 = %02X\n",
1352 ppsc
->wakeup_reason
= 0;
1354 rtlhal
->last_suspend_sec
= ktime_get_real_seconds();
1356 switch (fw_reason
) {
1357 case FW_WOW_V2_PTK_UPDATE_EVENT
:
1358 ppsc
->wakeup_reason
= WOL_REASON_PTK_UPDATE
;
1359 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1360 "It's a WOL PTK Key update event!\n");
1362 case FW_WOW_V2_GTK_UPDATE_EVENT
:
1363 ppsc
->wakeup_reason
= WOL_REASON_GTK_UPDATE
;
1364 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1365 "It's a WOL GTK Key update event!\n");
1367 case FW_WOW_V2_DISASSOC_EVENT
:
1368 ppsc
->wakeup_reason
= WOL_REASON_DISASSOC
;
1369 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1370 "It's a disassociation event!\n");
1372 case FW_WOW_V2_DEAUTH_EVENT
:
1373 ppsc
->wakeup_reason
= WOL_REASON_DEAUTH
;
1374 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1375 "It's a deauth event!\n");
1377 case FW_WOW_V2_FW_DISCONNECT_EVENT
:
1378 ppsc
->wakeup_reason
= WOL_REASON_AP_LOST
;
1379 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1380 "It's a Fw disconnect decision (AP lost) event!\n");
1382 case FW_WOW_V2_MAGIC_PKT_EVENT
:
1383 ppsc
->wakeup_reason
= WOL_REASON_MAGIC_PKT
;
1384 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1385 "It's a magic packet event!\n");
1387 case FW_WOW_V2_UNICAST_PKT_EVENT
:
1388 ppsc
->wakeup_reason
= WOL_REASON_UNICAST_PKT
;
1389 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1390 "It's an unicast packet event!\n");
1392 case FW_WOW_V2_PATTERN_PKT_EVENT
:
1393 ppsc
->wakeup_reason
= WOL_REASON_PATTERN_PKT
;
1394 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1395 "It's a pattern match event!\n");
1397 case FW_WOW_V2_RTD3_SSID_MATCH_EVENT
:
1398 ppsc
->wakeup_reason
= WOL_REASON_RTD3_SSID_MATCH
;
1399 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1400 "It's an RTD3 Ssid match event!\n");
1402 case FW_WOW_V2_REALWOW_V2_WAKEUPPKT
:
1403 ppsc
->wakeup_reason
= WOL_REASON_REALWOW_V2_WAKEUPPKT
;
1404 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1405 "It's an RealWoW wake packet event!\n");
1407 case FW_WOW_V2_REALWOW_V2_ACKLOST
:
1408 ppsc
->wakeup_reason
= WOL_REASON_REALWOW_V2_ACKLOST
;
1409 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1410 "It's an RealWoW ack lost event!\n");
1413 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1414 "WOL Read 0x1c7 = %02X, Unknown reason!\n",
1420 static void _rtl8821ae_init_trx_desc_hw_address(struct ieee80211_hw
*hw
)
1422 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1423 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1426 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
1427 rtlpci
->tx_ring
[BEACON_QUEUE
].dma
& DMA_BIT_MASK(32));
1428 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
1429 rtlpci
->tx_ring
[MGNT_QUEUE
].dma
& DMA_BIT_MASK(32));
1430 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
1431 rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
1432 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
1433 rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
1434 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
1435 rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
1436 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
1437 rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
1438 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
1439 rtlpci
->tx_ring
[HIGH_QUEUE
].dma
& DMA_BIT_MASK(32));
1440 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
1441 rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
& DMA_BIT_MASK(32));
1444 static bool _rtl8821ae_init_llt_table(struct ieee80211_hw
*hw
, u32 boundary
)
1448 u32 txpktbuf_bndy
= boundary
;
1449 u32 last_entry_of_txpktbuf
= LAST_ENTRY_OF_TX_PKT_BUFFER
;
1451 for (i
= 0 ; i
< (txpktbuf_bndy
- 1) ; i
++) {
1452 status
= _rtl8821ae_llt_write(hw
, i
, i
+ 1);
1457 status
= _rtl8821ae_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
1461 for (i
= txpktbuf_bndy
; i
< last_entry_of_txpktbuf
; i
++) {
1462 status
= _rtl8821ae_llt_write(hw
, i
, (i
+ 1));
1467 status
= _rtl8821ae_llt_write(hw
, last_entry_of_txpktbuf
,
1475 static bool _rtl8821ae_dynamic_rqpn(struct ieee80211_hw
*hw
, u32 boundary
,
1476 u16 npq_rqpn_value
, u32 rqpn_val
)
1478 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1481 u16 count
= 0, tmp16
;
1482 bool support_remote_wakeup
;
1484 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
1485 (u8
*)(&support_remote_wakeup
));
1487 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1488 "boundary=%#X, NPQ_RQPNValue=%#X, RQPNValue=%#X\n",
1489 boundary
, npq_rqpn_value
, rqpn_val
);
1492 * 1. 0x301[7:0] = 0xFE */
1493 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFE);
1496 * 2. polling till 0x41A[15:0]=0x07FF */
1497 tmp16
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
1498 while ((tmp16
& 0x07FF) != 0x07FF) {
1500 tmp16
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
1502 if ((count
% 200) == 0) {
1503 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1504 "Tx queue is not empty for 20ms!\n");
1506 if (count
>= 1000) {
1507 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1508 "Wait for Tx FIFO empty timeout!\n");
1514 * 3. reg 0x522=0xFF */
1515 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1517 /* Wait TX State Machine OK
1518 * 4. polling till reg 0x5FB~0x5F8 = 0x00000000 for 50ms */
1520 while (rtl_read_byte(rtlpriv
, REG_SCH_TXCMD
) != 0) {
1524 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1525 "Wait for TX State Machine ready timeout !!\n");
1532 * 6. wait till 0x284[17] == 1
1533 * wait RX DMA idle */
1535 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1536 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1538 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1541 } while (!(tmp
& BIT(1)) && count
< 100);
1543 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1544 "Wait until Rx DMA Idle. count=%d REG[0x286]=0x%x\n",
1548 * 7. 0x02 [0] = 0 */
1549 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
1551 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, tmp
);
1556 rtl_write_byte(rtlpriv
, REG_CR
, 0x00);
1559 /* Disable MAC Security Engine
1560 * 9. 0x100 bit[9]=0 */
1561 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1563 rtl_write_byte(rtlpriv
, REG_CR
+ 1, tmp
);
1565 /* To avoid DD-Tim Circuit hang
1566 * 10. 0x553 bit[5]=1 */
1567 tmp
= rtl_read_byte(rtlpriv
, REG_DUAL_TSF_RST
);
1568 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (tmp
| BIT(5)));
1570 /* Enable MAC Security Engine
1571 * 11. 0x100 bit[9]=1 */
1572 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1573 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
| BIT(1)));
1578 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1582 * 13. 0x02 [0] = 1 */
1583 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
1584 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, (tmp
| BIT(0)));
1587 * 14,15. set beacon head page (reg 0x209 and 0x424) */
1588 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, (u8
)boundary
);
1589 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, (u8
)boundary
);
1590 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, (u8
)boundary
);
1592 /* 16. WMAC_LBK_BF_HD 0x45D[7:0]
1594 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_WMAC_LBK_BF_HD
,
1597 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
, boundary
);
1601 if (!_rtl8821ae_init_llt_table(hw
, boundary
)) {
1602 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
1603 "Failed to init LLT table!\n");
1608 * 18. reallocate RQPN and init LLT */
1609 rtl_write_word(rtlpriv
, REG_RQPN_NPQ
, npq_rqpn_value
);
1610 rtl_write_dword(rtlpriv
, REG_RQPN
, rqpn_val
);
1614 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
1617 * 20. 0x301[7:0] = 0x00
1618 * 21. 0x284[18] = 0 */
1619 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0x00);
1620 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1621 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
&~BIT(2)));
1623 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "End.\n");
1627 static void _rtl8821ae_simple_initialize_adapter(struct ieee80211_hw
*hw
)
1629 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1630 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1631 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
1633 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
1634 /* Re-download normal Fw. */
1635 rtl8821ae_set_fw_related_for_wowlan(hw
, false);
1638 /* Re-Initialize LLT table. */
1639 if (rtlhal
->re_init_llt_table
) {
1640 u32 rqpn
= 0x80e70808;
1641 u8 rqpn_npq
= 0, boundary
= 0xF8;
1642 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1646 if (_rtl8821ae_dynamic_rqpn(hw
, boundary
, rqpn_npq
, rqpn
))
1647 rtlhal
->re_init_llt_table
= false;
1650 ppsc
->rfpwr_state
= ERFON
;
1653 static void _rtl8821ae_enable_l1off(struct ieee80211_hw
*hw
)
1656 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1658 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "--->\n");
1660 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x160);
1661 if (!(tmp
& (BIT(2) | BIT(3)))) {
1662 RT_TRACE(rtlpriv
, COMP_POWER
| COMP_INIT
, DBG_LOUD
,
1663 "0x160(%#x)return!!\n", tmp
);
1667 tmp
= _rtl8821ae_mdio_read(rtlpriv
, 0x1b);
1668 _rtl8821ae_mdio_write(rtlpriv
, 0x1b, (tmp
| BIT(4)));
1670 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x718);
1671 _rtl8821ae_dbi_write(rtlpriv
, 0x718, tmp
| BIT(5));
1673 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<---\n");
1676 static void _rtl8821ae_enable_ltr(struct ieee80211_hw
*hw
)
1679 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1681 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "--->\n");
1683 /* Check 0x98[10] */
1684 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x99);
1685 if (!(tmp
& BIT(2))) {
1686 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1687 "<---0x99(%#x) return!!\n", tmp
);
1691 /* LTR idle latency, 0x90 for 144us */
1692 rtl_write_dword(rtlpriv
, 0x798, 0x88908890);
1694 /* LTR active latency, 0x3c for 60us */
1695 rtl_write_dword(rtlpriv
, 0x79c, 0x883c883c);
1697 tmp
= rtl_read_byte(rtlpriv
, 0x7a4);
1698 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
| BIT(4)));
1700 tmp
= rtl_read_byte(rtlpriv
, 0x7a4);
1701 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
& (~BIT(0))));
1702 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
| BIT(0)));
1704 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<---\n");
1707 static bool _rtl8821ae_wowlan_initialize_adapter(struct ieee80211_hw
*hw
)
1709 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1710 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1711 bool init_finished
= true;
1714 /* Get Fw wake up reason. */
1715 _rtl8821ae_get_wakeup_reason(hw
);
1717 /* Patch Pcie Rx DMA hang after S3/S4 several times.
1718 * The root cause has not be found. */
1719 if (_rtl8821ae_check_pcie_dma_hang(hw
))
1720 _rtl8821ae_reset_pcie_interface_dma(hw
, true, false);
1722 /* Prepare Tx/Rx Desc Hw address. */
1723 _rtl8821ae_init_trx_desc_hw_address(hw
);
1725 /* Release Pcie Interface Rx DMA to allow wake packet DMA. */
1726 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFE);
1727 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Enable PCIE Rx DMA.\n");
1729 /* Check wake up event.
1730 * We should check wake packet bit before disable wowlan by H2C or
1731 * Fw will clear the bit. */
1732 tmp
= rtl_read_byte(rtlpriv
, REG_FTISR
+ 3);
1733 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
1734 "Read REG_FTISR 0x13f = %#X\n", tmp
);
1736 /* Set the WoWLAN related function control disable. */
1737 rtl8821ae_set_fw_wowlan_mode(hw
, false);
1738 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw
, 0);
1740 if (rtlhal
->hw_rof_enable
) {
1741 tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
+ 3);
1743 /* Clear GPIO9 ISR */
1744 rtl_write_byte(rtlpriv
, REG_HSISR
+ 3, tmp
| BIT(1));
1745 init_finished
= false;
1747 init_finished
= true;
1751 if (init_finished
) {
1752 _rtl8821ae_simple_initialize_adapter(hw
);
1754 /* Release Pcie Interface Tx DMA. */
1755 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0x00);
1756 /* Release Pcie RX DMA */
1757 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, 0x02);
1759 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1760 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
& (~BIT(0))));
1762 _rtl8821ae_enable_l1off(hw
);
1763 _rtl8821ae_enable_ltr(hw
);
1766 return init_finished
;
1769 static void _rtl8812ae_bb8812_config_1t(struct ieee80211_hw
*hw
)
1771 /* BB OFDM RX Path_A */
1772 rtl_set_bbreg(hw
, 0x808, 0xff, 0x11);
1773 /* BB OFDM TX Path_A */
1774 rtl_set_bbreg(hw
, 0x80c, MASKLWORD
, 0x1111);
1775 /* BB CCK R/Rx Path_A */
1776 rtl_set_bbreg(hw
, 0xa04, 0x0c000000, 0x0);
1778 rtl_set_bbreg(hw
, 0x8bc, 0xc0000060, 0x4);
1779 /* RF Path_B HSSI OFF */
1780 rtl_set_bbreg(hw
, 0xe00, 0xf, 0x4);
1781 /* RF Path_B Power Down */
1782 rtl_set_bbreg(hw
, 0xe90, MASKDWORD
, 0);
1783 /* ADDA Path_B OFF */
1784 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0);
1785 rtl_set_bbreg(hw
, 0xe64, MASKDWORD
, 0);
1788 static void _rtl8821ae_poweroff_adapter(struct ieee80211_hw
*hw
)
1790 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1791 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1794 rtlhal
->mac_func_enable
= false;
1796 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1797 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1798 /* 1. Run LPS WL RFOFF flow */
1799 /* RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1800 "=====>CardDisableRTL8812E,RTL8821A_NIC_LPS_ENTER_FLOW\n");
1802 rtl_hal_pwrseqcmdparsing(rtlpriv
,
1803 PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1804 PWR_INTF_PCI_MSK
, RTL8821A_NIC_LPS_ENTER_FLOW
);
1806 /* 2. 0x1F[7:0] = 0 */
1808 /* rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); */
1809 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) &&
1811 rtl8821ae_firmware_selfreset(hw
);
1814 /* Reset MCU. Suggested by Filen. */
1815 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1816 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+1, (u1b_tmp
& (~BIT(2))));
1818 /* g. MCUFWDL 0x80[1:0]=0 */
1819 /* reset MCU ready status */
1820 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1822 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1823 /* HW card disable configuration. */
1824 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1825 PWR_INTF_PCI_MSK
, RTL8821A_NIC_DISABLE_FLOW
);
1827 /* HW card disable configuration. */
1828 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1829 PWR_INTF_PCI_MSK
, RTL8812_NIC_DISABLE_FLOW
);
1832 /* Reset MCU IO Wrapper */
1833 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1834 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, (u1b_tmp
& (~BIT(0))));
1835 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1836 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, u1b_tmp
| BIT(0));
1838 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1839 /* lock ISO/CLK/Power control register */
1840 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0e);
1843 int rtl8821ae_hw_init(struct ieee80211_hw
*hw
)
1845 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1846 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1847 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1848 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1849 bool rtstatus
= true;
1852 bool support_remote_wakeup
;
1853 u32 nav_upper
= WIFI_NAV_UPPER_US
;
1855 rtlhal
->being_init_adapter
= true;
1856 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
1857 (u8
*)(&support_remote_wakeup
));
1858 rtlpriv
->intf_ops
->disable_aspm(hw
);
1860 /*YP wowlan not considered*/
1862 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_CR
);
1863 if (tmp_u1b
!= 0 && tmp_u1b
!= 0xEA) {
1864 rtlhal
->mac_func_enable
= true;
1865 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1866 "MAC has already power on.\n");
1868 rtlhal
->mac_func_enable
= false;
1869 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_8821AE
;
1872 if (support_remote_wakeup
&&
1873 rtlhal
->wake_from_pnp_sleep
&&
1874 rtlhal
->mac_func_enable
) {
1875 if (_rtl8821ae_wowlan_initialize_adapter(hw
)) {
1876 rtlhal
->being_init_adapter
= false;
1881 if (_rtl8821ae_check_pcie_dma_hang(hw
)) {
1882 _rtl8821ae_reset_pcie_interface_dma(hw
,
1883 rtlhal
->mac_func_enable
,
1885 rtlhal
->mac_func_enable
= false;
1888 /* Reset MAC/BB/RF status if it is not powered off
1889 * before calling initialize Hw flow to prevent
1890 * from interface and MAC status mismatch.
1891 * 2013.06.21, by tynli. Suggested by SD1 JackieLau. */
1892 if (rtlhal
->mac_func_enable
) {
1893 _rtl8821ae_poweroff_adapter(hw
);
1894 rtlhal
->mac_func_enable
= false;
1897 rtstatus
= _rtl8821ae_init_mac(hw
);
1898 if (rtstatus
!= true) {
1899 pr_err("Init MAC failed\n");
1904 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
);
1906 rtl_write_byte(rtlpriv
, REG_SYS_CFG
, tmp_u1b
);
1908 err
= rtl8821ae_download_fw(hw
, false);
1910 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1911 "Failed to download FW. Init HW without FW now\n");
1913 rtlhal
->fw_ready
= false;
1916 rtlhal
->fw_ready
= true;
1918 ppsc
->fw_current_inpsmode
= false;
1919 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_8821AE
;
1920 rtlhal
->fw_clk_change_in_progress
= false;
1921 rtlhal
->allow_sw_to_change_hwclc
= false;
1922 rtlhal
->last_hmeboxnum
= 0;
1924 /*SIC_Init(Adapter);
1925 if(rtlhal->AMPDUBurstMode)
1926 rtl_write_byte(rtlpriv,REG_AMPDU_BURST_MODE_8812, 0x7F);*/
1928 rtl8821ae_phy_mac_config(hw
);
1929 /* because last function modify RCR, so we update
1930 * rcr var here, or TP will unstable for receive_config
1931 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1932 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1933 rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
1934 rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
1935 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);*/
1936 rtl8821ae_phy_bb_config(hw
);
1938 rtl8821ae_phy_rf_config(hw
);
1940 if (rtlpriv
->phy
.rf_type
== RF_1T1R
&&
1941 rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
1942 _rtl8812ae_bb8812_config_1t(hw
);
1944 _rtl8821ae_hw_configure(hw
);
1946 rtl8821ae_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
1948 /*set wireless mode*/
1950 rtlhal
->mac_func_enable
= true;
1952 rtl_cam_reset_all_entry(hw
);
1954 rtl8821ae_enable_hw_security_config(hw
);
1956 ppsc
->rfpwr_state
= ERFON
;
1958 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1959 _rtl8821ae_enable_aspm_back_door(hw
);
1960 rtlpriv
->intf_ops
->enable_aspm(hw
);
1962 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
&&
1963 (rtlhal
->rfe_type
== 1 || rtlhal
->rfe_type
== 5))
1964 rtl_set_bbreg(hw
, 0x900, 0x00000303, 0x0302);
1966 rtl8821ae_bt_hw_init(hw
);
1967 rtlpriv
->rtlhal
.being_init_adapter
= false;
1969 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_NAV_UPPER
, (u8
*)&nav_upper
);
1971 /* rtl8821ae_dm_check_txpower_tracking(hw); */
1972 /* rtl8821ae_phy_lc_calibrate(hw); */
1973 if (support_remote_wakeup
)
1974 rtl_write_byte(rtlpriv
, REG_WOW_CTRL
, 0);
1977 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1978 if (tmp_u1b
& BIT(2)) {
1979 /* Release Rx DMA if needed*/
1981 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, tmp_u1b
);
1984 /* Release Tx/Rx PCIE DMA if*/
1985 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0);
1987 rtl8821ae_dm_init(hw
);
1988 rtl8821ae_macid_initialize_mediastatus(hw
);
1990 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rtl8821ae_hw_init() <====\n");
1994 static enum version_8821ae
_rtl8821ae_read_chip_version(struct ieee80211_hw
*hw
)
1996 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1997 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
1998 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1999 enum version_8821ae version
= VERSION_UNKNOWN
;
2002 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
2003 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2004 "ReadChipVersion8812A 0xF0 = 0x%x\n", value32
);
2006 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
2007 rtlphy
->rf_type
= RF_2T2R
;
2008 else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
)
2009 rtlphy
->rf_type
= RF_1T1R
;
2011 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2012 "RF_Type is %x!!\n", rtlphy
->rf_type
);
2014 if (value32
& TRP_VAUX_EN
) {
2015 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
2016 if (rtlphy
->rf_type
== RF_2T2R
)
2017 version
= VERSION_TEST_CHIP_2T2R_8812
;
2019 version
= VERSION_TEST_CHIP_1T1R_8812
;
2021 version
= VERSION_TEST_CHIP_8821
;
2023 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
2024 u32 rtl_id
= ((value32
& CHIP_VER_RTL_MASK
) >> 12) + 1;
2026 if (rtlphy
->rf_type
== RF_2T2R
)
2028 (enum version_8821ae
)(CHIP_8812
2032 version
= (enum version_8821ae
)(CHIP_8812
2035 version
= (enum version_8821ae
)(version
| (rtl_id
<< 12));
2036 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
2037 u32 rtl_id
= value32
& CHIP_VER_RTL_MASK
;
2039 version
= (enum version_8821ae
)(CHIP_8821
2040 | NORMAL_CHIP
| rtl_id
);
2044 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
2046 value32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
2047 rtlhal
->hw_rof_enable
= ((value32
& WL_HWROF_EN
) ? 1 : 0);
2051 case VERSION_TEST_CHIP_1T1R_8812
:
2052 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2053 "Chip Version ID: VERSION_TEST_CHIP_1T1R_8812\n");
2055 case VERSION_TEST_CHIP_2T2R_8812
:
2056 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2057 "Chip Version ID: VERSION_TEST_CHIP_2T2R_8812\n");
2059 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812
:
2060 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2061 "Chip Version ID:VERSION_NORMAL_TSMC_CHIP_1T1R_8812\n");
2063 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812
:
2064 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2065 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812\n");
2067 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812_C_CUT
:
2068 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2069 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_1T1R_8812 C CUT\n");
2071 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812_C_CUT
:
2072 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2073 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812 C CUT\n");
2075 case VERSION_TEST_CHIP_8821
:
2076 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2077 "Chip Version ID: VERSION_TEST_CHIP_8821\n");
2079 case VERSION_NORMAL_TSMC_CHIP_8821
:
2080 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2081 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 A CUT\n");
2083 case VERSION_NORMAL_TSMC_CHIP_8821_B_CUT
:
2084 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2085 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 B CUT\n");
2088 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2089 "Chip Version ID: Unknown (0x%X)\n", version
);
2096 static int _rtl8821ae_set_media_status(struct ieee80211_hw
*hw
,
2097 enum nl80211_iftype type
)
2099 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2100 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
2101 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
2104 rtl_write_dword(rtlpriv
, REG_BCN_CTRL
, 0);
2105 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_LOUD
,
2106 "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
2108 if (type
== NL80211_IFTYPE_UNSPECIFIED
||
2109 type
== NL80211_IFTYPE_STATION
) {
2110 _rtl8821ae_stop_tx_beacon(hw
);
2111 _rtl8821ae_enable_bcn_sub_func(hw
);
2112 } else if (type
== NL80211_IFTYPE_ADHOC
||
2113 type
== NL80211_IFTYPE_AP
) {
2114 _rtl8821ae_resume_tx_beacon(hw
);
2115 _rtl8821ae_disable_bcn_sub_func(hw
);
2117 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2118 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
2123 case NL80211_IFTYPE_UNSPECIFIED
:
2124 bt_msr
|= MSR_NOLINK
;
2125 ledaction
= LED_CTL_LINK
;
2126 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2127 "Set Network type to NO LINK!\n");
2129 case NL80211_IFTYPE_ADHOC
:
2130 bt_msr
|= MSR_ADHOC
;
2131 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2132 "Set Network type to Ad Hoc!\n");
2134 case NL80211_IFTYPE_STATION
:
2135 bt_msr
|= MSR_INFRA
;
2136 ledaction
= LED_CTL_LINK
;
2137 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2138 "Set Network type to STA!\n");
2140 case NL80211_IFTYPE_AP
:
2142 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2143 "Set Network type to AP!\n");
2146 pr_err("Network type %d not support!\n", type
);
2150 rtl_write_byte(rtlpriv
, MSR
, bt_msr
);
2151 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
2152 if ((bt_msr
& MSR_MASK
) == MSR_AP
)
2153 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
2155 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
2160 void rtl8821ae_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
2162 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2163 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2164 u32 reg_rcr
= rtlpci
->receive_config
;
2166 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
2170 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
2171 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
2173 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
2174 } else if (!check_bssid
) {
2175 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
2176 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
2177 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2178 HW_VAR_RCR
, (u8
*)(®_rcr
));
2182 int rtl8821ae_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
2184 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2186 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rtl8821ae_set_network_type!\n");
2188 if (_rtl8821ae_set_media_status(hw
, type
))
2191 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
2192 if (type
!= NL80211_IFTYPE_AP
)
2193 rtl8821ae_set_check_bssid(hw
, true);
2195 rtl8821ae_set_check_bssid(hw
, false);
2201 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
2202 void rtl8821ae_set_qos(struct ieee80211_hw
*hw
, int aci
)
2204 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2205 rtl8821ae_dm_init_edca_turbo(hw
);
2208 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
2211 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
2214 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
2217 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
2220 WARN_ONCE(true, "rtl8821ae: invalid aci: %d !\n", aci
);
2225 static void rtl8821ae_clear_interrupt(struct ieee80211_hw
*hw
)
2227 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2228 u32 tmp
= rtl_read_dword(rtlpriv
, REG_HISR
);
2230 rtl_write_dword(rtlpriv
, REG_HISR
, tmp
);
2232 tmp
= rtl_read_dword(rtlpriv
, REG_HISRE
);
2233 rtl_write_dword(rtlpriv
, REG_HISRE
, tmp
);
2235 tmp
= rtl_read_dword(rtlpriv
, REG_HSISR
);
2236 rtl_write_dword(rtlpriv
, REG_HSISR
, tmp
);
2239 void rtl8821ae_enable_interrupt(struct ieee80211_hw
*hw
)
2241 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2242 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2244 if (rtlpci
->int_clear
)
2245 rtl8821ae_clear_interrupt(hw
);/*clear it here first*/
2247 rtl_write_dword(rtlpriv
, REG_HIMR
, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
2248 rtl_write_dword(rtlpriv
, REG_HIMRE
, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
2249 rtlpci
->irq_enabled
= true;
2250 /* there are some C2H CMDs have been sent before
2251 system interrupt is enabled, e.g., C2H, CPWM.
2252 *So we need to clear all C2H events that FW has
2253 notified, otherwise FW won't schedule any commands anymore.
2255 /* rtl_write_byte(rtlpriv, REG_C2HEVT_CLEAR, 0); */
2256 /*enable system interrupt*/
2257 rtl_write_dword(rtlpriv
, REG_HSIMR
, rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
2260 void rtl8821ae_disable_interrupt(struct ieee80211_hw
*hw
)
2262 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2263 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2265 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
2266 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
2267 rtlpci
->irq_enabled
= false;
2268 /*synchronize_irq(rtlpci->pdev->irq);*/
2271 static void _rtl8821ae_clear_pci_pme_status(struct ieee80211_hw
*hw
)
2273 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2274 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2281 /* Get the Capability pointer first,
2282 * the Capability Pointer is located at
2283 * offset 0x34 from the Function Header */
2285 pci_read_config_byte(rtlpci
->pdev
, 0x34, &cap_pointer
);
2286 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2287 "PCI configuration 0x34 = 0x%2x\n", cap_pointer
);
2290 pci_read_config_word(rtlpci
->pdev
, cap_pointer
, &cap_hdr
);
2291 cap_id
= cap_hdr
& 0xFF;
2293 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2294 "in pci configuration, cap_pointer%x = %x\n",
2295 cap_pointer
, cap_id
);
2297 if (cap_id
== 0x01) {
2300 /* point to next Capability */
2301 cap_pointer
= (cap_hdr
>> 8) & 0xFF;
2302 /* 0: end of pci capability, 0xff: invalid value */
2303 if (cap_pointer
== 0x00 || cap_pointer
== 0xff) {
2308 } while (cnt
++ < 200);
2310 if (cap_id
== 0x01) {
2311 /* Get the PM CSR (Control/Status Register),
2312 * The PME_Status is located at PM Capatibility offset 5, bit 7
2314 pci_read_config_byte(rtlpci
->pdev
, cap_pointer
+ 5, &pmcs_reg
);
2316 if (pmcs_reg
& BIT(7)) {
2317 /* PME event occured, clear the PM_Status by write 1 */
2318 pmcs_reg
= pmcs_reg
| BIT(7);
2320 pci_write_config_byte(rtlpci
->pdev
, cap_pointer
+ 5,
2322 /* Read it back to check */
2323 pci_read_config_byte(rtlpci
->pdev
, cap_pointer
+ 5,
2325 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2326 "Clear PME status 0x%2x to 0x%2x\n",
2327 cap_pointer
+ 5, pmcs_reg
);
2329 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2330 "PME status(0x%2x) = 0x%2x\n",
2331 cap_pointer
+ 5, pmcs_reg
);
2334 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
2335 "Cannot find PME Capability\n");
2339 void rtl8821ae_card_disable(struct ieee80211_hw
*hw
)
2341 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2342 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2343 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
2344 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
2345 enum nl80211_iftype opmode
;
2346 bool support_remote_wakeup
;
2350 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
2351 (u8
*)(&support_remote_wakeup
));
2353 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2355 if (!(support_remote_wakeup
&& mac
->opmode
== NL80211_IFTYPE_STATION
)
2356 || !rtlhal
->enter_pnp_sleep
) {
2357 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Normal Power off\n");
2358 mac
->link_state
= MAC80211_NOLINK
;
2359 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
2360 _rtl8821ae_set_media_status(hw
, opmode
);
2361 _rtl8821ae_poweroff_adapter(hw
);
2363 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Wowlan Supported.\n");
2364 /* 3 <1> Prepare for configuring wowlan related infomations */
2365 /* Clear Fw WoWLAN event. */
2366 rtl_write_byte(rtlpriv
, REG_MCUTST_WOWLAN
, 0x0);
2368 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
2369 rtl8821ae_set_fw_related_for_wowlan(hw
, true);
2371 /* Dynamically adjust Tx packet boundary
2372 * for download reserved page packet.
2373 * reserve 30 pages for rsvd page */
2374 if (_rtl8821ae_dynamic_rqpn(hw
, 0xE0, 0x3, 0x80c20d0d))
2375 rtlhal
->re_init_llt_table
= true;
2377 /* 3 <2> Set Fw releted H2C cmd. */
2379 /* Set WoWLAN related security information. */
2380 rtl8821ae_set_fw_global_info_cmd(hw
);
2382 _rtl8821ae_download_rsvd_page(hw
, true);
2384 /* Just enable AOAC related functions when we connect to AP. */
2385 printk("mac->link_state = %d\n", mac
->link_state
);
2386 if (mac
->link_state
>= MAC80211_LINKED
&&
2387 mac
->opmode
== NL80211_IFTYPE_STATION
) {
2388 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
2389 rtl8821ae_set_fw_media_status_rpt_cmd(hw
,
2392 rtl8821ae_set_fw_wowlan_mode(hw
, true);
2393 /* Enable Fw Keep alive mechanism. */
2394 rtl8821ae_set_fw_keep_alive_cmd(hw
, true);
2396 /* Enable disconnect decision control. */
2397 rtl8821ae_set_fw_disconnect_decision_ctrl_cmd(hw
, true);
2400 /* 3 <3> Hw Configutations */
2402 /* Wait untill Rx DMA Finished before host sleep.
2403 * FW Pause Rx DMA may happens when received packet doing dma.
2405 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, BIT(2));
2407 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
2409 while (!(tmp
& BIT(1)) && (count
++ < 100)) {
2411 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
2413 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2414 "Wait Rx DMA Finished before host sleep. count=%d\n",
2417 /* reset trx ring */
2418 rtlpriv
->intf_ops
->reset_trx_ring(hw
);
2420 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, 0x0);
2422 _rtl8821ae_clear_pci_pme_status(hw
);
2423 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
2424 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, tmp
| BIT(3));
2425 /* prevent 8051 to be reset by PERST */
2426 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x20);
2427 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x60);
2430 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
2431 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
2432 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
2433 /* For wowlan+LPS+32k. */
2434 if (support_remote_wakeup
&& rtlhal
->enter_pnp_sleep
) {
2435 /* Set the WoWLAN related function control enable.
2436 * It should be the last H2C cmd in the WoWLAN flow. */
2437 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw
, 1);
2439 /* Stop Pcie Interface Tx DMA. */
2440 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xff);
2441 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Stop PCIE Tx DMA.\n");
2443 /* Wait for TxDMA idle. */
2446 tmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
);
2449 } while ((tmp
!= 0) && (count
< 100));
2450 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2451 "Wait Tx DMA Finished before host sleep. count=%d\n",
2454 if (rtlhal
->hw_rof_enable
) {
2455 printk("hw_rof_enable\n");
2456 tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
+ 3);
2457 rtl_write_byte(rtlpriv
, REG_HSISR
+ 3, tmp
| BIT(1));
2460 /* after power off we should do iqk again */
2461 rtlpriv
->phy
.iqk_initialized
= false;
2464 void rtl8821ae_interrupt_recognized(struct ieee80211_hw
*hw
,
2465 struct rtl_int
*intvec
)
2467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2468 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2470 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
2471 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
2473 intvec
->intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) & rtlpci
->irq_mask
[1];
2474 rtl_write_dword(rtlpriv
, REG_HISRE
, intvec
->intb
);
2477 void rtl8821ae_set_beacon_related_registers(struct ieee80211_hw
*hw
)
2479 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2480 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2481 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2482 u16 bcn_interval
, atim_window
;
2484 bcn_interval
= mac
->beacon_interval
;
2485 atim_window
= 2; /*FIX MERGE */
2486 rtl8821ae_disable_interrupt(hw
);
2487 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
2488 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
2489 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
2490 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
2491 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
2492 rtl_write_byte(rtlpriv
, 0x606, 0x30);
2493 rtlpci
->reg_bcn_ctrl_val
|= BIT(3);
2494 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
2495 rtl8821ae_enable_interrupt(hw
);
2498 void rtl8821ae_set_beacon_interval(struct ieee80211_hw
*hw
)
2500 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2501 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2502 u16 bcn_interval
= mac
->beacon_interval
;
2504 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2505 "beacon_interval:%d\n", bcn_interval
);
2506 rtl8821ae_disable_interrupt(hw
);
2507 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
2508 rtl8821ae_enable_interrupt(hw
);
2511 void rtl8821ae_update_interrupt_mask(struct ieee80211_hw
*hw
,
2512 u32 add_msr
, u32 rm_msr
)
2514 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2515 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2517 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
2518 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
2521 rtlpci
->irq_mask
[0] |= add_msr
;
2523 rtlpci
->irq_mask
[0] &= (~rm_msr
);
2524 rtl8821ae_disable_interrupt(hw
);
2525 rtl8821ae_enable_interrupt(hw
);
2528 static u8
_rtl8821ae_get_chnl_group(u8 chnl
)
2533 if (1 <= chnl
&& chnl
<= 2)
2535 else if (3 <= chnl
&& chnl
<= 5)
2537 else if (6 <= chnl
&& chnl
<= 8)
2539 else if (9 <= chnl
&& chnl
<= 11)
2541 else /*if (12 <= chnl && chnl <= 14)*/
2544 if (36 <= chnl
&& chnl
<= 42)
2546 else if (44 <= chnl
&& chnl
<= 48)
2548 else if (50 <= chnl
&& chnl
<= 58)
2550 else if (60 <= chnl
&& chnl
<= 64)
2552 else if (100 <= chnl
&& chnl
<= 106)
2554 else if (108 <= chnl
&& chnl
<= 114)
2556 else if (116 <= chnl
&& chnl
<= 122)
2558 else if (124 <= chnl
&& chnl
<= 130)
2560 else if (132 <= chnl
&& chnl
<= 138)
2562 else if (140 <= chnl
&& chnl
<= 144)
2564 else if (149 <= chnl
&& chnl
<= 155)
2566 else if (157 <= chnl
&& chnl
<= 161)
2568 else if (165 <= chnl
&& chnl
<= 171)
2570 else if (173 <= chnl
&& chnl
<= 177)
2574 "rtl8821ae: 5G, Channel %d in Group not found\n",
2580 static void _rtl8821ae_read_power_value_fromprom(struct ieee80211_hw
*hw
,
2581 struct txpower_info_2g
*pwrinfo24g
,
2582 struct txpower_info_5g
*pwrinfo5g
,
2586 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2587 u32 rfpath
, eeaddr
= EEPROM_TX_PWR_INX
, group
, txcount
= 0;
2589 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2590 "hal_ReadPowerValueFromPROM8821ae(): hwinfo[0x%x]=0x%x\n",
2591 (eeaddr
+ 1), hwinfo
[eeaddr
+ 1]);
2592 if (hwinfo
[eeaddr
+ 1] == 0xFF) /*YJ,add,120316*/
2593 autoload_fail
= true;
2595 if (autoload_fail
) {
2596 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2597 "auto load fail : Use Default value!\n");
2598 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
2599 /*2.4G default value*/
2600 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
2601 pwrinfo24g
->index_cck_base
[rfpath
][group
] = 0x2D;
2602 pwrinfo24g
->index_bw40_base
[rfpath
][group
] = 0x2D;
2604 for (txcount
= 0; txcount
< MAX_TX_COUNT
; txcount
++) {
2606 pwrinfo24g
->bw20_diff
[rfpath
][0] = 0x02;
2607 pwrinfo24g
->ofdm_diff
[rfpath
][0] = 0x04;
2609 pwrinfo24g
->bw20_diff
[rfpath
][txcount
] = 0xFE;
2610 pwrinfo24g
->bw40_diff
[rfpath
][txcount
] = 0xFE;
2611 pwrinfo24g
->cck_diff
[rfpath
][txcount
] = 0xFE;
2612 pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] = 0xFE;
2615 /*5G default value*/
2616 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++)
2617 pwrinfo5g
->index_bw40_base
[rfpath
][group
] = 0x2A;
2619 for (txcount
= 0; txcount
< MAX_TX_COUNT
; txcount
++) {
2621 pwrinfo5g
->ofdm_diff
[rfpath
][0] = 0x04;
2622 pwrinfo5g
->bw20_diff
[rfpath
][0] = 0x00;
2623 pwrinfo5g
->bw80_diff
[rfpath
][0] = 0xFE;
2624 pwrinfo5g
->bw160_diff
[rfpath
][0] = 0xFE;
2626 pwrinfo5g
->ofdm_diff
[rfpath
][0] = 0xFE;
2627 pwrinfo5g
->bw20_diff
[rfpath
][0] = 0xFE;
2628 pwrinfo5g
->bw40_diff
[rfpath
][0] = 0xFE;
2629 pwrinfo5g
->bw80_diff
[rfpath
][0] = 0xFE;
2630 pwrinfo5g
->bw160_diff
[rfpath
][0] = 0xFE;
2637 rtl_priv(hw
)->efuse
.txpwr_fromeprom
= true;
2639 for (rfpath
= 0 ; rfpath
< MAX_RF_PATH
; rfpath
++) {
2640 /*2.4G default value*/
2641 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
2642 pwrinfo24g
->index_cck_base
[rfpath
][group
] = hwinfo
[eeaddr
++];
2643 if (pwrinfo24g
->index_cck_base
[rfpath
][group
] == 0xFF)
2644 pwrinfo24g
->index_cck_base
[rfpath
][group
] = 0x2D;
2646 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
- 1; group
++) {
2647 pwrinfo24g
->index_bw40_base
[rfpath
][group
] = hwinfo
[eeaddr
++];
2648 if (pwrinfo24g
->index_bw40_base
[rfpath
][group
] == 0xFF)
2649 pwrinfo24g
->index_bw40_base
[rfpath
][group
] = 0x2D;
2651 for (txcount
= 0; txcount
< MAX_TX_COUNT
; txcount
++) {
2653 pwrinfo24g
->bw40_diff
[rfpath
][txcount
] = 0;
2654 /*bit sign number to 8 bit sign number*/
2655 pwrinfo24g
->bw20_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2656 if (pwrinfo24g
->bw20_diff
[rfpath
][txcount
] & BIT(3))
2657 pwrinfo24g
->bw20_diff
[rfpath
][txcount
] |= 0xF0;
2658 /*bit sign number to 8 bit sign number*/
2659 pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0x0f);
2660 if (pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] & BIT(3))
2661 pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] |= 0xF0;
2663 pwrinfo24g
->cck_diff
[rfpath
][txcount
] = 0;
2666 pwrinfo24g
->bw40_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2667 if (pwrinfo24g
->bw40_diff
[rfpath
][txcount
] & BIT(3))
2668 pwrinfo24g
->bw40_diff
[rfpath
][txcount
] |= 0xF0;
2670 pwrinfo24g
->bw20_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0x0f);
2671 if (pwrinfo24g
->bw20_diff
[rfpath
][txcount
] & BIT(3))
2672 pwrinfo24g
->bw20_diff
[rfpath
][txcount
] |= 0xF0;
2676 pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2677 if (pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] & BIT(3))
2678 pwrinfo24g
->ofdm_diff
[rfpath
][txcount
] |= 0xF0;
2680 pwrinfo24g
->cck_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0x0f);
2681 if (pwrinfo24g
->cck_diff
[rfpath
][txcount
] & BIT(3))
2682 pwrinfo24g
->cck_diff
[rfpath
][txcount
] |= 0xF0;
2688 /*5G default value*/
2689 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++) {
2690 pwrinfo5g
->index_bw40_base
[rfpath
][group
] = hwinfo
[eeaddr
++];
2691 if (pwrinfo5g
->index_bw40_base
[rfpath
][group
] == 0xFF)
2692 pwrinfo5g
->index_bw40_base
[rfpath
][group
] = 0xFE;
2695 for (txcount
= 0; txcount
< MAX_TX_COUNT
; txcount
++) {
2697 pwrinfo5g
->bw40_diff
[rfpath
][txcount
] = 0;
2699 pwrinfo5g
->bw20_diff
[rfpath
][0] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2700 if (pwrinfo5g
->bw20_diff
[rfpath
][txcount
] & BIT(3))
2701 pwrinfo5g
->bw20_diff
[rfpath
][txcount
] |= 0xF0;
2703 pwrinfo5g
->ofdm_diff
[rfpath
][0] = (hwinfo
[eeaddr
] & 0x0f);
2704 if (pwrinfo5g
->ofdm_diff
[rfpath
][txcount
] & BIT(3))
2705 pwrinfo5g
->ofdm_diff
[rfpath
][txcount
] |= 0xF0;
2709 pwrinfo5g
->bw40_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2710 if (pwrinfo5g
->bw40_diff
[rfpath
][txcount
] & BIT(3))
2711 pwrinfo5g
->bw40_diff
[rfpath
][txcount
] |= 0xF0;
2713 pwrinfo5g
->bw20_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0x0f);
2714 if (pwrinfo5g
->bw20_diff
[rfpath
][txcount
] & BIT(3))
2715 pwrinfo5g
->bw20_diff
[rfpath
][txcount
] |= 0xF0;
2721 pwrinfo5g
->ofdm_diff
[rfpath
][1] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2722 pwrinfo5g
->ofdm_diff
[rfpath
][2] = (hwinfo
[eeaddr
] & 0x0f);
2726 pwrinfo5g
->ofdm_diff
[rfpath
][3] = (hwinfo
[eeaddr
] & 0x0f);
2730 for (txcount
= 1; txcount
< MAX_TX_COUNT
; txcount
++) {
2731 if (pwrinfo5g
->ofdm_diff
[rfpath
][txcount
] & BIT(3))
2732 pwrinfo5g
->ofdm_diff
[rfpath
][txcount
] |= 0xF0;
2734 for (txcount
= 0; txcount
< MAX_TX_COUNT
; txcount
++) {
2735 pwrinfo5g
->bw80_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0xf0) >> 4;
2736 /* 4bit sign number to 8 bit sign number */
2737 if (pwrinfo5g
->bw80_diff
[rfpath
][txcount
] & BIT(3))
2738 pwrinfo5g
->bw80_diff
[rfpath
][txcount
] |= 0xF0;
2739 /* 4bit sign number to 8 bit sign number */
2740 pwrinfo5g
->bw160_diff
[rfpath
][txcount
] = (hwinfo
[eeaddr
] & 0x0f);
2741 if (pwrinfo5g
->bw160_diff
[rfpath
][txcount
] & BIT(3))
2742 pwrinfo5g
->bw160_diff
[rfpath
][txcount
] |= 0xF0;
2749 static void _rtl8812ae_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
2753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2754 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2755 struct txpower_info_2g pwrinfo24g
;
2756 struct txpower_info_5g pwrinfo5g
;
2760 _rtl8821ae_read_power_value_fromprom(hw
, &pwrinfo24g
,
2761 &pwrinfo5g
, autoload_fail
, hwinfo
);
2763 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
2764 for (i
= 0; i
< CHANNEL_MAX_NUMBER_2G
; i
++) {
2765 index
= _rtl8821ae_get_chnl_group(i
+ 1);
2767 if (i
== CHANNEL_MAX_NUMBER_2G
- 1) {
2768 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2769 pwrinfo24g
.index_cck_base
[rf_path
][5];
2770 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2771 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2773 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2774 pwrinfo24g
.index_cck_base
[rf_path
][index
];
2775 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2776 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2780 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G
; i
++) {
2781 index
= _rtl8821ae_get_chnl_group(channel5g
[i
]);
2782 rtlefuse
->txpwr_5g_bw40base
[rf_path
][i
] =
2783 pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2785 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G_80M
; i
++) {
2787 index
= _rtl8821ae_get_chnl_group(channel5g_80m
[i
]);
2788 upper
= pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2789 lower
= pwrinfo5g
.index_bw40_base
[rf_path
][index
+ 1];
2791 rtlefuse
->txpwr_5g_bw80base
[rf_path
][i
] = (upper
+ lower
) / 2;
2793 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
2794 rtlefuse
->txpwr_cckdiff
[rf_path
][i
] =
2795 pwrinfo24g
.cck_diff
[rf_path
][i
];
2796 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
2797 pwrinfo24g
.ofdm_diff
[rf_path
][i
];
2798 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
2799 pwrinfo24g
.bw20_diff
[rf_path
][i
];
2800 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
2801 pwrinfo24g
.bw40_diff
[rf_path
][i
];
2803 rtlefuse
->txpwr_5g_ofdmdiff
[rf_path
][i
] =
2804 pwrinfo5g
.ofdm_diff
[rf_path
][i
];
2805 rtlefuse
->txpwr_5g_bw20diff
[rf_path
][i
] =
2806 pwrinfo5g
.bw20_diff
[rf_path
][i
];
2807 rtlefuse
->txpwr_5g_bw40diff
[rf_path
][i
] =
2808 pwrinfo5g
.bw40_diff
[rf_path
][i
];
2809 rtlefuse
->txpwr_5g_bw80diff
[rf_path
][i
] =
2810 pwrinfo5g
.bw80_diff
[rf_path
][i
];
2814 if (!autoload_fail
) {
2815 rtlefuse
->eeprom_regulatory
=
2816 hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x07;/*bit0~2*/
2817 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xFF)
2818 rtlefuse
->eeprom_regulatory
= 0;
2820 rtlefuse
->eeprom_regulatory
= 0;
2823 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2824 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2827 static void _rtl8821ae_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
2831 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2832 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2833 struct txpower_info_2g pwrinfo24g
;
2834 struct txpower_info_5g pwrinfo5g
;
2838 _rtl8821ae_read_power_value_fromprom(hw
, &pwrinfo24g
,
2839 &pwrinfo5g
, autoload_fail
, hwinfo
);
2841 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
2842 for (i
= 0; i
< CHANNEL_MAX_NUMBER_2G
; i
++) {
2843 index
= _rtl8821ae_get_chnl_group(i
+ 1);
2845 if (i
== CHANNEL_MAX_NUMBER_2G
- 1) {
2846 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2847 pwrinfo24g
.index_cck_base
[rf_path
][5];
2848 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2849 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2851 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2852 pwrinfo24g
.index_cck_base
[rf_path
][index
];
2853 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2854 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2858 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G
; i
++) {
2859 index
= _rtl8821ae_get_chnl_group(channel5g
[i
]);
2860 rtlefuse
->txpwr_5g_bw40base
[rf_path
][i
] =
2861 pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2863 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G_80M
; i
++) {
2865 index
= _rtl8821ae_get_chnl_group(channel5g_80m
[i
]);
2866 upper
= pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2867 lower
= pwrinfo5g
.index_bw40_base
[rf_path
][index
+ 1];
2869 rtlefuse
->txpwr_5g_bw80base
[rf_path
][i
] = (upper
+ lower
) / 2;
2871 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
2872 rtlefuse
->txpwr_cckdiff
[rf_path
][i
] =
2873 pwrinfo24g
.cck_diff
[rf_path
][i
];
2874 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
2875 pwrinfo24g
.ofdm_diff
[rf_path
][i
];
2876 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
2877 pwrinfo24g
.bw20_diff
[rf_path
][i
];
2878 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
2879 pwrinfo24g
.bw40_diff
[rf_path
][i
];
2881 rtlefuse
->txpwr_5g_ofdmdiff
[rf_path
][i
] =
2882 pwrinfo5g
.ofdm_diff
[rf_path
][i
];
2883 rtlefuse
->txpwr_5g_bw20diff
[rf_path
][i
] =
2884 pwrinfo5g
.bw20_diff
[rf_path
][i
];
2885 rtlefuse
->txpwr_5g_bw40diff
[rf_path
][i
] =
2886 pwrinfo5g
.bw40_diff
[rf_path
][i
];
2887 rtlefuse
->txpwr_5g_bw80diff
[rf_path
][i
] =
2888 pwrinfo5g
.bw80_diff
[rf_path
][i
];
2892 if (!autoload_fail
) {
2893 rtlefuse
->eeprom_regulatory
= hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x07;
2894 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xFF)
2895 rtlefuse
->eeprom_regulatory
= 0;
2897 rtlefuse
->eeprom_regulatory
= 0;
2900 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2901 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2904 static void _rtl8812ae_read_pa_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
2907 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2908 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2910 if (!autoload_fail
) {
2911 rtlhal
->pa_type_2g
= hwinfo
[0XBC];
2912 rtlhal
->lna_type_2g
= hwinfo
[0XBD];
2913 if (rtlhal
->pa_type_2g
== 0xFF && rtlhal
->lna_type_2g
== 0xFF) {
2914 rtlhal
->pa_type_2g
= 0;
2915 rtlhal
->lna_type_2g
= 0;
2917 rtlhal
->external_pa_2g
= ((rtlhal
->pa_type_2g
& BIT(5)) &&
2918 (rtlhal
->pa_type_2g
& BIT(4))) ?
2920 rtlhal
->external_lna_2g
= ((rtlhal
->lna_type_2g
& BIT(7)) &&
2921 (rtlhal
->lna_type_2g
& BIT(3))) ?
2924 rtlhal
->pa_type_5g
= hwinfo
[0XBC];
2925 rtlhal
->lna_type_5g
= hwinfo
[0XBF];
2926 if (rtlhal
->pa_type_5g
== 0xFF && rtlhal
->lna_type_5g
== 0xFF) {
2927 rtlhal
->pa_type_5g
= 0;
2928 rtlhal
->lna_type_5g
= 0;
2930 rtlhal
->external_pa_5g
= ((rtlhal
->pa_type_5g
& BIT(1)) &&
2931 (rtlhal
->pa_type_5g
& BIT(0))) ?
2933 rtlhal
->external_lna_5g
= ((rtlhal
->lna_type_5g
& BIT(7)) &&
2934 (rtlhal
->lna_type_5g
& BIT(3))) ?
2937 rtlhal
->external_pa_2g
= 0;
2938 rtlhal
->external_lna_2g
= 0;
2939 rtlhal
->external_pa_5g
= 0;
2940 rtlhal
->external_lna_5g
= 0;
2944 static void _rtl8812ae_read_amplifier_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
2947 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2948 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2950 u8 ext_type_pa_2g_a
= (hwinfo
[0XBD] & BIT(2)) >> 2; /* 0XBD[2] */
2951 u8 ext_type_pa_2g_b
= (hwinfo
[0XBD] & BIT(6)) >> 6; /* 0XBD[6] */
2952 u8 ext_type_pa_5g_a
= (hwinfo
[0XBF] & BIT(2)) >> 2; /* 0XBF[2] */
2953 u8 ext_type_pa_5g_b
= (hwinfo
[0XBF] & BIT(6)) >> 6; /* 0XBF[6] */
2955 u8 ext_type_lna_2g_a
= (hwinfo
[0XBD] & (BIT(1) | BIT(0))) >> 0;
2957 u8 ext_type_lna_2g_b
= (hwinfo
[0XBD] & (BIT(5) | BIT(4))) >> 4;
2959 u8 ext_type_lna_5g_a
= (hwinfo
[0XBF] & (BIT(1) | BIT(0))) >> 0;
2961 u8 ext_type_lna_5g_b
= (hwinfo
[0XBF] & (BIT(5) | BIT(4))) >> 4;
2963 _rtl8812ae_read_pa_type(hw
, hwinfo
, autoload_fail
);
2965 /* [2.4G] Path A and B are both extPA */
2966 if ((rtlhal
->pa_type_2g
& (BIT(5) | BIT(4))) == (BIT(5) | BIT(4)))
2967 rtlhal
->type_gpa
= ext_type_pa_2g_b
<< 2 | ext_type_pa_2g_a
;
2969 /* [5G] Path A and B are both extPA */
2970 if ((rtlhal
->pa_type_5g
& (BIT(1) | BIT(0))) == (BIT(1) | BIT(0)))
2971 rtlhal
->type_apa
= ext_type_pa_5g_b
<< 2 | ext_type_pa_5g_a
;
2973 /* [2.4G] Path A and B are both extLNA */
2974 if ((rtlhal
->lna_type_2g
& (BIT(7) | BIT(3))) == (BIT(7) | BIT(3)))
2975 rtlhal
->type_glna
= ext_type_lna_2g_b
<< 2 | ext_type_lna_2g_a
;
2977 /* [5G] Path A and B are both extLNA */
2978 if ((rtlhal
->lna_type_5g
& (BIT(7) | BIT(3))) == (BIT(7) | BIT(3)))
2979 rtlhal
->type_alna
= ext_type_lna_5g_b
<< 2 | ext_type_lna_5g_a
;
2982 static void _rtl8821ae_read_pa_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
2985 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2986 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2988 if (!autoload_fail
) {
2989 rtlhal
->pa_type_2g
= hwinfo
[0XBC];
2990 rtlhal
->lna_type_2g
= hwinfo
[0XBD];
2991 if (rtlhal
->pa_type_2g
== 0xFF && rtlhal
->lna_type_2g
== 0xFF) {
2992 rtlhal
->pa_type_2g
= 0;
2993 rtlhal
->lna_type_2g
= 0;
2995 rtlhal
->external_pa_2g
= (rtlhal
->pa_type_2g
& BIT(5)) ? 1 : 0;
2996 rtlhal
->external_lna_2g
= (rtlhal
->lna_type_2g
& BIT(7)) ? 1 : 0;
2998 rtlhal
->pa_type_5g
= hwinfo
[0XBC];
2999 rtlhal
->lna_type_5g
= hwinfo
[0XBF];
3000 if (rtlhal
->pa_type_5g
== 0xFF && rtlhal
->lna_type_5g
== 0xFF) {
3001 rtlhal
->pa_type_5g
= 0;
3002 rtlhal
->lna_type_5g
= 0;
3004 rtlhal
->external_pa_5g
= (rtlhal
->pa_type_5g
& BIT(1)) ? 1 : 0;
3005 rtlhal
->external_lna_5g
= (rtlhal
->lna_type_5g
& BIT(7)) ? 1 : 0;
3007 rtlhal
->external_pa_2g
= 0;
3008 rtlhal
->external_lna_2g
= 0;
3009 rtlhal
->external_pa_5g
= 0;
3010 rtlhal
->external_lna_5g
= 0;
3014 static void _rtl8821ae_read_rfe_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
3017 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3018 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
3020 if (!autoload_fail
) {
3021 if (hwinfo
[EEPROM_RFE_OPTION
] & BIT(7)) {
3022 if (rtlhal
->external_lna_5g
) {
3023 if (rtlhal
->external_pa_5g
) {
3024 if (rtlhal
->external_lna_2g
&&
3025 rtlhal
->external_pa_2g
)
3026 rtlhal
->rfe_type
= 3;
3028 rtlhal
->rfe_type
= 0;
3030 rtlhal
->rfe_type
= 2;
3033 rtlhal
->rfe_type
= 4;
3036 rtlhal
->rfe_type
= hwinfo
[EEPROM_RFE_OPTION
] & 0x3F;
3038 if (rtlhal
->rfe_type
== 4 &&
3039 (rtlhal
->external_pa_5g
||
3040 rtlhal
->external_pa_2g
||
3041 rtlhal
->external_lna_5g
||
3042 rtlhal
->external_lna_2g
)) {
3043 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
3044 rtlhal
->rfe_type
= 2;
3048 rtlhal
->rfe_type
= 0x04;
3051 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3052 "RFE Type: 0x%2x\n", rtlhal
->rfe_type
);
3055 static void _rtl8812ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
3056 bool auto_load_fail
, u8
*hwinfo
)
3058 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3061 if (!auto_load_fail
) {
3062 value
= *(u8
*)&hwinfo
[EEPROM_RF_BOARD_OPTION
];
3063 if (((value
& 0xe0) >> 5) == 0x1)
3064 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
3066 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3067 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8812A
;
3069 value
= hwinfo
[EEPROM_RF_BT_SETTING
];
3070 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
3072 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3073 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8812A
;
3074 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
3076 /*move BT_InitHalVars() to init_sw_vars*/
3079 static void _rtl8821ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
3080 bool auto_load_fail
, u8
*hwinfo
)
3082 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3086 if (!auto_load_fail
) {
3087 tmpu_32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
3088 if (tmpu_32
& BIT(18))
3089 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
3091 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3092 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8821A
;
3094 value
= hwinfo
[EEPROM_RF_BT_SETTING
];
3095 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
3097 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3098 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8821A
;
3099 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
3101 /*move BT_InitHalVars() to init_sw_vars*/
3104 static void _rtl8821ae_read_adapter_info(struct ieee80211_hw
*hw
, bool b_pseudo_test
)
3106 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3107 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3108 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3109 int params
[] = {RTL_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
3110 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
3111 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
3112 COUNTRY_CODE_WORLD_WIDE_13
};
3115 if (b_pseudo_test
) {
3119 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
3123 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
3126 _rtl8821ae_read_txpower_info_from_hwpg(hw
, rtlefuse
->autoload_failflag
,
3129 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
3130 _rtl8812ae_read_amplifier_type(hw
, hwinfo
,
3131 rtlefuse
->autoload_failflag
);
3132 _rtl8812ae_read_bt_coexist_info_from_hwpg(hw
,
3133 rtlefuse
->autoload_failflag
, hwinfo
);
3135 _rtl8821ae_read_pa_type(hw
, hwinfo
, rtlefuse
->autoload_failflag
);
3136 _rtl8821ae_read_bt_coexist_info_from_hwpg(hw
,
3137 rtlefuse
->autoload_failflag
, hwinfo
);
3140 _rtl8821ae_read_rfe_type(hw
, hwinfo
, rtlefuse
->autoload_failflag
);
3142 rtlefuse
->board_type
= ODM_BOARD_DEFAULT
;
3143 if (rtlhal
->external_lna_2g
!= 0)
3144 rtlefuse
->board_type
|= ODM_BOARD_EXT_LNA
;
3145 if (rtlhal
->external_lna_5g
!= 0)
3146 rtlefuse
->board_type
|= ODM_BOARD_EXT_LNA_5G
;
3147 if (rtlhal
->external_pa_2g
!= 0)
3148 rtlefuse
->board_type
|= ODM_BOARD_EXT_PA
;
3149 if (rtlhal
->external_pa_5g
!= 0)
3150 rtlefuse
->board_type
|= ODM_BOARD_EXT_PA_5G
;
3152 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1)
3153 rtlefuse
->board_type
|= ODM_BOARD_BT
;
3155 rtlhal
->board_type
= rtlefuse
->board_type
;
3156 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3157 "board_type = 0x%x\n", rtlefuse
->board_type
);
3159 rtlefuse
->eeprom_channelplan
= *(u8
*)&hwinfo
[EEPROM_CHANNELPLAN
];
3160 if (rtlefuse
->eeprom_channelplan
== 0xff)
3161 rtlefuse
->eeprom_channelplan
= 0x7F;
3163 /* set channel plan from efuse */
3164 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
3167 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_8821AE
];
3168 if (rtlefuse
->crystalcap
== 0xFF)
3169 rtlefuse
->crystalcap
= 0x20;
3171 rtlefuse
->eeprom_thermalmeter
= *(u8
*)&hwinfo
[EEPROM_THERMAL_METER
];
3172 if ((rtlefuse
->eeprom_thermalmeter
== 0xff) ||
3173 rtlefuse
->autoload_failflag
) {
3174 rtlefuse
->apk_thermalmeterignore
= true;
3175 rtlefuse
->eeprom_thermalmeter
= 0xff;
3178 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
3179 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3180 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
3182 if (!rtlefuse
->autoload_failflag
) {
3183 rtlefuse
->antenna_div_cfg
=
3184 (hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x18) >> 3;
3185 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xff)
3186 rtlefuse
->antenna_div_cfg
= 0;
3188 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1 &&
3189 rtlpriv
->btcoexist
.btc_info
.ant_num
== ANT_X1
)
3190 rtlefuse
->antenna_div_cfg
= 0;
3192 rtlefuse
->antenna_div_type
= hwinfo
[EEPROM_RF_ANTENNA_OPT_88E
];
3193 if (rtlefuse
->antenna_div_type
== 0xff)
3194 rtlefuse
->antenna_div_type
= FIXED_HW_ANTDIV
;
3196 rtlefuse
->antenna_div_cfg
= 0;
3197 rtlefuse
->antenna_div_type
= 0;
3200 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3201 "SWAS: bHwAntDiv = %x, TRxAntDivType = %x\n",
3202 rtlefuse
->antenna_div_cfg
, rtlefuse
->antenna_div_type
);
3204 rtlpriv
->ledctl
.led_opendrain
= true;
3206 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
3207 switch (rtlefuse
->eeprom_oemid
) {
3208 case RT_CID_DEFAULT
:
3210 case EEPROM_CID_TOSHIBA
:
3211 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
3213 case EEPROM_CID_CCX
:
3214 rtlhal
->oem_id
= RT_CID_CCX
;
3216 case EEPROM_CID_QMI
:
3217 rtlhal
->oem_id
= RT_CID_819X_QMI
;
3219 case EEPROM_CID_WHQL
:
3229 /*static void _rtl8821ae_hal_customized_behavior(struct ieee80211_hw *hw)
3231 struct rtl_priv *rtlpriv = rtl_priv(hw);
3232 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
3233 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3235 rtlpriv->ledctl.led_opendrain = true;
3236 switch (rtlhal->oem_id) {
3237 case RT_CID_819X_HP:
3238 rtlpriv->ledctl.led_opendrain = true;
3240 case RT_CID_819X_LENOVO:
3241 case RT_CID_DEFAULT:
3242 case RT_CID_TOSHIBA:
3244 case RT_CID_819X_ACER:
3249 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3250 "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
3253 void rtl8821ae_read_eeprom_info(struct ieee80211_hw
*hw
)
3255 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3256 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3257 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3258 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3261 rtlhal
->version
= _rtl8821ae_read_chip_version(hw
);
3262 if (get_rf_type(rtlphy
) == RF_1T1R
)
3263 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
3265 rtlpriv
->dm
.rfpath_rxenable
[0] =
3266 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
3267 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
3270 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
3271 if (tmp_u1b
& BIT(4)) {
3272 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
3273 rtlefuse
->epromtype
= EEPROM_93C46
;
3275 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
3276 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
3279 if (tmp_u1b
& BIT(5)) {
3280 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
3281 rtlefuse
->autoload_failflag
= false;
3282 _rtl8821ae_read_adapter_info(hw
, false);
3284 pr_err("Autoload ERR!!\n");
3286 /*hal_ReadRFType_8812A()*/
3287 /* _rtl8821ae_hal_customized_behavior(hw); */
3290 static void rtl8821ae_update_hal_rate_table(struct ieee80211_hw
*hw
,
3291 struct ieee80211_sta
*sta
)
3293 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3294 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3295 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3296 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3299 u8 b_nmode
= mac
->ht_enable
;
3300 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
3303 u8 curtxbw_40mhz
= mac
->bw_40
;
3304 u8 b_curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
3306 u8 b_curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
3308 enum wireless_mode wirelessmode
= mac
->mode
;
3310 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
3311 ratr_value
= sta
->supp_rates
[1] << 4;
3313 ratr_value
= sta
->supp_rates
[0];
3314 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3316 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
3317 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
3318 switch (wirelessmode
) {
3319 case WIRELESS_MODE_B
:
3320 if (ratr_value
& 0x0000000c)
3321 ratr_value
&= 0x0000000d;
3323 ratr_value
&= 0x0000000f;
3325 case WIRELESS_MODE_G
:
3326 ratr_value
&= 0x00000FF5;
3328 case WIRELESS_MODE_N_24G
:
3329 case WIRELESS_MODE_N_5G
:
3331 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
3332 ratr_value
&= 0x0007F005;
3336 if (get_rf_type(rtlphy
) == RF_1T2R
||
3337 get_rf_type(rtlphy
) == RF_1T1R
)
3338 ratr_mask
= 0x000ff005;
3340 ratr_mask
= 0x0f0ff005;
3342 ratr_value
&= ratr_mask
;
3346 if (rtlphy
->rf_type
== RF_1T2R
)
3347 ratr_value
&= 0x000ff0ff;
3349 ratr_value
&= 0x0f0ff0ff;
3354 if ((rtlpriv
->btcoexist
.bt_coexistence
) &&
3355 (rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) &&
3356 (rtlpriv
->btcoexist
.bt_cur_state
) &&
3357 (rtlpriv
->btcoexist
.bt_ant_isolation
) &&
3358 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ||
3359 (rtlpriv
->btcoexist
.bt_service
== BT_BUSY
)))
3360 ratr_value
&= 0x0fffcfc0;
3362 ratr_value
&= 0x0FFFFFFF;
3364 if (b_nmode
&& ((curtxbw_40mhz
&&
3365 b_curshortgi_40mhz
) || (!curtxbw_40mhz
&&
3366 b_curshortgi_20mhz
))) {
3367 ratr_value
|= 0x10000000;
3368 tmp_ratr_value
= (ratr_value
>> 12);
3370 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
3371 if ((1 << shortgi_rate
) & tmp_ratr_value
)
3375 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
3376 (shortgi_rate
<< 4) | (shortgi_rate
);
3379 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
3381 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
3382 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
3385 static u32
_rtl8821ae_rate_to_bitmap_2ssvht(__le16 vht_rate
)
3388 u32 rate_bitmap
= 0;
3390 for (i
= j
= 0; i
< 4; i
+= 2, j
+= 10) {
3391 tmp_rate
= (le16_to_cpu(vht_rate
) >> i
) & 3;
3395 rate_bitmap
= rate_bitmap
| (0x03ff << j
);
3398 rate_bitmap
= rate_bitmap
| (0x01ff << j
);
3401 rate_bitmap
= rate_bitmap
| (0x00ff << j
);
3411 static u32
_rtl8821ae_set_ra_vht_ratr_bitmap(struct ieee80211_hw
*hw
,
3412 enum wireless_mode wirelessmode
,
3415 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3416 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3417 u32 ret_bitmap
= ratr_bitmap
;
3419 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
3420 || rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
)
3421 ret_bitmap
= ratr_bitmap
;
3422 else if (wirelessmode
== WIRELESS_MODE_AC_5G
3423 || wirelessmode
== WIRELESS_MODE_AC_24G
) {
3424 if (rtlphy
->rf_type
== RF_1T1R
)
3425 ret_bitmap
= ratr_bitmap
& (~BIT21
);
3427 ret_bitmap
= ratr_bitmap
& (~(BIT31
|BIT21
));
3433 static u8
_rtl8821ae_get_vht_eni(enum wireless_mode wirelessmode
,
3437 if (wirelessmode
< WIRELESS_MODE_N_24G
)
3439 else if (wirelessmode
== WIRELESS_MODE_AC_24G
) {
3440 if (ratr_bitmap
& 0xfff00000) /* Mix , 2SS */
3444 } else if (wirelessmode
== WIRELESS_MODE_AC_5G
) {
3451 static u8
_rtl8821ae_get_ra_ldpc(struct ieee80211_hw
*hw
,
3452 u8 mac_id
, struct rtl_sta_info
*sta_entry
,
3453 enum wireless_mode wirelessmode
)
3456 /*not support ldpc, do not open*/
3460 static u8
_rtl8821ae_get_ra_rftype(struct ieee80211_hw
*hw
,
3461 enum wireless_mode wirelessmode
,
3464 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3465 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3466 u8 rf_type
= RF_1T1R
;
3468 if (rtlphy
->rf_type
== RF_1T1R
)
3470 else if (wirelessmode
== WIRELESS_MODE_AC_5G
3471 || wirelessmode
== WIRELESS_MODE_AC_24G
3472 || wirelessmode
== WIRELESS_MODE_AC_ONLY
) {
3473 if (ratr_bitmap
& 0xffc00000)
3475 } else if (wirelessmode
== WIRELESS_MODE_N_5G
3476 || wirelessmode
== WIRELESS_MODE_N_24G
) {
3477 if (ratr_bitmap
& 0xfff00000)
3484 static bool _rtl8821ae_get_ra_shortgi(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
,
3487 bool b_short_gi
= false;
3488 u8 b_curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
3490 u8 b_curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
3492 u8 b_curshortgi_80mhz
= 0;
3493 b_curshortgi_80mhz
= (sta
->vht_cap
.cap
&
3494 IEEE80211_VHT_CAP_SHORT_GI_80
) ? 1 : 0;
3496 if (mac_id
== MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
)
3499 if (b_curshortgi_40mhz
|| b_curshortgi_80mhz
3500 || b_curshortgi_20mhz
)
3506 static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw
*hw
,
3507 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
3509 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3510 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3511 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3512 struct rtl_sta_info
*sta_entry
= NULL
;
3515 enum wireless_mode wirelessmode
= 0;
3516 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)
3518 bool b_shortgi
= false;
3521 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
3524 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
3525 wirelessmode
= sta_entry
->wireless_mode
;
3527 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_LOUD
,
3528 "wireless mode = 0x%x\n", wirelessmode
);
3529 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
3530 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
3531 curtxbw_40mhz
= mac
->bw_40
;
3532 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
3533 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3534 macid
= sta
->aid
+ 1;
3535 if (wirelessmode
== WIRELESS_MODE_N_5G
||
3536 wirelessmode
== WIRELESS_MODE_AC_5G
||
3537 wirelessmode
== WIRELESS_MODE_A
)
3538 ratr_bitmap
= sta
->supp_rates
[NL80211_BAND_5GHZ
] << 4;
3540 ratr_bitmap
= sta
->supp_rates
[NL80211_BAND_2GHZ
];
3542 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3543 ratr_bitmap
= 0xfff;
3545 if (wirelessmode
== WIRELESS_MODE_N_24G
3546 || wirelessmode
== WIRELESS_MODE_N_5G
)
3547 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
3548 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
3549 else if (wirelessmode
== WIRELESS_MODE_AC_24G
3550 || wirelessmode
== WIRELESS_MODE_AC_5G
3551 || wirelessmode
== WIRELESS_MODE_AC_ONLY
)
3552 ratr_bitmap
|= _rtl8821ae_rate_to_bitmap_2ssvht(
3553 sta
->vht_cap
.vht_mcs
.rx_mcs_map
) << 12;
3555 b_shortgi
= _rtl8821ae_get_ra_shortgi(hw
, sta
, macid
);
3556 rf_type
= _rtl8821ae_get_ra_rftype(hw
, wirelessmode
, ratr_bitmap
);
3559 switch (wirelessmode
) {
3560 case WIRELESS_MODE_B
:
3561 ratr_index
= RATR_INX_WIRELESS_B
;
3562 if (ratr_bitmap
& 0x0000000c)
3563 ratr_bitmap
&= 0x0000000d;
3565 ratr_bitmap
&= 0x0000000f;
3567 case WIRELESS_MODE_G
:
3568 ratr_index
= RATR_INX_WIRELESS_GB
;
3570 if (rssi_level
== 1)
3571 ratr_bitmap
&= 0x00000f00;
3572 else if (rssi_level
== 2)
3573 ratr_bitmap
&= 0x00000ff0;
3575 ratr_bitmap
&= 0x00000ff5;
3577 case WIRELESS_MODE_A
:
3578 ratr_index
= RATR_INX_WIRELESS_G
;
3579 ratr_bitmap
&= 0x00000ff0;
3581 case WIRELESS_MODE_N_24G
:
3582 case WIRELESS_MODE_N_5G
:
3583 if (wirelessmode
== WIRELESS_MODE_N_24G
)
3584 ratr_index
= RATR_INX_WIRELESS_NGB
;
3586 ratr_index
= RATR_INX_WIRELESS_NG
;
3588 if (mimo_ps
== IEEE80211_SMPS_STATIC
3589 || mimo_ps
== IEEE80211_SMPS_DYNAMIC
) {
3590 if (rssi_level
== 1)
3591 ratr_bitmap
&= 0x000f0000;
3592 else if (rssi_level
== 2)
3593 ratr_bitmap
&= 0x000ff000;
3595 ratr_bitmap
&= 0x000ff005;
3597 if (rf_type
== RF_1T1R
) {
3598 if (curtxbw_40mhz
) {
3599 if (rssi_level
== 1)
3600 ratr_bitmap
&= 0x000f0000;
3601 else if (rssi_level
== 2)
3602 ratr_bitmap
&= 0x000ff000;
3604 ratr_bitmap
&= 0x000ff015;
3606 if (rssi_level
== 1)
3607 ratr_bitmap
&= 0x000f0000;
3608 else if (rssi_level
== 2)
3609 ratr_bitmap
&= 0x000ff000;
3611 ratr_bitmap
&= 0x000ff005;
3614 if (curtxbw_40mhz
) {
3615 if (rssi_level
== 1)
3616 ratr_bitmap
&= 0x0fff0000;
3617 else if (rssi_level
== 2)
3618 ratr_bitmap
&= 0x0ffff000;
3620 ratr_bitmap
&= 0x0ffff015;
3622 if (rssi_level
== 1)
3623 ratr_bitmap
&= 0x0fff0000;
3624 else if (rssi_level
== 2)
3625 ratr_bitmap
&= 0x0ffff000;
3627 ratr_bitmap
&= 0x0ffff005;
3633 case WIRELESS_MODE_AC_24G
:
3634 ratr_index
= RATR_INX_WIRELESS_AC_24N
;
3635 if (rssi_level
== 1)
3636 ratr_bitmap
&= 0xfc3f0000;
3637 else if (rssi_level
== 2)
3638 ratr_bitmap
&= 0xfffff000;
3640 ratr_bitmap
&= 0xffffffff;
3643 case WIRELESS_MODE_AC_5G
:
3644 ratr_index
= RATR_INX_WIRELESS_AC_5N
;
3646 if (rf_type
== RF_1T1R
) {
3647 if (rssi_level
== 1) /*add by Gary for ac-series*/
3648 ratr_bitmap
&= 0x003f8000;
3649 else if (rssi_level
== 2)
3650 ratr_bitmap
&= 0x003ff000;
3652 ratr_bitmap
&= 0x003ff010;
3654 if (rssi_level
== 1)
3655 ratr_bitmap
&= 0xfe3f8000;
3656 else if (rssi_level
== 2)
3657 ratr_bitmap
&= 0xfffff000;
3659 ratr_bitmap
&= 0xfffff010;
3664 ratr_index
= RATR_INX_WIRELESS_NGB
;
3666 if (rf_type
== RF_1T2R
)
3667 ratr_bitmap
&= 0x000ff0ff;
3669 ratr_bitmap
&= 0x0f8ff0ff;
3673 ratr_index
= rtl_mrate_idx_to_arfr_id(hw
, ratr_index
, wirelessmode
);
3674 sta_entry
->ratr_index
= ratr_index
;
3675 ratr_bitmap
= _rtl8821ae_set_ra_vht_ratr_bitmap(hw
, wirelessmode
,
3678 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_LOUD
,
3679 "ratr_bitmap :%x\n", ratr_bitmap
);
3681 /* *(u32 *)& rate_mask = EF4BYTE((ratr_bitmap & 0x0fffffff) |
3682 (ratr_index << 28)); */
3684 rate_mask
[0] = macid
;
3685 rate_mask
[1] = ratr_index
| (b_shortgi
? 0x80 : 0x00);
3686 rate_mask
[2] = rtlphy
->current_chan_bw
| ((!update_bw
) << 3)
3687 | _rtl8821ae_get_vht_eni(wirelessmode
, ratr_bitmap
)
3688 | _rtl8821ae_get_ra_ldpc(hw
, macid
, sta_entry
, wirelessmode
);
3690 rate_mask
[3] = (u8
)(ratr_bitmap
& 0x000000ff);
3691 rate_mask
[4] = (u8
)((ratr_bitmap
& 0x0000ff00) >> 8);
3692 rate_mask
[5] = (u8
)((ratr_bitmap
& 0x00ff0000) >> 16);
3693 rate_mask
[6] = (u8
)((ratr_bitmap
& 0xff000000) >> 24);
3695 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
3696 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
3697 ratr_index
, ratr_bitmap
,
3698 rate_mask
[0], rate_mask
[1],
3699 rate_mask
[2], rate_mask
[3],
3700 rate_mask
[4], rate_mask
[5],
3702 rtl8821ae_fill_h2c_cmd(hw
, H2C_8821AE_RA_MASK
, 7, rate_mask
);
3703 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
3706 void rtl8821ae_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
3707 struct ieee80211_sta
*sta
, u8 rssi_level
, bool update_bw
)
3709 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3710 if (rtlpriv
->dm
.useramask
)
3711 rtl8821ae_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
3713 /*RT_TRACE(rtlpriv, COMP_RATR,DBG_LOUD,
3714 "rtl8821ae_update_hal_rate_tbl() Error! 8821ae FW RA Only\n");*/
3715 rtl8821ae_update_hal_rate_table(hw
, sta
);
3718 void rtl8821ae_update_channel_access_setting(struct ieee80211_hw
*hw
)
3720 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3721 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3722 u16 wireless_mode
= mac
->mode
;
3723 u8 sifs_timer
, r2t_sifs
;
3725 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
3726 (u8
*)&mac
->slot_time
);
3727 if (wireless_mode
== WIRELESS_MODE_G
)
3731 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
3735 if (wireless_mode
== WIRELESS_MODE_AC_5G
&&
3736 (mac
->vht_ldpc_cap
& LDPC_VHT_ENABLE_RX
) &&
3737 (mac
->vht_stbc_cap
& STBC_VHT_ENABLE_RX
)) {
3738 if (mac
->vendor
== PEER_ATH
)
3742 } else if (wireless_mode
== WIRELESS_MODE_AC_5G
) {
3746 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_R2T_SIFS
, (u8
*)&r2t_sifs
);
3749 bool rtl8821ae_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
3751 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3752 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
3753 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3754 enum rf_pwrstate e_rfpowerstate_toset
;
3756 bool b_actuallyset
= false;
3758 if (rtlpriv
->rtlhal
.being_init_adapter
)
3761 if (ppsc
->swrf_processing
)
3764 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3765 if (ppsc
->rfchange_inprogress
) {
3766 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3769 ppsc
->rfchange_inprogress
= true;
3770 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3773 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL_2
,
3774 rtl_read_byte(rtlpriv
,
3775 REG_GPIO_IO_SEL_2
) & ~(BIT(1)));
3777 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_PIN_CTRL_2
);
3779 if (rtlphy
->polarity_ctl
)
3780 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFOFF
: ERFON
;
3782 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFON
: ERFOFF
;
3784 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
3785 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3786 "GPIOChangeRF - HW Radio ON, RF ON\n");
3788 e_rfpowerstate_toset
= ERFON
;
3789 ppsc
->hwradiooff
= false;
3790 b_actuallyset
= true;
3791 } else if ((!ppsc
->hwradiooff
)
3792 && (e_rfpowerstate_toset
== ERFOFF
)) {
3793 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3794 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
3796 e_rfpowerstate_toset
= ERFOFF
;
3797 ppsc
->hwradiooff
= true;
3798 b_actuallyset
= true;
3801 if (b_actuallyset
) {
3802 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3803 ppsc
->rfchange_inprogress
= false;
3804 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3806 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
3807 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
3809 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3810 ppsc
->rfchange_inprogress
= false;
3811 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3815 return !ppsc
->hwradiooff
;
3818 void rtl8821ae_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
3819 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
3820 bool is_wepkey
, bool clear_all
)
3822 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3823 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3824 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3825 u8
*macaddr
= p_macaddr
;
3827 bool is_pairwise
= false;
3829 static u8 cam_const_addr
[4][6] = {
3830 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3831 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3832 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3833 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
3835 static u8 cam_const_broad
[] = {
3836 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
3842 u8 clear_number
= 5;
3844 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
3846 for (idx
= 0; idx
< clear_number
; idx
++) {
3847 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
3848 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
3851 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
3853 rtlpriv
->sec
.key_len
[idx
] = 0;
3858 case WEP40_ENCRYPTION
:
3859 enc_algo
= CAM_WEP40
;
3861 case WEP104_ENCRYPTION
:
3862 enc_algo
= CAM_WEP104
;
3864 case TKIP_ENCRYPTION
:
3865 enc_algo
= CAM_TKIP
;
3867 case AESCCMP_ENCRYPTION
:
3871 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
3872 "switch case %#x not processed\n", enc_algo
);
3873 enc_algo
= CAM_TKIP
;
3877 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
3878 macaddr
= cam_const_addr
[key_index
];
3879 entry_id
= key_index
;
3882 macaddr
= cam_const_broad
;
3883 entry_id
= key_index
;
3885 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
3886 entry_id
= rtl_cam_get_free_entry(hw
, p_macaddr
);
3887 if (entry_id
>= TOTAL_CAM_ENTRY
) {
3888 pr_err("an not find free hwsecurity cam entry\n");
3892 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
3895 key_index
= PAIRWISE_KEYIDX
;
3900 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
3901 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
3902 "delete one entry, entry_id is %d\n",
3904 if (mac
->opmode
== NL80211_IFTYPE_AP
)
3905 rtl_cam_del_entry(hw
, p_macaddr
);
3906 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
3908 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
3911 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
3912 "set Pairwise key\n");
3914 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
3916 CAM_CONFIG_NO_USEDK
,
3917 rtlpriv
->sec
.key_buf
[key_index
]);
3919 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
3922 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
3923 rtl_cam_add_one_entry(hw
,
3926 CAM_PAIRWISE_KEY_POSITION
,
3928 CAM_CONFIG_NO_USEDK
,
3929 rtlpriv
->sec
.key_buf
3933 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
3935 CAM_CONFIG_NO_USEDK
,
3936 rtlpriv
->sec
.key_buf
[entry_id
]);
3942 void rtl8821ae_bt_reg_init(struct ieee80211_hw
*hw
)
3944 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3946 /* 0:Low, 1:High, 2:From Efuse. */
3947 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
3948 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
3949 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
3950 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
3951 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
3954 void rtl8821ae_bt_hw_init(struct ieee80211_hw
*hw
)
3956 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3958 if (rtlpriv
->cfg
->ops
->get_btc_status())
3959 rtlpriv
->btcoexist
.btc_ops
->btc_init_hw_config(rtlpriv
);
3962 void rtl8821ae_suspend(struct ieee80211_hw
*hw
)
3966 void rtl8821ae_resume(struct ieee80211_hw
*hw
)
3970 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
3971 void rtl8821ae_allow_all_destaddr(struct ieee80211_hw
*hw
,
3972 bool allow_all_da
, bool write_into_reg
)
3974 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3975 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
3977 if (allow_all_da
) /* Set BIT0 */
3978 rtlpci
->receive_config
|= RCR_AAP
;
3979 else /* Clear BIT0 */
3980 rtlpci
->receive_config
&= ~RCR_AAP
;
3983 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
3985 RT_TRACE(rtlpriv
, COMP_TURBO
| COMP_INIT
, DBG_LOUD
,
3986 "receive_config=0x%08X, write_into_reg=%d\n",
3987 rtlpci
->receive_config
, write_into_reg
);
3990 /* WKFMCAMAddAllEntry8812 */
3991 void rtl8821ae_add_wowlan_pattern(struct ieee80211_hw
*hw
,
3992 struct rtl_wow_pattern
*rtl_pattern
,
3995 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4003 /* Count the WFCAM entry start offset. */
4005 /* RX page size = 128 byte */
4006 offset
= MAX_RX_DMA_BUFFER_SIZE_8812
/ 128;
4007 /* We should start from the boundry */
4008 cam_start
= offset
* 128;
4010 /* Enable Rx packet buffer access. */
4011 rtl_write_byte(rtlpriv
, REG_PKT_BUFF_ACCESS_CTRL
, RXPKT_BUF_SELECT
);
4012 for (addr
= 0; addr
< WKFMCAM_ADDR_NUM
; addr
++) {
4013 /* Set Rx packet buffer offset.
4014 * RXBufer pointer increases 1,
4015 * we can access 8 bytes in Rx packet buffer.
4016 * CAM start offset (unit: 1 byte) = index*WKFMCAM_SIZE
4017 * RXBufer addr = (CAM start offset +
4018 * per entry offset of a WKFM CAM)/8
4019 * * index: The index of the wake up frame mask
4020 * * WKFMCAM_SIZE: the total size of one WKFM CAM
4021 * * per entry offset of a WKFM CAM: Addr*4 bytes
4023 rxbuf_addr
= (cam_start
+ index
* WKFMCAM_SIZE
+ addr
* 4) >> 3;
4024 /* Set R/W start offset */
4025 rtl_write_word(rtlpriv
, REG_PKTBUF_DBG_CTRL
, rxbuf_addr
);
4028 cam
= BIT(31) | rtl_pattern
->crc
;
4030 if (rtl_pattern
->type
== UNICAST_PATTERN
)
4032 else if (rtl_pattern
->type
== MULTICAST_PATTERN
)
4034 else if (rtl_pattern
->type
== BROADCAST_PATTERN
)
4037 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_L
, cam
);
4038 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4039 "WRITE entry[%d] 0x%x: %x\n", addr
,
4040 REG_PKTBUF_DBG_DATA_L
, cam
);
4042 /* Write to Rx packet buffer. */
4043 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0x0f01);
4044 } else if (addr
== 2 || addr
== 4) {/* WKFM[127:0] */
4045 cam
= rtl_pattern
->mask
[addr
- 2];
4047 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_L
, cam
);
4048 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4049 "WRITE entry[%d] 0x%x: %x\n", addr
,
4050 REG_PKTBUF_DBG_DATA_L
, cam
);
4052 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0x0f01);
4053 } else if (addr
== 3 || addr
== 5) {/* WKFM[127:0] */
4054 cam
= rtl_pattern
->mask
[addr
- 2];
4056 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_H
, cam
);
4057 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4058 "WRITE entry[%d] 0x%x: %x\n", addr
,
4059 REG_PKTBUF_DBG_DATA_H
, cam
);
4061 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0xf001);
4066 tmp
= rtl_read_byte(rtlpriv
, REG_RXPKTBUF_CTRL
);
4069 } while (tmp
&& count
< 100);
4071 WARN_ONCE((count
>= 100),
4072 "rtl8821ae: Write wake up frame mask FAIL %d value!\n",
4075 /* Disable Rx packet buffer access. */
4076 rtl_write_byte(rtlpriv
, REG_PKT_BUFF_ACCESS_CTRL
,
4077 DISABLE_TRXPKT_BUF_ACCESS
);