-static uint64_t vhost_req_user_to_kernel[] = {
- [VHOST_USER_SET_OWNER] = VHOST_SET_OWNER,
- [VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
- [VHOST_USER_SET_FEATURES] = VHOST_SET_FEATURES,
- [VHOST_USER_GET_FEATURES] = VHOST_GET_FEATURES,
- [VHOST_USER_SET_VRING_CALL] = VHOST_SET_VRING_CALL,
- [VHOST_USER_SET_VRING_NUM] = VHOST_SET_VRING_NUM,
- [VHOST_USER_SET_VRING_BASE] = VHOST_SET_VRING_BASE,
- [VHOST_USER_GET_VRING_BASE] = VHOST_GET_VRING_BASE,
- [VHOST_USER_SET_VRING_ADDR] = VHOST_SET_VRING_ADDR,
- [VHOST_USER_SET_VRING_KICK] = VHOST_SET_VRING_KICK,
- [VHOST_USER_SET_MEM_TABLE] = VHOST_SET_MEM_TABLE,
-};
+static int
+vhost_kernel_ioctl(int fd, uint64_t request, void *arg)
+{
+ int ret;
+
+ ret = ioctl(fd, request, arg);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Vhost-kernel ioctl %"PRIu64" failed (%s)",
+ request, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+vhost_kernel_set_owner(struct virtio_user_dev *dev)
+{
+ int ret;
+ uint32_t i;
+ struct vhost_kernel_data *data = dev->backend_data;
+
+ for (i = 0; i < dev->max_queue_pairs; ++i) {
+ if (data->vhostfds[i] < 0)
+ continue;
+
+ ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_OWNER, NULL);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int
+vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)
+{
+ struct vhost_kernel_data *data = dev->backend_data;
+ unsigned int tap_flags;
+ int ret;
+
+ ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_GET_FEATURES, features);
+ if (ret < 0) {
+ PMD_DRV_LOG(ERR, "Failed to get features");
+ return -1;
+ }
+
+ ret = tap_get_flags(data->tapfds[0], &tap_flags);
+ if (ret < 0) {
+ PMD_DRV_LOG(ERR, "Failed to get TAP features");
+ return -1;
+ }
+
+ /* with tap as the backend, all these features are supported
+ * but not claimed by vhost-net, so we add them back when
+ * reporting to upper layer.
+ */
+ if (tap_flags & IFF_VNET_HDR) {
+ *features |= VHOST_KERNEL_GUEST_OFFLOADS_MASK;
+ *features |= VHOST_KERNEL_HOST_OFFLOADS_MASK;
+ }
+
+ /* vhost_kernel will not declare this feature, but it does
+ * support multi-queue.
+ */
+ if (tap_flags & IFF_MULTI_QUEUE)
+ *features |= (1ull << VIRTIO_NET_F_MQ);
+
+ return 0;
+}