[PATCH 1/2] net: dwc_eth_qos: Split TX and RX DMA rings

Ramon Fried rfried.dev at gmail.com
Sun Oct 16 20:15:27 CEST 2022


On Sun, Oct 9, 2022 at 6:51 PM Marek Vasut <marex at denx.de> wrote:
>
> Separate TX and RX DMA rings to make their handling slightly clearer.
> This is a preparatory patch for bulk RX descriptor flushing.
>
> Signed-off-by: Marek Vasut <marex at denx.de>
> ---
> Cc: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Patrice Chotard <patrice.chotard at foss.st.com>
> Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>
> Cc: Ramon Fried <rfried.dev at gmail.com>
> Cc: Stephen Warren <swarren at nvidia.com>
> ---
>  drivers/net/dwc_eth_qos.c | 33 ++++++++++++++++++++++-----------
>  drivers/net/dwc_eth_qos.h |  3 ++-
>  2 files changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
> index 001b028fa13..dde2c183b06 100644
> --- a/drivers/net/dwc_eth_qos.c
> +++ b/drivers/net/dwc_eth_qos.c
> @@ -75,9 +75,6 @@
>   */
>  static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num)
>  {
> -       eqos->desc_size = ALIGN(sizeof(struct eqos_desc),
> -                               (unsigned int)ARCH_DMA_MINALIGN);
> -
>         return memalign(eqos->desc_size, num * eqos->desc_size);
>  }
>
> @@ -89,8 +86,8 @@ static void eqos_free_descs(void *descs)
>  static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos,
>                                        unsigned int num, bool rx)
>  {
> -       return eqos->descs +
> -               ((rx ? EQOS_DESCRIPTORS_TX : 0) + num) * eqos->desc_size;
> +       return (rx ? eqos->rx_descs : eqos->tx_descs) +
> +              (num * eqos->desc_size);
>  }
>
>  void eqos_inval_desc_generic(void *desc)
> @@ -1001,7 +998,8 @@ static int eqos_start(struct udevice *dev)
>
>         /* Set up descriptors */
>
> -       memset(eqos->descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_NUM);
> +       memset(eqos->tx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_TX);
> +       memset(eqos->rx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_RX);
>
>         for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) {
>                 struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false);
> @@ -1234,13 +1232,23 @@ static int eqos_probe_resources_core(struct udevice *dev)
>
>         debug("%s(dev=%p):\n", __func__, dev);
>
> -       eqos->descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_NUM);
> -       if (!eqos->descs) {
> -               debug("%s: eqos_alloc_descs() failed\n", __func__);
> +       eqos->desc_size = ALIGN(sizeof(struct eqos_desc),
> +                               (unsigned int)ARCH_DMA_MINALIGN);
> +
> +       eqos->tx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_TX);
> +       if (!eqos->tx_descs) {
> +               debug("%s: eqos_alloc_descs(tx) failed\n", __func__);
>                 ret = -ENOMEM;
>                 goto err;
>         }
>
> +       eqos->rx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_RX);
> +       if (!eqos->rx_descs) {
> +               debug("%s: eqos_alloc_descs(rx) failed\n", __func__);
> +               ret = -ENOMEM;
> +               goto err_free_tx_descs;
> +       }
> +
>         eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE);
>         if (!eqos->tx_dma_buf) {
>                 debug("%s: memalign(tx_dma_buf) failed\n", __func__);
> @@ -1276,7 +1284,9 @@ err_free_rx_dma_buf:
>  err_free_tx_dma_buf:
>         free(eqos->tx_dma_buf);
>  err_free_descs:
> -       eqos_free_descs(eqos->descs);
> +       eqos_free_descs(eqos->rx_descs);
> +err_free_tx_descs:
> +       eqos_free_descs(eqos->tx_descs);
>  err:
>
>         debug("%s: returns %d\n", __func__, ret);
> @@ -1292,7 +1302,8 @@ static int eqos_remove_resources_core(struct udevice *dev)
>         free(eqos->rx_pkt);
>         free(eqos->rx_dma_buf);
>         free(eqos->tx_dma_buf);
> -       eqos_free_descs(eqos->descs);
> +       eqos_free_descs(eqos->rx_descs);
> +       eqos_free_descs(eqos->tx_descs);
>
>         debug("%s: OK\n", __func__);
>         return 0;
> diff --git a/drivers/net/dwc_eth_qos.h b/drivers/net/dwc_eth_qos.h
> index b35e7742634..e3e43c86d11 100644
> --- a/drivers/net/dwc_eth_qos.h
> +++ b/drivers/net/dwc_eth_qos.h
> @@ -264,7 +264,8 @@ struct eqos_priv {
>         struct phy_device *phy;
>         ofnode phy_of_node;
>         u32 max_speed;
> -       void *descs;
> +       void *tx_descs;
> +       void *rx_descs;
>         int tx_desc_idx, rx_desc_idx;
>         unsigned int desc_size;
>         void *tx_dma_buf;
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list