18691632fSRavi Kumar /* SPDX-License-Identifier: BSD-3-Clause 28691632fSRavi Kumar * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved. 38691632fSRavi Kumar * Copyright(c) 2018 Synopsys, Inc. All rights reserved. 48691632fSRavi Kumar */ 58691632fSRavi Kumar 68691632fSRavi Kumar #ifndef RTE_ETH_AXGBE_H_ 78691632fSRavi Kumar #define RTE_ETH_AXGBE_H_ 88691632fSRavi Kumar 98691632fSRavi Kumar #include <rte_mempool.h> 108691632fSRavi Kumar #include <rte_lcore.h> 118691632fSRavi Kumar #include "axgbe_common.h" 12e0444948SSelwin Sebastian #include "rte_time.h" 138691632fSRavi Kumar 149e890103SRavi Kumar #define IRQ 0xff 159e890103SRavi Kumar 169e890103SRavi Kumar #define AXGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1)) 179e890103SRavi Kumar #define AXGBE_RX_MAX_BUF_SIZE (0x3fff & ~(64 - 1)) 1825cf2630SFerruh Yigit #define AXGBE_RX_MIN_BUF_SIZE (RTE_ETHER_MAX_LEN + RTE_VLAN_HLEN) 1949a5e622SChandu Babu N #define AXGBE_MAX_MAC_ADDRS 32 20e01d9b2eSChandu Babu N #define AXGBE_MAX_HASH_MAC_ADDRS 256 219e890103SRavi Kumar 229e890103SRavi Kumar #define AXGBE_RX_BUF_ALIGN 64 239e890103SRavi Kumar 24572890efSRavi Kumar #define AXGBE_MAX_DMA_CHANNELS 16 25572890efSRavi Kumar #define AXGBE_MAX_QUEUES 16 26572890efSRavi Kumar #define AXGBE_PRIORITY_QUEUES 8 27572890efSRavi Kumar #define AXGBE_DMA_STOP_TIMEOUT 1 28572890efSRavi Kumar 29572890efSRavi Kumar /* DMA cache settings - Outer sharable, write-back, write-allocate */ 30572890efSRavi Kumar #define AXGBE_DMA_OS_AXDOMAIN 0x2 31572890efSRavi Kumar #define AXGBE_DMA_OS_ARCACHE 0xb 32572890efSRavi Kumar #define AXGBE_DMA_OS_AWCACHE 0xf 33572890efSRavi Kumar 34572890efSRavi Kumar /* DMA cache settings - System, no caches used */ 35572890efSRavi Kumar #define AXGBE_DMA_SYS_AXDOMAIN 0x3 36572890efSRavi Kumar #define AXGBE_DMA_SYS_ARCACHE 0x0 37572890efSRavi Kumar #define AXGBE_DMA_SYS_AWCACHE 0x0 38572890efSRavi Kumar 399e890103SRavi Kumar /* DMA channel interrupt modes */ 409e890103SRavi Kumar #define AXGBE_IRQ_MODE_EDGE 0 419e890103SRavi Kumar #define AXGBE_IRQ_MODE_LEVEL 1 429e890103SRavi Kumar 439e890103SRavi Kumar #define AXGBE_DMA_INTERRUPT_MASK 0x31c7 449e890103SRavi Kumar 459e890103SRavi Kumar #define AXGMAC_MIN_PACKET 60 469e890103SRavi Kumar #define AXGMAC_STD_PACKET_MTU 1500 479e890103SRavi Kumar #define AXGMAC_MAX_STD_PACKET 1518 489e890103SRavi Kumar #define AXGMAC_JUMBO_PACKET_MTU 9000 499e890103SRavi Kumar #define AXGMAC_MAX_JUMBO_PACKET 9018 509e890103SRavi Kumar /* Inter-frame gap + preamble */ 519e890103SRavi Kumar #define AXGMAC_ETH_PREAMBLE (12 + 8) 529e890103SRavi Kumar 539e890103SRavi Kumar #define AXGMAC_PFC_DATA_LEN 46 549e890103SRavi Kumar #define AXGMAC_PFC_DELAYS 14000 559e890103SRavi Kumar 56572890efSRavi Kumar /* PCI BAR mapping */ 57572890efSRavi Kumar #define AXGBE_AXGMAC_BAR 0 58572890efSRavi Kumar #define AXGBE_XPCS_BAR 1 59572890efSRavi Kumar #define AXGBE_MAC_PROP_OFFSET 0x1d000 60572890efSRavi Kumar #define AXGBE_I2C_CTRL_OFFSET 0x1e000 61572890efSRavi Kumar 62572890efSRavi Kumar /* PCI clock frequencies */ 63572890efSRavi Kumar #define AXGBE_V2_DMA_CLOCK_FREQ 500000000 64572890efSRavi Kumar #define AXGBE_V2_PTP_CLOCK_FREQ 125000000 65572890efSRavi Kumar 66e0444948SSelwin Sebastian /* Timestamp support - values based on 50MHz PTP clock 67e0444948SSelwin Sebastian * 50MHz => 20 nsec 68e0444948SSelwin Sebastian */ 69e0444948SSelwin Sebastian #define AXGBE_TSTAMP_SSINC 20 70e0444948SSelwin Sebastian #define AXGBE_TSTAMP_SNSINC 0 71e0444948SSelwin Sebastian #define AXGBE_CYCLECOUNTER_MASK 0xffffffffffffffffULL 72e0444948SSelwin Sebastian 73572890efSRavi Kumar #define AXGMAC_FIFO_MIN_ALLOC 2048 74572890efSRavi Kumar #define AXGMAC_FIFO_UNIT 256 75572890efSRavi Kumar #define AXGMAC_FIFO_ALIGN(_x) \ 76572890efSRavi Kumar (((_x) + AXGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1)) 77572890efSRavi Kumar #define AXGMAC_FIFO_FC_OFF 2048 78572890efSRavi Kumar #define AXGMAC_FIFO_FC_MIN 4096 79572890efSRavi Kumar 80572890efSRavi Kumar #define AXGBE_TC_MIN_QUANTUM 10 81572890efSRavi Kumar 82572890efSRavi Kumar /* Flow control queue count */ 83572890efSRavi Kumar #define AXGMAC_MAX_FLOW_CONTROL_QUEUES 8 84572890efSRavi Kumar 85572890efSRavi Kumar /* Flow control threshold units */ 86572890efSRavi Kumar #define AXGMAC_FLOW_CONTROL_UNIT 512 87572890efSRavi Kumar #define AXGMAC_FLOW_CONTROL_ALIGN(_x) \ 88572890efSRavi Kumar (((_x) + AXGMAC_FLOW_CONTROL_UNIT - 1) & \ 89572890efSRavi Kumar ~(AXGMAC_FLOW_CONTROL_UNIT - 1)) 90572890efSRavi Kumar #define AXGMAC_FLOW_CONTROL_VALUE(_x) \ 91572890efSRavi Kumar (((_x) < 1024) ? 0 : ((_x) / AXGMAC_FLOW_CONTROL_UNIT) - 2) 92572890efSRavi Kumar #define AXGMAC_FLOW_CONTROL_MAX 33280 93572890efSRavi Kumar 94e01d9b2eSChandu Babu N /* Maximum MAC address hash table size (256 bits = 8 dword) */ 95572890efSRavi Kumar #define AXGBE_MAC_HASH_TABLE_SIZE 8 96572890efSRavi Kumar 97572890efSRavi Kumar /* Receive Side Scaling */ 98572890efSRavi Kumar #define AXGBE_RSS_OFFLOAD ( \ 99295968d1SFerruh Yigit RTE_ETH_RSS_IPV4 | \ 100295968d1SFerruh Yigit RTE_ETH_RSS_NONFRAG_IPV4_TCP | \ 101295968d1SFerruh Yigit RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 102295968d1SFerruh Yigit RTE_ETH_RSS_IPV6 | \ 103295968d1SFerruh Yigit RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 104295968d1SFerruh Yigit RTE_ETH_RSS_NONFRAG_IPV6_UDP) 105572890efSRavi Kumar 106572890efSRavi Kumar #define AXGBE_RSS_HASH_KEY_SIZE 40 107572890efSRavi Kumar #define AXGBE_RSS_MAX_TABLE_SIZE 256 108572890efSRavi Kumar #define AXGBE_RSS_LOOKUP_TABLE_TYPE 0 109572890efSRavi Kumar #define AXGBE_RSS_HASH_KEY_TYPE 1 110572890efSRavi Kumar 111572890efSRavi Kumar /* Auto-negotiation */ 112572890efSRavi Kumar #define AXGBE_AN_MS_TIMEOUT 500 113572890efSRavi Kumar #define AXGBE_LINK_TIMEOUT 5 114572890efSRavi Kumar 115572890efSRavi Kumar #define AXGBE_SGMII_AN_LINK_STATUS BIT(1) 116572890efSRavi Kumar #define AXGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3)) 117572890efSRavi Kumar #define AXGBE_SGMII_AN_LINK_SPEED_100 0x04 118572890efSRavi Kumar #define AXGBE_SGMII_AN_LINK_SPEED_1000 0x08 119572890efSRavi Kumar #define AXGBE_SGMII_AN_LINK_DUPLEX BIT(4) 120572890efSRavi Kumar 121572890efSRavi Kumar /* ECC correctable error notification window (seconds) */ 122572890efSRavi Kumar #define AXGBE_ECC_LIMIT 60 123572890efSRavi Kumar 124572890efSRavi Kumar /* MDIO port types */ 125572890efSRavi Kumar #define AXGMAC_MAX_C22_PORT 3 126572890efSRavi Kumar 1272570c033SSteve Yang /* The max frame size with default MTU */ 1282570c033SSteve Yang #define AXGBE_ETH_MAX_LEN ( \ 1292570c033SSteve Yang RTE_ETHER_MTU + \ 1302570c033SSteve Yang RTE_ETHER_HDR_LEN + \ 1312570c033SSteve Yang RTE_ETHER_CRC_LEN) 1322570c033SSteve Yang 133572890efSRavi Kumar /* Helper macro for descriptor handling 134572890efSRavi Kumar * Always use AXGBE_GET_DESC_DATA to access the descriptor data 135572890efSRavi Kumar * since the index is free-running and needs to be and-ed 136572890efSRavi Kumar * with the descriptor count value of the ring to index to 137572890efSRavi Kumar * the proper descriptor data. 138572890efSRavi Kumar */ 139572890efSRavi Kumar #define AXGBE_GET_DESC_DATA(_ring, _idx) \ 140572890efSRavi Kumar ((_ring)->rdata + \ 141572890efSRavi Kumar ((_idx) & ((_ring)->rdesc_count - 1))) 142572890efSRavi Kumar 143572890efSRavi Kumar struct axgbe_port; 144572890efSRavi Kumar 145572890efSRavi Kumar enum axgbe_state { 146572890efSRavi Kumar AXGBE_DOWN, 147572890efSRavi Kumar AXGBE_LINK_INIT, 148572890efSRavi Kumar AXGBE_LINK_ERR, 149572890efSRavi Kumar AXGBE_STOPPED, 150572890efSRavi Kumar }; 151572890efSRavi Kumar 152572890efSRavi Kumar enum axgbe_int { 153572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_TI, 154572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_TPS, 155572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_TBU, 156572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_RI, 157572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_RBU, 158572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_RPS, 159572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_TI_RI, 160572890efSRavi Kumar AXGMAC_INT_DMA_CH_SR_FBE, 161572890efSRavi Kumar AXGMAC_INT_DMA_ALL, 162572890efSRavi Kumar }; 163572890efSRavi Kumar 164572890efSRavi Kumar enum axgbe_int_state { 165572890efSRavi Kumar AXGMAC_INT_STATE_SAVE, 166572890efSRavi Kumar AXGMAC_INT_STATE_RESTORE, 167572890efSRavi Kumar }; 168572890efSRavi Kumar 169572890efSRavi Kumar enum axgbe_ecc_sec { 170572890efSRavi Kumar AXGBE_ECC_SEC_TX, 171572890efSRavi Kumar AXGBE_ECC_SEC_RX, 172572890efSRavi Kumar AXGBE_ECC_SEC_DESC, 173572890efSRavi Kumar }; 174572890efSRavi Kumar 175572890efSRavi Kumar enum axgbe_speed { 176572890efSRavi Kumar AXGBE_SPEED_1000 = 0, 177572890efSRavi Kumar AXGBE_SPEED_2500, 178572890efSRavi Kumar AXGBE_SPEED_10000, 179572890efSRavi Kumar AXGBE_SPEEDS, 180572890efSRavi Kumar }; 181572890efSRavi Kumar 182572890efSRavi Kumar enum axgbe_xpcs_access { 183572890efSRavi Kumar AXGBE_XPCS_ACCESS_V1 = 0, 184572890efSRavi Kumar AXGBE_XPCS_ACCESS_V2, 185572890efSRavi Kumar }; 186572890efSRavi Kumar 187572890efSRavi Kumar enum axgbe_an_mode { 188572890efSRavi Kumar AXGBE_AN_MODE_CL73 = 0, 189572890efSRavi Kumar AXGBE_AN_MODE_CL73_REDRV, 190572890efSRavi Kumar AXGBE_AN_MODE_CL37, 191572890efSRavi Kumar AXGBE_AN_MODE_CL37_SGMII, 192572890efSRavi Kumar AXGBE_AN_MODE_NONE, 193572890efSRavi Kumar }; 194572890efSRavi Kumar 195572890efSRavi Kumar enum axgbe_an { 196572890efSRavi Kumar AXGBE_AN_READY = 0, 197572890efSRavi Kumar AXGBE_AN_PAGE_RECEIVED, 198572890efSRavi Kumar AXGBE_AN_INCOMPAT_LINK, 199572890efSRavi Kumar AXGBE_AN_COMPLETE, 200572890efSRavi Kumar AXGBE_AN_NO_LINK, 201572890efSRavi Kumar AXGBE_AN_ERROR, 202572890efSRavi Kumar }; 203572890efSRavi Kumar 204572890efSRavi Kumar enum axgbe_rx { 205572890efSRavi Kumar AXGBE_RX_BPA = 0, 206572890efSRavi Kumar AXGBE_RX_XNP, 207572890efSRavi Kumar AXGBE_RX_COMPLETE, 208572890efSRavi Kumar AXGBE_RX_ERROR, 209572890efSRavi Kumar }; 210572890efSRavi Kumar 211572890efSRavi Kumar enum axgbe_mode { 212572890efSRavi Kumar AXGBE_MODE_KX_1000 = 0, 213572890efSRavi Kumar AXGBE_MODE_KX_2500, 214572890efSRavi Kumar AXGBE_MODE_KR, 215572890efSRavi Kumar AXGBE_MODE_X, 216572890efSRavi Kumar AXGBE_MODE_SGMII_100, 217572890efSRavi Kumar AXGBE_MODE_SGMII_1000, 218572890efSRavi Kumar AXGBE_MODE_SFI, 219572890efSRavi Kumar AXGBE_MODE_UNKNOWN, 220572890efSRavi Kumar }; 221572890efSRavi Kumar 222572890efSRavi Kumar enum axgbe_speedset { 223572890efSRavi Kumar AXGBE_SPEEDSET_1000_10000 = 0, 224572890efSRavi Kumar AXGBE_SPEEDSET_2500_10000, 225572890efSRavi Kumar }; 226572890efSRavi Kumar 227572890efSRavi Kumar enum axgbe_mdio_mode { 228572890efSRavi Kumar AXGBE_MDIO_MODE_NONE = 0, 229572890efSRavi Kumar AXGBE_MDIO_MODE_CL22, 230572890efSRavi Kumar AXGBE_MDIO_MODE_CL45, 231572890efSRavi Kumar }; 232572890efSRavi Kumar 2334ac7516bSRavi Kumar struct axgbe_phy { 2344ac7516bSRavi Kumar uint32_t supported; 2354ac7516bSRavi Kumar uint32_t advertising; 2364ac7516bSRavi Kumar uint32_t lp_advertising; 2374ac7516bSRavi Kumar 2384ac7516bSRavi Kumar int address; 2394ac7516bSRavi Kumar 2404ac7516bSRavi Kumar int autoneg; 2414ac7516bSRavi Kumar int speed; 2424ac7516bSRavi Kumar int duplex; 2434ac7516bSRavi Kumar 2444ac7516bSRavi Kumar int link; 2454ac7516bSRavi Kumar 2464ac7516bSRavi Kumar int pause_autoneg; 2474ac7516bSRavi Kumar int tx_pause; 2484ac7516bSRavi Kumar int rx_pause; 2494ac7516bSRavi Kumar }; 2504ac7516bSRavi Kumar 2514ac7516bSRavi Kumar enum axgbe_i2c_cmd { 2524ac7516bSRavi Kumar AXGBE_I2C_CMD_READ = 0, 2534ac7516bSRavi Kumar AXGBE_I2C_CMD_WRITE, 2544ac7516bSRavi Kumar }; 2554ac7516bSRavi Kumar 2564ac7516bSRavi Kumar struct axgbe_i2c_op { 2574ac7516bSRavi Kumar enum axgbe_i2c_cmd cmd; 2584ac7516bSRavi Kumar 2594ac7516bSRavi Kumar unsigned int target; 2604ac7516bSRavi Kumar 2614ac7516bSRavi Kumar uint8_t *buf; 2624ac7516bSRavi Kumar unsigned int len; 2634ac7516bSRavi Kumar }; 2644ac7516bSRavi Kumar 2654ac7516bSRavi Kumar struct axgbe_i2c_op_state { 2664ac7516bSRavi Kumar struct axgbe_i2c_op *op; 2674ac7516bSRavi Kumar 2684ac7516bSRavi Kumar unsigned int tx_len; 2694ac7516bSRavi Kumar unsigned char *tx_buf; 2704ac7516bSRavi Kumar 2714ac7516bSRavi Kumar unsigned int rx_len; 2724ac7516bSRavi Kumar unsigned char *rx_buf; 2734ac7516bSRavi Kumar 2744ac7516bSRavi Kumar unsigned int tx_abort_source; 2754ac7516bSRavi Kumar 2764ac7516bSRavi Kumar int ret; 2774ac7516bSRavi Kumar }; 2784ac7516bSRavi Kumar 2794ac7516bSRavi Kumar struct axgbe_i2c { 2804ac7516bSRavi Kumar unsigned int started; 2814ac7516bSRavi Kumar unsigned int max_speed_mode; 2824ac7516bSRavi Kumar unsigned int rx_fifo_size; 2834ac7516bSRavi Kumar unsigned int tx_fifo_size; 2844ac7516bSRavi Kumar 2854ac7516bSRavi Kumar struct axgbe_i2c_op_state op_state; 2864ac7516bSRavi Kumar }; 2874ac7516bSRavi Kumar 288572890efSRavi Kumar struct axgbe_hw_if { 289572890efSRavi Kumar void (*config_flow_control)(struct axgbe_port *); 290572890efSRavi Kumar int (*config_rx_mode)(struct axgbe_port *); 291572890efSRavi Kumar 292572890efSRavi Kumar int (*init)(struct axgbe_port *); 293572890efSRavi Kumar 294572890efSRavi Kumar int (*read_mmd_regs)(struct axgbe_port *, int, int); 295572890efSRavi Kumar void (*write_mmd_regs)(struct axgbe_port *, int, int, int); 296572890efSRavi Kumar int (*set_speed)(struct axgbe_port *, int); 297572890efSRavi Kumar 298572890efSRavi Kumar int (*set_ext_mii_mode)(struct axgbe_port *, unsigned int, 299572890efSRavi Kumar enum axgbe_mdio_mode); 300572890efSRavi Kumar int (*read_ext_mii_regs)(struct axgbe_port *, int, int); 301572890efSRavi Kumar int (*write_ext_mii_regs)(struct axgbe_port *, int, int, uint16_t); 302572890efSRavi Kumar 303572890efSRavi Kumar /* For FLOW ctrl */ 304572890efSRavi Kumar int (*config_tx_flow_control)(struct axgbe_port *); 305572890efSRavi Kumar int (*config_rx_flow_control)(struct axgbe_port *); 306572890efSRavi Kumar 30786578516SGirish Nandibasappa /* vlan */ 30886578516SGirish Nandibasappa int (*enable_rx_vlan_stripping)(struct axgbe_port *); 30986578516SGirish Nandibasappa int (*disable_rx_vlan_stripping)(struct axgbe_port *); 31086578516SGirish Nandibasappa int (*enable_rx_vlan_filtering)(struct axgbe_port *); 31186578516SGirish Nandibasappa int (*disable_rx_vlan_filtering)(struct axgbe_port *); 31286578516SGirish Nandibasappa int (*update_vlan_hash_table)(struct axgbe_port *); 31386578516SGirish Nandibasappa 314572890efSRavi Kumar int (*exit)(struct axgbe_port *); 315572890efSRavi Kumar }; 316572890efSRavi Kumar 3174ac7516bSRavi Kumar /* This structure represents implementation specific routines for an 3184ac7516bSRavi Kumar * implementation of a PHY. All routines are required unless noted below. 3194ac7516bSRavi Kumar * Optional routines: 3204ac7516bSRavi Kumar * kr_training_pre, kr_training_post 3214ac7516bSRavi Kumar */ 3224ac7516bSRavi Kumar struct axgbe_phy_impl_if { 3234ac7516bSRavi Kumar /* Perform Setup/teardown actions */ 3244ac7516bSRavi Kumar int (*init)(struct axgbe_port *); 3254ac7516bSRavi Kumar void (*exit)(struct axgbe_port *); 3264ac7516bSRavi Kumar 3274ac7516bSRavi Kumar /* Perform start/stop specific actions */ 3284ac7516bSRavi Kumar int (*reset)(struct axgbe_port *); 3294ac7516bSRavi Kumar int (*start)(struct axgbe_port *); 3304ac7516bSRavi Kumar void (*stop)(struct axgbe_port *); 3314ac7516bSRavi Kumar 3324ac7516bSRavi Kumar /* Return the link status */ 3334ac7516bSRavi Kumar int (*link_status)(struct axgbe_port *, int *); 3344ac7516bSRavi Kumar 3354ac7516bSRavi Kumar /* Indicate if a particular speed is valid */ 3364ac7516bSRavi Kumar int (*valid_speed)(struct axgbe_port *, int); 3374ac7516bSRavi Kumar 3384ac7516bSRavi Kumar /* Check if the specified mode can/should be used */ 3394ac7516bSRavi Kumar bool (*use_mode)(struct axgbe_port *, enum axgbe_mode); 3404ac7516bSRavi Kumar /* Switch the PHY into various modes */ 3414ac7516bSRavi Kumar void (*set_mode)(struct axgbe_port *, enum axgbe_mode); 3424ac7516bSRavi Kumar /* Retrieve mode needed for a specific speed */ 3434ac7516bSRavi Kumar enum axgbe_mode (*get_mode)(struct axgbe_port *, int); 3444ac7516bSRavi Kumar /* Retrieve new/next mode when trying to auto-negotiate */ 3454ac7516bSRavi Kumar enum axgbe_mode (*switch_mode)(struct axgbe_port *); 3464ac7516bSRavi Kumar /* Retrieve current mode */ 3474ac7516bSRavi Kumar enum axgbe_mode (*cur_mode)(struct axgbe_port *); 3484ac7516bSRavi Kumar 3494ac7516bSRavi Kumar /* Retrieve current auto-negotiation mode */ 3504ac7516bSRavi Kumar enum axgbe_an_mode (*an_mode)(struct axgbe_port *); 3514ac7516bSRavi Kumar 3524ac7516bSRavi Kumar /* Configure auto-negotiation settings */ 3534ac7516bSRavi Kumar int (*an_config)(struct axgbe_port *); 3544ac7516bSRavi Kumar 3554ac7516bSRavi Kumar /* Set/override auto-negotiation advertisement settings */ 3564ac7516bSRavi Kumar unsigned int (*an_advertising)(struct axgbe_port *port); 3574ac7516bSRavi Kumar 3584ac7516bSRavi Kumar /* Process results of auto-negotiation */ 3594ac7516bSRavi Kumar enum axgbe_mode (*an_outcome)(struct axgbe_port *); 3604ac7516bSRavi Kumar 36100072056SRavi Kumar /* Pre/Post auto-negotiation support */ 36200072056SRavi Kumar void (*an_pre)(struct axgbe_port *port); 36300072056SRavi Kumar void (*an_post)(struct axgbe_port *port); 36400072056SRavi Kumar 3654ac7516bSRavi Kumar /* Pre/Post KR training enablement support */ 3664ac7516bSRavi Kumar void (*kr_training_pre)(struct axgbe_port *); 3674ac7516bSRavi Kumar void (*kr_training_post)(struct axgbe_port *); 3684ac7516bSRavi Kumar }; 3694ac7516bSRavi Kumar 3704ac7516bSRavi Kumar struct axgbe_phy_if { 3714ac7516bSRavi Kumar /* For PHY setup/teardown */ 3724ac7516bSRavi Kumar int (*phy_init)(struct axgbe_port *); 3734ac7516bSRavi Kumar void (*phy_exit)(struct axgbe_port *); 3744ac7516bSRavi Kumar 3754ac7516bSRavi Kumar /* For PHY support when setting device up/down */ 3764ac7516bSRavi Kumar int (*phy_reset)(struct axgbe_port *); 3774ac7516bSRavi Kumar int (*phy_start)(struct axgbe_port *); 3784ac7516bSRavi Kumar void (*phy_stop)(struct axgbe_port *); 3794ac7516bSRavi Kumar 3804ac7516bSRavi Kumar /* For PHY support while device is up */ 3814ac7516bSRavi Kumar void (*phy_status)(struct axgbe_port *); 3824ac7516bSRavi Kumar int (*phy_config_aneg)(struct axgbe_port *); 3834ac7516bSRavi Kumar 3844ac7516bSRavi Kumar /* For PHY settings validation */ 3854ac7516bSRavi Kumar int (*phy_valid_speed)(struct axgbe_port *, int); 3864ac7516bSRavi Kumar /* For single interrupt support */ 3874ac7516bSRavi Kumar void (*an_isr)(struct axgbe_port *); 3884ac7516bSRavi Kumar /* PHY implementation specific services */ 3894ac7516bSRavi Kumar struct axgbe_phy_impl_if phy_impl; 3904ac7516bSRavi Kumar }; 3914ac7516bSRavi Kumar 3924ac7516bSRavi Kumar struct axgbe_i2c_if { 3934ac7516bSRavi Kumar /* For initial I2C setup */ 3944ac7516bSRavi Kumar int (*i2c_init)(struct axgbe_port *); 3954ac7516bSRavi Kumar 3964ac7516bSRavi Kumar /* For I2C support when setting device up/down */ 3974ac7516bSRavi Kumar int (*i2c_start)(struct axgbe_port *); 3984ac7516bSRavi Kumar void (*i2c_stop)(struct axgbe_port *); 3994ac7516bSRavi Kumar 4004ac7516bSRavi Kumar /* For performing I2C operations */ 4014ac7516bSRavi Kumar int (*i2c_xfer)(struct axgbe_port *, struct axgbe_i2c_op *); 4024ac7516bSRavi Kumar }; 4034ac7516bSRavi Kumar 404572890efSRavi Kumar /* This structure contains flags that indicate what hardware features 405572890efSRavi Kumar * or configurations are present in the device. 406572890efSRavi Kumar */ 407572890efSRavi Kumar struct axgbe_hw_features { 408572890efSRavi Kumar /* HW Version */ 409572890efSRavi Kumar unsigned int version; 410572890efSRavi Kumar 411572890efSRavi Kumar /* HW Feature Register0 */ 412572890efSRavi Kumar unsigned int gmii; /* 1000 Mbps support */ 413572890efSRavi Kumar unsigned int vlhash; /* VLAN Hash Filter */ 414572890efSRavi Kumar unsigned int sma; /* SMA(MDIO) Interface */ 415572890efSRavi Kumar unsigned int rwk; /* PMT remote wake-up packet */ 416572890efSRavi Kumar unsigned int mgk; /* PMT magic packet */ 417572890efSRavi Kumar unsigned int mmc; /* RMON module */ 418572890efSRavi Kumar unsigned int aoe; /* ARP Offload */ 419572890efSRavi Kumar unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */ 420572890efSRavi Kumar unsigned int eee; /* Energy Efficient Ethernet */ 421572890efSRavi Kumar unsigned int tx_coe; /* Tx Checksum Offload */ 422572890efSRavi Kumar unsigned int rx_coe; /* Rx Checksum Offload */ 423572890efSRavi Kumar unsigned int addn_mac; /* Additional MAC Addresses */ 424572890efSRavi Kumar unsigned int ts_src; /* Timestamp Source */ 425572890efSRavi Kumar unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */ 426572890efSRavi Kumar 427572890efSRavi Kumar /* HW Feature Register1 */ 428572890efSRavi Kumar unsigned int rx_fifo_size; /* MTL Receive FIFO Size */ 429572890efSRavi Kumar unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */ 430572890efSRavi Kumar unsigned int adv_ts_hi; /* Advance Timestamping High Word */ 431572890efSRavi Kumar unsigned int dma_width; /* DMA width */ 432572890efSRavi Kumar unsigned int dcb; /* DCB Feature */ 433572890efSRavi Kumar unsigned int sph; /* Split Header Feature */ 434572890efSRavi Kumar unsigned int tso; /* TCP Segmentation Offload */ 435572890efSRavi Kumar unsigned int dma_debug; /* DMA Debug Registers */ 436572890efSRavi Kumar unsigned int rss; /* Receive Side Scaling */ 437572890efSRavi Kumar unsigned int tc_cnt; /* Number of Traffic Classes */ 438572890efSRavi Kumar unsigned int hash_table_size; /* Hash Table Size */ 439572890efSRavi Kumar unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */ 440572890efSRavi Kumar 441572890efSRavi Kumar /* HW Feature Register2 */ 442572890efSRavi Kumar unsigned int rx_q_cnt; /* Number of MTL Receive Queues */ 443572890efSRavi Kumar unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */ 444572890efSRavi Kumar unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */ 445572890efSRavi Kumar unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */ 446572890efSRavi Kumar unsigned int pps_out_num; /* Number of PPS outputs */ 447572890efSRavi Kumar unsigned int aux_snap_num; /* Number of Aux snapshot inputs */ 44886578516SGirish Nandibasappa 44986578516SGirish Nandibasappa /* HW Feature Register3 */ 45086578516SGirish Nandibasappa unsigned int tx_q_vlan_tag_ins; /* Queue/Channel based VLAN tag */ 45186578516SGirish Nandibasappa /* insertion on Tx Enable */ 45286578516SGirish Nandibasappa unsigned int no_of_vlan_extn; /* Number of Extended VLAN Tag */ 45386578516SGirish Nandibasappa /* Filters Enabled */ 454572890efSRavi Kumar }; 455572890efSRavi Kumar 456572890efSRavi Kumar struct axgbe_version_data { 4574ac7516bSRavi Kumar void (*init_function_ptrs_phy_impl)(struct axgbe_phy_if *); 458572890efSRavi Kumar enum axgbe_xpcs_access xpcs_access; 459572890efSRavi Kumar unsigned int mmc_64bit; 460572890efSRavi Kumar unsigned int tx_max_fifo_size; 461572890efSRavi Kumar unsigned int rx_max_fifo_size; 462572890efSRavi Kumar unsigned int tx_tstamp_workaround; 463572890efSRavi Kumar unsigned int ecc_support; 464572890efSRavi Kumar unsigned int i2c_support; 46500072056SRavi Kumar unsigned int an_cdr_workaround; 466572890efSRavi Kumar }; 467572890efSRavi Kumar 4689d1ef6b2SChandu Babu N struct axgbe_mmc_stats { 4699d1ef6b2SChandu Babu N /* Tx Stats */ 4709d1ef6b2SChandu Babu N uint64_t txoctetcount_gb; 4719d1ef6b2SChandu Babu N uint64_t txframecount_gb; 4729d1ef6b2SChandu Babu N uint64_t txbroadcastframes_g; 4739d1ef6b2SChandu Babu N uint64_t txmulticastframes_g; 4749d1ef6b2SChandu Babu N uint64_t tx64octets_gb; 4759d1ef6b2SChandu Babu N uint64_t tx65to127octets_gb; 4769d1ef6b2SChandu Babu N uint64_t tx128to255octets_gb; 4779d1ef6b2SChandu Babu N uint64_t tx256to511octets_gb; 4789d1ef6b2SChandu Babu N uint64_t tx512to1023octets_gb; 4799d1ef6b2SChandu Babu N uint64_t tx1024tomaxoctets_gb; 4809d1ef6b2SChandu Babu N uint64_t txunicastframes_gb; 4819d1ef6b2SChandu Babu N uint64_t txmulticastframes_gb; 4829d1ef6b2SChandu Babu N uint64_t txbroadcastframes_gb; 4839d1ef6b2SChandu Babu N uint64_t txunderflowerror; 4849d1ef6b2SChandu Babu N uint64_t txoctetcount_g; 4859d1ef6b2SChandu Babu N uint64_t txframecount_g; 4869d1ef6b2SChandu Babu N uint64_t txpauseframes; 4879d1ef6b2SChandu Babu N uint64_t txvlanframes_g; 4889d1ef6b2SChandu Babu N 4899d1ef6b2SChandu Babu N /* Rx Stats */ 4909d1ef6b2SChandu Babu N uint64_t rxframecount_gb; 4919d1ef6b2SChandu Babu N uint64_t rxoctetcount_gb; 4929d1ef6b2SChandu Babu N uint64_t rxoctetcount_g; 4939d1ef6b2SChandu Babu N uint64_t rxbroadcastframes_g; 4949d1ef6b2SChandu Babu N uint64_t rxmulticastframes_g; 4959d1ef6b2SChandu Babu N uint64_t rxcrcerror; 4969d1ef6b2SChandu Babu N uint64_t rxrunterror; 4979d1ef6b2SChandu Babu N uint64_t rxjabbererror; 4989d1ef6b2SChandu Babu N uint64_t rxundersize_g; 4999d1ef6b2SChandu Babu N uint64_t rxoversize_g; 5009d1ef6b2SChandu Babu N uint64_t rx64octets_gb; 5019d1ef6b2SChandu Babu N uint64_t rx65to127octets_gb; 5029d1ef6b2SChandu Babu N uint64_t rx128to255octets_gb; 5039d1ef6b2SChandu Babu N uint64_t rx256to511octets_gb; 5049d1ef6b2SChandu Babu N uint64_t rx512to1023octets_gb; 5059d1ef6b2SChandu Babu N uint64_t rx1024tomaxoctets_gb; 5069d1ef6b2SChandu Babu N uint64_t rxunicastframes_g; 5079d1ef6b2SChandu Babu N uint64_t rxlengtherror; 5089d1ef6b2SChandu Babu N uint64_t rxoutofrangetype; 5099d1ef6b2SChandu Babu N uint64_t rxpauseframes; 5109d1ef6b2SChandu Babu N uint64_t rxfifooverflow; 5119d1ef6b2SChandu Babu N uint64_t rxvlanframes_gb; 5129d1ef6b2SChandu Babu N uint64_t rxwatchdogerror; 5139d1ef6b2SChandu Babu N }; 5149d1ef6b2SChandu Babu N 515cf97f33eSAmaranath Somalapuram /* Flow control parameters */ 516cf97f33eSAmaranath Somalapuram struct xgbe_fc_info { 517cf97f33eSAmaranath Somalapuram uint32_t high_water[AXGBE_PRIORITY_QUEUES]; 518cf97f33eSAmaranath Somalapuram uint32_t low_water[AXGBE_PRIORITY_QUEUES]; 519cf97f33eSAmaranath Somalapuram uint16_t pause_time[AXGBE_PRIORITY_QUEUES]; 520cf97f33eSAmaranath Somalapuram uint16_t send_xon; 521cf97f33eSAmaranath Somalapuram enum rte_eth_fc_mode mode; 522cf97f33eSAmaranath Somalapuram uint8_t autoneg; 523cf97f33eSAmaranath Somalapuram }; 524cf97f33eSAmaranath Somalapuram 5258691632fSRavi Kumar /* 5268691632fSRavi Kumar * Structure to store private data for each port. 5278691632fSRavi Kumar */ 5288691632fSRavi Kumar struct axgbe_port { 5298691632fSRavi Kumar /* Ethdev where port belongs*/ 5308691632fSRavi Kumar struct rte_eth_dev *eth_dev; 5318691632fSRavi Kumar /* Pci dev info */ 5328691632fSRavi Kumar const struct rte_pci_device *pci_dev; 533572890efSRavi Kumar /* Version related data */ 534572890efSRavi Kumar struct axgbe_version_data *vdata; 535572890efSRavi Kumar 536572890efSRavi Kumar /* AXGMAC/XPCS related mmio registers */ 5377784d0d3SRavi Kumar void *xgmac_regs; /* AXGMAC CSRs */ 5387784d0d3SRavi Kumar void *xpcs_regs; /* XPCS MMD registers */ 5397784d0d3SRavi Kumar void *xprop_regs; /* AXGBE property registers */ 5407784d0d3SRavi Kumar void *xi2c_regs; /* AXGBE I2C CSRs */ 541572890efSRavi Kumar 542*a3ec01b4SVenkat Kumar Ande /* Port property registers */ 543*a3ec01b4SVenkat Kumar Ande unsigned int pp0; 544*a3ec01b4SVenkat Kumar Ande unsigned int pp1; 545*a3ec01b4SVenkat Kumar Ande unsigned int pp2; 546*a3ec01b4SVenkat Kumar Ande unsigned int pp3; 547*a3ec01b4SVenkat Kumar Ande unsigned int pp4; 548*a3ec01b4SVenkat Kumar Ande 54900072056SRavi Kumar bool cdr_track_early; 550572890efSRavi Kumar /* XPCS indirect addressing lock */ 551572890efSRavi Kumar unsigned int xpcs_window_def_reg; 552572890efSRavi Kumar unsigned int xpcs_window_sel_reg; 553572890efSRavi Kumar unsigned int xpcs_window; 554572890efSRavi Kumar unsigned int xpcs_window_size; 555572890efSRavi Kumar unsigned int xpcs_window_mask; 556572890efSRavi Kumar 557572890efSRavi Kumar /* Flags representing axgbe_state */ 5584693ae4aSJoyce Kong uint32_t dev_state; 559572890efSRavi Kumar 560572890efSRavi Kumar struct axgbe_hw_if hw_if; 5614ac7516bSRavi Kumar struct axgbe_phy_if phy_if; 5624ac7516bSRavi Kumar struct axgbe_i2c_if i2c_if; 563572890efSRavi Kumar 564572890efSRavi Kumar /* AXI DMA settings */ 565572890efSRavi Kumar unsigned int coherent; 566572890efSRavi Kumar unsigned int axdomain; 567572890efSRavi Kumar unsigned int arcache; 568572890efSRavi Kumar unsigned int awcache; 569572890efSRavi Kumar 570572890efSRavi Kumar unsigned int tx_max_channel_count; 571572890efSRavi Kumar unsigned int rx_max_channel_count; 572572890efSRavi Kumar unsigned int channel_count; 573572890efSRavi Kumar unsigned int tx_ring_count; 574572890efSRavi Kumar unsigned int tx_desc_count; 575572890efSRavi Kumar unsigned int rx_ring_count; 576572890efSRavi Kumar unsigned int rx_desc_count; 577572890efSRavi Kumar 578572890efSRavi Kumar unsigned int tx_max_q_count; 579572890efSRavi Kumar unsigned int rx_max_q_count; 580572890efSRavi Kumar unsigned int tx_q_count; 581572890efSRavi Kumar unsigned int rx_q_count; 582572890efSRavi Kumar 583572890efSRavi Kumar /* Tx/Rx common settings */ 584572890efSRavi Kumar unsigned int pblx8; 585572890efSRavi Kumar 586572890efSRavi Kumar /* Tx settings */ 587572890efSRavi Kumar unsigned int tx_sf_mode; 588572890efSRavi Kumar unsigned int tx_threshold; 589572890efSRavi Kumar unsigned int tx_pbl; 590572890efSRavi Kumar unsigned int tx_osp_mode; 591572890efSRavi Kumar unsigned int tx_max_fifo_size; 59293bffd8fSBhagyada Modali unsigned int multi_segs_tx; 593572890efSRavi Kumar 594572890efSRavi Kumar /* Rx settings */ 595572890efSRavi Kumar unsigned int rx_sf_mode; 596572890efSRavi Kumar unsigned int rx_threshold; 597572890efSRavi Kumar unsigned int rx_pbl; 598572890efSRavi Kumar unsigned int rx_max_fifo_size; 599572890efSRavi Kumar unsigned int rx_buf_size; 600572890efSRavi Kumar 601572890efSRavi Kumar /* Device clocks */ 602572890efSRavi Kumar unsigned long sysclk_rate; 603572890efSRavi Kumar unsigned long ptpclk_rate; 604572890efSRavi Kumar 605572890efSRavi Kumar /* Keeps track of power mode */ 606572890efSRavi Kumar unsigned int power_down; 607572890efSRavi Kumar 608572890efSRavi Kumar /* Current PHY settings */ 609572890efSRavi Kumar int phy_link; 610572890efSRavi Kumar int phy_speed; 611572890efSRavi Kumar 612572890efSRavi Kumar pthread_mutex_t xpcs_mutex; 613572890efSRavi Kumar pthread_mutex_t i2c_mutex; 614572890efSRavi Kumar pthread_mutex_t an_mutex; 615572890efSRavi Kumar pthread_mutex_t phy_mutex; 616572890efSRavi Kumar 617572890efSRavi Kumar /* Flow control settings */ 618572890efSRavi Kumar unsigned int pause_autoneg; 619572890efSRavi Kumar unsigned int tx_pause; 620572890efSRavi Kumar unsigned int rx_pause; 621572890efSRavi Kumar unsigned int rx_rfa[AXGBE_MAX_QUEUES]; 622572890efSRavi Kumar unsigned int rx_rfd[AXGBE_MAX_QUEUES]; 623572890efSRavi Kumar unsigned int fifo; 624e0543d4eSAmaranath Somalapuram unsigned int pfc_map[AXGBE_MAX_QUEUES]; 625572890efSRavi Kumar 626572890efSRavi Kumar /* Receive Side Scaling settings */ 627572890efSRavi Kumar u8 rss_key[AXGBE_RSS_HASH_KEY_SIZE]; 628572890efSRavi Kumar uint32_t rss_table[AXGBE_RSS_MAX_TABLE_SIZE]; 629572890efSRavi Kumar uint32_t rss_options; 630572890efSRavi Kumar int rss_enable; 63176d7664dSChandu Babu N uint64_t rss_hf; 632572890efSRavi Kumar 633572890efSRavi Kumar /* Hardware features of the device */ 634572890efSRavi Kumar struct axgbe_hw_features hw_feat; 635572890efSRavi Kumar 6366d13ea8eSOlivier Matz struct rte_ether_addr mac_addr; 6374ac7516bSRavi Kumar 6389e890103SRavi Kumar /* Software Tx/Rx structure pointers*/ 6399e890103SRavi Kumar void **rx_queues; 6409e890103SRavi Kumar void **tx_queues; 6419e890103SRavi Kumar 6424ac7516bSRavi Kumar /* MDIO/PHY related settings */ 6434ac7516bSRavi Kumar unsigned int phy_started; 6444ac7516bSRavi Kumar void *phy_data; 6454ac7516bSRavi Kumar struct axgbe_phy phy; 6464ac7516bSRavi Kumar int mdio_mmd; 6474ac7516bSRavi Kumar unsigned long link_check; 6484ac7516bSRavi Kumar volatile int mdio_completion; 6494ac7516bSRavi Kumar 6504ac7516bSRavi Kumar unsigned int kr_redrv; 6514ac7516bSRavi Kumar 6527be78d02SJosh Soref /* Auto-negotiation state machine support */ 6534ac7516bSRavi Kumar unsigned int an_int; 6544ac7516bSRavi Kumar unsigned int an_status; 6554ac7516bSRavi Kumar enum axgbe_an an_result; 6564ac7516bSRavi Kumar enum axgbe_an an_state; 6574ac7516bSRavi Kumar enum axgbe_rx kr_state; 6584ac7516bSRavi Kumar enum axgbe_rx kx_state; 6594ac7516bSRavi Kumar unsigned int an_supported; 6604ac7516bSRavi Kumar unsigned int parallel_detect; 6614ac7516bSRavi Kumar unsigned int fec_ability; 6624ac7516bSRavi Kumar unsigned long an_start; 6634ac7516bSRavi Kumar enum axgbe_an_mode an_mode; 6644ac7516bSRavi Kumar 6654ac7516bSRavi Kumar /* I2C support */ 6664ac7516bSRavi Kumar struct axgbe_i2c i2c; 6674ac7516bSRavi Kumar volatile int i2c_complete; 6689e890103SRavi Kumar 6699e890103SRavi Kumar /* CRC stripping by H/w for Rx packet*/ 6709e890103SRavi Kumar int crc_strip_enable; 6719e890103SRavi Kumar /* csum enable to hardware */ 6729e890103SRavi Kumar uint32_t rx_csum_enable; 6739d1ef6b2SChandu Babu N 6749d1ef6b2SChandu Babu N struct axgbe_mmc_stats mmc_stats; 675cf97f33eSAmaranath Somalapuram struct xgbe_fc_info fc; 676e01d9b2eSChandu Babu N 677e01d9b2eSChandu Babu N /* Hash filtering */ 678e01d9b2eSChandu Babu N unsigned int hash_table_shift; 679e01d9b2eSChandu Babu N unsigned int hash_table_count; 680e01d9b2eSChandu Babu N unsigned int uc_hash_mac_addr; 681e01d9b2eSChandu Babu N unsigned int uc_hash_table[AXGBE_MAC_HASH_TABLE_SIZE]; 682e0444948SSelwin Sebastian 68386578516SGirish Nandibasappa /* Filtering support */ 68486578516SGirish Nandibasappa unsigned long active_vlans[VLAN_TABLE_SIZE]; 68586578516SGirish Nandibasappa 686e0444948SSelwin Sebastian /* For IEEE1588 PTP */ 687e0444948SSelwin Sebastian struct rte_timecounter systime_tc; 688e0444948SSelwin Sebastian struct rte_timecounter tx_tstamp; 689e0444948SSelwin Sebastian unsigned int tstamp_addend; 690e0444948SSelwin Sebastian 6918691632fSRavi Kumar }; 6928691632fSRavi Kumar 693572890efSRavi Kumar void axgbe_init_function_ptrs_dev(struct axgbe_hw_if *hw_if); 6944ac7516bSRavi Kumar void axgbe_init_function_ptrs_phy(struct axgbe_phy_if *phy_if); 6954ac7516bSRavi Kumar void axgbe_init_function_ptrs_phy_v2(struct axgbe_phy_if *phy_if); 6964ac7516bSRavi Kumar void axgbe_init_function_ptrs_i2c(struct axgbe_i2c_if *i2c_if); 69749a5e622SChandu Babu N void axgbe_set_mac_addn_addr(struct axgbe_port *pdata, u8 *addr, 69849a5e622SChandu Babu N uint32_t index); 699e01d9b2eSChandu Babu N void axgbe_set_mac_hash_table(struct axgbe_port *pdata, u8 *addr, bool add); 70076d7664dSChandu Babu N int axgbe_write_rss_lookup_table(struct axgbe_port *pdata); 70176d7664dSChandu Babu N int axgbe_write_rss_hash_key(struct axgbe_port *pdata); 7024ac7516bSRavi Kumar 7038691632fSRavi Kumar #endif /* RTE_ETH_AXGBE_H_ */ 704