xref: /openbmc/u-boot/include/fsl-mc/fsl_dpni.h (revision cbd2fba1)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2013-2016 Freescale Semiconductor, Inc.
4  * Copyright 2017 NXP
5  */
6 #ifndef _FSL_DPNI_H
7 #define _FSL_DPNI_H
8 
9 /* DPNI Version */
10 #define DPNI_VER_MAJOR				7
11 #define DPNI_VER_MINOR				3
12 
13 /* Command IDs */
14 #define DPNI_CMDID_OPEN				0x8011
15 #define DPNI_CMDID_CLOSE			0x8001
16 #define DPNI_CMDID_CREATE			0x9011
17 #define DPNI_CMDID_DESTROY			0x9811
18 #define DPNI_CMDID_GET_API_VERSION              0xa011
19 
20 #define DPNI_CMDID_ENABLE			0x0021
21 #define DPNI_CMDID_DISABLE			0x0031
22 #define DPNI_CMDID_GET_ATTR			0x0041
23 #define DPNI_CMDID_RESET			0x0051
24 
25 #define DPNI_CMDID_SET_POOLS			0x2002
26 #define DPNI_CMDID_SET_BUFFER_LAYOUT		0x2651
27 #define DPNI_CMDID_GET_BUFFER_LAYOUT		0x2641
28 #define DPNI_CMDID_SET_ERRORS_BEHAVIOR		0x20B1
29 
30 #define DPNI_CMDID_GET_QDID			0x2101
31 #define DPNI_CMDID_GET_TX_DATA_OFFSET		0x2121
32 #define DPNI_CMDID_GET_LINK_STATE		0x2151
33 #define DPNI_CMDID_SET_LINK_CFG			0x21A1
34 
35 #define DPNI_CMDID_SET_PRIM_MAC			0x2241
36 #define DPNI_CMDID_GET_PRIM_MAC			0x2251
37 #define DPNI_CMDID_ADD_MAC_ADDR			0x2261
38 #define DPNI_CMDID_REMOVE_MAC_ADDR		0x2271
39 
40 #define DPNI_CMDID_GET_STATISTICS		0x25D1
41 #define DPNI_CMDID_RESET_STATISTICS		0x25E1
42 #define DPNI_CMDID_GET_QUEUE			0x25F1
43 #define DPNI_CMDID_SET_QUEUE			0x2601
44 #define DPNI_CMDID_SET_TX_CONFIRMATION_MODE	0x2661
45 
46 /*                cmd, param, offset, width, type, arg_name */
47 #define DPNI_CMD_OPEN(cmd, dpni_id) \
48 	MC_CMD_OP(cmd,	 0,	0,	32,	int,	dpni_id)
49 
50 /*                cmd, param, offset, width, type, arg_name */
51 #define DPNI_PREP_CFG(param, cfg) \
52 do { \
53 	MC_PREP_OP(param, 0, 0,   32, uint16_t, cfg->adv.options); \
54 	MC_PREP_OP(param, 0, 32,   8, uint16_t, cfg->adv.num_queues); \
55 	MC_PREP_OP(param, 0, 40,   8, uint16_t, cfg->adv.num_tcs); \
56 	MC_PREP_OP(param, 0, 48,   8, uint16_t, cfg->adv.mac_entries); \
57 	MC_PREP_OP(param, 1, 0,   8, uint16_t, cfg->adv.vlan_entries); \
58 	MC_PREP_OP(param, 1, 16,   8, uint16_t, cfg->adv.qos_entries); \
59 	MC_PREP_OP(param, 1, 32,   16, uint16_t, cfg->adv.fs_entries); \
60 } while (0)
61 
62 /*                cmd, param, offset, width, type, arg_name */
63 #define DPNI_EXT_CFG(param, cfg) \
64 do { \
65 	MC_EXT_OP(param, 0, 0,   32, uint16_t, cfg->adv.options); \
66 	MC_EXT_OP(param, 0, 32,   8, uint16_t, cfg->adv.num_queues); \
67 	MC_EXT_OP(param, 0, 40,   8, uint16_t, cfg->adv.num_tcs); \
68 	MC_EXT_OP(param, 0, 48,   8, uint16_t, cfg->adv.mac_entries); \
69 	MC_EXT_OP(param, 1, 0,   8, uint16_t, cfg->adv.vlan_entries); \
70 	MC_EXT_OP(param, 1, 16,   8, uint16_t, cfg->adv.qos_entries); \
71 	MC_EXT_OP(param, 1, 32,   16, uint16_t, cfg->adv.fs_entries); \
72 } while (0)
73 
74 /*                cmd, param, offset, width, type, arg_name */
75 #define DPNI_CMD_CREATE(cmd, cfg) \
76 do { \
77 	MC_CMD_OP(cmd, 0, 0,	32,	uint32_t,  cfg->adv.options); \
78 	MC_CMD_OP(cmd, 0, 32,	8,	uint8_t,   cfg->adv.num_queues); \
79 	MC_CMD_OP(cmd, 0, 40,	8,	uint8_t,   cfg->adv.num_tcs); \
80 	MC_CMD_OP(cmd, 0, 48,	8,	uint8_t,   cfg->adv.mac_entries); \
81 	MC_CMD_OP(cmd, 1, 0,	8,	uint8_t,   cfg->adv.vlan_entries); \
82 	MC_CMD_OP(cmd, 1, 16,	8,	uint8_t,   cfg->adv.qos_entries); \
83 	MC_CMD_OP(cmd, 1, 32,	16,	uint8_t,   cfg->adv.fs_entries); \
84 } while (0)
85 
86 /*                cmd, param, offset, width, type, arg_name */
87 #define DPNI_CMD_SET_POOLS(cmd, cfg) \
88 do { \
89 	MC_CMD_OP(cmd, 0, 0,  8,  uint8_t,  cfg->num_dpbp); \
90 	MC_CMD_OP(cmd, 0, 8,  1,  int,      cfg->pools[0].backup_pool); \
91 	MC_CMD_OP(cmd, 0, 9,  1,  int,      cfg->pools[1].backup_pool); \
92 	MC_CMD_OP(cmd, 0, 10, 1,  int,      cfg->pools[2].backup_pool); \
93 	MC_CMD_OP(cmd, 0, 11, 1,  int,      cfg->pools[3].backup_pool); \
94 	MC_CMD_OP(cmd, 0, 12, 1,  int,      cfg->pools[4].backup_pool); \
95 	MC_CMD_OP(cmd, 0, 13, 1,  int,      cfg->pools[5].backup_pool); \
96 	MC_CMD_OP(cmd, 0, 14, 1,  int,      cfg->pools[6].backup_pool); \
97 	MC_CMD_OP(cmd, 0, 15, 1,  int,      cfg->pools[7].backup_pool); \
98 	MC_CMD_OP(cmd, 0, 32, 32, int,      cfg->pools[0].dpbp_id); \
99 	MC_CMD_OP(cmd, 4, 32, 16, uint16_t, cfg->pools[0].buffer_size);\
100 	MC_CMD_OP(cmd, 1, 0,  32, int,      cfg->pools[1].dpbp_id); \
101 	MC_CMD_OP(cmd, 4, 48, 16, uint16_t, cfg->pools[1].buffer_size);\
102 	MC_CMD_OP(cmd, 1, 32, 32, int,      cfg->pools[2].dpbp_id); \
103 	MC_CMD_OP(cmd, 5, 0,  16, uint16_t, cfg->pools[2].buffer_size);\
104 	MC_CMD_OP(cmd, 2, 0,  32, int,      cfg->pools[3].dpbp_id); \
105 	MC_CMD_OP(cmd, 5, 16, 16, uint16_t, cfg->pools[3].buffer_size);\
106 	MC_CMD_OP(cmd, 2, 32, 32, int,      cfg->pools[4].dpbp_id); \
107 	MC_CMD_OP(cmd, 5, 32, 16, uint16_t, cfg->pools[4].buffer_size);\
108 	MC_CMD_OP(cmd, 3, 0,  32, int,      cfg->pools[5].dpbp_id); \
109 	MC_CMD_OP(cmd, 5, 48, 16, uint16_t, cfg->pools[5].buffer_size);\
110 	MC_CMD_OP(cmd, 3, 32, 32, int,      cfg->pools[6].dpbp_id); \
111 	MC_CMD_OP(cmd, 6, 0,  16, uint16_t, cfg->pools[6].buffer_size);\
112 	MC_CMD_OP(cmd, 4, 0,  32, int,      cfg->pools[7].dpbp_id); \
113 	MC_CMD_OP(cmd, 6, 16, 16, uint16_t, cfg->pools[7].buffer_size);\
114 } while (0)
115 
116 /*                cmd, param, offset, width, type, arg_name */
117 #define DPNI_RSP_GET_ATTR(cmd, attr) \
118 do { \
119 	MC_RSP_OP(cmd, 0, 0,  32, int,	    attr->options);\
120 	MC_RSP_OP(cmd, 0, 32,  8,  uint8_t,  attr->max_num_queues); \
121 	MC_RSP_OP(cmd, 0, 40,  8,  uint8_t,  attr->max_num_tcs); \
122 	MC_RSP_OP(cmd, 0, 48,  8,  uint8_t,  attr->max_mac_entries); \
123 	MC_RSP_OP(cmd, 1,  0,  8,  uint8_t,  attr->max_vlan_entries); \
124 	MC_RSP_OP(cmd, 1, 16,  8,  uint8_t,  attr->max_qos_entries); \
125 	MC_RSP_OP(cmd, 1, 32, 16,  uint16_t,  attr->max_fs_entries); \
126 	MC_RSP_OP(cmd, 2,  0,  8,  uint8_t,  attr->max_qos_key_size); \
127 	MC_RSP_OP(cmd, 2,  8,  8,  uint8_t,  attr->max_fs_key_size); \
128 	MC_RSP_OP(cmd, 2, 16, 16,  uint16_t,  attr->wriop_version); \
129 } while (0)
130 
131 /*                cmd, param, offset, width, type, arg_name */
132 #define DPNI_CMD_SET_ERRORS_BEHAVIOR(cmd, cfg) \
133 do { \
134 	MC_CMD_OP(cmd, 0, 0,  32, uint32_t, cfg->errors); \
135 	MC_CMD_OP(cmd, 0, 32, 4,  enum dpni_error_action, cfg->error_action); \
136 	MC_CMD_OP(cmd, 0, 36, 1,  int,      cfg->set_frame_annotation); \
137 } while (0)
138 
139 /*                cmd, param, offset, width, type, arg_name */
140 #define DPNI_CMD_SET_BUFFER_LAYOUT(cmd, layout, queue) \
141 do { \
142 	MC_CMD_OP(cmd, 0, 0,  8, enum dpni_queue_type, queue); \
143 	MC_CMD_OP(cmd, 1, 0,  16, uint16_t, layout->private_data_size); \
144 	MC_CMD_OP(cmd, 1, 16, 16, uint16_t, layout->data_align); \
145 	MC_CMD_OP(cmd, 0, 32, 16, uint16_t, layout->options); \
146 	MC_CMD_OP(cmd, 0, 48,  1,  int,	    layout->pass_timestamp); \
147 	MC_CMD_OP(cmd, 0, 49,  1,  int,	    layout->pass_parser_result); \
148 	MC_CMD_OP(cmd, 0, 50,  1,  int,	    layout->pass_frame_status); \
149 	MC_CMD_OP(cmd, 1, 32, 16, uint16_t, layout->data_head_room); \
150 	MC_CMD_OP(cmd, 1, 48, 16, uint16_t, layout->data_tail_room); \
151 } while (0)
152 
153 /*                cmd, param, offset, width, type, arg_name */
154 #define DPNI_RSP_GET_QDID(cmd, qdid) \
155 	MC_RSP_OP(cmd, 0, 0,  16, uint16_t, qdid)
156 
157 /*                cmd, param, offset, width, type, arg_name */
158 #define DPNI_RSP_GET_TX_DATA_OFFSET(cmd, data_offset) \
159 	MC_RSP_OP(cmd, 0, 0,  16, uint16_t, data_offset)
160 
161 /*                cmd, param, offset, width, type, arg_name */
162 #define DPNI_CMD_SET_LINK_CFG(cmd, cfg) \
163 do { \
164 	MC_CMD_OP(cmd, 1, 0,  32, uint32_t, cfg->rate);\
165 	MC_CMD_OP(cmd, 2, 0,  64, uint64_t, cfg->options);\
166 } while (0)
167 
168 /*                cmd, param, offset, width, type, arg_name */
169 #define DPNI_RSP_GET_LINK_STATE(cmd, state) \
170 do { \
171 	MC_RSP_OP(cmd, 0, 32,  1, int,      state->up);\
172 	MC_RSP_OP(cmd, 1, 0,  32, uint32_t, state->rate);\
173 	MC_RSP_OP(cmd, 2, 0,  64, uint64_t, state->options);\
174 } while (0)
175 
176 
177 
178 /*                cmd, param, offset, width, type, arg_name */
179 #define DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr) \
180 do { \
181 	MC_CMD_OP(cmd, 0, 16, 8,  uint8_t,  mac_addr[5]); \
182 	MC_CMD_OP(cmd, 0, 24, 8,  uint8_t,  mac_addr[4]); \
183 	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  mac_addr[3]); \
184 	MC_CMD_OP(cmd, 0, 40, 8,  uint8_t,  mac_addr[2]); \
185 	MC_CMD_OP(cmd, 0, 48, 8,  uint8_t,  mac_addr[1]); \
186 	MC_CMD_OP(cmd, 0, 56, 8,  uint8_t,  mac_addr[0]); \
187 } while (0)
188 
189 /*                cmd, param, offset, width, type, arg_name */
190 #define DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr) \
191 do { \
192 	MC_RSP_OP(cmd, 0, 16, 8,  uint8_t,  mac_addr[5]); \
193 	MC_RSP_OP(cmd, 0, 24, 8,  uint8_t,  mac_addr[4]); \
194 	MC_RSP_OP(cmd, 0, 32, 8,  uint8_t,  mac_addr[3]); \
195 	MC_RSP_OP(cmd, 0, 40, 8,  uint8_t,  mac_addr[2]); \
196 	MC_RSP_OP(cmd, 0, 48, 8,  uint8_t,  mac_addr[1]); \
197 	MC_RSP_OP(cmd, 0, 56, 8,  uint8_t,  mac_addr[0]); \
198 } while (0)
199 
200 /*                cmd, param, offset, width, type, arg_name */
201 #define DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr) \
202 do { \
203 	MC_CMD_OP(cmd, 0, 16, 8,  uint8_t,  mac_addr[5]); \
204 	MC_CMD_OP(cmd, 0, 24, 8,  uint8_t,  mac_addr[4]); \
205 	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  mac_addr[3]); \
206 	MC_CMD_OP(cmd, 0, 40, 8,  uint8_t,  mac_addr[2]); \
207 	MC_CMD_OP(cmd, 0, 48, 8,  uint8_t,  mac_addr[1]); \
208 	MC_CMD_OP(cmd, 0, 56, 8,  uint8_t,  mac_addr[0]); \
209 } while (0)
210 
211 /*                cmd, param, offset, width, type, arg_name */
212 #define DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr) \
213 do { \
214 	MC_CMD_OP(cmd, 0, 16, 8,  uint8_t,  mac_addr[5]); \
215 	MC_CMD_OP(cmd, 0, 24, 8,  uint8_t,  mac_addr[4]); \
216 	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  mac_addr[3]); \
217 	MC_CMD_OP(cmd, 0, 40, 8,  uint8_t,  mac_addr[2]); \
218 	MC_CMD_OP(cmd, 0, 48, 8,  uint8_t,  mac_addr[1]); \
219 	MC_CMD_OP(cmd, 0, 56, 8,  uint8_t,  mac_addr[0]); \
220 } while (0)
221 
222 #define DPNI_CMD_GET_QUEUE(cmd, type, tc, index) \
223 do { \
224 	MC_CMD_OP(cmd, 0,  0,  8, enum dpni_queue_type, type); \
225 	MC_CMD_OP(cmd, 0,  8,  8, uint8_t, tc); \
226 	MC_CMD_OP(cmd, 0, 16,  8, uint8_t, index); \
227 } while (0)
228 
229 #define DPNI_RSP_GET_QUEUE(cmd, queue) \
230 do { \
231 	MC_RSP_OP(cmd, 1,  0, 32, uint32_t, (queue)->destination.id); \
232 	MC_RSP_OP(cmd, 1, 56,  4, enum dpni_dest, (queue)->destination.type); \
233 	MC_RSP_OP(cmd, 1, 62,  1, char, (queue)->destination.stash_ctrl); \
234 	MC_RSP_OP(cmd, 1, 63,  1, char, (queue)->destination.hold_active); \
235 	MC_RSP_OP(cmd, 2,  0, 64, uint64_t, (queue)->flc); \
236 	MC_RSP_OP(cmd, 3,  0, 64, uint64_t, (queue)->user_context); \
237 	MC_RSP_OP(cmd, 4,  0, 32, uint32_t, (queue)->fqid); \
238 	MC_RSP_OP(cmd, 4, 32, 16, uint16_t, (queue)->qdbin); \
239 } while (0)
240 
241 #define DPNI_CMD_SET_QUEUE(cmd, type, tc, index, queue) \
242 do { \
243 	MC_CMD_OP(cmd, 0,  0,  8, enum dpni_queue_type, type); \
244 	MC_CMD_OP(cmd, 0,  8,  8, uint8_t, tc); \
245 	MC_CMD_OP(cmd, 0, 16,  8, uint8_t, index); \
246 	MC_CMD_OP(cmd, 0, 24,  8, uint8_t, (queue)->options); \
247 	MC_CMD_OP(cmd, 1,  0, 32, uint32_t, (queue)->destination.id); \
248 	MC_CMD_OP(cmd, 1, 56,  4, enum dpni_dest, (queue)->destination.type); \
249 	MC_CMD_OP(cmd, 1, 62,  1, char, (queue)->destination.stash_ctrl); \
250 	MC_CMD_OP(cmd, 1, 63,  1, char, (queue)->destination.hold_active); \
251 	MC_CMD_OP(cmd, 1,  0, 32, uint32_t, (queue)->destination.id); \
252 	MC_CMD_OP(cmd, 2,  0, 64, uint64_t, (queue)->flc); \
253 	MC_CMD_OP(cmd, 3,  0, 64, uint64_t, (queue)->user_context); \
254 } while (0)
255 
256 /*			cmd, param, offset, width, type, arg_name */
257 #define DPNI_CMD_GET_STATISTICS(cmd, page) \
258 	MC_CMD_OP(cmd, 0, 0, 8, uint8_t, page)
259 
260 /*                cmd, param, offset, width, type, arg_name */
261 #define DPNI_RSP_GET_STATISTICS(cmd, stat) \
262 do { \
263 	MC_RSP_OP(cmd, 0, 0, 64, uint64_t, (stat)->counter0); \
264 	MC_RSP_OP(cmd, 1, 0, 64, uint64_t, (stat)->counter1); \
265 	MC_RSP_OP(cmd, 2, 0, 64, uint64_t, (stat)->counter2); \
266 	MC_RSP_OP(cmd, 3, 0, 64, uint64_t, (stat)->counter3); \
267 	MC_RSP_OP(cmd, 4, 0, 64, uint64_t, (stat)->counter4); \
268 	MC_RSP_OP(cmd, 5, 0, 64, uint64_t, (stat)->counter5); \
269 	MC_RSP_OP(cmd, 6, 0, 64, uint64_t, (stat)->counter6); \
270 } while (0)
271 
272 enum net_prot {
273 	NET_PROT_NONE = 0,
274 	NET_PROT_PAYLOAD,
275 	NET_PROT_ETH,
276 	NET_PROT_VLAN,
277 	NET_PROT_IPV4,
278 	NET_PROT_IPV6,
279 	NET_PROT_IP,
280 	NET_PROT_TCP,
281 	NET_PROT_UDP,
282 	NET_PROT_UDP_LITE,
283 	NET_PROT_IPHC,
284 	NET_PROT_SCTP,
285 	NET_PROT_SCTP_CHUNK_DATA,
286 	NET_PROT_PPPOE,
287 	NET_PROT_PPP,
288 	NET_PROT_PPPMUX,
289 	NET_PROT_PPPMUX_SUBFRM,
290 	NET_PROT_L2TPV2,
291 	NET_PROT_L2TPV3_CTRL,
292 	NET_PROT_L2TPV3_SESS,
293 	NET_PROT_LLC,
294 	NET_PROT_LLC_SNAP,
295 	NET_PROT_NLPID,
296 	NET_PROT_SNAP,
297 	NET_PROT_MPLS,
298 	NET_PROT_IPSEC_AH,
299 	NET_PROT_IPSEC_ESP,
300 	NET_PROT_UDP_ENC_ESP, /* RFC 3948 */
301 	NET_PROT_MACSEC,
302 	NET_PROT_GRE,
303 	NET_PROT_MINENCAP,
304 	NET_PROT_DCCP,
305 	NET_PROT_ICMP,
306 	NET_PROT_IGMP,
307 	NET_PROT_ARP,
308 	NET_PROT_CAPWAP_DATA,
309 	NET_PROT_CAPWAP_CTRL,
310 	NET_PROT_RFC2684,
311 	NET_PROT_ICMPV6,
312 	NET_PROT_FCOE,
313 	NET_PROT_FIP,
314 	NET_PROT_ISCSI,
315 	NET_PROT_GTP,
316 	NET_PROT_USER_DEFINED_L2,
317 	NET_PROT_USER_DEFINED_L3,
318 	NET_PROT_USER_DEFINED_L4,
319 	NET_PROT_USER_DEFINED_L5,
320 	NET_PROT_USER_DEFINED_SHIM1,
321 	NET_PROT_USER_DEFINED_SHIM2,
322 
323 	NET_PROT_DUMMY_LAST
324 };
325 
326 /**
327  * Data Path Network Interface API
328  * Contains initialization APIs and runtime control APIs for DPNI
329  */
330 
331 struct fsl_mc_io;
332 
333 /* General DPNI macros */
334 
335 /* Maximum number of traffic classes */
336 #define DPNI_MAX_TC				8
337 /* Maximum number of buffer pools per DPNI */
338 #define DPNI_MAX_DPBP				8
339 
340 /* All traffic classes considered; see dpni_set_rx_flow() */
341 #define DPNI_ALL_TCS				(uint8_t)(-1)
342 /* All flows within traffic class considered; see dpni_set_rx_flow() */
343 #define DPNI_ALL_TC_FLOWS			(uint16_t)(-1)
344 /* Generate new flow ID; see dpni_set_tx_flow() */
345 #define DPNI_NEW_FLOW_ID			(uint16_t)(-1)
346 /* use for common tx-conf queue; see dpni_set_tx_conf_<x>() */
347 #define DPNI_COMMON_TX_CONF			(uint16_t)(-1)
348 
349 /**
350  * dpni_open() - Open a control session for the specified object
351  * @mc_io:	Pointer to MC portal's I/O object
352  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
353  * @dpni_id:	DPNI unique ID
354  * @token:	Returned token; use in subsequent API calls
355  *
356  * This function can be used to open a control session for an
357  * already created object; an object may have been declared in
358  * the DPL or by calling the dpni_create() function.
359  * This function returns a unique authentication token,
360  * associated with the specific object ID and the specific MC
361  * portal; this token must be used in all subsequent commands for
362  * this specific object.
363  *
364  * Return:	'0' on Success; Error code otherwise.
365  */
366 int dpni_open(struct fsl_mc_io	*mc_io,
367 	      uint32_t		cmd_flags,
368 	      int		dpni_id,
369 	      uint16_t		*token);
370 
371 /**
372  * dpni_close() - Close the control session of the object
373  * @mc_io:	Pointer to MC portal's I/O object
374  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
375  * @token:	Token of DPNI object
376  *
377  * After this function is called, no further operations are
378  * allowed on the object without opening a new control session.
379  *
380  * Return:	'0' on Success; Error code otherwise.
381  */
382 int dpni_close(struct fsl_mc_io	*mc_io,
383 	       uint32_t		cmd_flags,
384 	       uint16_t		token);
385 
386 /* DPNI configuration options */
387 
388 /**
389  * Allow different distribution key profiles for different traffic classes;
390  * if not set, a single key profile is assumed
391  */
392 #define DPNI_OPT_ALLOW_DIST_KEY_PER_TC		0x00000001
393 
394 /**
395  * Disable all non-error transmit confirmation; error frames are reported
396  * back to a common Tx error queue
397  */
398 #define DPNI_OPT_TX_CONF_DISABLED		0x00000002
399 
400 /* Disable per-sender private Tx confirmation/error queue */
401 #define DPNI_OPT_PRIVATE_TX_CONF_ERROR_DISABLED	0x00000004
402 
403 /**
404  * Support distribution based on hashed key;
405  * allows statistical distribution over receive queues in a traffic class
406  */
407 #define DPNI_OPT_DIST_HASH			0x00000010
408 
409 /**
410  * Support distribution based on flow steering;
411  * allows explicit control of distribution over receive queues in a traffic
412  * class
413  */
414 #define DPNI_OPT_DIST_FS			0x00000020
415 
416 /* Unicast filtering support */
417 #define DPNI_OPT_UNICAST_FILTER			0x00000080
418 /* Multicast filtering support */
419 #define DPNI_OPT_MULTICAST_FILTER		0x00000100
420 /* VLAN filtering support */
421 #define DPNI_OPT_VLAN_FILTER			0x00000200
422 /* Support IP reassembly on received packets */
423 #define DPNI_OPT_IPR				0x00000800
424 /* Support IP fragmentation on transmitted packets */
425 #define DPNI_OPT_IPF				0x00001000
426 /* VLAN manipulation support */
427 #define DPNI_OPT_VLAN_MANIPULATION		0x00010000
428 /* Support masking of QoS lookup keys */
429 #define DPNI_OPT_QOS_MASK_SUPPORT		0x00020000
430 /* Support masking of Flow Steering lookup keys */
431 #define DPNI_OPT_FS_MASK_SUPPORT		0x00040000
432 
433 /**
434  * enum dpni_queue_type - Identifies a type of queue targeted by the command
435  * @DPNI_QUEUE_RX: Rx queue
436  * @DPNI_QUEUE_TX: Tx queue
437  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
438  * @DPNI_QUEUE_RX_ERR: Rx error queue
439  */
440 enum dpni_queue_type {
441 	DPNI_QUEUE_RX,
442 	DPNI_QUEUE_TX,
443 	DPNI_QUEUE_TX_CONFIRM,
444 	DPNI_QUEUE_RX_ERR,
445 };
446 
447 struct dpni_cfg {
448 		uint8_t mac_addr[6];
449 	struct {
450 		uint32_t		options;
451 		uint16_t		fs_entries;
452 		uint8_t			num_queues;
453 		uint8_t			num_tcs;
454 		uint8_t			mac_entries;
455 		uint8_t			vlan_entries;
456 		uint8_t			qos_entries;
457 	} adv;
458 };
459 
460 /**
461  * struct dpni_extended_cfg - Structure representing extended DPNI configuration
462  * @tc_cfg: TCs configuration
463  * @ipr_cfg: IP reassembly configuration
464  */
465 struct dpni_extended_cfg {
466 	/**
467 	 * struct tc_cfg - TC configuration
468 	 * @max_dist: Maximum distribution size for Rx traffic class;
469 	 *	supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
470 	 *	112,128,192,224,256,384,448,512,768,896,1024;
471 	 *	value '0' will be treated as '1'.
472 	 *	other unsupported values will be round down to the nearest
473 	 *	supported value.
474 	 * @max_fs_entries: Maximum FS entries for Rx traffic class;
475 	 *	'0' means no support for this TC;
476 	 */
477 	struct {
478 		uint16_t	max_dist;
479 		uint16_t	max_fs_entries;
480 	} tc_cfg[DPNI_MAX_TC];
481 	/**
482 	 * struct ipr_cfg - Structure representing IP reassembly configuration
483 	 * @max_reass_frm_size: Maximum size of the reassembled frame
484 	 * @min_frag_size_ipv4: Minimum fragment size of IPv4 fragments
485 	 * @min_frag_size_ipv6: Minimum fragment size of IPv6 fragments
486 	 * @max_open_frames_ipv4: Maximum concurrent IPv4 packets in reassembly
487 	 *		process
488 	 * @max_open_frames_ipv6: Maximum concurrent IPv6 packets in reassembly
489 	 *		process
490 	 */
491 	struct {
492 		uint16_t max_reass_frm_size;
493 		uint16_t min_frag_size_ipv4;
494 		uint16_t min_frag_size_ipv6;
495 		uint16_t max_open_frames_ipv4;
496 		uint16_t max_open_frames_ipv6;
497 	} ipr_cfg;
498 };
499 
500 /**
501  * dpni_prepare_cfg() - function prepare parameters
502  * @cfg: cfg structure
503  * @cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
504  *
505  * This function has to be called before dpni_create()
506  */
507 int dpni_prepare_cfg(const struct dpni_cfg	*cfg,
508 		     uint8_t			*cfg_buf);
509 /**
510  * dpni_create() - Create the DPNI object
511  * @mc_io:	Pointer to MC portal's I/O object
512  * @token:	Authentication token.
513  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
514  * @cfg:	Configuration structure
515  * @obj_id:	Returned obj_id; use in subsequent API calls
516  *
517  * Create the DPNI object, allocate required resources and
518  * perform required initialization.
519  *
520  * The object can be created either by declaring it in the
521  * DPL file, or by calling this function.
522  *
523  * This function returns a unique authentication token,
524  * associated with the specific object ID and the specific MC
525  * portal; this token must be used in all subsequent calls to
526  * this specific object. For objects that are created using the
527  * DPL file, call dpni_open() function to get an authentication
528  * token first.
529  *
530  * Return:	'0' on Success; Error code otherwise.
531  */
532 int dpni_create(struct fsl_mc_io	*mc_io,
533 		uint16_t		token,
534 		uint32_t		cmd_flags,
535 		const struct dpni_cfg	*cfg,
536 		uint32_t		*obj_id);
537 
538 /**
539  * dpni_destroy() - Destroy the DPNI object and release all its resources.
540  * @mc_io:	Pointer to MC portal's I/O object
541  * @token:	Authentication token.
542  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
543  * @obj_id:	Returned obj_id; use in subsequent API calls
544  *
545  * Return:	'0' on Success; error code otherwise.
546  */
547 int dpni_destroy(struct fsl_mc_io	*mc_io,
548 		 uint16_t		token,
549 		 uint32_t		cmd_flags,
550 		 uint32_t		obj_id);
551 
552 /**
553  * struct dpni_pools_cfg - Structure representing buffer pools configuration
554  * @num_dpbp: Number of DPBPs
555  * @pools: Array of buffer pools parameters; The number of valid entries
556  *	must match 'num_dpbp' value
557  */
558 struct dpni_pools_cfg {
559 	uint8_t num_dpbp;
560 	/**
561 	 * struct pools - Buffer pools parameters
562 	 * @dpbp_id: DPBP object ID
563 	 * @buffer_size: Buffer size
564 	 * @backup_pool: Backup pool
565 	 */
566 	struct {
567 		int		dpbp_id;
568 		uint16_t	buffer_size;
569 		int		backup_pool;
570 	} pools[DPNI_MAX_DPBP];
571 };
572 
573 /**
574  * dpni_set_pools() - Set buffer pools configuration
575  * @mc_io:	Pointer to MC portal's I/O object
576  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
577  * @token:	Token of DPNI object
578  * @cfg:	Buffer pools configuration
579  *
580  * mandatory for DPNI operation
581  * warning:Allowed only when DPNI is disabled
582  *
583  * Return:	'0' on Success; Error code otherwise.
584  */
585 int dpni_set_pools(struct fsl_mc_io		*mc_io,
586 		   uint32_t			cmd_flags,
587 		   uint16_t			token,
588 		   const struct dpni_pools_cfg	*cfg);
589 
590 /**
591  * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
592  * @mc_io:	Pointer to MC portal's I/O object
593  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
594  * @token:		Token of DPNI object
595  *
596  * Return:	'0' on Success; Error code otherwise.
597  */
598 int dpni_enable(struct fsl_mc_io	*mc_io,
599 		uint32_t		cmd_flags,
600 		uint16_t		token);
601 
602 /**
603  * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
604  * @mc_io:	Pointer to MC portal's I/O object
605  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
606  * @token:	Token of DPNI object
607  *
608  * Return:	'0' on Success; Error code otherwise.
609  */
610 int dpni_disable(struct fsl_mc_io	*mc_io,
611 		 uint32_t		cmd_flags,
612 		 uint16_t		token);
613 
614 
615 /**
616  * dpni_reset() - Reset the DPNI, returns the object to initial state.
617  * @mc_io:	Pointer to MC portal's I/O object
618  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
619  * @token:	Token of DPNI object
620  *
621  * Return:	'0' on Success; Error code otherwise.
622  */
623 int dpni_reset(struct fsl_mc_io	*mc_io,
624 	       uint32_t		cmd_flags,
625 	       uint16_t		token);
626 
627 /**
628  * struct dpni_attr - Structure representing DPNI attributes
629  * @options: Mask of available options; reflects the value as was given in
630  *		object's creation
631  * @max_num_queues: Number of queues available (for both Tx and Rx)
632  * @max_num_tcs: Maximum number of traffic classes (for both Tx and Rx)
633  * @max_mac_entries: Maximum number of traffic classes (for both Tx and Rx)
634  * @max_unicast_filters: Maximum number of unicast filters
635  * @max_multicast_filters: Maximum number of multicast filters
636  * @max_vlan_entries: Maximum number of VLAN filters
637  * @max_qos_entries: if 'max_tcs > 1', declares the maximum entries in QoS table
638  * @max_fs_entries: declares the maximum entries in flow steering table
639  * @max_qos_key_size: Maximum key size for the QoS look-up
640  * @max_fs_key_size: Maximum key size for the flow steering
641  * @wriop_version: Indicates revision of WRIOP hardware block
642  */
643 struct dpni_attr {
644 	uint32_t id;
645 	uint32_t options;
646 	uint8_t max_num_queues;
647 	uint8_t max_num_tcs;
648 	uint8_t max_mac_entries;
649 	uint8_t max_vlan_entries;
650 	uint8_t max_qos_entries;
651 	uint16_t max_fs_entries;
652 	uint8_t max_qos_key_size;
653 	uint8_t max_fs_key_size;
654 	uint16_t wriop_version;
655 };
656 
657 /**
658  * dpni_get_attributes() - Retrieve DPNI attributes.
659  * @mc_io:	Pointer to MC portal's I/O object
660  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
661  * @token:	Token of DPNI object
662  * @attr:	Object's attributes
663  *
664  * Return:	'0' on Success; Error code otherwise.
665  */
666 int dpni_get_attributes(struct fsl_mc_io	*mc_io,
667 			uint32_t		cmd_flags,
668 			uint16_t		token,
669 			struct dpni_attr	*attr);
670 
671 /**
672  * dpni_extract_cfg() - extract the parameters
673  * @cfg: cfg structure
674  * @cfg_buf: 256 bytes of DMA-able memory
675  *
676  * This function has to be called after dpni_get_attributes()
677  */
678 int dpni_extract_cfg(struct dpni_cfg	*cfg,
679 		     const uint8_t	*cfg_buf);
680 
681 /**
682  * DPNI errors
683  */
684 
685 /**
686  * Extract out of frame header error
687  */
688 #define DPNI_ERROR_EOFHE	0x00020000
689 /**
690  * Frame length error
691  */
692 #define DPNI_ERROR_FLE		0x00002000
693 /**
694  * Frame physical error
695  */
696 #define DPNI_ERROR_FPE		0x00001000
697 /**
698  * Parsing header error
699  */
700 #define DPNI_ERROR_PHE		0x00000020
701 /**
702  * Parser L3 checksum error
703  */
704 #define DPNI_ERROR_L3CE		0x00000004
705 /**
706  * Parser L3 checksum error
707  */
708 #define DPNI_ERROR_L4CE		0x00000001
709 
710 /**
711  * enum dpni_error_action - Defines DPNI behavior for errors
712  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
713  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
714  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
715  */
716 enum dpni_error_action {
717 	DPNI_ERROR_ACTION_DISCARD = 0,
718 	DPNI_ERROR_ACTION_CONTINUE = 1,
719 	DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
720 };
721 
722 /**
723  * struct dpni_error_cfg - Structure representing DPNI errors treatment
724  * @errors: Errors mask; use 'DPNI_ERROR__<X>
725  * @error_action: The desired action for the errors mask
726  * @set_frame_annotation: Set to '1' to mark the errors in frame annotation
727  *		status (FAS); relevant only for the non-discard action
728  */
729 struct dpni_error_cfg {
730 	uint32_t		errors;
731 	enum dpni_error_action	error_action;
732 	int			set_frame_annotation;
733 };
734 
735 /**
736  * dpni_set_errors_behavior() - Set errors behavior
737  * @mc_io:	Pointer to MC portal's I/O object
738  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
739  * @token:	Token of DPNI object
740  * @cfg:	Errors configuration
741  *
742  * this function may be called numerous times with different
743  * error masks
744  *
745  * Return:	'0' on Success; Error code otherwise.
746  */
747 int dpni_set_errors_behavior(struct fsl_mc_io		*mc_io,
748 			     uint32_t			cmd_flags,
749 			     uint16_t			token,
750 			     struct dpni_error_cfg	*cfg);
751 
752 /* DPNI buffer layout modification options */
753 
754 /* Select to modify the time-stamp setting */
755 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP		0x00000001
756 /* Select to modify the parser-result setting; not applicable for Tx */
757 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT	0x00000002
758 /* Select to modify the frame-status setting */
759 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS	0x00000004
760 /* Select to modify the private-data-size setting */
761 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE	0x00000008
762 /* Select to modify the data-alignment setting */
763 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN		0x00000010
764 /* Select to modify the data-head-room setting */
765 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM	0x00000020
766 /*!< Select to modify the data-tail-room setting */
767 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM	0x00000040
768 
769 /**
770  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
771  * @options: Flags representing the suggested modifications to the buffer
772  *		layout; Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
773  * @pass_timestamp: Pass timestamp value
774  * @pass_parser_result: Pass parser results
775  * @pass_frame_status: Pass frame status
776  * @private_data_size: Size kept for private data (in bytes)
777  * @data_align: Data alignment
778  * @data_head_room: Data head room
779  * @data_tail_room: Data tail room
780  */
781 struct dpni_buffer_layout {
782 	uint16_t options;
783 	int pass_timestamp;
784 	int pass_parser_result;
785 	int pass_frame_status;
786 	uint16_t private_data_size;
787 	uint16_t data_align;
788 	uint16_t data_head_room;
789 	uint16_t data_tail_room;
790 };
791 
792 /**
793  * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
794  * @mc_io:	Pointer to MC portal's I/O object
795  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
796  * @token:	Token of DPNI object
797  * @layout:	Returns buffer layout attributes
798  * @type:	DPNI queue type
799  *
800  * Return:	'0' on Success; Error code otherwise.
801  */
802 int dpni_get_buffer_layout(struct fsl_mc_io			*mc_io,
803 			   uint32_t				cmd_flags,
804 			   uint16_t				token,
805 			   const struct dpni_buffer_layout	*layout,
806 			   enum dpni_queue_type			type);
807 
808 /**
809  * dpni_set_buffer_layout() - Set buffer layout configuration.
810  * @mc_io:	Pointer to MC portal's I/O object
811  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
812  * @token:	Token of DPNI object
813  * @layout:	Buffer layout configuration
814  * @type:	DPNI queue type
815  *
816  * Return:	'0' on Success; Error code otherwise.
817  *
818  * @warning	Allowed only when DPNI is disabled
819  */
820 int dpni_set_buffer_layout(struct fsl_mc_io			*mc_io,
821 			   uint32_t				cmd_flags,
822 			   uint16_t				token,
823 			   const struct dpni_buffer_layout	*layout,
824 			   enum dpni_queue_type			type);
825 
826 /**
827  * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
828  *			for enqueue operations
829  * @mc_io:	Pointer to MC portal's I/O object
830  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
831  * @token:	Token of DPNI object
832  * @qdid:	Returned virtual QDID value that should be used as an argument
833  *			in all enqueue operations
834  *
835  * Return:	'0' on Success; Error code otherwise.
836  */
837 int dpni_get_qdid(struct fsl_mc_io	*mc_io,
838 		  uint32_t		cmd_flags,
839 		  uint16_t		token,
840 		  uint16_t		*qdid);
841 
842 /**
843  * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
844  * @mc_io:	Pointer to MC portal's I/O object
845  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
846  * @token:	Token of DPNI object
847  * @data_offset: Tx data offset (from start of buffer)
848  *
849  * Return:	'0' on Success; Error code otherwise.
850  */
851 int dpni_get_tx_data_offset(struct fsl_mc_io	*mc_io,
852 			    uint32_t		cmd_flags,
853 			    uint16_t		token,
854 			    uint16_t		*data_offset);
855 
856 /* Enable auto-negotiation */
857 #define DPNI_LINK_OPT_AUTONEG		0x0000000000000001ULL
858 /* Enable half-duplex mode */
859 #define DPNI_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
860 /* Enable pause frames */
861 #define DPNI_LINK_OPT_PAUSE		0x0000000000000004ULL
862 /* Enable a-symmetric pause frames */
863 #define DPNI_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
864 
865 /**
866  * struct - Structure representing DPNI link configuration
867  * @rate: Rate
868  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
869  */
870 struct dpni_link_cfg {
871 	uint32_t rate;
872 	uint64_t options;
873 };
874 
875 /**
876  * dpni_set_link_cfg() - set the link configuration.
877  * @mc_io:	Pointer to MC portal's I/O object
878  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
879  * @token:	Token of DPNI object
880  * @cfg:	Link configuration
881  *
882  * Return:	'0' on Success; Error code otherwise.
883  */
884 int dpni_set_link_cfg(struct fsl_mc_io			*mc_io,
885 		      uint32_t				cmd_flags,
886 		      uint16_t				token,
887 		      const struct dpni_link_cfg	*cfg);
888 
889 /**
890  * struct dpni_link_state - Structure representing DPNI link state
891  * @rate: Rate
892  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
893  * @up: Link state; '0' for down, '1' for up
894  */
895 struct dpni_link_state {
896 	uint32_t rate;
897 	uint64_t options;
898 	int up;
899 };
900 
901 /**
902  * dpni_get_link_state() - Return the link state (either up or down)
903  * @mc_io:	Pointer to MC portal's I/O object
904  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
905  * @token:	Token of DPNI object
906  * @state:	Returned link state;
907  *
908  * Return:	'0' on Success; Error code otherwise.
909  */
910 int dpni_get_link_state(struct fsl_mc_io	*mc_io,
911 			uint32_t		cmd_flags,
912 			uint16_t		token,
913 			struct dpni_link_state	*state);
914 
915 /**
916  * dpni_set_primary_mac_addr() - Set the primary MAC address
917  * @mc_io:	Pointer to MC portal's I/O object
918  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
919  * @token:	Token of DPNI object
920  * @mac_addr:	MAC address to set as primary address
921  *
922  * Return:	'0' on Success; Error code otherwise.
923  */
924 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
925 			      uint32_t		cmd_flags,
926 			      uint16_t		token,
927 			      const uint8_t	mac_addr[6]);
928 
929 /**
930  * dpni_get_primary_mac_addr() - Get the primary MAC address
931  * @mc_io:	Pointer to MC portal's I/O object
932  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
933  * @token:	Token of DPNI object
934  * @mac_addr:	Returned MAC address
935  *
936  * Return:	'0' on Success; Error code otherwise.
937  */
938 int dpni_get_primary_mac_addr(struct fsl_mc_io	*mc_io,
939 			      uint32_t		cmd_flags,
940 			      uint16_t		token,
941 			      uint8_t		mac_addr[6]);
942 
943 /**
944  * dpni_add_mac_addr() - Add MAC address filter
945  * @mc_io:	Pointer to MC portal's I/O object
946  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
947  * @token:	Token of DPNI object
948  * @mac_addr:	MAC address to add
949  *
950  * Return:	'0' on Success; Error code otherwise.
951  */
952 int dpni_add_mac_addr(struct fsl_mc_io	*mc_io,
953 		      uint32_t		cmd_flags,
954 		      uint16_t		token,
955 		      const uint8_t	mac_addr[6]);
956 
957 /**
958  * dpni_remove_mac_addr() - Remove MAC address filter
959  * @mc_io:	Pointer to MC portal's I/O object
960  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
961  * @token:	Token of DPNI object
962  * @mac_addr:	MAC address to remove
963  *
964  * Return:	'0' on Success; Error code otherwise.
965  */
966 int dpni_remove_mac_addr(struct fsl_mc_io	*mc_io,
967 			 uint32_t		cmd_flags,
968 			 uint16_t		token,
969 			 const uint8_t		mac_addr[6]);
970 
971 /**
972  * enum dpni_dest - DPNI destination types
973  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
974  *		does not generate FQDAN notifications; user is expected to
975  *		dequeue from the queue based on polling or other user-defined
976  *		method
977  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
978  *		notifications to the specified DPIO; user is expected to dequeue
979  *		from the queue only after notification is received
980  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
981  *		FQDAN notifications, but is connected to the specified DPCON
982  *		object; user is expected to dequeue from the DPCON channel
983  */
984 enum dpni_dest {
985 	DPNI_DEST_NONE = 0,
986 	DPNI_DEST_DPIO = 1,
987 	DPNI_DEST_DPCON = 2
988 };
989 
990 /**
991  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
992  * @dest_type: Destination type
993  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
994  * @priority: Priority selection within the DPIO or DPCON channel; valid values
995  *		are 0-1 or 0-7, depending on the number of priorities in that
996  *		channel; not relevant for 'DPNI_DEST_NONE' option
997  */
998 struct dpni_dest_cfg {
999 	enum dpni_dest dest_type;
1000 	int dest_id;
1001 	uint8_t priority;
1002 };
1003 
1004 /**
1005  * enum dpni_flc_type - DPNI FLC types
1006  * @DPNI_FLC_USER_DEFINED: select the FLC to be used for user defined value
1007  * @DPNI_FLC_STASH: select the FLC to be used for stash control
1008  */
1009 enum dpni_flc_type {
1010 	DPNI_FLC_USER_DEFINED = 0,
1011 	DPNI_FLC_STASH = 1,
1012 };
1013 
1014 /**
1015  * enum dpni_stash_size - DPNI FLC stashing size
1016  * @DPNI_STASH_SIZE_0B: no stash
1017  * @DPNI_STASH_SIZE_64B: stashes 64 bytes
1018  * @DPNI_STASH_SIZE_128B: stashes 128 bytes
1019  * @DPNI_STASH_SIZE_192B: stashes 192 bytes
1020  */
1021 enum dpni_stash_size {
1022 	DPNI_STASH_SIZE_0B = 0,
1023 	DPNI_STASH_SIZE_64B = 1,
1024 	DPNI_STASH_SIZE_128B = 2,
1025 	DPNI_STASH_SIZE_192B = 3,
1026 };
1027 
1028 /* DPNI FLC stash options */
1029 
1030 /* stashes the whole annotation area (up to 192 bytes) */
1031 #define DPNI_FLC_STASH_FRAME_ANNOTATION	0x00000001
1032 
1033 /**
1034  * struct dpni_flc_cfg - Structure representing DPNI FLC configuration
1035  * @flc_type: FLC type
1036  * @options: Mask of available options;
1037  *	use 'DPNI_FLC_STASH_<X>' values
1038  * @frame_data_size: Size of frame data to be stashed
1039  * @flow_context_size: Size of flow context to be stashed
1040  * @flow_context: 1. In case flc_type is 'DPNI_FLC_USER_DEFINED':
1041  *			this value will be provided in the frame descriptor
1042  *			(FD[FLC])
1043  *		  2. In case flc_type is 'DPNI_FLC_STASH':
1044  *			this value will be I/O virtual address of the
1045  *			flow-context;
1046  *			Must be cacheline-aligned and DMA-able memory
1047  */
1048 struct dpni_flc_cfg {
1049 	enum dpni_flc_type flc_type;
1050 	uint32_t options;
1051 	enum dpni_stash_size frame_data_size;
1052 	enum dpni_stash_size flow_context_size;
1053 	uint64_t flow_context;
1054 };
1055 
1056 /* DPNI queue modification options */
1057 
1058 /* Select to modify the user's context associated with the queue */
1059 #define DPNI_QUEUE_OPT_USER_CTX		0x00000001
1060 /* Select to modify the queue's destination */
1061 #define DPNI_QUEUE_OPT_DEST		0x00000002
1062 /** Select to modify the flow-context parameters;
1063  * not applicable for Tx-conf/Err queues as the FD comes from the user
1064  */
1065 #define DPNI_QUEUE_OPT_FLC		0x00000004
1066 /* Select to modify the queue's order preservation */
1067 #define DPNI_QUEUE_OPT_ORDER_PRESERVATION 0x00000008
1068 /* Select to modify the queue's tail-drop threshold */
1069 #define DPNI_QUEUE_OPT_TAILDROP_THRESHOLD 0x00000010
1070 
1071 /**
1072  * struct dpni_queue_cfg - Structure representing queue configuration
1073  * @options: Flags representing the suggested modifications to the queue;
1074  *		Use any combination of 'DPNI_QUEUE_OPT_<X>' flags
1075  * @user_ctx: User context value provided in the frame descriptor of each
1076  *		dequeued frame; valid only if 'DPNI_QUEUE_OPT_USER_CTX'
1077  *		is contained in 'options'
1078  * @dest_cfg: Queue destination parameters;
1079  *		valid only if 'DPNI_QUEUE_OPT_DEST' is contained in 'options'
1080  * @flc_cfg: Flow context configuration; in case the TC's distribution
1081  *		is either NONE or HASH the FLC's settings of flow#0 are used.
1082  *		in the case of FS (flow-steering) the flow's FLC settings
1083  *		are used.
1084  *		valid only if 'DPNI_QUEUE_OPT_FLC' is contained in 'options'
1085  * @order_preservation_en: enable/disable order preservation;
1086  *		valid only if 'DPNI_QUEUE_OPT_ORDER_PRESERVATION' is contained
1087  *		in 'options'
1088  * @tail_drop_threshold: set the queue's tail drop threshold in bytes;
1089  *		'0' value disable the threshold; maximum value is 0xE000000;
1090  *		valid only if 'DPNI_QUEUE_OPT_TAILDROP_THRESHOLD' is contained
1091  *		in 'options'
1092  */
1093 struct dpni_queue_cfg {
1094 	uint32_t options;
1095 	uint64_t user_ctx;
1096 	struct dpni_dest_cfg dest_cfg;
1097 	struct dpni_flc_cfg flc_cfg;
1098 	int order_preservation_en;
1099 	uint32_t tail_drop_threshold;
1100 };
1101 
1102 /**
1103  * struct dpni_queue_attr - Structure representing queue attributes
1104  * @user_ctx: User context value provided in the frame descriptor of each
1105  *	dequeued frame
1106  * @dest_cfg: Queue destination configuration
1107  * @flc_cfg: Flow context configuration
1108  * @order_preservation_en: enable/disable order preservation
1109  * @tail_drop_threshold: queue's tail drop threshold in bytes;
1110  * @fqid: Virtual fqid value to be used for dequeue operations
1111  */
1112 struct dpni_queue_attr {
1113 	uint64_t user_ctx;
1114 	struct dpni_dest_cfg dest_cfg;
1115 	struct dpni_flc_cfg flc_cfg;
1116 	int order_preservation_en;
1117 	uint32_t tail_drop_threshold;
1118 	uint32_t fqid;
1119 };
1120 
1121 /* DPNI Tx flow modification options */
1122 
1123 /* Select to modify the settings for dedicate Tx confirmation/error */
1124 #define DPNI_TX_FLOW_OPT_TX_CONF_ERROR	0x00000001
1125 /*!< Select to modify the L3 checksum generation setting */
1126 #define DPNI_TX_FLOW_OPT_L3_CHKSUM_GEN	0x00000010
1127 /*!< Select to modify the L4 checksum generation setting */
1128 #define DPNI_TX_FLOW_OPT_L4_CHKSUM_GEN	0x00000020
1129 
1130 /**
1131  * dpni_get_api_version - Retrieve DPNI Major and Minor version info.
1132  *
1133  * @mc_io:	Pointer to MC portal's I/O object
1134  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1135  * @major_ver:	DPNI major version
1136  * @minor_ver:	DPNI minor version
1137  *
1138  * Return:     '0' on Success; Error code otherwise.
1139  */
1140 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1141 			 u32 cmd_flags,
1142 			 u16 *major_ver,
1143 			 u16 *minor_ver);
1144 
1145 /**
1146  * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
1147  * confirmation
1148  * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
1149  * an affine Tx Confirmation queue
1150  * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
1151  * confirmation queue
1152  * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
1153  * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
1154  * buffers will be leaked.
1155  */
1156 enum dpni_confirmation_mode {
1157 	DPNI_CONF_AFFINE,
1158 	DPNI_CONF_SINGLE,
1159 	DPNI_CONF_DISABLE,
1160 };
1161 
1162 struct dpni_tx_confirmation_mode {
1163 	uint32_t pad;
1164 	uint8_t confirmation_mode;
1165 };
1166 
1167 /**
1168  * struct dpni_queue - Queue structure
1169  * @fqid:  FQID used for enqueueing to and/or configuration of this specific FQ
1170  * @qdbin: Queueing bin, used to enqueue using QDID, DQBIN, QPRI. Only relevant
1171  *         for Tx queues.
1172  * @flc:   FLC value for traffic dequeued from this queue.
1173  * @user_context:    User data, presented to the user along with any frames
1174  *                   from this queue. Not relevant for Tx queues.
1175  */
1176 struct dpni_queue {
1177 	/**
1178 	* struct destination - Destination structure
1179 	* @id:   ID of the destination, only relevant if DEST_TYPE is > 0.
1180 	*        Identifies either a DPIO or a DPCON object. Not relevant for Tx
1181 	*        queues.
1182 	* @type: May be one of the following:
1183 	*         0 - No destination, queue can be manually queried, but won't
1184 	*             push traffic or notifications to a DPIO;
1185 	*         1 - The destination is DPIO. When traffic becomes available in
1186 	*             the queue a FQDAN (FQ data available notification) will be
1187 	*             generated to selected DPIO;
1188 	*         2 - The destination is a DPCON. The queue is associated with a
1189 	*             DPCON object for purpose of scheduling between multiple
1190 	*             queues. The DPCON may be independently configured to
1191 	*             generate notifications. Not relevant for Tx queues.
1192 	* @hold_active: Hold active
1193 	*/
1194 	struct {
1195 		uint32_t id;
1196 		enum dpni_dest type;
1197 		char hold_active;
1198 		char stash_ctrl;
1199 	} destination;
1200 	uint8_t  options;
1201 	uint32_t fqid;
1202 	uint16_t qdbin;
1203 	uint64_t flc;
1204 	uint64_t user_context;
1205 };
1206 
1207 /**
1208  * dpni_set_queue() - Set queue parameters
1209  * @mc_io:      Pointer to MC portal's I/O object
1210  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1211  * @token:      Token of DPNI object
1212  * @type:       Type of queue
1213  * @tc:         Traffic class, in range 0 to NUM_TCS - 1
1214  * @index:      Selects the specific queue out of the set allocated for the same
1215  *              TC. Value must be in range 0 to NUM_QUEUES - 1
1216  * @queue:      Queue structure
1217  *
1218  * Return:     '0' on Success; Error code otherwise.
1219  */
1220 int dpni_set_queue(struct fsl_mc_io		*mc_io,
1221 		   uint32_t			cmd_flags,
1222 		   uint16_t			token,
1223 		   enum dpni_queue_type		type,
1224 		   uint8_t			tc,
1225 		   uint8_t			index,
1226 		   const struct dpni_queue	*queue);
1227 
1228 /**
1229  * dpni_get_queue() - Get queue parameters
1230  * @mc_io:      Pointer to MC portal's I/O object
1231  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1232  * @token:      Token of DPNI object
1233  * @type:       Type of queue
1234  * @tc:         Traffic class, in range 0 to NUM_TCS - 1
1235  * @index:      Selects the specific queue out of the set allocated for the same
1236  *              TC. Value must be in range 0 to NUM_QUEUES - 1
1237  * @queue:      Queue structure
1238  *
1239  * Return:      '0' on Success; Error code otherwise.
1240  */
1241 int dpni_get_queue(struct fsl_mc_io		*mc_io,
1242 		   uint32_t			cmd_flags,
1243 		   uint16_t			token,
1244 		   enum dpni_queue_type		type,
1245 		   uint8_t			tc,
1246 		   uint8_t			index,
1247 		   struct dpni_queue		*queue);
1248 
1249 /**
1250  * dpni_set_tx_confirmation_mode() - Set TX conf mode
1251  * @mc_io:      Pointer to MC portal's I/O object
1252  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1253  * @token:      Token of DPNI object
1254  * @mode:       DPNI confirmation mode type
1255  *
1256  * Return:      '0' on Success; Error code otherwise.
1257  */
1258 int dpni_set_tx_confirmation_mode(struct fsl_mc_io	*mc_io,
1259 				  uint32_t		cmd_flags,
1260 				  uint16_t		token,
1261 				  enum dpni_confirmation_mode mode);
1262 struct dpni_statistics {
1263 	/**
1264 	 * Page_0 statistics structure
1265 	 * @ingress_all_frames: Ingress frame count
1266 	 * @ingress_all_bytes: Ingress byte count
1267 	 * @ingress_multicast_frames: Ingress multicast frame count
1268 	 * @ingress_multicast_bytes: Ingress multicast byte count
1269 	 * @ingress_broadcast_frames: Ingress broadcast frame count
1270 	 * @ingress_broadcast_bytes: Ingress broadcast byte count
1271 	 *
1272 	 * Page_1 statistics structure
1273 	 * @egress_all_frames: Egress frame count
1274 	 * @egress_all_bytes: Egress byte count
1275 	 * @egress_multicast_frames: Egress multicast frame count
1276 	 * @egress_multicast_bytes: Egress multicast byte count
1277 	 * @egress_broadcast_frames: Egress broadcast frame count
1278 	 * @egress_broadcast_bytes: Egress broadcast byte count
1279 	 *
1280 	 * Page_2 statistics structure
1281 	 * @ingress_filtered_frames: Ingress filtered frame count
1282 	 * @ingress_discarded_frames: Ingress discarded frame count
1283 	 * @ingress_nobuffer_discards: Ingress discarded frame count due to
1284 	 *  lack of buffers.
1285 	 * @egress_discarded_frames: Egress discarded frame count
1286 	 * @egress_confirmed_frames: Egress confirmed frame count
1287 	 */
1288 
1289 	uint64_t counter0;
1290 	uint64_t counter1;
1291 	uint64_t counter2;
1292 	uint64_t counter3;
1293 	uint64_t counter4;
1294 	uint64_t counter5;
1295 	uint64_t counter6;
1296 };
1297 
1298 /**
1299  * dpni_get_statistics() - Get DPNI statistics
1300  * @mc_io:	Pointer to MC portal's I/O object
1301  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1302  * @token:	Token of DPNI object
1303  * @page:	Selects the statistics page to retrieve, see DPNI_GET_STATISTICS
1304  *		output. Pages are numbered 0 to 2.
1305  * @stat:	Structure containing the statistics
1306  *
1307  * Return:	'0' on Success; Error code otherwise.
1308  */
1309 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1310 			uint32_t cmd_flags,
1311 			uint16_t token,
1312 			uint8_t page,
1313 			struct dpni_statistics *stat);
1314 
1315 /**
1316  * dpni_reset_statistics() - Clears DPNI statistics
1317  * @mc_io:	Pointer to MC portal's I/O object
1318  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1319  * @token:	Token of DPNI object
1320  *
1321  * Return:	'0' on Success; Error code otherwise.
1322  */
1323 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1324 			  uint32_t cmd_flags,
1325 			  uint16_t token);
1326 #endif /* _FSL_DPNI_H */
1327