net/virtio: keep device and frontend features separated
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Thu, 17 Jun 2021 14:17:16 +0000 (16:17 +0200)
committerChenbo Xia <chenbo.xia@intel.com>
Wed, 23 Jun 2021 07:55:45 +0000 (09:55 +0200)
This patch is preliminary rework to add support for getting
and setting device's config space.

In order to get or set a device config such as its MAC address,
we need to know whether the device itself support the feature,
or if it is emulated by the frontend.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
drivers/net/virtio/virtio_user/virtio_user_dev.c
drivers/net/virtio/virtio_user_ethdev.c

index 364f43e..ed55cd7 100644 (file)
@@ -573,11 +573,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
        if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER)
                dev->frontend_features |= (1ull << VIRTIO_NET_F_STATUS);
 
-       /*
-        * Device features =
-        *     (frontend_features | backend_features) & ~unsupported_features;
-        */
-       dev->device_features |= dev->frontend_features;
+       dev->frontend_features &= ~dev->unsupported_features;
        dev->device_features &= ~dev->unsupported_features;
 
        if (rte_mem_event_callback_register(VIRTIO_USER_MEM_EVENT_CLB_NAME,
@@ -980,12 +976,10 @@ virtio_user_dev_server_reconnect(struct virtio_user_dev *dev)
                return -1;
        }
 
-       dev->device_features |= dev->frontend_features;
-
        /* unmask vhost-user unsupported features */
        dev->device_features &= ~(dev->unsupported_features);
 
-       dev->features &= dev->device_features;
+       dev->features &= (dev->device_features | dev->frontend_features);
 
        /* For packed ring, resetting queues is required in reconnection. */
        if (virtio_with_packed_queue(hw) &&
index e85906e..3ecbb41 100644 (file)
@@ -110,7 +110,8 @@ virtio_user_get_features(struct virtio_hw *hw)
        struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
        /* unmask feature bits defined in vhost user protocol */
-       return dev->device_features & VIRTIO_PMD_SUPPORTED_GUEST_FEATURES;
+       return (dev->device_features | dev->frontend_features) &
+               VIRTIO_PMD_SUPPORTED_GUEST_FEATURES;
 }
 
 static void
@@ -118,7 +119,7 @@ virtio_user_set_features(struct virtio_hw *hw, uint64_t features)
 {
        struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
-       dev->features = features & dev->device_features;
+       dev->features = features & (dev->device_features | dev->frontend_features);
 }
 
 static int