From b7d2f4c7ddfbf4bdcd62534cdbf5eed79d04ebef Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:41:33 +1100 Subject: [PATCH 1/2] phy: apple: atc: Retry only a SuperSpeed port power-on that is still owed atcphy_mux_update_to() hands every USB-side failure to atcphy_usb3_port_retry(), also a failure to look up the root hub or to take the port down. When no port was held off, nothing is owed: the retry work only takes the controller, xHCI and root hub locks five times over about three seconds, which waits for any enumeration in progress, and if the lookup keeps failing it ends in "SuperSpeed port left off" for a port that was never off. The same happens for a port held off once its host or root hub is gone (-ENODEV, -ESHUTDOWN): no retry can bring that port back, and the next host powers the ports of its root hubs itself as it starts, where atcphy_usb3_set_mode() drops the debt. Schedule a retry only for a port that is still held off, and not for a host that is gone. What is left is the case the retry was added for: a power-on request to a running root hub that failed for want of memory, a failed runtime resume, or a controller or hub driver not bound yet. Nothing signals when such a request would succeed, so the bounded backoff stays, and each failed power-on is still logged as it happens. Document what is retried and why. Fixes: 5f5dc5faf13d ("phy: apple: atc: Retry a SuperSpeed port power-on that a mux update owes") Signed-off-by: Ryan Murray --- drivers/phy/apple/atc-test.c | 37 ++++++++++++++++++++++++++++++++++++ drivers/phy/apple/atc.c | 20 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..f06db3051ef24 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -507,6 +507,42 @@ static void atcphy_test_update_port_retry(struct kunit *test) KUNIT_EXPECT_FALSE(test, atcphy->usb3_port_off); } +/* Only a power-on still owed is retried, and not once the host is gone */ +static void atcphy_test_update_port_unowed(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_fixed_hub(test); + struct atcphy_test_steps *steps = atcphy_test_stub_steps(test); + + /* No port held off: a root hub not bound yet leaves nothing to retry */ + steps->pm_get_ret = -EAGAIN; + KUNIT_EXPECT_EQ(test, atcphy_test_update_dp(atcphy, TYPEC_DP_STATE_C), -EAGAIN); + KUNIT_EXPECT_STREQ(test, steps->log, "g"); + KUNIT_EXPECT_FALSE(test, atcphy_test_run_retry(atcphy)); + + /* A port held off behind a root hub not bound yet is retried */ + atcphy->usb3_port_off = true; + memset(steps->log, 0, sizeof(steps->log)); + KUNIT_EXPECT_EQ(test, atcphy_test_update_dp(atcphy, TYPEC_DP_STATE_D), 0); + KUNIT_EXPECT_TRUE(test, atcphy_test_run_retry(atcphy)); + KUNIT_EXPECT_STREQ(test, steps->log, "gg"); + + /* until the host is gone: the next host powers its port itself */ + steps->pm_get_ret = -ENODEV; + KUNIT_EXPECT_TRUE(test, atcphy_test_run_retry(atcphy)); + KUNIT_EXPECT_FALSE(test, atcphy_test_run_retry(atcphy)); + KUNIT_EXPECT_STREQ(test, steps->log, "ggg"); + KUNIT_EXPECT_TRUE(test, atcphy->usb3_port_off); + + /* A dead controller fails the power-on itself the same way */ + steps->pm_get_ret = 0; + steps->mode_port_on = true; + steps->port_on_ret = -ESHUTDOWN; + memset(steps->log, 0, sizeof(steps->log)); + KUNIT_EXPECT_EQ(test, atcphy_test_update_dp(atcphy, TYPEC_DP_STATE_D), 0); + KUNIT_EXPECT_STREQ(test, steps->log, "g0m1"); + KUNIT_EXPECT_FALSE(test, atcphy_test_run_retry(atcphy)); +} + /* A mode the PHY cannot run is turned down before USB3 goes down for it */ static void atcphy_test_update_unsupported(struct kunit *test) { @@ -1400,6 +1436,7 @@ static struct kunit_case atcphy_mux_test_cases[] = { KUNIT_CASE(atcphy_test_update_port_failure), KUNIT_CASE(atcphy_test_update_port_owed), KUNIT_CASE(atcphy_test_update_port_retry), + KUNIT_CASE(atcphy_test_update_port_unowed), KUNIT_CASE(atcphy_test_update_unsupported), KUNIT_CASE(atcphy_test_update_port_taken), KUNIT_CASE(atcphy_test_update_after_other), diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 34d3aa12b8f4c..08cfc53d284c0 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -5632,6 +5632,19 @@ static int atcphy_usb3_port_on(struct apple_atcphy *atcphy, struct atcphy_usb3_p * root hub, and only while the PIPE is on the USB3 backend of a running host. * The work is freezable, so it waits across system sleep, and is cancelled on * removal. + * + * What is retried is a failed request to a running root hub: out of memory + * for the control request, a runtime resume of the hub or its port that + * failed, or a controller or hub driver not bound yet (-EAGAIN). Nothing + * signals that such a request would now succeed, hence the backoff: 100, 200, + * 400, 800 and 1600 ms, about 3 s in all, then a warning. Each failed + * power-on is logged by atcphy_usb3_port_on() as it happens. + * + * Nothing is retried for a port that is not held off: there is no power-on + * to owe. Nor once the host or its root hub is gone or is not this PHY's + * (-ENODEV, -ESHUTDOWN): a new host powers the ports of its root hubs itself + * as it starts, and atcphy_usb3_set_mode() then drops the debt, so a retry + * could only end in the warning. */ #define ATCPHY_USB3_PORT_RETRIES 5 #define ATCPHY_USB3_PORT_RETRY_MS 100 @@ -5648,6 +5661,13 @@ static void atcphy_usb3_port_retry(struct apple_atcphy *atcphy, bool restart, in unsigned int retry = 0; scoped_guard(mutex, &atcphy->lock) { + if (!atcphy->usb3_port_off) + return; + if (err == -ENODEV || err == -ESHUTDOWN) { + dev_dbg(atcphy->dev, + "SuperSpeed port left to the next host: %d\n", err); + return; + } if (restart) atcphy->usb3_port_retries = ATCPHY_USB3_PORT_RETRIES; if (!atcphy->usb3_port_retries) { From 5ae30dc8a0ac7e95834547201220cb9d86577505 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:42:26 +1100 Subject: [PATCH 2/2] phy: apple: atc: Warn when the mode is not applied again after a sleep When atcphy_common_restore() cannot set a USB3 mode up again after a sleep in place, it falls back to USB2 and warns "USB2 for now", saying that the mux update after the wake tries the mode again. That second attempt is atcphy_sleep_ss_up(), which logs its result at debug level only: if it fails too, the port stays at USB2 until the next Type-C event, and the log has nothing beyond the first warning to say so. Warn when atcphy_sleep_ss_up() fails, and say in the fallback's comment and message which path applies the mode again, and that after a power cycle outside a sleep in place only the next Type-C event does. Why the set-up can fail after the sleep is not known yet; that is tracked in https://github.com/aurora-silicon/linux/issues/2314. The sleep path is Diljit Singh's, from commit d9b438c4ca41 ("arm64: apple: support coordinated suspend-to-RAM on T8140"). Signed-off-by: Ryan Murray --- drivers/phy/apple/atc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 08cfc53d284c0..df497e68f70ef 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -7279,8 +7279,15 @@ static int atcphy_common_restore(struct apple_atcphy *atcphy) ret = atcphy_configure(atcphy, mode); if (!ret || mode == APPLE_ATCPHY_MODE_USB2) return ret; - /* USB2 keeps the hub; the mux update after the wake then tries the mode again. */ - dev_warn(atcphy->dev, "mode %d not set up again after the sleep (%d): USB2 for now\n", + /* + * USB2 keeps the hub. After a sleep in place, atcphy_sleep_ss_up() + * applies the mode the mux last asked for again once the controller is + * back, and warns if that fails too; after a power cycle outside one, + * only the next Type-C event does. Why the set-up can fail here is not + * known yet, see https://github.com/aurora-silicon/linux/issues/2314. + */ + dev_warn(atcphy->dev, + "mode %d not set up again after the sleep (%d): USB2 until the mode is applied again\n", mode, ret); return atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB2); } @@ -7494,7 +7501,11 @@ static void atcphy_sleep_ss_up(struct apple_atcphy *atcphy) } } ret = atcphy_mux_update_to(atcphy, mode); - dev_dbg(atcphy->dev, "SuperSpeed side back after the sleep, mode %d: %d\n", mode, ret); + /* Nothing else applies the mode again before the next Type-C event. */ + if (ret) + dev_warn(atcphy->dev, "mode %d not applied again after the sleep: %d\n", mode, ret); + else + dev_dbg(atcphy->dev, "SuperSpeed side back after the sleep, mode %d\n", mode); } /* No lane or port change here: anything the sleep needs is done at noirq, in a few ms. */