]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/fsl-mc/fsl_dpmac.h
arm: fsl-layerscape: add 0x3040 serdes1 settings for LS1046A
[thirdparty/u-boot.git] / include / fsl-mc / fsl_dpmac.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
872d48a7
PK
2/*
3 * Freescale Layerscape MC I/O wrapper
4 *
a6f2a6ea 5 * Copyright 2015-2016 Freescale Semiconductor, Inc.
2557c5a9 6 * Copyright 2017 NXP
872d48a7 7 * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
872d48a7
PK
8 */
9
10#ifndef __FSL_DPMAC_H
11#define __FSL_DPMAC_H
12
13/* DPMAC Version */
2557c5a9 14#define DPMAC_VER_MAJOR 4
53e353fc 15#define DPMAC_VER_MINOR 2
872d48a7
PK
16
17/* Command IDs */
2557c5a9
YG
18#define DPMAC_CMDID_CLOSE 0x8001
19#define DPMAC_CMDID_OPEN 0x80c1
20#define DPMAC_CMDID_CREATE 0x90c1
21#define DPMAC_CMDID_DESTROY 0x98c1
22#define DPMAC_CMDID_GET_API_VERSION 0xa0c1
872d48a7 23
2557c5a9
YG
24#define DPMAC_CMDID_GET_ATTR 0x0041
25#define DPMAC_CMDID_RESET 0x0051
872d48a7 26
2557c5a9
YG
27#define DPMAC_CMDID_MDIO_READ 0x0c01
28#define DPMAC_CMDID_MDIO_WRITE 0x0c11
29#define DPMAC_CMDID_GET_LINK_CFG 0x0c21
30#define DPMAC_CMDID_SET_LINK_STATE 0x0c31
31#define DPMAC_CMDID_GET_COUNTER 0x0c41
872d48a7
PK
32
33/* cmd, param, offset, width, type, arg_name */
34#define DPMAC_CMD_CREATE(cmd, cfg) \
2557c5a9 35 MC_CMD_OP(cmd, 0, 0, 16, uint16_t, cfg->mac_id)
872d48a7
PK
36
37/* cmd, param, offset, width, type, arg_name */
38#define DPMAC_CMD_OPEN(cmd, dpmac_id) \
39 MC_CMD_OP(cmd, 0, 0, 32, int, dpmac_id)
40
41/* cmd, param, offset, width, type, arg_name */
42#define DPMAC_RSP_GET_ATTRIBUTES(cmd, attr) \
43do { \
44 MC_RSP_OP(cmd, 0, 0, 32, int, attr->phy_id);\
45 MC_RSP_OP(cmd, 0, 32, 32, int, attr->id);\
872d48a7
PK
46 MC_RSP_OP(cmd, 1, 32, 8, enum dpmac_link_type, attr->link_type);\
47 MC_RSP_OP(cmd, 1, 40, 8, enum dpmac_eth_if, attr->eth_if);\
48 MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->max_rate);\
49} while (0)
50
51/* cmd, param, offset, width, type, arg_name */
52#define DPMAC_CMD_MDIO_READ(cmd, cfg) \
53do { \
54 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
55 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
56} while (0)
57
58/* cmd, param, offset, width, type, arg_name */
59#define DPMAC_RSP_MDIO_READ(cmd, data) \
60 MC_RSP_OP(cmd, 0, 16, 16, uint16_t, data)
61
62/* cmd, param, offset, width, type, arg_name */
63#define DPMAC_CMD_MDIO_WRITE(cmd, cfg) \
64do { \
65 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
66 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
67 MC_CMD_OP(cmd, 0, 16, 16, uint16_t, cfg->data); \
68} while (0)
69
70/* cmd, param, offset, width, type, arg_name */
71#define DPMAC_RSP_GET_LINK_CFG(cmd, cfg) \
72do { \
73 MC_RSP_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
74 MC_RSP_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
75} while (0)
76
77/* cmd, param, offset, width, type, arg_name */
78#define DPMAC_CMD_SET_LINK_STATE(cmd, cfg) \
79do { \
80 MC_CMD_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
81 MC_CMD_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
82 MC_CMD_OP(cmd, 2, 0, 1, int, cfg->up); \
83} while (0)
84
85/* cmd, param, offset, width, type, arg_name */
86#define DPMAC_CMD_GET_COUNTER(cmd, type) \
2557c5a9 87 MC_CMD_OP(cmd, 1, 0, 64, enum dpmac_counter, type)
872d48a7
PK
88
89/* cmd, param, offset, width, type, arg_name */
90#define DPMAC_RSP_GET_COUNTER(cmd, counter) \
91 MC_RSP_OP(cmd, 1, 0, 64, uint64_t, counter)
92
93/* Data Path MAC API
94 * Contains initialization APIs and runtime control APIs for DPMAC
95 */
96
97struct fsl_mc_io;
98
99/**
100 * dpmac_open() - Open a control session for the specified object.
101 * @mc_io: Pointer to MC portal's I/O object
102 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
103 * @dpmac_id: DPMAC unique ID
104 * @token: Returned token; use in subsequent API calls
105 *
106 * This function can be used to open a control session for an
107 * already created object; an object may have been declared in
108 * the DPL or by calling the dpmac_create function.
109 * This function returns a unique authentication token,
110 * associated with the specific object ID and the specific MC
111 * portal; this token must be used in all subsequent commands for
112 * this specific object
113 *
114 * Return: '0' on Success; Error code otherwise.
115 */
116int dpmac_open(struct fsl_mc_io *mc_io,
117 uint32_t cmd_flags,
118 int dpmac_id,
119 uint16_t *token);
120
121/**
122 * dpmac_close() - Close the control session of the object
123 * @mc_io: Pointer to MC portal's I/O object
124 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
125 * @token: Token of DPMAC object
126 *
127 * After this function is called, no further operations are
128 * allowed on the object without opening a new control session.
129 *
130 * Return: '0' on Success; Error code otherwise.
131 */
132int dpmac_close(struct fsl_mc_io *mc_io,
133 uint32_t cmd_flags,
134 uint16_t token);
135
136/**
137 * enum dpmac_link_type - DPMAC link type
138 * @DPMAC_LINK_TYPE_NONE: No link
139 * @DPMAC_LINK_TYPE_FIXED: Link is fixed type
140 * @DPMAC_LINK_TYPE_PHY: Link by PHY ID
141 * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type
142 */
143enum dpmac_link_type {
144 DPMAC_LINK_TYPE_NONE,
145 DPMAC_LINK_TYPE_FIXED,
146 DPMAC_LINK_TYPE_PHY,
147 DPMAC_LINK_TYPE_BACKPLANE
148};
149
150/**
151 * enum dpmac_eth_if - DPMAC Ethrnet interface
152 * @DPMAC_ETH_IF_MII: MII interface
153 * @DPMAC_ETH_IF_RMII: RMII interface
154 * @DPMAC_ETH_IF_SMII: SMII interface
155 * @DPMAC_ETH_IF_GMII: GMII interface
156 * @DPMAC_ETH_IF_RGMII: RGMII interface
157 * @DPMAC_ETH_IF_SGMII: SGMII interface
158 * @DPMAC_ETH_IF_QSGMII: QSGMII interface
159 * @DPMAC_ETH_IF_XAUI: XAUI interface
160 * @DPMAC_ETH_IF_XFI: XFI interface
161 */
162enum dpmac_eth_if {
163 DPMAC_ETH_IF_MII,
164 DPMAC_ETH_IF_RMII,
165 DPMAC_ETH_IF_SMII,
166 DPMAC_ETH_IF_GMII,
167 DPMAC_ETH_IF_RGMII,
168 DPMAC_ETH_IF_SGMII,
169 DPMAC_ETH_IF_QSGMII,
170 DPMAC_ETH_IF_XAUI,
171 DPMAC_ETH_IF_XFI
172};
173
174/**
175 * struct dpmac_cfg - Structure representing DPMAC configuration
176 * @mac_id: Represents the Hardware MAC ID; in case of multiple WRIOP,
177 * the MAC IDs are continuous.
178 * For example: 2 WRIOPs, 16 MACs in each:
179 * MAC IDs for the 1st WRIOP: 1-16,
180 * MAC IDs for the 2nd WRIOP: 17-32.
181 */
182struct dpmac_cfg {
183 int mac_id;
184};
185
186/**
187 * dpmac_create() - Create the DPMAC object.
188 * @mc_io: Pointer to MC portal's I/O object
2557c5a9 189 * @token: Authentication token.
872d48a7
PK
190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
191 * @cfg: Configuration structure
2557c5a9 192 * @obj_id: Returned obj_id; use in subsequent API calls
872d48a7
PK
193 *
194 * Create the DPMAC object, allocate required resources and
195 * perform required initialization.
196 *
197 * The object can be created either by declaring it in the
198 * DPL file, or by calling this function.
199 * This function returns a unique authentication token,
200 * associated with the specific object ID and the specific MC
201 * portal; this token must be used in all subsequent calls to
202 * this specific object. For objects that are created using the
203 * DPL file, call dpmac_open function to get an authentication
204 * token first.
205 *
206 * Return: '0' on Success; Error code otherwise.
207 */
208int dpmac_create(struct fsl_mc_io *mc_io,
2557c5a9 209 uint16_t token,
872d48a7
PK
210 uint32_t cmd_flags,
211 const struct dpmac_cfg *cfg,
2557c5a9 212 uint32_t *obj_id);
872d48a7
PK
213
214/**
215 * dpmac_destroy() - Destroy the DPMAC object and release all its resources.
216 * @mc_io: Pointer to MC portal's I/O object
2557c5a9 217 * @token: Authentication token.
872d48a7 218 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2557c5a9 219 * @obj_id: DPMAC object id
872d48a7
PK
220 *
221 * Return: '0' on Success; error code otherwise.
222 */
223int dpmac_destroy(struct fsl_mc_io *mc_io,
2557c5a9 224 uint16_t token,
872d48a7 225 uint32_t cmd_flags,
2557c5a9 226 uint32_t obj_id);
872d48a7
PK
227
228/* DPMAC IRQ Index and Events */
229
230/* IRQ index */
231#define DPMAC_IRQ_INDEX 0
232/* IRQ event - indicates a change in link state */
233#define DPMAC_IRQ_EVENT_LINK_CFG_REQ 0x00000001
234/* irq event - Indicates that the link state changed */
235#define DPMAC_IRQ_EVENT_LINK_CHANGED 0x00000002
236
237/**
238 * struct dpmac_attr - Structure representing DPMAC attributes
239 * @id: DPMAC object ID
240 * @phy_id: PHY ID
241 * @link_type: link type
242 * @eth_if: Ethernet interface
243 * @max_rate: Maximum supported rate - in Mbps
244 * @version: DPMAC version
245 */
246struct dpmac_attr {
247 int id;
248 int phy_id;
249 enum dpmac_link_type link_type;
250 enum dpmac_eth_if eth_if;
251 uint32_t max_rate;
872d48a7
PK
252};
253
254/**
255 * dpmac_get_attributes - Retrieve DPMAC attributes.
256 *
257 * @mc_io: Pointer to MC portal's I/O object
258 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
259 * @token: Token of DPMAC object
260 * @attr: Returned object's attributes
261 *
262 * Return: '0' on Success; Error code otherwise.
263 */
264int dpmac_get_attributes(struct fsl_mc_io *mc_io,
265 uint32_t cmd_flags,
266 uint16_t token,
267 struct dpmac_attr *attr);
268
269/**
270 * struct dpmac_mdio_cfg - DPMAC MDIO read/write parameters
271 * @phy_addr: MDIO device address
272 * @reg: Address of the register within the Clause 45 PHY device from which data
273 * is to be read
274 * @data: Data read/write from/to MDIO
275 */
276struct dpmac_mdio_cfg {
277 uint8_t phy_addr;
278 uint8_t reg;
279 uint16_t data;
280};
281
282/**
283 * dpmac_mdio_read() - Perform MDIO read transaction
284 * @mc_io: Pointer to opaque I/O object
285 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
286 * @token: Token of DPMAC object
287 * @cfg: Structure with MDIO transaction parameters
288 *
289 * Return: '0' on Success; Error code otherwise.
290 */
291int dpmac_mdio_read(struct fsl_mc_io *mc_io,
292 uint32_t cmd_flags,
293 uint16_t token,
294 struct dpmac_mdio_cfg *cfg);
295
296/**
297 * dpmac_mdio_write() - Perform MDIO write transaction
298 * @mc_io: Pointer to opaque I/O object
299 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
300 * @token: Token of DPMAC object
301 * @cfg: Structure with MDIO transaction parameters
302 *
303 * Return: '0' on Success; Error code otherwise.
304 */
305int dpmac_mdio_write(struct fsl_mc_io *mc_io,
306 uint32_t cmd_flags,
307 uint16_t token,
308 struct dpmac_mdio_cfg *cfg);
309
310/* DPMAC link configuration/state options */
311
312/* Enable auto-negotiation */
313#define DPMAC_LINK_OPT_AUTONEG 0x0000000000000001ULL
314/* Enable half-duplex mode */
315#define DPMAC_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
316/* Enable pause frames */
317#define DPMAC_LINK_OPT_PAUSE 0x0000000000000004ULL
318/* Enable a-symmetric pause frames */
319#define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
320
321/**
322 * struct dpmac_link_cfg - Structure representing DPMAC link configuration
323 * @rate: Link's rate - in Mbps
324 * @options: Enable/Disable DPMAC link cfg features (bitmap)
325 */
326struct dpmac_link_cfg {
327 uint32_t rate;
328 uint64_t options;
329};
330
331/**
332 * dpmac_get_link_cfg() - Get Ethernet link configuration
333 * @mc_io: Pointer to opaque I/O object
334 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
335 * @token: Token of DPMAC object
336 * @cfg: Returned structure with the link configuration
337 *
338 * Return: '0' on Success; Error code otherwise.
339 */
340int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
341 uint32_t cmd_flags,
342 uint16_t token,
343 struct dpmac_link_cfg *cfg);
344
345/**
346 * struct dpmac_link_state - DPMAC link configuration request
347 * @rate: Rate in Mbps
348 * @options: Enable/Disable DPMAC link cfg features (bitmap)
349 * @up: Link state
350 */
351struct dpmac_link_state {
352 uint32_t rate;
353 uint64_t options;
354 int up;
355};
356
357/**
358 * dpmac_set_link_state() - Set the Ethernet link status
359 * @mc_io: Pointer to opaque I/O object
360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
361 * @token: Token of DPMAC object
362 * @link_state: Link state configuration
363 *
364 * Return: '0' on Success; Error code otherwise.
365 */
366int dpmac_set_link_state(struct fsl_mc_io *mc_io,
367 uint32_t cmd_flags,
368 uint16_t token,
369 struct dpmac_link_state *link_state);
370
371/**
372 * enum dpni_counter - DPNI counter types
373 * @DPMAC_CNT_ING_FRAME_64: counts 64-octet frame, good or bad.
374 * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-octet frame, good or bad.
375 * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-octet frame, good or bad.
376 * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-octet frame, good or bad.
377 * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-octet frame, good or bad.
378 * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-octet frame, good or bad.
379 * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-octet frame and larger
380 * (up to max frame length specified),
381 * good or bad.
382 * @DPMAC_CNT_ING_FRAG: counts packet which is shorter than 64 octets received
383 * with a wrong CRC
384 * @DPMAC_CNT_ING_JABBER: counts packet longer than the maximum frame length
385 * specified, with a bad frame check sequence.
386 * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped packet due to internal errors.
387 * Occurs when a receive FIFO overflows.
388 * Includes also packets truncated as a result of
389 * the receive FIFO overflow.
390 * @DPMAC_CNT_ING_ALIGN_ERR: counts frame with an alignment error
391 * (optional used for wrong SFD)
392 * @DPMAC_CNT_EGR_UNDERSIZED: counts packet transmitted that was less than 64
393 * octets long with a good CRC.
394 * @DPMAC_CNT_ING_OVERSIZED: counts packet longer than the maximum frame length
395 * specified, with a good frame check sequence.
396 * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frame (regular and PFC).
397 * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frame transmitted
398 * (regular and PFC).
399 * @DPMAC_CNT_ING_BYTE: counts octet received except preamble for all valid
400 * frames and valid pause frames.
401 * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frame
402 * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frame
403 * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad packet received.
404 * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frame
405 * @DPMAC_CNT_ING_ERR_FRAME: counts frame received with an error
406 * (except for undersized/fragment frame)
407 * @DPMAC_CNT_EGR_BYTE: counts octet transmitted except preamble for all valid
408 * frames and valid pause frames transmitted.
409 * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frame
410 * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frame
411 * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frame
412 * @DPMAC_CNT_EGR_ERR_FRAME: counts frame transmitted with an error
413 * @DPMAC_CNT_ING_GOOD_FRAME: counts frame received without error, including
414 * pause frames.
415 */
416enum dpmac_counter {
417 DPMAC_CNT_ING_FRAME_64,
418 DPMAC_CNT_ING_FRAME_127,
419 DPMAC_CNT_ING_FRAME_255,
420 DPMAC_CNT_ING_FRAME_511,
421 DPMAC_CNT_ING_FRAME_1023,
422 DPMAC_CNT_ING_FRAME_1518,
423 DPMAC_CNT_ING_FRAME_1519_MAX,
424 DPMAC_CNT_ING_FRAG,
425 DPMAC_CNT_ING_JABBER,
426 DPMAC_CNT_ING_FRAME_DISCARD,
427 DPMAC_CNT_ING_ALIGN_ERR,
428 DPMAC_CNT_EGR_UNDERSIZED,
429 DPMAC_CNT_ING_OVERSIZED,
430 DPMAC_CNT_ING_VALID_PAUSE_FRAME,
431 DPMAC_CNT_EGR_VALID_PAUSE_FRAME,
432 DPMAC_CNT_ING_BYTE,
433 DPMAC_CNT_ING_MCAST_FRAME,
434 DPMAC_CNT_ING_BCAST_FRAME,
435 DPMAC_CNT_ING_ALL_FRAME,
436 DPMAC_CNT_ING_UCAST_FRAME,
437 DPMAC_CNT_ING_ERR_FRAME,
438 DPMAC_CNT_EGR_BYTE,
439 DPMAC_CNT_EGR_MCAST_FRAME,
440 DPMAC_CNT_EGR_BCAST_FRAME,
441 DPMAC_CNT_EGR_UCAST_FRAME,
442 DPMAC_CNT_EGR_ERR_FRAME,
443 DPMAC_CNT_ING_GOOD_FRAME
444};
445
446/**
447 * dpmac_get_counter() - Read a specific DPMAC counter
448 * @mc_io: Pointer to opaque I/O object
449 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
450 * @token: Token of DPMAC object
451 * @type: The requested counter
452 * @counter: Returned counter value
453 *
454 * Return: The requested counter; '0' otherwise.
455 */
456int dpmac_get_counter(struct fsl_mc_io *mc_io,
457 uint32_t cmd_flags,
458 uint16_t token,
459 enum dpmac_counter type,
460 uint64_t *counter);
2557c5a9
YG
461/**
462 * dpmac_get_api_version - Retrieve DPMAC Major and Minor version info.
463 *
464 * @mc_io: Pointer to MC portal's I/O object
465 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
466 * @major_ver: DPMAC major version
467 * @minor_ver: DPMAC minor version
468 *
469 * Return: '0' on Success; Error code otherwise.
470 */
471int dpmac_get_api_version(struct fsl_mc_io *mc_io,
472 uint32_t cmd_flags,
473 uint16_t *major_ver,
474 uint16_t *minor_ver);
872d48a7
PK
475
476#endif /* __FSL_DPMAC_H */