1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
40 #include "../pwrseqcmd.h"
42 #include "../btcoexist/rtl_btc.h"
46 static void _rtl8821ae_return_beacon_queue_skb(struct ieee80211_hw
*hw
)
48 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
49 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
50 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
53 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
54 while (skb_queue_len(&ring
->queue
)) {
55 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
56 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
58 pci_unmap_single(rtlpci
->pdev
,
59 rtlpriv
->cfg
->ops
->get_desc(
60 (u8
*)entry
, true, HW_DESC_TXBUFF_ADDR
),
61 skb
->len
, PCI_DMA_TODEVICE
);
63 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
65 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
68 static void _rtl8821ae_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
69 u8 set_bits
, u8 clear_bits
)
71 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
72 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
74 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
75 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
77 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
80 void _rtl8821ae_stop_tx_beacon(struct ieee80211_hw
*hw
)
82 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
85 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
86 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
87 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
88 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
89 tmp1byte
&= ~(BIT(0));
90 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
93 void _rtl8821ae_resume_tx_beacon(struct ieee80211_hw
*hw
)
95 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
98 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
99 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
100 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
101 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
103 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
106 static void _rtl8821ae_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
108 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(1));
111 static void _rtl8821ae_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
113 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(1), 0);
116 static void _rtl8821ae_set_fw_clock_on(struct ieee80211_hw
*hw
,
117 u8 rpwm_val
, bool b_need_turn_off_ckk
)
119 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
120 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
121 bool b_support_remote_wake_up
;
122 u32 count
= 0, isr_regaddr
, content
;
123 bool b_schedule_timer
= b_need_turn_off_ckk
;
125 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
126 (u8
*)(&b_support_remote_wake_up
));
128 if (!rtlhal
->fw_ready
)
130 if (!rtlpriv
->psc
.fw_current_inpsmode
)
134 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
135 if (rtlhal
->fw_clk_change_in_progress
) {
136 while (rtlhal
->fw_clk_change_in_progress
) {
137 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
142 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
144 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
146 rtlhal
->fw_clk_change_in_progress
= false;
147 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
152 if (IS_IN_LOW_POWER_STATE_8821AE(rtlhal
->fw_ps_state
)) {
153 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
,
155 if (FW_PS_IS_ACK(rpwm_val
)) {
156 isr_regaddr
= REG_HISR
;
157 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
158 while (!(content
& IMR_CPWM
) && (count
< 500)) {
161 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
164 if (content
& IMR_CPWM
) {
165 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
166 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON_8821AE
;
167 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
168 "Receive CPWM INT!!! Set rtlhal->FwPSState = %X\n",
169 rtlhal
->fw_ps_state
);
173 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
174 rtlhal
->fw_clk_change_in_progress
= false;
175 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
176 if (b_schedule_timer
)
177 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
178 jiffies
+ MSECS(10));
180 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
181 rtlhal
->fw_clk_change_in_progress
= false;
182 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
186 static void _rtl8821ae_set_fw_clock_off(struct ieee80211_hw
*hw
,
189 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
190 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
191 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
192 struct rtl8192_tx_ring
*ring
;
193 enum rf_pwrstate rtstate
;
194 bool b_schedule_timer
= false;
197 if (!rtlhal
->fw_ready
)
199 if (!rtlpriv
->psc
.fw_current_inpsmode
)
201 if (!rtlhal
->allow_sw_to_change_hwclc
)
203 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
204 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
207 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
208 ring
= &rtlpci
->tx_ring
[queue
];
209 if (skb_queue_len(&ring
->queue
)) {
210 b_schedule_timer
= true;
215 if (b_schedule_timer
) {
216 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
217 jiffies
+ MSECS(10));
221 if (FW_PS_STATE(rtlhal
->fw_ps_state
) !=
222 FW_PS_STATE_RF_OFF_LOW_PWR_8821AE
) {
223 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
224 if (!rtlhal
->fw_clk_change_in_progress
) {
225 rtlhal
->fw_clk_change_in_progress
= true;
226 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
227 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
228 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
229 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
231 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
232 rtlhal
->fw_clk_change_in_progress
= false;
233 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
235 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
236 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
237 jiffies
+ MSECS(10));
242 static void _rtl8821ae_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
246 rpwm_val
|= (FW_PS_STATE_RF_OFF_8821AE
| FW_PS_ACK
);
247 _rtl8821ae_set_fw_clock_on(hw
, rpwm_val
, true);
250 static void _rtl8821ae_fwlps_leave(struct ieee80211_hw
*hw
)
252 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
253 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
254 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
255 bool fw_current_inps
= false;
256 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
258 if (ppsc
->low_power_enable
) {
259 rpwm_val
= (FW_PS_STATE_ALL_ON_8821AE
|FW_PS_ACK
);/* RF on */
260 _rtl8821ae_set_fw_clock_on(hw
, rpwm_val
, false);
261 rtlhal
->allow_sw_to_change_hwclc
= false;
262 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
263 (u8
*)(&fw_pwrmode
));
264 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
265 (u8
*)(&fw_current_inps
));
267 rpwm_val
= FW_PS_STATE_ALL_ON_8821AE
; /* RF on */
268 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
270 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
271 (u8
*)(&fw_pwrmode
));
272 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
273 (u8
*)(&fw_current_inps
));
277 static void _rtl8821ae_fwlps_enter(struct ieee80211_hw
*hw
)
279 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
280 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
281 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
282 bool fw_current_inps
= true;
285 if (ppsc
->low_power_enable
) {
286 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR_8821AE
; /* RF off */
287 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
288 HW_VAR_FW_PSMODE_STATUS
,
289 (u8
*)(&fw_current_inps
));
290 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
291 HW_VAR_H2C_FW_PWRMODE
,
292 (u8
*)(&ppsc
->fwctrl_psmode
));
293 rtlhal
->allow_sw_to_change_hwclc
= true;
294 _rtl8821ae_set_fw_clock_off(hw
, rpwm_val
);
296 rpwm_val
= FW_PS_STATE_RF_OFF_8821AE
; /* RF off */
297 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
298 HW_VAR_FW_PSMODE_STATUS
,
299 (u8
*)(&fw_current_inps
));
300 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
301 HW_VAR_H2C_FW_PWRMODE
,
302 (u8
*)(&ppsc
->fwctrl_psmode
));
303 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
309 static void _rtl8821ae_download_rsvd_page(struct ieee80211_hw
*hw
,
310 bool dl_whole_packets
)
312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
313 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
314 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
315 u8 count
= 0, dlbcn_count
= 0;
316 bool send_beacon
= false;
318 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
319 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
| BIT(0)));
321 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
322 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
324 tmp_reg422
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
325 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
326 tmp_reg422
& (~BIT(6)));
327 if (tmp_reg422
& BIT(6))
331 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
332 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
333 (bcnvalid_reg
| BIT(0)));
334 _rtl8821ae_return_beacon_queue_skb(hw
);
336 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
337 rtl8812ae_set_fw_rsvdpagepkt(hw
, false,
340 rtl8821ae_set_fw_rsvdpagepkt(hw
, false,
343 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
345 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
348 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
351 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
353 if (!(bcnvalid_reg
& BIT(0)))
354 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
355 "Download RSVD page failed!\n");
356 if (bcnvalid_reg
& BIT(0) && rtlhal
->enter_pnp_sleep
) {
357 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, bcnvalid_reg
| BIT(0));
358 _rtl8821ae_return_beacon_queue_skb(hw
);
362 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
363 bcnvalid_reg
| BIT(0));
365 _rtl8821ae_return_beacon_queue_skb(hw
);
367 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
368 rtl8812ae_set_fw_rsvdpagepkt(hw
, true,
371 rtl8821ae_set_fw_rsvdpagepkt(hw
, true,
374 /* check rsvd page download OK. */
375 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
378 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
382 rtl_read_byte(rtlpriv
,
386 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
388 if (!(bcnvalid_reg
& BIT(0)))
389 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
390 "2 Download RSVD page failed!\n");
394 if (bcnvalid_reg
& BIT(0))
395 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, BIT(0));
397 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
398 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
401 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
);
403 if (!rtlhal
->enter_pnp_sleep
) {
404 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
405 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
& ~(BIT(0))));
409 void rtl8821ae_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
411 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
412 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
413 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
414 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
417 case HW_VAR_ETHER_ADDR
:
418 *((u32
*)(val
)) = rtl_read_dword(rtlpriv
, REG_MACID
);
419 *((u16
*)(val
+4)) = rtl_read_word(rtlpriv
, REG_MACID
+ 4);
422 *((u32
*)(val
)) = rtl_read_dword(rtlpriv
, REG_BSSID
);
423 *((u16
*)(val
+4)) = rtl_read_word(rtlpriv
, REG_BSSID
+4);
425 case HW_VAR_MEDIA_STATUS
:
426 val
[0] = rtl_read_byte(rtlpriv
, MSR
) & 0x3;
428 case HW_VAR_SLOT_TIME
:
429 *((u8
*)(val
)) = mac
->slot_time
;
431 case HW_VAR_BEACON_INTERVAL
:
432 *((u16
*)(val
)) = rtl_read_word(rtlpriv
, REG_BCN_INTERVAL
);
434 case HW_VAR_ATIM_WINDOW
:
435 *((u16
*)(val
)) = rtl_read_word(rtlpriv
, REG_ATIMWND
);
438 *((u32
*)(val
)) = rtlpci
->receive_config
;
440 case HW_VAR_RF_STATE
:
441 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
443 case HW_VAR_FWLPS_RF_ON
:{
444 enum rf_pwrstate rfstate
;
447 rtlpriv
->cfg
->ops
->get_hw_reg(hw
,
450 if (rfstate
== ERFOFF
) {
451 *((bool *)(val
)) = true;
453 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
454 val_rcr
&= 0x00070000;
456 *((bool *)(val
)) = false;
458 *((bool *)(val
)) = true;
461 case HW_VAR_FW_PSMODE_STATUS
:
462 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
464 case HW_VAR_CORRECT_TSF
:{
466 u32
*ptsf_low
= (u32
*)&tsf
;
467 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
469 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
470 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
472 *((u64
*)(val
)) = tsf
;
476 if (ppsc
->wo_wlan_mode
)
477 *((bool *)(val
)) = true;
479 *((bool *)(val
)) = false;
482 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
483 "switch case not process %x\n", variable
);
488 void rtl8821ae_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
490 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
491 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
492 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
493 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
494 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
495 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
499 case HW_VAR_ETHER_ADDR
:{
500 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
501 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
506 case HW_VAR_BASIC_RATE
:{
507 u16 b_rate_cfg
= ((u16
*)val
)[0];
508 b_rate_cfg
= b_rate_cfg
& 0x15f;
509 rtl_write_word(rtlpriv
, REG_RRSR
, b_rate_cfg
);
513 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
514 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
520 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
521 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[0]);
523 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
524 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
526 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
+ 1, val
[0]);
527 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
, val
[0]);
529 case HW_VAR_R2T_SIFS
:
530 rtl_write_byte(rtlpriv
, REG_RESP_SIFS_OFDM
+ 1, val
[0]);
532 case HW_VAR_SLOT_TIME
:{
535 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
536 "HW_VAR_SLOT_TIME %x\n", val
[0]);
538 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
540 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
541 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
546 case HW_VAR_ACK_PREAMBLE
:{
548 u8 short_preamble
= (bool)(*(u8
*)val
);
550 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+2);
551 if (short_preamble
) {
553 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2,
556 reg_tmp
&= (~BIT(1));
557 rtl_write_byte(rtlpriv
,
562 case HW_VAR_WPA_CONFIG
:
563 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*)val
));
565 case HW_VAR_AMPDU_MIN_SPACE
:{
566 u8 min_spacing_to_set
;
569 min_spacing_to_set
= *((u8
*)val
);
570 if (min_spacing_to_set
<= 7) {
573 if (min_spacing_to_set
< sec_min_space
)
574 min_spacing_to_set
= sec_min_space
;
576 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
580 *val
= min_spacing_to_set
;
582 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
583 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
586 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
590 case HW_VAR_SHORTGI_DENSITY
:{
593 density_to_set
= *((u8
*)val
);
594 mac
->min_space_cfg
|= (density_to_set
<< 3);
596 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
597 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
600 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
604 case HW_VAR_AMPDU_FACTOR
:{
605 u32 ampdu_len
= (*((u8
*)val
));
607 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
608 if (ampdu_len
< VHT_AGG_SIZE_128K
)
610 (0x2000 << (*((u8
*)val
))) - 1;
613 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
614 if (ampdu_len
< HT_AGG_SIZE_64K
)
616 (0x2000 << (*((u8
*)val
))) - 1;
620 ampdu_len
|= BIT(31);
622 rtl_write_dword(rtlpriv
,
623 REG_AMPDU_MAX_LENGTH_8812
, ampdu_len
);
625 case HW_VAR_AC_PARAM
:{
626 u8 e_aci
= *((u8
*)val
);
628 rtl8821ae_dm_init_edca_turbo(hw
);
629 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
630 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
634 case HW_VAR_ACM_CTRL
:{
635 u8 e_aci
= *((u8
*)val
);
636 union aci_aifsn
*p_aci_aifsn
=
637 (union aci_aifsn
*)(&mac
->ac
[0].aifs
);
638 u8 acm
= p_aci_aifsn
->f
.acm
;
639 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
642 acm_ctrl
| ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
647 acm_ctrl
|= ACMHW_BEQEN
;
650 acm_ctrl
|= ACMHW_VIQEN
;
653 acm_ctrl
|= ACMHW_VOQEN
;
656 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
657 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
664 acm_ctrl
&= (~ACMHW_BEQEN
);
667 acm_ctrl
&= (~ACMHW_VIQEN
);
670 acm_ctrl
&= (~ACMHW_VOQEN
);
673 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
674 "switch case not process\n");
679 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
680 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
682 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
685 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
686 rtlpci
->receive_config
= ((u32
*)(val
))[0];
688 case HW_VAR_RETRY_LIMIT
:{
689 u8 retry_limit
= ((u8
*)(val
))[0];
691 rtl_write_word(rtlpriv
, REG_RL
,
692 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
693 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
695 case HW_VAR_DUAL_TSF_RST
:
696 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
698 case HW_VAR_EFUSE_BYTES
:
699 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
701 case HW_VAR_EFUSE_USAGE
:
702 rtlefuse
->efuse_usedpercentage
= *((u8
*)val
);
705 rtl8821ae_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
707 case HW_VAR_SET_RPWM
:{
710 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
713 if (rpwm_val
& BIT(7)) {
714 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
717 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
718 ((*(u8
*)val
) | BIT(7)));
722 case HW_VAR_H2C_FW_PWRMODE
:
723 rtl8821ae_set_fw_pwrmode_cmd(hw
, (*(u8
*)val
));
725 case HW_VAR_FW_PSMODE_STATUS
:
726 ppsc
->fw_current_inpsmode
= *((bool *)val
);
728 case HW_VAR_INIT_RTS_RATE
:
730 case HW_VAR_RESUME_CLK_ON
:
731 _rtl8821ae_set_fw_ps_rf_on(hw
);
733 case HW_VAR_FW_LPS_ACTION
:{
734 bool b_enter_fwlps
= *((bool *)val
);
737 _rtl8821ae_fwlps_enter(hw
);
739 _rtl8821ae_fwlps_leave(hw
);
741 case HW_VAR_H2C_FW_JOINBSSRPT
:{
742 u8 mstatus
= (*(u8
*)val
);
744 if (mstatus
== RT_MEDIA_CONNECT
) {
745 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
,
747 _rtl8821ae_download_rsvd_page(hw
, false);
749 rtl8821ae_set_fw_media_status_rpt_cmd(hw
, mstatus
);
752 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
753 rtl8821ae_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
757 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
759 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
762 case HW_VAR_CORRECT_TSF
:{
763 u8 btype_ibss
= ((u8
*)(val
))[0];
766 _rtl8821ae_stop_tx_beacon(hw
);
768 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(3));
770 rtl_write_dword(rtlpriv
, REG_TSFTR
,
771 (u32
)(mac
->tsf
& 0xffffffff));
772 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
773 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
775 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
778 _rtl8821ae_resume_tx_beacon(hw
);
780 case HW_VAR_NAV_UPPER
: {
781 u32 us_nav_upper
= ((u32
)*val
);
783 if (us_nav_upper
> HAL_92C_NAV_UPPER_UNIT
* 0xFF) {
784 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
785 "The setting value (0x%08X us) of NAV_UPPER is larger than (%d * 0xFF)!!!\n",
786 us_nav_upper
, HAL_92C_NAV_UPPER_UNIT
);
789 rtl_write_byte(rtlpriv
, REG_NAV_UPPER
,
790 ((u8
)((us_nav_upper
+
791 HAL_92C_NAV_UPPER_UNIT
- 1) /
792 HAL_92C_NAV_UPPER_UNIT
)));
794 case HW_VAR_KEEP_ALIVE
: {
797 array
[1] = *((u8
*)val
);
798 rtl8821ae_fill_h2c_cmd(hw
, H2C_8821AE_KEEP_ALIVE_CTRL
, 2,
802 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
803 "switch case not process %x\n", variable
);
808 static bool _rtl8821ae_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
810 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
813 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
814 _LLT_OP(_LLT_WRITE_ACCESS
);
816 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
819 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
820 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
823 if (count
> POLLING_LLT_THRESHOLD
) {
824 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
825 "Failed to polling write LLT done at address %d!\n",
835 static bool _rtl8821ae_llt_table_init(struct ieee80211_hw
*hw
)
837 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
845 txpktbuf_bndy
= 0xF8;
847 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8812AE
) {
848 txpktbuf_bndy
= 0xFA;
852 rtl_write_byte(rtlpriv
, REG_TRXFF_BNDY
, txpktbuf_bndy
);
853 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
+ 2, MAX_RX_DMA_BUFFER_SIZE
- 1);
855 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
857 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
858 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
860 rtl_write_byte(rtlpriv
, REG_PBP
, 0x31);
861 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
863 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
864 status
= _rtl8821ae_llt_write(hw
, i
, i
+ 1);
869 status
= _rtl8821ae_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
873 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
874 status
= _rtl8821ae_llt_write(hw
, i
, (i
+ 1));
879 status
= _rtl8821ae_llt_write(hw
, maxpage
, txpktbuf_bndy
);
883 rtl_write_dword(rtlpriv
, REG_RQPN
, rqpn
);
885 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x00);
890 static void _rtl8821ae_gen_refresh_led_state(struct ieee80211_hw
*hw
)
892 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
893 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
894 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
895 struct rtl_led
*pled0
= &pcipriv
->ledctl
.sw_led0
;
896 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
898 if (rtlpriv
->rtlhal
.up_first_time
)
901 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
902 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
903 rtl8812ae_sw_led_on(hw
, pled0
);
905 rtl8821ae_sw_led_on(hw
, pled0
);
906 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
907 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
908 rtl8812ae_sw_led_on(hw
, pled0
);
910 rtl8821ae_sw_led_on(hw
, pled0
);
912 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
913 rtl8812ae_sw_led_off(hw
, pled0
);
915 rtl8821ae_sw_led_off(hw
, pled0
);
918 static bool _rtl8821ae_init_mac(struct ieee80211_hw
*hw
)
920 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
921 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
922 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
926 bool mac_func_enable
= rtlhal
->mac_func_enable
;
928 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
930 /*Auto Power Down to CHIP-off State*/
931 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
932 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
934 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
935 /* HW Power on sequence*/
936 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
937 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
938 RTL8812_NIC_ENABLE_FLOW
)) {
939 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
940 "init 8812 MAC Fail as power on failure\n");
944 /* HW Power on sequence */
945 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_A_MSK
,
946 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
947 RTL8821A_NIC_ENABLE_FLOW
)){
948 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
949 "init 8821 MAC Fail as power on failure\n");
954 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
955 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
957 bytetmp
= rtl_read_byte(rtlpriv
, REG_CR
);
959 rtl_write_byte(rtlpriv
, REG_CR
, bytetmp
);
963 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, bytetmp
);
966 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
967 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
+ 3);
968 if (bytetmp
& BIT(0)) {
969 bytetmp
= rtl_read_byte(rtlpriv
, 0x7c);
971 rtl_write_byte(rtlpriv
, 0x7c, bytetmp
);
975 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1);
977 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1, bytetmp
);
979 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
981 if (!mac_func_enable
) {
982 if (!_rtl8821ae_llt_table_init(hw
))
986 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
987 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
989 /* Enable FW Beamformer Interrupt */
990 bytetmp
= rtl_read_byte(rtlpriv
, REG_FWIMR
+ 3);
991 rtl_write_byte(rtlpriv
, REG_FWIMR
+ 3, bytetmp
| BIT(6));
993 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
996 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
998 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 1, 0x1F);
999 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1000 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xFFFF);
1002 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
1003 rtlpci
->tx_ring
[BEACON_QUEUE
].dma
& DMA_BIT_MASK(32));
1004 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
1005 rtlpci
->tx_ring
[MGNT_QUEUE
].dma
& DMA_BIT_MASK(32));
1006 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
1007 rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
1008 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
1009 rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
1010 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
1011 rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
1012 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
1013 rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
1014 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
1015 rtlpci
->tx_ring
[HIGH_QUEUE
].dma
& DMA_BIT_MASK(32));
1016 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
1017 rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
& DMA_BIT_MASK(32));
1019 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3, 0x77);
1021 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
1023 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0);
1025 rtl_write_byte(rtlpriv
, REG_SECONDARY_CCA_CTRL
, 0x3);
1026 _rtl8821ae_gen_refresh_led_state(hw
);
1031 static void _rtl8821ae_hw_configure(struct ieee80211_hw
*hw
)
1033 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1034 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1037 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
1039 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_rrsr
);
1040 /* ARFB table 9 for 11ac 5G 2SS */
1041 rtl_write_dword(rtlpriv
, REG_ARFR0
+ 4, 0xfffff000);
1042 /* ARFB table 10 for 11ac 5G 1SS */
1043 rtl_write_dword(rtlpriv
, REG_ARFR1
+ 4, 0x003ff000);
1044 /* ARFB table 11 for 11ac 24G 1SS */
1045 rtl_write_dword(rtlpriv
, REG_ARFR2
, 0x00000015);
1046 rtl_write_dword(rtlpriv
, REG_ARFR2
+ 4, 0x003ff000);
1047 /* ARFB table 12 for 11ac 24G 1SS */
1048 rtl_write_dword(rtlpriv
, REG_ARFR3
, 0x00000015);
1049 rtl_write_dword(rtlpriv
, REG_ARFR3
+ 4, 0xffcff000);
1050 /* 0x420[7] = 0 , enable retry AMPDU in new AMPD not singal MPDU. */
1051 rtl_write_word(rtlpriv
, REG_FWHW_TXQ_CTRL
, 0x1F00);
1052 rtl_write_byte(rtlpriv
, REG_AMPDU_MAX_TIME
, 0x70);
1055 rtl_write_word(rtlpriv
, REG_RL
, 0x0707);
1057 /* Set Data / Response auto rate fallack retry count*/
1058 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x01000000);
1059 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4, 0x07060504);
1060 rtl_write_dword(rtlpriv
, REG_RARFRC
, 0x01000000);
1061 rtl_write_dword(rtlpriv
, REG_RARFRC
+ 4, 0x07060504);
1063 rtlpci
->reg_bcn_ctrl_val
= 0x1d;
1064 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, rtlpci
->reg_bcn_ctrl_val
);
1066 /* TBTT prohibit hold time. Suggested by designer TimChen. */
1067 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1069 /* AGGR_BK_TIME Reg51A 0x16 */
1070 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0040);
1072 /*For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
1073 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x03086666);
1075 rtl_write_byte(rtlpriv
, REG_HT_SINGLE_AMPDU
, 0x80);
1076 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x20);
1077 rtl_write_word(rtlpriv
, REG_MAX_AGGR_NUM
, 0x1F1F);
1080 static u16
_rtl8821ae_mdio_read(struct rtl_priv
*rtlpriv
, u8 addr
)
1083 u8 tmp
= 0, count
= 0;
1085 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(6));
1086 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1088 while (tmp
&& count
< 20) {
1090 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1094 ret
= rtl_read_word(rtlpriv
, REG_MDIO_RDATA
);
1099 static void _rtl8821ae_mdio_write(struct rtl_priv
*rtlpriv
, u8 addr
, u16 data
)
1101 u8 tmp
= 0, count
= 0;
1103 rtl_write_word(rtlpriv
, REG_MDIO_WDATA
, data
);
1104 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(5));
1105 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1107 while (tmp
&& count
< 20) {
1109 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1114 static u8
_rtl8821ae_dbi_read(struct rtl_priv
*rtlpriv
, u16 addr
)
1116 u16 read_addr
= addr
& 0xfffc;
1117 u8 tmp
= 0, count
= 0, ret
= 0;
1119 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, read_addr
);
1120 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x2);
1121 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1123 while (tmp
&& count
< 20) {
1125 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1129 read_addr
= REG_DBI_RDATA
+ addr
% 4;
1130 ret
= rtl_read_word(rtlpriv
, read_addr
);
1135 static void _rtl8821ae_dbi_write(struct rtl_priv
*rtlpriv
, u16 addr
, u8 data
)
1137 u8 tmp
= 0, count
= 0;
1138 u16 wrtie_addr
, remainder
= addr
% 4;
1140 wrtie_addr
= REG_DBI_WDATA
+ remainder
;
1141 rtl_write_byte(rtlpriv
, wrtie_addr
, data
);
1143 wrtie_addr
= (addr
& 0xfffc) | (BIT(0) << (remainder
+ 12));
1144 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, wrtie_addr
);
1146 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x1);
1148 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1150 while (tmp
&& count
< 20) {
1152 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1157 static void _rtl8821ae_enable_aspm_back_door(struct ieee80211_hw
*hw
)
1159 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1160 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1163 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1164 if (_rtl8821ae_mdio_read(rtlpriv
, 0x04) != 0x8544)
1165 _rtl8821ae_mdio_write(rtlpriv
, 0x04, 0x8544);
1167 if (_rtl8821ae_mdio_read(rtlpriv
, 0x0b) != 0x0070)
1168 _rtl8821ae_mdio_write(rtlpriv
, 0x0b, 0x0070);
1171 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x70f);
1172 _rtl8821ae_dbi_write(rtlpriv
, 0x70f, tmp
| BIT(7));
1174 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x719);
1175 _rtl8821ae_dbi_write(rtlpriv
, 0x719, tmp
| BIT(3) | BIT(4));
1177 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1178 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x718);
1179 _rtl8821ae_dbi_write(rtlpriv
, 0x718, tmp
|BIT(4));
1183 void rtl8821ae_enable_hw_security_config(struct ieee80211_hw
*hw
)
1185 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1189 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1190 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1191 rtlpriv
->sec
.pairwise_enc_algorithm
,
1192 rtlpriv
->sec
.group_enc_algorithm
);
1194 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1195 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1196 "not open hw encryption\n");
1200 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1202 if (rtlpriv
->sec
.use_defaultkey
) {
1203 sec_reg_value
|= SCR_TXUSEDK
;
1204 sec_reg_value
|= SCR_RXUSEDK
;
1207 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1209 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1210 rtl_write_byte(rtlpriv
, REG_CR
+ 1, tmp
| BIT(1));
1212 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1213 "The SECR-value %x\n", sec_reg_value
);
1215 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1218 /* Static MacID Mapping (cf. Used in MacIdDoStaticMapping) ---------- */
1219 #define MAC_ID_STATIC_FOR_DEFAULT_PORT 0
1220 #define MAC_ID_STATIC_FOR_BROADCAST_MULTICAST 1
1221 #define MAC_ID_STATIC_FOR_BT_CLIENT_START 2
1222 #define MAC_ID_STATIC_FOR_BT_CLIENT_END 3
1223 /* ----------------------------------------------------------- */
1225 static void rtl8821ae_macid_initialize_mediastatus(struct ieee80211_hw
*hw
)
1227 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1228 u8 media_rpt
[4] = {RT_MEDIA_CONNECT
, 1,
1229 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
,
1230 MAC_ID_STATIC_FOR_BT_CLIENT_END
};
1232 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1233 HW_VAR_H2C_FW_MEDIASTATUSRPT
, media_rpt
);
1235 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1236 "Initialize MacId media status: from %d to %d\n",
1237 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
,
1238 MAC_ID_STATIC_FOR_BT_CLIENT_END
);
1241 static bool _rtl8821ae_check_pcie_dma_hang(struct ieee80211_hw
*hw
)
1243 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1246 /* write reg 0x350 Bit[26]=1. Enable debug port. */
1247 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1248 if (!(tmp
& BIT(2))) {
1249 rtl_write_byte(rtlpriv
, REG_DBI_CTRL
+ 3, (tmp
| BIT(2)));
1253 /* read reg 0x350 Bit[25] if 1 : RX hang */
1254 /* read reg 0x350 Bit[24] if 1 : TX hang */
1255 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1256 if ((tmp
& BIT(0)) || (tmp
& BIT(1))) {
1257 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1258 "CheckPcieDMAHang8821AE(): true! Reset PCIE DMA!\n");
1265 static bool _rtl8821ae_reset_pcie_interface_dma(struct ieee80211_hw
*hw
,
1269 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1270 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1272 bool release_mac_rx_pause
;
1273 u8 backup_pcie_dma_pause
;
1275 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "\n");
1277 /* 1. Disable register write lock. 0x1c[1] = 0 */
1278 tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
);
1280 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, tmp
);
1281 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1282 /* write 0xCC bit[2] = 1'b1 */
1283 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1285 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1288 /* 2. Check and pause TRX DMA */
1289 /* write 0x284 bit[18] = 1'b1 */
1290 /* write 0x301 = 0xFF */
1291 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1293 /* Already pause before the function for another purpose. */
1294 release_mac_rx_pause
= false;
1296 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1297 release_mac_rx_pause
= true;
1299 backup_pcie_dma_pause
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1);
1300 if (backup_pcie_dma_pause
!= 0xFF)
1301 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFF);
1304 /* 3. reset TRX function */
1305 /* write 0x100 = 0x00 */
1306 rtl_write_byte(rtlpriv
, REG_CR
, 0);
1309 /* 4. Reset PCIe DMA. 0x3[0] = 0 */
1310 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1312 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1314 /* 5. Enable PCIe DMA. 0x3[0] = 1 */
1315 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1317 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1320 /* 6. enable TRX function */
1321 /* write 0x100 = 0xFF */
1322 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1324 /* We should init LLT & RQPN and
1325 * prepare Tx/Rx descrptor address later
1326 * because MAC function is reset.*/
1329 /* 7. Restore PCIe autoload down bit */
1330 /* 8812AE does not has the defination. */
1331 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1332 /* write 0xF8 bit[17] = 1'b1 */
1333 tmp
= rtl_read_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2);
1335 rtl_write_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2, tmp
);
1338 /* In MAC power on state, BB and RF maybe in ON state,
1339 * if we release TRx DMA here.
1340 * it will cause packets to be started to Tx/Rx,
1341 * so we release Tx/Rx DMA later.*/
1342 if (!mac_power_on
/* || in_watchdog*/) {
1343 /* 8. release TRX DMA */
1344 /* write 0x284 bit[18] = 1'b0 */
1345 /* write 0x301 = 0x00 */
1346 if (release_mac_rx_pause
) {
1347 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1348 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
,
1351 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1,
1352 backup_pcie_dma_pause
);
1355 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1356 /* 9. lock system register */
1357 /* write 0xCC bit[2] = 1'b0 */
1358 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1360 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1365 static void _rtl8821ae_get_wakeup_reason(struct ieee80211_hw
*hw
)
1367 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1368 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1369 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
1373 fw_reason
= rtl_read_byte(rtlpriv
, REG_MCUTST_WOWLAN
);
1375 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "WOL Read 0x1c7 = %02X\n",
1378 ppsc
->wakeup_reason
= 0;
1380 rtlhal
->last_suspend_sec
= ts
.tv_sec
;
1382 switch (fw_reason
) {
1383 case FW_WOW_V2_PTK_UPDATE_EVENT
:
1384 ppsc
->wakeup_reason
= WOL_REASON_PTK_UPDATE
;
1385 do_gettimeofday(&ts
);
1386 ppsc
->last_wakeup_time
= ts
.tv_sec
*1000 + ts
.tv_usec
/1000;
1387 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1388 "It's a WOL PTK Key update event!\n");
1390 case FW_WOW_V2_GTK_UPDATE_EVENT
:
1391 ppsc
->wakeup_reason
= WOL_REASON_GTK_UPDATE
;
1392 do_gettimeofday(&ts
);
1393 ppsc
->last_wakeup_time
= ts
.tv_sec
*1000 + ts
.tv_usec
/1000;
1394 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1395 "It's a WOL GTK Key update event!\n");
1397 case FW_WOW_V2_DISASSOC_EVENT
:
1398 ppsc
->wakeup_reason
= WOL_REASON_DISASSOC
;
1399 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1400 "It's a disassociation event!\n");
1402 case FW_WOW_V2_DEAUTH_EVENT
:
1403 ppsc
->wakeup_reason
= WOL_REASON_DEAUTH
;
1404 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1405 "It's a deauth event!\n");
1407 case FW_WOW_V2_FW_DISCONNECT_EVENT
:
1408 ppsc
->wakeup_reason
= WOL_REASON_AP_LOST
;
1409 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1410 "It's a Fw disconnect decision (AP lost) event!\n");
1412 case FW_WOW_V2_MAGIC_PKT_EVENT
:
1413 ppsc
->wakeup_reason
= WOL_REASON_MAGIC_PKT
;
1414 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1415 "It's a magic packet event!\n");
1417 case FW_WOW_V2_UNICAST_PKT_EVENT
:
1418 ppsc
->wakeup_reason
= WOL_REASON_UNICAST_PKT
;
1419 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1420 "It's an unicast packet event!\n");
1422 case FW_WOW_V2_PATTERN_PKT_EVENT
:
1423 ppsc
->wakeup_reason
= WOL_REASON_PATTERN_PKT
;
1424 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1425 "It's a pattern match event!\n");
1427 case FW_WOW_V2_RTD3_SSID_MATCH_EVENT
:
1428 ppsc
->wakeup_reason
= WOL_REASON_RTD3_SSID_MATCH
;
1429 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1430 "It's an RTD3 Ssid match event!\n");
1432 case FW_WOW_V2_REALWOW_V2_WAKEUPPKT
:
1433 ppsc
->wakeup_reason
= WOL_REASON_REALWOW_V2_WAKEUPPKT
;
1434 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1435 "It's an RealWoW wake packet event!\n");
1437 case FW_WOW_V2_REALWOW_V2_ACKLOST
:
1438 ppsc
->wakeup_reason
= WOL_REASON_REALWOW_V2_ACKLOST
;
1439 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1440 "It's an RealWoW ack lost event!\n");
1443 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
1444 "WOL Read 0x1c7 = %02X, Unknown reason!\n",
1450 static void _rtl8821ae_init_trx_desc_hw_address(struct ieee80211_hw
*hw
)
1452 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1453 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1456 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
1457 rtlpci
->tx_ring
[BEACON_QUEUE
].dma
& DMA_BIT_MASK(32));
1458 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
1459 rtlpci
->tx_ring
[MGNT_QUEUE
].dma
& DMA_BIT_MASK(32));
1460 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
1461 rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
1462 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
1463 rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
1464 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
1465 rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
1466 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
1467 rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
1468 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
1469 rtlpci
->tx_ring
[HIGH_QUEUE
].dma
& DMA_BIT_MASK(32));
1470 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
1471 rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
& DMA_BIT_MASK(32));
1474 static bool _rtl8821ae_init_llt_table(struct ieee80211_hw
*hw
, u32 boundary
)
1478 u32 txpktbuf_bndy
= boundary
;
1479 u32 last_entry_of_txpktbuf
= LAST_ENTRY_OF_TX_PKT_BUFFER
;
1481 for (i
= 0 ; i
< (txpktbuf_bndy
- 1) ; i
++) {
1482 status
= _rtl8821ae_llt_write(hw
, i
, i
+ 1);
1487 status
= _rtl8821ae_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
1491 for (i
= txpktbuf_bndy
; i
< last_entry_of_txpktbuf
; i
++) {
1492 status
= _rtl8821ae_llt_write(hw
, i
, (i
+ 1));
1497 status
= _rtl8821ae_llt_write(hw
, last_entry_of_txpktbuf
,
1505 static bool _rtl8821ae_dynamic_rqpn(struct ieee80211_hw
*hw
, u32 boundary
,
1506 u16 npq_rqpn_value
, u32 rqpn_val
)
1508 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1511 u16 count
= 0, tmp16
;
1512 bool support_remote_wakeup
;
1514 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
1515 (u8
*)(&support_remote_wakeup
));
1517 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1518 "boundary=%#X, NPQ_RQPNValue=%#X, RQPNValue=%#X\n",
1519 boundary
, npq_rqpn_value
, rqpn_val
);
1522 * 1. 0x301[7:0] = 0xFE */
1523 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFE);
1526 * 2. polling till 0x41A[15:0]=0x07FF */
1527 tmp16
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
1528 while ((tmp16
& 0x07FF) != 0x07FF) {
1530 tmp16
= rtl_read_word(rtlpriv
, REG_TXPKT_EMPTY
);
1532 if ((count
% 200) == 0) {
1533 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1534 "Tx queue is not empty for 20ms!\n");
1536 if (count
>= 1000) {
1537 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1538 "Wait for Tx FIFO empty timeout!\n");
1544 * 3. reg 0x522=0xFF */
1545 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1547 /* Wait TX State Machine OK
1548 * 4. polling till reg 0x5FB~0x5F8 = 0x00000000 for 50ms */
1550 while (rtl_read_byte(rtlpriv
, REG_SCH_TXCMD
) != 0) {
1554 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1555 "Wait for TX State Machine ready timeout !!\n");
1562 * 6. wait till 0x284[17] == 1
1563 * wait RX DMA idle */
1565 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1566 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1568 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1571 } while (!(tmp
& BIT(1)) && count
< 100);
1573 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1574 "Wait until Rx DMA Idle. count=%d REG[0x286]=0x%x\n",
1578 * 7. 0x02 [0] = 0 */
1579 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
1581 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, tmp
);
1586 rtl_write_byte(rtlpriv
, REG_CR
, 0x00);
1589 /* Disable MAC Security Engine
1590 * 9. 0x100 bit[9]=0 */
1591 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1593 rtl_write_byte(rtlpriv
, REG_CR
+ 1, tmp
);
1595 /* To avoid DD-Tim Circuit hang
1596 * 10. 0x553 bit[5]=1 */
1597 tmp
= rtl_read_byte(rtlpriv
, REG_DUAL_TSF_RST
);
1598 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (tmp
| BIT(5)));
1600 /* Enable MAC Security Engine
1601 * 11. 0x100 bit[9]=1 */
1602 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1603 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
| BIT(1)));
1608 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1612 * 13. 0x02 [0] = 1 */
1613 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
);
1614 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, (tmp
| BIT(0)));
1617 * 14,15. set beacon head page (reg 0x209 and 0x424) */
1618 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, (u8
)boundary
);
1619 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, (u8
)boundary
);
1620 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, (u8
)boundary
);
1622 /* 16. WMAC_LBK_BF_HD 0x45D[7:0]
1624 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_WMAC_LBK_BF_HD
,
1627 rtl_write_word(rtlpriv
, REG_TRXFF_BNDY
, boundary
);
1631 if (!_rtl8821ae_init_llt_table(hw
, boundary
)) {
1632 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
1633 "Failed to init LLT table!\n");
1638 * 18. reallocate RQPN and init LLT */
1639 rtl_write_word(rtlpriv
, REG_RQPN_NPQ
, npq_rqpn_value
);
1640 rtl_write_dword(rtlpriv
, REG_RQPN
, rqpn_val
);
1644 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0x00);
1647 * 20. 0x301[7:0] = 0x00
1648 * 21. 0x284[18] = 0 */
1649 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0x00);
1650 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1651 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
&~BIT(2)));
1653 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "End.\n");
1657 static void _rtl8821ae_simple_initialize_adapter(struct ieee80211_hw
*hw
)
1659 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1660 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1661 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
1663 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
1664 /* Re-download normal Fw. */
1665 rtl8821ae_set_fw_related_for_wowlan(hw
, false);
1668 /* Re-Initialize LLT table. */
1669 if (rtlhal
->re_init_llt_table
) {
1670 u32 rqpn
= 0x80e70808;
1671 u8 rqpn_npq
= 0, boundary
= 0xF8;
1672 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1676 if (_rtl8821ae_dynamic_rqpn(hw
, boundary
, rqpn_npq
, rqpn
))
1677 rtlhal
->re_init_llt_table
= false;
1680 ppsc
->rfpwr_state
= ERFON
;
1683 static void _rtl8821ae_enable_l1off(struct ieee80211_hw
*hw
)
1686 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1688 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "--->\n");
1690 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x160);
1691 if (!(tmp
& (BIT(2) | BIT(3)))) {
1692 RT_TRACE(rtlpriv
, COMP_POWER
| COMP_INIT
, DBG_LOUD
,
1693 "0x160(%#x)return!!\n", tmp
);
1697 tmp
= _rtl8821ae_mdio_read(rtlpriv
, 0x1b);
1698 _rtl8821ae_mdio_write(rtlpriv
, 0x1b, (tmp
| BIT(4)));
1700 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x718);
1701 _rtl8821ae_dbi_write(rtlpriv
, 0x718, tmp
| BIT(5));
1703 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<---\n");
1706 static void _rtl8821ae_enable_ltr(struct ieee80211_hw
*hw
)
1709 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1711 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "--->\n");
1713 /* Check 0x98[10] */
1714 tmp
= _rtl8821ae_dbi_read(rtlpriv
, 0x99);
1715 if (!(tmp
& BIT(2))) {
1716 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1717 "<---0x99(%#x) return!!\n", tmp
);
1721 /* LTR idle latency, 0x90 for 144us */
1722 rtl_write_dword(rtlpriv
, 0x798, 0x88908890);
1724 /* LTR active latency, 0x3c for 60us */
1725 rtl_write_dword(rtlpriv
, 0x79c, 0x883c883c);
1727 tmp
= rtl_read_byte(rtlpriv
, 0x7a4);
1728 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
| BIT(4)));
1730 tmp
= rtl_read_byte(rtlpriv
, 0x7a4);
1731 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
& (~BIT(0))));
1732 rtl_write_byte(rtlpriv
, 0x7a4, (tmp
| BIT(0)));
1734 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "<---\n");
1737 static bool _rtl8821ae_wowlan_initialize_adapter(struct ieee80211_hw
*hw
)
1739 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1740 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1741 bool init_finished
= true;
1744 /* Get Fw wake up reason. */
1745 _rtl8821ae_get_wakeup_reason(hw
);
1747 /* Patch Pcie Rx DMA hang after S3/S4 several times.
1748 * The root cause has not be found. */
1749 if (_rtl8821ae_check_pcie_dma_hang(hw
))
1750 _rtl8821ae_reset_pcie_interface_dma(hw
, true, false);
1752 /* Prepare Tx/Rx Desc Hw address. */
1753 _rtl8821ae_init_trx_desc_hw_address(hw
);
1755 /* Release Pcie Interface Rx DMA to allow wake packet DMA. */
1756 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFE);
1757 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Enable PCIE Rx DMA.\n");
1759 /* Check wake up event.
1760 * We should check wake packet bit before disable wowlan by H2C or
1761 * Fw will clear the bit. */
1762 tmp
= rtl_read_byte(rtlpriv
, REG_FTISR
+ 3);
1763 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
1764 "Read REG_FTISR 0x13f = %#X\n", tmp
);
1766 /* Set the WoWLAN related function control disable. */
1767 rtl8821ae_set_fw_wowlan_mode(hw
, false);
1768 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw
, 0);
1770 if (rtlhal
->hw_rof_enable
) {
1771 tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
+ 3);
1773 /* Clear GPIO9 ISR */
1774 rtl_write_byte(rtlpriv
, REG_HSISR
+ 3, tmp
| BIT(1));
1775 init_finished
= false;
1777 init_finished
= true;
1781 if (init_finished
) {
1782 _rtl8821ae_simple_initialize_adapter(hw
);
1784 /* Release Pcie Interface Tx DMA. */
1785 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0x00);
1786 /* Release Pcie RX DMA */
1787 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, 0x02);
1789 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
1790 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
& (~BIT(0))));
1792 _rtl8821ae_enable_l1off(hw
);
1793 _rtl8821ae_enable_ltr(hw
);
1796 return init_finished
;
1799 static void _rtl8812ae_bb8812_config_1t(struct ieee80211_hw
*hw
)
1801 /* BB OFDM RX Path_A */
1802 rtl_set_bbreg(hw
, 0x808, 0xff, 0x11);
1803 /* BB OFDM TX Path_A */
1804 rtl_set_bbreg(hw
, 0x80c, MASKLWORD
, 0x1111);
1805 /* BB CCK R/Rx Path_A */
1806 rtl_set_bbreg(hw
, 0xa04, 0x0c000000, 0x0);
1808 rtl_set_bbreg(hw
, 0x8bc, 0xc0000060, 0x4);
1809 /* RF Path_B HSSI OFF */
1810 rtl_set_bbreg(hw
, 0xe00, 0xf, 0x4);
1811 /* RF Path_B Power Down */
1812 rtl_set_bbreg(hw
, 0xe90, MASKDWORD
, 0);
1813 /* ADDA Path_B OFF */
1814 rtl_set_bbreg(hw
, 0xe60, MASKDWORD
, 0);
1815 rtl_set_bbreg(hw
, 0xe64, MASKDWORD
, 0);
1818 static void _rtl8821ae_poweroff_adapter(struct ieee80211_hw
*hw
)
1820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1821 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1824 rtlhal
->mac_func_enable
= false;
1826 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1827 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1828 /* 1. Run LPS WL RFOFF flow */
1829 /* RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1830 "=====>CardDisableRTL8812E,RTL8821A_NIC_LPS_ENTER_FLOW\n");
1832 rtl_hal_pwrseqcmdparsing(rtlpriv
,
1833 PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1834 PWR_INTF_PCI_MSK
, RTL8821A_NIC_LPS_ENTER_FLOW
);
1836 /* 2. 0x1F[7:0] = 0 */
1838 /* rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); */
1839 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) &&
1841 rtl8821ae_firmware_selfreset(hw
);
1844 /* Reset MCU. Suggested by Filen. */
1845 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1846 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+1, (u1b_tmp
& (~BIT(2))));
1848 /* g. MCUFWDL 0x80[1:0]=0 */
1849 /* reset MCU ready status */
1850 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1852 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
1853 /* HW card disable configuration. */
1854 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1855 PWR_INTF_PCI_MSK
, RTL8821A_NIC_DISABLE_FLOW
);
1857 /* HW card disable configuration. */
1858 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1859 PWR_INTF_PCI_MSK
, RTL8812_NIC_DISABLE_FLOW
);
1862 /* Reset MCU IO Wrapper */
1863 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1864 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, (u1b_tmp
& (~BIT(0))));
1865 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1866 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, u1b_tmp
| BIT(0));
1868 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1869 /* lock ISO/CLK/Power control register */
1870 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0e);
1873 int rtl8821ae_hw_init(struct ieee80211_hw
*hw
)
1875 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1876 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1877 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1878 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1879 bool rtstatus
= true;
1882 bool support_remote_wakeup
;
1883 u32 nav_upper
= WIFI_NAV_UPPER_US
;
1885 rtlhal
->being_init_adapter
= true;
1886 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
1887 (u8
*)(&support_remote_wakeup
));
1888 rtlpriv
->intf_ops
->disable_aspm(hw
);
1890 /*YP wowlan not considered*/
1892 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_CR
);
1893 if (tmp_u1b
!= 0 && tmp_u1b
!= 0xEA) {
1894 rtlhal
->mac_func_enable
= true;
1895 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1896 "MAC has already power on.\n");
1898 rtlhal
->mac_func_enable
= false;
1899 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_8821AE
;
1902 if (support_remote_wakeup
&&
1903 rtlhal
->wake_from_pnp_sleep
&&
1904 rtlhal
->mac_func_enable
) {
1905 if (_rtl8821ae_wowlan_initialize_adapter(hw
)) {
1906 rtlhal
->being_init_adapter
= false;
1911 if (_rtl8821ae_check_pcie_dma_hang(hw
)) {
1912 _rtl8821ae_reset_pcie_interface_dma(hw
,
1913 rtlhal
->mac_func_enable
,
1915 rtlhal
->mac_func_enable
= false;
1918 /* Reset MAC/BB/RF status if it is not powered off
1919 * before calling initialize Hw flow to prevent
1920 * from interface and MAC status mismatch.
1921 * 2013.06.21, by tynli. Suggested by SD1 JackieLau. */
1922 if (rtlhal
->mac_func_enable
) {
1923 _rtl8821ae_poweroff_adapter(hw
);
1924 rtlhal
->mac_func_enable
= false;
1927 rtstatus
= _rtl8821ae_init_mac(hw
);
1928 if (rtstatus
!= true) {
1929 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Init MAC failed\n");
1934 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
);
1936 rtl_write_byte(rtlpriv
, REG_SYS_CFG
, tmp_u1b
);
1938 err
= rtl8821ae_download_fw(hw
, false);
1940 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1941 "Failed to download FW. Init HW without FW now\n");
1943 rtlhal
->fw_ready
= false;
1946 rtlhal
->fw_ready
= true;
1948 ppsc
->fw_current_inpsmode
= false;
1949 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_8821AE
;
1950 rtlhal
->fw_clk_change_in_progress
= false;
1951 rtlhal
->allow_sw_to_change_hwclc
= false;
1952 rtlhal
->last_hmeboxnum
= 0;
1954 /*SIC_Init(Adapter);
1955 if(rtlhal->AMPDUBurstMode)
1956 rtl_write_byte(rtlpriv,REG_AMPDU_BURST_MODE_8812, 0x7F);*/
1958 rtl8821ae_phy_mac_config(hw
);
1959 /* because last function modify RCR, so we update
1960 * rcr var here, or TP will unstable for receive_config
1961 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1962 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1963 rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
1964 rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
1965 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);*/
1966 rtl8821ae_phy_bb_config(hw
);
1968 rtl8821ae_phy_rf_config(hw
);
1970 if (rtlpriv
->phy
.rf_type
== RF_1T1R
&&
1971 rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
1972 _rtl8812ae_bb8812_config_1t(hw
);
1974 _rtl8821ae_hw_configure(hw
);
1976 rtl8821ae_phy_switch_wirelessband(hw
, BAND_ON_2_4G
);
1978 /*set wireless mode*/
1980 rtlhal
->mac_func_enable
= true;
1982 rtl_cam_reset_all_entry(hw
);
1984 rtl8821ae_enable_hw_security_config(hw
);
1986 ppsc
->rfpwr_state
= ERFON
;
1988 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1989 _rtl8821ae_enable_aspm_back_door(hw
);
1990 rtlpriv
->intf_ops
->enable_aspm(hw
);
1992 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
&&
1993 (rtlhal
->rfe_type
== 1 || rtlhal
->rfe_type
== 5))
1994 rtl_set_bbreg(hw
, 0x900, 0x00000303, 0x0302);
1996 rtl8821ae_bt_hw_init(hw
);
1997 rtlpriv
->rtlhal
.being_init_adapter
= false;
1999 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_NAV_UPPER
, (u8
*)&nav_upper
);
2001 /* rtl8821ae_dm_check_txpower_tracking(hw); */
2002 /* rtl8821ae_phy_lc_calibrate(hw); */
2003 if (support_remote_wakeup
)
2004 rtl_write_byte(rtlpriv
, REG_WOW_CTRL
, 0);
2007 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
2008 if (tmp_u1b
& BIT(2)) {
2009 /* Release Rx DMA if needed*/
2011 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, tmp_u1b
);
2014 /* Release Tx/Rx PCIE DMA if*/
2015 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0);
2017 rtl8821ae_dm_init(hw
);
2018 rtl8821ae_macid_initialize_mediastatus(hw
);
2020 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rtl8821ae_hw_init() <====\n");
2024 static enum version_8821ae
_rtl8821ae_read_chip_version(struct ieee80211_hw
*hw
)
2026 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2027 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
2028 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2029 enum version_8821ae version
= VERSION_UNKNOWN
;
2032 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
2033 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2034 "ReadChipVersion8812A 0xF0 = 0x%x\n", value32
);
2036 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
2037 rtlphy
->rf_type
= RF_2T2R
;
2038 else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
)
2039 rtlphy
->rf_type
= RF_1T1R
;
2041 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2042 "RF_Type is %x!!\n", rtlphy
->rf_type
);
2044 if (value32
& TRP_VAUX_EN
) {
2045 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
2046 if (rtlphy
->rf_type
== RF_2T2R
)
2047 version
= VERSION_TEST_CHIP_2T2R_8812
;
2049 version
= VERSION_TEST_CHIP_1T1R_8812
;
2051 version
= VERSION_TEST_CHIP_8821
;
2053 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
2054 u32 rtl_id
= ((value32
& CHIP_VER_RTL_MASK
) >> 12) + 1;
2056 if (rtlphy
->rf_type
== RF_2T2R
)
2058 (enum version_8821ae
)(CHIP_8812
2062 version
= (enum version_8821ae
)(CHIP_8812
2065 version
= (enum version_8821ae
)(version
| (rtl_id
<< 12));
2066 } else if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
2067 u32 rtl_id
= value32
& CHIP_VER_RTL_MASK
;
2069 version
= (enum version_8821ae
)(CHIP_8821
2070 | NORMAL_CHIP
| rtl_id
);
2074 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8821AE
) {
2076 value32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
2077 rtlhal
->hw_rof_enable
= ((value32
& WL_HWROF_EN
) ? 1 : 0);
2081 case VERSION_TEST_CHIP_1T1R_8812
:
2082 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2083 "Chip Version ID: VERSION_TEST_CHIP_1T1R_8812\n");
2085 case VERSION_TEST_CHIP_2T2R_8812
:
2086 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2087 "Chip Version ID: VERSION_TEST_CHIP_2T2R_8812\n");
2089 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812
:
2090 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2091 "Chip Version ID:VERSION_NORMAL_TSMC_CHIP_1T1R_8812\n");
2093 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812
:
2094 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2095 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812\n");
2097 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812_C_CUT
:
2098 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2099 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_1T1R_8812 C CUT\n");
2101 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812_C_CUT
:
2102 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2103 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812 C CUT\n");
2105 case VERSION_TEST_CHIP_8821
:
2106 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2107 "Chip Version ID: VERSION_TEST_CHIP_8821\n");
2109 case VERSION_NORMAL_TSMC_CHIP_8821
:
2110 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2111 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 A CUT\n");
2113 case VERSION_NORMAL_TSMC_CHIP_8821_B_CUT
:
2114 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2115 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 B CUT\n");
2118 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2119 "Chip Version ID: Unknow (0x%X)\n", version
);
2126 static int _rtl8821ae_set_media_status(struct ieee80211_hw
*hw
,
2127 enum nl80211_iftype type
)
2129 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2130 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
2131 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
2134 rtl_write_dword(rtlpriv
, REG_BCN_CTRL
, 0);
2135 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_LOUD
,
2136 "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
2138 if (type
== NL80211_IFTYPE_UNSPECIFIED
||
2139 type
== NL80211_IFTYPE_STATION
) {
2140 _rtl8821ae_stop_tx_beacon(hw
);
2141 _rtl8821ae_enable_bcn_sub_func(hw
);
2142 } else if (type
== NL80211_IFTYPE_ADHOC
||
2143 type
== NL80211_IFTYPE_AP
) {
2144 _rtl8821ae_resume_tx_beacon(hw
);
2145 _rtl8821ae_disable_bcn_sub_func(hw
);
2147 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2148 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
2153 case NL80211_IFTYPE_UNSPECIFIED
:
2154 bt_msr
|= MSR_NOLINK
;
2155 ledaction
= LED_CTL_LINK
;
2156 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2157 "Set Network type to NO LINK!\n");
2159 case NL80211_IFTYPE_ADHOC
:
2160 bt_msr
|= MSR_ADHOC
;
2161 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2162 "Set Network type to Ad Hoc!\n");
2164 case NL80211_IFTYPE_STATION
:
2165 bt_msr
|= MSR_INFRA
;
2166 ledaction
= LED_CTL_LINK
;
2167 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2168 "Set Network type to STA!\n");
2170 case NL80211_IFTYPE_AP
:
2172 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
2173 "Set Network type to AP!\n");
2176 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2177 "Network type %d not support!\n", type
);
2181 rtl_write_byte(rtlpriv
, MSR
, bt_msr
);
2182 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
2183 if ((bt_msr
& MSR_MASK
) == MSR_AP
)
2184 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
2186 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
2191 void rtl8821ae_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
2193 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2194 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2195 u32 reg_rcr
= rtlpci
->receive_config
;
2197 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
2201 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
2202 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
2204 _rtl8821ae_set_bcn_ctrl_reg(hw
, 0, BIT(4));
2205 } else if (!check_bssid
) {
2206 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
2207 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(4), 0);
2208 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2209 HW_VAR_RCR
, (u8
*)(®_rcr
));
2213 int rtl8821ae_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
2215 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2217 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "rtl8821ae_set_network_type!\n");
2219 if (_rtl8821ae_set_media_status(hw
, type
))
2222 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
2223 if (type
!= NL80211_IFTYPE_AP
)
2224 rtl8821ae_set_check_bssid(hw
, true);
2226 rtl8821ae_set_check_bssid(hw
, false);
2232 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
2233 void rtl8821ae_set_qos(struct ieee80211_hw
*hw
, int aci
)
2235 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2236 rtl8821ae_dm_init_edca_turbo(hw
);
2239 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
2242 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
2245 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
2248 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
2251 RT_ASSERT(false, "invalid aci: %d !\n", aci
);
2256 static void rtl8821ae_clear_interrupt(struct ieee80211_hw
*hw
)
2258 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2259 u32 tmp
= rtl_read_dword(rtlpriv
, REG_HISR
);
2261 rtl_write_dword(rtlpriv
, REG_HISR
, tmp
);
2263 tmp
= rtl_read_dword(rtlpriv
, REG_HISRE
);
2264 rtl_write_dword(rtlpriv
, REG_HISRE
, tmp
);
2266 tmp
= rtl_read_dword(rtlpriv
, REG_HSISR
);
2267 rtl_write_dword(rtlpriv
, REG_HSISR
, tmp
);
2270 void rtl8821ae_enable_interrupt(struct ieee80211_hw
*hw
)
2272 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2273 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2275 if (rtlpci
->int_clear
)
2276 rtl8821ae_clear_interrupt(hw
);/*clear it here first*/
2278 rtl_write_dword(rtlpriv
, REG_HIMR
, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
2279 rtl_write_dword(rtlpriv
, REG_HIMRE
, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
2280 rtlpci
->irq_enabled
= true;
2281 /* there are some C2H CMDs have been sent before
2282 system interrupt is enabled, e.g., C2H, CPWM.
2283 *So we need to clear all C2H events that FW has
2284 notified, otherwise FW won't schedule any commands anymore.
2286 /* rtl_write_byte(rtlpriv, REG_C2HEVT_CLEAR, 0); */
2287 /*enable system interrupt*/
2288 rtl_write_dword(rtlpriv
, REG_HSIMR
, rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
2291 void rtl8821ae_disable_interrupt(struct ieee80211_hw
*hw
)
2293 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2294 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2296 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
2297 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
2298 rtlpci
->irq_enabled
= false;
2299 /*synchronize_irq(rtlpci->pdev->irq);*/
2302 static void _rtl8821ae_clear_pci_pme_status(struct ieee80211_hw
*hw
)
2304 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2305 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2312 /* Get the Capability pointer first,
2313 * the Capability Pointer is located at
2314 * offset 0x34 from the Function Header */
2316 pci_read_config_byte(rtlpci
->pdev
, 0x34, &cap_pointer
);
2317 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2318 "PCI configration 0x34 = 0x%2x\n", cap_pointer
);
2321 pci_read_config_word(rtlpci
->pdev
, cap_pointer
, &cap_hdr
);
2322 cap_id
= cap_hdr
& 0xFF;
2324 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2325 "in pci configration, cap_pointer%x = %x\n",
2326 cap_pointer
, cap_id
);
2328 if (cap_id
== 0x01) {
2331 /* point to next Capability */
2332 cap_pointer
= (cap_hdr
>> 8) & 0xFF;
2333 /* 0: end of pci capability, 0xff: invalid value */
2334 if (cap_pointer
== 0x00 || cap_pointer
== 0xff) {
2339 } while (cnt
++ < 200);
2341 if (cap_id
== 0x01) {
2342 /* Get the PM CSR (Control/Status Register),
2343 * The PME_Status is located at PM Capatibility offset 5, bit 7
2345 pci_read_config_byte(rtlpci
->pdev
, cap_pointer
+ 5, &pmcs_reg
);
2347 if (pmcs_reg
& BIT(7)) {
2348 /* PME event occured, clear the PM_Status by write 1 */
2349 pmcs_reg
= pmcs_reg
| BIT(7);
2351 pci_write_config_byte(rtlpci
->pdev
, cap_pointer
+ 5,
2353 /* Read it back to check */
2354 pci_read_config_byte(rtlpci
->pdev
, cap_pointer
+ 5,
2356 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2357 "Clear PME status 0x%2x to 0x%2x\n",
2358 cap_pointer
+ 5, pmcs_reg
);
2360 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2361 "PME status(0x%2x) = 0x%2x\n",
2362 cap_pointer
+ 5, pmcs_reg
);
2365 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_WARNING
,
2366 "Cannot find PME Capability\n");
2370 void rtl8821ae_card_disable(struct ieee80211_hw
*hw
)
2372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2373 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2374 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
2375 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
2376 enum nl80211_iftype opmode
;
2377 bool support_remote_wakeup
;
2381 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
2382 (u8
*)(&support_remote_wakeup
));
2384 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2386 if (!(support_remote_wakeup
&& mac
->opmode
== NL80211_IFTYPE_STATION
)
2387 || !rtlhal
->enter_pnp_sleep
) {
2388 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Normal Power off\n");
2389 mac
->link_state
= MAC80211_NOLINK
;
2390 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
2391 _rtl8821ae_set_media_status(hw
, opmode
);
2392 _rtl8821ae_poweroff_adapter(hw
);
2394 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Wowlan Supported.\n");
2395 /* 3 <1> Prepare for configuring wowlan related infomations */
2396 /* Clear Fw WoWLAN event. */
2397 rtl_write_byte(rtlpriv
, REG_MCUTST_WOWLAN
, 0x0);
2399 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
2400 rtl8821ae_set_fw_related_for_wowlan(hw
, true);
2402 /* Dynamically adjust Tx packet boundary
2403 * for download reserved page packet.
2404 * reserve 30 pages for rsvd page */
2405 if (_rtl8821ae_dynamic_rqpn(hw
, 0xE0, 0x3, 0x80c20d0d))
2406 rtlhal
->re_init_llt_table
= true;
2408 /* 3 <2> Set Fw releted H2C cmd. */
2410 /* Set WoWLAN related security information. */
2411 rtl8821ae_set_fw_global_info_cmd(hw
);
2413 _rtl8821ae_download_rsvd_page(hw
, true);
2415 /* Just enable AOAC related functions when we connect to AP. */
2416 printk("mac->link_state = %d\n", mac
->link_state
);
2417 if (mac
->link_state
>= MAC80211_LINKED
&&
2418 mac
->opmode
== NL80211_IFTYPE_STATION
) {
2419 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
2420 rtl8821ae_set_fw_media_status_rpt_cmd(hw
,
2423 rtl8821ae_set_fw_wowlan_mode(hw
, true);
2424 /* Enable Fw Keep alive mechanism. */
2425 rtl8821ae_set_fw_keep_alive_cmd(hw
, true);
2427 /* Enable disconnect decision control. */
2428 rtl8821ae_set_fw_disconnect_decision_ctrl_cmd(hw
, true);
2431 /* 3 <3> Hw Configutations */
2433 /* Wait untill Rx DMA Finished before host sleep.
2434 * FW Pause Rx DMA may happens when received packet doing dma.
2436 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, BIT(2));
2438 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
2440 while (!(tmp
& BIT(1)) && (count
++ < 100)) {
2442 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
2444 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2445 "Wait Rx DMA Finished before host sleep. count=%d\n",
2448 /* reset trx ring */
2449 rtlpriv
->intf_ops
->reset_trx_ring(hw
);
2451 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, 0x0);
2453 _rtl8821ae_clear_pci_pme_status(hw
);
2454 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
2455 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, tmp
| BIT(3));
2456 /* prevent 8051 to be reset by PERST */
2457 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x20);
2458 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x60);
2461 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
2462 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
2463 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
2464 /* For wowlan+LPS+32k. */
2465 if (support_remote_wakeup
&& rtlhal
->enter_pnp_sleep
) {
2466 /* Set the WoWLAN related function control enable.
2467 * It should be the last H2C cmd in the WoWLAN flow. */
2468 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw
, 1);
2470 /* Stop Pcie Interface Tx DMA. */
2471 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xff);
2472 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "Stop PCIE Tx DMA.\n");
2474 /* Wait for TxDMA idle. */
2477 tmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
);
2480 } while ((tmp
!= 0) && (count
< 100));
2481 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2482 "Wait Tx DMA Finished before host sleep. count=%d\n",
2485 if (rtlhal
->hw_rof_enable
) {
2486 printk("hw_rof_enable\n");
2487 tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
+ 3);
2488 rtl_write_byte(rtlpriv
, REG_HSISR
+ 3, tmp
| BIT(1));
2491 /* after power off we should do iqk again */
2492 rtlpriv
->phy
.iqk_initialized
= false;
2495 void rtl8821ae_interrupt_recognized(struct ieee80211_hw
*hw
,
2496 u32
*p_inta
, u32
*p_intb
)
2498 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2499 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2501 *p_inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
2502 rtl_write_dword(rtlpriv
, ISR
, *p_inta
);
2504 *p_intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) & rtlpci
->irq_mask
[1];
2505 rtl_write_dword(rtlpriv
, REG_HISRE
, *p_intb
);
2508 void rtl8821ae_set_beacon_related_registers(struct ieee80211_hw
*hw
)
2510 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2511 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2512 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2513 u16 bcn_interval
, atim_window
;
2515 bcn_interval
= mac
->beacon_interval
;
2516 atim_window
= 2; /*FIX MERGE */
2517 rtl8821ae_disable_interrupt(hw
);
2518 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
2519 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
2520 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
2521 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
2522 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
2523 rtl_write_byte(rtlpriv
, 0x606, 0x30);
2524 rtlpci
->reg_bcn_ctrl_val
|= BIT(3);
2525 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
2526 rtl8821ae_enable_interrupt(hw
);
2529 void rtl8821ae_set_beacon_interval(struct ieee80211_hw
*hw
)
2531 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2532 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2533 u16 bcn_interval
= mac
->beacon_interval
;
2535 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
2536 "beacon_interval:%d\n", bcn_interval
);
2537 rtl8821ae_disable_interrupt(hw
);
2538 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
2539 rtl8821ae_enable_interrupt(hw
);
2542 void rtl8821ae_update_interrupt_mask(struct ieee80211_hw
*hw
,
2543 u32 add_msr
, u32 rm_msr
)
2545 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2546 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2548 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
2549 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
2552 rtlpci
->irq_mask
[0] |= add_msr
;
2554 rtlpci
->irq_mask
[0] &= (~rm_msr
);
2555 rtl8821ae_disable_interrupt(hw
);
2556 rtl8821ae_enable_interrupt(hw
);
2559 static u8
_rtl8821ae_get_chnl_group(u8 chnl
)
2564 if (1 <= chnl
&& chnl
<= 2)
2566 else if (3 <= chnl
&& chnl
<= 5)
2568 else if (6 <= chnl
&& chnl
<= 8)
2570 else if (9 <= chnl
&& chnl
<= 11)
2572 else /*if (12 <= chnl && chnl <= 14)*/
2575 if (36 <= chnl
&& chnl
<= 42)
2577 else if (44 <= chnl
&& chnl
<= 48)
2579 else if (50 <= chnl
&& chnl
<= 58)
2581 else if (60 <= chnl
&& chnl
<= 64)
2583 else if (100 <= chnl
&& chnl
<= 106)
2585 else if (108 <= chnl
&& chnl
<= 114)
2587 else if (116 <= chnl
&& chnl
<= 122)
2589 else if (124 <= chnl
&& chnl
<= 130)
2591 else if (132 <= chnl
&& chnl
<= 138)
2593 else if (140 <= chnl
&& chnl
<= 144)
2595 else if (149 <= chnl
&& chnl
<= 155)
2597 else if (157 <= chnl
&& chnl
<= 161)
2599 else if (165 <= chnl
&& chnl
<= 171)
2601 else if (173 <= chnl
&& chnl
<= 177)
2604 /*RT_TRACE(rtlpriv, COMP_EFUSE,DBG_LOUD,
2605 "5G, Channel %d in Group not found\n",chnl);*/
2606 RT_ASSERT(!COMP_EFUSE
,
2607 "5G, Channel %d in Group not found\n", chnl
);
2612 static void _rtl8821ae_read_power_value_fromprom(struct ieee80211_hw
*hw
,
2613 struct txpower_info_2g
*pwrinfo24g
,
2614 struct txpower_info_5g
*pwrinfo5g
,
2618 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2619 u32 rfPath
, eeAddr
= EEPROM_TX_PWR_INX
, group
, TxCount
= 0;
2621 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2622 "hal_ReadPowerValueFromPROM8821ae(): hwinfo[0x%x]=0x%x\n",
2623 (eeAddr
+1), hwinfo
[eeAddr
+1]);
2624 if (0xFF == hwinfo
[eeAddr
+1]) /*YJ,add,120316*/
2625 autoload_fail
= true;
2627 if (autoload_fail
) {
2628 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2629 "auto load fail : Use Default value!\n");
2630 for (rfPath
= 0 ; rfPath
< MAX_RF_PATH
; rfPath
++) {
2631 /*2.4G default value*/
2632 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
2633 pwrinfo24g
->index_cck_base
[rfPath
][group
] = 0x2D;
2634 pwrinfo24g
->index_bw40_base
[rfPath
][group
] = 0x2D;
2636 for (TxCount
= 0; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2638 pwrinfo24g
->bw20_diff
[rfPath
][0] = 0x02;
2639 pwrinfo24g
->ofdm_diff
[rfPath
][0] = 0x04;
2641 pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] = 0xFE;
2642 pwrinfo24g
->bw40_diff
[rfPath
][TxCount
] = 0xFE;
2643 pwrinfo24g
->cck_diff
[rfPath
][TxCount
] = 0xFE;
2644 pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] = 0xFE;
2647 /*5G default value*/
2648 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++)
2649 pwrinfo5g
->index_bw40_base
[rfPath
][group
] = 0x2A;
2651 for (TxCount
= 0; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2653 pwrinfo5g
->ofdm_diff
[rfPath
][0] = 0x04;
2654 pwrinfo5g
->bw20_diff
[rfPath
][0] = 0x00;
2655 pwrinfo5g
->bw80_diff
[rfPath
][0] = 0xFE;
2656 pwrinfo5g
->bw160_diff
[rfPath
][0] = 0xFE;
2658 pwrinfo5g
->ofdm_diff
[rfPath
][0] = 0xFE;
2659 pwrinfo5g
->bw20_diff
[rfPath
][0] = 0xFE;
2660 pwrinfo5g
->bw40_diff
[rfPath
][0] = 0xFE;
2661 pwrinfo5g
->bw80_diff
[rfPath
][0] = 0xFE;
2662 pwrinfo5g
->bw160_diff
[rfPath
][0] = 0xFE;
2669 rtl_priv(hw
)->efuse
.txpwr_fromeprom
= true;
2671 for (rfPath
= 0 ; rfPath
< MAX_RF_PATH
; rfPath
++) {
2672 /*2.4G default value*/
2673 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
2674 pwrinfo24g
->index_cck_base
[rfPath
][group
] = hwinfo
[eeAddr
++];
2675 if (pwrinfo24g
->index_cck_base
[rfPath
][group
] == 0xFF)
2676 pwrinfo24g
->index_cck_base
[rfPath
][group
] = 0x2D;
2678 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
- 1; group
++) {
2679 pwrinfo24g
->index_bw40_base
[rfPath
][group
] = hwinfo
[eeAddr
++];
2680 if (pwrinfo24g
->index_bw40_base
[rfPath
][group
] == 0xFF)
2681 pwrinfo24g
->index_bw40_base
[rfPath
][group
] = 0x2D;
2683 for (TxCount
= 0; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2685 pwrinfo24g
->bw40_diff
[rfPath
][TxCount
] = 0;
2686 /*bit sign number to 8 bit sign number*/
2687 pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2688 if (pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] & BIT(3))
2689 pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] |= 0xF0;
2690 /*bit sign number to 8 bit sign number*/
2691 pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0x0f);
2692 if (pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] & BIT(3))
2693 pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] |= 0xF0;
2695 pwrinfo24g
->cck_diff
[rfPath
][TxCount
] = 0;
2698 pwrinfo24g
->bw40_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
]&0xf0) >> 4;
2699 if (pwrinfo24g
->bw40_diff
[rfPath
][TxCount
] & BIT(3))
2700 pwrinfo24g
->bw40_diff
[rfPath
][TxCount
] |= 0xF0;
2702 pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0x0f);
2703 if (pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] & BIT(3))
2704 pwrinfo24g
->bw20_diff
[rfPath
][TxCount
] |= 0xF0;
2708 pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2709 if (pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] & BIT(3))
2710 pwrinfo24g
->ofdm_diff
[rfPath
][TxCount
] |= 0xF0;
2712 pwrinfo24g
->cck_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0x0f);
2713 if (pwrinfo24g
->cck_diff
[rfPath
][TxCount
] & BIT(3))
2714 pwrinfo24g
->cck_diff
[rfPath
][TxCount
] |= 0xF0;
2720 /*5G default value*/
2721 for (group
= 0 ; group
< MAX_CHNL_GROUP_5G
; group
++) {
2722 pwrinfo5g
->index_bw40_base
[rfPath
][group
] = hwinfo
[eeAddr
++];
2723 if (pwrinfo5g
->index_bw40_base
[rfPath
][group
] == 0xFF)
2724 pwrinfo5g
->index_bw40_base
[rfPath
][group
] = 0xFE;
2727 for (TxCount
= 0; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2729 pwrinfo5g
->bw40_diff
[rfPath
][TxCount
] = 0;
2731 pwrinfo5g
->bw20_diff
[rfPath
][0] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2732 if (pwrinfo5g
->bw20_diff
[rfPath
][TxCount
] & BIT(3))
2733 pwrinfo5g
->bw20_diff
[rfPath
][TxCount
] |= 0xF0;
2735 pwrinfo5g
->ofdm_diff
[rfPath
][0] = (hwinfo
[eeAddr
] & 0x0f);
2736 if (pwrinfo5g
->ofdm_diff
[rfPath
][TxCount
] & BIT(3))
2737 pwrinfo5g
->ofdm_diff
[rfPath
][TxCount
] |= 0xF0;
2741 pwrinfo5g
->bw40_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2742 if (pwrinfo5g
->bw40_diff
[rfPath
][TxCount
] & BIT(3))
2743 pwrinfo5g
->bw40_diff
[rfPath
][TxCount
] |= 0xF0;
2745 pwrinfo5g
->bw20_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0x0f);
2746 if (pwrinfo5g
->bw20_diff
[rfPath
][TxCount
] & BIT(3))
2747 pwrinfo5g
->bw20_diff
[rfPath
][TxCount
] |= 0xF0;
2753 pwrinfo5g
->ofdm_diff
[rfPath
][1] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2754 pwrinfo5g
->ofdm_diff
[rfPath
][2] = (hwinfo
[eeAddr
] & 0x0f);
2758 pwrinfo5g
->ofdm_diff
[rfPath
][3] = (hwinfo
[eeAddr
] & 0x0f);
2762 for (TxCount
= 1; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2763 if (pwrinfo5g
->ofdm_diff
[rfPath
][TxCount
] & BIT(3))
2764 pwrinfo5g
->ofdm_diff
[rfPath
][TxCount
] |= 0xF0;
2766 for (TxCount
= 0; TxCount
< MAX_TX_COUNT
; TxCount
++) {
2767 pwrinfo5g
->bw80_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0xf0) >> 4;
2768 /* 4bit sign number to 8 bit sign number */
2769 if (pwrinfo5g
->bw80_diff
[rfPath
][TxCount
] & BIT(3))
2770 pwrinfo5g
->bw80_diff
[rfPath
][TxCount
] |= 0xF0;
2771 /* 4bit sign number to 8 bit sign number */
2772 pwrinfo5g
->bw160_diff
[rfPath
][TxCount
] = (hwinfo
[eeAddr
] & 0x0f);
2773 if (pwrinfo5g
->bw160_diff
[rfPath
][TxCount
] & BIT(3))
2774 pwrinfo5g
->bw160_diff
[rfPath
][TxCount
] |= 0xF0;
2781 static void _rtl8812ae_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
2785 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2786 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2787 struct txpower_info_2g pwrinfo24g
;
2788 struct txpower_info_5g pwrinfo5g
;
2792 _rtl8821ae_read_power_value_fromprom(hw
, &pwrinfo24g
,
2793 &pwrinfo5g
, autoload_fail
, hwinfo
);
2795 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
2796 for (i
= 0; i
< CHANNEL_MAX_NUMBER_2G
; i
++) {
2797 index
= _rtl8821ae_get_chnl_group(i
+ 1);
2799 if (i
== CHANNEL_MAX_NUMBER_2G
- 1) {
2800 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2801 pwrinfo24g
.index_cck_base
[rf_path
][5];
2802 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2803 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2805 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2806 pwrinfo24g
.index_cck_base
[rf_path
][index
];
2807 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2808 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2812 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G
; i
++) {
2813 index
= _rtl8821ae_get_chnl_group(channel5g
[i
]);
2814 rtlefuse
->txpwr_5g_bw40base
[rf_path
][i
] =
2815 pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2817 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G_80M
; i
++) {
2819 index
= _rtl8821ae_get_chnl_group(channel5g_80m
[i
]);
2820 upper
= pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2821 lower
= pwrinfo5g
.index_bw40_base
[rf_path
][index
+ 1];
2823 rtlefuse
->txpwr_5g_bw80base
[rf_path
][i
] = (upper
+ lower
) / 2;
2825 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
2826 rtlefuse
->txpwr_cckdiff
[rf_path
][i
] =
2827 pwrinfo24g
.cck_diff
[rf_path
][i
];
2828 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
2829 pwrinfo24g
.ofdm_diff
[rf_path
][i
];
2830 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
2831 pwrinfo24g
.bw20_diff
[rf_path
][i
];
2832 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
2833 pwrinfo24g
.bw40_diff
[rf_path
][i
];
2835 rtlefuse
->txpwr_5g_ofdmdiff
[rf_path
][i
] =
2836 pwrinfo5g
.ofdm_diff
[rf_path
][i
];
2837 rtlefuse
->txpwr_5g_bw20diff
[rf_path
][i
] =
2838 pwrinfo5g
.bw20_diff
[rf_path
][i
];
2839 rtlefuse
->txpwr_5g_bw40diff
[rf_path
][i
] =
2840 pwrinfo5g
.bw40_diff
[rf_path
][i
];
2841 rtlefuse
->txpwr_5g_bw80diff
[rf_path
][i
] =
2842 pwrinfo5g
.bw80_diff
[rf_path
][i
];
2846 if (!autoload_fail
) {
2847 rtlefuse
->eeprom_regulatory
=
2848 hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x07;/*bit0~2*/
2849 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xFF)
2850 rtlefuse
->eeprom_regulatory
= 0;
2852 rtlefuse
->eeprom_regulatory
= 0;
2855 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2856 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2859 static void _rtl8821ae_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
2863 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2864 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2865 struct txpower_info_2g pwrinfo24g
;
2866 struct txpower_info_5g pwrinfo5g
;
2870 _rtl8821ae_read_power_value_fromprom(hw
, &pwrinfo24g
,
2871 &pwrinfo5g
, autoload_fail
, hwinfo
);
2873 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
2874 for (i
= 0; i
< CHANNEL_MAX_NUMBER_2G
; i
++) {
2875 index
= _rtl8821ae_get_chnl_group(i
+ 1);
2877 if (i
== CHANNEL_MAX_NUMBER_2G
- 1) {
2878 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2879 pwrinfo24g
.index_cck_base
[rf_path
][5];
2880 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2881 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2883 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
2884 pwrinfo24g
.index_cck_base
[rf_path
][index
];
2885 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
2886 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
2890 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G
; i
++) {
2891 index
= _rtl8821ae_get_chnl_group(channel5g
[i
]);
2892 rtlefuse
->txpwr_5g_bw40base
[rf_path
][i
] =
2893 pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2895 for (i
= 0; i
< CHANNEL_MAX_NUMBER_5G_80M
; i
++) {
2897 index
= _rtl8821ae_get_chnl_group(channel5g_80m
[i
]);
2898 upper
= pwrinfo5g
.index_bw40_base
[rf_path
][index
];
2899 lower
= pwrinfo5g
.index_bw40_base
[rf_path
][index
+ 1];
2901 rtlefuse
->txpwr_5g_bw80base
[rf_path
][i
] = (upper
+ lower
) / 2;
2903 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
2904 rtlefuse
->txpwr_cckdiff
[rf_path
][i
] =
2905 pwrinfo24g
.cck_diff
[rf_path
][i
];
2906 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
2907 pwrinfo24g
.ofdm_diff
[rf_path
][i
];
2908 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
2909 pwrinfo24g
.bw20_diff
[rf_path
][i
];
2910 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
2911 pwrinfo24g
.bw40_diff
[rf_path
][i
];
2913 rtlefuse
->txpwr_5g_ofdmdiff
[rf_path
][i
] =
2914 pwrinfo5g
.ofdm_diff
[rf_path
][i
];
2915 rtlefuse
->txpwr_5g_bw20diff
[rf_path
][i
] =
2916 pwrinfo5g
.bw20_diff
[rf_path
][i
];
2917 rtlefuse
->txpwr_5g_bw40diff
[rf_path
][i
] =
2918 pwrinfo5g
.bw40_diff
[rf_path
][i
];
2919 rtlefuse
->txpwr_5g_bw80diff
[rf_path
][i
] =
2920 pwrinfo5g
.bw80_diff
[rf_path
][i
];
2924 if (!autoload_fail
) {
2925 rtlefuse
->eeprom_regulatory
= hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x07;
2926 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xFF)
2927 rtlefuse
->eeprom_regulatory
= 0;
2929 rtlefuse
->eeprom_regulatory
= 0;
2932 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2933 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2936 static void _rtl8812ae_read_pa_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
2939 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2940 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2942 if (!autoload_fail
) {
2943 rtlhal
->pa_type_2g
= hwinfo
[0xBC];
2944 rtlhal
->lna_type_2g
= hwinfo
[0xBD];
2945 if (rtlhal
->pa_type_2g
== 0xFF && rtlhal
->lna_type_2g
== 0xFF) {
2946 rtlhal
->pa_type_2g
= 0;
2947 rtlhal
->lna_type_2g
= 0;
2949 rtlhal
->external_pa_2g
= ((rtlhal
->pa_type_2g
& BIT(5)) &&
2950 (rtlhal
->pa_type_2g
& BIT(4))) ?
2952 rtlhal
->external_lna_2g
= ((rtlhal
->lna_type_2g
& BIT(7)) &&
2953 (rtlhal
->lna_type_2g
& BIT(3))) ?
2956 rtlhal
->pa_type_5g
= hwinfo
[0xBC];
2957 rtlhal
->lna_type_5g
= hwinfo
[0xBF];
2958 if (rtlhal
->pa_type_5g
== 0xFF && rtlhal
->lna_type_5g
== 0xFF) {
2959 rtlhal
->pa_type_5g
= 0;
2960 rtlhal
->lna_type_5g
= 0;
2962 rtlhal
->external_pa_5g
= ((rtlhal
->pa_type_5g
& BIT(1)) &&
2963 (rtlhal
->pa_type_5g
& BIT(0))) ?
2965 rtlhal
->external_lna_5g
= ((rtlhal
->lna_type_5g
& BIT(7)) &&
2966 (rtlhal
->lna_type_5g
& BIT(3))) ?
2969 rtlhal
->external_pa_2g
= 0;
2970 rtlhal
->external_lna_2g
= 0;
2971 rtlhal
->external_pa_5g
= 0;
2972 rtlhal
->external_lna_5g
= 0;
2976 static void _rtl8821ae_read_pa_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
2979 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2980 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
2982 if (!autoload_fail
) {
2983 rtlhal
->pa_type_2g
= hwinfo
[0xBC];
2984 rtlhal
->lna_type_2g
= hwinfo
[0xBD];
2985 if (rtlhal
->pa_type_2g
== 0xFF && rtlhal
->lna_type_2g
== 0xFF) {
2986 rtlhal
->pa_type_2g
= 0;
2987 rtlhal
->lna_type_2g
= 0;
2989 rtlhal
->external_pa_2g
= (rtlhal
->pa_type_2g
& BIT(5)) ? 1 : 0;
2990 rtlhal
->external_lna_2g
= (rtlhal
->lna_type_2g
& BIT(7)) ? 1 : 0;
2992 rtlhal
->pa_type_5g
= hwinfo
[0xBC];
2993 rtlhal
->lna_type_5g
= hwinfo
[0xBF];
2994 if (rtlhal
->pa_type_5g
== 0xFF && rtlhal
->lna_type_5g
== 0xFF) {
2995 rtlhal
->pa_type_5g
= 0;
2996 rtlhal
->lna_type_5g
= 0;
2998 rtlhal
->external_pa_5g
= (rtlhal
->pa_type_5g
& BIT(1)) ? 1 : 0;
2999 rtlhal
->external_lna_5g
= (rtlhal
->lna_type_5g
& BIT(7)) ? 1 : 0;
3001 rtlhal
->external_pa_2g
= 0;
3002 rtlhal
->external_lna_2g
= 0;
3003 rtlhal
->external_pa_5g
= 0;
3004 rtlhal
->external_lna_5g
= 0;
3008 static void _rtl8821ae_read_rfe_type(struct ieee80211_hw
*hw
, u8
*hwinfo
,
3011 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3012 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
3014 if (!autoload_fail
) {
3015 if (hwinfo
[EEPROM_RFE_OPTION
] & BIT(7)) {
3016 if (rtlhal
->external_lna_5g
) {
3017 if (rtlhal
->external_pa_5g
) {
3018 if (rtlhal
->external_lna_2g
&&
3019 rtlhal
->external_pa_2g
)
3020 rtlhal
->rfe_type
= 3;
3022 rtlhal
->rfe_type
= 0;
3024 rtlhal
->rfe_type
= 2;
3027 rtlhal
->rfe_type
= 4;
3030 rtlhal
->rfe_type
= hwinfo
[EEPROM_RFE_OPTION
] & 0x3F;
3032 if (rtlhal
->rfe_type
== 4 &&
3033 (rtlhal
->external_pa_5g
||
3034 rtlhal
->external_pa_2g
||
3035 rtlhal
->external_lna_5g
||
3036 rtlhal
->external_lna_2g
)) {
3037 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
)
3038 rtlhal
->rfe_type
= 2;
3042 rtlhal
->rfe_type
= 0x04;
3045 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3046 "RFE Type: 0x%2x\n", rtlhal
->rfe_type
);
3049 static void _rtl8812ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
3050 bool auto_load_fail
, u8
*hwinfo
)
3052 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3055 if (!auto_load_fail
) {
3056 value
= *(u8
*)&hwinfo
[EEPROM_RF_BOARD_OPTION
];
3057 if (((value
& 0xe0) >> 5) == 0x1)
3058 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
3060 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3061 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8812A
;
3063 value
= hwinfo
[EEPROM_RF_BT_SETTING
];
3064 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
3066 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3067 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8812A
;
3068 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
3070 /*move BT_InitHalVars() to init_sw_vars*/
3073 static void _rtl8821ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
3074 bool auto_load_fail
, u8
*hwinfo
)
3076 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3080 if (!auto_load_fail
) {
3081 tmpu_32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
3082 if (tmpu_32
& BIT(18))
3083 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
3085 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3086 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8821A
;
3088 value
= hwinfo
[EEPROM_RF_BT_SETTING
];
3089 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
3091 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
3092 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8821A
;
3093 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
3095 /*move BT_InitHalVars() to init_sw_vars*/
3098 static void _rtl8821ae_read_adapter_info(struct ieee80211_hw
*hw
, bool b_pseudo_test
)
3100 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3101 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3102 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3103 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
3105 u8 hwinfo
[HWSET_MAX_SIZE
];
3108 if (b_pseudo_test
) {
3112 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
3113 rtl_efuse_shadow_map_update(hw
);
3114 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
3116 } else if (rtlefuse
->epromtype
== EEPROM_93C46
) {
3117 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3118 "RTL819X Not boot from eeprom, check it !!");
3121 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP\n",
3122 hwinfo
, HWSET_MAX_SIZE
);
3124 eeprom_id
= *((u16
*)&hwinfo
[0]);
3125 if (eeprom_id
!= RTL_EEPROM_ID
) {
3126 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
3127 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
3128 rtlefuse
->autoload_failflag
= true;
3130 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
3131 rtlefuse
->autoload_failflag
= false;
3134 if (rtlefuse
->autoload_failflag
) {
3135 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
3136 "RTL8812AE autoload_failflag, check it !!");
3140 rtlefuse
->eeprom_version
= *(u8
*)&hwinfo
[EEPROM_VERSION
];
3141 if (rtlefuse
->eeprom_version
== 0xff)
3142 rtlefuse
->eeprom_version
= 0;
3144 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3145 "EEPROM version: 0x%2x\n", rtlefuse
->eeprom_version
);
3147 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
3148 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
3149 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[EEPROM_SVID
];
3150 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[EEPROM_SMID
];
3151 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3152 "EEPROMId = 0x%4x\n", eeprom_id
);
3153 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3154 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
3155 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3156 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
3157 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3158 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
3159 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3160 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
3163 rtlefuse
->eeprom_oemid
= *(u8
*)&hwinfo
[EEPROM_CUSTOMER_ID
];
3164 if (rtlefuse
->eeprom_oemid
== 0xFF)
3165 rtlefuse
->eeprom_oemid
= 0;
3167 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3168 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
3170 for (i
= 0; i
< 6; i
+= 2) {
3171 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
3172 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
3175 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
3176 "dev_addr: %pM\n", rtlefuse
->dev_addr
);
3178 _rtl8821ae_read_txpower_info_from_hwpg(hw
, rtlefuse
->autoload_failflag
,
3181 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
3182 _rtl8812ae_read_pa_type(hw
, hwinfo
, rtlefuse
->autoload_failflag
);
3183 _rtl8812ae_read_bt_coexist_info_from_hwpg(hw
,
3184 rtlefuse
->autoload_failflag
, hwinfo
);
3186 _rtl8821ae_read_pa_type(hw
, hwinfo
, rtlefuse
->autoload_failflag
);
3187 _rtl8821ae_read_bt_coexist_info_from_hwpg(hw
,
3188 rtlefuse
->autoload_failflag
, hwinfo
);
3191 _rtl8821ae_read_rfe_type(hw
, hwinfo
, rtlefuse
->autoload_failflag
);
3193 rtlefuse
->board_type
= ODM_BOARD_DEFAULT
;
3194 if (rtlhal
->external_lna_2g
!= 0)
3195 rtlefuse
->board_type
|= ODM_BOARD_EXT_LNA
;
3196 if (rtlhal
->external_lna_5g
!= 0)
3197 rtlefuse
->board_type
|= ODM_BOARD_EXT_LNA_5G
;
3198 if (rtlhal
->external_pa_2g
!= 0)
3199 rtlefuse
->board_type
|= ODM_BOARD_EXT_PA
;
3200 if (rtlhal
->external_pa_5g
!= 0)
3201 rtlefuse
->board_type
|= ODM_BOARD_EXT_PA_5G
;
3203 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1)
3204 rtlefuse
->board_type
|= ODM_BOARD_BT
;
3206 rtlhal
->board_type
= rtlefuse
->board_type
;
3207 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3208 "board_type = 0x%x\n", rtlefuse
->board_type
);
3210 rtlefuse
->eeprom_channelplan
= *(u8
*)&hwinfo
[EEPROM_CHANNELPLAN
];
3211 if (rtlefuse
->eeprom_channelplan
== 0xff)
3212 rtlefuse
->eeprom_channelplan
= 0x7F;
3214 /* set channel plan from efuse */
3215 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
3218 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_8821AE
];
3219 if (rtlefuse
->crystalcap
== 0xFF)
3220 rtlefuse
->crystalcap
= 0x20;
3222 rtlefuse
->eeprom_thermalmeter
= *(u8
*)&hwinfo
[EEPROM_THERMAL_METER
];
3223 if ((rtlefuse
->eeprom_thermalmeter
== 0xff) ||
3224 rtlefuse
->autoload_failflag
) {
3225 rtlefuse
->apk_thermalmeterignore
= true;
3226 rtlefuse
->eeprom_thermalmeter
= 0xff;
3229 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
3230 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3231 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
3233 if (!rtlefuse
->autoload_failflag
) {
3234 rtlefuse
->antenna_div_cfg
=
3235 (hwinfo
[EEPROM_RF_BOARD_OPTION
] & 0x18) >> 3;
3236 if (hwinfo
[EEPROM_RF_BOARD_OPTION
] == 0xff)
3237 rtlefuse
->antenna_div_cfg
= 0;
3239 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1 &&
3240 rtlpriv
->btcoexist
.btc_info
.ant_num
== ANT_X1
)
3241 rtlefuse
->antenna_div_cfg
= 0;
3243 rtlefuse
->antenna_div_type
= hwinfo
[EEPROM_RF_ANTENNA_OPT_88E
];
3244 if (rtlefuse
->antenna_div_type
== 0xff)
3245 rtlefuse
->antenna_div_type
= FIXED_HW_ANTDIV
;
3247 rtlefuse
->antenna_div_cfg
= 0;
3248 rtlefuse
->antenna_div_type
= 0;
3251 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
3252 "SWAS: bHwAntDiv = %x, TRxAntDivType = %x\n",
3253 rtlefuse
->antenna_div_cfg
, rtlefuse
->antenna_div_type
);
3255 pcipriv
->ledctl
.led_opendrain
= true;
3257 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
3258 switch (rtlefuse
->eeprom_oemid
) {
3259 case RT_CID_DEFAULT
:
3261 case EEPROM_CID_TOSHIBA
:
3262 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
3264 case EEPROM_CID_CCX
:
3265 rtlhal
->oem_id
= RT_CID_CCX
;
3267 case EEPROM_CID_QMI
:
3268 rtlhal
->oem_id
= RT_CID_819X_QMI
;
3270 case EEPROM_CID_WHQL
:
3278 /*static void _rtl8821ae_hal_customized_behavior(struct ieee80211_hw *hw)
3280 struct rtl_priv *rtlpriv = rtl_priv(hw);
3281 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
3282 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3284 pcipriv->ledctl.led_opendrain = true;
3285 switch (rtlhal->oem_id) {
3286 case RT_CID_819X_HP:
3287 pcipriv->ledctl.led_opendrain = true;
3289 case RT_CID_819X_LENOVO:
3290 case RT_CID_DEFAULT:
3291 case RT_CID_TOSHIBA:
3293 case RT_CID_819X_ACER:
3298 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3299 "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
3302 void rtl8821ae_read_eeprom_info(struct ieee80211_hw
*hw
)
3304 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3305 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3306 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3307 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3310 rtlhal
->version
= _rtl8821ae_read_chip_version(hw
);
3311 if (get_rf_type(rtlphy
) == RF_1T1R
)
3312 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
3314 rtlpriv
->dm
.rfpath_rxenable
[0] =
3315 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
3316 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
3319 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
3320 if (tmp_u1b
& BIT(4)) {
3321 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
3322 rtlefuse
->epromtype
= EEPROM_93C46
;
3324 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
3325 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
3328 if (tmp_u1b
& BIT(5)) {
3329 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
3330 rtlefuse
->autoload_failflag
= false;
3331 _rtl8821ae_read_adapter_info(hw
, false);
3333 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Autoload ERR!!\n");
3335 /*hal_ReadRFType_8812A()*/
3336 /* _rtl8821ae_hal_customized_behavior(hw); */
3339 static void rtl8821ae_update_hal_rate_table(struct ieee80211_hw
*hw
,
3340 struct ieee80211_sta
*sta
)
3342 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3343 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3344 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3345 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
3348 u8 b_nmode
= mac
->ht_enable
;
3349 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
3352 u8 curtxbw_40mhz
= mac
->bw_40
;
3353 u8 b_curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
3355 u8 b_curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
3357 enum wireless_mode wirelessmode
= mac
->mode
;
3359 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
3360 ratr_value
= sta
->supp_rates
[1] << 4;
3362 ratr_value
= sta
->supp_rates
[0];
3363 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3365 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
3366 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
3367 switch (wirelessmode
) {
3368 case WIRELESS_MODE_B
:
3369 if (ratr_value
& 0x0000000c)
3370 ratr_value
&= 0x0000000d;
3372 ratr_value
&= 0x0000000f;
3374 case WIRELESS_MODE_G
:
3375 ratr_value
&= 0x00000FF5;
3377 case WIRELESS_MODE_N_24G
:
3378 case WIRELESS_MODE_N_5G
:
3380 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
3381 ratr_value
&= 0x0007F005;
3385 if (get_rf_type(rtlphy
) == RF_1T2R
||
3386 get_rf_type(rtlphy
) == RF_1T1R
)
3387 ratr_mask
= 0x000ff005;
3389 ratr_mask
= 0x0f0ff005;
3391 ratr_value
&= ratr_mask
;
3395 if (rtlphy
->rf_type
== RF_1T2R
)
3396 ratr_value
&= 0x000ff0ff;
3398 ratr_value
&= 0x0f0ff0ff;
3403 if ((rtlpriv
->btcoexist
.bt_coexistence
) &&
3404 (rtlpriv
->btcoexist
.bt_coexist_type
== BT_CSR_BC4
) &&
3405 (rtlpriv
->btcoexist
.bt_cur_state
) &&
3406 (rtlpriv
->btcoexist
.bt_ant_isolation
) &&
3407 ((rtlpriv
->btcoexist
.bt_service
== BT_SCO
) ||
3408 (rtlpriv
->btcoexist
.bt_service
== BT_BUSY
)))
3409 ratr_value
&= 0x0fffcfc0;
3411 ratr_value
&= 0x0FFFFFFF;
3413 if (b_nmode
&& ((curtxbw_40mhz
&&
3414 b_curshortgi_40mhz
) || (!curtxbw_40mhz
&&
3415 b_curshortgi_20mhz
))) {
3416 ratr_value
|= 0x10000000;
3417 tmp_ratr_value
= (ratr_value
>> 12);
3419 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
3420 if ((1 << shortgi_rate
) & tmp_ratr_value
)
3424 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
3425 (shortgi_rate
<< 4) | (shortgi_rate
);
3428 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
3430 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
3431 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
3434 static u8
_rtl8821ae_mrate_idx_to_arfr_id(
3435 struct ieee80211_hw
*hw
, u8 rate_index
,
3436 enum wireless_mode wirelessmode
)
3438 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3439 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3441 switch (rate_index
) {
3442 case RATR_INX_WIRELESS_NGB
:
3443 if (rtlphy
->rf_type
== RF_1T1R
)
3448 case RATR_INX_WIRELESS_N
:
3449 case RATR_INX_WIRELESS_NG
:
3450 if (rtlphy
->rf_type
== RF_1T1R
)
3455 case RATR_INX_WIRELESS_NB
:
3456 if (rtlphy
->rf_type
== RF_1T1R
)
3461 case RATR_INX_WIRELESS_GB
:
3464 case RATR_INX_WIRELESS_G
:
3467 case RATR_INX_WIRELESS_B
:
3470 case RATR_INX_WIRELESS_MC
:
3471 if ((wirelessmode
== WIRELESS_MODE_B
)
3472 || (wirelessmode
== WIRELESS_MODE_G
)
3473 || (wirelessmode
== WIRELESS_MODE_N_24G
)
3474 || (wirelessmode
== WIRELESS_MODE_AC_24G
))
3478 case RATR_INX_WIRELESS_AC_5N
:
3479 if (rtlphy
->rf_type
== RF_1T1R
)
3484 case RATR_INX_WIRELESS_AC_24N
:
3485 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
3486 if (rtlphy
->rf_type
== RF_1T1R
)
3491 if (rtlphy
->rf_type
== RF_1T1R
)
3503 static u32
_rtl8821ae_rate_to_bitmap_2ssvht(__le16 vht_rate
)
3506 u32 rate_bitmap
= 0;
3508 for (i
= j
= 0; i
< 4; i
+= 2, j
+= 10) {
3509 tmp_rate
= (le16_to_cpu(vht_rate
) >> i
) & 3;
3513 rate_bitmap
= rate_bitmap
| (0x03ff << j
);
3516 rate_bitmap
= rate_bitmap
| (0x01ff << j
);
3519 rate_bitmap
= rate_bitmap
| (0x00ff << j
);
3529 static u32
_rtl8821ae_set_ra_vht_ratr_bitmap(struct ieee80211_hw
*hw
,
3530 enum wireless_mode wirelessmode
,
3533 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3534 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3535 u32 ret_bitmap
= ratr_bitmap
;
3537 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
3538 || rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
)
3539 ret_bitmap
= ratr_bitmap
;
3540 else if (wirelessmode
== WIRELESS_MODE_AC_5G
3541 || wirelessmode
== WIRELESS_MODE_AC_24G
) {
3542 if (rtlphy
->rf_type
== RF_1T1R
)
3543 ret_bitmap
= ratr_bitmap
& (~BIT21
);
3545 ret_bitmap
= ratr_bitmap
& (~(BIT31
|BIT21
));
3551 static u8
_rtl8821ae_get_vht_eni(enum wireless_mode wirelessmode
,
3555 if (wirelessmode
< WIRELESS_MODE_N_24G
)
3557 else if (wirelessmode
== WIRELESS_MODE_AC_24G
) {
3558 if (ratr_bitmap
& 0xfff00000) /* Mix , 2SS */
3562 } else if (wirelessmode
== WIRELESS_MODE_AC_5G
) {
3569 static u8
_rtl8821ae_get_ra_ldpc(struct ieee80211_hw
*hw
,
3570 u8 mac_id
, struct rtl_sta_info
*sta_entry
,
3571 enum wireless_mode wirelessmode
)
3574 /*not support ldpc, do not open*/
3578 static u8
_rtl8821ae_get_ra_rftype(struct ieee80211_hw
*hw
,
3579 enum wireless_mode wirelessmode
,
3582 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3583 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3584 u8 rf_type
= RF_1T1R
;
3586 if (rtlphy
->rf_type
== RF_1T1R
)
3588 else if (wirelessmode
== WIRELESS_MODE_AC_5G
3589 || wirelessmode
== WIRELESS_MODE_AC_24G
3590 || wirelessmode
== WIRELESS_MODE_AC_ONLY
) {
3591 if (ratr_bitmap
& 0xffc00000)
3593 } else if (wirelessmode
== WIRELESS_MODE_N_5G
3594 || wirelessmode
== WIRELESS_MODE_N_24G
) {
3595 if (ratr_bitmap
& 0xfff00000)
3602 static bool _rtl8821ae_get_ra_shortgi(struct ieee80211_hw
*hw
, struct ieee80211_sta
*sta
,
3605 bool b_short_gi
= false;
3606 u8 b_curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
3608 u8 b_curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
3610 u8 b_curshortgi_80mhz
= 0;
3611 b_curshortgi_80mhz
= (sta
->vht_cap
.cap
&
3612 IEEE80211_VHT_CAP_SHORT_GI_80
) ? 1 : 0;
3614 if (mac_id
== MAC_ID_STATIC_FOR_BROADCAST_MULTICAST
)
3617 if (b_curshortgi_40mhz
|| b_curshortgi_80mhz
3618 || b_curshortgi_20mhz
)
3624 static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw
*hw
,
3625 struct ieee80211_sta
*sta
, u8 rssi_level
)
3627 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3628 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3629 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3630 struct rtl_sta_info
*sta_entry
= NULL
;
3633 enum wireless_mode wirelessmode
= 0;
3634 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)
3636 bool b_shortgi
= false;
3639 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
3642 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
3643 wirelessmode
= sta_entry
->wireless_mode
;
3645 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_LOUD
,
3646 "wireless mode = 0x%x\n", wirelessmode
);
3647 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
3648 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
3649 curtxbw_40mhz
= mac
->bw_40
;
3650 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
3651 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3652 macid
= sta
->aid
+ 1;
3653 if (wirelessmode
== WIRELESS_MODE_N_5G
||
3654 wirelessmode
== WIRELESS_MODE_AC_5G
||
3655 wirelessmode
== WIRELESS_MODE_A
)
3656 ratr_bitmap
= sta
->supp_rates
[NL80211_BAND_5GHZ
] << 4;
3658 ratr_bitmap
= sta
->supp_rates
[NL80211_BAND_2GHZ
];
3660 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
3661 ratr_bitmap
= 0xfff;
3663 if (wirelessmode
== WIRELESS_MODE_N_24G
3664 || wirelessmode
== WIRELESS_MODE_N_5G
)
3665 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
3666 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
3667 else if (wirelessmode
== WIRELESS_MODE_AC_24G
3668 || wirelessmode
== WIRELESS_MODE_AC_5G
3669 || wirelessmode
== WIRELESS_MODE_AC_ONLY
)
3670 ratr_bitmap
|= _rtl8821ae_rate_to_bitmap_2ssvht(
3671 sta
->vht_cap
.vht_mcs
.rx_mcs_map
) << 12;
3673 b_shortgi
= _rtl8821ae_get_ra_shortgi(hw
, sta
, macid
);
3674 rf_type
= _rtl8821ae_get_ra_rftype(hw
, wirelessmode
, ratr_bitmap
);
3677 switch (wirelessmode
) {
3678 case WIRELESS_MODE_B
:
3679 ratr_index
= RATR_INX_WIRELESS_B
;
3680 if (ratr_bitmap
& 0x0000000c)
3681 ratr_bitmap
&= 0x0000000d;
3683 ratr_bitmap
&= 0x0000000f;
3685 case WIRELESS_MODE_G
:
3686 ratr_index
= RATR_INX_WIRELESS_GB
;
3688 if (rssi_level
== 1)
3689 ratr_bitmap
&= 0x00000f00;
3690 else if (rssi_level
== 2)
3691 ratr_bitmap
&= 0x00000ff0;
3693 ratr_bitmap
&= 0x00000ff5;
3695 case WIRELESS_MODE_A
:
3696 ratr_index
= RATR_INX_WIRELESS_G
;
3697 ratr_bitmap
&= 0x00000ff0;
3699 case WIRELESS_MODE_N_24G
:
3700 case WIRELESS_MODE_N_5G
:
3701 if (wirelessmode
== WIRELESS_MODE_N_24G
)
3702 ratr_index
= RATR_INX_WIRELESS_NGB
;
3704 ratr_index
= RATR_INX_WIRELESS_NG
;
3706 if (mimo_ps
== IEEE80211_SMPS_STATIC
3707 || mimo_ps
== IEEE80211_SMPS_DYNAMIC
) {
3708 if (rssi_level
== 1)
3709 ratr_bitmap
&= 0x000f0000;
3710 else if (rssi_level
== 2)
3711 ratr_bitmap
&= 0x000ff000;
3713 ratr_bitmap
&= 0x000ff005;
3715 if (rf_type
== RF_1T1R
) {
3716 if (curtxbw_40mhz
) {
3717 if (rssi_level
== 1)
3718 ratr_bitmap
&= 0x000f0000;
3719 else if (rssi_level
== 2)
3720 ratr_bitmap
&= 0x000ff000;
3722 ratr_bitmap
&= 0x000ff015;
3724 if (rssi_level
== 1)
3725 ratr_bitmap
&= 0x000f0000;
3726 else if (rssi_level
== 2)
3727 ratr_bitmap
&= 0x000ff000;
3729 ratr_bitmap
&= 0x000ff005;
3732 if (curtxbw_40mhz
) {
3733 if (rssi_level
== 1)
3734 ratr_bitmap
&= 0x0fff0000;
3735 else if (rssi_level
== 2)
3736 ratr_bitmap
&= 0x0ffff000;
3738 ratr_bitmap
&= 0x0ffff015;
3740 if (rssi_level
== 1)
3741 ratr_bitmap
&= 0x0fff0000;
3742 else if (rssi_level
== 2)
3743 ratr_bitmap
&= 0x0ffff000;
3745 ratr_bitmap
&= 0x0ffff005;
3751 case WIRELESS_MODE_AC_24G
:
3752 ratr_index
= RATR_INX_WIRELESS_AC_24N
;
3753 if (rssi_level
== 1)
3754 ratr_bitmap
&= 0xfc3f0000;
3755 else if (rssi_level
== 2)
3756 ratr_bitmap
&= 0xfffff000;
3758 ratr_bitmap
&= 0xffffffff;
3761 case WIRELESS_MODE_AC_5G
:
3762 ratr_index
= RATR_INX_WIRELESS_AC_5N
;
3764 if (rf_type
== RF_1T1R
) {
3765 if (rssi_level
== 1) /*add by Gary for ac-series*/
3766 ratr_bitmap
&= 0x003f8000;
3767 else if (rssi_level
== 2)
3768 ratr_bitmap
&= 0x003ff000;
3770 ratr_bitmap
&= 0x003ff010;
3772 if (rssi_level
== 1)
3773 ratr_bitmap
&= 0xfe3f8000;
3774 else if (rssi_level
== 2)
3775 ratr_bitmap
&= 0xfffff000;
3777 ratr_bitmap
&= 0xfffff010;
3782 ratr_index
= RATR_INX_WIRELESS_NGB
;
3784 if (rf_type
== RF_1T2R
)
3785 ratr_bitmap
&= 0x000ff0ff;
3787 ratr_bitmap
&= 0x0f8ff0ff;
3791 ratr_index
= _rtl8821ae_mrate_idx_to_arfr_id(hw
, ratr_index
, wirelessmode
);
3792 sta_entry
->ratr_index
= ratr_index
;
3793 ratr_bitmap
= _rtl8821ae_set_ra_vht_ratr_bitmap(hw
, wirelessmode
,
3796 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_LOUD
,
3797 "ratr_bitmap :%x\n", ratr_bitmap
);
3799 /* *(u32 *)& rate_mask = EF4BYTE((ratr_bitmap & 0x0fffffff) |
3800 (ratr_index << 28)); */
3802 rate_mask
[0] = macid
;
3803 rate_mask
[1] = ratr_index
| (b_shortgi
? 0x80 : 0x00);
3804 rate_mask
[2] = rtlphy
->current_chan_bw
3805 | _rtl8821ae_get_vht_eni(wirelessmode
, ratr_bitmap
)
3806 | _rtl8821ae_get_ra_ldpc(hw
, macid
, sta_entry
, wirelessmode
);
3808 rate_mask
[3] = (u8
)(ratr_bitmap
& 0x000000ff);
3809 rate_mask
[4] = (u8
)((ratr_bitmap
& 0x0000ff00) >> 8);
3810 rate_mask
[5] = (u8
)((ratr_bitmap
& 0x00ff0000) >> 16);
3811 rate_mask
[6] = (u8
)((ratr_bitmap
& 0xff000000) >> 24);
3813 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
3814 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
3815 ratr_index
, ratr_bitmap
,
3816 rate_mask
[0], rate_mask
[1],
3817 rate_mask
[2], rate_mask
[3],
3818 rate_mask
[4], rate_mask
[5],
3820 rtl8821ae_fill_h2c_cmd(hw
, H2C_8821AE_RA_MASK
, 7, rate_mask
);
3821 _rtl8821ae_set_bcn_ctrl_reg(hw
, BIT(3), 0);
3824 void rtl8821ae_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
3825 struct ieee80211_sta
*sta
, u8 rssi_level
)
3827 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3828 if (rtlpriv
->dm
.useramask
)
3829 rtl8821ae_update_hal_rate_mask(hw
, sta
, rssi_level
);
3831 /*RT_TRACE(rtlpriv, COMP_RATR,DBG_LOUD,
3832 "rtl8821ae_update_hal_rate_tbl() Error! 8821ae FW RA Only");*/
3833 rtl8821ae_update_hal_rate_table(hw
, sta
);
3836 void rtl8821ae_update_channel_access_setting(struct ieee80211_hw
*hw
)
3838 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3839 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3840 u16 wireless_mode
= mac
->mode
;
3841 u8 sifs_timer
, r2t_sifs
;
3843 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
3844 (u8
*)&mac
->slot_time
);
3845 if (wireless_mode
== WIRELESS_MODE_G
)
3849 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
3853 if (wireless_mode
== WIRELESS_MODE_AC_5G
&&
3854 (mac
->vht_ldpc_cap
& LDPC_VHT_ENABLE_RX
) &&
3855 (mac
->vht_stbc_cap
& STBC_VHT_ENABLE_RX
)) {
3856 if (mac
->vendor
== PEER_ATH
)
3860 } else if (wireless_mode
== WIRELESS_MODE_AC_5G
) {
3864 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_R2T_SIFS
, (u8
*)&r2t_sifs
);
3867 bool rtl8821ae_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
3869 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3870 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
3871 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
3872 enum rf_pwrstate e_rfpowerstate_toset
, cur_rfstate
;
3874 bool b_actuallyset
= false;
3876 if (rtlpriv
->rtlhal
.being_init_adapter
)
3879 if (ppsc
->swrf_processing
)
3882 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3883 if (ppsc
->rfchange_inprogress
) {
3884 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3887 ppsc
->rfchange_inprogress
= true;
3888 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3891 cur_rfstate
= ppsc
->rfpwr_state
;
3893 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL_2
,
3894 rtl_read_byte(rtlpriv
,
3895 REG_GPIO_IO_SEL_2
) & ~(BIT(1)));
3897 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_PIN_CTRL_2
);
3899 if (rtlphy
->polarity_ctl
)
3900 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFOFF
: ERFON
;
3902 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFON
: ERFOFF
;
3904 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
3905 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3906 "GPIOChangeRF - HW Radio ON, RF ON\n");
3908 e_rfpowerstate_toset
= ERFON
;
3909 ppsc
->hwradiooff
= false;
3910 b_actuallyset
= true;
3911 } else if ((!ppsc
->hwradiooff
)
3912 && (e_rfpowerstate_toset
== ERFOFF
)) {
3913 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
3914 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
3916 e_rfpowerstate_toset
= ERFOFF
;
3917 ppsc
->hwradiooff
= true;
3918 b_actuallyset
= true;
3921 if (b_actuallyset
) {
3922 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3923 ppsc
->rfchange_inprogress
= false;
3924 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3926 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
3927 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
3929 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
3930 ppsc
->rfchange_inprogress
= false;
3931 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
3935 return !ppsc
->hwradiooff
;
3938 void rtl8821ae_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
3939 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
3940 bool is_wepkey
, bool clear_all
)
3942 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
3943 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
3944 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
3945 u8
*macaddr
= p_macaddr
;
3947 bool is_pairwise
= false;
3949 static u8 cam_const_addr
[4][6] = {
3950 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3951 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3952 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3953 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
3955 static u8 cam_const_broad
[] = {
3956 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
3962 u8 clear_number
= 5;
3964 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
3966 for (idx
= 0; idx
< clear_number
; idx
++) {
3967 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
3968 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
3971 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
3973 rtlpriv
->sec
.key_len
[idx
] = 0;
3978 case WEP40_ENCRYPTION
:
3979 enc_algo
= CAM_WEP40
;
3981 case WEP104_ENCRYPTION
:
3982 enc_algo
= CAM_WEP104
;
3984 case TKIP_ENCRYPTION
:
3985 enc_algo
= CAM_TKIP
;
3987 case AESCCMP_ENCRYPTION
:
3991 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
3992 "switch case not process\n");
3993 enc_algo
= CAM_TKIP
;
3997 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
3998 macaddr
= cam_const_addr
[key_index
];
3999 entry_id
= key_index
;
4002 macaddr
= cam_const_broad
;
4003 entry_id
= key_index
;
4005 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
4006 entry_id
= rtl_cam_get_free_entry(hw
, p_macaddr
);
4007 if (entry_id
>= TOTAL_CAM_ENTRY
) {
4008 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_EMERG
,
4009 "Can not find free hwsecurity cam entry\n");
4013 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
4016 key_index
= PAIRWISE_KEYIDX
;
4021 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
4022 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
4023 "delete one entry, entry_id is %d\n",
4025 if (mac
->opmode
== NL80211_IFTYPE_AP
)
4026 rtl_cam_del_entry(hw
, p_macaddr
);
4027 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
4029 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
4032 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
4033 "set Pairwise key\n");
4035 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
4037 CAM_CONFIG_NO_USEDK
,
4038 rtlpriv
->sec
.key_buf
[key_index
]);
4040 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
4043 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
4044 rtl_cam_add_one_entry(hw
,
4047 CAM_PAIRWISE_KEY_POSITION
,
4049 CAM_CONFIG_NO_USEDK
,
4050 rtlpriv
->sec
.key_buf
4054 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
4056 CAM_CONFIG_NO_USEDK
,
4057 rtlpriv
->sec
.key_buf
[entry_id
]);
4063 void rtl8821ae_bt_reg_init(struct ieee80211_hw
*hw
)
4065 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4067 /* 0:Low, 1:High, 2:From Efuse. */
4068 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
4069 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
4070 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
4071 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
4072 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
4075 void rtl8821ae_bt_hw_init(struct ieee80211_hw
*hw
)
4077 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4079 if (rtlpriv
->cfg
->ops
->get_btc_status())
4080 rtlpriv
->btcoexist
.btc_ops
->btc_init_hw_config(rtlpriv
);
4083 void rtl8821ae_suspend(struct ieee80211_hw
*hw
)
4087 void rtl8821ae_resume(struct ieee80211_hw
*hw
)
4091 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
4092 void rtl8821ae_allow_all_destaddr(struct ieee80211_hw
*hw
,
4093 bool allow_all_da
, bool write_into_reg
)
4095 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4096 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
4098 if (allow_all_da
) /* Set BIT0 */
4099 rtlpci
->receive_config
|= RCR_AAP
;
4100 else /* Clear BIT0 */
4101 rtlpci
->receive_config
&= ~RCR_AAP
;
4104 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
4106 RT_TRACE(rtlpriv
, COMP_TURBO
| COMP_INIT
, DBG_LOUD
,
4107 "receive_config=0x%08X, write_into_reg=%d\n",
4108 rtlpci
->receive_config
, write_into_reg
);
4111 /* WKFMCAMAddAllEntry8812 */
4112 void rtl8821ae_add_wowlan_pattern(struct ieee80211_hw
*hw
,
4113 struct rtl_wow_pattern
*rtl_pattern
,
4116 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
4124 /* Count the WFCAM entry start offset. */
4126 /* RX page size = 128 byte */
4127 offset
= MAX_RX_DMA_BUFFER_SIZE_8812
/ 128;
4128 /* We should start from the boundry */
4129 cam_start
= offset
* 128;
4131 /* Enable Rx packet buffer access. */
4132 rtl_write_byte(rtlpriv
, REG_PKT_BUFF_ACCESS_CTRL
, RXPKT_BUF_SELECT
);
4133 for (addr
= 0; addr
< WKFMCAM_ADDR_NUM
; addr
++) {
4134 /* Set Rx packet buffer offset.
4135 * RxBufer pointer increases 1,
4136 * we can access 8 bytes in Rx packet buffer.
4137 * CAM start offset (unit: 1 byte) = index*WKFMCAM_SIZE
4138 * RxBufer addr = (CAM start offset +
4139 * per entry offset of a WKFM CAM)/8
4140 * * index: The index of the wake up frame mask
4141 * * WKFMCAM_SIZE: the total size of one WKFM CAM
4142 * * per entry offset of a WKFM CAM: Addr*4 bytes
4144 rxbuf_addr
= (cam_start
+ index
* WKFMCAM_SIZE
+ addr
* 4) >> 3;
4145 /* Set R/W start offset */
4146 rtl_write_word(rtlpriv
, REG_PKTBUF_DBG_CTRL
, rxbuf_addr
);
4149 cam
= BIT(31) | rtl_pattern
->crc
;
4151 if (rtl_pattern
->type
== UNICAST_PATTERN
)
4153 else if (rtl_pattern
->type
== MULTICAST_PATTERN
)
4155 else if (rtl_pattern
->type
== BROADCAST_PATTERN
)
4158 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_L
, cam
);
4159 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4160 "WRITE entry[%d] 0x%x: %x\n", addr
,
4161 REG_PKTBUF_DBG_DATA_L
, cam
);
4163 /* Write to Rx packet buffer. */
4164 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0x0f01);
4165 } else if (addr
== 2 || addr
== 4) {/* WKFM[127:0] */
4166 cam
= rtl_pattern
->mask
[addr
- 2];
4168 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_L
, cam
);
4169 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4170 "WRITE entry[%d] 0x%x: %x\n", addr
,
4171 REG_PKTBUF_DBG_DATA_L
, cam
);
4173 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0x0f01);
4174 } else if (addr
== 3 || addr
== 5) {/* WKFM[127:0] */
4175 cam
= rtl_pattern
->mask
[addr
- 2];
4177 rtl_write_dword(rtlpriv
, REG_PKTBUF_DBG_DATA_H
, cam
);
4178 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
4179 "WRITE entry[%d] 0x%x: %x\n", addr
,
4180 REG_PKTBUF_DBG_DATA_H
, cam
);
4182 rtl_write_word(rtlpriv
, REG_RXPKTBUF_CTRL
, 0xf001);
4187 tmp
= rtl_read_byte(rtlpriv
, REG_RXPKTBUF_CTRL
);
4190 } while (tmp
&& count
< 100);
4192 RT_ASSERT((count
< 100),
4193 "Write wake up frame mask FAIL %d value!\n", tmp
);
4195 /* Disable Rx packet buffer access. */
4196 rtl_write_byte(rtlpriv
, REG_PKT_BUFF_ACCESS_CTRL
,
4197 DISABLE_TRXPKT_BUF_ACCESS
);