1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
40 #include "../pwrseqcmd.h"
42 #include "../btcoexist/rtl_btc.h"
46 static void _rtl8821ae_return_beacon_queue_skb(struct ieee80211_hw *hw)
48 struct rtl_priv *rtlpriv = rtl_priv(hw);
49 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
50 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[BEACON_QUEUE];
53 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
54 while (skb_queue_len(&ring->queue)) {
55 struct rtl_tx_desc *entry = &ring->desc[ring->idx];
56 struct sk_buff *skb = __skb_dequeue(&ring->queue);
58 pci_unmap_single(rtlpci->pdev,
59 rtlpriv->cfg->ops->get_desc(
61 (u8 *)entry, true, HW_DESC_TXBUFF_ADDR),
62 skb->len, PCI_DMA_TODEVICE);
64 ring->idx = (ring->idx + 1) % ring->entries;
66 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
69 static void _rtl8821ae_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
70 u8 set_bits, u8 clear_bits)
72 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
73 struct rtl_priv *rtlpriv = rtl_priv(hw);
75 rtlpci->reg_bcn_ctrl_val |= set_bits;
76 rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
78 rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlpci->reg_bcn_ctrl_val);
81 void _rtl8821ae_stop_tx_beacon(struct ieee80211_hw *hw)
83 struct rtl_priv *rtlpriv = rtl_priv(hw);
86 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
87 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
88 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
89 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
90 tmp1byte &= ~(BIT(0));
91 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
94 void _rtl8821ae_resume_tx_beacon(struct ieee80211_hw *hw)
96 struct rtl_priv *rtlpriv = rtl_priv(hw);
99 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
100 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
101 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
102 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
104 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
107 static void _rtl8821ae_enable_bcn_sub_func(struct ieee80211_hw *hw)
109 _rtl8821ae_set_bcn_ctrl_reg(hw, 0, BIT(1));
112 static void _rtl8821ae_disable_bcn_sub_func(struct ieee80211_hw *hw)
114 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(1), 0);
117 static void _rtl8821ae_set_fw_clock_on(struct ieee80211_hw *hw,
118 u8 rpwm_val, bool b_need_turn_off_ckk)
120 struct rtl_priv *rtlpriv = rtl_priv(hw);
121 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
122 bool b_support_remote_wake_up;
123 u32 count = 0, isr_regaddr, content;
124 bool b_schedule_timer = b_need_turn_off_ckk;
126 rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
127 (u8 *)(&b_support_remote_wake_up));
129 if (!rtlhal->fw_ready)
131 if (!rtlpriv->psc.fw_current_inpsmode)
135 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
136 if (rtlhal->fw_clk_change_in_progress) {
137 while (rtlhal->fw_clk_change_in_progress) {
138 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
143 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
145 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
147 rtlhal->fw_clk_change_in_progress = false;
148 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
153 if (IS_IN_LOW_POWER_STATE_8821AE(rtlhal->fw_ps_state)) {
154 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_SET_RPWM,
156 if (FW_PS_IS_ACK(rpwm_val)) {
157 isr_regaddr = REG_HISR;
158 content = rtl_read_dword(rtlpriv, isr_regaddr);
159 while (!(content & IMR_CPWM) && (count < 500)) {
162 content = rtl_read_dword(rtlpriv, isr_regaddr);
165 if (content & IMR_CPWM) {
166 rtl_write_word(rtlpriv, isr_regaddr, 0x0100);
167 rtlhal->fw_ps_state = FW_PS_STATE_RF_ON_8821AE;
168 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
169 "Receive CPWM INT!!! Set rtlhal->FwPSState = %X\n",
170 rtlhal->fw_ps_state);
174 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
175 rtlhal->fw_clk_change_in_progress = false;
176 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
177 if (b_schedule_timer)
178 mod_timer(&rtlpriv->works.fw_clockoff_timer,
179 jiffies + MSECS(10));
181 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
182 rtlhal->fw_clk_change_in_progress = false;
183 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
187 static void _rtl8821ae_set_fw_clock_off(struct ieee80211_hw *hw,
190 struct rtl_priv *rtlpriv = rtl_priv(hw);
191 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
192 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
193 struct rtl8192_tx_ring *ring;
194 enum rf_pwrstate rtstate;
195 bool b_schedule_timer = false;
198 if (!rtlhal->fw_ready)
200 if (!rtlpriv->psc.fw_current_inpsmode)
202 if (!rtlhal->allow_sw_to_change_hwclc)
204 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rtstate));
205 if (rtstate == ERFOFF || rtlpriv->psc.inactive_pwrstate == ERFOFF)
208 for (queue = 0; queue < RTL_PCI_MAX_TX_QUEUE_COUNT; queue++) {
209 ring = &rtlpci->tx_ring[queue];
210 if (skb_queue_len(&ring->queue)) {
211 b_schedule_timer = true;
216 if (b_schedule_timer) {
217 mod_timer(&rtlpriv->works.fw_clockoff_timer,
218 jiffies + MSECS(10));
222 if (FW_PS_STATE(rtlhal->fw_ps_state) !=
223 FW_PS_STATE_RF_OFF_LOW_PWR_8821AE) {
224 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
225 if (!rtlhal->fw_clk_change_in_progress) {
226 rtlhal->fw_clk_change_in_progress = true;
227 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
228 rtlhal->fw_ps_state = FW_PS_STATE(rpwm_val);
229 rtl_write_word(rtlpriv, REG_HISR, 0x0100);
230 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
232 spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
233 rtlhal->fw_clk_change_in_progress = false;
234 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
236 spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
237 mod_timer(&rtlpriv->works.fw_clockoff_timer,
238 jiffies + MSECS(10));
243 static void _rtl8821ae_set_fw_ps_rf_on(struct ieee80211_hw *hw)
247 rpwm_val |= (FW_PS_STATE_RF_OFF_8821AE | FW_PS_ACK);
248 _rtl8821ae_set_fw_clock_on(hw, rpwm_val, true);
251 static void _rtl8821ae_fwlps_leave(struct ieee80211_hw *hw)
253 struct rtl_priv *rtlpriv = rtl_priv(hw);
254 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
255 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
256 bool fw_current_inps = false;
257 u8 rpwm_val = 0, fw_pwrmode = FW_PS_ACTIVE_MODE;
259 if (ppsc->low_power_enable) {
260 rpwm_val = (FW_PS_STATE_ALL_ON_8821AE|FW_PS_ACK);/* RF on */
261 _rtl8821ae_set_fw_clock_on(hw, rpwm_val, false);
262 rtlhal->allow_sw_to_change_hwclc = false;
263 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
264 (u8 *)(&fw_pwrmode));
265 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
266 (u8 *)(&fw_current_inps));
268 rpwm_val = FW_PS_STATE_ALL_ON_8821AE; /* RF on */
269 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
271 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
272 (u8 *)(&fw_pwrmode));
273 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
274 (u8 *)(&fw_current_inps));
278 static void _rtl8821ae_fwlps_enter(struct ieee80211_hw *hw)
280 struct rtl_priv *rtlpriv = rtl_priv(hw);
281 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
282 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
283 bool fw_current_inps = true;
286 if (ppsc->low_power_enable) {
287 rpwm_val = FW_PS_STATE_RF_OFF_LOW_PWR_8821AE; /* RF off */
288 rtlpriv->cfg->ops->set_hw_reg(hw,
289 HW_VAR_FW_PSMODE_STATUS,
290 (u8 *)(&fw_current_inps));
291 rtlpriv->cfg->ops->set_hw_reg(hw,
292 HW_VAR_H2C_FW_PWRMODE,
293 (u8 *)(&ppsc->fwctrl_psmode));
294 rtlhal->allow_sw_to_change_hwclc = true;
295 _rtl8821ae_set_fw_clock_off(hw, rpwm_val);
297 rpwm_val = FW_PS_STATE_RF_OFF_8821AE; /* RF off */
298 rtlpriv->cfg->ops->set_hw_reg(hw,
299 HW_VAR_FW_PSMODE_STATUS,
300 (u8 *)(&fw_current_inps));
301 rtlpriv->cfg->ops->set_hw_reg(hw,
302 HW_VAR_H2C_FW_PWRMODE,
303 (u8 *)(&ppsc->fwctrl_psmode));
304 rtlpriv->cfg->ops->set_hw_reg(hw,
310 static void _rtl8821ae_download_rsvd_page(struct ieee80211_hw *hw,
311 bool dl_whole_packets)
313 struct rtl_priv *rtlpriv = rtl_priv(hw);
314 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
315 u8 tmp_regcr, tmp_reg422, bcnvalid_reg;
316 u8 count = 0, dlbcn_count = 0;
317 bool send_beacon = false;
319 tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
320 rtl_write_byte(rtlpriv, REG_CR + 1, (tmp_regcr | BIT(0)));
322 _rtl8821ae_set_bcn_ctrl_reg(hw, 0, BIT(3));
323 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(4), 0);
325 tmp_reg422 = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
326 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
327 tmp_reg422 & (~BIT(6)));
328 if (tmp_reg422 & BIT(6))
332 bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL + 2);
333 rtl_write_byte(rtlpriv, REG_TDECTRL + 2,
334 (bcnvalid_reg | BIT(0)));
335 _rtl8821ae_return_beacon_queue_skb(hw);
337 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
338 rtl8812ae_set_fw_rsvdpagepkt(hw, false,
341 rtl8821ae_set_fw_rsvdpagepkt(hw, false,
344 bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL + 2);
346 while (!(bcnvalid_reg & BIT(0)) && count < 20) {
349 bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL + 2);
352 } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5);
354 if (!(bcnvalid_reg & BIT(0)))
355 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
356 "Download RSVD page failed!\n");
357 if (bcnvalid_reg & BIT(0) && rtlhal->enter_pnp_sleep) {
358 rtl_write_byte(rtlpriv, REG_TDECTRL + 2, bcnvalid_reg | BIT(0));
359 _rtl8821ae_return_beacon_queue_skb(hw);
363 rtl_write_byte(rtlpriv, REG_TDECTRL + 2,
364 bcnvalid_reg | BIT(0));
366 _rtl8821ae_return_beacon_queue_skb(hw);
368 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
369 rtl8812ae_set_fw_rsvdpagepkt(hw, true,
372 rtl8821ae_set_fw_rsvdpagepkt(hw, true,
375 /* check rsvd page download OK. */
376 bcnvalid_reg = rtl_read_byte(rtlpriv,
379 while (!(bcnvalid_reg & BIT(0)) && count < 20) {
383 rtl_read_byte(rtlpriv,
387 } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5);
389 if (!(bcnvalid_reg & BIT(0)))
390 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
391 "2 Download RSVD page failed!\n");
395 if (bcnvalid_reg & BIT(0))
396 rtl_write_byte(rtlpriv, REG_TDECTRL + 2, BIT(0));
398 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(3), 0);
399 _rtl8821ae_set_bcn_ctrl_reg(hw, 0, BIT(4));
402 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp_reg422);
404 if (!rtlhal->enter_pnp_sleep) {
405 tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
406 rtl_write_byte(rtlpriv, REG_CR + 1, (tmp_regcr & ~(BIT(0))));
410 void rtl8821ae_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
412 struct rtl_priv *rtlpriv = rtl_priv(hw);
413 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
414 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
415 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
418 case HW_VAR_ETHER_ADDR:
419 *((u32 *)(val)) = rtl_read_dword(rtlpriv, REG_MACID);
420 *((u16 *)(val+4)) = rtl_read_word(rtlpriv, REG_MACID + 4);
423 *((u32 *)(val)) = rtl_read_dword(rtlpriv, REG_BSSID);
424 *((u16 *)(val+4)) = rtl_read_word(rtlpriv, REG_BSSID+4);
426 case HW_VAR_MEDIA_STATUS:
427 val[0] = rtl_read_byte(rtlpriv, MSR) & 0x3;
429 case HW_VAR_SLOT_TIME:
430 *((u8 *)(val)) = mac->slot_time;
432 case HW_VAR_BEACON_INTERVAL:
433 *((u16 *)(val)) = rtl_read_word(rtlpriv, REG_BCN_INTERVAL);
435 case HW_VAR_ATIM_WINDOW:
436 *((u16 *)(val)) = rtl_read_word(rtlpriv, REG_ATIMWND);
439 *((u32 *)(val)) = rtlpci->receive_config;
441 case HW_VAR_RF_STATE:
442 *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
444 case HW_VAR_FWLPS_RF_ON:{
445 enum rf_pwrstate rfstate;
448 rtlpriv->cfg->ops->get_hw_reg(hw,
451 if (rfstate == ERFOFF) {
452 *((bool *)(val)) = true;
454 val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
455 val_rcr &= 0x00070000;
457 *((bool *)(val)) = false;
459 *((bool *)(val)) = true;
462 case HW_VAR_FW_PSMODE_STATUS:
463 *((bool *)(val)) = ppsc->fw_current_inpsmode;
465 case HW_VAR_CORRECT_TSF:{
467 u32 *ptsf_low = (u32 *)&tsf;
468 u32 *ptsf_high = ((u32 *)&tsf) + 1;
470 *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
471 *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
473 *((u64 *)(val)) = tsf;
477 if (ppsc->wo_wlan_mode)
478 *((bool *)(val)) = true;
480 *((bool *)(val)) = false;
483 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
484 "switch case %#x not processed\n", variable);
489 void rtl8821ae_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
491 struct rtl_priv *rtlpriv = rtl_priv(hw);
492 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
493 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
494 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
495 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
496 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
500 case HW_VAR_ETHER_ADDR:{
501 for (idx = 0; idx < ETH_ALEN; idx++) {
502 rtl_write_byte(rtlpriv, (REG_MACID + idx),
507 case HW_VAR_BASIC_RATE:{
508 u16 b_rate_cfg = ((u16 *)val)[0];
509 b_rate_cfg = b_rate_cfg & 0x15f;
510 rtl_write_word(rtlpriv, REG_RRSR, b_rate_cfg);
514 for (idx = 0; idx < ETH_ALEN; idx++) {
515 rtl_write_byte(rtlpriv, (REG_BSSID + idx),
521 rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
522 rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[0]);
524 rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
525 rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
527 rtl_write_byte(rtlpriv, REG_RESP_SIFS_OFDM + 1, val[0]);
528 rtl_write_byte(rtlpriv, REG_RESP_SIFS_OFDM, val[0]);
530 case HW_VAR_R2T_SIFS:
531 rtl_write_byte(rtlpriv, REG_RESP_SIFS_OFDM + 1, val[0]);
533 case HW_VAR_SLOT_TIME:{
536 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
537 "HW_VAR_SLOT_TIME %x\n", val[0]);
539 rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
541 for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
542 rtlpriv->cfg->ops->set_hw_reg(hw,
547 case HW_VAR_ACK_PREAMBLE:{
549 u8 short_preamble = (bool)(*(u8 *)val);
551 reg_tmp = rtl_read_byte(rtlpriv, REG_TRXPTCL_CTL+2);
552 if (short_preamble) {
554 rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL + 2,
557 reg_tmp &= (~BIT(1));
558 rtl_write_byte(rtlpriv,
563 case HW_VAR_WPA_CONFIG:
564 rtl_write_byte(rtlpriv, REG_SECCFG, *((u8 *)val));
566 case HW_VAR_AMPDU_MIN_SPACE:{
567 u8 min_spacing_to_set;
570 min_spacing_to_set = *((u8 *)val);
571 if (min_spacing_to_set <= 7) {
574 if (min_spacing_to_set < sec_min_space)
575 min_spacing_to_set = sec_min_space;
577 mac->min_space_cfg = ((mac->min_space_cfg &
581 *val = min_spacing_to_set;
583 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
584 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
587 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
591 case HW_VAR_SHORTGI_DENSITY:{
594 density_to_set = *((u8 *)val);
595 mac->min_space_cfg |= (density_to_set << 3);
597 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
598 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
601 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
605 case HW_VAR_AMPDU_FACTOR:{
606 u32 ampdu_len = (*((u8 *)val));
608 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
609 if (ampdu_len < VHT_AGG_SIZE_128K)
611 (0x2000 << (*((u8 *)val))) - 1;
614 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
615 if (ampdu_len < HT_AGG_SIZE_64K)
617 (0x2000 << (*((u8 *)val))) - 1;
621 ampdu_len |= BIT(31);
623 rtl_write_dword(rtlpriv,
624 REG_AMPDU_MAX_LENGTH_8812, ampdu_len);
626 case HW_VAR_AC_PARAM:{
627 u8 e_aci = *((u8 *)val);
629 rtl8821ae_dm_init_edca_turbo(hw);
630 if (rtlpci->acm_method != EACMWAY2_SW)
631 rtlpriv->cfg->ops->set_hw_reg(hw,
635 case HW_VAR_ACM_CTRL:{
636 u8 e_aci = *((u8 *)val);
637 union aci_aifsn *p_aci_aifsn =
638 (union aci_aifsn *)(&mac->ac[0].aifs);
639 u8 acm = p_aci_aifsn->f.acm;
640 u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
643 acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
648 acm_ctrl |= ACMHW_BEQEN;
651 acm_ctrl |= ACMHW_VIQEN;
654 acm_ctrl |= ACMHW_VOQEN;
657 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
658 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
665 acm_ctrl &= (~ACMHW_BEQEN);
668 acm_ctrl &= (~ACMHW_VIQEN);
671 acm_ctrl &= (~ACMHW_VOQEN);
674 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
675 "switch case %#x not processed\n",
681 RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
682 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
684 rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
687 rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]);
688 rtlpci->receive_config = ((u32 *)(val))[0];
690 case HW_VAR_RETRY_LIMIT:{
691 u8 retry_limit = ((u8 *)(val))[0];
693 rtl_write_word(rtlpriv, REG_RL,
694 retry_limit << RETRY_LIMIT_SHORT_SHIFT |
695 retry_limit << RETRY_LIMIT_LONG_SHIFT);
697 case HW_VAR_DUAL_TSF_RST:
698 rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
700 case HW_VAR_EFUSE_BYTES:
701 rtlefuse->efuse_usedbytes = *((u16 *)val);
703 case HW_VAR_EFUSE_USAGE:
704 rtlefuse->efuse_usedpercentage = *((u8 *)val);
707 rtl8821ae_phy_set_io_cmd(hw, (*(enum io_type *)val));
709 case HW_VAR_SET_RPWM:{
712 rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
715 if (rpwm_val & BIT(7)) {
716 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
719 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
720 ((*(u8 *)val) | BIT(7)));
724 case HW_VAR_H2C_FW_PWRMODE:
725 rtl8821ae_set_fw_pwrmode_cmd(hw, (*(u8 *)val));
727 case HW_VAR_FW_PSMODE_STATUS:
728 ppsc->fw_current_inpsmode = *((bool *)val);
730 case HW_VAR_INIT_RTS_RATE:
732 case HW_VAR_RESUME_CLK_ON:
733 _rtl8821ae_set_fw_ps_rf_on(hw);
735 case HW_VAR_FW_LPS_ACTION:{
736 bool b_enter_fwlps = *((bool *)val);
739 _rtl8821ae_fwlps_enter(hw);
741 _rtl8821ae_fwlps_leave(hw);
743 case HW_VAR_H2C_FW_JOINBSSRPT:{
744 u8 mstatus = (*(u8 *)val);
746 if (mstatus == RT_MEDIA_CONNECT) {
747 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
749 _rtl8821ae_download_rsvd_page(hw, false);
751 rtl8821ae_set_fw_media_status_rpt_cmd(hw, mstatus);
754 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
755 rtl8821ae_set_p2p_ps_offload_cmd(hw, (*(u8 *)val));
759 u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
761 rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
764 case HW_VAR_CORRECT_TSF:{
765 u8 btype_ibss = ((u8 *)(val))[0];
768 _rtl8821ae_stop_tx_beacon(hw);
770 _rtl8821ae_set_bcn_ctrl_reg(hw, 0, BIT(3));
772 rtl_write_dword(rtlpriv, REG_TSFTR,
773 (u32)(mac->tsf & 0xffffffff));
774 rtl_write_dword(rtlpriv, REG_TSFTR + 4,
775 (u32)((mac->tsf >> 32) & 0xffffffff));
777 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(3), 0);
780 _rtl8821ae_resume_tx_beacon(hw);
782 case HW_VAR_NAV_UPPER: {
783 u32 us_nav_upper = *(u32 *)val;
785 if (us_nav_upper > HAL_92C_NAV_UPPER_UNIT * 0xFF) {
786 RT_TRACE(rtlpriv, COMP_INIT , DBG_WARNING,
787 "The setting value (0x%08X us) of NAV_UPPER is larger than (%d * 0xFF)!!!\n",
788 us_nav_upper, HAL_92C_NAV_UPPER_UNIT);
791 rtl_write_byte(rtlpriv, REG_NAV_UPPER,
792 ((u8)((us_nav_upper +
793 HAL_92C_NAV_UPPER_UNIT - 1) /
794 HAL_92C_NAV_UPPER_UNIT)));
796 case HW_VAR_KEEP_ALIVE: {
799 array[1] = *((u8 *)val);
800 rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_KEEP_ALIVE_CTRL, 2,
804 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
805 "switch case %#x not processed\n", variable);
810 static bool _rtl8821ae_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
812 struct rtl_priv *rtlpriv = rtl_priv(hw);
815 u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) |
816 _LLT_OP(_LLT_WRITE_ACCESS);
818 rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
821 value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
822 if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
825 if (count > POLLING_LLT_THRESHOLD) {
826 pr_err("Failed to polling write LLT done at address %d!\n",
836 static bool _rtl8821ae_llt_table_init(struct ieee80211_hw *hw)
838 struct rtl_priv *rtlpriv = rtl_priv(hw);
846 txpktbuf_bndy = 0xF7;
849 rtl_write_byte(rtlpriv, REG_TRXFF_BNDY, txpktbuf_bndy);
850 rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, MAX_RX_DMA_BUFFER_SIZE - 1);
852 rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
854 rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
855 rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
857 rtl_write_byte(rtlpriv, REG_PBP, 0x31);
858 rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
860 for (i = 0; i < (txpktbuf_bndy - 1); i++) {
861 status = _rtl8821ae_llt_write(hw, i, i + 1);
866 status = _rtl8821ae_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
870 for (i = txpktbuf_bndy; i < maxpage; i++) {
871 status = _rtl8821ae_llt_write(hw, i, (i + 1));
876 status = _rtl8821ae_llt_write(hw, maxpage, txpktbuf_bndy);
880 rtl_write_dword(rtlpriv, REG_RQPN, rqpn);
882 rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x00);
887 static void _rtl8821ae_gen_refresh_led_state(struct ieee80211_hw *hw)
889 struct rtl_priv *rtlpriv = rtl_priv(hw);
890 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
891 struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
892 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
894 if (rtlpriv->rtlhal.up_first_time)
897 if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
898 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
899 rtl8812ae_sw_led_on(hw, pled0);
901 rtl8821ae_sw_led_on(hw, pled0);
902 else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
903 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
904 rtl8812ae_sw_led_on(hw, pled0);
906 rtl8821ae_sw_led_on(hw, pled0);
908 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
909 rtl8812ae_sw_led_off(hw, pled0);
911 rtl8821ae_sw_led_off(hw, pled0);
914 static bool _rtl8821ae_init_mac(struct ieee80211_hw *hw)
916 struct rtl_priv *rtlpriv = rtl_priv(hw);
917 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
918 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
922 bool mac_func_enable = rtlhal->mac_func_enable;
924 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
926 /*Auto Power Down to CHIP-off State*/
927 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) & (~BIT(7));
928 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
930 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
931 /* HW Power on sequence*/
932 if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK,
933 PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK,
934 RTL8812_NIC_ENABLE_FLOW)) {
935 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
936 "init 8812 MAC Fail as power on failure\n");
940 /* HW Power on sequence */
941 if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_A_MSK,
942 PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK,
943 RTL8821A_NIC_ENABLE_FLOW)){
944 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
945 "init 8821 MAC Fail as power on failure\n");
950 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO) | BIT(4);
951 rtl_write_byte(rtlpriv, REG_APS_FSMCO, bytetmp);
953 bytetmp = rtl_read_byte(rtlpriv, REG_CR);
955 rtl_write_byte(rtlpriv, REG_CR, bytetmp);
959 rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, bytetmp);
962 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
963 bytetmp = rtl_read_byte(rtlpriv, REG_SYS_CFG + 3);
964 if (bytetmp & BIT(0)) {
965 bytetmp = rtl_read_byte(rtlpriv, 0x7c);
967 rtl_write_byte(rtlpriv, 0x7c, bytetmp);
971 bytetmp = rtl_read_byte(rtlpriv, REG_GPIO_MUXCFG + 1);
973 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG + 1, bytetmp);
975 rtl_write_word(rtlpriv, REG_CR, 0x2ff);
977 if (!mac_func_enable) {
978 if (!_rtl8821ae_llt_table_init(hw))
982 rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
983 rtl_write_dword(rtlpriv, REG_HISRE, 0xffffffff);
985 /* Enable FW Beamformer Interrupt */
986 bytetmp = rtl_read_byte(rtlpriv, REG_FWIMR + 3);
987 rtl_write_byte(rtlpriv, REG_FWIMR + 3, bytetmp | BIT(6));
989 wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
992 rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
994 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
995 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
996 rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xFFFF);
998 rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
999 rtlpci->tx_ring[BEACON_QUEUE].dma & DMA_BIT_MASK(32));
1000 rtl_write_dword(rtlpriv, REG_MGQ_DESA,
1001 rtlpci->tx_ring[MGNT_QUEUE].dma & DMA_BIT_MASK(32));
1002 rtl_write_dword(rtlpriv, REG_VOQ_DESA,
1003 rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
1004 rtl_write_dword(rtlpriv, REG_VIQ_DESA,
1005 rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
1006 rtl_write_dword(rtlpriv, REG_BEQ_DESA,
1007 rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
1008 rtl_write_dword(rtlpriv, REG_BKQ_DESA,
1009 rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
1010 rtl_write_dword(rtlpriv, REG_HQ_DESA,
1011 rtlpci->tx_ring[HIGH_QUEUE].dma & DMA_BIT_MASK(32));
1012 rtl_write_dword(rtlpriv, REG_RX_DESA,
1013 rtlpci->rx_ring[RX_MPDU_QUEUE].dma & DMA_BIT_MASK(32));
1015 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x77);
1017 rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
1019 rtl_write_dword(rtlpriv, REG_MCUTST_1, 0);
1021 rtl_write_byte(rtlpriv, REG_SECONDARY_CCA_CTRL, 0x3);
1022 _rtl8821ae_gen_refresh_led_state(hw);
1027 static void _rtl8821ae_hw_configure(struct ieee80211_hw *hw)
1029 struct rtl_priv *rtlpriv = rtl_priv(hw);
1030 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1033 reg_rrsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
1035 rtl_write_dword(rtlpriv, REG_RRSR, reg_rrsr);
1036 /* ARFB table 9 for 11ac 5G 2SS */
1037 rtl_write_dword(rtlpriv, REG_ARFR0 + 4, 0xfffff000);
1038 /* ARFB table 10 for 11ac 5G 1SS */
1039 rtl_write_dword(rtlpriv, REG_ARFR1 + 4, 0x003ff000);
1040 /* ARFB table 11 for 11ac 24G 1SS */
1041 rtl_write_dword(rtlpriv, REG_ARFR2, 0x00000015);
1042 rtl_write_dword(rtlpriv, REG_ARFR2 + 4, 0x003ff000);
1043 /* ARFB table 12 for 11ac 24G 1SS */
1044 rtl_write_dword(rtlpriv, REG_ARFR3, 0x00000015);
1045 rtl_write_dword(rtlpriv, REG_ARFR3 + 4, 0xffcff000);
1046 /* 0x420[7] = 0 , enable retry AMPDU in new AMPD not singal MPDU. */
1047 rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F00);
1048 rtl_write_byte(rtlpriv, REG_AMPDU_MAX_TIME, 0x70);
1051 rtl_write_word(rtlpriv, REG_RL, 0x0707);
1053 /* Set Data / Response auto rate fallack retry count*/
1054 rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
1055 rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
1056 rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
1057 rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
1059 rtlpci->reg_bcn_ctrl_val = 0x1d;
1060 rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
1062 /* TBTT prohibit hold time. Suggested by designer TimChen. */
1063 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
1065 /* AGGR_BK_TIME Reg51A 0x16 */
1066 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0040);
1068 /*For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
1069 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
1071 rtl_write_byte(rtlpriv, REG_HT_SINGLE_AMPDU, 0x80);
1072 rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x20);
1073 rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, 0x1F1F);
1076 static u16 _rtl8821ae_mdio_read(struct rtl_priv *rtlpriv, u8 addr)
1079 u8 tmp = 0, count = 0;
1081 rtl_write_byte(rtlpriv, REG_MDIO_CTL, addr | BIT(6));
1082 tmp = rtl_read_byte(rtlpriv, REG_MDIO_CTL) & BIT(6);
1084 while (tmp && count < 20) {
1086 tmp = rtl_read_byte(rtlpriv, REG_MDIO_CTL) & BIT(6);
1090 ret = rtl_read_word(rtlpriv, REG_MDIO_RDATA);
1095 static void _rtl8821ae_mdio_write(struct rtl_priv *rtlpriv, u8 addr, u16 data)
1097 u8 tmp = 0, count = 0;
1099 rtl_write_word(rtlpriv, REG_MDIO_WDATA, data);
1100 rtl_write_byte(rtlpriv, REG_MDIO_CTL, addr | BIT(5));
1101 tmp = rtl_read_byte(rtlpriv, REG_MDIO_CTL) & BIT(5);
1103 while (tmp && count < 20) {
1105 tmp = rtl_read_byte(rtlpriv, REG_MDIO_CTL) & BIT(5);
1110 static u8 _rtl8821ae_dbi_read(struct rtl_priv *rtlpriv, u16 addr)
1112 u16 read_addr = addr & 0xfffc;
1113 u8 tmp = 0, count = 0, ret = 0;
1115 rtl_write_word(rtlpriv, REG_DBI_ADDR, read_addr);
1116 rtl_write_byte(rtlpriv, REG_DBI_FLAG, 0x2);
1117 tmp = rtl_read_byte(rtlpriv, REG_DBI_FLAG);
1119 while (tmp && count < 20) {
1121 tmp = rtl_read_byte(rtlpriv, REG_DBI_FLAG);
1125 read_addr = REG_DBI_RDATA + addr % 4;
1126 ret = rtl_read_byte(rtlpriv, read_addr);
1131 static void _rtl8821ae_dbi_write(struct rtl_priv *rtlpriv, u16 addr, u8 data)
1133 u8 tmp = 0, count = 0;
1134 u16 write_addr, remainder = addr % 4;
1136 write_addr = REG_DBI_WDATA + remainder;
1137 rtl_write_byte(rtlpriv, write_addr, data);
1139 write_addr = (addr & 0xfffc) | (BIT(0) << (remainder + 12));
1140 rtl_write_word(rtlpriv, REG_DBI_ADDR, write_addr);
1142 rtl_write_byte(rtlpriv, REG_DBI_FLAG, 0x1);
1144 tmp = rtl_read_byte(rtlpriv, REG_DBI_FLAG);
1146 while (tmp && count < 20) {
1148 tmp = rtl_read_byte(rtlpriv, REG_DBI_FLAG);
1153 static void _rtl8821ae_enable_aspm_back_door(struct ieee80211_hw *hw)
1155 struct rtl_priv *rtlpriv = rtl_priv(hw);
1156 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1159 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1160 if (_rtl8821ae_mdio_read(rtlpriv, 0x04) != 0x8544)
1161 _rtl8821ae_mdio_write(rtlpriv, 0x04, 0x8544);
1163 if (_rtl8821ae_mdio_read(rtlpriv, 0x0b) != 0x0070)
1164 _rtl8821ae_mdio_write(rtlpriv, 0x0b, 0x0070);
1167 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x70f);
1168 _rtl8821ae_dbi_write(rtlpriv, 0x70f, tmp | BIT(7) |
1169 ASPM_L1_LATENCY << 3);
1171 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x719);
1172 _rtl8821ae_dbi_write(rtlpriv, 0x719, tmp | BIT(3) | BIT(4));
1174 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
1175 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x718);
1176 _rtl8821ae_dbi_write(rtlpriv, 0x718, tmp|BIT(4));
1180 void rtl8821ae_enable_hw_security_config(struct ieee80211_hw *hw)
1182 struct rtl_priv *rtlpriv = rtl_priv(hw);
1186 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1187 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1188 rtlpriv->sec.pairwise_enc_algorithm,
1189 rtlpriv->sec.group_enc_algorithm);
1191 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
1192 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1193 "not open hw encryption\n");
1197 sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
1199 if (rtlpriv->sec.use_defaultkey) {
1200 sec_reg_value |= SCR_TXUSEDK;
1201 sec_reg_value |= SCR_RXUSEDK;
1204 sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
1206 tmp = rtl_read_byte(rtlpriv, REG_CR + 1);
1207 rtl_write_byte(rtlpriv, REG_CR + 1, tmp | BIT(1));
1209 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1210 "The SECR-value %x\n", sec_reg_value);
1212 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
1215 /* Static MacID Mapping (cf. Used in MacIdDoStaticMapping) ---------- */
1216 #define MAC_ID_STATIC_FOR_DEFAULT_PORT 0
1217 #define MAC_ID_STATIC_FOR_BROADCAST_MULTICAST 1
1218 #define MAC_ID_STATIC_FOR_BT_CLIENT_START 2
1219 #define MAC_ID_STATIC_FOR_BT_CLIENT_END 3
1220 /* ----------------------------------------------------------- */
1222 static void rtl8821ae_macid_initialize_mediastatus(struct ieee80211_hw *hw)
1224 struct rtl_priv *rtlpriv = rtl_priv(hw);
1225 u8 media_rpt[4] = {RT_MEDIA_CONNECT, 1,
1226 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST,
1227 MAC_ID_STATIC_FOR_BT_CLIENT_END};
1229 rtlpriv->cfg->ops->set_hw_reg(hw,
1230 HW_VAR_H2C_FW_MEDIASTATUSRPT, media_rpt);
1232 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1233 "Initialize MacId media status: from %d to %d\n",
1234 MAC_ID_STATIC_FOR_BROADCAST_MULTICAST,
1235 MAC_ID_STATIC_FOR_BT_CLIENT_END);
1238 static bool _rtl8821ae_check_pcie_dma_hang(struct ieee80211_hw *hw)
1240 struct rtl_priv *rtlpriv = rtl_priv(hw);
1243 /* write reg 0x350 Bit[26]=1. Enable debug port. */
1244 tmp = rtl_read_byte(rtlpriv, REG_DBI_CTRL + 3);
1245 if (!(tmp & BIT(2))) {
1246 rtl_write_byte(rtlpriv, REG_DBI_CTRL + 3, (tmp | BIT(2)));
1250 /* read reg 0x350 Bit[25] if 1 : RX hang */
1251 /* read reg 0x350 Bit[24] if 1 : TX hang */
1252 tmp = rtl_read_byte(rtlpriv, REG_DBI_CTRL + 3);
1253 if ((tmp & BIT(0)) || (tmp & BIT(1))) {
1254 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1255 "CheckPcieDMAHang8821AE(): true! Reset PCIE DMA!\n");
1262 static bool _rtl8821ae_reset_pcie_interface_dma(struct ieee80211_hw *hw,
1266 struct rtl_priv *rtlpriv = rtl_priv(hw);
1267 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1269 bool release_mac_rx_pause;
1270 u8 backup_pcie_dma_pause;
1272 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "\n");
1274 /* 1. Disable register write lock. 0x1c[1] = 0 */
1275 tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL);
1277 rtl_write_byte(rtlpriv, REG_RSV_CTRL, tmp);
1278 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1279 /* write 0xCC bit[2] = 1'b1 */
1280 tmp = rtl_read_byte(rtlpriv, REG_PMC_DBG_CTRL2);
1282 rtl_write_byte(rtlpriv, REG_PMC_DBG_CTRL2, tmp);
1285 /* 2. Check and pause TRX DMA */
1286 /* write 0x284 bit[18] = 1'b1 */
1287 /* write 0x301 = 0xFF */
1288 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
1290 /* Already pause before the function for another purpose. */
1291 release_mac_rx_pause = false;
1293 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, (tmp | BIT(2)));
1294 release_mac_rx_pause = true;
1296 backup_pcie_dma_pause = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG + 1);
1297 if (backup_pcie_dma_pause != 0xFF)
1298 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xFF);
1301 /* 3. reset TRX function */
1302 /* write 0x100 = 0x00 */
1303 rtl_write_byte(rtlpriv, REG_CR, 0);
1306 /* 4. Reset PCIe DMA. 0x3[0] = 0 */
1307 tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
1309 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmp);
1311 /* 5. Enable PCIe DMA. 0x3[0] = 1 */
1312 tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
1314 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmp);
1317 /* 6. enable TRX function */
1318 /* write 0x100 = 0xFF */
1319 rtl_write_byte(rtlpriv, REG_CR, 0xFF);
1321 /* We should init LLT & RQPN and
1322 * prepare Tx/Rx descrptor address later
1323 * because MAC function is reset.*/
1326 /* 7. Restore PCIe autoload down bit */
1327 /* 8812AE does not has the defination. */
1328 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1329 /* write 0xF8 bit[17] = 1'b1 */
1330 tmp = rtl_read_byte(rtlpriv, REG_MAC_PHY_CTRL_NORMAL + 2);
1332 rtl_write_byte(rtlpriv, REG_MAC_PHY_CTRL_NORMAL + 2, tmp);
1335 /* In MAC power on state, BB and RF maybe in ON state,
1336 * if we release TRx DMA here.
1337 * it will cause packets to be started to Tx/Rx,
1338 * so we release Tx/Rx DMA later.*/
1339 if (!mac_power_on/* || in_watchdog*/) {
1340 /* 8. release TRX DMA */
1341 /* write 0x284 bit[18] = 1'b0 */
1342 /* write 0x301 = 0x00 */
1343 if (release_mac_rx_pause) {
1344 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
1345 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL,
1348 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1,
1349 backup_pcie_dma_pause);
1352 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1353 /* 9. lock system register */
1354 /* write 0xCC bit[2] = 1'b0 */
1355 tmp = rtl_read_byte(rtlpriv, REG_PMC_DBG_CTRL2);
1357 rtl_write_byte(rtlpriv, REG_PMC_DBG_CTRL2, tmp);
1362 static void _rtl8821ae_get_wakeup_reason(struct ieee80211_hw *hw)
1364 struct rtl_priv *rtlpriv = rtl_priv(hw);
1365 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1366 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1369 fw_reason = rtl_read_byte(rtlpriv, REG_MCUTST_WOWLAN);
1371 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "WOL Read 0x1c7 = %02X\n",
1374 ppsc->wakeup_reason = 0;
1376 rtlhal->last_suspend_sec = ktime_get_real_seconds();
1378 switch (fw_reason) {
1379 case FW_WOW_V2_PTK_UPDATE_EVENT:
1380 ppsc->wakeup_reason = WOL_REASON_PTK_UPDATE;
1381 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1382 "It's a WOL PTK Key update event!\n");
1384 case FW_WOW_V2_GTK_UPDATE_EVENT:
1385 ppsc->wakeup_reason = WOL_REASON_GTK_UPDATE;
1386 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1387 "It's a WOL GTK Key update event!\n");
1389 case FW_WOW_V2_DISASSOC_EVENT:
1390 ppsc->wakeup_reason = WOL_REASON_DISASSOC;
1391 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1392 "It's a disassociation event!\n");
1394 case FW_WOW_V2_DEAUTH_EVENT:
1395 ppsc->wakeup_reason = WOL_REASON_DEAUTH;
1396 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1397 "It's a deauth event!\n");
1399 case FW_WOW_V2_FW_DISCONNECT_EVENT:
1400 ppsc->wakeup_reason = WOL_REASON_AP_LOST;
1401 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1402 "It's a Fw disconnect decision (AP lost) event!\n");
1404 case FW_WOW_V2_MAGIC_PKT_EVENT:
1405 ppsc->wakeup_reason = WOL_REASON_MAGIC_PKT;
1406 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1407 "It's a magic packet event!\n");
1409 case FW_WOW_V2_UNICAST_PKT_EVENT:
1410 ppsc->wakeup_reason = WOL_REASON_UNICAST_PKT;
1411 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1412 "It's an unicast packet event!\n");
1414 case FW_WOW_V2_PATTERN_PKT_EVENT:
1415 ppsc->wakeup_reason = WOL_REASON_PATTERN_PKT;
1416 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1417 "It's a pattern match event!\n");
1419 case FW_WOW_V2_RTD3_SSID_MATCH_EVENT:
1420 ppsc->wakeup_reason = WOL_REASON_RTD3_SSID_MATCH;
1421 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1422 "It's an RTD3 Ssid match event!\n");
1424 case FW_WOW_V2_REALWOW_V2_WAKEUPPKT:
1425 ppsc->wakeup_reason = WOL_REASON_REALWOW_V2_WAKEUPPKT;
1426 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1427 "It's an RealWoW wake packet event!\n");
1429 case FW_WOW_V2_REALWOW_V2_ACKLOST:
1430 ppsc->wakeup_reason = WOL_REASON_REALWOW_V2_ACKLOST;
1431 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1432 "It's an RealWoW ack lost event!\n");
1435 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
1436 "WOL Read 0x1c7 = %02X, Unknown reason!\n",
1442 static void _rtl8821ae_init_trx_desc_hw_address(struct ieee80211_hw *hw)
1444 struct rtl_priv *rtlpriv = rtl_priv(hw);
1445 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1448 rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
1449 rtlpci->tx_ring[BEACON_QUEUE].dma & DMA_BIT_MASK(32));
1450 rtl_write_dword(rtlpriv, REG_MGQ_DESA,
1451 rtlpci->tx_ring[MGNT_QUEUE].dma & DMA_BIT_MASK(32));
1452 rtl_write_dword(rtlpriv, REG_VOQ_DESA,
1453 rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
1454 rtl_write_dword(rtlpriv, REG_VIQ_DESA,
1455 rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
1456 rtl_write_dword(rtlpriv, REG_BEQ_DESA,
1457 rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
1458 rtl_write_dword(rtlpriv, REG_BKQ_DESA,
1459 rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
1460 rtl_write_dword(rtlpriv, REG_HQ_DESA,
1461 rtlpci->tx_ring[HIGH_QUEUE].dma & DMA_BIT_MASK(32));
1462 rtl_write_dword(rtlpriv, REG_RX_DESA,
1463 rtlpci->rx_ring[RX_MPDU_QUEUE].dma & DMA_BIT_MASK(32));
1466 static bool _rtl8821ae_init_llt_table(struct ieee80211_hw *hw, u32 boundary)
1470 u32 txpktbuf_bndy = boundary;
1471 u32 last_entry_of_txpktbuf = LAST_ENTRY_OF_TX_PKT_BUFFER;
1473 for (i = 0 ; i < (txpktbuf_bndy - 1) ; i++) {
1474 status = _rtl8821ae_llt_write(hw, i , i + 1);
1479 status = _rtl8821ae_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
1483 for (i = txpktbuf_bndy ; i < last_entry_of_txpktbuf ; i++) {
1484 status = _rtl8821ae_llt_write(hw, i, (i + 1));
1489 status = _rtl8821ae_llt_write(hw, last_entry_of_txpktbuf,
1497 static bool _rtl8821ae_dynamic_rqpn(struct ieee80211_hw *hw, u32 boundary,
1498 u16 npq_rqpn_value, u32 rqpn_val)
1500 struct rtl_priv *rtlpriv = rtl_priv(hw);
1503 u16 count = 0, tmp16;
1504 bool support_remote_wakeup;
1506 rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
1507 (u8 *)(&support_remote_wakeup));
1509 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1510 "boundary=%#X, NPQ_RQPNValue=%#X, RQPNValue=%#X\n",
1511 boundary, npq_rqpn_value, rqpn_val);
1514 * 1. 0x301[7:0] = 0xFE */
1515 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xFE);
1518 * 2. polling till 0x41A[15:0]=0x07FF */
1519 tmp16 = rtl_read_word(rtlpriv, REG_TXPKT_EMPTY);
1520 while ((tmp16 & 0x07FF) != 0x07FF) {
1522 tmp16 = rtl_read_word(rtlpriv, REG_TXPKT_EMPTY);
1524 if ((count % 200) == 0) {
1525 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1526 "Tx queue is not empty for 20ms!\n");
1528 if (count >= 1000) {
1529 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1530 "Wait for Tx FIFO empty timeout!\n");
1536 * 3. reg 0x522=0xFF */
1537 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
1539 /* Wait TX State Machine OK
1540 * 4. polling till reg 0x5FB~0x5F8 = 0x00000000 for 50ms */
1542 while (rtl_read_byte(rtlpriv, REG_SCH_TXCMD) != 0) {
1546 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1547 "Wait for TX State Machine ready timeout !!\n");
1554 * 6. wait till 0x284[17] == 1
1555 * wait RX DMA idle */
1557 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
1558 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, (tmp | BIT(2)));
1560 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
1563 } while (!(tmp & BIT(1)) && count < 100);
1565 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1566 "Wait until Rx DMA Idle. count=%d REG[0x286]=0x%x\n",
1570 * 7. 0x02 [0] = 0 */
1571 tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN);
1573 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, tmp);
1578 rtl_write_byte(rtlpriv, REG_CR, 0x00);
1581 /* Disable MAC Security Engine
1582 * 9. 0x100 bit[9]=0 */
1583 tmp = rtl_read_byte(rtlpriv, REG_CR + 1);
1585 rtl_write_byte(rtlpriv, REG_CR + 1, tmp);
1587 /* To avoid DD-Tim Circuit hang
1588 * 10. 0x553 bit[5]=1 */
1589 tmp = rtl_read_byte(rtlpriv, REG_DUAL_TSF_RST);
1590 rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (tmp | BIT(5)));
1592 /* Enable MAC Security Engine
1593 * 11. 0x100 bit[9]=1 */
1594 tmp = rtl_read_byte(rtlpriv, REG_CR + 1);
1595 rtl_write_byte(rtlpriv, REG_CR + 1, (tmp | BIT(1)));
1600 rtl_write_byte(rtlpriv, REG_CR, 0xFF);
1604 * 13. 0x02 [0] = 1 */
1605 tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN);
1606 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, (tmp | BIT(0)));
1609 * 14,15. set beacon head page (reg 0x209 and 0x424) */
1610 rtl_write_byte(rtlpriv, REG_TDECTRL + 1, (u8)boundary);
1611 rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, (u8)boundary);
1612 rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, (u8)boundary);
1614 /* 16. WMAC_LBK_BF_HD 0x45D[7:0]
1616 rtl_write_byte(rtlpriv, REG_TXPKTBUF_WMAC_LBK_BF_HD,
1619 rtl_write_word(rtlpriv, REG_TRXFF_BNDY, boundary);
1623 if (!_rtl8821ae_init_llt_table(hw, boundary)) {
1624 RT_TRACE(rtlpriv, COMP_INIT, DBG_WARNING,
1625 "Failed to init LLT table!\n");
1630 * 18. reallocate RQPN and init LLT */
1631 rtl_write_word(rtlpriv, REG_RQPN_NPQ, npq_rqpn_value);
1632 rtl_write_dword(rtlpriv, REG_RQPN, rqpn_val);
1636 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
1639 * 20. 0x301[7:0] = 0x00
1640 * 21. 0x284[18] = 0 */
1641 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0x00);
1642 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
1643 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, (tmp&~BIT(2)));
1645 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "End.\n");
1649 static void _rtl8821ae_simple_initialize_adapter(struct ieee80211_hw *hw)
1651 struct rtl_priv *rtlpriv = rtl_priv(hw);
1652 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1653 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1655 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
1656 /* Re-download normal Fw. */
1657 rtl8821ae_set_fw_related_for_wowlan(hw, false);
1660 /* Re-Initialize LLT table. */
1661 if (rtlhal->re_init_llt_table) {
1662 u32 rqpn = 0x80e70808;
1663 u8 rqpn_npq = 0, boundary = 0xF8;
1664 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
1668 if (_rtl8821ae_dynamic_rqpn(hw, boundary, rqpn_npq, rqpn))
1669 rtlhal->re_init_llt_table = false;
1672 ppsc->rfpwr_state = ERFON;
1675 static void _rtl8821ae_enable_l1off(struct ieee80211_hw *hw)
1678 struct rtl_priv *rtlpriv = rtl_priv(hw);
1680 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "--->\n");
1682 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x160);
1683 if (!(tmp & (BIT(2) | BIT(3)))) {
1684 RT_TRACE(rtlpriv, COMP_POWER | COMP_INIT, DBG_LOUD,
1685 "0x160(%#x)return!!\n", tmp);
1689 tmp = _rtl8821ae_mdio_read(rtlpriv, 0x1b);
1690 _rtl8821ae_mdio_write(rtlpriv, 0x1b, (tmp | BIT(4)));
1692 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x718);
1693 _rtl8821ae_dbi_write(rtlpriv, 0x718, tmp | BIT(5));
1695 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "<---\n");
1698 static void _rtl8821ae_enable_ltr(struct ieee80211_hw *hw)
1701 struct rtl_priv *rtlpriv = rtl_priv(hw);
1703 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "--->\n");
1705 /* Check 0x98[10] */
1706 tmp = _rtl8821ae_dbi_read(rtlpriv, 0x99);
1707 if (!(tmp & BIT(2))) {
1708 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1709 "<---0x99(%#x) return!!\n", tmp);
1713 /* LTR idle latency, 0x90 for 144us */
1714 rtl_write_dword(rtlpriv, 0x798, 0x88908890);
1716 /* LTR active latency, 0x3c for 60us */
1717 rtl_write_dword(rtlpriv, 0x79c, 0x883c883c);
1719 tmp = rtl_read_byte(rtlpriv, 0x7a4);
1720 rtl_write_byte(rtlpriv, 0x7a4, (tmp | BIT(4)));
1722 tmp = rtl_read_byte(rtlpriv, 0x7a4);
1723 rtl_write_byte(rtlpriv, 0x7a4, (tmp & (~BIT(0))));
1724 rtl_write_byte(rtlpriv, 0x7a4, (tmp | BIT(0)));
1726 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "<---\n");
1729 static bool _rtl8821ae_wowlan_initialize_adapter(struct ieee80211_hw *hw)
1731 struct rtl_priv *rtlpriv = rtl_priv(hw);
1732 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1733 bool init_finished = true;
1736 /* Get Fw wake up reason. */
1737 _rtl8821ae_get_wakeup_reason(hw);
1739 /* Patch Pcie Rx DMA hang after S3/S4 several times.
1740 * The root cause has not be found. */
1741 if (_rtl8821ae_check_pcie_dma_hang(hw))
1742 _rtl8821ae_reset_pcie_interface_dma(hw, true, false);
1744 /* Prepare Tx/Rx Desc Hw address. */
1745 _rtl8821ae_init_trx_desc_hw_address(hw);
1747 /* Release Pcie Interface Rx DMA to allow wake packet DMA. */
1748 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xFE);
1749 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "Enable PCIE Rx DMA.\n");
1751 /* Check wake up event.
1752 * We should check wake packet bit before disable wowlan by H2C or
1753 * Fw will clear the bit. */
1754 tmp = rtl_read_byte(rtlpriv, REG_FTISR + 3);
1755 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1756 "Read REG_FTISR 0x13f = %#X\n", tmp);
1758 /* Set the WoWLAN related function control disable. */
1759 rtl8821ae_set_fw_wowlan_mode(hw, false);
1760 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw, 0);
1762 if (rtlhal->hw_rof_enable) {
1763 tmp = rtl_read_byte(rtlpriv, REG_HSISR + 3);
1765 /* Clear GPIO9 ISR */
1766 rtl_write_byte(rtlpriv, REG_HSISR + 3, tmp | BIT(1));
1767 init_finished = false;
1769 init_finished = true;
1773 if (init_finished) {
1774 _rtl8821ae_simple_initialize_adapter(hw);
1776 /* Release Pcie Interface Tx DMA. */
1777 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0x00);
1778 /* Release Pcie RX DMA */
1779 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, 0x02);
1781 tmp = rtl_read_byte(rtlpriv, REG_CR + 1);
1782 rtl_write_byte(rtlpriv, REG_CR + 1, (tmp & (~BIT(0))));
1784 _rtl8821ae_enable_l1off(hw);
1785 _rtl8821ae_enable_ltr(hw);
1788 return init_finished;
1791 static void _rtl8812ae_bb8812_config_1t(struct ieee80211_hw *hw)
1793 /* BB OFDM RX Path_A */
1794 rtl_set_bbreg(hw, 0x808, 0xff, 0x11);
1795 /* BB OFDM TX Path_A */
1796 rtl_set_bbreg(hw, 0x80c, MASKLWORD, 0x1111);
1797 /* BB CCK R/Rx Path_A */
1798 rtl_set_bbreg(hw, 0xa04, 0x0c000000, 0x0);
1800 rtl_set_bbreg(hw, 0x8bc, 0xc0000060, 0x4);
1801 /* RF Path_B HSSI OFF */
1802 rtl_set_bbreg(hw, 0xe00, 0xf, 0x4);
1803 /* RF Path_B Power Down */
1804 rtl_set_bbreg(hw, 0xe90, MASKDWORD, 0);
1805 /* ADDA Path_B OFF */
1806 rtl_set_bbreg(hw, 0xe60, MASKDWORD, 0);
1807 rtl_set_bbreg(hw, 0xe64, MASKDWORD, 0);
1810 static void _rtl8821ae_poweroff_adapter(struct ieee80211_hw *hw)
1812 struct rtl_priv *rtlpriv = rtl_priv(hw);
1813 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1816 rtlhal->mac_func_enable = false;
1818 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1819 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1820 /* 1. Run LPS WL RFOFF flow */
1821 /* RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1822 "=====>CardDisableRTL8812E,RTL8821A_NIC_LPS_ENTER_FLOW\n");
1824 rtl_hal_pwrseqcmdparsing(rtlpriv,
1825 PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
1826 PWR_INTF_PCI_MSK, RTL8821A_NIC_LPS_ENTER_FLOW);
1828 /* 2. 0x1F[7:0] = 0 */
1830 /* rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); */
1831 if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) &&
1833 rtl8821ae_firmware_selfreset(hw);
1836 /* Reset MCU. Suggested by Filen. */
1837 u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
1838 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1b_tmp & (~BIT(2))));
1840 /* g. MCUFWDL 0x80[1:0]=0 */
1841 /* reset MCU ready status */
1842 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1844 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
1845 /* HW card disable configuration. */
1846 rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
1847 PWR_INTF_PCI_MSK, RTL8821A_NIC_DISABLE_FLOW);
1849 /* HW card disable configuration. */
1850 rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
1851 PWR_INTF_PCI_MSK, RTL8812_NIC_DISABLE_FLOW);
1854 /* Reset MCU IO Wrapper */
1855 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
1856 rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0))));
1857 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
1858 rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, u1b_tmp | BIT(0));
1860 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1861 /* lock ISO/CLK/Power control register */
1862 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1865 int rtl8821ae_hw_init(struct ieee80211_hw *hw)
1867 struct rtl_priv *rtlpriv = rtl_priv(hw);
1868 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1869 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1870 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1871 bool rtstatus = true;
1874 bool support_remote_wakeup;
1875 u32 nav_upper = WIFI_NAV_UPPER_US;
1877 rtlhal->being_init_adapter = true;
1878 rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
1879 (u8 *)(&support_remote_wakeup));
1880 rtlpriv->intf_ops->disable_aspm(hw);
1882 /*YP wowlan not considered*/
1884 tmp_u1b = rtl_read_byte(rtlpriv, REG_CR);
1885 if (tmp_u1b != 0 && tmp_u1b != 0xEA) {
1886 rtlhal->mac_func_enable = true;
1887 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1888 "MAC has already power on.\n");
1890 rtlhal->mac_func_enable = false;
1891 rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_8821AE;
1894 if (support_remote_wakeup &&
1895 rtlhal->wake_from_pnp_sleep &&
1896 rtlhal->mac_func_enable) {
1897 if (_rtl8821ae_wowlan_initialize_adapter(hw)) {
1898 rtlhal->being_init_adapter = false;
1903 if (_rtl8821ae_check_pcie_dma_hang(hw)) {
1904 _rtl8821ae_reset_pcie_interface_dma(hw,
1905 rtlhal->mac_func_enable,
1907 rtlhal->mac_func_enable = false;
1910 /* Reset MAC/BB/RF status if it is not powered off
1911 * before calling initialize Hw flow to prevent
1912 * from interface and MAC status mismatch.
1913 * 2013.06.21, by tynli. Suggested by SD1 JackieLau. */
1914 if (rtlhal->mac_func_enable) {
1915 _rtl8821ae_poweroff_adapter(hw);
1916 rtlhal->mac_func_enable = false;
1919 rtstatus = _rtl8821ae_init_mac(hw);
1920 if (rtstatus != true) {
1921 pr_err("Init MAC failed\n");
1926 tmp_u1b = rtl_read_byte(rtlpriv, REG_SYS_CFG);
1928 rtl_write_byte(rtlpriv, REG_SYS_CFG, tmp_u1b);
1930 err = rtl8821ae_download_fw(hw, false);
1932 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1933 "Failed to download FW. Init HW without FW now\n");
1935 rtlhal->fw_ready = false;
1938 rtlhal->fw_ready = true;
1940 ppsc->fw_current_inpsmode = false;
1941 rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_8821AE;
1942 rtlhal->fw_clk_change_in_progress = false;
1943 rtlhal->allow_sw_to_change_hwclc = false;
1944 rtlhal->last_hmeboxnum = 0;
1946 /*SIC_Init(Adapter);
1947 if(rtlhal->AMPDUBurstMode)
1948 rtl_write_byte(rtlpriv,REG_AMPDU_BURST_MODE_8812, 0x7F);*/
1950 rtl8821ae_phy_mac_config(hw);
1951 /* because last function modify RCR, so we update
1952 * rcr var here, or TP will unstable for receive_config
1953 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
1954 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
1955 rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
1956 rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
1957 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);*/
1958 rtl8821ae_phy_bb_config(hw);
1960 rtl8821ae_phy_rf_config(hw);
1962 if (rtlpriv->phy.rf_type == RF_1T1R &&
1963 rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
1964 _rtl8812ae_bb8812_config_1t(hw);
1966 _rtl8821ae_hw_configure(hw);
1968 rtl8821ae_phy_switch_wirelessband(hw, BAND_ON_2_4G);
1970 /*set wireless mode*/
1972 rtlhal->mac_func_enable = true;
1974 rtl_cam_reset_all_entry(hw);
1976 rtl8821ae_enable_hw_security_config(hw);
1978 ppsc->rfpwr_state = ERFON;
1980 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
1981 _rtl8821ae_enable_aspm_back_door(hw);
1982 rtlpriv->intf_ops->enable_aspm(hw);
1984 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE &&
1985 (rtlhal->rfe_type == 1 || rtlhal->rfe_type == 5))
1986 rtl_set_bbreg(hw, 0x900, 0x00000303, 0x0302);
1988 rtl8821ae_bt_hw_init(hw);
1989 rtlpriv->rtlhal.being_init_adapter = false;
1991 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_NAV_UPPER, (u8 *)&nav_upper);
1993 /* rtl8821ae_dm_check_txpower_tracking(hw); */
1994 /* rtl8821ae_phy_lc_calibrate(hw); */
1995 if (support_remote_wakeup)
1996 rtl_write_byte(rtlpriv, REG_WOW_CTRL, 0);
1999 tmp_u1b = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
2000 if (tmp_u1b & BIT(2)) {
2001 /* Release Rx DMA if needed*/
2003 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, tmp_u1b);
2006 /* Release Tx/Rx PCIE DMA if*/
2007 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0);
2009 rtl8821ae_dm_init(hw);
2010 rtl8821ae_macid_initialize_mediastatus(hw);
2012 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "rtl8821ae_hw_init() <====\n");
2016 static enum version_8821ae _rtl8821ae_read_chip_version(struct ieee80211_hw *hw)
2018 struct rtl_priv *rtlpriv = rtl_priv(hw);
2019 struct rtl_phy *rtlphy = &rtlpriv->phy;
2020 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2021 enum version_8821ae version = VERSION_UNKNOWN;
2024 value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
2025 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2026 "ReadChipVersion8812A 0xF0 = 0x%x\n", value32);
2028 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
2029 rtlphy->rf_type = RF_2T2R;
2030 else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE)
2031 rtlphy->rf_type = RF_1T1R;
2033 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2034 "RF_Type is %x!!\n", rtlphy->rf_type);
2036 if (value32 & TRP_VAUX_EN) {
2037 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
2038 if (rtlphy->rf_type == RF_2T2R)
2039 version = VERSION_TEST_CHIP_2T2R_8812;
2041 version = VERSION_TEST_CHIP_1T1R_8812;
2043 version = VERSION_TEST_CHIP_8821;
2045 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
2046 u32 rtl_id = ((value32 & CHIP_VER_RTL_MASK) >> 12) + 1;
2048 if (rtlphy->rf_type == RF_2T2R)
2050 (enum version_8821ae)(CHIP_8812
2054 version = (enum version_8821ae)(CHIP_8812
2057 version = (enum version_8821ae)(version | (rtl_id << 12));
2058 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
2059 u32 rtl_id = value32 & CHIP_VER_RTL_MASK;
2061 version = (enum version_8821ae)(CHIP_8821
2062 | NORMAL_CHIP | rtl_id);
2066 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
2068 value32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
2069 rtlhal->hw_rof_enable = ((value32 & WL_HWROF_EN) ? 1 : 0);
2073 case VERSION_TEST_CHIP_1T1R_8812:
2074 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2075 "Chip Version ID: VERSION_TEST_CHIP_1T1R_8812\n");
2077 case VERSION_TEST_CHIP_2T2R_8812:
2078 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2079 "Chip Version ID: VERSION_TEST_CHIP_2T2R_8812\n");
2081 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812:
2082 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2083 "Chip Version ID:VERSION_NORMAL_TSMC_CHIP_1T1R_8812\n");
2085 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812:
2086 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2087 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812\n");
2089 case VERSION_NORMAL_TSMC_CHIP_1T1R_8812_C_CUT:
2090 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2091 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_1T1R_8812 C CUT\n");
2093 case VERSION_NORMAL_TSMC_CHIP_2T2R_8812_C_CUT:
2094 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2095 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_2T2R_8812 C CUT\n");
2097 case VERSION_TEST_CHIP_8821:
2098 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2099 "Chip Version ID: VERSION_TEST_CHIP_8821\n");
2101 case VERSION_NORMAL_TSMC_CHIP_8821:
2102 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2103 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 A CUT\n");
2105 case VERSION_NORMAL_TSMC_CHIP_8821_B_CUT:
2106 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2107 "Chip Version ID: VERSION_NORMAL_TSMC_CHIP_8821 B CUT\n");
2110 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2111 "Chip Version ID: Unknown (0x%X)\n", version);
2118 static int _rtl8821ae_set_media_status(struct ieee80211_hw *hw,
2119 enum nl80211_iftype type)
2121 struct rtl_priv *rtlpriv = rtl_priv(hw);
2122 u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
2123 enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
2126 rtl_write_dword(rtlpriv, REG_BCN_CTRL, 0);
2127 RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD,
2128 "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
2130 if (type == NL80211_IFTYPE_UNSPECIFIED ||
2131 type == NL80211_IFTYPE_STATION) {
2132 _rtl8821ae_stop_tx_beacon(hw);
2133 _rtl8821ae_enable_bcn_sub_func(hw);
2134 } else if (type == NL80211_IFTYPE_ADHOC ||
2135 type == NL80211_IFTYPE_AP) {
2136 _rtl8821ae_resume_tx_beacon(hw);
2137 _rtl8821ae_disable_bcn_sub_func(hw);
2139 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
2140 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
2145 case NL80211_IFTYPE_UNSPECIFIED:
2146 bt_msr |= MSR_NOLINK;
2147 ledaction = LED_CTL_LINK;
2148 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
2149 "Set Network type to NO LINK!\n");
2151 case NL80211_IFTYPE_ADHOC:
2152 bt_msr |= MSR_ADHOC;
2153 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
2154 "Set Network type to Ad Hoc!\n");
2156 case NL80211_IFTYPE_STATION:
2157 bt_msr |= MSR_INFRA;
2158 ledaction = LED_CTL_LINK;
2159 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
2160 "Set Network type to STA!\n");
2162 case NL80211_IFTYPE_AP:
2164 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
2165 "Set Network type to AP!\n");
2168 pr_err("Network type %d not support!\n", type);
2172 rtl_write_byte(rtlpriv, MSR, bt_msr);
2173 rtlpriv->cfg->ops->led_control(hw, ledaction);
2174 if ((bt_msr & MSR_MASK) == MSR_AP)
2175 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
2177 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
2182 void rtl8821ae_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
2184 struct rtl_priv *rtlpriv = rtl_priv(hw);
2185 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2186 u32 reg_rcr = rtlpci->receive_config;
2188 if (rtlpriv->psc.rfpwr_state != ERFON)
2192 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
2193 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
2195 _rtl8821ae_set_bcn_ctrl_reg(hw, 0, BIT(4));
2196 } else if (!check_bssid) {
2197 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
2198 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(4), 0);
2199 rtlpriv->cfg->ops->set_hw_reg(hw,
2200 HW_VAR_RCR, (u8 *)(®_rcr));
2204 int rtl8821ae_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
2206 struct rtl_priv *rtlpriv = rtl_priv(hw);
2208 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "rtl8821ae_set_network_type!\n");
2210 if (_rtl8821ae_set_media_status(hw, type))
2213 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
2214 if (type != NL80211_IFTYPE_AP)
2215 rtl8821ae_set_check_bssid(hw, true);
2217 rtl8821ae_set_check_bssid(hw, false);
2223 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
2224 void rtl8821ae_set_qos(struct ieee80211_hw *hw, int aci)
2226 struct rtl_priv *rtlpriv = rtl_priv(hw);
2227 rtl8821ae_dm_init_edca_turbo(hw);
2230 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
2233 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
2236 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
2239 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
2242 WARN_ONCE(true, "rtl8821ae: invalid aci: %d !\n", aci);
2247 static void rtl8821ae_clear_interrupt(struct ieee80211_hw *hw)
2249 struct rtl_priv *rtlpriv = rtl_priv(hw);
2250 u32 tmp = rtl_read_dword(rtlpriv, REG_HISR);
2252 rtl_write_dword(rtlpriv, REG_HISR, tmp);
2254 tmp = rtl_read_dword(rtlpriv, REG_HISRE);
2255 rtl_write_dword(rtlpriv, REG_HISRE, tmp);
2257 tmp = rtl_read_dword(rtlpriv, REG_HSISR);
2258 rtl_write_dword(rtlpriv, REG_HSISR, tmp);
2261 void rtl8821ae_enable_interrupt(struct ieee80211_hw *hw)
2263 struct rtl_priv *rtlpriv = rtl_priv(hw);
2264 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2266 if (rtlpci->int_clear)
2267 rtl8821ae_clear_interrupt(hw);/*clear it here first*/
2269 rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
2270 rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
2271 rtlpci->irq_enabled = true;
2272 /* there are some C2H CMDs have been sent before
2273 system interrupt is enabled, e.g., C2H, CPWM.
2274 *So we need to clear all C2H events that FW has
2275 notified, otherwise FW won't schedule any commands anymore.
2277 /* rtl_write_byte(rtlpriv, REG_C2HEVT_CLEAR, 0); */
2278 /*enable system interrupt*/
2279 rtl_write_dword(rtlpriv, REG_HSIMR, rtlpci->sys_irq_mask & 0xFFFFFFFF);
2282 void rtl8821ae_disable_interrupt(struct ieee80211_hw *hw)
2284 struct rtl_priv *rtlpriv = rtl_priv(hw);
2285 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2287 rtl_write_dword(rtlpriv, REG_HIMR, IMR_DISABLED);
2288 rtl_write_dword(rtlpriv, REG_HIMRE, IMR_DISABLED);
2289 rtlpci->irq_enabled = false;
2290 /*synchronize_irq(rtlpci->pdev->irq);*/
2293 static void _rtl8821ae_clear_pci_pme_status(struct ieee80211_hw *hw)
2295 struct rtl_priv *rtlpriv = rtl_priv(hw);
2296 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2303 /* Get the Capability pointer first,
2304 * the Capability Pointer is located at
2305 * offset 0x34 from the Function Header */
2307 pci_read_config_byte(rtlpci->pdev, 0x34, &cap_pointer);
2308 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2309 "PCI configuration 0x34 = 0x%2x\n", cap_pointer);
2312 pci_read_config_word(rtlpci->pdev, cap_pointer, &cap_hdr);
2313 cap_id = cap_hdr & 0xFF;
2315 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2316 "in pci configuration, cap_pointer%x = %x\n",
2317 cap_pointer, cap_id);
2319 if (cap_id == 0x01) {
2322 /* point to next Capability */
2323 cap_pointer = (cap_hdr >> 8) & 0xFF;
2324 /* 0: end of pci capability, 0xff: invalid value */
2325 if (cap_pointer == 0x00 || cap_pointer == 0xff) {
2330 } while (cnt++ < 200);
2332 if (cap_id == 0x01) {
2333 /* Get the PM CSR (Control/Status Register),
2334 * The PME_Status is located at PM Capatibility offset 5, bit 7
2336 pci_read_config_byte(rtlpci->pdev, cap_pointer + 5, &pmcs_reg);
2338 if (pmcs_reg & BIT(7)) {
2339 /* PME event occured, clear the PM_Status by write 1 */
2340 pmcs_reg = pmcs_reg | BIT(7);
2342 pci_write_config_byte(rtlpci->pdev, cap_pointer + 5,
2344 /* Read it back to check */
2345 pci_read_config_byte(rtlpci->pdev, cap_pointer + 5,
2347 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2348 "Clear PME status 0x%2x to 0x%2x\n",
2349 cap_pointer + 5, pmcs_reg);
2351 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2352 "PME status(0x%2x) = 0x%2x\n",
2353 cap_pointer + 5, pmcs_reg);
2356 RT_TRACE(rtlpriv, COMP_INIT, DBG_WARNING,
2357 "Cannot find PME Capability\n");
2361 void rtl8821ae_card_disable(struct ieee80211_hw *hw)
2363 struct rtl_priv *rtlpriv = rtl_priv(hw);
2364 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
2365 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
2366 struct rtl_mac *mac = rtl_mac(rtlpriv);
2367 enum nl80211_iftype opmode;
2368 bool support_remote_wakeup;
2372 rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
2373 (u8 *)(&support_remote_wakeup));
2375 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2377 if (!(support_remote_wakeup && mac->opmode == NL80211_IFTYPE_STATION)
2378 || !rtlhal->enter_pnp_sleep) {
2379 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Normal Power off\n");
2380 mac->link_state = MAC80211_NOLINK;
2381 opmode = NL80211_IFTYPE_UNSPECIFIED;
2382 _rtl8821ae_set_media_status(hw, opmode);
2383 _rtl8821ae_poweroff_adapter(hw);
2385 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Wowlan Supported.\n");
2386 /* 3 <1> Prepare for configuring wowlan related infomations */
2387 /* Clear Fw WoWLAN event. */
2388 rtl_write_byte(rtlpriv, REG_MCUTST_WOWLAN, 0x0);
2390 #if (USE_SPECIFIC_FW_TO_SUPPORT_WOWLAN == 1)
2391 rtl8821ae_set_fw_related_for_wowlan(hw, true);
2393 /* Dynamically adjust Tx packet boundary
2394 * for download reserved page packet.
2395 * reserve 30 pages for rsvd page */
2396 if (_rtl8821ae_dynamic_rqpn(hw, 0xE0, 0x3, 0x80c20d0d))
2397 rtlhal->re_init_llt_table = true;
2399 /* 3 <2> Set Fw releted H2C cmd. */
2401 /* Set WoWLAN related security information. */
2402 rtl8821ae_set_fw_global_info_cmd(hw);
2404 _rtl8821ae_download_rsvd_page(hw, true);
2406 /* Just enable AOAC related functions when we connect to AP. */
2407 printk("mac->link_state = %d\n", mac->link_state);
2408 if (mac->link_state >= MAC80211_LINKED &&
2409 mac->opmode == NL80211_IFTYPE_STATION) {
2410 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID, NULL);
2411 rtl8821ae_set_fw_media_status_rpt_cmd(hw,
2414 rtl8821ae_set_fw_wowlan_mode(hw, true);
2415 /* Enable Fw Keep alive mechanism. */
2416 rtl8821ae_set_fw_keep_alive_cmd(hw, true);
2418 /* Enable disconnect decision control. */
2419 rtl8821ae_set_fw_disconnect_decision_ctrl_cmd(hw, true);
2422 /* 3 <3> Hw Configutations */
2424 /* Wait untill Rx DMA Finished before host sleep.
2425 * FW Pause Rx DMA may happens when received packet doing dma.
2427 rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, BIT(2));
2429 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
2431 while (!(tmp & BIT(1)) && (count++ < 100)) {
2433 tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
2435 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2436 "Wait Rx DMA Finished before host sleep. count=%d\n",
2439 /* reset trx ring */
2440 rtlpriv->intf_ops->reset_trx_ring(hw);
2442 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x0);
2444 _rtl8821ae_clear_pci_pme_status(hw);
2445 tmp = rtl_read_byte(rtlpriv, REG_SYS_CLKR);
2446 rtl_write_byte(rtlpriv, REG_SYS_CLKR, tmp | BIT(3));
2447 /* prevent 8051 to be reset by PERST */
2448 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x20);
2449 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x60);
2452 if (rtlpriv->rtlhal.driver_is_goingto_unload ||
2453 ppsc->rfoff_reason > RF_CHANGE_BY_PS)
2454 rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
2455 /* For wowlan+LPS+32k. */
2456 if (support_remote_wakeup && rtlhal->enter_pnp_sleep) {
2457 /* Set the WoWLAN related function control enable.
2458 * It should be the last H2C cmd in the WoWLAN flow. */
2459 rtl8821ae_set_fw_remote_wake_ctrl_cmd(hw, 1);
2461 /* Stop Pcie Interface Tx DMA. */
2462 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xff);
2463 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "Stop PCIE Tx DMA.\n");
2465 /* Wait for TxDMA idle. */
2468 tmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG);
2471 } while ((tmp != 0) && (count < 100));
2472 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2473 "Wait Tx DMA Finished before host sleep. count=%d\n",
2476 if (rtlhal->hw_rof_enable) {
2477 printk("hw_rof_enable\n");
2478 tmp = rtl_read_byte(rtlpriv, REG_HSISR + 3);
2479 rtl_write_byte(rtlpriv, REG_HSISR + 3, tmp | BIT(1));
2482 /* after power off we should do iqk again */
2483 rtlpriv->phy.iqk_initialized = false;
2486 void rtl8821ae_interrupt_recognized(struct ieee80211_hw *hw,
2487 struct rtl_int *intvec)
2489 struct rtl_priv *rtlpriv = rtl_priv(hw);
2490 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2492 intvec->inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
2493 rtl_write_dword(rtlpriv, ISR, intvec->inta);
2495 intvec->intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
2496 rtl_write_dword(rtlpriv, REG_HISRE, intvec->intb);
2499 void rtl8821ae_set_beacon_related_registers(struct ieee80211_hw *hw)
2501 struct rtl_priv *rtlpriv = rtl_priv(hw);
2502 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2503 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2504 u16 bcn_interval, atim_window;
2506 bcn_interval = mac->beacon_interval;
2507 atim_window = 2; /*FIX MERGE */
2508 rtl8821ae_disable_interrupt(hw);
2509 rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
2510 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
2511 rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
2512 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
2513 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
2514 rtl_write_byte(rtlpriv, 0x606, 0x30);
2515 rtlpci->reg_bcn_ctrl_val |= BIT(3);
2516 rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlpci->reg_bcn_ctrl_val);
2517 rtl8821ae_enable_interrupt(hw);
2520 void rtl8821ae_set_beacon_interval(struct ieee80211_hw *hw)
2522 struct rtl_priv *rtlpriv = rtl_priv(hw);
2523 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2524 u16 bcn_interval = mac->beacon_interval;
2526 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
2527 "beacon_interval:%d\n", bcn_interval);
2528 rtl8821ae_disable_interrupt(hw);
2529 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
2530 rtl8821ae_enable_interrupt(hw);
2533 void rtl8821ae_update_interrupt_mask(struct ieee80211_hw *hw,
2534 u32 add_msr, u32 rm_msr)
2536 struct rtl_priv *rtlpriv = rtl_priv(hw);
2537 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2539 RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
2540 "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr);
2543 rtlpci->irq_mask[0] |= add_msr;
2545 rtlpci->irq_mask[0] &= (~rm_msr);
2546 rtl8821ae_disable_interrupt(hw);
2547 rtl8821ae_enable_interrupt(hw);
2550 static u8 _rtl8821ae_get_chnl_group(u8 chnl)
2555 if (1 <= chnl && chnl <= 2)
2557 else if (3 <= chnl && chnl <= 5)
2559 else if (6 <= chnl && chnl <= 8)
2561 else if (9 <= chnl && chnl <= 11)
2563 else /*if (12 <= chnl && chnl <= 14)*/
2566 if (36 <= chnl && chnl <= 42)
2568 else if (44 <= chnl && chnl <= 48)
2570 else if (50 <= chnl && chnl <= 58)
2572 else if (60 <= chnl && chnl <= 64)
2574 else if (100 <= chnl && chnl <= 106)
2576 else if (108 <= chnl && chnl <= 114)
2578 else if (116 <= chnl && chnl <= 122)
2580 else if (124 <= chnl && chnl <= 130)
2582 else if (132 <= chnl && chnl <= 138)
2584 else if (140 <= chnl && chnl <= 144)
2586 else if (149 <= chnl && chnl <= 155)
2588 else if (157 <= chnl && chnl <= 161)
2590 else if (165 <= chnl && chnl <= 171)
2592 else if (173 <= chnl && chnl <= 177)
2596 "rtl8821ae: 5G, Channel %d in Group not found\n",
2602 static void _rtl8821ae_read_power_value_fromprom(struct ieee80211_hw *hw,
2603 struct txpower_info_2g *pwrinfo24g,
2604 struct txpower_info_5g *pwrinfo5g,
2608 struct rtl_priv *rtlpriv = rtl_priv(hw);
2609 u32 rfPath, eeAddr = EEPROM_TX_PWR_INX, group, TxCount = 0;
2611 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2612 "hal_ReadPowerValueFromPROM8821ae(): hwinfo[0x%x]=0x%x\n",
2613 (eeAddr+1), hwinfo[eeAddr+1]);
2614 if (0xFF == hwinfo[eeAddr+1]) /*YJ,add,120316*/
2615 autoload_fail = true;
2617 if (autoload_fail) {
2618 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
2619 "auto load fail : Use Default value!\n");
2620 for (rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++) {
2621 /*2.4G default value*/
2622 for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
2623 pwrinfo24g->index_cck_base[rfPath][group] = 0x2D;
2624 pwrinfo24g->index_bw40_base[rfPath][group] = 0x2D;
2626 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
2628 pwrinfo24g->bw20_diff[rfPath][0] = 0x02;
2629 pwrinfo24g->ofdm_diff[rfPath][0] = 0x04;
2631 pwrinfo24g->bw20_diff[rfPath][TxCount] = 0xFE;
2632 pwrinfo24g->bw40_diff[rfPath][TxCount] = 0xFE;
2633 pwrinfo24g->cck_diff[rfPath][TxCount] = 0xFE;
2634 pwrinfo24g->ofdm_diff[rfPath][TxCount] = 0xFE;
2637 /*5G default value*/
2638 for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++)
2639 pwrinfo5g->index_bw40_base[rfPath][group] = 0x2A;
2641 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
2643 pwrinfo5g->ofdm_diff[rfPath][0] = 0x04;
2644 pwrinfo5g->bw20_diff[rfPath][0] = 0x00;
2645 pwrinfo5g->bw80_diff[rfPath][0] = 0xFE;
2646 pwrinfo5g->bw160_diff[rfPath][0] = 0xFE;
2648 pwrinfo5g->ofdm_diff[rfPath][0] = 0xFE;
2649 pwrinfo5g->bw20_diff[rfPath][0] = 0xFE;
2650 pwrinfo5g->bw40_diff[rfPath][0] = 0xFE;
2651 pwrinfo5g->bw80_diff[rfPath][0] = 0xFE;
2652 pwrinfo5g->bw160_diff[rfPath][0] = 0xFE;
2659 rtl_priv(hw)->efuse.txpwr_fromeprom = true;
2661 for (rfPath = 0 ; rfPath < MAX_RF_PATH ; rfPath++) {
2662 /*2.4G default value*/
2663 for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
2664 pwrinfo24g->index_cck_base[rfPath][group] = hwinfo[eeAddr++];
2665 if (pwrinfo24g->index_cck_base[rfPath][group] == 0xFF)
2666 pwrinfo24g->index_cck_base[rfPath][group] = 0x2D;
2668 for (group = 0 ; group < MAX_CHNL_GROUP_24G - 1; group++) {
2669 pwrinfo24g->index_bw40_base[rfPath][group] = hwinfo[eeAddr++];
2670 if (pwrinfo24g->index_bw40_base[rfPath][group] == 0xFF)
2671 pwrinfo24g->index_bw40_base[rfPath][group] = 0x2D;
2673 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
2675 pwrinfo24g->bw40_diff[rfPath][TxCount] = 0;
2676 /*bit sign number to 8 bit sign number*/
2677 pwrinfo24g->bw20_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0xf0) >> 4;
2678 if (pwrinfo24g->bw20_diff[rfPath][TxCount] & BIT(3))
2679 pwrinfo24g->bw20_diff[rfPath][TxCount] |= 0xF0;
2680 /*bit sign number to 8 bit sign number*/
2681 pwrinfo24g->ofdm_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0x0f);
2682 if (pwrinfo24g->ofdm_diff[rfPath][TxCount] & BIT(3))
2683 pwrinfo24g->ofdm_diff[rfPath][TxCount] |= 0xF0;
2685 pwrinfo24g->cck_diff[rfPath][TxCount] = 0;
2688 pwrinfo24g->bw40_diff[rfPath][TxCount] = (hwinfo[eeAddr]&0xf0) >> 4;
2689 if (pwrinfo24g->bw40_diff[rfPath][TxCount] & BIT(3))
2690 pwrinfo24g->bw40_diff[rfPath][TxCount] |= 0xF0;
2692 pwrinfo24g->bw20_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0x0f);
2693 if (pwrinfo24g->bw20_diff[rfPath][TxCount] & BIT(3))
2694 pwrinfo24g->bw20_diff[rfPath][TxCount] |= 0xF0;
2698 pwrinfo24g->ofdm_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0xf0) >> 4;
2699 if (pwrinfo24g->ofdm_diff[rfPath][TxCount] & BIT(3))
2700 pwrinfo24g->ofdm_diff[rfPath][TxCount] |= 0xF0;
2702 pwrinfo24g->cck_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0x0f);
2703 if (pwrinfo24g->cck_diff[rfPath][TxCount] & BIT(3))
2704 pwrinfo24g->cck_diff[rfPath][TxCount] |= 0xF0;
2710 /*5G default value*/
2711 for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++) {
2712 pwrinfo5g->index_bw40_base[rfPath][group] = hwinfo[eeAddr++];
2713 if (pwrinfo5g->index_bw40_base[rfPath][group] == 0xFF)
2714 pwrinfo5g->index_bw40_base[rfPath][group] = 0xFE;
2717 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
2719 pwrinfo5g->bw40_diff[rfPath][TxCount] = 0;
2721 pwrinfo5g->bw20_diff[rfPath][0] = (hwinfo[eeAddr] & 0xf0) >> 4;
2722 if (pwrinfo5g->bw20_diff[rfPath][TxCount] & BIT(3))
2723 pwrinfo5g->bw20_diff[rfPath][TxCount] |= 0xF0;
2725 pwrinfo5g->ofdm_diff[rfPath][0] = (hwinfo[eeAddr] & 0x0f);
2726 if (pwrinfo5g->ofdm_diff[rfPath][TxCount] & BIT(3))
2727 pwrinfo5g->ofdm_diff[rfPath][TxCount] |= 0xF0;
2731 pwrinfo5g->bw40_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0xf0) >> 4;
2732 if (pwrinfo5g->bw40_diff[rfPath][TxCount] & BIT(3))
2733 pwrinfo5g->bw40_diff[rfPath][TxCount] |= 0xF0;
2735 pwrinfo5g->bw20_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0x0f);
2736 if (pwrinfo5g->bw20_diff[rfPath][TxCount] & BIT(3))
2737 pwrinfo5g->bw20_diff[rfPath][TxCount] |= 0xF0;
2743 pwrinfo5g->ofdm_diff[rfPath][1] = (hwinfo[eeAddr] & 0xf0) >> 4;
2744 pwrinfo5g->ofdm_diff[rfPath][2] = (hwinfo[eeAddr] & 0x0f);
2748 pwrinfo5g->ofdm_diff[rfPath][3] = (hwinfo[eeAddr] & 0x0f);
2752 for (TxCount = 1; TxCount < MAX_TX_COUNT; TxCount++) {
2753 if (pwrinfo5g->ofdm_diff[rfPath][TxCount] & BIT(3))
2754 pwrinfo5g->ofdm_diff[rfPath][TxCount] |= 0xF0;
2756 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
2757 pwrinfo5g->bw80_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0xf0) >> 4;
2758 /* 4bit sign number to 8 bit sign number */
2759 if (pwrinfo5g->bw80_diff[rfPath][TxCount] & BIT(3))
2760 pwrinfo5g->bw80_diff[rfPath][TxCount] |= 0xF0;
2761 /* 4bit sign number to 8 bit sign number */
2762 pwrinfo5g->bw160_diff[rfPath][TxCount] = (hwinfo[eeAddr] & 0x0f);
2763 if (pwrinfo5g->bw160_diff[rfPath][TxCount] & BIT(3))
2764 pwrinfo5g->bw160_diff[rfPath][TxCount] |= 0xF0;
2771 static void _rtl8812ae_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
2775 struct rtl_priv *rtlpriv = rtl_priv(hw);
2776 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2777 struct txpower_info_2g pwrinfo24g;
2778 struct txpower_info_5g pwrinfo5g;
2782 _rtl8821ae_read_power_value_fromprom(hw, &pwrinfo24g,
2783 &pwrinfo5g, autoload_fail, hwinfo);
2785 for (rf_path = 0; rf_path < 2; rf_path++) {
2786 for (i = 0; i < CHANNEL_MAX_NUMBER_2G; i++) {
2787 index = _rtl8821ae_get_chnl_group(i + 1);
2789 if (i == CHANNEL_MAX_NUMBER_2G - 1) {
2790 rtlefuse->txpwrlevel_cck[rf_path][i] =
2791 pwrinfo24g.index_cck_base[rf_path][5];
2792 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
2793 pwrinfo24g.index_bw40_base[rf_path][index];
2795 rtlefuse->txpwrlevel_cck[rf_path][i] =
2796 pwrinfo24g.index_cck_base[rf_path][index];
2797 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
2798 pwrinfo24g.index_bw40_base[rf_path][index];
2802 for (i = 0; i < CHANNEL_MAX_NUMBER_5G; i++) {
2803 index = _rtl8821ae_get_chnl_group(channel5g[i]);
2804 rtlefuse->txpwr_5g_bw40base[rf_path][i] =
2805 pwrinfo5g.index_bw40_base[rf_path][index];
2807 for (i = 0; i < CHANNEL_MAX_NUMBER_5G_80M; i++) {
2809 index = _rtl8821ae_get_chnl_group(channel5g_80m[i]);
2810 upper = pwrinfo5g.index_bw40_base[rf_path][index];
2811 lower = pwrinfo5g.index_bw40_base[rf_path][index + 1];
2813 rtlefuse->txpwr_5g_bw80base[rf_path][i] = (upper + lower) / 2;
2815 for (i = 0; i < MAX_TX_COUNT; i++) {
2816 rtlefuse->txpwr_cckdiff[rf_path][i] =
2817 pwrinfo24g.cck_diff[rf_path][i];
2818 rtlefuse->txpwr_legacyhtdiff[rf_path][i] =
2819 pwrinfo24g.ofdm_diff[rf_path][i];
2820 rtlefuse->txpwr_ht20diff[rf_path][i] =
2821 pwrinfo24g.bw20_diff[rf_path][i];
2822 rtlefuse->txpwr_ht40diff[rf_path][i] =
2823 pwrinfo24g.bw40_diff[rf_path][i];
2825 rtlefuse->txpwr_5g_ofdmdiff[rf_path][i] =
2826 pwrinfo5g.ofdm_diff[rf_path][i];
2827 rtlefuse->txpwr_5g_bw20diff[rf_path][i] =
2828 pwrinfo5g.bw20_diff[rf_path][i];
2829 rtlefuse->txpwr_5g_bw40diff[rf_path][i] =
2830 pwrinfo5g.bw40_diff[rf_path][i];
2831 rtlefuse->txpwr_5g_bw80diff[rf_path][i] =
2832 pwrinfo5g.bw80_diff[rf_path][i];
2836 if (!autoload_fail) {
2837 rtlefuse->eeprom_regulatory =
2838 hwinfo[EEPROM_RF_BOARD_OPTION] & 0x07;/*bit0~2*/
2839 if (hwinfo[EEPROM_RF_BOARD_OPTION] == 0xFF)
2840 rtlefuse->eeprom_regulatory = 0;
2842 rtlefuse->eeprom_regulatory = 0;
2845 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
2846 "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
2849 static void _rtl8821ae_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
2853 struct rtl_priv *rtlpriv = rtl_priv(hw);
2854 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2855 struct txpower_info_2g pwrinfo24g;
2856 struct txpower_info_5g pwrinfo5g;
2860 _rtl8821ae_read_power_value_fromprom(hw, &pwrinfo24g,
2861 &pwrinfo5g, autoload_fail, hwinfo);
2863 for (rf_path = 0; rf_path < 2; rf_path++) {
2864 for (i = 0; i < CHANNEL_MAX_NUMBER_2G; i++) {
2865 index = _rtl8821ae_get_chnl_group(i + 1);
2867 if (i == CHANNEL_MAX_NUMBER_2G - 1) {
2868 rtlefuse->txpwrlevel_cck[rf_path][i] =
2869 pwrinfo24g.index_cck_base[rf_path][5];
2870 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
2871 pwrinfo24g.index_bw40_base[rf_path][index];
2873 rtlefuse->txpwrlevel_cck[rf_path][i] =
2874 pwrinfo24g.index_cck_base[rf_path][index];
2875 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
2876 pwrinfo24g.index_bw40_base[rf_path][index];
2880 for (i = 0; i < CHANNEL_MAX_NUMBER_5G; i++) {
2881 index = _rtl8821ae_get_chnl_group(channel5g[i]);
2882 rtlefuse->txpwr_5g_bw40base[rf_path][i] =
2883 pwrinfo5g.index_bw40_base[rf_path][index];
2885 for (i = 0; i < CHANNEL_MAX_NUMBER_5G_80M; i++) {
2887 index = _rtl8821ae_get_chnl_group(channel5g_80m[i]);
2888 upper = pwrinfo5g.index_bw40_base[rf_path][index];
2889 lower = pwrinfo5g.index_bw40_base[rf_path][index + 1];
2891 rtlefuse->txpwr_5g_bw80base[rf_path][i] = (upper + lower) / 2;
2893 for (i = 0; i < MAX_TX_COUNT; i++) {
2894 rtlefuse->txpwr_cckdiff[rf_path][i] =
2895 pwrinfo24g.cck_diff[rf_path][i];
2896 rtlefuse->txpwr_legacyhtdiff[rf_path][i] =
2897 pwrinfo24g.ofdm_diff[rf_path][i];
2898 rtlefuse->txpwr_ht20diff[rf_path][i] =
2899 pwrinfo24g.bw20_diff[rf_path][i];
2900 rtlefuse->txpwr_ht40diff[rf_path][i] =
2901 pwrinfo24g.bw40_diff[rf_path][i];
2903 rtlefuse->txpwr_5g_ofdmdiff[rf_path][i] =
2904 pwrinfo5g.ofdm_diff[rf_path][i];
2905 rtlefuse->txpwr_5g_bw20diff[rf_path][i] =
2906 pwrinfo5g.bw20_diff[rf_path][i];
2907 rtlefuse->txpwr_5g_bw40diff[rf_path][i] =
2908 pwrinfo5g.bw40_diff[rf_path][i];
2909 rtlefuse->txpwr_5g_bw80diff[rf_path][i] =
2910 pwrinfo5g.bw80_diff[rf_path][i];
2914 if (!autoload_fail) {
2915 rtlefuse->eeprom_regulatory = hwinfo[EEPROM_RF_BOARD_OPTION] & 0x07;
2916 if (hwinfo[EEPROM_RF_BOARD_OPTION] == 0xFF)
2917 rtlefuse->eeprom_regulatory = 0;
2919 rtlefuse->eeprom_regulatory = 0;
2922 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
2923 "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
2926 static void _rtl8812ae_read_pa_type(struct ieee80211_hw *hw, u8 *hwinfo,
2929 struct rtl_priv *rtlpriv = rtl_priv(hw);
2930 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
2932 if (!autoload_fail) {
2933 rtlhal->pa_type_2g = hwinfo[0xBC];
2934 rtlhal->lna_type_2g = hwinfo[0xBD];
2935 if (rtlhal->pa_type_2g == 0xFF && rtlhal->lna_type_2g == 0xFF) {
2936 rtlhal->pa_type_2g = 0;
2937 rtlhal->lna_type_2g = 0;
2939 rtlhal->external_pa_2g = ((rtlhal->pa_type_2g & BIT(5)) &&
2940 (rtlhal->pa_type_2g & BIT(4))) ?
2942 rtlhal->external_lna_2g = ((rtlhal->lna_type_2g & BIT(7)) &&
2943 (rtlhal->lna_type_2g & BIT(3))) ?
2946 rtlhal->pa_type_5g = hwinfo[0xBC];
2947 rtlhal->lna_type_5g = hwinfo[0xBF];
2948 if (rtlhal->pa_type_5g == 0xFF && rtlhal->lna_type_5g == 0xFF) {
2949 rtlhal->pa_type_5g = 0;
2950 rtlhal->lna_type_5g = 0;
2952 rtlhal->external_pa_5g = ((rtlhal->pa_type_5g & BIT(1)) &&
2953 (rtlhal->pa_type_5g & BIT(0))) ?
2955 rtlhal->external_lna_5g = ((rtlhal->lna_type_5g & BIT(7)) &&
2956 (rtlhal->lna_type_5g & BIT(3))) ?
2959 rtlhal->external_pa_2g = 0;
2960 rtlhal->external_lna_2g = 0;
2961 rtlhal->external_pa_5g = 0;
2962 rtlhal->external_lna_5g = 0;
2966 static void _rtl8812ae_read_amplifier_type(struct ieee80211_hw *hw, u8 *hwinfo,
2969 struct rtl_priv *rtlpriv = rtl_priv(hw);
2970 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
2972 u8 ext_type_pa_2g_a = (hwinfo[0xBD] & BIT(2)) >> 2; /* 0xBD[2] */
2973 u8 ext_type_pa_2g_b = (hwinfo[0xBD] & BIT(6)) >> 6; /* 0xBD[6] */
2974 u8 ext_type_pa_5g_a = (hwinfo[0xBF] & BIT(2)) >> 2; /* 0xBF[2] */
2975 u8 ext_type_pa_5g_b = (hwinfo[0xBF] & BIT(6)) >> 6; /* 0xBF[6] */
2977 u8 ext_type_lna_2g_a = (hwinfo[0xBD] & (BIT(1) | BIT(0))) >> 0;
2979 u8 ext_type_lna_2g_b = (hwinfo[0xBD] & (BIT(5) | BIT(4))) >> 4;
2981 u8 ext_type_lna_5g_a = (hwinfo[0xBF] & (BIT(1) | BIT(0))) >> 0;
2983 u8 ext_type_lna_5g_b = (hwinfo[0xBF] & (BIT(5) | BIT(4))) >> 4;
2985 _rtl8812ae_read_pa_type(hw, hwinfo, autoload_fail);
2987 /* [2.4G] Path A and B are both extPA */
2988 if ((rtlhal->pa_type_2g & (BIT(5) | BIT(4))) == (BIT(5) | BIT(4)))
2989 rtlhal->type_gpa = ext_type_pa_2g_b << 2 | ext_type_pa_2g_a;
2991 /* [5G] Path A and B are both extPA */
2992 if ((rtlhal->pa_type_5g & (BIT(1) | BIT(0))) == (BIT(1) | BIT(0)))
2993 rtlhal->type_apa = ext_type_pa_5g_b << 2 | ext_type_pa_5g_a;
2995 /* [2.4G] Path A and B are both extLNA */
2996 if ((rtlhal->lna_type_2g & (BIT(7) | BIT(3))) == (BIT(7) | BIT(3)))
2997 rtlhal->type_glna = ext_type_lna_2g_b << 2 | ext_type_lna_2g_a;
2999 /* [5G] Path A and B are both extLNA */
3000 if ((rtlhal->lna_type_5g & (BIT(7) | BIT(3))) == (BIT(7) | BIT(3)))
3001 rtlhal->type_alna = ext_type_lna_5g_b << 2 | ext_type_lna_5g_a;
3004 static void _rtl8821ae_read_pa_type(struct ieee80211_hw *hw, u8 *hwinfo,
3007 struct rtl_priv *rtlpriv = rtl_priv(hw);
3008 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
3010 if (!autoload_fail) {
3011 rtlhal->pa_type_2g = hwinfo[0xBC];
3012 rtlhal->lna_type_2g = hwinfo[0xBD];
3013 if (rtlhal->pa_type_2g == 0xFF && rtlhal->lna_type_2g == 0xFF) {
3014 rtlhal->pa_type_2g = 0;
3015 rtlhal->lna_type_2g = 0;
3017 rtlhal->external_pa_2g = (rtlhal->pa_type_2g & BIT(5)) ? 1 : 0;
3018 rtlhal->external_lna_2g = (rtlhal->lna_type_2g & BIT(7)) ? 1 : 0;
3020 rtlhal->pa_type_5g = hwinfo[0xBC];
3021 rtlhal->lna_type_5g = hwinfo[0xBF];
3022 if (rtlhal->pa_type_5g == 0xFF && rtlhal->lna_type_5g == 0xFF) {
3023 rtlhal->pa_type_5g = 0;
3024 rtlhal->lna_type_5g = 0;
3026 rtlhal->external_pa_5g = (rtlhal->pa_type_5g & BIT(1)) ? 1 : 0;
3027 rtlhal->external_lna_5g = (rtlhal->lna_type_5g & BIT(7)) ? 1 : 0;
3029 rtlhal->external_pa_2g = 0;
3030 rtlhal->external_lna_2g = 0;
3031 rtlhal->external_pa_5g = 0;
3032 rtlhal->external_lna_5g = 0;
3036 static void _rtl8821ae_read_rfe_type(struct ieee80211_hw *hw, u8 *hwinfo,
3039 struct rtl_priv *rtlpriv = rtl_priv(hw);
3040 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
3042 if (!autoload_fail) {
3043 if (hwinfo[EEPROM_RFE_OPTION] & BIT(7)) {
3044 if (rtlhal->external_lna_5g) {
3045 if (rtlhal->external_pa_5g) {
3046 if (rtlhal->external_lna_2g &&
3047 rtlhal->external_pa_2g)
3048 rtlhal->rfe_type = 3;
3050 rtlhal->rfe_type = 0;
3052 rtlhal->rfe_type = 2;
3055 rtlhal->rfe_type = 4;
3058 rtlhal->rfe_type = hwinfo[EEPROM_RFE_OPTION] & 0x3F;
3060 if (rtlhal->rfe_type == 4 &&
3061 (rtlhal->external_pa_5g ||
3062 rtlhal->external_pa_2g ||
3063 rtlhal->external_lna_5g ||
3064 rtlhal->external_lna_2g)) {
3065 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
3066 rtlhal->rfe_type = 2;
3070 rtlhal->rfe_type = 0x04;
3073 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
3074 "RFE Type: 0x%2x\n", rtlhal->rfe_type);
3077 static void _rtl8812ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
3078 bool auto_load_fail, u8 *hwinfo)
3080 struct rtl_priv *rtlpriv = rtl_priv(hw);
3083 if (!auto_load_fail) {
3084 value = *(u8 *)&hwinfo[EEPROM_RF_BOARD_OPTION];
3085 if (((value & 0xe0) >> 5) == 0x1)
3086 rtlpriv->btcoexist.btc_info.btcoexist = 1;
3088 rtlpriv->btcoexist.btc_info.btcoexist = 0;
3089 rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8812A;
3091 value = hwinfo[EEPROM_RF_BT_SETTING];
3092 rtlpriv->btcoexist.btc_info.ant_num = (value & 0x1);
3094 rtlpriv->btcoexist.btc_info.btcoexist = 0;
3095 rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8812A;
3096 rtlpriv->btcoexist.btc_info.ant_num = ANT_X2;
3098 /*move BT_InitHalVars() to init_sw_vars*/
3101 static void _rtl8821ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
3102 bool auto_load_fail, u8 *hwinfo)
3104 struct rtl_priv *rtlpriv = rtl_priv(hw);
3108 if (!auto_load_fail) {
3109 tmpu_32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
3110 if (tmpu_32 & BIT(18))
3111 rtlpriv->btcoexist.btc_info.btcoexist = 1;
3113 rtlpriv->btcoexist.btc_info.btcoexist = 0;
3114 rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8821A;
3116 value = hwinfo[EEPROM_RF_BT_SETTING];
3117 rtlpriv->btcoexist.btc_info.ant_num = (value & 0x1);
3119 rtlpriv->btcoexist.btc_info.btcoexist = 0;
3120 rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8821A;
3121 rtlpriv->btcoexist.btc_info.ant_num = ANT_X2;
3123 /*move BT_InitHalVars() to init_sw_vars*/
3126 static void _rtl8821ae_read_adapter_info(struct ieee80211_hw *hw, bool b_pseudo_test)
3128 struct rtl_priv *rtlpriv = rtl_priv(hw);
3129 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
3130 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3131 int params[] = {RTL_EEPROM_ID, EEPROM_VID, EEPROM_DID,
3132 EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR,
3133 EEPROM_CHANNELPLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID,
3134 COUNTRY_CODE_WORLD_WIDE_13};
3137 if (b_pseudo_test) {
3141 hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL);
3145 if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params))
3148 _rtl8821ae_read_txpower_info_from_hwpg(hw, rtlefuse->autoload_failflag,
3151 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
3152 _rtl8812ae_read_amplifier_type(hw, hwinfo,
3153 rtlefuse->autoload_failflag);
3154 _rtl8812ae_read_bt_coexist_info_from_hwpg(hw,
3155 rtlefuse->autoload_failflag, hwinfo);
3157 _rtl8821ae_read_pa_type(hw, hwinfo, rtlefuse->autoload_failflag);
3158 _rtl8821ae_read_bt_coexist_info_from_hwpg(hw,
3159 rtlefuse->autoload_failflag, hwinfo);
3162 _rtl8821ae_read_rfe_type(hw, hwinfo, rtlefuse->autoload_failflag);
3164 rtlefuse->board_type = ODM_BOARD_DEFAULT;
3165 if (rtlhal->external_lna_2g != 0)
3166 rtlefuse->board_type |= ODM_BOARD_EXT_LNA;
3167 if (rtlhal->external_lna_5g != 0)
3168 rtlefuse->board_type |= ODM_BOARD_EXT_LNA_5G;
3169 if (rtlhal->external_pa_2g != 0)
3170 rtlefuse->board_type |= ODM_BOARD_EXT_PA;
3171 if (rtlhal->external_pa_5g != 0)
3172 rtlefuse->board_type |= ODM_BOARD_EXT_PA_5G;
3174 if (rtlpriv->btcoexist.btc_info.btcoexist == 1)
3175 rtlefuse->board_type |= ODM_BOARD_BT;
3177 rtlhal->board_type = rtlefuse->board_type;
3178 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
3179 "board_type = 0x%x\n", rtlefuse->board_type);
3181 rtlefuse->eeprom_channelplan = *(u8 *)&hwinfo[EEPROM_CHANNELPLAN];
3182 if (rtlefuse->eeprom_channelplan == 0xff)
3183 rtlefuse->eeprom_channelplan = 0x7F;
3185 /* set channel plan from efuse */
3186 rtlefuse->channel_plan = rtlefuse->eeprom_channelplan;
3189 rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_8821AE];
3190 if (rtlefuse->crystalcap == 0xFF)
3191 rtlefuse->crystalcap = 0x20;
3193 rtlefuse->eeprom_thermalmeter = *(u8 *)&hwinfo[EEPROM_THERMAL_METER];
3194 if ((rtlefuse->eeprom_thermalmeter == 0xff) ||
3195 rtlefuse->autoload_failflag) {
3196 rtlefuse->apk_thermalmeterignore = true;
3197 rtlefuse->eeprom_thermalmeter = 0xff;
3200 rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
3201 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
3202 "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
3204 if (!rtlefuse->autoload_failflag) {
3205 rtlefuse->antenna_div_cfg =
3206 (hwinfo[EEPROM_RF_BOARD_OPTION] & 0x18) >> 3;
3207 if (hwinfo[EEPROM_RF_BOARD_OPTION] == 0xff)
3208 rtlefuse->antenna_div_cfg = 0;
3210 if (rtlpriv->btcoexist.btc_info.btcoexist == 1 &&
3211 rtlpriv->btcoexist.btc_info.ant_num == ANT_X1)
3212 rtlefuse->antenna_div_cfg = 0;
3214 rtlefuse->antenna_div_type = hwinfo[EEPROM_RF_ANTENNA_OPT_88E];
3215 if (rtlefuse->antenna_div_type == 0xff)
3216 rtlefuse->antenna_div_type = FIXED_HW_ANTDIV;
3218 rtlefuse->antenna_div_cfg = 0;
3219 rtlefuse->antenna_div_type = 0;
3222 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
3223 "SWAS: bHwAntDiv = %x, TRxAntDivType = %x\n",
3224 rtlefuse->antenna_div_cfg, rtlefuse->antenna_div_type);
3226 rtlpriv->ledctl.led_opendrain = true;
3228 if (rtlhal->oem_id == RT_CID_DEFAULT) {
3229 switch (rtlefuse->eeprom_oemid) {
3230 case RT_CID_DEFAULT:
3232 case EEPROM_CID_TOSHIBA:
3233 rtlhal->oem_id = RT_CID_TOSHIBA;
3235 case EEPROM_CID_CCX:
3236 rtlhal->oem_id = RT_CID_CCX;
3238 case EEPROM_CID_QMI:
3239 rtlhal->oem_id = RT_CID_819X_QMI;
3241 case EEPROM_CID_WHQL:
3251 /*static void _rtl8821ae_hal_customized_behavior(struct ieee80211_hw *hw)
3253 struct rtl_priv *rtlpriv = rtl_priv(hw);
3254 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
3255 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3257 rtlpriv->ledctl.led_opendrain = true;
3258 switch (rtlhal->oem_id) {
3259 case RT_CID_819X_HP:
3260 rtlpriv->ledctl.led_opendrain = true;
3262 case RT_CID_819X_LENOVO:
3263 case RT_CID_DEFAULT:
3264 case RT_CID_TOSHIBA:
3266 case RT_CID_819X_ACER:
3271 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
3272 "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
3275 void rtl8821ae_read_eeprom_info(struct ieee80211_hw *hw)
3277 struct rtl_priv *rtlpriv = rtl_priv(hw);
3278 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
3279 struct rtl_phy *rtlphy = &rtlpriv->phy;
3280 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3283 rtlhal->version = _rtl8821ae_read_chip_version(hw);
3284 if (get_rf_type(rtlphy) == RF_1T1R)
3285 rtlpriv->dm.rfpath_rxenable[0] = true;
3287 rtlpriv->dm.rfpath_rxenable[0] =
3288 rtlpriv->dm.rfpath_rxenable[1] = true;
3289 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
3292 tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
3293 if (tmp_u1b & BIT(4)) {
3294 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
3295 rtlefuse->epromtype = EEPROM_93C46;
3297 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
3298 rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
3301 if (tmp_u1b & BIT(5)) {
3302 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
3303 rtlefuse->autoload_failflag = false;
3304 _rtl8821ae_read_adapter_info(hw, false);
3306 pr_err("Autoload ERR!!\n");
3308 /*hal_ReadRFType_8812A()*/
3309 /* _rtl8821ae_hal_customized_behavior(hw); */
3312 static void rtl8821ae_update_hal_rate_table(struct ieee80211_hw *hw,
3313 struct ieee80211_sta *sta)
3315 struct rtl_priv *rtlpriv = rtl_priv(hw);
3316 struct rtl_phy *rtlphy = &rtlpriv->phy;
3317 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
3318 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
3321 u8 b_nmode = mac->ht_enable;
3322 u8 mimo_ps = IEEE80211_SMPS_OFF;
3325 u8 curtxbw_40mhz = mac->bw_40;
3326 u8 b_curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
3328 u8 b_curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
3330 enum wireless_mode wirelessmode = mac->mode;
3332 if (rtlhal->current_bandtype == BAND_ON_5G)
3333 ratr_value = sta->supp_rates[1] << 4;
3335 ratr_value = sta->supp_rates[0];
3336 if (mac->opmode == NL80211_IFTYPE_ADHOC)
3338 ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
3339 sta->ht_cap.mcs.rx_mask[0] << 12);
3340 switch (wirelessmode) {
3341 case WIRELESS_MODE_B:
3342 if (ratr_value & 0x0000000c)
3343 ratr_value &= 0x0000000d;
3345 ratr_value &= 0x0000000f;
3347 case WIRELESS_MODE_G:
3348 ratr_value &= 0x00000FF5;
3350 case WIRELESS_MODE_N_24G:
3351 case WIRELESS_MODE_N_5G:
3353 if (mimo_ps == IEEE80211_SMPS_STATIC) {
3354 ratr_value &= 0x0007F005;
3358 if (get_rf_type(rtlphy) == RF_1T2R ||
3359 get_rf_type(rtlphy) == RF_1T1R)
3360 ratr_mask = 0x000ff005;
3362 ratr_mask = 0x0f0ff005;
3364 ratr_value &= ratr_mask;
3368 if (rtlphy->rf_type == RF_1T2R)
3369 ratr_value &= 0x000ff0ff;
3371 ratr_value &= 0x0f0ff0ff;
3376 if ((rtlpriv->btcoexist.bt_coexistence) &&
3377 (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) &&
3378 (rtlpriv->btcoexist.bt_cur_state) &&
3379 (rtlpriv->btcoexist.bt_ant_isolation) &&
3380 ((rtlpriv->btcoexist.bt_service == BT_SCO) ||
3381 (rtlpriv->btcoexist.bt_service == BT_BUSY)))
3382 ratr_value &= 0x0fffcfc0;
3384 ratr_value &= 0x0FFFFFFF;
3386 if (b_nmode && ((curtxbw_40mhz &&
3387 b_curshortgi_40mhz) || (!curtxbw_40mhz &&
3388 b_curshortgi_20mhz))) {
3389 ratr_value |= 0x10000000;
3390 tmp_ratr_value = (ratr_value >> 12);
3392 for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
3393 if ((1 << shortgi_rate) & tmp_ratr_value)
3397 shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
3398 (shortgi_rate << 4) | (shortgi_rate);
3401 rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
3403 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
3404 "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0));
3407 static u32 _rtl8821ae_rate_to_bitmap_2ssvht(__le16 vht_rate)
3410 u32 rate_bitmap = 0;
3412 for (i = j = 0; i < 4; i += 2, j += 10) {
3413 tmp_rate = (le16_to_cpu(vht_rate) >> i) & 3;
3417 rate_bitmap = rate_bitmap | (0x03ff << j);
3420 rate_bitmap = rate_bitmap | (0x01ff << j);
3423 rate_bitmap = rate_bitmap | (0x00ff << j);
3433 static u32 _rtl8821ae_set_ra_vht_ratr_bitmap(struct ieee80211_hw *hw,
3434 enum wireless_mode wirelessmode,
3437 struct rtl_priv *rtlpriv = rtl_priv(hw);
3438 struct rtl_phy *rtlphy = &rtlpriv->phy;
3439 u32 ret_bitmap = ratr_bitmap;
3441 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40
3442 || rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80)
3443 ret_bitmap = ratr_bitmap;
3444 else if (wirelessmode == WIRELESS_MODE_AC_5G
3445 || wirelessmode == WIRELESS_MODE_AC_24G) {
3446 if (rtlphy->rf_type == RF_1T1R)
3447 ret_bitmap = ratr_bitmap & (~BIT21);
3449 ret_bitmap = ratr_bitmap & (~(BIT31|BIT21));
3455 static u8 _rtl8821ae_get_vht_eni(enum wireless_mode wirelessmode,
3459 if (wirelessmode < WIRELESS_MODE_N_24G)
3461 else if (wirelessmode == WIRELESS_MODE_AC_24G) {
3462 if (ratr_bitmap & 0xfff00000) /* Mix , 2SS */
3466 } else if (wirelessmode == WIRELESS_MODE_AC_5G) {
3473 static u8 _rtl8821ae_get_ra_ldpc(struct ieee80211_hw *hw,
3474 u8 mac_id, struct rtl_sta_info *sta_entry,
3475 enum wireless_mode wirelessmode)
3478 /*not support ldpc, do not open*/
3482 static u8 _rtl8821ae_get_ra_rftype(struct ieee80211_hw *hw,
3483 enum wireless_mode wirelessmode,
3486 struct rtl_priv *rtlpriv = rtl_priv(hw);
3487 struct rtl_phy *rtlphy = &rtlpriv->phy;
3488 u8 rf_type = RF_1T1R;
3490 if (rtlphy->rf_type == RF_1T1R)
3492 else if (wirelessmode == WIRELESS_MODE_AC_5G
3493 || wirelessmode == WIRELESS_MODE_AC_24G
3494 || wirelessmode == WIRELESS_MODE_AC_ONLY) {
3495 if (ratr_bitmap & 0xffc00000)
3497 } else if (wirelessmode == WIRELESS_MODE_N_5G
3498 || wirelessmode == WIRELESS_MODE_N_24G) {
3499 if (ratr_bitmap & 0xfff00000)
3506 static bool _rtl8821ae_get_ra_shortgi(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
3509 bool b_short_gi = false;
3510 u8 b_curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
3512 u8 b_curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
3514 u8 b_curshortgi_80mhz = 0;
3515 b_curshortgi_80mhz = (sta->vht_cap.cap &
3516 IEEE80211_VHT_CAP_SHORT_GI_80) ? 1 : 0;
3518 if (mac_id == MAC_ID_STATIC_FOR_BROADCAST_MULTICAST)
3521 if (b_curshortgi_40mhz || b_curshortgi_80mhz
3522 || b_curshortgi_20mhz)
3528 static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw *hw,
3529 struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
3531 struct rtl_priv *rtlpriv = rtl_priv(hw);
3532 struct rtl_phy *rtlphy = &rtlpriv->phy;
3533 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
3534 struct rtl_sta_info *sta_entry = NULL;
3537 enum wireless_mode wirelessmode = 0;
3538 u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
3540 bool b_shortgi = false;
3543 u8 mimo_ps = IEEE80211_SMPS_OFF;
3546 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
3547 wirelessmode = sta_entry->wireless_mode;
3549 RT_TRACE(rtlpriv, COMP_RATR, DBG_LOUD,
3550 "wireless mode = 0x%x\n", wirelessmode);
3551 if (mac->opmode == NL80211_IFTYPE_STATION ||
3552 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
3553 curtxbw_40mhz = mac->bw_40;
3554 } else if (mac->opmode == NL80211_IFTYPE_AP ||
3555 mac->opmode == NL80211_IFTYPE_ADHOC)
3556 macid = sta->aid + 1;
3557 if (wirelessmode == WIRELESS_MODE_N_5G ||
3558 wirelessmode == WIRELESS_MODE_AC_5G ||
3559 wirelessmode == WIRELESS_MODE_A)
3560 ratr_bitmap = sta->supp_rates[NL80211_BAND_5GHZ] << 4;
3562 ratr_bitmap = sta->supp_rates[NL80211_BAND_2GHZ];
3564 if (mac->opmode == NL80211_IFTYPE_ADHOC)
3565 ratr_bitmap = 0xfff;
3567 if (wirelessmode == WIRELESS_MODE_N_24G
3568 || wirelessmode == WIRELESS_MODE_N_5G)
3569 ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
3570 sta->ht_cap.mcs.rx_mask[0] << 12);
3571 else if (wirelessmode == WIRELESS_MODE_AC_24G
3572 || wirelessmode == WIRELESS_MODE_AC_5G
3573 || wirelessmode == WIRELESS_MODE_AC_ONLY)
3574 ratr_bitmap |= _rtl8821ae_rate_to_bitmap_2ssvht(
3575 sta->vht_cap.vht_mcs.rx_mcs_map) << 12;
3577 b_shortgi = _rtl8821ae_get_ra_shortgi(hw, sta, macid);
3578 rf_type = _rtl8821ae_get_ra_rftype(hw, wirelessmode, ratr_bitmap);
3581 switch (wirelessmode) {
3582 case WIRELESS_MODE_B:
3583 ratr_index = RATR_INX_WIRELESS_B;
3584 if (ratr_bitmap & 0x0000000c)
3585 ratr_bitmap &= 0x0000000d;
3587 ratr_bitmap &= 0x0000000f;
3589 case WIRELESS_MODE_G:
3590 ratr_index = RATR_INX_WIRELESS_GB;
3592 if (rssi_level == 1)
3593 ratr_bitmap &= 0x00000f00;
3594 else if (rssi_level == 2)
3595 ratr_bitmap &= 0x00000ff0;
3597 ratr_bitmap &= 0x00000ff5;
3599 case WIRELESS_MODE_A:
3600 ratr_index = RATR_INX_WIRELESS_G;
3601 ratr_bitmap &= 0x00000ff0;
3603 case WIRELESS_MODE_N_24G:
3604 case WIRELESS_MODE_N_5G:
3605 if (wirelessmode == WIRELESS_MODE_N_24G)
3606 ratr_index = RATR_INX_WIRELESS_NGB;
3608 ratr_index = RATR_INX_WIRELESS_NG;
3610 if (mimo_ps == IEEE80211_SMPS_STATIC
3611 || mimo_ps == IEEE80211_SMPS_DYNAMIC) {
3612 if (rssi_level == 1)
3613 ratr_bitmap &= 0x000f0000;
3614 else if (rssi_level == 2)
3615 ratr_bitmap &= 0x000ff000;
3617 ratr_bitmap &= 0x000ff005;
3619 if (rf_type == RF_1T1R) {
3620 if (curtxbw_40mhz) {
3621 if (rssi_level == 1)
3622 ratr_bitmap &= 0x000f0000;
3623 else if (rssi_level == 2)
3624 ratr_bitmap &= 0x000ff000;
3626 ratr_bitmap &= 0x000ff015;
3628 if (rssi_level == 1)
3629 ratr_bitmap &= 0x000f0000;
3630 else if (rssi_level == 2)
3631 ratr_bitmap &= 0x000ff000;
3633 ratr_bitmap &= 0x000ff005;
3636 if (curtxbw_40mhz) {
3637 if (rssi_level == 1)
3638 ratr_bitmap &= 0x0fff0000;
3639 else if (rssi_level == 2)
3640 ratr_bitmap &= 0x0ffff000;
3642 ratr_bitmap &= 0x0ffff015;
3644 if (rssi_level == 1)
3645 ratr_bitmap &= 0x0fff0000;
3646 else if (rssi_level == 2)
3647 ratr_bitmap &= 0x0ffff000;
3649 ratr_bitmap &= 0x0ffff005;
3655 case WIRELESS_MODE_AC_24G:
3656 ratr_index = RATR_INX_WIRELESS_AC_24N;
3657 if (rssi_level == 1)
3658 ratr_bitmap &= 0xfc3f0000;
3659 else if (rssi_level == 2)
3660 ratr_bitmap &= 0xfffff000;
3662 ratr_bitmap &= 0xffffffff;
3665 case WIRELESS_MODE_AC_5G:
3666 ratr_index = RATR_INX_WIRELESS_AC_5N;
3668 if (rf_type == RF_1T1R) {
3669 if (rssi_level == 1) /*add by Gary for ac-series*/
3670 ratr_bitmap &= 0x003f8000;
3671 else if (rssi_level == 2)
3672 ratr_bitmap &= 0x003ff000;
3674 ratr_bitmap &= 0x003ff010;
3676 if (rssi_level == 1)
3677 ratr_bitmap &= 0xfe3f8000;
3678 else if (rssi_level == 2)
3679 ratr_bitmap &= 0xfffff000;
3681 ratr_bitmap &= 0xfffff010;
3686 ratr_index = RATR_INX_WIRELESS_NGB;
3688 if (rf_type == RF_1T2R)
3689 ratr_bitmap &= 0x000ff0ff;
3691 ratr_bitmap &= 0x0f8ff0ff;
3695 ratr_index = rtl_mrate_idx_to_arfr_id(hw, ratr_index, wirelessmode);
3696 sta_entry->ratr_index = ratr_index;
3697 ratr_bitmap = _rtl8821ae_set_ra_vht_ratr_bitmap(hw, wirelessmode,
3700 RT_TRACE(rtlpriv, COMP_RATR, DBG_LOUD,
3701 "ratr_bitmap :%x\n", ratr_bitmap);
3703 /* *(u32 *)& rate_mask = EF4BYTE((ratr_bitmap & 0x0fffffff) |
3704 (ratr_index << 28)); */
3706 rate_mask[0] = macid;
3707 rate_mask[1] = ratr_index | (b_shortgi ? 0x80 : 0x00);
3708 rate_mask[2] = rtlphy->current_chan_bw | ((!update_bw) << 3)
3709 | _rtl8821ae_get_vht_eni(wirelessmode, ratr_bitmap)
3710 | _rtl8821ae_get_ra_ldpc(hw, macid, sta_entry, wirelessmode);
3712 rate_mask[3] = (u8)(ratr_bitmap & 0x000000ff);
3713 rate_mask[4] = (u8)((ratr_bitmap & 0x0000ff00) >> 8);
3714 rate_mask[5] = (u8)((ratr_bitmap & 0x00ff0000) >> 16);
3715 rate_mask[6] = (u8)((ratr_bitmap & 0xff000000) >> 24);
3717 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
3718 "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
3719 ratr_index, ratr_bitmap,
3720 rate_mask[0], rate_mask[1],
3721 rate_mask[2], rate_mask[3],
3722 rate_mask[4], rate_mask[5],
3724 rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_RA_MASK, 7, rate_mask);
3725 _rtl8821ae_set_bcn_ctrl_reg(hw, BIT(3), 0);
3728 void rtl8821ae_update_hal_rate_tbl(struct ieee80211_hw *hw,
3729 struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
3731 struct rtl_priv *rtlpriv = rtl_priv(hw);
3732 if (rtlpriv->dm.useramask)
3733 rtl8821ae_update_hal_rate_mask(hw, sta, rssi_level, update_bw);
3735 /*RT_TRACE(rtlpriv, COMP_RATR,DBG_LOUD,
3736 "rtl8821ae_update_hal_rate_tbl() Error! 8821ae FW RA Only\n");*/
3737 rtl8821ae_update_hal_rate_table(hw, sta);
3740 void rtl8821ae_update_channel_access_setting(struct ieee80211_hw *hw)
3742 struct rtl_priv *rtlpriv = rtl_priv(hw);
3743 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
3744 u16 wireless_mode = mac->mode;
3745 u8 sifs_timer, r2t_sifs;
3747 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
3748 (u8 *)&mac->slot_time);
3749 if (wireless_mode == WIRELESS_MODE_G)
3753 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
3757 if (wireless_mode == WIRELESS_MODE_AC_5G &&
3758 (mac->vht_ldpc_cap & LDPC_VHT_ENABLE_RX) &&
3759 (mac->vht_stbc_cap & STBC_VHT_ENABLE_RX)) {
3760 if (mac->vendor == PEER_ATH)
3764 } else if (wireless_mode == WIRELESS_MODE_AC_5G) {
3768 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_R2T_SIFS, (u8 *)&r2t_sifs);
3771 bool rtl8821ae_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
3773 struct rtl_priv *rtlpriv = rtl_priv(hw);
3774 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
3775 struct rtl_phy *rtlphy = &rtlpriv->phy;
3776 enum rf_pwrstate e_rfpowerstate_toset;
3778 bool b_actuallyset = false;
3780 if (rtlpriv->rtlhal.being_init_adapter)
3783 if (ppsc->swrf_processing)
3786 spin_lock(&rtlpriv->locks.rf_ps_lock);
3787 if (ppsc->rfchange_inprogress) {
3788 spin_unlock(&rtlpriv->locks.rf_ps_lock);
3791 ppsc->rfchange_inprogress = true;
3792 spin_unlock(&rtlpriv->locks.rf_ps_lock);
3795 rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL_2,
3796 rtl_read_byte(rtlpriv,
3797 REG_GPIO_IO_SEL_2) & ~(BIT(1)));
3799 u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL_2);
3801 if (rtlphy->polarity_ctl)
3802 e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFOFF : ERFON;
3804 e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFON : ERFOFF;
3806 if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) {
3807 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
3808 "GPIOChangeRF - HW Radio ON, RF ON\n");
3810 e_rfpowerstate_toset = ERFON;
3811 ppsc->hwradiooff = false;
3812 b_actuallyset = true;
3813 } else if ((!ppsc->hwradiooff)
3814 && (e_rfpowerstate_toset == ERFOFF)) {
3815 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
3816 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
3818 e_rfpowerstate_toset = ERFOFF;
3819 ppsc->hwradiooff = true;
3820 b_actuallyset = true;
3823 if (b_actuallyset) {
3824 spin_lock(&rtlpriv->locks.rf_ps_lock);
3825 ppsc->rfchange_inprogress = false;
3826 spin_unlock(&rtlpriv->locks.rf_ps_lock);
3828 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
3829 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
3831 spin_lock(&rtlpriv->locks.rf_ps_lock);
3832 ppsc->rfchange_inprogress = false;
3833 spin_unlock(&rtlpriv->locks.rf_ps_lock);
3837 return !ppsc->hwradiooff;
3840 void rtl8821ae_set_key(struct ieee80211_hw *hw, u32 key_index,
3841 u8 *p_macaddr, bool is_group, u8 enc_algo,
3842 bool is_wepkey, bool clear_all)
3844 struct rtl_priv *rtlpriv = rtl_priv(hw);
3845 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
3846 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
3847 u8 *macaddr = p_macaddr;
3849 bool is_pairwise = false;
3851 static u8 cam_const_addr[4][6] = {
3852 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3853 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3854 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3855 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
3857 static u8 cam_const_broad[] = {
3858 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
3864 u8 clear_number = 5;
3866 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
3868 for (idx = 0; idx < clear_number; idx++) {
3869 rtl_cam_mark_invalid(hw, cam_offset + idx);
3870 rtl_cam_empty_entry(hw, cam_offset + idx);
3873 memset(rtlpriv->sec.key_buf[idx], 0,
3875 rtlpriv->sec.key_len[idx] = 0;
3880 case WEP40_ENCRYPTION:
3881 enc_algo = CAM_WEP40;
3883 case WEP104_ENCRYPTION:
3884 enc_algo = CAM_WEP104;
3886 case TKIP_ENCRYPTION:
3887 enc_algo = CAM_TKIP;
3889 case AESCCMP_ENCRYPTION:
3893 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
3894 "switch case %#x not processed\n", enc_algo);
3895 enc_algo = CAM_TKIP;
3899 if (is_wepkey || rtlpriv->sec.use_defaultkey) {
3900 macaddr = cam_const_addr[key_index];
3901 entry_id = key_index;
3904 macaddr = cam_const_broad;
3905 entry_id = key_index;
3907 if (mac->opmode == NL80211_IFTYPE_AP) {
3908 entry_id = rtl_cam_get_free_entry(hw, p_macaddr);
3909 if (entry_id >= TOTAL_CAM_ENTRY) {
3910 pr_err("an not find free hwsecurity cam entry\n");
3914 entry_id = CAM_PAIRWISE_KEY_POSITION;
3917 key_index = PAIRWISE_KEYIDX;
3922 if (rtlpriv->sec.key_len[key_index] == 0) {
3923 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
3924 "delete one entry, entry_id is %d\n",
3926 if (mac->opmode == NL80211_IFTYPE_AP)
3927 rtl_cam_del_entry(hw, p_macaddr);
3928 rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
3930 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
3933 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
3934 "set Pairwise key\n");
3936 rtl_cam_add_one_entry(hw, macaddr, key_index,
3938 CAM_CONFIG_NO_USEDK,
3939 rtlpriv->sec.key_buf[key_index]);
3941 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
3944 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
3945 rtl_cam_add_one_entry(hw,
3948 CAM_PAIRWISE_KEY_POSITION,
3950 CAM_CONFIG_NO_USEDK,
3951 rtlpriv->sec.key_buf
3955 rtl_cam_add_one_entry(hw, macaddr, key_index,
3957 CAM_CONFIG_NO_USEDK,
3958 rtlpriv->sec.key_buf[entry_id]);
3964 void rtl8821ae_bt_reg_init(struct ieee80211_hw *hw)
3966 struct rtl_priv *rtlpriv = rtl_priv(hw);
3968 /* 0:Low, 1:High, 2:From Efuse. */
3969 rtlpriv->btcoexist.reg_bt_iso = 2;
3970 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
3971 rtlpriv->btcoexist.reg_bt_sco = 3;
3972 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
3973 rtlpriv->btcoexist.reg_bt_sco = 0;
3976 void rtl8821ae_bt_hw_init(struct ieee80211_hw *hw)
3978 struct rtl_priv *rtlpriv = rtl_priv(hw);
3980 if (rtlpriv->cfg->ops->get_btc_status())
3981 rtlpriv->btcoexist.btc_ops->btc_init_hw_config(rtlpriv);
3984 void rtl8821ae_suspend(struct ieee80211_hw *hw)
3988 void rtl8821ae_resume(struct ieee80211_hw *hw)
3992 /* Turn on AAP (RCR:bit 0) for promicuous mode. */
3993 void rtl8821ae_allow_all_destaddr(struct ieee80211_hw *hw,
3994 bool allow_all_da, bool write_into_reg)
3996 struct rtl_priv *rtlpriv = rtl_priv(hw);
3997 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
3999 if (allow_all_da) /* Set BIT0 */
4000 rtlpci->receive_config |= RCR_AAP;
4001 else /* Clear BIT0 */
4002 rtlpci->receive_config &= ~RCR_AAP;
4005 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
4007 RT_TRACE(rtlpriv, COMP_TURBO | COMP_INIT, DBG_LOUD,
4008 "receive_config=0x%08X, write_into_reg=%d\n",
4009 rtlpci->receive_config, write_into_reg);
4012 /* WKFMCAMAddAllEntry8812 */
4013 void rtl8821ae_add_wowlan_pattern(struct ieee80211_hw *hw,
4014 struct rtl_wow_pattern *rtl_pattern,
4017 struct rtl_priv *rtlpriv = rtl_priv(hw);
4025 /* Count the WFCAM entry start offset. */
4027 /* RX page size = 128 byte */
4028 offset = MAX_RX_DMA_BUFFER_SIZE_8812 / 128;
4029 /* We should start from the boundry */
4030 cam_start = offset * 128;
4032 /* Enable Rx packet buffer access. */
4033 rtl_write_byte(rtlpriv, REG_PKT_BUFF_ACCESS_CTRL, RXPKT_BUF_SELECT);
4034 for (addr = 0; addr < WKFMCAM_ADDR_NUM; addr++) {
4035 /* Set Rx packet buffer offset.
4036 * RxBufer pointer increases 1,
4037 * we can access 8 bytes in Rx packet buffer.
4038 * CAM start offset (unit: 1 byte) = index*WKFMCAM_SIZE
4039 * RxBufer addr = (CAM start offset +
4040 * per entry offset of a WKFM CAM)/8
4041 * * index: The index of the wake up frame mask
4042 * * WKFMCAM_SIZE: the total size of one WKFM CAM
4043 * * per entry offset of a WKFM CAM: Addr*4 bytes
4045 rxbuf_addr = (cam_start + index * WKFMCAM_SIZE + addr * 4) >> 3;
4046 /* Set R/W start offset */
4047 rtl_write_word(rtlpriv, REG_PKTBUF_DBG_CTRL, rxbuf_addr);
4050 cam = BIT(31) | rtl_pattern->crc;
4052 if (rtl_pattern->type == UNICAST_PATTERN)
4054 else if (rtl_pattern->type == MULTICAST_PATTERN)
4056 else if (rtl_pattern->type == BROADCAST_PATTERN)
4059 rtl_write_dword(rtlpriv, REG_PKTBUF_DBG_DATA_L, cam);
4060 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
4061 "WRITE entry[%d] 0x%x: %x\n", addr,
4062 REG_PKTBUF_DBG_DATA_L, cam);
4064 /* Write to Rx packet buffer. */
4065 rtl_write_word(rtlpriv, REG_RXPKTBUF_CTRL, 0x0f01);
4066 } else if (addr == 2 || addr == 4) {/* WKFM[127:0] */
4067 cam = rtl_pattern->mask[addr - 2];
4069 rtl_write_dword(rtlpriv, REG_PKTBUF_DBG_DATA_L, cam);
4070 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
4071 "WRITE entry[%d] 0x%x: %x\n", addr,
4072 REG_PKTBUF_DBG_DATA_L, cam);
4074 rtl_write_word(rtlpriv, REG_RXPKTBUF_CTRL, 0x0f01);
4075 } else if (addr == 3 || addr == 5) {/* WKFM[127:0] */
4076 cam = rtl_pattern->mask[addr - 2];
4078 rtl_write_dword(rtlpriv, REG_PKTBUF_DBG_DATA_H, cam);
4079 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
4080 "WRITE entry[%d] 0x%x: %x\n", addr,
4081 REG_PKTBUF_DBG_DATA_H, cam);
4083 rtl_write_word(rtlpriv, REG_RXPKTBUF_CTRL, 0xf001);
4088 tmp = rtl_read_byte(rtlpriv, REG_RXPKTBUF_CTRL);
4091 } while (tmp && count < 100);
4093 WARN_ONCE((count >= 100),
4094 "rtl8821ae: Write wake up frame mask FAIL %d value!\n",
4097 /* Disable Rx packet buffer access. */
4098 rtl_write_byte(rtlpriv, REG_PKT_BUFF_ACCESS_CTRL,
4099 DISABLE_TRXPKT_BUF_ACCESS);