1 /******************************************************************************
3 * Copyright(c) 2009-2010 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 *****************************************************************************/
39 static u8 _rtl8821ae_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
41 __le16 fc = rtl_get_fc(skb);
43 if (unlikely(ieee80211_is_beacon(fc)))
45 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
51 /* mac80211's rate_idx is like this:
53 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
56 * (rx_status->flag & RX_FLAG_HT) = 0,
57 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
60 * (rx_status->flag & RX_FLAG_HT) = 1,
61 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
63 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
65 * (rx_status->flag & RX_FLAG_HT) = 0,
66 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
69 * (rx_status->flag & RX_FLAG_HT) = 1,
70 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
72 static int _rtl8821ae_rate_mapping(struct ieee80211_hw *hw,
73 bool isht, bool isvht, u8 desc_rate)
78 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
209 case DESC_RATEVHT1SS_MCS0:
212 case DESC_RATEVHT1SS_MCS1:
215 case DESC_RATEVHT1SS_MCS2:
218 case DESC_RATEVHT1SS_MCS3:
221 case DESC_RATEVHT1SS_MCS4:
224 case DESC_RATEVHT1SS_MCS5:
227 case DESC_RATEVHT1SS_MCS6:
230 case DESC_RATEVHT1SS_MCS7:
233 case DESC_RATEVHT1SS_MCS8:
236 case DESC_RATEVHT1SS_MCS9:
239 case DESC_RATEVHT2SS_MCS0:
242 case DESC_RATEVHT2SS_MCS1:
245 case DESC_RATEVHT2SS_MCS2:
248 case DESC_RATEVHT2SS_MCS3:
251 case DESC_RATEVHT2SS_MCS4:
254 case DESC_RATEVHT2SS_MCS5:
257 case DESC_RATEVHT2SS_MCS6:
260 case DESC_RATEVHT2SS_MCS7:
263 case DESC_RATEVHT2SS_MCS8:
266 case DESC_RATEVHT2SS_MCS9:
277 static u16 odm_cfo(char value)
283 ret_val = (ret_val << 1) + (ret_val >> 1);
284 /* set bit12 as 1 for negative cfo */
285 ret_val = ret_val | BIT(12);
288 ret_val = (ret_val << 1) + (ret_val >> 1);
293 static void query_rxphystatus(struct ieee80211_hw *hw,
294 struct rtl_stats *pstatus, u8 *pdesc,
295 struct rx_fwinfo_8821ae *p_drvinfo,
296 bool bpacket_match_bssid,
297 bool bpacket_toself, bool packet_beacon)
299 struct rtl_priv *rtlpriv = rtl_priv(hw);
300 struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
301 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
302 struct rtl_phy *rtlphy = &rtlpriv->phy;
303 char rx_pwr_all = 0, rx_pwr[4];
304 u8 rf_rx_num = 0, evm, evmdbm, pwdb_all;
305 u8 i, max_spatial_stream;
306 u32 rssi, total_rssi = 0;
307 bool is_cck = pstatus->is_cck;
310 /* Record it for next packet processing */
311 pstatus->packet_matchbssid = bpacket_match_bssid;
312 pstatus->packet_toself = bpacket_toself;
313 pstatus->packet_beacon = packet_beacon;
314 pstatus->rx_mimo_signalquality[0] = -1;
315 pstatus->rx_mimo_signalquality[1] = -1;
321 cck_agc_rpt = p_phystrpt->cfosho[0];
323 /* (1)Hardware does not provide RSSI for CCK
324 * (2)PWDB, Average PWDB cacluated by
325 * hardware (for rate adaptive)
327 cck_highpwr = (u8)rtlphy->cck_high_power;
329 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
330 vga_idx = (cck_agc_rpt & 0x1f);
331 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE) {
336 rx_pwr_all = -100 + 2*(27-vga_idx);
342 rx_pwr_all = -48 + 2*(2-vga_idx);
346 rx_pwr_all = -42 + 2*(7-vga_idx);
350 rx_pwr_all = -36 + 2*(7-vga_idx);
354 rx_pwr_all = -24 + 2*(7-vga_idx);
359 rx_pwr_all = -12 + 2*(5-vga_idx);
361 rx_pwr_all = -6 + 2*(5-vga_idx);
364 rx_pwr_all = 8-2*vga_idx;
367 rx_pwr_all = 14-2*vga_idx;
373 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
377 ((pwdb_all - 80)<<1) +
378 ((pwdb_all - 80)>>1) + 80;
379 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
389 rx_pwr_all = pout - 32 - (2*vga_idx);
392 rx_pwr_all = pout - 24 - (2*vga_idx);
395 rx_pwr_all = pout - 11 - (2*vga_idx);
398 rx_pwr_all = pout + 5 - (2*vga_idx);
401 rx_pwr_all = pout + 21 - (2*vga_idx);
404 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
407 pstatus->rx_pwdb_all = pwdb_all;
408 pstatus->recvsignalpower = rx_pwr_all;
410 /* (3) Get Signal Quality (EVM) */
411 if (bpacket_match_bssid) {
414 if (pstatus->rx_pwdb_all > 40) {
417 sq = p_phystrpt->pwdb_all;
423 sq = ((64 - sq) * 100) / 44;
426 pstatus->signalquality = sq;
427 pstatus->rx_mimo_signalquality[0] = sq;
428 pstatus->rx_mimo_signalquality[1] = -1;
431 /* (1)Get RSSI for HT rate */
432 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
433 /* we will judge RF RX path now. */
434 if (rtlpriv->dm.rfpath_rxenable[i])
437 rx_pwr[i] = (p_phystrpt->gain_trsw[i] & 0x7f) - 110;
439 /* Translate DBM to percentage. */
440 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
443 /* Get Rx snr value in DB */
444 pstatus->rx_snr[i] = p_phystrpt->rxsnr[i] / 2;
445 rtlpriv->stats.rx_snr_db[i] = p_phystrpt->rxsnr[i] / 2;
447 pstatus->cfo_short[i] = odm_cfo(p_phystrpt->cfosho[i]);
448 pstatus->cfo_tail[i] = odm_cfo(p_phystrpt->cfotail[i]);
449 /* Record Signal Strength for next packet */
450 pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
453 /* (2)PWDB, Average PWDB cacluated by
454 * hardware (for rate adaptive)
456 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
458 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
459 pstatus->rx_pwdb_all = pwdb_all;
460 pstatus->rxpower = rx_pwr_all;
461 pstatus->recvsignalpower = rx_pwr_all;
463 /* (3)EVM of HT rate */
464 if ((pstatus->is_ht && pstatus->rate >= DESC_RATEMCS8 &&
465 pstatus->rate <= DESC_RATEMCS15) ||
467 pstatus->rate >= DESC_RATEVHT2SS_MCS0 &&
468 pstatus->rate <= DESC_RATEVHT2SS_MCS9))
469 max_spatial_stream = 2;
471 max_spatial_stream = 1;
473 for (i = 0; i < max_spatial_stream; i++) {
474 evm = rtl_evm_db_to_percentage(p_phystrpt->rxevm[i]);
475 evmdbm = rtl_evm_dbm_jaguar(p_phystrpt->rxevm[i]);
477 if (bpacket_match_bssid) {
478 /* Fill value in RFD, Get the first
479 * spatial stream only
482 pstatus->signalquality = evm;
483 pstatus->rx_mimo_signalquality[i] = evm;
484 pstatus->rx_mimo_evm_dbm[i] = evmdbm;
487 if (bpacket_match_bssid) {
488 for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
489 rtl_priv(hw)->dm.cfo_tail[i] =
490 (char)p_phystrpt->cfotail[i];
492 rtl_priv(hw)->dm.packet_count++;
496 /* UI BSS List signal strength(in percentage),
497 * make it good looking, from 0~100.
500 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
502 else if (rf_rx_num != 0)
503 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
504 total_rssi /= rf_rx_num));
505 /*HW antenna diversity*/
506 rtldm->fat_table.antsel_rx_keep_0 = p_phystrpt->antidx_anta;
507 rtldm->fat_table.antsel_rx_keep_1 = p_phystrpt->antidx_antb;
510 static void translate_rx_signal_stuff(struct ieee80211_hw *hw,
512 struct rtl_stats *pstatus, u8 *pdesc,
513 struct rx_fwinfo_8821ae *p_drvinfo)
515 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
516 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
517 struct ieee80211_hdr *hdr;
523 bool packet_matchbssid, packet_toself, packet_beacon;
525 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
527 hdr = (struct ieee80211_hdr *)tmp_buf;
528 fc = hdr->frame_control;
529 type = WLAN_FC_GET_TYPE(hdr->frame_control);
531 psaddr = ieee80211_get_SA(hdr);
532 ether_addr_copy(pstatus->psaddr, psaddr);
534 packet_matchbssid = (!ieee80211_is_ctl(fc) &&
535 (ether_addr_equal(mac->bssid,
536 ieee80211_has_tods(fc) ?
538 ieee80211_has_fromds(fc) ?
539 hdr->addr2 : hdr->addr3)) &&
540 (!pstatus->hwerror) &&
541 (!pstatus->crc) && (!pstatus->icv));
543 packet_toself = packet_matchbssid &&
544 (ether_addr_equal(praddr, rtlefuse->dev_addr));
546 if (ieee80211_is_beacon(hdr->frame_control))
547 packet_beacon = true;
549 packet_beacon = false;
551 if (packet_beacon && packet_matchbssid)
552 rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
554 if (packet_matchbssid &&
555 ieee80211_is_data_qos(hdr->frame_control) &&
556 !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
557 struct ieee80211_qos_hdr *hdr_qos =
558 (struct ieee80211_qos_hdr *)tmp_buf;
559 u16 tid = le16_to_cpu(hdr_qos->qos_ctrl) & 0xf;
561 if (tid != 0 && tid != 3)
562 rtl_priv(hw)->dm.dbginfo.num_non_be_pkt++;
565 query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
566 packet_matchbssid, packet_toself,
568 /*_rtl8821ae_smart_antenna(hw, pstatus); */
569 rtl_process_phyinfo(hw, tmp_buf, pstatus);
572 static void _rtl8821ae_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
577 memset(virtualaddress, 0, 8);
579 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
580 if (ptcb_desc->empkt_num == 1) {
581 dwtmp = ptcb_desc->empkt_len[0];
583 dwtmp = ptcb_desc->empkt_len[0];
584 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
585 dwtmp += ptcb_desc->empkt_len[1];
587 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
589 if (ptcb_desc->empkt_num <= 3) {
590 dwtmp = ptcb_desc->empkt_len[2];
592 dwtmp = ptcb_desc->empkt_len[2];
593 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
594 dwtmp += ptcb_desc->empkt_len[3];
596 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
597 if (ptcb_desc->empkt_num <= 5) {
598 dwtmp = ptcb_desc->empkt_len[4];
600 dwtmp = ptcb_desc->empkt_len[4];
601 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
602 dwtmp += ptcb_desc->empkt_len[5];
604 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
605 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
606 if (ptcb_desc->empkt_num <= 7) {
607 dwtmp = ptcb_desc->empkt_len[6];
609 dwtmp = ptcb_desc->empkt_len[6];
610 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
611 dwtmp += ptcb_desc->empkt_len[7];
613 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
614 if (ptcb_desc->empkt_num <= 9) {
615 dwtmp = ptcb_desc->empkt_len[8];
617 dwtmp = ptcb_desc->empkt_len[8];
618 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
619 dwtmp += ptcb_desc->empkt_len[9];
621 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
624 static bool rtl8821ae_get_rxdesc_is_ht(struct ieee80211_hw *hw, u8 *pdesc)
626 struct rtl_priv *rtlpriv = rtl_priv(hw);
629 rx_rate = GET_RX_DESC_RXMCS(pdesc);
631 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
633 if ((rx_rate >= DESC_RATEMCS0) && (rx_rate <= DESC_RATEMCS15))
638 static bool rtl8821ae_get_rxdesc_is_vht(struct ieee80211_hw *hw, u8 *pdesc)
640 struct rtl_priv *rtlpriv = rtl_priv(hw);
643 rx_rate = GET_RX_DESC_RXMCS(pdesc);
645 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
647 if (rx_rate >= DESC_RATEVHT1SS_MCS0)
652 static u8 rtl8821ae_get_rx_vht_nss(struct ieee80211_hw *hw, u8 *pdesc)
657 rx_rate = GET_RX_DESC_RXMCS(pdesc);
658 if ((rx_rate >= DESC_RATEVHT1SS_MCS0) &&
659 (rx_rate <= DESC_RATEVHT1SS_MCS9))
661 else if ((rx_rate >= DESC_RATEVHT2SS_MCS0) &&
662 (rx_rate <= DESC_RATEVHT2SS_MCS9))
668 bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw,
669 struct rtl_stats *status,
670 struct ieee80211_rx_status *rx_status,
671 u8 *pdesc, struct sk_buff *skb)
673 struct rtl_priv *rtlpriv = rtl_priv(hw);
674 struct rx_fwinfo_8821ae *p_drvinfo;
675 struct ieee80211_hdr *hdr;
677 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
679 status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
680 status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
681 RX_DRV_INFO_SIZE_UNIT;
682 status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
683 status->icv = (u16)GET_RX_DESC_ICV(pdesc);
684 status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
685 status->hwerror = (status->crc | status->icv);
686 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
687 status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
688 status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
689 status->isampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
690 status->isfirst_ampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
691 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
692 status->rx_packet_bw = GET_RX_DESC_BW(pdesc);
693 status->macid = GET_RX_DESC_MACID(pdesc);
694 status->is_short_gi = !(bool)GET_RX_DESC_SPLCP(pdesc);
695 status->is_ht = rtl8821ae_get_rxdesc_is_ht(hw, pdesc);
696 status->is_vht = rtl8821ae_get_rxdesc_is_vht(hw, pdesc);
697 status->vht_nss = rtl8821ae_get_rx_vht_nss(hw, pdesc);
698 status->is_cck = RTL8821AE_RX_HAL_IS_CCK_RATE(status->rate);
700 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
701 "rx_packet_bw=%s,is_ht %d, is_vht %d, vht_nss=%d,is_short_gi %d.\n",
702 (status->rx_packet_bw == 2) ? "80M" :
703 (status->rx_packet_bw == 1) ? "40M" : "20M",
704 status->is_ht, status->is_vht, status->vht_nss,
705 status->is_short_gi);
707 if (GET_RX_STATUS_DESC_RPT_SEL(pdesc))
708 status->packet_report_type = C2H_PACKET;
710 status->packet_report_type = NORMAL_RX;
712 if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
713 status->wake_match = BIT(2);
714 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
715 status->wake_match = BIT(1);
716 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
717 status->wake_match = BIT(0);
719 status->wake_match = 0;
721 if (status->wake_match)
722 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
723 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
725 rx_status->freq = hw->conf.chandef.chan->center_freq;
726 rx_status->band = hw->conf.chandef.chan->band;
728 hdr = (struct ieee80211_hdr *)(skb->data +
729 status->rx_drvinfo_size + status->rx_bufshift);
732 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
734 if (status->rx_packet_bw == HT_CHANNEL_WIDTH_20_40)
735 rx_status->flag |= RX_FLAG_40MHZ;
736 else if (status->rx_packet_bw == HT_CHANNEL_WIDTH_80)
737 rx_status->vht_flag |= RX_VHT_FLAG_80MHZ;
739 rx_status->flag |= RX_FLAG_HT;
741 rx_status->flag |= RX_FLAG_VHT;
743 if (status->is_short_gi)
744 rx_status->flag |= RX_FLAG_SHORT_GI;
746 rx_status->vht_nss = status->vht_nss;
747 rx_status->flag |= RX_FLAG_MACTIME_START;
749 /* hw will set status->decrypted true, if it finds the
750 * frame is open data frame or mgmt frame.
751 * So hw will not decryption robust managment frame
752 * for IEEE80211w but still set status->decrypted
753 * true, so here we should set it back to undecrypted
754 * for IEEE80211w frame, and mac80211 sw will help
757 if (status->decrypted) {
758 if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
759 (ieee80211_has_protected(hdr->frame_control)))
760 rx_status->flag |= RX_FLAG_DECRYPTED;
762 rx_status->flag &= ~RX_FLAG_DECRYPTED;
765 /* rate_idx: index of data rate into band's
766 * supported rates or MCS index if HT rates
767 * are use (RX_FLAG_HT)
769 rx_status->rate_idx =
770 _rtl8821ae_rate_mapping(hw, status->is_ht,
771 status->is_vht, status->rate);
773 rx_status->mactime = status->timestamp_low;
775 p_drvinfo = (struct rx_fwinfo_8821ae *)(skb->data +
776 status->rx_bufshift);
778 translate_rx_signal_stuff(hw, skb, status, pdesc, p_drvinfo);
780 rx_status->signal = status->recvsignalpower + 10;
781 if (status->packet_report_type == TX_REPORT2) {
782 status->macid_valid_entry[0] =
783 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
784 status->macid_valid_entry[1] =
785 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
790 static u8 rtl8821ae_bw_mapping(struct ieee80211_hw *hw,
791 struct rtl_tcb_desc *ptcb_desc)
793 struct rtl_priv *rtlpriv = rtl_priv(hw);
794 struct rtl_phy *rtlphy = &rtlpriv->phy;
795 u8 bw_setting_of_desc = 0;
797 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
798 "rtl8821ae_bw_mapping, current_chan_bw %d, packet_bw %d\n",
799 rtlphy->current_chan_bw, ptcb_desc->packet_bw);
801 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
802 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80)
803 bw_setting_of_desc = 2;
804 else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40)
805 bw_setting_of_desc = 1;
807 bw_setting_of_desc = 0;
808 } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
809 if ((ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) ||
810 (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80))
811 bw_setting_of_desc = 1;
813 bw_setting_of_desc = 0;
815 bw_setting_of_desc = 0;
817 return bw_setting_of_desc;
820 static u8 rtl8821ae_sc_mapping(struct ieee80211_hw *hw,
821 struct rtl_tcb_desc *ptcb_desc)
823 struct rtl_priv *rtlpriv = rtl_priv(hw);
824 struct rtl_phy *rtlphy = &rtlpriv->phy;
825 struct rtl_mac *mac = rtl_mac(rtlpriv);
826 u8 sc_setting_of_desc = 0;
828 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
829 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80) {
830 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
831 } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
832 if (mac->cur_80_prime_sc ==
833 HAL_PRIME_CHNL_OFFSET_LOWER)
835 VHT_DATA_SC_40_LOWER_OF_80MHZ;
836 else if (mac->cur_80_prime_sc ==
837 HAL_PRIME_CHNL_OFFSET_UPPER)
839 VHT_DATA_SC_40_UPPER_OF_80MHZ;
841 RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
842 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
844 if ((mac->cur_40_prime_sc ==
845 HAL_PRIME_CHNL_OFFSET_LOWER) &&
846 (mac->cur_80_prime_sc ==
847 HAL_PRIME_CHNL_OFFSET_LOWER))
849 VHT_DATA_SC_20_LOWEST_OF_80MHZ;
850 else if ((mac->cur_40_prime_sc ==
851 HAL_PRIME_CHNL_OFFSET_UPPER) &&
852 (mac->cur_80_prime_sc ==
853 HAL_PRIME_CHNL_OFFSET_LOWER))
855 VHT_DATA_SC_20_LOWER_OF_80MHZ;
856 else if ((mac->cur_40_prime_sc ==
857 HAL_PRIME_CHNL_OFFSET_LOWER) &&
858 (mac->cur_80_prime_sc ==
859 HAL_PRIME_CHNL_OFFSET_UPPER))
861 VHT_DATA_SC_20_UPPER_OF_80MHZ;
862 else if ((mac->cur_40_prime_sc ==
863 HAL_PRIME_CHNL_OFFSET_UPPER) &&
864 (mac->cur_80_prime_sc ==
865 HAL_PRIME_CHNL_OFFSET_UPPER))
867 VHT_DATA_SC_20_UPPERST_OF_80MHZ;
869 RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
870 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
872 } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
873 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
874 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
875 } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20) {
876 if (mac->cur_40_prime_sc ==
877 HAL_PRIME_CHNL_OFFSET_UPPER) {
879 VHT_DATA_SC_20_UPPER_OF_80MHZ;
880 } else if (mac->cur_40_prime_sc ==
881 HAL_PRIME_CHNL_OFFSET_LOWER){
883 VHT_DATA_SC_20_LOWER_OF_80MHZ;
885 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
889 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
892 return sc_setting_of_desc;
895 void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
896 struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
897 struct ieee80211_tx_info *info,
898 struct ieee80211_sta *sta,
900 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
902 struct rtl_priv *rtlpriv = rtl_priv(hw);
903 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
904 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
905 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
906 u8 *pdesc = (u8 *)pdesc_tx;
908 __le16 fc = hdr->frame_control;
909 unsigned int buf_len = 0;
910 unsigned int skb_len = skb->len;
911 u8 fw_qsel = _rtl8821ae_map_hwqueue_to_fwqueue(skb, hw_queue);
912 bool firstseg = ((hdr->seq_ctrl &
913 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
914 bool lastseg = ((hdr->frame_control &
915 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
919 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
920 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
921 /* reserve 8 byte for AMPDU early mode */
922 if (rtlhal->earlymode_enable) {
923 skb_push(skb, EM_HDR_LEN);
924 memset(skb->data, 0, EM_HDR_LEN);
927 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
929 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
930 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
931 "DMA mapping error");
934 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8821ae));
935 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
940 if (rtlhal->earlymode_enable) {
941 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
942 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
944 if (ptcb_desc->empkt_num) {
945 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
946 "Insert 8 byte.pTcb->EMPktNum:%d\n",
947 ptcb_desc->empkt_num);
948 _rtl8821ae_insert_emcontent(ptcb_desc,
952 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
955 /* ptcb_desc->use_driver_rate = true; */
956 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
957 if (ptcb_desc->hw_rate > DESC_RATEMCS0)
958 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
960 short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
962 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
964 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
965 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
966 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x1f);
968 SET_TX_DESC_SEQ(pdesc, seq_number);
969 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
970 !ptcb_desc->cts_enable) ? 1 : 0));
971 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
972 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
974 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
975 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
976 SET_TX_DESC_RTS_SHORT(pdesc,
977 ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
978 (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
979 (ptcb_desc->rts_use_shortgi ? 1 : 0)));
981 if (ptcb_desc->tx_enable_sw_calc_duration)
982 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
984 SET_TX_DESC_DATA_BW(pdesc,
985 rtl8821ae_bw_mapping(hw, ptcb_desc));
987 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
988 rtl8821ae_sc_mapping(hw, ptcb_desc));
990 SET_TX_DESC_LINIP(pdesc, 0);
991 SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
993 u8 ampdu_density = sta->ht_cap.ampdu_density;
995 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
997 if (info->control.hw_key) {
998 struct ieee80211_key_conf *keyconf =
999 info->control.hw_key;
1000 switch (keyconf->cipher) {
1001 case WLAN_CIPHER_SUITE_WEP40:
1002 case WLAN_CIPHER_SUITE_WEP104:
1003 case WLAN_CIPHER_SUITE_TKIP:
1004 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
1006 case WLAN_CIPHER_SUITE_CCMP:
1007 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
1010 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
1015 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
1016 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
1017 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
1018 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
1020 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
1022 if (ieee80211_is_data_qos(fc)) {
1024 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
1025 "Enable RDG function.\n");
1026 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
1027 SET_TX_DESC_HTC(pdesc, 1);
1032 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
1033 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
1034 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
1035 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
1036 /* if (rtlpriv->dm.useramask) { */
1038 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
1039 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
1041 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
1042 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
1044 if (!ieee80211_is_data_qos(fc)) {
1045 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
1046 SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
1048 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
1049 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
1050 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
1051 SET_TX_DESC_BMC(pdesc, 1);
1054 rtl8821ae_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
1055 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
1058 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
1059 u8 *pdesc, bool firstseg,
1060 bool lastseg, struct sk_buff *skb)
1062 struct rtl_priv *rtlpriv = rtl_priv(hw);
1063 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1064 u8 fw_queue = QSLT_BEACON;
1066 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
1067 skb->data, skb->len,
1070 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
1071 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
1072 "DMA mapping error");
1075 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
1077 SET_TX_DESC_FIRST_SEG(pdesc, 1);
1078 SET_TX_DESC_LAST_SEG(pdesc, 1);
1080 SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len));
1082 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
1084 SET_TX_DESC_USE_RATE(pdesc, 1);
1085 SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
1086 SET_TX_DESC_DISABLE_FB(pdesc, 1);
1088 SET_TX_DESC_DATA_BW(pdesc, 0);
1090 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
1092 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
1094 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
1096 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
1098 SET_TX_DESC_MACID(pdesc, 0);
1100 SET_TX_DESC_OWN(pdesc, 1);
1102 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
1103 "H2C Tx Cmd Content\n",
1104 pdesc, TX_DESC_SIZE);
1107 void rtl8821ae_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
1108 bool istx, u8 desc_name, u8 *val)
1111 switch (desc_name) {
1113 SET_TX_DESC_OWN(pdesc, 1);
1115 case HW_DESC_TX_NEXTDESC_ADDR:
1116 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
1120 "ERR txdesc :%d not process\n", desc_name);
1124 switch (desc_name) {
1126 SET_RX_DESC_OWN(pdesc, 1);
1128 case HW_DESC_RXBUFF_ADDR:
1129 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
1131 case HW_DESC_RXPKT_LEN:
1132 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
1135 SET_RX_DESC_EOR(pdesc, 1);
1139 "ERR rxdesc :%d not process\n", desc_name);
1145 u32 rtl8821ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
1150 switch (desc_name) {
1152 ret = GET_TX_DESC_OWN(pdesc);
1154 case HW_DESC_TXBUFF_ADDR:
1155 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
1159 "ERR txdesc :%d not process\n", desc_name);
1163 switch (desc_name) {
1165 ret = GET_RX_DESC_OWN(pdesc);
1167 case HW_DESC_RXPKT_LEN:
1168 ret = GET_RX_DESC_PKT_LEN(pdesc);
1170 case HW_DESC_RXBUFF_ADDR:
1171 ret = GET_RX_DESC_BUFF_ADDR(pdesc);
1175 "ERR rxdesc :%d not process\n", desc_name);
1182 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw *hw,
1183 u8 hw_queue, u16 index)
1185 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1186 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
1187 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
1188 u8 own = (u8)rtl8821ae_get_desc(entry, true, HW_DESC_OWN);
1191 *beacon packet will only use the first
1192 *descriptor defautly,and the own may not
1193 *be cleared by the hardware
1200 void rtl8821ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
1202 struct rtl_priv *rtlpriv = rtl_priv(hw);
1204 if (hw_queue == BEACON_QUEUE) {
1205 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
1207 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
1208 BIT(0) << (hw_queue));
1212 u32 rtl8821ae_rx_command_packet(struct ieee80211_hw *hw,
1213 struct rtl_stats status,
1214 struct sk_buff *skb)
1217 struct rtl_priv *rtlpriv = rtl_priv(hw);
1219 switch (status.packet_report_type) {
1224 rtl8821ae_c2h_packet_handler(hw, skb->data, (u8)skb->len);
1226 RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
1227 "skb->len=%d\n\n", skb->len);
1230 RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
1231 "No this packet type!!\n");