xref: /dpdk/drivers/net/sfc/sfc_flow.h (revision 596419445de61e76c2d96e878a16dafc0749652c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2017-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9 
10 #ifndef _SFC_FLOW_H
11 #define _SFC_FLOW_H
12 
13 #include <stdbool.h>
14 
15 #include <rte_tailq.h>
16 #include <rte_flow_driver.h>
17 
18 #include "efx.h"
19 
20 #include "sfc_flow_rss.h"
21 #include "sfc_mae_ct.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /*
28  * The maximum number of fully elaborated hardware filter specifications
29  * which can be produced from a template by means of multiplication, if
30  * missing match flags are needed to be taken into account
31  */
32 #define SF_FLOW_SPEC_NB_FILTERS_MAX 8
33 
34 /* Used to guard action masks */
35 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
36 	RTE_BUILD_BUG_ON((_action) >= sizeof(_set) * CHAR_BIT)
37 
38 /* Flow engines supported by the implementation */
39 enum sfc_flow_spec_type {
40 	SFC_FLOW_SPEC_FILTER = 0,
41 	SFC_FLOW_SPEC_MAE,
42 
43 	SFC_FLOW_SPEC_NTYPES
44 };
45 
46 /* VNIC-specific flow specification */
47 struct sfc_flow_spec_filter {
48 	/* partial specification from flow rule */
49 	efx_filter_spec_t template;
50 	/* fully elaborated hardware filters specifications */
51 	efx_filter_spec_t filters[SF_FLOW_SPEC_NB_FILTERS_MAX];
52 	/* number of complete specifications */
53 	unsigned int count;
54 	/* RSS context (or NULL) */
55 	struct sfc_flow_rss_ctx *rss_ctx;
56 };
57 
58 /* Indicates the role of a given flow in tunnel offload */
59 enum sfc_ft_rule_type {
60 	/* The flow has nothing to do with tunnel offload */
61 	SFC_FT_RULE_NONE = 0,
62 	/* The flow is a TUNNEL rule, to match on an outer header */
63 	SFC_FT_RULE_TUNNEL,
64 	/*
65 	 * The flow is a SWITCH rule, to discard the outer header
66 	 * and dispatch the resulting packets to a vSwitch tenant
67 	 */
68 	SFC_FT_RULE_SWITCH,
69 };
70 
71 /* MAE-specific flow specification */
72 struct sfc_flow_spec_mae {
73 	/* FLow Tunnel (FT) rule type (or NONE) */
74 	enum sfc_ft_rule_type		ft_rule_type;
75 	/* Flow Tunnel (FT) context (or NULL) */
76 	struct sfc_ft_ctx		*ft_ctx;
77 	/* Desired priority level */
78 	unsigned int			priority;
79 	/*
80 	 * Outer rule registry entry (points to below action_rule->outer_rule
81 	 * when action_rule is not NULL; self-sufficient entry otherwise)
82 	 */
83 	struct sfc_mae_outer_rule	*outer_rule;
84 	/* Action rule registry entry */
85 	struct sfc_mae_action_rule	*action_rule;
86 	/* Conntrack (CT) assistance table entry key and response */
87 	sfc_mae_conntrack_response_t	ct_resp;
88 	sfc_mae_conntrack_key_t		ct_key;
89 	/* Conntrack (CT) assistance counter */
90 	struct sfc_mae_counter		*ct_counter;
91 };
92 
93 /* PMD-specific definition of the opaque type from rte_flow.h */
94 struct rte_flow_action_handle {
95 	TAILQ_ENTRY(rte_flow_action_handle)	entries;
96 
97 	bool					transfer;
98 	enum rte_flow_action_type		type;
99 
100 	union {
101 		struct sfc_mae_encap_header	*encap_header;
102 		struct sfc_mae_counter		*counter;
103 	};
104 };
105 
106 TAILQ_HEAD(sfc_flow_indir_actions, rte_flow_action_handle);
107 
108 /* Flow specification */
109 struct sfc_flow_spec {
110 	/* Flow specification type (engine-based) */
111 	enum sfc_flow_spec_type type;
112 
113 	union {
114 		/* Filter-based (VNIC level flows) specification */
115 		struct sfc_flow_spec_filter filter;
116 		/* MAE-based (lower-level HW switch flows) specification */
117 		struct sfc_flow_spec_mae mae;
118 	};
119 };
120 
121 /* PMD-specific definition of the opaque type from rte_flow.h */
122 struct rte_flow {
123 	struct sfc_flow_spec spec;	/* flow specification */
124 	TAILQ_ENTRY(rte_flow) entries;	/* flow list entries */
125 	bool internal;			/* true for internal rules */
126 };
127 
128 TAILQ_HEAD(sfc_flow_list, rte_flow);
129 
130 extern const struct rte_flow_ops sfc_flow_ops;
131 
132 enum sfc_flow_item_layers {
133 	SFC_FLOW_ITEM_ANY_LAYER,
134 	SFC_FLOW_ITEM_START_LAYER,
135 	SFC_FLOW_ITEM_L2,
136 	SFC_FLOW_ITEM_L3,
137 	SFC_FLOW_ITEM_L4,
138 };
139 
140 /* Flow parse context types */
141 enum sfc_flow_parse_ctx_type {
142 	SFC_FLOW_PARSE_CTX_FILTER = 0,
143 	SFC_FLOW_PARSE_CTX_MAE,
144 
145 	SFC_FLOW_PARSE_CTX_NTYPES
146 };
147 
148 /* Flow parse context */
149 struct sfc_flow_parse_ctx {
150 	enum sfc_flow_parse_ctx_type type;
151 
152 	union {
153 		/* Context pointer valid for filter-based (VNIC) flows */
154 		efx_filter_spec_t *filter;
155 		/* Context pointer valid for MAE-based flows */
156 		struct sfc_mae_parse_ctx *mae;
157 	};
158 };
159 
160 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
161 				  struct sfc_flow_parse_ctx *parse_ctx,
162 				  struct rte_flow_error *error);
163 
164 struct sfc_flow_item {
165 	enum rte_flow_item_type type;		/* Type of item */
166 	const char *name;			/* Item name */
167 	enum sfc_flow_item_layers layer;	/* Layer of item */
168 	enum sfc_flow_item_layers prev_layer;	/* Previous layer of item */
169 	enum sfc_flow_parse_ctx_type ctx_type;	/* Parse context type */
170 	sfc_flow_item_parse *parse;		/* Parsing function */
171 };
172 
173 struct sfc_adapter;
174 
175 int sfc_flow_parse_pattern(struct sfc_adapter *sa,
176 			   const struct sfc_flow_item *flow_items,
177 			   unsigned int nb_flow_items,
178 			   const struct rte_flow_item pattern[],
179 			   struct sfc_flow_parse_ctx *parse_ctx,
180 			   struct rte_flow_error *error);
181 
182 int sfc_flow_parse_init(const struct rte_flow_item *item,
183 			const void **spec_ptr,
184 			const void **mask_ptr,
185 			const void *supp_mask,
186 			const void *def_mask,
187 			unsigned int size,
188 			struct rte_flow_error *error);
189 
190 void sfc_flow_init(struct sfc_adapter *sa);
191 void sfc_flow_fini(struct sfc_adapter *sa);
192 int sfc_flow_start(struct sfc_adapter *sa);
193 void sfc_flow_stop(struct sfc_adapter *sa);
194 
195 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
196 				  const struct rte_flow_item items[],
197 				  const struct rte_flow_action actions[],
198 				  struct rte_flow *flow,
199 				  struct rte_flow_error *error);
200 
201 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
202 				   struct rte_flow *flow);
203 
204 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
205 				     struct rte_flow *flow);
206 
207 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
208 				   struct rte_flow *flow);
209 
210 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
211 				   struct rte_flow *flow);
212 
213 typedef int (sfc_flow_query_cb_t)(struct rte_eth_dev *dev,
214 				  struct rte_flow *flow,
215 				  const struct rte_flow_action *action,
216 				  void *data,
217 				  struct rte_flow_error *error);
218 
219 struct rte_flow *sfc_flow_create_locked(struct sfc_adapter *sa, bool internal,
220 					const struct rte_flow_attr *attr,
221 					const struct rte_flow_item pattern[],
222 					const struct rte_flow_action actions[],
223 					struct rte_flow_error *error);
224 
225 int sfc_flow_destroy_locked(struct sfc_adapter *sa, struct rte_flow *flow,
226 			    struct rte_flow_error *error);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif /* _SFC_FLOW_H */
232