svn commit: r272733 - in head/sys/dev/usb: . controller
Hans Petter Selasky
hselasky at FreeBSD.org
Wed Oct 8 07:00:52 UTC 2014
Author: hselasky
Date: Wed Oct 8 07:00:50 2014
New Revision: 272733
URL: https://svnweb.freebsd.org/changeset/base/272733
Log:
Add support for disabling USB enumeration in general or on selected
USB HUBs.
MFC after: 2 weeks
Modified:
head/sys/dev/usb/controller/usb_controller.c
head/sys/dev/usb/usb_freebsd.h
head/sys/dev/usb/usb_freebsd_loader.h
head/sys/dev/usb/usb_hub.c
Modified: head/sys/dev/usb/controller/usb_controller.c
==============================================================================
--- head/sys/dev/usb/controller/usb_controller.c Wed Oct 8 05:53:04 2014 (r272732)
+++ head/sys/dev/usb/controller/usb_controller.c Wed Oct 8 07:00:50 2014 (r272733)
@@ -102,6 +102,14 @@ static int usb_no_shutdown_wait = 0;
SYSCTL_INT(_hw_usb, OID_AUTO, no_shutdown_wait, CTLFLAG_RWTUN,
&usb_no_shutdown_wait, 0, "No USB device waiting at system shutdown.");
+#if USB_HAVE_DISABLE_ENUM
+static int usb_disable_enumeration = 0;
+SYSCTL_INT(_hw_usb, OID_AUTO, disable_enumeration, CTLFLAG_RWTUN,
+ &usb_disable_enumeration, 0, "Set to disable all USB device enumeration.");
+#else
+#define usb_disable_enumeration 0
+#endif
+
static devclass_t usb_devclass;
static device_method_t usb_methods[] = {
@@ -371,7 +379,8 @@ usb_bus_explore(struct usb_proc_msg *pm)
USB_BUS_LOCK(bus);
}
- if (udev != NULL && udev->hub != NULL) {
+ if (usb_disable_enumeration == 0 &&
+ udev != NULL && udev->hub != NULL) {
if (bus->do_probe) {
bus->do_probe = 0;
Modified: head/sys/dev/usb/usb_freebsd.h
==============================================================================
--- head/sys/dev/usb/usb_freebsd.h Wed Oct 8 05:53:04 2014 (r272732)
+++ head/sys/dev/usb/usb_freebsd.h Wed Oct 8 07:00:50 2014 (r272733)
@@ -50,6 +50,7 @@
#define USB_HAVE_FIXED_IFACE 0
#define USB_HAVE_FIXED_CONFIG 0
#define USB_HAVE_FIXED_PORT 0
+#define USB_HAVE_DISABLE_ENUM 1
/* define zero ticks callout value */
#define USB_CALLOUT_ZERO_TICKS 1
Modified: head/sys/dev/usb/usb_freebsd_loader.h
==============================================================================
--- head/sys/dev/usb/usb_freebsd_loader.h Wed Oct 8 05:53:04 2014 (r272732)
+++ head/sys/dev/usb/usb_freebsd_loader.h Wed Oct 8 07:00:50 2014 (r272733)
@@ -50,6 +50,7 @@
#define USB_HAVE_FIXED_IFACE 0
#define USB_HAVE_FIXED_CONFIG 0
#define USB_HAVE_FIXED_PORT 0
+#define USB_HAVE_DISABLE_ENUM 0
#define USB_CALLOUT_ZERO_TICKS 1
Modified: head/sys/dev/usb/usb_hub.c
==============================================================================
--- head/sys/dev/usb/usb_hub.c Wed Oct 8 05:53:04 2014 (r272732)
+++ head/sys/dev/usb/usb_hub.c Wed Oct 8 07:00:50 2014 (r272733)
@@ -111,6 +111,9 @@ struct uhub_softc {
struct mtx sc_mtx; /* our mutex */
struct usb_device *sc_udev; /* USB device */
struct usb_xfer *sc_xfer[UHUB_N_TRANSFER]; /* interrupt xfer */
+#if USB_HAVE_DISABLE_ENUM
+ int sc_disable_enumeration;
+#endif
uint8_t sc_flags;
#define UHUB_FLAG_DID_EXPLORE 0x01
};
@@ -993,6 +996,13 @@ uhub_explore(struct usb_device *udev)
DPRINTFN(11, "udev=%p addr=%d\n", udev, udev->address);
+#if USB_HAVE_DISABLE_ENUM
+ /* check if we should skip enumeration from this USB HUB */
+ if (sc->sc_disable_enumeration != 0) {
+ DPRINTF("Enumeration is disabled!\n");
+ return (0);
+ }
+#endif
/* ignore devices that are too deep */
if (uhub_is_too_deep(udev))
return (USB_ERR_TOO_DEEP);
@@ -1188,6 +1198,10 @@ uhub_attach(device_t dev)
struct usb_hub *hub;
struct usb_hub_descriptor hubdesc20;
struct usb_hub_ss_descriptor hubdesc30;
+#if USB_HAVE_DISABLE_ENUM
+ struct sysctl_ctx_list *sysctl_ctx;
+ struct sysctl_oid *sysctl_tree;
+#endif
uint16_t pwrdly;
uint16_t nports;
uint8_t x;
@@ -1469,6 +1483,19 @@ uhub_attach(device_t dev)
usbd_set_power_mode(udev, USB_POWER_MODE_SAVE);
+#if USB_HAVE_DISABLE_ENUM
+ /* Add device sysctls */
+
+ sysctl_ctx = device_get_sysctl_ctx(dev);
+ sysctl_tree = device_get_sysctl_tree(dev);
+
+ if (sysctl_ctx != NULL && sysctl_tree != NULL) {
+ (void) SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
+ OID_AUTO, "disable_enumeration", CTLFLAG_RWTUN,
+ &sc->sc_disable_enumeration, 0,
+ "Set to disable enumeration on this USB HUB.");
+ }
+#endif
return (0);
error:
More information about the svn-src-head
mailing list