1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
39 static u8
_rtl92ce_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
))
51 static int _rtl92ce_rate_mapping(bool isht
, u8 desc_rate
, bool first_ampdu
)
64 case DESC92C_RATE5_5M
:
112 case DESC92C_RATE5_5M
:
115 case DESC92C_RATE11M
:
124 case DESC92C_RATE12M
:
127 case DESC92C_RATE18M
:
130 case DESC92C_RATE24M
:
133 case DESC92C_RATE36M
:
136 case DESC92C_RATE48M
:
139 case DESC92C_RATE54M
:
149 static u8
_rtl92c_query_rxpwrpercentage(char antpower
)
151 if ((antpower
<= -100) || (antpower
>= 20))
153 else if (antpower
>= 0)
156 return 100 + antpower
;
159 static u8
_rtl92c_evm_db_to_percentage(char value
)
170 ret_val
= 0 - ret_val
;
179 static long _rtl92ce_translate_todbm(struct ieee80211_hw
*hw
,
180 u8 signal_strength_index
)
184 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
189 static long _rtl92ce_signal_scale_mapping(struct ieee80211_hw
*hw
,
194 if (currsig
>= 61 && currsig
<= 100)
195 retsig
= 90 + ((currsig
- 60) / 4);
196 else if (currsig
>= 41 && currsig
<= 60)
197 retsig
= 78 + ((currsig
- 40) / 2);
198 else if (currsig
>= 31 && currsig
<= 40)
199 retsig
= 66 + (currsig
- 30);
200 else if (currsig
>= 21 && currsig
<= 30)
201 retsig
= 54 + (currsig
- 20);
202 else if (currsig
>= 5 && currsig
<= 20)
203 retsig
= 42 + (((currsig
- 5) * 2) / 3);
204 else if (currsig
== 4)
206 else if (currsig
== 3)
208 else if (currsig
== 2)
210 else if (currsig
== 1)
218 static void _rtl92ce_query_rxphystatus(struct ieee80211_hw
*hw
,
219 struct rtl_stats
*pstats
,
220 struct rx_desc_92c
*pdesc
,
221 struct rx_fwinfo_92c
*p_drvinfo
,
222 bool packet_match_bssid
,
226 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
227 struct phy_sts_cck_8192s_t
*cck_buf
;
228 s8 rx_pwr_all
= 0, rx_pwr
[4];
229 u8 evm
, pwdb_all
, rf_rx_num
= 0;
230 u8 i
, max_spatial_stream
;
231 u32 rssi
, total_rssi
= 0;
232 bool in_powersavemode
= false;
235 is_cck_rate
= RX_HAL_IS_CCK_RATE(pdesc
);
236 pstats
->packet_matchbssid
= packet_match_bssid
;
237 pstats
->packet_toself
= packet_toself
;
238 pstats
->is_cck
= is_cck_rate
;
239 pstats
->packet_beacon
= packet_beacon
;
240 pstats
->is_cck
= is_cck_rate
;
241 pstats
->rx_mimo_signalquality
[0] = -1;
242 pstats
->rx_mimo_signalquality
[1] = -1;
245 u8 report
, cck_highpwr
;
246 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
248 if (!in_powersavemode
)
249 cck_highpwr
= (u8
) rtl_get_bbreg(hw
,
250 RFPGA0_XA_HSSIPARAMETER2
,
256 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
257 report
= cck_buf
->cck_agc_rpt
& 0xc0;
258 report
= report
>> 6;
261 rx_pwr_all
= -46 - (cck_agc_rpt
& 0x3e);
264 rx_pwr_all
= -26 - (cck_agc_rpt
& 0x3e);
267 rx_pwr_all
= -12 - (cck_agc_rpt
& 0x3e);
270 rx_pwr_all
= 16 - (cck_agc_rpt
& 0x3e);
274 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
275 report
= p_drvinfo
->cfosho
[0] & 0x60;
276 report
= report
>> 5;
279 rx_pwr_all
= -46 - ((cck_agc_rpt
& 0x1f) << 1);
282 rx_pwr_all
= -26 - ((cck_agc_rpt
& 0x1f) << 1);
285 rx_pwr_all
= -12 - ((cck_agc_rpt
& 0x1f) << 1);
288 rx_pwr_all
= 16 - ((cck_agc_rpt
& 0x1f) << 1);
293 pwdb_all
= _rtl92c_query_rxpwrpercentage(rx_pwr_all
);
294 pstats
->rx_pwdb_all
= pwdb_all
;
295 pstats
->recvsignalpower
= rx_pwr_all
;
297 if (packet_match_bssid
) {
299 if (pstats
->rx_pwdb_all
> 40)
302 sq
= cck_buf
->sq_rpt
;
308 sq
= ((64 - sq
) * 100) / 44;
311 pstats
->signalquality
= sq
;
312 pstats
->rx_mimo_signalquality
[0] = sq
;
313 pstats
->rx_mimo_signalquality
[1] = -1;
316 rtlpriv
->dm
.rfpath_rxenable
[0] =
317 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
318 for (i
= RF90_PATH_A
; i
< RF90_PATH_MAX
; i
++) {
319 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
323 ((p_drvinfo
->gain_trsw
[i
] & 0x3f) * 2) - 110;
324 rssi
= _rtl92c_query_rxpwrpercentage(rx_pwr
[i
]);
326 rtlpriv
->stats
.rx_snr_db
[i
] =
327 (long)(p_drvinfo
->rxsnr
[i
] / 2);
329 if (packet_match_bssid
)
330 pstats
->rx_mimo_signalstrength
[i
] = (u8
) rssi
;
333 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
334 pwdb_all
= _rtl92c_query_rxpwrpercentage(rx_pwr_all
);
335 pstats
->rx_pwdb_all
= pwdb_all
;
336 pstats
->rxpower
= rx_pwr_all
;
337 pstats
->recvsignalpower
= rx_pwr_all
;
339 if (pdesc
->rxht
&& pdesc
->rxmcs
>= DESC92C_RATEMCS8
&&
340 pdesc
->rxmcs
<= DESC92C_RATEMCS15
)
341 max_spatial_stream
= 2;
343 max_spatial_stream
= 1;
345 for (i
= 0; i
< max_spatial_stream
; i
++) {
346 evm
= _rtl92c_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
348 if (packet_match_bssid
) {
350 pstats
->signalquality
=
352 pstats
->rx_mimo_signalquality
[i
] =
359 pstats
->signalstrength
=
360 (u8
) (_rtl92ce_signal_scale_mapping(hw
, pwdb_all
));
361 else if (rf_rx_num
!= 0)
362 pstats
->signalstrength
=
363 (u8
) (_rtl92ce_signal_scale_mapping
364 (hw
, total_rssi
/= rf_rx_num
));
367 static void _rtl92ce_process_ui_rssi(struct ieee80211_hw
*hw
,
368 struct rtl_stats
*pstats
)
370 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
371 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
373 u32 last_rssi
, tmpval
;
375 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
376 rtlpriv
->stats
.rssi_calculate_cnt
++;
378 if (rtlpriv
->stats
.ui_rssi
.total_num
++ >=
379 PHY_RSSI_SLID_WIN_MAX
) {
381 rtlpriv
->stats
.ui_rssi
.total_num
=
382 PHY_RSSI_SLID_WIN_MAX
;
384 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->
385 stats
.ui_rssi
.index
];
386 rtlpriv
->stats
.ui_rssi
.total_val
-= last_rssi
;
389 rtlpriv
->stats
.ui_rssi
.total_val
+= pstats
->signalstrength
;
390 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->stats
.ui_rssi
.
392 pstats
->signalstrength
;
394 if (rtlpriv
->stats
.ui_rssi
.index
>= PHY_RSSI_SLID_WIN_MAX
)
395 rtlpriv
->stats
.ui_rssi
.index
= 0;
397 tmpval
= rtlpriv
->stats
.ui_rssi
.total_val
/
398 rtlpriv
->stats
.ui_rssi
.total_num
;
399 rtlpriv
->stats
.signal_strength
=
400 _rtl92ce_translate_todbm(hw
, (u8
) tmpval
);
401 pstats
->rssi
= rtlpriv
->stats
.signal_strength
;
404 if (!pstats
->is_cck
&& pstats
->packet_toself
) {
405 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
407 if (rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] == 0) {
408 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
409 pstats
->rx_mimo_signalstrength
[rfpath
];
413 if (pstats
->rx_mimo_signalstrength
[rfpath
] >
414 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]) {
415 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
417 rx_rssi_percentage
[rfpath
] *
418 (RX_SMOOTH_FACTOR
- 1)) +
419 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
422 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
423 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] +
426 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
428 rx_rssi_percentage
[rfpath
] *
429 (RX_SMOOTH_FACTOR
- 1)) +
430 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
438 static void _rtl92ce_update_rxsignalstatistics(struct ieee80211_hw
*hw
,
439 struct rtl_stats
*pstats
)
441 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
444 if (rtlpriv
->stats
.recv_signal_power
== 0)
445 rtlpriv
->stats
.recv_signal_power
= pstats
->recvsignalpower
;
447 if (pstats
->recvsignalpower
> rtlpriv
->stats
.recv_signal_power
)
450 else if (pstats
->recvsignalpower
< rtlpriv
->stats
.recv_signal_power
)
453 rtlpriv
->stats
.recv_signal_power
=
454 (rtlpriv
->stats
.recv_signal_power
* 5 +
455 pstats
->recvsignalpower
+ weighting
) / 6;
458 static void _rtl92ce_process_pwdb(struct ieee80211_hw
*hw
,
459 struct rtl_stats
*pstats
)
461 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
462 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
463 long undecorated_smoothed_pwdb
;
465 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
468 undecorated_smoothed_pwdb
=
469 rtlpriv
->dm
.undecorated_smoothed_pwdb
;
472 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
473 if (undecorated_smoothed_pwdb
< 0)
474 undecorated_smoothed_pwdb
= pstats
->rx_pwdb_all
;
476 if (pstats
->rx_pwdb_all
> (u32
) undecorated_smoothed_pwdb
) {
477 undecorated_smoothed_pwdb
=
478 (((undecorated_smoothed_pwdb
) *
479 (RX_SMOOTH_FACTOR
- 1)) +
480 (pstats
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
482 undecorated_smoothed_pwdb
= undecorated_smoothed_pwdb
485 undecorated_smoothed_pwdb
=
486 (((undecorated_smoothed_pwdb
) *
487 (RX_SMOOTH_FACTOR
- 1)) +
488 (pstats
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
491 rtlpriv
->dm
.undecorated_smoothed_pwdb
=
492 undecorated_smoothed_pwdb
;
493 _rtl92ce_update_rxsignalstatistics(hw
, pstats
);
497 static void _rtl92ce_process_ui_link_quality(struct ieee80211_hw
*hw
,
498 struct rtl_stats
*pstats
)
500 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
501 u32 last_evm
, n_spatialstream
, tmpval
;
503 if (pstats
->signalquality
!= 0) {
504 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
506 if (rtlpriv
->stats
.ui_link_quality
.total_num
++ >=
507 PHY_LINKQUALITY_SLID_WIN_MAX
) {
508 rtlpriv
->stats
.ui_link_quality
.total_num
=
509 PHY_LINKQUALITY_SLID_WIN_MAX
;
512 ui_link_quality
.elements
[rtlpriv
->
513 stats
.ui_link_quality
.
515 rtlpriv
->stats
.ui_link_quality
.total_val
-=
519 rtlpriv
->stats
.ui_link_quality
.total_val
+=
520 pstats
->signalquality
;
521 rtlpriv
->stats
.ui_link_quality
.elements
[rtlpriv
->stats
.
524 pstats
->signalquality
;
526 if (rtlpriv
->stats
.ui_link_quality
.index
>=
527 PHY_LINKQUALITY_SLID_WIN_MAX
)
528 rtlpriv
->stats
.ui_link_quality
.index
= 0;
530 tmpval
= rtlpriv
->stats
.ui_link_quality
.total_val
/
531 rtlpriv
->stats
.ui_link_quality
.total_num
;
532 rtlpriv
->stats
.signal_quality
= tmpval
;
534 rtlpriv
->stats
.last_sigstrength_inpercent
= tmpval
;
536 for (n_spatialstream
= 0; n_spatialstream
< 2;
539 rx_mimo_signalquality
[n_spatialstream
] !=
542 rx_evm_percentage
[n_spatialstream
]
547 pstats
->rx_mimo_signalquality
552 rx_evm_percentage
[n_spatialstream
] =
554 stats
.rx_evm_percentage
556 (RX_SMOOTH_FACTOR
- 1)) +
558 rx_mimo_signalquality
559 [n_spatialstream
] * 1)) /
569 static void _rtl92ce_process_phyinfo(struct ieee80211_hw
*hw
,
571 struct rtl_stats
*pcurrent_stats
)
574 if (!pcurrent_stats
->packet_matchbssid
&&
575 !pcurrent_stats
->packet_beacon
)
578 _rtl92ce_process_ui_rssi(hw
, pcurrent_stats
);
579 _rtl92ce_process_pwdb(hw
, pcurrent_stats
);
580 _rtl92ce_process_ui_link_quality(hw
, pcurrent_stats
);
583 static void _rtl92ce_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
585 struct rtl_stats
*pstats
,
586 struct rx_desc_92c
*pdesc
,
587 struct rx_fwinfo_92c
*p_drvinfo
)
589 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
590 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
592 struct ieee80211_hdr
*hdr
;
597 bool packet_matchbssid
, packet_toself
, packet_beacon
;
599 tmp_buf
= skb
->data
+ pstats
->rx_drvinfo_size
+ pstats
->rx_bufshift
;
601 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
602 fc
= hdr
->frame_control
;
603 c_fc
= le16_to_cpu(fc
);
604 type
= WLAN_FC_GET_TYPE(fc
);
608 ((IEEE80211_FTYPE_CTL
!= type
) &&
609 (!compare_ether_addr(mac
->bssid
,
610 (c_fc
& IEEE80211_FCTL_TODS
) ?
611 hdr
->addr1
: (c_fc
& IEEE80211_FCTL_FROMDS
) ?
612 hdr
->addr2
: hdr
->addr3
)) &&
613 (!pstats
->hwerror
) && (!pstats
->crc
) && (!pstats
->icv
));
615 packet_toself
= packet_matchbssid
&&
616 (!compare_ether_addr(praddr
, rtlefuse
->dev_addr
));
618 if (ieee80211_is_beacon(fc
))
619 packet_beacon
= true;
621 _rtl92ce_query_rxphystatus(hw
, pstats
, pdesc
, p_drvinfo
,
622 packet_matchbssid
, packet_toself
,
625 _rtl92ce_process_phyinfo(hw
, tmp_buf
, pstats
);
628 bool rtl92ce_rx_query_desc(struct ieee80211_hw
*hw
,
629 struct rtl_stats
*stats
,
630 struct ieee80211_rx_status
*rx_status
,
631 u8
*p_desc
, struct sk_buff
*skb
)
633 struct rx_fwinfo_92c
*p_drvinfo
;
634 struct rx_desc_92c
*pdesc
= (struct rx_desc_92c
*)p_desc
;
636 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
637 stats
->length
= (u16
) GET_RX_DESC_PKT_LEN(pdesc
);
638 stats
->rx_drvinfo_size
= (u8
) GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
639 RX_DRV_INFO_SIZE_UNIT
;
640 stats
->rx_bufshift
= (u8
) (GET_RX_DESC_SHIFT(pdesc
) & 0x03);
641 stats
->icv
= (u16
) GET_RX_DESC_ICV(pdesc
);
642 stats
->crc
= (u16
) GET_RX_DESC_CRC32(pdesc
);
643 stats
->hwerror
= (stats
->crc
| stats
->icv
);
644 stats
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
645 stats
->rate
= (u8
) GET_RX_DESC_RXMCS(pdesc
);
646 stats
->shortpreamble
= (u16
) GET_RX_DESC_SPLCP(pdesc
);
647 stats
->isampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
648 stats
->isampdu
= (bool) ((GET_RX_DESC_PAGGR(pdesc
) == 1)
649 && (GET_RX_DESC_FAGGR(pdesc
) == 1));
650 stats
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
651 stats
->rx_is40Mhzpacket
= (bool) GET_RX_DESC_BW(pdesc
);
653 rx_status
->freq
= hw
->conf
.channel
->center_freq
;
654 rx_status
->band
= hw
->conf
.channel
->band
;
656 if (GET_RX_DESC_CRC32(pdesc
))
657 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
659 if (!GET_RX_DESC_SWDEC(pdesc
))
660 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
662 if (GET_RX_DESC_BW(pdesc
))
663 rx_status
->flag
|= RX_FLAG_40MHZ
;
665 if (GET_RX_DESC_RXHT(pdesc
))
666 rx_status
->flag
|= RX_FLAG_HT
;
668 rx_status
->flag
|= RX_FLAG_MACTIME_MPDU
;
670 if (stats
->decrypted
)
671 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
673 rx_status
->rate_idx
= _rtl92ce_rate_mapping((bool)
674 GET_RX_DESC_RXHT(pdesc
),
676 GET_RX_DESC_RXMCS(pdesc
),
678 GET_RX_DESC_PAGGR(pdesc
));
680 rx_status
->mactime
= GET_RX_DESC_TSFL(pdesc
);
682 p_drvinfo
= (struct rx_fwinfo_92c
*)(skb
->data
+
685 _rtl92ce_translate_rx_signal_stuff(hw
,
690 /*rx_status->qual = stats->signal; */
691 rx_status
->signal
= stats
->rssi
+ 10;
692 /*rx_status->noise = -stats->noise; */
697 void rtl92ce_tx_fill_desc(struct ieee80211_hw
*hw
,
698 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
699 struct ieee80211_tx_info
*info
, struct sk_buff
*skb
,
700 u8 hw_queue
, struct rtl_tcb_desc
*tcb_desc
)
702 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
703 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
704 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
705 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
706 bool defaultadapter
= true;
707 struct ieee80211_sta
*sta
;
708 u8
*pdesc
= (u8
*) pdesc_tx
;
710 __le16 fc
= hdr
->frame_control
;
711 u8 fw_qsel
= _rtl92ce_map_hwqueue_to_fwqueue(skb
, hw_queue
);
712 bool firstseg
= ((hdr
->seq_ctrl
&
713 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
715 bool lastseg
= ((hdr
->frame_control
&
716 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
718 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
724 sta
= get_sta(hw
, mac
->vif
, mac
->bssid
);
725 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
727 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
728 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
730 bw_40
= sta
->ht_cap
.cap
&
731 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
734 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
736 rtl_get_tcb_desc(hw
, info
, sta
, skb
, tcb_desc
);
738 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_92c
));
740 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
745 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
747 SET_TX_DESC_TX_RATE(pdesc
, tcb_desc
->hw_rate
);
749 if (tcb_desc
->use_shortgi
|| tcb_desc
->use_shortpreamble
)
750 SET_TX_DESC_DATA_SHORTGI(pdesc
, 1);
752 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
753 SET_TX_DESC_AGG_BREAK(pdesc
, 1);
754 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
756 SET_TX_DESC_SEQ(pdesc
, seq_number
);
758 SET_TX_DESC_RTS_ENABLE(pdesc
, ((tcb_desc
->rts_enable
&&
760 cts_enable
) ? 1 : 0));
761 SET_TX_DESC_HW_RTS_ENABLE(pdesc
,
762 ((tcb_desc
->rts_enable
763 || tcb_desc
->cts_enable
) ? 1 : 0));
764 SET_TX_DESC_CTS2SELF(pdesc
, ((tcb_desc
->cts_enable
) ? 1 : 0));
765 SET_TX_DESC_RTS_STBC(pdesc
, ((tcb_desc
->rts_stbc
) ? 1 : 0));
767 SET_TX_DESC_RTS_RATE(pdesc
, tcb_desc
->rts_rate
);
768 SET_TX_DESC_RTS_BW(pdesc
, 0);
769 SET_TX_DESC_RTS_SC(pdesc
, tcb_desc
->rts_sc
);
770 SET_TX_DESC_RTS_SHORT(pdesc
,
771 ((tcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
772 (tcb_desc
->rts_use_shortpreamble
? 1 : 0)
773 : (tcb_desc
->rts_use_shortgi
? 1 : 0)));
776 if (tcb_desc
->packet_bw
) {
777 SET_TX_DESC_DATA_BW(pdesc
, 1);
778 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
780 SET_TX_DESC_DATA_BW(pdesc
, 0);
781 SET_TX_DESC_TX_SUB_CARRIER(pdesc
,
782 mac
->cur_40_prime_sc
);
785 SET_TX_DESC_DATA_BW(pdesc
, 0);
786 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
789 SET_TX_DESC_LINIP(pdesc
, 0);
790 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb
->len
);
793 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
794 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
797 if (info
->control
.hw_key
) {
798 struct ieee80211_key_conf
*keyconf
=
799 info
->control
.hw_key
;
801 switch (keyconf
->cipher
) {
802 case WLAN_CIPHER_SUITE_WEP40
:
803 case WLAN_CIPHER_SUITE_WEP104
:
804 case WLAN_CIPHER_SUITE_TKIP
:
805 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
807 case WLAN_CIPHER_SUITE_CCMP
:
808 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
811 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
817 SET_TX_DESC_PKT_ID(pdesc
, 0);
818 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
820 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
821 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
822 SET_TX_DESC_DISABLE_FB(pdesc
, 0);
823 SET_TX_DESC_USE_RATE(pdesc
, tcb_desc
->use_driver_rate
? 1 : 0);
825 if (ieee80211_is_data_qos(fc
)) {
827 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
828 ("Enable RDG function.\n"));
829 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
830 SET_TX_DESC_HTC(pdesc
, 1);
836 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
837 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
839 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) skb
->len
);
841 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
843 if (rtlpriv
->dm
.useramask
) {
844 SET_TX_DESC_RATE_ID(pdesc
, tcb_desc
->ratr_index
);
845 SET_TX_DESC_MACID(pdesc
, tcb_desc
->mac_id
);
847 SET_TX_DESC_RATE_ID(pdesc
, 0xC + tcb_desc
->ratr_index
);
848 SET_TX_DESC_MACID(pdesc
, tcb_desc
->ratr_index
);
851 if ((!ieee80211_is_data_qos(fc
)) && ppsc
->fwctrl_lps
) {
852 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
853 SET_TX_DESC_PKT_ID(pdesc
, 8);
856 SET_TX_DESC_QOS(pdesc
, 1);
859 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
861 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
862 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
863 SET_TX_DESC_BMC(pdesc
, 1);
866 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, ("\n"));
869 void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
870 u8
*pdesc
, bool firstseg
,
871 bool lastseg
, struct sk_buff
*skb
)
873 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
874 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
875 u8 fw_queue
= QSLT_BEACON
;
877 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
881 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)(skb
->data
);
882 __le16 fc
= hdr
->frame_control
;
884 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
887 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
889 SET_TX_DESC_TX_RATE(pdesc
, DESC92C_RATE1M
);
891 SET_TX_DESC_SEQ(pdesc
, 0);
893 SET_TX_DESC_LINIP(pdesc
, 0);
895 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
897 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
898 SET_TX_DESC_LAST_SEG(pdesc
, 1);
900 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) (skb
->len
));
902 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
904 SET_TX_DESC_RATE_ID(pdesc
, 7);
905 SET_TX_DESC_MACID(pdesc
, 0);
907 SET_TX_DESC_OWN(pdesc
, 1);
909 SET_TX_DESC_PKT_SIZE((u8
*) pdesc
, (u16
) (skb
->len
));
911 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
912 SET_TX_DESC_LAST_SEG(pdesc
, 1);
914 SET_TX_DESC_OFFSET(pdesc
, 0x20);
916 SET_TX_DESC_USE_RATE(pdesc
, 1);
918 if (!ieee80211_is_data_qos(fc
)) {
919 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
920 SET_TX_DESC_PKT_ID(pdesc
, 8);
923 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
924 "H2C Tx Cmd Content\n",
925 pdesc
, TX_DESC_SIZE
);
928 void rtl92ce_set_desc(u8
*pdesc
, bool istx
, u8 desc_name
, u8
*val
)
934 SET_TX_DESC_OWN(pdesc
, 1);
936 case HW_DESC_TX_NEXTDESC_ADDR
:
937 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*) val
);
940 RT_ASSERT(false, ("ERR txdesc :%d"
941 " not process\n", desc_name
));
948 SET_RX_DESC_OWN(pdesc
, 1);
950 case HW_DESC_RXBUFF_ADDR
:
951 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*) val
);
953 case HW_DESC_RXPKT_LEN
:
954 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*) val
);
957 SET_RX_DESC_EOR(pdesc
, 1);
960 RT_ASSERT(false, ("ERR rxdesc :%d "
961 "not process\n", desc_name
));
967 u32
rtl92ce_get_desc(u8
*p_desc
, bool istx
, u8 desc_name
)
974 ret
= GET_TX_DESC_OWN(p_desc
);
976 case HW_DESC_TXBUFF_ADDR
:
977 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(p_desc
);
980 RT_ASSERT(false, ("ERR txdesc :%d "
981 "not process\n", desc_name
));
985 struct rx_desc_92c
*pdesc
= (struct rx_desc_92c
*)p_desc
;
988 ret
= GET_RX_DESC_OWN(pdesc
);
990 case HW_DESC_RXPKT_LEN
:
991 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
994 RT_ASSERT(false, ("ERR rxdesc :%d "
995 "not process\n", desc_name
));
1002 void rtl92ce_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
1004 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1005 if (hw_queue
== BEACON_QUEUE
) {
1006 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
1008 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
1009 BIT(0) << (hw_queue
));