History

usb/hcd: Send a uevent signaling that the host controller had died

This change will send an OFFLINE event to udev with the ERROR=DEAD environment variable set when the HC dies. By notifying user space the appropriate policies can be applied. i.e., * Collect error logs. * Notify the user that USB is no longer functional. * Perform a graceful reboot.

Raul E Rangel committed 7 years ago

Commit a4d6a291 parent cf283693 files · +52 −0Browse files

Unified · Split

3 files
  1. Documentation/ABI/testing/usb-uevent +27 −0
  2. drivers/usb/core/hcd.c +24 −0
  3. include/linux/usb/hcd.h +1 −0
Documentation/ABI/testing/usb-uevent+27−0
@@ -0,0 +1,27 @@
1+What: Raise a uevent when a USB Host Controller has died
2+Date: 2019-04-17
3+KernelVersion: 5.2
4+Contact: linux-usb@vger.kernel.org
5+Description: When the USB Host Controller has entered a state where it is no
6+ longer functional a uevent will be raised. The uevent will
7+ contain ACTION=offline and ERROR=DEAD.
8+
9+ Here is an example taken using udevadm monitor -p:
10+
11+ KERNEL[130.428945] offline /devices/pci0000:00/0000:00:10.0/usb2 (usb)
12+ ACTION=offline
13+ BUSNUM=002
14+ DEVNAME=/dev/bus/usb/002/001
15+ DEVNUM=001
16+ DEVPATH=/devices/pci0000:00/0000:00:10.0/usb2
17+ DEVTYPE=usb_device
18+ DRIVER=usb
19+ ERROR=DEAD
20+ MAJOR=189
21+ MINOR=128
22+ PRODUCT=1d6b/2/414
23+ SEQNUM=2168
24+ SUBSYSTEM=usb
25+ TYPE=9/0/1
26+
27+Users: chromium-os-dev@chromium.org
drivers/usb/core/hcd.c+24−0
@@ -2435,6 +2435,19 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq); · 2434 unmodified lines
24352435
24362436 /*-------------------------------------------------------------------------*/
24372437
2438+/* Workqueue routine for when the root-hub has died. */
2439+static void hcd_died_work(struct work_struct *work)
2440+{
2441+ struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work);
2442+ static char *env[] = {
2443+ "ERROR=DEAD",
2444+ NULL
2445+ };
2446+
2447+ /* Notify user space that the host controller has died */
2448+ kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env);
2449+}
2450+
24382451 /**
24392452 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
24402453 * @hcd: pointer to the HCD representing the controller
@@ -2475,6 +2488,13 @@ void usb_hc_died (struct usb_hcd *hcd) · 34 unmodified lines
24752488 usb_kick_hub_wq(hcd->self.root_hub);
24762489 }
24772490 }
2491+
2492+ /* Handle the case where this function gets called with a shared HCD */
2493+ if (usb_hcd_is_primary_hcd(hcd))
2494+ schedule_work(&hcd->died_work);
2495+ else
2496+ schedule_work(&hcd->primary_hcd->died_work);
2497+
24782498 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
24792499 /* Make sure that the other roothub is also deallocated. */
24802500 }
@@ -2542,6 +2562,8 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver, · 61 unmodified lines
25422562 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
25432563 #endif
25442564
2565+ INIT_WORK(&hcd->died_work, hcd_died_work);
2566+
25452567 hcd->driver = driver;
25462568 hcd->speed = driver->flags & HCD_MASK;
25472569 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
@@ -2895,6 +2917,7 @@ error_create_attr_group: · 347 unmodified lines
28952917 #ifdef CONFIG_PM
28962918 cancel_work_sync(&hcd->wakeup_work);
28972919 #endif
2920+ cancel_work_sync(&hcd->died_work);
28982921 mutex_lock(&usb_bus_idr_lock);
28992922 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
29002923 mutex_unlock(&usb_bus_idr_lock);
@@ -2955,6 +2978,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) · 54 unmodified lines
29552978 #ifdef CONFIG_PM
29562979 cancel_work_sync(&hcd->wakeup_work);
29572980 #endif
2981+ cancel_work_sync(&hcd->died_work);
29582982
29592983 mutex_lock(&usb_bus_idr_lock);
29602984 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
include/linux/usb/hcd.h+1−0
@@ -98,6 +98,7 @@ struct usb_hcd { · 97 unmodified lines
9898 #ifdef CONFIG_PM
9999 struct work_struct wakeup_work; /* for remote wakeup */
100100 #endif
101+ struct work_struct died_work; /* for when the device dies */
101102
102103 /*
103104 * hardware info/state

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t