1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Mellanox Technologies, Ltd
5 #ifndef RTE_PMD_MLX5_FLOW_H_
6 #define RTE_PMD_MLX5_FLOW_H_
8 #include <netinet/in.h>
15 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
17 #pragma GCC diagnostic ignored "-Wpedantic"
19 #include <infiniband/verbs.h>
21 #pragma GCC diagnostic error "-Wpedantic"
24 /* Pattern outer Layer bits. */
25 #define MLX5_FLOW_LAYER_OUTER_L2 (1u << 0)
26 #define MLX5_FLOW_LAYER_OUTER_L3_IPV4 (1u << 1)
27 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6 (1u << 2)
28 #define MLX5_FLOW_LAYER_OUTER_L4_UDP (1u << 3)
29 #define MLX5_FLOW_LAYER_OUTER_L4_TCP (1u << 4)
30 #define MLX5_FLOW_LAYER_OUTER_VLAN (1u << 5)
32 /* Pattern inner Layer bits. */
33 #define MLX5_FLOW_LAYER_INNER_L2 (1u << 6)
34 #define MLX5_FLOW_LAYER_INNER_L3_IPV4 (1u << 7)
35 #define MLX5_FLOW_LAYER_INNER_L3_IPV6 (1u << 8)
36 #define MLX5_FLOW_LAYER_INNER_L4_UDP (1u << 9)
37 #define MLX5_FLOW_LAYER_INNER_L4_TCP (1u << 10)
38 #define MLX5_FLOW_LAYER_INNER_VLAN (1u << 11)
40 /* Pattern tunnel Layer bits. */
41 #define MLX5_FLOW_LAYER_VXLAN (1u << 12)
42 #define MLX5_FLOW_LAYER_VXLAN_GPE (1u << 13)
43 #define MLX5_FLOW_LAYER_GRE (1u << 14)
44 #define MLX5_FLOW_LAYER_MPLS (1u << 15)
47 #define MLX5_FLOW_LAYER_OUTER_L3 \
48 (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
49 #define MLX5_FLOW_LAYER_OUTER_L4 \
50 (MLX5_FLOW_LAYER_OUTER_L4_UDP | MLX5_FLOW_LAYER_OUTER_L4_TCP)
51 #define MLX5_FLOW_LAYER_OUTER \
52 (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_OUTER_L3 | \
53 MLX5_FLOW_LAYER_OUTER_L4)
56 #define MLX5_FLOW_LAYER_TUNNEL \
57 (MLX5_FLOW_LAYER_VXLAN | MLX5_FLOW_LAYER_VXLAN_GPE | \
58 MLX5_FLOW_LAYER_GRE | MLX5_FLOW_LAYER_MPLS)
61 #define MLX5_FLOW_LAYER_INNER_L3 \
62 (MLX5_FLOW_LAYER_INNER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
63 #define MLX5_FLOW_LAYER_INNER_L4 \
64 (MLX5_FLOW_LAYER_INNER_L4_UDP | MLX5_FLOW_LAYER_INNER_L4_TCP)
65 #define MLX5_FLOW_LAYER_INNER \
66 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3 | \
67 MLX5_FLOW_LAYER_INNER_L4)
69 /* Actions that modify the fate of matching traffic. */
70 #define MLX5_FLOW_FATE_DROP (1u << 0)
71 #define MLX5_FLOW_FATE_QUEUE (1u << 1)
72 #define MLX5_FLOW_FATE_RSS (1u << 2)
74 /* Modify a packet. */
75 #define MLX5_FLOW_MOD_FLAG (1u << 0)
76 #define MLX5_FLOW_MOD_MARK (1u << 1)
77 #define MLX5_FLOW_MOD_COUNT (1u << 2)
80 #define MLX5_FLOW_ACTION_DROP (1u << 0)
81 #define MLX5_FLOW_ACTION_QUEUE (1u << 1)
82 #define MLX5_FLOW_ACTION_RSS (1u << 2)
83 #define MLX5_FLOW_ACTION_FLAG (1u << 3)
84 #define MLX5_FLOW_ACTION_MARK (1u << 4)
85 #define MLX5_FLOW_ACTION_COUNT (1u << 5)
87 #define MLX5_FLOW_FATE_ACTIONS \
88 (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
91 #define IPPROTO_MPLS 137
94 /* Priority reserved for default flows. */
95 #define MLX5_FLOW_PRIO_RSVD ((uint32_t)-1)
98 * Number of sub priorities.
99 * For each kind of pattern matching i.e. L2, L3, L4 to have a correct
100 * matching on the NIC (firmware dependent) L4 most have the higher priority
101 * followed by L3 and ending with L2.
103 #define MLX5_PRIORITY_MAP_L2 2
104 #define MLX5_PRIORITY_MAP_L3 1
105 #define MLX5_PRIORITY_MAP_L4 0
106 #define MLX5_PRIORITY_MAP_MAX 3
108 /* Max number of actions per DV flow. */
109 #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
111 /* Verbs specification header. */
112 struct ibv_spec_header {
113 enum ibv_flow_spec_type type;
117 /** Handles information leading to a drop fate. */
118 struct mlx5_flow_verbs {
119 LIST_ENTRY(mlx5_flow_verbs) next;
120 unsigned int size; /**< Size of the attribute. */
122 struct ibv_flow_attr *attr;
123 /**< Pointer to the Specification buffer. */
124 uint8_t *specs; /**< Pointer to the specifications. */
126 struct ibv_flow *flow; /**< Verbs flow pointer. */
127 struct mlx5_hrxq *hrxq; /**< Hash Rx queue object. */
128 uint64_t hash_fields; /**< Verbs hash Rx queue hash fields. */
131 /** Device flow structure. */
133 LIST_ENTRY(mlx5_flow) next;
134 struct rte_flow *flow; /**< Pointer to the main flow. */
135 uint32_t layers; /**< Bit-fields that holds the detected layers. */
137 struct mlx5_flow_verbs verbs; /**< Holds the verbs dev-flow. */
141 /* Counters information. */
142 struct mlx5_flow_counter {
143 LIST_ENTRY(mlx5_flow_counter) next; /**< Pointer to the next counter. */
144 uint32_t shared:1; /**< Share counter ID with other flow rules. */
145 uint32_t ref_cnt:31; /**< Reference counter. */
146 uint32_t id; /**< Counter ID. */
147 struct ibv_counter_set *cs; /**< Holds the counters for the rule. */
148 uint64_t hits; /**< Number of packets matched by the rule. */
149 uint64_t bytes; /**< Number of bytes matched by the rule. */
152 /* Flow structure. */
154 TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */
155 struct rte_flow_attr attributes; /**< User flow attribute. */
157 /**< Bit-fields of present layers see MLX5_FLOW_LAYER_*. */
158 struct mlx5_flow_counter *counter; /**< Holds flow counter. */
159 struct rte_flow_action_rss rss;/**< RSS context. */
160 uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */
161 uint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */
162 void *nl_flow; /**< Netlink flow buffer if relevant. */
163 LIST_HEAD(dev_flows, mlx5_flow) dev_flows;
164 /**< Device flows that are part of the flow. */
165 uint32_t actions; /**< Bit-fields which mark all detected actions. */
167 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev,
168 const struct rte_flow_attr *attr,
169 const struct rte_flow_item items[],
170 const struct rte_flow_action actions[],
171 struct rte_flow_error *error);
172 typedef struct mlx5_flow *(*mlx5_flow_prepare_t)
173 (const struct rte_flow_attr *attr, const struct rte_flow_item items[],
174 const struct rte_flow_action actions[], uint64_t *item_flags,
175 uint64_t *action_flags, struct rte_flow_error *error);
176 typedef int (*mlx5_flow_translate_t)(struct rte_eth_dev *dev,
177 struct mlx5_flow *dev_flow,
178 const struct rte_flow_attr *attr,
179 const struct rte_flow_item items[],
180 const struct rte_flow_action actions[],
181 struct rte_flow_error *error);
182 typedef int (*mlx5_flow_apply_t)(struct rte_eth_dev *dev, struct rte_flow *flow,
183 struct rte_flow_error *error);
184 typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev,
185 struct rte_flow *flow);
186 typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev,
187 struct rte_flow *flow);
188 struct mlx5_flow_driver_ops {
189 mlx5_flow_validate_t validate;
190 mlx5_flow_prepare_t prepare;
191 mlx5_flow_translate_t translate;
192 mlx5_flow_apply_t apply;
193 mlx5_flow_remove_t remove;
194 mlx5_flow_destroy_t destroy;
199 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
200 uint32_t subpriority);
201 int mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
202 struct rte_flow_error *error);
203 int mlx5_flow_validate_action_drop(uint64_t action_flags,
204 struct rte_flow_error *error);
205 int mlx5_flow_validate_action_flag(uint64_t action_flags,
206 struct rte_flow_error *error);
207 int mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
208 uint64_t action_flags,
209 struct rte_flow_error *error);
210 int mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
211 uint64_t action_flags,
212 struct rte_eth_dev *dev,
213 struct rte_flow_error *error);
214 int mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
215 uint64_t action_flags,
216 struct rte_eth_dev *dev,
217 struct rte_flow_error *error);
218 int mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
219 const struct rte_flow_attr *attributes,
220 struct rte_flow_error *error);
221 int mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
223 struct rte_flow_error *error);
224 int mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
226 uint8_t target_protocol,
227 struct rte_flow_error *error);
228 int mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
230 struct rte_flow_error *error);
231 int mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
233 struct rte_flow_error *error);
234 int mlx5_flow_validate_item_mpls(const struct rte_flow_item *item,
236 uint8_t target_protocol,
237 struct rte_flow_error *error);
238 int mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
240 uint8_t target_protocol,
241 struct rte_flow_error *error);
242 int mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
244 uint8_t target_protocol,
245 struct rte_flow_error *error);
246 int mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
248 struct rte_flow_error *error);
249 int mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
251 struct rte_flow_error *error);
252 int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
254 struct rte_eth_dev *dev,
255 struct rte_flow_error *error);
256 void mlx5_flow_init_driver_ops(struct rte_eth_dev *dev);
259 void mlx5_flow_dv_get_driver_ops(struct mlx5_flow_driver_ops *flow_ops);
261 /* mlx5_flow_verbs.c */
263 void mlx5_flow_verbs_get_driver_ops(struct mlx5_flow_driver_ops *flow_ops);
265 #endif /* RTE_PMD_MLX5_FLOW_H_ */