1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2010 Realtek Corporation.*/
16 static u8
_rtl8821ae_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
18 __le16 fc
= rtl_get_fc(skb
);
20 if (unlikely(ieee80211_is_beacon(fc
)))
22 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
28 static u16
odm_cfo(s8 value
)
34 ret_val
= (ret_val
<< 1) + (ret_val
>> 1);
35 /* set bit12 as 1 for negative cfo */
36 ret_val
= ret_val
| BIT(12);
39 ret_val
= (ret_val
<< 1) + (ret_val
>> 1);
44 static u8
_rtl8821ae_evm_dbm_jaguar(s8 value
)
48 /* -33dB~0dB to 33dB ~ 0dB*/
52 ret_val
= 0 - ret_val
;
54 ret_val
= ret_val
>> 1;
58 static void query_rxphystatus(struct ieee80211_hw
*hw
,
59 struct rtl_stats
*pstatus
, __le32
*pdesc
,
60 struct rx_fwinfo_8821ae
*p_drvinfo
,
61 bool bpacket_match_bssid
,
62 bool bpacket_toself
, bool packet_beacon
)
64 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
65 struct phy_status_rpt
*p_phystrpt
= (struct phy_status_rpt
*)p_drvinfo
;
66 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
67 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
68 s8 rx_pwr_all
= 0, rx_pwr
[4];
69 u8 rf_rx_num
= 0, evm
, evmdbm
, pwdb_all
;
70 u8 i
, max_spatial_stream
;
71 u32 rssi
, total_rssi
= 0;
72 bool is_cck
= pstatus
->is_cck
;
75 /* Record it for next packet processing */
76 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
77 pstatus
->packet_toself
= bpacket_toself
;
78 pstatus
->packet_beacon
= packet_beacon
;
79 pstatus
->rx_mimo_signalquality
[0] = -1;
80 pstatus
->rx_mimo_signalquality
[1] = -1;
86 cck_agc_rpt
= p_phystrpt
->cfosho
[0];
88 /* (1)Hardware does not provide RSSI for CCK
89 * (2)PWDB, Average PWDB cacluated by
90 * hardware (for rate adaptive)
92 cck_highpwr
= (u8
)rtlphy
->cck_high_power
;
94 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
95 vga_idx
= (cck_agc_rpt
& 0x1f);
96 if (rtlpriv
->rtlhal
.hw_type
== HARDWARE_TYPE_RTL8812AE
) {
101 rx_pwr_all
= -100 + 2*(27-vga_idx
);
107 rx_pwr_all
= -48 + 2*(2-vga_idx
);
111 rx_pwr_all
= -42 + 2*(7-vga_idx
);
115 rx_pwr_all
= -36 + 2*(7-vga_idx
);
119 rx_pwr_all
= -24 + 2*(7-vga_idx
);
124 rx_pwr_all
= -12 + 2*(5-vga_idx
);
126 rx_pwr_all
= -6 + 2*(5-vga_idx
);
129 rx_pwr_all
= 8-2*vga_idx
;
132 rx_pwr_all
= 14-2*vga_idx
;
138 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
142 ((pwdb_all
- 80)<<1) +
143 ((pwdb_all
- 80)>>1) + 80;
144 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
154 rx_pwr_all
= pout
- 32 - (2*vga_idx
);
157 rx_pwr_all
= pout
- 24 - (2*vga_idx
);
160 rx_pwr_all
= pout
- 11 - (2*vga_idx
);
163 rx_pwr_all
= pout
+ 5 - (2*vga_idx
);
166 rx_pwr_all
= pout
+ 21 - (2*vga_idx
);
169 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
172 pstatus
->rx_pwdb_all
= pwdb_all
;
173 pstatus
->recvsignalpower
= rx_pwr_all
;
175 /* (3) Get Signal Quality (EVM) */
176 if (bpacket_match_bssid
) {
179 if (pstatus
->rx_pwdb_all
> 40) {
182 sq
= p_phystrpt
->pwdb_all
;
188 sq
= ((64 - sq
) * 100) / 44;
191 pstatus
->signalquality
= sq
;
192 pstatus
->rx_mimo_signalquality
[0] = sq
;
193 pstatus
->rx_mimo_signalquality
[1] = -1;
196 /* (1)Get RSSI for HT rate */
197 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
198 /* we will judge RF RX path now. */
199 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
202 rx_pwr
[i
] = (p_phystrpt
->gain_trsw
[i
] & 0x7f) - 110;
204 /* Translate DBM to percentage. */
205 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
208 /* Get Rx snr value in DB */
209 pstatus
->rx_snr
[i
] = p_phystrpt
->rxsnr
[i
] / 2;
210 rtlpriv
->stats
.rx_snr_db
[i
] = p_phystrpt
->rxsnr
[i
] / 2;
212 pstatus
->cfo_short
[i
] = odm_cfo(p_phystrpt
->cfosho
[i
]);
213 pstatus
->cfo_tail
[i
] = odm_cfo(p_phystrpt
->cfotail
[i
]);
214 /* Record Signal Strength for next packet */
215 pstatus
->rx_mimo_signalstrength
[i
] = (u8
)rssi
;
218 /* (2)PWDB, Average PWDB cacluated by
219 * hardware (for rate adaptive)
221 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
223 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
224 pstatus
->rx_pwdb_all
= pwdb_all
;
225 pstatus
->rxpower
= rx_pwr_all
;
226 pstatus
->recvsignalpower
= rx_pwr_all
;
228 /* (3)EVM of HT rate */
229 if ((pstatus
->is_ht
&& pstatus
->rate
>= DESC_RATEMCS8
&&
230 pstatus
->rate
<= DESC_RATEMCS15
) ||
232 pstatus
->rate
>= DESC_RATEVHT2SS_MCS0
&&
233 pstatus
->rate
<= DESC_RATEVHT2SS_MCS9
))
234 max_spatial_stream
= 2;
236 max_spatial_stream
= 1;
238 for (i
= 0; i
< max_spatial_stream
; i
++) {
239 evm
= rtl_evm_db_to_percentage(p_phystrpt
->rxevm
[i
]);
240 evmdbm
= _rtl8821ae_evm_dbm_jaguar(p_phystrpt
->rxevm
[i
]);
242 if (bpacket_match_bssid
) {
243 /* Fill value in RFD, Get the first
244 * spatial stream only
247 pstatus
->signalquality
= evm
;
248 pstatus
->rx_mimo_signalquality
[i
] = evm
;
249 pstatus
->rx_mimo_evm_dbm
[i
] = evmdbm
;
252 if (bpacket_match_bssid
) {
253 for (i
= RF90_PATH_A
; i
<= RF90_PATH_B
; i
++)
254 rtl_priv(hw
)->dm
.cfo_tail
[i
] =
255 (s8
)p_phystrpt
->cfotail
[i
];
257 rtl_priv(hw
)->dm
.packet_count
++;
261 /* UI BSS List signal strength(in percentage),
262 * make it good looking, from 0~100.
265 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
267 else if (rf_rx_num
!= 0)
268 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
269 total_rssi
/= rf_rx_num
));
270 /*HW antenna diversity*/
271 rtldm
->fat_table
.antsel_rx_keep_0
= p_phystrpt
->antidx_anta
;
272 rtldm
->fat_table
.antsel_rx_keep_1
= p_phystrpt
->antidx_antb
;
275 static void translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
277 struct rtl_stats
*pstatus
, __le32
*pdesc
,
278 struct rx_fwinfo_8821ae
*p_drvinfo
)
280 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
281 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
282 struct ieee80211_hdr
*hdr
;
287 bool packet_matchbssid
, packet_toself
, packet_beacon
;
289 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
291 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
292 fc
= hdr
->frame_control
;
294 psaddr
= ieee80211_get_SA(hdr
);
295 ether_addr_copy(pstatus
->psaddr
, psaddr
);
297 packet_matchbssid
= (!ieee80211_is_ctl(fc
) &&
298 (ether_addr_equal(mac
->bssid
,
299 ieee80211_has_tods(fc
) ?
301 ieee80211_has_fromds(fc
) ?
302 hdr
->addr2
: hdr
->addr3
)) &&
303 (!pstatus
->hwerror
) &&
304 (!pstatus
->crc
) && (!pstatus
->icv
));
306 packet_toself
= packet_matchbssid
&&
307 (ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
309 if (ieee80211_is_beacon(hdr
->frame_control
))
310 packet_beacon
= true;
312 packet_beacon
= false;
314 if (packet_beacon
&& packet_matchbssid
)
315 rtl_priv(hw
)->dm
.dbginfo
.num_qry_beacon_pkt
++;
317 if (packet_matchbssid
&&
318 ieee80211_is_data_qos(hdr
->frame_control
) &&
319 !is_multicast_ether_addr(ieee80211_get_DA(hdr
))) {
320 struct ieee80211_qos_hdr
*hdr_qos
=
321 (struct ieee80211_qos_hdr
*)tmp_buf
;
322 u16 tid
= le16_to_cpu(hdr_qos
->qos_ctrl
) & 0xf;
324 if (tid
!= 0 && tid
!= 3)
325 rtl_priv(hw
)->dm
.dbginfo
.num_non_be_pkt
++;
328 query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
329 packet_matchbssid
, packet_toself
,
331 /*_rtl8821ae_smart_antenna(hw, pstatus); */
332 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
335 static void rtl8821ae_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
336 __le32
*virtualaddress
)
340 memset(virtualaddress
, 0, 8);
342 set_earlymode_pktnum(virtualaddress
, ptcb_desc
->empkt_num
);
343 if (ptcb_desc
->empkt_num
== 1) {
344 dwtmp
= ptcb_desc
->empkt_len
[0];
346 dwtmp
= ptcb_desc
->empkt_len
[0];
347 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0)+4;
348 dwtmp
+= ptcb_desc
->empkt_len
[1];
350 set_earlymode_len0(virtualaddress
, dwtmp
);
352 if (ptcb_desc
->empkt_num
<= 3) {
353 dwtmp
= ptcb_desc
->empkt_len
[2];
355 dwtmp
= ptcb_desc
->empkt_len
[2];
356 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0)+4;
357 dwtmp
+= ptcb_desc
->empkt_len
[3];
359 set_earlymode_len1(virtualaddress
, dwtmp
);
360 if (ptcb_desc
->empkt_num
<= 5) {
361 dwtmp
= ptcb_desc
->empkt_len
[4];
363 dwtmp
= ptcb_desc
->empkt_len
[4];
364 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0)+4;
365 dwtmp
+= ptcb_desc
->empkt_len
[5];
367 set_earlymode_len2_1(virtualaddress
, dwtmp
& 0xF);
368 set_earlymode_len2_2(virtualaddress
, dwtmp
>> 4);
369 if (ptcb_desc
->empkt_num
<= 7) {
370 dwtmp
= ptcb_desc
->empkt_len
[6];
372 dwtmp
= ptcb_desc
->empkt_len
[6];
373 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0)+4;
374 dwtmp
+= ptcb_desc
->empkt_len
[7];
376 set_earlymode_len3(virtualaddress
, dwtmp
);
377 if (ptcb_desc
->empkt_num
<= 9) {
378 dwtmp
= ptcb_desc
->empkt_len
[8];
380 dwtmp
= ptcb_desc
->empkt_len
[8];
381 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0)+4;
382 dwtmp
+= ptcb_desc
->empkt_len
[9];
384 set_earlymode_len4(virtualaddress
, dwtmp
);
387 static bool rtl8821ae_get_rxdesc_is_ht(struct ieee80211_hw
*hw
, __le32
*pdesc
)
389 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
392 rx_rate
= get_rx_desc_rxmcs(pdesc
);
394 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
, "rx_rate=0x%02x.\n", rx_rate
);
396 if ((rx_rate
>= DESC_RATEMCS0
) && (rx_rate
<= DESC_RATEMCS15
))
401 static bool rtl8821ae_get_rxdesc_is_vht(struct ieee80211_hw
*hw
, __le32
*pdesc
)
403 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
406 rx_rate
= get_rx_desc_rxmcs(pdesc
);
408 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
, "rx_rate=0x%02x.\n", rx_rate
);
410 if (rx_rate
>= DESC_RATEVHT1SS_MCS0
)
415 static u8
rtl8821ae_get_rx_vht_nss(struct ieee80211_hw
*hw
, __le32
*pdesc
)
420 rx_rate
= get_rx_desc_rxmcs(pdesc
);
421 if ((rx_rate
>= DESC_RATEVHT1SS_MCS0
) &&
422 (rx_rate
<= DESC_RATEVHT1SS_MCS9
))
424 else if ((rx_rate
>= DESC_RATEVHT2SS_MCS0
) &&
425 (rx_rate
<= DESC_RATEVHT2SS_MCS9
))
431 bool rtl8821ae_rx_query_desc(struct ieee80211_hw
*hw
,
432 struct rtl_stats
*status
,
433 struct ieee80211_rx_status
*rx_status
,
434 u8
*pdesc8
, struct sk_buff
*skb
)
436 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
437 struct rx_fwinfo_8821ae
*p_drvinfo
;
438 struct ieee80211_hdr
*hdr
;
440 __le32
*pdesc
= (__le32
*)pdesc8
;
441 u32 phystatus
= get_rx_desc_physt(pdesc
);
443 status
->length
= (u16
)get_rx_desc_pkt_len(pdesc
);
444 status
->rx_drvinfo_size
= (u8
)get_rx_desc_drv_info_size(pdesc
) *
445 RX_DRV_INFO_SIZE_UNIT
;
446 status
->rx_bufshift
= (u8
)(get_rx_desc_shift(pdesc
) & 0x03);
447 status
->icv
= (u16
)get_rx_desc_icv(pdesc
);
448 status
->crc
= (u16
)get_rx_desc_crc32(pdesc
);
449 status
->hwerror
= (status
->crc
| status
->icv
);
450 status
->decrypted
= !get_rx_desc_swdec(pdesc
);
451 status
->rate
= (u8
)get_rx_desc_rxmcs(pdesc
);
452 status
->shortpreamble
= (u16
)get_rx_desc_splcp(pdesc
);
453 status
->isampdu
= (bool)(get_rx_desc_paggr(pdesc
) == 1);
454 status
->isfirst_ampdu
= (bool)(get_rx_desc_paggr(pdesc
) == 1);
455 status
->timestamp_low
= get_rx_desc_tsfl(pdesc
);
456 status
->rx_packet_bw
= get_rx_desc_bw(pdesc
);
457 status
->macid
= get_rx_desc_macid(pdesc
);
458 status
->is_short_gi
= !(bool)get_rx_desc_splcp(pdesc
);
459 status
->is_ht
= rtl8821ae_get_rxdesc_is_ht(hw
, pdesc
);
460 status
->is_vht
= rtl8821ae_get_rxdesc_is_vht(hw
, pdesc
);
461 status
->vht_nss
= rtl8821ae_get_rx_vht_nss(hw
, pdesc
);
462 status
->is_cck
= RTL8821AE_RX_HAL_IS_CCK_RATE(status
->rate
);
464 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
465 "rx_packet_bw=%s,is_ht %d, is_vht %d, vht_nss=%d,is_short_gi %d.\n",
466 (status
->rx_packet_bw
== 2) ? "80M" :
467 (status
->rx_packet_bw
== 1) ? "40M" : "20M",
468 status
->is_ht
, status
->is_vht
, status
->vht_nss
,
469 status
->is_short_gi
);
471 if (get_rx_status_desc_rpt_sel(pdesc
))
472 status
->packet_report_type
= C2H_PACKET
;
474 status
->packet_report_type
= NORMAL_RX
;
476 if (get_rx_status_desc_pattern_match(pdesc
))
478 else if (get_rx_status_desc_magic_match(pdesc
))
480 else if (get_rx_status_desc_unicast_match(pdesc
))
486 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
487 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
489 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
490 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
492 hdr
= (struct ieee80211_hdr
*)(skb
->data
+
493 status
->rx_drvinfo_size
+ status
->rx_bufshift
);
496 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
498 if (status
->rx_packet_bw
== HT_CHANNEL_WIDTH_20_40
)
499 rx_status
->bw
= RATE_INFO_BW_40
;
500 else if (status
->rx_packet_bw
== HT_CHANNEL_WIDTH_80
)
501 rx_status
->bw
= RATE_INFO_BW_80
;
503 rx_status
->encoding
= RX_ENC_HT
;
505 rx_status
->encoding
= RX_ENC_VHT
;
507 if (status
->is_short_gi
)
508 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
510 rx_status
->nss
= status
->vht_nss
;
511 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
513 /* hw will set status->decrypted true, if it finds the
514 * frame is open data frame or mgmt frame.
515 * So hw will not decryption robust managment frame
516 * for IEEE80211w but still set status->decrypted
517 * true, so here we should set it back to undecrypted
518 * for IEEE80211w frame, and mac80211 sw will help
521 if (status
->decrypted
) {
522 if ((!_ieee80211_is_robust_mgmt_frame(hdr
)) &&
523 (ieee80211_has_protected(hdr
->frame_control
)))
524 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
526 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
529 /* rate_idx: index of data rate into band's
530 * supported rates or MCS index if HT rates
531 * are use (RX_FLAG_HT)
533 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
537 rx_status
->mactime
= status
->timestamp_low
;
539 p_drvinfo
= (struct rx_fwinfo_8821ae
*)(skb
->data
+
540 status
->rx_bufshift
);
542 translate_rx_signal_stuff(hw
, skb
, status
, pdesc
, p_drvinfo
);
544 rx_status
->signal
= status
->recvsignalpower
+ 10;
545 if (status
->packet_report_type
== TX_REPORT2
) {
546 status
->macid_valid_entry
[0] =
547 get_rx_rpt2_desc_macid_valid_1(pdesc
);
548 status
->macid_valid_entry
[1] =
549 get_rx_rpt2_desc_macid_valid_2(pdesc
);
554 static u8
rtl8821ae_bw_mapping(struct ieee80211_hw
*hw
,
555 struct rtl_tcb_desc
*ptcb_desc
)
557 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
558 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
559 u8 bw_setting_of_desc
= 0;
561 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
562 "rtl8821ae_bw_mapping, current_chan_bw %d, packet_bw %d\n",
563 rtlphy
->current_chan_bw
, ptcb_desc
->packet_bw
);
565 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
566 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
)
567 bw_setting_of_desc
= 2;
568 else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
)
569 bw_setting_of_desc
= 1;
571 bw_setting_of_desc
= 0;
572 } else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
573 if ((ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) ||
574 (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
))
575 bw_setting_of_desc
= 1;
577 bw_setting_of_desc
= 0;
579 bw_setting_of_desc
= 0;
581 return bw_setting_of_desc
;
584 static u8
rtl8821ae_sc_mapping(struct ieee80211_hw
*hw
,
585 struct rtl_tcb_desc
*ptcb_desc
)
587 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
588 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
589 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
590 u8 sc_setting_of_desc
= 0;
592 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
593 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
) {
594 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
595 } else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
596 if (mac
->cur_80_prime_sc
==
597 HAL_PRIME_CHNL_OFFSET_LOWER
)
599 VHT_DATA_SC_40_LOWER_OF_80MHZ
;
600 else if (mac
->cur_80_prime_sc
==
601 HAL_PRIME_CHNL_OFFSET_UPPER
)
603 VHT_DATA_SC_40_UPPER_OF_80MHZ
;
605 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_LOUD
,
606 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
608 if ((mac
->cur_40_prime_sc
==
609 HAL_PRIME_CHNL_OFFSET_LOWER
) &&
610 (mac
->cur_80_prime_sc
==
611 HAL_PRIME_CHNL_OFFSET_LOWER
))
613 VHT_DATA_SC_20_LOWEST_OF_80MHZ
;
614 else if ((mac
->cur_40_prime_sc
==
615 HAL_PRIME_CHNL_OFFSET_UPPER
) &&
616 (mac
->cur_80_prime_sc
==
617 HAL_PRIME_CHNL_OFFSET_LOWER
))
619 VHT_DATA_SC_20_LOWER_OF_80MHZ
;
620 else if ((mac
->cur_40_prime_sc
==
621 HAL_PRIME_CHNL_OFFSET_LOWER
) &&
622 (mac
->cur_80_prime_sc
==
623 HAL_PRIME_CHNL_OFFSET_UPPER
))
625 VHT_DATA_SC_20_UPPER_OF_80MHZ
;
626 else if ((mac
->cur_40_prime_sc
==
627 HAL_PRIME_CHNL_OFFSET_UPPER
) &&
628 (mac
->cur_80_prime_sc
==
629 HAL_PRIME_CHNL_OFFSET_UPPER
))
631 VHT_DATA_SC_20_UPPERST_OF_80MHZ
;
633 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_LOUD
,
634 "rtl8821ae_sc_mapping: Not Correct Primary40MHz Setting\n");
636 } else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
637 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
638 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
639 } else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20
) {
640 if (mac
->cur_40_prime_sc
==
641 HAL_PRIME_CHNL_OFFSET_UPPER
) {
643 VHT_DATA_SC_20_UPPER_OF_80MHZ
;
644 } else if (mac
->cur_40_prime_sc
==
645 HAL_PRIME_CHNL_OFFSET_LOWER
){
647 VHT_DATA_SC_20_LOWER_OF_80MHZ
;
649 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
653 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
656 return sc_setting_of_desc
;
659 void rtl8821ae_tx_fill_desc(struct ieee80211_hw
*hw
,
660 struct ieee80211_hdr
*hdr
, u8
*pdesc8
, u8
*txbd
,
661 struct ieee80211_tx_info
*info
,
662 struct ieee80211_sta
*sta
,
664 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
666 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
667 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
668 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
669 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
670 struct rtlwifi_tx_info
*tx_info
= rtl_tx_skb_cb_info(skb
);
672 __le16 fc
= hdr
->frame_control
;
673 unsigned int buf_len
= 0;
674 unsigned int skb_len
= skb
->len
;
675 u8 fw_qsel
= _rtl8821ae_map_hwqueue_to_fwqueue(skb
, hw_queue
);
676 bool firstseg
= ((hdr
->seq_ctrl
&
677 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
678 bool lastseg
= ((hdr
->frame_control
&
679 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
683 __le32
*pdesc
= (__le32
*)pdesc8
;
685 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
686 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
687 /* reserve 8 byte for AMPDU early mode */
688 if (rtlhal
->earlymode_enable
) {
689 skb_push(skb
, EM_HDR_LEN
);
690 memset(skb
->data
, 0, EM_HDR_LEN
);
693 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
695 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
696 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
697 "DMA mapping error\n");
700 clear_pci_tx_desc_content(pdesc
, sizeof(struct tx_desc_8821ae
));
701 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
706 if (rtlhal
->earlymode_enable
) {
707 set_tx_desc_pkt_offset(pdesc
, 1);
708 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
+
710 if (ptcb_desc
->empkt_num
) {
711 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
712 "Insert 8 byte.pTcb->EMPktNum:%d\n",
713 ptcb_desc
->empkt_num
);
714 rtl8821ae_insert_emcontent(ptcb_desc
,
715 (__le32
*)skb
->data
);
718 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
722 /* ptcb_desc->use_driver_rate = true; */
723 set_tx_desc_tx_rate(pdesc
, ptcb_desc
->hw_rate
);
724 if (ptcb_desc
->hw_rate
> DESC_RATEMCS0
)
725 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
727 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
729 set_tx_desc_data_shortgi(pdesc
, short_gi
);
731 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
732 set_tx_desc_agg_enable(pdesc
, 1);
733 set_tx_desc_max_agg_num(pdesc
, 0x1f);
735 set_tx_desc_seq(pdesc
, seq_number
);
736 set_tx_desc_rts_enable(pdesc
,
737 ((ptcb_desc
->rts_enable
&&
738 !ptcb_desc
->cts_enable
) ? 1 : 0));
739 set_tx_desc_hw_rts_enable(pdesc
, 0);
740 set_tx_desc_cts2self(pdesc
, ((ptcb_desc
->cts_enable
) ? 1 : 0));
742 set_tx_desc_rts_rate(pdesc
, ptcb_desc
->rts_rate
);
743 set_tx_desc_rts_sc(pdesc
, ptcb_desc
->rts_sc
);
744 tmp_bool
= ((ptcb_desc
->rts_rate
<= DESC_RATE54M
) ?
745 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
746 (ptcb_desc
->rts_use_shortgi
? 1 : 0));
747 set_tx_desc_rts_short(pdesc
, tmp_bool
);
749 if (ptcb_desc
->tx_enable_sw_calc_duration
)
750 set_tx_desc_nav_use_hdr(pdesc
, 1);
752 set_tx_desc_data_bw(pdesc
,
753 rtl8821ae_bw_mapping(hw
, ptcb_desc
));
755 set_tx_desc_tx_sub_carrier(pdesc
,
756 rtl8821ae_sc_mapping(hw
, ptcb_desc
));
758 set_tx_desc_linip(pdesc
, 0);
759 set_tx_desc_pkt_size(pdesc
, (u16
)skb_len
);
761 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
763 set_tx_desc_ampdu_density(pdesc
, ampdu_density
);
765 if (info
->control
.hw_key
) {
766 struct ieee80211_key_conf
*keyconf
=
767 info
->control
.hw_key
;
768 switch (keyconf
->cipher
) {
769 case WLAN_CIPHER_SUITE_WEP40
:
770 case WLAN_CIPHER_SUITE_WEP104
:
771 case WLAN_CIPHER_SUITE_TKIP
:
772 set_tx_desc_sec_type(pdesc
, 0x1);
774 case WLAN_CIPHER_SUITE_CCMP
:
775 set_tx_desc_sec_type(pdesc
, 0x3);
778 set_tx_desc_sec_type(pdesc
, 0x0);
783 set_tx_desc_queue_sel(pdesc
, fw_qsel
);
784 set_tx_desc_data_rate_fb_limit(pdesc
, 0x1F);
785 set_tx_desc_rts_rate_fb_limit(pdesc
, 0xF);
786 set_tx_desc_disable_fb(pdesc
, ptcb_desc
->disable_ratefallback
?
788 set_tx_desc_use_rate(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
790 if (ieee80211_is_data_qos(fc
)) {
792 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
793 "Enable RDG function.\n");
794 set_tx_desc_rdg_enable(pdesc
, 1);
795 set_tx_desc_htc(pdesc
, 1);
799 rtl_set_tx_report(ptcb_desc
, pdesc8
, hw
, tx_info
);
802 set_tx_desc_first_seg(pdesc
, (firstseg
? 1 : 0));
803 set_tx_desc_last_seg(pdesc
, (lastseg
? 1 : 0));
804 set_tx_desc_tx_buffer_size(pdesc
, buf_len
);
805 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
806 /* if (rtlpriv->dm.useramask) { */
808 set_tx_desc_rate_id(pdesc
, ptcb_desc
->ratr_index
);
809 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
811 set_tx_desc_rate_id(pdesc
, 0xC + ptcb_desc
->ratr_index
);
812 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
814 if (!ieee80211_is_data_qos(fc
)) {
815 set_tx_desc_hwseq_en(pdesc
, 1);
816 set_tx_desc_hwseq_sel(pdesc
, 0);
818 set_tx_desc_more_frag(pdesc
, (lastseg
? 0 : 1));
819 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
820 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
821 set_tx_desc_bmc(pdesc
, 1);
824 rtl8821ae_dm_set_tx_ant_by_tx_info(hw
, pdesc8
, ptcb_desc
->mac_id
);
825 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
828 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
829 u8
*pdesc8
, bool firstseg
,
830 bool lastseg
, struct sk_buff
*skb
)
832 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
833 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
834 u8 fw_queue
= QSLT_BEACON
;
835 __le32
*pdesc
= (__le32
*)pdesc8
;
837 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
841 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
842 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
843 "DMA mapping error\n");
846 clear_pci_tx_desc_content(pdesc
, TX_DESC_SIZE
);
848 set_tx_desc_first_seg(pdesc
, 1);
849 set_tx_desc_last_seg(pdesc
, 1);
851 set_tx_desc_pkt_size(pdesc
, (u16
)(skb
->len
));
853 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
855 set_tx_desc_use_rate(pdesc
, 1);
856 set_tx_desc_tx_rate(pdesc
, DESC_RATE1M
);
857 set_tx_desc_disable_fb(pdesc
, 1);
859 set_tx_desc_data_bw(pdesc
, 0);
861 set_tx_desc_hwseq_en(pdesc
, 1);
863 set_tx_desc_queue_sel(pdesc
, fw_queue
);
865 set_tx_desc_tx_buffer_size(pdesc
, skb
->len
);
867 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
869 set_tx_desc_macid(pdesc
, 0);
871 set_tx_desc_own(pdesc
, 1);
873 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
874 "H2C Tx Cmd Content\n",
875 pdesc8
, TX_DESC_SIZE
);
878 void rtl8821ae_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc8
,
879 bool istx
, u8 desc_name
, u8
*val
)
881 __le32
*pdesc
= (__le32
*)pdesc8
;
886 set_tx_desc_own(pdesc
, 1);
888 case HW_DESC_TX_NEXTDESC_ADDR
:
889 set_tx_desc_next_desc_address(pdesc
, *(u32
*)val
);
893 "rtl8821ae: ERR txdesc :%d not processed\n",
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 "rtl8821ae: ERR rxdesc :%d not processed\n",
920 u64
rtl8821ae_get_desc(struct ieee80211_hw
*hw
,
921 u8
*pdesc8
, bool istx
, u8 desc_name
)
924 __le32
*pdesc
= (__le32
*)pdesc8
;
929 ret
= get_tx_desc_own(pdesc
);
931 case HW_DESC_TXBUFF_ADDR
:
932 ret
= get_tx_desc_tx_buffer_address(pdesc
);
936 "rtl8821ae: ERR txdesc :%d not processed\n",
943 ret
= get_rx_desc_own(pdesc
);
945 case HW_DESC_RXPKT_LEN
:
946 ret
= get_rx_desc_pkt_len(pdesc
);
948 case HW_DESC_RXBUFF_ADDR
:
949 ret
= get_rx_desc_buff_addr(pdesc
);
953 "rtl8821ae: ERR rxdesc :%d not processed\n",
961 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw
*hw
,
962 u8 hw_queue
, u16 index
)
964 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
965 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
966 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
967 u8 own
= (u8
)rtl8821ae_get_desc(hw
, entry
, true, HW_DESC_OWN
);
970 *beacon packet will only use the first
971 *descriptor defautly,and the own may not
972 *be cleared by the hardware
979 void rtl8821ae_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
981 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
983 if (hw_queue
== BEACON_QUEUE
) {
984 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
986 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
987 BIT(0) << (hw_queue
));