diff mbox series

[3/3] thunderbolt: Enable/disable sideband depending on USB4 port offline mode

Message ID 20230602091055.65049-4-mika.westerberg@linux.intel.com (mailing list archive)
State Accepted
Commit 87200371817ec6e48e42ef2f03756268661a8815
Headers show
Series thunderbolt: Few improvements for retimer access | expand

Commit Message

Mika Westerberg June 2, 2023, 9:10 a.m. UTC
When USB4 port is in offline mode (this mean there is no device
attached) we want to keep the sideband up to make it possible to
communicate with the retimers. In the same way there is no need to
enable sideband transactions when the USB4 port is not offline as they
are already up.

For this reason make the enabling/disabling depend on the USB4 port
offline status.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/retimer.c | 19 +++++++++++++++++++
 drivers/thunderbolt/tb.h      |  5 +++++
 2 files changed, 24 insertions(+)

Comments

Yehezkel Bernat June 3, 2023, 7:24 p.m. UTC | #1
On Fri, Jun 2, 2023 at 12:11 PM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> When USB4 port is in offline mode (this mean there is no device
> attached) we want to keep the sideband up to make it possible to
> communicate with the retimers. In the same way there is no need to
> enable sideband transactions when the USB4 port is not offline as they
> are already up.
>
> For this reason make the enabling/disabling depend on the USB4 port
> offline status.

I'm probably missing something here, but if we don't allow disabling it when the
port is offline, and when the port is online the sideband is enabled, when can
it be disabled? If we can manually disable it when the port is online, on
enablement we can't assume that it's already enabled just because the port
is online, as we might have manually disabled it earlier.
Mika Westerberg June 4, 2023, 5:11 a.m. UTC | #2
Hi,

On Sat, Jun 03, 2023 at 10:24:38PM +0300, Yehezkel Bernat wrote:
> On Fri, Jun 2, 2023 at 12:11 PM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > When USB4 port is in offline mode (this mean there is no device
> > attached) we want to keep the sideband up to make it possible to
> > communicate with the retimers. In the same way there is no need to
> > enable sideband transactions when the USB4 port is not offline as they
> > are already up.
> >
> > For this reason make the enabling/disabling depend on the USB4 port
> > offline status.
> 
> I'm probably missing something here, but if we don't allow disabling it when the
> port is offline, and when the port is online the sideband is enabled, when can
> it be disabled? If we can manually disable it when the port is online, on
> enablement we can't assume that it's already enabled just because the port
> is online, as we might have manually disabled it earlier.

We allow disabling them when the port is online. This all basically
separates how the device attached and non-device attached handle the
sideband communications.
Yehezkel Bernat June 4, 2023, 9:16 a.m. UTC | #3
On Sun, Jun 4, 2023 at 8:11 AM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> Hi,
>
> On Sat, Jun 03, 2023 at 10:24:38PM +0300, Yehezkel Bernat wrote:
> > On Fri, Jun 2, 2023 at 12:11 PM Mika Westerberg
> > <mika.westerberg@linux.intel.com> wrote:
> > >
> > > When USB4 port is in offline mode (this mean there is no device
> > > attached) we want to keep the sideband up to make it possible to
> > > communicate with the retimers. In the same way there is no need to
> > > enable sideband transactions when the USB4 port is not offline as they
> > > are already up.
> > >
> > > For this reason make the enabling/disabling depend on the USB4 port
> > > offline status.
> >
> > I'm probably missing something here, but if we don't allow disabling it when the
> > port is offline, and when the port is online the sideband is enabled, when can
> > it be disabled? If we can manually disable it when the port is online, on
> > enablement we can't assume that it's already enabled just because the port
> > is online, as we might have manually disabled it earlier.
>
> We allow disabling them when the port is online. This all basically
> separates how the device attached and non-device attached handle the
> sideband communications.

OK, but then we don't enable it back, as we assume it's enabled because the
port is online, even while the user might have disabled it earlier?
Mika Westerberg June 5, 2023, 6:19 a.m. UTC | #4
Hi,

On Sun, Jun 04, 2023 at 12:16:18PM +0300, Yehezkel Bernat wrote:
> On Sun, Jun 4, 2023 at 8:11 AM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > Hi,
> >
> > On Sat, Jun 03, 2023 at 10:24:38PM +0300, Yehezkel Bernat wrote:
> > > On Fri, Jun 2, 2023 at 12:11 PM Mika Westerberg
> > > <mika.westerberg@linux.intel.com> wrote:
> > > >
> > > > When USB4 port is in offline mode (this mean there is no device
> > > > attached) we want to keep the sideband up to make it possible to
> > > > communicate with the retimers. In the same way there is no need to
> > > > enable sideband transactions when the USB4 port is not offline as they
> > > > are already up.
> > > >
> > > > For this reason make the enabling/disabling depend on the USB4 port
> > > > offline status.
> > >
> > > I'm probably missing something here, but if we don't allow disabling it when the
> > > port is offline, and when the port is online the sideband is enabled, when can
> > > it be disabled? If we can manually disable it when the port is online, on
> > > enablement we can't assume that it's already enabled just because the port
> > > is online, as we might have manually disabled it earlier.
> >
> > We allow disabling them when the port is online. This all basically
> > separates how the device attached and non-device attached handle the
> > sideband communications.
> 
> OK, but then we don't enable it back, as we assume it's enabled because the
> port is online, even while the user might have disabled it earlier?

Well there are two "modes" how they are accessed. Normal cases user
cannot offline the port so the sideband comes up when the link comes up
(e.g device is connected). In this case after the retimer enumeration
put them back to "passthrough" mode by sending the UNSET_INBOUND_SBTX.
This is needed to make the link come up after hot-reboot etc and was
recommended by our hardware folks.

The second case is when there is no device attached. This requires
special firmare too. In ChromeOS there is an ACPI _DSM method that does
this and if present we allow user to offline the port but only when
there is no device attached. In this mode we need to bring up the
sideband so we must send the SET_INBOUND_SBTX during enumeration but we
also need to keep them communicating so we cannot send
UNSET_INBOUND_SBTX. This mode is only used to upgrade the retimer NVM
firmware.

This is the idea behind these patches but let me know if I misssed
something.
diff mbox series

Patch

diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c
index a273fb02a02c..47becb363ada 100644
--- a/drivers/thunderbolt/retimer.c
+++ b/drivers/thunderbolt/retimer.c
@@ -206,6 +206,15 @@  static void tb_retimer_set_inbound_sbtx(struct tb_port *port)
 {
 	int i;
 
+	/*
+	 * When USB4 port is online sideband communications are
+	 * already up.
+	 */
+	if (!usb4_port_device_is_offline(port->usb4))
+		return;
+
+	tb_port_dbg(port, "enabling sideband transactions\n");
+
 	for (i = 1; i <= TB_MAX_RETIMER_INDEX; i++)
 		usb4_port_retimer_set_inbound_sbtx(port, i);
 }
@@ -214,6 +223,16 @@  static void tb_retimer_unset_inbound_sbtx(struct tb_port *port)
 {
 	int i;
 
+	/*
+	 * When USB4 port is offline we need to keep the sideband
+	 * communications up to make it possible to communicate with
+	 * the connected retimers.
+	 */
+	if (usb4_port_device_is_offline(port->usb4))
+		return;
+
+	tb_port_dbg(port, "disabling sideband transactions\n");
+
 	for (i = TB_MAX_RETIMER_INDEX; i >= 1; i--)
 		usb4_port_retimer_unset_inbound_sbtx(port, i);
 }
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index a89e0eb399b0..71ca6d500032 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -1326,6 +1326,11 @@  struct usb4_port *usb4_port_device_add(struct tb_port *port);
 void usb4_port_device_remove(struct usb4_port *usb4);
 int usb4_port_device_resume(struct usb4_port *usb4);
 
+static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4)
+{
+	return usb4->offline;
+}
+
 void tb_check_quirks(struct tb_switch *sw);
 
 #ifdef CONFIG_ACPI