thunderbolt: Avoid notify PM core about runtime PM resume
Subsystems (2)
PATCH 1/2 thunderbolt: Avoid notify PM core about runtime PM resume
From: Gil Fine <[email protected]>
Currently we notify PM core about occurred wakes after any resume. This is not actually needed after resume from runtime suspend. Hence, notify PM core about occurred wakes only after resume from system sleep. Also, if the wake occurred in USB4 router upstream port, we don't notify the PM core about it since it is not actually needed and can cause unexpected autowake (e.g. if /sys/power/wakeup_count is used).
While there add the missing kernel-doc for tb_switch_resume().
--- drivers/thunderbolt/switch.c | 27 +++++++++++++++++++++++++-- drivers/thunderbolt/tb.c | 4 ++-- drivers/thunderbolt/tb.h | 3 ++- drivers/thunderbolt/usb4.c | 13 +++++++------ 4 files changed, 36 insertions(+), 11 deletions(-)
drivers/thunderbolt/switch.c +25 -2
@@ -3448,7 +3448,26 @@ static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags)return tb_lc_set_wake (sw, flags); } -int tb_switch_resume (struct tb_switch *sw) +static void tb_switch_check_wakes (struct tb_switch *sw) +{ +if (device_may_wakeup (&sw->dev)) { +if (tb_switch_is_usb4 (sw)) +usb4_switch_check_wakes (sw); + } +} + +/** +* tb_switch_resume() - Resume a switch after sleep +* @sw: Switch to resume +* @runtime: Is this resume from runtime suspend or system sleep +* +* Resumes and re-enumerates router (and all its children), if still plugged +* after suspend. Don't enumerate device router whose UID was changed during +* suspend. If this is resume from system sleep, notifies PM core about the +* wakes occurred during suspend. Disables all wakes, except USB4 wake of +* upstream port for USB4 routers that shall be always enabled. +*/ +int tb_switch_resume (struct tb_switch *sw,bool runtime) {struct tb_port *port;int err;
@@ -3497,6 +3516,9 @@ int tb_switch_resume(struct tb_switch *sw)if (err)return err; +if (!runtime) +tb_switch_check_wakes (sw); +/* Disable wakes */ tb_switch_set_wake (sw,0 );
@@ -3526,7 +3548,8 @@ int tb_switch_resume(struct tb_switch *sw)*/ if (tb_port_unlock (port))tb_port_warn (port,"failed to unlock port\n" ); -if (port->remote &&tb_switch_resume (port->remote->sw)) { +if (port->remote && +tb_switch_resume (port->remote->sw, runtime)) {tb_port_warn (port,"lost during suspend, disconnecting\n" );tb_sw_set_unplugged (port->remote->sw);
drivers/thunderbolt/tb.c +2 -2
@@ -2942,7 +2942,7 @@ static int tb_resume_noirq(struct tb *tb)if (!tb_switch_is_usb4 (tb->root_switch))tb_switch_reset (tb->root_switch); -tb_switch_resume (tb->root_switch); +tb_switch_resume (tb->root_switch, false);tb_free_invalid_tunnels (tb);tb_free_unplugged_children (tb->root_switch);tb_restore_children (tb->root_switch);
@@ -3068,7 +3068,7 @@ static int tb_runtime_resume(struct tb *tb)struct tb_tunnel *tunnel, *n;mutex_lock (&tb->lock); -tb_switch_resume (tb->root_switch); +tb_switch_resume (tb->root_switch, true);tb_free_invalid_tunnels (tb);tb_restore_children (tb->root_switch);list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list)
drivers/thunderbolt/tb.h +2 -1
@@ -827,7 +827,7 @@ int tb_switch_configuration_valid(struct tb_switch *sw);int tb_switch_add (struct tb_switch *sw);void tb_switch_remove (struct tb_switch *sw);void tb_switch_suspend (struct tb_switch *sw,bool runtime); -int tb_switch_resume (struct tb_switch *sw); +int tb_switch_resume (struct tb_switch *sw,bool runtime);int tb_switch_reset (struct tb_switch *sw);int tb_switch_wait_for_bit (struct tb_switch *sw,u32 offset,u32 bit,u32 value,int timeout_msec);
@@ -1288,6 +1288,7 @@ static inline bool tb_switch_is_usb4(const struct tb_switch *sw)return usb4_switch_version (sw) >0 ; } +void usb4_switch_check_wakes (struct tb_switch *sw);int usb4_switch_setup (struct tb_switch *sw);int usb4_switch_configuration_valid (struct tb_switch *sw);int usb4_switch_read_uid (struct tb_switch *sw,u64 *uid);
drivers/thunderbolt/usb4.c +7 -6
@@ -155,7 +155,13 @@ static inline int usb4_switch_op_data(struct tb_switch *sw, u16 opcode, tx_dwords, rx_data, rx_dwords); } -static void usb4_switch_check_wakes (struct tb_switch *sw) +/** +* usb4_switch_check_wakes() - Check for wakes and notify PM core about them +* @sw: Router whose wakes to check +* +* Checks wakes occurred during suspend and notify the PM core about them. +*/ +void usb4_switch_check_wakes (struct tb_switch *sw) {bool wakeup_usb4 = false;struct usb4_port *usb4;
@@ -163,9 +169,6 @@ static void usb4_switch_check_wakes(struct tb_switch *sw)bool wakeup = false;u32 val; -if (!device_may_wakeup (&sw->dev)) -return ; -if (tb_route (sw)) {if (tb_sw_read (sw, &val,TB_CFG_SWITCH ,ROUTER_CS_6 ,1 ))return ;
@@ -244,8 +247,6 @@ int usb4_switch_setup(struct tb_switch *sw)u32 val =0 ;int ret; -usb4_switch_check_wakes (sw); -if (!tb_route (sw))return 0 ;
Signature · 1 line
2.43.0
PATCH 2/2 thunderbolt: Fix calculation of consumed USB3 bandwidth on a path
From: Gil Fine <[email protected]>
Currently, when setup a new USB3 tunnel that is starting from downstream USB3 adapter of first depth router (or deeper), to upstream USB3 adapter of a second depth router (or deeper), we calculate consumed bandwidth. For this calculation we take into account first USB3 tunnel consumed bandwidth while we shouldn't, because we just recalculating the first USB3 tunnel allocated bandwidth.
Fix that, so that more bandwidth is available for the new USB3 tunnel being setup.
While there, fix the kernel-doc to decribe more accurately the purpose of the function.
--- drivers/thunderbolt/tb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/thunderbolt/tb.c +5 -4
@@ -498,8 +498,9 @@ static struct tb_tunnel *tb_find_first_usb3_tunnel(struct tb *tb,* @consumed_down: Consumed downstream bandwidth (Mb/s) * * Calculates consumed USB3 and PCIe bandwidth at @port between path -* from @src_port to @dst_port. Does not take tunnel starting from -* @src_port and ending from @src_port into account. +* from @src_port to @dst_port. Does not take USB3 tunnel starting from +* @src_port and ending on @src_port into account because that bandwidth is +* already included in as part of the "first hop" USB3 tunnel. */ static int tb_consumed_usb3_pcie_bandwidth(struct tb *tb, struct tb_port *src_port,
@@ -514,8 +515,8 @@ static int tb_consumed_usb3_pcie_bandwidth(struct tb *tb, *consumed_up = *consumed_down =0 ; tunnel =tb_find_first_usb3_tunnel (tb, src_port, dst_port); -if (tunnel && tunnel->src_port != src_port && - tunnel->dst_port != dst_port) { +if (tunnel && !tb_port_is_usb3_down (src_port) && + !tb_port_is_usb3_up (dst_port)) {int ret; ret = tb_tunnel_consumed_bandwidth(tunnel, consumed_up,
Signature · 1 line
2.43.0
Re: [PATCH 2/2] thunderbolt: Fix calculation of consumed USB3 bandwidth on a path
Quoted 8 lines · Mika Westerberg
From: Gil Fine <[email protected]>
Currently, when setup a new USB3 tunnel that is starting from downstream USB3 adapter of first depth router (or deeper), to upstream USB3 adapter of a second depth router (or deeper), we calculate consumed bandwidth. For this calculation we take into account first USB3 tunnel consumed bandwidth while we shouldn't, because we just recalculating the first USB3 tunnel allocated bandwidth.
Quoted 8 lines
Fix that, so that more bandwidth is available for the new USB3 tunnel being setup.
While there, fix the kernel-doc to decribe more accurately the purpose of the function.
Signed-off-by Gil Fine <[email protected]>Signed-off-by Mika Westerberg <[email protected]>
Please disregard both. I sent a wrong patch with the first one. I'll re-send with correct patches, sorry.