From patchwork Sat Nov 4 12:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13445506 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AEDC17737 for ; Sat, 4 Nov 2023 12:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bckd4k8Z" Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97210D60 for ; Sat, 4 Nov 2023 05:43:52 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-507be298d2aso3756197e87.1 for ; Sat, 04 Nov 2023 05:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699101830; x=1699706630; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9Oy6YnzrrQAU74UB/BgNy8fxjGeu1ULALolZntz7GpU=; b=bckd4k8ZwZWtVNFCjzqnJOHxFhsIXC9HPD4IS9cTYlU2EfXQ1/xY9lVF7Sm8ETRbUE g0qf51je+M0H0FQOHqDKssCUjTzO7tRiPw2ZH8V/tMrx5aclgws3a9sTdxUrd01ovi4F 21ijAT8ibZTaICo9vCVDGlAUoUwY9lpdmZSXKny6kg8oJcw9y6+Mnv3/9P9kAs4LTle1 JSQxndFOWQm5R7LwlerhD+4+l+pZv0kW3zUehWUBnITPUWsgmO6q5iMK5igaSNKUjOv7 315CGLHSqXGfxn3Mg0bjgP426dla0lKEFj/wKNN9YcWmmIebPyT8G8GC2IlIqtOsz98N 28DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699101830; x=1699706630; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Oy6YnzrrQAU74UB/BgNy8fxjGeu1ULALolZntz7GpU=; b=t4WmVhQre9yrTmqwnNVkMCnsGTkKQPM5ek07u6sqPrlBKToHLWw9Lf75zJUW0SBO6y wsE8D+ygxqd82ucp3jxdevoRR4PKmqT8PdwQsy6fZVbq3EwQC2j5oZfj9kOZP9m9DxEX AiaglDMT8DSsiSBT2SuvvSErzDGKbUcfBr7vbuouplSX7xesXlDJbBmVo2d1r6oKN8BM 0+bQrcleWeYpk2TeuoWZrMVFoNGj9BdYO3N9QadJdr/sptdbC7ZjYbJSF7rJ5c7ll7xh 4kCuF3MpcCjChMl+oPLXFc4nnivKEIj1U4IZ0bbDo7o+MEByXPVIfw5lEY4xcfxkHm2D 4jXQ== X-Gm-Message-State: AOJu0YyrmFKd+YtUIjtDwB1q7Lzcjsf9QzWVTTc/Sowh0QUEUZYYaZBY 8126SHP5BI/OtZUP2MlKkNGdCA== X-Google-Smtp-Source: AGHT+IGwsd6bMa0WdkB0xdWasEvDnIiyZd8prwFEb7gsYRpi9uYQ0Z3rXATmveYQoxaGQ3DQcung8A== X-Received: by 2002:a19:f80e:0:b0:500:7f71:e46b with SMTP id a14-20020a19f80e000000b005007f71e46bmr18641913lff.1.1699101830741; Sat, 04 Nov 2023 05:43:50 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id u22-20020ac24c36000000b005093312f66fsm496100lfq.124.2023.11.04.05.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:43:50 -0700 (PDT) From: Linus Walleij Date: Sat, 04 Nov 2023 13:43:48 +0100 Subject: [PATCH net 1/4] net: ethernet: cortina: Fix MTU max setting Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231104-gemini-largeframe-fix-v1-1-9c5513f22f33@linaro.org> References: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> In-Reply-To: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org The RX max frame size is over 10000 for the Gemini ethernet, but the TX max frame size is actually just 2047 (0x7ff after checking the datasheet). Reflect this in what we offer to Linux, cap the MTU at the TX max frame minus ethernet headers. Use the BIT() macro for related bit flags so these TX settings are consistent. Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 12 +++++++++--- drivers/net/ethernet/cortina/gemini.h | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 5423fe26b4ef..e12d14359133 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1151,6 +1151,11 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, if (skb->protocol == htons(ETH_P_8021Q)) mtu += VLAN_HLEN; + if (mtu > MTU_SIZE_BIT_MASK) { + netdev_err(netdev, "%s: MTU too big, max size 2047 bytes, capped\n", __func__); + mtu = MTU_SIZE_BIT_MASK; + } + word1 = skb->len; word3 = SOF_BIT; @@ -2464,11 +2469,12 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev) netdev->hw_features = GMAC_OFFLOAD_FEATURES; netdev->features |= GMAC_OFFLOAD_FEATURES | NETIF_F_GRO; - /* We can handle jumbo frames up to 10236 bytes so, let's accept - * payloads of 10236 bytes minus VLAN and ethernet header + /* We can receive jumbo frames up to 10236 bytes but only + * transmit 2047 bytes so, let's accept payloads of 2047 + * bytes minus VLAN and ethernet header */ netdev->min_mtu = ETH_MIN_MTU; - netdev->max_mtu = 10236 - VLAN_ETH_HLEN; + netdev->max_mtu = MTU_SIZE_BIT_MASK - VLAN_ETH_HLEN; port->freeq_refill = 0; netif_napi_add(netdev, &port->napi, gmac_napi_poll); diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h index 9fdf77d5eb37..d7101bfcb4a0 100644 --- a/drivers/net/ethernet/cortina/gemini.h +++ b/drivers/net/ethernet/cortina/gemini.h @@ -499,10 +499,10 @@ union gmac_txdesc_3 { }; #define SOF_EOF_BIT_MASK 0x3fffffff -#define SOF_BIT 0x80000000 -#define EOF_BIT 0x40000000 -#define EOFIE_BIT BIT(29) -#define MTU_SIZE_BIT_MASK 0x1fff +#define SOF_BIT BIT(31) /* Start of Frame */ +#define EOF_BIT BIT(30) /* End of Frame */ +#define EOFIE_BIT BIT(29) /* End of Frame Interrupt Enable */ +#define MTU_SIZE_BIT_MASK 0x7ff /* Max MTU 2047 bytes */ /* GMAC Tx Descriptor */ struct gmac_txdesc { From patchwork Sat Nov 4 12:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13445507 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FE4918022 for ; Sat, 4 Nov 2023 12:43:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fzaz3lDG" Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 909C1194 for ; Sat, 4 Nov 2023 05:43:53 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-507a62d4788so3892608e87.0 for ; Sat, 04 Nov 2023 05:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699101832; x=1699706632; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QWgOFAkaCrL22TdDDJiVpTuZM0XAGRWs9ieW0NKW7II=; b=fzaz3lDGtWmN0cUCFT7Iva7piX0heeiCfuSuxVjUKedBm5fMw95+gqlowm+R+MZyDU a17jaZu2Sv6XTm7lV2c+JzMpwpVFhpwK/rpMPPUp8is4Dgl+KS8T7k9xQu90hk6t9oM7 ++j5sJtL6YfD3+quANzBVwUZsn3LeDz9PAsLEAlKEnoM45GAG5FrQblDkUeXhx6oE2fL /X3NxBLBsyWcvYLtlAOaEw8EjoAQA75WNNP82gQsRFdHrEOqV3nglXOq3S6499pGUZOt 9uz3CKOupefq9pmCS4+H7hf61RpUq6v4x1ibGWjm2R/3NGz/d1i3quuQGJia63CqrF3f xbDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699101832; x=1699706632; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QWgOFAkaCrL22TdDDJiVpTuZM0XAGRWs9ieW0NKW7II=; b=qpo7jfNzQXlQQW92U2Tbm0cwbIgt3dyDKhYJ6QXoI0FEE91U4UvLwsUacZXABF/Gap 3CJWDugfoCRvhf9uTDSQVY+skNRL9DPOZoeFZDZBItc1NpckZH6lZP1914EILjSkbQnT wYYzDMr8vKQNp2DB3/jGsSmTtWeGZUebj8yCAnTaPOvqSV6JcRutRIVNkp1lgMq7tXV1 G/6phuVuETYE7HL3DWCcqvOzV1sAUHM38Ob0RZKvCfEI/p1wSUE3/2m+tl7J9RtS9/wv sTiAi1oVcKQQ5BWk5V4cYjJwJ1dwZfA9bd9DvkZQLvnKVTt4yTu1LH/Fh9qqK3/0+FLA bMRA== X-Gm-Message-State: AOJu0YxyGGPay9FN4vhagw1A/lva4FWUUDcdY6QW3VVBp6eY6SSviPRp AwZCx8uyFqM4nQLz+bCltTjCbg== X-Google-Smtp-Source: AGHT+IE/D76DP6LP5S/bC2ZUouN5nx6tvXDeDM1odIxhJnsb2wJCBGqDcoLyl8FiiBhU1HViFRqPDQ== X-Received: by 2002:a05:6512:3196:b0:4fa:f96c:745f with SMTP id i22-20020a056512319600b004faf96c745fmr23906142lfe.38.1699101831782; Sat, 04 Nov 2023 05:43:51 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id u22-20020ac24c36000000b005093312f66fsm496100lfq.124.2023.11.04.05.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:43:51 -0700 (PDT) From: Linus Walleij Date: Sat, 04 Nov 2023 13:43:49 +0100 Subject: [PATCH net 2/4] net: ethernet: cortina: Fix max RX frame define Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231104-gemini-largeframe-fix-v1-2-9c5513f22f33@linaro.org> References: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> In-Reply-To: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org Enumerator 3 is 1548 bytes according to the datasheet. Not 1542. Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij Reviewed-by: Andrew Lunn --- drivers/net/ethernet/cortina/gemini.c | 4 ++-- drivers/net/ethernet/cortina/gemini.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index e12d14359133..fd08f098850b 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -432,8 +432,8 @@ static const struct gmac_max_framelen gmac_maxlens[] = { .val = CONFIG0_MAXLEN_1536, }, { - .max_l3_len = 1542, - .val = CONFIG0_MAXLEN_1542, + .max_l3_len = 1548, + .val = CONFIG0_MAXLEN_1548, }, { .max_l3_len = 9212, diff --git a/drivers/net/ethernet/cortina/gemini.h b/drivers/net/ethernet/cortina/gemini.h index d7101bfcb4a0..e4b9049b6400 100644 --- a/drivers/net/ethernet/cortina/gemini.h +++ b/drivers/net/ethernet/cortina/gemini.h @@ -787,7 +787,7 @@ union gmac_config0 { #define CONFIG0_MAXLEN_1536 0 #define CONFIG0_MAXLEN_1518 1 #define CONFIG0_MAXLEN_1522 2 -#define CONFIG0_MAXLEN_1542 3 +#define CONFIG0_MAXLEN_1548 3 #define CONFIG0_MAXLEN_9k 4 /* 9212 */ #define CONFIG0_MAXLEN_10k 5 /* 10236 */ #define CONFIG0_MAXLEN_1518__6 6 From patchwork Sat Nov 4 12:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13445508 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7EC018B02 for ; Sat, 4 Nov 2023 12:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yy3Uh94e" Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420501BF for ; Sat, 4 Nov 2023 05:43:55 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-507973f3b65so3867554e87.3 for ; Sat, 04 Nov 2023 05:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699101833; x=1699706633; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vbrVElpE/LRcXL9QrTPOXjtUB0U3i3Et1aitWER/TV4=; b=yy3Uh94eo9ISIt7N3igeFW2Yn93KkptUPRKaRqm3tc95Hckgfob3SSvrYpMf9QyCGR /ae+NOo9o1uiKrgwVONTOQBO72lMiC6bN7n66oLerfIJ2I/pwJf4PL+f1sF4ft/CzB0q /vGTbxUE/lgnK+bCgP8P6nnnbRAfQ5vUMmbvxEbiwk7Ufef3G2Y2cwbrKgDi7uFTXeWq Tl+YJTVcdLA0SJ1cmeyRz6t7l71Mut7g0W2F1R1BkYG3Mh5t6LJAOHYgL7vq+UbZzA6B RIpTv+c4wD/6J1i/g0A9G0YrT01GB6ZUz5UeMOex12P0p0QTCWR2HYVXuPqifCHvn7NV Cm+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699101833; x=1699706633; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vbrVElpE/LRcXL9QrTPOXjtUB0U3i3Et1aitWER/TV4=; b=c0XB7fH53eGjhSDSfTAXueJupMOTV9bkUD59GINKOBA+WgMZJo1nw3aOMPum5dUnM1 t5rDxJvIf9AQieZmyNaMEE/V6E9AdKcUIqeZ7fNTRt+dwSsUUtvHIlOn7+hgdAgpxWNu mG89LV3micc88h2rdqKPzgZlHbs1hwi2TDUp1KbjQFg8u6Mz+ZkpmKw4pZI703Ae0/zG qVF4TjZcct9g6ywtSYl/jkpqOV6K/nM6CyWzkBviV9Wzop4Kl2pc0cImlVhYsXY+Z0N8 pNL2WbdxsxMOmrsWMhJ9QgpHuqpW9mX3CtemnsB2G6PiOiICjkLPxGVon8OQQ/oqessZ teug== X-Gm-Message-State: AOJu0Yw3tS0dGZRhXM/5XBTk8s/hfW9vPQ/fly9WdsH9u9+nECwXivrt qb6E7LBRF9b1r4+Sf4zpkQc+6A== X-Google-Smtp-Source: AGHT+IEOvtUSGS8gPMNB3spqJXMI2GzAA6fdOtLX2o73ozW/2re2ZnkjNq0X0bY0Zzh1Cl/kg6zB/Q== X-Received: by 2002:a05:6512:b93:b0:4fe:347d:7c4b with SMTP id b19-20020a0565120b9300b004fe347d7c4bmr23951283lfv.7.1699101833426; Sat, 04 Nov 2023 05:43:53 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id u22-20020ac24c36000000b005093312f66fsm496100lfq.124.2023.11.04.05.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:43:52 -0700 (PDT) From: Linus Walleij Date: Sat, 04 Nov 2023 13:43:50 +0100 Subject: [PATCH net 3/4] net: ethernet: cortina: Protect against oversized frames Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231104-gemini-largeframe-fix-v1-3-9c5513f22f33@linaro.org> References: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> In-Reply-To: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org The max size of a transfer no matter the MTU is 64KB-1 so immediately bail out if the skb exceeds that. Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index fd08f098850b..23723c9c0f93 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1156,6 +1156,12 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, mtu = MTU_SIZE_BIT_MASK; } + if (skb->len > 65535) { + /* The field for length is only 16 bits */ + netdev_err(netdev, "%s: frame too big, max size 65535 bytes\n", __func__); + return -EINVAL; + } + word1 = skb->len; word3 = SOF_BIT; From patchwork Sat Nov 4 12:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13445509 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC3A1A5A2 for ; Sat, 4 Nov 2023 12:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="d2xvWO4S" Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415C7D4E for ; Sat, 4 Nov 2023 05:43:56 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c509d5ab43so42064061fa.0 for ; Sat, 04 Nov 2023 05:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699101834; x=1699706634; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lGuoNoybmpAHVbeBRQ0Y/xZn4w65B05owlyMy7HgTuo=; b=d2xvWO4ScSw5iDGGrf5T4DdSaie2rYXL4P08TnmhPuTytCXNw16vb9TzYTpT0snlbg HJZUnMNOKFLVcUh0YZ4Qex3UDoIE5jpiUVrowLCwkJTzzJRUWhmVPq/ujbmhAAbQxogg Ppu08ekkM5OrENbvJX+0Ir5z4yeoU3evZN+YibULApcl4gAICZFaRtEr/sTBljFM2cXi BWpfe+kNA9MPS/abpXvdHQLNtkCML2QQe2gQxeHmTAzo241bRMcu8KbBwyrB/Wx4zQgO fLQWp0J96w779pogg1S8ZBPaGMY6CiY52ES1x9tThamt7ygywOrvuUUfTSJcx0JOqTJu qtfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699101834; x=1699706634; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lGuoNoybmpAHVbeBRQ0Y/xZn4w65B05owlyMy7HgTuo=; b=fxAxPsdHVIzTWDkg1x9GbuawUj54W08BC7TCl9snuYCmLSyl4Zq4f5xkYOG84uxCY9 c1Zn0HX/MoQ2Wv7kHZMpATilw1QpJ+KGuEVsFUPi4Ia+lGBocUPJJKndAN7Rh55DDKBE Ame3I0jyGgcJ8L2DtSs67aKanQ6KY6oIkyCAqt1Cc04Uj3Rtj45TKSRabZvmmOMFAk2p YNibNS7ePdJO4XMZqC1ymdFhQrs3PRL5ePnmQAZFb/Q4Dnz/gJjsZDIHQ+15L67xQWOR WgJ1yB9KoQP0iIZEM1km9nNv/JZzRj12B58dTzrohxzBJ5gk4Xx2TMPIJH2rLA8ggE7V 5Y6Q== X-Gm-Message-State: AOJu0Yw06yYaDRplvLKDfoOi4DqJuxiKd1VUh/GUey/XamartujOYrW/ mW4XFZThFiLqeOUKM4a4g84RhA== X-Google-Smtp-Source: AGHT+IFM8LyKtYP3lb6rmldO2Y/K2K0eNH2873kfaHunY7CPSwdiCXkmjcn14UjlqR8YVVm6mXvm5w== X-Received: by 2002:a05:6512:3f29:b0:509:62de:71c7 with SMTP id y41-20020a0565123f2900b0050962de71c7mr825163lfa.2.1699101834505; Sat, 04 Nov 2023 05:43:54 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id u22-20020ac24c36000000b005093312f66fsm496100lfq.124.2023.11.04.05.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 05:43:53 -0700 (PDT) From: Linus Walleij Date: Sat, 04 Nov 2023 13:43:51 +0100 Subject: [PATCH net 4/4] net: ethernet: cortina: Handle large frames Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231104-gemini-largeframe-fix-v1-4-9c5513f22f33@linaro.org> References: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> In-Reply-To: <20231104-gemini-largeframe-fix-v1-0-9c5513f22f33@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org The Gemini ethernet controller provides hardware checksumming for frames up to 1514 bytes including ethernet headers but not FCS. If we start sending bigger frames (after first bumping up the MTU on both interfaces sending and receiveing the frames), truncated packets start to appear on the target such as in this tcpdump resulting from ping -s 1474: 23:34:17.241983 14:d6:4d:a8:3c:4f (oui Unknown) > bc:ae:c5:6b:a8:3d (oui Unknown), ethertype IPv4 (0x0800), length 1514: truncated-ip - 2 bytes missing! (tos 0x0, ttl 64, id 32653, offset 0, flags [DF], proto ICMP (1), length 1502) OpenWrt.lan > Fecusia: ICMP echo request, id 1672, seq 50, length 1482 If we bypass the hardware checksumming and provide a software fallback, everything starts working fine up to the max TX MTU of 2047 bytes, for example ping -s2000 192.168.1.2: 00:44:29.587598 bc:ae:c5:6b:a8:3d (oui Unknown) > 14:d6:4d:a8:3c:4f (oui Unknown), ethertype IPv4 (0x0800), length 2042: (tos 0x0, ttl 64, id 51828, offset 0, flags [none], proto ICMP (1), length 2028) Fecusia > OpenWrt.lan: ICMP echo reply, id 1683, seq 4, length 2008 The bit enabling to bypass hardware checksum (or any of the "TSS" bits) are undocumented in the hardware reference manual. The entire hardware checksum unit appears undocumented. The conclusion that we need to use the "bypass" bit was found by trial-and-error. On the D-Link DIR-685 router this fixes a bug on the conduit interface to the RTL8366RB DSA switch: as the switch needs to add space for its tag it increases the MTU on the conduit interface to 1504 and that means that when the router sends packages of 1500 bytes these get an extra 4 bytes of DSA tag and the transfer fails because of the erroneous hardware checksumming, affecting such basic functionality as the LuCI web inteface. Suggested-by: Vladimir Oltean Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index 23723c9c0f93..063e58639379 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1145,6 +1145,7 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, dma_addr_t mapping; unsigned short mtu; void *buffer; + int ret; mtu = ETH_HLEN; mtu += netdev->mtu; @@ -1170,7 +1171,14 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, word3 |= mtu; } - if (skb->ip_summed != CHECKSUM_NONE) { + if (skb->len >= ETH_FRAME_LEN) { + /* Hardware offloaded checksumming isn't working on frames + * bigger than 1514 bytes. Perhaps the buffer is only 1518 + * bytes fitting mach a normal frame and a checksum? + * Just bypass on bigger frames. + */ + word1 |= TSS_BYPASS_BIT; + } else if (skb->ip_summed != CHECKSUM_NONE) { int tcp = 0; if (skb->protocol == htons(ETH_P_IP)) {