From patchwork Wed May 15 09:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1935401 X-Patchwork-Delegate: linus.walleij@linaro.org 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=QTC1voTI; 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=uz8lpKJV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::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 [IPv6:2607:7c80:54:3::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 4VfS2R39tjz1ydW for ; Wed, 15 May 2024 19:03:58 +1000 (AEST) 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=Z1CBo4b1utQ6ldTCjXip2SW/YqLoOo7nB11xREgQzYE=; b=QTC1voTIdqF5mW 7zQ6EL0612YsP65iKa4ArduYoa0Z1z92HphBNZfFxXTyInL3T6FErvT82/qy8Y4z9AIoevlPq6nUS V7IMdEWDkChEXoOY4nkcbt1XdRYy7EQoH+Zn+Ja4XjH+4ncUOm2NYDtThPFsVs1NpewSvthdO8KI5 drN+p+fq0W7Y6p886pmVb1BoyCDp8BsBgh7oglh2ybkuqTPtzYdVzj+A6nD7njJ7oa/v64FBbA0G7 bIMXNiVhvstrx/a83wn1w+uU9j6WMxEBngmWu0tGfDCHuPDH0Tf46ZmABWanWneK/RMfZx/YCKp2V h7hynq/4v9rRj/TeuOYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7AVb-000000011pa-0Ted; Wed, 15 May 2024 09:01:11 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7AVW-000000011mp-12xs for openwrt-devel@lists.openwrt.org; Wed, 15 May 2024 09:01:08 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a59cdd185b9so196989566b.1 for ; Wed, 15 May 2024 02:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715763662; x=1716368462; 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=73adixGSJktTRfBQ00j9wid2+m2F1BX8pBg3lCHZt9M=; b=uz8lpKJVl5jV8ETSz+njAibIRhd6Kd9Hzgu5aFVWKMv06J8PlY7EyLffOv5TeycAww Ht3tXMpN3lEt7+jheMmh1FKy9WOn78SgrhDchAphLhgUB89+ahHGpDokc865ogr368bu yN9sMuv80JqiztHDYZxGJQbqkQRpDvajLlIpXk3Y+KwVTh3Ow6IRIcM1mYDVkLQcC4G4 s9mXY1nonmI1nczFutkCNxnhVSpnzeaaK1pH488ZuRt6lcRXV0RSJaKu5uoavGnM6w5K FRazzVUDYUXvX5CLt/yGrB/rtttE+lXvqSK2w4sECvRYIoaM4uv8d1exBEZ6+Hs74Xgh aX6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715763662; x=1716368462; 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=73adixGSJktTRfBQ00j9wid2+m2F1BX8pBg3lCHZt9M=; b=W+ehgK1nZYxzB6N/mjSS4rAlwDwu9Hcl9nN3uw2N2kpKUFu1hRLPyjnJzCCkTN1AXp hqdtAhALUTSmwP7QJqaP76g2nC1dkmfgv1EcyJQWMbfBO3pN32Yq6xqqv8WVtHYYuquW qaVUyqzjPjqTAWtHl5Cp8NAexCYqMTCZXYJ6F8pZ6ppUkqfuA/7ITH/5VNRX/qdmHwTU KTJYJ0hcxn8+rXay8+WdOaYA3Q00Wh6d05QtlVGdncmAaTpuIMGaxpB0ww9NOSo/w48D uBFoNGv7jLa9vAJkLvGlV98ktHsJpYMqAJO6FEF/BHseTc5F8QjZAwjtDMV5CJFueFnc XnDA== X-Forwarded-Encrypted: i=1; AJvYcCVrj6dorBoVZZteS2UVKLOqLsg9GUQpWMqRlsQozbm8y8z9Q9k9qQYOMSymc/jZRRx2YXkKpIvTIw+HA2P9bCj3ey8/zMHTjG8e8IQmRXuX X-Gm-Message-State: AOJu0YyLeIM5+5EwcxuxYY5rDSlsXNCgEa5fVKiVVnUL+2F7yFCPwJ1i UfbeXMe6RthFgh5N9A0+Nm/3UQHF/0nW7srCk7pmPRICORBeXIsegVcxYeBXohcXWeAaLRP6542 pL30= X-Google-Smtp-Source: AGHT+IEZL4YIlvCz7R5Ng7uTWhlwXqFtNnhpFvQ7tk44OoxQTDp3W/Gab/dOOHWBKhayLah/FgYGfw== X-Received: by 2002:a17:906:ae99:b0:a59:be21:3587 with SMTP id a640c23a62f3a-a5a2d18aa67mr1299440066b.8.1715763661401; Wed, 15 May 2024 02:01:01 -0700 (PDT) Received: from [192.168.1.140] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17891f6esm832947166b.54.2024.05.15.02.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 02:01:01 -0700 (PDT) From: Linus Walleij Date: Wed, 15 May 2024 11:00:58 +0200 Subject: [PATCH] gemini: In-flight ethernet patches MIME-Version: 1.0 Message-Id: <20240515-gemini-ethernet-patches-v1-1-9a7c1770ef69@linaro.org> X-B4-Tracking: v=1; b=H4sIAMl5RGYC/x3MQQqAIBBG4avErBvISKyuEi3C/nQWWahEEN09a fkt3nsoIQoSjdVDEZckOUKBqiuyfgkOLGsxtU3bNVppdtglCCN7xIDM55KtR+J1sL3SmzKD0VT qM2KT+z9P8/t+KksMlmkAAAA= To: Christian Lamparter , Sebastian Luft , Hans Ulli Kroll , openwrt-devel@lists.openwrt.org Cc: Linus Walleij X-Mailer: b4 0.13.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_020106_451823_E56875BD X-CRM114-Status: GOOD ( 32.57 ) 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: These patches have partial acceptance upstream and are still a WIP, now there is merge window for kernel v6.10 so these will not be reposted until that is over. In the meantime, let's add the current [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:62c listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 These patches have partial acceptance upstream and are still a WIP, now there is merge window for kernel v6.10 so these will not be reposted until that is over. In the meantime, let's add the current state to OpenWrt so the ethernet on Gemini is up and working (tested on several devices). Signed-off-by: Linus Walleij --- ...-net-ethernet-cortina-Restore-TSO-support.patch | 124 +++++++++++++++++++++ ...hernet-cortina-Use-TSO-also-on-common-TCP.patch | 95 ++++++++++++++++ ...ernet-cortina-Rename-adjust-link-callback.patch | 36 ++++++ ...hernet-cortina-Use-negotiated-TX-RX-pause.patch | 46 ++++++++ ...thernet-cortina-Implement-.set_pauseparam.patch | 46 ++++++++ 5 files changed, 347 insertions(+) --- base-commit: 61e8728d86d7c11e1a5adab4bd37dae6b3b6cf2b change-id: 20240515-gemini-ethernet-patches-d9c815f17975 Best regards, diff --git a/target/linux/gemini/patches-6.6/0003-net-ethernet-cortina-Restore-TSO-support.patch b/target/linux/gemini/patches-6.6/0003-net-ethernet-cortina-Restore-TSO-support.patch new file mode 100644 index 000000000000..c8f8b6875d59 --- /dev/null +++ b/target/linux/gemini/patches-6.6/0003-net-ethernet-cortina-Restore-TSO-support.patch @@ -0,0 +1,124 @@ +From 30fcba19ed88997a2909e4a68b4d39ff371357c3 Mon Sep 17 00:00:00 2001 +From: Linus Walleij +Date: Wed, 1 May 2024 21:46:31 +0200 +Subject: [PATCH 1/5] net: ethernet: cortina: Restore TSO support + +An earlier commit deleted the TSO support in the Cortina Gemini +driver because the driver was confusing gso_size and MTU, +probably because what the Linux kernel calls "gso_size" was +called "MTU" in the datasheet. + +Restore the functionality properly reading the gso_size from +the skbuff. + +Tested with iperf3, running a server on a different machine +and client on the device with the cortina gemini ethernet: + +Connecting to host 192.168.1.2, port 5201 +60008000.ethernet-port eth0: segment offloading mss = 05ea len=1c8a +60008000.ethernet-port eth0: segment offloading mss = 05ea len=1c8a +60008000.ethernet-port eth0: segment offloading mss = 05ea len=27da +60008000.ethernet-port eth0: segment offloading mss = 05ea len=0b92 +60008000.ethernet-port eth0: segment offloading mss = 05ea len=2bda +(...) + +(The hardware MSS 0x05ea here includes the ethernet headers.) + +If I disable all segment offloading on the receiving host and +dump packets using tcpdump -xx like this: + +ethtool -K enp2s0 gro off gso off tso off +tcpdump -xx -i enp2s0 host 192.168.1.136 + +I get segmented packages such as this when running iperf3: + +23:16:54.024139 IP OpenWrt.lan.59168 > Fecusia.targus-getdata1: +Flags [.], seq 1486:2934, ack 1, win 4198, +options [nop,nop,TS val 3886192908 ecr 3601341877], length 1448 +0x0000: fc34 9701 a0c6 14d6 4da8 3c4f 0800 4500 +0x0010: 05dc 16a0 4000 4006 9aa1 c0a8 0188 c0a8 +0x0020: 0102 e720 1451 ff25 9822 4c52 29cf 8010 +0x0030: 1066 ac8c 0000 0101 080a e7a2 990c d6a8 +(...) +0x05c0: 5e49 e109 fe8c 4617 5e18 7a82 7eae d647 +0x05d0: e8ee ae64 dc88 c897 3f8a 07a4 3a33 6b1b +0x05e0: 3501 a30f 2758 cc44 4b4a + +Several such packets often follow after each other verifying +the segmentation into 0x05a8 (1448) byte packages also on the +reveiving end. As can be seen, the ethernet frames are +0x05ea (1514) in size. + +Performance with iperf3 before this patch: ~15.5 Mbit/s +Performance with iperf3 after this patch: ~175 Mbit/s + +This was running a 60 second test (twice) the best measurement +was 179 Mbit/s. + +For comparison if I run iperf3 with UDP I get around 1.05 Mbit/s +both before and after this patch. + +While this is a gigabit ethernet interface, the CPU is a cheap +D-Link DIR-685 router (based on the ARMv5 Faraday FA526 at +~50 MHz), and the software is not supposed to drive traffic, +as the device has a DSA chip, so this kind of numbers can be +expected. + +Fixes: ac631873c9e7 ("net: ethernet: cortina: Drop TSO support") +Reviewed-by: Eric Dumazet +Signed-off-by: Linus Walleij +--- + drivers/net/ethernet/cortina/gemini.c | 23 +++++++++++++++++++---- + 1 file changed, 19 insertions(+), 4 deletions(-) + +--- a/drivers/net/ethernet/cortina/gemini.c ++++ b/drivers/net/ethernet/cortina/gemini.c +@@ -79,7 +79,8 @@ MODULE_PARM_DESC(debug, "Debug level (0= + #define GMAC0_IRQ4_8 (GMAC0_MIB_INT_BIT | GMAC0_RX_OVERRUN_INT_BIT) + + #define GMAC_OFFLOAD_FEATURES (NETIF_F_SG | NETIF_F_IP_CSUM | \ +- NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM) ++ NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | \ ++ NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6) + + /** + * struct gmac_queue_page - page buffer per-page info +@@ -1143,13 +1144,25 @@ static int gmac_map_tx_bufs(struct net_d + skb_frag_t *skb_frag; + dma_addr_t mapping; + void *buffer; ++ u16 mss; + int ret; + +- /* TODO: implement proper TSO using MTU in word3 */ + word1 = skb->len; + word3 = SOF_BIT; + +- if (skb->len >= ETH_FRAME_LEN) { ++ mss = skb_shinfo(skb)->gso_size; ++ if (mss) { ++ /* This means we are dealing with TCP and skb->len is the ++ * sum total of all the segments. The TSO will deal with ++ * chopping this up for us. ++ */ ++ /* The accelerator needs the full frame size here */ ++ mss += skb_tcp_all_headers(skb); ++ netdev_dbg(netdev, "segment offloading mss = %04x len=%04x\n", ++ mss, skb->len); ++ word1 |= TSS_MTU_ENABLE_BIT; ++ word3 |= mss; ++ } else if (skb->len >= ETH_FRAME_LEN) { + /* Hardware offloaded checksumming isn't working on frames + * bigger than 1514 bytes. A hypothesis about this is that the + * checksum buffer is only 1518 bytes, so when the frames get +@@ -1164,7 +1177,9 @@ static int gmac_map_tx_bufs(struct net_d + return ret; + } + word1 |= TSS_BYPASS_BIT; +- } else if (skb->ip_summed == CHECKSUM_PARTIAL) { ++ } ++ ++ if (skb->ip_summed == CHECKSUM_PARTIAL) { + int tcp = 0; + + /* We do not switch off the checksumming on non TCP/UDP diff --git a/target/linux/gemini/patches-6.6/0004-net-ethernet-cortina-Use-TSO-also-on-common-TCP.patch b/target/linux/gemini/patches-6.6/0004-net-ethernet-cortina-Use-TSO-also-on-common-TCP.patch new file mode 100644 index 000000000000..7f7273f79ccb --- /dev/null +++ b/target/linux/gemini/patches-6.6/0004-net-ethernet-cortina-Use-TSO-also-on-common-TCP.patch @@ -0,0 +1,95 @@ +From 91fb8a7328dda827bc6c0da240a1eb17028416cd Mon Sep 17 00:00:00 2001 +From: Linus Walleij +Date: Thu, 9 May 2024 23:59:28 +0200 +Subject: [PATCH 2/5] net: ethernet: cortina: Use TSO also on common TCP + +It is possible to push the segment offloader to also +process non-segmented frames: just pass the skb->len +or desired MSS to the offloader and it will handle them. + +This is especially good if the user sets up the MTU +and the frames get big, because the checksumming engine +cannot handle any frames bigger than 1518 bytes, so +segmenting them all to be at max that will be helpful +for the hardware, which only need to quirk odd frames +such as big UDP ping packets. + +The vendor driver always uses the TSO like this, and +the driver seems more stable after this, so apparently +the hardware may have been engineered to always use +the TSO on anything it can handle. + +Signed-off-by: Linus Walleij +--- + drivers/net/ethernet/cortina/gemini.c | 31 +++++++++++++++++++++------ + 1 file changed, 24 insertions(+), 7 deletions(-) + +--- a/drivers/net/ethernet/cortina/gemini.c ++++ b/drivers/net/ethernet/cortina/gemini.c +@@ -1143,6 +1143,7 @@ static int gmac_map_tx_bufs(struct net_d + struct gmac_txdesc *txd; + skb_frag_t *skb_frag; + dma_addr_t mapping; ++ bool tcp = false; + void *buffer; + u16 mss; + int ret; +@@ -1150,6 +1151,13 @@ static int gmac_map_tx_bufs(struct net_d + word1 = skb->len; + word3 = SOF_BIT; + ++ /* Determine if we are doing TCP */ ++ if (skb->protocol == htons(ETH_P_IP)) ++ tcp = (ip_hdr(skb)->protocol == IPPROTO_TCP); ++ else ++ /* IPv6 */ ++ tcp = (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP); ++ + mss = skb_shinfo(skb)->gso_size; + if (mss) { + /* This means we are dealing with TCP and skb->len is the +@@ -1162,6 +1170,20 @@ static int gmac_map_tx_bufs(struct net_d + mss, skb->len); + word1 |= TSS_MTU_ENABLE_BIT; + word3 |= mss; ++ } else if (tcp) { ++ /* Even if we are not using TSO, use the segment offloader ++ * for transferring the TCP frame: the TSO engine will deal ++ * with chopping up frames that exceed ETH_DATA_LEN which ++ * the checksumming engine cannot handle (see below) into ++ * manageable chunks. It flawlessly deals with quite big ++ * frames and frames containing custom DSA EtherTypes. ++ */ ++ mss = netdev->mtu + skb_tcp_all_headers(skb); ++ mss = min(mss, skb->len); ++ netdev_dbg(netdev, "botched TSO len %04x mtu %04x mss %04x\n", ++ skb->len, netdev->mtu, mss); ++ word1 |= TSS_MTU_ENABLE_BIT; ++ word3 |= mss; + } else if (skb->len >= ETH_FRAME_LEN) { + /* Hardware offloaded checksumming isn't working on frames + * bigger than 1514 bytes. A hypothesis about this is that the +@@ -1180,21 +1202,16 @@ static int gmac_map_tx_bufs(struct net_d + } + + if (skb->ip_summed == CHECKSUM_PARTIAL) { +- int tcp = 0; +- + /* We do not switch off the checksumming on non TCP/UDP + * frames: as is shown from tests, the checksumming engine + * is smart enough to see that a frame is not actually TCP + * or UDP and then just pass it through without any changes + * to the frame. + */ +- if (skb->protocol == htons(ETH_P_IP)) { ++ if (skb->protocol == htons(ETH_P_IP)) + word1 |= TSS_IP_CHKSUM_BIT; +- tcp = ip_hdr(skb)->protocol == IPPROTO_TCP; +- } else { /* IPv6 */ ++ else + word1 |= TSS_IPV6_ENABLE_BIT; +- tcp = ipv6_hdr(skb)->nexthdr == IPPROTO_TCP; +- } + + word1 |= tcp ? TSS_TCP_CHKSUM_BIT : TSS_UDP_CHKSUM_BIT; + } diff --git a/target/linux/gemini/patches-6.6/0005-net-ethernet-cortina-Rename-adjust-link-callback.patch b/target/linux/gemini/patches-6.6/0005-net-ethernet-cortina-Rename-adjust-link-callback.patch new file mode 100644 index 000000000000..bbdef8fefc2b --- /dev/null +++ b/target/linux/gemini/patches-6.6/0005-net-ethernet-cortina-Rename-adjust-link-callback.patch @@ -0,0 +1,36 @@ +From fa01c904b844e6033445f75b0b4d46a8e83b6086 Mon Sep 17 00:00:00 2001 +From: Linus Walleij +Date: Fri, 10 May 2024 19:48:27 +0200 +Subject: [PATCH 3/5] net: ethernet: cortina: Rename adjust link callback + +The callback passed to of_phy_get_and_connect() in the +Cortina Gemini driver is called "gmac_speed_set" which is +archaic, rename it to "gmac_adjust_link" following the +pattern of most other drivers. + +Reviewed-by: Andrew Lunn +Signed-off-by: Linus Walleij +--- + drivers/net/ethernet/cortina/gemini.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/drivers/net/ethernet/cortina/gemini.c ++++ b/drivers/net/ethernet/cortina/gemini.c +@@ -288,7 +288,7 @@ static void gmac_set_flow_control(struct + spin_unlock_irqrestore(&port->config_lock, flags); + } + +-static void gmac_speed_set(struct net_device *netdev) ++static void gmac_adjust_link(struct net_device *netdev) + { + struct gemini_ethernet_port *port = netdev_priv(netdev); + struct phy_device *phydev = netdev->phydev; +@@ -367,7 +367,7 @@ static int gmac_setup_phy(struct net_dev + + phy = of_phy_get_and_connect(netdev, + dev->of_node, +- gmac_speed_set); ++ gmac_adjust_link); + if (!phy) + return -ENODEV; + netdev->phydev = phy; diff --git a/target/linux/gemini/patches-6.6/0006-net-ethernet-cortina-Use-negotiated-TX-RX-pause.patch b/target/linux/gemini/patches-6.6/0006-net-ethernet-cortina-Use-negotiated-TX-RX-pause.patch new file mode 100644 index 000000000000..a1b8707f7250 --- /dev/null +++ b/target/linux/gemini/patches-6.6/0006-net-ethernet-cortina-Use-negotiated-TX-RX-pause.patch @@ -0,0 +1,46 @@ +From 50ac9765c674bac803719c6b8294670edc6df31d Mon Sep 17 00:00:00 2001 +From: Linus Walleij +Date: Fri, 10 May 2024 19:44:39 +0200 +Subject: [PATCH 4/5] net: ethernet: cortina: Use negotiated TX/RX pause + +Instead of directly poking into registers of the PHY, use +the existing function to query phylib about this directly. + +Suggested-by: Andrew Lunn +Reviewed-by: Andrew Lunn +Signed-off-by: Linus Walleij +--- + drivers/net/ethernet/cortina/gemini.c | 15 +++++---------- + 1 file changed, 5 insertions(+), 10 deletions(-) + +--- a/drivers/net/ethernet/cortina/gemini.c ++++ b/drivers/net/ethernet/cortina/gemini.c +@@ -293,8 +293,8 @@ static void gmac_adjust_link(struct net_ + struct gemini_ethernet_port *port = netdev_priv(netdev); + struct phy_device *phydev = netdev->phydev; + union gmac_status status, old_status; +- int pause_tx = 0; +- int pause_rx = 0; ++ bool pause_tx = false; ++ bool pause_rx = false; + + status.bits32 = readl(port->gmac_base + GMAC_STATUS); + old_status.bits32 = status.bits32; +@@ -329,14 +329,9 @@ static void gmac_adjust_link(struct net_ + } + + if (phydev->duplex == DUPLEX_FULL) { +- u16 lcladv = phy_read(phydev, MII_ADVERTISE); +- u16 rmtadv = phy_read(phydev, MII_LPA); +- u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); +- +- if (cap & FLOW_CTRL_RX) +- pause_rx = 1; +- if (cap & FLOW_CTRL_TX) +- pause_tx = 1; ++ phy_get_pause(phydev, &pause_tx, &pause_rx); ++ netdev_dbg(netdev, "set negotiated pause params pause TX = %s, pause RX = %s\n", ++ pause_tx ? "ON" : "OFF", pause_rx ? "ON" : "OFF"); + } + + gmac_set_flow_control(netdev, pause_tx, pause_rx); diff --git a/target/linux/gemini/patches-6.6/0007-net-ethernet-cortina-Implement-.set_pauseparam.patch b/target/linux/gemini/patches-6.6/0007-net-ethernet-cortina-Implement-.set_pauseparam.patch new file mode 100644 index 000000000000..3c87d7ff3cef --- /dev/null +++ b/target/linux/gemini/patches-6.6/0007-net-ethernet-cortina-Implement-.set_pauseparam.patch @@ -0,0 +1,46 @@ +From 4eed4b87f17d10b7586349c13c3a30f9c24c9ba4 Mon Sep 17 00:00:00 2001 +From: Linus Walleij +Date: Wed, 8 May 2024 23:21:17 +0200 +Subject: [PATCH 5/5] net: ethernet: cortina: Implement .set_pauseparam() + +The Cortina Gemini ethernet can very well set up TX or RX +pausing, so add this functionality to the driver in a +.set_pauseparam() callback. Essentially just call down to +phylib and let phylib deal with this, .adjust_link() +will respect the setting from phylib. + +Signed-off-by: Linus Walleij +--- + drivers/net/ethernet/cortina/gemini.c | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +--- a/drivers/net/ethernet/cortina/gemini.c ++++ b/drivers/net/ethernet/cortina/gemini.c +@@ -2135,6 +2135,19 @@ static void gmac_get_pauseparam(struct n + pparam->autoneg = true; + } + ++static int gmac_set_pauseparam(struct net_device *netdev, ++ struct ethtool_pauseparam *pparam) ++{ ++ struct phy_device *phydev = netdev->phydev; ++ ++ if (!pparam->autoneg) ++ return -EOPNOTSUPP; ++ ++ phy_set_asym_pause(phydev, pparam->rx_pause, pparam->tx_pause); ++ ++ return 0; ++} ++ + static void gmac_get_ringparam(struct net_device *netdev, + struct ethtool_ringparam *rp, + struct kernel_ethtool_ringparam *kernel_rp, +@@ -2255,6 +2268,7 @@ static const struct ethtool_ops gmac_351 + .set_link_ksettings = gmac_set_ksettings, + .nway_reset = gmac_nway_reset, + .get_pauseparam = gmac_get_pauseparam, ++ .set_pauseparam = gmac_set_pauseparam, + .get_ringparam = gmac_get_ringparam, + .set_ringparam = gmac_set_ringparam, + .get_coalesce = gmac_get_coalesce,