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 @@
1What: Raise a uevent when a USB Host Controller has died
2Date: 2019-04-17
3KernelVersion: 5.2
4Contact: linux-usb@vger.kernel.org
5Description: 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
27Users: 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
2435 2435
2436/*-------------------------------------------------------------------------*/2436/*-------------------------------------------------------------------------*/
2437 2437
2438/* Workqueue routine for when the root-hub has died. */
2439static 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
2438/**2451/**
2439 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)2452 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
2440 * @hcd: pointer to the HCD representing the controller2453 * @hcd: pointer to the HCD representing the controller
@@ -2475,6 +2488,13 @@ void usb_hc_died (struct usb_hcd *hcd) · 34 unmodified lines
2475 usb_kick_hub_wq(hcd->self.root_hub);2488 usb_kick_hub_wq(hcd->self.root_hub);
2476 }2489 }
2477 }2490 }
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
2478 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);2498 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2479 /* Make sure that the other roothub is also deallocated. */2499 /* Make sure that the other roothub is also deallocated. */
2480}2500}
@@ -2542,6 +2562,8 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver, · 61 unmodified lines
2542 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);2562 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2543#endif2563#endif
2544 2564
2565 INIT_WORK(&hcd->died_work, hcd_died_work);
2566
2545 hcd->driver = driver;2567 hcd->driver = driver;
2546 hcd->speed = driver->flags & HCD_MASK;2568 hcd->speed = driver->flags & HCD_MASK;
2547 hcd->product_desc = (driver->product_desc) ? driver->product_desc :2569 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
@@ -2895,6 +2917,7 @@ error_create_attr_group: · 347 unmodified lines
2895#ifdef CONFIG_PM2917#ifdef CONFIG_PM
2896 cancel_work_sync(&hcd->wakeup_work);2918 cancel_work_sync(&hcd->wakeup_work);
2897#endif2919#endif
2920 cancel_work_sync(&hcd->died_work);
2898 mutex_lock(&usb_bus_idr_lock);2921 mutex_lock(&usb_bus_idr_lock);
2899 usb_disconnect(&rhdev); /* Sets rhdev to NULL */2922 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2900 mutex_unlock(&usb_bus_idr_lock);2923 mutex_unlock(&usb_bus_idr_lock);
@@ -2955,6 +2978,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) · 54 unmodified lines
2955#ifdef CONFIG_PM2978#ifdef CONFIG_PM
2956 cancel_work_sync(&hcd->wakeup_work);2979 cancel_work_sync(&hcd->wakeup_work);
2957#endif2980#endif
2981 cancel_work_sync(&hcd->died_work);
2958 2982
2959 mutex_lock(&usb_bus_idr_lock);2983 mutex_lock(&usb_bus_idr_lock);
2960 usb_disconnect(&rhdev); /* Sets rhdev to NULL */2984 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
include/linux/usb/hcd.h+1−0
@@ -98,6 +98,7 @@ struct usb_hcd { · 97 unmodified lines
98#ifdef CONFIG_PM98#ifdef CONFIG_PM
99 struct work_struct wakeup_work; /* for remote wakeup */99 struct work_struct wakeup_work; /* for remote wakeup */
100#endif100#endif
101 struct work_struct died_work; /* for when the device dies */
101 102
102 /*103 /*
103 * hardware info/state104 * 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