Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6892962rwl; Thu, 29 Dec 2022 23:36:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXtBY4Pbc9u74lkQSuyB12Has/+AlgRQFY6gZuklAFGXDpSfjKP09FDL2Pi/MoKIfFwt8sR8 X-Received: by 2002:aa7:c505:0:b0:47f:2419:336c with SMTP id o5-20020aa7c505000000b0047f2419336cmr25658411edq.25.1672385766173; Thu, 29 Dec 2022 23:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672385766; cv=none; d=google.com; s=arc-20160816; b=xNY1MAvEfKAFBjHWE0VsSEVt5vO0QXECAzB361f8HqV5DcXR2gEbZIvtG8zCkDH8jO AFcy8foGjrodry+UMBdhsVvzWB3wIZZ7bIQDseSNnT+k/x05XsxJmQ/sFDneBI5hL14N 3FO/aR6mzGzK0Etaovzd+YKjYWgMq6JsZsdUCvwng+kcXOp3xXNmoCG38p3zRRknSOAO DVA5+lMs/LpiqLw5A64RNaiAc31CU3aeZpMW0+x+zQKVojK7Fzuvq24h0ABqrSYa6DHz s2Fsn+kim9J1QesTOmHd0nl1EfLV6F/4j7CzsYocv0g3cyFjDT5UImllc7CrcQisami/ X0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BvOC66n7pZ2pEcN9qIrVWxECjhBPJGMGgZTSuErZAzs=; b=UPkYSCFqfQ8BN6JygNAQOe6UqiW1C9gsciB5rDbBlFgU2bKUHSHtw+tcM137EBzmLE ojB3TM+z72gOrpHrbYiNT+993oLWe+HfgCuKzgbw/ok/9RWe9hnpTrkiVFQ8BcU9WY1X VrR9Et7qr01KqegyA8rfRTEu9FU0Avp5lVTlfroljUn7cXlXfwhZmQUgKOdhy0pXHriE McZsX0NPogvawD6yDTKds48B0U8XqKCX7XOqhxAYTl/XeeFlvLow5t5ZxoghSvADIDwH FnjnswAR4LL9pHqLL28IUMk8TpaWG6hsR0HZFtu/qmgaOJy9Ell/uWOqnYTou0xvuPB3 ukEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=ftSUJwEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a056402036c00b004697dff9638si15804973edw.87.2022.12.29.23.35.51; Thu, 29 Dec 2022 23:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=ftSUJwEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234721AbiL3HcW (ORCPT + 64 others); Fri, 30 Dec 2022 02:32:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234648AbiL3HcH (ORCPT ); Fri, 30 Dec 2022 02:32:07 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379D6DE8D; Thu, 29 Dec 2022 23:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BvOC66n7pZ2pEcN9qIrVWxECjhBPJGMGgZTSuErZAzs=; b=ftSUJwElGo3Wc9UoKBU0nRZ+db 0CaCTeNwJN80mG+3lMtznUWbViysyQSQUkbcjNt+c3RgzliAxJETVMwV/p2lMFGCfDcErMOfFz9T9 lerBxsxsfWhMTZfAB84jxEq0WIEshZu5ywgF+oEOdf8qmKdDtX5W1quRA1oJUY/hti2Y=; Received: from p200300daa720fc00fd7bb9014adaf597.dip0.t-ipconnect.de ([2003:da:a720:fc00:fd7b:b901:4ada:f597] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pB9rn-00CcyM-4V; Fri, 30 Dec 2022 08:31:47 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger Cc: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v3 2/5] net: ethernet: mtk_eth_soc: work around issue with sending small fragments Date: Fri, 30 Dec 2022 08:31:42 +0100 Message-Id: <20221230073145.53386-2-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230073145.53386-1-nbd@nbd.name> References: <20221230073145.53386-1-nbd@nbd.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When lots of frames are sent with a number of very small fragments, an internal FIFO can overflow, causing the DMA engine to lock up lock up and transmit attempts time out. Fix this on MT7986 by increasing the reserved FIFO space. Fix this on older chips by detecting the presence of small fragments and use skb_gso_segment + skb_linearize to deal with them. Signed-off-by: Felix Fietkau --- v2: add proper fix for MT7986, limit workaround to NETSYS v1 v3: fix a regression on mt7986 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 38 +++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index e3de9a53b2d9..04b75c7ad5b0 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1441,12 +1441,28 @@ static void mtk_wake_queue(struct mtk_eth *eth) } } +static bool mtk_skb_has_small_frag(struct sk_buff *skb) +{ + int min_size = 16; + int i; + + if (skb_headlen(skb) < min_size) + return true; + + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size) + return true; + + return false; +} + static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct mtk_mac *mac = netdev_priv(dev); struct mtk_eth *eth = mac->hw; struct mtk_tx_ring *ring = ð->tx_ring; struct net_device_stats *stats = &dev->stats; + struct sk_buff *segs, *next; bool gso = false; int tx_num; @@ -1468,6 +1484,18 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_BUSY; } + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) && + skb_is_gso(skb) && mtk_skb_has_small_frag(skb)) { + segs = skb_gso_segment(skb, dev->features & ~NETIF_F_ALL_TSO); + if (IS_ERR(segs)) + goto drop; + + if (segs) { + consume_skb(skb); + skb = segs; + } + } + /* TSO: fill MSS info in tcp checksum field */ if (skb_is_gso(skb)) { if (skb_cow_head(skb, 0)) { @@ -1483,8 +1511,14 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) } } - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) - goto drop; + skb_list_walk_safe(skb, skb, next) { + if ((!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) && + mtk_skb_has_small_frag(skb) && skb_linearize(skb)) || + mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) { + stats->tx_dropped++; + dev_kfree_skb_any(skb); + } + } if (unlikely(atomic_read(&ring->free_count) <= ring->thresh)) netif_tx_stop_all_queues(dev); diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 877cee9bcc66..420a7d412f24 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -247,7 +247,7 @@ #define MTK_CHK_DDONE_EN BIT(28) #define MTK_DMAD_WR_WDONE BIT(26) #define MTK_WCOMP_EN BIT(24) -#define MTK_RESV_BUF (0x40 << 16) +#define MTK_RESV_BUF (0x80 << 16) #define MTK_MUTLI_CNT (0x4 << 12) #define MTK_LEAKY_BUCKET_EN BIT(11) -- 2.38.1