From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309008; b=4mP3w+alm0HlDks8ea9D969taKaCnMYkMH99aNRkC+qA72pulGKkPb/N73CJq2EJiPT1 G3vbn0KXsdkS34owo6LC5THWvKR/QzCYE1fXRvC0/NC2QnFTFmXCar3LZr81VvpymSRA5 JO6OVPIQn0RbqmZXmyU/zx0/Ol8CAO7SeVUwENlG/qWRGDTWHstVzDlAaNP0sEC+nwswL Zsues64l0Vj9onXe3SQ1Y9f8P/sTH6XPhRgUHEWwrdlbBoiiiFkGlYhmYKKYT+jnVy2Kh npdPHMrQffkWT4I1UvgHUfwr6e6oFpvOA+e93D1p3lnBTDA2mkmOhAwkUFfnpKbUBVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309008; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=oBKpMTn+OcuU/Eyv1YmnKESPSFOjd6ydKISWzY+eSxc=; b=Ndmaf8XmZApaSawr6cK+ATnak8VAfKfsnM/Ac2hr0XNJGZ7/Usp1VdgB62bCi8JLIQ37 uSGpXoF4nPMwbqYLyebXQBkV/n/93Tl+D8bqy9knOucfiw01sps+xb39gbCRNvlU4V7QP 7kDzbnKrmUuOpo2lWaDfSrCJZyVFzvA9X0A06g/lFPrh17M9H1lPibTtB4QOLh4OnaWSd M/e2zPJISK+axdeR3CvA2nR0jKAIY4vSYxtLr22upWHTqrXiHKoh5h9QSK9Y8Q/r9Gs6x B/b9sjNZTvSSAuw5ujQNgxNazes2JIR2PI08E6I1yQR4hrQj9VNqpkS9Lw5OEgLnOzQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=e8ibEwQ4; arc=none smtp.remote-ip=198.175.65.13 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE1C606A32F for ; Thu, 3 Dec 2026 14:43:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9DE1C606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=e8ibEwQ4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796309008; x=1827845008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oBKpMTn+OcuU/Eyv1YmnKESPSFOjd6ydKISWzY+eSxc=; b=e8ibEwQ4QpmmGeRXeBe1PV1MjV8pGesd/kBv+rI06sce0lC9TtECq/aR ZtntgpfBNMf/aZhSt9rjkIACj/7z7WftBAQeVZHMPiS49KQI9QLdu1MeW jRM+iEh5ykKwlc07/D1wy0+M/u6Jb9MWM230yUl8G1XaFi+wWuHtSIO0s L1LyRYvFsELnpGAkh9mu/SRb/sesoOnGZQoa9SrTYw8GzPIDdBuGR9JDe Q9ykuFvzbHD5mo1Hlu5vNdkJIiBf07WHVFqOaJeYXOxrv1ZskG0Zmrm55 5NtezCLOxWzUyfUi+T/UrgSUAtSsYXhp1EzWvvZeZS+JBXViDBowb0rBH Q==; X-CSE-ConnectionGUID: qoD6onDqQii0bJVUn//0/g== X-CSE-MsgGUID: 8LnCaMV9Tgacn4SSzRYGlQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5182617" X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="5182617" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 06:43:28 -0800 X-CSE-ConnectionGUID: +UB/mwjyTmSlRhWT1yrKrw== X-CSE-MsgGUID: X0s0p/grQqa1C/YuWOyb8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="14024131" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa001.jf.intel.com with ESMTP; 03 Dec 2026 06:43:26 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id 51EBB99; Thu, 03 Dec 2026 15:43:25 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH v3 02/12] usb: xhci: rework Port Speed macros Date: Thu, 3 Dec 2026 15:42:34 +0100 Message-ID: <20261203144244.1680587-3-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261203144244.1680587-1-niklas.neronin@linux.intel.com> References: <20261203144244.1680587-1-niklas.neronin@linux.intel.com> X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The PORTSC Port Speed macros are defined as values pre-shifted into bits 13:10, along with a set of DEV_*SPEED() helpers that mask and compare them. Replace DEV_SPEED_MASK with PORT_SPEED_MASK, defined using GENMASK(), and replace the pre-shifted XDEV_* speed IDs with plain PORT_SPEED_* field values. Callers now use FIELD_GET() to extract the field and compare it directly. Remove the DEV_*SPEED() and DEV_PORT_SPEED() helpers. DEV_UNDEFSPEED() and DEV_SUPERSPEEDPLUS() have no users and are dropped. The SLOT_SPEED_* macros describe Slot Context bits 23:20 and were built by shifting the pre-shifted PORTSC values again. Move them next to the other Slot Context 'dev_info' definitions in xhci.h and shift the speed ID by 20 directly. Update the Port Speed comment to list all speed IDs defined in xHCI specification section 7.2.2.1.1. No functional change. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-debugfs.c | 6 ++--- drivers/usb/host/xhci-hub.c | 8 +++--- drivers/usb/host/xhci-port.h | 46 ++++++++++++++------------------- drivers/usb/host/xhci-ring.c | 4 +-- drivers/usb/host/xhci-tegra.c | 13 ++++++---- drivers/usb/host/xhci.h | 13 ++++++++-- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 2aa01d99f23d..79bc1f7d745a 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -715,7 +715,7 @@ static int xhci_ss_bw_show(struct seq_file *s, void *unused) int ret; struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; - ret = xhci_port_bw_show(xhci, DEV_PORT_SPEED(XDEV_SS), s); + ret = xhci_port_bw_show(xhci, PORT_SPEED_SS, s); return ret; } @@ -724,7 +724,7 @@ static int xhci_hs_bw_show(struct seq_file *s, void *unused) int ret; struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; - ret = xhci_port_bw_show(xhci, DEV_PORT_SPEED(XDEV_HS), s); + ret = xhci_port_bw_show(xhci, PORT_SPEED_HS, s); return ret; } @@ -733,7 +733,7 @@ static int xhci_fs_bw_show(struct seq_file *s, void *unused) int ret; struct xhci_hcd *xhci = (struct xhci_hcd *)s->private; - ret = xhci_port_bw_show(xhci, DEV_PORT_SPEED(XDEV_FS), s); + ret = xhci_port_bw_show(xhci, PORT_SPEED_FS, s); return ret; } diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 55430b673f1e..ff9d9b26f810 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -376,9 +376,11 @@ static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, static unsigned int xhci_port_speed(int portsc) { - if (DEV_LOWSPEED(portsc)) + u32 port_speed = FIELD_GET(PORT_SPEED_MASK, portsc); + + if (port_speed == PORT_SPEED_LS) return USB_PORT_STAT_LOW_SPEED; - if (DEV_HIGHSPEED(portsc)) + if (port_speed == PORT_SPEED_HS) return USB_PORT_STAT_HIGH_SPEED; /* * FIXME: Yes, we should check for full speed, but the core uses that as @@ -1007,7 +1009,7 @@ static u32 xhci_get_ext_port_status(u32 portsc, u32 port_li) int speed_id; /* only support rx and tx lane counts of 1 in usb3.1 spec */ - speed_id = DEV_PORT_SPEED(portsc); + speed_id = FIELD_GET(PORT_SPEED_MASK, portsc); ext_stat |= speed_id; /* bits 3:0, RX speed id */ ext_stat |= speed_id << 4; /* bits 7:4, TX speed id */ diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h index 45e081a9c510..ec822f2f92d0 100644 --- a/drivers/usb/host/xhci-port.h +++ b/drivers/usb/host/xhci-port.h @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include /* PORTSC - Port Status and Control Register - port_status_base bitmasks */ @@ -33,35 +34,26 @@ /* true: port has power (see HCC_PPC) */ #define PORT_POWER BIT(9) -/* bits 10:13 indicate device speed: - * 0 - undefined speed - port hasn't be initialized by a reset yet - * 1 - full speed - * 2 - low speed - * 3 - high speed - * 4 - super speed - * 5-15 reserved +/* + * bits 13:10 - Port Speed + * Values defined in xHCI specification 7.2.2.1.1: + * 0 - undefined speed - port hasn't been initialized by a reset yet + * 1 - Full-speed + * 2 - Low-speed + * 3 - High-speed + * 4 - SuperSpeed Gen1 x1 + * 5 - SuperSpeed Gen2 x1 + * 6 - SuperSpeed Gen1 x2 + * 7 - SuperSpeed Gen2 x2 + * 8-15 Reserved */ -#define DEV_SPEED_MASK (0xf << 10) -#define XDEV_FS (0x1 << 10) -#define XDEV_LS (0x2 << 10) -#define XDEV_HS (0x3 << 10) -#define XDEV_SS (0x4 << 10) -#define XDEV_SSP (0x5 << 10) -#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10)) -#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS) -#define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS) -#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS) -#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS) -#define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP) -#define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS) -#define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f) +#define PORT_SPEED_MASK GENMASK(13, 10) +#define PORT_SPEED_FS 1 +#define PORT_SPEED_LS 2 +#define PORT_SPEED_HS 3 +#define PORT_SPEED_SS 4 +#define PORT_SPEED_SSP 5 -/* Bits 20:23 in the Slot Context are the speed for the device */ -#define SLOT_SPEED_FS (XDEV_FS << 10) -#define SLOT_SPEED_LS (XDEV_LS << 10) -#define SLOT_SPEED_HS (XDEV_HS << 10) -#define SLOT_SPEED_SS (XDEV_SS << 10) -#define SLOT_SPEED_SSP (XDEV_SSP << 10) /* Port Indicator Control */ #define PORT_LED_OFF (0 << 14) #define PORT_LED_AMBER (1 << 14) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a1fa188680f5..676f71d8305b 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2142,7 +2142,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) goto cleanup; } - if (DEV_SUPERSPEED_ANY(portsc)) { + if (FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS) { xhci_dbg(xhci, "remote wake SS port %d\n", port_id); /* Set a flag to say the port signaled remote wakeup, * so we can tell the difference between the end of @@ -2175,7 +2175,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) } if ((portsc & PORT_PLC) && - DEV_SUPERSPEED_ANY(portsc) && + FIELD_GET(PORT_SPEED_MASK, portsc) >= PORT_SPEED_SS && ((portsc & PORT_PLS_MASK) == XDEV_U0 || (portsc & PORT_PLS_MASK) == XDEV_U1 || (portsc & PORT_PLS_MASK) == XDEV_U2)) { diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index 1a14aea58b0b..b31c7b087fc7 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -2107,16 +2107,18 @@ static void tegra_xusb_restore_context(struct tegra_xusb *tegra) static enum usb_device_speed tegra_xhci_portsc_to_speed(struct tegra_xusb *tegra, u32 portsc) { - if (DEV_LOWSPEED(portsc)) + u32 port_speed = FIELD_GET(PORT_SPEED_MASK, portsc); + + if (port_speed == PORT_SPEED_LS) return USB_SPEED_LOW; - if (DEV_HIGHSPEED(portsc)) + if (port_speed == PORT_SPEED_HS) return USB_SPEED_HIGH; - if (DEV_FULLSPEED(portsc)) + if (port_speed == PORT_SPEED_FS) return USB_SPEED_FULL; - if (DEV_SUPERSPEED_ANY(portsc)) + if (port_speed >= PORT_SPEED_SS) return USB_SPEED_SUPER; return USB_SPEED_UNKNOWN; @@ -2255,7 +2257,8 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool is_auto_resume) continue; portsc = xhci_portsc_readl(xhci->usb2_rhub.ports[i]); tegra->lp0_utmi_pad_mask &= ~BIT(i); - if (((portsc & PORT_PLS_MASK) == XDEV_U3) || ((portsc & DEV_SPEED_MASK) == XDEV_FS)) + if (((portsc & PORT_PLS_MASK) == XDEV_U3) || + (FIELD_GET(PORT_SPEED_MASK, portsc) == PORT_SPEED_FS)) tegra->lp0_utmi_pad_mask |= BIT(i); } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index ec4bfeb4887c..61b132027963 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -12,6 +12,7 @@ #ifndef __LINUX_XHCI_HCD_H #define __LINUX_XHCI_HCD_H +#include #include #include #include @@ -362,9 +363,17 @@ struct xhci_slot_ctx { /* dev_info bitmasks */ /* Route String - 0:19 */ #define ROUTE_STRING_MASK (0xfffff) -/* Device speed - values defined by PORTSC Device Speed field - 20:23 */ +/* + * bits 23:20 - Device speed, values defined by PORTSC Speed field + * xHCI version 1.2 onwards these bits are Reserved + */ #define DEV_SPEED (0xf << 20) #define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20) +#define SLOT_SPEED_FS (PORT_SPEED_FS << 20) +#define SLOT_SPEED_LS (PORT_SPEED_LS << 20) +#define SLOT_SPEED_HS (PORT_SPEED_HS << 20) +#define SLOT_SPEED_SS (PORT_SPEED_SS << 20) +#define SLOT_SPEED_SSP (PORT_SPEED_SSP << 20) /* bit 24 reserved */ /* Is this LS/FS device connected through a HS hub? - bit 25 */ #define DEV_MTT BIT(25) @@ -2412,7 +2421,7 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc) if (portsc == ~(u32)0) return str; - ret += sprintf(str + ret, "Speed=%d ", DEV_PORT_SPEED(portsc)); + ret += sprintf(str + ret, "Speed=%lu ", FIELD_GET(PORT_SPEED_MASK, portsc)); ret += sprintf(str + ret, "Link=%s ", xhci_portsc_link_state_string(portsc)); /* RO/ROS: Read-only */ -- 2.50.1