1 /******************************************************************************
3 * Copyright(c) 2009-2013 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
44 #include "pwrseqcmd.h"
49 static void _rtl88ee_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
50 u8 set_bits
, u8 clear_bits
)
52 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
53 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
55 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
56 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
58 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
61 static void _rtl88ee_stop_tx_beacon(struct ieee80211_hw
*hw
)
63 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
66 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
67 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
68 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
69 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
70 tmp1byte
&= ~(BIT(0));
71 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
74 static void _rtl88ee_resume_tx_beacon(struct ieee80211_hw
*hw
)
76 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
79 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
80 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
81 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
82 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
84 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
87 static void _rtl88ee_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
89 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(1));
92 static void _rtl88ee_return_beacon_queue_skb(struct ieee80211_hw
*hw
)
94 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
95 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
96 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
98 while (skb_queue_len(&ring
->queue
)) {
99 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
100 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
102 pci_unmap_single(rtlpci
->pdev
,
103 rtlpriv
->cfg
->ops
->get_desc(
104 (u8
*)entry
, true, HW_DESC_TXBUFF_ADDR
),
105 skb
->len
, PCI_DMA_TODEVICE
);
107 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
111 static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
113 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(1), 0);
116 static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw
*hw
,
117 u8 rpwm_val
, bool need_turn_off_ckk
)
119 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
120 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
121 bool support_remote_wake_up
;
122 u32 count
= 0, isr_regaddr
, content
;
123 bool schedule_timer
= need_turn_off_ckk
;
125 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
126 (u8
*)(&support_remote_wake_up
));
127 if (!rtlhal
->fw_ready
)
129 if (!rtlpriv
->psc
.fw_current_inpsmode
)
133 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
134 if (rtlhal
->fw_clk_change_in_progress
) {
135 while (rtlhal
->fw_clk_change_in_progress
) {
136 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
140 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
142 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
144 rtlhal
->fw_clk_change_in_progress
= false;
145 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
150 if (IS_IN_LOW_POWER_STATE_88E(rtlhal
->fw_ps_state
)) {
151 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
,
153 if (FW_PS_IS_ACK(rpwm_val
)) {
154 isr_regaddr
= REG_HISR
;
155 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
156 while (!(content
& IMR_CPWM
) && (count
< 500)) {
159 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
162 if (content
& IMR_CPWM
) {
163 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
164 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON_88E
;
165 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
166 "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
167 rtlhal
->fw_ps_state
);
171 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
172 rtlhal
->fw_clk_change_in_progress
= false;
173 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
174 if (schedule_timer
) {
175 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
176 jiffies
+ MSECS(10));
179 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
180 rtlhal
->fw_clk_change_in_progress
= false;
181 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
185 static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw
*hw
,
188 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
189 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
190 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
191 struct rtl8192_tx_ring
*ring
;
192 enum rf_pwrstate rtstate
;
193 bool schedule_timer
= false;
196 if (!rtlhal
->fw_ready
)
198 if (!rtlpriv
->psc
.fw_current_inpsmode
)
200 if (!rtlhal
->allow_sw_to_change_hwclc
)
202 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
203 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
206 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
207 ring
= &rtlpci
->tx_ring
[queue
];
208 if (skb_queue_len(&ring
->queue
)) {
209 schedule_timer
= true;
214 if (schedule_timer
) {
215 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
216 jiffies
+ MSECS(10));
220 if (FW_PS_STATE(rtlhal
->fw_ps_state
) !=
221 FW_PS_STATE_RF_OFF_LOW_PWR_88E
) {
222 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
223 if (!rtlhal
->fw_clk_change_in_progress
) {
224 rtlhal
->fw_clk_change_in_progress
= true;
225 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
226 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
227 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
228 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
230 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
231 rtlhal
->fw_clk_change_in_progress
= false;
232 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
234 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
235 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
236 jiffies
+ MSECS(10));
241 static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
245 rpwm_val
|= (FW_PS_STATE_RF_OFF_88E
| FW_PS_ACK
);
246 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, true);
249 static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw
*hw
)
253 rpwm_val
|= FW_PS_STATE_RF_OFF_LOW_PWR_88E
;
254 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
257 void rtl88ee_fw_clk_off_timer_callback(unsigned long data
)
259 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
261 _rtl88ee_set_fw_ps_rf_off_low_power(hw
);
264 static void _rtl88ee_fwlps_leave(struct ieee80211_hw
*hw
)
266 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
267 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
268 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
269 bool fw_current_inps
= false;
270 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
272 if (ppsc
->low_power_enable
) {
273 rpwm_val
= (FW_PS_STATE_ALL_ON_88E
|FW_PS_ACK
);/* RF on */
274 _rtl88ee_set_fw_clock_on(hw
, rpwm_val
, false);
275 rtlhal
->allow_sw_to_change_hwclc
= false;
276 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
277 (u8
*)(&fw_pwrmode
));
278 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
279 (u8
*)(&fw_current_inps
));
281 rpwm_val
= FW_PS_STATE_ALL_ON_88E
; /* RF on */
282 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
284 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
285 (u8
*)(&fw_pwrmode
));
286 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
287 (u8
*)(&fw_current_inps
));
291 static void _rtl88ee_fwlps_enter(struct ieee80211_hw
*hw
)
293 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
294 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
295 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
296 bool fw_current_inps
= true;
299 if (ppsc
->low_power_enable
) {
300 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR_88E
; /* RF off */
301 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
302 (u8
*)(&fw_current_inps
));
303 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
304 (u8
*)(&ppsc
->fwctrl_psmode
));
305 rtlhal
->allow_sw_to_change_hwclc
= true;
306 _rtl88ee_set_fw_clock_off(hw
, rpwm_val
);
308 rpwm_val
= FW_PS_STATE_RF_OFF_88E
; /* RF off */
309 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
310 (u8
*)(&fw_current_inps
));
311 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
312 (u8
*)(&ppsc
->fwctrl_psmode
));
313 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
318 void rtl88ee_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
320 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
321 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
322 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
326 *((u32
*)(val
)) = rtlpci
->receive_config
;
328 case HW_VAR_RF_STATE
:
329 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
331 case HW_VAR_FWLPS_RF_ON
:{
332 enum rf_pwrstate rfstate
;
335 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
337 if (rfstate
== ERFOFF
) {
338 *((bool *)(val
)) = true;
340 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
341 val_rcr
&= 0x00070000;
343 *((bool *)(val
)) = false;
345 *((bool *)(val
)) = true;
349 case HW_VAR_FW_PSMODE_STATUS
:
350 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
352 case HW_VAR_CORRECT_TSF
:{
354 u32
*ptsf_low
= (u32
*)&tsf
;
355 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
357 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
358 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
360 *((u64
*)(val
)) = tsf
;
363 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
364 "switch case not process %x\n", variable
);
369 void rtl88ee_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
371 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
372 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
373 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
374 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
375 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
379 case HW_VAR_ETHER_ADDR
:
380 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
381 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
), val
[idx
]);
383 case HW_VAR_BASIC_RATE
:{
384 u16 rate_cfg
= ((u16
*)val
)[0];
386 rate_cfg
= rate_cfg
& 0x15f;
388 rtl_write_byte(rtlpriv
, REG_RRSR
, rate_cfg
& 0xff);
389 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1, (rate_cfg
>> 8) & 0xff);
390 while (rate_cfg
> 0x1) {
391 rate_cfg
= (rate_cfg
>> 1);
394 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
, rate_index
);
397 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
398 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
), val
[idx
]);
401 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
402 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
404 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
405 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
408 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
, 0x0e0e);
410 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
413 case HW_VAR_SLOT_TIME
:{
416 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
417 "HW_VAR_SLOT_TIME %x\n", val
[0]);
419 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
421 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
422 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
426 case HW_VAR_ACK_PREAMBLE
:{
428 u8 short_preamble
= (bool) (*(u8
*)val
);
429 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+2);
430 if (short_preamble
) {
432 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
435 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
438 case HW_VAR_WPA_CONFIG
:
439 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*)val
));
441 case HW_VAR_AMPDU_MIN_SPACE
:{
442 u8 min_spacing_to_set
;
445 min_spacing_to_set
= *((u8
*)val
);
446 if (min_spacing_to_set
<= 7) {
449 if (min_spacing_to_set
< sec_min_space
)
450 min_spacing_to_set
= sec_min_space
;
452 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
453 0xf8) | min_spacing_to_set
);
455 *val
= min_spacing_to_set
;
457 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
458 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
461 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
465 case HW_VAR_SHORTGI_DENSITY
:{
468 density_to_set
= *((u8
*)val
);
469 mac
->min_space_cfg
|= (density_to_set
<< 3);
471 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
472 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
475 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
478 case HW_VAR_AMPDU_FACTOR
:{
479 u8 regtoset_normal
[4] = { 0x41, 0xa8, 0x72, 0xb9 };
484 reg
= regtoset_normal
;
486 factor
= *((u8
*)val
);
488 factor
= (1 << (factor
+ 2));
492 for (id
= 0; id
< 4; id
++) {
493 if ((reg
[id
] & 0xf0) > (factor
<< 4))
494 reg
[id
] = (reg
[id
] & 0x0f) |
497 if ((reg
[id
] & 0x0f) > factor
)
498 reg
[id
] = (reg
[id
] & 0xf0) | (factor
);
500 rtl_write_byte(rtlpriv
, (REG_AGGLEN_LMT
+ id
),
504 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
505 "Set HW_VAR_AMPDU_FACTOR: %#x\n", factor
);
508 case HW_VAR_AC_PARAM
:{
509 u8 e_aci
= *((u8
*)val
);
510 rtl88e_dm_init_edca_turbo(hw
);
512 if (rtlpci
->acm_method
!= eAcmWay2_SW
)
513 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACM_CTRL
,
516 case HW_VAR_ACM_CTRL
:{
517 u8 e_aci
= *((u8
*)val
);
518 union aci_aifsn
*p_aci_aifsn
=
519 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
520 u8 acm
= p_aci_aifsn
->f
.acm
;
521 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
523 acm_ctrl
= acm_ctrl
| ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
528 acm_ctrl
|= ACMHW_BEQEN
;
531 acm_ctrl
|= ACMHW_VIQEN
;
534 acm_ctrl
|= ACMHW_VOQEN
;
537 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
538 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
545 acm_ctrl
&= (~ACMHW_BEQEN
);
548 acm_ctrl
&= (~ACMHW_VIQEN
);
551 acm_ctrl
&= (~ACMHW_BEQEN
);
554 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
555 "switch case not process\n");
560 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
561 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
563 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
566 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
567 rtlpci
->receive_config
= ((u32
*)(val
))[0];
569 case HW_VAR_RETRY_LIMIT
:{
570 u8 retry_limit
= ((u8
*)(val
))[0];
572 rtl_write_word(rtlpriv
, REG_RL
,
573 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
574 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
576 case HW_VAR_DUAL_TSF_RST
:
577 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
579 case HW_VAR_EFUSE_BYTES
:
580 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
582 case HW_VAR_EFUSE_USAGE
:
583 rtlefuse
->efuse_usedpercentage
= *((u8
*)val
);
586 rtl88e_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
588 case HW_VAR_SET_RPWM
:{
591 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
594 if (rpwm_val
& BIT(7)) {
595 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
598 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
599 ((*(u8
*)val
) | BIT(7)));
602 case HW_VAR_H2C_FW_PWRMODE
:
603 rtl88e_set_fw_pwrmode_cmd(hw
, (*(u8
*)val
));
605 case HW_VAR_FW_PSMODE_STATUS
:
606 ppsc
->fw_current_inpsmode
= *((bool *)val
);
608 case HW_VAR_RESUME_CLK_ON
:
609 _rtl88ee_set_fw_ps_rf_on(hw
);
611 case HW_VAR_FW_LPS_ACTION
:{
612 bool enter_fwlps
= *((bool *)val
);
615 _rtl88ee_fwlps_enter(hw
);
617 _rtl88ee_fwlps_leave(hw
);
619 case HW_VAR_H2C_FW_JOINBSSRPT
:{
620 u8 mstatus
= (*(u8
*)val
);
621 u8 tmp
, tmp_reg422
, uval
;
622 u8 count
= 0, dlbcn_count
= 0;
623 bool recover
= false;
625 if (mstatus
== RT_MEDIA_CONNECT
) {
626 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
628 tmp
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
629 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
| BIT(0)));
631 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
632 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
634 tmp_reg422
= rtl_read_byte(rtlpriv
,
635 REG_FWHW_TXQ_CTRL
+ 2);
636 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
637 tmp_reg422
& (~BIT(6)));
638 if (tmp_reg422
& BIT(6))
642 uval
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+2);
643 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2,
645 _rtl88ee_return_beacon_queue_skb(hw
);
647 rtl88e_set_fw_rsvdpagepkt(hw
, 0);
648 uval
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+2);
650 while (!(uval
& BIT(0)) && count
< 20) {
653 uval
= rtl_read_byte(rtlpriv
,
657 } while (!(uval
& BIT(0)) && dlbcn_count
< 5);
660 rtl_write_byte(rtlpriv
, REG_TDECTRL
+2, BIT(0));
662 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
663 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
666 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
669 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp
& ~(BIT(0))));
671 rtl88e_set_fw_joinbss_report_cmd(hw
, (*(u8
*)val
));
673 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
674 rtl88e_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
678 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
680 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
, (u2btmp
|
683 case HW_VAR_CORRECT_TSF
:{
684 u8 btype_ibss
= ((u8
*)(val
))[0];
686 if (btype_ibss
== true)
687 _rtl88ee_stop_tx_beacon(hw
);
689 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(3));
691 rtl_write_dword(rtlpriv
, REG_TSFTR
,
692 (u32
) (mac
->tsf
& 0xffffffff));
693 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
694 (u32
) ((mac
->tsf
>> 32) & 0xffffffff));
696 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
698 if (btype_ibss
== true)
699 _rtl88ee_resume_tx_beacon(hw
);
702 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
703 "switch case not process %x\n", variable
);
708 static bool _rtl88ee_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
710 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
713 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
714 _LLT_OP(_LLT_WRITE_ACCESS
);
716 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
719 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
720 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
723 if (count
> POLLING_LLT_THRESHOLD
) {
724 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
725 "Failed to polling write LLT done at address %d!\n",
735 static bool _rtl88ee_llt_table_init(struct ieee80211_hw
*hw
)
737 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
744 txpktbuf_bndy
= 0xAB;
746 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x01);
747 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80730d29);
750 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
, (0x25FF0000 | txpktbuf_bndy
));
751 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
753 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
754 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
756 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
757 rtl_write_byte(rtlpriv
, REG_PBP
, 0x11);
758 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
760 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
761 status
= _rtl88ee_llt_write(hw
, i
, i
+ 1);
766 status
= _rtl88ee_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
770 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
771 status
= _rtl88ee_llt_write(hw
, i
, (i
+ 1));
776 status
= _rtl88ee_llt_write(hw
, maxpage
, txpktbuf_bndy
);
783 static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw
*hw
)
785 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
786 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
787 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
788 struct rtl_led
*pLed0
= &(pcipriv
->ledctl
.sw_led0
);
790 if (rtlpriv
->rtlhal
.up_first_time
)
793 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
794 rtl88ee_sw_led_on(hw
, pLed0
);
795 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
796 rtl88ee_sw_led_on(hw
, pLed0
);
798 rtl88ee_sw_led_off(hw
, pLed0
);
801 static bool _rtl88ee_init_mac(struct ieee80211_hw
*hw
)
803 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
804 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
805 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
809 /*Disable XTAL OUTPUT for power saving. YJ, add, 111206. */
810 bytetmp
= rtl_read_byte(rtlpriv
, REG_XCK_OUT_CTRL
) & (~BIT(0));
811 rtl_write_byte(rtlpriv
, REG_XCK_OUT_CTRL
, bytetmp
);
812 /*Auto Power Down to CHIP-off State*/
813 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
814 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
816 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
817 /* HW Power on sequence */
818 if (!rtl88_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
819 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
820 Rtl8188E_NIC_ENABLE_FLOW
)) {
821 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
822 "init MAC Fail as rtl88_hal_pwrseqcmdparsing\n");
826 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
827 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
829 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2);
830 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+2, bytetmp
|BIT(2));
832 bytetmp
= rtl_read_byte(rtlpriv
, REG_WATCH_DOG
+1);
833 rtl_write_byte(rtlpriv
, REG_WATCH_DOG
+1, bytetmp
|BIT(7));
835 bytetmp
= rtl_read_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1);
836 rtl_write_byte(rtlpriv
, REG_AFE_XTAL_CTRL_EXT
+1, bytetmp
|BIT(1));
838 bytetmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
839 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, bytetmp
|BIT(1)|BIT(0));
840 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
+1, 2);
841 rtl_write_word(rtlpriv
, REG_TX_RPT_TIME
, 0xcdf0);
843 /*Add for wake up online*/
844 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
846 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, bytetmp
|BIT(3));
847 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+1);
848 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+1, (bytetmp
& (~BIT(4))));
849 rtl_write_byte(rtlpriv
, 0x367, 0x80);
851 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
852 rtl_write_byte(rtlpriv
, REG_CR
+1, 0x06);
853 rtl_write_byte(rtlpriv
, REG_CR
+2, 0x00);
855 if (!rtlhal
->mac_func_enable
) {
856 if (_rtl88ee_llt_table_init(hw
) == false) {
857 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
858 "LLT table init fail\n");
864 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
865 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
867 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
870 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
872 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
873 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xffff);
874 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
876 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
877 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
879 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
880 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
882 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
883 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
884 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
885 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
886 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
887 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
888 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
889 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
890 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
891 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
893 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
894 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
897 /* if we want to support 64 bit DMA, we should set it here,
898 * but at the moment we do not support 64 bit DMA
901 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
903 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
904 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0);/*Enable RX DMA */
906 if (rtlhal
->earlymode_enable
) {/*Early mode enable*/
907 bytetmp
= rtl_read_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
);
909 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, bytetmp
);
910 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
+3, 0x81);
912 _rtl88ee_gen_refresh_led_state(hw
);
916 static void _rtl88ee_hw_configure(struct ieee80211_hw
*hw
)
918 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
921 reg_prsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
923 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_prsr
);
924 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
927 static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw
*hw
)
929 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
930 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
932 u32 tmp4Byte
= 0, count
;
934 rtl_write_word(rtlpriv
, 0x354, 0x8104);
935 rtl_write_word(rtlpriv
, 0x358, 0x24);
937 rtl_write_word(rtlpriv
, 0x350, 0x70c);
938 rtl_write_byte(rtlpriv
, 0x352, 0x2);
939 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
941 while (tmp1byte
&& count
< 20) {
943 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
947 tmp4Byte
= rtl_read_dword(rtlpriv
, 0x34c);
948 rtl_write_dword(rtlpriv
, 0x348, tmp4Byte
|BIT(31));
949 rtl_write_word(rtlpriv
, 0x350, 0xf70c);
950 rtl_write_byte(rtlpriv
, 0x352, 0x1);
953 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
955 while (tmp1byte
&& count
< 20) {
957 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
961 rtl_write_word(rtlpriv
, 0x350, 0x718);
962 rtl_write_byte(rtlpriv
, 0x352, 0x2);
963 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
965 while (tmp1byte
&& count
< 20) {
967 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
970 if (ppsc
->support_backdoor
|| (0 == tmp1byte
)) {
971 tmp4Byte
= rtl_read_dword(rtlpriv
, 0x34c);
972 rtl_write_dword(rtlpriv
, 0x348, tmp4Byte
|BIT(11)|BIT(12));
973 rtl_write_word(rtlpriv
, 0x350, 0xf718);
974 rtl_write_byte(rtlpriv
, 0x352, 0x1);
976 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
978 while (tmp1byte
&& count
< 20) {
980 tmp1byte
= rtl_read_byte(rtlpriv
, 0x352);
985 void rtl88ee_enable_hw_security_config(struct ieee80211_hw
*hw
)
987 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
990 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
991 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
992 rtlpriv
->sec
.pairwise_enc_algorithm
,
993 rtlpriv
->sec
.group_enc_algorithm
);
995 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
996 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
997 "not open hw encryption\n");
1000 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1002 if (rtlpriv
->sec
.use_defaultkey
) {
1003 sec_reg_value
|= SCR_TXUSEDK
;
1004 sec_reg_value
|= SCR_RXUSEDK
;
1007 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1009 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1011 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1012 "The SECR-value %x\n", sec_reg_value
);
1013 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1016 int rtl88ee_hw_init(struct ieee80211_hw
*hw
)
1018 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1019 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1020 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1021 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1022 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1023 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1024 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1025 bool rtstatus
= true;
1028 unsigned long flags
;
1030 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Rtl8188EE hw init\n");
1031 rtlpriv
->rtlhal
.being_init_adapter
= true;
1032 /* As this function can take a very long time (up to 350 ms)
1033 * and can be called with irqs disabled, reenable the irqs
1034 * to let the other devices continue being serviced.
1036 * It is safe doing so since our own interrupts will only be enabled
1037 * in a subsequent step.
1039 local_save_flags(flags
);
1042 rtlpriv
->intf_ops
->disable_aspm(hw
);
1044 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
+1);
1045 u1byte
= rtl_read_byte(rtlpriv
, REG_CR
);
1046 if ((tmp_u1b
& BIT(3)) && (u1byte
!= 0 && u1byte
!= 0xEA)) {
1047 rtlhal
->mac_func_enable
= true;
1049 rtlhal
->mac_func_enable
= false;
1050 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1053 rtstatus
= _rtl88ee_init_mac(hw
);
1054 if (rtstatus
!= true) {
1055 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Init MAC failed\n");
1060 err
= rtl88e_download_fw(hw
, false);
1062 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1063 "Failed to download FW. Init HW without FW now..\n");
1067 rtlhal
->fw_ready
= true;
1069 /*fw related variable initialize */
1070 rtlhal
->last_hmeboxnum
= 0;
1071 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON_88E
;
1072 rtlhal
->fw_clk_change_in_progress
= false;
1073 rtlhal
->allow_sw_to_change_hwclc
= false;
1074 ppsc
->fw_current_inpsmode
= false;
1076 rtl88e_phy_mac_config(hw
);
1077 /* because last function modifies RCR, we update
1078 * rcr var here, or TP will be unstable for receive_config
1079 * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
1080 * RCR_APP_ICV will cause mac80211 disassoc for cisco 1252
1082 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1083 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1085 rtl88e_phy_bb_config(hw
);
1086 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BCCKEN
, 0x1);
1087 rtl_set_bbreg(hw
, RFPGA0_RFMOD
, BOFDMEN
, 0x1);
1089 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1090 rtl88e_phy_rf_config(hw
);
1092 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1093 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1094 rtlphy
->rfreg_chnlval
[0] = rtlphy
->rfreg_chnlval
[0] & 0xfff00fff;
1096 _rtl88ee_hw_configure(hw
);
1097 rtl_cam_reset_all_entry(hw
);
1098 rtl88ee_enable_hw_security_config(hw
);
1100 rtlhal
->mac_func_enable
= true;
1101 ppsc
->rfpwr_state
= ERFON
;
1103 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1104 _rtl88ee_enable_aspm_back_door(hw
);
1105 rtlpriv
->intf_ops
->enable_aspm(hw
);
1107 if (ppsc
->rfpwr_state
== ERFON
) {
1108 if ((rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
) ||
1109 ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) &&
1110 (rtlhal
->oem_id
== RT_CID_819x_HP
))) {
1111 rtl88e_phy_set_rfpath_switch(hw
, true);
1112 rtlpriv
->dm
.fat_table
.rx_idle_ant
= MAIN_ANT
;
1114 rtl88e_phy_set_rfpath_switch(hw
, false);
1115 rtlpriv
->dm
.fat_table
.rx_idle_ant
= AUX_ANT
;
1117 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1119 (rtlpriv
->dm
.fat_table
.rx_idle_ant
== MAIN_ANT
) ?
1120 ("MAIN_ANT") : ("AUX_ANT"));
1122 if (rtlphy
->iqk_initialized
) {
1123 rtl88e_phy_iq_calibrate(hw
, true);
1125 rtl88e_phy_iq_calibrate(hw
, false);
1126 rtlphy
->iqk_initialized
= true;
1128 rtl88e_dm_check_txpower_tracking(hw
);
1129 rtl88e_phy_lc_calibrate(hw
);
1132 tmp_u1b
= efuse_read_1byte(hw
, 0x1FA);
1133 if (!(tmp_u1b
& BIT(0))) {
1134 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0F, 0x05);
1135 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "PA BIAS path A\n");
1138 if (!(tmp_u1b
& BIT(4))) {
1139 tmp_u1b
= rtl_read_byte(rtlpriv
, 0x16);
1141 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x80);
1143 rtl_write_byte(rtlpriv
, 0x16, tmp_u1b
| 0x90);
1144 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "under 1.5V\n");
1146 rtl_write_byte(rtlpriv
, REG_NAV_CTRL
+2, ((30000+127)/128));
1149 local_irq_restore(flags
);
1150 rtlpriv
->rtlhal
.being_init_adapter
= false;
1151 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "end of Rtl8188EE hw init %x\n",
1156 static enum version_8188e
_rtl88ee_read_chip_version(struct ieee80211_hw
*hw
)
1158 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1159 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1160 enum version_8188e version
= VERSION_UNKNOWN
;
1163 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
1164 if (value32
& TRP_VAUX_EN
) {
1165 version
= (enum version_8188e
) VERSION_TEST_CHIP_88E
;
1167 version
= NORMAL_CHIP
;
1168 version
= version
| ((value32
& TYPE_ID
) ? RF_TYPE_2T2R
: 0);
1169 version
= version
| ((value32
& VENDOR_ID
) ?
1170 CHIP_VENDOR_UMC
: 0);
1173 rtlphy
->rf_type
= RF_1T1R
;
1174 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1175 "Chip RF Type: %s\n", (rtlphy
->rf_type
== RF_2T2R
) ?
1176 "RF_2T2R" : "RF_1T1R");
1181 static int _rtl88ee_set_media_status(struct ieee80211_hw
*hw
,
1182 enum nl80211_iftype type
)
1184 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1185 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1186 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1189 if (type
== NL80211_IFTYPE_UNSPECIFIED
||
1190 type
== NL80211_IFTYPE_STATION
) {
1191 _rtl88ee_stop_tx_beacon(hw
);
1192 _rtl88ee_enable_bcn_sub_func(hw
);
1193 } else if (type
== NL80211_IFTYPE_ADHOC
||
1194 type
== NL80211_IFTYPE_AP
||
1195 type
== NL80211_IFTYPE_MESH_POINT
) {
1196 _rtl88ee_resume_tx_beacon(hw
);
1197 _rtl88ee_disable_bcn_sub_func(hw
);
1199 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1200 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1205 case NL80211_IFTYPE_UNSPECIFIED
:
1206 bt_msr
|= MSR_NOLINK
;
1207 ledaction
= LED_CTL_LINK
;
1208 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1209 "Set Network type to NO LINK!\n");
1211 case NL80211_IFTYPE_ADHOC
:
1212 bt_msr
|= MSR_ADHOC
;
1213 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1214 "Set Network type to Ad Hoc!\n");
1216 case NL80211_IFTYPE_STATION
:
1217 bt_msr
|= MSR_INFRA
;
1218 ledaction
= LED_CTL_LINK
;
1219 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1220 "Set Network type to STA!\n");
1222 case NL80211_IFTYPE_AP
:
1224 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1225 "Set Network type to AP!\n");
1227 case NL80211_IFTYPE_MESH_POINT
:
1228 bt_msr
|= MSR_ADHOC
;
1229 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1230 "Set Network type to Mesh Point!\n");
1233 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1234 "Network type %d not support!\n", type
);
1238 rtl_write_byte(rtlpriv
, (MSR
), bt_msr
);
1239 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1240 if ((bt_msr
& 0xfc) == MSR_AP
)
1241 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1243 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1247 void rtl88ee_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1249 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1250 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1251 u32 reg_rcr
= rtlpci
->receive_config
;
1253 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1256 if (check_bssid
== true) {
1257 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1258 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1260 _rtl88ee_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1261 } else if (check_bssid
== false) {
1262 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1263 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1264 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1265 HW_VAR_RCR
, (u8
*)(®_rcr
));
1269 int rtl88ee_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1273 if (_rtl88ee_set_media_status(hw
, type
))
1276 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1277 if (type
!= NL80211_IFTYPE_AP
&&
1278 type
!= NL80211_IFTYPE_MESH_POINT
)
1279 rtl88ee_set_check_bssid(hw
, true);
1281 rtl88ee_set_check_bssid(hw
, false);
1287 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1288 void rtl88ee_set_qos(struct ieee80211_hw
*hw
, int aci
)
1290 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1291 rtl88e_dm_init_edca_turbo(hw
);
1294 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1299 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1302 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1305 RT_ASSERT(false, "invalid aci: %d !\n", aci
);
1310 void rtl88ee_enable_interrupt(struct ieee80211_hw
*hw
)
1312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1313 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1315 rtl_write_dword(rtlpriv
, REG_HIMR
, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1316 rtl_write_dword(rtlpriv
, REG_HIMRE
, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1317 rtlpci
->irq_enabled
= true;
1318 /* there are some C2H CMDs have been sent before system interrupt
1319 * is enabled, e.g., C2H, CPWM.
1320 * So we need to clear all C2H events that FW has notified, otherwise
1321 * FW won't schedule any commands anymore.
1323 rtl_write_byte(rtlpriv
, REG_C2HEVT_CLEAR
, 0);
1324 /*enable system interrupt*/
1325 rtl_write_dword(rtlpriv
, REG_HSIMR
, rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
1328 void rtl88ee_disable_interrupt(struct ieee80211_hw
*hw
)
1330 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1331 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1333 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
1334 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
1335 rtlpci
->irq_enabled
= false;
1336 synchronize_irq(rtlpci
->pdev
->irq
);
1339 static void _rtl88ee_poweroff_adapter(struct ieee80211_hw
*hw
)
1341 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1342 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1345 rtlhal
->mac_func_enable
= false;
1346 rtlpriv
->intf_ops
->enable_aspm(hw
);
1348 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "POWER OFF adapter\n");
1349 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_TX_RPT_CTRL
);
1350 rtl_write_byte(rtlpriv
, REG_TX_RPT_CTRL
, u1b_tmp
& (~BIT(1)));
1352 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1353 while (!(u1b_tmp
& BIT(1)) && (count
++ < 100)) {
1355 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1358 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+1, 0xFF);
1360 rtl88_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1362 Rtl8188E_NIC_LPS_ENTER_FLOW
);
1364 rtl_write_byte(rtlpriv
, REG_RF_CTRL
, 0x00);
1366 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) && rtlhal
->fw_ready
)
1367 rtl88e_firmware_selfreset(hw
);
1369 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+1);
1370 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, (u1b_tmp
& (~BIT(2))));
1371 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1373 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_32K_CTRL
);
1374 rtl_write_byte(rtlpriv
, REG_32K_CTRL
, (u1b_tmp
& (~BIT(0))));
1376 rtl88_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1377 PWR_INTF_PCI_MSK
, Rtl8188E_NIC_DISABLE_FLOW
);
1379 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1380 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
& (~BIT(3))));
1381 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+1);
1382 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+1, (u1b_tmp
| BIT(3)));
1384 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1386 u1b_tmp
= rtl_read_byte(rtlpriv
, GPIO_IN
);
1387 rtl_write_byte(rtlpriv
, GPIO_OUT
, u1b_tmp
);
1388 rtl_write_byte(rtlpriv
, GPIO_IO_SEL
, 0x7F);
1390 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
1391 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
, (u1b_tmp
<< 4) | u1b_tmp
);
1392 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
+1);
1393 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL
+1, u1b_tmp
| 0x0F);
1395 rtl_write_dword(rtlpriv
, REG_GPIO_IO_SEL_2
+2, 0x00080808);
1398 void rtl88ee_card_disable(struct ieee80211_hw
*hw
)
1400 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1401 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1402 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1403 enum nl80211_iftype opmode
;
1405 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "RTL8188ee card disable\n");
1407 mac
->link_state
= MAC80211_NOLINK
;
1408 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1410 _rtl88ee_set_media_status(hw
, opmode
);
1412 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1413 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1414 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1416 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1417 _rtl88ee_poweroff_adapter(hw
);
1419 /* after power off we should do iqk again */
1420 rtlpriv
->phy
.iqk_initialized
= false;
1423 void rtl88ee_interrupt_recognized(struct ieee80211_hw
*hw
,
1424 u32
*p_inta
, u32
*p_intb
)
1426 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1427 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1429 *p_inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1430 rtl_write_dword(rtlpriv
, ISR
, *p_inta
);
1432 *p_intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) & rtlpci
->irq_mask
[1];
1433 rtl_write_dword(rtlpriv
, REG_HISRE
, *p_intb
);
1436 void rtl88ee_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1438 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1439 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1440 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1441 u16 bcn_interval
, atim_window
;
1443 bcn_interval
= mac
->beacon_interval
;
1444 atim_window
= 2; /*FIX MERGE */
1445 rtl88ee_disable_interrupt(hw
);
1446 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1447 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1448 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1449 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1450 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1451 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1452 rtlpci
->reg_bcn_ctrl_val
|= BIT(3);
1453 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlpci
->reg_bcn_ctrl_val
);
1454 /*rtl88ee_enable_interrupt(hw);*/
1457 void rtl88ee_set_beacon_interval(struct ieee80211_hw
*hw
)
1459 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1460 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1461 u16 bcn_interval
= mac
->beacon_interval
;
1463 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1464 "beacon_interval:%d\n", bcn_interval
);
1465 /*rtl88ee_disable_interrupt(hw);*/
1466 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1467 /*rtl88ee_enable_interrupt(hw);*/
1470 void rtl88ee_update_interrupt_mask(struct ieee80211_hw
*hw
,
1471 u32 add_msr
, u32 rm_msr
)
1473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1474 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1476 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1477 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1479 rtl88ee_disable_interrupt(hw
);
1481 rtlpci
->irq_mask
[0] |= add_msr
;
1483 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1484 rtl88ee_enable_interrupt(hw
);
1487 static inline u8
get_chnl_group(u8 chnl
)
1498 static void set_diff0_2g(struct txpower_info_2g
*pwr2g
, u8
*hwinfo
, u32 path
,
1501 pwr2g
->bw40_diff
[path
][i
] = 0;
1502 if (hwinfo
[eadr
] == 0xFF) {
1503 pwr2g
->bw20_diff
[path
][i
] = 0x02;
1505 pwr2g
->bw20_diff
[path
][i
] = (hwinfo
[eadr
]&0xf0)>>4;
1506 /*bit sign number to 8 bit sign number*/
1507 if (pwr2g
->bw20_diff
[path
][i
] & BIT(3))
1508 pwr2g
->bw20_diff
[path
][i
] |= 0xF0;
1511 if (hwinfo
[eadr
] == 0xFF) {
1512 pwr2g
->ofdm_diff
[path
][i
] = 0x04;
1514 pwr2g
->ofdm_diff
[path
][i
] = (hwinfo
[eadr
] & 0x0f);
1515 /*bit sign number to 8 bit sign number*/
1516 if (pwr2g
->ofdm_diff
[path
][i
] & BIT(3))
1517 pwr2g
->ofdm_diff
[path
][i
] |= 0xF0;
1519 pwr2g
->cck_diff
[path
][i
] = 0;
1522 static void set_diff0_5g(struct txpower_info_5g
*pwr5g
, u8
*hwinfo
, u32 path
,
1525 pwr5g
->bw40_diff
[path
][i
] = 0;
1526 if (hwinfo
[eadr
] == 0xFF) {
1527 pwr5g
->bw20_diff
[path
][i
] = 0;
1529 pwr5g
->bw20_diff
[path
][i
] = (hwinfo
[eadr
]&0xf0)>>4;
1530 /*bit sign number to 8 bit sign number*/
1531 if (pwr5g
->bw20_diff
[path
][i
] & BIT(3))
1532 pwr5g
->bw20_diff
[path
][i
] |= 0xF0;
1535 if (hwinfo
[eadr
] == 0xFF) {
1536 pwr5g
->ofdm_diff
[path
][i
] = 0x04;
1538 pwr5g
->ofdm_diff
[path
][i
] = (hwinfo
[eadr
] & 0x0f);
1539 /*bit sign number to 8 bit sign number*/
1540 if (pwr5g
->ofdm_diff
[path
][i
] & BIT(3))
1541 pwr5g
->ofdm_diff
[path
][i
] |= 0xF0;
1545 static void set_diff1_2g(struct txpower_info_2g
*pwr2g
, u8
*hwinfo
, u32 path
,
1548 if (hwinfo
[eadr
] == 0xFF) {
1549 pwr2g
->bw40_diff
[path
][i
] = 0xFE;
1551 pwr2g
->bw40_diff
[path
][i
] = (hwinfo
[eadr
]&0xf0)>>4;
1552 if (pwr2g
->bw40_diff
[path
][i
] & BIT(3))
1553 pwr2g
->bw40_diff
[path
][i
] |= 0xF0;
1556 if (hwinfo
[eadr
] == 0xFF) {
1557 pwr2g
->bw20_diff
[path
][i
] = 0xFE;
1559 pwr2g
->bw20_diff
[path
][i
] = (hwinfo
[eadr
]&0x0f);
1560 if (pwr2g
->bw20_diff
[path
][i
] & BIT(3))
1561 pwr2g
->bw20_diff
[path
][i
] |= 0xF0;
1565 static void set_diff1_5g(struct txpower_info_5g
*pwr5g
, u8
*hwinfo
, u32 path
,
1568 if (hwinfo
[eadr
] == 0xFF) {
1569 pwr5g
->bw40_diff
[path
][i
] = 0xFE;
1571 pwr5g
->bw40_diff
[path
][i
] = (hwinfo
[eadr
]&0xf0)>>4;
1572 if (pwr5g
->bw40_diff
[path
][i
] & BIT(3))
1573 pwr5g
->bw40_diff
[path
][i
] |= 0xF0;
1576 if (hwinfo
[eadr
] == 0xFF) {
1577 pwr5g
->bw20_diff
[path
][i
] = 0xFE;
1579 pwr5g
->bw20_diff
[path
][i
] = (hwinfo
[eadr
] & 0x0f);
1580 if (pwr5g
->bw20_diff
[path
][i
] & BIT(3))
1581 pwr5g
->bw20_diff
[path
][i
] |= 0xF0;
1585 static void set_diff2_2g(struct txpower_info_2g
*pwr2g
, u8
*hwinfo
, u32 path
,
1588 if (hwinfo
[eadr
] == 0xFF) {
1589 pwr2g
->ofdm_diff
[path
][i
] = 0xFE;
1591 pwr2g
->ofdm_diff
[path
][i
] = (hwinfo
[eadr
]&0xf0)>>4;
1592 if (pwr2g
->ofdm_diff
[path
][i
] & BIT(3))
1593 pwr2g
->ofdm_diff
[path
][i
] |= 0xF0;
1596 if (hwinfo
[eadr
] == 0xFF) {
1597 pwr2g
->cck_diff
[path
][i
] = 0xFE;
1599 pwr2g
->cck_diff
[path
][i
] = (hwinfo
[eadr
]&0x0f);
1600 if (pwr2g
->cck_diff
[path
][i
] & BIT(3))
1601 pwr2g
->cck_diff
[path
][i
] |= 0xF0;
1605 static void _rtl8188e_read_power_value_fromprom(struct ieee80211_hw
*hw
,
1606 struct txpower_info_2g
*pwr2g
,
1607 struct txpower_info_5g
*pwr5g
,
1611 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1612 u32 path
, eadr
= EEPROM_TX_PWR_INX
, i
;
1614 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1615 "hal_ReadPowerValueFromPROM88E(): PROMContent[0x%x]= 0x%x\n",
1616 (eadr
+1), hwinfo
[eadr
+1]);
1617 if (0xFF == hwinfo
[eadr
+1])
1618 autoload_fail
= true;
1620 if (autoload_fail
) {
1621 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1622 "auto load fail : Use Default value!\n");
1623 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1624 /* 2.4G default value */
1625 for (i
= 0; i
< MAX_CHNL_GROUP_24G
; i
++) {
1626 pwr2g
->index_cck_base
[path
][i
] = 0x2D;
1627 pwr2g
->index_bw40_base
[path
][i
] = 0x2D;
1629 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
1631 pwr2g
->bw20_diff
[path
][0] = 0x02;
1632 pwr2g
->ofdm_diff
[path
][0] = 0x04;
1634 pwr2g
->bw20_diff
[path
][i
] = 0xFE;
1635 pwr2g
->bw40_diff
[path
][i
] = 0xFE;
1636 pwr2g
->cck_diff
[path
][i
] = 0xFE;
1637 pwr2g
->ofdm_diff
[path
][i
] = 0xFE;
1644 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1645 /*2.4G default value*/
1646 for (i
= 0; i
< MAX_CHNL_GROUP_24G
; i
++) {
1647 pwr2g
->index_cck_base
[path
][i
] = hwinfo
[eadr
++];
1648 if (pwr2g
->index_cck_base
[path
][i
] == 0xFF)
1649 pwr2g
->index_cck_base
[path
][i
] = 0x2D;
1651 for (i
= 0; i
< MAX_CHNL_GROUP_24G
; i
++) {
1652 pwr2g
->index_bw40_base
[path
][i
] = hwinfo
[eadr
++];
1653 if (pwr2g
->index_bw40_base
[path
][i
] == 0xFF)
1654 pwr2g
->index_bw40_base
[path
][i
] = 0x2D;
1656 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
1658 set_diff0_2g(pwr2g
, hwinfo
, path
, i
, eadr
);
1661 set_diff1_2g(pwr2g
, hwinfo
, path
, i
, eadr
);
1664 set_diff2_2g(pwr2g
, hwinfo
, path
, i
, eadr
);
1669 /*5G default value*/
1670 for (i
= 0; i
< MAX_CHNL_GROUP_5G
; i
++) {
1671 pwr5g
->index_bw40_base
[path
][i
] = hwinfo
[eadr
++];
1672 if (pwr5g
->index_bw40_base
[path
][i
] == 0xFF)
1673 pwr5g
->index_bw40_base
[path
][i
] = 0xFE;
1676 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
1678 set_diff0_5g(pwr5g
, hwinfo
, path
, i
, eadr
);
1681 set_diff1_5g(pwr5g
, hwinfo
, path
, i
, eadr
);
1686 if (hwinfo
[eadr
] == 0xFF) {
1687 pwr5g
->ofdm_diff
[path
][1] = 0xFE;
1688 pwr5g
->ofdm_diff
[path
][2] = 0xFE;
1690 pwr5g
->ofdm_diff
[path
][1] = (hwinfo
[eadr
] & 0xf0) >> 4;
1691 pwr5g
->ofdm_diff
[path
][2] = (hwinfo
[eadr
] & 0x0f);
1695 if (hwinfo
[eadr
] == 0xFF)
1696 pwr5g
->ofdm_diff
[path
][3] = 0xFE;
1698 pwr5g
->ofdm_diff
[path
][3] = (hwinfo
[eadr
]&0x0f);
1701 for (i
= 1; i
< MAX_TX_COUNT
; i
++) {
1702 if (pwr5g
->ofdm_diff
[path
][i
] == 0xFF)
1703 pwr5g
->ofdm_diff
[path
][i
] = 0xFE;
1704 else if (pwr5g
->ofdm_diff
[path
][i
] & BIT(3))
1705 pwr5g
->ofdm_diff
[path
][i
] |= 0xF0;
1710 static void _rtl88ee_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1714 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1715 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1716 struct txpower_info_2g pwrinfo24g
;
1717 struct txpower_info_5g pwrinfo5g
;
1720 int jj
= EEPROM_RF_BOARD_OPTION_88E
;
1721 int kk
= EEPROM_THERMAL_METER_88E
;
1723 _rtl8188e_read_power_value_fromprom(hw
, &pwrinfo24g
, &pwrinfo5g
,
1724 autoload_fail
, hwinfo
);
1726 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1727 for (i
= 0; i
< 14; i
++) {
1728 index
= get_chnl_group(i
+1);
1730 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1731 pwrinfo24g
.index_cck_base
[rf_path
][index
];
1733 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1734 pwrinfo24g
.index_bw40_base
[rf_path
][4];
1736 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1737 pwrinfo24g
.index_bw40_base
[rf_path
][index
];
1738 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
1739 pwrinfo24g
.bw20_diff
[rf_path
][0];
1740 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
1741 pwrinfo24g
.ofdm_diff
[rf_path
][0];
1744 for (i
= 0; i
< 14; i
++) {
1745 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1746 "RF(%d)-Ch(%d) [CCK / HT40_1S ] = "
1747 "[0x%x / 0x%x ]\n", rf_path
, i
,
1748 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1749 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
]);
1754 rtlefuse
->eeprom_thermalmeter
= hwinfo
[kk
];
1756 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1758 if (rtlefuse
->eeprom_thermalmeter
== 0xff || autoload_fail
) {
1759 rtlefuse
->apk_thermalmeterignore
= true;
1760 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1763 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1764 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1765 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1767 if (!autoload_fail
) {
1768 rtlefuse
->eeprom_regulatory
= hwinfo
[jj
] & 0x07;/*bit0~2*/
1769 if (hwinfo
[jj
] == 0xFF)
1770 rtlefuse
->eeprom_regulatory
= 0;
1772 rtlefuse
->eeprom_regulatory
= 0;
1774 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1775 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
1778 static void _rtl88ee_read_adapter_info(struct ieee80211_hw
*hw
)
1780 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1781 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1782 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1783 struct rtl_pci_priv
*rppriv
= rtl_pcipriv(hw
);
1785 u8 hwinfo
[HWSET_MAX_SIZE
];
1787 int jj
= EEPROM_RF_BOARD_OPTION_88E
;
1788 int kk
= EEPROM_RF_FEATURE_OPTION_88E
;
1790 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
1791 rtl_efuse_shadow_map_update(hw
);
1793 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
1795 } else if (rtlefuse
->epromtype
== EEPROM_93C46
) {
1796 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1797 "RTL819X Not boot from eeprom, check it !!");
1800 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("MAP\n"),
1801 hwinfo
, HWSET_MAX_SIZE
);
1803 eeprom_id
= *((u16
*)&hwinfo
[0]);
1804 if (eeprom_id
!= RTL8188E_EEPROM_ID
) {
1805 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1806 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1807 rtlefuse
->autoload_failflag
= true;
1809 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1810 rtlefuse
->autoload_failflag
= false;
1813 if (rtlefuse
->autoload_failflag
== true)
1815 /*VID DID SVID SDID*/
1816 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
1817 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
1818 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[EEPROM_SVID
];
1819 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[EEPROM_SMID
];
1820 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1821 "EEPROMId = 0x%4x\n", eeprom_id
);
1822 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1823 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1824 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1825 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1826 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1827 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1828 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1829 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1831 rtlefuse
->eeprom_oemid
= *(u8
*)&hwinfo
[EEPROM_CUSTOMER_ID
];
1832 if (rtlefuse
->eeprom_oemid
== 0xFF)
1833 rtlefuse
->eeprom_oemid
= 0;
1835 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1836 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1838 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
1840 for (i
= 0; i
< 6; i
+= 2) {
1841 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
1842 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
1845 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1846 "dev_addr: %pM\n", rtlefuse
->dev_addr
);
1848 rtlefuse
->eeprom_channelplan
= *(u8
*)&hwinfo
[EEPROM_CHANNELPLAN
];
1849 /* set channel paln to world wide 13 */
1850 rtlefuse
->channel_plan
= COUNTRY_CODE_WORLD_WIDE_13
;
1852 _rtl88ee_read_txpower_info_from_hwpg(hw
, rtlefuse
->autoload_failflag
,
1854 rtlefuse
->txpwr_fromeprom
= true;
1856 rtl8188ee_read_bt_coexist_info_from_hwpg(hw
,
1857 rtlefuse
->autoload_failflag
,
1860 rtlefuse
->board_type
= (((*(u8
*)&hwinfo
[jj
]) & 0xE0) >> 5);
1862 rtlefuse
->wowlan_enable
= ((hwinfo
[kk
] & 0x40) >> 6);
1864 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_88E
];
1865 if (hwinfo
[EEPROM_XTAL_88E
])
1866 rtlefuse
->crystalcap
= 0x20;
1867 /*antenna diversity*/
1868 rtlefuse
->antenna_div_cfg
= (hwinfo
[jj
] & 0x18) >> 3;
1869 if (hwinfo
[jj
] == 0xFF)
1870 rtlefuse
->antenna_div_cfg
= 0;
1871 if (rppriv
->bt_coexist
.eeprom_bt_coexist
!= 0 &&
1872 rppriv
->bt_coexist
.eeprom_bt_ant_num
== ANT_X1
)
1873 rtlefuse
->antenna_div_cfg
= 0;
1875 rtlefuse
->antenna_div_type
= hwinfo
[EEPROM_RF_ANTENNA_OPT_88E
];
1876 if (rtlefuse
->antenna_div_type
== 0xFF)
1877 rtlefuse
->antenna_div_type
= 0x01;
1878 if (rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
||
1879 rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)
1880 rtlefuse
->antenna_div_cfg
= 1;
1882 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
1883 switch (rtlefuse
->eeprom_oemid
) {
1884 case EEPROM_CID_DEFAULT
:
1885 if (rtlefuse
->eeprom_did
== 0x8179) {
1886 if (rtlefuse
->eeprom_svid
== 0x1025) {
1887 rtlhal
->oem_id
= RT_CID_819x_Acer
;
1888 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
1889 rtlefuse
->eeprom_smid
== 0x0179) ||
1890 (rtlefuse
->eeprom_svid
== 0x17AA &&
1891 rtlefuse
->eeprom_smid
== 0x0179)) {
1892 rtlhal
->oem_id
= RT_CID_819x_Lenovo
;
1893 } else if (rtlefuse
->eeprom_svid
== 0x103c &&
1894 rtlefuse
->eeprom_smid
== 0x197d) {
1895 rtlhal
->oem_id
= RT_CID_819x_HP
;
1897 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1900 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1903 case EEPROM_CID_TOSHIBA
:
1904 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
1906 case EEPROM_CID_QMI
:
1907 rtlhal
->oem_id
= RT_CID_819x_QMI
;
1909 case EEPROM_CID_WHQL
:
1911 rtlhal
->oem_id
= RT_CID_DEFAULT
;
1917 static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw
*hw
)
1919 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1920 struct rtl_pci_priv
*pcipriv
= rtl_pcipriv(hw
);
1921 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1923 pcipriv
->ledctl
.led_opendrain
= true;
1925 switch (rtlhal
->oem_id
) {
1926 case RT_CID_819x_HP
:
1927 pcipriv
->ledctl
.led_opendrain
= true;
1929 case RT_CID_819x_Lenovo
:
1930 case RT_CID_DEFAULT
:
1931 case RT_CID_TOSHIBA
:
1933 case RT_CID_819x_Acer
:
1938 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1939 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
1942 void rtl88ee_read_eeprom_info(struct ieee80211_hw
*hw
)
1944 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1945 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1946 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1947 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1950 rtlhal
->version
= _rtl88ee_read_chip_version(hw
);
1951 if (get_rf_type(rtlphy
) == RF_1T1R
) {
1952 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
1954 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
1955 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
1957 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
1959 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
1960 if (tmp_u1b
& BIT(4)) {
1961 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
1962 rtlefuse
->epromtype
= EEPROM_93C46
;
1964 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
1965 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
1967 if (tmp_u1b
& BIT(5)) {
1968 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1969 rtlefuse
->autoload_failflag
= false;
1970 _rtl88ee_read_adapter_info(hw
);
1972 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "Autoload ERR!!\n");
1974 _rtl88ee_hal_customized_behavior(hw
);
1977 static void rtl88ee_update_hal_rate_table(struct ieee80211_hw
*hw
,
1978 struct ieee80211_sta
*sta
)
1980 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1981 struct rtl_pci_priv
*rppriv
= rtl_pcipriv(hw
);
1982 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1983 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1984 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1987 u8 nmode
= mac
->ht_enable
;
1988 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
1991 u8 ctx40
= mac
->bw_40
;
1992 u16 cap
= sta
->ht_cap
.cap
;
1993 u8 short40
= (cap
& IEEE80211_HT_CAP_SGI_40
) ? 1 : 0;
1994 u8 short20
= (cap
& IEEE80211_HT_CAP_SGI_20
) ? 1 : 0;
1995 enum wireless_mode wirelessmode
= mac
->mode
;
1997 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1998 ratr_value
= sta
->supp_rates
[1] << 4;
2000 ratr_value
= sta
->supp_rates
[0];
2001 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2003 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2004 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2005 switch (wirelessmode
) {
2006 case WIRELESS_MODE_B
:
2007 if (ratr_value
& 0x0000000c)
2008 ratr_value
&= 0x0000000d;
2010 ratr_value
&= 0x0000000f;
2012 case WIRELESS_MODE_G
:
2013 ratr_value
&= 0x00000FF5;
2015 case WIRELESS_MODE_N_24G
:
2016 case WIRELESS_MODE_N_5G
:
2018 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2019 ratr_value
&= 0x0007F005;
2023 if (get_rf_type(rtlphy
) == RF_1T2R
||
2024 get_rf_type(rtlphy
) == RF_1T1R
)
2025 ratr_mask
= 0x000ff005;
2027 ratr_mask
= 0x0f0ff005;
2029 ratr_value
&= ratr_mask
;
2033 if (rtlphy
->rf_type
== RF_1T2R
)
2034 ratr_value
&= 0x000ff0ff;
2036 ratr_value
&= 0x0f0ff0ff;
2041 if ((rppriv
->bt_coexist
.bt_coexistence
) &&
2042 (rppriv
->bt_coexist
.bt_coexist_type
== BT_CSR_BC4
) &&
2043 (rppriv
->bt_coexist
.bt_cur_state
) &&
2044 (rppriv
->bt_coexist
.bt_ant_isolation
) &&
2045 ((rppriv
->bt_coexist
.bt_service
== BT_SCO
) ||
2046 (rppriv
->bt_coexist
.bt_service
== BT_BUSY
)))
2047 ratr_value
&= 0x0fffcfc0;
2049 ratr_value
&= 0x0FFFFFFF;
2051 if (nmode
&& ((ctx40
&& short40
) ||
2052 (!ctx40
&& short20
))) {
2053 ratr_value
|= 0x10000000;
2054 tmp_ratr_value
= (ratr_value
>> 12);
2056 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2057 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2061 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2062 (shortgi_rate
<< 4) | (shortgi_rate
);
2065 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2067 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2068 "%x\n", rtl_read_dword(rtlpriv
, REG_ARFR0
));
2071 static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2072 struct ieee80211_sta
*sta
, u8 rssi
)
2074 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2075 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2076 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2077 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2078 struct rtl_sta_info
*sta_entry
= NULL
;
2081 u16 cap
= sta
->ht_cap
.cap
;
2082 u8 ctx40
= (cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ? 1 : 0;
2083 u8 short40
= (cap
& IEEE80211_HT_CAP_SGI_40
) ? 1 : 0;
2084 u8 short20
= (cap
& IEEE80211_HT_CAP_SGI_20
) ? 1 : 0;
2085 enum wireless_mode wirelessmode
= 0;
2086 bool shortgi
= false;
2089 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2091 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
2092 wirelessmode
= sta_entry
->wireless_mode
;
2093 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2094 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2096 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2097 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2098 macid
= sta
->aid
+ 1;
2100 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2101 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2103 ratr_bitmap
= sta
->supp_rates
[0];
2104 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2105 ratr_bitmap
= 0xfff;
2106 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2107 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2108 switch (wirelessmode
) {
2109 case WIRELESS_MODE_B
:
2110 ratr_index
= RATR_INX_WIRELESS_B
;
2111 if (ratr_bitmap
& 0x0000000c)
2112 ratr_bitmap
&= 0x0000000d;
2114 ratr_bitmap
&= 0x0000000f;
2116 case WIRELESS_MODE_G
:
2117 ratr_index
= RATR_INX_WIRELESS_GB
;
2120 ratr_bitmap
&= 0x00000f00;
2122 ratr_bitmap
&= 0x00000ff0;
2124 ratr_bitmap
&= 0x00000ff5;
2126 case WIRELESS_MODE_A
:
2127 ratr_index
= RATR_INX_WIRELESS_A
;
2128 ratr_bitmap
&= 0x00000ff0;
2130 case WIRELESS_MODE_N_24G
:
2131 case WIRELESS_MODE_N_5G
:
2132 ratr_index
= RATR_INX_WIRELESS_NGB
;
2134 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2136 ratr_bitmap
&= 0x00070000;
2138 ratr_bitmap
&= 0x0007f000;
2140 ratr_bitmap
&= 0x0007f005;
2142 if (rtlphy
->rf_type
== RF_1T2R
||
2143 rtlphy
->rf_type
== RF_1T1R
) {
2146 ratr_bitmap
&= 0x000f0000;
2148 ratr_bitmap
&= 0x000ff000;
2150 ratr_bitmap
&= 0x000ff015;
2153 ratr_bitmap
&= 0x000f0000;
2155 ratr_bitmap
&= 0x000ff000;
2157 ratr_bitmap
&= 0x000ff005;
2162 ratr_bitmap
&= 0x0f8f0000;
2164 ratr_bitmap
&= 0x0f8ff000;
2166 ratr_bitmap
&= 0x0f8ff015;
2169 ratr_bitmap
&= 0x0f8f0000;
2171 ratr_bitmap
&= 0x0f8ff000;
2173 ratr_bitmap
&= 0x0f8ff005;
2178 if ((ctx40
&& short40
) || (!ctx40
&& short20
)) {
2181 else if (macid
== 1)
2186 ratr_index
= RATR_INX_WIRELESS_NGB
;
2188 if (rtlphy
->rf_type
== RF_1T2R
)
2189 ratr_bitmap
&= 0x000ff0ff;
2191 ratr_bitmap
&= 0x0f0ff0ff;
2194 sta_entry
->ratr_index
= ratr_index
;
2196 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2197 "ratr_bitmap :%x\n", ratr_bitmap
);
2198 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2200 rate_mask
[4] = macid
| (shortgi
? 0x20 : 0x00) | 0x80;
2201 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2202 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
2203 ratr_index
, ratr_bitmap
, rate_mask
[0], rate_mask
[1],
2204 rate_mask
[2], rate_mask
[3], rate_mask
[4]);
2205 rtl88e_fill_h2c_cmd(hw
, H2C_88E_RA_MASK
, 5, rate_mask
);
2206 _rtl88ee_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2209 void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2210 struct ieee80211_sta
*sta
, u8 rssi
)
2212 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2214 if (rtlpriv
->dm
.useramask
)
2215 rtl88ee_update_hal_rate_mask(hw
, sta
, rssi
);
2217 rtl88ee_update_hal_rate_table(hw
, sta
);
2220 void rtl88ee_update_channel_access_setting(struct ieee80211_hw
*hw
)
2222 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2223 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2226 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2227 (u8
*)&mac
->slot_time
);
2228 if (!mac
->ht_enable
)
2229 sifs_timer
= 0x0a0a;
2231 sifs_timer
= 0x0e0e;
2232 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2235 bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2237 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2238 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2239 enum rf_pwrstate state_toset
;
2241 bool actuallyset
= false;
2243 if (rtlpriv
->rtlhal
.being_init_adapter
)
2246 if (ppsc
->swrf_processing
)
2249 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2250 if (ppsc
->rfchange_inprogress
) {
2251 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2254 ppsc
->rfchange_inprogress
= true;
2255 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2258 u4tmp
= rtl_read_dword(rtlpriv
, REG_GPIO_OUTPUT
);
2259 state_toset
= (u4tmp
& BIT(31)) ? ERFON
: ERFOFF
;
2262 if ((ppsc
->hwradiooff
== true) && (state_toset
== ERFON
)) {
2263 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2264 "GPIOChangeRF - HW Radio ON, RF ON\n");
2266 state_toset
= ERFON
;
2267 ppsc
->hwradiooff
= false;
2269 } else if ((ppsc
->hwradiooff
== false) && (state_toset
== ERFOFF
)) {
2270 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2271 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2273 state_toset
= ERFOFF
;
2274 ppsc
->hwradiooff
= true;
2279 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2280 ppsc
->rfchange_inprogress
= false;
2281 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2283 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2284 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2286 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2287 ppsc
->rfchange_inprogress
= false;
2288 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2292 return !ppsc
->hwradiooff
;
2295 static void add_one_key(struct ieee80211_hw
*hw
, u8
*macaddr
,
2296 struct rtl_mac
*mac
, u32 key
, u32 id
,
2297 u8 enc_algo
, bool is_pairwise
)
2299 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2300 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2302 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "add one entry\n");
2304 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "set Pairwise key\n");
2306 rtl_cam_add_one_entry(hw
, macaddr
, key
, id
, enc_algo
,
2307 CAM_CONFIG_NO_USEDK
,
2308 rtlpriv
->sec
.key_buf
[key
]);
2310 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "set group key\n");
2312 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2313 rtl_cam_add_one_entry(hw
, rtlefuse
->dev_addr
,
2315 CAM_PAIRWISE_KEY_POSITION
,
2317 CAM_CONFIG_NO_USEDK
,
2318 rtlpriv
->sec
.key_buf
[id
]);
2321 rtl_cam_add_one_entry(hw
, macaddr
, key
, id
, enc_algo
,
2322 CAM_CONFIG_NO_USEDK
,
2323 rtlpriv
->sec
.key_buf
[id
]);
2327 void rtl88ee_set_key(struct ieee80211_hw
*hw
, u32 key
,
2328 u8
*mac_ad
, bool is_group
, u8 enc_algo
,
2329 bool is_wepkey
, bool clear_all
)
2331 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2332 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2333 u8
*macaddr
= mac_ad
;
2335 bool is_pairwise
= false;
2337 static u8 cam_const_addr
[4][6] = {
2338 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2339 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2340 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2341 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2343 static u8 cam_const_broad
[] = {
2344 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2350 u8 clear_number
= 5;
2352 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2354 for (idx
= 0; idx
< clear_number
; idx
++) {
2355 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2356 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2359 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2361 rtlpriv
->sec
.key_len
[idx
] = 0;
2367 case WEP40_ENCRYPTION
:
2368 enc_algo
= CAM_WEP40
;
2370 case WEP104_ENCRYPTION
:
2371 enc_algo
= CAM_WEP104
;
2373 case TKIP_ENCRYPTION
:
2374 enc_algo
= CAM_TKIP
;
2376 case AESCCMP_ENCRYPTION
:
2380 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2381 "switch case not processed\n");
2382 enc_algo
= CAM_TKIP
;
2386 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2387 macaddr
= cam_const_addr
[key
];
2391 macaddr
= cam_const_broad
;
2394 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2395 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
2396 id
= rtl_cam_get_free_entry(hw
, mac_ad
);
2397 if (id
>= TOTAL_CAM_ENTRY
) {
2398 RT_TRACE(rtlpriv
, COMP_SEC
,
2400 "Can not find free hw security cam entry\n");
2404 id
= CAM_PAIRWISE_KEY_POSITION
;
2407 key
= PAIRWISE_KEYIDX
;
2412 if (rtlpriv
->sec
.key_len
[key
] == 0) {
2413 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2414 "delete one entry, id is %d\n", id
);
2415 if (mac
->opmode
== NL80211_IFTYPE_AP
||
2416 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2417 rtl_cam_del_entry(hw
, mac_ad
);
2418 rtl_cam_delete_one_entry(hw
, mac_ad
, id
);
2420 add_one_key(hw
, macaddr
, mac
, key
, id
, enc_algo
,
2426 static void rtl8188ee_bt_var_init(struct ieee80211_hw
*hw
)
2428 struct rtl_pci_priv
*rppriv
= rtl_pcipriv(hw
);
2429 struct bt_coexist_info coexist
= rppriv
->bt_coexist
;
2431 coexist
.bt_coexistence
= rppriv
->bt_coexist
.eeprom_bt_coexist
;
2432 coexist
.bt_ant_num
= coexist
.eeprom_bt_ant_num
;
2433 coexist
.bt_coexist_type
= coexist
.eeprom_bt_type
;
2435 if (coexist
.reg_bt_iso
== 2)
2436 coexist
.bt_ant_isolation
= coexist
.eeprom_bt_ant_isol
;
2438 coexist
.bt_ant_isolation
= coexist
.reg_bt_iso
;
2440 coexist
.bt_radio_shared_type
= coexist
.eeprom_bt_radio_shared
;
2442 if (coexist
.bt_coexistence
) {
2443 if (coexist
.reg_bt_sco
== 1)
2444 coexist
.bt_service
= BT_OTHER_ACTION
;
2445 else if (coexist
.reg_bt_sco
== 2)
2446 coexist
.bt_service
= BT_SCO
;
2447 else if (coexist
.reg_bt_sco
== 4)
2448 coexist
.bt_service
= BT_BUSY
;
2449 else if (coexist
.reg_bt_sco
== 5)
2450 coexist
.bt_service
= BT_OTHERBUSY
;
2452 coexist
.bt_service
= BT_IDLE
;
2454 coexist
.bt_edca_ul
= 0;
2455 coexist
.bt_edca_dl
= 0;
2456 coexist
.bt_rssi_state
= 0xff;
2460 void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2461 bool auto_load_fail
, u8
*hwinfo
)
2463 rtl8188ee_bt_var_init(hw
);
2466 void rtl8188ee_bt_reg_init(struct ieee80211_hw
*hw
)
2468 struct rtl_pci_priv
*rppriv
= rtl_pcipriv(hw
);
2470 /* 0:Low, 1:High, 2:From Efuse. */
2471 rppriv
->bt_coexist
.reg_bt_iso
= 2;
2472 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2473 rppriv
->bt_coexist
.reg_bt_sco
= 3;
2474 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2475 rppriv
->bt_coexist
.reg_bt_sco
= 0;
2478 void rtl8188ee_bt_hw_init(struct ieee80211_hw
*hw
)
2480 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2481 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2482 struct rtl_pci_priv
*rppriv
= rtl_pcipriv(hw
);
2483 struct bt_coexist_info coexist
= rppriv
->bt_coexist
;
2486 if (coexist
.bt_coexistence
&&
2487 ((coexist
.bt_coexist_type
== BT_CSR_BC4
) ||
2488 coexist
.bt_coexist_type
== BT_CSR_BC8
)) {
2489 if (coexist
.bt_ant_isolation
)
2490 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
, 0xa0);
2492 u1_tmp
= rtl_read_byte(rtlpriv
, 0x4fd) &
2493 BIT_OFFSET_LEN_MASK_32(0, 1);
2494 u1_tmp
= u1_tmp
| ((coexist
.bt_ant_isolation
== 1) ?
2495 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
2496 ((coexist
.bt_service
== BT_SCO
) ?
2497 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
2498 rtl_write_byte(rtlpriv
, 0x4fd, u1_tmp
);
2500 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+4, 0xaaaa9aaa);
2501 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+8, 0xffbd0040);
2502 rtl_write_dword(rtlpriv
, REG_BT_COEX_TABLE
+0xc, 0x40000010);
2504 /* Config to 1T1R. */
2505 if (rtlphy
->rf_type
== RF_1T1R
) {
2506 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
);
2507 u1_tmp
&= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2508 rtl_write_byte(rtlpriv
, ROFDM0_TRXPATHENABLE
, u1_tmp
);
2510 u1_tmp
= rtl_read_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
);
2511 u1_tmp
&= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2512 rtl_write_byte(rtlpriv
, ROFDM1_TRXPATHENABLE
, u1_tmp
);
2517 void rtl88ee_suspend(struct ieee80211_hw
*hw
)
2521 void rtl88ee_resume(struct ieee80211_hw
*hw
)
2525 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
2526 void rtl88ee_allow_all_destaddr(struct ieee80211_hw
*hw
,
2527 bool allow_all_da
, bool write_into_reg
)
2529 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2530 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
2532 if (allow_all_da
) /* Set BIT0 */
2533 rtlpci
->receive_config
|= RCR_AAP
;
2534 else /* Clear BIT0 */
2535 rtlpci
->receive_config
&= ~RCR_AAP
;
2538 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
2540 RT_TRACE(rtlpriv
, COMP_TURBO
| COMP_INIT
, DBG_LOUD
,
2541 "receive_config = 0x%08X, write_into_reg =%d\n",
2542 rtlpci
->receive_config
, write_into_reg
);