From patchwork Fri Jun 14 06:03:49 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: 13697889 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 EC0B7C27C6E for ; Fri, 14 Jun 2024 06:05:05 +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=2lo12y0h1JrbPiWnZp57B9V/XXZzRLcsfqmffBDHVNA=; b=gIwaYtgZqk1FVpwdlurUahm+Fx xeME5H8bCvkirLbqlbxFNf3D8gKtX5NP3p0zaHxTXKvXY1v+6qLfZoTiQpDwhJ5e/cAKSm5YdY9B6 joEueRuwpULnZUL2dalc4ybsgy0p1VHV2KvS3Z3HTNMg5iunczV8M0T8WUqlM6Ieuro6EJ7MzAR8P lAF0bu1/8zV5ZBIjIHSEea44C5cybjvHD4StsczT3eHvwSQztifMAv4U7TXnsBsY26RNuMpJcg+aU AhN5ZUwrlCOM2vFz8zvqX/7ua4l4DZhLLdaVR+aUp08Y7AUUWUL3XXk0G1j4T/NmMd0BdG9l0GA3O 40otP3tA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI03S-00000001ZlH-3jqw; Fri, 14 Jun 2024 06:04:54 +0000 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI03Q-00000001Zks-24jO for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 06:04:54 +0000 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-254e42df409so1022618fac.0 for ; Thu, 13 Jun 2024 23:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718345091; x=1718949891; 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=2lo12y0h1JrbPiWnZp57B9V/XXZzRLcsfqmffBDHVNA=; b=Rb4dMUgMjxrejWN29AJF/zggnAiZ4Ar5jKItZ3U8Ijt3IjkjfsZaeaUXiYi+e1Whlh aU7AExwmwc2AHMs3qg6DRkKEWbjqrad8U8lrRJfq4WzH0lg385HxEnxcDLp7h/qdcywl xZrFsx5oW90UvRrgE/viLTQLTUWhDK7Eh9NKpDng6PmCsBDSyv+/NnS4I9BFhdIp6iOe 7BZpN5SkGKvXpR+eDF2S57pAbTBYP3fD6hQChEGe1P3VfQKYCTnr4GYZd5KLwcJU1gsr lZkI3xm369nZUHR9HG3skKHyTKBScLwTWjE+Gai5pmjoUbmF+wgL4joHUpUTJNF99DL4 jIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718345091; x=1718949891; 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=2lo12y0h1JrbPiWnZp57B9V/XXZzRLcsfqmffBDHVNA=; b=TG9/qrHBXL2gredXrbrcv3kR1YTK8au3nyWya6KP9x8GLHAdyzwMbHLEbk65aoxS+4 9KTYEZ75yQtaCfX5rA/nTbTASIifqA07TwVlxM/W93/zdmSNNGrrZTdwKegsXVxfwa+B y+1dI6r9r6+LdfyD6rN8UVGEVLfqA3RbVCvrMiEUNoQx3ZYduRm61qXAdwHBGMhzkq8D VHLy3G/G8cTgaCkMVisK95FgsMNk4qbbX/vLz0pUbVNtMCWTJcBvEj7S5adm3vu4A0Xx +7oJKk7L/tWDGbEuW2VhZW25cH1b59V2kD2sCsbBKSMc4qDWkB+nA+j0RKMVj9SbRA6S JPpQ== X-Forwarded-Encrypted: i=1; AJvYcCUZ59LuAzBV2oyCFqdzd9j9fSRR/yoTXfl0YZf5dKPSDGOBfOEhMfg/krsOlraB3QRwYTCgqOpuOt0r2HdStt6pxKLE5CAzGMmGkUPaWdaROQpMjbA= X-Gm-Message-State: AOJu0YzhLmNeLZewB9Jn1GRbP7LGXN8EelavNT450k/OFHqp3QkcXpZa CxLFA2Yuw7cQ2S6eg7UfXQ+IP9RVwsxrtC8I3upZWgu4lt8ZI2IJ X-Google-Smtp-Source: AGHT+IHd6Af/QURKSaUQ0MKuVRMqC3GMrW5NEG8Y0fvRhKF5F4mHn374tTiHmP39jrSgym0Wc2WhmQ== X-Received: by 2002:a05:6870:2251:b0:258:456f:2f91 with SMTP id 586e51a60fabf-258456f3325mr1445965fac.4.1718345091473; Thu, 13 Jun 2024 23:04:51 -0700 (PDT) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6fee2d36622sm1969337a12.60.2024.06.13.23.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 23:04:50 -0700 (PDT) From: Furong Xu <0x1207@gmail.com> To: "Russell King (Oracle)" , "David S. Miller" , Alexandre Torgue , Jose Abreu , Eric Dumazet , 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 v2] net: stmmac: Enable TSO on VLANs Date: Fri, 14 Jun 2024 14:03:49 +0800 Message-Id: <20240614060349.498414-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-20240613_230452_564961_FE9C481A X-CRM114-Status: GOOD ( 15.58 ) 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 v2: - Use __vlan_hwaccel_push_inside() to insert vlan tag to the payload. --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 27 ++++++++++--------- 1 file changed, 14 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..e8cbfada63ca 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4233,18 +4233,27 @@ 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); + + 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 +4306,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 +4315,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 +7681,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;