Skip to contentSkip to conversation

mtd: atmel-quadspi: fix build issues

RFC PATCH In review Arnd Bergmann 2 participants 6 messages Jul 21, 2017 – Oct 29, 2017

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

RFC PATCH 1/1 mtd: atmel-quadspi: fix build issues

I ran into a link-time error with the atmel-quadspi driver on the EBSA110 platform:

drivers/mtd/built-in.o: In function `atmel_qspi_run_command':
:(.text+0x1ee3c): undefined reference to _memcpy_toio' :(.text+0x1ee48): undefined reference to _memcpy_fromio'

The problem is that _memcpy_toio/_memcpy_fromio are not available on that platform, and we have to prevent building the driver there.

A related problem is that the functions are not portable APIs and should not be called directly from a device driver. On little-endian machines, the regular memcpy_toio/memcpy_fromio functions are defined as optimized versions using multi-byte transfers that are much faster.

Cyrille mentioned that initially using memcpy_toio/memcpy_fromio did not work, but I suspect that this was the result of a bug that has since been fixed. With that change, we can also compile-test on other architectures.

Fixes 161aaab8a067 ("mtd: atmel-quadspi: add driver for Atmel QSPI controller")
---
 drivers/mtd/spi-nor/Kconfig         | 2 +-
 drivers/mtd/spi-nor/atmel-quadspi.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/Kconfig +1 -1
index 293c8a4d1e49..22e5fc4080f8 100644
@@ -41,7 +41,7 @@ config SPI_ASPEED_SMC
 
 config SPI_ATMEL_QUADSPI
 	tristate "Atmel Quad SPI Controller"
-	depends on ARCH_AT91 || (ARM && COMPILE_TEST)
+	depends on ARCH_AT91 || (COMPILE_TEST && !ARCH_EBSA110)
 	depends on OF && HAS_IOMEM
 	help
 	  This enables support for the Quad SPI controller in master mode.
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
index ba76fa8f2031..ff3849106e77 100644
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
 	if (cmd->enable.bits.address)
 		ahb_mem += cmd->address;
 	if (cmd->tx_buf)
-		_memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+		memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
 	else
-		_memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+		memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 
 	return 0;
 }
Signature · 1 line
2.9.0
#1 lore raw

Hi Arnd,

Quoted 47 lines · Arnd Bergmann

I ran into a link-time error with the atmel-quadspi driver on the EBSA110 platform:

drivers/mtd/built-in.o: In function `atmel_qspi_run_command':
:(.text+0x1ee3c): undefined reference to _memcpy_toio' :(.text+0x1ee48): undefined reference to _memcpy_fromio'

The problem is that _memcpy_toio/_memcpy_fromio are not available on that platform, and we have to prevent building the driver there.

A related problem is that the functions are not portable APIs and should not be called directly from a device driver. On little-endian machines, the regular memcpy_toio/memcpy_fromio functions are defined as optimized versions using multi-byte transfers that are much faster.

Cyrille mentioned that initially using memcpy_toio/memcpy_fromio did not work, but I suspect that this was the result of a bug that has since been fixed. With that change, we can also compile-test on other architectures.

Fixes 161aaab8a067 ("mtd: atmel-quadspi: add driver for Atmel QSPI controller")
---
 drivers/mtd/spi-nor/Kconfig         | 2 +-
 drivers/mtd/spi-nor/atmel-quadspi.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/Kconfig +1 -1
index 293c8a4d1e49..22e5fc4080f8 100644
@@ -41,7 +41,7 @@ config SPI_ASPEED_SMC
 
 config SPI_ATMEL_QUADSPI
 	tristate "Atmel Quad SPI Controller"
-	depends on ARCH_AT91 || (ARM && COMPILE_TEST)
+	depends on ARCH_AT91 || (COMPILE_TEST && !ARCH_EBSA110)
 	depends on OF && HAS_IOMEM
 	help
 	  This enables support for the Quad SPI controller in master mode.
drivers/mtd/spi-nor/atmel-quadspi.c +0 -0
index ba76fa8f2031..ff3849106e77 100644

drivers/mtd/spi-nor/atmel-quadspi.c static int atmel_qspi_run_transfer(struct atmel_qspi *aq, · line 214

Quoted 9 lines
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
 	if (cmd->enable.bits.address)
 		ahb_mem += cmd->address;
 	if (cmd->tx_buf)
-		_memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+		memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
 	else
-		_memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+		memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 

At least on AT91 platforms and likely on most ARM boards, memcpy_fromio == memcpy_toio == memcpy.

I got some sama5d2 hardware last week, so I'll try to test your patch within few days because as you said maybe memcpy() was broken when I developed this driver at first but now memcpy() is likely to have been fixed so it might be interesting to get rid of _memcpy_fromio() and _memcpy_toio() because this is not the first time those 2 functions have created issues when building the Atmel Quad SPI driver on other platforms.

So thanks for you're patch, I'll give it a try :)

Best regards,

Cyrille

Quoted 3 lines
drivers/mtd/spi-nor/atmel-quadspi.c +0 -0
 	return 0;
 }
#2 lore raw
Quoted 17 lines · Cyrille Pitchen

drivers/mtd/spi-nor/atmel-quadspi.c static int atmel_qspi_run_transfer(struct atmel_qspi *aq, · line 214

Quoted 12 lines · Arnd Bergmann
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
      if (cmd->enable.bits.address)
              ahb_mem += cmd->address;
      if (cmd->tx_buf)
-             _memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+             memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
      else
-             _memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+             memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 

At least on AT91 platforms and likely on most ARM boards, memcpy_fromio == memcpy_toio == memcpy.

Just to give more background, it's a bit more complicated than this:

On big-endian kernels, memcpy_fromio/memcpy_toio are always defined as _memcpy_fromio/_memcpy_toio so we
do byte load/store operations in the correct order, while little-endian kernels have the optimized mmiocpy() that redirects to memcpy(). This is true for all ARM platforms other than EBSA110 IIRC.

Also, mmiocpy is an exported symbol that aliases to the external memcpy definition, but we can't call memcpy directly, because gcc knows how to inline calls to memcpy() and replace them by direct load/store instructions that might be unaligned and trap on uncached mmio areas.

Quoted 8 lines

I got some sama5d2 hardware last week, so I'll try to test your patch within few days because as you said maybe memcpy() was broken when I developed this driver at first but now memcpy() is likely to have been fixed so it might be interesting to get rid of _memcpy_fromio() and _memcpy_toio() because this is not the first time those 2 functions have created issues when building the Atmel Quad SPI driver on other platforms.

So thanks for you're patch, I'll give it a try :)

Ok, thanks.

Arnd

#3 lore raw

Hi Arnd,

+ Nicolas Ferre

Le 01/08/2017 à 22:10, Arnd Bergmann a écrit :

Quoted 29 lines
Quoted 17 lines · Cyrille Pitchen

drivers/mtd/spi-nor/atmel-quadspi.c static int atmel_qspi_run_transfer(struct atmel_qspi *aq, · line 214

Quoted 12 lines · Arnd Bergmann
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
      if (cmd->enable.bits.address)
              ahb_mem += cmd->address;
      if (cmd->tx_buf)
-             _memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+             memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
      else
-             _memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+             memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 

At least on AT91 platforms and likely on most ARM boards, memcpy_fromio == memcpy_toio == memcpy.

Just to give more background, it's a bit more complicated than this:

On big-endian kernels, memcpy_fromio/memcpy_toio are always defined as _memcpy_fromio/_memcpy_toio so we
do byte load/store operations in the correct order, while little-endian kernels have the optimized mmiocpy() that redirects to memcpy(). This is true for all ARM platforms other than EBSA110 IIRC.

Quoted 15 lines

Also, mmiocpy is an exported symbol that aliases to the external memcpy definition, but we can't call memcpy directly, because gcc knows how to inline calls to memcpy() and replace them by direct load/store instructions that might be unaligned and trap on uncached mmio areas.

Quoted 8 lines

I got some sama5d2 hardware last week, so I'll try to test your patch within few days because as you said maybe memcpy() was broken when I developed this driver at first but now memcpy() is likely to have been fixed so it might be interesting to get rid of _memcpy_fromio() and _memcpy_toio() because this is not the first time those 2 functions have created issues when building the Atmel Quad SPI driver on other platforms.

So thanks for you're patch, I'll give it a try :)

Bad news:

I've just tested this patch, applied onto the spi-nor/next branch of l2-mtd (based on 4.14.0-rc4), with a sama5d2 xplained board + Macronix MX25L25673G Quad SPI memory but it fails on the very first SPI command, Read JEDEC ID (9Fh):

atmel_qspi f0020000.spi: unrecognized JEDEC id bytes: c2, 20, 20
atmel_qspi: probe of f0020000.spi failed with error -2

Best regards,

Cyrille

Quoted 4 lines

Ok, thanks.

Arnd

#4 lore raw
Quoted 52 lines · Cyrille Pitchen

Hi Arnd,

+ Nicolas Ferre

Quoted 29 lines · Arnd Bergmann
Quoted 17 lines · Cyrille Pitchen

drivers/mtd/spi-nor/atmel-quadspi.c static int atmel_qspi_run_transfer(struct atmel_qspi *aq, · line 214

Quoted 12 lines · Arnd Bergmann
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
      if (cmd->enable.bits.address)
              ahb_mem += cmd->address;
      if (cmd->tx_buf)
-             _memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+             memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
      else
-             _memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+             memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 

At least on AT91 platforms and likely on most ARM boards, memcpy_fromio == memcpy_toio == memcpy.

Just to give more background, it's a bit more complicated than this:

On big-endian kernels, memcpy_fromio/memcpy_toio are always defined as _memcpy_fromio/_memcpy_toio so we
do byte load/store operations in the correct order, while little-endian kernels have the optimized mmiocpy() that redirects to memcpy(). This is true for all ARM platforms other than EBSA110 IIRC.

Quoted 15 lines

Also, mmiocpy is an exported symbol that aliases to the external memcpy definition, but we can't call memcpy directly, because gcc knows how to inline calls to memcpy() and replace them by direct load/store instructions that might be unaligned and trap on uncached mmio areas.

Quoted 8 lines

I got some sama5d2 hardware last week, so I'll try to test your patch within few days because as you said maybe memcpy() was broken when I developed this driver at first but now memcpy() is likely to have been fixed so it might be interesting to get rid of _memcpy_fromio() and _memcpy_toio() because this is not the first time those 2 functions have created issues when building the Atmel Quad SPI driver on other platforms.

So thanks for you're patch, I'll give it a try :)

Bad news:

Quoted 7 lines

I've just tested this patch, applied onto the spi-nor/next branch of l2-mtd (based on 4.14.0-rc4), with a sama5d2 xplained board + Macronix MX25L25673G Quad SPI memory but it fails on the very first SPI command, Read JEDEC ID (9Fh):

atmel_qspi f0020000.spi: unrecognized JEDEC id bytes: c2, 20, 20
atmel_qspi: probe of f0020000.spi failed with error -2

Ah, too bad. Should we just add the !ARCH_EBSA110 dependency then?

Arnd

#5 lore raw

Hi Arnd,

Le 16/10/2017 à 13:53, Arnd Bergmann a écrit :

Quoted 59 lines
Quoted 57 lines · Cyrille Pitchen

Hi Arnd,

+ Nicolas Ferre

Quoted 29 lines · Arnd Bergmann
Quoted 17 lines · Cyrille Pitchen

drivers/mtd/spi-nor/atmel-quadspi.c static int atmel_qspi_run_transfer(struct atmel_qspi *aq, · line 214

Quoted 12 lines · Arnd Bergmann
drivers/mtd/spi-nor/atmel-quadspi.c +2 -2
@@ -208,9 +208,9 @@ static int atmel_qspi_run_transfer(struct atmel_qspi *aq,
      if (cmd->enable.bits.address)
              ahb_mem += cmd->address;
      if (cmd->tx_buf)
-             _memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
+             memcpy_toio(ahb_mem, cmd->tx_buf, cmd->buf_len);
      else
-             _memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
+             memcpy_fromio(cmd->rx_buf, ahb_mem, cmd->buf_len);
 

At least on AT91 platforms and likely on most ARM boards, memcpy_fromio == memcpy_toio == memcpy.

Just to give more background, it's a bit more complicated than this:

On big-endian kernels, memcpy_fromio/memcpy_toio are always defined as _memcpy_fromio/_memcpy_toio so we
do byte load/store operations in the correct order, while little-endian kernels have the optimized mmiocpy() that redirects to memcpy(). This is true for all ARM platforms other than EBSA110 IIRC.

Quoted 15 lines

Also, mmiocpy is an exported symbol that aliases to the external memcpy definition, but we can't call memcpy directly, because gcc knows how to inline calls to memcpy() and replace them by direct load/store instructions that might be unaligned and trap on uncached mmio areas.

Quoted 8 lines

I got some sama5d2 hardware last week, so I'll try to test your patch within few days because as you said maybe memcpy() was broken when I developed this driver at first but now memcpy() is likely to have been fixed so it might be interesting to get rid of _memcpy_fromio() and _memcpy_toio() because this is not the first time those 2 functions have created issues when building the Atmel Quad SPI driver on other platforms.

So thanks for you're patch, I'll give it a try :)

Bad news:

I've just tested this patch, applied onto the spi-nor/next branch of l2-mtd (based on 4.14.0-rc4), with a sama5d2 xplained board + Macronix MX25L25673G Quad SPI memory but it fails on the very first SPI command, Read JEDEC ID (9Fh):

Quoted 5 lines
Quoted 2 lines

atmel_qspi f0020000.spi: unrecognized JEDEC id bytes: c2, 20, 20
atmel_qspi: probe of f0020000.spi failed with error -2

Ah, too bad. Should we just add the !ARCH_EBSA110 dependency then?

If it fixes the issue then I'm fine with this proposal.

Best regards,

Cyrille

Quoted 3 lines

Arnd