1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
15 #include <rte_spinlock.h>
19 #include "sfc_stats.h"
25 /** FW-allocatable resource context */
26 struct sfc_mae_fw_rsrc {
30 efx_mae_aset_id_t aset_id;
31 efx_mae_rule_id_t rule_id;
32 efx_mae_eh_id_t eh_id;
36 /** Outer rule registry entry */
37 struct sfc_mae_outer_rule {
38 TAILQ_ENTRY(sfc_mae_outer_rule) entries;
40 efx_mae_match_spec_t *match_spec;
41 efx_tunnel_protocol_t encap_type;
42 struct sfc_mae_fw_rsrc fw_rsrc;
45 TAILQ_HEAD(sfc_mae_outer_rules, sfc_mae_outer_rule);
47 /** Encap. header registry entry */
48 struct sfc_mae_encap_header {
49 TAILQ_ENTRY(sfc_mae_encap_header) entries;
53 efx_tunnel_protocol_t type;
54 struct sfc_mae_fw_rsrc fw_rsrc;
57 TAILQ_HEAD(sfc_mae_encap_headers, sfc_mae_encap_header);
60 struct sfc_mae_counter_id {
61 /* ID of a counter in MAE */
63 /* ID of a counter in RTE */
67 /** Action set registry entry */
68 struct sfc_mae_action_set {
69 TAILQ_ENTRY(sfc_mae_action_set) entries;
71 struct sfc_mae_counter_id *counters;
73 efx_mae_actions_t *spec;
74 struct sfc_mae_encap_header *encap_header;
75 struct sfc_mae_fw_rsrc fw_rsrc;
78 TAILQ_HEAD(sfc_mae_action_sets, sfc_mae_action_set);
80 /** Options for MAE support status */
82 SFC_MAE_STATUS_UNKNOWN = 0,
83 SFC_MAE_STATUS_UNSUPPORTED,
84 SFC_MAE_STATUS_SUPPORTED
88 * Encap. header bounce buffer. It is used to store header data
89 * when parsing the header definition in the action VXLAN_ENCAP.
91 struct sfc_mae_bounce_eh {
95 efx_tunnel_protocol_t type;
98 /** Counter collection entry */
99 struct sfc_mae_counter {
101 uint32_t generation_count;
102 union sfc_pkts_bytes value;
103 union sfc_pkts_bytes reset;
106 struct sfc_mae_counters_xstats {
107 uint64_t not_inuse_update;
108 uint64_t realloc_update;
111 struct sfc_mae_counters {
112 /** An array of all MAE counters */
113 struct sfc_mae_counter *mae_counters;
114 /** Extra statistics for counters */
115 struct sfc_mae_counters_xstats xstats;
116 /** Count of all MAE counters */
117 unsigned int n_mae_counters;
120 struct sfc_mae_counter_registry {
121 /* Common counter information */
122 /** Counters collection */
123 struct sfc_mae_counters counters;
125 /* Information used by counter update service */
126 /** Callback to get packets from RxQ */
127 eth_rx_burst_t rx_pkt_burst;
128 /** Data for the callback to get packets */
129 struct sfc_dp_rxq *rx_dp;
130 /** Number of buffers pushed to the RxQ */
131 unsigned int pushed_n_buffers;
132 /** Are credits used by counter stream */
135 /* Information used by configuration routines */
136 /** Counter service core ID */
137 uint32_t service_core_id;
138 /** Counter service ID */
143 * MAE rules used to capture traffic generated by VFs and direct it to
144 * representors (one for each VF).
146 #define SFC_MAE_NB_REPR_RULES_MAX (64)
148 /** Rules to forward traffic from PHY port to PF and from PF to PHY port */
149 #define SFC_MAE_NB_SWITCHDEV_RULES (2)
150 /** Maximum required internal MAE rules */
151 #define SFC_MAE_NB_RULES_MAX (SFC_MAE_NB_SWITCHDEV_RULES + \
152 SFC_MAE_NB_REPR_RULES_MAX)
154 struct sfc_mae_rule {
155 efx_mae_match_spec_t *spec;
156 efx_mae_actions_t *actions;
157 efx_mae_aset_id_t action_set;
158 efx_mae_rule_id_t rule_id;
161 struct sfc_mae_internal_rules {
163 * Rules required to sustain switchdev mode or to provide
164 * port representor functionality.
166 struct sfc_mae_rule rules[SFC_MAE_NB_RULES_MAX];
170 /** Assigned switch domain identifier */
171 uint16_t switch_domain_id;
172 /** Assigned switch port identifier */
173 uint16_t switch_port_id;
174 /** NIC support for MAE status */
175 enum sfc_mae_status status;
176 /** Priority level limit for MAE outer rules */
177 unsigned int nb_outer_rule_prios_max;
178 /** Priority level limit for MAE action rules */
179 unsigned int nb_action_rule_prios_max;
180 /** Encapsulation support status */
181 uint32_t encap_types_supported;
182 /** Outer rule registry */
183 struct sfc_mae_outer_rules outer_rules;
184 /** Encap. header registry */
185 struct sfc_mae_encap_headers encap_headers;
186 /** Action set registry */
187 struct sfc_mae_action_sets action_sets;
188 /** Encap. header bounce buffer */
189 struct sfc_mae_bounce_eh bounce_eh;
190 /** Flag indicating whether counter-only RxQ is running */
191 bool counter_rxq_running;
192 /** Counter registry */
193 struct sfc_mae_counter_registry counter_registry;
194 /** Driver-internal flow rules */
195 struct sfc_mae_internal_rules internal_rules;
197 * Switchdev default rules. They forward traffic from PHY port
198 * to PF and vice versa.
200 struct sfc_mae_rule *switchdev_rule_pf_to_ext;
201 struct sfc_mae_rule *switchdev_rule_ext_to_pf;
205 struct sfc_flow_spec;
207 /** This implementation supports double-tagging */
208 #define SFC_MAE_MATCH_VLAN_MAX_NTAGS (2)
210 /** It is possible to keep track of one item ETH and two items VLAN */
211 #define SFC_MAE_L2_MAX_NITEMS (SFC_MAE_MATCH_VLAN_MAX_NTAGS + 1)
213 /** Auxiliary entry format to keep track of L2 "type" ("inner_type") */
214 struct sfc_mae_ethertype {
219 struct sfc_mae_pattern_data {
221 * Keeps track of "type" ("inner_type") mask and value for each
222 * parsed L2 item in a pattern. These values/masks get filled
223 * in MAE match specification at the end of parsing. Also, this
224 * information is used to conduct consistency checks:
226 * - If an item ETH is followed by a single item VLAN,
227 * the former must have "type" set to one of supported
228 * TPID values (0x8100, 0x88a8, 0x9100, 0x9200, 0x9300),
231 * - If an item ETH is followed by two items VLAN, the
232 * item ETH must have "type" set to one of supported TPID
233 * values (0x88a8, 0x9100, 0x9200, 0x9300), or 0x0000/0x0000,
234 * and the outermost VLAN item must have "inner_type" set
235 * to TPID value 0x8100, or 0x0000/0x0000
237 * - If a L2 item is followed by a L3 one, the former must
238 * indicate "type" ("inner_type") which corresponds to
239 * the protocol used in the L3 item, or 0x0000/0x0000.
241 * In turn, mapping between RTE convention (above requirements) and
242 * MAE fields is non-trivial. The following scheme indicates
243 * which item EtherTypes go to which MAE fields in the case
246 * ETH (0x8100) --> VLAN0_PROTO_BE
247 * VLAN (L3 EtherType) --> ETHER_TYPE_BE
249 * Similarly, in the case of double tagging:
251 * ETH (0x88a8) --> VLAN0_PROTO_BE
252 * VLAN (0x8100) --> VLAN1_PROTO_BE
253 * VLAN (L3 EtherType) --> ETHER_TYPE_BE
255 struct sfc_mae_ethertype ethertypes[SFC_MAE_L2_MAX_NITEMS];
257 rte_be16_t tci_masks[SFC_MAE_MATCH_VLAN_MAX_NTAGS];
259 unsigned int nb_vlan_tags;
262 * L3 requirement for the innermost L2 item's "type" ("inner_type").
263 * This contains one of:
264 * - 0x0800/0xffff: IPV4
265 * - 0x86dd/0xffff: IPV6
266 * - 0x0000/0x0000: no L3 item
268 struct sfc_mae_ethertype innermost_ethertype_restriction;
271 * The following two fields keep track of L3 "proto" mask and value.
272 * The corresponding fields get filled in MAE match specification
273 * at the end of parsing. Also, the information is used by a
274 * post-check to enforce consistency requirements:
276 * - If a L3 item is followed by an item TCP, the former has
277 * its "proto" set to either 0x06/0xff or 0x00/0x00.
279 * - If a L3 item is followed by an item UDP, the former has
280 * its "proto" set to either 0x11/0xff or 0x00/0x00.
282 uint8_t l3_next_proto_value;
283 uint8_t l3_next_proto_mask;
286 * L4 requirement for L3 item's "proto".
287 * This contains one of:
290 * - 0x00/0x00: no L4 item
292 uint8_t l3_next_proto_restriction_value;
293 uint8_t l3_next_proto_restriction_mask;
295 /* Projected state of EFX_MAE_FIELD_HAS_OVLAN match bit */
296 bool has_ovlan_value;
299 /* Projected state of EFX_MAE_FIELD_HAS_IVLAN match bit */
300 bool has_ivlan_value;
304 struct sfc_mae_parse_ctx {
305 struct sfc_adapter *sa;
306 efx_mae_match_spec_t *match_spec_action;
307 efx_mae_match_spec_t *match_spec_outer;
309 * This points to either of the above two specifications depending
310 * on which part of the pattern is being parsed (outer / inner).
312 efx_mae_match_spec_t *match_spec;
314 * This points to either "field_ids_remap_to_encap"
315 * or "field_ids_no_remap" (see sfc_mae.c) depending on
316 * which part of the pattern is being parsed.
318 const efx_mae_field_id_t *field_ids_remap;
319 /* These two fields correspond to the tunnel-specific default mask. */
320 size_t tunnel_def_mask_size;
321 const void *tunnel_def_mask;
322 bool match_mport_set;
323 struct sfc_mae_pattern_data pattern_data;
324 efx_tunnel_protocol_t encap_type;
325 unsigned int priority;
328 int sfc_mae_attach(struct sfc_adapter *sa);
329 void sfc_mae_detach(struct sfc_adapter *sa);
330 sfc_flow_cleanup_cb_t sfc_mae_flow_cleanup;
331 int sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
332 const struct rte_flow_item pattern[],
333 struct sfc_flow_spec_mae *spec,
334 struct rte_flow_error *error);
335 int sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
336 const struct rte_flow_action actions[],
337 struct sfc_flow_spec_mae *spec_mae,
338 struct rte_flow_error *error);
339 sfc_flow_verify_cb_t sfc_mae_flow_verify;
340 sfc_flow_insert_cb_t sfc_mae_flow_insert;
341 sfc_flow_remove_cb_t sfc_mae_flow_remove;
342 sfc_flow_query_cb_t sfc_mae_flow_query;
345 * The value used to represent the lowest priority.
346 * Used in MAE rule API.
348 #define SFC_MAE_RULE_PRIO_LOWEST (-1)
351 * Insert a driver-internal flow rule that matches traffic originating from
352 * some m-port selector and redirects it to another one
353 * (eg. PF --> PHY, PHY --> PF).
355 * If requested priority is negative, use the lowest priority.
357 int sfc_mae_rule_add_mport_match_deliver(struct sfc_adapter *sa,
358 const efx_mport_sel_t *mport_match,
359 const efx_mport_sel_t *mport_deliver,
360 int prio, struct sfc_mae_rule **rulep);
361 void sfc_mae_rule_del(struct sfc_adapter *sa, struct sfc_mae_rule *rule);
362 int sfc_mae_switchdev_init(struct sfc_adapter *sa);
363 void sfc_mae_switchdev_fini(struct sfc_adapter *sa);
368 #endif /* _SFC_MAE_H */