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 *****************************************************************************/
38 static u8
_rtl8723be_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 _rtl8723be_query_rxphystatus(struct ieee80211_hw
*hw
,
51 struct rtl_stats
*pstatus
, u8
*pdesc
,
52 struct rx_fwinfo_8723be
*p_drvinfo
,
53 bool bpacket_match_bssid
,
57 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
58 struct phy_status_rpt
*p_phystrpt
= (struct phy_status_rpt
*)p_drvinfo
;
59 char rx_pwr_all
= 0, rx_pwr
[4];
60 u8 rf_rx_num
= 0, evm
, pwdb_all
, pwdb_all_bt
= 0;
61 u8 i
, max_spatial_stream
;
62 u32 rssi
, total_rssi
= 0;
63 bool is_cck
= pstatus
->is_cck
;
66 /* Record it for next packet processing */
67 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
68 pstatus
->packet_toself
= bpacket_toself
;
69 pstatus
->packet_beacon
= packet_beacon
;
70 pstatus
->rx_mimo_signalquality
[0] = -1;
71 pstatus
->rx_mimo_signalquality
[1] = -1;
77 cck_agc_rpt
= p_phystrpt
->cck_agc_rpt_ofdm_cfosho_a
;
79 /* (1)Hardware does not provide RSSI for CCK */
80 /* (2)PWDB, Average PWDB cacluated by
81 * hardware (for rate adaptive)
83 cck_highpwr
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
,
86 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
87 vga_idx
= (cck_agc_rpt
& 0x1f);
90 /* 46 53 73 95 201301231630 */
91 /* 46 53 77 99 201301241630 */
93 rx_pwr_all
= -34 - (2 * vga_idx
);
96 rx_pwr_all
= -14 - (2 * vga_idx
);
99 rx_pwr_all
= 6 - (2 * vga_idx
);
102 rx_pwr_all
= 16 - (2 * vga_idx
);
108 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
112 pstatus
->rx_pwdb_all
= pwdb_all
;
113 pstatus
->bt_rx_rssi_percentage
= pwdb_all
;
114 pstatus
->recvsignalpower
= rx_pwr_all
;
116 /* (3) Get Signal Quality (EVM) */
117 if (bpacket_match_bssid
) {
119 if (pstatus
->rx_pwdb_all
> 40) {
122 sq_rpt
= p_phystrpt
->cck_sig_qual_ofdm_pwdb_all
;
125 else if (sq_rpt
< 20)
128 sq
= ((64 - sq_rpt
) * 100) / 44;
130 pstatus
->signalquality
= sq
;
131 pstatus
->rx_mimo_signalquality
[0] = sq
;
132 pstatus
->rx_mimo_signalquality
[1] = -1;
135 /* (1)Get RSSI for HT rate */
136 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
137 /* we will judge RF RX path now. */
138 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
141 rx_pwr
[i
] = ((p_phystrpt
->path_agc
[i
].gain
& 0x3f) * 2)
144 pstatus
->rx_pwr
[i
] = rx_pwr
[i
];
145 /* Translate DBM to percentage. */
146 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
149 pstatus
->rx_mimo_signalstrength
[i
] = (u8
)rssi
;
152 /* (2)PWDB, Average PWDB cacluated by
153 * hardware (for rate adaptive)
155 rx_pwr_all
= ((p_phystrpt
->cck_sig_qual_ofdm_pwdb_all
>> 1) &
158 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
159 pwdb_all_bt
= pwdb_all
;
160 pstatus
->rx_pwdb_all
= pwdb_all
;
161 pstatus
->bt_rx_rssi_percentage
= pwdb_all_bt
;
162 pstatus
->rxpower
= rx_pwr_all
;
163 pstatus
->recvsignalpower
= rx_pwr_all
;
165 /* (3)EVM of HT rate */
166 if (pstatus
->rate
>= DESC92C_RATEMCS8
&&
167 pstatus
->rate
<= DESC92C_RATEMCS15
)
168 max_spatial_stream
= 2;
170 max_spatial_stream
= 1;
172 for (i
= 0; i
< max_spatial_stream
; i
++) {
173 evm
= rtl_evm_db_to_percentage(
174 p_phystrpt
->stream_rxevm
[i
]);
176 if (bpacket_match_bssid
) {
177 /* Fill value in RFD, Get the first
178 * spatial stream only
181 pstatus
->signalquality
=
183 pstatus
->rx_mimo_signalquality
[i
] =
188 if (bpacket_match_bssid
) {
189 for (i
= RF90_PATH_A
; i
<= RF90_PATH_B
; i
++)
190 rtl_priv(hw
)->dm
.cfo_tail
[i
] =
191 (int)p_phystrpt
->path_cfotail
[i
];
193 if (rtl_priv(hw
)->dm
.packet_count
== 0xffffffff)
194 rtl_priv(hw
)->dm
.packet_count
= 0;
196 rtl_priv(hw
)->dm
.packet_count
++;
200 /* UI BSS List signal strength(in percentage),
201 * make it good looking, from 0~100.
204 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
206 else if (rf_rx_num
!= 0)
207 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
208 total_rssi
/= rf_rx_num
));
211 static void _rtl8723be_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
213 struct rtl_stats
*pstatus
,
215 struct rx_fwinfo_8723be
*p_drvinfo
)
217 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
218 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
219 struct ieee80211_hdr
*hdr
;
224 bool packet_matchbssid
, packet_toself
, packet_beacon
;
226 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+ pstatus
->rx_bufshift
;
228 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
229 fc
= le16_to_cpu(hdr
->frame_control
);
230 type
= WLAN_FC_GET_TYPE(hdr
->frame_control
);
232 psaddr
= ieee80211_get_SA(hdr
);
233 memcpy(pstatus
->psaddr
, psaddr
, ETH_ALEN
);
235 packet_matchbssid
= ((IEEE80211_FTYPE_CTL
!= type
) &&
236 (ether_addr_equal(mac
->bssid
, (fc
& IEEE80211_FCTL_TODS
) ?
237 hdr
->addr1
: (fc
& IEEE80211_FCTL_FROMDS
) ?
238 hdr
->addr2
: hdr
->addr3
)) &&
239 (!pstatus
->hwerror
) &&
240 (!pstatus
->crc
) && (!pstatus
->icv
));
242 packet_toself
= packet_matchbssid
&&
243 (ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
245 /* YP: packet_beacon is not initialized,
246 * this assignment is neccesary,
247 * otherwise it counld be true in this case
248 * the situation is much worse in Kernel 3.10
250 if (ieee80211_is_beacon(hdr
->frame_control
))
251 packet_beacon
= true;
253 packet_beacon
= false;
255 if (packet_beacon
&& packet_matchbssid
)
256 rtl_priv(hw
)->dm
.dbginfo
.num_qry_beacon_pkt
++;
258 _rtl8723be_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
263 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
266 static void _rtl8723be_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
270 memset(virtualaddress
, 0, 8);
272 SET_EARLYMODE_PKTNUM(virtualaddress
, ptcb_desc
->empkt_num
);
273 if (ptcb_desc
->empkt_num
== 1) {
274 dwtmp
= ptcb_desc
->empkt_len
[0];
276 dwtmp
= ptcb_desc
->empkt_len
[0];
277 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
278 dwtmp
+= ptcb_desc
->empkt_len
[1];
280 SET_EARLYMODE_LEN0(virtualaddress
, dwtmp
);
282 if (ptcb_desc
->empkt_num
<= 3) {
283 dwtmp
= ptcb_desc
->empkt_len
[2];
285 dwtmp
= ptcb_desc
->empkt_len
[2];
286 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
287 dwtmp
+= ptcb_desc
->empkt_len
[3];
289 SET_EARLYMODE_LEN1(virtualaddress
, dwtmp
);
290 if (ptcb_desc
->empkt_num
<= 5) {
291 dwtmp
= ptcb_desc
->empkt_len
[4];
293 dwtmp
= ptcb_desc
->empkt_len
[4];
294 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
295 dwtmp
+= ptcb_desc
->empkt_len
[5];
297 SET_EARLYMODE_LEN2_1(virtualaddress
, dwtmp
& 0xF);
298 SET_EARLYMODE_LEN2_2(virtualaddress
, dwtmp
>> 4);
299 if (ptcb_desc
->empkt_num
<= 7) {
300 dwtmp
= ptcb_desc
->empkt_len
[6];
302 dwtmp
= ptcb_desc
->empkt_len
[6];
303 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
304 dwtmp
+= ptcb_desc
->empkt_len
[7];
306 SET_EARLYMODE_LEN3(virtualaddress
, dwtmp
);
307 if (ptcb_desc
->empkt_num
<= 9) {
308 dwtmp
= ptcb_desc
->empkt_len
[8];
310 dwtmp
= ptcb_desc
->empkt_len
[8];
311 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
312 dwtmp
+= ptcb_desc
->empkt_len
[9];
314 SET_EARLYMODE_LEN4(virtualaddress
, dwtmp
);
317 bool rtl8723be_rx_query_desc(struct ieee80211_hw
*hw
,
318 struct rtl_stats
*status
,
319 struct ieee80211_rx_status
*rx_status
,
320 u8
*pdesc
, struct sk_buff
*skb
)
322 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
323 struct rx_fwinfo_8723be
*p_drvinfo
;
324 struct ieee80211_hdr
*hdr
;
326 u32 phystatus
= GET_RX_DESC_PHYST(pdesc
);
328 status
->length
= (u16
)GET_RX_DESC_PKT_LEN(pdesc
);
329 status
->rx_drvinfo_size
= (u8
)GET_RX_DESC_DRV_INFO_SIZE(pdesc
) *
330 RX_DRV_INFO_SIZE_UNIT
;
331 status
->rx_bufshift
= (u8
)(GET_RX_DESC_SHIFT(pdesc
) & 0x03);
332 status
->icv
= (u16
) GET_RX_DESC_ICV(pdesc
);
333 status
->crc
= (u16
) GET_RX_DESC_CRC32(pdesc
);
334 status
->hwerror
= (status
->crc
| status
->icv
);
335 status
->decrypted
= !GET_RX_DESC_SWDEC(pdesc
);
336 status
->rate
= (u8
)GET_RX_DESC_RXMCS(pdesc
);
337 status
->shortpreamble
= (u16
)GET_RX_DESC_SPLCP(pdesc
);
338 status
->isampdu
= (bool)(GET_RX_DESC_PAGGR(pdesc
) == 1);
339 status
->isfirst_ampdu
= (bool)(GET_RX_DESC_PAGGR(pdesc
) == 1);
340 status
->timestamp_low
= GET_RX_DESC_TSFL(pdesc
);
341 status
->rx_is40Mhzpacket
= (bool)GET_RX_DESC_BW(pdesc
);
342 status
->bandwidth
= (u8
)GET_RX_DESC_BW(pdesc
);
343 status
->macid
= GET_RX_DESC_MACID(pdesc
);
344 status
->is_ht
= (bool)GET_RX_DESC_RXHT(pdesc
);
346 status
->is_cck
= RX_HAL_IS_CCK_RATE(status
->rate
);
348 if (GET_RX_STATUS_DESC_RPT_SEL(pdesc
))
349 status
->packet_report_type
= C2H_PACKET
;
351 status
->packet_report_type
= NORMAL_RX
;
354 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
355 status
->wake_match
= BIT(2);
356 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc
))
357 status
->wake_match
= BIT(1);
358 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc
))
359 status
->wake_match
= BIT(0);
361 status
->wake_match
= 0;
362 if (status
->wake_match
)
363 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
364 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
366 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
367 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
369 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ status
->rx_drvinfo_size
+
370 status
->rx_bufshift
);
373 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
375 if (status
->rx_is40Mhzpacket
)
376 rx_status
->flag
|= RX_FLAG_40MHZ
;
379 rx_status
->flag
|= RX_FLAG_HT
;
381 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
383 /* hw will set status->decrypted true, if it finds the
384 * frame is open data frame or mgmt frame.
385 * So hw will not decryption robust managment frame
386 * for IEEE80211w but still set status->decrypted
387 * true, so here we should set it back to undecrypted
388 * for IEEE80211w frame, and mac80211 sw will help
391 if (status
->decrypted
) {
392 if ((!_ieee80211_is_robust_mgmt_frame(hdr
)) &&
393 (ieee80211_has_protected(hdr
->frame_control
)))
394 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
396 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
399 /* rate_idx: index of data rate into band's
400 * supported rates or MCS index if HT rates
401 * are use (RX_FLAG_HT)
403 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
404 false, status
->rate
);
406 rx_status
->mactime
= status
->timestamp_low
;
408 p_drvinfo
= (struct rx_fwinfo_8723be
*)(skb
->data
+
409 status
->rx_bufshift
);
411 _rtl8723be_translate_rx_signal_stuff(hw
, skb
, status
,
414 rx_status
->signal
= status
->recvsignalpower
+ 10;
415 if (status
->packet_report_type
== TX_REPORT2
) {
416 status
->macid_valid_entry
[0] =
417 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc
);
418 status
->macid_valid_entry
[1] =
419 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc
);
424 void rtl8723be_tx_fill_desc(struct ieee80211_hw
*hw
,
425 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
426 u8
*txbd
, struct ieee80211_tx_info
*info
,
427 struct ieee80211_sta
*sta
, struct sk_buff
*skb
,
428 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
430 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
431 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
432 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
433 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
434 u8
*pdesc
= (u8
*)pdesc_tx
;
436 __le16 fc
= hdr
->frame_control
;
437 unsigned int buf_len
= 0;
438 unsigned int skb_len
= skb
->len
;
439 u8 fw_qsel
= _rtl8723be_map_hwqueue_to_fwqueue(skb
, hw_queue
);
440 bool firstseg
= ((hdr
->seq_ctrl
&
441 cpu_to_le16(IEEE80211_SCTL_FRAG
)) == 0);
442 bool lastseg
= ((hdr
->frame_control
&
443 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
)) == 0);
448 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
450 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
451 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
453 bw_40
= sta
->ht_cap
.cap
&
454 IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
456 seq_number
= (le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_SEQ
) >> 4;
457 rtl_get_tcb_desc(hw
, info
, sta
, skb
, ptcb_desc
);
458 /* reserve 8 byte for AMPDU early mode */
459 if (rtlhal
->earlymode_enable
) {
460 skb_push(skb
, EM_HDR_LEN
);
461 memset(skb
->data
, 0, EM_HDR_LEN
);
464 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
466 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
467 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "DMA mapping error");
470 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, sizeof(struct tx_desc_8723be
));
471 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
476 if (rtlhal
->earlymode_enable
) {
477 SET_TX_DESC_PKT_OFFSET(pdesc
, 1);
478 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
+
480 if (ptcb_desc
->empkt_num
) {
481 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
482 "Insert 8 byte.pTcb->EMPktNum:%d\n",
483 ptcb_desc
->empkt_num
);
484 _rtl8723be_insert_emcontent(ptcb_desc
,
488 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
491 /* ptcb_desc->use_driver_rate = true; */
492 SET_TX_DESC_TX_RATE(pdesc
, ptcb_desc
->hw_rate
);
493 if (ptcb_desc
->hw_rate
> DESC92C_RATEMCS0
)
494 short_gi
= (ptcb_desc
->use_shortgi
) ? 1 : 0;
496 short_gi
= (ptcb_desc
->use_shortpreamble
) ? 1 : 0;
498 SET_TX_DESC_DATA_SHORTGI(pdesc
, short_gi
);
500 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
501 SET_TX_DESC_AGG_ENABLE(pdesc
, 1);
502 SET_TX_DESC_MAX_AGG_NUM(pdesc
, 0x14);
504 SET_TX_DESC_SEQ(pdesc
, seq_number
);
505 SET_TX_DESC_RTS_ENABLE(pdesc
, ((ptcb_desc
->rts_enable
&&
506 !ptcb_desc
->cts_enable
) ?
508 SET_TX_DESC_HW_RTS_ENABLE(pdesc
, 0);
509 SET_TX_DESC_CTS2SELF(pdesc
, ((ptcb_desc
->cts_enable
) ?
512 SET_TX_DESC_RTS_RATE(pdesc
, ptcb_desc
->rts_rate
);
514 SET_TX_DESC_RTS_SC(pdesc
, ptcb_desc
->rts_sc
);
515 SET_TX_DESC_RTS_SHORT(pdesc
,
516 ((ptcb_desc
->rts_rate
<= DESC92C_RATE54M
) ?
517 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
518 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
520 if (ptcb_desc
->tx_enable_sw_calc_duration
)
521 SET_TX_DESC_NAV_USE_HDR(pdesc
, 1);
524 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
525 SET_TX_DESC_DATA_BW(pdesc
, 1);
526 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 3);
528 SET_TX_DESC_DATA_BW(pdesc
, 0);
529 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, mac
->cur_40_prime_sc
);
532 SET_TX_DESC_DATA_BW(pdesc
, 0);
533 SET_TX_DESC_TX_SUB_CARRIER(pdesc
, 0);
536 SET_TX_DESC_LINIP(pdesc
, 0);
537 SET_TX_DESC_PKT_SIZE(pdesc
, (u16
) skb_len
);
539 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
540 SET_TX_DESC_AMPDU_DENSITY(pdesc
, ampdu_density
);
542 if (info
->control
.hw_key
) {
543 struct ieee80211_key_conf
*keyconf
=
544 info
->control
.hw_key
;
545 switch (keyconf
->cipher
) {
546 case WLAN_CIPHER_SUITE_WEP40
:
547 case WLAN_CIPHER_SUITE_WEP104
:
548 case WLAN_CIPHER_SUITE_TKIP
:
549 SET_TX_DESC_SEC_TYPE(pdesc
, 0x1);
551 case WLAN_CIPHER_SUITE_CCMP
:
552 SET_TX_DESC_SEC_TYPE(pdesc
, 0x3);
555 SET_TX_DESC_SEC_TYPE(pdesc
, 0x0);
560 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_qsel
);
561 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc
, 0x1F);
562 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc
, 0xF);
563 SET_TX_DESC_DISABLE_FB(pdesc
, ptcb_desc
->disable_ratefallback
?
565 SET_TX_DESC_USE_RATE(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
567 /* Set TxRate and RTSRate in TxDesc */
568 /* This prevent Tx initial rate of new-coming packets */
569 /* from being overwritten by retried packet rate.*/
570 if (ieee80211_is_data_qos(fc
)) {
572 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
573 "Enable RDG function.\n");
574 SET_TX_DESC_RDG_ENABLE(pdesc
, 1);
575 SET_TX_DESC_HTC(pdesc
, 1);
580 SET_TX_DESC_FIRST_SEG(pdesc
, (firstseg
? 1 : 0));
581 SET_TX_DESC_LAST_SEG(pdesc
, (lastseg
? 1 : 0));
582 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
) buf_len
);
583 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
584 /* if (rtlpriv->dm.useramask) { */
586 SET_TX_DESC_RATE_ID(pdesc
, ptcb_desc
->ratr_index
);
587 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
589 SET_TX_DESC_RATE_ID(pdesc
, 0xC + ptcb_desc
->ratr_index
);
590 SET_TX_DESC_MACID(pdesc
, ptcb_desc
->mac_id
);
592 if (!ieee80211_is_data_qos(fc
)) {
593 SET_TX_DESC_HWSEQ_EN(pdesc
, 1);
594 SET_TX_DESC_HWSEQ_SEL(pdesc
, 0);
596 SET_TX_DESC_MORE_FRAG(pdesc
, (lastseg
? 0 : 1));
597 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
598 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
599 SET_TX_DESC_BMC(pdesc
, 1);
602 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
605 void rtl8723be_tx_fill_cmddesc(struct ieee80211_hw
*hw
, u8
*pdesc
,
606 bool firstseg
, bool lastseg
,
609 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
610 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
611 u8 fw_queue
= QSLT_BEACON
;
613 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
617 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
618 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
619 "DMA mapping error");
622 CLEAR_PCI_TX_DESC_CONTENT(pdesc
, TX_DESC_SIZE
);
624 SET_TX_DESC_OFFSET(pdesc
, USB_HWDESC_HEADER_LEN
);
626 SET_TX_DESC_TX_RATE(pdesc
, DESC92C_RATE1M
);
628 SET_TX_DESC_SEQ(pdesc
, 0);
630 SET_TX_DESC_LINIP(pdesc
, 0);
632 SET_TX_DESC_QUEUE_SEL(pdesc
, fw_queue
);
634 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
635 SET_TX_DESC_LAST_SEG(pdesc
, 1);
637 SET_TX_DESC_TX_BUFFER_SIZE(pdesc
, (u16
)(skb
->len
));
639 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
, mapping
);
641 SET_TX_DESC_RATE_ID(pdesc
, 0);
642 SET_TX_DESC_MACID(pdesc
, 0);
644 SET_TX_DESC_OWN(pdesc
, 1);
646 SET_TX_DESC_PKT_SIZE((u8
*)pdesc
, (u16
)(skb
->len
));
648 SET_TX_DESC_FIRST_SEG(pdesc
, 1);
649 SET_TX_DESC_LAST_SEG(pdesc
, 1);
651 SET_TX_DESC_USE_RATE(pdesc
, 1);
653 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
654 "H2C Tx Cmd Content\n", pdesc
, TX_DESC_SIZE
);
657 void rtl8723be_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc
,
658 bool istx
, u8 desc_name
, u8
*val
)
663 SET_TX_DESC_OWN(pdesc
, 1);
665 case HW_DESC_TX_NEXTDESC_ADDR
:
666 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc
, *(u32
*)val
);
669 RT_ASSERT(false, "ERR txdesc :%d not process\n",
676 SET_RX_DESC_OWN(pdesc
, 1);
678 case HW_DESC_RXBUFF_ADDR
:
679 SET_RX_DESC_BUFF_ADDR(pdesc
, *(u32
*)val
);
681 case HW_DESC_RXPKT_LEN
:
682 SET_RX_DESC_PKT_LEN(pdesc
, *(u32
*)val
);
685 SET_RX_DESC_EOR(pdesc
, 1);
688 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
695 u32
rtl8723be_get_desc(u8
*pdesc
, bool istx
, u8 desc_name
)
702 ret
= GET_TX_DESC_OWN(pdesc
);
704 case HW_DESC_TXBUFF_ADDR
:
705 ret
= GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc
);
708 RT_ASSERT(false, "ERR txdesc :%d not process\n",
715 ret
= GET_RX_DESC_OWN(pdesc
);
717 case HW_DESC_RXPKT_LEN
:
718 ret
= GET_RX_DESC_PKT_LEN(pdesc
);
720 case HW_DESC_RXBUFF_ADDR
:
721 ret
= GET_RX_DESC_BUFF_ADDR(pdesc
);
724 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
732 bool rtl8723be_is_tx_desc_closed(struct ieee80211_hw
*hw
,
733 u8 hw_queue
, u16 index
)
735 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
736 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
737 u8
*entry
= (u8
*)(&ring
->desc
[ring
->idx
]);
738 u8 own
= (u8
)rtl8723be_get_desc(entry
, true, HW_DESC_OWN
);
740 /*beacon packet will only use the first
741 *descriptor defautly,and the own may not
742 *be cleared by the hardware
749 void rtl8723be_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)
751 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
752 if (hw_queue
== BEACON_QUEUE
) {
753 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
, BIT(4));
755 rtl_write_word(rtlpriv
, REG_PCIE_CTRL_REG
,
756 BIT(0) << (hw_queue
));
760 u32
rtl8723be_rx_command_packet(struct ieee80211_hw
*hw
,
761 const struct rtl_stats
*status
,
765 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
767 switch (status
->packet_report_type
) {
772 rtl8723be_c2h_packet_handler(hw
, skb
->data
,
777 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_TRACE
,
778 "No this packet type!!\n");