All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eugeniu Rosca <erosca@de.adit-jv.com>
To: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Mathias Nyman <mathias.nyman@linux.intel.com>,
	Kai-Heng Feng <kai.heng.feng@canonical.com>,
	Felipe Balbi <felipe.balbi@linux.intel.com>,
	Nicolas Boichat <drinkcat@chromium.org>,
	Mathias Payer <mathias.payer@nebelwelt.net>,
	Kento Kobayashi <Kento.A.Kobayashi@sony.com>,
	Hui Peng <benquike@gmail.com>,
	Raul E Rangel <rrangel@chromium.org>,
	Douglas Anderson <dianders@chromium.org>,
	Jan-Marek Glogowski <glogow@fbihome.de>, Bin Liu <b-liu@ti.com>,
	Colin Ian King <colin.king@canonical.com>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	Jon Flatley <jflat@chromium.org>,
	Mathieu Malaterre <malat@debian.org>
Cc: Spyridon Papageorgiou <spapageorgiou@de.adit-jv.com>,
	Eugeniu Rosca <erosca@de.adit-jv.com>,
	Eugeniu Rosca <roscaeugeniu@gmail.com>,
	Joshua Frkuska <joshua_frkuska@mentor.com>,
	"George G . Davis" <george_davis@mentor.com>,
	<yuichi.kusakabe@denso-ten.com>, <yohhei.fukui@denso-ten.com>,
	<natsumi.kamei@denso-ten.com>, <yasano@jp.adit-jv.com>
Subject: [PATCH] usb: hub: report failure to enumerate uevent to userspace
Date: Wed, 5 Jun 2019 11:05:56 +0200	[thread overview]
Message-ID: <20190605090556.17792-1-erosca@de.adit-jv.com> (raw)

From: Spyridon Papageorgiou <spapageorgiou@de.adit-jv.com>

When a USB device fails to enumerate, only a kernel message is printed.
With this patch, a uevent is also generated to notify userspace.
Services can monitor for the event through udev and handle failures
accordingly.

The "port_enumerate_fail_notify()" function name follows the syntax of
"port_over_current_notify()" used in v4.20-rc1
commit 201af55da8a398 ("usb: core: added uevent for over-current").

Signed-off-by: Spyridon Papageorgiou <spapageorgiou@de.adit-jv.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
 Documentation/ABI/testing/usb-uevent | 36 ++++++++++++++++++++++++++++
 drivers/usb/core/hub.c               | 15 +++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/usb-uevent b/Documentation/ABI/testing/usb-uevent
index d35c3cad892c..23e618227d31 100644
--- a/Documentation/ABI/testing/usb-uevent
+++ b/Documentation/ABI/testing/usb-uevent
@@ -25,3 +25,39 @@ Description:	When the USB Host Controller has entered a state where it is no
 		TYPE=9/0/1
 
 Users:		chromium-os-dev@chromium.org
+
+What:		Raise a uevent when USB device enumeration has failed
+Date:		2019-06-05
+KernelVersion:	5.2
+Contact:	linux-usb@vger.kernel.org
+Description:	When a USB device has failed to enumerate, a uevent will be generated.
+		The uevent will contain ACTION=change, ENUMERATION_FAILURE=1 and
+		ENUMERATION_FAIL_PORT=<port_id>. Services can monitor for the event
+		through udev and handle failures accordingly.
+
+		Here is an example taken using udevadm monitor -p (R-Car H3ULCB):
+
+		UDEV  [47.298493] change   /devices/platform/soc/ee0a0000.usb/usb4/4-0:1.0 (usb)
+		ACTION=change
+		DEVPATH=/devices/platform/soc/ee0a0000.usb/usb4/4-0:1.0
+		DEVTYPE=usb_interface
+		DRIVER=hub
+		ENUMERATION_FAILURE=1
+		ENUMERATION_FAIL_PORT=1
+		ID_MODEL_FROM_DATABASE=1.1 root hub
+		ID_USB_CLASS_FROM_DATABASE=Hub
+		ID_USB_PROTOCOL_FROM_DATABASE=Full speed (or root) hub
+		ID_VENDOR_FROM_DATABASE=Linux Foundation
+		INTERFACE=9/0/0
+		MODALIAS=usb:v1D6Bp0001d0502dc09dsc00dp00ic09isc00ip00in00
+		OF_COMPATIBLE_0=generic-ohci
+		OF_COMPATIBLE_N=1
+		OF_FULLNAME=/soc/usb@ee0a0000
+		OF_NAME=usb
+		PRODUCT=1d6b/1/502
+		SEQNUM=1762
+		SUBSYSTEM=usb
+		TYPE=9/0/0
+		USEC_INITIALIZED=24344435
+
+Users:		ADIT, DENSO TEN
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2f94568ba385..da1a3d47a071 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4921,6 +4921,17 @@ hub_power_remaining(struct usb_hub *hub)
 	return remaining;
 }
 
+static void port_enumerate_fail_notify(struct usb_port *port)
+{
+	char env_port[32];
+	char *envp[3] = { "ENUMERATION_FAILURE=1", env_port, NULL };
+
+	snprintf(env_port, sizeof(env_port), "ENUMERATION_FAIL_PORT=%d",
+		 port->portnum);
+
+	kobject_uevent_env(&port->dev.parent->kobj, KOBJ_CHANGE, envp);
+}
+
 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 		u16 portchange)
 {
@@ -5131,9 +5142,11 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
 	if (hub->hdev->parent ||
 			!hcd->driver->port_handed_over ||
 			!(hcd->driver->port_handed_over)(hcd, port1)) {
-		if (status != -ENOTCONN && status != -ENODEV)
+		if (status != -ENOTCONN && status != -ENODEV) {
+			port_enumerate_fail_notify(port_dev);
 			dev_err(&port_dev->dev,
 					"unable to enumerate USB device\n");
+		}
 	}
 
 done:
-- 
2.21.0


             reply	other threads:[~2019-06-05  9:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05  9:05 Eugeniu Rosca [this message]
2019-06-05 10:03 ` [PATCH] usb: hub: report failure to enumerate uevent to userspace Greg Kroah-Hartman
2019-06-05 16:55   ` Eugeniu Rosca
2019-06-05 17:48     ` Greg Kroah-Hartman
2019-06-05 21:19   ` David Howells
2019-06-05 21:22   ` David Howells

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=20190605090556.17792-1-erosca@de.adit-jv.com \
    --to=erosca@de.adit-jv.com \
    --cc=Kento.A.Kobayashi@sony.com \
    --cc=b-liu@ti.com \
    --cc=benquike@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=dianders@chromium.org \
    --cc=drinkcat@chromium.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=george_davis@mentor.com \
    --cc=glogow@fbihome.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jflat@chromium.org \
    --cc=joshua_frkuska@mentor.com \
    --cc=kai.heng.feng@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=malat@debian.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mathias.payer@nebelwelt.net \
    --cc=natsumi.kamei@denso-ten.com \
    --cc=nsaenzjulienne@suse.de \
    --cc=roscaeugeniu@gmail.com \
    --cc=rrangel@chromium.org \
    --cc=spapageorgiou@de.adit-jv.com \
    --cc=stern@rowland.harvard.edu \
    --cc=yasano@jp.adit-jv.com \
    --cc=yohhei.fukui@denso-ten.com \
    --cc=yuichi.kusakabe@denso-ten.com \
    /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.