blob: 82c2476e1fa3f1e4b7e50e4b392f5d3ed2123d5a [file] [log] [blame]
Alex Marginean7a910c12019-07-03 12:11:40 +03001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * ENETC ethernet controller driver
Vladimir Oltean14ca0c32021-06-29 20:53:16 +03004 * Copyright 2017-2021 NXP
Alex Marginean7a910c12019-07-03 12:11:40 +03005 */
6
7#ifndef _ENETC_H
8#define _ENETC_H
9
Simon Glass4dcacfc2020-05-10 11:40:13 -060010#include <linux/bitops.h>
Alex Marginean7a910c12019-07-03 12:11:40 +030011#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 Marginean02155392019-07-03 12:11:41 +030015#define PCI_DEVICE_ID_ENETC_MDIO 0xEE01
Alice Guo9a347952025-01-16 05:03:29 +010016#define PCI_DEVICE_ID_ENETC4_EMDIO 0xEE00
Alex Marginean7a910c12019-07-03 12:11:40 +030017
18/* ENETC Ethernet controller registers */
19/* Station interface register offsets */
20#define ENETC_SIMR 0x000
21#define ENETC_SIMR_EN BIT(31)
22#define ENETC_SICAR0 0x040
23/* write cache cfg: snoop, no allocate, data & BD coherent */
24#define ENETC_SICAR_WR_CFG 0x6767
25/* read cache cfg: coherent copy, look up, don't alloc in cache */
26#define ENETC_SICAR_RD_CFG 0x27270000
27#define ENETC_SIROCT 0x300
28#define ENETC_SIRFRM 0x308
29#define ENETC_SITOCT 0x320
30#define ENETC_SITFRM 0x328
31
32/* Rx/Tx Buffer Descriptor Ring registers */
33enum enetc_bdr_type {TX, RX};
34#define ENETC_BDR(type, n, off) (0x8000 + (type) * 0x100 + (n) * 0x200 + (off))
35#define ENETC_BDR_IDX_MASK 0xffff
36
37/* Rx BDR reg offsets */
38#define ENETC_RBMR 0x00
39#define ENETC_RBMR_EN BIT(31)
40#define ENETC_RBBSR 0x08
41/* initial consumer index for Rx BDR */
42#define ENETC_RBCIR 0x0c
43#define ENETC_RBBAR0 0x10
44#define ENETC_RBBAR1 0x14
45#define ENETC_RBPIR 0x18
46#define ENETC_RBLENR 0x20
47
48/* Tx BDR reg offsets */
49#define ENETC_TBMR 0x00
50#define ENETC_TBMR_EN BIT(31)
51#define ENETC_TBBAR0 0x10
52#define ENETC_TBBAR1 0x14
53#define ENETC_TBPIR 0x18
54#define ENETC_TBCIR 0x1c
55#define ENETC_TBLENR 0x20
56
57/* Port registers offset */
58#define ENETC_PORT_REGS_OFF 0x10000
59
60/* Port registers */
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010061#define ENETC_PMR_OFFSET_LS 0x0000
Alex Marginean7a910c12019-07-03 12:11:40 +030062#define ENETC_PMR 0x0000
63#define ENETC_PMR_SI0_EN BIT(16)
64#define ENETC_PSIPMMR 0x0018
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010065#define ENETC_PSIPMARn_OFFSET_LS 0x0080
66#define ENETC_PSIPMAR0 0x0080
67#define ENETC_PSIPMAR1 0x0084
68#define ENETC_PCAPR_OFFSET_LS 0x0900
69#define ENETC_PCAPR0 0x0000
Alex Marginean38882ae2019-07-03 12:11:42 +030070#define ENETC_PCAPRO_MDIO BIT(11)
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010071#define ENETC_PSICFGR_OFFSET_LS 0x0940
72#define ENETC_PSICFGR_SHIFT_LS 0x10
73#define ENETC_PSICFGR(n, s) ((n) * (s))
74#define ENETC_PSICFGR_SET_BDR(rx, tx) (((rx) << 16) | (tx))
Alex Marginean7a910c12019-07-03 12:11:40 +030075/* MAC configuration */
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010076#define ENETC_PM_OFFSET_LS 0x8000
77#define ENETC_PM_CC 0x0008
Alex Marginean7a910c12019-07-03 12:11:40 +030078#define ENETC_PM_CC_DEFAULT 0x0810
79#define ENETC_PM_CC_RX_TX_EN 0x8813
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010080#define ENETC_PM_MAXFRM 0x0014
Alex Marginean7a910c12019-07-03 12:11:40 +030081#define ENETC_RX_MAXFRM_SIZE PKTSIZE_ALIGN
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010082#define ENETC_PM_IMDIO_BASE 0x0030
83#define ENETC_PM_IF_MODE 0x0300
Alex Marginean38882ae2019-07-03 12:11:42 +030084#define ENETC_PM_IF_MODE_RG BIT(2)
85#define ENETC_PM_IF_MODE_AN_ENA BIT(15)
Vladimir Oltean14ca0c32021-06-29 20:53:16 +030086#define ENETC_PM_IFM_SSP_MASK GENMASK(14, 13)
87#define ENETC_PM_IFM_SSP_1000 (2 << 13)
88#define ENETC_PM_IFM_SSP_100 (0 << 13)
89#define ENETC_PM_IFM_SSP_10 (1 << 13)
90#define ENETC_PM_IFM_FULL_DPX BIT(12)
Alex Marginean38882ae2019-07-03 12:11:42 +030091#define ENETC_PM_IF_IFMODE_MASK GENMASK(1, 0)
Alex Marginean7a910c12019-07-03 12:11:40 +030092
93/* buffer descriptors count must be multiple of 8 and aligned to 128 bytes */
94#define ENETC_BD_CNT CONFIG_SYS_RX_ETH_BUFFER
95#define ENETC_BD_ALIGN 128
96
97/* single pair of Rx/Tx rings */
98#define ENETC_RX_BDR_CNT 1
99#define ENETC_TX_BDR_CNT 1
100#define ENETC_RX_BDR_ID 0
101#define ENETC_TX_BDR_ID 0
102
103/* Tx buffer descriptor */
104struct enetc_tx_bd {
105 __le64 addr;
106 __le16 buf_len;
107 __le16 frm_len;
108 __le16 err_csum;
109 __le16 flags;
110};
111
112#define ENETC_TXBD_FLAGS_F BIT(15)
113#define ENETC_POLL_TRIES 32000
114
115/* Rx buffer descriptor */
116union enetc_rx_bd {
117 /* SW provided BD format */
118 struct {
119 __le64 addr;
120 u8 reserved[8];
121 } w;
122
123 /* ENETC returned BD format */
124 struct {
125 __le16 inet_csum;
126 __le16 parse_summary;
127 __le32 rss_hash;
128 __le16 buf_len;
129 __le16 vlan_opt;
130 union {
131 struct {
132 __le16 flags;
133 __le16 error;
134 };
135 __le32 lstatus;
136 };
137 } r;
138};
139
140#define ENETC_RXBD_STATUS_R(status) (((status) >> 30) & 0x1)
141#define ENETC_RXBD_STATUS_F(status) (((status) >> 31) & 0x1)
142#define ENETC_RXBD_STATUS_ERRORS(status) (((status) >> 16) & 0xff)
143#define ENETC_RXBD_STATUS(flags) ((flags) << 16)
144
145/* Tx/Rx ring info */
146struct bd_ring {
147 void *cons_idx;
148 void *prod_idx;
149 /* next BD index to use */
150 int next_prod_idx;
151 int next_cons_idx;
152 int bd_count;
153};
154
155/* ENETC private structure */
156struct enetc_priv {
157 struct enetc_tx_bd *enetc_txbd;
158 union enetc_rx_bd *enetc_rxbd;
159
160 void *regs_base; /* base ENETC registers */
161 void *port_regs; /* base ENETC port registers */
162
163 /* Rx/Tx buffer descriptor rings info */
164 struct bd_ring tx_bdr;
165 struct bd_ring rx_bdr;
Alex Marginean02155392019-07-03 12:11:41 +0300166
Simon Glassfada3f92022-09-17 09:00:09 -0600167 int uclass_id;
Alex Marginean38882ae2019-07-03 12:11:42 +0300168 struct mii_dev imdio;
Alex Marginean602e00f2019-11-25 17:15:13 +0200169 struct phy_device *phy;
Alex Marginean7a910c12019-07-03 12:11:40 +0300170};
171
Marek Vasutd89b2262025-01-16 05:03:26 +0100172struct enetc_data {
173 /* Register layout offsets */
174 u16 reg_offset_pmr;
175 u16 reg_offset_psipmar;
176 u16 reg_offset_pcapr;
177 u16 reg_offset_psicfgr;
178 u16 reg_offset_mac;
179};
180
Alex Marginean38882ae2019-07-03 12:11:42 +0300181/* PCS / internal SoC PHY ID, it defaults to 0 on all interfaces */
182#define ENETC_PCS_PHY_ADDR 0
183
184/* PCS registers */
185#define ENETC_PCS_CR 0x00
186#define ENETC_PCS_CR_RESET_AN 0x1200
187#define ENETC_PCS_CR_DEF_VAL 0x0140
Alex Marginean41a7ac52019-07-15 11:48:47 +0300188#define ENETC_PCS_CR_RST BIT(15)
Alex Marginean38882ae2019-07-03 12:11:42 +0300189#define ENETC_PCS_DEV_ABILITY 0x04
190#define ENETC_PCS_DEV_ABILITY_SGMII 0x4001
191#define ENETC_PCS_DEV_ABILITY_SXGMII 0x5001
192#define ENETC_PCS_LINK_TIMER1 0x12
193#define ENETC_PCS_LINK_TIMER1_VAL 0x06a0
194#define ENETC_PCS_LINK_TIMER2 0x13
195#define ENETC_PCS_LINK_TIMER2_VAL 0x0003
196#define ENETC_PCS_IF_MODE 0x14
Alex Marginean41a7ac52019-07-15 11:48:47 +0300197#define ENETC_PCS_IF_MODE_SGMII BIT(0)
198#define ENETC_PCS_IF_MODE_SGMII_AN BIT(1)
199#define ENETC_PCS_IF_MODE_SPEED_1G BIT(3)
Alex Marginean38882ae2019-07-03 12:11:42 +0300200
201/* PCS replicator block for USXGMII */
202#define ENETC_PCS_DEVAD_REPL 0x1f
203
Alex Marginean4ea74fd2021-01-25 14:23:55 +0200204#define ENETC_PCS_REPL_LINK_TIMER_1 0x12
205#define ENETC_PCS_REPL_LINK_TIMER_1_DEF 0x0003
206#define ENETC_PCS_REPL_LINK_TIMER_2 0x13
207#define ENETC_PCS_REPL_LINK_TIMER_2_DEF 0x06a0
208
Alex Marginean02155392019-07-03 12:11:41 +0300209/* ENETC external MDIO registers */
210#define ENETC_MDIO_BASE 0x1c00
211#define ENETC_MDIO_CFG 0x00
212#define ENETC_EMDIO_CFG_C22 0x00809508
213#define ENETC_EMDIO_CFG_C45 0x00809548
214#define ENETC_EMDIO_CFG_RD_ER BIT(1)
215#define ENETC_EMDIO_CFG_BSY BIT(0)
216#define ENETC_MDIO_CTL 0x04
217#define ENETC_MDIO_CTL_READ BIT(15)
218#define ENETC_MDIO_DATA 0x08
219#define ENETC_MDIO_STAT 0x0c
220
221#define ENETC_MDIO_READ_ERR 0xffff
222
223struct enetc_mdio_priv {
224 void *regs_base;
225};
226
Alex Marginean38882ae2019-07-03 12:11:42 +0300227/*
228 * these functions are implemented by ENETC_MDIO and are re-used by ENETC driver
229 * to drive serdes / internal SoC PHYs
230 */
231int enetc_mdio_read_priv(struct enetc_mdio_priv *priv, int addr, int devad,
232 int reg);
233int enetc_mdio_write_priv(struct enetc_mdio_priv *priv, int addr, int devad,
234 int reg, u16 val);
235
Alex Marginean805b8592019-12-10 16:55:39 +0200236/* sets up primary MAC addresses in DT/IERB */
237void fdt_fixup_enetc_mac(void *blob);
238
Alex Marginean7a910c12019-07-03 12:11:40 +0300239#endif /* _ENETC_H */