airoha: backport patch fixing out of order DMA for ethernet driver
authorChristian Marangi <[email protected]>
Mon, 10 Nov 2025 18:27:11 +0000 (19:27 +0100)
committerChristian Marangi <[email protected]>
Mon, 10 Nov 2025 18:27:11 +0000 (19:27 +0100)
Backport upstream patch fixing out of order DMA access for ethernet
driver. This is relevant in the context of QoS when packets doesn't
follow linear handling by QDMA HW.

Signed-off-by: Christian Marangi <[email protected]>
target/linux/airoha/patches-6.12/108-v6.19-net-airoha-Add-the-capability-to-consume-out-of-orde.patch [new file with mode: 0644]
target/linux/airoha/patches-6.12/116-02-net-airoha-deassert-XSI-line-on-hw-init.patch
target/linux/airoha/patches-6.12/116-06-net-airoha-add-initial-fixup-for-GDM3-4-port-support.patch
target/linux/airoha/patches-6.12/116-07-airoha-ethernet-drop-xsi-mac-reset.patch
target/linux/airoha/patches-6.12/116-10-net-airoha-add-phylink-support-for-GDM2-4.patch
target/linux/airoha/patches-6.12/606-net-airoha-disable-external-phy-code-if-PCS_AIROHA-i.patch

diff --git a/target/linux/airoha/patches-6.12/108-v6.19-net-airoha-Add-the-capability-to-consume-out-of-orde.patch b/target/linux/airoha/patches-6.12/108-v6.19-net-airoha-Add-the-capability-to-consume-out-of-orde.patch
new file mode 100644 (file)
index 0000000..b09ebd5
--- /dev/null
@@ -0,0 +1,245 @@
+From 3f47e67dff1f7266e112c50313d63824f6f17102 Mon Sep 17 00:00:00 2001
+From: Lorenzo Bianconi <[email protected]>
+Date: Thu, 6 Nov 2025 13:53:23 +0100
+Subject: [PATCH] net: airoha: Add the capability to consume out-of-order DMA
+ tx descriptors
+
+EN7581 and AN7583 SoCs are capable of DMA mapping non-linear tx skbs on
+non-consecutive DMA descriptors. This feature is useful when multiple
+flows are queued on the same hw tx queue since it allows to fully utilize
+the available tx DMA descriptors and to avoid the starvation of
+high-priority flow we have in the current codebase due to head-of-line
+blocking introduced by low-priority flows.
+
+Tested-by: Xuegang Lu <[email protected]>
+Reviewed-by: Jacob Keller <[email protected]>
+Signed-off-by: Lorenzo Bianconi <[email protected]>
+Link: https://patch.msgid.link/[email protected]
+Signed-off-by: Jakub Kicinski <[email protected]>
+---
+ drivers/net/ethernet/airoha/airoha_eth.c | 85 +++++++++++-------------
+ drivers/net/ethernet/airoha/airoha_eth.h |  7 +-
+ 2 files changed, 45 insertions(+), 47 deletions(-)
+
+--- a/drivers/net/ethernet/airoha/airoha_eth.c
++++ b/drivers/net/ethernet/airoha/airoha_eth.c
+@@ -892,19 +892,13 @@ static int airoha_qdma_tx_napi_poll(stru
+               dma_unmap_single(eth->dev, e->dma_addr, e->dma_len,
+                                DMA_TO_DEVICE);
+-              memset(e, 0, sizeof(*e));
++              e->dma_addr = 0;
++              list_add_tail(&e->list, &q->tx_list);
++
+               WRITE_ONCE(desc->msg0, 0);
+               WRITE_ONCE(desc->msg1, 0);
+               q->queued--;
+-              /* completion ring can report out-of-order indexes if hw QoS
+-               * is enabled and packets with different priority are queued
+-               * to same DMA ring. Take into account possible out-of-order
+-               * reports incrementing DMA ring tail pointer
+-               */
+-              while (q->tail != q->head && !q->entry[q->tail].dma_addr)
+-                      q->tail = (q->tail + 1) % q->ndesc;
+-
+               if (skb) {
+                       u16 queue = skb_get_queue_mapping(skb);
+                       struct netdev_queue *txq;
+@@ -949,6 +943,7 @@ static int airoha_qdma_init_tx_queue(str
+       q->ndesc = size;
+       q->qdma = qdma;
+       q->free_thr = 1 + MAX_SKB_FRAGS;
++      INIT_LIST_HEAD(&q->tx_list);
+       q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
+                               GFP_KERNEL);
+@@ -961,9 +956,9 @@ static int airoha_qdma_init_tx_queue(str
+               return -ENOMEM;
+       for (i = 0; i < q->ndesc; i++) {
+-              u32 val;
++              u32 val = FIELD_PREP(QDMA_DESC_DONE_MASK, 1);
+-              val = FIELD_PREP(QDMA_DESC_DONE_MASK, 1);
++              list_add_tail(&q->entry[i].list, &q->tx_list);
+               WRITE_ONCE(q->desc[i].ctrl, cpu_to_le32(val));
+       }
+@@ -973,9 +968,9 @@ static int airoha_qdma_init_tx_queue(str
+       airoha_qdma_wr(qdma, REG_TX_RING_BASE(qid), dma_addr);
+       airoha_qdma_rmw(qdma, REG_TX_CPU_IDX(qid), TX_RING_CPU_IDX_MASK,
+-                      FIELD_PREP(TX_RING_CPU_IDX_MASK, q->head));
++                      FIELD_PREP(TX_RING_CPU_IDX_MASK, 0));
+       airoha_qdma_rmw(qdma, REG_TX_DMA_IDX(qid), TX_RING_DMA_IDX_MASK,
+-                      FIELD_PREP(TX_RING_DMA_IDX_MASK, q->head));
++                      FIELD_PREP(TX_RING_DMA_IDX_MASK, 0));
+       return 0;
+ }
+@@ -1031,17 +1026,21 @@ static int airoha_qdma_init_tx(struct ai
+ static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
+ {
+       struct airoha_eth *eth = q->qdma->eth;
++      int i;
+       spin_lock_bh(&q->lock);
+-      while (q->queued) {
+-              struct airoha_queue_entry *e = &q->entry[q->tail];
++      for (i = 0; i < q->ndesc; i++) {
++              struct airoha_queue_entry *e = &q->entry[i];
++
++              if (!e->dma_addr)
++                      continue;
+               dma_unmap_single(eth->dev, e->dma_addr, e->dma_len,
+                                DMA_TO_DEVICE);
+               dev_kfree_skb_any(e->skb);
++              e->dma_addr = 0;
+               e->skb = NULL;
+-
+-              q->tail = (q->tail + 1) % q->ndesc;
++              list_add_tail(&e->list, &q->tx_list);
+               q->queued--;
+       }
+       spin_unlock_bh(&q->lock);
+@@ -1883,20 +1882,6 @@ static u32 airoha_get_dsa_tag(struct sk_
+ #endif
+ }
+-static bool airoha_dev_tx_queue_busy(struct airoha_queue *q, u32 nr_frags)
+-{
+-      u32 tail = q->tail <= q->head ? q->tail + q->ndesc : q->tail;
+-      u32 index = q->head + nr_frags;
+-
+-      /* completion napi can free out-of-order tx descriptors if hw QoS is
+-       * enabled and packets with different priorities are queued to the same
+-       * DMA ring. Take into account possible out-of-order reports checking
+-       * if the tx queue is full using circular buffer head/tail pointers
+-       * instead of the number of queued packets.
+-       */
+-      return index >= tail;
+-}
+-
+ static int airoha_get_fe_port(struct airoha_gdm_port *port)
+ {
+       struct airoha_qdma *qdma = port->qdma;
+@@ -1919,8 +1904,10 @@ static netdev_tx_t airoha_dev_xmit(struc
+       struct airoha_gdm_port *port = netdev_priv(dev);
+       struct airoha_qdma *qdma = port->qdma;
+       u32 nr_frags, tag, msg0, msg1, len;
++      struct airoha_queue_entry *e;
+       struct netdev_queue *txq;
+       struct airoha_queue *q;
++      LIST_HEAD(tx_list);
+       void *data;
+       int i, qid;
+       u16 index;
+@@ -1966,7 +1953,7 @@ static netdev_tx_t airoha_dev_xmit(struc
+       txq = netdev_get_tx_queue(dev, qid);
+       nr_frags = 1 + skb_shinfo(skb)->nr_frags;
+-      if (airoha_dev_tx_queue_busy(q, nr_frags)) {
++      if (q->queued + nr_frags >= q->ndesc) {
+               /* not enough space in the queue */
+               netif_tx_stop_queue(txq);
+               spin_unlock_bh(&q->lock);
+@@ -1975,11 +1962,13 @@ static netdev_tx_t airoha_dev_xmit(struc
+       len = skb_headlen(skb);
+       data = skb->data;
+-      index = q->head;
++
++      e = list_first_entry(&q->tx_list, struct airoha_queue_entry,
++                           list);
++      index = e - q->entry;
+       for (i = 0; i < nr_frags; i++) {
+               struct airoha_qdma_desc *desc = &q->desc[index];
+-              struct airoha_queue_entry *e = &q->entry[index];
+               skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+               dma_addr_t addr;
+               u32 val;
+@@ -1989,7 +1978,14 @@ static netdev_tx_t airoha_dev_xmit(struc
+               if (unlikely(dma_mapping_error(dev->dev.parent, addr)))
+                       goto error_unmap;
+-              index = (index + 1) % q->ndesc;
++              list_move_tail(&e->list, &tx_list);
++              e->skb = i ? NULL : skb;
++              e->dma_addr = addr;
++              e->dma_len = len;
++
++              e = list_first_entry(&q->tx_list, struct airoha_queue_entry,
++                                   list);
++              index = e - q->entry;
+               val = FIELD_PREP(QDMA_DESC_LEN_MASK, len);
+               if (i < nr_frags - 1)
+@@ -2002,15 +1998,9 @@ static netdev_tx_t airoha_dev_xmit(struc
+               WRITE_ONCE(desc->msg1, cpu_to_le32(msg1));
+               WRITE_ONCE(desc->msg2, cpu_to_le32(0xffff));
+-              e->skb = i ? NULL : skb;
+-              e->dma_addr = addr;
+-              e->dma_len = len;
+-
+               data = skb_frag_address(frag);
+               len = skb_frag_size(frag);
+       }
+-
+-      q->head = index;
+       q->queued += i;
+       skb_tx_timestamp(skb);
+@@ -2019,7 +2009,7 @@ static netdev_tx_t airoha_dev_xmit(struc
+       if (netif_xmit_stopped(txq) || !netdev_xmit_more())
+               airoha_qdma_rmw(qdma, REG_TX_CPU_IDX(qid),
+                               TX_RING_CPU_IDX_MASK,
+-                              FIELD_PREP(TX_RING_CPU_IDX_MASK, q->head));
++                              FIELD_PREP(TX_RING_CPU_IDX_MASK, index));
+       if (q->ndesc - q->queued < q->free_thr)
+               netif_tx_stop_queue(txq);
+@@ -2029,10 +2019,13 @@ static netdev_tx_t airoha_dev_xmit(struc
+       return NETDEV_TX_OK;
+ error_unmap:
+-      for (i--; i >= 0; i--) {
+-              index = (q->head + i) % q->ndesc;
+-              dma_unmap_single(dev->dev.parent, q->entry[index].dma_addr,
+-                               q->entry[index].dma_len, DMA_TO_DEVICE);
++      while (!list_empty(&tx_list)) {
++              e = list_first_entry(&tx_list, struct airoha_queue_entry,
++                                   list);
++              dma_unmap_single(dev->dev.parent, e->dma_addr, e->dma_len,
++                               DMA_TO_DEVICE);
++              e->dma_addr = 0;
++              list_move_tail(&e->list, &q->tx_list);
+       }
+       spin_unlock_bh(&q->lock);
+--- a/drivers/net/ethernet/airoha/airoha_eth.h
++++ b/drivers/net/ethernet/airoha/airoha_eth.h
+@@ -169,7 +169,10 @@ enum trtcm_param {
+ struct airoha_queue_entry {
+       union {
+               void *buf;
+-              struct sk_buff *skb;
++              struct {
++                      struct list_head list;
++                      struct sk_buff *skb;
++              };
+       };
+       dma_addr_t dma_addr;
+       u16 dma_len;
+@@ -193,6 +196,8 @@ struct airoha_queue {
+       struct napi_struct napi;
+       struct page_pool *page_pool;
+       struct sk_buff *skb;
++
++      struct list_head tx_list;
+ };
+ struct airoha_tx_irq_queue {
index d7e312dfcf4eb2fe89d522b45b33510332dde547..41425bbc69ca9810e151c6643e14a147513cb6ae 100644 (file)
@@ -13,7 +13,7 @@ Signed-off-by: Christian Marangi <[email protected]>
 
 --- a/drivers/net/ethernet/airoha/airoha_eth.c
 +++ b/drivers/net/ethernet/airoha/airoha_eth.c
-@@ -1383,6 +1383,10 @@ static int airoha_hw_init(struct platfor
+@@ -1382,6 +1382,10 @@ static int airoha_hw_init(struct platfor
        if (err)
                return err;
  
index 7b395bfcb7170a301ac95a93f264bda0a5781e6f..3805febe717b7417aa361cfccb7f381358cc2e07 100644 (file)
@@ -28,7 +28,7 @@ Signed-off-by: Christian Marangi <[email protected]>
  
        airoha_fe_crsn_qsel_init(eth);
  
-@@ -1625,7 +1627,8 @@ static int airoha_dev_open(struct net_de
+@@ -1624,7 +1626,8 @@ static int airoha_dev_open(struct net_de
        if (err)
                return err;
  
index 508ae97154c9e483a1d6a193f10576d035eb24a1..7e0fc5a7988e2eb2b93dd19b5f2e1e21f711370c 100644 (file)
@@ -15,7 +15,7 @@ Signed-off-by: Christian Marangi <[email protected]>
 
 --- a/drivers/net/ethernet/airoha/airoha_eth.c
 +++ b/drivers/net/ethernet/airoha/airoha_eth.c
-@@ -3095,7 +3095,6 @@ static void airoha_remove(struct platfor
+@@ -3088,7 +3088,6 @@ static void airoha_remove(struct platfor
  }
  
  static const char * const en7581_xsi_rsts_names[] = {
@@ -23,7 +23,7 @@ Signed-off-by: Christian Marangi <[email protected]>
        "hsi0-mac",
        "hsi1-mac",
        "hsi-mac",
-@@ -3127,7 +3126,6 @@ static int airoha_en7581_get_src_port_id
+@@ -3120,7 +3119,6 @@ static int airoha_en7581_get_src_port_id
  }
  
  static const char * const an7583_xsi_rsts_names[] = {
index 8ce66b706ab13a548721a654e0e28c08f6730867..d0e658b81e3b8cb1d2dbf59e6e076f44edb0f79f 100644 (file)
@@ -35,7 +35,7 @@ Signed-off-by: Christian Marangi <[email protected]>
  static void airoha_set_macaddr(struct airoha_gdm_port *port, const u8 *addr)
  {
        struct airoha_eth *eth = port->qdma->eth;
-@@ -1622,6 +1628,17 @@ static int airoha_dev_open(struct net_de
+@@ -1621,6 +1627,17 @@ static int airoha_dev_open(struct net_de
        struct airoha_gdm_port *port = netdev_priv(dev);
        struct airoha_qdma *qdma = port->qdma;
  
@@ -53,7 +53,7 @@ Signed-off-by: Christian Marangi <[email protected]>
        netif_tx_start_all_queues(dev);
        err = airoha_set_vip_for_gdm_port(port, true);
        if (err)
-@@ -1675,6 +1692,11 @@ static int airoha_dev_stop(struct net_de
+@@ -1674,6 +1691,11 @@ static int airoha_dev_stop(struct net_de
                }
        }
  
@@ -65,7 +65,7 @@ Signed-off-by: Christian Marangi <[email protected]>
        return 0;
  }
  
-@@ -2823,6 +2845,20 @@ static const struct ethtool_ops airoha_e
+@@ -2816,6 +2838,20 @@ static const struct ethtool_ops airoha_e
        .get_link               = ethtool_op_get_link,
  };
  
@@ -86,7 +86,7 @@ Signed-off-by: Christian Marangi <[email protected]>
  static int airoha_metadata_dst_alloc(struct airoha_gdm_port *port)
  {
        int i;
-@@ -2867,6 +2903,99 @@ bool airoha_is_valid_gdm_port(struct air
+@@ -2860,6 +2896,99 @@ bool airoha_is_valid_gdm_port(struct air
        return false;
  }
  
@@ -186,7 +186,7 @@ Signed-off-by: Christian Marangi <[email protected]>
  static int airoha_alloc_gdm_port(struct airoha_eth *eth,
                                 struct device_node *np, int index)
  {
-@@ -2945,6 +3074,12 @@ static int airoha_alloc_gdm_port(struct
+@@ -2938,6 +3067,12 @@ static int airoha_alloc_gdm_port(struct
        if (err)
                return err;
  
@@ -199,7 +199,7 @@ Signed-off-by: Christian Marangi <[email protected]>
        err = register_netdev(dev);
        if (err)
                goto free_metadata_dst;
-@@ -3060,6 +3195,10 @@ error_hw_cleanup:
+@@ -3053,6 +3188,10 @@ error_hw_cleanup:
                if (port && port->dev->reg_state == NETREG_REGISTERED) {
                        unregister_netdev(port->dev);
                        airoha_metadata_dst_free(port);
@@ -210,7 +210,7 @@ Signed-off-by: Christian Marangi <[email protected]>
                }
        }
        free_netdev(eth->napi_dev);
-@@ -3087,6 +3226,10 @@ static void airoha_remove(struct platfor
+@@ -3080,6 +3219,10 @@ static void airoha_remove(struct platfor
                airoha_dev_stop(port->dev);
                unregister_netdev(port->dev);
                airoha_metadata_dst_free(port);
@@ -223,7 +223,7 @@ Signed-off-by: Christian Marangi <[email protected]>
  
 --- a/drivers/net/ethernet/airoha/airoha_eth.h
 +++ b/drivers/net/ethernet/airoha/airoha_eth.h
-@@ -531,6 +531,10 @@ struct airoha_gdm_port {
+@@ -536,6 +536,10 @@ struct airoha_gdm_port {
        struct net_device *dev;
        int id;
  
index 1734019d53ae42cb2fdf73d36877c4b10443a84d..bcc80b002d1c10c4a21ef4e5a7a7796484944ec6 100644 (file)
@@ -28,7 +28,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
  static void airoha_set_macaddr(struct airoha_gdm_port *port, const u8 *addr)
  {
-@@ -1631,6 +1633,7 @@ static int airoha_dev_open(struct net_de
+@@ -1630,6 +1632,7 @@ static int airoha_dev_open(struct net_de
        struct airoha_gdm_port *port = netdev_priv(dev);
        struct airoha_qdma *qdma = port->qdma;
  
@@ -36,7 +36,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
        if (airhoa_is_phy_external(port)) {
                err = phylink_of_phy_connect(port->phylink, dev->dev.of_node, 0);
                if (err) {
-@@ -1641,6 +1644,7 @@ static int airoha_dev_open(struct net_de
+@@ -1640,6 +1643,7 @@ static int airoha_dev_open(struct net_de
  
                phylink_start(port->phylink);
        }
@@ -44,7 +44,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
        netif_tx_start_all_queues(dev);
        err = airoha_set_vip_for_gdm_port(port, true);
-@@ -1695,10 +1699,12 @@ static int airoha_dev_stop(struct net_de
+@@ -1694,10 +1698,12 @@ static int airoha_dev_stop(struct net_de
                }
        }
  
@@ -57,7 +57,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
        return 0;
  }
-@@ -2848,6 +2854,7 @@ static const struct ethtool_ops airoha_e
+@@ -2841,6 +2847,7 @@ static const struct ethtool_ops airoha_e
        .get_link               = ethtool_op_get_link,
  };
  
@@ -65,7 +65,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  static struct phylink_pcs *airoha_phylink_mac_select_pcs(struct phylink_config *config,
                                                         phy_interface_t interface)
  {
-@@ -2861,6 +2868,7 @@ static void airoha_mac_config(struct phy
+@@ -2854,6 +2861,7 @@ static void airoha_mac_config(struct phy
                              const struct phylink_link_state *state)
  {
  }
@@ -73,7 +73,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
  static int airoha_metadata_dst_alloc(struct airoha_gdm_port *port)
  {
-@@ -2906,6 +2914,7 @@ bool airoha_is_valid_gdm_port(struct air
+@@ -2899,6 +2907,7 @@ bool airoha_is_valid_gdm_port(struct air
        return false;
  }
  
@@ -81,7 +81,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy,
                               unsigned int mode, phy_interface_t interface,
                               int speed, int duplex, bool tx_pause, bool rx_pause)
-@@ -2998,6 +3007,7 @@ static int airoha_setup_phylink(struct n
+@@ -2991,6 +3000,7 @@ static int airoha_setup_phylink(struct n
  
        return 0;
  }
@@ -89,7 +89,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
  static int airoha_alloc_gdm_port(struct airoha_eth *eth,
                                 struct device_node *np, int index)
-@@ -3077,11 +3087,13 @@ static int airoha_alloc_gdm_port(struct
+@@ -3070,11 +3080,13 @@ static int airoha_alloc_gdm_port(struct
        if (err)
                return err;
  
@@ -103,7 +103,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
        err = register_netdev(dev);
        if (err)
-@@ -3198,10 +3210,12 @@ error_hw_cleanup:
+@@ -3191,10 +3203,12 @@ error_hw_cleanup:
                if (port && port->dev->reg_state == NETREG_REGISTERED) {
                        unregister_netdev(port->dev);
                        airoha_metadata_dst_free(port);
@@ -116,7 +116,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
                }
        }
        free_netdev(eth->napi_dev);
-@@ -3229,10 +3243,12 @@ static void airoha_remove(struct platfor
+@@ -3222,10 +3236,12 @@ static void airoha_remove(struct platfor
                airoha_dev_stop(port->dev);
                unregister_netdev(port->dev);
                airoha_metadata_dst_free(port);
@@ -131,7 +131,7 @@ Signed-off-by: Mikhail Kshevetskiy <[email protected]>
  
 --- a/drivers/net/ethernet/airoha/airoha_eth.h
 +++ b/drivers/net/ethernet/airoha/airoha_eth.h
-@@ -531,9 +531,11 @@ struct airoha_gdm_port {
+@@ -536,9 +536,11 @@ struct airoha_gdm_port {
        struct net_device *dev;
        int id;