[RFC PATCH v2 2/7] virtio-usb: add protocol header and skeleton dual-role driver
From: Igor Skalkin
Date: Tue Dec 01 2026 - 12:36:12 EST
From: Aiswarya Cyriac <aiswarya.cyriac@xxxxxxxxxxxxxxxx>
Add the virtio_usb device and virtqueue-wrapper skeleton, the
protocol header shared with the vhost gadget driver and userspace
backend, and probe()/remove() plumbing with no role support yet.
Introduce a per-port virtio_usb_port array (vports[]), sized to the
device's negotiated port count, ahead of any code that actually
populates or reads it. Every later commit that adds a role to a port
(host or device) or role switching builds on this same array from
the start, instead of the host, device, and role-switch code each
growing their own separate port-indexed storage that later has to
be reconciled.
All wire-protocol constants in the uapi header use explicit #define
values rather than enums, matching virtio_rtc.h's style, since these
values go out over the wire and must not depend on implicit
enum auto-increment (Documentation/process/botching-up-ioctls.rst).
Signed-off-by: Aiswarya Cyriac <aiswarya.cyriac@xxxxxxxxxxxxxxxx>
Co-developed-by: Igor Skalkin <igor.skalkin@xxxxxxxxxxxxxxxx>
Signed-off-by: Igor Skalkin <igor.skalkin@xxxxxxxxxxxxxxxx>
---
MAINTAINERS | 10 +
drivers/usb/Kconfig | 2 +
drivers/usb/Makefile | 1 +
drivers/usb/virtio_usb/Kconfig | 13 ++
drivers/usb/virtio_usb/Makefile | 5 +
drivers/usb/virtio_usb/controller.c | 155 ++++++++++++++++
drivers/usb/virtio_usb/controller.h | 84 +++++++++
include/uapi/linux/virtio_usb.h | 278 ++++++++++++++++++++++++++++
8 files changed, 548 insertions(+)
create mode 100644 drivers/usb/virtio_usb/Kconfig
create mode 100644 drivers/usb/virtio_usb/Makefile
create mode 100644 drivers/usb/virtio_usb/controller.c
create mode 100644 drivers/usb/virtio_usb/controller.h
create mode 100644 include/uapi/linux/virtio_usb.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..845bc1842249 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -29809,6 +29809,16 @@ S: Maintained
F: drivers/spi/spi-virtio.c
F: include/uapi/linux/virtio_spi.h
+VIRTIO USB DRIVER
+M: Igor Skalkin <igor.skalkin@xxxxxxxxxxxxxxxx>
+M: Aiswarya Cyriac <aiswarya.cyriac@xxxxxxxxxxxxxxxx>
+M: Vasilii Ianikeev <vasilii.ianikeev@xxxxxxxxxxxxxxxx>
+L: virtualization@xxxxxxxxxxxxxxx
+L: linux-usb@xxxxxxxxxxxxxxx
+S: Maintained
+F: drivers/usb/virtio_usb/
+F: include/uapi/linux/virtio_usb.h
+
VIRTUAL BOX GUEST DEVICE DRIVER
M: Hans de Goede <hansg@xxxxxxxxxx>
M: Arnd Bergmann <arnd@xxxxxxxx>
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index abf8c6cdea9e..68076db03203 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -139,6 +139,8 @@ source "drivers/usb/chipidea/Kconfig"
source "drivers/usb/isp1760/Kconfig"
+source "drivers/usb/virtio_usb/Kconfig"
+
comment "USB port drivers"
if USB
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index eecbd631fdab..f28a4b7989bf 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_USB_SUPPORT) += phy/
obj-$(CONFIG_USB_DWC3) += dwc3/
obj-$(CONFIG_USB_DWC2) += dwc2/
obj-$(CONFIG_USB_ISP1760) += isp1760/
+obj-$(CONFIG_USB_VIRTIO) += virtio_usb/
obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns3/
diff --git a/drivers/usb/virtio_usb/Kconfig b/drivers/usb/virtio_usb/Kconfig
new file mode 100644
index 000000000000..0cc5df26151c
--- /dev/null
+++ b/drivers/usb/virtio_usb/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+config USB_VIRTIO
+ tristate "Virtio USB controller support"
+ depends on VIRTIO && USB && USB_GADGET
+ help
+ This driver supports the virtio USB device, a paravirtualized
+ dual-role USB controller. Each port of the device acts either
+ as a USB host controller port or as a USB device controller
+ (UDC).
+
+ To compile this driver as a module, choose M here: the module
+ will be called virtio-usb.
diff --git a/drivers/usb/virtio_usb/Makefile b/drivers/usb/virtio_usb/Makefile
new file mode 100644
index 000000000000..38aa6a822366
--- /dev/null
+++ b/drivers/usb/virtio_usb/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+obj-$(CONFIG_USB_VIRTIO) += virtio-usb.o
+
+virtio-usb-y := controller.o
diff --git a/drivers/usb/virtio_usb/controller.c b/drivers/usb/virtio_usb/controller.c
new file mode 100644
index 000000000000..4fcf3d7a6107
--- /dev/null
+++ b/drivers/usb/virtio_usb/controller.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * virtio_usb: VirtIO USB device
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#include <linux/module.h>
+#include <linux/virtio_ids.h>
+
+#include "controller.h"
+
+/**
+ * virtio_usb_find_vqs() - Enumerate and initialize all virtqueues.
+ * @vusb: VirtIO usb device.
+ *
+ * Context: Any context.
+ * Return: 0 on success, -errno on failure.
+ */
+static int virtio_usb_find_vqs(struct virtio_usb *vusb)
+{
+ unsigned int nvqs = vusb->nvqs, i;
+ struct virtqueue **vqs = NULL;
+ int rc = -ENOMEM;
+
+ vqs = kcalloc(nvqs, sizeof(void *), GFP_KERNEL);
+ if (!vqs)
+ return -ENOMEM;
+
+ struct virtqueue_info *vqs_info =
+ kcalloc(nvqs, sizeof(*vqs_info), GFP_KERNEL);
+ if (!vqs_info) {
+ rc = -ENOMEM;
+ goto on_exit;
+ }
+ for (i = 0; i < nvqs; i++) {
+ vqs_info[i].name = vusb->vqueues[i].name;
+ vqs_info[i].callback = vusb->vqueues[i].callback;
+ }
+ rc = virtio_find_vqs(vusb->vdev, nvqs, vqs, vqs_info, NULL);
+
+ kfree(vqs_info);
+
+ for (i = 0; i < nvqs; i++) {
+ vusb->vqueues[i].vqueue = vqs[i];
+ spin_lock_init(&vusb->vqueues[i].lock);
+ }
+on_exit:
+ kfree(vqs);
+ return rc;
+}
+
+/**
+ * virtio_usb_validate() - Validate if the device can be started.
+ * @vdev: VirtIO parent device.
+ *
+ * Context: Any context.
+ * Return: 0 on success, -EINVAL on failure.
+ */
+static int virtio_usb_validate(struct virtio_device *vdev)
+{
+ if (!vdev->config->get) {
+ dev_err(&vdev->dev, "configuration access disabled\n");
+ return -EINVAL;
+ }
+
+ if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
+ dev_err(&vdev->dev,
+ "device does not comply with spec version 1.x\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/**
+ * virtio_usb_probe() - Probe VirtIO usb controller.
+ * @vdev: VirtIO parent device.
+ *
+ * Context: Any context that permits to sleep.
+ * Return: 0 on success, -errno on failure.
+ */
+static int virtio_usb_probe(struct virtio_device *vdev)
+{
+ struct virtio_usb *vusb;
+ unsigned int nvqs = 0;
+ int rc = 0;
+
+ vusb = devm_kzalloc(&vdev->dev, sizeof(*vusb), GFP_KERNEL);
+ if (!vusb)
+ return -ENOMEM;
+
+ vusb->vdev = vdev;
+ vdev->priv = vusb;
+
+ virtio_cread_le(vdev, struct virtio_usb_config, ports, &vusb->nports);
+
+ vusb->vports = devm_kcalloc(&vdev->dev, vusb->nports,
+ sizeof(*vusb->vports), GFP_KERNEL);
+ if (!vusb->vports)
+ return -ENOMEM;
+
+ vusb->vqueues = devm_kcalloc(&vdev->dev, nvqs, sizeof(*vusb->vqueues),
+ GFP_KERNEL);
+ if (!vusb->vqueues)
+ return -ENOMEM;
+
+ vusb->nvqs = nvqs;
+
+ rc = virtio_usb_find_vqs(vusb);
+ if (rc)
+ goto on_exit;
+
+ virtio_device_ready(vdev);
+
+on_exit:
+ return rc;
+}
+
+/**
+ * virtio_usb_remove() - Remove VirtIO usb device.
+ * @vdev: VirtIO parent device.
+ *
+ * Context: Any context that permits to sleep.
+ */
+static void virtio_usb_remove(struct virtio_device *vdev)
+{
+ struct virtio_usb *vusb = vdev->priv;
+ int i;
+
+ virtio_reset_device(vdev);
+ for (i = 0; i < vusb->nvqs; i++)
+ vusb->vqueues[i].stop(vusb, &vusb->vqueues[i]);
+
+ vdev->config->del_vqs(vdev);
+}
+
+static const struct virtio_device_id id_table[] = {
+ { VIRTIO_ID_USB, VIRTIO_DEV_ANY_ID },
+ { 0 },
+};
+
+static struct virtio_driver virtio_usb_driver = {
+ .driver.name = KBUILD_MODNAME,
+ .id_table = id_table,
+ .validate = virtio_usb_validate,
+ .probe = virtio_usb_probe,
+ .remove = virtio_usb_remove,
+};
+
+module_virtio_driver(virtio_usb_driver);
+
+MODULE_DEVICE_TABLE(virtio, id_table);
+MODULE_DESCRIPTION("Dual-role virtio-usb controller driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/virtio_usb/controller.h b/drivers/usb/virtio_usb/controller.h
new file mode 100644
index 000000000000..5a47c9ca52ad
--- /dev/null
+++ b/drivers/usb/virtio_usb/controller.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * virtio-usb: Virtio usb device
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef VIRTIO_USB_CONTROLLER_H
+#define VIRTIO_USB_CONTROLLER_H
+
+#include <linux/slab.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+
+#include <linux/virtio_usb.h>
+
+/**
+ * struct virtio_usb_port - Per-virtual-port state.
+ * @role: Role of this port (VIRTIO_USB_ROLE_HOST or _DEVICE), once a
+ * role-providing commit has assigned it. Unused for now - this
+ * struct is deliberately introduced ahead of any code that
+ * populates or reads @role, so that every later commit that adds
+ * a role (host, device) or role switching can build on this same
+ * per-port array from the start instead of each reinventing its
+ * own port-indexed storage.
+ */
+struct virtio_usb_port {
+ unsigned int role;
+};
+
+/**
+ * struct virtio_usb - VirtIO USB device.
+ * @vdev: Underlying virtio device
+ * @vqueues: Array of virtqueue wrappers.
+ * @vports: Array of per-port structures, one entry per virtual port.
+ * @nports: number of supported ports
+ * @nvqs: number of virtqueues for the device
+ */
+struct virtio_usb {
+ struct virtio_device *vdev;
+ struct virtio_usb_queue *vqueues;
+ struct virtio_usb_port *vports;
+ unsigned int nports;
+ u32 nvqs;
+};
+
+/**
+ * struct virtio_usb_queue - Virtqueue wrapper structure.
+ * @name: Name of the virtqueue.
+ * @callback: Used to synchronize access to a virtqueue.
+ * @vqueue: Underlying virtqueue.
+ * @lock: Used to synchronize access to a virtqueue.
+ * @process: queue process callback function
+ * @stop: queue stop callback function
+ */
+struct virtio_usb_queue {
+ const char *name;
+ vq_callback_t *callback;
+ struct virtqueue *vqueue;
+ spinlock_t lock;
+ void (*process)(struct virtio_usb *vusb, void *buf);
+ void (*stop)(struct virtio_usb *vusb, struct virtio_usb_queue *vq);
+};
+
+/**
+ * struct virtio_usb_vq_desc - Read-only virtqueue template.
+ * @name: Name of the virtqueue.
+ * @callback: Virtqueue notification callback function.
+ * @process: queue process callback function.
+ * @stop: queue stop callback function.
+ *
+ * Immutable per-role virtqueue description, copied into a fresh
+ * per-instance struct virtio_usb_queue during probe() instead of being
+ * shared directly - so that multiple probed virtio_usb instances never
+ * alias the same struct virtqueue.
+ */
+struct virtio_usb_vq_desc {
+ const char *name;
+ vq_callback_t *callback;
+ void (*process)(struct virtio_usb *vusb, void *buf);
+ void (*stop)(struct virtio_usb *vusb, struct virtio_usb_queue *vq);
+};
+
+#endif /* VIRTIO_USB_CONTROLLER_H */
diff --git a/include/uapi/linux/virtio_usb.h b/include/uapi/linux/virtio_usb.h
new file mode 100644
index 000000000000..c494ca94d1ff
--- /dev/null
+++ b/include/uapi/linux/virtio_usb.h
@@ -0,0 +1,278 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later WITH Linux-syscall-note */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef _UAPI_LINUX_VIRTIO_USB_H
+#define _UAPI_LINUX_VIRTIO_USB_H
+
+#include <linux/virtio_types.h>
+
+/*****************************************************************************
+ * FEATURE BITS
+ */
+/* Host controller is supported */
+#define VIRTIO_USB_F_HOST 0
+/* Device controller is supported */
+#define VIRTIO_USB_F_DEVICE 1
+/* Role switching is supported */
+#define VIRTIO_USB_F_SWITCH_ROLE 2
+
+/*****************************************************************************
+ * CONFIGURATION SPACE
+ */
+struct virtio_usb_config {
+ /* # of available ports */
+ __le32 ports;
+};
+
+/*****************************************************************************
+ * COMMON DEFINITIONS
+ */
+#define VIRTIO_USB_VQ_HOST_COMMAND 0
+#define VIRTIO_USB_VQ_HOST_EVENT 1
+#define VIRTIO_USB_VQ_HOST_DATA 2
+#define VIRTIO_USB_VQ_DEV_COMMAND 3
+#define VIRTIO_USB_VQ_DEV_EVENT 4
+#define VIRTIO_USB_VQ_DEV_DATA 5
+#define VIRTIO_USB_VQ_ROLE_COMMAND 6
+#define VIRTIO_USB_VQ_ROLE_EVENT 7
+#define VIRTIO_USB_VQ_MAX 8
+
+#define VIRTIO_USB_EP_CONTROL 0
+#define VIRTIO_USB_EP_INTERRUPT 1
+#define VIRTIO_USB_EP_BULK 2
+#define VIRTIO_USB_EP_ISOCHRONOUS 3
+
+#define VIRTIO_USB_S_OK 0
+#define VIRTIO_USB_S_ERR_BAD_MSG 1
+#define VIRTIO_USB_S_ERR_INTERNAL 2
+#define VIRTIO_USB_S_ERR_NO_DEVICE 3
+#define VIRTIO_USB_S_ERR_ISO_XFER 4
+#define VIRTIO_USB_S_ERR_ISO_BIG 5
+#define VIRTIO_USB_S_ERR_DATA_IN 6
+#define VIRTIO_USB_S_ERR_DATA_OUT 7
+#define VIRTIO_USB_S_ERR_MSG_SIZE 8
+#define VIRTIO_USB_S_ERR_OVERFLOW 9
+#define VIRTIO_USB_S_ERR_STALL 10
+#define VIRTIO_USB_S_ERR_SHORT_PKT 11
+#define VIRTIO_USB_S_ERR_CANCELLED 12
+#define VIRTIO_USB_S_ERR_HOST 13
+
+struct virtio_usb_cmd_status {
+ __le32 code; /* VIRTIO_USB_S_XXX */
+};
+
+/*****************************************************************************
+ * HOST COMMAND MESSAGES
+ */
+#define VIRTIO_USB_CMD_HOST_CANCEL 0
+#define VIRTIO_USB_CMD_HOST_STREAMS_ALLOC 1
+#define VIRTIO_USB_CMD_HOST_STREAMS_FREE 2
+
+struct virtio_usb_host_cmd_hdr {
+ __le32 code; /* VIRTIO_USB_CMD_HOST_XXX */
+ __le32 port; /* Port ID */
+};
+
+/* VIRTIO_USB_CMD_HOST_CANCEL */
+struct virtio_usb_host_cmd_cancel {
+ struct virtio_usb_host_cmd_hdr hdr;
+ __le64 tag;
+};
+
+/* VIRTIO_USB_CMD_HOST_STREAMS_ALLOC/FREE */
+struct virtio_usb_host_cmd_streams {
+ struct virtio_usb_host_cmd_hdr hdr;
+ __le32 number_of_streams;
+ __le32 number_of_eps;
+};
+
+/*****************************************************************************
+ * HOST EVENT MESSAGES
+ */
+#define VIRTIO_USB_EVT_HOST_PORT_CONNECTED 0
+#define VIRTIO_USB_EVT_HOST_PORT_DISCONNECTED 1
+
+/* VIRTIO_USB_EVT_HOST_PORT_CONNECTED/DISCONNECTED */
+#define VIRTIO_USB_SPEED_UNKNOWN 0
+#define VIRTIO_USB_SPEED_LOW 1
+#define VIRTIO_USB_SPEED_FULL 2 /* usb 1.1 */
+#define VIRTIO_USB_SPEED_HIGH 3 /* usb 2.0 */
+#define VIRTIO_USB_SPEED_SUPER 5 /* usb 3.0 */
+#define VIRTIO_USB_SPEED_SUPER_PLUS 6 /* usb 3.1 */
+
+struct virtio_usb_host_port_event {
+ __le32 code; /* VIRTIO_USB_EVT_HOST_PORT_XXX */
+ __le32 port_id;
+ __le32 speed; /* VIRTIO_USB_SPEED_XXX */
+ __le32 padding;
+};
+
+/*****************************************************************************
+ * DEVICE COMMAND MESSAGES
+ */
+#define VIRTIO_USB_CMD_DEV_GET_ENDPOINT_COUNT 0
+#define VIRTIO_USB_CMD_DEV_GET_ENDPOINT_INFO 1
+#define VIRTIO_USB_CMD_DEV_PULLUP 2
+#define VIRTIO_USB_CMD_DEV_VBUS_DRAW 3
+#define VIRTIO_USB_CMD_DEV_EP_ENABLE 4
+#define VIRTIO_USB_CMD_DEV_EP_DISABLE 5
+#define VIRTIO_USB_CMD_DEV_EP_SET_HALT 6
+#define VIRTIO_USB_CMD_DEV_EP_SET_WEDGE 7
+#define VIRTIO_USB_CMD_DEV_CANCEL 8
+
+struct virtio_usb_dev_cmd_hdr {
+ __le32 code; /* VIRTIO_USB_CMD_DEV_XXX */
+ __le16 port; /* Port ID */
+ __le16 endpoint; /* Endpoint ID */
+};
+
+/* VIRTIO_USB_CMD_DEV_GET_ENDPOINT_COUNT */
+struct virtio_usb_dev_cmd_ep_count {
+ struct virtio_usb_cmd_status status;
+ __le32 count; /* # of supported endpoints */
+};
+
+#define VIRTIO_USB_DIR_OUT 0
+#define VIRTIO_USB_DIR_IN 1
+
+#define VIRTIO_USB_EP_DIR_OUT 0
+#define VIRTIO_USB_EP_DIR_IN 0x80
+
+/*
+ * VIRTIO_USB_CMD_DEV_GET_ENDPOINT_INFO
+ *
+ * Response:
+ * struct virtio_usb_cmd_status
+ * struct virtio_usb_dev_ep_info [count]
+ */
+struct virtio_usb_dev_cmd_ep_info {
+ __le16 types; /* supported type bit map (1 << VIRTIO_USB_EP_XXX) */
+ __le16 directions; /* supported direction bit map (1 << VIRTIO_USB_DIR_XXX) */
+ __le16 maxpacket_limit;
+ __le16 max_streams;
+};
+
+/*******************************************************************************
+ * DEVICE EVENT MESSAGES
+ */
+#define VIRTIO_USB_EVT_DEV_CONNECTED 0
+#define VIRTIO_USB_EVT_DEV_DISCONNECTED 1
+#define VIRTIO_USB_EVT_DEV_SETUP 2
+#define VIRTIO_USB_EVT_DEV_RESET 3
+#define VIRTIO_USB_EVT_DEV_SUSPEND 4
+#define VIRTIO_USB_EVT_DEV_RESUME 5
+
+struct virtio_usb_dev_event {
+ __le32 code; /* VIRTIO_USB_EVT_DEV_XXX */
+ __u8 padding[12];
+};
+
+/* VIRTIO_USB_EVT_DEV_SETUP */
+struct virtio_usb_dev_setup_event {
+ __le32 code; /* VIRTIO_USB_EVT_DEV_SETUP */
+ __u8 setup[8]; /* setup packet contents */
+ __u8 padding[4];
+};
+
+/*******************************************************************************
+ * HOST/DEVICE DATA MESSAGES
+ */
+#define VIRTIO_USB_FLAG_SHORT_NOT_OK (1 << 0)
+#define VIRTIO_USB_FLAG_ISO_ASAP (1 << 1)
+#define VIRTIO_USB_FLAG_ZERO_PACKET (1 << 2)
+
+struct virtio_usb_request {
+ __le64 tag;
+ __le16 port; /* Port ID */
+ __le16 endpoint; /* Endpoint ID */
+ __le16 transfer_type; /* VIRTIO_USB_EP_XXX */
+ __le16 transfer_flags; /* VIRTIO_USB_FLAG_XXX */
+ union {
+ /* transfer_type = VIRTIO_USB_EP_CONTROL */
+ struct {
+ __u8 setup[8];
+ } control;
+ /* transfer_type = VIRTIO_USB_EP_INTERRUPT */
+ struct {
+ __le32 interval;
+ } interrupt;
+ /* transfer_type = VIRTIO_USB_EP_BULK */
+ struct {
+ __le32 stream_id;
+ } bulk;
+ /* transfer_type = VIRTIO_USB_EP_ISOCHRONOUS */
+ struct {
+ __le32 interval;
+ __le32 start_frame;
+ __le32 number_of_packets;
+ __le32 padding;
+ } iso;
+ };
+};
+
+struct virtio_usb_response {
+ __le32 status; /* VIRTIO_USB_S_XXX */
+ __le32 actual_length;
+ __le32 interval; /* type = VIRTIO_USB_EP_INTERRUPT/ISOCHRONOUS */
+ __le32 start_frame; /* type = VIRTIO_USB_EP_ISOCHRONOUS */
+};
+
+/*
+ * ISO request:
+ * struct virtio_usb_request
+ * struct virtio_usb_iso_packet [number_of_packets]
+ * ISO response:
+ * struct virtio_usb_response
+ * struct virtio_usb_iso_status [number_of_packets]
+ */
+struct virtio_usb_iso_packet {
+ __le32 offset;
+ __le32 length;
+};
+
+struct virtio_usb_iso_status {
+ __le32 status; /* VIRTIO_USB_S_XXX */
+ __le32 actual_length;
+};
+
+/*****************************************************************************
+ * ROLE COMMAND MESSAGES
+ */
+#define VIRTIO_USB_CMD_ROLE_GET 0
+/* If VIRTIO_USB_F_SWITCH_ROLE is negotiated */
+#define VIRTIO_USB_CMD_ROLE_SET 1
+
+struct virtio_usb_role_cmd_hdr {
+ __le32 code; /* VIRTIO_USB_CMD_ROLE_XXX */
+ __le32 port; /* Port ID */
+};
+
+/* VIRTIO_USB_CMD_ROLE_SET */
+struct virtio_usb_role_set {
+ struct virtio_usb_role_cmd_hdr hdr;
+ __le32 role; /* VIRTIO_USB_ROLE_XXX */
+};
+
+/* VIRTIO_USB_CMD_ROLE_GET */
+#define VIRTIO_USB_ROLE_HOST 0
+#define VIRTIO_USB_ROLE_DEVICE 1
+
+struct virtio_usb_role_info {
+ struct virtio_usb_cmd_status status;
+ __le32 role; /* VIRTIO_USB_ROLE_XXX */
+ __le32 supported_role; /* VIRTIO_USB_F_[HOST|DEVICE|SWITCH_ROLE] */
+};
+
+/*****************************************************************************
+ * ROLE EVENT MESSAGES
+ */
+#define VIRTIO_USB_EVT_ROLE_CHANGE 0
+
+struct virtio_usb_role_event {
+ __le32 code; /* VIRTIO_USB_EVT_ROLE_XXX */
+ __le32 port; /* Port ID */
+};
+
+#endif /* _UAPI_LINUX_VIRTIO_USB_H */
--
2.49.0