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_flow_tunnel_rule_type {
57 /* The flow has nothing to do with tunnel offload */
59 /* The flow represents a JUMP rule */
61 /* The flow represents a GROUP rule */
65 /* MAE-specific flow specification */
66 struct sfc_flow_spec_mae {
67 /* FLow Tunnel (FT) rule type (or NONE) */
68 enum sfc_flow_tunnel_rule_type ft_rule_type;
69 /* Flow Tunnel (FT) context (or NULL) */
70 struct sfc_flow_tunnel *ft;
71 /* Desired priority level */
72 unsigned int priority;
73 /* Outer rule registry entry */
74 struct sfc_mae_outer_rule *outer_rule;
75 /* EFX match specification */
76 efx_mae_match_spec_t *match_spec;
77 /* Action set registry entry */
78 struct sfc_mae_action_set *action_set;
79 /* Firmware-allocated rule ID */
80 efx_mae_rule_id_t rule_id;
83 /* Flow specification */
84 struct sfc_flow_spec {
85 /* Flow specification type (engine-based) */
86 enum sfc_flow_spec_type type;
90 /* Filter-based (VNIC level flows) specification */
91 struct sfc_flow_spec_filter filter;
92 /* MAE-based (lower-level HW switch flows) specification */
93 struct sfc_flow_spec_mae mae;
97 /* PMD-specific definition of the opaque type from rte_flow.h */
99 struct sfc_flow_spec spec; /* flow specification */
100 TAILQ_ENTRY(rte_flow) entries; /* flow list entries */
103 TAILQ_HEAD(sfc_flow_list, rte_flow);
105 extern const struct rte_flow_ops sfc_flow_ops;
107 enum sfc_flow_item_layers {
108 SFC_FLOW_ITEM_ANY_LAYER,
109 SFC_FLOW_ITEM_START_LAYER,
115 /* Flow parse context types */
116 enum sfc_flow_parse_ctx_type {
117 SFC_FLOW_PARSE_CTX_FILTER = 0,
118 SFC_FLOW_PARSE_CTX_MAE,
120 SFC_FLOW_PARSE_CTX_NTYPES
123 /* Flow parse context */
124 struct sfc_flow_parse_ctx {
125 enum sfc_flow_parse_ctx_type type;
129 /* Context pointer valid for filter-based (VNIC) flows */
130 efx_filter_spec_t *filter;
131 /* Context pointer valid for MAE-based flows */
132 struct sfc_mae_parse_ctx *mae;
136 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
137 struct sfc_flow_parse_ctx *parse_ctx,
138 struct rte_flow_error *error);
140 struct sfc_flow_item {
141 enum rte_flow_item_type type; /* Type of item */
142 const char *name; /* Item name */
143 enum sfc_flow_item_layers layer; /* Layer of item */
144 enum sfc_flow_item_layers prev_layer; /* Previous layer of item */
145 enum sfc_flow_parse_ctx_type ctx_type; /* Parse context type */
146 sfc_flow_item_parse *parse; /* Parsing function */
151 int sfc_flow_parse_pattern(struct sfc_adapter *sa,
152 const struct sfc_flow_item *flow_items,
153 unsigned int nb_flow_items,
154 const struct rte_flow_item pattern[],
155 struct sfc_flow_parse_ctx *parse_ctx,
156 struct rte_flow_error *error);
158 int sfc_flow_parse_init(const struct rte_flow_item *item,
159 const void **spec_ptr,
160 const void **mask_ptr,
161 const void *supp_mask,
162 const void *def_mask,
164 struct rte_flow_error *error);
166 void sfc_flow_init(struct sfc_adapter *sa);
167 void sfc_flow_fini(struct sfc_adapter *sa);
168 int sfc_flow_start(struct sfc_adapter *sa);
169 void sfc_flow_stop(struct sfc_adapter *sa);
171 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
172 const struct rte_flow_item items[],
173 const struct rte_flow_action actions[],
174 struct rte_flow *flow,
175 struct rte_flow_error *error);
177 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
178 struct rte_flow *flow);
180 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
181 struct rte_flow *flow);
183 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
184 struct rte_flow *flow);
186 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
187 struct rte_flow *flow);
189 typedef int (sfc_flow_query_cb_t)(struct rte_eth_dev *dev,
190 struct rte_flow *flow,
191 const struct rte_flow_action *action,
193 struct rte_flow_error *error);
198 #endif /* _SFC_FLOW_H */