thunderbolt: Notify userspace about tunneling events in the domain
Subsystems (2)
PATCH 1/3 thunderbolt: Introduce domain event message handler
In reply to Mika WesterbergFrom: Alan Borzeszkowski <[email protected]>
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.
--- drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/tb.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/thunderbolt/domain.c +1 -1
@@ -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);
drivers/thunderbolt/tb.h +13 -0
@@ -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);
Signature · 1 line
2.47.2
PATCH 2/3 thunderbolt: Notify userspace about software CM tunneling events
In reply to Mika WesterbergFrom: Alan Borzeszkowski <[email protected]>
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.
--- drivers/thunderbolt/tb.c | 22 +++++++-- drivers/thunderbolt/tunnel.c | 92 ++++++++++++++++++++++++++++++++++-- drivers/thunderbolt/tunnel.h | 23 +++++++++ 3 files changed, 129 insertions(+), 8 deletions(-)
drivers/thunderbolt/tb.c +19 -3
@@ -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;
drivers/thunderbolt/tunnel.c +87 -5
128 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +23 -0
@@ -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...) \
Signature · 1 line
2.47.2
PATCH 3/3 thunderbolt: Notify userspace about firmware CM tunneling events
In reply to Mika WesterbergFrom: Alan Borzeszkowski <[email protected]>
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.
--- drivers/thunderbolt/icm.c | 36 ++++++++++++++++++++++++++++++++++- drivers/thunderbolt/tb_msgs.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/thunderbolt/icm.c +35 -1
@@ -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 ®_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 ;
drivers/thunderbolt/tb_msgs.h +1 -0
@@ -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, };
Signature · 1 line
2.47.2
cover thunderbolt: Notify userspace about tunneling events in the domain
Hi all,
This series adds support to sending uevents to userspace about changes in tunneling such as creation, removal and bandwidth related. One intented use-case for this is an upcoming USB-C daemon developed by Saranya that then notifies user for example if there is not enough bandwidth for DisplayPort requirements. We also added debug tools [1] support for these (currently it just updates various screens on event but we are working on add event log there too).
The Firmware Connection manager side is kind of limited though since there are not that many notifications we get.
[1] https://github.com/intel/tbtools
Alan Borzeszkowski (3):
thunderbolt: Introduce domain event message handler
thunderbolt: Notify userspace about software CM tunneling events
thunderbolt: Notify userspace about firmware CM tunneling events
drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/icm.c | 36 +++++++++++++- drivers/thunderbolt/tb.c | 22 +++++++-- drivers/thunderbolt/tb.h | 13 +++++ drivers/thunderbolt/tb_msgs.h | 1 + drivers/thunderbolt/tunnel.c | 92 +++++++++++++++++++++++++++++++++-- drivers/thunderbolt/tunnel.h | 23 +++++++++ 7 files changed, 179 insertions(+), 10 deletions(-)
Signature · 1 line
2.47.2
Greg KH
maintainerRe: [PATCH 2/3] thunderbolt: Notify userspace about software CM tunneling events
In reply to Mika WesterbergQuoted 8 lines · Mika Westerberg
From: Alan Borzeszkowski <[email protected]>
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:
Quoted 8 lines
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 <[email protected]>
You didn't sign off on this? :(
Also, you are adding a new user/kernel api here, where is it documented?
thanks,
greg k-h
Re: [PATCH 2/3] thunderbolt: Notify userspace about software CM tunneling events
Quoted 13 lines · Greg KH
Quoted 12 lines · Mika Westerberg
From: Alan Borzeszkowski <[email protected]>
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)
Quoted 6 lines
Quoted 4 lines
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 <[email protected]>You didn't sign off on this? :(
Oops, sorry missed it completely. I'll fix this in v2.
Quoted 1 line
Also, you are adding a new user/kernel api here, where is it documented?
Hm, where uevent documentation lives? I know for sysfs is under Documentation/ABI/* but not sure for uevents.
Greg KH
maintainerRe: [PATCH 2/3] thunderbolt: Notify userspace about software CM tunneling events
Quoted 19 lines · Mika Westerberg
Quoted 18 lines · Greg KH
Quoted 16 lines · Mika Westerberg
From: Alan Borzeszkowski <[email protected]>
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 <[email protected]>
Quoted 8 lines
Quoted 1 line
You didn't sign off on this? :(
Oops, sorry missed it completely. I'll fix this in v2.
Quoted 1 line
Also, you are adding a new user/kernel api here, where is it documented?
Hm, where uevent documentation lives? I know for sysfs is under
Documentation/ABI/*but not sure for uevents.
Maybe in your Documentation/admin-guide/thunderbolt.rst file?
Re: [PATCH 2/3] thunderbolt: Notify userspace about software CM tunneling events
Quoted 22 lines · Greg KH
Quoted 21 lines · Mika Westerberg
Quoted 19 lines · Greg KH
Quoted 8 lines · Mika Westerberg
From: Alan Borzeszkowski <[email protected]>
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:
Quoted 8 lines
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 <[email protected]>You didn't sign off on this? :(
Quoted 8 lines
Quoted 6 lines
Oops, sorry missed it completely. I'll fix this in v2.
Quoted 1 line
Also, you are adding a new user/kernel api here, where is it documented?
Hm, where uevent documentation lives? I know for sysfs is under
Documentation/ABI/*but not sure for uevents.Maybe in your
Documentation/admin-guide/thunderbolt.rstfile?
Works for me. We'll add it there. Thanks!