Skip to contentSkip to conversation

remove gratuitous reads from maple pci config space methods

RFC/PATCH In review Nathan Lynch 5 participants 15 messages Aug 9, 2007 – Aug 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The maple pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous. Furthermore, this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition. It definitely causes a system hang for me with a Broadcom 5721 PCIE network adapter, which is fixed by this change.

Remove the gratuitous reads from u3_agp_write_config, u3_ht_write_config, and u4_pcie_write_config.

---
 arch/powerpc/platforms/maple/pci.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)
arch/powerpc/platforms/maple/pci.c +0 -9
index 2542403..b095eaa 100644
@@ -169,15 +169,12 @@ static int u3_agp_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -268,15 +265,12 @@ static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -376,15 +370,12 @@ static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
         switch (len) {
         case 1:
                 out_8(addr, val);
-                (void) in_8(addr);
                 break;
         case 2:
                 out_le16(addr, val);
-                (void) in_le16(addr);
                 break;
         default:
                 out_le32(addr, val);
-                (void) in_le32(addr);
                 break;
         }
         return PCIBIOS_SUCCESSFUL;
Signature · 1 line
1.5.2.4
#1 lore raw
Quoted 11 lines · Nathan Lynch

The maple pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous. Furthermore, this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition. It definitely causes a system hang for me with a Broadcom 5721 PCIE network adapter, which is fixed by this change.

Quoted 4 lines

Remove the gratuitous reads from u3_agp_write_config, u3_ht_write_config, and u4_pcie_write_config.

---

Thanks ! Care to fix powermac too ? :-)

Cheers,
Ben.

Quoted 56 lines
---
 arch/powerpc/platforms/maple/pci.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)
arch/powerpc/platforms/maple/pci.c +0 -9
index 2542403..b095eaa 100644
@@ -169,15 +169,12 @@ static int u3_agp_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -268,15 +265,12 @@ static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -376,15 +370,12 @@ static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
         switch (len) {
         case 1:
                 out_8(addr, val);
-                (void) in_8(addr);
                 break;
         case 2:
                 out_le16(addr, val);
-                (void) in_le16(addr);
                 break;
         default:
                 out_le32(addr, val);
-                (void) in_le32(addr);
                 break;
         }
         return PCIBIOS_SUCCESSFUL;
#3 lore raw
Quoted 8 lines · Nathan Lynch
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Nathan Lynch

Remove the gratuitous reads from u3_agp_write_config, u3_ht_write_config, and u4_pcie_write_config.

Quoted 7 lines
Quoted 4 lines

---

Thanks ! Care to fix powermac too ? :-)

Sure, I'll get it tomorrow... looks like pasemi cribbed the powermac code too :)

Allright, thanks !

Cheersm
Ben.

#4 lore raw
In reply to Nathan Lynch
Quoted 8 lines · Nathan Lynch
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Nathan Lynch

Remove the gratuitous reads from u3_agp_write_config, u3_ht_write_config, and u4_pcie_write_config.

Quoted 7 lines
Quoted 4 lines

---

Thanks ! Care to fix powermac too ? :-)

Sure, I'll get it tomorrow... looks like pasemi cribbed the powermac code too :)

Yeah, it originated either from powermac or maple so it's there too. Feel free to fix it too while you're at it.

-Olof

#5 lore raw

PATCH 1/1 remove gratuitous reads from pasemi pci config space methods

The pasemi pci configuration space write method reads the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous. Furthermore, this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition.

Remove the unnecessary reads from pa_pxp_write_config.

---
 arch/powerpc/platforms/pasemi/pci.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
arch/powerpc/platforms/pasemi/pci.c +0 -3
index ab1f5f6..f7da373 100644
@@ -107,15 +107,12 @@ static int pa_pxp_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
Signature · 1 line
1.5.2.4
Acked-by on v1 1/1
#6 lore raw

Re: [PATCH] remove gratuitous reads from pasemi pci config space methods

Quoted 10 lines · Nathan Lynch

The pasemi pci configuration space write method reads the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous. Furthermore, this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition.

Remove the unnecessary reads from pa_pxp_write_config.

Thanks!

Quoted 1 line

-Olof

#7 lore raw

PATCH 1/1 remove gratuitous reads from powermac pci config space methods

In reply to Benjamin Herrenschmidt

The powermac pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous. Furthermore, this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition.

Remove the unnecessary reads from macrisc_write_config, u3_ht_write_config, and u4_pcie_write_config.

---
 arch/powerpc/platforms/powermac/pci.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)
arch/powerpc/platforms/powermac/pci.c +0 -9
index 92586db..bf1f5d1 100644
@@ -209,15 +209,12 @@ static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -440,15 +437,12 @@ static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32((u32 __iomem *)addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
@@ -545,15 +539,12 @@ static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
 	switch (len) {
 	case 1:
 		out_8(addr, val);
-		(void) in_8(addr);
 		break;
 	case 2:
 		out_le16(addr, val);
-		(void) in_le16(addr);
 		break;
 	default:
 		out_le32(addr, val);
-		(void) in_le32(addr);
 		break;
 	}
 	return PCIBIOS_SUCCESSFUL;
Signature · 1 line
1.5.2.4
#8 lore raw
In reply to Nathan Lynch
Quoted 4 lines · Nathan Lynch

The maple pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous.

It might be worth checking that there isn't a particular reason for these. Just because posting writes are forbidden doesn't mean a particular bridge won't screw it up...

Quoted 10 lines

Furthermore,
this behavior potentially causes us to violate the PCI PM spec when changing between e.g. D0 and D3 states, because a delay of up to 10ms may be required before the OS accesses configuration space after the write which initiates the transition. It definitely causes a system hang for me with a Broadcom 5721 PCIE network adapter, which is fixed by this change.

Remove the gratuitous reads from u3_agp_write_config, u3_ht_write_config, and u4_pcie_write_config.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw
Quoted 9 lines · David Gibson
Quoted 4 lines · Nathan Lynch

The maple pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous.

It might be worth checking that there isn't a particular reason for these. Just because posting writes are forbidden doesn't mean a particular bridge won't screw it up...

Well, I had already checked with Ben, who wrote the code, and my understanding is that the reads are intended to work around some misbehaving Apple bridges, but that a sync after the write (implied by releasing pci_lock in the generic pci code) should suffice for those.

#10 lore raw
Quoted 11 lines · Nathan Lynch
Quoted 9 lines · David Gibson
Quoted 4 lines · Nathan Lynch

The maple pci configuration space write methods read the written location immediately after the write is performed, presumably in order to flush the write. However, configuration space writes are not allowed to be posted, making these reads gratuitous.

It might be worth checking that there isn't a particular reason for these. Just because posting writes are forbidden doesn't mean a particular bridge won't screw it up...

Quoted 5 lines

Well, I had already checked with Ben, who wrote the code, and my understanding is that the reads are intended to work around some misbehaving Apple bridges, but that a sync after the write (implied by releasing pci_lock in the generic pci code) should suffice for those.

Ah, ok then.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#11 lore raw
In reply to Nathan Lynch
Quoted 7 lines
Quoted 3 lines

It might be worth checking that there isn't a particular reason for these. Just because posting writes are forbidden doesn't mean a particular bridge won't screw it up...

Well, I had already checked with Ben, who wrote the code, and my understanding is that the reads are intended to work around some misbehaving Apple bridges,

None of the PCI interfaces on the U3 or U4 bridges have that problem as far as I know. I think the workaround was copied from code for older Apple bridges?

Quoted 2 lines

but that a sync after the write (implied by
releasing pci_lock in the generic pci code) should suffice for those.

I don't see how a sync could help here at all, not more than an eieio anyway?

Segher

#12 lore raw
Quoted 11 lines · Segher Boessenkool
Quoted 7 lines
Quoted 3 lines

It might be worth checking that there isn't a particular reason for these. Just because posting writes are forbidden doesn't mean a particular bridge won't screw it up...

Well, I had already checked with Ben, who wrote the code, and my understanding is that the reads are intended to work around some misbehaving Apple bridges,

None of the PCI interfaces on the U3 or U4 bridges have that problem as far as I know. I think the workaround was copied from code for older Apple bridges?

Okay, then the change should be fine for maple.

Quoted 5 lines
Quoted 2 lines

but that a sync after the write (implied by
releasing pci_lock in the generic pci code) should suffice for those.

I don't see how a sync could help here at all, not more than an eieio anyway?

Alright, well, maybe take it up with Ben when I post the patch for powermac, since that's where it could actually matter.

#13 lore raw
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

Well, I had already checked with Ben, who wrote the code, and my understanding is that the reads are intended to work around some misbehaving Apple bridges,

None of the PCI interfaces on the U3 or U4 bridges have that problem as far as I know. I think the workaround was copied from code for older Apple bridges?

Okay, then the change should be fine for maple.

Yes. Of course, as usual, testing is needed, yada yada.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

but that a sync after the write (implied by
releasing pci_lock in the generic pci code) should suffice for those.

I don't see how a sync could help here at all, not more than an eieio anyway?

Alright, well, maybe take it up with Ben when I post the patch for powermac, since that's where it could actually matter.

It should be fine on PowerMac as well -- all G5s use U3/U4, the workaround is for certain older Apple bridge chips.

Segher

#14 lore raw
Quoted 3 lines

It should be fine on PowerMac as well -- all G5s use U3/U4, the workaround is for certain older Apple bridge chips.

Yeah, remove them. The workaround that is needed afaik is really only the one that reads back the -address- before accessing the data register (and I think it's sill needed on U3), but it's unrelated to what that patch changes.

As I said on IRC, I suspect those reads come from misguided attempts on my part to avoid the processor itself posting those writes, since we want config space access to be synchronous all the way. In that case, however, a sync will do the job just fine to ensure the previous write did hit the bridge.

Cheers,
Ben.