Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2024 Realtek Corporation. All rights reserved
3 : : */
4 : :
5 : : #ifndef R8169_ETHDEV_H
6 : : #define R8169_ETHDEV_H
7 : :
8 : : #include <stdint.h>
9 : :
10 : : #include <rte_ethdev.h>
11 : : #include <rte_ethdev_core.h>
12 : :
13 : : #include "r8169_compat.h"
14 : :
15 : : struct rtl_hw;
16 : :
17 : : struct rtl_hw_ops {
18 : : void (*hw_config)(struct rtl_hw *hw);
19 : : void (*hw_init_rxcfg)(struct rtl_hw *hw);
20 : : void (*hw_ephy_config)(struct rtl_hw *hw);
21 : : void (*hw_phy_config)(struct rtl_hw *hw);
22 : : void (*hw_mac_mcu_config)(struct rtl_hw *hw);
23 : : void (*hw_phy_mcu_config)(struct rtl_hw *hw);
24 : : };
25 : :
26 : : /* Flow control settings */
27 : : enum rtl_fc_mode {
28 : : rtl_fc_none = 0,
29 : : rtl_fc_rx_pause,
30 : : rtl_fc_tx_pause,
31 : : rtl_fc_full,
32 : : rtl_fc_default
33 : : };
34 : :
35 : : enum rtl_rss_register_content {
36 : : /* RSS */
37 : : RSS_CTRL_TCP_IPV4_SUPP = (1 << 0),
38 : : RSS_CTRL_IPV4_SUPP = (1 << 1),
39 : : RSS_CTRL_TCP_IPV6_SUPP = (1 << 2),
40 : : RSS_CTRL_IPV6_SUPP = (1 << 3),
41 : : RSS_CTRL_IPV6_EXT_SUPP = (1 << 4),
42 : : RSS_CTRL_TCP_IPV6_EXT_SUPP = (1 << 5),
43 : : RSS_HALF_SUPP = (1 << 7),
44 : : RSS_CTRL_UDP_IPV4_SUPP = (1 << 11),
45 : : RSS_CTRL_UDP_IPV6_SUPP = (1 << 12),
46 : : RSS_CTRL_UDP_IPV6_EXT_SUPP = (1 << 13),
47 : : RSS_QUAD_CPU_EN = (1 << 16),
48 : : RSS_HQ_Q_SUP_R = (1 << 31),
49 : : };
50 : :
51 : : #define RTL_RSS_OFFLOAD_ALL ( \
52 : : RTE_ETH_RSS_IPV4 | \
53 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \
54 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
55 : : RTE_ETH_RSS_IPV6 | \
56 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \
57 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
58 : : RTE_ETH_RSS_IPV6_EX | \
59 : : RTE_ETH_RSS_IPV6_TCP_EX | \
60 : : RTE_ETH_RSS_IPV6_UDP_EX)
61 : :
62 : : #define RTL_RSS_CTRL_OFFLOAD_ALL ( \
63 : : RSS_CTRL_TCP_IPV4_SUPP | \
64 : : RSS_CTRL_IPV4_SUPP | \
65 : : RSS_CTRL_TCP_IPV6_SUPP | \
66 : : RSS_CTRL_IPV6_SUPP | \
67 : : RSS_CTRL_IPV6_EXT_SUPP | \
68 : : RSS_CTRL_TCP_IPV6_EXT_SUPP | \
69 : : RSS_CTRL_UDP_IPV4_SUPP | \
70 : : RSS_CTRL_UDP_IPV6_SUPP | \
71 : : RSS_CTRL_UDP_IPV6_EXT_SUPP)
72 : :
73 : : #define RTL_RSS_KEY_SIZE 40 /* size of RSS Hash Key in bytes */
74 : : #define RTL_MAX_INDIRECTION_TABLE_ENTRIES RTE_ETH_RSS_RETA_SIZE_128
75 : : #define RSS_MASK_BITS_OFFSET 8
76 : : #define RSS_CPU_NUM_OFFSET 16
77 : :
78 : : struct rtl_hw {
79 : : struct rtl_hw_ops hw_ops;
80 : : u8 *mmio_addr;
81 : : u8 *cmac_ioaddr; /* cmac memory map physical address */
82 : : u8 chipset_name;
83 : : u8 HwIcVerUnknown;
84 : : u32 mcfg;
85 : : u32 mtu;
86 : : u8 HwSuppIntMitiVer;
87 : : u16 cur_page;
88 : : u8 mac_addr[RTE_ETHER_ADDR_LEN];
89 : : u32 rx_buf_sz;
90 : :
91 : : struct rtl_counters *tally_vaddr;
92 : : u64 tally_paddr;
93 : :
94 : : u8 RequirePhyMdiSwapPatch;
95 : : u8 NotWrMcuPatchCode;
96 : : u8 HwSuppMacMcuVer;
97 : : u16 MacMcuPageSize;
98 : : u64 hw_mcu_patch_code_ver;
99 : : u64 bin_mcu_patch_code_ver;
100 : :
101 : : u8 NotWrRamCodeToMicroP;
102 : : u8 HwHasWrRamCodeToMicroP;
103 : : u8 HwSuppCheckPhyDisableModeVer;
104 : :
105 : : u16 sw_ram_code_ver;
106 : : u16 hw_ram_code_ver;
107 : :
108 : : u8 autoneg;
109 : : u8 duplex;
110 : : u32 speed;
111 : : u64 advertising;
112 : : enum rtl_fc_mode fcpause;
113 : :
114 : : u32 HwSuppMaxPhyLinkSpeed;
115 : :
116 : : u8 HwSuppNowIsOobVer;
117 : :
118 : : u16 mcu_pme_setting;
119 : :
120 : : /* Device function */
121 : : u8 function;
122 : :
123 : : /* Enable Tx No Close */
124 : : u8 HwSuppTxNoCloseVer;
125 : : u8 EnableTxNoClose;
126 : : u32 MaxTxDescPtrMask;
127 : :
128 : : /* Dash */
129 : : u8 HwSuppDashVer;
130 : : u8 DASH;
131 : : u8 HwSuppOcpChannelVer;
132 : : u8 AllowAccessDashOcp;
133 : : u8 HwPkgDet;
134 : : u8 HwSuppSerDesPhyVer;
135 : :
136 : : /* Fiber */
137 : : u32 HwFiberModeVer;
138 : :
139 : : /* Multi queue*/
140 : : u8 EnableRss;
141 : : u8 HwSuppRxDescType;
142 : : u16 RxDescLength;
143 : : u8 rss_key[RTL_RSS_KEY_SIZE];
144 : : u8 rss_indir_tbl[RTL_MAX_INDIRECTION_TABLE_ENTRIES];
145 : : };
146 : :
147 : : struct rtl_sw_stats {
148 : : u64 tx_packets;
149 : : u64 tx_bytes;
150 : : u64 tx_errors;
151 : : u64 rx_packets;
152 : : u64 rx_bytes;
153 : : u64 rx_errors;
154 : : };
155 : :
156 : : struct rtl_adapter {
157 : : struct rtl_hw hw;
158 : : struct rtl_sw_stats sw_stats;
159 : : };
160 : :
161 : : /* Struct RxDesc in kernel r8169 */
162 : : struct rtl_rx_desc {
163 : : u32 opts1;
164 : : u32 opts2;
165 : : u64 addr;
166 : : };
167 : :
168 : : struct rtl_rx_descv3 {
169 : : union {
170 : : struct {
171 : : u32 rsv1;
172 : : u32 rsv2;
173 : : } RxDescDDWord1;
174 : : };
175 : :
176 : : union {
177 : : struct {
178 : : u32 RSSResult;
179 : : u16 HeaderBufferLen;
180 : : u16 HeaderInfo;
181 : : } RxDescNormalDDWord2;
182 : :
183 : : struct {
184 : : u32 rsv5;
185 : : u32 rsv6;
186 : : } RxDescDDWord2;
187 : : };
188 : :
189 : : union {
190 : : u64 addr;
191 : :
192 : : struct {
193 : : u32 TimeStampLow;
194 : : u32 TimeStampHigh;
195 : : } RxDescTimeStamp;
196 : :
197 : : struct {
198 : : u32 rsv8;
199 : : u32 rsv9;
200 : : } RxDescDDWord3;
201 : : };
202 : :
203 : : union {
204 : : struct {
205 : : u32 opts2;
206 : : u32 opts1;
207 : : } RxDescNormalDDWord4;
208 : :
209 : : struct {
210 : : u16 TimeStampHHigh;
211 : : u16 rsv11;
212 : : u32 opts1;
213 : : } RxDescPTPDDWord4;
214 : : };
215 : : };
216 : :
217 : : struct rtl_rx_descv4 {
218 : : union {
219 : : u64 addr;
220 : :
221 : : struct {
222 : : u32 RSSInfo;
223 : : u32 RSSResult;
224 : : } RxDescNormalDDWord1;
225 : : };
226 : :
227 : : struct {
228 : : u32 opts2;
229 : : u32 opts1;
230 : : } RxDescNormalDDWord2;
231 : : };
232 : :
233 : : enum rx_desc_ring_type {
234 : : RX_DESC_RING_TYPE_UNKNOWN = 0,
235 : : RX_DESC_RING_TYPE_1,
236 : : RX_DESC_RING_TYPE_2,
237 : : RX_DESC_RING_TYPE_3,
238 : : RX_DESC_RING_TYPE_4,
239 : : RX_DESC_RING_TYPE_MAX
240 : : };
241 : :
242 : : enum rx_desc_len {
243 : : RX_DESC_LEN_TYPE_1 = (sizeof(struct rtl_rx_desc)),
244 : : RX_DESC_LEN_TYPE_3 = (sizeof(struct rtl_rx_descv3)),
245 : : RX_DESC_LEN_TYPE_4 = (sizeof(struct rtl_rx_descv4))
246 : : };
247 : :
248 : : #define RTL_DEV_PRIVATE(eth_dev) \
249 : : ((struct rtl_adapter *)((eth_dev)->data->dev_private))
250 : :
251 : : #define R8169_LINK_CHECK_TIMEOUT 50 /* 10s */
252 : : #define R8169_LINK_CHECK_INTERVAL 200 /* ms */
253 : :
254 : : #define PCI_READ_CONFIG_BYTE(dev, val, where) \
255 : : rte_pci_read_config(dev, val, 1, where)
256 : :
257 : : #define PCI_READ_CONFIG_WORD(dev, val, where) \
258 : : rte_pci_read_config(dev, val, 2, where)
259 : :
260 : : #define PCI_READ_CONFIG_DWORD(dev, val, where) \
261 : : rte_pci_read_config(dev, val, 4, where)
262 : :
263 : : #define PCI_WRITE_CONFIG_BYTE(dev, val, where) \
264 : : rte_pci_write_config(dev, val, 1, where)
265 : :
266 : : #define PCI_WRITE_CONFIG_WORD(dev, val, where) \
267 : : rte_pci_write_config(dev, val, 2, where)
268 : :
269 : : #define PCI_WRITE_CONFIG_DWORD(dev, val, where) \
270 : : rte_pci_write_config(dev, val, 4, where)
271 : :
272 : : int rtl_rx_init(struct rte_eth_dev *dev);
273 : : int rtl_tx_init(struct rte_eth_dev *dev);
274 : :
275 : : uint16_t rtl_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
276 : : uint16_t rtl_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
277 : : uint16_t rtl_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
278 : : uint16_t nb_pkts);
279 : :
280 : : void rtl_rx_queue_release(struct rte_eth_dev *dev, uint16_t rx_queue_id);
281 : : void rtl_tx_queue_release(struct rte_eth_dev *dev, uint16_t tx_queue_id);
282 : :
283 : : void rtl_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
284 : : struct rte_eth_rxq_info *qinfo);
285 : : void rtl_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
286 : : struct rte_eth_txq_info *qinfo);
287 : :
288 : : uint64_t rtl_get_rx_port_offloads(struct rtl_hw *hw);
289 : : uint64_t rtl_get_tx_port_offloads(void);
290 : :
291 : : int rtl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
292 : : uint16_t nb_rx_desc, unsigned int socket_id,
293 : : const struct rte_eth_rxconf *rx_conf,
294 : : struct rte_mempool *mb_pool);
295 : : int rtl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
296 : : uint16_t nb_tx_desc, unsigned int socket_id,
297 : : const struct rte_eth_txconf *tx_conf);
298 : :
299 : : int rtl_tx_done_cleanup(void *tx_queue, uint32_t free_cnt);
300 : :
301 : : int rtl_stop_queues(struct rte_eth_dev *dev);
302 : : void rtl_free_queues(struct rte_eth_dev *dev);
303 : :
304 : : static inline struct rtl_rx_desc*
305 : : rtl_get_rxdesc(struct rtl_hw *hw, struct rtl_rx_desc *base, u32 const number)
306 : : {
307 [ # # # # : 0 : return (struct rtl_rx_desc *)((u8 *)base + hw->RxDescLength * number);
# # # # #
# # # # #
# ]
308 : : }
309 : :
310 : : #endif /* R8169_ETHDEV_H */
|