1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2013 Realtek Corporation.*/
15 static u8
_rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
17 __le16 fc
= rtl_get_fc(skb
);
19 if (unlikely(ieee80211_is_beacon(fc
)))
21 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
27 static void _rtl88ee_query_rxphystatus(struct ieee80211_hw
*hw
,
28 struct rtl_stats
*pstatus
, __le32
*pdesc
,
29 struct rx_fwinfo_88e
*p_drvinfo
,
30 bool bpacket_match_bssid
,
31 bool bpacket_toself
, bool packet_beacon
)
33 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
34 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
35 struct phy_sts_cck_8192s_t
*cck_buf
;
36 struct phy_status_rpt
*phystrpt
=
37 (struct phy_status_rpt
*)p_drvinfo
;
38 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
39 s8 rx_pwr_all
= 0, rx_pwr
[4];
40 u8 rf_rx_num
= 0, evm
, pwdb_all
;
41 u8 i
, max_spatial_stream
;
42 u32 rssi
, total_rssi
= 0;
43 bool is_cck
= pstatus
->is_cck
;
46 /* Record it for next packet processing */
47 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
48 pstatus
->packet_toself
= bpacket_toself
;
49 pstatus
->packet_beacon
= packet_beacon
;
50 pstatus
->rx_mimo_signalquality
[0] = -1;
51 pstatus
->rx_mimo_signalquality
[1] = -1;
56 /* CCK Driver info Structure is not the same as OFDM packet. */
57 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
58 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
60 /* (1)Hardware does not provide RSSI for CCK
61 * (2)PWDB, Average PWDB cacluated by
62 * hardware (for rate adaptive)
64 if (ppsc
->rfpwr_state
== ERFON
)
66 (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
,
71 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
72 vga_idx
= (cck_agc_rpt
& 0x1f);
77 rx_pwr_all
= -100 + 2*(27-vga_idx
);
83 rx_pwr_all
= -48 + 2*(2-vga_idx
);
87 rx_pwr_all
= -42 + 2*(7-vga_idx
);
91 rx_pwr_all
= -36 + 2*(7-vga_idx
);
95 rx_pwr_all
= -24 + 2*(7-vga_idx
);
100 rx_pwr_all
= -12 + 2*(5-vga_idx
);
102 rx_pwr_all
= -6 + 2*(5-vga_idx
);
105 rx_pwr_all
= 8-2*vga_idx
;
108 rx_pwr_all
= 14-2*vga_idx
;
114 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
115 /* CCK gain is smaller than OFDM/MCS gain, */
116 /* so we add gain diff by experiences, the val is 6 */
120 /* modify the offset to make the same
121 * gain index with OFDM.
123 if (pwdb_all
> 34 && pwdb_all
<= 42)
125 else if (pwdb_all
> 26 && pwdb_all
<= 34)
127 else if (pwdb_all
> 14 && pwdb_all
<= 26)
129 else if (pwdb_all
> 4 && pwdb_all
<= 14)
133 pwdb_all
= ((pwdb_all
-80)<<1) +
134 ((pwdb_all
-80)>>1) + 80;
135 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
141 pstatus
->rx_pwdb_all
= pwdb_all
;
142 pstatus
->recvsignalpower
= rx_pwr_all
;
144 /* (3) Get Signal Quality (EVM) */
145 if (bpacket_match_bssid
) {
148 if (pstatus
->rx_pwdb_all
> 40)
151 sq
= cck_buf
->sq_rpt
;
157 sq
= ((64 - sq
) * 100) / 44;
160 pstatus
->signalquality
= sq
;
161 pstatus
->rx_mimo_signalquality
[0] = sq
;
162 pstatus
->rx_mimo_signalquality
[1] = -1;
165 rtlpriv
->dm
.rfpath_rxenable
[0] =
166 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
168 /* (1)Get RSSI for HT rate */
169 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
170 /* we will judge RF RX path now. */
171 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
174 rx_pwr
[i
] = ((p_drvinfo
->gain_trsw
[i
] &
177 /* Translate DBM to percentage. */
178 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
181 /* Get Rx snr value in DB */
182 rtlpriv
->stats
.rx_snr_db
[i
] =
183 (long)(p_drvinfo
->rxsnr
[i
] / 2);
185 /* Record Signal Strength for next packet */
186 if (bpacket_match_bssid
)
187 pstatus
->rx_mimo_signalstrength
[i
] = (u8
)rssi
;
190 /* (2)PWDB, Average PWDB cacluated by
191 * hardware (for rate adaptive)
193 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
195 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
196 pstatus
->rx_pwdb_all
= pwdb_all
;
197 pstatus
->rxpower
= rx_pwr_all
;
198 pstatus
->recvsignalpower
= rx_pwr_all
;
200 /* (3)EVM of HT rate */
201 if (pstatus
->is_ht
&& pstatus
->rate
>= DESC92C_RATEMCS8
&&
202 pstatus
->rate
<= DESC92C_RATEMCS15
)
203 max_spatial_stream
= 2;
205 max_spatial_stream
= 1;
207 for (i
= 0; i
< max_spatial_stream
; i
++) {
208 evm
= rtl_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
210 if (bpacket_match_bssid
) {
211 /* Fill value in RFD, Get the first
212 * spatial stream onlyi
215 pstatus
->signalquality
=
217 pstatus
->rx_mimo_signalquality
[i
] =
223 /* UI BSS List signal strength(in percentage),
224 * make it good looking, from 0~100.
227 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
229 else if (rf_rx_num
!= 0)
230 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
231 total_rssi
/= rf_rx_num
));
232 /*HW antenna diversity*/
233 rtldm
->fat_table
.antsel_rx_keep_0
= phystrpt
->ant_sel
;
234 rtldm
->fat_table
.antsel_rx_keep_1
= phystrpt
->ant_sel_b
;
235 rtldm
->fat_table
.antsel_rx_keep_2
= phystrpt
->antsel_rx_keep_2
;
238 static void _rtl88ee_smart_antenna(struct ieee80211_hw
*hw
,
239 struct rtl_stats
*pstatus
)
241 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
242 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
244 struct fast_ant_training
*pfat_table
= &rtldm
->fat_table
;
246 if (rtlefuse
->antenna_div_type
== CG_TRX_SMART_ANTDIV
) {
247 if (pfat_table
->fat_state
== FAT_TRAINING_STATE
) {
248 if (pstatus
->packet_toself
) {
250 (pfat_table
->antsel_rx_keep_2
<< 2) |
251 (pfat_table
->antsel_rx_keep_1
<< 1) |
252 pfat_table
->antsel_rx_keep_0
;
253 pfat_table
->ant_sum
[antsel_tr_mux
] +=
254 pstatus
->rx_pwdb_all
;
255 pfat_table
->ant_cnt
[antsel_tr_mux
]++;
258 } else if ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) ||
259 (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)) {
260 if (pstatus
->packet_toself
|| pstatus
->packet_matchbssid
) {
261 antsel_tr_mux
= (pfat_table
->antsel_rx_keep_2
<< 2) |
262 (pfat_table
->antsel_rx_keep_1
<< 1) |
263 pfat_table
->antsel_rx_keep_0
;
264 rtl88e_dm_ant_sel_statistics(hw
, antsel_tr_mux
, 0,
265 pstatus
->rx_pwdb_all
);
271 static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
273 struct rtl_stats
*pstatus
,
275 struct rx_fwinfo_88e
*p_drvinfo
)
277 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
278 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
279 struct ieee80211_hdr
*hdr
;
284 bool packet_matchbssid
, packet_toself
, packet_beacon
;
286 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
288 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
289 fc
= hdr
->frame_control
;
291 psaddr
= ieee80211_get_SA(hdr
);
292 memcpy(pstatus
->psaddr
, psaddr
, ETH_ALEN
);
294 packet_matchbssid
= ((!ieee80211_is_ctl(fc
)) &&
295 (ether_addr_equal(mac
->bssid
, ieee80211_has_tods(fc
) ?
296 hdr
->addr1
: ieee80211_has_fromds(fc
) ?
297 hdr
->addr2
: hdr
->addr3
)) &&
298 (!pstatus
->hwerror
) &&
299 (!pstatus
->crc
) && (!pstatus
->icv
));
301 packet_toself
= packet_matchbssid
&&
302 (ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
304 if (ieee80211_is_beacon(hdr
->frame_control
))
305 packet_beacon
= true;
307 packet_beacon
= false;
309 _rtl88ee_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
310 packet_matchbssid
, packet_toself
,
312 _rtl88ee_smart_antenna(hw
, pstatus
);
313 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
316 static void rtl88ee_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
317 __le32
*virtualaddress
)
320 memset(virtualaddress
, 0, 8);
322 set_earlymode_pktnum(virtualaddress
, ptcb_desc
->empkt_num
);
323 if (ptcb_desc
->empkt_num
== 1) {
324 dwtmp
= ptcb_desc
->empkt_len
[0];
326 dwtmp
= ptcb_desc
->empkt_len
[0];
327 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
328 dwtmp
+= ptcb_desc
->empkt_len
[1];
330 set_earlymode_len0(virtualaddress
, dwtmp
);
332 if (ptcb_desc
->empkt_num
<= 3) {
333 dwtmp
= ptcb_desc
->empkt_len
[2];
335 dwtmp
= ptcb_desc
->empkt_len
[2];
336 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
337 dwtmp
+= ptcb_desc
->empkt_len
[3];
339 set_earlymode_len1(virtualaddress
, dwtmp
);
340 if (ptcb_desc
->empkt_num
<= 5) {
341 dwtmp
= ptcb_desc
->empkt_len
[4];
343 dwtmp
= ptcb_desc
->empkt_len
[4];
344 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
345 dwtmp
+= ptcb_desc
->empkt_len
[5];
347 set_earlymode_len2_1(virtualaddress
, dwtmp
& 0xF);
348 set_earlymode_len2_2(virtualaddress
, dwtmp
>> 4);
349 if (ptcb_desc
->empkt_num
<= 7) {
350 dwtmp
= ptcb_desc
->empkt_len
[6];
352 dwtmp
= ptcb_desc
->empkt_len
[6];
353 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
354 dwtmp
+= ptcb_desc
->empkt_len
[7];
356 set_earlymode_len3(virtualaddress
, dwtmp
);
357 if (ptcb_desc
->empkt_num
<= 9) {
358 dwtmp
= ptcb_desc
->empkt_len
[8];
360 dwtmp
= ptcb_desc
->empkt_len
[8];
361 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
362 dwtmp
+= ptcb_desc
->empkt_len
[9];
364 set_earlymode_len4(virtualaddress
, dwtmp
);
367 bool rtl88ee_rx_query_desc(struct ieee80211_hw
*hw
,
368 struct rtl_stats
*status
,
369 struct ieee80211_rx_status
*rx_status
,
370 u8
*pdesc8
, struct sk_buff
*skb
)
372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
373 struct rx_fwinfo_88e
*p_drvinfo
;
374 struct ieee80211_hdr
*hdr
;
376 __le32
*pdesc
= (__le32
*)pdesc8
;
377 u32 phystatus
= get_rx_desc_physt(pdesc
);
379 status
->packet_report_type
= (u8
)get_rx_status_desc_rpt_sel(pdesc
);
380 if (status
->packet_report_type
== TX_REPORT2
)
381 status
->length
= (u16
)get_rx_rpt2_desc_pkt_len(pdesc
);
383 status
->length
= (u16
)get_rx_desc_pkt_len(pdesc
);
384 status
->rx_drvinfo_size
= (u8
)get_rx_desc_drv_info_size(pdesc
) *
385 RX_DRV_INFO_SIZE_UNIT
;
386 status
->rx_bufshift
= (u8
)(get_rx_desc_shift(pdesc
) & 0x03);
387 status
->icv
= (u16
)get_rx_desc_icv(pdesc
);
388 status
->crc
= (u16
)get_rx_desc_crc32(pdesc
);
389 status
->hwerror
= (status
->crc
| status
->icv
);
390 status
->decrypted
= !get_rx_desc_swdec(pdesc
);
391 status
->rate
= (u8
)get_rx_desc_rxmcs(pdesc
);
392 status
->shortpreamble
= (u16
)get_rx_desc_splcp(pdesc
);
393 status
->isampdu
= (bool) (get_rx_desc_paggr(pdesc
) == 1);
394 status
->isfirst_ampdu
= (bool)((get_rx_desc_paggr(pdesc
) == 1) &&
395 (get_rx_desc_faggr(pdesc
) == 1));
396 if (status
->packet_report_type
== NORMAL_RX
)
397 status
->timestamp_low
= get_rx_desc_tsfl(pdesc
);
398 status
->rx_is40mhzpacket
= (bool)get_rx_desc_bw(pdesc
);
399 status
->is_ht
= (bool)get_rx_desc_rxht(pdesc
);
401 status
->is_cck
= RTL8188_RX_HAL_IS_CCK_RATE(status
->rate
);
403 status
->macid
= get_rx_desc_macid(pdesc
);
404 if (get_rx_status_desc_pattern_match(pdesc
))
406 else if (get_rx_status_desc_magic_match(pdesc
))
408 else if (get_rx_status_desc_unicast_match(pdesc
))
413 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
414 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
416 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
417 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
419 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ status
->rx_drvinfo_size
420 + status
->rx_bufshift
);
423 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
425 if (status
->rx_is40mhzpacket
)
426 rx_status
->bw
= RATE_INFO_BW_40
;
429 rx_status
->encoding
= RX_ENC_HT
;
431 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
433 /* hw will set status->decrypted true, if it finds the
434 * frame is open data frame or mgmt frame.
435 * So hw will not decryption robust managment frame
436 * for IEEE80211w but still set status->decrypted
437 * true, so here we should set it back to undecrypted
438 * for IEEE80211w frame, and mac80211 sw will help
441 if (status
->decrypted
) {
442 if ((!_ieee80211_is_robust_mgmt_frame(hdr
)) &&
443 (ieee80211_has_protected(hdr
->frame_control
)))
444 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
446 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
449 /* rate_idx: index of data rate into band's
450 * supported rates or MCS index if HT rates
451 * are use (RX_FLAG_HT)
452 * Notice: this is diff with windows define
454 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
455 false, status
->rate
);
457 rx_status
->mactime
= status
->timestamp_low
;
458 if (phystatus
== true) {
459 p_drvinfo
= (struct rx_fwinfo_88e
*)(skb
->data
+
460 status
->rx_bufshift
);
462 _rtl88ee_translate_rx_signal_stuff(hw
,
466 rx_status
->signal
= status
->recvsignalpower
+ 10;
467 if (status
->packet_report_type
== TX_REPORT2
) {
468 status
->macid_valid_entry
[0] =
469 get_rx_rpt2_desc_macid_valid_1(pdesc
);
470 status
->macid_valid_entry
[1] =
471 get_rx_rpt2_desc_macid_valid_2(pdesc
);
476 void rtl88ee_tx_fill_desc(struct ieee80211_hw
*hw
,
477 struct ieee80211_hdr
*hdr
, u8
*pdesc8
,
478 u8
*txbd
, struct ieee80211_tx_info
*info
,
479 struct ieee80211_sta
*sta
,
481 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
484 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
485 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
486 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
487 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
489 __le16 fc
= hdr
->frame_control
;
490 unsigned int buf_len
= 0;
491 unsigned int skb_len
= skb
->len
;
492 u8 fw_qsel
= _rtl88ee_map_hwqueue_to_fwqueue(skb
, hw_queue
);
493 bool firstseg
= ((hdr
->seq_ctrl
&
494 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
495 bool lastseg
= ((hdr
->frame_control
&
496 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
500 __le32
*pdesc
= (u32
*)pdesc8
;
502 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
504 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
505 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
507 bw_40
= sta
->ht_cap
.cap
&
508 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
510 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
511 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
512 /* reserve 8 byte for AMPDU early mode */
513 if (rtlhal
->earlymode_enable
) {
514 skb_push(skb
, EM_HDR_LEN
);
515 memset(skb
->data
, 0, EM_HDR_LEN
);
518 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
520 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
521 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
522 "DMA mapping error\n");
525 clear_pci_tx_desc_content(pdesc
, sizeof(struct tx_desc_88e
));
526 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
531 if (rtlhal
->earlymode_enable
) {
532 set_tx_desc_pkt_offset(pdesc
, 1);
533 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
+
535 if (ptcb_desc
->empkt_num
) {
536 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
537 "Insert 8 byte.pTcb->EMPktNum:%d\n",
538 ptcb_desc
->empkt_num
);
539 rtl88ee_insert_emcontent(ptcb_desc
,
540 (__le32
*)(skb
->data
));
543 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
546 ptcb_desc
->use_driver_rate
= true;
547 set_tx_desc_tx_rate(pdesc
, ptcb_desc
->hw_rate
);
548 if (ptcb_desc
->hw_rate
> DESC92C_RATEMCS0
)
549 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
551 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
553 set_tx_desc_data_shortgi(pdesc
, short_gi
);
555 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
556 set_tx_desc_agg_enable(pdesc
, 1);
557 set_tx_desc_max_agg_num(pdesc
, 0x14);
559 set_tx_desc_seq(pdesc
, seq_number
);
560 set_tx_desc_rts_enable(pdesc
, ((ptcb_desc
->rts_enable
&&
561 !ptcb_desc
->cts_enable
) ? 1 : 0));
562 set_tx_desc_hw_rts_enable(pdesc
, 0);
563 set_tx_desc_cts2self(pdesc
, ((ptcb_desc
->cts_enable
) ? 1 : 0));
564 set_tx_desc_rts_stbc(pdesc
, ((ptcb_desc
->rts_stbc
) ? 1 : 0));
566 set_tx_desc_rts_rate(pdesc
, ptcb_desc
->rts_rate
);
567 set_tx_desc_rts_bw(pdesc
, 0);
568 set_tx_desc_rts_sc(pdesc
, ptcb_desc
->rts_sc
);
569 set_tx_desc_rts_short(pdesc
,
570 ((ptcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
571 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
572 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
574 if (ptcb_desc
->tx_enable_sw_calc_duration
)
575 set_tx_desc_nav_use_hdr(pdesc
, 1);
578 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
579 set_tx_desc_data_bw(pdesc
, 1);
580 set_tx_desc_tx_sub_carrier(pdesc
, 3);
582 set_tx_desc_data_bw(pdesc
, 0);
583 set_tx_desc_tx_sub_carrier(pdesc
,
584 mac
->cur_40_prime_sc
);
587 set_tx_desc_data_bw(pdesc
, 0);
588 set_tx_desc_tx_sub_carrier(pdesc
, 0);
591 set_tx_desc_linip(pdesc
, 0);
592 set_tx_desc_pkt_size(pdesc
, (u16
)skb_len
);
594 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
595 set_tx_desc_ampdu_density(pdesc
, ampdu_density
);
597 if (info
->control
.hw_key
) {
598 struct ieee80211_key_conf
*keyconf
;
600 keyconf
= info
->control
.hw_key
;
601 switch (keyconf
->cipher
) {
602 case WLAN_CIPHER_SUITE_WEP40
:
603 case WLAN_CIPHER_SUITE_WEP104
:
604 case WLAN_CIPHER_SUITE_TKIP
:
605 set_tx_desc_sec_type(pdesc
, 0x1);
607 case WLAN_CIPHER_SUITE_CCMP
:
608 set_tx_desc_sec_type(pdesc
, 0x3);
611 set_tx_desc_sec_type(pdesc
, 0x0);
617 set_tx_desc_queue_sel(pdesc
, fw_qsel
);
618 set_tx_desc_data_rate_fb_limit(pdesc
, 0x1F);
619 set_tx_desc_rts_rate_fb_limit(pdesc
, 0xF);
620 set_tx_desc_disable_fb(pdesc
, ptcb_desc
->disable_ratefallback
?
622 set_tx_desc_use_rate(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
624 /*set_tx_desc_pwr_status(pdesc, pwr_status);*/
625 /* Set TxRate and RTSRate in TxDesc */
626 /* This prevent Tx initial rate of new-coming packets */
627 /* from being overwritten by retried packet rate.*/
628 if (!ptcb_desc
->use_driver_rate
) {
629 /*set_tx_desc_rts_rate(pdesc, 0x08); */
630 /* set_tx_desc_tx_rate(pdesc, 0x0b); */
632 if (ieee80211_is_data_qos(fc
)) {
634 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
635 "Enable RDG function.\n");
636 set_tx_desc_rdg_enable(pdesc
, 1);
637 set_tx_desc_htc(pdesc
, 1);
642 set_tx_desc_first_seg(pdesc
, (firstseg
? 1 : 0));
643 set_tx_desc_last_seg(pdesc
, (lastseg
? 1 : 0));
644 set_tx_desc_tx_buffer_size(pdesc
, (u16
)buf_len
);
645 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
646 if (rtlpriv
->dm
.useramask
) {
647 set_tx_desc_rate_id(pdesc
, ptcb_desc
->ratr_index
);
648 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
650 set_tx_desc_rate_id(pdesc
, 0xC + ptcb_desc
->ratr_index
);
651 set_tx_desc_macid(pdesc
, ptcb_desc
->ratr_index
);
653 if (ieee80211_is_data_qos(fc
))
654 set_tx_desc_qos(pdesc
, 1);
656 if (!ieee80211_is_data_qos(fc
))
657 set_tx_desc_hwseq_en(pdesc
, 1);
658 set_tx_desc_more_frag(pdesc
, (lastseg
? 0 : 1));
659 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
660 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
661 set_tx_desc_bmc(pdesc
, 1);
664 rtl88e_dm_set_tx_ant_by_tx_info(hw
, pdesc8
, ptcb_desc
->mac_id
);
665 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
668 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
669 u8
*pdesc8
, bool firstseg
,
670 bool lastseg
, struct sk_buff
*skb
)
672 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
673 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
674 u8 fw_queue
= QSLT_BEACON
;
675 __le32
*pdesc
= (__le32
*)pdesc8
;
677 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
681 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)(skb
->data
);
682 __le16 fc
= hdr
->frame_control
;
684 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
685 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
686 "DMA mapping error\n");
689 clear_pci_tx_desc_content(pdesc
, TX_DESC_SIZE
);
692 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
694 set_tx_desc_tx_rate(pdesc
, DESC92C_RATE1M
);
696 set_tx_desc_seq(pdesc
, 0);
698 set_tx_desc_linip(pdesc
, 0);
700 set_tx_desc_queue_sel(pdesc
, fw_queue
);
702 set_tx_desc_first_seg(pdesc
, 1);
703 set_tx_desc_last_seg(pdesc
, 1);
705 set_tx_desc_tx_buffer_size(pdesc
, (u16
)(skb
->len
));
707 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
709 set_tx_desc_rate_id(pdesc
, 7);
710 set_tx_desc_macid(pdesc
, 0);
712 set_tx_desc_own(pdesc
, 1);
714 set_tx_desc_pkt_size(pdesc
, (u16
)(skb
->len
));
716 set_tx_desc_first_seg(pdesc
, 1);
717 set_tx_desc_last_seg(pdesc
, 1);
719 set_tx_desc_offset(pdesc
, 0x20);
721 set_tx_desc_use_rate(pdesc
, 1);
723 if (!ieee80211_is_data_qos(fc
))
724 set_tx_desc_hwseq_en(pdesc
, 1);
726 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
727 "H2C Tx Cmd Content\n",
728 pdesc
, TX_DESC_SIZE
);
731 void rtl88ee_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc8
,
732 bool istx
, u8 desc_name
, u8
*val
)
734 __le32
*pdesc
= (__le32
*)pdesc8
;
739 set_tx_desc_own(pdesc
, 1);
741 case HW_DESC_TX_NEXTDESC_ADDR
:
742 set_tx_desc_next_desc_address(pdesc
, *(u32
*)val
);
745 WARN_ONCE(true, "rtl8188ee: ERR txdesc :%d not processed\n",
752 set_rx_desc_own(pdesc
, 1);
754 case HW_DESC_RXBUFF_ADDR
:
755 set_rx_desc_buff_addr(pdesc
, *(u32
*)val
);
757 case HW_DESC_RXPKT_LEN
:
758 set_rx_desc_pkt_len(pdesc
, *(u32
*)val
);
761 set_rx_desc_eor(pdesc
, 1);
764 WARN_ONCE(true, "rtl8188ee: ERR rxdesc :%d not processed\n",
771 u64
rtl88ee_get_desc(struct ieee80211_hw
*hw
,
772 u8
*pdesc8
, bool istx
, u8 desc_name
)
775 __le32
*pdesc
= (__le32
*)pdesc8
;
780 ret
= get_tx_desc_own(pdesc
);
782 case HW_DESC_TXBUFF_ADDR
:
783 ret
= get_tx_desc_tx_buffer_address(pdesc
);
786 WARN_ONCE(true, "rtl8188ee: ERR txdesc :%d not processed\n",
793 ret
= get_rx_desc_own(pdesc
);
795 case HW_DESC_RXPKT_LEN
:
796 ret
= get_rx_desc_pkt_len(pdesc
);
798 case HW_DESC_RXBUFF_ADDR
:
799 ret
= get_rx_desc_buff_addr(pdesc
);
802 WARN_ONCE(true, "rtl8188ee: ERR rxdesc :%d not processed\n",
810 bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw
*hw
, u8 hw_queue
, u16 index
)
812 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
813 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
814 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
815 u8 own
= (u8
)rtl88ee_get_desc(hw
, entry
, true, HW_DESC_OWN
);
817 /*beacon packet will only use the first
818 *descriptor defautly,and the own may not
819 *be cleared by the hardware
826 void rtl88ee_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
828 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
829 if (hw_queue
== BEACON_QUEUE
) {
830 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
832 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
833 BIT(0) << (hw_queue
));