Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2024-2026 NXP
3 : : *
4 : : * This header file defines the register offsets and bit fields
5 : : * of ENETC4 PF and VFs.
6 : : */
7 : :
8 : : #ifndef _ENETC4_HW_H_
9 : : #define _ENETC4_HW_H_
10 : : #include <rte_io.h>
11 : : #include "enetc_hw.h"
12 : :
13 : : #define BIT(x) ((uint64_t)1 << ((x)))
14 : :
15 : : /* ENETC4 device IDs */
16 : : #define ENETC4_DEV_ID 0xe101
17 : : #define ENETC4_DEV_ID_VF 0xef00
18 : : #define PCI_VENDOR_ID_NXP 0x1131
19 : :
20 : : struct enetc_msg_swbd {
21 : : void *vaddr;
22 : : uint64_t dma;
23 : : uint32_t size;
24 : : };
25 : :
26 : : /* enetc4 txbd flags */
27 : : #define ENETC4_TXBD_FLAGS_L4CS BIT(0)
28 : : /* Request LSO (Large Send Offload) segmentation for this frame */
29 : : #define ENETC4_TXBD_FLAGS_LSO BIT(1)
30 : : /* L4 checksum insertion (also used for checksum update on LSO) */
31 : : #define ENETC4_TXBD_FLAGS_L_TX_CKSUM BIT(3)
32 : : /* Extended descriptor: the next 16B ring entry is an extension BD */
33 : : #define ENETC4_TXBD_FLAGS_EXT BIT(6)
34 : : #define ENETC4_TXBD_FLAGS_F BIT(7)
35 : : /* L4 type */
36 : : #define ENETC4_TXBD_L4T_UDP BIT(0)
37 : : #define ENETC4_TXBD_L4T_TCP BIT(1)
38 : : /* L3 type is set to 0 for IPv4 and 1 for IPv6 */
39 : : #define ENETC4_TXBD_L3T 0
40 : : /* IPv4 checksum */
41 : : #define ENETC4_TXBD_IPCS 1
42 : :
43 : : /*
44 : : * Extension Transmit Buffer Descriptor (16B). When the standard BD has the
45 : : * extended flag set, this occupies the next ring entry and carries the extra
46 : : * fields required by LSO.
47 : : */
48 : : struct enetc_tx_bd_ext {
49 : : uint32_t timestamp; /* PTP timestamp, unused for LSO */
50 : : uint32_t vlan; /* VLAN insert, unused for LSO */
51 : : uint32_t lso; /* LSO_MAX_SEG_SIZE and FRM_LEN_EXT */
52 : : uint32_t flags; /* extension flags */
53 : : };
54 : :
55 : : /* LSO_MAX_SEG_SIZE occupies bits 13-0 of the LSO word */
56 : : #define ENETC4_TXBD_EXT_LSO_SEG_MASK 0x3fff
57 : : #define ENETC4_TXBD_EXT_LSO_SEG(mss) \
58 : : ((uint32_t)((mss) & ENETC4_TXBD_EXT_LSO_SEG_MASK))
59 : : /* FRM_LEN_EXT occupies bits 19-16 of the LSO word (top 4 bits of data len) */
60 : : #define ENETC4_TXBD_EXT_FRM_LEN_EXT(x) \
61 : : (((uint32_t)((x) & 0xf)) << 16)
62 : :
63 : : /* NETC does not create LSO frames larger than this many bytes */
64 : : #define ENETC4_LSO_MAX_FRAME 9600
65 : : /* Maximum LSO data unit (payload to be segmented) supported by HW: 256KB */
66 : : #define ENETC4_LSO_MAX_DATA_UNIT (256 * 1024)
67 : :
68 : : /***************************ENETC port registers**************************/
69 : : #define ENETC4_PMR 0x10
70 : : #define ENETC4_PMR_EN (BIT(16) | BIT(17) | BIT(18))
71 : :
72 : : #define ENETC4_PARCSCR 0x9c
73 : : #define L3_CKSUM BIT(0)
74 : : #define L4_CKSUM BIT(1)
75 : :
76 : : /* Port Station interface promiscuous MAC mode register */
77 : : #define ENETC4_PSIPMMR 0x200
78 : : #define PSIPMMR_SI0_MAC_UP BIT(0)
79 : : #define PSIPMMR_SI_MAC_UP (BIT(0) | BIT(1) | BIT(2))
80 : : #define PSIPMMR_SI0_MAC_MP BIT(16)
81 : : #define PSIPMMR_SI_MAC_MP (BIT(16) | BIT(17) | BIT(18))
82 : :
83 : : /* Port Station interface a primary MAC address registers */
84 : : #define ENETC4_PSIPMAR0(a) ((a) * 0x80 + 0x2000)
85 : : #define ENETC4_PSIPMAR1(a) ((a) * 0x80 + 0x2004)
86 : :
87 : : /* Port MAC address register 0/1 */
88 : : #define ENETC4_PMAR0 0x4020
89 : : #define ENETC4_PMAR1 0x4024
90 : :
91 : : /* Port operational register */
92 : : #define ENETC4_POR 0x4100
93 : :
94 : : /* Port traffic class a transmit maximum SDU register */
95 : : #define ENETC4_PTCTMSDUR(a) ((a) * 0x20 + 0x4208)
96 : : #define SDU_TYPE_MPDU BIT(16)
97 : :
98 : : #define ENETC4_PM_CMD_CFG(mac) (0x5008 + (mac) * 0x400)
99 : : #define PM_CMD_CFG_TX_EN BIT(0)
100 : : #define PM_CMD_CFG_RX_EN BIT(1)
101 : :
102 : : /* RBaMR[CRC]: 0 = FCS removed, 1 = FCS preserved (KEEP_CRC) */
103 : : #define ENETC4_RBMR_CRC BIT(8)
104 : : /*
105 : : * RBaMR[BDS]: buffer descriptor size select for a receive ring.
106 : : * 0 = standard 16B descriptors, 1 = extended 32B descriptors.
107 : : * RSC requires 32B descriptors (BDS = 1). Matches the Linux enetc
108 : : * driver definition (ENETC_RBMR_BDS = BIT(2)).
109 : : */
110 : : #define ENETC4_RBMR_BDS BIT(2)
111 : :
112 : : /*
113 : : * Rx BDR a RSC register (RBaRSCR), offset 0x30 from the ring base.
114 : : * Controls Receive Segment Coalesce (RSC / LRO) for the ring.
115 : : */
116 : : #define ENETC4_RBRSCR 0x30
117 : : /* Enable RSC on this ring */
118 : : #define ENETC4_RBRSCR_EN BIT(31)
119 : : /* Permit coalescing of TCP segments that carry the timestamp option */
120 : : #define ENETC4_RBRSCR_CT BIT(29)
121 : : /* SIZE field (bits 15-0): maximum coalesced frame size produced by RSC */
122 : : #define ENETC4_RBRSCR_SIZE(x) ((uint32_t)((x) & 0xffff))
123 : :
124 : : /*
125 : : * RBaICR0[ICEN]: interrupt coalescing enable. RSC requires interrupt
126 : : * coalescing to be enabled; the coalescing timer doubles as the RSC flush
127 : : * timer. ICPT (bits 8-0) is the packet-count threshold.
128 : : */
129 : : #define ENETC4_RBICR0 0xa8
130 : : #define ENETC4_RBICR0_ICEN BIT(31)
131 : : #define ENETC4_RBICR0_ICPT(x) ((uint32_t)((x) & 0x1ff))
132 : : /* Rx BDR a interrupt coalescing register 1 (threshold timer) */
133 : : #define ENETC4_RBICR1 0xac
134 : :
135 : : /*
136 : : * SI-level Rx interrupt detect register 0 (SIRXIDR0). W1C, one bit per Rx
137 : : * ring (RX0..RX23). The interrupt-coalescing timer (which also gates RSC
138 : : * coalescing) does not re-arm while a ring's detect bit stays set, so the
139 : : * poll-mode driver writes BIT(ring index) here every poll to keep RSC
140 : : * coalescing. The per-ring RBaIDR (0xa4) is read-only and cannot be used.
141 : : */
142 : : #define ENETC_SIRXIDR 0xa28
143 : :
144 : : /*
145 : : * RSC (Receive Segment Coalesce) limits and defaults.
146 : : * Maximum coalesced frame size the HW will build (programmed in RBaRSCR[SIZE]).
147 : : * Bounded to 16 bits by the SIZE field width.
148 : : */
149 : : #define ENETC4_RSC_MAX_FRAME 0xffff
150 : : /* Default interrupt coalescing packet threshold used to satisfy RSC's ICEN
151 : : * precondition. The PMD is poll-mode, so this only gates the RSC flush timer.
152 : : */
153 : : #define ENETC4_RSC_DEF_ICPT 1
154 : : /*
155 : : * Default interrupt coalescing timer threshold (RBaICR1[ICTT]), in NETC
156 : : * platform clock cycles. This timer is the RSC coalesce-hold window: HW keeps
157 : : * a coalesced frame open while it runs and appends in-order segments. A value
158 : : * of 0 disables the timer and flushes every segment separately (no
159 : : * coalescing), so it must be non-zero for RSC to merge anything.
160 : : */
161 : : #define ENETC4_RSC_DEF_ICTT 0x10000
162 : :
163 : : /*
164 : : * Extended 32B receive writeback buffer descriptor. Used only on RSC-enabled
165 : : * rings (RBaMR[BDS] = 1). The first 16 bytes match the standard descriptor
166 : : * writeback layout; the second 16 bytes carry the RSC and timestamp fields.
167 : : * RSC_FRAMES reports how many frames were coalesced (1 to 255; 1 means the
168 : : * frame was not coalesced).
169 : : */
170 : : struct enetc_rx_bd_ext {
171 : : uint32_t timestamp; /* offset 0x10: PTP timestamp */
172 : : uint32_t rsc_frames; /* offset 0x14: RSC_FRAMES in bits 7-0 */
173 : : uint32_t rsc_abs_ts_delta; /* offset 0x18 */
174 : : uint32_t reserved; /* offset 0x1c */
175 : : };
176 : :
177 : : /* RSC_FRAMES occupies bits 7-0 of the rsc_frames word */
178 : : #define ENETC4_RXBD_EXT_RSC_FRAMES(x) ((x) & 0xff)
179 : :
180 : : /* i.MX95 supports jumbo frame, but it is recommended to set the max frame
181 : : * size to 2000 bytes.
182 : : */
183 : : #define ENETC4_MAC_MAXFRM_SIZE 2000
184 : :
185 : : /* Number of MAC Address Filter table entries */
186 : : #define ENETC4_MAC_ENTRIES 4
187 : :
188 : : /* Port MAC 0/1 Maximum Frame Length Register */
189 : : #define ENETC4_PM_MAXFRM(mac) (0x5014 + (mac) * 0x400)
190 : :
191 : : /* Config register to reset counters */
192 : : #define ENETC4_PM0_STAT_CONFIG 0x50e0
193 : : /* Stats Reset Bit */
194 : : #define ENETC4_CLEAR_STATS BIT(2)
195 : :
196 : : /* Port MAC 0/1 Receive Ethernet Octets Counter */
197 : : #define ENETC4_PM_REOCT(mac) (0x5100 + (mac) * 0x400)
198 : :
199 : : /* Port MAC 0/1 Receive Frame Error Counter */
200 : : #define ENETC4_PM_RERR(mac) (0x5138 + (mac) * 0x400)
201 : :
202 : : /* Port MAC 0/1 Receive Dropped Packets Counter */
203 : : #define ENETC4_PM_RDRP(mac) (0x5158 + (mac) * 0x400)
204 : :
205 : : /* Port MAC 0/1 Receive Packets Counter */
206 : : #define ENETC4_PM_RPKT(mac) (0x5160 + (mac) * 0x400)
207 : :
208 : : /* Port MAC 0/1 Transmit Frame Error Counter */
209 : : #define ENETC4_PM_TERR(mac) (0x5238 + (mac) * 0x400)
210 : :
211 : : /* Port MAC 0/1 Transmit Ethernet Octets Counter */
212 : : #define ENETC4_PM_TEOCT(mac) (0x5200 + (mac) * 0x400)
213 : :
214 : : /* Port MAC 0/1 Transmit Packets Counter */
215 : : #define ENETC4_PM_TPKT(mac) (0x5260 + (mac) * 0x400)
216 : :
217 : : /* Port MAC 0 Interface Mode Control Register */
218 : : #define ENETC4_PM_IF_MODE(mac) (0x5300 + (mac) * 0x400)
219 : : #define PM_IF_MODE_IFMODE (BIT(0) | BIT(1) | BIT(2))
220 : : #define IFMODE_XGMII 0
221 : : #define IFMODE_RMII 3
222 : : #define IFMODE_RGMII 4
223 : : #define IFMODE_SGMII 5
224 : : #define PM_IF_MODE_ENA BIT(15)
225 : :
226 : : /* Port MAC 0 Interface Status Register */
227 : : #define ENETC4_PM_IF_STATUS(mac) (0x5304 + (mac) * 0x400)
228 : : #define ENETC4_LINK_MODE 0x0000000000080000ULL
229 : : #define ENETC4_LINK_STATUS 0x0000000000010000ULL
230 : : #define ENETC4_LINK_SPEED_MASK 0x0000000000060000ULL
231 : : #define ENETC4_LINK_SPEED_10M 0x0ULL
232 : : #define ENETC4_LINK_SPEED_100M 0x0000000000020000ULL
233 : : #define ENETC4_LINK_SPEED_1G 0x0000000000040000ULL
234 : :
235 : : #define ENETC4_DEF_VSI_WAIT_TIMEOUT_UPDATE 100
236 : : #define ENETC4_DEF_VSI_WAIT_DELAY_UPDATE 2000 /* us */
237 : :
238 : : /* Station interface statistics */
239 : : #define ENETC4_SIROCT0 0x300
240 : : #define ENETC4_SIRFRM0 0x308
241 : : #define ENETC4_SITOCT0 0x320
242 : : #define ENETC4_SITFRM0 0x328
243 : : #define ENETC4_SITDFCR 0x340
244 : :
245 : : /* Station interface interrupts */
246 : : #define ENETC4_SIMSIVR 0xA30
247 : : #define ENETC4_VSIIER 0xA00
248 : : #define ENETC4_VSIIDR 0xA08
249 : : #define ENETC4_VSIIER_MRIE BIT(9)
250 : : #define ENETC4_SI_INT_IDX 0
251 : : /* MSI-X vector base for per-Rx-queue interrupts; vector 0 is the mailbox. */
252 : : #define ENETC4_VF_RX_VEC_BASE 1
253 : :
254 : : /* VSI Registers */
255 : : #define ENETC4_VSIMSGSR 0x204 /* RO */
256 : : #define ENETC4_VSIMSGSR_MB BIT(0)
257 : : #define ENETC4_VSIMSGSR_MS BIT(1)
258 : : #define ENETC4_VSIMSGSNDAR0 0x210
259 : : #define ENETC4_VSIMSGSNDAR1 0x214
260 : :
261 : : #define ENETC4_VSIMSGRR 0x208
262 : : #define ENETC4_VSIMSGRR_MR BIT(0)
263 : :
264 : : #define ENETC_SIMSGSR_SET_MC(val) ((val) << 16)
265 : : #define ENETC_SIMSGSR_GET_MC(val) ((val) >> 16)
266 : :
267 : : /* Control BDR regs */
268 : : #define ENETC4_SICBDRMR 0x800
269 : : #define ENETC4_SICBDRSR 0x804 /* RO */
270 : : #define ENETC4_SICBDRBAR0 0x810
271 : : #define ENETC4_SICBDRBAR1 0x814
272 : : #define ENETC4_SICBDRPIR 0x818
273 : : #define ENETC4_SICBDRCIR 0x81c
274 : : #define ENETC4_SICBDRLENR 0x820
275 : : #define ENETC4_SICTR0 0x18
276 : : #define ENETC4_SICTR1 0x1c
277 : :
278 : : /* PSI SI VLAN register: per-SI VLAN tag for insertion/removal */
279 : : #define ENETC4_PSIVLANR(a) ((a) * 0x80 + 0x2008)
280 : : #define ENETC4_PSIVLANR_E BIT(31) /* enable SI VLAN processing */
281 : : #define ENETC4_PSIVLANR_VTEA BIT(30) /* 0=strip tag, 1=zero VID */
282 : : #define ENETC4_PSIVLANR_PCP(v) (((uint32_t)(v) & 0x7) << 13)
283 : : #define ENETC4_PSIVLANR_DEI BIT(12)
284 : : #define ENETC4_PSIVLANR_VID(v) ((uint32_t)(v) & 0xfff)
285 : :
286 : : /* PSI SI configuration register 0 */
287 : : #define ENETC4_PSICFGR0(a) ((a) * 0x80 + 0x2010)
288 : : #define ENETC4_PSICFGR0_SIVC_CVLAN BIT(24) /* allow C-VLAN 0x8100 */
289 : : #define ENETC4_PSICFGR0_SIVIE BIT(14) /* SI VLAN insertion enable */
290 : : #define ENETC4_PSICFGR0_VTE BIT(12) /* SI VLAN removal enable */
291 : :
292 : : /* general register accessors */
293 : : #define enetc4_rd_reg(reg) rte_read32((void *)(reg))
294 : : #define enetc4_wr_reg(reg, val) rte_write32((val), (void *)(reg))
295 : :
296 : : #define enetc4_rd(hw, off) enetc4_rd_reg((size_t)(hw)->reg + (off))
297 : : static inline uint64_t
298 : : enetc4_rd64(struct enetc_hw *hw, uint32_t off)
299 : : {
300 : 0 : size_t base = (size_t)hw->reg + off;
301 : : uint32_t lo, hi, hi_check;
302 : :
303 : : /*
304 : : * A 64-bit statistics counter is read as two 32-bit accesses, so
305 : : * the low word can carry into the high word between the two reads
306 : : * and produce a value that is off by 2^32. Read the high word,
307 : : * then the low word, then re-read the high word; if the high word
308 : : * changed a carry happened during the sequence, so retry.
309 : : */
310 : : do {
311 : 0 : hi = enetc4_rd_reg(base + 4);
312 : 0 : lo = enetc4_rd_reg(base);
313 : : hi_check = enetc4_rd_reg(base + 4);
314 [ # # # # : 0 : } while (hi != hi_check);
# # # # #
# # # # #
# # ]
315 : :
316 : 0 : return (uint64_t)hi << 32 | lo;
317 : : }
318 : : #define enetc4_wr(hw, off, val) enetc4_wr_reg((size_t)(hw)->reg + (off), val)
319 : : /* port register accessors - PF only */
320 : : #define enetc4_port_rd(hw, off) enetc4_rd_reg((size_t)(hw)->port + (off))
321 : : #define enetc4_port_wr(hw, off, val) \
322 : : enetc4_wr_reg((size_t)(hw)->port + (off), val)
323 : : /* BDR register accessors, see ENETC_BDR() */
324 : : #define enetc4_bdr_rd(hw, t, n, off) \
325 : : enetc4_rd(hw, ENETC_BDR(t, n, off))
326 : : #define enetc4_bdr_wr(hw, t, n, off, val) \
327 : : enetc4_wr(hw, ENETC_BDR(t, n, off), val)
328 : : #define enetc4_txbdr_rd(hw, n, off) enetc4_bdr_rd(hw, TX, n, off)
329 : : #define enetc4_rxbdr_rd(hw, n, off) enetc4_bdr_rd(hw, RX, n, off)
330 : : #define enetc4_txbdr_wr(hw, n, off, val) \
331 : : enetc4_bdr_wr(hw, TX, n, off, val)
332 : : #define enetc4_rxbdr_wr(hw, n, off, val) \
333 : : enetc4_bdr_wr(hw, RX, n, off, val)
334 : : #endif
|