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;
395 /* Outer TPID cannot be matched */
396 if (eth_mask->ether_type)
400 * When packet matching, the VIC always compares vlan-stripped
401 * L2, regardless of vlan stripping settings. So, the inner type
402 * from vlan becomes the ether type of the eth header.
404 eth_mask->ether_type = mask->inner_type;
405 eth_val->ether_type = spec->inner_type;
406 fm_data->fk_header_select |= FKH_ETHER | FKH_QTAG;
407 fm_mask->fk_header_select |= FKH_ETHER | FKH_QTAG;
408 fm_data->fk_vlan = rte_be_to_cpu_16(spec->tci);
409 fm_mask->fk_vlan = rte_be_to_cpu_16(mask->tci);
414 enic_fm_copy_item_ipv4(struct copy_item_args *arg)
416 const struct rte_flow_item *item = arg->item;
417 const struct rte_flow_item_ipv4 *spec = item->spec;
418 const struct rte_flow_item_ipv4 *mask = item->mask;
419 const uint8_t lvl = arg->header_level;
420 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
421 struct fm_header_set *fm_data, *fm_mask;
423 ENICPMD_FUNC_TRACE();
424 fm_data = &entry->ftm_data.fk_hdrset[lvl];
425 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
426 fm_data->fk_metadata |= FKM_IPV4;
427 fm_mask->fk_metadata |= FKM_IPV4;
432 mask = &rte_flow_item_ipv4_mask;
434 fm_data->fk_header_select |= FKH_IPV4;
435 fm_mask->fk_header_select |= FKH_IPV4;
436 memcpy(&fm_data->l3.ip4, spec, sizeof(*spec));
437 memcpy(&fm_mask->l3.ip4, mask, sizeof(*mask));
442 enic_fm_copy_item_ipv6(struct copy_item_args *arg)
444 const struct rte_flow_item *item = arg->item;
445 const struct rte_flow_item_ipv6 *spec = item->spec;
446 const struct rte_flow_item_ipv6 *mask = item->mask;
447 const uint8_t lvl = arg->header_level;
448 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
449 struct fm_header_set *fm_data, *fm_mask;
451 ENICPMD_FUNC_TRACE();
452 fm_data = &entry->ftm_data.fk_hdrset[lvl];
453 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
454 fm_data->fk_metadata |= FKM_IPV6;
455 fm_mask->fk_metadata |= FKM_IPV6;
460 mask = &rte_flow_item_ipv6_mask;
462 fm_data->fk_header_select |= FKH_IPV6;
463 fm_mask->fk_header_select |= FKH_IPV6;
464 memcpy(&fm_data->l3.ip6, spec, sizeof(*spec));
465 memcpy(&fm_mask->l3.ip6, mask, sizeof(*mask));
470 enic_fm_copy_item_udp(struct copy_item_args *arg)
472 const struct rte_flow_item *item = arg->item;
473 const struct rte_flow_item_udp *spec = item->spec;
474 const struct rte_flow_item_udp *mask = item->mask;
475 const uint8_t lvl = arg->header_level;
476 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
477 struct fm_header_set *fm_data, *fm_mask;
479 ENICPMD_FUNC_TRACE();
480 fm_data = &entry->ftm_data.fk_hdrset[lvl];
481 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
482 fm_data->fk_metadata |= FKM_UDP;
483 fm_mask->fk_metadata |= FKM_UDP;
488 mask = &rte_flow_item_udp_mask;
490 fm_data->fk_header_select |= FKH_UDP;
491 fm_mask->fk_header_select |= FKH_UDP;
492 memcpy(&fm_data->l4.udp, spec, sizeof(*spec));
493 memcpy(&fm_mask->l4.udp, mask, sizeof(*mask));
498 enic_fm_copy_item_tcp(struct copy_item_args *arg)
500 const struct rte_flow_item *item = arg->item;
501 const struct rte_flow_item_tcp *spec = item->spec;
502 const struct rte_flow_item_tcp *mask = item->mask;
503 const uint8_t lvl = arg->header_level;
504 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
505 struct fm_header_set *fm_data, *fm_mask;
507 ENICPMD_FUNC_TRACE();
508 fm_data = &entry->ftm_data.fk_hdrset[lvl];
509 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
510 fm_data->fk_metadata |= FKM_TCP;
511 fm_mask->fk_metadata |= FKM_TCP;
516 mask = &rte_flow_item_tcp_mask;
518 fm_data->fk_header_select |= FKH_TCP;
519 fm_mask->fk_header_select |= FKH_TCP;
520 memcpy(&fm_data->l4.tcp, spec, sizeof(*spec));
521 memcpy(&fm_mask->l4.tcp, mask, sizeof(*mask));
526 enic_fm_copy_item_sctp(struct copy_item_args *arg)
528 const struct rte_flow_item *item = arg->item;
529 const struct rte_flow_item_sctp *spec = item->spec;
530 const struct rte_flow_item_sctp *mask = item->mask;
531 const uint8_t lvl = arg->header_level;
532 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
533 struct fm_header_set *fm_data, *fm_mask;
534 uint8_t *ip_proto_mask = NULL;
535 uint8_t *ip_proto = NULL;
538 ENICPMD_FUNC_TRACE();
539 fm_data = &entry->ftm_data.fk_hdrset[lvl];
540 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
542 * The NIC filter API has no flags for "match sctp", so explicitly
543 * set the protocol number in the IP pattern.
545 if (fm_data->fk_metadata & FKM_IPV4) {
546 struct rte_ipv4_hdr *ip;
547 ip = (struct rte_ipv4_hdr *)&fm_mask->l3.ip4;
548 ip_proto_mask = &ip->next_proto_id;
549 ip = (struct rte_ipv4_hdr *)&fm_data->l3.ip4;
550 ip_proto = &ip->next_proto_id;
552 } else if (fm_data->fk_metadata & FKM_IPV6) {
553 struct rte_ipv6_hdr *ip;
554 ip = (struct rte_ipv6_hdr *)&fm_mask->l3.ip6;
555 ip_proto_mask = &ip->proto;
556 ip = (struct rte_ipv6_hdr *)&fm_data->l3.ip6;
557 ip_proto = &ip->proto;
560 /* Need IPv4/IPv6 pattern first */
563 *ip_proto = IPPROTO_SCTP;
564 *ip_proto_mask = 0xff;
565 fm_data->fk_header_select |= l3_fkh;
566 fm_mask->fk_header_select |= l3_fkh;
571 mask = &rte_flow_item_sctp_mask;
573 fm_data->fk_header_select |= FKH_L4RAW;
574 fm_mask->fk_header_select |= FKH_L4RAW;
575 memcpy(fm_data->l4.rawdata, spec, sizeof(*spec));
576 memcpy(fm_mask->l4.rawdata, mask, sizeof(*mask));
581 enic_fm_copy_item_vxlan(struct copy_item_args *arg)
583 const struct rte_flow_item *item = arg->item;
584 const struct rte_flow_item_vxlan *spec = item->spec;
585 const struct rte_flow_item_vxlan *mask = item->mask;
586 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
587 struct fm_header_set *fm_data, *fm_mask;
589 ENICPMD_FUNC_TRACE();
590 /* Only 2 header levels (outer and inner) allowed */
591 if (arg->header_level > 0)
594 fm_data = &entry->ftm_data.fk_hdrset[0];
595 fm_mask = &entry->ftm_mask.fk_hdrset[0];
596 fm_data->fk_metadata |= FKM_VXLAN;
597 fm_mask->fk_metadata |= FKM_VXLAN;
598 /* items from here on out are inner header items */
599 arg->header_level = 1;
601 /* Match all if no spec */
605 mask = &rte_flow_item_vxlan_mask;
607 fm_data->fk_header_select |= FKH_VXLAN;
608 fm_mask->fk_header_select |= FKH_VXLAN;
609 memcpy(&fm_data->vxlan, spec, sizeof(*spec));
610 memcpy(&fm_mask->vxlan, mask, sizeof(*mask));
615 * Currently, raw pattern match is very limited. It is intended for matching
616 * UDP tunnel header (e.g. vxlan or geneve).
619 enic_fm_copy_item_raw(struct copy_item_args *arg)
621 const struct rte_flow_item *item = arg->item;
622 const struct rte_flow_item_raw *spec = item->spec;
623 const struct rte_flow_item_raw *mask = item->mask;
624 const uint8_t lvl = arg->header_level;
625 struct fm_tcam_match_entry *entry = arg->fm_tcam_entry;
626 struct fm_header_set *fm_data, *fm_mask;
628 ENICPMD_FUNC_TRACE();
629 /* Cannot be used for inner packet */
632 /* Need both spec and mask */
635 /* Only supports relative with offset 0 */
636 if (!spec->relative || spec->offset != 0 || spec->search ||
639 /* Need non-null pattern that fits within the NIC's filter pattern */
640 if (spec->length == 0 ||
641 spec->length + sizeof(struct rte_udp_hdr) > FM_LAYER_SIZE ||
642 !spec->pattern || !mask->pattern)
645 * Mask fields, including length, are often set to zero. Assume that
646 * means "same as spec" to avoid breaking existing apps. If length
647 * is not zero, then it should be >= spec length.
649 * No more pattern follows this, so append to the L4 layer instead of
650 * L5 to work with both recent and older VICs.
652 if (mask->length != 0 && mask->length < spec->length)
655 fm_data = &entry->ftm_data.fk_hdrset[lvl];
656 fm_mask = &entry->ftm_mask.fk_hdrset[lvl];
657 fm_data->fk_header_select |= FKH_L4RAW;
658 fm_mask->fk_header_select |= FKH_L4RAW;
659 fm_data->fk_header_select &= ~FKH_UDP;
660 fm_mask->fk_header_select &= ~FKH_UDP;
661 memcpy(fm_data->l4.rawdata + sizeof(struct rte_udp_hdr),
662 spec->pattern, spec->length);
663 memcpy(fm_mask->l4.rawdata + sizeof(struct rte_udp_hdr),
664 mask->pattern, spec->length);
669 flowman_cmd(struct enic_flowman *fm, uint64_t *args, int nargs)
671 return vnic_dev_flowman_cmd(fm->owner_enic->vdev, args, nargs);
675 enic_fet_alloc(struct enic_flowman *fm, uint8_t ingress,
676 struct fm_key_template *key, int entries,
677 struct enic_fm_fet **fet_out)
679 struct fm_exact_match_table *cmd;
680 struct fm_header_set *hdr;
681 struct enic_fm_fet *fet;
685 ENICPMD_FUNC_TRACE();
686 fet = calloc(1, sizeof(struct enic_fm_fet));
689 cmd = &fm->cmd.va->fm_exact_match_table;
690 memset(cmd, 0, sizeof(*cmd));
691 cmd->fet_direction = ingress ? FM_INGRESS : FM_EGRESS;
692 cmd->fet_stage = FM_STAGE_LAST;
693 cmd->fet_max_entries = entries ? entries : FM_MAX_EXACT_TABLE_SIZE;
695 hdr = &cmd->fet_key.fk_hdrset[0];
696 memset(hdr, 0, sizeof(*hdr));
697 hdr->fk_header_select = FKH_IPV4 | FKH_UDP;
698 hdr->l3.ip4.fk_saddr = 0xFFFFFFFF;
699 hdr->l3.ip4.fk_daddr = 0xFFFFFFFF;
700 hdr->l4.udp.fk_source = 0xFFFF;
701 hdr->l4.udp.fk_dest = 0xFFFF;
702 fet->default_key = 1;
704 memcpy(&cmd->fet_key, key, sizeof(*key));
705 memcpy(&fet->key, key, sizeof(*key));
706 fet->default_key = 0;
708 cmd->fet_key.fk_packet_tag = 1;
710 args[0] = FM_EXACT_TABLE_ALLOC;
711 args[1] = fm->cmd.pa;
712 ret = flowman_cmd(fm, args, 2);
714 ENICPMD_LOG(ERR, "cannot alloc exact match table: rc=%d", ret);
718 fet->handle = args[0];
719 fet->ingress = ingress;
720 ENICPMD_LOG(DEBUG, "allocated exact match table: handle=0x%" PRIx64,
727 enic_fet_free(struct enic_flowman *fm, struct enic_fm_fet *fet)
729 ENICPMD_FUNC_TRACE();
730 enic_fm_tbl_free(fm, fet->handle);
731 if (!fet->default_key)
732 TAILQ_REMOVE(&fm->fet_list, fet, list);
737 * Get the exact match table for the given combination of
738 * <group, ingress, key>. Allocate one on the fly as necessary.
741 enic_fet_get(struct enic_flowman *fm,
744 struct fm_key_template *key,
745 struct enic_fm_fet **fet_out,
746 struct rte_flow_error *error)
748 struct enic_fm_fet *fet;
750 ENICPMD_FUNC_TRACE();
751 /* See if we already have this table open */
752 TAILQ_FOREACH(fet, &fm->fet_list, list) {
753 if (fet->group == group && fet->ingress == ingress)
757 /* Jumping to a non-existing group? Use the default table */
759 fet = ingress ? fm->default_ig_fet : fm->default_eg_fet;
760 } else if (enic_fet_alloc(fm, ingress, key, 0, &fet)) {
761 return rte_flow_error_set(error, EINVAL,
762 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
763 NULL, "enic: cannot get exact match table");
766 /* Default table is never on the open table list */
767 if (!fet->default_key)
768 TAILQ_INSERT_HEAD(&fm->fet_list, fet, list);
772 ENICPMD_LOG(DEBUG, "fet_get: %s %s group=%u ref=%u",
773 fet->default_key ? "default" : "",
774 fet->ingress ? "ingress" : "egress",
775 fet->group, fet->ref);
780 enic_fet_put(struct enic_flowman *fm, struct enic_fm_fet *fet)
782 ENICPMD_FUNC_TRACE();
783 RTE_ASSERT(fet->ref > 0);
785 ENICPMD_LOG(DEBUG, "fet_put: %s %s group=%u ref=%u",
786 fet->default_key ? "default" : "",
787 fet->ingress ? "ingress" : "egress",
788 fet->group, fet->ref);
790 enic_fet_free(fm, fet);
793 /* Return 1 if current item is valid on top of the previous one. */
795 fm_item_stacking_valid(enum rte_flow_item_type prev_item,
796 const struct enic_fm_items *item_info,
797 uint8_t is_first_item)
799 enum rte_flow_item_type const *allowed_items = item_info->prev_items;
801 ENICPMD_FUNC_TRACE();
802 for (; *allowed_items != RTE_FLOW_ITEM_TYPE_END; allowed_items++) {
803 if (prev_item == *allowed_items)
807 /* This is the first item in the stack. Check if that's cool */
808 if (is_first_item && item_info->valid_start_item)
814 * Build the flow manager match entry structure from the provided pattern.
815 * The pattern is validated as the items are copied.
818 enic_fm_copy_entry(struct enic_flowman *fm,
819 const struct rte_flow_item pattern[],
820 struct rte_flow_error *error)
822 const struct enic_fm_items *item_info;
823 enum rte_flow_item_type prev_item;
824 const struct rte_flow_item *item;
825 struct copy_item_args args;
826 uint8_t prev_header_level;
827 uint8_t is_first_item;
830 ENICPMD_FUNC_TRACE();
833 prev_item = RTE_FLOW_ITEM_TYPE_END;
835 args.fm_tcam_entry = &fm->tcam_entry;
836 args.header_level = 0;
837 prev_header_level = 0;
838 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
840 * Get info about how to validate and copy the item. If NULL
841 * is returned the nic does not support the item.
843 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
846 item_info = &enic_fm_items[item->type];
848 if (item->type > FM_MAX_ITEM_TYPE ||
849 item_info->copy_item == NULL) {
850 return rte_flow_error_set(error, ENOTSUP,
851 RTE_FLOW_ERROR_TYPE_ITEM,
852 NULL, "enic: unsupported item");
855 /* check to see if item stacking is valid */
856 if (!fm_item_stacking_valid(prev_item, item_info,
861 ret = item_info->copy_item(&args);
863 goto item_not_supported;
864 /* Going from outer to inner? Treat it as a new packet start */
865 if (prev_header_level != args.header_level) {
866 prev_item = RTE_FLOW_ITEM_TYPE_END;
869 prev_item = item->type;
872 prev_header_level = args.header_level;
877 return rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_ITEM,
878 NULL, "enic: unsupported item type");
881 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
882 item, "enic: unsupported item stack");
886 flow_item_skip_void(const struct rte_flow_item **item)
889 if ((*item)->type != RTE_FLOW_ITEM_TYPE_VOID)
894 append_template(void **template, uint8_t *off, const void *data, int len)
896 memcpy(*template, data, len);
897 *template = (char *)*template + len;
902 enic_fm_append_action_op(struct enic_flowman *fm,
903 struct fm_action_op *fm_op,
904 struct rte_flow_error *error)
908 count = fm->action_op_count;
909 ENICPMD_LOG(DEBUG, "append action op: idx=%d op=%u",
910 count, fm_op->fa_op);
911 if (count == FM_ACTION_OP_MAX) {
912 return rte_flow_error_set(error, EINVAL,
913 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
914 "too many action operations");
916 fm->action.fma_action_ops[count] = *fm_op;
917 fm->action_op_count = count + 1;
921 /* NIC requires that 1st steer appear before decap.
922 * Correct example: steer, decap, steer, steer, ...
925 enic_fm_reorder_action_op(struct enic_flowman *fm)
927 struct fm_action_op *op, *steer, *decap;
928 struct fm_action_op tmp_op;
930 ENICPMD_FUNC_TRACE();
931 /* Find 1st steer and decap */
932 op = fm->action.fma_action_ops;
935 while (op->fa_op != FMOP_END) {
936 if (!decap && op->fa_op == FMOP_DECAP_NOSTRIP)
938 else if (!steer && op->fa_op == FMOP_RQ_STEER)
942 /* If decap is before steer, swap */
943 if (steer && decap && decap < steer) {
944 op = fm->action.fma_action_ops;
945 ENICPMD_LOG(DEBUG, "swap decap %ld <-> steer %ld",
946 (long)(decap - op), (long)(steer - op));
953 /* VXLAN decap is done via flowman compound action */
955 enic_fm_copy_vxlan_decap(struct enic_flowman *fm,
956 struct fm_tcam_match_entry *fmt,
957 const struct rte_flow_action *action,
958 struct rte_flow_error *error)
960 struct fm_header_set *fm_data;
961 struct fm_action_op fm_op;
963 ENICPMD_FUNC_TRACE();
964 fm_data = &fmt->ftm_data.fk_hdrset[0];
965 if (!(fm_data->fk_metadata & FKM_VXLAN)) {
966 return rte_flow_error_set(error, EINVAL,
967 RTE_FLOW_ERROR_TYPE_ACTION, action,
968 "vxlan-decap: vxlan must be in pattern");
971 memset(&fm_op, 0, sizeof(fm_op));
972 fm_op.fa_op = FMOP_DECAP_NOSTRIP;
973 return enic_fm_append_action_op(fm, &fm_op, error);
976 /* VXLAN encap is done via flowman compound action */
978 enic_fm_copy_vxlan_encap(struct enic_flowman *fm,
979 const struct rte_flow_item *item,
980 struct rte_flow_error *error)
982 struct fm_action_op fm_op;
983 struct rte_ether_hdr *eth;
988 ENICPMD_FUNC_TRACE();
989 memset(&fm_op, 0, sizeof(fm_op));
990 fm_op.fa_op = FMOP_ENCAP;
991 template = fm->action.fma_data;
994 * Copy flow items to the flowman template starting L2.
995 * L2 must be ethernet.
997 flow_item_skip_void(&item);
998 if (item->type != RTE_FLOW_ITEM_TYPE_ETH)
999 return rte_flow_error_set(error, EINVAL,
1000 RTE_FLOW_ERROR_TYPE_ITEM, item,
1001 "vxlan-encap: first item should be ethernet");
1002 eth = (struct rte_ether_hdr *)template;
1003 ethertype = ð->ether_type;
1004 append_template(&template, &off, item->spec,
1005 sizeof(struct rte_flow_item_eth));
1007 flow_item_skip_void(&item);
1009 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1010 const struct rte_flow_item_vlan *spec;
1012 ENICPMD_LOG(DEBUG, "vxlan-encap: vlan");
1014 fm_op.encap.outer_vlan = rte_be_to_cpu_16(spec->tci);
1016 flow_item_skip_void(&item);
1018 /* L3 must be IPv4, IPv6 */
1019 switch (item->type) {
1020 case RTE_FLOW_ITEM_TYPE_IPV4:
1022 struct rte_ipv4_hdr *ip4;
1024 ENICPMD_LOG(DEBUG, "vxlan-encap: ipv4");
1025 *ethertype = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
1026 ip4 = (struct rte_ipv4_hdr *)template;
1028 * Offset of IPv4 length field and its initial value
1029 * (IP + UDP + VXLAN) are specified in the action. The NIC
1030 * will add inner packet length.
1032 fm_op.encap.len1_offset = off +
1033 offsetof(struct rte_ipv4_hdr, total_length);
1034 fm_op.encap.len1_delta = sizeof(struct rte_ipv4_hdr) +
1035 sizeof(struct rte_udp_hdr) +
1036 sizeof(struct rte_vxlan_hdr);
1037 append_template(&template, &off, item->spec,
1038 sizeof(struct rte_ipv4_hdr));
1039 ip4->version_ihl = RTE_IPV4_VHL_DEF;
1040 if (ip4->time_to_live == 0)
1041 ip4->time_to_live = IP_DEFTTL;
1042 ip4->next_proto_id = IPPROTO_UDP;
1045 case RTE_FLOW_ITEM_TYPE_IPV6:
1047 struct rte_ipv6_hdr *ip6;
1049 ENICPMD_LOG(DEBUG, "vxlan-encap: ipv6");
1050 *ethertype = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
1051 ip6 = (struct rte_ipv6_hdr *)template;
1052 fm_op.encap.len1_offset = off +
1053 offsetof(struct rte_ipv6_hdr, payload_len);
1054 fm_op.encap.len1_delta = sizeof(struct rte_udp_hdr) +
1055 sizeof(struct rte_vxlan_hdr);
1056 append_template(&template, &off, item->spec,
1057 sizeof(struct rte_ipv6_hdr));
1058 ip6->vtc_flow |= rte_cpu_to_be_32(IP6_VTC_FLOW);
1059 if (ip6->hop_limits == 0)
1060 ip6->hop_limits = IP_DEFTTL;
1061 ip6->proto = IPPROTO_UDP;
1065 return rte_flow_error_set(error,
1066 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, item,
1067 "vxlan-encap: L3 must be IPv4/IPv6");
1070 flow_item_skip_void(&item);
1073 if (item->type != RTE_FLOW_ITEM_TYPE_UDP)
1074 return rte_flow_error_set(error, EINVAL,
1075 RTE_FLOW_ERROR_TYPE_ITEM, item,
1076 "vxlan-encap: UDP must follow IPv4/IPv6");
1077 /* UDP length = UDP + VXLAN. NIC will add inner packet length. */
1078 fm_op.encap.len2_offset =
1079 off + offsetof(struct rte_udp_hdr, dgram_len);
1080 fm_op.encap.len2_delta =
1081 sizeof(struct rte_udp_hdr) + sizeof(struct rte_vxlan_hdr);
1082 append_template(&template, &off, item->spec,
1083 sizeof(struct rte_udp_hdr));
1085 flow_item_skip_void(&item);
1088 if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN)
1089 return rte_flow_error_set(error,
1090 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, item,
1091 "vxlan-encap: VXLAN must follow UDP");
1092 append_template(&template, &off, item->spec,
1093 sizeof(struct rte_flow_item_vxlan));
1096 * Fill in the rest of the action structure.
1097 * Indicate that we want to encap with vxlan at packet start.
1099 fm_op.encap.template_offset = 0;
1100 fm_op.encap.template_len = off;
1101 return enic_fm_append_action_op(fm, &fm_op, error);
1105 enic_fm_find_vnic(struct enic *enic, const struct rte_pci_addr *addr,
1112 ENICPMD_FUNC_TRACE();
1113 ENICPMD_LOG(DEBUG, "bdf=%x:%x:%x", addr->bus, addr->devid,
1115 bdf = addr->bus << 8 | addr->devid << 3 | addr->function;
1116 args[0] = FM_VNIC_FIND;
1118 rc = vnic_dev_flowman_cmd(enic->vdev, args, 2);
1120 /* Expected to fail if BDF is not on the adapter */
1121 ENICPMD_LOG(DEBUG, "cannot find vnic handle: rc=%d", rc);
1125 ENICPMD_LOG(DEBUG, "found vnic: handle=0x%" PRIx64, *handle);
1130 * Egress: target port should be either PF uplink or VF.
1132 * 1. VF egress -> PF uplink
1133 * PF may be this VF's PF, or another PF, as long as they are on the same VIC.
1134 * 2. VF egress -> VF
1137 * 1. PF egress -> VF
1138 * App should be using representor to pass packets to VF
1141 vf_egress_port_id_action(struct enic_flowman *fm,
1142 struct rte_eth_dev *dst_dev,
1143 uint64_t dst_vnic_h,
1144 struct fm_action_op *fm_op,
1145 struct rte_flow_error *error)
1147 struct enic *src_enic, *dst_enic;
1148 struct enic_vf_representor *vf;
1152 ENICPMD_FUNC_TRACE();
1153 src_enic = fm->user_enic;
1154 dst_enic = pmd_priv(dst_dev);
1155 if (!(src_enic->rte_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
1156 return rte_flow_error_set(error, EINVAL,
1157 RTE_FLOW_ERROR_TYPE_ACTION,
1158 NULL, "source port is not VF representor");
1161 /* VF -> PF uplink. dst is not VF representor */
1162 if (!(dst_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)) {
1163 /* PF is the VF's PF? Then nothing to do */
1164 vf = VF_ENIC_TO_VF_REP(src_enic);
1165 if (vf->pf == dst_enic) {
1166 ENICPMD_LOG(DEBUG, "destination port is VF's PF");
1169 /* If not, steer to the remote PF's uplink */
1170 uif = dst_enic->fm_vnic_uif;
1171 ENICPMD_LOG(DEBUG, "steer to uplink %u", uif);
1172 memset(fm_op, 0, sizeof(*fm_op));
1173 fm_op->fa_op = FMOP_SET_EGPORT;
1174 fm_op->set_egport.egport = uif;
1175 ret = enic_fm_append_action_op(fm, fm_op, error);
1179 /* VF -> VF loopback. Hairpin and steer to vnic */
1180 memset(fm_op, 0, sizeof(*fm_op));
1181 fm_op->fa_op = FMOP_EG_HAIRPIN;
1182 ret = enic_fm_append_action_op(fm, fm_op, error);
1185 ENICPMD_LOG(DEBUG, "egress hairpin");
1186 fm->hairpin_steer_vnic_h = dst_vnic_h;
1187 fm->need_hairpin_steer = 1;
1191 /* Translate flow actions to flowman TCAM entry actions */
1193 enic_fm_copy_action(struct enic_flowman *fm,
1194 const struct rte_flow_action actions[],
1196 struct rte_flow_error *error)
1207 struct fm_tcam_match_entry *fmt;
1208 struct fm_action_op fm_op;
1209 bool need_ovlan_action;
1218 ENICPMD_FUNC_TRACE();
1219 fmt = &fm->tcam_entry;
1220 need_ovlan_action = false;
1224 enic = fm->user_enic;
1226 vnic_h = enic->fm_vnic_handle;
1228 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1229 switch (actions->type) {
1230 case RTE_FLOW_ACTION_TYPE_VOID:
1232 case RTE_FLOW_ACTION_TYPE_PASSTHRU: {
1233 if (overlap & PASSTHRU)
1235 overlap |= PASSTHRU;
1238 case RTE_FLOW_ACTION_TYPE_JUMP: {
1239 const struct rte_flow_action_jump *jump =
1241 struct enic_fm_fet *fet;
1245 ret = enic_fet_get(fm, jump->group, ingress, NULL,
1250 memset(&fm_op, 0, sizeof(fm_op));
1251 fm_op.fa_op = FMOP_EXACT_MATCH;
1252 fm_op.exact.handle = fet->handle;
1254 ret = enic_fm_append_action_op(fm, &fm_op, error);
1259 case RTE_FLOW_ACTION_TYPE_MARK: {
1260 const struct rte_flow_action_mark *mark =
1263 if (mark->id >= ENIC_MAGIC_FILTER_ID - 1)
1264 return rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ACTION,
1266 NULL, "invalid mark id");
1267 memset(&fm_op, 0, sizeof(fm_op));
1268 fm_op.fa_op = FMOP_MARK;
1269 fm_op.mark.mark = mark->id + 1;
1270 ret = enic_fm_append_action_op(fm, &fm_op, error);
1275 case RTE_FLOW_ACTION_TYPE_FLAG: {
1276 /* ENIC_MAGIC_FILTER_ID is reserved for flagging */
1277 memset(&fm_op, 0, sizeof(fm_op));
1278 fm_op.fa_op = FMOP_MARK;
1279 fm_op.mark.mark = ENIC_MAGIC_FILTER_ID;
1280 ret = enic_fm_append_action_op(fm, &fm_op, error);
1285 case RTE_FLOW_ACTION_TYPE_QUEUE: {
1286 const struct rte_flow_action_queue *queue =
1290 * If fate other than QUEUE or RSS, fail. Multiple
1291 * rss and queue actions are ok.
1293 if ((overlap & FATE) && first_rq)
1297 memset(&fm_op, 0, sizeof(fm_op));
1298 fm_op.fa_op = FMOP_RQ_STEER;
1299 fm_op.rq_steer.rq_index =
1300 enic_rte_rq_idx_to_sop_idx(queue->index);
1301 fm_op.rq_steer.rq_count = 1;
1302 fm_op.rq_steer.vnic_handle = vnic_h;
1303 ret = enic_fm_append_action_op(fm, &fm_op, error);
1306 ENICPMD_LOG(DEBUG, "create QUEUE action rq: %u",
1307 fm_op.rq_steer.rq_index);
1311 case RTE_FLOW_ACTION_TYPE_DROP: {
1315 memset(&fm_op, 0, sizeof(fm_op));
1316 fm_op.fa_op = FMOP_DROP;
1317 ret = enic_fm_append_action_op(fm, &fm_op, error);
1320 ENICPMD_LOG(DEBUG, "create DROP action");
1323 case RTE_FLOW_ACTION_TYPE_COUNT: {
1324 if (overlap & COUNT)
1327 /* Count is associated with entry not action on VIC. */
1328 fmt->ftm_flags |= FMEF_COUNTER;
1331 case RTE_FLOW_ACTION_TYPE_RSS: {
1332 const struct rte_flow_action_rss *rss = actions->conf;
1337 * If fate other than QUEUE or RSS, fail. Multiple
1338 * rss and queue actions are ok.
1340 if ((overlap & FATE) && first_rq)
1346 * Hardware only supports RSS actions on outer level
1347 * with default type and function. Queues must be
1350 allow = rss->func == RTE_ETH_HASH_FUNCTION_DEFAULT &&
1351 rss->level == 0 && (rss->types == 0 ||
1352 rss->types == enic->rss_hf) &&
1353 rss->queue_num <= enic->rq_count &&
1354 rss->queue[rss->queue_num - 1] < enic->rq_count;
1357 /* Identity queue map needs to be sequential */
1358 for (i = 1; i < rss->queue_num; i++)
1359 allow = allow && (rss->queue[i] ==
1360 rss->queue[i - 1] + 1);
1364 memset(&fm_op, 0, sizeof(fm_op));
1365 fm_op.fa_op = FMOP_RQ_STEER;
1366 fm_op.rq_steer.rq_index =
1367 enic_rte_rq_idx_to_sop_idx(rss->queue[0]);
1368 fm_op.rq_steer.rq_count = rss->queue_num;
1369 fm_op.rq_steer.vnic_handle = vnic_h;
1370 ret = enic_fm_append_action_op(fm, &fm_op, error);
1373 ENICPMD_LOG(DEBUG, "create QUEUE action rq: %u",
1374 fm_op.rq_steer.rq_index);
1378 case RTE_FLOW_ACTION_TYPE_PORT_ID: {
1379 const struct rte_flow_action_port_id *port;
1380 struct rte_eth_dev *dev;
1382 if (!ingress && (overlap & PORT_ID)) {
1383 ENICPMD_LOG(DEBUG, "cannot have multiple egress PORT_ID actions");
1386 port = actions->conf;
1387 if (port->original) {
1388 vnic_h = enic->fm_vnic_handle; /* This port */
1391 ENICPMD_LOG(DEBUG, "port id %u", port->id);
1392 if (!rte_eth_dev_is_valid_port(port->id)) {
1393 return rte_flow_error_set(error, EINVAL,
1394 RTE_FLOW_ERROR_TYPE_ACTION,
1395 NULL, "invalid port_id");
1397 dev = &rte_eth_devices[port->id];
1398 if (!dev_is_enic(dev)) {
1399 return rte_flow_error_set(error, EINVAL,
1400 RTE_FLOW_ERROR_TYPE_ACTION,
1401 NULL, "port_id is not enic");
1403 if (enic->switch_domain_id !=
1404 pmd_priv(dev)->switch_domain_id) {
1405 return rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ACTION,
1407 NULL, "destination and source ports are not in the same switch domain");
1409 vnic_h = pmd_priv(dev)->fm_vnic_handle;
1412 * Ingress. Nothing more to do. We add an implicit
1413 * steer at the end if needed.
1418 ret = vf_egress_port_id_action(fm, dev, vnic_h, &fm_op,
1424 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP: {
1425 if (overlap & DECAP)
1429 ret = enic_fm_copy_vxlan_decap(fm, fmt, actions,
1435 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP: {
1436 const struct rte_flow_action_vxlan_encap *encap;
1438 encap = actions->conf;
1439 if (overlap & ENCAP)
1442 ret = enic_fm_copy_vxlan_encap(fm, encap->definition,
1448 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: {
1449 memset(&fm_op, 0, sizeof(fm_op));
1450 fm_op.fa_op = FMOP_POP_VLAN;
1451 ret = enic_fm_append_action_op(fm, &fm_op, error);
1456 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN: {
1457 const struct rte_flow_action_of_push_vlan *vlan;
1459 if (overlap & PASSTHRU)
1461 vlan = actions->conf;
1462 if (vlan->ethertype != RTE_BE16(RTE_ETHER_TYPE_VLAN)) {
1463 return rte_flow_error_set(error, EINVAL,
1464 RTE_FLOW_ERROR_TYPE_ACTION,
1465 NULL, "unexpected push_vlan ethertype");
1467 overlap |= PUSH_VLAN;
1468 need_ovlan_action = true;
1471 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP: {
1472 const struct rte_flow_action_of_set_vlan_pcp *pcp;
1474 pcp = actions->conf;
1475 if (pcp->vlan_pcp > 7) {
1476 return rte_flow_error_set(error, EINVAL,
1477 RTE_FLOW_ERROR_TYPE_ACTION,
1478 NULL, "invalid vlan_pcp");
1480 need_ovlan_action = true;
1481 ovlan |= ((uint16_t)pcp->vlan_pcp) << 13;
1484 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID: {
1485 const struct rte_flow_action_of_set_vlan_vid *vid;
1487 vid = actions->conf;
1488 need_ovlan_action = true;
1489 ovlan |= rte_be_to_cpu_16(vid->vlan_vid);
1497 if (!(overlap & (FATE | PASSTHRU | COUNT | PORT_ID)))
1499 /* Egress from VF: need implicit WQ match */
1500 if (enic_is_vf_rep(enic) && !ingress) {
1501 fmt->ftm_data.fk_wq_id = 0;
1502 fmt->ftm_mask.fk_wq_id = 0xffff;
1503 fmt->ftm_data.fk_wq_vnic = enic->fm_vnic_handle;
1504 ENICPMD_LOG(DEBUG, "add implicit wq id match for vf %d",
1505 VF_ENIC_TO_VF_REP(enic)->vf_id);
1507 if (need_ovlan_action) {
1508 memset(&fm_op, 0, sizeof(fm_op));
1509 fm_op.fa_op = FMOP_SET_OVLAN;
1510 fm_op.ovlan.vlan = ovlan;
1511 ret = enic_fm_append_action_op(fm, &fm_op, error);
1515 /* Add steer op for PORT_ID without QUEUE */
1516 if ((overlap & PORT_ID) && !steer && ingress) {
1517 memset(&fm_op, 0, sizeof(fm_op));
1518 /* Always to queue 0 for now as generic RSS is not available */
1519 fm_op.fa_op = FMOP_RQ_STEER;
1520 fm_op.rq_steer.rq_index = 0;
1521 fm_op.rq_steer.vnic_handle = vnic_h;
1522 ret = enic_fm_append_action_op(fm, &fm_op, error);
1525 ENICPMD_LOG(DEBUG, "add implicit steer op");
1527 /* Add required END */
1528 memset(&fm_op, 0, sizeof(fm_op));
1529 fm_op.fa_op = FMOP_END;
1530 ret = enic_fm_append_action_op(fm, &fm_op, error);
1533 enic_fm_reorder_action_op(fm);
1537 return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
1538 NULL, "enic: unsupported action");
1541 /** Check if the action is supported */
1543 enic_fm_match_action(const struct rte_flow_action *action,
1544 const enum rte_flow_action_type *supported_actions)
1546 for (; *supported_actions != RTE_FLOW_ACTION_TYPE_END;
1547 supported_actions++) {
1548 if (action->type == *supported_actions)
1554 /* Debug function to dump internal NIC action structure. */
1556 enic_fm_dump_tcam_actions(const struct fm_action *fm_action)
1558 /* Manually keep in sync with FMOP commands */
1559 const char *fmop_str[FMOP_OP_MAX] = {
1561 [FMOP_DROP] = "drop",
1562 [FMOP_RQ_STEER] = "steer",
1563 [FMOP_EXACT_MATCH] = "exmatch",
1564 [FMOP_MARK] = "mark",
1565 [FMOP_EXT_MARK] = "ext_mark",
1567 [FMOP_EG_HAIRPIN] = "eg_hairpin",
1568 [FMOP_IG_HAIRPIN] = "ig_hairpin",
1569 [FMOP_ENCAP_IVLAN] = "encap_ivlan",
1570 [FMOP_ENCAP_NOIVLAN] = "encap_noivlan",
1571 [FMOP_ENCAP] = "encap",
1572 [FMOP_SET_OVLAN] = "set_ovlan",
1573 [FMOP_DECAP_NOSTRIP] = "decap_nostrip",
1574 [FMOP_DECAP_STRIP] = "decap_strip",
1575 [FMOP_POP_VLAN] = "pop_vlan",
1576 [FMOP_SET_EGPORT] = "set_egport",
1577 [FMOP_RQ_STEER_ONLY] = "rq_steer_only",
1578 [FMOP_SET_ENCAP_VLAN] = "set_encap_vlan",
1579 [FMOP_EMIT] = "emit",
1580 [FMOP_MODIFY] = "modify",
1582 const struct fm_action_op *op = &fm_action->fma_action_ops[0];
1583 char buf[128], *bp = buf;
1588 buf_len = sizeof(buf);
1589 for (i = 0; i < FM_ACTION_OP_MAX; i++) {
1590 if (op->fa_op == FMOP_END)
1592 if (op->fa_op >= FMOP_OP_MAX)
1595 op_str = fmop_str[op->fa_op];
1596 n = snprintf(bp, buf_len, "%s,", op_str);
1597 if (n > 0 && n < buf_len) {
1603 /* Remove trailing comma */
1606 ENICPMD_LOG(DEBUG, " Acions: %s", buf);
1610 bits_to_str(uint32_t bits, const char *strings[], int max,
1611 char *buf, int buf_len)
1613 int i, n = 0, len = 0;
1615 for (i = 0; i < max; i++) {
1616 if (bits & (1 << i)) {
1617 n = snprintf(buf, buf_len, "%s,", strings[i]);
1618 if (n > 0 && n < buf_len) {
1625 /* Remove trailing comma */
1633 /* Debug function to dump internal NIC filter structure. */
1635 __enic_fm_dump_tcam_match(const struct fm_header_set *fk_hdrset, char *buf,
1638 /* Manually keep in sync with FKM_BITS */
1639 const char *fm_fkm_str[FKM_BIT_COUNT] = {
1640 [FKM_QTAG_BIT] = "qtag",
1641 [FKM_CMD_BIT] = "cmd",
1642 [FKM_IPV4_BIT] = "ip4",
1643 [FKM_IPV6_BIT] = "ip6",
1644 [FKM_ROCE_BIT] = "roce",
1645 [FKM_UDP_BIT] = "udp",
1646 [FKM_TCP_BIT] = "tcp",
1647 [FKM_TCPORUDP_BIT] = "tcpportudp",
1648 [FKM_IPFRAG_BIT] = "ipfrag",
1649 [FKM_NVGRE_BIT] = "nvgre",
1650 [FKM_VXLAN_BIT] = "vxlan",
1651 [FKM_GENEVE_BIT] = "geneve",
1652 [FKM_NSH_BIT] = "nsh",
1653 [FKM_ROCEV2_BIT] = "rocev2",
1654 [FKM_VLAN_PRES_BIT] = "vlan_pres",
1655 [FKM_IPOK_BIT] = "ipok",
1656 [FKM_L4OK_BIT] = "l4ok",
1657 [FKM_ROCEOK_BIT] = "roceok",
1658 [FKM_FCSOK_BIT] = "fcsok",
1659 [FKM_EG_SPAN_BIT] = "eg_span",
1660 [FKM_IG_SPAN_BIT] = "ig_span",
1661 [FKM_EG_HAIRPINNED_BIT] = "eg_hairpinned",
1663 /* Manually keep in sync with FKH_BITS */
1664 const char *fm_fkh_str[FKH_BIT_COUNT] = {
1665 [FKH_ETHER_BIT] = "eth",
1666 [FKH_QTAG_BIT] = "qtag",
1667 [FKH_L2RAW_BIT] = "l2raw",
1668 [FKH_IPV4_BIT] = "ip4",
1669 [FKH_IPV6_BIT] = "ip6",
1670 [FKH_L3RAW_BIT] = "l3raw",
1671 [FKH_UDP_BIT] = "udp",
1672 [FKH_TCP_BIT] = "tcp",
1673 [FKH_ICMP_BIT] = "icmp",
1674 [FKH_VXLAN_BIT] = "vxlan",
1675 [FKH_L4RAW_BIT] = "l4raw",
1677 uint32_t fkh_bits = fk_hdrset->fk_header_select;
1678 uint32_t fkm_bits = fk_hdrset->fk_metadata;
1681 if (!fkm_bits && !fkh_bits)
1683 n = snprintf(buf, buf_len, "metadata(");
1684 if (n > 0 && n < buf_len) {
1688 n = bits_to_str(fkm_bits, fm_fkm_str, FKM_BIT_COUNT, buf, buf_len);
1689 if (n > 0 && n < buf_len) {
1693 n = snprintf(buf, buf_len, ") valid hdr fields(");
1694 if (n > 0 && n < buf_len) {
1698 n = bits_to_str(fkh_bits, fm_fkh_str, FKH_BIT_COUNT, buf, buf_len);
1699 if (n > 0 && n < buf_len) {
1703 snprintf(buf, buf_len, ")");
1707 enic_fm_dump_tcam_match(const struct fm_tcam_match_entry *match,
1712 memset(buf, 0, sizeof(buf));
1713 __enic_fm_dump_tcam_match(&match->ftm_mask.fk_hdrset[0],
1715 ENICPMD_LOG(DEBUG, " TCAM %s Outer: %s %scounter",
1716 (ingress) ? "IG" : "EG", buf,
1717 (match->ftm_flags & FMEF_COUNTER) ? "" : "no ");
1718 memset(buf, 0, sizeof(buf));
1719 __enic_fm_dump_tcam_match(&match->ftm_mask.fk_hdrset[1],
1722 ENICPMD_LOG(DEBUG, " Inner: %s", buf);
1725 /* Debug function to dump internal NIC flow structures. */
1727 enic_fm_dump_tcam_entry(const struct fm_tcam_match_entry *fm_match,
1728 const struct fm_action *fm_action,
1731 if (!rte_log_can_log(enic_pmd_logtype, RTE_LOG_DEBUG))
1733 enic_fm_dump_tcam_match(fm_match, ingress);
1734 enic_fm_dump_tcam_actions(fm_action);
1738 enic_fm_flow_parse(struct enic_flowman *fm,
1739 const struct rte_flow_attr *attrs,
1740 const struct rte_flow_item pattern[],
1741 const struct rte_flow_action actions[],
1742 struct rte_flow_error *error)
1744 const struct rte_flow_action *action;
1746 static const enum rte_flow_action_type *sa;
1748 ENICPMD_FUNC_TRACE();
1751 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1752 NULL, "no pattern specified");
1757 rte_flow_error_set(error, EINVAL,
1758 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1759 NULL, "no action specified");
1764 if (attrs->priority) {
1765 rte_flow_error_set(error, ENOTSUP,
1766 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1768 "priorities are not supported");
1770 } else if (!fm->owner_enic->switchdev_mode && attrs->transfer) {
1771 rte_flow_error_set(error, ENOTSUP,
1772 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1774 "transfer is not supported");
1776 } else if (attrs->ingress && attrs->egress) {
1777 rte_flow_error_set(error, ENOTSUP,
1778 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1780 "bidirectional rules not supported");
1785 rte_flow_error_set(error, EINVAL,
1786 RTE_FLOW_ERROR_TYPE_ATTR,
1787 NULL, "no attribute specified");
1791 /* Verify Actions. */
1792 sa = (attrs->ingress) ? enic_fm_supported_ig_actions :
1793 enic_fm_supported_eg_actions;
1794 for (action = &actions[0]; action->type != RTE_FLOW_ACTION_TYPE_END;
1796 if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
1798 else if (!enic_fm_match_action(action, sa))
1801 if (action->type != RTE_FLOW_ACTION_TYPE_END) {
1802 rte_flow_error_set(error, EPERM, RTE_FLOW_ERROR_TYPE_ACTION,
1803 action, "invalid action");
1806 ret = enic_fm_copy_entry(fm, pattern, error);
1809 ret = enic_fm_copy_action(fm, actions, attrs->ingress, error);
1814 enic_fm_counter_free(struct enic_flowman *fm, struct enic_fm_flow *fm_flow)
1816 if (!fm_flow->counter_valid)
1818 SLIST_INSERT_HEAD(&fm->counters, fm_flow->counter, next);
1819 fm_flow->counter_valid = false;
1823 enic_fm_more_counters(struct enic_flowman *fm)
1825 struct enic_fm_counter *new_stack;
1826 struct enic_fm_counter *ctrs;
1830 ENICPMD_FUNC_TRACE();
1831 new_stack = rte_realloc(fm->counter_stack, (fm->counters_alloced +
1832 FM_COUNTERS_EXPAND) *
1833 sizeof(struct enic_fm_counter), 0);
1834 if (new_stack == NULL) {
1835 ENICPMD_LOG(ERR, "cannot alloc counter memory");
1838 fm->counter_stack = new_stack;
1840 args[0] = FM_COUNTER_BRK;
1841 args[1] = fm->counters_alloced + FM_COUNTERS_EXPAND;
1842 rc = flowman_cmd(fm, args, 2);
1844 ENICPMD_LOG(ERR, "cannot alloc counters rc=%d", rc);
1847 ctrs = (struct enic_fm_counter *)fm->counter_stack +
1848 fm->counters_alloced;
1849 for (i = 0; i < FM_COUNTERS_EXPAND; i++, ctrs++) {
1850 ctrs->handle = fm->counters_alloced + i;
1851 SLIST_INSERT_HEAD(&fm->counters, ctrs, next);
1853 fm->counters_alloced += FM_COUNTERS_EXPAND;
1854 ENICPMD_LOG(DEBUG, "%u counters allocated, total: %u",
1855 FM_COUNTERS_EXPAND, fm->counters_alloced);
1860 enic_fm_counter_zero(struct enic_flowman *fm, struct enic_fm_counter *c)
1865 ENICPMD_FUNC_TRACE();
1866 args[0] = FM_COUNTER_QUERY;
1867 args[1] = c->handle;
1868 args[2] = 1; /* clear */
1869 ret = flowman_cmd(fm, args, 3);
1871 ENICPMD_LOG(ERR, "counter init: rc=%d handle=0x%x",
1879 enic_fm_counter_alloc(struct enic_flowman *fm, struct rte_flow_error *error,
1880 struct enic_fm_counter **ctr)
1882 struct enic_fm_counter *c;
1885 ENICPMD_FUNC_TRACE();
1887 if (SLIST_EMPTY(&fm->counters)) {
1888 ret = enic_fm_more_counters(fm);
1890 return rte_flow_error_set(error, -ret,
1891 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1892 NULL, "enic: out of counters");
1894 c = SLIST_FIRST(&fm->counters);
1895 SLIST_REMOVE_HEAD(&fm->counters, next);
1901 enic_fm_action_free(struct enic_flowman *fm, uint64_t handle)
1906 ENICPMD_FUNC_TRACE();
1907 args[0] = FM_ACTION_FREE;
1909 rc = flowman_cmd(fm, args, 2);
1911 ENICPMD_LOG(ERR, "cannot free action: rc=%d handle=0x%" PRIx64,
1917 enic_fm_entry_free(struct enic_flowman *fm, uint64_t handle)
1922 ENICPMD_FUNC_TRACE();
1923 args[0] = FM_MATCH_ENTRY_REMOVE;
1925 rc = flowman_cmd(fm, args, 2);
1927 ENICPMD_LOG(ERR, "cannot free match entry: rc=%d"
1928 " handle=0x%" PRIx64, rc, handle);
1932 static struct enic_fm_jump_flow *
1933 find_jump_flow(struct enic_flowman *fm, uint32_t group)
1935 struct enic_fm_jump_flow *j;
1937 ENICPMD_FUNC_TRACE();
1938 TAILQ_FOREACH(j, &fm->jump_list, list) {
1939 if (j->group == group)
1946 remove_jump_flow(struct enic_flowman *fm, struct rte_flow *flow)
1948 struct enic_fm_jump_flow *j;
1950 ENICPMD_FUNC_TRACE();
1951 TAILQ_FOREACH(j, &fm->jump_list, list) {
1952 if (j->flow == flow) {
1953 TAILQ_REMOVE(&fm->jump_list, j, list);
1961 save_jump_flow(struct enic_flowman *fm,
1962 struct rte_flow *flow,
1964 struct fm_tcam_match_entry *match,
1965 struct fm_action *action)
1967 struct enic_fm_jump_flow *j;
1969 ENICPMD_FUNC_TRACE();
1970 j = calloc(1, sizeof(struct enic_fm_jump_flow));
1976 j->action = *action;
1977 TAILQ_INSERT_HEAD(&fm->jump_list, j, list);
1978 ENICPMD_LOG(DEBUG, "saved jump flow: flow=%p group=%u", flow, group);
1983 __enic_fm_flow_free(struct enic_flowman *fm, struct enic_fm_flow *fm_flow)
1985 if (fm_flow->entry_handle != FM_INVALID_HANDLE) {
1986 enic_fm_entry_free(fm, fm_flow->entry_handle);
1987 fm_flow->entry_handle = FM_INVALID_HANDLE;
1989 if (fm_flow->action_handle != FM_INVALID_HANDLE) {
1990 enic_fm_action_free(fm, fm_flow->action_handle);
1991 fm_flow->action_handle = FM_INVALID_HANDLE;
1993 enic_fm_counter_free(fm, fm_flow);
1995 enic_fet_put(fm, fm_flow->fet);
1996 fm_flow->fet = NULL;
2001 enic_fm_flow_free(struct enic_flowman *fm, struct rte_flow *flow)
2003 struct enic_fm_flow *steer = flow->fm->hairpin_steer_flow;
2005 if (flow->fm->fet && flow->fm->fet->default_key)
2006 remove_jump_flow(fm, flow);
2007 __enic_fm_flow_free(fm, flow->fm);
2009 __enic_fm_flow_free(fm, steer);
2017 enic_fm_add_tcam_entry(struct enic_flowman *fm,
2018 struct fm_tcam_match_entry *match_in,
2019 uint64_t *entry_handle,
2021 struct rte_flow_error *error)
2023 struct fm_tcam_match_entry *ftm;
2027 ENICPMD_FUNC_TRACE();
2028 /* Copy entry to the command buffer */
2029 ftm = &fm->cmd.va->fm_tcam_match_entry;
2030 memcpy(ftm, match_in, sizeof(*ftm));
2031 /* Add TCAM entry */
2032 args[0] = FM_TCAM_ENTRY_INSTALL;
2033 args[1] = ingress ? fm->ig_tcam_hndl : fm->eg_tcam_hndl;
2034 args[2] = fm->cmd.pa;
2035 ret = flowman_cmd(fm, args, 3);
2037 ENICPMD_LOG(ERR, "cannot add %s TCAM entry: rc=%d",
2038 ingress ? "ingress" : "egress", ret);
2039 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2040 NULL, "enic: devcmd(tcam-entry-install)");
2043 ENICPMD_LOG(DEBUG, "installed %s TCAM entry: handle=0x%" PRIx64,
2044 ingress ? "ingress" : "egress", (uint64_t)args[0]);
2045 *entry_handle = args[0];
2050 enic_fm_add_exact_entry(struct enic_flowman *fm,
2051 struct fm_tcam_match_entry *match_in,
2052 uint64_t *entry_handle,
2053 struct enic_fm_fet *fet,
2054 struct rte_flow_error *error)
2056 struct fm_exact_match_entry *fem;
2060 ENICPMD_FUNC_TRACE();
2061 /* The new entry must have the table's key */
2062 if (memcmp(fet->key.fk_hdrset, match_in->ftm_mask.fk_hdrset,
2063 sizeof(struct fm_header_set) * FM_HDRSET_MAX)) {
2064 return rte_flow_error_set(error, EINVAL,
2065 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2066 "enic: key does not match group's key");
2069 /* Copy entry to the command buffer */
2070 fem = &fm->cmd.va->fm_exact_match_entry;
2072 * Translate TCAM entry to exact entry. As is only need to drop
2073 * position and mask. The mask is part of the exact match table.
2074 * Position (aka priority) is not supported in the exact match table.
2076 fem->fem_data = match_in->ftm_data;
2077 fem->fem_flags = match_in->ftm_flags;
2078 fem->fem_action = match_in->ftm_action;
2079 fem->fem_counter = match_in->ftm_counter;
2081 /* Add exact entry */
2082 args[0] = FM_EXACT_ENTRY_INSTALL;
2083 args[1] = fet->handle;
2084 args[2] = fm->cmd.pa;
2085 ret = flowman_cmd(fm, args, 3);
2087 ENICPMD_LOG(ERR, "cannot add %s exact entry: group=%u",
2088 fet->ingress ? "ingress" : "egress", fet->group);
2089 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2090 NULL, "enic: devcmd(exact-entry-install)");
2093 ENICPMD_LOG(DEBUG, "installed %s exact entry: group=%u"
2094 " handle=0x%" PRIx64,
2095 fet->ingress ? "ingress" : "egress", fet->group,
2097 *entry_handle = args[0];
2101 /* Push match-action to the NIC. */
2103 __enic_fm_flow_add_entry(struct enic_flowman *fm,
2104 struct enic_fm_flow *fm_flow,
2105 struct fm_tcam_match_entry *match_in,
2106 struct fm_action *action_in,
2109 struct rte_flow_error *error)
2111 struct enic_fm_counter *ctr;
2112 struct fm_action *fma;
2118 ENICPMD_FUNC_TRACE();
2119 /* Allocate action. */
2120 fma = &fm->cmd.va->fm_action;
2121 memcpy(fma, action_in, sizeof(*fma));
2122 args[0] = FM_ACTION_ALLOC;
2123 args[1] = fm->cmd.pa;
2124 ret = flowman_cmd(fm, args, 2);
2126 ENICPMD_LOG(ERR, "allocating TCAM table action rc=%d", ret);
2127 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2128 NULL, "enic: devcmd(action-alloc)");
2132 fm_flow->action_handle = action_h;
2133 match_in->ftm_action = action_h;
2134 ENICPMD_LOG(DEBUG, "action allocated: handle=0x%" PRIx64, action_h);
2136 /* Allocate counter if requested. */
2137 if (match_in->ftm_flags & FMEF_COUNTER) {
2138 ret = enic_fm_counter_alloc(fm, error, &ctr);
2139 if (ret) /* error has been filled in */
2141 fm_flow->counter_valid = true;
2142 fm_flow->counter = ctr;
2143 match_in->ftm_counter = ctr->handle;
2147 * Get the group's table (either TCAM or exact match table) and
2148 * add entry to it. If we use the exact match table, the handler
2149 * will translate the TCAM entry (match_in) to the appropriate
2150 * exact match entry and use that instead.
2152 entry_h = FM_INVALID_HANDLE;
2153 if (group == FM_TCAM_RTE_GROUP) {
2154 ret = enic_fm_add_tcam_entry(fm, match_in, &entry_h, ingress,
2158 /* Jump action might have a ref to fet */
2159 fm_flow->fet = fm->fet;
2162 struct enic_fm_fet *fet = NULL;
2164 ret = enic_fet_get(fm, group, ingress,
2165 &match_in->ftm_mask, &fet, error);
2169 ret = enic_fm_add_exact_entry(fm, match_in, &entry_h, fet,
2174 /* Clear counter after adding entry, as it requires in-use counter */
2175 if (fm_flow->counter_valid) {
2176 ret = enic_fm_counter_zero(fm, fm_flow->counter);
2180 fm_flow->entry_handle = entry_h;
2184 /* Push match-action to the NIC. */
2185 static struct rte_flow *
2186 enic_fm_flow_add_entry(struct enic_flowman *fm,
2187 struct fm_tcam_match_entry *match_in,
2188 struct fm_action *action_in,
2189 const struct rte_flow_attr *attrs,
2190 struct rte_flow_error *error)
2192 struct enic_fm_flow *fm_flow;
2193 struct rte_flow *flow;
2195 ENICPMD_FUNC_TRACE();
2196 enic_fm_dump_tcam_entry(match_in, action_in, attrs->ingress);
2197 flow = calloc(1, sizeof(*flow));
2198 fm_flow = calloc(1, sizeof(*fm_flow));
2199 if (flow == NULL || fm_flow == NULL) {
2200 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
2201 NULL, "enic: cannot allocate rte_flow");
2207 fm_flow->action_handle = FM_INVALID_HANDLE;
2208 fm_flow->entry_handle = FM_INVALID_HANDLE;
2209 if (__enic_fm_flow_add_entry(fm, fm_flow, match_in, action_in,
2210 attrs->group, attrs->ingress, error)) {
2211 enic_fm_flow_free(fm, flow);
2218 convert_jump_flows(struct enic_flowman *fm, struct enic_fm_fet *fet,
2219 struct rte_flow_error *error)
2221 struct enic_fm_flow *fm_flow;
2222 struct enic_fm_jump_flow *j;
2223 struct fm_action *fma;
2226 ENICPMD_FUNC_TRACE();
2228 * Find the saved flows that should jump to the new table (fet).
2229 * Then delete the old TCAM entry that jumps to the default table,
2230 * and add a new one that jumps to the new table.
2233 j = find_jump_flow(fm, group);
2235 ENICPMD_LOG(DEBUG, "convert jump flow: flow=%p group=%u",
2237 /* Delete old entry */
2238 fm_flow = j->flow->fm;
2239 __enic_fm_flow_free(fm, fm_flow);
2243 fma->fma_action_ops[0].exact.handle = fet->handle;
2244 if (__enic_fm_flow_add_entry(fm, fm_flow, &j->match, fma,
2245 FM_TCAM_RTE_GROUP, fet->ingress, error)) {
2246 /* Cannot roll back changes at the moment */
2247 ENICPMD_LOG(ERR, "cannot convert jump flow: flow=%p",
2252 ENICPMD_LOG(DEBUG, "convert ok: group=%u ref=%u",
2253 fet->group, fet->ref);
2256 TAILQ_REMOVE(&fm->jump_list, j, list);
2258 j = find_jump_flow(fm, group);
2263 add_hairpin_steer(struct enic_flowman *fm, struct rte_flow *flow,
2264 struct rte_flow_error *error)
2266 struct fm_tcam_match_entry *fm_tcam_entry;
2267 struct enic_fm_flow *fm_flow;
2268 struct fm_action *fm_action;
2269 struct fm_action_op fm_op;
2272 ENICPMD_FUNC_TRACE();
2273 fm_flow = calloc(1, sizeof(*fm_flow));
2274 if (fm_flow == NULL) {
2275 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
2276 NULL, "enic: cannot allocate rte_flow");
2279 /* Original egress hairpin flow */
2280 fm_tcam_entry = &fm->tcam_entry;
2281 fm_action = &fm->action;
2282 /* Use the match pattern of the egress flow as is, without counters */
2283 fm_tcam_entry->ftm_flags &= ~FMEF_COUNTER;
2284 /* The only action is steer to vnic */
2285 fm->action_op_count = 0;
2286 memset(fm_action, 0, sizeof(*fm_action));
2287 memset(&fm_op, 0, sizeof(fm_op));
2288 /* Always to queue 0 for now */
2289 fm_op.fa_op = FMOP_RQ_STEER;
2290 fm_op.rq_steer.rq_index = 0;
2291 fm_op.rq_steer.vnic_handle = fm->hairpin_steer_vnic_h;
2292 ret = enic_fm_append_action_op(fm, &fm_op, error);
2294 goto error_with_flow;
2295 ENICPMD_LOG(DEBUG, "add steer op");
2296 /* Add required END */
2297 memset(&fm_op, 0, sizeof(fm_op));
2298 fm_op.fa_op = FMOP_END;
2299 ret = enic_fm_append_action_op(fm, &fm_op, error);
2301 goto error_with_flow;
2302 /* Add the ingress flow */
2303 fm_flow->action_handle = FM_INVALID_HANDLE;
2304 fm_flow->entry_handle = FM_INVALID_HANDLE;
2305 ret = __enic_fm_flow_add_entry(fm, fm_flow, fm_tcam_entry, fm_action,
2306 FM_TCAM_RTE_GROUP, 1 /* ingress */, error);
2308 ENICPMD_LOG(ERR, "cannot add hairpin-steer flow");
2309 goto error_with_flow;
2311 /* The new flow is now the egress flow's paired flow */
2312 flow->fm->hairpin_steer_flow = fm_flow;
2321 enic_fm_open_scratch(struct enic_flowman *fm)
2323 fm->action_op_count = 0;
2325 fm->need_hairpin_steer = 0;
2326 fm->hairpin_steer_vnic_h = 0;
2327 memset(&fm->tcam_entry, 0, sizeof(fm->tcam_entry));
2328 memset(&fm->action, 0, sizeof(fm->action));
2332 enic_fm_close_scratch(struct enic_flowman *fm)
2335 enic_fet_put(fm, fm->fet);
2338 fm->action_op_count = 0;
2342 enic_fm_flow_validate(struct rte_eth_dev *dev,
2343 const struct rte_flow_attr *attrs,
2344 const struct rte_flow_item pattern[],
2345 const struct rte_flow_action actions[],
2346 struct rte_flow_error *error)
2348 struct fm_tcam_match_entry *fm_tcam_entry;
2349 struct fm_action *fm_action;
2350 struct enic_flowman *fm;
2353 ENICPMD_FUNC_TRACE();
2354 fm = begin_fm(pmd_priv(dev));
2357 enic_fm_open_scratch(fm);
2358 ret = enic_fm_flow_parse(fm, attrs, pattern, actions, error);
2360 fm_tcam_entry = &fm->tcam_entry;
2361 fm_action = &fm->action;
2362 enic_fm_dump_tcam_entry(fm_tcam_entry, fm_action,
2365 enic_fm_close_scratch(fm);
2371 enic_fm_flow_query_count(struct rte_eth_dev *dev,
2372 struct rte_flow *flow, void *data,
2373 struct rte_flow_error *error)
2375 struct rte_flow_query_count *query;
2376 struct enic_fm_flow *fm_flow;
2377 struct enic_flowman *fm;
2381 ENICPMD_FUNC_TRACE();
2382 fm = begin_fm(pmd_priv(dev));
2385 if (!fm_flow->counter_valid) {
2386 rc = rte_flow_error_set(error, ENOTSUP,
2387 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2388 "enic: flow does not have counter");
2392 args[0] = FM_COUNTER_QUERY;
2393 args[1] = fm_flow->counter->handle;
2394 args[2] = query->reset;
2395 rc = flowman_cmd(fm, args, 3);
2397 ENICPMD_LOG(ERR, "cannot query counter: rc=%d handle=0x%x",
2398 rc, fm_flow->counter->handle);
2401 query->hits_set = 1;
2402 query->hits = args[0];
2403 query->bytes_set = 1;
2404 query->bytes = args[1];
2412 enic_fm_flow_query(struct rte_eth_dev *dev,
2413 struct rte_flow *flow,
2414 const struct rte_flow_action *actions,
2416 struct rte_flow_error *error)
2420 ENICPMD_FUNC_TRACE();
2421 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2422 switch (actions->type) {
2423 case RTE_FLOW_ACTION_TYPE_VOID:
2425 case RTE_FLOW_ACTION_TYPE_COUNT:
2426 ret = enic_fm_flow_query_count(dev, flow, data, error);
2429 return rte_flow_error_set(error, ENOTSUP,
2430 RTE_FLOW_ERROR_TYPE_ACTION,
2432 "action not supported");
2440 static struct rte_flow *
2441 enic_fm_flow_create(struct rte_eth_dev *dev,
2442 const struct rte_flow_attr *attrs,
2443 const struct rte_flow_item pattern[],
2444 const struct rte_flow_action actions[],
2445 struct rte_flow_error *error)
2447 struct fm_tcam_match_entry *fm_tcam_entry;
2448 struct fm_action *fm_action;
2449 struct enic_flowman *fm;
2450 struct enic_fm_fet *fet;
2451 struct rte_flow *flow;
2455 ENICPMD_FUNC_TRACE();
2456 enic = pmd_priv(dev);
2457 fm = begin_fm(enic);
2459 rte_flow_error_set(error, ENOTSUP,
2460 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2461 "flowman is not initialized");
2464 enic_fm_open_scratch(fm);
2466 ret = enic_fm_flow_parse(fm, attrs, pattern, actions, error);
2468 goto error_with_scratch;
2469 fm_tcam_entry = &fm->tcam_entry;
2470 fm_action = &fm->action;
2471 flow = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2474 /* Add ingress rule that pairs with hairpin rule */
2475 if (fm->need_hairpin_steer) {
2476 ret = add_hairpin_steer(fm, flow, error);
2478 enic_fm_flow_free(fm, flow);
2480 goto error_with_scratch;
2483 LIST_INSERT_HEAD(&enic->flows, flow, next);
2484 fet = flow->fm->fet;
2485 if (fet && fet->default_key) {
2487 * Jump to non-existent group? Save the relevant info
2488 * so we can convert this flow when that group
2491 save_jump_flow(fm, flow, fet->group,
2492 fm_tcam_entry, fm_action);
2493 } else if (fet && fet->ref == 1) {
2495 * A new table is created. Convert the saved flows
2496 * that should jump to this group.
2498 convert_jump_flows(fm, fet, error);
2503 enic_fm_close_scratch(fm);
2509 enic_fm_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
2510 __rte_unused struct rte_flow_error *error)
2512 struct enic *enic = pmd_priv(dev);
2513 struct enic_flowman *fm;
2515 ENICPMD_FUNC_TRACE();
2516 fm = begin_fm(enic);
2519 LIST_REMOVE(flow, next);
2520 enic_fm_flow_free(fm, flow);
2526 enic_fm_flow_flush(struct rte_eth_dev *dev,
2527 __rte_unused struct rte_flow_error *error)
2529 LIST_HEAD(enic_flows, rte_flow) internal;
2530 struct enic_fm_flow *fm_flow;
2531 struct enic_flowman *fm;
2532 struct rte_flow *flow;
2533 struct enic *enic = pmd_priv(dev);
2535 ENICPMD_FUNC_TRACE();
2537 fm = begin_fm(enic);
2540 /* Destroy all non-internal flows */
2541 LIST_INIT(&internal);
2542 while (!LIST_EMPTY(&enic->flows)) {
2543 flow = LIST_FIRST(&enic->flows);
2545 LIST_REMOVE(flow, next);
2546 if (flow->internal) {
2547 LIST_INSERT_HEAD(&internal, flow, next);
2551 * If tables are null, then vNIC is closing, and the firmware
2552 * has already cleaned up flowman state. So do not try to free
2553 * resources, as it only causes errors.
2555 if (fm->ig_tcam_hndl == FM_INVALID_HANDLE) {
2556 fm_flow->entry_handle = FM_INVALID_HANDLE;
2557 fm_flow->action_handle = FM_INVALID_HANDLE;
2558 fm_flow->fet = NULL;
2560 enic_fm_flow_free(fm, flow);
2562 while (!LIST_EMPTY(&internal)) {
2563 flow = LIST_FIRST(&internal);
2564 LIST_REMOVE(flow, next);
2565 LIST_INSERT_HEAD(&enic->flows, flow, next);
2572 enic_fm_tbl_free(struct enic_flowman *fm, uint64_t handle)
2577 args[0] = FM_MATCH_TABLE_FREE;
2579 rc = flowman_cmd(fm, args, 2);
2581 ENICPMD_LOG(ERR, "cannot free table: rc=%d handle=0x%" PRIx64,
2587 enic_fm_tcam_tbl_alloc(struct enic_flowman *fm, uint32_t direction,
2588 uint32_t max_entries, uint64_t *handle)
2590 struct fm_tcam_match_table *tcam_tbl;
2594 ENICPMD_FUNC_TRACE();
2595 tcam_tbl = &fm->cmd.va->fm_tcam_match_table;
2596 tcam_tbl->ftt_direction = direction;
2597 tcam_tbl->ftt_stage = FM_STAGE_LAST;
2598 tcam_tbl->ftt_max_entries = max_entries;
2599 args[0] = FM_TCAM_TABLE_ALLOC;
2600 args[1] = fm->cmd.pa;
2601 rc = flowman_cmd(fm, args, 2);
2603 ENICPMD_LOG(ERR, "cannot alloc %s TCAM table: rc=%d",
2604 (direction == FM_INGRESS) ? "IG" : "EG", rc);
2608 ENICPMD_LOG(DEBUG, "%s TCAM table allocated, handle=0x%" PRIx64,
2609 (direction == FM_INGRESS) ? "IG" : "EG", *handle);
2614 enic_fm_init_counters(struct enic_flowman *fm)
2616 ENICPMD_FUNC_TRACE();
2617 SLIST_INIT(&fm->counters);
2618 return enic_fm_more_counters(fm);
2622 enic_fm_free_all_counters(struct enic_flowman *fm)
2627 args[0] = FM_COUNTER_BRK;
2629 rc = flowman_cmd(fm, args, 2);
2631 ENICPMD_LOG(ERR, "cannot free counters: rc=%d", rc);
2632 rte_free(fm->counter_stack);
2636 enic_fm_alloc_tcam_tables(struct enic_flowman *fm)
2640 ENICPMD_FUNC_TRACE();
2641 rc = enic_fm_tcam_tbl_alloc(fm, FM_INGRESS, FM_MAX_TCAM_TABLE_SIZE,
2645 rc = enic_fm_tcam_tbl_alloc(fm, FM_EGRESS, FM_MAX_TCAM_TABLE_SIZE,
2651 enic_fm_free_tcam_tables(struct enic_flowman *fm)
2653 ENICPMD_FUNC_TRACE();
2654 if (fm->ig_tcam_hndl) {
2655 ENICPMD_LOG(DEBUG, "free IG TCAM table handle=0x%" PRIx64,
2657 enic_fm_tbl_free(fm, fm->ig_tcam_hndl);
2658 fm->ig_tcam_hndl = FM_INVALID_HANDLE;
2660 if (fm->eg_tcam_hndl) {
2661 ENICPMD_LOG(DEBUG, "free EG TCAM table handle=0x%" PRIx64,
2663 enic_fm_tbl_free(fm, fm->eg_tcam_hndl);
2664 fm->eg_tcam_hndl = FM_INVALID_HANDLE;
2669 enic_fm_init(struct enic *enic)
2671 const struct rte_pci_addr *addr;
2672 struct enic_flowman *fm;
2673 uint8_t name[RTE_MEMZONE_NAMESIZE];
2676 if (enic->flow_filter_mode != FILTER_FLOWMAN)
2678 ENICPMD_FUNC_TRACE();
2679 /* Get vnic handle and save for port-id action */
2680 if (enic_is_vf_rep(enic))
2681 addr = &VF_ENIC_TO_VF_REP(enic)->bdf;
2683 addr = &RTE_ETH_DEV_TO_PCI(enic->rte_dev)->addr;
2684 rc = enic_fm_find_vnic(enic, addr, &enic->fm_vnic_handle);
2686 ENICPMD_LOG(ERR, "cannot find vnic handle for %x:%x:%x",
2687 addr->bus, addr->devid, addr->function);
2690 /* Save UIF for egport action */
2691 enic->fm_vnic_uif = vnic_dev_uif(enic->vdev);
2692 ENICPMD_LOG(DEBUG, "uif %u", enic->fm_vnic_uif);
2693 /* Nothing else to do for representor. It will share the PF flowman */
2694 if (enic_is_vf_rep(enic))
2696 fm = calloc(1, sizeof(*fm));
2698 ENICPMD_LOG(ERR, "cannot alloc flowman struct");
2701 fm->owner_enic = enic;
2702 rte_spinlock_init(&fm->lock);
2703 TAILQ_INIT(&fm->fet_list);
2704 TAILQ_INIT(&fm->jump_list);
2705 /* Allocate host memory for flowman commands */
2706 snprintf((char *)name, sizeof(name), "fm-cmd-%s", enic->bdf_name);
2707 fm->cmd.va = enic_alloc_consistent(enic,
2708 sizeof(union enic_flowman_cmd_mem), &fm->cmd.pa, name);
2710 ENICPMD_LOG(ERR, "cannot allocate flowman command memory");
2714 /* Allocate TCAM tables upfront as they are the main tables */
2715 rc = enic_fm_alloc_tcam_tables(fm);
2717 ENICPMD_LOG(ERR, "cannot alloc TCAM tables");
2720 /* Then a number of counters */
2721 rc = enic_fm_init_counters(fm);
2723 ENICPMD_LOG(ERR, "cannot alloc counters");
2727 * One default exact match table for each direction. We hold onto
2730 rc = enic_fet_alloc(fm, 1, NULL, 128, &fm->default_ig_fet);
2732 ENICPMD_LOG(ERR, "cannot alloc default IG exact match table");
2733 goto error_counters;
2735 fm->default_ig_fet->ref = 1;
2736 rc = enic_fet_alloc(fm, 0, NULL, 128, &fm->default_eg_fet);
2738 ENICPMD_LOG(ERR, "cannot alloc default EG exact match table");
2741 fm->default_eg_fet->ref = 1;
2742 fm->vf_rep_tag = FM_VF_REP_TAG;
2747 enic_fet_free(fm, fm->default_ig_fet);
2749 enic_fm_free_all_counters(fm);
2751 enic_fm_free_tcam_tables(fm);
2753 enic_free_consistent(enic, sizeof(union enic_flowman_cmd_mem),
2754 fm->cmd.va, fm->cmd.pa);
2761 enic_fm_destroy(struct enic *enic)
2763 struct enic_flowman *fm;
2764 struct enic_fm_fet *fet;
2766 ENICPMD_FUNC_TRACE();
2767 if (enic_is_vf_rep(enic)) {
2768 delete_rep_flows(enic);
2771 if (enic->fm == NULL)
2774 enic_fet_free(fm, fm->default_eg_fet);
2775 enic_fet_free(fm, fm->default_ig_fet);
2776 /* Free all exact match tables still open */
2777 while (!TAILQ_EMPTY(&fm->fet_list)) {
2778 fet = TAILQ_FIRST(&fm->fet_list);
2779 enic_fet_free(fm, fet);
2781 enic_fm_free_tcam_tables(fm);
2782 enic_fm_free_all_counters(fm);
2783 enic_free_consistent(enic, sizeof(union enic_flowman_cmd_mem),
2784 fm->cmd.va, fm->cmd.pa);
2791 enic_fm_allocate_switch_domain(struct enic *pf)
2793 const struct rte_pci_addr *cur_a, *prev_a;
2794 struct rte_eth_dev *dev;
2795 struct enic *cur, *prev;
2801 ENICPMD_FUNC_TRACE();
2802 if (enic_is_vf_rep(pf))
2805 cur_a = &RTE_ETH_DEV_TO_PCI(cur->rte_dev)->addr;
2806 /* Go through ports and find another PF that is on the same adapter */
2807 RTE_ETH_FOREACH_DEV(pid) {
2808 dev = &rte_eth_devices[pid];
2809 if (!dev_is_enic(dev))
2811 if (dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
2813 if (dev == cur->rte_dev)
2815 /* dev is another PF. Is it on the same adapter? */
2816 prev = pmd_priv(dev);
2817 prev_a = &RTE_ETH_DEV_TO_PCI(dev)->addr;
2818 if (!enic_fm_find_vnic(cur, prev_a, &vnic_h)) {
2819 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",
2820 cur->rte_dev->data->port_id,
2821 cur_a->bus, cur_a->devid, cur_a->function,
2823 prev_a->bus, prev_a->devid, prev_a->function,
2824 prev->switch_domain_id);
2825 cur->switch_domain_id = prev->switch_domain_id;
2829 ret = rte_eth_switch_domain_alloc(&domain_id);
2831 ENICPMD_LOG(WARNING, "failed to allocate switch domain for device %d",
2834 cur->switch_domain_id = domain_id;
2835 ENICPMD_LOG(DEBUG, "Port %u (PF BDF %x:%x:%x) is the 1st PF on the VIC. Allocated switch domain id %u",
2836 cur->rte_dev->data->port_id,
2837 cur_a->bus, cur_a->devid, cur_a->function,
2842 const struct rte_flow_ops enic_fm_flow_ops = {
2843 .validate = enic_fm_flow_validate,
2844 .create = enic_fm_flow_create,
2845 .destroy = enic_fm_flow_destroy,
2846 .flush = enic_fm_flow_flush,
2847 .query = enic_fm_flow_query,
2850 /* Add a high priority flow that loops representor packets to VF */
2852 enic_fm_add_rep2vf_flow(struct enic_vf_representor *vf)
2854 struct fm_tcam_match_entry *fm_tcam_entry;
2855 struct rte_flow *flow0, *flow1;
2856 struct fm_action *fm_action;
2857 struct rte_flow_error error;
2858 struct rte_flow_attr attrs;
2859 struct fm_action_op fm_op;
2860 struct enic_flowman *fm;
2866 tag = fm->vf_rep_tag;
2867 enic_fm_open_scratch(fm);
2868 fm_tcam_entry = &fm->tcam_entry;
2869 fm_action = &fm->action;
2870 /* Egress rule: match WQ ID and tag+hairpin */
2871 fm_tcam_entry->ftm_data.fk_wq_id = vf->pf_wq_idx;
2872 fm_tcam_entry->ftm_mask.fk_wq_id = 0xffff;
2873 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2874 memset(&fm_op, 0, sizeof(fm_op));
2875 fm_op.fa_op = FMOP_TAG;
2876 fm_op.tag.tag = tag;
2877 enic_fm_append_action_op(fm, &fm_op, &error);
2878 memset(&fm_op, 0, sizeof(fm_op));
2879 fm_op.fa_op = FMOP_EG_HAIRPIN;
2880 enic_fm_append_action_op(fm, &fm_op, &error);
2881 memset(&fm_op, 0, sizeof(fm_op));
2882 fm_op.fa_op = FMOP_END;
2883 enic_fm_append_action_op(fm, &fm_op, &error);
2887 attrs.priority = FM_HIGHEST_PRIORITY;
2888 flow0 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2890 enic_fm_close_scratch(fm);
2891 if (flow0 == NULL) {
2892 ENICPMD_LOG(ERR, "Cannot create flow 0 for representor->VF");
2895 LIST_INSERT_HEAD(&pf->flows, flow0, next);
2896 /* Make this flow internal, so the user app cannot delete it */
2897 flow0->internal = 1;
2898 ENICPMD_LOG(DEBUG, "representor->VF %d flow created: wq %d -> tag %d hairpin",
2899 vf->vf_id, vf->pf_wq_idx, tag);
2901 /* Ingress: steer hairpinned to VF RQ 0 */
2902 enic_fm_open_scratch(fm);
2903 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2904 fm_tcam_entry->ftm_data.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2905 fm_tcam_entry->ftm_mask.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2906 fm_tcam_entry->ftm_data.fk_packet_tag = tag;
2907 fm_tcam_entry->ftm_mask.fk_packet_tag = 0xff;
2908 memset(&fm_op, 0, sizeof(fm_op));
2909 fm_op.fa_op = FMOP_RQ_STEER;
2910 fm_op.rq_steer.rq_index = 0;
2911 fm_op.rq_steer.vnic_handle = vf->enic.fm_vnic_handle;
2912 enic_fm_append_action_op(fm, &fm_op, &error);
2913 memset(&fm_op, 0, sizeof(fm_op));
2914 fm_op.fa_op = FMOP_END;
2915 enic_fm_append_action_op(fm, &fm_op, &error);
2919 attrs.priority = FM_HIGHEST_PRIORITY;
2920 flow1 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2922 enic_fm_close_scratch(fm);
2923 if (flow1 == NULL) {
2924 ENICPMD_LOG(ERR, "Cannot create flow 1 for representor->VF");
2925 enic_fm_flow_destroy(pf->rte_dev, flow0, &error);
2928 LIST_INSERT_HEAD(&pf->flows, flow1, next);
2929 flow1->internal = 1;
2930 ENICPMD_LOG(DEBUG, "representor->VF %d flow created: tag %d hairpinned -> VF RQ %d",
2931 vf->vf_id, tag, fm_op.rq_steer.rq_index);
2932 vf->rep2vf_flow[0] = flow0;
2933 vf->rep2vf_flow[1] = flow1;
2934 /* Done with this tag, use a different one next time */
2940 * Add a low priority flow that matches all packets from VF and loops them
2941 * back to the representor.
2944 enic_fm_add_vf2rep_flow(struct enic_vf_representor *vf)
2946 struct fm_tcam_match_entry *fm_tcam_entry;
2947 struct rte_flow *flow0, *flow1;
2948 struct fm_action *fm_action;
2949 struct rte_flow_error error;
2950 struct rte_flow_attr attrs;
2951 struct fm_action_op fm_op;
2952 struct enic_flowman *fm;
2958 tag = fm->vf_rep_tag;
2959 enic_fm_open_scratch(fm);
2960 fm_tcam_entry = &fm->tcam_entry;
2961 fm_action = &fm->action;
2962 /* Egress rule: match-any and tag+hairpin */
2963 fm_tcam_entry->ftm_data.fk_wq_id = 0;
2964 fm_tcam_entry->ftm_mask.fk_wq_id = 0xffff;
2965 fm_tcam_entry->ftm_data.fk_wq_vnic = vf->enic.fm_vnic_handle;
2966 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2967 memset(&fm_op, 0, sizeof(fm_op));
2968 fm_op.fa_op = FMOP_TAG;
2969 fm_op.tag.tag = tag;
2970 enic_fm_append_action_op(fm, &fm_op, &error);
2971 memset(&fm_op, 0, sizeof(fm_op));
2972 fm_op.fa_op = FMOP_EG_HAIRPIN;
2973 enic_fm_append_action_op(fm, &fm_op, &error);
2974 memset(&fm_op, 0, sizeof(fm_op));
2975 fm_op.fa_op = FMOP_END;
2976 enic_fm_append_action_op(fm, &fm_op, &error);
2980 attrs.priority = FM_LOWEST_PRIORITY;
2981 flow0 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
2983 enic_fm_close_scratch(fm);
2984 if (flow0 == NULL) {
2985 ENICPMD_LOG(ERR, "Cannot create flow 0 for VF->representor");
2988 LIST_INSERT_HEAD(&pf->flows, flow0, next);
2989 /* Make this flow internal, so the user app cannot delete it */
2990 flow0->internal = 1;
2991 ENICPMD_LOG(DEBUG, "VF %d->representor flow created: wq %d (low prio) -> tag %d hairpin",
2992 vf->vf_id, fm_tcam_entry->ftm_data.fk_wq_id, tag);
2994 /* Ingress: steer hairpinned to VF rep RQ */
2995 enic_fm_open_scratch(fm);
2996 fm_tcam_entry->ftm_flags |= FMEF_COUNTER;
2997 fm_tcam_entry->ftm_data.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2998 fm_tcam_entry->ftm_mask.fk_hdrset[0].fk_metadata |= FKM_EG_HAIRPINNED;
2999 fm_tcam_entry->ftm_data.fk_packet_tag = tag;
3000 fm_tcam_entry->ftm_mask.fk_packet_tag = 0xff;
3001 memset(&fm_op, 0, sizeof(fm_op));
3002 fm_op.fa_op = FMOP_RQ_STEER;
3003 fm_op.rq_steer.rq_index = vf->pf_rq_sop_idx;
3004 fm_op.rq_steer.vnic_handle = pf->fm_vnic_handle;
3005 enic_fm_append_action_op(fm, &fm_op, &error);
3006 memset(&fm_op, 0, sizeof(fm_op));
3007 fm_op.fa_op = FMOP_END;
3008 enic_fm_append_action_op(fm, &fm_op, &error);
3012 attrs.priority = FM_HIGHEST_PRIORITY;
3013 flow1 = enic_fm_flow_add_entry(fm, fm_tcam_entry, fm_action,
3015 enic_fm_close_scratch(fm);
3016 if (flow1 == NULL) {
3017 ENICPMD_LOG(ERR, "Cannot create flow 1 for VF->representor");
3018 enic_fm_flow_destroy(pf->rte_dev, flow0, &error);
3021 LIST_INSERT_HEAD(&pf->flows, flow1, next);
3022 flow1->internal = 1;
3023 ENICPMD_LOG(DEBUG, "VF %d->representor flow created: tag %d hairpinned -> PF RQ %d",
3024 vf->vf_id, tag, vf->pf_rq_sop_idx);
3025 vf->vf2rep_flow[0] = flow0;
3026 vf->vf2rep_flow[1] = flow1;
3027 /* Done with this tag, use a different one next time */
3032 /* Destroy representor flows created by enic_fm_add_{rep2vf,vf2rep}_flow */
3034 delete_rep_flows(struct enic *enic)
3036 struct enic_vf_representor *vf;
3037 struct rte_flow_error error;
3038 struct rte_eth_dev *dev;
3041 RTE_ASSERT(enic_is_vf_rep(enic));
3042 vf = VF_ENIC_TO_VF_REP(enic);
3043 dev = vf->pf->rte_dev;
3044 for (i = 0; i < ARRAY_SIZE(vf->vf2rep_flow); i++) {
3045 if (vf->vf2rep_flow[i])
3046 enic_fm_flow_destroy(dev, vf->vf2rep_flow[i], &error);
3048 for (i = 0; i < ARRAY_SIZE(vf->rep2vf_flow); i++) {
3049 if (vf->rep2vf_flow[i])
3050 enic_fm_flow_destroy(dev, vf->rep2vf_flow[i], &error);
3054 static struct enic_flowman *
3055 begin_fm(struct enic *enic)
3057 struct enic_vf_representor *vf;
3058 struct enic_flowman *fm;
3060 /* Representor uses PF flowman */
3061 if (enic_is_vf_rep(enic)) {
3062 vf = VF_ENIC_TO_VF_REP(enic);
3067 /* Save the API caller and lock if representors exist */
3069 if (fm->owner_enic->switchdev_mode)
3070 rte_spinlock_lock(&fm->lock);
3071 fm->user_enic = enic;
3077 end_fm(struct enic_flowman *fm)
3079 fm->user_enic = NULL;
3080 if (fm->owner_enic->switchdev_mode)
3081 rte_spinlock_unlock(&fm->lock);