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_RUN_TIME_CFG 0x00000020 138 __le32 seg_type; 139 struct ice_pkg_ver seg_format_ver; 140 __le32 seg_size; 141 char seg_id[ICE_PKG_NAME_SIZE]; 142 }; 143 144 /* ice specific segment */ 145 146 union ice_device_id { 147 struct { 148 __le16 device_id; 149 __le16 vendor_id; 150 } dev_vend_id; 151 __le32 id; 152 }; 153 154 struct ice_device_id_entry { 155 union ice_device_id device; 156 union ice_device_id sub_device; 157 }; 158 159 struct ice_seg { 160 struct ice_generic_seg_hdr hdr; 161 __le32 device_table_count; 162 struct ice_device_id_entry device_table[STRUCT_HACK_VAR_LEN]; 163 }; 164 165 struct ice_nvm_table { 166 __le32 table_count; 167 __le32 vers[STRUCT_HACK_VAR_LEN]; 168 }; 169 170 struct ice_buf { 171 #define ICE_PKG_BUF_SIZE 4096 172 u8 buf[ICE_PKG_BUF_SIZE]; 173 }; 174 175 struct ice_buf_table { 176 __le32 buf_count; 177 struct ice_buf buf_array[STRUCT_HACK_VAR_LEN]; 178 }; 179 180 struct ice_run_time_cfg_seg { 181 struct ice_generic_seg_hdr hdr; 182 u8 rsvd[8]; 183 struct ice_buf_table buf_table; 184 }; 185 186 /* global metadata specific segment */ 187 struct ice_global_metadata_seg { 188 struct ice_generic_seg_hdr hdr; 189 struct ice_pkg_ver pkg_ver; 190 __le32 rsvd; 191 char pkg_name[ICE_PKG_NAME_SIZE]; 192 }; 193 194 #define ICE_MIN_S_OFF 12 195 #define ICE_MAX_S_OFF 4095 196 #define ICE_MIN_S_SZ 1 197 #define ICE_MAX_S_SZ 4084 198 199 struct ice_sign_seg { 200 struct ice_generic_seg_hdr hdr; 201 __le32 seg_id; 202 __le32 sign_type; 203 __le32 signed_seg_idx; 204 __le32 signed_buf_start; 205 __le32 signed_buf_count; 206 #define ICE_SIGN_SEG_RESERVED_COUNT 44 207 u8 reserved[ICE_SIGN_SEG_RESERVED_COUNT]; 208 struct ice_buf_table buf_tbl; 209 }; 210 211 /* section information */ 212 struct ice_section_entry { 213 __le32 type; 214 __le16 offset; 215 __le16 size; 216 }; 217 218 #define ICE_MIN_S_COUNT 1 219 #define ICE_MAX_S_COUNT 511 220 #define ICE_MIN_S_DATA_END 12 221 #define ICE_MAX_S_DATA_END 4096 222 223 #define ICE_METADATA_BUF 0x80000000 224 225 struct ice_buf_hdr { 226 __le16 section_count; 227 __le16 data_end; 228 struct ice_section_entry section_entry[STRUCT_HACK_VAR_LEN]; 229 }; 230 231 #define ICE_MAX_ENTRIES_IN_BUF(hd_sz, ent_sz) ((ICE_PKG_BUF_SIZE - \ 232 ice_struct_size((struct ice_buf_hdr *)0, section_entry, 1) - (hd_sz)) /\ 233 (ent_sz)) 234 235 /* ice package section IDs */ 236 #define ICE_SID_METADATA 1 237 #define ICE_SID_XLT0_SW 10 238 #define ICE_SID_XLT_KEY_BUILDER_SW 11 239 #define ICE_SID_XLT1_SW 12 240 #define ICE_SID_XLT2_SW 13 241 #define ICE_SID_PROFID_TCAM_SW 14 242 #define ICE_SID_PROFID_REDIR_SW 15 243 #define ICE_SID_FLD_VEC_SW 16 244 #define ICE_SID_CDID_KEY_BUILDER_SW 17 245 #define ICE_SID_CDID_REDIR_SW 18 246 247 #define ICE_SID_XLT0_ACL 20 248 #define ICE_SID_XLT_KEY_BUILDER_ACL 21 249 #define ICE_SID_XLT1_ACL 22 250 #define ICE_SID_XLT2_ACL 23 251 #define ICE_SID_PROFID_TCAM_ACL 24 252 #define ICE_SID_PROFID_REDIR_ACL 25 253 #define ICE_SID_FLD_VEC_ACL 26 254 #define ICE_SID_CDID_KEY_BUILDER_ACL 27 255 #define ICE_SID_CDID_REDIR_ACL 28 256 257 #define ICE_SID_XLT0_FD 30 258 #define ICE_SID_XLT_KEY_BUILDER_FD 31 259 #define ICE_SID_XLT1_FD 32 260 #define ICE_SID_XLT2_FD 33 261 #define ICE_SID_PROFID_TCAM_FD 34 262 #define ICE_SID_PROFID_REDIR_FD 35 263 #define ICE_SID_FLD_VEC_FD 36 264 #define ICE_SID_CDID_KEY_BUILDER_FD 37 265 #define ICE_SID_CDID_REDIR_FD 38 266 267 #define ICE_SID_XLT0_RSS 40 268 #define ICE_SID_XLT_KEY_BUILDER_RSS 41 269 #define ICE_SID_XLT1_RSS 42 270 #define ICE_SID_XLT2_RSS 43 271 #define ICE_SID_PROFID_TCAM_RSS 44 272 #define ICE_SID_PROFID_REDIR_RSS 45 273 #define ICE_SID_FLD_VEC_RSS 46 274 #define ICE_SID_CDID_KEY_BUILDER_RSS 47 275 #define ICE_SID_CDID_REDIR_RSS 48 276 277 #define ICE_SID_RXPARSER_CAM 50 278 #define ICE_SID_RXPARSER_NOMATCH_CAM 51 279 #define ICE_SID_RXPARSER_IMEM 52 280 #define ICE_SID_RXPARSER_XLT0_BUILDER 53 281 #define ICE_SID_RXPARSER_NODE_PTYPE 54 282 #define ICE_SID_RXPARSER_MARKER_PTYPE 55 283 #define ICE_SID_RXPARSER_BOOST_TCAM 56 284 #define ICE_SID_RXPARSER_PROTO_GRP 57 285 #define ICE_SID_RXPARSER_METADATA_INIT 58 286 #define ICE_SID_RXPARSER_XLT0 59 287 288 #define ICE_SID_TXPARSER_CAM 60 289 #define ICE_SID_TXPARSER_NOMATCH_CAM 61 290 #define ICE_SID_TXPARSER_IMEM 62 291 #define ICE_SID_TXPARSER_XLT0_BUILDER 63 292 #define ICE_SID_TXPARSER_NODE_PTYPE 64 293 #define ICE_SID_TXPARSER_MARKER_PTYPE 65 294 #define ICE_SID_TXPARSER_BOOST_TCAM 66 295 #define ICE_SID_TXPARSER_PROTO_GRP 67 296 #define ICE_SID_TXPARSER_METADATA_INIT 68 297 #define ICE_SID_TXPARSER_XLT0 69 298 299 #define ICE_SID_RXPARSER_INIT_REDIR 70 300 #define ICE_SID_TXPARSER_INIT_REDIR 71 301 #define ICE_SID_RXPARSER_MARKER_GRP 72 302 #define ICE_SID_TXPARSER_MARKER_GRP 73 303 #define ICE_SID_RXPARSER_LAST_PROTO 74 304 #define ICE_SID_TXPARSER_LAST_PROTO 75 305 #define ICE_SID_RXPARSER_PG_SPILL 76 306 #define ICE_SID_TXPARSER_PG_SPILL 77 307 #define ICE_SID_RXPARSER_NOMATCH_SPILL 78 308 #define ICE_SID_TXPARSER_NOMATCH_SPILL 79 309 310 #define ICE_SID_XLT0_PE 80 311 #define ICE_SID_XLT_KEY_BUILDER_PE 81 312 #define ICE_SID_XLT1_PE 82 313 #define ICE_SID_XLT2_PE 83 314 #define ICE_SID_PROFID_TCAM_PE 84 315 #define ICE_SID_PROFID_REDIR_PE 85 316 #define ICE_SID_FLD_VEC_PE 86 317 #define ICE_SID_CDID_KEY_BUILDER_PE 87 318 #define ICE_SID_CDID_REDIR_PE 88 319 320 #define ICE_SID_RXPARSER_FLAG_REDIR 97 321 322 /* Label Metadata section IDs */ 323 #define ICE_SID_LBL_FIRST 0x80000010 324 #define ICE_SID_LBL_RXPARSER_IMEM 0x80000010 325 #define ICE_SID_LBL_TXPARSER_IMEM 0x80000011 326 #define ICE_SID_LBL_RESERVED_12 0x80000012 327 #define ICE_SID_LBL_RESERVED_13 0x80000013 328 #define ICE_SID_LBL_RXPARSER_MARKER 0x80000014 329 #define ICE_SID_LBL_TXPARSER_MARKER 0x80000015 330 #define ICE_SID_LBL_PTYPE 0x80000016 331 #define ICE_SID_LBL_PROTOCOL_ID 0x80000017 332 #define ICE_SID_LBL_RXPARSER_TMEM 0x80000018 333 #define ICE_SID_LBL_TXPARSER_TMEM 0x80000019 334 #define ICE_SID_LBL_RXPARSER_PG 0x8000001A 335 #define ICE_SID_LBL_TXPARSER_PG 0x8000001B 336 #define ICE_SID_LBL_RXPARSER_M_TCAM 0x8000001C 337 #define ICE_SID_LBL_TXPARSER_M_TCAM 0x8000001D 338 #define ICE_SID_LBL_SW_PROFID_TCAM 0x8000001E 339 #define ICE_SID_LBL_ACL_PROFID_TCAM 0x8000001F 340 #define ICE_SID_LBL_PE_PROFID_TCAM 0x80000020 341 #define ICE_SID_LBL_RSS_PROFID_TCAM 0x80000021 342 #define ICE_SID_LBL_FD_PROFID_TCAM 0x80000022 343 #define ICE_SID_LBL_FLAG 0x80000023 344 #define ICE_SID_LBL_REG 0x80000024 345 #define ICE_SID_LBL_SW_PTG 0x80000025 346 #define ICE_SID_LBL_ACL_PTG 0x80000026 347 #define ICE_SID_LBL_PE_PTG 0x80000027 348 #define ICE_SID_LBL_RSS_PTG 0x80000028 349 #define ICE_SID_LBL_FD_PTG 0x80000029 350 #define ICE_SID_LBL_SW_VSIG 0x8000002A 351 #define ICE_SID_LBL_ACL_VSIG 0x8000002B 352 #define ICE_SID_LBL_PE_VSIG 0x8000002C 353 #define ICE_SID_LBL_RSS_VSIG 0x8000002D 354 #define ICE_SID_LBL_FD_VSIG 0x8000002E 355 #define ICE_SID_LBL_PTYPE_META 0x8000002F 356 #define ICE_SID_LBL_SW_PROFID 0x80000030 357 #define ICE_SID_LBL_ACL_PROFID 0x80000031 358 #define ICE_SID_LBL_PE_PROFID 0x80000032 359 #define ICE_SID_LBL_RSS_PROFID 0x80000033 360 #define ICE_SID_LBL_FD_PROFID 0x80000034 361 #define ICE_SID_LBL_RXPARSER_MARKER_GRP 0x80000035 362 #define ICE_SID_LBL_TXPARSER_MARKER_GRP 0x80000036 363 #define ICE_SID_LBL_RXPARSER_PROTO 0x80000037 364 #define ICE_SID_LBL_TXPARSER_PROTO 0x80000038 365 /* The following define MUST be updated to reflect the last label section ID */ 366 #define ICE_SID_LBL_LAST 0x80000038 367 368 /* Label ICE runtime configuration section IDs */ 369 #define ICE_SID_TX_5_LAYER_TOPO 0x10 370 371 enum ice_block { 372 ICE_BLK_SW = 0, 373 ICE_BLK_ACL, 374 ICE_BLK_FD, 375 ICE_BLK_RSS, 376 ICE_BLK_PE, 377 ICE_BLK_COUNT 378 }; 379 380 enum ice_sect { 381 ICE_XLT0 = 0, 382 ICE_XLT_KB, 383 ICE_XLT1, 384 ICE_XLT2, 385 ICE_PROF_TCAM, 386 ICE_PROF_REDIR, 387 ICE_VEC_TBL, 388 ICE_CDID_KB, 389 ICE_CDID_REDIR, 390 ICE_SECT_COUNT 391 }; 392 393 /* package buffer building */ 394 395 struct ice_buf_build { 396 struct ice_buf buf; 397 u16 reserved_section_table_entries; 398 }; 399 400 struct ice_pkg_enum { 401 struct ice_buf_table *buf_table; 402 u32 buf_idx; 403 404 u32 type; 405 struct ice_buf_hdr *buf; 406 u32 sect_idx; 407 void *sect; 408 u32 sect_type; 409 410 u32 entry_idx; 411 void *(*handler)(u32 sect_type, void *section, u32 index, u32 *offset); 412 }; 413 414 struct ice_hw; 415 416 enum ice_status 417 ice_acquire_change_lock(struct ice_hw *hw, enum ice_aq_res_access_type access); 418 void ice_release_change_lock(struct ice_hw *hw); 419 420 struct ice_buf_build *ice_pkg_buf_alloc(struct ice_hw *hw); 421 void * 422 ice_pkg_buf_alloc_section(struct ice_buf_build *bld, u32 type, u16 size); 423 enum ice_status 424 ice_pkg_buf_reserve_section(struct ice_buf_build *bld, u16 count); 425 enum ice_status 426 ice_get_sw_fv_list(struct ice_hw *hw, struct ice_prot_lkup_ext *lkups, 427 ice_bitmap_t *bm, struct LIST_HEAD_TYPE *fv_list); 428 enum ice_status 429 ice_pkg_buf_unreserve_section(struct ice_buf_build *bld, u16 count); 430 u16 ice_pkg_buf_get_free_space(struct ice_buf_build *bld); 431 u16 ice_pkg_buf_get_active_sections(struct ice_buf_build *bld); 432 433 enum ice_status 434 ice_update_pkg(struct ice_hw *hw, struct ice_buf *bufs, u32 count); 435 enum ice_status 436 ice_update_pkg_no_lock(struct ice_hw *hw, struct ice_buf *bufs, u32 count); 437 void ice_release_global_cfg_lock(struct ice_hw *hw); 438 struct ice_generic_seg_hdr * 439 ice_find_seg_in_pkg(struct ice_hw *hw, u32 seg_type, 440 struct ice_pkg_hdr *pkg_hdr); 441 enum ice_ddp_state 442 ice_verify_pkg(struct ice_pkg_hdr *pkg, u32 len); 443 enum ice_ddp_state 444 ice_get_pkg_info(struct ice_hw *hw); 445 void ice_init_pkg_hints(struct ice_hw *hw, struct ice_seg *ice_seg); 446 struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg); 447 enum ice_status 448 ice_acquire_global_cfg_lock(struct ice_hw *hw, 449 enum ice_aq_res_access_type access); 450 451 struct ice_buf_table *ice_find_buf_table(struct ice_seg *ice_seg); 452 struct ice_buf_hdr * 453 ice_pkg_enum_buf(struct ice_seg *ice_seg, struct ice_pkg_enum *state); 454 bool 455 ice_pkg_advance_sect(struct ice_seg *ice_seg, struct ice_pkg_enum *state); 456 void * 457 ice_pkg_enum_entry(struct ice_seg *ice_seg, struct ice_pkg_enum *state, 458 u32 sect_type, u32 *offset, 459 void *(*handler)(u32 sect_type, void *section, 460 u32 index, u32 *offset)); 461 void * 462 ice_pkg_enum_section(struct ice_seg *ice_seg, struct ice_pkg_enum *state, 463 u32 sect_type); 464 enum ice_ddp_state ice_init_pkg(struct ice_hw *hw, u8 *buff, u32 len); 465 enum ice_ddp_state 466 ice_copy_and_init_pkg(struct ice_hw *hw, const u8 *buf, u32 len); 467 bool ice_is_init_pkg_successful(enum ice_ddp_state state); 468 void ice_free_seg(struct ice_hw *hw); 469 470 struct ice_buf_build * 471 ice_pkg_buf_alloc_single_section(struct ice_hw *hw, u32 type, u16 size, 472 void **section); 473 struct ice_buf *ice_pkg_buf(struct ice_buf_build *bld); 474 void ice_pkg_buf_free(struct ice_hw *hw, struct ice_buf_build *bld); 475 476 enum ice_status ice_cfg_tx_topo(struct ice_hw *hw, u8 *buf, u32 len); 477 478 #endif /* _ICE_DDP_COMMON_H_ */ 479