* [PATCH master 2/2] net: fsl-fman: fix CONFIG_DMA_API_DEBUG warnings
2024-01-08 10:14 [PATCH master 1/2] net: fsl-fman: fix alignment of RX buffer Ahmad Fatoum
@ 2024-01-08 10:14 ` Ahmad Fatoum
2024-01-10 6:42 ` [PATCH master 1/2] net: fsl-fman: fix alignment of RX buffer Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-01-08 10:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The first time a buffer is provided to a device, it needs to be mapped
with dma_map_single, before dma_sync_single_for_* may be called.
>From a cache coherence point of view, dma_map_single and
dma_sync_single_for_device have the same effect, but the former
is necessary, so DMA API debugging can catch issues.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/net/fsl-fman.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index baafe027c079..12cb240a37c0 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -583,7 +583,6 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
void *rx_bd_ring_base;
void *rx_buf_pool;
u32 bd_ring_base_lo, bd_ring_base_hi;
- u32 buf_lo, buf_hi;
struct fm_port_bd *rxbd;
struct fm_port_qd *rxqd;
struct fm_bmi_rx_port *bmi_rx_port = fm_eth->rx_port;
@@ -631,19 +630,21 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
/* init Rx BDs ring */
for (i = 0; i < RX_BD_RING_SIZE; i++) {
+ dma_addr_t dma;
+
rxbd = &fm_eth->rx_bd_ring[i];
muram_writew(&rxbd->status, RxBD_EMPTY);
muram_writew(&rxbd->len, 0);
- buf_hi = upper_32_bits(virt_to_phys(rx_buf_pool +
- i * MAX_RXBUF_LEN));
- buf_lo = lower_32_bits(virt_to_phys(rx_buf_pool +
- i * MAX_RXBUF_LEN));
- dma_sync_single_for_device(fm_eth->dev,
- (unsigned long)rx_buf_pool + i * MAX_RXBUF_LEN,
- MAX_RXBUF_LEN, DMA_FROM_DEVICE);
- muram_writew(&rxbd->buf_ptr_hi, (u16)buf_hi);
- out_be32(&rxbd->buf_ptr_lo, buf_lo);
+
+ dma = dma_map_single(fm_eth->dev,
+ rx_buf_pool + i * MAX_RXBUF_LEN,
+ MAX_RXBUF_LEN, DMA_FROM_DEVICE);
+ if (dma_mapping_error(fm_eth->dev, dma))
+ return -EFAULT;
+
+ muram_writew(&rxbd->buf_ptr_hi, (u16)upper_32_bits(dma));
+ out_be32(&rxbd->buf_ptr_lo, lower_32_bits(dma));
}
/* set the Rx queue descriptor */
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH master 1/2] net: fsl-fman: fix alignment of RX buffer
2024-01-08 10:14 [PATCH master 1/2] net: fsl-fman: fix alignment of RX buffer Ahmad Fatoum
2024-01-08 10:14 ` [PATCH master 2/2] net: fsl-fman: fix CONFIG_DMA_API_DEBUG warnings Ahmad Fatoum
@ 2024-01-10 6:42 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-01-10 6:42 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Jan 08, 2024 at 11:14:18AM +0100, Ahmad Fatoum wrote:
> The receive buffer needs to be cacheline aligned for cache maintenance
> to avoid invalidating unrelated malloc memory. This was so far not the
> case due to malloc's minimum alignment of 8-byte (with TLSF), so switch
> to dma_alloc instead.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/net/fsl-fman.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
> index ff32fa8fc753..baafe027c079 100644
> --- a/drivers/net/fsl-fman.c
> +++ b/drivers/net/fsl-fman.c
> @@ -620,9 +620,7 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
> * RX_BD_RING_SIZE);
>
> /* alloc Rx buffer from main memory */
> - rx_buf_pool = malloc(MAX_RXBUF_LEN * RX_BD_RING_SIZE);
> - if (!rx_buf_pool)
> - return -ENOMEM;
> + rx_buf_pool = dma_alloc(MAX_RXBUF_LEN * RX_BD_RING_SIZE);
>
> memset(rx_buf_pool, 0, MAX_RXBUF_LEN * RX_BD_RING_SIZE);
>
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread