xref: /freebsd/sys/dev/dpaa2/dpaa2_mcp.h (revision 58983e4b0253ad38a3e1ef2166fedd3133fdb552)
1ba7319e9SDmitry Salychev /*-
2ba7319e9SDmitry Salychev  * SPDX-License-Identifier: BSD-2-Clause
3ba7319e9SDmitry Salychev  *
4ba7319e9SDmitry Salychev  * Copyright © 2021-2022 Dmitry Salychev
5ba7319e9SDmitry Salychev  *
6ba7319e9SDmitry Salychev  * Redistribution and use in source and binary forms, with or without
7ba7319e9SDmitry Salychev  * modification, are permitted provided that the following conditions
8ba7319e9SDmitry Salychev  * are met:
9ba7319e9SDmitry Salychev  * 1. Redistributions of source code must retain the above copyright
10ba7319e9SDmitry Salychev  *    notice, this list of conditions and the following disclaimer.
11ba7319e9SDmitry Salychev  * 2. Redistributions in binary form must reproduce the above copyright
12ba7319e9SDmitry Salychev  *    notice, this list of conditions and the following disclaimer in the
13ba7319e9SDmitry Salychev  *    documentation and/or other materials provided with the distribution.
14ba7319e9SDmitry Salychev  *
15ba7319e9SDmitry Salychev  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ba7319e9SDmitry Salychev  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17ba7319e9SDmitry Salychev  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ba7319e9SDmitry Salychev  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ba7319e9SDmitry Salychev  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ba7319e9SDmitry Salychev  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ba7319e9SDmitry Salychev  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ba7319e9SDmitry Salychev  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ba7319e9SDmitry Salychev  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ba7319e9SDmitry Salychev  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ba7319e9SDmitry Salychev  * SUCH DAMAGE.
26ba7319e9SDmitry Salychev  */
27ba7319e9SDmitry Salychev 
28ba7319e9SDmitry Salychev #ifndef	_DPAA2_MCP_H
29ba7319e9SDmitry Salychev #define	_DPAA2_MCP_H
30ba7319e9SDmitry Salychev 
31ba7319e9SDmitry Salychev #include <sys/rman.h>
32ba7319e9SDmitry Salychev #include <sys/mutex.h>
33ba7319e9SDmitry Salychev 
34ba7319e9SDmitry Salychev #include "dpaa2_types.h"
35ba7319e9SDmitry Salychev 
36ba7319e9SDmitry Salychev /*
37ba7319e9SDmitry Salychev  * DPAA2 MC command interface helper routines.
38ba7319e9SDmitry Salychev  */
39ba7319e9SDmitry Salychev 
40ba7319e9SDmitry Salychev #define DPAA2_PORTAL_TIMEOUT		100000	/* us */
41ba7319e9SDmitry Salychev #define DPAA2_MCP_MEM_WIDTH		0x40 /* Minimal size of the MC portal. */
42ba7319e9SDmitry Salychev #define DPAA2_MCP_MAX_RESOURCES		1 /* resources per DPMCP: 1 SYS_MEM */
43ba7319e9SDmitry Salychev 
44ba7319e9SDmitry Salychev /*
45ba7319e9SDmitry Salychev  * Portal flags.
46ba7319e9SDmitry Salychev  *
47ba7319e9SDmitry Salychev  * TODO: Use the same flags for both MC and software portals.
48ba7319e9SDmitry Salychev  */
49ba7319e9SDmitry Salychev #define DPAA2_PORTAL_DEF		0x0u
50ba7319e9SDmitry Salychev #define DPAA2_PORTAL_NOWAIT_ALLOC	0x2u	/* Do not sleep during init */
51ba7319e9SDmitry Salychev #define DPAA2_PORTAL_LOCKED		0x4000u	/* Wait till portal's unlocked */
52ba7319e9SDmitry Salychev #define DPAA2_PORTAL_DESTROYED		0x8000u /* Terminate any operations */
53ba7319e9SDmitry Salychev 
54ba7319e9SDmitry Salychev /* Command flags. */
55ba7319e9SDmitry Salychev #define DPAA2_CMD_DEF			0x0u
56ba7319e9SDmitry Salychev #define DPAA2_CMD_HIGH_PRIO		0x80u	/* High priority command */
57ba7319e9SDmitry Salychev #define DPAA2_CMD_INTR_DIS		0x100u	/* Disable cmd finished intr */
58ba7319e9SDmitry Salychev #define DPAA2_CMD_NOWAIT_ALLOC		0x8000u	/* Do not sleep during init */
59ba7319e9SDmitry Salychev 
60ba7319e9SDmitry Salychev /* DPAA2 command return codes. */
61ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_OK		0x0	/* Set by MC on success */
62ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_READY		0x1	/* Ready to be processed */
63ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_AUTH_ERR		0x3	/* Illegal object-portal-icid */
64ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_NO_PRIVILEGE	0x4	/* No privilege */
65ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_DMA_ERR		0x5	/* DMA or I/O error */
66ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_CONFIG_ERR	0x6	/* Invalid/conflicting params */
67ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_TIMEOUT		0x7	/* Command timed out */
68ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_NO_RESOURCE	0x8	/* No DPAA2 resources */
69ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_NO_MEMORY	0x9	/* No memory available */
70ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_BUSY		0xA	/* Device is busy */
71ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_UNSUPPORTED_OP	0xB	/* Unsupported operation */
72ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_INVALID_STATE	0xC	/* Invalid state */
73ba7319e9SDmitry Salychev /* Driver-specific return codes. */
74ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_UNKNOWN_OBJ	0xFD	/* Unknown DPAA2 object. */
75ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_EINVAL		0xFE	/* Invalid argument */
76ba7319e9SDmitry Salychev #define DPAA2_CMD_STAT_ERR		0xFF	/* General error */
77ba7319e9SDmitry Salychev 
78ba7319e9SDmitry Salychev /* Object's memory region flags. */
79ba7319e9SDmitry Salychev #define DPAA2_RC_REG_CACHEABLE		0x1	/* Cacheable memory mapping */
80ba7319e9SDmitry Salychev 
81ba7319e9SDmitry Salychev #define DPAA2_HW_FLAG_HIGH_PRIO		0x80u
82ba7319e9SDmitry Salychev #define DPAA2_SW_FLAG_INTR_DIS		0x01u
83ba7319e9SDmitry Salychev 
84ba7319e9SDmitry Salychev #define DPAA2_CMD_PARAMS_N		7u
85ba7319e9SDmitry Salychev #define DPAA2_LABEL_SZ			16
86ba7319e9SDmitry Salychev 
87ba7319e9SDmitry Salychev /* ------------------------- MNG command IDs -------------------------------- */
88ba7319e9SDmitry Salychev #define CMD_MNG_BASE_VERSION	1
89ba7319e9SDmitry Salychev #define CMD_MNG_ID_OFFSET	4
90ba7319e9SDmitry Salychev 
91ba7319e9SDmitry Salychev #define CMD_MNG(id)	(((id) << CMD_MNG_ID_OFFSET) | CMD_MNG_BASE_VERSION)
92ba7319e9SDmitry Salychev 
93ba7319e9SDmitry Salychev #define CMDID_MNG_GET_VER			CMD_MNG(0x831)
94ba7319e9SDmitry Salychev #define CMDID_MNG_GET_SOC_VER			CMD_MNG(0x832)
95ba7319e9SDmitry Salychev #define CMDID_MNG_GET_CONT_ID			CMD_MNG(0x830)
96ba7319e9SDmitry Salychev 
97ba7319e9SDmitry Salychev /* ------------------------- DPRC command IDs ------------------------------- */
98ba7319e9SDmitry Salychev #define CMD_RC_BASE_VERSION	1
99ba7319e9SDmitry Salychev #define CMD_RC_2ND_VERSION	2
100ba7319e9SDmitry Salychev #define CMD_RC_3RD_VERSION	3
101ba7319e9SDmitry Salychev #define CMD_RC_ID_OFFSET	4
102ba7319e9SDmitry Salychev 
103ba7319e9SDmitry Salychev #define CMD_RC(id)	(((id) << CMD_RC_ID_OFFSET) | CMD_RC_BASE_VERSION)
104ba7319e9SDmitry Salychev #define CMD_RC_V2(id)	(((id) << CMD_RC_ID_OFFSET) | CMD_RC_2ND_VERSION)
105ba7319e9SDmitry Salychev #define CMD_RC_V3(id)	(((id) << CMD_RC_ID_OFFSET) | CMD_RC_3RD_VERSION)
106ba7319e9SDmitry Salychev 
107ba7319e9SDmitry Salychev #define CMDID_RC_OPEN				CMD_RC(0x805)
108ba7319e9SDmitry Salychev #define CMDID_RC_CLOSE				CMD_RC(0x800)
109ba7319e9SDmitry Salychev #define CMDID_RC_GET_API_VERSION		CMD_RC(0xA05)
110ba7319e9SDmitry Salychev #define CMDID_RC_GET_ATTR			CMD_RC(0x004)
111ba7319e9SDmitry Salychev #define CMDID_RC_RESET_CONT			CMD_RC(0x005)
112ba7319e9SDmitry Salychev #define CMDID_RC_RESET_CONT_V2			CMD_RC_V2(0x005)
113ba7319e9SDmitry Salychev #define CMDID_RC_SET_IRQ			CMD_RC(0x010)
114ba7319e9SDmitry Salychev #define CMDID_RC_SET_IRQ_ENABLE			CMD_RC(0x012)
115ba7319e9SDmitry Salychev #define CMDID_RC_SET_IRQ_MASK			CMD_RC(0x014)
116ba7319e9SDmitry Salychev #define CMDID_RC_GET_IRQ_STATUS			CMD_RC(0x016)
117ba7319e9SDmitry Salychev #define CMDID_RC_CLEAR_IRQ_STATUS		CMD_RC(0x017)
118ba7319e9SDmitry Salychev #define CMDID_RC_GET_CONT_ID			CMD_RC(0x830)
119ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ_COUNT			CMD_RC(0x159)
120ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ			CMD_RC(0x15A)
121ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ_DESC			CMD_RC(0x162)
122ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ_REG			CMD_RC(0x15E)
123ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ_REG_V2			CMD_RC_V2(0x15E)
124ba7319e9SDmitry Salychev #define CMDID_RC_GET_OBJ_REG_V3			CMD_RC_V3(0x15E)
125ba7319e9SDmitry Salychev #define CMDID_RC_SET_OBJ_IRQ			CMD_RC(0x15F)
126ba7319e9SDmitry Salychev #define CMDID_RC_GET_CONN			CMD_RC(0x16C)
127ba7319e9SDmitry Salychev 
128ba7319e9SDmitry Salychev /* ------------------------- DPIO command IDs ------------------------------- */
129ba7319e9SDmitry Salychev #define CMD_IO_BASE_VERSION	1
130ba7319e9SDmitry Salychev #define CMD_IO_ID_OFFSET	4
131ba7319e9SDmitry Salychev 
132ba7319e9SDmitry Salychev #define CMD_IO(id)	(((id) << CMD_IO_ID_OFFSET) | CMD_IO_BASE_VERSION)
133ba7319e9SDmitry Salychev 
134ba7319e9SDmitry Salychev #define CMDID_IO_OPEN				CMD_IO(0x803)
135ba7319e9SDmitry Salychev #define CMDID_IO_CLOSE				CMD_IO(0x800)
136ba7319e9SDmitry Salychev #define CMDID_IO_ENABLE				CMD_IO(0x002)
137ba7319e9SDmitry Salychev #define CMDID_IO_DISABLE			CMD_IO(0x003)
138ba7319e9SDmitry Salychev #define CMDID_IO_GET_ATTR			CMD_IO(0x004)
139ba7319e9SDmitry Salychev #define CMDID_IO_RESET				CMD_IO(0x005)
140ba7319e9SDmitry Salychev #define CMDID_IO_SET_IRQ_ENABLE			CMD_IO(0x012)
141ba7319e9SDmitry Salychev #define CMDID_IO_SET_IRQ_MASK			CMD_IO(0x014)
142ba7319e9SDmitry Salychev #define CMDID_IO_GET_IRQ_STATUS			CMD_IO(0x016)
143ba7319e9SDmitry Salychev #define CMDID_IO_ADD_STATIC_DQ_CHAN		CMD_IO(0x122)
144ba7319e9SDmitry Salychev 
145ba7319e9SDmitry Salychev /* ------------------------- DPNI command IDs ------------------------------- */
146ba7319e9SDmitry Salychev #define CMD_NI_BASE_VERSION	1
147ba7319e9SDmitry Salychev #define CMD_NI_2ND_VERSION	2
148ba7319e9SDmitry Salychev #define CMD_NI_4TH_VERSION	4
149ba7319e9SDmitry Salychev #define CMD_NI_ID_OFFSET	4
150ba7319e9SDmitry Salychev 
151ba7319e9SDmitry Salychev #define CMD_NI(id)	(((id) << CMD_NI_ID_OFFSET) | CMD_NI_BASE_VERSION)
152ba7319e9SDmitry Salychev #define CMD_NI_V2(id)	(((id) << CMD_NI_ID_OFFSET) | CMD_NI_2ND_VERSION)
153ba7319e9SDmitry Salychev #define CMD_NI_V4(id)	(((id) << CMD_NI_ID_OFFSET) | CMD_NI_4TH_VERSION)
154ba7319e9SDmitry Salychev 
155ba7319e9SDmitry Salychev #define CMDID_NI_OPEN				CMD_NI(0x801)
156ba7319e9SDmitry Salychev #define CMDID_NI_CLOSE				CMD_NI(0x800)
157ba7319e9SDmitry Salychev #define CMDID_NI_ENABLE				CMD_NI(0x002)
158ba7319e9SDmitry Salychev #define CMDID_NI_DISABLE			CMD_NI(0x003)
159ba7319e9SDmitry Salychev #define CMDID_NI_GET_API_VER			CMD_NI(0xA01)
160ba7319e9SDmitry Salychev #define CMDID_NI_RESET				CMD_NI(0x005)
161ba7319e9SDmitry Salychev #define CMDID_NI_GET_ATTR			CMD_NI(0x004)
162ba7319e9SDmitry Salychev #define CMDID_NI_SET_BUF_LAYOUT			CMD_NI(0x265)
163ba7319e9SDmitry Salychev #define CMDID_NI_GET_TX_DATA_OFF		CMD_NI(0x212)
164ba7319e9SDmitry Salychev #define CMDID_NI_GET_PORT_MAC_ADDR		CMD_NI(0x263)
165ba7319e9SDmitry Salychev #define CMDID_NI_SET_PRIM_MAC_ADDR		CMD_NI(0x224)
166ba7319e9SDmitry Salychev #define CMDID_NI_GET_PRIM_MAC_ADDR		CMD_NI(0x225)
167ba7319e9SDmitry Salychev #define CMDID_NI_SET_LINK_CFG			CMD_NI(0x21A)
168ba7319e9SDmitry Salychev #define CMDID_NI_GET_LINK_CFG			CMD_NI(0x278)
169ba7319e9SDmitry Salychev #define CMDID_NI_GET_LINK_STATE			CMD_NI(0x215)
170ba7319e9SDmitry Salychev #define CMDID_NI_SET_QOS_TABLE			CMD_NI(0x240)
171ba7319e9SDmitry Salychev #define CMDID_NI_CLEAR_QOS_TABLE		CMD_NI(0x243)
172ba7319e9SDmitry Salychev #define CMDID_NI_SET_POOLS			CMD_NI(0x200)
173ba7319e9SDmitry Salychev #define CMDID_NI_SET_ERR_BEHAVIOR		CMD_NI(0x20B)
174ba7319e9SDmitry Salychev #define CMDID_NI_GET_QUEUE			CMD_NI(0x25F)
175ba7319e9SDmitry Salychev #define CMDID_NI_SET_QUEUE			CMD_NI(0x260)
176ba7319e9SDmitry Salychev #define CMDID_NI_GET_QDID			CMD_NI(0x210)
177ba7319e9SDmitry Salychev #define CMDID_NI_ADD_MAC_ADDR			CMD_NI(0x226)
178ba7319e9SDmitry Salychev #define CMDID_NI_REMOVE_MAC_ADDR		CMD_NI(0x227)
179ba7319e9SDmitry Salychev #define CMDID_NI_CLEAR_MAC_FILTERS		CMD_NI(0x228)
180ba7319e9SDmitry Salychev #define CMDID_NI_SET_MFL			CMD_NI(0x216)
181ba7319e9SDmitry Salychev #define CMDID_NI_SET_OFFLOAD			CMD_NI(0x26C)
182ba7319e9SDmitry Salychev #define CMDID_NI_SET_IRQ_MASK			CMD_NI(0x014)
183ba7319e9SDmitry Salychev #define CMDID_NI_SET_IRQ_ENABLE			CMD_NI(0x012)
184ba7319e9SDmitry Salychev #define CMDID_NI_GET_IRQ_STATUS			CMD_NI(0x016)
185ba7319e9SDmitry Salychev #define CMDID_NI_SET_UNI_PROMISC		CMD_NI(0x222)
186ba7319e9SDmitry Salychev #define CMDID_NI_SET_MULTI_PROMISC		CMD_NI(0x220)
187ba7319e9SDmitry Salychev #define CMDID_NI_GET_STATISTICS			CMD_NI(0x25D)
188ba7319e9SDmitry Salychev #define CMDID_NI_SET_RX_TC_DIST			CMD_NI(0x235)
189ba7319e9SDmitry Salychev 
190ba7319e9SDmitry Salychev /* ------------------------- DPBP command IDs ------------------------------- */
191ba7319e9SDmitry Salychev #define CMD_BP_BASE_VERSION	1
192ba7319e9SDmitry Salychev #define CMD_BP_ID_OFFSET	4
193ba7319e9SDmitry Salychev 
194ba7319e9SDmitry Salychev #define CMD_BP(id)	(((id) << CMD_BP_ID_OFFSET) | CMD_BP_BASE_VERSION)
195ba7319e9SDmitry Salychev 
196ba7319e9SDmitry Salychev #define CMDID_BP_OPEN				CMD_BP(0x804)
197ba7319e9SDmitry Salychev #define CMDID_BP_CLOSE				CMD_BP(0x800)
198ba7319e9SDmitry Salychev #define CMDID_BP_ENABLE				CMD_BP(0x002)
199ba7319e9SDmitry Salychev #define CMDID_BP_DISABLE			CMD_BP(0x003)
200ba7319e9SDmitry Salychev #define CMDID_BP_GET_ATTR			CMD_BP(0x004)
201ba7319e9SDmitry Salychev #define CMDID_BP_RESET				CMD_BP(0x005)
202ba7319e9SDmitry Salychev 
203ba7319e9SDmitry Salychev /* ------------------------- DPMAC command IDs ------------------------------ */
204ba7319e9SDmitry Salychev #define CMD_MAC_BASE_VERSION	1
205ba7319e9SDmitry Salychev #define CMD_MAC_2ND_VERSION	2
206ba7319e9SDmitry Salychev #define CMD_MAC_ID_OFFSET	4
207ba7319e9SDmitry Salychev 
208ba7319e9SDmitry Salychev #define CMD_MAC(id)	(((id) << CMD_MAC_ID_OFFSET) | CMD_MAC_BASE_VERSION)
209ba7319e9SDmitry Salychev #define CMD_MAC_V2(id)	(((id) << CMD_MAC_ID_OFFSET) | CMD_MAC_2ND_VERSION)
210ba7319e9SDmitry Salychev 
211ba7319e9SDmitry Salychev #define CMDID_MAC_OPEN				CMD_MAC(0x80C)
212ba7319e9SDmitry Salychev #define CMDID_MAC_CLOSE				CMD_MAC(0x800)
213ba7319e9SDmitry Salychev #define CMDID_MAC_RESET				CMD_MAC(0x005)
214ba7319e9SDmitry Salychev #define CMDID_MAC_MDIO_READ			CMD_MAC(0x0C0)
215ba7319e9SDmitry Salychev #define CMDID_MAC_MDIO_WRITE			CMD_MAC(0x0C1)
216ba7319e9SDmitry Salychev #define CMDID_MAC_GET_ADDR			CMD_MAC(0x0C5)
217ba7319e9SDmitry Salychev #define CMDID_MAC_GET_ATTR			CMD_MAC(0x004)
218ba7319e9SDmitry Salychev #define CMDID_MAC_SET_LINK_STATE		CMD_MAC_V2(0x0C3)
219ba7319e9SDmitry Salychev #define CMDID_MAC_SET_IRQ_MASK			CMD_MAC(0x014)
220ba7319e9SDmitry Salychev #define CMDID_MAC_SET_IRQ_ENABLE		CMD_MAC(0x012)
221ba7319e9SDmitry Salychev #define CMDID_MAC_GET_IRQ_STATUS		CMD_MAC(0x016)
222ba7319e9SDmitry Salychev 
223ba7319e9SDmitry Salychev /* ------------------------- DPCON command IDs ------------------------------ */
224ba7319e9SDmitry Salychev #define CMD_CON_BASE_VERSION	1
225ba7319e9SDmitry Salychev #define CMD_CON_ID_OFFSET	4
226ba7319e9SDmitry Salychev 
227ba7319e9SDmitry Salychev #define CMD_CON(id)	(((id) << CMD_CON_ID_OFFSET) | CMD_CON_BASE_VERSION)
228ba7319e9SDmitry Salychev 
229ba7319e9SDmitry Salychev #define CMDID_CON_OPEN				CMD_CON(0x808)
230ba7319e9SDmitry Salychev #define CMDID_CON_CLOSE				CMD_CON(0x800)
231ba7319e9SDmitry Salychev #define CMDID_CON_ENABLE			CMD_CON(0x002)
232ba7319e9SDmitry Salychev #define CMDID_CON_DISABLE			CMD_CON(0x003)
233ba7319e9SDmitry Salychev #define CMDID_CON_GET_ATTR			CMD_CON(0x004)
234ba7319e9SDmitry Salychev #define CMDID_CON_RESET				CMD_CON(0x005)
235ba7319e9SDmitry Salychev #define CMDID_CON_SET_NOTIF			CMD_CON(0x100)
236ba7319e9SDmitry Salychev 
237ba7319e9SDmitry Salychev /* ------------------------- DPMCP command IDs ------------------------------ */
238ba7319e9SDmitry Salychev #define CMD_MCP_BASE_VERSION	1
239ba7319e9SDmitry Salychev #define CMD_MCP_2ND_VERSION	2
240ba7319e9SDmitry Salychev #define CMD_MCP_ID_OFFSET	4
241ba7319e9SDmitry Salychev 
242ba7319e9SDmitry Salychev #define CMD_MCP(id)	(((id) << CMD_MCP_ID_OFFSET) | CMD_MCP_BASE_VERSION)
243ba7319e9SDmitry Salychev #define CMD_MCP_V2(id)	(((id) << CMD_MCP_ID_OFFSET) | CMD_MCP_2ND_VERSION)
244ba7319e9SDmitry Salychev 
245ba7319e9SDmitry Salychev #define CMDID_MCP_CREATE			CMD_MCP_V2(0x90B)
246ba7319e9SDmitry Salychev #define CMDID_MCP_DESTROY			CMD_MCP(0x98B)
247ba7319e9SDmitry Salychev #define CMDID_MCP_OPEN				CMD_MCP(0x80B)
248ba7319e9SDmitry Salychev #define CMDID_MCP_CLOSE				CMD_MCP(0x800)
249ba7319e9SDmitry Salychev #define CMDID_MCP_RESET				CMD_MCP(0x005)
250ba7319e9SDmitry Salychev 
251ba7319e9SDmitry Salychev #define DPAA2_MCP_LOCK(__mcp, __flags) do {		\
252ba7319e9SDmitry Salychev 	mtx_assert(&(__mcp)->lock, MA_NOTOWNED);	\
253ba7319e9SDmitry Salychev 	mtx_lock(&(__mcp)->lock);			\
254ba7319e9SDmitry Salychev 	*(__flags) = (__mcp)->flags;			\
255ba7319e9SDmitry Salychev 	(__mcp)->flags |= DPAA2_PORTAL_LOCKED;		\
256ba7319e9SDmitry Salychev } while (0)
257ba7319e9SDmitry Salychev 
258ba7319e9SDmitry Salychev #define DPAA2_MCP_UNLOCK(__mcp) do {		\
259ba7319e9SDmitry Salychev 	mtx_assert(&(__mcp)->lock, MA_OWNED);	\
260ba7319e9SDmitry Salychev 	(__mcp)->flags &= ~DPAA2_PORTAL_LOCKED;	\
261ba7319e9SDmitry Salychev 	mtx_unlock(&(__mcp)->lock);		\
262ba7319e9SDmitry Salychev } while (0)
263ba7319e9SDmitry Salychev 
264ba7319e9SDmitry Salychev enum dpaa2_rc_region_type {
265ba7319e9SDmitry Salychev 	DPAA2_RC_REG_MC_PORTAL,
266ba7319e9SDmitry Salychev 	DPAA2_RC_REG_QBMAN_PORTAL
267ba7319e9SDmitry Salychev };
268ba7319e9SDmitry Salychev 
269ba7319e9SDmitry Salychev /**
270ba7319e9SDmitry Salychev  * @brief Helper object to interact with the MC portal.
271ba7319e9SDmitry Salychev  *
272ba7319e9SDmitry Salychev  * res:			Unmapped portal's I/O memory.
273ba7319e9SDmitry Salychev  * map:			Mapped portal's I/O memory.
274ba7319e9SDmitry Salychev  * lock:		Lock to send a command to the portal and wait for the
275ba7319e9SDmitry Salychev  *			result.
276ba7319e9SDmitry Salychev  * flags:		Current state of the object.
277ba7319e9SDmitry Salychev  * rc_api_major:	Major version of the DPRC API.
278ba7319e9SDmitry Salychev  * rc_api_minor:	Minor version of the DPRC API.
279ba7319e9SDmitry Salychev  */
280ba7319e9SDmitry Salychev struct dpaa2_mcp {
281ba7319e9SDmitry Salychev 	struct resource *res;
282ba7319e9SDmitry Salychev 	struct resource_map *map;
283ba7319e9SDmitry Salychev 	struct mtx	lock;
284ba7319e9SDmitry Salychev 	uint16_t	flags;
285ba7319e9SDmitry Salychev 	uint16_t	rc_api_major;
286ba7319e9SDmitry Salychev 	uint16_t	rc_api_minor;
287ba7319e9SDmitry Salychev };
288ba7319e9SDmitry Salychev 
289ba7319e9SDmitry Salychev /**
290ba7319e9SDmitry Salychev  * @brief Command object holds data to be written to the MC portal.
291ba7319e9SDmitry Salychev  *
292ba7319e9SDmitry Salychev  * header:	8 least significant bytes of the MC portal.
293ba7319e9SDmitry Salychev  * params:	Parameters to pass together with the command to MC. Might keep
294ba7319e9SDmitry Salychev  *		command execution results.
295ba7319e9SDmitry Salychev  *
296ba7319e9SDmitry Salychev  * NOTE: 64 bytes.
297ba7319e9SDmitry Salychev  */
298ba7319e9SDmitry Salychev struct dpaa2_cmd {
299ba7319e9SDmitry Salychev 	uint64_t	header;
300ba7319e9SDmitry Salychev 	uint64_t	params[DPAA2_CMD_PARAMS_N];
301ba7319e9SDmitry Salychev };
302ba7319e9SDmitry Salychev 
303ba7319e9SDmitry Salychev /**
304ba7319e9SDmitry Salychev  * @brief Helper object to access fields of the MC command header.
305ba7319e9SDmitry Salychev  *
306ba7319e9SDmitry Salychev  * srcid:	The SoC architected source ID of the submitter. This field is
307ba7319e9SDmitry Salychev  *		reserved and cannot be written by the driver.
308ba7319e9SDmitry Salychev  * flags_hw:	Bits from 8 to 15 of the command header. Most of them are
309ba7319e9SDmitry Salychev  *		reserved at the moment.
310ba7319e9SDmitry Salychev  * status:	Command ready/status. This field is used as the handshake field
311ba7319e9SDmitry Salychev  *		between MC and the driver. MC reports command completion with
312ba7319e9SDmitry Salychev  *		success/error codes in this field.
313ba7319e9SDmitry Salychev  * flags_sw:	...
314ba7319e9SDmitry Salychev  * token:	...
315ba7319e9SDmitry Salychev  * cmdid:	...
316ba7319e9SDmitry Salychev  *
317ba7319e9SDmitry Salychev  * NOTE: 8 bytes.
318ba7319e9SDmitry Salychev  */
319ba7319e9SDmitry Salychev struct dpaa2_cmd_header {
320ba7319e9SDmitry Salychev 	uint8_t		srcid;
321ba7319e9SDmitry Salychev 	uint8_t		flags_hw;
322ba7319e9SDmitry Salychev 	uint8_t		status;
323ba7319e9SDmitry Salychev 	uint8_t		flags_sw;
324ba7319e9SDmitry Salychev 	uint16_t	token;
325ba7319e9SDmitry Salychev 	uint16_t	cmdid;
326ba7319e9SDmitry Salychev } __packed;
327ba7319e9SDmitry Salychev 
328ba7319e9SDmitry Salychev /**
329ba7319e9SDmitry Salychev  * @brief Information about DPAA2 object.
330ba7319e9SDmitry Salychev  *
331ba7319e9SDmitry Salychev  * id:		ID of a logical object resource.
332ba7319e9SDmitry Salychev  * vendor:	Object vendor identifier.
333ba7319e9SDmitry Salychev  * irq_count:	Number of interrupts supported by the object.
334ba7319e9SDmitry Salychev  * reg_count:	Number of mappable regions supported by the object.
335ba7319e9SDmitry Salychev  * state:	Object state (combination of states).
336ba7319e9SDmitry Salychev  * ver_major:	Major version of the object.
337ba7319e9SDmitry Salychev  * ver_minor:	Minor version of the object.
338ba7319e9SDmitry Salychev  * flags:	Object attributes flags.
339ba7319e9SDmitry Salychev  * type:	...
340ba7319e9SDmitry Salychev  * label:	...
341ba7319e9SDmitry Salychev  */
342ba7319e9SDmitry Salychev struct dpaa2_obj {
343ba7319e9SDmitry Salychev 	uint32_t	id;
344ba7319e9SDmitry Salychev 	uint16_t	vendor;
345ba7319e9SDmitry Salychev 	uint8_t		irq_count;
346ba7319e9SDmitry Salychev 	uint8_t		reg_count;
347ba7319e9SDmitry Salychev 	uint32_t	state;
348ba7319e9SDmitry Salychev 	uint16_t	ver_major;
349ba7319e9SDmitry Salychev 	uint16_t	ver_minor;
350ba7319e9SDmitry Salychev 	uint16_t	flags;
351ba7319e9SDmitry Salychev 	uint8_t		label[DPAA2_LABEL_SZ];
352ba7319e9SDmitry Salychev 	enum dpaa2_dev_type type;
353ba7319e9SDmitry Salychev };
354ba7319e9SDmitry Salychev 
355ba7319e9SDmitry Salychev /**
356ba7319e9SDmitry Salychev  * @brief Attributes of the DPRC object.
357ba7319e9SDmitry Salychev  *
358ba7319e9SDmitry Salychev  * cont_id:	Container ID.
359ba7319e9SDmitry Salychev  * portal_id:	Container's portal ID.
360ba7319e9SDmitry Salychev  * options:	Container's options as set at container's creation.
361ba7319e9SDmitry Salychev  * icid:	Container's isolation context ID.
362ba7319e9SDmitry Salychev  */
363ba7319e9SDmitry Salychev struct dpaa2_rc_attr {
364ba7319e9SDmitry Salychev 	uint32_t	cont_id;
365ba7319e9SDmitry Salychev 	uint32_t	portal_id;
366ba7319e9SDmitry Salychev 	uint32_t	options;
367ba7319e9SDmitry Salychev 	uint32_t	icid;
368ba7319e9SDmitry Salychev };
369ba7319e9SDmitry Salychev 
370ba7319e9SDmitry Salychev /**
371ba7319e9SDmitry Salychev  * @brief Description of the object's memory region.
372ba7319e9SDmitry Salychev  *
373ba7319e9SDmitry Salychev  * base_paddr:	Region base physical address.
374ba7319e9SDmitry Salychev  * base_offset:	Region base offset.
375ba7319e9SDmitry Salychev  * size:	Region size (in bytes).
376ba7319e9SDmitry Salychev  * flags:	Region flags (cacheable, etc.)
377ba7319e9SDmitry Salychev  * type:	Type of a software portal this region belongs to.
378ba7319e9SDmitry Salychev  */
379ba7319e9SDmitry Salychev struct dpaa2_rc_obj_region {
380ba7319e9SDmitry Salychev 	uint64_t	base_paddr;
381ba7319e9SDmitry Salychev 	uint64_t	base_offset;
382ba7319e9SDmitry Salychev 	uint32_t	size;
383ba7319e9SDmitry Salychev 	uint32_t	flags;
384ba7319e9SDmitry Salychev 	enum dpaa2_rc_region_type type;
385ba7319e9SDmitry Salychev };
386ba7319e9SDmitry Salychev 
387ba7319e9SDmitry Salychev /**
388ba7319e9SDmitry Salychev  * @brief DPAA2 endpoint descriptor.
389ba7319e9SDmitry Salychev  *
390ba7319e9SDmitry Salychev  * obj_id:	Endpoint object ID.
391ba7319e9SDmitry Salychev  * if_id:	Interface ID; for endpoints with multiple interfaces
392ba7319e9SDmitry Salychev  *		(DPSW, DPDMUX), 0 - otherwise.
393ba7319e9SDmitry Salychev  * type:	Endpoint object type, null-terminated string.
394ba7319e9SDmitry Salychev  */
395ba7319e9SDmitry Salychev struct dpaa2_ep_desc {
396ba7319e9SDmitry Salychev 	uint32_t	obj_id;
397ba7319e9SDmitry Salychev 	uint32_t	if_id;
398ba7319e9SDmitry Salychev 	enum dpaa2_dev_type type;
399ba7319e9SDmitry Salychev };
400ba7319e9SDmitry Salychev 
401ba7319e9SDmitry Salychev /**
402ba7319e9SDmitry Salychev  * @brief Configuration of the channel data availability notification (CDAN).
403ba7319e9SDmitry Salychev  *
404ba7319e9SDmitry Salychev  * qman_ctx:	Context value provided with each CDAN message.
405ba7319e9SDmitry Salychev  * dpio_id:	DPIO object ID configured with a notification channel.
406ba7319e9SDmitry Salychev  * prior:	Priority selection within the DPIO channel; valid values
407ba7319e9SDmitry Salychev  *		are 0-7, depending on the number of priorities in that channel.
408ba7319e9SDmitry Salychev  */
409ba7319e9SDmitry Salychev struct dpaa2_con_notif_cfg {
410ba7319e9SDmitry Salychev 	uint64_t	qman_ctx;
411ba7319e9SDmitry Salychev 	uint32_t	dpio_id;
412ba7319e9SDmitry Salychev 	uint8_t		prior;
413ba7319e9SDmitry Salychev };
414ba7319e9SDmitry Salychev 
415ba7319e9SDmitry Salychev /**
416ba7319e9SDmitry Salychev  * @brief Attributes of the DPMCP object.
417ba7319e9SDmitry Salychev  *
418ba7319e9SDmitry Salychev  * id:		 DPMCP object ID.
419ba7319e9SDmitry Salychev  * options:	 Options of the MC portal (disabled high-prio commands, etc.).
420ba7319e9SDmitry Salychev  */
421ba7319e9SDmitry Salychev struct dpaa2_mcp_attr {
422ba7319e9SDmitry Salychev 	uint32_t		id;
423ba7319e9SDmitry Salychev 	uint32_t		options;
424ba7319e9SDmitry Salychev };
425ba7319e9SDmitry Salychev 
426ba7319e9SDmitry Salychev /**
427ba7319e9SDmitry Salychev  * @brief Software context for the DPAA2 MC portal.
428ba7319e9SDmitry Salychev  */
429ba7319e9SDmitry Salychev struct dpaa2_mcp_softc {
430ba7319e9SDmitry Salychev 	device_t		 dev;
431ba7319e9SDmitry Salychev 	struct dpaa2_mcp_attr	 attr;
432ba7319e9SDmitry Salychev 
433ba7319e9SDmitry Salychev 	struct resource 	*res[DPAA2_MCP_MAX_RESOURCES];
434ba7319e9SDmitry Salychev 	struct resource_map	 map[DPAA2_MCP_MAX_RESOURCES];
435ba7319e9SDmitry Salychev };
436ba7319e9SDmitry Salychev 
437ba7319e9SDmitry Salychev int	dpaa2_mcp_init_portal(struct dpaa2_mcp **mcp, struct resource *res,
438ba7319e9SDmitry Salychev 	    struct resource_map *map, uint16_t flags);
439ba7319e9SDmitry Salychev void	dpaa2_mcp_free_portal(struct dpaa2_mcp *mcp);
440ba7319e9SDmitry Salychev 
441ba7319e9SDmitry Salychev /* to quickly update command token */
442*4cd96614SDmitry Salychev struct dpaa2_cmd *dpaa2_mcp_tk(struct dpaa2_cmd *cmd, const uint16_t token);
443ba7319e9SDmitry Salychev /* to quickly update command flags */
444*4cd96614SDmitry Salychev struct dpaa2_cmd *dpaa2_mcp_f(struct dpaa2_cmd *cmd, const uint16_t flags);
445*4cd96614SDmitry Salychev 
446*4cd96614SDmitry Salychev #define DPAA2_CMD_INIT_FLAGS(__cmd, __flags) do {			\
447*4cd96614SDmitry Salychev 	KASSERT((__cmd) != NULL, ("%s:%d: failed", __func__, __LINE__)); \
448*4cd96614SDmitry Salychev 	struct dpaa2_cmd_header *__hdr;					\
449*4cd96614SDmitry Salychev 	uint32_t __dcpi;						\
450*4cd96614SDmitry Salychev 									\
451*4cd96614SDmitry Salychev 	__hdr = (struct dpaa2_cmd_header *)&((__cmd)->header);		\
452*4cd96614SDmitry Salychev 	__hdr->srcid = 0;						\
453*4cd96614SDmitry Salychev 	__hdr->status = DPAA2_CMD_STAT_OK;				\
454*4cd96614SDmitry Salychev 	__hdr->token = 0;						\
455*4cd96614SDmitry Salychev 	__hdr->cmdid = 0;						\
456*4cd96614SDmitry Salychev 	__hdr->flags_hw = DPAA2_CMD_DEF;				\
457*4cd96614SDmitry Salychev 	__hdr->flags_sw = DPAA2_CMD_DEF;				\
458*4cd96614SDmitry Salychev 	if ((__flags) & DPAA2_CMD_HIGH_PRIO) {				\
459*4cd96614SDmitry Salychev 		__hdr->flags_hw |= DPAA2_HW_FLAG_HIGH_PRIO;		\
460*4cd96614SDmitry Salychev 	}								\
461*4cd96614SDmitry Salychev 	if ((__flags) & DPAA2_CMD_INTR_DIS) {				\
462*4cd96614SDmitry Salychev 		__hdr->flags_sw |= DPAA2_SW_FLAG_INTR_DIS;		\
463*4cd96614SDmitry Salychev 	}								\
464*4cd96614SDmitry Salychev 	for (__dcpi = 0; __dcpi < DPAA2_CMD_PARAMS_N; __dcpi++) {	\
465*4cd96614SDmitry Salychev 		(__cmd)->params[__dcpi] = 0;				\
466*4cd96614SDmitry Salychev 	}								\
467*4cd96614SDmitry Salychev } while (0)
468*4cd96614SDmitry Salychev #define DPAA2_CMD_INIT(c)	DPAA2_CMD_INIT_FLAGS((c), DPAA2_CMD_DEF)
469*4cd96614SDmitry Salychev #define DPAA2_CMD_TK(c, t)	dpaa2_mcp_tk((c), (t))
470*4cd96614SDmitry Salychev #define DPAA2_CMD_F(c, f)	dpaa2_mcp_f((c), (f))
471ba7319e9SDmitry Salychev 
472ba7319e9SDmitry Salychev #endif /* _DPAA2_MCP_H */
473