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 *****************************************************************************/
40 static u8
_rtl92se_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 skb_queue
)
42 __le16 fc
= rtl_get_fc(skb
);
44 if (unlikely(ieee80211_is_beacon(fc
)))
46 if (ieee80211_is_mgmt(fc
))
48 if (ieee80211_is_nullfunc(fc
))
54 static int _rtl92se_rate_mapping(bool isht
, u8 desc_rate
, bool first_ampdu
)
67 case DESC92S_RATE5_5M
:
115 case DESC92S_RATE5_5M
:
118 case DESC92S_RATE11M
:
127 case DESC92S_RATE12M
:
130 case DESC92S_RATE18M
:
133 case DESC92S_RATE24M
:
136 case DESC92S_RATE36M
:
139 case DESC92S_RATE48M
:
142 case DESC92S_RATE54M
:
152 static u8
_rtl92s_query_rxpwrpercentage(char antpower
)
154 if ((antpower
<= -100) || (antpower
>= 20))
156 else if (antpower
>= 0)
159 return 100 + antpower
;
162 static u8
_rtl92s_evm_db_to_percentage(char value
)
173 ret_val
= 0 - ret_val
;
182 static long _rtl92se_translate_todbm(struct ieee80211_hw
*hw
,
183 u8 signal_strength_index
)
187 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
192 static long _rtl92se_signal_scale_mapping(struct ieee80211_hw
*hw
,
197 /* Step 1. Scale mapping. */
200 else if (currsig
> 14 && currsig
<= 47)
201 retsig
= 100 - ((47 - currsig
) * 3) / 2;
202 else if (currsig
> 2 && currsig
<= 14)
203 retsig
= 48 - ((14 - currsig
) * 15) / 7;
204 else if (currsig
>= 0)
205 retsig
= currsig
* 9 + 1;
211 static void _rtl92se_query_rxphystatus(struct ieee80211_hw
*hw
,
212 struct rtl_stats
*pstats
, u8
*pdesc
,
213 struct rx_fwinfo
*p_drvinfo
,
214 bool packet_match_bssid
,
218 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
219 struct phy_sts_cck_8192s_t
*cck_buf
;
220 s8 rx_pwr_all
= 0, rx_pwr
[4];
221 u8 rf_rx_num
= 0, evm
, pwdb_all
;
222 u8 i
, max_spatial_stream
;
223 u32 rssi
, total_rssi
= 0;
224 bool in_powersavemode
= false;
227 is_cck_rate
= RX_HAL_IS_CCK_RATE(pdesc
);
228 pstats
->packet_matchbssid
= packet_match_bssid
;
229 pstats
->packet_toself
= packet_toself
;
230 pstats
->is_cck
= is_cck_rate
;
231 pstats
->packet_beacon
= packet_beacon
;
232 pstats
->is_cck
= is_cck_rate
;
233 pstats
->rx_mimo_signalquality
[0] = -1;
234 pstats
->rx_mimo_signalquality
[1] = -1;
237 u8 report
, cck_highpwr
;
238 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
240 if (!in_powersavemode
)
241 cck_highpwr
= (u8
) rtl_get_bbreg(hw
,
242 RFPGA0_XA_HSSIPARAMETER2
,
248 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
249 report
= cck_buf
->cck_agc_rpt
& 0xc0;
250 report
= report
>> 6;
253 rx_pwr_all
= -40 - (cck_agc_rpt
& 0x3e);
256 rx_pwr_all
= -20 - (cck_agc_rpt
& 0x3e);
259 rx_pwr_all
= -2 - (cck_agc_rpt
& 0x3e);
262 rx_pwr_all
= 14 - (cck_agc_rpt
& 0x3e);
266 u8 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
267 report
= p_drvinfo
->cfosho
[0] & 0x60;
268 report
= report
>> 5;
271 rx_pwr_all
= -40 - ((cck_agc_rpt
& 0x1f) << 1);
274 rx_pwr_all
= -20 - ((cck_agc_rpt
& 0x1f) << 1);
277 rx_pwr_all
= -2 - ((cck_agc_rpt
& 0x1f) << 1);
280 rx_pwr_all
= 14 - ((cck_agc_rpt
& 0x1f) << 1);
285 pwdb_all
= _rtl92s_query_rxpwrpercentage(rx_pwr_all
);
287 /* CCK gain is smaller than OFDM/MCS gain, */
288 /* so we add gain diff by experiences, the val is 6 */
292 /* modify the offset to make the same gain index with OFDM. */
293 if (pwdb_all
> 34 && pwdb_all
<= 42)
295 else if (pwdb_all
> 26 && pwdb_all
<= 34)
297 else if (pwdb_all
> 14 && pwdb_all
<= 26)
299 else if (pwdb_all
> 4 && pwdb_all
<= 14)
302 pstats
->rx_pwdb_all
= pwdb_all
;
303 pstats
->recvsignalpower
= rx_pwr_all
;
305 if (packet_match_bssid
) {
307 if (pstats
->rx_pwdb_all
> 40) {
310 sq
= cck_buf
->sq_rpt
;
316 sq
= ((64 - sq
) * 100) / 44;
319 pstats
->signalquality
= sq
;
320 pstats
->rx_mimo_signalquality
[0] = sq
;
321 pstats
->rx_mimo_signalquality
[1] = -1;
324 rtlpriv
->dm
.rfpath_rxenable
[0] =
325 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
326 for (i
= RF90_PATH_A
; i
< RF90_PATH_MAX
; i
++) {
327 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
330 rx_pwr
[i
] = ((p_drvinfo
->gain_trsw
[i
] &
332 rssi
= _rtl92s_query_rxpwrpercentage(rx_pwr
[i
]);
334 rtlpriv
->stats
.rx_snr_db
[i
] =
335 (long)(p_drvinfo
->rxsnr
[i
] / 2);
337 if (packet_match_bssid
)
338 pstats
->rx_mimo_signalstrength
[i
] = (u8
) rssi
;
341 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
342 pwdb_all
= _rtl92s_query_rxpwrpercentage(rx_pwr_all
);
343 pstats
->rx_pwdb_all
= pwdb_all
;
344 pstats
->rxpower
= rx_pwr_all
;
345 pstats
->recvsignalpower
= rx_pwr_all
;
347 if (GET_RX_STATUS_DESC_RX_HT(pdesc
) &&
348 GET_RX_STATUS_DESC_RX_MCS(pdesc
) >= DESC92S_RATEMCS8
&&
349 GET_RX_STATUS_DESC_RX_MCS(pdesc
) <= DESC92S_RATEMCS15
)
350 max_spatial_stream
= 2;
352 max_spatial_stream
= 1;
354 for (i
= 0; i
< max_spatial_stream
; i
++) {
355 evm
= _rtl92s_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
357 if (packet_match_bssid
) {
359 pstats
->signalquality
= (u8
)(evm
&
361 pstats
->rx_mimo_signalquality
[i
] =
368 pstats
->signalstrength
= (u8
)(_rtl92se_signal_scale_mapping(hw
,
370 else if (rf_rx_num
!= 0)
371 pstats
->signalstrength
= (u8
) (_rtl92se_signal_scale_mapping(hw
,
372 total_rssi
/= rf_rx_num
));
375 static void _rtl92se_process_ui_rssi(struct ieee80211_hw
*hw
,
376 struct rtl_stats
*pstats
)
378 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
379 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
381 u32 last_rssi
, tmpval
;
383 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
384 rtlpriv
->stats
.rssi_calculate_cnt
++;
386 if (rtlpriv
->stats
.ui_rssi
.total_num
++ >=
387 PHY_RSSI_SLID_WIN_MAX
) {
388 rtlpriv
->stats
.ui_rssi
.total_num
=
389 PHY_RSSI_SLID_WIN_MAX
;
390 last_rssi
= rtlpriv
->stats
.ui_rssi
.elements
[
391 rtlpriv
->stats
.ui_rssi
.index
];
392 rtlpriv
->stats
.ui_rssi
.total_val
-= last_rssi
;
395 rtlpriv
->stats
.ui_rssi
.total_val
+= pstats
->signalstrength
;
396 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->stats
.ui_rssi
.index
++]
397 = pstats
->signalstrength
;
399 if (rtlpriv
->stats
.ui_rssi
.index
>= PHY_RSSI_SLID_WIN_MAX
)
400 rtlpriv
->stats
.ui_rssi
.index
= 0;
402 tmpval
= rtlpriv
->stats
.ui_rssi
.total_val
/
403 rtlpriv
->stats
.ui_rssi
.total_num
;
404 rtlpriv
->stats
.signal_strength
= _rtl92se_translate_todbm(hw
,
406 pstats
->rssi
= rtlpriv
->stats
.signal_strength
;
409 if (!pstats
->is_cck
&& pstats
->packet_toself
) {
410 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
412 if (rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] == 0) {
413 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
414 pstats
->rx_mimo_signalstrength
[rfpath
];
418 if (pstats
->rx_mimo_signalstrength
[rfpath
] >
419 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]) {
420 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
421 ((rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]
422 * (RX_SMOOTH_FACTOR
- 1)) +
423 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
426 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
427 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]
430 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
431 ((rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]
432 * (RX_SMOOTH_FACTOR
- 1)) +
433 (pstats
->rx_mimo_signalstrength
[rfpath
])) /
441 static void _rtl92se_update_rxsignalstatistics(struct ieee80211_hw
*hw
,
442 struct rtl_stats
*pstats
)
444 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
447 if (rtlpriv
->stats
.recv_signal_power
== 0)
448 rtlpriv
->stats
.recv_signal_power
= pstats
->recvsignalpower
;
450 if (pstats
->recvsignalpower
> rtlpriv
->stats
.recv_signal_power
)
452 else if (pstats
->recvsignalpower
< rtlpriv
->stats
.recv_signal_power
)
455 rtlpriv
->stats
.recv_signal_power
= (rtlpriv
->stats
.recv_signal_power
* 5
456 + pstats
->recvsignalpower
+
460 static void _rtl92se_process_pwdb(struct ieee80211_hw
*hw
,
461 struct rtl_stats
*pstats
)
463 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
464 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
465 long undec_sm_pwdb
= 0;
467 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
471 rtlpriv
->dm
.undecorated_smoothed_pwdb
;
474 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
475 if (undec_sm_pwdb
< 0)
476 undec_sm_pwdb
= pstats
->rx_pwdb_all
;
478 if (pstats
->rx_pwdb_all
> (u32
) undec_sm_pwdb
) {
481 (RX_SMOOTH_FACTOR
- 1)) +
482 (pstats
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
484 undec_sm_pwdb
= undec_sm_pwdb
+ 1;
486 undec_sm_pwdb
= (((undec_sm_pwdb
) *
487 (RX_SMOOTH_FACTOR
- 1)) + (pstats
->rx_pwdb_all
)) /
491 rtlpriv
->dm
.undecorated_smoothed_pwdb
= undec_sm_pwdb
;
492 _rtl92se_update_rxsignalstatistics(hw
, pstats
);
496 static void rtl_92s_process_streams(struct ieee80211_hw
*hw
,
497 struct rtl_stats
*pstats
)
499 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
502 for (stream
= 0; stream
< 2; stream
++) {
503 if (pstats
->rx_mimo_signalquality
[stream
] != -1) {
504 if (rtlpriv
->stats
.rx_evm_percentage
[stream
] == 0) {
505 rtlpriv
->stats
.rx_evm_percentage
[stream
] =
506 pstats
->rx_mimo_signalquality
[stream
];
509 rtlpriv
->stats
.rx_evm_percentage
[stream
] =
510 ((rtlpriv
->stats
.rx_evm_percentage
[stream
] *
511 (RX_SMOOTH_FACTOR
- 1)) +
512 (pstats
->rx_mimo_signalquality
[stream
] *
513 1)) / (RX_SMOOTH_FACTOR
);
518 static void _rtl92se_process_ui_link_quality(struct ieee80211_hw
*hw
,
519 struct rtl_stats
*pstats
)
521 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
522 u32 last_evm
= 0, tmpval
;
524 if (pstats
->signalquality
!= 0) {
525 if (pstats
->packet_toself
|| pstats
->packet_beacon
) {
527 if (rtlpriv
->stats
.ui_link_quality
.total_num
++ >=
528 PHY_LINKQUALITY_SLID_WIN_MAX
) {
529 rtlpriv
->stats
.ui_link_quality
.total_num
=
530 PHY_LINKQUALITY_SLID_WIN_MAX
;
532 rtlpriv
->stats
.ui_link_quality
.elements
[
533 rtlpriv
->stats
.ui_link_quality
.index
];
534 rtlpriv
->stats
.ui_link_quality
.total_val
-=
538 rtlpriv
->stats
.ui_link_quality
.total_val
+=
539 pstats
->signalquality
;
540 rtlpriv
->stats
.ui_link_quality
.elements
[
541 rtlpriv
->stats
.ui_link_quality
.index
++] =
542 pstats
->signalquality
;
544 if (rtlpriv
->stats
.ui_link_quality
.index
>=
545 PHY_LINKQUALITY_SLID_WIN_MAX
)
546 rtlpriv
->stats
.ui_link_quality
.index
= 0;
548 tmpval
= rtlpriv
->stats
.ui_link_quality
.total_val
/
549 rtlpriv
->stats
.ui_link_quality
.total_num
;
550 rtlpriv
->stats
.signal_quality
= tmpval
;
552 rtlpriv
->stats
.last_sigstrength_inpercent
= tmpval
;
554 rtl_92s_process_streams(hw
, pstats
);
560 static void _rtl92se_process_phyinfo(struct ieee80211_hw
*hw
,
562 struct rtl_stats
*pcurrent_stats
)
565 if (!pcurrent_stats
->packet_matchbssid
&&
566 !pcurrent_stats
->packet_beacon
)
569 _rtl92se_process_ui_rssi(hw
, pcurrent_stats
);
570 _rtl92se_process_pwdb(hw
, pcurrent_stats
);
571 _rtl92se_process_ui_link_quality(hw
, pcurrent_stats
);
574 static void _rtl92se_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
575 struct sk_buff
*skb
, struct rtl_stats
*pstats
,
576 u8
*pdesc
, struct rx_fwinfo
*p_drvinfo
)
578 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
579 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
581 struct ieee80211_hdr
*hdr
;
587 bool packet_matchbssid
, packet_toself
, packet_beacon
;
589 tmp_buf
= skb
->data
+ pstats
->rx_drvinfo_size
+ pstats
->rx_bufshift
;
591 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
592 fc
= hdr
->frame_control
;
593 cfc
= le16_to_cpu(fc
);
594 type
= WLAN_FC_GET_TYPE(fc
);
598 packet_matchbssid
= ((IEEE80211_FTYPE_CTL
!= type
) &&
599 (!compare_ether_addr(mac
->bssid
, (cfc
& IEEE80211_FCTL_TODS
) ?
600 hdr
->addr1
: (cfc
& IEEE80211_FCTL_FROMDS
) ?
601 hdr
->addr2
: hdr
->addr3
)) && (!pstats
->hwerror
) &&
602 (!pstats
->crc
) && (!pstats
->icv
));
604 packet_toself
= packet_matchbssid
&&
605 (!compare_ether_addr(praddr
, rtlefuse
->dev_addr
));
607 if (ieee80211_is_beacon(fc
))
608 packet_beacon
= true;
610 _rtl92se_query_rxphystatus(hw
, pstats
, pdesc
, p_drvinfo
,
611 packet_matchbssid
, packet_toself
, packet_beacon
);
612 _rtl92se_process_phyinfo(hw
, tmp_buf
, pstats
);
615 bool rtl92se_rx_query_desc(struct ieee80211_hw
*hw
, struct rtl_stats
*stats
,
616 struct ieee80211_rx_status
*rx_status
, u8
*pdesc
,
619 struct rx_fwinfo
*p_drvinfo
;
620 u32 phystatus
= (u32
)GET_RX_STATUS_DESC_PHY_STATUS(pdesc
);
622 stats
->length
= (u16
)GET_RX_STATUS_DESC_PKT_LEN(pdesc
);
623 stats
->rx_drvinfo_size
= (u8
)GET_RX_STATUS_DESC_DRVINFO_SIZE(pdesc
) * 8;
624 stats
->rx_bufshift
= (u8
)(GET_RX_STATUS_DESC_SHIFT(pdesc
) & 0x03);
625 stats
->icv
= (u16
)GET_RX_STATUS_DESC_ICV(pdesc
);
626 stats
->crc
= (u16
)GET_RX_STATUS_DESC_CRC32(pdesc
);
627 stats
->hwerror
= (u16
)(stats
->crc
| stats
->icv
);
628 stats
->decrypted
= !GET_RX_STATUS_DESC_SWDEC(pdesc
);
630 stats
->rate
= (u8
)GET_RX_STATUS_DESC_RX_MCS(pdesc
);
631 stats
->shortpreamble
= (u16
)GET_RX_STATUS_DESC_SPLCP(pdesc
);
632 stats
->isampdu
= (bool)(GET_RX_STATUS_DESC_PAGGR(pdesc
) == 1);
633 stats
->timestamp_low
= GET_RX_STATUS_DESC_TSFL(pdesc
);
634 stats
->rx_is40Mhzpacket
= (bool)GET_RX_STATUS_DESC_BW(pdesc
);
639 rx_status
->freq
= hw
->conf
.channel
->center_freq
;
640 rx_status
->band
= hw
->conf
.channel
->band
;
642 if (GET_RX_STATUS_DESC_CRC32(pdesc
))
643 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
645 if (!GET_RX_STATUS_DESC_SWDEC(pdesc
))
646 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
648 if (GET_RX_STATUS_DESC_BW(pdesc
))
649 rx_status
->flag
|= RX_FLAG_40MHZ
;
651 if (GET_RX_STATUS_DESC_RX_HT(pdesc
))
652 rx_status
->flag
|= RX_FLAG_HT
;
654 rx_status
->flag
|= RX_FLAG_MACTIME_MPDU
;
656 if (stats
->decrypted
)
657 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
659 rx_status
->rate_idx
= _rtl92se_rate_mapping((bool)
660 GET_RX_STATUS_DESC_RX_HT(pdesc
),
661 (u8
)GET_RX_STATUS_DESC_RX_MCS(pdesc
),
662 (bool)GET_RX_STATUS_DESC_PAGGR(pdesc
));
665 rx_status
->mactime
= GET_RX_STATUS_DESC_TSFL(pdesc
);
666 if (phystatus
== true) {
667 p_drvinfo
= (struct rx_fwinfo
*)(skb
->data
+
669 _rtl92se_translate_rx_signal_stuff(hw
, skb
, stats
, pdesc
,
673 /*rx_status->qual = stats->signal; */
674 rx_status
->signal
= stats
->rssi
+ 10;
675 /*rx_status->noise = -stats->noise; */
680 void rtl92se_tx_fill_desc(struct ieee80211_hw
*hw
,
681 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
682 struct ieee80211_tx_info
*info
, struct sk_buff
*skb
,
683 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
685 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
686 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
687 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
688 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
689 struct ieee80211_sta
*sta
= info
->control
.sta
;
690 u8
*pdesc
= (u8
*) pdesc_tx
;
692 __le16 fc
= hdr
->frame_control
;
693 u8 reserved_macid
= 0;
694 u8 fw_qsel
= _rtl92se_map_hwqueue_to_fwqueue(skb
, hw_queue
);
695 bool firstseg
= (!(hdr
->seq_ctrl
& cpu_to_le16(IEEE80211_SCTL_FRAG
)));
696 bool lastseg
= (!(hdr
->frame_control
&
697 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)));
698 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
702 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
704 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
705 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
707 bw_40
= sta
->ht_cap
.cap
&
708 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
711 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
713 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
715 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE_RTL8192S
);
718 if (rtlpriv
->dm
.useramask
) {
719 /* set txdesc macId */
720 if (ptcb_desc
->mac_id
< 32) {
721 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
722 reserved_macid
|= ptcb_desc
->mac_id
;
725 SET_TX_DESC_RSVD_MACID(pdesc
, reserved_macid
);
727 SET_TX_DESC_TXHT(pdesc
, ((ptcb_desc
->hw_rate
>=
728 DESC92S_RATEMCS0
) ? 1 : 0));
730 if (rtlhal
->version
== VERSION_8192S_ACUT
) {
731 if (ptcb_desc
->hw_rate
== DESC92S_RATE1M
||
732 ptcb_desc
->hw_rate
== DESC92S_RATE2M
||
733 ptcb_desc
->hw_rate
== DESC92S_RATE5_5M
||
734 ptcb_desc
->hw_rate
== DESC92S_RATE11M
) {
735 ptcb_desc
->hw_rate
= DESC92S_RATE12M
;
739 SET_TX_DESC_TX_RATE(pdesc
, ptcb_desc
->hw_rate
);
741 if (ptcb_desc
->use_shortgi
|| ptcb_desc
->use_shortpreamble
)
742 SET_TX_DESC_TX_SHORT(pdesc
, 0);
744 /* Aggregation related */
745 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
)
746 SET_TX_DESC_AGG_ENABLE(pdesc
, 1);
748 /* For AMPDU, we must insert SSN into TX_DESC */
749 SET_TX_DESC_SEQ(pdesc
, seq_number
);
751 /* Protection mode related */
752 /* For 92S, if RTS/CTS are set, HW will execute RTS. */
753 /* We choose only one protection mode to execute */
754 SET_TX_DESC_RTS_ENABLE(pdesc
, ((ptcb_desc
->rts_enable
&&
755 !ptcb_desc
->cts_enable
) ? 1 : 0));
756 SET_TX_DESC_CTS_ENABLE(pdesc
, ((ptcb_desc
->cts_enable
) ?
758 SET_TX_DESC_RTS_STBC(pdesc
, ((ptcb_desc
->rts_stbc
) ? 1 : 0));
760 SET_TX_DESC_RTS_RATE(pdesc
, ptcb_desc
->rts_rate
);
761 SET_TX_DESC_RTS_BANDWIDTH(pdesc
, 0);
762 SET_TX_DESC_RTS_SUB_CARRIER(pdesc
, ptcb_desc
->rts_sc
);
763 SET_TX_DESC_RTS_SHORT(pdesc
, ((ptcb_desc
->rts_rate
<=
765 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0)
766 : (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
769 /* Set Bandwidth and sub-channel settings. */
771 if (ptcb_desc
->packet_bw
) {
772 SET_TX_DESC_TX_BANDWIDTH(pdesc
, 1);
773 /* use duplicated mode */
774 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
776 SET_TX_DESC_TX_BANDWIDTH(pdesc
, 0);
777 SET_TX_DESC_TX_SUB_CARRIER(pdesc
,
778 mac
->cur_40_prime_sc
);
781 SET_TX_DESC_TX_BANDWIDTH(pdesc
, 0);
782 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
785 /* 3 Fill necessary field in First Descriptor */
787 SET_TX_DESC_LINIP(pdesc
, 0);
788 SET_TX_DESC_OFFSET(pdesc
, 32);
789 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb
->len
);
792 SET_TX_DESC_RA_BRSR_ID(pdesc
, ptcb_desc
->ratr_index
);
794 /* Fill security related */
795 if (info
->control
.hw_key
) {
796 struct ieee80211_key_conf
*keyconf
;
798 keyconf
= info
->control
.hw_key
;
799 switch (keyconf
->cipher
) {
800 case WLAN_CIPHER_SUITE_WEP40
:
801 case WLAN_CIPHER_SUITE_WEP104
:
802 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
804 case WLAN_CIPHER_SUITE_TKIP
:
805 SET_TX_DESC_SEC_TYPE(pdesc
, 0x2);
807 case WLAN_CIPHER_SUITE_CCMP
:
808 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
811 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
818 SET_TX_DESC_PACKET_ID(pdesc
, 0);
820 /* We will assign magement queue to BK. */
821 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
823 /* Alwasy enable all rate fallback range */
824 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
826 /* Fix: I don't kown why hw use 6.5M to tx when set it */
827 SET_TX_DESC_USER_RATE(pdesc
,
828 ptcb_desc
->use_driver_rate
? 1 : 0);
830 /* Set NON_QOS bit. */
831 if (!ieee80211_is_data_qos(fc
))
832 SET_TX_DESC_NON_QOS(pdesc
, 1);
836 /* Fill fields that are required to be initialized
837 * in all of the descriptors */
839 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
840 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
843 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) skb
->len
);
846 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, cpu_to_le32(mapping
));
848 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, ("\n"));
851 void rtl92se_tx_fill_cmddesc(struct ieee80211_hw
*hw
, u8
*pdesc
,
852 bool firstseg
, bool lastseg
, struct sk_buff
*skb
)
854 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
855 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
856 struct rtl_tcb_desc
*tcb_desc
= (struct rtl_tcb_desc
*)(skb
->cb
);
858 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
861 /* Clear all status */
862 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_CMDDESC_SIZE_RTL8192S
);
864 /* This bit indicate this packet is used for FW download. */
865 if (tcb_desc
->cmd_or_init
== DESC_PACKET_TYPE_INIT
) {
866 /* For firmware downlaod we only need to set LINIP */
867 SET_TX_DESC_LINIP(pdesc
, tcb_desc
->last_inipkt
);
869 /* 92SE must set as 1 for firmware download HW DMA error */
870 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
871 SET_TX_DESC_LAST_SEG(pdesc
, 1);
873 /* 92SE need not to set TX packet size when firmware download */
874 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
)(skb
->len
));
875 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
876 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, cpu_to_le32(mapping
));
878 SET_TX_DESC_OWN(pdesc
, 1);
879 } else { /* H2C Command Desc format (Host TXCMD) */
880 /* 92SE must set as 1 for firmware download HW DMA error */
881 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
882 SET_TX_DESC_LAST_SEG(pdesc
, 1);
884 SET_TX_DESC_OFFSET(pdesc
, 0x20);
886 /* Buffer size + command header */
887 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
)(skb
->len
));
888 /* Fixed queue of H2C command */
889 SET_TX_DESC_QUEUE_SEL(pdesc
, 0x13);
891 SET_BITS_TO_LE_4BYTE(skb
->data
, 24, 7, rtlhal
->h2c_txcmd_seq
);
893 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
894 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, cpu_to_le32(mapping
));
896 SET_TX_DESC_OWN(pdesc
, 1);
901 void rtl92se_set_desc(u8
*pdesc
, bool istx
, u8 desc_name
, u8
*val
)
906 SET_TX_DESC_OWN(pdesc
, 1);
908 case HW_DESC_TX_NEXTDESC_ADDR
:
909 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*) val
);
912 RT_ASSERT(false, ("ERR txdesc :%d not process\n",
919 SET_RX_STATUS_DESC_OWN(pdesc
, 1);
921 case HW_DESC_RXBUFF_ADDR
:
922 SET_RX_STATUS__DESC_BUFF_ADDR(pdesc
, *(u32
*) val
);
924 case HW_DESC_RXPKT_LEN
:
925 SET_RX_STATUS_DESC_PKT_LEN(pdesc
, *(u32
*) val
);
928 SET_RX_STATUS_DESC_EOR(pdesc
, 1);
931 RT_ASSERT(false, ("ERR rxdesc :%d not process\n",
938 u32
rtl92se_get_desc(u8
*desc
, bool istx
, u8 desc_name
)
945 ret
= GET_TX_DESC_OWN(desc
);
947 case HW_DESC_TXBUFF_ADDR
:
948 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(desc
);
951 RT_ASSERT(false, ("ERR txdesc :%d not process\n",
958 ret
= GET_RX_STATUS_DESC_OWN(desc
);
960 case HW_DESC_RXPKT_LEN
:
961 ret
= GET_RX_STATUS_DESC_PKT_LEN(desc
);
964 RT_ASSERT(false, ("ERR rxdesc :%d not process\n",
972 void rtl92se_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
974 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
975 rtl_write_word(rtlpriv
, TP_POLL
, BIT(0) << (hw_queue
));