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