diff mbox series

[v2] usb: export firmware port location in sysfs

Message ID 20180928103502.13256-1-bjorn@mork.no (mailing list archive)
State New, archived
Headers show
Series [v2] usb: export firmware port location in sysfs | expand

Commit Message

Bjørn Mork Sept. 28, 2018, 10:35 a.m. UTC
The platform firmware "location" data is used to find port peer
relationships. But firmware is an unreliable source, and there are
real world examples of errors leading to missing or wrong peer
relationships.  Debugging this is currently hard.

Exporting the location attribute makes it easier to spot mismatches
between the firmware data and the real world.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
v2: Sorry, forgot to rebase the old branch before sending v1

This patch got stuck in one of my debugging branches.  It proved very
useful to me while trying to figure out why the "peer" link was useless
on a specific host. And if it was useful to me once, then maybe it will
be to someone else as well...

tl;dr; The full use case for anyone interested:

Some current LTE modems with USB3 SS support come with a bootloader
supporting USB2 only. The application and bootloader modes are provided
by different softwares running on the modem (which of course is just
another Linux system with a UDC).  None of the descriptors are therefore
guaranteed to be identical, or even similar.

Doing a firmware upgrade of such a device involves
 - some preparation in application mode (USB3), 
 - rebooting into bootloader mode (USB2), and 
 - finally booting into the upgraded application firmware (USB3) to verify
   the upgrade. 

The firmware upgrade tool should make sure it talks to the same physical
device in all three phases.  The only semi-reliable way to do that is to
look for "new" devices in the expected mode, connected to the same physical
USB port. But the locical port will change due to the USB2/3 switch, and
all we are left with is the "peer" link.  Which can, and do, fail due to
buggy ACPI tables.

This patch won't solve that problem, but it makes it a lot easier to
detect.

 Documentation/ABI/testing/sysfs-bus-usb | 18 ++++++++++++++----
 drivers/usb/core/port.c                 |  9 +++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

Comments

kernel test robot Sept. 28, 2018, 11:44 a.m. UTC | #1
Hi Bjørn,

I love your patch! Perhaps something to improve:

[auto build test WARNING on peter.chen-usb/ci-for-usb-next]
[also build test WARNING on v4.19-rc5 next-20180928]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Bj-rn-Mork/usb-export-firmware-port-location-in-sysfs/20180928-192720
base:   https://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git ci-for-usb-next
config: i386-randconfig-x005-201838 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/linux/pm_qos.h:10:0,
                    from drivers/usb//core/port.c:11:
   include/linux/device.h:598:26: warning: 'dev_attr_location' defined but not used [-Wunused-variable]
     struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
                             ^
>> drivers/usb//core/port.c:26:8: note: in expansion of macro 'DEVICE_ATTR_RO'
    static DEVICE_ATTR_RO(location);
           ^~~~~~~~~~~~~~

vim +/DEVICE_ATTR_RO +26 drivers/usb//core/port.c

  > 11	#include <linux/pm_qos.h>
    12	
    13	#include "hub.h"
    14	
    15	static int usb_port_block_power_off;
    16	
    17	static const struct attribute_group *port_dev_group[];
    18	
    19	static ssize_t location_show(struct device *dev,
    20				     struct device_attribute *attr, char *buf)
    21	{
    22		struct usb_port *port_dev = to_usb_port(dev);
    23	
    24		return sprintf(buf, "0x%08x\n", port_dev->location);
    25	}
  > 26	static DEVICE_ATTR_RO(location);
    27	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index 08d456e07b53..8f394c976fee 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -173,14 +173,14 @@  Description:
 		The file will be present for all speeds of USB devices, and will
 		always read "no" for USB 1.1 and USB 2.0 devices.
 
-What:		/sys/bus/usb/devices/.../(hub interface)/portX
+What:		/sys/bus/usb/devices/.../(hub interface)/usbY-portX
 Date:		August 2012
 Contact:	Lan Tianyu <tianyu.lan@intel.com>
 Description:
 		The /sys/bus/usb/devices/.../(hub interface)/portX
 		is usb port device's sysfs directory.
 
-What:		/sys/bus/usb/devices/.../(hub interface)/portX/connect_type
+What:		/sys/bus/usb/devices/.../(hub interface)/usbY-portX/connect_type
 Date:		January 2013
 Contact:	Lan Tianyu <tianyu.lan@intel.com>
 Description:
@@ -189,7 +189,17 @@  Description:
 		The file will read "hotplug", "wired" and "not used" if the
 		information is available, and "unknown" otherwise.
 
-What:		/sys/bus/usb/devices/.../(hub interface)/portX/quirks
+What:		/sys/bus/usb/devices/.../(hub interface)/usbY-portX/location
+Date:		October 2018
+Contact:	Bjørn Mork <bjorn@mork.no>
+Description:
+		Some platforms provide usb port physical location through
+		firmware. This is used by the kernel to pair up logical ports
+		mapping to the same physical connector. The attribute exposes the
+		raw location value as a hex integer.
+
+
+What:		/sys/bus/usb/devices/.../(hub interface)/usbY-portX/quirks
 Date:		May 2018
 Contact:	Nicolas Boichat <drinkcat@chromium.org>
 Description:
@@ -211,7 +221,7 @@  Description:
 		   used to help make enumeration work better on some high speed
 		   devices.
 
-What:		/sys/bus/usb/devices/.../(hub interface)/portX/over_current_count
+What:		/sys/bus/usb/devices/.../(hub interface)/usbY-portX/over_current_count
 Date:		February 2018
 Contact:	Richard Leitner <richard.leitner@skidata.com>
 Description:
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 4a2143195395..47e45d317201 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -16,6 +16,15 @@  static int usb_port_block_power_off;
 
 static const struct attribute_group *port_dev_group[];
 
+static ssize_t location_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct usb_port *port_dev = to_usb_port(dev);
+
+	return sprintf(buf, "0x%08x\n", port_dev->location);
+}
+static DEVICE_ATTR_RO(location);
+
 static ssize_t connect_type_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {