Skip to content

Commit 7ecf6d8

Browse files
BodongWangdledford
authored andcommitted
IB/mlx5: Restore IB guid/policy for virtual functions
When a user sets port_guid, node_guid or policy of an IB virtual function, save this information in "struct mlx5_vf_context". This information will be restored later when pci_resume is called. To make sure this works, one can use aer-inject to generate PCI errors on mlx5 devices and verify if relevant fields are restored after PCI resume. Signed-off-by: Bodong Wang <bodong@mellanox.com> Reviewed-by: Eli Cohen <eli@mellanox.com> Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 4a2da0b commit 7ecf6d8

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

drivers/infiniband/hw/mlx5/ib_virt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
9696
struct mlx5_ib_dev *dev = to_mdev(device);
9797
struct mlx5_core_dev *mdev = dev->mdev;
9898
struct mlx5_hca_vport_context *in;
99+
struct mlx5_vf_context *vfs_ctx = mdev->priv.sriov.vfs_ctx;
99100
int err;
100101

101102
in = kzalloc(sizeof(*in), GFP_KERNEL);
@@ -109,6 +110,8 @@ int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
109110
}
110111
in->field_select = MLX5_HCA_VPORT_SEL_STATE_POLICY;
111112
err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
113+
if (!err)
114+
vfs_ctx[vf].policy = in->policy;
112115

113116
out:
114117
kfree(in);
@@ -151,6 +154,7 @@ static int set_vf_node_guid(struct ib_device *device, int vf, u8 port, u64 guid)
151154
struct mlx5_ib_dev *dev = to_mdev(device);
152155
struct mlx5_core_dev *mdev = dev->mdev;
153156
struct mlx5_hca_vport_context *in;
157+
struct mlx5_vf_context *vfs_ctx = mdev->priv.sriov.vfs_ctx;
154158
int err;
155159

156160
in = kzalloc(sizeof(*in), GFP_KERNEL);
@@ -160,6 +164,8 @@ static int set_vf_node_guid(struct ib_device *device, int vf, u8 port, u64 guid)
160164
in->field_select = MLX5_HCA_VPORT_SEL_NODE_GUID;
161165
in->node_guid = guid;
162166
err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
167+
if (!err)
168+
vfs_ctx[vf].node_guid = guid;
163169
kfree(in);
164170
return err;
165171
}
@@ -169,6 +175,7 @@ static int set_vf_port_guid(struct ib_device *device, int vf, u8 port, u64 guid)
169175
struct mlx5_ib_dev *dev = to_mdev(device);
170176
struct mlx5_core_dev *mdev = dev->mdev;
171177
struct mlx5_hca_vport_context *in;
178+
struct mlx5_vf_context *vfs_ctx = mdev->priv.sriov.vfs_ctx;
172179
int err;
173180

174181
in = kzalloc(sizeof(*in), GFP_KERNEL);
@@ -178,6 +185,8 @@ static int set_vf_port_guid(struct ib_device *device, int vf, u8 port, u64 guid)
178185
in->field_select = MLX5_HCA_VPORT_SEL_PORT_GUID;
179186
in->port_guid = guid;
180187
err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
188+
if (!err)
189+
vfs_ctx[vf].port_guid = guid;
181190
kfree(in);
182191
return err;
183192
}

drivers/net/ethernet/mellanox/mlx5/core/sriov.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <linux/pci.h>
3434
#include <linux/mlx5/driver.h>
35+
#include <linux/mlx5/vport.h>
3536
#include "mlx5_core.h"
3637
#ifdef CONFIG_MLX5_CORE_EN
3738
#include "eswitch.h"
@@ -44,6 +45,38 @@ bool mlx5_sriov_is_enabled(struct mlx5_core_dev *dev)
4445
return !!sriov->num_vfs;
4546
}
4647

48+
static int sriov_restore_guids(struct mlx5_core_dev *dev, int vf)
49+
{
50+
struct mlx5_core_sriov *sriov = &dev->priv.sriov;
51+
struct mlx5_hca_vport_context *in;
52+
int err = 0;
53+
54+
/* Restore sriov guid and policy settings */
55+
if (sriov->vfs_ctx[vf].node_guid ||
56+
sriov->vfs_ctx[vf].port_guid ||
57+
sriov->vfs_ctx[vf].policy != MLX5_POLICY_INVALID) {
58+
in = kzalloc(sizeof(*in), GFP_KERNEL);
59+
if (!in)
60+
return -ENOMEM;
61+
62+
in->node_guid = sriov->vfs_ctx[vf].node_guid;
63+
in->port_guid = sriov->vfs_ctx[vf].port_guid;
64+
in->policy = sriov->vfs_ctx[vf].policy;
65+
in->field_select =
66+
!!(in->port_guid) * MLX5_HCA_VPORT_SEL_PORT_GUID |
67+
!!(in->node_guid) * MLX5_HCA_VPORT_SEL_NODE_GUID |
68+
!!(in->policy) * MLX5_HCA_VPORT_SEL_STATE_POLICY;
69+
70+
err = mlx5_core_modify_hca_vport_context(dev, 1, 1, vf + 1, in);
71+
if (err)
72+
mlx5_core_warn(dev, "modify vport context failed, unable to restore VF %d settings\n", vf);
73+
74+
kfree(in);
75+
}
76+
77+
return err;
78+
}
79+
4780
static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
4881
{
4982
struct mlx5_core_sriov *sriov = &dev->priv.sriov;
@@ -74,6 +107,15 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
74107
}
75108
sriov->vfs_ctx[vf].enabled = 1;
76109
sriov->enabled_vfs++;
110+
if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) {
111+
err = sriov_restore_guids(dev, vf);
112+
if (err) {
113+
mlx5_core_warn(dev,
114+
"failed to restore VF %d settings, err %d\n",
115+
vf, err);
116+
continue;
117+
}
118+
}
77119
mlx5_core_dbg(dev, "successfully enabled VF* %d\n", vf);
78120

79121
}

include/linux/mlx5/driver.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ enum dbg_rsc_type {
162162
MLX5_DBG_RSC_CQ,
163163
};
164164

165+
enum port_state_policy {
166+
MLX5_POLICY_DOWN = 0,
167+
MLX5_POLICY_UP = 1,
168+
MLX5_POLICY_FOLLOW = 2,
169+
MLX5_POLICY_INVALID = 0xffffffff
170+
};
171+
165172
struct mlx5_field_desc {
166173
struct dentry *dent;
167174
int i;
@@ -525,6 +532,9 @@ struct mlx5_mkey_table {
525532

526533
struct mlx5_vf_context {
527534
int enabled;
535+
u64 port_guid;
536+
u64 node_guid;
537+
enum port_state_policy policy;
528538
};
529539

530540
struct mlx5_core_sriov {
@@ -842,13 +852,6 @@ struct mlx5_pas {
842852
u8 log_sz;
843853
};
844854

845-
enum port_state_policy {
846-
MLX5_POLICY_DOWN = 0,
847-
MLX5_POLICY_UP = 1,
848-
MLX5_POLICY_FOLLOW = 2,
849-
MLX5_POLICY_INVALID = 0xffffffff
850-
};
851-
852855
enum phy_port_state {
853856
MLX5_AAA_111
854857
};

0 commit comments

Comments
 (0)