1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2013-2016 Freescale Semiconductor, Inc.
4 * Copyright 2017, 2023 NXP
5 */
6#ifndef _FSL_DPNI_H
7#define _FSL_DPNI_H
8
9/* DPNI Version */
10#define DPNI_VER_MAJOR				7
11#define DPNI_VER_MINOR				3
12
13/* Command IDs */
14#define DPNI_CMDID_OPEN				0x8011
15#define DPNI_CMDID_CLOSE			0x8001
16#define DPNI_CMDID_CREATE			0x9011
17#define DPNI_CMDID_DESTROY			0x9811
18#define DPNI_CMDID_GET_API_VERSION              0xa011
19
20#define DPNI_CMDID_ENABLE			0x0021
21#define DPNI_CMDID_DISABLE			0x0031
22#define DPNI_CMDID_GET_ATTR			0x0041
23#define DPNI_CMDID_RESET			0x0051
24
25#define DPNI_CMDID_SET_POOLS			0x2002
26#define DPNI_CMDID_SET_BUFFER_LAYOUT		0x2651
27
28#define DPNI_CMDID_GET_QDID			0x2101
29#define DPNI_CMDID_GET_TX_DATA_OFFSET		0x2121
30#define DPNI_CMDID_GET_LINK_STATE		0x2151
31#define DPNI_CMDID_SET_LINK_CFG			0x21A1
32
33#define DPNI_CMDID_ADD_MAC_ADDR			0x2261
34
35#define DPNI_CMDID_GET_STATISTICS		0x25D1
36#define DPNI_CMDID_GET_QUEUE			0x25F1
37#define DPNI_CMDID_SET_QUEUE			0x2601
38#define DPNI_CMDID_SET_TX_CONFIRMATION_MODE	0x2661
39
40/* Macros for accessing command fields smaller than 1byte */
41#define DPNI_MASK(field)	\
42	GENMASK(DPNI_##field##_SHIFT + DPNI_##field##_SIZE - 1, \
43		DPNI_##field##_SHIFT)
44#define dpni_set_field(var, field, val)	\
45	((var) |= (((val) << DPNI_##field##_SHIFT) & DPNI_MASK(field)))
46#define dpni_get_field(var, field)	\
47	(((var) & DPNI_MASK(field)) >> DPNI_##field##_SHIFT)
48
49#pragma pack(push, 1)
50struct dpni_cmd_open {
51	__le32 dpni_id;
52};
53
54struct dpni_cmd_create {
55	__le32 options;
56	u8 num_queues;
57	u8 num_tcs;
58	u8 mac_filter_entries;
59	u8 num_channels;
60	u8 vlan_filter_entries;
61	u8 pad2;
62	u8 qos_entries;
63	u8 pad3;
64	__le16 fs_entries;
65	u8 num_rx_tcs;
66	u8 pad4;
67	u8  num_cgs;
68	__le16 num_opr;
69	u8 dist_key_size;
70};
71
72struct dpni_cmd_destroy {
73	__le32 dpni_id;
74};
75
76#define DPNI_BACKUP_POOL(val, order)	(((val) & 0x1) << (order))
77
78struct dpni_cmd_pool {
79	__le16 dpbp_id;
80	u8 priority_mask;
81	u8 pad;
82};
83
84struct dpni_cmd_set_pools {
85	u8 num_dpbp;
86	u8 backup_pool_mask;
87	u8 pad;
88	u8 pool_options;
89	struct dpni_cmd_pool pool[8];
90	__le16 buffer_size[8];
91};
92
93struct dpni_rsp_get_attr {
94	/* response word 0 */
95	__le32 options;
96	u8 num_queues;
97	u8 num_rx_tcs;
98	u8 mac_filter_entries;
99	u8 num_tx_tcs;
100	/* response word 1 */
101	u8 vlan_filter_entries;
102	u8 num_channels;
103	u8 qos_entries;
104	u8 pad2;
105	__le16 fs_entries;
106	__le16 num_opr;
107	/* response word 2 */
108	u8 qos_key_size;
109	u8 fs_key_size;
110	__le16 wriop_version;
111	u8 num_cgs;
112};
113
114/* There are 3 separate commands for configuring Rx, Tx and Tx confirmation
115 * buffer layouts, but they all share the same parameters.
116 * If one of the functions changes, below structure needs to be split.
117 */
118
119#define DPNI_PASS_TS_SHIFT		0
120#define DPNI_PASS_TS_SIZE		1
121#define DPNI_PASS_PR_SHIFT		1
122#define DPNI_PASS_PR_SIZE		1
123#define DPNI_PASS_FS_SHIFT		2
124#define DPNI_PASS_FS_SIZE		1
125#define DPNI_PASS_SWO_SHIFT		3
126#define DPNI_PASS_SWO_SIZE		1
127
128struct dpni_cmd_set_buffer_layout {
129	/* cmd word 0 */
130	u8 qtype;
131	u8 pad0[3];
132	__le16 options;
133	/* from LSB: pass_timestamp:1, parser_result:1, frame_status:1 */
134	u8 flags;
135	u8 pad1;
136	/* cmd word 1 */
137	__le16 private_data_size;
138	__le16 data_align;
139	__le16 head_room;
140	__le16 tail_room;
141};
142
143struct dpni_cmd_get_qdid {
144	u8 qtype;
145};
146
147struct dpni_rsp_get_qdid {
148	__le16 qdid;
149};
150
151struct dpni_rsp_get_tx_data_offset {
152	__le16 data_offset;
153};
154
155struct dpni_cmd_set_link_cfg {
156	__le64 pad0;
157	__le32 rate;
158	__le32 pad1;
159	__le64 options;
160	__le64 advertising;
161};
162
163#define DPNI_LINK_STATE_SHIFT		0
164#define DPNI_LINK_STATE_SIZE		1
165#define DPNI_STATE_VALID_SHIFT		1
166#define DPNI_STATE_VALID_SIZE		1
167
168struct dpni_rsp_get_link_state {
169	__le32 pad0;
170	/* from LSB: up:1 */
171	u8 flags;
172	u8 pad1[3];
173	__le32 rate;
174	__le32 pad2;
175	__le64 options;
176	__le64 supported;
177	__le64 advertising;
178};
179
180struct dpni_cmd_add_mac_addr {
181	u8 flags;
182	u8 pad;
183	u8 mac_addr[6];
184	u8 tc_id;
185	u8 fq_id;
186};
187
188struct dpni_cmd_get_queue {
189	u8 qtype;
190	u8 tc;
191	u8 index;
192	u8 channel_id;
193};
194
195#define DPNI_DEST_TYPE_SHIFT		0
196#define DPNI_DEST_TYPE_SIZE		4
197#define DPNI_CGID_VALID_SHIFT		5
198#define DPNI_CGID_VALID_SIZE		1
199#define DPNI_STASH_CTRL_SHIFT		6
200#define DPNI_STASH_CTRL_SIZE		1
201#define DPNI_HOLD_ACTIVE_SHIFT		7
202#define DPNI_HOLD_ACTIVE_SIZE		1
203
204struct dpni_rsp_get_queue {
205	/* response word 0 */
206	__le64 pad0;
207	/* response word 1 */
208	__le32 dest_id;
209	__le16 pad1;
210	u8 dest_prio;
211	/* From LSB: dest_type:4, pad:1, cgid_valid:1, flc_stash_ctrl:1, hold_active:1 */
212	u8 flags;
213	/* response word 2 */
214	__le64 flc;
215	/* response word 3 */
216	__le64 user_context;
217	/* response word 4 */
218	__le32 fqid;
219	__le16 qdbin;
220	__le16 pad2;
221	/* response word 5*/
222	u8 cgid;
223};
224
225struct dpni_cmd_set_queue {
226	/* cmd word 0 */
227	u8 qtype;
228	u8 tc;
229	u8 index;
230	u8 options;
231	__le32 pad0;
232	/* cmd word 1 */
233	__le32 dest_id;
234	__le16 pad1;
235	u8 dest_prio;
236	u8 flags;
237	/* cmd word 2 */
238	__le64 flc;
239	/* cmd word 3 */
240	__le64 user_context;
241	/* cmd word 4 */
242	u8 cgid;
243	u8 channel_id;
244};
245
246struct dpni_tx_confirmation_mode {
247	u8 ceetm_ch_idx;
248	u8 pad1;
249	__le16 pad2;
250	u8 confirmation_mode;
251};
252
253struct dpni_cmd_get_statistics {
254	u8 page_number;
255	__le16 param;
256};
257
258struct dpni_rsp_get_statistics {
259	__le64 counter[7];
260};
261
262#pragma pack(pop)
263
264/**
265 * Data Path Network Interface API
266 * Contains initialization APIs and runtime control APIs for DPNI
267 */
268
269struct fsl_mc_io;
270
271/* General DPNI macros */
272
273/* Maximum number of traffic classes */
274#define DPNI_MAX_TC				8
275/* Maximum number of buffer pools per DPNI */
276#define DPNI_MAX_DPBP				8
277
278/* All traffic classes considered; see dpni_set_rx_flow() */
279#define DPNI_ALL_TCS				(u8)(-1)
280/* All flows within traffic class considered; see dpni_set_rx_flow() */
281#define DPNI_ALL_TC_FLOWS			(u16)(-1)
282/* Generate new flow ID; see dpni_set_tx_flow() */
283#define DPNI_NEW_FLOW_ID			(u16)(-1)
284/* use for common tx-conf queue; see dpni_set_tx_conf_<x>() */
285#define DPNI_COMMON_TX_CONF			(u16)(-1)
286
287int dpni_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpni_id, u16 *token);
288
289int dpni_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
290
291/* DPNI configuration options */
292
293/**
294 * Allow different distribution key profiles for different traffic classes;
295 * if not set, a single key profile is assumed
296 */
297#define DPNI_OPT_ALLOW_DIST_KEY_PER_TC		0x00000001
298
299/**
300 * Disable all non-error transmit confirmation; error frames are reported
301 * back to a common Tx error queue
302 */
303#define DPNI_OPT_TX_CONF_DISABLED		0x00000002
304
305/* Disable per-sender private Tx confirmation/error queue */
306#define DPNI_OPT_PRIVATE_TX_CONF_ERROR_DISABLED	0x00000004
307
308/**
309 * Support distribution based on hashed key;
310 * allows statistical distribution over receive queues in a traffic class
311 */
312#define DPNI_OPT_DIST_HASH			0x00000010
313
314/**
315 * Support distribution based on flow steering;
316 * allows explicit control of distribution over receive queues in a traffic
317 * class
318 */
319#define DPNI_OPT_DIST_FS			0x00000020
320
321/* Unicast filtering support */
322#define DPNI_OPT_UNICAST_FILTER			0x00000080
323/* Multicast filtering support */
324#define DPNI_OPT_MULTICAST_FILTER		0x00000100
325/* VLAN filtering support */
326#define DPNI_OPT_VLAN_FILTER			0x00000200
327/* Support IP reassembly on received packets */
328#define DPNI_OPT_IPR				0x00000800
329/* Support IP fragmentation on transmitted packets */
330#define DPNI_OPT_IPF				0x00001000
331/* VLAN manipulation support */
332#define DPNI_OPT_VLAN_MANIPULATION		0x00010000
333/* Support masking of QoS lookup keys */
334#define DPNI_OPT_QOS_MASK_SUPPORT		0x00020000
335/* Support masking of Flow Steering lookup keys */
336#define DPNI_OPT_FS_MASK_SUPPORT		0x00040000
337
338/**
339 * enum dpni_queue_type - Identifies a type of queue targeted by the command
340 * @DPNI_QUEUE_RX: Rx queue
341 * @DPNI_QUEUE_TX: Tx queue
342 * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
343 * @DPNI_QUEUE_RX_ERR: Rx error queue
344 */
345enum dpni_queue_type {
346	DPNI_QUEUE_RX,
347	DPNI_QUEUE_TX,
348	DPNI_QUEUE_TX_CONFIRM,
349	DPNI_QUEUE_RX_ERR,
350};
351
352/**
353 * struct dpni_cfg - Structure representing DPNI configuration
354 * @options: Any combination of the following options:
355 *		DPNI_OPT_TX_FRM_RELEASE
356 *		DPNI_OPT_NO_MAC_FILTER
357 *		DPNI_OPT_HAS_POLICING
358 *		DPNI_OPT_SHARED_CONGESTION
359 *		DPNI_OPT_HAS_KEY_MASKING
360 *		DPNI_OPT_NO_FS
361 *		DPNI_OPT_SINGLE_SENDER
362 *		DPNI_OPT_STASHING_DIS
363 * @fs_entries: Number of entries in the flow steering table.
364 *		This table is used to select the ingress queue for
365 *		ingress traffic, targeting a GPP core or another.
366 *		In addition it can be used to discard traffic that
367 *		matches the set rule. It is either an exact match table
368 *		or a TCAM table, depending on DPNI_OPT_ HAS_KEY_MASKING
369 *		bit in OPTIONS field. This field is ignored if
370 *		DPNI_OPT_NO_FS bit is set in OPTIONS field. Otherwise,
371 *		value 0 defaults to 64. Maximum supported value is 1024.
372 *		Note that the total number of entries is limited on the
373 *		SoC to as low as 512 entries if TCAM is used.
374 * @vlan_filter_entries: Number of entries in the VLAN address filtering
375 *		table. This is an exact match table used to filter
376 *		ingress traffic based on VLAN IDs. Value 0 disables VLAN
377 *		filtering. Maximum supported value is 16.
378 * @mac_filter_entries: Number of entries in the MAC address filtering
379 *		table. This is an exact match table and allows both
380 *		unicast and multicast entries. The primary MAC address
381 *		of the network interface is not part of this table,
382 *		this contains only entries in addition to it. This
383 *		field is ignored if DPNI_OPT_ NO_MAC_FILTER is set in
384 *		OPTIONS field. Otherwise, value 0 defaults to 80.
385 *		Maximum supported value is 80.
386 * @num_queues: Number of Tx and Rx queues used for traffic
387 *		distribution. This is orthogonal to QoS and is only
388 *		used to distribute traffic to multiple GPP cores.
389 *		This configuration affects the number of Tx queues
390 *		(logical FQs, all associated with a single CEETM queue),
391 *		Rx queues and Tx confirmation queues, if applicable.
392 *		Value 0 defaults to one queue. Maximum supported value
393 *		is 8.
394 * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
395 *		TCs can have different priority levels for the purpose
396 *		of Tx scheduling (see DPNI_SET_TX_PRIORITIES), different
397 *		BPs (DPNI_ SET_POOLS), policers. There are dedicated QM
398 *		queues for traffic classes (including class queues on
399 *		Tx). Value 0 defaults to one TC. Maximum supported value
400 *		is 16. There are maximum 16 TCs for Tx and 8 TCs for Rx.
401 *		When num_tcs>8 Tx will use this value but Rx will have
402 *		only 8 traffic classes.
403 * @num_rx_tcs: if set to other value than zero represents number
404 *		of TCs used for Rx. Maximum value is 8. If set to zero the
405 *		number of Rx TCs will be initialized with the value provided
406 *		in num_tcs parameter.
407 * @qos_entries: Number of entries in the QoS classification table. This
408 *		table is used to select the TC for ingress traffic. It
409 *		is either an exact match or a TCAM table, depending on
410 *		DPNI_OPT_ HAS_KEY_MASKING bit in OPTIONS field. This
411 *		field is ignored if the DPNI has a single TC. Otherwise,
412 *		a value of 0 defaults to 64. Maximum supported value
413 *		is 64.
414 * @num_channels: Number of egress channels used by this dpni object. If
415 *		set to zero the dpni object will use a single CEETM channel.
416 */
417struct dpni_cfg {
418	u32 options;
419	u16 fs_entries;
420	u8  vlan_filter_entries;
421	u8  mac_filter_entries;
422	u8  num_queues;
423	u8  num_tcs;
424	u8  num_rx_tcs;
425	u8  qos_entries;
426	u8  num_cgs;
427	u16 num_opr;
428	u8  dist_key_size;
429	u8  num_channels;
430};
431
432/**
433 * dpni_prepare_cfg() - function prepare parameters
434 * @cfg: cfg structure
435 * @cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
436 *
437 * This function has to be called before dpni_create()
438 */
439int dpni_prepare_cfg(const struct dpni_cfg	*cfg,
440		     u8			*cfg_buf);
441
442int dpni_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
443		const struct dpni_cfg *cfg, u32 *obj_id);
444
445int dpni_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
446		 u32 object_id);
447
448/**
449 * struct dpni_pools_cfg - Structure representing buffer pools configuration
450 * @num_dpbp:	Number of DPBPs
451 * @pool_options: Buffer assignment options
452 *                This field is a combination of DPNI_POOL_ASSOC_flags
453 * @pools:	Array of buffer pools parameters; The number of valid entries
454 *		must match 'num_dpbp' value
455 * @pools.dpbp_id:     DPBP object ID
456 * @pools.priority:    Priority mask that indicates TC's used with this buffer.
457 *		       I set to 0x00 MC will assume value 0xff.
458 * @pools.buffer_size: Buffer size
459 * @pools.backup_pool: Backup pool
460 */
461
462#define DPNI_POOL_ASSOC_QPRI	0
463#define DPNI_POOL_ASSOC_QDBIN	1
464
465struct dpni_pools_cfg {
466	u8 num_dpbp;
467	u8 pool_options;
468	struct {
469		int		dpbp_id;
470		u8		priority_mask;
471		u16	buffer_size;
472		int		backup_pool;
473	} pools[DPNI_MAX_DPBP];
474};
475
476int dpni_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
477		   const struct dpni_pools_cfg *cfg);
478
479int dpni_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
480
481int dpni_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
482
483int dpni_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
484
485/**
486 * struct dpni_attr - Structure representing DPNI attributes
487 * @options: Any combination of the following options:
488 *		DPNI_OPT_TX_FRM_RELEASE
489 *		DPNI_OPT_NO_MAC_FILTER
490 *		DPNI_OPT_HAS_POLICING
491 *		DPNI_OPT_SHARED_CONGESTION
492 *		DPNI_OPT_HAS_KEY_MASKING
493 *		DPNI_OPT_NO_FS
494 *		DPNI_OPT_STASHING_DIS
495 * @num_queues: Number of Tx and Rx queues used for traffic distribution.
496 * @num_rx_tcs: Number of RX traffic classes (TCs), reserved for the DPNI.
497 * @num_tx_tcs: Number of TX traffic classes (TCs), reserved for the DPNI.
498 * @mac_filter_entries: Number of entries in the MAC address filtering
499 *		table.
500 * @vlan_filter_entries: Number of entries in the VLAN address filtering
501 *		table.
502 * @qos_entries: Number of entries in the QoS classification table.
503 * @fs_entries: Number of entries in the flow steering table.
504 * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
505 *			than this when adding QoS entries will result
506 *			in an error.
507 * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
508 *			key larger than this when composing the hash + FS key
509 *			will result in an error.
510 * @wriop_version: Version of WRIOP HW block.
511 *			The 3 version values are stored on 6, 5, 5 bits
512 *			respectively.
513 *			Values returned:
514 *			- 0x400 - WRIOP version 1.0.0, used on LS2080 and
515 *			variants,
516 *			- 0x421 - WRIOP version 1.1.1, used on LS2088 and
517 *			variants,
518 *			- 0x422 - WRIOP version 1.1.2, used on LS1088 and
519 *			variants.
520 *			- 0xC00 - WRIOP version 3.0.0, used on LX2160 and
521 *			variants.
522 */
523struct dpni_attr {
524	u32 options;
525	u8  num_queues;
526	u8  num_rx_tcs;
527	u8  num_tx_tcs;
528	u8  mac_filter_entries;
529	u8  vlan_filter_entries;
530	u8  qos_entries;
531	u16 fs_entries;
532	u16 num_opr;
533	u8  qos_key_size;
534	u8  fs_key_size;
535	u16 wriop_version;
536	u8  num_cgs;
537	u8  num_channels;
538};
539
540int dpni_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
541			struct dpni_attr *attr);
542
543/* DPNI buffer layout modification options */
544
545/* Select to modify the time-stamp setting */
546#define DPNI_BUF_LAYOUT_OPT_TIMESTAMP		0x00000001
547/* Select to modify the parser-result setting; not applicable for Tx */
548#define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT	0x00000002
549/* Select to modify the frame-status setting */
550#define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS	0x00000004
551/* Select to modify the private-data-size setting */
552#define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE	0x00000008
553/* Select to modify the data-alignment setting */
554#define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN		0x00000010
555/* Select to modify the data-head-room setting */
556#define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM	0x00000020
557/*!< Select to modify the data-tail-room setting */
558#define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM	0x00000040
559/* Select to modify the sw-opaque value setting */
560#define DPNI_BUF_LAYOUT_OPT_SW_OPAQUE		0x00000080
561/* Select to disable Scatter Gather and use single buffer */
562#define DPNI_BUF_LAYOUT_OPT_NO_SG		0x00000100
563
564/**
565 * struct dpni_buffer_layout - Structure representing DPNI buffer layout
566 * @options:		Flags representing the suggested modifications to the
567 *			buffer layout;
568 *			Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
569 * @pass_timestamp:	Pass timestamp value
570 * @pass_parser_result:	Pass parser results
571 * @pass_frame_status:	Pass frame status
572 * @private_data_size:	Size kept for private data (in bytes)
573 * @data_align:		Data alignment
574 * @data_head_room:	Data head room
575 * @data_tail_room:	Data tail room
576 */
577struct dpni_buffer_layout {
578	u32 options;
579	int pass_timestamp;
580	int pass_parser_result;
581	int pass_frame_status;
582	int pass_sw_opaque;
583	u16 private_data_size;
584	u16 data_align;
585	u16 data_head_room;
586	u16 data_tail_room;
587};
588
589int dpni_set_buffer_layout(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
590			   enum dpni_queue_type qtype,
591			   const struct dpni_buffer_layout *layout);
592
593int dpni_get_qdid(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
594		  enum dpni_queue_type qtype, u16 *qdid);
595
596int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
597			    u16 *data_offset);
598
599/* Enable auto-negotiation */
600#define DPNI_LINK_OPT_AUTONEG		0x0000000000000001ULL
601/* Enable half-duplex mode */
602#define DPNI_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
603/* Enable pause frames */
604#define DPNI_LINK_OPT_PAUSE		0x0000000000000004ULL
605/* Enable a-symmetric pause frames */
606#define DPNI_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
607
608/**
609 * struct - Structure representing DPNI link configuration
610 * @rate: Rate
611 * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
612 * @advertising: Speeds that are advertised for autoneg (bitmap)
613 */
614struct dpni_link_cfg {
615	u32 rate;
616	u64 options;
617	u64 advertising;
618};
619
620int dpni_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
621		      const struct dpni_link_cfg *cfg);
622
623/**
624 * struct dpni_link_state - Structure representing DPNI link state
625 * @rate:	Rate
626 * @options:	Mask of available options; use 'DPNI_LINK_OPT_<X>' values
627 * @up:		Link state; '0' for down, '1' for up
628 * @state_valid: Ignore/Update the state of the link
629 * @supported: Speeds capability of the phy (bitmap)
630 * @advertising: Speeds that are advertised for autoneg (bitmap)
631 */
632struct dpni_link_state {
633	u32 rate;
634	u64 options;
635	int up;
636	int     state_valid;
637	u64 supported;
638	u64 advertising;
639};
640
641int dpni_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
642			struct dpni_link_state *state);
643
644int dpni_add_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
645		      const u8 mac_addr[6], u8 flags,
646		      u8 tc_id, u8 flow_id);
647
648int dpni_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
649			 u16 *major_ver, u16 *minor_ver);
650
651/**
652 * enum dpni_dest - DPNI destination types
653 * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
654 *		does not generate FQDAN notifications; user is expected to
655 *		dequeue from the queue based on polling or other user-defined
656 *		method
657 * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
658 *		notifications to the specified DPIO; user is expected to dequeue
659 *		from the queue only after notification is received
660 * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
661 *		FQDAN notifications, but is connected to the specified DPCON
662 *		object; user is expected to dequeue from the DPCON channel
663 */
664enum dpni_dest {
665	DPNI_DEST_NONE = 0,
666	DPNI_DEST_DPIO = 1,
667	DPNI_DEST_DPCON = 2
668};
669
670/* DPNI Tx flow modification options */
671
672/* Select to modify the settings for dedicate Tx confirmation/error */
673#define DPNI_TX_FLOW_OPT_TX_CONF_ERROR	0x00000001
674/*!< Select to modify the L3 checksum generation setting */
675#define DPNI_TX_FLOW_OPT_L3_CHKSUM_GEN	0x00000010
676/*!< Select to modify the L4 checksum generation setting */
677#define DPNI_TX_FLOW_OPT_L4_CHKSUM_GEN	0x00000020
678
679/**
680 * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
681 * confirmation
682 * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
683 * an affine Tx Confirmation queue
684 * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
685 * confirmation queue
686 * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
687 * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
688 * buffers will be leaked
689 */
690enum dpni_confirmation_mode {
691	DPNI_CONF_AFFINE,
692	DPNI_CONF_SINGLE,
693	DPNI_CONF_DISABLE,
694};
695
696/**
697 * stashes the whole annotation area (up to 192 bytes)
698 */
699#define DPNI_FLC_STASH_FRAME_ANNOTATION	0x00000001
700
701/**
702 * struct dpni_queue - Queue structure
703 * @destination - Destination structure
704 * @destination.id:	ID of the destination, only relevant if DEST_TYPE is > 0.
705 *	Identifies either a DPIO or a DPCON object.
706 *	Not relevant for Tx queues.
707 * @destination.type:	May be one of the following:
708 *	0 - No destination, queue can be manually
709 *		queried, but will not push traffic or
710 *		notifications to a DPIO;
711 *	1 - The destination is a DPIO. When traffic
712 *		becomes available in the queue a FQDAN
713 *		(FQ data available notification) will be
714 *		generated to selected DPIO;
715 *	2 - The destination is a DPCON. The queue is
716 *		associated with a DPCON object for the
717 *		purpose of scheduling between multiple
718 *		queues. The DPCON may be independently
719 *		configured to generate notifications.
720 *		Not relevant for Tx queues.
721 * @destination.hold_active: Hold active, maintains a queue scheduled for longer
722 *	in a DPIO during dequeue to reduce spread of traffic.
723 *	Only relevant if queues are
724 *	not affined to a single DPIO.
725 * @user_context: User data, presented to the user along with any frames
726 *	from this queue. Not relevant for Tx queues.
727 * @flc: FD FLow Context structure
728 * @flc.value: Default FLC value for traffic dequeued from
729 *      this queue.  Please check description of FD
730 *      structure for more information.
731 *      Note that FLC values set using dpni_add_fs_entry,
732 *      if any, take precedence over values per queue.
733 * @flc.stash_control: Boolean, indicates whether the 6 lowest
734 *      - significant bits are used for stash control.
735 *      significant bits are used for stash control.  If set, the 6
736 *      least significant bits in value are interpreted as follows:
737 *      - bits 0-1: indicates the number of 64 byte units of context
738 *      that are stashed.  FLC value is interpreted as a memory address
739 *      in this case, excluding the 6 LS bits.
740 *      - bits 2-3: indicates the number of 64 byte units of frame
741 *      annotation to be stashed.  Annotation is placed at FD[ADDR].
742 *      - bits 4-5: indicates the number of 64 byte units of frame
743 *      data to be stashed.  Frame data is placed at FD[ADDR] +
744 *      FD[OFFSET].
745 *      For more details check the Frame Descriptor section in the
746 *      hardware documentation.
747 *@cgid :indicate the cgid to set relative to dpni
748 */
749struct dpni_queue {
750	struct {
751		u16 id;
752		enum dpni_dest type;
753		char hold_active;
754		u8 priority;
755	} destination;
756	u64 user_context;
757	struct {
758		u64 value;
759		char stash_control;
760	} flc;
761	int cgid;
762};
763
764/**
765 * struct dpni_queue_id - Queue identification, used for enqueue commands
766 *				or queue control
767 * @fqid:	FQID used for enqueueing to and/or configuration of this
768 *			specific FQ
769 * @qdbin:	Queueing bin, used to enqueue using QDID, DQBIN, QPRI.
770 *			Only relevant for Tx queues.
771 */
772struct dpni_queue_id {
773	u32 fqid;
774	u16 qdbin;
775};
776
777int dpni_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
778		   enum dpni_queue_type qtype, u16 param, u8 index,
779		   u8 options, const struct dpni_queue *queue);
780
781int dpni_get_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
782		   enum dpni_queue_type qtype, u16 param, u8 index,
783		   struct dpni_queue *queue, struct dpni_queue_id *qid);
784
785int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
786				  u8 ceetm_ch_idx, enum dpni_confirmation_mode mode);
787
788#define DPNI_STATISTICS_CNT		7
789
790/**
791 * union dpni_statistics - Union describing the DPNI statistics
792 * @page_0: Page_0 statistics structure
793 * @page_0.ingress_all_frames: Ingress frame count
794 * @page_0.ingress_all_bytes: Ingress byte count
795 * @page_0.ingress_multicast_frames: Ingress multicast frame count
796 * @page_0.ingress_multicast_bytes: Ingress multicast byte count
797 * @page_0.ingress_broadcast_frames: Ingress broadcast frame count
798 * @page_0.ingress_broadcast_bytes: Ingress broadcast byte count
799 * @page_1: Page_1 statistics structure
800 * @page_1.egress_all_frames: Egress frame count
801 * @page_1.egress_all_bytes: Egress byte count
802 * @page_1.egress_multicast_frames: Egress multicast frame count
803 * @page_1.egress_multicast_bytes: Egress multicast byte count
804 * @page_1.egress_broadcast_frames: Egress broadcast frame count
805 * @page_1.egress_broadcast_bytes: Egress broadcast byte count
806 * @page_2: Page_2 statistics structure
807 * @page_2.ingress_filtered_frames: Ingress filtered frame count
808 * @page_2.ingress_discarded_frames: Ingress discarded frame count
809 * @page_2.ingress_nobuffer_discards: Ingress discarded frame count due to
810 *	lack of buffers
811 * @page_2.egress_discarded_frames: Egress discarded frame count
812 * @page_2.egress_confirmed_frames: Egress confirmed frame count
813 * @page_3: Page_3 statistics structure
814 * @page_3.egress_dequeue_bytes: Cumulative count of the number of bytes
815 *	dequeued from egress FQs
816 * @page_3.egress_dequeue_frames: Cumulative count of the number of frames
817 *	dequeued from egress FQs
818 * @page_3.egress_reject_bytes: Cumulative count of the number of bytes in
819 *	egress frames whose enqueue was rejected
820 * @page_3.egress_reject_frames: Cumulative count of the number of egress
821 *	frames whose enqueue was rejected
822 * @page_4: Page_4 statistics structure: congestion points
823 * @page_4.cgr_reject_frames: number of rejected frames due to congestion point
824 * @page_4.cgr_reject_bytes: number of rejected bytes due to congestion point
825 * @page_5: Page_5 statistics structure: policer
826 * @page_5.policer_cnt_red: NUmber of red colored frames
827 * @page_5.policer_cnt_yellow: number of yellow colored frames
828 * @page_5.policer_cnt_green: number of green colored frames
829 * @page_5.policer_cnt_re_red: number of recolored red frames
830 * @page_5.policer_cnt_re_yellow: number of recolored yellow frames
831 * @page_6: Page_6 statistics structure
832 * @page_6.tx_pending_frames: total number of frames pending in egress FQs
833 * @raw: raw statistics structure, used to index counters
834 */
835union dpni_statistics {
836	struct {
837		u64 ingress_all_frames;
838		u64 ingress_all_bytes;
839		u64 ingress_multicast_frames;
840		u64 ingress_multicast_bytes;
841		u64 ingress_broadcast_frames;
842		u64 ingress_broadcast_bytes;
843	} page_0;
844	struct {
845		u64 egress_all_frames;
846		u64 egress_all_bytes;
847		u64 egress_multicast_frames;
848		u64 egress_multicast_bytes;
849		u64 egress_broadcast_frames;
850		u64 egress_broadcast_bytes;
851	} page_1;
852	struct {
853		u64 ingress_filtered_frames;
854		u64 ingress_discarded_frames;
855		u64 ingress_nobuffer_discards;
856		u64 egress_discarded_frames;
857		u64 egress_confirmed_frames;
858	} page_2;
859	struct {
860		u64 egress_dequeue_bytes;
861		u64 egress_dequeue_frames;
862		u64 egress_reject_bytes;
863		u64 egress_reject_frames;
864	} page_3;
865	struct {
866		u64 cgr_reject_frames;
867		u64 cgr_reject_bytes;
868	} page_4;
869	struct {
870		u64 policer_cnt_red;
871		u64 policer_cnt_yellow;
872		u64 policer_cnt_green;
873		u64 policer_cnt_re_red;
874		u64 policer_cnt_re_yellow;
875	} page_5;
876	struct {
877		u64 tx_pending_frames;
878	} page_6;
879	struct {
880		u64 counter[DPNI_STATISTICS_CNT];
881	} raw;
882};
883
884int dpni_get_statistics(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
885			u8 page, u16 param, union dpni_statistics *stat);
886#endif /* _FSL_DPNI_H */
887