From patchwork Fri Jun 14 07:02:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13697948 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C91B3C27C6E for ; Fri, 14 Jun 2024 07:02:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=By4P0vcgLroOQCJskwfGLQoINqqC43myu7beQ18KDt0=; b=xQCSWq2MWkbk66jxeuuJJLtQac eYySfXcFIXKM8rkXFUuButir9OAx24Zb1fA81LrVQwyoP54T1O3iQMAmwGYfevNKljlt7sNYeZwdA OudRBg/DeyP41pU43eDhQzbed3TJrpBaobZCdURPOHhemsZm6TPhSdSrQLiKSLh7m6dtZK7nwR5iZ z2TN9nOj8CBGhATDk3uILi1oYFJ6ybC63IwnM8QtYL9PDme4+8vgN46W+mUDNgRzA2+pgdMwKS6SI /R097r8zoJvZ/RCp6eef/f+5wwiw+EFDRBTmX8PlMDkk13nzWgdqncjq2pRVrq8o1Cf1KwjPQ9A6O 6D00jCeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI0xN-00000001hPz-0Vkt; Fri, 14 Jun 2024 07:02:41 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI0xJ-00000001hPW-0lL1 for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 07:02:38 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3d23a0a32afso1010530b6e.3 for ; Fri, 14 Jun 2024 00:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718348556; x=1718953356; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=By4P0vcgLroOQCJskwfGLQoINqqC43myu7beQ18KDt0=; b=F0I30jiZoydF4Z6nDsnAxBW++IZSjHlWswdXdd+WzF7rOqPCqu1a+93L/RL7YfPNa+ NuNTBLoi1UHzQmzgZT0cYhv4DE2g1+l5r2MMjtG2clQQ7ykOFtJrvqsAPsLTR8L/pHfz MdAoKY5HIlNYHS0kcIiBdOe9cNEkFagBfersgTIM9a73E8pSlq2hat1IyZY9xxP25SEJ zX8CYZ5wEn0ztMnGae3Wvfk7PXs4+TwQ9Fp35CEvhhx9rROXJCd7LGW4LMMrIEjZnx4p UidncANGKSoqPoLiaYNd0r7/ddsUXKXdUK2T0A9oV/3zrPMRaCFEFPG30fXmhbRxFAW3 qz7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718348556; x=1718953356; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=By4P0vcgLroOQCJskwfGLQoINqqC43myu7beQ18KDt0=; b=xCFvfB79KHd06IjjDT6NAHIRn8zCNSSXsRV4kfvw2N8bvFbbNkUNFlYXghpKiqvCFe 6n3Bzx+6su7IePlK9AzhvmV9mXiJk1Vv+/vWNbUwa2rWKj9o9M/GlOXJB4hSv6+z6ZqT EFyiRZOpUR4HCQPOM+7giXnYKhi6NStXPRZ9nocbdG+Xp+7E3abay3unIQXdBpPmjGiE cYsW8tYfrfSbXsyRuUBC5QjLhDDwf/dD/qofLYouOST+hkErP9PN3dGbujL1rlx2uZDh slAQORZEyDBsqq1v9LbDwTV0MpLhx0nqkswAMGNy8MqWQyI+axxjTn0QDuYZRGk0oAUq ahcw== X-Forwarded-Encrypted: i=1; AJvYcCUCopSy3sDtZGpgOGhvbDsLYfNHXpT5WsWXpAC8Tl3hy33bFb8kF3Gr9ZRATSj6zLgQEuytxala1EwvhVT1UeFc6dByp2We/zjG2QMgE6PoqN/lZ1w= X-Gm-Message-State: AOJu0Yxvkr2RMUmjFcM4Kd/OqCCDVuYJwKJnHAxXCqocC39FoqK34X7y zcCEMUU4o768nU+QBqfjSABLC0nThFxrN4FzlF+PazIIkgMruU2h X-Google-Smtp-Source: AGHT+IFIcoEGF1ujGsaAknACmdVAzRUo/ikVN155rUrAwKruOrjOfcAV7bcoaC10WeY7S6jOQeHj6w== X-Received: by 2002:a05:6358:7184:b0:19f:5631:97cd with SMTP id e5c5f4694b2df-19fa9e5c312mr252970455d.15.1718348555911; Fri, 14 Jun 2024 00:02:35 -0700 (PDT) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6fede354612sm2072893a12.35.2024.06.14.00.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 00:02:35 -0700 (PDT) From: Furong Xu <0x1207@gmail.com> To: "Russell King (Oracle)" , Eric Dumazet , "David S. Miller" , Alexandre Torgue , Jose Abreu , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Joao Pinto , Corinna Vinschen Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, xfr@outlook.com, rock.xu@nio.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v3] net: stmmac: Enable TSO on VLANs Date: Fri, 14 Jun 2024 15:02:06 +0800 Message-Id: <20240614070206.506999-1-0x1207@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_000237_245666_3FAF7C38 X-CRM114-Status: GOOD ( 16.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The TSO engine works well when the frames are not VLAN Tagged. But it will produce broken segments when frames are VLAN Tagged. The first segment is all good, while the second segment to the last segment are broken, they lack of required VLAN tag. An example here: ======== // 1st segment of a VLAN Tagged TSO frame, nothing wrong. MacSrc > MacDst, ethertype 802.1Q (0x8100), length 1518: vlan 100, p 1, ethertype IPv4 (0x0800), HostA:42643 > HostB:5201: Flags [.], seq 1:1449 // 2nd to last segments of a VLAN Tagged TSO frame, VLAN tag is missing. MacSrc > MacDst, ethertype IPv4 (0x0800), length 1514: HostA:42643 > HostB:5201: Flags [.], seq 1449:2897 MacSrc > MacDst, ethertype IPv4 (0x0800), length 1514: HostA:42643 > HostB:5201: Flags [.], seq 2897:4345 MacSrc > MacDst, ethertype IPv4 (0x0800), length 1514: HostA:42643 > HostB:5201: Flags [.], seq 4345:5793 MacSrc > MacDst, ethertype IPv4 (0x0800), length 1514: HostA:42643 > HostB:5201: Flags [P.], seq 5793:7241 // normal VLAN Tagged non-TSO frame, nothing wrong. MacSrc > MacDst, ethertype 802.1Q (0x8100), length 1022: vlan 100, p 1, ethertype IPv4 (0x0800), HostA:42643 > HostB:5201: Flags [P.], seq 7241:8193 MacSrc > MacDst, ethertype 802.1Q (0x8100), length 70: vlan 100, p 1, ethertype IPv4 (0x0800), HostA:42643 > HostB:5201: Flags [F.], seq 8193 ======== When transmitting VLAN Tagged TSO frames, never insert VLAN tag by HW, always insert VLAN tag to SKB payload, then TSO works well on VLANs for all MAC cores. Tested on DWMAC CORE 5.10a, DWMAC CORE 5.20a and DWXGMAC CORE 3.20a Signed-off-by: Furong Xu <0x1207@gmail.com> --- Changes in v3: - Drop packet and increase stats counter when vlan tag insert fails. Changes in v2: - Use __vlan_hwaccel_push_inside() to insert vlan tag to the payload. --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bbedf2a8c60f..87aa3528cc0c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4233,18 +4233,32 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) { struct dma_desc *desc, *first, *mss_desc = NULL; struct stmmac_priv *priv = netdev_priv(dev); - int nfrags = skb_shinfo(skb)->nr_frags; - u32 queue = skb_get_queue_mapping(skb); unsigned int first_entry, tx_packets; struct stmmac_txq_stats *txq_stats; - int tmp_pay_len = 0, first_tx; + int tmp_pay_len = 0, first_tx, nfrags; struct stmmac_tx_queue *tx_q; - bool has_vlan, set_ic; + bool set_ic; u8 proto_hdr_len, hdr; - u32 pay_len, mss; + u32 pay_len, mss, queue; dma_addr_t des; int i; + /* Always insert VLAN tag to SKB payload for TSO frames. + * + * Never insert VLAN tag by HW, since segments splited by + * TSO engine will be un-tagged by mistake. + */ + if (skb_vlan_tag_present(skb)) { + skb = __vlan_hwaccel_push_inside(skb); + if (unlikely(!skb)) { + priv->xstats.tx_dropped++; + return NETDEV_TX_OK; + } + } + + nfrags = skb_shinfo(skb)->nr_frags; + queue = skb_get_queue_mapping(skb); + tx_q = &priv->dma_conf.tx_queue[queue]; txq_stats = &priv->xstats.txq_stats[queue]; first_tx = tx_q->cur_tx; @@ -4297,9 +4311,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) skb->data_len); } - /* Check if VLAN can be inserted by HW */ - has_vlan = stmmac_vlan_insert(priv, skb, tx_q); - first_entry = tx_q->cur_tx; WARN_ON(tx_q->tx_skbuff[first_entry]); @@ -4309,9 +4320,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) desc = &tx_q->dma_tx[first_entry]; first = desc; - if (has_vlan) - stmmac_set_desc_vlan(priv, first, STMMAC_VLAN_INSERT); - /* first descriptor: fill Headers on Buf1 */ des = dma_map_single(priv->device, skb->data, skb_headlen(skb), DMA_TO_DEVICE); @@ -7678,8 +7686,6 @@ int stmmac_dvr_probe(struct device *device, ndev->features |= NETIF_F_RXHASH; ndev->vlan_features |= ndev->features; - /* TSO doesn't work on VLANs yet */ - ndev->vlan_features &= ~NETIF_F_TSO; /* MTU range: 46 - hw-specific max */ ndev->min_mtu = ETH_ZLEN - ETH_HLEN;