1325638Shselasky/*-
2325638Shselasky * Copyright (c) 2013-2017, Mellanox Technologies, Ltd.  All rights reserved.
3325638Shselasky *
4325638Shselasky * Redistribution and use in source and binary forms, with or without
5325638Shselasky * modification, are permitted provided that the following conditions
6325638Shselasky * are met:
7325638Shselasky * 1. Redistributions of source code must retain the above copyright
8325638Shselasky *    notice, this list of conditions and the following disclaimer.
9325638Shselasky * 2. Redistributions in binary form must reproduce the above copyright
10325638Shselasky *    notice, this list of conditions and the following disclaimer in the
11325638Shselasky *    documentation and/or other materials provided with the distribution.
12325638Shselasky *
13325638Shselasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14325638Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15325638Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16325638Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17325638Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18325638Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19325638Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20325638Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21325638Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22325638Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23325638Shselasky * SUCH DAMAGE.
24325638Shselasky *
25325638Shselasky * $FreeBSD: stable/11/sys/dev/mlx5/fs.h 329200 2018-02-13 14:37:21Z hselasky $
26325638Shselasky */
27325638Shselasky
28325638Shselasky#ifndef _MLX5_FS_
29325638Shselasky#define _MLX5_FS_
30325638Shselasky
31325638Shselasky#include <linux/list.h>
32325638Shselasky
33325638Shselasky#include <dev/mlx5/mlx5_ifc.h>
34325638Shselasky#include <dev/mlx5/device.h>
35325638Shselasky#include <dev/mlx5/driver.h>
36325638Shselasky
37325638Shselaskyenum {
38325638Shselasky	MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO	= 1 << 16,
39325638Shselasky};
40325638Shselasky
41325638Shselasky/*Flow tag*/
42325638Shselaskyenum {
43325638Shselasky	MLX5_FS_DEFAULT_FLOW_TAG  = 0xFFFFFF,
44325638Shselasky	MLX5_FS_ETH_FLOW_TAG  = 0xFFFFFE,
45325638Shselasky	MLX5_FS_SNIFFER_FLOW_TAG  = 0xFFFFFD,
46325638Shselasky};
47325638Shselasky
48325638Shselaskyenum {
49325638Shselasky	MLX5_FS_FLOW_TAG_MASK = 0xFFFFFF,
50325638Shselasky};
51325638Shselasky
52325638Shselasky#define FS_MAX_TYPES		10
53325638Shselasky#define FS_MAX_ENTRIES		32000U
54325638Shselasky
55325638Shselaskyenum mlx5_flow_namespace_type {
56325638Shselasky	MLX5_FLOW_NAMESPACE_BYPASS,
57325638Shselasky	MLX5_FLOW_NAMESPACE_KERNEL,
58325638Shselasky	MLX5_FLOW_NAMESPACE_LEFTOVERS,
59325638Shselasky	MLX5_FLOW_NAMESPACE_SNIFFER_RX,
60325638Shselasky	MLX5_FLOW_NAMESPACE_SNIFFER_TX,
61325638Shselasky	MLX5_FLOW_NAMESPACE_FDB,
62325638Shselasky	MLX5_FLOW_NAMESPACE_ESW_EGRESS,
63325638Shselasky	MLX5_FLOW_NAMESPACE_ESW_INGRESS,
64325638Shselasky};
65325638Shselasky
66325638Shselaskystruct mlx5_flow_table;
67325638Shselaskystruct mlx5_flow_group;
68325638Shselaskystruct mlx5_flow_rule;
69325638Shselaskystruct mlx5_flow_namespace;
70325638Shselasky
71325638Shselaskystruct mlx5_flow_spec {
72325638Shselasky	u8   match_criteria_enable;
73325638Shselasky	u32  match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
74325638Shselasky	u32  match_value[MLX5_ST_SZ_DW(fte_match_param)];
75325638Shselasky};
76325638Shselasky
77325638Shselaskystruct mlx5_flow_destination {
78325638Shselasky	u32	type;
79325638Shselasky	union {
80325638Shselasky		u32			tir_num;
81325638Shselasky		struct mlx5_flow_table	*ft;
82325638Shselasky		u32			vport_num;
83325638Shselasky	};
84325638Shselasky};
85325638Shselasky
86325638Shselasky#define FT_NAME_STR_SZ 20
87325638Shselasky#define LEFTOVERS_RULE_NUM 2
88325638Shselaskystatic inline void build_leftovers_ft_param(char *name,
89325638Shselasky	unsigned int *priority,
90325638Shselasky	int *n_ent,
91325638Shselasky	int *n_grp)
92325638Shselasky{
93325638Shselasky	snprintf(name, FT_NAME_STR_SZ, "leftovers");
94325638Shselasky	*priority = 0; /*Priority of leftovers_prio-0*/
95325638Shselasky	*n_ent = LEFTOVERS_RULE_NUM + 1; /*1: star rules*/
96325638Shselasky	*n_grp = LEFTOVERS_RULE_NUM;
97325638Shselasky}
98325638Shselasky
99325638Shselaskystatic inline bool outer_header_zero(u32 *match_criteria)
100325638Shselasky{
101325638Shselasky	int size = MLX5_ST_SZ_BYTES(fte_match_param);
102325638Shselasky	char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
103325638Shselasky					     outer_headers);
104325638Shselasky
105325638Shselasky	return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
106325638Shselasky						  outer_headers_c + 1,
107325638Shselasky						  size - 1);
108325638Shselasky}
109325638Shselasky
110325638Shselaskystruct mlx5_flow_namespace *
111325638Shselaskymlx5_get_flow_namespace(struct mlx5_core_dev *dev,
112325638Shselasky			enum mlx5_flow_namespace_type type);
113325638Shselasky
114325638Shselasky/* The underlying implementation create two more entries for
115325638Shselasky * chaining flow tables. the user should be aware that if he pass
116325638Shselasky * max_num_ftes as 2^N it will result in doubled size flow table
117325638Shselasky */
118325638Shselaskystruct mlx5_flow_table *
119325638Shselaskymlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
120325638Shselasky				    int prio,
121325638Shselasky				    const char *name,
122325638Shselasky				    int num_flow_table_entries,
123325638Shselasky				    int max_num_groups);
124325638Shselasky
125325638Shselaskystruct mlx5_flow_table *
126325638Shselaskymlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
127325638Shselasky							 u16 vport,
128325638Shselasky							 int prio,
129325638Shselasky							 const char *name,
130325638Shselasky							 int num_flow_table_entries);
131325638Shselasky
132325638Shselaskystruct mlx5_flow_table *
133325638Shselaskymlx5_create_flow_table(struct mlx5_flow_namespace *ns,
134325638Shselasky		       int prio,
135325638Shselasky		       const char *name,
136325638Shselasky		       int num_flow_table_entries);
137325638Shselaskyint mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
138325638Shselasky
139325638Shselasky/* inbox should be set with the following values:
140325638Shselasky * start_flow_index
141325638Shselasky * end_flow_index
142325638Shselasky * match_criteria_enable
143325638Shselasky * match_criteria
144325638Shselasky */
145325638Shselaskystruct mlx5_flow_group *
146325638Shselaskymlx5_create_flow_group(struct mlx5_flow_table *ft, u32 *in);
147325638Shselaskyvoid mlx5_destroy_flow_group(struct mlx5_flow_group *fg);
148325638Shselasky
149325638Shselasky/* Single destination per rule.
150325638Shselasky * Group ID is implied by the match criteria.
151325638Shselasky */
152325638Shselaskystruct mlx5_flow_rule *
153325638Shselaskymlx5_add_flow_rule(struct mlx5_flow_table *ft,
154325638Shselasky		   u8 match_criteria_enable,
155325638Shselasky		   u32 *match_criteria,
156325638Shselasky		   u32 *match_value,
157325638Shselasky		   u32 action,
158325638Shselasky		   u32 flow_tag,
159325638Shselasky		   struct mlx5_flow_destination *dest);
160325638Shselaskyvoid mlx5_del_flow_rule(struct mlx5_flow_rule *fr);
161325638Shselasky
162325638Shselasky/*The following API is for sniffer*/
163325638Shselaskytypedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
164325638Shselasky			     bool ctx_changed,
165325638Shselasky			     void *client_data,
166325638Shselasky			     void *context);
167325638Shselasky
168325638Shselaskystruct mlx5_flow_handler;
169325638Shselasky
170325638Shselaskystruct flow_client_priv_data;
171325638Shselasky
172325638Shselaskyvoid mlx5e_sniffer_roce_mode_notify(
173325638Shselasky	struct mlx5_core_dev *mdev,
174325638Shselasky	int action);
175325638Shselasky
176325638Shselaskyint mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
177325638Shselasky			       mlx5_flow_handler *handler,  void
178325638Shselasky			       *client_data);
179325638Shselasky
180325638Shselaskystruct mlx5_flow_handler *mlx5_register_rule_notifier(struct mlx5_core_dev *dev,
181325638Shselasky						      enum mlx5_flow_namespace_type ns_type,
182325638Shselasky						      rule_event_fn add_cb,
183325638Shselasky						      rule_event_fn del_cb,
184325638Shselasky						      void *context);
185325638Shselasky
186325638Shselaskyvoid mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
187325638Shselasky
188325638Shselaskyvoid mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
189325638Shselasky					     rule_event_fn cb,
190325638Shselasky					     void *context);
191325638Shselasky
192325638Shselaskyvoid mlx5_get_match_criteria(u32 *match_criteria,
193325638Shselasky			     struct mlx5_flow_rule *rule);
194325638Shselasky
195325638Shselaskyvoid mlx5_get_match_value(u32 *match_value,
196325638Shselasky			  struct mlx5_flow_rule *rule);
197325638Shselasky
198325638Shselaskyu8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
199325638Shselasky
200325638Shselaskystruct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
201325638Shselasky
202325638Shselaskyvoid mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
203325638Shselasky
204325638Shselaskystruct mlx5_flow_rules_list {
205325638Shselasky	struct list_head head;
206325638Shselasky};
207325638Shselasky
208325638Shselaskystruct mlx5_flow_rule_node {
209325638Shselasky	struct	list_head list;
210325638Shselasky	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
211325638Shselasky	u32	match_value[MLX5_ST_SZ_DW(fte_match_param)];
212325638Shselasky	u8	match_criteria_enable;
213325638Shselasky};
214325638Shselasky
215325638Shselaskystruct mlx5_core_fs_mask {
216325638Shselasky	u8	match_criteria_enable;
217325638Shselasky	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
218325638Shselasky};
219325638Shselasky
220325638Shselaskybool fs_match_exact_val(
221325638Shselasky		struct mlx5_core_fs_mask *mask,
222325638Shselasky		void *val1,
223325638Shselasky		void *val2);
224325638Shselasky
225325638Shselaskybool fs_match_exact_mask(
226325638Shselasky		u8 match_criteria_enable1,
227325638Shselasky		u8 match_criteria_enable2,
228325638Shselasky		void *mask1,
229325638Shselasky		void *mask2);
230325638Shselasky/**********end API for sniffer**********/
231325638Shselasky
232325638Shselasky#endif
233