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