Re: [PATCH v4 3/3] usbip: vhci extension: dynamic extension

2016-08-09 Thread Greg KH
On Mon, Jun 13, 2016 at 11:33:42AM +0900, Nobuo Iwata wrote:
> Modification for dynamic device registration and unregistration.

As I didn't take patch 2/3, can you resend this one as well after fixing
up that patch?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/3] usbip: vhci extension: dynamic extension

2016-06-12 Thread Nobuo Iwata
Modification for dynamic device registration and unregistration.

1. kernel config

Followings are added.

USBIP_VHCI_HC_PORTS: Number of ports per USB/IP virtual host 
controller. The default is 8 - same as current VHCI_NPORTS.
USBIP_VHCI_MAX_HCS: Muximum number of USB/IP virtual host controllers. 
The default is 1.
USBIP_VHCI_INIT_HCS: Initial number of USB/IP virtual host controllers. 
The default is 1.
Static number of devices: USBIP_VHCI_NR_HCS in patch 1/3 is removed 
with this patch.

2. view from sysfs

Sysfs structure is changed as following.

BEFORE this patchset:
/sys/devices/platform
+-- vhci
+-- status
+-- attach
+-- detach
+-- usbip_debug

AFTER: example for CONFIG_USBIP_INIT_HCS=2 CONFIG_USBIP_MAX_HCS=4
At the beginning
/sys/devices/platform
+-- vhci
|   +-- nports
|   +-- status
|   +-- status.1
|   +-- status.2
|   +-- status.3
|   +-- attach
|   +-- detach
|   +-- usbip_debug
+-- vhci.1

The status files are shown to the maximum number of devices. Port 
status in status.2 and status.3 represents as free but corresponding 
devices are not yes registered.
When all ports in status and status.1 are used, userspace tool requests 
'attach' to a port in status.2 then vhci.2 will be registred. The limit 
is defined with USBIP_VHCI_MAX_NCS.

By preparing muximum number of status files, there's no need to 
introduce additional operations for userspace tool.

When number of free ports becomes more than USBIP_VHCI_HC_PORTS * 
VHCI_FREE_HCS(2), a free controller other than the first one will be 
unregistered. It will be invoked by 'detach' operation and other error 
situations which ports are released.

Signed-off-by: Nobuo Iwata 
---
 drivers/usb/usbip/Kconfig  |  17 ++-
 drivers/usb/usbip/vhci.h   |  36 -
 drivers/usb/usbip/vhci_hcd.c   | 251 -
 drivers/usb/usbip/vhci_rx.c|  10 +-
 drivers/usb/usbip/vhci_sysfs.c |  49 ---
 drivers/usb/usbip/vhci_tx.c|   6 +-
 6 files changed, 294 insertions(+), 75 deletions(-)

diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig
index 29492c7..d11b548 100644
--- a/drivers/usb/usbip/Kconfig
+++ b/drivers/usb/usbip/Kconfig
@@ -34,8 +34,8 @@ config USBIP_VHCI_HC_PORTS
  host controller driver, this defines number of ports per
  USB/IP virtual host controller.
 
-config USBIP_VHCI_NR_HCS
-   int "Number of USB/IP virtual host controllers"
+config USBIP_VHCI_MAX_HCS
+   int "Maximum number of USB/IP virtual host controllers"
range 1 128
default 1
depends on USBIP_VHCI_HCD
@@ -43,7 +43,18 @@ config USBIP_VHCI_NR_HCS
  To increase number of ports available for USB/IP virtual
  host controller driver, this defines number of USB/IP
  virtual host controllers as if adding physical host
- controllers.
+ controllers. This defines the maximum number.
+
+config USBIP_VHCI_INIT_HCS
+   int "Initial number of USB/IP virtual host controllers"
+   range 1 USBIP_VHCI_MAX_HCS
+   default 1
+   depends on USBIP_VHCI_MAX_HCS
+   ---help---
+ To increase number of ports available for USB/IP virtual
+ host controller driver, this defines number of USB/IP
+ virtual host controllers as if adding physical host
+ controllers. This defines the number at initializing.
 
 config USBIP_HOST
tristate "Host driver"
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index 88b71c4..ba893a7 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -51,6 +51,9 @@ struct vhci_device {
 
/* vhci_tx thread sleeps for this queue */
wait_queue_head_t waitq_tx;
+
+   /* denotes port is in-use */
+   atomic_t using_port;
 };
 
 /* urb->hcpriv, use container_of() */
@@ -79,12 +82,21 @@ struct vhci_unlink {
 #define VHCI_HC_PORTS 8
 #endif
 
-#ifdef CONFIG_USBIP_VHCI_NR_HCS
-#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
+#ifdef CONFIG_USBIP_VHCI_MAX_HCS
+#define VHCI_MAX_HCS CONFIG_USBIP_VHCI_MAX_HCS
+#else
+#define VHCI_MAX_HCS 1
+#endif
+
+#ifdef CONFIG_USBIP_VHCI_INIT_HCS
+#define VHCI_INIT_HCS CONFIG_USBIP_VHCI_INIT_HCS
 #else
-#define VHCI_NR_HCS 1
+#define VHCI_INIT_HCS 1
 #endif
 
+/* VHCI_FREE_HCS * VHCI_HC_PORTS: ports to keep free at unregister */
+#define VHCI_FREE_HCS 2
+
 #define MAX_STATUS_NAME 16
 
 /* for usb_bus.hcpriv */
@@ -98,6 +110,8 @@ struct vhci_hcd {
 
atomic_t seqnum;
 
+   unsigned int using_ports;
+
/*
 * NOTE:
 * wIndex shows the port number and begins from 1.
@@ -106,12 +120,18 @@ struct vhci_hcd {
struct vhci_device vdev[VHCI_HC_PORTS];
 };
 
+extern int vhci_max_controllers;
+extern int vhci_init_controllers;
 extern int vhci_num_controllers;
 extern struct platform_device **vhci_pdevs;
 extern struct