vdpa/mlx5: make MTU/STATUS presence conditional on feature bits
authorSi-Wei Liu <si-wei.liu@oracle.com>
Mon, 6 Feb 2023 23:12:03 +0000 (15:12 -0800)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 21 Feb 2023 00:27:00 +0000 (19:27 -0500)
The spec says:
    mtu only exists if VIRTIO_NET_F_MTU is set
    status only exists if VIRTIO_NET_F_STATUS is set

We should only present MTU and STATUS conditionally depending on
the feature bits.

Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
Message-Id: <1675725124-7375-6-git-send-email-si-wei.liu@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/mlx5/net/mlx5_vnet.c

index 8f06026517b82fd3e3433ec38612ebcaad088dbc..9e5af6c0ee329aaa75aafbf8a63ecb62b8e14bcd 100644 (file)
@@ -3046,6 +3046,8 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
        struct mlx5_vdpa_wq_ent *wqent;
 
        if (event == MLX5_EVENT_TYPE_PORT_CHANGE) {
+               if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_STATUS)))
+                       return NOTIFY_DONE;
                switch (eqe->sub_type) {
                case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
                case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
@@ -3155,16 +3157,20 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
                        goto err_alloc;
        }
 
-       err = query_mtu(mdev, &mtu);
-       if (err)
-               goto err_alloc;
+       if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_MTU)) {
+               err = query_mtu(mdev, &mtu);
+               if (err)
+                       goto err_alloc;
 
-       ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
+               ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu);
+       }
 
-       if (get_link_state(mvdev))
-               ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
-       else
-               ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
+       if (ndev->mvdev.mlx_features & BIT_ULL(VIRTIO_NET_F_STATUS)) {
+               if (get_link_state(mvdev))
+                       ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
+               else
+                       ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
+       }
 
        if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
                memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN);