kbp_rop.h (14654B)
1 /** \file kbp_rop.h 2 * 3 * Functions and defines for handling jericho2 kbp ROP. 4 */ 5 /* 6 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 7 * 8 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 9 */ 10 #if defined(INCLUDE_KBP) 11 12 #ifndef _KBP_ROP_INCLUDED__ 13 /* 14 * { 15 */ 16 17 #define _KBP_ROP_INCLUDED__ 18 19 /************* 20 * INCLUDES * 21 */ 22 /* 23 * { 24 */ 25 #include <soc/register.h> 26 #include <soc/kbp/nlm3/arch/nlmarch.h> 27 28 #include <soc/dnx/dnx_data/auto_generated/dnx_data_elk.h> 29 #include <soc/dnx/dnx_data/auto_generated/dnx_data_nif.h> 30 #include <soc/dnx/dbal/dbal.h> 31 #include <bcm/port.h> 32 /* 33 * } 34 */ 35 36 /************* 37 * DEFINES * 38 */ 39 /* 40 * { 41 */ 42 43 #define DNX_KBP_CPU_DATA_REGISTER_BYTE_LEN (64) 44 #define DNX_KBP_CPU_LOOKUP_REPLY_DATA_REGISTER_BYTE_LEN (32) 45 46 #define DNX_KBP_MAX_NUM_OF_PARALLEL_SEARCHES (8) 47 48 #define DNX_KBP_ERROR_RETRANMISSION (5) 49 50 #define DNX_KBP_LUT_DATA_ADDR_BIT_LEN (0x8) 51 #define DNX_KBP_LUT_DATA_ADDR_MASK (0xFF) 52 #define DNX_KBP_LUTWR_DATA_ADDR_START_BIT (0) 53 54 #define DNX_KBP_LUT_REC_SIZE_BIT_LEN (0x7) 55 #define DNX_KBP_LUT_REC_SIZE_MASK (0x7F) 56 #define DNX_KBP_LUTWR_REC_SIZE_START_BIT (DNX_KBP_LUT_DATA_ADDR_BIT_LEN + DNX_KBP_LUTWR_DATA_ADDR_START_BIT) 57 #define DNX_KBP_LUTRD_REC_SIZE_START_BIT (0) 58 59 #define DNX_KBP_LUT_REC_VALID_BIT_LEN (0x1) 60 #define DNX_KBP_LUT_REC_VALID_MASK (0x1) 61 #define DNX_KBP_LUTWR_REC_VALID_START_BIT (DNX_KBP_LUTWR_REC_SIZE_START_BIT + DNX_KBP_LUT_REC_SIZE_BIT_LEN) 62 #define DNX_KBP_LUTRD_REC_VALID_START_BIT (DNX_KBP_LUTRD_REC_SIZE_START_BIT + DNX_KBP_LUT_REC_SIZE_BIT_LEN) 63 64 #define DNX_KBP_LUT_MODE_BIT_LEN (0x1) 65 #define DNX_KBP_LUT_MODE_MASK (0x1) 66 #define DNX_KBP_LUTWR_MODE_START_BIT (0) 67 #define DNX_KBP_LUTRD_MODE_START_BIT (DNX_KBP_LUTRD_REC_VALID_START_BIT + DNX_KBP_LUT_REC_VALID_BIT_LEN) 68 69 #define DNX_KBP_LUT_INSTR_BIT_LEN (0xa) 70 #define DNX_KBP_LUT_INSTR_MASK (0x3FF) 71 #define DNX_KBP_LUTWR_INSTR_START_BIT (DNX_KBP_LUTWR_MODE_START_BIT + DNX_KBP_LUT_MODE_BIT_LEN) 72 #define DNX_KBP_LUTRD_INSTR_START_BIT (DNX_KBP_LUTRD_MODE_START_BIT + DNX_KBP_LUT_MODE_BIT_LEN) 73 74 #define DNX_KBP_LUT_LTR_BIT_LEN (0x7) 75 #define DNX_KBP_LUT_LTR_MASK (0x7F) 76 77 #define DNX_KBP_LUT_CMP_INSTR_BIT_LEN (0x1) 78 #define DNX_KBP_LUT_CMP_INSTR_MASK (0x1) 79 #define DNX_KBP_LUTWR_CMP_INSTR_START_BIT (DNX_KBP_LUTWR_MODE_START_BIT + DNX_KBP_LUT_MODE_BIT_LEN + DNX_KBP_LUT_LTR_BIT_LEN) 80 #define DNX_KBP_LUTRD_CMP_INSTR_START_BIT (0) 81 82 #define DNX_KBP_LUT_PROG0_REG_ADDR_PORT0 \ 83 ((Kbp_app_data[unit]->device_type == KBP_DEVICE_OP) ? 0xA005 : 0x2005) 84 #define DNX_KBP_LUT_PROG1_REG_ADDR_PORT0 \ 85 ((Kbp_app_data[unit]->device_type == KBP_DEVICE_OP) ? 0xA006 : 0x2006) 86 #define DNX_KBP_LUT_PROG_REG_DEVAD_PORT0 0x1 87 88 #define DNX_KBP_LUT_RDADDR_REG_ADDR_PORT0 0xA007 89 #define DNX_KBP_LUT_RDATA0_REG_ADDR_PORT0 0xA008 90 #define DNX_KBP_LUT_RDATA1_REG_ADDR_PORT0 0xA009 91 92 #define DNX_KBP_LUT_PROG0_REG_ADDR_PORT1 \ 93 ((Kbp_app_data[unit]->device_type == KBP_DEVICE_OP) ? 0xB005 : 0x2005) 94 #define DNX_KBP_LUT_PROG1_REG_ADDR_PORT1 \ 95 ((Kbp_app_data[unit]->device_type == KBP_DEVICE_OP) ? 0xB006 : 0x2006) 96 #define DNX_KBP_LUT_PROG_REG_DEVAD_PORT1 \ 97 ((Kbp_app_data[unit]->device_type == KBP_DEVICE_OP) ? 0x1 : 0x2) 98 99 #define DNX_KBP_LUT_RDADDR_REG_ADDR_PORT1 0xB007 100 #define DNX_KBP_LUT_RDATA0_REG_ADDR_PORT1 0xB008 101 #define DNX_KBP_LUT_RDATA1_REG_ADDR_PORT1 0xB009 102 103 /* 104 * } 105 */ 106 /************* 107 * MACROS * 108 */ 109 /* 110 * { 111 */ 112 #define DNX_KBP_ROP_REVERSE_DATA(data_in, data_out, len) \ 113 { \ 114 int i; \ 115 for (i = 0; i < len; i++) \ 116 { \ 117 data_out[i] = data_in[len - 1 - i]; \ 118 } \ 119 } \ 120 121 #define DNX_KBP_ROP_LUT_LTR_GET(instr) \ 122 ((instr & 0x3F) | (instr & 0x8000) >> 9) 123 124 #define DNX_KBP_ROP_LUT_INSTR_GET(ltr) \ 125 ((ltr & 0x3f) | (0x001 << 6) | ((ltr & 0x40) << 9)) 126 127 /* 128 * Get ROP packet from DNX side 129 */ 130 #define DNX_KBP_ROP_GET_DNX_SIDE 0x1 131 /* 132 * Get ROP packet from KBP side 133 */ 134 #define DNX_KBP_ROP_GET_KBP_SIDE 0x2 135 136 #define DNX_KBP_ROP_OPCODE_LEN_IN_BYTE 0x1 137 #define DNX_KBP_ROP_SEQ_NUM_LEN_IN_BYTE 0x2 138 139 #define DNX_KBP_ROP_OPCODE_OFFSET 0x0 140 #define DNX_KBP_ROP_SEQ_NUM_OFFSET (DNX_KBP_ROP_OPCODE_OFFSET + DNX_KBP_ROP_OPCODE_LEN_IN_BYTE) 141 #define DNX_KBP_ROP_PAYLOAD_OFFSET (DNX_KBP_ROP_SEQ_NUM_OFFSET + DNX_KBP_ROP_SEQ_NUM_LEN_IN_BYTE) 142 143 /* 144 * } 145 */ 146 147 /************* 148 * ENUMS * 149 */ 150 /* 151 * { 152 */ 153 typedef enum 154 { 155 /* 156 * CB Write 157 */ 158 NLM_DNX_CB_INST_WRITE, 159 /* 160 * CB Write and Compare 1 161 */ 162 NLM_DNX_CB_INST_CMP1, 163 /* 164 * CB Write and Compare 2 165 */ 166 NLM_DNX_CB_INST_CMP2, 167 /* 168 * CB Write and Compare 3 169 */ 170 NLM_DNX_CB_INST_CMP3, 171 /* 172 * CB Write and LPM 173 */ 174 NLM_DNX_CB_INST_LPM, 175 /* 176 * This does not represent any instruction and is used for marking end of the enum 177 */ 178 NLM_DNX_CB_INST_NONE 179 } NlmDnxCBInstType; 180 typedef enum NlmDnxReadMode 181 { 182 /* 183 * The read of a database X value is performed 184 */ 185 NLM_DNX_READ_MODE_DATA_X, 186 /* 187 * The read of a database Y value is performed 188 */ 189 NLM_DNX_READ_MODE_DATA_Y 190 } NlmDnxReadMode; 191 typedef enum NlmDnxWriteMode 192 { 193 /* 194 * The write mode is database-data mask mode 195 */ 196 NLM_DNX_WRITE_MODE_DATABASE_DM, 197 /* 198 * The write mode is database-XY mode 199 */ 200 NLM_DNX_WRITE_MODE_DATABASE_XY 201 } NlmDnxWriteMode; 202 typedef enum NlmDnxCompareResponseFormat 203 { 204 /* 205 * Return only index without Associated Data in the result 206 */ 207 NLM_DNX_ONLY_INDEX_NO_AD = 0x0, 208 /* 209 * Return index + 32b Associated Data in the result 210 */ 211 NLM_DNX_INDEX_AND_32B_AD = 0x1, 212 /* 213 * Return index + 64b Associated Data in the result 214 */ 215 NLM_DNX_INDEX_AND_64B_AD = 0x2, 216 /* 217 * Return index + 128b Associated Data in the result 218 */ 219 NLM_DNX_INDEX_AND_128B_AD = 0x3, 220 /* 221 * Return index + 256b Associated Data in the result 222 */ 223 NLM_DNX_INDEX_AND_256B_AD = 0x4, 224 /* 225 * No result 226 */ 227 NLM_DNX_NO_INDEX_NO_AD = -1 228 } NlmDnxCompareResponseFormat; 229 230 /* 231 * } 232 */ 233 /************* 234 * TYPE DEFS * 235 */ 236 /* 237 * { 238 */ 239 /* 240 * Request Decoder 241 */ 242 typedef struct dnx_kbp_lut_data_t 243 { 244 245 /* 246 * Record Size (max upto 672b=84B) 640b of data + 16b of instr + 16b of contextid 247 */ 248 uint32 rec_size; 249 250 /* 251 * Record Type Options: DNX_KBP_LUT_REC_TYPE_INFO DNX_KBP_LUT_REC_TYPE_REQUEST 252 */ 253 uint32 rec_type; 254 255 /* 256 * Record Is Valid 257 */ 258 uint32 rec_is_valid; 259 260 /* 261 * Request Control 262 */ 263 264 /* 265 * Mode - To be used to construct the instr, contextId and Key to core based on table 1 266 * Options: 267 * DNX_KBP_LUT_INSTR_LUT1_CONTEXID_SEQ_NUM_MODE 268 * DNX_KBP_LUT_INSTR_LUT1_REC_DATA_CONTEXID_SEQ_NUM_MODE 269 * DNX_KBP_LUT_INSTR_REC_DATA_CONTEXID_SEQ_NUM_MODE 270 * DNX_KBP_LUT_INSTR_LUT1_CONTEXID_REC_DATA_MODE 271 * DNX_KBP_LUT_INSTR_REC_DATA_CONTEXID_REC_DATA_MODE 272 */ 273 uint32 mode; 274 275 /* 276 * Key_config 277 * Options: 278 * DNX_KBP_LUT_KEY_CONFIG_APPEND_INCOMING_DATA - This feature makes sense only for Compare kind of instructions 279 * DNX_KBP_LUT_KEY_CONFIG_SEND_INCOMING_DATA 280 */ 281 uint32 key_config; 282 283 /* 284 * Lut Key Data 285 * Data to be used for final key construction. 286 * max value - 0xff 287 */ 288 uint32 lut_key_data; 289 290 /* 291 * Instruction Bits 292 * max_value - 0x3ff 293 */ 294 uint32 instr; 295 296 /* 297 * key_w_cpd_gt_80 298 * Length of key if record data is between 80b and 128b and copy_data > 80b 299 * Options: 300 * DNX_KBP_LUT_KEY_SIZE - 301 * DNX_KBP_LUT_80b_KEY_SIZE - 80b 302 */ 303 uint32 key_w_cpd_gt_80; 304 305 /* 306 * Copy Data Config 307 * Number of bits of Copy Data to be extracted from MSB portion of Record Data (after instr/ctxtId have been extracted 308 * if applicable but before lut_key_data has been appended to form the final key) and attached to reply. 309 * Options: 310 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_16b 311 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_32b 312 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_48b 313 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_64b 314 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_80b 315 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_96b 316 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_112b 317 * DNX_KBP_LUT_EXTR_MSB_PORTION_DATA_128b 318 */ 319 uint32 copy_data_cfg; 320 321 /* 322 * Reply Format 323 */ 324 /* 325 * Resultx Index or AD 326 * Options: 327 * DNX_KBP_LUT_TRANSFER_INDX_ONLY 328 * DNX_KBP_LUT_TRANSFER_AD_ONLY 329 */ 330 331 /* 332 * Resultx Index Ad Cfg 333 * Optiond: 334 * If Index is to be transferred ( resultx_idx_or_ad = DNX_KBP_LUT_TRANSFER_INDX_ONLY): 335 * DNX_KBP_LUT_INDX_TRANSFER_1B 336 * DNX_KBP_LUT_INDX_TRANSFER_2B 337 * DNX_KBP_LUT_INDX_TRANSFER_2B 338 * If AD is to be transferred ( resultx_idx_or_ad = DNX_KBP_LUT_TRANSFER_AD_ONLY): 339 * DNX_KBP_LUT_AD_TRANSFER_1B, DNX_KBP_LUT_AD_TRANSFER_2B... DNX_KBP_LUT_AD_TRANSFER_16B 340 */ 341 uint32 result_idx_ad_cfg[DNX_KBP_MAX_NUM_OF_PARALLEL_SEARCHES]; 342 uint32 result_idx_or_ad[DNX_KBP_MAX_NUM_OF_PARALLEL_SEARCHES]; 343 } dnx_kbp_lut_data_t; 344 typedef struct dnx_kbp_rop_write_s 345 { 346 /* 347 * Address of location where data should be written. includes all :vbit, wrmode ... 348 */ 349 uint8 addr[NLMDEV_REG_ADDR_LEN_IN_BYTES]; 350 /* 351 * The data that should be written 352 */ 353 uint8 data[NLM_DATA_WIDTH_BYTES]; 354 /* 355 * The mask that should be written if it is a database entry 356 */ 357 uint8 mask[NLM_DATA_WIDTH_BYTES]; 358 /* 359 * Address of location where data should be written. includes nothing 360 */ 361 uint8 addr_short[NLMDEV_REG_ADDR_LEN_IN_BYTES]; 362 /* 363 * The valid bit which indicates if the database entry should be enabled or disabled 364 */ 365 uint8 vBit; 366 /* 367 * Write mode which indicates if it is Database X or Y 368 */ 369 NlmDnxWriteMode writeMode; 370 uint32 loop; 371 372 } dnx_kbp_rop_write_t; 373 374 typedef struct dnx_kbp_rop_read_s 375 { 376 /* 377 * Address of the memory location to be read 378 */ 379 uint8 addr[NLMDEV_REG_ADDR_LEN_IN_BYTES]; 380 /* 381 * valid bit for database read 382 */ 383 uint8 vBit; 384 /* 385 * reading data either X or Y 386 */ 387 NlmDnxReadMode dataType; 388 /* 389 * data read will be stored here 390 */ 391 uint8 data[NLM_DATA_WIDTH_BYTES + 1]; 392 } dnx_kbp_rop_read_t; 393 394 typedef struct dnx_kbp_rop_cbw_s 395 { 396 /* 397 * max 640-bit data valid data specified by datalen 398 */ 399 uint8 data[NLM_MAX_CMP_DATA_LEN_BYTES]; 400 /* 401 * data length in Bytes (should be multiple of 10, max value = 80) 402 */ 403 uint32 data_len; 404 } dnx_kbp_rop_cbw_t; 405 406 typedef struct NlmDnxCompareResult 407 { 408 /* 409 * Indicates if the hit or miss are valid or not if no blocks have * been configured for an output port, then 410 * the hit/miss returned is * not valid 411 */ 412 uint8 isResultValid[NLM_MAX_NUM_RESULTS]; 413 /* 414 * Indicates if a hit or miss occured 415 */ 416 uint8 hitOrMiss[NLM_MAX_NUM_RESULTS]; 417 /* 418 * Hit indexes indicating DBA/UDA address 419 */ 420 uint32 hitIndex[NLM_MAX_NUM_RESULTS]; 421 /* 422 * Indicates the size of AD in the result 423 */ 424 NlmDnxCompareResponseFormat responseFormat[NLM_MAX_NUM_RESULTS]; 425 /* 426 * Associated data. If result 0 has 16b associated data, then it will be stored in m_assocData[0][0] and 427 * m_assocData[0][1] 428 */ 429 uint8 assocData[NLM_MAX_NUM_RESULTS][NLM_MAX_SRAM_SB_WIDTH_IN_BYTES]; 430 uint8 data_raw[NLMDEV_MAX_RESP_LEN_IN_BYTES]; 431 } NlmDnxCompareResult; 432 433 typedef struct dnx_kbp_rop_cbw_cmp_s 434 { 435 NlmDnxCBInstType type; 436 uint32 opcode; 437 uint32 ltr; 438 dnx_kbp_rop_cbw_t cbw_data; 439 NlmDnxCompareResult result; 440 } dnx_kbp_rop_cbw_cmp_t; 441 442 typedef struct dnx_kbp_rop_blk_s 443 { 444 uint32 opcode; 445 uint16 loop_cnt; 446 /* 447 * First DB address location 448 */ 449 uint32 src_addr; 450 /* 451 * destination address for copy/move instructions 452 */ 453 uint32 dst_addr; 454 /* 455 * validate or invalidate for clear/invalidate instructions 456 */ 457 uint8 set_not_clr; 458 /* 459 * specifies if address is incremented or decremented in the loop 460 */ 461 uint8 copy_dir; 462 /* 463 * data length in Bytes 464 */ 465 uint32 data_len; 466 } dnx_kbp_rop_blk_t; 467 468 typedef struct dnx_kbp_record_trigger_s 469 { 470 int msb_trigger; 471 int lsb_trigger; 472 int record_trigger; 473 } dnx_kbp_record_trigger_t; 474 475 typedef struct dnx_kbp_record_reply_s 476 { 477 uint32 reply_valid; 478 soc_reg_above_64_val_t reply_data; 479 uint32 rop_error; 480 uint32 elk_error; 481 } dnx_kbp_record_reply_t; 482 483 typedef struct dnx_kbp_rop_packet_s 484 { 485 uint8 opcode; 486 uint16 sequence_num; 487 uint8 payload[DBAL_FIELD_ARRAY_MAX_SIZE_IN_BYTES]; 488 uint32 payload_len; 489 } dnx_kbp_rop_packet_t; 490 491 typedef enum 492 { 493 DNX_KBP_ROP_REQUEST, 494 DNX_KBP_ROP_RESPONSE, 495 } dnx_kbp_rop_packet_type_e; 496 497 /* 498 * } 499 */ 500 501 /************* 502 * GLOBALS * 503 */ 504 /* 505 * { 506 */ 507 /* 508 * } 509 */ 510 /************* 511 * FUNCTIONS * 512 */ 513 /* 514 * { 515 */ 516 /* 517 * Utility functions 518 */ 519 /* 520 * ELK CPU/ROP access functions 521 */ 522 shr_error_e dnx_kbp_cpu_lookup_reply( 523 int unit, 524 uint32 core, 525 dnx_kbp_record_reply_t * reccord_reply); 526 527 shr_error_e dnx_kbp_cpu_record_send( 528 int unit, 529 uint32 core, 530 uint32 opcode, 531 soc_reg_above_64_val_t msb_data, 532 soc_reg_above_64_val_t lsb_data, 533 int lsb_enable, 534 soc_reg_above_64_val_t read_data); 535 536 shr_error_e dnx_kbp_lut_write( 537 int unit, 538 uint32 core, 539 uint8 addr, 540 dnx_kbp_lut_data_t * lut_data); 541 542 shr_error_e dnx_kbp_lut_read( 543 int unit, 544 uint32 core, 545 uint8 addr, 546 dnx_kbp_lut_data_t * lut_data); 547 548 shr_error_e dnx_kbp_rop_read( 549 int unit, 550 uint32 core, 551 dnx_kbp_rop_read_t * rd_data); 552 553 shr_error_e dnx_kbp_rop_write( 554 int unit, 555 uint32 core, 556 dnx_kbp_rop_write_t * wr_data); 557 558 shr_error_e dnx_kbp_rop_scratch_write_read( 559 int unit, 560 bcm_core_t core); 561 562 shr_error_e dnx_kbp_rop_cbw_cmp( 563 int unit, 564 uint32 core, 565 dnx_kbp_rop_cbw_cmp_t * cbw_cmp_data); 566 567 shr_error_e dnx_kbp_init_rop_test( 568 int unit); 569 570 shr_error_e dnx_kbp_rop_last_request_get( 571 int unit, 572 bcm_core_t core, 573 uint32 flags, 574 dnx_kbp_rop_packet_t * pkt); 575 576 shr_error_e dnx_kbp_rop_last_response_get( 577 int unit, 578 bcm_core_t core, 579 uint32 flags, 580 dnx_kbp_rop_packet_t * pkt); 581 582 #if defined(BE_HOST) 583 void dnx_kbp_buffer_endians_fix( 584 int unit, 585 soc_reg_above_64_val_t buffer); 586 #endif 587 /* 588 * } 589 */ 590 #endif /* __KBP_ROP_INCLUDED__ */ 591 #endif /* defined(INCLUDE_KBP) */