All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Michael Jamet <michael.jamet@intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>,
	Andreas Noever <andreas.noever@gmail.com>,
	Lukas Wunner <lukas@wunner.de>,
	Mario Limonciello <mario.limonciello@dell.com>,
	Christian Kellner <christian@kellner.me>,
	Benson Leung <bleung@google.com>,
	Prashant Malani <pmalani@google.com>,
	Diego Rivas <diegorivas@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 1/3] thunderbolt: Add details to router uevent
Date: Tue,  9 Mar 2021 16:48:16 +0300	[thread overview]
Message-ID: <20210309134818.63118-2-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20210309134818.63118-1-mika.westerberg@linux.intel.com>

Expose two environment variables for routers as part of the initial
uevent:

  USB4_VERSION=1.0
  USB4_TYPE=host|device|hub

Userspace can use this information to expose more details about each
connected device. Only USB4 devices have USB4_VERSION but all devices
have USB4_TYPE.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/switch.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 72b43c7c0651..a82032c081e8 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -1827,6 +1827,39 @@ static void tb_switch_release(struct device *dev)
 	kfree(sw);
 }
 
+static int tb_switch_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct tb_switch *sw = tb_to_switch(dev);
+	const char *type;
+
+	if (sw->config.thunderbolt_version == USB4_VERSION_1_0) {
+		if (add_uevent_var(env, "USB4_VERSION=1.0"))
+			return -ENOMEM;
+	}
+
+	if (!tb_route(sw)) {
+		type = "host";
+	} else {
+		const struct tb_port *port;
+		bool hub = false;
+
+		/* Device is hub if it has any downstream ports */
+		tb_switch_for_each_port(sw, port) {
+			if (!port->disabled && !tb_is_upstream_port(port) &&
+			     tb_port_is_null(port)) {
+				hub = true;
+				break;
+			}
+		}
+
+		type = hub ? "hub" : "device";
+	}
+
+	if (add_uevent_var(env, "USB4_TYPE=%s", type))
+		return -ENOMEM;
+	return 0;
+}
+
 /*
  * Currently only need to provide the callbacks. Everything else is handled
  * in the connection manager.
@@ -1860,6 +1893,7 @@ static const struct dev_pm_ops tb_switch_pm_ops = {
 struct device_type tb_switch_type = {
 	.name = "thunderbolt_device",
 	.release = tb_switch_release,
+	.uevent = tb_switch_uevent,
 	.pm = &tb_switch_pm_ops,
 };
 
-- 
2.30.1


  reply	other threads:[~2021-03-09 13:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 13:48 [PATCH 0/3] thunderbolt: Expose details about tunneling Mika Westerberg
2021-03-09 13:48 ` Mika Westerberg [this message]
2021-03-09 14:10   ` [PATCH 1/3] thunderbolt: Add details to router uevent Greg Kroah-Hartman
2021-03-10 17:28   ` Limonciello, Mario
2021-03-11  7:59     ` Mika Westerberg
2021-03-09 13:48 ` [PATCH 2/3] thunderbolt: Hide authorized attribute if router does not support PCIe tunnels Mika Westerberg
2021-03-09 14:10   ` Greg Kroah-Hartman
2021-03-09 13:48 ` [PATCH 3/3] thunderbolt: Expose more details about USB 3.x and DisplayPort tunnels Mika Westerberg
2021-03-09 14:09   ` Greg Kroah-Hartman
2021-03-10  7:54     ` Mika Westerberg
2021-03-10  8:53       ` Greg Kroah-Hartman
2021-03-10  9:21         ` Mika Westerberg
2021-03-10  9:34           ` Greg Kroah-Hartman
2021-03-10  9:39             ` Mika Westerberg
2021-03-10 16:24               ` Limonciello, Mario
2021-03-10 18:49                 ` Lukas Wunner
2021-03-10 19:32                   ` Limonciello, Mario
2021-03-17 10:19   ` 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=20210309134818.63118-2-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=bleung@google.com \
    --cc=christian@kellner.me \
    --cc=diegorivas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mario.limonciello@dell.com \
    --cc=michael.jamet@intel.com \
    --cc=pmalani@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.