linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
@ 2025-06-23 19:13 Mario Limonciello
  2025-06-24  7:22 ` Lukas Wunner
  0 siblings, 1 reply; 6+ messages in thread
From: Mario Limonciello @ 2025-06-23 19:13 UTC (permalink / raw)
  To: mario.limonciello, bhelgaas; +Cc: Lukas Wunner, linux-pci

From: Mario Limonciello <mario.limonciello@amd.com>

When a USB4 dock is unplugged the PCIe bridge it's connected to will
issue a "Link Down" and "Card not detected event". The PCI core will
treat this as a surprise hotplug event and unconfigure all downstream
devices. This involves setting the device error state to
`pci_channel_io_perm_failure` which pci_dev_is_disconnected() will check.

It doesn't make sense to runtime resume disconnected devices to D0 and
report the (expected) error, so bail early.

Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v4:
 * no info message
v3:
 * Adjust text and subject
 * Add an info message instead
v2:
 * Use pci_dev_is_disconnected()
v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
---
 drivers/pci/pci.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9e42090fb1089..160a9a482c732 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
 		return -EIO;
 	}
 
+	if (pci_dev_is_disconnected(dev)) {
+		dev->current_state = PCI_D3cold;
+		return -EIO;
+	}
+
 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 	if (PCI_POSSIBLE_ERROR(pmcsr)) {
 		pci_err(dev, "Unable to change power state from %s to D0, device inaccessible\n",
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
  2025-06-23 19:13 [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected Mario Limonciello
@ 2025-06-24  7:22 ` Lukas Wunner
  2025-06-24 10:24   ` Rafael J. Wysocki
  0 siblings, 1 reply; 6+ messages in thread
From: Lukas Wunner @ 2025-06-24  7:22 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: mario.limonciello, bhelgaas, linux-pci, Rafael J. Wysocki,
	Mika Westerberg

[cc += Rafael, Mika]

On Mon, Jun 23, 2025 at 02:13:34PM -0500, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> When a USB4 dock is unplugged the PCIe bridge it's connected to will
> issue a "Link Down" and "Card not detected event". The PCI core will
> treat this as a surprise hotplug event and unconfigure all downstream
> devices. This involves setting the device error state to
> `pci_channel_io_perm_failure` which pci_dev_is_disconnected() will check.
> 
> It doesn't make sense to runtime resume disconnected devices to D0 and
> report the (expected) error, so bail early.
> 
> Suggested-by: Lukas Wunner <lukas@wunner.de>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Reviewed-by: Lukas Wunner <lukas@wunner.de>

> ---
> v4:
>  * no info message
> v3:
>  * Adjust text and subject
>  * Add an info message instead
> v2:
>  * Use pci_dev_is_disconnected()
> v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
> ---
>  drivers/pci/pci.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 9e42090fb1089..160a9a482c732 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
>  		return -EIO;
>  	}
>  
> +	if (pci_dev_is_disconnected(dev)) {
> +		dev->current_state = PCI_D3cold;
> +		return -EIO;
> +	}
> +
>  	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
>  	if (PCI_POSSIBLE_ERROR(pmcsr)) {
>  		pci_err(dev, "Unable to change power state from %s to D0, device inaccessible\n",
> -- 
> 2.43.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
  2025-06-24  7:22 ` Lukas Wunner
@ 2025-06-24 10:24   ` Rafael J. Wysocki
  2025-06-24 15:08     ` Mario Limonciello
  0 siblings, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-06-24 10:24 UTC (permalink / raw)
  To: Lukas Wunner, Mario Limonciello
  Cc: mario.limonciello, bhelgaas, linux-pci, Mika Westerberg

On Tue, Jun 24, 2025 at 9:22 AM Lukas Wunner <lukas@wunner.de> wrote:
>
> [cc += Rafael, Mika]
>
> On Mon, Jun 23, 2025 at 02:13:34PM -0500, Mario Limonciello wrote:
> > From: Mario Limonciello <mario.limonciello@amd.com>
> >
> > When a USB4 dock is unplugged the PCIe bridge it's connected to will
> > issue a "Link Down" and "Card not detected event". The PCI core will
> > treat this as a surprise hotplug event and unconfigure all downstream
> > devices. This involves setting the device error state to
> > `pci_channel_io_perm_failure` which pci_dev_is_disconnected() will check.
> >
> > It doesn't make sense to runtime resume disconnected devices to D0 and
> > report the (expected) error, so bail early.
> >
> > Suggested-by: Lukas Wunner <lukas@wunner.de>
> > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>
> Reviewed-by: Lukas Wunner <lukas@wunner.de>
>
> > ---
> > v4:
> >  * no info message
> > v3:
> >  * Adjust text and subject
> >  * Add an info message instead
> > v2:
> >  * Use pci_dev_is_disconnected()
> > v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
> > ---
> >  drivers/pci/pci.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 9e42090fb1089..160a9a482c732 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
> >               return -EIO;
> >       }
> >
> > +     if (pci_dev_is_disconnected(dev)) {
> > +             dev->current_state = PCI_D3cold;

Why not PCI_UNKNOWN?

> > +             return -EIO;
> > +     }
> > +
> >       pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> >       if (PCI_POSSIBLE_ERROR(pmcsr)) {
> >               pci_err(dev, "Unable to change power state from %s to D0, device inaccessible\n",
> > --
> > 2.43.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
  2025-06-24 10:24   ` Rafael J. Wysocki
@ 2025-06-24 15:08     ` Mario Limonciello
  2025-06-26 12:09       ` Ilpo Järvinen
  2025-06-26 12:31       ` Rafael J. Wysocki
  0 siblings, 2 replies; 6+ messages in thread
From: Mario Limonciello @ 2025-06-24 15:08 UTC (permalink / raw)
  To: Rafael J. Wysocki, Lukas Wunner, Bjorn Helgaas
  Cc: mario.limonciello, linux-pci, Mika Westerberg

On 6/24/25 5:24 AM, Rafael J. Wysocki wrote:
> On Tue, Jun 24, 2025 at 9:22 AM Lukas Wunner <lukas@wunner.de> wrote:
>>
>> [cc += Rafael, Mika]
>>
>> On Mon, Jun 23, 2025 at 02:13:34PM -0500, Mario Limonciello wrote:
>>> From: Mario Limonciello <mario.limonciello@amd.com>
>>>
>>> When a USB4 dock is unplugged the PCIe bridge it's connected to will
>>> issue a "Link Down" and "Card not detected event". The PCI core will
>>> treat this as a surprise hotplug event and unconfigure all downstream
>>> devices. This involves setting the device error state to
>>> `pci_channel_io_perm_failure` which pci_dev_is_disconnected() will check.
>>>
>>> It doesn't make sense to runtime resume disconnected devices to D0 and
>>> report the (expected) error, so bail early.
>>>
>>> Suggested-by: Lukas Wunner <lukas@wunner.de>
>>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>>
>> Reviewed-by: Lukas Wunner <lukas@wunner.de>
>>
>>> ---
>>> v4:
>>>   * no info message
>>> v3:
>>>   * Adjust text and subject
>>>   * Add an info message instead
>>> v2:
>>>   * Use pci_dev_is_disconnected()
>>> v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
>>> ---
>>>   drivers/pci/pci.c | 5 +++++
>>>   1 file changed, 5 insertions(+)
>>>
>>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>>> index 9e42090fb1089..160a9a482c732 100644
>>> --- a/drivers/pci/pci.c
>>> +++ b/drivers/pci/pci.c
>>> @@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
>>>                return -EIO;
>>>        }
>>>
>>> +     if (pci_dev_is_disconnected(dev)) {
>>> +             dev->current_state = PCI_D3cold;
> 
> Why not PCI_UNKNOWN?

It was following what other situations of failure did:
* existing error in pci_power_up()
* error in pci_update_current_state()
* error in pci_set_low_power_state()

I view all of these cases as unrecoverable failures.

So perhaps if changing this one to PCI_UNKNOWN those three should those 
also be PCI_UNKNOWN?

Bjorn, Lukas, thoughts?

> 
>>> +             return -EIO;
>>> +     }
>>> +
>>>        pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
>>>        if (PCI_POSSIBLE_ERROR(pmcsr)) {
>>>                pci_err(dev, "Unable to change power state from %s to D0, device inaccessible\n",
>>> --
>>> 2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
  2025-06-24 15:08     ` Mario Limonciello
@ 2025-06-26 12:09       ` Ilpo Järvinen
  2025-06-26 12:31       ` Rafael J. Wysocki
  1 sibling, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2025-06-26 12:09 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Rafael J. Wysocki, Lukas Wunner, Bjorn Helgaas, mario.limonciello,
	linux-pci, Mika Westerberg

[-- Attachment #1: Type: text/plain, Size: 2812 bytes --]

On Tue, 24 Jun 2025, Mario Limonciello wrote:

> On 6/24/25 5:24 AM, Rafael J. Wysocki wrote:
> > On Tue, Jun 24, 2025 at 9:22 AM Lukas Wunner <lukas@wunner.de> wrote:
> > > 
> > > [cc += Rafael, Mika]
> > > 
> > > On Mon, Jun 23, 2025 at 02:13:34PM -0500, Mario Limonciello wrote:
> > > > From: Mario Limonciello <mario.limonciello@amd.com>
> > > > 
> > > > When a USB4 dock is unplugged the PCIe bridge it's connected to will
> > > > issue a "Link Down" and "Card not detected event". The PCI core will
> > > > treat this as a surprise hotplug event and unconfigure all downstream
> > > > devices. This involves setting the device error state to
> > > > `pci_channel_io_perm_failure` which pci_dev_is_disconnected() will
> > > > check.
> > > > 
> > > > It doesn't make sense to runtime resume disconnected devices to D0 and
> > > > report the (expected) error, so bail early.
> > > > 
> > > > Suggested-by: Lukas Wunner <lukas@wunner.de>
> > > > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> > > 
> > > Reviewed-by: Lukas Wunner <lukas@wunner.de>
> > > 
> > > > ---
> > > > v4:
> > > >   * no info message
> > > > v3:
> > > >   * Adjust text and subject
> > > >   * Add an info message instead
> > > > v2:
> > > >   * Use pci_dev_is_disconnected()
> > > > v1:
> > > > https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
> > > > ---
> > > >   drivers/pci/pci.c | 5 +++++
> > > >   1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > > > index 9e42090fb1089..160a9a482c732 100644
> > > > --- a/drivers/pci/pci.c
> > > > +++ b/drivers/pci/pci.c
> > > > @@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
> > > >                return -EIO;
> > > >        }
> > > > 
> > > > +     if (pci_dev_is_disconnected(dev)) {
> > > > +             dev->current_state = PCI_D3cold;
> > 
> > Why not PCI_UNKNOWN?
> 
> It was following what other situations of failure did:
> * existing error in pci_power_up()
> * error in pci_update_current_state()
> * error in pci_set_low_power_state()
> 
> I view all of these cases as unrecoverable failures.
> 
> So perhaps if changing this one to PCI_UNKNOWN those three should those also
> be PCI_UNKNOWN?
> 
> Bjorn, Lukas, thoughts?
> 
> > 
> > > > +             return -EIO;
> > > > +     }
> > > > +
> > > >        pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> > > >        if (PCI_POSSIBLE_ERROR(pmcsr)) {
> > > >                pci_err(dev, "Unable to change power state from %s to D0,
> > > > device inaccessible\n",

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

(I've no opinion on PCI_UNKNOWN or not.)

-- 
 i.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected
  2025-06-24 15:08     ` Mario Limonciello
  2025-06-26 12:09       ` Ilpo Järvinen
@ 2025-06-26 12:31       ` Rafael J. Wysocki
  1 sibling, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-06-26 12:31 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Rafael J. Wysocki, Lukas Wunner, Bjorn Helgaas, mario.limonciello,
	linux-pci, Mika Westerberg

On Tue, Jun 24, 2025 at 5:08 PM Mario Limonciello <superm1@kernel.org> wrote:
>
> On 6/24/25 5:24 AM, Rafael J. Wysocki wrote:
> > On Tue, Jun 24, 2025 at 9:22 AM Lukas Wunner <lukas@wunner.de> wrote:
> >>
> >> [cc += Rafael, Mika]
> >>
> >> On Mon, Jun 23, 2025 at 02:13:34PM -0500, Mario Limonciello wrote:
> >>> From: Mario Limonciello <mario.limonciello@amd.com>
> >>>
> >>> When a USB4 dock is unplugged the PCIe bridge it's connected to will
> >>> issue a "Link Down" and "Card not detected event". The PCI core will
> >>> treat this as a surprise hotplug event and unconfigure all downstream
> >>> devices. This involves setting the device error state to
> >>> `pci_channel_io_perm_failure` which pci_dev_is_disconnected() will check.
> >>>
> >>> It doesn't make sense to runtime resume disconnected devices to D0 and
> >>> report the (expected) error, so bail early.
> >>>
> >>> Suggested-by: Lukas Wunner <lukas@wunner.de>
> >>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> >>
> >> Reviewed-by: Lukas Wunner <lukas@wunner.de>
> >>
> >>> ---
> >>> v4:
> >>>   * no info message
> >>> v3:
> >>>   * Adjust text and subject
> >>>   * Add an info message instead
> >>> v2:
> >>>   * Use pci_dev_is_disconnected()
> >>> v1: https://lore.kernel.org/linux-usb/20250609020223.269407-1-superm1@kernel.org/T/#mf95c947990d016fbfccfd11afe60b8ae08aafa0b
> >>> ---
> >>>   drivers/pci/pci.c | 5 +++++
> >>>   1 file changed, 5 insertions(+)
> >>>
> >>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> >>> index 9e42090fb1089..160a9a482c732 100644
> >>> --- a/drivers/pci/pci.c
> >>> +++ b/drivers/pci/pci.c
> >>> @@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
> >>>                return -EIO;
> >>>        }
> >>>
> >>> +     if (pci_dev_is_disconnected(dev)) {
> >>> +             dev->current_state = PCI_D3cold;
> >
> > Why not PCI_UNKNOWN?
>
> It was following what other situations of failure did:
> * existing error in pci_power_up()
> * error in pci_update_current_state()
> * error in pci_set_low_power_state()
>
> I view all of these cases as unrecoverable failures.
>
> So perhaps if changing this one to PCI_UNKNOWN those three should those
> also be PCI_UNKNOWN?
>
> Bjorn, Lukas, thoughts?

Note that pci_device_remove() sets power_state to PCI_UNKNOWN, but
only if the old value is PCI_D0, so it would be good to make all of
that consistent at one point.

Anyway, feel free to add

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

to this patch.

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-26 12:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 19:13 [PATCH v4] PCI/PM: Skip resuming to D0 if disconnected Mario Limonciello
2025-06-24  7:22 ` Lukas Wunner
2025-06-24 10:24   ` Rafael J. Wysocki
2025-06-24 15:08     ` Mario Limonciello
2025-06-26 12:09       ` Ilpo Järvinen
2025-06-26 12:31       ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).