[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251104113248.223594-2-lec.jakub@gmail.com>
Date: Tue, 4 Nov 2025 12:32:46 +0100
From: Jakub Lecki <lec.jakub@...il.com>
To: linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: Valentina Manea <valentina.manea.m@...il.com>,
Shuah Khan <shuah@...nel.org>,
Hongren Zheng <i@...ithal.me>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jakub Lecki <lec.jakub@...il.com>
Subject: [PATCH 1/3] usbip: Convert CONFIG_USBIP_VHCI_NR_HCS to a module parameter.
In workflows involving a greater number of remote
USB/IP devices, the default number of available virtual ports may be
insufficient, forcing user to recompile the module with greater number
of configured virtual host controllers and/or number of ports.
Allow a user to configure the number of USB/IP virtual host controllers
via a new 'num_controllers' module parameter to simplify the usage of
this module.
VHCI controller structures are already dynamically allocated during
module initialization, so the only change is switch from assigning
'vhci_num_controllers' via Kconfig to using the module parameter
framework.
- Remove the USBIP_VHCI_NR_HCS Kconfig option and replace it with a
module parameter.
- Trim the value of the configured 'num_controllers' parameter if it
exceeds bounds, and emit a warning.
Signed-off-by: Jakub Lecki <lec.jakub@...il.com>
---
drivers/usb/usbip/Kconfig | 11 -----------
drivers/usb/usbip/vhci.h | 9 +++------
drivers/usb/usbip/vhci_hcd.c | 16 ++++++++++++++--
3 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig
index b9f94e2e278d..bdcb6f4fdbec 100644
--- a/drivers/usb/usbip/Kconfig
+++ b/drivers/usb/usbip/Kconfig
@@ -38,17 +38,6 @@ 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"
- range 1 128
- default 1
- depends on USBIP_VHCI_HCD
- 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.
-
config USBIP_HOST
tristate "Host driver"
depends on USBIP_CORE && USB
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index 5659dce1526e..30b8540e0b49 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -82,11 +82,8 @@ enum hub_speed {
/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
#define VHCI_PORTS (VHCI_HC_PORTS*2)
-#ifdef CONFIG_USBIP_VHCI_NR_HCS
-#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
-#else
-#define VHCI_NR_HCS 1
-#endif
+#define VHCI_DEFAULT_NR_HCS 1
+#define VHCI_MAX_NR_HCS 128
#define MAX_STATUS_NAME 16
@@ -118,7 +115,7 @@ struct vhci_hcd {
struct vhci_device vdev[VHCI_HC_PORTS];
};
-extern int vhci_num_controllers;
+extern unsigned int vhci_num_controllers;
extern struct vhci *vhcis;
extern struct attribute_group vhci_attr_group;
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index e70fba9f55d6..93c3fa3e1c53 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -10,6 +10,7 @@
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/printk.h>
#include <linux/slab.h>
#include <linux/string_choices.h>
@@ -44,7 +45,12 @@ static int vhci_get_frame_number(struct usb_hcd *hcd);
static const char driver_name[] = "vhci_hcd";
static const char driver_desc[] = "USB/IP Virtual Host Controller";
-int vhci_num_controllers = VHCI_NR_HCS;
+unsigned int vhci_num_controllers = VHCI_DEFAULT_NR_HCS;
+module_param_named(num_controllers, vhci_num_controllers, uint, 0444);
+MODULE_PARM_DESC(num_controllers, "Number of USB/IP virtual host controllers (range: 0-"
+ __MODULE_STRING(VHCI_MAX_NR_HCS) ", default: "
+ __MODULE_STRING(VHCI_DEFAULT_NR_HCS) ")");
+
struct vhci *vhcis;
static const char * const bit_desc[] = {
@@ -1510,8 +1516,14 @@ static int __init vhci_hcd_init(void)
if (usb_disabled())
return -ENODEV;
- if (vhci_num_controllers < 1)
+ if (vhci_num_controllers < 1) {
+ pr_warn("num_controllers less than 1, setting to 1\n");
vhci_num_controllers = 1;
+ } else if (vhci_num_controllers > VHCI_MAX_NR_HCS) {
+ pr_warn("num_controllers too high, limiting to %d\n",
+ VHCI_MAX_NR_HCS);
+ vhci_num_controllers = VHCI_MAX_NR_HCS;
+ }
vhcis = kcalloc(vhci_num_controllers, sizeof(struct vhci), GFP_KERNEL);
if (vhcis == NULL)
--
2.43.0
Powered by blists - more mailing lists