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 rtl_dbg(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 rtl_dbg(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 rtl_dbg(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 rtl_dbg(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 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
562 "%s, current_chan_bw %d, packet_bw %d\n",
564 rtlphy
->current_chan_bw
, ptcb_desc
->packet_bw
);
566 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
567 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
)
568 bw_setting_of_desc
= 2;
569 else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
)
570 bw_setting_of_desc
= 1;
572 bw_setting_of_desc
= 0;
573 } else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
574 if ((ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) ||
575 (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
))
576 bw_setting_of_desc
= 1;
578 bw_setting_of_desc
= 0;
580 bw_setting_of_desc
= 0;
582 return bw_setting_of_desc
;
585 static u8
rtl8821ae_sc_mapping(struct ieee80211_hw
*hw
,
586 struct rtl_tcb_desc
*ptcb_desc
)
588 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
589 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
590 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
591 u8 sc_setting_of_desc
= 0;
593 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
594 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_80
) {
595 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
596 } else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
597 if (mac
->cur_80_prime_sc
==
598 HAL_PRIME_CHNL_OFFSET_LOWER
)
600 VHT_DATA_SC_40_LOWER_OF_80MHZ
;
601 else if (mac
->cur_80_prime_sc
==
602 HAL_PRIME_CHNL_OFFSET_UPPER
)
604 VHT_DATA_SC_40_UPPER_OF_80MHZ
;
606 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_LOUD
,
607 "%s: Not Correct Primary40MHz Setting\n",
610 if ((mac
->cur_40_prime_sc
==
611 HAL_PRIME_CHNL_OFFSET_LOWER
) &&
612 (mac
->cur_80_prime_sc
==
613 HAL_PRIME_CHNL_OFFSET_LOWER
))
615 VHT_DATA_SC_20_LOWEST_OF_80MHZ
;
616 else if ((mac
->cur_40_prime_sc
==
617 HAL_PRIME_CHNL_OFFSET_UPPER
) &&
618 (mac
->cur_80_prime_sc
==
619 HAL_PRIME_CHNL_OFFSET_LOWER
))
621 VHT_DATA_SC_20_LOWER_OF_80MHZ
;
622 else if ((mac
->cur_40_prime_sc
==
623 HAL_PRIME_CHNL_OFFSET_LOWER
) &&
624 (mac
->cur_80_prime_sc
==
625 HAL_PRIME_CHNL_OFFSET_UPPER
))
627 VHT_DATA_SC_20_UPPER_OF_80MHZ
;
628 else if ((mac
->cur_40_prime_sc
==
629 HAL_PRIME_CHNL_OFFSET_UPPER
) &&
630 (mac
->cur_80_prime_sc
==
631 HAL_PRIME_CHNL_OFFSET_UPPER
))
633 VHT_DATA_SC_20_UPPERST_OF_80MHZ
;
635 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_LOUD
,
636 "%s: Not Correct Primary40MHz Setting\n",
639 } else if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_20_40
) {
640 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
641 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
642 } else if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20
) {
643 if (mac
->cur_40_prime_sc
==
644 HAL_PRIME_CHNL_OFFSET_UPPER
) {
646 VHT_DATA_SC_20_UPPER_OF_80MHZ
;
647 } else if (mac
->cur_40_prime_sc
==
648 HAL_PRIME_CHNL_OFFSET_LOWER
){
650 VHT_DATA_SC_20_LOWER_OF_80MHZ
;
652 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
656 sc_setting_of_desc
= VHT_DATA_SC_DONOT_CARE
;
659 return sc_setting_of_desc
;
662 void rtl8821ae_tx_fill_desc(struct ieee80211_hw
*hw
,
663 struct ieee80211_hdr
*hdr
, u8
*pdesc8
, u8
*txbd
,
664 struct ieee80211_tx_info
*info
,
665 struct ieee80211_sta
*sta
,
667 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
669 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
670 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
671 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
672 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
673 struct rtlwifi_tx_info
*tx_info
= rtl_tx_skb_cb_info(skb
);
675 __le16 fc
= hdr
->frame_control
;
676 unsigned int buf_len
= 0;
677 unsigned int skb_len
= skb
->len
;
678 u8 fw_qsel
= _rtl8821ae_map_hwqueue_to_fwqueue(skb
, hw_queue
);
679 bool firstseg
= ((hdr
->seq_ctrl
&
680 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
681 bool lastseg
= ((hdr
->frame_control
&
682 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
686 __le32
*pdesc
= (__le32
*)pdesc8
;
688 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
689 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
690 /* reserve 8 byte for AMPDU early mode */
691 if (rtlhal
->earlymode_enable
) {
692 skb_push(skb
, EM_HDR_LEN
);
693 memset(skb
->data
, 0, EM_HDR_LEN
);
696 mapping
= dma_map_single(&rtlpci
->pdev
->dev
, skb
->data
, skb
->len
,
698 if (dma_mapping_error(&rtlpci
->pdev
->dev
, mapping
)) {
699 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
700 "DMA mapping error\n");
703 clear_pci_tx_desc_content(pdesc
, sizeof(struct tx_desc_8821ae
));
704 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
709 if (rtlhal
->earlymode_enable
) {
710 set_tx_desc_pkt_offset(pdesc
, 1);
711 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
+
713 if (ptcb_desc
->empkt_num
) {
714 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
715 "Insert 8 byte.pTcb->EMPktNum:%d\n",
716 ptcb_desc
->empkt_num
);
717 rtl8821ae_insert_emcontent(ptcb_desc
,
718 (__le32
*)skb
->data
);
721 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
725 /* ptcb_desc->use_driver_rate = true; */
726 set_tx_desc_tx_rate(pdesc
, ptcb_desc
->hw_rate
);
727 if (ptcb_desc
->hw_rate
> DESC_RATEMCS0
)
728 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
730 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
732 set_tx_desc_data_shortgi(pdesc
, short_gi
);
734 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
735 set_tx_desc_agg_enable(pdesc
, 1);
736 set_tx_desc_max_agg_num(pdesc
, 0x1f);
738 set_tx_desc_seq(pdesc
, seq_number
);
739 set_tx_desc_rts_enable(pdesc
,
740 ((ptcb_desc
->rts_enable
&&
741 !ptcb_desc
->cts_enable
) ? 1 : 0));
742 set_tx_desc_hw_rts_enable(pdesc
, 0);
743 set_tx_desc_cts2self(pdesc
, ((ptcb_desc
->cts_enable
) ? 1 : 0));
745 set_tx_desc_rts_rate(pdesc
, ptcb_desc
->rts_rate
);
746 set_tx_desc_rts_sc(pdesc
, ptcb_desc
->rts_sc
);
747 tmp_bool
= ((ptcb_desc
->rts_rate
<= DESC_RATE54M
) ?
748 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
749 (ptcb_desc
->rts_use_shortgi
? 1 : 0));
750 set_tx_desc_rts_short(pdesc
, tmp_bool
);
752 if (ptcb_desc
->tx_enable_sw_calc_duration
)
753 set_tx_desc_nav_use_hdr(pdesc
, 1);
755 set_tx_desc_data_bw(pdesc
,
756 rtl8821ae_bw_mapping(hw
, ptcb_desc
));
758 set_tx_desc_tx_sub_carrier(pdesc
,
759 rtl8821ae_sc_mapping(hw
, ptcb_desc
));
761 set_tx_desc_linip(pdesc
, 0);
762 set_tx_desc_pkt_size(pdesc
, (u16
)skb_len
);
764 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
766 set_tx_desc_ampdu_density(pdesc
, ampdu_density
);
768 if (info
->control
.hw_key
) {
769 struct ieee80211_key_conf
*keyconf
=
770 info
->control
.hw_key
;
771 switch (keyconf
->cipher
) {
772 case WLAN_CIPHER_SUITE_WEP40
:
773 case WLAN_CIPHER_SUITE_WEP104
:
774 case WLAN_CIPHER_SUITE_TKIP
:
775 set_tx_desc_sec_type(pdesc
, 0x1);
777 case WLAN_CIPHER_SUITE_CCMP
:
778 set_tx_desc_sec_type(pdesc
, 0x3);
781 set_tx_desc_sec_type(pdesc
, 0x0);
786 set_tx_desc_queue_sel(pdesc
, fw_qsel
);
787 set_tx_desc_data_rate_fb_limit(pdesc
, 0x1F);
788 set_tx_desc_rts_rate_fb_limit(pdesc
, 0xF);
789 set_tx_desc_disable_fb(pdesc
, ptcb_desc
->disable_ratefallback
?
791 set_tx_desc_use_rate(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
793 if (ieee80211_is_data_qos(fc
)) {
795 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
796 "Enable RDG function.\n");
797 set_tx_desc_rdg_enable(pdesc
, 1);
798 set_tx_desc_htc(pdesc
, 1);
802 rtl_set_tx_report(ptcb_desc
, pdesc8
, hw
, tx_info
);
805 set_tx_desc_first_seg(pdesc
, (firstseg
? 1 : 0));
806 set_tx_desc_last_seg(pdesc
, (lastseg
? 1 : 0));
807 set_tx_desc_tx_buffer_size(pdesc
, buf_len
);
808 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
809 /* if (rtlpriv->dm.useramask) { */
811 set_tx_desc_rate_id(pdesc
, ptcb_desc
->ratr_index
);
812 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
814 set_tx_desc_rate_id(pdesc
, 0xC + ptcb_desc
->ratr_index
);
815 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
817 if (!ieee80211_is_data_qos(fc
)) {
818 set_tx_desc_hwseq_en(pdesc
, 1);
819 set_tx_desc_hwseq_sel(pdesc
, 0);
821 set_tx_desc_more_frag(pdesc
, (lastseg
? 0 : 1));
822 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
823 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
824 set_tx_desc_bmc(pdesc
, 1);
827 rtl8821ae_dm_set_tx_ant_by_tx_info(hw
, pdesc8
, ptcb_desc
->mac_id
);
828 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
831 void rtl8821ae_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
832 u8
*pdesc8
, bool firstseg
,
833 bool lastseg
, struct sk_buff
*skb
)
835 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
836 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
837 u8 fw_queue
= QSLT_BEACON
;
838 __le32
*pdesc
= (__le32
*)pdesc8
;
840 dma_addr_t mapping
= dma_map_single(&rtlpci
->pdev
->dev
, skb
->data
,
841 skb
->len
, DMA_TO_DEVICE
);
843 if (dma_mapping_error(&rtlpci
->pdev
->dev
, mapping
)) {
844 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_TRACE
,
845 "DMA mapping error\n");
848 clear_pci_tx_desc_content(pdesc
, TX_DESC_SIZE
);
850 set_tx_desc_first_seg(pdesc
, 1);
851 set_tx_desc_last_seg(pdesc
, 1);
853 set_tx_desc_pkt_size(pdesc
, (u16
)(skb
->len
));
855 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
857 set_tx_desc_use_rate(pdesc
, 1);
858 set_tx_desc_tx_rate(pdesc
, DESC_RATE1M
);
859 set_tx_desc_disable_fb(pdesc
, 1);
861 set_tx_desc_data_bw(pdesc
, 0);
863 set_tx_desc_hwseq_en(pdesc
, 1);
865 set_tx_desc_queue_sel(pdesc
, fw_queue
);
867 set_tx_desc_tx_buffer_size(pdesc
, skb
->len
);
869 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
871 set_tx_desc_macid(pdesc
, 0);
873 set_tx_desc_own(pdesc
, 1);
875 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
876 "H2C Tx Cmd Content\n",
877 pdesc8
, TX_DESC_SIZE
);
880 void rtl8821ae_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc8
,
881 bool istx
, u8 desc_name
, u8
*val
)
883 __le32
*pdesc
= (__le32
*)pdesc8
;
888 set_tx_desc_own(pdesc
, 1);
890 case HW_DESC_TX_NEXTDESC_ADDR
:
891 set_tx_desc_next_desc_address(pdesc
, *(u32
*)val
);
895 "rtl8821ae: ERR txdesc :%d not processed\n",
902 set_rx_desc_own(pdesc
, 1);
904 case HW_DESC_RXBUFF_ADDR
:
905 set_rx_desc_buff_addr(pdesc
, *(u32
*)val
);
907 case HW_DESC_RXPKT_LEN
:
908 set_rx_desc_pkt_len(pdesc
, *(u32
*)val
);
911 set_rx_desc_eor(pdesc
, 1);
915 "rtl8821ae: ERR rxdesc :%d not processed\n",
922 u64
rtl8821ae_get_desc(struct ieee80211_hw
*hw
,
923 u8
*pdesc8
, bool istx
, u8 desc_name
)
926 __le32
*pdesc
= (__le32
*)pdesc8
;
931 ret
= get_tx_desc_own(pdesc
);
933 case HW_DESC_TXBUFF_ADDR
:
934 ret
= get_tx_desc_tx_buffer_address(pdesc
);
938 "rtl8821ae: ERR txdesc :%d not processed\n",
945 ret
= get_rx_desc_own(pdesc
);
947 case HW_DESC_RXPKT_LEN
:
948 ret
= get_rx_desc_pkt_len(pdesc
);
950 case HW_DESC_RXBUFF_ADDR
:
951 ret
= get_rx_desc_buff_addr(pdesc
);
955 "rtl8821ae: ERR rxdesc :%d not processed\n",
963 bool rtl8821ae_is_tx_desc_closed(struct ieee80211_hw
*hw
,
964 u8 hw_queue
, u16 index
)
966 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
967 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
968 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
969 u8 own
= (u8
)rtl8821ae_get_desc(hw
, entry
, true, HW_DESC_OWN
);
972 *beacon packet will only use the first
973 *descriptor defautly,and the own may not
974 *be cleared by the hardware
981 void rtl8821ae_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
983 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
985 if (hw_queue
== BEACON_QUEUE
) {
986 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
988 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
989 BIT(0) << (hw_queue
));