diff --git a/drivers/gpu/drm/apple/dcp-fabric-topology-test.c b/drivers/gpu/drm/apple/dcp-fabric-topology-test.c index f1c62a6f010ae..4f42e76942f8f 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-topology-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-topology-test.c @@ -403,13 +403,55 @@ static void topology_route_skip_test(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cs); KUNIT_EXPECT_FALSE(test, of_device_is_available(route_np)); - /* A changeset still applied must not be destroyed */ + /* A repeated refusal neither allocates a changeset nor replaces status. */ + KUNIT_EXPECT_NULL(test, dcp_typec_routes_disable_nodes(dev, NULL, route_np)); + KUNIT_EXPECT_NULL(test, dcp_typec_routes_disable_nodes(dev, route_np->parent, NULL)); + KUNIT_EXPECT_EQ(test, PTR_ERR(dcp_typec_route_skip(dev, route_np, "typec1")), + -ENODEV); + KUNIT_EXPECT_FALSE(test, of_device_is_available(route_np)); + + /* + * A changeset still applied must not be destroyed here: retain it so + * the test can revert before overlay removal. + */ KUNIT_ASSERT_EQ(test, of_changeset_revert(cs), 0); - of_changeset_destroy(cs); - kfree(cs); + dcp_typec_routes_disable_free(cs); KUNIT_EXPECT_TRUE(test, of_device_is_available(route_np)); } +/* Permanent changes retain their properties, but not changeset node refs. */ +static void topology_route_disable_cleanup_test(struct kunit *test) +{ + struct device_node *route_np; + struct property *status; + struct device *dev; + unsigned int refs; + + KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, dcp_route_supplier_test)); + dev = kunit_device_register(test, "dcp-route-disable"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dev->of_node = of_find_node_by_path("/dcp-route-supplier-test/dcp"); + KUNIT_ASSERT_NOT_NULL(test, dev->of_node); + KUNIT_ASSERT_EQ(test, + kunit_add_action_or_reset(test, topology_route_supplier_put, dev), 0); + route_np = of_find_node_by_path("/dcp-route-supplier-test/dcp/typec-routes/route@1"); + KUNIT_ASSERT_NOT_NULL(test, route_np); + KUNIT_ASSERT_EQ(test, + kunit_add_action_or_reset(test, topology_route_node_put, route_np), 0); + refs = kref_read(&route_np->kobj.kref); + + dcp_typec_routes_disable_dev(dev); + KUNIT_EXPECT_FALSE(test, of_device_is_available(route_np)); + KUNIT_EXPECT_EQ(test, kref_read(&route_np->kobj.kref), refs); + status = of_find_property(route_np, "status", NULL); + KUNIT_ASSERT_NOT_NULL(test, status); + KUNIT_EXPECT_STREQ(test, status->value, "disabled"); + + dcp_typec_routes_disable_dev(dev); + KUNIT_EXPECT_PTR_EQ(test, of_find_property(route_np, "status", NULL), status); + KUNIT_EXPECT_EQ(test, kref_read(&route_np->kobj.kref), refs); +} + /* * apple_typec_port_rgb8_only(): a Type-C port is 8-bit RGB only if one of * the pipelines in scope (all of them, or only @pipeline) is a candidate for @@ -533,6 +575,7 @@ static struct kunit_case dcp_topology_cases[] = { KUNIT_CASE(topology_connector_group_test), KUNIT_CASE(topology_route_supplier_test), KUNIT_CASE(topology_route_skip_test), + KUNIT_CASE(topology_route_disable_cleanup_test), KUNIT_CASE(topology_rgb8_only_test), {} }; diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 22148f031868f..d0c11273b71ca 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -4850,8 +4850,9 @@ static bool dcp_typec_route_supplier_available(struct device *dev, const char *l * Disables @route, or every available route under @routes if @route is NULL, * in the device tree, in one changeset, for good. A connector passes over * unavailable routes when it looks for its display routes, so the port no - * longer waits for them. Returns the applied changeset, which stays (the live - * tree refers to it), or an ERR_PTR. + * longer waits for them. Returns the applied changeset, NULL if nothing was + * available, or an ERR_PTR. The caller must destroy and free the changeset; + * destroying it does not revert the changes or free the live properties. */ static struct of_changeset *dcp_typec_routes_disable_nodes(struct device *dev, struct device_node *routes, @@ -4861,6 +4862,9 @@ static struct of_changeset *dcp_typec_routes_disable_nodes(struct device *dev, struct device_node *np; int ret = 0; + if (route ? !of_device_is_available(route) : !dcp_typec_routes_available(routes)) + return NULL; + cs = kzalloc_obj(*cs); if (!cs) return ERR_PTR(-ENOMEM); @@ -4890,6 +4894,14 @@ static struct of_changeset *dcp_typec_routes_disable_nodes(struct device *dev, return cs; } +static void dcp_typec_routes_disable_free(struct of_changeset *cs) +{ + if (IS_ERR_OR_NULL(cs)) + return; + of_changeset_destroy(cs); + kfree(cs); +} + /* * Which of @dev's suppliers for its Type-C route @name ("typecN") has a * disabled node: "DP PHY", "display crossbar", or NULL if neither. Such a @@ -4916,11 +4928,14 @@ static struct of_changeset *dcp_typec_route_skip(struct device *dev, const char *name) { const char *what = dcp_typec_route_supplier_disabled(dev, name); + struct of_changeset *cs; if (!what) return NULL; dev_warn(dev, "%pOF: its %s is disabled, route skipped\n", route_np, what); - return dcp_typec_routes_disable_nodes(dev, NULL, route_np); + cs = dcp_typec_routes_disable_nodes(dev, NULL, route_np); + /* A concurrent refusal may already have disabled it; still skip it. */ + return cs ?: ERR_PTR(-ENODEV); } static int dcp_register_typec_routes_present(void *data) @@ -4933,6 +4948,7 @@ static int dcp_register_typec_routes_present(void *data) int ret; for_each_available_child_of_node_scoped(routes, route_np) { + struct of_changeset *cs; struct apple_dcp_typec_route *route; struct device_node *endpoint __free(device_node) = NULL; struct device_node *connector_np; @@ -4964,8 +4980,11 @@ static int dcp_register_typec_routes_present(void *data) return -ENOMEM; /* Skipped even if disabling it failed (logged): it cannot register */ - if (dcp_typec_route_skip(dev, route_np, name)) + cs = dcp_typec_route_skip(dev, route_np, name); + if (cs) { + dcp_typec_routes_disable_free(cs); continue; + } route = &dcp->typec_routes[dcp->nr_typec_routes]; route->dcp = dcp; @@ -5092,7 +5111,7 @@ void dcp_typec_routes_disable_dev(struct device *dev) of_get_child_by_name(dev->of_node, "typec-routes"); if (routes) - dcp_typec_routes_disable_nodes(dev, routes, NULL); + dcp_typec_routes_disable_free(dcp_typec_routes_disable_nodes(dev, routes, NULL)); } int dcp_register_typec_routes(struct apple_dcp *dcp) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index cb3a94977182a..ca11e5085cc6e 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -101,6 +101,7 @@ #include #include #include +#include #include #include #include @@ -354,6 +355,13 @@ static const struct apple_cio_hw apple_cio_t6040_hw = { */ #define APPLE_CIO_LINK_LOST_MS 3000 #define APPLE_CIO_LINK_LOST_CYCLES 3 +/* + * Recovery policy: three automatic port cycles per one-minute window, even + * when a flapping peer completes discovery between link losses. A loss past + * the limit is checked again when the window ends, so a peer that settles + * still gets its link back without a replug. + */ +#define APPLE_CIO_LINK_LOST_INTERVAL (60 * HZ) static bool resume_recovery; module_param(resume_recovery, bool, 0644); @@ -569,6 +577,7 @@ struct apple_cio { unsigned int start_gen; /* protected by lock: bumped by every start */ unsigned int link_lost_gen; /* start_gen when the peer went away */ unsigned int link_lost_cycles; /* protected by lock */ + struct ratelimit_state link_lost_limit; /* survives domain rebuilds */ u64 link_lost_cycle_activity; /* remote activity of this domain at the last cycle */ bool link_lost_restart; /* protected by lock: cycle requested */ struct notifier_block pm_notifier; @@ -3964,6 +3973,20 @@ static void apple_cio_link_lost_work(struct work_struct *work) acio->sleep_peer_wanted = false; return; } + /* Discovery refills the consecutive budget, not this rate limit. */ + if (!__ratelimit(&acio->link_lost_limit)) { + dev_warn(acio->dev, + "peer link keeps dropping, next port restart check in %d s\n", + APPLE_CIO_LINK_LOST_INTERVAL / HZ); + acio->sleep_peer_wanted = false; + /* + * Look again once the window is over: a peer that has + * settled by then gets its port restart. + */ + mod_delayed_work(system_freezable_wq, &acio->link_lost_work, + APPLE_CIO_LINK_LOST_INTERVAL); + return; + } acio->link_lost_cycles++; WRITE_ONCE(acio->link_lost_cycle_activity, activity); acio->link_lost_restart = true; @@ -4749,6 +4772,9 @@ static int apple_cio_probe(struct platform_device *pdev) apple_cio_pcie_tunnel_work); INIT_DELAYED_WORK(&acio->resume_link_work, apple_cio_resume_link_work); INIT_DELAYED_WORK(&acio->link_lost_work, apple_cio_link_lost_work); + ratelimit_state_init(&acio->link_lost_limit, APPLE_CIO_LINK_LOST_INTERVAL, + APPLE_CIO_LINK_LOST_CYCLES); + ratelimit_set_flags(&acio->link_lost_limit, RATELIMIT_MSG_ON_RELEASE); INIT_DELAYED_WORK(&acio->sleep_restart_work, apple_cio_sleep_restart_work); INIT_WORK(&acio->sleep_dp_undo_work, apple_cio_sleep_dp_undo_work); init_completion(&acio->nhi_boot_completion); diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index d9ece372d36a4..c469e5b47b96b 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -1310,8 +1310,9 @@ static void cd321x_update_work(struct work_struct *work) /* * ACIO carries the tunneled PCIe reset handshake over the still-live * Type-C data path. Close a disappearing USB4/TBT session before dropping - * the USB role; otherwise the role transition tears down the ATC lanes and - * PCIe-C cannot quiesce its hierarchy before NHI removal. + * the USB role, so PCIe-C can quiesce its hierarchy before NHI removal. + * Stopping the USB role parks its PIPE; the Type-C mux releases the ATC + * lanes after the USB4/TBT session has closed. */ if ((!new_connected || was_disconnected) && (!cd321x->state_valid || cd321x->state.mode != TYPEC_STATE_SAFE)) { diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 1403fa2a637c1..972dbd8deb517 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -9,7 +9,7 @@ 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 DT-to-driver match contract is checked from the actual sources. -CIO ownership during USB host shutdown is covered on T8103 and T8132; T8132 lane setup +CIO ownership, PIPE parking and mux disconnect are covered on every modeled generation; T8132 lane setup and electrical behavior are not modeled. Hardware qualification remains necessary. Run --mutations for sensitivity checks. """ @@ -421,17 +421,22 @@ def block(source, marker): static void usb_stop_keeps_cio_until_mux_disconnect(void) { const enum atcphy_mode modes[] = { APPLE_ATCPHY_MODE_TBT, APPLE_ATCPHY_MODE_USB4 }; /* Every generation: T8112 and T600x run the T8103 PHY sequence. */ - const enum atcphy_generation gens[] = { ATCPHY_GENERATION_T8103, ATCPHY_GENERATION_T8132 }; - for (unsigned g=0;g<2;g++) for (unsigned i=0;i<2;i++) { + const enum atcphy_generation gens[] = { ATCPHY_GENERATION_T8103, ATCPHY_GENERATION_T8122, + ATCPHY_GENERATION_T8132 }; + for (unsigned g=0;gmode) && !atcphy->mode_dirty', 'atcphy->hw->gen == ATCPHY_GENERATION_T8132 && atcphy_mode_is_cio(atcphy->mode) && !atcphy->mode_dirty'), + 'usb4-stop-skips-pipe-park': ('atcphy_usb3_power_off', + 'ret = atcphy_park_pipehandler(atcphy, true);', + 'ret = atcphy->pipe_state == ATCPHY_PIPEHANDLER_STATE_USB4 ? 0 : atcphy_park_pipehandler(atcphy, true);'), + 'cio-mux-disconnect-keeps-lanes': ('atcphy_mux_switch', + 'ret = atcphy_configure(atcphy, target_mode);\n\tif (ret)', + 'ret = target_mode == APPLE_ATCPHY_MODE_OFF && atcphy_mode_is_cio(atcphy->mode) ? 0 : atcphy_configure(atcphy, target_mode);\n\tif (ret)'), 't8132-device-role-refused': ('atcphy_usb3_set_mode', 'if (usb2_device) {', 'if (usb2_device) {\n\t\t\treturn -EOPNOTSUPP;'),