* [PATCH 1/5] driver: Adopt DMA mask concept from Linux
@ 2018-08-31 5:18 Andrey Smirnov
2018-08-31 5:18 ` [PATCH 2/5] net: fec_imx: Specify that DMA is 32-bit only Andrey Smirnov
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-08-31 5:18 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
In order to be able to detect cases where DMA isn't capable of
reaching every memory address, port the concept of DMA mask,
dma_set_mask() function and add appropriate check to
dma_mapping_error().
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
include/dma.h | 12 +++++++++++-
include/driver.h | 2 ++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/dma.h b/include/dma.h
index 5fdcb1733..7f9578263 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -35,11 +35,21 @@ dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
enum dma_data_direction dir);
+#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
+
+#define DMA_MASK_NONE 0x0ULL
+
+static inline void dma_set_mask(struct device_d *dev, u64 dma_mask)
+{
+ dev->dma_mask = dma_mask;
+}
+
#define DMA_ERROR_CODE (~(dma_addr_t)0)
static inline int dma_mapping_error(struct device_d *dev, dma_addr_t dma_addr)
{
- return dma_addr == DMA_ERROR_CODE;
+ return dma_addr == DMA_ERROR_CODE ||
+ (dev->dma_mask && dma_addr > dev->dma_mask);
}
/* streaming DMA - implement the below calls to support HAS_DMA */
diff --git a/include/driver.h b/include/driver.h
index 91653b794..1b61f2066 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -82,6 +82,8 @@ struct device_d {
const struct of_device_id *of_id_entry;
+ u64 dma_mask;
+
void (*info) (struct device_d *);
/*
* For devices which take longer to probe this is called
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/5] net: fec_imx: Specify that DMA is 32-bit only
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
@ 2018-08-31 5:18 ` Andrey Smirnov
2018-08-31 5:18 ` [PATCH 3/5] mci: imx-esdhc: " Andrey Smirnov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-08-31 5:18 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
FEC can only do a DMA transfer to 32-bit address space, so mark it as
such.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/net/fec_imx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 087483801..f459516df 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -769,6 +769,8 @@ static int fec_probe(struct device_d *dev)
edev->set_ethaddr = fec_set_hwaddr;
edev->parent = dev;
+ dma_set_mask(dev, DMA_BIT_MASK(32));
+
ret = fec_clk_get(fec);
if (ret < 0)
goto err_free;
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] mci: imx-esdhc: Specify that DMA is 32-bit only
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
2018-08-31 5:18 ` [PATCH 2/5] net: fec_imx: Specify that DMA is 32-bit only Andrey Smirnov
@ 2018-08-31 5:18 ` Andrey Smirnov
2018-08-31 5:18 ` [PATCH 4/5] net: fec_imx: Return EFAULT when DMA mapping fails Andrey Smirnov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-08-31 5:18 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
ESDHC can only do a DMA transfer to 32-bit address space, so mark it
as such.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/mci/imx-esdhc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index db96a8139..7f2472012 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -629,6 +629,8 @@ static int fsl_esdhc_probe(struct device_d *dev)
host->socdata = &esdhc_imx25_data;
}
+ dma_set_mask(dev, DMA_BIT_MASK(32));
+
host->clk = clk_get(dev, "per");
if (IS_ERR(host->clk))
return PTR_ERR(host->clk);
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] net: fec_imx: Return EFAULT when DMA mapping fails
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
2018-08-31 5:18 ` [PATCH 2/5] net: fec_imx: Specify that DMA is 32-bit only Andrey Smirnov
2018-08-31 5:18 ` [PATCH 3/5] mci: imx-esdhc: " Andrey Smirnov
@ 2018-08-31 5:18 ` Andrey Smirnov
2018-08-31 5:18 ` [PATCH 5/5] mci: imx-esdhc: " Andrey Smirnov
2018-08-31 6:46 ` [PATCH 1/5] driver: Adopt DMA mask concept from Linux Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-08-31 5:18 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
EFAULT seems to be much more appropriate error code for DMA mapping
failure, it also produces more informative message, compare:
ping 192.168.53.7
WARNING: eth0: No MAC address set. Using random address 92:4e:f1:18:96:67
eth0: 100Mbps full duplex link detected
ping failed: Bad address
versus old message:
ping 192.168.53.7
WARNING: eth0: No MAC address set. Using random address c6:b7:67:bb:4a:c3
eth0: 100Mbps full duplex link detected
ping failed: I/O error
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/net/fec_imx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index f459516df..33262bdfa 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -466,7 +466,7 @@ static int fec_send(struct eth_device *dev, void *eth_data, int data_length)
dma = dma_map_single(fec->dev, eth_data, data_length, DMA_TO_DEVICE);
if (dma_mapping_error(fec->dev, dma))
- return -EIO;
+ return -EFAULT;
writel((uint32_t)(dma), &fec->tbd_base[fec->tbd_index].data_pointer);
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] mci: imx-esdhc: Return EFAULT when DMA mapping fails
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
` (2 preceding siblings ...)
2018-08-31 5:18 ` [PATCH 4/5] net: fec_imx: Return EFAULT when DMA mapping fails Andrey Smirnov
@ 2018-08-31 5:18 ` Andrey Smirnov
2018-08-31 6:46 ` [PATCH 1/5] driver: Adopt DMA mask concept from Linux Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Andrey Smirnov @ 2018-08-31 5:18 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
EFAULT seems to be much more appropriate error code for DMA mapping
failure
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/mci/imx-esdhc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 7f2472012..7f2285635 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -303,7 +303,7 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
dma = dma_map_single(host->dev, ptr, num_bytes, dir);
if (dma_mapping_error(host->dev, dma))
- return -EIO;
+ return -EFAULT;
}
err = esdhc_setup_data(mci, data, dma);
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/5] driver: Adopt DMA mask concept from Linux
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
` (3 preceding siblings ...)
2018-08-31 5:18 ` [PATCH 5/5] mci: imx-esdhc: " Andrey Smirnov
@ 2018-08-31 6:46 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2018-08-31 6:46 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
On Thu, Aug 30, 2018 at 10:18:22PM -0700, Andrey Smirnov wrote:
> In order to be able to detect cases where DMA isn't capable of
> reaching every memory address, port the concept of DMA mask,
> dma_set_mask() function and add appropriate check to
> dma_mapping_error().
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
Applied, thanks
Sascha
> include/dma.h | 12 +++++++++++-
> include/driver.h | 2 ++
> 2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/include/dma.h b/include/dma.h
> index 5fdcb1733..7f9578263 100644
> --- a/include/dma.h
> +++ b/include/dma.h
> @@ -35,11 +35,21 @@ dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
> void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
> enum dma_data_direction dir);
>
> +#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
> +
> +#define DMA_MASK_NONE 0x0ULL
> +
> +static inline void dma_set_mask(struct device_d *dev, u64 dma_mask)
> +{
> + dev->dma_mask = dma_mask;
> +}
> +
> #define DMA_ERROR_CODE (~(dma_addr_t)0)
>
> static inline int dma_mapping_error(struct device_d *dev, dma_addr_t dma_addr)
> {
> - return dma_addr == DMA_ERROR_CODE;
> + return dma_addr == DMA_ERROR_CODE ||
> + (dev->dma_mask && dma_addr > dev->dma_mask);
> }
>
> /* streaming DMA - implement the below calls to support HAS_DMA */
> diff --git a/include/driver.h b/include/driver.h
> index 91653b794..1b61f2066 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -82,6 +82,8 @@ struct device_d {
>
> const struct of_device_id *of_id_entry;
>
> + u64 dma_mask;
> +
> void (*info) (struct device_d *);
> /*
> * For devices which take longer to probe this is called
> --
> 2.17.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-08-31 6:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31 5:18 [PATCH 1/5] driver: Adopt DMA mask concept from Linux Andrey Smirnov
2018-08-31 5:18 ` [PATCH 2/5] net: fec_imx: Specify that DMA is 32-bit only Andrey Smirnov
2018-08-31 5:18 ` [PATCH 3/5] mci: imx-esdhc: " Andrey Smirnov
2018-08-31 5:18 ` [PATCH 4/5] net: fec_imx: Return EFAULT when DMA mapping fails Andrey Smirnov
2018-08-31 5:18 ` [PATCH 5/5] mci: imx-esdhc: " Andrey Smirnov
2018-08-31 6:46 ` [PATCH 1/5] driver: Adopt DMA mask concept from Linux Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox