Skip to contentSkip to conversation

thunderbolt: Introduce USB4STREAM coupling

PATCH New Mika Westerberg 1 participant 10 messages Nov 25

Subsystems (3)
lore
Share & tools
lore
#4 lore raw

PATCH 4/9 thunderbolt: stream: Validate the ConfigFS group name more strictly

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

The ConfigFS group names must match the Thunderbolt service names so passing something like "0-1.0a" will not match any service but it is accepted at the moment. Make this more strict. We are going to need this also later in the series when we introduce USB4STREAM coupling.

---
 drivers/thunderbolt/stream.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/thunderbolt/stream.c +12 -4
index 2b73f585ccff..2661f563b99c 100644
@@ -1763,16 +1763,24 @@ static const struct config_item_type tbstream_dev_group_type = {
 	.ct_item_ops = &tbstream_item_ops,
 };
 
+static bool tbstream_valid_service_name(const char *name)
+{
+	unsigned int domain, index;
+	int len = 0;
+	u64 route;
+
+	if (sscanf(name, "%u-%llx.%u%n", &domain, &route, &index, &len) != 3)
+		return false;
+	return len == strlen(name);
+}
+
 static struct config_group *
 tbstream_make_group(struct config_group *group, const char *name)
 {
 	struct tbstream_group *sg;
 	struct tbstream *stream;
-	int domain, index;
-	u64 route;
 
-	/* Make sure the format is correct */
-	if (sscanf(name, "%u-%llx.%u", &domain, &route, &index) != 3)
+	if (!tbstream_valid_service_name(name))
 		return ERR_PTR(-EINVAL);
 
 	sg = kzalloc_obj(*sg);
Signature · 1 line
2.50.1
#0 lore raw

cover thunderbolt: Introduce USB4STREAM coupling

Hi all,

This series makes it possible to "couple" streams through host or device router lane adapters. For example we can have topology like this:

host1 <-USB4/TB cable-> host2 <-USB4/TB cable-> host3

You can already forward stream from host1 to host3 through host2 using dd or similar but we can also make direct tunnel through the host2 host router. This does not consume CPU cycles of the host2. Same can be done if there is a device router where the hosts are connected. It will take the shortest path.

The first patches are fixes that the rest of the series needs. The usage steps are in the last patch.

This applies on top of my "shared buffer" series here:

https://lore.kernel.org/linux-usb/[email protected]/

Mika Westerberg (Intel) (9):
thunderbolt: Add and remove XDomain services outside of the state work
thunderbolt: Unregister XDomains when the domain is removed
thunderbolt: stream: Keep better track of the HopIDs
thunderbolt: stream: Validate the ConfigFS group name more strictly
thunderbolt: Allow DMA tunnel also between two lane adapters
thunderbolt: Add KUnit tests for lane to lane DMA tunnels
thunderbolt: Add tb_xdomains_enable_paths() and tb_xdomains_disable_paths()
thunderbolt: stream: Introduce USB4STREAM coupling
Documentation: thunderbolt: Document USB4STREAM coupling

 .../ABI/testing/configfs-thunderbolt_stream   |  82 ++
 Documentation/admin-guide/thunderbolt.rst     | 119 +++
 drivers/thunderbolt/domain.c                  | 104 +-
 drivers/thunderbolt/icm.c                     |  49 +-
 drivers/thunderbolt/stream.c                  | 971 +++++++++++++++++-
 drivers/thunderbolt/tb.c                      | 150 +--
 drivers/thunderbolt/tb.h                      |  28 +-
 drivers/thunderbolt/test.c                    | 558 ++++++++--
 drivers/thunderbolt/tunnel.c                  | 171 +--
 drivers/thunderbolt/tunnel.h                  |  14 +-
 drivers/thunderbolt/xdomain.c                 | 163 ++-
 include/linux/thunderbolt.h                   |  14 +
 12 files changed, 2108 insertions(+), 315 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/9 thunderbolt: Add and remove XDomain services outside of the state work

From: "Mika Westerberg (Intel)" <[email protected]>

The XDomain services are registered and unregistered from the state work, which means the service driver probe and remove callbacks are called from there too. The state work is cancelled synchronously in tb_xdomain_remove() which is called with tb->lock held, so if a service driver calls anything that takes tb->lock, such as tb_xdomain_disable_paths() they end up waiting for each other.

Fix this by moving the service enumeration into a separate work that is only waited for in tb_xdomain_unregister(), which is called without tb->lock.

Fixes a8937f35cf39 ("thunderbolt: Remove XDomain from the bus without holding tb->lock")
---
 drivers/thunderbolt/xdomain.c | 53 ++++++++++++++++++++++++++---------
 include/linux/thunderbolt.h   |  5 ++++
 2 files changed, 44 insertions(+), 14 deletions(-)
drivers/thunderbolt/xdomain.c +39 -14
index e5a962537920..55e17f4e35dc 100644
@@ -1164,15 +1164,14 @@ static void __unregister_service(struct device *dev)
 
 static int remove_missing_service(struct device *dev, void *data)
 {
-	struct tb_xdomain *xd = data;
+	struct tb_property_dir *dir = data;
 	struct tb_service *svc;
 
 	svc = tb_to_service(dev);
 	if (!svc)
 		return 0;
 
-	if (!tb_property_find(xd->remote_properties, svc->key,
-			      TB_PROPERTY_TYPE_DIRECTORY))
+	if (!tb_property_find(dir, svc->key, TB_PROPERTY_TYPE_DIRECTORY))
 		__unregister_service(dev);
 
 	return 0;
@@ -1223,7 +1222,8 @@ static int populate_service(struct tb_service *svc,
 	return 0;
 }
 
-static void enumerate_services(struct tb_xdomain *xd)
+static void enumerate_services(struct tb_xdomain *xd,
+			       struct tb_property_dir *dir)
 {
 	struct tb_service *svc;
 	struct tb_property *p;
@@ -1234,10 +1234,10 @@ static void enumerate_services(struct tb_xdomain *xd)
 	 * First remove all services that are not available anymore in
 	 * the updated property block.
 	 */
-	device_for_each_child_reverse(&xd->dev, xd, remove_missing_service);
+	device_for_each_child_reverse(&xd->dev, dir, remove_missing_service);
 
 	/* Then re-enumerate properties creating new services as we go */
-	tb_property_for_each(xd->remote_properties, p) {
+	tb_property_for_each(dir, p) {
 		if (p->type != TB_PROPERTY_TYPE_DIRECTORY)
 			continue;
 
@@ -1544,7 +1544,6 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)
 {
 	struct tb_property_dir *dir;
 	struct tb *tb = xd->tb;
-	bool update = false;
 	u32 *block = NULL;
 	u32 gen = 0;
 	int ret;
@@ -1570,7 +1569,8 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)
 	mutex_lock(&xd->lock);
 
 	/* Only accept newer generation properties */
-	if (xd->remote_properties && gen <= xd->remote_property_block_gen) {
+	if (xd->remote_properties && gen <= xd->remote_property_block_gen &&
+	    !xd->remote_properties_stale) {
 		ret = 0;
 		goto err_free_block;
 	}
@@ -1589,13 +1589,12 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)
 	}
 
 	/* Release the existing one */
-	if (xd->remote_properties) {
+	if (xd->remote_properties)
 		tb_property_free_dir(xd->remote_properties);
-		update = true;
-	}
 
 	xd->remote_properties = dir;
 	xd->remote_property_block_gen = gen;
+	xd->remote_properties_stale = false;
 
 	tb_xdomain_update_link_attributes(xd);
 
@@ -1608,7 +1607,7 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)
 	 * bus and let userspace know about it. If the device is already
 	 * registered, we notify the userspace that it has changed.
 	 */
-	if (!update) {
+	if (!device_is_registered(&xd->dev)) {
 		/*
 		 * Now disable lane 1 if bonding was not enabled. Do
 		 * this only if bonding was possible at the beginning
@@ -1643,7 +1642,7 @@ static int tb_xdomain_get_properties(struct tb_xdomain *xd)
 		kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
 	}
 
-	enumerate_services(xd);
+	queue_work(system_long_wq, &xd->services_work);
 	return 0;
 
 err_free_dir:
@@ -1842,6 +1841,24 @@ static void tb_xdomain_state_work(struct work_struct *work)
 			   msecs_to_jiffies(XDOMAIN_DEFAULT_TIMEOUT));
 }
 
+static void tb_xdomain_services_work(struct work_struct *work)
+{
+	struct tb_xdomain *xd = container_of(work, typeof(*xd), services_work);
+	struct tb_property_dir *dir;
+
+	/* The state work may replace the remote properties meanwhile */
+	scoped_guard(mutex, &xd->lock) {
+		if (xd->removing)
+			return;
+		dir = tb_property_copy_dir(xd->remote_properties);
+		if (!dir)
+			return;
+	}
+
+	enumerate_services(xd, dir);
+	tb_property_free_dir(dir);
+}
+
 static void tb_xdomain_properties_changed(struct work_struct *work)
 {
 	struct tb_xdomain *xd = container_of(work, typeof(*xd),
@@ -2040,7 +2057,13 @@ static void tb_xdomain_release(struct device *dev)
 
 static int __maybe_unused tb_xdomain_suspend(struct device *dev)
 {
-	stop_handshake(tb_to_xdomain(dev));
+	struct tb_xdomain *xd = tb_to_xdomain(dev);
+
+	stop_handshake(xd);
+	if (cancel_work_sync(&xd->services_work)) {
+		guard(mutex)(&xd->lock);
+		xd->remote_properties_stale = true;
+	}
 	return 0;
 }
 
@@ -2151,6 +2174,7 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
 	INIT_DELAYED_WORK(&xd->state_work, tb_xdomain_state_work);
 	INIT_DELAYED_WORK(&xd->properties_changed_work,
 			  tb_xdomain_properties_changed);
+	INIT_WORK(&xd->services_work, tb_xdomain_services_work);
 	atomic_set(&xd->ntunnels, 0);
 
 	xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL);
@@ -2265,6 +2289,7 @@ void tb_xdomain_unregister(struct tb_xdomain *xd)
 {
 	lockdep_assert_not_held(&xd->tb->lock);
 
+	cancel_work_sync(&xd->services_work);
 	device_for_each_child_reverse(&xd->dev, xd, unregister_service);
 
 	dev_info(&xd->dev, "host disconnected\n");
include/linux/thunderbolt.h +5 -0
index 57502da29080..48ae996a779c 100644
@@ -226,6 +226,8 @@ enum tb_link_width {
  * @local_property_block_len: Length of the @local_property_block in dwords
  * @remote_properties: Properties exported by the remote domain
  * @remote_property_block_gen: Generation of @remote_properties
+ * @remote_properties_stale: Accept the next properties even if
+ *			     @remote_property_block_gen has not changed
  * @state: Next XDomain discovery state to run
  * @state_work: Work used to run the next state
  * @state_retries: Number of retries remain for the state
@@ -233,6 +235,7 @@ enum tb_link_width {
  *			     our properties have changed
  * @properties_changed_retries: Number of times left to send properties
  *				changed notification
+ * @services_work: Work used to add and remove the services
  * @bonding_possible: True if lane bonding is possible on local side
  * @target_link_width: Target link width from the remote host
  * @ntunnels: Keeps track of how many tunnels go through this XDomain
@@ -275,11 +278,13 @@ struct tb_xdomain {
 	u32 local_property_block_len;
 	struct tb_property_dir *remote_properties;
 	u32 remote_property_block_gen;
+	bool remote_properties_stale;
 	int state;
 	struct delayed_work state_work;
 	int state_retries;
 	struct delayed_work properties_changed_work;
 	int properties_changed_retries;
+	struct work_struct services_work;
 	bool bonding_possible;
 	u8 target_link_width;
 	atomic_t ntunnels;
Signature · 1 line
2.50.1
#2 lore raw

PATCH 2/9 thunderbolt: Unregister XDomains when the domain is removed

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

tb_xdomain_remove() only stops the handshake and leaves the XDomain registered to the bus. Unregistering happens separately without tb->lock by tb_domain_unregister_unplugged_xdomains() but this is never called when the domain itself is removed. This may cause adding XDomains later on fail like:

sysfs: cannot create duplicate filename '/bus/thunderbolt/devices/0-1' thunderbolt 0-1: failed to add XDomain device

Fix this by first unbinding the service drivers in tb_domain_remove(), and then unregistering the XDomains once tb->lock has been released and the workqueue has been flushed (the work items unregister the unplugged XDomains too, so this avoids doing it twice).

Fixes a8937f35cf39 ("thunderbolt: Remove XDomain from the bus without holding tb->lock")
---
 drivers/thunderbolt/domain.c  | 34 ++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/xdomain.c |  2 +-
 include/linux/thunderbolt.h   |  3 +++
 3 files changed, 38 insertions(+), 1 deletion(-)
drivers/thunderbolt/domain.c +34 -0
index f9951d4311cb..61666e1a9b39 100644
@@ -78,6 +78,9 @@ static int tb_service_probe(struct device *dev)
 	struct tb_service *svc = tb_to_service(dev);
 	struct tb_service_driver *driver;
 
+	if (READ_ONCE(tb_service_parent(svc)->tb->removing))
+		return -ENODEV;
+
 	driver = container_of(dev->driver, struct tb_service_driver, driver);
 
 	return driver->probe(svc);
@@ -491,6 +494,29 @@ int tb_domain_add(struct tb *tb, bool reset)
 	return ret;
 }
 
+static int unbind_service(struct device *dev, void *data)
+{
+	if (tb_is_service(dev))
+		device_release_driver(dev);
+	return 0;
+}
+
+static int unbind_services(struct device *dev, void *data)
+{
+	struct tb_xdomain *xd;
+	const struct tb *tb = data;
+
+	xd = tb_to_xdomain(dev);
+	if (xd && xd->tb == tb) {
+		scoped_guard(mutex, &xd->lock)
+			xd->removing = true;
+		cancel_work_sync(&xd->services_work);
+		device_for_each_child_reverse(&xd->dev, NULL, unbind_service);
+	}
+
+	return 0;
+}
+
 /**
  * tb_domain_remove() - Removes and releases a domain
  * @tb: Domain to remove
@@ -500,6 +526,13 @@ int tb_domain_add(struct tb *tb, bool reset)
  */
 void tb_domain_remove(struct tb *tb)
 {
+	WRITE_ONCE(tb->removing, true);
+	/*
+	 * Unbind service drivers now so they can do their cleanup with
+	 * the working control channel.
+	 */
+	bus_for_each_dev(&tb_bus_type, NULL, tb, unbind_services);
+
 	mutex_lock(&tb->lock);
 	if (tb->cm_ops->stop)
 		tb->cm_ops->stop(tb);
@@ -508,6 +541,7 @@ void tb_domain_remove(struct tb *tb)
 	mutex_unlock(&tb->lock);
 
 	flush_workqueue(tb->wq);
+	tb_domain_unregister_unplugged_xdomains(tb);
 
 	if (tb->cm_ops->deinit)
 		tb->cm_ops->deinit(tb);
drivers/thunderbolt/xdomain.c +1 -1
index 55e17f4e35dc..fceaa177b3c1 100644
@@ -1848,7 +1848,7 @@ static void tb_xdomain_services_work(struct work_struct *work)
 
 	/* The state work may replace the remote properties meanwhile */
 	scoped_guard(mutex, &xd->lock) {
-		if (xd->removing)
+		if (READ_ONCE(xd->tb->removing) || xd->removing)
 			return;
 		dir = tb_property_copy_dir(xd->remote_properties);
 		if (!dir)
include/linux/thunderbolt.h +3 -0
index 48ae996a779c..03f315934e44 100644
@@ -78,6 +78,8 @@ enum tb_security_level {
  * @index: Linux assigned domain number
  * @security_level: Current security level
  * @nboot_acl: Number of boot ACLs the domain supports
+ * @removing: Domain is about to be removed, no new XDomain services are
+ *	      allowed to be registered
  * @privdata: Private connection manager specific data
  */
 struct tb {
@@ -91,6 +93,7 @@ struct tb {
 	int index;
 	enum tb_security_level security_level;
 	size_t nboot_acl;
+	bool removing;
 	unsigned long privdata[];
 };
 
Signature · 1 line
2.50.1
#3 lore raw

PATCH 3/9 thunderbolt: stream: Keep better track of the HopIDs

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

Currently if a HopID is already taken and we try to allocate that with previous HopID already set like this (HopID 10 is already allocated)

  # echo 9 > in_hopid
  # echo 10 > in_hopid

In the second echo we release 9 but since allocation of 10 fails we return -EBUSY and leave 9 as ->in_hopid. If at this point the stream is removed with rmdir we release 9 again which results WARN() from ida_free().

Make this work better so that we keep track of what we actually have allocated and keep the configured value as separate.

---
 drivers/thunderbolt/stream.c | 77 +++++++++++++++++++++++++-----------
 1 file changed, 53 insertions(+), 24 deletions(-)
drivers/thunderbolt/stream.c +53 -24
index c9e1987a6924..2b73f585ccff 100644
@@ -128,6 +128,8 @@ struct tbstream_ring {
  * @index: Unique identifier for the character device
  * @in_hopid: In HopID
  * @out_hopid: Out HopID
+ * @in_hopid_alloc: Allocated @in_hopid, %0 if not allocated
+ * @out_hopid_alloc: Allocated @out_hopid, %0 if not allocated
  * @ring_size: Size of the rings
  * @throttling: Interrupt throttling rate in ns
  * @busy_poll: Instead of interrupts, busy poll the rings
@@ -145,6 +147,11 @@ struct tbstream_ring {
  * @close_received is used on write side to notify the writer that the
  * other side sent CLOSE. @closed on the other hand is used on the read
  * side to make read(2) return EOF to the caller.
+ *
+ * @in_hopid and @out_hopid are the values configured by the user and
+ * stay (except %-1 which will be replaced by an automatically allocated
+ * HopID). @in_hopid_alloc and @out_hopid_alloc are the currently
+ * allocated values based on those.
  */
 struct tbstream_dev {
 	struct config_group group;
@@ -154,6 +161,8 @@ struct tbstream_dev {
 	int index;
 	int in_hopid;
 	int out_hopid;
+	int in_hopid_alloc;
+	int out_hopid_alloc;
 	unsigned int ring_size;
 	unsigned int throttling;
 	bool busy_poll;
@@ -308,10 +317,10 @@ static void tbstream_dev_release(struct kref *kref)
 	if (sdev->stream) {
 		struct tb_xdomain *xd = tbstream_dev_xdomain(sdev);
 
-		if (sdev->out_hopid > 0)
-			tb_xdomain_release_out_hopid(xd, sdev->out_hopid);
-		if (sdev->in_hopid > 0)
-			tb_xdomain_release_in_hopid(xd, sdev->in_hopid);
+		if (sdev->out_hopid_alloc)
+			tb_xdomain_release_out_hopid(xd, sdev->out_hopid_alloc);
+		if (sdev->in_hopid_alloc)
+			tb_xdomain_release_in_hopid(xd, sdev->in_hopid_alloc);
 
 		tbstream_put(sdev->stream);
 	}
@@ -344,7 +353,7 @@ static inline int tbstream_dev_valid(const struct tbstream_dev *sdev)
 
 	if (!tbstream_valid(stream))
 		return -ENXIO;
-	if (sdev->in_hopid <= 0 || sdev->out_hopid <= 0)
+	if (!sdev->in_hopid_alloc || !sdev->out_hopid_alloc)
 		return -EINVAL;
 	return 0;
 }
@@ -660,10 +669,10 @@ static int tbstream_dev_start(struct tbstream_dev *sdev)
 	}
 	sdev->rx_ring.ring = ring;
 
-	ret = tb_xdomain_enable_paths(xd, sdev->out_hopid,
-				     sdev->tx_ring.ring->hop,
-				     sdev->in_hopid,
-				     sdev->rx_ring.ring->hop);
+	ret = tb_xdomain_enable_paths(xd, sdev->out_hopid_alloc,
+				      sdev->tx_ring.ring->hop,
+				      sdev->in_hopid_alloc,
+				      sdev->rx_ring.ring->hop);
 	if (ret)
 		goto err_free_rx;
 
@@ -736,9 +745,9 @@ static void tbstream_dev_stop(struct tbstream_dev *sdev)
 
 	xd = tbstream_dev_xdomain(sdev);
 	if (xd) {
-		tb_xdomain_disable_paths(xd, sdev->out_hopid,
+		tb_xdomain_disable_paths(xd, sdev->out_hopid_alloc,
 					 sdev->tx_ring.ring->hop,
-					 sdev->in_hopid,
+					 sdev->in_hopid_alloc,
 					 sdev->rx_ring.ring->hop);
 	}
 
@@ -1331,7 +1340,8 @@ static int tbstream_dev_update_properties(struct tbstream_dev *sdev)
 
 	ret = service_update_properties(stream->svc,
 					config_item_name(&sdev->group.cg_item),
-					sdev->in_hopid, sdev->out_hopid);
+					sdev->in_hopid_alloc,
+					sdev->out_hopid_alloc);
 	if (!ret)
 		tb_service_properties_changed(stream->svc);
 
@@ -1344,9 +1354,15 @@ static int tbstream_dev_alloc_in_hopid(struct tbstream_dev *sdev, int hopid)
 	struct tb_xdomain *xd = tbstream_dev_xdomain(sdev);
 	int ret;
 
-	if (sdev->in_hopid > 0 && sdev->in_hopid != hopid)
-		tb_xdomain_release_in_hopid(xd, sdev->in_hopid);
+	/* Already allocated */
+	if (hopid > 0 && hopid == sdev->in_hopid_alloc)
+		return 0;
+	if (hopid < 0 && sdev->in_hopid_alloc)
+		return 0;
 	if (!hopid) {
+		if (sdev->in_hopid_alloc)
+			tb_xdomain_release_in_hopid(xd, sdev->in_hopid_alloc);
+		sdev->in_hopid_alloc = 0;
 		sdev->in_hopid = hopid;
 		return 0;
 	}
@@ -1361,7 +1377,9 @@ static int tbstream_dev_alloc_in_hopid(struct tbstream_dev *sdev, int hopid)
 		tb_xdomain_release_in_hopid(xd, ret);
 		return -EBUSY;
 	}
-	sdev->in_hopid = ret;
+	if (sdev->in_hopid_alloc)
+		tb_xdomain_release_in_hopid(xd, sdev->in_hopid_alloc);
+	sdev->in_hopid_alloc = sdev->in_hopid = ret;
 	return 0;
 }
 
@@ -1370,9 +1388,14 @@ static int tbstream_dev_alloc_out_hopid(struct tbstream_dev *sdev, int hopid)
 	struct tb_xdomain *xd = tbstream_dev_xdomain(sdev);
 	int ret;
 
-	if (sdev->out_hopid > 0 && sdev->out_hopid != hopid)
-		tb_xdomain_release_out_hopid(xd, sdev->out_hopid);
+	if (hopid > 0 && hopid == sdev->out_hopid_alloc)
+		return 0;
+	if (hopid < 0 && sdev->out_hopid_alloc)
+		return 0;
 	if (!hopid) {
+		if (sdev->out_hopid_alloc)
+			tb_xdomain_release_out_hopid(xd, sdev->out_hopid_alloc);
+		sdev->out_hopid_alloc = 0;
 		sdev->out_hopid = hopid;
 		return 0;
 	}
@@ -1383,7 +1406,9 @@ static int tbstream_dev_alloc_out_hopid(struct tbstream_dev *sdev, int hopid)
 		tb_xdomain_release_out_hopid(xd, ret);
 		return -EBUSY;
 	}
-	sdev->out_hopid = ret;
+	if (sdev->out_hopid_alloc)
+		tb_xdomain_release_out_hopid(xd, sdev->out_hopid_alloc);
+	sdev->out_hopid_alloc = sdev->out_hopid = ret;
 	return 0;
 }
 
@@ -1597,8 +1622,8 @@ tbstream_dev_attach_stream(struct tbstream_dev *sdev, struct tbstream_group *sg)
 			tbstream_dev_alloc_out_hopid(sdev, sdev->out_hopid);
 	}
 
-	service_update_properties(stream->svc, name, sdev->in_hopid,
-				  sdev->out_hopid);
+	service_update_properties(stream->svc, name, sdev->in_hopid_alloc,
+				  sdev->out_hopid_alloc);
 	tb_service_properties_changed(stream->svc);
 
 	/* Notify any openerers that the stream is now attached */
@@ -1617,10 +1642,14 @@ static void tbstream_dev_detach_stream(struct tbstream_dev *sdev)
 			return;
 		sdev->stream = NULL;
 		xd = tb_service_parent(stream->svc);
-		if (sdev->out_hopid > 0)
-			tb_xdomain_release_out_hopid(xd, sdev->out_hopid);
-		if (sdev->in_hopid > 0)
-			tb_xdomain_release_in_hopid(xd, sdev->in_hopid);
+		if (sdev->out_hopid_alloc) {
+			tb_xdomain_release_out_hopid(xd, sdev->out_hopid_alloc);
+			sdev->out_hopid_alloc = 0;
+		}
+		if (sdev->in_hopid_alloc) {
+			tb_xdomain_release_in_hopid(xd, sdev->in_hopid_alloc);
+			sdev->in_hopid_alloc = 0;
+		}
 	}
 
 	service_update_properties(stream->svc, name, 0, 0);
Signature · 1 line
2.50.1
#9 lore raw

PATCH 9/9 Documentation: thunderbolt: Document USB4STREAM coupling

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

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

---
 Documentation/admin-guide/thunderbolt.rst | 119 ++++++++++++++++++++++
 1 file changed, 119 insertions(+)
Documentation/admin-guide/thunderbolt.rst +119 -0
index ff25fe853706..3b71feaa1efa 100644
@@ -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
Signature · 1 line
2.50.1
#6 lore raw

PATCH 6/9 thunderbolt: Add KUnit tests for lane to lane DMA tunnels

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

This adds KUnit tests for the lane to lane DMA tunnels we just started to support.

---
 drivers/thunderbolt/test.c | 408 +++++++++++++++++++++++++++++++++++++
 1 file changed, 408 insertions(+)
drivers/thunderbolt/test.c +408 -0
index 0321408fe91c..b36bbe8bd7c1 100644
@@ -2154,6 +2154,239 @@ static void tb_test_tunnel_dma_match(struct kunit *test)
 #undef MATCH
 }
 
+static void tb_test_tunnel_dma_lane2lane(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port;
+	struct tb_tunnel *tunnel;
+	struct tb_switch *host;
+
+	/*
+	 * Create DMA tunnel between two hosts that are connected to lane
+	 * adapters 1 and 3 of this host.
+	 *
+	 *   [Host 2]                     [Host 3]
+	 * ............ Domain border ............
+	 *      |                             |
+	 *    1 v In HopID 8 -> Out HopID 8   |
+	 *    1 ^ Out HopID 8 <- In HopID 8   v 3
+	 *              [Host 1]
+	 */
+	host = alloc_host(test);
+	src_port = &host->ports[1];
+	dst_port = &host->ports[3];
+
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, 8, dst_port, 8, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DMA);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, src_port);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->dst_port, dst_port);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, 2);
+	/* Path from the second host to the first one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[0]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].in_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 8);
+	KUNIT_EXPECT_TRUE(test, tunnel->paths[0]->hops[0].ingress_fc_enable);
+	KUNIT_EXPECT_TRUE(test, tunnel->paths[0]->hops[0].egress_fc_enable);
+	/* Path from the first host to the second one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[1]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].in_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].out_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].next_hop_index, 8);
+	KUNIT_EXPECT_TRUE(test, tunnel->paths[1]->hops[0].ingress_fc_enable);
+	KUNIT_EXPECT_TRUE(test, tunnel->paths[1]->hops[0].egress_fc_enable);
+
+	tb_tunnel_put(tunnel);
+}
+
+static void tb_test_tunnel_dma_lane2lane_one_way(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port;
+	struct tb_tunnel *tunnel;
+	struct tb_switch *host;
+
+	/*
+	 * Create uni-directional DMA tunnels between two hosts that are
+	 * connected to lane adapters 1 and 3 of this host.
+	 *
+	 *   [Host 2]                     [Host 3]
+	 * ............ Domain border ............
+	 *      |                             |
+	 *    1 v In HopID 8 -> Out HopID 8   v 3
+	 *              [Host 1]
+	 */
+	host = alloc_host(test);
+	src_port = &host->ports[1];
+	dst_port = &host->ports[3];
+
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, -1, dst_port, -1, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, 1);
+	KUNIT_ASSERT_EQ(test, tunnel->paths[0]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].in_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 8);
+
+	tb_tunnel_put(tunnel);
+
+	/* Now the other way around */
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, -1, 8, dst_port, 8, -1);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, 1);
+	KUNIT_ASSERT_EQ(test, tunnel->paths[0]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].in_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 8);
+
+	tb_tunnel_put(tunnel);
+}
+
+static void tb_test_tunnel_dma_lane2lane_chain(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port;
+	struct tb_switch *host, *dev;
+	struct tb_tunnel *tunnel;
+
+	/*
+	 * Create DMA tunnel between a host connected to lane adapter 1 of
+	 * this host and another one that is behind a device router.
+	 *
+	 *   [Host 2]
+	 * ............ Domain border
+	 *      |
+	 *    1 | In and Out HopID 8
+	 *  [Host 1]
+	 *      3 \
+	 *        1 \
+	 *      [Device #1]
+	 *          3 | In and Out HopID 8
+	 *            v
+	 * ............ Domain border
+	 *            |
+	 *         [Host 3]
+	 */
+	host = alloc_host(test);
+	dev = alloc_dev_default(test, host, 0x3, true);
+
+	src_port = &host->ports[1];
+	dst_port = &dev->ports[3];
+
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, 8, dst_port, 8, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, 2);
+	/* Path from the second host to the first one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[0]->path_length, 2);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].in_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port,
+			    &dev->ports[1]);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[1].in_port,
+			    &host->ports[3]);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[1].out_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[1].next_hop_index, 8);
+	/* Path from the first host to the second one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[1]->path_length, 2);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].in_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].out_port,
+			    &host->ports[3]);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[1].in_port,
+			    &dev->ports[1]);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[1].out_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[1].next_hop_index, 8);
+
+	tb_tunnel_put(tunnel);
+}
+
+static void tb_test_tunnel_dma_lane2lane_hub(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port;
+	struct tb_switch *host, *hub;
+	struct tb_tunnel *tunnel;
+
+	/*
+	 * Create DMA tunnel between two hosts that are both connected to a
+	 * hub below this host. Now the path goes directly from one downstream
+	 * port of the hub to the other one and does not reach this host at
+	 * all.
+	 *
+	 *              [Host 1]
+	 *                  1 |
+	 *                  1 |
+	 *               [Hub #1]
+	 *   3 v In HopID 8 -> Out HopID 8 v 5
+	 *   3 ^ Out HopID 8 <- In HopID 8 ^ 5
+	 * ............ Domain border ............
+	 *     |                              |
+	 *  [Host 2]                      [Host 3]
+	 */
+	host = alloc_host(test);
+	hub = alloc_dev_default(test, host, 0x1, true);
+
+	src_port = &hub->ports[3];
+	dst_port = &hub->ports[5];
+
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, 8, dst_port, 8, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, 2);
+	/* Path from the second host to the first one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[0]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].in_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 8);
+	/* Path from the first host to the second one */
+	KUNIT_ASSERT_EQ(test, tunnel->paths[1]->path_length, 1);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].in_port, src_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].in_hop_index, 8);
+	KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].out_port, dst_port);
+	KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].next_hop_index, 8);
+
+	tb_tunnel_put(tunnel);
+}
+
+static void tb_test_tunnel_dma_lane2lane_match(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port, *nhi;
+	struct tb_tunnel *tunnel;
+	struct tb_switch *host;
+
+	host = alloc_host(test);
+	nhi = &host->ports[7];
+	src_port = &host->ports[1];
+	dst_port = &host->ports[3];
+
+	/*
+	 * Use a different HopID for each end and direction, which is what
+	 * happens when there are already other tunnels going through, so
+	 * that mixing them up gets caught below.
+	 */
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, 9, dst_port, 10, 11);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+
+#define MATCH(src, src_in, src_out, dst, dst_in, dst_out) \
+	tb_tunnel_match_dma(tunnel, src, src_in, src_out, dst, dst_in, dst_out)
+
+	KUNIT_EXPECT_TRUE(test, MATCH(src_port, 8, 9, dst_port, 10, 11));
+	KUNIT_EXPECT_TRUE(test, MATCH(src_port, 8, -1, NULL, -1, -1));
+	KUNIT_EXPECT_TRUE(test, MATCH(dst_port, 10, -1, NULL, -1, -1));
+	KUNIT_EXPECT_TRUE(test, MATCH(src_port, -1, -1, dst_port, -1, -1));
+	/* The HopIDs of the two ends cannot be mixed up */
+	KUNIT_EXPECT_FALSE(test, MATCH(src_port, 10, 11, dst_port, 8, 9));
+	KUNIT_EXPECT_FALSE(test, MATCH(src_port, 9, -1, NULL, -1, -1));
+	KUNIT_EXPECT_FALSE(test, MATCH(dst_port, -1, 10, NULL, -1, -1));
+	/* Neither end is at the host interface */
+	KUNIT_EXPECT_FALSE(test, MATCH(nhi, -1, -1, NULL, -1, -1));
+
+	tb_tunnel_put(tunnel);
+
+#undef MATCH
+}
+
 static void tb_test_credit_alloc_legacy_not_bonded(struct kunit *test)
 {
 	struct tb_switch *host, *dev;
@@ -3382,6 +3615,174 @@ static void tb_test_credit_alloc_shared_hop(struct kunit *test)
 	usb4_switch_free_credit_pools(host);
 }
 
+/* Same as what tb_port_configure_xdomain() does for the credit pools */
+static void tb_test_connect_xdomain(struct kunit *test, struct tb_port *port)
+{
+	port->xdomain = kunit_kzalloc(test, sizeof(*port->xdomain), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, port->xdomain);
+	usb4_port_update_credit_pools(port);
+}
+
+static unsigned int tb_test_dma_credits_used(const struct tb_port *port)
+{
+	return usb4_credit_pool_used(&port->credit_pool[USB4_CREDIT_POOL_COMMON]);
+}
+
+static void tb_test_credit_alloc_dma_lane2lane(struct kunit *test)
+{
+	struct tb_port *src_port, *dst_port;
+	struct tb_switch *host, *dev;
+	struct tb_tunnel *tunnel;
+	struct tb_path *path;
+
+	host = alloc_host_usb4(test);
+	dev = alloc_dev_usb4(test, host, 0x3, true);
+
+	KUNIT_ASSERT_EQ(test, usb4_switch_alloc_credit_pools(host), 0);
+	KUNIT_ASSERT_EQ(test, usb4_switch_alloc_credit_pools(dev), 0);
+
+	src_port = &host->ports[1];
+	dst_port = &dev->ports[3];
+
+	tb_test_connect_xdomain(test, src_port);
+	tb_test_connect_xdomain(test, dst_port);
+
+	tunnel = tb_tunnel_alloc_dma(NULL, src_port, 8, 8, dst_port, 8, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, (size_t)2);
+
+	/*
+	 * Both directions are treated the same way. The first hop is the
+	 * lane adapter facing the remote host so all its buffers are
+	 * available for DMA, the rest are allocated from the intermediate
+	 * hops. Both paths end to a lane adapter so flow control is
+	 * enabled on egress of every hop.
+	 */
+	path = tunnel->paths[0];
+	KUNIT_ASSERT_EQ(test, path->path_length, 2);
+	tb_test_check_path_fc(test, path, true);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 14U);
+
+	path = tunnel->paths[1];
+	KUNIT_ASSERT_EQ(test, path->path_length, 2);
+	tb_test_check_path_fc(test, path, true);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 14U);
+
+	tb_tunnel_put(tunnel);
+
+	usb4_switch_free_credit_pools(dev);
+	usb4_switch_free_credit_pools(host);
+}
+
+static void tb_test_credit_alloc_dma_lane2lane_multiple(struct kunit *test)
+{
+	struct tb_tunnel *tunnel1, *tunnel2, *tunnel3, *tunnel4, *tunnel5;
+	struct tb_port *src_port, *dst_port;
+	struct tb_tunnel *tunnel6;
+	struct tb_switch *host;
+	struct tb_path *path;
+
+	host = alloc_host_usb4(test);
+
+	KUNIT_ASSERT_EQ(test, usb4_switch_alloc_credit_pools(host), 0);
+
+	src_port = &host->ports[1];
+	dst_port = &host->ports[3];
+
+	tb_test_connect_xdomain(test, src_port);
+	tb_test_connect_xdomain(test, dst_port);
+
+	/*
+	 * Couple the two hosts connected to lane adapters 1 and 3 several
+	 * times, each coupling using different HopIDs.
+	 *
+	 * Neither lane adapter tunnels other protocols so all their
+	 * buffers except the ones reserved for control traffic stay in
+	 * the common pool:
+	 *
+	 *   60 - 2 = 58
+	 *
+	 * Each coupling takes 14 of those from both adapters, so the first
+	 * four get what they asked for, the fifth gets the remaining 2 and
+	 * after that we run out of buffers.
+	 */
+	tunnel1 = tb_tunnel_alloc_dma(NULL, src_port, 8, 8, dst_port, 8, 8);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel1);
+	KUNIT_ASSERT_EQ(test, tunnel1->npaths, (size_t)2);
+
+	path = tunnel1->paths[0];
+	KUNIT_ASSERT_EQ(test, path->path_length, 1);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+
+	path = tunnel1->paths[1];
+	KUNIT_ASSERT_EQ(test, path->path_length, 1);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+
+	tunnel2 = tb_tunnel_alloc_dma(NULL, src_port, 9, 9, dst_port, 9, 9);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel2);
+	tunnel3 = tb_tunnel_alloc_dma(NULL, src_port, 10, 10, dst_port, 10, 10);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel3);
+	tunnel4 = tb_tunnel_alloc_dma(NULL, src_port, 11, 11, dst_port, 11, 11);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel4);
+
+	path = tunnel4->paths[0];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+	path = tunnel4->paths[1];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+
+	/* Both adapters have now handed out 4 * 14 = 56 of their 58 */
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(src_port), 56U);
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(dst_port), 56U);
+
+	/* The fifth one has to make do with what is left */
+	tunnel5 = tb_tunnel_alloc_dma(NULL, src_port, 12, 12, dst_port, 12, 12);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel5);
+
+	path = tunnel5->paths[0];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 2U);
+	path = tunnel5->paths[1];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 2U);
+
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(src_port), 58U);
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(dst_port), 58U);
+
+	/* And the sixth one no longer fits */
+	tunnel6 = tb_tunnel_alloc_dma(NULL, src_port, 13, 13, dst_port, 13, 13);
+	KUNIT_ASSERT_NULL(test, tunnel6);
+
+	/* Releasing the first one makes room for another */
+	tb_tunnel_put(tunnel1);
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(src_port), 44U);
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(dst_port), 44U);
+
+	tunnel1 = tb_tunnel_alloc_dma(NULL, src_port, 13, 13, dst_port, 13, 13);
+	KUNIT_ASSERT_NOT_NULL(test, tunnel1);
+
+	path = tunnel1->paths[0];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+	path = tunnel1->paths[1];
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 14U);
+
+	tb_tunnel_put(tunnel5);
+	tb_tunnel_put(tunnel4);
+	tb_tunnel_put(tunnel3);
+	tb_tunnel_put(tunnel2);
+	tb_tunnel_put(tunnel1);
+
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(src_port), 0U);
+	KUNIT_EXPECT_EQ(test, tb_test_dma_credits_used(dst_port), 0U);
+
+	usb4_switch_free_credit_pools(host);
+}
+
 static struct tb_tunnel *TB_TEST_PCIE_TUNNEL(struct kunit *test,
 			struct tb_switch *host, struct tb_switch *dev)
 {
@@ -4147,6 +4548,11 @@ static struct kunit_case tb_test_cases[] = {
 	KUNIT_CASE(tb_test_tunnel_dma_tx),
 	KUNIT_CASE(tb_test_tunnel_dma_chain),
 	KUNIT_CASE(tb_test_tunnel_dma_match),
+	KUNIT_CASE(tb_test_tunnel_dma_lane2lane),
+	KUNIT_CASE(tb_test_tunnel_dma_lane2lane_one_way),
+	KUNIT_CASE(tb_test_tunnel_dma_lane2lane_chain),
+	KUNIT_CASE(tb_test_tunnel_dma_lane2lane_hub),
+	KUNIT_CASE(tb_test_tunnel_dma_lane2lane_match),
 	KUNIT_CASE(tb_test_credit_alloc_legacy_not_bonded),
 	KUNIT_CASE(tb_test_credit_alloc_legacy_bonded),
 	KUNIT_CASE(tb_test_credit_alloc_pcie),
@@ -4166,6 +4572,8 @@ static struct kunit_case tb_test_cases[] = {
 	KUNIT_CASE(tb_test_credit_alloc_dma_shared_mixed),
 	KUNIT_CASE(tb_test_credit_alloc_dma_shared_no_credit_allocation),
 	KUNIT_CASE(tb_test_credit_alloc_shared_hop),
+	KUNIT_CASE(tb_test_credit_alloc_dma_lane2lane),
+	KUNIT_CASE(tb_test_credit_alloc_dma_lane2lane_multiple),
 	KUNIT_CASE(tb_test_credit_alloc_all),
 	KUNIT_CASE(tb_test_property_parse),
 	KUNIT_CASE(tb_test_property_format),
Signature · 1 line
2.50.1
#5 lore raw

PATCH 5/9 thunderbolt: Allow DMA tunnel also between two lane adapters

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

At the moment we only support DMA tunnels between two hosts so that it ends up or starts from the host interface adapter. This is the typical use-case. However, it is entirely possible to make a DMA tunnel from one lane adapter to another so acting as "passthrough" instead of ending or starting the traffic.

This modifies the existing DMA tunneling functions to support lane adapter to lane adapter tunnels as well.

---
 drivers/thunderbolt/tb.c     |  11 +--
 drivers/thunderbolt/test.c   | 150 ++++++++++++++++--------------
 drivers/thunderbolt/tunnel.c | 171 +++++++++++++++++++++--------------
 drivers/thunderbolt/tunnel.h |  14 +--
 4 files changed, 194 insertions(+), 152 deletions(-)
drivers/thunderbolt/tb.c +5 -6
index 10fca534ff78..c7a009a62411 100644
@@ -2393,8 +2393,8 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
 	 */
 	tb_disable_clx(sw);
 
-	tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path,
-				     transmit_ring, receive_path, receive_ring);
+	tunnel = tb_tunnel_alloc_dma(tb, nhi_port, transmit_ring, receive_ring,
+				     dst_port, receive_path, transmit_path);
 	if (!tunnel) {
 		ret = -ENOMEM;
 		goto err_clx;
@@ -2437,11 +2437,10 @@ static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
 	list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
 		if (!tb_tunnel_is_dma(tunnel))
 			continue;
-		if (tunnel->src_port != nhi_port || tunnel->dst_port != dst_port)
-			continue;
 
-		if (tb_tunnel_match_dma(tunnel, transmit_path, transmit_ring,
-					receive_path, receive_ring))
+		if (tb_tunnel_match_dma(tunnel, nhi_port, transmit_ring,
+					receive_ring, dst_port, receive_path,
+					transmit_path))
 			tb_deactivate_and_free_tunnel(tunnel);
 	}
 
drivers/thunderbolt/test.c +80 -70

349 lines not on this page · raw message

drivers/thunderbolt/tunnel.c +101 -70

233 lines not on this page · raw message

drivers/thunderbolt/tunnel.h +8 -6
index 35d026c5bc96..5dedf742b14d 100644
@@ -119,12 +119,14 @@ struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
 				     struct tb_port *out, int link_nr,
 				     int max_up, int max_down,
 				     void (*callback)(struct tb_tunnel *));
-struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
-				      struct tb_port *dst, int transmit_path,
-				      int transmit_ring, int receive_path,
-				      int receive_ring);
-bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
-			 int transmit_ring, int receive_path, int receive_ring);
+struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *src,
+				      int src_in_hopid, int src_out_hopid,
+				      struct tb_port *dst, int dst_in_hopid,
+				      int dst_out_hopid);
+bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel,
+			 const struct tb_port *src, int src_in_hopid,
+			 int src_out_hopid, const struct tb_port *dst,
+			 int dst_in_hopid, int dst_out_hopid);
 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
 				       struct tb_port *down, int max_up,
Signature · 1 line
2.50.1
#8 lore raw

PATCH 8/9 thunderbolt: stream: Introduce USB4STREAM coupling

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

When there are multiple hosts involved like host1 <-> host2 <-> host3, and there is need to forward one stream to another through the middle host (host2), the simplest way is to run something like:

  # dd if=/dev/tbstream0 of=/dev/tbstream1

However, that involves copying the frames to the userspace and back, and this is just for one direction (in case of tool such as dd, a custom application may do this in both directions simultaneously).

We can avoid all this by making a tunnel directly between the leaf hosts. This does not involve the middle host CPU at all on the data path. This is called USB4STREAM coupling. It is configured on the middle host via ConfigFS as before but it will not result a /dev/tbstreamX to be created:

  # cd /sys/kernel/config/thunderbolt/stream/coupling
  # mkdir -p 0-1.0_0-3.0/data
  # cd 0-1.0_0-3.0/data
  # echo -1 > 0-1.0/in_hopid
  # echo -1 > 0-1.0/out_hopid
  # echo -1 > 0-3.0/in_hopid
  # echo -1 > 0-3.0/out_hopid

Once the XDomains are connected this will create a DMA tunnel directly between XDomains 0-1 and 0-3 using the HopIDs configured above. Then the hosts at both ends can use their stream exactly as before.

To get rid of the coupling run rmdir similarly to regular streams:

  # cd /sys/kernel/config/thunderbolt/stream/coupling
  # rmdir -p 0-1.0_0-3.0/data
---
 .../ABI/testing/configfs-thunderbolt_stream   |  82 ++
 drivers/thunderbolt/stream.c                  | 888 +++++++++++++++++-
 2 files changed, 960 insertions(+), 10 deletions(-)
Documentation/ABI/testing/configfs-thunderbolt_stream +82 -0
index cbecb3d8db50..d4af0596b602 100644
@@ -96,3 +96,85 @@ Contact:	Mika Westerberg <[email protected]>
 Description:
 		Interrupt throttling rate in ns. Lower values can give
 		better latency. The default is 8192 ns.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		Fixed directory for coupled streams. If this host is
+		connected to two other hosts, for example A <-> B <-> C
+		where B is this host, then B can forward streams between A
+		and C through the routers in its domain.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling/<pair>
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		Configuration group for a pair of stream services that are
+		coupled together. The <pair> name consists of the two
+		service names separated by "_", for instance
+		"0-1.0_0-3.0". The two must be different and belong to the
+		same domain. The order does not matter and the same two
+		services can be paired only once.
+
+		A service can be part of several pairs, so streams of one
+		host can be forwarded to more than one other host.
+
+		Like with the non-coupled streams the group can be created
+		before either of the two hosts is connected. The couplings
+		below it are established once both of them show up.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling/<pair>/$name
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		Creates a new coupled stream with $name. The stream is
+		established once in_hopid and out_hopid of both sides
+		have been filled in. If the two hosts announce the
+		HopIDs of a stream with this name they are filled in
+		automatically. Likewise the HopIDs of each side are
+		announced to the host on that side, so it is enough to
+		configure this end.
+
+		There will be no /dev/tbstreamX device for coupled
+		streams.
+
+		Removing the directory tears the tunnel down and this is
+		also the only way to get rid of a coupling.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling/<pair>/$name/<xdomain>.<service>
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		Holds the HopIDs of one side of the coupling. Both sides are
+		always present, named after the two stream services of
+		<pair>.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling/<pair>/$name/<xdomain>.<service>/in_hopid
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		In HopID the host on this side of the coupling uses to send
+		packets to this host. It needs to match the out_hopid that
+		host has configured for the stream, and if that host
+		announces it in its XDomain properties it is picked up from
+		there. You can pass -1 for automatic allocation.
+
+		Once both HopIDs are filled in for both services the
+		tunnel will be established. Writing 0 to any of the
+		attributes will tear it down.
+
+What:		/sys/kernel/config/thunderbolt/stream/coupling/<pair>/$name/<xdomain>.<service>/out_hopid
+Date:		Feb 2027
+KernelVersion:	v7.5
+Contact:	Mika Westerberg <[email protected]>
+Description:
+		Out HopID this host uses to send packets to the host on
+		this side of the coupling. It needs to match the in_hopid
+		that host has configured for the stream. Otherwise this
+		behaves like in_hopid above.
drivers/thunderbolt/stream.c +878 -10

954 lines not on this page · raw message

Signature · 1 line
2.50.1
#7 lore raw

PATCH 7/9 thunderbolt: Add tb_xdomains_enable_paths() and tb_xdomains_disable_paths()

In reply to Mika Westerberg

From: "Mika Westerberg (Intel)" <[email protected]>

A DMA tunnel does not need to end at the host interface. Both ends can be lane adapters as well, in which case the router forwards the packets from one remote host to the other. Generalize the DMA path handling to cover this, and provide two new API functions: tb_xdomains_enable_paths() and tb_xdomains_disable_paths() that can be used to create DMA tunnels between two XDomains.

While there replace the only place where -ENOTSUPP is returned over -EOPNOTSUPP.

---
 drivers/thunderbolt/domain.c  |  70 +++++++++-------
 drivers/thunderbolt/icm.c     |  49 +++++++----
 drivers/thunderbolt/tb.c      | 149 +++++++++++++++++++++-------------
 drivers/thunderbolt/tb.h      |  28 ++++---
 drivers/thunderbolt/xdomain.c | 110 +++++++++++++++++++++++--
 include/linux/thunderbolt.h   |   6 ++
 6 files changed, 291 insertions(+), 121 deletions(-)
drivers/thunderbolt/domain.c +40 -30
index 61666e1a9b39..d4094036837e 100644
@@ -797,59 +797,69 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb)
 /**
  * tb_domain_approve_xdomain_paths() - Enable DMA paths for XDomain
  * @tb: Domain enabling the DMA paths
- * @xd: XDomain DMA paths are created to
- * @transmit_path: HopID we are using to send out packets
- * @transmit_ring: DMA ring used to send out packets
- * @receive_path: HopID the other end is using to send packets to us
- * @receive_ring: DMA ring used to receive packets from @receive_path
+ * @xd_a: XDomain DMA paths are created to
+ * @a_in_hopid: HopID @xd_a is using to send packets to us
+ * @a_out_hopid: HopID we are using to send packets to @xd_a
+ * @xd_b: The other end of the DMA paths or %NULL if it is the host
+ *	  interface. In the latter case @b_in_hopid and @b_out_hopid are
+ *	  the DMA ring numbers used to send and receive the packets.
+ * @b_in_hopid: HopID @xd_b is using to send packets to us
+ * @b_out_hopid: HopID we are using to send packets to @xd_b
  *
- * Calls connection manager specific method to enable DMA paths to the
- * XDomain in question.
+ * Calls connection manager specific method to enable DMA paths between the
+ * two ends. Passing %-1 as HopID of a direction leaves that direction out.
  *
  * Return:
  * * %0 - On success.
- * * %-ENOTSUPP - If the connection manager implementation does not support
- *   XDomains.
+ * * %-EOPNOTSUPP - If the connection manager implementation does not support
+ *		    XDomains.
  * * Negative errno - An error occurred.
  */
-int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
-				    int transmit_path, int transmit_ring,
-				    int receive_path, int receive_ring)
+int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd_a,
+				    int a_in_hopid, int a_out_hopid,
+				    struct tb_xdomain *xd_b, int b_in_hopid,
+				    int b_out_hopid)
 {
 	if (!tb->cm_ops->approve_xdomain_paths)
-		return -ENOTSUPP;
+		return -EOPNOTSUPP;
 
-	return tb->cm_ops->approve_xdomain_paths(tb, xd, transmit_path,
-			transmit_ring, receive_path, receive_ring);
+	return tb->cm_ops->approve_xdomain_paths(tb, xd_a, a_in_hopid,
+						 a_out_hopid, xd_b, b_in_hopid,
+						 b_out_hopid);
 }
 
 /**
  * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain
  * @tb: Domain disabling the DMA paths
- * @xd: XDomain whose DMA paths are disconnected
- * @transmit_path: HopID we are using to send out packets
- * @transmit_ring: DMA ring used to send out packets
- * @receive_path: HopID the other end is using to send packets to us
- * @receive_ring: DMA ring used to receive packets from @receive_path
+ * @xd_a: XDomain whose DMA paths are disconnected
+ * @a_in_hopid: HopID @xd_a is using to send packets to us
+ * @a_out_hopid: HopID we are using to send packets to @xd_a
+ * @xd_b: The other end of the DMA paths or %NULL if it is the host
+ *	  interface. In the latter case @b_in_hopid and @b_out_hopid are
+ *	  the DMA ring numbers.
+ * @b_in_hopid: HopID @xd_b is using to send packets to us
+ * @b_out_hopid: HopID we are using to send packets to @xd_b
  *
- * Calls connection manager specific method to disconnect DMA paths to
- * the XDomain in question.
+ * Calls connection manager specific method to disconnect the DMA paths
+ * previously established by tb_domain_approve_xdomain_paths(). Passing %-1
+ * as any of the HopIDs means don't care.
  *
  * Return:
  * * %0 - On success.
- * * %-ENOTSUPP - If the connection manager implementation does not support
- *   XDomains.
+ * * %-EOPNOTSUPP - If the connection manager implementation does not support
+ *		    XDomains.
  * * Negative errno - An error occurred.
  */
-int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
-				       int transmit_path, int transmit_ring,
-				       int receive_path, int receive_ring)
+int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd_a,
+				       int a_in_hopid, int a_out_hopid,
+				       struct tb_xdomain *xd_b, int b_in_hopid,
+				       int b_out_hopid)
 {
 	if (!tb->cm_ops->disconnect_xdomain_paths)
-		return -ENOTSUPP;
+		return -EOPNOTSUPP;
 
-	return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path,
-			transmit_ring, receive_path, receive_ring);
+	return tb->cm_ops->disconnect_xdomain_paths(tb, xd_a, a_in_hopid,
+				a_out_hopid, xd_b, b_in_hopid, b_out_hopid);
 }
 
 static int disconnect_xdomain(struct device *dev, void *data)
drivers/thunderbolt/icm.c +33 -16

102 lines not on this page · raw message

drivers/thunderbolt/tb.c +91 -58

204 lines not on this page · raw message

drivers/thunderbolt/tb.h +16 -12
index 6da3492fd322..3126610a3602 100644
@@ -639,12 +639,14 @@ struct tb_cm_ops {
 	int (*challenge_switch_key)(struct tb *tb, struct tb_switch *sw,
 				    const u8 *challenge, u8 *response);
 	int (*disconnect_pcie_paths)(struct tb *tb);
-	int (*approve_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
-				     int transmit_path, int transmit_ring,
-				     int receive_path, int receive_ring);
-	int (*disconnect_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
-					int transmit_path, int transmit_ring,
-					int receive_path, int receive_ring);
+	int (*approve_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd_a,
+				     int a_in_hopid, int a_out_hopid,
+				     struct tb_xdomain *xd_b, int b_in_hopid,
+				     int b_out_hopid);
+	int (*disconnect_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd_a,
+					int a_in_hopid, int a_out_hopid,
+					struct tb_xdomain *xd_b, int b_in_hopid,
+					int b_out_hopid);
 	int (*usb4_switch_op)(struct tb_switch *sw, u16 opcode, u32 *metadata,
 			      u8 *status, const void *tx_data, size_t tx_data_len,
 			      void *rx_data, size_t rx_data_len);
@@ -896,12 +898,14 @@ int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);
 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw);
 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw);
 int tb_domain_disconnect_pcie_paths(struct tb *tb);
-int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
-				    int transmit_path, int transmit_ring,
-				    int receive_path, int receive_ring);
-int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
-				       int transmit_path, int transmit_ring,
-				       int receive_path, int receive_ring);
+int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd_a,
+				    int a_in_hopid, int a_out_hopid,
+				    struct tb_xdomain *xd_b, int b_in_hopid,
+				    int b_out_hopid);
+int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd_a,
+				       int a_in_hopid, int a_out_hopid,
+				       struct tb_xdomain *xd_b, int b_in_hopid,
+				       int b_out_hopid);
 int tb_domain_disconnect_all_paths(struct tb *tb);
 int tb_domain_unregister_unplugged_xdomains(struct tb *tb);
 
drivers/thunderbolt/xdomain.c +105 -5

128 lines not on this page · raw message

include/linux/thunderbolt.h +6 -0
index 03f315934e44..a19d6fede0bd 100644
@@ -307,6 +307,12 @@ int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path,
 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path,
 			     int transmit_ring, int receive_path,
 			     int receive_ring);
+int tb_xdomains_enable_paths(struct tb_xdomain *xd_a, int a_in_hopid,
+			     int a_out_hopid, struct tb_xdomain *xd_b,
+			     int b_in_hopid, int b_out_hopid);
+int tb_xdomains_disable_paths(struct tb_xdomain *xd_a, int a_in_hopid,
+			      int a_out_hopid, struct tb_xdomain *xd_b,
+			      int b_in_hopid, int b_out_hopid);
 
 static inline int tb_xdomain_disable_all_paths(struct tb_xdomain *xd)
 {
Signature · 1 line
2.50.1