xref: /linux/drivers/net/ethernet/intel/ice/ice_ddp.h (revision be239684b18e1cdcafcf8c7face4a2f562c745ad)
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_MARKER_PTYPE 55
265 #define ICE_SID_RXPARSER_BOOST_TCAM 56
266 #define ICE_SID_RXPARSER_METADATA_INIT 58
267 #define ICE_SID_TXPARSER_BOOST_TCAM 66
268 
269 #define ICE_SID_XLT0_PE 80
270 #define ICE_SID_XLT_KEY_BUILDER_PE 81
271 #define ICE_SID_XLT1_PE 82
272 #define ICE_SID_XLT2_PE 83
273 #define ICE_SID_PROFID_TCAM_PE 84
274 #define ICE_SID_PROFID_REDIR_PE 85
275 #define ICE_SID_FLD_VEC_PE 86
276 #define ICE_SID_CDID_KEY_BUILDER_PE 87
277 #define ICE_SID_CDID_REDIR_PE 88
278 
279 /* Label Metadata section IDs */
280 #define ICE_SID_LBL_FIRST 0x80000010
281 #define ICE_SID_LBL_RXPARSER_TMEM 0x80000018
282 /* The following define MUST be updated to reflect the last label section ID */
283 #define ICE_SID_LBL_LAST 0x80000038
284 
285 /* Label ICE runtime configuration section IDs */
286 #define ICE_SID_TX_5_LAYER_TOPO 0x10
287 
288 enum ice_block {
289 	ICE_BLK_SW = 0,
290 	ICE_BLK_ACL,
291 	ICE_BLK_FD,
292 	ICE_BLK_RSS,
293 	ICE_BLK_PE,
294 	ICE_BLK_COUNT
295 };
296 
297 enum ice_sect {
298 	ICE_XLT0 = 0,
299 	ICE_XLT_KB,
300 	ICE_XLT1,
301 	ICE_XLT2,
302 	ICE_PROF_TCAM,
303 	ICE_PROF_REDIR,
304 	ICE_VEC_TBL,
305 	ICE_CDID_KB,
306 	ICE_CDID_REDIR,
307 	ICE_SECT_COUNT
308 };
309 
310 /* package labels */
311 struct ice_label {
312 	__le16 value;
313 #define ICE_PKG_LABEL_SIZE 64
314 	char name[ICE_PKG_LABEL_SIZE];
315 };
316 
317 struct ice_label_section {
318 	__le16 count;
319 	struct ice_label label[];
320 };
321 
322 #define ICE_MAX_LABELS_IN_BUF                                             \
323 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_label_section,  \
324 					   label, 1) -                    \
325 				       sizeof(struct ice_label),          \
326 			       sizeof(struct ice_label))
327 
328 struct ice_sw_fv_section {
329 	__le16 count;
330 	__le16 base_offset;
331 	struct ice_fv fv[];
332 };
333 
334 struct ice_sw_fv_list_entry {
335 	struct list_head list_entry;
336 	u32 profile_id;
337 	struct ice_fv *fv_ptr;
338 };
339 
340 /* The BOOST TCAM stores the match packet header in reverse order, meaning
341  * the fields are reversed; in addition, this means that the normally big endian
342  * fields of the packet are now little endian.
343  */
344 struct ice_boost_key_value {
345 #define ICE_BOOST_REMAINING_HV_KEY 15
346 	u8 remaining_hv_key[ICE_BOOST_REMAINING_HV_KEY];
347 	__le16 hv_dst_port_key;
348 	__le16 hv_src_port_key;
349 	u8 tcam_search_key;
350 } __packed;
351 
352 struct ice_boost_key {
353 	struct ice_boost_key_value key;
354 	struct ice_boost_key_value key2;
355 };
356 
357 /* package Boost TCAM entry */
358 struct ice_boost_tcam_entry {
359 	__le16 addr;
360 	__le16 reserved;
361 	/* break up the 40 bytes of key into different fields */
362 	struct ice_boost_key key;
363 	u8 boost_hit_index_group;
364 	/* The following contains bitfields which are not on byte boundaries.
365 	 * These fields are currently unused by driver software.
366 	 */
367 #define ICE_BOOST_BIT_FIELDS 43
368 	u8 bit_fields[ICE_BOOST_BIT_FIELDS];
369 };
370 
371 struct ice_boost_tcam_section {
372 	__le16 count;
373 	__le16 reserved;
374 	struct ice_boost_tcam_entry tcam[];
375 };
376 
377 #define ICE_MAX_BST_TCAMS_IN_BUF                                               \
378 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_boost_tcam_section,  \
379 					   tcam, 1) -                          \
380 				       sizeof(struct ice_boost_tcam_entry),    \
381 			       sizeof(struct ice_boost_tcam_entry))
382 
383 /* package Marker Ptype TCAM entry */
384 struct ice_marker_ptype_tcam_entry {
385 #define ICE_MARKER_PTYPE_TCAM_ADDR_MAX 1024
386 	__le16 addr;
387 	__le16 ptype;
388 	u8 keys[20];
389 };
390 
391 struct ice_marker_ptype_tcam_section {
392 	__le16 count;
393 	__le16 reserved;
394 	struct ice_marker_ptype_tcam_entry tcam[];
395 };
396 
397 #define ICE_MAX_MARKER_PTYPE_TCAMS_IN_BUF                                    \
398 	ICE_MAX_ENTRIES_IN_BUF(struct_size_t(struct ice_marker_ptype_tcam_section,  tcam, \
399 			    1) -                                             \
400 			sizeof(struct ice_marker_ptype_tcam_entry),          \
401 		sizeof(struct ice_marker_ptype_tcam_entry))
402 
403 struct ice_xlt1_section {
404 	__le16 count;
405 	__le16 offset;
406 	u8 value[];
407 };
408 
409 struct ice_xlt2_section {
410 	__le16 count;
411 	__le16 offset;
412 	__le16 value[];
413 };
414 
415 struct ice_prof_redir_section {
416 	__le16 count;
417 	__le16 offset;
418 	u8 redir_value[];
419 };
420 
421 /* package buffer building */
422 
423 struct ice_buf_build {
424 	struct ice_buf buf;
425 	u16 reserved_section_table_entries;
426 };
427 
428 struct ice_pkg_enum {
429 	struct ice_buf_table *buf_table;
430 	u32 buf_idx;
431 
432 	u32 type;
433 	struct ice_buf_hdr *buf;
434 	u32 sect_idx;
435 	void *sect;
436 	u32 sect_type;
437 
438 	u32 entry_idx;
439 	void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset);
440 };
441 
442 int ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
443 			  u16 buf_size, struct ice_sq_cd *cd);
444 
445 void *ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size);
446 
447 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw);
448 
449 int ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
450 int ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
451 
452 int ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count);
453 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld);
454 void *ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
455 			   u32 sect_type);
456 
457 #endif
458