xref: /dpdk/drivers/net/sfc/sfc_flow.h (revision 42a8fc7daa46256d150278fc9a7a846e27945a0c)
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 <rte_tailq.h>
14 #include <rte_flow_driver.h>
15 
16 #include "efx.h"
17 
18 #include "sfc_flow_rss.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /*
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
28  */
29 #define SF_FLOW_SPEC_NB_FILTERS_MAX 8
30 
31 /* Used to guard action masks */
32 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
33 	RTE_BUILD_BUG_ON((_action) >= sizeof(_set) * CHAR_BIT)
34 
35 /* Flow engines supported by the implementation */
36 enum sfc_flow_spec_type {
37 	SFC_FLOW_SPEC_FILTER = 0,
38 	SFC_FLOW_SPEC_MAE,
39 
40 	SFC_FLOW_SPEC_NTYPES
41 };
42 
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 */
50 	unsigned int count;
51 	/* RSS context (or NULL) */
52 	struct sfc_flow_rss_ctx *rss_ctx;
53 };
54 
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 */
58 	SFC_FT_RULE_NONE = 0,
59 	/* The flow is a TUNNEL rule, to match on an outer header */
60 	SFC_FT_RULE_TUNNEL,
61 	/*
62 	 * The flow is a SWITCH rule, to discard the outer header
63 	 * and dispatch the resulting packets to a vSwitch tenant
64 	 */
65 	SFC_FT_RULE_SWITCH,
66 };
67 
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;
84 };
85 
86 /* Flow specification */
87 struct sfc_flow_spec {
88 	/* Flow specification type (engine-based) */
89 	enum sfc_flow_spec_type type;
90 
91 	RTE_STD_C11
92 	union {
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;
97 	};
98 };
99 
100 /* PMD-specific definition of the opaque type from rte_flow.h */
101 struct rte_flow {
102 	struct sfc_flow_spec spec;	/* flow specification */
103 	TAILQ_ENTRY(rte_flow) entries;	/* flow list entries */
104 };
105 
106 TAILQ_HEAD(sfc_flow_list, rte_flow);
107 
108 extern const struct rte_flow_ops sfc_flow_ops;
109 
110 enum sfc_flow_item_layers {
111 	SFC_FLOW_ITEM_ANY_LAYER,
112 	SFC_FLOW_ITEM_START_LAYER,
113 	SFC_FLOW_ITEM_L2,
114 	SFC_FLOW_ITEM_L3,
115 	SFC_FLOW_ITEM_L4,
116 };
117 
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,
122 
123 	SFC_FLOW_PARSE_CTX_NTYPES
124 };
125 
126 /* Flow parse context */
127 struct sfc_flow_parse_ctx {
128 	enum sfc_flow_parse_ctx_type type;
129 
130 	RTE_STD_C11
131 	union {
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;
136 	};
137 };
138 
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);
142 
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 */
150 };
151 
152 struct sfc_adapter;
153 
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);
160 
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,
166 			unsigned int size,
167 			struct rte_flow_error *error);
168 
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);
173 
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);
179 
180 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
181 				   struct rte_flow *flow);
182 
183 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
184 				     struct rte_flow *flow);
185 
186 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
187 				   struct rte_flow *flow);
188 
189 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
190 				   struct rte_flow *flow);
191 
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,
195 				  void *data,
196 				  struct rte_flow_error *error);
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif /* _SFC_FLOW_H */
202