1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
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_ARP_ETH_IPV4,
19 ROC_NPC_ITEM_TYPE_MPLS,
20 ROC_NPC_ITEM_TYPE_ICMP,
21 ROC_NPC_ITEM_TYPE_IGMP,
22 ROC_NPC_ITEM_TYPE_UDP,
23 ROC_NPC_ITEM_TYPE_TCP,
24 ROC_NPC_ITEM_TYPE_SCTP,
25 ROC_NPC_ITEM_TYPE_ESP,
26 ROC_NPC_ITEM_TYPE_GRE,
27 ROC_NPC_ITEM_TYPE_NVGRE,
28 ROC_NPC_ITEM_TYPE_VXLAN,
29 ROC_NPC_ITEM_TYPE_GTPC,
30 ROC_NPC_ITEM_TYPE_GTPU,
31 ROC_NPC_ITEM_TYPE_GENEVE,
32 ROC_NPC_ITEM_TYPE_VXLAN_GPE,
33 ROC_NPC_ITEM_TYPE_IPV6_EXT,
34 ROC_NPC_ITEM_TYPE_GRE_KEY,
35 ROC_NPC_ITEM_TYPE_HIGIG2,
36 ROC_NPC_ITEM_TYPE_CPT_HDR,
37 ROC_NPC_ITEM_TYPE_L3_CUSTOM,
38 ROC_NPC_ITEM_TYPE_QINQ,
39 ROC_NPC_ITEM_TYPE_RAW,
40 ROC_NPC_ITEM_TYPE_END,
43 struct roc_npc_item_info {
44 enum roc_npc_item_type type; /* Item type */
45 uint32_t size; /* item size */
46 const void *spec; /**< Pointer to item specification structure. */
47 const void *mask; /**< Bit-mask applied to spec and last. */
48 const void *last; /* For range */
51 struct roc_npc_flow_item_raw {
52 uint32_t relative : 1; /**< Look for pattern after the previous item. */
53 uint32_t search : 1; /**< Search pattern from offset. */
54 uint32_t reserved : 30; /**< Reserved, must be set to zero. */
55 int32_t offset; /**< Absolute or relative offset for pattern. */
56 uint16_t limit; /**< Search area limit for start of pattern. */
57 uint16_t length; /**< Pattern length. */
58 const uint8_t *pattern; /**< Byte string to look for. */
61 struct roc_ether_addr {
62 uint8_t addr_bytes[PLT_ETHER_ADDR_LEN]; /**< Addr bytes in tx order */
65 struct roc_ether_hdr {
66 struct roc_ether_addr d_addr; /**< Destination address. */
69 struct roc_ether_addr s_addr; /**< Source address. */
71 struct roc_ether_addr S_addr;
72 } S_un; /**< Do not use directly; use s_addr instead.*/
74 uint16_t ether_type; /**< Frame type. */
78 struct roc_npc_flow_item_eth {
82 * These fields are retained
84 * Please switch to the new header field below.
86 struct roc_ether_addr dst; /**< Destination MAC. */
87 struct roc_ether_addr src; /**< Source MAC. */
88 uint16_t type; /**< EtherType or TPID. */
90 struct roc_ether_hdr hdr;
92 uint32_t has_vlan : 1; /**< Packet header contains at least one VLAN. */
93 uint32_t reserved : 31; /**< Reserved, must be zero. */
97 uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
98 uint16_t eth_proto; /**< Ethernet type of encapsulated frame. */
102 struct roc_npc_flow_item_vlan {
105 uint16_t tci; /**< Tag control information. */
106 uint16_t inner_type; /**< Inner EtherType or TPID. */
108 struct roc_vlan_hdr hdr;
110 uint32_t has_more_vlan : 1;
111 /**< Packet header contains at least one more VLAN, after this VLAN. */
112 uint32_t reserved : 31; /**< Reserved, must be zero. */
115 #define ROC_NPC_MAX_ACTION_COUNT 19
117 enum roc_npc_action_type {
118 ROC_NPC_ACTION_TYPE_END = (1 << 0),
119 ROC_NPC_ACTION_TYPE_VOID = (1 << 1),
120 ROC_NPC_ACTION_TYPE_MARK = (1 << 2),
121 ROC_NPC_ACTION_TYPE_FLAG = (1 << 3),
122 ROC_NPC_ACTION_TYPE_DROP = (1 << 4),
123 ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5),
124 ROC_NPC_ACTION_TYPE_RSS = (1 << 6),
125 ROC_NPC_ACTION_TYPE_DUP = (1 << 7),
126 ROC_NPC_ACTION_TYPE_SEC = (1 << 8),
127 ROC_NPC_ACTION_TYPE_COUNT = (1 << 9),
128 ROC_NPC_ACTION_TYPE_PF = (1 << 10),
129 ROC_NPC_ACTION_TYPE_VF = (1 << 11),
130 ROC_NPC_ACTION_TYPE_VLAN_STRIP = (1 << 12),
131 ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
132 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
133 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
134 ROC_NPC_ACTION_TYPE_PORT_ID = (1 << 16),
135 ROC_NPC_ACTION_TYPE_METER = (1 << 17),
138 struct roc_npc_action {
139 enum roc_npc_action_type type; /**< Action type. */
140 const void *conf; /**< Pointer to action configuration object. */
143 struct roc_npc_action_mark {
144 uint32_t id; /**< Integer value to return with packets. */
147 struct roc_npc_action_vf {
148 uint32_t original : 1; /**< Use original VF ID if possible. */
149 uint32_t reserved : 31; /**< Reserved, must be zero. */
150 uint32_t id; /**< VF ID. */
153 struct roc_npc_action_port_id {
154 uint32_t original : 1; /**< Use original port ID if possible. */
155 uint32_t reserved : 31; /**< Reserved, must be zero. */
156 uint32_t id; /**< port ID. */
159 struct roc_npc_action_queue {
160 uint16_t index; /**< Queue index to use. */
163 struct roc_npc_action_of_push_vlan {
164 uint16_t ethertype; /**< EtherType. */
167 struct roc_npc_action_of_set_vlan_vid {
168 uint16_t vlan_vid; /**< VLAN id. */
171 struct roc_npc_action_of_set_vlan_pcp {
172 uint8_t vlan_pcp; /**< VLAN priority. */
175 struct roc_npc_action_meter {
176 uint32_t mtr_id; /**< Meter id to be applied. > */
179 struct roc_npc_attr {
180 uint32_t priority; /**< Rule priority level within group. */
181 uint32_t ingress : 1; /**< Rule applies to ingress traffic. */
182 uint32_t egress : 1; /**< Rule applies to egress traffic. */
183 uint32_t reserved : 30; /**< Reserved, must be zero. */
186 struct roc_npc_flow_dump_data {
191 struct roc_npc_flow {
198 #define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
199 /* Contiguous match string */
200 uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
201 uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
203 uint64_t vtag_action;
204 bool vtag_insert_enabled;
205 uint8_t vtag_insert_count;
206 #define ROC_NPC_MAX_FLOW_PATTERNS 32
207 struct roc_npc_flow_dump_data dump_data[ROC_NPC_MAX_FLOW_PATTERNS];
208 uint16_t num_patterns;
210 TAILQ_ENTRY(roc_npc_flow) next;
213 enum roc_npc_rss_hash_function {
214 ROC_NPC_RSS_HASH_FUNCTION_DEFAULT = 0,
215 ROC_NPC_RSS_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
216 ROC_NPC_RSS_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
217 ROC_NPC_RSS_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
218 ROC_NPC_RSS_HASH_FUNCTION_MAX,
221 struct roc_npc_action_rss {
222 enum roc_npc_rss_hash_function func;
224 uint64_t types; /**< Specific RSS hash types (see RTE_ETH_RSS_*). */
225 uint32_t key_len; /**< Hash key length in bytes. */
226 uint32_t queue_num; /**< Number of entries in @p queue. */
227 const uint8_t *key; /**< Hash key. */
228 const uint16_t *queue; /**< Queue indices to use. */
234 ROC_NPC_INTF_MAX = 2,
237 enum flow_vtag_cfg_dir { VTAG_TX, VTAG_RX };
238 #define ROC_ETHER_TYPE_VLAN 0x8100 /**< IEEE 802.1Q VLAN tagging. */
239 #define ROC_ETHER_TYPE_QINQ 0x88A8 /**< IEEE 802.1ad QinQ tagging. */
242 struct roc_nix *roc_nix;
243 uint8_t switch_header_type;
244 uint8_t pre_l2_size_offset; /**< Offset with in header that holds
245 * size of custom header
247 uint8_t pre_l2_size_offset_mask; /**< Offset mask with in header
248 * that holds size of custom header
250 uint8_t pre_l2_size_shift_dir; /**< Shift direction to calculate size
252 uint16_t flow_prealloc_size;
253 uint16_t flow_max_priority;
256 uint64_t kex_capability;
257 uint64_t rx_parse_nibble;
258 /* Parsed RSS Flowkey cfg for current flow being created */
259 uint32_t flowkey_cfg_state;
260 bool is_sdp_mask_set;
261 uint16_t sdp_channel;
262 uint16_t sdp_channel_mask;
264 #define ROC_NPC_MEM_SZ (5 * 1024)
265 uint8_t reserved[ROC_NPC_MEM_SZ];
266 } __plt_cache_aligned;
268 int __roc_api roc_npc_init(struct roc_npc *roc_npc);
269 int __roc_api roc_npc_fini(struct roc_npc *roc_npc);
270 const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc);
272 struct roc_npc_flow *__roc_api
273 roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
274 const struct roc_npc_item_info pattern[],
275 const struct roc_npc_action actions[], int *errcode);
276 int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
277 struct roc_npc_flow *flow);
278 int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
279 int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc,
280 struct roc_npc_flow *mcam,
281 struct roc_npc_flow *ref_mcam, int prio,
283 int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
284 int *alloc_entry, int req_count,
285 int priority, int *resp_count);
286 int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc,
287 struct roc_npc_flow *mcam,
289 int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc,
290 struct roc_npc_flow *mcam);
291 int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc,
292 const struct roc_npc_attr *attr,
293 const struct roc_npc_item_info pattern[],
294 const struct roc_npc_action actions[],
295 struct roc_npc_flow *flow);
296 int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc);
297 int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc,
299 int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc,
300 uint32_t ctr_id, uint64_t *count);
301 int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc,
303 int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc);
304 void __roc_api roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc);
305 void __roc_api roc_npc_flow_mcam_dump(FILE *file, struct roc_npc *roc_npc,
306 struct roc_npc_flow *mcam);
307 int __roc_api roc_npc_mark_actions_get(struct roc_npc *roc_npc);
308 int __roc_api roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc,
310 int __roc_api roc_npc_vtag_actions_get(struct roc_npc *roc_npc);
311 int __roc_api roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc,
313 int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
314 struct roc_npc_flow *flow);
315 int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
316 struct roc_npc *roc_npc_dst);
317 #endif /* _ROC_NPC_H_ */