1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
3 * Copyright(c) 2018 Synopsys, Inc. All rights reserved.
6 #ifndef RTE_ETH_AXGBE_H_
7 #define RTE_ETH_AXGBE_H_
9 #include <rte_mempool.h>
10 #include <rte_lcore.h>
11 #include "axgbe_common.h"
13 #define AXGBE_MAX_DMA_CHANNELS 16
14 #define AXGBE_MAX_QUEUES 16
15 #define AXGBE_PRIORITY_QUEUES 8
16 #define AXGBE_DMA_STOP_TIMEOUT 1
18 /* DMA cache settings - Outer sharable, write-back, write-allocate */
19 #define AXGBE_DMA_OS_AXDOMAIN 0x2
20 #define AXGBE_DMA_OS_ARCACHE 0xb
21 #define AXGBE_DMA_OS_AWCACHE 0xf
23 /* DMA cache settings - System, no caches used */
24 #define AXGBE_DMA_SYS_AXDOMAIN 0x3
25 #define AXGBE_DMA_SYS_ARCACHE 0x0
26 #define AXGBE_DMA_SYS_AWCACHE 0x0
29 #define AXGBE_AXGMAC_BAR 0
30 #define AXGBE_XPCS_BAR 1
31 #define AXGBE_MAC_PROP_OFFSET 0x1d000
32 #define AXGBE_I2C_CTRL_OFFSET 0x1e000
34 /* PCI clock frequencies */
35 #define AXGBE_V2_DMA_CLOCK_FREQ 500000000
36 #define AXGBE_V2_PTP_CLOCK_FREQ 125000000
38 #define AXGMAC_FIFO_MIN_ALLOC 2048
39 #define AXGMAC_FIFO_UNIT 256
40 #define AXGMAC_FIFO_ALIGN(_x) \
41 (((_x) + AXGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
42 #define AXGMAC_FIFO_FC_OFF 2048
43 #define AXGMAC_FIFO_FC_MIN 4096
45 #define AXGBE_TC_MIN_QUANTUM 10
47 /* Flow control queue count */
48 #define AXGMAC_MAX_FLOW_CONTROL_QUEUES 8
50 /* Flow control threshold units */
51 #define AXGMAC_FLOW_CONTROL_UNIT 512
52 #define AXGMAC_FLOW_CONTROL_ALIGN(_x) \
53 (((_x) + AXGMAC_FLOW_CONTROL_UNIT - 1) & \
54 ~(AXGMAC_FLOW_CONTROL_UNIT - 1))
55 #define AXGMAC_FLOW_CONTROL_VALUE(_x) \
56 (((_x) < 1024) ? 0 : ((_x) / AXGMAC_FLOW_CONTROL_UNIT) - 2)
57 #define AXGMAC_FLOW_CONTROL_MAX 33280
59 /* Maximum MAC address hash table size (256 bits = 8 bytes) */
60 #define AXGBE_MAC_HASH_TABLE_SIZE 8
62 /* Receive Side Scaling */
63 #define AXGBE_RSS_OFFLOAD ( \
65 ETH_RSS_NONFRAG_IPV4_TCP | \
66 ETH_RSS_NONFRAG_IPV4_UDP | \
68 ETH_RSS_NONFRAG_IPV6_TCP | \
69 ETH_RSS_NONFRAG_IPV6_UDP)
71 #define AXGBE_RSS_HASH_KEY_SIZE 40
72 #define AXGBE_RSS_MAX_TABLE_SIZE 256
73 #define AXGBE_RSS_LOOKUP_TABLE_TYPE 0
74 #define AXGBE_RSS_HASH_KEY_TYPE 1
76 /* Auto-negotiation */
77 #define AXGBE_AN_MS_TIMEOUT 500
78 #define AXGBE_LINK_TIMEOUT 5
80 #define AXGBE_SGMII_AN_LINK_STATUS BIT(1)
81 #define AXGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
82 #define AXGBE_SGMII_AN_LINK_SPEED_100 0x04
83 #define AXGBE_SGMII_AN_LINK_SPEED_1000 0x08
84 #define AXGBE_SGMII_AN_LINK_DUPLEX BIT(4)
86 /* ECC correctable error notification window (seconds) */
87 #define AXGBE_ECC_LIMIT 60
90 #define AXGMAC_MAX_C22_PORT 3
92 /* Helper macro for descriptor handling
93 * Always use AXGBE_GET_DESC_DATA to access the descriptor data
94 * since the index is free-running and needs to be and-ed
95 * with the descriptor count value of the ring to index to
96 * the proper descriptor data.
98 #define AXGBE_GET_DESC_DATA(_ring, _idx) \
100 ((_idx) & ((_ring)->rdesc_count - 1)))
112 AXGMAC_INT_DMA_CH_SR_TI,
113 AXGMAC_INT_DMA_CH_SR_TPS,
114 AXGMAC_INT_DMA_CH_SR_TBU,
115 AXGMAC_INT_DMA_CH_SR_RI,
116 AXGMAC_INT_DMA_CH_SR_RBU,
117 AXGMAC_INT_DMA_CH_SR_RPS,
118 AXGMAC_INT_DMA_CH_SR_TI_RI,
119 AXGMAC_INT_DMA_CH_SR_FBE,
123 enum axgbe_int_state {
124 AXGMAC_INT_STATE_SAVE,
125 AXGMAC_INT_STATE_RESTORE,
135 AXGBE_SPEED_1000 = 0,
141 enum axgbe_xpcs_access {
142 AXGBE_XPCS_ACCESS_V1 = 0,
143 AXGBE_XPCS_ACCESS_V2,
147 AXGBE_AN_MODE_CL73 = 0,
148 AXGBE_AN_MODE_CL73_REDRV,
150 AXGBE_AN_MODE_CL37_SGMII,
156 AXGBE_AN_PAGE_RECEIVED,
157 AXGBE_AN_INCOMPAT_LINK,
171 AXGBE_MODE_KX_1000 = 0,
175 AXGBE_MODE_SGMII_100,
176 AXGBE_MODE_SGMII_1000,
181 enum axgbe_speedset {
182 AXGBE_SPEEDSET_1000_10000 = 0,
183 AXGBE_SPEEDSET_2500_10000,
186 enum axgbe_mdio_mode {
187 AXGBE_MDIO_MODE_NONE = 0,
188 AXGBE_MDIO_MODE_CL22,
189 AXGBE_MDIO_MODE_CL45,
193 void (*config_flow_control)(struct axgbe_port *);
194 int (*config_rx_mode)(struct axgbe_port *);
196 int (*init)(struct axgbe_port *);
198 int (*read_mmd_regs)(struct axgbe_port *, int, int);
199 void (*write_mmd_regs)(struct axgbe_port *, int, int, int);
200 int (*set_speed)(struct axgbe_port *, int);
202 int (*set_ext_mii_mode)(struct axgbe_port *, unsigned int,
203 enum axgbe_mdio_mode);
204 int (*read_ext_mii_regs)(struct axgbe_port *, int, int);
205 int (*write_ext_mii_regs)(struct axgbe_port *, int, int, uint16_t);
208 int (*config_tx_flow_control)(struct axgbe_port *);
209 int (*config_rx_flow_control)(struct axgbe_port *);
211 int (*exit)(struct axgbe_port *);
214 /* This structure contains flags that indicate what hardware features
215 * or configurations are present in the device.
217 struct axgbe_hw_features {
219 unsigned int version;
221 /* HW Feature Register0 */
222 unsigned int gmii; /* 1000 Mbps support */
223 unsigned int vlhash; /* VLAN Hash Filter */
224 unsigned int sma; /* SMA(MDIO) Interface */
225 unsigned int rwk; /* PMT remote wake-up packet */
226 unsigned int mgk; /* PMT magic packet */
227 unsigned int mmc; /* RMON module */
228 unsigned int aoe; /* ARP Offload */
229 unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
230 unsigned int eee; /* Energy Efficient Ethernet */
231 unsigned int tx_coe; /* Tx Checksum Offload */
232 unsigned int rx_coe; /* Rx Checksum Offload */
233 unsigned int addn_mac; /* Additional MAC Addresses */
234 unsigned int ts_src; /* Timestamp Source */
235 unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
237 /* HW Feature Register1 */
238 unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
239 unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
240 unsigned int adv_ts_hi; /* Advance Timestamping High Word */
241 unsigned int dma_width; /* DMA width */
242 unsigned int dcb; /* DCB Feature */
243 unsigned int sph; /* Split Header Feature */
244 unsigned int tso; /* TCP Segmentation Offload */
245 unsigned int dma_debug; /* DMA Debug Registers */
246 unsigned int rss; /* Receive Side Scaling */
247 unsigned int tc_cnt; /* Number of Traffic Classes */
248 unsigned int hash_table_size; /* Hash Table Size */
249 unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
251 /* HW Feature Register2 */
252 unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
253 unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
254 unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
255 unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
256 unsigned int pps_out_num; /* Number of PPS outputs */
257 unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
260 struct axgbe_version_data {
261 enum axgbe_xpcs_access xpcs_access;
262 unsigned int mmc_64bit;
263 unsigned int tx_max_fifo_size;
264 unsigned int rx_max_fifo_size;
265 unsigned int tx_tstamp_workaround;
266 unsigned int ecc_support;
267 unsigned int i2c_support;
271 * Structure to store private data for each port.
274 /* Ethdev where port belongs*/
275 struct rte_eth_dev *eth_dev;
277 const struct rte_pci_device *pci_dev;
278 /* Version related data */
279 struct axgbe_version_data *vdata;
281 /* AXGMAC/XPCS related mmio registers */
282 uint64_t xgmac_regs; /* AXGMAC CSRs */
283 uint64_t xpcs_regs; /* XPCS MMD registers */
284 uint64_t xprop_regs; /* AXGBE property registers */
285 uint64_t xi2c_regs; /* AXGBE I2C CSRs */
287 /* XPCS indirect addressing lock */
288 unsigned int xpcs_window_def_reg;
289 unsigned int xpcs_window_sel_reg;
290 unsigned int xpcs_window;
291 unsigned int xpcs_window_size;
292 unsigned int xpcs_window_mask;
294 /* Flags representing axgbe_state */
295 unsigned long dev_state;
297 struct axgbe_hw_if hw_if;
299 /* AXI DMA settings */
300 unsigned int coherent;
301 unsigned int axdomain;
302 unsigned int arcache;
303 unsigned int awcache;
305 unsigned int tx_max_channel_count;
306 unsigned int rx_max_channel_count;
307 unsigned int channel_count;
308 unsigned int tx_ring_count;
309 unsigned int tx_desc_count;
310 unsigned int rx_ring_count;
311 unsigned int rx_desc_count;
313 unsigned int tx_max_q_count;
314 unsigned int rx_max_q_count;
315 unsigned int tx_q_count;
316 unsigned int rx_q_count;
318 /* Tx/Rx common settings */
322 unsigned int tx_sf_mode;
323 unsigned int tx_threshold;
325 unsigned int tx_osp_mode;
326 unsigned int tx_max_fifo_size;
329 unsigned int rx_sf_mode;
330 unsigned int rx_threshold;
332 unsigned int rx_max_fifo_size;
333 unsigned int rx_buf_size;
336 unsigned long sysclk_rate;
337 unsigned long ptpclk_rate;
339 /* Keeps track of power mode */
340 unsigned int power_down;
342 /* Current PHY settings */
346 pthread_mutex_t xpcs_mutex;
347 pthread_mutex_t i2c_mutex;
348 pthread_mutex_t an_mutex;
349 pthread_mutex_t phy_mutex;
351 /* Flow control settings */
352 unsigned int pause_autoneg;
353 unsigned int tx_pause;
354 unsigned int rx_pause;
355 unsigned int rx_rfa[AXGBE_MAX_QUEUES];
356 unsigned int rx_rfd[AXGBE_MAX_QUEUES];
359 /* Receive Side Scaling settings */
360 u8 rss_key[AXGBE_RSS_HASH_KEY_SIZE];
361 uint32_t rss_table[AXGBE_RSS_MAX_TABLE_SIZE];
362 uint32_t rss_options;
365 /* Hardware features of the device */
366 struct axgbe_hw_features hw_feat;
368 struct ether_addr mac_addr;
371 void axgbe_init_function_ptrs_dev(struct axgbe_hw_if *hw_if);
372 #endif /* RTE_ETH_AXGBE_H_ */