Re: [PATCH 3/5] phy: tegra: xusb: Fix ordering issue when switching roles on USB2 ports

From: Diogo Ivo

Date: Tue Jan 13 2026 - 08:59:46 EST




On 1/13/26 11:44, Jon Hunter wrote:

On 13/01/2026 11:35, Jon Hunter wrote:

On 04/12/2025 21:27, Diogo Ivo wrote:
The current implementation of USB2 role switching on Tegra relies on
whichever the previous USB controller driver was using the PHY to first
"yield" it back to USB_ROLE_NONE before the next controller configures
it for the new role. However, no mechanism to guarantee this ordering
was implemented, and currently, in the general case, the configuration
functions tegra_xhci_id_work() and tegra_xudc_usb_role_sw_work() end up
running in the same order regardless of the transition being HOST- >DEVICE
or DEVICE->HOST, leading to one of these transitions ending up in a
non-working state due to the new configuration being clobbered by the
previous controller driver setting USB_ROLE_NONE after the fact.

Fix this by introducing a helper that waits for the USB2 port’s current
role to become USB_ROLE_NONE and add it in the configuration functions
above before setting the role to either USB_ROLE_HOST or
USB_ROLE_DEVICE. The specific parameters of the helper function are
choices that seem reasonable in my testing and have no other basis.

This was tested on a Tegra210 platform (Smaug). However, due to the similar
approach in Tegra186 it is likely that not only this problem exists there
but that this patch also fixes it.

Signed-off-by: Diogo Ivo <diogo.ivo@xxxxxxxxxxxxxxxxxx>
---
drivers/phy/tegra/xusb.c | 23 +++++++++++++++++++++++
drivers/usb/gadget/udc/tegra-xudc.c | 4 ++++
drivers/usb/host/xhci-tegra.c | 15 ++++++++++-----
include/linux/phy/tegra/xusb.h | 1 +
4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index c89df95aa6ca..e05c3f2d1421 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -740,6 +740,29 @@ static void tegra_xusb_parse_usb_role_default_mode(struct tegra_xusb_port *port)
}
}
+bool tegra_xusb_usb2_port_wait_role_none(struct tegra_xusb_padctl *padctl, int index)
+{
+ struct tegra_xusb_usb2_port *usb2 = tegra_xusb_find_usb2_port(padctl,
+ index);
+ int retries = 5;
+
+ if (!usb2) {
+ dev_err(&usb2->base.dev, "no port found for USB2 lane %u\n", index);
+ return false;
+ }
+
+ do {
+ if (usb2->role == USB_ROLE_NONE)
+ return true;
+
+ usleep_range(50, 60);
+ } while (retries--);
+
+ dev_err(&usb2->base.dev, "timed out waiting for USB_ROLE_NONE");
+
+ return false;
+}


This patch is causing the following build error today with -next ...

Sorry this is not in -next, I had just applied locally on top!

MODPOST Module.symvers
ERROR: modpost: "tegra_xusb_usb2_port_wait_role_none" [drivers/usb/ host/ xhci-tegra.ko] undefined!

The above function symbol needs to be exported.

You're right, thanks for catching this. I'll fix it in v2.


Nonetheless this needs to be fixed.

Jon