]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: mana: Handle SKB if TX SGEs exceed hardware limit
authorAditya Garg <gargaditya@linux.microsoft.com>
Tue, 18 Nov 2025 11:11:08 +0000 (03:11 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 20 Nov 2025 04:11:57 +0000 (20:11 -0800)
The MANA hardware supports a maximum of 30 scatter-gather entries (SGEs)
per TX WQE. Exceeding this limit can cause TX failures.
Add ndo_features_check() callback to validate SKB layout before
transmission. For GSO SKBs that would exceed the hardware SGE limit, clear
NETIF_F_GSO_MASK to enforce software segmentation in the stack.
Add a fallback in mana_start_xmit() to linearize non-GSO SKBs that still
exceed the SGE limit.

Also, Add ethtool counter for SKBs linearized

Co-developed-by: Dipayaan Roy <dipayanroy@linux.microsoft.com>
Signed-off-by: Dipayaan Roy <dipayanroy@linux.microsoft.com>
Signed-off-by: Aditya Garg <gargaditya@linux.microsoft.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Link: https://patch.msgid.link/1763464269-10431-2-git-send-email-gargaditya@linux.microsoft.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microsoft/mana/mana_en.c
drivers/net/ethernet/microsoft/mana/mana_ethtool.c
include/net/mana/gdma.h
include/net/mana/mana.h

index 13f47be7aca6996b56a468ab7a01e5a1a7ba9cc3..7b49ab005e2d258b0d16fab9e1cdadbd219dc2a3 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/mm.h>
 #include <linux/pci.h>
 #include <linux/export.h>
+#include <linux/skbuff.h>
 
 #include <net/checksum.h>
 #include <net/ip6_checksum.h>
@@ -329,6 +330,21 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)
        cq = &apc->tx_qp[txq_idx].tx_cq;
        tx_stats = &txq->stats;
 
+       BUILD_BUG_ON(MAX_TX_WQE_SGL_ENTRIES != MANA_MAX_TX_WQE_SGL_ENTRIES);
+       if (MAX_SKB_FRAGS + 2 > MAX_TX_WQE_SGL_ENTRIES &&
+           skb_shinfo(skb)->nr_frags + 2 > MAX_TX_WQE_SGL_ENTRIES) {
+               /* GSO skb with Hardware SGE limit exceeded is not expected here
+                * as they are handled in mana_features_check() callback
+                */
+               if (skb_linearize(skb)) {
+                       netdev_warn_once(ndev, "Failed to linearize skb with nr_frags=%d and is_gso=%d\n",
+                                        skb_shinfo(skb)->nr_frags,
+                                        skb_is_gso(skb));
+                       goto tx_drop_count;
+               }
+               apc->eth_stats.tx_linear_pkt_cnt++;
+       }
+
        pkg.tx_oob.s_oob.vcq_num = cq->gdma_id;
        pkg.tx_oob.s_oob.vsq_frame = txq->vsq_frame;
 
@@ -442,8 +458,6 @@ netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev)
                }
        }
 
-       WARN_ON_ONCE(pkg.wqe_req.num_sge > MAX_TX_WQE_SGL_ENTRIES);
-
        if (pkg.wqe_req.num_sge <= ARRAY_SIZE(pkg.sgl_array)) {
                pkg.wqe_req.sgl = pkg.sgl_array;
        } else {
@@ -518,6 +532,25 @@ tx_drop:
        return NETDEV_TX_OK;
 }
 
+#if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES)
+static netdev_features_t mana_features_check(struct sk_buff *skb,
+                                            struct net_device *ndev,
+                                            netdev_features_t features)
+{
+       if (skb_shinfo(skb)->nr_frags + 2 > MAX_TX_WQE_SGL_ENTRIES) {
+               /* Exceeds HW SGE limit.
+                * GSO case:
+                *   Disable GSO so the stack will software-segment the skb
+                *   into smaller skbs that fit the SGE budget.
+                * Non-GSO case:
+                *   The xmit path will attempt skb_linearize() as a fallback.
+                */
+               features &= ~NETIF_F_GSO_MASK;
+       }
+       return features;
+}
+#endif
+
 static void mana_get_stats64(struct net_device *ndev,
                             struct rtnl_link_stats64 *st)
 {
@@ -883,6 +916,9 @@ static const struct net_device_ops mana_devops = {
        .ndo_open               = mana_open,
        .ndo_stop               = mana_close,
        .ndo_select_queue       = mana_select_queue,
+#if (MAX_SKB_FRAGS + 2 > MANA_MAX_TX_WQE_SGL_ENTRIES)
+       .ndo_features_check     = mana_features_check,
+#endif
        .ndo_start_xmit         = mana_start_xmit,
        .ndo_validate_addr      = eth_validate_addr,
        .ndo_get_stats64        = mana_get_stats64,
index 99e8112086833917b5c1e6a2a60b215f76894128..0e2f4343ac67fe6246d9d06eefbb979eeb10cddc 100644 (file)
@@ -18,6 +18,8 @@ static const struct mana_stats_desc mana_eth_stats[] = {
        {"tx_cq_err", offsetof(struct mana_ethtool_stats, tx_cqe_err)},
        {"tx_cqe_unknown_type", offsetof(struct mana_ethtool_stats,
                                        tx_cqe_unknown_type)},
+       {"tx_linear_pkt_cnt", offsetof(struct mana_ethtool_stats,
+                                      tx_linear_pkt_cnt)},
        {"rx_coalesced_err", offsetof(struct mana_ethtool_stats,
                                        rx_coalesced_err)},
        {"rx_cqe_unknown_type", offsetof(struct mana_ethtool_stats,
index 2e4f2f3175e55fcb93640015add8266394701995..a4cf307859f857c45429820be0eb88c505896bed 100644 (file)
@@ -486,6 +486,8 @@ struct gdma_wqe {
 #define INLINE_OOB_SMALL_SIZE 8
 #define INLINE_OOB_LARGE_SIZE 24
 
+#define MANA_MAX_TX_WQE_SGL_ENTRIES 30
+
 #define MAX_TX_WQE_SIZE 512
 #define MAX_RX_WQE_SIZE 256
 
@@ -592,6 +594,9 @@ enum {
 #define GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE BIT(17)
 #define GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE BIT(6)
 
+/* Driver supports linearizing the skb when num_sge exceeds hardware limit */
+#define GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE BIT(20)
+
 /* Driver can send HWC periodically to query stats */
 #define GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY BIT(21)
 
@@ -605,7 +610,8 @@ enum {
         GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \
         GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \
         GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE | \
-        GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY)
+        GDMA_DRV_CAP_FLAG_1_PERIODIC_STATS_QUERY | \
+        GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE)
 
 #define GDMA_DRV_CAP_FLAGS2 0
 
index d37f4cea0ac3e9876d8ad884bac94216d07fc030..fb28b3cac067bc1ffd1e99375cb91bbe7da1009e 100644 (file)
@@ -377,6 +377,7 @@ struct mana_ethtool_stats {
        u64 wake_queue;
        u64 tx_cqe_err;
        u64 tx_cqe_unknown_type;
+       u64 tx_linear_pkt_cnt;
        u64 rx_coalesced_err;
        u64 rx_cqe_unknown_type;
 };