From patchwork Thu Jun 13 02:38:08 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: 13695975 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 EC44EC27C6E for ; Thu, 13 Jun 2024 02:39:18 +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=FgbGeC4i3nOuWMYoPUlXHb+7fSmu0PqN2K8q/uuqHSs=; b=dYfLmOTDbDhOulsRgEKAhaTJWA nDa56qaTPlR2RiJhMQY5QeCO6JrR3hbY4zN4UyInt3hhHjBRiFkvb2cqwJIZEHCMRwv4PqAmmk7o0 WCz2bdhYei1AgfA2Yx7H67hUSBPRca5ls25I/+D1Xe8oolUFUqvghWwAqz1V9Y7GA7ZQ469cpBhgW iOJvznuvq+7lUs1JxqqA98bxt+lXhQ8Q7S3IkM2pvUtLlRIxbBWHl8zsvg67l8n3qFSMN9rDF8Wx5 vNjhRaCmZv+K9Bfjwi+qpTU3XlmXXNBGURJ6nj1gYt/ykvrltr4KJc/Sy6zNAL6Kk26003S8/hEe4 svoNxfFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHaMl-0000000EsVL-2VYm; Thu, 13 Jun 2024 02:39:07 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHaMg-0000000EsUm-2NqC for linux-arm-kernel@lists.infradead.org; Thu, 13 Jun 2024 02:39:04 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6f97b836c42so293925a34.1 for ; Wed, 12 Jun 2024 19:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718246339; x=1718851139; 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=FgbGeC4i3nOuWMYoPUlXHb+7fSmu0PqN2K8q/uuqHSs=; b=AKUNKkAVaP0udAK+T0XiXZA0lJs+AxCF2EfJhZHSQlzplsEBmds4OAfnkx3DI7Vqyi wY/GuPEhSuFJIh+tU2WWlj1jqp8+9KTuMfCDODGKeImuIwyAWInIWaIXGo20pP+wWEUB fI9q3hcC+Gv1f9Y4VrBV/gCaKpi97S+j2BnyU0h5jTCrU2hU7qHR5Pc/epxp4djlR99U MCzSBbgFs0FNpA97Wg0axYS9S1V8Be5apEL8XkIhyONWtgmnvfzxnKJ/JSK25/qjByQy i1Dy5i/jVFomeEq6/KOYq6RfZXDfHm5Bl0NmHgWAAOHbK3zbU8IFprwVkyMlTFA20G9M r8Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718246339; x=1718851139; 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=FgbGeC4i3nOuWMYoPUlXHb+7fSmu0PqN2K8q/uuqHSs=; b=Ya996QqfXWsDSS3opVA2nCh4cHBBo1OE57+4KLuDNsnI3i0S1WT8e+P2taLERK2V6e mZ+JkmZ7v8q8Xe6msesWKvT+Iw85CiEyB/YTN+owR8pKNZ/0kOJMf0HJl/efPl2grke/ +vap69Jw6y2uKFRlURRPh5kJWXQf/ZdyE4+eIsqlimBtt4ItjrRloitO1lBCY5XnZgQQ HnLW7AYNN18s4HRMoQ0OtmMHd8d302TNMN+6FUBcxTqG3onsDXR9eREXwLTylTN/FThT /76lGyTQL08nXez2rKr9UJakvFRthY1khCeig+bhUX2C1eK0VxbdQLdnPxKLtpObBSBa VHSQ== X-Forwarded-Encrypted: i=1; AJvYcCX3KgYvsx6FJyzdS5fJzEgaM/eLluVnmU+gIpEGJYIGVMpwKoWmPhE3qz7NLJUbBI4WanCHL60LQMIRUr3AzIjclUzAjQI2scr9IHmx0OfjbfIBcME= X-Gm-Message-State: AOJu0YziXSX371fGLDExDsP48FDYUXiVpxKSuYWFILsFIbNa5VdgQQcF s7XQOhlctypgeAR3pkp5YIuBR7eugE/TWPSHnz6pcZ2szfO0qV5V X-Google-Smtp-Source: AGHT+IGNr5kdsBRA2T5pp3GrUSQlJ23/IcNXqRpmruBsCoKYpEqhh2PB3TfnlgZj0Ys2t9iz3+YC0w== X-Received: by 2002:a05:6830:264a:b0:6f9:944a:254f with SMTP id 46e09a7af769-6fa1b942179mr4011182a34.0.1718246339340; Wed, 12 Jun 2024 19:38:59 -0700 (PDT) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-6fee2d36622sm177556a12.60.2024.06.12.19.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 19:38:58 -0700 (PDT) From: Furong Xu <0x1207@gmail.com> To: "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 v1] net: stmmac: Enable TSO on VLANs Date: Thu, 13 Jun 2024 10:38:08 +0800 Message-Id: <20240613023808.448495-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-20240612_193902_636530_08EDB645 X-CRM114-Status: GOOD ( 14.66 ) 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> --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bbedf2a8c60f..d2d09edf5476 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4239,16 +4239,32 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) struct stmmac_txq_stats *txq_stats; int tmp_pay_len = 0, first_tx; struct stmmac_tx_queue *tx_q; - bool has_vlan, set_ic; + bool set_ic; u8 proto_hdr_len, hdr; u32 pay_len, mss; dma_addr_t des; int i; + struct vlan_ethhdr *veth; tx_q = &priv->dma_conf.tx_queue[queue]; txq_stats = &priv->xstats.txq_stats[queue]; first_tx = tx_q->cur_tx; + if (skb_vlan_tag_present(skb)) { + /* 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. + */ + skb_push(skb, VLAN_HLEN); + memmove(skb->data, skb->data + VLAN_HLEN, ETH_ALEN * 2); + + veth = skb_vlan_eth_hdr(skb); + veth->h_vlan_proto = skb->vlan_proto; + veth->h_vlan_TCI = htons(skb_vlan_tag_get(skb)); + __vlan_hwaccel_clear_tag(skb); + } + /* Compute header lengths */ if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) { proto_hdr_len = skb_transport_offset(skb) + sizeof(struct udphdr); @@ -4297,9 +4313,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 +4322,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 +7688,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;