1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021 Mellanox Technologies. */
3
4 #ifndef __MLX5_EN_TC_PRIV_H__
5 #define __MLX5_EN_TC_PRIV_H__
6
7 #include "en_tc.h"
8 #include "en/tc/act/act.h"
9
10 #define MLX5E_TC_FLOW_BASE (MLX5E_TC_FLAG_LAST_EXPORTED_BIT + 1)
11
12 #define MLX5E_TC_MAX_SPLITS 1
13
14
15 enum {
16 MLX5E_TC_FLOW_FLAG_INGRESS = MLX5E_TC_FLAG_INGRESS_BIT,
17 MLX5E_TC_FLOW_FLAG_EGRESS = MLX5E_TC_FLAG_EGRESS_BIT,
18 MLX5E_TC_FLOW_FLAG_ESWITCH = MLX5E_TC_FLAG_ESW_OFFLOAD_BIT,
19 MLX5E_TC_FLOW_FLAG_FT = MLX5E_TC_FLAG_FT_OFFLOAD_BIT,
20 MLX5E_TC_FLOW_FLAG_NIC = MLX5E_TC_FLAG_NIC_OFFLOAD_BIT,
21 MLX5E_TC_FLOW_FLAG_OFFLOADED = MLX5E_TC_FLOW_BASE,
22 MLX5E_TC_FLOW_FLAG_HAIRPIN = MLX5E_TC_FLOW_BASE + 1,
23 MLX5E_TC_FLOW_FLAG_HAIRPIN_RSS = MLX5E_TC_FLOW_BASE + 2,
24 MLX5E_TC_FLOW_FLAG_SLOW = MLX5E_TC_FLOW_BASE + 3,
25 MLX5E_TC_FLOW_FLAG_DUP = MLX5E_TC_FLOW_BASE + 4,
26 MLX5E_TC_FLOW_FLAG_NOT_READY = MLX5E_TC_FLOW_BASE + 5,
27 MLX5E_TC_FLOW_FLAG_DELETED = MLX5E_TC_FLOW_BASE + 6,
28 MLX5E_TC_FLOW_FLAG_L3_TO_L2_DECAP = MLX5E_TC_FLOW_BASE + 7,
29 MLX5E_TC_FLOW_FLAG_TUN_RX = MLX5E_TC_FLOW_BASE + 8,
30 MLX5E_TC_FLOW_FLAG_FAILED = MLX5E_TC_FLOW_BASE + 9,
31 MLX5E_TC_FLOW_FLAG_SAMPLE = MLX5E_TC_FLOW_BASE + 10,
32 MLX5E_TC_FLOW_FLAG_USE_ACT_STATS = MLX5E_TC_FLOW_BASE + 11,
33 MLX5E_TC_FLOW_FLAG_PEER = MLX5E_TC_FLOW_BASE + 12,
34 };
35
36 struct mlx5e_tc_flow_parse_attr {
37 const struct ip_tunnel_info *tun_info[MLX5_MAX_FLOW_FWD_VPORTS];
38 struct mlx5e_mpls_info mpls_info[MLX5_MAX_FLOW_FWD_VPORTS];
39 struct net_device *filter_dev;
40 struct mlx5_flow_spec spec;
41 struct pedit_headers_action hdrs[__PEDIT_CMD_MAX];
42 struct mlx5e_tc_mod_hdr_acts mod_hdr_acts;
43 int mirred_ifindex[MLX5_MAX_FLOW_FWD_VPORTS];
44 struct mlx5e_tc_act_parse_state parse_state;
45 };
46
47 struct mlx5_fs_chains *mlx5e_nic_chains(struct mlx5e_tc_table *tc);
48
49 /* Helper struct for accessing a struct containing list_head array.
50 * Containing struct
51 * |- Helper array
52 * [0] Helper item 0
53 * |- list_head item 0
54 * |- index (0)
55 * [1] Helper item 1
56 * |- list_head item 1
57 * |- index (1)
58 * To access the containing struct from one of the list_head items:
59 * 1. Get the helper item from the list_head item using
60 * helper item =
61 * container_of(list_head item, helper struct type, list_head field)
62 * 2. Get the contining struct from the helper item and its index in the array:
63 * containing struct =
64 * container_of(helper item, containing struct type, helper field[index])
65 */
66 struct encap_flow_item {
67 struct mlx5e_encap_entry *e; /* attached encap instance */
68 struct list_head list;
69 int index;
70 };
71
72 struct encap_route_flow_item {
73 struct mlx5e_route_entry *r; /* attached route instance */
74 int index;
75 };
76
77 struct mlx5e_tc_flow {
78 struct rhash_head node;
79 struct mlx5e_priv *priv;
80 u64 cookie;
81 unsigned long flags;
82 struct mlx5_flow_handle *rule[MLX5E_TC_MAX_SPLITS + 1];
83
84 /* flows sharing the same reformat object - currently mpls decap */
85 struct list_head l3_to_l2_reformat;
86 struct mlx5e_decap_entry *decap_reformat;
87
88 /* flows sharing same route entry */
89 struct list_head decap_routes;
90 struct mlx5e_route_entry *decap_route;
91 struct encap_route_flow_item encap_routes[MLX5_MAX_FLOW_FWD_VPORTS];
92
93 /* Flow can be associated with multiple encap IDs.
94 * The number of encaps is bounded by the number of supported
95 * destinations.
96 */
97 struct encap_flow_item encaps[MLX5_MAX_FLOW_FWD_VPORTS];
98 struct mlx5e_hairpin_entry *hpe; /* attached hairpin instance */
99 struct list_head hairpin; /* flows sharing the same hairpin */
100 struct list_head peer[MLX5_MAX_PORTS]; /* flows with peer flow */
101 DECLARE_BITMAP(peer_used, MLX5_MAX_PORTS); /* tracks populated peer
102 * slots
103 */
104 struct list_head unready; /* flows not ready to be offloaded (e.g
105 * due to missing route)
106 */
107 struct list_head peer_flows; /* flows on peer */
108 int peer_index; /* peer-flow index pinned at add time, used at del
109 * time so removal is independent of LAG state
110 * changes between add and del.
111 */
112 struct net_device *orig_dev; /* netdev adding flow first */
113 int tmp_entry_index;
114 struct list_head tmp_list; /* temporary flow list used by neigh update */
115 refcount_t refcnt;
116 struct rcu_head rcu_head;
117 struct completion init_done;
118 struct completion del_hw_done;
119 struct mlx5_flow_attr *attr;
120 struct mlx5_flow_attr *extra_split_attr;
121 struct list_head attrs;
122 u32 chain_mapping;
123 };
124
125 struct mlx5_flow_handle *
126 mlx5e_tc_rule_offload(struct mlx5e_priv *priv,
127 struct mlx5_flow_spec *spec,
128 struct mlx5_flow_attr *attr);
129
130 void
131 mlx5e_tc_rule_unoffload(struct mlx5e_priv *priv,
132 struct mlx5_flow_handle *rule,
133 struct mlx5_flow_attr *attr);
134
135 u8 mlx5e_tc_get_ip_version(struct mlx5_flow_spec *spec, bool outer);
136
137 struct mlx5_flow_handle *
138 mlx5e_tc_offload_fdb_rules(struct mlx5_eswitch *esw,
139 struct mlx5e_tc_flow *flow,
140 struct mlx5_flow_spec *spec,
141 struct mlx5_flow_attr *attr);
142
143 struct mlx5_flow_attr *
144 mlx5e_tc_get_encap_attr(struct mlx5e_tc_flow *flow);
145
146 void mlx5e_tc_unoffload_flow_post_acts(struct mlx5e_tc_flow *flow);
147 int mlx5e_tc_offload_flow_post_acts(struct mlx5e_tc_flow *flow);
148
149 bool mlx5e_is_eswitch_flow(struct mlx5e_tc_flow *flow);
150 bool mlx5e_is_ft_flow(struct mlx5e_tc_flow *flow);
151 bool mlx5e_is_offloaded_flow(struct mlx5e_tc_flow *flow);
152 int mlx5e_get_flow_namespace(struct mlx5e_tc_flow *flow);
153 bool mlx5e_same_hw_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv);
154
__flow_flag_set(struct mlx5e_tc_flow * flow,unsigned long flag)155 static inline void __flow_flag_set(struct mlx5e_tc_flow *flow, unsigned long flag)
156 {
157 /* Complete all memory stores before setting bit. */
158 smp_mb__before_atomic();
159 set_bit(flag, &flow->flags);
160 }
161
162 #define flow_flag_set(flow, flag) __flow_flag_set(flow, MLX5E_TC_FLOW_FLAG_##flag)
163
__flow_flag_test_and_set(struct mlx5e_tc_flow * flow,unsigned long flag)164 static inline bool __flow_flag_test_and_set(struct mlx5e_tc_flow *flow,
165 unsigned long flag)
166 {
167 /* test_and_set_bit() provides all necessary barriers */
168 return test_and_set_bit(flag, &flow->flags);
169 }
170
171 #define flow_flag_test_and_set(flow, flag) \
172 __flow_flag_test_and_set(flow, \
173 MLX5E_TC_FLOW_FLAG_##flag)
174
__flow_flag_clear(struct mlx5e_tc_flow * flow,unsigned long flag)175 static inline void __flow_flag_clear(struct mlx5e_tc_flow *flow, unsigned long flag)
176 {
177 /* Complete all memory stores before clearing bit. */
178 smp_mb__before_atomic();
179 clear_bit(flag, &flow->flags);
180 }
181
182 #define flow_flag_clear(flow, flag) __flow_flag_clear(flow, \
183 MLX5E_TC_FLOW_FLAG_##flag)
184
__flow_flag_test(struct mlx5e_tc_flow * flow,unsigned long flag)185 static inline bool __flow_flag_test(struct mlx5e_tc_flow *flow, unsigned long flag)
186 {
187 bool ret = test_bit(flag, &flow->flags);
188
189 /* Read fields of flow structure only after checking flags. */
190 smp_mb__after_atomic();
191 return ret;
192 }
193
194 #define flow_flag_test(flow, flag) __flow_flag_test(flow, \
195 MLX5E_TC_FLOW_FLAG_##flag)
196
197 void mlx5e_tc_unoffload_from_slow_path(struct mlx5_eswitch *esw,
198 struct mlx5e_tc_flow *flow);
199 struct mlx5_flow_handle *
200 mlx5e_tc_offload_to_slow_path(struct mlx5_eswitch *esw,
201 struct mlx5e_tc_flow *flow,
202 struct mlx5_flow_spec *spec);
203
204 void mlx5e_tc_unoffload_fdb_rules(struct mlx5_eswitch *esw,
205 struct mlx5e_tc_flow *flow,
206 struct mlx5_flow_attr *attr);
207
208 struct mlx5e_tc_flow *mlx5e_flow_get(struct mlx5e_tc_flow *flow);
209 void mlx5e_flow_put(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow);
210
211 struct mlx5_fc *mlx5e_tc_get_counter(struct mlx5e_tc_flow *flow);
212
213 struct mlx5e_tc_int_port_priv *
214 mlx5e_get_int_port_priv(struct mlx5e_priv *priv);
215
216 struct mlx5e_flow_meters *mlx5e_get_flow_meters(struct mlx5_core_dev *dev);
217
218 void *mlx5e_get_match_headers_value(u32 flags, struct mlx5_flow_spec *spec);
219 void *mlx5e_get_match_headers_criteria(u32 flags, struct mlx5_flow_spec *spec);
220
221 #endif /* __MLX5_EN_TC_PRIV_H__ */
222