xref: /freebsd/sys/dev/dpaa2/dpaa2_ni.h (revision 58983e4b0253ad38a3e1ef2166fedd3133fdb552)
1ba7319e9SDmitry Salychev /*-
2ba7319e9SDmitry Salychev  * SPDX-License-Identifier: BSD-2-Clause
3ba7319e9SDmitry Salychev  *
4*58983e4bSDmitry Salychev  * Copyright © 2021-2023 Dmitry Salychev
5ba7319e9SDmitry Salychev  * Copyright © 2022 Mathew McBride
6ba7319e9SDmitry Salychev  *
7ba7319e9SDmitry Salychev  * Redistribution and use in source and binary forms, with or without
8ba7319e9SDmitry Salychev  * modification, are permitted provided that the following conditions
9ba7319e9SDmitry Salychev  * are met:
10ba7319e9SDmitry Salychev  * 1. Redistributions of source code must retain the above copyright
11ba7319e9SDmitry Salychev  *    notice, this list of conditions and the following disclaimer.
12ba7319e9SDmitry Salychev  * 2. Redistributions in binary form must reproduce the above copyright
13ba7319e9SDmitry Salychev  *    notice, this list of conditions and the following disclaimer in the
14ba7319e9SDmitry Salychev  *    documentation and/or other materials provided with the distribution.
15ba7319e9SDmitry Salychev  *
16ba7319e9SDmitry Salychev  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ba7319e9SDmitry Salychev  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ba7319e9SDmitry Salychev  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ba7319e9SDmitry Salychev  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ba7319e9SDmitry Salychev  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ba7319e9SDmitry Salychev  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ba7319e9SDmitry Salychev  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ba7319e9SDmitry Salychev  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ba7319e9SDmitry Salychev  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ba7319e9SDmitry Salychev  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ba7319e9SDmitry Salychev  * SUCH DAMAGE.
27ba7319e9SDmitry Salychev  */
28ba7319e9SDmitry Salychev 
29ba7319e9SDmitry Salychev #ifndef	_DPAA2_NI_H
30ba7319e9SDmitry Salychev #define	_DPAA2_NI_H
31ba7319e9SDmitry Salychev 
32ba7319e9SDmitry Salychev #include <sys/rman.h>
33ba7319e9SDmitry Salychev #include <sys/bus.h>
34ba7319e9SDmitry Salychev #include <sys/queue.h>
35ba7319e9SDmitry Salychev #include <sys/taskqueue.h>
36ba7319e9SDmitry Salychev #include <sys/mbuf.h>
37ba7319e9SDmitry Salychev #include <sys/param.h>
38ba7319e9SDmitry Salychev #include <sys/socket.h>
39ba7319e9SDmitry Salychev #include <sys/buf_ring.h>
40ba7319e9SDmitry Salychev #include <sys/proc.h>
41*58983e4bSDmitry Salychev #include <sys/lock.h>
42ba7319e9SDmitry Salychev #include <sys/mutex.h>
43ba7319e9SDmitry Salychev 
44ba7319e9SDmitry Salychev #include <net/if.h>
45ba7319e9SDmitry Salychev #include <net/ethernet.h>
46ba7319e9SDmitry Salychev #include <net/if_media.h>
47ba7319e9SDmitry Salychev 
48ba7319e9SDmitry Salychev #include "dpaa2_types.h"
49ba7319e9SDmitry Salychev #include "dpaa2_mcp.h"
50ba7319e9SDmitry Salychev #include "dpaa2_swp.h"
51ba7319e9SDmitry Salychev #include "dpaa2_io.h"
52ba7319e9SDmitry Salychev #include "dpaa2_mac.h"
53ba7319e9SDmitry Salychev #include "dpaa2_ni_dpkg.h"
54*58983e4bSDmitry Salychev #include "dpaa2_channel.h"
55ba7319e9SDmitry Salychev 
56ba7319e9SDmitry Salychev /* Name of the DPAA2 network interface. */
57ba7319e9SDmitry Salychev #define DPAA2_NI_IFNAME		"dpni"
58ba7319e9SDmitry Salychev 
59ba7319e9SDmitry Salychev /* Maximum resources per DPNI: 16 DPIOs + 16 DPCONs + 1 DPBP + 1 DPMCP. */
60ba7319e9SDmitry Salychev #define DPAA2_NI_MAX_RESOURCES	34
61ba7319e9SDmitry Salychev 
62ba7319e9SDmitry Salychev #define DPAA2_NI_MSI_COUNT	1  /* MSIs per DPNI */
63ba7319e9SDmitry Salychev #define DPAA2_NI_MAX_POOLS	8  /* buffer pools per DPNI */
64ba7319e9SDmitry Salychev 
65*58983e4bSDmitry Salychev #define DPAA2_NI_BUFS_INIT	(5u * DPAA2_SWP_BUFS_PER_CMD)
66ba7319e9SDmitry Salychev 
67ba7319e9SDmitry Salychev /* Maximum number of buffers allocated per Tx ring. */
68ba7319e9SDmitry Salychev #define DPAA2_NI_BUFS_PER_TX	(1 << 7)
69*58983e4bSDmitry Salychev #define DPAA2_NI_MAX_BPTX	(1 << 8)
70ba7319e9SDmitry Salychev 
71ba7319e9SDmitry Salychev /* Number of the DPNI statistics counters. */
72ba7319e9SDmitry Salychev #define DPAA2_NI_STAT_COUNTERS	7u
73ba7319e9SDmitry Salychev #define	DPAA2_NI_STAT_SYSCTLS	9u
74ba7319e9SDmitry Salychev 
75ba7319e9SDmitry Salychev /* Error and status bits in the frame annotation status word. */
76ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_DISC	0x80000000 /* debug frame */
77ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_MS		0x40000000 /* MACSEC frame */
78ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_PTP	0x08000000
79ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_MC		0x04000000 /* Ethernet multicast frame */
80ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_BC		0x02000000 /* Ethernet broadcast frame */
81ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_KSE	0x00040000
82ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_EOFHE	0x00020000
83ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_MNLE	0x00010000
84ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_TIDE	0x00008000
85ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_PIEE	0x00004000
86ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_FLE	0x00002000 /* Frame length error */
87ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_FPE	0x00001000 /* Frame physical error */
88ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_PTE	0x00000080
89ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_ISP	0x00000040
90ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_PHE	0x00000020
91ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_BLE	0x00000010
92ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_L3CV	0x00000008 /* L3 csum validation performed */
93ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_L3CE	0x00000004 /* L3 csum error */
94ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_L4CV	0x00000002 /* L4 csum validation performed */
95ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_L4CE	0x00000001 /* L4 csum error */
96ba7319e9SDmitry Salychev 
97ba7319e9SDmitry Salychev /* Mask for errors on the ingress path. */
98ba7319e9SDmitry Salychev #define DPAA2_NI_FAS_RX_ERR_MASK (DPAA2_NI_FAS_KSE |	\
99ba7319e9SDmitry Salychev     DPAA2_NI_FAS_EOFHE |				\
100ba7319e9SDmitry Salychev     DPAA2_NI_FAS_MNLE |					\
101ba7319e9SDmitry Salychev     DPAA2_NI_FAS_TIDE |					\
102ba7319e9SDmitry Salychev     DPAA2_NI_FAS_PIEE |					\
103ba7319e9SDmitry Salychev     DPAA2_NI_FAS_FLE |					\
104ba7319e9SDmitry Salychev     DPAA2_NI_FAS_FPE |					\
105ba7319e9SDmitry Salychev     DPAA2_NI_FAS_PTE |					\
106ba7319e9SDmitry Salychev     DPAA2_NI_FAS_ISP |					\
107ba7319e9SDmitry Salychev     DPAA2_NI_FAS_PHE |					\
108ba7319e9SDmitry Salychev     DPAA2_NI_FAS_BLE |					\
109ba7319e9SDmitry Salychev     DPAA2_NI_FAS_L3CE |					\
110ba7319e9SDmitry Salychev     DPAA2_NI_FAS_L4CE					\
111ba7319e9SDmitry Salychev )
112ba7319e9SDmitry Salychev 
113ba7319e9SDmitry Salychev /* Option bits to select specific queue configuration options to apply. */
114ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_USER_CTX	0x00000001
115ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_DEST		0x00000002
116ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_FLC		0x00000004
117ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_HOLD_ACTIVE	0x00000008
118ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_SET_CGID	0x00000040
119ba7319e9SDmitry Salychev #define DPAA2_NI_QUEUE_OPT_CLEAR_CGID	0x00000080
120ba7319e9SDmitry Salychev 
121ba7319e9SDmitry Salychev /* DPNI link configuration options. */
122ba7319e9SDmitry Salychev #define DPAA2_NI_LINK_OPT_AUTONEG	((uint64_t) 0x01u)
123ba7319e9SDmitry Salychev #define DPAA2_NI_LINK_OPT_HALF_DUPLEX	((uint64_t) 0x02u)
124ba7319e9SDmitry Salychev #define DPAA2_NI_LINK_OPT_PAUSE		((uint64_t) 0x04u)
125ba7319e9SDmitry Salychev #define DPAA2_NI_LINK_OPT_ASYM_PAUSE	((uint64_t) 0x08u)
126ba7319e9SDmitry Salychev #define DPAA2_NI_LINK_OPT_PFC_PAUSE	((uint64_t) 0x10u)
127ba7319e9SDmitry Salychev 
128ba7319e9SDmitry Salychev /*
129ba7319e9SDmitry Salychev  * Number of times to retry a frame enqueue before giving up. Value determined
130ba7319e9SDmitry Salychev  * empirically, in order to minimize the number of frames dropped on Tx.
131ba7319e9SDmitry Salychev  */
132ba7319e9SDmitry Salychev #define DPAA2_NI_ENQUEUE_RETRIES	10
133ba7319e9SDmitry Salychev 
134*58983e4bSDmitry Salychev /* Channel storage buffer configuration */
135*58983e4bSDmitry Salychev #define DPAA2_ETH_STORE_FRAMES		16u
136*58983e4bSDmitry Salychev #define DPAA2_ETH_STORE_SIZE \
137*58983e4bSDmitry Salychev 	((DPAA2_ETH_STORE_FRAMES + 1) * sizeof(struct dpaa2_dq))
138*58983e4bSDmitry Salychev 
139*58983e4bSDmitry Salychev /*
140*58983e4bSDmitry Salychev  * NOTE: Don't forget to update dpaa2_ni_spec in case of any changes in macros!
141*58983e4bSDmitry Salychev  */
142*58983e4bSDmitry Salychev /* DPMCP resources */
143*58983e4bSDmitry Salychev #define DPAA2_NI_MCP_RES_NUM	(1u)
144*58983e4bSDmitry Salychev #define DPAA2_NI_MCP_RID_OFF	(0u)
145*58983e4bSDmitry Salychev #define DPAA2_NI_MCP_RID(rid)	((rid) + DPAA2_NI_MCP_RID_OFF)
146*58983e4bSDmitry Salychev /* DPIO resources (software portals) */
147*58983e4bSDmitry Salychev #define DPAA2_NI_IO_RES_NUM	(16u)
148*58983e4bSDmitry Salychev #define DPAA2_NI_IO_RID_OFF	(DPAA2_NI_MCP_RID_OFF + DPAA2_NI_MCP_RES_NUM)
149*58983e4bSDmitry Salychev #define DPAA2_NI_IO_RID(rid)	((rid) + DPAA2_NI_IO_RID_OFF)
150*58983e4bSDmitry Salychev /* DPBP resources (buffer pools) */
151*58983e4bSDmitry Salychev #define DPAA2_NI_BP_RES_NUM	(1u)
152*58983e4bSDmitry Salychev #define DPAA2_NI_BP_RID_OFF	(DPAA2_NI_IO_RID_OFF + DPAA2_NI_IO_RES_NUM)
153*58983e4bSDmitry Salychev #define DPAA2_NI_BP_RID(rid)	((rid) + DPAA2_NI_BP_RID_OFF)
154*58983e4bSDmitry Salychev /* DPCON resources (channels) */
155*58983e4bSDmitry Salychev #define DPAA2_NI_CON_RES_NUM	(16u)
156*58983e4bSDmitry Salychev #define DPAA2_NI_CON_RID_OFF	(DPAA2_NI_BP_RID_OFF + DPAA2_NI_BP_RES_NUM)
157*58983e4bSDmitry Salychev #define DPAA2_NI_CON_RID(rid)	((rid) + DPAA2_NI_CON_RID_OFF)
158ba7319e9SDmitry Salychev 
159ba7319e9SDmitry Salychev enum dpaa2_ni_dest_type {
160ba7319e9SDmitry Salychev 	DPAA2_NI_DEST_NONE = 0,
161ba7319e9SDmitry Salychev 	DPAA2_NI_DEST_DPIO,
162ba7319e9SDmitry Salychev 	DPAA2_NI_DEST_DPCON
163ba7319e9SDmitry Salychev };
164ba7319e9SDmitry Salychev 
165ba7319e9SDmitry Salychev enum dpaa2_ni_ofl_type {
166ba7319e9SDmitry Salychev 	DPAA2_NI_OFL_RX_L3_CSUM = 0,
167ba7319e9SDmitry Salychev 	DPAA2_NI_OFL_RX_L4_CSUM,
168ba7319e9SDmitry Salychev 	DPAA2_NI_OFL_TX_L3_CSUM,
169ba7319e9SDmitry Salychev 	DPAA2_NI_OFL_TX_L4_CSUM,
170ba7319e9SDmitry Salychev 	DPAA2_NI_OFL_FLCTYPE_HASH /* FD flow context for AIOP/CTLU */
171ba7319e9SDmitry Salychev };
172ba7319e9SDmitry Salychev 
173ba7319e9SDmitry Salychev /**
174ba7319e9SDmitry Salychev  * @brief DPNI ingress traffic distribution mode.
175ba7319e9SDmitry Salychev  */
176ba7319e9SDmitry Salychev enum dpaa2_ni_dist_mode {
177ba7319e9SDmitry Salychev 	DPAA2_NI_DIST_MODE_NONE = 0,
178ba7319e9SDmitry Salychev 	DPAA2_NI_DIST_MODE_HASH,
179ba7319e9SDmitry Salychev 	DPAA2_NI_DIST_MODE_FS
180ba7319e9SDmitry Salychev };
181ba7319e9SDmitry Salychev 
182ba7319e9SDmitry Salychev /**
183ba7319e9SDmitry Salychev  * @brief DPNI behavior in case of errors.
184ba7319e9SDmitry Salychev  */
185ba7319e9SDmitry Salychev enum dpaa2_ni_err_action {
186ba7319e9SDmitry Salychev 	DPAA2_NI_ERR_DISCARD = 0,
187ba7319e9SDmitry Salychev 	DPAA2_NI_ERR_CONTINUE,
188ba7319e9SDmitry Salychev 	DPAA2_NI_ERR_SEND_TO_ERROR_QUEUE
189ba7319e9SDmitry Salychev };
190ba7319e9SDmitry Salychev 
191*58983e4bSDmitry Salychev struct dpaa2_channel;
192ba7319e9SDmitry Salychev struct dpaa2_ni_fq;
193ba7319e9SDmitry Salychev 
194ba7319e9SDmitry Salychev /**
195ba7319e9SDmitry Salychev  * @brief Attributes of the DPNI object.
196ba7319e9SDmitry Salychev  *
197ba7319e9SDmitry Salychev  * options:	 ...
198ba7319e9SDmitry Salychev  * wriop_ver:	 Revision of the underlying WRIOP hardware block.
199ba7319e9SDmitry Salychev  */
200ba7319e9SDmitry Salychev struct dpaa2_ni_attr {
201ba7319e9SDmitry Salychev 	uint32_t		 options;
202ba7319e9SDmitry Salychev 	uint16_t		 wriop_ver;
203ba7319e9SDmitry Salychev 	struct {
204ba7319e9SDmitry Salychev 		uint16_t	 fs;
205ba7319e9SDmitry Salychev 		uint8_t		 mac;
206ba7319e9SDmitry Salychev 		uint8_t		 vlan;
207ba7319e9SDmitry Salychev 		uint8_t		 qos;
208ba7319e9SDmitry Salychev 	} entries;
209ba7319e9SDmitry Salychev 	struct {
210ba7319e9SDmitry Salychev 		uint8_t		 queues;
211ba7319e9SDmitry Salychev 		uint8_t		 rx_tcs;
212ba7319e9SDmitry Salychev 		uint8_t		 tx_tcs;
213ba7319e9SDmitry Salychev 		uint8_t		 channels;
214ba7319e9SDmitry Salychev 		uint8_t		 cgs;
215ba7319e9SDmitry Salychev 	} num;
216ba7319e9SDmitry Salychev 	struct {
217ba7319e9SDmitry Salychev 		uint8_t		 fs;
218ba7319e9SDmitry Salychev 		uint8_t		 qos;
219ba7319e9SDmitry Salychev 	} key_size;
220ba7319e9SDmitry Salychev };
221ba7319e9SDmitry Salychev 
222ba7319e9SDmitry Salychev /**
223ba7319e9SDmitry Salychev  * @brief Configuration of the network interface queue.
224ba7319e9SDmitry Salychev  *
225ba7319e9SDmitry Salychev  * NOTE: This configuration is used to obtain information of a queue by
226ba7319e9SDmitry Salychev  *	 DPNI_GET_QUEUE command and update it by DPNI_SET_QUEUE one.
227ba7319e9SDmitry Salychev  *
228ba7319e9SDmitry Salychev  * It includes binding of the queue to a DPIO or DPCON object to receive
229ba7319e9SDmitry Salychev  * notifications and traffic on the CPU.
230ba7319e9SDmitry Salychev  *
231ba7319e9SDmitry Salychev  * user_ctx:	(r/w) User defined data, presented along with the frames
232ba7319e9SDmitry Salychev  *		being dequeued from this queue.
233ba7319e9SDmitry Salychev  * flow_ctx:	(r/w) Set default FLC value for traffic dequeued from this queue.
234ba7319e9SDmitry Salychev  *		Please check description of FD structure for more information.
235ba7319e9SDmitry Salychev  *		Note that FLC values set using DPNI_ADD_FS_ENTRY, if any, take
236ba7319e9SDmitry Salychev  *		precedence over values per queue.
237ba7319e9SDmitry Salychev  * dest_id:	(r/w) The ID of a DPIO or DPCON object, depending on
238ba7319e9SDmitry Salychev  *		DEST_TYPE (in flags) value. This field is ignored for DEST_TYPE
239ba7319e9SDmitry Salychev  *		set to 0 (DPNI_DEST_NONE).
240ba7319e9SDmitry Salychev  * fqid:	(r) Frame queue ID, can be used to enqueue/dequeue or execute
241ba7319e9SDmitry Salychev  *		other commands on the queue through DPIO. Note that Tx queues
242ba7319e9SDmitry Salychev  *		are logical queues and not all management commands are available
243ba7319e9SDmitry Salychev  *		on these queue types.
244ba7319e9SDmitry Salychev  * qdbin:	(r) Queue destination bin. Can be used with the DPIO enqueue
245ba7319e9SDmitry Salychev  *		operation based on QDID, QDBIN and QPRI.
246ba7319e9SDmitry Salychev  * type:	Type of the queue to set configuration to.
247ba7319e9SDmitry Salychev  * tc:		Traffic class. Ignored for QUEUE_TYPE 2 and 3 (Tx confirmation
248ba7319e9SDmitry Salychev  *		and Rx error queues).
249ba7319e9SDmitry Salychev  * idx:		Selects a specific queue out of the set of queues in a TC.
250ba7319e9SDmitry Salychev  *		Accepted values are in range 0 to NUM_QUEUES–1. This field is
251ba7319e9SDmitry Salychev  *		ignored for QUEUE_TYPE 3 (Rx error queue). For access to the
252ba7319e9SDmitry Salychev  *		shared Tx confirmation queue (for Tx confirmation mode 1), this
253ba7319e9SDmitry Salychev  *		field must be set to 0xff.
254ba7319e9SDmitry Salychev  * cgid:	(r/w) Congestion group ID.
255ba7319e9SDmitry Salychev  * chan_id:	(w) Channel index to be configured. Used only when QUEUE_TYPE is
256ba7319e9SDmitry Salychev  *		set to DPNI_QUEUE_TX.
257ba7319e9SDmitry Salychev  * priority:	(r/w) Sets the priority in the destination DPCON or DPIO for
258ba7319e9SDmitry Salychev  *		dequeued traffic. Supported values are 0 to # of priorities in
259ba7319e9SDmitry Salychev  *		destination DPCON or DPIO - 1. This field is ignored for
260ba7319e9SDmitry Salychev  *		DEST_TYPE set to 0 (DPNI_DEST_NONE), except if this DPNI is in
261ba7319e9SDmitry Salychev  *		AIOP context. In that case the DPNI_SET_QUEUE can be used to
262ba7319e9SDmitry Salychev  *		override the default assigned priority of the FQ from the TC.
263ba7319e9SDmitry Salychev  * options:	Option bits selecting specific configuration options to apply.
264ba7319e9SDmitry Salychev  *		See DPAA2_NI_QUEUE_OPT_* for details.
265ba7319e9SDmitry Salychev  * dest_type:	Type of destination for dequeued traffic.
266ba7319e9SDmitry Salychev  * cgid_valid:	(r) Congestion group ID is valid.
267ba7319e9SDmitry Salychev  * stash_control: (r/w) If true, lowest 6 bits of FLC are used for stash control.
268ba7319e9SDmitry Salychev  *		Please check description of FD structure for more information.
269ba7319e9SDmitry Salychev  * hold_active:	(r/w) If true, this flag prevents the queue from being
270ba7319e9SDmitry Salychev  *		rescheduled between DPIOs while it carries traffic and is active
271ba7319e9SDmitry Salychev  *		on one DPIO. Can help reduce reordering if one queue is services
272ba7319e9SDmitry Salychev  *		on multiple CPUs, but the queue is also more likely to be trapped
273ba7319e9SDmitry Salychev  *		in one DPIO, especially when congested.
274ba7319e9SDmitry Salychev  */
275ba7319e9SDmitry Salychev struct dpaa2_ni_queue_cfg {
276ba7319e9SDmitry Salychev 	uint64_t		 user_ctx;
277ba7319e9SDmitry Salychev 	uint64_t		 flow_ctx;
278ba7319e9SDmitry Salychev 	uint32_t		 dest_id;
279ba7319e9SDmitry Salychev 	uint32_t		 fqid;
280ba7319e9SDmitry Salychev 	uint16_t		 qdbin;
281ba7319e9SDmitry Salychev 	enum dpaa2_ni_queue_type type;
282ba7319e9SDmitry Salychev 	uint8_t			 tc;
283ba7319e9SDmitry Salychev 	uint8_t			 idx;
284ba7319e9SDmitry Salychev 	uint8_t			 cgid;
285ba7319e9SDmitry Salychev 	uint8_t			 chan_id;
286ba7319e9SDmitry Salychev 	uint8_t			 priority;
287ba7319e9SDmitry Salychev 	uint8_t			 options;
288ba7319e9SDmitry Salychev 
289ba7319e9SDmitry Salychev 	enum dpaa2_ni_dest_type	 dest_type;
290ba7319e9SDmitry Salychev 	bool			 cgid_valid;
291ba7319e9SDmitry Salychev 	bool			 stash_control;
292ba7319e9SDmitry Salychev 	bool			 hold_active;
293ba7319e9SDmitry Salychev };
294ba7319e9SDmitry Salychev 
295ba7319e9SDmitry Salychev /**
296ba7319e9SDmitry Salychev  * @brief Buffer layout attributes.
297ba7319e9SDmitry Salychev  *
298ba7319e9SDmitry Salychev  * pd_size:		Size kept for private data (in bytes).
299ba7319e9SDmitry Salychev  * fd_align:		Frame data alignment.
300ba7319e9SDmitry Salychev  * head_size:		Data head room.
301ba7319e9SDmitry Salychev  * tail_size:		Data tail room.
302ba7319e9SDmitry Salychev  * options:		...
303ba7319e9SDmitry Salychev  * pass_timestamp:	Timestamp is included in the buffer layout.
304ba7319e9SDmitry Salychev  * pass_parser_result:	Parsing results are included in the buffer layout.
305ba7319e9SDmitry Salychev  * pass_frame_status:	Frame status is included in the buffer layout.
306ba7319e9SDmitry Salychev  * pass_sw_opaque:	SW annotation is activated.
307ba7319e9SDmitry Salychev  * queue_type:		Type of a queue this configuration applies to.
308ba7319e9SDmitry Salychev  */
309ba7319e9SDmitry Salychev struct dpaa2_ni_buf_layout {
310ba7319e9SDmitry Salychev 	uint16_t	pd_size;
311ba7319e9SDmitry Salychev 	uint16_t	fd_align;
312ba7319e9SDmitry Salychev 	uint16_t	head_size;
313ba7319e9SDmitry Salychev 	uint16_t	tail_size;
314ba7319e9SDmitry Salychev 	uint16_t	options;
315ba7319e9SDmitry Salychev 	bool		pass_timestamp;
316ba7319e9SDmitry Salychev 	bool		pass_parser_result;
317ba7319e9SDmitry Salychev 	bool		pass_frame_status;
318ba7319e9SDmitry Salychev 	bool		pass_sw_opaque;
319ba7319e9SDmitry Salychev 	enum dpaa2_ni_queue_type queue_type;
320ba7319e9SDmitry Salychev };
321ba7319e9SDmitry Salychev 
322ba7319e9SDmitry Salychev /**
323ba7319e9SDmitry Salychev  * @brief Buffer pools configuration for a network interface.
324ba7319e9SDmitry Salychev  */
325ba7319e9SDmitry Salychev struct dpaa2_ni_pools_cfg {
326ba7319e9SDmitry Salychev 	uint8_t		pools_num;
327ba7319e9SDmitry Salychev 	struct {
328ba7319e9SDmitry Salychev 		uint32_t bp_obj_id;
329ba7319e9SDmitry Salychev 		uint16_t buf_sz;
330ba7319e9SDmitry Salychev 		int	 backup_flag; /* 0 - regular pool, 1 - backup pool */
331ba7319e9SDmitry Salychev 	} pools[DPAA2_NI_MAX_POOLS];
332ba7319e9SDmitry Salychev };
333ba7319e9SDmitry Salychev 
334ba7319e9SDmitry Salychev /**
335ba7319e9SDmitry Salychev  * @brief Errors behavior configuration for a network interface.
336ba7319e9SDmitry Salychev  *
337ba7319e9SDmitry Salychev  * err_mask:		The errors mask to configure.
338ba7319e9SDmitry Salychev  * action:		Desired action for the errors selected in the mask.
339ba7319e9SDmitry Salychev  * set_err_fas:		Set to true to mark the errors in frame annotation
340ba7319e9SDmitry Salychev  * 			status (FAS); relevant for non-discard actions only.
341ba7319e9SDmitry Salychev  */
342ba7319e9SDmitry Salychev struct dpaa2_ni_err_cfg {
343ba7319e9SDmitry Salychev 	uint32_t	err_mask;
344ba7319e9SDmitry Salychev 	enum dpaa2_ni_err_action action;
345ba7319e9SDmitry Salychev 	bool		set_err_fas;
346ba7319e9SDmitry Salychev };
347ba7319e9SDmitry Salychev 
348ba7319e9SDmitry Salychev /**
349ba7319e9SDmitry Salychev  * @brief Link configuration.
350ba7319e9SDmitry Salychev  *
351ba7319e9SDmitry Salychev  * options:	Mask of available options.
352ba7319e9SDmitry Salychev  * adv_speeds:	Speeds that are advertised for autoneg.
353ba7319e9SDmitry Salychev  * rate:	Rate in Mbps.
354ba7319e9SDmitry Salychev  */
355ba7319e9SDmitry Salychev struct dpaa2_ni_link_cfg {
356ba7319e9SDmitry Salychev 	uint64_t	options;
357ba7319e9SDmitry Salychev 	uint64_t	adv_speeds;
358ba7319e9SDmitry Salychev 	uint32_t	rate;
359ba7319e9SDmitry Salychev };
360ba7319e9SDmitry Salychev 
361ba7319e9SDmitry Salychev /**
362ba7319e9SDmitry Salychev  * @brief Link state.
363ba7319e9SDmitry Salychev  *
364ba7319e9SDmitry Salychev  * options:	Mask of available options.
365ba7319e9SDmitry Salychev  * adv_speeds:	Speeds that are advertised for autoneg.
366ba7319e9SDmitry Salychev  * sup_speeds:	Speeds capability of the PHY.
367ba7319e9SDmitry Salychev  * rate:	Rate in Mbps.
368ba7319e9SDmitry Salychev  * link_up:	Link state (true if link is up, false otherwise).
369ba7319e9SDmitry Salychev  * state_valid:	Ignore/Update the state of the link.
370ba7319e9SDmitry Salychev  */
371ba7319e9SDmitry Salychev struct dpaa2_ni_link_state {
372ba7319e9SDmitry Salychev 	uint64_t	options;
373ba7319e9SDmitry Salychev 	uint64_t	adv_speeds;
374ba7319e9SDmitry Salychev 	uint64_t	sup_speeds;
375ba7319e9SDmitry Salychev 	uint32_t	rate;
376ba7319e9SDmitry Salychev 	bool		link_up;
377ba7319e9SDmitry Salychev 	bool		state_valid;
378ba7319e9SDmitry Salychev };
379ba7319e9SDmitry Salychev 
380ba7319e9SDmitry Salychev /**
381ba7319e9SDmitry Salychev  * @brief QoS table configuration.
382ba7319e9SDmitry Salychev  *
383ba7319e9SDmitry Salychev  * kcfg_busaddr:	Address of the buffer in I/O virtual address space which
384ba7319e9SDmitry Salychev  *			holds the QoS table key configuration.
385ba7319e9SDmitry Salychev  * default_tc:		Default traffic class to use in case of a lookup miss in
386ba7319e9SDmitry Salychev  *			the QoS table.
387ba7319e9SDmitry Salychev  * discard_on_miss:	Set to true to discard frames in case of no match.
388ba7319e9SDmitry Salychev  *			Default traffic class will be used otherwise.
389ba7319e9SDmitry Salychev  * keep_entries:	Set to true to keep existing QoS table entries. This
390ba7319e9SDmitry Salychev  *			option will work properly only for DPNI objects created
391ba7319e9SDmitry Salychev  *			with DPNI_OPT_HAS_KEY_MASKING option.
392ba7319e9SDmitry Salychev  */
393ba7319e9SDmitry Salychev struct dpaa2_ni_qos_table {
394ba7319e9SDmitry Salychev 	uint64_t	kcfg_busaddr;
395ba7319e9SDmitry Salychev 	uint8_t		default_tc;
396ba7319e9SDmitry Salychev 	bool		discard_on_miss;
397ba7319e9SDmitry Salychev 	bool		keep_entries;
398ba7319e9SDmitry Salychev };
399ba7319e9SDmitry Salychev 
400ba7319e9SDmitry Salychev /**
401ba7319e9SDmitry Salychev  * @brief Context to add multicast physical addresses to the filter table.
402ba7319e9SDmitry Salychev  *
403ba7319e9SDmitry Salychev  * ifp:		Network interface associated with the context.
404ba7319e9SDmitry Salychev  * error:	Result of the last MC command.
405ba7319e9SDmitry Salychev  * nent:	Number of entries added.
406ba7319e9SDmitry Salychev  */
407ba7319e9SDmitry Salychev struct dpaa2_ni_mcaddr_ctx {
408ba7319e9SDmitry Salychev 	struct ifnet	*ifp;
409ba7319e9SDmitry Salychev 	int		 error;
410ba7319e9SDmitry Salychev 	int		 nent;
411ba7319e9SDmitry Salychev };
412ba7319e9SDmitry Salychev 
413ba7319e9SDmitry Salychev struct dpaa2_eth_dist_fields {
414ba7319e9SDmitry Salychev 	uint64_t	rxnfc_field;
415ba7319e9SDmitry Salychev 	enum net_prot	cls_prot;
416ba7319e9SDmitry Salychev 	int		cls_field;
417ba7319e9SDmitry Salychev 	int		size;
418ba7319e9SDmitry Salychev 	uint64_t	id;
419ba7319e9SDmitry Salychev };
420ba7319e9SDmitry Salychev 
421ba7319e9SDmitry Salychev struct dpni_mask_cfg {
422ba7319e9SDmitry Salychev 	uint8_t		mask;
423ba7319e9SDmitry Salychev 	uint8_t		offset;
424ba7319e9SDmitry Salychev } __packed;
425ba7319e9SDmitry Salychev 
426ba7319e9SDmitry Salychev struct dpni_dist_extract {
427ba7319e9SDmitry Salychev 	uint8_t		prot;
428ba7319e9SDmitry Salychev 	uint8_t		efh_type; /* EFH type is in the 4 LSBs. */
429ba7319e9SDmitry Salychev 	uint8_t		size;
430ba7319e9SDmitry Salychev 	uint8_t		offset;
431ba7319e9SDmitry Salychev 	uint32_t	field;
432ba7319e9SDmitry Salychev 	uint8_t		hdr_index;
433ba7319e9SDmitry Salychev 	uint8_t		constant;
434ba7319e9SDmitry Salychev 	uint8_t		num_of_repeats;
435ba7319e9SDmitry Salychev 	uint8_t		num_of_byte_masks;
436ba7319e9SDmitry Salychev 	uint8_t		extract_type; /* Extraction type is in the 4 LSBs */
437ba7319e9SDmitry Salychev 	uint8_t		_reserved[3];
438ba7319e9SDmitry Salychev 	struct dpni_mask_cfg masks[4];
439ba7319e9SDmitry Salychev } __packed;
440ba7319e9SDmitry Salychev 
441ba7319e9SDmitry Salychev struct dpni_ext_set_rx_tc_dist {
442ba7319e9SDmitry Salychev 	uint8_t		num_extracts;
443ba7319e9SDmitry Salychev 	uint8_t		_reserved[7];
444ba7319e9SDmitry Salychev 	struct dpni_dist_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
445ba7319e9SDmitry Salychev } __packed;
446ba7319e9SDmitry Salychev 
447ba7319e9SDmitry Salychev /**
448ba7319e9SDmitry Salychev  * @brief Software context for the DPAA2 Network Interface driver.
449ba7319e9SDmitry Salychev  */
450ba7319e9SDmitry Salychev struct dpaa2_ni_softc {
451ba7319e9SDmitry Salychev 	device_t		 dev;
452ba7319e9SDmitry Salychev 	struct resource 	*res[DPAA2_NI_MAX_RESOURCES];
453ba7319e9SDmitry Salychev 	uint16_t		 api_major;
454ba7319e9SDmitry Salychev 	uint16_t		 api_minor;
455ba7319e9SDmitry Salychev 	uint64_t		 rx_hash_fields;
456ba7319e9SDmitry Salychev 	uint16_t		 tx_data_off;
457ba7319e9SDmitry Salychev 	uint16_t		 tx_qdid;
458ba7319e9SDmitry Salychev 	uint32_t		 link_options;
459ba7319e9SDmitry Salychev 	int			 link_state;
460ba7319e9SDmitry Salychev 
461ba7319e9SDmitry Salychev 	uint16_t		 buf_align;
462ba7319e9SDmitry Salychev 	uint16_t		 buf_sz;
463ba7319e9SDmitry Salychev 
464ba7319e9SDmitry Salychev 	uint64_t		 rx_anomaly_frames;
465ba7319e9SDmitry Salychev 	uint64_t		 rx_single_buf_frames;
466ba7319e9SDmitry Salychev 	uint64_t		 rx_sg_buf_frames;
467ba7319e9SDmitry Salychev 	uint64_t		 rx_enq_rej_frames;
468ba7319e9SDmitry Salychev 	uint64_t		 rx_ieoi_err_frames;
469ba7319e9SDmitry Salychev 	uint64_t		 tx_single_buf_frames;
470ba7319e9SDmitry Salychev 	uint64_t		 tx_sg_frames;
471ba7319e9SDmitry Salychev 
472ba7319e9SDmitry Salychev 	struct dpaa2_ni_attr	 attr;
473ba7319e9SDmitry Salychev 
474ba7319e9SDmitry Salychev 	struct ifnet		*ifp;
475ba7319e9SDmitry Salychev 	uint32_t		 if_flags;
476ba7319e9SDmitry Salychev 	struct mtx		 lock;
477ba7319e9SDmitry Salychev 	device_t		 miibus;
478ba7319e9SDmitry Salychev 	struct mii_data		*mii;
4791efae8a2SJohn Baldwin 	bool			 fixed_link;
480ba7319e9SDmitry Salychev 	struct ifmedia		 fixed_ifmedia;
481ba7319e9SDmitry Salychev 	int			 media_status;
482ba7319e9SDmitry Salychev 
483ba7319e9SDmitry Salychev 	bus_dma_tag_t		 rxd_dmat; /* for Rx distribution key */
484ba7319e9SDmitry Salychev 	bus_dma_tag_t		 qos_dmat; /* for QoS table key */
485ba7319e9SDmitry Salychev 
486*58983e4bSDmitry Salychev 	struct dpaa2_buf	 qos_kcfg; /* QoS table key config */
487*58983e4bSDmitry Salychev 	struct dpaa2_buf	 rxd_kcfg; /* Rx distribution key config */
488ba7319e9SDmitry Salychev 
489ba7319e9SDmitry Salychev 	uint32_t		 chan_n;
490*58983e4bSDmitry Salychev 	struct dpaa2_channel	*channels[DPAA2_MAX_CHANNELS];
491*58983e4bSDmitry Salychev 	struct dpaa2_ni_fq	 rxe_queue; /* one per DPNI */
492ba7319e9SDmitry Salychev 
493ba7319e9SDmitry Salychev 	struct dpaa2_atomic	 buf_num;
494ba7319e9SDmitry Salychev 	struct dpaa2_atomic	 buf_free; /* for sysctl(9) only */
495ba7319e9SDmitry Salychev 
496ba7319e9SDmitry Salychev 	int			 irq_rid[DPAA2_NI_MSI_COUNT];
497ba7319e9SDmitry Salychev 	struct resource		*irq_res;
498*58983e4bSDmitry Salychev 	void			*intr;
499ba7319e9SDmitry Salychev 
500ba7319e9SDmitry Salychev 	struct taskqueue	*bp_taskq;
501ba7319e9SDmitry Salychev 
502ba7319e9SDmitry Salychev 	struct callout		 mii_callout;
503ba7319e9SDmitry Salychev 
504ba7319e9SDmitry Salychev 	struct {
505ba7319e9SDmitry Salychev 		uint32_t	 dpmac_id;
506ba7319e9SDmitry Salychev 		uint8_t		 addr[ETHER_ADDR_LEN];
507ba7319e9SDmitry Salychev 		device_t	 phy_dev;
508ba7319e9SDmitry Salychev 		int		 phy_loc;
509*58983e4bSDmitry Salychev 	} mac; /* Info about connected DPMAC (if exists) */
510ba7319e9SDmitry Salychev };
511ba7319e9SDmitry Salychev 
512ba7319e9SDmitry Salychev extern struct resource_spec dpaa2_ni_spec[];
513ba7319e9SDmitry Salychev 
514ba7319e9SDmitry Salychev #endif /* _DPAA2_NI_H */
515