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 u8
_rtl92c_query_rxpwrpercentage(char antpower
)
53 if ((antpower
<= -100) || (antpower
>= 20))
55 else if (antpower
>= 0)
58 return 100 + antpower
;
61 static u8
_rtl92c_evm_db_to_percentage(char value
)
72 ret_val
= 0 - ret_val
;
81 static long _rtl92ce_translate_todbm(struct ieee80211_hw
*hw
,
82 u8 signal_strength_index
)
86 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
91 static long _rtl92ce_signal_scale_mapping(struct ieee80211_hw
*hw
,
96 if (currsig
>= 61 && currsig
<= 100)
97 retsig
= 90 + ((currsig
- 60) / 4);
98 else if (currsig
>= 41 && currsig
<= 60)
99 retsig
= 78 + ((currsig
- 40) / 2);
100 else if (currsig
>= 31 && currsig
<= 40)
101 retsig
= 66 + (currsig
- 30);
102 else if (currsig
>= 21 && currsig
<= 30)
103 retsig
= 54 + (currsig
- 20);
104 else if (currsig
>= 5 && currsig
<= 20)
105 retsig
= 42 + (((currsig
- 5) * 2) / 3);
106 else if (currsig
== 4)
108 else if (currsig
== 3)
110 else if (currsig
== 2)
112 else if (currsig
== 1)
120 static void _rtl92ce_query_rxphystatus(struct ieee80211_hw
*hw
,
121 struct rtl_stats
*pstats
,
122 struct rx_desc_92c
*pdesc
,
123 struct rx_fwinfo_92c
*p_drvinfo
,
124 bool packet_match_bssid
,
128 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
129 struct phy_sts_cck_8192s_t
*cck_buf
;
130 s8 rx_pwr_all
= 0, rx_pwr
[4];
131 u8 evm
, pwdb_all
, rf_rx_num
= 0;
132 u8 i
, max_spatial_stream
;
133 u32 rssi
, total_rssi
= 0;
134 bool in_powersavemode
= false;
137 is_cck_rate
= RX_HAL_IS_CCK_RATE(pdesc
);
138 pstats
->packet_matchbssid
= packet_match_bssid
;
139 pstats
->packet_toself
= packet_toself
;
140 pstats
->is_cck
= is_cck_rate
;
141 pstats
->packet_beacon
= packet_beacon
;
142 pstats
->is_cck
= is_cck_rate
;
143 pstats
->rx_mimo_signalquality
[0] = -1;
144 pstats
->rx_mimo_signalquality
[1] = -1;
147 u8 report
, cck_highpwr
;
148 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
150 if (!in_powersavemode
)
151 cck_highpwr
= (u8
) rtl_get_bbreg(hw
,
152 RFPGA0_XA_HSSIPARAMETER2
,
158 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
159 report
= cck_buf
->cck_agc_rpt
& 0xc0;
160 report
= report
>> 6;
163 rx_pwr_all
= -46 - (cck_agc_rpt
& 0x3e);
166 rx_pwr_all
= -26 - (cck_agc_rpt
& 0x3e);
169 rx_pwr_all
= -12 - (cck_agc_rpt
& 0x3e);
172 rx_pwr_all
= 16 - (cck_agc_rpt
& 0x3e);
176 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
177 report
= p_drvinfo
->cfosho
[0] & 0x60;
178 report
= report
>> 5;
181 rx_pwr_all
= -46 - ((cck_agc_rpt
& 0x1f) << 1);
184 rx_pwr_all
= -26 - ((cck_agc_rpt
& 0x1f) << 1);
187 rx_pwr_all
= -12 - ((cck_agc_rpt
& 0x1f) << 1);
190 rx_pwr_all
= 16 - ((cck_agc_rpt
& 0x1f) << 1);
195 pwdb_all
= _rtl92c_query_rxpwrpercentage(rx_pwr_all
);
196 pstats
->rx_pwdb_all
= pwdb_all
;
197 pstats
->recvsignalpower
= rx_pwr_all
;
199 if (packet_match_bssid
) {
201 if (pstats
->rx_pwdb_all
> 40)
204 sq
= cck_buf
->sq_rpt
;
210 sq
= ((64 - sq
) * 100) / 44;
213 pstats
->signalquality
= sq
;
214 pstats
->rx_mimo_signalquality
[0] = sq
;
215 pstats
->rx_mimo_signalquality
[1] = -1;
218 rtlpriv
->dm
.rfpath_rxenable
[0] =
219 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
220 for (i
= RF90_PATH_A
; i
< RF90_PATH_MAX
; i
++) {
221 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
225 ((p_drvinfo
->gain_trsw
[i
] & 0x3f) * 2) - 110;
226 rssi
= _rtl92c_query_rxpwrpercentage(rx_pwr
[i
]);
228 rtlpriv
->stats
.rx_snr_db
[i
] =
229 (long)(p_drvinfo
->rxsnr
[i
] / 2);
231 if (packet_match_bssid
)
232 pstats
->rx_mimo_signalstrength
[i
] = (u8
) rssi
;
235 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
236 pwdb_all
= _rtl92c_query_rxpwrpercentage(rx_pwr_all
);
237 pstats
->rx_pwdb_all
= pwdb_all
;
238 pstats
->rxpower
= rx_pwr_all
;
239 pstats
->recvsignalpower
= rx_pwr_all
;
241 if (pdesc
->rxht
&& pdesc
->rxmcs
>= DESC92_RATEMCS8
&&
242 pdesc
->rxmcs
<= DESC92_RATEMCS15
)
243 max_spatial_stream
= 2;
245 max_spatial_stream
= 1;
247 for (i
= 0; i
< max_spatial_stream
; i
++) {
248 evm
= _rtl92c_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
250 if (packet_match_bssid
) {
252 pstats
->signalquality
=
254 pstats
->rx_mimo_signalquality
[i
] =
261 pstats
->signalstrength
=
262 (u8
) (_rtl92ce_signal_scale_mapping(hw
, pwdb_all
));
263 else if (rf_rx_num
!= 0)
264 pstats
->signalstrength
=
265 (u8
) (_rtl92ce_signal_scale_mapping
266 (hw
, total_rssi
/= rf_rx_num
));
269 static void _rtl92ce_process_ui_rssi(struct ieee80211_hw
*hw
,
270 struct rtl_stats
*pstats
)
272 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
273 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
275 u32 last_rssi
, tmpval
;
277 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
278 rtlpriv
->stats
.rssi_calculate_cnt
++;
280 if (rtlpriv
->stats
.ui_rssi
.total_num
++ >=
281 PHY_RSSI_SLID_WIN_MAX
) {
283 rtlpriv
->stats
.ui_rssi
.total_num
=
284 PHY_RSSI_SLID_WIN_MAX
;
286 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->
287 stats
.ui_rssi
.index
];
288 rtlpriv
->stats
.ui_rssi
.total_val
-= last_rssi
;
291 rtlpriv
->stats
.ui_rssi
.total_val
+= pstats
->signalstrength
;
292 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->stats
.ui_rssi
.
294 pstats
->signalstrength
;
296 if (rtlpriv
->stats
.ui_rssi
.index
>= PHY_RSSI_SLID_WIN_MAX
)
297 rtlpriv
->stats
.ui_rssi
.index
= 0;
299 tmpval
= rtlpriv
->stats
.ui_rssi
.total_val
/
300 rtlpriv
->stats
.ui_rssi
.total_num
;
301 rtlpriv
->stats
.signal_strength
=
302 _rtl92ce_translate_todbm(hw
, (u8
) tmpval
);
303 pstats
->rssi
= rtlpriv
->stats
.signal_strength
;
306 if (!pstats
->is_cck
&& pstats
->packet_toself
) {
307 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
309 if (rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] == 0) {
310 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
311 pstats
->rx_mimo_signalstrength
[rfpath
];
315 if (pstats
->rx_mimo_signalstrength
[rfpath
] >
316 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]) {
317 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
319 rx_rssi_percentage
[rfpath
] *
320 (RX_SMOOTH_FACTOR
- 1)) +
321 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
324 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
325 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] +
328 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
330 rx_rssi_percentage
[rfpath
] *
331 (RX_SMOOTH_FACTOR
- 1)) +
332 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
340 static void _rtl92ce_update_rxsignalstatistics(struct ieee80211_hw
*hw
,
341 struct rtl_stats
*pstats
)
343 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
346 if (rtlpriv
->stats
.recv_signal_power
== 0)
347 rtlpriv
->stats
.recv_signal_power
= pstats
->recvsignalpower
;
349 if (pstats
->recvsignalpower
> rtlpriv
->stats
.recv_signal_power
)
352 else if (pstats
->recvsignalpower
< rtlpriv
->stats
.recv_signal_power
)
355 rtlpriv
->stats
.recv_signal_power
=
356 (rtlpriv
->stats
.recv_signal_power
* 5 +
357 pstats
->recvsignalpower
+ weighting
) / 6;
360 static void _rtl92ce_process_pwdb(struct ieee80211_hw
*hw
,
361 struct rtl_stats
*pstats
)
363 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
364 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
365 long undecorated_smoothed_pwdb
;
367 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
370 undecorated_smoothed_pwdb
=
371 rtlpriv
->dm
.undecorated_smoothed_pwdb
;
374 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
375 if (undecorated_smoothed_pwdb
< 0)
376 undecorated_smoothed_pwdb
= pstats
->rx_pwdb_all
;
378 if (pstats
->rx_pwdb_all
> (u32
) undecorated_smoothed_pwdb
) {
379 undecorated_smoothed_pwdb
=
380 (((undecorated_smoothed_pwdb
) *
381 (RX_SMOOTH_FACTOR
- 1)) +
382 (pstats
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
384 undecorated_smoothed_pwdb
= undecorated_smoothed_pwdb
387 undecorated_smoothed_pwdb
=
388 (((undecorated_smoothed_pwdb
) *
389 (RX_SMOOTH_FACTOR
- 1)) +
390 (pstats
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
393 rtlpriv
->dm
.undecorated_smoothed_pwdb
=
394 undecorated_smoothed_pwdb
;
395 _rtl92ce_update_rxsignalstatistics(hw
, pstats
);
399 static void _rtl92ce_process_ui_link_quality(struct ieee80211_hw
*hw
,
400 struct rtl_stats
*pstats
)
402 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
403 u32 last_evm
, n_spatialstream
, tmpval
;
405 if (pstats
->signalquality
!= 0) {
406 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
408 if (rtlpriv
->stats
.ui_link_quality
.total_num
++ >=
409 PHY_LINKQUALITY_SLID_WIN_MAX
) {
410 rtlpriv
->stats
.ui_link_quality
.total_num
=
411 PHY_LINKQUALITY_SLID_WIN_MAX
;
414 ui_link_quality
.elements
[rtlpriv
->
415 stats
.ui_link_quality
.
417 rtlpriv
->stats
.ui_link_quality
.total_val
-=
421 rtlpriv
->stats
.ui_link_quality
.total_val
+=
422 pstats
->signalquality
;
423 rtlpriv
->stats
.ui_link_quality
.elements
[rtlpriv
->stats
.
426 pstats
->signalquality
;
428 if (rtlpriv
->stats
.ui_link_quality
.index
>=
429 PHY_LINKQUALITY_SLID_WIN_MAX
)
430 rtlpriv
->stats
.ui_link_quality
.index
= 0;
432 tmpval
= rtlpriv
->stats
.ui_link_quality
.total_val
/
433 rtlpriv
->stats
.ui_link_quality
.total_num
;
434 rtlpriv
->stats
.signal_quality
= tmpval
;
436 rtlpriv
->stats
.last_sigstrength_inpercent
= tmpval
;
438 for (n_spatialstream
= 0; n_spatialstream
< 2;
441 rx_mimo_signalquality
[n_spatialstream
] !=
444 rx_evm_percentage
[n_spatialstream
]
449 pstats
->rx_mimo_signalquality
454 rx_evm_percentage
[n_spatialstream
] =
456 stats
.rx_evm_percentage
458 (RX_SMOOTH_FACTOR
- 1)) +
460 rx_mimo_signalquality
461 [n_spatialstream
] * 1)) /
471 static void _rtl92ce_process_phyinfo(struct ieee80211_hw
*hw
,
473 struct rtl_stats
*pcurrent_stats
)
476 if (!pcurrent_stats
->packet_matchbssid
&&
477 !pcurrent_stats
->packet_beacon
)
480 _rtl92ce_process_ui_rssi(hw
, pcurrent_stats
);
481 _rtl92ce_process_pwdb(hw
, pcurrent_stats
);
482 _rtl92ce_process_ui_link_quality(hw
, pcurrent_stats
);
485 static void _rtl92ce_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
487 struct rtl_stats
*pstats
,
488 struct rx_desc_92c
*pdesc
,
489 struct rx_fwinfo_92c
*p_drvinfo
)
491 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
492 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
494 struct ieee80211_hdr
*hdr
;
499 bool packet_matchbssid
, packet_toself
, packet_beacon
;
501 tmp_buf
= skb
->data
+ pstats
->rx_drvinfo_size
+ pstats
->rx_bufshift
;
503 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
504 fc
= hdr
->frame_control
;
505 c_fc
= le16_to_cpu(fc
);
506 type
= WLAN_FC_GET_TYPE(fc
);
510 ((IEEE80211_FTYPE_CTL
!= type
) &&
511 (!compare_ether_addr(mac
->bssid
,
512 (c_fc
& IEEE80211_FCTL_TODS
) ?
513 hdr
->addr1
: (c_fc
& IEEE80211_FCTL_FROMDS
) ?
514 hdr
->addr2
: hdr
->addr3
)) &&
515 (!pstats
->hwerror
) && (!pstats
->crc
) && (!pstats
->icv
));
517 packet_toself
= packet_matchbssid
&&
518 (!compare_ether_addr(praddr
, rtlefuse
->dev_addr
));
520 if (ieee80211_is_beacon(fc
))
521 packet_beacon
= true;
523 _rtl92ce_query_rxphystatus(hw
, pstats
, pdesc
, p_drvinfo
,
524 packet_matchbssid
, packet_toself
,
527 _rtl92ce_process_phyinfo(hw
, tmp_buf
, pstats
);
530 bool rtl92ce_rx_query_desc(struct ieee80211_hw
*hw
,
531 struct rtl_stats
*stats
,
532 struct ieee80211_rx_status
*rx_status
,
533 u8
*p_desc
, struct sk_buff
*skb
)
535 struct rx_fwinfo_92c
*p_drvinfo
;
536 struct rx_desc_92c
*pdesc
= (struct rx_desc_92c
*)p_desc
;
538 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
539 stats
->length
= (u16
) GET_RX_DESC_PKT_LEN(pdesc
);
540 stats
->rx_drvinfo_size
= (u8
) GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
541 RX_DRV_INFO_SIZE_UNIT
;
542 stats
->rx_bufshift
= (u8
) (GET_RX_DESC_SHIFT(pdesc
) & 0x03);
543 stats
->icv
= (u16
) GET_RX_DESC_ICV(pdesc
);
544 stats
->crc
= (u16
) GET_RX_DESC_CRC32(pdesc
);
545 stats
->hwerror
= (stats
->crc
| stats
->icv
);
546 stats
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
547 stats
->rate
= (u8
) GET_RX_DESC_RXMCS(pdesc
);
548 stats
->shortpreamble
= (u16
) GET_RX_DESC_SPLCP(pdesc
);
549 stats
->isampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
550 stats
->isampdu
= (bool) ((GET_RX_DESC_PAGGR(pdesc
) == 1)
551 && (GET_RX_DESC_FAGGR(pdesc
) == 1));
552 stats
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
553 stats
->rx_is40Mhzpacket
= (bool) GET_RX_DESC_BW(pdesc
);
555 rx_status
->freq
= hw
->conf
.channel
->center_freq
;
556 rx_status
->band
= hw
->conf
.channel
->band
;
558 if (GET_RX_DESC_CRC32(pdesc
))
559 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
561 if (!GET_RX_DESC_SWDEC(pdesc
))
562 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
564 if (GET_RX_DESC_BW(pdesc
))
565 rx_status
->flag
|= RX_FLAG_40MHZ
;
567 if (GET_RX_DESC_RXHT(pdesc
))
568 rx_status
->flag
|= RX_FLAG_HT
;
570 rx_status
->flag
|= RX_FLAG_MACTIME_MPDU
;
572 if (stats
->decrypted
)
573 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
575 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
,
576 (bool)GET_RX_DESC_RXHT(pdesc
),
577 (u8
)GET_RX_DESC_RXMCS(pdesc
),
578 (bool)GET_RX_DESC_PAGGR(pdesc
));
580 rx_status
->mactime
= GET_RX_DESC_TSFL(pdesc
);
582 p_drvinfo
= (struct rx_fwinfo_92c
*)(skb
->data
+
585 _rtl92ce_translate_rx_signal_stuff(hw
,
590 /*rx_status->qual = stats->signal; */
591 rx_status
->signal
= stats
->rssi
+ 10;
592 /*rx_status->noise = -stats->noise; */
597 void rtl92ce_tx_fill_desc(struct ieee80211_hw
*hw
,
598 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
599 struct ieee80211_tx_info
*info
, struct sk_buff
*skb
,
600 u8 hw_queue
, struct rtl_tcb_desc
*tcb_desc
)
602 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
603 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
604 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
605 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
606 bool defaultadapter
= true;
607 struct ieee80211_sta
*sta
;
608 u8
*pdesc
= (u8
*) pdesc_tx
;
610 __le16 fc
= hdr
->frame_control
;
611 u8 fw_qsel
= _rtl92ce_map_hwqueue_to_fwqueue(skb
, hw_queue
);
612 bool firstseg
= ((hdr
->seq_ctrl
&
613 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
615 bool lastseg
= ((hdr
->frame_control
&
616 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
618 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
624 sta
= get_sta(hw
, mac
->vif
, mac
->bssid
);
625 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
627 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
628 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
630 bw_40
= sta
->ht_cap
.cap
&
631 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
634 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
636 rtl_get_tcb_desc(hw
, info
, sta
, skb
, tcb_desc
);
638 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_92c
));
640 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
645 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
647 SET_TX_DESC_TX_RATE(pdesc
, tcb_desc
->hw_rate
);
649 if (tcb_desc
->use_shortgi
|| tcb_desc
->use_shortpreamble
)
650 SET_TX_DESC_DATA_SHORTGI(pdesc
, 1);
652 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
653 SET_TX_DESC_AGG_BREAK(pdesc
, 1);
654 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
656 SET_TX_DESC_SEQ(pdesc
, seq_number
);
658 SET_TX_DESC_RTS_ENABLE(pdesc
, ((tcb_desc
->rts_enable
&&
660 cts_enable
) ? 1 : 0));
661 SET_TX_DESC_HW_RTS_ENABLE(pdesc
,
662 ((tcb_desc
->rts_enable
663 || tcb_desc
->cts_enable
) ? 1 : 0));
664 SET_TX_DESC_CTS2SELF(pdesc
, ((tcb_desc
->cts_enable
) ? 1 : 0));
665 SET_TX_DESC_RTS_STBC(pdesc
, ((tcb_desc
->rts_stbc
) ? 1 : 0));
667 SET_TX_DESC_RTS_RATE(pdesc
, tcb_desc
->rts_rate
);
668 SET_TX_DESC_RTS_BW(pdesc
, 0);
669 SET_TX_DESC_RTS_SC(pdesc
, tcb_desc
->rts_sc
);
670 SET_TX_DESC_RTS_SHORT(pdesc
,
671 ((tcb_desc
->rts_rate
<= DESC92_RATE54M
) ?
672 (tcb_desc
->rts_use_shortpreamble
? 1 : 0)
673 : (tcb_desc
->rts_use_shortgi
? 1 : 0)));
676 if (tcb_desc
->packet_bw
) {
677 SET_TX_DESC_DATA_BW(pdesc
, 1);
678 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
680 SET_TX_DESC_DATA_BW(pdesc
, 0);
681 SET_TX_DESC_TX_SUB_CARRIER(pdesc
,
682 mac
->cur_40_prime_sc
);
685 SET_TX_DESC_DATA_BW(pdesc
, 0);
686 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
689 SET_TX_DESC_LINIP(pdesc
, 0);
690 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb
->len
);
693 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
694 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
697 if (info
->control
.hw_key
) {
698 struct ieee80211_key_conf
*keyconf
=
699 info
->control
.hw_key
;
701 switch (keyconf
->cipher
) {
702 case WLAN_CIPHER_SUITE_WEP40
:
703 case WLAN_CIPHER_SUITE_WEP104
:
704 case WLAN_CIPHER_SUITE_TKIP
:
705 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
707 case WLAN_CIPHER_SUITE_CCMP
:
708 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
711 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
717 SET_TX_DESC_PKT_ID(pdesc
, 0);
718 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
720 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
721 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
722 SET_TX_DESC_DISABLE_FB(pdesc
, 0);
723 SET_TX_DESC_USE_RATE(pdesc
, tcb_desc
->use_driver_rate
? 1 : 0);
725 if (ieee80211_is_data_qos(fc
)) {
727 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
728 ("Enable RDG function.\n"));
729 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
730 SET_TX_DESC_HTC(pdesc
, 1);
736 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
737 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
739 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) skb
->len
);
741 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
743 if (rtlpriv
->dm
.useramask
) {
744 SET_TX_DESC_RATE_ID(pdesc
, tcb_desc
->ratr_index
);
745 SET_TX_DESC_MACID(pdesc
, tcb_desc
->mac_id
);
747 SET_TX_DESC_RATE_ID(pdesc
, 0xC + tcb_desc
->ratr_index
);
748 SET_TX_DESC_MACID(pdesc
, tcb_desc
->ratr_index
);
751 if ((!ieee80211_is_data_qos(fc
)) && ppsc
->fwctrl_lps
) {
752 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
753 SET_TX_DESC_PKT_ID(pdesc
, 8);
756 SET_TX_DESC_QOS(pdesc
, 1);
759 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
761 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
762 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
763 SET_TX_DESC_BMC(pdesc
, 1);
766 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, ("\n"));
769 void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
770 u8
*pdesc
, bool firstseg
,
771 bool lastseg
, struct sk_buff
*skb
)
773 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
774 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
775 u8 fw_queue
= QSLT_BEACON
;
777 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
781 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)(skb
->data
);
782 __le16 fc
= hdr
->frame_control
;
784 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
787 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
789 SET_TX_DESC_TX_RATE(pdesc
, DESC92_RATE1M
);
791 SET_TX_DESC_SEQ(pdesc
, 0);
793 SET_TX_DESC_LINIP(pdesc
, 0);
795 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
797 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
798 SET_TX_DESC_LAST_SEG(pdesc
, 1);
800 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) (skb
->len
));
802 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
804 SET_TX_DESC_RATE_ID(pdesc
, 7);
805 SET_TX_DESC_MACID(pdesc
, 0);
807 SET_TX_DESC_OWN(pdesc
, 1);
809 SET_TX_DESC_PKT_SIZE((u8
*) pdesc
, (u16
) (skb
->len
));
811 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
812 SET_TX_DESC_LAST_SEG(pdesc
, 1);
814 SET_TX_DESC_OFFSET(pdesc
, 0x20);
816 SET_TX_DESC_USE_RATE(pdesc
, 1);
818 if (!ieee80211_is_data_qos(fc
)) {
819 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
820 SET_TX_DESC_PKT_ID(pdesc
, 8);
823 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
824 "H2C Tx Cmd Content\n",
825 pdesc
, TX_DESC_SIZE
);
828 void rtl92ce_set_desc(u8
*pdesc
, bool istx
, u8 desc_name
, u8
*val
)
834 SET_TX_DESC_OWN(pdesc
, 1);
836 case HW_DESC_TX_NEXTDESC_ADDR
:
837 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*) val
);
840 RT_ASSERT(false, ("ERR txdesc :%d"
841 " not process\n", desc_name
));
848 SET_RX_DESC_OWN(pdesc
, 1);
850 case HW_DESC_RXBUFF_ADDR
:
851 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*) val
);
853 case HW_DESC_RXPKT_LEN
:
854 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*) val
);
857 SET_RX_DESC_EOR(pdesc
, 1);
860 RT_ASSERT(false, ("ERR rxdesc :%d "
861 "not process\n", desc_name
));
867 u32
rtl92ce_get_desc(u8
*p_desc
, bool istx
, u8 desc_name
)
874 ret
= GET_TX_DESC_OWN(p_desc
);
876 case HW_DESC_TXBUFF_ADDR
:
877 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(p_desc
);
880 RT_ASSERT(false, ("ERR txdesc :%d "
881 "not process\n", desc_name
));
885 struct rx_desc_92c
*pdesc
= (struct rx_desc_92c
*)p_desc
;
888 ret
= GET_RX_DESC_OWN(pdesc
);
890 case HW_DESC_RXPKT_LEN
:
891 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
894 RT_ASSERT(false, ("ERR rxdesc :%d "
895 "not process\n", desc_name
));
902 void rtl92ce_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
904 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
905 if (hw_queue
== BEACON_QUEUE
) {
906 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
908 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
909 BIT(0) << (hw_queue
));