Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * ENETC ethernet controller driver |
Vladimir Oltean | 14ca0c3 | 2021-06-29 20:53:16 +0300 | [diff] [blame] | 4 | * Copyright 2017-2021 NXP |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _ENETC_H |
| 8 | #define _ENETC_H |
| 9 | |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 11 | #define enetc_dbg(dev, fmt, args...) debug("%s:" fmt, dev->name, ##args) |
| 12 | |
| 13 | /* PCI function IDs */ |
| 14 | #define PCI_DEVICE_ID_ENETC_ETH 0xE100 |
Alex Marginean | 0215539 | 2019-07-03 12:11:41 +0300 | [diff] [blame] | 15 | #define PCI_DEVICE_ID_ENETC_MDIO 0xEE01 |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 16 | |
| 17 | /* ENETC Ethernet controller registers */ |
| 18 | /* Station interface register offsets */ |
| 19 | #define ENETC_SIMR 0x000 |
| 20 | #define ENETC_SIMR_EN BIT(31) |
| 21 | #define ENETC_SICAR0 0x040 |
| 22 | /* write cache cfg: snoop, no allocate, data & BD coherent */ |
| 23 | #define ENETC_SICAR_WR_CFG 0x6767 |
| 24 | /* read cache cfg: coherent copy, look up, don't alloc in cache */ |
| 25 | #define ENETC_SICAR_RD_CFG 0x27270000 |
| 26 | #define ENETC_SIROCT 0x300 |
| 27 | #define ENETC_SIRFRM 0x308 |
| 28 | #define ENETC_SITOCT 0x320 |
| 29 | #define ENETC_SITFRM 0x328 |
| 30 | |
| 31 | /* Rx/Tx Buffer Descriptor Ring registers */ |
| 32 | enum enetc_bdr_type {TX, RX}; |
| 33 | #define ENETC_BDR(type, n, off) (0x8000 + (type) * 0x100 + (n) * 0x200 + (off)) |
| 34 | #define ENETC_BDR_IDX_MASK 0xffff |
| 35 | |
| 36 | /* Rx BDR reg offsets */ |
| 37 | #define ENETC_RBMR 0x00 |
| 38 | #define ENETC_RBMR_EN BIT(31) |
| 39 | #define ENETC_RBBSR 0x08 |
| 40 | /* initial consumer index for Rx BDR */ |
| 41 | #define ENETC_RBCIR 0x0c |
| 42 | #define ENETC_RBBAR0 0x10 |
| 43 | #define ENETC_RBBAR1 0x14 |
| 44 | #define ENETC_RBPIR 0x18 |
| 45 | #define ENETC_RBLENR 0x20 |
| 46 | |
| 47 | /* Tx BDR reg offsets */ |
| 48 | #define ENETC_TBMR 0x00 |
| 49 | #define ENETC_TBMR_EN BIT(31) |
| 50 | #define ENETC_TBBAR0 0x10 |
| 51 | #define ENETC_TBBAR1 0x14 |
| 52 | #define ENETC_TBPIR 0x18 |
| 53 | #define ENETC_TBCIR 0x1c |
| 54 | #define ENETC_TBLENR 0x20 |
| 55 | |
| 56 | /* Port registers offset */ |
| 57 | #define ENETC_PORT_REGS_OFF 0x10000 |
| 58 | |
| 59 | /* Port registers */ |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 60 | #define ENETC_PMR_OFFSET_LS 0x0000 |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 61 | #define ENETC_PMR 0x0000 |
| 62 | #define ENETC_PMR_SI0_EN BIT(16) |
| 63 | #define ENETC_PSIPMMR 0x0018 |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 64 | #define ENETC_PSIPMARn_OFFSET_LS 0x0080 |
| 65 | #define ENETC_PSIPMAR0 0x0080 |
| 66 | #define ENETC_PSIPMAR1 0x0084 |
| 67 | #define ENETC_PCAPR_OFFSET_LS 0x0900 |
| 68 | #define ENETC_PCAPR0 0x0000 |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 69 | #define ENETC_PCAPRO_MDIO BIT(11) |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 70 | #define ENETC_PSICFGR_OFFSET_LS 0x0940 |
| 71 | #define ENETC_PSICFGR_SHIFT_LS 0x10 |
| 72 | #define ENETC_PSICFGR(n, s) ((n) * (s)) |
| 73 | #define ENETC_PSICFGR_SET_BDR(rx, tx) (((rx) << 16) | (tx)) |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 74 | /* MAC configuration */ |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 75 | #define ENETC_PM_OFFSET_LS 0x8000 |
| 76 | #define ENETC_PM_CC 0x0008 |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 77 | #define ENETC_PM_CC_DEFAULT 0x0810 |
| 78 | #define ENETC_PM_CC_RX_TX_EN 0x8813 |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 79 | #define ENETC_PM_MAXFRM 0x0014 |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 80 | #define ENETC_RX_MAXFRM_SIZE PKTSIZE_ALIGN |
Marek Vasut | a1fa5cb | 2025-01-16 05:03:25 +0100 | [diff] [blame^] | 81 | #define ENETC_PM_IMDIO_BASE 0x0030 |
| 82 | #define ENETC_PM_IF_MODE 0x0300 |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 83 | #define ENETC_PM_IF_MODE_RG BIT(2) |
| 84 | #define ENETC_PM_IF_MODE_AN_ENA BIT(15) |
Vladimir Oltean | 14ca0c3 | 2021-06-29 20:53:16 +0300 | [diff] [blame] | 85 | #define ENETC_PM_IFM_SSP_MASK GENMASK(14, 13) |
| 86 | #define ENETC_PM_IFM_SSP_1000 (2 << 13) |
| 87 | #define ENETC_PM_IFM_SSP_100 (0 << 13) |
| 88 | #define ENETC_PM_IFM_SSP_10 (1 << 13) |
| 89 | #define ENETC_PM_IFM_FULL_DPX BIT(12) |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 90 | #define ENETC_PM_IF_IFMODE_MASK GENMASK(1, 0) |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 91 | |
| 92 | /* buffer descriptors count must be multiple of 8 and aligned to 128 bytes */ |
| 93 | #define ENETC_BD_CNT CONFIG_SYS_RX_ETH_BUFFER |
| 94 | #define ENETC_BD_ALIGN 128 |
| 95 | |
| 96 | /* single pair of Rx/Tx rings */ |
| 97 | #define ENETC_RX_BDR_CNT 1 |
| 98 | #define ENETC_TX_BDR_CNT 1 |
| 99 | #define ENETC_RX_BDR_ID 0 |
| 100 | #define ENETC_TX_BDR_ID 0 |
| 101 | |
| 102 | /* Tx buffer descriptor */ |
| 103 | struct enetc_tx_bd { |
| 104 | __le64 addr; |
| 105 | __le16 buf_len; |
| 106 | __le16 frm_len; |
| 107 | __le16 err_csum; |
| 108 | __le16 flags; |
| 109 | }; |
| 110 | |
| 111 | #define ENETC_TXBD_FLAGS_F BIT(15) |
| 112 | #define ENETC_POLL_TRIES 32000 |
| 113 | |
| 114 | /* Rx buffer descriptor */ |
| 115 | union enetc_rx_bd { |
| 116 | /* SW provided BD format */ |
| 117 | struct { |
| 118 | __le64 addr; |
| 119 | u8 reserved[8]; |
| 120 | } w; |
| 121 | |
| 122 | /* ENETC returned BD format */ |
| 123 | struct { |
| 124 | __le16 inet_csum; |
| 125 | __le16 parse_summary; |
| 126 | __le32 rss_hash; |
| 127 | __le16 buf_len; |
| 128 | __le16 vlan_opt; |
| 129 | union { |
| 130 | struct { |
| 131 | __le16 flags; |
| 132 | __le16 error; |
| 133 | }; |
| 134 | __le32 lstatus; |
| 135 | }; |
| 136 | } r; |
| 137 | }; |
| 138 | |
| 139 | #define ENETC_RXBD_STATUS_R(status) (((status) >> 30) & 0x1) |
| 140 | #define ENETC_RXBD_STATUS_F(status) (((status) >> 31) & 0x1) |
| 141 | #define ENETC_RXBD_STATUS_ERRORS(status) (((status) >> 16) & 0xff) |
| 142 | #define ENETC_RXBD_STATUS(flags) ((flags) << 16) |
| 143 | |
| 144 | /* Tx/Rx ring info */ |
| 145 | struct bd_ring { |
| 146 | void *cons_idx; |
| 147 | void *prod_idx; |
| 148 | /* next BD index to use */ |
| 149 | int next_prod_idx; |
| 150 | int next_cons_idx; |
| 151 | int bd_count; |
| 152 | }; |
| 153 | |
| 154 | /* ENETC private structure */ |
| 155 | struct enetc_priv { |
| 156 | struct enetc_tx_bd *enetc_txbd; |
| 157 | union enetc_rx_bd *enetc_rxbd; |
| 158 | |
| 159 | void *regs_base; /* base ENETC registers */ |
| 160 | void *port_regs; /* base ENETC port registers */ |
| 161 | |
| 162 | /* Rx/Tx buffer descriptor rings info */ |
| 163 | struct bd_ring tx_bdr; |
| 164 | struct bd_ring rx_bdr; |
Alex Marginean | 0215539 | 2019-07-03 12:11:41 +0300 | [diff] [blame] | 165 | |
Simon Glass | fada3f9 | 2022-09-17 09:00:09 -0600 | [diff] [blame] | 166 | int uclass_id; |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 167 | struct mii_dev imdio; |
Alex Marginean | 602e00f | 2019-11-25 17:15:13 +0200 | [diff] [blame] | 168 | struct phy_device *phy; |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 169 | }; |
| 170 | |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 171 | /* PCS / internal SoC PHY ID, it defaults to 0 on all interfaces */ |
| 172 | #define ENETC_PCS_PHY_ADDR 0 |
| 173 | |
| 174 | /* PCS registers */ |
| 175 | #define ENETC_PCS_CR 0x00 |
| 176 | #define ENETC_PCS_CR_RESET_AN 0x1200 |
| 177 | #define ENETC_PCS_CR_DEF_VAL 0x0140 |
Alex Marginean | 41a7ac5 | 2019-07-15 11:48:47 +0300 | [diff] [blame] | 178 | #define ENETC_PCS_CR_RST BIT(15) |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 179 | #define ENETC_PCS_DEV_ABILITY 0x04 |
| 180 | #define ENETC_PCS_DEV_ABILITY_SGMII 0x4001 |
| 181 | #define ENETC_PCS_DEV_ABILITY_SXGMII 0x5001 |
| 182 | #define ENETC_PCS_LINK_TIMER1 0x12 |
| 183 | #define ENETC_PCS_LINK_TIMER1_VAL 0x06a0 |
| 184 | #define ENETC_PCS_LINK_TIMER2 0x13 |
| 185 | #define ENETC_PCS_LINK_TIMER2_VAL 0x0003 |
| 186 | #define ENETC_PCS_IF_MODE 0x14 |
Alex Marginean | 41a7ac5 | 2019-07-15 11:48:47 +0300 | [diff] [blame] | 187 | #define ENETC_PCS_IF_MODE_SGMII BIT(0) |
| 188 | #define ENETC_PCS_IF_MODE_SGMII_AN BIT(1) |
| 189 | #define ENETC_PCS_IF_MODE_SPEED_1G BIT(3) |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 190 | |
| 191 | /* PCS replicator block for USXGMII */ |
| 192 | #define ENETC_PCS_DEVAD_REPL 0x1f |
| 193 | |
Alex Marginean | 4ea74fd | 2021-01-25 14:23:55 +0200 | [diff] [blame] | 194 | #define ENETC_PCS_REPL_LINK_TIMER_1 0x12 |
| 195 | #define ENETC_PCS_REPL_LINK_TIMER_1_DEF 0x0003 |
| 196 | #define ENETC_PCS_REPL_LINK_TIMER_2 0x13 |
| 197 | #define ENETC_PCS_REPL_LINK_TIMER_2_DEF 0x06a0 |
| 198 | |
Alex Marginean | 0215539 | 2019-07-03 12:11:41 +0300 | [diff] [blame] | 199 | /* ENETC external MDIO registers */ |
| 200 | #define ENETC_MDIO_BASE 0x1c00 |
| 201 | #define ENETC_MDIO_CFG 0x00 |
| 202 | #define ENETC_EMDIO_CFG_C22 0x00809508 |
| 203 | #define ENETC_EMDIO_CFG_C45 0x00809548 |
| 204 | #define ENETC_EMDIO_CFG_RD_ER BIT(1) |
| 205 | #define ENETC_EMDIO_CFG_BSY BIT(0) |
| 206 | #define ENETC_MDIO_CTL 0x04 |
| 207 | #define ENETC_MDIO_CTL_READ BIT(15) |
| 208 | #define ENETC_MDIO_DATA 0x08 |
| 209 | #define ENETC_MDIO_STAT 0x0c |
| 210 | |
| 211 | #define ENETC_MDIO_READ_ERR 0xffff |
| 212 | |
| 213 | struct enetc_mdio_priv { |
| 214 | void *regs_base; |
| 215 | }; |
| 216 | |
Alex Marginean | 38882ae | 2019-07-03 12:11:42 +0300 | [diff] [blame] | 217 | /* |
| 218 | * these functions are implemented by ENETC_MDIO and are re-used by ENETC driver |
| 219 | * to drive serdes / internal SoC PHYs |
| 220 | */ |
| 221 | int enetc_mdio_read_priv(struct enetc_mdio_priv *priv, int addr, int devad, |
| 222 | int reg); |
| 223 | int enetc_mdio_write_priv(struct enetc_mdio_priv *priv, int addr, int devad, |
| 224 | int reg, u16 val); |
| 225 | |
Alex Marginean | 805b859 | 2019-12-10 16:55:39 +0200 | [diff] [blame] | 226 | /* sets up primary MAC addresses in DT/IERB */ |
| 227 | void fdt_fixup_enetc_mac(void *blob); |
| 228 | |
Alex Marginean | 7a910c1 | 2019-07-03 12:11:40 +0300 | [diff] [blame] | 229 | #endif /* _ENETC_H */ |