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=1796309009; b=Lq+x+5DxnL7LurKf+gmWgXBfZ1tkgOMVd5H0VHT0nFPpEphQ6wGYkc6ER7A4gbQ+hcZY +ASKrRWiNUvb8Knc3YVlcb59sGoJaVzJh9YtRQWBt3X3iwTqbeaBt3imxt+OgjlpQVJLz fp/bcUc5QD+rfsiqElnxrgEduWMY/QgTJKlhkzev7PgPKh9o/DUTKzh3bu/PtV1Q5oVOe v7WHvNY7NckzOI5HTsUtlSkl+fK8+sLJ7YUFy1lY2Mlyyjyxb3nUq3s3hnLUnFDIOZ1qQ cBBiam2wGFWTygL0LoQNxKmP0O6OSgbryxAA7hDU9tKpcWvxd/hqVI88JEpPB375eog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309009; 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=9QYRlXhDQWPHnfyn7LPUSVwyjVhncbfYnBJQUxbznk8=; b=PVY88s8xK1FUIutoABSDbC5CTVBuya4sqAw0H+k7K8NBF7U6qV+lcNhc7AW16b2k8A3o +gxJEZumJ+piKeBCL2n2SPFzbFGSrC4ZYn7hNKrE6cV4TqPVtdc9nr5kx9DReMt/DJ15Z yEOlQ+X9Xin56m+QMp+G8uSyQwZdYLv+aZZbz2UN7sQO2+nBIPpYGrYkW8WdNPcId6ZuP FmQofc+5SA7hbBefaOqE+6xEvejDedItupTWAmAEzZtXfuVJqt6vqZQ4oAelpPXmNz2Pb LYm47x00/sz2uSLYhYzkZHrPxoszKtGTPF8QtKKq6CNVDTYmTl0Y66+z3Va5H4oWtBA== 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="KKy1h/eX"; 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 424B4606A684 for ; Thu, 3 Dec 2026 14:43:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 424B4606A684 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=KKy1h/eX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796309009; x=1827845009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9QYRlXhDQWPHnfyn7LPUSVwyjVhncbfYnBJQUxbznk8=; b=KKy1h/eXEScrCylOrca7GDezlGT5svlN70kIlTov1JSw3oP5IzDfM5ND 52tZlZmS2m3cZcXSFVWGlbdXXVpWURXF+BMx9ILp7jbeLdB7OEo3BNEjU 3U2G7CobTyxAWBX87MKSB4jpUr+taY6Lb0oVzyk11oL/fGOCyEMfwAWr9 UC7J+NhghHLDH28ImI7CgBsnmcflCMO/9XOt6OaeNPcp/xUKkGLt1HhFM s+82R42SmSc6rVNhydxRg+EP1WKc4Saq65jGouYW5P3U7wrCiLLAsmAPR HWaJvV1JuUodio3tXfEPMEpFG2wcjK+NZCK9WjWOqkmzfNTwZ/r+lomWI w==; X-CSE-ConnectionGUID: WN7h479UTPCwMTAimosrtA== X-CSE-MsgGUID: FOtnRaBEQReMtBFLQxirsA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5182622" X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="5182622" 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:29 -0800 X-CSE-ConnectionGUID: fUefnNRoSWqMH5OgqFyiwA== X-CSE-MsgGUID: Ezzgbgq8T9G51jEHji3Vqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="14024138" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa001.jf.intel.com with ESMTP; 03 Dec 2026 06:43:28 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id 2DE0998; Thu, 03 Dec 2026 15:43:27 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH v3 06/12] usb: xhci: rework USB2 PORTPMSC macros Date: Thu, 3 Dec 2026 15:42:38 +0100 Message-ID: <20261203144244.1680587-7-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 Define macros to describe only the bit masks, and use the standard FIELD_* helpers to extract, set, and update field values. By consolidating macro usage and eliminating custom helpers, the code becomes simpler and easier to follow. The use of standard bitfield macros improves readability and enforces consistent register field handling. Rename bits 7:4 mask from the legacy HIRD definition to BESL, as per xHCI specification. Raname xhci_port_set_test_mode() local variabel 'temp' to 'portpmsc'. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-hub.c | 8 ++++---- drivers/usb/host/xhci-port.h | 28 ++++++++++++++++++---------- drivers/usb/host/xhci.c | 7 ++++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 58d18a1c3064..2b0522efc29a 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -678,14 +678,14 @@ static void xhci_set_port_power(struct xhci_hcd *xhci, struct xhci_port *port, static void xhci_port_set_test_mode(struct xhci_hcd *xhci, u16 test_mode, int portnum) { - u32 temp; + u32 portpmsc; struct xhci_port *port; /* xhci only supports test mode for usb2 ports */ port = xhci->usb2_rhub.ports[portnum]; - temp = readl(&port->port_reg->portpmsc); - temp |= test_mode << PORT_TEST_MODE_SHIFT; - writel(temp, &port->port_reg->portpmsc); + portpmsc = readl(&port->port_reg->portpmsc); + FIELD_MODIFY(PORT_TEST_MODE_MASK, &portpmsc, test_mode); + writel(portpmsc, &port->port_reg->portpmsc); xhci->test_mode = test_mode; if (test_mode == USB_TEST_FORCE_ENABLE) xhci_start(xhci); diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h index fc87d4cacfbe..d6af7b878586 100644 --- a/drivers/usb/host/xhci-port.h +++ b/drivers/usb/host/xhci-port.h @@ -130,16 +130,24 @@ /* bit 16 - Force Link PM Accept (FLA) */ /* bits 31:17 - RsvdP */ -/* USB2 Protocol PORTSPMSC */ -#define PORT_L1S_MASK 7 -#define PORT_L1S_SUCCESS 1 -#define PORT_RWE BIT(3) -#define PORT_HIRD(p) (((p) & 0xf) << 4) -#define PORT_HIRD_MASK (0xf << 4) -#define PORT_L1DS_MASK (0xff << 8) -#define PORT_L1DS(p) (((p) & 0xff) << 8) -#define PORT_HLE BIT(16) -#define PORT_TEST_MODE_SHIFT 28 +/* USB2 Port Power Management Status and Control (PORTPMSC) 5.4.9.2 */ +/* bits 2:0 - L1 Status */ +#define PORT_L1S_MASK GENMASK(2, 0) +/* bit 3 - Remote Wake Enable */ +#define PORT_RWE BIT(3) +/* + * bits 7:4 - Best Effort Service Latency + * Some host controllers may implement the pre-2011 USB 2.0 LPM definition, + * where this field is interpreted as Host Initiated Resume Duration (HIRD). + */ +#define PORT_BESL_MASK GENMASK(7, 4) +/* bits 15:8 - L1 Device Slot */ +#define PORT_L1DS_MASK GENMASK(15, 8) +/* bit 16 - Hardware LPM Enable */ +#define PORT_HLE BIT(16) +/* bits 27:17 - RsvdP */ +/* bits 31:28 - Port Test Control */ +#define PORT_TEST_MODE_MASK GENMASK(31, 28) /* USB3 Protocol PORTLI Port Link Information */ #define PORT_LEC(p) ((p) & 0xffff) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 884a3214484c..7a42361608f6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4735,8 +4735,9 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, hird = xhci_calculate_hird_besl(xhci, udev); } - pm_val &= ~PORT_HIRD_MASK; - pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); + FIELD_MODIFY(PORT_BESL_MASK, &pm_val, hird); + FIELD_MODIFY(PORT_L1DS_MASK, &pm_val, udev->slot_id); + pm_val |= PORT_RWE; writel(pm_val, &port_reg->portpmsc); pm_val = readl(&port_reg->portpmsc); pm_val |= PORT_HLE; @@ -4744,7 +4745,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, /* flush write */ readl(&port_reg->portpmsc); } else { - pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK); + pm_val &= ~(PORT_HLE | PORT_RWE | PORT_BESL_MASK | PORT_L1DS_MASK); writel(pm_val, &port_reg->portpmsc); /* flush write */ readl(&port_reg->portpmsc); -- 2.50.1