1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2/* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3
4#ifndef __MLX5_EN_TC_ACT_H__
5#define __MLX5_EN_TC_ACT_H__
6
7#include <net/tc_act/tc_pedit.h>
8#include <net/flow_offload.h>
9#include <linux/netlink.h>
10#include "eswitch.h"
11#include "pedit.h"
12
13struct mlx5_flow_attr;
14
15struct mlx5e_tc_act_parse_state {
16	struct flow_action *flow_action;
17	struct mlx5e_tc_flow *flow;
18	struct netlink_ext_ack *extack;
19	u32 actions;
20	bool encap;
21	bool decap;
22	bool mpls_push;
23	bool eth_push;
24	bool eth_pop;
25	bool ptype_host;
26	const struct ip_tunnel_info *tun_info;
27	struct mlx5e_mpls_info mpls_info;
28	int ifindexes[MLX5_MAX_FLOW_FWD_VPORTS];
29	int if_count;
30	struct mlx5_tc_ct_priv *ct_priv;
31};
32
33struct mlx5e_tc_act_branch_ctrl {
34	enum flow_action_id act_id;
35	u32 extval;
36};
37
38struct mlx5e_tc_act {
39	bool (*can_offload)(struct mlx5e_tc_act_parse_state *parse_state,
40			    const struct flow_action_entry *act,
41			    int act_index,
42			    struct mlx5_flow_attr *attr);
43
44	int (*parse_action)(struct mlx5e_tc_act_parse_state *parse_state,
45			    const struct flow_action_entry *act,
46			    struct mlx5e_priv *priv,
47			    struct mlx5_flow_attr *attr);
48
49	int (*post_parse)(struct mlx5e_tc_act_parse_state *parse_state,
50			  struct mlx5e_priv *priv,
51			  struct mlx5_flow_attr *attr);
52
53	bool (*is_multi_table_act)(struct mlx5e_priv *priv,
54				   const struct flow_action_entry *act,
55				   struct mlx5_flow_attr *attr);
56
57	bool (*is_missable)(const struct flow_action_entry *act);
58
59	int (*offload_action)(struct mlx5e_priv *priv,
60			      struct flow_offload_action *fl_act,
61			      struct flow_action_entry *act);
62
63	int (*destroy_action)(struct mlx5e_priv *priv,
64			      struct flow_offload_action *fl_act);
65
66	int (*stats_action)(struct mlx5e_priv *priv,
67			    struct flow_offload_action *fl_act);
68
69	bool (*get_branch_ctrl)(const struct flow_action_entry *act,
70				struct mlx5e_tc_act_branch_ctrl *cond_true,
71				struct mlx5e_tc_act_branch_ctrl *cond_false);
72
73	bool is_terminating_action;
74};
75
76struct mlx5e_tc_flow_action {
77	unsigned int num_entries;
78	struct flow_action_entry **entries;
79};
80
81extern struct mlx5e_tc_act mlx5e_tc_act_drop;
82extern struct mlx5e_tc_act mlx5e_tc_act_trap;
83extern struct mlx5e_tc_act mlx5e_tc_act_accept;
84extern struct mlx5e_tc_act mlx5e_tc_act_mark;
85extern struct mlx5e_tc_act mlx5e_tc_act_goto;
86extern struct mlx5e_tc_act mlx5e_tc_act_tun_encap;
87extern struct mlx5e_tc_act mlx5e_tc_act_tun_decap;
88extern struct mlx5e_tc_act mlx5e_tc_act_csum;
89extern struct mlx5e_tc_act mlx5e_tc_act_pedit;
90extern struct mlx5e_tc_act mlx5e_tc_act_vlan;
91extern struct mlx5e_tc_act mlx5e_tc_act_vlan_mangle;
92extern struct mlx5e_tc_act mlx5e_tc_act_mpls_push;
93extern struct mlx5e_tc_act mlx5e_tc_act_mpls_pop;
94extern struct mlx5e_tc_act mlx5e_tc_act_mirred;
95extern struct mlx5e_tc_act mlx5e_tc_act_redirect;
96extern struct mlx5e_tc_act mlx5e_tc_act_mirred_nic;
97extern struct mlx5e_tc_act mlx5e_tc_act_ct;
98extern struct mlx5e_tc_act mlx5e_tc_act_sample;
99extern struct mlx5e_tc_act mlx5e_tc_act_ptype;
100extern struct mlx5e_tc_act mlx5e_tc_act_redirect_ingress;
101extern struct mlx5e_tc_act mlx5e_tc_act_police;
102
103struct mlx5e_tc_act *
104mlx5e_tc_act_get(enum flow_action_id act_id,
105		 enum mlx5_flow_namespace_type ns_type);
106
107void
108mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
109			      struct mlx5e_tc_flow *flow,
110			      struct flow_action *flow_action,
111			      struct netlink_ext_ack *extack);
112
113int
114mlx5e_tc_act_post_parse(struct mlx5e_tc_act_parse_state *parse_state,
115			struct flow_action *flow_action, int from, int to,
116			struct mlx5_flow_attr *attr,
117			enum mlx5_flow_namespace_type ns_type);
118
119int
120mlx5e_tc_act_set_next_post_act(struct mlx5e_tc_flow *flow,
121			       struct mlx5_flow_attr *attr,
122			       struct mlx5_flow_attr *next_attr);
123
124#endif /* __MLX5_EN_TC_ACT_H__ */
125