xref: /linux/drivers/net/ethernet/freescale/dpaa2/dpmac.h (revision 06ed6aa56ffac9241e03a24649e8d048f8f1b10c)
1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3  * Copyright 2019 NXP
4  */
5 #ifndef __FSL_DPMAC_H
6 #define __FSL_DPMAC_H
7 
8 /* Data Path MAC API
9  * Contains initialization APIs and runtime control APIs for DPMAC
10  */
11 
12 struct fsl_mc_io;
13 
14 int dpmac_open(struct fsl_mc_io *mc_io,
15 	       u32 cmd_flags,
16 	       int dpmac_id,
17 	       u16 *token);
18 
19 int dpmac_close(struct fsl_mc_io *mc_io,
20 		u32 cmd_flags,
21 		u16 token);
22 
23 /**
24  * enum dpmac_link_type -  DPMAC link type
25  * @DPMAC_LINK_TYPE_NONE: No link
26  * @DPMAC_LINK_TYPE_FIXED: Link is fixed type
27  * @DPMAC_LINK_TYPE_PHY: Link by PHY ID
28  * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type
29  */
30 enum dpmac_link_type {
31 	DPMAC_LINK_TYPE_NONE,
32 	DPMAC_LINK_TYPE_FIXED,
33 	DPMAC_LINK_TYPE_PHY,
34 	DPMAC_LINK_TYPE_BACKPLANE
35 };
36 
37 /**
38  * enum dpmac_eth_if - DPMAC Ethrnet interface
39  * @DPMAC_ETH_IF_MII: MII interface
40  * @DPMAC_ETH_IF_RMII: RMII interface
41  * @DPMAC_ETH_IF_SMII: SMII interface
42  * @DPMAC_ETH_IF_GMII: GMII interface
43  * @DPMAC_ETH_IF_RGMII: RGMII interface
44  * @DPMAC_ETH_IF_SGMII: SGMII interface
45  * @DPMAC_ETH_IF_QSGMII: QSGMII interface
46  * @DPMAC_ETH_IF_XAUI: XAUI interface
47  * @DPMAC_ETH_IF_XFI: XFI interface
48  * @DPMAC_ETH_IF_CAUI: CAUI interface
49  * @DPMAC_ETH_IF_1000BASEX: 1000BASEX interface
50  * @DPMAC_ETH_IF_USXGMII: USXGMII interface
51  */
52 enum dpmac_eth_if {
53 	DPMAC_ETH_IF_MII,
54 	DPMAC_ETH_IF_RMII,
55 	DPMAC_ETH_IF_SMII,
56 	DPMAC_ETH_IF_GMII,
57 	DPMAC_ETH_IF_RGMII,
58 	DPMAC_ETH_IF_SGMII,
59 	DPMAC_ETH_IF_QSGMII,
60 	DPMAC_ETH_IF_XAUI,
61 	DPMAC_ETH_IF_XFI,
62 	DPMAC_ETH_IF_CAUI,
63 	DPMAC_ETH_IF_1000BASEX,
64 	DPMAC_ETH_IF_USXGMII,
65 };
66 
67 /**
68  * struct dpmac_attr - Structure representing DPMAC attributes
69  * @id:		DPMAC object ID
70  * @max_rate:	Maximum supported rate - in Mbps
71  * @eth_if:	Ethernet interface
72  * @link_type:	link type
73  */
74 struct dpmac_attr {
75 	u16 id;
76 	u32 max_rate;
77 	enum dpmac_eth_if eth_if;
78 	enum dpmac_link_type link_type;
79 };
80 
81 int dpmac_get_attributes(struct fsl_mc_io *mc_io,
82 			 u32 cmd_flags,
83 			 u16 token,
84 			 struct dpmac_attr *attr);
85 
86 /**
87  * DPMAC link configuration/state options
88  */
89 
90 /**
91  * Enable auto-negotiation
92  */
93 #define DPMAC_LINK_OPT_AUTONEG			BIT_ULL(0)
94 /**
95  * Enable half-duplex mode
96  */
97 #define DPMAC_LINK_OPT_HALF_DUPLEX		BIT_ULL(1)
98 /**
99  * Enable pause frames
100  */
101 #define DPMAC_LINK_OPT_PAUSE			BIT_ULL(2)
102 /**
103  * Enable a-symmetric pause frames
104  */
105 #define DPMAC_LINK_OPT_ASYM_PAUSE		BIT_ULL(3)
106 
107 /**
108  * Advertised link speeds
109  */
110 #define DPMAC_ADVERTISED_10BASET_FULL		BIT_ULL(0)
111 #define DPMAC_ADVERTISED_100BASET_FULL		BIT_ULL(1)
112 #define DPMAC_ADVERTISED_1000BASET_FULL		BIT_ULL(2)
113 #define DPMAC_ADVERTISED_10000BASET_FULL	BIT_ULL(4)
114 #define DPMAC_ADVERTISED_2500BASEX_FULL		BIT_ULL(5)
115 
116 /**
117  * Advertise auto-negotiation enable
118  */
119 #define DPMAC_ADVERTISED_AUTONEG		BIT_ULL(3)
120 
121 /**
122  * struct dpmac_link_state - DPMAC link configuration request
123  * @rate: Rate in Mbps
124  * @options: Enable/Disable DPMAC link cfg features (bitmap)
125  * @up: Link state
126  * @state_valid: Ignore/Update the state of the link
127  * @supported: Speeds capability of the phy (bitmap)
128  * @advertising: Speeds that are advertised for autoneg (bitmap)
129  */
130 struct dpmac_link_state {
131 	u32 rate;
132 	u64 options;
133 	int up;
134 	int state_valid;
135 	u64 supported;
136 	u64 advertising;
137 };
138 
139 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
140 			 u32 cmd_flags,
141 			 u16 token,
142 			 struct dpmac_link_state *link_state);
143 
144 /**
145  * enum dpmac_counter_id - DPMAC counter types
146  *
147  * @DPMAC_CNT_ING_FRAME_64: counts 64-bytes frames, good or bad.
148  * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-bytes frames, good or bad.
149  * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-bytes frames, good or bad.
150  * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-bytes frames, good or bad.
151  * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-bytes frames, good or bad.
152  * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-bytes frames, good or bad.
153  * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-bytes frames and larger
154  *				  (up to max frame length specified),
155  *				  good or bad.
156  * @DPMAC_CNT_ING_FRAG: counts frames which are shorter than 64 bytes received
157  *			with a wrong CRC
158  * @DPMAC_CNT_ING_JABBER: counts frames longer than the maximum frame length
159  *			  specified, with a bad frame check sequence.
160  * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped frames due to internal errors.
161  *				 Occurs when a receive FIFO overflows.
162  *				 Includes also frames truncated as a result of
163  *				 the receive FIFO overflow.
164  * @DPMAC_CNT_ING_ALIGN_ERR: counts frames with an alignment error
165  *			     (optional used for wrong SFD).
166  * @DPMAC_CNT_EGR_UNDERSIZED: counts frames transmitted that was less than 64
167  *			      bytes long with a good CRC.
168  * @DPMAC_CNT_ING_OVERSIZED: counts frames longer than the maximum frame length
169  *			     specified, with a good frame check sequence.
170  * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frames (regular and PFC)
171  * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frames transmitted
172  *				     (regular and PFC).
173  * @DPMAC_CNT_ING_BYTE: counts bytes received except preamble for all valid
174  *			frames and valid pause frames.
175  * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frames.
176  * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frames.
177  * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad frames received.
178  * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frames.
179  * @DPMAC_CNT_ING_ERR_FRAME: counts frames received with an error
180  *			     (except for undersized/fragment frame).
181  * @DPMAC_CNT_EGR_BYTE: counts bytes transmitted except preamble for all valid
182  *			frames and valid pause frames transmitted.
183  * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frames.
184  * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frames.
185  * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frames.
186  * @DPMAC_CNT_EGR_ERR_FRAME: counts frames transmitted with an error.
187  * @DPMAC_CNT_ING_GOOD_FRAME: counts frames received without error, including
188  *			      pause frames.
189  * @DPMAC_CNT_EGR_GOOD_FRAME: counts frames transmitted without error, including
190  *			      pause frames.
191  */
192 enum dpmac_counter_id {
193 	DPMAC_CNT_ING_FRAME_64,
194 	DPMAC_CNT_ING_FRAME_127,
195 	DPMAC_CNT_ING_FRAME_255,
196 	DPMAC_CNT_ING_FRAME_511,
197 	DPMAC_CNT_ING_FRAME_1023,
198 	DPMAC_CNT_ING_FRAME_1518,
199 	DPMAC_CNT_ING_FRAME_1519_MAX,
200 	DPMAC_CNT_ING_FRAG,
201 	DPMAC_CNT_ING_JABBER,
202 	DPMAC_CNT_ING_FRAME_DISCARD,
203 	DPMAC_CNT_ING_ALIGN_ERR,
204 	DPMAC_CNT_EGR_UNDERSIZED,
205 	DPMAC_CNT_ING_OVERSIZED,
206 	DPMAC_CNT_ING_VALID_PAUSE_FRAME,
207 	DPMAC_CNT_EGR_VALID_PAUSE_FRAME,
208 	DPMAC_CNT_ING_BYTE,
209 	DPMAC_CNT_ING_MCAST_FRAME,
210 	DPMAC_CNT_ING_BCAST_FRAME,
211 	DPMAC_CNT_ING_ALL_FRAME,
212 	DPMAC_CNT_ING_UCAST_FRAME,
213 	DPMAC_CNT_ING_ERR_FRAME,
214 	DPMAC_CNT_EGR_BYTE,
215 	DPMAC_CNT_EGR_MCAST_FRAME,
216 	DPMAC_CNT_EGR_BCAST_FRAME,
217 	DPMAC_CNT_EGR_UCAST_FRAME,
218 	DPMAC_CNT_EGR_ERR_FRAME,
219 	DPMAC_CNT_ING_GOOD_FRAME,
220 	DPMAC_CNT_EGR_GOOD_FRAME
221 };
222 
223 int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
224 		      enum dpmac_counter_id id, u64 *value);
225 
226 #endif /* __FSL_DPMAC_H */
227