MIPS: sgi-ip32: Fence PIO reads on CRIME 1.1
PATCH v2 1/1 MIPS: sgi-ip32: Fence PIO reads on CRIME 1.1
On CRIME 1.1, the next MACE or PCI load after a read of the aic7880 HCNTRL, INTSTAT or ERROR register can return that register's data instead of its own; a gap of about 2us avoids it. Under audio and SCSI DMA, repeating aic7xxx's ahc_pause(), register read, ahc_unpause() can hang; fenced, it runs clean. The next load can be an interrupt handler's, so the fence follows the trigger.
Add a read hook to the MIPS accessors that, on CRIME 1.1, follows each MMIO and port read by 5us with interrupts off. Other platforms compile it out.
---
Changes in v2:
- Reworded the first paragraph of the commit message.
v1: https://lore.kernel.org/r/[email protected]
arch/mips/include/asm/io.h | 11 +++++++ .../include/asm/mach-generic/read-fence.h | 20 +++++++++++++ arch/mips/include/asm/mach-ip32/read-fence.h | 29 +++++++++++++++++++ arch/mips/sgi-ip32/crime.c | 12 ++++++++ 4 files changed, 72 insertions(+) create mode 100644 arch/mips/include/asm/mach-generic/read-fence.h create mode 100644 arch/mips/include/asm/mach-ip32/read-fence.h
arch/mips/include/asm/io.h +11 -0
@@ -26,6 +26,7 @@#include <asm/pgtable-bits.h> #include <asm/string.h> #include <mangle-port.h> +#include <read-fence.h> /* * Raw operations are never swapped in software. OTOH values that raw
@@ -222,6 +223,8 @@ static inline void pfx##write##bwlq(type val, \ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \ { \ volatile type *__mem; \ + unsigned long __rflags; \ + bool __fence; \ type __val; \ \ __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \
@@ -229,6 +232,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \if (barrier) \iobarrier_rw (); \ \ + __fence =plat_read_fence_begin (&__rflags); \if (sizeof (type) !=sizeof (u64) ||sizeof (u64) ==sizeof (long )) \ __val = *__mem; \else if (cpu_has_64bits) { \
@@ -251,6 +255,8 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \ __val =0 ; \BUG (); \ } \ +if (__fence) \ +plat_read_fence_end (__rflags); \ \/* prevent prefetching of coherent DMA data prematurely */ \if (!relax) \
@@ -283,6 +289,8 @@ static inline void pfx##out##bwlq(type val, unsigned long port) \ static inline type pfx##in##bwlq(unsigned long port) \ { \ volatile type *__addr; \ + unsigned long __rflags; \ + bool __fence; \ type __val; \ \ __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
@@ -292,7 +300,10 @@ static inline type pfx##in##bwlq(unsigned long port) \if (barrier) \iobarrier_rw (); \ \ + __fence =plat_read_fence_begin (&__rflags); \ __val = *__addr; \ +if (__fence) \ +plat_read_fence_end (__rflags); \ \/* prevent prefetching of coherent DMA data prematurely */ \if (!relax) \
arch/mips/include/asm/mach-generic/read-fence.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MACH_GENERIC_READ_FENCE_H +#define __ASM_MACH_GENERIC_READ_FENCE_H + +#include <linux/types.h> + +/* +* Called around every MMIO and port read; plat_read_fence_end() runs only +* when plat_read_fence_begin() returned true. +*/ +static inline bool plat_read_fence_begin (unsigned long *flags) +{ +return false; +} + +static inline void plat_read_fence_end (unsigned long flags) +{ +} + +#endif /* __ASM_MACH_GENERIC_READ_FENCE_H */
arch/mips/include/asm/mach-ip32/read-fence.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MACH_IP32_READ_FENCE_H +#define __ASM_MACH_IP32_READ_FENCE_H + +#include <linux/irqflags.h> +#include <linux/types.h> + +extern bool crime_read_fence; +void crime_read_fence_end (unsigned long flags); + +/* +* CRIME 1.1 can return a PCI read's data again to the next MACE or PCI +* read issued within about 2us, so each read is followed by 5us with +* interrupts off. +*/ +static inline bool plat_read_fence_begin (unsigned long *flags) +{ +if (!crime_read_fence) +return false; +local_irq_save (*flags); +return true; +} + +static inline void plat_read_fence_end (unsigned long flags) +{ +crime_read_fence_end (flags); +} + +#endif /* __ASM_MACH_IP32_READ_FENCE_H */
arch/mips/sgi-ip32/crime.c +12 -0
@@ -7,6 +7,7 @@* Copyright (C) 2005 Ilya A. Volynets <[email protected]> */ #include <linux/types.h> +#include <linux/delay.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/interrupt.h>
@@ -25,6 +26,16 @@ struct sgi_mace __iomem *mace;EXPORT_SYMBOL_GPL (mace); +bool crime_read_fence__read_mostly ; +EXPORT_SYMBOL (crime_read_fence); + +void crime_read_fence_end (unsigned long flags) +{ +udelay (5 ); +local_irq_restore (flags); +} +EXPORT_SYMBOL (crime_read_fence_end); +void __init crime_init (void ) {static const char *const revs[] = {"1.1" ,"1.3" ,"1.4" };
@@ -41,6 +52,7 @@ void __init crime_init(void)switch (id &CRIME_ID_IDBITS ) {case CRIME_ID_IDVALUE : rev = revs[min_t (u64, id >>32 ,ARRAY_SIZE (revs) -1 )]; + crime_read_fence = !(id >>32 );break ;case CRIME_ID_IDVALUE_B : rev ="1.5" ;
Signature · 1 line
2.47.3
Quoted 23 lines · Imre Kaloz
arch/mips/include/asm/mach-ip32/read-fence.h new file +17
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_MACH_IP32_READ_FENCE_H +#define __ASM_MACH_IP32_READ_FENCE_H + +#include <linux/irqflags.h> +#include <linux/types.h> + +extern bool crime_read_fence; +void crime_read_fence_end (unsigned long flags); + +/* +* CRIME 1.1 can return a PCI read's data again to the next MACE or PCI +* read issued within about 2us, so each read is followed by 5us with +* interrupts off. +*/ +static inline bool plat_read_fence_begin (unsigned long *flags) +{
arch/mips/include/asm/mach-ip32/read-fence.h line 27
Quoted 10 lines
arch/mips/include/asm/mach-ip32/read-fence.h new file +10
-0+if (!crime_read_fence) +return false; +local_irq_save (*flags); +return true; +} + +static inline void plat_read_fence_end (unsigned long flags) +{ +crime_read_fence_end (flags); +}
This seems hackish to me with the call to local_irq_restore() buried incrime_read_fence_end(). Why is is out of line?
Maciej
Quoted 1 line · Maciej W. Rozycki
On Sat, 7 Nov 2026, Imre Kaloz wrote:
<snip>
Quoted 7 lines
arch/mips/include/asm/mach-ip32/read-fence.h line 27
Quoted 4 lines
arch/mips/include/asm/mach-ip32/read-fence.h new file +4
-0+static inline void plat_read_fence_end (unsigned long flags) +{ +crime_read_fence_end (flags); +}This seems hackish to me with the call to
local_irq_restore()buried incrime_read_fence_end(). Why is is out of line?
Good point, thanks. Only the 5us udelay() needs to be out of line, so that asm/io.h does not have to pull in linux/delay.h, the irq restore had no business being buried in there with it.
v3 keeps local_irq_save() and local_irq_restore() together in read-fence.h and makes only crime_read_fence_delay() out of line.
It has been retested on a CRIME 1.1 O2 with audio and SCSI DMA
running: 0 stale reads in 50M read pairs with the fence on, 15 in 10M with it off.
Thanks,
Imre