xref: /freebsd/sys/dev/ice/ice_ddp_common.h (revision db33c6f3ae9d1231087710068ee4ea5398aacca7)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2024, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _ICE_DDP_COMMON_H_
33 #define _ICE_DDP_COMMON_H_
34 
35 #include "ice_osdep.h"
36 #include "ice_adminq_cmd.h"
37 #include "ice_controlq.h"
38 #include "ice_status.h"
39 #include "ice_flex_type.h"
40 #include "ice_protocol_type.h"
41 
42 /* Package minimal version supported */
43 #define ICE_PKG_SUPP_VER_MAJ	1
44 #define ICE_PKG_SUPP_VER_MNR	3
45 
46 /* Package format version */
47 #define ICE_PKG_FMT_VER_MAJ	1
48 #define ICE_PKG_FMT_VER_MNR	0
49 #define ICE_PKG_FMT_VER_UPD	0
50 #define ICE_PKG_FMT_VER_DFT	0
51 
52 #define ICE_PKG_CNT 4
53 
54 enum ice_ddp_state {
55 	/* Indicates that this call to ice_init_pkg
56 	 * successfully loaded the requested DDP package
57 	 */
58 	ICE_DDP_PKG_SUCCESS				= 0,
59 
60 	/* Generic error for already loaded errors, it is mapped later to
61 	 * the more specific one (one of the next 3)
62 	 */
63 	ICE_DDP_PKG_ALREADY_LOADED			= -1,
64 
65 	/* Indicates that a DDP package of the same version has already been
66 	 * loaded onto the device by a previous call or by another PF
67 	 */
68 	ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED		= -2,
69 
70 	/* The device has a DDP package that is not supported by the driver */
71 	ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED	= -3,
72 
73 	/* The device has a compatible package
74 	 * (but different from the request) already loaded
75 	 */
76 	ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED		= -4,
77 
78 	/* The firmware loaded on the device is not compatible with
79 	 * the DDP package loaded
80 	 */
81 	ICE_DDP_PKG_FW_MISMATCH				= -5,
82 
83 	/* The DDP package file is invalid */
84 	ICE_DDP_PKG_INVALID_FILE			= -6,
85 
86 	/* The version of the DDP package provided is higher than
87 	 * the driver supports
88 	 */
89 	ICE_DDP_PKG_FILE_VERSION_TOO_HIGH		= -7,
90 
91 	/* The version of the DDP package provided is lower than the
92 	 * driver supports
93 	 */
94 	ICE_DDP_PKG_FILE_VERSION_TOO_LOW		= -8,
95 
96 	/* Missing security manifest in DDP pkg */
97 	ICE_DDP_PKG_NO_SEC_MANIFEST			= -9,
98 
99 	/* The RSA signature of the DDP package file provided is invalid */
100 	ICE_DDP_PKG_FILE_SIGNATURE_INVALID		= -10,
101 
102 	/* The DDP package file security revision is too low and not
103 	 * supported by firmware
104 	 */
105 	ICE_DDP_PKG_SECURE_VERSION_NBR_TOO_LOW		= -11,
106 
107 	/* Manifest hash mismatch */
108 	ICE_DDP_PKG_MANIFEST_INVALID			= -12,
109 
110 	/* Buffer hash mismatches manifest */
111 	ICE_DDP_PKG_BUFFER_INVALID			= -13,
112 
113 	/* Other errors */
114 	ICE_DDP_PKG_ERR					= -14,
115 };
116 
117 /* Package and segment headers and tables */
118 struct ice_pkg_hdr {
119 	struct ice_pkg_ver pkg_format_ver;
120 	__le32 seg_count;
121 	__le32 seg_offset[STRUCT_HACK_VAR_LEN];
122 };
123 
124 /* Package signing algorithm types */
125 #define SEGMENT_SIGN_TYPE_INVALID	0x00000000
126 #define SEGMENT_SIGN_TYPE_RSA2K		0x00000001
127 #define SEGMENT_SIGN_TYPE_RSA3K		0x00000002
128 #define SEGMENT_SIGN_TYPE_RSA3K_SBB	0x00000003 /* Secure Boot Block */
129 #define SEGMENT_SIGN_TYPE_RSA3K_E825	0x00000005
130 
131 /* generic segment */
132 struct ice_generic_seg_hdr {
133 #define	SEGMENT_TYPE_INVALID	0x00000000
134 #define SEGMENT_TYPE_METADATA	0x00000001
135 #define SEGMENT_TYPE_ICE_E810	0x00000010
136 #define SEGMENT_TYPE_SIGNING	0x00001001
137 #define SEGMENT_TYPE_ICE_E830	0x00000017
138 #define SEGMENT_TYPE_ICE_RUN_TIME_CFG 0x00000020
139 	__le32 seg_type;
140 	struct ice_pkg_ver seg_format_ver;
141 	__le32 seg_size;
142 	char seg_id[ICE_PKG_NAME_SIZE];
143 };
144 
145 /* ice specific segment */
146 
147 union ice_device_id {
148 	struct {
149 		__le16 device_id;
150 		__le16 vendor_id;
151 	} dev_vend_id;
152 	__le32 id;
153 };
154 
155 struct ice_device_id_entry {
156 	union ice_device_id device;
157 	union ice_device_id sub_device;
158 };
159 
160 struct ice_seg {
161 	struct ice_generic_seg_hdr hdr;
162 	__le32 device_table_count;
163 	struct ice_device_id_entry device_table[STRUCT_HACK_VAR_LEN];
164 };
165 
166 struct ice_nvm_table {
167 	__le32 table_count;
168 	__le32 vers[STRUCT_HACK_VAR_LEN];
169 };
170 
171 struct ice_buf {
172 #define ICE_PKG_BUF_SIZE	4096
173 	u8 buf[ICE_PKG_BUF_SIZE];
174 };
175 
176 struct ice_buf_table {
177 	__le32 buf_count;
178 	struct ice_buf buf_array[STRUCT_HACK_VAR_LEN];
179 };
180 
181 struct ice_run_time_cfg_seg {
182 	struct ice_generic_seg_hdr hdr;
183 	u8 rsvd[8];
184 	struct ice_buf_table buf_table;
185 };
186 
187 /* global metadata specific segment */
188 struct ice_global_metadata_seg {
189 	struct ice_generic_seg_hdr hdr;
190 	struct ice_pkg_ver pkg_ver;
191 	__le32 rsvd;
192 	char pkg_name[ICE_PKG_NAME_SIZE];
193 };
194 
195 #define ICE_MIN_S_OFF		12
196 #define ICE_MAX_S_OFF		4095
197 #define ICE_MIN_S_SZ		1
198 #define ICE_MAX_S_SZ		4084
199 
200 struct ice_sign_seg {
201 	struct ice_generic_seg_hdr hdr;
202 	__le32 seg_id;
203 	__le32 sign_type;
204 	__le32 signed_seg_idx;
205 	__le32 signed_buf_start;
206 	__le32 signed_buf_count;
207 #define ICE_SIGN_SEG_FLAGS_VALID	0x80000000
208 #define ICE_SIGN_SEG_FLAGS_LAST		0x00000001
209 	__le32 flags;
210 #define ICE_SIGN_SEG_RESERVED_COUNT	40
211 	u8 reserved[ICE_SIGN_SEG_RESERVED_COUNT];
212 	struct ice_buf_table buf_tbl;
213 };
214 
215 /* section information */
216 struct ice_section_entry {
217 	__le32 type;
218 	__le16 offset;
219 	__le16 size;
220 };
221 
222 #define ICE_MIN_S_COUNT		1
223 #define ICE_MAX_S_COUNT		511
224 #define ICE_MIN_S_DATA_END	12
225 #define ICE_MAX_S_DATA_END	4096
226 
227 #define ICE_METADATA_BUF	0x80000000
228 
229 struct ice_buf_hdr {
230 	__le16 section_count;
231 	__le16 data_end;
232 	struct ice_section_entry section_entry[STRUCT_HACK_VAR_LEN];
233 };
234 
235 #define ICE_MAX_ENTRIES_IN_BUF(hd_sz, ent_sz) ((ICE_PKG_BUF_SIZE - \
236 	ice_struct_size((struct ice_buf_hdr *)0, section_entry, 1) - (hd_sz)) /\
237 	(ent_sz))
238 
239 /* ice package section IDs */
240 #define ICE_SID_METADATA		1
241 #define ICE_SID_XLT0_SW			10
242 #define ICE_SID_XLT_KEY_BUILDER_SW	11
243 #define ICE_SID_XLT1_SW			12
244 #define ICE_SID_XLT2_SW			13
245 #define ICE_SID_PROFID_TCAM_SW		14
246 #define ICE_SID_PROFID_REDIR_SW		15
247 #define ICE_SID_FLD_VEC_SW		16
248 #define ICE_SID_CDID_KEY_BUILDER_SW	17
249 #define ICE_SID_CDID_REDIR_SW		18
250 
251 #define ICE_SID_XLT0_ACL		20
252 #define ICE_SID_XLT_KEY_BUILDER_ACL	21
253 #define ICE_SID_XLT1_ACL		22
254 #define ICE_SID_XLT2_ACL		23
255 #define ICE_SID_PROFID_TCAM_ACL		24
256 #define ICE_SID_PROFID_REDIR_ACL	25
257 #define ICE_SID_FLD_VEC_ACL		26
258 #define ICE_SID_CDID_KEY_BUILDER_ACL	27
259 #define ICE_SID_CDID_REDIR_ACL		28
260 
261 #define ICE_SID_XLT0_FD			30
262 #define ICE_SID_XLT_KEY_BUILDER_FD	31
263 #define ICE_SID_XLT1_FD			32
264 #define ICE_SID_XLT2_FD			33
265 #define ICE_SID_PROFID_TCAM_FD		34
266 #define ICE_SID_PROFID_REDIR_FD		35
267 #define ICE_SID_FLD_VEC_FD		36
268 #define ICE_SID_CDID_KEY_BUILDER_FD	37
269 #define ICE_SID_CDID_REDIR_FD		38
270 
271 #define ICE_SID_XLT0_RSS		40
272 #define ICE_SID_XLT_KEY_BUILDER_RSS	41
273 #define ICE_SID_XLT1_RSS		42
274 #define ICE_SID_XLT2_RSS		43
275 #define ICE_SID_PROFID_TCAM_RSS		44
276 #define ICE_SID_PROFID_REDIR_RSS	45
277 #define ICE_SID_FLD_VEC_RSS		46
278 #define ICE_SID_CDID_KEY_BUILDER_RSS	47
279 #define ICE_SID_CDID_REDIR_RSS		48
280 
281 #define ICE_SID_RXPARSER_CAM		50
282 #define ICE_SID_RXPARSER_NOMATCH_CAM	51
283 #define ICE_SID_RXPARSER_IMEM		52
284 #define ICE_SID_RXPARSER_XLT0_BUILDER	53
285 #define ICE_SID_RXPARSER_NODE_PTYPE	54
286 #define ICE_SID_RXPARSER_MARKER_PTYPE	55
287 #define ICE_SID_RXPARSER_BOOST_TCAM	56
288 #define ICE_SID_RXPARSER_PROTO_GRP	57
289 #define ICE_SID_RXPARSER_METADATA_INIT	58
290 #define ICE_SID_RXPARSER_XLT0		59
291 
292 #define ICE_SID_TXPARSER_CAM		60
293 #define ICE_SID_TXPARSER_NOMATCH_CAM	61
294 #define ICE_SID_TXPARSER_IMEM		62
295 #define ICE_SID_TXPARSER_XLT0_BUILDER	63
296 #define ICE_SID_TXPARSER_NODE_PTYPE	64
297 #define ICE_SID_TXPARSER_MARKER_PTYPE	65
298 #define ICE_SID_TXPARSER_BOOST_TCAM	66
299 #define ICE_SID_TXPARSER_PROTO_GRP	67
300 #define ICE_SID_TXPARSER_METADATA_INIT	68
301 #define ICE_SID_TXPARSER_XLT0		69
302 
303 #define ICE_SID_RXPARSER_INIT_REDIR	70
304 #define ICE_SID_TXPARSER_INIT_REDIR	71
305 #define ICE_SID_RXPARSER_MARKER_GRP	72
306 #define ICE_SID_TXPARSER_MARKER_GRP	73
307 #define ICE_SID_RXPARSER_LAST_PROTO	74
308 #define ICE_SID_TXPARSER_LAST_PROTO	75
309 #define ICE_SID_RXPARSER_PG_SPILL	76
310 #define ICE_SID_TXPARSER_PG_SPILL	77
311 #define ICE_SID_RXPARSER_NOMATCH_SPILL	78
312 #define ICE_SID_TXPARSER_NOMATCH_SPILL	79
313 
314 #define ICE_SID_XLT0_PE			80
315 #define ICE_SID_XLT_KEY_BUILDER_PE	81
316 #define ICE_SID_XLT1_PE			82
317 #define ICE_SID_XLT2_PE			83
318 #define ICE_SID_PROFID_TCAM_PE		84
319 #define ICE_SID_PROFID_REDIR_PE		85
320 #define ICE_SID_FLD_VEC_PE		86
321 #define ICE_SID_CDID_KEY_BUILDER_PE	87
322 #define ICE_SID_CDID_REDIR_PE		88
323 
324 #define ICE_SID_RXPARSER_FLAG_REDIR	97
325 
326 /* Label Metadata section IDs */
327 #define ICE_SID_LBL_FIRST		0x80000010
328 #define ICE_SID_LBL_RXPARSER_IMEM	0x80000010
329 #define ICE_SID_LBL_TXPARSER_IMEM	0x80000011
330 #define ICE_SID_LBL_RESERVED_12		0x80000012
331 #define ICE_SID_LBL_RESERVED_13		0x80000013
332 #define ICE_SID_LBL_RXPARSER_MARKER	0x80000014
333 #define ICE_SID_LBL_TXPARSER_MARKER	0x80000015
334 #define ICE_SID_LBL_PTYPE		0x80000016
335 #define ICE_SID_LBL_PROTOCOL_ID		0x80000017
336 #define ICE_SID_LBL_RXPARSER_TMEM	0x80000018
337 #define ICE_SID_LBL_TXPARSER_TMEM	0x80000019
338 #define ICE_SID_LBL_RXPARSER_PG		0x8000001A
339 #define ICE_SID_LBL_TXPARSER_PG		0x8000001B
340 #define ICE_SID_LBL_RXPARSER_M_TCAM	0x8000001C
341 #define ICE_SID_LBL_TXPARSER_M_TCAM	0x8000001D
342 #define ICE_SID_LBL_SW_PROFID_TCAM	0x8000001E
343 #define ICE_SID_LBL_ACL_PROFID_TCAM	0x8000001F
344 #define ICE_SID_LBL_PE_PROFID_TCAM	0x80000020
345 #define ICE_SID_LBL_RSS_PROFID_TCAM	0x80000021
346 #define ICE_SID_LBL_FD_PROFID_TCAM	0x80000022
347 #define ICE_SID_LBL_FLAG		0x80000023
348 #define ICE_SID_LBL_REG			0x80000024
349 #define ICE_SID_LBL_SW_PTG		0x80000025
350 #define ICE_SID_LBL_ACL_PTG		0x80000026
351 #define ICE_SID_LBL_PE_PTG		0x80000027
352 #define ICE_SID_LBL_RSS_PTG		0x80000028
353 #define ICE_SID_LBL_FD_PTG		0x80000029
354 #define ICE_SID_LBL_SW_VSIG		0x8000002A
355 #define ICE_SID_LBL_ACL_VSIG		0x8000002B
356 #define ICE_SID_LBL_PE_VSIG		0x8000002C
357 #define ICE_SID_LBL_RSS_VSIG		0x8000002D
358 #define ICE_SID_LBL_FD_VSIG		0x8000002E
359 #define ICE_SID_LBL_PTYPE_META		0x8000002F
360 #define ICE_SID_LBL_SW_PROFID		0x80000030
361 #define ICE_SID_LBL_ACL_PROFID		0x80000031
362 #define ICE_SID_LBL_PE_PROFID		0x80000032
363 #define ICE_SID_LBL_RSS_PROFID		0x80000033
364 #define ICE_SID_LBL_FD_PROFID		0x80000034
365 #define ICE_SID_LBL_RXPARSER_MARKER_GRP	0x80000035
366 #define ICE_SID_LBL_TXPARSER_MARKER_GRP	0x80000036
367 #define ICE_SID_LBL_RXPARSER_PROTO	0x80000037
368 #define ICE_SID_LBL_TXPARSER_PROTO	0x80000038
369 /* The following define MUST be updated to reflect the last label section ID */
370 #define ICE_SID_LBL_LAST		0x80000038
371 
372 /* Label ICE runtime configuration section IDs */
373 #define ICE_SID_TX_5_LAYER_TOPO		0x10
374 
375 enum ice_block {
376 	ICE_BLK_SW = 0,
377 	ICE_BLK_ACL,
378 	ICE_BLK_FD,
379 	ICE_BLK_RSS,
380 	ICE_BLK_PE,
381 	ICE_BLK_COUNT
382 };
383 
384 enum ice_sect {
385 	ICE_XLT0 = 0,
386 	ICE_XLT_KB,
387 	ICE_XLT1,
388 	ICE_XLT2,
389 	ICE_PROF_TCAM,
390 	ICE_PROF_REDIR,
391 	ICE_VEC_TBL,
392 	ICE_CDID_KB,
393 	ICE_CDID_REDIR,
394 	ICE_SECT_COUNT
395 };
396 
397 /* package buffer building */
398 
399 struct ice_buf_build {
400 	struct ice_buf buf;
401 	u16 reserved_section_table_entries;
402 };
403 
404 struct ice_pkg_enum {
405 	struct ice_buf_table *buf_table;
406 	u32 buf_idx;
407 
408 	u32 type;
409 	struct ice_buf_hdr *buf;
410 	u32 sect_idx;
411 	void *sect;
412 	u32 sect_type;
413 
414 	u32 entry_idx;
415 	void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset);
416 };
417 
418 struct ice_hw;
419 
420 int
421 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access);
422 void ice_release_change_lock(struct ice_hw *hw);
423 
424 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw);
425 void *
426 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size);
427 int
428 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count);
429 int
430 ice_get_sw_fv_list(struct ice_hw *hw, struct ice_prot_lkup_ext *lkups,
431 		   ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list);
432 int
433 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count);
434 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld);
435 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld);
436 
437 int
438 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
439 int
440 ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
441 void ice_release_global_cfg_lock(struct ice_hw *hw);
442 struct ice_generic_seg_hdr *
443 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
444 		    struct ice_pkg_hdr *pkg_hdr);
445 enum ice_ddp_state
446 ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len);
447 enum ice_ddp_state
448 ice_get_pkg_info(struct ice_hw *hw);
449 void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg);
450 struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg);
451 int
452 ice_acquire_global_cfg_lock(struct ice_hw *hw,
453 			    enum ice_aq_res_access_type access);
454 
455 struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg);
456 struct ice_buf_hdr *
457 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state);
458 bool
459 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state);
460 void *
461 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
462 		   u32 sect_type, u32 *offset,
463 		   void *(*handler)(u32 sect_type, void *section,
464 				    u32 index, u32 *offset));
465 void *
466 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
467 		     u32 sect_type);
468 enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buff, u32 len);
469 enum ice_ddp_state
470 ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len);
471 bool ice_is_init_pkg_successful(enum ice_ddp_state state);
472 void ice_free_seg(struct ice_hw *hw);
473 
474 struct ice_buf_build *
475 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size,
476 				 void **section);
477 struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld);
478 void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld);
479 
480 int ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len);
481 
482 #endif /* _ICE_DDP_H_ */
483