xref: /linux/drivers/net/ethernet/intel/ice/ice_ddp.h (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
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 /* generic segment */
102 struct ice_generic_seg_hdr {
103 #define SEGMENT_TYPE_METADATA 0x00000001
104 #define SEGMENT_TYPE_ICE 0x00000010
105 	__le32 seg_type;
106 	struct ice_pkg_ver seg_format_ver;
107 	__le32 seg_size;
108 	char seg_id[ICE_PKG_NAME_SIZE];
109 };
110 
111 /* ice specific segment */
112 
113 union ice_device_id {
114 	struct {
115 		__le16 device_id;
116 		__le16 vendor_id;
117 	} dev_vend_id;
118 	__le32 id;
119 };
120 
121 struct ice_device_id_entry {
122 	union ice_device_id device;
123 	union ice_device_id sub_device;
124 };
125 
126 struct ice_seg {
127 	struct ice_generic_seg_hdr hdr;
128 	__le32 device_table_count;
129 	struct ice_device_id_entry device_table[];
130 };
131 
132 struct ice_nvm_table {
133 	__le32 table_count;
134 	__le32 vers[];
135 };
136 
137 struct ice_buf {
138 #define ICE_PKG_BUF_SIZE 4096
139 	u8 buf[ICE_PKG_BUF_SIZE];
140 };
141 
142 struct ice_buf_table {
143 	__le32 buf_count;
144 	struct ice_buf buf_array[];
145 };
146 
147 struct ice_run_time_cfg_seg {
148 	struct ice_generic_seg_hdr hdr;
149 	u8 rsvd[8];
150 	struct ice_buf_table buf_table;
151 };
152 
153 /* global metadata specific segment */
154 struct ice_global_metadata_seg {
155 	struct ice_generic_seg_hdr hdr;
156 	struct ice_pkg_ver pkg_ver;
157 	__le32 rsvd;
158 	char pkg_name[ICE_PKG_NAME_SIZE];
159 };
160 
161 #define ICE_MIN_S_OFF 12
162 #define ICE_MAX_S_OFF 4095
163 #define ICE_MIN_S_SZ 1
164 #define ICE_MAX_S_SZ 4084
165 
166 /* section information */
167 struct ice_section_entry {
168 	__le32 type;
169 	__le16 offset;
170 	__le16 size;
171 };
172 
173 #define ICE_MIN_S_COUNT 1
174 #define ICE_MAX_S_COUNT 511
175 #define ICE_MIN_S_DATA_END 12
176 #define ICE_MAX_S_DATA_END 4096
177 
178 #define ICE_METADATA_BUF 0x80000000
179 
180 struct ice_buf_hdr {
181 	__le16 section_count;
182 	__le16 data_end;
183 	struct ice_section_entry section_entry[];
184 };
185 
186 #define ICE_MAX_ENTRIES_IN_BUF(hd_sz, ent_sz)                                 \
187 	((ICE_PKG_BUF_SIZE -                                                  \
188 	  struct_size((struct ice_buf_hdr *)0, section_entry, 1) - (hd_sz)) / \
189 	 (ent_sz))
190 
191 /* ice package section IDs */
192 #define ICE_SID_METADATA 1
193 #define ICE_SID_XLT0_SW 10
194 #define ICE_SID_XLT_KEY_BUILDER_SW 11
195 #define ICE_SID_XLT1_SW 12
196 #define ICE_SID_XLT2_SW 13
197 #define ICE_SID_PROFID_TCAM_SW 14
198 #define ICE_SID_PROFID_REDIR_SW 15
199 #define ICE_SID_FLD_VEC_SW 16
200 #define ICE_SID_CDID_KEY_BUILDER_SW 17
201 
202 struct ice_meta_sect {
203 	struct ice_pkg_ver ver;
204 #define ICE_META_SECT_NAME_SIZE 28
205 	char name[ICE_META_SECT_NAME_SIZE];
206 	__le32 track_id;
207 };
208 
209 #define ICE_SID_CDID_REDIR_SW 18
210 
211 #define ICE_SID_XLT0_ACL 20
212 #define ICE_SID_XLT_KEY_BUILDER_ACL 21
213 #define ICE_SID_XLT1_ACL 22
214 #define ICE_SID_XLT2_ACL 23
215 #define ICE_SID_PROFID_TCAM_ACL 24
216 #define ICE_SID_PROFID_REDIR_ACL 25
217 #define ICE_SID_FLD_VEC_ACL 26
218 #define ICE_SID_CDID_KEY_BUILDER_ACL 27
219 #define ICE_SID_CDID_REDIR_ACL 28
220 
221 #define ICE_SID_XLT0_FD 30
222 #define ICE_SID_XLT_KEY_BUILDER_FD 31
223 #define ICE_SID_XLT1_FD 32
224 #define ICE_SID_XLT2_FD 33
225 #define ICE_SID_PROFID_TCAM_FD 34
226 #define ICE_SID_PROFID_REDIR_FD 35
227 #define ICE_SID_FLD_VEC_FD 36
228 #define ICE_SID_CDID_KEY_BUILDER_FD 37
229 #define ICE_SID_CDID_REDIR_FD 38
230 
231 #define ICE_SID_XLT0_RSS 40
232 #define ICE_SID_XLT_KEY_BUILDER_RSS 41
233 #define ICE_SID_XLT1_RSS 42
234 #define ICE_SID_XLT2_RSS 43
235 #define ICE_SID_PROFID_TCAM_RSS 44
236 #define ICE_SID_PROFID_REDIR_RSS 45
237 #define ICE_SID_FLD_VEC_RSS 46
238 #define ICE_SID_CDID_KEY_BUILDER_RSS 47
239 #define ICE_SID_CDID_REDIR_RSS 48
240 
241 #define ICE_SID_RXPARSER_MARKER_PTYPE 55
242 #define ICE_SID_RXPARSER_BOOST_TCAM 56
243 #define ICE_SID_RXPARSER_METADATA_INIT 58
244 #define ICE_SID_TXPARSER_BOOST_TCAM 66
245 
246 #define ICE_SID_XLT0_PE 80
247 #define ICE_SID_XLT_KEY_BUILDER_PE 81
248 #define ICE_SID_XLT1_PE 82
249 #define ICE_SID_XLT2_PE 83
250 #define ICE_SID_PROFID_TCAM_PE 84
251 #define ICE_SID_PROFID_REDIR_PE 85
252 #define ICE_SID_FLD_VEC_PE 86
253 #define ICE_SID_CDID_KEY_BUILDER_PE 87
254 #define ICE_SID_CDID_REDIR_PE 88
255 
256 /* Label Metadata section IDs */
257 #define ICE_SID_LBL_FIRST 0x80000010
258 #define ICE_SID_LBL_RXPARSER_TMEM 0x80000018
259 /* The following define MUST be updated to reflect the last label section ID */
260 #define ICE_SID_LBL_LAST 0x80000038
261 
262 /* Label ICE runtime configuration section IDs */
263 #define ICE_SID_TX_5_LAYER_TOPO 0x10
264 
265 enum ice_block {
266 	ICE_BLK_SW = 0,
267 	ICE_BLK_ACL,
268 	ICE_BLK_FD,
269 	ICE_BLK_RSS,
270 	ICE_BLK_PE,
271 	ICE_BLK_COUNT
272 };
273 
274 enum ice_sect {
275 	ICE_XLT0 = 0,
276 	ICE_XLT_KB,
277 	ICE_XLT1,
278 	ICE_XLT2,
279 	ICE_PROF_TCAM,
280 	ICE_PROF_REDIR,
281 	ICE_VEC_TBL,
282 	ICE_CDID_KB,
283 	ICE_CDID_REDIR,
284 	ICE_SECT_COUNT
285 };
286 
287 /* package labels */
288 struct ice_label {
289 	__le16 value;
290 #define ICE_PKG_LABEL_SIZE 64
291 	char name[ICE_PKG_LABEL_SIZE];
292 };
293 
294 struct ice_label_section {
295 	__le16 count;
296 	struct ice_label label[];
297 };
298 
299 #define ICE_MAX_LABELS_IN_BUF                                             \
300 	ICE_MAX_ENTRIES_IN_BUF(struct_size((struct ice_label_section *)0, \
301 					   label, 1) -                    \
302 				       sizeof(struct ice_label),          \
303 			       sizeof(struct ice_label))
304 
305 struct ice_sw_fv_section {
306 	__le16 count;
307 	__le16 base_offset;
308 	struct ice_fv fv[];
309 };
310 
311 struct ice_sw_fv_list_entry {
312 	struct list_head list_entry;
313 	u32 profile_id;
314 	struct ice_fv *fv_ptr;
315 };
316 
317 /* The BOOST TCAM stores the match packet header in reverse order, meaning
318  * the fields are reversed; in addition, this means that the normally big endian
319  * fields of the packet are now little endian.
320  */
321 struct ice_boost_key_value {
322 #define ICE_BOOST_REMAINING_HV_KEY 15
323 	u8 remaining_hv_key[ICE_BOOST_REMAINING_HV_KEY];
324 	__le16 hv_dst_port_key;
325 	__le16 hv_src_port_key;
326 	u8 tcam_search_key;
327 } __packed;
328 
329 struct ice_boost_key {
330 	struct ice_boost_key_value key;
331 	struct ice_boost_key_value key2;
332 };
333 
334 /* package Boost TCAM entry */
335 struct ice_boost_tcam_entry {
336 	__le16 addr;
337 	__le16 reserved;
338 	/* break up the 40 bytes of key into different fields */
339 	struct ice_boost_key key;
340 	u8 boost_hit_index_group;
341 	/* The following contains bitfields which are not on byte boundaries.
342 	 * These fields are currently unused by driver software.
343 	 */
344 #define ICE_BOOST_BIT_FIELDS 43
345 	u8 bit_fields[ICE_BOOST_BIT_FIELDS];
346 };
347 
348 struct ice_boost_tcam_section {
349 	__le16 count;
350 	__le16 reserved;
351 	struct ice_boost_tcam_entry tcam[];
352 };
353 
354 #define ICE_MAX_BST_TCAMS_IN_BUF                                               \
355 	ICE_MAX_ENTRIES_IN_BUF(struct_size((struct ice_boost_tcam_section *)0, \
356 					   tcam, 1) -                          \
357 				       sizeof(struct ice_boost_tcam_entry),    \
358 			       sizeof(struct ice_boost_tcam_entry))
359 
360 /* package Marker Ptype TCAM entry */
361 struct ice_marker_ptype_tcam_entry {
362 #define ICE_MARKER_PTYPE_TCAM_ADDR_MAX 1024
363 	__le16 addr;
364 	__le16 ptype;
365 	u8 keys[20];
366 };
367 
368 struct ice_marker_ptype_tcam_section {
369 	__le16 count;
370 	__le16 reserved;
371 	struct ice_marker_ptype_tcam_entry tcam[];
372 };
373 
374 #define ICE_MAX_MARKER_PTYPE_TCAMS_IN_BUF                                    \
375 	ICE_MAX_ENTRIES_IN_BUF(                                              \
376 		struct_size((struct ice_marker_ptype_tcam_section *)0, tcam, \
377 			    1) -                                             \
378 			sizeof(struct ice_marker_ptype_tcam_entry),          \
379 		sizeof(struct ice_marker_ptype_tcam_entry))
380 
381 struct ice_xlt1_section {
382 	__le16 count;
383 	__le16 offset;
384 	u8 value[];
385 };
386 
387 struct ice_xlt2_section {
388 	__le16 count;
389 	__le16 offset;
390 	__le16 value[];
391 };
392 
393 struct ice_prof_redir_section {
394 	__le16 count;
395 	__le16 offset;
396 	u8 redir_value[];
397 };
398 
399 /* package buffer building */
400 
401 struct ice_buf_build {
402 	struct ice_buf buf;
403 	u16 reserved_section_table_entries;
404 };
405 
406 struct ice_pkg_enum {
407 	struct ice_buf_table *buf_table;
408 	u32 buf_idx;
409 
410 	u32 type;
411 	struct ice_buf_hdr *buf;
412 	u32 sect_idx;
413 	void *sect;
414 	u32 sect_type;
415 
416 	u32 entry_idx;
417 	void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset);
418 };
419 
420 int ice_aq_download_pkg(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
421 			u16 buf_size, bool last_buf, u32 *error_offset,
422 			u32 *error_info, struct ice_sq_cd *cd);
423 int ice_aq_upload_section(struct ice_hw *hw, struct ice_buf_hdr *pkg_buf,
424 			  u16 buf_size, struct ice_sq_cd *cd);
425 
426 void *ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size);
427 
428 enum ice_ddp_state ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len);
429 
430 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw);
431 
432 struct ice_generic_seg_hdr *ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type,
433 						struct ice_pkg_hdr *pkg_hdr);
434 
435 int ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
436 int ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count);
437 
438 int ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count);
439 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld);
440 void *ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state,
441 			   u32 sect_type);
442 
443 struct ice_buf_hdr *ice_pkg_val_buf(struct ice_buf *buf);
444 
445 #endif
446