From patchwork Wed Jan 24 08:23:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1890092 X-Patchwork-Delegate: noltari@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=KqOASrAk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=DbbtuzK6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=198.137.202.133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TKcZ44wrVz23dy for ; Wed, 24 Jan 2024 19:29:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Oi5pEoNPL0fsBObPVetf317gktp1Mh+29viu5ljXnFg=; b=KqOASrAkMP4DtH bAxL/C4nSR018Om322TQ/zFaoxaRgvCEF5gOLojBn8/WO1r8Gzoj30gE/I2+uqsDpy359mJPf7Gga GddLMWlrlCaf62Zzap0+wvx+qhs8/28xMIzbHmO3C81JTuPcA+4YIkIJtxH4FBAmsCQF0RJzxQol+ /yJpZDROcEe+I+gFeXqYN5yNv+OdhS20o4NdwhjxGtciEy7s+ykbfwHVkNruI05qdABUnAPB04P6A eStP8NoyuUxVA11F9nr7Hp2eGBOcp1KPtxDjDIUh3v4Cjl8rGrvKSQcL+hG03Ey1Oacmyz1PyLc/p mFLCuarEcpKVyaBVq/Zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSYXX-00205a-21; Wed, 24 Jan 2024 08:23:19 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSYXU-00203r-0Q for openwrt-devel@lists.openwrt.org; Wed, 24 Jan 2024 08:23:18 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-50f1c524010so5694821e87.3 for ; Wed, 24 Jan 2024 00:23:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706084594; x=1706689394; darn=lists.openwrt.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=slIJLT+lb1nrCL+yvpWs4zkLbQl0YB1wRCYYXMbxG40=; b=DbbtuzK6I6OWxu9bKzpDdZF6ZaWBwcNMjBWNfkAiWwLi3j8anNIhtuqkqdyauoHgvR WHb4QoJA2mutOmk0T3YZi9lxxOd4Cio9OTJNdhtFUIBmsLIKzVXhVNzXPgZD/PaxAlyH qzJLV5QPvoL/uoOfdtrFOew1+K0Sx5RhDhLnHKDx6IH8Vt4utkN2rvj5NbYp/VPGZ3/T dQ5v/yBxiMZlDci1MNanZp7kHqhd7vOcoCNJ51HBa43wvzaVA6G5YQ8c/p4RrxgOgu7o lyd4i4jEFP+L1TP2JA/oEmfZkErG1QDIYzvqOOkeyGaNWjrfMXcDfzCGmF8jiGTpy0EA RMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706084594; x=1706689394; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=slIJLT+lb1nrCL+yvpWs4zkLbQl0YB1wRCYYXMbxG40=; b=LhLI8uq49qVlGeHnlBDPiQPOsSRuPt8a3PQCkr66X4T/E3OGxQNO+j+jKs+iu/csal a2o2oJFsLBX7bXfiVS9sPalQryae2BQwtxZ/CeEo6/bh/wAifs8bfknVnYq9w6RVlyDj Petl/5TlHhvNliAauuj7SwI8Mq386AGOWRtjQfQvw8674+/5O6yB0NhW3suZ1EpGwfuz ppl8r7ynsz0Sx0XbR8/KXqlnqC4EgMOJ6t2O6YNWf6FvHYO/WsfAG5n8PuNou09ZKxLR lclR94g8zZ37EfTcVzGdaMkosSevFUjf995PG2yXPzj9IDLCNOL5NIhJzIbULag1cNTI /iWA== X-Gm-Message-State: AOJu0YwErLWcur1P4fpXUMczJmX23auh4Wo27PBWlu6+pJmgMu6Zeqjp oMM+N+EJu5uQtKJ3+onEzPcTFAUXQP2uqUmS2XFRmWL+nPG/7j5BK2kUEtl2jaM= X-Google-Smtp-Source: AGHT+IFyhvw5+WKsKDxYLbxPELxyIZZJNq2vJwSSrN+dXbCP+V0NurXsmCMTaCVLYL5gM6rqGB3drQ== X-Received: by 2002:a05:6512:3f0d:b0:50e:d4fe:7dfe with SMTP id y13-20020a0565123f0d00b0050ed4fe7dfemr1842142lfa.71.1706084593534; Wed, 24 Jan 2024 00:23:13 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id w3-20020ac254a3000000b0051010705343sm102984lfk.1.2024.01.24.00.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 00:23:13 -0800 (PST) From: Linus Walleij Date: Wed, 24 Jan 2024 09:23:12 +0100 Subject: [PATCH v7] bmips: bcm6368-enetsw: Bump max MTU MIME-Version: 1.0 Message-Id: <20240124-bcm6368-mtu-v7-1-694c86d8d435@linaro.org> X-B4-Tracking: v=1; b=H4sIAO/IsGUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyzHUUlJIzE vPSU3UzU4B8JSMDIxMDQyMT3aTkXDNjMwvd3JJS3RTjJCPzlOREw+RECyWgjoKi1LTMCrBp0bG 1tQA0+rIUXQAAAA== To: openwrt-devel@lists.openwrt.org, =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Ro?= =?utf-8?q?jas?= , Jonas Gorski Cc: Paul Donald , Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240124_002316_171521_7CB82E52 X-CRM114-Status: GOOD ( 23.26 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The safe max frame size for this ethernet switch is 1532 bytes, excluding the DSA TAG and extra VLAN header, so the maximum outgoing frame is 1542 bytes. The available overhead is needed when using the DSA switch with a cascaded Marvell DSA switch, which is something that exist in real products, in this case the Inteno XG6846. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:133 listed in] [list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The safe max frame size for this ethernet switch is 1532 bytes, excluding the DSA TAG and extra VLAN header, so the maximum outgoing frame is 1542 bytes. The available overhead is needed when using the DSA switch with a cascaded Marvell DSA switch, which is something that exist in real products, in this case the Inteno XG6846. Use defines at the top of the size for max MTU so it is clear how we think about this, add comments. We need to adjust the RX buffer size to fit the new max frame size, which is 1542 when the DSA tag (6 bytes) and VLAN header (4 extra bytes) is added. We also drop this default MTU: #define ENETSW_TAG_SIZE (6 + VLAN_HLEN) ndev->mtu = ETH_DATA_LEN + ENETSW_TAG_SIZE; in favor of just: ndev->mtu = ETH_DATA_LEN; I don't know why the default MTU is trying to second guess the overhead required by DSA and VLAN but the framework will also try to bump the MTU for e.g. DSA tags, and the VLAN overhead is not supposed to be included in the MTU, so this is clearly not right. Before this patch (on the lan1 DSA port in this case): dsa_slave_change_mtu: master->max_mtu = 9724, dev->max_mtu = 10218, DSA overhead = 8 dsa_slave_change_mtu: master = extsw, dev = lan1 dsa_slave_change_mtu: master->max_mtu = 1510, dev->max_mtu = 9724, DSA overhead = 6 dsa_slave_change_mtu: master = eth0, dev = extsw dsa_slave_change_mtu new_master_mtu 1514 > mtu_limit 1510 mdio_mux-0.1:00: nonfatal error -34 setting MTU to 1500 on port 0 My added debug prints before the nonfatal error: the first switch from the top is the Marvell switch, the second in the bcm6368-enetsw with its 1510 limit. After this patch the error is gone. OpenWrt adds a VLAN to each port so we get VLAN tags on all frames. On this setup we even have 4 more bytes left after the two DSA tags and VLAN so we can go all the way up to 1532 as MTU. Testing the new 1532 MTU: eth0 ext1 enp7s0 .--------. .-----------. cable .------. | enetsw | <-> | mv88e6152 | <-----> | host | `--------´ `-----------´ `------´ On the router we set the max MTU for test: ifconfig eth0 mtu 1520 ifconfig br-wan mtu 1520 ifconfig ext1 mtu 1506 An MTU of 1506 on ext1 is a logic consequence of the above setup: this is the max bytes actually transferred. The framing added will be: - 18 bytes standard ethernet header - 4 bytes VLAN header - 6 bytes DSA tag for enetsw - 8 bytes DSA tag for mv88e6152 Sum: 1506 + 18 + 4 + 6 + 8 = 1542 which is out max frame size. Test pinging from host: ping -s 1478 -M do 192.168.1.220 PING 192.168.1.220 (192.168.1.220) 1478(1506) bytes of data. 1486 bytes from 192.168.1.220: icmp_seq=1 ttl=64 time=0.696 ms 1486 bytes from 192.168.1.220: icmp_seq=2 ttl=64 time=0.615 ms Test pinging from router: PING 192.168.1.2 (192.168.1.2): 1478 data bytes 1486 bytes from 192.168.1.2: seq=0 ttl=64 time=0.931 ms 1486 bytes from 192.168.1.2: seq=1 ttl=64 time=0.810 ms The max IP packet without headers is 1478, the outgoing ICMP packet is 1506 bytes. Then the DSA, VLAN and ethernet overhead is added. Let us verify the contents of the resulting ethernet frame of 1542 bytes. Ping packet on router side as viewed with tcpdump: 00:54:51.900869 AF Unknown (1429722180), length 1538: 0x0000: 3d93 bcae c56b a83d 8874 0300 0004 8100 =....k.=.t...... 0x0010: 0000 dada 0000 c020 0fff 0800 4500 05e2 ............E... 0x0020: 0000 4000 4001 b0ec c0a8 0102 c0a8 01dc ..@.@........... 0x0030: 0800 7628 00c3 0001 f5da 1d65 0000 0000 ..v(.......e.... 0x0040: ce65 0a00 0000 0000 1011 1213 1415 1617 .e.............. 0x0050: 1819 1a1b 1c1d 1e1f 2021 2223 2425 2627 .........!"#$%&' 0x0060: 2829 2a2b 2c2d 2e2f 3031 3233 3435 3637 ()*+,-./0123456 (...) - 3d93 = First four bytes are the last two bytes of the destination ethernet address I don't know why the first four are missing, but it sure explains why the paket is 1538 bytes and not 1542 which is the actual max frame size. - bcae c56b a83b = source ethernet address - 8874 0300 0004 = Broadcom enetsw DSA tag - 8100 0000 = VLAN 802.1Q header - dada 0000 c020 0fff = EDSA tag for the Marvell (outer) switch, - 0800 is the ethertype (part of the EDSA tag technically) - Next follows the contents of the ping packet as it appears if we dump it on the DSA interface such as tcpdump -i lan1 etc, there we get the stripped out packet, 1506 bytes. - At the end 4 bytes of FCS. This clearly illustrates that the DSA tag is included in the MTU which we set up in Linux, but the VLAN tag and ethernet headers and checksum is not. Cc: Álvaro Fernández Rojas Cc: Jonas Gorski Tested-by: Paul Donald Signed-off-by: Linus Walleij --- ChangeLog v6->v7: - Rebase on master. - Perhaps we can merge this now? ChangeLog v5->v6: - Rewrite thoroughly after discussing with Jonas that the safe MTU is probably 1532 without DSA tag and extra VLAN header. - Reword commit message and redo tests so it is crystal clear what is going on, as illustrated by tcpdump. ChangeLog v4->v5: - Drop the confusing ENETSW_MTU_OVERHEAD altogether after discussing with Jonas. ChangeLog v3->v4: - Adjust the RX buffer size and we can use the max "jumbo" frame size 2048. ChangeLog v2->v3: - Make a more believable case for the max MTU with tcpdump example. ChangeLog v1->v2: - Do some better research after help on IRC, did some ping tests. --- .../drivers/net/ethernet/broadcom/bcm6368-enetsw.c | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) --- base-commit: 1b7e62b20b1735fcdc498a35e005afcd775abcf4 change-id: 20240124-bcm6368-mtu-d3b27dca1ca8 Best regards, diff --git a/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c b/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c index 321e95dbbb3d..b72a788378fa 100644 --- a/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c +++ b/target/linux/bmips/files/drivers/net/ethernet/broadcom/bcm6368-enetsw.c @@ -22,10 +22,19 @@ #include #include -/* MTU */ -#define ENETSW_TAG_SIZE (6 + VLAN_HLEN) -#define ENETSW_MTU_OVERHEAD (VLAN_ETH_HLEN + VLAN_HLEN + \ - ENETSW_TAG_SIZE) +/* TODO: Bigger frames may work but we do not trust that they are safe on all + * platforms so more research is needed, a max frame size of 2048 has been + * tested. We use the safe frame size 1542 which is 1532 plus DSA and VLAN + * overhead. + */ +#define ENETSW_MAX_FRAME 1542 +#define ENETSW_DSA_TAG_SIZE 6 +/* The MTU in Linux does not include ethernet or VLAN headers, but it DOES + * include the DSA overhead (the framework will increase the MTU to fit + * any DSA header). + */ +#define ENETSW_MAX_MTU (ENETSW_MAX_FRAME - VLAN_ETH_HLEN - \ + VLAN_HLEN) #define ENETSW_FRAG_SIZE(x) (SKB_DATA_ALIGN(NET_SKB_PAD + x + \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))) @@ -1006,7 +1015,7 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev) dev_info(dev, "random mac\n"); } - priv->rx_buf_size = ALIGN(ndev->mtu + ENETSW_MTU_OVERHEAD, + priv->rx_buf_size = ALIGN(ENETSW_MAX_FRAME, ENETSW_DMA_MAXBURST * 4); priv->rx_frag_size = ENETSW_FRAG_SIZE(priv->rx_buf_size); @@ -1066,8 +1075,8 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev) /* register netdevice */ ndev->netdev_ops = &bcm6368_enetsw_ops; ndev->min_mtu = ETH_ZLEN; - ndev->mtu = ETH_DATA_LEN + ENETSW_TAG_SIZE; - ndev->max_mtu = ETH_DATA_LEN + ENETSW_TAG_SIZE; + ndev->mtu = ETH_DATA_LEN; + ndev->max_mtu = ENETSW_MAX_MTU; #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0) netif_napi_add(ndev, &priv->napi, bcm6368_enetsw_poll); #else