]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/mlx5/fs.h
Update releng/11.3 to RC3 as part of the 11.3-RELEASE cycle.
[FreeBSD/FreeBSD.git] / sys / dev / mlx5 / fs.h
1 /*-
2  * Copyright (c) 2013-2017, Mellanox Technologies, Ltd.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27
28 #ifndef _MLX5_FS_
29 #define _MLX5_FS_
30
31 #include <linux/list.h>
32
33 #include <dev/mlx5/mlx5_ifc.h>
34 #include <dev/mlx5/device.h>
35 #include <dev/mlx5/driver.h>
36
37 enum {
38         MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO  = 1 << 16,
39 };
40
41 /*Flow tag*/
42 enum {
43         MLX5_FS_DEFAULT_FLOW_TAG  = 0xFFFFFF,
44         MLX5_FS_ETH_FLOW_TAG  = 0xFFFFFE,
45         MLX5_FS_SNIFFER_FLOW_TAG  = 0xFFFFFD,
46 };
47
48 enum {
49         MLX5_FS_FLOW_TAG_MASK = 0xFFFFFF,
50 };
51
52 #define FS_MAX_TYPES            10
53 #define FS_MAX_ENTRIES          32000U
54
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,
64 };
65
66 struct mlx5_flow_table;
67 struct mlx5_flow_group;
68 struct mlx5_flow_rule;
69 struct mlx5_flow_namespace;
70
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)];
75 };
76
77 struct mlx5_flow_destination {
78         u32     type;
79         union {
80                 u32                     tir_num;
81                 struct mlx5_flow_table  *ft;
82                 u32                     vport_num;
83         };
84 };
85
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,
90         int *n_ent,
91         int *n_grp)
92 {
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;
97 }
98
99 static inline bool outer_header_zero(u32 *match_criteria)
100 {
101         int size = MLX5_ST_SZ_BYTES(fte_match_param);
102         char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
103                                              outer_headers);
104
105         return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
106                                                   outer_headers_c + 1,
107                                                   size - 1);
108 }
109
110 struct mlx5_flow_namespace *
111 mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
112                         enum mlx5_flow_namespace_type type);
113
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
117  */
118 struct mlx5_flow_table *
119 mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
120                                     int prio,
121                                     const char *name,
122                                     int num_flow_table_entries,
123                                     int max_num_groups);
124
125 struct mlx5_flow_table *
126 mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
127                                                          u16 vport,
128                                                          int prio,
129                                                          const char *name,
130                                                          int num_flow_table_entries);
131
132 struct mlx5_flow_table *
133 mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
134                        int prio,
135                        const char *name,
136                        int num_flow_table_entries);
137 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
138
139 /* inbox should be set with the following values:
140  * start_flow_index
141  * end_flow_index
142  * match_criteria_enable
143  * match_criteria
144  */
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);
148
149 /* Single destination per rule.
150  * Group ID is implied by the match criteria.
151  */
152 struct mlx5_flow_rule *
153 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
154                    u8 match_criteria_enable,
155                    u32 *match_criteria,
156                    u32 *match_value,
157                    u32 action,
158                    u32 flow_tag,
159                    struct mlx5_flow_destination *dest);
160 void mlx5_del_flow_rule(struct mlx5_flow_rule *fr);
161
162 /*The following API is for sniffer*/
163 typedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
164                              bool ctx_changed,
165                              void *client_data,
166                              void *context);
167
168 struct mlx5_flow_handler;
169
170 struct flow_client_priv_data;
171
172 void mlx5e_sniffer_roce_mode_notify(
173         struct mlx5_core_dev *mdev,
174         int action);
175
176 int mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
177                                mlx5_flow_handler *handler,  void
178                                *client_data);
179
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,
184                                                       void *context);
185
186 void mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
187
188 void mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
189                                              rule_event_fn cb,
190                                              void *context);
191
192 void mlx5_get_match_criteria(u32 *match_criteria,
193                              struct mlx5_flow_rule *rule);
194
195 void mlx5_get_match_value(u32 *match_value,
196                           struct mlx5_flow_rule *rule);
197
198 u8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
199
200 struct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
201
202 void mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
203
204 struct mlx5_flow_rules_list {
205         struct list_head head;
206 };
207
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;
213 };
214
215 struct mlx5_core_fs_mask {
216         u8      match_criteria_enable;
217         u32     match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
218 };
219
220 bool fs_match_exact_val(
221                 struct mlx5_core_fs_mask *mask,
222                 void *val1,
223                 void *val2);
224
225 bool fs_match_exact_mask(
226                 u8 match_criteria_enable1,
227                 u8 match_criteria_enable2,
228                 void *mask1,
229                 void *mask2);
230 /**********end API for sniffer**********/
231
232 #endif