blob: 804df853bf51170d6c3b5b819122edfca2c4aadd [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
Alice Guo2e0be5a2025-01-16 05:03:30 +010015#define PCI_DEVICE_ID_ENETC4_ETH 0xE101
Alex Marginean02155392019-07-03 12:11:41 +030016#define PCI_DEVICE_ID_ENETC_MDIO 0xEE01
Alice Guo9a347952025-01-16 05:03:29 +010017#define PCI_DEVICE_ID_ENETC4_EMDIO 0xEE00
Alex Marginean7a910c12019-07-03 12:11:40 +030018
19/* ENETC Ethernet controller registers */
20/* Station interface register offsets */
21#define ENETC_SIMR 0x000
22#define ENETC_SIMR_EN BIT(31)
23#define ENETC_SICAR0 0x040
24/* write cache cfg: snoop, no allocate, data & BD coherent */
25#define ENETC_SICAR_WR_CFG 0x6767
26/* read cache cfg: coherent copy, look up, don't alloc in cache */
Alice Guo2e0be5a2025-01-16 05:03:30 +010027#define ENETC_SICAR_RD_CFG_LS 0x27270000
28#define ENETC_SICAR_RD_CFG_IMX 0x2b2b0000
Alex Marginean7a910c12019-07-03 12:11:40 +030029#define ENETC_SIROCT 0x300
30#define ENETC_SIRFRM 0x308
31#define ENETC_SITOCT 0x320
32#define ENETC_SITFRM 0x328
33
34/* Rx/Tx Buffer Descriptor Ring registers */
35enum enetc_bdr_type {TX, RX};
36#define ENETC_BDR(type, n, off) (0x8000 + (type) * 0x100 + (n) * 0x200 + (off))
37#define ENETC_BDR_IDX_MASK 0xffff
38
39/* Rx BDR reg offsets */
40#define ENETC_RBMR 0x00
41#define ENETC_RBMR_EN BIT(31)
42#define ENETC_RBBSR 0x08
43/* initial consumer index for Rx BDR */
44#define ENETC_RBCIR 0x0c
45#define ENETC_RBBAR0 0x10
46#define ENETC_RBBAR1 0x14
47#define ENETC_RBPIR 0x18
48#define ENETC_RBLENR 0x20
49
50/* Tx BDR reg offsets */
51#define ENETC_TBMR 0x00
52#define ENETC_TBMR_EN BIT(31)
53#define ENETC_TBBAR0 0x10
54#define ENETC_TBBAR1 0x14
55#define ENETC_TBPIR 0x18
56#define ENETC_TBCIR 0x1c
57#define ENETC_TBLENR 0x20
58
59/* Port registers offset */
60#define ENETC_PORT_REGS_OFF 0x10000
61
62/* Port registers */
Alice Guo2e0be5a2025-01-16 05:03:30 +010063#define ENETC_PMR_OFFSET_IMX 0x0010
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010064#define ENETC_PMR_OFFSET_LS 0x0000
Alex Marginean7a910c12019-07-03 12:11:40 +030065#define ENETC_PMR 0x0000
66#define ENETC_PMR_SI0_EN BIT(16)
67#define ENETC_PSIPMMR 0x0018
Alice Guo2e0be5a2025-01-16 05:03:30 +010068#define ENETC_PSIPMARn_OFFSET_IMX 0x0000
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010069#define ENETC_PSIPMARn_OFFSET_LS 0x0080
70#define ENETC_PSIPMAR0 0x0080
71#define ENETC_PSIPMAR1 0x0084
Alice Guo2e0be5a2025-01-16 05:03:30 +010072#define ENETC_PCAPR_OFFSET_IMX 0x4008
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010073#define ENETC_PCAPR_OFFSET_LS 0x0900
74#define ENETC_PCAPR0 0x0000
Alice Guo2e0be5a2025-01-16 05:03:30 +010075#define ENETC_PCAPRO_MDIO BIT(11) /* LS only */
76#define ENETC_PCS_PROT GENMASK(15, 0) /* IMX only */
77/* ENETC base registers */
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010078#define ENETC_PSICFGR_OFFSET_LS 0x0940
79#define ENETC_PSICFGR_SHIFT_LS 0x10
Alice Guo2e0be5a2025-01-16 05:03:30 +010080#define ENETC_PSICFGR_OFFSET_IMX 0x2010
81#define ENETC_PSICFGR_SHIFT_IMX 0x80
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010082#define ENETC_PSICFGR(n, s) ((n) * (s))
83#define ENETC_PSICFGR_SET_BDR(rx, tx) (((rx) << 16) | (tx))
Alex Marginean7a910c12019-07-03 12:11:40 +030084/* MAC configuration */
Alice Guo2e0be5a2025-01-16 05:03:30 +010085#define ENETC_PM_OFFSET_IMX 0x5000
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010086#define ENETC_PM_OFFSET_LS 0x8000
87#define ENETC_PM_CC 0x0008
Alex Marginean7a910c12019-07-03 12:11:40 +030088#define ENETC_PM_CC_DEFAULT 0x0810
Alice Guo2e0be5a2025-01-16 05:03:30 +010089#define ENETC_PM_CC_TXP_IMX BIT(15)
90#define ENETC_PM_CC_TXP_LS BIT(11)
91#define ENETC_PM_CC_PROMIS BIT(4)
92#define ENETC_PM_CC_TX BIT(1)
93#define ENETC_PM_CC_RX BIT(0)
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010094#define ENETC_PM_MAXFRM 0x0014
Alex Marginean7a910c12019-07-03 12:11:40 +030095#define ENETC_RX_MAXFRM_SIZE PKTSIZE_ALIGN
Marek Vasuta1fa5cb2025-01-16 05:03:25 +010096#define ENETC_PM_IMDIO_BASE 0x0030
97#define ENETC_PM_IF_MODE 0x0300
Alex Marginean38882ae2019-07-03 12:11:42 +030098#define ENETC_PM_IF_MODE_RG BIT(2)
99#define ENETC_PM_IF_MODE_AN_ENA BIT(15)
Vladimir Oltean14ca0c32021-06-29 20:53:16 +0300100#define ENETC_PM_IFM_SSP_MASK GENMASK(14, 13)
101#define ENETC_PM_IFM_SSP_1000 (2 << 13)
102#define ENETC_PM_IFM_SSP_100 (0 << 13)
103#define ENETC_PM_IFM_SSP_10 (1 << 13)
Alice Guo2e0be5a2025-01-16 05:03:30 +0100104#define ENETC_PM_IFM_FULL_DPX_IMX BIT(6)
105#define ENETC_PM_IFM_FULL_DPX_LS BIT(12)
106#define ENETC_PM_IF_IFMODE_MASK_IMX GENMASK(2, 0)
107#define ENETC_PM_IF_IFMODE_MASK_LS GENMASK(1, 0)
108
109/* i.MX95 specific registers */
110#define IMX95_ENETC_SIPMAR0 0x80
111#define IMX95_ENETC_SIPMAR1 0x84
112
113/* Port registers */
114#define IMX95_ENETC_PMAR0 0x4020
115#define IMX95_ENETC_PMAR1 0x4024
116#define ENETC_POR 0x4100
Alex Marginean7a910c12019-07-03 12:11:40 +0300117
118/* buffer descriptors count must be multiple of 8 and aligned to 128 bytes */
119#define ENETC_BD_CNT CONFIG_SYS_RX_ETH_BUFFER
120#define ENETC_BD_ALIGN 128
121
122/* single pair of Rx/Tx rings */
123#define ENETC_RX_BDR_CNT 1
124#define ENETC_TX_BDR_CNT 1
125#define ENETC_RX_BDR_ID 0
126#define ENETC_TX_BDR_ID 0
127
128/* Tx buffer descriptor */
129struct enetc_tx_bd {
130 __le64 addr;
131 __le16 buf_len;
132 __le16 frm_len;
133 __le16 err_csum;
134 __le16 flags;
135};
136
137#define ENETC_TXBD_FLAGS_F BIT(15)
138#define ENETC_POLL_TRIES 32000
139
140/* Rx buffer descriptor */
141union enetc_rx_bd {
142 /* SW provided BD format */
143 struct {
144 __le64 addr;
145 u8 reserved[8];
146 } w;
147
148 /* ENETC returned BD format */
149 struct {
150 __le16 inet_csum;
151 __le16 parse_summary;
152 __le32 rss_hash;
153 __le16 buf_len;
154 __le16 vlan_opt;
155 union {
156 struct {
157 __le16 flags;
158 __le16 error;
159 };
160 __le32 lstatus;
161 };
162 } r;
163};
164
165#define ENETC_RXBD_STATUS_R(status) (((status) >> 30) & 0x1)
166#define ENETC_RXBD_STATUS_F(status) (((status) >> 31) & 0x1)
167#define ENETC_RXBD_STATUS_ERRORS(status) (((status) >> 16) & 0xff)
168#define ENETC_RXBD_STATUS(flags) ((flags) << 16)
169
170/* Tx/Rx ring info */
171struct bd_ring {
172 void *cons_idx;
173 void *prod_idx;
174 /* next BD index to use */
175 int next_prod_idx;
176 int next_cons_idx;
177 int bd_count;
178};
179
180/* ENETC private structure */
181struct enetc_priv {
182 struct enetc_tx_bd *enetc_txbd;
183 union enetc_rx_bd *enetc_rxbd;
184
185 void *regs_base; /* base ENETC registers */
186 void *port_regs; /* base ENETC port registers */
187
188 /* Rx/Tx buffer descriptor rings info */
189 struct bd_ring tx_bdr;
190 struct bd_ring rx_bdr;
Alex Marginean02155392019-07-03 12:11:41 +0300191
Simon Glassfada3f92022-09-17 09:00:09 -0600192 int uclass_id;
Alex Marginean38882ae2019-07-03 12:11:42 +0300193 struct mii_dev imdio;
Alex Marginean602e00f2019-11-25 17:15:13 +0200194 struct phy_device *phy;
Alex Marginean7a910c12019-07-03 12:11:40 +0300195};
196
Marek Vasutd89b2262025-01-16 05:03:26 +0100197struct enetc_data {
198 /* Register layout offsets */
199 u16 reg_offset_pmr;
200 u16 reg_offset_psipmar;
201 u16 reg_offset_pcapr;
202 u16 reg_offset_psicfgr;
203 u16 reg_offset_mac;
204};
205
Alex Marginean38882ae2019-07-03 12:11:42 +0300206/* PCS / internal SoC PHY ID, it defaults to 0 on all interfaces */
207#define ENETC_PCS_PHY_ADDR 0
208
209/* PCS registers */
210#define ENETC_PCS_CR 0x00
211#define ENETC_PCS_CR_RESET_AN 0x1200
212#define ENETC_PCS_CR_DEF_VAL 0x0140
Alex Marginean41a7ac52019-07-15 11:48:47 +0300213#define ENETC_PCS_CR_RST BIT(15)
Alex Marginean38882ae2019-07-03 12:11:42 +0300214#define ENETC_PCS_DEV_ABILITY 0x04
215#define ENETC_PCS_DEV_ABILITY_SGMII 0x4001
216#define ENETC_PCS_DEV_ABILITY_SXGMII 0x5001
217#define ENETC_PCS_LINK_TIMER1 0x12
218#define ENETC_PCS_LINK_TIMER1_VAL 0x06a0
219#define ENETC_PCS_LINK_TIMER2 0x13
220#define ENETC_PCS_LINK_TIMER2_VAL 0x0003
221#define ENETC_PCS_IF_MODE 0x14
Alex Marginean41a7ac52019-07-15 11:48:47 +0300222#define ENETC_PCS_IF_MODE_SGMII BIT(0)
223#define ENETC_PCS_IF_MODE_SGMII_AN BIT(1)
224#define ENETC_PCS_IF_MODE_SPEED_1G BIT(3)
Alex Marginean38882ae2019-07-03 12:11:42 +0300225
226/* PCS replicator block for USXGMII */
227#define ENETC_PCS_DEVAD_REPL 0x1f
228
Alex Marginean4ea74fd2021-01-25 14:23:55 +0200229#define ENETC_PCS_REPL_LINK_TIMER_1 0x12
230#define ENETC_PCS_REPL_LINK_TIMER_1_DEF 0x0003
231#define ENETC_PCS_REPL_LINK_TIMER_2 0x13
232#define ENETC_PCS_REPL_LINK_TIMER_2_DEF 0x06a0
233
Alex Marginean02155392019-07-03 12:11:41 +0300234/* ENETC external MDIO registers */
235#define ENETC_MDIO_BASE 0x1c00
236#define ENETC_MDIO_CFG 0x00
237#define ENETC_EMDIO_CFG_C22 0x00809508
238#define ENETC_EMDIO_CFG_C45 0x00809548
239#define ENETC_EMDIO_CFG_RD_ER BIT(1)
240#define ENETC_EMDIO_CFG_BSY BIT(0)
241#define ENETC_MDIO_CTL 0x04
242#define ENETC_MDIO_CTL_READ BIT(15)
243#define ENETC_MDIO_DATA 0x08
244#define ENETC_MDIO_STAT 0x0c
245
246#define ENETC_MDIO_READ_ERR 0xffff
247
248struct enetc_mdio_priv {
249 void *regs_base;
250};
251
Alex Marginean38882ae2019-07-03 12:11:42 +0300252/*
253 * these functions are implemented by ENETC_MDIO and are re-used by ENETC driver
254 * to drive serdes / internal SoC PHYs
255 */
256int enetc_mdio_read_priv(struct enetc_mdio_priv *priv, int addr, int devad,
257 int reg);
258int enetc_mdio_write_priv(struct enetc_mdio_priv *priv, int addr, int devad,
259 int reg, u16 val);
260
Alex Marginean805b8592019-12-10 16:55:39 +0200261/* sets up primary MAC addresses in DT/IERB */
262void fdt_fixup_enetc_mac(void *blob);
263
Alex Marginean7a910c12019-07-03 12:11:40 +0300264#endif /* _ENETC_H */