2 * Freescale Layerscape MC I/O wrapper
4 * Copyright (C) 2015 Freescale Semiconductor, Inc.
5 * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
7 * SPDX-License-Identifier: GPL-2.0+
14 #define DPMAC_VER_MAJOR 3
15 #define DPMAC_VER_MINOR 2
18 #define DPMAC_CMDID_CLOSE 0x800
19 #define DPMAC_CMDID_OPEN 0x80c
20 #define DPMAC_CMDID_CREATE 0x90c
21 #define DPMAC_CMDID_DESTROY 0x900
23 #define DPMAC_CMDID_GET_ATTR 0x004
24 #define DPMAC_CMDID_RESET 0x005
26 #define DPMAC_CMDID_MDIO_READ 0x0c0
27 #define DPMAC_CMDID_MDIO_WRITE 0x0c1
28 #define DPMAC_CMDID_GET_LINK_CFG 0x0c2
29 #define DPMAC_CMDID_SET_LINK_STATE 0x0c3
30 #define DPMAC_CMDID_GET_COUNTER 0x0c4
32 /* cmd, param, offset, width, type, arg_name */
33 #define DPMAC_CMD_CREATE(cmd, cfg) \
34 MC_CMD_OP(cmd, 0, 0, 32, int, cfg->mac_id)
36 /* cmd, param, offset, width, type, arg_name */
37 #define DPMAC_CMD_OPEN(cmd, dpmac_id) \
38 MC_CMD_OP(cmd, 0, 0, 32, int, dpmac_id)
40 /* cmd, param, offset, width, type, arg_name */
41 #define DPMAC_RSP_GET_ATTRIBUTES(cmd, attr) \
43 MC_RSP_OP(cmd, 0, 0, 32, int, attr->phy_id);\
44 MC_RSP_OP(cmd, 0, 32, 32, int, attr->id);\
45 MC_RSP_OP(cmd, 1, 0, 16, uint16_t, attr->version.major);\
46 MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
47 MC_RSP_OP(cmd, 1, 32, 8, enum dpmac_link_type, attr->link_type);\
48 MC_RSP_OP(cmd, 1, 40, 8, enum dpmac_eth_if, attr->eth_if);\
49 MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->max_rate);\
52 /* cmd, param, offset, width, type, arg_name */
53 #define DPMAC_CMD_MDIO_READ(cmd, cfg) \
55 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
56 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
59 /* cmd, param, offset, width, type, arg_name */
60 #define DPMAC_RSP_MDIO_READ(cmd, data) \
61 MC_RSP_OP(cmd, 0, 16, 16, uint16_t, data)
63 /* cmd, param, offset, width, type, arg_name */
64 #define DPMAC_CMD_MDIO_WRITE(cmd, cfg) \
66 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \
67 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \
68 MC_CMD_OP(cmd, 0, 16, 16, uint16_t, cfg->data); \
71 /* cmd, param, offset, width, type, arg_name */
72 #define DPMAC_RSP_GET_LINK_CFG(cmd, cfg) \
74 MC_RSP_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
75 MC_RSP_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
78 /* cmd, param, offset, width, type, arg_name */
79 #define DPMAC_CMD_SET_LINK_STATE(cmd, cfg) \
81 MC_CMD_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
82 MC_CMD_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
83 MC_CMD_OP(cmd, 2, 0, 1, int, cfg->up); \
86 /* cmd, param, offset, width, type, arg_name */
87 #define DPMAC_CMD_GET_COUNTER(cmd, type) \
88 MC_CMD_OP(cmd, 0, 0, 8, enum dpmac_counter, type)
90 /* cmd, param, offset, width, type, arg_name */
91 #define DPMAC_RSP_GET_COUNTER(cmd, counter) \
92 MC_RSP_OP(cmd, 1, 0, 64, uint64_t, counter)
95 * Contains initialization APIs and runtime control APIs for DPMAC
101 * dpmac_open() - Open a control session for the specified object.
102 * @mc_io: Pointer to MC portal's I/O object
103 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
104 * @dpmac_id: DPMAC unique ID
105 * @token: Returned token; use in subsequent API calls
107 * This function can be used to open a control session for an
108 * already created object; an object may have been declared in
109 * the DPL or by calling the dpmac_create function.
110 * This function returns a unique authentication token,
111 * associated with the specific object ID and the specific MC
112 * portal; this token must be used in all subsequent commands for
113 * this specific object
115 * Return: '0' on Success; Error code otherwise.
117 int dpmac_open(struct fsl_mc_io *mc_io,
123 * dpmac_close() - Close the control session of the object
124 * @mc_io: Pointer to MC portal's I/O object
125 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
126 * @token: Token of DPMAC object
128 * After this function is called, no further operations are
129 * allowed on the object without opening a new control session.
131 * Return: '0' on Success; Error code otherwise.
133 int dpmac_close(struct fsl_mc_io *mc_io,
138 * enum dpmac_link_type - DPMAC link type
139 * @DPMAC_LINK_TYPE_NONE: No link
140 * @DPMAC_LINK_TYPE_FIXED: Link is fixed type
141 * @DPMAC_LINK_TYPE_PHY: Link by PHY ID
142 * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type
144 enum dpmac_link_type {
145 DPMAC_LINK_TYPE_NONE,
146 DPMAC_LINK_TYPE_FIXED,
148 DPMAC_LINK_TYPE_BACKPLANE
152 * enum dpmac_eth_if - DPMAC Ethrnet interface
153 * @DPMAC_ETH_IF_MII: MII interface
154 * @DPMAC_ETH_IF_RMII: RMII interface
155 * @DPMAC_ETH_IF_SMII: SMII interface
156 * @DPMAC_ETH_IF_GMII: GMII interface
157 * @DPMAC_ETH_IF_RGMII: RGMII interface
158 * @DPMAC_ETH_IF_SGMII: SGMII interface
159 * @DPMAC_ETH_IF_QSGMII: QSGMII interface
160 * @DPMAC_ETH_IF_XAUI: XAUI interface
161 * @DPMAC_ETH_IF_XFI: XFI interface
176 * struct dpmac_cfg - Structure representing DPMAC configuration
177 * @mac_id: Represents the Hardware MAC ID; in case of multiple WRIOP,
178 * the MAC IDs are continuous.
179 * For example: 2 WRIOPs, 16 MACs in each:
180 * MAC IDs for the 1st WRIOP: 1-16,
181 * MAC IDs for the 2nd WRIOP: 17-32.
188 * dpmac_create() - Create the DPMAC object.
189 * @mc_io: Pointer to MC portal's I/O object
190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
191 * @cfg: Configuration structure
192 * @token: Returned token; use in subsequent API calls
194 * Create the DPMAC object, allocate required resources and
195 * perform required initialization.
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
206 * Return: '0' on Success; Error code otherwise.
208 int dpmac_create(struct fsl_mc_io *mc_io,
210 const struct dpmac_cfg *cfg,
214 * dpmac_destroy() - Destroy the DPMAC object and release all its resources.
215 * @mc_io: Pointer to MC portal's I/O object
216 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
217 * @token: Token of DPMAC object
219 * Return: '0' on Success; error code otherwise.
221 int dpmac_destroy(struct fsl_mc_io *mc_io,
225 /* DPMAC IRQ Index and Events */
228 #define DPMAC_IRQ_INDEX 0
229 /* IRQ event - indicates a change in link state */
230 #define DPMAC_IRQ_EVENT_LINK_CFG_REQ 0x00000001
231 /* irq event - Indicates that the link state changed */
232 #define DPMAC_IRQ_EVENT_LINK_CHANGED 0x00000002
235 * struct dpmac_attr - Structure representing DPMAC attributes
236 * @id: DPMAC object ID
238 * @link_type: link type
239 * @eth_if: Ethernet interface
240 * @max_rate: Maximum supported rate - in Mbps
241 * @version: DPMAC version
246 enum dpmac_link_type link_type;
247 enum dpmac_eth_if eth_if;
250 * struct version - Structure representing DPMAC version
251 * @major: DPMAC major version
252 * @minor: DPMAC minor version
261 * dpmac_get_attributes - Retrieve DPMAC attributes.
263 * @mc_io: Pointer to MC portal's I/O object
264 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
265 * @token: Token of DPMAC object
266 * @attr: Returned object's attributes
268 * Return: '0' on Success; Error code otherwise.
270 int dpmac_get_attributes(struct fsl_mc_io *mc_io,
273 struct dpmac_attr *attr);
276 * struct dpmac_mdio_cfg - DPMAC MDIO read/write parameters
277 * @phy_addr: MDIO device address
278 * @reg: Address of the register within the Clause 45 PHY device from which data
280 * @data: Data read/write from/to MDIO
282 struct dpmac_mdio_cfg {
289 * dpmac_mdio_read() - Perform MDIO read transaction
290 * @mc_io: Pointer to opaque I/O object
291 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
292 * @token: Token of DPMAC object
293 * @cfg: Structure with MDIO transaction parameters
295 * Return: '0' on Success; Error code otherwise.
297 int dpmac_mdio_read(struct fsl_mc_io *mc_io,
300 struct dpmac_mdio_cfg *cfg);
303 * dpmac_mdio_write() - Perform MDIO write transaction
304 * @mc_io: Pointer to opaque I/O object
305 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
306 * @token: Token of DPMAC object
307 * @cfg: Structure with MDIO transaction parameters
309 * Return: '0' on Success; Error code otherwise.
311 int dpmac_mdio_write(struct fsl_mc_io *mc_io,
314 struct dpmac_mdio_cfg *cfg);
316 /* DPMAC link configuration/state options */
318 /* Enable auto-negotiation */
319 #define DPMAC_LINK_OPT_AUTONEG 0x0000000000000001ULL
320 /* Enable half-duplex mode */
321 #define DPMAC_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
322 /* Enable pause frames */
323 #define DPMAC_LINK_OPT_PAUSE 0x0000000000000004ULL
324 /* Enable a-symmetric pause frames */
325 #define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
328 * struct dpmac_link_cfg - Structure representing DPMAC link configuration
329 * @rate: Link's rate - in Mbps
330 * @options: Enable/Disable DPMAC link cfg features (bitmap)
332 struct dpmac_link_cfg {
338 * dpmac_get_link_cfg() - Get Ethernet link configuration
339 * @mc_io: Pointer to opaque I/O object
340 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
341 * @token: Token of DPMAC object
342 * @cfg: Returned structure with the link configuration
344 * Return: '0' on Success; Error code otherwise.
346 int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
349 struct dpmac_link_cfg *cfg);
352 * struct dpmac_link_state - DPMAC link configuration request
353 * @rate: Rate in Mbps
354 * @options: Enable/Disable DPMAC link cfg features (bitmap)
357 struct dpmac_link_state {
364 * dpmac_set_link_state() - Set the Ethernet link status
365 * @mc_io: Pointer to opaque I/O object
366 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
367 * @token: Token of DPMAC object
368 * @link_state: Link state configuration
370 * Return: '0' on Success; Error code otherwise.
372 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
375 struct dpmac_link_state *link_state);
378 * enum dpni_counter - DPNI counter types
379 * @DPMAC_CNT_ING_FRAME_64: counts 64-octet frame, good or bad.
380 * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-octet frame, good or bad.
381 * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-octet frame, good or bad.
382 * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-octet frame, good or bad.
383 * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-octet frame, good or bad.
384 * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-octet frame, good or bad.
385 * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-octet frame and larger
386 * (up to max frame length specified),
388 * @DPMAC_CNT_ING_FRAG: counts packet which is shorter than 64 octets received
390 * @DPMAC_CNT_ING_JABBER: counts packet longer than the maximum frame length
391 * specified, with a bad frame check sequence.
392 * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped packet due to internal errors.
393 * Occurs when a receive FIFO overflows.
394 * Includes also packets truncated as a result of
395 * the receive FIFO overflow.
396 * @DPMAC_CNT_ING_ALIGN_ERR: counts frame with an alignment error
397 * (optional used for wrong SFD)
398 * @DPMAC_CNT_EGR_UNDERSIZED: counts packet transmitted that was less than 64
399 * octets long with a good CRC.
400 * @DPMAC_CNT_ING_OVERSIZED: counts packet longer than the maximum frame length
401 * specified, with a good frame check sequence.
402 * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frame (regular and PFC).
403 * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frame transmitted
405 * @DPMAC_CNT_ING_BYTE: counts octet received except preamble for all valid
406 * frames and valid pause frames.
407 * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frame
408 * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frame
409 * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad packet received.
410 * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frame
411 * @DPMAC_CNT_ING_ERR_FRAME: counts frame received with an error
412 * (except for undersized/fragment frame)
413 * @DPMAC_CNT_EGR_BYTE: counts octet transmitted except preamble for all valid
414 * frames and valid pause frames transmitted.
415 * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frame
416 * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frame
417 * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frame
418 * @DPMAC_CNT_EGR_ERR_FRAME: counts frame transmitted with an error
419 * @DPMAC_CNT_ING_GOOD_FRAME: counts frame received without error, including
423 DPMAC_CNT_ING_FRAME_64,
424 DPMAC_CNT_ING_FRAME_127,
425 DPMAC_CNT_ING_FRAME_255,
426 DPMAC_CNT_ING_FRAME_511,
427 DPMAC_CNT_ING_FRAME_1023,
428 DPMAC_CNT_ING_FRAME_1518,
429 DPMAC_CNT_ING_FRAME_1519_MAX,
431 DPMAC_CNT_ING_JABBER,
432 DPMAC_CNT_ING_FRAME_DISCARD,
433 DPMAC_CNT_ING_ALIGN_ERR,
434 DPMAC_CNT_EGR_UNDERSIZED,
435 DPMAC_CNT_ING_OVERSIZED,
436 DPMAC_CNT_ING_VALID_PAUSE_FRAME,
437 DPMAC_CNT_EGR_VALID_PAUSE_FRAME,
439 DPMAC_CNT_ING_MCAST_FRAME,
440 DPMAC_CNT_ING_BCAST_FRAME,
441 DPMAC_CNT_ING_ALL_FRAME,
442 DPMAC_CNT_ING_UCAST_FRAME,
443 DPMAC_CNT_ING_ERR_FRAME,
445 DPMAC_CNT_EGR_MCAST_FRAME,
446 DPMAC_CNT_EGR_BCAST_FRAME,
447 DPMAC_CNT_EGR_UCAST_FRAME,
448 DPMAC_CNT_EGR_ERR_FRAME,
449 DPMAC_CNT_ING_GOOD_FRAME
453 * dpmac_get_counter() - Read a specific DPMAC counter
454 * @mc_io: Pointer to opaque I/O object
455 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
456 * @token: Token of DPMAC object
457 * @type: The requested counter
458 * @counter: Returned counter value
460 * Return: The requested counter; '0' otherwise.
462 int dpmac_get_counter(struct fsl_mc_io *mc_io,
465 enum dpmac_counter type,
468 #endif /* __FSL_DPMAC_H */