1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
16 static u8
_rtl92ee_map_hwqueue_to_fwqueue(struct sk_buff
*skb
, u8 hw_queue
)
18 __le16 fc
= rtl_get_fc(skb
);
20 if (unlikely(ieee80211_is_beacon(fc
)))
22 if (ieee80211_is_mgmt(fc
) || ieee80211_is_ctl(fc
))
28 static void _rtl92ee_query_rxphystatus(struct ieee80211_hw
*hw
,
29 struct rtl_stats
*pstatus
, u8
*pdesc
,
30 struct rx_fwinfo
*p_drvinfo
,
31 bool bpacket_match_bssid
,
35 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
36 struct phy_status_rpt
*p_phystrpt
= (struct phy_status_rpt
*)p_drvinfo
;
37 s8 rx_pwr_all
, rx_pwr
[4];
38 u8 rf_rx_num
= 0, evm
, pwdb_all
;
39 u8 i
, max_spatial_stream
;
40 u32 rssi
, total_rssi
= 0;
41 bool is_cck
= pstatus
->is_cck
;
44 /* Record it for next packet processing */
45 pstatus
->packet_matchbssid
= bpacket_match_bssid
;
46 pstatus
->packet_toself
= bpacket_toself
;
47 pstatus
->packet_beacon
= packet_beacon
;
48 pstatus
->rx_mimo_signalquality
[0] = -1;
49 pstatus
->rx_mimo_signalquality
[1] = -1;
54 /* CCK Driver info Structure is not the same as OFDM packet. */
55 cck_agc_rpt
= p_phystrpt
->cck_agc_rpt_ofdm_cfosho_a
;
57 /* (1)Hardware does not provide RSSI for CCK
58 * (2)PWDB, Average PWDB cacluated by
59 * hardware (for rate adaptive)
61 cck_highpwr
= (u8
)rtl_get_bbreg(hw
, RFPGA0_XA_HSSIPARAMETER2
,
64 lan_idx
= ((cck_agc_rpt
& 0xE0) >> 5);
65 vga_idx
= (cck_agc_rpt
& 0x1f);
67 case 7: /*VGA_idx = 27~2*/
69 rx_pwr_all
= -100 + 2 * (27 - vga_idx
);
73 case 6: /*VGA_idx = 2~0*/
74 rx_pwr_all
= -48 + 2 * (2 - vga_idx
);
76 case 5: /*VGA_idx = 7~5*/
77 rx_pwr_all
= -42 + 2 * (7 - vga_idx
);
79 case 4: /*VGA_idx = 7~4*/
80 rx_pwr_all
= -36 + 2 * (7 - vga_idx
);
82 case 3: /*VGA_idx = 7~0*/
83 rx_pwr_all
= -24 + 2 * (7 - vga_idx
);
85 case 2: /*VGA_idx = 5~0*/
87 rx_pwr_all
= -12 + 2 * (5 - vga_idx
);
89 rx_pwr_all
= -6 + 2 * (5 - vga_idx
);
92 rx_pwr_all
= 8 - 2 * vga_idx
;
95 rx_pwr_all
= 14 - 2 * vga_idx
;
102 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
106 pwdb_all
= ((pwdb_all
- 80) << 1) +
107 ((pwdb_all
- 80) >> 1) + 80;
108 else if ((pwdb_all
<= 78) && (pwdb_all
>= 20))
114 pstatus
->rx_pwdb_all
= pwdb_all
;
115 pstatus
->bt_rx_rssi_percentage
= pwdb_all
;
116 pstatus
->recvsignalpower
= rx_pwr_all
;
118 /* (3) Get Signal Quality (EVM) */
119 if (bpacket_match_bssid
) {
122 if (pstatus
->rx_pwdb_all
> 40) {
125 sq_rpt
= p_phystrpt
->cck_sig_qual_ofdm_pwdb_all
;
128 else if (sq_rpt
< 20)
131 sq
= ((64 - sq_rpt
) * 100) / 44;
134 pstatus
->signalquality
= sq
;
135 pstatus
->rx_mimo_signalquality
[0] = sq
;
136 pstatus
->rx_mimo_signalquality
[1] = -1;
139 /* (1)Get RSSI for HT rate */
140 for (i
= RF90_PATH_A
; i
< RF6052_MAX_PATH
; i
++) {
141 /* we will judge RF RX path now. */
142 if (rtlpriv
->dm
.rfpath_rxenable
[i
])
145 rx_pwr
[i
] = ((p_phystrpt
->path_agc
[i
].gain
& 0x3f) * 2)
148 pstatus
->rx_pwr
[i
] = rx_pwr
[i
];
149 /* Translate DBM to percentage. */
150 rssi
= rtl_query_rxpwrpercentage(rx_pwr
[i
]);
153 pstatus
->rx_mimo_signalstrength
[i
] = (u8
)rssi
;
156 /* (2)PWDB, Average PWDB cacluated by
157 * hardware (for rate adaptive)
159 rx_pwr_all
= ((p_phystrpt
->cck_sig_qual_ofdm_pwdb_all
>> 1)
162 pwdb_all
= rtl_query_rxpwrpercentage(rx_pwr_all
);
163 pstatus
->rx_pwdb_all
= pwdb_all
;
164 pstatus
->bt_rx_rssi_percentage
= pwdb_all
;
165 pstatus
->rxpower
= rx_pwr_all
;
166 pstatus
->recvsignalpower
= rx_pwr_all
;
168 /* (3)EVM of HT rate */
169 if (pstatus
->rate
>= DESC_RATEMCS8
&&
170 pstatus
->rate
<= DESC_RATEMCS15
)
171 max_spatial_stream
= 2;
173 max_spatial_stream
= 1;
175 for (i
= 0; i
< max_spatial_stream
; i
++) {
176 evm
= rtl_evm_db_to_percentage(
177 p_phystrpt
->stream_rxevm
[i
]);
179 if (bpacket_match_bssid
) {
180 /* Fill value in RFD, Get the first
181 * spatial stream only
184 pstatus
->signalquality
= (u8
)(evm
&
186 pstatus
->rx_mimo_signalquality
[i
] = (u8
)(evm
&
191 if (bpacket_match_bssid
) {
192 for (i
= RF90_PATH_A
; i
<= RF90_PATH_B
; i
++)
193 rtl_priv(hw
)->dm
.cfo_tail
[i
] =
194 (int)p_phystrpt
->path_cfotail
[i
];
196 if (rtl_priv(hw
)->dm
.packet_count
== 0xffffffff)
197 rtl_priv(hw
)->dm
.packet_count
= 0;
199 rtl_priv(hw
)->dm
.packet_count
++;
203 /* UI BSS List signal strength(in percentage),
204 * make it good looking, from 0~100.
207 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
209 else if (rf_rx_num
!= 0)
210 pstatus
->signalstrength
= (u8
)(rtl_signal_scale_mapping(hw
,
211 total_rssi
/= rf_rx_num
));
214 static void _rtl92ee_translate_rx_signal_stuff(struct ieee80211_hw
*hw
,
216 struct rtl_stats
*pstatus
,
218 struct rx_fwinfo
*p_drvinfo
)
220 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
221 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
222 struct ieee80211_hdr
*hdr
;
227 bool packet_matchbssid
, packet_toself
, packet_beacon
;
229 tmp_buf
= skb
->data
+ pstatus
->rx_drvinfo_size
+
230 pstatus
->rx_bufshift
+ 24;
232 hdr
= (struct ieee80211_hdr
*)tmp_buf
;
233 fc
= hdr
->frame_control
;
235 psaddr
= ieee80211_get_SA(hdr
);
236 ether_addr_copy(pstatus
->psaddr
, psaddr
);
238 packet_matchbssid
= (!ieee80211_is_ctl(fc
) &&
239 (ether_addr_equal(mac
->bssid
,
240 ieee80211_has_tods(fc
) ?
242 ieee80211_has_fromds(fc
) ?
243 hdr
->addr2
: hdr
->addr3
)) &&
244 (!pstatus
->hwerror
) && (!pstatus
->crc
) &&
247 packet_toself
= packet_matchbssid
&&
248 (ether_addr_equal(praddr
, rtlefuse
->dev_addr
));
250 if (ieee80211_is_beacon(fc
))
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 if (packet_matchbssid
&& ieee80211_is_data_qos(hdr
->frame_control
) &&
259 !is_multicast_ether_addr(ieee80211_get_DA(hdr
))) {
260 struct ieee80211_qos_hdr
*hdr_qos
=
261 (struct ieee80211_qos_hdr
*)tmp_buf
;
262 u16 tid
= le16_to_cpu(hdr_qos
->qos_ctrl
) & 0xf;
264 if (tid
!= 0 && tid
!= 3)
265 rtl_priv(hw
)->dm
.dbginfo
.num_non_be_pkt
++;
268 _rtl92ee_query_rxphystatus(hw
, pstatus
, pdesc
, p_drvinfo
,
269 packet_matchbssid
, packet_toself
,
271 rtl_process_phyinfo(hw
, tmp_buf
, pstatus
);
274 static void _rtl92ee_insert_emcontent(struct rtl_tcb_desc
*ptcb_desc
,
278 __le32
*virtualaddress
= (__le32
*)virtualaddress8
;
280 memset(virtualaddress
, 0, 8);
282 set_earlymode_pktnum(virtualaddress
, ptcb_desc
->empkt_num
);
283 if (ptcb_desc
->empkt_num
== 1) {
284 dwtmp
= ptcb_desc
->empkt_len
[0];
286 dwtmp
= ptcb_desc
->empkt_len
[0];
287 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
288 dwtmp
+= ptcb_desc
->empkt_len
[1];
290 set_earlymode_len0(virtualaddress
, dwtmp
);
292 if (ptcb_desc
->empkt_num
<= 3) {
293 dwtmp
= ptcb_desc
->empkt_len
[2];
295 dwtmp
= ptcb_desc
->empkt_len
[2];
296 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
297 dwtmp
+= ptcb_desc
->empkt_len
[3];
299 set_earlymode_len1(virtualaddress
, dwtmp
);
300 if (ptcb_desc
->empkt_num
<= 5) {
301 dwtmp
= ptcb_desc
->empkt_len
[4];
303 dwtmp
= ptcb_desc
->empkt_len
[4];
304 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
305 dwtmp
+= ptcb_desc
->empkt_len
[5];
307 set_earlymode_len2_1(virtualaddress
, dwtmp
& 0xF);
308 set_earlymode_len2_2(virtualaddress
, dwtmp
>> 4);
309 if (ptcb_desc
->empkt_num
<= 7) {
310 dwtmp
= ptcb_desc
->empkt_len
[6];
312 dwtmp
= ptcb_desc
->empkt_len
[6];
313 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
314 dwtmp
+= ptcb_desc
->empkt_len
[7];
316 set_earlymode_len3(virtualaddress
, dwtmp
);
317 if (ptcb_desc
->empkt_num
<= 9) {
318 dwtmp
= ptcb_desc
->empkt_len
[8];
320 dwtmp
= ptcb_desc
->empkt_len
[8];
321 dwtmp
+= ((dwtmp
% 4) ? (4 - dwtmp
% 4) : 0) + 4;
322 dwtmp
+= ptcb_desc
->empkt_len
[9];
324 set_earlymode_len4(virtualaddress
, dwtmp
);
327 bool rtl92ee_rx_query_desc(struct ieee80211_hw
*hw
,
328 struct rtl_stats
*status
,
329 struct ieee80211_rx_status
*rx_status
,
330 u8
*pdesc8
, struct sk_buff
*skb
)
332 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
333 struct rx_fwinfo
*p_drvinfo
;
334 struct ieee80211_hdr
*hdr
;
335 __le32
*pdesc
= (__le32
*)pdesc8
;
336 u32 phystatus
= get_rx_desc_physt(pdesc
);
339 if (get_rx_status_desc_rpt_sel(pdesc
) == 0)
340 status
->packet_report_type
= NORMAL_RX
;
342 status
->packet_report_type
= C2H_PACKET
;
343 status
->length
= (u16
)get_rx_desc_pkt_len(pdesc
);
344 status
->rx_drvinfo_size
= (u8
)get_rx_desc_drv_info_size(pdesc
) *
345 RX_DRV_INFO_SIZE_UNIT
;
346 status
->rx_bufshift
= (u8
)(get_rx_desc_shift(pdesc
) & 0x03);
347 status
->icv
= (u16
)get_rx_desc_icv(pdesc
);
348 status
->crc
= (u16
)get_rx_desc_crc32(pdesc
);
349 status
->hwerror
= (status
->crc
| status
->icv
);
350 status
->decrypted
= !get_rx_desc_swdec(pdesc
);
351 status
->rate
= (u8
)get_rx_desc_rxmcs(pdesc
);
352 status
->isampdu
= (bool)(get_rx_desc_paggr(pdesc
) == 1);
353 status
->timestamp_low
= get_rx_desc_tsfl(pdesc
);
354 status
->is_cck
= RTL92EE_RX_HAL_IS_CCK_RATE(status
->rate
);
356 status
->macid
= get_rx_desc_macid(pdesc
);
357 if (get_rx_status_desc_pattern_match(pdesc
))
359 else if (get_rx_status_desc_magic_match(pdesc
))
361 else if (get_rx_status_desc_unicast_match(pdesc
))
366 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_LOUD
,
367 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
369 rx_status
->freq
= hw
->conf
.chandef
.chan
->center_freq
;
370 rx_status
->band
= hw
->conf
.chandef
.chan
->band
;
372 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ status
->rx_drvinfo_size
+
373 status
->rx_bufshift
+ 24);
376 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
378 if (status
->rx_is40mhzpacket
)
379 rx_status
->bw
= RATE_INFO_BW_40
;
382 rx_status
->encoding
= RX_ENC_HT
;
384 rx_status
->flag
|= RX_FLAG_MACTIME_START
;
386 /* hw will set status->decrypted true, if it finds the
387 * frame is open data frame or mgmt frame.
388 * So hw will not decryption robust managment frame
389 * for IEEE80211w but still set status->decrypted
390 * true, so here we should set it back to undecrypted
391 * for IEEE80211w frame, and mac80211 sw will help
394 if (status
->decrypted
) {
395 if ((!_ieee80211_is_robust_mgmt_frame(hdr
)) &&
396 (ieee80211_has_protected(hdr
->frame_control
)))
397 rx_status
->flag
|= RX_FLAG_DECRYPTED
;
399 rx_status
->flag
&= ~RX_FLAG_DECRYPTED
;
402 /* rate_idx: index of data rate into band's
403 * supported rates or MCS index if HT rates
404 * are use (RX_FLAG_HT)
405 * Notice: this is diff with windows define
407 rx_status
->rate_idx
= rtlwifi_rate_mapping(hw
, status
->is_ht
,
408 false, status
->rate
);
410 rx_status
->mactime
= status
->timestamp_low
;
412 p_drvinfo
= (struct rx_fwinfo
*)(skb
->data
+
413 status
->rx_bufshift
+ 24);
415 _rtl92ee_translate_rx_signal_stuff(hw
, skb
, status
, pdesc8
,
418 rx_status
->signal
= status
->recvsignalpower
+ 10;
419 if (status
->packet_report_type
== TX_REPORT2
) {
420 status
->macid_valid_entry
[0] =
421 get_rx_rpt2_desc_macid_valid_1(pdesc
);
422 status
->macid_valid_entry
[1] =
423 get_rx_rpt2_desc_macid_valid_2(pdesc
);
428 /*in Windows, this == Rx_92EE_Interrupt*/
429 void rtl92ee_rx_check_dma_ok(struct ieee80211_hw
*hw
, u8
*header_desc8
,
436 __le32
*header_desc
= (__le32
*)header_desc8
;
438 if (header_desc
== NULL
)
441 total_len
= (u16
)get_rx_buffer_desc_total_length(header_desc
);
443 first_seg
= (u8
)get_rx_buffer_desc_fs(header_desc
);
445 last_seg
= (u8
)get_rx_buffer_desc_ls(header_desc
);
447 while (total_len
== 0 && first_seg
== 0 && last_seg
== 0) {
449 total_len
= (u16
)get_rx_buffer_desc_total_length(header_desc
);
450 first_seg
= (u8
)get_rx_buffer_desc_fs(header_desc
);
451 last_seg
= (u8
)get_rx_buffer_desc_ls(header_desc
);
458 u16
rtl92ee_rx_desc_buff_remained_cnt(struct ieee80211_hw
*hw
, u8 queue_index
)
460 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
461 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
462 u16 read_point
, write_point
, remind_cnt
;
464 static bool start_rx
;
466 tmp_4byte
= rtl_read_dword(rtlpriv
, REG_RXQ_TXBD_IDX
);
467 read_point
= (u16
)((tmp_4byte
>>16) & 0x7ff);
468 write_point
= (u16
)(tmp_4byte
& 0x7ff);
470 if (write_point
!= rtlpci
->rx_ring
[queue_index
].next_rx_rp
) {
471 RT_TRACE(rtlpriv
, COMP_RXDESC
, DBG_DMESG
,
472 "!!!write point is 0x%x, reg 0x3B4 value is 0x%x\n",
473 write_point
, tmp_4byte
);
474 tmp_4byte
= rtl_read_dword(rtlpriv
, REG_RXQ_TXBD_IDX
);
475 read_point
= (u16
)((tmp_4byte
>>16) & 0x7ff);
476 write_point
= (u16
)(tmp_4byte
& 0x7ff);
484 remind_cnt
= calc_fifo_space(read_point
, write_point
,
485 RTL_PCI_MAX_RX_COUNT
);
490 rtlpci
->rx_ring
[queue_index
].next_rx_rp
= write_point
;
495 static u16
get_desc_addr_fr_q_idx(u16 queue_index
)
499 switch (queue_index
) {
501 desc_address
= REG_BKQ_TXBD_IDX
;
504 desc_address
= REG_BEQ_TXBD_IDX
;
507 desc_address
= REG_VIQ_TXBD_IDX
;
510 desc_address
= REG_VOQ_TXBD_IDX
;
513 desc_address
= REG_BEQ_TXBD_IDX
;
516 desc_address
= REG_BEQ_TXBD_IDX
;
519 desc_address
= REG_MGQ_TXBD_IDX
;
522 desc_address
= REG_HI0Q_TXBD_IDX
;
525 desc_address
= REG_BEQ_TXBD_IDX
;
528 desc_address
= REG_BEQ_TXBD_IDX
;
534 u16
rtl92ee_get_available_desc(struct ieee80211_hw
*hw
, u8 q_idx
)
536 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
538 u16 current_tx_read_point
, current_tx_write_point
;
541 tmp_4byte
= rtl_read_dword(rtlpriv
,
542 get_desc_addr_fr_q_idx(q_idx
));
543 current_tx_read_point
= (u16
)((tmp_4byte
>> 16) & 0x0fff);
544 current_tx_write_point
= (u16
)((tmp_4byte
) & 0x0fff);
546 point_diff
= calc_fifo_space(current_tx_read_point
,
547 current_tx_write_point
,
553 void rtl92ee_pre_fill_tx_bd_desc(struct ieee80211_hw
*hw
,
554 u8
*tx_bd_desc8
, u8
*desc8
, u8 queue_index
,
555 struct sk_buff
*skb
, dma_addr_t addr
)
557 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
558 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
559 u32 pkt_len
= skb
->len
;
560 u16 desc_size
= 40; /*tx desc size*/
563 u32 total_packet_size
;
566 u16 real_desc_size
= 0x28;
567 u16 append_early_mode_size
= 0;
568 u8 segmentnum
= 1 << (RTL8192EE_SEG_NUM
+ 1);
569 dma_addr_t desc_dma_addr
;
570 bool dma64
= rtlpriv
->cfg
->mod_params
->dma64
;
571 __le32
*desc
= (__le32
*)desc8
;
572 __le32
*tx_bd_desc
= (__le32
*)tx_bd_desc8
;
575 current_bd_desc
= rtlpci
->tx_ring
[queue_index
].cur_tx_wp
;
577 total_packet_size
= desc_size
+pkt_len
;
579 if (rtlpriv
->rtlhal
.earlymode_enable
) {
580 if (queue_index
< BEACON_QUEUE
) {
581 append_early_mode_size
= 8;
582 total_packet_size
+= append_early_mode_size
;
586 if (tx_page_size
> 0) {
587 psblen
= (pkt_len
+ real_desc_size
+ append_early_mode_size
) /
588 (tx_page_size
* 128);
590 if (psblen
* (tx_page_size
* 128) < total_packet_size
)
595 desc_dma_addr
= rtlpci
->tx_ring
[queue_index
].dma
+
596 (current_bd_desc
* TX_DESC_SIZE
);
599 set_tx_buff_desc_len_0(tx_bd_desc
, 0);
600 set_tx_buff_desc_psb(tx_bd_desc
, 0);
601 set_tx_buff_desc_own(tx_bd_desc
, 0);
603 for (i
= 1; i
< segmentnum
; i
++) {
604 set_txbuffer_desc_len_with_offset(tx_bd_desc
, i
, 0);
605 set_txbuffer_desc_amsdu_with_offset(tx_bd_desc
, i
, 0);
606 set_txbuffer_desc_add_low_with_offset(tx_bd_desc
, i
, 0);
607 set_txbuffer_desc_add_high_with_offset(tx_bd_desc
, i
, 0, dma64
);
610 /* Clear all status */
611 clear_pci_tx_desc_content(desc
, TX_DESC_SIZE
);
613 if (rtlpriv
->rtlhal
.earlymode_enable
) {
614 if (queue_index
< BEACON_QUEUE
) {
615 /* This if needs braces */
616 set_tx_buff_desc_len_0(tx_bd_desc
, desc_size
+ 8);
618 set_tx_buff_desc_len_0(tx_bd_desc
, desc_size
);
621 set_tx_buff_desc_len_0(tx_bd_desc
, desc_size
);
623 set_tx_buff_desc_psb(tx_bd_desc
, psblen
);
624 set_tx_buff_desc_addr_low_0(tx_bd_desc
, desc_dma_addr
);
625 set_tx_buff_desc_addr_high_0(tx_bd_desc
, ((u64
)desc_dma_addr
>> 32),
628 set_txbuffer_desc_len_with_offset(tx_bd_desc
, 1, pkt_len
);
629 /* don't using extendsion mode. */
630 set_txbuffer_desc_amsdu_with_offset(tx_bd_desc
, 1, 0);
631 set_txbuffer_desc_add_low_with_offset(tx_bd_desc
, 1, addr
);
632 set_txbuffer_desc_add_high_with_offset(tx_bd_desc
, 1,
633 ((u64
)addr
>> 32), dma64
);
635 set_tx_desc_pkt_size(desc
, (u16
)(pkt_len
));
636 set_tx_desc_tx_buffer_size(desc
, (u16
)(pkt_len
));
639 void rtl92ee_tx_fill_desc(struct ieee80211_hw
*hw
,
640 struct ieee80211_hdr
*hdr
, u8
*pdesc8
,
642 struct ieee80211_tx_info
*info
,
643 struct ieee80211_sta
*sta
,
645 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
)
647 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
648 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
649 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
650 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
651 struct rtlwifi_tx_info
*tx_info
= rtl_tx_skb_cb_info(skb
);
653 __le16 fc
= hdr
->frame_control
;
654 u8 fw_qsel
= _rtl92ee_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);
661 __le32
*pdesc
= (__le32
*)pdesc8
;
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
);
678 mapping
= pci_map_single(rtlpci
->pdev
, skb
->data
, skb
->len
,
680 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
681 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
682 "DMA mapping error\n");
686 if (pbd_desc_tx
!= NULL
)
687 rtl92ee_pre_fill_tx_bd_desc(hw
, pbd_desc_tx
, pdesc8
, hw_queue
,
690 if (ieee80211_is_nullfunc(fc
) || ieee80211_is_ctl(fc
)) {
695 if (rtlhal
->earlymode_enable
) {
696 set_tx_desc_pkt_offset(pdesc
, 1);
697 set_tx_desc_offset(pdesc
,
698 USB_HWDESC_HEADER_LEN
+ EM_HDR_LEN
);
699 if (ptcb_desc
->empkt_num
) {
700 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
701 "Insert 8 byte.pTcb->EMPktNum:%d\n",
702 ptcb_desc
->empkt_num
);
703 _rtl92ee_insert_emcontent(ptcb_desc
,
707 set_tx_desc_offset(pdesc
, USB_HWDESC_HEADER_LEN
);
711 set_tx_desc_tx_rate(pdesc
, ptcb_desc
->hw_rate
);
713 if (ieee80211_is_mgmt(fc
)) {
714 ptcb_desc
->use_driver_rate
= true;
716 if (rtlpriv
->ra
.is_special_data
) {
717 ptcb_desc
->use_driver_rate
= true;
718 set_tx_desc_tx_rate(pdesc
, DESC_RATE11M
);
720 ptcb_desc
->use_driver_rate
= false;
724 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
725 set_tx_desc_agg_enable(pdesc
, 1);
726 set_tx_desc_max_agg_num(pdesc
, 0x14);
728 set_tx_desc_seq(pdesc
, seq_number
);
729 set_tx_desc_rts_enable(pdesc
,
730 ((ptcb_desc
->rts_enable
&&
731 !ptcb_desc
->cts_enable
) ? 1 : 0));
732 set_tx_desc_hw_rts_enable(pdesc
, 0);
733 set_tx_desc_cts2self(pdesc
,
734 ((ptcb_desc
->cts_enable
) ? 1 : 0));
736 set_tx_desc_rts_rate(pdesc
, ptcb_desc
->rts_rate
);
737 set_tx_desc_rts_sc(pdesc
, ptcb_desc
->rts_sc
);
738 set_tx_desc_rts_short(pdesc
,
739 ((ptcb_desc
->rts_rate
<= DESC_RATE54M
) ?
740 (ptcb_desc
->rts_use_shortpreamble
? 1 : 0) :
741 (ptcb_desc
->rts_use_shortgi
? 1 : 0)));
743 if (ptcb_desc
->tx_enable_sw_calc_duration
)
744 set_tx_desc_nav_use_hdr(pdesc
, 1);
747 if (ptcb_desc
->packet_bw
== HT_CHANNEL_WIDTH_20_40
) {
748 set_tx_desc_data_bw(pdesc
, 1);
749 set_tx_desc_tx_sub_carrier(pdesc
, 3);
751 set_tx_desc_data_bw(pdesc
, 0);
752 set_tx_desc_tx_sub_carrier(pdesc
,
753 mac
->cur_40_prime_sc
);
756 set_tx_desc_data_bw(pdesc
, 0);
757 set_tx_desc_tx_sub_carrier(pdesc
, 0);
760 set_tx_desc_linip(pdesc
, 0);
762 u8 ampdu_density
= sta
->ht_cap
.ampdu_density
;
764 set_tx_desc_ampdu_density(pdesc
, ampdu_density
);
766 if (info
->control
.hw_key
) {
767 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
769 switch (key
->cipher
) {
770 case WLAN_CIPHER_SUITE_WEP40
:
771 case WLAN_CIPHER_SUITE_WEP104
:
772 case WLAN_CIPHER_SUITE_TKIP
:
773 set_tx_desc_sec_type(pdesc
, 0x1);
775 case WLAN_CIPHER_SUITE_CCMP
:
776 set_tx_desc_sec_type(pdesc
, 0x3);
779 set_tx_desc_sec_type(pdesc
, 0x0);
784 set_tx_desc_queue_sel(pdesc
, fw_qsel
);
785 set_tx_desc_data_rate_fb_limit(pdesc
, 0x1F);
786 set_tx_desc_rts_rate_fb_limit(pdesc
, 0xF);
787 set_tx_desc_disable_fb(pdesc
,
788 ptcb_desc
->disable_ratefallback
? 1 : 0);
789 set_tx_desc_use_rate(pdesc
, ptcb_desc
->use_driver_rate
? 1 : 0);
791 /*set_tx_desc_pwr_status(pdesc, pwr_status);*/
792 /* Set TxRate and RTSRate in TxDesc */
793 /* This prevent Tx initial rate of new-coming packets */
794 /* from being overwritten by retried packet rate.*/
795 if (!ptcb_desc
->use_driver_rate
) {
796 /*set_tx_desc_rts_rate(pdesc, 0x08); */
797 /* set_tx_desc_tx_rate(pdesc, 0x0b); */
799 if (ieee80211_is_data_qos(fc
)) {
801 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
802 "Enable RDG function.\n");
803 set_tx_desc_rdg_enable(pdesc
, 1);
804 set_tx_desc_htc(pdesc
, 1);
808 rtl_set_tx_report(ptcb_desc
, pdesc8
, hw
, tx_info
);
811 set_tx_desc_first_seg(pdesc
, (firstseg
? 1 : 0));
812 set_tx_desc_last_seg(pdesc
, (lastseg
? 1 : 0));
813 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
814 if (rtlpriv
->dm
.useramask
) {
815 set_tx_desc_rate_id(pdesc
, ptcb_desc
->ratr_index
);
816 set_tx_desc_macid(pdesc
, ptcb_desc
->mac_id
);
818 set_tx_desc_rate_id(pdesc
, 0xC + ptcb_desc
->ratr_index
);
819 set_tx_desc_macid(pdesc
, ptcb_desc
->ratr_index
);
822 set_tx_desc_more_frag(pdesc
, (lastseg
? 0 : 1));
823 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)) ||
824 is_broadcast_ether_addr(ieee80211_get_DA(hdr
))) {
825 set_tx_desc_bmc(pdesc
, 1);
827 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
, "\n");
830 void rtl92ee_tx_fill_cmddesc(struct ieee80211_hw
*hw
,
831 u8
*pdesc8
, bool firstseg
,
832 bool lastseg
, struct sk_buff
*skb
)
834 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
835 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
836 u8 fw_queue
= QSLT_BEACON
;
837 dma_addr_t mapping
= pci_map_single(rtlpci
->pdev
,
841 __le32
*pdesc
= (__le32
*)pdesc8
;
843 if (pci_dma_mapping_error(rtlpci
->pdev
, mapping
)) {
844 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_TRACE
,
845 "DMA mapping error\n");
848 clear_pci_tx_desc_content(pdesc
, txdesc_len
);
851 set_tx_desc_offset(pdesc
, txdesc_len
);
853 set_tx_desc_tx_rate(pdesc
, DESC_RATE1M
);
855 set_tx_desc_seq(pdesc
, 0);
857 set_tx_desc_linip(pdesc
, 0);
859 set_tx_desc_queue_sel(pdesc
, fw_queue
);
861 set_tx_desc_first_seg(pdesc
, 1);
862 set_tx_desc_last_seg(pdesc
, 1);
864 set_tx_desc_tx_buffer_size(pdesc
, (u16
)(skb
->len
));
866 set_tx_desc_tx_buffer_address(pdesc
, mapping
);
868 set_tx_desc_rate_id(pdesc
, 7);
869 set_tx_desc_macid(pdesc
, 0);
871 set_tx_desc_own(pdesc
, 1);
873 set_tx_desc_pkt_size(pdesc
, (u16
)(skb
->len
));
875 set_tx_desc_first_seg(pdesc
, 1);
876 set_tx_desc_last_seg(pdesc
, 1);
878 set_tx_desc_offset(pdesc
, 40);
880 set_tx_desc_use_rate(pdesc
, 1);
882 RT_PRINT_DATA(rtlpriv
, COMP_CMD
, DBG_LOUD
,
883 "H2C Tx Cmd Content\n", pdesc
, txdesc_len
);
886 void rtl92ee_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc8
, bool istx
,
887 u8 desc_name
, u8
*val
)
889 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
891 bool dma64
= rtlpriv
->cfg
->mod_params
->dma64
;
892 __le32
*pdesc
= (__le32
*)pdesc8
;
896 case HW_DESC_TX_NEXTDESC_ADDR
:
897 set_tx_desc_next_desc_address(pdesc
, *(u32
*)val
);
900 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
901 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[q_idx
];
902 u16 max_tx_desc
= ring
->entries
;
904 if (q_idx
== BEACON_QUEUE
) {
907 set_tx_buff_desc_own(pdesc
, 1);
911 /* make sure tx desc is available by caller */
912 ring
->cur_tx_wp
= ((ring
->cur_tx_wp
+ 1) % max_tx_desc
);
914 rtl_write_word(rtlpriv
,
915 get_desc_addr_fr_q_idx(q_idx
),
922 case HW_DESC_RX_PREPARE
:
923 set_rx_buffer_desc_ls(pdesc
, 0);
924 set_rx_buffer_desc_fs(pdesc
, 0);
925 set_rx_buffer_desc_total_length(pdesc
, 0);
927 set_rx_buffer_desc_data_length(pdesc
,
928 MAX_RECEIVE_BUFFER_SIZE
+
931 set_rx_buffer_physical_low(pdesc
, (*(dma_addr_t
*)val
) &
933 set_rx_buffer_physical_high(pdesc
,
934 ((u64
)(*(dma_addr_t
*)val
)
939 set_rx_desc_eor(pdesc
, 1);
943 "rtl8192ee: ERR rxdesc :%d not processed\n",
950 u64
rtl92ee_get_desc(struct ieee80211_hw
*hw
,
951 u8
*pdesc8
, bool istx
, u8 desc_name
)
953 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
955 bool dma64
= rtlpriv
->cfg
->mod_params
->dma64
;
956 __le32
*pdesc
= (__le32
*)pdesc8
;
961 ret
= get_tx_desc_own(pdesc
);
963 case HW_DESC_TXBUFF_ADDR
:
964 ret
= get_txbuffer_desc_addr_low(pdesc
, 1);
965 ret
|= (u64
)get_txbuffer_desc_addr_high(pdesc
, 1,
970 "rtl8192ee: ERR txdesc :%d not processed\n",
977 ret
= get_rx_desc_own(pdesc
);
979 case HW_DESC_RXPKT_LEN
:
980 ret
= get_rx_desc_pkt_len(pdesc
);
982 case HW_DESC_RXBUFF_ADDR
:
983 ret
= get_rx_desc_buff_addr(pdesc
);
987 "rtl8192ee: ERR rxdesc :%d not processed\n",
995 bool rtl92ee_is_tx_desc_closed(struct ieee80211_hw
*hw
, u8 hw_queue
, u16 index
)
997 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
998 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
999 u16 read_point
, write_point
;
1001 static u8 stop_report_cnt
;
1002 struct rtl8192_tx_ring
*ring
= &rtlpci
->tx_ring
[hw_queue
];
1009 rtl_read_dword(rtlpriv
,
1010 get_desc_addr_fr_q_idx(hw_queue
));
1011 cur_tx_rp
= (u16
)((tmpu32
>> 16) & 0x0fff);
1013 /* don't need to update ring->cur_tx_wp */
1014 ring
->cur_tx_rp
= cur_tx_rp
;
1017 read_point
= ring
->cur_tx_rp
;
1018 write_point
= ring
->cur_tx_wp
;
1020 if (write_point
> read_point
) {
1021 if (index
< write_point
&& index
>= read_point
)
1025 } else if (write_point
< read_point
) {
1026 if (index
> write_point
&& index
< read_point
)
1031 if (index
!= read_point
)
1035 if (hw_queue
== BEACON_QUEUE
)
1038 if (rtlpriv
->rtlhal
.driver_is_goingto_unload
||
1039 rtlpriv
->psc
.rfoff_reason
> RF_CHANGE_BY_PS
)
1042 if (hw_queue
< BEACON_QUEUE
) {
1046 stop_report_cnt
= 0;
1052 void rtl92ee_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
)