1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2017-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
13 #include <rte_tailq.h>
14 #include <rte_flow_driver.h>
18 #include "sfc_flow_rss.h"
25 * The maximum number of fully elaborated hardware filter specifications
26 * which can be produced from a template by means of multiplication, if
27 * missing match flags are needed to be taken into account
29 #define SF_FLOW_SPEC_NB_FILTERS_MAX 8
31 /* Used to guard action masks */
32 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
33 RTE_BUILD_BUG_ON((_action) >= sizeof(_set) * CHAR_BIT)
35 /* Flow engines supported by the implementation */
36 enum sfc_flow_spec_type {
37 SFC_FLOW_SPEC_FILTER = 0,
43 /* VNIC-specific flow specification */
44 struct sfc_flow_spec_filter {
45 /* partial specification from flow rule */
46 efx_filter_spec_t template;
47 /* fully elaborated hardware filters specifications */
48 efx_filter_spec_t filters[SF_FLOW_SPEC_NB_FILTERS_MAX];
49 /* number of complete specifications */
51 /* RSS context (or NULL) */
52 struct sfc_flow_rss_ctx *rss_ctx;
55 /* Indicates the role of a given flow in tunnel offload */
56 enum sfc_ft_rule_type {
57 /* The flow has nothing to do with tunnel offload */
59 /* The flow is a TUNNEL rule, to match on an outer header */
62 * The flow is a SWITCH rule, to discard the outer header
63 * and dispatch the resulting packets to a vSwitch tenant
68 /* MAE-specific flow specification */
69 struct sfc_flow_spec_mae {
70 /* FLow Tunnel (FT) rule type (or NONE) */
71 enum sfc_ft_rule_type ft_rule_type;
72 /* Flow Tunnel (FT) context (or NULL) */
73 struct sfc_ft_ctx *ft_ctx;
74 /* Desired priority level */
75 unsigned int priority;
76 /* Outer rule registry entry */
77 struct sfc_mae_outer_rule *outer_rule;
78 /* EFX match specification */
79 efx_mae_match_spec_t *match_spec;
80 /* Action set registry entry */
81 struct sfc_mae_action_set *action_set;
82 /* Firmware-allocated rule ID */
83 efx_mae_rule_id_t rule_id;
86 /* Flow specification */
87 struct sfc_flow_spec {
88 /* Flow specification type (engine-based) */
89 enum sfc_flow_spec_type type;
93 /* Filter-based (VNIC level flows) specification */
94 struct sfc_flow_spec_filter filter;
95 /* MAE-based (lower-level HW switch flows) specification */
96 struct sfc_flow_spec_mae mae;
100 /* PMD-specific definition of the opaque type from rte_flow.h */
102 struct sfc_flow_spec spec; /* flow specification */
103 TAILQ_ENTRY(rte_flow) entries; /* flow list entries */
106 TAILQ_HEAD(sfc_flow_list, rte_flow);
108 extern const struct rte_flow_ops sfc_flow_ops;
110 enum sfc_flow_item_layers {
111 SFC_FLOW_ITEM_ANY_LAYER,
112 SFC_FLOW_ITEM_START_LAYER,
118 /* Flow parse context types */
119 enum sfc_flow_parse_ctx_type {
120 SFC_FLOW_PARSE_CTX_FILTER = 0,
121 SFC_FLOW_PARSE_CTX_MAE,
123 SFC_FLOW_PARSE_CTX_NTYPES
126 /* Flow parse context */
127 struct sfc_flow_parse_ctx {
128 enum sfc_flow_parse_ctx_type type;
132 /* Context pointer valid for filter-based (VNIC) flows */
133 efx_filter_spec_t *filter;
134 /* Context pointer valid for MAE-based flows */
135 struct sfc_mae_parse_ctx *mae;
139 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
140 struct sfc_flow_parse_ctx *parse_ctx,
141 struct rte_flow_error *error);
143 struct sfc_flow_item {
144 enum rte_flow_item_type type; /* Type of item */
145 const char *name; /* Item name */
146 enum sfc_flow_item_layers layer; /* Layer of item */
147 enum sfc_flow_item_layers prev_layer; /* Previous layer of item */
148 enum sfc_flow_parse_ctx_type ctx_type; /* Parse context type */
149 sfc_flow_item_parse *parse; /* Parsing function */
154 int sfc_flow_parse_pattern(struct sfc_adapter *sa,
155 const struct sfc_flow_item *flow_items,
156 unsigned int nb_flow_items,
157 const struct rte_flow_item pattern[],
158 struct sfc_flow_parse_ctx *parse_ctx,
159 struct rte_flow_error *error);
161 int sfc_flow_parse_init(const struct rte_flow_item *item,
162 const void **spec_ptr,
163 const void **mask_ptr,
164 const void *supp_mask,
165 const void *def_mask,
167 struct rte_flow_error *error);
169 void sfc_flow_init(struct sfc_adapter *sa);
170 void sfc_flow_fini(struct sfc_adapter *sa);
171 int sfc_flow_start(struct sfc_adapter *sa);
172 void sfc_flow_stop(struct sfc_adapter *sa);
174 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
175 const struct rte_flow_item items[],
176 const struct rte_flow_action actions[],
177 struct rte_flow *flow,
178 struct rte_flow_error *error);
180 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
181 struct rte_flow *flow);
183 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
184 struct rte_flow *flow);
186 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
187 struct rte_flow *flow);
189 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
190 struct rte_flow *flow);
192 typedef int (sfc_flow_query_cb_t)(struct rte_eth_dev *dev,
193 struct rte_flow *flow,
194 const struct rte_flow_action *action,
196 struct rte_flow_error *error);
201 #endif /* _SFC_FLOW_H */