From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Brad Campbell <lists2009@fnarfbargle.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Apple Thunderbolt Display chaining
Date: Tue, 9 Aug 2022 18:50:28 +0300 [thread overview]
Message-ID: <YvKCRPtoN6m2rMr2@lahna> (raw)
In-Reply-To: <39268cc6-4e05-b83c-ff73-3056925eeb76@fnarfbargle.com>
Hi,
On Tue, Aug 09, 2022 at 11:16:27PM +0800, Brad Campbell wrote:
> If I then reboot and load the driver it fails.
>
> The only thing I could think of doing was an lspci -vvv after the boot and module load
> and an lspci -vvv after a warm reboot and diff them, because there are changes around the
> thunderbolt bridge devices. I've done a diff -u50 to try and keep as much context as possible.
>
> On the first boot I can unload/reload the thunderbolt module repeatedly and there's no issue
> but loading it after a reboot locks up. There are no lspci changes on the first boot after the
> initial module load unless I rescan the PCI bus, but they're minor and it doesn't cause an issue
> with loading the thunderbolt module.
>
> The firmware *must* be doing something on reboot I suppose or the PCIe configs wouldn't change.
Okay, let's try a bigger hammer and reset all the ports upon load. That
should hopefully clear out the "bad state" too. This is completely
untested but it should trigger reset and then re-initialize the TBT
links.
diff --git a/drivers/thunderbolt/lc.c b/drivers/thunderbolt/lc.c
index 633970fbe9b0..c419c2568de4 100644
--- a/drivers/thunderbolt/lc.c
+++ b/drivers/thunderbolt/lc.c
@@ -6,6 +6,8 @@
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
*/
+#include <linux/delay.h>
+
#include "tb.h"
/**
@@ -327,6 +329,34 @@ void tb_lc_xhci_disconnect(struct tb_port *port)
tb_port_dbg(port, "xHCI disconnected\n");
}
+int tb_lc_reset_port(struct tb_port *port)
+{
+ struct tb_switch *sw = port->sw;
+ int cap, ret;
+ u32 val;
+
+ if (sw->generation != 3)
+ return -EINVAL;
+
+ cap = find_port_lc_cap(port);
+ if (cap < 0)
+ return cap;
+
+ ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
+ if (ret)
+ return ret;
+
+ val |= TB_LC_PORT_MODE_DPR;
+ ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
+ if (ret)
+ return ret;
+
+ msleep(20);
+
+ val &= ~TB_LC_PORT_MODE_DPR;
+ return tb_sw_write(sw, &val, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
+}
+
static int tb_lc_set_wake_one(struct tb_switch *sw, unsigned int offset,
unsigned int flags)
{
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 0ae8a7ec7c9c..21ac3ccf1cf9 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -740,6 +740,11 @@ int tb_port_disable(struct tb_port *port)
return __tb_port_enable(port, false);
}
+int tb_port_reset(struct tb_port *port)
+{
+ return tb_lc_reset_port(port);
+}
+
/*
* tb_init_port() - initialize a port
*
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 8030fc544c5e..48a7396994ef 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -1875,6 +1875,7 @@ static int tb_scan_finalize_switch(struct device *dev, void *data)
static int tb_start(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
+ struct tb_port *p;
int ret;
tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
@@ -1911,6 +1912,12 @@ static int tb_start(struct tb *tb)
false);
/* Enable TMU if it is off */
tb_switch_tmu_enable(tb->root_switch);
+
+ tb_switch_for_each_port(tb->root_switch, p) {
+ if (tb_port_is_null(p))
+ tb_port_reset(p);
+ }
+
/* 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 */
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 28bb80d967d6..fe5edefec712 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -1028,6 +1028,7 @@ int tb_port_clear_counter(struct tb_port *port, int counter);
int tb_port_unlock(struct tb_port *port);
int tb_port_enable(struct tb_port *port);
int tb_port_disable(struct tb_port *port);
+int tb_port_reset(struct tb_port *port);
int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
void tb_port_release_in_hopid(struct tb_port *port, int hopid);
int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
@@ -1121,6 +1122,7 @@ bool tb_lc_is_usb_plugged(struct tb_port *port);
bool tb_lc_is_xhci_connected(struct tb_port *port);
int tb_lc_xhci_connect(struct tb_port *port);
void tb_lc_xhci_disconnect(struct tb_port *port);
+int tb_lc_reset_port(struct tb_port *port);
int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags);
int tb_lc_set_sleep(struct tb_switch *sw);
bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h
index f8c1ca3464d9..8fd12bc2d500 100644
--- a/drivers/thunderbolt/tb_regs.h
+++ b/drivers/thunderbolt/tb_regs.h
@@ -555,6 +555,9 @@ struct tb_regs_hop {
#define TB_LC_POWER 0x740
/* Link controller registers */
+#define TB_LC_PORT_MODE 0x26
+#define TB_LC_PORT_MODE_DPR BIT(6)
+
#define TB_LC_CS_42 0x2a
#define TB_LC_CS_42_USB_PLUGGED BIT(31)
next prev parent reply other threads:[~2022-08-09 15:52 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <acbb3a86-ea15-47ec-90fa-72fbd94921b1@fnarfbargle.com>
2022-03-29 11:31 ` Apple Thunderbolt Display chaining Mika Westerberg
2022-03-29 12:35 ` Brad Campbell
2022-03-29 13:00 ` Mika Westerberg
2022-03-29 14:06 ` Brad Campbell
2022-03-30 10:18 ` Mika Westerberg
2022-03-30 13:19 ` Brad Campbell
2022-03-30 13:43 ` Mika Westerberg
2022-03-30 14:24 ` Brad Campbell
2022-03-30 14:47 ` Mika Westerberg
2022-03-31 9:02 ` Brad Campbell
2022-03-31 16:36 ` Mika Westerberg
2022-04-01 5:48 ` Brad Campbell
2022-04-01 14:30 ` Mika Westerberg
2022-04-01 15:05 ` Brad Campbell
2022-04-04 10:10 ` Mika Westerberg
2022-04-04 11:38 ` Brad Campbell
2022-04-04 12:53 ` Mika Westerberg
2022-04-06 2:51 ` Brad Campbell
2022-04-06 14:56 ` Mika Westerberg
2022-08-05 7:41 ` Brad Campbell
2022-08-05 11:30 ` Mika Westerberg
2022-08-05 12:43 ` Brad Campbell
2022-08-05 13:01 ` Mika Westerberg
2022-08-05 14:13 ` Brad Campbell
2022-08-05 14:21 ` Mika Westerberg
2022-08-05 14:43 ` Brad Campbell
2022-08-06 6:13 ` Mika Westerberg
2022-08-06 9:41 ` Brad Campbell
2022-08-08 9:51 ` Mika Westerberg
2022-08-08 11:55 ` Brad Campbell
2022-08-08 12:25 ` Brad Campbell
2022-08-08 12:46 ` Mika Westerberg
2022-08-08 13:27 ` Brad Campbell
2022-08-09 10:23 ` Mika Westerberg
2022-08-09 10:40 ` Brad Campbell
2022-08-09 10:55 ` Mika Westerberg
2022-08-09 11:03 ` Brad Campbell
2022-08-09 11:08 ` Brad Campbell
2022-08-09 14:42 ` Mika Westerberg
2022-08-09 15:16 ` Brad Campbell
2022-08-09 15:50 ` Mika Westerberg [this message]
2022-08-10 7:40 ` Brad Campbell
2022-08-11 9:50 ` Mika Westerberg
2022-08-11 14:17 ` Brad Campbell
2022-08-12 9:35 ` Mika Westerberg
2022-08-12 10:16 ` Brad Campbell
2022-08-08 12:42 ` 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=YvKCRPtoN6m2rMr2@lahna \
--to=mika.westerberg@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lists2009@fnarfbargle.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