1 /******************************************************************************
3 * Copyright(c) 2009-2013 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 *****************************************************************************/
41 static u8
_rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
43 __le16 fc
= rtl_get_fc(skb
);
45 if (unlikely(ieee80211_is_beacon(fc
)))
47 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
53 static void _rtl88ee_query_rxphystatus(struct ieee80211_hw
*hw
,
54 struct rtl_stats
*pstatus
, u8
*pdesc
,
55 struct rx_fwinfo_88e
*p_drvinfo
,
56 bool bpacket_match_bssid
,
57 bool bpacket_toself
, bool packet_beacon
)
59 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
60 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
61 struct phy_sts_cck_8192s_t
*cck_buf
;
62 struct phy_status_rpt
*phystrpt
= (struct phy_status_rpt
*)p_drvinfo
;
63 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
64 char rx_pwr_all
= 0, rx_pwr
[4];
65 u8 rf_rx_num
= 0, evm
, pwdb_all
;
66 u8 i
, max_spatial_stream
;
67 u32 rssi
, total_rssi
= 0;
68 bool is_cck
= pstatus
->is_cck
;
71 /* Record it for next packet processing */
72 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
73 pstatus
->packet_toself
= bpacket_toself
;
74 pstatus
->packet_beacon
= packet_beacon
;
75 pstatus
->rx_mimo_sig_qual
[0] = -1;
76 pstatus
->rx_mimo_sig_qual
[1] = -1;
81 /* CCK Driver info Structure is not the same as OFDM packet. */
82 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
83 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
85 /* (1)Hardware does not provide RSSI for CCK
86 * (2)PWDB, Average PWDB cacluated by
87 * hardware (for rate adaptive)
89 if (ppsc
->rfpwr_state
== ERFON
)
90 cck_hipwr
= rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
,
95 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
96 vga_idx
= (cck_agc_rpt
& 0x1f);
100 rx_pwr_all
= -100 + 2 * (27 - vga_idx
);
105 rx_pwr_all
= -48 + 2 * (2 - vga_idx
); /*VGA_idx = 2~0*/
108 rx_pwr_all
= -42 + 2 * (7 - vga_idx
); /*VGA_idx = 7~5*/
111 rx_pwr_all
= -36 + 2 * (7 - vga_idx
); /*VGA_idx = 7~4*/
114 rx_pwr_all
= -24 + 2 * (7 - vga_idx
); /*VGA_idx = 7~0*/
118 rx_pwr_all
= -12 + 2 * (5 - vga_idx
);
120 rx_pwr_all
= -6 + 2 * (5 - vga_idx
);
123 rx_pwr_all
= 8 - 2 * vga_idx
;
126 rx_pwr_all
= 14 - 2 * vga_idx
;
132 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
133 /* CCK gain is smaller than OFDM/MCS gain,
134 * so we add gain diff by experiences,
140 /* modify the offset to make the same
141 * gain index with OFDM.
143 if (pwdb_all
> 34 && pwdb_all
<= 42)
145 else if (pwdb_all
> 26 && pwdb_all
<= 34)
147 else if (pwdb_all
> 14 && pwdb_all
<= 26)
149 else if (pwdb_all
> 4 && pwdb_all
<= 14)
151 if (cck_hipwr
== false) {
153 pwdb_all
= ((pwdb_all
- 80)<<1) +
154 ((pwdb_all
- 80)>>1) + 80;
155 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
161 pstatus
->rx_pwdb_all
= pwdb_all
;
162 pstatus
->recvsignalpower
= rx_pwr_all
;
164 /* (3) Get Signal Quality (EVM) */
165 if (bpacket_match_bssid
) {
168 if (pstatus
->rx_pwdb_all
> 40) {
171 sq
= cck_buf
->sq_rpt
;
177 sq
= ((64 - sq
) * 100) / 44;
180 pstatus
->signalquality
= sq
;
181 pstatus
->rx_mimo_sig_qual
[0] = sq
;
182 pstatus
->rx_mimo_sig_qual
[1] = -1;
185 rtlpriv
->dm
.rfpath_rxenable
[0] =
186 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
188 /* (1)Get RSSI for HT rate */
189 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
190 /* we will judge RF RX path now. */
191 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
194 rx_pwr
[i
] = ((p_drvinfo
->gain_trsw
[i
] & 0x3f) * 2)-110;
196 /* Translate DBM to percentage. */
197 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
200 /* Get Rx snr value in DB */
201 rtlpriv
->stats
.rx_snr_db
[i
] = p_drvinfo
->rxsnr
[i
] / 2;
203 /* Record Signal Strength for next packet */
204 if (bpacket_match_bssid
)
205 pstatus
->rx_mimo_signalstrength
[i
] = (u8
) rssi
;
208 /* (2)PWDB, Average PWDB cacluated by
209 * hardware (for rate adaptive)
211 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
213 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
214 pstatus
->rx_pwdb_all
= pwdb_all
;
215 pstatus
->rxpower
= rx_pwr_all
;
216 pstatus
->recvsignalpower
= rx_pwr_all
;
218 /* (3)EVM of HT rate */
219 if (pstatus
->is_ht
&& pstatus
->rate
>= DESC92C_RATEMCS8
&&
220 pstatus
->rate
<= DESC92C_RATEMCS15
)
221 max_spatial_stream
= 2;
223 max_spatial_stream
= 1;
225 for (i
= 0; i
< max_spatial_stream
; i
++) {
226 evm
= rtl_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
228 if (bpacket_match_bssid
) {
229 /* Fill value in RFD, Get the first
230 * spatial stream only
233 pstatus
->signalquality
= evm
& 0xff;
234 pstatus
->rx_mimo_sig_qual
[i
] = evm
& 0xff;
239 /* UI BSS List signal strength(in percentage),
240 * make it good looking, from 0~100.
243 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
245 else if (rf_rx_num
!= 0)
246 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
247 total_rssi
/= rf_rx_num
));
248 /*HW antenna diversity*/
249 rtldm
->fat_table
.antsel_rx_keep_0
= phystrpt
->ant_sel
;
250 rtldm
->fat_table
.antsel_rx_keep_1
= phystrpt
->ant_sel_b
;
251 rtldm
->fat_table
.antsel_rx_keep_2
= phystrpt
->antsel_rx_keep_2
;
254 static void _rtl88ee_smart_antenna(struct ieee80211_hw
*hw
,
255 struct rtl_stats
*pstatus
)
257 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
258 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
260 struct fast_ant_training
*pfat
= &(rtldm
->fat_table
);
262 if (rtlefuse
->antenna_div_type
== CG_TRX_SMART_ANTDIV
) {
263 if (pfat
->fat_state
== FAT_TRAINING_STATE
) {
264 if (pstatus
->packet_toself
) {
265 ant_mux
= (pfat
->antsel_rx_keep_2
<< 2) |
266 (pfat
->antsel_rx_keep_1
<< 1) |
267 pfat
->antsel_rx_keep_0
;
268 pfat
->ant_sum
[ant_mux
] += pstatus
->rx_pwdb_all
;
269 pfat
->ant_cnt
[ant_mux
]++;
272 } else if ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) ||
273 (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)) {
274 if (pstatus
->packet_toself
|| pstatus
->packet_matchbssid
) {
275 ant_mux
= (pfat
->antsel_rx_keep_2
<< 2) |
276 (pfat
->antsel_rx_keep_1
<< 1) |
277 pfat
->antsel_rx_keep_0
;
278 rtl88e_dm_ant_sel_statistics(hw
, ant_mux
, 0,
279 pstatus
->rx_pwdb_all
);
284 static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
285 struct sk_buff
*skb
, struct rtl_stats
*pstatus
,
286 u8
*pdesc
, struct rx_fwinfo_88e
*p_drvinfo
)
288 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
289 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
290 struct ieee80211_hdr
*hdr
;
296 bool match_bssid
, packet_toself
, packet_beacon
= false, addr
;
298 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
300 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
301 fc
= hdr
->frame_control
;
302 ufc
= le16_to_cpu(fc
);
303 type
= WLAN_FC_GET_TYPE(fc
);
305 psaddr
= ieee80211_get_SA(hdr
);
306 memcpy(pstatus
->psaddr
, psaddr
, ETH_ALEN
);
308 addr
= ether_addr_equal(mac
->bssid
,
309 (ufc
& IEEE80211_FCTL_TODS
) ? hdr
->addr1
:
310 (ufc
& IEEE80211_FCTL_FROMDS
) ? hdr
->addr2
:
312 match_bssid
= ((IEEE80211_FTYPE_CTL
!= type
) && (!pstatus
->hwerror
) &&
313 (!pstatus
->crc
) && (!pstatus
->icv
)) && addr
;
315 addr
= ether_addr_equal(praddr
, rtlefuse
->dev_addr
);
316 packet_toself
= match_bssid
&& addr
;
318 if (ieee80211_is_beacon(fc
))
319 packet_beacon
= true;
321 _rtl88ee_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
322 match_bssid
, packet_toself
, packet_beacon
);
323 _rtl88ee_smart_antenna(hw
, pstatus
);
324 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
327 static void insert_em(struct rtl_tcb_desc
*ptcb_desc
, u8
*virtualaddress
)
331 memset(virtualaddress
, 0, 8);
333 SET_EARLYMODE_PKTNUM(virtualaddress
, ptcb_desc
->empkt_num
);
334 if (ptcb_desc
->empkt_num
== 1) {
335 dwtmp
= ptcb_desc
->empkt_len
[0];
337 dwtmp
= ptcb_desc
->empkt_len
[0];
338 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
339 dwtmp
+= ptcb_desc
->empkt_len
[1];
341 SET_EARLYMODE_LEN0(virtualaddress
, dwtmp
);
343 if (ptcb_desc
->empkt_num
<= 3) {
344 dwtmp
= ptcb_desc
->empkt_len
[2];
346 dwtmp
= ptcb_desc
->empkt_len
[2];
347 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
348 dwtmp
+= ptcb_desc
->empkt_len
[3];
350 SET_EARLYMODE_LEN1(virtualaddress
, dwtmp
);
351 if (ptcb_desc
->empkt_num
<= 5) {
352 dwtmp
= ptcb_desc
->empkt_len
[4];
354 dwtmp
= ptcb_desc
->empkt_len
[4];
355 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
356 dwtmp
+= ptcb_desc
->empkt_len
[5];
358 SET_EARLYMODE_LEN2_1(virtualaddress
, dwtmp
& 0xF);
359 SET_EARLYMODE_LEN2_2(virtualaddress
, dwtmp
>> 4);
360 if (ptcb_desc
->empkt_num
<= 7) {
361 dwtmp
= ptcb_desc
->empkt_len
[6];
363 dwtmp
= ptcb_desc
->empkt_len
[6];
364 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
365 dwtmp
+= ptcb_desc
->empkt_len
[7];
367 SET_EARLYMODE_LEN3(virtualaddress
, dwtmp
);
368 if (ptcb_desc
->empkt_num
<= 9) {
369 dwtmp
= ptcb_desc
->empkt_len
[8];
371 dwtmp
= ptcb_desc
->empkt_len
[8];
372 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
373 dwtmp
+= ptcb_desc
->empkt_len
[9];
375 SET_EARLYMODE_LEN4(virtualaddress
, dwtmp
);
378 bool rtl88ee_rx_query_desc(struct ieee80211_hw
*hw
,
379 struct rtl_stats
*status
,
380 struct ieee80211_rx_status
*rx_status
,
381 u8
*pdesc
, struct sk_buff
*skb
)
383 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
384 struct rx_fwinfo_88e
*p_drvinfo
;
385 struct ieee80211_hdr
*hdr
;
387 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
388 status
->packet_report_type
= (u8
)GET_RX_STATUS_DESC_RPT_SEL(pdesc
);
389 if (status
->packet_report_type
== TX_REPORT2
)
390 status
->length
= (u16
) GET_RX_RPT2_DESC_PKT_LEN(pdesc
);
392 status
->length
= (u16
) GET_RX_DESC_PKT_LEN(pdesc
);
393 status
->rx_drvinfo_size
= (u8
) GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
394 RX_DRV_INFO_SIZE_UNIT
;
395 status
->rx_bufshift
= (u8
) (GET_RX_DESC_SHIFT(pdesc
) & 0x03);
396 status
->icv
= (u16
) GET_RX_DESC_ICV(pdesc
);
397 status
->crc
= (u16
) GET_RX_DESC_CRC32(pdesc
);
398 status
->hwerror
= (status
->crc
| status
->icv
);
399 status
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
400 status
->rate
= (u8
) GET_RX_DESC_RXMCS(pdesc
);
401 status
->shortpreamble
= (u16
) GET_RX_DESC_SPLCP(pdesc
);
402 status
->isampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
403 status
->isfirst_ampdu
= (bool) ((GET_RX_DESC_PAGGR(pdesc
) == 1) &&
404 (GET_RX_DESC_FAGGR(pdesc
) == 1));
405 if (status
->packet_report_type
== NORMAL_RX
)
406 status
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
407 status
->rx_is40Mhzpacket
= (bool) GET_RX_DESC_BW(pdesc
);
408 status
->is_ht
= (bool)GET_RX_DESC_RXHT(pdesc
);
410 status
->is_cck
= RTL8188_RX_HAL_IS_CCK_RATE(status
->rate
);
412 status
->macid
= GET_RX_DESC_MACID(pdesc
);
413 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
414 status
->wake_match
= BIT(2);
415 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
416 status
->wake_match
= BIT(1);
417 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc
))
418 status
->wake_match
= BIT(0);
420 status
->wake_match
= 0;
421 if (status
->wake_match
)
422 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
423 "Get Wakeup Packet!! WakeMatch =%d\n",
425 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
426 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
429 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
431 if (status
->rx_is40Mhzpacket
)
432 rx_status
->flag
|= RX_FLAG_40MHZ
;
435 rx_status
->flag
|= RX_FLAG_HT
;
437 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
439 /* hw will set status->decrypted true, if it finds the
440 * frame is open data frame or mgmt frame.
441 * So hw will not decryption robust managment frame
442 * for IEEE80211w but still set status->decrypted
443 * true, so here we should set it back to undecrypted
444 * for IEEE80211w frame, and mac80211 sw will help
447 if (status
->decrypted
) {
448 hdr
= (struct ieee80211_hdr
*)(skb
->data
+
449 status
->rx_drvinfo_size
+ status
->rx_bufshift
);
452 /* During testing, hdr was NULL */
455 if ((ieee80211_is_robust_mgmt_frame(hdr
)) &&
456 (ieee80211_has_protected(hdr
->frame_control
)))
457 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
459 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
462 /* rate_idx: index of data rate into band's
463 * supported rates or MCS index if HT rates
464 * are use (RX_FLAG_HT)
465 * Notice: this is diff with windows define
467 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
468 status
->rate
, false);
470 rx_status
->mactime
= status
->timestamp_low
;
471 if (phystatus
== true) {
472 p_drvinfo
= (struct rx_fwinfo_88e
*)(skb
->data
+
473 status
->rx_bufshift
);
475 _rtl88ee_translate_rx_signal_stuff(hw
, skb
, status
, pdesc
,
479 /*rx_status->qual = status->signal; */
480 rx_status
->signal
= status
->recvsignalpower
+ 10;
481 /*rx_status->noise = -status->noise; */
482 if (status
->packet_report_type
== TX_REPORT2
) {
483 status
->macid_valid_entry
[0] =
484 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc
);
485 status
->macid_valid_entry
[1] =
486 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc
);
491 void rtl88ee_tx_fill_desc(struct ieee80211_hw
*hw
,
492 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
493 struct ieee80211_tx_info
*info
,
494 struct ieee80211_sta
*sta
,
496 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
498 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
499 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
500 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
501 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
502 u8
*pdesc
= (u8
*)pdesc_tx
;
504 __le16 fc
= hdr
->frame_control
;
505 unsigned int buf_len
= 0;
506 unsigned int skb_len
= skb
->len
;
507 u8 fw_qsel
= _rtl88ee_map_hwqueue_to_fwqueue(skb
, hw_queue
);
508 bool firstseg
= ((hdr
->seq_ctrl
&
509 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
510 bool lastseg
= ((hdr
->frame_control
&
511 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
516 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
518 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
519 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
521 bw_40
= sta
->ht_cap
.cap
&
522 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
524 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
525 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
526 /* reserve 8 byte for AMPDU early mode */
527 if (rtlhal
->earlymode_enable
) {
528 skb_push(skb
, EM_HDR_LEN
);
529 memset(skb
->data
, 0, EM_HDR_LEN
);
532 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
534 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
535 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
536 "DMA mapping error");
539 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_88e
));
540 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
545 if (rtlhal
->earlymode_enable
) {
546 SET_TX_DESC_PKT_OFFSET(pdesc
, 1);
547 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
+
549 if (ptcb_desc
->empkt_num
) {
550 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
551 "Insert 8 byte.pTcb->EMPktNum:%d\n",
552 ptcb_desc
->empkt_num
);
553 insert_em(ptcb_desc
, (u8
*)(skb
->data
));
556 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
559 ptcb_desc
->use_driver_rate
= true;
560 SET_TX_DESC_TX_RATE(pdesc
, ptcb_desc
->hw_rate
);
561 if (ptcb_desc
->hw_rate
> DESC92C_RATEMCS0
)
562 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
564 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
565 SET_TX_DESC_DATA_SHORTGI(pdesc
, short_gi
);
567 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
568 SET_TX_DESC_AGG_ENABLE(pdesc
, 1);
569 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
571 SET_TX_DESC_SEQ(pdesc
, seq_number
);
572 SET_TX_DESC_RTS_ENABLE(pdesc
, ((ptcb_desc
->rts_enable
&&
573 !ptcb_desc
->cts_enable
) ? 1 : 0));
574 SET_TX_DESC_HW_RTS_ENABLE(pdesc
, 0);
575 SET_TX_DESC_CTS2SELF(pdesc
, ((ptcb_desc
->cts_enable
) ? 1 : 0));
576 SET_TX_DESC_RTS_STBC(pdesc
, ((ptcb_desc
->rts_stbc
) ? 1 : 0));
578 SET_TX_DESC_RTS_RATE(pdesc
, ptcb_desc
->rts_rate
);
579 SET_TX_DESC_RTS_BW(pdesc
, 0);
580 SET_TX_DESC_RTS_SC(pdesc
, ptcb_desc
->rts_sc
);
581 SET_TX_DESC_RTS_SHORT(pdesc
,
582 ((ptcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
583 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
584 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
586 if (ptcb_desc
->btx_enable_sw_calc_duration
)
587 SET_TX_DESC_NAV_USE_HDR(pdesc
, 1);
590 if (ptcb_desc
->packet_bw
) {
591 SET_TX_DESC_DATA_BW(pdesc
, 1);
592 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
594 SET_TX_DESC_DATA_BW(pdesc
, 0);
595 SET_TX_DESC_TX_SUB_CARRIER(pdesc
,
596 mac
->cur_40_prime_sc
);
599 SET_TX_DESC_DATA_BW(pdesc
, 0);
600 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
603 SET_TX_DESC_LINIP(pdesc
, 0);
604 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb_len
);
606 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
607 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
609 if (info
->control
.hw_key
) {
610 struct ieee80211_key_conf
*keyconf
;
611 keyconf
= info
->control
.hw_key
;
612 switch (keyconf
->cipher
) {
613 case WLAN_CIPHER_SUITE_WEP40
:
614 case WLAN_CIPHER_SUITE_WEP104
:
615 case WLAN_CIPHER_SUITE_TKIP
:
616 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
618 case WLAN_CIPHER_SUITE_CCMP
:
619 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
622 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
627 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
628 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
629 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
630 SET_TX_DESC_DISABLE_FB(pdesc
, ptcb_desc
->disable_ratefallback
?
632 SET_TX_DESC_USE_RATE(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
634 /* Set TxRate and RTSRate in TxDesc */
635 /* This prevent Tx initial rate of new-coming packets */
636 /* from being overwritten by retried packet rate.*/
637 if (!ptcb_desc
->use_driver_rate
) {
638 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
639 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
641 if (ieee80211_is_data_qos(fc
)) {
643 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
644 "Enable RDG function.\n");
645 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
646 SET_TX_DESC_HTC(pdesc
, 1);
651 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
652 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
653 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) buf_len
);
654 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
655 if (rtlpriv
->dm
.useramask
) {
656 SET_TX_DESC_RATE_ID(pdesc
, ptcb_desc
->ratr_index
);
657 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
659 SET_TX_DESC_RATE_ID(pdesc
, 0xC + ptcb_desc
->ratr_index
);
660 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->ratr_index
);
662 if (ieee80211_is_data_qos(fc
))
663 SET_TX_DESC_QOS(pdesc
, 1);
665 if (!ieee80211_is_data_qos(fc
))
666 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
667 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
668 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
669 is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
670 SET_TX_DESC_BMC(pdesc
, 1);
672 rtl88e_dm_set_tx_ant_by_tx_info(hw
, pdesc
, ptcb_desc
->mac_id
);
673 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
676 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
677 u8
*pdesc
, bool firstseg
,
678 bool lastseg
, struct sk_buff
*skb
)
680 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
681 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
682 u8 fw_queue
= QSLT_BEACON
;
684 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
688 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)(skb
->data
);
689 __le16 fc
= hdr
->frame_control
;
691 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
692 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
693 "DMA mapping error");
696 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
699 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
701 SET_TX_DESC_TX_RATE(pdesc
, DESC92C_RATE1M
);
703 SET_TX_DESC_SEQ(pdesc
, 0);
705 SET_TX_DESC_LINIP(pdesc
, 0);
707 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
709 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
710 SET_TX_DESC_LAST_SEG(pdesc
, 1);
712 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
714 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
716 SET_TX_DESC_RATE_ID(pdesc
, 7);
717 SET_TX_DESC_MACID(pdesc
, 0);
719 SET_TX_DESC_OWN(pdesc
, 1);
721 SET_TX_DESC_PKT_SIZE((u8
*)pdesc
, (u16
)(skb
->len
));
723 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
724 SET_TX_DESC_LAST_SEG(pdesc
, 1);
726 SET_TX_DESC_OFFSET(pdesc
, 0x20);
728 SET_TX_DESC_USE_RATE(pdesc
, 1);
730 if (!ieee80211_is_data_qos(fc
))
731 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
733 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
734 "H2C Tx Cmd Content\n",
735 pdesc
, TX_DESC_SIZE
);
738 void rtl88ee_set_desc(u8
*pdesc
, bool istx
, u8 desc_name
, u8
*val
)
743 SET_TX_DESC_OWN(pdesc
, 1);
745 case HW_DESC_TX_NEXTDESC_ADDR
:
746 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*)val
);
749 RT_ASSERT(false, "ERR txdesc :%d not processed\n",
756 SET_RX_DESC_OWN(pdesc
, 1);
758 case HW_DESC_RXBUFF_ADDR
:
759 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*)val
);
761 case HW_DESC_RXPKT_LEN
:
762 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*)val
);
765 SET_RX_DESC_EOR(pdesc
, 1);
768 RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
775 u32
rtl88ee_get_desc(u8
*pdesc
, bool istx
, u8 desc_name
)
782 ret
= GET_TX_DESC_OWN(pdesc
);
784 case HW_DESC_TXBUFF_ADDR
:
785 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
);
788 RT_ASSERT(false, "ERR txdesc :%d not processed\n",
795 ret
= GET_RX_DESC_OWN(pdesc
);
797 case HW_DESC_RXPKT_LEN
:
798 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
801 RT_ASSERT(false, "ERR rxdesc :%d not processed\n",
809 void rtl88ee_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
811 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
812 if (hw_queue
== BEACON_QUEUE
) {
813 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
815 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
816 BIT(0) << (hw_queue
));