1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012  Realtek Corporation.*/
3 
4 #include "../wifi.h"
5 #include "../pci.h"
6 #include "../ps.h"
7 #include "../core.h"
8 #include "reg.h"
9 #include "def.h"
10 #include "hw.h"
11 #include "phy.h"
12 #include "../rtl8192c/phy_common.h"
13 #include "rf.h"
14 #include "dm.h"
15 #include "../rtl8192c/dm_common.h"
16 #include "../rtl8192c/fw_common.h"
17 #include "table.h"
18 
19 static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
20 
21 u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
22 			    enum radio_path rfpath, u32 regaddr, u32 bitmask)
23 {
24 	struct rtl_priv *rtlpriv = rtl_priv(hw);
25 	u32 original_value, readback_value, bitshift;
26 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
27 
28 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
29 		"regaddr(%#x), rfpath(%#x), bitmask(%#x)\n",
30 		regaddr, rfpath, bitmask);
31 
32 	spin_lock(&rtlpriv->locks.rf_lock);
33 
34 	if (rtlphy->rf_mode != RF_OP_BY_FW) {
35 		original_value = _rtl92c_phy_rf_serial_read(hw,
36 							    rfpath, regaddr);
37 	} else {
38 		original_value = _rtl92c_phy_fw_rf_serial_read(hw,
39 							       rfpath, regaddr);
40 	}
41 
42 	bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
43 	readback_value = (original_value & bitmask) >> bitshift;
44 
45 	spin_unlock(&rtlpriv->locks.rf_lock);
46 
47 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
48 		"regaddr(%#x), rfpath(%#x), bitmask(%#x), original_value(%#x)\n",
49 		regaddr, rfpath, bitmask, original_value);
50 
51 	return readback_value;
52 }
53 
54 bool rtl92c_phy_mac_config(struct ieee80211_hw *hw)
55 {
56 	struct rtl_priv *rtlpriv = rtl_priv(hw);
57 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
58 	bool is92c = IS_92C_SERIAL(rtlhal->version);
59 	bool rtstatus = _rtl92c_phy_config_mac_with_headerfile(hw);
60 
61 	if (is92c)
62 		rtl_write_byte(rtlpriv, 0x14, 0x71);
63 	else
64 		rtl_write_byte(rtlpriv, 0x04CA, 0x0A);
65 	return rtstatus;
66 }
67 
68 bool rtl92c_phy_bb_config(struct ieee80211_hw *hw)
69 {
70 	bool rtstatus = true;
71 	struct rtl_priv *rtlpriv = rtl_priv(hw);
72 	u16 regval;
73 	u32 regvaldw;
74 	u8 reg_hwparafile = 1;
75 
76 	_rtl92c_phy_init_bb_rf_register_definition(hw);
77 	regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
78 	rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
79 		       regval | BIT(13) | BIT(0) | BIT(1));
80 	rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
81 	rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
82 	rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
83 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
84 		       FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
85 		       FEN_BB_GLB_RSTN | FEN_BBRSTB);
86 	rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
87 	regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
88 	rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
89 	if (reg_hwparafile == 1)
90 		rtstatus = _rtl92c_phy_bb8192c_config_parafile(hw);
91 	return rtstatus;
92 }
93 
94 void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
95 			    enum radio_path rfpath,
96 			    u32 regaddr, u32 bitmask, u32 data)
97 {
98 	struct rtl_priv *rtlpriv = rtl_priv(hw);
99 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
100 	u32 original_value, bitshift;
101 
102 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
103 		"regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
104 		regaddr, bitmask, data, rfpath);
105 
106 	spin_lock(&rtlpriv->locks.rf_lock);
107 
108 	if (rtlphy->rf_mode != RF_OP_BY_FW) {
109 		if (bitmask != RFREG_OFFSET_MASK) {
110 			original_value = _rtl92c_phy_rf_serial_read(hw,
111 								    rfpath,
112 								    regaddr);
113 			bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
114 			data =
115 			    ((original_value & (~bitmask)) |
116 			     (data << bitshift));
117 		}
118 
119 		_rtl92c_phy_rf_serial_write(hw, rfpath, regaddr, data);
120 	} else {
121 		if (bitmask != RFREG_OFFSET_MASK) {
122 			original_value = _rtl92c_phy_fw_rf_serial_read(hw,
123 								       rfpath,
124 								       regaddr);
125 			bitshift = _rtl92c_phy_calculate_bit_shift(bitmask);
126 			data =
127 			    ((original_value & (~bitmask)) |
128 			     (data << bitshift));
129 		}
130 		_rtl92c_phy_fw_rf_serial_write(hw, rfpath, regaddr, data);
131 	}
132 
133 	spin_unlock(&rtlpriv->locks.rf_lock);
134 
135 	rtl_dbg(rtlpriv, COMP_RF, DBG_TRACE,
136 		"regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
137 		regaddr, bitmask, data, rfpath);
138 }
139 
140 static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
141 {
142 	struct rtl_priv *rtlpriv = rtl_priv(hw);
143 	u32 i;
144 	u32 arraylength;
145 	u32 *ptrarray;
146 
147 	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Read Rtl819XMACPHY_Array\n");
148 	arraylength = MAC_2T_ARRAYLENGTH;
149 	ptrarray = RTL8192CEMAC_2T_ARRAY;
150 	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Img:RTL8192CEMAC_2T_ARRAY\n");
151 	for (i = 0; i < arraylength; i = i + 2)
152 		rtl_write_byte(rtlpriv, ptrarray[i], (u8) ptrarray[i + 1]);
153 	return true;
154 }
155 
156 bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
157 					    u8 configtype)
158 {
159 	int i;
160 	u32 *phy_regarray_table;
161 	u32 *agctab_array_table;
162 	u16 phy_reg_arraylen, agctab_arraylen;
163 	struct rtl_priv *rtlpriv = rtl_priv(hw);
164 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
165 
166 	if (IS_92C_SERIAL(rtlhal->version)) {
167 		agctab_arraylen = AGCTAB_2TARRAYLENGTH;
168 		agctab_array_table = RTL8192CEAGCTAB_2TARRAY;
169 		phy_reg_arraylen = PHY_REG_2TARRAY_LENGTH;
170 		phy_regarray_table = RTL8192CEPHY_REG_2TARRAY;
171 	} else {
172 		agctab_arraylen = AGCTAB_1TARRAYLENGTH;
173 		agctab_array_table = RTL8192CEAGCTAB_1TARRAY;
174 		phy_reg_arraylen = PHY_REG_1TARRAY_LENGTH;
175 		phy_regarray_table = RTL8192CEPHY_REG_1TARRAY;
176 	}
177 	if (configtype == BASEBAND_CONFIG_PHY_REG) {
178 		for (i = 0; i < phy_reg_arraylen; i = i + 2) {
179 			rtl_addr_delay(phy_regarray_table[i]);
180 			rtl_set_bbreg(hw, phy_regarray_table[i], MASKDWORD,
181 				      phy_regarray_table[i + 1]);
182 			udelay(1);
183 			rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
184 				"The phy_regarray_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
185 				phy_regarray_table[i],
186 				phy_regarray_table[i + 1]);
187 		}
188 	} else if (configtype == BASEBAND_CONFIG_AGC_TAB) {
189 		for (i = 0; i < agctab_arraylen; i = i + 2) {
190 			rtl_set_bbreg(hw, agctab_array_table[i], MASKDWORD,
191 				      agctab_array_table[i + 1]);
192 			udelay(1);
193 			rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
194 				"The agctab_array_table[0] is %x Rtl819XPHY_REGArray[1] is %x\n",
195 				agctab_array_table[i],
196 				agctab_array_table[i + 1]);
197 		}
198 	}
199 	return true;
200 }
201 
202 bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
203 					      u8 configtype)
204 {
205 	struct rtl_priv *rtlpriv = rtl_priv(hw);
206 	int i;
207 	u32 *phy_regarray_table_pg;
208 	u16 phy_regarray_pg_len;
209 
210 	phy_regarray_pg_len = PHY_REG_ARRAY_PGLENGTH;
211 	phy_regarray_table_pg = RTL8192CEPHY_REG_ARRAY_PG;
212 
213 	if (configtype == BASEBAND_CONFIG_PHY_REG) {
214 		for (i = 0; i < phy_regarray_pg_len; i = i + 3) {
215 			rtl_addr_delay(phy_regarray_table_pg[i]);
216 
217 			_rtl92c_store_pwrindex_diffrate_offset(hw,
218 					       phy_regarray_table_pg[i],
219 					       phy_regarray_table_pg[i + 1],
220 					       phy_regarray_table_pg[i + 2]);
221 		}
222 	} else {
223 
224 		rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
225 			"configtype != BaseBand_Config_PHY_REG\n");
226 	}
227 	return true;
228 }
229 
230 bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
231 					  enum radio_path rfpath)
232 {
233 
234 	int i;
235 	u32 *radioa_array_table;
236 	u32 *radiob_array_table;
237 	u16 radioa_arraylen, radiob_arraylen;
238 	struct rtl_priv *rtlpriv = rtl_priv(hw);
239 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
240 
241 	if (IS_92C_SERIAL(rtlhal->version)) {
242 		radioa_arraylen = RADIOA_2TARRAYLENGTH;
243 		radioa_array_table = RTL8192CERADIOA_2TARRAY;
244 		radiob_arraylen = RADIOB_2TARRAYLENGTH;
245 		radiob_array_table = RTL8192CE_RADIOB_2TARRAY;
246 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
247 			"Radio_A:RTL8192CERADIOA_2TARRAY\n");
248 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
249 			"Radio_B:RTL8192CE_RADIOB_2TARRAY\n");
250 	} else {
251 		radioa_arraylen = RADIOA_1TARRAYLENGTH;
252 		radioa_array_table = RTL8192CE_RADIOA_1TARRAY;
253 		radiob_arraylen = RADIOB_1TARRAYLENGTH;
254 		radiob_array_table = RTL8192CE_RADIOB_1TARRAY;
255 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
256 			"Radio_A:RTL8192CE_RADIOA_1TARRAY\n");
257 		rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE,
258 			"Radio_B:RTL8192CE_RADIOB_1TARRAY\n");
259 	}
260 	rtl_dbg(rtlpriv, COMP_INIT, DBG_TRACE, "Radio No %x\n", rfpath);
261 	switch (rfpath) {
262 	case RF90_PATH_A:
263 		for (i = 0; i < radioa_arraylen; i = i + 2) {
264 			rtl_rfreg_delay(hw, rfpath, radioa_array_table[i],
265 					RFREG_OFFSET_MASK,
266 					radioa_array_table[i + 1]);
267 		}
268 		break;
269 	case RF90_PATH_B:
270 		for (i = 0; i < radiob_arraylen; i = i + 2) {
271 			rtl_rfreg_delay(hw, rfpath, radiob_array_table[i],
272 					RFREG_OFFSET_MASK,
273 					radiob_array_table[i + 1]);
274 		}
275 		break;
276 	case RF90_PATH_C:
277 	case RF90_PATH_D:
278 		pr_info("Incorrect rfpath %#x\n", rfpath);
279 		break;
280 	default:
281 		pr_info("switch case %#x not processed\n", rfpath);
282 		break;
283 	}
284 	return true;
285 }
286 
287 void rtl92ce_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
288 {
289 	struct rtl_priv *rtlpriv = rtl_priv(hw);
290 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
291 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
292 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
293 	u8 reg_bw_opmode;
294 	u8 reg_prsr_rsc;
295 
296 	rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "Switch to %s bandwidth\n",
297 		rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
298 		"20MHz" : "40MHz");
299 
300 	if (is_hal_stop(rtlhal)) {
301 		rtlphy->set_bwmode_inprogress = false;
302 		return;
303 	}
304 
305 	reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
306 	reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
307 
308 	switch (rtlphy->current_chan_bw) {
309 	case HT_CHANNEL_WIDTH_20:
310 		reg_bw_opmode |= BW_OPMODE_20MHZ;
311 		rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
312 		break;
313 	case HT_CHANNEL_WIDTH_20_40:
314 		reg_bw_opmode &= ~BW_OPMODE_20MHZ;
315 		rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
316 		reg_prsr_rsc =
317 		    (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5);
318 		rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
319 		break;
320 	default:
321 		pr_info("unknown bandwidth: %#X\n", rtlphy->current_chan_bw);
322 		break;
323 	}
324 
325 	switch (rtlphy->current_chan_bw) {
326 	case HT_CHANNEL_WIDTH_20:
327 		rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
328 		rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
329 		rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
330 		break;
331 	case HT_CHANNEL_WIDTH_20_40:
332 		rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
333 		rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
334 
335 		rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND,
336 			      (mac->cur_40_prime_sc >> 1));
337 		rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
338 		rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);
339 
340 		rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
341 			      (mac->cur_40_prime_sc ==
342 			       HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
343 		break;
344 	default:
345 		pr_err("unknown bandwidth: %#X\n",
346 		       rtlphy->current_chan_bw);
347 		break;
348 	}
349 	rtl92ce_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
350 	rtlphy->set_bwmode_inprogress = false;
351 	rtl_dbg(rtlpriv, COMP_SCAN, DBG_TRACE, "<==\n");
352 }
353 
354 void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
355 {
356 	u8 tmpreg;
357 	u32 rf_a_mode = 0, rf_b_mode = 0, lc_cal;
358 	struct rtl_priv *rtlpriv = rtl_priv(hw);
359 
360 	tmpreg = rtl_read_byte(rtlpriv, 0xd03);
361 
362 	if ((tmpreg & 0x70) != 0)
363 		rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
364 	else
365 		rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
366 
367 	if ((tmpreg & 0x70) != 0) {
368 		rf_a_mode = rtl_get_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS);
369 
370 		if (is2t)
371 			rf_b_mode = rtl_get_rfreg(hw, RF90_PATH_B, 0x00,
372 						  MASK12BITS);
373 
374 		rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS,
375 			      (rf_a_mode & 0x8FFFF) | 0x10000);
376 
377 		if (is2t)
378 			rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
379 				      (rf_b_mode & 0x8FFFF) | 0x10000);
380 	}
381 	lc_cal = rtl_get_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS);
382 
383 	rtl_set_rfreg(hw, RF90_PATH_A, 0x18, MASK12BITS, lc_cal | 0x08000);
384 
385 	mdelay(100);
386 
387 	if ((tmpreg & 0x70) != 0) {
388 		rtl_write_byte(rtlpriv, 0xd03, tmpreg);
389 		rtl_set_rfreg(hw, RF90_PATH_A, 0x00, MASK12BITS, rf_a_mode);
390 
391 		if (is2t)
392 			rtl_set_rfreg(hw, RF90_PATH_B, 0x00, MASK12BITS,
393 				      rf_b_mode);
394 	} else {
395 		rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
396 	}
397 }
398 
399 static void _rtl92ce_phy_set_rf_sleep(struct ieee80211_hw *hw)
400 {
401 	u32 u4b_tmp;
402 	u8 delay = 5;
403 	struct rtl_priv *rtlpriv = rtl_priv(hw);
404 
405 	rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
406 	rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
407 	rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
408 	u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
409 	while (u4b_tmp != 0 && delay > 0) {
410 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
411 		rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
412 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
413 		u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
414 		delay--;
415 	}
416 	if (delay == 0) {
417 		rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
418 		rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
419 		rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
420 		rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
421 		rtl_dbg(rtlpriv, COMP_POWER, DBG_TRACE,
422 			"Switch RF timeout !!!\n");
423 		return;
424 	}
425 	rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
426 	rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
427 }
428 
429 static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
430 					    enum rf_pwrstate rfpwr_state)
431 {
432 	struct rtl_priv *rtlpriv = rtl_priv(hw);
433 	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
434 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
435 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
436 	bool bresult = true;
437 	u8 i, queue_id;
438 	struct rtl8192_tx_ring *ring = NULL;
439 
440 	switch (rfpwr_state) {
441 	case ERFON:{
442 			if ((ppsc->rfpwr_state == ERFOFF) &&
443 			    RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
444 				bool rtstatus;
445 				u32 initializecount = 0;
446 
447 				do {
448 					initializecount++;
449 					rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG,
450 						"IPS Set eRf nic enable\n");
451 					rtstatus = rtl_ps_enable_nic(hw);
452 				} while (!rtstatus && (initializecount < 10));
453 				RT_CLEAR_PS_LEVEL(ppsc,
454 						  RT_RF_OFF_LEVL_HALT_NIC);
455 			} else {
456 				rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG,
457 					"Set ERFON slept:%d ms\n",
458 					jiffies_to_msecs(jiffies -
459 						 ppsc->last_sleep_jiffies));
460 				ppsc->last_awake_jiffies = jiffies;
461 				rtl92ce_phy_set_rf_on(hw);
462 			}
463 			if (mac->link_state == MAC80211_LINKED) {
464 				rtlpriv->cfg->ops->led_control(hw,
465 							       LED_CTL_LINK);
466 			} else {
467 				rtlpriv->cfg->ops->led_control(hw,
468 							       LED_CTL_NO_LINK);
469 			}
470 			break;
471 		}
472 	case ERFOFF:{
473 			if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
474 				rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG,
475 					"IPS Set eRf nic disable\n");
476 				rtl_ps_disable_nic(hw);
477 				RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
478 			} else {
479 				if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
480 					rtlpriv->cfg->ops->led_control(hw,
481 							       LED_CTL_NO_LINK);
482 				} else {
483 					rtlpriv->cfg->ops->led_control(hw,
484 							     LED_CTL_POWER_OFF);
485 				}
486 			}
487 			break;
488 		}
489 	case ERFSLEEP:{
490 			if (ppsc->rfpwr_state == ERFOFF)
491 				break;
492 			for (queue_id = 0, i = 0;
493 			     queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
494 				ring = &pcipriv->dev.tx_ring[queue_id];
495 				if (queue_id == BEACON_QUEUE ||
496 				    skb_queue_len(&ring->queue) == 0) {
497 					queue_id++;
498 					continue;
499 				} else {
500 					rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING,
501 						"eRf Off/Sleep: %d times TcbBusyQueue[%d] =%d before doze!\n",
502 						i + 1, queue_id,
503 						skb_queue_len(&ring->queue));
504 
505 					udelay(10);
506 					i++;
507 				}
508 				if (i >= MAX_DOZE_WAITING_TIMES_9x) {
509 					rtl_dbg(rtlpriv, COMP_ERR, DBG_WARNING,
510 						"ERFSLEEP: %d times TcbBusyQueue[%d] = %d !\n",
511 						MAX_DOZE_WAITING_TIMES_9x,
512 						queue_id,
513 						skb_queue_len(&ring->queue));
514 					break;
515 				}
516 			}
517 			rtl_dbg(rtlpriv, COMP_RF, DBG_DMESG,
518 				"Set ERFSLEEP awaked:%d ms\n",
519 				jiffies_to_msecs(jiffies -
520 						 ppsc->last_awake_jiffies));
521 			ppsc->last_sleep_jiffies = jiffies;
522 			_rtl92ce_phy_set_rf_sleep(hw);
523 			break;
524 		}
525 	default:
526 		pr_err("switch case %#x not processed\n",
527 		       rfpwr_state);
528 		bresult = false;
529 		break;
530 	}
531 	if (bresult)
532 		ppsc->rfpwr_state = rfpwr_state;
533 	return bresult;
534 }
535 
536 bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
537 				   enum rf_pwrstate rfpwr_state)
538 {
539 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
540 
541 	bool bresult = false;
542 
543 	if (rfpwr_state == ppsc->rfpwr_state)
544 		return bresult;
545 	bresult = _rtl92ce_phy_set_rf_power_state(hw, rfpwr_state);
546 	return bresult;
547 }
548