thunderbolt: Improve DisplayPort tunneling
Subsystems (2)
cover thunderbolt: Improve DisplayPort tunneling
Hi all,
This series provides cleanups and few improvements for DisplayPort tunneling. First of all we increase the DPRX capabilites read timeout to cope with the fact that graphics driver may be runtime suspended. Secondly we move the DPRX negotiation to happen in a separate worker to allow forward progress even if the graphics driver is not yet loaded (this is kind if rare case but common in Intel Graphics CI).
Mika Westerberg (12):
thunderbolt: Drop doubled empty line from ctl.h
thunderbolt: Log config space when invalid config space reply is received
thunderbolt: Debug log an invalid config space reply just once
thunderbolt: Increase DPRX capabilities read timeout
thunderbolt: Make tb_tunnel_one_dp() return void
thunderbolt: Show path name in debug log when path is deactivated
thunderbolt: Rework how tunnel->[init|deinit] hooks are called
thunderbolt: Drop tb_tunnel_restart()
thunderbolt: Pass reason to tb_dp_resource_unavailable()
thunderbolt: Move forward declarations in one place
thunderbolt: Rework tb_tunnel_consumed_bandwidth()
thunderbolt: Handle DisplayPort tunnel activation asynchronously
drivers/thunderbolt/ctl.c | 11 +- drivers/thunderbolt/ctl.h | 1 - drivers/thunderbolt/path.c | 4 +- drivers/thunderbolt/tb.c | 196 ++++++++++++----- drivers/thunderbolt/test.c | 90 ++++---- drivers/thunderbolt/tunnel.c | 406 +++++++++++++++++++++-------------- drivers/thunderbolt/tunnel.h | 61 +++++- 7 files changed, 494 insertions(+), 275 deletions(-)
Signature · 1 line
2.45.2
PATCH 2/12 thunderbolt: Log config space when invalid config space reply is received
For debugging purposes helps to see the config space that was being accessed.
--- drivers/thunderbolt/ctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thunderbolt/ctl.c +4 -4
@@ -265,7 +265,7 @@ static struct tb_cfg_result parse_header(const struct ctl_pkg *pkg, u32 len,return res; } -static void tb_cfg_print_error (struct tb_ctl *ctl, +static void tb_cfg_print_error (struct tb_ctl *ctl,enum tb_cfg_space space,const struct tb_cfg_result *res) {WARN_ON (res->err !=1 );
@@ -279,8 +279,8 @@ static void tb_cfg_print_error(struct tb_ctl *ctl,* Invalid cfg_space/offset/length combination in * cfg_read/cfg_write. */ -tb_ctl_dbg (ctl,"%llx:%x: invalid config space or offset\n" , - res->response_route, res->response_port); +tb_ctl_dbg (ctl,"%llx:%x: invalid config space (%u) or offset\n" , + res->response_route, res->response_port, space);return ;case TB_CFG_ERROR_NO_SUCH_PORT :/*
@@ -1072,7 +1072,7 @@ static int tb_cfg_get_error(struct tb_ctl *ctl, enum tb_cfg_space space, res->tb_error == TB_CFG_ERROR_INVALID_CONFIG_SPACE)return -ENODEV ; -tb_cfg_print_error (ctl, res); +tb_cfg_print_error (ctl, space, res);if (res->tb_error ==TB_CFG_ERROR_LOCK )return -EACCES ;
Signature · 1 line
2.45.2
PATCH 1/12 thunderbolt: Drop doubled empty line from ctl.h
In reply to Mika WesterbergNo functional changes.
--- drivers/thunderbolt/ctl.h | 1 - 1 file changed, 1 deletion(-)
drivers/thunderbolt/ctl.h +0 -1
@@ -140,5 +140,4 @@ int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port, enum tb_cfg_space space, u32 offset, u32 length);int tb_cfg_get_upstream_port (struct tb_ctl *ctl,u64 route); -#endif
Signature · 1 line
2.45.2
PATCH 3/12 thunderbolt: Debug log an invalid config space reply just once
In reply to Mika WesterbergThese can mess up the debug log if a router does not implement the config space register blocks fully and we are reading registers through debugfs. To avoid this, just log it once.
--- drivers/thunderbolt/ctl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/thunderbolt/ctl.c +5 -2
@@ -70,6 +70,9 @@ struct tb_ctl { #define tb_ctl_dbg(ctl, format, arg...) \ dev_dbg(&(ctl)->nhi->pdev->dev, format, ## arg) +#define tb_ctl_dbg_once(ctl, format, arg...) \ + dev_dbg_once(&(ctl)->nhi->pdev->dev, format, ## arg) +static DECLARE_WAIT_QUEUE_HEAD (tb_cfg_request_cancel_queue);/* Serializes access to request kref_get/put */ static DEFINE_MUTEX (tb_cfg_request_lock);
@@ -279,8 +282,8 @@ static void tb_cfg_print_error(struct tb_ctl *ctl, enum tb_cfg_space space,* Invalid cfg_space/offset/length combination in * cfg_read/cfg_write. */ -tb_ctl_dbg (ctl,"%llx:%x: invalid config space (%u) or offset\n" , - res->response_route, res->response_port, space); +tb_ctl_dbg_once (ctl,"%llx:%x: invalid config space (%u) or offset\n" , + res->response_route, res->response_port, space);return ;case TB_CFG_ERROR_NO_SUCH_PORT :/*
Signature · 1 line
2.45.2
PATCH 4/12 thunderbolt: Increase DPRX capabilities read timeout
In reply to Mika WesterbergSome graphics drivers such as i915 support runtime power management and if there is nothing connected at the moment they will runtime suspend to save power. At least i915 is polling for new connections every 10 seconds if the hardware does support sending PME. To allow i915 and other graphics from detect the just established DisplayPort tunnel allow the DPRX capabilities read to take up to 12 seconds.
--- drivers/thunderbolt/tunnel.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/thunderbolt/tunnel.c +5 -2
@@ -1186,9 +1186,12 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,* return that bandwidth (it may be smaller than the * reduced one). According to VESA spec, the DPRX * negotiation shall compete in 5 seconds after tunnel -* established. We give it 100ms extra just in case. +* established. Since at least i915 can runtime suspend +* if there is nothing connected, and that it polls any +* new connections every 10 seconds, we use 12 seconds +* here. */ - ret =tb_dp_wait_dprx (tunnel,5100 ); + ret =tb_dp_wait_dprx (tunnel,12000 );if (ret)return ret; ret =tb_dp_read_cap (tunnel,DP_COMMON_CAP , &rate, &lanes);
Signature · 1 line
2.45.2
PATCH 9/12 thunderbolt: Pass reason to tb_dp_resource_unavailable()
In reply to Mika WesterbergSince we are going to call this also when DisplayPort tunnel establishment fails it is useful to have the reason logged.
--- drivers/thunderbolt/tb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/thunderbolt/tb.c +5 -4
@@ -2088,17 +2088,18 @@ static void tb_switch_exit_redrive(struct tb_switch *sw) } } -static void tb_dp_resource_unavailable (struct tb *tb,struct tb_port *port) +static void tb_dp_resource_unavailable (struct tb *tb,struct tb_port *port, +const char *reason) {struct tb_port *in, *out;struct tb_tunnel *tunnel;if (tb_port_is_dpin (port)) { -tb_port_dbg (port,"DP IN resource unavailable\n" ); +tb_port_dbg (port,"DP IN resource unavailable: %s\n" , reason); in = port; out =NULL ; }else { -tb_port_dbg (port,"DP OUT resource unavailable\n" ); +tb_port_dbg (port,"DP OUT resource unavailable: %s\n" , reason); in =NULL ; out = port; }
@@ -2404,7 +2405,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) { -tb_dp_resource_unavailable (tb, port); +tb_dp_resource_unavailable (tb, port,"adapter unplug" ); }else if (!port->port) {tb_sw_dbg (sw,"xHCI disconnect request\n" );tb_switch_xhci_disconnect (sw);
Signature · 1 line
2.45.2
PATCH 6/12 thunderbolt: Show path name in debug log when path is deactivated
In reply to Mika WesterbergSimilarly as we do when activating the path. Helps in debugging.
--- drivers/thunderbolt/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thunderbolt/path.c +2 -2
@@ -581,10 +581,10 @@ int tb_path_activate(struct tb_path *path) } } path->activated = true; -tb_dbg (path->tb,"path activation complete\n" ); +tb_dbg (path->tb,"%s path activation complete\n" , path->name);return 0 ; err: -tb_WARN (path->tb,"path activation failed\n" ); +tb_WARN (path->tb,"%s path activation failed\n" , path->name);return res; }
Signature · 1 line
2.45.2
PATCH 11/12 thunderbolt: Rework tb_tunnel_consumed_bandwidth()
In reply to Mika WesterbergRework to avoid the goto as it only makes it confusing. Move logging to happen at the end so we can see all the tunnels this is being called.
--- drivers/thunderbolt/tunnel.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/thunderbolt/tunnel.c +2 -8
@@ -2361,26 +2361,20 @@ int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up, {int up_bw =0 , down_bw =0 ; -if (!tb_tunnel_is_active (tunnel)) - goto out; - -if (tunnel->consumed_bandwidth) { +if (tb_tunnel_is_active (tunnel) && tunnel->consumed_bandwidth) {int ret; ret = tunnel->consumed_bandwidth (tunnel, &up_bw, &down_bw);if (ret)return ret; - -tb_tunnel_dbg (tunnel,"consumed bandwidth %d/%d Mb/s\n" , up_bw, - down_bw); } -out:if (consumed_up) *consumed_up = up_bw;if (consumed_down) *consumed_down = down_bw; +tb_tunnel_dbg (tunnel,"consumed bandwidth %d/%d Mb/s\n" , up_bw, down_bw);return 0 ; }
Signature · 1 line
2.45.2
PATCH 7/12 thunderbolt: Rework how tunnel->[init|deinit] hooks are called
In reply to Mika WesterbergThe way these are called is not exactly symmetric as it is supposed to
be: the former is called when tunnel is being activated and the latter is called when it is being released (not when it is being de-activated).
Furthermore host-to-host (DMA) tunnels are abusing the ->deinit hook to clear out the credits. This makes it quite hard to follow what is being called and when.
For these reasons rework the two "init" hooks to be called symmetrically and rename them accordingly. For the DMA one, add a new hook that is specifically used to run clean up for the tunnel when its memory is being released.
--- drivers/thunderbolt/tunnel.c | 37 +++++++++++++++++++----------------- drivers/thunderbolt/tunnel.h | 13 +++++++++---- 2 files changed, 29 insertions(+), 21 deletions(-)
drivers/thunderbolt/tunnel.c +20 -17
@@ -851,7 +851,7 @@ static int tb_dp_bandwidth_alloc_mode_enable(struct tb_tunnel *tunnel)return 0 ; } -static int tb_dp_init (struct tb_tunnel *tunnel) +static int tb_dp_pre_activate (struct tb_tunnel *tunnel) {struct tb_port *in = tunnel->src_port;struct tb_switch *sw = in->sw;
@@ -877,7 +877,7 @@ static int tb_dp_init(struct tb_tunnel *tunnel)return tb_dp_bandwidth_alloc_mode_enable (tunnel); } -static void tb_dp_deinit (struct tb_tunnel *tunnel) +static void tb_dp_post_deactivate (struct tb_tunnel *tunnel) {struct tb_port *in = tunnel->src_port;
@@ -1368,9 +1368,9 @@ struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,if (!tunnel)return NULL ; - tunnel->init = tb_dp_init; - tunnel->deinit = tb_dp_deinit; + tunnel->pre_activate = tb_dp_pre_activate; tunnel->activate = tb_dp_activate; + tunnel->post_deactivate = tb_dp_post_deactivate; tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth;
@@ -1464,9 +1464,9 @@ struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,if (!tunnel)return NULL ; - tunnel->init = tb_dp_init; - tunnel->deinit = tb_dp_deinit; + tunnel->pre_activate = tb_dp_pre_activate; tunnel->activate = tb_dp_activate; + tunnel->post_deactivate = tb_dp_post_deactivate; tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth;
@@ -1623,7 +1623,7 @@ static void tb_dma_release_credits(struct tb_path_hop *hop) } } -static void tb_dma_deinit_path (struct tb_path *path) +static void tb_dma_destroy_path (struct tb_path *path) {struct tb_path_hop *hop;
@@ -1631,14 +1631,14 @@ static void tb_dma_deinit_path(struct tb_path *path)tb_dma_release_credits (hop); } -static void tb_dma_deinit (struct tb_tunnel *tunnel) +static void tb_dma_destroy (struct tb_tunnel *tunnel) {int i;for (i =0 ; i < tunnel->npaths; i++) {if (!tunnel->paths[i])continue ; -tb_dma_deinit_path (tunnel->paths[i]); +tb_dma_destroy_path (tunnel->paths[i]); } }
@@ -1684,7 +1684,7 @@ struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, tunnel->src_port = nhi; tunnel->dst_port = dst; - tunnel->deinit = tb_dma_deinit; + tunnel->destroy = tb_dma_destroy; credits =min_not_zero (dma_credits, nhi->sw->max_dma_credits);
@@ -1796,7 +1796,7 @@ static int tb_usb3_max_link_rate(struct tb_port *up, struct tb_port *down)return min (up_max_rate, down_max_rate); } -static int tb_usb3_init (struct tb_tunnel *tunnel) +static int tb_usb3_pre_activate (struct tb_tunnel *tunnel) {tb_tunnel_dbg (tunnel,"allocating initial bandwidth %d/%d Mb/s\n" , tunnel->allocated_up, tunnel->allocated_down);
@@ -2027,7 +2027,7 @@ struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,tb_tunnel_dbg (tunnel,"currently allocated bandwidth %d/%d Mb/s\n" , tunnel->allocated_up, tunnel->allocated_down); - tunnel->init = tb_usb3_init; + tunnel->pre_activate = tb_usb3_pre_activate; tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; tunnel->release_unused_bandwidth = tb_usb3_release_unused_bandwidth;
@@ -2116,7 +2116,7 @@ struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up, tunnel->allocated_up =min (max_rate, max_up); tunnel->allocated_down =min (max_rate, max_down); - tunnel->init = tb_usb3_init; + tunnel->pre_activate = tb_usb3_pre_activate; tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; tunnel->release_unused_bandwidth = tb_usb3_release_unused_bandwidth;
@@ -2140,8 +2140,8 @@ void tb_tunnel_free(struct tb_tunnel *tunnel)if (!tunnel)return ; -if (tunnel->deinit) - tunnel->deinit (tunnel); +if (tunnel->destroy) + tunnel->destroy (tunnel);for (i =0 ; i < tunnel->npaths; i++) {if (tunnel->paths[i])
@@ -2192,8 +2192,8 @@ int tb_tunnel_restart(struct tb_tunnel *tunnel) } } -if (tunnel->init) { - res = tunnel->init (tunnel); +if (tunnel->pre_activate) { + res = tunnel->pre_activate (tunnel);if (res)return res; }
@@ -2256,6 +2256,9 @@ void tb_tunnel_deactivate(struct tb_tunnel *tunnel)if (tunnel->paths[i] && tunnel->paths[i]->activated)tb_path_deactivate (tunnel->paths[i]); } + +if (tunnel->post_deactivate) + tunnel->post_deactivate (tunnel); }/**
drivers/thunderbolt/tunnel.h +9 -4
@@ -26,9 +26,13 @@ enum tb_tunnel_type {* tunnels may be %NULL or null adapter port instead. * @paths: All paths required by the tunnel * @npaths: Number of paths in @paths -* @init: Optional tunnel specific initialization -* @deinit: Optional tunnel specific de-initialization +* @pre_activate: Optional tunnel specific initialization called before +* activation. Can touch hardware. * @activate: Optional tunnel specific activation/deactivation +* @post_deactivate: Optional tunnel specific de-initialization called +* after deactivation. Can touch hardware. +* @destroy: Optional tunnel specific callback called when the tunnel +* memory is being released. Should not touch hardware. * @maximum_bandwidth: Returns maximum possible bandwidth for this tunnel * @allocated_bandwidth: Return how much bandwidth is allocated for the tunnel * @alloc_bandwidth: Change tunnel bandwidth allocation
@@ -52,9 +56,10 @@ struct tb_tunnel {struct tb_port *dst_port;struct tb_path **paths;size_t npaths; -int (*init)(struct tb_tunnel *tunnel); -void (*deinit)(struct tb_tunnel *tunnel); +int (*pre_activate)(struct tb_tunnel *tunnel);int (*activate)(struct tb_tunnel *tunnel,bool activate); +void (*post_deactivate)(struct tb_tunnel *tunnel); +void (*destroy)(struct tb_tunnel *tunnel);int (*maximum_bandwidth)(struct tb_tunnel *tunnel,int *max_up,int *max_down); int (*allocated_bandwidth)(struct tb_tunnel *tunnel, int *allocated_up,
Signature · 1 line
2.45.2
PATCH 10/12 thunderbolt: Move forward declarations in one place
In reply to Mika WesterbergSometimes we need to have these but move them into one place so that the code is bit more understanable.
--- drivers/thunderbolt/tb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thunderbolt/tb.c +1 -2
@@ -76,6 +76,7 @@ struct tb_hotplug_event {bool unplug; }; +static void tb_scan_port (struct tb_port *port);static void tb_handle_hotplug (struct work_struct *work);static void tb_queue_hotplug (struct tb *tb,u64 route,u8 port,bool unplug)
@@ -1238,8 +1239,6 @@ static void tb_configure_link(struct tb_port *down, struct tb_port *up,tb_switch_configure_link (sw); } -static void tb_scan_port (struct tb_port *port); -/* * tb_scan_switch() - scan for and initialize downstream switches */
Signature · 1 line
2.45.2
PATCH 12/12 thunderbolt: Handle DisplayPort tunnel activation asynchronously
In reply to Mika WesterbergSometimes setting up a DisplayPort tunnel may take quite long time. The reason is that the graphics driver (DPRX) is expected to issue read of certain monitor capabilities over the AUX channel and the "suggested" timeout from VESA is 5 seconds. If there is no graphics driver loaded this does not happen and currently we timeout and tear the tunnel down. The reason for this is that at least Intel discrete USB4 controllers do not send plug/unplug events about whether the DisplayPort cable from the GPU to the controller is connected or not, so in order to "release" the DisplayPort OUT adapter (the one that has monitor connected) we must tear the tunnel down after this timeout has been elapsed.
In typical cases there is always graphics driver loaded, and also all the cables are connected but for instance in Intel graphics CI they only load the graphics driver after the system is fully booted up. This makes the driver to tear down the DisplayPort tunnel. To help this case we allow passing bigger or indefinite timeout through a new module parameter (dprx_timeout). To keep the driver bit more responsive during that time we change the way DisplayPort tunnels get activated. We first do the normal tunnel setup and then run the polling of DPRX capabilities read completion in a separate worker. This also makes the driver to accept bandwidth requests to already established DisplayPort tunnels more responsive.
If the tunnel still fails to establish we will tear it down and remove the DisplayPort IN adapter from the dp_resource list to avoid using it again (unless we get hotplug to that adapter).
--- drivers/thunderbolt/tb.c | 174 +++++++++++++----- drivers/thunderbolt/test.c | 90 ++++----- drivers/thunderbolt/tunnel.c | 341 +++++++++++++++++++++++------------ drivers/thunderbolt/tunnel.h | 47 ++++- 4 files changed, 444 insertions(+), 208 deletions(-)
drivers/thunderbolt/tb.c +127 -47
@@ -19,6 +19,12 @@#define TB_TIMEOUT 100/* ms */ #define TB_RELEASE_BW_TIMEOUT 10000/* ms */ +/* +* How many time bandwidth allocation request from graphics driver is +* retried if the DP tunnel is still activating. +*/ +#define TB_BW_ALLOC_RETRIES 3 +/* * Minimum bandwidth (in Mb/s) that is needed in the single transmitter/receiver * direction. This is 40G - 10% guard band bandwidth.
@@ -69,15 +75,20 @@ static inline struct tb *tcm_to_tb(struct tb_cm *tcm) }struct tb_hotplug_event { -struct work_struct work; +struct delayed_work work;struct tb *tb;u64 route;u8 port;bool unplug; +int retry; };static void tb_scan_port (struct tb_port *port);static void tb_handle_hotplug (struct work_struct *work); +static void tb_dp_resource_unavailable (struct tb *tb,struct tb_port *port, +const char *reason); +static void tb_queue_dp_bandwidth_request (struct tb *tb,u64 route,u8 port, +int retry,unsigned long delay);static void tb_queue_hotplug (struct tb *tb,u64 route,u8 port,bool unplug) {
@@ -91,8 +102,8 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) ev->route = route; ev->port = port; ev->unplug = unplug; -INIT_WORK (&ev->work, tb_handle_hotplug); -queue_work (tb->wq, &ev->work); +INIT_DELAYED_WORK (&ev->work, tb_handle_hotplug); +queue_delayed_work (tb->wq, &ev->work,0 ); }/* enumeration & hot plug handling */
@@ -962,7 +973,7 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)return 0 ; err_free: -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); err_reclaim:if (tb_route (parent))tb_reclaim_usb3_bandwidth (tb, down, up);
@@ -1726,7 +1737,7 @@ static void tb_deactivate_and_free_tunnel(struct tb_tunnel *tunnel)break ; } -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); }/*
@@ -1863,12 +1874,76 @@ static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in)return NULL ; } +static void tb_dp_tunnel_active (struct tb_tunnel *tunnel,void *data) +{ +struct tb_port *in = tunnel->src_port; +struct tb_port *out = tunnel->dst_port; +struct tb *tb = data; + +mutex_lock (&tb->lock); +if (tb_tunnel_is_active (tunnel)) { +int consumed_up, consumed_down, ret; + +tb_tunnel_dbg (tunnel,"DPRX capabilities read completed\n" ); + +/* If fail reading tunnel's consumed bandwidth, tear it down */ + ret =tb_tunnel_consumed_bandwidth (tunnel, &consumed_up, + &consumed_down); +if (ret) { +tb_tunnel_warn (tunnel, +"failed to read consumed bandwidth, tearing down\n" ); +tb_deactivate_and_free_tunnel (tunnel); + }else { +tb_reclaim_usb3_bandwidth (tb, in, out); +/* +* Transition the links to asymmetric if the +* consumption exceeds the threshold. +*/ +tb_configure_asym (tb, in, out, consumed_up, + consumed_down); +/* +* Update the domain with the new bandwidth +* estimation. +*/ +tb_recalc_estimated_bandwidth (tb); +/* +* In case of DP tunnel exists, change host +* router's 1st children TMU mode to HiFi for +* CL0s to work. +*/ +tb_increase_tmu_accuracy (tunnel); + } + }else { +struct tb_port *in = tunnel->src_port; + +/* +* This tunnel failed to establish. This means DPRX +* negotiation most likely did not complete which +* happens either because there is no graphics driver +* loaded or not all DP cables where connected to the +* discrete router. +* +* In both cases we remove the DP IN adapter from the +* available resources as it is not usable. This will +* also tear down the tunnel and try to re-use the +* released DP OUT. +* +* It will be added back only if there is hotplug for +* the DP IN again. +*/ +tb_tunnel_warn (tunnel,"not active, tearing down\n" ); +tb_dp_resource_unavailable (tb, in,"DPRX negotiation failed" ); + } +mutex_unlock (&tb->lock); + +tb_domain_put (tb); +} +static void tb_tunnel_one_dp (struct tb *tb,struct tb_port *in,struct tb_port *out) {int available_up, available_down, ret, link_nr;struct tb_cm *tcm =tb_priv (tb); -int consumed_up, consumed_down;struct tb_tunnel *tunnel;/*
@@ -1920,47 +1995,29 @@ static void tb_tunnel_one_dp(struct tb *tb, struct tb_port *in, available_up, available_down); tunnel =tb_tunnel_alloc_dp (tb, in, out, link_nr, available_up, - available_down); + available_down, tb_dp_tunnel_active, +tb_domain_get (tb));if (!tunnel) {tb_port_dbg (out,"could not allocate DP tunnel\n" ); goto err_reclaim_usb; } -if (tb_tunnel_activate (tunnel)) { +list_add_tail (&tunnel->list, &tcm->tunnel_list); + + ret =tb_tunnel_activate (tunnel); +if (ret && ret != -EINPROGRESS ) {tb_port_info (out,"DP tunnel activation failed, aborting\n" ); +list_del (&tunnel->list); goto err_free; } -/* If fail reading tunnel's consumed bandwidth, tear it down */ - ret =tb_tunnel_consumed_bandwidth (tunnel, &consumed_up, &consumed_down); -if (ret) - goto err_deactivate; - -list_add_tail (&tunnel->list, &tcm->tunnel_list); - -tb_reclaim_usb3_bandwidth (tb, in, out); -/* -* Transition the links to asymmetric if the consumption exceeds -* the threshold. -*/ -tb_configure_asym (tb, in, out, consumed_up, consumed_down); - -/* Update the domain with the new bandwidth estimation */ -tb_recalc_estimated_bandwidth (tb); - -/* -* In case of DP tunnel exists, change host router's 1st children -* TMU mode to HiFi for CL0s to work. -*/ -tb_increase_tmu_accuracy (tunnel);return ; -err_deactivate: -tb_tunnel_deactivate (tunnel); err_free: -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); err_reclaim_usb:tb_reclaim_usb3_bandwidth (tb, in, out); +tb_domain_put (tb); err_detach_group:tb_detach_bandwidth_group (in); err_dealloc_dp:
@@ -2180,7 +2237,7 @@ static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)tb_tunnel_deactivate (tunnel);list_del (&tunnel->list); -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel);return 0 ; }
@@ -2210,7 +2267,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)if (tb_tunnel_activate (tunnel)) {tb_port_info (up,"PCIe tunnel activation failed, aborting\n" ); -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel);return -EIO ; }
@@ -2269,7 +2326,7 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,return 0 ; err_free: -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); err_clx:tb_enable_clx (sw);mutex_unlock (&tb->lock);
@@ -2332,7 +2389,7 @@ static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,*/ static void tb_handle_hotplug (struct work_struct *work) { -struct tb_hotplug_event *ev =container_of (work,typeof (*ev), work); +struct tb_hotplug_event *ev =container_of (work,typeof (*ev), work.work);struct tb *tb = ev->tb;struct tb_cm *tcm =tb_priv (tb);struct tb_switch *sw;
@@ -2637,7 +2694,7 @@ static int tb_alloc_dp_bandwidth(struct tb_tunnel *tunnel, int *requested_up,static void tb_handle_dp_bandwidth_request (struct work_struct *work) { -struct tb_hotplug_event *ev =container_of (work,typeof (*ev), work); +struct tb_hotplug_event *ev =container_of (work,typeof (*ev), work.work);int requested_bw, requested_up, requested_down, ret;struct tb_tunnel *tunnel;struct tb *tb = ev->tb;
@@ -2664,7 +2721,7 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) goto put_sw; } -tb_port_dbg (in,"handling bandwidth allocation request\n" ); +tb_port_dbg (in,"handling bandwidth allocation request, retry %d\n" , ev->retry); tunnel =tb_find_tunnel (tb,TB_TUNNEL_DP , in,NULL );if (!tunnel) {
@@ -2717,12 +2774,33 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work) ret =tb_alloc_dp_bandwidth (tunnel, &requested_up, &requested_down);if (ret) { -if (ret == -ENOBUFS ) +if (ret == -ENOBUFS ) {tb_tunnel_warn (tunnel,"not enough bandwidth available\n" ); -else + }else if (ret == -ENOTCONN ) { +tb_tunnel_dbg (tunnel,"not active yet\n" ); +/* +* We got bandwidth allocation request but the +* tunnel is not yet active. This means that +* tb_dp_tunnel_active() is not yet called for +* this tunnel. Allow it some time and retry +* this request a couple of times. +*/ +if (ev->retry <TB_BW_ALLOC_RETRIES ) { +tb_tunnel_dbg (tunnel, +"retrying bandwidth allocation request\n" ); +tb_queue_dp_bandwidth_request (tb, ev->route, + ev->port, + ev->retry +1 , +msecs_to_jiffies (50 )); + }else { +tb_tunnel_dbg (tunnel, +"run out of retries, failing the request" ); + } + }else {tb_tunnel_warn (tunnel,"failed to change bandwidth allocation\n" ); + } }else { tb_tunnel_dbg(tunnel, "bandwidth allocation changed to %d/%d Mb/s\n",
@@ -2743,7 +2821,8 @@ static void tb_handle_dp_bandwidth_request(struct work_struct *work)kfree (ev); } -static void tb_queue_dp_bandwidth_request (struct tb *tb,u64 route,u8 port) +static void tb_queue_dp_bandwidth_request (struct tb *tb,u64 route,u8 port, +int retry,unsigned long delay) {struct tb_hotplug_event *ev;
@@ -2754,8 +2833,9 @@ static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port) ev->tb = tb; ev->route = route; ev->port = port; -INIT_WORK (&ev->work, tb_handle_dp_bandwidth_request); -queue_work (tb->wq, &ev->work); + ev->retry = retry; +INIT_DELAYED_WORK (&ev->work, tb_handle_dp_bandwidth_request); +queue_delayed_work (tb->wq, &ev->work, delay); } static void tb_handle_notification(struct tb *tb, u64 route,
@@ -2775,7 +2855,7 @@ static void tb_handle_notification(struct tb *tb, u64 route,if (tb_cfg_ack_notification (tb->ctl, route, error))tb_warn (tb,"could not ack notification on %llx\n" , route); -tb_queue_dp_bandwidth_request (tb, route, error->port); +tb_queue_dp_bandwidth_request (tb, route, error->port,0 ,0 );break ;default :
@@ -2830,7 +2910,7 @@ static void tb_stop(struct tb *tb)*/ if (tb_tunnel_is_dma (tunnel))tb_tunnel_deactivate (tunnel); -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); }tb_switch_remove (tb->root_switch); tcm->hotplug_active = false;/* signal tb_handle_hotplug to quit */
@@ -3026,7 +3106,7 @@ static int tb_resume_noirq(struct tb *tb)if (tb_tunnel_is_usb3 (tunnel)) usb3_delay =500 ;tb_tunnel_deactivate (tunnel); -tb_tunnel_free (tunnel); +tb_tunnel_put (tunnel); }/* Re-create our tunnels now */
drivers/thunderbolt/test.c +45 -45
306 lines not on this page · raw message
drivers/thunderbolt/tunnel.c +227 -114
538 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +45 -2
94 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH 5/12 thunderbolt: Make tb_tunnel_one_dp() return void
In reply to Mika WesterbergThe boolean return value is never used so we can make this return void instead.
--- drivers/thunderbolt/tb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thunderbolt/tb.c +2 -4
@@ -1864,7 +1864,7 @@ static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in)return NULL ; } -static bool tb_tunnel_one_dp (struct tb *tb,struct tb_port *in, +static void tb_tunnel_one_dp (struct tb *tb,struct tb_port *in,struct tb_port *out) {int available_up, available_down, ret, link_nr;
@@ -1954,7 +1954,7 @@ static bool tb_tunnel_one_dp(struct tb *tb, struct tb_port *in,* TMU mode to HiFi for CL0s to work. */ tb_increase_tmu_accuracy (tunnel); -return true; +return ; err_deactivate:tb_tunnel_deactivate (tunnel);
@@ -1971,8 +1971,6 @@ static bool tb_tunnel_one_dp(struct tb *tb, struct tb_port *in,pm_runtime_put_autosuspend (&out->sw->dev);pm_runtime_mark_last_busy (&in->sw->dev);pm_runtime_put_autosuspend (&in->sw->dev); - -return false; }static void tb_tunnel_dp (struct tb *tb)
Signature · 1 line
2.45.2
PATCH 8/12 thunderbolt: Drop tb_tunnel_restart()
In reply to Mika WesterbergIt is pretty much the same as tb_tunnel_activate() excepts does check for already activated paths. This is not needed anymore and makes it more streamlined so drop tb_tunnel_restart() in favour of tb_tunnel_activate().
--- drivers/thunderbolt/tb.c | 4 ++-- drivers/thunderbolt/tunnel.c | 27 +++------------------------ drivers/thunderbolt/tunnel.h | 1 - 3 files changed, 5 insertions(+), 27 deletions(-)
drivers/thunderbolt/tb.c +2 -2
@@ -3037,7 +3037,7 @@ static int tb_resume_noirq(struct tb *tb)/* Only need to do it once */ usb3_delay =0 ; } -tb_tunnel_restart (tunnel); +tb_tunnel_activate (tunnel); }if (!list_empty (&tcm->tunnel_list)) {/*
@@ -3147,7 +3147,7 @@ static int tb_runtime_resume(struct tb *tb)tb_free_invalid_tunnels (tb);tb_restore_children (tb->root_switch);list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list) -tb_tunnel_restart (tunnel); +tb_tunnel_activate (tunnel);tb_switch_enter_redrive (tb->root_switch); tcm->hotplug_active = true;mutex_unlock (&tb->lock);
drivers/thunderbolt/tunnel.c +3 -24
@@ -2170,12 +2170,12 @@ bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel) }/** -* tb_tunnel_restart() - activate a tunnel after a hardware reset -* @tunnel: Tunnel to restart +* tb_tunnel_activate() - activate a tunnel +* @tunnel: Tunnel to activate * * Return: 0 on success and negative errno in case if failure */ -int tb_tunnel_restart (struct tb_tunnel *tunnel) +int tb_tunnel_activate (struct tb_tunnel *tunnel) {int res, i;
@@ -2218,27 +2218,6 @@ int tb_tunnel_restart(struct tb_tunnel *tunnel)return res; } -/** -* tb_tunnel_activate() - activate a tunnel -* @tunnel: Tunnel to activate -* -* Return: Returns 0 on success or an error code on failure. -*/ -int tb_tunnel_activate (struct tb_tunnel *tunnel) -{ -int i; - -for (i =0 ; i < tunnel->npaths; i++) { -if (tunnel->paths[i]->activated) { -tb_tunnel_WARN (tunnel, -"trying to activate an already activated tunnel\n" ); -return -EINVAL ; - } - } - -return tb_tunnel_restart (tunnel); -} -/** * tb_tunnel_deactivate() - deactivate a tunnel * @tunnel: Tunnel to deactivate
drivers/thunderbolt/tunnel.h +0 -1
@@ -106,7 +106,6 @@ struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,void tb_tunnel_free (struct tb_tunnel *tunnel);int tb_tunnel_activate (struct tb_tunnel *tunnel); -int tb_tunnel_restart (struct tb_tunnel *tunnel);void tb_tunnel_deactivate (struct tb_tunnel *tunnel);bool tb_tunnel_is_invalid (struct tb_tunnel *tunnel); bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
Signature · 1 line
2.45.2
Re: [PATCH 12/12] thunderbolt: Handle DisplayPort tunnel activation asynchronously
In reply to Mika WesterbergQuoted 11 lines · Mika Westerberg
In typical cases there is always graphics driver loaded, and also all the cables are connected but for instance in Intel graphics CI they only load the graphics driver after the system is fully booted up. This makes the driver to tear down the DisplayPort tunnel. To help this case we allow passing bigger or indefinite timeout through a new module parameter (
dprx_timeout). To keep the driver bit more responsive during that time we change the way DisplayPort tunnels get activated. We first do the normal tunnel setup and then run the polling of DPRX capabilities read completion in a separate worker. This also makes the driver to accept bandwidth requests to already established DisplayPort tunnels more responsive.
Does this mean one has to add that command line option unless i915 is already loaded on boot (or built-in)? I can easily see i915 not being in the initrd for some reason but being loaded only after the root filesystem is mounted. And that in turn may take a while if the user has to enter a password for disk encryption. If the user has to add a command line option in such cases I think that would be very inconvenient.
Thanks,
Lukas
Re: [PATCH 12/12] thunderbolt: Handle DisplayPort tunnel activation asynchronously
Quoted 13 lines · Lukas Wunner
Quoted 11 lines · Mika Westerberg
In typical cases there is always graphics driver loaded, and also all the cables are connected but for instance in Intel graphics CI they only load the graphics driver after the system is fully booted up. This makes the driver to tear down the DisplayPort tunnel. To help this case we allow passing bigger or indefinite timeout through a new module parameter (
dprx_timeout). To keep the driver bit more responsive during that time we change the way DisplayPort tunnels get activated. We first do the normal tunnel setup and then run the polling of DPRX capabilities read completion in a separate worker. This also makes the driver to accept bandwidth requests to already established DisplayPort tunnels more responsive.
Quoted 7 lines
Does this mean one has to add that command line option unless i915 is already loaded on boot (or built-in)? I can easily see i915 not being in the initrd for some reason but being loaded only after the root filesystem is mounted. And that in turn may take a while if the user has to enter a password for disk encryption. If the user has to add a command line option in such cases I think that would be very inconvenient.
Typically no. We wait for the 12s now before tearing down the tunnel and that should be enough for i915 to kick in and read the capabilities. At least we did not see any problems during testing. But the command line option is there as "escape hatch" if defaults don't work.
Mika Westerberg
AppliedQuoted 9 lines · Mika Westerberg
Hi all,
This series provides cleanups and few improvements for DisplayPort tunneling. First of all we increase the DPRX capabilites read timeout to cope with the fact that graphics driver may be runtime suspended. Secondly we move the DPRX negotiation to happen in a separate worker to allow forward progress even if the graphics driver is not yet loaded (this is kind if rare case but common in Intel Graphics CI).
Quoted 13 lines
Mika Westerberg (12):
thunderbolt: Drop doubled empty line fromctl.h
thunderbolt: Log config space when invalid config space reply is received
thunderbolt: Debug log an invalid config space reply just once
thunderbolt: Increase DPRX capabilities read timeout
thunderbolt: Maketb_tunnel_one_dp()return void
thunderbolt: Show path name in debug log when path is deactivated
thunderbolt: Rework how tunnel->[init|deinit] hooks are called
thunderbolt: Droptb_tunnel_restart()
thunderbolt: Pass reason totb_dp_resource_unavailable()
thunderbolt: Move forward declarations in one place
thunderbolt: Reworktb_tunnel_consumed_bandwidth()
thunderbolt: Handle DisplayPort tunnel activation asynchronously
Applied to thunderbolt.git/next.