]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
flow_offload: Add flow_match_ct to get rule ct match
[mirror_ubuntu-jammy-kernel.git] / drivers / net / ethernet / mellanox / mlx5 / core / eswitch.h
CommitLineData
073bb189
SM
1/*
2 * Copyright (c) 2015, Mellanox Technologies, Ltd. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef __MLX5_ESWITCH_H__
34#define __MLX5_ESWITCH_H__
35
77256579
SM
36#include <linux/if_ether.h>
37#include <linux/if_link.h>
525e84be 38#include <linux/atomic.h>
feae9087 39#include <net/devlink.h>
073bb189 40#include <linux/mlx5/device.h>
57cbd893 41#include <linux/mlx5/eswitch.h>
a1b3839a 42#include <linux/mlx5/vport.h>
cc495188 43#include <linux/mlx5/fs.h>
eeb66cdb 44#include "lib/mpfs.h"
073bb189 45
2cf2954b 46#define FDB_TC_MAX_CHAIN 3
975b992f
PB
47#define FDB_FT_CHAIN (FDB_TC_MAX_CHAIN + 1)
48#define FDB_TC_SLOW_PATH_CHAIN (FDB_FT_CHAIN + 1)
49
50/* The index of the last real chain (FT) + 1 as chain zero is valid as well */
51#define FDB_NUM_CHAINS (FDB_FT_CHAIN + 1)
52
2cf2954b 53#define FDB_TC_MAX_PRIO 16
4db7b98e 54#define FDB_TC_LEVELS_PER_PRIO 2
12063c2e 55
e80541ec
SM
56#ifdef CONFIG_MLX5_ESWITCH
57
87dac697
JL
58#define ESW_OFFLOADS_DEFAULT_NUM_GROUPS 15
59
073bb189
SM
60#define MLX5_MAX_UC_PER_VPORT(dev) \
61 (1 << MLX5_CAP_GEN(dev, log_max_current_uc_list))
62
63#define MLX5_MAX_MC_PER_VPORT(dev) \
64 (1 << MLX5_CAP_GEN(dev, log_max_current_mc_list))
65
c9497c98
MHY
66#define MLX5_MIN_BW_SHARE 1
67
68#define MLX5_RATE_TO_BW_SHARE(rate, divider, limit) \
69 min_t(u32, max_t(u32, (rate) / (divider), MLX5_MIN_BW_SHARE), limit)
70
a842dd04
CM
71#define mlx5_esw_has_fwd_fdb(dev) \
72 MLX5_CAP_ESW_FLOWTABLE(dev, fdb_multi_path_to_table)
73
5742df0f
MHY
74struct vport_ingress {
75 struct mlx5_flow_table *acl;
10652f39 76 struct mlx5_flow_handle *allow_rule;
853b5352 77 struct {
10652f39
PP
78 struct mlx5_flow_group *allow_spoofchk_only_grp;
79 struct mlx5_flow_group *allow_untagged_spoofchk_grp;
80 struct mlx5_flow_group *allow_untagged_only_grp;
81 struct mlx5_flow_group *drop_grp;
853b5352
PP
82 struct mlx5_flow_handle *drop_rule;
83 struct mlx5_fc *drop_counter;
84 } legacy;
d68316b5 85 struct {
b7826076
PP
86 /* Optional group to add an FTE to do internal priority
87 * tagging on ingress packets.
88 */
89 struct mlx5_flow_group *metadata_prio_tag_grp;
90 /* Group to add default match-all FTE entry to tag ingress
91 * packet with metadata.
92 */
93 struct mlx5_flow_group *metadata_allmatch_grp;
d68316b5
PP
94 struct mlx5_modify_hdr *modify_metadata;
95 struct mlx5_flow_handle *modify_metadata_rule;
96 } offloads;
5742df0f
MHY
97};
98
99struct vport_egress {
100 struct mlx5_flow_table *acl;
101 struct mlx5_flow_group *allowed_vlans_grp;
102 struct mlx5_flow_group *drop_grp;
74491de9 103 struct mlx5_flow_handle *allowed_vlan;
853b5352
PP
104 struct {
105 struct mlx5_flow_handle *drop_rule;
106 struct mlx5_fc *drop_counter;
107 } legacy;
b8a0dbe3
EE
108};
109
110struct mlx5_vport_drop_stats {
111 u64 rx_dropped;
112 u64 tx_dropped;
5742df0f
MHY
113};
114
1ab2068a
MHY
115struct mlx5_vport_info {
116 u8 mac[ETH_ALEN];
117 u16 vlan;
118 u8 qos;
119 u64 node_guid;
120 int link_state;
c9497c98 121 u32 min_rate;
1bd27b11 122 u32 max_rate;
1ab2068a
MHY
123 bool spoofchk;
124 bool trusted;
125};
126
5019833d
PP
127/* Vport context events */
128enum mlx5_eswitch_vport_event {
129 MLX5_VPORT_UC_ADDR_CHANGE = BIT(0),
130 MLX5_VPORT_MC_ADDR_CHANGE = BIT(1),
131 MLX5_VPORT_PROMISC_CHANGE = BIT(3),
132};
133
073bb189
SM
134struct mlx5_vport {
135 struct mlx5_core_dev *dev;
136 int vport;
137 struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];
81848731 138 struct hlist_head mc_list[MLX5_L2_ADDR_HASH_SIZE];
74491de9
MB
139 struct mlx5_flow_handle *promisc_rule;
140 struct mlx5_flow_handle *allmulti_rule;
073bb189
SM
141 struct work_struct vport_change_handler;
142
5742df0f
MHY
143 struct vport_ingress ingress;
144 struct vport_egress egress;
145
1ab2068a
MHY
146 struct mlx5_vport_info info;
147
1bd27b11
MHY
148 struct {
149 bool enabled;
150 u32 esw_tsar_ix;
c9497c98 151 u32 bw_share;
1bd27b11
MHY
152 } qos;
153
073bb189 154 bool enabled;
5019833d 155 enum mlx5_eswitch_vport_event enabled_events;
073bb189
SM
156};
157
e52c2802
PB
158enum offloads_fdb_flags {
159 ESW_FDB_CHAINS_AND_PRIOS_SUPPORTED = BIT(0),
160};
161
39ac237c 162struct mlx5_esw_chains_priv;
e52c2802 163
81848731 164struct mlx5_eswitch_fdb {
6ab36e35
OG
165 union {
166 struct legacy_fdb {
52fff327 167 struct mlx5_flow_table *fdb;
6ab36e35
OG
168 struct mlx5_flow_group *addr_grp;
169 struct mlx5_flow_group *allmulti_grp;
170 struct mlx5_flow_group *promisc_grp;
8da202b2
HN
171 struct mlx5_flow_table *vepa_fdb;
172 struct mlx5_flow_handle *vepa_uplink_rule;
173 struct mlx5_flow_handle *vepa_star_rule;
6ab36e35 174 } legacy;
69697b6e
OG
175
176 struct offloads_fdb {
8463daf1 177 struct mlx5_flow_namespace *ns;
52fff327 178 struct mlx5_flow_table *slow_fdb;
69697b6e 179 struct mlx5_flow_group *send_to_vport_grp;
ac004b83
RD
180 struct mlx5_flow_group *peer_miss_grp;
181 struct mlx5_flow_handle **peer_miss_rules;
69697b6e 182 struct mlx5_flow_group *miss_grp;
f80be543
MB
183 struct mlx5_flow_handle *miss_rule_uni;
184 struct mlx5_flow_handle *miss_rule_multi;
f5f82476 185 int vlan_push_pop_refcount;
e52c2802 186
39ac237c 187 struct mlx5_esw_chains_priv *esw_chains_priv;
96e32687
EC
188 struct {
189 DECLARE_HASHTABLE(table, 8);
190 /* Protects vports.table */
191 struct mutex lock;
192 } vports;
193
69697b6e 194 } offloads;
6ab36e35 195 };
e52c2802 196 u32 flags;
6ab36e35
OG
197};
198
c116c6ee 199struct mlx5_esw_offload {
11b717d6
PB
200 struct mlx5_flow_table *ft_offloads_restore;
201 struct mlx5_flow_group *restore_group;
6724e66b 202 struct mlx5_modify_hdr *restore_copy_hdr_id;
11b717d6 203
c116c6ee 204 struct mlx5_flow_table *ft_offloads;
fed9ce22 205 struct mlx5_flow_group *vport_rx_group;
127ea380 206 struct mlx5_eswitch_rep *vport_reps;
04de7dda
RD
207 struct list_head peer_flows;
208 struct mutex peer_mutex;
61086f39 209 struct mutex encap_tbl_lock; /* protects encap_tbl */
a54e20b4 210 DECLARE_HASHTABLE(encap_tbl, 8);
dd58edc3 211 struct mod_hdr_tbl mod_hdr;
10caabda
OS
212 DECLARE_HASHTABLE(termtbl_tbl, 8);
213 struct mutex termtbl_mutex; /* protects termtbl hash */
8693115a 214 const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES];
bffaa916 215 u8 inline_mode;
525e84be 216 atomic64_t num_flows;
98fdbea5 217 enum devlink_eswitch_encap_mode encap;
c116c6ee
OG
218};
219
0a0ab1d2
EC
220/* E-Switch MC FDB table hash node */
221struct esw_mc_addr { /* SRIOV only */
222 struct l2addr_node node;
223 struct mlx5_flow_handle *uplink_rule; /* Forward to uplink rule */
224 u32 refcnt;
225};
226
a3888f33
BW
227struct mlx5_host_work {
228 struct work_struct work;
229 struct mlx5_eswitch *esw;
230};
231
cd56f929 232struct mlx5_esw_functions {
a3888f33
BW
233 struct mlx5_nb nb;
234 u16 num_vfs;
235};
236
7445cfb1
JL
237enum {
238 MLX5_ESWITCH_VPORT_MATCH_METADATA = BIT(0),
5b7cb745 239 MLX5_ESWITCH_REG_C1_LOOPBACK_ENABLED = BIT(1),
7445cfb1
JL
240};
241
073bb189
SM
242struct mlx5_eswitch {
243 struct mlx5_core_dev *dev;
6933a937 244 struct mlx5_nb nb;
81848731 245 struct mlx5_eswitch_fdb fdb_table;
99ecd646 246 /* legacy data structures */
81848731 247 struct hlist_head mc_table[MLX5_L2_ADDR_HASH_SIZE];
131ce701
PP
248 struct esw_mc_addr mc_promisc;
249 /* end of legacy */
073bb189
SM
250 struct workqueue_struct *work_queue;
251 struct mlx5_vport *vports;
7445cfb1 252 u32 flags;
073bb189 253 int total_vports;
81848731 254 int enabled_vports;
dfcb1ed3
MHY
255 /* Synchronize between vport change events
256 * and async SRIOV admin state changes
257 */
258 struct mutex state_lock;
1bd27b11
MHY
259
260 struct {
261 bool enabled;
262 u32 root_tsar_id;
263 } qos;
264
c116c6ee 265 struct mlx5_esw_offload offloads;
6ab36e35 266 int mode;
e52c2802 267 int nvports;
a1b3839a 268 u16 manager_vport;
411ec9e0 269 u16 first_host_vport;
cd56f929 270 struct mlx5_esw_functions esw_funcs;
87dac697
JL
271 struct {
272 u32 large_group_num;
273 } params;
073bb189
SM
274};
275
5896b972
PP
276void esw_offloads_disable(struct mlx5_eswitch *esw);
277int esw_offloads_enable(struct mlx5_eswitch *esw);
e8d31c4d
MB
278void esw_offloads_cleanup_reps(struct mlx5_eswitch *esw);
279int esw_offloads_init_reps(struct mlx5_eswitch *esw);
18486737
EB
280void esw_vport_cleanup_ingress_rules(struct mlx5_eswitch *esw,
281 struct mlx5_vport *vport);
10652f39
PP
282int esw_vport_create_ingress_acl_table(struct mlx5_eswitch *esw,
283 struct mlx5_vport *vport,
284 int table_size);
285void esw_vport_destroy_ingress_acl_table(struct mlx5_vport *vport);
18486737
EB
286void esw_vport_cleanup_egress_rules(struct mlx5_eswitch *esw,
287 struct mlx5_vport *vport);
288int esw_vport_enable_egress_acl(struct mlx5_eswitch *esw,
289 struct mlx5_vport *vport);
290void esw_vport_disable_egress_acl(struct mlx5_eswitch *esw,
291 struct mlx5_vport *vport);
fcb64c0f
EC
292int mlx5_esw_modify_vport_rate(struct mlx5_eswitch *esw, u16 vport_num,
293 u32 rate_mbps);
766a0e97 294
073bb189
SM
295/* E-Switch API */
296int mlx5_eswitch_init(struct mlx5_core_dev *dev);
297void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
062f4bf4 298int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int mode);
556b9d16 299void mlx5_eswitch_disable(struct mlx5_eswitch *esw, bool clear_vf);
77256579 300int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
02f3afd9 301 u16 vport, u8 mac[ETH_ALEN]);
77256579 302int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
02f3afd9 303 u16 vport, int link_state);
9e7ea352 304int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
02f3afd9 305 u16 vport, u16 vlan, u8 qos);
f942380c 306int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch *esw,
02f3afd9 307 u16 vport, bool spoofchk);
1edc57e2 308int mlx5_eswitch_set_vport_trust(struct mlx5_eswitch *esw,
02f3afd9
PP
309 u16 vport_num, bool setting);
310int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, u16 vport,
c9497c98 311 u32 max_rate, u32 min_rate);
8da202b2
HN
312int mlx5_eswitch_set_vepa(struct mlx5_eswitch *esw, u8 setting);
313int mlx5_eswitch_get_vepa(struct mlx5_eswitch *esw, u8 *setting);
77256579 314int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
02f3afd9 315 u16 vport, struct ifla_vf_info *ivi);
3b751a2a 316int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
02f3afd9 317 u16 vport,
3b751a2a 318 struct ifla_vf_stats *vf_stats);
159fe639 319void mlx5_eswitch_del_send_to_vport_rule(struct mlx5_flow_handle *rule);
073bb189 320
238302fa
PP
321int mlx5_eswitch_modify_esw_vport_context(struct mlx5_core_dev *dev, u16 vport,
322 bool other_vport,
57843868 323 void *in, int inlen);
238302fa
PP
324int mlx5_eswitch_query_esw_vport_context(struct mlx5_core_dev *dev, u16 vport,
325 bool other_vport,
57843868
JL
326 void *out, int outlen);
327
3d80d1a2 328struct mlx5_flow_spec;
776b12b6 329struct mlx5_esw_flow_attr;
10caabda
OS
330struct mlx5_termtbl_handle;
331
332bool
333mlx5_eswitch_termtbl_required(struct mlx5_eswitch *esw,
334 struct mlx5_flow_act *flow_act,
335 struct mlx5_flow_spec *spec);
336
337struct mlx5_flow_handle *
338mlx5_eswitch_add_termtbl_rule(struct mlx5_eswitch *esw,
339 struct mlx5_flow_table *ft,
340 struct mlx5_flow_spec *spec,
341 struct mlx5_esw_flow_attr *attr,
342 struct mlx5_flow_act *flow_act,
343 struct mlx5_flow_destination *dest,
344 int num_dest);
345
346void
347mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw,
348 struct mlx5_termtbl_handle *tt);
3d80d1a2 349
74491de9 350struct mlx5_flow_handle *
3d80d1a2
OG
351mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
352 struct mlx5_flow_spec *spec,
776b12b6 353 struct mlx5_esw_flow_attr *attr);
e4ad91f2
CM
354struct mlx5_flow_handle *
355mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,
356 struct mlx5_flow_spec *spec,
357 struct mlx5_esw_flow_attr *attr);
d85cdccb
OG
358void
359mlx5_eswitch_del_offloaded_rule(struct mlx5_eswitch *esw,
360 struct mlx5_flow_handle *rule,
361 struct mlx5_esw_flow_attr *attr);
48265006
OG
362void
363mlx5_eswitch_del_fwd_rule(struct mlx5_eswitch *esw,
364 struct mlx5_flow_handle *rule,
365 struct mlx5_esw_flow_attr *attr);
d85cdccb 366
74491de9 367struct mlx5_flow_handle *
02f3afd9 368mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, u16 vport,
c966f7d5 369 struct mlx5_flow_destination *dest);
fed9ce22 370
e33dfe31
OG
371enum {
372 SET_VLAN_STRIP = BIT(0),
373 SET_VLAN_INSERT = BIT(1)
374};
375
d708f902
OG
376enum mlx5_flow_match_level {
377 MLX5_MATCH_NONE = MLX5_INLINE_MODE_NONE,
378 MLX5_MATCH_L2 = MLX5_INLINE_MODE_L2,
379 MLX5_MATCH_L3 = MLX5_INLINE_MODE_IP,
380 MLX5_MATCH_L4 = MLX5_INLINE_MODE_TCP_UDP,
381};
382
592d3651
CM
383/* current maximum for flow based vport multicasting */
384#define MLX5_MAX_FLOW_FWD_VPORTS 2
385
f493f155
EB
386enum {
387 MLX5_ESW_DEST_ENCAP = BIT(0),
8c4dc42b 388 MLX5_ESW_DEST_ENCAP_VALID = BIT(1),
f493f155
EB
389};
390
39ac237c
PB
391enum {
392 MLX5_ESW_ATTR_FLAG_VLAN_HANDLED = BIT(0),
393 MLX5_ESW_ATTR_FLAG_SLOW_PATH = BIT(1),
6fb0701a 394 MLX5_ESW_ATTR_FLAG_NO_IN_PORT = BIT(2),
39ac237c
PB
395};
396
776b12b6
OG
397struct mlx5_esw_flow_attr {
398 struct mlx5_eswitch_rep *in_rep;
10ff5359 399 struct mlx5_core_dev *in_mdev;
f9392795 400 struct mlx5_core_dev *counter_dev;
776b12b6 401
e85e02ba 402 int split_count;
592d3651
CM
403 int out_count;
404
776b12b6 405 int action;
cc495188
JL
406 __be16 vlan_proto[MLX5_FS_VLAN_DEPTH];
407 u16 vlan_vid[MLX5_FS_VLAN_DEPTH];
408 u8 vlan_prio[MLX5_FS_VLAN_DEPTH];
409 u8 total_vlan;
df65a573 410 struct {
f493f155 411 u32 flags;
df65a573 412 struct mlx5_eswitch_rep *rep;
2b688ea5 413 struct mlx5_pkt_reformat *pkt_reformat;
df65a573 414 struct mlx5_core_dev *mdev;
10caabda 415 struct mlx5_termtbl_handle *termtbl;
df65a573 416 } dests[MLX5_MAX_FLOW_FWD_VPORTS];
2b688ea5 417 struct mlx5_modify_hdr *modify_hdr;
93b3586e
HN
418 u8 inner_match_level;
419 u8 outer_match_level;
b8aee822 420 struct mlx5_fc *counter;
e52c2802
PB
421 u32 chain;
422 u16 prio;
423 u32 dest_chain;
39ac237c 424 u32 flags;
d18296ff
PB
425 struct mlx5_flow_table *fdb;
426 struct mlx5_flow_table *dest_ft;
232c0013 427 struct mlx5e_tc_flow_parse_attr *parse_attr;
776b12b6
OG
428};
429
db7ff19e
EB
430int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
431 struct netlink_ext_ack *extack);
feae9087 432int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode);
db7ff19e
EB
433int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode,
434 struct netlink_ext_ack *extack);
bffaa916 435int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode);
98fdbea5
LR
436int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
437 enum devlink_eswitch_encap_mode encap,
db7ff19e 438 struct netlink_ext_ack *extack);
98fdbea5
LR
439int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
440 enum devlink_eswitch_encap_mode *encap);
a4b97ab4 441void *mlx5_eswitch_get_uplink_priv(struct mlx5_eswitch *esw, u8 rep_type);
feae9087 442
f5f82476
OG
443int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
444 struct mlx5_esw_flow_attr *attr);
445int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
446 struct mlx5_esw_flow_attr *attr);
447int __mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
02f3afd9 448 u16 vport, u16 vlan, u8 qos, u8 set_flags);
f5f82476 449
fdde49e0
PP
450int mlx5_esw_create_vport_egress_acl_vlan(struct mlx5_eswitch *esw,
451 struct mlx5_vport *vport,
452 u16 vlan_id, u32 flow_action);
453
cc495188
JL
454static inline bool mlx5_eswitch_vlan_actions_supported(struct mlx5_core_dev *dev,
455 u8 vlan_depth)
6acfbf38 456{
cc495188
JL
457 bool ret = MLX5_CAP_ESW_FLOWTABLE_FDB(dev, pop_vlan) &&
458 MLX5_CAP_ESW_FLOWTABLE_FDB(dev, push_vlan);
459
460 if (vlan_depth == 1)
461 return ret;
462
463 return ret && MLX5_CAP_ESW_FLOWTABLE_FDB(dev, pop_vlan_2) &&
464 MLX5_CAP_ESW_FLOWTABLE_FDB(dev, push_vlan_2);
6acfbf38
OG
465}
466
eff849b2
RL
467bool mlx5_esw_lag_prereq(struct mlx5_core_dev *dev0,
468 struct mlx5_core_dev *dev1);
544fe7c2
RD
469bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0,
470 struct mlx5_core_dev *dev1);
eff849b2 471
dd28087c 472const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev);
cd56f929 473
69697b6e
OG
474#define MLX5_DEBUG_ESWITCH_MASK BIT(3)
475
27b942fb
PP
476#define esw_info(__dev, format, ...) \
477 dev_info((__dev)->device, "E-Switch: " format, ##__VA_ARGS__)
69697b6e 478
27b942fb
PP
479#define esw_warn(__dev, format, ...) \
480 dev_warn((__dev)->device, "E-Switch: " format, ##__VA_ARGS__)
69697b6e
OG
481
482#define esw_debug(dev, format, ...) \
483 mlx5_core_dbg_mask(dev, MLX5_DEBUG_ESWITCH_MASK, format, ##__VA_ARGS__)
a1b3839a
BW
484
485/* The returned number is valid only when the dev is eswitch manager. */
486static inline u16 mlx5_eswitch_manager_vport(struct mlx5_core_dev *dev)
487{
488 return mlx5_core_is_ecpf_esw_manager(dev) ?
489 MLX5_VPORT_ECPF : MLX5_VPORT_PF;
490}
491
ea2300e0
PP
492static inline bool
493mlx5_esw_is_manager_vport(const struct mlx5_eswitch *esw, u16 vport_num)
494{
495 return esw->manager_vport == vport_num;
496}
497
411ec9e0
BW
498static inline u16 mlx5_eswitch_first_host_vport_num(struct mlx5_core_dev *dev)
499{
500 return mlx5_core_is_ecpf_esw_manager(dev) ?
501 MLX5_VPORT_PF : MLX5_VPORT_FIRST_VF;
502}
503
6706a3b9
VP
504static inline bool mlx5_eswitch_is_funcs_handler(struct mlx5_core_dev *dev)
505{
506 /* Ideally device should have the functions changed supported
507 * capability regardless of it being ECPF or PF wherever such
508 * event should be processed such as on eswitch manager device.
509 * However, some ECPF based device might not have this capability
510 * set. Hence OR for ECPF check to cover such device.
511 */
512 return MLX5_CAP_ESW(dev, esw_functions_changed) ||
513 mlx5_core_is_ecpf_esw_manager(dev);
514}
515
5ae51620
BW
516static inline int mlx5_eswitch_uplink_idx(struct mlx5_eswitch *esw)
517{
518 /* Uplink always locate at the last element of the array.*/
519 return esw->total_vports - 1;
520}
521
81cd229c
BW
522static inline int mlx5_eswitch_ecpf_idx(struct mlx5_eswitch *esw)
523{
524 return esw->total_vports - 2;
525}
526
5ae51620
BW
527static inline int mlx5_eswitch_vport_num_to_index(struct mlx5_eswitch *esw,
528 u16 vport_num)
529{
81cd229c
BW
530 if (vport_num == MLX5_VPORT_ECPF) {
531 if (!mlx5_ecpf_vport_exists(esw->dev))
532 esw_warn(esw->dev, "ECPF vport doesn't exist!\n");
533 return mlx5_eswitch_ecpf_idx(esw);
534 }
535
5ae51620
BW
536 if (vport_num == MLX5_VPORT_UPLINK)
537 return mlx5_eswitch_uplink_idx(esw);
538
539 return vport_num;
540}
541
02f3afd9 542static inline u16 mlx5_eswitch_index_to_vport_num(struct mlx5_eswitch *esw,
5ae51620
BW
543 int index)
544{
81cd229c
BW
545 if (index == mlx5_eswitch_ecpf_idx(esw) &&
546 mlx5_ecpf_vport_exists(esw->dev))
547 return MLX5_VPORT_ECPF;
548
5ae51620
BW
549 if (index == mlx5_eswitch_uplink_idx(esw))
550 return MLX5_VPORT_UPLINK;
551
552 return index;
553}
554
ee576ec1
SM
555/* TODO: This mlx5e_tc function shouldn't be called by eswitch */
556void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
557
786ef904
PP
558/* The vport getter/iterator are only valid after esw->total_vports
559 * and vport->vport are initialized in mlx5_eswitch_init.
560 */
561#define mlx5_esw_for_all_vports(esw, i, vport) \
562 for ((i) = MLX5_VPORT_PF; \
563 (vport) = &(esw)->vports[i], \
564 (i) < (esw)->total_vports; (i)++)
565
5019833d
PP
566#define mlx5_esw_for_all_vports_reverse(esw, i, vport) \
567 for ((i) = (esw)->total_vports - 1; \
568 (vport) = &(esw)->vports[i], \
569 (i) >= MLX5_VPORT_PF; (i)--)
570
786ef904
PP
571#define mlx5_esw_for_each_vf_vport(esw, i, vport, nvfs) \
572 for ((i) = MLX5_VPORT_FIRST_VF; \
573 (vport) = &(esw)->vports[(i)], \
574 (i) <= (nvfs); (i)++)
575
576#define mlx5_esw_for_each_vf_vport_reverse(esw, i, vport, nvfs) \
577 for ((i) = (nvfs); \
578 (vport) = &(esw)->vports[(i)], \
579 (i) >= MLX5_VPORT_FIRST_VF; (i)--)
580
581/* The rep getter/iterator are only valid after esw->total_vports
582 * and vport->vport are initialized in mlx5_eswitch_init.
583 */
584#define mlx5_esw_for_all_reps(esw, i, rep) \
585 for ((i) = MLX5_VPORT_PF; \
586 (rep) = &(esw)->offloads.vport_reps[i], \
587 (i) < (esw)->total_vports; (i)++)
588
589#define mlx5_esw_for_each_vf_rep(esw, i, rep, nvfs) \
590 for ((i) = MLX5_VPORT_FIRST_VF; \
591 (rep) = &(esw)->offloads.vport_reps[i], \
592 (i) <= (nvfs); (i)++)
593
594#define mlx5_esw_for_each_vf_rep_reverse(esw, i, rep, nvfs) \
595 for ((i) = (nvfs); \
596 (rep) = &(esw)->offloads.vport_reps[i], \
597 (i) >= MLX5_VPORT_FIRST_VF; (i)--)
598
599#define mlx5_esw_for_each_vf_vport_num(esw, vport, nvfs) \
600 for ((vport) = MLX5_VPORT_FIRST_VF; (vport) <= (nvfs); (vport)++)
601
602#define mlx5_esw_for_each_vf_vport_num_reverse(esw, vport, nvfs) \
603 for ((vport) = (nvfs); (vport) >= MLX5_VPORT_FIRST_VF; (vport)--)
604
411ec9e0
BW
605/* Includes host PF (vport 0) if it's not esw manager. */
606#define mlx5_esw_for_each_host_func_rep(esw, i, rep, nvfs) \
607 for ((i) = (esw)->first_host_vport; \
608 (rep) = &(esw)->offloads.vport_reps[i], \
609 (i) <= (nvfs); (i)++)
610
611#define mlx5_esw_for_each_host_func_rep_reverse(esw, i, rep, nvfs) \
612 for ((i) = (nvfs); \
613 (rep) = &(esw)->offloads.vport_reps[i], \
614 (i) >= (esw)->first_host_vport; (i)--)
615
616#define mlx5_esw_for_each_host_func_vport(esw, vport, nvfs) \
617 for ((vport) = (esw)->first_host_vport; \
618 (vport) <= (nvfs); (vport)++)
619
620#define mlx5_esw_for_each_host_func_vport_reverse(esw, vport, nvfs) \
621 for ((vport) = (nvfs); \
622 (vport) >= (esw)->first_host_vport; (vport)--)
623
5d9986a3
BW
624struct mlx5_vport *__must_check
625mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);
626
91d6291c
PP
627bool mlx5_eswitch_is_vf_vport(const struct mlx5_eswitch *esw, u16 vport_num);
628
062f4bf4 629void mlx5_eswitch_update_num_of_vfs(struct mlx5_eswitch *esw, const int num_vfs);
16fff98a 630int mlx5_esw_funcs_changed_handler(struct notifier_block *nb, unsigned long type, void *data);
062f4bf4 631
925a6acc 632int
5019833d
PP
633mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw,
634 enum mlx5_eswitch_vport_event enabled_events);
635void mlx5_eswitch_disable_pf_vf_vports(struct mlx5_eswitch *esw);
636
748da30b
VP
637int
638esw_vport_create_offloads_acl_tables(struct mlx5_eswitch *esw,
639 struct mlx5_vport *vport);
640void
641esw_vport_destroy_offloads_acl_tables(struct mlx5_eswitch *esw,
642 struct mlx5_vport *vport);
643
96e32687
EC
644int mlx5_esw_vport_tbl_get(struct mlx5_eswitch *esw);
645void mlx5_esw_vport_tbl_put(struct mlx5_eswitch *esw);
646
11b717d6
PB
647struct mlx5_flow_handle *
648esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag);
649u32
650esw_get_max_restore_tag(struct mlx5_eswitch *esw);
651
e80541ec
SM
652#else /* CONFIG_MLX5_ESWITCH */
653/* eswitch API stubs */
654static inline int mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
655static inline void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw) {}
062f4bf4 656static inline int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int mode) { return 0; }
556b9d16 657static inline void mlx5_eswitch_disable(struct mlx5_eswitch *esw, bool clear_vf) {}
eff849b2 658static inline bool mlx5_esw_lag_prereq(struct mlx5_core_dev *dev0, struct mlx5_core_dev *dev1) { return true; }
6706a3b9 659static inline bool mlx5_eswitch_is_funcs_handler(struct mlx5_core_dev *dev) { return false; }
dd28087c 660static inline const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev)
10ee82ce 661{
dd28087c 662 return ERR_PTR(-EOPNOTSUPP);
10ee82ce 663}
328edb49 664
062f4bf4
BW
665static inline void mlx5_eswitch_update_num_of_vfs(struct mlx5_eswitch *esw, const int num_vfs) {}
666
11b717d6
PB
667static struct mlx5_flow_handle *
668esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag)
669{
670 return ERR_PTR(-EOPNOTSUPP);
671}
672
e80541ec
SM
673#endif /* CONFIG_MLX5_ESWITCH */
674
073bb189 675#endif /* __MLX5_ESWITCH_H__ */