xref: /linux/include/linux/net/intel/libie/adminq.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2025 Intel Corporation */
3 
4 #ifndef __LIBIE_ADMINQ_H
5 #define __LIBIE_ADMINQ_H
6 
7 #include <linux/build_bug.h>
8 #include <linux/types.h>
9 
10 #define LIBIE_CHECK_STRUCT_LEN(n, X)	\
11 	static_assert((n) == sizeof(struct X))
12 
13 /**
14  * struct libie_aqc_generic - Generic structure used in adminq communication
15  * @param0: generic parameter high 32bit
16  * @param1: generic parameter lower 32bit
17  * @addr_high: generic address high 32bit
18  * @addr_low: generic address lower 32bit
19  */
20 struct libie_aqc_generic {
21 	__le32 param0;
22 	__le32 param1;
23 	__le32 addr_high;
24 	__le32 addr_low;
25 };
26 LIBIE_CHECK_STRUCT_LEN(16, libie_aqc_generic);
27 
28 /**
29  * struct libie_aqc_get_ver -  Used in command get version (direct 0x0001)
30  * @rom_ver: rom version
31  * @fw_build: number coressponding to firmware build
32  * @fw_branch: branch identifier of firmware version
33  * @fw_major: major number of firmware version
34  * @fw_minor: minor number of firmware version
35  * @fw_patch: patch of firmware version
36  * @api_branch: brancch identifier of API version
37  * @api_major: major number of API version
38  * @api_minor: minor number of API version
39  * @api_patch: patch of API version
40  */
41 struct libie_aqc_get_ver {
42 	__le32	rom_ver;
43 	__le32	fw_build;
44 	u8	fw_branch;
45 	u8	fw_major;
46 	u8	fw_minor;
47 	u8	fw_patch;
48 	u8	api_branch;
49 	u8	api_major;
50 	u8	api_minor;
51 	u8	api_patch;
52 };
53 LIBIE_CHECK_STRUCT_LEN(16, libie_aqc_get_ver);
54 
55 /**
56  * struct libie_aqc_driver_ver - Used in command send driver version
57  *				 (indirect 0x0002)
58  * @major_ver: driver major version
59  * @minor_ver: driver minor version
60  * @build_ver: driver build version
61  * @subbuild_ver: driver subbuild version
62  * @reserved: for feature use
63  * @addr_high: high part of response address buff
64  * @addr_low: low part of response address buff
65  */
66 struct libie_aqc_driver_ver {
67 	u8	major_ver;
68 	u8	minor_ver;
69 	u8	build_ver;
70 	u8	subbuild_ver;
71 	u8	reserved[4];
72 	__le32	addr_high;
73 	__le32	addr_low;
74 };
75 LIBIE_CHECK_STRUCT_LEN(16, libie_aqc_driver_ver);
76 
77 enum libie_aq_res_id {
78 	LIBIE_AQC_RES_ID_NVM				= 1,
79 	LIBIE_AQC_RES_ID_SDP				= 2,
80 	LIBIE_AQC_RES_ID_CHNG_LOCK			= 3,
81 	LIBIE_AQC_RES_ID_GLBL_LOCK			= 4,
82 };
83 
84 enum libie_aq_res_access_type {
85 	LIBIE_AQC_RES_ACCESS_READ			= 1,
86 	LIBIE_AQC_RES_ACCESS_WRITE			= 2,
87 };
88 
89 #define LIBIE_AQ_RES_NVM_READ_DFLT_TIMEOUT_MS		3000
90 #define LIBIE_AQ_RES_NVM_WRITE_DFLT_TIMEOUT_MS		180000
91 #define LIBIE_AQ_RES_CHNG_LOCK_DFLT_TIMEOUT_MS		1000
92 #define LIBIE_AQ_RES_GLBL_LOCK_DFLT_TIMEOUT_MS		3000
93 
94 #define LIBIE_AQ_RES_GLBL_SUCCESS			0
95 #define LIBIE_AQ_RES_GLBL_IN_PROG			1
96 #define LIBIE_AQ_RES_GLBL_DONE				2
97 
98 /**
99  * struct libie_aqc_req_res - Request resource ownership
100  * @res_id: resource ID (look at enum definition above)
101  * @access_type: read or write (enum definition above)
102  * @timeout: Upon successful completion, FW writes this value and driver is
103  * expected to release resource before timeout. This value is provided in
104  * milliseconds.
105  * @res_number: for SDP, this is the pin ID of the SDP
106  * @status: status only used for LIBIE_AQC_RES_ID_GLBL_LOCK, for others reserved
107  * @reserved: reserved for future use
108  *
109  * Used in commands:
110  * request resource ownership (direct 0x0008)
111  * request resource ownership (direct 0x0009)
112  */
113 struct libie_aqc_req_res {
114 	__le16	res_id;
115 	__le16	access_type;
116 
117 	__le32	timeout;
118 	__le32	res_number;
119 	__le16	status;
120 	u8	reserved[2];
121 };
122 LIBIE_CHECK_STRUCT_LEN(16, libie_aqc_req_res);
123 
124 /**
125  * struct libie_aqc_list_caps - Getting capabilities
126  * @cmd_flags: command flags
127  * @pf_index: index of PF to get caps from
128  * @reserved: reserved for future use
129  * @count: number of capabilities records
130  * @addr_high: high part of response address buff
131  * @addr_low: low part of response address buff
132  *
133  * Used in commands:
134  * get function capabilities (indirect 0x000A)
135  * get device capabilities (indirect 0x000B)
136  */
137 struct libie_aqc_list_caps {
138 	u8	cmd_flags;
139 	u8	pf_index;
140 	u8	reserved[2];
141 	__le32	count;
142 	__le32	addr_high;
143 	__le32	addr_low;
144 };
145 LIBIE_CHECK_STRUCT_LEN(16, libie_aqc_list_caps);
146 
147 /* Device/Function buffer entry, repeated per reported capability */
148 #define LIBIE_AQC_CAPS_SWITCH_MODE			0x0001
149 #define LIBIE_AQC_CAPS_MNG_MODE				0x0002
150 #define LIBIE_AQC_CAPS_NPAR_ACTIVE			0x0003
151 #define LIBIE_AQC_CAPS_OS2BMC_CAP			0x0004
152 #define LIBIE_AQC_CAPS_VALID_FUNCTIONS			0x0005
153 #define LIBIE_AQC_MAX_VALID_FUNCTIONS			0x8
154 #define LIBIE_AQC_CAPS_SRIOV				0x0012
155 #define LIBIE_AQC_CAPS_VF				0x0013
156 #define LIBIE_AQC_CAPS_VMDQ				0x0014
157 #define LIBIE_AQC_CAPS_8021QBG				0x0015
158 #define LIBIE_AQC_CAPS_8021QBR				0x0016
159 #define LIBIE_AQC_CAPS_VSI				0x0017
160 #define LIBIE_AQC_CAPS_DCB				0x0018
161 #define LIBIE_AQC_CAPS_FCOE				0x0021
162 #define LIBIE_AQC_CAPS_ISCSI				0x0022
163 #define LIBIE_AQC_CAPS_RSS				0x0040
164 #define LIBIE_AQC_CAPS_RXQS				0x0041
165 #define LIBIE_AQC_CAPS_TXQS				0x0042
166 #define LIBIE_AQC_CAPS_MSIX				0x0043
167 #define LIBIE_AQC_CAPS_VF_MSIX				0x0044
168 #define LIBIE_AQC_CAPS_FD				0x0045
169 #define LIBIE_AQC_CAPS_1588				0x0046
170 #define LIBIE_AQC_CAPS_MAX_MTU				0x0047
171 #define LIBIE_AQC_CAPS_NVM_VER				0x0048
172 #define LIBIE_AQC_CAPS_PENDING_NVM_VER			0x0049
173 #define LIBIE_AQC_CAPS_OROM_VER				0x004A
174 #define LIBIE_AQC_CAPS_PENDING_OROM_VER			0x004B
175 #define LIBIE_AQC_CAPS_NET_VER				0x004C
176 #define LIBIE_AQC_CAPS_PENDING_NET_VER			0x004D
177 #define LIBIE_AQC_CAPS_RDMA				0x0051
178 #define LIBIE_AQC_CAPS_LED				0x0061
179 #define LIBIE_AQC_CAPS_SDP				0x0062
180 #define LIBIE_AQC_CAPS_MDIO				0x0063
181 #define LIBIE_AQC_CAPS_WSR_PROT				0x0064
182 #define LIBIE_AQC_CAPS_SENSOR_READING			0x0067
183 #define LIBIE_AQC_INLINE_IPSEC				0x0070
184 #define LIBIE_AQC_CAPS_NUM_ENABLED_PORTS		0x0072
185 #define LIBIE_AQC_CAPS_PCIE_RESET_AVOIDANCE		0x0076
186 #define LIBIE_AQC_CAPS_POST_UPDATE_RESET_RESTRICT	0x0077
187 #define LIBIE_AQC_CAPS_NVM_MGMT				0x0080
188 #define LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG0		0x0081
189 #define LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG1		0x0082
190 #define LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG2		0x0083
191 #define LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG3		0x0084
192 #define LIBIE_AQC_CAPS_TX_SCHED_TOPO_COMP_MODE		0x0085
193 #define LIBIE_AQC_CAPS_NAC_TOPOLOGY			0x0087
194 #define LIBIE_AQC_CAPS_FW_LAG_SUPPORT			0x0092
195 #define LIBIE_AQC_BIT_ROCEV2_LAG			0x01
196 #define LIBIE_AQC_BIT_SRIOV_LAG				0x02
197 #define LIBIE_AQC_CAPS_FLEX10				0x00F1
198 #define LIBIE_AQC_CAPS_CEM				0x00F2
199 
200 /**
201  * struct libie_aqc_list_caps_elem - Getting list of caps elements
202  * @cap: one from the defines list above
203  * @major_ver: major version
204  * @minor_ver: minor version
205  * @number: number of resources described by this capability
206  * @logical_id: logical ID, only meaningful for some types of resources
207  * @phys_id: physical ID, only meaningful for some types of resources
208  * @rsvd1: reserved for future use
209  * @rsvd2: reserved for future use
210  */
211 struct libie_aqc_list_caps_elem {
212 	__le16	cap;
213 
214 	u8	major_ver;
215 	u8	minor_ver;
216 	__le32	number;
217 	__le32	logical_id;
218 	__le32	phys_id;
219 	__le64	rsvd1;
220 	__le64	rsvd2;
221 };
222 LIBIE_CHECK_STRUCT_LEN(32, libie_aqc_list_caps_elem);
223 
224 /**
225  * struct libie_aq_desc - Admin Queue (AQ) descriptor
226  * @flags: LIBIE_AQ_FLAG_* flags
227  * @opcode: AQ command opcode
228  * @datalen: length in bytes of indirect/external data buffer
229  * @retval: return value from firmware
230  * @cookie_high: opaque data high-half
231  * @cookie_low: opaque data low-half
232  * @params: command-specific parameters
233  *
234  * Descriptor format for commands the driver posts on the Admin Transmit Queue
235  * (ATQ). The firmware writes back onto the command descriptor and returns
236  * the result of the command. Asynchronous events that are not an immediate
237  * result of the command are written to the Admin Receive Queue (ARQ) using
238  * the same descriptor format. Descriptors are in little-endian notation with
239  * 32-bit words.
240  */
241 struct libie_aq_desc {
242 	__le16	flags;
243 	__le16	opcode;
244 	__le16	datalen;
245 	__le16	retval;
246 	__le32	cookie_high;
247 	__le32	cookie_low;
248 	union {
249 		u8	raw[16];
250 		struct	libie_aqc_generic generic;
251 		struct	libie_aqc_get_ver get_ver;
252 		struct	libie_aqc_driver_ver driver_ver;
253 		struct	libie_aqc_req_res res_owner;
254 		struct	libie_aqc_list_caps get_cap;
255 	} params;
256 };
257 LIBIE_CHECK_STRUCT_LEN(32, libie_aq_desc);
258 
259 /* FW defined boundary for a large buffer, 4k >= Large buffer > 512 bytes */
260 #define LIBIE_AQ_LG_BUF				512
261 
262 /* Flags sub-structure
263  * |0  |1  |2  |3  |4  |5  |6  |7  |8  |9  |10 |11 |12 |13 |14 |15 |
264  * |DD |CMP|ERR|VFE| * *  RESERVED * * |LB |RD |VFC|BUF|SI |EI |FE |
265  */
266 #define LIBIE_AQ_FLAG_DD			BIT(0)	/* 0x1    */
267 #define LIBIE_AQ_FLAG_CMP			BIT(1)	/* 0x2    */
268 #define LIBIE_AQ_FLAG_ERR			BIT(2)	/* 0x4    */
269 #define LIBIE_AQ_FLAG_VFE			BIT(3)	/* 0x8    */
270 #define LIBIE_AQ_FLAG_LB			BIT(9)	/* 0x200  */
271 #define LIBIE_AQ_FLAG_RD			BIT(10)	/* 0x400  */
272 #define LIBIE_AQ_FLAG_VFC			BIT(11) /* 0x800  */
273 #define LIBIE_AQ_FLAG_BUF			BIT(12)	/* 0x1000 */
274 #define LIBIE_AQ_FLAG_SI			BIT(13)	/* 0x2000 */
275 #define LIBIE_AQ_FLAG_EI			BIT(14)	/* 0x4000 */
276 #define LIBIE_AQ_FLAG_FE			BIT(15)	/* 0x8000 */
277 
278 /* error codes */
279 enum libie_aq_err {
280 	LIBIE_AQ_RC_OK		= 0,  /* Success */
281 	LIBIE_AQ_RC_EPERM	= 1,  /* Operation not permitted */
282 	LIBIE_AQ_RC_ENOENT	= 2,  /* No such element */
283 	LIBIE_AQ_RC_ESRCH	= 3,  /* Bad opcode */
284 	LIBIE_AQ_RC_EIO		= 5,  /* I/O error */
285 	LIBIE_AQ_RC_EAGAIN	= 8,  /* Try again */
286 	LIBIE_AQ_RC_ENOMEM	= 9,  /* Out of memory */
287 	LIBIE_AQ_RC_EACCES	= 10, /* Permission denied */
288 	LIBIE_AQ_RC_EBUSY	= 12, /* Device or resource busy */
289 	LIBIE_AQ_RC_EEXIST	= 13, /* Object already exists */
290 	LIBIE_AQ_RC_EINVAL	= 14, /* Invalid argument */
291 	LIBIE_AQ_RC_ENOSPC	= 16, /* No space left or allocation failure */
292 	LIBIE_AQ_RC_ENOSYS	= 17, /* Function not implemented */
293 	LIBIE_AQ_RC_EMODE	= 21, /* Op not allowed in current dev mode */
294 	LIBIE_AQ_RC_ENOSEC	= 24, /* Missing security manifest */
295 	LIBIE_AQ_RC_EBADSIG	= 25, /* Bad RSA signature */
296 	LIBIE_AQ_RC_ESVN	= 26, /* SVN number prohibits this package */
297 	LIBIE_AQ_RC_EBADMAN	= 27, /* Manifest hash mismatch */
298 	LIBIE_AQ_RC_EBADBUF	= 28, /* Buffer hash mismatches manifest */
299 };
300 
libie_aq_raw(struct libie_aq_desc * desc)301 static inline void *libie_aq_raw(struct libie_aq_desc *desc)
302 {
303 	return &desc->params.raw;
304 }
305 
306 const char *libie_aq_str(enum libie_aq_err err);
307 
308 #endif /* __LIBIE_ADMINQ_H */
309