2 * Copyright (c) 2013-2017, Mellanox Technologies, Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <linux/list.h>
33 #include <dev/mlx5/mlx5_ifc.h>
34 #include <dev/mlx5/device.h>
35 #include <dev/mlx5/driver.h>
38 MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO = 1 << 16,
43 MLX5_FS_DEFAULT_FLOW_TAG = 0xFFFFFF,
44 MLX5_FS_ETH_FLOW_TAG = 0xFFFFFE,
45 MLX5_FS_SNIFFER_FLOW_TAG = 0xFFFFFD,
49 MLX5_FS_FLOW_TAG_MASK = 0xFFFFFF,
52 #define FS_MAX_TYPES 10
53 #define FS_MAX_ENTRIES 32000U
55 enum mlx5_flow_namespace_type {
56 MLX5_FLOW_NAMESPACE_BYPASS,
57 MLX5_FLOW_NAMESPACE_KERNEL,
58 MLX5_FLOW_NAMESPACE_LEFTOVERS,
59 MLX5_FLOW_NAMESPACE_SNIFFER_RX,
60 MLX5_FLOW_NAMESPACE_SNIFFER_TX,
61 MLX5_FLOW_NAMESPACE_FDB,
62 MLX5_FLOW_NAMESPACE_ESW_EGRESS,
63 MLX5_FLOW_NAMESPACE_ESW_INGRESS,
66 struct mlx5_flow_table;
67 struct mlx5_flow_group;
68 struct mlx5_flow_rule;
69 struct mlx5_flow_namespace;
71 struct mlx5_flow_spec {
72 u8 match_criteria_enable;
73 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
74 u32 match_value[MLX5_ST_SZ_DW(fte_match_param)];
77 struct mlx5_flow_destination {
81 struct mlx5_flow_table *ft;
86 #define FT_NAME_STR_SZ 20
87 #define LEFTOVERS_RULE_NUM 2
88 static inline void build_leftovers_ft_param(char *name,
89 unsigned int *priority,
93 snprintf(name, FT_NAME_STR_SZ, "leftovers");
94 *priority = 0; /*Priority of leftovers_prio-0*/
95 *n_ent = LEFTOVERS_RULE_NUM + 1; /*1: star rules*/
96 *n_grp = LEFTOVERS_RULE_NUM;
99 static inline bool outer_header_zero(u32 *match_criteria)
101 int size = MLX5_ST_SZ_BYTES(fte_match_param);
102 char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
105 return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
110 struct mlx5_flow_namespace *
111 mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
112 enum mlx5_flow_namespace_type type);
114 /* The underlying implementation create two more entries for
115 * chaining flow tables. the user should be aware that if he pass
116 * max_num_ftes as 2^N it will result in doubled size flow table
118 struct mlx5_flow_table *
119 mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
122 int num_flow_table_entries,
125 struct mlx5_flow_table *
126 mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
130 int num_flow_table_entries);
132 struct mlx5_flow_table *
133 mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
136 int num_flow_table_entries);
137 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
139 /* inbox should be set with the following values:
142 * match_criteria_enable
145 struct mlx5_flow_group *
146 mlx5_create_flow_group(struct mlx5_flow_table *ft, u32 *in);
147 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg);
149 /* Single destination per rule.
150 * Group ID is implied by the match criteria.
152 struct mlx5_flow_rule *
153 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
154 u8 match_criteria_enable,
159 struct mlx5_flow_destination *dest);
160 void mlx5_del_flow_rule(struct mlx5_flow_rule *fr);
162 /*The following API is for sniffer*/
163 typedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
168 struct mlx5_flow_handler;
170 struct flow_client_priv_data;
172 void mlx5e_sniffer_roce_mode_notify(
173 struct mlx5_core_dev *mdev,
176 int mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
177 mlx5_flow_handler *handler, void
180 struct mlx5_flow_handler *mlx5_register_rule_notifier(struct mlx5_core_dev *dev,
181 enum mlx5_flow_namespace_type ns_type,
182 rule_event_fn add_cb,
183 rule_event_fn del_cb,
186 void mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
188 void mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
192 void mlx5_get_match_criteria(u32 *match_criteria,
193 struct mlx5_flow_rule *rule);
195 void mlx5_get_match_value(u32 *match_value,
196 struct mlx5_flow_rule *rule);
198 u8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
200 struct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
202 void mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
204 struct mlx5_flow_rules_list {
205 struct list_head head;
208 struct mlx5_flow_rule_node {
209 struct list_head list;
210 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
211 u32 match_value[MLX5_ST_SZ_DW(fte_match_param)];
212 u8 match_criteria_enable;
215 struct mlx5_core_fs_mask {
216 u8 match_criteria_enable;
217 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
220 bool fs_match_exact_val(
221 struct mlx5_core_fs_mask *mask,
225 bool fs_match_exact_mask(
226 u8 match_criteria_enable1,
227 u8 match_criteria_enable2,
230 /**********end API for sniffer**********/