Linux USB
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
	Lukas Wunner <lukas@wunner.de>,
	Andreas Noever <andreas.noever@gmail.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Mika Westerberg <westeri@kernel.org>
Subject: [PATCH 9/9] Documentation: thunderbolt: Document USB4STREAM coupling
Date: Wed, 25 Nov 2026 16:26:22 +0100	[thread overview]
Message-ID: <20261125152623.456054-10-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20261125152623.456054-1-mika.westerberg@linux.intel.com>

From: "Mika Westerberg (Intel)" <westeri@kernel.org>

This adds a section to the admin guide describing how USB4STREAM
coupling could be used.

Signed-off-by: Mika Westerberg (Intel) <westeri@kernel.org>
---
 Documentation/admin-guide/thunderbolt.rst | 119 ++++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/Documentation/admin-guide/thunderbolt.rst b/Documentation/admin-guide/thunderbolt.rst
index ff25fe853706..3b71feaa1efa 100644
--- a/Documentation/admin-guide/thunderbolt.rst
+++ b/Documentation/admin-guide/thunderbolt.rst
@@ -434,6 +434,125 @@ Then you have ``/dev/tbstream0`` for ``control`` and ``/dev/tbstream1``
 for ``data``. Before you can use them you need to configure them as
 shown above for the one stream case.
 
+Coupling a stream between two other hosts
+-----------------------------------------
+If a host is connected to two other hosts, say
+``host1 <-> host2 <-> host3`` where ``host2`` is the one running Linux,
+then ``host2`` can forward streams between ``host1`` and ``host3``
+through the routers of its domain. The two hosts do not need to be
+connected directly to ``host2``, there can be device routers such as
+USB4 hubs in between.
+
+This can already be done in userspace like::
+
+  host2 # dd if=/dev/tbstream0 of=/dev/tbstream1
+
+but that copies every frame through the memory of ``host2`` and needs
+another process for the other direction.
+
+With coupling the frames go through a tunnel directly between ``host1``
+and ``host3`` through the shortest path so there is no need for a
+separate application that copies the frames. Coupling only works with
+the software connection manager as ``host2``.
+
+Start from ``host2``, where ``host1`` is ``0-1.0`` and ``host3`` is
+``0-3.0``. The coupling is created under ``coupling`` in a directory
+named after the two services, and it has a sub-directory for each of
+them::
+
+  host2 # cd /sys/kernel/config/thunderbolt/stream/coupling
+  host2 # mkdir -p 0-1.0_0-3.0/data
+  host2 # cd 0-1.0_0-3.0/data
+  host2 # echo -1 > 0-1.0/in_hopid
+  host2 # echo -1 > 0-1.0/out_hopid
+  host2 # echo -1 > 0-3.0/in_hopid
+  host2 # echo -1 > 0-3.0/out_hopid
+
+Like elsewhere in the driver ``in_hopid`` is the HopID the host on that
+side sends with and ``out_hopid`` the one used when sending towards it.
+Using ``-1`` picks the next available one::
+
+  host2 # grep -H . 0-1.0/*_hopid 0-3.0/*_hopid
+  0-1.0/in_hopid:8
+  0-1.0/out_hopid:8
+  0-3.0/in_hopid:8
+  0-3.0/out_hopid:8
+
+HopIDs are allocated per adapter and per direction, so each adapter has
+one for the packets coming in and another for the ones going out (more
+details can be found from USB4 spec). In the above example there were no
+other tunnels through the lane adapters so the first available HopID in
+either direction is ``8``.
+
+Each host announces its streams to the other side of the link which
+allows performing auto-configuration on that side using the same name
+for the stream.
+
+Now ``host1`` and ``host3`` only need the stream created because the
+HopIDs are picked up from what ``host2`` announces, reversed so that the
+``in_hopid`` of one end matches the ``out_hopid`` of the other::
+
+  host1 # cd /sys/kernel/config/thunderbolt/stream
+  host1 # mkdir -p 0-1.0/data
+
+  host3 # cd /sys/kernel/config/thunderbolt/stream
+  host3 # mkdir -p 0-1.0/data
+
+Note that ``host2`` is ``0-1.0`` for both of them, the service names are
+relative to the domain of each host. The other way around works just as
+well: if the streams on ``host1`` and ``host3`` are configured first,
+creating the two directories on ``host2`` is enough and the HopIDs of
+both of its sides are picked up from them. It is also possible to
+configure HopIDs manually.
+
+There is no ``/dev/tbstreamX`` node on ``host2`` because the frames do
+not go through it. Once all four HopIDs are in place and both hosts are
+connected the tunnel is established and ``host1`` and ``host3`` can talk
+to each other as if there was a single cable between them. It can be
+inspected with ``tbtunnels`` from tbtools.
+
+The tunnel only covers the routers that are actually between the two
+hosts and it turns at the closest common router of the two, which is not
+necessarily the one of ``host2``. If both hosts are connected to the
+same hub below ``host2``::
+
+              [host2]
+                 |
+               [Hub]
+              /     \
+        [host1]     [host3]
+
+then the tunnel goes only through the hub, not involving the host router
+on ``host2`` at all. ``host2`` still needs to set it up because it
+is the connection manager of that domain.
+
+After this the ``/dev/tbstreamX`` on ``host1`` and ``host3`` can be used
+like a regular stream described in the previous section, with the
+difference explained below. The hosts ``host1`` and ``host3`` do not
+need to support coupling themselves and can be even using firmware
+connection manager.
+
+Each hop of a path keeps track of the credits it has sent and received,
+and this state is only reset when the path is set up (see the USB4 spec
+for details). For a coupled stream the path is split between three
+hosts: ``host1`` and ``host3`` set up their part when the stream is
+opened and tear it down when it is closed, while the part ``host2`` set
+up stays in place. It is therefore recommended that the whole tunnel is
+torn down and recreated before a new transfer takes place::
+
+  host2 # cd /sys/kernel/config/thunderbolt/stream/coupling
+  host2 # rmdir 0-1.0_0-3.0/data
+  host2 # mkdir 0-1.0_0-3.0/data
+
+This assumes both sides announce their HopIDs so the coupling can be
+re-created based on those. Otherwise HopIDs need to be filled in as
+well.
+
+The coupling stays until it is removed as below::
+
+  host2 # cd /sys/kernel/config/thunderbolt/stream/coupling
+  host2 # rmdir -p 0-1.0_0-3.0/data
+
 Forcing power
 -------------
 Many OEMs include a method that can be used to force the power of a
-- 
2.50.1


      parent reply	other threads:[~2026-11-25 15:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:26 [PATCH 0/9] thunderbolt: Introduce USB4STREAM coupling Mika Westerberg
2026-11-25 15:26 ` [PATCH 1/9] thunderbolt: Add and remove XDomain services outside of the state work Mika Westerberg
2026-11-25 15:26 ` [PATCH 2/9] thunderbolt: Unregister XDomains when the domain is removed Mika Westerberg
2026-11-25 15:26 ` [PATCH 3/9] thunderbolt: stream: Keep better track of the HopIDs Mika Westerberg
2026-11-25 15:26 ` [PATCH 4/9] thunderbolt: stream: Validate the ConfigFS group name more strictly Mika Westerberg
2026-11-25 15:26 ` [PATCH 5/9] thunderbolt: Allow DMA tunnel also between two lane adapters Mika Westerberg
2026-11-25 15:26 ` [PATCH 6/9] thunderbolt: Add KUnit tests for lane to lane DMA tunnels Mika Westerberg
2026-11-25 15:26 ` [PATCH 7/9] thunderbolt: Add tb_xdomains_enable_paths() and tb_xdomains_disable_paths() Mika Westerberg
2026-11-25 15:26 ` [PATCH 8/9] thunderbolt: stream: Introduce USB4STREAM coupling Mika Westerberg
2026-11-25 15:26 ` Mika Westerberg [this message]

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=20261125152623.456054-10-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=westeri@kernel.org \
    /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