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