Skip to content

Commit 8a7c321

Browse files
committed
vdpa/mlx5: fix up endian-ness for mtu
VDPA mlx5 accesses config space as native endian - this is wrong since it's a modern device and actually uses LE. It only supports modern guests so we could punt and just force LE, but let's use the full virtio APIs since people tend to copy/paste code, and this is not data path anyway. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent cf16fe9 commit 8a7c321

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct mlx5_vdpa_net {
137137
struct mlx5_fc *rx_counter;
138138
struct mlx5_flow_handle *rx_rule;
139139
bool setup;
140+
u16 mtu;
140141
};
141142

142143
static void free_resources(struct mlx5_vdpa_net *ndev);
@@ -1506,6 +1507,13 @@ static void teardown_virtqueues(struct mlx5_vdpa_net *ndev)
15061507
}
15071508
}
15081509

1510+
/* TODO: cross-endian support */
1511+
static inline bool mlx5_vdpa_is_little_endian(struct mlx5_vdpa_dev *mvdev)
1512+
{
1513+
return virtio_legacy_is_little_endian() ||
1514+
(mvdev->actual_features & (1ULL << VIRTIO_F_VERSION_1));
1515+
}
1516+
15091517
static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
15101518
{
15111519
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -1519,6 +1527,8 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
15191527
return err;
15201528

15211529
ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
1530+
ndev->config.mtu = __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev),
1531+
ndev->mtu);
15221532
return err;
15231533
}
15241534

@@ -1925,7 +1935,7 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
19251935
init_mvqs(ndev);
19261936
mutex_init(&ndev->reslock);
19271937
config = &ndev->config;
1928-
err = mlx5_query_nic_vport_mtu(mdev, &config->mtu);
1938+
err = mlx5_query_nic_vport_mtu(mdev, &ndev->mtu);
19291939
if (err)
19301940
goto err_mtu;
19311941

0 commit comments

Comments
 (0)