1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
6 #include <linux/mlx5/vport.h>
10 static const struct mlx5_ib_profile vf_rep_profile = {
11 STAGE_CREATE(MLX5_IB_STAGE_INIT,
12 mlx5_ib_stage_init_init,
13 mlx5_ib_stage_init_cleanup),
14 STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB,
15 mlx5_ib_stage_rep_flow_db_init,
17 STAGE_CREATE(MLX5_IB_STAGE_CAPS,
18 mlx5_ib_stage_caps_init,
20 STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB,
21 mlx5_ib_stage_rep_non_default_cb,
23 STAGE_CREATE(MLX5_IB_STAGE_ROCE,
24 mlx5_ib_stage_rep_roce_init,
25 mlx5_ib_stage_rep_roce_cleanup),
26 STAGE_CREATE(MLX5_IB_STAGE_SRQ,
28 mlx5_cleanup_srq_table),
29 STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
30 mlx5_ib_stage_dev_res_init,
31 mlx5_ib_stage_dev_res_cleanup),
32 STAGE_CREATE(MLX5_IB_STAGE_COUNTERS,
33 mlx5_ib_stage_counters_init,
34 mlx5_ib_stage_counters_cleanup),
35 STAGE_CREATE(MLX5_IB_STAGE_BFREG,
36 mlx5_ib_stage_bfrag_init,
37 mlx5_ib_stage_bfrag_cleanup),
38 STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR,
40 mlx5_ib_stage_pre_ib_reg_umr_cleanup),
41 STAGE_CREATE(MLX5_IB_STAGE_IB_REG,
42 mlx5_ib_stage_ib_reg_init,
43 mlx5_ib_stage_ib_reg_cleanup),
44 STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR,
45 mlx5_ib_stage_post_ib_reg_umr_init,
50 mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
52 const struct mlx5_ib_profile *profile;
53 struct mlx5_ib_dev *ibdev;
55 if (rep->vport == MLX5_VPORT_UPLINK)
56 profile = &uplink_rep_profile;
58 profile = &vf_rep_profile;
60 ibdev = ib_alloc_device(mlx5_ib_dev, ib_dev);
66 ibdev->num_ports = max(MLX5_CAP_GEN(dev, num_ports),
67 MLX5_CAP_GEN(dev, num_vhca_ports));
68 if (!__mlx5_ib_add(ibdev, profile)) {
69 ib_dealloc_device(&ibdev->ib_dev);
73 rep->rep_if[REP_IB].priv = ibdev;
79 mlx5_ib_vport_rep_unload(struct mlx5_eswitch_rep *rep)
81 struct mlx5_ib_dev *dev;
83 if (!rep->rep_if[REP_IB].priv)
86 dev = mlx5_ib_rep_to_dev(rep);
87 __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX);
88 rep->rep_if[REP_IB].priv = NULL;
89 ib_dealloc_device(&dev->ib_dev);
92 static void *mlx5_ib_vport_get_proto_dev(struct mlx5_eswitch_rep *rep)
94 return mlx5_ib_rep_to_dev(rep);
97 void mlx5_ib_register_vport_reps(struct mlx5_core_dev *mdev)
99 struct mlx5_eswitch *esw = mdev->priv.eswitch;
100 struct mlx5_eswitch_rep_if rep_if = {};
102 rep_if.load = mlx5_ib_vport_rep_load;
103 rep_if.unload = mlx5_ib_vport_rep_unload;
104 rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
106 mlx5_eswitch_register_vport_reps(esw, &rep_if, REP_IB);
109 void mlx5_ib_unregister_vport_reps(struct mlx5_core_dev *mdev)
111 struct mlx5_eswitch *esw = mdev->priv.eswitch;
113 mlx5_eswitch_unregister_vport_reps(esw, REP_IB);
116 u8 mlx5_ib_eswitch_mode(struct mlx5_eswitch *esw)
118 return mlx5_eswitch_mode(esw);
121 struct mlx5_ib_dev *mlx5_ib_get_rep_ibdev(struct mlx5_eswitch *esw,
124 return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_IB);
127 struct net_device *mlx5_ib_get_rep_netdev(struct mlx5_eswitch *esw,
130 return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_ETH);
133 struct mlx5_ib_dev *mlx5_ib_get_uplink_ibdev(struct mlx5_eswitch *esw)
135 return mlx5_eswitch_uplink_get_proto_dev(esw, REP_IB);
138 struct mlx5_eswitch_rep *mlx5_ib_vport_rep(struct mlx5_eswitch *esw, int vport)
140 return mlx5_eswitch_vport_rep(esw, vport);
143 int create_flow_rule_vport_sq(struct mlx5_ib_dev *dev,
144 struct mlx5_ib_sq *sq)
146 struct mlx5_flow_handle *flow_rule;
147 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
153 mlx5_eswitch_add_send_to_vport_rule(esw,
156 if (IS_ERR(flow_rule))
157 return PTR_ERR(flow_rule);
158 sq->flow_rule = flow_rule;