1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
14 #include "../rtl8723com/phy_common.h"
16 #include "../rtl8723com/dm_common.h"
18 #include "../rtl8723com/fw_common.h"
21 #include "../pwrseqcmd.h"
23 #include "../btcoexist/rtl_btc.h"
24 #include <linux/kernel.h>
28 static void _rtl8723be_return_beacon_queue_skb(struct ieee80211_hw
*hw
)
30 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
31 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
32 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
35 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
36 while (skb_queue_len(&ring
->queue
)) {
37 struct rtl_tx_desc
*entry
= &ring
->desc
[ring
->idx
];
38 struct sk_buff
*skb
= __skb_dequeue(&ring
->queue
);
40 pci_unmap_single(rtlpci
->pdev
,
41 rtlpriv
->cfg
->ops
->get_desc(
43 (u8
*)entry
, true, HW_DESC_TXBUFF_ADDR
),
44 skb
->len
, PCI_DMA_TODEVICE
);
46 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
48 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
51 static void _rtl8723be_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
52 u8 set_bits
, u8 clear_bits
)
54 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
55 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
57 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
58 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
60 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
63 static void _rtl8723be_stop_tx_beacon(struct ieee80211_hw
*hw
)
65 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
68 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
69 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
70 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
71 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
72 tmp1byte
&= ~(BIT(0));
73 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
76 static void _rtl8723be_resume_tx_beacon(struct ieee80211_hw
*hw
)
78 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
81 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
82 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
83 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
84 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
86 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
89 static void _rtl8723be_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
91 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(1));
94 static void _rtl8723be_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
96 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(1), 0);
99 static void _rtl8723be_set_fw_clock_on(struct ieee80211_hw
*hw
, u8 rpwm_val
,
100 bool b_need_turn_off_ckk
)
102 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
103 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
104 bool b_support_remote_wake_up
;
105 u32 count
= 0, isr_regaddr
, content
;
106 bool b_schedule_timer
= b_need_turn_off_ckk
;
107 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
108 (u8
*)(&b_support_remote_wake_up
));
110 if (!rtlhal
->fw_ready
)
112 if (!rtlpriv
->psc
.fw_current_inpsmode
)
116 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
117 if (rtlhal
->fw_clk_change_in_progress
) {
118 while (rtlhal
->fw_clk_change_in_progress
) {
119 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
124 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
126 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
128 rtlhal
->fw_clk_change_in_progress
= false;
129 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
134 if (IS_IN_LOW_POWER_STATE(rtlhal
->fw_ps_state
)) {
135 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
,
137 if (FW_PS_IS_ACK(rpwm_val
)) {
138 isr_regaddr
= REG_HISR
;
139 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
140 while (!(content
& IMR_CPWM
) && (count
< 500)) {
143 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
146 if (content
& IMR_CPWM
) {
147 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
148 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON
;
149 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
150 "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
151 rtlhal
->fw_ps_state
);
155 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
156 rtlhal
->fw_clk_change_in_progress
= false;
157 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
158 if (b_schedule_timer
)
159 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
160 jiffies
+ MSECS(10));
162 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
163 rtlhal
->fw_clk_change_in_progress
= false;
164 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
168 static void _rtl8723be_set_fw_clock_off(struct ieee80211_hw
*hw
, u8 rpwm_val
)
170 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
171 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
172 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
173 struct rtl8192_tx_ring
*ring
;
174 enum rf_pwrstate rtstate
;
175 bool b_schedule_timer
= false;
178 if (!rtlhal
->fw_ready
)
180 if (!rtlpriv
->psc
.fw_current_inpsmode
)
182 if (!rtlhal
->allow_sw_to_change_hwclc
)
184 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
185 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
188 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
189 ring
= &rtlpci
->tx_ring
[queue
];
190 if (skb_queue_len(&ring
->queue
)) {
191 b_schedule_timer
= true;
196 if (b_schedule_timer
) {
197 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
198 jiffies
+ MSECS(10));
202 if (FW_PS_STATE(rtlhal
->fw_ps_state
) != FW_PS_STATE_RF_OFF_LOW_PWR
) {
203 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
204 if (!rtlhal
->fw_clk_change_in_progress
) {
205 rtlhal
->fw_clk_change_in_progress
= true;
206 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
207 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
208 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
209 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
211 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
212 rtlhal
->fw_clk_change_in_progress
= false;
213 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
215 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
216 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
217 jiffies
+ MSECS(10));
223 static void _rtl8723be_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
226 rpwm_val
|= (FW_PS_STATE_RF_OFF
| FW_PS_ACK
);
227 _rtl8723be_set_fw_clock_on(hw
, rpwm_val
, true);
230 static void _rtl8723be_fwlps_leave(struct ieee80211_hw
*hw
)
232 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
233 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
234 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
235 bool fw_current_inps
= false;
236 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
238 if (ppsc
->low_power_enable
) {
239 rpwm_val
= (FW_PS_STATE_ALL_ON
| FW_PS_ACK
);/* RF on */
240 _rtl8723be_set_fw_clock_on(hw
, rpwm_val
, false);
241 rtlhal
->allow_sw_to_change_hwclc
= false;
242 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
243 (u8
*)(&fw_pwrmode
));
244 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
245 (u8
*)(&fw_current_inps
));
247 rpwm_val
= FW_PS_STATE_ALL_ON
; /* RF on */
248 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
250 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
251 (u8
*)(&fw_pwrmode
));
252 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
253 (u8
*)(&fw_current_inps
));
258 static void _rtl8723be_fwlps_enter(struct ieee80211_hw
*hw
)
260 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
261 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
262 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
263 bool fw_current_inps
= true;
266 if (ppsc
->low_power_enable
) {
267 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR
; /* RF off */
268 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
269 (u8
*)(&fw_current_inps
));
270 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
271 (u8
*)(&ppsc
->fwctrl_psmode
));
272 rtlhal
->allow_sw_to_change_hwclc
= true;
273 _rtl8723be_set_fw_clock_off(hw
, rpwm_val
);
275 rpwm_val
= FW_PS_STATE_RF_OFF
; /* RF off */
276 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
277 (u8
*)(&fw_current_inps
));
278 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
279 (u8
*)(&ppsc
->fwctrl_psmode
));
280 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
286 void rtl8723be_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
288 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
289 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
290 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
294 *((u32
*)(val
)) = rtlpci
->receive_config
;
296 case HW_VAR_RF_STATE
:
297 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
299 case HW_VAR_FWLPS_RF_ON
:{
300 enum rf_pwrstate rfstate
;
303 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
305 if (rfstate
== ERFOFF
) {
306 *((bool *)(val
)) = true;
308 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
309 val_rcr
&= 0x00070000;
311 *((bool *)(val
)) = false;
313 *((bool *)(val
)) = true;
317 case HW_VAR_FW_PSMODE_STATUS
:
318 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
320 case HW_VAR_CORRECT_TSF
:{
322 u32
*ptsf_low
= (u32
*)&tsf
;
323 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
325 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
326 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
328 *((u64
*)(val
)) = tsf
;
334 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
335 "switch case %#x not processed\n", variable
);
340 static void _rtl8723be_download_rsvd_page(struct ieee80211_hw
*hw
)
342 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
343 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
344 u8 count
= 0, dlbcn_count
= 0;
345 bool b_recover
= false;
347 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
348 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
349 (tmp_regcr
| BIT(0)));
351 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(3));
352 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(4), 0);
354 tmp_reg422
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
355 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
& (~BIT(6)));
356 if (tmp_reg422
& BIT(6))
360 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
361 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
362 (bcnvalid_reg
| BIT(0)));
363 _rtl8723be_return_beacon_queue_skb(hw
);
365 rtl8723be_set_fw_rsvdpagepkt(hw
, 0);
366 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
368 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
371 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
375 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
377 if (bcnvalid_reg
& BIT(0))
378 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, BIT(0));
380 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
381 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(4));
384 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
);
386 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
387 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
& ~(BIT(0))));
390 void rtl8723be_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
392 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
393 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
394 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
395 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
396 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
400 case HW_VAR_ETHER_ADDR
:
401 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
402 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
), val
[idx
]);
404 case HW_VAR_BASIC_RATE
:{
405 u16 b_rate_cfg
= ((u16
*)val
)[0];
407 b_rate_cfg
= b_rate_cfg
& 0x15f;
409 rtl_write_byte(rtlpriv
, REG_RRSR
, b_rate_cfg
& 0xff);
410 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1, (b_rate_cfg
>> 8) & 0xff);
411 while (b_rate_cfg
> 0x1) {
412 b_rate_cfg
= (b_rate_cfg
>> 1);
415 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
, rate_index
);
419 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
420 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
), val
[idx
]);
424 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
425 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
427 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
428 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
431 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
, 0x0e0e);
433 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
436 case HW_VAR_SLOT_TIME
:{
439 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
440 "HW_VAR_SLOT_TIME %x\n", val
[0]);
442 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
444 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
445 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
450 case HW_VAR_ACK_PREAMBLE
:{
452 u8 short_preamble
= (bool)(*(u8
*)val
);
453 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2);
454 if (short_preamble
) {
456 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
459 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
463 case HW_VAR_WPA_CONFIG
:
464 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*)val
));
466 case HW_VAR_AMPDU_MIN_SPACE
:{
467 u8 min_spacing_to_set
;
470 min_spacing_to_set
= *((u8
*)val
);
471 if (min_spacing_to_set
<= 7) {
474 if (min_spacing_to_set
< sec_min_space
)
475 min_spacing_to_set
= sec_min_space
;
477 mac
->min_space_cfg
= ((mac
->min_space_cfg
& 0xf8) |
480 *val
= min_spacing_to_set
;
482 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
483 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
486 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
491 case HW_VAR_SHORTGI_DENSITY
:{
494 density_to_set
= *((u8
*)val
);
495 mac
->min_space_cfg
|= (density_to_set
<< 3);
497 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
498 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
501 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
505 case HW_VAR_AMPDU_FACTOR
:{
506 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
508 u8
*p_regtoset
= NULL
;
511 p_regtoset
= regtoset_normal
;
513 factor_toset
= *((u8
*)val
);
514 if (factor_toset
<= 3) {
515 factor_toset
= (1 << (factor_toset
+ 2));
516 if (factor_toset
> 0xf)
519 for (index
= 0; index
< 4; index
++) {
520 if ((p_regtoset
[index
] & 0xf0) >
523 (p_regtoset
[index
] & 0x0f) |
526 if ((p_regtoset
[index
] & 0x0f) > factor_toset
)
528 (p_regtoset
[index
] & 0xf0) |
531 rtl_write_byte(rtlpriv
,
532 (REG_AGGLEN_LMT
+ index
),
537 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
538 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
543 case HW_VAR_AC_PARAM
:{
544 u8 e_aci
= *((u8
*)val
);
545 rtl8723_dm_init_edca_turbo(hw
);
547 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
548 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACM_CTRL
,
552 case HW_VAR_ACM_CTRL
:{
553 u8 e_aci
= *((u8
*)val
);
554 union aci_aifsn
*p_aci_aifsn
=
555 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
556 u8 acm
= p_aci_aifsn
->f
.acm
;
557 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
560 acm_ctrl
| ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
565 acm_ctrl
|= ACMHW_BEQEN
;
568 acm_ctrl
|= ACMHW_VIQEN
;
571 acm_ctrl
|= ACMHW_VOQEN
;
574 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
575 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
582 acm_ctrl
&= (~ACMHW_BEQEN
);
585 acm_ctrl
&= (~ACMHW_VIQEN
);
588 acm_ctrl
&= (~ACMHW_VOQEN
);
591 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
592 "switch case %#x not processed\n",
598 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
599 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
601 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
605 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
606 rtlpci
->receive_config
= ((u32
*)(val
))[0];
608 case HW_VAR_RETRY_LIMIT
:{
609 u8 retry_limit
= ((u8
*)(val
))[0];
611 rtl_write_word(rtlpriv
, REG_RL
,
612 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
613 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
616 case HW_VAR_DUAL_TSF_RST
:
617 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
619 case HW_VAR_EFUSE_BYTES
:
620 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
622 case HW_VAR_EFUSE_USAGE
:
623 rtlefuse
->efuse_usedpercentage
= *((u8
*)val
);
626 rtl8723be_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
628 case HW_VAR_SET_RPWM
:{
631 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
634 if (rpwm_val
& BIT(7)) {
635 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, (*(u8
*)val
));
637 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
638 ((*(u8
*)val
) | BIT(7)));
642 case HW_VAR_H2C_FW_PWRMODE
:
643 rtl8723be_set_fw_pwrmode_cmd(hw
, (*(u8
*)val
));
645 case HW_VAR_FW_PSMODE_STATUS
:
646 ppsc
->fw_current_inpsmode
= *((bool *)val
);
648 case HW_VAR_RESUME_CLK_ON
:
649 _rtl8723be_set_fw_ps_rf_on(hw
);
651 case HW_VAR_FW_LPS_ACTION
:{
652 bool b_enter_fwlps
= *((bool *)val
);
655 _rtl8723be_fwlps_enter(hw
);
657 _rtl8723be_fwlps_leave(hw
);
660 case HW_VAR_H2C_FW_JOINBSSRPT
:{
661 u8 mstatus
= (*(u8
*)val
);
663 if (mstatus
== RT_MEDIA_CONNECT
) {
664 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
665 _rtl8723be_download_rsvd_page(hw
);
667 rtl8723be_set_fw_media_status_rpt_cmd(hw
, mstatus
);
670 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
671 rtl8723be_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
675 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
677 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
,
678 (u2btmp
| mac
->assoc_id
));
681 case HW_VAR_CORRECT_TSF
:{
682 u8 btype_ibss
= ((u8
*)(val
))[0];
685 _rtl8723be_stop_tx_beacon(hw
);
687 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(3));
689 rtl_write_dword(rtlpriv
, REG_TSFTR
,
690 (u32
) (mac
->tsf
& 0xffffffff));
691 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
692 (u32
) ((mac
->tsf
>> 32) & 0xffffffff));
694 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
697 _rtl8723be_resume_tx_beacon(hw
);
700 case HW_VAR_KEEP_ALIVE
:{
703 array
[1] = *((u8
*)val
);
704 rtl8723be_fill_h2c_cmd(hw
, H2C_8723B_KEEP_ALIVE_CTRL
, 2, array
);
708 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
709 "switch case %#x not processed\n", variable
);
714 static bool _rtl8723be_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
716 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
719 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
720 _LLT_OP(_LLT_WRITE_ACCESS
);
722 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
725 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
726 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
729 if (count
> POLLING_LLT_THRESHOLD
) {
730 pr_err("Failed to polling write LLT done at address %d!\n",
740 static bool _rtl8723be_llt_table_init(struct ieee80211_hw
*hw
)
742 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
751 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
,
752 (0x27FF0000 | txpktbuf_bndy
));
753 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
755 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
756 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
758 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
759 rtl_write_byte(rtlpriv
, REG_PBP
, 0x31);
760 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
762 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
763 status
= _rtl8723be_llt_write(hw
, i
, i
+ 1);
768 status
= _rtl8723be_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
773 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
774 status
= _rtl8723be_llt_write(hw
, i
, (i
+ 1));
779 status
= _rtl8723be_llt_write(hw
, maxpage
, txpktbuf_bndy
);
783 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80e40808);
784 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x00);
789 static void _rtl8723be_gen_refresh_led_state(struct ieee80211_hw
*hw
)
791 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
792 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
793 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
795 if (rtlpriv
->rtlhal
.up_first_time
)
798 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
799 rtl8723be_sw_led_on(hw
, pled0
);
800 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
801 rtl8723be_sw_led_on(hw
, pled0
);
803 rtl8723be_sw_led_off(hw
, pled0
);
806 static bool _rtl8723be_init_mac(struct ieee80211_hw
*hw
)
808 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
809 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
810 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
811 unsigned char bytetmp
;
812 unsigned short wordtmp
;
814 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
816 /*Auto Power Down to CHIP-off State*/
817 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
818 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
820 /* HW Power on sequence */
821 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
822 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
823 RTL8723_NIC_ENABLE_FLOW
)) {
824 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
825 "init MAC Fail as power on failure\n");
829 if (rtlpriv
->cfg
->ops
->get_btc_status())
830 rtlpriv
->btcoexist
.btc_ops
->btc_power_on_setting(rtlpriv
);
832 bytetmp
= rtl_read_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
);
833 rtl_write_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
, bytetmp
| BIT(3));
835 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
836 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
838 bytetmp
= rtl_read_byte(rtlpriv
, REG_CR
);
840 rtl_write_byte(rtlpriv
, REG_CR
, bytetmp
);
843 bytetmp
= rtl_read_byte(rtlpriv
, REG_HWSEQ_CTRL
);
845 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, bytetmp
);
848 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
+ 3);
849 if (bytetmp
& BIT(0)) {
850 bytetmp
= rtl_read_byte(rtlpriv
, 0x7c);
851 rtl_write_byte(rtlpriv
, 0x7c, bytetmp
| BIT(6));
854 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
855 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, bytetmp
| BIT(3));
856 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1);
857 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1, bytetmp
& (~BIT(4)));
859 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
861 if (!rtlhal
->mac_func_enable
) {
862 if (_rtl8723be_llt_table_init(hw
) == false)
866 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
867 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
869 /* Enable FW Beamformer Interrupt */
870 bytetmp
= rtl_read_byte(rtlpriv
, REG_FWIMR
+ 3);
871 rtl_write_byte(rtlpriv
, REG_FWIMR
+ 3, bytetmp
| BIT(6));
873 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
876 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
878 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 1, 0x1F);
879 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
880 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xFFFF);
881 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
883 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
884 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
886 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
887 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
889 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
890 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
891 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
892 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
893 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
894 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
895 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
896 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
897 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
898 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
900 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
901 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
904 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3);
905 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3, bytetmp
| 0x77);
907 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
909 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
911 rtl_write_byte(rtlpriv
, REG_SECONDARY_CCA_CTRL
, 0x3);
913 /* <20130114, Kordan> The following setting is
914 * only for DPDT and Fixed board type.
915 * TODO: A better solution is configure it
916 * according EFUSE during the run-time.
918 rtl_set_bbreg(hw
, 0x64, BIT(20), 0x0);/* 0x66[4]=0 */
919 rtl_set_bbreg(hw
, 0x64, BIT(24), 0x0);/* 0x66[8]=0 */
920 rtl_set_bbreg(hw
, 0x40, BIT(4), 0x0)/* 0x40[4]=0 */;
921 rtl_set_bbreg(hw
, 0x40, BIT(3), 0x1)/* 0x40[3]=1 */;
922 rtl_set_bbreg(hw
, 0x4C, BIT(24) | BIT(23), 0x2)/* 0x4C[24:23]=10 */;
923 rtl_set_bbreg(hw
, 0x944, BIT(1) | BIT(0), 0x3)/* 0x944[1:0]=11 */;
924 rtl_set_bbreg(hw
, 0x930, MASKBYTE0
, 0x77)/* 0x930[7:0]=77 */;
925 rtl_set_bbreg(hw
, 0x38, BIT(11), 0x1)/* 0x38[11]=1 */;
927 bytetmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
928 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, bytetmp
& (~BIT(2)));
930 _rtl8723be_gen_refresh_led_state(hw
);
934 static void _rtl8723be_hw_configure(struct ieee80211_hw
*hw
)
936 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
937 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
940 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
941 /* Init value for RRSR. */
942 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_rrsr
);
944 /* ARFB table 9 for 11ac 5G 2SS */
945 rtl_write_dword(rtlpriv
, REG_ARFR0
+ 4, 0xfffff000);
947 /* ARFB table 10 for 11ac 5G 1SS */
948 rtl_write_dword(rtlpriv
, REG_ARFR1
+ 4, 0x003ff000);
950 /* CF-End setting. */
951 rtl_write_word(rtlpriv
, REG_FWHW_TXQ_CTRL
, 0x1F00);
953 /* 0x456 = 0x70, sugguested by Zhilin */
954 rtl_write_byte(rtlpriv
, REG_AMPDU_MAX_TIME
, 0x70);
956 /* Set retry limit */
957 rtl_write_word(rtlpriv
, REG_RL
, 0x0707);
959 /* Set Data / Response auto rate fallack retry count */
960 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x01000000);
961 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4, 0x07060504);
962 rtl_write_dword(rtlpriv
, REG_RARFRC
, 0x01000000);
963 rtl_write_dword(rtlpriv
, REG_RARFRC
+ 4, 0x07060504);
965 rtlpci
->reg_bcn_ctrl_val
= 0x1d;
966 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, rtlpci
->reg_bcn_ctrl_val
);
968 /* TBTT prohibit hold time. Suggested by designer TimChen. */
969 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff); /* 8 ms */
971 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0040);
973 /*For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
974 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x03086666);
976 rtl_write_byte(rtlpriv
, REG_HT_SINGLE_AMPDU
, 0x80);
978 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x20);
980 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x1F);
983 static u8
_rtl8723be_dbi_read(struct rtl_priv
*rtlpriv
, u16 addr
)
985 u16 read_addr
= addr
& 0xfffc;
986 u8 ret
= 0, tmp
= 0, count
= 0;
988 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, read_addr
);
989 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x2);
990 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
992 while (tmp
&& count
< 20) {
994 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
998 read_addr
= REG_DBI_RDATA
+ addr
% 4;
999 ret
= rtl_read_byte(rtlpriv
, read_addr
);
1005 static void _rtl8723be_dbi_write(struct rtl_priv
*rtlpriv
, u16 addr
, u8 data
)
1007 u8 tmp
= 0, count
= 0;
1008 u16 write_addr
= 0, remainder
= addr
% 4;
1010 /* Write DBI 1Byte Data */
1011 write_addr
= REG_DBI_WDATA
+ remainder
;
1012 rtl_write_byte(rtlpriv
, write_addr
, data
);
1014 /* Write DBI 2Byte Address & Write Enable */
1015 write_addr
= (addr
& 0xfffc) | (BIT(0) << (remainder
+ 12));
1016 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, write_addr
);
1018 /* Write DBI Write Flag */
1019 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x1);
1021 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1023 while (tmp
&& count
< 20) {
1025 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1030 static u16
_rtl8723be_mdio_read(struct rtl_priv
*rtlpriv
, u8 addr
)
1033 u8 tmp
= 0, count
= 0;
1035 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(6));
1036 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1038 while (tmp
&& count
< 20) {
1040 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1045 ret
= rtl_read_word(rtlpriv
, REG_MDIO_RDATA
);
1050 static void _rtl8723be_mdio_write(struct rtl_priv
*rtlpriv
, u8 addr
, u16 data
)
1052 u8 tmp
= 0, count
= 0;
1054 rtl_write_word(rtlpriv
, REG_MDIO_WDATA
, data
);
1055 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(5));
1056 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1058 while (tmp
&& count
< 20) {
1060 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1065 static void _rtl8723be_enable_aspm_back_door(struct ieee80211_hw
*hw
)
1067 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1071 /* <Roger_Notes> Overwrite following ePHY parameter for
1072 * some platform compatibility issue,
1073 * especially when CLKReq is enabled, 2012.11.09.
1075 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x01);
1076 if (tmp16
!= 0x0663)
1077 _rtl8723be_mdio_write(rtlpriv
, 0x01, 0x0663);
1079 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x04);
1080 if (tmp16
!= 0x7544)
1081 _rtl8723be_mdio_write(rtlpriv
, 0x04, 0x7544);
1083 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x06);
1084 if (tmp16
!= 0xB880)
1085 _rtl8723be_mdio_write(rtlpriv
, 0x06, 0xB880);
1087 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x07);
1088 if (tmp16
!= 0x4000)
1089 _rtl8723be_mdio_write(rtlpriv
, 0x07, 0x4000);
1091 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x08);
1092 if (tmp16
!= 0x9003)
1093 _rtl8723be_mdio_write(rtlpriv
, 0x08, 0x9003);
1095 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x09);
1096 if (tmp16
!= 0x0D03)
1097 _rtl8723be_mdio_write(rtlpriv
, 0x09, 0x0D03);
1099 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x0A);
1100 if (tmp16
!= 0x4037)
1101 _rtl8723be_mdio_write(rtlpriv
, 0x0A, 0x4037);
1103 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x0B);
1104 if (tmp16
!= 0x0070)
1105 _rtl8723be_mdio_write(rtlpriv
, 0x0B, 0x0070);
1107 /* Configuration Space offset 0x70f BIT7 is used to control L0S */
1108 tmp8
= _rtl8723be_dbi_read(rtlpriv
, 0x70f);
1109 _rtl8723be_dbi_write(rtlpriv
, 0x70f, tmp8
| BIT(7) |
1110 ASPM_L1_LATENCY
<< 3);
1112 /* Configuration Space offset 0x719 Bit3 is for L1
1113 * BIT4 is for clock request
1115 tmp8
= _rtl8723be_dbi_read(rtlpriv
, 0x719);
1116 _rtl8723be_dbi_write(rtlpriv
, 0x719, tmp8
| BIT(3) | BIT(4));
1119 void rtl8723be_enable_hw_security_config(struct ieee80211_hw
*hw
)
1121 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1124 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1125 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1126 rtlpriv
->sec
.pairwise_enc_algorithm
,
1127 rtlpriv
->sec
.group_enc_algorithm
);
1129 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1130 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1131 "not open hw encryption\n");
1135 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1137 if (rtlpriv
->sec
.use_defaultkey
) {
1138 sec_reg_value
|= SCR_TXUSEDK
;
1139 sec_reg_value
|= SCR_RXUSEDK
;
1142 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1144 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1146 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1147 "The SECR-value %x\n", sec_reg_value
);
1149 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1152 static void _rtl8723be_poweroff_adapter(struct ieee80211_hw
*hw
)
1154 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1155 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1158 rtlhal
->mac_func_enable
= false;
1159 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1160 /* 1. Run LPS WL RFOFF flow */
1161 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1162 PWR_INTF_PCI_MSK
, RTL8723_NIC_LPS_ENTER_FLOW
);
1164 /* 2. 0x1F[7:0] = 0 */
1166 /* rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); */
1167 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) &&
1169 rtl8723be_firmware_selfreset(hw
);
1172 /* Reset MCU. Suggested by Filen. */
1173 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1174 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, (u1b_tmp
& (~BIT(2))));
1176 /* g. MCUFWDL 0x80[1:0]=0 */
1177 /* reset MCU ready status */
1178 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1180 /* HW card disable configuration. */
1181 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1182 PWR_INTF_PCI_MSK
, RTL8723_NIC_DISABLE_FLOW
);
1184 /* Reset MCU IO Wrapper */
1185 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1186 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, (u1b_tmp
& (~BIT(0))));
1187 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1188 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, u1b_tmp
| BIT(0));
1190 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1191 /* lock ISO/CLK/Power control register */
1192 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0e);
1195 static bool _rtl8723be_check_pcie_dma_hang(struct rtl_priv
*rtlpriv
)
1199 /* write reg 0x350 Bit[26]=1. Enable debug port. */
1200 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1201 if (!(tmp
& BIT(2))) {
1202 rtl_write_byte(rtlpriv
, REG_DBI_CTRL
+ 3, (tmp
| BIT(2)));
1203 mdelay(100); /* Suggested by DD Justin_tsai. */
1206 /* read reg 0x350 Bit[25] if 1 : RX hang
1207 * read reg 0x350 Bit[24] if 1 : TX hang
1209 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1210 if ((tmp
& BIT(0)) || (tmp
& BIT(1))) {
1211 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1212 "CheckPcieDMAHang8723BE(): true!!\n");
1218 static void _rtl8723be_reset_pcie_interface_dma(struct rtl_priv
*rtlpriv
,
1222 bool release_mac_rx_pause
;
1223 u8 backup_pcie_dma_pause
;
1225 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1226 "ResetPcieInterfaceDMA8723BE()\n");
1228 /* Revise Note: Follow the document "PCIe RX DMA Hang Reset Flow_v03"
1229 * released by SD1 Alan.
1230 * 2013.05.07, by tynli.
1233 /* 1. disable register write lock
1234 * write 0x1C bit[1:0] = 2'h0
1235 * write 0xCC bit[2] = 1'b1
1237 tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
);
1238 tmp
&= ~(BIT(1) | BIT(0));
1239 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, tmp
);
1240 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1242 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1244 /* 2. Check and pause TRX DMA
1245 * write 0x284 bit[18] = 1'b1
1246 * write 0x301 = 0xFF
1248 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1250 /* Already pause before the function for another purpose. */
1251 release_mac_rx_pause
= false;
1253 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1254 release_mac_rx_pause
= true;
1257 backup_pcie_dma_pause
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1);
1258 if (backup_pcie_dma_pause
!= 0xFF)
1259 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFF);
1262 /* 3. reset TRX function
1263 * write 0x100 = 0x00
1265 rtl_write_byte(rtlpriv
, REG_CR
, 0);
1268 /* 4. Reset PCIe DMA
1269 * write 0x003 bit[0] = 0
1271 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1273 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1275 /* 5. Enable PCIe DMA
1276 * write 0x003 bit[0] = 1
1278 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1280 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1283 /* 6. enable TRX function
1284 * write 0x100 = 0xFF
1286 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1288 /* We should init LLT & RQPN and
1289 * prepare Tx/Rx descrptor address later
1290 * because MAC function is reset.
1294 /* 7. Restore PCIe autoload down bit
1295 * write 0xF8 bit[17] = 1'b1
1297 tmp
= rtl_read_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2);
1299 rtl_write_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2, tmp
);
1301 /* In MAC power on state, BB and RF maybe in ON state,
1302 * if we release TRx DMA here
1303 * it will cause packets to be started to Tx/Rx,
1304 * so we release Tx/Rx DMA later.
1306 if (!mac_power_on
) {
1307 /* 8. release TRX DMA
1308 * write 0x284 bit[18] = 1'b0
1309 * write 0x301 = 0x00
1311 if (release_mac_rx_pause
) {
1312 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1313 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
,
1316 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1,
1317 backup_pcie_dma_pause
);
1320 /* 9. lock system register
1321 * write 0xCC bit[2] = 1'b0
1323 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1325 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1328 int rtl8723be_hw_init(struct ieee80211_hw
*hw
)
1330 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1331 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1332 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1333 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1334 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1335 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1336 bool rtstatus
= true;
1339 unsigned long flags
;
1341 /* reenable interrupts to not interfere with other devices */
1342 local_save_flags(flags
);
1345 rtlhal
->fw_ready
= false;
1346 rtlpriv
->rtlhal
.being_init_adapter
= true;
1347 rtlpriv
->intf_ops
->disable_aspm(hw
);
1349 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_CR
);
1350 if (tmp_u1b
!= 0 && tmp_u1b
!= 0xea) {
1351 rtlhal
->mac_func_enable
= true;
1353 rtlhal
->mac_func_enable
= false;
1354 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON
;
1357 if (_rtl8723be_check_pcie_dma_hang(rtlpriv
)) {
1358 _rtl8723be_reset_pcie_interface_dma(rtlpriv
,
1359 rtlhal
->mac_func_enable
);
1360 rtlhal
->mac_func_enable
= false;
1362 if (rtlhal
->mac_func_enable
) {
1363 _rtl8723be_poweroff_adapter(hw
);
1364 rtlhal
->mac_func_enable
= false;
1366 rtstatus
= _rtl8723be_init_mac(hw
);
1368 pr_err("Init MAC failed\n");
1373 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
);
1374 rtl_write_byte(rtlpriv
, REG_SYS_CFG
, tmp_u1b
& 0x7F);
1376 err
= rtl8723_download_fw(hw
, true, FW_8723B_POLLING_TIMEOUT_COUNT
);
1378 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1379 "Failed to download FW. Init HW without FW now..\n");
1383 rtlhal
->fw_ready
= true;
1385 rtlhal
->last_hmeboxnum
= 0;
1386 rtl8723be_phy_mac_config(hw
);
1387 /* because last function modify RCR, so we update
1388 * rcr var here, or TP will unstable for receive_config
1389 * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
1390 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1392 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, REG_RCR
);
1393 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1394 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1396 rtl8723be_phy_bb_config(hw
);
1397 rtl8723be_phy_rf_config(hw
);
1399 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1400 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1401 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
1402 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1403 rtlphy
->rfreg_chnlval
[0] &= 0xFFF03FF;
1404 rtlphy
->rfreg_chnlval
[0] |= (BIT(10) | BIT(11));
1406 _rtl8723be_hw_configure(hw
);
1407 rtlhal
->mac_func_enable
= true;
1408 rtl_cam_reset_all_entry(hw
);
1409 rtl8723be_enable_hw_security_config(hw
);
1411 ppsc
->rfpwr_state
= ERFON
;
1413 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1414 _rtl8723be_enable_aspm_back_door(hw
);
1415 rtlpriv
->intf_ops
->enable_aspm(hw
);
1417 rtl8723be_bt_hw_init(hw
);
1419 if (ppsc
->rfpwr_state
== ERFON
) {
1420 rtl8723be_phy_set_rfpath_switch(hw
, 1);
1421 /* when use 1ant NIC, iqk will disturb BT music
1422 * root cause is not clear now, is something
1423 * related with 'mdelay' and Reg[0x948]
1425 if (rtlpriv
->btcoexist
.btc_info
.ant_num
== ANT_X2
||
1426 !rtlpriv
->cfg
->ops
->get_btc_status()) {
1427 rtl8723be_phy_iq_calibrate(hw
,
1428 (rtlphy
->iqk_initialized
?
1430 rtlphy
->iqk_initialized
= true;
1432 rtl8723be_dm_check_txpower_tracking(hw
);
1433 rtl8723be_phy_lc_calibrate(hw
);
1435 rtl_write_byte(rtlpriv
, REG_NAV_UPPER
, ((30000 + 127) / 128));
1437 /* Release Rx DMA. */
1438 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1439 if (tmp_u1b
& BIT(2)) {
1440 /* Release Rx DMA if needed */
1441 tmp_u1b
&= (~BIT(2));
1442 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, tmp_u1b
);
1444 /* Release Tx/Rx PCIE DMA. */
1445 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0);
1447 rtl8723be_dm_init(hw
);
1449 local_irq_restore(flags
);
1450 rtlpriv
->rtlhal
.being_init_adapter
= false;
1454 static enum version_8723e
_rtl8723be_read_chip_version(struct ieee80211_hw
*hw
)
1456 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1457 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1458 enum version_8723e version
= VERSION_UNKNOWN
;
1461 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG1
);
1462 if ((value32
& (CHIP_8723B
)) != CHIP_8723B
)
1463 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "unknown chip version\n");
1465 version
= (enum version_8723e
)CHIP_8723B
;
1467 rtlphy
->rf_type
= RF_1T1R
;
1469 /* treat rtl8723be chip as MP version in default */
1470 version
= (enum version_8723e
)(version
| NORMAL_CHIP
);
1472 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
1474 version
|= (enum version_8723e
)(value32
& CHIP_VER_RTL_MASK
);
1476 if (((value32
& EXT_VENDOR_ID
) >> 18) == 0x01)
1477 version
= (enum version_8723e
)(version
| CHIP_VENDOR_SMIC
);
1479 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1480 "Chip RF Type: %s\n", (rtlphy
->rf_type
== RF_2T2R
) ?
1481 "RF_2T2R" : "RF_1T1R");
1486 static int _rtl8723be_set_media_status(struct ieee80211_hw
*hw
,
1487 enum nl80211_iftype type
)
1489 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1490 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & 0xfc;
1491 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1492 u8 mode
= MSR_NOLINK
;
1495 case NL80211_IFTYPE_UNSPECIFIED
:
1497 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1498 "Set Network type to NO LINK!\n");
1500 case NL80211_IFTYPE_ADHOC
:
1501 case NL80211_IFTYPE_MESH_POINT
:
1503 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1504 "Set Network type to Ad Hoc!\n");
1506 case NL80211_IFTYPE_STATION
:
1508 ledaction
= LED_CTL_LINK
;
1509 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1510 "Set Network type to STA!\n");
1512 case NL80211_IFTYPE_AP
:
1514 ledaction
= LED_CTL_LINK
;
1515 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1516 "Set Network type to AP!\n");
1519 pr_err("Network type %d not support!\n", type
);
1523 /* MSR_INFRA == Link in infrastructure network;
1524 * MSR_ADHOC == Link in ad hoc network;
1525 * Therefore, check link state is necessary.
1527 * MSR_AP == AP mode; link state is not cared here.
1529 if (mode
!= MSR_AP
&& rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
) {
1531 ledaction
= LED_CTL_NO_LINK
;
1534 if (mode
== MSR_NOLINK
|| mode
== MSR_INFRA
) {
1535 _rtl8723be_stop_tx_beacon(hw
);
1536 _rtl8723be_enable_bcn_sub_func(hw
);
1537 } else if (mode
== MSR_ADHOC
|| mode
== MSR_AP
) {
1538 _rtl8723be_resume_tx_beacon(hw
);
1539 _rtl8723be_disable_bcn_sub_func(hw
);
1541 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1542 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1546 rtl_write_byte(rtlpriv
, MSR
, bt_msr
| mode
);
1547 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1549 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1551 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1555 void rtl8723be_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1557 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1558 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1559 u32 reg_rcr
= rtlpci
->receive_config
;
1561 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1565 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1566 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1568 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1569 } else if (!check_bssid
) {
1570 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1571 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1572 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1578 int rtl8723be_set_network_type(struct ieee80211_hw
*hw
,
1579 enum nl80211_iftype type
)
1581 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1583 if (_rtl8723be_set_media_status(hw
, type
))
1586 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1587 if (type
!= NL80211_IFTYPE_AP
)
1588 rtl8723be_set_check_bssid(hw
, true);
1590 rtl8723be_set_check_bssid(hw
, false);
1596 /* don't set REG_EDCA_BE_PARAM here
1597 * because mac80211 will send pkt when scan
1599 void rtl8723be_set_qos(struct ieee80211_hw
*hw
, int aci
)
1601 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1603 rtl8723_dm_init_edca_turbo(hw
);
1606 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1611 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1614 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1617 WARN_ONCE(true, "rtl8723be: invalid aci: %d !\n", aci
);
1622 void rtl8723be_enable_interrupt(struct ieee80211_hw
*hw
)
1624 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1625 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1627 rtl_write_dword(rtlpriv
, REG_HIMR
, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1628 rtl_write_dword(rtlpriv
, REG_HIMRE
, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1629 rtlpci
->irq_enabled
= true;
1631 /*enable system interrupt*/
1632 rtl_write_dword(rtlpriv
, REG_HSIMR
, rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
1635 void rtl8723be_disable_interrupt(struct ieee80211_hw
*hw
)
1637 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1638 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1640 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
1641 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
1642 rtlpci
->irq_enabled
= false;
1643 /*synchronize_irq(rtlpci->pdev->irq);*/
1646 void rtl8723be_card_disable(struct ieee80211_hw
*hw
)
1648 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1649 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1650 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1651 enum nl80211_iftype opmode
;
1653 mac
->link_state
= MAC80211_NOLINK
;
1654 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1655 _rtl8723be_set_media_status(hw
, opmode
);
1656 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1657 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1658 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1659 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1660 _rtl8723be_poweroff_adapter(hw
);
1662 /* after power off we should do iqk again */
1663 if (!rtlpriv
->cfg
->ops
->get_btc_status())
1664 rtlpriv
->phy
.iqk_initialized
= false;
1667 void rtl8723be_interrupt_recognized(struct ieee80211_hw
*hw
,
1668 struct rtl_int
*intvec
)
1670 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1671 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1673 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1674 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1676 intvec
->intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) &
1677 rtlpci
->irq_mask
[1];
1678 rtl_write_dword(rtlpriv
, REG_HISRE
, intvec
->intb
);
1681 void rtl8723be_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1683 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1684 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1685 u16 bcn_interval
, atim_window
;
1687 bcn_interval
= mac
->beacon_interval
;
1688 atim_window
= 2; /*FIX MERGE */
1689 rtl8723be_disable_interrupt(hw
);
1690 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1691 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1692 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1693 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1694 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1695 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1696 rtl8723be_enable_interrupt(hw
);
1699 void rtl8723be_set_beacon_interval(struct ieee80211_hw
*hw
)
1701 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1702 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1703 u16 bcn_interval
= mac
->beacon_interval
;
1705 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1706 "beacon_interval:%d\n", bcn_interval
);
1707 rtl8723be_disable_interrupt(hw
);
1708 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1709 rtl8723be_enable_interrupt(hw
);
1712 void rtl8723be_update_interrupt_mask(struct ieee80211_hw
*hw
,
1713 u32 add_msr
, u32 rm_msr
)
1715 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1716 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1718 RT_TRACE(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1719 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1722 rtlpci
->irq_mask
[0] |= add_msr
;
1724 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1725 rtl8723be_disable_interrupt(hw
);
1726 rtl8723be_enable_interrupt(hw
);
1729 static u8
_rtl8723be_get_chnl_group(u8 chnl
)
1742 static void _rtl8723be_read_power_value_fromprom(struct ieee80211_hw
*hw
,
1743 struct txpower_info_2g
*pw2g
,
1744 struct txpower_info_5g
*pw5g
,
1745 bool autoload_fail
, u8
*hwinfo
)
1747 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1748 u32 path
, addr
= EEPROM_TX_PWR_INX
, group
, cnt
= 0;
1750 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1751 "hal_ReadPowerValueFromPROM8723BE(): PROMContent[0x%x]=0x%x\n",
1752 (addr
+ 1), hwinfo
[addr
+ 1]);
1753 if (0xFF == hwinfo
[addr
+ 1]) /*YJ,add,120316*/
1754 autoload_fail
= true;
1756 if (autoload_fail
) {
1757 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1758 "auto load fail : Use Default value!\n");
1759 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1760 /* 2.4G default value */
1761 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1762 pw2g
->index_cck_base
[path
][group
] = 0x2D;
1763 pw2g
->index_bw40_base
[path
][group
] = 0x2D;
1765 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1767 pw2g
->bw20_diff
[path
][0] = 0x02;
1768 pw2g
->ofdm_diff
[path
][0] = 0x04;
1770 pw2g
->bw20_diff
[path
][cnt
] = 0xFE;
1771 pw2g
->bw40_diff
[path
][cnt
] = 0xFE;
1772 pw2g
->cck_diff
[path
][cnt
] = 0xFE;
1773 pw2g
->ofdm_diff
[path
][cnt
] = 0xFE;
1780 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1781 /*2.4G default value*/
1782 for (group
= 0; group
< MAX_CHNL_GROUP_24G
; group
++) {
1783 pw2g
->index_cck_base
[path
][group
] = hwinfo
[addr
++];
1784 if (pw2g
->index_cck_base
[path
][group
] == 0xFF)
1785 pw2g
->index_cck_base
[path
][group
] = 0x2D;
1788 for (group
= 0; group
< MAX_CHNL_GROUP_24G
- 1; group
++) {
1789 pw2g
->index_bw40_base
[path
][group
] = hwinfo
[addr
++];
1790 if (pw2g
->index_bw40_base
[path
][group
] == 0xFF)
1791 pw2g
->index_bw40_base
[path
][group
] = 0x2D;
1793 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1795 pw2g
->bw40_diff
[path
][cnt
] = 0;
1796 if (hwinfo
[addr
] == 0xFF) {
1797 pw2g
->bw20_diff
[path
][cnt
] = 0x02;
1799 pw2g
->bw20_diff
[path
][cnt
] =
1800 (hwinfo
[addr
] & 0xf0) >> 4;
1801 /*bit sign number to 8 bit sign number*/
1802 if (pw2g
->bw20_diff
[path
][cnt
] & BIT(3))
1803 pw2g
->bw20_diff
[path
][cnt
] |=
1807 if (hwinfo
[addr
] == 0xFF) {
1808 pw2g
->ofdm_diff
[path
][cnt
] = 0x04;
1810 pw2g
->ofdm_diff
[path
][cnt
] =
1811 (hwinfo
[addr
] & 0x0f);
1812 /*bit sign number to 8 bit sign number*/
1813 if (pw2g
->ofdm_diff
[path
][cnt
] & BIT(3))
1814 pw2g
->ofdm_diff
[path
][cnt
] |=
1817 pw2g
->cck_diff
[path
][cnt
] = 0;
1820 if (hwinfo
[addr
] == 0xFF) {
1821 pw2g
->bw40_diff
[path
][cnt
] = 0xFE;
1823 pw2g
->bw40_diff
[path
][cnt
] =
1824 (hwinfo
[addr
] & 0xf0) >> 4;
1825 if (pw2g
->bw40_diff
[path
][cnt
] & BIT(3))
1826 pw2g
->bw40_diff
[path
][cnt
] |=
1830 if (hwinfo
[addr
] == 0xFF) {
1831 pw2g
->bw20_diff
[path
][cnt
] = 0xFE;
1833 pw2g
->bw20_diff
[path
][cnt
] =
1834 (hwinfo
[addr
] & 0x0f);
1835 if (pw2g
->bw20_diff
[path
][cnt
] & BIT(3))
1836 pw2g
->bw20_diff
[path
][cnt
] |=
1841 if (hwinfo
[addr
] == 0xFF) {
1842 pw2g
->ofdm_diff
[path
][cnt
] = 0xFE;
1844 pw2g
->ofdm_diff
[path
][cnt
] =
1845 (hwinfo
[addr
] & 0xf0) >> 4;
1846 if (pw2g
->ofdm_diff
[path
][cnt
] & BIT(3))
1847 pw2g
->ofdm_diff
[path
][cnt
] |=
1851 if (hwinfo
[addr
] == 0xFF)
1852 pw2g
->cck_diff
[path
][cnt
] = 0xFE;
1854 pw2g
->cck_diff
[path
][cnt
] =
1855 (hwinfo
[addr
] & 0x0f);
1856 if (pw2g
->cck_diff
[path
][cnt
] & BIT(3))
1857 pw2g
->cck_diff
[path
][cnt
] |=
1864 /*5G default value*/
1865 for (group
= 0; group
< MAX_CHNL_GROUP_5G
; group
++) {
1866 pw5g
->index_bw40_base
[path
][group
] = hwinfo
[addr
++];
1867 if (pw5g
->index_bw40_base
[path
][group
] == 0xFF)
1868 pw5g
->index_bw40_base
[path
][group
] = 0xFE;
1871 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1873 pw5g
->bw40_diff
[path
][cnt
] = 0;
1875 if (hwinfo
[addr
] == 0xFF) {
1876 pw5g
->bw20_diff
[path
][cnt
] = 0;
1878 pw5g
->bw20_diff
[path
][0] =
1879 (hwinfo
[addr
] & 0xf0) >> 4;
1880 if (pw5g
->bw20_diff
[path
][cnt
] & BIT(3))
1881 pw5g
->bw20_diff
[path
][cnt
] |=
1885 if (hwinfo
[addr
] == 0xFF)
1886 pw5g
->ofdm_diff
[path
][cnt
] = 0x04;
1888 pw5g
->ofdm_diff
[path
][0] =
1889 (hwinfo
[addr
] & 0x0f);
1890 if (pw5g
->ofdm_diff
[path
][cnt
] & BIT(3))
1891 pw5g
->ofdm_diff
[path
][cnt
] |=
1896 if (hwinfo
[addr
] == 0xFF) {
1897 pw5g
->bw40_diff
[path
][cnt
] = 0xFE;
1899 pw5g
->bw40_diff
[path
][cnt
] =
1900 (hwinfo
[addr
] & 0xf0) >> 4;
1901 if (pw5g
->bw40_diff
[path
][cnt
] & BIT(3))
1902 pw5g
->bw40_diff
[path
][cnt
] |= 0xF0;
1905 if (hwinfo
[addr
] == 0xFF) {
1906 pw5g
->bw20_diff
[path
][cnt
] = 0xFE;
1908 pw5g
->bw20_diff
[path
][cnt
] =
1909 (hwinfo
[addr
] & 0x0f);
1910 if (pw5g
->bw20_diff
[path
][cnt
] & BIT(3))
1911 pw5g
->bw20_diff
[path
][cnt
] |= 0xF0;
1917 if (hwinfo
[addr
] == 0xFF) {
1918 pw5g
->ofdm_diff
[path
][1] = 0xFE;
1919 pw5g
->ofdm_diff
[path
][2] = 0xFE;
1921 pw5g
->ofdm_diff
[path
][1] = (hwinfo
[addr
] & 0xf0) >> 4;
1922 pw5g
->ofdm_diff
[path
][2] = (hwinfo
[addr
] & 0x0f);
1926 if (hwinfo
[addr
] == 0xFF)
1927 pw5g
->ofdm_diff
[path
][3] = 0xFE;
1929 pw5g
->ofdm_diff
[path
][3] = (hwinfo
[addr
] & 0x0f);
1932 for (cnt
= 1; cnt
< MAX_TX_COUNT
; cnt
++) {
1933 if (pw5g
->ofdm_diff
[path
][cnt
] == 0xFF)
1934 pw5g
->ofdm_diff
[path
][cnt
] = 0xFE;
1935 else if (pw5g
->ofdm_diff
[path
][cnt
] & BIT(3))
1936 pw5g
->ofdm_diff
[path
][cnt
] |= 0xF0;
1941 static void _rtl8723be_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1945 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1946 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1947 struct txpower_info_2g pw2g
;
1948 struct txpower_info_5g pw5g
;
1952 _rtl8723be_read_power_value_fromprom(hw
, &pw2g
, &pw5g
, autoload_fail
,
1955 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1956 for (i
= 0; i
< 14; i
++) {
1957 index
= _rtl8723be_get_chnl_group(i
+1);
1959 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1960 pw2g
.index_cck_base
[rf_path
][index
];
1961 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1962 pw2g
.index_bw40_base
[rf_path
][index
];
1964 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
1965 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
1966 pw2g
.bw20_diff
[rf_path
][i
];
1967 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
1968 pw2g
.bw40_diff
[rf_path
][i
];
1969 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
1970 pw2g
.ofdm_diff
[rf_path
][i
];
1973 for (i
= 0; i
< 14; i
++) {
1974 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1975 "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n",
1977 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1978 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
]);
1983 rtlefuse
->eeprom_thermalmeter
=
1984 hwinfo
[EEPROM_THERMAL_METER_88E
];
1986 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1988 if (rtlefuse
->eeprom_thermalmeter
== 0xff || autoload_fail
) {
1989 rtlefuse
->apk_thermalmeterignore
= true;
1990 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1993 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1994 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1995 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1997 if (!autoload_fail
) {
1998 rtlefuse
->eeprom_regulatory
=
1999 hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x07;/*bit0~2*/
2000 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
2001 rtlefuse
->eeprom_regulatory
= 0;
2003 rtlefuse
->eeprom_regulatory
= 0;
2005 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2006 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2009 static u8
_rtl8723be_read_package_type(struct ieee80211_hw
*hw
)
2014 efuse_power_switch(hw
, false, true);
2015 if (!efuse_one_byte_read(hw
, 0x1FB, &value
))
2017 efuse_power_switch(hw
, false, false);
2019 switch (value
& 0x7) {
2021 package_type
= PACKAGE_TFBGA79
;
2024 package_type
= PACKAGE_TFBGA90
;
2027 package_type
= PACKAGE_QFN68
;
2030 package_type
= PACKAGE_TFBGA80
;
2033 package_type
= PACKAGE_DEFAULT
;
2037 return package_type
;
2040 static void _rtl8723be_read_adapter_info(struct ieee80211_hw
*hw
,
2043 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2044 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2045 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2046 int params
[] = {RTL8723BE_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
2047 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
2048 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
2049 COUNTRY_CODE_WORLD_WIDE_13
};
2052 bool is_toshiba_smid1
= false;
2053 bool is_toshiba_smid2
= false;
2054 bool is_samsung_smid
= false;
2055 bool is_lenovo_smid
= false;
2056 u16 toshiba_smid1
[] = {
2057 0x6151, 0x6152, 0x6154, 0x6155, 0x6177, 0x6178, 0x6179, 0x6180,
2058 0x7151, 0x7152, 0x7154, 0x7155, 0x7177, 0x7178, 0x7179, 0x7180,
2059 0x8151, 0x8152, 0x8154, 0x8155, 0x8181, 0x8182, 0x8184, 0x8185,
2060 0x9151, 0x9152, 0x9154, 0x9155, 0x9181, 0x9182, 0x9184, 0x9185
2062 u16 toshiba_smid2
[] = {
2063 0x6181, 0x6184, 0x6185, 0x7181, 0x7182, 0x7184, 0x7185, 0x8181,
2064 0x8182, 0x8184, 0x8185, 0x9181, 0x9182, 0x9184, 0x9185
2066 u16 samsung_smid
[] = {
2067 0x6191, 0x6192, 0x6193, 0x7191, 0x7192, 0x7193, 0x8191, 0x8192,
2068 0x8193, 0x9191, 0x9192, 0x9193
2070 u16 lenovo_smid
[] = {
2071 0x8195, 0x9195, 0x7194, 0x8200, 0x8201, 0x8202, 0x9199, 0x9200
2075 /* needs to be added */
2079 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
2083 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
2087 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_8723BE
];
2088 if (rtlefuse
->crystalcap
== 0xFF)
2089 rtlefuse
->crystalcap
= 0x20;
2091 _rtl8723be_read_txpower_info_from_hwpg(hw
, rtlefuse
->autoload_failflag
,
2094 rtl8723be_read_bt_coexist_info_from_hwpg(hw
,
2095 rtlefuse
->autoload_failflag
,
2098 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1)
2099 rtlefuse
->board_type
|= BIT(2); /* ODM_BOARD_BT */
2101 rtlhal
->board_type
= rtlefuse
->board_type
;
2102 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2103 "board_type = 0x%x\n", rtlefuse
->board_type
);
2105 rtlhal
->package_type
= _rtl8723be_read_package_type(hw
);
2107 /* set channel plan from efuse */
2108 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
2110 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
2111 /* Does this one have a Toshiba SMID from group 1? */
2112 for (i
= 0; i
< ARRAY_SIZE(toshiba_smid1
); i
++) {
2113 if (rtlefuse
->eeprom_smid
== toshiba_smid1
[i
]) {
2114 is_toshiba_smid1
= true;
2118 /* Does this one have a Toshiba SMID from group 2? */
2119 for (i
= 0; i
< ARRAY_SIZE(toshiba_smid2
); i
++) {
2120 if (rtlefuse
->eeprom_smid
== toshiba_smid2
[i
]) {
2121 is_toshiba_smid2
= true;
2125 /* Does this one have a Samsung SMID? */
2126 for (i
= 0; i
< ARRAY_SIZE(samsung_smid
); i
++) {
2127 if (rtlefuse
->eeprom_smid
== samsung_smid
[i
]) {
2128 is_samsung_smid
= true;
2132 /* Does this one have a Lenovo SMID? */
2133 for (i
= 0; i
< ARRAY_SIZE(lenovo_smid
); i
++) {
2134 if (rtlefuse
->eeprom_smid
== lenovo_smid
[i
]) {
2135 is_lenovo_smid
= true;
2139 switch (rtlefuse
->eeprom_oemid
) {
2140 case EEPROM_CID_DEFAULT
:
2141 if (rtlefuse
->eeprom_did
== 0x8176) {
2142 if (rtlefuse
->eeprom_svid
== 0x10EC &&
2144 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2145 } else if (rtlefuse
->eeprom_svid
== 0x1025) {
2146 rtlhal
->oem_id
= RT_CID_819X_ACER
;
2147 } else if (rtlefuse
->eeprom_svid
== 0x10EC &&
2149 rtlhal
->oem_id
= RT_CID_819X_SAMSUNG
;
2150 } else if (rtlefuse
->eeprom_svid
== 0x10EC &&
2152 rtlhal
->oem_id
= RT_CID_819X_LENOVO
;
2153 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2154 rtlefuse
->eeprom_smid
== 0x8197) ||
2155 (rtlefuse
->eeprom_svid
== 0x10EC &&
2156 rtlefuse
->eeprom_smid
== 0x9196)) {
2157 rtlhal
->oem_id
= RT_CID_819X_CLEVO
;
2158 } else if ((rtlefuse
->eeprom_svid
== 0x1028 &&
2159 rtlefuse
->eeprom_smid
== 0x8194) ||
2160 (rtlefuse
->eeprom_svid
== 0x1028 &&
2161 rtlefuse
->eeprom_smid
== 0x8198) ||
2162 (rtlefuse
->eeprom_svid
== 0x1028 &&
2163 rtlefuse
->eeprom_smid
== 0x9197) ||
2164 (rtlefuse
->eeprom_svid
== 0x1028 &&
2165 rtlefuse
->eeprom_smid
== 0x9198)) {
2166 rtlhal
->oem_id
= RT_CID_819X_DELL
;
2167 } else if ((rtlefuse
->eeprom_svid
== 0x103C &&
2168 rtlefuse
->eeprom_smid
== 0x1629)) {
2169 rtlhal
->oem_id
= RT_CID_819X_HP
;
2170 } else if ((rtlefuse
->eeprom_svid
== 0x1A32 &&
2171 rtlefuse
->eeprom_smid
== 0x2315)) {
2172 rtlhal
->oem_id
= RT_CID_819X_QMI
;
2173 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2174 rtlefuse
->eeprom_smid
== 0x8203)) {
2175 rtlhal
->oem_id
= RT_CID_819X_PRONETS
;
2176 } else if ((rtlefuse
->eeprom_svid
== 0x1043 &&
2177 rtlefuse
->eeprom_smid
== 0x84B5)) {
2178 rtlhal
->oem_id
= RT_CID_819X_EDIMAX_ASUS
;
2180 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2182 } else if (rtlefuse
->eeprom_did
== 0x8178) {
2183 if (rtlefuse
->eeprom_svid
== 0x10EC &&
2185 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2186 else if (rtlefuse
->eeprom_svid
== 0x1025)
2187 rtlhal
->oem_id
= RT_CID_819X_ACER
;
2188 else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2189 rtlefuse
->eeprom_smid
== 0x8186))
2190 rtlhal
->oem_id
= RT_CID_819X_PRONETS
;
2191 else if ((rtlefuse
->eeprom_svid
== 0x1043 &&
2192 rtlefuse
->eeprom_smid
== 0x84B6))
2194 RT_CID_819X_EDIMAX_ASUS
;
2196 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2198 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2201 case EEPROM_CID_TOSHIBA
:
2202 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2204 case EEPROM_CID_CCX
:
2205 rtlhal
->oem_id
= RT_CID_CCX
;
2207 case EEPROM_CID_QMI
:
2208 rtlhal
->oem_id
= RT_CID_819X_QMI
;
2210 case EEPROM_CID_WHQL
:
2213 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2221 static void _rtl8723be_hal_customized_behavior(struct ieee80211_hw
*hw
)
2223 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2224 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2226 rtlpriv
->ledctl
.led_opendrain
= true;
2227 switch (rtlhal
->oem_id
) {
2228 case RT_CID_819X_HP
:
2229 rtlpriv
->ledctl
.led_opendrain
= true;
2231 case RT_CID_819X_LENOVO
:
2232 case RT_CID_DEFAULT
:
2233 case RT_CID_TOSHIBA
:
2235 case RT_CID_819X_ACER
:
2240 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2241 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
2244 void rtl8723be_read_eeprom_info(struct ieee80211_hw
*hw
)
2246 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2247 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2248 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2249 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2252 rtlhal
->version
= _rtl8723be_read_chip_version(hw
);
2253 if (get_rf_type(rtlphy
) == RF_1T1R
)
2254 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
2256 rtlpriv
->dm
.rfpath_rxenable
[0] =
2257 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
2258 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
2260 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
2261 if (tmp_u1b
& BIT(4)) {
2262 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
2263 rtlefuse
->epromtype
= EEPROM_93C46
;
2265 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
2266 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
2268 if (tmp_u1b
& BIT(5)) {
2269 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
2270 rtlefuse
->autoload_failflag
= false;
2271 _rtl8723be_read_adapter_info(hw
, false);
2273 pr_err("Autoload ERR!!\n");
2275 _rtl8723be_hal_customized_behavior(hw
);
2278 static u8
_rtl8723be_mrate_idx_to_arfr_id(struct ieee80211_hw
*hw
,
2282 switch (rate_index
) {
2283 case RATR_INX_WIRELESS_NGB
:
2286 case RATR_INX_WIRELESS_N
:
2287 case RATR_INX_WIRELESS_NG
:
2290 case RATR_INX_WIRELESS_NB
:
2293 case RATR_INX_WIRELESS_GB
:
2296 case RATR_INX_WIRELESS_G
:
2299 case RATR_INX_WIRELESS_B
:
2309 static void rtl8723be_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2310 struct ieee80211_sta
*sta
,
2311 u8 rssi_level
, bool update_bw
)
2313 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2314 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2315 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2316 struct rtl_sta_info
*sta_entry
= NULL
;
2319 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
&
2320 IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ? 1 : 0;
2321 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2323 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2325 enum wireless_mode wirelessmode
= 0;
2326 bool shortgi
= false;
2330 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
2331 wirelessmode
= sta_entry
->wireless_mode
;
2332 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2333 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2334 curtxbw_40mhz
= mac
->bw_40
;
2335 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2336 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2337 macid
= sta
->aid
+ 1;
2339 ratr_bitmap
= sta
->supp_rates
[0];
2341 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2342 ratr_bitmap
= 0xfff;
2344 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2345 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2346 switch (wirelessmode
) {
2347 case WIRELESS_MODE_B
:
2348 ratr_index
= RATR_INX_WIRELESS_B
;
2349 if (ratr_bitmap
& 0x0000000c)
2350 ratr_bitmap
&= 0x0000000d;
2352 ratr_bitmap
&= 0x0000000f;
2354 case WIRELESS_MODE_G
:
2355 ratr_index
= RATR_INX_WIRELESS_GB
;
2357 if (rssi_level
== 1)
2358 ratr_bitmap
&= 0x00000f00;
2359 else if (rssi_level
== 2)
2360 ratr_bitmap
&= 0x00000ff0;
2362 ratr_bitmap
&= 0x00000ff5;
2364 case WIRELESS_MODE_N_24G
:
2365 case WIRELESS_MODE_N_5G
:
2366 ratr_index
= RATR_INX_WIRELESS_NGB
;
2367 if (rtlphy
->rf_type
== RF_1T1R
) {
2368 if (curtxbw_40mhz
) {
2369 if (rssi_level
== 1)
2370 ratr_bitmap
&= 0x000f0000;
2371 else if (rssi_level
== 2)
2372 ratr_bitmap
&= 0x000ff000;
2374 ratr_bitmap
&= 0x000ff015;
2376 if (rssi_level
== 1)
2377 ratr_bitmap
&= 0x000f0000;
2378 else if (rssi_level
== 2)
2379 ratr_bitmap
&= 0x000ff000;
2381 ratr_bitmap
&= 0x000ff005;
2384 if (curtxbw_40mhz
) {
2385 if (rssi_level
== 1)
2386 ratr_bitmap
&= 0x0f8f0000;
2387 else if (rssi_level
== 2)
2388 ratr_bitmap
&= 0x0f8ff000;
2390 ratr_bitmap
&= 0x0f8ff015;
2392 if (rssi_level
== 1)
2393 ratr_bitmap
&= 0x0f8f0000;
2394 else if (rssi_level
== 2)
2395 ratr_bitmap
&= 0x0f8ff000;
2397 ratr_bitmap
&= 0x0f8ff005;
2400 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2401 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2404 else if (macid
== 1)
2409 ratr_index
= RATR_INX_WIRELESS_NGB
;
2411 if (rtlphy
->rf_type
== RF_1T2R
)
2412 ratr_bitmap
&= 0x000ff0ff;
2414 ratr_bitmap
&= 0x0f0ff0ff;
2418 sta_entry
->ratr_index
= ratr_index
;
2420 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2421 "ratr_bitmap :%x\n", ratr_bitmap
);
2422 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2424 rate_mask
[0] = macid
;
2425 rate_mask
[1] = _rtl8723be_mrate_idx_to_arfr_id(hw
, ratr_index
) |
2426 (shortgi
? 0x80 : 0x00);
2427 rate_mask
[2] = curtxbw_40mhz
| ((!update_bw
) << 3);
2429 rate_mask
[3] = (u8
)(ratr_bitmap
& 0x000000ff);
2430 rate_mask
[4] = (u8
)((ratr_bitmap
& 0x0000ff00) >> 8);
2431 rate_mask
[5] = (u8
)((ratr_bitmap
& 0x00ff0000) >> 16);
2432 rate_mask
[6] = (u8
)((ratr_bitmap
& 0xff000000) >> 24);
2434 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2435 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
2436 ratr_index
, ratr_bitmap
,
2437 rate_mask
[0], rate_mask
[1],
2438 rate_mask
[2], rate_mask
[3],
2439 rate_mask
[4], rate_mask
[5],
2441 rtl8723be_fill_h2c_cmd(hw
, H2C_8723B_RA_MASK
, 7, rate_mask
);
2442 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2445 void rtl8723be_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2446 struct ieee80211_sta
*sta
,
2447 u8 rssi_level
, bool update_bw
)
2449 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2450 if (rtlpriv
->dm
.useramask
)
2451 rtl8723be_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2454 void rtl8723be_update_channel_access_setting(struct ieee80211_hw
*hw
)
2456 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2457 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2460 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
, &mac
->slot_time
);
2461 if (!mac
->ht_enable
)
2462 sifs_timer
= 0x0a0a;
2464 sifs_timer
= 0x0e0e;
2465 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2468 bool rtl8723be_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2470 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2471 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2472 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2473 enum rf_pwrstate e_rfpowerstate_toset
;
2475 bool b_actuallyset
= false;
2477 if (rtlpriv
->rtlhal
.being_init_adapter
)
2480 if (ppsc
->swrf_processing
)
2483 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2484 if (ppsc
->rfchange_inprogress
) {
2485 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2488 ppsc
->rfchange_inprogress
= true;
2489 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2492 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL_2
,
2493 rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL_2
) & ~(BIT(1)));
2495 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_PIN_CTRL_2
);
2497 if (rtlphy
->polarity_ctl
)
2498 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFOFF
: ERFON
;
2500 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFON
: ERFOFF
;
2502 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
2503 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2504 "GPIOChangeRF - HW Radio ON, RF ON\n");
2506 e_rfpowerstate_toset
= ERFON
;
2507 ppsc
->hwradiooff
= false;
2508 b_actuallyset
= true;
2509 } else if (!ppsc
->hwradiooff
&& (e_rfpowerstate_toset
== ERFOFF
)) {
2510 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
2511 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2513 e_rfpowerstate_toset
= ERFOFF
;
2514 ppsc
->hwradiooff
= true;
2515 b_actuallyset
= true;
2518 if (b_actuallyset
) {
2519 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2520 ppsc
->rfchange_inprogress
= false;
2521 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2523 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2524 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2526 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2527 ppsc
->rfchange_inprogress
= false;
2528 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2532 return !ppsc
->hwradiooff
;
2536 void rtl8723be_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
2537 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
2538 bool is_wepkey
, bool clear_all
)
2540 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2541 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2542 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2543 u8
*macaddr
= p_macaddr
;
2545 bool is_pairwise
= false;
2547 static u8 cam_const_addr
[4][6] = {
2548 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2549 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2550 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2551 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2553 static u8 cam_const_broad
[] = {
2554 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2560 u8 clear_number
= 5;
2562 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2564 for (idx
= 0; idx
< clear_number
; idx
++) {
2565 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2566 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2569 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2571 rtlpriv
->sec
.key_len
[idx
] = 0;
2577 case WEP40_ENCRYPTION
:
2578 enc_algo
= CAM_WEP40
;
2580 case WEP104_ENCRYPTION
:
2581 enc_algo
= CAM_WEP104
;
2583 case TKIP_ENCRYPTION
:
2584 enc_algo
= CAM_TKIP
;
2586 case AESCCMP_ENCRYPTION
:
2590 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2591 "switch case %#x not processed\n", enc_algo
);
2592 enc_algo
= CAM_TKIP
;
2596 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2597 macaddr
= cam_const_addr
[key_index
];
2598 entry_id
= key_index
;
2601 macaddr
= cam_const_broad
;
2602 entry_id
= key_index
;
2604 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2605 entry_id
= rtl_cam_get_free_entry(hw
,
2607 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2608 pr_err("Can not find free hw security cam entry\n");
2612 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2615 key_index
= PAIRWISE_KEYIDX
;
2620 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2621 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2622 "delete one entry, entry_id is %d\n",
2624 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2625 rtl_cam_del_entry(hw
, p_macaddr
);
2626 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2628 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2631 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2632 "set Pairwise key\n");
2634 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2636 CAM_CONFIG_NO_USEDK
,
2637 rtlpriv
->sec
.key_buf
[key_index
]);
2639 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2642 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2643 rtl_cam_add_one_entry(hw
,
2646 CAM_PAIRWISE_KEY_POSITION
,
2648 CAM_CONFIG_NO_USEDK
,
2649 rtlpriv
->sec
.key_buf
2653 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2655 CAM_CONFIG_NO_USEDK
,
2656 rtlpriv
->sec
.key_buf
[entry_id
]);
2662 void rtl8723be_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2663 bool auto_load_fail
, u8
*hwinfo
)
2665 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2666 struct rtl_mod_params
*mod_params
= rtlpriv
->cfg
->mod_params
;
2670 if (!auto_load_fail
) {
2671 tmpu_32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
2672 if (tmpu_32
& BIT(18))
2673 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
2675 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
2676 value
= hwinfo
[EEPROM_RF_BT_SETTING_8723B
];
2677 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8723B
;
2678 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
2679 rtlpriv
->btcoexist
.btc_info
.single_ant_path
=
2680 (value
& 0x40 ? ANT_AUX
: ANT_MAIN
); /*0xc3[6]*/
2682 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
2683 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8723B
;
2684 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
2685 rtlpriv
->btcoexist
.btc_info
.single_ant_path
= ANT_MAIN
;
2688 /* override ant_num / ant_path */
2689 if (mod_params
->ant_sel
) {
2690 rtlpriv
->btcoexist
.btc_info
.ant_num
=
2691 (mod_params
->ant_sel
== 1 ? ANT_X1
: ANT_X2
);
2693 rtlpriv
->btcoexist
.btc_info
.single_ant_path
=
2694 (mod_params
->ant_sel
== 1 ? ANT_AUX
: ANT_MAIN
);
2698 void rtl8723be_bt_reg_init(struct ieee80211_hw
*hw
)
2700 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2702 /* 0:Low, 1:High, 2:From Efuse. */
2703 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
2704 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2705 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
2706 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2707 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
2710 void rtl8723be_bt_hw_init(struct ieee80211_hw
*hw
)
2712 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2714 if (rtlpriv
->cfg
->ops
->get_btc_status())
2715 rtlpriv
->btcoexist
.btc_ops
->btc_init_hw_config(rtlpriv
);
2719 void rtl8723be_suspend(struct ieee80211_hw
*hw
)
2723 void rtl8723be_resume(struct ieee80211_hw
*hw
)