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C_NPC_ITEM_TYPE_IPV6_ROUTING_EXT, 45 ROC_NPC_ITEM_TYPE_REPRESENTED_PORT, 46 ROC_NPC_ITEM_TYPE_END, 47 }; 48 49 struct roc_npc_item_info { 50 enum roc_npc_item_type type; /* Item type */ 51 uint32_t size; /* item size */ 52 const void *spec; /**< Pointer to item specification structure. */ 53 const void *mask; /**< Bit-mask applied to spec and last. */ 54 const void *last; /* For range */ 55 }; 56 57 struct roc_npc_flow_item_raw { 58 uint32_t relative : 1; /**< Look for pattern after the previous item. */ 59 uint32_t search : 1; /**< Search pattern from offset. */ 60 uint32_t reserved : 30; /**< Reserved, must be set to zero. */ 61 int32_t offset; /**< Absolute or relative offset for pattern. */ 62 uint16_t limit; /**< Search area limit for start of pattern. */ 63 uint16_t length; /**< Pattern length. */ 64 const uint8_t *pattern; /**< Byte string to look for. */ 65 }; 66 67 struct roc_ether_addr { 68 uint8_t addr_bytes[PLT_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ 69 } __plt_aligned(2); 70 71 struct roc_ether_hdr { 72 struct roc_ether_addr d_addr; /**< Destination address. */ 73 union { 74 struct roc_ether_addr s_addr; /**< Source address. */ 75 struct { 76 struct roc_ether_addr S_addr; 77 } S_un; /**< Do not use directly; use s_addr instead.*/ 78 }; 79 uint16_t ether_type; /**< Frame type. */ 80 } __plt_aligned(2); 81 82 struct roc_npc_flow_item_eth { 83 union { 84 struct { 85 /* 86 * These fields are retained 87 * for compatibility. 88 * Please switch to the new header field below. 89 */ 90 struct roc_ether_addr dst; /**< Destination MAC. */ 91 struct roc_ether_addr src; /**< Source MAC. */ 92 uint16_t type; /**< EtherType or TPID. */ 93 }; 94 struct roc_ether_hdr hdr; 95 }; 96 uint32_t has_vlan : 1; /**< Packet header contains at least one VLAN. */ 97 uint32_t reserved : 31; /**< Reserved, must be zero. */ 98 }; 99 100 struct __plt_packed_begin roc_vlan_hdr { 101 uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */ 102 uint16_t eth_proto; /**< Ethernet type of encapsulated frame. */ 103 } __plt_packed_end; 104 105 struct roc_npc_flow_item_vlan { 106 union { 107 struct { 108 uint16_t tci; /**< Tag control information. */ 109 uint16_t inner_type; /**< Inner EtherType or TPID. */ 110 }; 111 struct roc_vlan_hdr hdr; 112 }; 113 uint32_t has_more_vlan : 1; 114 /**< Packet header contains at least one more VLAN, after this VLAN. */ 115 uint32_t reserved : 31; /**< Reserved, must be zero. */ 116 }; 117 118 struct __plt_packed_begin roc_ipv6_hdr { 119 uint32_t vtc_flow; /**< IP version, traffic class & flow label. */ 120 uint16_t payload_len; /**< IP payload size, including ext. headers */ 121 uint8_t proto; /**< Protocol, next header. */ 122 uint8_t hop_limits; /**< Hop limits. */ 123 uint8_t src_addr[16]; /**< IP address of source host. */ 124 uint8_t dst_addr[16]; /**< IP address of destination host(s). */ 125 } __plt_packed_end; 126 127 struct __plt_packed_begin roc_ipv6_fragment_ext { 128 uint8_t next_header; /**< Next header type */ 129 uint8_t reserved; /**< Reserved */ 130 uint16_t frag_data; /**< All fragmentation data */ 131 uint32_t id; /**< Packet ID */ 132 } __plt_packed_end; 133 134 struct __plt_packed_begin roc_ipv6_routing_ext { 135 uint8_t next_hdr; /**< Protocol, next header. */ 136 uint8_t hdr_len; /**< Header length. */ 137 uint8_t type; /**< Extension header type. */ 138 uint8_t segments_left; /**< Valid segments number. */ 139 union { 140 uint32_t flags; /**< Packet control data per type. */ 141 struct { 142 uint8_t last_entry; /**< The last_entry field of SRH */ 143 uint8_t flag; /**< Packet flag. */ 144 uint16_t tag; /**< Packet tag. */ 145 }; 146 }; 147 /* Next are 128-bit IPv6 address fields to describe segments. */ 148 } __plt_packed_end; 149 150 struct roc_flow_item_ipv6_ext { 151 uint8_t next_hdr; /**< Next header. */ 152 }; 153 154 struct roc_npc_flow_item_ipv6 { 155 struct roc_ipv6_hdr hdr; /**< IPv6 header definition. */ 156 uint32_t has_hop_ext : 1; 157 /**< Header contains Hop-by-Hop Options extension header. */ 158 uint32_t has_route_ext : 1; 159 /**< Header contains Routing extension header. */ 160 uint32_t has_frag_ext : 1; 161 /**< Header contains Fragment extension header. */ 162 uint32_t has_auth_ext : 1; 163 /**< Header contains Authentication extension header. */ 164 uint32_t has_esp_ext : 1; 165 /**< Header contains Encapsulation Security Payload extension header. */ 166 uint32_t has_dest_ext : 1; 167 /**< Header contains Destination Options extension header. */ 168 uint32_t has_mobil_ext : 1; 169 /**< Header contains Mobility extension header. */ 170 uint32_t has_hip_ext : 1; 171 /**< Header contains Host Identity Protocol extension header. */ 172 uint32_t has_shim6_ext : 1; 173 /**< Header contains Shim6 Protocol extension header. */ 174 uint32_t reserved : 23; 175 /**< Reserved for future extension headers, must be zero. */ 176 }; 177 178 #define ROC_NPC_MAX_ACTION_COUNT 19 179 180 enum roc_npc_action_type { 181 ROC_NPC_ACTION_TYPE_END = (1 << 0), 182 ROC_NPC_ACTION_TYPE_VOID = (1 << 1), 183 ROC_NPC_ACTION_TYPE_MARK = (1 << 2), 184 ROC_NPC_ACTION_TYPE_FLAG = (1 << 3), 185 ROC_NPC_ACTION_TYPE_DROP = (1 << 4), 186 ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5), 187 ROC_NPC_ACTION_TYPE_RSS = (1 << 6), 188 ROC_NPC_ACTION_TYPE_DUP = (1 << 7), 189 ROC_NPC_ACTION_TYPE_SEC = (1 << 8), 190 ROC_NPC_ACTION_TYPE_COUNT = (1 << 9), 191 ROC_NPC_ACTION_TYPE_PF = (1 << 10), 192 ROC_NPC_ACTION_TYPE_VF = (1 << 11), 193 ROC_NPC_ACTION_TYPE_VLAN_STRIP = (1 << 12), 194 ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13), 195 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14), 196 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15), 197 ROC_NPC_ACTION_TYPE_PORT_ID = (1 << 16), 198 ROC_NPC_ACTION_TYPE_METER = (1 << 17), 199 ROC_NPC_ACTION_TYPE_AGE = (1 << 18), 200 ROC_NPC_ACTION_TYPE_SAMPLE = (1 << 19), 201 }; 202 203 struct roc_npc_action { 204 enum roc_npc_action_type type; /**< Action type. */ 205 const void *conf; /**< Pointer to action configuration object. */ 206 uint16_t rss_repte_pf_func; /**< Per flow tmp var for rss representee pffunc */ 207 }; 208 209 struct roc_npc_action_sample { 210 uint32_t ratio; /**< packets sampled equals to '1/ratio'. */ 211 uint32_t action_type; /* PF or VF or PORT_ID target. */ 212 uint16_t pf_func; 213 uint16_t channel; 214 }; 215 216 struct roc_npc_action_mark { 217 uint32_t id; /**< Integer value to return with packets. */ 218 }; 219 220 struct roc_npc_action_vf { 221 uint32_t original : 1; /**< Use original VF ID if possible. */ 222 uint32_t reserved : 31; /**< Reserved, must be zero. */ 223 uint32_t id; /**< VF ID. */ 224 }; 225 226 struct roc_npc_action_port_id { 227 uint32_t original : 1; /**< Use original port ID if possible. */ 228 uint32_t reserved : 31; /**< Reserved, must be zero. */ 229 uint32_t id; /**< port ID. */ 230 }; 231 232 struct roc_npc_action_age { 233 uint32_t timeout : 24; /**< Time in seconds. */ 234 uint32_t reserved : 8; /**< Reserved, must be zero. */ 235 /** The user flow context, NULL means the flow pointer. */ 236 void *context; 237 }; 238 239 /** 240 * ESP Header 241 */ 242 struct roc_npc_item_esp_hdr { 243 uint32_t spi; /**< Security Parameters Index */ 244 uint32_t seq; /**< packet sequence number */ 245 }; 246 247 struct roc_npc_action_queue { 248 uint16_t index; /**< Queue index to use. */ 249 }; 250 251 struct roc_npc_action_of_push_vlan { 252 uint16_t ethertype; /**< EtherType. */ 253 }; 254 255 struct roc_npc_action_of_set_vlan_vid { 256 uint16_t vlan_vid; /**< VLAN id. */ 257 }; 258 259 struct roc_npc_action_of_set_vlan_pcp { 260 uint8_t vlan_pcp; /**< VLAN priority. */ 261 }; 262 263 struct roc_npc_action_meter { 264 uint32_t mtr_id; /**< Meter id to be applied. > */ 265 }; 266 267 enum roc_npc_sec_action_alg { 268 ROC_NPC_SEC_ACTION_ALG0, 269 ROC_NPC_SEC_ACTION_ALG1, 270 ROC_NPC_SEC_ACTION_ALG2, 271 ROC_NPC_SEC_ACTION_ALG3, 272 ROC_NPC_SEC_ACTION_ALG4, 273 }; 274 275 struct roc_npc_sec_action { 276 /* Used as lookup result for ALG3 */ 277 uint32_t sa_index; 278 /* When true XOR initial SA_INDEX with SA_HI/SA_LO to get SA_MCAM */ 279 bool sa_xor; 280 uint16_t sa_hi, sa_lo; 281 /* Determines alg to be applied post SA_MCAM computation with/without 282 * XOR 283 */ 284 enum roc_npc_sec_action_alg alg; 285 }; 286 287 struct roc_npc_attr { 288 uint32_t priority; /**< Rule priority level within group. */ 289 uint32_t ingress : 1; /**< Rule applies to ingress traffic. */ 290 uint32_t egress : 1; /**< Rule applies to egress traffic. */ 291 uint32_t reserved : 30; /**< Reserved, must be zero. */ 292 }; 293 294 struct roc_npc_flow_dump_data { 295 uint8_t lid; 296 uint16_t ltype; 297 }; 298 299 struct roc_npc_spi_to_sa_action_info { 300 uint32_t spi; 301 uint32_t hash_index; 302 uint8_t way; 303 bool duplicate; 304 bool has_action; 305 }; 306 307 struct mbox; 308 309 struct roc_npc_flow { 310 uint8_t nix_intf; 311 uint8_t enable; 312 uint32_t mcam_id; 313 uint8_t use_ctr; 314 int32_t ctr_id; 315 uint32_t priority; 316 uint32_t mtr_id; 317 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7 318 /* Contiguous match string */ 319 uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS]; 320 uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS]; 321 uint64_t npc_action; 322 uint64_t vtag_action; 323 bool vtag_insert_enabled; 324 uint8_t vtag_insert_count; 325 #define ROC_NPC_MAX_FLOW_PATTERNS 32 326 struct roc_npc_flow_dump_data dump_data[ROC_NPC_MAX_FLOW_PATTERNS]; 327 uint16_t num_patterns; 328 struct roc_npc_spi_to_sa_action_info spi_to_sa_info; 329 uint16_t tx_pf_func; 330 bool is_validate; 331 uint16_t match_id; 332 uint8_t is_inline_dev; 333 bool use_pre_alloc; 334 uint64_t timeout_cycles; 335 void *age_context; 336 uint32_t timeout; 337 bool has_age_action; 338 uint16_t rep_pf_func; 339 uint16_t rep_act_pf_func; 340 bool rep_act_rep; 341 uint16_t rep_channel; 342 struct mbox *rep_mbox; 343 bool has_rep; 344 bool is_rep_vf; 345 struct npc *rep_npc; 346 int port_id; 347 bool is_sampling_rule; 348 uint32_t recv_queue; 349 uint32_t mcast_grp_index; 350 uint32_t mce_start_index; 351 #define ROC_NPC_MIRROR_LIST_SIZE 2 352 uint16_t mcast_pf_funcs[ROC_NPC_MIRROR_LIST_SIZE]; 353 uint16_t mcast_channels[ROC_NPC_MIRROR_LIST_SIZE]; 354 355 TAILQ_ENTRY(roc_npc_flow) next; 356 }; 357 358 enum roc_npc_rss_hash_function { 359 ROC_NPC_RSS_HASH_FUNCTION_DEFAULT = 0, 360 ROC_NPC_RSS_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */ 361 ROC_NPC_RSS_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */ 362 ROC_NPC_RSS_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, 363 ROC_NPC_RSS_HASH_FUNCTION_MAX, 364 }; 365 366 struct roc_npc_action_rss { 367 enum roc_npc_rss_hash_function func; 368 uint32_t level; 369 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */ 370 uint32_t key_len; /**< Hash key length in bytes. */ 371 uint32_t queue_num; /**< Number of entries in @p queue. */ 372 const uint8_t *key; /**< Hash key. */ 373 const uint16_t *queue; /**< Queue indices to use. */ 374 }; 375 376 enum roc_npc_intf { 377 ROC_NPC_INTF_RX = 0, 378 ROC_NPC_INTF_TX = 1, 379 ROC_NPC_INTF_MAX = 2, 380 }; 381 382 enum flow_vtag_cfg_dir { VTAG_TX, VTAG_RX }; 383 #define ROC_ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */ 384 #define ROC_ETHER_TYPE_QINQ 0x88A8 /**< IEEE 802.1ad QinQ tagging. */ 385 386 struct roc_npc_flow_age { 387 plt_seqcount_t seq_cnt; 388 uint32_t aging_poll_freq; 389 uint32_t age_flow_refcnt; 390 uint32_t aged_flows_cnt; 391 uint32_t start_id; 392 uint32_t end_id; 393 plt_thread_t aged_flows_poll_thread; 394 struct plt_bitmap *aged_flows; 395 void *age_mem; 396 bool aged_flows_get_thread_exit; 397 }; 398 399 struct roc_npc { 400 struct roc_nix *roc_nix; 401 uint8_t switch_header_type; 402 uint8_t pre_l2_size_offset; /**< Offset with in header that holds 403 * size of custom header 404 */ 405 uint8_t pre_l2_size_offset_mask; /**< Offset mask with in header 406 * that holds size of custom header 407 */ 408 uint8_t pre_l2_size_shift_dir; /**< Shift direction to calculate size 409 */ 410 uint16_t flow_prealloc_size; 411 uint16_t flow_max_priority; 412 uint16_t channel; 413 uint16_t pf_func; 414 uint64_t kex_capability; 415 uint64_t rx_parse_nibble; 416 /* Parsed RSS Flowkey cfg for current flow being created */ 417 uint32_t flowkey_cfg_state; 418 bool is_sdp_mask_set; 419 uint16_t sdp_channel; 420 uint16_t sdp_channel_mask; 421 struct roc_npc_flow_age flow_age; 422 struct roc_npc *rep_npc; 423 uint16_t rep_pf_func; 424 uint16_t rep_rx_channel; 425 uint16_t rep_act_pf_func; 426 bool rep_act_rep; 427 int rep_port_id; 428 429 #define ROC_NPC_MEM_SZ (6 * 1024) 430 uint8_t reserved[ROC_NPC_MEM_SZ]; 431 } __plt_cache_aligned; 432 433 #define ROC_NPC_AGE_POLL_FREQ_MIN 10 434 435 int __roc_api roc_npc_init(struct roc_npc *roc_npc); 436 int __roc_api roc_npc_fini(struct roc_npc *roc_npc); 437 const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc); 438 int __roc_api roc_npc_kex_capa_get(struct roc_nix *roc_nix, uint64_t *kex_capability); 439 440 struct roc_npc_flow *__roc_api roc_npc_flow_create(struct roc_npc *roc_npc, 441 const struct roc_npc_attr *attr, 442 const struct roc_npc_item_info pattern[], 443 const struct roc_npc_action actions[], 444 uint16_t dst_pf_func, int *errcode); 445 int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow); 446 int __roc_api roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam); 447 int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry); 448 int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc, bool enable); 449 int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam, 450 struct roc_npc_flow *ref_mcam, int prio, int *resp_count); 451 int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry, int *alloc_entry, 452 int req_count, int priority, int *resp_count, 453 bool is_conti); 454 int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam, 455 bool enable); 456 int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam); 457 int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc, const struct roc_npc_attr *attr, 458 const struct roc_npc_item_info pattern[], 459 const struct roc_npc_action actions[], struct roc_npc_flow *flow); 460 int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc); 461 int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc, uint16_t ctr_id); 462 int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc, uint32_t ctr_id, uint64_t *count); 463 int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc, uint32_t ctr_id); 464 int __roc_api roc_npc_mcam_alloc_counter(struct roc_npc *roc_npc, uint16_t *ctr_id); 465 int __roc_api roc_npc_get_free_mcam_entry(struct roc_npc *roc_npc, struct roc_npc_flow *flow); 466 int __roc_api roc_npc_inl_mcam_read_counter(uint32_t ctr_id, uint64_t *count); 467 int __roc_api roc_npc_inl_mcam_clear_counter(uint32_t ctr_id); 468 int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc); 469 void __roc_api roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc, int rep_port_id); 470 void __roc_api roc_npc_flow_mcam_dump(FILE *file, struct roc_npc *roc_npc, 471 struct roc_npc_flow *mcam); 472 int __roc_api roc_npc_mark_actions_get(struct roc_npc *roc_npc); 473 int __roc_api roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count); 474 int __roc_api roc_npc_vtag_actions_get(struct roc_npc *roc_npc); 475 int __roc_api roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc, uint32_t count); 476 int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc, 477 struct roc_npc_flow *flow); 478 int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src, 479 struct roc_npc *roc_npc_dst); 480 int __roc_api roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow, int mcam_id); 481 int __roc_api roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent); 482 void *__roc_api roc_npc_aged_flow_ctx_get(struct roc_npc *roc_npc, uint32_t mcam_id); 483 void __roc_api roc_npc_sdp_channel_get(struct roc_npc *roc_npc, uint16_t *chan_base, 484 uint16_t *chan_mask); 485 #endif /* _ROC_NPC_H_ */ 486