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_OFFLOADS,
58 MLX5_FLOW_NAMESPACE_KERNEL,
59 MLX5_FLOW_NAMESPACE_LEFTOVERS,
60 MLX5_FLOW_NAMESPACE_SNIFFER_RX,
61 MLX5_FLOW_NAMESPACE_SNIFFER_TX,
62 MLX5_FLOW_NAMESPACE_FDB,
63 MLX5_FLOW_NAMESPACE_ESW_EGRESS,
64 MLX5_FLOW_NAMESPACE_ESW_INGRESS,
67 struct mlx5_flow_table;
68 struct mlx5_flow_group;
69 struct mlx5_flow_rule;
70 struct mlx5_flow_namespace;
72 struct mlx5_flow_spec {
73 u8 match_criteria_enable;
74 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
75 u32 match_value[MLX5_ST_SZ_DW(fte_match_param)];
78 struct mlx5_flow_destination {
82 struct mlx5_flow_table *ft;
87 #define FT_NAME_STR_SZ 20
88 #define LEFTOVERS_RULE_NUM 2
89 static inline void build_leftovers_ft_param(char *name,
90 unsigned int *priority,
94 snprintf(name, FT_NAME_STR_SZ, "leftovers");
95 *priority = 0; /*Priority of leftovers_prio-0*/
96 *n_ent = LEFTOVERS_RULE_NUM + 1; /*1: star rules*/
97 *n_grp = LEFTOVERS_RULE_NUM;
100 static inline bool outer_header_zero(u32 *match_criteria)
102 int size = MLX5_ST_SZ_BYTES(fte_match_param);
103 char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
106 return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
111 struct mlx5_flow_namespace *
112 mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
113 enum mlx5_flow_namespace_type type);
115 /* The underlying implementation create two more entries for
116 * chaining flow tables. the user should be aware that if he pass
117 * max_num_ftes as 2^N it will result in doubled size flow table
119 struct mlx5_flow_table *
120 mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
123 int num_flow_table_entries,
126 struct mlx5_flow_table *
127 mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
131 int num_flow_table_entries);
133 struct mlx5_flow_table *
134 mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
137 int num_flow_table_entries);
138 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
140 /* inbox should be set with the following values:
143 * match_criteria_enable
146 struct mlx5_flow_group *
147 mlx5_create_flow_group(struct mlx5_flow_table *ft, u32 *in);
148 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg);
150 /* Single destination per rule.
151 * Group ID is implied by the match criteria.
153 struct mlx5_flow_rule *
154 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
155 u8 match_criteria_enable,
160 struct mlx5_flow_destination *dest);
161 void mlx5_del_flow_rule(struct mlx5_flow_rule *fr);
163 /*The following API is for sniffer*/
164 typedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
169 struct mlx5_flow_handler;
171 struct flow_client_priv_data;
173 void mlx5e_sniffer_roce_mode_notify(
174 struct mlx5_core_dev *mdev,
177 int mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
178 mlx5_flow_handler *handler, void
181 struct mlx5_flow_handler *mlx5_register_rule_notifier(struct mlx5_core_dev *dev,
182 enum mlx5_flow_namespace_type ns_type,
183 rule_event_fn add_cb,
184 rule_event_fn del_cb,
187 void mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
189 void mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
193 void mlx5_get_match_criteria(u32 *match_criteria,
194 struct mlx5_flow_rule *rule);
196 void mlx5_get_match_value(u32 *match_value,
197 struct mlx5_flow_rule *rule);
199 u8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
201 struct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
203 void mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
205 struct mlx5_flow_rules_list {
206 struct list_head head;
209 struct mlx5_flow_rule_node {
210 struct list_head list;
211 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
212 u32 match_value[MLX5_ST_SZ_DW(fte_match_param)];
213 u8 match_criteria_enable;
216 struct mlx5_core_fs_mask {
217 u8 match_criteria_enable;
218 u32 match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
221 bool fs_match_exact_val(
222 struct mlx5_core_fs_mask *mask,
226 bool fs_match_exact_mask(
227 u8 match_criteria_enable1,
228 u8 match_criteria_enable2,
231 /**********end API for sniffer**********/