1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /*
3  * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
4  */
5 
6 #ifndef _MLX5_ESWITCH_
7 #define _MLX5_ESWITCH_
8 
9 #include <linux/mlx5/driver.h>
10 
11 #define MLX5_ESWITCH_MANAGER(mdev) MLX5_CAP_GEN(mdev, eswitch_manager)
12 
13 enum {
14 	SRIOV_NONE,
15 	SRIOV_LEGACY,
16 	SRIOV_OFFLOADS
17 };
18 
19 enum {
20 	REP_ETH,
21 	REP_IB,
22 	NUM_REP_TYPES,
23 };
24 
25 struct mlx5_eswitch_rep;
26 struct mlx5_eswitch_rep_if {
27 	int		       (*load)(struct mlx5_core_dev *dev,
28 				       struct mlx5_eswitch_rep *rep);
29 	void		       (*unload)(struct mlx5_eswitch_rep *rep);
30 	void		       *(*get_proto_dev)(struct mlx5_eswitch_rep *rep);
31 	void			*priv;
32 	bool		       valid;
33 };
34 
35 struct mlx5_eswitch_rep {
36 	struct mlx5_eswitch_rep_if rep_if[NUM_REP_TYPES];
37 	u16		       vport;
38 	u8		       hw_id[ETH_ALEN];
39 	u16		       vlan;
40 	u32		       vlan_refcount;
41 };
42 
43 void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch *esw,
44 				     int vport_index,
45 				     struct mlx5_eswitch_rep_if *rep_if,
46 				     u8 rep_type);
47 void mlx5_eswitch_unregister_vport_rep(struct mlx5_eswitch *esw,
48 				       int vport_index,
49 				       u8 rep_type);
50 void *mlx5_eswitch_get_proto_dev(struct mlx5_eswitch *esw,
51 				 int vport,
52 				 u8 rep_type);
53 struct mlx5_eswitch_rep *mlx5_eswitch_vport_rep(struct mlx5_eswitch *esw,
54 						int vport);
55 void *mlx5_eswitch_uplink_get_proto_dev(struct mlx5_eswitch *esw, u8 rep_type);
56 u8 mlx5_eswitch_mode(struct mlx5_eswitch *esw);
57 struct mlx5_flow_handle *
58 mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *esw,
59 				    int vport, u32 sqn);
60 #endif
61