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 "../base.h"
7 #include "../stats.h"
8 #include "reg.h"
9 #include "def.h"
10 #include "phy.h"
11 #include "fw.h"
12 #include "trx.h"
13 #include "led.h"
14 
15 static u8 _rtl92se_map_hwqueue_to_fwqueue(struct sk_buff *skb,	u8 skb_queue)
16 {
17 	__le16 fc = rtl_get_fc(skb);
18 
19 	if (unlikely(ieee80211_is_beacon(fc)))
20 		return QSLT_BEACON;
21 	if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
22 		return QSLT_MGNT;
23 	if (ieee80211_is_nullfunc(fc))
24 		return QSLT_HIGH;
25 
26 	/* Kernel commit 1bf4bbb4024dcdab changed EAPOL packets to use
27 	 * queue V0 at priority 7; however, the RTL8192SE appears to have
28 	 * that queue at priority 6
29 	 */
30 	if (skb->priority == 7)
31 		return QSLT_VO;
32 	return skb->priority;
33 }
34 
35 static void _rtl92se_query_rxphystatus(struct ieee80211_hw *hw,
36 				       struct rtl_stats *pstats, u8 *pdesc,
37 				       struct rx_fwinfo *p_drvinfo,
38 				       bool packet_match_bssid,
39 				       bool packet_toself,
40 				       bool packet_beacon)
41 {
42 	struct rtl_priv *rtlpriv = rtl_priv(hw);
43 	struct phy_sts_cck_8192s_t *cck_buf;
44 	struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
45 	s8 rx_pwr_all = 0, rx_pwr[4];
46 	u8 rf_rx_num = 0, evm, pwdb_all;
47 	u8 i, max_spatial_stream;
48 	u32 rssi, total_rssi = 0;
49 	bool is_cck = pstats->is_cck;
50 
51 	pstats->packet_matchbssid = packet_match_bssid;
52 	pstats->packet_toself = packet_toself;
53 	pstats->packet_beacon = packet_beacon;
54 	pstats->rx_mimo_sig_qual[0] = -1;
55 	pstats->rx_mimo_sig_qual[1] = -1;
56 
57 	if (is_cck) {
58 		u8 report, cck_highpwr;
59 		cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
60 
61 		if (ppsc->rfpwr_state == ERFON)
62 			cck_highpwr = (u8) rtl_get_bbreg(hw,
63 						RFPGA0_XA_HSSIPARAMETER2,
64 						0x200);
65 		else
66 			cck_highpwr = false;
67 
68 		if (!cck_highpwr) {
69 			u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
70 			report = cck_buf->cck_agc_rpt & 0xc0;
71 			report = report >> 6;
72 			switch (report) {
73 			case 0x3:
74 				rx_pwr_all = -40 - (cck_agc_rpt & 0x3e);
75 				break;
76 			case 0x2:
77 				rx_pwr_all = -20 - (cck_agc_rpt & 0x3e);
78 				break;
79 			case 0x1:
80 				rx_pwr_all = -2 - (cck_agc_rpt & 0x3e);
81 				break;
82 			case 0x0:
83 				rx_pwr_all = 14 - (cck_agc_rpt & 0x3e);
84 				break;
85 			}
86 		} else {
87 			u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
88 			report = p_drvinfo->cfosho[0] & 0x60;
89 			report = report >> 5;
90 			switch (report) {
91 			case 0x3:
92 				rx_pwr_all = -40 - ((cck_agc_rpt & 0x1f) << 1);
93 				break;
94 			case 0x2:
95 				rx_pwr_all = -20 - ((cck_agc_rpt & 0x1f) << 1);
96 				break;
97 			case 0x1:
98 				rx_pwr_all = -2 - ((cck_agc_rpt & 0x1f) << 1);
99 				break;
100 			case 0x0:
101 				rx_pwr_all = 14 - ((cck_agc_rpt & 0x1f) << 1);
102 				break;
103 			}
104 		}
105 
106 		pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
107 
108 		/* CCK gain is smaller than OFDM/MCS gain,  */
109 		/* so we add gain diff by experiences, the val is 6 */
110 		pwdb_all += 6;
111 		if (pwdb_all > 100)
112 			pwdb_all = 100;
113 		/* modify the offset to make the same gain index with OFDM. */
114 		if (pwdb_all > 34 && pwdb_all <= 42)
115 			pwdb_all -= 2;
116 		else if (pwdb_all > 26 && pwdb_all <= 34)
117 			pwdb_all -= 6;
118 		else if (pwdb_all > 14 && pwdb_all <= 26)
119 			pwdb_all -= 8;
120 		else if (pwdb_all > 4 && pwdb_all <= 14)
121 			pwdb_all -= 4;
122 
123 		pstats->rx_pwdb_all = pwdb_all;
124 		pstats->recvsignalpower = rx_pwr_all;
125 
126 		if (packet_match_bssid) {
127 			u8 sq;
128 			if (pstats->rx_pwdb_all > 40) {
129 				sq = 100;
130 			} else {
131 				sq = cck_buf->sq_rpt;
132 				if (sq > 64)
133 					sq = 0;
134 				else if (sq < 20)
135 					sq = 100;
136 				else
137 					sq = ((64 - sq) * 100) / 44;
138 			}
139 
140 			pstats->signalquality = sq;
141 			pstats->rx_mimo_sig_qual[0] = sq;
142 			pstats->rx_mimo_sig_qual[1] = -1;
143 		}
144 	} else {
145 		rtlpriv->dm.rfpath_rxenable[0] =
146 		    rtlpriv->dm.rfpath_rxenable[1] = true;
147 		for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
148 			if (rtlpriv->dm.rfpath_rxenable[i])
149 				rf_rx_num++;
150 
151 			rx_pwr[i] = ((p_drvinfo->gain_trsw[i] &
152 				    0x3f) * 2) - 110;
153 			rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
154 			total_rssi += rssi;
155 			rtlpriv->stats.rx_snr_db[i] =
156 					 (long)(p_drvinfo->rxsnr[i] / 2);
157 
158 			if (packet_match_bssid)
159 				pstats->rx_mimo_signalstrength[i] = (u8) rssi;
160 		}
161 
162 		rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
163 		pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
164 		pstats->rx_pwdb_all = pwdb_all;
165 		pstats->rxpower = rx_pwr_all;
166 		pstats->recvsignalpower = rx_pwr_all;
167 
168 		if (pstats->is_ht && pstats->rate >= DESC_RATEMCS8 &&
169 		    pstats->rate <= DESC_RATEMCS15)
170 			max_spatial_stream = 2;
171 		else
172 			max_spatial_stream = 1;
173 
174 		for (i = 0; i < max_spatial_stream; i++) {
175 			evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
176 
177 			if (packet_match_bssid) {
178 				if (i == 0)
179 					pstats->signalquality = (u8)(evm &
180 								 0xff);
181 				pstats->rx_mimo_sig_qual[i] = (u8) (evm & 0xff);
182 			}
183 		}
184 	}
185 
186 	if (is_cck)
187 		pstats->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
188 					 pwdb_all));
189 	else if (rf_rx_num != 0)
190 		pstats->signalstrength = (u8) (rtl_signal_scale_mapping(hw,
191 				total_rssi /= rf_rx_num));
192 }
193 
194 static void _rtl92se_translate_rx_signal_stuff(struct ieee80211_hw *hw,
195 		struct sk_buff *skb, struct rtl_stats *pstats,
196 		u8 *pdesc, struct rx_fwinfo *p_drvinfo)
197 {
198 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
199 	struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
200 
201 	struct ieee80211_hdr *hdr;
202 	u8 *tmp_buf;
203 	u8 *praddr;
204 	__le16 fc;
205 	u16 type, cfc;
206 	bool packet_matchbssid, packet_toself, packet_beacon = false;
207 
208 	tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
209 
210 	hdr = (struct ieee80211_hdr *)tmp_buf;
211 	fc = hdr->frame_control;
212 	cfc = le16_to_cpu(fc);
213 	type = WLAN_FC_GET_TYPE(fc);
214 	praddr = hdr->addr1;
215 
216 	packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
217 	     ether_addr_equal(mac->bssid,
218 			      (cfc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
219 			      (cfc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
220 			      hdr->addr3) &&
221 	     (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
222 
223 	packet_toself = packet_matchbssid &&
224 	    ether_addr_equal(praddr, rtlefuse->dev_addr);
225 
226 	if (ieee80211_is_beacon(fc))
227 		packet_beacon = true;
228 
229 	_rtl92se_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
230 			packet_matchbssid, packet_toself, packet_beacon);
231 	rtl_process_phyinfo(hw, tmp_buf, pstats);
232 }
233 
234 bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
235 			   struct ieee80211_rx_status *rx_status, u8 *pdesc,
236 			   struct sk_buff *skb)
237 {
238 	struct rx_fwinfo *p_drvinfo;
239 	u32 phystatus = (u32)GET_RX_STATUS_DESC_PHY_STATUS(pdesc);
240 	struct ieee80211_hdr *hdr;
241 
242 	stats->length = (u16)GET_RX_STATUS_DESC_PKT_LEN(pdesc);
243 	stats->rx_drvinfo_size = (u8)GET_RX_STATUS_DESC_DRVINFO_SIZE(pdesc) * 8;
244 	stats->rx_bufshift = (u8)(GET_RX_STATUS_DESC_SHIFT(pdesc) & 0x03);
245 	stats->icv = (u16)GET_RX_STATUS_DESC_ICV(pdesc);
246 	stats->crc = (u16)GET_RX_STATUS_DESC_CRC32(pdesc);
247 	stats->hwerror = (u16)(stats->crc | stats->icv);
248 	stats->decrypted = !GET_RX_STATUS_DESC_SWDEC(pdesc);
249 
250 	stats->rate = (u8)GET_RX_STATUS_DESC_RX_MCS(pdesc);
251 	stats->shortpreamble = (u16)GET_RX_STATUS_DESC_SPLCP(pdesc);
252 	stats->isampdu = (bool)(GET_RX_STATUS_DESC_PAGGR(pdesc) == 1);
253 	stats->isfirst_ampdu = (bool) ((GET_RX_STATUS_DESC_PAGGR(pdesc) == 1)
254 			       && (GET_RX_STATUS_DESC_FAGGR(pdesc) == 1));
255 	stats->timestamp_low = GET_RX_STATUS_DESC_TSFL(pdesc);
256 	stats->rx_is40mhzpacket = (bool)GET_RX_STATUS_DESC_BW(pdesc);
257 	stats->is_ht = (bool)GET_RX_STATUS_DESC_RX_HT(pdesc);
258 	stats->is_cck = SE_RX_HAL_IS_CCK_RATE(pdesc);
259 
260 	if (stats->hwerror)
261 		return false;
262 
263 	rx_status->freq = hw->conf.chandef.chan->center_freq;
264 	rx_status->band = hw->conf.chandef.chan->band;
265 
266 	if (stats->crc)
267 		rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
268 
269 	if (stats->rx_is40mhzpacket)
270 		rx_status->bw = RATE_INFO_BW_40;
271 
272 	if (stats->is_ht)
273 		rx_status->encoding = RX_ENC_HT;
274 
275 	rx_status->flag |= RX_FLAG_MACTIME_START;
276 
277 	/* hw will set stats->decrypted true, if it finds the
278 	 * frame is open data frame or mgmt frame,
279 	 * hw will not decrypt robust managment frame
280 	 * for IEEE80211w but still set stats->decrypted
281 	 * true, so here we should set it back to undecrypted
282 	 * for IEEE80211w frame, and mac80211 sw will help
283 	 * to decrypt it */
284 	if (stats->decrypted) {
285 		hdr = (struct ieee80211_hdr *)(skb->data +
286 		       stats->rx_drvinfo_size + stats->rx_bufshift);
287 
288 		if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
289 			(ieee80211_has_protected(hdr->frame_control)))
290 			rx_status->flag &= ~RX_FLAG_DECRYPTED;
291 		else
292 			rx_status->flag |= RX_FLAG_DECRYPTED;
293 	}
294 
295 	rx_status->rate_idx = rtlwifi_rate_mapping(hw, stats->is_ht,
296 						   false, stats->rate);
297 
298 	rx_status->mactime = stats->timestamp_low;
299 	if (phystatus) {
300 		p_drvinfo = (struct rx_fwinfo *)(skb->data +
301 						 stats->rx_bufshift);
302 		_rtl92se_translate_rx_signal_stuff(hw, skb, stats, pdesc,
303 						   p_drvinfo);
304 	}
305 
306 	/*rx_status->qual = stats->signal; */
307 	rx_status->signal = stats->recvsignalpower + 10;
308 
309 	return true;
310 }
311 
312 void rtl92se_tx_fill_desc(struct ieee80211_hw *hw,
313 		struct ieee80211_hdr *hdr, u8 *pdesc_tx,
314 		u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
315 		struct ieee80211_sta *sta,
316 		struct sk_buff *skb,
317 		u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
318 {
319 	struct rtl_priv *rtlpriv = rtl_priv(hw);
320 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
321 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
322 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
323 	u8 *pdesc = pdesc_tx;
324 	u16 seq_number;
325 	__le16 fc = hdr->frame_control;
326 	u8 reserved_macid = 0;
327 	u8 fw_qsel = _rtl92se_map_hwqueue_to_fwqueue(skb, hw_queue);
328 	bool firstseg = (!(hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)));
329 	bool lastseg = (!(hdr->frame_control &
330 			cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)));
331 	dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
332 		    PCI_DMA_TODEVICE);
333 	u8 bw_40 = 0;
334 
335 	if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
336 		RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
337 			 "DMA mapping error\n");
338 		return;
339 	}
340 	if (mac->opmode == NL80211_IFTYPE_STATION) {
341 		bw_40 = mac->bw_40;
342 	} else if (mac->opmode == NL80211_IFTYPE_AP ||
343 		mac->opmode == NL80211_IFTYPE_ADHOC) {
344 		if (sta)
345 			bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
346 	}
347 
348 	seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
349 
350 	rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
351 
352 	CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE_RTL8192S);
353 
354 	if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
355 		firstseg = true;
356 		lastseg = true;
357 	}
358 
359 	if (firstseg) {
360 		if (rtlpriv->dm.useramask) {
361 			/* set txdesc macId */
362 			if (ptcb_desc->mac_id < 32) {
363 				SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
364 				reserved_macid |= ptcb_desc->mac_id;
365 			}
366 		}
367 		SET_TX_DESC_RSVD_MACID(pdesc, reserved_macid);
368 
369 		SET_TX_DESC_TXHT(pdesc, ((ptcb_desc->hw_rate >=
370 				 DESC_RATEMCS0) ? 1 : 0));
371 
372 		if (rtlhal->version == VERSION_8192S_ACUT) {
373 			if (ptcb_desc->hw_rate == DESC_RATE1M ||
374 			    ptcb_desc->hw_rate  == DESC_RATE2M ||
375 			    ptcb_desc->hw_rate == DESC_RATE5_5M ||
376 			    ptcb_desc->hw_rate == DESC_RATE11M) {
377 				ptcb_desc->hw_rate = DESC_RATE12M;
378 			}
379 		}
380 
381 		SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
382 
383 		if (ptcb_desc->use_shortgi || ptcb_desc->use_shortpreamble)
384 			SET_TX_DESC_TX_SHORT(pdesc, 0);
385 
386 		/* Aggregation related */
387 		if (info->flags & IEEE80211_TX_CTL_AMPDU)
388 			SET_TX_DESC_AGG_ENABLE(pdesc, 1);
389 
390 		/* For AMPDU, we must insert SSN into TX_DESC */
391 		SET_TX_DESC_SEQ(pdesc, seq_number);
392 
393 		/* Protection mode related */
394 		/* For 92S, if RTS/CTS are set, HW will execute RTS. */
395 		/* We choose only one protection mode to execute */
396 		SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
397 				!ptcb_desc->cts_enable) ? 1 : 0));
398 		SET_TX_DESC_CTS_ENABLE(pdesc, ((ptcb_desc->cts_enable) ?
399 				       1 : 0));
400 		SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
401 
402 		SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
403 		SET_TX_DESC_RTS_BANDWIDTH(pdesc, 0);
404 		SET_TX_DESC_RTS_SUB_CARRIER(pdesc, ptcb_desc->rts_sc);
405 		SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <=
406 		       DESC_RATE54M) ?
407 		       (ptcb_desc->rts_use_shortpreamble ? 1 : 0)
408 		       : (ptcb_desc->rts_use_shortgi ? 1 : 0)));
409 
410 
411 		/* Set Bandwidth and sub-channel settings. */
412 		if (bw_40) {
413 			if (ptcb_desc->packet_bw) {
414 				SET_TX_DESC_TX_BANDWIDTH(pdesc, 1);
415 				/* use duplicated mode */
416 				SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
417 			} else {
418 				SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
419 				SET_TX_DESC_TX_SUB_CARRIER(pdesc,
420 						   mac->cur_40_prime_sc);
421 			}
422 		} else {
423 			SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
424 			SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
425 		}
426 
427 		/* 3 Fill necessary field in First Descriptor */
428 		/*DWORD 0*/
429 		SET_TX_DESC_LINIP(pdesc, 0);
430 		SET_TX_DESC_OFFSET(pdesc, 32);
431 		SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
432 
433 		/*DWORD 1*/
434 		SET_TX_DESC_RA_BRSR_ID(pdesc, ptcb_desc->ratr_index);
435 
436 		/* Fill security related */
437 		if (info->control.hw_key) {
438 			struct ieee80211_key_conf *keyconf;
439 
440 			keyconf = info->control.hw_key;
441 			switch (keyconf->cipher) {
442 			case WLAN_CIPHER_SUITE_WEP40:
443 			case WLAN_CIPHER_SUITE_WEP104:
444 				SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
445 				break;
446 			case WLAN_CIPHER_SUITE_TKIP:
447 				SET_TX_DESC_SEC_TYPE(pdesc, 0x2);
448 				break;
449 			case WLAN_CIPHER_SUITE_CCMP:
450 				SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
451 				break;
452 			default:
453 				SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
454 				break;
455 
456 			}
457 		}
458 
459 		/* Set Packet ID */
460 		SET_TX_DESC_PACKET_ID(pdesc, 0);
461 
462 		/* We will assign magement queue to BK. */
463 		SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
464 
465 		/* Alwasy enable all rate fallback range */
466 		SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
467 
468 		/* Fix: I don't kown why hw use 6.5M to tx when set it */
469 		SET_TX_DESC_USER_RATE(pdesc,
470 				      ptcb_desc->use_driver_rate ? 1 : 0);
471 
472 		/* Set NON_QOS bit. */
473 		if (!ieee80211_is_data_qos(fc))
474 			SET_TX_DESC_NON_QOS(pdesc, 1);
475 
476 	}
477 
478 	/* Fill fields that are required to be initialized
479 	 * in all of the descriptors */
480 	/*DWORD 0 */
481 	SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
482 	SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
483 
484 	/* DWORD 7 */
485 	SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
486 
487 	/* DOWRD 8 */
488 	SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
489 
490 	RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
491 }
492 
493 void rtl92se_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
494 	bool firstseg, bool lastseg, struct sk_buff *skb)
495 {
496 	struct rtl_priv *rtlpriv = rtl_priv(hw);
497 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
498 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
499 	struct rtl_tcb_desc *tcb_desc = (struct rtl_tcb_desc *)(skb->cb);
500 
501 	dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
502 			PCI_DMA_TODEVICE);
503 
504 	if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
505 		RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
506 			 "DMA mapping error\n");
507 		return;
508 	}
509 	/* Clear all status	*/
510 	CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_CMDDESC_SIZE_RTL8192S);
511 
512 	/* This bit indicate this packet is used for FW download. */
513 	if (tcb_desc->cmd_or_init == DESC_PACKET_TYPE_INIT) {
514 		/* For firmware downlaod we only need to set LINIP */
515 		SET_TX_DESC_LINIP(pdesc, tcb_desc->last_inipkt);
516 
517 		/* 92SE must set as 1 for firmware download HW DMA error */
518 		SET_TX_DESC_FIRST_SEG(pdesc, 1);
519 		SET_TX_DESC_LAST_SEG(pdesc, 1);
520 
521 		/* 92SE need not to set TX packet size when firmware download */
522 		SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
523 		SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
524 		SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
525 
526 		wmb();
527 		SET_TX_DESC_OWN(pdesc, 1);
528 	} else { /* H2C Command Desc format (Host TXCMD) */
529 		/* 92SE must set as 1 for firmware download HW DMA error */
530 		SET_TX_DESC_FIRST_SEG(pdesc, 1);
531 		SET_TX_DESC_LAST_SEG(pdesc, 1);
532 
533 		SET_TX_DESC_OFFSET(pdesc, 0x20);
534 
535 		/* Buffer size + command header */
536 		SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
537 		/* Fixed queue of H2C command */
538 		SET_TX_DESC_QUEUE_SEL(pdesc, 0x13);
539 
540 		SET_BITS_TO_LE_4BYTE(skb->data, 24, 7, rtlhal->h2c_txcmd_seq);
541 
542 		SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
543 		SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
544 
545 		wmb();
546 		SET_TX_DESC_OWN(pdesc, 1);
547 
548 	}
549 }
550 
551 void rtl92se_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
552 		      u8 desc_name, u8 *val)
553 {
554 	if (istx) {
555 		switch (desc_name) {
556 		case HW_DESC_OWN:
557 			wmb();
558 			SET_TX_DESC_OWN(pdesc, 1);
559 			break;
560 		case HW_DESC_TX_NEXTDESC_ADDR:
561 			SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
562 			break;
563 		default:
564 			WARN_ONCE(true, "rtl8192se: ERR txdesc :%d not processed\n",
565 				  desc_name);
566 			break;
567 		}
568 	} else {
569 		switch (desc_name) {
570 		case HW_DESC_RXOWN:
571 			wmb();
572 			SET_RX_STATUS_DESC_OWN(pdesc, 1);
573 			break;
574 		case HW_DESC_RXBUFF_ADDR:
575 			SET_RX_STATUS__DESC_BUFF_ADDR(pdesc, *(u32 *) val);
576 			break;
577 		case HW_DESC_RXPKT_LEN:
578 			SET_RX_STATUS_DESC_PKT_LEN(pdesc, *(u32 *) val);
579 			break;
580 		case HW_DESC_RXERO:
581 			SET_RX_STATUS_DESC_EOR(pdesc, 1);
582 			break;
583 		default:
584 			WARN_ONCE(true, "rtl8192se: ERR rxdesc :%d not processed\n",
585 				  desc_name);
586 			break;
587 		}
588 	}
589 }
590 
591 u64 rtl92se_get_desc(struct ieee80211_hw *hw,
592 		     u8 *desc, bool istx, u8 desc_name)
593 {
594 	u32 ret = 0;
595 
596 	if (istx) {
597 		switch (desc_name) {
598 		case HW_DESC_OWN:
599 			ret = GET_TX_DESC_OWN(desc);
600 			break;
601 		case HW_DESC_TXBUFF_ADDR:
602 			ret = GET_TX_DESC_TX_BUFFER_ADDRESS(desc);
603 			break;
604 		default:
605 			WARN_ONCE(true, "rtl8192se: ERR txdesc :%d not processed\n",
606 				  desc_name);
607 			break;
608 		}
609 	} else {
610 		switch (desc_name) {
611 		case HW_DESC_OWN:
612 			ret = GET_RX_STATUS_DESC_OWN(desc);
613 			break;
614 		case HW_DESC_RXPKT_LEN:
615 			ret = GET_RX_STATUS_DESC_PKT_LEN(desc);
616 			break;
617 		case HW_DESC_RXBUFF_ADDR:
618 			ret = GET_RX_STATUS_DESC_BUFF_ADDR(desc);
619 			break;
620 		default:
621 			WARN_ONCE(true, "rtl8192se: ERR rxdesc :%d not processed\n",
622 				  desc_name);
623 			break;
624 		}
625 	}
626 	return ret;
627 }
628 
629 void rtl92se_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
630 {
631 	struct rtl_priv *rtlpriv = rtl_priv(hw);
632 	rtl_write_word(rtlpriv, TP_POLL, BIT(0) << (hw_queue));
633 }
634