From patchwork Thu Apr 17 09:04:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 882243 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F29C199E9A for ; Thu, 17 Apr 2025 09:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880673; cv=none; b=nMxYo1kPYvlH1zPgyzzFVYDYdfLqwVxaLLS+Yig+eScT1LmdqRnaukkzZCjBcMr2/jPpfwijHZ93GvO6PubO50VEosMfNn/7yMKXuD03nqxAYI7ZUuZpOOpudD0shMZIL8xh6JSUmmDnvP5pGB8uBImy03NULz1RGR2HvifVEG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880673; c=relaxed/simple; bh=6KrJ7W2cRxSJR2K+OvRI3JtZW+2jWadpO5qaoyPi6TI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SUW9fG/Cj8oBiUHSwru/lPTd6MCQSMwVKYAmZy+dWOkEiAyhDuh4BIc9BPAXBp8CQXiHs8cHX4RFcb8vUa1jaehCrD0XFpIZxZFznYaM6RhmKoVT74NMR9HhEyEiNAnQgmkJHDvpEI2xuZMLCmRTeJ+pC0TQzKPrQ/CHHAQkRhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=e4glTUPf; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e4glTUPf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744880672; x=1776416672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6KrJ7W2cRxSJR2K+OvRI3JtZW+2jWadpO5qaoyPi6TI=; b=e4glTUPfk99FyiyYpMmD7HVMhuYP9q0y8z3HH699kLNuiHvd34GD+UUQ cMuJctjCmF3BzeFEO8+ogs6L2gfOCScjLr8hGC+dEb0D5eu46zNkdRlpM 2lQHxuX24AAWixcRoVFpt7DrH9zuOwtmfM4VTqbg0na3hKQqG0b1q1OLP zYe8s2DwINFAFxG+UhNtTSwKvHAWMUAJqzqXPQqdGJRH7mXNywvwzA0Ub 1SpgaP90C/nQFhcM/OKV4LRXsEuJSB9ZSFDcAOSRZXluCsOWM9imLYW2s Hnh40Qw17RiAs/XKEheFp6MsxmzsWZ4MTXjQln0jIFwOEPmzhyObhmmzW Q==; X-CSE-ConnectionGUID: 9+YB56FyTRC1PuPIpca4MA== X-CSE-MsgGUID: knME+Vp4QAq+PMAyjqZvOQ== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="45692739" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="45692739" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:04:30 -0700 X-CSE-ConnectionGUID: JbayzdDZTraDW3wJHGiO4Q== X-CSE-MsgGUID: FpxGsblJTK+biy9ZtcgDfA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="131287404" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 17 Apr 2025 02:04:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id F405A74E; Thu, 17 Apr 2025 12:04:26 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Alan Borzeszkowski , Saranya Gopal , Greg KH , Mika Westerberg Subject: [PATCH v2 1/4] thunderbolt: Introduce domain event message handler Date: Thu, 17 Apr 2025 12:04:23 +0300 Message-ID: <20250417090426.221773-2-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250417090426.221773-1-mika.westerberg@linux.intel.com> References: <20250417090426.221773-1-mika.westerberg@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alan Borzeszkowski This patch introduces a function that can be used to send uevent notifications in the domain to userspace. For instance, it can indicate that a DisplayPort tunnel could not be established due to insufficient bandwidth. Userspace can then forward to user via dialog or similar. Convert boot_acl_store() to call this instead of open-coding. Signed-off-by: Alan Borzeszkowski Signed-off-by: Mika Westerberg --- drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/tb.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c index 144d0232a70c..a3a7c8059eee 100644 --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c @@ -217,7 +217,7 @@ static ssize_t boot_acl_store(struct device *dev, struct device_attribute *attr, ret = tb->cm_ops->set_boot_acl(tb, acl, tb->nboot_acl); if (!ret) { /* Notify userspace about the change */ - kobject_uevent(&tb->dev.kobj, KOBJ_CHANGE); + tb_domain_event(tb, NULL); } mutex_unlock(&tb->lock); diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index b54147a1ba87..5869b379e4f7 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -804,6 +804,19 @@ static inline void tb_domain_put(struct tb *tb) put_device(&tb->dev); } +/** + * tb_domain_event() - Notify userspace about an event in domain + * @tb: Domain where event occurred + * @envp: Array of uevent environment strings (can be %NULL) + * + * This function provides a way to notify userspace about any events + * that take place in the domain. + */ +static inline void tb_domain_event(struct tb *tb, char *envp[]) +{ + kobject_uevent_env(&tb->dev.kobj, KOBJ_CHANGE, envp); +} + struct tb_nvm *tb_nvm_alloc(struct device *dev); int tb_nvm_read_version(struct tb_nvm *nvm); int tb_nvm_validate(struct tb_nvm *nvm); From patchwork Thu Apr 17 09:04:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 882570 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D914C227E94 for ; Thu, 17 Apr 2025 09:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880674; cv=none; b=Ozxv3iecMnULfxzRUcHMI49se7JI6YseS0vImihSvywtVnv84vhTWZL7itqhWoP5kpsEMzX6ZAZHZnOIU6sxrDN5T8OUgBInSYDRJ2cyissWTVW4IBPvBzQUvEqGkTESK0i2Z18Nq4fCkLPbDJqu5EZs9p3D+Xp0TET+T0+1GAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880674; c=relaxed/simple; bh=w4/E/uG9xfZKyESIFc/a8meKbbaPSygZubR2fGdsEug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jrbTIbWnVRIn5eHHi+//ftaWDqUvUtltEAeNXmr0c2Khs3U1L9gI4WQIsOmxxujeMnww/vPExnMnVgSH99vS+IVN+8+XMW+youzJF8cfzlEy2WhDFeF1j5A9gTgfXhDl5uVpCOSNsW71mY//OwMNlsCnU9owV9UcDbgCuyEL4BU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AkfsBN7I; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AkfsBN7I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744880672; x=1776416672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w4/E/uG9xfZKyESIFc/a8meKbbaPSygZubR2fGdsEug=; b=AkfsBN7IhYG92AodBkQkLYM/UIy6BmqdRKI2/+ca3nrt6ZGN35utg1J6 1gKgjXjZQC0nT3Mh7HRZ92Oa29ymHKTjkljtSvDp/6xJSMhrS3BG75nGU 817yiCgpe2yCzFrxhxrsK/XVmB2/Tpf2MzSwb5Y/XLVNbIaSFkFxzVVFD yG/bCOnDP1oX1m51lxwaTjHuoGyJpcW2g1Z8nCS/0cLk1n5z9V/uuFM+o 0FeRpx54Ti7c0KMZFi4rYJ7tehDhjtXi82ZXPjhccSGWYgLvIyA5FKviF o0o4NYbK3qinOEqy3UV445vJur8sscg9ZBFVxw7SKv2reOVm1/dXzhXry g==; X-CSE-ConnectionGUID: eibX5pFWRYOlzQbixaACTA== X-CSE-MsgGUID: Cav5YrHSRYmX7c4GG/gH8g== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="50281225" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="50281225" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:04:30 -0700 X-CSE-ConnectionGUID: SqQF3yFMQ/q55ZPV1oWKLg== X-CSE-MsgGUID: hcjeWXwkRguY7OmlYGmdpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="131066816" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa008.fm.intel.com with ESMTP; 17 Apr 2025 02:04:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id EF16C8F; Thu, 17 Apr 2025 12:04:26 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Alan Borzeszkowski , Saranya Gopal , Greg KH , Mika Westerberg Subject: [PATCH v2 2/4] thunderbolt: Notify userspace about software CM tunneling events Date: Thu, 17 Apr 2025 12:04:24 +0300 Message-ID: <20250417090426.221773-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250417090426.221773-1-mika.westerberg@linux.intel.com> References: <20250417090426.221773-1-mika.westerberg@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alan Borzeszkowski This adds notification whenever software connection manager activates, changes or deactivates a tunnel, and also if there is limitation in bandwidth. The notification looks like below: TUNNEL_EVENT=activated|changed|deactivated|low bandwidth| insufficient bandwidth TUNNEL_DETAILS=0:12 <-> 1:20 (USB3) Userspace can then listen these and inform user if needed. For example if there is not enough bandwidth, it can show warning dialog to the user. Signed-off-by: Alan Borzeszkowski Signed-off-by: Mika Westerberg --- drivers/thunderbolt/tb.c | 22 +++++++-- drivers/thunderbolt/tunnel.c | 92 ++++++++++++++++++++++++++++++++++-- drivers/thunderbolt/tunnel.h | 23 +++++++++ 3 files changed, 129 insertions(+), 8 deletions(-) diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 8c527af98927..c14ab1fbeeaf 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -952,6 +952,15 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) tb_port_dbg(up, "available bandwidth for new USB3 tunnel %d/%d Mb/s\n", available_up, available_down); + /* + * If the available bandwidth is less than 1.5 Gb/s notify + * userspace that the connected isochronous device may not work + * properly. + */ + if (available_up < 1500 || available_down < 1500) + tb_tunnel_event(tb, TB_TUNNEL_LOW_BANDWIDTH, TB_TUNNEL_USB3, + down, up); + tunnel = tb_tunnel_alloc_usb3(tb, up, down, available_up, available_down); if (!tunnel) { @@ -2000,8 +2009,10 @@ static void tb_tunnel_one_dp(struct tb *tb, struct tb_port *in, ret = tb_available_bandwidth(tb, in, out, &available_up, &available_down, true); - if (ret) + if (ret) { + tb_tunnel_event(tb, TB_TUNNEL_NO_BANDWIDTH, TB_TUNNEL_DP, in, out); goto err_reclaim_usb; + } tb_dbg(tb, "available bandwidth for new DP tunnel %u/%u Mb/s\n", available_up, available_down); @@ -2622,8 +2633,12 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up, } } - return tb_tunnel_alloc_bandwidth(tunnel, requested_up, - requested_down); + ret = tb_tunnel_alloc_bandwidth(tunnel, requested_up, + requested_down); + if (ret) + goto fail; + + return 0; } /* @@ -2699,6 +2714,7 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up, "failing the request by rewriting allocated %d/%d Mb/s\n", allocated_up, allocated_down); tb_tunnel_alloc_bandwidth(tunnel, &allocated_up, &allocated_down); + tb_tunnel_event(tb, TB_TUNNEL_NO_BANDWIDTH, TB_TUNNEL_DP, in, out); } return ret; diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c index 76254ed3f47f..d52efe3f658c 100644 --- a/drivers/thunderbolt/tunnel.c +++ b/drivers/thunderbolt/tunnel.c @@ -100,6 +100,14 @@ MODULE_PARM_DESC(bw_alloc_mode, static const char * const tb_tunnel_names[] = { "PCI", "DP", "DMA", "USB3" }; +static const char * const tb_event_names[] = { + [TB_TUNNEL_ACTIVATED] = "activated", + [TB_TUNNEL_CHANGED] = "changed", + [TB_TUNNEL_DEACTIVATED] = "deactivated", + [TB_TUNNEL_LOW_BANDWIDTH] = "low bandwidth", + [TB_TUNNEL_NO_BANDWIDTH] = "insufficient bandwidth", +}; + /* Synchronizes kref_get()/put() of struct tb_tunnel */ static DEFINE_MUTEX(tb_tunnel_lock); @@ -220,6 +228,72 @@ void tb_tunnel_put(struct tb_tunnel *tunnel) mutex_unlock(&tb_tunnel_lock); } +/** + * tb_tunnel_event() - Notify userspace about tunneling event + * @tb: Domain where the event occurred + * @event: Event that happened + * @type: Type of the tunnel in question + * @src_port: Tunnel source port (can be %NULL) + * @dst_port: Tunnel destination port (can be %NULL) + * + * Notifies userspace about tunneling @event in the domain. The tunnel + * does not need to exist (e.g the tunnel was not activated because + * there is not enough bandwidth). If the @src_port and @dst_port are + * given fill in full %TUNNEL_DETAILS environment variable. Otherwise + * uses the shorter one (just the tunnel type). + */ +void tb_tunnel_event(struct tb *tb, enum tb_tunnel_event event, + enum tb_tunnel_type type, + const struct tb_port *src_port, + const struct tb_port *dst_port) +{ + char *envp[3] = { NULL }; + + if (WARN_ON_ONCE(event >= ARRAY_SIZE(tb_event_names))) + return; + if (WARN_ON_ONCE(type >= ARRAY_SIZE(tb_tunnel_names))) + return; + + envp[0] = kasprintf(GFP_KERNEL, "TUNNEL_EVENT=%s", tb_event_names[event]); + if (!envp[0]) + return; + + if (src_port != NULL && dst_port != NULL) { + envp[1] = kasprintf(GFP_KERNEL, "TUNNEL_DETAILS=%llx:%u <-> %llx:%u (%s)", + tb_route(src_port->sw), src_port->port, + tb_route(dst_port->sw), dst_port->port, + tb_tunnel_names[type]); + } else { + envp[1] = kasprintf(GFP_KERNEL, "TUNNEL_DETAILS=(%s)", + tb_tunnel_names[type]); + } + + if (envp[1]) + tb_domain_event(tb, envp); + + kfree(envp[1]); + kfree(envp[0]); +} + +static inline void tb_tunnel_set_active(struct tb_tunnel *tunnel, bool active) +{ + if (active) { + tunnel->state = TB_TUNNEL_ACTIVE; + tb_tunnel_event(tunnel->tb, TB_TUNNEL_ACTIVATED, tunnel->type, + tunnel->src_port, tunnel->dst_port); + } else { + tunnel->state = TB_TUNNEL_INACTIVE; + tb_tunnel_event(tunnel->tb, TB_TUNNEL_DEACTIVATED, tunnel->type, + tunnel->src_port, tunnel->dst_port); + } +} + +static inline void tb_tunnel_changed(struct tb_tunnel *tunnel) +{ + tb_tunnel_event(tunnel->tb, TB_TUNNEL_CHANGED, tunnel->type, + tunnel->src_port, tunnel->dst_port); +} + static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable) { struct tb_port *port = tb_upstream_port(tunnel->dst_port->sw); @@ -992,7 +1066,7 @@ static void tb_dp_dprx_work(struct work_struct *work) return; } } else { - tunnel->state = TB_TUNNEL_ACTIVE; + tb_tunnel_set_active(tunnel, true); } mutex_unlock(&tb->lock); } @@ -2326,7 +2400,7 @@ int tb_tunnel_activate(struct tb_tunnel *tunnel) } } - tunnel->state = TB_TUNNEL_ACTIVE; + tb_tunnel_set_active(tunnel, true); return 0; err: @@ -2356,7 +2430,7 @@ void tb_tunnel_deactivate(struct tb_tunnel *tunnel) if (tunnel->post_deactivate) tunnel->post_deactivate(tunnel); - tunnel->state = TB_TUNNEL_INACTIVE; + tb_tunnel_set_active(tunnel, false); } /** @@ -2449,8 +2523,16 @@ int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up, if (!tb_tunnel_is_active(tunnel)) return -ENOTCONN; - if (tunnel->alloc_bandwidth) - return tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down); + if (tunnel->alloc_bandwidth) { + int ret; + + ret = tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down); + if (ret) + return ret; + + tb_tunnel_changed(tunnel); + return 0; + } return -EOPNOTSUPP; } diff --git a/drivers/thunderbolt/tunnel.h b/drivers/thunderbolt/tunnel.h index 8a0a0cb21a89..5e9fb73d5220 100644 --- a/drivers/thunderbolt/tunnel.h +++ b/drivers/thunderbolt/tunnel.h @@ -194,6 +194,29 @@ static inline bool tb_tunnel_direction_downstream(const struct tb_tunnel *tunnel tunnel->dst_port); } +/** + * enum tb_tunnel_event - Tunnel related events + * @TB_TUNNEL_ACTIVATED: A tunnel was activated + * @TB_TUNNEL_CHANGED: There is a tunneling change in the domain. Includes + * full %TUNNEL_DETAILS if the tunnel in question is known + * (ICM does not provide that information). + * @TB_TUNNEL_DEACTIVATED: A tunnel was torn down + * @TB_TUNNEL_LOW_BANDWIDTH: Tunnel bandwidth is not optimal + * @TB_TUNNEL_NO_BANDWIDTH: There is not enough bandwidth for a tunnel + */ +enum tb_tunnel_event { + TB_TUNNEL_ACTIVATED, + TB_TUNNEL_CHANGED, + TB_TUNNEL_DEACTIVATED, + TB_TUNNEL_LOW_BANDWIDTH, + TB_TUNNEL_NO_BANDWIDTH, +}; + +void tb_tunnel_event(struct tb *tb, enum tb_tunnel_event event, + enum tb_tunnel_type type, + const struct tb_port *src_port, + const struct tb_port *dst_port); + const char *tb_tunnel_type_name(const struct tb_tunnel *tunnel); #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ From patchwork Thu Apr 17 09:04:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 882569 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034562288E3 for ; Thu, 17 Apr 2025 09:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880675; cv=none; b=leIFdoACiDftm9Woj/ST/SkwhIg3re+avEY71e7+EV3UwSL08Kt9Y9lVDRjfDZGHodd5/zQMMKWVkh4aklatP4vCIvWD8A8WwaC3q94+jEkSkBV1BZAfI637owLd9QwKhw6KPi7IU0sGfjriCsb2HxuyRRrFFWCuWcFFL7FfgY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880675; c=relaxed/simple; bh=8ptKG71osZf9Z7VcQVSNGRCr6hO9tgDtvzwD3L6mOmQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PkvgXjV0dRkY/EvgYg2ybkVA2cJ+EXY/WaSIuosrF61ApSl/F1T0b2amjMxT2lrRvJXAgyskwCxJak92QjIngObXUawBsopeeuOsyt6daLvxxFVxeZcAeVlFiJKY7/A350Bs4tbFqv/NTLi3LLI4xlPPcPrrEvDrGxbzU36zBbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=k4ftZmI9; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="k4ftZmI9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744880674; x=1776416674; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8ptKG71osZf9Z7VcQVSNGRCr6hO9tgDtvzwD3L6mOmQ=; b=k4ftZmI90dsHWlh8cYSZisOj05W0dhbLUGA3brgNJodpfAoC5rPf15hA Ocbk8sTxrj7TSQE+jg7K5EK6tBwtet/oLl2tYzgE1083jh2iGdqhsSSzn 5W0djGYcspMjtp7WluaEl6im8/rVBuI0Jmb3zx4P6PoW6iu+Jg3MFTULW tCVj70VkHBDyizSseQuO0s/28PNGpGRPXJnzKPd3GYonmTNuXGsmCwEkn Ukkb46gWIGnevdkqMk27zomET/u3V3YvCt/fZg0xG+Np0UZfEP4ssEgR+ 54uuRn6m+URyvNoyl2qVZsPRBwS/UOP+CZOGJMgP622WGyQPCCEdriNj0 w==; X-CSE-ConnectionGUID: KDaBpfAMSwCxFHziSR2R1Q== X-CSE-MsgGUID: KfE7Pk16TxW/xTFT7L5M7g== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="45692743" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="45692743" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:04:30 -0700 X-CSE-ConnectionGUID: HOBzvQCOTWCOhhre5M1Iyg== X-CSE-MsgGUID: 94oycCNIQEyHvr4VOd12qA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="131287407" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 17 Apr 2025 02:04:29 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 050B5741; Thu, 17 Apr 2025 12:04:27 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Alan Borzeszkowski , Saranya Gopal , Greg KH , Mika Westerberg Subject: [PATCH v2 3/4] thunderbolt: Notify userspace about firmware CM tunneling events Date: Thu, 17 Apr 2025 12:04:25 +0300 Message-ID: <20250417090426.221773-4-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250417090426.221773-1-mika.westerberg@linux.intel.com> References: <20250417090426.221773-1-mika.westerberg@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alan Borzeszkowski In the same way we do for software connection manager, send notifications about tunneling changes done by the firmware connection manager as well. There are some limitations with this though, for example we only get "DP Configuration Changed" message from the firmware without any indication if DisplayPort tunnel was activated or deactivated. Also we don't get information about the tunnel itself either so the event then looks like: TUNNEL_EVENT=changed TUNNEL_DETAILS=(DP) XDomain connections are similar to what the software connection manager sends. Signed-off-by: Alan Borzeszkowski Signed-off-by: Mika Westerberg --- drivers/thunderbolt/icm.c | 36 ++++++++++++++++++++++++++++++++++- drivers/thunderbolt/tb_msgs.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index 7859bccc592d..f213d9174dc5 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -22,6 +22,7 @@ #include "ctl.h" #include "nhi_regs.h" #include "tb.h" +#include "tunnel.h" #define PCIE2CIO_CMD 0x30 #define PCIE2CIO_CMD_TIMEOUT BIT(31) @@ -379,6 +380,27 @@ static bool icm_firmware_running(const struct tb_nhi *nhi) return !!(val & REG_FW_STS_ICM_EN); } +static void icm_xdomain_activated(struct tb_xdomain *xd, bool activated) +{ + struct tb_port *nhi_port, *dst_port; + struct tb *tb = xd->tb; + + nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); + dst_port = tb_xdomain_downstream_port(xd); + + if (activated) + tb_tunnel_event(tb, TB_TUNNEL_ACTIVATED, TB_TUNNEL_DMA, + nhi_port, dst_port); + else + tb_tunnel_event(tb, TB_TUNNEL_DEACTIVATED, TB_TUNNEL_DMA, + nhi_port, dst_port); +} + +static void icm_dp_event(struct tb *tb) +{ + tb_tunnel_event(tb, TB_TUNNEL_CHANGED, TB_TUNNEL_DP, NULL, NULL); +} + static bool icm_fr_is_supported(struct tb *tb) { return !x86_apple_machine; @@ -584,6 +606,7 @@ static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, if (reply.hdr.flags & ICM_FLAGS_ERROR) return -EIO; + icm_xdomain_activated(xd, true); return 0; } @@ -603,6 +626,8 @@ static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, nhi_mailbox_cmd(tb->nhi, cmd, 1); usleep_range(10, 50); nhi_mailbox_cmd(tb->nhi, cmd, 2); + + icm_xdomain_activated(xd, false); return 0; } @@ -1151,6 +1176,7 @@ static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, if (reply.hdr.flags & ICM_FLAGS_ERROR) return -EIO; + icm_xdomain_activated(xd, true); return 0; } @@ -1191,7 +1217,12 @@ static int icm_tr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, return ret; usleep_range(10, 50); - return icm_tr_xdomain_tear_down(tb, xd, 2); + ret = icm_tr_xdomain_tear_down(tb, xd, 2); + if (ret) + return ret; + + icm_xdomain_activated(xd, false); + return 0; } static void @@ -1718,6 +1749,9 @@ static void icm_handle_notification(struct work_struct *work) if (tb_is_xdomain_enabled()) icm->xdomain_disconnected(tb, n->pkg); break; + case ICM_EVENT_DP_CONFIG_CHANGED: + icm_dp_event(tb); + break; case ICM_EVENT_RTD3_VETO: icm->rtd3_veto(tb, n->pkg); break; diff --git a/drivers/thunderbolt/tb_msgs.h b/drivers/thunderbolt/tb_msgs.h index a1670a96cbdc..144f7332d5d2 100644 --- a/drivers/thunderbolt/tb_msgs.h +++ b/drivers/thunderbolt/tb_msgs.h @@ -118,6 +118,7 @@ enum icm_event_code { ICM_EVENT_DEVICE_DISCONNECTED = 0x4, ICM_EVENT_XDOMAIN_CONNECTED = 0x6, ICM_EVENT_XDOMAIN_DISCONNECTED = 0x7, + ICM_EVENT_DP_CONFIG_CHANGED = 0x8, ICM_EVENT_RTD3_VETO = 0xa, }; From patchwork Thu Apr 17 09:04:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 882242 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A70622839A for ; Thu, 17 Apr 2025 09:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880674; cv=none; b=k8OSS4HpbW7AfRmZhlYbHc8MGVZ4K7QTsqwPKl1EaataKYotVRzxO+MyE1hbvVJv+nHR6EcmODx1pH2IvFwYxJ6LBn0DNuB16w3Vf9bBur9NDkFN7W/uWxAv89DYnpEA7bA3yyHTtCJNsd8bsdAtHfAu9ATj2e0uQUcCTft2bhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744880674; c=relaxed/simple; bh=2RjpNy06yXPrE3hSRzUl9kgDDVd40NjZgyFWjNKOeZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bSHpe4IRLyMipenagvkiuluH+4gSelHT1JE8fst4PDReaP8M/37ps3xyxdlKN9I1TBYS0wqf/cnhb1WTk9pQbtxt/ADAZzGiU/NP/KDpvmiWKFyRtAUl9haNhHSR4IJl13+iebJiw+zR0lc8j/PI5+Kjf5vpLeFYahamUBNPwJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iJx91+i4; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iJx91+i4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744880673; x=1776416673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2RjpNy06yXPrE3hSRzUl9kgDDVd40NjZgyFWjNKOeZA=; b=iJx91+i47706Ci0gRcHDP5IlaW+lch31EVCv+GkJ7b2h7kzvxSRNqWpI 1VP6wWuG3+bPAnESNyQoljJhBIIYkBxWYbYJba52YRVs5tqvS8Iuej7AB 2/k8en6NXdRTBKaPBmkkyQY+9T2oc0DRlAyA3oqvbpZ1JzuzwMvobyAq0 YxUYuSScwb37RVkUiRQn4omZ3bvLHMe3iYeWkkvGsPQ2hVK/jvzF5fh54 Rdamd8PsBw5LGFmgNgyFLQ1IUSOSvEOuw3YWjoN03Cq6qe0Ia/GIPsHsm 654Uti28aZIHvyDYWoeJbObF+ov27nrc0I37GrNbiWxVqC5cXWPZACFmt Q==; X-CSE-ConnectionGUID: RnFJZfUWQeStWA/MfLNA0g== X-CSE-MsgGUID: ge8vKT9TQ9GlBY4Q1Tq6Iw== X-IronPort-AV: E=McAfee;i="6700,10204,11405"; a="50281229" X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="50281229" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2025 02:04:30 -0700 X-CSE-ConnectionGUID: dzTIh8j6Sced7M7BbrySAw== X-CSE-MsgGUID: U0lcJcAcTNi+a6D2+zJktA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,218,1739865600"; d="scan'208";a="131066818" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa008.fm.intel.com with ESMTP; 17 Apr 2025 02:04:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 14269C0B; Thu, 17 Apr 2025 12:04:27 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Alan Borzeszkowski , Saranya Gopal , Greg KH , Mika Westerberg Subject: [PATCH v2 4/4] Documentation/admin-guide: Document Thunderbolt/USB4 tunneling events Date: Thu, 17 Apr 2025 12:04:26 +0300 Message-ID: <20250417090426.221773-5-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250417090426.221773-1-mika.westerberg@linux.intel.com> References: <20250417090426.221773-1-mika.westerberg@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alan Borzeszkowski Add documentation about the Thunderbolt/USB4 tunneling events to the user’s and administrator’s guide. Signed-off-by: Alan Borzeszkowski Signed-off-by: Mika Westerberg --- Documentation/admin-guide/thunderbolt.rst | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/admin-guide/thunderbolt.rst b/Documentation/admin-guide/thunderbolt.rst index d0502691dfa1..f0368ab6bd1f 100644 --- a/Documentation/admin-guide/thunderbolt.rst +++ b/Documentation/admin-guide/thunderbolt.rst @@ -296,6 +296,39 @@ information is missing. To recover from this mode, one needs to flash a valid NVM image to the host controller in the same way it is done in the previous chapter. +Tunneling events +---------------- +The driver sends ``KOBJ_CHANGE`` events to userspace when there is a +tunneling change in the ``thunderbolt_domain``. The notification carries +following environment variables:: + + TUNNEL_EVENT= + TUNNEL_DETAILS=0:12 <-> 1:20 (USB3) + +Possible values for ```` are: + + activated + The tunnel was activated (created). + + changed + There is a change in this tunnel. For example bandwidth allocation was + changed. + + deactivated + The tunnel was torn down. + + low bandwidth + The tunnel is not getting optimal bandwidth. + + insufficient bandwidth + There is not enough bandwidth for the current tunnel requirements. + +The ``TUNNEL_DETAILS`` is only provided if the tunnel is known. For +example, in case of Firmware Connection Manager this is missing or does +not provide full tunnel information. In case of Software Connection Manager +this includes full tunnel details. The format matches what the driver uses +when logging. + Networking over Thunderbolt cable --------------------------------- Thunderbolt technology allows software communication between two hosts