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 dma_unmap_single(&rtlpci
->pdev
->dev
,
41 rtlpriv
->cfg
->ops
->get_desc(hw
, (u8
*)entry
,
42 true, HW_DESC_TXBUFF_ADDR
),
43 skb
->len
, DMA_TO_DEVICE
);
45 ring
->idx
= (ring
->idx
+ 1) % ring
->entries
;
47 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
50 static void _rtl8723be_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
51 u8 set_bits
, u8 clear_bits
)
53 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
54 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
56 rtlpci
->reg_bcn_ctrl_val
|= set_bits
;
57 rtlpci
->reg_bcn_ctrl_val
&= ~clear_bits
;
59 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlpci
->reg_bcn_ctrl_val
);
62 static void _rtl8723be_stop_tx_beacon(struct ieee80211_hw
*hw
)
64 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
67 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
68 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
& (~BIT(6)));
69 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
70 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
71 tmp1byte
&= ~(BIT(0));
72 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
75 static void _rtl8723be_resume_tx_beacon(struct ieee80211_hw
*hw
)
77 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
80 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
81 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp1byte
| BIT(6));
82 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
83 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
85 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
88 static void _rtl8723be_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
90 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(1));
93 static void _rtl8723be_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
95 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(1), 0);
98 static void _rtl8723be_set_fw_clock_on(struct ieee80211_hw
*hw
, u8 rpwm_val
,
99 bool b_need_turn_off_ckk
)
101 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
102 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
103 bool b_support_remote_wake_up
;
104 u32 count
= 0, isr_regaddr
, content
;
105 bool b_schedule_timer
= b_need_turn_off_ckk
;
106 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
107 (u8
*)(&b_support_remote_wake_up
));
109 if (!rtlhal
->fw_ready
)
111 if (!rtlpriv
->psc
.fw_current_inpsmode
)
115 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
116 if (rtlhal
->fw_clk_change_in_progress
) {
117 while (rtlhal
->fw_clk_change_in_progress
) {
118 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
123 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
125 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
127 rtlhal
->fw_clk_change_in_progress
= false;
128 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
133 if (IS_IN_LOW_POWER_STATE(rtlhal
->fw_ps_state
)) {
134 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_SET_RPWM
,
136 if (FW_PS_IS_ACK(rpwm_val
)) {
137 isr_regaddr
= REG_HISR
;
138 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
139 while (!(content
& IMR_CPWM
) && (count
< 500)) {
142 content
= rtl_read_dword(rtlpriv
, isr_regaddr
);
145 if (content
& IMR_CPWM
) {
146 rtl_write_word(rtlpriv
, isr_regaddr
, 0x0100);
147 rtlhal
->fw_ps_state
= FW_PS_STATE_RF_ON
;
148 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_LOUD
,
149 "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
150 rtlhal
->fw_ps_state
);
154 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
155 rtlhal
->fw_clk_change_in_progress
= false;
156 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
157 if (b_schedule_timer
)
158 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
159 jiffies
+ MSECS(10));
161 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
162 rtlhal
->fw_clk_change_in_progress
= false;
163 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
167 static void _rtl8723be_set_fw_clock_off(struct ieee80211_hw
*hw
, u8 rpwm_val
)
169 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
170 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
171 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
172 struct rtl8192_tx_ring
*ring
;
173 enum rf_pwrstate rtstate
;
174 bool b_schedule_timer
= false;
177 if (!rtlhal
->fw_ready
)
179 if (!rtlpriv
->psc
.fw_current_inpsmode
)
181 if (!rtlhal
->allow_sw_to_change_hwclc
)
183 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
, (u8
*)(&rtstate
));
184 if (rtstate
== ERFOFF
|| rtlpriv
->psc
.inactive_pwrstate
== ERFOFF
)
187 for (queue
= 0; queue
< RTL_PCI_MAX_TX_QUEUE_COUNT
; queue
++) {
188 ring
= &rtlpci
->tx_ring
[queue
];
189 if (skb_queue_len(&ring
->queue
)) {
190 b_schedule_timer
= true;
195 if (b_schedule_timer
) {
196 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
197 jiffies
+ MSECS(10));
201 if (FW_PS_STATE(rtlhal
->fw_ps_state
) != FW_PS_STATE_RF_OFF_LOW_PWR
) {
202 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
203 if (!rtlhal
->fw_clk_change_in_progress
) {
204 rtlhal
->fw_clk_change_in_progress
= true;
205 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
206 rtlhal
->fw_ps_state
= FW_PS_STATE(rpwm_val
);
207 rtl_write_word(rtlpriv
, REG_HISR
, 0x0100);
208 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
210 spin_lock_bh(&rtlpriv
->locks
.fw_ps_lock
);
211 rtlhal
->fw_clk_change_in_progress
= false;
212 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
214 spin_unlock_bh(&rtlpriv
->locks
.fw_ps_lock
);
215 mod_timer(&rtlpriv
->works
.fw_clockoff_timer
,
216 jiffies
+ MSECS(10));
222 static void _rtl8723be_set_fw_ps_rf_on(struct ieee80211_hw
*hw
)
225 rpwm_val
|= (FW_PS_STATE_RF_OFF
| FW_PS_ACK
);
226 _rtl8723be_set_fw_clock_on(hw
, rpwm_val
, true);
229 static void _rtl8723be_fwlps_leave(struct ieee80211_hw
*hw
)
231 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
232 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
233 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
234 bool fw_current_inps
= false;
235 u8 rpwm_val
= 0, fw_pwrmode
= FW_PS_ACTIVE_MODE
;
237 if (ppsc
->low_power_enable
) {
238 rpwm_val
= (FW_PS_STATE_ALL_ON
| FW_PS_ACK
);/* RF on */
239 _rtl8723be_set_fw_clock_on(hw
, rpwm_val
, false);
240 rtlhal
->allow_sw_to_change_hwclc
= false;
241 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
242 (u8
*)(&fw_pwrmode
));
243 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
244 (u8
*)(&fw_current_inps
));
246 rpwm_val
= FW_PS_STATE_ALL_ON
; /* RF on */
247 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
249 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
250 (u8
*)(&fw_pwrmode
));
251 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
252 (u8
*)(&fw_current_inps
));
257 static void _rtl8723be_fwlps_enter(struct ieee80211_hw
*hw
)
259 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
260 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
261 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
262 bool fw_current_inps
= true;
265 if (ppsc
->low_power_enable
) {
266 rpwm_val
= FW_PS_STATE_RF_OFF_LOW_PWR
; /* RF off */
267 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
268 (u8
*)(&fw_current_inps
));
269 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
270 (u8
*)(&ppsc
->fwctrl_psmode
));
271 rtlhal
->allow_sw_to_change_hwclc
= true;
272 _rtl8723be_set_fw_clock_off(hw
, rpwm_val
);
274 rpwm_val
= FW_PS_STATE_RF_OFF
; /* RF off */
275 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
276 (u8
*)(&fw_current_inps
));
277 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_H2C_FW_PWRMODE
,
278 (u8
*)(&ppsc
->fwctrl_psmode
));
279 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SET_RPWM
,
285 void rtl8723be_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
287 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
288 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
289 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
293 *((u32
*)(val
)) = rtlpci
->receive_config
;
295 case HW_VAR_RF_STATE
:
296 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
298 case HW_VAR_FWLPS_RF_ON
:{
299 enum rf_pwrstate rfstate
;
302 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
304 if (rfstate
== ERFOFF
) {
305 *((bool *)(val
)) = true;
307 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
308 val_rcr
&= 0x00070000;
310 *((bool *)(val
)) = false;
312 *((bool *)(val
)) = true;
316 case HW_VAR_FW_PSMODE_STATUS
:
317 *((bool *)(val
)) = ppsc
->fw_current_inpsmode
;
319 case HW_VAR_CORRECT_TSF
:{
321 u32
*ptsf_low
= (u32
*)&tsf
;
322 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
324 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
325 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
327 *((u64
*)(val
)) = tsf
;
333 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
334 "switch case %#x not processed\n", variable
);
339 static void _rtl8723be_download_rsvd_page(struct ieee80211_hw
*hw
)
341 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
342 u8 tmp_regcr
, tmp_reg422
, bcnvalid_reg
;
343 u8 count
= 0, dlbcn_count
= 0;
344 bool b_recover
= false;
346 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
347 rtl_write_byte(rtlpriv
, REG_CR
+ 1,
348 (tmp_regcr
| BIT(0)));
350 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(3));
351 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(4), 0);
353 tmp_reg422
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
354 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
& (~BIT(6)));
355 if (tmp_reg422
& BIT(6))
359 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
360 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2,
361 (bcnvalid_reg
| BIT(0)));
362 _rtl8723be_return_beacon_queue_skb(hw
);
364 rtl8723be_set_fw_rsvdpagepkt(hw
, 0);
365 bcnvalid_reg
= rtl_read_byte(rtlpriv
, REG_TDECTRL
+ 2);
367 while (!(bcnvalid_reg
& BIT(0)) && count
< 20) {
370 bcnvalid_reg
= rtl_read_byte(rtlpriv
,
374 } while (!(bcnvalid_reg
& BIT(0)) && dlbcn_count
< 5);
376 if (bcnvalid_reg
& BIT(0))
377 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 2, BIT(0));
379 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
380 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(4));
383 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2, tmp_reg422
);
385 tmp_regcr
= rtl_read_byte(rtlpriv
, REG_CR
+ 1);
386 rtl_write_byte(rtlpriv
, REG_CR
+ 1, (tmp_regcr
& ~(BIT(0))));
389 void rtl8723be_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
391 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
392 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
393 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
394 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
395 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
399 case HW_VAR_ETHER_ADDR
:
400 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
401 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
), val
[idx
]);
403 case HW_VAR_BASIC_RATE
:{
404 u16 b_rate_cfg
= ((u16
*)val
)[0];
406 b_rate_cfg
= b_rate_cfg
& 0x15f;
408 rtl_write_byte(rtlpriv
, REG_RRSR
, b_rate_cfg
& 0xff);
409 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1, (b_rate_cfg
>> 8) & 0xff);
410 while (b_rate_cfg
> 0x1) {
411 b_rate_cfg
= (b_rate_cfg
>> 1);
414 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
, rate_index
);
418 for (idx
= 0; idx
< ETH_ALEN
; idx
++)
419 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
), val
[idx
]);
423 rtl_write_byte(rtlpriv
, REG_SIFS_CTX
+ 1, val
[0]);
424 rtl_write_byte(rtlpriv
, REG_SIFS_TRX
+ 1, val
[1]);
426 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
427 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
430 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
, 0x0e0e);
432 rtl_write_word(rtlpriv
, REG_RESP_SIFS_OFDM
,
435 case HW_VAR_SLOT_TIME
:{
438 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
439 "HW_VAR_SLOT_TIME %x\n", val
[0]);
441 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
443 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++) {
444 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
449 case HW_VAR_ACK_PREAMBLE
:{
451 u8 short_preamble
= (bool)(*(u8
*)val
);
452 reg_tmp
= rtl_read_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2);
453 if (short_preamble
) {
455 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
458 rtl_write_byte(rtlpriv
, REG_TRXPTCL_CTL
+ 2, reg_tmp
);
462 case HW_VAR_WPA_CONFIG
:
463 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*)val
));
465 case HW_VAR_AMPDU_MIN_SPACE
:{
466 u8 min_spacing_to_set
;
469 min_spacing_to_set
= *((u8
*)val
);
470 if (min_spacing_to_set
<= 7) {
473 if (min_spacing_to_set
< sec_min_space
)
474 min_spacing_to_set
= sec_min_space
;
476 mac
->min_space_cfg
= ((mac
->min_space_cfg
& 0xf8) |
479 *val
= min_spacing_to_set
;
481 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
482 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
485 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
490 case HW_VAR_SHORTGI_DENSITY
:{
493 density_to_set
= *((u8
*)val
);
494 mac
->min_space_cfg
|= (density_to_set
<< 3);
496 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
497 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
500 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
504 case HW_VAR_AMPDU_FACTOR
:{
505 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
507 u8
*p_regtoset
= NULL
;
510 p_regtoset
= regtoset_normal
;
512 factor_toset
= *((u8
*)val
);
513 if (factor_toset
<= 3) {
514 factor_toset
= (1 << (factor_toset
+ 2));
515 if (factor_toset
> 0xf)
518 for (index
= 0; index
< 4; index
++) {
519 if ((p_regtoset
[index
] & 0xf0) >
522 (p_regtoset
[index
] & 0x0f) |
525 if ((p_regtoset
[index
] & 0x0f) > factor_toset
)
527 (p_regtoset
[index
] & 0xf0) |
530 rtl_write_byte(rtlpriv
,
531 (REG_AGGLEN_LMT
+ index
),
536 rtl_dbg(rtlpriv
, COMP_MLME
, DBG_LOUD
,
537 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
542 case HW_VAR_AC_PARAM
:{
543 u8 e_aci
= *((u8
*)val
);
544 rtl8723_dm_init_edca_turbo(hw
);
546 if (rtlpci
->acm_method
!= EACMWAY2_SW
)
547 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACM_CTRL
,
551 case HW_VAR_ACM_CTRL
:{
552 u8 e_aci
= *((u8
*)val
);
553 union aci_aifsn
*p_aci_aifsn
=
554 (union aci_aifsn
*)(&(mac
->ac
[0].aifs
));
555 u8 acm
= p_aci_aifsn
->f
.acm
;
556 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
559 acm_ctrl
| ((rtlpci
->acm_method
== 2) ? 0x0 : 0x1);
564 acm_ctrl
|= ACMHW_BEQEN
;
567 acm_ctrl
|= ACMHW_VIQEN
;
570 acm_ctrl
|= ACMHW_VOQEN
;
573 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
574 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
581 acm_ctrl
&= (~ACMHW_BEQEN
);
584 acm_ctrl
&= (~ACMHW_VIQEN
);
587 acm_ctrl
&= (~ACMHW_VOQEN
);
590 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
591 "switch case %#x not processed\n",
597 rtl_dbg(rtlpriv
, COMP_QOS
, DBG_TRACE
,
598 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
600 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
604 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*)(val
))[0]);
605 rtlpci
->receive_config
= ((u32
*)(val
))[0];
607 case HW_VAR_RETRY_LIMIT
:{
608 u8 retry_limit
= ((u8
*)(val
))[0];
610 rtl_write_word(rtlpriv
, REG_RL
,
611 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
612 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
615 case HW_VAR_DUAL_TSF_RST
:
616 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
618 case HW_VAR_EFUSE_BYTES
:
619 rtlefuse
->efuse_usedbytes
= *((u16
*)val
);
621 case HW_VAR_EFUSE_USAGE
:
622 rtlefuse
->efuse_usedpercentage
= *((u8
*)val
);
625 rtl8723be_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
627 case HW_VAR_SET_RPWM
:{
630 rpwm_val
= rtl_read_byte(rtlpriv
, REG_PCIE_HRPWM
);
633 if (rpwm_val
& BIT(7)) {
634 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
, (*(u8
*)val
));
636 rtl_write_byte(rtlpriv
, REG_PCIE_HRPWM
,
637 ((*(u8
*)val
) | BIT(7)));
641 case HW_VAR_H2C_FW_PWRMODE
:
642 rtl8723be_set_fw_pwrmode_cmd(hw
, (*(u8
*)val
));
644 case HW_VAR_FW_PSMODE_STATUS
:
645 ppsc
->fw_current_inpsmode
= *((bool *)val
);
647 case HW_VAR_RESUME_CLK_ON
:
648 _rtl8723be_set_fw_ps_rf_on(hw
);
650 case HW_VAR_FW_LPS_ACTION
:{
651 bool b_enter_fwlps
= *((bool *)val
);
654 _rtl8723be_fwlps_enter(hw
);
656 _rtl8723be_fwlps_leave(hw
);
659 case HW_VAR_H2C_FW_JOINBSSRPT
:{
660 u8 mstatus
= (*(u8
*)val
);
662 if (mstatus
== RT_MEDIA_CONNECT
) {
663 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AID
, NULL
);
664 _rtl8723be_download_rsvd_page(hw
);
666 rtl8723be_set_fw_media_status_rpt_cmd(hw
, mstatus
);
669 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD
:
670 rtl8723be_set_p2p_ps_offload_cmd(hw
, (*(u8
*)val
));
674 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
676 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
,
677 (u2btmp
| mac
->assoc_id
));
680 case HW_VAR_CORRECT_TSF
:{
681 u8 btype_ibss
= ((u8
*)(val
))[0];
684 _rtl8723be_stop_tx_beacon(hw
);
686 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(3));
688 rtl_write_dword(rtlpriv
, REG_TSFTR
,
689 (u32
) (mac
->tsf
& 0xffffffff));
690 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
691 (u32
) ((mac
->tsf
>> 32) & 0xffffffff));
693 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
696 _rtl8723be_resume_tx_beacon(hw
);
699 case HW_VAR_KEEP_ALIVE
:{
702 array
[1] = *((u8
*)val
);
703 rtl8723be_fill_h2c_cmd(hw
, H2C_8723B_KEEP_ALIVE_CTRL
, 2, array
);
707 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
708 "switch case %#x not processed\n", variable
);
713 static bool _rtl8723be_llt_write(struct ieee80211_hw
*hw
, u32 address
, u32 data
)
715 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
718 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
719 _LLT_OP(_LLT_WRITE_ACCESS
);
721 rtl_write_dword(rtlpriv
, REG_LLT_INIT
, value
);
724 value
= rtl_read_dword(rtlpriv
, REG_LLT_INIT
);
725 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
))
728 if (count
> POLLING_LLT_THRESHOLD
) {
729 pr_err("Failed to polling write LLT done at address %d!\n",
739 static bool _rtl8723be_llt_table_init(struct ieee80211_hw
*hw
)
741 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
750 rtl_write_dword(rtlpriv
, REG_TRXFF_BNDY
,
751 (0x27FF0000 | txpktbuf_bndy
));
752 rtl_write_byte(rtlpriv
, REG_TDECTRL
+ 1, txpktbuf_bndy
);
754 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
755 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
757 rtl_write_byte(rtlpriv
, 0x45D, txpktbuf_bndy
);
758 rtl_write_byte(rtlpriv
, REG_PBP
, 0x31);
759 rtl_write_byte(rtlpriv
, REG_RX_DRVINFO_SZ
, 0x4);
761 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
762 status
= _rtl8723be_llt_write(hw
, i
, i
+ 1);
767 status
= _rtl8723be_llt_write(hw
, (txpktbuf_bndy
- 1), 0xFF);
772 for (i
= txpktbuf_bndy
; i
< maxpage
; i
++) {
773 status
= _rtl8723be_llt_write(hw
, i
, (i
+ 1));
778 status
= _rtl8723be_llt_write(hw
, maxpage
, txpktbuf_bndy
);
782 rtl_write_dword(rtlpriv
, REG_RQPN
, 0x80e40808);
783 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, 0x00);
788 static void _rtl8723be_gen_refresh_led_state(struct ieee80211_hw
*hw
)
790 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
791 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
792 struct rtl_led
*pled0
= &rtlpriv
->ledctl
.sw_led0
;
794 if (rtlpriv
->rtlhal
.up_first_time
)
797 if (ppsc
->rfoff_reason
== RF_CHANGE_BY_IPS
)
798 rtl8723be_sw_led_on(hw
, pled0
);
799 else if (ppsc
->rfoff_reason
== RF_CHANGE_BY_INIT
)
800 rtl8723be_sw_led_on(hw
, pled0
);
802 rtl8723be_sw_led_off(hw
, pled0
);
805 static bool _rtl8723be_init_mac(struct ieee80211_hw
*hw
)
807 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
808 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
809 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
810 unsigned char bytetmp
;
811 unsigned short wordtmp
;
813 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x00);
815 /*Auto Power Down to CHIP-off State*/
816 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
+ 1) & (~BIT(7));
817 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
+ 1, bytetmp
);
819 /* HW Power on sequence */
820 if (!rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
,
821 PWR_FAB_ALL_MSK
, PWR_INTF_PCI_MSK
,
822 RTL8723_NIC_ENABLE_FLOW
)) {
823 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
824 "init MAC Fail as power on failure\n");
828 if (rtlpriv
->cfg
->ops
->get_btc_status())
829 rtlpriv
->btcoexist
.btc_ops
->btc_power_on_setting(rtlpriv
);
831 bytetmp
= rtl_read_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
);
832 rtl_write_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
, bytetmp
| BIT(3));
834 bytetmp
= rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) | BIT(4);
835 rtl_write_byte(rtlpriv
, REG_APS_FSMCO
, bytetmp
);
837 bytetmp
= rtl_read_byte(rtlpriv
, REG_CR
);
839 rtl_write_byte(rtlpriv
, REG_CR
, bytetmp
);
842 bytetmp
= rtl_read_byte(rtlpriv
, REG_HWSEQ_CTRL
);
844 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, bytetmp
);
847 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
+ 3);
848 if (bytetmp
& BIT(0)) {
849 bytetmp
= rtl_read_byte(rtlpriv
, 0x7c);
850 rtl_write_byte(rtlpriv
, 0x7c, bytetmp
| BIT(6));
853 bytetmp
= rtl_read_byte(rtlpriv
, REG_SYS_CLKR
);
854 rtl_write_byte(rtlpriv
, REG_SYS_CLKR
, bytetmp
| BIT(3));
855 bytetmp
= rtl_read_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1);
856 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+ 1, bytetmp
& (~BIT(4)));
858 rtl_write_word(rtlpriv
, REG_CR
, 0x2ff);
860 if (!rtlhal
->mac_func_enable
) {
861 if (!_rtl8723be_llt_table_init(hw
))
865 rtl_write_dword(rtlpriv
, REG_HISR
, 0xffffffff);
866 rtl_write_dword(rtlpriv
, REG_HISRE
, 0xffffffff);
868 /* Enable FW Beamformer Interrupt */
869 bytetmp
= rtl_read_byte(rtlpriv
, REG_FWIMR
+ 3);
870 rtl_write_byte(rtlpriv
, REG_FWIMR
+ 3, bytetmp
| BIT(6));
872 wordtmp
= rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
);
875 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, wordtmp
);
877 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 1, 0x1F);
878 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
879 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, 0xFFFF);
880 rtl_write_dword(rtlpriv
, REG_TCR
, rtlpci
->transmit_config
);
882 rtl_write_dword(rtlpriv
, REG_BCNQ_DESA
,
883 ((u64
) rtlpci
->tx_ring
[BEACON_QUEUE
].dma
) &
885 rtl_write_dword(rtlpriv
, REG_MGQ_DESA
,
886 (u64
) rtlpci
->tx_ring
[MGNT_QUEUE
].dma
&
888 rtl_write_dword(rtlpriv
, REG_VOQ_DESA
,
889 (u64
) rtlpci
->tx_ring
[VO_QUEUE
].dma
& DMA_BIT_MASK(32));
890 rtl_write_dword(rtlpriv
, REG_VIQ_DESA
,
891 (u64
) rtlpci
->tx_ring
[VI_QUEUE
].dma
& DMA_BIT_MASK(32));
892 rtl_write_dword(rtlpriv
, REG_BEQ_DESA
,
893 (u64
) rtlpci
->tx_ring
[BE_QUEUE
].dma
& DMA_BIT_MASK(32));
894 rtl_write_dword(rtlpriv
, REG_BKQ_DESA
,
895 (u64
) rtlpci
->tx_ring
[BK_QUEUE
].dma
& DMA_BIT_MASK(32));
896 rtl_write_dword(rtlpriv
, REG_HQ_DESA
,
897 (u64
) rtlpci
->tx_ring
[HIGH_QUEUE
].dma
&
899 rtl_write_dword(rtlpriv
, REG_RX_DESA
,
900 (u64
) rtlpci
->rx_ring
[RX_MPDU_QUEUE
].dma
&
903 bytetmp
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3);
904 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 3, bytetmp
| 0x77);
906 rtl_write_dword(rtlpriv
, REG_INT_MIG
, 0);
908 rtl_write_dword(rtlpriv
, REG_MCUTST_1
, 0x0);
910 rtl_write_byte(rtlpriv
, REG_SECONDARY_CCA_CTRL
, 0x3);
912 /* <20130114, Kordan> The following setting is
913 * only for DPDT and Fixed board type.
914 * TODO: A better solution is configure it
915 * according EFUSE during the run-time.
917 rtl_set_bbreg(hw
, 0x64, BIT(20), 0x0);/* 0x66[4]=0 */
918 rtl_set_bbreg(hw
, 0x64, BIT(24), 0x0);/* 0x66[8]=0 */
919 rtl_set_bbreg(hw
, 0x40, BIT(4), 0x0)/* 0x40[4]=0 */;
920 rtl_set_bbreg(hw
, 0x40, BIT(3), 0x1)/* 0x40[3]=1 */;
921 rtl_set_bbreg(hw
, 0x4C, BIT(24) | BIT(23), 0x2)/* 0x4C[24:23]=10 */;
922 rtl_set_bbreg(hw
, 0x944, BIT(1) | BIT(0), 0x3)/* 0x944[1:0]=11 */;
923 rtl_set_bbreg(hw
, 0x930, MASKBYTE0
, 0x77)/* 0x930[7:0]=77 */;
924 rtl_set_bbreg(hw
, 0x38, BIT(11), 0x1)/* 0x38[11]=1 */;
926 bytetmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
927 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, bytetmp
& (~BIT(2)));
929 _rtl8723be_gen_refresh_led_state(hw
);
933 static void _rtl8723be_hw_configure(struct ieee80211_hw
*hw
)
935 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
936 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
939 reg_rrsr
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
940 /* Init value for RRSR. */
941 rtl_write_dword(rtlpriv
, REG_RRSR
, reg_rrsr
);
943 /* ARFB table 9 for 11ac 5G 2SS */
944 rtl_write_dword(rtlpriv
, REG_ARFR0
+ 4, 0xfffff000);
946 /* ARFB table 10 for 11ac 5G 1SS */
947 rtl_write_dword(rtlpriv
, REG_ARFR1
+ 4, 0x003ff000);
949 /* CF-End setting. */
950 rtl_write_word(rtlpriv
, REG_FWHW_TXQ_CTRL
, 0x1F00);
952 /* 0x456 = 0x70, sugguested by Zhilin */
953 rtl_write_byte(rtlpriv
, REG_AMPDU_MAX_TIME
, 0x70);
955 /* Set retry limit */
956 rtl_write_word(rtlpriv
, REG_RL
, 0x0707);
958 /* Set Data / Response auto rate fallack retry count */
959 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x01000000);
960 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4, 0x07060504);
961 rtl_write_dword(rtlpriv
, REG_RARFRC
, 0x01000000);
962 rtl_write_dword(rtlpriv
, REG_RARFRC
+ 4, 0x07060504);
964 rtlpci
->reg_bcn_ctrl_val
= 0x1d;
965 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, rtlpci
->reg_bcn_ctrl_val
);
967 /* TBTT prohibit hold time. Suggested by designer TimChen. */
968 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff); /* 8 ms */
970 rtl_write_word(rtlpriv
, REG_NAV_PROT_LEN
, 0x0040);
972 /*For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
973 rtl_write_dword(rtlpriv
, REG_FAST_EDCA_CTRL
, 0x03086666);
975 rtl_write_byte(rtlpriv
, REG_HT_SINGLE_AMPDU
, 0x80);
977 rtl_write_byte(rtlpriv
, REG_RX_PKT_LIMIT
, 0x20);
979 rtl_write_byte(rtlpriv
, REG_MAX_AGGR_NUM
, 0x1F);
982 static u8
_rtl8723be_dbi_read(struct rtl_priv
*rtlpriv
, u16 addr
)
984 u16 read_addr
= addr
& 0xfffc;
985 u8 ret
= 0, tmp
= 0, count
= 0;
987 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, read_addr
);
988 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x2);
989 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
991 while (tmp
&& count
< 20) {
993 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
997 read_addr
= REG_DBI_RDATA
+ addr
% 4;
998 ret
= rtl_read_byte(rtlpriv
, read_addr
);
1004 static void _rtl8723be_dbi_write(struct rtl_priv
*rtlpriv
, u16 addr
, u8 data
)
1006 u8 tmp
= 0, count
= 0;
1007 u16 write_addr
= 0, remainder
= addr
% 4;
1009 /* Write DBI 1Byte Data */
1010 write_addr
= REG_DBI_WDATA
+ remainder
;
1011 rtl_write_byte(rtlpriv
, write_addr
, data
);
1013 /* Write DBI 2Byte Address & Write Enable */
1014 write_addr
= (addr
& 0xfffc) | (BIT(0) << (remainder
+ 12));
1015 rtl_write_word(rtlpriv
, REG_DBI_ADDR
, write_addr
);
1017 /* Write DBI Write Flag */
1018 rtl_write_byte(rtlpriv
, REG_DBI_FLAG
, 0x1);
1020 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1022 while (tmp
&& count
< 20) {
1024 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_FLAG
);
1029 static u16
_rtl8723be_mdio_read(struct rtl_priv
*rtlpriv
, u8 addr
)
1032 u8 tmp
= 0, count
= 0;
1034 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(6));
1035 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1037 while (tmp
&& count
< 20) {
1039 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(6);
1044 ret
= rtl_read_word(rtlpriv
, REG_MDIO_RDATA
);
1049 static void _rtl8723be_mdio_write(struct rtl_priv
*rtlpriv
, u8 addr
, u16 data
)
1051 u8 tmp
= 0, count
= 0;
1053 rtl_write_word(rtlpriv
, REG_MDIO_WDATA
, data
);
1054 rtl_write_byte(rtlpriv
, REG_MDIO_CTL
, addr
| BIT(5));
1055 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1057 while (tmp
&& count
< 20) {
1059 tmp
= rtl_read_byte(rtlpriv
, REG_MDIO_CTL
) & BIT(5);
1064 static void _rtl8723be_enable_aspm_back_door(struct ieee80211_hw
*hw
)
1066 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1070 /* <Roger_Notes> Overwrite following ePHY parameter for
1071 * some platform compatibility issue,
1072 * especially when CLKReq is enabled, 2012.11.09.
1074 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x01);
1075 if (tmp16
!= 0x0663)
1076 _rtl8723be_mdio_write(rtlpriv
, 0x01, 0x0663);
1078 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x04);
1079 if (tmp16
!= 0x7544)
1080 _rtl8723be_mdio_write(rtlpriv
, 0x04, 0x7544);
1082 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x06);
1083 if (tmp16
!= 0xB880)
1084 _rtl8723be_mdio_write(rtlpriv
, 0x06, 0xB880);
1086 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x07);
1087 if (tmp16
!= 0x4000)
1088 _rtl8723be_mdio_write(rtlpriv
, 0x07, 0x4000);
1090 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x08);
1091 if (tmp16
!= 0x9003)
1092 _rtl8723be_mdio_write(rtlpriv
, 0x08, 0x9003);
1094 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x09);
1095 if (tmp16
!= 0x0D03)
1096 _rtl8723be_mdio_write(rtlpriv
, 0x09, 0x0D03);
1098 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x0A);
1099 if (tmp16
!= 0x4037)
1100 _rtl8723be_mdio_write(rtlpriv
, 0x0A, 0x4037);
1102 tmp16
= _rtl8723be_mdio_read(rtlpriv
, 0x0B);
1103 if (tmp16
!= 0x0070)
1104 _rtl8723be_mdio_write(rtlpriv
, 0x0B, 0x0070);
1106 /* Configuration Space offset 0x70f BIT7 is used to control L0S */
1107 tmp8
= _rtl8723be_dbi_read(rtlpriv
, 0x70f);
1108 _rtl8723be_dbi_write(rtlpriv
, 0x70f, tmp8
| BIT(7) |
1109 ASPM_L1_LATENCY
<< 3);
1111 /* Configuration Space offset 0x719 Bit3 is for L1
1112 * BIT4 is for clock request
1114 tmp8
= _rtl8723be_dbi_read(rtlpriv
, 0x719);
1115 _rtl8723be_dbi_write(rtlpriv
, 0x719, tmp8
| BIT(3) | BIT(4));
1118 void rtl8723be_enable_hw_security_config(struct ieee80211_hw
*hw
)
1120 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1123 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1124 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1125 rtlpriv
->sec
.pairwise_enc_algorithm
,
1126 rtlpriv
->sec
.group_enc_algorithm
);
1128 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1129 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1130 "not open hw encryption\n");
1134 sec_reg_value
= SCR_TXENCENABLE
| SCR_RXDECENABLE
;
1136 if (rtlpriv
->sec
.use_defaultkey
) {
1137 sec_reg_value
|= SCR_TXUSEDK
;
1138 sec_reg_value
|= SCR_RXUSEDK
;
1141 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1143 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1145 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1146 "The SECR-value %x\n", sec_reg_value
);
1148 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1151 static void _rtl8723be_poweroff_adapter(struct ieee80211_hw
*hw
)
1153 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1154 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1157 rtlhal
->mac_func_enable
= false;
1158 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1159 /* 1. Run LPS WL RFOFF flow */
1160 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1161 PWR_INTF_PCI_MSK
, RTL8723_NIC_LPS_ENTER_FLOW
);
1163 /* 2. 0x1F[7:0] = 0 */
1165 /* rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); */
1166 if ((rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(7)) &&
1168 rtl8723be_firmware_selfreset(hw
);
1171 /* Reset MCU. Suggested by Filen. */
1172 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1173 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, (u1b_tmp
& (~BIT(2))));
1175 /* g. MCUFWDL 0x80[1:0]=0 */
1176 /* reset MCU ready status */
1177 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0x00);
1179 /* HW card disable configuration. */
1180 rtl_hal_pwrseqcmdparsing(rtlpriv
, PWR_CUT_ALL_MSK
, PWR_FAB_ALL_MSK
,
1181 PWR_INTF_PCI_MSK
, RTL8723_NIC_DISABLE_FLOW
);
1183 /* Reset MCU IO Wrapper */
1184 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1185 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, (u1b_tmp
& (~BIT(0))));
1186 u1b_tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
+ 1);
1187 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
+ 1, u1b_tmp
| BIT(0));
1189 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1190 /* lock ISO/CLK/Power control register */
1191 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0e);
1194 static bool _rtl8723be_check_pcie_dma_hang(struct rtl_priv
*rtlpriv
)
1198 /* write reg 0x350 Bit[26]=1. Enable debug port. */
1199 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1200 if (!(tmp
& BIT(2))) {
1201 rtl_write_byte(rtlpriv
, REG_DBI_CTRL
+ 3, (tmp
| BIT(2)));
1202 mdelay(100); /* Suggested by DD Justin_tsai. */
1205 /* read reg 0x350 Bit[25] if 1 : RX hang
1206 * read reg 0x350 Bit[24] if 1 : TX hang
1208 tmp
= rtl_read_byte(rtlpriv
, REG_DBI_CTRL
+ 3);
1209 if ((tmp
& BIT(0)) || (tmp
& BIT(1))) {
1210 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1211 "CheckPcieDMAHang8723BE(): true!!\n");
1217 static void _rtl8723be_reset_pcie_interface_dma(struct rtl_priv
*rtlpriv
,
1221 bool release_mac_rx_pause
;
1222 u8 backup_pcie_dma_pause
;
1224 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1225 "ResetPcieInterfaceDMA8723BE()\n");
1227 /* Revise Note: Follow the document "PCIe RX DMA Hang Reset Flow_v03"
1228 * released by SD1 Alan.
1229 * 2013.05.07, by tynli.
1232 /* 1. disable register write lock
1233 * write 0x1C bit[1:0] = 2'h0
1234 * write 0xCC bit[2] = 1'b1
1236 tmp
= rtl_read_byte(rtlpriv
, REG_RSV_CTRL
);
1237 tmp
&= ~(BIT(1) | BIT(0));
1238 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, tmp
);
1239 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1241 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1243 /* 2. Check and pause TRX DMA
1244 * write 0x284 bit[18] = 1'b1
1245 * write 0x301 = 0xFF
1247 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1249 /* Already pause before the function for another purpose. */
1250 release_mac_rx_pause
= false;
1252 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, (tmp
| BIT(2)));
1253 release_mac_rx_pause
= true;
1256 backup_pcie_dma_pause
= rtl_read_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1);
1257 if (backup_pcie_dma_pause
!= 0xFF)
1258 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0xFF);
1261 /* 3. reset TRX function
1262 * write 0x100 = 0x00
1264 rtl_write_byte(rtlpriv
, REG_CR
, 0);
1267 /* 4. Reset PCIe DMA
1268 * write 0x003 bit[0] = 0
1270 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1272 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1274 /* 5. Enable PCIe DMA
1275 * write 0x003 bit[0] = 1
1277 tmp
= rtl_read_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1);
1279 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, tmp
);
1282 /* 6. enable TRX function
1283 * write 0x100 = 0xFF
1285 rtl_write_byte(rtlpriv
, REG_CR
, 0xFF);
1287 /* We should init LLT & RQPN and
1288 * prepare Tx/Rx descrptor address later
1289 * because MAC function is reset.
1293 /* 7. Restore PCIe autoload down bit
1294 * write 0xF8 bit[17] = 1'b1
1296 tmp
= rtl_read_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2);
1298 rtl_write_byte(rtlpriv
, REG_MAC_PHY_CTRL_NORMAL
+ 2, tmp
);
1300 /* In MAC power on state, BB and RF maybe in ON state,
1301 * if we release TRx DMA here
1302 * it will cause packets to be started to Tx/Rx,
1303 * so we release Tx/Rx DMA later.
1305 if (!mac_power_on
) {
1306 /* 8. release TRX DMA
1307 * write 0x284 bit[18] = 1'b0
1308 * write 0x301 = 0x00
1310 if (release_mac_rx_pause
) {
1311 tmp
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1312 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
,
1315 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1,
1316 backup_pcie_dma_pause
);
1319 /* 9. lock system register
1320 * write 0xCC bit[2] = 1'b0
1322 tmp
= rtl_read_byte(rtlpriv
, REG_PMC_DBG_CTRL2
);
1324 rtl_write_byte(rtlpriv
, REG_PMC_DBG_CTRL2
, tmp
);
1327 int rtl8723be_hw_init(struct ieee80211_hw
*hw
)
1329 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1330 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1331 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1332 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1333 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1334 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1335 bool rtstatus
= true;
1338 unsigned long flags
;
1340 /* reenable interrupts to not interfere with other devices */
1341 local_save_flags(flags
);
1344 rtlhal
->fw_ready
= false;
1345 rtlpriv
->rtlhal
.being_init_adapter
= true;
1346 rtlpriv
->intf_ops
->disable_aspm(hw
);
1348 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_CR
);
1349 if (tmp_u1b
!= 0 && tmp_u1b
!= 0xea) {
1350 rtlhal
->mac_func_enable
= true;
1352 rtlhal
->mac_func_enable
= false;
1353 rtlhal
->fw_ps_state
= FW_PS_STATE_ALL_ON
;
1356 if (_rtl8723be_check_pcie_dma_hang(rtlpriv
)) {
1357 _rtl8723be_reset_pcie_interface_dma(rtlpriv
,
1358 rtlhal
->mac_func_enable
);
1359 rtlhal
->mac_func_enable
= false;
1361 if (rtlhal
->mac_func_enable
) {
1362 _rtl8723be_poweroff_adapter(hw
);
1363 rtlhal
->mac_func_enable
= false;
1365 rtstatus
= _rtl8723be_init_mac(hw
);
1367 pr_err("Init MAC failed\n");
1372 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_SYS_CFG
);
1373 rtl_write_byte(rtlpriv
, REG_SYS_CFG
, tmp_u1b
& 0x7F);
1375 err
= rtl8723_download_fw(hw
, true, FW_8723B_POLLING_TIMEOUT_COUNT
);
1377 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1378 "Failed to download FW. Init HW without FW now..\n");
1382 rtlhal
->fw_ready
= true;
1384 rtlhal
->last_hmeboxnum
= 0;
1385 rtl8723be_phy_mac_config(hw
);
1386 /* because last function modify RCR, so we update
1387 * rcr var here, or TP will unstable for receive_config
1388 * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
1389 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1391 rtlpci
->receive_config
= rtl_read_dword(rtlpriv
, REG_RCR
);
1392 rtlpci
->receive_config
&= ~(RCR_ACRC32
| RCR_AICV
);
1393 rtl_write_dword(rtlpriv
, REG_RCR
, rtlpci
->receive_config
);
1395 rtl8723be_phy_bb_config(hw
);
1396 rtl8723be_phy_rf_config(hw
);
1398 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1399 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1400 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
1401 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1402 rtlphy
->rfreg_chnlval
[0] &= 0xFFF03FF;
1403 rtlphy
->rfreg_chnlval
[0] |= (BIT(10) | BIT(11));
1405 _rtl8723be_hw_configure(hw
);
1406 rtlhal
->mac_func_enable
= true;
1407 rtl_cam_reset_all_entry(hw
);
1408 rtl8723be_enable_hw_security_config(hw
);
1410 ppsc
->rfpwr_state
= ERFON
;
1412 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1413 _rtl8723be_enable_aspm_back_door(hw
);
1414 rtlpriv
->intf_ops
->enable_aspm(hw
);
1416 rtl8723be_bt_hw_init(hw
);
1418 if (ppsc
->rfpwr_state
== ERFON
) {
1419 rtl8723be_phy_set_rfpath_switch(hw
, 1);
1420 /* when use 1ant NIC, iqk will disturb BT music
1421 * root cause is not clear now, is something
1422 * related with 'mdelay' and Reg[0x948]
1424 if (rtlpriv
->btcoexist
.btc_info
.ant_num
== ANT_X2
||
1425 !rtlpriv
->cfg
->ops
->get_btc_status()) {
1426 rtl8723be_phy_iq_calibrate(hw
,
1427 (rtlphy
->iqk_initialized
?
1429 rtlphy
->iqk_initialized
= true;
1431 rtl8723be_dm_check_txpower_tracking(hw
);
1432 rtl8723be_phy_lc_calibrate(hw
);
1434 rtl_write_byte(rtlpriv
, REG_NAV_UPPER
, ((30000 + 127) / 128));
1436 /* Release Rx DMA. */
1437 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_RXDMA_CONTROL
);
1438 if (tmp_u1b
& BIT(2)) {
1439 /* Release Rx DMA if needed */
1440 tmp_u1b
&= (~BIT(2));
1441 rtl_write_byte(rtlpriv
, REG_RXDMA_CONTROL
, tmp_u1b
);
1443 /* Release Tx/Rx PCIE DMA. */
1444 rtl_write_byte(rtlpriv
, REG_PCIE_CTRL_REG
+ 1, 0);
1446 rtl8723be_dm_init(hw
);
1448 local_irq_restore(flags
);
1449 rtlpriv
->rtlhal
.being_init_adapter
= false;
1453 static enum version_8723e
_rtl8723be_read_chip_version(struct ieee80211_hw
*hw
)
1455 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1456 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1457 enum version_8723e version
= VERSION_UNKNOWN
;
1460 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG1
);
1461 if ((value32
& (CHIP_8723B
)) != CHIP_8723B
)
1462 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "unknown chip version\n");
1464 version
= (enum version_8723e
)CHIP_8723B
;
1466 rtlphy
->rf_type
= RF_1T1R
;
1468 /* treat rtl8723be chip as MP version in default */
1469 version
= (enum version_8723e
)(version
| NORMAL_CHIP
);
1471 value32
= rtl_read_dword(rtlpriv
, REG_SYS_CFG
);
1473 version
|= (enum version_8723e
)(value32
& CHIP_VER_RTL_MASK
);
1475 if (((value32
& EXT_VENDOR_ID
) >> 18) == 0x01)
1476 version
= (enum version_8723e
)(version
| CHIP_VENDOR_SMIC
);
1478 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1479 "Chip RF Type: %s\n", (rtlphy
->rf_type
== RF_2T2R
) ?
1480 "RF_2T2R" : "RF_1T1R");
1485 static int _rtl8723be_set_media_status(struct ieee80211_hw
*hw
,
1486 enum nl80211_iftype type
)
1488 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1489 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
) & 0xfc;
1490 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1491 u8 mode
= MSR_NOLINK
;
1494 case NL80211_IFTYPE_UNSPECIFIED
:
1496 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1497 "Set Network type to NO LINK!\n");
1499 case NL80211_IFTYPE_ADHOC
:
1500 case NL80211_IFTYPE_MESH_POINT
:
1502 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1503 "Set Network type to Ad Hoc!\n");
1505 case NL80211_IFTYPE_STATION
:
1507 ledaction
= LED_CTL_LINK
;
1508 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1509 "Set Network type to STA!\n");
1511 case NL80211_IFTYPE_AP
:
1513 ledaction
= LED_CTL_LINK
;
1514 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1515 "Set Network type to AP!\n");
1518 pr_err("Network type %d not support!\n", type
);
1522 /* MSR_INFRA == Link in infrastructure network;
1523 * MSR_ADHOC == Link in ad hoc network;
1524 * Therefore, check link state is necessary.
1526 * MSR_AP == AP mode; link state is not cared here.
1528 if (mode
!= MSR_AP
&& rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
) {
1530 ledaction
= LED_CTL_NO_LINK
;
1533 if (mode
== MSR_NOLINK
|| mode
== MSR_INFRA
) {
1534 _rtl8723be_stop_tx_beacon(hw
);
1535 _rtl8723be_enable_bcn_sub_func(hw
);
1536 } else if (mode
== MSR_ADHOC
|| mode
== MSR_AP
) {
1537 _rtl8723be_resume_tx_beacon(hw
);
1538 _rtl8723be_disable_bcn_sub_func(hw
);
1540 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1541 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1545 rtl_write_byte(rtlpriv
, MSR
, bt_msr
| mode
);
1546 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1548 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1550 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1554 void rtl8723be_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1556 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1557 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1558 u32 reg_rcr
= rtlpci
->receive_config
;
1560 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1564 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1565 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1567 _rtl8723be_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1568 } else if (!check_bssid
) {
1569 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1570 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1571 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1577 int rtl8723be_set_network_type(struct ieee80211_hw
*hw
,
1578 enum nl80211_iftype type
)
1580 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1582 if (_rtl8723be_set_media_status(hw
, type
))
1585 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1586 if (type
!= NL80211_IFTYPE_AP
)
1587 rtl8723be_set_check_bssid(hw
, true);
1589 rtl8723be_set_check_bssid(hw
, false);
1595 /* don't set REG_EDCA_BE_PARAM here
1596 * because mac80211 will send pkt when scan
1598 void rtl8723be_set_qos(struct ieee80211_hw
*hw
, int aci
)
1600 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1602 rtl8723_dm_init_edca_turbo(hw
);
1605 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
, 0xa44f);
1610 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
, 0x5e4322);
1613 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
, 0x2f3222);
1616 WARN_ONCE(true, "rtl8723be: invalid aci: %d !\n", aci
);
1621 void rtl8723be_enable_interrupt(struct ieee80211_hw
*hw
)
1623 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1624 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1626 rtl_write_dword(rtlpriv
, REG_HIMR
, rtlpci
->irq_mask
[0] & 0xFFFFFFFF);
1627 rtl_write_dword(rtlpriv
, REG_HIMRE
, rtlpci
->irq_mask
[1] & 0xFFFFFFFF);
1628 rtlpci
->irq_enabled
= true;
1630 /*enable system interrupt*/
1631 rtl_write_dword(rtlpriv
, REG_HSIMR
, rtlpci
->sys_irq_mask
& 0xFFFFFFFF);
1634 void rtl8723be_disable_interrupt(struct ieee80211_hw
*hw
)
1636 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1637 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1639 rtl_write_dword(rtlpriv
, REG_HIMR
, IMR_DISABLED
);
1640 rtl_write_dword(rtlpriv
, REG_HIMRE
, IMR_DISABLED
);
1641 rtlpci
->irq_enabled
= false;
1642 /*synchronize_irq(rtlpci->pdev->irq);*/
1645 void rtl8723be_card_disable(struct ieee80211_hw
*hw
)
1647 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1648 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1649 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1650 enum nl80211_iftype opmode
;
1652 mac
->link_state
= MAC80211_NOLINK
;
1653 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1654 _rtl8723be_set_media_status(hw
, opmode
);
1655 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1656 ppsc
->rfoff_reason
> RF_CHANGE_BY_PS
)
1657 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1658 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1659 _rtl8723be_poweroff_adapter(hw
);
1661 /* after power off we should do iqk again */
1662 if (!rtlpriv
->cfg
->ops
->get_btc_status())
1663 rtlpriv
->phy
.iqk_initialized
= false;
1666 void rtl8723be_interrupt_recognized(struct ieee80211_hw
*hw
,
1667 struct rtl_int
*intvec
)
1669 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1670 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1672 intvec
->inta
= rtl_read_dword(rtlpriv
, ISR
) & rtlpci
->irq_mask
[0];
1673 rtl_write_dword(rtlpriv
, ISR
, intvec
->inta
);
1675 intvec
->intb
= rtl_read_dword(rtlpriv
, REG_HISRE
) &
1676 rtlpci
->irq_mask
[1];
1677 rtl_write_dword(rtlpriv
, REG_HISRE
, intvec
->intb
);
1680 void rtl8723be_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1682 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1683 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1684 u16 bcn_interval
, atim_window
;
1686 bcn_interval
= mac
->beacon_interval
;
1687 atim_window
= 2; /*FIX MERGE */
1688 rtl8723be_disable_interrupt(hw
);
1689 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1690 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1691 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660f);
1692 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x18);
1693 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x18);
1694 rtl_write_byte(rtlpriv
, 0x606, 0x30);
1695 rtl8723be_enable_interrupt(hw
);
1698 void rtl8723be_set_beacon_interval(struct ieee80211_hw
*hw
)
1700 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1701 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1702 u16 bcn_interval
= mac
->beacon_interval
;
1704 rtl_dbg(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1705 "beacon_interval:%d\n", bcn_interval
);
1706 rtl8723be_disable_interrupt(hw
);
1707 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1708 rtl8723be_enable_interrupt(hw
);
1711 void rtl8723be_update_interrupt_mask(struct ieee80211_hw
*hw
,
1712 u32 add_msr
, u32 rm_msr
)
1714 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1715 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1717 rtl_dbg(rtlpriv
, COMP_INTR
, DBG_LOUD
,
1718 "add_msr:%x, rm_msr:%x\n", add_msr
, rm_msr
);
1721 rtlpci
->irq_mask
[0] |= add_msr
;
1723 rtlpci
->irq_mask
[0] &= (~rm_msr
);
1724 rtl8723be_disable_interrupt(hw
);
1725 rtl8723be_enable_interrupt(hw
);
1728 static u8
_rtl8723be_get_chnl_group(u8 chnl
)
1741 static void _rtl8723be_read_power_value_fromprom(struct ieee80211_hw
*hw
,
1742 struct txpower_info_2g
*pw2g
,
1743 struct txpower_info_5g
*pw5g
,
1744 bool autoload_fail
, u8
*hwinfo
)
1746 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1747 u32 path
, addr
= EEPROM_TX_PWR_INX
, group
, cnt
= 0;
1749 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1750 "hal_ReadPowerValueFromPROM8723BE(): PROMContent[0x%x]=0x%x\n",
1751 (addr
+ 1), hwinfo
[addr
+ 1]);
1752 if (0xFF == hwinfo
[addr
+ 1]) /*YJ,add,120316*/
1753 autoload_fail
= true;
1755 if (autoload_fail
) {
1756 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1757 "auto load fail : Use Default value!\n");
1758 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1759 /* 2.4G default value */
1760 for (group
= 0 ; group
< MAX_CHNL_GROUP_24G
; group
++) {
1761 pw2g
->index_cck_base
[path
][group
] = 0x2D;
1762 pw2g
->index_bw40_base
[path
][group
] = 0x2D;
1764 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1766 pw2g
->bw20_diff
[path
][0] = 0x02;
1767 pw2g
->ofdm_diff
[path
][0] = 0x04;
1769 pw2g
->bw20_diff
[path
][cnt
] = 0xFE;
1770 pw2g
->bw40_diff
[path
][cnt
] = 0xFE;
1771 pw2g
->cck_diff
[path
][cnt
] = 0xFE;
1772 pw2g
->ofdm_diff
[path
][cnt
] = 0xFE;
1779 for (path
= 0; path
< MAX_RF_PATH
; path
++) {
1780 /*2.4G default value*/
1781 for (group
= 0; group
< MAX_CHNL_GROUP_24G
; group
++) {
1782 pw2g
->index_cck_base
[path
][group
] = hwinfo
[addr
++];
1783 if (pw2g
->index_cck_base
[path
][group
] == 0xFF)
1784 pw2g
->index_cck_base
[path
][group
] = 0x2D;
1787 for (group
= 0; group
< MAX_CHNL_GROUP_24G
- 1; group
++) {
1788 pw2g
->index_bw40_base
[path
][group
] = hwinfo
[addr
++];
1789 if (pw2g
->index_bw40_base
[path
][group
] == 0xFF)
1790 pw2g
->index_bw40_base
[path
][group
] = 0x2D;
1792 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1794 pw2g
->bw40_diff
[path
][cnt
] = 0;
1795 if (hwinfo
[addr
] == 0xFF) {
1796 pw2g
->bw20_diff
[path
][cnt
] = 0x02;
1798 pw2g
->bw20_diff
[path
][cnt
] =
1799 (hwinfo
[addr
] & 0xf0) >> 4;
1800 /*bit sign number to 8 bit sign number*/
1801 if (pw2g
->bw20_diff
[path
][cnt
] & BIT(3))
1802 pw2g
->bw20_diff
[path
][cnt
] |=
1806 if (hwinfo
[addr
] == 0xFF) {
1807 pw2g
->ofdm_diff
[path
][cnt
] = 0x04;
1809 pw2g
->ofdm_diff
[path
][cnt
] =
1810 (hwinfo
[addr
] & 0x0f);
1811 /*bit sign number to 8 bit sign number*/
1812 if (pw2g
->ofdm_diff
[path
][cnt
] & BIT(3))
1813 pw2g
->ofdm_diff
[path
][cnt
] |=
1816 pw2g
->cck_diff
[path
][cnt
] = 0;
1819 if (hwinfo
[addr
] == 0xFF) {
1820 pw2g
->bw40_diff
[path
][cnt
] = 0xFE;
1822 pw2g
->bw40_diff
[path
][cnt
] =
1823 (hwinfo
[addr
] & 0xf0) >> 4;
1824 if (pw2g
->bw40_diff
[path
][cnt
] & BIT(3))
1825 pw2g
->bw40_diff
[path
][cnt
] |=
1829 if (hwinfo
[addr
] == 0xFF) {
1830 pw2g
->bw20_diff
[path
][cnt
] = 0xFE;
1832 pw2g
->bw20_diff
[path
][cnt
] =
1833 (hwinfo
[addr
] & 0x0f);
1834 if (pw2g
->bw20_diff
[path
][cnt
] & BIT(3))
1835 pw2g
->bw20_diff
[path
][cnt
] |=
1840 if (hwinfo
[addr
] == 0xFF) {
1841 pw2g
->ofdm_diff
[path
][cnt
] = 0xFE;
1843 pw2g
->ofdm_diff
[path
][cnt
] =
1844 (hwinfo
[addr
] & 0xf0) >> 4;
1845 if (pw2g
->ofdm_diff
[path
][cnt
] & BIT(3))
1846 pw2g
->ofdm_diff
[path
][cnt
] |=
1850 if (hwinfo
[addr
] == 0xFF)
1851 pw2g
->cck_diff
[path
][cnt
] = 0xFE;
1853 pw2g
->cck_diff
[path
][cnt
] =
1854 (hwinfo
[addr
] & 0x0f);
1855 if (pw2g
->cck_diff
[path
][cnt
] & BIT(3))
1856 pw2g
->cck_diff
[path
][cnt
] |=
1863 /*5G default value*/
1864 for (group
= 0; group
< MAX_CHNL_GROUP_5G
; group
++) {
1865 pw5g
->index_bw40_base
[path
][group
] = hwinfo
[addr
++];
1866 if (pw5g
->index_bw40_base
[path
][group
] == 0xFF)
1867 pw5g
->index_bw40_base
[path
][group
] = 0xFE;
1870 for (cnt
= 0; cnt
< MAX_TX_COUNT
; cnt
++) {
1872 pw5g
->bw40_diff
[path
][cnt
] = 0;
1874 if (hwinfo
[addr
] == 0xFF) {
1875 pw5g
->bw20_diff
[path
][cnt
] = 0;
1877 pw5g
->bw20_diff
[path
][0] =
1878 (hwinfo
[addr
] & 0xf0) >> 4;
1879 if (pw5g
->bw20_diff
[path
][cnt
] & BIT(3))
1880 pw5g
->bw20_diff
[path
][cnt
] |=
1884 if (hwinfo
[addr
] == 0xFF)
1885 pw5g
->ofdm_diff
[path
][cnt
] = 0x04;
1887 pw5g
->ofdm_diff
[path
][0] =
1888 (hwinfo
[addr
] & 0x0f);
1889 if (pw5g
->ofdm_diff
[path
][cnt
] & BIT(3))
1890 pw5g
->ofdm_diff
[path
][cnt
] |=
1895 if (hwinfo
[addr
] == 0xFF) {
1896 pw5g
->bw40_diff
[path
][cnt
] = 0xFE;
1898 pw5g
->bw40_diff
[path
][cnt
] =
1899 (hwinfo
[addr
] & 0xf0) >> 4;
1900 if (pw5g
->bw40_diff
[path
][cnt
] & BIT(3))
1901 pw5g
->bw40_diff
[path
][cnt
] |= 0xF0;
1904 if (hwinfo
[addr
] == 0xFF) {
1905 pw5g
->bw20_diff
[path
][cnt
] = 0xFE;
1907 pw5g
->bw20_diff
[path
][cnt
] =
1908 (hwinfo
[addr
] & 0x0f);
1909 if (pw5g
->bw20_diff
[path
][cnt
] & BIT(3))
1910 pw5g
->bw20_diff
[path
][cnt
] |= 0xF0;
1916 if (hwinfo
[addr
] == 0xFF) {
1917 pw5g
->ofdm_diff
[path
][1] = 0xFE;
1918 pw5g
->ofdm_diff
[path
][2] = 0xFE;
1920 pw5g
->ofdm_diff
[path
][1] = (hwinfo
[addr
] & 0xf0) >> 4;
1921 pw5g
->ofdm_diff
[path
][2] = (hwinfo
[addr
] & 0x0f);
1925 if (hwinfo
[addr
] == 0xFF)
1926 pw5g
->ofdm_diff
[path
][3] = 0xFE;
1928 pw5g
->ofdm_diff
[path
][3] = (hwinfo
[addr
] & 0x0f);
1931 for (cnt
= 1; cnt
< MAX_TX_COUNT
; cnt
++) {
1932 if (pw5g
->ofdm_diff
[path
][cnt
] == 0xFF)
1933 pw5g
->ofdm_diff
[path
][cnt
] = 0xFE;
1934 else if (pw5g
->ofdm_diff
[path
][cnt
] & BIT(3))
1935 pw5g
->ofdm_diff
[path
][cnt
] |= 0xF0;
1940 static void _rtl8723be_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
1944 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1945 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1946 struct txpower_info_2g pw2g
;
1947 struct txpower_info_5g pw5g
;
1951 _rtl8723be_read_power_value_fromprom(hw
, &pw2g
, &pw5g
, autoload_fail
,
1954 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
1955 for (i
= 0; i
< 14; i
++) {
1956 index
= _rtl8723be_get_chnl_group(i
+1);
1958 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
1959 pw2g
.index_cck_base
[rf_path
][index
];
1960 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
1961 pw2g
.index_bw40_base
[rf_path
][index
];
1963 for (i
= 0; i
< MAX_TX_COUNT
; i
++) {
1964 rtlefuse
->txpwr_ht20diff
[rf_path
][i
] =
1965 pw2g
.bw20_diff
[rf_path
][i
];
1966 rtlefuse
->txpwr_ht40diff
[rf_path
][i
] =
1967 pw2g
.bw40_diff
[rf_path
][i
];
1968 rtlefuse
->txpwr_legacyhtdiff
[rf_path
][i
] =
1969 pw2g
.ofdm_diff
[rf_path
][i
];
1972 for (i
= 0; i
< 14; i
++) {
1973 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1974 "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n",
1976 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
1977 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
]);
1982 rtlefuse
->eeprom_thermalmeter
=
1983 hwinfo
[EEPROM_THERMAL_METER_88E
];
1985 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1987 if (rtlefuse
->eeprom_thermalmeter
== 0xff || autoload_fail
) {
1988 rtlefuse
->apk_thermalmeterignore
= true;
1989 rtlefuse
->eeprom_thermalmeter
= EEPROM_DEFAULT_THERMALMETER
;
1992 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
1993 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
1994 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
1996 if (!autoload_fail
) {
1997 rtlefuse
->eeprom_regulatory
=
1998 hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] & 0x07;/*bit0~2*/
1999 if (hwinfo
[EEPROM_RF_BOARD_OPTION_88E
] == 0xFF)
2000 rtlefuse
->eeprom_regulatory
= 0;
2002 rtlefuse
->eeprom_regulatory
= 0;
2004 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
2005 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
2008 static u8
_rtl8723be_read_package_type(struct ieee80211_hw
*hw
)
2013 efuse_power_switch(hw
, false, true);
2014 if (!efuse_one_byte_read(hw
, 0x1FB, &value
))
2016 efuse_power_switch(hw
, false, false);
2018 switch (value
& 0x7) {
2020 package_type
= PACKAGE_TFBGA79
;
2023 package_type
= PACKAGE_TFBGA90
;
2026 package_type
= PACKAGE_QFN68
;
2029 package_type
= PACKAGE_TFBGA80
;
2032 package_type
= PACKAGE_DEFAULT
;
2036 return package_type
;
2039 static void _rtl8723be_read_adapter_info(struct ieee80211_hw
*hw
,
2042 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2043 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2044 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2045 int params
[] = {RTL8723BE_EEPROM_ID
, EEPROM_VID
, EEPROM_DID
,
2046 EEPROM_SVID
, EEPROM_SMID
, EEPROM_MAC_ADDR
,
2047 EEPROM_CHANNELPLAN
, EEPROM_VERSION
, EEPROM_CUSTOMER_ID
,
2048 COUNTRY_CODE_WORLD_WIDE_13
};
2051 bool is_toshiba_smid1
= false;
2052 bool is_toshiba_smid2
= false;
2053 bool is_samsung_smid
= false;
2054 bool is_lenovo_smid
= false;
2055 u16 toshiba_smid1
[] = {
2056 0x6151, 0x6152, 0x6154, 0x6155, 0x6177, 0x6178, 0x6179, 0x6180,
2057 0x7151, 0x7152, 0x7154, 0x7155, 0x7177, 0x7178, 0x7179, 0x7180,
2058 0x8151, 0x8152, 0x8154, 0x8155, 0x8181, 0x8182, 0x8184, 0x8185,
2059 0x9151, 0x9152, 0x9154, 0x9155, 0x9181, 0x9182, 0x9184, 0x9185
2061 u16 toshiba_smid2
[] = {
2062 0x6181, 0x6184, 0x6185, 0x7181, 0x7182, 0x7184, 0x7185, 0x8181,
2063 0x8182, 0x8184, 0x8185, 0x9181, 0x9182, 0x9184, 0x9185
2065 u16 samsung_smid
[] = {
2066 0x6191, 0x6192, 0x6193, 0x7191, 0x7192, 0x7193, 0x8191, 0x8192,
2067 0x8193, 0x9191, 0x9192, 0x9193
2069 u16 lenovo_smid
[] = {
2070 0x8195, 0x9195, 0x7194, 0x8200, 0x8201, 0x8202, 0x9199, 0x9200
2074 /* needs to be added */
2078 hwinfo
= kzalloc(HWSET_MAX_SIZE
, GFP_KERNEL
);
2082 if (rtl_get_hwinfo(hw
, rtlpriv
, HWSET_MAX_SIZE
, hwinfo
, params
))
2086 rtlefuse
->crystalcap
= hwinfo
[EEPROM_XTAL_8723BE
];
2087 if (rtlefuse
->crystalcap
== 0xFF)
2088 rtlefuse
->crystalcap
= 0x20;
2090 _rtl8723be_read_txpower_info_from_hwpg(hw
, rtlefuse
->autoload_failflag
,
2093 rtl8723be_read_bt_coexist_info_from_hwpg(hw
,
2094 rtlefuse
->autoload_failflag
,
2097 if (rtlpriv
->btcoexist
.btc_info
.btcoexist
== 1)
2098 rtlefuse
->board_type
|= BIT(2); /* ODM_BOARD_BT */
2100 rtlhal
->board_type
= rtlefuse
->board_type
;
2101 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
,
2102 "board_type = 0x%x\n", rtlefuse
->board_type
);
2104 rtlhal
->package_type
= _rtl8723be_read_package_type(hw
);
2106 /* set channel plan from efuse */
2107 rtlefuse
->channel_plan
= rtlefuse
->eeprom_channelplan
;
2109 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
2110 /* Does this one have a Toshiba SMID from group 1? */
2111 for (i
= 0; i
< ARRAY_SIZE(toshiba_smid1
); i
++) {
2112 if (rtlefuse
->eeprom_smid
== toshiba_smid1
[i
]) {
2113 is_toshiba_smid1
= true;
2117 /* Does this one have a Toshiba SMID from group 2? */
2118 for (i
= 0; i
< ARRAY_SIZE(toshiba_smid2
); i
++) {
2119 if (rtlefuse
->eeprom_smid
== toshiba_smid2
[i
]) {
2120 is_toshiba_smid2
= true;
2124 /* Does this one have a Samsung SMID? */
2125 for (i
= 0; i
< ARRAY_SIZE(samsung_smid
); i
++) {
2126 if (rtlefuse
->eeprom_smid
== samsung_smid
[i
]) {
2127 is_samsung_smid
= true;
2131 /* Does this one have a Lenovo SMID? */
2132 for (i
= 0; i
< ARRAY_SIZE(lenovo_smid
); i
++) {
2133 if (rtlefuse
->eeprom_smid
== lenovo_smid
[i
]) {
2134 is_lenovo_smid
= true;
2138 switch (rtlefuse
->eeprom_oemid
) {
2139 case EEPROM_CID_DEFAULT
:
2140 if (rtlefuse
->eeprom_did
== 0x8176) {
2141 if (rtlefuse
->eeprom_svid
== 0x10EC &&
2143 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2144 } else if (rtlefuse
->eeprom_svid
== 0x1025) {
2145 rtlhal
->oem_id
= RT_CID_819X_ACER
;
2146 } else if (rtlefuse
->eeprom_svid
== 0x10EC &&
2148 rtlhal
->oem_id
= RT_CID_819X_SAMSUNG
;
2149 } else if (rtlefuse
->eeprom_svid
== 0x10EC &&
2151 rtlhal
->oem_id
= RT_CID_819X_LENOVO
;
2152 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2153 rtlefuse
->eeprom_smid
== 0x8197) ||
2154 (rtlefuse
->eeprom_svid
== 0x10EC &&
2155 rtlefuse
->eeprom_smid
== 0x9196)) {
2156 rtlhal
->oem_id
= RT_CID_819X_CLEVO
;
2157 } else if ((rtlefuse
->eeprom_svid
== 0x1028 &&
2158 rtlefuse
->eeprom_smid
== 0x8194) ||
2159 (rtlefuse
->eeprom_svid
== 0x1028 &&
2160 rtlefuse
->eeprom_smid
== 0x8198) ||
2161 (rtlefuse
->eeprom_svid
== 0x1028 &&
2162 rtlefuse
->eeprom_smid
== 0x9197) ||
2163 (rtlefuse
->eeprom_svid
== 0x1028 &&
2164 rtlefuse
->eeprom_smid
== 0x9198)) {
2165 rtlhal
->oem_id
= RT_CID_819X_DELL
;
2166 } else if ((rtlefuse
->eeprom_svid
== 0x103C &&
2167 rtlefuse
->eeprom_smid
== 0x1629)) {
2168 rtlhal
->oem_id
= RT_CID_819X_HP
;
2169 } else if ((rtlefuse
->eeprom_svid
== 0x1A32 &&
2170 rtlefuse
->eeprom_smid
== 0x2315)) {
2171 rtlhal
->oem_id
= RT_CID_819X_QMI
;
2172 } else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2173 rtlefuse
->eeprom_smid
== 0x8203)) {
2174 rtlhal
->oem_id
= RT_CID_819X_PRONETS
;
2175 } else if ((rtlefuse
->eeprom_svid
== 0x1043 &&
2176 rtlefuse
->eeprom_smid
== 0x84B5)) {
2177 rtlhal
->oem_id
= RT_CID_819X_EDIMAX_ASUS
;
2179 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2181 } else if (rtlefuse
->eeprom_did
== 0x8178) {
2182 if (rtlefuse
->eeprom_svid
== 0x10EC &&
2184 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2185 else if (rtlefuse
->eeprom_svid
== 0x1025)
2186 rtlhal
->oem_id
= RT_CID_819X_ACER
;
2187 else if ((rtlefuse
->eeprom_svid
== 0x10EC &&
2188 rtlefuse
->eeprom_smid
== 0x8186))
2189 rtlhal
->oem_id
= RT_CID_819X_PRONETS
;
2190 else if ((rtlefuse
->eeprom_svid
== 0x1043 &&
2191 rtlefuse
->eeprom_smid
== 0x84B6))
2193 RT_CID_819X_EDIMAX_ASUS
;
2195 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2197 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2200 case EEPROM_CID_TOSHIBA
:
2201 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
2203 case EEPROM_CID_CCX
:
2204 rtlhal
->oem_id
= RT_CID_CCX
;
2206 case EEPROM_CID_QMI
:
2207 rtlhal
->oem_id
= RT_CID_819X_QMI
;
2209 case EEPROM_CID_WHQL
:
2212 rtlhal
->oem_id
= RT_CID_DEFAULT
;
2220 static void _rtl8723be_hal_customized_behavior(struct ieee80211_hw
*hw
)
2222 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2223 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2225 rtlpriv
->ledctl
.led_opendrain
= true;
2226 switch (rtlhal
->oem_id
) {
2227 case RT_CID_819X_HP
:
2228 rtlpriv
->ledctl
.led_opendrain
= true;
2230 case RT_CID_819X_LENOVO
:
2231 case RT_CID_DEFAULT
:
2232 case RT_CID_TOSHIBA
:
2234 case RT_CID_819X_ACER
:
2239 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
,
2240 "RT Customized ID: 0x%02X\n", rtlhal
->oem_id
);
2243 void rtl8723be_read_eeprom_info(struct ieee80211_hw
*hw
)
2245 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2246 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2247 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2248 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2251 rtlhal
->version
= _rtl8723be_read_chip_version(hw
);
2252 if (get_rf_type(rtlphy
) == RF_1T1R
)
2253 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
2255 rtlpriv
->dm
.rfpath_rxenable
[0] =
2256 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
2257 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "VersionID = 0x%4x\n",
2259 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
2260 if (tmp_u1b
& BIT(4)) {
2261 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EEPROM\n");
2262 rtlefuse
->epromtype
= EEPROM_93C46
;
2264 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from EFUSE\n");
2265 rtlefuse
->epromtype
= EEPROM_BOOT_EFUSE
;
2267 if (tmp_u1b
& BIT(5)) {
2268 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
2269 rtlefuse
->autoload_failflag
= false;
2270 _rtl8723be_read_adapter_info(hw
, false);
2272 pr_err("Autoload ERR!!\n");
2274 _rtl8723be_hal_customized_behavior(hw
);
2277 static u8
_rtl8723be_mrate_idx_to_arfr_id(struct ieee80211_hw
*hw
,
2281 switch (rate_index
) {
2282 case RATR_INX_WIRELESS_NGB
:
2285 case RATR_INX_WIRELESS_N
:
2286 case RATR_INX_WIRELESS_NG
:
2289 case RATR_INX_WIRELESS_NB
:
2292 case RATR_INX_WIRELESS_GB
:
2295 case RATR_INX_WIRELESS_G
:
2298 case RATR_INX_WIRELESS_B
:
2308 static void rtl8723be_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2309 struct ieee80211_sta
*sta
,
2310 u8 rssi_level
, bool update_bw
)
2312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2313 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2314 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2315 struct rtl_sta_info
*sta_entry
= NULL
;
2318 u8 curtxbw_40mhz
= (sta
->ht_cap
.cap
&
2319 IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ? 1 : 0;
2320 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2322 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2324 enum wireless_mode wirelessmode
= 0;
2325 bool shortgi
= false;
2329 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
2330 wirelessmode
= sta_entry
->wireless_mode
;
2331 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2332 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2333 curtxbw_40mhz
= mac
->bw_40
;
2334 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2335 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2336 macid
= sta
->aid
+ 1;
2338 ratr_bitmap
= sta
->supp_rates
[0];
2340 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2341 ratr_bitmap
= 0xfff;
2343 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2344 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2345 switch (wirelessmode
) {
2346 case WIRELESS_MODE_B
:
2347 ratr_index
= RATR_INX_WIRELESS_B
;
2348 if (ratr_bitmap
& 0x0000000c)
2349 ratr_bitmap
&= 0x0000000d;
2351 ratr_bitmap
&= 0x0000000f;
2353 case WIRELESS_MODE_G
:
2354 ratr_index
= RATR_INX_WIRELESS_GB
;
2356 if (rssi_level
== 1)
2357 ratr_bitmap
&= 0x00000f00;
2358 else if (rssi_level
== 2)
2359 ratr_bitmap
&= 0x00000ff0;
2361 ratr_bitmap
&= 0x00000ff5;
2363 case WIRELESS_MODE_N_24G
:
2364 case WIRELESS_MODE_N_5G
:
2365 ratr_index
= RATR_INX_WIRELESS_NGB
;
2366 if (rtlphy
->rf_type
== RF_1T1R
) {
2367 if (curtxbw_40mhz
) {
2368 if (rssi_level
== 1)
2369 ratr_bitmap
&= 0x000f0000;
2370 else if (rssi_level
== 2)
2371 ratr_bitmap
&= 0x000ff000;
2373 ratr_bitmap
&= 0x000ff015;
2375 if (rssi_level
== 1)
2376 ratr_bitmap
&= 0x000f0000;
2377 else if (rssi_level
== 2)
2378 ratr_bitmap
&= 0x000ff000;
2380 ratr_bitmap
&= 0x000ff005;
2383 if (curtxbw_40mhz
) {
2384 if (rssi_level
== 1)
2385 ratr_bitmap
&= 0x0f8f0000;
2386 else if (rssi_level
== 2)
2387 ratr_bitmap
&= 0x0f8ff000;
2389 ratr_bitmap
&= 0x0f8ff015;
2391 if (rssi_level
== 1)
2392 ratr_bitmap
&= 0x0f8f0000;
2393 else if (rssi_level
== 2)
2394 ratr_bitmap
&= 0x0f8ff000;
2396 ratr_bitmap
&= 0x0f8ff005;
2399 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2400 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2403 else if (macid
== 1)
2408 ratr_index
= RATR_INX_WIRELESS_NGB
;
2410 if (rtlphy
->rf_type
== RF_1T2R
)
2411 ratr_bitmap
&= 0x000ff0ff;
2413 ratr_bitmap
&= 0x0f0ff0ff;
2417 sta_entry
->ratr_index
= ratr_index
;
2419 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2420 "ratr_bitmap :%x\n", ratr_bitmap
);
2421 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2423 rate_mask
[0] = macid
;
2424 rate_mask
[1] = _rtl8723be_mrate_idx_to_arfr_id(hw
, ratr_index
) |
2425 (shortgi
? 0x80 : 0x00);
2426 rate_mask
[2] = curtxbw_40mhz
| ((!update_bw
) << 3);
2428 rate_mask
[3] = (u8
)(ratr_bitmap
& 0x000000ff);
2429 rate_mask
[4] = (u8
)((ratr_bitmap
& 0x0000ff00) >> 8);
2430 rate_mask
[5] = (u8
)((ratr_bitmap
& 0x00ff0000) >> 16);
2431 rate_mask
[6] = (u8
)((ratr_bitmap
& 0xff000000) >> 24);
2433 rtl_dbg(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2434 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
2435 ratr_index
, ratr_bitmap
,
2436 rate_mask
[0], rate_mask
[1],
2437 rate_mask
[2], rate_mask
[3],
2438 rate_mask
[4], rate_mask
[5],
2440 rtl8723be_fill_h2c_cmd(hw
, H2C_8723B_RA_MASK
, 7, rate_mask
);
2441 _rtl8723be_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2444 void rtl8723be_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2445 struct ieee80211_sta
*sta
,
2446 u8 rssi_level
, bool update_bw
)
2448 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2449 if (rtlpriv
->dm
.useramask
)
2450 rtl8723be_update_hal_rate_mask(hw
, sta
, rssi_level
, update_bw
);
2453 void rtl8723be_update_channel_access_setting(struct ieee80211_hw
*hw
)
2455 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2456 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2459 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
, &mac
->slot_time
);
2460 if (!mac
->ht_enable
)
2461 sifs_timer
= 0x0a0a;
2463 sifs_timer
= 0x0e0e;
2464 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2467 bool rtl8723be_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
*valid
)
2469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2470 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2471 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2472 enum rf_pwrstate e_rfpowerstate_toset
;
2474 bool b_actuallyset
= false;
2476 if (rtlpriv
->rtlhal
.being_init_adapter
)
2479 if (ppsc
->swrf_processing
)
2482 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2483 if (ppsc
->rfchange_inprogress
) {
2484 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2487 ppsc
->rfchange_inprogress
= true;
2488 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2491 rtl_write_byte(rtlpriv
, REG_GPIO_IO_SEL_2
,
2492 rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL_2
) & ~(BIT(1)));
2494 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_PIN_CTRL_2
);
2496 if (rtlphy
->polarity_ctl
)
2497 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFOFF
: ERFON
;
2499 e_rfpowerstate_toset
= (u1tmp
& BIT(1)) ? ERFON
: ERFOFF
;
2501 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
2502 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2503 "GPIOChangeRF - HW Radio ON, RF ON\n");
2505 e_rfpowerstate_toset
= ERFON
;
2506 ppsc
->hwradiooff
= false;
2507 b_actuallyset
= true;
2508 } else if (!ppsc
->hwradiooff
&& (e_rfpowerstate_toset
== ERFOFF
)) {
2509 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
2510 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2512 e_rfpowerstate_toset
= ERFOFF
;
2513 ppsc
->hwradiooff
= true;
2514 b_actuallyset
= true;
2517 if (b_actuallyset
) {
2518 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2519 ppsc
->rfchange_inprogress
= false;
2520 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2522 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_HALT_NIC
)
2523 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
2525 spin_lock(&rtlpriv
->locks
.rf_ps_lock
);
2526 ppsc
->rfchange_inprogress
= false;
2527 spin_unlock(&rtlpriv
->locks
.rf_ps_lock
);
2531 return !ppsc
->hwradiooff
;
2535 void rtl8723be_set_key(struct ieee80211_hw
*hw
, u32 key_index
,
2536 u8
*p_macaddr
, bool is_group
, u8 enc_algo
,
2537 bool is_wepkey
, bool clear_all
)
2539 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2540 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2541 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2542 u8
*macaddr
= p_macaddr
;
2544 bool is_pairwise
= false;
2546 static u8 cam_const_addr
[4][6] = {
2547 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2548 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2549 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2550 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2552 static u8 cam_const_broad
[] = {
2553 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2559 u8 clear_number
= 5;
2561 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "clear_all\n");
2563 for (idx
= 0; idx
< clear_number
; idx
++) {
2564 rtl_cam_mark_invalid(hw
, cam_offset
+ idx
);
2565 rtl_cam_empty_entry(hw
, cam_offset
+ idx
);
2568 memset(rtlpriv
->sec
.key_buf
[idx
], 0,
2570 rtlpriv
->sec
.key_len
[idx
] = 0;
2576 case WEP40_ENCRYPTION
:
2577 enc_algo
= CAM_WEP40
;
2579 case WEP104_ENCRYPTION
:
2580 enc_algo
= CAM_WEP104
;
2582 case TKIP_ENCRYPTION
:
2583 enc_algo
= CAM_TKIP
;
2585 case AESCCMP_ENCRYPTION
:
2589 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
2590 "switch case %#x not processed\n", enc_algo
);
2591 enc_algo
= CAM_TKIP
;
2595 if (is_wepkey
|| rtlpriv
->sec
.use_defaultkey
) {
2596 macaddr
= cam_const_addr
[key_index
];
2597 entry_id
= key_index
;
2600 macaddr
= cam_const_broad
;
2601 entry_id
= key_index
;
2603 if (mac
->opmode
== NL80211_IFTYPE_AP
) {
2604 entry_id
= rtl_cam_get_free_entry(hw
,
2606 if (entry_id
>= TOTAL_CAM_ENTRY
) {
2607 pr_err("Can not find free hw security cam entry\n");
2611 entry_id
= CAM_PAIRWISE_KEY_POSITION
;
2614 key_index
= PAIRWISE_KEYIDX
;
2619 if (rtlpriv
->sec
.key_len
[key_index
] == 0) {
2620 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2621 "delete one entry, entry_id is %d\n",
2623 if (mac
->opmode
== NL80211_IFTYPE_AP
)
2624 rtl_cam_del_entry(hw
, p_macaddr
);
2625 rtl_cam_delete_one_entry(hw
, p_macaddr
, entry_id
);
2627 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2630 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2631 "set Pairwise key\n");
2633 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2635 CAM_CONFIG_NO_USEDK
,
2636 rtlpriv
->sec
.key_buf
[key_index
]);
2638 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
2641 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
2642 rtl_cam_add_one_entry(hw
,
2645 CAM_PAIRWISE_KEY_POSITION
,
2647 CAM_CONFIG_NO_USEDK
,
2648 rtlpriv
->sec
.key_buf
2652 rtl_cam_add_one_entry(hw
, macaddr
, key_index
,
2654 CAM_CONFIG_NO_USEDK
,
2655 rtlpriv
->sec
.key_buf
[entry_id
]);
2661 void rtl8723be_read_bt_coexist_info_from_hwpg(struct ieee80211_hw
*hw
,
2662 bool auto_load_fail
, u8
*hwinfo
)
2664 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2665 struct rtl_mod_params
*mod_params
= rtlpriv
->cfg
->mod_params
;
2669 if (!auto_load_fail
) {
2670 tmpu_32
= rtl_read_dword(rtlpriv
, REG_MULTI_FUNC_CTRL
);
2671 if (tmpu_32
& BIT(18))
2672 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 1;
2674 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
2675 value
= hwinfo
[EEPROM_RF_BT_SETTING_8723B
];
2676 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8723B
;
2677 rtlpriv
->btcoexist
.btc_info
.ant_num
= (value
& 0x1);
2678 rtlpriv
->btcoexist
.btc_info
.single_ant_path
=
2679 (value
& 0x40 ? ANT_AUX
: ANT_MAIN
); /*0xc3[6]*/
2681 rtlpriv
->btcoexist
.btc_info
.btcoexist
= 0;
2682 rtlpriv
->btcoexist
.btc_info
.bt_type
= BT_RTL8723B
;
2683 rtlpriv
->btcoexist
.btc_info
.ant_num
= ANT_X2
;
2684 rtlpriv
->btcoexist
.btc_info
.single_ant_path
= ANT_MAIN
;
2687 /* override ant_num / ant_path */
2688 if (mod_params
->ant_sel
) {
2689 rtlpriv
->btcoexist
.btc_info
.ant_num
=
2690 (mod_params
->ant_sel
== 1 ? ANT_X1
: ANT_X2
);
2692 rtlpriv
->btcoexist
.btc_info
.single_ant_path
=
2693 (mod_params
->ant_sel
== 1 ? ANT_AUX
: ANT_MAIN
);
2697 void rtl8723be_bt_reg_init(struct ieee80211_hw
*hw
)
2699 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2701 /* 0:Low, 1:High, 2:From Efuse. */
2702 rtlpriv
->btcoexist
.reg_bt_iso
= 2;
2703 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2704 rtlpriv
->btcoexist
.reg_bt_sco
= 3;
2705 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2706 rtlpriv
->btcoexist
.reg_bt_sco
= 0;
2709 void rtl8723be_bt_hw_init(struct ieee80211_hw
*hw
)
2711 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2713 if (rtlpriv
->cfg
->ops
->get_btc_status())
2714 rtlpriv
->btcoexist
.btc_ops
->btc_init_hw_config(rtlpriv
);
2718 void rtl8723be_suspend(struct ieee80211_hw
*hw
)
2722 void rtl8723be_resume(struct ieee80211_hw
*hw
)