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