1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
9 static const struct mlx5_ib_profile rep_profile = {
10 STAGE_CREATE(MLX5_IB_STAGE_INIT,
11 mlx5_ib_stage_init_init,
12 mlx5_ib_stage_init_cleanup),
13 STAGE_CREATE(MLX5_IB_STAGE_FLOW_DB,
14 mlx5_ib_stage_rep_flow_db_init,
16 STAGE_CREATE(MLX5_IB_STAGE_CAPS,
17 mlx5_ib_stage_caps_init,
19 STAGE_CREATE(MLX5_IB_STAGE_NON_DEFAULT_CB,
20 mlx5_ib_stage_rep_non_default_cb,
22 STAGE_CREATE(MLX5_IB_STAGE_ROCE,
23 mlx5_ib_stage_rep_roce_init,
24 mlx5_ib_stage_rep_roce_cleanup),
25 STAGE_CREATE(MLX5_IB_STAGE_SRQ,
27 mlx5_cleanup_srq_table),
28 STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
29 mlx5_ib_stage_dev_res_init,
30 mlx5_ib_stage_dev_res_cleanup),
31 STAGE_CREATE(MLX5_IB_STAGE_COUNTERS,
32 mlx5_ib_stage_counters_init,
33 mlx5_ib_stage_counters_cleanup),
34 STAGE_CREATE(MLX5_IB_STAGE_BFREG,
35 mlx5_ib_stage_bfrag_init,
36 mlx5_ib_stage_bfrag_cleanup),
37 STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR,
39 mlx5_ib_stage_pre_ib_reg_umr_cleanup),
40 STAGE_CREATE(MLX5_IB_STAGE_IB_REG,
41 mlx5_ib_stage_ib_reg_init,
42 mlx5_ib_stage_ib_reg_cleanup),
43 STAGE_CREATE(MLX5_IB_STAGE_POST_IB_REG_UMR,
44 mlx5_ib_stage_post_ib_reg_umr_init,
49 mlx5_ib_nic_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
51 struct mlx5_ib_dev *ibdev;
53 ibdev = mlx5_ib_rep_to_dev(rep);
54 if (!__mlx5_ib_add(ibdev, ibdev->profile))
60 mlx5_ib_nic_rep_unload(struct mlx5_eswitch_rep *rep)
62 struct mlx5_ib_dev *ibdev;
64 ibdev = mlx5_ib_rep_to_dev(rep);
65 __mlx5_ib_remove(ibdev, ibdev->profile, MLX5_IB_STAGE_MAX);
69 mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
71 struct mlx5_ib_dev *ibdev;
73 ibdev = (struct mlx5_ib_dev *)ib_alloc_device(sizeof(*ibdev));
79 ibdev->num_ports = max(MLX5_CAP_GEN(dev, num_ports),
80 MLX5_CAP_GEN(dev, num_vhca_ports));
81 if (!__mlx5_ib_add(ibdev, &rep_profile))
84 rep->rep_if[REP_IB].priv = ibdev;
90 mlx5_ib_vport_rep_unload(struct mlx5_eswitch_rep *rep)
92 struct mlx5_ib_dev *dev;
94 if (!rep->rep_if[REP_IB].priv)
97 dev = mlx5_ib_rep_to_dev(rep);
98 __mlx5_ib_remove(dev, dev->profile, MLX5_IB_STAGE_MAX);
99 rep->rep_if[REP_IB].priv = NULL;
100 ib_dealloc_device(&dev->ib_dev);
103 static void *mlx5_ib_vport_get_proto_dev(struct mlx5_eswitch_rep *rep)
105 return mlx5_ib_rep_to_dev(rep);
108 static void mlx5_ib_rep_register_vf_vports(struct mlx5_ib_dev *dev)
110 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
111 int total_vfs = MLX5_TOTAL_VPORTS(dev->mdev);
114 for (vport = 1; vport < total_vfs; vport++) {
115 struct mlx5_eswitch_rep_if rep_if = {};
117 rep_if.load = mlx5_ib_vport_rep_load;
118 rep_if.unload = mlx5_ib_vport_rep_unload;
119 rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
120 mlx5_eswitch_register_vport_rep(esw, vport, &rep_if, REP_IB);
124 static void mlx5_ib_rep_unregister_vf_vports(struct mlx5_ib_dev *dev)
126 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
127 int total_vfs = MLX5_TOTAL_VPORTS(dev->mdev);
130 for (vport = 1; vport < total_vfs; vport++)
131 mlx5_eswitch_unregister_vport_rep(esw, vport, REP_IB);
134 void mlx5_ib_register_vport_reps(struct mlx5_ib_dev *dev)
136 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
137 struct mlx5_eswitch_rep_if rep_if = {};
139 rep_if.load = mlx5_ib_nic_rep_load;
140 rep_if.unload = mlx5_ib_nic_rep_unload;
141 rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
144 mlx5_eswitch_register_vport_rep(esw, 0, &rep_if, REP_IB);
146 mlx5_ib_rep_register_vf_vports(dev);
149 void mlx5_ib_unregister_vport_reps(struct mlx5_ib_dev *dev)
151 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
153 mlx5_ib_rep_unregister_vf_vports(dev); /* VFs vports */
154 mlx5_eswitch_unregister_vport_rep(esw, 0, REP_IB); /* UPLINK PF*/
157 u8 mlx5_ib_eswitch_mode(struct mlx5_eswitch *esw)
159 return mlx5_eswitch_mode(esw);
162 struct mlx5_ib_dev *mlx5_ib_get_rep_ibdev(struct mlx5_eswitch *esw,
165 return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_IB);
168 struct net_device *mlx5_ib_get_rep_netdev(struct mlx5_eswitch *esw,
171 return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_ETH);
174 struct mlx5_ib_dev *mlx5_ib_get_uplink_ibdev(struct mlx5_eswitch *esw)
176 return mlx5_eswitch_uplink_get_proto_dev(esw, REP_IB);
179 struct mlx5_eswitch_rep *mlx5_ib_vport_rep(struct mlx5_eswitch *esw, int vport)
181 return mlx5_eswitch_vport_rep(esw, vport);
184 int create_flow_rule_vport_sq(struct mlx5_ib_dev *dev,
185 struct mlx5_ib_sq *sq)
187 struct mlx5_flow_handle *flow_rule;
188 struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
194 mlx5_eswitch_add_send_to_vport_rule(esw,
197 if (IS_ERR(flow_rule))
198 return PTR_ERR(flow_rule);
199 sq->flow_rule = flow_rule;