net/axgbe: add structs for MAC init and reset
[dpdk.git] / drivers / net / axgbe / axgbe_ethdev.h
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.
4  */
5
6 #ifndef RTE_ETH_AXGBE_H_
7 #define RTE_ETH_AXGBE_H_
8
9 #include <rte_mempool.h>
10 #include <rte_lcore.h>
11 #include "axgbe_common.h"
12
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
17
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
22
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
27
28 /* PCI BAR mapping */
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
33
34 /* PCI clock frequencies */
35 #define AXGBE_V2_DMA_CLOCK_FREQ         500000000
36 #define AXGBE_V2_PTP_CLOCK_FREQ         125000000
37
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
44
45 #define AXGBE_TC_MIN_QUANTUM            10
46
47 /* Flow control queue count */
48 #define AXGMAC_MAX_FLOW_CONTROL_QUEUES  8
49
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
58
59 /* Maximum MAC address hash table size (256 bits = 8 bytes) */
60 #define AXGBE_MAC_HASH_TABLE_SIZE       8
61
62 /* Receive Side Scaling */
63 #define AXGBE_RSS_OFFLOAD  ( \
64         ETH_RSS_IPV4 | \
65         ETH_RSS_NONFRAG_IPV4_TCP | \
66         ETH_RSS_NONFRAG_IPV4_UDP | \
67         ETH_RSS_IPV6 | \
68         ETH_RSS_NONFRAG_IPV6_TCP | \
69         ETH_RSS_NONFRAG_IPV6_UDP)
70
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
75
76 /* Auto-negotiation */
77 #define AXGBE_AN_MS_TIMEOUT             500
78 #define AXGBE_LINK_TIMEOUT              5
79
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)
85
86 /* ECC correctable error notification window (seconds) */
87 #define AXGBE_ECC_LIMIT                 60
88
89 /* MDIO port types */
90 #define AXGMAC_MAX_C22_PORT             3
91
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.
97  */
98 #define AXGBE_GET_DESC_DATA(_ring, _idx)                        \
99         ((_ring)->rdata +                                       \
100          ((_idx) & ((_ring)->rdesc_count - 1)))
101
102 struct axgbe_port;
103
104 enum axgbe_state {
105         AXGBE_DOWN,
106         AXGBE_LINK_INIT,
107         AXGBE_LINK_ERR,
108         AXGBE_STOPPED,
109 };
110
111 enum axgbe_int {
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,
120         AXGMAC_INT_DMA_ALL,
121 };
122
123 enum axgbe_int_state {
124         AXGMAC_INT_STATE_SAVE,
125         AXGMAC_INT_STATE_RESTORE,
126 };
127
128 enum axgbe_ecc_sec {
129         AXGBE_ECC_SEC_TX,
130         AXGBE_ECC_SEC_RX,
131         AXGBE_ECC_SEC_DESC,
132 };
133
134 enum axgbe_speed {
135         AXGBE_SPEED_1000 = 0,
136         AXGBE_SPEED_2500,
137         AXGBE_SPEED_10000,
138         AXGBE_SPEEDS,
139 };
140
141 enum axgbe_xpcs_access {
142         AXGBE_XPCS_ACCESS_V1 = 0,
143         AXGBE_XPCS_ACCESS_V2,
144 };
145
146 enum axgbe_an_mode {
147         AXGBE_AN_MODE_CL73 = 0,
148         AXGBE_AN_MODE_CL73_REDRV,
149         AXGBE_AN_MODE_CL37,
150         AXGBE_AN_MODE_CL37_SGMII,
151         AXGBE_AN_MODE_NONE,
152 };
153
154 enum axgbe_an {
155         AXGBE_AN_READY = 0,
156         AXGBE_AN_PAGE_RECEIVED,
157         AXGBE_AN_INCOMPAT_LINK,
158         AXGBE_AN_COMPLETE,
159         AXGBE_AN_NO_LINK,
160         AXGBE_AN_ERROR,
161 };
162
163 enum axgbe_rx {
164         AXGBE_RX_BPA = 0,
165         AXGBE_RX_XNP,
166         AXGBE_RX_COMPLETE,
167         AXGBE_RX_ERROR,
168 };
169
170 enum axgbe_mode {
171         AXGBE_MODE_KX_1000 = 0,
172         AXGBE_MODE_KX_2500,
173         AXGBE_MODE_KR,
174         AXGBE_MODE_X,
175         AXGBE_MODE_SGMII_100,
176         AXGBE_MODE_SGMII_1000,
177         AXGBE_MODE_SFI,
178         AXGBE_MODE_UNKNOWN,
179 };
180
181 enum axgbe_speedset {
182         AXGBE_SPEEDSET_1000_10000 = 0,
183         AXGBE_SPEEDSET_2500_10000,
184 };
185
186 enum axgbe_mdio_mode {
187         AXGBE_MDIO_MODE_NONE = 0,
188         AXGBE_MDIO_MODE_CL22,
189         AXGBE_MDIO_MODE_CL45,
190 };
191
192 struct axgbe_hw_if {
193         void (*config_flow_control)(struct axgbe_port *);
194         int (*config_rx_mode)(struct axgbe_port *);
195
196         int (*init)(struct axgbe_port *);
197
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);
201
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);
206
207         /* For FLOW ctrl */
208         int (*config_tx_flow_control)(struct axgbe_port *);
209         int (*config_rx_flow_control)(struct axgbe_port *);
210
211         int (*exit)(struct axgbe_port *);
212 };
213
214 /* This structure contains flags that indicate what hardware features
215  * or configurations are present in the device.
216  */
217 struct axgbe_hw_features {
218         /* HW Version */
219         unsigned int version;
220
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 */
236
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 */
250
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 */
258 };
259
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;
268 };
269
270 /*
271  * Structure to store private data for each port.
272  */
273 struct axgbe_port {
274         /*  Ethdev where port belongs*/
275         struct rte_eth_dev *eth_dev;
276         /* Pci dev info */
277         const struct rte_pci_device *pci_dev;
278         /* Version related data */
279         struct axgbe_version_data *vdata;
280
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 */
286
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;
293
294         /* Flags representing axgbe_state */
295         unsigned long dev_state;
296
297         struct axgbe_hw_if hw_if;
298
299         /* AXI DMA settings */
300         unsigned int coherent;
301         unsigned int axdomain;
302         unsigned int arcache;
303         unsigned int awcache;
304
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;
312
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;
317
318         /* Tx/Rx common settings */
319         unsigned int pblx8;
320
321         /* Tx settings */
322         unsigned int tx_sf_mode;
323         unsigned int tx_threshold;
324         unsigned int tx_pbl;
325         unsigned int tx_osp_mode;
326         unsigned int tx_max_fifo_size;
327
328         /* Rx settings */
329         unsigned int rx_sf_mode;
330         unsigned int rx_threshold;
331         unsigned int rx_pbl;
332         unsigned int rx_max_fifo_size;
333         unsigned int rx_buf_size;
334
335         /* Device clocks */
336         unsigned long sysclk_rate;
337         unsigned long ptpclk_rate;
338
339         /* Keeps track of power mode */
340         unsigned int power_down;
341
342         /* Current PHY settings */
343         int phy_link;
344         int phy_speed;
345
346         pthread_mutex_t xpcs_mutex;
347         pthread_mutex_t i2c_mutex;
348         pthread_mutex_t an_mutex;
349         pthread_mutex_t phy_mutex;
350
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];
357         unsigned int fifo;
358
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;
363         int rss_enable;
364
365         /* Hardware features of the device */
366         struct axgbe_hw_features hw_feat;
367
368         struct ether_addr mac_addr;
369 };
370
371 void axgbe_init_function_ptrs_dev(struct axgbe_hw_if *hw_if);
372 #endif /* RTE_ETH_AXGBE_H_ */