Skip to contentSkip to conversation

net: fec: do not use readl()/writel() for ColdFire

RFC In review Greg Ungerer 10 participants 29 messages May 6 – Jun 10

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

RFC 1/4 net: fec: do not use readl()/writel() for ColdFire

From: Greg Ungerer <[email protected]>

Modify the FEC driver to not directly use readl() and writel() to access hardware registers but instead local fec_readl() and fec_writel() methods. This allows for different architecture users of this driver to have different underlying access functions - to support both little and big endian hardware.

The FEC hardware block in ColdFire SoC parts is accessed big-endian. The usual kernel readl()/writel() IO memory access methods are defined to access little endian data. Change access for ColdFire to use __raw_readl() and __raw_writel() access methods - which do not modify or swap bytes on access.

The FEC driver works today because the m68k architecture io.h has a kludge in the definitions of the readl() and writel() functions for ColdFire that allow big-endian access if the address of the register to access is within the SoC's internal peripheral registers. This is being fixed in the near future to define readl() and writel() correctly - with no byte swapping. Thus the motivation for this fix here.

__raw_readl()/__raw_writel() access methods are used instead of the more commonly used ioread32be()/iowrite32be() here because those are broken too, because of the current readl()/writel() kludge. They are implemented in asm-generic/io.h in terms of readl()/writel().

Note that even when readl() and writel() are fixed on ColdFire they will not be the right thing to use within the FEC driver on ColdFire hardware.

---
 drivers/net/ethernet/freescale/fec.h      |  15 ++
 drivers/net/ethernet/freescale/fec_main.c | 254 +++++++++++-----------
 drivers/net/ethernet/freescale/fec_ptp.c  |  78 +++----
 3 files changed, 181 insertions(+), 166 deletions(-)
drivers/net/ethernet/freescale/fec.h +15 -0
index 7176803146f3..af31d946a638 100644
@@ -701,5 +701,20 @@ int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,
 		struct netlink_ext_ack *extack);
 void fec_ptp_get(struct net_device *ndev, struct kernel_hwtstamp_config *config);
 
+/*
+ * ColdFire SoC peripheral blocks are big-endian, so use the raw IO access
+ * functions for them.
+ */
+#ifdef CONFIG_COLDFIRE
+#define fec_readl __raw_readl
+#define fec_writel __raw_writel
+#define fec_readl_poll_timeout_atomic(addr, val, cond, delay_us, timeout_us) \
+	readx_poll_timeout_atomic(__raw_readl, addr, val, cond, delay_us, timeout_us)
+#else
+#define fec_readl readl
+#define fec_writel writel
+#define fec_readl_poll_timeout_atomic readl_poll_timeout_atomic
+#endif
+
 /****************************************************************************/
 #endif /* FEC_H */
drivers/net/ethernet/freescale/fec_main.c +127 -127

628 lines not on this page · raw message

drivers/net/ethernet/freescale/fec_ptp.c +39 -39

208 lines not on this page · raw message

Signature · 1 line
2.54.0
#1 lore raw

RFC 2/4 net: smc91x: do not use readw()/writew() on ColdFire platforms

From: Greg Ungerer <[email protected]>

Modify the access macros and functions used to access the smsc hardware registers when used on ColdFire SoC platforms so they do not use readw() or writew(), or derived functions like ioread16be() and iowrite16be().

The current set of readX()/writeX() access methods for ColdFire have historically been non-standard, in that they mostly access memory big-endian instead of the expected little-endian. Before fixing the ColdFire readX() and writeX() supporting code to properly work with little-endian data existing driver uses need to be fixed. Convert the smsc driver ColdFire uses of these to use the raw access macros - which are well defined to be (native) big-endian on ColdFire. This change requires some byte swapping at time of access to retain existing correct behavior.

---
 drivers/net/ethernet/smsc/smc91x.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/smsc/smc91x.h +8 -4
index 38aa4374e813..1290335629c1 100644
@@ -142,22 +142,26 @@ static inline void _SMC_outw_align4(u16 val, void __iomem *ioaddr, int reg,
 #define SMC_CAN_USE_32BIT	0
 #define SMC_NOWAIT		1
 
+/*
+ * Access SMSC device registers using raw IO access primitives. Byte
+ * swap as required for device registers, but not data.
+ */
 static inline void mcf_insw(void __iomem *a, unsigned char *p, int l)
 {
 	u16 *wp = (u16 *) p;
 	while (l-- > 0)
-		*wp++ = readw(a);
+		*wp++ = __raw_readw(a);
 }
 
 static inline void mcf_outsw(void __iomem *a, unsigned char *p, int l)
 {
 	u16 *wp = (u16 *) p;
 	while (l-- > 0)
-		writew(*wp++, a);
+		__raw_writew(*wp++, a);
 }
 
-#define SMC_inw(a, r)		ioread16be((a) + (r))
-#define SMC_outw(lp, v, a, r)	iowrite16be(v, (a) + (r))
+#define SMC_inw(a, r)		swab16(__raw_readw((a) + (r)))
+#define SMC_outw(lp, v, a, r)	__raw_writew(swab16(v), (a) + (r))
 #define SMC_insw(a, r, p, l)	mcf_insw(a + r, p, l)
 #define SMC_outsw(a, r, p, l)	mcf_outsw(a + r, p, l)
 
Signature · 1 line
2.54.0
#2 lore raw

RFC 3/4 mmc: sdhci-esdhc-mcf: do not use readl()/writel() on ColdFire

In reply to Greg Ungerer

From: Greg Ungerer <[email protected]>

The implementation of the readX() and writeX() family of IO access functions is non-standard on ColdFire platforms. They check the supplied IO address and will return either big or little endian results based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are wrong. This is now in the process of being cleaned up and fixed.

Change the use of the readX() and writeX() access functions in this driver to use the recently defined specific ColdFire internal SoC hardware IO access functions mcf_read8()/mcf_read16()/mcf_read32() and mcf_write8()/mcf_write16()/mcf_write32().

There is no functional change to the driver. Though it does have the effect of making the IO access slightly more efficient, since there is no longer a need to do the address check at every register access.

---
 drivers/mmc/host/sdhci-esdhc-mcf.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Note that the patches to introduce mcf_readX() and mcf_writeX functions are not in mainline yet. They are currently in the m68knommu git tree for-next branch, and so should also be in linux-next.

drivers/mmc/host/sdhci-esdhc-mcf.c +12 -12
index 375fce5639d7..6853521e8b2c 100644
@@ -55,7 +55,7 @@ static inline void esdhc_clrset_be(struct sdhci_host *host,
 	if (reg == SDHCI_HOST_CONTROL)
 		val |= ESDHC_PROCTL_D3CD;
 
-	writel((readl(base) & ~mask) | val, base);
+	mcf_write32((mcf_read32(base) & ~mask) | val, base);
 }
 
 /*
@@ -71,7 +71,7 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
 	if (reg == SDHCI_HOST_CONTROL) {
 		u32 host_ctrl = ESDHC_DEFAULT_HOST_CONTROL;
 		u8 dma_bits = (val & SDHCI_CTRL_DMA_MASK) >> 3;
-		u8 tmp = readb(host->ioaddr + SDHCI_HOST_CONTROL + 1);
+		u8 tmp = mcf_read8(host->ioaddr + SDHCI_HOST_CONTROL + 1);
 
 		tmp &= ~0x03;
 		tmp |= dma_bits;
@@ -82,12 +82,12 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
 		 */
 		host_ctrl |= val;
 		host_ctrl |= (dma_bits << 8);
-		writel(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
+		mcf_write32(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
 
 		return;
 	}
 
-	writel((readl(base) & mask) | (val << shift), base);
+	mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
@@ -110,24 +110,24 @@ static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
 		 * As for the fsl driver,
 		 * we have to set the mode in a single write here.
 		 */
-		writel(val << 16 | mcf_data->aside,
+		mcf_write32(val << 16 | mcf_data->aside,
 		       host->ioaddr + SDHCI_TRANSFER_MODE);
 		return;
 	}
 
-	writel((readl(base) & mask) | (val << shift), base);
+	mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writel_be(struct sdhci_host *host, u32 val, int reg)
 {
-	writel(val, host->ioaddr + reg);
+	mcf_write32(val, host->ioaddr + reg);
 }
 
 static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
 {
 	if (reg == SDHCI_HOST_CONTROL) {
 		u8 __iomem *base = host->ioaddr + (reg & ~3);
-		u16 val = readw(base + 2);
+		u16 val = mcf_read16(base + 2);
 		u8 dma_bits = (val >> 5) & SDHCI_CTRL_DMA_MASK;
 		u8 host_ctrl = val & 0xff;
 
@@ -137,7 +137,7 @@ static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
 		return host_ctrl;
 	}
 
-	return readb(host->ioaddr + (reg ^ 0x3));
+	return mcf_read8(host->ioaddr + (reg ^ 0x3));
 }
 
 static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
@@ -149,14 +149,14 @@ static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
 	if (reg == SDHCI_HOST_VERSION)
 		reg -= 2;
 
-	return readw(host->ioaddr + (reg ^ 0x2));
+	return mcf_read16(host->ioaddr + (reg ^ 0x2));
 }
 
 static u32 esdhc_mcf_readl_be(struct sdhci_host *host, int reg)
 {
 	u32 val;
 
-	val = readl(host->ioaddr + reg);
+	val = mcf_read32(host->ioaddr + reg);
 
 	/*
 	 * RM (25.3.9) sd pin clock must never exceed 25Mhz.
@@ -245,7 +245,7 @@ static void esdhc_mcf_pltfm_set_clock(struct sdhci_host *host,
 	 * fvco = fsys * outdvi1 + 1
 	 * fshdc = fvco / outdiv3 + 1
 	 */
-	temp = readl(pll_dr);
+	temp = mcf_read32(pll_dr);
 	fsys = pltfm_host->clock;
 	fvco = fsys * ((temp & 0x1f) + 1);
 	fesdhc = fvco / (((temp >> 10) & 0x1f) + 1);
Signature · 1 line
2.54.0
#3 lore raw

Re: [RFC 3/4] mmc: sdhci-esdhc-mcf: do not use readl()/writel() on ColdFire

Quoted 21 lines · Greg Ungerer

From: Greg Ungerer <[email protected]>

The implementation of the readX() and writeX() family of IO access functions is non-standard on ColdFire platforms. They check the supplied IO address and will return either big or little endian results based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are wrong. This is now in the process of being cleaned up and fixed.

Change the use of the readX() and writeX() access functions in this driver to use the recently defined specific ColdFire internal SoC hardware IO access functions mcf_read8()/mcf_read16()/mcf_read32() and mcf_write8()/mcf_write16()/mcf_write32().

There is no functional change to the driver. Though it does have the effect of making the IO access slightly more efficient, since there is no longer a need to do the address check at every register access.

Quoted 8 lines
---
 drivers/mmc/host/sdhci-esdhc-mcf.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Note that the patches to introduce mcf_readX() and mcf_writeX functions are not in mainline yet. They are currently in the m68knommu git tree for-next branch, and so should also be in linux-next.

Okay, so please resubmit the $subject patch when the mcf_readX|writeX functions are available in a v7.x-rc so I can pick it up.

Another option is if someone can host an immutable branch for me to pull in the changes for mcf_readX|writeX.

Kind regards
Uffe

Quoted 106 lines
drivers/mmc/host/sdhci-esdhc-mcf.c +12 -13
index 375fce5639d7..6853521e8b2c 100644
@@ -55,7 +55,7 @@ static inline void esdhc_clrset_be(struct sdhci_host *host,
        if (reg == SDHCI_HOST_CONTROL)
                val |= ESDHC_PROCTL_D3CD;
 
-       writel((readl(base) & ~mask) | val, base);
+       mcf_write32((mcf_read32(base) & ~mask) | val, base);
 }
 
 /*
@@ -71,7 +71,7 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
        if (reg == SDHCI_HOST_CONTROL) {
                u32 host_ctrl = ESDHC_DEFAULT_HOST_CONTROL;
                u8 dma_bits = (val & SDHCI_CTRL_DMA_MASK) >> 3;
-               u8 tmp = readb(host->ioaddr + SDHCI_HOST_CONTROL + 1);
+               u8 tmp = mcf_read8(host->ioaddr + SDHCI_HOST_CONTROL + 1);
 
                tmp &= ~0x03;
                tmp |= dma_bits;
@@ -82,12 +82,12 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
                 */
                host_ctrl |= val;
                host_ctrl |= (dma_bits << 8);
-               writel(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
+               mcf_write32(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
 
                return;
        }
 
-       writel((readl(base) & mask) | (val << shift), base);
+       mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
@@ -110,24 +110,24 @@ static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
                 * As for the fsl driver,
                 * we have to set the mode in a single write here.
                 */
-               writel(val << 16 | mcf_data->aside,
+               mcf_write32(val << 16 | mcf_data->aside,
                       host->ioaddr + SDHCI_TRANSFER_MODE);
                return;
        }
 
-       writel((readl(base) & mask) | (val << shift), base);
+       mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writel_be(struct sdhci_host *host, u32 val, int reg)
 {
-       writel(val, host->ioaddr + reg);
+       mcf_write32(val, host->ioaddr + reg);
 }
 
 static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
 {
        if (reg == SDHCI_HOST_CONTROL) {
                u8 __iomem *base = host->ioaddr + (reg & ~3);
-               u16 val = readw(base + 2);
+               u16 val = mcf_read16(base + 2);
                u8 dma_bits = (val >> 5) & SDHCI_CTRL_DMA_MASK;
                u8 host_ctrl = val & 0xff;
 
@@ -137,7 +137,7 @@ static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
                return host_ctrl;
        }
 
-       return readb(host->ioaddr + (reg ^ 0x3));
+       return mcf_read8(host->ioaddr + (reg ^ 0x3));
 }
 
 static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
@@ -149,14 +149,14 @@ static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
        if (reg == SDHCI_HOST_VERSION)
                reg -= 2;
 
-       return readw(host->ioaddr + (reg ^ 0x2));
+       return mcf_read16(host->ioaddr + (reg ^ 0x2));
 }
 
 static u32 esdhc_mcf_readl_be(struct sdhci_host *host, int reg)
 {
        u32 val;
 
-       val = readl(host->ioaddr + reg);
+       val = mcf_read32(host->ioaddr + reg);
 
        /*
         * RM (25.3.9) sd pin clock must never exceed 25Mhz.
@@ -245,7 +245,7 @@ static void esdhc_mcf_pltfm_set_clock(struct sdhci_host *host,
         * fvco = fsys * outdvi1 + 1
         * fshdc = fvco / outdiv3 + 1
         */
-       temp = readl(pll_dr);
+       temp = mcf_read32(pll_dr);
        fsys = pltfm_host->clock;
        fvco = fsys * ((temp & 0x1f) + 1);
        fesdhc = fvco / (((temp >> 10) & 0x1f) + 1);
--

2.54.0

#4 lore raw

Re: [RFC 3/4] mmc: sdhci-esdhc-mcf: do not use readl()/writel() on ColdFire

Quoted 31 lines · Ulf Hansson
Quoted 21 lines · Greg Ungerer

From: Greg Ungerer <[email protected]>

The implementation of the readX() and writeX() family of IO access functions is non-standard on ColdFire platforms. They check the supplied IO address and will return either big or little endian results based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are wrong. This is now in the process of being cleaned up and fixed.

Change the use of the readX() and writeX() access functions in this driver to use the recently defined specific ColdFire internal SoC hardware IO access functions mcf_read8()/mcf_read16()/mcf_read32() and mcf_write8()/mcf_write16()/mcf_write32().

There is no functional change to the driver. Though it does have the effect of making the IO access slightly more efficient, since there is no longer a need to do the address check at every register access.

Quoted 8 lines
---
  drivers/mmc/host/sdhci-esdhc-mcf.c | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)

Note that the patches to introduce mcf_readX() and mcf_writeX functions are not in mainline yet. They are currently in the m68knommu git tree for-next branch, and so should also be in linux-next.

Quoted 5 lines

Okay, so please resubmit the $subject patch when the mcf_readX|writeX functions are available in a v7.x-rc so I can pick it up.

Another option is if someone can host an immutable branch for me to pull in the changes for mcf_readX|writeX.

Those changes are now on an immutable branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu.git
cf-internal-io branch

I will follow up after 7.2-rc1 is out with this patch set as well.

Regards
Greg

Quoted 110 lines

Kind regards
Uffe

Quoted 106 lines
drivers/mmc/host/sdhci-esdhc-mcf.c +12 -13
index 375fce5639d7..6853521e8b2c 100644
@@ -55,7 +55,7 @@ static inline void esdhc_clrset_be(struct sdhci_host *host,
         if (reg == SDHCI_HOST_CONTROL)
                 val |= ESDHC_PROCTL_D3CD;
 
-       writel((readl(base) & ~mask) | val, base);
+       mcf_write32((mcf_read32(base) & ~mask) | val, base);
  }
 
  /*
@@ -71,7 +71,7 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
         if (reg == SDHCI_HOST_CONTROL) {
                 u32 host_ctrl = ESDHC_DEFAULT_HOST_CONTROL;
                 u8 dma_bits = (val & SDHCI_CTRL_DMA_MASK) >> 3;
-               u8 tmp = readb(host->ioaddr + SDHCI_HOST_CONTROL + 1);
+               u8 tmp = mcf_read8(host->ioaddr + SDHCI_HOST_CONTROL + 1);
 
                 tmp &= ~0x03;
                 tmp |= dma_bits;
@@ -82,12 +82,12 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
                  */
                 host_ctrl |= val;
                 host_ctrl |= (dma_bits << 8);
-               writel(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
+               mcf_write32(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
 
                 return;
         }
 
-       writel((readl(base) & mask) | (val << shift), base);
+       mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
  }
 
  static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
@@ -110,24 +110,24 @@ static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
                  * As for the fsl driver,
                  * we have to set the mode in a single write here.
                  */
-               writel(val << 16 | mcf_data->aside,
+               mcf_write32(val << 16 | mcf_data->aside,
                        host->ioaddr + SDHCI_TRANSFER_MODE);
                 return;
         }
 
-       writel((readl(base) & mask) | (val << shift), base);
+       mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
  }
 
  static void esdhc_mcf_writel_be(struct sdhci_host *host, u32 val, int reg)
  {
-       writel(val, host->ioaddr + reg);
+       mcf_write32(val, host->ioaddr + reg);
  }
 
  static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
  {
         if (reg == SDHCI_HOST_CONTROL) {
                 u8 __iomem *base = host->ioaddr + (reg & ~3);
-               u16 val = readw(base + 2);
+               u16 val = mcf_read16(base + 2);
                 u8 dma_bits = (val >> 5) & SDHCI_CTRL_DMA_MASK;
                 u8 host_ctrl = val & 0xff;
 
@@ -137,7 +137,7 @@ static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
                 return host_ctrl;
         }
 
-       return readb(host->ioaddr + (reg ^ 0x3));
+       return mcf_read8(host->ioaddr + (reg ^ 0x3));
  }
 
  static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
@@ -149,14 +149,14 @@ static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
         if (reg == SDHCI_HOST_VERSION)
                 reg -= 2;
 
-       return readw(host->ioaddr + (reg ^ 0x2));
+       return mcf_read16(host->ioaddr + (reg ^ 0x2));
  }
 
  static u32 esdhc_mcf_readl_be(struct sdhci_host *host, int reg)
  {
         u32 val;
 
-       val = readl(host->ioaddr + reg);
+       val = mcf_read32(host->ioaddr + reg);
 
         /*
          * RM (25.3.9) sd pin clock must never exceed 25Mhz.
@@ -245,7 +245,7 @@ static void esdhc_mcf_pltfm_set_clock(struct sdhci_host *host,
          * fvco = fsys * outdvi1 + 1
          * fshdc = fvco / outdiv3 + 1
          */
-       temp = readl(pll_dr);
+       temp = mcf_read32(pll_dr);
         fsys = pltfm_host->clock;
         fvco = fsys * ((temp & 0x1f) + 1);
         fesdhc = fvco / (((temp >> 10) & 0x1f) + 1);
--

2.54.0

maintainer Acked-by Tested-by on v1 3/4
#5 lore raw

Re: [RFC 3/4] mmc: sdhci-esdhc-mcf: do not use readl()/writel() on ColdFire

In reply to Greg Ungerer

Hi Greg,

Quoted 131 lines · Greg Ungerer

From: Greg Ungerer <[email protected]>

The implementation of the readX() and writeX() family of IO access functions is non-standard on ColdFire platforms. They check the supplied IO address and will return either big or little endian results based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are wrong. This is now in the process of being cleaned up and fixed.

Change the use of the readX() and writeX() access functions in this driver to use the recently defined specific ColdFire internal SoC hardware IO access functions mcf_read8()/mcf_read16()/mcf_read32() and mcf_write8()/mcf_write16()/mcf_write32().

There is no functional change to the driver. Though it does have the effect of making the IO access slightly more efficient, since there is no longer a need to do the address check at every register access.

---
 drivers/mmc/host/sdhci-esdhc-mcf.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Note that the patches to introduce mcf_readX() and mcf_writeX functions are not in mainline yet. They are currently in the m68knommu git tree for-next branch, and so should also be in linux-next.

drivers/mmc/host/sdhci-esdhc-mcf.c +12 -13
index 375fce5639d7..6853521e8b2c 100644
@@ -55,7 +55,7 @@ static inline void esdhc_clrset_be(struct sdhci_host *host,
 	if (reg == SDHCI_HOST_CONTROL)
 		val |= ESDHC_PROCTL_D3CD;
 
-	writel((readl(base) & ~mask) | val, base);
+	mcf_write32((mcf_read32(base) & ~mask) | val, base);
 }
 
 /*
@@ -71,7 +71,7 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
 	if (reg == SDHCI_HOST_CONTROL) {
 		u32 host_ctrl = ESDHC_DEFAULT_HOST_CONTROL;
 		u8 dma_bits = (val & SDHCI_CTRL_DMA_MASK) >> 3;
-		u8 tmp = readb(host->ioaddr + SDHCI_HOST_CONTROL + 1);
+		u8 tmp = mcf_read8(host->ioaddr + SDHCI_HOST_CONTROL + 1);
 
 		tmp &= ~0x03;
 		tmp |= dma_bits;
@@ -82,12 +82,12 @@ static void esdhc_mcf_writeb_be(struct sdhci_host *host, u8 val, int reg)
 		 */
 		host_ctrl |= val;
 		host_ctrl |= (dma_bits << 8);
-		writel(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
+		mcf_write32(host_ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
 
 		return;
 	}
 
-	writel((readl(base) & mask) | (val << shift), base);
+	mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
@@ -110,24 +110,24 @@ static void esdhc_mcf_writew_be(struct sdhci_host *host, u16 val, int reg)
 		 * As for the fsl driver,
 		 * we have to set the mode in a single write here.
 		 */
-		writel(val << 16 | mcf_data->aside,
+		mcf_write32(val << 16 | mcf_data->aside,
 		       host->ioaddr + SDHCI_TRANSFER_MODE);
 		return;
 	}
 
-	writel((readl(base) & mask) | (val << shift), base);
+	mcf_write32((mcf_read32(base) & mask) | (val << shift), base);
 }
 
 static void esdhc_mcf_writel_be(struct sdhci_host *host, u32 val, int reg)
 {
-	writel(val, host->ioaddr + reg);
+	mcf_write32(val, host->ioaddr + reg);
 }
 
 static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
 {
 	if (reg == SDHCI_HOST_CONTROL) {
 		u8 __iomem *base = host->ioaddr + (reg & ~3);
-		u16 val = readw(base + 2);
+		u16 val = mcf_read16(base + 2);
 		u8 dma_bits = (val >> 5) & SDHCI_CTRL_DMA_MASK;
 		u8 host_ctrl = val & 0xff;
 
@@ -137,7 +137,7 @@ static u8 esdhc_mcf_readb_be(struct sdhci_host *host, int reg)
 		return host_ctrl;
 	}
 
-	return readb(host->ioaddr + (reg ^ 0x3));
+	return mcf_read8(host->ioaddr + (reg ^ 0x3));
 }
 
 static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
@@ -149,14 +149,14 @@ static u16 esdhc_mcf_readw_be(struct sdhci_host *host, int reg)
 	if (reg == SDHCI_HOST_VERSION)
 		reg -= 2;
 
-	return readw(host->ioaddr + (reg ^ 0x2));
+	return mcf_read16(host->ioaddr + (reg ^ 0x2));
 }
 
 static u32 esdhc_mcf_readl_be(struct sdhci_host *host, int reg)
 {
 	u32 val;
 
-	val = readl(host->ioaddr + reg);
+	val = mcf_read32(host->ioaddr + reg);
 
 	/*
 	 * RM (25.3.9) sd pin clock must never exceed 25Mhz.
@@ -245,7 +245,7 @@ static void esdhc_mcf_pltfm_set_clock(struct sdhci_host *host,
 	 * fvco = fsys * outdvi1 + 1
 	 * fshdc = fvco / outdiv3 + 1
 	 */
-	temp = readl(pll_dr);
+	temp = mcf_read32(pll_dr);
 	fsys = pltfm_host->clock;
 	fvco = fsys * ((temp & 0x1f) + 1);
 	fesdhc = fvco / (((temp >> 10) & 0x1f) + 1);
--
Quoted 2 lines

2.54.0

Tested this now on stmark2, sdcard mount/umount/read/write/erase works as usual. Thanks.

reagrds,
angelo

#6 lore raw

Re: [RFC 3/4] mmc: sdhci-esdhc-mcf: do not use readl()/writel() on ColdFire

Hi Angelo,

Quoted 24 lines · Angelo Dureghello

Hi Greg,

Quoted 21 lines · Greg Ungerer

From: Greg Ungerer <[email protected]>

The implementation of the readX() and writeX() family of IO access functions is non-standard on ColdFire platforms. They check the supplied IO address and will return either big or little endian results based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are wrong. This is now in the process of being cleaned up and fixed.

Change the use of the readX() and writeX() access functions in this driver to use the recently defined specific ColdFire internal SoC hardware IO access functions mcf_read8()/mcf_read16()/mcf_read32() and mcf_write8()/mcf_write16()/mcf_write32().

There is no functional change to the driver. Though it does have the effect of making the IO access slightly more efficient, since there is no longer a need to do the address check at every register access.

[snip]

Quoted 6 lines

Tested this now on stmark2, sdcard mount/umount/read/write/erase works as usual. Thanks.

Fantastic, thanks testing.

Regards
Greg

#7 lore raw

RFC 4/4 m68k: coldfire: fix non-standard readX()/writeX() functions

In reply to Greg Ungerer

From: Greg Ungerer <[email protected]>

Remove the local ColdFire definitions of readb()/readw()/readl() and writeb()/writew()/writel() and use the asm-generic versions of them.

The implementation of the readX()/writeX() family of IO access functions is non-standard on ColdFire platforms. They either return big-endian (that is native endian) data, or on platforms with PCI bus support check the supplied address and return either big or little endian data based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are currently broken because they are implemented using the readX()/writeX() functions.

The change to use the asm-generic versions of readX()/writeX() itself is quite strait forward, just remove the ColdFire local versions of them. But this of course has implications for any remaining drivers that use any of these IO access functions. A number of drivers can be independently fixed, before this final fix to readX()/writeX() for ColdFire. A small number of drivers cannot easily be independently fixed and remain in a working state. Those drivers are fixed here as well:

drivers/dma/mcf-edma-main.c
Supports big-endian access by setting the big-endian flag of the drivers struct fsl_edma_engine. But locally should be using ioread32be() and iowrite32be() instead of ioread32() and iowrite32().

drivers/net/can/flexcan/flexcan-core.c
Setting the driver quirks flag for big-endian access will force driver to use correct access functions.

drivers/spi/spi-fsl-dspi.c
Setting the regmap format_endian flags to use native endian will force driver to use appropriate big or little endian access on whatever platform it is built for.

These drivers have only been compile tested.

---
 arch/m68k/include/asm/io_no.h          | 68 +++-----------------------
 drivers/dma/mcf-edma-main.c            | 14 +++---
 drivers/net/can/flexcan/flexcan-core.c |  1 +
 drivers/spi/spi-fsl-dspi.c             |  2 +
 4 files changed, 16 insertions(+), 69 deletions(-)
arch/m68k/include/asm/io_no.h +6 -62
index 4f0f34b06e37..2f12f4ed0da5 100644
@@ -3,15 +3,10 @@
 #define _M68KNOMMU_IO_H
 
 /*
- * Convert a physical memory address into a IO memory address.
- * For us this is trivially a type cast.
- */
-#define iomem(a)	((void __iomem *) (a))
-
-/*
- * The non-MMU m68k and ColdFire IO and memory mapped hardware access
- * functions have always worked in CPU native endian. We need to define
- * that behavior here first before we include asm-generic/io.h.
+ * Historically the raw native endian IO access macros for non-MMU m68k and
+ * ColdFire have accepted any integral value as the address argument.
+ * The asm-generic versions of these expect "void __iomem *" for the address,
+ * so define local permissive versions here.
  */
 #define __raw_readb(addr) \
     ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
@@ -45,66 +40,15 @@
  * applies just the same of there is no MMU but something like a PCI bus
  * is present.
  */
-static int __cf_internalio(unsigned long addr)
+static inline int __cf_internalio(unsigned long addr)
 {
 	return (addr >= IOMEMBASE) && (addr <= IOMEMBASE + IOMEMSIZE - 1);
 }
 
-static int cf_internalio(const volatile void __iomem *addr)
+static inline int cf_internalio(const volatile void __iomem *addr)
 {
 	return __cf_internalio((unsigned long) addr);
 }
-
-/*
- * We need to treat built-in peripherals and bus based address ranges
- * differently. Local built-in peripherals (and the ColdFire SoC parts
- * have quite a lot of them) are always native endian - which is big
- * endian on m68k/ColdFire. Bus based address ranges, like the PCI bus,
- * are accessed little endian - so we need to byte swap those.
- */
-#define readw readw
-static inline u16 readw(const volatile void __iomem *addr)
-{
-	if (cf_internalio(addr))
-		return __raw_readw(addr);
-	return swab16(__raw_readw(addr));
-}
-
-#define readl readl
-static inline u32 readl(const volatile void __iomem *addr)
-{
-	if (cf_internalio(addr))
-		return __raw_readl(addr);
-	return swab32(__raw_readl(addr));
-}
-
-#define writew writew
-static inline void writew(u16 value, volatile void __iomem *addr)
-{
-	if (cf_internalio(addr))
-		__raw_writew(value, addr);
-	else
-		__raw_writew(swab16(value), addr);
-}
-
-#define writel writel
-static inline void writel(u32 value, volatile void __iomem *addr)
-{
-	if (cf_internalio(addr))
-		__raw_writel(value, addr);
-	else
-		__raw_writel(swab32(value), addr);
-}
-
-#else
-
-#define readb __raw_readb
-#define readw __raw_readw
-#define readl __raw_readl
-#define writeb __raw_writeb
-#define writew __raw_writew
-#define writel __raw_writel
-
 #endif /* IOMEMBASE */
 
 #if defined(CONFIG_COLDFIRE)
drivers/dma/mcf-edma-main.c +7 -7
index 9e1c6400c77b..4ed0ce644e37 100644
@@ -21,9 +21,9 @@ static irqreturn_t mcf_edma_tx_handler(int irq, void *dev_id)
 	unsigned int ch;
 	u64 intmap;
 
-	intmap = ioread32(regs->inth);
+	intmap = ioread32be(regs->inth);
 	intmap <<= 32;
-	intmap |= ioread32(regs->intl);
+	intmap |= ioread32be(regs->intl);
 	if (!intmap)
 		return IRQ_NONE;
 
@@ -43,7 +43,7 @@ static irqreturn_t mcf_edma_err_handler(int irq, void *dev_id)
 	struct edma_regs *regs = &mcf_edma->regs;
 	unsigned int err, ch;
 
-	err = ioread32(regs->errl);
+	err = ioread32be(regs->errl);
 	if (!err)
 		return IRQ_NONE;
 
@@ -55,7 +55,7 @@ static irqreturn_t mcf_edma_err_handler(int irq, void *dev_id)
 		}
 	}
 
-	err = ioread32(regs->errh);
+	err = ioread32be(regs->errh);
 	if (!err)
 		return IRQ_NONE;
 
@@ -203,8 +203,8 @@ static int mcf_edma_probe(struct platform_device *pdev)
 		edma_write_tcdreg(mcf_chan, cpu_to_le32(0), csr);
 	}
 
-	iowrite32(~0, regs->inth);
-	iowrite32(~0, regs->intl);
+	iowrite32be(~0, regs->inth);
+	iowrite32be(~0, regs->intl);
 
 	ret = mcf_edma->drvdata->setup_irq(pdev, mcf_edma);
 	if (ret)
@@ -248,7 +248,7 @@ static int mcf_edma_probe(struct platform_device *pdev)
 	}
 
 	/* Enable round robin arbitration */
-	iowrite32(EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
+	iowrite32be(EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr);
 
 	return 0;
 }
drivers/net/can/flexcan/flexcan-core.c +1 -0
index f5d22c61503f..a682f02d2c43 100644
@@ -296,6 +296,7 @@ static_assert(sizeof(struct flexcan_regs) ==  0x4 * 18 + 0xfb8);
 static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE |
 		FLEXCAN_QUIRK_NR_IRQ_3 | FLEXCAN_QUIRK_NR_MB_16 |
+		FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN |
 		FLEXCAN_QUIRK_SUPPORT_RX_MAILBOX |
 		FLEXCAN_QUIRK_SUPPORT_RX_FIFO,
 };
drivers/spi/spi-fsl-dspi.c +2 -0
index 9f2a7b8163b1..964ca6baf32f 100644
@@ -203,6 +203,8 @@ static const struct regmap_config dspi_regmap_config[] = {
 		.volatile_table	= &dspi_volatile_table,
 		.rd_table	= &dspi_access_table,
 		.wr_table	= &dspi_access_table,
+		.reg_format_endian = REGMAP_ENDIAN_NATIVE,
+		.val_format_endian = REGMAP_ENDIAN_NATIVE,
 	},
 	[S32G_DSPI_REGMAP] = {
 		.reg_bits	= 32,
Signature · 1 line
2.54.0
reviewer
#8 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 37 lines · Greg Ungerer

From: Greg Ungerer <[email protected]>

Remove the local ColdFire definitions of readb()/readw()/readl() and writeb()/writew()/writel() and use the asm-generic versions of them.

The implementation of the readX()/writeX() family of IO access functions is non-standard on ColdFire platforms. They either return big-endian (that is native endian) data, or on platforms with PCI bus support check the supplied address and return either big or little endian data based on that check. This is non-standard, they are expected to always return little-endian byte ordered data. Unfortunately this behavior also means that ioreadX()/iowroteX() and their big-endian counter parts ioreadXbe()/iowriteXbe() are currently broken because they are implemented using the readX()/writeX() functions.

The change to use the asm-generic versions of readX()/writeX() itself is quite strait forward, just remove the ColdFire local versions of them. But this of course has implications for any remaining drivers that use any of these IO access functions. A number of drivers can be independently fixed, before this final fix to readX()/writeX() for ColdFire. A small number of drivers cannot easily be independently fixed and remain in a working state. Those drivers are fixed here as well:

drivers/dma/mcf-edma-main.c
Supports big-endian access by setting the big-endian flag of the drivers struct fsl_edma_engine. But locally should be using ioread32be() and iowrite32be() instead of ioread32() and iowrite32().

drivers/net/can/flexcan/flexcan-core.c
Setting the driver quirks flag for big-endian access will force driver to use correct access functions.

drivers/spi/spi-fsl-dspi.c
Setting the regmap format_endian flags to use native endian will force driver to use appropriate big or little endian access on whatever platform it is built for.

Quoted 6 lines

These drivers have only been compile tested.

---
 arch/m68k/include/asm/io_no.h          | 68 +++-----------------------
 drivers/dma/mcf-edma-main.c            | 14 +++---

Suppose it is correct, but I have not such platform to test it. it should be correct if disassembly code is the same at access register.

Frank

Quoted 1 line
#9 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

In reply to Greg Ungerer
Quoted 4 lines · Greg Ungerer

drivers/dma/mcf-edma-main.c
Supports big-endian access by setting the big-endian flag of the drivers struct fsl_edma_engine. But locally should be using ioread32be() and iowrite32be() instead of ioread32() and iowrite32().

I'm still a bit confused about how this works at the moment, since the drivers/dma/fsl-edma-common.h file already contains checks for the edma->big_endian flag, which is set in mcf_edma_probe(). The version after your patch makes sense to me, but it looks like the existing code cannot work.

Quoted 6 lines

drivers/spi/spi-fsl-dspi.c
Setting the regmap format_endian flags to use native endian will force driver to use appropriate big or little endian access on whatever platform it is built for.

These drivers have only been compile tested.

I would suggest marking these as explicit BIG_ENDIAN rather than NATIVE_ENDIAN. The effect should be the same since coldfire CPUs cannot run little-endian code, but the way that hardware usually works is that the endianess is fixed at the bus level to one way or the other. NATIVE_ENDIAN to me implies that the registers have configurable endianess that is switched along with the CPU mode.

Arnd

#10 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi Arnd,

Quoted 7 lines · Arnd Bergmann
Quoted 4 lines · Greg Ungerer

drivers/dma/mcf-edma-main.c
Supports big-endian access by setting the big-endian flag of the drivers struct fsl_edma_engine. But locally should be using ioread32be() and iowrite32be() instead of ioread32() and iowrite32().

Quoted 5 lines

I'm still a bit confused about how this works at the moment, since the drivers/dma/fsl-edma-common.h file already contains checks for the edma->big_endian flag, which is set in mcf_edma_probe(). The version after your patch makes sense to me, but it looks like the existing code cannot work.

Yes, it certainly doesn't look right to me either.

Angelo: you look to be the original author of this driver, can you shed any light on its working status in mainline currently?

Quoted 7 lines
Quoted 6 lines

drivers/spi/spi-fsl-dspi.c
Setting the regmap format_endian flags to use native endian will force driver to use appropriate big or little endian access on whatever platform it is built for.

These drivers have only been compile tested.

Quoted 7 lines

I would suggest marking these as explicit BIG_ENDIAN rather than NATIVE_ENDIAN. The effect should be the same since coldfire CPUs cannot run little-endian code, but the way that hardware usually works is that the endianess is fixed at the bus level to one way or the other. NATIVE_ENDIAN to me implies that the registers have configurable endianess that is switched along with the CPU mode.

Ok, will change. I chose native endian in this case since the regmap config entry used for the m5441x family is also used by the vf610 devce (which looks to be an ARM imx SoC). So it will need a duplicate setup with those endian flags set to BIG_ENDIAN. But that is no problem.

Thanks
Greg

#11 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 11 lines · Greg Ungerer
Quoted 9 lines · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

I would suggest marking these as explicit BIG_ENDIAN rather than NATIVE_ENDIAN. The effect should be the same since coldfire CPUs cannot run little-endian code, but the way that hardware usually works is that the endianess is fixed at the bus level to one way or the other. NATIVE_ENDIAN to me implies that the registers have configurable endianess that is switched along with the CPU mode.

Quoted 4 lines

Ok, will change. I chose native endian in this case since the regmap config entry used for the m5441x family is also used by the vf610 devce (which looks to be an ARM imx SoC). So it will need a duplicate setup with those endian flags set to BIG_ENDIAN. But that is no problem.

Sounds good. In this case, splitting it up is technically even required, because you can run a big-endian ARMv7 kernel on vf610, so the vf610 entry has to use little-endian registers rather than native.

I don't think anyone has run big-endian kernels on vf610, though I have heard of users testing them successfully on i.MX6.

Arnd

#12 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

In reply to Greg Ungerer

Hi all,

sorry that i could check this now only, hope is not too late.

Quoted 16 lines · Greg Ungerer

Hi Arnd,

Quoted 7 lines · Arnd Bergmann
Quoted 4 lines · Greg Ungerer

drivers/dma/mcf-edma-main.c
Supports big-endian access by setting the big-endian flag of the drivers struct fsl_edma_engine. But locally should be using ioread32be() and iowrite32be() instead of ioread32() and iowrite32().

Quoted 5 lines

I'm still a bit confused about how this works at the moment, since the drivers/dma/fsl-edma-common.h file already contains checks for the edma->big_endian flag, which is set in mcf_edma_probe(). The version after your patch makes sense to me, but it looks like the existing code cannot work.

Quoted 5 lines

Yes, it certainly doesn't look right to me either.

Angelo: you look to be the original author of this driver, can you shed any light on its working status in mainline currently?

I was some years far from this driver (and the kernel itself), but i have seen there are several changes in the edma common part from that time. I remember i reviewed/tested some of them, some other unfortunately not.

I realized last month, that i was back working on this board (stmark2) that somehting related to edma or dspi looks broken in mainline now:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.
- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

Anyway, tested the patch, nothing looks changed nor in better or worst. Will look into this in the next days.

Quoted 16 lines
Quoted 8 lines
Quoted 7 lines

drivers/spi/spi-fsl-dspi.c
Setting the regmap format_endian flags to use native endian will force driver to use appropriate big or little endian access on whatever platform it is built for.

These drivers have only been compile tested.

Quoted 7 lines

I would suggest marking these as explicit BIG_ENDIAN rather than NATIVE_ENDIAN. The effect should be the same since coldfire CPUs cannot run little-endian code, but the way that hardware usually works is that the endianess is fixed at the bus level to one way or the other. NATIVE_ENDIAN to me implies that the registers have configurable endianess that is switched along with the CPU mode.

Quoted 8 lines

Ok, will change. I chose native endian in this case since the regmap config entry used for the m5441x family is also used by the vf610 devce (which looks to be an ARM imx SoC). So it will need a duplicate setup with those endian flags set to BIG_ENDIAN. But that is no problem.

Thanks
Greg

Regards,
angelo

#13 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Quoted 5 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

Arnd

#14 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi Arnd,

Quoted 35 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

        if (edma->big_endian)
                val = ioread32be(addr);

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Regards,
angelo

Quoted 1 line

Arnd

#15 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi,

Quoted 14 lines · Angelo Dureghello

Hi Arnd,

Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5

About this issue, it fails on dma_pool_alloc(), so tomorrow will check, i probably lost some dma config option.

Quoted 69 lines
Quoted 24 lines
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

        if (edma->big_endian)
                val = ioread32be(addr);
Quoted 10 lines

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Regards,
angelo

Quoted 1 line

Arnd

Regards,
angelo

maintainer Reviewed-by Greg Ungerer Tested-by Greg Ungerer
#16 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi All,

Quoted 18 lines · Angelo Dureghello

Hi,

Quoted 14 lines · Angelo Dureghello

Hi Arnd,

Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 3 lines

About this issue, it fails on dma_pool_alloc(), so tomorrow will check, i probably lost some dma config option.

so i worked on this open issue above:

- moved to master and rebased,
- crated a wip/edma branch,
- bisected and found the offending commit, before this, mcf-edma driver and connected spi-fsl-dspi (using edma) was both working correctly.

7a360df941a4bd60847208de59f1ac8b166265a2 is the first bad commit commit 7a360df941a4bd60847208de59f1ac8b166265a2 (HEAD)

Author: Christoph Hellwig <[email protected]>
Date:   Thu Oct 12 09:52:27 2023 +0200

m68k: don't provide arch_dma_alloc for nommu/coldfire

Coldfire cores configured with a data cache can't provide coherent DMA allocations at all.

Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation.

The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently.

 arch/m68k/Kconfig      |  1 -
 arch/m68k/kernel/dma.c | 23 -----------------------
 2 files changed, 24 deletions(-)

So i can try next week a patch for edma looking what has been done in fec, and since i am probably the only with mcf54415, will test it here.

Quoted 75 lines
Quoted 75 lines
Quoted 24 lines
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

        if (edma->big_endian)
                val = ioread32be(addr);

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Quoted 7 lines
Quoted 4 lines

Regards,
angelo

Quoted 1 line

Arnd

Regards,
angelo

Regards,
angelo

#17 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 52 lines · Angelo Dureghello

Hi All,

Quoted 18 lines · Angelo Dureghello

Hi,

Quoted 14 lines · Angelo Dureghello

Hi Arnd,

Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 3 lines

About this issue, it fails on dma_pool_alloc(), so tomorrow will check, i probably lost some dma config option.

so i worked on this open issue above:

- moved to master and rebased,
- crated a wip/edma branch,
- bisected and found the offending commit, before this, mcf-edma driver and connected spi-fsl-dspi (using edma) was both working correctly.

7a360df941a4bd60847208de59f1ac8b166265a2 is the first bad commit commit 7a360df941a4bd60847208de59f1ac8b166265a2 (HEAD)

Author: Christoph Hellwig <[email protected]>
Date:   Thu Oct 12 09:52:27 2023 +0200

m68k: don't provide arch_dma_alloc for nommu/coldfire

Coldfire cores configured with a data cache can't provide coherent DMA allocations at all.

Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation.

The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently.

Quoted 8 lines
 arch/m68k/Kconfig      |  1 -
 arch/m68k/kernel/dma.c | 23 -----------------------
 2 files changed, 24 deletions(-)

So i can try next week a patch for edma looking what has been done in fec, and since i am probably the only with mcf54415, will test it here.

Looking into this better, looks like the above commit was meant for the majority on non-mmu ColdFire. I think mcf5441x and some other with mmu enabled can flag pages as "page cache disabled".

So i would re-enabled that code only for such mmu families.

Please let me know if i am correct.
Thanks.

Quoted 78 lines
Quoted 78 lines
Quoted 78 lines
Quoted 24 lines
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

        if (edma->big_endian)
                val = ioread32be(addr);

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Regards,
angelo

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Arnd

Regards,
angelo

Regards,
angelo

Regards,
angelo

#18 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi Greg and all,

so i posted a patch this morning to have edma driver back working. If approved, i can proceed testing this RFC (adjusting it as needed) with edma and dspi driver.

Regards,
angelo

Quoted 159 lines · Angelo Dureghello
Quoted 52 lines · Angelo Dureghello

Hi All,

Quoted 18 lines · Angelo Dureghello

Hi,

Quoted 14 lines · Angelo Dureghello

Hi Arnd,

Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 3 lines

About this issue, it fails on dma_pool_alloc(), so tomorrow will check, i probably lost some dma config option.

so i worked on this open issue above:

- moved to master and rebased,
- crated a wip/edma branch,
- bisected and found the offending commit, before this, mcf-edma driver and connected spi-fsl-dspi (using edma) was both working correctly.

7a360df941a4bd60847208de59f1ac8b166265a2 is the first bad commit commit 7a360df941a4bd60847208de59f1ac8b166265a2 (HEAD)

Author: Christoph Hellwig <[email protected]>
Date:   Thu Oct 12 09:52:27 2023 +0200

m68k: don't provide arch_dma_alloc for nommu/coldfire

Coldfire cores configured with a data cache can't provide coherent DMA allocations at all.

Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation.

The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently.

Quoted 8 lines
 arch/m68k/Kconfig      |  1 -
 arch/m68k/kernel/dma.c | 23 -----------------------
 2 files changed, 24 deletions(-)

So i can try next week a patch for edma looking what has been done in fec, and since i am probably the only with mcf54415, will test it here.

Looking into this better, looks like the above commit was meant for the majority on non-mmu ColdFire. I think mcf5441x and some other with mmu enabled can flag pages as "page cache disabled".

So i would re-enabled that code only for such mmu families.

Please let me know if i am correct.
Thanks.

Quoted 78 lines
Quoted 78 lines
Quoted 78 lines
Quoted 24 lines
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
        return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

        if (edma->big_endian)
                val = ioread32be(addr);

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Regards,
angelo

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Arnd

Regards,
angelo

Regards,
angelo

Regards,
angelo

#19 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

In reply to Angelo Dureghello

Hi Angelo,

(Adding Christoph to CC list)

Quoted 57 lines · Angelo Dureghello
Quoted 56 lines · Angelo Dureghello

Hi All,

Quoted 18 lines · Angelo Dureghello

Hi,

Quoted 14 lines · Angelo Dureghello

Hi Arnd,

Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Angelo Dureghello
Quoted 2 lines · Greg Ungerer
Quoted 1 line · Arnd Bergmann

On Wed, May 6, 2026, at 16:26, Greg Ungerer wrote:

[    2.270000] fsl-dspi fsl-dspi.0: Not able to get desc for DMA xfer
[    2.280000] fsl-dspi fsl-dspi.0: DMA transfer failed
[    2.280000] spi_master spi0: failed to transfer one message from queue
[    2.290000] spi_master spi0: noqueue transfer failed
[    2.290000] spi-nor spi0.1: probe with driver spi-nor failed with error -5
Quoted 3 lines

About this issue, it fails on dma_pool_alloc(), so tomorrow will check, i probably lost some dma config option.

so i worked on this open issue above:

- moved to master and rebased,
- crated a wip/edma branch,
- bisected and found the offending commit, before this, mcf-edma driver and connected spi-fsl-dspi (using edma) was both working correctly.

7a360df941a4bd60847208de59f1ac8b166265a2 is the first bad commit commit 7a360df941a4bd60847208de59f1ac8b166265a2 (HEAD)

Author: Christoph Hellwig <[email protected]>
Date:   Thu Oct 12 09:52:27 2023 +0200

m68k: don't provide arch_dma_alloc for nommu/coldfire

Coldfire cores configured with a data cache can't provide coherent DMA allocations at all.

Instead of returning non-coherent kernel memory in this case, return NULL and fail the allocation.

The only driver that used to rely on the previous behavior (fec) has been switched to use non-coherent allocations for this case recently.

  arch/m68k/Kconfig      |  1 -
  arch/m68k/kernel/dma.c | 23 -----------------------
  2 files changed, 24 deletions(-)
Quoted 8 lines
Quoted 4 lines

So i can try next week a patch for edma looking what has been done in fec, and since i am probably the only with mcf54415, will test it here.

Looking into this better, looks like the above commit was meant for the majority on non-mmu ColdFire. I think mcf5441x and some other with mmu enabled can flag pages as "page cache disabled".

I don't think that is right. The way the underlying data cache is setup for MMU ColdFire (via the ACR/CACR registers) means that individual pages cannot be marked as non-cached. So coherent memory allocations are not possible - at least the way things are today.

It would be possible to set aside a chunk of RAM at kernel startup time to use as a pool for coherent allocations (since it could be marked as non-cached via the ACR/CACR registers), but there is no code to support doing that today.

Regards
Greg

Quoted 93 lines

So i would re-enabled that code only for such mmu families.

Please let me know if i am correct.
Thanks.

Quoted 78 lines
Quoted 78 lines
Quoted 78 lines
Quoted 24 lines
Quoted 5 lines

DSPI is using edma, i will try to understand where the issue is asap.

About how it works:
- for accesses to edma module (IP) mmio registers, must be native big_endian, so using the "be" suffix in "mcf"_edma looks ok for me.

The twist here is that with the way that readl() is defined on coldfire as a non-swapping operation, and the generic definition assuming the opposite in

static inline u32 ioread32be(const void __iomem *addr)

{
         return swab32(readl(addr));
}

the function called ioread32be() actually tries to access the registers as little-endian. I can see two possible ways we got here, but don't know which one is currect:

a) the device actually has little-endian registers (like it does on i.MX, but unlike all other coldfire devices), and you just never noticed because using ioread32be() worked as you expected.

Quoted 4 lines

b) you tested the driver using an ioread32be() definition that did not have a byteswap and it correctly accessed big-endian registers at the time, but the version in mainline today does not.

Ok. The ioread32be now works properly since i had applied Greg patches. I generated an error in _probe on edma channel 2, reading status reg. looks consistent:

	iowrite16(2121, regs->erqh);
	iowrite8(0x77, regs->serq);
	iowrite8(0x12, regs->ssrt);
	
	u32 status = ioread32be(regs->es);
	printk("%s() status: %04x\n", __func__, status);
[    0.140000] mcf_edma_probe() entering
[    0.140000] mcf_edma_probe(): allocating data
[    0.140000] mcf_edma_probe() status: 800012f8

If i am not loosing myself in this r/w labyrinth, the path should be:

1) Greg removed coldfire readl/writel, leaving now the standard LE r/w,
2) So the ioread32be swaps the standard LE read giving BE.

Am i correct ?

Quoted 11 lines
Quoted 6 lines

- for accessing the "tcd" memory structure, that must be, from what i remember, anyway in little endian, independently from the cpu core endiannes, this is the reason that big_endian flag is needed, it is used for tcd area accesses, so the IP module was built.
The tcd area may be similar to pci accesses (see mcf54415 RM 19.4.16).

edma_read_tcdreg() calls into edma_readl(), which is the same function that is used for normal register access, so from what I can tell, they always use the same endianess here.

If edma_readl was using

         if (edma->big_endian)
                 val = ioread32be(addr);

and never changed, without Greg patch, it was likely returning little endian for coldfire and correct LE for other arch ? :)

I remember something about tcd area was coded LE, but will investigate better, now i am over midnight.

Regards,
angelo

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Arnd

Regards,
angelo

Regards,
angelo

Regards,
angelo

#20 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 9 lines · Greg Ungerer

I don't think that is right. The way the underlying data cache is setup for MMU ColdFire (via the ACR/CACR registers) means that individual pages cannot be marked as non-cached. So coherent memory allocations are not possible - at least the way things are today.

It would be possible to set aside a chunk of RAM at kernel startup time to use as a pool for coherent allocations (since it could be marked as non-cached via the ACR/CACR registers), but there is no code to support doing that today.

With CONFIG_DMA_GLOBAL_POOL there is some generic code dealing with most of this. But if this driver worked on coldfire in the past, it must have been fine with non-coherent memory and could use the non-coherent allocator.

#21 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi,

Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Greg Ungerer

I don't think that is right. The way the underlying data cache is setup for MMU ColdFire (via the ACR/CACR registers) means that individual pages cannot be marked as non-cached. So coherent memory allocations are not possible - at least the way things are today.

It would be possible to set aside a chunk of RAM at kernel startup time to use as a pool for coherent allocations (since it could be marked as non-cached via the ACR/CACR registers), but there is no code to support doing that today.

Quoted 5 lines

With CONFIG_DMA_GLOBAL_POOL there is some generic code dealing with most of this. But if this driver worked on coldfire in the past, it must have been fine with non-coherent memory and could use the non-coherent allocator.

Ok, thanks, so the driver is working fine with non coherent memory but may be just for a case. I will try to setup a better SD test. And will send another patch to have dma enabled with non coherent allocator.

Regards,
angelo

#22 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Hi Angelo,

Quoted 18 lines · Angelo Dureghello
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Greg Ungerer

I don't think that is right. The way the underlying data cache is setup for MMU ColdFire (via the ACR/CACR registers) means that individual pages cannot be marked as non-cached. So coherent memory allocations are not possible - at least the way things are today.

It would be possible to set aside a chunk of RAM at kernel startup time to use as a pool for coherent allocations (since it could be marked as non-cached via the ACR/CACR registers), but there is no code to support doing that today.

Quoted 5 lines

With CONFIG_DMA_GLOBAL_POOL there is some generic code dealing with most of this. But if this driver worked on coldfire in the past, it must have been fine with non-coherent memory and could use the non-coherent allocator.

Quoted 3 lines

Ok, thanks, so the driver is working fine with non coherent memory but may be just for a case. I will try to setup a better SD test. And will send another patch to have dma enabled with non coherent allocator.

Sounds good. Thanks for taking the time to look into this.

Regards
Greg

maintainer Acked-by on v1 4/4
#23 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

In reply to Greg Ungerer

drivers/net/can/flexcan/flexcan-core.c static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8); · line 297

Quoted 7 lines · Greg Ungerer
drivers/net/can/flexcan/flexcan-core.c +0 -0
index f5d22c61503f..a682f02d2c43 100644
@@ -296,6 +296,7 @@ static_assert(sizeof(struct flexcan_regs) ==  0x4 * 18 + 0xfb8);
 static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE |

Nitpick:
Can you move it here, so that the quirks stay sorted?

FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN |

drivers/net/can/flexcan/flexcan-core.c static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8); · line 302

Quoted 5 lines
drivers/net/can/flexcan/flexcan-core.c +1 -0
 		FLEXCAN_QUIRK_NR_IRQ_3 | FLEXCAN_QUIRK_NR_MB_16 |
+		FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN |
 		FLEXCAN_QUIRK_SUPPORT_RX_MAILBOX |
 		FLEXCAN_QUIRK_SUPPORT_RX_FIFO,
 };

With that change:

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
#24 lore raw

Re: [RFC 4/4] m68k: coldfire: fix non-standard readX()/writeX() functions

Quoted 11 lines · Marc Kleine-Budde

drivers/net/can/flexcan/flexcan-core.c static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8); · line 297

Quoted 7 lines · Greg Ungerer
drivers/net/can/flexcan/flexcan-core.c +0 -0
index f5d22c61503f..a682f02d2c43 100644
@@ -296,6 +296,7 @@ static_assert(sizeof(struct flexcan_regs) ==  0x4 * 18 + 0xfb8);
  static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = {
  	.quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE |

Nitpick:
Can you move it here, so that the quirks stay sorted?

Yep, sure thing.

Quoted 11 lines

FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN |

drivers/net/can/flexcan/flexcan-core.c static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8); · line 302

Quoted 5 lines
drivers/net/can/flexcan/flexcan-core.c +1 -0
  		FLEXCAN_QUIRK_NR_IRQ_3 | FLEXCAN_QUIRK_NR_MB_16 |
+		FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN |
  		FLEXCAN_QUIRK_SUPPORT_RX_MAILBOX |
  		FLEXCAN_QUIRK_SUPPORT_RX_FIFO,
  };

With that change:

Thanks
Greg

maintainer
#25 lore raw
In reply to Greg Ungerer

drivers/net/ethernet/freescale/fec_main.c static void fec_irqs_disable(struct net_device *ndev) · line 1402

Quoted 6 lines

static void
fec_stop(struct net_device *ndev)
{

drivers/net/ethernet/freescale/fec_main.c +1 -1
 	struct fec_enet_private *fep = netdev_priv(ndev);
-	u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;
+	u32 rmii_mode = fec_readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;

This is not an issue, but since you changed this line, the new code should follow the "reverse xmas tree" style.

See: https://elixir.bootlin.com/linux/v7.0.1/source/Documentation/process/maintainer-netdev.rst#L380

Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c +2 -2
 	u32 val;
 
 	/* We cannot expect a graceful transmit stop without link !!! */
 	if (fep->link) {
-		writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
+		fec_writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
 		udelay(10);
-		if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
+		if (!(fec_readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
 			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
 	}
#26 lore raw
Quoted 9 lines · On Fri, 8 May 2026 02:46:38 +0000 Wei Fang <[email protected]> wrote:

drivers/net/ethernet/freescale/fec_main.c static void fec_irqs_disable(struct net_device *ndev) · line 1402

Quoted 6 lines

static void
fec_stop(struct net_device *ndev)
{

drivers/net/ethernet/freescale/fec_main.c +1 -1
 	struct fec_enet_private *fep = netdev_priv(ndev);
-	u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;
+	u32 rmii_mode = fec_readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;  

This is not an issue, but since you changed this line, the new code should follow the "reverse xmas tree" style.

Looking rmii_mode isn't even used until much later in the function. (and then not very often)
Much better to read it just before it is needed.

David

Quoted 17 lines

See: https://elixir.bootlin.com/linux/v7.0.1/source/Documentation/process/maintainer-netdev.rst#L380

Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c +2 -2
 	u32 val;
 
 	/* We cannot expect a graceful transmit stop without link !!! */
 	if (fep->link) {
-		writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
+		fec_writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
 		udelay(10);
-		if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
+		if (!(fec_readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
 			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
 	}
#27 lore raw
Quoted 13 lines · David Laight
Quoted 9 lines · On Fri, 8 May 2026 02:46:38 +0000 Wei Fang <[email protected]> wrote:

drivers/net/ethernet/freescale/fec_main.c static void fec_irqs_disable(struct net_device *ndev) · line 1402

Quoted 6 lines
  static void
  fec_stop(struct net_device *ndev)
  {
  	struct fec_enet_private *fep = netdev_priv(ndev);
drivers/net/ethernet/freescale/fec_main.c +1 -1
-	u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;
+	u32 rmii_mode = fec_readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;

This is not an issue, but since you changed this line, the new code should follow the "reverse xmas tree" style.

Quoted 3 lines

Looking rmii_mode isn't even used until much later in the function. (and then not very often)
Much better to read it just before it is needed.

Sure, but that feels like a change for a separate patch. The changes to this file are a global search and replace. The final produced object is identical before and after.

Regards
Greg

Quoted 21 lines

David

Quoted 17 lines

See: https://elixir.bootlin.com/linux/v7.0.1/source/Documentation/process/maintainer-netdev.rst#L380

Quoted 12 lines

u32 val;

/* We cannot expect a graceful transmit stop without link !!! */ if (fep->link) {

drivers/net/ethernet/freescale/fec_main.c +2 -2
-		writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
+		fec_writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
  		udelay(10);
-		if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
+		if (!(fec_readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
  			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
  	}
#28 lore raw
In reply to Wei Fang
Quoted 9 lines · Wei Fang

drivers/net/ethernet/freescale/fec_main.c static void fec_irqs_disable(struct net_device *ndev) · line 1402

Quoted 6 lines
  static void
  fec_stop(struct net_device *ndev)
  {
  	struct fec_enet_private *fep = netdev_priv(ndev);
drivers/net/ethernet/freescale/fec_main.c +1 -1
-	u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;
+	u32 rmii_mode = fec_readl(fep->hwp + FEC_R_CNTRL) & FEC_RCR_RMII;

This is not an issue, but since you changed this line, the new code should follow the "reverse xmas tree" style.

Sure, will change in next version.

Thanks
Greg

Quoted 15 lines

See: https://elixir.bootlin.com/linux/v7.0.1/source/Documentation/process/maintainer-netdev.rst#L380

Quoted 12 lines

u32 val;

/* We cannot expect a graceful transmit stop without link !!! */ if (fep->link) {

drivers/net/ethernet/freescale/fec_main.c +2 -2
-		writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
+		fec_writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */
  		udelay(10);
-		if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
+		if (!(fec_readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA))
  			netdev_err(ndev, "Graceful transmit stop did not complete!\n");
  	}