All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Skalkin <igor.skalkin@oss.qualcomm.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowangio@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org,
	Vasilii Ianikeev <vasilii.ianikeev@oss.qualcomm.com>,
	Aiswarya Cyriac <aiswarya.cyriac@oss.qualcomm.com>,
	Anton Yakovlev <anton.yakovlev@oss.qualcomm.com>,
	Trilok Soni <trilok.soni@oss.qualcomm.com>,
	Igor Skalkin <igor.skalkin@oss.qualcomm.com>
Subject: [PATCH 8/8] virtio-usb: support a guest UDC name prefix from the bind event
Date: Thu, 24 Sep 2026 18:09:07 +0200	[thread overview]
Message-ID: <20260924160907.145405-9-igor.skalkin@oss.qualcomm.com> (raw)
In-Reply-To: <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com>

Let the host backend supply a name prefix for a port's UDC parent
platform_device via the bind event, instead of always using the
generic GADGET_NAME. When present, the prefix is used verbatim as
the parent device's name and the gadget name becomes
"<prefix>_p<port>"; when empty, behavior is unchanged.

Signed-off-by: Igor Skalkin <igor.skalkin@oss.qualcomm.com>
---
 drivers/usb/virtio_usb/device.c |   47 +++++++++++++++++++++++++++++++++-------
 include/uapi/linux/virtio_usb.h |    4 ++-
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/virtio_usb/device.c b/drivers/usb/virtio_usb/device.c
index ee41ea9..fedce74 100644
--- a/drivers/usb/virtio_usb/device.c
+++ b/drivers/usb/virtio_usb/device.c
@@ -1369,11 +1369,26 @@ on_error:
 	return rc;
 }
 
-static int virtio_usb_dc_parent_create(struct virtio_usb_dc *vudc)
+static int virtio_usb_dc_parent_create(struct virtio_usb_dc *vudc,
+				       const unsigned char *udc_prefix)
 {
+	size_t prefix_len;
+	char *parent_name;
 	int rc;
 
-	vudc->pdev = platform_device_alloc(GADGET_NAME, vudc->port);
+	prefix_len = strnlen((const char *)udc_prefix,
+			     VIRTIO_USB_UDC_NAME_PREFIX_MAX);
+	if (prefix_len) {
+		parent_name = kasprintf(GFP_KERNEL, "%.*s", (int)prefix_len,
+					(const char *)udc_prefix);
+	} else {
+		parent_name = kstrdup(GADGET_NAME, GFP_KERNEL);
+	}
+	if (!parent_name)
+		return -ENOMEM;
+
+	vudc->pdev = platform_device_alloc(parent_name, vudc->port);
+	kfree(parent_name);
 	if (!vudc->pdev)
 		return -ENOMEM;
 
@@ -1421,6 +1436,7 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
 	switch (le32_to_cpu(evt->code)) {
 	case VIRTIO_USB_EVT_DEV_BIND: {
 		u8 max_speed;
+		size_t udc_prefix_len;
 
 		if (vudc->registered) {
 			dev_err(&vusb->vdev->dev,
@@ -1447,7 +1463,8 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
 			break;
 		}
 		if (!vudc->pdev) {
-			rc = virtio_usb_dc_parent_create(vudc);
+			rc = virtio_usb_dc_parent_create(
+				vudc, bind_evt->udc_name_prefix);
 			if (rc) {
 				dev_err(&vusb->vdev->dev,
 					"Failed to create UDC parent device\n");
@@ -1456,8 +1473,18 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
 				break;
 			}
 		}
-		vudc->gadget.name =
-			kasprintf(GFP_KERNEL, "%s_%d", GADGET_NAME, port_id);
+		udc_prefix_len =
+			strnlen((const char *)bind_evt->udc_name_prefix,
+				VIRTIO_USB_UDC_NAME_PREFIX_MAX);
+		if (udc_prefix_len) {
+			vudc->gadget.name = kasprintf(
+				GFP_KERNEL, "%.*s_p%d", (int)udc_prefix_len,
+				(const char *)bind_evt->udc_name_prefix,
+				port_id);
+		} else {
+			vudc->gadget.name = kasprintf(GFP_KERNEL, "%s_%d",
+						      GADGET_NAME, port_id);
+		}
 		if (!vudc->gadget.name) {
 			rc = -ENOMEM;
 			kfree(vudc->veps);
@@ -1480,7 +1507,6 @@ static void virtio_usb_dc_event_process(struct virtio_usb_event *event)
 			break;
 		}
 
-		//vudc->gadget.dev.init_name = gadget_name;
 		vudc->gadget.dev.parent = &vudc->pdev->dev;
 		rc = usb_add_gadget_udc(&vudc->pdev->dev, &vudc->gadget);
 		if (rc) {
@@ -1612,11 +1638,16 @@ int virtio_usb_dc_event_populate(struct virtio_usb *vusb)
 {
 	struct virtio_usb_queue *evt_queue =
 		&vusb->vqueues[vusb->dev_vq_base + VIRTIO_USB_VQ_EVENT_IDX];
+	size_t evt_size;
 	struct virtio_usb_event *events;
 	int rc;
 
-	events = virtio_usb_events_alloc(vusb, evt_queue,
-					 sizeof(struct virtio_usb_dev_event));
+	evt_size = max_t(size_t, sizeof(struct virtio_usb_dev_event),
+			 sizeof(struct virtio_usb_dev_setup_event));
+	evt_size = max_t(size_t, evt_size,
+			 sizeof(struct virtio_usb_dev_bind_event));
+
+	events = virtio_usb_events_alloc(vusb, evt_queue, evt_size);
 
 	if (!events)
 		return -ENOMEM;
diff --git a/include/uapi/linux/virtio_usb.h b/include/uapi/linux/virtio_usb.h
index d89223d..5fff248 100644
--- a/include/uapi/linux/virtio_usb.h
+++ b/include/uapi/linux/virtio_usb.h
@@ -216,6 +216,8 @@ enum {
 	VIRTIO_USB_EVT_DEV_UNBIND,
 };
 
+#define VIRTIO_USB_UDC_NAME_PREFIX_MAX 64
+
 struct virtio_usb_dev_event {
 	__le32 code; /* VIRTIO_USB_EVT_DEV_XXX */
 	__le16 port; /* Device ID */
@@ -227,7 +229,7 @@ struct virtio_usb_dev_bind_event {
 	__le32 code; /* VIRTIO_USB_EVT_DEV_BIND */
 	__le16 port; /* Device ID */
 	__u8 max_speed; /* enum usb_device_speed */
-	__u8 padding[9];
+	__u8 udc_name_prefix[VIRTIO_USB_UDC_NAME_PREFIX_MAX];
 };
 
 /* VIRTIO_USB_EVT_DEV_SETUP */

  parent reply	other threads:[~2026-09-24 16:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 16:08 [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Igor Skalkin
2026-09-24 16:09 ` [PATCH 1/8] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-09-24 16:23   ` sashiko-bot
2026-09-25  5:14   ` Greg Kroah-Hartman
2026-09-28 14:19     ` Igor Skalkin
2026-09-25  5:21   ` Greg Kroah-Hartman
2026-09-28 14:14     ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 2/8] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-09-24 16:25   ` sashiko-bot
2026-09-25  5:18   ` Greg Kroah-Hartman
2026-09-28 14:01     ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 3/8] virtio-usb: add device role (USB Device " Igor Skalkin
2026-09-24 16:28   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 4/8] virtio-usb: add OTG role query support Igor Skalkin
2026-09-24 16:19   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 5/8] virtio-usb: add USB On-The-Go role-switching support Igor Skalkin
2026-09-24 16:24   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 6/8] virtio-usb: rework endpoint lifecycle to an async split-phase state machine Igor Skalkin
2026-09-24 16:30   ` sashiko-bot
2026-09-24 16:09 ` [PATCH 7/8] virtio-usb: add SuperSpeed device-role support Igor Skalkin
2026-09-24 16:35   ` sashiko-bot
2026-09-24 16:09 ` Igor Skalkin [this message]
2026-09-24 16:35   ` [PATCH 8/8] virtio-usb: support a guest UDC name prefix from the bind event sashiko-bot
2026-09-25  5:17 ` [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Greg Kroah-Hartman
2026-09-28 13:55   ` Igor Skalkin
2026-09-28 14:44     ` Greg Kroah-Hartman
2026-09-28 15:56       ` Igor Skalkin
2026-09-28 16:10         ` Greg Kroah-Hartman
2026-09-29  9:47     ` Michael S. Tsirkin
2026-09-29 16:01       ` Greg Kroah-Hartman
2026-09-29 19:02         ` Vasilii Ianikeev
2026-09-29 19:58         ` Vasilii Ianikeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260924160907.145405-9-igor.skalkin@oss.qualcomm.com \
    --to=igor.skalkin@oss.qualcomm.com \
    --cc=aiswarya.cyriac@oss.qualcomm.com \
    --cc=anton.yakovlev@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowangio@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=trilok.soni@oss.qualcomm.com \
    --cc=vasilii.ianikeev@oss.qualcomm.com \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.