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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
41 u8 _rtl8821ae_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
43 u16 fc = rtl_get_fc(skb);
45 if (unlikely(ieee80211_is_beacon(fc)))
47 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
53 /* mac80211's rate_idx is like this:
55 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
58 * (rx_status->flag & RX_FLAG_HT) = 0,
59 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
62 * (rx_status->flag & RX_FLAG_HT) = 1,
63 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
65 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
67 * (rx_status->flag & RX_FLAG_HT) = 0,
68 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
71 * (rx_status->flag & RX_FLAG_HT) = 1,
72 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
74 static int _rtl8821ae_rate_mapping(struct ieee80211_hw *hw,
75 bool isht, u8 desc_rate)
80 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
81 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
83 if (IEEE80211_BAND_2GHZ == hw->conf.channel->band) {
215 static void _rtl8821ae_query_rxphystatus(struct ieee80211_hw *hw,
216 struct rtl_stats *pstatus, u8 *pdesc,
217 struct rx_fwinfo_8821ae *p_drvinfo, bool bpacket_match_bssid,
218 bool bpacket_toself, bool b_packet_beacon)
220 struct rtl_priv *rtlpriv = rtl_priv(hw);
221 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
222 struct phy_sts_cck_8821ae_t *cck_buf;
223 struct phy_status_rpt *p_phystRpt = (struct phy_status_rpt *)p_drvinfo;
224 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
225 char rx_pwr_all = 0, rx_pwr[4];
226 u8 rf_rx_num = 0, evm, pwdb_all;
227 u8 i, max_spatial_stream;
228 u32 rssi, total_rssi = 0;
229 bool b_is_cck = pstatus->b_is_cck;
232 /* Record it for next packet processing */
233 pstatus->b_packet_matchbssid = bpacket_match_bssid;
234 pstatus->b_packet_toself = bpacket_toself;
235 pstatus->b_packet_beacon = b_packet_beacon;
236 pstatus->rx_mimo_signalquality[0] = -1;
237 pstatus->rx_mimo_signalquality[1] = -1;
242 /* CCK Driver info Structure is not the same as OFDM packet. */
243 cck_buf = (struct phy_sts_cck_8821ae_t *)p_drvinfo;
244 cck_agc_rpt = cck_buf->cck_agc_rpt;
246 /* (1)Hardware does not provide RSSI for CCK */
247 /* (2)PWDB, Average PWDB cacluated by
248 * hardware (for rate adaptive) */
249 if (ppsc->rfpwr_state == ERFON)
250 cck_highpwr = (u8) rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
255 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
256 vga_idx = (cck_agc_rpt & 0x1f);
260 rx_pwr_all = -100 + 2*(27-vga_idx); /*VGA_idx = 27~2*/
265 rx_pwr_all = -48 + 2*(2-vga_idx); /*VGA_idx = 2~0*/
268 rx_pwr_all = -42 + 2*(7-vga_idx); /*VGA_idx = 7~5*/
271 rx_pwr_all = -36 + 2*(7-vga_idx); /*VGA_idx = 7~4*/
274 rx_pwr_all = -24 + 2*(7-vga_idx); /*VGA_idx = 7~0*/
278 rx_pwr_all = -12 + 2*(5-vga_idx); /*VGA_idx = 5~0*/
280 rx_pwr_all = -6+ 2*(5-vga_idx);
283 rx_pwr_all = 8-2*vga_idx;
286 rx_pwr_all = 14-2*vga_idx;
292 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
293 /* CCK gain is smaller than OFDM/MCS gain, */
294 /* so we add gain diff by experiences,
299 /* modify the offset to make the same
300 * gain index with OFDM. */
301 if(pwdb_all > 34 && pwdb_all <= 42)
303 else if(pwdb_all > 26 && pwdb_all <= 34)
305 else if(pwdb_all > 14 && pwdb_all <= 26)
307 else if(pwdb_all > 4 && pwdb_all <= 14)
309 if (cck_highpwr == false){
311 pwdb_all =((pwdb_all-80)<<1)+((pwdb_all-80)>>1)+80;
312 else if((pwdb_all <= 78) && (pwdb_all >= 20))
318 pstatus->rx_pwdb_all = pwdb_all;
319 pstatus->recvsignalpower = rx_pwr_all;
321 /* (3) Get Signal Quality (EVM) */
322 if (bpacket_match_bssid) {
325 if (pstatus->rx_pwdb_all > 40)
328 sq = cck_buf->sq_rpt;
334 sq = ((64 - sq) * 100) / 44;
337 pstatus->signalquality = sq;
338 pstatus->rx_mimo_signalquality[0] = sq;
339 pstatus->rx_mimo_signalquality[1] = -1;
342 rtlpriv->dm.brfpath_rxenable[0] =
343 rtlpriv->dm.brfpath_rxenable[1] = true;
345 /* (1)Get RSSI for HT rate */
346 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
348 /* we will judge RF RX path now. */
349 if (rtlpriv->dm.brfpath_rxenable[i])
352 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110;
354 /* Translate DBM to percentage. */
355 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
358 /* Get Rx snr value in DB */
359 rtlpriv->stats.rx_snr_db[i] = (long)(p_drvinfo->rxsnr[i] / 2);
361 /* Record Signal Strength for next packet */
362 if (bpacket_match_bssid)
363 pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
366 /* (2)PWDB, Average PWDB cacluated by
367 * hardware (for rate adaptive) */
368 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
370 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
371 pstatus->rx_pwdb_all = pwdb_all;
372 pstatus->rxpower = rx_pwr_all;
373 pstatus->recvsignalpower = rx_pwr_all;
375 /* (3)EVM of HT rate */
376 if (pstatus->b_is_ht && pstatus->rate >= DESC_RATEMCS8 &&
377 pstatus->rate <= DESC_RATEMCS15)
378 max_spatial_stream = 2;
380 max_spatial_stream = 1;
382 for (i = 0; i < max_spatial_stream; i++) {
383 evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
385 if (bpacket_match_bssid) {
386 /* Fill value in RFD, Get the first
387 * spatial stream only */
389 pstatus->signalquality = (u8) (evm & 0xff);
390 pstatus->rx_mimo_signalquality[i] = (u8) (evm & 0xff);
395 /* UI BSS List signal strength(in percentage),
396 * make it good looking, from 0~100. */
398 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
400 else if (rf_rx_num != 0)
401 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
402 total_rssi /= rf_rx_num));
403 /*HW antenna diversity*/
404 rtldm->fat_table.antsel_rx_keep_0 = p_phystRpt->ant_sel;
405 rtldm->fat_table.antsel_rx_keep_1 = p_phystRpt->ant_sel_b;
406 rtldm->fat_table.antsel_rx_keep_2 = p_phystRpt->antsel_rx_keep_2;
410 static void _rtl8821ae_smart_antenna(struct ieee80211_hw *hw,
411 struct rtl_stats *pstatus)
413 struct rtl_dm *rtldm= rtl_dm(rtl_priv(hw));
414 struct rtl_efuse *rtlefuse =rtl_efuse(rtl_priv(hw));
416 struct fast_ant_trainning *pfat_table = &(rtldm->fat_table);
418 if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
419 if (pfat_table->fat_state == FAT_TRAINING_STATE) {
420 if (pstatus->b_packet_toself) {
421 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
422 (pfat_table->antsel_rx_keep_1 << 1) | pfat_table->antsel_rx_keep_0;
423 pfat_table->ant_sum_rssi[antsel_tr_mux] += pstatus->rx_pwdb_all;
424 pfat_table->ant_rssi_cnt[antsel_tr_mux]++;
427 } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
428 (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
429 if (pstatus->b_packet_toself || pstatus->b_packet_matchbssid) {
430 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
431 (pfat_table->antsel_rx_keep_1 << 1) | pfat_table->antsel_rx_keep_0;
432 rtl8821ae_dm_ant_sel_statistics(hw, antsel_tr_mux, 0, pstatus->rx_pwdb_all);
438 static void _rtl8821ae_translate_rx_signal_stuff(struct ieee80211_hw *hw,
439 struct sk_buff *skb, struct rtl_stats *pstatus,
440 u8 *pdesc, struct rx_fwinfo_8821ae *p_drvinfo)
442 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
443 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
444 struct ieee80211_hdr *hdr;
449 bool b_packet_matchbssid, b_packet_toself, b_packet_beacon;
451 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
453 hdr = (struct ieee80211_hdr *)tmp_buf;
454 fc = le16_to_cpu(hdr->frame_control);
455 type = WLAN_FC_GET_TYPE(fc);
457 psaddr = ieee80211_get_SA(hdr);
458 memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
460 b_packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
461 (!ether_addr_equal(mac->bssid, (fc & IEEE80211_FCTL_TODS) ?
462 hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ?
463 hdr->addr2 : hdr->addr3)) && (!pstatus->b_hwerror) &&
464 (!pstatus->b_crc) && (!pstatus->b_icv));
466 b_packet_toself = b_packet_matchbssid &&
467 (!ether_addr_equal(praddr, rtlefuse->dev_addr));
469 if (ieee80211_is_beacon(fc))
470 b_packet_beacon = true;
472 b_packet_beacon = false;
474 if (b_packet_beacon && b_packet_matchbssid)
475 rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
477 _rtl8821ae_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
478 b_packet_matchbssid, b_packet_toself,
480 /*_rtl8821ae_smart_antenna(hw, pstatus); */
481 rtl_process_phyinfo(hw, tmp_buf, pstatus);
484 static void _rtl8821ae_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
488 memset(virtualaddress, 0, 8);
490 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
491 if (ptcb_desc->empkt_num == 1)
492 dwtmp = ptcb_desc->empkt_len[0];
494 dwtmp = ptcb_desc->empkt_len[0];
495 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
496 dwtmp += ptcb_desc->empkt_len[1];
498 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
500 if (ptcb_desc->empkt_num <= 3)
501 dwtmp = ptcb_desc->empkt_len[2];
503 dwtmp = ptcb_desc->empkt_len[2];
504 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
505 dwtmp += ptcb_desc->empkt_len[3];
507 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
508 if (ptcb_desc->empkt_num <= 5)
509 dwtmp = ptcb_desc->empkt_len[4];
511 dwtmp = ptcb_desc->empkt_len[4];
512 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
513 dwtmp += ptcb_desc->empkt_len[5];
515 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
516 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
517 if (ptcb_desc->empkt_num <= 7)
518 dwtmp = ptcb_desc->empkt_len[6];
520 dwtmp = ptcb_desc->empkt_len[6];
521 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
522 dwtmp += ptcb_desc->empkt_len[7];
524 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
525 if (ptcb_desc->empkt_num <= 9)
526 dwtmp = ptcb_desc->empkt_len[8];
528 dwtmp = ptcb_desc->empkt_len[8];
529 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
530 dwtmp += ptcb_desc->empkt_len[9];
532 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
535 bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw,
536 struct rtl_stats *status,
537 struct ieee80211_rx_status *rx_status,
538 u8 *pdesc, struct sk_buff *skb)
540 struct rtl_priv *rtlpriv = rtl_priv(hw);
541 struct rx_fwinfo_8821ae *p_drvinfo;
542 struct ieee80211_hdr *hdr;
544 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
546 status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
547 status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
548 RX_DRV_INFO_SIZE_UNIT;
549 status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
550 status->b_icv = (u16) GET_RX_DESC_ICV(pdesc);
551 status->b_crc = (u16) GET_RX_DESC_CRC32(pdesc);
552 status->b_hwerror = (status->b_crc | status->b_icv);
553 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
554 status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
555 status->b_shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
556 status->b_isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
557 status->b_isfirst_ampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
558 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
559 status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
560 status->macid = GET_RX_DESC_MACID(pdesc);
561 status->b_is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
563 status->b_is_cck = RX_HAL_IS_CCK_RATE(status->rate);
565 if (GET_RX_STATUS_DESC_RPT_SEL(pdesc))
566 status->packet_report_type = C2H_PACKET;
568 status->packet_report_type = NORMAL_RX;
570 if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
571 status->wake_match = BIT(2);
572 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
573 status->wake_match = BIT(1);
574 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
575 status->wake_match = BIT(0);
577 status->wake_match = 0;
579 if (status->wake_match)
580 RT_TRACE(COMP_RXDESC,DBG_LOUD,
581 ("GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",status->wake_match ));
582 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
583 rx_status->freq = hw->conf.chandef.chan->center_freq;
584 rx_status->band = hw->conf.chandef.chan->band;
586 rx_status->freq = hw->conf.channel->center_freq;
587 rx_status->band = hw->conf.channel->band;
590 hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
591 + status->rx_bufshift);
594 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
596 if (status->rx_is40Mhzpacket)
597 rx_status->flag |= RX_FLAG_40MHZ;
600 rx_status->flag |= RX_FLAG_HT;
602 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
604 /* hw will set status->decrypted true, if it finds the
605 * frame is open data frame or mgmt frame. */
606 /* So hw will not decryption robust managment frame
607 * for IEEE80211w but still set status->decrypted
608 * true, so here we should set it back to undecrypted
609 * for IEEE80211w frame, and mac80211 sw will help
611 if (status->decrypted) {
614 pr_err("decrypted is true but hdr NULL, from skb %p\n",
619 if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
620 (ieee80211_has_protected(hdr->frame_control)))
621 rx_status->flag &= ~RX_FLAG_DECRYPTED;
623 rx_status->flag |= RX_FLAG_DECRYPTED;
626 /* rate_idx: index of data rate into band's
627 * supported rates or MCS index if HT rates
628 * are use (RX_FLAG_HT)*/
629 /* Notice: this is diff with windows define */
630 rx_status->rate_idx = _rtl8821ae_rate_mapping(hw,
631 status->b_is_ht, status->rate);
633 rx_status->mactime = status->timestamp_low;
634 if (phystatus == true) {
635 p_drvinfo = (struct rx_fwinfo_8821ae *)(skb->data +
636 status->rx_bufshift);
638 _rtl8821ae_translate_rx_signal_stuff(hw,
643 /*rx_status->qual = status->signal; */
644 rx_status->signal = status->recvsignalpower + 10;
645 /*rx_status->noise = -status->noise; */
646 if (status->packet_report_type == TX_REPORT2){
647 status->macid_valid_entry[0] = GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
648 status->macid_valid_entry[1] = GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
653 /*<delete in kernel start>*/
654 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
655 void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
656 struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
657 struct ieee80211_tx_info *info, struct sk_buff *skb,
658 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
660 /*<delete in kernel end>*/
661 void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
662 struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
663 struct ieee80211_tx_info *info,
664 struct ieee80211_sta *sta,
666 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
667 /*<delete in kernel start>*/
669 /*<delete in kernel end>*/
671 struct rtl_priv *rtlpriv = rtl_priv(hw);
672 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
673 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
674 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
675 /*<delete in kernel start>*/
676 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
677 struct ieee80211_sta *sta = info->control.sta;
679 /*<delete in kernel end>*/
680 u8 *pdesc = (u8 *) pdesc_tx;
682 u16 fc = le16_to_cpu(hdr->frame_control);
683 unsigned int buf_len = 0;
684 unsigned int skb_len = skb->len;
685 u8 fw_qsel = _rtl8821ae_map_hwqueue_to_fwqueue(skb, hw_queue);
686 bool b_firstseg = ((hdr->seq_ctrl &
687 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
688 bool b_lastseg = ((hdr->frame_control &
689 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
694 if (mac->opmode == NL80211_IFTYPE_STATION) {
696 } else if (mac->opmode == NL80211_IFTYPE_AP ||
697 mac->opmode == NL80211_IFTYPE_ADHOC) {
699 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
701 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
702 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
703 /* reserve 8 byte for AMPDU early mode */
704 if (rtlhal->b_earlymode_enable) {
705 skb_push(skb, EM_HDR_LEN);
706 memset(skb->data, 0, EM_HDR_LEN);
709 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
711 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
712 RT_TRACE(COMP_SEND, DBG_TRACE,
713 ("DMA mapping error"));
716 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8821ae));
717 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
722 if (rtlhal->b_earlymode_enable) {
723 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
724 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN + EM_HDR_LEN);
725 if (ptcb_desc->empkt_num) {
726 RT_TRACE(COMP_SEND, DBG_TRACE,
727 ("Insert 8 byte.pTcb->EMPktNum:%d\n",
728 ptcb_desc->empkt_num));
729 _rtl8821ae_insert_emcontent(ptcb_desc, (u8 *)(skb->data));
732 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
735 /* ptcb_desc->use_driver_rate = true; */
736 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
737 if (ptcb_desc->hw_rate > DESC_RATEMCS0) {
738 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
740 short_gi = (ptcb_desc->use_shortpreamble) ? 1 :0;
742 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
744 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
745 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
746 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
748 SET_TX_DESC_SEQ(pdesc, seq_number);
749 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->b_rts_enable &&
750 !ptcb_desc->b_cts_enable) ? 1 : 0));
751 SET_TX_DESC_HW_RTS_ENABLE(pdesc,0);
752 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->b_cts_enable) ? 1 : 0));
753 /* SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->b_rts_stbc) ? 1 : 0));*/
755 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
756 /* SET_TX_DESC_RTS_BW(pdesc, 0);*/
757 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
758 SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
759 (ptcb_desc->b_rts_use_shortpreamble ? 1 : 0) :
760 (ptcb_desc->b_rts_use_shortgi ? 1 : 0)));
762 if(ptcb_desc->btx_enable_sw_calc_duration)
763 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
766 if (ptcb_desc->b_packet_bw) {
767 SET_TX_DESC_DATA_BW(pdesc, 1);
768 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
770 SET_TX_DESC_DATA_BW(pdesc, 0);
771 SET_TX_DESC_TX_SUB_CARRIER(pdesc, mac->cur_40_prime_sc);
774 SET_TX_DESC_DATA_BW(pdesc, 0);
775 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
778 SET_TX_DESC_LINIP(pdesc, 0);
779 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
781 u8 ampdu_density = sta->ht_cap.ampdu_density;
782 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
784 if (info->control.hw_key) {
785 struct ieee80211_key_conf *keyconf = info->control.hw_key;
786 /*<delete in kernel start>*/
787 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
788 /*<delete in kernel end>*/
789 switch (keyconf->cipher) {
790 case WLAN_CIPHER_SUITE_WEP40:
791 case WLAN_CIPHER_SUITE_WEP104:
792 case WLAN_CIPHER_SUITE_TKIP:
793 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
795 case WLAN_CIPHER_SUITE_CCMP:
796 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
799 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
803 /*<delete in kernel start>*/
805 switch (keyconf->alg) {
808 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
811 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
814 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
819 /*<delete in kernel end>*/
822 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
823 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
824 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
825 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ? 1 : 0);
826 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
829 SET_TX_DESC_USE_RATE(pdesc, 1);
830 SET_TX_DESC_TX_RATE(pdesc, 0x04);
832 SET_TX_DESC_RETRY_LIMIT_ENABLE(pdesc, 1);
833 SET_TX_DESC_DATA_RETRY_LIMIT(pdesc, 0x3f);
836 /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
837 /* Set TxRate and RTSRate in TxDesc */
838 /* This prevent Tx initial rate of new-coming packets */
839 /* from being overwritten by retried packet rate.*/
840 if (!ptcb_desc->use_driver_rate) {
841 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
842 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
844 if (ieee80211_is_data_qos(fc)) {
846 RT_TRACE(COMP_SEND, DBG_TRACE,
847 ("Enable RDG function.\n"));
848 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
849 SET_TX_DESC_HTC(pdesc, 1);
854 SET_TX_DESC_FIRST_SEG(pdesc, (b_firstseg ? 1 : 0));
855 SET_TX_DESC_LAST_SEG(pdesc, (b_lastseg ? 1 : 0));
856 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
857 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
858 //if (rtlpriv->dm.b_useramask) {
860 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
861 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
863 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
864 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
866 /* if (ieee80211_is_data_qos(fc))
867 SET_TX_DESC_QOS(pdesc, 1);
869 if (!ieee80211_is_data_qos(fc)) {
870 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
871 SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
873 SET_TX_DESC_MORE_FRAG(pdesc, (b_lastseg ? 0 : 1));
874 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
875 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
876 SET_TX_DESC_BMC(pdesc, 1);
879 rtl8821ae_dm_set_tx_ant_by_tx_info(hw,pdesc,ptcb_desc->mac_id);
880 RT_TRACE(COMP_SEND, DBG_TRACE, ("\n"));
883 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
884 u8 *pdesc, bool b_firstseg,
885 bool b_lastseg, struct sk_buff *skb)
887 struct rtl_priv *rtlpriv = rtl_priv(hw);
888 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
889 u8 fw_queue = QSLT_BEACON;
891 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
895 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
896 RT_TRACE(COMP_SEND, DBG_TRACE,
897 ("DMA mapping error"));
900 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
902 SET_TX_DESC_FIRST_SEG(pdesc, 1);
903 SET_TX_DESC_LAST_SEG(pdesc, 1);
905 SET_TX_DESC_PKT_SIZE((u8 *) pdesc, (u16) (skb->len));
907 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
909 SET_TX_DESC_USE_RATE(pdesc, 1);
910 SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
911 SET_TX_DESC_DISABLE_FB(pdesc, 1);
913 SET_TX_DESC_DATA_BW(pdesc, 0);
915 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
917 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
919 if(IsCtrlNDPA(VirtualAddress) || IsMgntNDPA(VirtualAddress))
921 SET_TX_DESC_DATA_RETRY_LIMIT_8812(pDesc, 5);
922 SET_TX_DESC_RETRY_LIMIT_ENABLE_8812(pDesc, 1);
924 if(IsMgntNDPA(VirtualAddress))
926 SET_TX_DESC_NDPA_8812(pDesc, 1);
927 SET_TX_DESC_RTS_SC_8812(pDesc, SCMapping_8812(Adapter, pTcb));
931 SET_TX_DESC_NDPA_8812(pDesc, 2);
932 SET_TX_DESC_RTS_SC_8812(pDesc, SCMapping_8812(Adapter, pTcb));
936 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
938 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
940 SET_TX_DESC_MACID(pdesc, 0);
942 SET_TX_DESC_OWN(pdesc, 1);
944 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
945 "H2C Tx Cmd Content\n",
946 pdesc, TX_DESC_SIZE);
949 void rtl8821ae_set_desc(struct ieee80211_hw * hw, u8 *pdesc, bool istx, u8 desc_name, u8 *val)
954 SET_TX_DESC_OWN(pdesc, 1);
956 case HW_DESC_TX_NEXTDESC_ADDR:
957 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
960 RT_ASSERT(false, ("ERR txdesc :%d"
961 " not process\n", desc_name));
967 SET_RX_DESC_OWN(pdesc, 1);
969 case HW_DESC_RXBUFF_ADDR:
970 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val);
972 case HW_DESC_RXPKT_LEN:
973 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val);
976 SET_RX_DESC_EOR(pdesc, 1);
979 RT_ASSERT(false, ("ERR rxdesc :%d "
980 "not process\n", desc_name));
986 u32 rtl8821ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
993 ret = GET_TX_DESC_OWN(pdesc);
995 case HW_DESC_TXBUFF_ADDR:
996 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
999 RT_ASSERT(false, ("ERR txdesc :%d "
1000 "not process\n", desc_name));
1004 switch (desc_name) {
1006 ret = GET_RX_DESC_OWN(pdesc);
1008 case HW_DESC_RXPKT_LEN:
1009 ret = GET_RX_DESC_PKT_LEN(pdesc);
1012 RT_ASSERT(false, ("ERR rxdesc :%d "
1013 "not process\n", desc_name));
1020 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw *hw,
1021 u8 hw_queue, u16 index)
1023 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1024 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
1025 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
1026 u8 own = (u8) rtl8821ae_get_desc(entry, true, HW_DESC_OWN);
1029 *beacon packet will only use the first
1030 *descriptor defautly,and the own may not
1031 *be cleared by the hardware
1040 void rtl8821ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
1042 struct rtl_priv *rtlpriv = rtl_priv(hw);
1044 if (hw_queue == BEACON_QUEUE) {
1045 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
1047 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
1048 BIT(0) << (hw_queue));