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 static 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 (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
211 static void _rtl8821ae_query_rxphystatus(struct ieee80211_hw *hw,
212 struct rtl_stats *pstatus, u8 *pdesc,
213 struct rx_fwinfo_8821ae *p_drvinfo, bool bpacket_match_bssid,
214 bool bpacket_toself, bool b_packet_beacon)
216 struct rtl_priv *rtlpriv = rtl_priv(hw);
217 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
218 struct phy_sts_cck_8821ae_t *cck_buf;
219 struct phy_status_rpt *p_phystRpt = (struct phy_status_rpt *)p_drvinfo;
220 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
221 char rx_pwr_all = 0, rx_pwr[4];
222 u8 rf_rx_num = 0, evm, pwdb_all;
223 u8 i, max_spatial_stream;
224 u32 rssi, total_rssi = 0;
225 bool b_is_cck = pstatus->b_is_cck;
228 /* Record it for next packet processing */
229 pstatus->b_packet_matchbssid = bpacket_match_bssid;
230 pstatus->b_packet_toself = bpacket_toself;
231 pstatus->b_packet_beacon = b_packet_beacon;
232 pstatus->rx_mimo_signalquality[0] = -1;
233 pstatus->rx_mimo_signalquality[1] = -1;
238 /* CCK Driver info Structure is not the same as OFDM packet. */
239 cck_buf = (struct phy_sts_cck_8821ae_t *)p_drvinfo;
240 cck_agc_rpt = cck_buf->cck_agc_rpt;
242 /* (1)Hardware does not provide RSSI for CCK */
243 /* (2)PWDB, Average PWDB calculated by
244 * hardware (for rate adaptive) */
245 if (ppsc->rfpwr_state == ERFON)
246 cck_highpwr = (u8) rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
251 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
252 vga_idx = (cck_agc_rpt & 0x1f);
256 rx_pwr_all = -100 + 2*(27-vga_idx); /*VGA_idx = 27~2*/
261 rx_pwr_all = -48 + 2*(2-vga_idx); /*VGA_idx = 2~0*/
264 rx_pwr_all = -42 + 2*(7-vga_idx); /*VGA_idx = 7~5*/
267 rx_pwr_all = -36 + 2*(7-vga_idx); /*VGA_idx = 7~4*/
270 rx_pwr_all = -24 + 2*(7-vga_idx); /*VGA_idx = 7~0*/
274 rx_pwr_all = -12 + 2*(5-vga_idx); /*VGA_idx = 5~0*/
276 rx_pwr_all = -6+ 2*(5-vga_idx);
279 rx_pwr_all = 8-2*vga_idx;
282 rx_pwr_all = 14-2*vga_idx;
288 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
289 /* CCK gain is smaller than OFDM/MCS gain, */
290 /* so we add gain diff by experiences,
295 /* modify the offset to make the same
296 * gain index with OFDM. */
297 if(pwdb_all > 34 && pwdb_all <= 42)
299 else if(pwdb_all > 26 && pwdb_all <= 34)
301 else if(pwdb_all > 14 && pwdb_all <= 26)
303 else if(pwdb_all > 4 && pwdb_all <= 14)
305 if (cck_highpwr == false){
307 pwdb_all =((pwdb_all-80)<<1)+((pwdb_all-80)>>1)+80;
308 else if((pwdb_all <= 78) && (pwdb_all >= 20))
314 pstatus->rx_pwdb_all = pwdb_all;
315 pstatus->recvsignalpower = rx_pwr_all;
317 /* (3) Get Signal Quality (EVM) */
318 if (bpacket_match_bssid) {
321 if (pstatus->rx_pwdb_all > 40)
324 sq = cck_buf->sq_rpt;
330 sq = ((64 - sq) * 100) / 44;
333 pstatus->signalquality = sq;
334 pstatus->rx_mimo_signalquality[0] = sq;
335 pstatus->rx_mimo_signalquality[1] = -1;
338 rtlpriv->dm.brfpath_rxenable[0] =
339 rtlpriv->dm.brfpath_rxenable[1] = true;
341 /* (1)Get RSSI for HT rate */
342 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
344 /* we will judge RF RX path now. */
345 if (rtlpriv->dm.brfpath_rxenable[i])
348 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110;
350 /* Translate DBM to percentage. */
351 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
354 /* Get Rx snr value in DB */
355 rtlpriv->stats.rx_snr_db[i] = (long)(p_drvinfo->rxsnr[i] / 2);
357 /* Record Signal Strength for next packet */
358 if (bpacket_match_bssid)
359 pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
362 /* (2)PWDB, Average PWDB calculated by
363 * hardware (for rate adaptive) */
364 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
366 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
367 pstatus->rx_pwdb_all = pwdb_all;
368 pstatus->rxpower = rx_pwr_all;
369 pstatus->recvsignalpower = rx_pwr_all;
371 /* (3)EVM of HT rate */
372 if (pstatus->b_is_ht && pstatus->rate >= DESC_RATEMCS8 &&
373 pstatus->rate <= DESC_RATEMCS15)
374 max_spatial_stream = 2;
376 max_spatial_stream = 1;
378 for (i = 0; i < max_spatial_stream; i++) {
379 evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
381 if (bpacket_match_bssid) {
382 /* Fill value in RFD, Get the first
383 * spatial stream only */
385 pstatus->signalquality = (u8) (evm & 0xff);
386 pstatus->rx_mimo_signalquality[i] = (u8) (evm & 0xff);
391 /* UI BSS List signal strength(in percentage),
392 * make it good looking, from 0~100. */
394 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
396 else if (rf_rx_num != 0)
397 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
398 total_rssi /= rf_rx_num));
399 /*HW antenna diversity*/
400 rtldm->fat_table.antsel_rx_keep_0 = p_phystRpt->ant_sel;
401 rtldm->fat_table.antsel_rx_keep_1 = p_phystRpt->ant_sel_b;
402 rtldm->fat_table.antsel_rx_keep_2 = p_phystRpt->antsel_rx_keep_2;
406 static void _rtl8821ae_smart_antenna(struct ieee80211_hw *hw,
407 struct rtl_stats *pstatus)
409 struct rtl_dm *rtldm= rtl_dm(rtl_priv(hw));
410 struct rtl_efuse *rtlefuse =rtl_efuse(rtl_priv(hw));
412 struct fast_ant_trainning *pfat_table = &(rtldm->fat_table);
414 if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) {
415 if (pfat_table->fat_state == FAT_TRAINING_STATE) {
416 if (pstatus->b_packet_toself) {
417 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
418 (pfat_table->antsel_rx_keep_1 << 1) | pfat_table->antsel_rx_keep_0;
419 pfat_table->ant_sum_rssi[antsel_tr_mux] += pstatus->rx_pwdb_all;
420 pfat_table->ant_rssi_cnt[antsel_tr_mux]++;
423 } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) ||
424 (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) {
425 if (pstatus->b_packet_toself || pstatus->b_packet_matchbssid) {
426 antsel_tr_mux = (pfat_table->antsel_rx_keep_2 << 2) |
427 (pfat_table->antsel_rx_keep_1 << 1) | pfat_table->antsel_rx_keep_0;
428 rtl8821ae_dm_ant_sel_statistics(hw, antsel_tr_mux, 0, pstatus->rx_pwdb_all);
434 static void _rtl8821ae_translate_rx_signal_stuff(struct ieee80211_hw *hw,
435 struct sk_buff *skb, struct rtl_stats *pstatus,
436 u8 *pdesc, struct rx_fwinfo_8821ae *p_drvinfo)
438 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
439 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
440 struct ieee80211_hdr *hdr;
445 bool b_packet_matchbssid, b_packet_toself, b_packet_beacon;
447 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
449 hdr = (struct ieee80211_hdr *)tmp_buf;
450 fc = le16_to_cpu(hdr->frame_control);
451 type = WLAN_FC_GET_TYPE(fc);
453 psaddr = ieee80211_get_SA(hdr);
454 memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
456 b_packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
457 (!ether_addr_equal(mac->bssid, (fc & IEEE80211_FCTL_TODS) ?
458 hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ?
459 hdr->addr2 : hdr->addr3)) && (!pstatus->b_hwerror) &&
460 (!pstatus->b_crc) && (!pstatus->b_icv));
462 b_packet_toself = b_packet_matchbssid &&
463 (!ether_addr_equal(praddr, rtlefuse->dev_addr));
465 if (ieee80211_is_beacon(fc))
466 b_packet_beacon = true;
468 b_packet_beacon = false;
470 if (b_packet_beacon && b_packet_matchbssid)
471 rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
473 _rtl8821ae_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
474 b_packet_matchbssid, b_packet_toself,
476 /*_rtl8821ae_smart_antenna(hw, pstatus); */
477 rtl_process_phyinfo(hw, tmp_buf, pstatus);
480 static void _rtl8821ae_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
484 memset(virtualaddress, 0, 8);
486 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
487 if (ptcb_desc->empkt_num == 1)
488 dwtmp = ptcb_desc->empkt_len[0];
490 dwtmp = ptcb_desc->empkt_len[0];
491 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
492 dwtmp += ptcb_desc->empkt_len[1];
494 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
496 if (ptcb_desc->empkt_num <= 3)
497 dwtmp = ptcb_desc->empkt_len[2];
499 dwtmp = ptcb_desc->empkt_len[2];
500 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
501 dwtmp += ptcb_desc->empkt_len[3];
503 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
504 if (ptcb_desc->empkt_num <= 5)
505 dwtmp = ptcb_desc->empkt_len[4];
507 dwtmp = ptcb_desc->empkt_len[4];
508 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
509 dwtmp += ptcb_desc->empkt_len[5];
511 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
512 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
513 if (ptcb_desc->empkt_num <= 7)
514 dwtmp = ptcb_desc->empkt_len[6];
516 dwtmp = ptcb_desc->empkt_len[6];
517 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
518 dwtmp += ptcb_desc->empkt_len[7];
520 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
521 if (ptcb_desc->empkt_num <= 9)
522 dwtmp = ptcb_desc->empkt_len[8];
524 dwtmp = ptcb_desc->empkt_len[8];
525 dwtmp += ((dwtmp%4)?(4-dwtmp%4):0)+4;
526 dwtmp += ptcb_desc->empkt_len[9];
528 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
531 bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw,
532 struct rtl_stats *status,
533 struct ieee80211_rx_status *rx_status,
534 u8 *pdesc, struct sk_buff *skb)
536 struct rtl_priv *rtlpriv = rtl_priv(hw);
537 struct rx_fwinfo_8821ae *p_drvinfo;
538 struct ieee80211_hdr *hdr;
540 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
542 status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
543 status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
544 RX_DRV_INFO_SIZE_UNIT;
545 status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
546 status->b_icv = (u16) GET_RX_DESC_ICV(pdesc);
547 status->b_crc = (u16) GET_RX_DESC_CRC32(pdesc);
548 status->b_hwerror = (status->b_crc | status->b_icv);
549 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
550 status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
551 status->b_shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
552 status->b_isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
553 status->b_isfirst_ampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
554 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
555 status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
556 status->macid = GET_RX_DESC_MACID(pdesc);
557 status->b_is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
559 status->b_is_cck = RX_HAL_IS_CCK_RATE(status->rate);
561 if (GET_RX_STATUS_DESC_RPT_SEL(pdesc))
562 status->packet_report_type = C2H_PACKET;
564 status->packet_report_type = NORMAL_RX;
566 if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
567 status->wake_match = BIT(2);
568 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
569 status->wake_match = BIT(1);
570 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
571 status->wake_match = BIT(0);
573 status->wake_match = 0;
575 if (status->wake_match)
576 RT_TRACE(COMP_RXDESC,DBG_LOUD,
577 ("GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",status->wake_match ));
578 rx_status->freq = hw->conf.chandef.chan->center_freq;
579 rx_status->band = hw->conf.chandef.chan->band;
581 hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size
582 + status->rx_bufshift);
585 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
587 if (status->rx_is40Mhzpacket)
588 rx_status->flag |= RX_FLAG_40MHZ;
591 rx_status->flag |= RX_FLAG_HT;
593 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
595 /* hw will set status->decrypted true, if it finds the
596 * frame is open data frame or mgmt frame. */
597 /* So hw will not decryption robust management frame
598 * for IEEE80211w but still set status->decrypted
599 * true, so here we should set it back to undecrypted
600 * for IEEE80211w frame, and mac80211 sw will help
602 if (status->decrypted) {
605 pr_err("decrypted is true but hdr NULL, from skb %p\n",
610 if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
611 (ieee80211_has_protected(hdr->frame_control)))
612 rx_status->flag &= ~RX_FLAG_DECRYPTED;
614 rx_status->flag |= RX_FLAG_DECRYPTED;
617 /* rate_idx: index of data rate into band's
618 * supported rates or MCS index if HT rates
619 * are use (RX_FLAG_HT)*/
620 /* Notice: this is diff with windows define */
621 rx_status->rate_idx = _rtl8821ae_rate_mapping(hw,
622 status->b_is_ht, status->rate);
624 rx_status->mactime = status->timestamp_low;
625 if (phystatus == true) {
626 p_drvinfo = (struct rx_fwinfo_8821ae *)(skb->data +
627 status->rx_bufshift);
629 _rtl8821ae_translate_rx_signal_stuff(hw,
634 /*rx_status->qual = status->signal; */
635 rx_status->signal = status->recvsignalpower + 10;
636 /*rx_status->noise = -status->noise; */
637 if (status->packet_report_type == TX_REPORT2){
638 status->macid_valid_entry[0] = GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
639 status->macid_valid_entry[1] = GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
644 void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
645 struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
646 struct ieee80211_tx_info *info,
647 struct ieee80211_sta *sta,
649 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
651 struct rtl_priv *rtlpriv = rtl_priv(hw);
652 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
653 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
654 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
655 u8 *pdesc = (u8 *) pdesc_tx;
657 u16 fc = le16_to_cpu(hdr->frame_control);
658 unsigned int buf_len = 0;
659 unsigned int skb_len = skb->len;
660 u8 fw_qsel = _rtl8821ae_map_hwqueue_to_fwqueue(skb, hw_queue);
661 bool b_firstseg = ((hdr->seq_ctrl &
662 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
663 bool b_lastseg = ((hdr->frame_control &
664 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
669 if (mac->opmode == NL80211_IFTYPE_STATION) {
671 } else if (mac->opmode == NL80211_IFTYPE_AP ||
672 mac->opmode == NL80211_IFTYPE_ADHOC) {
674 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
676 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
677 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
678 /* reserve 8 byte for AMPDU early mode */
679 if (rtlhal->b_earlymode_enable) {
680 skb_push(skb, EM_HDR_LEN);
681 memset(skb->data, 0, EM_HDR_LEN);
684 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
686 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
687 RT_TRACE(COMP_SEND, DBG_TRACE,
688 ("DMA mapping error"));
691 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8821ae));
692 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
697 if (rtlhal->b_earlymode_enable) {
698 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
699 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN + EM_HDR_LEN);
700 if (ptcb_desc->empkt_num) {
701 RT_TRACE(COMP_SEND, DBG_TRACE,
702 ("Insert 8 byte.pTcb->EMPktNum:%d\n",
703 ptcb_desc->empkt_num));
704 _rtl8821ae_insert_emcontent(ptcb_desc, (u8 *)(skb->data));
707 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
710 /* ptcb_desc->use_driver_rate = true; */
711 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
712 if (ptcb_desc->hw_rate > DESC_RATEMCS0) {
713 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
715 short_gi = (ptcb_desc->use_shortpreamble) ? 1 :0;
717 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
719 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
720 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
721 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
723 SET_TX_DESC_SEQ(pdesc, seq_number);
724 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->b_rts_enable &&
725 !ptcb_desc->b_cts_enable) ? 1 : 0));
726 SET_TX_DESC_HW_RTS_ENABLE(pdesc,0);
727 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->b_cts_enable) ? 1 : 0));
728 /* SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->b_rts_stbc) ? 1 : 0));*/
730 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
731 /* SET_TX_DESC_RTS_BW(pdesc, 0);*/
732 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
733 SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
734 (ptcb_desc->b_rts_use_shortpreamble ? 1 : 0) :
735 (ptcb_desc->b_rts_use_shortgi ? 1 : 0)));
737 if(ptcb_desc->btx_enable_sw_calc_duration)
738 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
741 if (ptcb_desc->b_packet_bw) {
742 SET_TX_DESC_DATA_BW(pdesc, 1);
743 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
745 SET_TX_DESC_DATA_BW(pdesc, 0);
746 SET_TX_DESC_TX_SUB_CARRIER(pdesc, mac->cur_40_prime_sc);
749 SET_TX_DESC_DATA_BW(pdesc, 0);
750 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
753 SET_TX_DESC_LINIP(pdesc, 0);
754 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
756 u8 ampdu_density = sta->ht_cap.ampdu_density;
757 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
759 if (info->control.hw_key) {
760 struct ieee80211_key_conf *keyconf = info->control.hw_key;
761 switch (keyconf->cipher) {
762 case WLAN_CIPHER_SUITE_WEP40:
763 case WLAN_CIPHER_SUITE_WEP104:
764 case WLAN_CIPHER_SUITE_TKIP:
765 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
767 case WLAN_CIPHER_SUITE_CCMP:
768 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
771 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
777 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
778 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
779 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
780 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ? 1 : 0);
781 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
784 SET_TX_DESC_USE_RATE(pdesc, 1);
785 SET_TX_DESC_TX_RATE(pdesc, 0x04);
787 SET_TX_DESC_RETRY_LIMIT_ENABLE(pdesc, 1);
788 SET_TX_DESC_DATA_RETRY_LIMIT(pdesc, 0x3f);
791 /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
792 /* Set TxRate and RTSRate in TxDesc */
793 /* This prevent Tx initial rate of new-coming packets */
794 /* from being overwritten by retried packet rate.*/
795 if (!ptcb_desc->use_driver_rate) {
796 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
797 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
799 if (ieee80211_is_data_qos(fc)) {
801 RT_TRACE(COMP_SEND, DBG_TRACE,
802 ("Enable RDG function.\n"));
803 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
804 SET_TX_DESC_HTC(pdesc, 1);
809 SET_TX_DESC_FIRST_SEG(pdesc, (b_firstseg ? 1 : 0));
810 SET_TX_DESC_LAST_SEG(pdesc, (b_lastseg ? 1 : 0));
811 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
812 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
813 //if (rtlpriv->dm.b_useramask) {
815 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
816 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
818 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
819 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
821 /* if (ieee80211_is_data_qos(fc))
822 SET_TX_DESC_QOS(pdesc, 1);
824 if (!ieee80211_is_data_qos(fc)) {
825 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
826 SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
828 SET_TX_DESC_MORE_FRAG(pdesc, (b_lastseg ? 0 : 1));
829 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
830 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
831 SET_TX_DESC_BMC(pdesc, 1);
834 rtl8821ae_dm_set_tx_ant_by_tx_info(hw,pdesc,ptcb_desc->mac_id);
835 RT_TRACE(COMP_SEND, DBG_TRACE, ("\n"));
838 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
839 u8 *pdesc, bool b_firstseg,
840 bool b_lastseg, struct sk_buff *skb)
842 struct rtl_priv *rtlpriv = rtl_priv(hw);
843 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
844 u8 fw_queue = QSLT_BEACON;
846 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
850 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
851 RT_TRACE(COMP_SEND, DBG_TRACE,
852 ("DMA mapping error"));
855 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
857 SET_TX_DESC_FIRST_SEG(pdesc, 1);
858 SET_TX_DESC_LAST_SEG(pdesc, 1);
860 SET_TX_DESC_PKT_SIZE((u8 *) pdesc, (u16) (skb->len));
862 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
864 SET_TX_DESC_USE_RATE(pdesc, 1);
865 SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
866 SET_TX_DESC_DISABLE_FB(pdesc, 1);
868 SET_TX_DESC_DATA_BW(pdesc, 0);
870 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
872 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
874 if(IsCtrlNDPA(VirtualAddress) || IsMgntNDPA(VirtualAddress))
876 SET_TX_DESC_DATA_RETRY_LIMIT_8812(pDesc, 5);
877 SET_TX_DESC_RETRY_LIMIT_ENABLE_8812(pDesc, 1);
879 if(IsMgntNDPA(VirtualAddress))
881 SET_TX_DESC_NDPA_8812(pDesc, 1);
882 SET_TX_DESC_RTS_SC_8812(pDesc, SCMapping_8812(Adapter, pTcb));
886 SET_TX_DESC_NDPA_8812(pDesc, 2);
887 SET_TX_DESC_RTS_SC_8812(pDesc, SCMapping_8812(Adapter, pTcb));
891 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
893 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
895 SET_TX_DESC_MACID(pdesc, 0);
897 SET_TX_DESC_OWN(pdesc, 1);
899 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
900 "H2C Tx Cmd Content\n",
901 pdesc, TX_DESC_SIZE);
904 void rtl8821ae_set_desc(struct ieee80211_hw * hw, u8 *pdesc, bool istx, u8 desc_name, u8 *val)
909 SET_TX_DESC_OWN(pdesc, 1);
911 case HW_DESC_TX_NEXTDESC_ADDR:
912 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
915 RT_ASSERT(false, ("ERR txdesc :%d"
916 " not process\n", desc_name));
922 SET_RX_DESC_OWN(pdesc, 1);
924 case HW_DESC_RXBUFF_ADDR:
925 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val);
927 case HW_DESC_RXPKT_LEN:
928 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val);
931 SET_RX_DESC_EOR(pdesc, 1);
934 RT_ASSERT(false, ("ERR rxdesc :%d "
935 "not process\n", desc_name));
941 u32 rtl8821ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
948 ret = GET_TX_DESC_OWN(pdesc);
950 case HW_DESC_TXBUFF_ADDR:
951 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
954 RT_ASSERT(false, ("ERR txdesc :%d "
955 "not process\n", desc_name));
961 ret = GET_RX_DESC_OWN(pdesc);
963 case HW_DESC_RXPKT_LEN:
964 ret = GET_RX_DESC_PKT_LEN(pdesc);
967 RT_ASSERT(false, ("ERR rxdesc :%d "
968 "not process\n", desc_name));
975 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw *hw,
976 u8 hw_queue, u16 index)
978 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
979 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
980 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
981 u8 own = (u8) rtl8821ae_get_desc(entry, true, HW_DESC_OWN);
984 *beacon packet will only use the first
985 *descriptor defautly,and the own may not
986 *be cleared by the hardware
995 void rtl8821ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
997 struct rtl_priv *rtlpriv = rtl_priv(hw);
999 if (hw_queue == BEACON_QUEUE) {
1000 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
1002 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
1003 BIT(0) << (hw_queue));