1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
15 static u8 _rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
17 __le16 fc = rtl_get_fc(skb);
19 if (unlikely(ieee80211_is_beacon(fc)))
21 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
27 static void _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw,
28 struct rtl_stats *pstatus, u8 *pdesc,
29 struct rx_fwinfo_88e *p_drvinfo,
30 bool bpacket_match_bssid,
31 bool bpacket_toself, bool packet_beacon)
33 struct rtl_priv *rtlpriv = rtl_priv(hw);
34 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
35 struct phy_sts_cck_8192s_t *cck_buf;
36 struct phy_status_rpt *phystrpt =
37 (struct phy_status_rpt *)p_drvinfo;
38 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
39 s8 rx_pwr_all = 0, rx_pwr[4];
40 u8 rf_rx_num = 0, evm, pwdb_all;
41 u8 i, max_spatial_stream;
42 u32 rssi, total_rssi = 0;
43 bool is_cck = pstatus->is_cck;
46 /* Record it for next packet processing */
47 pstatus->packet_matchbssid = bpacket_match_bssid;
48 pstatus->packet_toself = bpacket_toself;
49 pstatus->packet_beacon = packet_beacon;
50 pstatus->rx_mimo_signalquality[0] = -1;
51 pstatus->rx_mimo_signalquality[1] = -1;
56 /* CCK Driver info Structure is not the same as OFDM packet. */
57 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
58 cck_agc_rpt = cck_buf->cck_agc_rpt;
60 /* (1)Hardware does not provide RSSI for CCK
61 * (2)PWDB, Average PWDB cacluated by
62 * hardware (for rate adaptive)
64 if (ppsc->rfpwr_state == ERFON)
66 (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
71 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
72 vga_idx = (cck_agc_rpt & 0x1f);
77 rx_pwr_all = -100 + 2*(27-vga_idx);
83 rx_pwr_all = -48 + 2*(2-vga_idx);
87 rx_pwr_all = -42 + 2*(7-vga_idx);
91 rx_pwr_all = -36 + 2*(7-vga_idx);
95 rx_pwr_all = -24 + 2*(7-vga_idx);
100 rx_pwr_all = -12 + 2*(5-vga_idx);
102 rx_pwr_all = -6 + 2*(5-vga_idx);
105 rx_pwr_all = 8-2*vga_idx;
108 rx_pwr_all = 14-2*vga_idx;
114 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
115 /* CCK gain is smaller than OFDM/MCS gain, */
116 /* so we add gain diff by experiences, the val is 6 */
120 /* modify the offset to make the same
121 * gain index with OFDM.
123 if (pwdb_all > 34 && pwdb_all <= 42)
125 else if (pwdb_all > 26 && pwdb_all <= 34)
127 else if (pwdb_all > 14 && pwdb_all <= 26)
129 else if (pwdb_all > 4 && pwdb_all <= 14)
133 pwdb_all = ((pwdb_all-80)<<1) +
134 ((pwdb_all-80)>>1) + 80;
135 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
141 pstatus->rx_pwdb_all = pwdb_all;
142 pstatus->recvsignalpower = rx_pwr_all;
144 /* (3) Get Signal Quality (EVM) */
145 if (bpacket_match_bssid) {
148 if (pstatus->rx_pwdb_all > 40)
151 sq = cck_buf->sq_rpt;
157 sq = ((64 - sq) * 100) / 44;
160 pstatus->signalquality = sq;
161 pstatus->rx_mimo_signalquality[0] = sq;
162 pstatus->rx_mimo_signalquality[1] = -1;
165 rtlpriv->dm.rfpath_rxenable[0] =
166 rtlpriv->dm.rfpath_rxenable[1] = true;
168 /* (1)Get RSSI for HT rate */
169 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
170 /* we will judge RF RX path now. */
171 if (rtlpriv->dm.rfpath_rxenable[i])
174 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] &
177 /* Translate DBM to percentage. */
178 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
181 /* Get Rx snr value in DB */
182 rtlpriv->stats.rx_snr_db[i] =
183 (long)(p_drvinfo->rxsnr[i] / 2);
185 /* Record Signal Strength for next packet */
186 if (bpacket_match_bssid)
187 pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
190 /* (2)PWDB, Average PWDB cacluated by
191 * hardware (for rate adaptive)
193 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
195 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
196 pstatus->rx_pwdb_all = pwdb_all;
197 pstatus->rxpower = rx_pwr_all;
198 pstatus->recvsignalpower = rx_pwr_all;
200 /* (3)EVM of HT rate */
201 if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
202 pstatus->rate <= DESC92C_RATEMCS15)
203 max_spatial_stream = 2;
205 max_spatial_stream = 1;
207 for (i = 0; i < max_spatial_stream; i++) {
208 evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
210 if (bpacket_match_bssid) {
211 /* Fill value in RFD, Get the first
212 * spatial stream onlyi
215 pstatus->signalquality =
217 pstatus->rx_mimo_signalquality[i] =
223 /* UI BSS List signal strength(in percentage),
224 * make it good looking, from 0~100.
227 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
229 else if (rf_rx_num != 0)
230 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
231 total_rssi /= rf_rx_num));
232 /*HW antenna diversity*/
233 rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel;
234 rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b;
235 rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2;
238 static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw,
239 struct rtl_stats *pstatus)
241 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
242 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
244 struct fast_ant_training *pfat_table = &rtldm->fat_table;
246 if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
247 if (pfat_table->fat_state == FAT_TRAINING_STATE) {
248 if (pstatus->packet_toself) {
250 (pfat_table->antsel_rx_keep_2 << 2) |
251 (pfat_table->antsel_rx_keep_1 << 1) |
252 pfat_table->antsel_rx_keep_0;
253 pfat_table->ant_sum[antsel_tr_mux] +=
254 pstatus->rx_pwdb_all;
255 pfat_table->ant_cnt[antsel_tr_mux]++;
258 } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
259 (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
260 if (pstatus->packet_toself || pstatus->packet_matchbssid) {
261 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
262 (pfat_table->antsel_rx_keep_1 << 1) |
263 pfat_table->antsel_rx_keep_0;
264 rtl88e_dm_ant_sel_statistics(hw, antsel_tr_mux, 0,
265 pstatus->rx_pwdb_all);
271 static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw,
273 struct rtl_stats *pstatus,
275 struct rx_fwinfo_88e *p_drvinfo)
277 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
278 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
279 struct ieee80211_hdr *hdr;
284 bool packet_matchbssid, packet_toself, packet_beacon;
286 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
288 hdr = (struct ieee80211_hdr *)tmp_buf;
289 fc = hdr->frame_control;
291 psaddr = ieee80211_get_SA(hdr);
292 memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
294 packet_matchbssid = ((!ieee80211_is_ctl(fc)) &&
295 (ether_addr_equal(mac->bssid, ieee80211_has_tods(fc) ?
296 hdr->addr1 : ieee80211_has_fromds(fc) ?
297 hdr->addr2 : hdr->addr3)) &&
298 (!pstatus->hwerror) &&
299 (!pstatus->crc) && (!pstatus->icv));
301 packet_toself = packet_matchbssid &&
302 (ether_addr_equal(praddr, rtlefuse->dev_addr));
304 if (ieee80211_is_beacon(hdr->frame_control))
305 packet_beacon = true;
307 packet_beacon = false;
309 _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
310 packet_matchbssid, packet_toself,
312 _rtl88ee_smart_antenna(hw, pstatus);
313 rtl_process_phyinfo(hw, tmp_buf, pstatus);
316 static void _rtl88ee_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
320 memset(virtualaddress, 0, 8);
322 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
323 if (ptcb_desc->empkt_num == 1) {
324 dwtmp = ptcb_desc->empkt_len[0];
326 dwtmp = ptcb_desc->empkt_len[0];
327 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
328 dwtmp += ptcb_desc->empkt_len[1];
330 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
332 if (ptcb_desc->empkt_num <= 3) {
333 dwtmp = ptcb_desc->empkt_len[2];
335 dwtmp = ptcb_desc->empkt_len[2];
336 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
337 dwtmp += ptcb_desc->empkt_len[3];
339 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
340 if (ptcb_desc->empkt_num <= 5) {
341 dwtmp = ptcb_desc->empkt_len[4];
343 dwtmp = ptcb_desc->empkt_len[4];
344 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
345 dwtmp += ptcb_desc->empkt_len[5];
347 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
348 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
349 if (ptcb_desc->empkt_num <= 7) {
350 dwtmp = ptcb_desc->empkt_len[6];
352 dwtmp = ptcb_desc->empkt_len[6];
353 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
354 dwtmp += ptcb_desc->empkt_len[7];
356 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
357 if (ptcb_desc->empkt_num <= 9) {
358 dwtmp = ptcb_desc->empkt_len[8];
360 dwtmp = ptcb_desc->empkt_len[8];
361 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
362 dwtmp += ptcb_desc->empkt_len[9];
364 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
367 bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
368 struct rtl_stats *status,
369 struct ieee80211_rx_status *rx_status,
370 u8 *pdesc, struct sk_buff *skb)
372 struct rtl_priv *rtlpriv = rtl_priv(hw);
373 struct rx_fwinfo_88e *p_drvinfo;
374 struct ieee80211_hdr *hdr;
376 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
378 status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
379 if (status->packet_report_type == TX_REPORT2)
380 status->length = (u16)GET_RX_RPT2_DESC_PKT_LEN(pdesc);
382 status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
383 status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
384 RX_DRV_INFO_SIZE_UNIT;
385 status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
386 status->icv = (u16)GET_RX_DESC_ICV(pdesc);
387 status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
388 status->hwerror = (status->crc | status->icv);
389 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
390 status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
391 status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
392 status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
393 status->isfirst_ampdu = (bool)((GET_RX_DESC_PAGGR(pdesc) == 1) &&
394 (GET_RX_DESC_FAGGR(pdesc) == 1));
395 if (status->packet_report_type == NORMAL_RX)
396 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
397 status->rx_is40mhzpacket = (bool)GET_RX_DESC_BW(pdesc);
398 status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
400 status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate);
402 status->macid = GET_RX_DESC_MACID(pdesc);
403 if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
405 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
407 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
412 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
413 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
415 rx_status->freq = hw->conf.chandef.chan->center_freq;
416 rx_status->band = hw->conf.chandef.chan->band;
418 hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
419 + status->rx_bufshift);
422 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
424 if (status->rx_is40mhzpacket)
425 rx_status->bw = RATE_INFO_BW_40;
428 rx_status->encoding = RX_ENC_HT;
430 rx_status->flag |= RX_FLAG_MACTIME_START;
432 /* hw will set status->decrypted true, if it finds the
433 * frame is open data frame or mgmt frame.
434 * So hw will not decryption robust managment frame
435 * for IEEE80211w but still set status->decrypted
436 * true, so here we should set it back to undecrypted
437 * for IEEE80211w frame, and mac80211 sw will help
440 if (status->decrypted) {
441 if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
442 (ieee80211_has_protected(hdr->frame_control)))
443 rx_status->flag |= RX_FLAG_DECRYPTED;
445 rx_status->flag &= ~RX_FLAG_DECRYPTED;
448 /* rate_idx: index of data rate into band's
449 * supported rates or MCS index if HT rates
450 * are use (RX_FLAG_HT)
451 * Notice: this is diff with windows define
453 rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
454 false, status->rate);
456 rx_status->mactime = status->timestamp_low;
457 if (phystatus == true) {
458 p_drvinfo = (struct rx_fwinfo_88e *)(skb->data +
459 status->rx_bufshift);
461 _rtl88ee_translate_rx_signal_stuff(hw,
465 rx_status->signal = status->recvsignalpower + 10;
466 if (status->packet_report_type == TX_REPORT2) {
467 status->macid_valid_entry[0] =
468 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
469 status->macid_valid_entry[1] =
470 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
475 void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw,
476 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
477 u8 *txbd, struct ieee80211_tx_info *info,
478 struct ieee80211_sta *sta,
480 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
483 struct rtl_priv *rtlpriv = rtl_priv(hw);
484 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
485 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
486 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
487 u8 *pdesc = (u8 *)pdesc_tx;
489 __le16 fc = hdr->frame_control;
490 unsigned int buf_len = 0;
491 unsigned int skb_len = skb->len;
492 u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue);
493 bool firstseg = ((hdr->seq_ctrl &
494 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
495 bool lastseg = ((hdr->frame_control &
496 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
501 if (mac->opmode == NL80211_IFTYPE_STATION) {
503 } else if (mac->opmode == NL80211_IFTYPE_AP ||
504 mac->opmode == NL80211_IFTYPE_ADHOC) {
506 bw_40 = sta->ht_cap.cap &
507 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
509 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
510 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
511 /* reserve 8 byte for AMPDU early mode */
512 if (rtlhal->earlymode_enable) {
513 skb_push(skb, EM_HDR_LEN);
514 memset(skb->data, 0, EM_HDR_LEN);
517 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
519 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
520 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
521 "DMA mapping error\n");
524 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e));
525 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
530 if (rtlhal->earlymode_enable) {
531 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
532 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
534 if (ptcb_desc->empkt_num) {
535 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
536 "Insert 8 byte.pTcb->EMPktNum:%d\n",
537 ptcb_desc->empkt_num);
538 _rtl88ee_insert_emcontent(ptcb_desc,
542 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
545 ptcb_desc->use_driver_rate = true;
546 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
547 if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
548 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
550 short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
552 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
554 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
555 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
556 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
558 SET_TX_DESC_SEQ(pdesc, seq_number);
559 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
560 !ptcb_desc->cts_enable) ? 1 : 0));
561 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
562 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
563 SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
565 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
566 SET_TX_DESC_RTS_BW(pdesc, 0);
567 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
568 SET_TX_DESC_RTS_SHORT(pdesc,
569 ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
570 (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
571 (ptcb_desc->rts_use_shortgi ? 1 : 0)));
573 if (ptcb_desc->tx_enable_sw_calc_duration)
574 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
577 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
578 SET_TX_DESC_DATA_BW(pdesc, 1);
579 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
581 SET_TX_DESC_DATA_BW(pdesc, 0);
582 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
583 mac->cur_40_prime_sc);
586 SET_TX_DESC_DATA_BW(pdesc, 0);
587 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
590 SET_TX_DESC_LINIP(pdesc, 0);
591 SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
593 u8 ampdu_density = sta->ht_cap.ampdu_density;
594 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
596 if (info->control.hw_key) {
597 struct ieee80211_key_conf *keyconf;
599 keyconf = info->control.hw_key;
600 switch (keyconf->cipher) {
601 case WLAN_CIPHER_SUITE_WEP40:
602 case WLAN_CIPHER_SUITE_WEP104:
603 case WLAN_CIPHER_SUITE_TKIP:
604 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
606 case WLAN_CIPHER_SUITE_CCMP:
607 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
610 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
616 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
617 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
618 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
619 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
621 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
623 /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
624 /* Set TxRate and RTSRate in TxDesc */
625 /* This prevent Tx initial rate of new-coming packets */
626 /* from being overwritten by retried packet rate.*/
627 if (!ptcb_desc->use_driver_rate) {
628 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
629 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
631 if (ieee80211_is_data_qos(fc)) {
633 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
634 "Enable RDG function.\n");
635 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
636 SET_TX_DESC_HTC(pdesc, 1);
641 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
642 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
643 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
644 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
645 if (rtlpriv->dm.useramask) {
646 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
647 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
649 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
650 SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index);
652 if (ieee80211_is_data_qos(fc))
653 SET_TX_DESC_QOS(pdesc, 1);
655 if (!ieee80211_is_data_qos(fc))
656 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
657 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
658 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
659 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
660 SET_TX_DESC_BMC(pdesc, 1);
663 rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
664 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
667 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
668 u8 *pdesc, bool firstseg,
669 bool lastseg, struct sk_buff *skb)
671 struct rtl_priv *rtlpriv = rtl_priv(hw);
672 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
673 u8 fw_queue = QSLT_BEACON;
675 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
679 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
680 __le16 fc = hdr->frame_control;
682 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
683 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
684 "DMA mapping error\n");
687 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
690 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
692 SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
694 SET_TX_DESC_SEQ(pdesc, 0);
696 SET_TX_DESC_LINIP(pdesc, 0);
698 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
700 SET_TX_DESC_FIRST_SEG(pdesc, 1);
701 SET_TX_DESC_LAST_SEG(pdesc, 1);
703 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
705 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
707 SET_TX_DESC_RATE_ID(pdesc, 7);
708 SET_TX_DESC_MACID(pdesc, 0);
710 SET_TX_DESC_OWN(pdesc, 1);
712 SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
714 SET_TX_DESC_FIRST_SEG(pdesc, 1);
715 SET_TX_DESC_LAST_SEG(pdesc, 1);
717 SET_TX_DESC_OFFSET(pdesc, 0x20);
719 SET_TX_DESC_USE_RATE(pdesc, 1);
721 if (!ieee80211_is_data_qos(fc))
722 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
724 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
725 "H2C Tx Cmd Content\n",
726 pdesc, TX_DESC_SIZE);
729 void rtl88ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
730 bool istx, u8 desc_name, u8 *val)
735 SET_TX_DESC_OWN(pdesc, 1);
737 case HW_DESC_TX_NEXTDESC_ADDR:
738 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
741 WARN_ONCE(true, "rtl8188ee: ERR txdesc :%d not processed\n",
748 SET_RX_DESC_OWN(pdesc, 1);
750 case HW_DESC_RXBUFF_ADDR:
751 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
753 case HW_DESC_RXPKT_LEN:
754 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
757 SET_RX_DESC_EOR(pdesc, 1);
760 WARN_ONCE(true, "rtl8188ee: ERR rxdesc :%d not processed\n",
767 u64 rtl88ee_get_desc(struct ieee80211_hw *hw,
768 u8 *pdesc, bool istx, u8 desc_name)
775 ret = GET_TX_DESC_OWN(pdesc);
777 case HW_DESC_TXBUFF_ADDR:
778 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
781 WARN_ONCE(true, "rtl8188ee: ERR txdesc :%d not processed\n",
788 ret = GET_RX_DESC_OWN(pdesc);
790 case HW_DESC_RXPKT_LEN:
791 ret = GET_RX_DESC_PKT_LEN(pdesc);
793 case HW_DESC_RXBUFF_ADDR:
794 ret = GET_RX_DESC_BUFF_ADDR(pdesc);
797 WARN_ONCE(true, "rtl8188ee: ERR rxdesc :%d not processed\n",
805 bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index)
807 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
808 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
809 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
810 u8 own = (u8)rtl88ee_get_desc(hw, entry, true, HW_DESC_OWN);
812 /*beacon packet will only use the first
813 *descriptor defautly,and the own may not
814 *be cleared by the hardware
821 void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
823 struct rtl_priv *rtlpriv = rtl_priv(hw);
824 if (hw_queue == BEACON_QUEUE) {
825 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
827 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
828 BIT(0) << (hw_queue));