1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3  * Copyright 2016 NXP
4  * Copyright 2020 NXP
5  */
6 #ifndef __FSL_DPNI_H
7 #define __FSL_DPNI_H
8 
9 #include "dpkg.h"
10 
11 struct fsl_mc_io;
12 
13 /* Data Path Network Interface API
14  * Contains initialization APIs and runtime control APIs for DPNI
15  */
16 
17 /** General DPNI macros */
18 
19 /**
20  * DPNI_MAX_TC - Maximum number of traffic classes
21  */
22 #define DPNI_MAX_TC				8
23 /**
24  * DPNI_MAX_DPBP - Maximum number of buffer pools per DPNI
25  */
26 #define DPNI_MAX_DPBP				8
27 
28 /**
29  * DPNI_ALL_TCS - All traffic classes considered; see dpni_set_queue()
30  */
31 #define DPNI_ALL_TCS				(u8)(-1)
32 /**
33  * DPNI_ALL_TC_FLOWS - All flows within traffic class considered; see
34  * dpni_set_queue()
35  */
36 #define DPNI_ALL_TC_FLOWS			(u16)(-1)
37 /**
38  * DPNI_NEW_FLOW_ID - Generate new flow ID; see dpni_set_queue()
39  */
40 #define DPNI_NEW_FLOW_ID			(u16)(-1)
41 
42 /**
43  * DPNI_OPT_TX_FRM_RELEASE - Tx traffic is always released to a buffer pool on
44  * transmit, there are no resources allocated to have the frames confirmed back
45  * to the source after transmission.
46  */
47 #define DPNI_OPT_TX_FRM_RELEASE			0x000001
48 /**
49  * DPNI_OPT_NO_MAC_FILTER - Disables support for MAC address filtering for
50  * addresses other than primary MAC address. This affects both unicast and
51  * multicast. Promiscuous mode can still be enabled/disabled for both unicast
52  * and multicast. If promiscuous mode is disabled, only traffic matching the
53  * primary MAC address will be accepted.
54  */
55 #define DPNI_OPT_NO_MAC_FILTER			0x000002
56 /**
57  * DPNI_OPT_HAS_POLICING - Allocate policers for this DPNI. They can be used to
58  * rate-limit traffic per traffic class (TC) basis.
59  */
60 #define DPNI_OPT_HAS_POLICING			0x000004
61 /**
62  * DPNI_OPT_SHARED_CONGESTION - Congestion can be managed in several ways,
63  * allowing the buffer pool to deplete on ingress, taildrop on each queue or
64  * use congestion groups for sets of queues. If set, it configures a single
65  * congestion groups across all TCs.  If reset, a congestion group is allocated
66  * for each TC. Only relevant if the DPNI has multiple traffic classes.
67  */
68 #define DPNI_OPT_SHARED_CONGESTION		0x000008
69 /**
70  * DPNI_OPT_HAS_KEY_MASKING - Enables TCAM for Flow Steering and QoS look-ups.
71  * If not specified, all look-ups are exact match. Note that TCAM is not
72  * available on LS1088 and its variants. Setting this bit on these SoCs will
73  * trigger an error.
74  */
75 #define DPNI_OPT_HAS_KEY_MASKING		0x000010
76 /**
77  * DPNI_OPT_NO_FS - Disables the flow steering table.
78  */
79 #define DPNI_OPT_NO_FS				0x000020
80 /**
81  * DPNI_OPT_SHARED_FS - Flow steering table is shared between all traffic
82  * classes
83  */
84 #define DPNI_OPT_SHARED_FS			0x001000
85 
86 int dpni_open(struct fsl_mc_io	*mc_io,
87 	      u32		cmd_flags,
88 	      int		dpni_id,
89 	      u16		*token);
90 
91 int dpni_close(struct fsl_mc_io	*mc_io,
92 	       u32		cmd_flags,
93 	       u16		token);
94 
95 /**
96  * struct dpni_pools_cfg - Structure representing buffer pools configuration
97  * @num_dpbp: Number of DPBPs
98  * @pools: Array of buffer pools parameters; The number of valid entries
99  *	must match 'num_dpbp' value
100  * @pools.dpbp_id: DPBP object ID
101  * @pools.buffer_size: Buffer size
102  * @pools.backup_pool: Backup pool
103  */
104 struct dpni_pools_cfg {
105 	u8		num_dpbp;
106 	struct {
107 		int	dpbp_id;
108 		u16	buffer_size;
109 		int	backup_pool;
110 	} pools[DPNI_MAX_DPBP];
111 };
112 
113 int dpni_set_pools(struct fsl_mc_io		*mc_io,
114 		   u32				cmd_flags,
115 		   u16				token,
116 		   const struct dpni_pools_cfg	*cfg);
117 
118 int dpni_enable(struct fsl_mc_io	*mc_io,
119 		u32			cmd_flags,
120 		u16			token);
121 
122 int dpni_disable(struct fsl_mc_io	*mc_io,
123 		 u32			cmd_flags,
124 		 u16			token);
125 
126 int dpni_is_enabled(struct fsl_mc_io	*mc_io,
127 		    u32			cmd_flags,
128 		    u16			token,
129 		    int			*en);
130 
131 int dpni_reset(struct fsl_mc_io	*mc_io,
132 	       u32		cmd_flags,
133 	       u16		token);
134 
135 /* DPNI IRQ Index and Events */
136 
137 #define DPNI_IRQ_INDEX				0
138 
139 /* DPNI_IRQ_EVENT_LINK_CHANGED - indicates a change in link state */
140 #define DPNI_IRQ_EVENT_LINK_CHANGED		0x00000001
141 
142 /* DPNI_IRQ_EVENT_ENDPOINT_CHANGED - indicates a change in endpoint */
143 #define DPNI_IRQ_EVENT_ENDPOINT_CHANGED		0x00000002
144 
145 int dpni_set_irq_enable(struct fsl_mc_io	*mc_io,
146 			u32			cmd_flags,
147 			u16			token,
148 			u8			irq_index,
149 			u8			en);
150 
151 int dpni_get_irq_enable(struct fsl_mc_io	*mc_io,
152 			u32			cmd_flags,
153 			u16			token,
154 			u8			irq_index,
155 			u8			*en);
156 
157 int dpni_set_irq_mask(struct fsl_mc_io	*mc_io,
158 		      u32		cmd_flags,
159 		      u16		token,
160 		      u8		irq_index,
161 		      u32		mask);
162 
163 int dpni_get_irq_mask(struct fsl_mc_io	*mc_io,
164 		      u32		cmd_flags,
165 		      u16		token,
166 		      u8		irq_index,
167 		      u32		*mask);
168 
169 int dpni_get_irq_status(struct fsl_mc_io	*mc_io,
170 			u32			cmd_flags,
171 			u16			token,
172 			u8			irq_index,
173 			u32			*status);
174 
175 int dpni_clear_irq_status(struct fsl_mc_io	*mc_io,
176 			  u32			cmd_flags,
177 			  u16			token,
178 			  u8			irq_index,
179 			  u32			status);
180 
181 /**
182  * struct dpni_attr - Structure representing DPNI attributes
183  * @options: Any combination of the following options:
184  *		DPNI_OPT_TX_FRM_RELEASE
185  *		DPNI_OPT_NO_MAC_FILTER
186  *		DPNI_OPT_HAS_POLICING
187  *		DPNI_OPT_SHARED_CONGESTION
188  *		DPNI_OPT_HAS_KEY_MASKING
189  *		DPNI_OPT_NO_FS
190  * @num_queues: Number of Tx and Rx queues used for traffic distribution.
191  * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
192  * @mac_filter_entries: Number of entries in the MAC address filtering table.
193  * @vlan_filter_entries: Number of entries in the VLAN address filtering table.
194  * @qos_entries: Number of entries in the QoS classification table.
195  * @fs_entries: Number of entries in the flow steering table.
196  * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
197  *		than this when adding QoS entries will result in an error.
198  * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
199  *		key larger than this when composing the hash + FS key will
200  *		result in an error.
201  * @wriop_version: Version of WRIOP HW block. The 3 version values are stored
202  *		on 6, 5, 5 bits respectively.
203  */
204 struct dpni_attr {
205 	u32 options;
206 	u8 num_queues;
207 	u8 num_tcs;
208 	u8 mac_filter_entries;
209 	u8 vlan_filter_entries;
210 	u8 qos_entries;
211 	u16 fs_entries;
212 	u8 qos_key_size;
213 	u8 fs_key_size;
214 	u16 wriop_version;
215 };
216 
217 int dpni_get_attributes(struct fsl_mc_io	*mc_io,
218 			u32			cmd_flags,
219 			u16			token,
220 			struct dpni_attr	*attr);
221 
222 /* DPNI errors */
223 
224 /**
225  * DPNI_ERROR_EOFHE - Extract out of frame header error
226  */
227 #define DPNI_ERROR_EOFHE	0x00020000
228 /**
229  * DPNI_ERROR_FLE - Frame length error
230  */
231 #define DPNI_ERROR_FLE		0x00002000
232 /**
233  * DPNI_ERROR_FPE - Frame physical error
234  */
235 #define DPNI_ERROR_FPE		0x00001000
236 /**
237  * DPNI_ERROR_PHE - Parsing header error
238  */
239 #define DPNI_ERROR_PHE		0x00000020
240 /**
241  * DPNI_ERROR_L3CE - Parser L3 checksum error
242  */
243 #define DPNI_ERROR_L3CE		0x00000004
244 /**
245  * DPNI_ERROR_L4CE - Parser L3 checksum error
246  */
247 #define DPNI_ERROR_L4CE		0x00000001
248 
249 /**
250  * enum dpni_error_action - Defines DPNI behavior for errors
251  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
252  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
253  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
254  */
255 enum dpni_error_action {
256 	DPNI_ERROR_ACTION_DISCARD = 0,
257 	DPNI_ERROR_ACTION_CONTINUE = 1,
258 	DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
259 };
260 
261 /**
262  * struct dpni_error_cfg - Structure representing DPNI errors treatment
263  * @errors: Errors mask; use 'DPNI_ERROR__<X>
264  * @error_action: The desired action for the errors mask
265  * @set_frame_annotation: Set to '1' to mark the errors in frame annotation
266  *		status (FAS); relevant only for the non-discard action
267  */
268 struct dpni_error_cfg {
269 	u32			errors;
270 	enum dpni_error_action	error_action;
271 	int			set_frame_annotation;
272 };
273 
274 int dpni_set_errors_behavior(struct fsl_mc_io		*mc_io,
275 			     u32			cmd_flags,
276 			     u16			token,
277 			     struct dpni_error_cfg	*cfg);
278 
279 /* DPNI buffer layout modification options */
280 
281 /**
282  * DPNI_BUF_LAYOUT_OPT_TIMESTAMP - Select to modify the time-stamp setting
283  */
284 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP		0x00000001
285 /**
286  * DPNI_BUF_LAYOUT_OPT_PARSER_RESULT - Select to modify the parser-result
287  * setting; not applicable for Tx
288  */
289 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT	0x00000002
290 /**
291  * DPNI_BUF_LAYOUT_OPT_FRAME_STATUS - Select to modify the frame-status setting
292  */
293 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS	0x00000004
294 /**
295  * DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE - Select to modify the private-data-size setting
296  */
297 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE	0x00000008
298 /**
299  * DPNI_BUF_LAYOUT_OPT_DATA_ALIGN - Select to modify the data-alignment setting
300  */
301 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN		0x00000010
302 /**
303  * DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM - Select to modify the data-head-room setting
304  */
305 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM	0x00000020
306 /**
307  * DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM - Select to modify the data-tail-room setting
308  */
309 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM	0x00000040
310 
311 /**
312  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
313  * @options: Flags representing the suggested modifications to the buffer
314  *		layout; Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
315  * @pass_timestamp: Pass timestamp value
316  * @pass_parser_result: Pass parser results
317  * @pass_frame_status: Pass frame status
318  * @private_data_size: Size kept for private data (in bytes)
319  * @data_align: Data alignment
320  * @data_head_room: Data head room
321  * @data_tail_room: Data tail room
322  */
323 struct dpni_buffer_layout {
324 	u32	options;
325 	int	pass_timestamp;
326 	int	pass_parser_result;
327 	int	pass_frame_status;
328 	u16	private_data_size;
329 	u16	data_align;
330 	u16	data_head_room;
331 	u16	data_tail_room;
332 };
333 
334 /**
335  * enum dpni_queue_type - Identifies a type of queue targeted by the command
336  * @DPNI_QUEUE_RX: Rx queue
337  * @DPNI_QUEUE_TX: Tx queue
338  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
339  * @DPNI_QUEUE_RX_ERR: Rx error queue
340  */
341 enum dpni_queue_type {
342 	DPNI_QUEUE_RX,
343 	DPNI_QUEUE_TX,
344 	DPNI_QUEUE_TX_CONFIRM,
345 	DPNI_QUEUE_RX_ERR,
346 };
347 
348 int dpni_get_buffer_layout(struct fsl_mc_io		*mc_io,
349 			   u32				cmd_flags,
350 			   u16				token,
351 			   enum dpni_queue_type		qtype,
352 			   struct dpni_buffer_layout	*layout);
353 
354 int dpni_set_buffer_layout(struct fsl_mc_io		   *mc_io,
355 			   u32				   cmd_flags,
356 			   u16				   token,
357 			   enum dpni_queue_type		   qtype,
358 			   const struct dpni_buffer_layout *layout);
359 
360 /**
361  * enum dpni_offload - Identifies a type of offload targeted by the command
362  * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
363  * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
364  * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
365  * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
366  */
367 enum dpni_offload {
368 	DPNI_OFF_RX_L3_CSUM,
369 	DPNI_OFF_RX_L4_CSUM,
370 	DPNI_OFF_TX_L3_CSUM,
371 	DPNI_OFF_TX_L4_CSUM,
372 };
373 
374 int dpni_set_offload(struct fsl_mc_io	*mc_io,
375 		     u32		cmd_flags,
376 		     u16		token,
377 		     enum dpni_offload	type,
378 		     u32		config);
379 
380 int dpni_get_offload(struct fsl_mc_io	*mc_io,
381 		     u32		cmd_flags,
382 		     u16		token,
383 		     enum dpni_offload	type,
384 		     u32		*config);
385 
386 int dpni_get_qdid(struct fsl_mc_io	*mc_io,
387 		  u32			cmd_flags,
388 		  u16			token,
389 		  enum dpni_queue_type	qtype,
390 		  u16			*qdid);
391 
392 int dpni_get_tx_data_offset(struct fsl_mc_io	*mc_io,
393 			    u32			cmd_flags,
394 			    u16			token,
395 			    u16			*data_offset);
396 
397 #define DPNI_STATISTICS_CNT		7
398 
399 /**
400  * union dpni_statistics - Union describing the DPNI statistics
401  * @page_0: Page_0 statistics structure
402  * @page_0.ingress_all_frames: Ingress frame count
403  * @page_0.ingress_all_bytes: Ingress byte count
404  * @page_0.ingress_multicast_frames: Ingress multicast frame count
405  * @page_0.ingress_multicast_bytes: Ingress multicast byte count
406  * @page_0.ingress_broadcast_frames: Ingress broadcast frame count
407  * @page_0.ingress_broadcast_bytes: Ingress broadcast byte count
408  * @page_1: Page_1 statistics structure
409  * @page_1.egress_all_frames: Egress frame count
410  * @page_1.egress_all_bytes: Egress byte count
411  * @page_1.egress_multicast_frames: Egress multicast frame count
412  * @page_1.egress_multicast_bytes: Egress multicast byte count
413  * @page_1.egress_broadcast_frames: Egress broadcast frame count
414  * @page_1.egress_broadcast_bytes: Egress broadcast byte count
415  * @page_2: Page_2 statistics structure
416  * @page_2.ingress_filtered_frames: Ingress filtered frame count
417  * @page_2.ingress_discarded_frames: Ingress discarded frame count
418  * @page_2.ingress_nobuffer_discards: Ingress discarded frame count due to
419  *	lack of buffers
420  * @page_2.egress_discarded_frames: Egress discarded frame count
421  * @page_2.egress_confirmed_frames: Egress confirmed frame count
422  * @page_3: Page_3 statistics structure
423  * @page_3.egress_dequeue_bytes: Cumulative count of the number of bytes
424  *	dequeued from egress FQs
425  * @page_3.egress_dequeue_frames: Cumulative count of the number of frames
426  *	dequeued from egress FQs
427  * @page_3.egress_reject_bytes: Cumulative count of the number of bytes in
428  *	egress frames whose enqueue was rejected
429  * @page_3.egress_reject_frames: Cumulative count of the number of egress
430  *	frames whose enqueue was rejected
431  * @page_4: Page_4 statistics structure: congestion points
432  * @page_4.cgr_reject_frames: number of rejected frames due to congestion point
433  * @page_4.cgr_reject_bytes: number of rejected bytes due to congestion point
434  * @page_5: Page_5 statistics structure: policer
435  * @page_5.policer_cnt_red: NUmber of red colored frames
436  * @page_5.policer_cnt_yellow: number of yellow colored frames
437  * @page_5.policer_cnt_green: number of green colored frames
438  * @page_5.policer_cnt_re_red: number of recolored red frames
439  * @page_5.policer_cnt_re_yellow: number of recolored yellow frames
440  * @page_6: Page_6 statistics structure
441  * @page_6.tx_pending_frames: total number of frames pending in egress FQs
442  * @raw: raw statistics structure, used to index counters
443  */
444 union dpni_statistics {
445 	struct {
446 		u64 ingress_all_frames;
447 		u64 ingress_all_bytes;
448 		u64 ingress_multicast_frames;
449 		u64 ingress_multicast_bytes;
450 		u64 ingress_broadcast_frames;
451 		u64 ingress_broadcast_bytes;
452 	} page_0;
453 	struct {
454 		u64 egress_all_frames;
455 		u64 egress_all_bytes;
456 		u64 egress_multicast_frames;
457 		u64 egress_multicast_bytes;
458 		u64 egress_broadcast_frames;
459 		u64 egress_broadcast_bytes;
460 	} page_1;
461 	struct {
462 		u64 ingress_filtered_frames;
463 		u64 ingress_discarded_frames;
464 		u64 ingress_nobuffer_discards;
465 		u64 egress_discarded_frames;
466 		u64 egress_confirmed_frames;
467 	} page_2;
468 	struct {
469 		u64 egress_dequeue_bytes;
470 		u64 egress_dequeue_frames;
471 		u64 egress_reject_bytes;
472 		u64 egress_reject_frames;
473 	} page_3;
474 	struct {
475 		u64 cgr_reject_frames;
476 		u64 cgr_reject_bytes;
477 	} page_4;
478 	struct {
479 		u64 policer_cnt_red;
480 		u64 policer_cnt_yellow;
481 		u64 policer_cnt_green;
482 		u64 policer_cnt_re_red;
483 		u64 policer_cnt_re_yellow;
484 	} page_5;
485 	struct {
486 		u64 tx_pending_frames;
487 	} page_6;
488 	struct {
489 		u64 counter[DPNI_STATISTICS_CNT];
490 	} raw;
491 };
492 
493 int dpni_get_statistics(struct fsl_mc_io	*mc_io,
494 			u32			cmd_flags,
495 			u16			token,
496 			u8			page,
497 			union dpni_statistics	*stat);
498 
499 #define DPNI_LINK_OPT_AUTONEG		0x0000000000000001ULL
500 #define DPNI_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
501 #define DPNI_LINK_OPT_PAUSE		0x0000000000000004ULL
502 #define DPNI_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
503 #define DPNI_LINK_OPT_PFC_PAUSE		0x0000000000000010ULL
504 
505 /**
506  * struct dpni_link_cfg - Structure representing DPNI link configuration
507  * @rate: Rate
508  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
509  */
510 struct dpni_link_cfg {
511 	u32 rate;
512 	u64 options;
513 };
514 
515 int dpni_set_link_cfg(struct fsl_mc_io			*mc_io,
516 		      u32				cmd_flags,
517 		      u16				token,
518 		      const struct dpni_link_cfg	*cfg);
519 
520 int dpni_get_link_cfg(struct fsl_mc_io			*mc_io,
521 		      u32				cmd_flags,
522 		      u16				token,
523 		      struct dpni_link_cfg		*cfg);
524 
525 /**
526  * struct dpni_link_state - Structure representing DPNI link state
527  * @rate: Rate
528  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
529  * @up: Link state; '0' for down, '1' for up
530  */
531 struct dpni_link_state {
532 	u32	rate;
533 	u64	options;
534 	int	up;
535 };
536 
537 int dpni_get_link_state(struct fsl_mc_io	*mc_io,
538 			u32			cmd_flags,
539 			u16			token,
540 			struct dpni_link_state	*state);
541 
542 int dpni_set_max_frame_length(struct fsl_mc_io	*mc_io,
543 			      u32		cmd_flags,
544 			      u16		token,
545 			      u16		max_frame_length);
546 
547 int dpni_get_max_frame_length(struct fsl_mc_io	*mc_io,
548 			      u32		cmd_flags,
549 			      u16		token,
550 			      u16		*max_frame_length);
551 
552 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
553 			       u32		cmd_flags,
554 			       u16		token,
555 			       int		en);
556 
557 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
558 			       u32		cmd_flags,
559 			       u16		token,
560 			       int		*en);
561 
562 int dpni_set_unicast_promisc(struct fsl_mc_io	*mc_io,
563 			     u32		cmd_flags,
564 			     u16		token,
565 			     int		en);
566 
567 int dpni_get_unicast_promisc(struct fsl_mc_io	*mc_io,
568 			     u32		cmd_flags,
569 			     u16		token,
570 			     int		*en);
571 
572 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
573 			      u32		cmd_flags,
574 			      u16		token,
575 			      const u8		mac_addr[6]);
576 
577 int dpni_get_primary_mac_addr(struct fsl_mc_io	*mc_io,
578 			      u32		cmd_flags,
579 			      u16		token,
580 			      u8		mac_addr[6]);
581 
582 int dpni_get_port_mac_addr(struct fsl_mc_io	*mc_io,
583 			   u32			cm_flags,
584 			   u16			token,
585 			   u8			mac_addr[6]);
586 
587 int dpni_add_mac_addr(struct fsl_mc_io	*mc_io,
588 		      u32		cmd_flags,
589 		      u16		token,
590 		      const u8		mac_addr[6]);
591 
592 int dpni_remove_mac_addr(struct fsl_mc_io	*mc_io,
593 			 u32			cmd_flags,
594 			 u16			token,
595 			 const u8		mac_addr[6]);
596 
597 int dpni_clear_mac_filters(struct fsl_mc_io	*mc_io,
598 			   u32			cmd_flags,
599 			   u16			token,
600 			   int			unicast,
601 			   int			multicast);
602 
603 /**
604  * enum dpni_dist_mode - DPNI distribution mode
605  * @DPNI_DIST_MODE_NONE: No distribution
606  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
607  *		the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
608  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
609  *	 the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
610  */
611 enum dpni_dist_mode {
612 	DPNI_DIST_MODE_NONE = 0,
613 	DPNI_DIST_MODE_HASH = 1,
614 	DPNI_DIST_MODE_FS = 2
615 };
616 
617 /**
618  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
619  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
620  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
621  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
622  */
623 enum dpni_fs_miss_action {
624 	DPNI_FS_MISS_DROP = 0,
625 	DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
626 	DPNI_FS_MISS_HASH = 2
627 };
628 
629 /**
630  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
631  * @miss_action: Miss action selection
632  * @default_flow_id: Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
633  */
634 struct dpni_fs_tbl_cfg {
635 	enum dpni_fs_miss_action	miss_action;
636 	u16				default_flow_id;
637 };
638 
639 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
640 			 u8 *key_cfg_buf);
641 
642 /**
643  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
644  * @dist_size: Set the distribution size;
645  *	supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
646  *	112,128,192,224,256,384,448,512,768,896,1024
647  * @dist_mode: Distribution mode
648  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
649  *		the extractions to be used for the distribution key by calling
650  *		dpni_prepare_key_cfg() relevant only when
651  *		'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
652  * @fs_cfg: Flow Steering table configuration; only relevant if
653  *		'dist_mode = DPNI_DIST_MODE_FS'
654  */
655 struct dpni_rx_tc_dist_cfg {
656 	u16			dist_size;
657 	enum dpni_dist_mode	dist_mode;
658 	u64			key_cfg_iova;
659 	struct dpni_fs_tbl_cfg	fs_cfg;
660 };
661 
662 int dpni_set_rx_tc_dist(struct fsl_mc_io			*mc_io,
663 			u32					cmd_flags,
664 			u16					token,
665 			u8					tc_id,
666 			const struct dpni_rx_tc_dist_cfg	*cfg);
667 
668 /**
669  * DPNI_FS_MISS_DROP - When used for fs_miss_flow_id in function
670  * dpni_set_rx_dist, will signal to dpni to drop all unclassified frames
671  */
672 #define DPNI_FS_MISS_DROP		((uint16_t)-1)
673 
674 /**
675  * struct dpni_rx_dist_cfg - Rx distribution configuration
676  * @dist_size:	distribution size
677  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
678  *		the extractions to be used for the distribution key by calling
679  *		dpni_prepare_key_cfg(); relevant only when enable!=0 otherwise
680  *		it can be '0'
681  * @enable: enable/disable the distribution.
682  * @tc: TC id for which distribution is set
683  * @fs_miss_flow_id: when packet misses all rules from flow steering table and
684  *		hash is disabled it will be put into this queue id; use
685  *		DPNI_FS_MISS_DROP to drop frames. The value of this field is
686  *		used only when flow steering distribution is enabled and hash
687  *		distribution is disabled
688  */
689 struct dpni_rx_dist_cfg {
690 	u16 dist_size;
691 	u64 key_cfg_iova;
692 	u8 enable;
693 	u8 tc;
694 	u16 fs_miss_flow_id;
695 };
696 
697 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
698 			u32 cmd_flags,
699 			u16 token,
700 			const struct dpni_rx_dist_cfg *cfg);
701 
702 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
703 			  u32 cmd_flags,
704 			  u16 token,
705 			  const struct dpni_rx_dist_cfg *cfg);
706 
707 /**
708  * struct dpni_qos_tbl_cfg - Structure representing QOS table configuration
709  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
710  *		key extractions to be used as the QoS criteria by calling
711  *		dpkg_prepare_key_cfg()
712  * @discard_on_miss: Set to '1' to discard frames in case of no match (miss);
713  *		'0' to use the 'default_tc' in such cases
714  * @default_tc: Used in case of no-match and 'discard_on_miss'= 0
715  */
716 struct dpni_qos_tbl_cfg {
717 	u64 key_cfg_iova;
718 	int discard_on_miss;
719 	u8 default_tc;
720 };
721 
722 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
723 		       u32 cmd_flags,
724 		       u16 token,
725 		       const struct dpni_qos_tbl_cfg *cfg);
726 
727 /**
728  * enum dpni_dest - DPNI destination types
729  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
730  *		does not generate FQDAN notifications; user is expected to
731  *		dequeue from the queue based on polling or other user-defined
732  *		method
733  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
734  *		notifications to the specified DPIO; user is expected to dequeue
735  *		from the queue only after notification is received
736  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
737  *		FQDAN notifications, but is connected to the specified DPCON
738  *		object; user is expected to dequeue from the DPCON channel
739  */
740 enum dpni_dest {
741 	DPNI_DEST_NONE = 0,
742 	DPNI_DEST_DPIO = 1,
743 	DPNI_DEST_DPCON = 2
744 };
745 
746 /**
747  * struct dpni_queue - Queue structure
748  * @destination: - Destination structure
749  * @destination.id: ID of the destination, only relevant if DEST_TYPE is > 0.
750  *	Identifies either a DPIO or a DPCON object.
751  *	Not relevant for Tx queues.
752  * @destination.type:	May be one of the following:
753  *	0 - No destination, queue can be manually
754  *		queried, but will not push traffic or
755  *		notifications to a DPIO;
756  *	1 - The destination is a DPIO. When traffic
757  *		becomes available in the queue a FQDAN
758  *		(FQ data available notification) will be
759  *		generated to selected DPIO;
760  *	2 - The destination is a DPCON. The queue is
761  *		associated with a DPCON object for the
762  *		purpose of scheduling between multiple
763  *		queues. The DPCON may be independently
764  *		configured to generate notifications.
765  *		Not relevant for Tx queues.
766  * @destination.hold_active: Hold active, maintains a queue scheduled for longer
767  *	in a DPIO during dequeue to reduce spread of traffic.
768  *	Only relevant if queues are
769  *	not affined to a single DPIO.
770  * @user_context: User data, presented to the user along with any frames
771  *	from this queue. Not relevant for Tx queues.
772  * @flc: FD FLow Context structure
773  * @flc.value: Default FLC value for traffic dequeued from
774  *      this queue.  Please check description of FD
775  *      structure for more information.
776  *      Note that FLC values set using dpni_add_fs_entry,
777  *      if any, take precedence over values per queue.
778  * @flc.stash_control: Boolean, indicates whether the 6 lowest
779  *      - significant bits are used for stash control.
780  *      significant bits are used for stash control.  If set, the 6
781  *      least significant bits in value are interpreted as follows:
782  *      - bits 0-1: indicates the number of 64 byte units of context
783  *      that are stashed.  FLC value is interpreted as a memory address
784  *      in this case, excluding the 6 LS bits.
785  *      - bits 2-3: indicates the number of 64 byte units of frame
786  *      annotation to be stashed.  Annotation is placed at FD[ADDR].
787  *      - bits 4-5: indicates the number of 64 byte units of frame
788  *      data to be stashed.  Frame data is placed at FD[ADDR] +
789  *      FD[OFFSET].
790  *      For more details check the Frame Descriptor section in the
791  *      hardware documentation.
792  */
793 struct dpni_queue {
794 	struct {
795 		u16 id;
796 		enum dpni_dest type;
797 		char hold_active;
798 		u8 priority;
799 	} destination;
800 	u64 user_context;
801 	struct {
802 		u64 value;
803 		char stash_control;
804 	} flc;
805 };
806 
807 /**
808  * struct dpni_queue_id - Queue identification, used for enqueue commands
809  *			or queue control
810  * @fqid: FQID used for enqueueing to and/or configuration of this specific FQ
811  * @qdbin: Queueing bin, used to enqueue using QDID, DQBIN, QPRI. Only relevant
812  *		for Tx queues.
813  */
814 struct dpni_queue_id {
815 	u32 fqid;
816 	u16 qdbin;
817 };
818 
819 /* Set User Context */
820 #define DPNI_QUEUE_OPT_USER_CTX		0x00000001
821 #define DPNI_QUEUE_OPT_DEST		0x00000002
822 #define DPNI_QUEUE_OPT_FLC		0x00000004
823 #define DPNI_QUEUE_OPT_HOLD_ACTIVE	0x00000008
824 
825 int dpni_set_queue(struct fsl_mc_io	*mc_io,
826 		   u32			cmd_flags,
827 		   u16			token,
828 		   enum dpni_queue_type	qtype,
829 		   u8			tc,
830 		   u8			index,
831 		   u8			options,
832 		   const struct dpni_queue *queue);
833 
834 int dpni_get_queue(struct fsl_mc_io	*mc_io,
835 		   u32			cmd_flags,
836 		   u16			token,
837 		   enum dpni_queue_type	qtype,
838 		   u8			tc,
839 		   u8			index,
840 		   struct dpni_queue	*queue,
841 		   struct dpni_queue_id	*qid);
842 
843 /**
844  * enum dpni_congestion_unit - DPNI congestion units
845  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
846  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
847  */
848 enum dpni_congestion_unit {
849 	DPNI_CONGESTION_UNIT_BYTES = 0,
850 	DPNI_CONGESTION_UNIT_FRAMES
851 };
852 
853 /**
854  * enum dpni_congestion_point - Structure representing congestion point
855  * @DPNI_CP_QUEUE: Set taildrop per queue, identified by QUEUE_TYPE, TC and
856  *		QUEUE_INDEX
857  * @DPNI_CP_GROUP: Set taildrop per queue group. Depending on options used to
858  *		define the DPNI this can be either per TC (default) or per
859  *		interface (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
860  *		QUEUE_INDEX is ignored if this type is used.
861  */
862 enum dpni_congestion_point {
863 	DPNI_CP_QUEUE,
864 	DPNI_CP_GROUP,
865 };
866 
867 /**
868  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
869  * @dest_type:	Destination type
870  * @dest_id:	Either DPIO ID or DPCON ID, depending on the destination type
871  * @priority:	Priority selection within the DPIO or DPCON channel; valid
872  *		values are 0-1 or 0-7, depending on the number of priorities
873  *		in that channel; not relevant for 'DPNI_DEST_NONE' option
874  */
875 struct dpni_dest_cfg {
876 	enum dpni_dest dest_type;
877 	int dest_id;
878 	u8 priority;
879 };
880 
881 /* DPNI congestion options */
882 
883 /**
884  * DPNI_CONG_OPT_FLOW_CONTROL - This congestion will trigger flow control or
885  * priority flow control.  This will have effect only if flow control is
886  * enabled with dpni_set_link_cfg().
887  */
888 #define DPNI_CONG_OPT_FLOW_CONTROL		0x00000040
889 
890 /**
891  * struct dpni_congestion_notification_cfg - congestion notification
892  *					configuration
893  * @units: Units type
894  * @threshold_entry: Above this threshold we enter a congestion state.
895  *		set it to '0' to disable it
896  * @threshold_exit: Below this threshold we exit the congestion state.
897  * @message_ctx: The context that will be part of the CSCN message
898  * @message_iova: I/O virtual address (must be in DMA-able memory),
899  *		must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>'
900  *		is contained in 'options'
901  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
902  * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
903  */
904 
905 struct dpni_congestion_notification_cfg {
906 	enum dpni_congestion_unit units;
907 	u32 threshold_entry;
908 	u32 threshold_exit;
909 	u64 message_ctx;
910 	u64 message_iova;
911 	struct dpni_dest_cfg dest_cfg;
912 	u16 notification_mode;
913 };
914 
915 int dpni_set_congestion_notification(
916 			struct fsl_mc_io *mc_io,
917 			u32 cmd_flags,
918 			u16 token,
919 			enum dpni_queue_type qtype,
920 			u8 tc_id,
921 			const struct dpni_congestion_notification_cfg *cfg);
922 
923 /**
924  * struct dpni_taildrop - Structure representing the taildrop
925  * @enable:	Indicates whether the taildrop is active or not.
926  * @units:	Indicates the unit of THRESHOLD. Queue taildrop only supports
927  *		byte units, this field is ignored and assumed = 0 if
928  *		CONGESTION_POINT is 0.
929  * @threshold:	Threshold value, in units identified by UNITS field. Value 0
930  *		cannot be used as a valid taildrop threshold, THRESHOLD must
931  *		be > 0 if the taildrop is enabled.
932  */
933 struct dpni_taildrop {
934 	char enable;
935 	enum dpni_congestion_unit units;
936 	u32 threshold;
937 };
938 
939 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
940 		      u32 cmd_flags,
941 		      u16 token,
942 		      enum dpni_congestion_point cg_point,
943 		      enum dpni_queue_type q_type,
944 		      u8 tc,
945 		      u8 q_index,
946 		      struct dpni_taildrop *taildrop);
947 
948 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
949 		      u32 cmd_flags,
950 		      u16 token,
951 		      enum dpni_congestion_point cg_point,
952 		      enum dpni_queue_type q_type,
953 		      u8 tc,
954 		      u8 q_index,
955 		      struct dpni_taildrop *taildrop);
956 
957 /**
958  * struct dpni_rule_cfg - Rule configuration for table lookup
959  * @key_iova: I/O virtual address of the key (must be in DMA-able memory)
960  * @mask_iova: I/O virtual address of the mask (must be in DMA-able memory)
961  * @key_size: key and mask size (in bytes)
962  */
963 struct dpni_rule_cfg {
964 	u64	key_iova;
965 	u64	mask_iova;
966 	u8	key_size;
967 };
968 
969 /**
970  * DPNI_FS_OPT_DISCARD - Discard matching traffic. If set, this takes
971  * precedence over any other configuration and matching traffic is always
972  * discarded.
973  */
974  #define DPNI_FS_OPT_DISCARD            0x1
975 
976 /**
977  * DPNI_FS_OPT_SET_FLC - Set FLC value. If set, flc member of struct
978  * dpni_fs_action_cfg is used to override the FLC value set per queue.
979  * For more details check the Frame Descriptor section in the hardware
980  * documentation.
981  */
982 #define DPNI_FS_OPT_SET_FLC            0x2
983 
984 /**
985  * DPNI_FS_OPT_SET_STASH_CONTROL - Indicates whether the 6 lowest significant
986  * bits of FLC are used for stash control. If set, the 6 least significant bits
987  * in value are interpreted as follows:
988  *     - bits 0-1: indicates the number of 64 byte units of context that are
989  *     stashed. FLC value is interpreted as a memory address in this case,
990  *     excluding the 6 LS bits.
991  *     - bits 2-3: indicates the number of 64 byte units of frame annotation
992  *     to be stashed. Annotation is placed at FD[ADDR].
993  *     - bits 4-5: indicates the number of 64 byte units of frame data to be
994  *     stashed. Frame data is placed at FD[ADDR] + FD[OFFSET].
995  * This flag is ignored if DPNI_FS_OPT_SET_FLC is not specified.
996  */
997 #define DPNI_FS_OPT_SET_STASH_CONTROL  0x4
998 
999 /**
1000  * struct dpni_fs_action_cfg - Action configuration for table look-up
1001  * @flc:	FLC value for traffic matching this rule. Please check the
1002  *		Frame Descriptor section in the hardware documentation for
1003  *		more information.
1004  * @flow_id:	Identifies the Rx queue used for matching traffic. Supported
1005  *		values are in range 0 to num_queue-1.
1006  * @options:	Any combination of DPNI_FS_OPT_ values.
1007  */
1008 struct dpni_fs_action_cfg {
1009 	u64 flc;
1010 	u16 flow_id;
1011 	u16 options;
1012 };
1013 
1014 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1015 		      u32 cmd_flags,
1016 		      u16 token,
1017 		      u8 tc_id,
1018 		      u16 index,
1019 		      const struct dpni_rule_cfg *cfg,
1020 		      const struct dpni_fs_action_cfg *action);
1021 
1022 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1023 			 u32 cmd_flags,
1024 			 u16 token,
1025 			 u8 tc_id,
1026 			 const struct dpni_rule_cfg *cfg);
1027 
1028 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1029 		       u32 cmd_flags,
1030 		       u16 token,
1031 		       const struct dpni_rule_cfg *cfg,
1032 		       u8 tc_id,
1033 		       u16 index);
1034 
1035 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1036 			  u32 cmd_flags,
1037 			  u16 token,
1038 			  const struct dpni_rule_cfg *cfg);
1039 
1040 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1041 			 u32 cmd_flags,
1042 			 u16 token);
1043 
1044 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1045 			 u32 cmd_flags,
1046 			 u16 *major_ver,
1047 			 u16 *minor_ver);
1048 /**
1049  * struct dpni_tx_shaping_cfg - Structure representing DPNI tx shaping configuration
1050  * @rate_limit:		Rate in Mbps
1051  * @max_burst_size:	Burst size in bytes (up to 64KB)
1052  */
1053 struct dpni_tx_shaping_cfg {
1054 	u32 rate_limit;
1055 	u16 max_burst_size;
1056 };
1057 
1058 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
1059 			u32 cmd_flags,
1060 			u16 token,
1061 			const struct dpni_tx_shaping_cfg *tx_cr_shaper,
1062 			const struct dpni_tx_shaping_cfg *tx_er_shaper,
1063 			int coupled);
1064 
1065 /**
1066  * struct dpni_single_step_cfg - configure single step PTP (IEEE 1588)
1067  * @en:		enable single step PTP. When enabled the PTPv1 functionality
1068  *		will not work. If the field is zero, offset and ch_update
1069  *		parameters will be ignored
1070  * @offset:	start offset from the beginning of the frame where
1071  *		timestamp field is found. The offset must respect all MAC
1072  *		headers, VLAN tags and other protocol headers
1073  * @ch_update:	when set UDP checksum will be updated inside packet
1074  * @peer_delay:	For peer-to-peer transparent clocks add this value to the
1075  *		correction field in addition to the transient time update.
1076  *		The value expresses nanoseconds.
1077  * @ptp_onestep_reg_base: 1588 SINGLE_STEP register base address. This address
1078  *			  is used to update directly the register contents.
1079  *			  User has to create an address mapping for it.
1080  *
1081  *
1082  */
1083 struct dpni_single_step_cfg {
1084 	u8	en;
1085 	u8	ch_update;
1086 	u16	offset;
1087 	u32	peer_delay;
1088 	u32	ptp_onestep_reg_base;
1089 };
1090 
1091 int dpni_set_single_step_cfg(struct fsl_mc_io *mc_io,
1092 			     u32 cmd_flags,
1093 			     u16 token,
1094 			     struct dpni_single_step_cfg *ptp_cfg);
1095 
1096 int dpni_get_single_step_cfg(struct fsl_mc_io *mc_io,
1097 			     u32 cmd_flags,
1098 			     u16 token,
1099 			     struct dpni_single_step_cfg *ptp_cfg);
1100 
1101 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1102 			    u32 en);
1103 
1104 int dpni_add_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1105 		     u16 vlan_id, u8 flags, u8 tc_id, u8 flow_id);
1106 
1107 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1108 			u16 vlan_id);
1109 
1110 #endif /* __FSL_DPNI_H */
1111