Skip to content

Commit deeacf3

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa/mlx5: support device features provisioning
This patch implements features provisioning for mlx5_vdpa. 1) Validate the provisioned features are a subset of the parent features. 2) Clearing features that are not wanted by userspace. For example: # vdpa mgmtdev show pci/0000:41:04.2: supported_classes net max_supported_vqs 65 dev_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 1) Provision vDPA device with all features derived from the parent # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 # vdpa dev config show vdpa1: mac e4:11:c6:d3:45:f0 link up link_announce false max_vq_pairs 1 mtu 1500 negotiated_features CSUM GUEST_CSUM MTU HOST_TSO4 HOST_TSO6 STATUS CTRL_VQ CTRL_VLAN MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 2) Provision vDPA device with a subset of parent features # vdpa dev add name vdpa1 mgmtdev pci/0000:41:04.2 device_features 0x300020000 # vdpa dev config show vdpa1: negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com> Reviewed-by: Eli Cohen <elic@nvidia.com> Message-Id: <1675725124-7375-7-git-send-email-si-wei.liu@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 033779a commit deeacf3

1 file changed

Lines changed: 45 additions & 8 deletions

File tree

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,7 @@ static u64 get_supported_features(struct mlx5_core_dev *mdev)
22092209
mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_STATUS);
22102210
mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MTU);
22112211
mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_CTRL_VLAN);
2212+
mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MAC);
22122213

22132214
return mlx_vdpa_features;
22142215
}
@@ -3099,6 +3100,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
30993100
struct mlx5_vdpa_dev *mvdev;
31003101
struct mlx5_vdpa_net *ndev;
31013102
struct mlx5_core_dev *mdev;
3103+
u64 device_features;
31023104
u32 max_vqs;
31033105
u16 mtu;
31043106
int err;
@@ -3107,6 +3109,24 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
31073109
return -ENOSPC;
31083110

31093111
mdev = mgtdev->madev->mdev;
3112+
device_features = mgtdev->mgtdev.supported_features;
3113+
if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) {
3114+
if (add_config->device_features & ~device_features) {
3115+
dev_warn(mdev->device,
3116+
"The provisioned features 0x%llx are not supported by this device with features 0x%llx\n",
3117+
add_config->device_features, device_features);
3118+
return -EINVAL;
3119+
}
3120+
device_features &= add_config->device_features;
3121+
}
3122+
if (!(device_features & BIT_ULL(VIRTIO_F_VERSION_1) &&
3123+
device_features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM))) {
3124+
dev_warn(mdev->device,
3125+
"Must provision minimum features 0x%llx for this device",
3126+
BIT_ULL(VIRTIO_F_VERSION_1) | BIT_ULL(VIRTIO_F_ACCESS_PLATFORM));
3127+
return -EOPNOTSUPP;
3128+
}
3129+
31103130
if (!(MLX5_CAP_DEV_VDPA_EMULATION(mdev, virtio_queue_type) &
31113131
MLX5_VIRTIO_EMULATION_CAP_VIRTIO_QUEUE_TYPE_SPLIT)) {
31123132
dev_warn(mdev->device, "missing support for split virtqueues\n");
@@ -3135,7 +3155,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
31353155
if (IS_ERR(ndev))
31363156
return PTR_ERR(ndev);
31373157

3138-
ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features;
31393158
ndev->mvdev.max_vqs = max_vqs;
31403159
mvdev = &ndev->mvdev;
31413160
mvdev->mdev = mdev;
@@ -3157,15 +3176,15 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
31573176
goto err_alloc;
31583177
}
31593178

3160-
if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
3179+
if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
31613180
err = query_mtu(mdev, &mtu);
31623181
if (err)
31633182
goto err_alloc;
31643183

31653184
ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
31663185
}
31673186

3168-
if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
3187+
if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
31693188
if (get_link_state(mvdev))
31703189
ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
31713190
else
@@ -3174,7 +3193,9 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
31743193

31753194
if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
31763195
memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);
3177-
} else {
3196+
/* No bother setting mac address in config if not going to provision _F_MAC */
3197+
} else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0 ||
3198+
device_features & BIT_ULL(VIRTIO_NET_F_MAC)) {
31783199
err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac);
31793200
if (err)
31803201
goto err_alloc;
@@ -3185,11 +3206,26 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
31853206
err = mlx5_mpfs_add_mac(pfmdev, config->mac);
31863207
if (err)
31873208
goto err_alloc;
3188-
3189-
ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_MAC);
3209+
} else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0) {
3210+
/*
3211+
* We used to clear _F_MAC feature bit if seeing
3212+
* zero mac address when device features are not
3213+
* specifically provisioned. Keep the behaviour
3214+
* so old scripts do not break.
3215+
*/
3216+
device_features &= ~BIT_ULL(VIRTIO_NET_F_MAC);
3217+
} else if (device_features & BIT_ULL(VIRTIO_NET_F_MAC)) {
3218+
/* Don't provision zero mac address for _F_MAC */
3219+
mlx5_vdpa_warn(&ndev->mvdev,
3220+
"No mac address provisioned?\n");
3221+
err = -EINVAL;
3222+
goto err_alloc;
31903223
}
31913224

3192-
config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2);
3225+
if (device_features & BIT_ULL(VIRTIO_NET_F_MQ))
3226+
config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2);
3227+
3228+
ndev->mvdev.mlx_features = device_features;
31933229
mvdev->vdev.dma_dev = &mdev->pdev->dev;
31943230
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
31953231
if (err)
@@ -3289,7 +3325,8 @@ static int mlx5v_probe(struct auxiliary_device *adev,
32893325
mgtdev->mgtdev.id_table = id_table;
32903326
mgtdev->mgtdev.config_attr_mask = BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR) |
32913327
BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP) |
3292-
BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU);
3328+
BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) |
3329+
BIT_ULL(VDPA_ATTR_DEV_FEATURES);
32933330
mgtdev->mgtdev.max_supported_vqs =
32943331
MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1;
32953332
mgtdev->mgtdev.supported_features = get_supported_features(mdev);

0 commit comments

Comments
 (0)