Linux USB
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Mario Limonciello <superm1@kernel.org>,
	andreas.noever@gmail.com, michael.jamet@intel.com,
	westeri@kernel.org, YehezkelShB@gmail.com
Cc: stable@vger.kernel.org,
	Alexander Kovacs <Alexander.Kovacs@amd.com>,
	mika.westerberg@linux.intel.com, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] thunderbolt: Fix wake on connect at runtime
Date: Thu, 19 Jun 2025 16:03:43 -0500	[thread overview]
Message-ID: <fdf78dfa-452c-47c1-8322-c05bb5d2f1bd@amd.com> (raw)
In-Reply-To: <20250619152501.697723-1-superm1@kernel.org>

On 6/19/2025 10:24 AM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> commit 1a760d10ded37 ("thunderbolt: Fix a logic error in wake on connect")
> fixated on the USB4 port sysfs wakeup file not working properly to control
> policy, but it had an unintended side effect that the sysfs file controls
> policy both at runtime and at suspend time. The sysfs file is supposed to
> only control behavior while system is suspended.
> 
> Pass whether programming a port for runtime into usb4_switch_set_wake()
> and if runtime then ignore the value in the sysfs file.
> 
> Cc: stable@vger.kernel.org
> Reported-by: Alexander Kovacs <Alexander.Kovacs@amd.com>
> Tested-by: Alexander Kovacs <Alexander.Kovacs@amd.com>
> Fixes: 1a760d10ded37 ("thunderbolt: Fix a logic error in wake on connect")
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v2:
>   * Fix kdoc issue reported by lkp robot
> ---
>   drivers/thunderbolt/switch.c |  8 ++++----
>   drivers/thunderbolt/tb.h     |  2 +-
>   drivers/thunderbolt/usb4.c   | 10 +++++-----
>   3 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
> index 28febb95f8fa1..e9809fb57c354 100644
> --- a/drivers/thunderbolt/switch.c
> +++ b/drivers/thunderbolt/switch.c
> @@ -3437,7 +3437,7 @@ void tb_sw_set_unplugged(struct tb_switch *sw)
>   	}
>   }
>   
> -static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags)
> +static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime)
>   {
>   	if (flags)
>   		tb_sw_dbg(sw, "enabling wakeup: %#x\n", flags);
> @@ -3445,7 +3445,7 @@ static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags)
>   		tb_sw_dbg(sw, "disabling wakeup\n");
>   
>   	if (tb_switch_is_usb4(sw))
> -		return usb4_switch_set_wake(sw, flags);
> +		return usb4_switch_set_wake(sw, flags, runtime);
>   	return tb_lc_set_wake(sw, flags);
>   }
>   
> @@ -3521,7 +3521,7 @@ int tb_switch_resume(struct tb_switch *sw, bool runtime)
>   		tb_switch_check_wakes(sw);
>   
>   	/* Disable wakes */
> -	tb_switch_set_wake(sw, 0);
> +	tb_switch_set_wake(sw, 0, true);
>   
>   	err = tb_switch_tmu_init(sw);
>   	if (err)
> @@ -3603,7 +3603,7 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)
>   		flags |= TB_WAKE_ON_USB4 | TB_WAKE_ON_USB3 | TB_WAKE_ON_PCIE;
>   	}
>   
> -	tb_switch_set_wake(sw, flags);
> +	tb_switch_set_wake(sw, flags, runtime);
>   
>   	if (tb_switch_is_usb4(sw))
>   		usb4_switch_set_sleep(sw);
> diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
> index 87afd5a7c504b..f503bad864130 100644
> --- a/drivers/thunderbolt/tb.h
> +++ b/drivers/thunderbolt/tb.h
> @@ -1317,7 +1317,7 @@ int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
>   int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
>   			  size_t size);
>   bool usb4_switch_lane_bonding_possible(struct tb_switch *sw);
> -int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags);
> +int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime);
>   int usb4_switch_set_sleep(struct tb_switch *sw);
>   int usb4_switch_nvm_sector_size(struct tb_switch *sw);
>   int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
> diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
> index fce3c0f2354a7..d46d9434933c4 100644
> --- a/drivers/thunderbolt/usb4.c
> +++ b/drivers/thunderbolt/usb4.c
> @@ -403,10 +403,11 @@ bool usb4_switch_lane_bonding_possible(struct tb_switch *sw)
>    * usb4_switch_set_wake() - Enabled/disable wake
>    * @sw: USB4 router
>    * @flags: Wakeup flags (%0 to disable)
> + * @runtime: Wake is being programmed during system runtime
>    *
>    * Enables/disables router to wake up from sleep.
>    */
> -int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
> +int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime)
>   {
>   	struct usb4_port *usb4;
>   	struct tb_port *port;
> @@ -438,13 +439,12 @@ int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
>   			val |= PORT_CS_19_WOU4;
>   		} else {
>   			bool configured = val & PORT_CS_19_PC;
> +			bool wakeup = runtime || device_may_wakeup(&usb4->dev);
>   			usb4 = port->usb4;

Mistake here; at suspend this is causing a problem since the pointer 
isn't assigned 🤦.

I'll follow up with a v3, sorry for the noise.

>   
> -			if (((flags & TB_WAKE_ON_CONNECT) &&
> -			      device_may_wakeup(&usb4->dev)) && !configured)
> +			if ((flags & TB_WAKE_ON_CONNECT) && wakeup && !configured)
>   				val |= PORT_CS_19_WOC;
> -			if (((flags & TB_WAKE_ON_DISCONNECT) &&
> -			      device_may_wakeup(&usb4->dev)) && configured)
> +			if ((flags & TB_WAKE_ON_DISCONNECT) && wakeup && configured)
>   				val |= PORT_CS_19_WOD;
>   			if ((flags & TB_WAKE_ON_USB4) && configured)
>   				val |= PORT_CS_19_WOU4;


      reply	other threads:[~2025-06-19 21:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19 15:24 [PATCH v2] thunderbolt: Fix wake on connect at runtime Mario Limonciello
2025-06-19 21:03 ` Mario Limonciello [this message]

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=fdf78dfa-452c-47c1-8322-c05bb5d2f1bd@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Alexander.Kovacs@amd.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=michael.jamet@intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=stable@vger.kernel.org \
    --cc=superm1@kernel.org \
    --cc=westeri@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox