Skip to content

Commit fc385b7

Browse files
mark-blochSaeed Mahameed
authored andcommitted
IB/mlx5: Add basic regiser/unregister representors code
Create the basic infrastructure of registering and unregistering IB representors. The load/unload callbacks are left empty and proper implementation will be introduced in following patches. Signed-off-by: Mark Bloch <[email protected]> Reviewed-by: Or Gerlitz <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 5e65b02 commit fc385b7

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

drivers/infiniband/hw/mlx5/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o
22

33
mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o ib_virt.o cmd.o cong.o
44
mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o
5+
mlx5_ib-$(CONFIG_MLX5_ESWITCH) += ib_rep.o

drivers/infiniband/hw/mlx5/ib_rep.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2+
/*
3+
* Copyright (c) 2018 Mellanox Technologies. All rights reserved.
4+
*/
5+
6+
#include "ib_rep.h"
7+
8+
static int
9+
mlx5_ib_nic_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
10+
{
11+
return 0;
12+
}
13+
14+
static void
15+
mlx5_ib_nic_rep_unload(struct mlx5_eswitch_rep *rep)
16+
{
17+
}
18+
19+
static int
20+
mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
21+
{
22+
return 0;
23+
}
24+
25+
static void
26+
mlx5_ib_vport_rep_unload(struct mlx5_eswitch_rep *rep)
27+
{
28+
}
29+
30+
static void *mlx5_ib_vport_get_proto_dev(struct mlx5_eswitch_rep *rep)
31+
{
32+
return mlx5_ib_rep_to_dev(rep);
33+
}
34+
35+
static void mlx5_ib_rep_register_vf_vports(struct mlx5_ib_dev *dev)
36+
{
37+
struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
38+
int total_vfs = MLX5_TOTAL_VPORTS(dev->mdev);
39+
int vport;
40+
41+
for (vport = 1; vport < total_vfs; vport++) {
42+
struct mlx5_eswitch_rep_if rep_if = {};
43+
44+
rep_if.load = mlx5_ib_vport_rep_load;
45+
rep_if.unload = mlx5_ib_vport_rep_unload;
46+
rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
47+
mlx5_eswitch_register_vport_rep(esw, vport, &rep_if, REP_IB);
48+
}
49+
}
50+
51+
static void mlx5_ib_rep_unregister_vf_vports(struct mlx5_ib_dev *dev)
52+
{
53+
struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
54+
int total_vfs = MLX5_TOTAL_VPORTS(dev->mdev);
55+
int vport;
56+
57+
for (vport = 1; vport < total_vfs; vport++)
58+
mlx5_eswitch_unregister_vport_rep(esw, vport, REP_IB);
59+
}
60+
61+
void mlx5_ib_register_vport_reps(struct mlx5_ib_dev *dev)
62+
{
63+
struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
64+
struct mlx5_eswitch_rep_if rep_if = {};
65+
66+
rep_if.load = mlx5_ib_nic_rep_load;
67+
rep_if.unload = mlx5_ib_nic_rep_unload;
68+
rep_if.get_proto_dev = mlx5_ib_vport_get_proto_dev;
69+
rep_if.priv = dev;
70+
71+
mlx5_eswitch_register_vport_rep(esw, 0, &rep_if, REP_IB);
72+
73+
mlx5_ib_rep_register_vf_vports(dev);
74+
}
75+
76+
void mlx5_ib_unregister_vport_reps(struct mlx5_ib_dev *dev)
77+
{
78+
struct mlx5_eswitch *esw = dev->mdev->priv.eswitch;
79+
80+
mlx5_ib_rep_unregister_vf_vports(dev); /* VFs vports */
81+
mlx5_eswitch_unregister_vport_rep(esw, 0, REP_IB); /* UPLINK PF*/
82+
}
83+
84+
u8 mlx5_ib_eswitch_mode(struct mlx5_eswitch *esw)
85+
{
86+
return mlx5_eswitch_mode(esw);
87+
}
88+
89+
struct mlx5_ib_dev *mlx5_ib_get_rep_ibdev(struct mlx5_eswitch *esw,
90+
int vport_index)
91+
{
92+
return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_IB);
93+
}
94+
95+
struct net_device *mlx5_ib_get_rep_netdev(struct mlx5_eswitch *esw,
96+
int vport_index)
97+
{
98+
return mlx5_eswitch_get_proto_dev(esw, vport_index, REP_ETH);
99+
}
100+
101+
struct mlx5_eswitch_rep *mlx5_ib_vport_rep(struct mlx5_eswitch *esw, int vport)
102+
{
103+
return mlx5_eswitch_vport_rep(esw, vport);
104+
}

drivers/infiniband/hw/mlx5/ib_rep.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_IB_REP_H__
7+
#define __MLX5_IB_REP_H__
8+
9+
#include <linux/mlx5/eswitch.h>
10+
#include "mlx5_ib.h"
11+
12+
#ifdef CONFIG_MLX5_ESWITCH
13+
u8 mlx5_ib_eswitch_mode(struct mlx5_eswitch *esw);
14+
struct mlx5_ib_dev *mlx5_ib_get_rep_ibdev(struct mlx5_eswitch *esw,
15+
int vport_index);
16+
struct mlx5_eswitch_rep *mlx5_ib_vport_rep(struct mlx5_eswitch *esw,
17+
int vport_index);
18+
void mlx5_ib_register_vport_reps(struct mlx5_ib_dev *dev);
19+
void mlx5_ib_unregister_vport_reps(struct mlx5_ib_dev *dev);
20+
#else /* CONFIG_MLX5_ESWITCH */
21+
static inline u8 mlx5_ib_eswitch_mode(struct mlx5_eswitch *esw)
22+
{
23+
return SRIOV_NONE;
24+
}
25+
26+
static inline
27+
struct mlx5_ib_dev *mlx5_ib_get_rep_ibdev(struct mlx5_eswitch *esw,
28+
int vport_index)
29+
{
30+
return NULL;
31+
}
32+
33+
static inline
34+
struct mlx5_eswitch_rep *mlx5_ib_vport_rep(struct mlx5_eswitch *esw,
35+
int vport_index)
36+
{
37+
return NULL;
38+
}
39+
40+
static inline void mlx5_ib_register_vport_reps(struct mlx5_ib_dev *dev) {}
41+
static inline void mlx5_ib_unregister_vport_reps(struct mlx5_ib_dev *dev) {}
42+
#endif
43+
44+
static inline
45+
struct mlx5_ib_dev *mlx5_ib_rep_to_dev(struct mlx5_eswitch_rep *rep)
46+
{
47+
return (struct mlx5_ib_dev *)rep->rep_if[REP_IB].priv;
48+
}
49+
#endif /* __MLX5_IB_REP_H__ */

drivers/infiniband/hw/mlx5/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/in.h>
5858
#include <linux/etherdevice.h>
5959
#include "mlx5_ib.h"
60+
#include "ib_rep.h"
6061
#include "cmd.h"
6162

6263
#define DRIVER_NAME "mlx5_ib"
@@ -4905,6 +4906,18 @@ static int mlx5_ib_stage_class_attr_init(struct mlx5_ib_dev *dev)
49054906
return 0;
49064907
}
49074908

4909+
static int mlx5_ib_stage_rep_reg_init(struct mlx5_ib_dev *dev)
4910+
{
4911+
mlx5_ib_register_vport_reps(dev);
4912+
4913+
return 0;
4914+
}
4915+
4916+
static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev)
4917+
{
4918+
mlx5_ib_unregister_vport_reps(dev);
4919+
}
4920+
49084921
static void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
49094922
const struct mlx5_ib_profile *profile,
49104923
int stage)

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ enum mlx5_ib_stages {
743743
MLX5_IB_STAGE_UMR_RESOURCES,
744744
MLX5_IB_STAGE_DELAY_DROP,
745745
MLX5_IB_STAGE_CLASS_ATTR,
746+
MLX5_IB_STAGE_REP_REG,
746747
MLX5_IB_STAGE_MAX,
747748
};
748749

@@ -807,6 +808,7 @@ struct mlx5_ib_dev {
807808
struct mlx5_sq_bfreg fp_bfreg;
808809
struct mlx5_ib_delay_drop delay_drop;
809810
const struct mlx5_ib_profile *profile;
811+
struct mlx5_eswitch_rep *rep;
810812

811813
/* protect the user_td */
812814
struct mutex lb_mutex;

0 commit comments

Comments
 (0)