1 /******************************************************************************
3 * Copyright(c) 2009-2013 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
38 static u8 _rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
40 __le16 fc = rtl_get_fc(skb);
42 if (unlikely(ieee80211_is_beacon(fc)))
44 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
50 /* mac80211's rate_idx is like this:
52 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
55 * (rx_status->flag & RX_FLAG_HT) = 0,
56 * DESC92C_RATE1M-->DESC92C_RATE54M ==> idx is 0-->11,
59 * (rx_status->flag & RX_FLAG_HT) = 1,
60 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
62 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
64 * (rx_status->flag & RX_FLAG_HT) = 0,
65 * DESC92C_RATE6M-->DESC92C_RATE54M ==> idx is 0-->7,
68 * (rx_status->flag & RX_FLAG_HT) = 1,
69 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
71 static int _rtl88ee_rate_mapping(struct ieee80211_hw *hw,
72 bool isht, u8 desc_rate)
77 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
85 case DESC92C_RATE5_5M:
100 case DESC92C_RATE18M:
103 case DESC92C_RATE24M:
106 case DESC92C_RATE36M:
109 case DESC92C_RATE48M:
112 case DESC92C_RATE54M:
127 case DESC92C_RATE12M:
130 case DESC92C_RATE18M:
133 case DESC92C_RATE24M:
136 case DESC92C_RATE36M:
139 case DESC92C_RATE48M:
142 case DESC92C_RATE54M:
152 case DESC92C_RATEMCS0:
155 case DESC92C_RATEMCS1:
158 case DESC92C_RATEMCS2:
161 case DESC92C_RATEMCS3:
164 case DESC92C_RATEMCS4:
167 case DESC92C_RATEMCS5:
170 case DESC92C_RATEMCS6:
173 case DESC92C_RATEMCS7:
176 case DESC92C_RATEMCS8:
179 case DESC92C_RATEMCS9:
182 case DESC92C_RATEMCS10:
185 case DESC92C_RATEMCS11:
188 case DESC92C_RATEMCS12:
191 case DESC92C_RATEMCS13:
194 case DESC92C_RATEMCS14:
197 case DESC92C_RATEMCS15:
208 static void _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw,
209 struct rtl_stats *pstatus, u8 *pdesc,
210 struct rx_fwinfo_88e *p_drvinfo,
211 bool bpacket_match_bssid,
212 bool bpacket_toself, bool packet_beacon)
214 struct rtl_priv *rtlpriv = rtl_priv(hw);
215 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
216 struct phy_sts_cck_8192s_t *cck_buf;
217 struct phy_status_rpt *phystrpt =
218 (struct phy_status_rpt *)p_drvinfo;
219 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
220 char rx_pwr_all = 0, rx_pwr[4];
221 u8 rf_rx_num = 0, evm, pwdb_all;
222 u8 i, max_spatial_stream;
223 u32 rssi, total_rssi = 0;
224 bool is_cck = pstatus->is_cck;
227 /* Record it for next packet processing */
228 pstatus->packet_matchbssid = bpacket_match_bssid;
229 pstatus->packet_toself = bpacket_toself;
230 pstatus->packet_beacon = packet_beacon;
231 pstatus->rx_mimo_signalquality[0] = -1;
232 pstatus->rx_mimo_signalquality[1] = -1;
237 /* CCK Driver info Structure is not the same as OFDM packet. */
238 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
239 cck_agc_rpt = cck_buf->cck_agc_rpt;
241 /* (1)Hardware does not provide RSSI for CCK
242 * (2)PWDB, Average PWDB cacluated by
243 * hardware (for rate adaptive)
245 if (ppsc->rfpwr_state == ERFON)
247 (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
252 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
253 vga_idx = (cck_agc_rpt & 0x1f);
258 rx_pwr_all = -100 + 2*(27-vga_idx);
264 rx_pwr_all = -48 + 2*(2-vga_idx);
268 rx_pwr_all = -42 + 2*(7-vga_idx);
272 rx_pwr_all = -36 + 2*(7-vga_idx);
276 rx_pwr_all = -24 + 2*(7-vga_idx);
281 rx_pwr_all = -12 + 2*(5-vga_idx);
283 rx_pwr_all = -6 + 2*(5-vga_idx);
286 rx_pwr_all = 8-2*vga_idx;
289 rx_pwr_all = 14-2*vga_idx;
295 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
296 /* CCK gain is smaller than OFDM/MCS gain, */
297 /* so we add gain diff by experiences, the val is 6 */
301 /* modify the offset to make the same
302 * gain index with OFDM.
304 if (pwdb_all > 34 && pwdb_all <= 42)
306 else if (pwdb_all > 26 && pwdb_all <= 34)
308 else if (pwdb_all > 14 && pwdb_all <= 26)
310 else if (pwdb_all > 4 && pwdb_all <= 14)
314 pwdb_all = ((pwdb_all-80)<<1) +
315 ((pwdb_all-80)>>1) + 80;
316 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
322 pstatus->rx_pwdb_all = pwdb_all;
323 pstatus->recvsignalpower = rx_pwr_all;
325 /* (3) Get Signal Quality (EVM) */
326 if (bpacket_match_bssid) {
329 if (pstatus->rx_pwdb_all > 40)
332 sq = cck_buf->sq_rpt;
338 sq = ((64 - sq) * 100) / 44;
341 pstatus->signalquality = sq;
342 pstatus->rx_mimo_signalquality[0] = sq;
343 pstatus->rx_mimo_signalquality[1] = -1;
346 rtlpriv->dm.rfpath_rxenable[0] =
347 rtlpriv->dm.rfpath_rxenable[1] = true;
349 /* (1)Get RSSI for HT rate */
350 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
351 /* we will judge RF RX path now. */
352 if (rtlpriv->dm.rfpath_rxenable[i])
355 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] &
358 /* Translate DBM to percentage. */
359 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
362 /* Get Rx snr value in DB */
363 rtlpriv->stats.rx_snr_db[i] =
364 (long)(p_drvinfo->rxsnr[i] / 2);
366 /* Record Signal Strength for next packet */
367 if (bpacket_match_bssid)
368 pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
371 /* (2)PWDB, Average PWDB cacluated by
372 * hardware (for rate adaptive)
374 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
376 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
377 pstatus->rx_pwdb_all = pwdb_all;
378 pstatus->rxpower = rx_pwr_all;
379 pstatus->recvsignalpower = rx_pwr_all;
381 /* (3)EVM of HT rate */
382 if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
383 pstatus->rate <= DESC92C_RATEMCS15)
384 max_spatial_stream = 2;
386 max_spatial_stream = 1;
388 for (i = 0; i < max_spatial_stream; i++) {
389 evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
391 if (bpacket_match_bssid) {
392 /* Fill value in RFD, Get the first
393 * spatial stream onlyi
396 pstatus->signalquality =
398 pstatus->rx_mimo_signalquality[i] =
404 /* UI BSS List signal strength(in percentage),
405 * make it good looking, from 0~100.
408 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
410 else if (rf_rx_num != 0)
411 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
412 total_rssi /= rf_rx_num));
413 /*HW antenna diversity*/
414 rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel;
415 rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b;
416 rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2;
419 static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw,
420 struct rtl_stats *pstatus)
422 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
423 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
425 struct fast_ant_training *pfat_table = &rtldm->fat_table;
427 if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
428 if (pfat_table->fat_state == FAT_TRAINING_STATE) {
429 if (pstatus->packet_toself) {
431 (pfat_table->antsel_rx_keep_2 << 2) |
432 (pfat_table->antsel_rx_keep_1 << 1) |
433 pfat_table->antsel_rx_keep_0;
434 pfat_table->ant_sum[antsel_tr_mux] +=
435 pstatus->rx_pwdb_all;
436 pfat_table->ant_cnt[antsel_tr_mux]++;
439 } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
440 (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
441 if (pstatus->packet_toself || pstatus->packet_matchbssid) {
442 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
443 (pfat_table->antsel_rx_keep_1 << 1) |
444 pfat_table->antsel_rx_keep_0;
445 rtl88e_dm_ant_sel_statistics(hw, antsel_tr_mux, 0,
446 pstatus->rx_pwdb_all);
452 static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw,
454 struct rtl_stats *pstatus,
456 struct rx_fwinfo_88e *p_drvinfo)
458 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
459 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
460 struct ieee80211_hdr *hdr;
465 bool packet_matchbssid, packet_toself, packet_beacon;
467 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
469 hdr = (struct ieee80211_hdr *)tmp_buf;
470 fc = hdr->frame_control;
472 psaddr = ieee80211_get_SA(hdr);
473 memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
475 packet_matchbssid = ((!ieee80211_is_ctl(fc)) &&
476 (ether_addr_equal(mac->bssid, ieee80211_has_tods(fc) ?
477 hdr->addr1 : ieee80211_has_fromds(fc) ?
478 hdr->addr2 : hdr->addr3)) &&
479 (!pstatus->hwerror) &&
480 (!pstatus->crc) && (!pstatus->icv));
482 packet_toself = packet_matchbssid &&
483 (ether_addr_equal(praddr, rtlefuse->dev_addr));
485 if (ieee80211_is_beacon(hdr->frame_control))
486 packet_beacon = true;
488 packet_beacon = false;
490 _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
491 packet_matchbssid, packet_toself,
493 _rtl88ee_smart_antenna(hw, pstatus);
494 rtl_process_phyinfo(hw, tmp_buf, pstatus);
497 static void _rtl88ee_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
501 memset(virtualaddress, 0, 8);
503 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
504 if (ptcb_desc->empkt_num == 1) {
505 dwtmp = ptcb_desc->empkt_len[0];
507 dwtmp = ptcb_desc->empkt_len[0];
508 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
509 dwtmp += ptcb_desc->empkt_len[1];
511 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
513 if (ptcb_desc->empkt_num <= 3) {
514 dwtmp = ptcb_desc->empkt_len[2];
516 dwtmp = ptcb_desc->empkt_len[2];
517 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
518 dwtmp += ptcb_desc->empkt_len[3];
520 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
521 if (ptcb_desc->empkt_num <= 5) {
522 dwtmp = ptcb_desc->empkt_len[4];
524 dwtmp = ptcb_desc->empkt_len[4];
525 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
526 dwtmp += ptcb_desc->empkt_len[5];
528 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
529 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
530 if (ptcb_desc->empkt_num <= 7) {
531 dwtmp = ptcb_desc->empkt_len[6];
533 dwtmp = ptcb_desc->empkt_len[6];
534 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
535 dwtmp += ptcb_desc->empkt_len[7];
537 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
538 if (ptcb_desc->empkt_num <= 9) {
539 dwtmp = ptcb_desc->empkt_len[8];
541 dwtmp = ptcb_desc->empkt_len[8];
542 dwtmp += ((dwtmp%4) ? (4-dwtmp%4) : 0)+4;
543 dwtmp += ptcb_desc->empkt_len[9];
545 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
548 bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
549 struct rtl_stats *status,
550 struct ieee80211_rx_status *rx_status,
551 u8 *pdesc, struct sk_buff *skb)
553 struct rtl_priv *rtlpriv = rtl_priv(hw);
554 struct rx_fwinfo_88e *p_drvinfo;
555 struct ieee80211_hdr *hdr;
557 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
558 status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
559 if (status->packet_report_type == TX_REPORT2)
560 status->length = (u16)GET_RX_RPT2_DESC_PKT_LEN(pdesc);
562 status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
563 status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
564 RX_DRV_INFO_SIZE_UNIT;
565 status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
566 status->icv = (u16)GET_RX_DESC_ICV(pdesc);
567 status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
568 status->hwerror = (status->crc | status->icv);
569 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
570 status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
571 status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
572 status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
573 status->isfirst_ampdu = (bool)((GET_RX_DESC_PAGGR(pdesc) == 1) &&
574 (GET_RX_DESC_FAGGR(pdesc) == 1));
575 if (status->packet_report_type == NORMAL_RX)
576 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
577 status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
578 status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
580 status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate);
582 status->macid = GET_RX_DESC_MACID(pdesc);
583 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
584 status->wake_match = BIT(2);
585 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
586 status->wake_match = BIT(1);
587 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
588 status->wake_match = BIT(0);
590 status->wake_match = 0;
591 if (status->wake_match)
592 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
593 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
595 rx_status->freq = hw->conf.chandef.chan->center_freq;
596 rx_status->band = hw->conf.chandef.chan->band;
598 hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
599 + status->rx_bufshift);
602 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
604 if (status->rx_is40Mhzpacket)
605 rx_status->flag |= RX_FLAG_40MHZ;
608 rx_status->flag |= RX_FLAG_HT;
610 rx_status->flag |= RX_FLAG_MACTIME_START;
612 /* hw will set status->decrypted true, if it finds the
613 * frame is open data frame or mgmt frame.
614 * So hw will not decryption robust managment frame
615 * for IEEE80211w but still set status->decrypted
616 * true, so here we should set it back to undecrypted
617 * for IEEE80211w frame, and mac80211 sw will help
620 if (status->decrypted) {
621 if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
622 (ieee80211_has_protected(hdr->frame_control)))
623 rx_status->flag |= RX_FLAG_DECRYPTED;
625 rx_status->flag &= ~RX_FLAG_DECRYPTED;
628 /* rate_idx: index of data rate into band's
629 * supported rates or MCS index if HT rates
630 * are use (RX_FLAG_HT)
631 * Notice: this is diff with windows define
633 rx_status->rate_idx = _rtl88ee_rate_mapping(hw,
634 status->is_ht, status->rate);
636 rx_status->mactime = status->timestamp_low;
637 if (phystatus == true) {
638 p_drvinfo = (struct rx_fwinfo_88e *)(skb->data +
639 status->rx_bufshift);
641 _rtl88ee_translate_rx_signal_stuff(hw,
645 rx_status->signal = status->recvsignalpower + 10;
646 if (status->packet_report_type == TX_REPORT2) {
647 status->macid_valid_entry[0] =
648 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
649 status->macid_valid_entry[1] =
650 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
655 void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw,
656 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
657 u8 *txbd, struct ieee80211_tx_info *info,
658 struct ieee80211_sta *sta,
660 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
663 struct rtl_priv *rtlpriv = rtl_priv(hw);
664 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
665 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
666 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
667 u8 *pdesc = (u8 *)pdesc_tx;
669 __le16 fc = hdr->frame_control;
670 unsigned int buf_len = 0;
671 unsigned int skb_len = skb->len;
672 u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue);
673 bool firstseg = ((hdr->seq_ctrl &
674 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
675 bool lastseg = ((hdr->frame_control &
676 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
681 if (mac->opmode == NL80211_IFTYPE_STATION) {
683 } else if (mac->opmode == NL80211_IFTYPE_AP ||
684 mac->opmode == NL80211_IFTYPE_ADHOC) {
686 bw_40 = sta->ht_cap.cap &
687 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
689 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
690 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
691 /* reserve 8 byte for AMPDU early mode */
692 if (rtlhal->earlymode_enable) {
693 skb_push(skb, EM_HDR_LEN);
694 memset(skb->data, 0, EM_HDR_LEN);
697 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
699 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
700 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
701 "DMA mapping error");
704 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e));
705 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
710 if (rtlhal->earlymode_enable) {
711 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
712 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
714 if (ptcb_desc->empkt_num) {
715 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
716 "Insert 8 byte.pTcb->EMPktNum:%d\n",
717 ptcb_desc->empkt_num);
718 _rtl88ee_insert_emcontent(ptcb_desc,
722 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
725 ptcb_desc->use_driver_rate = true;
726 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
727 if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
728 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
730 short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
732 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
734 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
735 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
736 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
738 SET_TX_DESC_SEQ(pdesc, seq_number);
739 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
740 !ptcb_desc->cts_enable) ? 1 : 0));
741 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
742 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
743 SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
745 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
746 SET_TX_DESC_RTS_BW(pdesc, 0);
747 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
748 SET_TX_DESC_RTS_SHORT(pdesc,
749 ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
750 (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
751 (ptcb_desc->rts_use_shortgi ? 1 : 0)));
753 if (ptcb_desc->tx_enable_sw_calc_duration)
754 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
757 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
758 SET_TX_DESC_DATA_BW(pdesc, 1);
759 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
761 SET_TX_DESC_DATA_BW(pdesc, 0);
762 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
763 mac->cur_40_prime_sc);
766 SET_TX_DESC_DATA_BW(pdesc, 0);
767 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
770 SET_TX_DESC_LINIP(pdesc, 0);
771 SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
773 u8 ampdu_density = sta->ht_cap.ampdu_density;
774 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
776 if (info->control.hw_key) {
777 struct ieee80211_key_conf *keyconf;
779 keyconf = info->control.hw_key;
780 switch (keyconf->cipher) {
781 case WLAN_CIPHER_SUITE_WEP40:
782 case WLAN_CIPHER_SUITE_WEP104:
783 case WLAN_CIPHER_SUITE_TKIP:
784 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
786 case WLAN_CIPHER_SUITE_CCMP:
787 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
790 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
796 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
797 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
798 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
799 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
801 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
803 /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
804 /* Set TxRate and RTSRate in TxDesc */
805 /* This prevent Tx initial rate of new-coming packets */
806 /* from being overwritten by retried packet rate.*/
807 if (!ptcb_desc->use_driver_rate) {
808 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
809 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
811 if (ieee80211_is_data_qos(fc)) {
813 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
814 "Enable RDG function.\n");
815 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
816 SET_TX_DESC_HTC(pdesc, 1);
821 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
822 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
823 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
824 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
825 if (rtlpriv->dm.useramask) {
826 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
827 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
829 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
830 SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index);
832 if (ieee80211_is_data_qos(fc))
833 SET_TX_DESC_QOS(pdesc, 1);
835 if (!ieee80211_is_data_qos(fc))
836 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
837 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
838 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
839 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
840 SET_TX_DESC_BMC(pdesc, 1);
843 rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
844 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
847 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
848 u8 *pdesc, bool firstseg,
849 bool lastseg, struct sk_buff *skb)
851 struct rtl_priv *rtlpriv = rtl_priv(hw);
852 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
853 u8 fw_queue = QSLT_BEACON;
855 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
859 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
860 __le16 fc = hdr->frame_control;
862 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
863 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
864 "DMA mapping error");
867 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
870 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
872 SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
874 SET_TX_DESC_SEQ(pdesc, 0);
876 SET_TX_DESC_LINIP(pdesc, 0);
878 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
880 SET_TX_DESC_FIRST_SEG(pdesc, 1);
881 SET_TX_DESC_LAST_SEG(pdesc, 1);
883 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
885 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
887 SET_TX_DESC_RATE_ID(pdesc, 7);
888 SET_TX_DESC_MACID(pdesc, 0);
890 SET_TX_DESC_OWN(pdesc, 1);
892 SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
894 SET_TX_DESC_FIRST_SEG(pdesc, 1);
895 SET_TX_DESC_LAST_SEG(pdesc, 1);
897 SET_TX_DESC_OFFSET(pdesc, 0x20);
899 SET_TX_DESC_USE_RATE(pdesc, 1);
901 if (!ieee80211_is_data_qos(fc))
902 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
904 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
905 "H2C Tx Cmd Content\n",
906 pdesc, TX_DESC_SIZE);
909 void rtl88ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
910 bool istx, u8 desc_name, u8 *val)
915 SET_TX_DESC_OWN(pdesc, 1);
917 case HW_DESC_TX_NEXTDESC_ADDR:
918 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
921 RT_ASSERT(false, "ERR txdesc :%d not process\n",
928 SET_RX_DESC_OWN(pdesc, 1);
930 case HW_DESC_RXBUFF_ADDR:
931 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
933 case HW_DESC_RXPKT_LEN:
934 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
937 SET_RX_DESC_EOR(pdesc, 1);
940 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
947 u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name)
954 ret = GET_TX_DESC_OWN(pdesc);
956 case HW_DESC_TXBUFF_ADDR:
957 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
960 RT_ASSERT(false, "ERR txdesc :%d not process\n",
967 ret = GET_RX_DESC_OWN(pdesc);
969 case HW_DESC_RXPKT_LEN:
970 ret = GET_RX_DESC_PKT_LEN(pdesc);
972 case HW_DESC_RXBUFF_ADDR:
973 ret = GET_RX_DESC_BUFF_ADDR(pdesc);
976 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
984 bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index)
986 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
987 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
988 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
989 u8 own = (u8)rtl88ee_get_desc(entry, true, HW_DESC_OWN);
991 /*beacon packet will only use the first
992 *descriptor defautly,and the own may not
993 *be cleared by the hardware
1000 void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
1002 struct rtl_priv *rtlpriv = rtl_priv(hw);
1003 if (hw_queue == BEACON_QUEUE) {
1004 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
1006 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
1007 BIT(0) << (hw_queue));
1011 u32 rtl88ee_rx_command_packet(struct ieee80211_hw *hw,
1012 struct rtl_stats status,
1013 struct sk_buff *skb)