From patchwork Fri Sep 28 10:35:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 10619559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0E90112B for ; Fri, 28 Sep 2018 10:35:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E34EB2AF05 for ; Fri, 28 Sep 2018 10:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D76C62AF31; Fri, 28 Sep 2018 10:35:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B5A22AF05 for ; Fri, 28 Sep 2018 10:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729373AbeI1Q62 (ORCPT ); Fri, 28 Sep 2018 12:58:28 -0400 Received: from canardo.mork.no ([148.122.252.1]:50115 "EHLO canardo.mork.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729242AbeI1Q62 (ORCPT ); Fri, 28 Sep 2018 12:58:28 -0400 Received: from miraculix.mork.no ([IPv6:2a02:2121:2c4:9292:c40f:c1ff:fecc:90f1]) (authenticated bits=0) by canardo.mork.no (8.15.2/8.15.2) with ESMTPSA id w8SAZInU016962 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 28 Sep 2018 12:35:19 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1538130919; bh=bg1+knOHJesWmQd9kZ+hQdc3cz5/gxgWdqmk5ahpx38=; h=From:To:Cc:Subject:Date:Message-Id:From; b=M42yo8GuFn8yCOH7l5GGvIi5wnZLvbSkSB5qPpGttROazybahhiBOyu6ytgCxy2j4 0C66Fx8LBACdJjnrkLAumOUcV9cHoi65DcbtFJKUswEz7NaLKy6z5LwHm3BhrqTogj Qx8khXk8oZ60sRD6DeVSCofkFenfUfOSHZXvdPwg= Received: from bjorn by miraculix.mork.no with local (Exim 4.89) (envelope-from ) id 1g5q71-0003TT-O2; Fri, 28 Sep 2018 12:35:07 +0200 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: linux-usb@vger.kernel.org Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Subject: [PATCH v2] usb: export firmware port location in sysfs Date: Fri, 28 Sep 2018 12:35:02 +0200 Message-Id: <20180928103502.13256-1-bjorn@mork.no> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.100.1 at canardo X-Virus-Status: Clean Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(-) 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 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 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 +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 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 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) {