Re: [PATCH v2 15/29] net: designware: fix non-1:1 mapped 64-bit systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jun 19, 2021 at 06:50:41AM +0200, Ahmad Fatoum wrote:
> drivers/net/designware.c handles the older Designware < 4.x MAC IPs,
> which do not support DMA beyond 32-bit. They are still being integrated
> into SoCs with 64-bit CPUs like the StarFive JH7100, which additionally
> needs a non 1:1 mapping for coherent DMA.
> 
> Fix the driver to support such usage. The driver still has the assumption
> that barebox core will only pass it 32-bit pointers. This is now made
> explicit by returning error codes when the DMA mask is violated.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
>  arch/riscv/include/asm/io.h | 10 +++++++
>  drivers/net/designware.c    | 57 ++++++++++++++++++++++---------------
>  drivers/net/designware.h    | 28 +++++++++++++++---
>  3 files changed, 68 insertions(+), 27 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
> index 3cdea7fcace1..795e670e3b9b 100644
> --- a/arch/riscv/include/asm/io.h
> +++ b/arch/riscv/include/asm/io.h
> @@ -5,4 +5,14 @@
>  
>  #include <asm-generic/io.h>
>  
> +static inline void *phys_to_virt(unsigned long phys)
> +{
> +	return (void *)phys;
> +}
> +
> +static inline unsigned long virt_to_phys(volatile void *mem)
> +{
> +	return (unsigned long)mem;
> +}
> +
>  #endif /* __ASM_RISCV_IO_H */
> diff --git a/drivers/net/designware.c b/drivers/net/designware.c
> index 0ee6d3d78ac7..559e202c29ce 100644
> --- a/drivers/net/designware.c
> +++ b/drivers/net/designware.c
> @@ -104,15 +104,15 @@ static void tx_descs_init(struct eth_device *dev)
>  {
>  	struct dw_eth_dev *priv = dev->priv;
>  	struct eth_dma_regs *dma_p = priv->dma_regs_p;
> -	struct dmamacdescr *desc_table_p = &priv->tx_mac_descrtable[0];
> +	struct dmamacdescr *desc_table_p = &priv->tx_mac_descrtable_cpu[0];
>  	char *txbuffs = &priv->txbuffs[0];
>  	struct dmamacdescr *desc_p;
>  	u32 idx;
>  
>  	for (idx = 0; idx < CONFIG_TX_DESCR_NUM; idx++) {
>  		desc_p = &desc_table_p[idx];
> -		desc_p->dmamac_addr = &txbuffs[idx * CONFIG_ETH_BUFSIZE];
> -		desc_p->dmamac_next = &desc_table_p[idx + 1];
> +		desc_p->dmamac_addr = virt_to_phys(&txbuffs[idx * CONFIG_ETH_BUFSIZE]);
> +		desc_p->dmamac_next = tx_dma_addr(priv, &desc_table_p[idx + 1]);
>  
>  		if (priv->enh_desc) {
>  			desc_p->txrx_status &= ~(DESC_ENH_TXSTS_TXINT | DESC_ENH_TXSTS_TXLAST |
> @@ -130,9 +130,9 @@ static void tx_descs_init(struct eth_device *dev)
>  	}
>  
>  	/* Correcting the last pointer of the chain */
> -	desc_p->dmamac_next = &desc_table_p[0];
> +	desc_p->dmamac_next = tx_dma_addr(priv, &desc_table_p[0]);
>  
> -	writel((ulong)&desc_table_p[0], &dma_p->txdesclistaddr);
> +	writel(desc_p->dmamac_next, &dma_p->txdesclistaddr);
>  	priv->tx_currdescnum = 0;
>  }
>  
> @@ -140,15 +140,15 @@ static void rx_descs_init(struct eth_device *dev)
>  {
>  	struct dw_eth_dev *priv = dev->priv;
>  	struct eth_dma_regs *dma_p = priv->dma_regs_p;
> -	struct dmamacdescr *desc_table_p = &priv->rx_mac_descrtable[0];
> +	struct dmamacdescr *desc_table_p = &priv->rx_mac_descrtable_cpu[0];
>  	char *rxbuffs = &priv->rxbuffs[0];
>  	struct dmamacdescr *desc_p;
>  	u32 idx;
>  
>  	for (idx = 0; idx < CONFIG_RX_DESCR_NUM; idx++) {
>  		desc_p = &desc_table_p[idx];
> -		desc_p->dmamac_addr = &rxbuffs[idx * CONFIG_ETH_BUFSIZE];
> -		desc_p->dmamac_next = &desc_table_p[idx + 1];
> +		desc_p->dmamac_addr = virt_to_phys(&rxbuffs[idx * CONFIG_ETH_BUFSIZE]);

You have both the DMA and virtual addresses available when allocating
the memory. I think you should use this information rather than
introducing the need for a virt_to_phys() phys_to_virt() pair.

> @@ -276,7 +276,7 @@ static int dwc_ether_send(struct eth_device *dev, void *packet, int length)
>  	struct dw_eth_dev *priv = dev->priv;
>  	struct eth_dma_regs *dma_p = priv->dma_regs_p;
>  	u32 owndma, desc_num = priv->tx_currdescnum;
> -	struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num];
> +	struct dmamacdescr *desc_p = &priv->tx_mac_descrtable_cpu[desc_num];
>  
>  	owndma = priv->enh_desc ? DESC_ENH_TXSTS_OWNBYDMA : DESC_TXSTS_OWNBYDMA;
>  	/* Check if the descriptor is owned by CPU */
> @@ -285,8 +285,8 @@ static int dwc_ether_send(struct eth_device *dev, void *packet, int length)
>  		return -1;
>  	}
>  
> -	memcpy((void *)desc_p->dmamac_addr, packet, length);
> -	dma_sync_single_for_device((unsigned long)desc_p->dmamac_addr, length,
> +	memcpy(dmamac_addr(desc_p), packet, length);
> +	dma_sync_single_for_device(desc_p->dmamac_addr, length,
>  				   DMA_TO_DEVICE);

Rather use dma_map_single() here?

Sascha


-- 
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 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux