Re: [PATCH v7 2/3] usb: Introduce Xen pvUSB frontend (xen hcd)

2021-12-13 Thread Greg Kroah-Hartman
On Fri, Dec 03, 2021 at 01:50:44PM +0100, Juergen Gross wrote:
> On 03.12.21 13:49, Greg Kroah-Hartman wrote:
> > On Tue, Nov 23, 2021 at 02:20:47PM +0100, Juergen Gross wrote:
> > > Introduces the Xen pvUSB frontend. With pvUSB it is possible for a Xen
> > > domU to communicate with a USB device assigned to that domU. The
> > > communication is all done via the pvUSB backend in a driver domain
> > > (usually Dom0) which is owner of the physical device.
> > > 
> > > The pvUSB frontend is a USB hcd for a virtual USB host connector.
> > > 
> > > The code is taken from the pvUSB implementation in Xen done by Fujitsu
> > > based on Linux kernel 2.6.18.
> > > 
> > > Changes from the original version are:
> > > - port to upstream kernel
> > > - put all code in just one source file
> > > - move module to appropriate location in kernel tree
> > > - adapt to Linux style guide
> > > - minor code modifications to increase readability
> > > 
> > > Signed-off-by: Juergen Gross 
> > > ---
> > >   drivers/usb/host/Kconfig   |   11 +
> > >   drivers/usb/host/Makefile  |1 +
> > >   drivers/usb/host/xen-hcd.c | 1606 
> > >   3 files changed, 1618 insertions(+)
> > >   create mode 100644 drivers/usb/host/xen-hcd.c
> > 
> > This looks sane to me, but I don't know the HCD interface as well as
> > others on linux-usb do, like Alan Stern.
> > 
> > What tree do you want this to be merged through, my USB one?
> 
> Either that, or I can carry it through the Xen tree.
> 
> Its your choice. :-)

I've grabbed them now, thanks.

greg k-h



Re: [PATCH v7 2/3] usb: Introduce Xen pvUSB frontend (xen hcd)

2021-12-03 Thread Juergen Gross

On 03.12.21 13:49, Greg Kroah-Hartman wrote:

On Tue, Nov 23, 2021 at 02:20:47PM +0100, Juergen Gross wrote:

Introduces the Xen pvUSB frontend. With pvUSB it is possible for a Xen
domU to communicate with a USB device assigned to that domU. The
communication is all done via the pvUSB backend in a driver domain
(usually Dom0) which is owner of the physical device.

The pvUSB frontend is a USB hcd for a virtual USB host connector.

The code is taken from the pvUSB implementation in Xen done by Fujitsu
based on Linux kernel 2.6.18.

Changes from the original version are:
- port to upstream kernel
- put all code in just one source file
- move module to appropriate location in kernel tree
- adapt to Linux style guide
- minor code modifications to increase readability

Signed-off-by: Juergen Gross 
---
  drivers/usb/host/Kconfig   |   11 +
  drivers/usb/host/Makefile  |1 +
  drivers/usb/host/xen-hcd.c | 1606 
  3 files changed, 1618 insertions(+)
  create mode 100644 drivers/usb/host/xen-hcd.c


This looks sane to me, but I don't know the HCD interface as well as
others on linux-usb do, like Alan Stern.

What tree do you want this to be merged through, my USB one?


Either that, or I can carry it through the Xen tree.

Its your choice. :-)


Juergen


OpenPGP_0xB0DE9DD628BF132F.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: [PATCH v7 2/3] usb: Introduce Xen pvUSB frontend (xen hcd)

2021-12-03 Thread Greg Kroah-Hartman
On Tue, Nov 23, 2021 at 02:20:47PM +0100, Juergen Gross wrote:
> Introduces the Xen pvUSB frontend. With pvUSB it is possible for a Xen
> domU to communicate with a USB device assigned to that domU. The
> communication is all done via the pvUSB backend in a driver domain
> (usually Dom0) which is owner of the physical device.
> 
> The pvUSB frontend is a USB hcd for a virtual USB host connector.
> 
> The code is taken from the pvUSB implementation in Xen done by Fujitsu
> based on Linux kernel 2.6.18.
> 
> Changes from the original version are:
> - port to upstream kernel
> - put all code in just one source file
> - move module to appropriate location in kernel tree
> - adapt to Linux style guide
> - minor code modifications to increase readability
> 
> Signed-off-by: Juergen Gross 
> ---
>  drivers/usb/host/Kconfig   |   11 +
>  drivers/usb/host/Makefile  |1 +
>  drivers/usb/host/xen-hcd.c | 1606 
>  3 files changed, 1618 insertions(+)
>  create mode 100644 drivers/usb/host/xen-hcd.c

This looks sane to me, but I don't know the HCD interface as well as
others on linux-usb do, like Alan Stern.

What tree do you want this to be merged through, my USB one?

thanks,

greg k-h



[PATCH v7 2/3] usb: Introduce Xen pvUSB frontend (xen hcd)

2021-11-23 Thread Juergen Gross
Introduces the Xen pvUSB frontend. With pvUSB it is possible for a Xen
domU to communicate with a USB device assigned to that domU. The
communication is all done via the pvUSB backend in a driver domain
(usually Dom0) which is owner of the physical device.

The pvUSB frontend is a USB hcd for a virtual USB host connector.

The code is taken from the pvUSB implementation in Xen done by Fujitsu
based on Linux kernel 2.6.18.

Changes from the original version are:
- port to upstream kernel
- put all code in just one source file
- move module to appropriate location in kernel tree
- adapt to Linux style guide
- minor code modifications to increase readability

Signed-off-by: Juergen Gross 
---
 drivers/usb/host/Kconfig   |   11 +
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/xen-hcd.c | 1606 
 3 files changed, 1618 insertions(+)
 create mode 100644 drivers/usb/host/xen-hcd.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index d1d926f8f9c2..57ca5f97a3dc 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -772,3 +772,14 @@ config USB_HCD_TEST_MODE
  This option is of interest only to developers who need to validate
  their USB hardware designs.  It is not needed for normal use.  If
  unsure, say N.
+
+config USB_XEN_HCD
+   tristate "Xen usb virtual host driver"
+   depends on XEN
+   select XEN_XENBUS_FRONTEND
+   help
+ The Xen usb virtual host driver serves as a frontend driver enabling
+ a Xen guest system to access USB Devices passed through to the guest
+ by the Xen host (usually Dom0).
+ Only needed if the kernel is running in a Xen guest and generic
+ access to a USB device is needed.
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 171de4df50bd..2948983618fb 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -85,3 +85,4 @@ obj-$(CONFIG_USB_HCD_BCMA)+= bcma-hcd.o
 obj-$(CONFIG_USB_HCD_SSB)  += ssb-hcd.o
 obj-$(CONFIG_USB_FOTG210_HCD)  += fotg210-hcd.o
 obj-$(CONFIG_USB_MAX3421_HCD)  += max3421-hcd.o
+obj-$(CONFIG_USB_XEN_HCD)  += xen-hcd.o
diff --git a/drivers/usb/host/xen-hcd.c b/drivers/usb/host/xen-hcd.c
new file mode 100644
index ..7801dde6f5ee
--- /dev/null
+++ b/drivers/usb/host/xen-hcd.c
@@ -0,0 +1,1606 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * xen-hcd.c
+ *
+ * Xen USB Virtual Host Controller driver
+ *
+ * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
+ * Author: Noboru Iwamatsu 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* Private per-URB data */
+struct urb_priv {
+   struct list_head list;
+   struct urb *urb;
+   int req_id; /* RING_REQUEST id for submitting */
+   int unlink_req_id;  /* RING_REQUEST id for unlinking */
+   int status;
+   bool unlinked;  /* dequeued marker */
+};
+
+/* virtual roothub port status */
+struct rhport_status {
+   __u32 status;
+   bool resuming;  /* in resuming */
+   bool c_connection;  /* connection changed */
+   unsigned long timeout;
+};
+
+/* status of attached device */
+struct vdevice_status {
+   int devnum;
+   enum usb_device_state status;
+   enum usb_device_speed speed;
+};
+
+/* RING request shadow */
+struct usb_shadow {
+   struct xenusb_urb_request req;
+   struct urb *urb;
+};
+
+struct xenhcd_info {
+   /* Virtual Host Controller has 4 urb queues */
+   struct list_head pending_submit_list;
+   struct list_head pending_unlink_list;
+   struct list_head in_progress_list;
+   struct list_head giveback_waiting_list;
+
+   spinlock_t lock;
+
+   /* timer that kick pending and giveback waiting urbs */
+   struct timer_list watchdog;
+   unsigned long actions;
+
+   /* virtual root hub */
+   int rh_numports;
+   struct rhport_status ports[XENUSB_MAX_PORTNR];
+   struct vdevice_status devices[XENUSB_MAX_PORTNR];
+
+   /* Xen related staff */
+   struct xenbus_device *xbdev;
+   int urb_ring_ref;
+   int conn_ring_ref;
+   struct xenusb_urb_front_ring urb_ring;
+   struct xenusb_conn_front_ring conn_ring;
+
+   unsigned int evtchn;
+   unsigned int irq;
+   struct usb_shadow shadow[XENUSB_URB_RING_SIZE];
+   unsigned int shadow_free;
+
+   bool error;
+};
+
+#define GRANT_INVALID_REF 0
+
+#define XENHCD_RING_JIFFIES (HZ/200)
+#define XENHCD_SCAN_JIFFIES 1
+
+enum xenhcd_timer_action {
+   TIMER_RING_WATCHDOG,
+   TIMER_SCAN_PENDING_URBS,
+};
+
+static struct kmem_cache *xenhcd_urbp_cachep;
+
+static inline struct xenhcd_info *xenhcd_hcd_to_info(struct usb_hcd *hcd)
+{
+   return (struct xenhcd_info *)hcd->hcd_priv;
+}
+
+static inline struct usb_hcd *xenhcd_info_to_hcd(struct xenhcd_info *info)
+{
+   retur