1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(C) 2021 Marvell. 3 */ 4 5 #ifndef _ROC_NPC_H_ 6 #define _ROC_NPC_H_ 7 8 #include <sys/queue.h> 9 10 enum roc_npc_item_type { 11 ROC_NPC_ITEM_TYPE_VOID, 12 ROC_NPC_ITEM_TYPE_ANY, 13 ROC_NPC_ITEM_TYPE_ETH, 14 ROC_NPC_ITEM_TYPE_VLAN, 15 ROC_NPC_ITEM_TYPE_E_TAG, 16 ROC_NPC_ITEM_TYPE_IPV4, 17 ROC_NPC_ITEM_TYPE_IPV6, 18 ROC_NPC_ITEM_TYPE_IPV6_FRAG_EXT, 19 ROC_NPC_ITEM_TYPE_ARP_ETH_IPV4, 20 ROC_NPC_ITEM_TYPE_MPLS, 21 ROC_NPC_ITEM_TYPE_ICMP, 22 ROC_NPC_ITEM_TYPE_IGMP, 23 ROC_NPC_ITEM_TYPE_UDP, 24 ROC_NPC_ITEM_TYPE_TCP, 25 ROC_NPC_ITEM_TYPE_SCTP, 26 ROC_NPC_ITEM_TYPE_ESP, 27 ROC_NPC_ITEM_TYPE_GRE, 28 ROC_NPC_ITEM_TYPE_NVGRE, 29 ROC_NPC_ITEM_TYPE_VXLAN, 30 ROC_NPC_ITEM_TYPE_GTPC, 31 ROC_NPC_ITEM_TYPE_GTPU, 32 ROC_NPC_ITEM_TYPE_GENEVE, 33 ROC_NPC_ITEM_TYPE_VXLAN_GPE, 34 ROC_NPC_ITEM_TYPE_IPV6_EXT, 35 ROC_NPC_ITEM_TYPE_GRE_KEY, 36 ROC_NPC_ITEM_TYPE_HIGIG2, 37 ROC_NPC_ITEM_TYPE_CPT_HDR, 38 ROC_NPC_ITEM_TYPE_L3_CUSTOM, 39 ROC_NPC_ITEM_TYPE_QINQ, 40 ROC_NPC_ITEM_TYPE_RAW, 41 ROC_NPC_ITEM_TYPE_MARK, 42 ROC_NPC_ITEM_TYPE_END, 43 }; 44 45 struct roc_npc_item_info { 46 enum roc_npc_item_type type; /* Item type */ 47 uint32_t size; /* item size */ 48 const void *spec; /**< Pointer to item specification structure. */ 49 const void *mask; /**< Bit-mask applied to spec and last. */ 50 const void *last; /* For range */ 51 }; 52 53 struct roc_npc_flow_item_raw { 54 uint32_t relative : 1; /**< Look for pattern after the previous item. */ 55 uint32_t search : 1; /**< Search pattern from offset. */ 56 uint32_t reserved : 30; /**< Reserved, must be set to zero. */ 57 int32_t offset; /**< Absolute or relative offset for pattern. */ 58 uint16_t limit; /**< Search area limit for start of pattern. */ 59 uint16_t length; /**< Pattern length. */ 60 const uint8_t *pattern; /**< Byte string to look for. */ 61 }; 62 63 struct roc_ether_addr { 64 uint8_t addr_bytes[PLT_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ 65 } __plt_aligned(2); 66 67 struct roc_ether_hdr { 68 struct roc_ether_addr d_addr; /**< Destination address. */ 69 PLT_STD_C11 70 union { 71 struct roc_ether_addr s_addr; /**< Source address. */ 72 struct { 73 struct roc_ether_addr S_addr; 74 } S_un; /**< Do not use directly; use s_addr instead.*/ 75 }; 76 uint16_t ether_type; /**< Frame type. */ 77 } __plt_aligned(2); 78 79 PLT_STD_C11 80 struct roc_npc_flow_item_eth { 81 union { 82 struct { 83 /* 84 * These fields are retained 85 * for compatibility. 86 * Please switch to the new header field below. 87 */ 88 struct roc_ether_addr dst; /**< Destination MAC. */ 89 struct roc_ether_addr src; /**< Source MAC. */ 90 uint16_t type; /**< EtherType or TPID. */ 91 }; 92 struct roc_ether_hdr hdr; 93 }; 94 uint32_t has_vlan : 1; /**< Packet header contains at least one VLAN. */ 95 uint32_t reserved : 31; /**< Reserved, must be zero. */ 96 }; 97 98 struct roc_vlan_hdr { 99 uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */ 100 uint16_t eth_proto; /**< Ethernet type of encapsulated frame. */ 101 } __plt_packed; 102 103 PLT_STD_C11 104 struct roc_npc_flow_item_vlan { 105 union { 106 struct { 107 uint16_t tci; /**< Tag control information. */ 108 uint16_t inner_type; /**< Inner EtherType or TPID. */ 109 }; 110 struct roc_vlan_hdr hdr; 111 }; 112 uint32_t has_more_vlan : 1; 113 /**< Packet header contains at least one more VLAN, after this VLAN. */ 114 uint32_t reserved : 31; /**< Reserved, must be zero. */ 115 }; 116 117 struct roc_ipv6_hdr { 118 uint32_t vtc_flow; /**< IP version, traffic class & flow label. */ 119 uint16_t payload_len; /**< IP payload size, including ext. headers */ 120 uint8_t proto; /**< Protocol, next header. */ 121 uint8_t hop_limits; /**< Hop limits. */ 122 uint8_t src_addr[16]; /**< IP address of source host. */ 123 uint8_t dst_addr[16]; /**< IP address of destination host(s). */ 124 } __plt_packed; 125 126 struct roc_npc_flow_item_ipv6 { 127 struct roc_ipv6_hdr hdr; /**< IPv6 header definition. */ 128 uint32_t has_hop_ext : 1; 129 /**< Header contains Hop-by-Hop Options extension header. */ 130 uint32_t has_route_ext : 1; 131 /**< Header contains Routing extension header. */ 132 uint32_t has_frag_ext : 1; 133 /**< Header contains Fragment extension header. */ 134 uint32_t has_auth_ext : 1; 135 /**< Header contains Authentication extension header. */ 136 uint32_t has_esp_ext : 1; 137 /**< Header contains Encapsulation Security Payload extension header. */ 138 uint32_t has_dest_ext : 1; 139 /**< Header contains Destination Options extension header. */ 140 uint32_t has_mobil_ext : 1; 141 /**< Header contains Mobility extension header. */ 142 uint32_t has_hip_ext : 1; 143 /**< Header contains Host Identity Protocol extension header. */ 144 uint32_t has_shim6_ext : 1; 145 /**< Header contains Shim6 Protocol extension header. */ 146 uint32_t reserved : 23; 147 /**< Reserved for future extension headers, must be zero. */ 148 }; 149 150 #define ROC_NPC_MAX_ACTION_COUNT 19 151 152 enum roc_npc_action_type { 153 ROC_NPC_ACTION_TYPE_END = (1 << 0), 154 ROC_NPC_ACTION_TYPE_VOID = (1 << 1), 155 ROC_NPC_ACTION_TYPE_MARK = (1 << 2), 156 ROC_NPC_ACTION_TYPE_FLAG = (1 << 3), 157 ROC_NPC_ACTION_TYPE_DROP = (1 << 4), 158 ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5), 159 ROC_NPC_ACTION_TYPE_RSS = (1 << 6), 160 ROC_NPC_ACTION_TYPE_DUP = (1 << 7), 161 ROC_NPC_ACTION_TYPE_SEC = (1 << 8), 162 ROC_NPC_ACTION_TYPE_COUNT = (1 << 9), 163 ROC_NPC_ACTION_TYPE_PF = (1 << 10), 164 ROC_NPC_ACTION_TYPE_VF = (1 << 11), 165 ROC_NPC_ACTION_TYPE_VLAN_STRIP = (1 << 12), 166 ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13), 167 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14), 168 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15), 169 ROC_NPC_ACTION_TYPE_PORT_ID = (1 << 16), 170 ROC_NPC_ACTION_TYPE_METER = (1 << 17), 171 }; 172 173 struct roc_npc_action { 174 enum roc_npc_action_type type; /**< Action type. */ 175 const void *conf; /**< Pointer to action configuration object. */ 176 }; 177 178 struct roc_npc_action_mark { 179 uint32_t id; /**< Integer value to return with packets. */ 180 }; 181 182 struct roc_npc_action_vf { 183 uint32_t original : 1; /**< Use original VF ID if possible. */ 184 uint32_t reserved : 31; /**< Reserved, must be zero. */ 185 uint32_t id; /**< VF ID. */ 186 }; 187 188 struct roc_npc_action_port_id { 189 uint32_t original : 1; /**< Use original port ID if possible. */ 190 uint32_t reserved : 31; /**< Reserved, must be zero. */ 191 uint32_t id; /**< port ID. */ 192 }; 193 194 struct roc_npc_action_queue { 195 uint16_t index; /**< Queue index to use. */ 196 }; 197 198 struct roc_npc_action_of_push_vlan { 199 uint16_t ethertype; /**< EtherType. */ 200 }; 201 202 struct roc_npc_action_of_set_vlan_vid { 203 uint16_t vlan_vid; /**< VLAN id. */ 204 }; 205 206 struct roc_npc_action_of_set_vlan_pcp { 207 uint8_t vlan_pcp; /**< VLAN priority. */ 208 }; 209 210 struct roc_npc_action_meter { 211 uint32_t mtr_id; /**< Meter id to be applied. > */ 212 }; 213 214 enum roc_npc_sec_action_alg { 215 ROC_NPC_SEC_ACTION_ALG0, 216 ROC_NPC_SEC_ACTION_ALG1, 217 ROC_NPC_SEC_ACTION_ALG2, 218 ROC_NPC_SEC_ACTION_ALG3, 219 }; 220 221 struct roc_npc_sec_action { 222 /* Used as lookup result for ALG3 */ 223 uint32_t sa_index; 224 /* When true XOR initial SA_INDEX with SA_HI/SA_LO to get SA_MCAM */ 225 bool sa_xor; 226 uint16_t sa_hi, sa_lo; 227 /* Determines alg to be applied post SA_MCAM computation with/without 228 * XOR 229 */ 230 enum roc_npc_sec_action_alg alg; 231 }; 232 233 struct roc_npc_attr { 234 uint32_t priority; /**< Rule priority level within group. */ 235 uint32_t ingress : 1; /**< Rule applies to ingress traffic. */ 236 uint32_t egress : 1; /**< Rule applies to egress traffic. */ 237 uint32_t reserved : 30; /**< Reserved, must be zero. */ 238 }; 239 240 struct roc_npc_flow_dump_data { 241 uint8_t lid; 242 uint16_t ltype; 243 }; 244 245 struct roc_npc_flow { 246 uint8_t nix_intf; 247 uint8_t enable; 248 uint32_t mcam_id; 249 int32_t ctr_id; 250 uint32_t priority; 251 uint32_t mtr_id; 252 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7 253 /* Contiguous match string */ 254 uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS]; 255 uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS]; 256 uint64_t npc_action; 257 uint64_t vtag_action; 258 bool vtag_insert_enabled; 259 uint8_t vtag_insert_count; 260 #define ROC_NPC_MAX_FLOW_PATTERNS 32 261 struct roc_npc_flow_dump_data dump_data[ROC_NPC_MAX_FLOW_PATTERNS]; 262 uint16_t num_patterns; 263 264 TAILQ_ENTRY(roc_npc_flow) next; 265 }; 266 267 enum roc_npc_rss_hash_function { 268 ROC_NPC_RSS_HASH_FUNCTION_DEFAULT = 0, 269 ROC_NPC_RSS_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */ 270 ROC_NPC_RSS_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */ 271 ROC_NPC_RSS_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, 272 ROC_NPC_RSS_HASH_FUNCTION_MAX, 273 }; 274 275 struct roc_npc_action_rss { 276 enum roc_npc_rss_hash_function func; 277 uint32_t level; 278 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */ 279 uint32_t key_len; /**< Hash key length in bytes. */ 280 uint32_t queue_num; /**< Number of entries in @p queue. */ 281 const uint8_t *key; /**< Hash key. */ 282 const uint16_t *queue; /**< Queue indices to use. */ 283 }; 284 285 enum roc_npc_intf { 286 ROC_NPC_INTF_RX = 0, 287 ROC_NPC_INTF_TX = 1, 288 ROC_NPC_INTF_MAX = 2, 289 }; 290 291 enum flow_vtag_cfg_dir { VTAG_TX, VTAG_RX }; 292 #define ROC_ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */ 293 #define ROC_ETHER_TYPE_QINQ 0x88A8 /**< IEEE 802.1ad QinQ tagging. */ 294 295 struct roc_npc { 296 struct roc_nix *roc_nix; 297 uint8_t switch_header_type; 298 uint8_t pre_l2_size_offset; /**< Offset with in header that holds 299 * size of custom header 300 */ 301 uint8_t pre_l2_size_offset_mask; /**< Offset mask with in header 302 * that holds size of custom header 303 */ 304 uint8_t pre_l2_size_shift_dir; /**< Shift direction to calculate size 305 */ 306 uint16_t flow_prealloc_size; 307 uint16_t flow_max_priority; 308 uint16_t channel; 309 uint16_t pf_func; 310 uint64_t kex_capability; 311 uint64_t rx_parse_nibble; 312 /* Parsed RSS Flowkey cfg for current flow being created */ 313 uint32_t flowkey_cfg_state; 314 bool is_sdp_mask_set; 315 uint16_t sdp_channel; 316 uint16_t sdp_channel_mask; 317 318 #define ROC_NPC_MEM_SZ (5 * 1024) 319 uint8_t reserved[ROC_NPC_MEM_SZ]; 320 } __plt_cache_aligned; 321 322 int __roc_api roc_npc_init(struct roc_npc *roc_npc); 323 int __roc_api roc_npc_fini(struct roc_npc *roc_npc); 324 const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc); 325 326 struct roc_npc_flow *__roc_api 327 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr, 328 const struct roc_npc_item_info pattern[], 329 const struct roc_npc_action actions[], int *errcode); 330 int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc, 331 struct roc_npc_flow *flow); 332 int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry); 333 int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc, 334 bool enable); 335 int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, 336 struct roc_npc_flow *mcam, 337 struct roc_npc_flow *ref_mcam, int prio, 338 int *resp_count); 339 int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry, 340 int *alloc_entry, int req_count, 341 int priority, int *resp_count); 342 int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc, 343 struct roc_npc_flow *mcam, 344 bool enable); 345 int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc, 346 struct roc_npc_flow *mcam); 347 int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc, 348 const struct roc_npc_attr *attr, 349 const struct roc_npc_item_info pattern[], 350 const struct roc_npc_action actions[], 351 struct roc_npc_flow *flow); 352 int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc); 353 int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc, 354 uint16_t ctr_id); 355 int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc, 356 uint32_t ctr_id, uint64_t *count); 357 int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc, 358 uint32_t ctr_id); 359 int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc); 360 void __roc_api roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc); 361 void __roc_api roc_npc_flow_mcam_dump(FILE *file, struct roc_npc *roc_npc, 362 struct roc_npc_flow *mcam); 363 int __roc_api roc_npc_vtag_actions_get(struct roc_npc *roc_npc); 364 int __roc_api roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc, 365 uint32_t count); 366 int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc, 367 struct roc_npc_flow *flow); 368 int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src, 369 struct roc_npc *roc_npc_dst); 370 #endif /* _ROC_NPC_H_ */ 371