usb: xhci: rework xHCI Port macros
v3 cover usb: xhci: rework xHCI Port macros
This series cleans up the xHCI port register macros in xhci-port.h:
PORTSC, PORTPMSC, PORTLI and PORTHLPMC.
Many fields are defined as pre-shifted values, together with helper macros that mask, shift and compare them. This series defines each field with GENMASK()/BIT(), uses plain field values, and accesses the fields with FIELD_GET(), FIELD_PREP() and FIELD_MODIFY(). Register comments are aligned with the xHCI specification, and the PORTSC field macros are renamed to the spec abbreviations.
This is part 1 of the port register cleanup.
v3 changes:
* Dropped the second half of the original patch series. The remaining patches are relatively small reworks. The second half will be submitted separately.
* Updated all commit messages.
Niklas Neronin (12):
usb: xhci: use BIT() for single bit port register flags
usb: xhci: rework Port Speed macros
usb: xhci: rework Port Link State macros
usb: xhci: rework Port Indicator Control macro
usb: xhci: rework USB3 PORTPMSC macros
usb: xhci: rework USB2 PORTPMSC macros
usb: xhci: rework USB3 PORTLI macros
usb: xhci: rework USB2 PORTLI macros
usb: xhci: document USB3 PORTHLPMC register layout
usb: xhci: rework USB2 PORTHLPMC macros
usb: xhci: update port register bitfield comments for consistency
usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
drivers/usb/dwc3/host.c | 2 +- drivers/usb/early/xhci-dbc.c | 4 +- drivers/usb/host/xhci-debugfs.c | 23 +-- drivers/usb/host/xhci-hub.c | 225 ++++++++++++------------ drivers/usb/host/xhci-pci.c | 4 +- drivers/usb/host/xhci-port.h | 293 ++++++++++++++++++-------------- drivers/usb/host/xhci-ring.c | 25 ++- drivers/usb/host/xhci-tegra.c | 23 +-- drivers/usb/host/xhci.c | 24 +-- drivers/usb/host/xhci.h | 65 ++++--- 10 files changed, 370 insertions(+), 318 deletions(-)
Signature · 1 line
2.50.1
PATCH v3 1/12 usb: xhci: use BIT() for single bit port register flags
Replace open-coded (1 << n) shifts with BIT(n) for the single-bit flags in the PORTSC and PORTPMSC register definitions. This matches common kernel style and makes the bitfield definitions easier to read.
BIT_ULL() is not needed because all port registers are 32 bits wide.
Multi-bit field masks are left as they are, converting them to GENMASK() is done separately.
No functional change.
--- drivers/usb/host/xhci-port.h | 44 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/usb/host/xhci-port.h +23 -21
@@ -1,15 +1,17 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/bits.h> +/* PORTSC - Port Status and Control Register - port_status_base bitmasks */ /* true: device connected */ -#define PORT_CONNECT (1 << 0) +#define PORT_CONNECT BIT(0)/* true: port enabled */ -#define PORT_PE (1 << 1) +#define PORT_PE BIT(1)/* bit 2 reserved and zeroed */ /* true: port has an over-current condition */ -#define PORT_OC (1 << 3) +#define PORT_OC BIT(3)/* true: port reset signaling asserted */ -#define PORT_RESET (1 << 4) +#define PORT_RESET BIT(4)/* Port Link State - bits 5:8 * A read gives the current link PM state of the port, * a write with Link State Write Strobe set sets the link state.
@@ -30,7 +32,7 @@#define XDEV_RESUME (0xf << 5)/* true: port has power (see HCC_PPC) */ -#define PORT_POWER (1 << 9) +#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
@@ -66,21 +68,21 @@#define PORT_LED_GREEN (2 << 14)#define PORT_LED_MASK (3 << 14)/* Port Link State Write Strobe - set this when changing link state */ -#define PORT_LINK_STROBE (1 << 16) +#define PORT_LINK_STROBE BIT(16)/* true: connect status change */ -#define PORT_CSC (1 << 17) +#define PORT_CSC BIT(17)/* true: port enable change */ -#define PORT_PEC (1 << 18) +#define PORT_PEC BIT(18)/* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port * into an enabled state, and the device into the default state. A "warm" reset * also resets the link, forcing the device through the link training sequence. * SW can also look at the Port Reset register to see when warm reset is done. */ -#define PORT_WRC (1 << 19) +#define PORT_WRC BIT(19)/* true: over-current change */ -#define PORT_OCC (1 << 20) +#define PORT_OCC BIT(20)/* true: reset change - 1 to 0 transition of PORT_RESET */ -#define PORT_RC (1 << 21) +#define PORT_RC BIT(21)/* port link status change - set on some port link state transitions: * Transition Reason * ------------------------------------------------------------------------------
@@ -94,9 +96,9 @@* - U0 to disabled L1 entry error with USB 2.1 device * - Any state to inactive Error on USB 3.0 port */ -#define PORT_PLC (1 << 22) +#define PORT_PLC BIT(22)/* port configure error change - port failed to configure its link partner */ -#define PORT_CEC (1 << 23) +#define PORT_CEC BIT(23)#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ PORT_RC | PORT_PLC | PORT_CEC)
@@ -105,18 +107,18 @@* Sx state. Warm port reset should be perfomed to clear this bit and move port * to connected state. */ -#define PORT_CAS (1 << 24) +#define PORT_CAS BIT(24)/* wake on connect (enable) */ -#define PORT_WKCONN_E (1 << 25) +#define PORT_WKCONN_E BIT(25)/* wake on disconnect (enable) */ -#define PORT_WKDISC_E (1 << 26) +#define PORT_WKDISC_E BIT(26)/* wake on over-current (enable) */ -#define PORT_WKOC_E (1 << 27) +#define PORT_WKOC_E BIT(27)/* bits 28:29 reserved */ /* true: device is non-removable - for USB 3.0 roothub emulation */ -#define PORT_DEV_REMOVE (1 << 30) +#define PORT_DEV_REMOVE BIT(30)/* Initiate a warm port reset - complete when PORT_WRC is '1' */ -#define PORT_WR (1 << 31) +#define PORT_WR BIT(31)/* We mark duplicate entries with -1 */ #define DUPLICATE_ENTRY ((u8)(-1))
@@ -135,12 +137,12 @@/* USB2 Protocol PORTSPMSC */ #define PORT_L1S_MASK 7#define PORT_L1S_SUCCESS 1 -#define PORT_RWE (1 << 3) +#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 (1 << 16) +#define PORT_HLE BIT(16)#define PORT_TEST_MODE_SHIFT 28/* USB3 Protocol PORTLI Port Link Information */
Signature · 1 line
2.50.1
PATCH v3 2/12 usb: xhci: rework Port Speed macros
In reply to Niklas NeroninThe 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.
--- 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(-)
drivers/usb/host/xhci-debugfs.c +3 -3
@@ -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; }
drivers/usb/host/xhci-hub.c +5 -3
@@ -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 */
drivers/usb/host/xhci-port.h +19 -27
59 lines not on this page · raw message
drivers/usb/host/xhci-ring.c +2 -2
@@ -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 )) {
drivers/usb/host/xhci-tegra.c +8 -5
@@ -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); }
drivers/usb/host/xhci.h +11 -2
@@ -12,6 +12,7 @@#ifndef __LINUX_XHCI_HCD_H#define __LINUX_XHCI_HCD_H +#include <linux/bitfield.h> #include <linux/bits.h> #include <linux/usb.h> #include <linux/timer.h>
@@ -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 */
Signature · 1 line
2.50.1
PATCH v3 3/12 usb: xhci: rework Port Link State macros
In reply to Niklas NeroninThe PORTSC Port Link State (PLS) values are defined pre-shifted into bits 8:5, and callers mask and compare the raw register value.
Define PORT_PLS_MASK with GENMASK() and replace the pre-shifted XDEV_* link states with plain PLS_* field values. Use FIELD_GET() to read the field and FIELD_MODIFY() to update it. xhci_set_link_state() now takes an unshifted link state.
xhci_hub_report_usb3_link_state() reports the PLS value read from PORTSC, but overrides it in some cases with the pre-shifted USB_SS_PORT_LS_* values from ch11.h. Since the reported value comes from PORTSC, use the PLS_* values throughout, and write the result into 'wPortStatus' bits 8:5 with FIELD_MODIFY(). The USB 3 hub link state encoding and bit position are identical to the xHCI PLS field, so the reported status does not change.
For the same reason, compliance_mode_recovery() now compares against PLS_COMP_MODE instead of USB_SS_PORT_LS_COMP_MOD.
Update the Port Link State comment to note the default value, the LWS requirement for writes, and the reserved values 12-14.
No functional change.
--- drivers/usb/host/xhci-debugfs.c | 6 +- drivers/usb/host/xhci-hub.c | 113 ++++++++++++++++---------------- drivers/usb/host/xhci-pci.c | 2 +- drivers/usb/host/xhci-port.h | 37 ++++++----- drivers/usb/host/xhci-ring.c | 17 +++-- drivers/usb/host/xhci-tegra.c | 6 +- drivers/usb/host/xhci.c | 8 +-- drivers/usb/host/xhci.h | 28 ++++---- 8 files changed, 109 insertions(+), 108 deletions(-)
drivers/usb/host/xhci-debugfs.c +3 -3
@@ -361,13 +361,13 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,spin_lock_irqsave (&xhci->lock, flags);/* compliance mode can only be enabled on ports in RxDetect */ portsc =xhci_portsc_readl (port); -if ((portsc &PORT_PLS_MASK ) !=XDEV_RXDETECT ) { +if (FIELD_GET (PORT_PLS_MASK , portsc) !=PLS_RXDETECT ) {spin_unlock_irqrestore (&xhci->lock, flags);return -EPERM ; } portsc =xhci_port_state_to_neutral (portsc); - portsc &= ~PORT_PLS_MASK ; - portsc |=PORT_LINK_STROBE |XDEV_COMP_MODE ; +FIELD_MODIFY (PORT_PLS_MASK , &portsc,PLS_COMP_MODE ); + portsc |=PORT_LINK_STROBE ;xhci_portsc_writel (port, portsc);spin_unlock_irqrestore (&xhci->lock, flags); }else {
drivers/usb/host/xhci-hub.c +57 -56
325 lines not on this page · raw message
drivers/usb/host/xhci-pci.c +1 -1
@@ -922,7 +922,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup) port = &xhci->hw_ports[i]; portsc =xhci_portsc_readl (port); -if ((portsc &PORT_PLS_MASK ) !=XDEV_U3 ) +if (FIELD_GET (PORT_PLS_MASK , portsc) !=PLS_U3 )continue ;if (!port->slot_id || !xhci->devs[port->slot_id]) {
drivers/usb/host/xhci-port.h +19 -18
@@ -13,25 +13,26 @@#define PORT_OC BIT(3)/* true: port reset signaling asserted */ #define PORT_RESET BIT(4) -/* Port Link State - bits 5:8 -* A read gives the current link PM state of the port, -* a write with Link State Write Strobe set sets the link state. +/* +* bits 8:5 - Port Link State, by default '5'. +* Reading gives the current link PM state of the port. +* Writing sets the link state, Port Link State Write Strobe (LWS) must be set. */ -#define PORT_PLS_MASK (0xf << 5) -#define XDEV_U0 (0x0 << 5) -#define XDEV_U1 (0x1 << 5) -#define XDEV_U2 (0x2 << 5) -#define XDEV_U3 (0x3 << 5) -#define XDEV_DISABLED (0x4 << 5) -#define XDEV_RXDETECT (0x5 << 5) -#define XDEV_INACTIVE (0x6 << 5) -#define XDEV_POLLING (0x7 << 5) -#define XDEV_RECOVERY (0x8 << 5) -#define XDEV_HOT_RESET (0x9 << 5) -#define XDEV_COMP_MODE (0xa << 5) -#define XDEV_TEST_MODE (0xb << 5) -#define XDEV_RESUME (0xf << 5) - +#define PORT_PLS_MASK GENMASK(8, 5) +#define PLS_U0 0 +#define PLS_U1 1 +#define PLS_U2 2 +#define PLS_U3 3 +#define PLS_DISABLED 4 +#define PLS_RXDETECT 5 +#define PLS_INACTIVE 6 +#define PLS_POLLING 7 +#define PLS_RECOVERY 8 +#define PLS_HOT_RESET 9 +#define PLS_COMP_MODE 10 +#define PLS_TEST_MODE 11 +/* Values 12-14 are Reserved */ +#define PLS_RESUME 15/* true: port has power (see HCC_PPC) */ #define PORT_POWER BIT(9)/*
drivers/usb/host/xhci-ring.c +8 -9
@@ -2112,7 +2112,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) bus_state = &port->rhub->bus_state; hcd_portnum = port->hcd_portnum; portsc =xhci_portsc_readl (port); - pls = portsc &PORT_PLS_MASK ; + pls =FIELD_GET (PORT_PLS_MASK , portsc);xhci_dbg (xhci,"Port change event, %d-%d, id %d, portsc: 0x%x\n" , hcd->self.busnum, hcd_portnum +1 , port_id, portsc);
@@ -2129,11 +2129,12 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)* Link status is not relible while port is in reset. */ if (!(portsc &PORT_RESET )) { - port->link_inactive = (pls ==XDEV_INACTIVE ); + port->link_inactive = (pls ==PLS_INACTIVE ); port->connected = !!(portsc &PORT_CONNECT ); } -if ((portsc &PORT_PLC ) && (portsc &PORT_PLS_MASK ) ==XDEV_RESUME ) { + pls =FIELD_GET (PORT_PLS_MASK , portsc); +if ((portsc &PORT_PLC ) && pls ==PLS_RESUME ) {xhci_dbg (xhci,"port resume event for port %d\n" , port_id); cmd_reg =readl (&xhci->op_regs->command);
@@ -2151,7 +2152,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) bus_state->port_remote_wakeup |=1 << hcd_portnum;xhci_test_and_clear_bit (xhci, port,PORT_PLC );usb_hcd_start_port_resume (&hcd->self, hcd_portnum); -xhci_set_link_state (xhci, port,XDEV_U0 ); +xhci_set_link_state (xhci, port,PLS_U0 );/* Need to wait until the next link state change * indicates the device is actually in U0. */
@@ -2174,11 +2175,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) } } -if ((portsc &PORT_PLC ) && -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 )) { + pls =FIELD_GET (PORT_PLS_MASK , portsc); +if ((portsc &PORT_PLC ) && pls <=PLS_U2 && +FIELD_GET (PORT_SPEED_MASK , portsc) >=PORT_SPEED_SS ) {xhci_dbg (xhci,"resume SS port %d finished\n" , port_id);complete (&port->u3exit_done);/* We've just brought the device into U0/1/2 through either the
drivers/usb/host/xhci-tegra.c +3 -3
@@ -2036,7 +2036,7 @@ static bool xhci_hub_ports_suspended(struct xhci_hub *hub)if ((value &PORT_PE ) ==0 )continue ; -if ((value &PORT_PLS_MASK ) !=XDEV_U3 ) { +if (FIELD_GET (PORT_PLS_MASK , value) !=PLS_U3 ) {dev_info (dev,"%u-%u isn't suspended: %#010x\n" , hub->hcd->self.busnum, i +1 , value); status = false;
@@ -2257,7 +2257,7 @@ 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 ) || +if ((FIELD_GET (PORT_PLS_MASK , portsc) ==PLS_U3 ) || (FIELD_GET (PORT_SPEED_MASK , portsc) ==PORT_SPEED_FS )) tegra->lp0_utmi_pad_mask |=BIT (i); }
@@ -2836,7 +2836,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,if (!test_bit (i, &bus_state->resuming_ports))continue ; portsc =xhci_portsc_readl (ports[i]); -if ((portsc &PORT_PLS_MASK ) ==XDEV_RESUME ) +if (FIELD_GET (PORT_PLS_MASK , portsc) ==PLS_RESUME )tegra_phy_xusb_utmi_pad_power_on (tegra_xusb_get_phy (tegra,"usb2" , (int ) i)); }
drivers/usb/host/xhci.c +4 -4
@@ -377,7 +377,7 @@ static void compliance_mode_recovery(struct timer_list *t)for (i =0 ; i < rhub->num_ports; i++) { temp =xhci_portsc_readl (rhub->ports[i]); -if ((temp &PORT_PLS_MASK ) ==USB_SS_PORT_LS_COMP_MOD ) { +if (FIELD_GET (PORT_PLS_MASK , temp) ==PLS_COMP_MODE ) {/* * Compliance Mode Detected. Letting USB Core * handle the Warm Reset
@@ -929,7 +929,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)while (port_index--) { portsc =xhci_portsc_readl (ports[port_index]);if (portsc &PORT_CHANGE_MASK || - (portsc &PORT_PLS_MASK ) ==XDEV_RESUME ) +FIELD_GET (PORT_PLS_MASK , portsc) ==PLS_RESUME )return true; } port_index = xhci->usb3_rhub.num_ports;
@@ -937,7 +937,7 @@ static bool xhci_pending_portevent(struct xhci_hcd *xhci)while (port_index--) { portsc =xhci_portsc_readl (ports[port_index]);if (portsc & (PORT_CHANGE_MASK |PORT_CAS ) || - (portsc &PORT_PLS_MASK ) ==XDEV_RESUME ) +FIELD_GET (PORT_PLS_MASK , portsc) ==PLS_RESUME )return true; }return false;
@@ -4752,7 +4752,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,spin_unlock_irqrestore (&xhci->lock, flags);xhci_change_max_exit_latency (xhci, udev,0 );readl_poll_timeout (&ports[port_num]->port_reg->portsc, pm_val, - (pm_val &PORT_PLS_MASK ) ==XDEV_U0 , +FIELD_GET (PORT_PLS_MASK , pm_val) ==PLS_U0 ,100 ,10000 );return 0 ; }
drivers/usb/host/xhci.h +14 -14
@@ -2379,32 +2379,32 @@ static inline const char *xhci_decode_slot_context(char *str,static inline const char *xhci_portsc_link_state_string (u32 portsc) { -switch (portsc &PORT_PLS_MASK ) { -case XDEV_U0 : +switch (FIELD_GET (PORT_PLS_MASK , portsc)) { +case PLS_U0 :return "U0" ; -case XDEV_U1 : +case PLS_U1 :return "U1" ; -case XDEV_U2 : +case PLS_U2 :return "U2" ; -case XDEV_U3 : +case PLS_U3 :return "U3" ; -case XDEV_DISABLED : +case PLS_DISABLED :return "Disabled" ; -case XDEV_RXDETECT : +case PLS_RXDETECT :return "RxDetect" ; -case XDEV_INACTIVE : +case PLS_INACTIVE :return "Inactive" ; -case XDEV_POLLING : +case PLS_POLLING :return "Polling" ; -case XDEV_RECOVERY : +case PLS_RECOVERY :return "Recovery" ; -case XDEV_HOT_RESET : +case PLS_HOT_RESET :return "Hot Reset" ; -case XDEV_COMP_MODE : +case PLS_COMP_MODE :return "Compliance mode" ; -case XDEV_TEST_MODE : +case PLS_TEST_MODE :return "Test mode" ; -case XDEV_RESUME : +case PLS_RESUME :return "Resume" ;default :break ;
Signature · 1 line
2.50.1
PATCH v3 4/12 usb: xhci: rework Port Indicator Control macro
In reply to Niklas NeroninDefine the PORTSC Port Indicator Control field mask with GENMASK() and make the indicator values plain field values. Rename the macros after the xHCI specification abbreviation (PIC):
The macros currently have no users.
No functional change.
--- drivers/usb/host/xhci-port.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-port.h +5 -5
@@ -55,11 +55,11 @@#define PORT_SPEED_SS 4#define PORT_SPEED_SSP 5 -/* Port Indicator Control */ -#define PORT_LED_OFF (0 << 14) -#define PORT_LED_AMBER (1 << 14) -#define PORT_LED_GREEN (2 << 14) -#define PORT_LED_MASK (3 << 14) +/* bits 15:14 - Port Indicator Control */ +#define PORT_PIC_MASK GENMASK(15, 14) +#define PIC_OFF 0 +#define PIC_AMBER 1 +#define PIC_GREEN 2/* Port Link State Write Strobe - set this when changing link state */ #define PORT_LINK_STROBE BIT(16)/* true: connect status change */
Signature · 1 line
2.50.1
PATCH v3 5/12 usb: xhci: rework USB3 PORTPMSC macros
In reply to Niklas NeroninReplace the PORT_U1_TIMEOUT() and PORT_U2_TIMEOUT() helpers with GENMASK() based field masks, and use FIELD_MODIFY() to update the U1/U2 Timeout fields.
While at it, update the PORTPMSC comments to match xHCI 5.4.9.1:
- document the valid, reserved and infinite U1/U2 Timeout values
- add the Force Link PM Accept (FLA) bit and RsvdP bits 31:17
- drop the "Bits 24:31 for port testing" note, which applies to the USB2 PORTPMSC register, not the USB3 one
No functional change.
--- drivers/usb/host/xhci-hub.c | 6 ++---- drivers/usb/host/xhci-port.h | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/usb/host/xhci-hub.c +2 -4
@@ -1499,8 +1499,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, timeout = (wIndex &0xff00 ) >>8 ; portpmsc =readl (&port->port_reg->portpmsc); - portpmsc &= ~PORT_U1_TIMEOUT_MASK ; - portpmsc |=PORT_U1_TIMEOUT (timeout); +FIELD_MODIFY (PORT_U1_TIMEOUT_MASK , &portpmsc, timeout);writel (portpmsc, &port->port_reg->portpmsc);break ;case USB_PORT_FEAT_U2_TIMEOUT :
@@ -1509,8 +1508,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, timeout = (wIndex &0xff00 ) >>8 ; portpmsc =readl (&port->port_reg->portpmsc); - portpmsc &= ~PORT_U2_TIMEOUT_MASK ; - portpmsc |=PORT_U2_TIMEOUT (timeout); +FIELD_MODIFY (PORT_U2_TIMEOUT_MASK , &portpmsc, timeout);writel (portpmsc, &port->port_reg->portpmsc);break ;case USB_PORT_FEAT_TEST :
drivers/usb/host/xhci-port.h +12 -9
@@ -116,16 +116,19 @@/* We mark duplicate entries with -1 */ #define DUPLICATE_ENTRY ((u8)(-1)) -/* Port Power Management Status and Control - port_power_base bitmasks */ -/* Inactivity timer value for transitions into U1, in microseconds. -* Timeout can be up to 127us. 0xFF means an infinite timeout. +/* USB3 Port Power Management Status and Control (PORTPMSC) 5.4.9.1 */ +/* +* bits 7:0 - U1 Timeout, inactivity timer value for transitions into U1. +* Timeout can be 0 to 127us, in 1us increments and 0xff is infinite timeout. */ -#define PORT_U1_TIMEOUT (p) ((p) & 0xff) -#define PORT_U1_TIMEOUT_MASK 0xff -/* Inactivity timer value for transitions into U2 */ -#define PORT_U2_TIMEOUT (p) (((p) & 0xff) << 8) -#define PORT_U2_TIMEOUT_MASK (0xff << 8) -/* Bits 24:31 for port testing */ +#define PORT_U1_TIMEOUT_MASK GENMASK(7, 0) +/* +* bits 15:8 - U2 Timeout, inactivity timer value for transitions into U2. +* Timeout can be 0 to 65024us, in 256us increments and 0xff is infinite timeout. +*/ +#define PORT_U2_TIMEOUT_MASK GENMASK(15, 8) +/* bit 16 - Force Link PM Accept (FLA) */ +/* bits 31:17 - RsvdP */ /* USB2 Protocol PORTSPMSC */ #define PORT_L1S_MASK 7
Signature · 1 line
2.50.1
PATCH v3 6/12 usb: xhci: rework USB2 PORTPMSC macros
In reply to Niklas NeroninDefine 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'.
--- 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(-)
drivers/usb/host/xhci-hub.c +4 -4
@@ -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);
drivers/usb/host/xhci-port.h +18 -10
@@ -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)
drivers/usb/host/xhci.c +4 -3
@@ -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);
Signature · 1 line
2.50.1
PATCH v3 7/12 usb: xhci: rework USB3 PORTLI macros
In reply to Niklas NeroninReplace the PORT_LEC(), PORT_RX_LANES() and PORT_TX_LANES() helpers with GENMASK() based field masks, and use FIELD_GET() to extract the fields. Rename the lane count masks after the xHCI specification abbreviations (RLC, TLC).
Adjust the debugfs format specifiers to %lu to match the FIELD_GET() result type.
No functional change.
--- drivers/usb/host/xhci-debugfs.c | 6 ++++-- drivers/usb/host/xhci-hub.c | 4 ++-- drivers/usb/host/xhci-port.h | 12 ++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-)
drivers/usb/host/xhci-debugfs.c +4 -2
@@ -402,8 +402,10 @@ static int xhci_portli_show(struct seq_file *s, void *unused)/* PORTLI fields are valid if port is a USB3 or eUSB2V2 port */ if (port->rhub == &xhci->usb3_rhub) -seq_printf (s,"0x%08x LEC=%u RLC=%u TLC=%u\n" , portli, -PORT_LEC (portli),PORT_RX_LANES (portli),PORT_TX_LANES (portli)); +seq_printf (s,"0x%08x LEC=%lu RLC=%lu TLC=%lu\n" , portli, +FIELD_GET (PORT_LEC_MASK , portli), +FIELD_GET (PORT_RLC_MASK , portli), +FIELD_GET (PORT_TLC_MASK , portli));else if (xhci->hcc_params2 &HCC2_E2V2C )seq_printf (s,"0x%08x RDR=%u TDR=%u\n" , portli,PORTLI_RDR (portli),PORTLI_TDR (portli));
drivers/usb/host/xhci-hub.c +2 -2
@@ -1013,8 +1013,8 @@ static u32 xhci_get_ext_port_status(u32 portsc, u32 port_li) ext_stat |= speed_id;/* bits 3:0, RX speed id */ ext_stat |= speed_id <<4 ;/* bits 7:4, TX speed id */ - ext_stat |=PORT_RX_LANES (port_li) <<8 ;/* bits 11:8 Rx lane count */ - ext_stat |=PORT_TX_LANES (port_li) <<12 ;/* bits 15:12 Tx lane count */ + ext_stat |=FIELD_GET (PORT_RLC_MASK , port_li) <<8 ;/* bits 11:8 Rx lane count */ + ext_stat |=FIELD_GET (PORT_TLC_MASK , port_li) <<12 ;/* bits 15:12 Tx lane count */ return ext_stat; }
drivers/usb/host/xhci-port.h +8 -4
@@ -149,10 +149,14 @@/* 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) -#define PORT_RX_LANES (p) (((p) >> 16) & 0xf) -#define PORT_TX_LANES (p) (((p) >> 20) & 0xf) +/* USB3 Port Link Info Register (PORTLI) 5.4.10.1 */ +/* bits 15:0 - Link Error Count */ +#define PORT_LEC_MASK GENMASK(15, 0) +/* bits 19:16 - Rx Lane Count */ +#define PORT_RLC_MASK GENMASK(19, 16) +/* bits 23:20 - Tx Lane Count */ +#define PORT_TLC_MASK GENMASK(23, 20) +/* bits 31:24 - RsvdP */ /* eUSB2v2 protocol PORTLI Port Link information, RsvdP for normal USB2 */ #define PORTLI_RDR (p) ((p) & 0xf)
Signature · 1 line
2.50.1
PATCH v3 8/12 usb: xhci: rework USB2 PORTLI macros
In reply to Niklas NeroninReplace the PORTLI_RDR() and PORTLI_TDR() helpers with GENMASK() based field masks, and use FIELD_GET() to extract the Rx/Tx Data Rate fields.
The macros are renamed to PORT_RDR_MASK and PORT_TDR_MASK, matching the naming used for the USB3 PORTLI fields.
The RDR and TDR fields are only defined for eUSB2v2 ports, i.e. when the controller reports E2V2C=1; on normal USB2 ports the register is RsvdP.
No functional change.
--- drivers/usb/host/xhci-debugfs.c | 5 +++-- drivers/usb/host/xhci-port.h | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-debugfs.c +3 -2
@@ -407,8 +407,9 @@ static int xhci_portli_show(struct seq_file *s, void *unused)FIELD_GET (PORT_RLC_MASK , portli), FIELD_GET(PORT_TLC_MASK, portli)); else if (xhci->hcc_params2 & HCC2_E2V2C) - seq_printf(s, "0x%08x RDR=%u TDR=%u\n", portli, - PORTLI_RDR(portli), PORTLI_TDR(portli)); + seq_printf(s, "0x%08x RDR=%lu TDR=%lu\n", portli, +FIELD_GET (PORT_RDR_MASK , portli), + FIELD_GET(PORT_TDR_MASK, portli)); else seq_printf(s, "0x%08x RsvdP\n", portli);
drivers/usb/host/xhci-port.h +10 -3
@@ -158,9 +158,16 @@#define PORT_TLC_MASK GENMASK(23, 20)/* bits 31:24 - RsvdP */ -/* eUSB2v2 protocol PORTLI Port Link information, RsvdP for normal USB2 */ -#define PORTLI_RDR (p) ((p) & 0xf) -#define PORTLI_TDR (p) (((p) >> 4) & 0xf) +/* +* USB2 Port Link Info Register (PORTLI), xHCI 5.4.10.2 +* Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1), +* otherwise the whole register is RsvdP. +*/ +/* bits 3:0 - Rx Data Rate (RDR) */ +#define PORT_RDR_MASK GENMASK(3, 0) +/* bits 7:4 - Tx Data Rate (TDR) */ +#define PORT_TDR_MASK GENMASK(7, 4) +/* bits 31:8 - RsvdP */ /* USB2 Protocol PORTHLPMC */ #define PORT_HIRDM (p)((p) & 3)
Signature · 1 line
2.50.1
PATCH v3 9/12 usb: xhci: document USB3 PORTHLPMC register layout
In reply to Niklas NeroninAdd comments describing the USB3 Port Hardware LPM Control (PORTHLPMC) register fields as defined by the xHCI specification.
--- drivers/usb/host/xhci-port.h | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/host/xhci-port.h +4 -0
@@ -169,6 +169,10 @@#define PORT_TDR_MASK GENMASK(7, 4)/* bits 31:8 - RsvdP */ +/* USB3 Port Hardware LPM Control Register (PORTHLPMC) 5.4.11.1 */ +/* bits 15:0 - Link Soft Error Count, if LSECC=1 else RsvdP */ +/* bits 31:16 - RsvdP */ +/* USB2 Protocol PORTHLPMC */ #define PORT_HIRDM (p)((p) & 3)#define PORT_L1_TIMEOUT (p)(((p) & 0xff) << 2)
Signature · 1 line
2.50.1
PATCH v3 10/12 usb: xhci: rework USB2 PORTHLPMC macros
In reply to Niklas NeroninReplace the PORT_HIRDM(), PORT_L1_TIMEOUT() and PORT_BESLD() helpers with GENMASK() based field masks, and use FIELD_PREP() to build the PORTHLPMC value in xhci_calculate_usb2_hw_lpm_params().
While at it, document the PORTHLPMC register layout as described in xHCI 5.4.11.2.
No functional change.
--- drivers/usb/host/xhci-port.h | 19 +++++++++++++------ drivers/usb/host/xhci.c | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-port.h +13 -6
@@ -173,13 +173,20 @@/* bits 15:0 - Link Soft Error Count, if LSECC=1 else RsvdP */ /* bits 31:16 - RsvdP */ -/* USB2 Protocol PORTHLPMC */ -#define PORT_HIRDM (p)((p) & 3) -#define PORT_L1_TIMEOUT (p)(((p) & 0xff) << 2) -#define PORT_BESLD (p)(((p) & 0xf) << 10) - +/* USB2 Port Hardware LPM Control Register (PORTHLPMC), xHCI 5.4.11.2 */ +/* bits 1:0 - Host Initiated Resume Duration Mode (HIRDM) */ +#define PORT_HIRDM_MASK GENMASK(1, 0) +/* +* bits 9:2 - L1 Timeout, L1 inactivity timer value. +* 0x00: 128 us (default). +* 0x01-0xff: 256 us to 65280 us, in 256 us increments. +*/ +#define PORT_L1_TIMEOUT_MASK GENMASK(9, 2)/* use 512 microseconds as USB2 LPM L1 default timeout. */ -#define XHCI_L1_TIMEOUT 512 +#define XHCI_L1_TIMEOUT 512 +/* bits 13:10 - Best Effort Service Latency Deep (BESLD) */ +#define PORT_BESLD_MASK GENMASK(13, 10) +/* bits 31:14 - RsvdP */ /* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. * Safe to use with mixed HIRD and BESL systems (host and device) and is used
drivers/usb/host/xhci.c +2 -1
@@ -4665,7 +4665,8 @@ static int xhci_calculate_usb2_hw_lpm_params(struct usb_device *udev) hirdm =1 ; } -return PORT_BESLD (besld) |PORT_L1_TIMEOUT (l1) |PORT_HIRDM (hirdm); +return FIELD_PREP (PORT_BESLD_MASK , besld) |FIELD_PREP (PORT_L1_TIMEOUT_MASK , l1) | +FIELD_PREP (PORT_HIRDM_MASK , hirdm); } static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
Signature · 1 line
2.50.1
PATCH v3 11/12 usb: xhci: update port register bitfield comments for consistency
In reply to Niklas NeroninUpdate comments in xhci-port.h to improve readability and ensure a consistent format across all Port Register bit fields.
Each field comment now includes the bit range and the field name and its valid value range or meaning where applicable:
/* <bit range> - <Field name>, <notes> */
The updates are based on the xHCI specification, revision 1.2.
While at it:
- move PORT_CHANGE_MASK below the PORTSC bit definitions
- fix the XHCI_DEFAULT_BESL location reference in xhci.c, the macro is defined in xhci-port.h
No functional change.
--- drivers/usb/host/xhci-port.h | 65 ++++++++++++++++++++---------------- drivers/usb/host/xhci.c | 2 +- 2 files changed, 37 insertions(+), 30 deletions(-)
drivers/usb/host/xhci-port.h +36 -29
@@ -1,17 +1,21 @@/* SPDX-License-Identifier: GPL-2.0 */ +/* +* xHCI Host Controller USB Port Register Set +* xHCI Specification Section 5.4, Revision 1.2. +*/ #include <linux/bitfield.h> #include <linux/bits.h> -/* PORTSC - Port Status and Control Register - port_status_base bitmasks */ -/* true: device connected */ +/* Port Status and Control (PORTSC) 5.4.8 */ +/* bit 0 - Current Connect Status */ #define PORT_CONNECT BIT(0) -/* true: port enabled */ +/* bit 1 - Port Enabled/Disabled */ #define PORT_PE BIT(1) -/* bit 2 reserved and zeroed */ -/* true: port has an over-current condition */ +/* bit 2 - RsvdZ */ +/* bit 3 - Over-current Active */ #define PORT_OC BIT(3) -/* true: port reset signaling asserted */ +/* bit 4 - Port Reset */ #define PORT_RESET BIT(4)/* * bits 8:5 - Port Link State, by default '5'.
@@ -33,7 +37,7 @@#define PLS_TEST_MODE 11/* Values 12-14 are Reserved */ #define PLS_RESUME 15 -/* true: port has power (see HCC_PPC) */ +/* bit 9 - Port Power, see HCC_PPC */ #define PORT_POWER BIT(9)/* * bits 13:10 - Port Speed
@@ -60,23 +64,26 @@#define PIC_OFF 0#define PIC_AMBER 1#define PIC_GREEN 2 -/* Port Link State Write Strobe - set this when changing link state */ +/* bit 16 - Port Link State Write Strobe, set this when changing link state */ #define PORT_LINK_STROBE BIT(16) -/* true: connect status change */ +/* bit 17 - Connect Status Change */ #define PORT_CSC BIT(17) -/* true: port enable change */ +/* bit 18 - Port Enabled/Disabled Change */ #define PORT_PEC BIT(18) -/* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port +/* +* bit 19 - Warm Port Reset Change +* Warm reset for a USB 3.0 device is done. A "hot" reset puts the port * into an enabled state, and the device into the default state. A "warm" reset * also resets the link, forcing the device through the link training sequence. * SW can also look at the Port Reset register to see when warm reset is done. */ #define PORT_WRC BIT(19) -/* true: over-current change */ +/* bit 20 - Over-current Change */ #define PORT_OCC BIT(20) -/* true: reset change - 1 to 0 transition of PORT_RESET */ +/* bit 21 - Port Reset Change */ #define PORT_RC BIT(21) -/* port link status change - set on some port link state transitions: +/* +* bit 22 - Port Link State Change, set on some port link state transitions: * Transition Reason * ------------------------------------------------------------------------------ * - U3 to Resume Wakeup signaling from a device
@@ -90,28 +97,27 @@* - Any state to inactive Error on USB 3.0 port */ #define PORT_PLC BIT(22) -/* port configure error change - port failed to configure its link partner */ +/* bit 23 - Port Config Error Change, port failed to configure its link partner */ #define PORT_CEC BIT(23) -#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ - PORT_RC | PORT_PLC | PORT_CEC) - - -/* Cold Attach Status - xHC can set this bit to report device attached during -* Sx state. Warm port reset should be perfomed to clear this bit and move port -* to connected state. +/* +* bit 24 - Cold Attach Status +* xHC can set this bit to report device attached during Sx state. +* Warm port reset should be perfomed to clear this bit and move port to connected state. */ #define PORT_CAS BIT(24) -/* wake on connect (enable) */ +/* bit 25 - Wake on Connect Enable */ #define PORT_WKCONN_E BIT(25) -/* wake on disconnect (enable) */ +/* bit 26 - Wake on Disconnect Enable */ #define PORT_WKDISC_E BIT(26) -/* wake on over-current (enable) */ +/* bit 27 - Wake on Over-current Enable */ #define PORT_WKOC_E BIT(27) -/* bits 28:29 reserved */ -/* true: device is non-removable - for USB 3.0 roothub emulation */ +/* bits 29:28 - RsvdZ */ +/* bit 30 - Device Removable, for USB 3.0 roothub emulation */ #define PORT_DEV_REMOVE BIT(30) -/* Initiate a warm port reset - complete when PORT_WRC is '1' */ +/* bit 31 - Warm Port Reset, complete when PORT_WRC is '1' */ #define PORT_WR BIT(31) +#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ + PORT_RC | PORT_PLC | PORT_CEC)/* We mark duplicate entries with -1 */ #define DUPLICATE_ENTRY ((u8)(-1))
@@ -188,7 +194,8 @@#define PORT_BESLD_MASK GENMASK(13, 10)/* bits 31:14 - RsvdP */ -/* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. +/* +* Set default HIRD/BESL value to 4 (350/400us) for USB2 L1 LPM resume latency. * Safe to use with mixed HIRD and BESL systems (host and device) and is used * by other operating systems. *
drivers/usb/host/xhci.c +1 -1
@@ -4710,7 +4710,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,if (udev->usb2_hw_lpm_besl_capable) {/* if device doesn't have a preferred BESL value use a * default one which works with mixed HIRD and BESL -* systems. See XHCI_DEFAULT_BESL definition in xhci.h +* systems. See XHCI_DEFAULT_BESL definition in xhci-port.h */ field =le32_to_cpu (udev->bos->ext_cap->bmAttributes); if ((field & USB_BESL_SUPPORT) &&
Signature · 1 line
2.50.1
PATCH v3 12/12 usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
In reply to Niklas NeroninThe PORTSC field macros currently use two naming schemes. Some use the xHCI specification abbreviations (e.g. PORT_CSC, PORT_PEC, PORT_CAS) and others use driver-specific names (e.g. PORT_CONNECT, PORT_PE, PORT_OC). The driver-specific names don't follow a consistent pattern, which makes them harder to search for and to match against the specification.
Rename the remaining driver-specific macros to their xHCI specification (section 5.4.8) abbreviations:
PORT_CONNECT -> PORT_CCS PORT_PE -> PORT_PED PORT_OC -> PORT_OCA PORT_RESET -> PORT_PR PORT_POWER -> PORT_PP PORT_LINK_STROBE -> PORT_LWS PORT_RC -> PORT_PRC PORT_WKCONN_E -> PORT_WCE PORT_WKDISC_E -> PORT_WDE PORT_WKOC_E -> PORT_WOE PORT_DEV_REMOVE -> PORT_DR PORT_WR -> PORT_WPR
Each macro name is now the spec abbreviation, so the "(XXX)" suffixes in the bitfield comments are no longer needed and are dropped.
The dwc3 host glue (drivers/usb/dwc3/host.c) and the early xHCI debug capability driver (drivers/usb/early/xhci-dbc.c) include xhci-port.h, so they are updated to the new names as well.
The cdnsp gadget driver has its own copy of these definitions and is not affected.
Compared objdump -dr output before and after the change: the object code is identical.
No functional change intended.
--- drivers/usb/dwc3/host.c | 2 +- drivers/usb/early/xhci-dbc.c | 4 +- drivers/usb/host/xhci-debugfs.c | 2 +- drivers/usb/host/xhci-hub.c | 94 ++++++++++++++++----------------- drivers/usb/host/xhci-pci.c | 2 +- drivers/usb/host/xhci-port.h | 30 +++++------ drivers/usb/host/xhci-ring.c | 6 +-- drivers/usb/host/xhci-tegra.c | 6 +-- drivers/usb/host/xhci.c | 4 +- drivers/usb/host/xhci.h | 24 ++++----- 10 files changed, 87 insertions(+), 87 deletions(-)
drivers/usb/dwc3/host.c +1 -1
@@ -54,7 +54,7 @@ static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)for (i =1 ; i <= port_num; i++) { offset = op_regs_base +XHCI_PORTSC_BASE +0x10 * (i -1 ); reg =readl (xhci_regs + offset); - reg &= ~PORT_POWER ; + reg &= ~PORT_PP ;writel (reg, xhci_regs + offset); }
drivers/usb/early/xhci-dbc.c +2 -2
@@ -359,8 +359,8 @@ static void xdbc_do_reset_debug_port(u32 id, u32 count)for (i = id; i < (id + count); i++) { portsc = ops_reg +0x400 + i *0x10 ; val =readl (portsc); -if (!(val &PORT_CONNECT )) -writel (val |PORT_RESET , portsc); +if (!(val &PORT_CCS )) +writel (val |PORT_PR , portsc); } }
drivers/usb/host/xhci-debugfs.c +1 -1
@@ -367,7 +367,7 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf, } portsc =xhci_port_state_to_neutral (portsc);FIELD_MODIFY (PORT_PLS_MASK , &portsc,PLS_COMP_MODE ); - portsc |=PORT_LINK_STROBE ; + portsc |=PORT_LWS ;xhci_portsc_writel (port, portsc);spin_unlock_irqrestore (&xhci->lock, flags); }else {
drivers/usb/host/xhci-hub.c +47 -47
284 lines not on this page · raw message
drivers/usb/host/xhci-pci.c +1 -1
@@ -941,7 +941,7 @@ static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)xhci_dbg (xhci,"port %d-%d in U3 without wakeup, disable it\n" , port->rhub->hcd->self.busnum, port->hcd_portnum +1 ); portsc =xhci_port_state_to_neutral (portsc); -xhci_portsc_writel (port, portsc |PORT_PE ); +xhci_portsc_writel (port, portsc |PORT_PED ); }return 0 ;
drivers/usb/host/xhci-port.h +15 -15
@@ -9,14 +9,14 @@/* Port Status and Control (PORTSC) 5.4.8 */ /* bit 0 - Current Connect Status */ -#define PORT_CONNECT BIT(0) +#define PORT_CCS BIT(0)/* bit 1 - Port Enabled/Disabled */ -#define PORT_PE BIT(1) +#define PORT_PED BIT(1)/* bit 2 - RsvdZ */ /* bit 3 - Over-current Active */ -#define PORT_OC BIT(3) +#define PORT_OCA BIT(3)/* bit 4 - Port Reset */ -#define PORT_RESET BIT(4) +#define PORT_PR BIT(4)/* * bits 8:5 - Port Link State, by default '5'. * Reading gives the current link PM state of the port.
@@ -38,7 +38,7 @@/* Values 12-14 are Reserved */ #define PLS_RESUME 15/* bit 9 - Port Power, see HCC_PPC */ -#define PORT_POWER BIT(9) +#define PORT_PP BIT(9)/* * bits 13:10 - Port Speed * Values defined in xHCI specification 7.2.2.1.1:
@@ -65,7 +65,7 @@#define PIC_AMBER 1#define PIC_GREEN 2/* bit 16 - Port Link State Write Strobe, set this when changing link state */ -#define PORT_LINK_STROBE BIT(16) +#define PORT_LWS BIT(16)/* bit 17 - Connect Status Change */ #define PORT_CSC BIT(17)/* bit 18 - Port Enabled/Disabled Change */
@@ -81,7 +81,7 @@/* bit 20 - Over-current Change */ #define PORT_OCC BIT(20)/* bit 21 - Port Reset Change */ -#define PORT_RC BIT(21) +#define PORT_PRC BIT(21)/* * bit 22 - Port Link State Change, set on some port link state transitions: * Transition Reason
@@ -106,18 +106,18 @@*/ #define PORT_CAS BIT(24)/* bit 25 - Wake on Connect Enable */ -#define PORT_WKCONN_E BIT(25) +#define PORT_WCE BIT(25)/* bit 26 - Wake on Disconnect Enable */ -#define PORT_WKDISC_E BIT(26) +#define PORT_WDE BIT(26)/* bit 27 - Wake on Over-current Enable */ -#define PORT_WKOC_E BIT(27) +#define PORT_WOE BIT(27)/* bits 29:28 - RsvdZ */ /* bit 30 - Device Removable, for USB 3.0 roothub emulation */ -#define PORT_DEV_REMOVE BIT(30) +#define PORT_DR BIT(30)/* bit 31 - Warm Port Reset, complete when PORT_WRC is '1' */ -#define PORT_WR BIT(31) +#define PORT_WPR BIT(31)#define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ - PORT_RC | PORT_PLC | PORT_CEC) + PORT_PRC | PORT_PLC | PORT_CEC)/* We mark duplicate entries with -1 */ #define DUPLICATE_ENTRY ((u8)(-1))
@@ -169,9 +169,9 @@* Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1), * otherwise the whole register is RsvdP. */ -/* bits 3:0 - Rx Data Rate (RDR) */ +/* bits 3:0 - Rx Data Rate */ #define PORT_RDR_MASK GENMASK(3, 0) -/* bits 7:4 - Tx Data Rate (TDR) */ +/* bits 7:4 - Tx Data Rate */ #define PORT_TDR_MASK GENMASK(7, 4)/* bits 31:8 - RsvdP */
drivers/usb/host/xhci-ring.c +3 -3
@@ -2128,9 +2128,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)* Tag broken links to avoid retries while hub driver sorts it out. * Link status is not relible while port is in reset. */ -if (!(portsc &PORT_RESET )) { +if (!(portsc &PORT_PR )) { port->link_inactive = (pls ==PLS_INACTIVE ); - port->connected = !!(portsc &PORT_CONNECT ); + port->connected = !!(portsc &PORT_CCS ); } pls =FIELD_GET (PORT_PLS_MASK , portsc);
@@ -2213,7 +2213,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)if (hcd->speed <HCD_USB3 ) {xhci_test_and_clear_bit (xhci, port,PORT_PLC );if ((xhci->quirks &XHCI_RESET_PLL_ON_DISCONNECT ) && - (portsc &PORT_CSC ) && !(portsc &PORT_CONNECT )) + (portsc &PORT_CSC ) && !(portsc &PORT_CCS ))xhci_cavium_reset_phy_quirk (xhci); }
drivers/usb/host/xhci-tegra.c +3 -3
@@ -2033,7 +2033,7 @@ static bool xhci_hub_ports_suspended(struct xhci_hub *hub)for (i =0 ; i < hub->num_ports; i++) { value =xhci_portsc_readl (hub->ports[i]); -if ((value &PORT_PE ) ==0 ) +if ((value &PORT_PED ) ==0 )continue ;if (FIELD_GET (PORT_PLS_MASK , value) !=PLS_U3 ) {
@@ -2854,7 +2854,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,return -EPIPE ; ports = rhub->ports; portsc =xhci_portsc_readl (ports[port]); -if (portsc &PORT_CONNECT ) +if (portsc &PORT_CCS )tegra_phy_xusb_utmi_pad_power_on (phy); } }
@@ -2873,7 +2873,7 @@ static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value,if ((type_req == ClearPortFeature) && (value ==USB_PORT_FEAT_C_CONNECTION )) { ports = rhub->ports; portsc =xhci_portsc_readl (ports[port]); -if (!(portsc &PORT_CONNECT )) { +if (!(portsc &PORT_CCS )) {/* We don't suspend the PAD while HNP role swap happens on the OTG * port */
drivers/usb/host/xhci.c +2 -2
@@ -31,7 +31,7 @@#define DRIVER_AUTHOR "Sarah Sharp"#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" -#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) +#define PORT_WAKE_BITS (PORT_WOE | PORT_WDE | PORT_WCE)/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */ static int link_quirk;
@@ -896,7 +896,7 @@ static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, t2 &= ~PORT_WAKE_BITS ;/* Don't touch csc bit if connected or connect change is set */ -if (!(portsc & (PORT_CSC |PORT_CONNECT ))) +if (!(portsc & (PORT_CSC |PORT_CCS ))) t2 |=PORT_CSC ;if (t1 != t2) {
drivers/usb/host/xhci.h +12 -12
@@ -2425,37 +2425,37 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc) ret +=sprintf (str + ret,"Link=%s " ,xhci_portsc_link_state_string (portsc));/* RO/ROS: Read-only */ -if (portsc &PORT_CONNECT ) +if (portsc &PORT_CCS ) ret +=sprintf (str + ret,"CCS " ); -if (portsc &PORT_OC ) +if (portsc &PORT_OCA ) ret +=sprintf (str + ret,"OCA " );/* No set for USB2 ports */ if (portsc &PORT_CAS ) ret +=sprintf (str + ret,"CAS " ); -if (portsc &PORT_DEV_REMOVE ) +if (portsc &PORT_DR ) ret +=sprintf (str + ret,"DR " );/* RWS; writing 1 sets the bit, writing 0 clears the bit. */ -if (portsc &PORT_POWER ) +if (portsc &PORT_PP ) ret +=sprintf (str + ret,"PP " ); -if (portsc &PORT_WKCONN_E ) +if (portsc &PORT_WCE ) ret +=sprintf (str + ret,"WCE " ); -if (portsc &PORT_WKDISC_E ) +if (portsc &PORT_WDE ) ret +=sprintf (str + ret,"WDE " ); -if (portsc &PORT_WKOC_E ) +if (portsc &PORT_WOE ) ret +=sprintf (str + ret,"WOE " );/* RW; writing 1 sets the bit, writing 0 clears the bit */ -if (portsc &PORT_LINK_STROBE ) +if (portsc &PORT_LWS ) ret +=sprintf (str + ret,"LWS " );/* LWS 0 write is ignored */ /* RW1S; writing 1 sets the bit, writing 0 has no effect */ -if (portsc &PORT_RESET ) +if (portsc &PORT_PR ) ret +=sprintf (str + ret,"PR " ); -if (portsc &PORT_WR ) +if (portsc &PORT_WPR ) ret +=sprintf (str + ret,"WPR " );/* RsvdZ for USB2 ports */ /* RW1CS; writing 1 clears the bit, writing 0 has no effect. */ -if (portsc &PORT_PE ) +if (portsc &PORT_PED ) ret +=sprintf (str + ret,"PED " );if (portsc &PORT_CSC ) ret +=sprintf (str + ret,"CSC " );
@@ -2465,7 +2465,7 @@ static inline const char *xhci_decode_portsc(char *str, u32 portsc) ret +=sprintf (str + ret,"WRC " );/* RsvdZ for USB2 ports */ if (portsc &PORT_OCC ) ret +=sprintf (str + ret,"OCC " ); -if (portsc &PORT_RC ) +if (portsc &PORT_PRC ) ret +=sprintf (str + ret,"PRC " );if (portsc &PORT_PLC ) ret +=sprintf (str + ret,"PLC " );
Signature · 1 line
2.50.1
[email protected]
AI reviewRe: [PATCH v3 05/12] usb: xhci: rework USB3 PORTPMSC macros
In reply to Niklas NeroninThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] usb: xhci: PORTPMSC comments omit reserved values claimed in commit message --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] usb: xhci: PORTPMSC comments omit reserved values claimed in commit message
--
commit 566b043ef88e37f2c0ec0cdfe002e8e9bd68833e
Author: Niklas Neronin <[email protected]>
usb: xhci: rework USB3 PORTPMSC macros
This commit replaces PORT_U1_TIMEOUT() and PORT_U2_TIMEOUT() with GENMASK() masks and FIELD_MODIFY(), and updates the USB3 PORTPMSC register comments in xhci-port.h.
Quoted 1 line
- document the valid, reserved and infinite U1/U2 Timeout values
[ ... ]
Quoted 18 lines
drivers/usb/host/xhci-port.h +7
-3@@ -116,16 +116,19 @@/* We mark duplicate entries with -1 */ #define DUPLICATE_ENTRY ((u8)(-1)) -/* Port Power Management Status and Control - port_power_base bitmasks */ -/* Inactivity timer value for transitions into U1, in microseconds. -* Timeout can be up to 127us. 0xFF means an infinite timeout. +/* USB3 Port Power Management Status and Control (PORTPMSC) 5.4.9.1 */ +/* +* bits 7:0 - U1 Timeout, inactivity timer value for transitions into U1. +* Timeout can be 0 to 127us, in 1us increments and 0xff is infinite timeout. +*/ +#define PORT_U1_TIMEOUT_MASK GENMASK(7, 0) +/*
drivers/usb/host/xhci-port.h line 129
Quoted 10 lines
drivers/usb/host/xhci-port.h +3
-6+* bits 15:8 - U2 Timeout, inactivity timer value for transitions into U2. +* Timeout can be 0 to 65024us, in 256us increments and 0xff is infinite timeout. */ -#define PORT_U1_TIMEOUT (p) ((p) & 0xff) -#define PORT_U1_TIMEOUT_MASK 0xff -/* Inactivity timer value for transitions into U2 */ -#define PORT_U2_TIMEOUT (p) (((p) & 0xff) << 8) -#define PORT_U2_TIMEOUT_MASK (0xff << 8) -/* Bits 24:31 for port testing */ +#define PORT_U2_TIMEOUT_MASK GENMASK(15, 8)
[Severity: Low]
The commit message says the comments document the reserved U1/U2 Timeout values, but neither comment mentions reserved values. In xHCI 5.4.9.1, values 0x80 to 0xfe are reserved for U1 Timeout, while U2 Timeout has no reserved encodings since 0x00 through 0xfe cover 0 to 65024us.
Should the U1 Timeout comment note that 0x80 to 0xfe are reserved, or should the commit message be updated to match the comments?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v3 12/12] usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
In reply to Niklas NeroninThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] usb: xhci: leftover (HIRDM) and (BESLD) comment suffixes in xhci-port.h --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] usb: xhci: leftover (HIRDM) and (BESLD) comment suffixes in xhci-port.h
--
commit ede0c330cbe2f7e6299b961bb18175f88934c294
Author: Niklas Neronin <[email protected]>
usb: xhci: rename PORTSC field macros to xHCI spec abbreviations
This commit renames the remaining driver-specific PORTSC field macros in xhci-port.h and their users to their xHCI specification abbreviations, and drops the now-redundant abbreviation suffixes from bitfield comments.
Quoted 4 lines
drivers/usb/host/xhci-port.h +0
-0
[ ... ]
drivers/usb/host/xhci-port.h line 176
Quoted 11 lines
drivers/usb/host/xhci-port.h +2
-2@@ -169,9 +169,9 @@* Fields are only defined for eUSB2v2 ports (HCC2_E2V2C = 1), * otherwise the whole register is RsvdP. */ -/* bits 3:0 - Rx Data Rate (RDR) */ +/* bits 3:0 - Rx Data Rate */ #define PORT_RDR_MASK GENMASK(3, 0) -/* bits 7:4 - Tx Data Rate (TDR) */ +/* bits 7:4 - Tx Data Rate */ #define PORT_TDR_MASK GENMASK(7, 4)/* bits 31:8 - RsvdP */
[Severity: Low]
Should the (HIRDM) and (BESLD) suffixes on the PORT_HIRDM_MASK and PORT_BESLD_MASK comments right below in the USB2 PORTHLPMC section also be dropped? Their macro names already use those spec abbreviations, so keeping them leaves the comment cleanup stated in the commit message incomplete.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
[email protected]
AI reviewRe: [PATCH v3 03/12] usb: xhci: rework Port Link State macros
In reply to Niklas NeroninThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] usb: xhci: redundant FIELD_GET(PORT_PLS_MASK) calls in handle_port_status() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] usb: xhci: redundant FIELD_GET(PORT_PLS_MASK) calls in handle_port_status()
--
commit ee9d70e142f86a51d9ccfe785b68150e454c910c
Author: Niklas Neronin <[email protected]>
usb: xhci: rework Port Link State macros
This commit replaces the pre-shifted XDEV_* Port Link State macros with unshifted PLS_* values defined against GENMASK(8, 5), and updates callers to use FIELD_GET() and FIELD_MODIFY().
Quoted 28 lines
drivers/usb/host/xhci-ring.c +4
-3@@ -2112,7 +2112,7 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) bus_state = &port->rhub->bus_state; hcd_portnum = port->hcd_portnum; portsc =xhci_portsc_readl (port); - pls = portsc &PORT_PLS_MASK ; + pls =FIELD_GET (PORT_PLS_MASK , portsc);xhci_dbg (xhci,"Port change event, %d-%d, id %d, portsc: 0x%x\n" , hcd->self.busnum, hcd_portnum +1 , port_id, portsc);@@ -2129,11 +2129,12 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)* Link status is not relible while port is in reset. */ if (!(portsc &PORT_RESET )) { - port->link_inactive = (pls ==XDEV_INACTIVE ); + port->link_inactive = (pls ==PLS_INACTIVE ); port->connected = !!(portsc &PORT_CONNECT ); } -if ((portsc &PORT_PLC ) && (portsc &PORT_PLS_MASK ) ==XDEV_RESUME ) { + pls =FIELD_GET (PORT_PLS_MASK , portsc); +if ((portsc &PORT_PLC ) && pls ==PLS_RESUME ) {xhci_dbg (xhci,"port resume event for port %d\n" , port_id); cmd_reg =readl (&xhci->op_regs->command);
[ ... ]
drivers/usb/host/xhci-ring.c static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) · line 2180
Quoted 12 lines
drivers/usb/host/xhci-ring.c +3
-5@@ -2174,11 +2175,9 @@ static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) } } -if ((portsc &PORT_PLC ) && -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 )) { + pls =FIELD_GET (PORT_PLS_MASK , portsc); +if ((portsc &PORT_PLC ) && pls <=PLS_U2 && +FIELD_GET (PORT_SPEED_MASK , portsc) >=PORT_SPEED_SS ) {
[Severity: Low]
Are these two extra pls = FIELD_GET(PORT_PLS_MASK, portsc) assignments needed? handle_port_status() already extracts pls right after reading portsc, and neither portsc nor pls is modified afterwards, so repeating the extraction can mislead readers into thinking portsc was re-read from hardware.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewSashiko has finished reviewing this 12-patch series:
Sashiko has finished reviewing this 12-patch series:
- Patches 1, 2, 4, and 6-11: no issues found.
- Patch 3 ("usb: xhci: rework Port Link State macros"): 1 potential issue (1 Low)
- Patch 5 ("usb: xhci: rework USB3 PORTPMSC macros"): 1 potential issue (1 Low)
- Patch 12 ("usb: xhci: rename PORTSC field macros to xHCI spec a..."):
1 potential issue (1 Low)
Detailed reviews have been sent as separate replies to patches 3, 5, and 12.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]