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 static u16 odm_cfo(char value)
57 ret_val = (ret_val << 1) + (ret_val >> 1);
58 /* set bit12 as 1 for negative cfo */
59 ret_val = ret_val | BIT(12);
62 ret_val = (ret_val << 1) + (ret_val >> 1);
67 static void query_rxphystatus(struct ieee80211_hw *hw,
68 struct rtl_stats *pstatus, u8 *pdesc,
69 struct rx_fwinfo_8821ae *p_drvinfo,
70 bool bpacket_match_bssid,
71 bool bpacket_toself, bool packet_beacon)
73 struct rtl_priv *rtlpriv = rtl_priv(hw);
74 struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
75 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
76 struct rtl_phy *rtlphy = &rtlpriv->phy;
77 char rx_pwr_all = 0, rx_pwr[4];
78 u8 rf_rx_num = 0, evm, evmdbm, pwdb_all;
79 u8 i, max_spatial_stream;
80 u32 rssi, total_rssi = 0;
81 bool is_cck = pstatus->is_cck;
84 /* Record it for next packet processing */
85 pstatus->packet_matchbssid = bpacket_match_bssid;
86 pstatus->packet_toself = bpacket_toself;
87 pstatus->packet_beacon = packet_beacon;
88 pstatus->rx_mimo_signalquality[0] = -1;
89 pstatus->rx_mimo_signalquality[1] = -1;
95 cck_agc_rpt = p_phystrpt->cfosho[0];
97 /* (1)Hardware does not provide RSSI for CCK
98 * (2)PWDB, Average PWDB cacluated by
99 * hardware (for rate adaptive)
101 cck_highpwr = (u8)rtlphy->cck_high_power;
103 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
104 vga_idx = (cck_agc_rpt & 0x1f);
105 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE) {
110 rx_pwr_all = -100 + 2*(27-vga_idx);
116 rx_pwr_all = -48 + 2*(2-vga_idx);
120 rx_pwr_all = -42 + 2*(7-vga_idx);
124 rx_pwr_all = -36 + 2*(7-vga_idx);
128 rx_pwr_all = -24 + 2*(7-vga_idx);
133 rx_pwr_all = -12 + 2*(5-vga_idx);
135 rx_pwr_all = -6 + 2*(5-vga_idx);
138 rx_pwr_all = 8-2*vga_idx;
141 rx_pwr_all = 14-2*vga_idx;
147 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
151 ((pwdb_all - 80)<<1) +
152 ((pwdb_all - 80)>>1) + 80;
153 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
163 rx_pwr_all = pout - 32 - (2*vga_idx);
166 rx_pwr_all = pout - 24 - (2*vga_idx);
169 rx_pwr_all = pout - 11 - (2*vga_idx);
172 rx_pwr_all = pout + 5 - (2*vga_idx);
175 rx_pwr_all = pout + 21 - (2*vga_idx);
178 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
181 pstatus->rx_pwdb_all = pwdb_all;
182 pstatus->recvsignalpower = rx_pwr_all;
184 /* (3) Get Signal Quality (EVM) */
185 if (bpacket_match_bssid) {
188 if (pstatus->rx_pwdb_all > 40) {
191 sq = p_phystrpt->pwdb_all;
197 sq = ((64 - sq) * 100) / 44;
200 pstatus->signalquality = sq;
201 pstatus->rx_mimo_signalquality[0] = sq;
202 pstatus->rx_mimo_signalquality[1] = -1;
205 /* (1)Get RSSI for HT rate */
206 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
207 /* we will judge RF RX path now. */
208 if (rtlpriv->dm.rfpath_rxenable[i])
211 rx_pwr[i] = (p_phystrpt->gain_trsw[i] & 0x7f) - 110;
213 /* Translate DBM to percentage. */
214 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
217 /* Get Rx snr value in DB */
218 pstatus->rx_snr[i] = p_phystrpt->rxsnr[i] / 2;
219 rtlpriv->stats.rx_snr_db[i] = p_phystrpt->rxsnr[i] / 2;
221 pstatus->cfo_short[i] = odm_cfo(p_phystrpt->cfosho[i]);
222 pstatus->cfo_tail[i] = odm_cfo(p_phystrpt->cfotail[i]);
223 /* Record Signal Strength for next packet */
224 pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
227 /* (2)PWDB, Average PWDB cacluated by
228 * hardware (for rate adaptive)
230 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
232 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
233 pstatus->rx_pwdb_all = pwdb_all;
234 pstatus->rxpower = rx_pwr_all;
235 pstatus->recvsignalpower = rx_pwr_all;
237 /* (3)EVM of HT rate */
238 if ((pstatus->is_ht && pstatus->rate >= DESC_RATEMCS8 &&
239 pstatus->rate <= DESC_RATEMCS15) ||
241 pstatus->rate >= DESC_RATEVHT2SS_MCS0 &&
242 pstatus->rate <= DESC_RATEVHT2SS_MCS9))
243 max_spatial_stream = 2;
245 max_spatial_stream = 1;
247 for (i = 0; i < max_spatial_stream; i++) {
248 evm = rtl_evm_db_to_percentage(p_phystrpt->rxevm[i]);
249 evmdbm = rtl_evm_dbm_jaguar(p_phystrpt->rxevm[i]);
251 if (bpacket_match_bssid) {
252 /* Fill value in RFD, Get the first
253 * spatial stream only
256 pstatus->signalquality = evm;
257 pstatus->rx_mimo_signalquality[i] = evm;
258 pstatus->rx_mimo_evm_dbm[i] = evmdbm;
261 if (bpacket_match_bssid) {
262 for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
263 rtl_priv(hw)->dm.cfo_tail[i] =
264 (char)p_phystrpt->cfotail[i];
266 rtl_priv(hw)->dm.packet_count++;
270 /* UI BSS List signal strength(in percentage),
271 * make it good looking, from 0~100.
274 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
276 else if (rf_rx_num != 0)
277 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
278 total_rssi /= rf_rx_num));
279 /*HW antenna diversity*/
280 rtldm->fat_table.antsel_rx_keep_0 = p_phystrpt->antidx_anta;
281 rtldm->fat_table.antsel_rx_keep_1 = p_phystrpt->antidx_antb;
284 static void translate_rx_signal_stuff(struct ieee80211_hw *hw,
286 struct rtl_stats *pstatus, u8 *pdesc,
287 struct rx_fwinfo_8821ae *p_drvinfo)
289 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
290 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
291 struct ieee80211_hdr *hdr;
297 bool packet_matchbssid, packet_toself, packet_beacon;
299 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
301 hdr = (struct ieee80211_hdr *)tmp_buf;
302 fc = hdr->frame_control;
303 type = WLAN_FC_GET_TYPE(hdr->frame_control);
305 psaddr = ieee80211_get_SA(hdr);
306 ether_addr_copy(pstatus->psaddr, psaddr);
308 packet_matchbssid = (!ieee80211_is_ctl(fc) &&
309 (ether_addr_equal(mac->bssid,
310 ieee80211_has_tods(fc) ?
312 ieee80211_has_fromds(fc) ?
313 hdr->addr2 : hdr->addr3)) &&
314 (!pstatus->hwerror) &&
315 (!pstatus->crc) && (!pstatus->icv));
317 packet_toself = packet_matchbssid &&
318 (ether_addr_equal(praddr, rtlefuse->dev_addr));
320 if (ieee80211_is_beacon(hdr->frame_control))
321 packet_beacon = true;
323 packet_beacon = false;
325 if (packet_beacon && packet_matchbssid)
326 rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
328 if (packet_matchbssid &&
329 ieee80211_is_data_qos(hdr->frame_control) &&
330 !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
331 struct ieee80211_qos_hdr *hdr_qos =
332 (struct ieee80211_qos_hdr *)tmp_buf;
333 u16 tid = le16_to_cpu(hdr_qos->qos_ctrl) & 0xf;
335 if (tid != 0 && tid != 3)
336 rtl_priv(hw)->dm.dbginfo.num_non_be_pkt++;
339 query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
340 packet_matchbssid, packet_toself,
342 /*_rtl8821ae_smart_antenna(hw, pstatus); */
343 rtl_process_phyinfo(hw, tmp_buf, pstatus);
346 static void _rtl8821ae_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
351 memset(virtualaddress, 0, 8);
353 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
354 if (ptcb_desc->empkt_num == 1) {
355 dwtmp = ptcb_desc->empkt_len[0];
357 dwtmp = ptcb_desc->empkt_len[0];
358 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
359 dwtmp += ptcb_desc->empkt_len[1];
361 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
363 if (ptcb_desc->empkt_num <= 3) {
364 dwtmp = ptcb_desc->empkt_len[2];
366 dwtmp = ptcb_desc->empkt_len[2];
367 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
368 dwtmp += ptcb_desc->empkt_len[3];
370 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
371 if (ptcb_desc->empkt_num <= 5) {
372 dwtmp = ptcb_desc->empkt_len[4];
374 dwtmp = ptcb_desc->empkt_len[4];
375 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
376 dwtmp += ptcb_desc->empkt_len[5];
378 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
379 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
380 if (ptcb_desc->empkt_num <= 7) {
381 dwtmp = ptcb_desc->empkt_len[6];
383 dwtmp = ptcb_desc->empkt_len[6];
384 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
385 dwtmp += ptcb_desc->empkt_len[7];
387 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
388 if (ptcb_desc->empkt_num <= 9) {
389 dwtmp = ptcb_desc->empkt_len[8];
391 dwtmp = ptcb_desc->empkt_len[8];
392 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0)+4;
393 dwtmp += ptcb_desc->empkt_len[9];
395 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
398 static bool rtl8821ae_get_rxdesc_is_ht(struct ieee80211_hw *hw, u8 *pdesc)
400 struct rtl_priv *rtlpriv = rtl_priv(hw);
403 rx_rate = GET_RX_DESC_RXMCS(pdesc);
405 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
407 if ((rx_rate >= DESC_RATEMCS0) && (rx_rate <= DESC_RATEMCS15))
412 static bool rtl8821ae_get_rxdesc_is_vht(struct ieee80211_hw *hw, u8 *pdesc)
414 struct rtl_priv *rtlpriv = rtl_priv(hw);
417 rx_rate = GET_RX_DESC_RXMCS(pdesc);
419 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, "rx_rate=0x%02x.\n", rx_rate);
421 if (rx_rate >= DESC_RATEVHT1SS_MCS0)
426 static u8 rtl8821ae_get_rx_vht_nss(struct ieee80211_hw *hw, u8 *pdesc)
431 rx_rate = GET_RX_DESC_RXMCS(pdesc);
432 if ((rx_rate >= DESC_RATEVHT1SS_MCS0) &&
433 (rx_rate <= DESC_RATEVHT1SS_MCS9))
435 else if ((rx_rate >= DESC_RATEVHT2SS_MCS0) &&
436 (rx_rate <= DESC_RATEVHT2SS_MCS9))
442 bool rtl8821ae_rx_query_desc(struct ieee80211_hw *hw,
443 struct rtl_stats *status,
444 struct ieee80211_rx_status *rx_status,
445 u8 *pdesc, struct sk_buff *skb)
447 struct rtl_priv *rtlpriv = rtl_priv(hw);
448 struct rx_fwinfo_8821ae *p_drvinfo;
449 struct ieee80211_hdr *hdr;
451 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
453 status->length = (u16)GET_RX_DESC_PKT_LEN(pdesc);
454 status->rx_drvinfo_size = (u8)GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
455 RX_DRV_INFO_SIZE_UNIT;
456 status->rx_bufshift = (u8)(GET_RX_DESC_SHIFT(pdesc) & 0x03);
457 status->icv = (u16)GET_RX_DESC_ICV(pdesc);
458 status->crc = (u16)GET_RX_DESC_CRC32(pdesc);
459 status->hwerror = (status->crc | status->icv);
460 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
461 status->rate = (u8)GET_RX_DESC_RXMCS(pdesc);
462 status->shortpreamble = (u16)GET_RX_DESC_SPLCP(pdesc);
463 status->isampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
464 status->isfirst_ampdu = (bool)(GET_RX_DESC_PAGGR(pdesc) == 1);
465 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
466 status->rx_packet_bw = GET_RX_DESC_BW(pdesc);
467 status->macid = GET_RX_DESC_MACID(pdesc);
468 status->is_short_gi = !(bool)GET_RX_DESC_SPLCP(pdesc);
469 status->is_ht = rtl8821ae_get_rxdesc_is_ht(hw, pdesc);
470 status->is_vht = rtl8821ae_get_rxdesc_is_vht(hw, pdesc);
471 status->vht_nss = rtl8821ae_get_rx_vht_nss(hw, pdesc);
472 status->is_cck = RTL8821AE_RX_HAL_IS_CCK_RATE(status->rate);
474 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
475 "rx_packet_bw=%s,is_ht %d, is_vht %d, vht_nss=%d,is_short_gi %d.\n",
476 (status->rx_packet_bw == 2) ? "80M" :
477 (status->rx_packet_bw == 1) ? "40M" : "20M",
478 status->is_ht, status->is_vht, status->vht_nss,
479 status->is_short_gi);
481 if (GET_RX_STATUS_DESC_RPT_SEL(pdesc))
482 status->packet_report_type = C2H_PACKET;
484 status->packet_report_type = NORMAL_RX;
486 if (GET_RX_STATUS_DESC_PATTERN_MATCH(pdesc))
487 status->wake_match = BIT(2);
488 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
489 status->wake_match = BIT(1);
490 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
491 status->wake_match = BIT(0);
493 status->wake_match = 0;
495 if (status->wake_match)
496 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
497 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
499 rx_status->freq = hw->conf.chandef.chan->center_freq;
500 rx_status->band = hw->conf.chandef.chan->band;
502 hdr = (struct ieee80211_hdr *)(skb->data +
503 status->rx_drvinfo_size + status->rx_bufshift);
506 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
508 if (status->rx_packet_bw == HT_CHANNEL_WIDTH_20_40)
509 rx_status->flag |= RX_FLAG_40MHZ;
510 else if (status->rx_packet_bw == HT_CHANNEL_WIDTH_80)
511 rx_status->vht_flag |= RX_VHT_FLAG_80MHZ;
513 rx_status->flag |= RX_FLAG_HT;
515 rx_status->flag |= RX_FLAG_VHT;
517 if (status->is_short_gi)
518 rx_status->flag |= RX_FLAG_SHORT_GI;
520 rx_status->vht_nss = status->vht_nss;
521 rx_status->flag |= RX_FLAG_MACTIME_START;
523 /* hw will set status->decrypted true, if it finds the
524 * frame is open data frame or mgmt frame.
525 * So hw will not decryption robust managment frame
526 * for IEEE80211w but still set status->decrypted
527 * true, so here we should set it back to undecrypted
528 * for IEEE80211w frame, and mac80211 sw will help
531 if (status->decrypted) {
532 if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
533 (ieee80211_has_protected(hdr->frame_control)))
534 rx_status->flag |= RX_FLAG_DECRYPTED;
536 rx_status->flag &= ~RX_FLAG_DECRYPTED;
539 /* rate_idx: index of data rate into band's
540 * supported rates or MCS index if HT rates
541 * are use (RX_FLAG_HT)
543 rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
547 rx_status->mactime = status->timestamp_low;
549 p_drvinfo = (struct rx_fwinfo_8821ae *)(skb->data +
550 status->rx_bufshift);
552 translate_rx_signal_stuff(hw, skb, status, pdesc, p_drvinfo);
554 rx_status->signal = status->recvsignalpower + 10;
555 if (status->packet_report_type == TX_REPORT2) {
556 status->macid_valid_entry[0] =
557 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
558 status->macid_valid_entry[1] =
559 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
564 static u8 rtl8821ae_bw_mapping(struct ieee80211_hw *hw,
565 struct rtl_tcb_desc *ptcb_desc)
567 struct rtl_priv *rtlpriv = rtl_priv(hw);
568 struct rtl_phy *rtlphy = &rtlpriv->phy;
569 u8 bw_setting_of_desc = 0;
571 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
572 "rtl8821ae_bw_mapping, current_chan_bw %d, packet_bw %d\n",
573 rtlphy->current_chan_bw, ptcb_desc->packet_bw);
575 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
576 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80)
577 bw_setting_of_desc = 2;
578 else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40)
579 bw_setting_of_desc = 1;
581 bw_setting_of_desc = 0;
582 } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
583 if ((ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) ||
584 (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80))
585 bw_setting_of_desc = 1;
587 bw_setting_of_desc = 0;
589 bw_setting_of_desc = 0;
591 return bw_setting_of_desc;
594 static u8 rtl8821ae_sc_mapping(struct ieee80211_hw *hw,
595 struct rtl_tcb_desc *ptcb_desc)
597 struct rtl_priv *rtlpriv = rtl_priv(hw);
598 struct rtl_phy *rtlphy = &rtlpriv->phy;
599 struct rtl_mac *mac = rtl_mac(rtlpriv);
600 u8 sc_setting_of_desc = 0;
602 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) {
603 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_80) {
604 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
605 } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
606 if (mac->cur_80_prime_sc ==
607 HAL_PRIME_CHNL_OFFSET_LOWER)
609 VHT_DATA_SC_40_LOWER_OF_80MHZ;
610 else if (mac->cur_80_prime_sc ==
611 HAL_PRIME_CHNL_OFFSET_UPPER)
613 VHT_DATA_SC_40_UPPER_OF_80MHZ;
615 RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
616 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
618 if ((mac->cur_40_prime_sc ==
619 HAL_PRIME_CHNL_OFFSET_LOWER) &&
620 (mac->cur_80_prime_sc ==
621 HAL_PRIME_CHNL_OFFSET_LOWER))
623 VHT_DATA_SC_20_LOWEST_OF_80MHZ;
624 else if ((mac->cur_40_prime_sc ==
625 HAL_PRIME_CHNL_OFFSET_UPPER) &&
626 (mac->cur_80_prime_sc ==
627 HAL_PRIME_CHNL_OFFSET_LOWER))
629 VHT_DATA_SC_20_LOWER_OF_80MHZ;
630 else if ((mac->cur_40_prime_sc ==
631 HAL_PRIME_CHNL_OFFSET_LOWER) &&
632 (mac->cur_80_prime_sc ==
633 HAL_PRIME_CHNL_OFFSET_UPPER))
635 VHT_DATA_SC_20_UPPER_OF_80MHZ;
636 else if ((mac->cur_40_prime_sc ==
637 HAL_PRIME_CHNL_OFFSET_UPPER) &&
638 (mac->cur_80_prime_sc ==
639 HAL_PRIME_CHNL_OFFSET_UPPER))
641 VHT_DATA_SC_20_UPPERST_OF_80MHZ;
643 RT_TRACE(rtlpriv, COMP_SEND, DBG_LOUD,
644 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
646 } else if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20_40) {
647 if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
648 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
649 } else if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20) {
650 if (mac->cur_40_prime_sc ==
651 HAL_PRIME_CHNL_OFFSET_UPPER) {
653 VHT_DATA_SC_20_UPPER_OF_80MHZ;
654 } else if (mac->cur_40_prime_sc ==
655 HAL_PRIME_CHNL_OFFSET_LOWER){
657 VHT_DATA_SC_20_LOWER_OF_80MHZ;
659 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
663 sc_setting_of_desc = VHT_DATA_SC_DONOT_CARE;
666 return sc_setting_of_desc;
669 void rtl8821ae_tx_fill_desc(struct ieee80211_hw *hw,
670 struct ieee80211_hdr *hdr, u8 *pdesc_tx, u8 *txbd,
671 struct ieee80211_tx_info *info,
672 struct ieee80211_sta *sta,
674 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
676 struct rtl_priv *rtlpriv = rtl_priv(hw);
677 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
678 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
679 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
680 u8 *pdesc = (u8 *)pdesc_tx;
682 __le16 fc = 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 firstseg = ((hdr->seq_ctrl &
687 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
688 bool lastseg = ((hdr->frame_control &
689 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
693 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
694 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
695 /* reserve 8 byte for AMPDU early mode */
696 if (rtlhal->earlymode_enable) {
697 skb_push(skb, EM_HDR_LEN);
698 memset(skb->data, 0, EM_HDR_LEN);
701 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
703 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
704 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
705 "DMA mapping error");
708 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8821ae));
709 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
714 if (rtlhal->earlymode_enable) {
715 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
716 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
718 if (ptcb_desc->empkt_num) {
719 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
720 "Insert 8 byte.pTcb->EMPktNum:%d\n",
721 ptcb_desc->empkt_num);
722 _rtl8821ae_insert_emcontent(ptcb_desc,
726 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
729 /* ptcb_desc->use_driver_rate = true; */
730 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
731 if (ptcb_desc->hw_rate > DESC_RATEMCS0)
732 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
734 short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
736 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
738 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
739 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
740 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x1f);
742 SET_TX_DESC_SEQ(pdesc, seq_number);
743 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
744 !ptcb_desc->cts_enable) ? 1 : 0));
745 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
746 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0));
748 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
749 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
750 SET_TX_DESC_RTS_SHORT(pdesc,
751 ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
752 (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
753 (ptcb_desc->rts_use_shortgi ? 1 : 0)));
755 if (ptcb_desc->tx_enable_sw_calc_duration)
756 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
758 SET_TX_DESC_DATA_BW(pdesc,
759 rtl8821ae_bw_mapping(hw, ptcb_desc));
761 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
762 rtl8821ae_sc_mapping(hw, ptcb_desc));
764 SET_TX_DESC_LINIP(pdesc, 0);
765 SET_TX_DESC_PKT_SIZE(pdesc, (u16)skb_len);
767 u8 ampdu_density = sta->ht_cap.ampdu_density;
769 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
771 if (info->control.hw_key) {
772 struct ieee80211_key_conf *keyconf =
773 info->control.hw_key;
774 switch (keyconf->cipher) {
775 case WLAN_CIPHER_SUITE_WEP40:
776 case WLAN_CIPHER_SUITE_WEP104:
777 case WLAN_CIPHER_SUITE_TKIP:
778 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
780 case WLAN_CIPHER_SUITE_CCMP:
781 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
784 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
789 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
790 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
791 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
792 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
794 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
796 if (ieee80211_is_data_qos(fc)) {
798 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
799 "Enable RDG function.\n");
800 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
801 SET_TX_DESC_HTC(pdesc, 1);
806 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
807 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
808 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)buf_len);
809 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
810 /* if (rtlpriv->dm.useramask) { */
812 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
813 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
815 SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index);
816 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
818 if (!ieee80211_is_data_qos(fc)) {
819 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
820 SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
822 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
823 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
824 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
825 SET_TX_DESC_BMC(pdesc, 1);
828 rtl8821ae_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id);
829 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
832 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw *hw,
833 u8 *pdesc, bool firstseg,
834 bool lastseg, struct sk_buff *skb)
836 struct rtl_priv *rtlpriv = rtl_priv(hw);
837 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
838 u8 fw_queue = QSLT_BEACON;
840 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
844 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
845 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
846 "DMA mapping error");
849 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
851 SET_TX_DESC_FIRST_SEG(pdesc, 1);
852 SET_TX_DESC_LAST_SEG(pdesc, 1);
854 SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len));
856 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
858 SET_TX_DESC_USE_RATE(pdesc, 1);
859 SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
860 SET_TX_DESC_DISABLE_FB(pdesc, 1);
862 SET_TX_DESC_DATA_BW(pdesc, 0);
864 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
866 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
868 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
870 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
872 SET_TX_DESC_MACID(pdesc, 0);
874 SET_TX_DESC_OWN(pdesc, 1);
876 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
877 "H2C Tx Cmd Content\n",
878 pdesc, TX_DESC_SIZE);
881 void rtl8821ae_set_desc(struct ieee80211_hw *hw, u8 *pdesc,
882 bool istx, u8 desc_name, u8 *val)
887 SET_TX_DESC_OWN(pdesc, 1);
889 case HW_DESC_TX_NEXTDESC_ADDR:
890 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
894 "ERR txdesc :%d not process\n", desc_name);
900 SET_RX_DESC_OWN(pdesc, 1);
902 case HW_DESC_RXBUFF_ADDR:
903 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
905 case HW_DESC_RXPKT_LEN:
906 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
909 SET_RX_DESC_EOR(pdesc, 1);
913 "ERR rxdesc :%d not process\n", desc_name);
919 u32 rtl8821ae_get_desc(u8 *pdesc, bool istx, u8 desc_name)
926 ret = GET_TX_DESC_OWN(pdesc);
928 case HW_DESC_TXBUFF_ADDR:
929 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
933 "ERR txdesc :%d not process\n", desc_name);
939 ret = GET_RX_DESC_OWN(pdesc);
941 case HW_DESC_RXPKT_LEN:
942 ret = GET_RX_DESC_PKT_LEN(pdesc);
944 case HW_DESC_RXBUFF_ADDR:
945 ret = GET_RX_DESC_BUFF_ADDR(pdesc);
949 "ERR rxdesc :%d not process\n", desc_name);
956 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw *hw,
957 u8 hw_queue, u16 index)
959 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
960 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
961 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
962 u8 own = (u8)rtl8821ae_get_desc(entry, true, HW_DESC_OWN);
965 *beacon packet will only use the first
966 *descriptor defautly,and the own may not
967 *be cleared by the hardware
974 void rtl8821ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
976 struct rtl_priv *rtlpriv = rtl_priv(hw);
978 if (hw_queue == BEACON_QUEUE) {
979 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
981 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
982 BIT(0) << (hw_queue));
986 u32 rtl8821ae_rx_command_packet(struct ieee80211_hw *hw,
987 struct rtl_stats status,
991 struct rtl_priv *rtlpriv = rtl_priv(hw);
993 switch (status.packet_report_type) {
998 rtl8821ae_c2h_packet_handler(hw, skb->data, (u8)skb->len);
1000 RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
1001 "skb->len=%d\n\n", skb->len);
1004 RT_TRACE(rtlpriv, COMP_RECV, DBG_LOUD,
1005 "No this packet type!!\n");