1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2009-2014 Realtek Corporation.*/
4 #ifndef __RTL92E_TRX_H__
5 #define __RTL92E_TRX_H__
7 #define TX_DESC_SIZE 64
9 #define RX_DRV_INFO_SIZE_UNIT 8
11 #define TX_DESC_NEXT_DESC_OFFSET 40
12 #define USB_HWDESC_HEADER_LEN 40
14 #define RX_DESC_SIZE 24
15 #define MAX_RECEIVE_BUFFER_SIZE 8192
17 static inline void set_tx_desc_pkt_size(__le32
*__pdesc
, u32 __val
)
19 le32p_replace_bits(__pdesc
, __val
, GENMASK(15, 0));
22 static inline void set_tx_desc_offset(__le32
*__pdesc
, u32 __val
)
24 le32p_replace_bits(__pdesc
, __val
, GENMASK(23, 16));
27 static inline void set_tx_desc_bmc(__le32
*__pdesc
, u32 __val
)
29 le32p_replace_bits(__pdesc
, __val
, BIT(24));
32 static inline void set_tx_desc_htc(__le32
*__pdesc
, u32 __val
)
34 le32p_replace_bits(__pdesc
, __val
, BIT(25));
37 static inline void set_tx_desc_last_seg(__le32
*__pdesc
, u32 __val
)
39 le32p_replace_bits(__pdesc
, __val
, BIT(26));
42 static inline void set_tx_desc_first_seg(__le32
*__pdesc
, u32 __val
)
44 le32p_replace_bits(__pdesc
, __val
, BIT(27));
47 static inline void set_tx_desc_linip(__le32
*__pdesc
, u32 __val
)
49 le32p_replace_bits(__pdesc
, __val
, BIT(28));
52 static inline void set_tx_desc_own(__le32
*__pdesc
, u32 __val
)
54 le32p_replace_bits(__pdesc
, __val
, BIT(31));
57 static inline int get_tx_desc_own(__le32
*__pdesc
)
59 return le32_get_bits(*(__pdesc
), BIT(31));
62 static inline void set_tx_desc_macid(__le32
*__pdesc
, u32 __val
)
64 le32p_replace_bits((__pdesc
+ 1), __val
, GENMASK(6, 0));
67 static inline void set_tx_desc_queue_sel(__le32
*__pdesc
, u32 __val
)
69 le32p_replace_bits((__pdesc
+ 1), __val
, GENMASK(12, 8));
72 static inline void set_tx_desc_rate_id(__le32
*__pdesc
, u32 __val
)
74 le32p_replace_bits((__pdesc
+ 1), __val
, GENMASK(20, 16));
77 static inline void set_tx_desc_sec_type(__le32
*__pdesc
, u32 __val
)
79 le32p_replace_bits((__pdesc
+ 1), __val
, GENMASK(23, 22));
82 static inline void set_tx_desc_pkt_offset(__le32
*__pdesc
, u32 __val
)
84 le32p_replace_bits((__pdesc
+ 1), __val
, GENMASK(28, 24));
87 static inline void set_tx_desc_agg_enable(__le32
*__pdesc
, u32 __val
)
89 le32p_replace_bits((__pdesc
+ 2), __val
, BIT(12));
92 static inline void set_tx_desc_rdg_enable(__le32
*__pdesc
, u32 __val
)
94 le32p_replace_bits((__pdesc
+ 2), __val
, BIT(13));
97 static inline void set_tx_desc_more_frag(__le32
*__pdesc
, u32 __val
)
99 le32p_replace_bits((__pdesc
+ 2), __val
, BIT(17));
102 static inline void set_tx_desc_ampdu_density(__le32
*__pdesc
, u32 __val
)
104 le32p_replace_bits((__pdesc
+ 2), __val
, GENMASK(22, 20));
107 static inline void set_tx_desc_use_rate(__le32
*__pdesc
, u32 __val
)
109 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(8));
112 static inline void set_tx_desc_disable_fb(__le32
*__pdesc
, u32 __val
)
114 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(10));
117 static inline void set_tx_desc_cts2self(__le32
*__pdesc
, u32 __val
)
119 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(11));
122 static inline void set_tx_desc_rts_enable(__le32
*__pdesc
, u32 __val
)
124 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(12));
127 static inline void set_tx_desc_hw_rts_enable(__le32
*__pdesc
, u32 __val
)
129 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(13));
132 static inline void set_tx_desc_nav_use_hdr(__le32
*__pdesc
, u32 __val
)
134 le32p_replace_bits((__pdesc
+ 3), __val
, BIT(15));
137 static inline void set_tx_desc_max_agg_num(__le32
*__pdesc
, u32 __val
)
139 le32p_replace_bits((__pdesc
+ 3), __val
, GENMASK(21, 17));
143 static inline void set_tx_desc_tx_rate(__le32
*__pdesc
, u32 __val
)
145 le32p_replace_bits((__pdesc
+ 4), __val
, GENMASK(6, 0));
148 static inline void set_tx_desc_data_rate_fb_limit(__le32
*__pdesc
, u32 __val
)
150 le32p_replace_bits((__pdesc
+ 4), __val
, GENMASK(12, 8));
153 static inline void set_tx_desc_rts_rate_fb_limit(__le32
*__pdesc
, u32 __val
)
155 le32p_replace_bits((__pdesc
+ 4), __val
, GENMASK(16, 13));
158 static inline void set_tx_desc_rts_rate(__le32
*__pdesc
, u32 __val
)
160 le32p_replace_bits((__pdesc
+ 4), __val
, GENMASK(28, 24));
164 static inline void set_tx_desc_tx_sub_carrier(__le32
*__pdesc
, u32 __val
)
166 le32p_replace_bits((__pdesc
+ 5), __val
, GENMASK(3, 0));
169 static inline void set_tx_desc_data_bw(__le32
*__pdesc
, u32 __val
)
171 le32p_replace_bits((__pdesc
+ 4), __val
, GENMASK(6, 5));
174 static inline void set_tx_desc_rts_short(__le32
*__pdesc
, u32 __val
)
176 le32p_replace_bits((__pdesc
+ 5), __val
, BIT(12));
179 static inline void set_tx_desc_rts_sc(__le32
*__pdesc
, u32 __val
)
181 le32p_replace_bits((__pdesc
+ 5), __val
, GENMASK(16, 13));
185 static inline void set_tx_desc_tx_buffer_size(__le32
*__pdesc
, u32 __val
)
187 le32p_replace_bits((__pdesc
+ 7), __val
, GENMASK(15, 0));
191 static inline void set_tx_desc_seq(__le32
*__pdesc
, u32 __val
)
193 le32p_replace_bits((__pdesc
+ 9), __val
, GENMASK(23, 12));
197 static inline void set_tx_desc_tx_buffer_address(__le32
*__pdesc
, u32 __val
)
199 *(__pdesc
+ 10) = cpu_to_le32(__val
);
203 static inline void set_tx_desc_next_desc_address(__le32
*__pdesc
, u32 __val
)
205 *(__pdesc
+ 12) = cpu_to_le32(__val
);
208 static inline void set_earlymode_pktnum(__le32
*__paddr
, u32 __val
)
210 le32p_replace_bits(__paddr
, __val
, GENMASK(3, 0));
213 static inline void set_earlymode_len0(__le32
*__paddr
, u32 __val
)
215 le32p_replace_bits(__paddr
, __val
, GENMASK(18, 4));
218 static inline void set_earlymode_len1(__le32
*__paddr
, u32 __val
)
220 le32p_replace_bits(__paddr
, __val
, GENMASK(17, 16));
223 static inline void set_earlymode_len2_1(__le32
*__paddr
, u32 __val
)
225 le32p_replace_bits(__paddr
, __val
, GENMASK(5, 2));
228 static inline void set_earlymode_len2_2(__le32
*__paddr
, u32 __val
)
230 le32p_replace_bits((__paddr
+ 1), __val
, GENMASK(7, 0));
233 static inline void set_earlymode_len3(__le32
*__paddr
, u32 __val
)
235 le32p_replace_bits((__paddr
+ 1), __val
, GENMASK(31, 17));
238 static inline void set_earlymode_len4(__le32
*__paddr
, u32 __val
)
240 le32p_replace_bits((__paddr
+ 1), __val
, GENMASK(31, 20));
243 /* TX/RX buffer descriptor */
245 /* for Txfilldescroptor92ee, fill the desc content. */
246 static inline void set_txbuffer_desc_len_with_offset(__le32
*__pdesc
,
247 u8 __offset
, u32 __val
)
249 le32p_replace_bits((__pdesc
+ 4 * __offset
), __val
,
253 static inline void set_txbuffer_desc_amsdu_with_offset(__le32
*__pdesc
,
254 u8 __offset
, u32 __val
)
256 le32p_replace_bits((__pdesc
+ 4 * __offset
), __val
, BIT(31));
259 static inline void set_txbuffer_desc_add_low_with_offset(__le32
*__pdesc
,
263 *(__pdesc
+ 4 * __offset
+ 1) = cpu_to_le32(__val
);
266 static inline void set_txbuffer_desc_add_high_with_offset(__le32
*pbd
, u8 off
,
270 *(pbd
+ 4 * off
+ 2) = cpu_to_le32(val
);
272 *(pbd
+ 4 * off
+ 2) = 0;
275 static inline u32
get_txbuffer_desc_addr_low(__le32
*__pdesc
, u8 __offset
)
277 return le32_to_cpu(*((__pdesc
+ 4 * __offset
+ 1)));
280 static inline u32
get_txbuffer_desc_addr_high(__le32
*pbd
, u32 off
, bool dma64
)
283 return le32_to_cpu(*((pbd
+ 4 * off
+ 2)));
288 static inline void set_tx_buff_desc_len_0(__le32
*__pdesc
, u32 __val
)
290 le32p_replace_bits(__pdesc
, __val
, GENMASK(13, 0));
293 static inline void set_tx_buff_desc_psb(__le32
*__pdesc
, u32 __val
)
295 le32p_replace_bits(__pdesc
, __val
, GENMASK(30, 16));
298 static inline void set_tx_buff_desc_own(__le32
*__pdesc
, u32 __val
)
300 le32p_replace_bits(__pdesc
, __val
, BIT(31));
304 static inline void set_tx_buff_desc_addr_low_0(__le32
*__pdesc
, u32 __val
)
306 *(__pdesc
+ 1) = cpu_to_le32(__val
);
310 static inline void set_tx_buff_desc_addr_high_0(__le32
*pdesc
, u32 val
,
314 *(pdesc
+ 2) = cpu_to_le32(val
);
322 static inline void set_rx_buffer_desc_data_length(__le32
*__status
, u32 __val
)
324 le32p_replace_bits(__status
, __val
, GENMASK(13, 0));
327 static inline void set_rx_buffer_desc_ls(__le32
*__status
, u32 __val
)
329 le32p_replace_bits(__status
, __val
, BIT(15));
332 static inline void set_rx_buffer_desc_fs(__le32
*__status
, u32 __val
)
334 le32p_replace_bits(__status
, __val
, BIT(16));
337 static inline void set_rx_buffer_desc_total_length(__le32
*__status
, u32 __val
)
339 le32p_replace_bits(__status
, __val
, GENMASK(30, 16));
342 static inline int get_rx_buffer_desc_ls(__le32
*__status
)
344 return le32_get_bits(*(__status
), BIT(15));
347 static inline int get_rx_buffer_desc_fs(__le32
*__status
)
349 return le32_get_bits(*(__status
), BIT(16));
352 static inline int get_rx_buffer_desc_total_length(__le32
*__status
)
354 return le32_get_bits(*(__status
), GENMASK(30, 16));
358 static inline void set_rx_buffer_physical_low(__le32
*__status
, u32 __val
)
360 *(__status
+ 1) = cpu_to_le32(__val
);
364 static inline void set_rx_buffer_physical_high(__le32
*__rx_status_desc
,
365 u32 __val
, bool dma64
)
368 *(__rx_status_desc
+ 2) = cpu_to_le32(__val
);
370 *(__rx_status_desc
+ 2) = 0;
373 static inline int get_rx_desc_pkt_len(__le32
*__pdesc
)
375 return le32_get_bits(*__pdesc
, GENMASK(13, 0));
378 static inline int get_rx_desc_crc32(__le32
*__pdesc
)
380 return le32_get_bits(*__pdesc
, BIT(14));
383 static inline int get_rx_desc_icv(__le32
*__pdesc
)
385 return le32_get_bits(*__pdesc
, BIT(15));
388 static inline int get_rx_desc_drv_info_size(__le32
*__pdesc
)
390 return le32_get_bits(*__pdesc
, GENMASK(19, 16));
393 static inline int get_rx_desc_shift(__le32
*__pdesc
)
395 return le32_get_bits(*__pdesc
, GENMASK(25, 24));
398 static inline int get_rx_desc_physt(__le32
*__pdesc
)
400 return le32_get_bits(*__pdesc
, BIT(26));
403 static inline int get_rx_desc_swdec(__le32
*__pdesc
)
405 return le32_get_bits(*__pdesc
, BIT(27));
408 static inline int get_rx_desc_own(__le32
*__pdesc
)
410 return le32_get_bits(*__pdesc
, BIT(31));
413 static inline void set_rx_desc_eor(__le32
*__pdesc
, u32 __val
)
415 le32p_replace_bits(__pdesc
, __val
, BIT(30));
418 static inline int get_rx_desc_macid(__le32
*__pdesc
)
420 return le32_get_bits(*(__pdesc
+ 1), GENMASK(6, 0));
423 static inline int get_rx_desc_paggr(__le32
*__pdesc
)
425 return le32_get_bits(*(__pdesc
+ 1), BIT(15));
428 static inline int get_rx_status_desc_rpt_sel(__le32
*__pdesc
)
430 return le32_get_bits(*(__pdesc
+ 2), BIT(28));
433 static inline int get_rx_desc_rxmcs(__le32
*__pdesc
)
435 return le32_get_bits(*(__pdesc
+ 3), GENMASK(6, 0));
438 static inline int get_rx_status_desc_pattern_match(__le32
*__pdesc
)
440 return le32_get_bits(*(__pdesc
+ 3), BIT(29));
443 static inline int get_rx_status_desc_unicast_match(__le32
*__pdesc
)
445 return le32_get_bits(*(__pdesc
+ 3), BIT(30));
448 static inline int get_rx_status_desc_magic_match(__le32
*__pdesc
)
450 return le32_get_bits(*(__pdesc
+ 3), BIT(31));
453 static inline u32
get_rx_desc_tsfl(__le32
*__pdesc
)
455 return le32_to_cpu(*((__pdesc
+ 5)));
458 static inline u32
get_rx_desc_buff_addr(__le32
*__pdesc
)
460 return le32_to_cpu(*((__pdesc
+ 6)));
463 /* TX report 2 format in Rx desc*/
465 static inline u32
get_rx_rpt2_desc_macid_valid_1(__le32
*__status
)
467 return le32_to_cpu(*((__status
+ 4)));
470 static inline u32
get_rx_rpt2_desc_macid_valid_2(__le32
*__status
)
472 return le32_to_cpu(*((__status
+ 5)));
475 static inline void clear_pci_tx_desc_content(__le32
*__pdesc
, int _size
)
477 if (_size
> TX_DESC_NEXT_DESC_OFFSET
)
478 memset(__pdesc
, 0, TX_DESC_NEXT_DESC_OFFSET
);
480 memset(__pdesc
, 0, _size
);
483 #define RTL92EE_RX_HAL_IS_CCK_RATE(rxmcs)\
484 (rxmcs == DESC_RATE1M ||\
485 rxmcs == DESC_RATE2M ||\
486 rxmcs == DESC_RATE5_5M ||\
487 rxmcs == DESC_RATE11M)
489 #define IS_LITTLE_ENDIAN 1
491 struct phy_rx_agc_info_t
{
499 struct phy_status_rpt
{
500 struct phy_rx_agc_info_t path_agc
[2];
502 u8 cck_sig_qual_ofdm_pwdb_all
;
503 u8 cck_agc_rpt_ofdm_cfosho_a
;
504 u8 cck_rpt_b_ofdm_cfosho_b
;
506 u8 noise_power_db_msb
;
511 u8 noise_power_db_lsb
;
514 u8 stream_target_csi
[2];
518 u8 antsel_rx_keep_2
:1; /*ex_intf_flg:1;*/
525 #else /* _BIG_ENDIAN_ */
532 u8 antsel_rx_keep_2
:1; /*ex_intf_flg:1;*/
630 u32 rtsrate_fb_lmt
:4;
655 u32 nextdescaddress64
;
657 u32 reserve_pass_pcie_mm_limit
[4];
718 void rtl92ee_rx_check_dma_ok(struct ieee80211_hw
*hw
, u8
*header_desc
,
720 u16
rtl92ee_rx_desc_buff_remained_cnt(struct ieee80211_hw
*hw
,
722 u16
rtl92ee_get_available_desc(struct ieee80211_hw
*hw
, u8 queue_index
);
723 void rtl92ee_pre_fill_tx_bd_desc(struct ieee80211_hw
*hw
,
724 u8
*tx_bd_desc
, u8
*desc
, u8 queue_index
,
725 struct sk_buff
*skb
, dma_addr_t addr
);
727 void rtl92ee_tx_fill_desc(struct ieee80211_hw
*hw
,
728 struct ieee80211_hdr
*hdr
, u8
*pdesc_tx
,
730 struct ieee80211_tx_info
*info
,
731 struct ieee80211_sta
*sta
,
733 u8 hw_queue
, struct rtl_tcb_desc
*ptcb_desc
);
734 bool rtl92ee_rx_query_desc(struct ieee80211_hw
*hw
,
735 struct rtl_stats
*status
,
736 struct ieee80211_rx_status
*rx_status
,
737 u8
*pdesc
, struct sk_buff
*skb
);
738 void rtl92ee_set_desc(struct ieee80211_hw
*hw
, u8
*pdesc
, bool istx
,
739 u8 desc_name
, u8
*val
);
741 u64
rtl92ee_get_desc(struct ieee80211_hw
*hw
,
742 u8
*pdesc
, bool istx
, u8 desc_name
);
743 bool rtl92ee_is_tx_desc_closed(struct ieee80211_hw
*hw
, u8 hw_queue
, u16 index
);
744 void rtl92ee_tx_polling(struct ieee80211_hw
*hw
, u8 hw_queue
);
745 void rtl92ee_tx_fill_cmddesc(struct ieee80211_hw
*hw
, u8
*pdesc
,
746 bool firstseg
, bool lastseg
,
747 struct sk_buff
*skb
);