xref: /linux/drivers/net/wireless/realtek/rtlwifi/rtl8192se/trx.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
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, __le32 *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 		__le32 *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 	struct ieee80211_hdr *hdr;
201 	u8 *tmp_buf;
202 	u8 *praddr;
203 	__le16 fc;
204 	u16 type, cfc;
205 	bool packet_matchbssid, packet_toself, packet_beacon = false;
206 
207 	tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
208 
209 	hdr = (struct ieee80211_hdr *)tmp_buf;
210 	fc = hdr->frame_control;
211 	cfc = le16_to_cpu(fc);
212 	type = WLAN_FC_GET_TYPE(fc);
213 	praddr = hdr->addr1;
214 
215 	packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
216 	     ether_addr_equal(mac->bssid,
217 			      (cfc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
218 			      (cfc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
219 			      hdr->addr3) &&
220 	     (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
221 
222 	packet_toself = packet_matchbssid &&
223 	    ether_addr_equal(praddr, rtlefuse->dev_addr);
224 
225 	if (ieee80211_is_beacon(fc))
226 		packet_beacon = true;
227 
228 	_rtl92se_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
229 			packet_matchbssid, packet_toself, packet_beacon);
230 	rtl_process_phyinfo(hw, tmp_buf, pstats);
231 }
232 
233 bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
234 			   struct ieee80211_rx_status *rx_status, u8 *pdesc8,
235 			   struct sk_buff *skb)
236 {
237 	struct rx_fwinfo *p_drvinfo;
238 	__le32 *pdesc = (__le32 *)pdesc8;
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 *pdesc8,
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 	__le32 *pdesc = (__le32 *)pdesc8;
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 = dma_map_single(&rtlpci->pdev->dev, skb->data,
332 					    skb->len, DMA_TO_DEVICE);
333 	u8 bw_40 = 0;
334 
335 	if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
336 		rtl_dbg(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->deflink.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) ?
398 					       1 : 0));
399 		set_tx_desc_cts_enable(pdesc, ((ptcb_desc->cts_enable) ?
400 				       1 : 0));
401 		set_tx_desc_rts_stbc(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
402 
403 		set_tx_desc_rts_rate(pdesc, ptcb_desc->rts_rate);
404 		set_tx_desc_rts_bandwidth(pdesc, 0);
405 		set_tx_desc_rts_sub_carrier(pdesc, ptcb_desc->rts_sc);
406 		set_tx_desc_rts_short(pdesc, ((ptcb_desc->rts_rate <=
407 		       DESC_RATE54M) ?
408 		       (ptcb_desc->rts_use_shortpreamble ? 1 : 0)
409 		       : (ptcb_desc->rts_use_shortgi ? 1 : 0)));
410 
411 
412 		/* Set Bandwidth and sub-channel settings. */
413 		if (bw_40) {
414 			if (ptcb_desc->packet_bw) {
415 				set_tx_desc_tx_bandwidth(pdesc, 1);
416 				/* use duplicated mode */
417 				set_tx_desc_tx_sub_carrier(pdesc, 0);
418 			} else {
419 				set_tx_desc_tx_bandwidth(pdesc, 0);
420 				set_tx_desc_tx_sub_carrier(pdesc,
421 						   mac->cur_40_prime_sc);
422 			}
423 		} else {
424 			set_tx_desc_tx_bandwidth(pdesc, 0);
425 			set_tx_desc_tx_sub_carrier(pdesc, 0);
426 		}
427 
428 		/* 3 Fill necessary field in First Descriptor */
429 		/*DWORD 0*/
430 		set_tx_desc_linip(pdesc, 0);
431 		set_tx_desc_offset(pdesc, 32);
432 		set_tx_desc_pkt_size(pdesc, (u16)skb->len);
433 
434 		/*DWORD 1*/
435 		set_tx_desc_ra_brsr_id(pdesc, ptcb_desc->ratr_index);
436 
437 		/* Fill security related */
438 		if (info->control.hw_key) {
439 			struct ieee80211_key_conf *keyconf;
440 
441 			keyconf = info->control.hw_key;
442 			switch (keyconf->cipher) {
443 			case WLAN_CIPHER_SUITE_WEP40:
444 			case WLAN_CIPHER_SUITE_WEP104:
445 				set_tx_desc_sec_type(pdesc, 0x1);
446 				break;
447 			case WLAN_CIPHER_SUITE_TKIP:
448 				set_tx_desc_sec_type(pdesc, 0x2);
449 				break;
450 			case WLAN_CIPHER_SUITE_CCMP:
451 				set_tx_desc_sec_type(pdesc, 0x3);
452 				break;
453 			default:
454 				set_tx_desc_sec_type(pdesc, 0x0);
455 				break;
456 
457 			}
458 		}
459 
460 		/* Set Packet ID */
461 		set_tx_desc_packet_id(pdesc, 0);
462 
463 		/* We will assign magement queue to BK. */
464 		set_tx_desc_queue_sel(pdesc, fw_qsel);
465 
466 		/* Alwasy enable all rate fallback range */
467 		set_tx_desc_data_rate_fb_limit(pdesc, 0x1F);
468 
469 		/* Fix: I don't kown why hw use 6.5M to tx when set it */
470 		set_tx_desc_user_rate(pdesc,
471 				      ptcb_desc->use_driver_rate ? 1 : 0);
472 
473 		/* Set NON_QOS bit. */
474 		if (!ieee80211_is_data_qos(fc))
475 			set_tx_desc_non_qos(pdesc, 1);
476 
477 	}
478 
479 	/* Fill fields that are required to be initialized
480 	 * in all of the descriptors */
481 	/*DWORD 0 */
482 	set_tx_desc_first_seg(pdesc, (firstseg ? 1 : 0));
483 	set_tx_desc_last_seg(pdesc, (lastseg ? 1 : 0));
484 
485 	/* DWORD 7 */
486 	set_tx_desc_tx_buffer_size(pdesc, (u16)skb->len);
487 
488 	/* DOWRD 8 */
489 	set_tx_desc_tx_buffer_address(pdesc, mapping);
490 
491 	rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
492 }
493 
494 void rtl92se_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc8,
495 			     bool firstseg, bool lastseg, struct sk_buff *skb)
496 {
497 	struct rtl_priv *rtlpriv = rtl_priv(hw);
498 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
499 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
500 	struct rtl_tcb_desc *tcb_desc = (struct rtl_tcb_desc *)(skb->cb);
501 	__le32 *pdesc = (__le32 *)pdesc8;
502 
503 	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
504 					    skb->len, DMA_TO_DEVICE);
505 
506 	if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
507 		rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
508 			"DMA mapping error\n");
509 		return;
510 	}
511 	/* Clear all status	*/
512 	CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_CMDDESC_SIZE_RTL8192S);
513 
514 	/* This bit indicate this packet is used for FW download. */
515 	if (tcb_desc->cmd_or_init == DESC_PACKET_TYPE_INIT) {
516 		/* For firmware download we only need to set LINIP */
517 		set_tx_desc_linip(pdesc, tcb_desc->last_inipkt);
518 
519 		/* 92SE must set as 1 for firmware download HW DMA error */
520 		set_tx_desc_first_seg(pdesc, 1);
521 		set_tx_desc_last_seg(pdesc, 1);
522 
523 		/* 92SE need not to set TX packet size when firmware download */
524 		set_tx_desc_pkt_size(pdesc, (u16)(skb->len));
525 		set_tx_desc_tx_buffer_size(pdesc, (u16)(skb->len));
526 		set_tx_desc_tx_buffer_address(pdesc, mapping);
527 
528 		wmb();
529 		set_tx_desc_own(pdesc, 1);
530 	} else { /* H2C Command Desc format (Host TXCMD) */
531 		/* 92SE must set as 1 for firmware download HW DMA error */
532 		set_tx_desc_first_seg(pdesc, 1);
533 		set_tx_desc_last_seg(pdesc, 1);
534 
535 		set_tx_desc_offset(pdesc, 0x20);
536 
537 		/* Buffer size + command header */
538 		set_tx_desc_pkt_size(pdesc, (u16)(skb->len));
539 		/* Fixed queue of H2C command */
540 		set_tx_desc_queue_sel(pdesc, 0x13);
541 
542 		le32p_replace_bits((__le32 *)skb->data, rtlhal->h2c_txcmd_seq,
543 				   GENMASK(30, 24));
544 		set_tx_desc_tx_buffer_size(pdesc, (u16)(skb->len));
545 		set_tx_desc_tx_buffer_address(pdesc, mapping);
546 
547 		wmb();
548 		set_tx_desc_own(pdesc, 1);
549 
550 	}
551 }
552 
553 void rtl92se_set_desc(struct ieee80211_hw *hw, u8 *pdesc8, bool istx,
554 		      u8 desc_name, u8 *val)
555 {
556 	__le32 *pdesc = (__le32 *)pdesc8;
557 
558 	if (istx) {
559 		switch (desc_name) {
560 		case HW_DESC_OWN:
561 			wmb();
562 			set_tx_desc_own(pdesc, 1);
563 			break;
564 		case HW_DESC_TX_NEXTDESC_ADDR:
565 			set_tx_desc_next_desc_address(pdesc, *(u32 *)val);
566 			break;
567 		default:
568 			WARN_ONCE(true, "rtl8192se: ERR txdesc :%d not processed\n",
569 				  desc_name);
570 			break;
571 		}
572 	} else {
573 		switch (desc_name) {
574 		case HW_DESC_RXOWN:
575 			wmb();
576 			set_rx_status_desc_own(pdesc, 1);
577 			break;
578 		case HW_DESC_RXBUFF_ADDR:
579 			set_rx_status__desc_buff_addr(pdesc, *(u32 *)val);
580 			break;
581 		case HW_DESC_RXPKT_LEN:
582 			set_rx_status_desc_pkt_len(pdesc, *(u32 *)val);
583 			break;
584 		case HW_DESC_RXERO:
585 			set_rx_status_desc_eor(pdesc, 1);
586 			break;
587 		default:
588 			WARN_ONCE(true, "rtl8192se: ERR rxdesc :%d not processed\n",
589 				  desc_name);
590 			break;
591 		}
592 	}
593 }
594 
595 u64 rtl92se_get_desc(struct ieee80211_hw *hw,
596 		     u8 *desc8, bool istx, u8 desc_name)
597 {
598 	u32 ret = 0;
599 	__le32 *desc = (__le32 *)desc8;
600 
601 	if (istx) {
602 		switch (desc_name) {
603 		case HW_DESC_OWN:
604 			ret = get_tx_desc_own(desc);
605 			break;
606 		case HW_DESC_TXBUFF_ADDR:
607 			ret = get_tx_desc_tx_buffer_address(desc);
608 			break;
609 		default:
610 			WARN_ONCE(true, "rtl8192se: ERR txdesc :%d not processed\n",
611 				  desc_name);
612 			break;
613 		}
614 	} else {
615 		switch (desc_name) {
616 		case HW_DESC_OWN:
617 			ret = get_rx_status_desc_own(desc);
618 			break;
619 		case HW_DESC_RXPKT_LEN:
620 			ret = get_rx_status_desc_pkt_len(desc);
621 			break;
622 		case HW_DESC_RXBUFF_ADDR:
623 			ret = get_rx_status_desc_buff_addr(desc);
624 			break;
625 		default:
626 			WARN_ONCE(true, "rtl8192se: ERR rxdesc :%d not processed\n",
627 				  desc_name);
628 			break;
629 		}
630 	}
631 	return ret;
632 }
633 
634 void rtl92se_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
635 {
636 	struct rtl_priv *rtlpriv = rtl_priv(hw);
637 	rtl_write_word(rtlpriv, TP_POLL, BIT(0) << (hw_queue));
638 }
639