1 /******************************************************************************
3 * Copyright(c) 2009-2014 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 *****************************************************************************/
37 static u8
_rtl8723be_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
39 __le16 fc
= rtl_get_fc(skb
);
41 if (unlikely(ieee80211_is_beacon(fc
)))
43 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
49 /* mac80211's rate_idx is like this:
51 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
54 * (rx_status->flag & RX_FLAG_HT) = 0,
55 * DESC92C_RATE1M-->DESC92C_RATE54M ==> idx is 0-->11,
58 * (rx_status->flag & RX_FLAG_HT) = 1,
59 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
61 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
63 * (rx_status->flag & RX_FLAG_HT) = 0,
64 * DESC92C_RATE6M-->DESC92C_RATE54M ==> idx is 0-->7,
67 * (rx_status->flag & RX_FLAG_HT) = 1,
68 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
70 static int _rtl8723be_rate_mapping(struct ieee80211_hw
*hw
,
71 bool isht
, u8 desc_rate
)
76 if (IEEE80211_BAND_2GHZ
== hw
->conf
.chandef
.chan
->band
) {
84 case DESC92C_RATE5_5M
:
102 case DESC92C_RATE24M
:
105 case DESC92C_RATE36M
:
108 case DESC92C_RATE48M
:
111 case DESC92C_RATE54M
:
126 case DESC92C_RATE12M
:
129 case DESC92C_RATE18M
:
132 case DESC92C_RATE24M
:
135 case DESC92C_RATE36M
:
138 case DESC92C_RATE48M
:
141 case DESC92C_RATE54M
:
151 case DESC92C_RATEMCS0
:
154 case DESC92C_RATEMCS1
:
157 case DESC92C_RATEMCS2
:
160 case DESC92C_RATEMCS3
:
163 case DESC92C_RATEMCS4
:
166 case DESC92C_RATEMCS5
:
169 case DESC92C_RATEMCS6
:
172 case DESC92C_RATEMCS7
:
175 case DESC92C_RATEMCS8
:
178 case DESC92C_RATEMCS9
:
181 case DESC92C_RATEMCS10
:
184 case DESC92C_RATEMCS11
:
187 case DESC92C_RATEMCS12
:
190 case DESC92C_RATEMCS13
:
193 case DESC92C_RATEMCS14
:
196 case DESC92C_RATEMCS15
:
207 static void _rtl8723be_query_rxphystatus(struct ieee80211_hw
*hw
,
208 struct rtl_stats
*pstatus
, u8
*pdesc
,
209 struct rx_fwinfo_8723be
*p_drvinfo
,
210 bool packet_match_bssid
,
214 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
215 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtlpriv
);
216 struct phy_sts_cck_8723e_t
*cck_buf
;
217 struct phy_status_rpt
*p_phystrpt
= (struct phy_status_rpt
*)p_drvinfo
;
218 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
219 char rx_pwr_all
= 0, rx_pwr
[4];
220 u8 rf_rx_num
= 0, evm
, pwdb_all
;
221 u8 i
, max_spatial_stream
;
222 u32 rssi
, total_rssi
= 0;
223 bool is_cck
= pstatus
->is_cck
;
226 /* Record it for next packet processing */
227 pstatus
->packet_matchbssid
= packet_match_bssid
;
228 pstatus
->packet_toself
= packet_toself
;
229 pstatus
->packet_beacon
= packet_beacon
;
230 pstatus
->rx_mimo_sig_qual
[0] = -1;
231 pstatus
->rx_mimo_sig_qual
[1] = -1;
236 /* CCK Driver info Structure is not the same as OFDM packet. */
237 cck_buf
= (struct phy_sts_cck_8723e_t
*)p_drvinfo
;
238 cck_agc_rpt
= cck_buf
->cck_agc_rpt
;
240 /* (1)Hardware does not provide RSSI for CCK
241 * (2)PWDB, Average PWDB cacluated by
242 * hardware (for rate adaptive)
244 if (ppsc
->rfpwr_state
== ERFON
)
245 cck_highpwr
= (u8
) rtl_get_bbreg(hw
,
246 RFPGA0_XA_HSSIPARAMETER2
,
251 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
252 vga_idx
= (cck_agc_rpt
& 0x1f);
255 if (vga_idx
<= 27)/*VGA_idx = 27~2*/
256 rx_pwr_all
= -100 + 2 * (27 - vga_idx
);
260 case 6:/*VGA_idx = 2~0*/
261 rx_pwr_all
= -48 + 2 * (2 - vga_idx
);
263 case 5:/*VGA_idx = 7~5*/
264 rx_pwr_all
= -42 + 2 * (7 - vga_idx
);
266 case 4:/*VGA_idx = 7~4*/
267 rx_pwr_all
= -36 + 2 * (7 - vga_idx
);
269 case 3:/*VGA_idx = 7~0*/
270 rx_pwr_all
= -24 + 2 * (7 - vga_idx
);
273 if (cck_highpwr
)/*VGA_idx = 5~0*/
274 rx_pwr_all
= -12 + 2 * (5 - vga_idx
);
276 rx_pwr_all
= -6 + 2 * (5 - vga_idx
);
279 rx_pwr_all
= 8 - 2 * vga_idx
;
282 rx_pwr_all
= 14 - 2 * vga_idx
;
288 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
289 /* CCK gain is smaller than OFDM/MCS gain, */
290 /* so we add gain diff by experiences,
296 /* modify the offset to make the same gain index with OFDM. */
297 if (pwdb_all
> 34 && pwdb_all
<= 42)
299 else if (pwdb_all
> 26 && pwdb_all
<= 34)
301 else if (pwdb_all
> 14 && pwdb_all
<= 26)
303 else if (pwdb_all
> 4 && pwdb_all
<= 14)
307 pwdb_all
= ((pwdb_all
- 80) << 1) +
308 ((pwdb_all
- 80) >> 1) + 80;
309 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
315 pstatus
->rx_pwdb_all
= pwdb_all
;
316 pstatus
->recvsignalpower
= rx_pwr_all
;
318 /* (3) Get Signal Quality (EVM) */
319 if (packet_match_bssid
) {
322 if (pstatus
->rx_pwdb_all
> 40) {
325 sq
= cck_buf
->sq_rpt
;
331 sq
= ((64 - sq
) * 100) / 44;
334 pstatus
->signalquality
= sq
;
335 pstatus
->rx_mimo_sig_qual
[0] = sq
;
336 pstatus
->rx_mimo_sig_qual
[1] = -1;
339 rtlpriv
->dm
.rfpath_rxenable
[0] = true;
340 rtlpriv
->dm
.rfpath_rxenable
[1] = true;
342 /* (1)Get RSSI for HT rate */
343 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
344 /* we will judge RF RX path now. */
345 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
348 rx_pwr
[i
] = ((p_drvinfo
->gain_trsw
[i
] & 0x3f)*2) - 110;
350 /* Translate DBM to percentage. */
351 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
354 /* Get Rx snr value in DB */
355 rtlpriv
->stats
.rx_snr_db
[i
] =
356 (long)(p_drvinfo
->rxsnr
[i
] / 2);
358 /* Record Signal Strength for next packet */
359 if (packet_match_bssid
)
360 pstatus
->rx_mimo_signalstrength
[i
] = (u8
) rssi
;
363 /* (2)PWDB, Avg cacluated by hardware (for rate adaptive) */
364 rx_pwr_all
= ((p_drvinfo
->pwdb_all
>> 1) & 0x7f) - 110;
366 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
367 pstatus
->rx_pwdb_all
= pwdb_all
;
368 pstatus
->rxpower
= rx_pwr_all
;
369 pstatus
->recvsignalpower
= rx_pwr_all
;
371 /* (3)EVM of HT rate */
372 if (pstatus
->is_ht
&& pstatus
->rate
>= DESC92C_RATEMCS8
&&
373 pstatus
->rate
<= DESC92C_RATEMCS15
)
374 max_spatial_stream
= 2;
376 max_spatial_stream
= 1;
378 for (i
= 0; i
< max_spatial_stream
; i
++) {
379 evm
= rtl_evm_db_to_percentage(p_drvinfo
->rxevm
[i
]);
381 if (packet_match_bssid
) {
382 /* Fill value in RFD, Get the first
383 * spatial stream only
386 pstatus
->signalquality
=
388 pstatus
->rx_mimo_sig_qual
[i
] =
392 if (packet_match_bssid
) {
393 for (i
= RF90_PATH_A
; i
<= RF90_PATH_B
; i
++)
394 rtl_priv(hw
)->dm
.cfo_tail
[i
] =
395 (char)p_phystrpt
->path_cfotail
[i
];
397 rtl_priv(hw
)->dm
.packet_count
++;
398 if (rtl_priv(hw
)->dm
.packet_count
== 0xffffffff)
399 rtl_priv(hw
)->dm
.packet_count
= 0;
403 /* UI BSS List signal strength(in percentage),
404 * make it good looking, from 0~100.
407 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
409 else if (rf_rx_num
!= 0)
410 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
411 total_rssi
/= rf_rx_num
));
412 /*HW antenna diversity*/
413 rtldm
->fat_table
.antsel_rx_keep_0
= p_phystrpt
->ant_sel
;
414 rtldm
->fat_table
.antsel_rx_keep_1
= p_phystrpt
->ant_sel_b
;
415 rtldm
->fat_table
.antsel_rx_keep_2
= p_phystrpt
->antsel_rx_keep_2
;
418 static void _rtl8723be_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
420 struct rtl_stats
*pstatus
,
422 struct rx_fwinfo_8723be
*p_drvinfo
)
424 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
425 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
426 struct ieee80211_hdr
*hdr
;
431 bool packet_matchbssid
, packet_toself
, packet_beacon
;
433 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
435 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
436 fc
= le16_to_cpu(hdr
->frame_control
);
437 type
= WLAN_FC_GET_TYPE(hdr
->frame_control
);
439 psaddr
= ieee80211_get_SA(hdr
);
440 memcpy(pstatus
->psaddr
, psaddr
, ETH_ALEN
);
442 packet_matchbssid
= ((IEEE80211_FTYPE_CTL
!= type
) &&
443 (!ether_addr_equal(mac
->bssid
, (fc
& IEEE80211_FCTL_TODS
) ?
444 hdr
->addr1
: (fc
& IEEE80211_FCTL_FROMDS
) ?
445 hdr
->addr2
: hdr
->addr3
)) &&
446 (!pstatus
->hwerror
) &&
447 (!pstatus
->crc
) && (!pstatus
->icv
));
449 packet_toself
= packet_matchbssid
&&
450 (!ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
452 /* YP: packet_beacon is not initialized,
453 * this assignment is neccesary,
454 * otherwise it counld be true in this case
455 * the situation is much worse in Kernel 3.10
457 if (ieee80211_is_beacon(hdr
->frame_control
))
458 packet_beacon
= true;
460 packet_beacon
= false;
462 if (packet_beacon
&& packet_matchbssid
)
463 rtl_priv(hw
)->dm
.dbginfo
.num_qry_beacon_pkt
++;
465 _rtl8723be_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
470 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
473 static void _rtl8723be_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
477 memset(virtualaddress
, 0, 8);
479 SET_EARLYMODE_PKTNUM(virtualaddress
, ptcb_desc
->empkt_num
);
480 if (ptcb_desc
->empkt_num
== 1) {
481 dwtmp
= ptcb_desc
->empkt_len
[0];
483 dwtmp
= ptcb_desc
->empkt_len
[0];
484 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
485 dwtmp
+= ptcb_desc
->empkt_len
[1];
487 SET_EARLYMODE_LEN0(virtualaddress
, dwtmp
);
489 if (ptcb_desc
->empkt_num
<= 3) {
490 dwtmp
= ptcb_desc
->empkt_len
[2];
492 dwtmp
= ptcb_desc
->empkt_len
[2];
493 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
494 dwtmp
+= ptcb_desc
->empkt_len
[3];
496 SET_EARLYMODE_LEN1(virtualaddress
, dwtmp
);
497 if (ptcb_desc
->empkt_num
<= 5) {
498 dwtmp
= ptcb_desc
->empkt_len
[4];
500 dwtmp
= ptcb_desc
->empkt_len
[4];
501 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
502 dwtmp
+= ptcb_desc
->empkt_len
[5];
504 SET_EARLYMODE_LEN2_1(virtualaddress
, dwtmp
& 0xF);
505 SET_EARLYMODE_LEN2_2(virtualaddress
, dwtmp
>> 4);
506 if (ptcb_desc
->empkt_num
<= 7) {
507 dwtmp
= ptcb_desc
->empkt_len
[6];
509 dwtmp
= ptcb_desc
->empkt_len
[6];
510 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
511 dwtmp
+= ptcb_desc
->empkt_len
[7];
513 SET_EARLYMODE_LEN3(virtualaddress
, dwtmp
);
514 if (ptcb_desc
->empkt_num
<= 9) {
515 dwtmp
= ptcb_desc
->empkt_len
[8];
517 dwtmp
= ptcb_desc
->empkt_len
[8];
518 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
519 dwtmp
+= ptcb_desc
->empkt_len
[9];
521 SET_EARLYMODE_LEN4(virtualaddress
, dwtmp
);
524 bool rtl8723be_rx_query_desc(struct ieee80211_hw
*hw
,
525 struct rtl_stats
*status
,
526 struct ieee80211_rx_status
*rx_status
,
527 u8
*pdesc
, struct sk_buff
*skb
)
529 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
530 struct rx_fwinfo_8723be
*p_drvinfo
;
531 struct ieee80211_hdr
*hdr
;
533 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
534 status
->packet_report_type
= (u8
)GET_RX_STATUS_DESC_RPT_SEL(pdesc
);
535 if (status
->packet_report_type
== TX_REPORT2
)
536 status
->length
= (u16
) GET_RX_RPT2_DESC_PKT_LEN(pdesc
);
538 status
->length
= (u16
) GET_RX_DESC_PKT_LEN(pdesc
);
539 status
->rx_drvinfo_size
= (u8
) GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
540 RX_DRV_INFO_SIZE_UNIT
;
541 status
->rx_bufshift
= (u8
) (GET_RX_DESC_SHIFT(pdesc
) & 0x03);
542 status
->icv
= (u16
) GET_RX_DESC_ICV(pdesc
);
543 status
->crc
= (u16
) GET_RX_DESC_CRC32(pdesc
);
544 status
->hwerror
= (status
->crc
| status
->icv
);
545 status
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
546 status
->rate
= (u8
) GET_RX_DESC_RXMCS(pdesc
);
547 status
->shortpreamble
= (u16
) GET_RX_DESC_SPLCP(pdesc
);
548 status
->isampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
549 status
->isfirst_ampdu
= (bool) (GET_RX_DESC_PAGGR(pdesc
) == 1);
550 if (status
->packet_report_type
== NORMAL_RX
)
551 status
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
552 status
->rx_is40Mhzpacket
= (bool) GET_RX_DESC_BW(pdesc
);
553 status
->is_ht
= (bool)GET_RX_DESC_RXHT(pdesc
);
555 status
->is_cck
= RTL8723E_RX_HAL_IS_CCK_RATE(status
->rate
);
557 status
->macid
= GET_RX_DESC_MACID(pdesc
);
558 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
559 status
->wake_match
= BIT(2);
560 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
561 status
->wake_match
= BIT(1);
562 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc
))
563 status
->wake_match
= BIT(0);
565 status
->wake_match
= 0;
566 if (status
->wake_match
)
567 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
568 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
570 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
571 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
574 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ status
->rx_drvinfo_size
+
575 status
->rx_bufshift
);
578 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
580 if (status
->rx_is40Mhzpacket
)
581 rx_status
->flag
|= RX_FLAG_40MHZ
;
584 rx_status
->flag
|= RX_FLAG_HT
;
586 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
588 /* hw will set status->decrypted true, if it finds the
589 * frame is open data frame or mgmt frame.
590 * So hw will not decryption robust managment frame
591 * for IEEE80211w but still set status->decrypted
592 * true, so here we should set it back to undecrypted
593 * for IEEE80211w frame, and mac80211 sw will help
596 if (status
->decrypted
) {
599 pr_err("decrypted is true but hdr NULL in skb %p\n",
604 if ((_ieee80211_is_robust_mgmt_frame(hdr
)) &&
605 (ieee80211_has_protected(hdr
->frame_control
)))
606 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
608 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
611 /* rate_idx: index of data rate into band's
612 * supported rates or MCS index if HT rates
613 * are use (RX_FLAG_HT)
614 * Notice: this is diff with windows define
616 rx_status
->rate_idx
= _rtl8723be_rate_mapping(hw
, status
->is_ht
,
619 rx_status
->mactime
= status
->timestamp_low
;
621 p_drvinfo
= (struct rx_fwinfo_8723be
*)(skb
->data
+
622 status
->rx_bufshift
);
624 _rtl8723be_translate_rx_signal_stuff(hw
, skb
, status
,
628 /*rx_status->qual = status->signal; */
629 rx_status
->signal
= status
->recvsignalpower
+ 10;
630 if (status
->packet_report_type
== TX_REPORT2
) {
631 status
->macid_valid_entry
[0] =
632 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc
);
633 status
->macid_valid_entry
[1] =
634 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc
);
639 void rtl8723be_tx_fill_desc(struct ieee80211_hw
*hw
,
640 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
641 u8
*pbd_desc_tx
, struct ieee80211_tx_info
*info
,
642 struct ieee80211_sta
*sta
, struct sk_buff
*skb
,
643 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
645 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
646 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
647 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
648 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
649 u8
*pdesc
= pdesc_tx
;
651 __le16 fc
= hdr
->frame_control
;
652 unsigned int buf_len
= 0;
653 unsigned int skb_len
= skb
->len
;
654 u8 fw_qsel
= _rtl8723be_map_hwqueue_to_fwqueue(skb
, hw_queue
);
655 bool firstseg
= ((hdr
->seq_ctrl
&
656 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
657 bool lastseg
= ((hdr
->frame_control
&
658 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
663 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
665 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
666 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
668 bw_40
= sta
->ht_cap
.cap
&
669 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
671 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
672 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
673 /* reserve 8 byte for AMPDU early mode */
674 if (rtlhal
->earlymode_enable
) {
675 skb_push(skb
, EM_HDR_LEN
);
676 memset(skb
->data
, 0, EM_HDR_LEN
);
679 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
681 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
682 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "DMA mapping error");
685 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_8723be
));
686 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
691 if (rtlhal
->earlymode_enable
) {
692 SET_TX_DESC_PKT_OFFSET(pdesc
, 1);
693 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
+
695 if (ptcb_desc
->empkt_num
) {
696 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
697 "Insert 8 byte.pTcb->EMPktNum:%d\n",
698 ptcb_desc
->empkt_num
);
699 _rtl8723be_insert_emcontent(ptcb_desc
,
703 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
706 /* ptcb_desc->use_driver_rate = true; */
707 SET_TX_DESC_TX_RATE(pdesc
, ptcb_desc
->hw_rate
);
708 if (ptcb_desc
->hw_rate
> DESC92C_RATEMCS0
)
709 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
711 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
713 SET_TX_DESC_DATA_SHORTGI(pdesc
, short_gi
);
715 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
716 SET_TX_DESC_AGG_ENABLE(pdesc
, 1);
717 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
719 SET_TX_DESC_SEQ(pdesc
, seq_number
);
720 SET_TX_DESC_RTS_ENABLE(pdesc
, ((ptcb_desc
->rts_enable
&&
721 !ptcb_desc
->cts_enable
) ?
723 SET_TX_DESC_HW_RTS_ENABLE(pdesc
, 0);
724 SET_TX_DESC_CTS2SELF(pdesc
, ((ptcb_desc
->cts_enable
) ?
727 SET_TX_DESC_RTS_RATE(pdesc
, ptcb_desc
->rts_rate
);
729 SET_TX_DESC_RTS_SC(pdesc
, ptcb_desc
->rts_sc
);
730 SET_TX_DESC_RTS_SHORT(pdesc
,
731 ((ptcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
732 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
733 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
735 if (ptcb_desc
->btx_enable_sw_calc_duration
)
736 SET_TX_DESC_NAV_USE_HDR(pdesc
, 1);
739 if (ptcb_desc
->packet_bw
) {
740 SET_TX_DESC_DATA_BW(pdesc
, 1);
741 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
743 SET_TX_DESC_DATA_BW(pdesc
, 0);
744 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, mac
->cur_40_prime_sc
);
747 SET_TX_DESC_DATA_BW(pdesc
, 0);
748 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
751 SET_TX_DESC_LINIP(pdesc
, 0);
752 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb_len
);
754 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
755 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
757 if (info
->control
.hw_key
) {
758 struct ieee80211_key_conf
*keyconf
=
759 info
->control
.hw_key
;
760 switch (keyconf
->cipher
) {
761 case WLAN_CIPHER_SUITE_WEP40
:
762 case WLAN_CIPHER_SUITE_WEP104
:
763 case WLAN_CIPHER_SUITE_TKIP
:
764 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
766 case WLAN_CIPHER_SUITE_CCMP
:
767 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
770 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
775 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
776 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
777 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
778 SET_TX_DESC_DISABLE_FB(pdesc
, ptcb_desc
->disable_ratefallback
?
780 SET_TX_DESC_USE_RATE(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
782 if (ieee80211_is_data_qos(fc
)) {
784 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
785 "Enable RDG function.\n");
786 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
787 SET_TX_DESC_HTC(pdesc
, 1);
792 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
793 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
794 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) buf_len
);
795 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
796 SET_TX_DESC_RATE_ID(pdesc
, ptcb_desc
->ratr_index
);
797 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
799 if (!ieee80211_is_data_qos(fc
)) {
800 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
801 SET_TX_DESC_HWSEQ_SEL(pdesc
, 0);
803 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
804 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
805 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
806 SET_TX_DESC_BMC(pdesc
, 1);
808 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
811 void rtl8723be_tx_fill_cmddesc(struct ieee80211_hw
*hw
, u8
*pdesc
,
812 bool b_firstseg
, bool b_lastseg
,
815 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
816 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
817 u8 fw_queue
= QSLT_BEACON
;
819 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
823 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
824 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
825 "DMA mapping error");
828 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
830 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
832 SET_TX_DESC_TX_RATE(pdesc
, DESC92C_RATE1M
);
834 SET_TX_DESC_SEQ(pdesc
, 0);
836 SET_TX_DESC_LINIP(pdesc
, 0);
838 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
840 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
841 SET_TX_DESC_LAST_SEG(pdesc
, 1);
843 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
845 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
847 SET_TX_DESC_RATE_ID(pdesc
, 0);
848 SET_TX_DESC_MACID(pdesc
, 0);
850 SET_TX_DESC_OWN(pdesc
, 1);
852 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
)(skb
->len
));
854 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
855 SET_TX_DESC_LAST_SEG(pdesc
, 1);
857 SET_TX_DESC_USE_RATE(pdesc
, 1);
860 void rtl8723be_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc
, bool istx
,
861 u8 desc_name
, u8
*val
)
866 SET_TX_DESC_OWN(pdesc
, 1);
868 case HW_DESC_TX_NEXTDESC_ADDR
:
869 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*)val
);
872 RT_ASSERT(false, "ERR txdesc :%d not process\n",
879 SET_RX_DESC_OWN(pdesc
, 1);
881 case HW_DESC_RXBUFF_ADDR
:
882 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*)val
);
884 case HW_DESC_RXPKT_LEN
:
885 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*)val
);
888 SET_RX_DESC_EOR(pdesc
, 1);
891 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
898 u32
rtl8723be_get_desc(u8
*pdesc
, bool istx
, u8 desc_name
)
905 ret
= GET_TX_DESC_OWN(pdesc
);
907 case HW_DESC_TXBUFF_ADDR
:
908 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
);
911 RT_ASSERT(false, "ERR txdesc :%d not process\n",
918 ret
= GET_RX_DESC_OWN(pdesc
);
920 case HW_DESC_RXPKT_LEN
:
921 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
924 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
932 bool rtl8723be_is_tx_desc_closed(struct ieee80211_hw
*hw
,
933 u8 hw_queue
, u16 index
)
935 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
936 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
937 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
938 u8 own
= (u8
) rtl8723be_get_desc(entry
, true, HW_DESC_OWN
);
940 /*beacon packet will only use the first
941 *descriptor by default, and the own may not
942 *be cleared by the hardware
950 void rtl8723be_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
952 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
953 if (hw_queue
== BEACON_QUEUE
) {
954 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
956 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
957 BIT(0) << (hw_queue
));