]> www.infradead.org Git - users/willy/linux.git/commitdiff
net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size
authorJijie Shao <shaojijie@huawei.com>
Fri, 15 Aug 2025 10:04:13 +0000 (18:04 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 Aug 2025 01:11:15 +0000 (18:11 -0700)
Since the driver always enables tx bounce buffer,
there are minimum values for `copybreak` and `tx_spare_buf_size`.

This patch will check and reject configurations
with values smaller than these minimums.

Closes: https://lore.kernel.org/all/20250723072900.GV2459@horms.kernel.org/
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
Link: https://patch.msgid.link/20250815100414.949752-2-shaojijie@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

index d5454e126c856cf07cfc9e033547283becb739af..a752d0e3db3a73539d94255a261519eee7d4cc3d 100644 (file)
@@ -1927,6 +1927,31 @@ static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
        return ret;
 }
 
+static int hns3_check_tx_copybreak(struct net_device *netdev, u32 copybreak)
+{
+       struct hns3_nic_priv *priv = netdev_priv(netdev);
+
+       if (copybreak < priv->min_tx_copybreak) {
+               netdev_err(netdev, "tx copybreak %u should be no less than %u!\n",
+                          copybreak, priv->min_tx_copybreak);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int hns3_check_tx_spare_buf_size(struct net_device *netdev, u32 buf_size)
+{
+       struct hns3_nic_priv *priv = netdev_priv(netdev);
+
+       if (buf_size < priv->min_tx_spare_buf_size) {
+               netdev_err(netdev,
+                          "tx spare buf size %u should be no less than %u!\n",
+                          buf_size, priv->min_tx_spare_buf_size);
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static int hns3_set_tunable(struct net_device *netdev,
                            const struct ethtool_tunable *tuna,
                            const void *data)
@@ -1943,6 +1968,10 @@ static int hns3_set_tunable(struct net_device *netdev,
 
        switch (tuna->id) {
        case ETHTOOL_TX_COPYBREAK:
+               ret = hns3_check_tx_copybreak(netdev, *(u32 *)data);
+               if (ret)
+                       return ret;
+
                priv->tx_copybreak = *(u32 *)data;
 
                for (i = 0; i < h->kinfo.num_tqps; i++)
@@ -1957,6 +1986,10 @@ static int hns3_set_tunable(struct net_device *netdev,
 
                break;
        case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
+               ret = hns3_check_tx_spare_buf_size(netdev, *(u32 *)data);
+               if (ret)
+                       return ret;
+
                old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
                new_tx_spare_buf_size = *(u32 *)data;
                netdev_info(netdev, "request to set tx spare buf size from %u to %u\n",