1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Freescale Layerscape MC I/O wrapper
5 * Copyright 2015-2016 Freescale Semiconductor, Inc.
7 * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
14 #define DPMAC_VER_MAJOR 4
15 #define DPMAC_VER_MINOR 2
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
24 #define DPMAC_CMDID_GET_ATTR 0x0041
25 #define DPMAC_CMDID_RESET 0x0051
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
33 /* cmd, param, offset, width, type, arg_name */
34 #define DPMAC_CMD_CREATE(cmd, cfg) \
35 MC_CMD_OP(cmd, 0, 0, 16, uint16_t, cfg->mac_id)
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)
41 /* cmd, param, offset, width, type, arg_name */
42 #define DPMAC_RSP_GET_ATTRIBUTES(cmd, attr) \
44 MC_RSP_OP(cmd, 0, 0, 32, int, attr->phy_id);\
45 MC_RSP_OP(cmd, 0, 32, 32, int, attr->id);\
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);\
51 /* cmd, param, offset, width, type, arg_name */
52 #define DPMAC_CMD_MDIO_READ(cmd, cfg) \
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); \
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)
62 /* cmd, param, offset, width, type, arg_name */
63 #define DPMAC_CMD_MDIO_WRITE(cmd, cfg) \
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); \
70 /* cmd, param, offset, width, type, arg_name */
71 #define DPMAC_RSP_GET_LINK_CFG(cmd, cfg) \
73 MC_RSP_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \
74 MC_RSP_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \
77 /* cmd, param, offset, width, type, arg_name */
78 #define DPMAC_CMD_SET_LINK_STATE(cmd, cfg) \
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); \
85 /* cmd, param, offset, width, type, arg_name */
86 #define DPMAC_CMD_GET_COUNTER(cmd, type) \
87 MC_CMD_OP(cmd, 1, 0, 64, enum dpmac_counter, type)
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)
94 * Contains initialization APIs and runtime control APIs for DPMAC
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
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
114 * Return: '0' on Success; Error code otherwise.
116 int dpmac_open(struct fsl_mc_io *mc_io,
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
127 * After this function is called, no further operations are
128 * allowed on the object without opening a new control session.
130 * Return: '0' on Success; Error code otherwise.
132 int dpmac_close(struct fsl_mc_io *mc_io,
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
143 enum dpmac_link_type {
144 DPMAC_LINK_TYPE_NONE,
145 DPMAC_LINK_TYPE_FIXED,
147 DPMAC_LINK_TYPE_BACKPLANE
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
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.
187 * dpmac_create() - Create the DPMAC object.
188 * @mc_io: Pointer to MC portal's I/O object
189 * @token: Authentication token.
190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
191 * @cfg: Configuration structure
192 * @obj_id: Returned obj_id; 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,
211 const struct dpmac_cfg *cfg,
215 * dpmac_destroy() - Destroy the DPMAC object and release all its resources.
216 * @mc_io: Pointer to MC portal's I/O object
217 * @token: Authentication token.
218 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
219 * @obj_id: DPMAC object id
221 * Return: '0' on Success; error code otherwise.
223 int dpmac_destroy(struct fsl_mc_io *mc_io,
228 /* DPMAC IRQ Index and Events */
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
238 * struct dpmac_attr - Structure representing DPMAC attributes
239 * @id: DPMAC object ID
241 * @link_type: link type
242 * @eth_if: Ethernet interface
243 * @max_rate: Maximum supported rate - in Mbps
244 * @version: DPMAC version
249 enum dpmac_link_type link_type;
250 enum dpmac_eth_if eth_if;
255 * dpmac_get_attributes - Retrieve DPMAC attributes.
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
262 * Return: '0' on Success; Error code otherwise.
264 int dpmac_get_attributes(struct fsl_mc_io *mc_io,
267 struct dpmac_attr *attr);
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
274 * @data: Data read/write from/to MDIO
276 struct dpmac_mdio_cfg {
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
289 * Return: '0' on Success; Error code otherwise.
291 int dpmac_mdio_read(struct fsl_mc_io *mc_io,
294 struct dpmac_mdio_cfg *cfg);
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
303 * Return: '0' on Success; Error code otherwise.
305 int dpmac_mdio_write(struct fsl_mc_io *mc_io,
308 struct dpmac_mdio_cfg *cfg);
310 /* DPMAC link configuration/state options */
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
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)
326 struct dpmac_link_cfg {
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
338 * Return: '0' on Success; Error code otherwise.
340 int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
343 struct dpmac_link_cfg *cfg);
346 * struct dpmac_link_state - DPMAC link configuration request
347 * @rate: Rate in Mbps
348 * @options: Enable/Disable DPMAC link cfg features (bitmap)
351 struct dpmac_link_state {
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
364 * Return: '0' on Success; Error code otherwise.
366 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
369 struct dpmac_link_state *link_state);
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),
382 * @DPMAC_CNT_ING_FRAG: counts packet which is shorter than 64 octets received
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
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
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,
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,
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,
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
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
454 * Return: The requested counter; '0' otherwise.
456 int dpmac_get_counter(struct fsl_mc_io *mc_io,
459 enum dpmac_counter type,
462 * dpmac_get_api_version - Retrieve DPMAC Major and Minor version info.
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
469 * Return: '0' on Success; Error code otherwise.
471 int dpmac_get_api_version(struct fsl_mc_io *mc_io,
474 uint16_t *minor_ver);
476 #endif /* __FSL_DPMAC_H */