xref: /linux/drivers/net/ethernet/intel/ice/ice_ddp.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2022, Intel Corporation. */
3 
4 #ifndef _ICE_DDP_H_
5 #define _ICE_DDP_H_
6 
7 #include "ice_type.h"
8 
9 /* Package minimal version supported */
10 #define ICE_PKG_SUPP_VER_MAJ 1
11 #define ICE_PKG_SUPP_VER_MNR 3
12 
13 /* Package format version */
14 #define ICE_PKG_FMT_VER_MAJ 1
15 #define ICE_PKG_FMT_VER_MNR 0
16 #define ICE_PKG_FMT_VER_UPD 0
17 #define ICE_PKG_FMT_VER_DFT 0
18 
19 #define ICE_PKG_CNT 4
20 
21 #define ICE_FV_OFFSET_INVAL 0x1FF
22 
23 /* Extraction Sequence (Field Vector) Table */
24 struct ice_fv_word {
25 	u8 prot_id;
26 	u16 off; /* Offset within the protocol header */
27 	u8 resvrd;
28 } __packed;
29 
30 #define ICE_MAX_NUM_PROFILES 256
31 
32 #define ICE_MAX_FV_WORDS 48
33 struct ice_fv {
34 	struct ice_fv_word ew[ICE_MAX_FV_WORDS];
35 };
36 
37 enum ice_ddp_state {
38 	/* Indicates that this call to ice_init_pkg
39 	 * successfully loaded the requested DDP package
40 	 */
41 	ICE_DDP_PKG_SUCCESS = 0,
42 
43 	/* Generic error for already loaded errors, it is mapped later to
44 	 * the more specific one (one of the next 3)
45 	 */
46 	ICE_DDP_PKG_ALREADY_LOADED = -1,
47 
48 	/* Indicates that a DDP package of the same version has already been
49 	 * loaded onto the device by a previous call or by another PF
50 	 */
51 	ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED = -2,
52 
53 	/* The device has a DDP package that is not supported by the driver */
54 	ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED = -3,
55 
56 	/* The device has a compatible package
57 	 * (but different from the request) already loaded
58 	 */
59 	ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED = -4,
60 
61 	/* The firmware loaded on the device is not compatible with
62 	 * the DDP package loaded
63 	 */
64 	ICE_DDP_PKG_FW_MISMATCH = -5,
65 
66 	/* The DDP package file is invalid */
67 	ICE_DDP_PKG_INVALID_FILE = -6,
68 
69 	/* The version of the DDP package provided is higher than
70 	 * the driver supports
71 	 */
72 	ICE_DDP_PKG_FILE_VERSION_TOO_HIGH = -7,
73 
74 	/* The version of the DDP package provided is lower than the
75 	 * driver supports
76 	 */
77 	ICE_DDP_PKG_FILE_VERSION_TOO_LOW = -8,
78 
79 	/* The signature of the DDP package file provided is invalid */
80 	ICE_DDP_PKG_FILE_SIGNATURE_INVALID = -9,
81 
82 	/* The DDP package file security revision is too low and not
83 	 * supported by firmware
84 	 */
85 	ICE_DDP_PKG_FILE_REVISION_TOO_LOW = -10,
86 
87 	/* An error occurred in firmware while loading the DDP package */
88 	ICE_DDP_PKG_LOAD_ERROR = -11,
89 
90 	/* Other errors */
91 	ICE_DDP_PKG_ERR = -12
92 };
93 
94 /* Package and segment headers and tables */
95 struct ice_pkg_hdr {
96 	struct ice_pkg_ver pkg_format_ver;
97 	__le32 seg_count;
98 	__le32 seg_offset[];
99 };
100 
101 /* Package signing algorithm types */
102 #define SEGMENT_SIGN_TYPE_INVALID	0x00000000
103 #define SEGMENT_SIGN_TYPE_RSA2K		0x00000001
104 #define SEGMENT_SIGN_TYPE_RSA3K		0x00000002
105 #define SEGMENT_SIGN_TYPE_RSA3K_SBB	0x00000003 /* Secure Boot Block */
106 #define SEGMENT_SIGN_TYPE_RSA3K_E825	0x00000005
107 
108 /* generic segment */
109 struct ice_generic_seg_hdr {
110 #define SEGMENT_TYPE_INVALID	0x00000000
111 #define SEGMENT_TYPE_METADATA	0x00000001
112 #define SEGMENT_TYPE_ICE_E810	0x00000010
113 #define SEGMENT_TYPE_SIGNING	0x00001001
114 #define SEGMENT_TYPE_ICE_RUN_TIME_CFG 0x00000020
115 #define SEGMENT_TYPE_ICE_E830	0x00000017
116 	__le32 seg_type;
117 	struct ice_pkg_ver seg_format_ver;
118 	__le32 seg_size;
119 	char seg_id[ICE_PKG_NAME_SIZE];
120 };
121 
122 /* ice specific segment */
123 
124 union ice_device_id {
125 	struct {
126 		__le16 device_id;
127 		__le16 vendor_id;
128 	} dev_vend_id;
129 	__le32 id;
130 };
131 
132 struct ice_device_id_entry {
133 	union ice_device_id device;
134 	union ice_device_id sub_device;
135 };
136 
137 struct ice_seg {
138 	struct ice_generic_seg_hdr hdr;
139 	__le32 device_table_count;
140 	struct ice_device_id_entry device_table[];
141 };
142 
143 struct ice_nvm_table {
144 	__le32 table_count;
145 	__le32 vers[];
146 };
147 
148 struct ice_buf {
149 #define ICE_PKG_BUF_SIZE 4096
150 	u8 buf[ICE_PKG_BUF_SIZE];
151 };
152 
153 struct ice_buf_table {
154 	__le32 buf_count;
155 	struct ice_buf buf_array[];
156 };
157 
158 struct ice_run_time_cfg_seg {
159 	struct ice_generic_seg_hdr hdr;
160 	u8 rsvd[8];
161 	struct ice_buf_table buf_table;
162 };
163 
164 /* global metadata specific segment */
165 struct ice_global_metadata_seg {
166 	struct ice_generic_seg_hdr hdr;
167 	struct ice_pkg_ver pkg_ver;
168 	__le32 rsvd;
169 	char pkg_name[ICE_PKG_NAME_SIZE];
170 };
171 
172 #define ICE_MIN_S_OFF 12
173 #define ICE_MAX_S_OFF 4095
174 #define ICE_MIN_S_SZ 1
175 #define ICE_MAX_S_SZ 4084
176 
177 struct ice_sign_seg {
178 	struct ice_generic_seg_hdr hdr;
179 	__le32 seg_id;
180 	__le32 sign_type;
181 	__le32 signed_seg_idx;
182 	__le32 signed_buf_start;
183 	__le32 signed_buf_count;
184 #define ICE_SIGN_SEG_RESERVED_COUNT	44
185 	u8 reserved[ICE_SIGN_SEG_RESERVED_COUNT];
186 	struct ice_buf_table buf_tbl;
187 };
188 
189 /* section information */
190 struct ice_section_entry {
191 	__le32 type;
192 	__le16 offset;
193 	__le16 size;
194 };
195 
196 #define ICE_MIN_S_COUNT 1
197 #define ICE_MAX_S_COUNT 511
198 #define ICE_MIN_S_DATA_END 12
199 #define ICE_MAX_S_DATA_END 4096
200 
201 #define ICE_METADATA_BUF 0x80000000
202 
203 struct ice_buf_hdr {
204 	__le16 section_count;
205 	__le16 data_end;
206 	struct ice_section_entry section_entry[];
207 };
208 
209 #define ICE_MAX_ENTRIES_IN_BUF(hd_sz, ent_sz)                                 \
210 	((ICE_PKG_BUF_SIZE -                                                  \
211 	  struct_size_t(struct ice_buf_hdr,  section_entry, 1) - (hd_sz)) / \
212 	 (ent_sz))
213 
214 /* ice package section IDs */
215 #define ICE_SID_METADATA 1
216 #define ICE_SID_XLT0_SW 10
217 #define ICE_SID_XLT_KEY_BUILDER_SW 11
218 #define ICE_SID_XLT1_SW 12
219 #define ICE_SID_XLT2_SW 13
220 #define ICE_SID_PROFID_TCAM_SW 14
221 #define ICE_SID_PROFID_REDIR_SW 15
222 #define ICE_SID_FLD_VEC_SW 16
223 #define ICE_SID_CDID_KEY_BUILDER_SW 17
224 
225 struct ice_meta_sect {
226 	struct ice_pkg_ver ver;
227 #define ICE_META_SECT_NAME_SIZE 28
228 	char name[ICE_META_SECT_NAME_SIZE];
229 	__le32 track_id;
230 };
231 
232 #define ICE_SID_CDID_REDIR_SW 18
233 
234 #define ICE_SID_XLT0_ACL 20
235 #define ICE_SID_XLT_KEY_BUILDER_ACL 21
236 #define ICE_SID_XLT1_ACL 22
237 #define ICE_SID_XLT2_ACL 23
238 #define ICE_SID_PROFID_TCAM_ACL 24
239 #define ICE_SID_PROFID_REDIR_ACL 25
240 #define ICE_SID_FLD_VEC_ACL 26
241 #define ICE_SID_CDID_KEY_BUILDER_ACL 27
242 #define ICE_SID_CDID_REDIR_ACL 28
243 
244 #define ICE_SID_XLT0_FD 30
245 #define ICE_SID_XLT_KEY_BUILDER_FD 31
246 #define ICE_SID_XLT1_FD 32
247 #define ICE_SID_XLT2_FD 33
248 #define ICE_SID_PROFID_TCAM_FD 34
249 #define ICE_SID_PROFID_REDIR_FD 35
250 #define ICE_SID_FLD_VEC_FD 36
251 #define ICE_SID_CDID_KEY_BUILDER_FD 37
252 #define ICE_SID_CDID_REDIR_FD 38
253 
254 #define ICE_SID_XLT0_RSS 40
255 #define ICE_SID_XLT_KEY_BUILDER_RSS 41
256 #define ICE_SID_XLT1_RSS 42
257 #define ICE_SID_XLT2_RSS 43
258 #define ICE_SID_PROFID_TCAM_RSS 44
259 #define ICE_SID_PROFID_REDIR_RSS 45
260 #define ICE_SID_FLD_VEC_RSS 46
261 #define ICE_SID_CDID_KEY_BUILDER_RSS 47
262 #define ICE_SID_CDID_REDIR_RSS 48
263 
264 #define ICE_SID_RXPARSER_CAM           50
265 #define ICE_SID_RXPARSER_NOMATCH_CAM   51
266 #define ICE_SID_RXPARSER_IMEM          52
267 #define ICE_SID_RXPARSER_MARKER_PTYPE 55
268 #define ICE_SID_RXPARSER_BOOST_TCAM 56
269 #define ICE_SID_RXPARSER_PROTO_GRP     57
270 #define ICE_SID_RXPARSER_METADATA_INIT 58
271 #define ICE_SID_TXPARSER_BOOST_TCAM 66
272 #define ICE_SID_RXPARSER_MARKER_GRP    72
273 #define ICE_SID_RXPARSER_PG_SPILL      76
274 #define ICE_SID_RXPARSER_NOMATCH_SPILL 78
275 
276 #define ICE_SID_XLT0_PE 80
277 #define ICE_SID_XLT_KEY_BUILDER_PE 81
278 #define ICE_SID_XLT1_PE 82
279 #define ICE_SID_XLT2_PE 83
280 #define ICE_SID_PROFID_TCAM_PE 84
281 #define ICE_SID_PROFID_REDIR_PE 85
282 #define ICE_SID_FLD_VEC_PE 86
283 #define ICE_SID_CDID_KEY_BUILDER_PE 87
284 #define ICE_SID_CDID_REDIR_PE 88
285 
286 #define ICE_SID_RXPARSER_FLAG_REDIR	97
287 /* Label Metadata section IDs */
288 #define ICE_SID_LBL_FIRST 0x80000010
289 #define ICE_SID_LBL_RXPARSER_TMEM 0x80000018
290 /* The following define MUST be updated to reflect the last label section ID */
291 #define ICE_SID_LBL_LAST 0x80000038
292 
293 /* Label ICE runtime configuration section IDs */
294 #define ICE_SID_TX_5_LAYER_TOPO 0x10
295 
296 enum ice_block {
297 	ICE_BLK_SW = 0,
298 	ICE_BLK_ACL,
299 	ICE_BLK_FD,
300 	ICE_BLK_RSS,
301 	ICE_BLK_PE,
302 	ICE_BLK_COUNT
303 };
304 
305 enum ice_sect {
306 	ICE_XLT0 = 0,
307 	ICE_XLT_KB,
308 	ICE_XLT1,
309 	ICE_XLT2,
310 	ICE_PROF_TCAM,
311 	ICE_PROF_REDIR,
312 	ICE_VEC_TBL,
313 	ICE_CDID_KB,
314 	ICE_CDID_REDIR,
315 	ICE_SECT_COUNT
316 };
317 
318 /* package labels */
319 struct ice_label {
320 	__le16 value;
321 #define ICE_PKG_LABEL_SIZE 64
322 	char name[ICE_PKG_LABEL_SIZE];
323 };
324 
325 struct ice_label_section {
326 	__le16 count;
327 	struct ice_label label[];
328 };
329 
330 #define ICE_MAX_LABELS_IN_BUF                                             \
331 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_label_section,  \
332 					   label, 1) -                    \
333 				       sizeof(struct ice_label),          \
334 			       sizeof(struct ice_label))
335 
336 struct ice_sw_fv_section {
337 	__le16 count;
338 	__le16 base_offset;
339 	struct ice_fv fv[];
340 };
341 
342 struct ice_sw_fv_list_entry {
343 	struct list_head list_entry;
344 	u32 profile_id;
345 	struct ice_fv *fv_ptr;
346 };
347 
348 /* The BOOST TCAM stores the match packet header in reverse order, meaning
349  * the fields are reversed; in addition, this means that the normally big endian
350  * fields of the packet are now little endian.
351  */
352 struct ice_boost_key_value {
353 #define ICE_BOOST_REMAINING_HV_KEY 15
354 	u8 remaining_hv_key[ICE_BOOST_REMAINING_HV_KEY];
355 	__le16 hv_dst_port_key;
356 	__le16 hv_src_port_key;
357 	u8 tcam_search_key;
358 } __packed;
359 
360 struct ice_boost_key {
361 	struct ice_boost_key_value key;
362 	struct ice_boost_key_value key2;
363 };
364 
365 /* package Boost TCAM entry */
366 struct ice_boost_tcam_entry {
367 	__le16 addr;
368 	__le16 reserved;
369 	/* break up the 40 bytes of key into different fields */
370 	struct ice_boost_key key;
371 	u8 boost_hit_index_group;
372 	/* The following contains bitfields which are not on byte boundaries.
373 	 * These fields are currently unused by driver software.
374 	 */
375 #define ICE_BOOST_BIT_FIELDS 43
376 	u8 bit_fields[ICE_BOOST_BIT_FIELDS];
377 };
378 
379 struct ice_boost_tcam_section {
380 	__le16 count;
381 	__le16 reserved;
382 	struct ice_boost_tcam_entry tcam[];
383 };
384 
385 #define ICE_MAX_BST_TCAMS_IN_BUF                                               \
386 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_boost_tcam_section,  \
387 					   tcam, 1) -                          \
388 				       sizeof(struct ice_boost_tcam_entry),    \
389 			       sizeof(struct ice_boost_tcam_entry))
390 
391 /* package Marker Ptype TCAM entry */
392 struct ice_marker_ptype_tcam_entry {
393 #define ICE_MARKER_PTYPE_TCAM_ADDR_MAX 1024
394 	__le16 addr;
395 	__le16 ptype;
396 	u8 keys[20];
397 };
398 
399 struct ice_marker_ptype_tcam_section {
400 	__le16 count;
401 	__le16 reserved;
402 	struct ice_marker_ptype_tcam_entry tcam[];
403 };
404 
405 #define ICE_MAX_MARKER_PTYPE_TCAMS_IN_BUF                                    \
406 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_marker_ptype_tcam_section,  tcam, \
407 			    1) -                                             \
408 			sizeof(struct ice_marker_ptype_tcam_entry),          \
409 		sizeof(struct ice_marker_ptype_tcam_entry))
410 
411 struct ice_xlt1_section {
412 	__le16 count;
413 	__le16 offset;
414 	u8 value[];
415 };
416 
417 struct ice_xlt2_section {
418 	__le16 count;
419 	__le16 offset;
420 	__le16 value[];
421 };
422 
423 struct ice_prof_redir_section {
424 	__le16 count;
425 	__le16 offset;
426 	u8 redir_value[];
427 };
428 
429 /* package buffer building */
430 
431 struct ice_buf_build {
432 	struct ice_buf buf;
433 	u16 reserved_section_table_entries;
434 };
435 
436 struct ice_pkg_enum {
437 	struct ice_buf_table *buf_table;
438 	u32 buf_idx;
439 
440 	u32 type;
441 	const struct ice_buf_hdr *buf;
442 	u32 sect_idx;
443 	void *sect;
444 	u32 sect_type;
445 
446 	u32 entry_idx;
447 	void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset);
448 };
449 
450 int ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
451 			  u16 buf_size, struct ice_sq_cd *cd);
452 
453 void *ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size);
454 
455 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw);
456 
457 int ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
458 int ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
459 
460 int ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count);
461 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld);
462 void *
463 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
464 		   u32 sect_type, u32 *offset,
465 		   void *(*handler)(u32 sect_type, void *section,
466 				    u32 index, u32 *offset));
467 void *ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
468 			   u32 sect_type);
469 
470 int ice_cfg_tx_topo(struct ice_hw *hw, const void *buf, u32 len);
471 
472 #endif
473