1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2008-2019 Cisco Systems, Inc. All rights reserved.
8 #include <rte_ethdev_driver.h>
9 #include <rte_flow_driver.h>
10 #include <rte_ether.h>
13 #include <rte_memzone.h>
15 #include "enic_compat.h"
20 #define IP_DEFTTL 64 /* from RFC 1340. */
21 #define IP6_VTC_FLOW 0x60000000
23 /* Highest Item type supported by Flowman */
24 #define FM_MAX_ITEM_TYPE RTE_FLOW_ITEM_TYPE_VXLAN
26 /* Up to 1024 TCAM entries */
27 #define FM_MAX_TCAM_TABLE_SIZE 1024
29 /* Up to 4096 entries per exact match table */
30 #define FM_MAX_EXACT_TABLE_SIZE 4096
32 /* Number of counters to increase on for each increment */
33 #define FM_COUNTERS_EXPAND 100
35 #define FM_INVALID_HANDLE 0
37 /* Low priority used for implicit VF -> representor flow */
38 #define FM_LOWEST_PRIORITY 100000
40 /* High priority used for implicit representor -> VF flow */
41 #define FM_HIGHEST_PRIORITY 0
43 /* Tag used for implicit VF <-> representor flows */
44 #define FM_VF_REP_TAG 1
47 * Flow exact match tables (FET) in the VIC and rte_flow groups.
48 * Use a simple scheme to map groups to tables.
49 * Group 0 uses the single TCAM tables, one for each direction.
50 * Group 1, 2, ... uses its own exact match table.
52 * The TCAM tables are allocated upfront during init.
54 * Exact match tables are allocated on demand. 3 paths that lead allocations.
56 * 1. Add a flow that jumps from group 0 to group N.
58 * If N does not exist, we allocate an exact match table for it, using
59 * a dummy key. A key is required for the table.
61 * 2. Add a flow that uses group N.
63 * If N does not exist, we allocate an exact match table for it, using
64 * the flow's key. Subsequent flows to the same group all should have
67 * Without a jump flow to N, N is not reachable in hardware. No packets
70 * 3. Add a flow to an empty group N.
72 * N has been created via (1) and the dummy key. We free that table, allocate
73 * a new table using the new flow's key. Also re-do the existing jump flow to
74 * point to the new table.
76 #define FM_TCAM_RTE_GROUP 0
79 TAILQ_ENTRY(enic_fm_fet) list;
80 uint32_t group; /* rte_flow group ID */
81 uint64_t handle; /* Exact match table handle from flowman */
84 int ref; /* Reference count via get/put */
85 struct fm_key_template key; /* Key associated with the table */
88 struct enic_fm_counter {
89 SLIST_ENTRY(enic_fm_counter) next;
96 uint64_t entry_handle;
97 uint64_t action_handle;
98 struct enic_fm_counter *counter;
99 struct enic_fm_fet *fet;
100 /* Auto-added steer action for hairpin flows (e.g. vnic->vnic) */
101 struct enic_fm_flow *hairpin_steer_flow;
104 struct enic_fm_jump_flow {
105 TAILQ_ENTRY(enic_fm_jump_flow) list;
106 struct rte_flow *flow;
108 struct fm_tcam_match_entry match;
109 struct fm_action action;
113 * Flowman uses host memory for commands. This structure is allocated
114 * in DMA-able memory.
116 union enic_flowman_cmd_mem {
117 struct fm_tcam_match_table fm_tcam_match_table;
118 struct fm_exact_match_table fm_exact_match_table;
119 struct fm_tcam_match_entry fm_tcam_match_entry;
120 struct fm_exact_match_entry fm_exact_match_entry;
121 struct fm_action fm_action;
125 * PF has a flowman instance, and VF representors share it with PF.
126 * PF allocates this structure and owns it. VF representors borrow
127 * the PF's structure during API calls (e.g. create, query).
129 struct enic_flowman {
130 struct enic *owner_enic; /* PF */
131 struct enic *user_enic; /* API caller (PF or representor) */
133 * Representors and PF share the same underlying flowman.
134 * Lock API calls to serialize accesses from them. Only used
135 * when VF representors are present.
140 union enic_flowman_cmd_mem *va;
143 /* TCAM tables allocated upfront, used for group 0 */
144 uint64_t ig_tcam_hndl;
145 uint64_t eg_tcam_hndl;
147 SLIST_HEAD(enic_free_counters, enic_fm_counter) counters;
149 uint32_t counters_alloced;
150 /* Exact match tables for groups != 0, dynamically allocated */
151 TAILQ_HEAD(fet_list, enic_fm_fet) fet_list;
153 * Default exact match tables used for jump actions to
154 * non-existent groups.
156 struct enic_fm_fet *default_eg_fet;
157 struct enic_fm_fet *default_ig_fet;
158 /* Flows that jump to the default table above */
159 TAILQ_HEAD(jump_flow_list, enic_fm_jump_flow) jump_list;
161 * Scratch data used during each invocation of flow_create
164 struct enic_fm_fet *fet;
165 struct fm_tcam_match_entry tcam_entry;
166 struct fm_action action;
167 struct fm_action action_tmp; /* enic_fm_reorder_action_op */
169 /* Tags used for representor flows */
171 /* For auto-added steer action for hairpin */
172 int need_hairpin_steer;
173 uint64_t hairpin_steer_vnic_h;
176 static int enic_fm_tbl_free(struct enic_flowman *fm, uint64_t handle);
178 * API functions (create, destroy, validate, flush) call begin_fm()
179 * upon entering to save the caller enic (PF or VF representor) and
180 * lock. Upon exit, they call end_fm() to unlock.
182 static struct enic_flowman *begin_fm(struct enic *enic);
183 static void end_fm(struct enic_flowman *fm);
184 /* Delete internal flows created for representor paths */
185 static void delete_rep_flows(struct enic *enic);
188 * Common arguments passed to copy_item functions. Use this structure
189 * so we can easily add new arguments.
190 * item: Item specification.
191 * fm_tcam_entry: Flowman TCAM match entry.
192 * header_level: 0 for outer header, 1 for inner header.
194 struct copy_item_args {
195 const struct rte_flow_item *item;
196 struct fm_tcam_match_entry *fm_tcam_entry;
197 uint8_t header_level;
200 /* functions for copying items into flowman match */
201 typedef int (enic_copy_item_fn)(struct copy_item_args *arg);
203 /* Info about how to copy items into flowman match */
204 struct enic_fm_items {
205 /* Function for copying and validating an item. */
206 enic_copy_item_fn * const copy_item;
207 /* List of valid previous items. */
208 const enum rte_flow_item_type * const prev_items;
210 * True if it's OK for this item to be the first item. For some NIC
211 * versions, it's invalid to start the stack above layer 3.
213 const uint8_t valid_start_item;
216 static enic_copy_item_fn enic_fm_copy_item_eth;
217 static enic_copy_item_fn enic_fm_copy_item_ipv4;
218 static enic_copy_item_fn enic_fm_copy_item_ipv6;
219 static enic_copy_item_fn enic_fm_copy_item_raw;
220 static enic_copy_item_fn enic_fm_copy_item_sctp;
221 static enic_copy_item_fn enic_fm_copy_item_tcp;
222 static enic_copy_item_fn enic_fm_copy_item_udp;
223 static enic_copy_item_fn enic_fm_copy_item_vlan;
224 static enic_copy_item_fn enic_fm_copy_item_vxlan;
226 /* Ingress actions */
227 static const enum rte_flow_action_type enic_fm_supported_ig_actions[] = {
228 RTE_FLOW_ACTION_TYPE_COUNT,
229 RTE_FLOW_ACTION_TYPE_DROP,
230 RTE_FLOW_ACTION_TYPE_FLAG,
231 RTE_FLOW_ACTION_TYPE_JUMP,
232 RTE_FLOW_ACTION_TYPE_MARK,
233 RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
234 RTE_FLOW_ACTION_TYPE_PORT_ID,
235 RTE_FLOW_ACTION_TYPE_PASSTHRU,
236 RTE_FLOW_ACTION_TYPE_QUEUE,
237 RTE_FLOW_ACTION_TYPE_RSS,
238 RTE_FLOW_ACTION_TYPE_VOID,
239 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
240 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
241 RTE_FLOW_ACTION_TYPE_END, /* END must be the last entry */
245 static const enum rte_flow_action_type enic_fm_supported_eg_actions[] = {
246 RTE_FLOW_ACTION_TYPE_COUNT,
247 RTE_FLOW_ACTION_TYPE_DROP,
248 RTE_FLOW_ACTION_TYPE_JUMP,
249 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
250 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
251 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
252 RTE_FLOW_ACTION_TYPE_PORT_ID,
253 RTE_FLOW_ACTION_TYPE_PASSTHRU,
254 RTE_FLOW_ACTION_TYPE_VOID,
255 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
256 RTE_FLOW_ACTION_TYPE_END,
259 static const struct enic_fm_items enic_fm_items[] = {
260 [RTE_FLOW_ITEM_TYPE_RAW] = {
261 .copy_item = enic_fm_copy_item_raw,
262 .valid_start_item = 0,
263 .prev_items = (const enum rte_flow_item_type[]) {
264 RTE_FLOW_ITEM_TYPE_UDP,
265 RTE_FLOW_ITEM_TYPE_END,
268 [RTE_FLOW_ITEM_TYPE_ETH] = {
269 .copy_item = enic_fm_copy_item_eth,
270 .valid_start_item = 1,
271 .prev_items = (const enum rte_flow_item_type[]) {
272 RTE_FLOW_ITEM_TYPE_END,
275 [RTE_FLOW_ITEM_TYPE_VLAN] = {
276 .copy_item = enic_fm_copy_item_vlan,
277 .valid_start_item = 1,
278 .prev_items = (const enum rte_flow_item_type[]) {
279 RTE_FLOW_ITEM_TYPE_ETH,
280 RTE_FLOW_ITEM_TYPE_END,
283 [RTE_FLOW_ITEM_TYPE_IPV4] = {
284 .copy_item = enic_fm_copy_item_ipv4,
285 .valid_start_item = 1,
286 .prev_items = (const enum rte_flow_item_type[]) {
287 RTE_FLOW_ITEM_TYPE_ETH,
288 RTE_FLOW_ITEM_TYPE_VLAN,
289 RTE_FLOW_ITEM_TYPE_END,
292 [RTE_FLOW_ITEM_TYPE_IPV6] = {
293 .copy_item = enic_fm_copy_item_ipv6,
294 .valid_start_item = 1,
295 .prev_items = (const enum rte_flow_item_type[]) {
296 RTE_FLOW_ITEM_TYPE_ETH,
297 RTE_FLOW_ITEM_TYPE_VLAN,
298 RTE_FLOW_ITEM_TYPE_END,
301 [RTE_FLOW_ITEM_TYPE_UDP] = {
302 .copy_item = enic_fm_copy_item_udp,
303 .valid_start_item = 1,
304 .prev_items = (const enum rte_flow_item_type[]) {
305 RTE_FLOW_ITEM_TYPE_IPV4,
306 RTE_FLOW_ITEM_TYPE_IPV6,
307 RTE_FLOW_ITEM_TYPE_END,
310 [RTE_FLOW_ITEM_TYPE_TCP] = {
311 .copy_item = enic_fm_copy_item_tcp,
312 .valid_start_item = 1,
313 .prev_items = (const enum rte_flow_item_type[]) {
314 RTE_FLOW_ITEM_TYPE_IPV4,
315 RTE_FLOW_ITEM_TYPE_IPV6,
316 RTE_FLOW_ITEM_TYPE_END,
319 [RTE_FLOW_ITEM_TYPE_SCTP] = {
320 .copy_item = enic_fm_copy_item_sctp,
321 .valid_start_item = 0,
322 .prev_items = (const enum rte_flow_item_type[]) {
323 RTE_FLOW_ITEM_TYPE_IPV4,
324 RTE_FLOW_ITEM_TYPE_IPV6,
325 RTE_FLOW_ITEM_TYPE_END,
328 [RTE_FLOW_ITEM_TYPE_VXLAN] = {
329 .copy_item = enic_fm_copy_item_vxlan,
330 .valid_start_item = 1,
331 .prev_items = (const enum rte_flow_item_type[]) {
332 RTE_FLOW_ITEM_TYPE_UDP,
333 RTE_FLOW_ITEM_TYPE_END,
339 enic_fm_copy_item_eth(struct copy_item_args *arg)
341 const struct rte_flow_item *item = arg->item;
342 const struct rte_flow_item_eth *spec = item->spec;
343 const struct rte_flow_item_eth *mask = item->mask;
344 const uint8_t lvl = arg->header_level;
345 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
346 struct fm_header_set *fm_data, *fm_mask;
348 ENICPMD_FUNC_TRACE();
349 /* Match all if no spec */
353 mask = &rte_flow_item_eth_mask;
354 fm_data = &entry->ftm_data.fk_hdrset[lvl];
355 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
356 fm_data->fk_header_select |= FKH_ETHER;
357 fm_mask->fk_header_select |= FKH_ETHER;
358 memcpy(&fm_data->l2.eth, spec, sizeof(*spec));
359 memcpy(&fm_mask->l2.eth, mask, sizeof(*mask));
364 enic_fm_copy_item_vlan(struct copy_item_args *arg)
366 const struct rte_flow_item *item = arg->item;
367 const struct rte_flow_item_vlan *spec = item->spec;
368 const struct rte_flow_item_vlan *mask = item->mask;
369 const uint8_t lvl = arg->header_level;
370 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
371 struct fm_header_set *fm_data, *fm_mask;
372 struct rte_ether_hdr *eth_mask;
373 struct rte_ether_hdr *eth_val;
376 ENICPMD_FUNC_TRACE();
377 fm_data = &entry->ftm_data.fk_hdrset[lvl];
378 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
379 /* Outer and inner packet vlans need different flags */
380 meta = FKM_VLAN_PRES;
383 fm_data->fk_metadata |= meta;
384 fm_mask->fk_metadata |= meta;
386 /* Match all if no spec */
390 mask = &rte_flow_item_vlan_mask;
392 eth_mask = (void *)&fm_mask->l2.eth;
393 eth_val = (void *)&fm_data->l2.eth;
396 * Outer TPID cannot be matched. If inner_type is 0, use what is
399 if (eth_mask->ether_type && mask->inner_type)
403 * When packet matching, the VIC always compares vlan-stripped
404 * L2, regardless of vlan stripping settings. So, the inner type
405 * from vlan becomes the ether type of the eth header.
407 if (mask->inner_type) {
408 eth_mask->ether_type = mask->inner_type;
409 eth_val->ether_type = spec->inner_type;
411 fm_data->fk_header_select |= FKH_ETHER | FKH_QTAG;
412 fm_mask->fk_header_select |= FKH_ETHER | FKH_QTAG;
413 fm_data->fk_vlan = rte_be_to_cpu_16(spec->tci);
414 fm_mask->fk_vlan = rte_be_to_cpu_16(mask->tci);
419 enic_fm_copy_item_ipv4(struct copy_item_args *arg)
421 const struct rte_flow_item *item = arg->item;
422 const struct rte_flow_item_ipv4 *spec = item->spec;
423 const struct rte_flow_item_ipv4 *mask = item->mask;
424 const uint8_t lvl = arg->header_level;
425 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
426 struct fm_header_set *fm_data, *fm_mask;
428 ENICPMD_FUNC_TRACE();
429 fm_data = &entry->ftm_data.fk_hdrset[lvl];
430 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
431 fm_data->fk_metadata |= FKM_IPV4;
432 fm_mask->fk_metadata |= FKM_IPV4;
437 mask = &rte_flow_item_ipv4_mask;
439 fm_data->fk_header_select |= FKH_IPV4;
440 fm_mask->fk_header_select |= FKH_IPV4;
441 memcpy(&fm_data->l3.ip4, spec, sizeof(*spec));
442 memcpy(&fm_mask->l3.ip4, mask, sizeof(*mask));
447 enic_fm_copy_item_ipv6(struct copy_item_args *arg)
449 const struct rte_flow_item *item = arg->item;
450 const struct rte_flow_item_ipv6 *spec = item->spec;
451 const struct rte_flow_item_ipv6 *mask = item->mask;
452 const uint8_t lvl = arg->header_level;
453 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
454 struct fm_header_set *fm_data, *fm_mask;
456 ENICPMD_FUNC_TRACE();
457 fm_data = &entry->ftm_data.fk_hdrset[lvl];
458 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
459 fm_data->fk_metadata |= FKM_IPV6;
460 fm_mask->fk_metadata |= FKM_IPV6;
465 mask = &rte_flow_item_ipv6_mask;
467 fm_data->fk_header_select |= FKH_IPV6;
468 fm_mask->fk_header_select |= FKH_IPV6;
469 memcpy(&fm_data->l3.ip6, spec, sizeof(*spec));
470 memcpy(&fm_mask->l3.ip6, mask, sizeof(*mask));
475 enic_fm_copy_item_udp(struct copy_item_args *arg)
477 const struct rte_flow_item *item = arg->item;
478 const struct rte_flow_item_udp *spec = item->spec;
479 const struct rte_flow_item_udp *mask = item->mask;
480 const uint8_t lvl = arg->header_level;
481 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
482 struct fm_header_set *fm_data, *fm_mask;
484 ENICPMD_FUNC_TRACE();
485 fm_data = &entry->ftm_data.fk_hdrset[lvl];
486 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
487 fm_data->fk_metadata |= FKM_UDP;
488 fm_mask->fk_metadata |= FKM_UDP;
493 mask = &rte_flow_item_udp_mask;
495 fm_data->fk_header_select |= FKH_UDP;
496 fm_mask->fk_header_select |= FKH_UDP;
497 memcpy(&fm_data->l4.udp, spec, sizeof(*spec));
498 memcpy(&fm_mask->l4.udp, mask, sizeof(*mask));
503 enic_fm_copy_item_tcp(struct copy_item_args *arg)
505 const struct rte_flow_item *item = arg->item;
506 const struct rte_flow_item_tcp *spec = item->spec;
507 const struct rte_flow_item_tcp *mask = item->mask;
508 const uint8_t lvl = arg->header_level;
509 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
510 struct fm_header_set *fm_data, *fm_mask;
512 ENICPMD_FUNC_TRACE();
513 fm_data = &entry->ftm_data.fk_hdrset[lvl];
514 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
515 fm_data->fk_metadata |= FKM_TCP;
516 fm_mask->fk_metadata |= FKM_TCP;
521 mask = &rte_flow_item_tcp_mask;
523 fm_data->fk_header_select |= FKH_TCP;
524 fm_mask->fk_header_select |= FKH_TCP;
525 memcpy(&fm_data->l4.tcp, spec, sizeof(*spec));
526 memcpy(&fm_mask->l4.tcp, mask, sizeof(*mask));
531 enic_fm_copy_item_sctp(struct copy_item_args *arg)
533 const struct rte_flow_item *item = arg->item;
534 const struct rte_flow_item_sctp *spec = item->spec;
535 const struct rte_flow_item_sctp *mask = item->mask;
536 const uint8_t lvl = arg->header_level;
537 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
538 struct fm_header_set *fm_data, *fm_mask;
539 uint8_t *ip_proto_mask = NULL;
540 uint8_t *ip_proto = NULL;
543 ENICPMD_FUNC_TRACE();
544 fm_data = &entry->ftm_data.fk_hdrset[lvl];
545 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
547 * The NIC filter API has no flags for "match sctp", so explicitly
548 * set the protocol number in the IP pattern.
550 if (fm_data->fk_metadata & FKM_IPV4) {
551 struct rte_ipv4_hdr *ip;
552 ip = (struct rte_ipv4_hdr *)&fm_mask->l3.ip4;
553 ip_proto_mask = &ip->next_proto_id;
554 ip = (struct rte_ipv4_hdr *)&fm_data->l3.ip4;
555 ip_proto = &ip->next_proto_id;
557 } else if (fm_data->fk_metadata & FKM_IPV6) {
558 struct rte_ipv6_hdr *ip;
559 ip = (struct rte_ipv6_hdr *)&fm_mask->l3.ip6;
560 ip_proto_mask = &ip->proto;
561 ip = (struct rte_ipv6_hdr *)&fm_data->l3.ip6;
562 ip_proto = &ip->proto;
565 /* Need IPv4/IPv6 pattern first */
568 *ip_proto = IPPROTO_SCTP;
569 *ip_proto_mask = 0xff;
570 fm_data->fk_header_select |= l3_fkh;
571 fm_mask->fk_header_select |= l3_fkh;
576 mask = &rte_flow_item_sctp_mask;
578 fm_data->fk_header_select |= FKH_L4RAW;
579 fm_mask->fk_header_select |= FKH_L4RAW;
580 memcpy(fm_data->l4.rawdata, spec, sizeof(*spec));
581 memcpy(fm_mask->l4.rawdata, mask, sizeof(*mask));
586 enic_fm_copy_item_vxlan(struct copy_item_args *arg)
588 const struct rte_flow_item *item = arg->item;
589 const struct rte_flow_item_vxlan *spec = item->spec;
590 const struct rte_flow_item_vxlan *mask = item->mask;
591 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
592 struct fm_header_set *fm_data, *fm_mask;
594 ENICPMD_FUNC_TRACE();
595 /* Only 2 header levels (outer and inner) allowed */
596 if (arg->header_level > 0)
599 fm_data = &entry->ftm_data.fk_hdrset[0];
600 fm_mask = &entry->ftm_mask.fk_hdrset[0];
601 fm_data->fk_metadata |= FKM_VXLAN;
602 fm_mask->fk_metadata |= FKM_VXLAN;
603 /* items from here on out are inner header items */
604 arg->header_level = 1;
606 /* Match all if no spec */
610 mask = &rte_flow_item_vxlan_mask;
612 fm_data->fk_header_select |= FKH_VXLAN;
613 fm_mask->fk_header_select |= FKH_VXLAN;
614 memcpy(&fm_data->vxlan, spec, sizeof(*spec));
615 memcpy(&fm_mask->vxlan, mask, sizeof(*mask));
620 * Currently, raw pattern match is very limited. It is intended for matching
621 * UDP tunnel header (e.g. vxlan or geneve).
624 enic_fm_copy_item_raw(struct copy_item_args *arg)
626 const struct rte_flow_item *item = arg->item;
627 const struct rte_flow_item_raw *spec = item->spec;
628 const struct rte_flow_item_raw *mask = item->mask;
629 const uint8_t lvl = arg->header_level;
630 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
631 struct fm_header_set *fm_data, *fm_mask;
633 ENICPMD_FUNC_TRACE();
634 /* Cannot be used for inner packet */
637 /* Need both spec and mask */
640 /* Only supports relative with offset 0 */
641 if (!spec->relative || spec->offset != 0 || spec->search ||
644 /* Need non-null pattern that fits within the NIC's filter pattern */
645 if (spec->length == 0 ||
646 spec->length + sizeof(struct rte_udp_hdr) > FM_LAYER_SIZE ||
647 !spec->pattern || !mask->pattern)
650 * Mask fields, including length, are often set to zero. Assume that
651 * means "same as spec" to avoid breaking existing apps. If length
652 * is not zero, then it should be >= spec length.
654 * No more pattern follows this, so append to the L4 layer instead of
655 * L5 to work with both recent and older VICs.
657 if (mask->length != 0 && mask->length < spec->length)
660 fm_data = &entry->ftm_data.fk_hdrset[lvl];
661 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
662 fm_data->fk_header_select |= FKH_L4RAW;
663 fm_mask->fk_header_select |= FKH_L4RAW;
664 fm_data->fk_header_select &= ~FKH_UDP;
665 fm_mask->fk_header_select &= ~FKH_UDP;
666 memcpy(fm_data->l4.rawdata + sizeof(struct rte_udp_hdr),
667 spec->pattern, spec->length);
668 memcpy(fm_mask->l4.rawdata + sizeof(struct rte_udp_hdr),
669 mask->pattern, spec->length);
674 flowman_cmd(struct enic_flowman *fm, uint64_t *args, int nargs)
676 return vnic_dev_flowman_cmd(fm->owner_enic->vdev, args, nargs);
680 enic_fet_alloc(struct enic_flowman *fm, uint8_t ingress,
681 struct fm_key_template *key, int entries,
682 struct enic_fm_fet **fet_out)
684 struct fm_exact_match_table *cmd;
685 struct fm_header_set *hdr;
686 struct enic_fm_fet *fet;
690 ENICPMD_FUNC_TRACE();
691 fet = calloc(1, sizeof(struct enic_fm_fet));
694 cmd = &fm->cmd.va->fm_exact_match_table;
695 memset(cmd, 0, sizeof(*cmd));
696 cmd->fet_direction = ingress ? FM_INGRESS : FM_EGRESS;
697 cmd->fet_stage = FM_STAGE_LAST;
698 cmd->fet_max_entries = entries ? entries : FM_MAX_EXACT_TABLE_SIZE;
700 hdr = &cmd->fet_key.fk_hdrset[0];
701 memset(hdr, 0, sizeof(*hdr));
702 hdr->fk_header_select = FKH_IPV4 | FKH_UDP;
703 hdr->l3.ip4.fk_saddr = 0xFFFFFFFF;
704 hdr->l3.ip4.fk_daddr = 0xFFFFFFFF;
705 hdr->l4.udp.fk_source = 0xFFFF;
706 hdr->l4.udp.fk_dest = 0xFFFF;
707 fet->default_key = 1;
709 memcpy(&cmd->fet_key, key, sizeof(*key));
710 memcpy(&fet->key, key, sizeof(*key));
711 fet->default_key = 0;
713 cmd->fet_key.fk_packet_tag = 1;
715 args[0] = FM_EXACT_TABLE_ALLOC;
716 args[1] = fm->cmd.pa;
717 ret = flowman_cmd(fm, args, 2);
719 ENICPMD_LOG(ERR, "cannot alloc exact match table: rc=%d", ret);
723 fet->handle = args[0];
724 fet->ingress = ingress;
725 ENICPMD_LOG(DEBUG, "allocated exact match table: handle=0x%" PRIx64,
732 enic_fet_free(struct enic_flowman *fm, struct enic_fm_fet *fet)
734 ENICPMD_FUNC_TRACE();
735 enic_fm_tbl_free(fm, fet->handle);
736 if (!fet->default_key)
737 TAILQ_REMOVE(&fm->fet_list, fet, list);
742 * Get the exact match table for the given combination of
743 * <group, ingress, key>. Allocate one on the fly as necessary.
746 enic_fet_get(struct enic_flowman *fm,
749 struct fm_key_template *key,
750 struct enic_fm_fet **fet_out,
751 struct rte_flow_error *error)
753 struct enic_fm_fet *fet;
755 ENICPMD_FUNC_TRACE();
756 /* See if we already have this table open */
757 TAILQ_FOREACH(fet, &fm->fet_list, list) {
758 if (fet->group == group && fet->ingress == ingress)
762 /* Jumping to a non-existing group? Use the default table */
764 fet = ingress ? fm->default_ig_fet : fm->default_eg_fet;
765 } else if (enic_fet_alloc(fm, ingress, key, 0, &fet)) {
766 return rte_flow_error_set(error, EINVAL,
767 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
768 NULL, "enic: cannot get exact match table");
771 /* Default table is never on the open table list */
772 if (!fet->default_key)
773 TAILQ_INSERT_HEAD(&fm->fet_list, fet, list);
777 ENICPMD_LOG(DEBUG, "fet_get: %s %s group=%u ref=%u",
778 fet->default_key ? "default" : "",
779 fet->ingress ? "ingress" : "egress",
780 fet->group, fet->ref);
785 enic_fet_put(struct enic_flowman *fm, struct enic_fm_fet *fet)
787 ENICPMD_FUNC_TRACE();
788 RTE_ASSERT(fet->ref > 0);
790 ENICPMD_LOG(DEBUG, "fet_put: %s %s group=%u ref=%u",
791 fet->default_key ? "default" : "",
792 fet->ingress ? "ingress" : "egress",
793 fet->group, fet->ref);
795 enic_fet_free(fm, fet);
798 /* Return 1 if current item is valid on top of the previous one. */
800 fm_item_stacking_valid(enum rte_flow_item_type prev_item,
801 const struct enic_fm_items *item_info,
802 uint8_t is_first_item)
804 enum rte_flow_item_type const *allowed_items = item_info->prev_items;
806 ENICPMD_FUNC_TRACE();
807 for (; *allowed_items != RTE_FLOW_ITEM_TYPE_END; allowed_items++) {
808 if (prev_item == *allowed_items)
812 /* This is the first item in the stack. Check if that's cool */
813 if (is_first_item && item_info->valid_start_item)
819 * Build the flow manager match entry structure from the provided pattern.
820 * The pattern is validated as the items are copied.
823 enic_fm_copy_entry(struct enic_flowman *fm,
824 const struct rte_flow_item pattern[],
825 struct rte_flow_error *error)
827 const struct enic_fm_items *item_info;
828 enum rte_flow_item_type prev_item;
829 const struct rte_flow_item *item;
830 struct copy_item_args args;
831 uint8_t prev_header_level;
832 uint8_t is_first_item;
835 ENICPMD_FUNC_TRACE();
838 prev_item = RTE_FLOW_ITEM_TYPE_END;
840 args.fm_tcam_entry = &fm->tcam_entry;
841 args.header_level = 0;
842 prev_header_level = 0;
843 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
845 * Get info about how to validate and copy the item. If NULL
846 * is returned the nic does not support the item.
848 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
851 item_info = &enic_fm_items[item->type];
853 if (item->type > FM_MAX_ITEM_TYPE ||
854 item_info->copy_item == NULL) {
855 return rte_flow_error_set(error, ENOTSUP,
856 RTE_FLOW_ERROR_TYPE_ITEM,
857 NULL, "enic: unsupported item");
860 /* check to see if item stacking is valid */
861 if (!fm_item_stacking_valid(prev_item, item_info,
866 ret = item_info->copy_item(&args);
868 goto item_not_supported;
869 /* Going from outer to inner? Treat it as a new packet start */
870 if (prev_header_level != args.header_level) {
871 prev_item = RTE_FLOW_ITEM_TYPE_END;
874 prev_item = item->type;
877 prev_header_level = args.header_level;
882 return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM,
883 NULL, "enic: unsupported item type");
886 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
887 item, "enic: unsupported item stack");
891 flow_item_skip_void(const struct rte_flow_item **item)
894 if ((*item)->type != RTE_FLOW_ITEM_TYPE_VOID)
899 append_template(void **template, uint8_t *off, const void *data, int len)
901 memcpy(*template, data, len);
902 *template = (char *)*template + len;
907 enic_fm_append_action_op(struct enic_flowman *fm,
908 struct fm_action_op *fm_op,
909 struct rte_flow_error *error)
913 count = fm->action_op_count;
914 ENICPMD_LOG(DEBUG, "append action op: idx=%d op=%u",
915 count, fm_op->fa_op);
916 if (count == FM_ACTION_OP_MAX) {
917 return rte_flow_error_set(error, EINVAL,
918 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
919 "too many action operations");
921 fm->action.fma_action_ops[count] = *fm_op;
922 fm->action_op_count = count + 1;
926 static struct fm_action_op *
927 find_prev_action_op(struct enic_flowman *fm, uint32_t opcode)
929 struct fm_action_op *op;
932 for (i = 0; i < fm->action_op_count; i++) {
933 op = &fm->action.fma_action_ops[i];
934 if (op->fa_op == opcode)
940 /* NIC requires that 1st steer appear before decap.
941 * Correct example: steer, decap, steer, steer, ...
944 enic_fm_reorder_action_op(struct enic_flowman *fm)
946 struct fm_action_op *op, *steer, *decap;
947 struct fm_action_op tmp_op;
949 ENICPMD_FUNC_TRACE();
950 /* Find 1st steer and decap */
951 op = fm->action.fma_action_ops;
954 while (op->fa_op != FMOP_END) {
955 if (!decap && (op->fa_op == FMOP_DECAP_NOSTRIP ||
956 op->fa_op == FMOP_DECAP_STRIP))
958 else if (!steer && op->fa_op == FMOP_RQ_STEER)
962 /* If decap is before steer, swap */
963 if (steer && decap && decap < steer) {
964 op = fm->action.fma_action_ops;
965 ENICPMD_LOG(DEBUG, "swap decap %ld <-> steer %ld",
966 (long)(decap - op), (long)(steer - op));
973 /* VXLAN decap is done via flowman compound action */
975 enic_fm_copy_vxlan_decap(struct enic_flowman *fm,
976 struct fm_tcam_match_entry *fmt,
977 const struct rte_flow_action *action,
978 struct rte_flow_error *error)
980 struct fm_header_set *fm_data;
981 struct fm_action_op fm_op;
983 ENICPMD_FUNC_TRACE();
984 fm_data = &fmt->ftm_data.fk_hdrset[0];
985 if (!(fm_data->fk_metadata & FKM_VXLAN)) {
986 return rte_flow_error_set(error, EINVAL,
987 RTE_FLOW_ERROR_TYPE_ACTION, action,
988 "vxlan-decap: vxlan must be in pattern");
991 memset(&fm_op, 0, sizeof(fm_op));
992 fm_op.fa_op = FMOP_DECAP_NOSTRIP;
993 return enic_fm_append_action_op(fm, &fm_op, error);
996 /* Generate a reasonable source port number */
1000 /* Min/max below are the default values in OVS-DPDK and Linux */
1001 uint16_t p = rte_rand();
1002 p = RTE_MAX(p, 32768);
1003 p = RTE_MIN(p, 61000);
1004 return rte_cpu_to_be_16(p);
1007 /* VXLAN encap is done via flowman compound action */
1009 enic_fm_copy_vxlan_encap(struct enic_flowman *fm,
1010 const struct rte_flow_item *item,
1011 struct rte_flow_error *error)
1013 struct fm_action_op fm_op;
1014 struct rte_ether_hdr *eth;
1015 struct rte_udp_hdr *udp;
1016 uint16_t *ethertype;
1020 ENICPMD_FUNC_TRACE();
1021 memset(&fm_op, 0, sizeof(fm_op));
1022 fm_op.fa_op = FMOP_ENCAP;
1023 template = fm->action.fma_data;
1026 * Copy flow items to the flowman template starting L2.
1027 * L2 must be ethernet.
1029 flow_item_skip_void(&item);
1030 if (item->type != RTE_FLOW_ITEM_TYPE_ETH)
1031 return rte_flow_error_set(error, EINVAL,
1032 RTE_FLOW_ERROR_TYPE_ITEM, item,
1033 "vxlan-encap: first item should be ethernet");
1034 eth = (struct rte_ether_hdr *)template;
1035 ethertype = ð->ether_type;
1036 append_template(&template, &off, item->spec,
1037 sizeof(struct rte_flow_item_eth));
1039 flow_item_skip_void(&item);
1041 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1042 const struct rte_flow_item_vlan *spec;
1044 ENICPMD_LOG(DEBUG, "vxlan-encap: vlan");
1046 fm_op.encap.outer_vlan = rte_be_to_cpu_16(spec->tci);
1048 flow_item_skip_void(&item);
1050 /* L3 must be IPv4, IPv6 */
1051 switch (item->type) {
1052 case RTE_FLOW_ITEM_TYPE_IPV4:
1054 struct rte_ipv4_hdr *ip4;
1056 ENICPMD_LOG(DEBUG, "vxlan-encap: ipv4");
1057 *ethertype = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
1058 ip4 = (struct rte_ipv4_hdr *)template;
1060 * Offset of IPv4 length field and its initial value
1061 * (IP + UDP + VXLAN) are specified in the action. The NIC
1062 * will add inner packet length.
1064 fm_op.encap.len1_offset = off +
1065 offsetof(struct rte_ipv4_hdr, total_length);
1066 fm_op.encap.len1_delta = sizeof(struct rte_ipv4_hdr) +
1067 sizeof(struct rte_udp_hdr) +
1068 sizeof(struct rte_vxlan_hdr);
1069 append_template(&template, &off, item->spec,
1070 sizeof(struct rte_ipv4_hdr));
1071 ip4->version_ihl = RTE_IPV4_VHL_DEF;
1072 if (ip4->time_to_live == 0)
1073 ip4->time_to_live = IP_DEFTTL;
1074 ip4->next_proto_id = IPPROTO_UDP;
1077 case RTE_FLOW_ITEM_TYPE_IPV6:
1079 struct rte_ipv6_hdr *ip6;
1081 ENICPMD_LOG(DEBUG, "vxlan-encap: ipv6");
1082 *ethertype = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
1083 ip6 = (struct rte_ipv6_hdr *)template;
1084 fm_op.encap.len1_offset = off +
1085 offsetof(struct rte_ipv6_hdr, payload_len);
1086 fm_op.encap.len1_delta = sizeof(struct rte_udp_hdr) +
1087 sizeof(struct rte_vxlan_hdr);
1088 append_template(&template, &off, item->spec,
1089 sizeof(struct rte_ipv6_hdr));
1090 ip6->vtc_flow |= rte_cpu_to_be_32(IP6_VTC_FLOW);
1091 if (ip6->hop_limits == 0)
1092 ip6->hop_limits = IP_DEFTTL;
1093 ip6->proto = IPPROTO_UDP;
1097 return rte_flow_error_set(error,
1098 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, item,
1099 "vxlan-encap: L3 must be IPv4/IPv6");
1102 flow_item_skip_void(&item);
1105 if (item->type != RTE_FLOW_ITEM_TYPE_UDP)
1106 return rte_flow_error_set(error, EINVAL,
1107 RTE_FLOW_ERROR_TYPE_ITEM, item,
1108 "vxlan-encap: UDP must follow IPv4/IPv6");
1109 /* UDP length = UDP + VXLAN. NIC will add inner packet length. */
1110 fm_op.encap.len2_offset =
1111 off + offsetof(struct rte_udp_hdr, dgram_len);
1112 fm_op.encap.len2_delta =
1113 sizeof(struct rte_udp_hdr) + sizeof(struct rte_vxlan_hdr);
1114 udp = (struct rte_udp_hdr *)template;
1115 append_template(&template, &off, item->spec,
1116 sizeof(struct rte_udp_hdr));
1118 * Firmware does not hash/fill source port yet. Generate a
1119 * random port, as there is *usually* one rte_flow for the
1120 * given inner packet stream (i.e. a single stream has one
1123 if (udp->src_port == 0)
1124 udp->src_port = gen_src_port();
1126 flow_item_skip_void(&item);
1129 if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN)
1130 return rte_flow_error_set(error,
1131 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, item,
1132 "vxlan-encap: VXLAN must follow UDP");
1133 append_template(&template, &off, item->spec,
1134 sizeof(struct rte_flow_item_vxlan));
1137 * Fill in the rest of the action structure.
1138 * Indicate that we want to encap with vxlan at packet start.
1140 fm_op.encap.template_offset = 0;
1141 fm_op.encap.template_len = off;
1142 return enic_fm_append_action_op(fm, &fm_op, error);
1146 enic_fm_find_vnic(struct enic *enic, const struct rte_pci_addr *addr,
1153 ENICPMD_FUNC_TRACE();
1154 ENICPMD_LOG(DEBUG, "bdf=%x:%x:%x", addr->bus, addr->devid,
1156 bdf = addr->bus << 8 | addr->devid << 3 | addr->function;
1157 args[0] = FM_VNIC_FIND;
1159 rc = vnic_dev_flowman_cmd(enic->vdev, args, 2);
1161 /* Expected to fail if BDF is not on the adapter */
1162 ENICPMD_LOG(DEBUG, "cannot find vnic handle: rc=%d", rc);
1166 ENICPMD_LOG(DEBUG, "found vnic: handle=0x%" PRIx64, *handle);
1171 * Egress: target port should be either PF uplink or VF.
1173 * 1. VF egress -> PF uplink
1174 * PF may be this VF's PF, or another PF, as long as they are on the same VIC.
1175 * 2. VF egress -> VF
1178 * 1. PF egress -> VF
1179 * App should be using representor to pass packets to VF
1182 vf_egress_port_id_action(struct enic_flowman *fm,
1183 struct rte_eth_dev *dst_dev,
1184 uint64_t dst_vnic_h,
1185 struct fm_action_op *fm_op,
1186 struct rte_flow_error *error)
1188 struct enic *src_enic, *dst_enic;
1189 struct enic_vf_representor *vf;
1193 ENICPMD_FUNC_TRACE();
1194 src_enic = fm->user_enic;
1195 dst_enic = pmd_priv(dst_dev);
1196 if (!(src_enic->rte_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
1197 return rte_flow_error_set(error, EINVAL,
1198 RTE_FLOW_ERROR_TYPE_ACTION,
1199 NULL, "source port is not VF representor");
1202 /* VF -> PF uplink. dst is not VF representor */
1203 if (!(dst_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
1204 /* PF is the VF's PF? Then nothing to do */
1205 vf = VF_ENIC_TO_VF_REP(src_enic);
1206 if (vf->pf == dst_enic) {
1207 ENICPMD_LOG(DEBUG, "destination port is VF's PF");
1210 /* If not, steer to the remote PF's uplink */
1211 uif = dst_enic->fm_vnic_uif;
1212 ENICPMD_LOG(DEBUG, "steer to uplink %u", uif);
1213 memset(fm_op, 0, sizeof(*fm_op));
1214 fm_op->fa_op = FMOP_SET_EGPORT;
1215 fm_op->set_egport.egport = uif;
1216 ret = enic_fm_append_action_op(fm, fm_op, error);
1220 /* VF -> VF loopback. Hairpin and steer to vnic */
1221 memset(fm_op, 0, sizeof(*fm_op));
1222 fm_op->fa_op = FMOP_EG_HAIRPIN;
1223 ret = enic_fm_append_action_op(fm, fm_op, error);
1226 ENICPMD_LOG(DEBUG, "egress hairpin");
1227 fm->hairpin_steer_vnic_h = dst_vnic_h;
1228 fm->need_hairpin_steer = 1;
1232 /* Translate flow actions to flowman TCAM entry actions */
1234 enic_fm_copy_action(struct enic_flowman *fm,
1235 const struct rte_flow_action actions[],
1237 struct rte_flow_error *error)
1248 struct fm_tcam_match_entry *fmt;
1249 struct fm_action_op fm_op;
1250 bool need_ovlan_action;
1259 ENICPMD_FUNC_TRACE();
1260 fmt = &fm->tcam_entry;
1261 need_ovlan_action = false;
1265 enic = fm->user_enic;
1267 vnic_h = enic->fm_vnic_handle;
1269 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1270 switch (actions->type) {
1271 case RTE_FLOW_ACTION_TYPE_VOID:
1273 case RTE_FLOW_ACTION_TYPE_PASSTHRU: {
1274 if (overlap & PASSTHRU)
1276 overlap |= PASSTHRU;
1279 case RTE_FLOW_ACTION_TYPE_JUMP: {
1280 const struct rte_flow_action_jump *jump =
1282 struct enic_fm_fet *fet;
1286 ret = enic_fet_get(fm, jump->group, ingress, NULL,
1291 memset(&fm_op, 0, sizeof(fm_op));
1292 fm_op.fa_op = FMOP_EXACT_MATCH;
1293 fm_op.exact.handle = fet->handle;
1295 ret = enic_fm_append_action_op(fm, &fm_op, error);
1300 case RTE_FLOW_ACTION_TYPE_MARK: {
1301 const struct rte_flow_action_mark *mark =
1304 if (mark->id >= ENIC_MAGIC_FILTER_ID - 1)
1305 return rte_flow_error_set(error, EINVAL,
1306 RTE_FLOW_ERROR_TYPE_ACTION,
1307 NULL, "invalid mark id");
1308 memset(&fm_op, 0, sizeof(fm_op));
1309 fm_op.fa_op = FMOP_MARK;
1310 fm_op.mark.mark = mark->id + 1;
1311 ret = enic_fm_append_action_op(fm, &fm_op, error);
1316 case RTE_FLOW_ACTION_TYPE_FLAG: {
1317 /* ENIC_MAGIC_FILTER_ID is reserved for flagging */
1318 memset(&fm_op, 0, sizeof(fm_op));
1319 fm_op.fa_op = FMOP_MARK;
1320 fm_op.mark.mark = ENIC_MAGIC_FILTER_ID;
1321 ret = enic_fm_append_action_op(fm, &fm_op, error);
1326 case RTE_FLOW_ACTION_TYPE_QUEUE: {
1327 const struct rte_flow_action_queue *queue =
1331 * If fate other than QUEUE or RSS, fail. Multiple
1332 * rss and queue actions are ok.
1334 if ((overlap & FATE) && first_rq)
1338 memset(&fm_op, 0, sizeof(fm_op));
1339 fm_op.fa_op = FMOP_RQ_STEER;
1340 fm_op.rq_steer.rq_index =
1341 enic_rte_rq_idx_to_sop_idx(queue->index);
1342 fm_op.rq_steer.rq_count = 1;
1343 fm_op.rq_steer.vnic_handle = vnic_h;
1344 ret = enic_fm_append_action_op(fm, &fm_op, error);
1347 ENICPMD_LOG(DEBUG, "create QUEUE action rq: %u",
1348 fm_op.rq_steer.rq_index);
1352 case RTE_FLOW_ACTION_TYPE_DROP: {
1356 memset(&fm_op, 0, sizeof(fm_op));
1357 fm_op.fa_op = FMOP_DROP;
1358 ret = enic_fm_append_action_op(fm, &fm_op, error);
1361 ENICPMD_LOG(DEBUG, "create DROP action");
1364 case RTE_FLOW_ACTION_TYPE_COUNT: {
1365 if (overlap & COUNT)
1368 /* Count is associated with entry not action on VIC. */
1369 fmt->ftm_flags |= FMEF_COUNTER;
1372 case RTE_FLOW_ACTION_TYPE_RSS: {
1373 const struct rte_flow_action_rss *rss = actions->conf;
1378 * If fate other than QUEUE or RSS, fail. Multiple
1379 * rss and queue actions are ok.
1381 if ((overlap & FATE) && first_rq)
1387 * Hardware only supports RSS actions on outer level
1388 * with default type and function. Queues must be
1391 allow = rss->func == RTE_ETH_HASH_FUNCTION_DEFAULT &&
1392 rss->level == 0 && (rss->types == 0 ||
1393 rss->types == enic->rss_hf) &&
1394 rss->queue_num <= enic->rq_count &&
1395 rss->queue[rss->queue_num - 1] < enic->rq_count;
1398 /* Identity queue map needs to be sequential */
1399 for (i = 1; i < rss->queue_num; i++)
1400 allow = allow && (rss->queue[i] ==
1401 rss->queue[i - 1] + 1);
1405 memset(&fm_op, 0, sizeof(fm_op));
1406 fm_op.fa_op = FMOP_RQ_STEER;
1407 fm_op.rq_steer.rq_index =
1408 enic_rte_rq_idx_to_sop_idx(rss->queue[0]);
1409 fm_op.rq_steer.rq_count = rss->queue_num;
1410 fm_op.rq_steer.vnic_handle = vnic_h;
1411 ret = enic_fm_append_action_op(fm, &fm_op, error);
1414 ENICPMD_LOG(DEBUG, "create QUEUE action rq: %u",
1415 fm_op.rq_steer.rq_index);
1419 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
1420 const struct rte_flow_action_port_id *port;
1421 struct rte_eth_dev *dev;
1423 if (!ingress && (overlap & PORT_ID)) {
1424 ENICPMD_LOG(DEBUG, "cannot have multiple egress PORT_ID actions");
1427 port = actions->conf;
1428 if (port->original) {
1429 vnic_h = enic->fm_vnic_handle; /* This port */
1432 ENICPMD_LOG(DEBUG, "port id %u", port->id);
1433 if (!rte_eth_dev_is_valid_port(port->id)) {
1434 return rte_flow_error_set(error, EINVAL,
1435 RTE_FLOW_ERROR_TYPE_ACTION,
1436 NULL, "invalid port_id");
1438 dev = &rte_eth_devices[port->id];
1439 if (!dev_is_enic(dev)) {
1440 return rte_flow_error_set(error, EINVAL,
1441 RTE_FLOW_ERROR_TYPE_ACTION,
1442 NULL, "port_id is not enic");
1444 if (enic->switch_domain_id !=
1445 pmd_priv(dev)->switch_domain_id) {
1446 return rte_flow_error_set(error, EINVAL,
1447 RTE_FLOW_ERROR_TYPE_ACTION,
1448 NULL, "destination and source ports are not in the same switch domain");
1450 vnic_h = pmd_priv(dev)->fm_vnic_handle;
1453 * Ingress. Nothing more to do. We add an implicit
1454 * steer at the end if needed.
1459 ret = vf_egress_port_id_action(fm, dev, vnic_h, &fm_op,
1465 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP: {
1466 if (overlap & DECAP)
1470 ret = enic_fm_copy_vxlan_decap(fm, fmt, actions,
1476 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP: {
1477 const struct rte_flow_action_vxlan_encap *encap;
1479 encap = actions->conf;
1480 if (overlap & ENCAP)
1483 ret = enic_fm_copy_vxlan_encap(fm, encap->definition,
1489 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: {
1490 struct fm_action_op *decap;
1493 * If decap-nostrip appears before pop vlan, this pop
1494 * applies to the inner packet vlan. Turn it into
1497 decap = find_prev_action_op(fm, FMOP_DECAP_NOSTRIP);
1499 ENICPMD_LOG(DEBUG, "pop-vlan inner: decap-nostrip => decap-strip");
1500 decap->fa_op = FMOP_DECAP_STRIP;
1503 memset(&fm_op, 0, sizeof(fm_op));
1504 fm_op.fa_op = FMOP_POP_VLAN;
1505 ret = enic_fm_append_action_op(fm, &fm_op, error);
1510 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN: {
1511 const struct rte_flow_action_of_push_vlan *vlan;
1513 if (overlap & PASSTHRU)
1515 vlan = actions->conf;
1516 if (vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN)) {
1517 return rte_flow_error_set(error, EINVAL,
1518 RTE_FLOW_ERROR_TYPE_ACTION,
1519 NULL, "unexpected push_vlan ethertype");
1521 overlap |= PUSH_VLAN;
1522 need_ovlan_action = true;
1525 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP: {
1526 const struct rte_flow_action_of_set_vlan_pcp *pcp;
1528 pcp = actions->conf;
1529 if (pcp->vlan_pcp > 7) {
1530 return rte_flow_error_set(error, EINVAL,
1531 RTE_FLOW_ERROR_TYPE_ACTION,
1532 NULL, "invalid vlan_pcp");
1534 need_ovlan_action = true;
1535 ovlan |= ((uint16_t)pcp->vlan_pcp) << 13;
1538 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID: {
1539 const struct rte_flow_action_of_set_vlan_vid *vid;
1541 vid = actions->conf;
1542 need_ovlan_action = true;
1543 ovlan |= rte_be_to_cpu_16(vid->vlan_vid);
1551 if (!(overlap & (FATE | PASSTHRU | COUNT | PORT_ID)))
1553 /* Egress from VF: need implicit WQ match */
1554 if (enic_is_vf_rep(enic) && !ingress) {
1555 fmt->ftm_data.fk_wq_id = 0;
1556 fmt->ftm_mask.fk_wq_id = 0xffff;
1557 fmt->ftm_data.fk_wq_vnic = enic->fm_vnic_handle;
1558 ENICPMD_LOG(DEBUG, "add implicit wq id match for vf %d",
1559 VF_ENIC_TO_VF_REP(enic)->vf_id);
1561 if (need_ovlan_action) {
1562 memset(&fm_op, 0, sizeof(fm_op));
1563 fm_op.fa_op = FMOP_SET_OVLAN;
1564 fm_op.ovlan.vlan = ovlan;
1565 ret = enic_fm_append_action_op(fm, &fm_op, error);
1569 /* Add steer op for PORT_ID without QUEUE */
1570 if ((overlap & PORT_ID) && !steer && ingress) {
1571 memset(&fm_op, 0, sizeof(fm_op));
1572 /* Always to queue 0 for now as generic RSS is not available */
1573 fm_op.fa_op = FMOP_RQ_STEER;
1574 fm_op.rq_steer.rq_index = 0;
1575 fm_op.rq_steer.vnic_handle = vnic_h;
1576 ret = enic_fm_append_action_op(fm, &fm_op, error);
1579 ENICPMD_LOG(DEBUG, "add implicit steer op");
1581 /* Add required END */
1582 memset(&fm_op, 0, sizeof(fm_op));
1583 fm_op.fa_op = FMOP_END;
1584 ret = enic_fm_append_action_op(fm, &fm_op, error);
1587 enic_fm_reorder_action_op(fm);
1591 return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
1592 NULL, "enic: unsupported action");
1595 /** Check if the action is supported */
1597 enic_fm_match_action(const struct rte_flow_action *action,
1598 const enum rte_flow_action_type *supported_actions)
1600 for (; *supported_actions != RTE_FLOW_ACTION_TYPE_END;
1601 supported_actions++) {
1602 if (action->type == *supported_actions)
1608 /* Debug function to dump internal NIC action structure. */
1610 enic_fm_dump_tcam_actions(const struct fm_action *fm_action)
1612 /* Manually keep in sync with FMOP commands */
1613 const char *fmop_str[FMOP_OP_MAX] = {
1615 [FMOP_DROP] = "drop",
1616 [FMOP_RQ_STEER] = "steer",
1617 [FMOP_EXACT_MATCH] = "exmatch",
1618 [FMOP_MARK] = "mark",
1619 [FMOP_EXT_MARK] = "ext_mark",
1621 [FMOP_EG_HAIRPIN] = "eg_hairpin",
1622 [FMOP_IG_HAIRPIN] = "ig_hairpin",
1623 [FMOP_ENCAP_IVLAN] = "encap_ivlan",
1624 [FMOP_ENCAP_NOIVLAN] = "encap_noivlan",
1625 [FMOP_ENCAP] = "encap",
1626 [FMOP_SET_OVLAN] = "set_ovlan",
1627 [FMOP_DECAP_NOSTRIP] = "decap_nostrip",
1628 [FMOP_DECAP_STRIP] = "decap_strip",
1629 [FMOP_POP_VLAN] = "pop_vlan",
1630 [FMOP_SET_EGPORT] = "set_egport",
1631 [FMOP_RQ_STEER_ONLY] = "rq_steer_only",
1632 [FMOP_SET_ENCAP_VLAN] = "set_encap_vlan",
1633 [FMOP_EMIT] = "emit",
1634 [FMOP_MODIFY] = "modify",
1636 const struct fm_action_op *op = &fm_action->fma_action_ops[0];
1637 char buf[128], *bp = buf;
1642 buf_len = sizeof(buf);
1643 for (i = 0; i < FM_ACTION_OP_MAX; i++) {
1644 if (op->fa_op == FMOP_END)
1646 if (op->fa_op >= FMOP_OP_MAX)
1649 op_str = fmop_str[op->fa_op];
1650 n = snprintf(bp, buf_len, "%s,", op_str);
1651 if (n > 0 && n < buf_len) {
1657 /* Remove trailing comma */
1660 ENICPMD_LOG(DEBUG, " Acions: %s", buf);
1664 bits_to_str(uint32_t bits, const char *strings[], int max,
1665 char *buf, int buf_len)
1667 int i, n = 0, len = 0;
1669 for (i = 0; i < max; i++) {
1670 if (bits & (1 << i)) {
1671 n = snprintf(buf, buf_len, "%s,", strings[i]);
1672 if (n > 0 && n < buf_len) {
1679 /* Remove trailing comma */
1687 /* Debug function to dump internal NIC filter structure. */
1689 __enic_fm_dump_tcam_match(const struct fm_header_set *fk_hdrset, char *buf,
1692 /* Manually keep in sync with FKM_BITS */
1693 const char *fm_fkm_str[FKM_BIT_COUNT] = {
1694 [FKM_QTAG_BIT] = "qtag",
1695 [FKM_CMD_BIT] = "cmd",
1696 [FKM_IPV4_BIT] = "ip4",
1697 [FKM_IPV6_BIT] = "ip6",
1698 [FKM_ROCE_BIT] = "roce",
1699 [FKM_UDP_BIT] = "udp",
1700 [FKM_TCP_BIT] = "tcp",
1701 [FKM_TCPORUDP_BIT] = "tcpportudp",
1702 [FKM_IPFRAG_BIT] = "ipfrag",
1703 [FKM_NVGRE_BIT] = "nvgre",
1704 [FKM_VXLAN_BIT] = "vxlan",
1705 [FKM_GENEVE_BIT] = "geneve",
1706 [FKM_NSH_BIT] = "nsh",
1707 [FKM_ROCEV2_BIT] = "rocev2",
1708 [FKM_VLAN_PRES_BIT] = "vlan_pres",
1709 [FKM_IPOK_BIT] = "ipok",
1710 [FKM_L4OK_BIT] = "l4ok",
1711 [FKM_ROCEOK_BIT] = "roceok",
1712 [FKM_FCSOK_BIT] = "fcsok",
1713 [FKM_EG_SPAN_BIT] = "eg_span",
1714 [FKM_IG_SPAN_BIT] = "ig_span",
1715 [FKM_EG_HAIRPINNED_BIT] = "eg_hairpinned",
1717 /* Manually keep in sync with FKH_BITS */
1718 const char *fm_fkh_str[FKH_BIT_COUNT] = {
1719 [FKH_ETHER_BIT] = "eth",
1720 [FKH_QTAG_BIT] = "qtag",
1721 [FKH_L2RAW_BIT] = "l2raw",
1722 [FKH_IPV4_BIT] = "ip4",
1723 [FKH_IPV6_BIT] = "ip6",
1724 [FKH_L3RAW_BIT] = "l3raw",
1725 [FKH_UDP_BIT] = "udp",
1726 [FKH_TCP_BIT] = "tcp",
1727 [FKH_ICMP_BIT] = "icmp",
1728 [FKH_VXLAN_BIT] = "vxlan",
1729 [FKH_L4RAW_BIT] = "l4raw",
1731 uint32_t fkh_bits = fk_hdrset->fk_header_select;
1732 uint32_t fkm_bits = fk_hdrset->fk_metadata;
1735 if (!fkm_bits && !fkh_bits)
1737 n = snprintf(buf, buf_len, "metadata(");
1738 if (n > 0 && n < buf_len) {
1742 n = bits_to_str(fkm_bits, fm_fkm_str, FKM_BIT_COUNT, buf, buf_len);
1743 if (n > 0 && n < buf_len) {
1747 n = snprintf(buf, buf_len, ") valid hdr fields(");
1748 if (n > 0 && n < buf_len) {
1752 n = bits_to_str(fkh_bits, fm_fkh_str, FKH_BIT_COUNT, buf, buf_len);
1753 if (n > 0 && n < buf_len) {
1757 snprintf(buf, buf_len, ")");
1761 enic_fm_dump_tcam_match(const struct fm_tcam_match_entry *match,
1766 memset(buf, 0, sizeof(buf));
1767 __enic_fm_dump_tcam_match(&match->ftm_mask.fk_hdrset[0],
1769 ENICPMD_LOG(DEBUG, " TCAM %s Outer: %s %scounter position %u",
1770 (ingress) ? "IG" : "EG", buf,
1771 (match->ftm_flags & FMEF_COUNTER) ? "" : "no ",
1772 match->ftm_position);
1773 memset(buf, 0, sizeof(buf));
1774 __enic_fm_dump_tcam_match(&match->ftm_mask.fk_hdrset[1],
1777 ENICPMD_LOG(DEBUG, " Inner: %s", buf);
1780 /* Debug function to dump internal NIC flow structures. */
1782 enic_fm_dump_tcam_entry(const struct fm_tcam_match_entry *fm_match,
1783 const struct fm_action *fm_action,
1786 if (!rte_log_can_log(enic_pmd_logtype, RTE_LOG_DEBUG))
1788 enic_fm_dump_tcam_match(fm_match, ingress);
1789 enic_fm_dump_tcam_actions(fm_action);
1793 enic_fm_flow_parse(struct enic_flowman *fm,
1794 const struct rte_flow_attr *attrs,
1795 const struct rte_flow_item pattern[],
1796 const struct rte_flow_action actions[],
1797 struct rte_flow_error *error)
1799 const struct rte_flow_action *action;
1801 static const enum rte_flow_action_type *sa;
1803 ENICPMD_FUNC_TRACE();
1806 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1807 NULL, "no pattern specified");
1812 rte_flow_error_set(error, EINVAL,
1813 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1814 NULL, "no action specified");
1819 if (attrs->group != FM_TCAM_RTE_GROUP && attrs->priority) {
1820 rte_flow_error_set(error, ENOTSUP,
1821 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1823 "priorities are not supported for non-default (0) groups");
1825 } else if (!fm->owner_enic->switchdev_mode && attrs->transfer) {
1826 rte_flow_error_set(error, ENOTSUP,
1827 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1829 "transfer is not supported");
1831 } else if (attrs->ingress && attrs->egress) {
1832 rte_flow_error_set(error, ENOTSUP,
1833 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1835 "bidirectional rules not supported");
1840 rte_flow_error_set(error, EINVAL,
1841 RTE_FLOW_ERROR_TYPE_ATTR,
1842 NULL, "no attribute specified");
1846 /* Verify Actions. */
1847 sa = (attrs->ingress) ? enic_fm_supported_ig_actions :
1848 enic_fm_supported_eg_actions;
1849 for (action = &actions[0]; action->type != RTE_FLOW_ACTION_TYPE_END;
1851 if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
1853 else if (!enic_fm_match_action(action, sa))
1856 if (action->type != RTE_FLOW_ACTION_TYPE_END) {
1857 rte_flow_error_set(error, EPERM, RTE_FLOW_ERROR_TYPE_ACTION,
1858 action, "invalid action");
1861 ret = enic_fm_copy_entry(fm, pattern, error);
1864 ret = enic_fm_copy_action(fm, actions, attrs->ingress, error);
1869 enic_fm_counter_free(struct enic_flowman *fm, struct enic_fm_flow *fm_flow)
1871 if (!fm_flow->counter_valid)
1873 SLIST_INSERT_HEAD(&fm->counters, fm_flow->counter, next);
1874 fm_flow->counter_valid = false;
1878 enic_fm_more_counters(struct enic_flowman *fm)
1880 struct enic_fm_counter *new_stack;
1881 struct enic_fm_counter *ctrs;
1885 ENICPMD_FUNC_TRACE();
1886 new_stack = rte_realloc(fm->counter_stack, (fm->counters_alloced +
1887 FM_COUNTERS_EXPAND) *
1888 sizeof(struct enic_fm_counter), 0);
1889 if (new_stack == NULL) {
1890 ENICPMD_LOG(ERR, "cannot alloc counter memory");
1893 fm->counter_stack = new_stack;
1895 args[0] = FM_COUNTER_BRK;
1896 args[1] = fm->counters_alloced + FM_COUNTERS_EXPAND;
1897 rc = flowman_cmd(fm, args, 2);
1899 ENICPMD_LOG(ERR, "cannot alloc counters rc=%d", rc);
1902 ctrs = (struct enic_fm_counter *)fm->counter_stack +
1903 fm->counters_alloced;
1904 for (i = 0; i < FM_COUNTERS_EXPAND; i++, ctrs++) {
1905 ctrs->handle = fm->counters_alloced + i;
1906 SLIST_INSERT_HEAD(&fm->counters, ctrs, next);
1908 fm->counters_alloced += FM_COUNTERS_EXPAND;
1909 ENICPMD_LOG(DEBUG, "%u counters allocated, total: %u",
1910 FM_COUNTERS_EXPAND, fm->counters_alloced);
1915 enic_fm_counter_zero(struct enic_flowman *fm, struct enic_fm_counter *c)
1920 ENICPMD_FUNC_TRACE();
1921 args[0] = FM_COUNTER_QUERY;
1922 args[1] = c->handle;
1923 args[2] = 1; /* clear */
1924 ret = flowman_cmd(fm, args, 3);
1926 ENICPMD_LOG(ERR, "counter init: rc=%d handle=0x%x",
1934 enic_fm_counter_alloc(struct enic_flowman *fm, struct rte_flow_error *error,
1935 struct enic_fm_counter **ctr)
1937 struct enic_fm_counter *c;
1940 ENICPMD_FUNC_TRACE();
1942 if (SLIST_EMPTY(&fm->counters)) {
1943 ret = enic_fm_more_counters(fm);
1945 return rte_flow_error_set(error, -ret,
1946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1947 NULL, "enic: out of counters");
1949 c = SLIST_FIRST(&fm->counters);
1950 SLIST_REMOVE_HEAD(&fm->counters, next);
1956 enic_fm_action_free(struct enic_flowman *fm, uint64_t handle)
1961 ENICPMD_FUNC_TRACE();
1962 args[0] = FM_ACTION_FREE;
1964 rc = flowman_cmd(fm, args, 2);
1966 ENICPMD_LOG(ERR, "cannot free action: rc=%d handle=0x%" PRIx64,
1972 enic_fm_entry_free(struct enic_flowman *fm, uint64_t handle)
1977 ENICPMD_FUNC_TRACE();
1978 args[0] = FM_MATCH_ENTRY_REMOVE;
1980 rc = flowman_cmd(fm, args, 2);
1982 ENICPMD_LOG(ERR, "cannot free match entry: rc=%d"
1983 " handle=0x%" PRIx64, rc, handle);
1987 static struct enic_fm_jump_flow *
1988 find_jump_flow(struct enic_flowman *fm, uint32_t group)
1990 struct enic_fm_jump_flow *j;
1992 ENICPMD_FUNC_TRACE();
1993 TAILQ_FOREACH(j, &fm->jump_list, list) {
1994 if (j->group == group)
2001 remove_jump_flow(struct enic_flowman *fm, struct rte_flow *flow)
2003 struct enic_fm_jump_flow *j;
2005 ENICPMD_FUNC_TRACE();
2006 TAILQ_FOREACH(j, &fm->jump_list, list) {
2007 if (j->flow == flow) {
2008 TAILQ_REMOVE(&fm->jump_list, j, list);
2016 save_jump_flow(struct enic_flowman *fm,
2017 struct rte_flow *flow,
2019 struct fm_tcam_match_entry *match,
2020 struct fm_action *action)
2022 struct enic_fm_jump_flow *j;
2024 ENICPMD_FUNC_TRACE();
2025 j = calloc(1, sizeof(struct enic_fm_jump_flow));
2031 j->action = *action;
2032 TAILQ_INSERT_HEAD(&fm->jump_list, j, list);
2033 ENICPMD_LOG(DEBUG, "saved jump flow: flow=%p group=%u", flow, group);
2038 __enic_fm_flow_free(struct enic_flowman *fm, struct enic_fm_flow *fm_flow)
2040 if (fm_flow->entry_handle != FM_INVALID_HANDLE) {
2041 enic_fm_entry_free(fm, fm_flow->entry_handle);
2042 fm_flow->entry_handle = FM_INVALID_HANDLE;
2044 if (fm_flow->action_handle != FM_INVALID_HANDLE) {
2045 enic_fm_action_free(fm, fm_flow->action_handle);
2046 fm_flow->action_handle = FM_INVALID_HANDLE;
2048 enic_fm_counter_free(fm, fm_flow);
2050 enic_fet_put(fm, fm_flow->fet);
2051 fm_flow->fet = NULL;
2056 enic_fm_flow_free(struct enic_flowman *fm, struct rte_flow *flow)
2058 struct enic_fm_flow *steer = flow->fm->hairpin_steer_flow;
2060 if (flow->fm->fet && flow->fm->fet->default_key)
2061 remove_jump_flow(fm, flow);
2062 __enic_fm_flow_free(fm, flow->fm);
2064 __enic_fm_flow_free(fm, steer);
2072 enic_fm_add_tcam_entry(struct enic_flowman *fm,
2073 struct fm_tcam_match_entry *match_in,
2074 uint64_t *entry_handle,
2076 struct rte_flow_error *error)
2078 struct fm_tcam_match_entry *ftm;
2082 ENICPMD_FUNC_TRACE();
2083 /* Copy entry to the command buffer */
2084 ftm = &fm->cmd.va->fm_tcam_match_entry;
2085 memcpy(ftm, match_in, sizeof(*ftm));
2086 /* Add TCAM entry */
2087 args[0] = FM_TCAM_ENTRY_INSTALL;
2088 args[1] = ingress ? fm->ig_tcam_hndl : fm->eg_tcam_hndl;
2089 args[2] = fm->cmd.pa;
2090 ret = flowman_cmd(fm, args, 3);
2092 ENICPMD_LOG(ERR, "cannot add %s TCAM entry: rc=%d",
2093 ingress ? "ingress" : "egress", ret);
2094 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2095 NULL, "enic: devcmd(tcam-entry-install)");
2098 ENICPMD_LOG(DEBUG, "installed %s TCAM entry: handle=0x%" PRIx64,
2099 ingress ? "ingress" : "egress", (uint64_t)args[0]);
2100 *entry_handle = args[0];
2105 enic_fm_add_exact_entry(struct enic_flowman *fm,
2106 struct fm_tcam_match_entry *match_in,
2107 uint64_t *entry_handle,
2108 struct enic_fm_fet *fet,
2109 struct rte_flow_error *error)
2111 struct fm_exact_match_entry *fem;
2115 ENICPMD_FUNC_TRACE();
2116 /* The new entry must have the table's key */
2117 if (memcmp(fet->key.fk_hdrset, match_in->ftm_mask.fk_hdrset,
2118 sizeof(struct fm_header_set) * FM_HDRSET_MAX)) {
2119 return rte_flow_error_set(error, EINVAL,
2120 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2121 "enic: key does not match group's key");
2124 /* Copy entry to the command buffer */
2125 fem = &fm->cmd.va->fm_exact_match_entry;
2127 * Translate TCAM entry to exact entry. As is only need to drop
2128 * position and mask. The mask is part of the exact match table.
2129 * Position (aka priority) is not supported in the exact match table.
2131 fem->fem_data = match_in->ftm_data;
2132 fem->fem_flags = match_in->ftm_flags;
2133 fem->fem_action = match_in->ftm_action;
2134 fem->fem_counter = match_in->ftm_counter;
2136 /* Add exact entry */
2137 args[0] = FM_EXACT_ENTRY_INSTALL;
2138 args[1] = fet->handle;
2139 args[2] = fm->cmd.pa;
2140 ret = flowman_cmd(fm, args, 3);
2142 ENICPMD_LOG(ERR, "cannot add %s exact entry: group=%u",
2143 fet->ingress ? "ingress" : "egress", fet->group);
2144 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2145 NULL, "enic: devcmd(exact-entry-install)");
2148 ENICPMD_LOG(DEBUG, "installed %s exact entry: group=%u"
2149 " handle=0x%" PRIx64,
2150 fet->ingress ? "ingress" : "egress", fet->group,
2152 *entry_handle = args[0];
2156 /* Push match-action to the NIC. */
2158 __enic_fm_flow_add_entry(struct enic_flowman *fm,
2159 struct enic_fm_flow *fm_flow,
2160 struct fm_tcam_match_entry *match_in,
2161 struct fm_action *action_in,
2164 struct rte_flow_error *error)
2166 struct enic_fm_counter *ctr;
2167 struct fm_action *fma;
2173 ENICPMD_FUNC_TRACE();
2174 /* Allocate action. */
2175 fma = &fm->cmd.va->fm_action;
2176 memcpy(fma, action_in, sizeof(*fma));
2177 args[0] = FM_ACTION_ALLOC;
2178 args[1] = fm->cmd.pa;
2179 ret = flowman_cmd(fm, args, 2);
2181 ENICPMD_LOG(ERR, "allocating TCAM table action rc=%d", ret);
2182 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2183 NULL, "enic: devcmd(action-alloc)");
2187 fm_flow->action_handle = action_h;
2188 match_in->ftm_action = action_h;
2189 ENICPMD_LOG(DEBUG, "action allocated: handle=0x%" PRIx64, action_h);
2191 /* Allocate counter if requested. */
2192 if (match_in->ftm_flags & FMEF_COUNTER) {
2193 ret = enic_fm_counter_alloc(fm, error, &ctr);
2194 if (ret) /* error has been filled in */
2196 fm_flow->counter_valid = true;
2197 fm_flow->counter = ctr;
2198 match_in->ftm_counter = ctr->handle;
2202 * Get the group's table (either TCAM or exact match table) and
2203 * add entry to it. If we use the exact match table, the handler
2204 * will translate the TCAM entry (match_in) to the appropriate
2205 * exact match entry and use that instead.
2207 entry_h = FM_INVALID_HANDLE;
2208 if (group == FM_TCAM_RTE_GROUP) {
2209 ret = enic_fm_add_tcam_entry(fm, match_in, &entry_h, ingress,
2213 /* Jump action might have a ref to fet */
2214 fm_flow->fet = fm->fet;
2217 struct enic_fm_fet *fet = NULL;
2219 ret = enic_fet_get(fm, group, ingress,
2220 &match_in->ftm_mask, &fet, error);
2224 ret = enic_fm_add_exact_entry(fm, match_in, &entry_h, fet,
2229 /* Clear counter after adding entry, as it requires in-use counter */
2230 if (fm_flow->counter_valid) {
2231 ret = enic_fm_counter_zero(fm, fm_flow->counter);
2235 fm_flow->entry_handle = entry_h;
2239 /* Push match-action to the NIC. */
2240 static struct rte_flow *
2241 enic_fm_flow_add_entry(struct enic_flowman *fm,
2242 struct fm_tcam_match_entry *match_in,
2243 struct fm_action *action_in,
2244 const struct rte_flow_attr *attrs,
2245 struct rte_flow_error *error)
2247 struct enic_fm_flow *fm_flow;
2248 struct rte_flow *flow;
2250 ENICPMD_FUNC_TRACE();
2251 match_in->ftm_position = attrs->priority;
2252 enic_fm_dump_tcam_entry(match_in, action_in, attrs->ingress);
2253 flow = calloc(1, sizeof(*flow));
2254 fm_flow = calloc(1, sizeof(*fm_flow));
2255 if (flow == NULL || fm_flow == NULL) {
2256 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
2257 NULL, "enic: cannot allocate rte_flow");
2263 fm_flow->action_handle = FM_INVALID_HANDLE;
2264 fm_flow->entry_handle = FM_INVALID_HANDLE;
2265 if (__enic_fm_flow_add_entry(fm, fm_flow, match_in, action_in,
2266 attrs->group, attrs->ingress, error)) {
2267 enic_fm_flow_free(fm, flow);
2274 convert_jump_flows(struct enic_flowman *fm, struct enic_fm_fet *fet,
2275 struct rte_flow_error *error)
2277 struct enic_fm_flow *fm_flow;
2278 struct enic_fm_jump_flow *j;
2279 struct fm_action *fma;
2282 ENICPMD_FUNC_TRACE();
2284 * Find the saved flows that should jump to the new table (fet).
2285 * Then delete the old TCAM entry that jumps to the default table,
2286 * and add a new one that jumps to the new table.
2289 j = find_jump_flow(fm, group);
2291 ENICPMD_LOG(DEBUG, "convert jump flow: flow=%p group=%u",
2293 /* Delete old entry */
2294 fm_flow = j->flow->fm;
2295 __enic_fm_flow_free(fm, fm_flow);
2299 fma->fma_action_ops[0].exact.handle = fet->handle;
2300 if (__enic_fm_flow_add_entry(fm, fm_flow, &j->match, fma,
2301 FM_TCAM_RTE_GROUP, fet->ingress, error)) {
2302 /* Cannot roll back changes at the moment */
2303 ENICPMD_LOG(ERR, "cannot convert jump flow: flow=%p",
2308 ENICPMD_LOG(DEBUG, "convert ok: group=%u ref=%u",
2309 fet->group, fet->ref);
2312 TAILQ_REMOVE(&fm->jump_list, j, list);
2314 j = find_jump_flow(fm, group);
2319 add_hairpin_steer(struct enic_flowman *fm, struct rte_flow *flow,
2320 struct rte_flow_error *error)
2322 struct fm_tcam_match_entry *fm_tcam_entry;
2323 struct enic_fm_flow *fm_flow;
2324 struct fm_action *fm_action;
2325 struct fm_action_op fm_op;
2328 ENICPMD_FUNC_TRACE();
2329 fm_flow = calloc(1, sizeof(*fm_flow));
2330 if (fm_flow == NULL) {
2331 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
2332 NULL, "enic: cannot allocate rte_flow");
2335 /* Original egress hairpin flow */
2336 fm_tcam_entry = &fm->tcam_entry;
2337 fm_action = &fm->action;
2338 /* Use the match pattern of the egress flow as is, without counters */
2339 fm_tcam_entry->ftm_flags &= ~FMEF_COUNTER;
2340 /* The only action is steer to vnic */
2341 fm->action_op_count = 0;
2342 memset(fm_action, 0, sizeof(*fm_action));
2343 memset(&fm_op, 0, sizeof(fm_op));
2344 /* Always to queue 0 for now */
2345 fm_op.fa_op = FMOP_RQ_STEER;
2346 fm_op.rq_steer.rq_index = 0;
2347 fm_op.rq_steer.vnic_handle = fm->hairpin_steer_vnic_h;
2348 ret = enic_fm_append_action_op(fm, &fm_op, error);
2350 goto error_with_flow;
2351 ENICPMD_LOG(DEBUG, "add steer op");
2352 /* Add required END */
2353 memset(&fm_op, 0, sizeof(fm_op));
2354 fm_op.fa_op = FMOP_END;
2355 ret = enic_fm_append_action_op(fm, &fm_op, error);
2357 goto error_with_flow;
2358 /* Add the ingress flow */
2359 fm_flow->action_handle = FM_INVALID_HANDLE;
2360 fm_flow->entry_handle = FM_INVALID_HANDLE;
2361 ret = __enic_fm_flow_add_entry(fm, fm_flow, fm_tcam_entry, fm_action,
2362 FM_TCAM_RTE_GROUP, 1 /* ingress */, error);
2364 ENICPMD_LOG(ERR, "cannot add hairpin-steer flow");
2365 goto error_with_flow;
2367 /* The new flow is now the egress flow's paired flow */
2368 flow->fm->hairpin_steer_flow = fm_flow;
2377 enic_fm_open_scratch(struct enic_flowman *fm)
2379 fm->action_op_count = 0;
2381 fm->need_hairpin_steer = 0;
2382 fm->hairpin_steer_vnic_h = 0;
2383 memset(&fm->tcam_entry, 0, sizeof(fm->tcam_entry));
2384 memset(&fm->action, 0, sizeof(fm->action));
2388 enic_fm_close_scratch(struct enic_flowman *fm)
2391 enic_fet_put(fm, fm->fet);
2394 fm->action_op_count = 0;
2398 enic_fm_flow_validate(struct rte_eth_dev *dev,
2399 const struct rte_flow_attr *attrs,
2400 const struct rte_flow_item pattern[],
2401 const struct rte_flow_action actions[],
2402 struct rte_flow_error *error)
2404 struct fm_tcam_match_entry *fm_tcam_entry;
2405 struct fm_action *fm_action;
2406 struct enic_flowman *fm;
2409 ENICPMD_FUNC_TRACE();
2410 fm = begin_fm(pmd_priv(dev));
2413 enic_fm_open_scratch(fm);
2414 ret = enic_fm_flow_parse(fm, attrs, pattern, actions, error);
2416 fm_tcam_entry = &fm->tcam_entry;
2417 fm_action = &fm->action;
2418 enic_fm_dump_tcam_entry(fm_tcam_entry, fm_action,
2421 enic_fm_close_scratch(fm);
2427 enic_fm_flow_query_count(struct rte_eth_dev *dev,
2428 struct rte_flow *flow, void *data,
2429 struct rte_flow_error *error)
2431 struct rte_flow_query_count *query;
2432 struct enic_fm_flow *fm_flow;
2433 struct enic_flowman *fm;
2437 ENICPMD_FUNC_TRACE();
2438 fm = begin_fm(pmd_priv(dev));
2441 if (!fm_flow->counter_valid) {
2442 rc = rte_flow_error_set(error, ENOTSUP,
2443 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2444 "enic: flow does not have counter");
2448 args[0] = FM_COUNTER_QUERY;
2449 args[1] = fm_flow->counter->handle;
2450 args[2] = query->reset;
2451 rc = flowman_cmd(fm, args, 3);
2453 ENICPMD_LOG(ERR, "cannot query counter: rc=%d handle=0x%x",
2454 rc, fm_flow->counter->handle);
2457 query->hits_set = 1;
2458 query->hits = args[0];
2459 query->bytes_set = 1;
2460 query->bytes = args[1];
2468 enic_fm_flow_query(struct rte_eth_dev *dev,
2469 struct rte_flow *flow,
2470 const struct rte_flow_action *actions,
2472 struct rte_flow_error *error)
2476 ENICPMD_FUNC_TRACE();
2477 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2478 switch (actions->type) {
2479 case RTE_FLOW_ACTION_TYPE_VOID:
2481 case RTE_FLOW_ACTION_TYPE_COUNT:
2482 ret = enic_fm_flow_query_count(dev, flow, data, error);
2485 return rte_flow_error_set(error, ENOTSUP,
2486 RTE_FLOW_ERROR_TYPE_ACTION,
2488 "action not supported");
2496 static struct rte_flow *
2497 enic_fm_flow_create(struct rte_eth_dev *dev,
2498 const struct rte_flow_attr *attrs,
2499 const struct rte_flow_item pattern[],
2500 const struct rte_flow_action actions[],
2501 struct rte_flow_error *error)
2503 struct fm_tcam_match_entry *fm_tcam_entry;
2504 struct fm_action *fm_action;
2505 struct enic_flowman *fm;
2506 struct enic_fm_fet *fet;
2507 struct rte_flow *flow;
2511 ENICPMD_FUNC_TRACE();
2512 enic = pmd_priv(dev);
2513 fm = begin_fm(enic);
2515 rte_flow_error_set(error, ENOTSUP,
2516 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2517 "flowman is not initialized");
2520 enic_fm_open_scratch(fm);
2522 ret = enic_fm_flow_parse(fm, attrs, pattern, actions, error);
2524 goto error_with_scratch;
2525 fm_tcam_entry = &fm->tcam_entry;
2526 fm_action = &fm->action;
2527 flow = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2530 /* Add ingress rule that pairs with hairpin rule */
2531 if (fm->need_hairpin_steer) {
2532 ret = add_hairpin_steer(fm, flow, error);
2534 enic_fm_flow_free(fm, flow);
2536 goto error_with_scratch;
2539 LIST_INSERT_HEAD(&enic->flows, flow, next);
2540 fet = flow->fm->fet;
2541 if (fet && fet->default_key) {
2543 * Jump to non-existent group? Save the relevant info
2544 * so we can convert this flow when that group
2547 save_jump_flow(fm, flow, fet->group,
2548 fm_tcam_entry, fm_action);
2549 } else if (fet && fet->ref == 1) {
2551 * A new table is created. Convert the saved flows
2552 * that should jump to this group.
2554 convert_jump_flows(fm, fet, error);
2559 enic_fm_close_scratch(fm);
2565 enic_fm_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
2566 __rte_unused struct rte_flow_error *error)
2568 struct enic *enic = pmd_priv(dev);
2569 struct enic_flowman *fm;
2571 ENICPMD_FUNC_TRACE();
2572 fm = begin_fm(enic);
2575 LIST_REMOVE(flow, next);
2576 enic_fm_flow_free(fm, flow);
2582 enic_fm_flow_flush(struct rte_eth_dev *dev,
2583 __rte_unused struct rte_flow_error *error)
2585 LIST_HEAD(enic_flows, rte_flow) internal;
2586 struct enic_fm_flow *fm_flow;
2587 struct enic_flowman *fm;
2588 struct rte_flow *flow;
2589 struct enic *enic = pmd_priv(dev);
2591 ENICPMD_FUNC_TRACE();
2593 fm = begin_fm(enic);
2596 /* Destroy all non-internal flows */
2597 LIST_INIT(&internal);
2598 while (!LIST_EMPTY(&enic->flows)) {
2599 flow = LIST_FIRST(&enic->flows);
2601 LIST_REMOVE(flow, next);
2602 if (flow->internal) {
2603 LIST_INSERT_HEAD(&internal, flow, next);
2607 * If tables are null, then vNIC is closing, and the firmware
2608 * has already cleaned up flowman state. So do not try to free
2609 * resources, as it only causes errors.
2611 if (fm->ig_tcam_hndl == FM_INVALID_HANDLE) {
2612 fm_flow->entry_handle = FM_INVALID_HANDLE;
2613 fm_flow->action_handle = FM_INVALID_HANDLE;
2614 fm_flow->fet = NULL;
2616 enic_fm_flow_free(fm, flow);
2618 while (!LIST_EMPTY(&internal)) {
2619 flow = LIST_FIRST(&internal);
2620 LIST_REMOVE(flow, next);
2621 LIST_INSERT_HEAD(&enic->flows, flow, next);
2628 enic_fm_tbl_free(struct enic_flowman *fm, uint64_t handle)
2633 args[0] = FM_MATCH_TABLE_FREE;
2635 rc = flowman_cmd(fm, args, 2);
2637 ENICPMD_LOG(ERR, "cannot free table: rc=%d handle=0x%" PRIx64,
2643 enic_fm_tcam_tbl_alloc(struct enic_flowman *fm, uint32_t direction,
2644 uint32_t max_entries, uint64_t *handle)
2646 struct fm_tcam_match_table *tcam_tbl;
2650 ENICPMD_FUNC_TRACE();
2651 tcam_tbl = &fm->cmd.va->fm_tcam_match_table;
2652 tcam_tbl->ftt_direction = direction;
2653 tcam_tbl->ftt_stage = FM_STAGE_LAST;
2654 tcam_tbl->ftt_max_entries = max_entries;
2655 args[0] = FM_TCAM_TABLE_ALLOC;
2656 args[1] = fm->cmd.pa;
2657 rc = flowman_cmd(fm, args, 2);
2659 ENICPMD_LOG(ERR, "cannot alloc %s TCAM table: rc=%d",
2660 (direction == FM_INGRESS) ? "IG" : "EG", rc);
2664 ENICPMD_LOG(DEBUG, "%s TCAM table allocated, handle=0x%" PRIx64,
2665 (direction == FM_INGRESS) ? "IG" : "EG", *handle);
2670 enic_fm_init_counters(struct enic_flowman *fm)
2672 ENICPMD_FUNC_TRACE();
2673 SLIST_INIT(&fm->counters);
2674 return enic_fm_more_counters(fm);
2678 enic_fm_free_all_counters(struct enic_flowman *fm)
2683 args[0] = FM_COUNTER_BRK;
2685 rc = flowman_cmd(fm, args, 2);
2687 ENICPMD_LOG(ERR, "cannot free counters: rc=%d", rc);
2688 rte_free(fm->counter_stack);
2692 enic_fm_alloc_tcam_tables(struct enic_flowman *fm)
2696 ENICPMD_FUNC_TRACE();
2697 rc = enic_fm_tcam_tbl_alloc(fm, FM_INGRESS, FM_MAX_TCAM_TABLE_SIZE,
2701 rc = enic_fm_tcam_tbl_alloc(fm, FM_EGRESS, FM_MAX_TCAM_TABLE_SIZE,
2707 enic_fm_free_tcam_tables(struct enic_flowman *fm)
2709 ENICPMD_FUNC_TRACE();
2710 if (fm->ig_tcam_hndl) {
2711 ENICPMD_LOG(DEBUG, "free IG TCAM table handle=0x%" PRIx64,
2713 enic_fm_tbl_free(fm, fm->ig_tcam_hndl);
2714 fm->ig_tcam_hndl = FM_INVALID_HANDLE;
2716 if (fm->eg_tcam_hndl) {
2717 ENICPMD_LOG(DEBUG, "free EG TCAM table handle=0x%" PRIx64,
2719 enic_fm_tbl_free(fm, fm->eg_tcam_hndl);
2720 fm->eg_tcam_hndl = FM_INVALID_HANDLE;
2725 enic_fm_init(struct enic *enic)
2727 const struct rte_pci_addr *addr;
2728 struct enic_flowman *fm;
2729 uint8_t name[RTE_MEMZONE_NAMESIZE];
2732 if (enic->flow_filter_mode != FILTER_FLOWMAN)
2734 ENICPMD_FUNC_TRACE();
2735 /* Get vnic handle and save for port-id action */
2736 if (enic_is_vf_rep(enic))
2737 addr = &VF_ENIC_TO_VF_REP(enic)->bdf;
2739 addr = &RTE_ETH_DEV_TO_PCI(enic->rte_dev)->addr;
2740 rc = enic_fm_find_vnic(enic, addr, &enic->fm_vnic_handle);
2742 ENICPMD_LOG(ERR, "cannot find vnic handle for %x:%x:%x",
2743 addr->bus, addr->devid, addr->function);
2746 /* Save UIF for egport action */
2747 enic->fm_vnic_uif = vnic_dev_uif(enic->vdev);
2748 ENICPMD_LOG(DEBUG, "uif %u", enic->fm_vnic_uif);
2749 /* Nothing else to do for representor. It will share the PF flowman */
2750 if (enic_is_vf_rep(enic))
2752 fm = calloc(1, sizeof(*fm));
2754 ENICPMD_LOG(ERR, "cannot alloc flowman struct");
2757 fm->owner_enic = enic;
2758 rte_spinlock_init(&fm->lock);
2759 TAILQ_INIT(&fm->fet_list);
2760 TAILQ_INIT(&fm->jump_list);
2761 /* Allocate host memory for flowman commands */
2762 snprintf((char *)name, sizeof(name), "fm-cmd-%s", enic->bdf_name);
2763 fm->cmd.va = enic_alloc_consistent(enic,
2764 sizeof(union enic_flowman_cmd_mem), &fm->cmd.pa, name);
2766 ENICPMD_LOG(ERR, "cannot allocate flowman command memory");
2770 /* Allocate TCAM tables upfront as they are the main tables */
2771 rc = enic_fm_alloc_tcam_tables(fm);
2773 ENICPMD_LOG(ERR, "cannot alloc TCAM tables");
2776 /* Then a number of counters */
2777 rc = enic_fm_init_counters(fm);
2779 ENICPMD_LOG(ERR, "cannot alloc counters");
2783 * One default exact match table for each direction. We hold onto
2786 rc = enic_fet_alloc(fm, 1, NULL, 128, &fm->default_ig_fet);
2788 ENICPMD_LOG(ERR, "cannot alloc default IG exact match table");
2789 goto error_counters;
2791 fm->default_ig_fet->ref = 1;
2792 rc = enic_fet_alloc(fm, 0, NULL, 128, &fm->default_eg_fet);
2794 ENICPMD_LOG(ERR, "cannot alloc default EG exact match table");
2797 fm->default_eg_fet->ref = 1;
2798 fm->vf_rep_tag = FM_VF_REP_TAG;
2803 enic_fet_free(fm, fm->default_ig_fet);
2805 enic_fm_free_all_counters(fm);
2807 enic_fm_free_tcam_tables(fm);
2809 enic_free_consistent(enic, sizeof(union enic_flowman_cmd_mem),
2810 fm->cmd.va, fm->cmd.pa);
2817 enic_fm_destroy(struct enic *enic)
2819 struct enic_flowman *fm;
2820 struct enic_fm_fet *fet;
2822 ENICPMD_FUNC_TRACE();
2823 if (enic_is_vf_rep(enic)) {
2824 delete_rep_flows(enic);
2827 if (enic->fm == NULL)
2830 enic_fet_free(fm, fm->default_eg_fet);
2831 enic_fet_free(fm, fm->default_ig_fet);
2832 /* Free all exact match tables still open */
2833 while (!TAILQ_EMPTY(&fm->fet_list)) {
2834 fet = TAILQ_FIRST(&fm->fet_list);
2835 enic_fet_free(fm, fet);
2837 enic_fm_free_tcam_tables(fm);
2838 enic_fm_free_all_counters(fm);
2839 enic_free_consistent(enic, sizeof(union enic_flowman_cmd_mem),
2840 fm->cmd.va, fm->cmd.pa);
2847 enic_fm_allocate_switch_domain(struct enic *pf)
2849 const struct rte_pci_addr *cur_a, *prev_a;
2850 struct rte_eth_dev *dev;
2851 struct enic *cur, *prev;
2857 ENICPMD_FUNC_TRACE();
2858 if (enic_is_vf_rep(pf))
2861 cur_a = &RTE_ETH_DEV_TO_PCI(cur->rte_dev)->addr;
2862 /* Go through ports and find another PF that is on the same adapter */
2863 RTE_ETH_FOREACH_DEV(pid) {
2864 dev = &rte_eth_devices[pid];
2865 if (!dev_is_enic(dev))
2867 if (dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
2869 if (dev == cur->rte_dev)
2871 /* dev is another PF. Is it on the same adapter? */
2872 prev = pmd_priv(dev);
2873 prev_a = &RTE_ETH_DEV_TO_PCI(dev)->addr;
2874 if (!enic_fm_find_vnic(cur, prev_a, &vnic_h)) {
2875 ENICPMD_LOG(DEBUG, "Port %u (PF BDF %x:%x:%x) and port %u (PF BDF %x:%x:%x domain %u) are on the same VIC",
2876 cur->rte_dev->data->port_id,
2877 cur_a->bus, cur_a->devid, cur_a->function,
2879 prev_a->bus, prev_a->devid, prev_a->function,
2880 prev->switch_domain_id);
2881 cur->switch_domain_id = prev->switch_domain_id;
2885 ret = rte_eth_switch_domain_alloc(&domain_id);
2887 ENICPMD_LOG(WARNING, "failed to allocate switch domain for device %d",
2890 cur->switch_domain_id = domain_id;
2891 ENICPMD_LOG(DEBUG, "Port %u (PF BDF %x:%x:%x) is the 1st PF on the VIC. Allocated switch domain id %u",
2892 cur->rte_dev->data->port_id,
2893 cur_a->bus, cur_a->devid, cur_a->function,
2898 const struct rte_flow_ops enic_fm_flow_ops = {
2899 .validate = enic_fm_flow_validate,
2900 .create = enic_fm_flow_create,
2901 .destroy = enic_fm_flow_destroy,
2902 .flush = enic_fm_flow_flush,
2903 .query = enic_fm_flow_query,
2906 /* Add a high priority flow that loops representor packets to VF */
2908 enic_fm_add_rep2vf_flow(struct enic_vf_representor *vf)
2910 struct fm_tcam_match_entry *fm_tcam_entry;
2911 struct rte_flow *flow0, *flow1;
2912 struct fm_action *fm_action;
2913 struct rte_flow_error error;
2914 struct rte_flow_attr attrs;
2915 struct fm_action_op fm_op;
2916 struct enic_flowman *fm;
2922 tag = fm->vf_rep_tag;
2923 enic_fm_open_scratch(fm);
2924 fm_tcam_entry = &fm->tcam_entry;
2925 fm_action = &fm->action;
2926 /* Egress rule: match WQ ID and tag+hairpin */
2927 fm_tcam_entry->ftm_data.fk_wq_id = vf->pf_wq_idx;
2928 fm_tcam_entry->ftm_mask.fk_wq_id = 0xffff;
2929 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2930 memset(&fm_op, 0, sizeof(fm_op));
2931 fm_op.fa_op = FMOP_TAG;
2932 fm_op.tag.tag = tag;
2933 enic_fm_append_action_op(fm, &fm_op, &error);
2934 memset(&fm_op, 0, sizeof(fm_op));
2935 fm_op.fa_op = FMOP_EG_HAIRPIN;
2936 enic_fm_append_action_op(fm, &fm_op, &error);
2937 memset(&fm_op, 0, sizeof(fm_op));
2938 fm_op.fa_op = FMOP_END;
2939 enic_fm_append_action_op(fm, &fm_op, &error);
2943 attrs.priority = FM_HIGHEST_PRIORITY;
2944 flow0 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2946 enic_fm_close_scratch(fm);
2947 if (flow0 == NULL) {
2948 ENICPMD_LOG(ERR, "Cannot create flow 0 for representor->VF");
2951 LIST_INSERT_HEAD(&pf->flows, flow0, next);
2952 /* Make this flow internal, so the user app cannot delete it */
2953 flow0->internal = 1;
2954 ENICPMD_LOG(DEBUG, "representor->VF %d flow created: wq %d -> tag %d hairpin",
2955 vf->vf_id, vf->pf_wq_idx, tag);
2957 /* Ingress: steer hairpinned to VF RQ 0 */
2958 enic_fm_open_scratch(fm);
2959 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2960 fm_tcam_entry->ftm_data.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2961 fm_tcam_entry->ftm_mask.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2962 fm_tcam_entry->ftm_data.fk_packet_tag = tag;
2963 fm_tcam_entry->ftm_mask.fk_packet_tag = 0xff;
2964 memset(&fm_op, 0, sizeof(fm_op));
2965 fm_op.fa_op = FMOP_RQ_STEER;
2966 fm_op.rq_steer.rq_index = 0;
2967 fm_op.rq_steer.vnic_handle = vf->enic.fm_vnic_handle;
2968 enic_fm_append_action_op(fm, &fm_op, &error);
2969 memset(&fm_op, 0, sizeof(fm_op));
2970 fm_op.fa_op = FMOP_END;
2971 enic_fm_append_action_op(fm, &fm_op, &error);
2975 attrs.priority = FM_HIGHEST_PRIORITY;
2976 flow1 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2978 enic_fm_close_scratch(fm);
2979 if (flow1 == NULL) {
2980 ENICPMD_LOG(ERR, "Cannot create flow 1 for representor->VF");
2981 enic_fm_flow_destroy(pf->rte_dev, flow0, &error);
2984 LIST_INSERT_HEAD(&pf->flows, flow1, next);
2985 flow1->internal = 1;
2986 ENICPMD_LOG(DEBUG, "representor->VF %d flow created: tag %d hairpinned -> VF RQ %d",
2987 vf->vf_id, tag, fm_op.rq_steer.rq_index);
2988 vf->rep2vf_flow[0] = flow0;
2989 vf->rep2vf_flow[1] = flow1;
2990 /* Done with this tag, use a different one next time */
2996 * Add a low priority flow that matches all packets from VF and loops them
2997 * back to the representor.
3000 enic_fm_add_vf2rep_flow(struct enic_vf_representor *vf)
3002 struct fm_tcam_match_entry *fm_tcam_entry;
3003 struct rte_flow *flow0, *flow1;
3004 struct fm_action *fm_action;
3005 struct rte_flow_error error;
3006 struct rte_flow_attr attrs;
3007 struct fm_action_op fm_op;
3008 struct enic_flowman *fm;
3014 tag = fm->vf_rep_tag;
3015 enic_fm_open_scratch(fm);
3016 fm_tcam_entry = &fm->tcam_entry;
3017 fm_action = &fm->action;
3018 /* Egress rule: match-any and tag+hairpin */
3019 fm_tcam_entry->ftm_data.fk_wq_id = 0;
3020 fm_tcam_entry->ftm_mask.fk_wq_id = 0xffff;
3021 fm_tcam_entry->ftm_data.fk_wq_vnic = vf->enic.fm_vnic_handle;
3022 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
3023 memset(&fm_op, 0, sizeof(fm_op));
3024 fm_op.fa_op = FMOP_TAG;
3025 fm_op.tag.tag = tag;
3026 enic_fm_append_action_op(fm, &fm_op, &error);
3027 memset(&fm_op, 0, sizeof(fm_op));
3028 fm_op.fa_op = FMOP_EG_HAIRPIN;
3029 enic_fm_append_action_op(fm, &fm_op, &error);
3030 memset(&fm_op, 0, sizeof(fm_op));
3031 fm_op.fa_op = FMOP_END;
3032 enic_fm_append_action_op(fm, &fm_op, &error);
3036 attrs.priority = FM_LOWEST_PRIORITY;
3037 flow0 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
3039 enic_fm_close_scratch(fm);
3040 if (flow0 == NULL) {
3041 ENICPMD_LOG(ERR, "Cannot create flow 0 for VF->representor");
3044 LIST_INSERT_HEAD(&pf->flows, flow0, next);
3045 /* Make this flow internal, so the user app cannot delete it */
3046 flow0->internal = 1;
3047 ENICPMD_LOG(DEBUG, "VF %d->representor flow created: wq %d (low prio) -> tag %d hairpin",
3048 vf->vf_id, fm_tcam_entry->ftm_data.fk_wq_id, tag);
3050 /* Ingress: steer hairpinned to VF rep RQ */
3051 enic_fm_open_scratch(fm);
3052 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
3053 fm_tcam_entry->ftm_data.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
3054 fm_tcam_entry->ftm_mask.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
3055 fm_tcam_entry->ftm_data.fk_packet_tag = tag;
3056 fm_tcam_entry->ftm_mask.fk_packet_tag = 0xff;
3057 memset(&fm_op, 0, sizeof(fm_op));
3058 fm_op.fa_op = FMOP_RQ_STEER;
3059 fm_op.rq_steer.rq_index = vf->pf_rq_sop_idx;
3060 fm_op.rq_steer.vnic_handle = pf->fm_vnic_handle;
3061 enic_fm_append_action_op(fm, &fm_op, &error);
3062 memset(&fm_op, 0, sizeof(fm_op));
3063 fm_op.fa_op = FMOP_END;
3064 enic_fm_append_action_op(fm, &fm_op, &error);
3068 attrs.priority = FM_HIGHEST_PRIORITY;
3069 flow1 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
3071 enic_fm_close_scratch(fm);
3072 if (flow1 == NULL) {
3073 ENICPMD_LOG(ERR, "Cannot create flow 1 for VF->representor");
3074 enic_fm_flow_destroy(pf->rte_dev, flow0, &error);
3077 LIST_INSERT_HEAD(&pf->flows, flow1, next);
3078 flow1->internal = 1;
3079 ENICPMD_LOG(DEBUG, "VF %d->representor flow created: tag %d hairpinned -> PF RQ %d",
3080 vf->vf_id, tag, vf->pf_rq_sop_idx);
3081 vf->vf2rep_flow[0] = flow0;
3082 vf->vf2rep_flow[1] = flow1;
3083 /* Done with this tag, use a different one next time */
3088 /* Destroy representor flows created by enic_fm_add_{rep2vf,vf2rep}_flow */
3090 delete_rep_flows(struct enic *enic)
3092 struct enic_vf_representor *vf;
3093 struct rte_flow_error error;
3094 struct rte_eth_dev *dev;
3097 RTE_ASSERT(enic_is_vf_rep(enic));
3098 vf = VF_ENIC_TO_VF_REP(enic);
3099 dev = vf->pf->rte_dev;
3100 for (i = 0; i < ARRAY_SIZE(vf->vf2rep_flow); i++) {
3101 if (vf->vf2rep_flow[i])
3102 enic_fm_flow_destroy(dev, vf->vf2rep_flow[i], &error);
3104 for (i = 0; i < ARRAY_SIZE(vf->rep2vf_flow); i++) {
3105 if (vf->rep2vf_flow[i])
3106 enic_fm_flow_destroy(dev, vf->rep2vf_flow[i], &error);
3110 static struct enic_flowman *
3111 begin_fm(struct enic *enic)
3113 struct enic_vf_representor *vf;
3114 struct enic_flowman *fm;
3116 /* Representor uses PF flowman */
3117 if (enic_is_vf_rep(enic)) {
3118 vf = VF_ENIC_TO_VF_REP(enic);
3123 /* Save the API caller and lock if representors exist */
3125 if (fm->owner_enic->switchdev_mode)
3126 rte_spinlock_lock(&fm->lock);
3127 fm->user_enic = enic;
3133 end_fm(struct enic_flowman *fm)
3135 fm->user_enic = NULL;
3136 if (fm->owner_enic->switchdev_mode)
3137 rte_spinlock_unlock(&fm->lock);