xref: /linux/drivers/net/ethernet/freescale/dpaa2/dpni.h (revision b8d312aa075f33282565467662c4628dae0a2aff)
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  * @raw: raw statistics structure, used to index counters
420  */
421 union dpni_statistics {
422 	struct {
423 		u64 ingress_all_frames;
424 		u64 ingress_all_bytes;
425 		u64 ingress_multicast_frames;
426 		u64 ingress_multicast_bytes;
427 		u64 ingress_broadcast_frames;
428 		u64 ingress_broadcast_bytes;
429 	} page_0;
430 	struct {
431 		u64 egress_all_frames;
432 		u64 egress_all_bytes;
433 		u64 egress_multicast_frames;
434 		u64 egress_multicast_bytes;
435 		u64 egress_broadcast_frames;
436 		u64 egress_broadcast_bytes;
437 	} page_1;
438 	struct {
439 		u64 ingress_filtered_frames;
440 		u64 ingress_discarded_frames;
441 		u64 ingress_nobuffer_discards;
442 		u64 egress_discarded_frames;
443 		u64 egress_confirmed_frames;
444 	} page_2;
445 	struct {
446 		u64 counter[DPNI_STATISTICS_CNT];
447 	} raw;
448 };
449 
450 int dpni_get_statistics(struct fsl_mc_io	*mc_io,
451 			u32			cmd_flags,
452 			u16			token,
453 			u8			page,
454 			union dpni_statistics	*stat);
455 
456 /**
457  * Enable auto-negotiation
458  */
459 #define DPNI_LINK_OPT_AUTONEG		0x0000000000000001ULL
460 /**
461  * Enable half-duplex mode
462  */
463 #define DPNI_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
464 /**
465  * Enable pause frames
466  */
467 #define DPNI_LINK_OPT_PAUSE		0x0000000000000004ULL
468 /**
469  * Enable a-symmetric pause frames
470  */
471 #define DPNI_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
472 
473 /**
474  * struct - Structure representing DPNI link configuration
475  * @rate: Rate
476  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
477  */
478 struct dpni_link_cfg {
479 	u32 rate;
480 	u64 options;
481 };
482 
483 int dpni_set_link_cfg(struct fsl_mc_io			*mc_io,
484 		      u32				cmd_flags,
485 		      u16				token,
486 		      const struct dpni_link_cfg	*cfg);
487 
488 /**
489  * struct dpni_link_state - Structure representing DPNI link state
490  * @rate: Rate
491  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
492  * @up: Link state; '0' for down, '1' for up
493  */
494 struct dpni_link_state {
495 	u32	rate;
496 	u64	options;
497 	int	up;
498 };
499 
500 int dpni_get_link_state(struct fsl_mc_io	*mc_io,
501 			u32			cmd_flags,
502 			u16			token,
503 			struct dpni_link_state	*state);
504 
505 int dpni_set_max_frame_length(struct fsl_mc_io	*mc_io,
506 			      u32		cmd_flags,
507 			      u16		token,
508 			      u16		max_frame_length);
509 
510 int dpni_get_max_frame_length(struct fsl_mc_io	*mc_io,
511 			      u32		cmd_flags,
512 			      u16		token,
513 			      u16		*max_frame_length);
514 
515 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
516 			       u32		cmd_flags,
517 			       u16		token,
518 			       int		en);
519 
520 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
521 			       u32		cmd_flags,
522 			       u16		token,
523 			       int		*en);
524 
525 int dpni_set_unicast_promisc(struct fsl_mc_io	*mc_io,
526 			     u32		cmd_flags,
527 			     u16		token,
528 			     int		en);
529 
530 int dpni_get_unicast_promisc(struct fsl_mc_io	*mc_io,
531 			     u32		cmd_flags,
532 			     u16		token,
533 			     int		*en);
534 
535 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
536 			      u32		cmd_flags,
537 			      u16		token,
538 			      const u8		mac_addr[6]);
539 
540 int dpni_get_primary_mac_addr(struct fsl_mc_io	*mc_io,
541 			      u32		cmd_flags,
542 			      u16		token,
543 			      u8		mac_addr[6]);
544 
545 int dpni_get_port_mac_addr(struct fsl_mc_io	*mc_io,
546 			   u32			cm_flags,
547 			   u16			token,
548 			   u8			mac_addr[6]);
549 
550 int dpni_add_mac_addr(struct fsl_mc_io	*mc_io,
551 		      u32		cmd_flags,
552 		      u16		token,
553 		      const u8		mac_addr[6]);
554 
555 int dpni_remove_mac_addr(struct fsl_mc_io	*mc_io,
556 			 u32			cmd_flags,
557 			 u16			token,
558 			 const u8		mac_addr[6]);
559 
560 int dpni_clear_mac_filters(struct fsl_mc_io	*mc_io,
561 			   u32			cmd_flags,
562 			   u16			token,
563 			   int			unicast,
564 			   int			multicast);
565 
566 /**
567  * enum dpni_dist_mode - DPNI distribution mode
568  * @DPNI_DIST_MODE_NONE: No distribution
569  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
570  *		the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
571  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
572  *	 the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
573  */
574 enum dpni_dist_mode {
575 	DPNI_DIST_MODE_NONE = 0,
576 	DPNI_DIST_MODE_HASH = 1,
577 	DPNI_DIST_MODE_FS = 2
578 };
579 
580 /**
581  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
582  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
583  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
584  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
585  */
586 enum dpni_fs_miss_action {
587 	DPNI_FS_MISS_DROP = 0,
588 	DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
589 	DPNI_FS_MISS_HASH = 2
590 };
591 
592 /**
593  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
594  * @miss_action: Miss action selection
595  * @default_flow_id: Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
596  */
597 struct dpni_fs_tbl_cfg {
598 	enum dpni_fs_miss_action	miss_action;
599 	u16				default_flow_id;
600 };
601 
602 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
603 			 u8 *key_cfg_buf);
604 
605 /**
606  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
607  * @dist_size: Set the distribution size;
608  *	supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
609  *	112,128,192,224,256,384,448,512,768,896,1024
610  * @dist_mode: Distribution mode
611  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
612  *		the extractions to be used for the distribution key by calling
613  *		dpni_prepare_key_cfg() relevant only when
614  *		'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
615  * @fs_cfg: Flow Steering table configuration; only relevant if
616  *		'dist_mode = DPNI_DIST_MODE_FS'
617  */
618 struct dpni_rx_tc_dist_cfg {
619 	u16			dist_size;
620 	enum dpni_dist_mode	dist_mode;
621 	u64			key_cfg_iova;
622 	struct dpni_fs_tbl_cfg	fs_cfg;
623 };
624 
625 int dpni_set_rx_tc_dist(struct fsl_mc_io			*mc_io,
626 			u32					cmd_flags,
627 			u16					token,
628 			u8					tc_id,
629 			const struct dpni_rx_tc_dist_cfg	*cfg);
630 
631 /**
632  * When used for fs_miss_flow_id in function dpni_set_rx_dist,
633  * will signal to dpni to drop all unclassified frames
634  */
635 #define DPNI_FS_MISS_DROP		((uint16_t)-1)
636 
637 /**
638  * struct dpni_rx_dist_cfg - Rx distribution configuration
639  * @dist_size:	distribution size
640  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
641  *		the extractions to be used for the distribution key by calling
642  *		dpni_prepare_key_cfg(); relevant only when enable!=0 otherwise
643  *		it can be '0'
644  * @enable: enable/disable the distribution.
645  * @tc: TC id for which distribution is set
646  * @fs_miss_flow_id: when packet misses all rules from flow steering table and
647  *		hash is disabled it will be put into this queue id; use
648  *		DPNI_FS_MISS_DROP to drop frames. The value of this field is
649  *		used only when flow steering distribution is enabled and hash
650  *		distribution is disabled
651  */
652 struct dpni_rx_dist_cfg {
653 	u16 dist_size;
654 	u64 key_cfg_iova;
655 	u8 enable;
656 	u8 tc;
657 	u16 fs_miss_flow_id;
658 };
659 
660 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
661 			u32 cmd_flags,
662 			u16 token,
663 			const struct dpni_rx_dist_cfg *cfg);
664 
665 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
666 			  u32 cmd_flags,
667 			  u16 token,
668 			  const struct dpni_rx_dist_cfg *cfg);
669 
670 /**
671  * enum dpni_dest - DPNI destination types
672  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
673  *		does not generate FQDAN notifications; user is expected to
674  *		dequeue from the queue based on polling or other user-defined
675  *		method
676  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
677  *		notifications to the specified DPIO; user is expected to dequeue
678  *		from the queue only after notification is received
679  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
680  *		FQDAN notifications, but is connected to the specified DPCON
681  *		object; user is expected to dequeue from the DPCON channel
682  */
683 enum dpni_dest {
684 	DPNI_DEST_NONE = 0,
685 	DPNI_DEST_DPIO = 1,
686 	DPNI_DEST_DPCON = 2
687 };
688 
689 /**
690  * struct dpni_queue - Queue structure
691  * @destination - Destination structure
692  * @destination.id: ID of the destination, only relevant if DEST_TYPE is > 0.
693  *	Identifies either a DPIO or a DPCON object.
694  *	Not relevant for Tx queues.
695  * @destination.type:	May be one of the following:
696  *	0 - No destination, queue can be manually
697  *		queried, but will not push traffic or
698  *		notifications to a DPIO;
699  *	1 - The destination is a DPIO. When traffic
700  *		becomes available in the queue a FQDAN
701  *		(FQ data available notification) will be
702  *		generated to selected DPIO;
703  *	2 - The destination is a DPCON. The queue is
704  *		associated with a DPCON object for the
705  *		purpose of scheduling between multiple
706  *		queues. The DPCON may be independently
707  *		configured to generate notifications.
708  *		Not relevant for Tx queues.
709  * @destination.hold_active: Hold active, maintains a queue scheduled for longer
710  *	in a DPIO during dequeue to reduce spread of traffic.
711  *	Only relevant if queues are
712  *	not affined to a single DPIO.
713  * @user_context: User data, presented to the user along with any frames
714  *	from this queue. Not relevant for Tx queues.
715  * @flc: FD FLow Context structure
716  * @flc.value: Default FLC value for traffic dequeued from
717  *      this queue.  Please check description of FD
718  *      structure for more information.
719  *      Note that FLC values set using dpni_add_fs_entry,
720  *      if any, take precedence over values per queue.
721  * @flc.stash_control: Boolean, indicates whether the 6 lowest
722  *      - significant bits are used for stash control.
723  *      significant bits are used for stash control.  If set, the 6
724  *      least significant bits in value are interpreted as follows:
725  *      - bits 0-1: indicates the number of 64 byte units of context
726  *      that are stashed.  FLC value is interpreted as a memory address
727  *      in this case, excluding the 6 LS bits.
728  *      - bits 2-3: indicates the number of 64 byte units of frame
729  *      annotation to be stashed.  Annotation is placed at FD[ADDR].
730  *      - bits 4-5: indicates the number of 64 byte units of frame
731  *      data to be stashed.  Frame data is placed at FD[ADDR] +
732  *      FD[OFFSET].
733  *      For more details check the Frame Descriptor section in the
734  *      hardware documentation.
735  */
736 struct dpni_queue {
737 	struct {
738 		u16 id;
739 		enum dpni_dest type;
740 		char hold_active;
741 		u8 priority;
742 	} destination;
743 	u64 user_context;
744 	struct {
745 		u64 value;
746 		char stash_control;
747 	} flc;
748 };
749 
750 /**
751  * struct dpni_queue_id - Queue identification, used for enqueue commands
752  *			or queue control
753  * @fqid: FQID used for enqueueing to and/or configuration of this specific FQ
754  * @qdbin: Queueing bin, used to enqueue using QDID, DQBIN, QPRI. Only relevant
755  *		for Tx queues.
756  */
757 struct dpni_queue_id {
758 	u32 fqid;
759 	u16 qdbin;
760 };
761 
762 /**
763  * Set User Context
764  */
765 #define DPNI_QUEUE_OPT_USER_CTX		0x00000001
766 #define DPNI_QUEUE_OPT_DEST		0x00000002
767 #define DPNI_QUEUE_OPT_FLC		0x00000004
768 #define DPNI_QUEUE_OPT_HOLD_ACTIVE	0x00000008
769 
770 int dpni_set_queue(struct fsl_mc_io	*mc_io,
771 		   u32			cmd_flags,
772 		   u16			token,
773 		   enum dpni_queue_type	qtype,
774 		   u8			tc,
775 		   u8			index,
776 		   u8			options,
777 		   const struct dpni_queue *queue);
778 
779 int dpni_get_queue(struct fsl_mc_io	*mc_io,
780 		   u32			cmd_flags,
781 		   u16			token,
782 		   enum dpni_queue_type	qtype,
783 		   u8			tc,
784 		   u8			index,
785 		   struct dpni_queue	*queue,
786 		   struct dpni_queue_id	*qid);
787 
788 /**
789  * enum dpni_congestion_unit - DPNI congestion units
790  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
791  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
792  */
793 enum dpni_congestion_unit {
794 	DPNI_CONGESTION_UNIT_BYTES = 0,
795 	DPNI_CONGESTION_UNIT_FRAMES
796 };
797 
798 /**
799  * enum dpni_congestion_point - Structure representing congestion point
800  * @DPNI_CP_QUEUE: Set taildrop per queue, identified by QUEUE_TYPE, TC and
801  *		QUEUE_INDEX
802  * @DPNI_CP_GROUP: Set taildrop per queue group. Depending on options used to
803  *		define the DPNI this can be either per TC (default) or per
804  *		interface (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
805  *		QUEUE_INDEX is ignored if this type is used.
806  */
807 enum dpni_congestion_point {
808 	DPNI_CP_QUEUE,
809 	DPNI_CP_GROUP,
810 };
811 
812 /**
813  * struct dpni_taildrop - Structure representing the taildrop
814  * @enable:	Indicates whether the taildrop is active or not.
815  * @units:	Indicates the unit of THRESHOLD. Queue taildrop only supports
816  *		byte units, this field is ignored and assumed = 0 if
817  *		CONGESTION_POINT is 0.
818  * @threshold:	Threshold value, in units identified by UNITS field. Value 0
819  *		cannot be used as a valid taildrop threshold, THRESHOLD must
820  *		be > 0 if the taildrop is enabled.
821  */
822 struct dpni_taildrop {
823 	char enable;
824 	enum dpni_congestion_unit units;
825 	u32 threshold;
826 };
827 
828 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
829 		      u32 cmd_flags,
830 		      u16 token,
831 		      enum dpni_congestion_point cg_point,
832 		      enum dpni_queue_type q_type,
833 		      u8 tc,
834 		      u8 q_index,
835 		      struct dpni_taildrop *taildrop);
836 
837 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
838 		      u32 cmd_flags,
839 		      u16 token,
840 		      enum dpni_congestion_point cg_point,
841 		      enum dpni_queue_type q_type,
842 		      u8 tc,
843 		      u8 q_index,
844 		      struct dpni_taildrop *taildrop);
845 
846 /**
847  * struct dpni_rule_cfg - Rule configuration for table lookup
848  * @key_iova: I/O virtual address of the key (must be in DMA-able memory)
849  * @mask_iova: I/O virtual address of the mask (must be in DMA-able memory)
850  * @key_size: key and mask size (in bytes)
851  */
852 struct dpni_rule_cfg {
853 	u64	key_iova;
854 	u64	mask_iova;
855 	u8	key_size;
856 };
857 
858 /**
859  * Discard matching traffic. If set, this takes precedence over any other
860  * configuration and matching traffic is always discarded.
861  */
862  #define DPNI_FS_OPT_DISCARD            0x1
863 
864 /**
865  * Set FLC value. If set, flc member of struct dpni_fs_action_cfg is used to
866  * override the FLC value set per queue.
867  * For more details check the Frame Descriptor section in the hardware
868  * documentation.
869  */
870 #define DPNI_FS_OPT_SET_FLC            0x2
871 
872 /**
873  * Indicates whether the 6 lowest significant bits of FLC are used for stash
874  * control. If set, the 6 least significant bits in value are interpreted as
875  * follows:
876  *     - bits 0-1: indicates the number of 64 byte units of context that are
877  *     stashed. FLC value is interpreted as a memory address in this case,
878  *     excluding the 6 LS bits.
879  *     - bits 2-3: indicates the number of 64 byte units of frame annotation
880  *     to be stashed. Annotation is placed at FD[ADDR].
881  *     - bits 4-5: indicates the number of 64 byte units of frame data to be
882  *     stashed. Frame data is placed at FD[ADDR] + FD[OFFSET].
883  * This flag is ignored if DPNI_FS_OPT_SET_FLC is not specified.
884  */
885 #define DPNI_FS_OPT_SET_STASH_CONTROL  0x4
886 
887 /**
888  * struct dpni_fs_action_cfg - Action configuration for table look-up
889  * @flc:	FLC value for traffic matching this rule. Please check the
890  *		Frame Descriptor section in the hardware documentation for
891  *		more information.
892  * @flow_id:	Identifies the Rx queue used for matching traffic. Supported
893  *		values are in range 0 to num_queue-1.
894  * @options:	Any combination of DPNI_FS_OPT_ values.
895  */
896 struct dpni_fs_action_cfg {
897 	u64 flc;
898 	u16 flow_id;
899 	u16 options;
900 };
901 
902 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
903 		      u32 cmd_flags,
904 		      u16 token,
905 		      u8 tc_id,
906 		      u16 index,
907 		      const struct dpni_rule_cfg *cfg,
908 		      const struct dpni_fs_action_cfg *action);
909 
910 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
911 			 u32 cmd_flags,
912 			 u16 token,
913 			 u8 tc_id,
914 			 const struct dpni_rule_cfg *cfg);
915 
916 int dpni_get_api_version(struct fsl_mc_io *mc_io,
917 			 u32 cmd_flags,
918 			 u16 *major_ver,
919 			 u16 *minor_ver);
920 
921 #endif /* __FSL_DPNI_H */
922