From: Sanath S <Sanath.S@amd.com>
To: <mario.limonciello@amd.com>, <andreas.noever@gmail.com>,
<michael.jamet@intel.com>, <mika.westerberg@linux.intel.com>,
<YehezkelShB@gmail.com>, <linux-usb@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: Sanath S <Sanath.S@amd.com>
Subject: [PATCH 2/2] thunderbolt: Teardown tunnels and reset downstream ports created by boot firmware
Date: Tue, 12 Dec 2023 19:30:47 +0530 [thread overview]
Message-ID: <20231212140047.2021496-3-Sanath.S@amd.com> (raw)
In-Reply-To: <20231212140047.2021496-1-Sanath.S@amd.com>
Boot firmware might have created tunnels of its own. Since we cannot
be sure they are usable for us. Tear them down and reset the ports
to handle it as a new hotplug.
Since we teardown the tunnels, Discovering of tunnels is not needed.
Removing helper functions tb_discover_tunnels(),
tb_discover_dp_resources(), tb_create_usb3_tunnels(),
tb_add_dp_resources() and device_for_each_child().
Suggested-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Sanath S <Sanath.S@amd.com>
---
drivers/thunderbolt/tb.c | 137 ++-------------------------------------
1 file changed, 7 insertions(+), 130 deletions(-)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index fd49f86e0353..bfad14846514 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -151,24 +151,6 @@ tb_attach_bandwidth_group(struct tb_cm *tcm, struct tb_port *in,
return group;
}
-static void tb_discover_bandwidth_group(struct tb_cm *tcm, struct tb_port *in,
- struct tb_port *out)
-{
- if (usb4_dp_port_bandwidth_mode_enabled(in)) {
- int index, i;
-
- index = usb4_dp_port_group_id(in);
- for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) {
- if (tcm->groups[i].index == index) {
- tb_bandwidth_group_attach_port(&tcm->groups[i], in);
- return;
- }
- }
- }
-
- tb_attach_bandwidth_group(tcm, in, out);
-}
-
static void tb_detach_bandwidth_group(struct tb_port *in)
{
struct tb_bandwidth_group *group = in->group;
@@ -247,32 +229,6 @@ static void tb_remove_dp_resources(struct tb_switch *sw)
}
}
-static void tb_discover_dp_resource(struct tb *tb, struct tb_port *port)
-{
- struct tb_cm *tcm = tb_priv(tb);
- struct tb_port *p;
-
- list_for_each_entry(p, &tcm->dp_resources, list) {
- if (p == port)
- return;
- }
-
- tb_port_dbg(port, "DP %s resource available discovered\n",
- tb_port_is_dpin(port) ? "IN" : "OUT");
- list_add_tail(&port->list, &tcm->dp_resources);
-}
-
-static void tb_discover_dp_resources(struct tb *tb)
-{
- struct tb_cm *tcm = tb_priv(tb);
- struct tb_tunnel *tunnel;
-
- list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
- if (tb_tunnel_is_dp(tunnel))
- tb_discover_dp_resource(tb, tunnel->dst_port);
- }
-}
-
/* Enables CL states up to host router */
static int tb_enable_clx(struct tb_switch *sw)
{
@@ -472,34 +428,6 @@ static void tb_switch_discover_tunnels(struct tb_switch *sw,
}
}
-static void tb_discover_tunnels(struct tb *tb)
-{
- struct tb_cm *tcm = tb_priv(tb);
- struct tb_tunnel *tunnel;
-
- tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true);
-
- list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
- if (tb_tunnel_is_pci(tunnel)) {
- struct tb_switch *parent = tunnel->dst_port->sw;
-
- while (parent != tunnel->src_port->sw) {
- parent->boot = true;
- parent = tb_switch_parent(parent);
- }
- } else if (tb_tunnel_is_dp(tunnel)) {
- struct tb_port *in = tunnel->src_port;
- struct tb_port *out = tunnel->dst_port;
-
- /* Keep the domain from powering down */
- pm_runtime_get_sync(&in->sw->dev);
- pm_runtime_get_sync(&out->sw->dev);
-
- tb_discover_bandwidth_group(tcm, in, out);
- }
- }
-}
-
static int tb_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd)
{
if (tb_switch_is_usb4(port->sw))
@@ -1043,31 +971,6 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)
return ret;
}
-static int tb_create_usb3_tunnels(struct tb_switch *sw)
-{
- struct tb_port *port;
- int ret;
-
- if (!tb_acpi_may_tunnel_usb3())
- return 0;
-
- if (tb_route(sw)) {
- ret = tb_tunnel_usb3(sw->tb, sw);
- if (ret)
- return ret;
- }
-
- tb_switch_for_each_port(sw, port) {
- if (!tb_port_has_remote(port))
- continue;
- ret = tb_create_usb3_tunnels(port->remote->sw);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
/**
* tb_configure_asym() - Transition links to asymmetric if needed
* @tb: Domain structure
@@ -2534,27 +2437,6 @@ static void tb_stop(struct tb *tb)
tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
}
-static int tb_scan_finalize_switch(struct device *dev, void *data)
-{
- if (tb_is_switch(dev)) {
- struct tb_switch *sw = tb_to_switch(dev);
-
- /*
- * If we found that the switch was already setup by the
- * boot firmware, mark it as authorized now before we
- * send uevent to userspace.
- */
- if (sw->boot)
- sw->authorized = 1;
-
- dev_set_uevent_suppress(dev, false);
- kobject_uevent(&dev->kobj, KOBJ_ADD);
- device_for_each_child(dev, NULL, tb_scan_finalize_switch);
- }
-
- return 0;
-}
-
static int tb_start(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
@@ -2598,20 +2480,15 @@ static int tb_start(struct tb *tb)
tb_switch_tmu_enable(tb->root_switch);
/* Full scan to discover devices added before the driver was loaded. */
tb_scan_switch(tb->root_switch);
- /* Find out tunnels created by the boot firmware */
- tb_discover_tunnels(tb);
- /* Add DP resources from the DP tunnels created by the boot firmware */
- tb_discover_dp_resources(tb);
/*
- * If the boot firmware did not create USB 3.x tunnels create them
- * now for the whole topology.
+ * Boot firmware might have created tunnels of its own. Since we cannot
+ * be sure they are usable for us, Tear them down and reset the ports
+ * to handle it as new hotplug.
*/
- tb_create_usb3_tunnels(tb->root_switch);
- /* Add DP IN resources for the root switch */
- tb_add_dp_resources(tb->root_switch);
- /* Make the discovered switches available to the userspace */
- device_for_each_child(&tb->root_switch->dev, NULL,
- tb_scan_finalize_switch);
+ tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, false);
+ ret = tb_switch_reset_ports(tb->root_switch);
+ if (ret)
+ return ret;
/* Allow tb_handle_hotplug to progress events */
tcm->hotplug_active = true;
--
2.34.1
next prev parent reply other threads:[~2023-12-12 14:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 14:00 [PATCH 0/2] Add support for downstream port reset(DPR) Sanath S
2023-12-12 14:00 ` [PATCH 1/2] thunderbolt: Introduce tb_switch_reset_ports(), tb_port_reset() and usb4_port_reset() Sanath S
2023-12-12 15:27 ` Mika Westerberg
2023-12-12 15:32 ` Mario Limonciello
2023-12-12 15:41 ` Mika Westerberg
2023-12-12 14:00 ` Sanath S [this message]
2023-12-12 15:10 ` [PATCH 2/2] thunderbolt: Teardown tunnels and reset downstream ports created by boot firmware Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231212140047.2021496-3-Sanath.S@amd.com \
--to=sanath.s@amd.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=michael.jamet@intel.com \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox