xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/hw.c (revision 0421dd4167ec7d74daf891aae9e64801a3adcd4f)
10770f718SLarry Finger // SPDX-License-Identifier: GPL-2.0
20770f718SLarry Finger /* Copyright(c) 2009-2012  Realtek Corporation.*/
3f1d2b4d3SLarry Finger 
4f1d2b4d3SLarry Finger #include "../wifi.h"
5f1d2b4d3SLarry Finger #include "../efuse.h"
6f1d2b4d3SLarry Finger #include "../base.h"
7f1d2b4d3SLarry Finger #include "../regd.h"
8f1d2b4d3SLarry Finger #include "../cam.h"
9f1d2b4d3SLarry Finger #include "../ps.h"
10f1d2b4d3SLarry Finger #include "../pci.h"
11f1d2b4d3SLarry Finger #include "reg.h"
12f1d2b4d3SLarry Finger #include "def.h"
13f1d2b4d3SLarry Finger #include "phy.h"
14f1d2b4d3SLarry Finger #include "../rtl8192c/dm_common.h"
15f1d2b4d3SLarry Finger #include "../rtl8192c/fw_common.h"
16f1d2b4d3SLarry Finger #include "../rtl8192c/phy_common.h"
17f1d2b4d3SLarry Finger #include "dm.h"
18f1d2b4d3SLarry Finger #include "led.h"
19f1d2b4d3SLarry Finger #include "hw.h"
20f1d2b4d3SLarry Finger 
21f1d2b4d3SLarry Finger #define LLT_CONFIG	5
22f1d2b4d3SLarry Finger 
23f1d2b4d3SLarry Finger static void _rtl92ce_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
24f1d2b4d3SLarry Finger 				      u8 set_bits, u8 clear_bits)
25f1d2b4d3SLarry Finger {
26f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
27f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
28f1d2b4d3SLarry Finger 
29f1d2b4d3SLarry Finger 	rtlpci->reg_bcn_ctrl_val |= set_bits;
30f1d2b4d3SLarry Finger 	rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
31f1d2b4d3SLarry Finger 
32f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlpci->reg_bcn_ctrl_val);
33f1d2b4d3SLarry Finger }
34f1d2b4d3SLarry Finger 
35f1d2b4d3SLarry Finger static void _rtl92ce_stop_tx_beacon(struct ieee80211_hw *hw)
36f1d2b4d3SLarry Finger {
37f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
38f1d2b4d3SLarry Finger 	u8 tmp1byte;
39f1d2b4d3SLarry Finger 
40f1d2b4d3SLarry Finger 	tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
41f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
42f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
43f1d2b4d3SLarry Finger 	tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
44f1d2b4d3SLarry Finger 	tmp1byte &= ~(BIT(0));
45f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
46f1d2b4d3SLarry Finger }
47f1d2b4d3SLarry Finger 
48f1d2b4d3SLarry Finger static void _rtl92ce_resume_tx_beacon(struct ieee80211_hw *hw)
49f1d2b4d3SLarry Finger {
50f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
51f1d2b4d3SLarry Finger 	u8 tmp1byte;
52f1d2b4d3SLarry Finger 
53f1d2b4d3SLarry Finger 	tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
54f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
55f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
56f1d2b4d3SLarry Finger 	tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
57f1d2b4d3SLarry Finger 	tmp1byte |= BIT(0);
58f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
59f1d2b4d3SLarry Finger }
60f1d2b4d3SLarry Finger 
61f1d2b4d3SLarry Finger static void _rtl92ce_enable_bcn_sub_func(struct ieee80211_hw *hw)
62f1d2b4d3SLarry Finger {
63f1d2b4d3SLarry Finger 	_rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(1));
64f1d2b4d3SLarry Finger }
65f1d2b4d3SLarry Finger 
66f1d2b4d3SLarry Finger static void _rtl92ce_disable_bcn_sub_func(struct ieee80211_hw *hw)
67f1d2b4d3SLarry Finger {
68f1d2b4d3SLarry Finger 	_rtl92ce_set_bcn_ctrl_reg(hw, BIT(1), 0);
69f1d2b4d3SLarry Finger }
70f1d2b4d3SLarry Finger 
71f1d2b4d3SLarry Finger void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
72f1d2b4d3SLarry Finger {
73f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
74f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
75f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
76f1d2b4d3SLarry Finger 
77f1d2b4d3SLarry Finger 	switch (variable) {
78f1d2b4d3SLarry Finger 	case HW_VAR_RCR:
79f1d2b4d3SLarry Finger 		*((u32 *) (val)) = rtlpci->receive_config;
80f1d2b4d3SLarry Finger 		break;
81f1d2b4d3SLarry Finger 	case HW_VAR_RF_STATE:
82f1d2b4d3SLarry Finger 		*((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
83f1d2b4d3SLarry Finger 		break;
84f1d2b4d3SLarry Finger 	case HW_VAR_FWLPS_RF_ON:{
85ff970453SLarry Finger 			enum rf_pwrstate rfstate;
86f1d2b4d3SLarry Finger 			u32 val_rcr;
87f1d2b4d3SLarry Finger 
88f1d2b4d3SLarry Finger 			rtlpriv->cfg->ops->get_hw_reg(hw,
89f1d2b4d3SLarry Finger 						      HW_VAR_RF_STATE,
90ff970453SLarry Finger 						      (u8 *)(&rfstate));
91ff970453SLarry Finger 			if (rfstate == ERFOFF) {
92f1d2b4d3SLarry Finger 				*((bool *) (val)) = true;
93f1d2b4d3SLarry Finger 			} else {
94f1d2b4d3SLarry Finger 				val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
95f1d2b4d3SLarry Finger 				val_rcr &= 0x00070000;
96f1d2b4d3SLarry Finger 				if (val_rcr)
97f1d2b4d3SLarry Finger 					*((bool *) (val)) = false;
98f1d2b4d3SLarry Finger 				else
99f1d2b4d3SLarry Finger 					*((bool *) (val)) = true;
100f1d2b4d3SLarry Finger 			}
101f1d2b4d3SLarry Finger 			break;
102f1d2b4d3SLarry Finger 		}
103f1d2b4d3SLarry Finger 	case HW_VAR_FW_PSMODE_STATUS:
104f1d2b4d3SLarry Finger 		*((bool *) (val)) = ppsc->fw_current_inpsmode;
105f1d2b4d3SLarry Finger 		break;
106f1d2b4d3SLarry Finger 	case HW_VAR_CORRECT_TSF:{
107f1d2b4d3SLarry Finger 		u64 tsf;
108f1d2b4d3SLarry Finger 		u32 *ptsf_low = (u32 *)&tsf;
109f1d2b4d3SLarry Finger 		u32 *ptsf_high = ((u32 *)&tsf) + 1;
110f1d2b4d3SLarry Finger 
111f1d2b4d3SLarry Finger 		*ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
112f1d2b4d3SLarry Finger 		*ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
113f1d2b4d3SLarry Finger 
114f1d2b4d3SLarry Finger 		*((u64 *) (val)) = tsf;
115f1d2b4d3SLarry Finger 
116f1d2b4d3SLarry Finger 		break;
117f1d2b4d3SLarry Finger 		}
1181cc49a5bSLarry Finger 	case HAL_DEF_WOWLAN:
1191cc49a5bSLarry Finger 		break;
120f1d2b4d3SLarry Finger 	default:
121e40a0056SLarry Finger 		pr_err("switch case %#x not processed\n", variable);
122f1d2b4d3SLarry Finger 		break;
123f1d2b4d3SLarry Finger 	}
124f1d2b4d3SLarry Finger }
125f1d2b4d3SLarry Finger 
126f1d2b4d3SLarry Finger void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
127f1d2b4d3SLarry Finger {
128f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
129f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
130f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
131f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
132f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
133f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
134f1d2b4d3SLarry Finger 	u8 idx;
135f1d2b4d3SLarry Finger 
136f1d2b4d3SLarry Finger 	switch (variable) {
137f1d2b4d3SLarry Finger 	case HW_VAR_ETHER_ADDR:{
138f1d2b4d3SLarry Finger 			for (idx = 0; idx < ETH_ALEN; idx++) {
139f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, (REG_MACID + idx),
140f1d2b4d3SLarry Finger 					       val[idx]);
141f1d2b4d3SLarry Finger 			}
142f1d2b4d3SLarry Finger 			break;
143f1d2b4d3SLarry Finger 		}
144f1d2b4d3SLarry Finger 	case HW_VAR_BASIC_RATE:{
145f1d2b4d3SLarry Finger 			u16 rate_cfg = ((u16 *) val)[0];
146f1d2b4d3SLarry Finger 			u8 rate_index = 0;
147f1d2b4d3SLarry Finger 			rate_cfg &= 0x15f;
148f1d2b4d3SLarry Finger 			rate_cfg |= 0x01;
149f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
150f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_RRSR + 1,
151f1d2b4d3SLarry Finger 				       (rate_cfg >> 8) & 0xff);
152f1d2b4d3SLarry Finger 			while (rate_cfg > 0x1) {
153f1d2b4d3SLarry Finger 				rate_cfg = (rate_cfg >> 1);
154f1d2b4d3SLarry Finger 				rate_index++;
155f1d2b4d3SLarry Finger 			}
156f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
157f1d2b4d3SLarry Finger 				       rate_index);
158f1d2b4d3SLarry Finger 			break;
159f1d2b4d3SLarry Finger 		}
160f1d2b4d3SLarry Finger 	case HW_VAR_BSSID:{
161f1d2b4d3SLarry Finger 			for (idx = 0; idx < ETH_ALEN; idx++) {
162f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, (REG_BSSID + idx),
163f1d2b4d3SLarry Finger 					       val[idx]);
164f1d2b4d3SLarry Finger 			}
165f1d2b4d3SLarry Finger 			break;
166f1d2b4d3SLarry Finger 		}
167f1d2b4d3SLarry Finger 	case HW_VAR_SIFS:{
168f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
169f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
170f1d2b4d3SLarry Finger 
171f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
172f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
173f1d2b4d3SLarry Finger 
174f1d2b4d3SLarry Finger 			if (!mac->ht_enable)
175f1d2b4d3SLarry Finger 				rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
176f1d2b4d3SLarry Finger 					       0x0e0e);
177f1d2b4d3SLarry Finger 			else
178f1d2b4d3SLarry Finger 				rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
179f1d2b4d3SLarry Finger 					       *((u16 *) val));
180f1d2b4d3SLarry Finger 			break;
181f1d2b4d3SLarry Finger 		}
182f1d2b4d3SLarry Finger 	case HW_VAR_SLOT_TIME:{
183f1d2b4d3SLarry Finger 			u8 e_aci;
184f1d2b4d3SLarry Finger 
185f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
186f1d2b4d3SLarry Finger 				 "HW_VAR_SLOT_TIME %x\n", val[0]);
187f1d2b4d3SLarry Finger 
188f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
189f1d2b4d3SLarry Finger 
190f1d2b4d3SLarry Finger 			for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
191f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
192f1d2b4d3SLarry Finger 							      HW_VAR_AC_PARAM,
193f1d2b4d3SLarry Finger 							      &e_aci);
194f1d2b4d3SLarry Finger 			}
195f1d2b4d3SLarry Finger 			break;
196f1d2b4d3SLarry Finger 		}
197f1d2b4d3SLarry Finger 	case HW_VAR_ACK_PREAMBLE:{
198f1d2b4d3SLarry Finger 			u8 reg_tmp;
199f1d2b4d3SLarry Finger 			u8 short_preamble = (bool)*val;
200f1d2b4d3SLarry Finger 			reg_tmp = (mac->cur_40_prime_sc) << 5;
201f1d2b4d3SLarry Finger 			if (short_preamble)
202f1d2b4d3SLarry Finger 				reg_tmp |= 0x80;
203f1d2b4d3SLarry Finger 
204f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
205f1d2b4d3SLarry Finger 			break;
206f1d2b4d3SLarry Finger 		}
207f1d2b4d3SLarry Finger 	case HW_VAR_AMPDU_MIN_SPACE:{
208f1d2b4d3SLarry Finger 			u8 min_spacing_to_set;
209f1d2b4d3SLarry Finger 			u8 sec_min_space;
210f1d2b4d3SLarry Finger 
211f1d2b4d3SLarry Finger 			min_spacing_to_set = *val;
212f1d2b4d3SLarry Finger 			if (min_spacing_to_set <= 7) {
213f1d2b4d3SLarry Finger 				sec_min_space = 0;
214f1d2b4d3SLarry Finger 
215f1d2b4d3SLarry Finger 				if (min_spacing_to_set < sec_min_space)
216f1d2b4d3SLarry Finger 					min_spacing_to_set = sec_min_space;
217f1d2b4d3SLarry Finger 
218f1d2b4d3SLarry Finger 				mac->min_space_cfg = ((mac->min_space_cfg &
219f1d2b4d3SLarry Finger 						       0xf8) |
220f1d2b4d3SLarry Finger 						      min_spacing_to_set);
221f1d2b4d3SLarry Finger 
222f1d2b4d3SLarry Finger 				*val = min_spacing_to_set;
223f1d2b4d3SLarry Finger 
224f1d2b4d3SLarry Finger 				RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
225f1d2b4d3SLarry Finger 					 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
226f1d2b4d3SLarry Finger 					 mac->min_space_cfg);
227f1d2b4d3SLarry Finger 
228f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
229f1d2b4d3SLarry Finger 					       mac->min_space_cfg);
230f1d2b4d3SLarry Finger 			}
231f1d2b4d3SLarry Finger 			break;
232f1d2b4d3SLarry Finger 		}
233f1d2b4d3SLarry Finger 	case HW_VAR_SHORTGI_DENSITY:{
234f1d2b4d3SLarry Finger 			u8 density_to_set;
235f1d2b4d3SLarry Finger 
236f1d2b4d3SLarry Finger 			density_to_set = *val;
237f1d2b4d3SLarry Finger 			mac->min_space_cfg |= (density_to_set << 3);
238f1d2b4d3SLarry Finger 
239f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
240f1d2b4d3SLarry Finger 				 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
241f1d2b4d3SLarry Finger 				 mac->min_space_cfg);
242f1d2b4d3SLarry Finger 
243f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
244f1d2b4d3SLarry Finger 				       mac->min_space_cfg);
245f1d2b4d3SLarry Finger 
246f1d2b4d3SLarry Finger 			break;
247f1d2b4d3SLarry Finger 		}
248f1d2b4d3SLarry Finger 	case HW_VAR_AMPDU_FACTOR:{
249f1d2b4d3SLarry Finger 			u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
250f1d2b4d3SLarry Finger 			u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
251f1d2b4d3SLarry Finger 
252f1d2b4d3SLarry Finger 			u8 factor_toset;
253f1d2b4d3SLarry Finger 			u8 *p_regtoset = NULL;
254f1d2b4d3SLarry Finger 			u8 index = 0;
255f1d2b4d3SLarry Finger 
256d5efe153SLarry Finger 			if ((rtlpriv->btcoexist.bt_coexistence) &&
257d5efe153SLarry Finger 			    (rtlpriv->btcoexist.bt_coexist_type ==
258f1d2b4d3SLarry Finger 			    BT_CSR_BC4))
259f1d2b4d3SLarry Finger 				p_regtoset = regtoset_bt;
260f1d2b4d3SLarry Finger 			else
261f1d2b4d3SLarry Finger 				p_regtoset = regtoset_normal;
262f1d2b4d3SLarry Finger 
263f1d2b4d3SLarry Finger 			factor_toset = *(val);
264f1d2b4d3SLarry Finger 			if (factor_toset <= 3) {
265f1d2b4d3SLarry Finger 				factor_toset = (1 << (factor_toset + 2));
266f1d2b4d3SLarry Finger 				if (factor_toset > 0xf)
267f1d2b4d3SLarry Finger 					factor_toset = 0xf;
268f1d2b4d3SLarry Finger 
269f1d2b4d3SLarry Finger 				for (index = 0; index < 4; index++) {
270f1d2b4d3SLarry Finger 					if ((p_regtoset[index] & 0xf0) >
271f1d2b4d3SLarry Finger 					    (factor_toset << 4))
272f1d2b4d3SLarry Finger 						p_regtoset[index] =
273f1d2b4d3SLarry Finger 						    (p_regtoset[index] & 0x0f) |
274f1d2b4d3SLarry Finger 						    (factor_toset << 4);
275f1d2b4d3SLarry Finger 
276f1d2b4d3SLarry Finger 					if ((p_regtoset[index] & 0x0f) >
277f1d2b4d3SLarry Finger 					    factor_toset)
278f1d2b4d3SLarry Finger 						p_regtoset[index] =
279f1d2b4d3SLarry Finger 						    (p_regtoset[index] & 0xf0) |
280f1d2b4d3SLarry Finger 						    (factor_toset);
281f1d2b4d3SLarry Finger 
282f1d2b4d3SLarry Finger 					rtl_write_byte(rtlpriv,
283f1d2b4d3SLarry Finger 						       (REG_AGGLEN_LMT + index),
284f1d2b4d3SLarry Finger 						       p_regtoset[index]);
285f1d2b4d3SLarry Finger 
286f1d2b4d3SLarry Finger 				}
287f1d2b4d3SLarry Finger 
288f1d2b4d3SLarry Finger 				RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
289f1d2b4d3SLarry Finger 					 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
290f1d2b4d3SLarry Finger 					 factor_toset);
291f1d2b4d3SLarry Finger 			}
292f1d2b4d3SLarry Finger 			break;
293f1d2b4d3SLarry Finger 		}
294f1d2b4d3SLarry Finger 	case HW_VAR_AC_PARAM:{
295f1d2b4d3SLarry Finger 			u8 e_aci = *(val);
296f1d2b4d3SLarry Finger 			rtl92c_dm_init_edca_turbo(hw);
297f1d2b4d3SLarry Finger 
298f1d2b4d3SLarry Finger 			if (rtlpci->acm_method != EACMWAY2_SW)
299f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
300f1d2b4d3SLarry Finger 							      HW_VAR_ACM_CTRL,
301f1d2b4d3SLarry Finger 							      (&e_aci));
302f1d2b4d3SLarry Finger 			break;
303f1d2b4d3SLarry Finger 		}
304f1d2b4d3SLarry Finger 	case HW_VAR_ACM_CTRL:{
305f1d2b4d3SLarry Finger 			u8 e_aci = *(val);
306f1d2b4d3SLarry Finger 			union aci_aifsn *p_aci_aifsn =
307f1d2b4d3SLarry Finger 			    (union aci_aifsn *)(&(mac->ac[0].aifs));
308f1d2b4d3SLarry Finger 			u8 acm = p_aci_aifsn->f.acm;
309f1d2b4d3SLarry Finger 			u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
310f1d2b4d3SLarry Finger 
311f1d2b4d3SLarry Finger 			acm_ctrl =
312f1d2b4d3SLarry Finger 			    acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
313f1d2b4d3SLarry Finger 
314f1d2b4d3SLarry Finger 			if (acm) {
315f1d2b4d3SLarry Finger 				switch (e_aci) {
316f1d2b4d3SLarry Finger 				case AC0_BE:
317ff970453SLarry Finger 					acm_ctrl |= ACMHW_BEQEN;
318f1d2b4d3SLarry Finger 					break;
319f1d2b4d3SLarry Finger 				case AC2_VI:
320ff970453SLarry Finger 					acm_ctrl |= ACMHW_VIQEN;
321f1d2b4d3SLarry Finger 					break;
322f1d2b4d3SLarry Finger 				case AC3_VO:
323ff970453SLarry Finger 					acm_ctrl |= ACMHW_VOQEN;
324f1d2b4d3SLarry Finger 					break;
325f1d2b4d3SLarry Finger 				default:
326f1d2b4d3SLarry Finger 					RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
327f1d2b4d3SLarry Finger 						 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
328f1d2b4d3SLarry Finger 						 acm);
329f1d2b4d3SLarry Finger 					break;
330f1d2b4d3SLarry Finger 				}
331f1d2b4d3SLarry Finger 			} else {
332f1d2b4d3SLarry Finger 				switch (e_aci) {
333f1d2b4d3SLarry Finger 				case AC0_BE:
334ff970453SLarry Finger 					acm_ctrl &= (~ACMHW_BEQEN);
335f1d2b4d3SLarry Finger 					break;
336f1d2b4d3SLarry Finger 				case AC2_VI:
337ff970453SLarry Finger 					acm_ctrl &= (~ACMHW_VIQEN);
338f1d2b4d3SLarry Finger 					break;
339f1d2b4d3SLarry Finger 				case AC3_VO:
340ff970453SLarry Finger 					acm_ctrl &= (~ACMHW_VOQEN);
341f1d2b4d3SLarry Finger 					break;
342f1d2b4d3SLarry Finger 				default:
343e40a0056SLarry Finger 					pr_err("switch case %#x not processed\n",
344ad574889SJoe Perches 					       e_aci);
345f1d2b4d3SLarry Finger 					break;
346f1d2b4d3SLarry Finger 				}
347f1d2b4d3SLarry Finger 			}
348f1d2b4d3SLarry Finger 
349f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
350f1d2b4d3SLarry Finger 				 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
351f1d2b4d3SLarry Finger 				 acm_ctrl);
352f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
353f1d2b4d3SLarry Finger 			break;
354f1d2b4d3SLarry Finger 		}
355f1d2b4d3SLarry Finger 	case HW_VAR_RCR:{
356f1d2b4d3SLarry Finger 			rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
357f1d2b4d3SLarry Finger 			rtlpci->receive_config = ((u32 *) (val))[0];
358f1d2b4d3SLarry Finger 			break;
359f1d2b4d3SLarry Finger 		}
360f1d2b4d3SLarry Finger 	case HW_VAR_RETRY_LIMIT:{
361f1d2b4d3SLarry Finger 			u8 retry_limit = val[0];
362f1d2b4d3SLarry Finger 
363f1d2b4d3SLarry Finger 			rtl_write_word(rtlpriv, REG_RL,
364f1d2b4d3SLarry Finger 				       retry_limit << RETRY_LIMIT_SHORT_SHIFT |
365f1d2b4d3SLarry Finger 				       retry_limit << RETRY_LIMIT_LONG_SHIFT);
366f1d2b4d3SLarry Finger 			break;
367f1d2b4d3SLarry Finger 		}
368f1d2b4d3SLarry Finger 	case HW_VAR_DUAL_TSF_RST:
369f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
370f1d2b4d3SLarry Finger 		break;
371f1d2b4d3SLarry Finger 	case HW_VAR_EFUSE_BYTES:
372f1d2b4d3SLarry Finger 		rtlefuse->efuse_usedbytes = *((u16 *) val);
373f1d2b4d3SLarry Finger 		break;
374f1d2b4d3SLarry Finger 	case HW_VAR_EFUSE_USAGE:
375f1d2b4d3SLarry Finger 		rtlefuse->efuse_usedpercentage = *val;
376f1d2b4d3SLarry Finger 		break;
377f1d2b4d3SLarry Finger 	case HW_VAR_IO_CMD:
378f1d2b4d3SLarry Finger 		rtl92c_phy_set_io_cmd(hw, (*(enum io_type *)val));
379f1d2b4d3SLarry Finger 		break;
380f1d2b4d3SLarry Finger 	case HW_VAR_WPA_CONFIG:
381f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_SECCFG, *val);
382f1d2b4d3SLarry Finger 		break;
383f1d2b4d3SLarry Finger 	case HW_VAR_SET_RPWM:{
384f1d2b4d3SLarry Finger 			u8 rpwm_val;
385f1d2b4d3SLarry Finger 
386f1d2b4d3SLarry Finger 			rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
387f1d2b4d3SLarry Finger 			udelay(1);
388f1d2b4d3SLarry Finger 
389f1d2b4d3SLarry Finger 			if (rpwm_val & BIT(7)) {
390f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
391f1d2b4d3SLarry Finger 			} else {
392f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
393f1d2b4d3SLarry Finger 					       *val | BIT(7));
394f1d2b4d3SLarry Finger 			}
395f1d2b4d3SLarry Finger 
396f1d2b4d3SLarry Finger 			break;
397f1d2b4d3SLarry Finger 		}
398f1d2b4d3SLarry Finger 	case HW_VAR_H2C_FW_PWRMODE:{
399f1d2b4d3SLarry Finger 			u8 psmode = *val;
400f1d2b4d3SLarry Finger 
401f1d2b4d3SLarry Finger 			if ((psmode != FW_PS_ACTIVE_MODE) &&
402f1d2b4d3SLarry Finger 			    (!IS_92C_SERIAL(rtlhal->version))) {
403f1d2b4d3SLarry Finger 				rtl92c_dm_rf_saving(hw, true);
404f1d2b4d3SLarry Finger 			}
405f1d2b4d3SLarry Finger 
406f1d2b4d3SLarry Finger 			rtl92c_set_fw_pwrmode_cmd(hw, *val);
407f1d2b4d3SLarry Finger 			break;
408f1d2b4d3SLarry Finger 		}
409f1d2b4d3SLarry Finger 	case HW_VAR_FW_PSMODE_STATUS:
410f1d2b4d3SLarry Finger 		ppsc->fw_current_inpsmode = *((bool *) val);
411f1d2b4d3SLarry Finger 		break;
412f1d2b4d3SLarry Finger 	case HW_VAR_H2C_FW_JOINBSSRPT:{
413f1d2b4d3SLarry Finger 			u8 mstatus = *val;
414f1d2b4d3SLarry Finger 			u8 tmp_regcr, tmp_reg422;
415f1d2b4d3SLarry Finger 			bool recover = false;
416f1d2b4d3SLarry Finger 
417f1d2b4d3SLarry Finger 			if (mstatus == RT_MEDIA_CONNECT) {
418f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
419f1d2b4d3SLarry Finger 							      NULL);
420f1d2b4d3SLarry Finger 
421f1d2b4d3SLarry Finger 				tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
422f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_CR + 1,
423f1d2b4d3SLarry Finger 					       (tmp_regcr | BIT(0)));
424f1d2b4d3SLarry Finger 
425f1d2b4d3SLarry Finger 				_rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
426f1d2b4d3SLarry Finger 				_rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
427f1d2b4d3SLarry Finger 
428f1d2b4d3SLarry Finger 				tmp_reg422 =
429f1d2b4d3SLarry Finger 				    rtl_read_byte(rtlpriv,
430f1d2b4d3SLarry Finger 						  REG_FWHW_TXQ_CTRL + 2);
431f1d2b4d3SLarry Finger 				if (tmp_reg422 & BIT(6))
432f1d2b4d3SLarry Finger 					recover = true;
433f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
434f1d2b4d3SLarry Finger 					       tmp_reg422 & (~BIT(6)));
435f1d2b4d3SLarry Finger 
436f1d2b4d3SLarry Finger 				rtl92c_set_fw_rsvdpagepkt(hw, NULL);
437f1d2b4d3SLarry Finger 
438f1d2b4d3SLarry Finger 				_rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
439f1d2b4d3SLarry Finger 				_rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
440f1d2b4d3SLarry Finger 
441f1d2b4d3SLarry Finger 				if (recover) {
442f1d2b4d3SLarry Finger 					rtl_write_byte(rtlpriv,
443f1d2b4d3SLarry Finger 						       REG_FWHW_TXQ_CTRL + 2,
444f1d2b4d3SLarry Finger 						       tmp_reg422);
445f1d2b4d3SLarry Finger 				}
446f1d2b4d3SLarry Finger 
447f1d2b4d3SLarry Finger 				rtl_write_byte(rtlpriv, REG_CR + 1,
448f1d2b4d3SLarry Finger 					       (tmp_regcr & ~(BIT(0))));
449f1d2b4d3SLarry Finger 			}
450f1d2b4d3SLarry Finger 			rtl92c_set_fw_joinbss_report_cmd(hw, *val);
451f1d2b4d3SLarry Finger 
452f1d2b4d3SLarry Finger 			break;
453f1d2b4d3SLarry Finger 		}
454f1d2b4d3SLarry Finger 	case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
455f1d2b4d3SLarry Finger 		rtl92c_set_p2p_ps_offload_cmd(hw, *val);
456f1d2b4d3SLarry Finger 		break;
457f1d2b4d3SLarry Finger 	case HW_VAR_AID:{
458f1d2b4d3SLarry Finger 			u16 u2btmp;
459f1d2b4d3SLarry Finger 			u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
460f1d2b4d3SLarry Finger 			u2btmp &= 0xC000;
461f1d2b4d3SLarry Finger 			rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
462f1d2b4d3SLarry Finger 						mac->assoc_id));
463f1d2b4d3SLarry Finger 
464f1d2b4d3SLarry Finger 			break;
465f1d2b4d3SLarry Finger 		}
466f1d2b4d3SLarry Finger 	case HW_VAR_CORRECT_TSF:{
467f1d2b4d3SLarry Finger 			u8 btype_ibss = val[0];
468f1d2b4d3SLarry Finger 
469f1d2b4d3SLarry Finger 			if (btype_ibss)
470f1d2b4d3SLarry Finger 				_rtl92ce_stop_tx_beacon(hw);
471f1d2b4d3SLarry Finger 
472f1d2b4d3SLarry Finger 			_rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
473f1d2b4d3SLarry Finger 
474f1d2b4d3SLarry Finger 			rtl_write_dword(rtlpriv, REG_TSFTR,
475f1d2b4d3SLarry Finger 					(u32) (mac->tsf & 0xffffffff));
476f1d2b4d3SLarry Finger 			rtl_write_dword(rtlpriv, REG_TSFTR + 4,
477f1d2b4d3SLarry Finger 					(u32) ((mac->tsf >> 32) & 0xffffffff));
478f1d2b4d3SLarry Finger 
479f1d2b4d3SLarry Finger 			_rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
480f1d2b4d3SLarry Finger 
481f1d2b4d3SLarry Finger 			if (btype_ibss)
482f1d2b4d3SLarry Finger 				_rtl92ce_resume_tx_beacon(hw);
483f1d2b4d3SLarry Finger 
484f1d2b4d3SLarry Finger 			break;
485f1d2b4d3SLarry Finger 
486f1d2b4d3SLarry Finger 		}
487f1d2b4d3SLarry Finger 	case HW_VAR_FW_LPS_ACTION: {
488f1d2b4d3SLarry Finger 			bool enter_fwlps = *((bool *)val);
489f1d2b4d3SLarry Finger 			u8 rpwm_val, fw_pwrmode;
490f1d2b4d3SLarry Finger 			bool fw_current_inps;
491f1d2b4d3SLarry Finger 
492f1d2b4d3SLarry Finger 			if (enter_fwlps) {
493f1d2b4d3SLarry Finger 				rpwm_val = 0x02;	/* RF off */
494f1d2b4d3SLarry Finger 				fw_current_inps = true;
495f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
496f1d2b4d3SLarry Finger 						HW_VAR_FW_PSMODE_STATUS,
497f1d2b4d3SLarry Finger 						(u8 *)(&fw_current_inps));
498f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
499f1d2b4d3SLarry Finger 						HW_VAR_H2C_FW_PWRMODE,
500f1d2b4d3SLarry Finger 						&ppsc->fwctrl_psmode);
501f1d2b4d3SLarry Finger 
502f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
503f1d2b4d3SLarry Finger 							      HW_VAR_SET_RPWM,
504f1d2b4d3SLarry Finger 							      &rpwm_val);
505f1d2b4d3SLarry Finger 			} else {
506f1d2b4d3SLarry Finger 				rpwm_val = 0x0C;	/* RF on */
507f1d2b4d3SLarry Finger 				fw_pwrmode = FW_PS_ACTIVE_MODE;
508f1d2b4d3SLarry Finger 				fw_current_inps = false;
509f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
510f1d2b4d3SLarry Finger 							      HW_VAR_SET_RPWM,
511f1d2b4d3SLarry Finger 							      &rpwm_val);
512f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
513f1d2b4d3SLarry Finger 						HW_VAR_H2C_FW_PWRMODE,
514f1d2b4d3SLarry Finger 						&fw_pwrmode);
515f1d2b4d3SLarry Finger 
516f1d2b4d3SLarry Finger 				rtlpriv->cfg->ops->set_hw_reg(hw,
517f1d2b4d3SLarry Finger 						HW_VAR_FW_PSMODE_STATUS,
518f1d2b4d3SLarry Finger 						(u8 *)(&fw_current_inps));
519f1d2b4d3SLarry Finger 			}
520f1d2b4d3SLarry Finger 		break; }
521f1d2b4d3SLarry Finger 	case HW_VAR_KEEP_ALIVE: {
522f1d2b4d3SLarry Finger 		u8 array[2];
523f1d2b4d3SLarry Finger 
524f1d2b4d3SLarry Finger 		array[0] = 0xff;
525f1d2b4d3SLarry Finger 		array[1] = *((u8 *)val);
526f1d2b4d3SLarry Finger 		rtl92c_fill_h2c_cmd(hw, H2C_92C_KEEP_ALIVE_CTRL, 2, array);
527f1d2b4d3SLarry Finger 		break; }
528f1d2b4d3SLarry Finger 	default:
529e40a0056SLarry Finger 		pr_err("switch case %d not processed\n", variable);
530f1d2b4d3SLarry Finger 		break;
531f1d2b4d3SLarry Finger 	}
532f1d2b4d3SLarry Finger }
533f1d2b4d3SLarry Finger 
534f1d2b4d3SLarry Finger static bool _rtl92ce_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
535f1d2b4d3SLarry Finger {
536f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
537f1d2b4d3SLarry Finger 	bool status = true;
538f1d2b4d3SLarry Finger 	long count = 0;
539f1d2b4d3SLarry Finger 	u32 value = _LLT_INIT_ADDR(address) |
540f1d2b4d3SLarry Finger 	    _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
541f1d2b4d3SLarry Finger 
542f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
543f1d2b4d3SLarry Finger 
544f1d2b4d3SLarry Finger 	do {
545f1d2b4d3SLarry Finger 		value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
546f1d2b4d3SLarry Finger 		if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
547f1d2b4d3SLarry Finger 			break;
548f1d2b4d3SLarry Finger 
549f1d2b4d3SLarry Finger 		if (count > POLLING_LLT_THRESHOLD) {
550e40a0056SLarry Finger 			pr_err("Failed to polling write LLT done at address %d!\n",
551f1d2b4d3SLarry Finger 			       address);
552f1d2b4d3SLarry Finger 			status = false;
553f1d2b4d3SLarry Finger 			break;
554f1d2b4d3SLarry Finger 		}
555f1d2b4d3SLarry Finger 	} while (++count);
556f1d2b4d3SLarry Finger 
557f1d2b4d3SLarry Finger 	return status;
558f1d2b4d3SLarry Finger }
559f1d2b4d3SLarry Finger 
560f1d2b4d3SLarry Finger static bool _rtl92ce_llt_table_init(struct ieee80211_hw *hw)
561f1d2b4d3SLarry Finger {
562f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
563f1d2b4d3SLarry Finger 	unsigned short i;
564f1d2b4d3SLarry Finger 	u8 txpktbuf_bndy;
565ff970453SLarry Finger 	u8 maxpage;
566f1d2b4d3SLarry Finger 	bool status;
567f1d2b4d3SLarry Finger 
568f1d2b4d3SLarry Finger #if LLT_CONFIG == 1
569ff970453SLarry Finger 	maxpage = 255;
570f1d2b4d3SLarry Finger 	txpktbuf_bndy = 252;
571f1d2b4d3SLarry Finger #elif LLT_CONFIG == 2
572ff970453SLarry Finger 	maxpage = 127;
573f1d2b4d3SLarry Finger 	txpktbuf_bndy = 124;
574f1d2b4d3SLarry Finger #elif LLT_CONFIG == 3
575ff970453SLarry Finger 	maxpage = 255;
576f1d2b4d3SLarry Finger 	txpktbuf_bndy = 174;
577f1d2b4d3SLarry Finger #elif LLT_CONFIG == 4
578ff970453SLarry Finger 	maxpage = 255;
579f1d2b4d3SLarry Finger 	txpktbuf_bndy = 246;
580f1d2b4d3SLarry Finger #elif LLT_CONFIG == 5
581ff970453SLarry Finger 	maxpage = 255;
582f1d2b4d3SLarry Finger 	txpktbuf_bndy = 246;
583f1d2b4d3SLarry Finger #endif
584f1d2b4d3SLarry Finger 
585f1d2b4d3SLarry Finger #if LLT_CONFIG == 1
586f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c);
587f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c);
588f1d2b4d3SLarry Finger #elif LLT_CONFIG == 2
589f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010);
590f1d2b4d3SLarry Finger #elif LLT_CONFIG == 3
591f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484);
592f1d2b4d3SLarry Finger #elif LLT_CONFIG == 4
593f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c);
594f1d2b4d3SLarry Finger #elif LLT_CONFIG == 5
595f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
596f1d2b4d3SLarry Finger 
597f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RQPN, 0x80b01c29);
598f1d2b4d3SLarry Finger #endif
599f1d2b4d3SLarry Finger 
600f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
601f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
602f1d2b4d3SLarry Finger 
603f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
604f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
605f1d2b4d3SLarry Finger 
606f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
607f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_PBP, 0x11);
608f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
609f1d2b4d3SLarry Finger 
610f1d2b4d3SLarry Finger 	for (i = 0; i < (txpktbuf_bndy - 1); i++) {
611f1d2b4d3SLarry Finger 		status = _rtl92ce_llt_write(hw, i, i + 1);
612f1d2b4d3SLarry Finger 		if (true != status)
613f1d2b4d3SLarry Finger 			return status;
614f1d2b4d3SLarry Finger 	}
615f1d2b4d3SLarry Finger 
616f1d2b4d3SLarry Finger 	status = _rtl92ce_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
617f1d2b4d3SLarry Finger 	if (true != status)
618f1d2b4d3SLarry Finger 		return status;
619f1d2b4d3SLarry Finger 
620ff970453SLarry Finger 	for (i = txpktbuf_bndy; i < maxpage; i++) {
621f1d2b4d3SLarry Finger 		status = _rtl92ce_llt_write(hw, i, (i + 1));
622f1d2b4d3SLarry Finger 		if (true != status)
623f1d2b4d3SLarry Finger 			return status;
624f1d2b4d3SLarry Finger 	}
625f1d2b4d3SLarry Finger 
626ff970453SLarry Finger 	status = _rtl92ce_llt_write(hw, maxpage, txpktbuf_bndy);
627f1d2b4d3SLarry Finger 	if (true != status)
628f1d2b4d3SLarry Finger 		return status;
629f1d2b4d3SLarry Finger 
630f1d2b4d3SLarry Finger 	return true;
631f1d2b4d3SLarry Finger }
632f1d2b4d3SLarry Finger 
633f1d2b4d3SLarry Finger static void _rtl92ce_gen_refresh_led_state(struct ieee80211_hw *hw)
634f1d2b4d3SLarry Finger {
635d5efe153SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
636f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
637f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
638d5efe153SLarry Finger 	struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
639f1d2b4d3SLarry Finger 
640f1d2b4d3SLarry Finger 	if (rtlpci->up_first_time)
641f1d2b4d3SLarry Finger 		return;
642f1d2b4d3SLarry Finger 
643f1d2b4d3SLarry Finger 	if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
644d5efe153SLarry Finger 		rtl92ce_sw_led_on(hw, pled0);
645f1d2b4d3SLarry Finger 	else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
646d5efe153SLarry Finger 		rtl92ce_sw_led_on(hw, pled0);
647f1d2b4d3SLarry Finger 	else
648d5efe153SLarry Finger 		rtl92ce_sw_led_off(hw, pled0);
649f1d2b4d3SLarry Finger }
650f1d2b4d3SLarry Finger 
651f1d2b4d3SLarry Finger static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
652f1d2b4d3SLarry Finger {
653f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
654f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
655f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
656f1d2b4d3SLarry Finger 
657f1d2b4d3SLarry Finger 	unsigned char bytetmp;
658f1d2b4d3SLarry Finger 	unsigned short wordtmp;
659f1d2b4d3SLarry Finger 	u16 retry;
660f1d2b4d3SLarry Finger 
661f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
662d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence) {
663f1d2b4d3SLarry Finger 		u32 value32;
664f1d2b4d3SLarry Finger 		value32 = rtl_read_dword(rtlpriv, REG_APS_FSMCO);
665f1d2b4d3SLarry Finger 		value32 |= (SOP_ABG | SOP_AMB | XOP_BTCK);
666f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_APS_FSMCO, value32);
667f1d2b4d3SLarry Finger 	}
668f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
669f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
670f1d2b4d3SLarry Finger 
671d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence) {
672f1d2b4d3SLarry Finger 		u32 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
673f1d2b4d3SLarry Finger 
674f1d2b4d3SLarry Finger 		u4b_tmp &= (~0x00024800);
675f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
676f1d2b4d3SLarry Finger 	}
677f1d2b4d3SLarry Finger 
678f1d2b4d3SLarry Finger 	bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
679f1d2b4d3SLarry Finger 	udelay(2);
680f1d2b4d3SLarry Finger 
681f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
682f1d2b4d3SLarry Finger 	udelay(2);
683f1d2b4d3SLarry Finger 
684f1d2b4d3SLarry Finger 	bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
685f1d2b4d3SLarry Finger 	udelay(2);
686f1d2b4d3SLarry Finger 
687f1d2b4d3SLarry Finger 	retry = 0;
688f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
689f1d2b4d3SLarry Finger 		 rtl_read_dword(rtlpriv, 0xEC), bytetmp);
690f1d2b4d3SLarry Finger 
691f1d2b4d3SLarry Finger 	while ((bytetmp & BIT(0)) && retry < 1000) {
692f1d2b4d3SLarry Finger 		retry++;
693f1d2b4d3SLarry Finger 		udelay(50);
694f1d2b4d3SLarry Finger 		bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
695f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
696f1d2b4d3SLarry Finger 			 rtl_read_dword(rtlpriv, 0xEC), bytetmp);
697f1d2b4d3SLarry Finger 		udelay(50);
698f1d2b4d3SLarry Finger 	}
699f1d2b4d3SLarry Finger 
700f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x1012);
701f1d2b4d3SLarry Finger 
702f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
703f1d2b4d3SLarry Finger 	udelay(2);
704f1d2b4d3SLarry Finger 
705d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence) {
706f1d2b4d3SLarry Finger 		bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL+2) & 0xfd;
707f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL+2, bytetmp);
708f1d2b4d3SLarry Finger 	}
709f1d2b4d3SLarry Finger 
710f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_CR, 0x2ff);
711f1d2b4d3SLarry Finger 
712f1d2b4d3SLarry Finger 	if (!_rtl92ce_llt_table_init(hw))
713f1d2b4d3SLarry Finger 		return false;
714f1d2b4d3SLarry Finger 
715f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
716f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
717f1d2b4d3SLarry Finger 
718f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
719f1d2b4d3SLarry Finger 
720f1d2b4d3SLarry Finger 	wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
721f1d2b4d3SLarry Finger 	wordtmp &= 0xf;
722f1d2b4d3SLarry Finger 	wordtmp |= 0xF771;
723f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
724f1d2b4d3SLarry Finger 
725f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
726f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
727f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
728f1d2b4d3SLarry Finger 
729f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x4d0, 0x0);
730f1d2b4d3SLarry Finger 
731f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
732f1d2b4d3SLarry Finger 			((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
733f1d2b4d3SLarry Finger 			DMA_BIT_MASK(32));
734f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_MGQ_DESA,
735f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
736f1d2b4d3SLarry Finger 			DMA_BIT_MASK(32));
737f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_VOQ_DESA,
738f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
739f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_VIQ_DESA,
740f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
741f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_BEQ_DESA,
742f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
743f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_BKQ_DESA,
744f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
745f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HQ_DESA,
746f1d2b4d3SLarry Finger 			(u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
747f1d2b4d3SLarry Finger 			DMA_BIT_MASK(32));
748f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RX_DESA,
749f1d2b4d3SLarry Finger 			(u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
750f1d2b4d3SLarry Finger 			DMA_BIT_MASK(32));
751f1d2b4d3SLarry Finger 
752f1d2b4d3SLarry Finger 	if (IS_92C_SERIAL(rtlhal->version))
753f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x77);
754f1d2b4d3SLarry Finger 	else
755f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x22);
756f1d2b4d3SLarry Finger 
757f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
758f1d2b4d3SLarry Finger 
759f1d2b4d3SLarry Finger 	bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
760f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
761f1d2b4d3SLarry Finger 	do {
762f1d2b4d3SLarry Finger 		retry++;
763f1d2b4d3SLarry Finger 		bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
764f1d2b4d3SLarry Finger 	} while ((retry < 200) && (bytetmp & BIT(7)));
765f1d2b4d3SLarry Finger 
766f1d2b4d3SLarry Finger 	_rtl92ce_gen_refresh_led_state(hw);
767f1d2b4d3SLarry Finger 
768f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
769f1d2b4d3SLarry Finger 
770f1d2b4d3SLarry Finger 	return true;
771f1d2b4d3SLarry Finger }
772f1d2b4d3SLarry Finger 
773f1d2b4d3SLarry Finger static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
774f1d2b4d3SLarry Finger {
775f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
776f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
777f1d2b4d3SLarry Finger 	u8 reg_bw_opmode;
778f1d2b4d3SLarry Finger 	u32 reg_prsr;
779f1d2b4d3SLarry Finger 
780f1d2b4d3SLarry Finger 	reg_bw_opmode = BW_OPMODE_20MHZ;
781f1d2b4d3SLarry Finger 	reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
782f1d2b4d3SLarry Finger 
783f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
784f1d2b4d3SLarry Finger 
785f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
786f1d2b4d3SLarry Finger 
787f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
788f1d2b4d3SLarry Finger 
789f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
790f1d2b4d3SLarry Finger 
791f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
792f1d2b4d3SLarry Finger 
793f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
794f1d2b4d3SLarry Finger 
795f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_RL, 0x0707);
796f1d2b4d3SLarry Finger 
797f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
798f1d2b4d3SLarry Finger 
799f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
800f1d2b4d3SLarry Finger 
801f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
802f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
803f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
804f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
805f1d2b4d3SLarry Finger 
806d5efe153SLarry Finger 	if ((rtlpriv->btcoexist.bt_coexistence) &&
807d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4))
808f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
809f1d2b4d3SLarry Finger 	else
810f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
811f1d2b4d3SLarry Finger 
812f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
813f1d2b4d3SLarry Finger 
814f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
815f1d2b4d3SLarry Finger 
816f1d2b4d3SLarry Finger 	rtlpci->reg_bcn_ctrl_val = 0x1f;
817f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
818f1d2b4d3SLarry Finger 
819f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
820f1d2b4d3SLarry Finger 
821f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
822f1d2b4d3SLarry Finger 
823f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
824f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
825f1d2b4d3SLarry Finger 
826d5efe153SLarry Finger 	if ((rtlpriv->btcoexist.bt_coexistence) &&
827d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4)) {
828f1d2b4d3SLarry Finger 		rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
829f1d2b4d3SLarry Finger 		rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
830f1d2b4d3SLarry Finger 	} else {
831f1d2b4d3SLarry Finger 		rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
832f1d2b4d3SLarry Finger 		rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
833f1d2b4d3SLarry Finger 	}
834f1d2b4d3SLarry Finger 
835d5efe153SLarry Finger 	if ((rtlpriv->btcoexist.bt_coexistence) &&
836d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4))
837f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
838f1d2b4d3SLarry Finger 	else
839f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
840f1d2b4d3SLarry Finger 
841f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
842f1d2b4d3SLarry Finger 
843f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
844f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
845f1d2b4d3SLarry Finger 
846f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
847f1d2b4d3SLarry Finger 
848f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
849f1d2b4d3SLarry Finger 
850f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
851f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
852f1d2b4d3SLarry Finger 
853f1d2b4d3SLarry Finger }
854f1d2b4d3SLarry Finger 
855f1d2b4d3SLarry Finger static void _rtl92ce_enable_aspm_back_door(struct ieee80211_hw *hw)
856f1d2b4d3SLarry Finger {
857f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
858f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
859f1d2b4d3SLarry Finger 
860f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x34b, 0x93);
861f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, 0x350, 0x870c);
862f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x352, 0x1);
863f1d2b4d3SLarry Finger 
864f1d2b4d3SLarry Finger 	if (ppsc->support_backdoor)
865f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, 0x349, 0x1b);
866f1d2b4d3SLarry Finger 	else
867f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, 0x349, 0x03);
868f1d2b4d3SLarry Finger 
869f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, 0x350, 0x2718);
870f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x352, 0x1);
871f1d2b4d3SLarry Finger }
872f1d2b4d3SLarry Finger 
873f1d2b4d3SLarry Finger void rtl92ce_enable_hw_security_config(struct ieee80211_hw *hw)
874f1d2b4d3SLarry Finger {
875f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
876f1d2b4d3SLarry Finger 	u8 sec_reg_value;
877f1d2b4d3SLarry Finger 
878f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
879*0421dd41SColin Ian King 		 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
880f1d2b4d3SLarry Finger 		 rtlpriv->sec.pairwise_enc_algorithm,
881f1d2b4d3SLarry Finger 		 rtlpriv->sec.group_enc_algorithm);
882f1d2b4d3SLarry Finger 
883f1d2b4d3SLarry Finger 	if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
884f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
885f1d2b4d3SLarry Finger 			 "not open hw encryption\n");
886f1d2b4d3SLarry Finger 		return;
887f1d2b4d3SLarry Finger 	}
888f1d2b4d3SLarry Finger 
889ff970453SLarry Finger 	sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
890f1d2b4d3SLarry Finger 
891f1d2b4d3SLarry Finger 	if (rtlpriv->sec.use_defaultkey) {
892ff970453SLarry Finger 		sec_reg_value |= SCR_TXUSEDK;
893ff970453SLarry Finger 		sec_reg_value |= SCR_RXUSEDK;
894f1d2b4d3SLarry Finger 	}
895f1d2b4d3SLarry Finger 
896f1d2b4d3SLarry Finger 	sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
897f1d2b4d3SLarry Finger 
898f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
899f1d2b4d3SLarry Finger 
900f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
901f1d2b4d3SLarry Finger 		 "The SECR-value %x\n", sec_reg_value);
902f1d2b4d3SLarry Finger 
903f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
904f1d2b4d3SLarry Finger 
905f1d2b4d3SLarry Finger }
906f1d2b4d3SLarry Finger 
907f1d2b4d3SLarry Finger int rtl92ce_hw_init(struct ieee80211_hw *hw)
908f1d2b4d3SLarry Finger {
909f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
910f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
911f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
912f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
913f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
914f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
915f1d2b4d3SLarry Finger 	bool rtstatus = true;
916f1d2b4d3SLarry Finger 	bool is92c;
917f1d2b4d3SLarry Finger 	int err;
918f1d2b4d3SLarry Finger 	u8 tmp_u1b;
919f1d2b4d3SLarry Finger 	unsigned long flags;
920f1d2b4d3SLarry Finger 
921f1d2b4d3SLarry Finger 	rtlpci->being_init_adapter = true;
922f1d2b4d3SLarry Finger 
923f1d2b4d3SLarry Finger 	/* Since this function can take a very long time (up to 350 ms)
924f1d2b4d3SLarry Finger 	 * and can be called with irqs disabled, reenable the irqs
925f1d2b4d3SLarry Finger 	 * to let the other devices continue being serviced.
926f1d2b4d3SLarry Finger 	 *
927f1d2b4d3SLarry Finger 	 * It is safe doing so since our own interrupts will only be enabled
928f1d2b4d3SLarry Finger 	 * in a subsequent step.
929f1d2b4d3SLarry Finger 	 */
930f1d2b4d3SLarry Finger 	local_save_flags(flags);
931f1d2b4d3SLarry Finger 	local_irq_enable();
932f1d2b4d3SLarry Finger 
933f1d2b4d3SLarry Finger 	rtlhal->fw_ready = false;
934f1d2b4d3SLarry Finger 	rtlpriv->intf_ops->disable_aspm(hw);
935f1d2b4d3SLarry Finger 	rtstatus = _rtl92ce_init_mac(hw);
936f1d2b4d3SLarry Finger 	if (!rtstatus) {
937e40a0056SLarry Finger 		pr_err("Init MAC failed\n");
938f1d2b4d3SLarry Finger 		err = 1;
939f1d2b4d3SLarry Finger 		goto exit;
940f1d2b4d3SLarry Finger 	}
941f1d2b4d3SLarry Finger 
942f1d2b4d3SLarry Finger 	err = rtl92c_download_fw(hw);
943f1d2b4d3SLarry Finger 	if (err) {
944f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
945f1d2b4d3SLarry Finger 			 "Failed to download FW. Init HW without FW now..\n");
946f1d2b4d3SLarry Finger 		err = 1;
947f1d2b4d3SLarry Finger 		goto exit;
948f1d2b4d3SLarry Finger 	}
949f1d2b4d3SLarry Finger 
950f1d2b4d3SLarry Finger 	rtlhal->fw_ready = true;
951f1d2b4d3SLarry Finger 	rtlhal->last_hmeboxnum = 0;
952f1d2b4d3SLarry Finger 	rtl92c_phy_mac_config(hw);
953f1d2b4d3SLarry Finger 	/* because last function modify RCR, so we update
954f1d2b4d3SLarry Finger 	 * rcr var here, or TP will unstable for receive_config
955f1d2b4d3SLarry Finger 	 * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
956f1d2b4d3SLarry Finger 	 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252*/
957f1d2b4d3SLarry Finger 	rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
958f1d2b4d3SLarry Finger 	rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
959f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
960f1d2b4d3SLarry Finger 	rtl92c_phy_bb_config(hw);
961f1d2b4d3SLarry Finger 	rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
962f1d2b4d3SLarry Finger 	rtl92c_phy_rf_config(hw);
963f1d2b4d3SLarry Finger 	if (IS_VENDOR_UMC_A_CUT(rtlhal->version) &&
964f1d2b4d3SLarry Finger 	    !IS_92C_SERIAL(rtlhal->version)) {
965f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255);
966f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00);
967f1d2b4d3SLarry Finger 	} else if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version)) {
968f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, 0x0C, MASKDWORD, 0x894AE);
969f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, 0x0A, MASKDWORD, 0x1AF31);
970f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_IPA, MASKDWORD, 0x8F425);
971f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_SYN_G2, MASKDWORD, 0x4F200);
972f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK1, MASKDWORD, 0x44053);
973f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK2, MASKDWORD, 0x80201);
974f1d2b4d3SLarry Finger 	}
975f1d2b4d3SLarry Finger 	rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
976f1d2b4d3SLarry Finger 						 RF_CHNLBW, RFREG_OFFSET_MASK);
977f1d2b4d3SLarry Finger 	rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
978f1d2b4d3SLarry Finger 						 RF_CHNLBW, RFREG_OFFSET_MASK);
979f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
980f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
981f1d2b4d3SLarry Finger 	rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
982f1d2b4d3SLarry Finger 	_rtl92ce_hw_configure(hw);
983f1d2b4d3SLarry Finger 	rtl_cam_reset_all_entry(hw);
984f1d2b4d3SLarry Finger 	rtl92ce_enable_hw_security_config(hw);
985f1d2b4d3SLarry Finger 
986f1d2b4d3SLarry Finger 	ppsc->rfpwr_state = ERFON;
987f1d2b4d3SLarry Finger 
988f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
989f1d2b4d3SLarry Finger 	_rtl92ce_enable_aspm_back_door(hw);
990f1d2b4d3SLarry Finger 	rtlpriv->intf_ops->enable_aspm(hw);
991f1d2b4d3SLarry Finger 
992f1d2b4d3SLarry Finger 	rtl8192ce_bt_hw_init(hw);
993f1d2b4d3SLarry Finger 
994f1d2b4d3SLarry Finger 	if (ppsc->rfpwr_state == ERFON) {
995f1d2b4d3SLarry Finger 		rtl92c_phy_set_rfpath_switch(hw, 1);
996f1d2b4d3SLarry Finger 		if (rtlphy->iqk_initialized) {
997f1d2b4d3SLarry Finger 			rtl92c_phy_iq_calibrate(hw, true);
998f1d2b4d3SLarry Finger 		} else {
999f1d2b4d3SLarry Finger 			rtl92c_phy_iq_calibrate(hw, false);
1000f1d2b4d3SLarry Finger 			rtlphy->iqk_initialized = true;
1001f1d2b4d3SLarry Finger 		}
1002f1d2b4d3SLarry Finger 
1003f1d2b4d3SLarry Finger 		rtl92c_dm_check_txpower_tracking(hw);
1004f1d2b4d3SLarry Finger 		rtl92c_phy_lc_calibrate(hw);
1005f1d2b4d3SLarry Finger 	}
1006f1d2b4d3SLarry Finger 
1007f1d2b4d3SLarry Finger 	is92c = IS_92C_SERIAL(rtlhal->version);
1008f1d2b4d3SLarry Finger 	tmp_u1b = efuse_read_1byte(hw, 0x1FA);
1009f1d2b4d3SLarry Finger 	if (!(tmp_u1b & BIT(0))) {
1010f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
1011f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path A\n");
1012f1d2b4d3SLarry Finger 	}
1013f1d2b4d3SLarry Finger 
1014f1d2b4d3SLarry Finger 	if (!(tmp_u1b & BIT(1)) && is92c) {
1015f1d2b4d3SLarry Finger 		rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0F, 0x05);
1016f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path B\n");
1017f1d2b4d3SLarry Finger 	}
1018f1d2b4d3SLarry Finger 
1019f1d2b4d3SLarry Finger 	if (!(tmp_u1b & BIT(4))) {
1020f1d2b4d3SLarry Finger 		tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
1021f1d2b4d3SLarry Finger 		tmp_u1b &= 0x0F;
1022f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
1023f1d2b4d3SLarry Finger 		udelay(10);
1024f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
1025f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
1026f1d2b4d3SLarry Finger 	}
1027f1d2b4d3SLarry Finger 	rtl92c_dm_init(hw);
1028f1d2b4d3SLarry Finger exit:
1029f1d2b4d3SLarry Finger 	local_irq_restore(flags);
1030f1d2b4d3SLarry Finger 	rtlpci->being_init_adapter = false;
1031f1d2b4d3SLarry Finger 	return err;
1032f1d2b4d3SLarry Finger }
1033f1d2b4d3SLarry Finger 
1034f1d2b4d3SLarry Finger static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw)
1035f1d2b4d3SLarry Finger {
1036f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1037f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1038f1d2b4d3SLarry Finger 	enum version_8192c version = VERSION_UNKNOWN;
1039f1d2b4d3SLarry Finger 	u32 value32;
1040f1d2b4d3SLarry Finger 	const char *versionid;
1041f1d2b4d3SLarry Finger 
1042f1d2b4d3SLarry Finger 	value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
1043f1d2b4d3SLarry Finger 	if (value32 & TRP_VAUX_EN) {
1044f1d2b4d3SLarry Finger 		version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C :
1045f1d2b4d3SLarry Finger 			   VERSION_A_CHIP_88C;
1046f1d2b4d3SLarry Finger 	} else {
1047f1d2b4d3SLarry Finger 		version = (enum version_8192c) (CHIP_VER_B |
1048f1d2b4d3SLarry Finger 				((value32 & TYPE_ID) ? CHIP_92C_BITMASK : 0) |
1049f1d2b4d3SLarry Finger 				((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
1050f1d2b4d3SLarry Finger 		if ((!IS_CHIP_VENDOR_UMC(version)) && (value32 &
1051f1d2b4d3SLarry Finger 		     CHIP_VER_RTL_MASK)) {
1052f1d2b4d3SLarry Finger 			version = (enum version_8192c)(version |
1053f1d2b4d3SLarry Finger 				   ((((value32 & CHIP_VER_RTL_MASK) == BIT(12))
1054f1d2b4d3SLarry Finger 				   ? CHIP_VENDOR_UMC_B_CUT : CHIP_UNKNOWN) |
1055f1d2b4d3SLarry Finger 				   CHIP_VENDOR_UMC));
1056f1d2b4d3SLarry Finger 		}
1057f1d2b4d3SLarry Finger 		if (IS_92C_SERIAL(version)) {
1058f1d2b4d3SLarry Finger 			value32 = rtl_read_dword(rtlpriv, REG_HPON_FSM);
1059f1d2b4d3SLarry Finger 			version = (enum version_8192c)(version |
1060f1d2b4d3SLarry Finger 				   ((CHIP_BONDING_IDENTIFIER(value32)
1061f1d2b4d3SLarry Finger 				   == CHIP_BONDING_92C_1T2R) ?
1062f1d2b4d3SLarry Finger 				   RF_TYPE_1T2R : 0));
1063f1d2b4d3SLarry Finger 		}
1064f1d2b4d3SLarry Finger 	}
1065f1d2b4d3SLarry Finger 
1066f1d2b4d3SLarry Finger 	switch (version) {
1067f1d2b4d3SLarry Finger 	case VERSION_B_CHIP_92C:
1068f1d2b4d3SLarry Finger 		versionid = "B_CHIP_92C";
1069f1d2b4d3SLarry Finger 		break;
1070f1d2b4d3SLarry Finger 	case VERSION_B_CHIP_88C:
1071f1d2b4d3SLarry Finger 		versionid = "B_CHIP_88C";
1072f1d2b4d3SLarry Finger 		break;
1073f1d2b4d3SLarry Finger 	case VERSION_A_CHIP_92C:
1074f1d2b4d3SLarry Finger 		versionid = "A_CHIP_92C";
1075f1d2b4d3SLarry Finger 		break;
1076f1d2b4d3SLarry Finger 	case VERSION_A_CHIP_88C:
1077f1d2b4d3SLarry Finger 		versionid = "A_CHIP_88C";
1078f1d2b4d3SLarry Finger 		break;
1079f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_92C_1T2R_A_CUT:
1080f1d2b4d3SLarry Finger 		versionid = "A_CUT_92C_1T2R";
1081f1d2b4d3SLarry Finger 		break;
1082f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_92C_A_CUT:
1083f1d2b4d3SLarry Finger 		versionid = "A_CUT_92C";
1084f1d2b4d3SLarry Finger 		break;
1085f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_88C_A_CUT:
1086f1d2b4d3SLarry Finger 		versionid = "A_CUT_88C";
1087f1d2b4d3SLarry Finger 		break;
1088f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_92C_1T2R_B_CUT:
1089f1d2b4d3SLarry Finger 		versionid = "B_CUT_92C_1T2R";
1090f1d2b4d3SLarry Finger 		break;
1091f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_92C_B_CUT:
1092f1d2b4d3SLarry Finger 		versionid = "B_CUT_92C";
1093f1d2b4d3SLarry Finger 		break;
1094f1d2b4d3SLarry Finger 	case VERSION_NORMAL_UMC_CHIP_88C_B_CUT:
1095f1d2b4d3SLarry Finger 		versionid = "B_CUT_88C";
1096f1d2b4d3SLarry Finger 		break;
1097f1d2b4d3SLarry Finger 	default:
1098f1d2b4d3SLarry Finger 		versionid = "Unknown. Bug?";
1099f1d2b4d3SLarry Finger 		break;
1100f1d2b4d3SLarry Finger 	}
1101f1d2b4d3SLarry Finger 
1102e40a0056SLarry Finger 	pr_info("Chip Version ID: %s\n", versionid);
1103f1d2b4d3SLarry Finger 
1104f1d2b4d3SLarry Finger 	switch (version & 0x3) {
1105f1d2b4d3SLarry Finger 	case CHIP_88C:
1106f1d2b4d3SLarry Finger 		rtlphy->rf_type = RF_1T1R;
1107f1d2b4d3SLarry Finger 		break;
1108f1d2b4d3SLarry Finger 	case CHIP_92C:
1109f1d2b4d3SLarry Finger 		rtlphy->rf_type = RF_2T2R;
1110f1d2b4d3SLarry Finger 		break;
1111f1d2b4d3SLarry Finger 	case CHIP_92C_1T2R:
1112f1d2b4d3SLarry Finger 		rtlphy->rf_type = RF_1T2R;
1113f1d2b4d3SLarry Finger 		break;
1114f1d2b4d3SLarry Finger 	default:
1115f1d2b4d3SLarry Finger 		rtlphy->rf_type = RF_1T1R;
1116e40a0056SLarry Finger 		pr_err("ERROR RF_Type is set!!\n");
1117f1d2b4d3SLarry Finger 		break;
1118f1d2b4d3SLarry Finger 	}
1119f1d2b4d3SLarry Finger 
1120f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n",
1121f1d2b4d3SLarry Finger 		 rtlphy->rf_type == RF_2T2R ? "RF_2T2R" : "RF_1T1R");
1122f1d2b4d3SLarry Finger 
1123f1d2b4d3SLarry Finger 	return version;
1124f1d2b4d3SLarry Finger }
1125f1d2b4d3SLarry Finger 
1126f1d2b4d3SLarry Finger static int _rtl92ce_set_media_status(struct ieee80211_hw *hw,
1127f1d2b4d3SLarry Finger 				     enum nl80211_iftype type)
1128f1d2b4d3SLarry Finger {
1129f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1130f1d2b4d3SLarry Finger 	u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
1131f1d2b4d3SLarry Finger 	enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
1132f1d2b4d3SLarry Finger 	u8 mode = MSR_NOLINK;
1133f1d2b4d3SLarry Finger 
1134f1d2b4d3SLarry Finger 	bt_msr &= 0xfc;
1135f1d2b4d3SLarry Finger 
1136f1d2b4d3SLarry Finger 	switch (type) {
1137f1d2b4d3SLarry Finger 	case NL80211_IFTYPE_UNSPECIFIED:
1138f1d2b4d3SLarry Finger 		mode = MSR_NOLINK;
1139f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1140f1d2b4d3SLarry Finger 			 "Set Network type to NO LINK!\n");
1141f1d2b4d3SLarry Finger 		break;
1142f1d2b4d3SLarry Finger 	case NL80211_IFTYPE_ADHOC:
1143f1d2b4d3SLarry Finger 		mode = MSR_ADHOC;
1144f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1145f1d2b4d3SLarry Finger 			 "Set Network type to Ad Hoc!\n");
1146f1d2b4d3SLarry Finger 		break;
1147f1d2b4d3SLarry Finger 	case NL80211_IFTYPE_STATION:
1148f1d2b4d3SLarry Finger 		mode = MSR_INFRA;
1149f1d2b4d3SLarry Finger 		ledaction = LED_CTL_LINK;
1150f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1151f1d2b4d3SLarry Finger 			 "Set Network type to STA!\n");
1152f1d2b4d3SLarry Finger 		break;
1153f1d2b4d3SLarry Finger 	case NL80211_IFTYPE_AP:
1154f1d2b4d3SLarry Finger 		mode = MSR_AP;
1155f1d2b4d3SLarry Finger 		ledaction = LED_CTL_LINK;
1156f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1157f1d2b4d3SLarry Finger 			 "Set Network type to AP!\n");
1158f1d2b4d3SLarry Finger 		break;
1159f1d2b4d3SLarry Finger 	case NL80211_IFTYPE_MESH_POINT:
1160f1d2b4d3SLarry Finger 		mode = MSR_ADHOC;
1161f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1162f1d2b4d3SLarry Finger 			 "Set Network type to Mesh Point!\n");
1163f1d2b4d3SLarry Finger 		break;
1164f1d2b4d3SLarry Finger 	default:
1165e40a0056SLarry Finger 		pr_err("Network type %d not supported!\n", type);
1166f1d2b4d3SLarry Finger 		return 1;
1167f1d2b4d3SLarry Finger 
1168f1d2b4d3SLarry Finger 	}
1169f1d2b4d3SLarry Finger 
1170f1d2b4d3SLarry Finger 	/* MSR_INFRA == Link in infrastructure network;
1171f1d2b4d3SLarry Finger 	 * MSR_ADHOC == Link in ad hoc network;
1172f1d2b4d3SLarry Finger 	 * Therefore, check link state is necessary.
1173f1d2b4d3SLarry Finger 	 *
1174f1d2b4d3SLarry Finger 	 * MSR_AP == AP mode; link state does not matter here.
1175f1d2b4d3SLarry Finger 	 */
1176f1d2b4d3SLarry Finger 	if (mode != MSR_AP &&
1177f1d2b4d3SLarry Finger 	    rtlpriv->mac80211.link_state < MAC80211_LINKED) {
1178f1d2b4d3SLarry Finger 		mode = MSR_NOLINK;
1179f1d2b4d3SLarry Finger 		ledaction = LED_CTL_NO_LINK;
1180f1d2b4d3SLarry Finger 	}
1181f1d2b4d3SLarry Finger 	if (mode == MSR_NOLINK || mode == MSR_INFRA) {
1182f1d2b4d3SLarry Finger 		_rtl92ce_stop_tx_beacon(hw);
1183f1d2b4d3SLarry Finger 		_rtl92ce_enable_bcn_sub_func(hw);
1184f1d2b4d3SLarry Finger 	} else if (mode == MSR_ADHOC || mode == MSR_AP) {
1185f1d2b4d3SLarry Finger 		_rtl92ce_resume_tx_beacon(hw);
1186f1d2b4d3SLarry Finger 		_rtl92ce_disable_bcn_sub_func(hw);
1187f1d2b4d3SLarry Finger 	} else {
1188f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1189f1d2b4d3SLarry Finger 			 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1190f1d2b4d3SLarry Finger 			 mode);
1191f1d2b4d3SLarry Finger 	}
1192f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, MSR, bt_msr | mode);
1193f1d2b4d3SLarry Finger 
1194f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->led_control(hw, ledaction);
1195f1d2b4d3SLarry Finger 	if (mode == MSR_AP)
1196f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
1197f1d2b4d3SLarry Finger 	else
1198f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
1199f1d2b4d3SLarry Finger 	return 0;
1200f1d2b4d3SLarry Finger }
1201f1d2b4d3SLarry Finger 
1202f1d2b4d3SLarry Finger void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1203f1d2b4d3SLarry Finger {
1204f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1205f1d2b4d3SLarry Finger 	u32 reg_rcr;
1206f1d2b4d3SLarry Finger 
1207f1d2b4d3SLarry Finger 	if (rtlpriv->psc.rfpwr_state != ERFON)
1208f1d2b4d3SLarry Finger 		return;
1209f1d2b4d3SLarry Finger 
1210f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
1211f1d2b4d3SLarry Finger 
1212f1d2b4d3SLarry Finger 	if (check_bssid) {
1213f1d2b4d3SLarry Finger 		reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1214f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1215f1d2b4d3SLarry Finger 					      (u8 *) (&reg_rcr));
1216f1d2b4d3SLarry Finger 		_rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
1217f1d2b4d3SLarry Finger 	} else if (!check_bssid) {
1218f1d2b4d3SLarry Finger 		reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1219f1d2b4d3SLarry Finger 		_rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
1220f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->set_hw_reg(hw,
1221f1d2b4d3SLarry Finger 					      HW_VAR_RCR, (u8 *) (&reg_rcr));
1222f1d2b4d3SLarry Finger 	}
1223f1d2b4d3SLarry Finger 
1224f1d2b4d3SLarry Finger }
1225f1d2b4d3SLarry Finger 
1226f1d2b4d3SLarry Finger int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
1227f1d2b4d3SLarry Finger {
1228f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1229f1d2b4d3SLarry Finger 
1230f1d2b4d3SLarry Finger 	if (_rtl92ce_set_media_status(hw, type))
1231f1d2b4d3SLarry Finger 		return -EOPNOTSUPP;
1232f1d2b4d3SLarry Finger 
1233f1d2b4d3SLarry Finger 	if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1234f1d2b4d3SLarry Finger 		if (type != NL80211_IFTYPE_AP &&
1235f1d2b4d3SLarry Finger 		    type != NL80211_IFTYPE_MESH_POINT)
1236f1d2b4d3SLarry Finger 			rtl92ce_set_check_bssid(hw, true);
1237f1d2b4d3SLarry Finger 	} else {
1238f1d2b4d3SLarry Finger 		rtl92ce_set_check_bssid(hw, false);
1239f1d2b4d3SLarry Finger 	}
1240f1d2b4d3SLarry Finger 
1241f1d2b4d3SLarry Finger 	return 0;
1242f1d2b4d3SLarry Finger }
1243f1d2b4d3SLarry Finger 
1244f1d2b4d3SLarry Finger /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1245f1d2b4d3SLarry Finger void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci)
1246f1d2b4d3SLarry Finger {
1247f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1248f1d2b4d3SLarry Finger 	rtl92c_dm_init_edca_turbo(hw);
1249f1d2b4d3SLarry Finger 	switch (aci) {
1250f1d2b4d3SLarry Finger 	case AC1_BK:
1251f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1252f1d2b4d3SLarry Finger 		break;
1253f1d2b4d3SLarry Finger 	case AC0_BE:
1254f1d2b4d3SLarry Finger 		/* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
1255f1d2b4d3SLarry Finger 		break;
1256f1d2b4d3SLarry Finger 	case AC2_VI:
1257f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1258f1d2b4d3SLarry Finger 		break;
1259f1d2b4d3SLarry Finger 	case AC3_VO:
1260f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1261f1d2b4d3SLarry Finger 		break;
1262f1d2b4d3SLarry Finger 	default:
1263531940f9SLarry Finger 		WARN_ONCE(true, "rtl8192ce: invalid aci: %d !\n", aci);
1264f1d2b4d3SLarry Finger 		break;
1265f1d2b4d3SLarry Finger 	}
1266f1d2b4d3SLarry Finger }
1267f1d2b4d3SLarry Finger 
1268f1d2b4d3SLarry Finger void rtl92ce_enable_interrupt(struct ieee80211_hw *hw)
1269f1d2b4d3SLarry Finger {
1270f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1271f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1272f1d2b4d3SLarry Finger 
1273f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
1274f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
1275f1d2b4d3SLarry Finger 	rtlpci->irq_enabled = true;
1276f1d2b4d3SLarry Finger }
1277f1d2b4d3SLarry Finger 
1278f1d2b4d3SLarry Finger void rtl92ce_disable_interrupt(struct ieee80211_hw *hw)
1279f1d2b4d3SLarry Finger {
1280f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1281f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1282f1d2b4d3SLarry Finger 
1283f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
1284f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
1285f1d2b4d3SLarry Finger 	rtlpci->irq_enabled = false;
1286f1d2b4d3SLarry Finger }
1287f1d2b4d3SLarry Finger 
1288f1d2b4d3SLarry Finger static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
1289f1d2b4d3SLarry Finger {
1290f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1291f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1292f1d2b4d3SLarry Finger 	u8 u1b_tmp;
1293f1d2b4d3SLarry Finger 	u32 u4b_tmp;
1294f1d2b4d3SLarry Finger 
1295f1d2b4d3SLarry Finger 	rtlpriv->intf_ops->enable_aspm(hw);
1296f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
1297f1d2b4d3SLarry Finger 	rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
1298f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
1299f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
1300f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1301f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE0);
1302f1d2b4d3SLarry Finger 	if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7))
1303f1d2b4d3SLarry Finger 		rtl92c_firmware_selfreset(hw);
1304f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x51);
1305f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1306f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
1307f1d2b4d3SLarry Finger 	u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
1308d5efe153SLarry Finger 	if ((rtlpriv->btcoexist.bt_coexistence) &&
1309d5efe153SLarry Finger 	    ((rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) ||
1310d5efe153SLarry Finger 	     (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC8))) {
1311f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00F30000 |
1312f1d2b4d3SLarry Finger 				(u1b_tmp << 8));
1313f1d2b4d3SLarry Finger 	} else {
1314f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 |
1315f1d2b4d3SLarry Finger 				(u1b_tmp << 8));
1316f1d2b4d3SLarry Finger 	}
1317f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
1318f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
1319f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
1320f1d2b4d3SLarry Finger 	if (!IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version))
1321f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
1322d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence) {
1323f1d2b4d3SLarry Finger 		u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
1324f1d2b4d3SLarry Finger 		u4b_tmp |= 0x03824800;
1325f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
1326f1d2b4d3SLarry Finger 	} else {
1327f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
1328f1d2b4d3SLarry Finger 	}
1329f1d2b4d3SLarry Finger 
1330f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1331f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
1332f1d2b4d3SLarry Finger }
1333f1d2b4d3SLarry Finger 
1334f1d2b4d3SLarry Finger void rtl92ce_card_disable(struct ieee80211_hw *hw)
1335f1d2b4d3SLarry Finger {
1336f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1337f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1338f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1339f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1340f1d2b4d3SLarry Finger 	enum nl80211_iftype opmode;
1341f1d2b4d3SLarry Finger 
1342f1d2b4d3SLarry Finger 	mac->link_state = MAC80211_NOLINK;
1343f1d2b4d3SLarry Finger 	opmode = NL80211_IFTYPE_UNSPECIFIED;
1344f1d2b4d3SLarry Finger 	_rtl92ce_set_media_status(hw, opmode);
1345f1d2b4d3SLarry Finger 	if (rtlpci->driver_is_goingto_unload ||
1346f1d2b4d3SLarry Finger 	    ppsc->rfoff_reason > RF_CHANGE_BY_PS)
1347f1d2b4d3SLarry Finger 		rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
1348f1d2b4d3SLarry Finger 	RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
1349f1d2b4d3SLarry Finger 	_rtl92ce_poweroff_adapter(hw);
1350f1d2b4d3SLarry Finger 
1351f1d2b4d3SLarry Finger 	/* after power off we should do iqk again */
1352f1d2b4d3SLarry Finger 	rtlpriv->phy.iqk_initialized = false;
1353f1d2b4d3SLarry Finger }
1354f1d2b4d3SLarry Finger 
1355f1d2b4d3SLarry Finger void rtl92ce_interrupt_recognized(struct ieee80211_hw *hw,
135678aa6012SLarry Finger 				  struct rtl_int *intvec)
1357f1d2b4d3SLarry Finger {
1358f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1359f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1360f1d2b4d3SLarry Finger 
136178aa6012SLarry Finger 	intvec->inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
136278aa6012SLarry Finger 	rtl_write_dword(rtlpriv, ISR, intvec->inta);
1363f1d2b4d3SLarry Finger }
1364f1d2b4d3SLarry Finger 
1365f1d2b4d3SLarry Finger void rtl92ce_set_beacon_related_registers(struct ieee80211_hw *hw)
1366f1d2b4d3SLarry Finger {
1367f1d2b4d3SLarry Finger 
1368f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1369f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1370f1d2b4d3SLarry Finger 	u16 bcn_interval, atim_window;
1371f1d2b4d3SLarry Finger 
1372f1d2b4d3SLarry Finger 	bcn_interval = mac->beacon_interval;
1373f1d2b4d3SLarry Finger 	atim_window = 2;	/*FIX MERGE */
1374f1d2b4d3SLarry Finger 	rtl92ce_disable_interrupt(hw);
1375f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
1376f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1377f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
1378f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
1379f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
1380f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, 0x606, 0x30);
1381f1d2b4d3SLarry Finger 	rtl92ce_enable_interrupt(hw);
1382f1d2b4d3SLarry Finger }
1383f1d2b4d3SLarry Finger 
1384f1d2b4d3SLarry Finger void rtl92ce_set_beacon_interval(struct ieee80211_hw *hw)
1385f1d2b4d3SLarry Finger {
1386f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1387f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1388f1d2b4d3SLarry Finger 	u16 bcn_interval = mac->beacon_interval;
1389f1d2b4d3SLarry Finger 
1390f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
1391f1d2b4d3SLarry Finger 		 "beacon_interval:%d\n", bcn_interval);
1392f1d2b4d3SLarry Finger 	rtl92ce_disable_interrupt(hw);
1393f1d2b4d3SLarry Finger 	rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1394f1d2b4d3SLarry Finger 	rtl92ce_enable_interrupt(hw);
1395f1d2b4d3SLarry Finger }
1396f1d2b4d3SLarry Finger 
1397f1d2b4d3SLarry Finger void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw,
1398f1d2b4d3SLarry Finger 				   u32 add_msr, u32 rm_msr)
1399f1d2b4d3SLarry Finger {
1400f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1401f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1402f1d2b4d3SLarry Finger 
1403f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n",
1404f1d2b4d3SLarry Finger 		 add_msr, rm_msr);
1405f1d2b4d3SLarry Finger 
1406f1d2b4d3SLarry Finger 	if (add_msr)
1407f1d2b4d3SLarry Finger 		rtlpci->irq_mask[0] |= add_msr;
1408f1d2b4d3SLarry Finger 	if (rm_msr)
1409f1d2b4d3SLarry Finger 		rtlpci->irq_mask[0] &= (~rm_msr);
1410f1d2b4d3SLarry Finger 	rtl92ce_disable_interrupt(hw);
1411f1d2b4d3SLarry Finger 	rtl92ce_enable_interrupt(hw);
1412f1d2b4d3SLarry Finger }
1413f1d2b4d3SLarry Finger 
1414f1d2b4d3SLarry Finger static void _rtl92ce_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
1415f1d2b4d3SLarry Finger 						 bool autoload_fail,
1416f1d2b4d3SLarry Finger 						 u8 *hwinfo)
1417f1d2b4d3SLarry Finger {
1418f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1419f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1420f1d2b4d3SLarry Finger 	u8 rf_path, index, tempval;
1421f1d2b4d3SLarry Finger 	u16 i;
1422f1d2b4d3SLarry Finger 
1423f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++) {
1424f1d2b4d3SLarry Finger 		for (i = 0; i < 3; i++) {
1425f1d2b4d3SLarry Finger 			if (!autoload_fail) {
1426f1d2b4d3SLarry Finger 				rtlefuse->
1427f1d2b4d3SLarry Finger 				    eeprom_chnlarea_txpwr_cck[rf_path][i] =
1428f1d2b4d3SLarry Finger 				    hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
1429f1d2b4d3SLarry Finger 				rtlefuse->
1430f1d2b4d3SLarry Finger 				    eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1431f1d2b4d3SLarry Finger 				    hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 +
1432f1d2b4d3SLarry Finger 					   i];
1433f1d2b4d3SLarry Finger 			} else {
1434f1d2b4d3SLarry Finger 				rtlefuse->
1435f1d2b4d3SLarry Finger 				    eeprom_chnlarea_txpwr_cck[rf_path][i] =
1436f1d2b4d3SLarry Finger 				    EEPROM_DEFAULT_TXPOWERLEVEL;
1437f1d2b4d3SLarry Finger 				rtlefuse->
1438f1d2b4d3SLarry Finger 				    eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1439f1d2b4d3SLarry Finger 				    EEPROM_DEFAULT_TXPOWERLEVEL;
1440f1d2b4d3SLarry Finger 			}
1441f1d2b4d3SLarry Finger 		}
1442f1d2b4d3SLarry Finger 	}
1443f1d2b4d3SLarry Finger 
1444f1d2b4d3SLarry Finger 	for (i = 0; i < 3; i++) {
1445f1d2b4d3SLarry Finger 		if (!autoload_fail)
1446f1d2b4d3SLarry Finger 			tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
1447f1d2b4d3SLarry Finger 		else
1448f1d2b4d3SLarry Finger 			tempval = EEPROM_DEFAULT_HT40_2SDIFF;
1449f1d2b4d3SLarry Finger 		rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] =
1450f1d2b4d3SLarry Finger 		    (tempval & 0xf);
1451f1d2b4d3SLarry Finger 		rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] =
1452f1d2b4d3SLarry Finger 		    ((tempval & 0xf0) >> 4);
1453f1d2b4d3SLarry Finger 	}
1454f1d2b4d3SLarry Finger 
1455f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++)
1456f1d2b4d3SLarry Finger 		for (i = 0; i < 3; i++)
1457f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1458f1d2b4d3SLarry Finger 				"RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
1459f1d2b4d3SLarry Finger 				rf_path, i,
1460f1d2b4d3SLarry Finger 				rtlefuse->
1461f1d2b4d3SLarry Finger 				eeprom_chnlarea_txpwr_cck[rf_path][i]);
1462f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++)
1463f1d2b4d3SLarry Finger 		for (i = 0; i < 3; i++)
1464f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1465f1d2b4d3SLarry Finger 				"RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1466f1d2b4d3SLarry Finger 				rf_path, i,
1467f1d2b4d3SLarry Finger 				rtlefuse->
1468f1d2b4d3SLarry Finger 				eeprom_chnlarea_txpwr_ht40_1s[rf_path][i]);
1469f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++)
1470f1d2b4d3SLarry Finger 		for (i = 0; i < 3; i++)
1471f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1472f1d2b4d3SLarry Finger 				"RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1473f1d2b4d3SLarry Finger 				rf_path, i,
1474f1d2b4d3SLarry Finger 				rtlefuse->
1475f1d2b4d3SLarry Finger 				eprom_chnl_txpwr_ht40_2sdf[rf_path][i]);
1476f1d2b4d3SLarry Finger 
1477f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++) {
1478f1d2b4d3SLarry Finger 		for (i = 0; i < 14; i++) {
1479f1d2b4d3SLarry Finger 			index = rtl92c_get_chnl_group((u8)i);
1480f1d2b4d3SLarry Finger 
1481f1d2b4d3SLarry Finger 			rtlefuse->txpwrlevel_cck[rf_path][i] =
1482f1d2b4d3SLarry Finger 			    rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][index];
1483f1d2b4d3SLarry Finger 			rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
1484f1d2b4d3SLarry Finger 			    rtlefuse->
1485f1d2b4d3SLarry Finger 			    eeprom_chnlarea_txpwr_ht40_1s[rf_path][index];
1486f1d2b4d3SLarry Finger 
1487f1d2b4d3SLarry Finger 			if ((rtlefuse->
1488f1d2b4d3SLarry Finger 			     eeprom_chnlarea_txpwr_ht40_1s[rf_path][index] -
1489f1d2b4d3SLarry Finger 			     rtlefuse->
1490f1d2b4d3SLarry Finger 			     eprom_chnl_txpwr_ht40_2sdf[rf_path][index])
1491f1d2b4d3SLarry Finger 			    > 0) {
1492f1d2b4d3SLarry Finger 				rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
1493f1d2b4d3SLarry Finger 				    rtlefuse->
1494f1d2b4d3SLarry Finger 				    eeprom_chnlarea_txpwr_ht40_1s[rf_path]
1495f1d2b4d3SLarry Finger 				    [index] -
1496f1d2b4d3SLarry Finger 				    rtlefuse->
1497f1d2b4d3SLarry Finger 				    eprom_chnl_txpwr_ht40_2sdf[rf_path]
1498f1d2b4d3SLarry Finger 				    [index];
1499f1d2b4d3SLarry Finger 			} else {
1500f1d2b4d3SLarry Finger 				rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
1501f1d2b4d3SLarry Finger 			}
1502f1d2b4d3SLarry Finger 		}
1503f1d2b4d3SLarry Finger 
1504f1d2b4d3SLarry Finger 		for (i = 0; i < 14; i++) {
1505f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1506f1d2b4d3SLarry Finger 				"RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
1507f1d2b4d3SLarry Finger 				rf_path, i,
1508f1d2b4d3SLarry Finger 				rtlefuse->txpwrlevel_cck[rf_path][i],
1509f1d2b4d3SLarry Finger 				rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
1510f1d2b4d3SLarry Finger 				rtlefuse->txpwrlevel_ht40_2s[rf_path][i]);
1511f1d2b4d3SLarry Finger 		}
1512f1d2b4d3SLarry Finger 	}
1513f1d2b4d3SLarry Finger 
1514f1d2b4d3SLarry Finger 	for (i = 0; i < 3; i++) {
1515f1d2b4d3SLarry Finger 		if (!autoload_fail) {
1516f1d2b4d3SLarry Finger 			rtlefuse->eeprom_pwrlimit_ht40[i] =
1517f1d2b4d3SLarry Finger 			    hwinfo[EEPROM_TXPWR_GROUP + i];
1518f1d2b4d3SLarry Finger 			rtlefuse->eeprom_pwrlimit_ht20[i] =
1519f1d2b4d3SLarry Finger 			    hwinfo[EEPROM_TXPWR_GROUP + 3 + i];
1520f1d2b4d3SLarry Finger 		} else {
1521f1d2b4d3SLarry Finger 			rtlefuse->eeprom_pwrlimit_ht40[i] = 0;
1522f1d2b4d3SLarry Finger 			rtlefuse->eeprom_pwrlimit_ht20[i] = 0;
1523f1d2b4d3SLarry Finger 		}
1524f1d2b4d3SLarry Finger 	}
1525f1d2b4d3SLarry Finger 
1526f1d2b4d3SLarry Finger 	for (rf_path = 0; rf_path < 2; rf_path++) {
1527f1d2b4d3SLarry Finger 		for (i = 0; i < 14; i++) {
1528f1d2b4d3SLarry Finger 			index = rtl92c_get_chnl_group((u8)i);
1529f1d2b4d3SLarry Finger 
1530f1d2b4d3SLarry Finger 			if (rf_path == RF90_PATH_A) {
1531f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht20[rf_path][i] =
1532f1d2b4d3SLarry Finger 				    (rtlefuse->eeprom_pwrlimit_ht20[index]
1533f1d2b4d3SLarry Finger 				     & 0xf);
1534f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht40[rf_path][i] =
1535f1d2b4d3SLarry Finger 				    (rtlefuse->eeprom_pwrlimit_ht40[index]
1536f1d2b4d3SLarry Finger 				     & 0xf);
1537f1d2b4d3SLarry Finger 			} else if (rf_path == RF90_PATH_B) {
1538f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht20[rf_path][i] =
1539f1d2b4d3SLarry Finger 				    ((rtlefuse->eeprom_pwrlimit_ht20[index]
1540f1d2b4d3SLarry Finger 				      & 0xf0) >> 4);
1541f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht40[rf_path][i] =
1542f1d2b4d3SLarry Finger 				    ((rtlefuse->eeprom_pwrlimit_ht40[index]
1543f1d2b4d3SLarry Finger 				      & 0xf0) >> 4);
1544f1d2b4d3SLarry Finger 			}
1545f1d2b4d3SLarry Finger 
1546f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1547f1d2b4d3SLarry Finger 				"RF-%d pwrgroup_ht20[%d] = 0x%x\n",
1548f1d2b4d3SLarry Finger 				rf_path, i,
1549f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht20[rf_path][i]);
1550f1d2b4d3SLarry Finger 			RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1551f1d2b4d3SLarry Finger 				"RF-%d pwrgroup_ht40[%d] = 0x%x\n",
1552f1d2b4d3SLarry Finger 				rf_path, i,
1553f1d2b4d3SLarry Finger 				rtlefuse->pwrgroup_ht40[rf_path][i]);
1554f1d2b4d3SLarry Finger 		}
1555f1d2b4d3SLarry Finger 	}
1556f1d2b4d3SLarry Finger 
1557f1d2b4d3SLarry Finger 	for (i = 0; i < 14; i++) {
1558f1d2b4d3SLarry Finger 		index = rtl92c_get_chnl_group((u8)i);
1559f1d2b4d3SLarry Finger 
1560f1d2b4d3SLarry Finger 		if (!autoload_fail)
1561f1d2b4d3SLarry Finger 			tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
1562f1d2b4d3SLarry Finger 		else
1563f1d2b4d3SLarry Finger 			tempval = EEPROM_DEFAULT_HT20_DIFF;
1564f1d2b4d3SLarry Finger 
1565f1d2b4d3SLarry Finger 		rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
1566f1d2b4d3SLarry Finger 		rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
1567f1d2b4d3SLarry Finger 		    ((tempval >> 4) & 0xF);
1568f1d2b4d3SLarry Finger 
1569f1d2b4d3SLarry Finger 		if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
1570f1d2b4d3SLarry Finger 			rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
1571f1d2b4d3SLarry Finger 
1572f1d2b4d3SLarry Finger 		if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
1573f1d2b4d3SLarry Finger 			rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
1574f1d2b4d3SLarry Finger 
1575f1d2b4d3SLarry Finger 		index = rtl92c_get_chnl_group((u8)i);
1576f1d2b4d3SLarry Finger 
1577f1d2b4d3SLarry Finger 		if (!autoload_fail)
1578f1d2b4d3SLarry Finger 			tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
1579f1d2b4d3SLarry Finger 		else
1580f1d2b4d3SLarry Finger 			tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
1581f1d2b4d3SLarry Finger 
1582f1d2b4d3SLarry Finger 		rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
1583f1d2b4d3SLarry Finger 		rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
1584f1d2b4d3SLarry Finger 		    ((tempval >> 4) & 0xF);
1585f1d2b4d3SLarry Finger 	}
1586f1d2b4d3SLarry Finger 
1587f1d2b4d3SLarry Finger 	rtlefuse->legacy_ht_txpowerdiff =
1588f1d2b4d3SLarry Finger 	    rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
1589f1d2b4d3SLarry Finger 
1590f1d2b4d3SLarry Finger 	for (i = 0; i < 14; i++)
1591f1d2b4d3SLarry Finger 		RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1592f1d2b4d3SLarry Finger 			"RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
1593f1d2b4d3SLarry Finger 			i, rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]);
1594f1d2b4d3SLarry Finger 	for (i = 0; i < 14; i++)
1595f1d2b4d3SLarry Finger 		RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1596f1d2b4d3SLarry Finger 			"RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
1597f1d2b4d3SLarry Finger 			i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]);
1598f1d2b4d3SLarry Finger 	for (i = 0; i < 14; i++)
1599f1d2b4d3SLarry Finger 		RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1600f1d2b4d3SLarry Finger 			"RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
1601f1d2b4d3SLarry Finger 			i, rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]);
1602f1d2b4d3SLarry Finger 	for (i = 0; i < 14; i++)
1603f1d2b4d3SLarry Finger 		RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1604f1d2b4d3SLarry Finger 			"RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
1605f1d2b4d3SLarry Finger 			i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
1606f1d2b4d3SLarry Finger 
1607f1d2b4d3SLarry Finger 	if (!autoload_fail)
1608f1d2b4d3SLarry Finger 		rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7);
1609f1d2b4d3SLarry Finger 	else
1610f1d2b4d3SLarry Finger 		rtlefuse->eeprom_regulatory = 0;
1611f1d2b4d3SLarry Finger 	RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1612f1d2b4d3SLarry Finger 		"eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
1613f1d2b4d3SLarry Finger 
1614f1d2b4d3SLarry Finger 	if (!autoload_fail) {
1615f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A];
1616f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_B] = hwinfo[EEPROM_TSSI_B];
1617f1d2b4d3SLarry Finger 	} else {
1618f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI;
1619f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_B] = EEPROM_DEFAULT_TSSI;
1620f1d2b4d3SLarry Finger 	}
1621f1d2b4d3SLarry Finger 	RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1622f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_A],
1623f1d2b4d3SLarry Finger 		rtlefuse->eeprom_tssi[RF90_PATH_B]);
1624f1d2b4d3SLarry Finger 
1625f1d2b4d3SLarry Finger 	if (!autoload_fail)
1626f1d2b4d3SLarry Finger 		tempval = hwinfo[EEPROM_THERMAL_METER];
1627f1d2b4d3SLarry Finger 	else
1628f1d2b4d3SLarry Finger 		tempval = EEPROM_DEFAULT_THERMALMETER;
1629f1d2b4d3SLarry Finger 	rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
1630f1d2b4d3SLarry Finger 
1631f1d2b4d3SLarry Finger 	if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
1632f1d2b4d3SLarry Finger 		rtlefuse->apk_thermalmeterignore = true;
1633f1d2b4d3SLarry Finger 
1634f1d2b4d3SLarry Finger 	rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
1635f1d2b4d3SLarry Finger 	RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
1636f1d2b4d3SLarry Finger 		"thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
1637f1d2b4d3SLarry Finger }
1638f1d2b4d3SLarry Finger 
1639f1d2b4d3SLarry Finger static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1640f1d2b4d3SLarry Finger {
1641f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1642f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1643f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1644df5cbc69SLarry Finger 	int params[] = {RTL8190_EEPROM_ID, EEPROM_VID, EEPROM_DID,
1645df5cbc69SLarry Finger 			EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR,
1646df5cbc69SLarry Finger 			EEPROM_CHANNELPLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID,
1647df5cbc69SLarry Finger 			COUNTRY_CODE_WORLD_WIDE_13};
1648df5cbc69SLarry Finger 	u8 *hwinfo;
1649f1d2b4d3SLarry Finger 
1650df5cbc69SLarry Finger 	hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL);
1651df5cbc69SLarry Finger 	if (!hwinfo)
16525345ea6aSArnd Bergmann 		return;
16535345ea6aSArnd Bergmann 
1654df5cbc69SLarry Finger 	if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params))
1655df5cbc69SLarry Finger 		goto exit;
1656f1d2b4d3SLarry Finger 
1657f1d2b4d3SLarry Finger 	_rtl92ce_read_txpower_info_from_hwpg(hw,
1658f1d2b4d3SLarry Finger 					     rtlefuse->autoload_failflag,
1659f1d2b4d3SLarry Finger 					     hwinfo);
1660f1d2b4d3SLarry Finger 
1661f1d2b4d3SLarry Finger 	rtl8192ce_read_bt_coexist_info_from_hwpg(hw,
1662f1d2b4d3SLarry Finger 						 rtlefuse->autoload_failflag,
1663f1d2b4d3SLarry Finger 						 hwinfo);
1664f1d2b4d3SLarry Finger 	if (rtlhal->oem_id == RT_CID_DEFAULT) {
1665f1d2b4d3SLarry Finger 		switch (rtlefuse->eeprom_oemid) {
1666f1d2b4d3SLarry Finger 		case EEPROM_CID_DEFAULT:
1667f1d2b4d3SLarry Finger 			if (rtlefuse->eeprom_did == 0x8176) {
1668f1d2b4d3SLarry Finger 				if ((rtlefuse->eeprom_svid == 0x103C &&
1669f1d2b4d3SLarry Finger 				     rtlefuse->eeprom_smid == 0x1629))
1670f1d2b4d3SLarry Finger 					rtlhal->oem_id = RT_CID_819X_HP;
1671f1d2b4d3SLarry Finger 				else
1672f1d2b4d3SLarry Finger 					rtlhal->oem_id = RT_CID_DEFAULT;
1673f1d2b4d3SLarry Finger 			} else {
1674f1d2b4d3SLarry Finger 				rtlhal->oem_id = RT_CID_DEFAULT;
1675f1d2b4d3SLarry Finger 			}
1676f1d2b4d3SLarry Finger 			break;
1677f1d2b4d3SLarry Finger 		case EEPROM_CID_TOSHIBA:
1678f1d2b4d3SLarry Finger 			rtlhal->oem_id = RT_CID_TOSHIBA;
1679f1d2b4d3SLarry Finger 			break;
1680f1d2b4d3SLarry Finger 		case EEPROM_CID_QMI:
1681f1d2b4d3SLarry Finger 			rtlhal->oem_id = RT_CID_819X_QMI;
1682f1d2b4d3SLarry Finger 			break;
1683f1d2b4d3SLarry Finger 		case EEPROM_CID_WHQL:
1684f1d2b4d3SLarry Finger 		default:
1685f1d2b4d3SLarry Finger 			rtlhal->oem_id = RT_CID_DEFAULT;
1686f1d2b4d3SLarry Finger 			break;
1687f1d2b4d3SLarry Finger 		}
1688f1d2b4d3SLarry Finger 	}
1689df5cbc69SLarry Finger exit:
1690df5cbc69SLarry Finger 	kfree(hwinfo);
1691f1d2b4d3SLarry Finger }
1692f1d2b4d3SLarry Finger 
1693f1d2b4d3SLarry Finger static void _rtl92ce_hal_customized_behavior(struct ieee80211_hw *hw)
1694f1d2b4d3SLarry Finger {
1695f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1696f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1697f1d2b4d3SLarry Finger 
1698f1d2b4d3SLarry Finger 	switch (rtlhal->oem_id) {
1699f1d2b4d3SLarry Finger 	case RT_CID_819X_HP:
1700d5efe153SLarry Finger 		rtlpriv->ledctl.led_opendrain = true;
1701f1d2b4d3SLarry Finger 		break;
1702f1d2b4d3SLarry Finger 	case RT_CID_819X_LENOVO:
1703f1d2b4d3SLarry Finger 	case RT_CID_DEFAULT:
1704f1d2b4d3SLarry Finger 	case RT_CID_TOSHIBA:
1705f1d2b4d3SLarry Finger 	case RT_CID_CCX:
1706f1d2b4d3SLarry Finger 	case RT_CID_819X_ACER:
1707f1d2b4d3SLarry Finger 	case RT_CID_WHQL:
1708f1d2b4d3SLarry Finger 	default:
1709f1d2b4d3SLarry Finger 		break;
1710f1d2b4d3SLarry Finger 	}
1711f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1712f1d2b4d3SLarry Finger 		 "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
1713f1d2b4d3SLarry Finger }
1714f1d2b4d3SLarry Finger 
1715f1d2b4d3SLarry Finger void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw)
1716f1d2b4d3SLarry Finger {
1717f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1718f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1719f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1720f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1721f1d2b4d3SLarry Finger 	u8 tmp_u1b;
1722f1d2b4d3SLarry Finger 
1723f1d2b4d3SLarry Finger 	rtlhal->version = _rtl92ce_read_chip_version(hw);
1724f1d2b4d3SLarry Finger 	if (get_rf_type(rtlphy) == RF_1T1R)
1725f1d2b4d3SLarry Finger 		rtlpriv->dm.rfpath_rxenable[0] = true;
1726f1d2b4d3SLarry Finger 	else
1727f1d2b4d3SLarry Finger 		rtlpriv->dm.rfpath_rxenable[0] =
1728f1d2b4d3SLarry Finger 		    rtlpriv->dm.rfpath_rxenable[1] = true;
1729f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
1730f1d2b4d3SLarry Finger 		 rtlhal->version);
1731f1d2b4d3SLarry Finger 	tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
1732f1d2b4d3SLarry Finger 	if (tmp_u1b & BIT(4)) {
1733f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
1734f1d2b4d3SLarry Finger 		rtlefuse->epromtype = EEPROM_93C46;
1735f1d2b4d3SLarry Finger 	} else {
1736f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
1737f1d2b4d3SLarry Finger 		rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
1738f1d2b4d3SLarry Finger 	}
1739f1d2b4d3SLarry Finger 	if (tmp_u1b & BIT(5)) {
1740f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
1741f1d2b4d3SLarry Finger 		rtlefuse->autoload_failflag = false;
1742f1d2b4d3SLarry Finger 		_rtl92ce_read_adapter_info(hw);
1743f1d2b4d3SLarry Finger 	} else {
1744e40a0056SLarry Finger 		pr_err("Autoload ERR!!\n");
1745f1d2b4d3SLarry Finger 	}
1746f1d2b4d3SLarry Finger 	_rtl92ce_hal_customized_behavior(hw);
1747f1d2b4d3SLarry Finger }
1748f1d2b4d3SLarry Finger 
1749f1d2b4d3SLarry Finger static void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw,
1750f1d2b4d3SLarry Finger 		struct ieee80211_sta *sta)
1751f1d2b4d3SLarry Finger {
1752f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1753f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1754f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1755f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1756f1d2b4d3SLarry Finger 	u32 ratr_value;
1757f1d2b4d3SLarry Finger 	u8 ratr_index = 0;
1758f1d2b4d3SLarry Finger 	u8 nmode = mac->ht_enable;
1759f1d2b4d3SLarry Finger 	u16 shortgi_rate;
1760f1d2b4d3SLarry Finger 	u32 tmp_ratr_value;
1761f1d2b4d3SLarry Finger 	u8 curtxbw_40mhz = mac->bw_40;
1762f1d2b4d3SLarry Finger 	u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1763f1d2b4d3SLarry Finger 			       1 : 0;
1764f1d2b4d3SLarry Finger 	u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1765f1d2b4d3SLarry Finger 			       1 : 0;
1766f1d2b4d3SLarry Finger 	enum wireless_mode wirelessmode = mac->mode;
1767f1d2b4d3SLarry Finger 	u32 ratr_mask;
1768f1d2b4d3SLarry Finger 
1769f1d2b4d3SLarry Finger 	if (rtlhal->current_bandtype == BAND_ON_5G)
1770f1d2b4d3SLarry Finger 		ratr_value = sta->supp_rates[1] << 4;
1771f1d2b4d3SLarry Finger 	else
1772f1d2b4d3SLarry Finger 		ratr_value = sta->supp_rates[0];
1773f1d2b4d3SLarry Finger 	if (mac->opmode == NL80211_IFTYPE_ADHOC)
1774f1d2b4d3SLarry Finger 		ratr_value = 0xfff;
1775f1d2b4d3SLarry Finger 
1776f1d2b4d3SLarry Finger 	ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1777f1d2b4d3SLarry Finger 			sta->ht_cap.mcs.rx_mask[0] << 12);
1778f1d2b4d3SLarry Finger 	switch (wirelessmode) {
1779f1d2b4d3SLarry Finger 	case WIRELESS_MODE_B:
1780f1d2b4d3SLarry Finger 		if (ratr_value & 0x0000000c)
1781f1d2b4d3SLarry Finger 			ratr_value &= 0x0000000d;
1782f1d2b4d3SLarry Finger 		else
1783f1d2b4d3SLarry Finger 			ratr_value &= 0x0000000f;
1784f1d2b4d3SLarry Finger 		break;
1785f1d2b4d3SLarry Finger 	case WIRELESS_MODE_G:
1786f1d2b4d3SLarry Finger 		ratr_value &= 0x00000FF5;
1787f1d2b4d3SLarry Finger 		break;
1788f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_24G:
1789f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_5G:
1790f1d2b4d3SLarry Finger 		nmode = 1;
1791f1d2b4d3SLarry Finger 		if (get_rf_type(rtlphy) == RF_1T2R ||
1792f1d2b4d3SLarry Finger 		    get_rf_type(rtlphy) == RF_1T1R)
1793f1d2b4d3SLarry Finger 			ratr_mask = 0x000ff005;
1794f1d2b4d3SLarry Finger 		else
1795f1d2b4d3SLarry Finger 			ratr_mask = 0x0f0ff005;
1796f1d2b4d3SLarry Finger 
1797f1d2b4d3SLarry Finger 		ratr_value &= ratr_mask;
1798f1d2b4d3SLarry Finger 		break;
1799f1d2b4d3SLarry Finger 	default:
1800f1d2b4d3SLarry Finger 		if (rtlphy->rf_type == RF_1T2R)
1801f1d2b4d3SLarry Finger 			ratr_value &= 0x000ff0ff;
1802f1d2b4d3SLarry Finger 		else
1803f1d2b4d3SLarry Finger 			ratr_value &= 0x0f0ff0ff;
1804f1d2b4d3SLarry Finger 
1805f1d2b4d3SLarry Finger 		break;
1806f1d2b4d3SLarry Finger 	}
1807f1d2b4d3SLarry Finger 
1808d5efe153SLarry Finger 	if ((rtlpriv->btcoexist.bt_coexistence) &&
1809d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) &&
1810d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_cur_state) &&
1811d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_ant_isolation) &&
1812d5efe153SLarry Finger 	    ((rtlpriv->btcoexist.bt_service == BT_SCO) ||
1813d5efe153SLarry Finger 	    (rtlpriv->btcoexist.bt_service == BT_BUSY)))
1814f1d2b4d3SLarry Finger 		ratr_value &= 0x0fffcfc0;
1815f1d2b4d3SLarry Finger 	else
1816f1d2b4d3SLarry Finger 		ratr_value &= 0x0FFFFFFF;
1817f1d2b4d3SLarry Finger 
1818f1d2b4d3SLarry Finger 	if (nmode && ((curtxbw_40mhz &&
1819f1d2b4d3SLarry Finger 			 curshortgi_40mhz) || (!curtxbw_40mhz &&
1820f1d2b4d3SLarry Finger 					       curshortgi_20mhz))) {
1821f1d2b4d3SLarry Finger 
1822f1d2b4d3SLarry Finger 		ratr_value |= 0x10000000;
1823f1d2b4d3SLarry Finger 		tmp_ratr_value = (ratr_value >> 12);
1824f1d2b4d3SLarry Finger 
1825f1d2b4d3SLarry Finger 		for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
1826f1d2b4d3SLarry Finger 			if ((1 << shortgi_rate) & tmp_ratr_value)
1827f1d2b4d3SLarry Finger 				break;
1828f1d2b4d3SLarry Finger 		}
1829f1d2b4d3SLarry Finger 
1830f1d2b4d3SLarry Finger 		shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
1831f1d2b4d3SLarry Finger 		    (shortgi_rate << 4) | (shortgi_rate);
1832f1d2b4d3SLarry Finger 	}
1833f1d2b4d3SLarry Finger 
1834f1d2b4d3SLarry Finger 	rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
1835f1d2b4d3SLarry Finger 
1836f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
1837f1d2b4d3SLarry Finger 		 rtl_read_dword(rtlpriv, REG_ARFR0));
1838f1d2b4d3SLarry Finger }
1839f1d2b4d3SLarry Finger 
1840f1d2b4d3SLarry Finger static void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw,
18411d22b177SPing-Ke Shih 		struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
1842f1d2b4d3SLarry Finger {
1843f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1844f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
1845f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1846f1d2b4d3SLarry Finger 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1847f1d2b4d3SLarry Finger 	struct rtl_sta_info *sta_entry = NULL;
1848f1d2b4d3SLarry Finger 	u32 ratr_bitmap;
1849f1d2b4d3SLarry Finger 	u8 ratr_index;
1850f1d2b4d3SLarry Finger 	u8 curtxbw_40mhz = (sta->ht_cap.cap &
1851f1d2b4d3SLarry Finger 			    IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
1852f1d2b4d3SLarry Finger 	u8 curshortgi_40mhz = (sta->ht_cap.cap &
1853f1d2b4d3SLarry Finger 			       IEEE80211_HT_CAP_SGI_40) ?  1 : 0;
1854f1d2b4d3SLarry Finger 	u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1855f1d2b4d3SLarry Finger 				1 : 0;
1856f1d2b4d3SLarry Finger 	enum wireless_mode wirelessmode = 0;
1857f1d2b4d3SLarry Finger 	bool shortgi = false;
1858f1d2b4d3SLarry Finger 	u8 rate_mask[5];
1859f1d2b4d3SLarry Finger 	u8 macid = 0;
1860f1d2b4d3SLarry Finger 
1861f1d2b4d3SLarry Finger 	sta_entry = (struct rtl_sta_info *) sta->drv_priv;
1862f1d2b4d3SLarry Finger 	wirelessmode = sta_entry->wireless_mode;
1863f1d2b4d3SLarry Finger 	if (mac->opmode == NL80211_IFTYPE_STATION ||
1864f1d2b4d3SLarry Finger 	    mac->opmode == NL80211_IFTYPE_MESH_POINT)
1865f1d2b4d3SLarry Finger 		curtxbw_40mhz = mac->bw_40;
1866f1d2b4d3SLarry Finger 	else if (mac->opmode == NL80211_IFTYPE_AP ||
1867f1d2b4d3SLarry Finger 		mac->opmode == NL80211_IFTYPE_ADHOC)
1868f1d2b4d3SLarry Finger 		macid = sta->aid + 1;
1869f1d2b4d3SLarry Finger 
1870f1d2b4d3SLarry Finger 	if (rtlhal->current_bandtype == BAND_ON_5G)
1871f1d2b4d3SLarry Finger 		ratr_bitmap = sta->supp_rates[1] << 4;
1872f1d2b4d3SLarry Finger 	else
1873f1d2b4d3SLarry Finger 		ratr_bitmap = sta->supp_rates[0];
1874f1d2b4d3SLarry Finger 	if (mac->opmode == NL80211_IFTYPE_ADHOC)
1875f1d2b4d3SLarry Finger 		ratr_bitmap = 0xfff;
1876f1d2b4d3SLarry Finger 	ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1877f1d2b4d3SLarry Finger 			sta->ht_cap.mcs.rx_mask[0] << 12);
1878f1d2b4d3SLarry Finger 	switch (wirelessmode) {
1879f1d2b4d3SLarry Finger 	case WIRELESS_MODE_B:
1880f1d2b4d3SLarry Finger 		ratr_index = RATR_INX_WIRELESS_B;
1881f1d2b4d3SLarry Finger 		if (ratr_bitmap & 0x0000000c)
1882f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x0000000d;
1883f1d2b4d3SLarry Finger 		else
1884f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x0000000f;
1885f1d2b4d3SLarry Finger 		break;
1886f1d2b4d3SLarry Finger 	case WIRELESS_MODE_G:
1887f1d2b4d3SLarry Finger 		ratr_index = RATR_INX_WIRELESS_GB;
1888f1d2b4d3SLarry Finger 
1889f1d2b4d3SLarry Finger 		if (rssi_level == 1)
1890f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x00000f00;
1891f1d2b4d3SLarry Finger 		else if (rssi_level == 2)
1892f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x00000ff0;
1893f1d2b4d3SLarry Finger 		else
1894f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x00000ff5;
1895f1d2b4d3SLarry Finger 		break;
1896f1d2b4d3SLarry Finger 	case WIRELESS_MODE_A:
1897f1d2b4d3SLarry Finger 		ratr_index = RATR_INX_WIRELESS_A;
1898f1d2b4d3SLarry Finger 		ratr_bitmap &= 0x00000ff0;
1899f1d2b4d3SLarry Finger 		break;
1900f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_24G:
1901f1d2b4d3SLarry Finger 	case WIRELESS_MODE_N_5G:
1902f1d2b4d3SLarry Finger 		ratr_index = RATR_INX_WIRELESS_NGB;
1903f1d2b4d3SLarry Finger 
1904f1d2b4d3SLarry Finger 		if (rtlphy->rf_type == RF_1T2R ||
1905f1d2b4d3SLarry Finger 		    rtlphy->rf_type == RF_1T1R) {
1906f1d2b4d3SLarry Finger 			if (curtxbw_40mhz) {
1907f1d2b4d3SLarry Finger 				if (rssi_level == 1)
1908f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000f0000;
1909f1d2b4d3SLarry Finger 				else if (rssi_level == 2)
1910f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000ff000;
1911f1d2b4d3SLarry Finger 				else
1912f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000ff015;
1913f1d2b4d3SLarry Finger 			} else {
1914f1d2b4d3SLarry Finger 				if (rssi_level == 1)
1915f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000f0000;
1916f1d2b4d3SLarry Finger 				else if (rssi_level == 2)
1917f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000ff000;
1918f1d2b4d3SLarry Finger 				else
1919f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x000ff005;
1920f1d2b4d3SLarry Finger 			}
1921f1d2b4d3SLarry Finger 		} else {
1922f1d2b4d3SLarry Finger 			if (curtxbw_40mhz) {
1923f1d2b4d3SLarry Finger 				if (rssi_level == 1)
1924f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0f0000;
1925f1d2b4d3SLarry Finger 				else if (rssi_level == 2)
1926f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0ff000;
1927f1d2b4d3SLarry Finger 				else
1928f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0ff015;
1929f1d2b4d3SLarry Finger 			} else {
1930f1d2b4d3SLarry Finger 				if (rssi_level == 1)
1931f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0f0000;
1932f1d2b4d3SLarry Finger 				else if (rssi_level == 2)
1933f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0ff000;
1934f1d2b4d3SLarry Finger 				else
1935f1d2b4d3SLarry Finger 					ratr_bitmap &= 0x0f0ff005;
1936f1d2b4d3SLarry Finger 			}
1937f1d2b4d3SLarry Finger 		}
1938f1d2b4d3SLarry Finger 
1939f1d2b4d3SLarry Finger 		if ((curtxbw_40mhz && curshortgi_40mhz) ||
1940f1d2b4d3SLarry Finger 		    (!curtxbw_40mhz && curshortgi_20mhz)) {
1941f1d2b4d3SLarry Finger 
1942f1d2b4d3SLarry Finger 			if (macid == 0)
1943f1d2b4d3SLarry Finger 				shortgi = true;
1944f1d2b4d3SLarry Finger 			else if (macid == 1)
1945f1d2b4d3SLarry Finger 				shortgi = false;
1946f1d2b4d3SLarry Finger 		}
1947f1d2b4d3SLarry Finger 		break;
1948f1d2b4d3SLarry Finger 	default:
1949f1d2b4d3SLarry Finger 		ratr_index = RATR_INX_WIRELESS_NGB;
1950f1d2b4d3SLarry Finger 
1951f1d2b4d3SLarry Finger 		if (rtlphy->rf_type == RF_1T2R)
1952f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x000ff0ff;
1953f1d2b4d3SLarry Finger 		else
1954f1d2b4d3SLarry Finger 			ratr_bitmap &= 0x0f0ff0ff;
1955f1d2b4d3SLarry Finger 		break;
1956f1d2b4d3SLarry Finger 	}
1957f1d2b4d3SLarry Finger 	sta_entry->ratr_index = ratr_index;
1958f1d2b4d3SLarry Finger 
1959f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1960f1d2b4d3SLarry Finger 		 "ratr_bitmap :%x\n", ratr_bitmap);
1961f1d2b4d3SLarry Finger 	*(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
1962f1d2b4d3SLarry Finger 				     (ratr_index << 28);
1963f1d2b4d3SLarry Finger 	rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
1964f1d2b4d3SLarry Finger 	RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1965f1d2b4d3SLarry Finger 		 "Rate_index:%x, ratr_val:%x, %5phC\n",
1966f1d2b4d3SLarry Finger 		 ratr_index, ratr_bitmap, rate_mask);
1967f1d2b4d3SLarry Finger 	rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
1968f1d2b4d3SLarry Finger }
1969f1d2b4d3SLarry Finger 
1970f1d2b4d3SLarry Finger void rtl92ce_update_hal_rate_tbl(struct ieee80211_hw *hw,
19711d22b177SPing-Ke Shih 		struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
1972f1d2b4d3SLarry Finger {
1973f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1974f1d2b4d3SLarry Finger 
1975f1d2b4d3SLarry Finger 	if (rtlpriv->dm.useramask)
19761d22b177SPing-Ke Shih 		rtl92ce_update_hal_rate_mask(hw, sta, rssi_level, update_bw);
1977f1d2b4d3SLarry Finger 	else
1978f1d2b4d3SLarry Finger 		rtl92ce_update_hal_rate_table(hw, sta);
1979f1d2b4d3SLarry Finger }
1980f1d2b4d3SLarry Finger 
1981f1d2b4d3SLarry Finger void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw)
1982f1d2b4d3SLarry Finger {
1983f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1984f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1985f1d2b4d3SLarry Finger 	u16 sifs_timer;
1986f1d2b4d3SLarry Finger 
1987f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
1988f1d2b4d3SLarry Finger 				      &mac->slot_time);
1989f1d2b4d3SLarry Finger 	if (!mac->ht_enable)
1990f1d2b4d3SLarry Finger 		sifs_timer = 0x0a0a;
1991f1d2b4d3SLarry Finger 	else
1992f1d2b4d3SLarry Finger 		sifs_timer = 0x1010;
1993f1d2b4d3SLarry Finger 	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
1994f1d2b4d3SLarry Finger }
1995f1d2b4d3SLarry Finger 
1996f1d2b4d3SLarry Finger bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
1997f1d2b4d3SLarry Finger {
1998f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
1999f1d2b4d3SLarry Finger 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2000f1d2b4d3SLarry Finger 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2001f1d2b4d3SLarry Finger 	enum rf_pwrstate e_rfpowerstate_toset;
2002f1d2b4d3SLarry Finger 	u8 u1tmp;
2003f1d2b4d3SLarry Finger 	bool actuallyset = false;
2004f1d2b4d3SLarry Finger 	unsigned long flag;
2005f1d2b4d3SLarry Finger 
2006f1d2b4d3SLarry Finger 	if (rtlpci->being_init_adapter)
2007f1d2b4d3SLarry Finger 		return false;
2008f1d2b4d3SLarry Finger 
2009f1d2b4d3SLarry Finger 	if (ppsc->swrf_processing)
2010f1d2b4d3SLarry Finger 		return false;
2011f1d2b4d3SLarry Finger 
2012f1d2b4d3SLarry Finger 	spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2013f1d2b4d3SLarry Finger 	if (ppsc->rfchange_inprogress) {
2014f1d2b4d3SLarry Finger 		spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2015f1d2b4d3SLarry Finger 		return false;
2016f1d2b4d3SLarry Finger 	} else {
2017f1d2b4d3SLarry Finger 		ppsc->rfchange_inprogress = true;
2018f1d2b4d3SLarry Finger 		spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2019f1d2b4d3SLarry Finger 	}
2020f1d2b4d3SLarry Finger 
2021f1d2b4d3SLarry Finger 	rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
2022f1d2b4d3SLarry Finger 		       REG_MAC_PINMUX_CFG)&~(BIT(3)));
2023f1d2b4d3SLarry Finger 
2024f1d2b4d3SLarry Finger 	u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
2025f1d2b4d3SLarry Finger 	e_rfpowerstate_toset = (u1tmp & BIT(3)) ? ERFON : ERFOFF;
2026f1d2b4d3SLarry Finger 
2027f1d2b4d3SLarry Finger 	if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) {
2028f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2029f1d2b4d3SLarry Finger 			 "GPIOChangeRF  - HW Radio ON, RF ON\n");
2030f1d2b4d3SLarry Finger 
2031f1d2b4d3SLarry Finger 		e_rfpowerstate_toset = ERFON;
2032f1d2b4d3SLarry Finger 		ppsc->hwradiooff = false;
2033f1d2b4d3SLarry Finger 		actuallyset = true;
2034f1d2b4d3SLarry Finger 	} else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) {
2035f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2036f1d2b4d3SLarry Finger 			 "GPIOChangeRF  - HW Radio OFF, RF OFF\n");
2037f1d2b4d3SLarry Finger 
2038f1d2b4d3SLarry Finger 		e_rfpowerstate_toset = ERFOFF;
2039f1d2b4d3SLarry Finger 		ppsc->hwradiooff = true;
2040f1d2b4d3SLarry Finger 		actuallyset = true;
2041f1d2b4d3SLarry Finger 	}
2042f1d2b4d3SLarry Finger 
2043f1d2b4d3SLarry Finger 	if (actuallyset) {
2044f1d2b4d3SLarry Finger 		spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2045f1d2b4d3SLarry Finger 		ppsc->rfchange_inprogress = false;
2046f1d2b4d3SLarry Finger 		spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2047f1d2b4d3SLarry Finger 	} else {
2048f1d2b4d3SLarry Finger 		if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
2049f1d2b4d3SLarry Finger 			RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2050f1d2b4d3SLarry Finger 
2051f1d2b4d3SLarry Finger 		spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2052f1d2b4d3SLarry Finger 		ppsc->rfchange_inprogress = false;
2053f1d2b4d3SLarry Finger 		spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2054f1d2b4d3SLarry Finger 	}
2055f1d2b4d3SLarry Finger 
2056f1d2b4d3SLarry Finger 	*valid = 1;
2057f1d2b4d3SLarry Finger 	return !ppsc->hwradiooff;
2058f1d2b4d3SLarry Finger 
2059f1d2b4d3SLarry Finger }
2060f1d2b4d3SLarry Finger 
2061f1d2b4d3SLarry Finger void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
2062f1d2b4d3SLarry Finger 		     u8 *p_macaddr, bool is_group, u8 enc_algo,
2063f1d2b4d3SLarry Finger 		     bool is_wepkey, bool clear_all)
2064f1d2b4d3SLarry Finger {
2065f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
2066f1d2b4d3SLarry Finger 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2067f1d2b4d3SLarry Finger 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2068f1d2b4d3SLarry Finger 	u8 *macaddr = p_macaddr;
2069f1d2b4d3SLarry Finger 	u32 entry_id = 0;
2070f1d2b4d3SLarry Finger 	bool is_pairwise = false;
2071f1d2b4d3SLarry Finger 
2072f1d2b4d3SLarry Finger 	static u8 cam_const_addr[4][6] = {
2073f1d2b4d3SLarry Finger 		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2074f1d2b4d3SLarry Finger 		{0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2075f1d2b4d3SLarry Finger 		{0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2076f1d2b4d3SLarry Finger 		{0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2077f1d2b4d3SLarry Finger 	};
2078f1d2b4d3SLarry Finger 	static u8 cam_const_broad[] = {
2079f1d2b4d3SLarry Finger 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2080f1d2b4d3SLarry Finger 	};
2081f1d2b4d3SLarry Finger 
2082f1d2b4d3SLarry Finger 	if (clear_all) {
2083f1d2b4d3SLarry Finger 		u8 idx = 0;
2084f1d2b4d3SLarry Finger 		u8 cam_offset = 0;
2085f1d2b4d3SLarry Finger 		u8 clear_number = 5;
2086f1d2b4d3SLarry Finger 
2087f1d2b4d3SLarry Finger 		RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
2088f1d2b4d3SLarry Finger 
2089f1d2b4d3SLarry Finger 		for (idx = 0; idx < clear_number; idx++) {
2090f1d2b4d3SLarry Finger 			rtl_cam_mark_invalid(hw, cam_offset + idx);
2091f1d2b4d3SLarry Finger 			rtl_cam_empty_entry(hw, cam_offset + idx);
2092f1d2b4d3SLarry Finger 
2093f1d2b4d3SLarry Finger 			if (idx < 5) {
2094f1d2b4d3SLarry Finger 				memset(rtlpriv->sec.key_buf[idx], 0,
2095f1d2b4d3SLarry Finger 				       MAX_KEY_LEN);
2096f1d2b4d3SLarry Finger 				rtlpriv->sec.key_len[idx] = 0;
2097f1d2b4d3SLarry Finger 			}
2098f1d2b4d3SLarry Finger 		}
2099f1d2b4d3SLarry Finger 
2100f1d2b4d3SLarry Finger 	} else {
2101f1d2b4d3SLarry Finger 		switch (enc_algo) {
2102f1d2b4d3SLarry Finger 		case WEP40_ENCRYPTION:
2103f1d2b4d3SLarry Finger 			enc_algo = CAM_WEP40;
2104f1d2b4d3SLarry Finger 			break;
2105f1d2b4d3SLarry Finger 		case WEP104_ENCRYPTION:
2106f1d2b4d3SLarry Finger 			enc_algo = CAM_WEP104;
2107f1d2b4d3SLarry Finger 			break;
2108f1d2b4d3SLarry Finger 		case TKIP_ENCRYPTION:
2109f1d2b4d3SLarry Finger 			enc_algo = CAM_TKIP;
2110f1d2b4d3SLarry Finger 			break;
2111f1d2b4d3SLarry Finger 		case AESCCMP_ENCRYPTION:
2112f1d2b4d3SLarry Finger 			enc_algo = CAM_AES;
2113f1d2b4d3SLarry Finger 			break;
2114f1d2b4d3SLarry Finger 		default:
2115e40a0056SLarry Finger 			pr_err("switch case %#x not processed\n",
2116e40a0056SLarry Finger 			       enc_algo);
2117f1d2b4d3SLarry Finger 			enc_algo = CAM_TKIP;
2118f1d2b4d3SLarry Finger 			break;
2119f1d2b4d3SLarry Finger 		}
2120f1d2b4d3SLarry Finger 
2121f1d2b4d3SLarry Finger 		if (is_wepkey || rtlpriv->sec.use_defaultkey) {
2122f1d2b4d3SLarry Finger 			macaddr = cam_const_addr[key_index];
2123f1d2b4d3SLarry Finger 			entry_id = key_index;
2124f1d2b4d3SLarry Finger 		} else {
2125f1d2b4d3SLarry Finger 			if (is_group) {
2126f1d2b4d3SLarry Finger 				macaddr = cam_const_broad;
2127f1d2b4d3SLarry Finger 				entry_id = key_index;
2128f1d2b4d3SLarry Finger 			} else {
2129f1d2b4d3SLarry Finger 				if (mac->opmode == NL80211_IFTYPE_AP ||
2130f1d2b4d3SLarry Finger 				    mac->opmode == NL80211_IFTYPE_MESH_POINT) {
2131f1d2b4d3SLarry Finger 					entry_id = rtl_cam_get_free_entry(hw,
2132f1d2b4d3SLarry Finger 								 p_macaddr);
2133f1d2b4d3SLarry Finger 					if (entry_id >=  TOTAL_CAM_ENTRY) {
2134e40a0056SLarry Finger 						pr_err("Can not find free hw security cam entry\n");
2135f1d2b4d3SLarry Finger 						return;
2136f1d2b4d3SLarry Finger 					}
2137f1d2b4d3SLarry Finger 				} else {
2138f1d2b4d3SLarry Finger 					entry_id = CAM_PAIRWISE_KEY_POSITION;
2139f1d2b4d3SLarry Finger 				}
2140f1d2b4d3SLarry Finger 
2141f1d2b4d3SLarry Finger 				key_index = PAIRWISE_KEYIDX;
2142f1d2b4d3SLarry Finger 				is_pairwise = true;
2143f1d2b4d3SLarry Finger 			}
2144f1d2b4d3SLarry Finger 		}
2145f1d2b4d3SLarry Finger 
2146f1d2b4d3SLarry Finger 		if (rtlpriv->sec.key_len[key_index] == 0) {
2147f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2148f1d2b4d3SLarry Finger 				 "delete one entry, entry_id is %d\n",
2149f1d2b4d3SLarry Finger 				 entry_id);
2150f1d2b4d3SLarry Finger 			if (mac->opmode == NL80211_IFTYPE_AP ||
2151f1d2b4d3SLarry Finger 			    mac->opmode == NL80211_IFTYPE_MESH_POINT)
2152f1d2b4d3SLarry Finger 				rtl_cam_del_entry(hw, p_macaddr);
2153f1d2b4d3SLarry Finger 			rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2154f1d2b4d3SLarry Finger 		} else {
2155f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2156f1d2b4d3SLarry Finger 				 "The insert KEY length is %d\n",
2157f1d2b4d3SLarry Finger 				 rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
2158f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2159f1d2b4d3SLarry Finger 				 "The insert KEY is %x %x\n",
2160f1d2b4d3SLarry Finger 				 rtlpriv->sec.key_buf[0][0],
2161f1d2b4d3SLarry Finger 				 rtlpriv->sec.key_buf[0][1]);
2162f1d2b4d3SLarry Finger 
2163f1d2b4d3SLarry Finger 			RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2164f1d2b4d3SLarry Finger 				 "add one entry\n");
2165f1d2b4d3SLarry Finger 			if (is_pairwise) {
2166f1d2b4d3SLarry Finger 				RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
2167f1d2b4d3SLarry Finger 					      "Pairwise Key content",
2168f1d2b4d3SLarry Finger 					      rtlpriv->sec.pairwise_key,
2169f1d2b4d3SLarry Finger 					      rtlpriv->sec.
2170f1d2b4d3SLarry Finger 					      key_len[PAIRWISE_KEYIDX]);
2171f1d2b4d3SLarry Finger 
2172f1d2b4d3SLarry Finger 				RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2173f1d2b4d3SLarry Finger 					 "set Pairwise key\n");
2174f1d2b4d3SLarry Finger 
2175f1d2b4d3SLarry Finger 				rtl_cam_add_one_entry(hw, macaddr, key_index,
2176f1d2b4d3SLarry Finger 						      entry_id, enc_algo,
2177f1d2b4d3SLarry Finger 						      CAM_CONFIG_NO_USEDK,
2178f1d2b4d3SLarry Finger 						      rtlpriv->sec.
2179f1d2b4d3SLarry Finger 						      key_buf[key_index]);
2180f1d2b4d3SLarry Finger 			} else {
2181f1d2b4d3SLarry Finger 				RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2182f1d2b4d3SLarry Finger 					 "set group key\n");
2183f1d2b4d3SLarry Finger 
2184f1d2b4d3SLarry Finger 				if (mac->opmode == NL80211_IFTYPE_ADHOC) {
2185f1d2b4d3SLarry Finger 					rtl_cam_add_one_entry(hw,
2186f1d2b4d3SLarry Finger 						rtlefuse->dev_addr,
2187f1d2b4d3SLarry Finger 						PAIRWISE_KEYIDX,
2188f1d2b4d3SLarry Finger 						CAM_PAIRWISE_KEY_POSITION,
2189f1d2b4d3SLarry Finger 						enc_algo,
2190f1d2b4d3SLarry Finger 						CAM_CONFIG_NO_USEDK,
2191f1d2b4d3SLarry Finger 						rtlpriv->sec.key_buf
2192f1d2b4d3SLarry Finger 						[entry_id]);
2193f1d2b4d3SLarry Finger 				}
2194f1d2b4d3SLarry Finger 
2195f1d2b4d3SLarry Finger 				rtl_cam_add_one_entry(hw, macaddr, key_index,
2196f1d2b4d3SLarry Finger 						entry_id, enc_algo,
2197f1d2b4d3SLarry Finger 						CAM_CONFIG_NO_USEDK,
2198f1d2b4d3SLarry Finger 						rtlpriv->sec.key_buf[entry_id]);
2199f1d2b4d3SLarry Finger 			}
2200f1d2b4d3SLarry Finger 
2201f1d2b4d3SLarry Finger 		}
2202f1d2b4d3SLarry Finger 	}
2203f1d2b4d3SLarry Finger }
2204f1d2b4d3SLarry Finger 
2205f1d2b4d3SLarry Finger static void rtl8192ce_bt_var_init(struct ieee80211_hw *hw)
2206f1d2b4d3SLarry Finger {
2207d5efe153SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
2208f1d2b4d3SLarry Finger 
2209d5efe153SLarry Finger 	rtlpriv->btcoexist.bt_coexistence =
2210d5efe153SLarry Finger 			rtlpriv->btcoexist.eeprom_bt_coexist;
2211d5efe153SLarry Finger 	rtlpriv->btcoexist.bt_ant_num =
2212d5efe153SLarry Finger 			rtlpriv->btcoexist.eeprom_bt_ant_num;
2213d5efe153SLarry Finger 	rtlpriv->btcoexist.bt_coexist_type =
2214d5efe153SLarry Finger 			rtlpriv->btcoexist.eeprom_bt_type;
2215f1d2b4d3SLarry Finger 
2216d5efe153SLarry Finger 	if (rtlpriv->btcoexist.reg_bt_iso == 2)
2217d5efe153SLarry Finger 		rtlpriv->btcoexist.bt_ant_isolation =
2218d5efe153SLarry Finger 			rtlpriv->btcoexist.eeprom_bt_ant_isol;
2219f1d2b4d3SLarry Finger 	else
2220d5efe153SLarry Finger 		rtlpriv->btcoexist.bt_ant_isolation =
2221d5efe153SLarry Finger 			rtlpriv->btcoexist.reg_bt_iso;
2222f1d2b4d3SLarry Finger 
2223d5efe153SLarry Finger 	rtlpriv->btcoexist.bt_radio_shared_type =
2224d5efe153SLarry Finger 			rtlpriv->btcoexist.eeprom_bt_radio_shared;
2225f1d2b4d3SLarry Finger 
2226d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence) {
2227d5efe153SLarry Finger 		if (rtlpriv->btcoexist.reg_bt_sco == 1)
2228d5efe153SLarry Finger 			rtlpriv->btcoexist.bt_service = BT_OTHER_ACTION;
2229d5efe153SLarry Finger 		else if (rtlpriv->btcoexist.reg_bt_sco == 2)
2230d5efe153SLarry Finger 			rtlpriv->btcoexist.bt_service = BT_SCO;
2231d5efe153SLarry Finger 		else if (rtlpriv->btcoexist.reg_bt_sco == 4)
2232d5efe153SLarry Finger 			rtlpriv->btcoexist.bt_service = BT_BUSY;
2233d5efe153SLarry Finger 		else if (rtlpriv->btcoexist.reg_bt_sco == 5)
2234d5efe153SLarry Finger 			rtlpriv->btcoexist.bt_service = BT_OTHERBUSY;
2235f1d2b4d3SLarry Finger 		else
2236d5efe153SLarry Finger 			rtlpriv->btcoexist.bt_service = BT_IDLE;
2237f1d2b4d3SLarry Finger 
2238d5efe153SLarry Finger 		rtlpriv->btcoexist.bt_edca_ul = 0;
2239d5efe153SLarry Finger 		rtlpriv->btcoexist.bt_edca_dl = 0;
2240d5efe153SLarry Finger 		rtlpriv->btcoexist.bt_rssi_state = 0xff;
2241f1d2b4d3SLarry Finger 	}
2242f1d2b4d3SLarry Finger }
2243f1d2b4d3SLarry Finger 
2244f1d2b4d3SLarry Finger void rtl8192ce_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
2245f1d2b4d3SLarry Finger 					      bool auto_load_fail, u8 *hwinfo)
2246f1d2b4d3SLarry Finger {
2247d5efe153SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
2248f1d2b4d3SLarry Finger 	u8 val;
2249f1d2b4d3SLarry Finger 
2250f1d2b4d3SLarry Finger 	if (!auto_load_fail) {
2251d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_coexist =
2252f1d2b4d3SLarry Finger 					((hwinfo[RF_OPTION1] & 0xe0) >> 5);
2253f1d2b4d3SLarry Finger 		val = hwinfo[RF_OPTION4];
2254d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_type = ((val & 0xe) >> 1);
2255d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_ant_num = (val & 0x1);
2256d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_ant_isol = ((val & 0x10) >> 4);
2257d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_radio_shared =
2258f1d2b4d3SLarry Finger 							 ((val & 0x20) >> 5);
2259f1d2b4d3SLarry Finger 	} else {
2260d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_coexist = 0;
2261d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_type = BT_2WIRE;
2262d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2;
2263d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_ant_isol = 0;
2264d5efe153SLarry Finger 		rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
2265f1d2b4d3SLarry Finger 	}
2266f1d2b4d3SLarry Finger 
2267f1d2b4d3SLarry Finger 	rtl8192ce_bt_var_init(hw);
2268f1d2b4d3SLarry Finger }
2269f1d2b4d3SLarry Finger 
2270f1d2b4d3SLarry Finger void rtl8192ce_bt_reg_init(struct ieee80211_hw *hw)
2271f1d2b4d3SLarry Finger {
2272d5efe153SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
2273f1d2b4d3SLarry Finger 
2274f1d2b4d3SLarry Finger 	/* 0:Low, 1:High, 2:From Efuse. */
2275d5efe153SLarry Finger 	rtlpriv->btcoexist.reg_bt_iso = 2;
2276f1d2b4d3SLarry Finger 	/* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2277d5efe153SLarry Finger 	rtlpriv->btcoexist.reg_bt_sco = 3;
2278f1d2b4d3SLarry Finger 	/* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2279d5efe153SLarry Finger 	rtlpriv->btcoexist.reg_bt_sco = 0;
2280f1d2b4d3SLarry Finger }
2281f1d2b4d3SLarry Finger 
2282f1d2b4d3SLarry Finger 
2283f1d2b4d3SLarry Finger void rtl8192ce_bt_hw_init(struct ieee80211_hw *hw)
2284f1d2b4d3SLarry Finger {
2285f1d2b4d3SLarry Finger 	struct rtl_priv *rtlpriv = rtl_priv(hw);
2286f1d2b4d3SLarry Finger 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
2287f1d2b4d3SLarry Finger 
2288f1d2b4d3SLarry Finger 	u8 u1_tmp;
2289f1d2b4d3SLarry Finger 
2290d5efe153SLarry Finger 	if (rtlpriv->btcoexist.bt_coexistence &&
2291d5efe153SLarry Finger 	    ((rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) ||
2292d5efe153SLarry Finger 	      rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC8)) {
2293f1d2b4d3SLarry Finger 
2294d5efe153SLarry Finger 		if (rtlpriv->btcoexist.bt_ant_isolation)
2295f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
2296f1d2b4d3SLarry Finger 
2297f1d2b4d3SLarry Finger 		u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
2298f1d2b4d3SLarry Finger 			 BIT_OFFSET_LEN_MASK_32(0, 1);
2299f1d2b4d3SLarry Finger 		u1_tmp = u1_tmp |
2300d5efe153SLarry Finger 			 ((rtlpriv->btcoexist.bt_ant_isolation == 1) ?
2301f1d2b4d3SLarry Finger 			 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
2302d5efe153SLarry Finger 			 ((rtlpriv->btcoexist.bt_service == BT_SCO) ?
2303f1d2b4d3SLarry Finger 			 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
2304f1d2b4d3SLarry Finger 		rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
2305f1d2b4d3SLarry Finger 
2306f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
2307f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
2308f1d2b4d3SLarry Finger 		rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
2309f1d2b4d3SLarry Finger 
2310f1d2b4d3SLarry Finger 		/* Config to 1T1R. */
2311f1d2b4d3SLarry Finger 		if (rtlphy->rf_type == RF_1T1R) {
2312f1d2b4d3SLarry Finger 			u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
2313f1d2b4d3SLarry Finger 			u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2314f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
2315f1d2b4d3SLarry Finger 
2316f1d2b4d3SLarry Finger 			u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
2317f1d2b4d3SLarry Finger 			u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2318f1d2b4d3SLarry Finger 			rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
2319f1d2b4d3SLarry Finger 		}
2320f1d2b4d3SLarry Finger 	}
2321f1d2b4d3SLarry Finger }
2322f1d2b4d3SLarry Finger 
2323f1d2b4d3SLarry Finger void rtl92ce_suspend(struct ieee80211_hw *hw)
2324f1d2b4d3SLarry Finger {
2325f1d2b4d3SLarry Finger }
2326f1d2b4d3SLarry Finger 
2327f1d2b4d3SLarry Finger void rtl92ce_resume(struct ieee80211_hw *hw)
2328f1d2b4d3SLarry Finger {
2329f1d2b4d3SLarry Finger }
2330