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