From 45de996d6f0ae705901e97d552bdb4f5f9161292 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:11:29 +1100 Subject: [PATCH 1/3] phy: apple: atc: hold one PIPE lock request for a live USB3 handoff Before a lane change, a live T8103-generation USB3 PIPE is parked on the dummy backend under the PIPE handler's lock. The lock was asked for up to ten times: each request polled for 1 ms, dropped, then usleep_range(5000, 10000) before the next. The ACK is the controller's own signal that it has let go of the PIPE. Dropping the request and asking again adds nothing it waits for. Ask once, keep the request up, and poll the ACK for 100 ms, the span the ten tries covered. Poll in 100 us steps over a window that long. A controller held in reset or clamped (PIPEHANDLER_AON_GEN) clocks no ACK. Refuse the lock at once then, instead of waiting out the window. Update the host harness (tools/asahi/atc-usb3-tests.py): the retry cases become single-request cases, a held controller is never asked, and the mutations follow the new body. 39 cases pass and every mutation is killed. The handoff is Chris Kearney's, after milijan's AsahiLinux/linux#503. Fixes: 0287dbe78b82 ("phy: apple: make legacy USB3 handoff completion retryable") Signed-off-by: Ryan Murray --- drivers/phy/apple/atc.c | 40 ++++++++++++++++------- tools/asahi/atc-usb3-tests.py | 61 +++++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 34d3aa12b8f4c..3ef86dbbada6b 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -536,6 +536,13 @@ enum atcphy_lane_mode { #define PIPEHANDLER_NATIVE_POWER_DOWN GENMASK(3, 0) #define PIPEHANDLER_LOCK_ACK_TIMEOUT_US 1000 +/* + * A live USB3 PIPE: the controller ACKs the lock only once it has let go of + * the PIPE, which a running link can take several ms to do. The old handoff + * asked up to ten times, 1 ms each with 5-10 ms between; this window covers + * the same span with the request held. + */ +#define PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US (100 * USEC_PER_MSEC) /* USB2 PHY regs */ #define USB2PHY_USBCTL 0x00 @@ -1366,8 +1373,10 @@ static int atcphy_pipehandler_lock_timeout(struct apple_atcphy *atcphy, u32 time set32(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ, PIPEHANDLER_LOCK_EN); } + /* Step coarser over a long window: the ACK is the only signal to wait for. */ ret = readl_poll_timeout(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_ACK, reg, - reg & PIPEHANDLER_LOCK_EN, 10, timeout); + reg & PIPEHANDLER_LOCK_EN, + timeout > 10 * USEC_PER_MSEC ? 100 : 10, timeout); /* * A controller that still drives the PIPE can take longer than this to * let go. What that means is the caller's to decide: a best-effort lock @@ -1394,20 +1403,27 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy) 6000 : PIPEHANDLER_LOCK_ACK_TIMEOUT_US); } -/* Retry only a live legacy PIPE: USB4 and stopped parking cannot clock the ACK. */ +/* + * Lock a live USB3 PIPE: the running controller clocks the ACK, and gives it + * once it has let go of the PIPE. One request, held, and the ACK polled for the + * whole live window, rather than dropping and asking again. USB4 and stopped + * parking cannot clock the ACK and do not come here. + */ static int atcphy_pipehandler_lock_live(struct apple_atcphy *atcphy) { - unsigned int attempts = atcphy->t8103_usb3_workaround ? 10 : 1; - int ret; + u32 aon; - for (unsigned int attempt = 0; attempt < attempts; attempt++) { - ret = atcphy_pipehandler_lock(atcphy); - if (!ret) - return 0; - if (attempt + 1 < attempts) - usleep_range(5000, 10000); - } - return ret; + /* The tests stand in for the controller that acknowledges the lock. */ + if (IS_ENABLED(CONFIG_PHY_APPLE_ATC_KUNIT_TEST)) + KUNIT_STATIC_STUB_REDIRECT(atcphy_pipehandler_lock_live, atcphy); + + /* A controller held in reset or clamped clocks nothing: no ACK can come. */ + aon = readl(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN); + if (!(aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) || + (aon & PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN)) + return -ETIMEDOUT; + + return atcphy_pipehandler_lock_timeout(atcphy, PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US); } static int atcphy_pipehandler_unlock(struct apple_atcphy *atcphy) diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 3a7955197c9f9..b56c39dd2cd54 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -58,6 +58,7 @@ def block(source, marker): typedef uint32_t u32; #define BIT(n) (1U << (n)) #define GENMASK(h,l) ((UINT32_MAX >> (31-(h))) & (UINT32_MAX << (l))) +#define USEC_PER_MSEC 1000U /* Warnings and errors the driver reports; debug output is not counted. */ static unsigned reports; #define dev_warn(...) ((void)reports++) @@ -118,6 +119,7 @@ def block(source, marker): static unsigned dummy_muxes, pending_seen_at_unlock; static unsigned usb2_power_off_calls; static unsigned ack_on; +static unsigned last_timeout; static int check_ret, bist_ret, unlock_ret, configure_ret; static bool concurrent_override_change; static bool model_t8132_off; @@ -144,8 +146,10 @@ def block(source, marker): return ack_on && polls >= ack_on ? PIPEHANDLER_LOCK_EN : 0; } #define readl_poll_timeout(addr,val,cond,delay,timeout) \ - ({ assert((delay) == 10 && (timeout) == 1000); \ - (val) = poll_value(addr); (cond) ? 0 : -ETIMEDOUT; }) + ({ assert((timeout) == PIPEHANDLER_LOCK_ACK_TIMEOUT_US || \ + (timeout) == PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US); \ + assert((delay) == ((timeout) > 10 * USEC_PER_MSEC ? 100 : 10)); \ + last_timeout = (timeout); (val) = poll_value(addr); (cond) ? 0 : -ETIMEDOUT; }) static void usleep_range(unsigned lo, unsigned hi) { assert(lo == 5000 && hi == 10000); sleeps++; } @@ -199,6 +203,8 @@ def block(source, marker): } static void reset(enum atcphy_generation generation, bool t8140) { memset(memory, 0, sizeof(memory)); + /* A running controller: out of reset and unclamped. */ + writel(PIPEHANDLER_AON_GEN_DWC3_RESET_N, memory + PIPEHANDLER_AON_GEN); hw = (struct atcphy_hw){ .gen = generation, .has_t8140_dp = t8140 }; p = (struct apple_atcphy){ .hw = &hw, .regs = {memory, memory}, .mode = APPLE_ATCPHY_MODE_OFF, .typec_mode = APPLE_ATCPHY_MODE_USB3, @@ -212,6 +218,7 @@ def block(source, marker): dummy_muxes = pending_seen_at_unlock = 0; usb2_power_off_calls = 0; ack_on = 1; + last_timeout = 0; check_ret = bist_ret = unlock_ret = configure_ret = 0; concurrent_override_change = false; model_t8132_off = false; @@ -227,23 +234,36 @@ def block(source, marker): TESTS = r''' static unsigned tests; #define TEST(name) do { name(); tests++; } while (0) -static void live_retry_last(void) { - reset(ATCPHY_GENERATION_T8103,false); ack_on=10; +/* A live PIPE: one request, held, and its ACK polled over the live window. */ +static void live_single_request(void) { + reset(ATCPHY_GENERATION_T8103,false); writel(BIT(7),memory+PIPEHANDLER_LOCK_REQ); assert(!atcphy_pipehandler_lock_live(&p)); - assert(polls==10 && sleeps==9 && sets==10 && clears==9); + assert(polls==1 && !sleeps && sets==1 && !clears); + assert(last_timeout==PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US); assert(readl(memory+PIPEHANDLER_LOCK_REQ)==(BIT(7)|PIPEHANDLER_LOCK_EN)); } -static void live_retry_exhausted(void) { +static void live_window_exhausted(void) { reset(ATCPHY_GENERATION_T8103,false); ack_on=0; assert(atcphy_pipehandler_lock_live(&p)==-ETIMEDOUT); - assert(polls==10 && sleeps==9 && sets==10 && clears==10); + assert(polls==1 && !sleeps && sets==1 && clears==1); + assert(last_timeout==PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US); } static void request_is_not_ack(void) { reset(ATCPHY_GENERATION_T8103,false); ack_on=2; writel(PIPEHANDLER_LOCK_EN,memory+PIPEHANDLER_LOCK_REQ); - assert(!atcphy_pipehandler_lock_live(&p)); - assert(polls==2 && sleeps==1 && sets==1 && clears==1); + assert(atcphy_pipehandler_lock_live(&p)==-ETIMEDOUT); + assert(polls==1 && !sleeps && !sets && clears==1); +} +/* A controller in reset or clamped clocks no ACK: nothing is requested. */ +static void live_held_controller_not_asked(void) { + for(unsigned clamp=0;clamp<2;clamp++) { + reset(ATCPHY_GENERATION_T8103,false); + writel(clamp?(PIPEHANDLER_AON_GEN_DWC3_RESET_N|PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN):0, + memory+PIPEHANDLER_AON_GEN); + assert(atcphy_pipehandler_lock_live(&p)==-ETIMEDOUT); + assert(!polls && !sets && !clears && !sleeps); + } } static void requested_ack_no_writes(void) { reset(ATCPHY_GENERATION_T8103,false); @@ -261,9 +281,11 @@ def block(source, marker): static void usb4_and_dead_parking_single_poll(void) { reset(ATCPHY_GENERATION_T8103,false); ack_on=0; assert(!atcphy_configure_pipehandler_usb4(&p)); assert(polls==1 && !sleeps); + assert(last_timeout==PIPEHANDLER_LOCK_ACK_TIMEOUT_US); reset(ATCPHY_GENERATION_T8103,false); ack_on=0; p.pipe_state=ATCPHY_PIPEHANDLER_STATE_USB4; assert(!atcphy_park_pipehandler(&p,true)); assert(polls==1 && !sleeps); + assert(last_timeout==PIPEHANDLER_LOCK_ACK_TIMEOUT_US); } static void early_host_and_device(void) { for(unsigned host=0;host<2;host++) { @@ -310,7 +332,7 @@ def block(source, marker): writel(BIT(7),memory+PIPEHANDLER_OVERRIDE); writel(BIT(7)|PIPEHANDLER_OVERRIDE_VAL_RXDETECT0,memory+PIPEHANDLER_OVERRIDE_VALUES); assert(atcphy_park_live_t8103_pipehandler(&p)==-ETIMEDOUT); - assert(polls==10&&sleeps==9&&!muxes&&!unlocks); + assert(polls==1&&!sleeps&&!muxes&&!unlocks); assert(readl(memory+PIPEHANDLER_OVERRIDE)==(BIT(7)|BIT(9))); assert(readl(memory+PIPEHANDLER_OVERRIDE_VALUES)==(BIT(7)|BIT(9)|PIPEHANDLER_OVERRIDE_VAL_RXDETECT0)); assert(p.pipe_state==ATCPHY_PIPEHANDLER_STATE_USB3&&!p.t8103_dummy_pending&&!p.t8103_usb3_retry&&!p.mode_dirty); @@ -328,7 +350,8 @@ def block(source, marker): } static void legacy_live_dispatch_and_generation(void) { setup_legacy_usb3();ack_on=0; - assert(atcphy_park_pipehandler(&p,false)==-ETIMEDOUT);assert(polls==10&&!muxes); + assert(atcphy_park_pipehandler(&p,false)==-ETIMEDOUT);assert(polls==1&&!muxes); + assert(last_timeout==PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US); reset(ATCPHY_GENERATION_T8122,true);p.fixed_usb2=true;p.host_active=true;p.pipe_pending=true;p.pipe_state=ATCPHY_PIPEHANDLER_STATE_USB3;ack_on=0; assert(atcphy_park_pipehandler(&p,false)==-ETIMEDOUT);assert(polls==1&&!sleeps&&!muxes&&p.mode_dirty); assert(atcphy_park_live_t8103_pipehandler(&p)==-EOPNOTSUPP); @@ -454,7 +477,7 @@ def block(source, marker): for(unsigned i=0;ihw->gen == ATCPHY_GENERATION_T8132 && atcphy_mode_is_cio(atcphy->mode)', 'atcphy->hw->gen == ATCPHY_GENERATION_T8132'), - 'no-live-retry': ('atcphy_pipehandler_lock_live', '? 10 : 1;', '? 1 : 1;'), - 'retry-later-generations': ('atcphy_pipehandler_lock_live', '? 10 : 1;', '? 10 : 10;'), - 'sleep-after-last': ('atcphy_pipehandler_lock_live', 'if (attempt + 1 < attempts)', 'if (true)'), + 'live-short-window': ('atcphy_pipehandler_lock_live', + 'PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US);', + 'PIPEHANDLER_LOCK_ACK_TIMEOUT_US);'), + 'live-ignores-reset': ('atcphy_pipehandler_lock_live', + '!(aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) ||', 'false ||'), + 'live-ignores-clamp': ('atcphy_pipehandler_lock_live', + '(aon & PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN))', 'false)'), 'missing-ack-check': ('atcphy_pipehandler_lock_timeout', 'if (requested & PIPEHANDLER_LOCK_EN) {', 'if (requested & PIPEHANDLER_LOCK_EN) return 0;\n' From b8ba9d1136e4b8ccdc2542b1b908660cae644621 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:12:19 +1100 Subject: [PATCH 2/3] phy: apple: atc: take the USB3 handoff on every T8103-generation PHY The USB3 handoff of the T8103-generation PIPE handler parks a live PIPE under a held lock before a lane change, skips host BIST, and routes USB3 for an early dwc3 role once Type-C asks for it. bb71dfa9d1ba admitted it only on an apple,t8103 machine, because M1 Pro/Max/Ultra, M2 and M2 Pro/Max/Ultra had not been qualified. Those SoCs bind the same apple,t8103-atcphy fallback and get the same PIPE handler (atcphy_hw_t8103). The handoff is a property of that block, so select it by the PHY generation, as 0287dbe78b82 first did. T8122, T8132, T8140 and T8142 PHYs are another generation and stay out. Update the KUnit admission case and the host harness to the generation rule; the mutations that equated machine and generation become equivalent and are dropped. Fixes: bb71dfa9d1ba ("phy: apple: restrict the USB3 handoff workaround to base M1") Signed-off-by: Ryan Murray --- drivers/phy/apple/atc-test.c | 43 ++++--------------- drivers/phy/apple/atc.c | 18 +++++--- tools/asahi/atc-usb3-tests.py | 80 ++++++++++------------------------- 3 files changed, 42 insertions(+), 99 deletions(-) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..a667b5a6ef932 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -1351,43 +1351,18 @@ static void atcphy_test_t8132_restore_mode(struct kunit *test) PIPEHANDLER_AON_GEN_DWC3_RESET_N); } -static void atcphy_test_t8103_usb3_machine_scope(struct kunit *test) -{ - static const struct { - const char *compatible; - bool enabled; - } cases[] = { - { "apple,t8103", true }, - { "apple,t6000", false }, - { "apple,t6001", false }, - { "apple,t6002", false }, - { "apple,t8112", false }, - { "apple,t6020", false }, - { "apple,t6021", false }, - { "apple,t6022", false }, - { "apple,t8122", false }, - { "apple,t6030", false }, - { "apple,t6031", false }, - { "apple,t6034", false }, - { "apple,t8140", false }, - { "apple,t8142", false }, - }; - struct property compatible = { .name = "compatible" }; - struct device_node root = { .properties = &compatible }; - - for (size_t i = 0; i < ARRAY_SIZE(cases); i++) { - compatible.value = (void *)cases[i].compatible; - compatible.length = strlen(cases[i].compatible) + 1; - /* M2 and Pro/Max PHYs select this same fallback hardware row. */ - KUNIT_EXPECT_EQ(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8103, &root), - cases[i].enabled); - KUNIT_EXPECT_FALSE(test, - atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8122, &root)); - } +/* The handoff follows the PIPE handler generation, whatever the machine. */ +static void atcphy_test_t8103_usb3_generation_scope(struct kunit *test) +{ + KUNIT_EXPECT_TRUE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8103)); + KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8122)); + KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8132)); + KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8140)); + KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8142)); } static struct kunit_case atcphy_mux_test_cases[] = { - KUNIT_CASE(atcphy_test_t8103_usb3_machine_scope), + KUNIT_CASE(atcphy_test_t8103_usb3_generation_scope), KUNIT_CASE(atcphy_test_target_mode), KUNIT_CASE(atcphy_test_target_mode_fixed_hub), KUNIT_CASE(atcphy_test_target_mode_t8132), diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 3ef86dbbada6b..3624e3ceacb87 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -836,7 +836,7 @@ struct atcphy_cio_sleep { * @pipe_state: Backend the PIPE mux ("pipehandler") is routed to * @t8103_dummy_pending: A live T8103-generation handoff still needs its unlock ACK * @t8103_usb3_retry: USB3 routing owed after a deferred role or parked lane change - * @t8103_usb3_workaround: Base M1 admission for the USB3 handoff workaround + * @t8103_usb3_workaround: The T8103-generation USB3 handoff, see atcphy_has_t8103_usb3_workaround() * @pd_nb: Power domain notifier, registered with restore_after_pd_off * @pd_was_off: The power domain was switched off since the state was last * brought back; set from the notifier, cleared under @lock @@ -6890,12 +6890,16 @@ static bool atcphy_probe_pd_notifier(struct apple_atcphy *atcphy) return !ret; } -/* The T8103 PHY compatible is also a fallback on unqualified M1/M2 variants. */ -static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw, - const struct device_node *root) +/* + * The USB3 handoff of the T8103-generation PIPE handler: a live PIPE is parked + * on the dummy backend under a held lock before a lane change, host BIST is + * skipped, and an early dwc3 role routes USB3 once Type-C asks for it. It is a + * property of that PIPE handler, so every PHY of the generation takes it: the + * apple,t8103-atcphy fallback of T8103, T600x, T8112 and T602x. + */ +static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw) { - return hw->gen == ATCPHY_GENERATION_T8103 && - of_device_is_compatible(root, "apple,t8103"); + return hw->gen == ATCPHY_GENERATION_T8103; } static void atcphy_sleep_finish_work(struct work_struct *work); @@ -6914,7 +6918,7 @@ static int atcphy_probe(struct platform_device *pdev) atcphy->hw = of_device_get_match_data(&pdev->dev); if (!atcphy->hw) return -EINVAL; - atcphy->t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(atcphy->hw, of_root); + atcphy->t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(atcphy->hw); atcphy->dev = dev; atcphy->np = dev->of_node; diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index b56c39dd2cd54..c6638b3e16429 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -5,9 +5,9 @@ Compile the actual driver functions, defines, enums and mode table. MMIO polling models a single completed timeout/success per invocation; no timing, electrical behavior, firmware, real BIST sequence or kernel mutex behavior is simulated. -The actual admission helper restricts the workaround to base M1 machines; -T600x/T8112/T602x still match the T8103 PHY fallback but keep their previous -single-poll/BIST/role behavior. OF compatible lookup is a modeled boundary. +The actual admission helper selects the handoff by PHY generation, so every +T8103-generation PHY (T8103, T600x, T8112, T602x through the T8103 fallback +compatible) takes it, whatever the machine. The DT-to-driver match contract is checked from the actual sources. T8132 cases cover CIO ownership during USB host shutdown; its lane setup and electrical behavior are not modeled. Hardware qualification remains necessary. @@ -80,13 +80,6 @@ def block(source, marker): struct atcphy_hw { enum atcphy_generation gen; bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; bool clear_boot_hold, dp_banked_tunables; }; -struct device_node { const char *const *compatible; unsigned int count; }; -static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { - if (!root) return false; - for (unsigned int i = 0; i < root->count; i++) - if (!strcasecmp(root->compatible[i], compatible)) return true; - return false; -} /* ACTUAL_ADMISSION */ struct reset_controller_dev { int unused; }; struct apple_atcphy { @@ -209,9 +202,7 @@ def block(source, marker): p = (struct apple_atcphy){ .hw = &hw, .regs = {memory, memory}, .mode = APPLE_ATCPHY_MODE_OFF, .typec_mode = APPLE_ATCPHY_MODE_USB3, .ss_tunables = true }; - const char *const compatibles[] = {generation == ATCPHY_GENERATION_T8103 ? "apple,t8103" : "apple,t8122"}; - const struct device_node root = {compatibles, 1}; - p.t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(&hw, &root); + p.t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(&hw); phy.data = &p; polls = sleeps = sets = clears = muxes = bist_old = bist_new = 0; configure_calls = restore_calls = unlocks = warnings = reports = 0; @@ -223,11 +214,10 @@ def block(source, marker): concurrent_override_change = false; model_t8132_off = false; } +/* The machine no longer enters the admission; kept to name the DT row under test. */ static void reset_machine(enum atcphy_generation generation, const char *machine) { + (void)machine; reset(generation, false); - const char *const compatibles[] = {"apple,synthetic-board", machine}; - const struct device_node root = {compatibles, 2}; - p.t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(&hw, &root); } ''' @@ -480,42 +470,28 @@ def block(source, marker): assert(polls==1 && !sleeps); } } -static void admission_requires_machine_and_generation(void) { +static void admission_follows_generation(void) { reset_machine(ATCPHY_GENERATION_T8103,"apple,t8103"); assert(p.t8103_usb3_workaround); + reset_machine(ATCPHY_GENERATION_T8103,"apple,synthetic-board"); + assert(p.t8103_usb3_workaround); reset_machine(ATCPHY_GENERATION_T8122,"apple,t8103"); assert(!p.t8103_usb3_workaround); - reset_machine(ATCPHY_GENERATION_T8103,"apple,t8103-extra"); - assert(!p.t8103_usb3_workaround); - reset_machine(ATCPHY_GENERATION_T8103,"APPLE,T8103"); - assert(p.t8103_usb3_workaround); /* OF compatible lookup is case-insensitive. */ - assert(!atcphy_has_t8103_usb3_workaround(&hw,NULL)); } -static void fallback_machines_keep_previous_behavior(void) { +/* M1 Pro/Max/Ultra, M2 and M2 Pro/Max/Ultra share the base M1 PIPE handler. */ +static void fallback_machines_take_the_handoff(void) { const char *const machines[]={"apple,t6000","apple,t6001","apple,t6002", "apple,t8112","apple,t6020","apple,t6021","apple,t6022"}; - for(unsigned i=0;it8103_usb3_retry = false;\n\t\t}\n\t\t/* Retry a failed PIPE setup', '\t\t\t(void)0;\n\t\t}\n\t\t/* Retry a failed PIPE setup'), - 'admission-ignores-machine': ('bool atcphy_has_t8103_usb3_workaround', - 'of_device_is_compatible(root, "apple,t8103")', - 'true'), 'admission-ignores-generation': ('bool atcphy_has_t8103_usb3_workaround', - 'hw->gen == ATCPHY_GENERATION_T8103 &&', - 'true &&'), + 'hw->gen == ATCPHY_GENERATION_T8103;', + 'true;'), 'bist-restored-t8103': ('atcphy_configure_pipehandler', 'host && !atcphy->t8103_usb3_workaround', 'host'), 'bist-skipped-later': ('atcphy_configure_pipehandler', 'host && !atcphy->t8103_usb3_workaround', 'false'), - 'bist-skipped-fallback-machines': ('atcphy_configure_pipehandler', - 'host && !atcphy->t8103_usb3_workaround', - 'host && atcphy->hw->gen != ATCPHY_GENERATION_T8103'), 'failed-state-published': ('atcphy_configure_pipehandler', 'if (!ret) {', 'if (true) {'), 'live-generation-gate-removed': ('atcphy_park_live_t8103_pipehandler', 'if (!atcphy->t8103_usb3_workaround)', 'if (false)'), - 'live-park-dispatch-all-fallbacks': ('atcphy_park_pipehandler', - '!stopped && atcphy->t8103_usb3_workaround &&', - '!stopped && atcphy->hw->gen == ATCPHY_GENERATION_T8103 &&'), - 'mux-live-park-all-fallbacks': ('atcphy_mux_switch', - 'if (atcphy->t8103_usb3_workaround)', - 'if (atcphy->hw->gen == ATCPHY_GENERATION_T8103)'), 'no-values-restore': ('atcphy_park_live_t8103_pipehandler', 'mask32(pipe + PIPEHANDLER_OVERRIDE_VALUES, value_mask,\n' '\t\t\t values & value_mask);', From 1adc1d7acc1cce5695b86d8581f68ef81046bba4 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 11:28:04 +1100 Subject: [PATCH 3/3] selftests: apple-dcp: define USEC_PER_MSEC for the atc host units The live PIPE lock window in drivers/phy/apple/atc.c is written with USEC_PER_MSEC. The host units that compile the extracted atc.c bodies had no definition, so eleven cases stopped building: host.c: error: use of undeclared identifier 'USEC_PER_MSEC' (pm-ownership, controller-lifecycle, usb-unreachable, parking, adverse-retry, masked-context, off-hardening, warm-reset, pipe, probe-mux-pm-dispatch and dwc3-teardown). Define it, with the kernel's value from include/vdso/time64.h, next to the usleep_range() stub in the three phy.py preludes and in dwc3/prefix.c. The driver keeps the named constant. Signed-off-by: Ryan Murray --- tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c | 1 + tools/testing/selftests/drivers/gpu/apple-dcp/phy.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c index 8c0bfb426e8a0..f42c7dc456167 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/prefix.c @@ -19,6 +19,7 @@ typedef uint8_t u8; #define __iomem #define udelay(n) ((void)(n)) #define usleep_range(a, b) ((void)(a), (void)(b)) +#define USEC_PER_MSEC 1000L #define fallthrough __attribute__((fallthrough)) static unsigned int warnings, generic_warnings; static void warning(const char *message) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 26c0f62dabb25..e113da10c1d7e 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -237,6 +237,7 @@ def function(source, name): #define ndelay(n) ((void)(n)) #define udelay(n) ((void)(n)) #define usleep_range(a, b) ((void)(a), (void)(b)) +#define USEC_PER_MSEC 1000L enum { TYPEC_STATE_SAFE, TYPEC_STATE_USB, TYPEC_MODE_USB4, TYPEC_DP_STATE_C, TYPEC_DP_STATE_D, TYPEC_DP_STATE_E }; enum { USB_TYPEC_TBT_SID = 0x8087, USB_TYPEC_DP_SID = 0xff01 }; @@ -2057,6 +2058,7 @@ def function(name): #define guard(kind) (void) #define fallthrough __attribute__((fallthrough)) #define usleep_range(...) ((void)0) +#define USEC_PER_MSEC 1000L #define udelay(n) ((void)(n)) #define __iomem enum { TYPEC_STATE_SAFE, TYPEC_STATE_USB, TYPEC_MODE_USB4, @@ -2480,6 +2482,7 @@ def function(source, name): #define ndelay(n) ((void)(n)) #define udelay(n) ((void)(n)) #define usleep_range(a, b) ((void)(a), (void)(b)) +#define USEC_PER_MSEC 1000L enum { TYPEC_STATE_SAFE, TYPEC_STATE_USB, TYPEC_MODE_USB4, TYPEC_DP_STATE_C, TYPEC_DP_STATE_D, TYPEC_DP_STATE_E }; enum { USB_TYPEC_TBT_SID = 0x8087, USB_TYPEC_DP_SID = 0xff01 };