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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
38 static u8
_rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
40 __le16 fc
= rtl_get_fc(skb
);
42 if (unlikely(ieee80211_is_beacon(fc
)))
44 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
50 static void _rtl88ee_query_rxphystatus(struct ieee80211_hw
*hw
,
51 struct rtl_stats
*pstatus
, u8
*pdesc
,
52 struct rx_fwinfo_88e
*p_drvinfo
,
53 bool bpacket_match_bssid
,
54 bool bpacket_toself
, bool packet_beacon
)
56 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
57 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
58 struct phy_sts_cck_8192s_t
*cck_buf
;
59 struct phy_status_rpt
*phystrpt
=
60 (struct phy_status_rpt
*)p_drvinfo
;
61 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
62 char rx_pwr_all
= 0, rx_pwr
[4];
63 u8 rf_rx_num
= 0, evm
, pwdb_all
;
64 u8 i
, max_spatial_stream
;
65 u32 rssi
, total_rssi
= 0;
66 bool is_cck
= pstatus
->is_cck
;
69 /* Record it for next packet processing */
70 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
71 pstatus
->packet_toself
= bpacket_toself
;
72 pstatus
->packet_beacon
= packet_beacon
;
73 pstatus
->rx_mimo_signalquality
[0] = -1;
74 pstatus
->rx_mimo_signalquality
[1] = -1;
79 /* CCK Driver info Structure is not the same as OFDM packet. */
80 cck_buf
= (struct phy_sts_cck_8192s_t
*)p_drvinfo
;
81 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
83 /* (1)Hardware does not provide RSSI for CCK
84 * (2)PWDB, Average PWDB cacluated by
85 * hardware (for rate adaptive)
87 if (ppsc
->rfpwr_state
== ERFON
)
89 (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
,
94 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
95 vga_idx
= (cck_agc_rpt
& 0x1f);
100 rx_pwr_all
= -100 + 2*(27-vga_idx
);
106 rx_pwr_all
= -48 + 2*(2-vga_idx
);
110 rx_pwr_all
= -42 + 2*(7-vga_idx
);
114 rx_pwr_all
= -36 + 2*(7-vga_idx
);
118 rx_pwr_all
= -24 + 2*(7-vga_idx
);
123 rx_pwr_all
= -12 + 2*(5-vga_idx
);
125 rx_pwr_all
= -6 + 2*(5-vga_idx
);
128 rx_pwr_all
= 8-2*vga_idx
;
131 rx_pwr_all
= 14-2*vga_idx
;
137 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
138 /* CCK gain is smaller than OFDM/MCS gain, */
139 /* so we add gain diff by experiences, the val is 6 */
143 /* modify the offset to make the same
144 * gain index with OFDM.
146 if (pwdb_all
> 34 && pwdb_all
<= 42)
148 else if (pwdb_all
> 26 && pwdb_all
<= 34)
150 else if (pwdb_all
> 14 && pwdb_all
<= 26)
152 else if (pwdb_all
> 4 && pwdb_all
<= 14)
156 pwdb_all
= ((pwdb_all
-80)<<1) +
157 ((pwdb_all
-80)>>1) + 80;
158 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
164 pstatus
->rx_pwdb_all
= pwdb_all
;
165 pstatus
->recvsignalpower
= rx_pwr_all
;
167 /* (3) Get Signal Quality (EVM) */
168 if (bpacket_match_bssid
) {
171 if (pstatus
->rx_pwdb_all
> 40)
174 sq
= cck_buf
->sq_rpt
;
180 sq
= ((64 - sq
) * 100) / 44;
183 pstatus
->signalquality
= sq
;
184 pstatus
->rx_mimo_signalquality
[0] = sq
;
185 pstatus
->rx_mimo_signalquality
[1] = -1;
188 rtlpriv
->dm
.rfpath_rxenable
[0] =
189 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
191 /* (1)Get RSSI for HT rate */
192 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
193 /* we will judge RF RX path now. */
194 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
197 rx_pwr
[i
] = ((p_drvinfo
->gain_trsw
[i
] &
200 /* Translate DBM to percentage. */
201 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
204 /* Get Rx snr value in DB */
205 rtlpriv
->stats
.rx_snr_db
[i
] =
206 (long)(p_drvinfo
->rxsnr
[i
] / 2);
208 /* Record Signal Strength for next packet */
209 if (bpacket_match_bssid
)
210 pstatus
->rx_mimo_signalstrength
[i
] = (u8
)rssi
;
213 /* (2)PWDB, Average PWDB cacluated by
214 * hardware (for rate adaptive)
216 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
218 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
219 pstatus
->rx_pwdb_all
= pwdb_all
;
220 pstatus
->rxpower
= rx_pwr_all
;
221 pstatus
->recvsignalpower
= rx_pwr_all
;
223 /* (3)EVM of HT rate */
224 if (pstatus
->is_ht
&& pstatus
->rate
>= DESC92C_RATEMCS8
&&
225 pstatus
->rate
<= DESC92C_RATEMCS15
)
226 max_spatial_stream
= 2;
228 max_spatial_stream
= 1;
230 for (i
= 0; i
< max_spatial_stream
; i
++) {
231 evm
= rtl_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
233 if (bpacket_match_bssid
) {
234 /* Fill value in RFD, Get the first
235 * spatial stream onlyi
238 pstatus
->signalquality
=
240 pstatus
->rx_mimo_signalquality
[i
] =
246 /* UI BSS List signal strength(in percentage),
247 * make it good looking, from 0~100.
250 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
252 else if (rf_rx_num
!= 0)
253 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
254 total_rssi
/= rf_rx_num
));
255 /*HW antenna diversity*/
256 rtldm
->fat_table
.antsel_rx_keep_0
= phystrpt
->ant_sel
;
257 rtldm
->fat_table
.antsel_rx_keep_1
= phystrpt
->ant_sel_b
;
258 rtldm
->fat_table
.antsel_rx_keep_2
= phystrpt
->antsel_rx_keep_2
;
261 static void _rtl88ee_smart_antenna(struct ieee80211_hw
*hw
,
262 struct rtl_stats
*pstatus
)
264 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
265 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
267 struct fast_ant_training
*pfat_table
= &rtldm
->fat_table
;
269 if (rtlefuse
->antenna_div_type
== CG_TRX_SMART_ANTDIV
) {
270 if (pfat_table
->fat_state
== FAT_TRAINING_STATE
) {
271 if (pstatus
->packet_toself
) {
273 (pfat_table
->antsel_rx_keep_2
<< 2) |
274 (pfat_table
->antsel_rx_keep_1
<< 1) |
275 pfat_table
->antsel_rx_keep_0
;
276 pfat_table
->ant_sum
[antsel_tr_mux
] +=
277 pstatus
->rx_pwdb_all
;
278 pfat_table
->ant_cnt
[antsel_tr_mux
]++;
281 } else if ((rtlefuse
->antenna_div_type
== CG_TRX_HW_ANTDIV
) ||
282 (rtlefuse
->antenna_div_type
== CGCS_RX_HW_ANTDIV
)) {
283 if (pstatus
->packet_toself
|| pstatus
->packet_matchbssid
) {
284 antsel_tr_mux
= (pfat_table
->antsel_rx_keep_2
<< 2) |
285 (pfat_table
->antsel_rx_keep_1
<< 1) |
286 pfat_table
->antsel_rx_keep_0
;
287 rtl88e_dm_ant_sel_statistics(hw
, antsel_tr_mux
, 0,
288 pstatus
->rx_pwdb_all
);
294 static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
296 struct rtl_stats
*pstatus
,
298 struct rx_fwinfo_88e
*p_drvinfo
)
300 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
301 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
302 struct ieee80211_hdr
*hdr
;
307 bool packet_matchbssid
, packet_toself
, packet_beacon
;
309 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
311 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
312 fc
= hdr
->frame_control
;
314 psaddr
= ieee80211_get_SA(hdr
);
315 memcpy(pstatus
->psaddr
, psaddr
, ETH_ALEN
);
317 packet_matchbssid
= ((!ieee80211_is_ctl(fc
)) &&
318 (ether_addr_equal(mac
->bssid
, ieee80211_has_tods(fc
) ?
319 hdr
->addr1
: ieee80211_has_fromds(fc
) ?
320 hdr
->addr2
: hdr
->addr3
)) &&
321 (!pstatus
->hwerror
) &&
322 (!pstatus
->crc
) && (!pstatus
->icv
));
324 packet_toself
= packet_matchbssid
&&
325 (ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
327 if (ieee80211_is_beacon(hdr
->frame_control
))
328 packet_beacon
= true;
330 packet_beacon
= false;
332 _rtl88ee_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
333 packet_matchbssid
, packet_toself
,
335 _rtl88ee_smart_antenna(hw
, pstatus
);
336 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
339 static void _rtl88ee_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
343 memset(virtualaddress
, 0, 8);
345 SET_EARLYMODE_PKTNUM(virtualaddress
, ptcb_desc
->empkt_num
);
346 if (ptcb_desc
->empkt_num
== 1) {
347 dwtmp
= ptcb_desc
->empkt_len
[0];
349 dwtmp
= ptcb_desc
->empkt_len
[0];
350 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
351 dwtmp
+= ptcb_desc
->empkt_len
[1];
353 SET_EARLYMODE_LEN0(virtualaddress
, dwtmp
);
355 if (ptcb_desc
->empkt_num
<= 3) {
356 dwtmp
= ptcb_desc
->empkt_len
[2];
358 dwtmp
= ptcb_desc
->empkt_len
[2];
359 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
360 dwtmp
+= ptcb_desc
->empkt_len
[3];
362 SET_EARLYMODE_LEN1(virtualaddress
, dwtmp
);
363 if (ptcb_desc
->empkt_num
<= 5) {
364 dwtmp
= ptcb_desc
->empkt_len
[4];
366 dwtmp
= ptcb_desc
->empkt_len
[4];
367 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
368 dwtmp
+= ptcb_desc
->empkt_len
[5];
370 SET_EARLYMODE_LEN2_1(virtualaddress
, dwtmp
& 0xF);
371 SET_EARLYMODE_LEN2_2(virtualaddress
, dwtmp
>> 4);
372 if (ptcb_desc
->empkt_num
<= 7) {
373 dwtmp
= ptcb_desc
->empkt_len
[6];
375 dwtmp
= ptcb_desc
->empkt_len
[6];
376 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
377 dwtmp
+= ptcb_desc
->empkt_len
[7];
379 SET_EARLYMODE_LEN3(virtualaddress
, dwtmp
);
380 if (ptcb_desc
->empkt_num
<= 9) {
381 dwtmp
= ptcb_desc
->empkt_len
[8];
383 dwtmp
= ptcb_desc
->empkt_len
[8];
384 dwtmp
+= ((dwtmp
%4) ? (4-dwtmp
%4) : 0)+4;
385 dwtmp
+= ptcb_desc
->empkt_len
[9];
387 SET_EARLYMODE_LEN4(virtualaddress
, dwtmp
);
390 bool rtl88ee_rx_query_desc(struct ieee80211_hw
*hw
,
391 struct rtl_stats
*status
,
392 struct ieee80211_rx_status
*rx_status
,
393 u8
*pdesc
, struct sk_buff
*skb
)
395 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
396 struct rx_fwinfo_88e
*p_drvinfo
;
397 struct ieee80211_hdr
*hdr
;
399 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
400 status
->packet_report_type
= (u8
)GET_RX_STATUS_DESC_RPT_SEL(pdesc
);
401 if (status
->packet_report_type
== TX_REPORT2
)
402 status
->length
= (u16
)GET_RX_RPT2_DESC_PKT_LEN(pdesc
);
404 status
->length
= (u16
)GET_RX_DESC_PKT_LEN(pdesc
);
405 status
->rx_drvinfo_size
= (u8
)GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
406 RX_DRV_INFO_SIZE_UNIT
;
407 status
->rx_bufshift
= (u8
)(GET_RX_DESC_SHIFT(pdesc
) & 0x03);
408 status
->icv
= (u16
)GET_RX_DESC_ICV(pdesc
);
409 status
->crc
= (u16
)GET_RX_DESC_CRC32(pdesc
);
410 status
->hwerror
= (status
->crc
| status
->icv
);
411 status
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
412 status
->rate
= (u8
)GET_RX_DESC_RXMCS(pdesc
);
413 status
->shortpreamble
= (u16
)GET_RX_DESC_SPLCP(pdesc
);
414 status
->isampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
415 status
->isfirst_ampdu
= (bool)((GET_RX_DESC_PAGGR(pdesc
) == 1) &&
416 (GET_RX_DESC_FAGGR(pdesc
) == 1));
417 if (status
->packet_report_type
== NORMAL_RX
)
418 status
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
419 status
->rx_is40Mhzpacket
= (bool) GET_RX_DESC_BW(pdesc
);
420 status
->is_ht
= (bool)GET_RX_DESC_RXHT(pdesc
);
422 status
->is_cck
= RTL8188_RX_HAL_IS_CCK_RATE(status
->rate
);
424 status
->macid
= GET_RX_DESC_MACID(pdesc
);
425 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
426 status
->wake_match
= BIT(2);
427 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
428 status
->wake_match
= BIT(1);
429 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc
))
430 status
->wake_match
= BIT(0);
432 status
->wake_match
= 0;
433 if (status
->wake_match
)
434 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
435 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
437 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
438 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
440 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ status
->rx_drvinfo_size
441 + status
->rx_bufshift
);
444 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
446 if (status
->rx_is40Mhzpacket
)
447 rx_status
->flag
|= RX_FLAG_40MHZ
;
450 rx_status
->flag
|= RX_FLAG_HT
;
452 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
454 /* hw will set status->decrypted true, if it finds the
455 * frame is open data frame or mgmt frame.
456 * So hw will not decryption robust managment frame
457 * for IEEE80211w but still set status->decrypted
458 * true, so here we should set it back to undecrypted
459 * for IEEE80211w frame, and mac80211 sw will help
462 if (status
->decrypted
) {
463 if ((!_ieee80211_is_robust_mgmt_frame(hdr
)) &&
464 (ieee80211_has_protected(hdr
->frame_control
)))
465 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
467 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
470 /* rate_idx: index of data rate into band's
471 * supported rates or MCS index if HT rates
472 * are use (RX_FLAG_HT)
473 * Notice: this is diff with windows define
475 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
476 false, status
->rate
);
478 rx_status
->mactime
= status
->timestamp_low
;
479 if (phystatus
== true) {
480 p_drvinfo
= (struct rx_fwinfo_88e
*)(skb
->data
+
481 status
->rx_bufshift
);
483 _rtl88ee_translate_rx_signal_stuff(hw
,
487 rx_status
->signal
= status
->recvsignalpower
+ 10;
488 if (status
->packet_report_type
== TX_REPORT2
) {
489 status
->macid_valid_entry
[0] =
490 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc
);
491 status
->macid_valid_entry
[1] =
492 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc
);
497 void rtl88ee_tx_fill_desc(struct ieee80211_hw
*hw
,
498 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
499 u8
*txbd
, struct ieee80211_tx_info
*info
,
500 struct ieee80211_sta
*sta
,
502 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
505 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
506 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
507 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
508 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
509 u8
*pdesc
= (u8
*)pdesc_tx
;
511 __le16 fc
= hdr
->frame_control
;
512 unsigned int buf_len
= 0;
513 unsigned int skb_len
= skb
->len
;
514 u8 fw_qsel
= _rtl88ee_map_hwqueue_to_fwqueue(skb
, hw_queue
);
515 bool firstseg
= ((hdr
->seq_ctrl
&
516 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
517 bool lastseg
= ((hdr
->frame_control
&
518 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
523 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
525 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
526 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
528 bw_40
= sta
->ht_cap
.cap
&
529 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
531 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
532 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
533 /* reserve 8 byte for AMPDU early mode */
534 if (rtlhal
->earlymode_enable
) {
535 skb_push(skb
, EM_HDR_LEN
);
536 memset(skb
->data
, 0, EM_HDR_LEN
);
539 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
541 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
542 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
543 "DMA mapping error");
546 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_88e
));
547 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
552 if (rtlhal
->earlymode_enable
) {
553 SET_TX_DESC_PKT_OFFSET(pdesc
, 1);
554 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
+
556 if (ptcb_desc
->empkt_num
) {
557 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
558 "Insert 8 byte.pTcb->EMPktNum:%d\n",
559 ptcb_desc
->empkt_num
);
560 _rtl88ee_insert_emcontent(ptcb_desc
,
564 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
567 ptcb_desc
->use_driver_rate
= true;
568 SET_TX_DESC_TX_RATE(pdesc
, ptcb_desc
->hw_rate
);
569 if (ptcb_desc
->hw_rate
> DESC92C_RATEMCS0
)
570 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
572 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
574 SET_TX_DESC_DATA_SHORTGI(pdesc
, short_gi
);
576 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
577 SET_TX_DESC_AGG_ENABLE(pdesc
, 1);
578 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
580 SET_TX_DESC_SEQ(pdesc
, seq_number
);
581 SET_TX_DESC_RTS_ENABLE(pdesc
, ((ptcb_desc
->rts_enable
&&
582 !ptcb_desc
->cts_enable
) ? 1 : 0));
583 SET_TX_DESC_HW_RTS_ENABLE(pdesc
, 0);
584 SET_TX_DESC_CTS2SELF(pdesc
, ((ptcb_desc
->cts_enable
) ? 1 : 0));
585 SET_TX_DESC_RTS_STBC(pdesc
, ((ptcb_desc
->rts_stbc
) ? 1 : 0));
587 SET_TX_DESC_RTS_RATE(pdesc
, ptcb_desc
->rts_rate
);
588 SET_TX_DESC_RTS_BW(pdesc
, 0);
589 SET_TX_DESC_RTS_SC(pdesc
, ptcb_desc
->rts_sc
);
590 SET_TX_DESC_RTS_SHORT(pdesc
,
591 ((ptcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
592 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
593 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
595 if (ptcb_desc
->tx_enable_sw_calc_duration
)
596 SET_TX_DESC_NAV_USE_HDR(pdesc
, 1);
599 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
600 SET_TX_DESC_DATA_BW(pdesc
, 1);
601 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
603 SET_TX_DESC_DATA_BW(pdesc
, 0);
604 SET_TX_DESC_TX_SUB_CARRIER(pdesc
,
605 mac
->cur_40_prime_sc
);
608 SET_TX_DESC_DATA_BW(pdesc
, 0);
609 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
612 SET_TX_DESC_LINIP(pdesc
, 0);
613 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
)skb_len
);
615 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
616 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
618 if (info
->control
.hw_key
) {
619 struct ieee80211_key_conf
*keyconf
;
621 keyconf
= info
->control
.hw_key
;
622 switch (keyconf
->cipher
) {
623 case WLAN_CIPHER_SUITE_WEP40
:
624 case WLAN_CIPHER_SUITE_WEP104
:
625 case WLAN_CIPHER_SUITE_TKIP
:
626 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
628 case WLAN_CIPHER_SUITE_CCMP
:
629 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
632 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
638 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
639 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
640 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
641 SET_TX_DESC_DISABLE_FB(pdesc
, ptcb_desc
->disable_ratefallback
?
643 SET_TX_DESC_USE_RATE(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
645 /*SET_TX_DESC_PWR_STATUS(pdesc, pwr_status);*/
646 /* Set TxRate and RTSRate in TxDesc */
647 /* This prevent Tx initial rate of new-coming packets */
648 /* from being overwritten by retried packet rate.*/
649 if (!ptcb_desc
->use_driver_rate
) {
650 /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */
651 /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */
653 if (ieee80211_is_data_qos(fc
)) {
655 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
656 "Enable RDG function.\n");
657 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
658 SET_TX_DESC_HTC(pdesc
, 1);
663 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
664 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
665 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)buf_len
);
666 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
667 if (rtlpriv
->dm
.useramask
) {
668 SET_TX_DESC_RATE_ID(pdesc
, ptcb_desc
->ratr_index
);
669 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
671 SET_TX_DESC_RATE_ID(pdesc
, 0xC + ptcb_desc
->ratr_index
);
672 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->ratr_index
);
674 if (ieee80211_is_data_qos(fc
))
675 SET_TX_DESC_QOS(pdesc
, 1);
677 if (!ieee80211_is_data_qos(fc
))
678 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
679 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
680 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
681 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
682 SET_TX_DESC_BMC(pdesc
, 1);
685 rtl88e_dm_set_tx_ant_by_tx_info(hw
, pdesc
, ptcb_desc
->mac_id
);
686 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
689 void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
690 u8
*pdesc
, bool firstseg
,
691 bool lastseg
, struct sk_buff
*skb
)
693 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
694 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
695 u8 fw_queue
= QSLT_BEACON
;
697 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
701 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)(skb
->data
);
702 __le16 fc
= hdr
->frame_control
;
704 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
705 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
706 "DMA mapping error");
709 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
712 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
714 SET_TX_DESC_TX_RATE(pdesc
, DESC92C_RATE1M
);
716 SET_TX_DESC_SEQ(pdesc
, 0);
718 SET_TX_DESC_LINIP(pdesc
, 0);
720 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
722 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
723 SET_TX_DESC_LAST_SEG(pdesc
, 1);
725 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
727 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
729 SET_TX_DESC_RATE_ID(pdesc
, 7);
730 SET_TX_DESC_MACID(pdesc
, 0);
732 SET_TX_DESC_OWN(pdesc
, 1);
734 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
)(skb
->len
));
736 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
737 SET_TX_DESC_LAST_SEG(pdesc
, 1);
739 SET_TX_DESC_OFFSET(pdesc
, 0x20);
741 SET_TX_DESC_USE_RATE(pdesc
, 1);
743 if (!ieee80211_is_data_qos(fc
))
744 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
746 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
747 "H2C Tx Cmd Content\n",
748 pdesc
, TX_DESC_SIZE
);
751 void rtl88ee_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc
,
752 bool istx
, u8 desc_name
, u8
*val
)
757 SET_TX_DESC_OWN(pdesc
, 1);
759 case HW_DESC_TX_NEXTDESC_ADDR
:
760 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*)val
);
763 RT_ASSERT(false, "ERR txdesc :%d not process\n",
770 SET_RX_DESC_OWN(pdesc
, 1);
772 case HW_DESC_RXBUFF_ADDR
:
773 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*)val
);
775 case HW_DESC_RXPKT_LEN
:
776 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*)val
);
779 SET_RX_DESC_EOR(pdesc
, 1);
782 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
789 u32
rtl88ee_get_desc(u8
*pdesc
, bool istx
, u8 desc_name
)
796 ret
= GET_TX_DESC_OWN(pdesc
);
798 case HW_DESC_TXBUFF_ADDR
:
799 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
);
802 RT_ASSERT(false, "ERR txdesc :%d not process\n",
809 ret
= GET_RX_DESC_OWN(pdesc
);
811 case HW_DESC_RXPKT_LEN
:
812 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
814 case HW_DESC_RXBUFF_ADDR
:
815 ret
= GET_RX_DESC_BUFF_ADDR(pdesc
);
818 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
826 bool rtl88ee_is_tx_desc_closed(struct ieee80211_hw
*hw
, u8 hw_queue
, u16 index
)
828 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
829 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
830 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
831 u8 own
= (u8
)rtl88ee_get_desc(entry
, true, HW_DESC_OWN
);
833 /*beacon packet will only use the first
834 *descriptor defautly,and the own may not
835 *be cleared by the hardware
842 void rtl88ee_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
844 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
845 if (hw_queue
== BEACON_QUEUE
) {
846 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
848 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
849 BIT(0) << (hw_queue
));
853 u32
rtl88ee_rx_command_packet(struct ieee80211_hw
*hw
,
854 struct rtl_stats status
,