linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
@ 2008-07-24 16:18 Alan Cox
  2008-07-24 16:54 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alan Cox @ 2008-07-24 16:18 UTC (permalink / raw)
  To: jeff, greg, linux-kernel

Libata has some hacks to deal with certain controllers going silly in D3
state. The right way to handle this is to keep a PCI device flag for such
devices. That can then be generalised for no ATA devices with power
problems.

Signed-off-by: Alan Cox <alan@redhat.com>

diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index fbe6057..c5f91e6 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -259,12 +259,6 @@ static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
 		.port_ops	= &pacpi_ops,
 	};
 	const struct ata_port_info *ppi[] = { &info, NULL };
-	if (pdev->vendor == PCI_VENDOR_ID_ATI) {
-		int rc = pcim_enable_device(pdev);
-		if (rc < 0)
-			return rc;
-		pcim_pin_device(pdev);
-	}
 	return ata_pci_sff_init_one(pdev, ppi, &pacpi_sht, NULL);
 }
 
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d00f0e0..1f70a9e 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -572,6 +572,10 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 		if (!ret)
 			pci_update_current_state(dev);
 	}
+	/* This device is quirked not to be put into D3, so
+	   don't put it in D3 */
+	if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
+		return 0;
 
 	error = pci_raw_set_power_state(dev, state);
 
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 12d4893..11cc96d 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -908,7 +908,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB
 /*
  *	Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
  */
-static void __init quirk_ide_samemode(struct pci_dev *pdev)
+static void __devinit quirk_ide_samemode(struct pci_dev *pdev)
 {
 	u8 prog;
 
@@ -923,6 +923,19 @@ static void __init quirk_ide_samemode(struct pci_dev *pdev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
 
+/*
+ * Some ATA devices break if put into D3
+ */
+
+static void __devinit quirk_no_ata_d3(struct pci_dev *pdev)
+{
+	/* Quirk the legacy ATA devices only. The AHCI ones are ok */
+	if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
+		pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID, quirk_no_ata_d3);
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID, quirk_no_ata_d3);
+
 /* This was originally an Alpha specific thing, but it really fits here.
  * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
  */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a6a088e..02ebeb5 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -124,6 +124,8 @@ enum pci_dev_flags {
 	 * generation too.
 	 */
 	PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) 1,
+	/* Device configuration is irrevocably lost if disabled into D3 */
+	PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) 2,
 };
 
 typedef unsigned short __bitwise pci_bus_flags_t;

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

* Re: [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
  2008-07-24 16:18 [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI Alan Cox
@ 2008-07-24 16:54 ` Greg KH
  2008-07-24 20:11 ` Jesse Barnes
  2008-09-29  4:17 ` Jeff Garzik
  2 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2008-07-24 16:54 UTC (permalink / raw)
  To: Alan Cox; +Cc: jeff, linux-kernel, jbarnes

On Thu, Jul 24, 2008 at 05:18:38PM +0100, Alan Cox wrote:
> Libata has some hacks to deal with certain controllers going silly in D3
> state. The right way to handle this is to keep a PCI device flag for such
> devices. That can then be generalised for no ATA devices with power
> problems.
> 
> Signed-off-by: Alan Cox <alan@redhat.com>

No objection from me at all, but the current PCI maintainer might want
to also look at it :)

(added Jesse to the CC: with the full patch below.)

thanks,

greg k-h

> 
> diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
> index fbe6057..c5f91e6 100644
> --- a/drivers/ata/pata_acpi.c
> +++ b/drivers/ata/pata_acpi.c
> @@ -259,12 +259,6 @@ static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
>  		.port_ops	= &pacpi_ops,
>  	};
>  	const struct ata_port_info *ppi[] = { &info, NULL };
> -	if (pdev->vendor == PCI_VENDOR_ID_ATI) {
> -		int rc = pcim_enable_device(pdev);
> -		if (rc < 0)
> -			return rc;
> -		pcim_pin_device(pdev);
> -	}
>  	return ata_pci_sff_init_one(pdev, ppi, &pacpi_sht, NULL);
>  }
>  
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index d00f0e0..1f70a9e 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -572,6 +572,10 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
>  		if (!ret)
>  			pci_update_current_state(dev);
>  	}
> +	/* This device is quirked not to be put into D3, so
> +	   don't put it in D3 */
> +	if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
> +		return 0;
>  
>  	error = pci_raw_set_power_state(dev, state);
>  
> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 12d4893..11cc96d 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -908,7 +908,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB
>  /*
>   *	Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
>   */
> -static void __init quirk_ide_samemode(struct pci_dev *pdev)
> +static void __devinit quirk_ide_samemode(struct pci_dev *pdev)
>  {
>  	u8 prog;
>  
> @@ -923,6 +923,19 @@ static void __init quirk_ide_samemode(struct pci_dev *pdev)
>  }
>  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
>  
> +/*
> + * Some ATA devices break if put into D3
> + */
> +
> +static void __devinit quirk_no_ata_d3(struct pci_dev *pdev)
> +{
> +	/* Quirk the legacy ATA devices only. The AHCI ones are ok */
> +	if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
> +		pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
> +}
> +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID, quirk_no_ata_d3);
> +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID, quirk_no_ata_d3);
> +
>  /* This was originally an Alpha specific thing, but it really fits here.
>   * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
>   */
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index a6a088e..02ebeb5 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -124,6 +124,8 @@ enum pci_dev_flags {
>  	 * generation too.
>  	 */
>  	PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) 1,
> +	/* Device configuration is irrevocably lost if disabled into D3 */
> +	PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) 2,
>  };
>  
>  typedef unsigned short __bitwise pci_bus_flags_t;

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

* Re: [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
  2008-07-24 16:18 [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI Alan Cox
  2008-07-24 16:54 ` Greg KH
@ 2008-07-24 20:11 ` Jesse Barnes
  2008-07-24 20:14   ` Alan Cox
  2008-09-29  4:17 ` Jeff Garzik
  2 siblings, 1 reply; 6+ messages in thread
From: Jesse Barnes @ 2008-07-24 20:11 UTC (permalink / raw)
  To: Alan Cox; +Cc: jeff, greg, linux-kernel

On Thursday, July 24, 2008 9:18 am Alan Cox wrote:
> Libata has some hacks to deal with certain controllers going silly in D3
> state. The right way to handle this is to keep a PCI device flag for such
> devices. That can then be generalised for no ATA devices with power
> problems.
>
> Signed-off-by: Alan Cox <alan@redhat.com>

Looks pretty reasonable to me; do you want me to take the drivers/ata bits 
along with the PCI stuff?

Btw, what happens to these devices in D3hot?  Do they behave like they're in 
D3cold or something and require a reset?  Or do they otherwise kill the bus 
somehow?

Thanks,
Jesse

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

* Re: [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
  2008-07-24 20:11 ` Jesse Barnes
@ 2008-07-24 20:14   ` Alan Cox
  2008-07-28 22:14     ` Jesse Barnes
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2008-07-24 20:14 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: jeff, greg, linux-kernel

On Thu, 24 Jul 2008 13:11:24 -0700
Jesse Barnes <jbarnes@virtuousgeek.org> wrote:

> On Thursday, July 24, 2008 9:18 am Alan Cox wrote:
> > Libata has some hacks to deal with certain controllers going silly in D3
> > state. The right way to handle this is to keep a PCI device flag for such
> > devices. That can then be generalised for no ATA devices with power
> > problems.
> >
> > Signed-off-by: Alan Cox <alan@redhat.com>
> 
> Looks pretty reasonable to me; do you want me to take the drivers/ata bits 
> along with the PCI stuff?
> 
> Btw, what happens to these devices in D3hot?  Do they behave like they're in 
> D3cold or something and require a reset?  Or do they otherwise kill the bus 
> somehow?

They lose some of their configuration bits in a manner we can't restore.
The end effect of that is that if we disable/re-enable them they can't be
put back into proper DMA mode.

Windows it seems doesn't do this to these devices and the BIOS re-inits
the legacy ATA controllers during boot up which makes suspend/resume work.

Alan

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

* Re: [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
  2008-07-24 20:14   ` Alan Cox
@ 2008-07-28 22:14     ` Jesse Barnes
  0 siblings, 0 replies; 6+ messages in thread
From: Jesse Barnes @ 2008-07-28 22:14 UTC (permalink / raw)
  To: Alan Cox; +Cc: jeff, greg, linux-kernel

On Thursday, July 24, 2008 1:14 pm Alan Cox wrote:
> On Thu, 24 Jul 2008 13:11:24 -0700
>
> Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> > On Thursday, July 24, 2008 9:18 am Alan Cox wrote:
> > > Libata has some hacks to deal with certain controllers going silly in
> > > D3 state. The right way to handle this is to keep a PCI device flag for
> > > such devices. That can then be generalised for no ATA devices with
> > > power problems.
> > >
> > > Signed-off-by: Alan Cox <alan@redhat.com>
> >
> > Looks pretty reasonable to me; do you want me to take the drivers/ata
> > bits along with the PCI stuff?
> >
> > Btw, what happens to these devices in D3hot?  Do they behave like they're
> > in D3cold or something and require a reset?  Or do they otherwise kill
> > the bus somehow?
>
> They lose some of their configuration bits in a manner we can't restore.
> The end effect of that is that if we disable/re-enable them they can't be
> put back into proper DMA mode.
>
> Windows it seems doesn't do this to these devices and the BIOS re-inits
> the legacy ATA controllers during boot up which makes suspend/resume work.

I applied the PCI bits of this patch to my for-linus branch (see below for
diff), thanks Alan.

Jesse

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c95f77d..0a3d856 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -572,6 +572,10 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t st
                if (!ret)
                        pci_update_current_state(dev);
        }
+       /* This device is quirked not to be put into D3, so
+          don't put it in D3 */
+       if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
+               return 0;

        error = pci_raw_set_power_state(dev, state);

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 12d4893..0fb3650 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -923,6 +923,19 @@ static void __init quirk_ide_samemode(struct pci_dev *pdev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, qu

+/*
+ * Some ATA devices break if put into D3
+ */
+
+static void __devinit quirk_no_ata_d3(struct pci_dev *pdev)
+{
+       /* Quirk the legacy ATA devices only. The AHCI ones are ok */
+       if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
+               pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
+}
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID, quirk_no_ata_d3)
+DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID, quirk_no_ata_d3);
+
 /* This was originally an Alpha specific thing, but it really fits here.
  * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
  */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 1d296d3..825be38 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -124,6 +124,8 @@ enum pci_dev_flags {
         * generation too.
         */
        PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) 1,
+       /* Device configuration is irrevocably lost if disabled into D3 */
+       PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) 2,
 };

 typedef unsigned short __bitwise pci_bus_flags_t;



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

* Re: [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI
  2008-07-24 16:18 [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI Alan Cox
  2008-07-24 16:54 ` Greg KH
  2008-07-24 20:11 ` Jesse Barnes
@ 2008-09-29  4:17 ` Jeff Garzik
  2 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2008-09-29  4:17 UTC (permalink / raw)
  To: Alan Cox; +Cc: greg, linux-kernel

Alan Cox wrote:
> Libata has some hacks to deal with certain controllers going silly in D3
> state. The right way to handle this is to keep a PCI device flag for such
> devices. That can then be generalised for no ATA devices with power
> problems.
> 
> Signed-off-by: Alan Cox <alan@redhat.com>


ACK


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

end of thread, other threads:[~2008-09-29  4:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-24 16:18 [PATCH PROPOSAL] libata/pci: Move D3 hack handling from libata into PCI Alan Cox
2008-07-24 16:54 ` Greg KH
2008-07-24 20:11 ` Jesse Barnes
2008-07-24 20:14   ` Alan Cox
2008-07-28 22:14     ` Jesse Barnes
2008-09-29  4:17 ` Jeff Garzik

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).