From patchwork Sat Jul 23 20:53:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659984 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Fv7ulAJ/; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=G7G3Dl3Y; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lqzfd5Bhlz9sGp for ; Sun, 24 Jul 2022 07:17:45 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LZAn7lM3ofTajT30FXg0j06jPGdHbbUdWX/ARo3HI5o=; b=Fv7ulAJ/d9zV29 Yq4iZQ+JeE0VCudIjxOaIt5i3XhApoHKxpRpye0NaMSEEZx22+xE++2PbPCTr9cxNdsTm6Lx2ORoV RqDSxnKPK/jul1OVWZyE7QulGSauw9KzxVmQ0Si+Xt2TMGPZD91pYMW8GQ2udqpBrTKLIcysCoBtf HxQZe8gaQ8Q0fdFKrjuGgrEzakRgFewPlD8BFQoWuZW0W7yP7djmtmwiHrBpNBPD8+O4QBN+k57aU mHGfqouRgMe0JD6ubZE02pTCydqgrIduaDMYKPdOYyLIBlJQyhyPF5PZwNCMbqYPoPjMqmXF6JfRB 463rJub/pUXUg5NJ4yDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMRC-007NbE-CD; Sat, 23 Jul 2022 21:13:27 +0000 Received: from srv4.3e8.eu ([2001:67c:12a0:200::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM83-007Db2-2D for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:41 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 4CD4A60211; Sat, 23 Jul 2022 22:53:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvJdROZL2jjxEXoYy7096pf+vKrgpbBaOVvyjSFekBA=; b=G7G3Dl3YfBjA/UDNb0aQqXacJ6Q7+TjO2q7nPMfwhSBz+tnrN4+zY4Zw/OUh1eoEHH5/g/ yGHjxqCKsVXLFsJM/VliC6qxWcTf/fJdmdvXrECwzYZByKtm+wLYMl1wnQ4jzUWC9OZ/D8 WVtwZmnjtwLIcx2Cqc9g2F/lxfvfOu1azIMh8w9I2q+cYe0z4WUqjwy+kugsEmAWs3tWPC 4EmIzqdHScf6zafwn8MhkZySS8KrW1pnuvsLpF7rwowgEk23HbdbrCrtVCC9y+zHSa3s2H H6E5aAWYHD1ukp36+tRkTuX9XunsDjXCicR7bQD6fDviSdLMljzRwmXy871YVQ== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 1/7] realtek: rtl83xx-phy: fix RTL8214FC media change Date: Sat, 23 Jul 2022 22:53:13 +0200 Message-Id: <20220723205319.3326374-2-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135339_463704_8BF0ACBB X-CRM114-Status: UNSURE ( 8.22 ) X-CRM114-Notice: Please train this message. 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: Toggle power on the individual PHY instead of the package. Otherwise a media change always toggles power on the first port, and not the one that is being configured. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/phy/rtl83xx-phy.c | 32 +++++++++ 1 file changed, 16 insertions(+), 16 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Toggle power on the individual PHY instead of the package. Otherwise a media change always toggles power on the first port, and not the one that is being configured. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/phy/rtl83xx-phy.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c index f0c30b36555e..252389489106 100644 --- a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c +++ b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c @@ -949,19 +949,20 @@ static void rtl8380_rtl8214fc_media_set(struct phy_device *phydev, bool set_fibr pr_info("Current media %x\n", media); if (media & 0x2) { pr_info("Powering off COPPER\n"); - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); /* Ensure power is off */ - power = phy_package_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); + power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); if (!(power & (1 << 11))) - phy_package_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); + phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); } else { - pr_info("Powering off FIBRE"); - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); + pr_info("Powering off FIBRE\n"); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); /* Ensure power is off */ - power = phy_package_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); + power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); if (!(power & (1 << 11))) - phy_package_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); + phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); } + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); if (set_fibre) { val |= 1 << 10; @@ -975,22 +976,21 @@ static void rtl8380_rtl8214fc_media_set(struct phy_device *phydev, bool set_fibr phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); if (set_fibre) { - pr_info("Powering on FIBRE"); - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); + pr_info("Powering on FIBRE\n"); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); /* Ensure power is off */ - power = phy_package_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); + power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); if (power & (1 << 11)) - phy_package_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); + phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); } else { pr_info("Powering on COPPER\n"); - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); /* Ensure power is off */ - power = phy_package_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); + power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); if (power & (1 << 11)) - phy_package_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); + phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); } - - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); } static bool rtl8380_rtl8214fc_media_is_fibre(struct phy_device *phydev) From patchwork Sat Jul 23 20:53:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659982 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=In3icPxM; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=SI2/n6oO; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LqzcP29gTz9sGp for ; Sun, 24 Jul 2022 07:15:49 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TXozbY1HAVdxOAxKwT5Oac0He76f+FQfhX2oPfer9cg=; b=In3icPxMRGECgf ei0Y7imcJgQZJVzIi7MOkojY63e6Ckaa47ybgyV0NAL+Vr50adyy1qf6AfR4yLoSG4r6dFtvMguWw IvCuKAgxMoqNFfJawk0W+3dRc5Wi+znDZD4Aav8VZGdm48Dob3pA3jMNUYkj+yuB9zORE/ka3cyAy UYzR6h2VlDX7X/cBqLj55NoNmeVRm6J19ENUrxT/AfcO89m/aMK/mxbwIJLdezU/2SA5HzdJwNGn6 ClZwOV6kyfIw5fR7MZfRVH4xfz17iVzRasTcrmxh9WH0a3AyRbVU63OojRevMnTXxsHTCeq2jEXp7 eCj7db4Wp/6URdkMihSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMQ7-007N8b-7E; Sat, 23 Jul 2022 21:12:19 +0000 Received: from srv4.3e8.eu ([193.25.101.238]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM82-007DbZ-1c for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:40 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 8982C600B5; Sat, 23 Jul 2022 22:53:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=58L1lMGv5/Q9u6TCTbNYKcFWBUeflDKBkTiGWZDbp2g=; b=SI2/n6oODnTfNRStR7mqs2FidMAp3rUrh++DHHqfE0YTKJDQXYdScw4dOBv1zETp4I3a3v PmA2Nsaale2LxnG8TYEBZze1aTGPIyohzqp89gxOiNx3JprBFrFG262Xt4HScBryLRpXkv AYKYFJ5t1+SM6KmiFJje7imshR/c418DLP/HqMEVB/Yq2WF8lFq5E3XiZkSnPKWIK3mnPy 0I+AIN2wC99s/aiEZUM5VF1w6kwUZpWJNfnJboS2duruDi35WijDy0DCxfSdkYHHHVzy5X 8xP/MUHvE0ZsyNpJuazZobS2qOxNMXyW1f0m4MiG5vEqOIGm+3f2HfluaHvx7Q== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 2/7] realtek: rtl83xx-phy: decouple RTL8214FC media change and power config Date: Sat, 23 Jul 2022 22:53:14 +0200 Message-Id: <20220723205319.3326374-3-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135338_446088_74CDB292 X-CRM114-Status: GOOD ( 14.46 ) 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: Move RTL8214FC power configuration to newly created suspend and resume methods. A media change now only results in power configuration if the PHY is not suspended, to avoid powering up a port when the [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Move RTL8214FC power configuration to newly created suspend and resume methods. A media change now only results in power configuration if the PHY is not suspended, to avoid powering up a port when the interface is currently not up. While at it, remove the rtl8380 prefix from function names, as this is actually not SoC-specific. Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/phy/rtl83xx-phy.c | 122 ++++++++++-------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c index 252389489106..70b57924b9b3 100644 --- a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c +++ b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c @@ -934,78 +934,96 @@ static int rtl8218b_ext_match_phy_device(struct phy_device *phydev) return phydev->phy_id == PHY_ID_RTL8218B_E; } -static void rtl8380_rtl8214fc_media_set(struct phy_device *phydev, bool set_fibre) +static bool rtl8214fc_media_is_fibre(struct phy_device *phydev) { int mac = phydev->mdio.addr; static int reg[] = {16, 19, 20, 21}; - int val, media, power; + u32 val; - pr_info("%s: port %d, set_fibre: %d\n", __func__, mac, set_fibre); phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_INTERNAL); val = phy_package_read_paged(phydev, RTL821X_PAGE_PORT, reg[mac % 4]); + phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); - media = (val >> 10) & 0x3; - pr_info("Current media %x\n", media); - if (media & 0x2) { - pr_info("Powering off COPPER\n"); - phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); - /* Ensure power is off */ - power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); - if (!(power & (1 << 11))) - phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); - } else { - pr_info("Powering off FIBRE\n"); + if (val & BIT(11)) + return false; + + return true; +} + +static void rtl8214fc_power_set(struct phy_device *phydev, int port, bool on) +{ + char *state = on ? "on" : "off"; + + if (port == PORT_FIBRE) { + pr_info("%s: Powering %s FIBRE (port %d)\n", __func__, state, phydev->mdio.addr); phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); - /* Ensure power is off */ - power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); - if (!(power & (1 << 11))) - phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power | (1 << 11)); + } else { + pr_info("%s: Powering %s COPPER (port %d)\n", __func__, state, phydev->mdio.addr); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); } - phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); - if (set_fibre) { - val |= 1 << 10; - val &= ~(1 << 11); + if (on) { + phy_modify_paged(phydev, RTL821X_PAGE_POWER, 0x10, BIT(11), 0); } else { - val |= 1 << 10; - val |= 1 << 11; + phy_modify_paged(phydev, RTL821X_PAGE_POWER, 0x10, 0, BIT(11)); } - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_INTERNAL); - phy_package_write_paged(phydev, RTL821X_PAGE_PORT, reg[mac % 4], val); - phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); - if (set_fibre) { - pr_info("Powering on FIBRE\n"); - phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_FIBRE); - /* Ensure power is off */ - power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); - if (power & (1 << 11)) - phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); + phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); +} + +static int rtl8214fc_suspend(struct phy_device *phydev) +{ + rtl8214fc_power_set(phydev, PORT_MII, false); + rtl8214fc_power_set(phydev, PORT_FIBRE, false); + + return 0; +} + +static int rtl8214fc_resume(struct phy_device *phydev) +{ + if (rtl8214fc_media_is_fibre(phydev)) { + rtl8214fc_power_set(phydev, PORT_MII, false); + rtl8214fc_power_set(phydev, PORT_FIBRE, true); } else { - pr_info("Powering on COPPER\n"); - phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_COPPER); - /* Ensure power is off */ - power = phy_read_paged(phydev, RTL821X_PAGE_POWER, 0x10); - if (power & (1 << 11)) - phy_write_paged(phydev, RTL821X_PAGE_POWER, 0x10, power & ~(1 << 11)); + rtl8214fc_power_set(phydev, PORT_FIBRE, false); + rtl8214fc_power_set(phydev, PORT_MII, true); } - phy_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); + + return 0; } -static bool rtl8380_rtl8214fc_media_is_fibre(struct phy_device *phydev) +static void rtl8214fc_media_set(struct phy_device *phydev, bool set_fibre) { int mac = phydev->mdio.addr; static int reg[] = {16, 19, 20, 21}; - u32 val; + int val; + pr_info("%s: port %d, set_fibre: %d\n", __func__, mac, set_fibre); phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_INTERNAL); val = phy_package_read_paged(phydev, RTL821X_PAGE_PORT, reg[mac % 4]); + + val |= BIT(10); + if (set_fibre) { + val &= ~BIT(11); + } else { + val |= BIT(11); + } + + phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_INTERNAL); + phy_package_write_paged(phydev, RTL821X_PAGE_PORT, reg[mac % 4], val); phy_package_write_paged(phydev, RTL83XX_PAGE_RAW, RTL821XINT_MEDIA_PAGE_SELECT, RTL821X_MEDIA_PAGE_AUTO); - if (val & (1 << 11)) - return false; - return true; + + if (!phydev->suspended) { + if (set_fibre) { + rtl8214fc_power_set(phydev, PORT_MII, false); + rtl8214fc_power_set(phydev, PORT_FIBRE, true); + } else { + rtl8214fc_power_set(phydev, PORT_FIBRE, false); + rtl8214fc_power_set(phydev, PORT_MII, true); + } + } } static int rtl8214fc_set_port(struct phy_device *phydev, int port) @@ -1015,7 +1033,7 @@ static int rtl8214fc_set_port(struct phy_device *phydev, int port) pr_debug("%s port %d to %d\n", __func__, addr, port); - rtl8380_rtl8214fc_media_set(phydev, is_fibre); + rtl8214fc_media_set(phydev, is_fibre); return 0; } @@ -1024,7 +1042,7 @@ static int rtl8214fc_get_port(struct phy_device *phydev) int addr = phydev->mdio.addr; pr_debug("%s: port %d\n", __func__, addr); - if (rtl8380_rtl8214fc_media_is_fibre(phydev)) + if (rtl8214fc_media_is_fibre(phydev)) return PORT_FIBRE; return PORT_MII; } @@ -1131,7 +1149,7 @@ static int rtl8214fc_set_eee(struct phy_device *phydev, pr_debug("In %s port %d, enabled %d\n", __func__, port, e->eee_enabled); - if (rtl8380_rtl8214fc_media_is_fibre(phydev)) { + if (rtl8214fc_media_is_fibre(phydev)) { netdev_err(phydev->attached_dev, "Port %d configured for FIBRE", port); return -ENOTSUPP; } @@ -1184,7 +1202,7 @@ static int rtl8214fc_get_eee(struct phy_device *phydev, int addr = phydev->mdio.addr; pr_debug("In %s port %d, enabled %d\n", __func__, addr, e->eee_enabled); - if (rtl8380_rtl8214fc_media_is_fibre(phydev)) { + if (rtl8214fc_media_is_fibre(phydev)) { netdev_err(phydev->attached_dev, "Port %d configured for FIBRE", addr); return -ENOTSUPP; } @@ -3842,8 +3860,8 @@ static struct phy_driver rtl83xx_phy_driver[] = { .flags = PHY_HAS_REALTEK_PAGES, .match_phy_device = rtl8214fc_match_phy_device, .probe = rtl8214fc_phy_probe, - .suspend = genphy_suspend, - .resume = genphy_resume, + .suspend = rtl8214fc_suspend, + .resume = rtl8214fc_resume, .set_loopback = genphy_loopback, .set_port = rtl8214fc_set_port, .get_port = rtl8214fc_get_port, From patchwork Sat Jul 23 20:53:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659981 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=cbHd2m4y; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=Sc3icFAh; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lqzc522yFz9sGp for ; Sun, 24 Jul 2022 07:15:33 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2W5XOSIKaQU37/bvlVvcQ1oK1/knnKOTqYBzIRBkfR4=; b=cbHd2m4yRNCxY1 DgEyltEC/SmnP5SbVCjsirlH1P8Jp77eLI6D+lNwG+AVBsHtNwf6wUCy2pxiEJBN6alJqrzwbNNr+ +i5Cxj36m7xtkx4WCPrwUTB+sOMQ2coTc0R6jZwemoKCRISPrn/Vrcjy02Mfygl5979muwZN3eE6x Of0UszSiRmPYWrE2//UjmVs3i078ZYXaXrUqkYR5WxXH/ZokXZUEeQwd4HBv8ZBfJfOfyXH2Zsw27 IPqmgkKO6q7blfefNfBxKqzFIkR2LYJ4LVd+UGS98kFuRKWjBFpNtbZ4zwlBf4y8/TvHjxEAlR04i 4D4SuQ6OuDbNQEah4KSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMPC-007Mdc-00; Sat, 23 Jul 2022 21:11:22 +0000 Received: from srv4.3e8.eu ([193.25.101.238]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM83-007DcH-65 for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:40 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 496B760212; Sat, 23 Jul 2022 22:53:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U7yabNuHMj6pmzF0fnLDLVUn+zD23e2dMrZPa4Xq0bo=; b=Sc3icFAhhkz7lk86/l6n+x+f6FjRphkI4n3THagmTgF5ijL38fGSfSbWaBQ5tLCTl/3TzS H5XvxbF5QLulxi+6p1dQ+LzRj4CqU8jy6UkfhKSJEksCMs2ri7GfiFeHxJyHHj2JsKEZvA 9DG9arKM2VvwO6N0qCWBYXKkrBxbPqVgVuSvkRABjEh2jkK2BINP/qDrn+JhmXnfTOmO/5 ituzUrSFBDtaPUsDWrlWCWMJUgKExfArfzBtP4JiQCKOIZJIYdrMPBRFTn1M15x8/ivzKV 7Np6BikdcdbtitQghjNV5VHEMTbeBPCmob+yVc6/6hXuZr0Z+FAxUR5SYlQ0yQ== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann , Birger Koblitz Subject: [PATCH 3/7] realtek: add SFP support for RTL8214FC PHY Date: Sat, 23 Jul 2022 22:53:15 +0200 Message-Id: <20220723205319.3326374-4-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135339_417067_AEC42203 X-CRM114-Status: GOOD ( 11.07 ) 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: Probe the SFP module during PHY initialization and implement insertion/removal handlers to automatically configure the media type of the respective port. Suggested-by: Birger Koblitz Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/phy/rtl83xx-phy.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+) [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Probe the SFP module during PHY initialization and implement insertion/removal handlers to automatically configure the media type of the respective port. Suggested-by: Birger Koblitz Signed-off-by: Jan Hoffmann --- .../files-5.10/drivers/net/phy/rtl83xx-phy.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c index 70b57924b9b3..4175b950435e 100644 --- a/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c +++ b/target/linux/realtek/files-5.10/drivers/net/phy/rtl83xx-phy.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "rtl83xx-phy.h" @@ -3676,6 +3677,29 @@ int rtl931x_link_sts_get(u32 sds) return sts1; } +static int rtl8214fc_sfp_insert(void *upstream, const struct sfp_eeprom_id *id) +{ + struct phy_device *phydev = upstream; + + rtl8214fc_media_set(phydev, true); + + return 0; +} + +static void rtl8214fc_sfp_remove(void *upstream) +{ + struct phy_device *phydev = upstream; + + rtl8214fc_media_set(phydev, false); +} + +static const struct sfp_upstream_ops rtl8214fc_sfp_ops = { + .attach = phy_sfp_attach, + .detach = phy_sfp_detach, + .module_insert = rtl8214fc_sfp_insert, + .module_remove = rtl8214fc_sfp_remove, +}; + static int rtl8214fc_phy_probe(struct phy_device *phydev) { struct device *dev = &phydev->mdio.dev; @@ -3699,7 +3723,7 @@ static int rtl8214fc_phy_probe(struct phy_device *phydev) return ret; } - return 0; + return phy_sfp_probe(phydev, &rtl8214fc_sfp_ops); } static int rtl8214c_phy_probe(struct phy_device *phydev) From patchwork Sat Jul 23 20:53:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659983 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=AVJWqWTk; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=f7lsgBxc; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lqzdp4YD0z9sGp for ; Sun, 24 Jul 2022 07:17:02 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SrCK4pNRfmudlvexfODy2UOgTUQOt7t+//QnodR29PE=; b=AVJWqWTk9bZv1w bqsUmFa3kaSIok0E1JNgRygW7V83CpOcSv2dZZRiDcVjkPqfN2QdImFfdlgAd9Ko6Wy28+CcTbPQf 0LWY5ZzkB9G2X7QKjpa0ULSN7WqzZNsH3j7Rc4BiNN5BSB6ObCLl3cFfIljqOqqm/g/wuHmkYjJ4X Uqx+mTzUWlwxaq6sACoDlPjvBdOwqFODsveNg3WrEotvN2YoAoi8kyawXZMXDF0kM+SdEasPwL6M9 YAGgER4+pGm4c7FRXF0C0P1Z8wa9DoiPC8MjXZdY6J/TwJlo8+AKov4K0MAoSS2VkP/BW8SQ4NYvx o7hGGGnjJxdCwVmAOD1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMSe-007OJi-Db; Sat, 23 Jul 2022 21:14:56 +0000 Received: from srv4.3e8.eu ([193.25.101.238]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM83-007Dcr-Rz for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:42 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 6AAD760213; Sat, 23 Jul 2022 22:53:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cmKGO6pYUohrUWwYUQ9912hkOZ8G+s1RwR3b4Kmb4E=; b=f7lsgBxcFPPeBbl1szeLzOyZwTR4HEJDjbneZSDOavFji2nytZsMWY6+CJGCPv7bA7fczy e2wb40KDGJLymyVUkvDD16lZD2z+MZ6OpR+1Os3bCA4Kze+XEM25wonta2gzUfWD1Swcd+ phPFQv/Y4b78K+102MQZdtiA8cfNdszppORUnqPE5dw8Y/ov8aT042/rMNnatwqjJ8GSYt /yzxbQjItkf7yA9Fm9iOjq+VifIxVh/SH0mt/Tn2YFpnWtC8/8dVQhOdNvN/E6sn3BSjop mAy1A1VFhdza/KaC8TD9uZ3UgP1WtcR1zvYkq8Ni8QGhDLMnI+rbvKAHMhUoOg== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 4/7] realtek: clean up rtl838x MDIO busy wait loop Date: Sat, 23 Jul 2022 22:53:16 +0200 Message-Id: <20220723205319.3326374-5-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135340_337865_D4D0E92E X-CRM114-Status: GOOD ( 12.14 ) 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: Don't use udelay to allow other kernel tasks to execute if the kernel has been built without preemption. Also determine the timeout based on jiffies instead of loop iterations. This is especially important on devices containing a watchdog with a short timeout. Without this change, the watchdog is not serviced during PHY patching which can take multiple seconds. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Don't use udelay to allow other kernel tasks to execute if the kernel has been built without preemption. Also determine the timeout based on jiffies instead of loop iterations. This is especially important on devices containing a watchdog with a short timeout. Without this change, the watchdog is not serviced during PHY patching which can take multiple seconds. Signed-off-by: Jan Hoffmann --- .../drivers/net/dsa/rtl83xx/rtl838x.c | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c index cdf176677805..524594d725fc 100644 --- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c @@ -1805,13 +1805,20 @@ irqreturn_t rtl838x_switch_irq(int irq, void *dev_id) int rtl838x_smi_wait_op(int timeout) { - do { - timeout--; - udelay(10); - } while ((sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1) && (timeout >= 0)); - if (timeout <= 0) - return -1; - return 0; + unsigned long end = jiffies + usecs_to_jiffies(timeout); + + while (1) { + if (!(sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_1) & 0x1)) + return 0; + + if (time_after(jiffies, end)) + break; + + usleep_range(10, 20); + } + + pr_err("rtl838x_smi_wait_op: timeout\n"); + return -1; } /* @@ -1832,7 +1839,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2); @@ -1842,7 +1849,7 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1868,7 +1875,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) return -ENOTSUPP; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(BIT(port), RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1881,7 +1888,7 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock); @@ -1901,7 +1908,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1916,7 +1923,7 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) v = 1 << 1 | 0 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; @@ -1940,7 +1947,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) val &= 0xffff; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); @@ -1954,7 +1961,7 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) v = 1 << 1 | 1 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(10000)) + if (rtl838x_smi_wait_op(100000)) goto timeout; mutex_unlock(&smi_lock); From patchwork Sat Jul 23 20:53:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659986 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=hnZbTQob; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=OYGOowYt; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LqzjL0qlfz9sR4 for ; Sun, 24 Jul 2022 07:20:05 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NuSvrsQCIaRP/eyRi5Ns++sOW90zO+atzVhs8fglcIw=; b=hnZbTQobl/vI2Y eUL+ktcJaO1vzgzMJgqHBCgIIEM4qfEpeJPYeXSJIOC7JSXXoE9i3aFsuzCkQU9r+kK6kCOjRyv4/ ZekGIzkGLDLrvzwMHpzZrVJZcPxPclSfCp5kOaCjA+PPYFYDqMKLwCSdOR8AW4pVfnoYh2i/S/eVG Gn7iPpRztx9cwk311gCcDqJruN8CHDenMb2bbP9HSVkifBoi2stCg+uV6M6p33mTY/ZgDCpYs18/7 /K8Sh9pA53OVwmt3EHMx1n49zA3vR/B03tn0WvqQvAvcGjfN3Cv3uMtkiwvmYhUe467S3BCyJOW48 Eh5i6RJ6/ki7/lwiBL1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMVf-007Pql-Ik; Sat, 23 Jul 2022 21:18:04 +0000 Received: from srv4.3e8.eu ([2001:67c:12a0:200::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM85-007DeD-60 for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:43 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 1E2D060214; Sat, 23 Jul 2022 22:53:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O8nj+C07d5kkLZxNTyqbm8Sgm+JmqHpZAdL6hc4G7cE=; b=OYGOowYtuvYbokC4n+XsXz6DItOZJ2IA8610ylrQt2JUVQUH2PZBgLb47lp62nqUY2rK3W rciEHgLjEfVZCBrLUTttzAMPxQph+8kI21EyxMABslv9V+EPMDmgpEU9+JGLkoytwty6Kk UbVExXeCfRhUdLyJSSyNAnhblJAWyqW6YJT8OqT+PLsbmfWCNNcEtVtcbOa69ydRPpNTuB 1z3/WjIt/62NasUOHght+KfIGaW8zrGrrcsQpcg4k/7PN4jRB4Toxy2IPfjqzkGz9AplBZ OyKibb1YNPbkPAvF868nwhC3gVl7EhlLtCopLGS7lRPk2QC78sxbdINnp7f7Bw== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 5/7] kernel: mtdsplit: add support for H3C VFS filesystem Date: Sat, 23 Jul 2022 22:53:17 +0200 Message-Id: <20220723205319.3326374-6-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135341_571977_944B5515 X-CRM114-Status: GOOD ( 23.72 ) 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 bootloader on some H3C devices (for example HPE 1920 switches) only supports booting from flash by reading an image from an "VFS" filesystem which spans most of the available flash. The filesystem [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 bootloader on some H3C devices (for example HPE 1920 switches) only supports booting from flash by reading an image from an "VFS" filesystem which spans most of the available flash. The filesystem size is hard- coded in the bootloader. However, as long as no write operations are performed in the bootloader menu, it is sufficient if the start of the partition contains a valid filesystem with the kernel image. This mtdsplit parser reads the size and location of the kernel image and finds the location of the rootfs stored after it. It assumes that the filesystem image matches the layout of one generated by mkh3cvfs, with a filename of "openwrt-kernel.bin" for the kernel image. Signed-off-by: Jan Hoffmann --- target/linux/generic/config-5.10 | 1 + target/linux/generic/config-5.15 | 1 + .../files/drivers/mtd/mtdsplit/Kconfig | 5 + .../files/drivers/mtd/mtdsplit/Makefile | 1 + .../drivers/mtd/mtdsplit/mtdsplit_h3c_vfs.c | 170 ++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_h3c_vfs.c diff --git a/target/linux/generic/config-5.10 b/target/linux/generic/config-5.10 index c14851dbdb6f..2223456fe01a 100644 --- a/target/linux/generic/config-5.10 +++ b/target/linux/generic/config-5.10 @@ -3683,6 +3683,7 @@ CONFIG_MTD_SPLIT=y # CONFIG_MTD_SPLIT_FIRMWARE is not set CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware" # CONFIG_MTD_SPLIT_FIT_FW is not set +# CONFIG_MTD_SPLIT_H3C_VFS is not set # CONFIG_MTD_SPLIT_JIMAGE_FW is not set # CONFIG_MTD_SPLIT_LZMA_FW is not set # CONFIG_MTD_SPLIT_MINOR_FW is not set diff --git a/target/linux/generic/config-5.15 b/target/linux/generic/config-5.15 index 72a6ee2fbe0d..c21f7631ec1e 100644 --- a/target/linux/generic/config-5.15 +++ b/target/linux/generic/config-5.15 @@ -3827,6 +3827,7 @@ CONFIG_MTD_SPLIT=y # CONFIG_MTD_SPLIT_FIRMWARE is not set CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware" # CONFIG_MTD_SPLIT_FIT_FW is not set +# CONFIG_MTD_SPLIT_H3C_VFS is not set # CONFIG_MTD_SPLIT_JIMAGE_FW is not set # CONFIG_MTD_SPLIT_LZMA_FW is not set # CONFIG_MTD_SPLIT_MINOR_FW is not set diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig index 794a39f2c322..f929c6153e7f 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig @@ -101,3 +101,8 @@ config MTD_SPLIT_ELF_FW bool "ELF loader firmware partition parser" depends on MTD_SPLIT_SUPPORT select MTD_SPLIT + +config MTD_SPLIT_H3C_VFS + bool "Parser finding rootfs appended to H3C VFS" + depends on MTD_SPLIT_SUPPORT + select MTD_SPLIT diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile index 1461099b7c8b..a969c336aaeb 100644 --- a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile @@ -15,3 +15,4 @@ obj-$(CONFIG_MTD_SPLIT_WRGG_FW) += mtdsplit_wrgg.o obj-$(CONFIG_MTD_SPLIT_MINOR_FW) += mtdsplit_minor.o obj-$(CONFIG_MTD_SPLIT_JIMAGE_FW) += mtdsplit_jimage.o obj-$(CONFIG_MTD_SPLIT_ELF_FW) += mtdsplit_elf.o +obj-$(CONFIG_MTD_SPLIT_H3C_VFS) += mtdsplit_h3c_vfs.o diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_h3c_vfs.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_h3c_vfs.c new file mode 100644 index 000000000000..0adc2b6b1e0b --- /dev/null +++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_h3c_vfs.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Some devices made by H3C use a "VFS" filesystem to store firmware images. + * This parses the start of the filesystem to read the length of the first + * file (the kernel image). It then searches for the rootfs after the end of + * the file data. This driver assumes that the filesystem was generated by + * mkh3cvfs, and only works if the filesystem matches the expected layout, + * which includes the file name of the kernel image. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "mtdsplit.h" + +#define VFS_ERASEBLOCK_SIZE 0x10000 +#define VFS_BLOCK_SIZE 0x400 +#define VFS_BLOCKS_PER_ERASEBLOCK (VFS_ERASEBLOCK_SIZE / VFS_BLOCK_SIZE) + +#define FORMAT_FLAG_OFFSET 0x0 + +#define FORMAT_FLAG (VFS_ERASEBLOCK_SIZE << 12 | VFS_BLOCK_SIZE) + +#define FILE_ENTRY_OFFSET 0x800 + +#define FILE_ENTRY_FLAGS 0x3f +#define FILE_ENTRY_PARENT_BLOCK 0 +#define FILE_ENTRY_PARENT_INDEX 0 +#define FILE_ENTRY_DATA_BLOCK 2 +#define FILE_ENTRY_NAME "openwrt-kernel.bin" + +#define NR_PARTS 2 + +struct file_entry { + uint8_t flags; + + uint8_t res0[5]; + + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + + uint8_t res1[3]; + + uint32_t length; + + uint32_t parent_block; + uint16_t parent_index; + + uint8_t res2[2]; + + uint32_t data_block; + + char name[96]; +} __attribute__ ((packed)); + +static inline size_t block_offset(int block) +{ + return VFS_ERASEBLOCK_SIZE * (block / (VFS_BLOCKS_PER_ERASEBLOCK-1)) + + VFS_BLOCK_SIZE * (1 + (block % (VFS_BLOCKS_PER_ERASEBLOCK-1))); +} + +static inline int block_count(size_t size) +{ + return (size + VFS_BLOCK_SIZE - 1) / VFS_BLOCK_SIZE; +} + +static int mtdsplit_h3c_vfs_parse(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + struct mtd_partition *parts; + uint32_t format_flag; + struct file_entry file_entry; + size_t retlen; + int err; + size_t kernel_size; + size_t expected_offset; + size_t rootfs_offset; + + if (mtd->erasesize != VFS_ERASEBLOCK_SIZE) + return -EINVAL; + + /* Check format flag */ + err = mtd_read(mtd, FORMAT_FLAG_OFFSET, sizeof(format_flag), &retlen, + (void *) &format_flag); + if (err) + return err; + + if (retlen != sizeof(format_flag)) + return -EIO; + + if (format_flag != FORMAT_FLAG) + return -EINVAL; + + /* Check file entry */ + err = mtd_read(mtd, FILE_ENTRY_OFFSET, sizeof(file_entry), &retlen, + (void *) &file_entry); + if (err) + return err; + + if (retlen != sizeof(file_entry)) + return -EIO; + + if (file_entry.flags != FILE_ENTRY_FLAGS) + return -EINVAL; + + if (file_entry.parent_block != FILE_ENTRY_PARENT_BLOCK) + return -EINVAL; + + if (file_entry.parent_index != FILE_ENTRY_PARENT_INDEX) + return -EINVAL; + + if (file_entry.data_block != FILE_ENTRY_DATA_BLOCK) + return -EINVAL; + + if (strncmp(file_entry.name, FILE_ENTRY_NAME, sizeof(file_entry.name)) != 0) + return -EINVAL; + + /* Find rootfs offset */ + kernel_size = block_offset(file_entry.data_block + + block_count(file_entry.length) - 1) + + VFS_BLOCK_SIZE; + + expected_offset = mtd_roundup_to_eb(kernel_size, mtd); + + err = mtd_find_rootfs_from(mtd, expected_offset, mtd->size, + &rootfs_offset, NULL); + if (err) + return err; + + parts = kzalloc(NR_PARTS * sizeof(*parts), GFP_KERNEL); + if (!parts) + return -ENOMEM; + + parts[0].name = KERNEL_PART_NAME; + parts[0].offset = 0; + parts[0].size = rootfs_offset; + + parts[1].name = ROOTFS_PART_NAME; + parts[1].offset = rootfs_offset; + parts[1].size = mtd->size - rootfs_offset; + + *pparts = parts; + return NR_PARTS; +} + +static const struct of_device_id mtdsplit_h3c_vfs_of_match_table[] = { + { .compatible = "h3c,vfs-firmware" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtdsplit_h3c_vfs_of_match_table); + +static struct mtd_part_parser mtdsplit_h3c_vfs_parser = { + .owner = THIS_MODULE, + .name = "h3c-vfs", + .of_match_table = mtdsplit_h3c_vfs_of_match_table, + .parse_fn = mtdsplit_h3c_vfs_parse, + .type = MTD_PARSER_TYPE_FIRMWARE, +}; + +module_mtd_part_parser(mtdsplit_h3c_vfs_parser); From patchwork Sat Jul 23 20:53:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659985 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=EIaA2AmD; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=n8CpXxc1; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lqzgc329tz9sR4 for ; Sun, 24 Jul 2022 07:18:36 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WnLyFh1nSQWapEmYD/0B/LLJpBq6m3booIuJR4QSa6s=; b=EIaA2AmDLw2+I4 yddtZHRKM4GNIZDrV4YcuoIxP6KVJ6EYP8IMp+jmeopyEWgMPrxO39BiL+6NFgbOpoPZktGf+l/37 zTN6Q8RJPDsxD/Chy22sWfNWHVV4MPnT1zTbgd7T7F/JOVrbXS4HT1PfnLcmSYuM8VPL995X8s1MT SNXemvXulJRBPDqwZEl23swXri5YkkJAEz+zaUWWQvkvs//LBp4ZXvS573HjliNN9I7Qs1p4NHXAC Pv9mb0p07gq/kE5MbFL3tbam8wUZh5z166vySVgjQvjmlEeImMGBQfa5WwhdqX1GysTb0imcD3S0X jUqCupSu9URMzMMxc+4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMUE-007P6k-Re; Sat, 23 Jul 2022 21:16:35 +0000 Received: from srv4.3e8.eu ([2001:67c:12a0:200::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM86-007Df0-0L for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:44 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 52EEB600B5; Sat, 23 Jul 2022 22:53:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AohhWsNmhA4wou9FGAoAaZ3YMi65EHPXmkSJiAOyVaA=; b=n8CpXxc1d2MMvIK2gQT/EwAcYSuM1r13TTunt4NsxmlA5dSs5cUtkVuEo+yguuY9L0mIOc 5pOmt91oYaaadqh8fsbCefWw3SwIejEjk+TgIklxPCHaRF7u+EmT+sj+XcrAOz14QXzV0N 36amucHGSFI0yd+W6MxF0+DFIQ0RdVggN8Mi2H0CKRtpLm2uoXk4zQXSjil74NFDrRZePd 5R48fI/uUgsoJZ4elVDxoNS5VjadaQhyoJCKnaWBhzpnbKH2BTrWZiSdUhKkVhrsYkY8GD 9XaWCVu+ABDJLh8jF7N1oPzj5l7J9P/YQ2KlUoJ7hD+NeZwwozS2jRtrE5iepA== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 6/7] tools: add 7z host package Date: Sat, 23 Jul 2022 22:53:18 +0200 Message-Id: <20220723205319.3326374-7-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135342_272042_4F3817C2 X-CRM114-Status: GOOD ( 14.44 ) 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: Add the 7zr command line tool, which is a version of the 7z application that only supports 7z archives. 7z is one of the two compression formats supported in H3C firmware images (the alternative would be ARJ). Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Add the 7zr command line tool, which is a version of the 7z application that only supports 7z archives. 7z is one of the two compression formats supported in H3C firmware images (the alternative would be ARJ). (Alternatively, the 7zr command line tool could also be built from a current version of the public-domain LZMA SDK. That would require repackaging the source package, as it is only provided in 7z format.) Signed-off-by: Jan Hoffmann --- tools/7z/Makefile | 36 ++++++++++++++++++++++++++++++++++++ tools/Makefile | 1 + 2 files changed, 37 insertions(+) create mode 100644 tools/7z/Makefile diff --git a/tools/7z/Makefile b/tools/7z/Makefile new file mode 100644 index 000000000000..c94d746c6489 --- /dev/null +++ b/tools/7z/Makefile @@ -0,0 +1,36 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=7z +PKG_VERSION:=22.00 +PKG_SOURCE_VERSION:=2200 + +PKG_SOURCE:=$(PKG_NAME)$(PKG_SOURCE_VERSION)-src.tar.xz +PKG_SOURCE_URL:=https://7-zip.org/a/ +PKG_HASH:=40969f601e86aff49aaa0ba0df5ce6fd397cf7e2683a84b591b0081e461ef675 + +# This builds the 7zr variant which supports only 7z, so no non-LGPL code should be included +PKG_LICENSE:=LGPL-2.1-or-later +PKG_LICENSE_FILES:=DOC/License.txt DOC/copying.txt + +HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/host-build.mk + +TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS) + +ALONE_DIR=$(HOST_BUILD_DIR)/CPP/7zip/Bundles/Alone7z + +define Host/Compile + $(MAKE) -C $(ALONE_DIR) -f makefile.gcc +endef + +define Host/Install + $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin + $(INSTALL_BIN) $(ALONE_DIR)/_o/7zr $(STAGING_DIR_HOST)/bin/7zr +endef + +define Host/Clean + rm -f $(STAGING_DIR_HOST)/bin/7zr +endef + +$(eval $(call HostBuild)) diff --git a/tools/Makefile b/tools/Makefile index be1a23ed512f..0d6e675d4ceb 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -32,6 +32,7 @@ tools-$(BUILD_TOOLCHAIN) += expat gmp mpc mpfr tools-$(CONFIG_TARGET_apm821xx)$(CONFIG_TARGET_gemini) += genext2fs tools-$(CONFIG_TARGET_ath79) += lzma-old squashfs tools-$(CONFIG_TARGET_mxs) += elftosb sdimage +tools-$(CONFIG_TARGET_realtek) += 7z tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs tools-$(CONFIG_USES_MINOR) += kernel2minor tools-$(CONFIG_USE_SPARSE) += sparse From patchwork Sat Jul 23 20:53:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hoffmann X-Patchwork-Id: 1659987 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=FSIJ2f6D; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=3e8.eu header.i=@3e8.eu header.a=rsa-sha256 header.s=mail20211217 header.b=AlDjE4vG; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LqzlQ54V3z9sFx for ; Sun, 24 Jul 2022 07:21:54 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8lwZ2vqSVVCs3zBIps7SJXh+NcYgWR//2fL8FHDyMGM=; b=FSIJ2f6DNKY0Re 61lOfAXjzu6/ophGBVfn80TAyClXdbPIP3l3lVa5dLQdAHgXIAZOcjpyTv2BVuq8EY6lQv16O2YDp sZr1S0rwO6/H0R9cGwJmvPD/+esZKgcz7CfrQG1qgSA7oIZTBfF1uFOy/G664SxXuZMP6EfSA1VZi O+IvJJCSVZm2SrSc2zLeadwLQdKd2EOhvYIHzhSWGRj1wU8wY8s7kTj5PgIYyGhhMyy9jsIgVglm/ edLm06+mXHcA4WFzX29g1OiPx2wf+kSFB3CPN/5zIVLi8G4Z5Y6hWNbSjYrHOL/Ay+wj/IOvM0Ini C/m9pBLsYqe//3t1UoIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFMWz-007QWr-Lz; Sat, 23 Jul 2022 21:19:26 +0000 Received: from srv4.3e8.eu ([2001:67c:12a0:200::2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFM87-007Dfy-BX for openwrt-devel@lists.openwrt.org; Sat, 23 Jul 2022 20:53:47 +0000 Received: from localhost.localdomain (p200300c6cf1309a09555e5d92b92c48c.dip0.t-ipconnect.de [IPv6:2003:c6:cf13:9a0:9555:e5d9:2b92:c48c]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits)) (No client certificate requested) by srv4.3e8.eu (Postfix) with ESMTPSA id 37B0360215; Sat, 23 Jul 2022 22:53:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=3e8.eu; s=mail20211217; t=1658609621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VyN3zlpt9obzGwWzffI48XaP+rvjsrl13xYraX6T3gg=; b=AlDjE4vGNKia13PH9pGeQWVbqtbUkLl4bfqf00kSjnmnP7zhFSbJ1QfnPwDNaQRX17U8oI btl/f2tkfVscaNhy6wJOfXBO60hoCy/Qek42bwtLIBbTaQm4o7KFLqA35z7sln9Rpicf6J 1lGePNquHs/P8ZafH31nBSLTqI4D+phD8JmCK23Rhw5UvCuVObDpkafg4beMCJp11p2HrO 5jHidoyf6MB6vZ5bssZWAwzZP6I0m3Gz6to3SME6VnoZEIBPzIfT7ojnZIBGlz3ZFvA94/ n7izbfDbAQOm0vFEy84ETwtuSsO7nHRjXPOtjUwA/7ngq+03XPP3mghHvtog2A== From: Jan Hoffmann To: openwrt-devel@lists.openwrt.org Cc: Birger Koblitz , Sander Vanheule , Jan Hoffmann Subject: [PATCH 7/7] realtek: add support for HPE 1920 series Date: Sat, 23 Jul 2022 22:53:19 +0200 Message-Id: <20220723205319.3326374-8-jan@3e8.eu> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220723205319.3326374-1-jan@3e8.eu> References: <20220723205319.3326374-1-jan@3e8.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220723_135343_780608_6AEB0A43 X-CRM114-Status: GOOD ( 24.18 ) 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: Hardware information: - HPE 1920-8G: - RTL8380 SoC - 8 Gigabit RJ45 ports (built-in RTL8218B) - 2 SFP ports (built-in SerDes) - HPE 1920-16G / HPE 1920-24G (same board): - RTL8382 SoC - 16/24 Gigabit RJ45 ports (built-in RTL8218B, 1/2 external RTL8218D) - 4 SFP ports (external RTL8214FC) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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 Hardware information: --------------------- - HPE 1920-8G: - RTL8380 SoC - 8 Gigabit RJ45 ports (built-in RTL8218B) - 2 SFP ports (built-in SerDes) - HPE 1920-16G / HPE 1920-24G (same board): - RTL8382 SoC - 16/24 Gigabit RJ45 ports (built-in RTL8218B, 1/2 external RTL8218D) - 4 SFP ports (external RTL8214FC) - Common: - RJ45 RS232 port on front panel - 32 MiB NOR Flash - 128 MiB DDR3 DRAM - PT7A7514 watchdog Booting initramfs image: ------------------------ - Prepare a FTP or TFTP server serving the OpenWrt initramfs image and connect the server to a switch port. - Connect to the console port of the device and enter the extended boot menu by typing Ctrl+B when prompted. - Choose the menu option "<3> Enter Ethernet SubMenu". - Set network parameters via the option "<5> Modify Ethernet Parameter". Enter the FTP/TFTP filename as "Load File Name" ("Target File Name" can be left blank, it is not required for booting from RAM). Note that the configuration is saved on flash, so it only needs to be done once. - Select "<1> Download Application Program To SDRAM And Run". Initial installation: --------------------- - Boot an initramfs image as described above, then use sysupgrade to install OpenWrt permanently. After initial installation, the bootloader needs to be configured to load the correct image file - Enter the extended boot menu again and choose "<4> File Control", then select "<2> Set Application File type". - Enter the number of the file "openwrt-kernel.bin" (should be 1), and use the option "<1> +Main" to select it as boot image. - Choose "<0> Exit To Main Menu" and then "<1> Boot System". NOTE: The bootloader on these devices can only boot from the VFS filesystem which normally spans most of the flash. With OpenWrt, only the first part of the firmware partition contains a valid filesystem, the rest is used for rootfs. As the bootloader does not know about this, you must not do any file operations in the bootloader, as this may corrupt the OpenWrt installation (selecting the boot image is an exception, as it only stores a flag in the bootloader data, but doesn't write to the filesystem). Signed-off-by: Jan Hoffmann --- .../realtek/base-files/etc/board.d/02_network | 18 ++- .../realtek/dts-5.10/rtl8380_hpe_1920-8g.dts | 113 +++++++++++++++++ .../realtek/dts-5.10/rtl8382_hpe_1920-16g.dts | 48 +++++++ .../realtek/dts-5.10/rtl8382_hpe_1920-24g.dts | 68 ++++++++++ .../realtek/dts-5.10/rtl8382_hpe_1920.dtsi | 117 ++++++++++++++++++ target/linux/realtek/dts-5.10/rtl838x.dtsi | 7 ++ .../realtek/dts-5.10/rtl838x_hpe_1920.dtsi | 96 ++++++++++++++ target/linux/realtek/image/Makefile | 49 ++++++++ target/linux/realtek/image/rtl838x.mk | 24 ++++ target/linux/realtek/rtl838x/config-5.10 | 3 + 10 files changed, 540 insertions(+), 3 deletions(-) create mode 100644 target/linux/realtek/dts-5.10/rtl8380_hpe_1920-8g.dts create mode 100644 target/linux/realtek/dts-5.10/rtl8382_hpe_1920-16g.dts create mode 100644 target/linux/realtek/dts-5.10/rtl8382_hpe_1920-24g.dts create mode 100644 target/linux/realtek/dts-5.10/rtl8382_hpe_1920.dtsi create mode 100644 target/linux/realtek/dts-5.10/rtl838x_hpe_1920.dtsi diff --git a/target/linux/realtek/base-files/etc/board.d/02_network b/target/linux/realtek/base-files/etc/board.d/02_network index af9db848dd8a..5356bcac65d0 100644 --- a/target/linux/realtek/base-files/etc/board.d/02_network +++ b/target/linux/realtek/base-files/etc/board.d/02_network @@ -22,9 +22,20 @@ ucidef_set_bridge_device switch ucidef_set_interface_lan "$lan_list" lan_mac="" +lan_mac_start="" lan_mac_end="" label_mac="" case $board in +hpe,1920-8g|\ +hpe,1920-16g|\ +hpe,1920-24g) + label_mac=$(mtd_get_mac_binary factory 0x68) + lan_mac=$label_mac + mac_count1=$(hexdump -v -n 4 -s 0x110 -e '4 "%d"' $(find_mtd_part factory) 2>/dev/null) + mac_count2=$(hexdump -v -n 4 -s 0x114 -e '4 "%d"' $(find_mtd_part factory) 2>/dev/null) + lan_mac_start=$(macaddr_add $lan_mac 2) + lan_mac_end=$(macaddr_add $lan_mac $((mac_count2-mac_count1))) + ;; *) lan_mac=$(mtd_get_mac_ascii u-boot-env2 mac_start) lan_mac_end=$(mtd_get_mac_ascii u-boot-env2 mac_end) @@ -36,10 +47,11 @@ esac ucidef_set_interface_macaddr "lan" $lan_mac ucidef_set_bridge_mac "$lan_mac" ucidef_set_network_device_mac eth0 $lan_mac +[ -z "$lan_mac_start" ] && lan_mac_start=$lan_mac for lan in $lan_list; do - ucidef_set_network_device_mac $lan $lan_mac - [ -z "$lan_mac_end" ] || [ "$lan_mac" == "$lan_mac_end" ] && lan_mac=$(macaddr_setbit_la $lan_mac) - lan_mac=$(macaddr_add $lan_mac 1) + ucidef_set_network_device_mac $lan $lan_mac_start + [ -z "$lan_mac_end" ] || [ "$lan_mac_start" == "$lan_mac_end" ] && lan_mac_start=$(macaddr_setbit_la $lan_mac_start) + lan_mac_start=$(macaddr_add $lan_mac_start 1) done [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac diff --git a/target/linux/realtek/dts-5.10/rtl8380_hpe_1920-8g.dts b/target/linux/realtek/dts-5.10/rtl8380_hpe_1920-8g.dts new file mode 100644 index 000000000000..b51c75f35524 --- /dev/null +++ b/target/linux/realtek/dts-5.10/rtl8380_hpe_1920-8g.dts @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "rtl838x.dtsi" +#include "rtl838x_hpe_1920.dtsi" + +/ { + compatible = "hpe,1920-8g", "realtek,rtl838x-soc"; + model = "HPE 1920-8G (JG920A)"; + + gpio1: rtl8231-gpio { + compatible = "realtek,rtl8231-gpio"; + #gpio-cells = <2>; + gpio-controller; + indirect-access-bus-id = <0>; + }; + + i2c0: i2c-gpio-0 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 23 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 24 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp0: sfp-0 { + compatible = "sff,sfp"; + i2c-bus = <&i2c0>; + los-gpio = <&gpio1 26 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 25 GPIO_ACTIVE_LOW>; + // tx-fault and tx-disable unconnected + }; + + i2c1: i2c-gpio-1 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 13 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 14 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp1: sfp-1 { + compatible = "sff,sfp"; + i2c-bus = <&i2c1>; + los-gpio = <&gpio1 22 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 21 GPIO_ACTIVE_LOW>; + // tx-fault and tx-disable unconnected + }; +}; + +ðernet0 { + mdio: mdio-bus { + compatible = "realtek,rtl838x-mdio"; + regmap = <ðernet0>; + #address-cells = <1>; + #size-cells = <0>; + + INTERNAL_PHY(8) + INTERNAL_PHY(9) + INTERNAL_PHY(10) + INTERNAL_PHY(11) + INTERNAL_PHY(12) + INTERNAL_PHY(13) + INTERNAL_PHY(14) + INTERNAL_PHY(15) + + INTERNAL_PHY(24) + INTERNAL_PHY(26) + }; +}; + +&switch0 { + ports { + #address-cells = <1>; + #size-cells = <0>; + + SWITCH_PORT(8, 1, internal) + SWITCH_PORT(9, 2, internal) + SWITCH_PORT(10, 3, internal) + SWITCH_PORT(11, 4, internal) + SWITCH_PORT(12, 5, internal) + SWITCH_PORT(13, 6, internal) + SWITCH_PORT(14, 7, internal) + SWITCH_PORT(15, 8, internal) + + port@24 { + reg = <24>; + label = "lan9"; + phy-mode = "1000base-x"; + managed = "in-band-status"; + sfp = <&sfp0>; + }; + + port@26 { + reg = <26>; + label = "lan10"; + phy-mode = "1000base-x"; + managed = "in-band-status"; + sfp = <&sfp1>; + }; + + port@28 { + ethernet = <ðernet0>; + reg = <28>; + phy-mode = "internal"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; +}; diff --git a/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-16g.dts b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-16g.dts new file mode 100644 index 000000000000..59043b2f6f79 --- /dev/null +++ b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-16g.dts @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "rtl8382_hpe_1920.dtsi" + +/ { + compatible = "hpe,1920-16g", "realtek,rtl838x-soc"; + model = "HPE 1920-16G (JG923A)"; +}; + +&switch0 { + ports { + #address-cells = <1>; + #size-cells = <0>; + + SWITCH_PORT(8, 1, internal) + SWITCH_PORT(9, 2, internal) + SWITCH_PORT(10, 3, internal) + SWITCH_PORT(11, 4, internal) + SWITCH_PORT(12, 5, internal) + SWITCH_PORT(13, 6, internal) + SWITCH_PORT(14, 7, internal) + SWITCH_PORT(15, 8, internal) + + SWITCH_PORT(16, 9, qsgmii) + SWITCH_PORT(17, 10, qsgmii) + SWITCH_PORT(18, 11, qsgmii) + SWITCH_PORT(19, 12, qsgmii) + SWITCH_PORT(20, 13, qsgmii) + SWITCH_PORT(21, 14, qsgmii) + SWITCH_PORT(22, 15, qsgmii) + SWITCH_PORT(23, 16, qsgmii) + + SWITCH_PORT(24, 17, qsgmii) + SWITCH_PORT(25, 18, qsgmii) + SWITCH_PORT(26, 19, qsgmii) + SWITCH_PORT(27, 20, qsgmii) + + port@28 { + ethernet = <ðernet0>; + reg = <28>; + phy-mode = "internal"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; +}; diff --git a/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-24g.dts b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-24g.dts new file mode 100644 index 000000000000..61781c708e28 --- /dev/null +++ b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920-24g.dts @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "rtl8382_hpe_1920.dtsi" + +/ { + compatible = "hpe,1920-24g", "realtek,rtl838x-soc"; + model = "HPE 1920-24G (JG924A)"; +}; + +&mdio { + EXTERNAL_PHY(0) + EXTERNAL_PHY(1) + EXTERNAL_PHY(2) + EXTERNAL_PHY(3) + EXTERNAL_PHY(4) + EXTERNAL_PHY(5) + EXTERNAL_PHY(6) + EXTERNAL_PHY(7) +}; + +&switch0 { + ports { + #address-cells = <1>; + #size-cells = <0>; + + SWITCH_PORT(0, 1, qsgmii) + SWITCH_PORT(1, 2, qsgmii) + SWITCH_PORT(2, 3, qsgmii) + SWITCH_PORT(3, 4, qsgmii) + SWITCH_PORT(4, 5, qsgmii) + SWITCH_PORT(5, 6, qsgmii) + SWITCH_PORT(6, 7, qsgmii) + SWITCH_PORT(7, 8, qsgmii) + + SWITCH_PORT(8, 9, internal) + SWITCH_PORT(9, 10, internal) + SWITCH_PORT(10, 11, internal) + SWITCH_PORT(11, 12, internal) + SWITCH_PORT(12, 13, internal) + SWITCH_PORT(13, 14, internal) + SWITCH_PORT(14, 15, internal) + SWITCH_PORT(15, 16, internal) + + SWITCH_PORT(16, 17, qsgmii) + SWITCH_PORT(17, 18, qsgmii) + SWITCH_PORT(18, 19, qsgmii) + SWITCH_PORT(19, 20, qsgmii) + SWITCH_PORT(20, 21, qsgmii) + SWITCH_PORT(21, 22, qsgmii) + SWITCH_PORT(22, 23, qsgmii) + SWITCH_PORT(23, 24, qsgmii) + + SWITCH_PORT(24, 25, qsgmii) + SWITCH_PORT(25, 26, qsgmii) + SWITCH_PORT(26, 27, qsgmii) + SWITCH_PORT(27, 28, qsgmii) + + port@28 { + ethernet = <ðernet0>; + reg = <28>; + phy-mode = "internal"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; +}; diff --git a/target/linux/realtek/dts-5.10/rtl8382_hpe_1920.dtsi b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920.dtsi new file mode 100644 index 000000000000..5368b41c2769 --- /dev/null +++ b/target/linux/realtek/dts-5.10/rtl8382_hpe_1920.dtsi @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "rtl838x.dtsi" +#include "rtl838x_hpe_1920.dtsi" + +/ { + gpio1: rtl8231-gpio { + compatible = "realtek,rtl8231-gpio"; + #gpio-cells = <2>; + gpio-controller; + indirect-access-bus-id = <0>; + }; + + i2c0: i2c-gpio-0 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 13 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 14 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp0: sfp-0 { + compatible = "sff,sfp"; + i2c-bus = <&i2c0>; + los-gpio = <&gpio1 22 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 21 GPIO_ACTIVE_LOW>; + // tx-fault unconnected + // tx-disable connected to RTL8214FC + }; + + i2c1: i2c-gpio-1 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 23 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 24 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp1: sfp-1 { + compatible = "sff,sfp"; + i2c-bus = <&i2c1>; + los-gpio = <&gpio1 26 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 25 GPIO_ACTIVE_LOW>; + // tx-fault unconnected + // tx-disable connected to RTL8214FC + }; + + i2c2: i2c-gpio-2 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 27 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 28 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp2: sfp-2 { + compatible = "sff,sfp"; + i2c-bus = <&i2c2>; + los-gpio = <&gpio1 30 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 29 GPIO_ACTIVE_LOW>; + // tx-fault unconnected + // tx-disable connected to RTL8214FC + }; + + i2c3: i2c-gpio-3 { + compatible = "i2c-gpio"; + sda-gpios = <&gpio1 31 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + scl-gpios = <&gpio1 32 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + sfp3: sfp-3 { + compatible = "sff,sfp"; + i2c-bus = <&i2c3>; + los-gpio = <&gpio1 34 GPIO_ACTIVE_HIGH>; + mod-def0-gpio = <&gpio1 33 GPIO_ACTIVE_LOW>; + // tx-fault unconnected + // tx-disable connected to RTL8214FC + }; +}; + +ðernet0 { + mdio: mdio-bus { + compatible = "realtek,rtl838x-mdio"; + regmap = <ðernet0>; + #address-cells = <1>; + #size-cells = <0>; + + INTERNAL_PHY(8) + INTERNAL_PHY(9) + INTERNAL_PHY(10) + INTERNAL_PHY(11) + INTERNAL_PHY(12) + INTERNAL_PHY(13) + INTERNAL_PHY(14) + INTERNAL_PHY(15) + + EXTERNAL_PHY(16) + EXTERNAL_PHY(17) + EXTERNAL_PHY(18) + EXTERNAL_PHY(19) + EXTERNAL_PHY(20) + EXTERNAL_PHY(21) + EXTERNAL_PHY(22) + EXTERNAL_PHY(23) + + EXTERNAL_SFP_PHY_FULL(24, 0) + EXTERNAL_SFP_PHY_FULL(25, 1) + EXTERNAL_SFP_PHY_FULL(26, 2) + EXTERNAL_SFP_PHY_FULL(27, 3) + }; +}; diff --git a/target/linux/realtek/dts-5.10/rtl838x.dtsi b/target/linux/realtek/dts-5.10/rtl838x.dtsi index 11cabc3f63cb..41fdbdae20b2 100644 --- a/target/linux/realtek/dts-5.10/rtl838x.dtsi +++ b/target/linux/realtek/dts-5.10/rtl838x.dtsi @@ -27,6 +27,13 @@ reg = <##n>; \ }; +#define EXTERNAL_SFP_PHY_FULL(n, s) \ + phy##n: ethernet-phy@##n { \ + compatible = "ethernet-phy-ieee802.3-c22"; \ + sfp = <&sfp##s>; \ + reg = <##n>; \ + }; + #define SWITCH_PORT(n, s, m) \ port@##n { \ reg = <##n>; \ diff --git a/target/linux/realtek/dts-5.10/rtl838x_hpe_1920.dtsi b/target/linux/realtek/dts-5.10/rtl838x_hpe_1920.dtsi new file mode 100644 index 000000000000..8e29af62bbf4 --- /dev/null +++ b/target/linux/realtek/dts-5.10/rtl838x_hpe_1920.dtsi @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include +#include + +/ { + chosen { + bootargs = "console=ttyS0,38400"; + }; + + memory@0 { + device_type = "memory"; + reg = <0x0 0x8000000>; + }; + + watchdog1: watchdog { + // PT7A7514 + compatible = "linux,wdt-gpio"; + gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; + hw_algo = "toggle"; + hw_margin_ms = <1000>; + always-running; + + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_disable_sys_led>; + }; +}; + +&watchdog0 { + status = "disabled"; +}; + +&spi0 { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <50000000>; + m25p,fast-read; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "bootware_basic"; + reg = <0x0 0x50000>; + read-only; + }; + + partition@0x60000 { + label = "bootware_data"; + reg = <0x60000 0x30000>; + read-only; + }; + + partition@0x90000 { + label = "bootware_extend"; + reg = <0x90000 0x40000>; + read-only; + }; + + partition@0x100000 { + label = "bootware_basic_backup"; + reg = <0x100000 0x50000>; + read-only; + }; + + partition@0x160000 { + label = "bootware_data_backup"; + reg = <0x160000 0x30000>; + read-only; + }; + + partition@0x190000 { + label = "bootware_extend_backup"; + reg = <0x190000 0x40000>; + read-only; + }; + + partition@0x300000 { + label = "firmware"; + compatible = "h3c,vfs-firmware"; + reg = <0x300000 0x1cf0000>; + }; + + partition@0x1ff0000 { + label = "factory"; + reg = <0x1ff0000 0x10000>; + read-only; + }; + }; + }; +}; diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index cf779002e86e..6165d99bfc51 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -8,6 +8,7 @@ KERNEL_ENTRY = 0x80000400 DEVICE_VARS += ZYXEL_VERS DLINK_KERNEL_PART_SIZE DEVICE_VARS += CAMEO_KERNEL_PART CAMEO_ROOTFS_PART CAMEO_CUSTOMER_SIGNATURE CAMEO_BOARD_VERSION +DEVICE_VARS += H3C_PRODUCT_ID H3C_DEVICE_ID define Build/zyxel-vers ( echo VERS;\ @@ -41,6 +42,43 @@ define Build/dlink-headers cat $@.kernel_part.hex $@.rootfs_part.hex > $@ endef +define Build/7z + $(STAGING_DIR_HOST)/bin/7zr a $(@).new -t7z -m0=lzma $(@) + mv $@.new $@ +endef + +define Build/h3c-image + $(STAGING_DIR_HOST)/bin/mkh3cimg \ + -i $(@) \ + -o $(@).new \ + -c 7z \ + -p $(H3C_PRODUCT_ID) \ + -d $(H3C_DEVICE_ID) + mv $@.new $@ +endef + +define Build/h3c-vfs + $(STAGING_DIR_HOST)/bin/mkh3cvfs \ + -i $(@) \ + -o $(@).new \ + -f openwrt-kernel.bin + mv $@.new $@ +endef + +define Build/relocate-kernel + rm -rf $@.relocate + $(CP) ../../generic/image/relocate $@.relocate + $(MAKE) -j1 -C $@.relocate KERNEL_ADDR=$(KERNEL_LOADADDR) LZMA_TEXT_START=0x82000000 \ + CROSS_COMPILE=$(TARGET_CROSS) + ( \ + dd if=$@.relocate/loader.bin bs=32 conv=sync && \ + perl -e '@s = stat("$@"); print pack("N", @s[7])' && \ + cat "$@" \ + ) > "$@.new" + mv "$@.new" "$@" + rm -rf $@.relocate +endef + define Device/Default PROFILES = Default KERNEL := kernel-bin | append-dtb | gzip | uImage gzip @@ -52,6 +90,17 @@ define Device/Default check-size | append-metadata endef +define Device/hpe_1920 + DEVICE_VENDOR := HPE + IMAGE_SIZE := 29632k + BLOCKSIZE := 64k + H3C_PRODUCT_ID := 0x3c010501 + KERNEL := kernel-bin | append-dtb | relocate-kernel | 7z | h3c-image | h3c-vfs + KERNEL_INITRAMFS := kernel-bin | append-dtb | relocate-kernel | 7z | h3c-image + IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \ + pad-rootfs | check-size | append-metadata +endef + # "NGE" refers to the uImage magic define Device/netgear_nge KERNEL := kernel-bin | append-dtb | lzma | uImage lzma diff --git a/target/linux/realtek/image/rtl838x.mk b/target/linux/realtek/image/rtl838x.mk index 887f82e385c4..60eda5359d29 100644 --- a/target/linux/realtek/image/rtl838x.mk +++ b/target/linux/realtek/image/rtl838x.mk @@ -65,6 +65,30 @@ define Device/engenius_ews2910p endef TARGET_DEVICES += engenius_ews2910p +define Device/hpe_1920-8g + $(Device/hpe_1920) + SOC := rtl8380 + DEVICE_MODEL := 1920-8G (JG920A) + H3C_DEVICE_ID := 0x00010023 +endef +TARGET_DEVICES += hpe_1920-8g + +define Device/hpe_1920-16g + $(Device/hpe_1920) + SOC := rtl8382 + DEVICE_MODEL := 1920-16G (JG923A) + H3C_DEVICE_ID := 0x00010026 +endef +TARGET_DEVICES += hpe_1920-16g + +define Device/hpe_1920-24g + $(Device/hpe_1920) + SOC := rtl8382 + DEVICE_MODEL := 1920-24G (JG924A) + H3C_DEVICE_ID := 0x00010027 +endef +TARGET_DEVICES += hpe_1920-24g + define Device/inaba_aml2-17gp SOC := rtl8382 IMAGE_SIZE := 13504k diff --git a/target/linux/realtek/rtl838x/config-5.10 b/target/linux/realtek/rtl838x/config-5.10 index c117fc489a81..9075aa6d3cfa 100644 --- a/target/linux/realtek/rtl838x/config-5.10 +++ b/target/linux/realtek/rtl838x/config-5.10 @@ -74,6 +74,8 @@ CONFIG_GPIO_PCA953X=y CONFIG_GPIO_PCA953X_IRQ=y CONFIG_GPIO_REALTEK_OTTO=y CONFIG_GPIO_RTL8231=y +CONFIG_GPIO_WATCHDOG=y +# CONFIG_GPIO_WATCHDOG_ARCH_INITCALL is not set CONFIG_GRO_CELLS=y CONFIG_HANDLE_DOMAIN_IRQ=y CONFIG_HARDWARE_WATCHPOINTS=y @@ -134,6 +136,7 @@ CONFIG_MTD_SPI_NOR=y CONFIG_MTD_SPLIT_BRNIMAGE_FW=y CONFIG_MTD_SPLIT_EVA_FW=y CONFIG_MTD_SPLIT_FIRMWARE=y +CONFIG_MTD_SPLIT_H3C_VFS=y CONFIG_MTD_SPLIT_TPLINK_FW=y CONFIG_MTD_SPLIT_UIMAGE_FW=y CONFIG_NEED_DMA_MAP_STATE=y